/* * This pops up a message. */ void popupLabelAttrib (CDKSCREEN *screen, char **mesg, int count, chtype attrib) { CDKLABEL *popup = 0; int oldCursState; boolean functionKey; /* Create the label. */ popup = newCDKLabel (screen, CENTER, CENTER, mesg, count, TRUE, FALSE); setCDKLabelBackgroundAttrib(popup, attrib); oldCursState = curs_set(0); /* Draw it on the screen. */ drawCDKLabel (popup, TRUE); /* Wait for some input. */ keypad (popup->win, TRUE); getchCDKObject (ObjOf(popup), &functionKey); /* Kill it. */ destroyCDKLabel (popup); /* Clean the screen. */ curs_set(oldCursState); eraseCDKScreen (screen); refreshCDKScreen (screen); }
/* * This pops up a dialog box. */ int popupDialog (CDKSCREEN *screen, CDK_CSTRING2 mesg, int mesgCount, CDK_CSTRING2 buttons, int buttonCount) { /* Declare local variables. */ CDKDIALOG *popup = 0; int choice; /* Create the dialog box. */ popup = newCDKDialog (screen, CENTER, CENTER, mesg, mesgCount, buttons, buttonCount, A_REVERSE, TRUE, TRUE, FALSE); /* Activate the dialog box */ drawCDKDialog (popup, TRUE); /* Get the choice. */ choice = activateCDKDialog (popup, 0); /* Destroy the dialog box. */ destroyCDKDialog (popup); /* Clean the screen. */ eraseCDKScreen (screen); refreshCDKScreen (screen); /* Return the choice. */ return choice; }
/* * This injects a single character into the widget. */ static int _injectCDKButton (CDKOBJS *object, chtype input) { CDKBUTTON *widget = (CDKBUTTON *)object; int ret = unknownInt; bool complete = FALSE; setExitType (widget, 0); /* Check a predefined binding. */ if (checkCDKObjectBind (vBUTTON, widget, input) != 0) { checkEarlyExit (widget); complete = TRUE; } else { switch (input) { case KEY_ESC: setExitType (widget, input); complete = TRUE; break; case KEY_ERROR: setExitType (widget, input); complete = TRUE; break; case KEY_ENTER: case SPACE: if (widget->callback) widget->callback (widget); setExitType (widget, KEY_ENTER); ret = 0; complete = TRUE; break; case CDK_REFRESH: eraseCDKScreen (ScreenOf (widget)); refreshCDKScreen (ScreenOf (widget)); break; default: BEEP (); break; } } if (!complete) { setExitType (widget, 0); } ResultOf (widget).valueInt = ret; return (ret != unknownInt); }
/* * This function allows the user to dump the * information from the viewer into a file. */ static void saveInformation (CDKVIEWER *widget) { /* Declare local variables. */ CDKENTRY *entry = 0; char *filename = 0; char temp[256], *mesg[10]; int linesSaved; /* Create the entry field to get the filename. */ entry = newCDKEntry (ScreenOf(widget), CENTER, CENTER, "<C></B/5>Enter the filename of the save file.", "Filename: ", A_NORMAL, '_', vMIXED, 20, 1, 256, TRUE, FALSE); /* Get the filename. */ filename = activateCDKEntry (entry, 0); /* Did they hit escape? */ if (entry->exitType == vESCAPE_HIT) { /* Popup a message. */ mesg[0] = "<C></B/5>Save Canceled."; mesg[1] = "<C>Escape hit. Scrolling window information not saved."; mesg[2] = " "; mesg[3] = "<C>Press any key to continue."; popupLabel (ScreenOf(widget), mesg, 4); destroyCDKEntry (entry); return; } /* Write the contents of the viewer to the file. */ linesSaved = dumpViewer (widget, filename); /* Was the save successful? */ if (linesSaved == -1) { /* Nope, tell 'em. */ mesg[0] = "<C></B/16>Error"; mesg[1] = "<C>Could not save to the file."; sprintf (temp, "<C>(%s)", filename); mesg[2] = copyChar (temp); mesg[3] = " "; mesg[4] = "<C>Press any key to continue."; popupLabel (ScreenOf(widget), mesg, 5); freeChar (mesg[2]); } else { mesg[0] = "<C></B/5>Save Successful"; sprintf (temp, "<C>There were %d lines saved to the file", linesSaved); mesg[1] = copyChar (temp); sprintf (temp, "<C>(%s)", filename); mesg[2] = copyChar (temp); mesg[3] = " "; mesg[4] = "<C>Press any key to continue."; popupLabel (ScreenOf(widget), mesg, 5); freeChar (mesg[1]); freeChar (mesg[2]); } destroyCDKEntry (entry); eraseCDKScreen (ScreenOf(widget)); drawCDKScreen (ScreenOf(widget)); }
/* * This allows the user to use the cursor keys to adjust the * position of the widget. */ void positionCDKButton (CDKBUTTON *button) { /* Declare some variables. */ int origX = getbegx (button->win); int origY = getbegy (button->win); chtype key = (chtype)0; boolean functionKey; /* Let them move the widget around until they hit return. */ while (key != KEY_ENTER) { key = (chtype)getchCDKObject (ObjOf (button), &functionKey); if (key == KEY_UP || key == '8') { if (getbegy (button->win) > 0) { moveCDKButton (button, 0, -1, TRUE, TRUE); } else { BEEP (); } } else if (key == KEY_DOWN || key == '2') { if (getbegy (button->win) + getmaxy (button->win) < getmaxy (WindowOf (button)) - 1) { moveCDKButton (button, 0, 1, TRUE, TRUE); } else { BEEP (); } } else if (key == KEY_LEFT || key == '4') { if (getbegx (button->win) > 0) { moveCDKButton (button, -1, 0, TRUE, TRUE); } else { BEEP (); } } else if (key == KEY_RIGHT || key == '6') { if (getbegx (button->win) + getmaxx (button->win) < getmaxx (WindowOf (button)) - 1) { moveCDKButton (button, 1, 0, TRUE, TRUE); } else { BEEP (); } } else if (key == '7') { if (getbegy (button->win) > 0 && getbegx (button->win) > 0) { moveCDKButton (button, -1, -1, TRUE, TRUE); } else { BEEP (); } } else if (key == '9') { if (getbegx (button->win) + getmaxx (button->win) < getmaxx (WindowOf (button)) - 1 && getbegy (button->win) > 0) { moveCDKButton (button, 1, -1, TRUE, TRUE); } else { BEEP (); } } else if (key == '1') { if (getbegx (button->win) > 0 && getbegx (button->win) + getmaxx (button->win) < getmaxx (WindowOf (button)) - 1) { moveCDKButton (button, -1, 1, TRUE, TRUE); } else { BEEP (); } } else if (key == '3') { if (getbegx (button->win) + getmaxx (button->win) < getmaxx (WindowOf (button)) - 1 && getbegy (button->win) + getmaxy (button->win) < getmaxy (WindowOf (button)) - 1) { moveCDKButton (button, 1, 1, TRUE, TRUE); } else { BEEP (); } } else if (key == '5') { moveCDKButton (button, CENTER, CENTER, FALSE, TRUE); } else if (key == 't') { moveCDKButton (button, getbegx (button->win), TOP, FALSE, TRUE); } else if (key == 'b') { moveCDKButton (button, getbegx (button->win), BOTTOM, FALSE, TRUE); } else if (key == 'l') { moveCDKButton (button, LEFT, getbegy (button->win), FALSE, TRUE); } else if (key == 'r') { moveCDKButton (button, RIGHT, getbegy (button->win), FALSE, TRUE); } else if (key == 'c') { moveCDKButton (button, CENTER, getbegy (button->win), FALSE, TRUE); } else if (key == 'C') { moveCDKButton (button, getbegx (button->win), CENTER, FALSE, TRUE); } else if (key == CDK_REFRESH) { eraseCDKScreen (ScreenOf (button)); refreshCDKScreen (ScreenOf (button)); } else if (key == KEY_ESC) { moveCDKButton (button, origX, origY, FALSE, TRUE); } else if (key != KEY_ENTER) { BEEP (); } } }
/* * This function injects a single character into the widget. */ float injectCDKFScale (CDKFSCALE *scale, chtype input) { /* Declare some local variables. */ int ppReturn = 1; /* Set the exit type. */ scale->exitType = vEARLY_EXIT; /* Draw the field. */ drawCDKFScaleField (scale); /* Check if there is a pre-process function to be called. */ if (scale->preProcessFunction != 0) { /* Call the pre-process function. */ ppReturn = scale->preProcessFunction (vFSCALE, scale, scale->preProcessData, input); } /* Should we continue? */ if (ppReturn != 0) { /* Check for a key binding. */ if (checkCDKObjectBind(vFSCALE, scale, input) != 0) { scale->exitType = vESCAPE_HIT; return 0.; } else { switch (input) { case KEY_LEFT : case 'd' : case '-' : case KEY_DOWN : if (scale->current > scale->low) { scale->current -= scale->inc; if (scale->current < scale->low) { scale->current = scale->low; } } else { Beep(); } break; case KEY_RIGHT : case 'u' : case '+' : case KEY_UP : if (scale->current < scale->high) { scale->current += scale->inc; if (scale->current > scale->high) { scale->current = scale->high; } } else { Beep(); } break; case KEY_PPAGE : case 'U' : case CONTROL('B') : if ((scale->current + scale->fastinc) <= scale->high) { scale->current += scale->fastinc; } else { Beep(); } break; case KEY_NPAGE : case 'D' : case CONTROL('F') : if ((scale->current - scale->fastinc) >= scale->low) { scale->current -= scale->fastinc; } else { Beep(); } break; case KEY_HOME : case 'g' : case '0' : scale->current = scale->low; break; case KEY_END : case 'G' : case '$' : scale->current = scale->high; break; case KEY_RETURN : case TAB : case KEY_ENTER : scale->exitType = vNORMAL; return (scale->current); case KEY_ESC : scale->exitType = vESCAPE_HIT; return (scale->current); case CDK_REFRESH : eraseCDKScreen (ScreenOf(scale)); refreshCDKScreen (ScreenOf(scale)); break; default : break; } } /* Should we call a post-process? */ if (scale->postProcessFunction != 0) { scale->postProcessFunction (vFSCALE, scale, scale->postProcessData, input); } } /* Draw the field window. */ drawCDKFScaleField (scale); /* Set the exit type and return. */ scale->exitType = vEARLY_EXIT; return 0.; }
/* * This injects a single character into the widget. */ static int _injectCDKScroll (CDKOBJS *object, chtype input) { CDKSCROLL *widget = (CDKSCROLL *)object; int ppReturn = 1; int ret = unknownInt; bool complete = FALSE; /* Set the exit type for the widget. */ setExitType (widget, 0); /* Draw the scrolling list */ drawCDKScrollList (widget, ObjOf (widget)->box); /* Check if there is a pre-process function to be called. */ if (PreProcessFuncOf (widget) != 0) { /* Call the pre-process function. */ ppReturn = PreProcessFuncOf (widget) (vSCROLL, widget, PreProcessDataOf (widget), input); } /* Should we continue? */ if (ppReturn != 0) { /* Check for a predefined key binding. */ if (checkCDKObjectBind (vSCROLL, widget, input) != 0) { checkEarlyExit (widget); complete = TRUE; } else { switch (input) { case KEY_UP: scroller_KEY_UP (widget); break; case KEY_DOWN: scroller_KEY_DOWN (widget); break; case KEY_RIGHT: scroller_KEY_RIGHT (widget); break; case KEY_LEFT: scroller_KEY_LEFT (widget); break; case KEY_PPAGE: scroller_KEY_PPAGE (widget); break; case KEY_NPAGE: scroller_KEY_NPAGE (widget); break; case KEY_HOME: scroller_KEY_HOME (widget); break; case KEY_END: scroller_KEY_END (widget); break; case '$': widget->leftChar = widget->maxLeftChar; break; case '|': widget->leftChar = 0; break; case KEY_ESC: setExitType (widget, input); complete = TRUE; break; case KEY_ERROR: setExitType (widget, input); complete = TRUE; break; case CDK_REFRESH: eraseCDKScreen (ScreenOf (widget)); refreshCDKScreen (ScreenOf (widget)); break; case KEY_TAB: case KEY_ENTER: setExitType (widget, input); ret = widget->currentItem; complete = TRUE; break; default: break; } } /* Should we call a post-process? */ if (!complete && (PostProcessFuncOf (widget) != 0)) { PostProcessFuncOf (widget) (vSCROLL, widget, PostProcessDataOf (widget), input); } } if (!complete) { drawCDKScrollList (widget, ObjOf (widget)->box); setExitType (widget, 0); } fixCursorPosition (widget); ResultOf (widget).valueInt = ret; return (ret != unknownInt); }
int main (int argc, char **argv) { /* *INDENT-EQLS* */ CDKSCREEN *cdkscreen = 0; CDKMENTRY *widget = 0; char *info = 0; const char *label = "</R>Message"; const char *title = "<C></5>Enter a message (\".\" to exit).<!5>\n" "<C>It can be </3>multi<!3>-line!"; int boxWidth; CDK_PARAMS params; CDKparseParams (argc, argv, ¶ms, "w:h:l:" CDK_MIN_PARAMS); cdkscreen = initCDKScreen (NULL); /* Start CDK Colors. */ initCDKColor (); /* Set up the multi-line entry field. */ boxWidth = CDKparamValue (¶ms, 'w', 40); widget = newCDKMentry (cdkscreen, CDKparamValue (¶ms, 'X', CENTER), CDKparamValue (¶ms, 'Y', CENTER), title, label, A_BOLD, '.', vMIXED, boxWidth, CDKparamValue (¶ms, 'h', 5), CDKparamValue (¶ms, 'l', 20), 0, CDKparamValue (¶ms, 'N', TRUE), CDKparamValue (¶ms, 'S', FALSE)); /* Is the object null? */ if (widget == 0) { /* Shut down CDK. */ destroyCDKScreen (cdkscreen); endCDK (); printf ("Cannot create CDK object. Is the window too small?\n"); ExitProgram (EXIT_FAILURE); } refreshCDKScreen (cdkscreen); for (;;) { info = getCdkTitle (ObjOf (widget)); setCDKMentry (widget, info, 0, TRUE); free (info); activateCDKMentry (widget, 0); if (strlen (widget->info) > 1) { setCdkTitle (ObjOf (widget), widget->info, getmaxx (widget->win)); eraseCDKScreen (ScreenOf (widget)); drawCDKScreen (ScreenOf (widget)); } else { break; } } destroyCDKMentry (widget); destroyCDKScreen (cdkscreen); endCDK (); ExitProgram (EXIT_SUCCESS); }
/* * This function injects a single character into the widget. */ static int _injectCDKUScale (CDKOBJS *object, chtype input) { CDKUSCALE *widget = (CDKUSCALE *)object; int ppReturn = 1; unsigned ret = unknownUnsigned; bool complete = FALSE; /* Set the exit type. */ setExitType(widget, 0); /* Draw the field. */ drawCDKUScaleField (widget); /* Check if there is a pre-process function to be called. */ if (PreProcessFuncOf(widget) != 0) { /* Call the pre-process function. */ ppReturn = PreProcessFuncOf(widget) (vUSCALE, widget, PreProcessDataOf(widget), input); } /* Should we continue? */ if (ppReturn != 0) { /* Check for a key binding. */ if (checkCDKObjectBind(vUSCALE, widget, input) != 0) { checkEarlyExit(widget); complete = TRUE; } else { switch (input) { case KEY_LEFT : setEditPosition(widget, widget->fieldEdit + 1); break; case KEY_RIGHT : setEditPosition(widget, widget->fieldEdit - 1); break; case KEY_DOWN : Decrement(widget->current, widget->inc); break; case KEY_UP : Increment(widget->current, widget->inc); break; case KEY_PPAGE : Increment(widget->current, widget->fastinc); break; case KEY_NPAGE : Decrement(widget->current, widget->fastinc); break; case KEY_HOME : widget->current = widget->low; break; case KEY_END : widget->current = widget->high; break; case KEY_TAB : case KEY_ENTER : setExitType(widget, input); ret = (widget->current); complete = TRUE; break; case KEY_ESC : setExitType(widget, input); complete = TRUE; break; case CDK_REFRESH : eraseCDKScreen (ScreenOf(widget)); refreshCDKScreen (ScreenOf(widget)); break; default : if (widget->fieldEdit) { if (!performEdit(widget, input)) BEEP(); } else { /* * The cursor is not within the editable text. Interpret * input as commands. */ switch (input) { case 'd': case '-': return _injectCDKUScale(object, KEY_DOWN); case '+': return _injectCDKUScale(object, KEY_UP); case 'D': return _injectCDKUScale(object, KEY_NPAGE); case '0': return _injectCDKUScale(object, KEY_HOME); default: BEEP(); break; } } break; } } limitCurrentValue(widget); /* Should we call a post-process? */ if (!complete && (PostProcessFuncOf(widget) != 0)) { PostProcessFuncOf(widget) (vUSCALE, widget, PostProcessDataOf(widget), input); } } if (!complete) { drawCDKUScaleField (widget); setExitType(widget, 0); } ResultOf(widget).valueUnsigned = ret; return (ret != unknownUnsigned); }
/* * This allows the user to use the cursor keys to adjust the * position of the widget. */ void positionCDKObject (CDKOBJS *obj, WINDOW *win) { /* *INDENT-EQLS* */ CDKSCREEN *screen = ScreenOf (obj); WINDOW *parent = screen->window; int origX = getbegx (win); int origY = getbegy (win); int begX = getbegx (parent); int begY = getbegy (parent); int endX = begX + getmaxx (WindowOf (obj)); int endY = begY + getmaxy (WindowOf (obj)); chtype key; boolean functionKey; /* Let them move the widget around until they hit return. */ while ((key = (chtype)getchCDKObject (obj, &functionKey)) != KEY_ENTER) { switch (key) { case KEY_UP: case '8': if (getbegy (win) > begY) { moveCDKObject (obj, 0, -1, TRUE, TRUE); } else { BEEP (); } break; case KEY_DOWN: case '2': if (getendy (win) < endY) { moveCDKObject (obj, 0, 1, TRUE, TRUE); } else { BEEP (); } break; case KEY_LEFT: case '4': if (getbegx (win) > begX) { moveCDKObject (obj, -1, 0, TRUE, TRUE); } else { BEEP (); } break; case KEY_RIGHT: case '6': if (getendx (win) < endX) { moveCDKObject (obj, 1, 0, TRUE, TRUE); } else { BEEP (); } break; case '7': if (getbegy (win) > begY && getbegx (win) > begX) { moveCDKObject (obj, -1, -1, TRUE, TRUE); } else { BEEP (); } break; case '9': if (getendx (win) < endX && getbegy (win) > begY) { moveCDKObject (obj, 1, -1, TRUE, TRUE); } else { BEEP (); } break; case '1': if (getbegx (win) > begX && getendy (win) < endY) { moveCDKObject (obj, -1, 1, TRUE, TRUE); } else { BEEP (); } break; case '3': if (getendx (win) < endX && getendy (win) < endY) { moveCDKObject (obj, 1, 1, TRUE, TRUE); } else { BEEP (); } break; case '5': moveCDKObject (obj, CENTER, CENTER, FALSE, TRUE); break; case 't': moveCDKObject (obj, getbegx (win), TOP, FALSE, TRUE); break; case 'b': moveCDKObject (obj, getbegx (win), BOTTOM, FALSE, TRUE); break; case 'l': moveCDKObject (obj, LEFT, getbegy (win), FALSE, TRUE); break; case 'r': moveCDKObject (obj, RIGHT, getbegy (win), FALSE, TRUE); break; case 'c': moveCDKObject (obj, CENTER, getbegy (win), FALSE, TRUE); break; case 'C': moveCDKObject (obj, getbegx (win), CENTER, FALSE, TRUE); break; case CDK_REFRESH: eraseCDKScreen (ScreenOf (obj)); refreshCDKScreen (ScreenOf (obj)); break; case KEY_ESC: moveCDKObject (obj, origX, origY, FALSE, TRUE); break; default: BEEP (); break; } } }
/* * This injects a single character into the dialog widget. */ int injectCDKDialog (CDKDIALOG *dialog, chtype input) { int firstButton = 0; int lastButton = dialog->buttonCount - 1; int ppReturn = 1; /* Set the exit type. */ dialog->exitType = vEARLY_EXIT; /* Check if there is a pre-process function to be called. */ if (dialog->preProcessFunction != 0) { ppReturn = dialog->preProcessFunction (vDIALOG, dialog, dialog->preProcessData, input); } /* Should we continue? */ if (ppReturn != 0) { /* Check for a key binding. */ if (checkCDKObjectBind (vDIALOG, dialog, input) != 0) { dialog->exitType = vESCAPE_HIT; return -1; } else { switch (input) { case KEY_LEFT : case CDK_PREV : if (dialog->currentButton == firstButton) { dialog->currentButton = lastButton;; } else { dialog->currentButton--; } break; case KEY_RIGHT : case CDK_NEXT : case KEY_TAB : case ' ' : if (dialog->currentButton == lastButton) { dialog->currentButton = firstButton; } else { dialog->currentButton++; } break; case KEY_UP : case KEY_DOWN : Beep(); break; case CDK_REFRESH : eraseCDKScreen (ScreenOf(dialog)); refreshCDKScreen (ScreenOf(dialog)); break; case KEY_ESC : dialog->exitType = vESCAPE_HIT; return -1; case KEY_RETURN : case KEY_ENTER : dialog->exitType = vNORMAL; return dialog->currentButton; default : break; } } /* Should we call a post-process? */ if (dialog->postProcessFunction != 0) { dialog->postProcessFunction (vDIALOG, dialog, dialog->postProcessData, input); } } /* Redraw the buttons. */ drawCDKDialogButtons (dialog); wrefresh (dialog->win); /* Exit the dialog box. */ dialog->exitType = vEARLY_EXIT; return -1; }