📄 help
字号:
if(flags==1){ wmove(w,y+1,x+(width-4)/2); waddstr(w,"<OK>"); wrefresh(w); while(getch()!=Key_enter); Putrect(w,j,k,Scr); Free(Scr); return 0; } wmove(w,y+1,x+(width-17)/2); waddstr(w,CL1); wrefresh(w); i=2; while(1){ ch=getch(); switch(ch){ case Key_left: case Key_right: if(i==1){ i=2; wmove(w,y+1,x+(width-17)/2); waddstr(w,CL1); wrefresh(w); }else{ i=1; wmove(w,y+1,x+(width-17)/2); waddstr(w,OK1); wrefresh(w); } break; case Key_enter: Putrect(w,j,k,Scr); Free(Scr); break; } if(ch==Key_enter) break; } return(i);}/*** 是否支持颜色***/is_terminal(){ if ( strcmp( getenv( "TERM", "ansi" ) == 0 )) return(1); else return(0);}/*** Getchar() ***/int f_getch(){ int keynum ; keynum = getch(); if(keynum==Key_esc){ if( ( keynum=getch())==91){ return(getch()); } } return( keynum );}/***** 把 s2 放到 s1 的前面***/f_strcat( s1, s2 )char *s1;char *s2;{ char s[512]; strcpy( s, s2 ); strcat ( s, s1 ); strcpy( s1 , s );}END:tool.cBEGIN:tool1.c#include "./apmenu.h"static int CXH; /*****TREELIST的显示次序*****//***** 新生成一个树形控件*****/TREE_CONTROL *init_treecontrol( win, y, x, h, w, fn_color, bk_color,sefn_color,sebk_color)WINDOW *win;int y;int x;int h;int w;int bk_color; int fn_color;int sebk_color;int sefn_color;{ TREE_CONTROL *tree = (TREE_CONTROL *)malloc(sizeof(TREE_CONTROL)); tree->win = win; tree->y = y; tree->x = x; tree->w = w; tree->h = h; tree->bk_color=bk_color; tree->fn_color=fn_color; tree->sebk_color=sebk_color; tree->sefn_color=sefn_color; tree->i = 0; tree->col = 1; int nscroll; int nselect; { int i, j, k,l,len, level; char tail[256],s[512],text[TREE_TEXT_LEN+1]; TREE_LIST *list; TREE_ITEM *item; wsetcolor( tree->win, tree->fn_color, tree->bk_color ); list = tree->list; j = 0; /**** j 是可显示的第几条 ****/ l = 0; /**** l 是在屏幕上可显示的第几条 ****/ for ( i = 0; i < tree->num; i ++ ) { if ( list[i].visible == 1 ) { j ++; if ( j >=nscroll && ( l < tree->h ) ) { /********** 绘ITEM *************/ l ++; level = list[i].level; strcpy( text, list[i].item->text ); *tail = '\0'; item = list[i].item; for ( k = 1; k <= level-1 ; k++) { /***** 生成TEXT前的线条 *****/ if ( k < level -1 ) { if ( item == (TREE_ITEM *)NULL) f_strcat( tail, " " ); else { item=item->prelevellink; if(item->nextlink== (TREE_ITEM *)NULL) f_strcat(tail," " ); else f_strcat( tail,"│ "); } } else if ( k == level -1 ) { if ( tree->list[i].item->nextlink == (TREE_ITEM *) NULL ) strcat( tail, "└" ); else strcat( tail, "├" ); if (tree->list[i].item->nextlevellink == (TREE_ITEM *) NULL ) strcat( tail, "--" ); else strcat( tail, "*>" ); } } if ( (level-1)*4 > tree->w ) strmove( s, tail,tree->w ); else strcpy( s, tail ); mvwaddstr(tree->win,tree->y+l-1,tree->x, s ); len = strlen(text); if (( len + (level-1) *4 ) > tree->w ) if( tree->w >= (level-1)*4 ) strmove( s, tree->list[i].item->text, tree->w - (level-1)*4 ); else *s = '\0'; else strcpy( s,text ); if ( nselect == l ) { /***选中行*****/ wsetcolor( tree->win, tree->sefn_color, tree->sebk_color ); mvwaddstr(tree->win,tree->y+l-1, tree->x+(level-1)*4 , s ); wsetcolor( tree->win, tree->fn_color, tree->bk_color ); } else mvwaddstr(tree->win,tree->y+l-1, tree->x+(level-1)*4 , s ); *s = '\0'; for (k = (level-1)*2+len; k < tree->w;k++) strcat( s, " " ); mvwaddstr(tree->win,tree->y+l-1, tree->x+(level-1)*4+len , s ); } } /* if ( l >= tree->h ) break; */ } if ( l < tree->h ) { *s = '\0'; for ( k = 1; k<= tree->w ;k++ ) strcat( s, " " ); for( k = l+1 ; k<=tree->h ; k ++ ) mvwaddstr(tree->win,tree->y+k-1,tree->x, s ); } wrefresh(tree->win); tree->col = nscroll; if ( nselect != 0 ) tree->scr_col = nselect; tree->n = j ; return (l);}/*** 生成TREELIST** 目的: 加快屏幕翻滚速度***/generate_treelist( tree )TREE_CONTROL *tree;{ if ( tree->list != (TREE_LIST *)NULL ) free ( tree->list ); tree->list = (TREE_LIST *)malloc( (tree->num) * sizeof( TREE_LIST ) ); tree->i = 0; CXH = 0; if ( tree->startitem == NULL ) return (0); add_tree_list( tree, tree->startitem ); /*** 递归调用 ***/ return (1);}/*** 生成相同层的TREELIST** 目的: 递归调用 */add_tree_list( tree, clink )TREE_CONTROL *tree;TREE_ITEM *clink;{ TREE_ITEM * item; item = clink; while(1){ tree->i ++; tree->list[tree->i-1].level = item->level; tree->list[tree->i-1].item = item; if ( item->openflag == 1 ) { CXH ++; tree->list[tree->i-1].visible = 1; tree->list[tree->i-1].xh = CXH; } else { tree->list[tree->i-1].visible = 0; tree->list[tree->i-1].xh = 0; } if (item->nextlevellink != (TREE_ITEM *)NULL ) { add_tree_list( tree, item->nextlevellink ); } if( item->nextlink == (TREE_ITEM *)NULL ) return(0); else item = item ->nextlink; }/* return(0);*/}/***** 扩张 TREE_ITEM ***/expand_tree( tree ) TREE_CONTROL *tree;{ TREE_ITEM *item; int n; int col, scr_col; n = cal_listnum(tree); item = tree->list[n].item->nextlevellink; if ( item == ( TREE_ITEM *)NULL ) { return (0); } while(1) { item->openflag = 1; if ( item->nextlink == (TREE_ITEM *)NULL ) break; item = item->nextlink ; } generate_treelist( tree ); cal_linecol( tree, item->prelevellink ,&col, &scr_col ); show_treecontrol( tree, col, scr_col );}/***** 收缩 TREE_ITEM ***/unexpand_tree( tree ) TREE_CONTROL *tree;{ int n ; int col, scr_col; TREE_ITEM *item; n = cal_listnum(tree); item = tree->list[n].item->prelevellink; if ( item == ( TREE_ITEM *)NULL ) return (0); unexpand_tree_self( item ); generate_treelist( tree ); cal_linecol( tree, item ,&col, &scr_col ); show_treecontrol( tree, col, scr_col );}/***** 收缩 TREE_ITEM 自身***/unexpand_tree_self( item ) TREE_ITEM *item;{ TREE_ITEM *my_item; if ( item == (TREE_ITEM *)NULL ) return(-1); my_item = item->nextlevellink; if ( my_item == (TREE_ITEM *)NULL ) { return(0); } while(1) { my_item->openflag = 0; if ( my_item->nextlevellink != (TREE_ITEM *)NULL ) unexpand_tree_self( my_item ); if ( my_item->nextlink == (TREE_ITEM *)NULL ) return(0); my_item = my_item->nextlink ; }}/* ** 检索整个树,返回(TREE_ITEM *) 静态变量 **/TREE_ITEM *Serach_tree( TREE_CONTROL *tree, TREE_ITEM *item ){ if ( item == NULL ) return tree->startitem; if ( item->nextlevellink != NULL ) return item->nextlevellink; else if ( item->nextlink != NULL ) return item->nextlink; else if ( item->prelevellink != NULL ) return item->prelevellink->nextlink; } /* ** FIND the string in the tree **/TREE_ITEM *Find_tree_str( TREE_CONTROL *tree, char *s ){ TREE_ITEM *item = NULL; while( item = Serach_tree( tree, item ) ) { if ( strstr( item->text , s ) > 0 ) return item; } return (TREE_ITEM *)NULL;} /***** 求出当前TREE_CONTROL的TREE_ITEM*****/TREE_ITEM *Getcuritem( tree ) TREE_CONTROL *tree;{ return (TREE_ITEM *)(tree->list[cal_listnum( tree )].item);}/***** 求出当前TREE_CONTROL是第几行( LIST[n] )*****/int cal_listnum( tree ) TREE_CONTROL *tree;{ int n = 0 ,i = 0 ; while(1){ if ( tree->list[i].visible == 1 ) { n++; } if ( n >= tree->col + tree->scr_col - 1 ) break; i ++; } return (i);} END:tool1.cBEGIN:apmenu.h/***** APMENU.H 1998/11*****/#include "view.h"#define Key_up 65#define Key_down 66#define Key_left 68#define Key_right 67#define Key_ctrl_up 56#define Key_ctrl_down 50#define Key_ctrl_left 52#define Key_ctrl_right 54#define Key_esc 27#define Key_enter 13#define Key_nxtrow 10#define Key_space 32#define Key_backspace 8#define Key_end 70#define Key_f1 77#define Key_pagedown 71#define Key_home 72#define Key_pageup 73#define Key_tab 9 #define Max_y 23 #define Max_x 80 #define Min(a,b) (((a)<(b))?(a):(b))#define Max(a,b) (((a)>(b))?(a):(b))#define strmove(s1,s2,nmove) ( (strncpy( s1, s2, nmove )), (s1[nmove] = '\0') )#define LS_FC LT_WHITE /***** 子菜单:选中项FONTCOLOR*******/ #define LS_BC RED /***** 子菜单:选中项BACKCOLOR*******/ #define L_FC BLUE /***** 子菜单:非选中项FONTCOLOR*****/ #define L_BC WHITE /***** 子菜单:非选中项BACKCOLOR*****/ #define MS_FC BLUE /***** 主菜单:选中项FONTCOLOR*******/ #define MS_BC CYAN /***** 主菜单:选中项BACKCOLOR*******/ #define M_FC LT_WHITE /***** 主菜单:非选中项FONTCOLOR*****/ #define M_BC BLUE /***** 主菜单:非选中项BACKCOLOR*****/ #define MENUSHADOW 0 /***** 子菜单:SHOW THE SHADOW*******/ struct save_scr{ int height,width; int *p; };typedef struct save_scr SAVESCR;extern struct menu_item_code { int level; char code[5]; char *itemname; char *acckey; } ;typedef struct menu_item_code MENU_ITEM;struct menu_code_proc { char code[5]; int (*itemproc)(); } ;typedef struct menu_code_proc MENU_PROC;#define TREE_TEXT_LEN 64#define TREE_TOPIC_LEN 64struct tree_item { /****树形结构链表*********/ int level; bool openflag; char text[TREE_TEXT_LEN]; /********显示内容*********/ void *link; /**** 附信息指针 *********/ struct tree_item *nextlink; struct tree_item *prelink; struct tree_item *nextlevellink; /****下层TREE_ITEM链首****/ struct tree_item *prelevellink; /****下层TREE_ITEM链首****/};typedef struct tree_item TREE_ITEM;struct tree_control_list { /*树形控件的屏幕显示列表**/ int xh; /*****顺序显示的序号******/ int level; /******** 级 别 **********/ int visible; /********显示标志*********/ struct tree_item *item; /********对应的链表*******/};typedef struct tree_control_list TREE_LIST;#define MAX_LIST_NUM 1024 /***每个控件允许LIST个数**/struct tree_control { /*******树形结构控件******/ WINDOW *win; /******** WINDOW ********/ int y; /******** y point ********/ int x; /******** x point ********/ int h; /******** height ********/ int w; /******** width ********/ int bk_color; /******非选中背景色*******/ int fn_color; /******非选中前景色*******/ int sebk_color; /****** 选中背景色 *******/ int sefn_color; /****** 选中前景色 *******/ int cur_col; /*** 当前的是第几条LIST***/ int col; /*** 从第几行开始显示 ****/ int scr_col; /*** 显示屏幕的当前行 ****/ int n; /*** 可显示的LIST个数 ****/ int i; /****** 生成LIST个数 *****/ int num; /********ITEM个数*********/ struct tree_item *startitem; /**********链首***********/ struct tree_item *curitem; /********当前链表*********/ struct tree_control_list *list; /********LIST数组*********/ int (*enterproc)(); int (*moveproc)(); int (*keydownproc)(); };typedef struct tree_control TREE_CONTROL;END:apmenu.h
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -