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

📄 menu.cpp

📁 串行通信编程源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
int     Menu::DisplaySubMenu(Menu *n,       // entry to highlight
                             Window *w)     // window to display in
{
int  w_row = 1,                             // work row in menu bar
     s_row;                                 // row of selected entry
Menu *m = this;                             // work menu pointer


for (;;)                                    // loop 'til all done
    {
    w->AtSay(1, w_row, " ");                // put some space out

    if (m == n)                             // q. find entry?
        {
        w->DisplayReverse(m->item);         // a. yes .. highlight it
        s_row = w_row;                      // ..and save row number
        }
     else
        w->Display(m->item);                // else .. display normally

    w_row++;                                // next row number

    if ((m = m->next) == 0)                 // q. end of list?
        break;                              // a. yes .. exit loop
    }

return(s_row);                              // return with entry's row

}



/* ******************************************************************** *
 *
 *  DoMenuAction -- process menu entry
 *
 * ******************************************************************** */

int     Menu::DoMenuAction(Menu *m,         // selected menu entry
                           int c, int r)    // column and row
{

c += 2;                                     // new column number
r++;                                        // ..and row number

if (m->sub == 0)                            // q. submenu present?
    {                                       // a. no .. continue
    if (m->fnc != 0)                        // q. function available?
        return((*(m->fnc))(c, r));          // a. yes .. call it
     else
        return(0);                          // else .. just return
    }

 else
    return(m->sub->DisplaySub(c, r));       // else .. do submenu
}



/* ******************************************************************** *
 *
 *  Find -- find a menu entry by key
 *
 * ******************************************************************** */

Menu *Menu::Find(char c)                    // key to search for
{
Menu *m = this;                             // work menu pointer

c = toupper(c);                             // force uppercase search

for (;;)                                    // loop thru the list
    {
    if (toupper(m->key) == c)               // q. find the entry?
        return(m);                          // a. yes .. quit here

    if ((m = m->next) == 0)                 // q. end of list?
        break;                              // a. yes .. exit loop
    }

return(0);                                  // else return empty-handed

}



/* ******************************************************************** *
 *
 *  FindAlt -- find a menu entry by alt character (scan code)
 *
 * ******************************************************************** */

Menu *Menu::FindAlt(char alt_c)             // scan code to search
{
Menu *m = this;                             // work menu pointer


for (;;)                                    // loop thru the list
    {
    if (m->alt_key == alt_c)                // q. find the entry?
        return(m);                          // a. yes .. quit here

    if ((m = m->next) == 0)                 // q. end of list?
        break;                              // a. yes .. exit loop
    }

return(0);                                  // else return empty-handed

}



/* ******************************************************************** *
 *
 *  Left -- find a menu entry's left
 *
 * ******************************************************************** */

Menu *Menu::Left(Menu *m)                   // source menu entry
{
Menu *t = this,                             // target menu pointer
     *last;                                 // last processed entry

for (;;)                                    // loop thru the list
    {
    if (t->next == m)                       // q. find the entry?
        return(t);                          // a. yes .. quit here

    last = t;                               // save last one

    if ((t = t->next) == 0)                 // q. end of list?
        return(last);                       // a. yes .. exit w/last one
    }
}



/* ******************************************************************** *
 *
 *  Right -- find a menu entry's right
 *
 * ******************************************************************** */

Menu *Menu::Right(Menu *m)                  // source menu entry
{

return(m->next ? m->next : this);           // either next or 1st in list

}



/* ******************************************************************** *
 *
 *  MaxWidth -- find the widest menu label
 *
 * ******************************************************************** */

int     Menu::MaxWidth(void)
{
int     x = 0,                              // max width
        w;                                  // working width
Menu   *m = this;                           // work pointer


for (;;)                                    // loop thru the list
    {
    w = strlen(m->item);                    // get length of this entry

    if (x < w)                              // q. find a larger one?
        x = w;                              // a. yes .. save larger

    if ((m = m->next) == 0)                 // q. end of list?
        return(x);                          // a. yes .. exit loop
    }
}



/* ******************************************************************** *
 *
 *  Count -- find the count of menu items
 *
 * ******************************************************************** */

int     Menu::Count(void)
{
int     i;                                  // loop counter
Menu   *m = this;                           // work pointer


for (i = 0; m->next; i++, m = m->next)      // count number of entries
    ;

return(i);                                  // ..and return w/count

}



