⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 te_menu.c

📁 用BC++3.1编的C语言文本编辑器
💻 C
字号:
#include "te.h"
#define MAXMENU 4
#define MAXPOP  11

extern void quit(int);
extern char isInsert,szFilePath[MAXPATH];
int wincolor=0x17;
int cur_menu_x=0,cur_menu_y=0,cur_menu_num,len;
int menu_x0=0,menu_y0=0,menu_x1=0,menu_y1=0,is_poped=0;
char is_showpop=0;
void ShowMenu(int);

char *pszMain[MAXMENU]={"~File",
		 "~Search",
		 "~Option",
		 "~Help"
		 };

char *pszMenu[][MAXPOP][2]=
 {
  {
   {"~New","Create a new file" },
   {"~Open           F2","Open a exist file"},
   {"~Save           F3","Save current file"},
   {"Save ~As...     F4","Save current file to a new file"},
   {"+",NULL},
   {"~Dos Shell","Temporily return to DOS"},
   {"+",NULL},
   {"E~xit        Alt+X","Exit Text Editor"},
   {NULL,NULL}
  },
  {

   {"~Find...    Ctrl+F","Search Text"},
   {"Find ~Next      F5","Continue search Text"},
    {NULL,NULL}
  },
  {
   {"~Text Color         F7","Set Text color"},
   {"~Background Color   F8","Set Background Color"},
   {NULL,NULL}
  },
  {
   {"~Help contents   F1","Show help box"},
   {"+",NULL},
   {"~About","Show text editor version"},
   {NULL,NULL}
  }
};

int mainmenu(int is_all)
{
int i,ret=0;
char ctemp[100];
 cur_type=isInsert?1:2;

 if(is_all)
 {
  ret=1;
  if(is_all==2)
   textmode(C80);
  window(2,3,79,24);
  textattr(wincolor);
  clr();
 }
 window(1,1,80,1);
 textattr(0x70);
 clr();

 window(1,25,80,25);
 textattr(0x70);
 clr();

 ShowMenu(-1);
  for(i=3;i<25;i++)
  {
   outxy(1,i,0x7,l[1]);
   outxy(80,i,0x7,l[1]);
  }
  for(i=2;i<80;i++)
   outxy(i,2,0x7,l[0]);
  outxy(1,2,0x07,border[0][0]);
  outxy(80,2,0x7,border[0][2]);
 i=sprintf(ctemp,"  %s %s",szFilePath,isReadOnly?"\v\(R\)":" ");
 outs((80-i)/2,2,0x30,0x34,ctemp);
 window(2,3,79,24);
 textattr(wincolor);
 cur(cur_type);
 return ret;
}



void ShowMenu(int index) /*显示主菜单*/
{
int i,j=0;
 for(i=0;i<MAXMENU;i++)
  {
   if(i==index)
	outs(3+j,1,0x0F,0x0F,pszMain[i]);
   else outs(3+j,1,0x70,0x74,pszMain[i]);
   j+=slen(pszMain[i])+1;
  }

}


int ShowPopMenu(int hotkey[])    /*显示下拉菜单*/
{
int i,j;
/*box(menu_x0,menu_y0,menu_x1-1,menu_y1-1,1,0x3e,0);*/

for(j=0;j<cur_menu_num;j++)
{
 if(pszMenu[cur_menu_x][j][0][0]=='+')
     {
      hotkey[j]=0;
      outxy(menu_x0,menu_y0+1+j,0x70,'\xc3');
      for(i=0;i<len+1;i++)
      outxy(menu_x0+1+i,j+menu_y0+1,0x70,'\xc4');
      outxy(menu_x0+1+i,menu_y0+1+j,0x70,'\xb4');
     }
 else
  {
   if(cur_menu_y==j)
    {
      for(i=0;i<len+1;i++)
      outxy(menu_x0+1+i,j+menu_y0+1,0x23,' ');
      hotkey[j]=outs(menu_x0+2,j+menu_y0+1,0x20,0x24,pszMenu[cur_menu_x][j][0]);
      outs(2,25,0x7a,0X74,"\t\x30");
      outs(2,25,0x7e,0x7E,pszMenu[cur_menu_x][j][1]);
    }
   else
    {
     for(i=0;i<len+1;i++)
      outxy(menu_x0+1+i,j+menu_y0+1,0x70,' ');
     hotkey[j]=outs(menu_x0+2,j+menu_y0+1,0x70,0x74,pszMenu[cur_menu_x][j][0]);
    }
  }
}
return 0;
}

