/* * Create a graph widget. */ CDKGRAPH *newCDKGraph (CDKSCREEN *cdkscreen, int xplace, int yplace, int height, int width, const char *title, const char *xtitle, const char *ytitle) { /* *INDENT-EQLS* */ CDKGRAPH *widget = 0; int parentWidth = getmaxx (cdkscreen->window); int parentHeight = getmaxy (cdkscreen->window); int boxWidth = width; int boxHeight = height; int xpos = xplace; int ypos = yplace; if ((widget = newCDKObject (CDKGRAPH, &my_funcs)) == 0) return (0); setCDKGraphBox (widget, FALSE); /* *INDENT-EQLS* */ boxHeight = setWidgetDimension (parentHeight, height, 3); boxWidth = setWidgetDimension (parentWidth, width, 0); boxWidth = setCdkTitle (ObjOf (widget), title, boxWidth); boxHeight += TitleLinesOf (widget); boxWidth = MINIMUM (boxWidth, parentWidth); boxHeight = MINIMUM (boxHeight, parentHeight); /* Rejustify the x and y positions if we need to. */ alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight); /* *INDENT-EQLS* Create the widget pointer. */ ScreenOf (widget) = cdkscreen; widget->parent = cdkscreen->window; widget->win = newwin (boxHeight, boxWidth, ypos, xpos); widget->boxHeight = boxHeight; widget->boxWidth = boxWidth; widget->minx = 0; widget->maxx = 0; widget->xscale = 0; widget->yscale = 0; widget->count = 0; widget->displayType = vLINE; if (widget->win == 0) { destroyCDKObject (widget); return (0); } keypad (widget->win, TRUE); /* Translate the X Axis title char * to a chtype * */ if (xtitle != 0) { widget->xtitle = char2Chtype (xtitle, &widget->xtitleLen, &widget->xtitlePos); widget->xtitlePos = justifyString (widget->boxHeight, widget->xtitleLen, widget->xtitlePos); } else { widget->xtitle = char2Chtype ("<C></5>X Axis", &widget->xtitleLen, &widget->xtitlePos); widget->xtitlePos = justifyString (widget->boxHeight, widget->xtitleLen, widget->xtitlePos); } /* Translate the Y Axis title char * to a chtype * */ if (ytitle != 0) { widget->ytitle = char2Chtype (ytitle, &widget->ytitleLen, &widget->ytitlePos); widget->ytitlePos = justifyString (widget->boxWidth, widget->ytitleLen, widget->ytitlePos); } else { widget->ytitle = char2Chtype ("<C></5>Y Axis", &widget->ytitleLen, &widget->ytitlePos); widget->ytitlePos = justifyString (widget->boxWidth, widget->ytitleLen, widget->ytitlePos); } widget->graphChar = 0; registerCDKObject (cdkscreen, vGRAPH, widget); return (widget); }
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 creates a new scrolling list widget. */ CDKSCROLL *newCDKScroll (CDKSCREEN *cdkscreen, int xplace, int yplace, int splace, int height, int width, const char *title, CDK_CSTRING2 list, int listSize, boolean numbers, chtype highlight, boolean Box, boolean shadow) { /* *INDENT-EQLS* */ CDKSCROLL *scrollp = 0; int parentWidth = getmaxx (cdkscreen->window); int parentHeight = getmaxy (cdkscreen->window); int boxWidth = width; int boxHeight = height; int xpos = xplace; int ypos = yplace; int scrollAdjust = 0; int x; /* *INDENT-OFF* */ static const struct { int from; int to; } bindings[] = { { CDK_BACKCHAR, KEY_PPAGE }, { CDK_FORCHAR, KEY_NPAGE }, { 'g', KEY_HOME }, { '1', KEY_HOME }, { 'G', KEY_END }, { '<', KEY_HOME }, { '>', KEY_END }, }; /* *INDENT-ON* */ if ((scrollp = newCDKObject (CDKSCROLL, &my_funcs)) == 0) { destroyCDKObject (scrollp); return (0); } setCDKScrollBox (scrollp, Box); /* * If the height is a negative value, the height will * be ROWS-height, otherwise, the height will be the * given height. */ boxHeight = setWidgetDimension (parentHeight, height, 0); /* * If the width is a negative value, the width will * be COLS-width, otherwise, the width will be the * given width. */ boxWidth = setWidgetDimension (parentWidth, width, 0); boxWidth = setCdkTitle (ObjOf (scrollp), title, boxWidth); /* Set the box height. */ if (TitleLinesOf (scrollp) > boxHeight) { boxHeight = (TitleLinesOf (scrollp) + MINIMUM (listSize, 8) + 2 * BorderOf (scrollp)); } /* Adjust the box width if there is a scrollp bar. */ if ((splace == LEFT) || (splace == RIGHT)) { scrollp->scrollbar = TRUE; boxWidth += 1; } else { scrollp->scrollbar = FALSE; } /* * Make sure we didn't extend beyond the dimensions of the window. */ scrollp->boxWidth = (boxWidth > parentWidth ? (parentWidth - scrollAdjust) : boxWidth); scrollp->boxHeight = (boxHeight > parentHeight ? parentHeight : boxHeight); setViewSize (scrollp, listSize); /* Rejustify the x and y positions if we need to. */ alignxy (cdkscreen->window, &xpos, &ypos, scrollp->boxWidth, scrollp->boxHeight); /* Make the scrolling window */ scrollp->win = newwin (scrollp->boxHeight, scrollp->boxWidth, ypos, xpos); /* Is the scrolling window null?? */ if (scrollp->win == 0) { destroyCDKObject (scrollp); return (0); } /* Turn the keypad on for the window. */ keypad (scrollp->win, TRUE); /* Create the scrollbar window. */ if (splace == RIGHT) { scrollp->scrollbarWin = subwin (scrollp->win, maxViewSize (scrollp), 1, SCREEN_YPOS (scrollp, ypos), xpos + scrollp->boxWidth - BorderOf (scrollp) - 1); } else if (splace == LEFT) { scrollp->scrollbarWin = subwin (scrollp->win, maxViewSize (scrollp), 1, SCREEN_YPOS (scrollp, ypos), SCREEN_XPOS (scrollp, xpos)); } else { scrollp->scrollbarWin = 0; } /* create the list window */ scrollp->listWin = subwin (scrollp->win, maxViewSize (scrollp), scrollp->boxWidth - 2 * BorderOf (scrollp) - scrollAdjust, SCREEN_YPOS (scrollp, ypos), SCREEN_XPOS (scrollp, xpos) + (splace == LEFT ? 1 : 0)); /* *INDENT-EQLS* Set the rest of the variables */ ScreenOf (scrollp) = cdkscreen; scrollp->parent = cdkscreen->window; scrollp->shadowWin = 0; scrollp->scrollbarPlacement = splace; scrollp->maxLeftChar = 0; scrollp->leftChar = 0; scrollp->highlight = highlight; initExitType (scrollp); ObjOf (scrollp)->acceptsFocus = TRUE; ObjOf (scrollp)->inputWindow = scrollp->win; scrollp->shadow = shadow; setCDKScrollPosition (scrollp, 0); /* Create the scrolling list item list and needed variables. */ if (createCDKScrollItemList (scrollp, numbers, list, listSize) <= 0) { destroyCDKObject (scrollp); return (0); } /* Do we need to create a shadow? */ if (shadow) { scrollp->shadowWin = newwin (scrollp->boxHeight, boxWidth, ypos + 1, xpos + 1); } /* Setup the key bindings. */ for (x = 0; x < (int)SIZEOF (bindings); ++x) bindCDKObject (vSCROLL, scrollp, (chtype)bindings[x].from, getcCDKBind, (void *)(long)bindings[x].to); registerCDKObject (cdkscreen, vSCROLL, scrollp); /* Return the scrolling list */ return scrollp; }
/* * This function creates a widget. */ CDKUSCALE *newCDKUScale (CDKSCREEN *cdkscreen, int xplace, int yplace, char *title, char *label, chtype fieldAttr, int fieldWidth, unsigned start, unsigned low, unsigned high, unsigned inc, unsigned fastInc, boolean Box, boolean shadow) { CDKUSCALE *widget = 0; int parentWidth = getmaxx(cdkscreen->window); int parentHeight = getmaxy(cdkscreen->window); int boxHeight; int boxWidth; int horizontalAdjust, oldWidth; int xpos = xplace; int ypos = yplace; int x, junk; static const struct { int from; int to; } bindings[] = { { 'u', KEY_UP }, { 'U', KEY_PPAGE }, { CDK_BACKCHAR, KEY_PPAGE }, { CDK_FORCHAR, KEY_NPAGE }, { 'g', KEY_HOME }, { '^', KEY_HOME }, { 'G', KEY_END }, { '$', KEY_END }, }; if ((widget = newCDKObject(CDKUSCALE, &my_funcs)) == 0) return (0); setCDKUScaleBox (widget, Box); boxHeight = (BorderOf(widget) * 2) + 1; boxWidth = fieldWidth + 2*BorderOf(widget); /* Set some basic values of the widget's data field. */ widget->label = 0; widget->labelLen = 0; widget->labelWin = 0; /* * If the fieldWidth is a negative value, the fieldWidth will * be COLS-fieldWidth, otherwise, the fieldWidth will be the * given width. */ fieldWidth = setWidgetDimension (parentWidth, fieldWidth, 0); boxWidth = fieldWidth + 2*BorderOf(widget); /* Translate the label char *pointer to a chtype pointer. */ if (label != 0) { widget->label = char2Chtype (label, &widget->labelLen, &junk); boxWidth = widget->labelLen + fieldWidth + 2; } oldWidth = boxWidth; boxWidth = setCdkTitle(ObjOf(widget), title, boxWidth); horizontalAdjust = (boxWidth - oldWidth) / 2; boxHeight += TitleLinesOf(widget); /* * Make sure we didn't extend beyond the dimensions of the window. */ boxWidth = (boxWidth > parentWidth ? parentWidth : boxWidth); boxHeight = (boxHeight > parentHeight ? parentHeight : boxHeight); fieldWidth = (fieldWidth > (boxWidth - widget->labelLen - 2*BorderOf(widget)) ? (boxWidth - widget->labelLen - 2*BorderOf(widget)) : fieldWidth); /* Rejustify the x and y positions if we need to. */ alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight); /* Make the widget's window. */ widget->win = newwin (boxHeight, boxWidth, ypos, xpos); /* Is the main window null??? */ if (widget->win == 0) { destroyCDKObject(widget); return (0); } /* Create the widget's label window. */ if (widget->label != 0) { widget->labelWin = subwin (widget->win, 1, widget->labelLen, ypos + TitleLinesOf(widget) + BorderOf(widget), xpos + horizontalAdjust + BorderOf(widget)); if (widget->labelWin == 0) { destroyCDKObject(widget); return (0); } } /* Create the widget's data field window. */ widget->fieldWin = subwin (widget->win, 1, fieldWidth, ypos + TitleLinesOf(widget) + BorderOf(widget), xpos + widget->labelLen + horizontalAdjust + BorderOf(widget)); if (widget->fieldWin == 0) { destroyCDKObject(widget); return (0); } keypad (widget->fieldWin, TRUE); keypad (widget->win, TRUE); /* Create the widget's data field. */ ScreenOf(widget) = cdkscreen; widget->parent = cdkscreen->window; widget->shadowWin = 0; widget->boxWidth = boxWidth; widget->boxHeight = boxHeight; widget->fieldWidth = fieldWidth; widget->fieldAttr = (chtype)fieldAttr; widget->current = low; widget->low = low; widget->high = high; widget->current = start; widget->inc = inc; widget->fastinc = fastInc; initExitType(widget); ObjOf(widget)->acceptsFocus = TRUE; ObjOf(widget)->inputWindow = widget->win; widget->shadow = shadow; /* Do we want a shadow??? */ if (shadow) { widget->shadowWin = newwin (boxHeight, boxWidth, ypos + 1, xpos + 1); if (widget->shadowWin == 0) { destroyCDKObject(widget); return (0); } } /* Setup the key bindings. */ for (x = 0; x < (int) SIZEOF(bindings); ++x) bindCDKObject (vUSCALE, widget, bindings[x].from, getcCDKBind, (void *)(long)bindings[x].to); registerCDKObject (cdkscreen, vUSCALE, widget); return (widget); }