/* * 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 allows the person to use the widget's data field. */ unsigned activateCDKUScale (CDKUSCALE *widget, chtype *actions) { unsigned ret; /* Draw the widget. */ drawCDKUScale (widget, ObjOf(widget)->box); if (actions == 0) { chtype input = 0; boolean functionKey; for (;;) { input = getchCDKObject (ObjOf(widget), &functionKey); /* Inject the character into the widget. */ ret = injectCDKUScale (widget, input); if (widget->exitType != vEARLY_EXIT) { return ret; } } } else { int length = chlen (actions); int x = 0; /* Inject each character one at a time. */ for (x=0; x < length; x++) { ret = injectCDKUScale (widget, actions[x]); if (widget->exitType != vEARLY_EXIT) { return ret; } } } /* Set the exit type and return. */ setExitType(widget, 0); return unknownUnsigned; }
/* * This actually does all the 'real' work of managing the scrolling list. */ int activateCDKScroll (CDKSCROLL *scrollp, chtype *actions) { /* Draw the scrolling list */ drawCDKScroll (scrollp, ObjOf (scrollp)->box); if (actions == 0) { chtype input; boolean functionKey; int ret; for (;;) { fixCursorPosition (scrollp); input = (chtype)getchCDKObject (ObjOf (scrollp), &functionKey); /* Inject the character into the widget. */ ret = injectCDKScroll (scrollp, input); if (scrollp->exitType != vEARLY_EXIT) { return ret; } } } else { int length = chlen (actions); int i = 0; int ret; /* Inject each character one at a time. */ for (i = 0; i < length; i++) { ret = injectCDKScroll (scrollp, actions[i]); if (scrollp->exitType != vEARLY_EXIT) return ret; } } /* Set the exit type for the widget and return. */ setExitType (scrollp, 0); return -1; }
/* * This was added for the builder. */ int activateCDKButton (CDKBUTTON *button, chtype *actions) { chtype input = 0; boolean functionKey; int ret; drawCDKButton (button, ObjOf (button)->box); if (actions == 0) { for (;;) { input = (chtype)getchCDKObject (ObjOf (button), &functionKey); /* Inject the character into the widget. */ ret = injectCDKButton (button, input); if (button->exitType != vEARLY_EXIT) { return ret; } } } else { int length = chlen (actions); int x = 0; /* Inject each character one at a time. */ for (x = 0; x < length; x++) { ret = injectCDKButton (button, actions[x]); if (button->exitType != vEARLY_EXIT) { return ret; } } } /* Set the exit type and exit. */ setExitType (button, 0); return -1; }
int main (void) { /* *INDENT-EQLS* */ CDKSCREEN *cdkscreen = 0; CDKLABEL *stopSign = 0; CDKLABEL *title = 0; const char *mesg[5]; const char *sign[4]; chtype key; boolean functionKey; cdkscreen = initCDKScreen (NULL); /* Start CDK Colors. */ initCDKColor (); /* Set the labels up. */ mesg[0] = "<C><#HL(40)>"; mesg[1] = "<C>Press </B/16>r<!B!16> for the </B/16>red light"; mesg[2] = "<C>Press </B/32>y<!B!32> for the </B/32>yellow light"; mesg[3] = "<C>Press </B/24>g<!B!24> for the </B/24>green light"; mesg[4] = "<C><#HL(40)>"; sign[0] = " <#DI> "; sign[1] = " <#DI> "; sign[2] = " <#DI> "; /* Declare the labels. */ title = newCDKLabel (cdkscreen, CENTER, TOP, (CDK_CSTRING2) mesg, 5, FALSE, FALSE); stopSign = newCDKLabel (cdkscreen, CENTER, CENTER, (CDK_CSTRING2) sign, 3, TRUE, TRUE); /* Do this until they hit q or escape. */ for (;;) { drawCDKLabel (title, FALSE); drawCDKLabel (stopSign, TRUE); key = (chtype)getchCDKObject (ObjOf (stopSign), &functionKey); if (key == KEY_ESC || key == 'q' || key == 'Q') { break; } else if (key == 'r' || key == 'R') { sign[0] = " </B/16><#DI> "; sign[1] = " o "; sign[2] = " o "; } else if (key == 'y' || key == 'Y') { sign[0] = " o "; sign[1] = " </B/32><#DI> "; sign[2] = " o "; } else if (key == 'g' || key == 'G') { sign[0] = " o "; sign[1] = " o "; sign[2] = " </B/24><#DI> "; } /* Set the contents of the label and re-draw it. */ setCDKLabel (stopSign, (CDK_CSTRING2) sign, 3, TRUE); } /* Clean up. */ destroyCDKLabel (title); destroyCDKLabel (stopSign); destroyCDKScreen (cdkscreen); endCDK (); ExitProgram (EXIT_SUCCESS); }
/* * 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 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; } } }