char *PopMenu(int is_ret)  /*不拉菜单的边框*/
{
int i,j,k,start_x;
char ctemp[100];
static char *buff=NULL;
start_x=3;
len=slen(pszMenu[cur_menu_x][0][0]);
for(i=0;i<cur_menu_x;i++)start_x+=slen(pszMain[i]);
for(i=1;i<MAXPOP;i++)
 {
  if(pszMenu[cur_menu_x][i][0]==NULL)
   {cur_menu_num=i;
    break;
   }
  j=slen(pszMenu[cur_menu_x][i][0]);
  if(len<j)len=j;
 }
if(buff)
 {puttext(menu_x0,menu_y0,menu_x1,menu_y1,buff);
  farfree(buff);
  buff=NULL;
 }
if(is_ret)return NULL;
cur_menu_y=0;
menu_x0=cur_menu_x+start_x-1,menu_y0=2,menu_x1=menu_x0+len+3,menu_y1=menu_y0+cur_menu_num+2;
buff=(char *)farmalloc((menu_y1-menu_y0+1)*(menu_x1-menu_x0+1)*2);
if(buff==NULL)quit(1);
gettext(menu_x0,menu_y0,menu_x1,menu_y1,buff);
box(menu_x0,menu_y0,menu_x1-1,menu_y1-1,3,0x70,1);
return buff;
}


int DriveMenu(KEYCODE *pkc)  /*菜单控制的主函数*/
{
int k,i;
char is_showmain=1,*scrbuff=NULL,is_poped=0;
int hotkey[MAXPOP];
char is_showpopmenu=0;
KEYCODE kc;
cur(0);
do
{
 if(is_showmain)
  {
   ShowMenu(cur_menu_x);
   is_showmain=0;
  }
 if(is_showpop)
  {
   scrbuff=PopMenu(0);
   is_showpop=0;
   is_showpopmenu=1;
   is_poped=1;
  }
 if(is_showpopmenu)
 {
  ShowPopMenu(hotkey);
  is_showpopmenu=0;
 }
 k=getkey(&kc);
 switch(k)
 {
  case ESC:
    pkc->code=0;
    break;
  case UP:
    if(!is_poped)
     {
      is_showpop=1;
      break;
     }
    if(cur_menu_y>0)
      {
       cur_menu_y--;
       if(pszMenu[cur_menu_x][cur_menu_y][0][0]=='+')
	 cur_menu_y--;
      }
    else
      cur_menu_y=cur_menu_num-1;
    is_showpopmenu=1;

    break;
  case DOWN:
    if(!is_poped)
     {
      is_showpop=1;
      break;
     }
    if(cur_menu_y<cur_menu_num-1)
      {
       cur_menu_y++;
       if(pszMenu[cur_menu_x][cur_menu_y][0][0]=='+')
	 cur_menu_y++;
      }
    else
      cur_menu_y=0;
    is_showpopmenu=1;
    break;
  case ENTER:
    if(!is_poped)
     {
      is_showpop=1;
      break;
     }
     pkc->code=hotkey[cur_menu_y]+0x100*(cur_menu_x+1);
     k=ESC;
     break;
  case LEFT:
    if(cur_menu_x>0)cur_menu_x--;
    else cur_menu_x=MAXMENU-1;
    is_showmain=1;
    if(is_poped)is_showpop=1;
    break;
  case RIGHT:
    if(cur_menu_x<MAXMENU-1)cur_menu_x++;
    else cur_menu_x=0;
    is_showmain=1;
    if(is_poped)is_showpop=1;
    break;
  default:
    if(!is_poped)break;
    for(i=0;i<cur_menu_num;i++)
      if(kc.cup==hotkey[i])
       {
	pkc->code=hotkey[i]+0x100*(cur_menu_x+1);
	k=ESC;
       }
    break;
 }
}
while(k!=ESC);
if(scrbuff)
 PopMenu(1);
cur(isInsert?1:2);
ShowMenu(-1);
mainmenu(0);
return pkc->code;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -