#include "cdk.h" #ifdef HAVE_XCURSES char *XCursesProgramName="menu_ex"; #endif int displayCallback (EObjectType cdktype, void *object, void *clientData, chtype input); char *menulist[MAX_MENU_ITEMS][MAX_SUB_ITEMS]; char *menuInfo[3][4] = {{"", "This saves the current info.", "This exits the program.", ""}, {"", "This cuts text", "This copies text", "This pastes text"}, {"", "Help for editing", "Help for file management", "Info about the program"}}; /* * This program demonstratres the Cdk menu widget. */ int main (int argc, char **argv) { /* Declare variables. */ CDKSCREEN *cdkscreen = (CDKSCREEN *)NULL; CDKLABEL *infoBox = (CDKLABEL *)NULL; CDKMENU*menu = (CDKMENU *)NULL; WINDOW*cursesWin = (WINDOW *)NULL; int submenusize[3], menuloc[4]; char *mesg[10], temp[256]; int selection; /* Set up CDK. */ cursesWin = initscr(); cdkscreen = initCDKScreen (cursesWin); /* Start CDK color. */ initCDKColor(); /* Set up the menu. */ menulist[0][0] = "File" ; menulist[1][0] = "Edit"; menulist[2][0] = "Help"; menulist[0][1] = "Save" ; menulist[1][1] = "Cut "; menulist[2][1] = "On Edit "; menulist[0][2] = "Exit" ; menulist[1][2] = "Copy"; menulist[2][2] = "On File "; menulist[1][3] = "Paste"; menulist[2][3] = "About..."; submenusize[0] = 3; menuloc[0] = LEFT; submenusize[1] = 4; menuloc[1] = LEFT; submenusize[2] = 4; menuloc[2] = RIGHT; /* Create the label window. */ mesg[0] = " "; mesg[1] = " "; mesg[2] = " "; mesg[3] = " "; infoBox = newCDKLabel (cdkscreen, CENTER, CENTER, mesg, 4, TRUE, TRUE); /* Create the menu. */ menu = newCDKMenu (cdkscreen, menulist, 3, submenusize, menuloc, TOP, A_UNDERLINE, A_REVERSE); /* Create the post process function. */ setCDKMenuPostProcess (menu, displayCallback, infoBox); /* Draw the CDK screen. */ refreshCDKScreen (cdkscreen); /* Activate the menu. */ selection = activateCDKMenu (menu, (chtype *)NULL); /* Determine how the user exitted from the widget. */ if (menu->exitType == vEARLY_EXIT) { mesg[0] = "You hit escape. No menu item was selected."; mesg[1] = "", mesg[2] = "Press any key to continue."; popupLabel (cdkscreen, mesg, 3); } else if (menu->exitType == vNORMAL) { sprintf (temp, "You selected menu #%d, submenu #%d", selection/100, selection%100); mesg[0] = copyChar (temp); mesg[1] = "", mesg[2] = "Press any key to continue."; popupLabel (cdkscreen, mesg, 3); freeChar (mesg[0]); } /* Clean up. */ destroyCDKMenu (menu); destroyCDKLabel (infoBox); destroyCDKScreen (cdkscreen); delwin (cursesWin); endCDK(); exit (0); } /* * This gets called after every movement. */ int displayCallback (EObjectType cdktype, void *object, void *clientData, chtype input) { CDKMENU *menu = (CDKMENU *)object; CDKLABEL *infoBox = (CDKLABEL *)clientData; char *mesg[10]; char temp[256]; /* Recreate the label message. */ sprintf (temp, "Title: %s", menulist[menu->currentTitle][0]); mesg[0] = strdup (temp); sprintf (temp, "Sub-Title: %s", menulist[menu->currentTitle][menu->currentSubtitle+1]); mesg[1] = strdup (temp); mesg[2] = ""; sprintf (temp, "%s", menuInfo[menu->currentTitle][menu->currentSubtitle+1]); mesg[3] = strdup (temp); /* Set the message of the label. */ setCDKLabel (infoBox, mesg, 4, TRUE); drawCDKLabel (infoBox, TRUE); /* Clean up. */ freeChar (mesg[0]); freeChar (mesg[1]); freeChar (mesg[3]); return 0; }