/* ******************************************************************** *
 *
 *  SetColors -- set global menu colors
 *
 * ******************************************************************** */

void    Menu::SetColors(int cn,             // new normal color combo
                        int cr)             // ..and reverse color combo
{

menu_cn = cn;                               // set up new global
menu_cr = cr;                               // ..color scheme

}



/* ******************************************************************** *
 *
 *  ValidateKey -- validate key for a menu
 *
 * ******************************************************************** */

Menu   *Menu::ValidateKey(int c)            // char to check
{


if (c == 0x100)                             // q. just alt key?
    return(this);                           // a. yes .. use first entry

if (c > 0x100)                              // q. alt key?
    return(FindAlt(c));                     // a. yes .. check alt list
 else
    return(Find(c));                        // else .. check regular list

}



/* ******************************************************************** *
 *
 *  ~Menu -- object destructor
 *
 * ******************************************************************** */

Menu::~Menu()
{

delete item;                                // de-allocate string memory

}



/* ******************************************************************** *
 *
 *  get_key() -- get a key (including function keys)
 *
 * ******************************************************************** */

int     get_key(int alt_key)                // nonzero = allow alt_key
{
static
int     k;                                  // local key variable


if ((k = bioskey(1)) != 0)                  // q. key available?
    {                                       // a. yes .. process it
    if (k == -1)                            // q. control break?
        {
        k = 0;                              // a. yes .. clear key,
        wait(1);                            // ..wait a tick, then return
        }
     else
        {
        k = bioskey(0);                     // else .. get waiting key

        if (NOT (k & 0xff))                 // q. fnc or extended key?
            k = 0x100 + (k >> 8);           // a. yes .. show special key
         else
            k &= 0xff;                      // else .. force regular key
        }
    }
 else if (alt_key &&                        // q. allowing alt key?
         (_bios_keybrd(_KEYBRD_SHIFTSTATUS) // ..and one pressed?
            & 0x08))
    k = 0x100;                              // a. yes .. special key
 else
    k = 0;                                  // else .. nothing available

return(k);                                  // return w/key if available

}



/* ******************************************************************** *
 *
 *  get_scan() -- get scan code for a printable character
 *
 * ******************************************************************** */

char    get_scan(unsigned char c)           // ASCII character to convert
{
static
char    scan_codes[] =                      // scan codes for ! thru ~
    {
    0x02, 0x28, 0x04, 0x05, 0x06, 0x08, 0x28, 0x0a, 0x0b, 0x09, 0x0d,
    0x33, 0x0c, 0x34, 0x35, 0x0b, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
    0x08, 0x09, 0x0a, 0x27, 0x27, 0x33, 0x0d, 0x34, 0x35, 0x03, 0x1e,
    0x30, 0x2e, 0x20, 0x12, 0x21, 0x22, 0x23, 0x17, 0x24, 0x25, 0x26,
    0x32, 0x31, 0x18, 0x19, 0x10, 0x13, 0x1f, 0x14, 0x16, 0x2f, 0x11,
    0x2d, 0x15, 0x2c, 0x1a, 0x2b, 0x1b, 0x07, 0x0c, 0x29, 0x1e, 0x30,
    0x2e, 0x20, 0x12, 0x21, 0x22, 0x23, 0x17, 0x24, 0x25, 0x26, 0x32,
    0x31, 0x18, 0x19, 0x10, 0x13, 0x1f, 0x14, 0x16, 0x2f, 0x11, 0x2d,
    0x15, 0x2c, 0x1a, 0x2b, 0x1b, 0x29
    };

return((c >= '!' && c <= '~') ?             // if valid rtn scan code
            scan_codes[c - '!'] : 0);       // ..else return a zero

}



/* ******************************************************************** *
 *
 *  NotYet -- null routine for incomplete menu entries
 *
 * ******************************************************************** */

int     NotYet(int c, int r)                // column and row of window
{
Window  ny_win(c, r, c + 28, r + 3,         // define not yet window
            menu_cn, menu_cr);              // ..using default colors


ny_win.Open(single_line);                   // open window with a border
ny_win.Display(" ** Not Yet Implemented **" //display the not yet message
               "\n\r"
               " Press any key to continue");

while (NOT get_key(NO_ALT))                 // wait for a key
    ;                                       // ..before closing down

return(0);                                  // return to menu system

}

⌨️ 快捷键说明

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