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

📄 menu.c

📁 linux内核
💻 C
📖 第 1 页 / 共 3 页
字号:
  if (inactivenormal != 0xFF)   ms->inactattr[0]    = inactivenormal;  if (inactiveselected != 0xFF) ms->revinactattr[0] = inactiveselected;}void set_normal_hlite(uchar normal, uchar selected, uchar inactivenormal, uchar inactiveselected){  if (normal != 0xFF)           ms->normalattr[1]   = normal;  if (selected != 0xFF)         ms->reverseattr[1]  = selected;  if (inactivenormal != 0xFF)   ms->inactattr[1]    = inactivenormal;  if (inactiveselected != 0xFF) ms->revinactattr[1] = inactiveselected;}void set_status_info(uchar statusattr, uchar statushlite, uchar statline){  if (statusattr != 0xFF) ms->statusattr[NOHLITE] = statusattr;  if (statushlite!= 0xFF) ms->statusattr[HLITE] = statushlite;  // statline is relative to minrow  if (statline >= ms->numrows) statline = ms->numrows - 1;  ms->statline = statline; // relative to ms->minrow, 0 based}void set_title_info(uchar tfillchar, uchar titleattr){  if (tfillchar  != 0xFF) ms->tfillchar  = tfillchar;  if (titleattr  != 0xFF) ms->titleattr  = titleattr;}void set_misc_info(uchar fillchar, uchar fillattr,uchar spacechar, uchar shadowattr){  if (fillchar  != 0xFF) ms->fillchar  = fillchar;  if (fillattr  != 0xFF) ms->fillattr  = fillattr;  if (spacechar != 0xFF) ms->spacechar = spacechar;  if (shadowattr!= 0xFF) ms->shadowattr= shadowattr;}void set_box_type(boxtype bt){  uchar *bxc;  ms->menubt = bt;  bxc = getboxchars(bt);  ms->box_horiz = bxc[BOX_HORIZ]; // The char used to draw top line  ms->box_ltrt = bxc[BOX_LTRT];   ms->box_rtlt = bxc[BOX_RTLT]; }void set_menu_options(uchar maxmenuheight) {  if (maxmenuheight != 0xFF) ms->maxmenuheight = maxmenuheight;}// Set the window which menusystem should usevoid set_window_size(uchar top, uchar left, uchar bot, uchar right) {      uchar nr,nc;  if ((top > bot) || (left > right)) return; // Sorry no change will happen here  nr = getnumrows();  nc = getnumcols();  if (bot >= nr) bot = nr-1;  if (right >= nc) right = nc-1;  ms->minrow = top;  ms->mincol = left;  ms->maxrow = bot;  ms->maxcol = right;  ms->numcols = right - left + 1;  ms->numrows = bot - top + 1;  if (ms->statline >= ms->numrows) ms->statline = ms->numrows - 1; // Clip statline if need be}void reg_handler( t_handler htype, void * handler){  // If bad value set to default screen handler  switch(htype) {    case HDLR_KEYS:         ms->keys_handler = (t_keys_handler) handler;         break;    default:         ms->handler = (t_menusystem_handler) handler;         break;  }}void unreg_handler(t_handler htype){  switch(htype) {    case HDLR_KEYS:         ms->keys_handler = NULL;         break;    default:         ms->handler = NULL;         break;  }}void reg_ontimeout(t_timeout_handler handler, unsigned int numsteps, unsigned int stepsize){  ms->ontimeout = handler;  if (numsteps != 0) ms->tm_numsteps = numsteps;  if (stepsize != 0) ms->tm_stepsize = stepsize;}void unreg_ontimeout(){  ms->ontimeout = NULL;}int next_visible(pt_menu menu, int index) {  int ans;  if (index < 0) ans = 0 ;  else if (index >= menu->numitems) ans = menu->numitems-1;  else ans = index;  while ((ans < menu->numitems-1) && 	 ((menu->items[ans]->action == OPT_INVISIBLE) || 	  (menu->items[ans]->action == OPT_SEP)))     ans++;  return ans;}int prev_visible(pt_menu menu, int index) // Return index of prev visible{  int ans;  if (index < 0) ans = 0;  else if (index >= menu->numitems) ans = menu->numitems-1;  else ans = index;  while ((ans > 0) && 	 ((menu->items[ans]->action == OPT_INVISIBLE) ||	  (menu->items[ans]->action == OPT_SEP)))     ans--;  return ans;}int next_visible_sep(pt_menu menu, int index) {  int ans;  if (index < 0) ans = 0 ;  else if (index >= menu->numitems) ans = menu->numitems-1;  else ans = index;  while ((ans < menu->numitems-1) && 	 (menu->items[ans]->action == OPT_INVISIBLE))      ans++;  return ans;}int prev_visible_sep(pt_menu menu, int index) // Return index of prev visible{  int ans;  if (index < 0) ans = 0;  else if (index >= menu->numitems) ans = menu->numitems-1;  else ans = index;  while ((ans > 0) && 	 (menu->items[ans]->action == OPT_INVISIBLE))     ans--;  return ans;}int calc_visible(pt_menu menu,int first){  int ans,i;  if (menu == NULL) return 0;    ans = 0;  for (i=first; i < menu->numitems; i++)    if (menu->items[i]->action != OPT_INVISIBLE) ans++;  return ans;}// is curr visible if first entry is first?int isvisible(pt_menu menu,int first, int curr){  if (curr < first) return 0;  return (calc_visible(menu,first)-calc_visible(menu,curr) < menu->menuheight);}// Calculate the first entry to be displayed// so that curr is visible and make curr as late as possibleint calc_first_late(pt_menu menu,int curr){  int ans,i,nv;  nv = calc_visible(menu,0);  if (nv <= menu->menuheight) return 0;  // Start with curr and go back menu->menuheight times  ans = curr+1;  for (i=0; i < menu->menuheight; i++)    ans = prev_visible_sep(menu,ans-1);  return ans;}// Calculate the first entry to be displayed// so that curr is visible and make curr as early as possibleint calc_first_early(pt_menu menu,int curr){  int ans,i,nv;  nv = calc_visible(menu,0);  if (nv <= menu->menuheight) return 0;  // Start with curr and go back till >= menu->menuheight   // items are visible   nv = calc_visible(menu,curr); // Already nv of them are visible  ans = curr;  for (i=0; i < menu->menuheight - nv; i++)    ans = prev_visible_sep(menu,ans-1);  return ans;}// Create a new menu and return its positionuchar add_menu(const char *title, int maxmenusize) {  int num,i;  pt_menu m;  num = ms->nummenus;  if (num >= MAXMENUS) return -1;  m = NULL;  m = (pt_menu) malloc(sizeof(t_menu));  if (m == NULL) return -1;  ms->menus[num] = m;  m->numitems = 0;  m->row = 0xFF;  m->col = 0xFF;  if (maxmenusize < 1)     m->maxmenusize = MAXMENUSIZE;  else m->maxmenusize = maxmenusize;  m->items = (pt_menuitem *) malloc(sizeof(pt_menuitem)*(m->maxmenusize));  for (i=0; i < m->maxmenusize; i++) m->items[i] = NULL;     m->title = (char *)malloc(MENULEN+1);  if (title)    {      if (strlen(title) > MENULEN - 2)	strcpy(m->title,TITLELONG);      else strcpy(m->title,title);     }  else strcpy(m->title,EMPTYSTR);   m ->menuwidth = strlen(m->title);  ms->nummenus ++;  return ms->nummenus - 1;}void set_menu_pos(uchar row,uchar col) // Set the position of this menu.{  pt_menu m;  m = ms->menus[ms->nummenus-1];  m->row = row;  m->col = col;}pt_menuitem add_sep() // Add a separator to current menu{  pt_menuitem mi;  pt_menu m;  m = (ms->menus[ms->nummenus-1]);  mi = NULL;  mi = (pt_menuitem) malloc(sizeof(t_menuitem));  if (mi == NULL) return NULL;  m->items[(unsigned int)m->numitems] = mi;  mi->handler = NULL; // No handler  mi->item = mi->status = mi->data = NULL;  mi->action = OPT_SEP;  mi->index = m->numitems++;  mi->parindex = ms->nummenus-1;  mi->shortcut = 0;  mi->helpid=0;  return mi;}// Add item to the "current" menupt_menuitem add_item(const char *item, const char *status, t_action action, 		     const char *data, uchar itemdata) {  pt_menuitem mi;  pt_menu m;  const char *str;  uchar inhlite=0; // Are we inside hlite area  m = (ms->menus[ms->nummenus-1]);  mi = NULL;  mi = (pt_menuitem) malloc(sizeof(t_menuitem));  if (mi == NULL) return NULL;  m->items[(unsigned int) m->numitems] = mi;  mi->handler = NULL; // No handler  // Allocate space to store stuff  mi->item = (char *)malloc(MENULEN+1);  mi->status = (char *)malloc(STATLEN+1);  mi->data = (char *)malloc(ACTIONLEN+1);  if (item) {    if (strlen(item) > MENULEN) {      strcpy(mi->item,ITEMLONG);     } else {      strcpy(mi->item,item);     }    if (strlen(mi->item) > m->menuwidth) m->menuwidth = strlen(mi->item);  } else strcpy(mi->item,EMPTYSTR);   if (status) {    if (strlen(status) > STATLEN) {      strcpy(mi->status,STATUSLONG);     } else {      strcpy(mi->status,status);     }  } else strcpy(mi->status,EMPTYSTR);       mi->action=action;  str = mi->item;  mi->shortcut = 0;  mi->helpid = 0xFFFF;  inhlite = 0; // We have not yet seen an ENABLEHLITE char  // Find the first char in [A-Za-z0-9] after ENABLEHLITE and not arg to control char  while (*str)    {      if (*str == ENABLEHLITE) 	{	  inhlite=1;	}      if (*str == DISABLEHLITE)	{	  inhlite = 0;	}      if ( (inhlite == 1) && 	   (((*str >= 'A') && (*str <= 'Z')) || 	    ((*str >= 'a') && (*str <= 'z')) ||	    ((*str >= '0') && (*str <= '9'))))	{	  mi->shortcut=*str;	  break;	}      ++str;    }  if ((mi->shortcut >= 'A') && (mi->shortcut <= 'Z')) // Make lower case    mi->shortcut = mi->shortcut -'A'+'a';  if (data) {    if (strlen(data) > ACTIONLEN) {      strcpy(mi->data,ACTIONLONG);     } else {      strcpy(mi->data,data);     }  } else strcpy(mi->data,EMPTYSTR);  switch (action)    {    case OPT_SUBMENU:      mi->itemdata.submenunum = itemdata;      break;    case OPT_CHECKBOX:      mi->itemdata.checked = itemdata;      break;    case OPT_RADIOMENU:      mi->itemdata.radiomenunum = itemdata;      mi->data = NULL; // No selection made      break;    default: // to keep the compiler happy      break;    }  mi->index = m->numitems++;  mi->parindex = ms->nummenus-1;  return mi;}// Set the shortcut key for the current itemvoid set_item_options(uchar shortcut,int helpid){  pt_menuitem mi;  pt_menu m;  m = (ms->menus[ms->nummenus-1]);   if (m->numitems <= 0) return;  mi = m->items[(unsigned int) m->numitems-1];  if (shortcut != 0xFF) mi->shortcut = shortcut;  if (helpid != 0xFFFF) mi->helpid = helpid;}// Free internal datasutructuresvoid close_menusystem(void){}

⌨️ 快捷键说明

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