/* * This sets the background color of the widget. */ void setCDKFScaleBackgroundColor (CDKFSCALE *scale, char *color) { chtype *holder = 0; int junk1, junk2; /* Make sure the color isn't null. */ if (color == 0) { return; } /* Convert the value of the environment variable to a chtype. */ holder = char2Chtype (color, &junk1, &junk2); /* Set the widgets background color. */ wbkgd (scale->win, holder[0]); wbkgd (scale->fieldWin, holder[0]); if (scale->labelWin != 0) { wbkgd (scale->labelWin, holder[0]); } /* Clean up. */ freeChtype (holder); }
/* * This sets the information within the button. */ void setCDKButtonMessage (CDKBUTTON *button, const char *info) { /* Clean out the old message. */ freeChtype (button->info); button->infoPos = 0; button->infoLen = 0; /* Copy in the new message. */ button->info = char2Chtype (info, &button->infoLen, &button->infoPos); button->infoPos = justifyString (button->boxWidth - 2 * BorderOf (button), button->infoLen, button->infoPos); /* Redraw the button widget. */ eraseCDKButton (button); drawCDKButton (button, ObjOf (button)->box); }
/* * This sets the background color of the widget. */ void setCDKDialogBackgroundColor (CDKDIALOG *dialog, char *color) { chtype *holder = 0; int junk1, junk2; /* Make sure the color isn't null. */ if (color == 0) { return; } /* Convert the value of the environment variable to a chtype. */ holder = char2Chtype (color, &junk1, &junk2); /* Set the widgets background color. */ wbkgd (dialog->win, holder[0]); /* Clean up. */ freeChtype (holder); }
static boolean allocListItem (CDKSCROLL *scrollp, int which, char **work, size_t * used, int number, const char *value) { if (number > 0) { size_t need = NUMBER_LEN (value); if (need > *used) { *used = ((need + 2) * 2); if (*work == 0) { if ((*work = (char *)malloc (*used)) == 0) return FALSE; } else { if ((*work = (char *)realloc (*work, *used)) == 0) return FALSE; } } sprintf (*work, NUMBER_FMT, number, value); value = *work; } if ((scrollp->item[which] = char2Chtype (value, &(scrollp->itemLen[which]), &(scrollp->itemPos[which]))) == 0) return FALSE; scrollp->itemPos[which] = justifyString (scrollp->boxWidth, scrollp->itemLen[which], scrollp->itemPos[which]); return TRUE; }
/* * This activates the widget. */ int activateCDKMarquee (CDKMARQUEE *widget, char *mesg, int delay, int repeat, boolean Box) { chtype *message; int mesgLength = 0; int startPos = 0; int firstChar = 0; int lastChar = 1; int repeatCount = 0; int viewSize = 0; int viewLimit; int padding; int x, y, junk, oldcurs; bool firstTime = TRUE; /* Make sure the message has some content. */ if (mesg == 0 || *mesg == '\0') { return (-1); } /* Keep the box info, setting BorderOf () */ setCDKMarqueeBox (widget, Box); padding = (mesg[strlen (mesg) - 1] == ' ') ? 0 : 1; /* Translate the char * to a chtype * */ message = char2Chtype (mesg, &mesgLength, &junk); /* Draw in the widget. */ drawCDKMarquee (widget, ObjOf (widget)->box); viewLimit = widget->width - (2 * BorderOf (widget)); /* Start doing the marquee thing... */ oldcurs = curs_set (0); while (widget->active) { if (firstTime) { firstChar = 0; lastChar = 1; viewSize = lastChar - firstChar; startPos = widget->width - viewSize - BorderOf (widget); firstTime = FALSE; } /* Draw in the characters. */ y = firstChar; for (x = startPos; x < (startPos + viewSize); x++) { chtype ch = (y < mesgLength) ? message[y] : ' '; mvwaddch (widget->win, BorderOf (widget), x, ch); y++; } wrefresh (widget->win); /* Set my variables. */ if (mesgLength < viewLimit) { if (lastChar < (mesgLength + padding)) { lastChar++; viewSize++; startPos = widget->width - viewSize - BorderOf (widget); } else if (startPos > BorderOf (widget)) { /* This means the whole string is visible. */ startPos--; viewSize = mesgLength + padding; } else { /* We have to start chopping the viewSize */ startPos = BorderOf (widget); firstChar++; viewSize--; } } else { if (startPos > BorderOf (widget)) { lastChar++; viewSize++; startPos--; } else if (lastChar < (mesgLength + padding)) { firstChar++; lastChar++; startPos = BorderOf (widget); viewSize = viewLimit; } else { startPos = BorderOf (widget); firstChar++; viewSize--; } } /* OK, lets check if we have to start over. */ if (viewSize <= 0 && firstChar == mesgLength + padding) { /* Check if we repeat a specified number, or loop indefinitely. */ if ((repeat > 0) && (++repeatCount >= repeat)) { break; } /* Time to start over. */ mvwaddch (widget->win, BorderOf (widget), BorderOf (widget), ' '); wrefresh (widget->win); firstTime = TRUE; } /* Now sleep */ napms (delay * 10); } if (oldcurs < 0) oldcurs = 1; curs_set (oldcurs); freeChtype (message); return (0); }
/* * This creates a button widget. */ CDKBUTTON *newCDKButton (CDKSCREEN *cdkscreen, int xplace, int yplace, const char *text, tButtonCallback callback, boolean Box, boolean shadow) { /* *INDENT-EQLS* */ CDKBUTTON *button = 0; int parentWidth = getmaxx (cdkscreen->window); int parentHeight = getmaxy (cdkscreen->window); int boxWidth = 0; int boxHeight; int xpos = xplace; int ypos = yplace; if ((button = newCDKObject (CDKBUTTON, &my_funcs)) == 0) return (0); setCDKButtonBox (button, Box); boxHeight = 1 + 2 * BorderOf (button); /* Translate the char * to a chtype. */ button->info = char2Chtype (text, &button->infoLen, &button->infoPos); boxWidth = MAXIMUM (boxWidth, button->infoLen) + 2 * BorderOf (button); /* Create the string alignments. */ button->infoPos = justifyString (boxWidth - 2 * BorderOf (button), button->infoLen, button->infoPos); /* * Make sure we didn't extend beyond the dimensions of the window. */ boxWidth = (boxWidth > parentWidth ? parentWidth : boxWidth); boxHeight = (boxHeight > parentHeight ? parentHeight : boxHeight); /* Rejustify the x and y positions if we need to. */ alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight); /* *INDENT-EQLS* Create the button. */ ScreenOf (button) = cdkscreen; ObjOf (button)->fn = &my_funcs; button->parent = cdkscreen->window; button->win = newwin (boxHeight, boxWidth, ypos, xpos); button->shadowWin = (WINDOW *)NULL; button->xpos = xpos; button->ypos = ypos; button->boxWidth = boxWidth; button->boxHeight = boxHeight; button->callback = callback; ObjOf (button)->inputWindow = button->win; ObjOf (button)->acceptsFocus = TRUE; initExitType (button); button->shadow = shadow; /* Is the window NULL? */ if (button->win == (WINDOW *)NULL) { destroyCDKObject (button); return (0); } keypad (button->win, TRUE); /* If a shadow was requested, then create the shadow window. */ if (shadow) button->shadowWin = newwin (boxHeight, boxWidth, ypos + 1, xpos + 1); /* Register this baby. */ registerCDKObject (cdkscreen, vBUTTON, button); /* Return the button pointer. */ return (button); }
/* * This creates a file selection widget. */ CDKFSELECT *newCDKFselect (CDKSCREEN *cdkscreen, int xplace, int yplace, int height, int width, char *title, char *label, chtype fieldAttribute, chtype fillerChar, chtype highlight, char *dAttribute, char *fAttribute, char *lAttribute, char *sAttribute, boolean Box, boolean shadow) { /* Set up some variables. */ CDKFSELECT *fselect = newCDKObject(CDKFSELECT, &my_funcs); int parentWidth = getmaxx(cdkscreen->window) - 1; int parentHeight = getmaxy(cdkscreen->window) - 1; int boxWidth = width; int boxHeight = height; int xpos = xplace; int ypos = yplace; int entryWidth, x, labelLen, junk; chtype *chtypeString; /* * 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); /* Rejustify the x and y positions if we need to. */ alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight); /* Make sure the box isn't too small. */ boxWidth = (boxWidth < 15 ? 15 : boxWidth); boxHeight = (boxHeight < 6 ? 6 : boxHeight); /* Make the file selector window. */ fselect->win = newwin (boxHeight, boxWidth, ypos, xpos); /* Is the window null? */ if (fselect->win == 0) { return (0); } keypad (fselect->win, TRUE); /* Set some variables. */ ScreenOf(fselect) = cdkscreen; fselect->parent = cdkscreen->window; fselect->dirAttribute = copyChar (dAttribute); fselect->fileAttribute = copyChar (fAttribute); fselect->linkAttribute = copyChar (lAttribute); fselect->sockAttribute = copyChar (sAttribute); fselect->highlight = highlight; fselect->fillerCharacter = fillerChar; fselect->fieldAttribute = fieldAttribute; fselect->boxHeight = boxHeight; fselect->boxWidth = boxWidth; fselect->fileCounter = 0; fselect->pwd = 0; fselect->exitType = vNEVER_ACTIVATED; ObjOf(fselect)->box = Box; fselect->shadow = shadow; fselect->shadowWin = 0; /* Zero out the contents of the directory listing. */ for (x=0; x < MAX_ITEMS; x++) { fselect->dirContents[x] = 0; } /* Get the present working directory. */ setPWD(fselect); /* Get the contents of the current directory. */ setCDKFselectDirContents (fselect); /* Create the entry field in the selector. */ chtypeString = char2Chtype (label, &labelLen, &junk); freeChtype (chtypeString); entryWidth = boxWidth - labelLen - 3; fselect->entryField = newCDKEntry (cdkscreen, getbegx(fselect->win), getbegy(fselect->win), title, label, fieldAttribute, fillerChar, vMIXED, entryWidth, 0, 512, Box, FALSE); /* Make sure the widget was created. */ if (fselect->entryField == 0) { /* Clean up. */ freeCharList (fselect->dirContents, MAX_ITEMS); freeChar (fselect->pwd); freeChar (fselect->dirAttribute); freeChar (fselect->fileAttribute); freeChar (fselect->linkAttribute); freeChar (fselect->sockAttribute); deleteCursesWindow (fselect->win); return (0); } /* Set the lower left/right characters of the entry field. */ setCDKEntryLLChar (fselect->entryField, ACS_LTEE); setCDKEntryLRChar (fselect->entryField, ACS_RTEE); /* Define the callbacks for the entry field. */ bindCDKObject (vENTRY, fselect->entryField, KEY_UP, fselectAdjustScrollCB, fselect); bindCDKObject (vENTRY, fselect->entryField, KEY_PPAGE, fselectAdjustScrollCB, fselect); bindCDKObject (vENTRY, fselect->entryField, CONTROL('B'), fselectAdjustScrollCB, fselect); bindCDKObject (vENTRY, fselect->entryField, KEY_DOWN, fselectAdjustScrollCB, fselect); bindCDKObject (vENTRY, fselect->entryField, KEY_NPAGE, fselectAdjustScrollCB, fselect); bindCDKObject (vENTRY, fselect->entryField, CONTROL('F'), fselectAdjustScrollCB, fselect); bindCDKObject (vENTRY, fselect->entryField, KEY_TAB, completeFilenameCB, fselect); bindCDKObject (vENTRY, fselect->entryField, CONTROL('^'), displayFileInfoCB, fselect); /* Put the current working directory in the entry field. */ setCDKEntryValue (fselect->entryField, fselect->pwd); /* Create the scrolling list in the selector. */ fselect->scrollField = newCDKScroll (cdkscreen, getbegx(fselect->win), getbegy(fselect->win) + (fselect->entryField)->titleLines + 2, RIGHT, boxHeight - (fselect->entryField)->titleLines - 3, boxWidth-2, 0, fselect->dirContents, fselect->fileCounter, NONUMBERS, fselect->highlight, Box, FALSE); /* Set the lower left/right characters of the entry field. */ setCDKScrollULChar (fselect->scrollField, ACS_LTEE); setCDKScrollURChar (fselect->scrollField, ACS_RTEE); /* Do we want a shadow? */ if (shadow) { fselect->shadowWin = newwin (boxHeight, boxWidth, ypos + 1, xpos + 1); } /* Register this baby. */ registerCDKObject (cdkscreen, vFSELECT, fselect); /* Return the file selector pointer. */ return (fselect); }
int main (int argc, char **argv) { /* Declare variables. */ CDKSCREEN *cdkScreen = 0; CDKENTRY *widget = 0; CDKBUTTONBOX *buttonWidget = 0; WINDOW *cursesWindow = 0; chtype *holder = 0; chtype fieldAttr = A_NORMAL; char *answer = 0; char *CDK_WIDGET_COLOR = 0; char *temp = 0; char filler = '.'; EDisplayType dType = vMIXED; int buttonCount = 0; int selection = 0; int shadowHeight = 0; FILE *fp = stderr; char **buttonList = 0; int j1, j2; CDK_PARAMS params; boolean boxWidget; boolean shadowWidget; char *buttons; char *filename; char *outputFile; char *initValue; char *title; char *label; char *tempFiller; int maxValue; int fieldWidth; int minValue; int xpos; int ypos; CDKparseParams(argc, argv, ¶ms, "d:f:i:m:B:F:L:M:O:T:" "X:Y:NS"); xpos = CDKparamValue(¶ms, 'X', CENTER); ypos = CDKparamValue(¶ms, 'Y', CENTER); boxWidget = CDKparamValue(¶ms, 'N', TRUE); shadowWidget = CDKparamValue(¶ms, 'S', FALSE); minValue = CDKparamValue(¶ms, 'm', 0); fieldWidth = CDKparamValue(¶ms, 'f', 0); maxValue = CDKparamValue(¶ms, 'M', 256); filename = CDKparamString(¶ms, 'f'); initValue = CDKparamString(¶ms, 'i'); buttons = CDKparamString(¶ms, 'B'); tempFiller = CDKparamString(¶ms, 'F'); label = CDKparamString(¶ms, 'L'); outputFile = CDKparamString(¶ms, 'O'); title = CDKparamString(¶ms, 'T'); if ((temp = CDKparamString(¶ms, 'd')) != 0) dType = char2DisplayType (temp); /* Make sure all the command line parameters were provided. */ if (fieldWidth <= 0) { fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage); ExitProgram (CLI_ERROR); } /* If the user asked for an output file, try to open it. */ if (outputFile != 0) { if ((fp = fopen (outputFile, "w")) == 0) { fprintf (stderr, "%s: Can not open output file %s\n", argv[0], outputFile); ExitProgram (CLI_ERROR); } } /* Set up CDK. */ cursesWindow = initscr(); cdkScreen = initCDKScreen (cursesWindow); /* Start color. */ initCDKColor(); /* Check if the user wants to set the background of the main screen. */ if ((temp = getenv ("CDK_SCREEN_COLOR")) != 0) { holder = char2Chtype (temp, &j1, &j2); wbkgd (cdkScreen->window, holder[0]); wrefresh (cdkScreen->window); freeChtype (holder); } /* Get the widget color background color. */ if ((CDK_WIDGET_COLOR = getenv ("CDK_WIDGET_COLOR")) == 0) { CDK_WIDGET_COLOR = 0; } /* If the set the filler character, set it now. */ if (tempFiller != 0) { holder = char2Chtype (tempFiller, &j1, &j2); fieldAttr = A_ATTRIBUTES & holder[0]; filler = (chtype)holder[0]; freeChtype (holder); } /* Create the entry widget. */ widget = newCDKEntry (cdkScreen, xpos, ypos, title, label, fieldAttr, filler | fieldAttr, dType, fieldWidth, minValue, maxValue, boxWidget, FALSE); /* Check to make sure we created the dialog box. */ if (widget == 0) { /* Shut down curses and CDK. */ destroyCDKScreen (cdkScreen); endCDK(); fprintf (stderr, "Error: Could not create the entry field. Is the window too small?\n"); ExitProgram (CLI_ERROR); } /* Split the buttons if they supplied some. */ if (buttons != 0) { buttonList = CDKsplitString (buttons, '\n'); buttonCount = CDKcountStrings (buttonList); buttonWidget = newCDKButtonbox (cdkScreen, getbegx (widget->win), getbegy (widget->win) + widget->boxHeight - 1, 1, widget->boxWidth - 1, 0, 1, buttonCount, buttonList, buttonCount, A_REVERSE, boxWidget, FALSE); CDKfreeStrings (buttonList); setCDKButtonboxULChar (buttonWidget, ACS_LTEE); setCDKButtonboxURChar (buttonWidget, ACS_RTEE); /* * We need to set the lower left and right * characters of the entry field. */ setCDKEntryLLChar (widget, ACS_LTEE); setCDKEntryLRChar (widget, ACS_RTEE); /* * Bind the Tab key in the entry field to send a * Tab key to the button box widget. */ bindCDKObject (vENTRY, widget, KEY_TAB, widgetCB, buttonWidget); bindCDKObject (vENTRY, widget, CDK_NEXT, widgetCB, buttonWidget); bindCDKObject (vENTRY, widget, CDK_PREV, widgetCB, buttonWidget); /* Check if the user wants to set the background of the widget. */ setCDKButtonboxBackgroundColor (buttonWidget, CDK_WIDGET_COLOR); /* Draw the button widget. */ drawCDKButtonbox (buttonWidget, boxWidget); } /* * If the user asked for a shadow, we need to create one. Do this instead * of using the shadow parameter because the button widget is not part of * the main widget and if the user asks for both buttons and a shadow, we * need to create a shadow big enough for both widgets. Create the shadow * window using the widgets shadowWin element, so screen refreshes will draw * them as well. */ if (shadowWidget == TRUE) { /* Determine the height of the shadow window. */ shadowHeight = (buttonWidget == 0 ? widget->boxHeight : widget->boxHeight + buttonWidget->boxHeight - 1); /* Create the shadow window. */ widget->shadowWin = newwin (shadowHeight, widget->boxWidth, getbegy (widget->win) + 1, getbegx (widget->win) + 1); /* Make sure we could have created the shadow window. */ if (widget->shadowWin != 0) { widget->shadow = TRUE; /* * We force the widget and buttonWidget to be drawn so the * buttonbox widget will be drawn when the widget is activated. * Otherwise the shadow window will draw over the button widget. */ drawCDKEntry (widget, ObjOf(widget)->box); eraseCDKButtonbox (buttonWidget); drawCDKButtonbox (buttonWidget, ObjOf(buttonWidget)->box); } } /* Check if the user wants to set the background of the widget. */ setCDKEntryBackgroundColor (widget, CDK_WIDGET_COLOR); /* If there was an initial value, set it. */ if (initValue != 0) { setCDKEntryValue (widget, initValue); } /* Activate the widget. */ answer = copyChar (activateCDKEntry (widget, 0)); /* If there were buttons, get the button selected. */ if (buttonWidget != 0) { selection = buttonWidget->currentButton; destroyCDKButtonbox (buttonWidget); } /* End CDK. */ destroyCDKEntry (widget); destroyCDKScreen (cdkScreen); endCDK(); /* Print the value from the widget. */ if (answer != 0) { fprintf (fp, "%s\n", answer); freeChar (answer); } fclose (fp); /* Exit with the button number picked. */ ExitProgram (selection); }
int main (int argc, char **argv) { /* *INDENT-EQLS* */ CDKSCREEN *cdkScreen = 0; CDKMATRIX *widget = 0; CDKBUTTONBOX *buttonWidget = 0; chtype *holder = 0; char *buttons = 0; char *CDK_WIDGET_COLOR = 0; char *temp = 0; chtype filler = A_NORMAL | '.'; int rows = -1; int cols = -1; int buttonCount = 0; int selection = 0; int shadowHeight = 0; FILE *fp = stderr; char **rowTitles; char **colTitles; char **rowTemp = 0; char **colTemp = 0; char **kolTemp = 0; char **buttonList = 0; int *colWidths; int *colTypes; int count, infoLines, x, y, j1, j2; CDK_PARAMS params; boolean boxWidget; boolean shadowWidget; char *defaultValue; char *myColTitles; char *myColTypes; char *myColWidths; char *myFiller; char *myRowTitles; char *outputFile; char *title; int vrows; int xpos; int ypos; CDKparseParams (argc, argv, ¶ms, "c:d:r:t:w:v:B:F:O:T:" CDK_MIN_PARAMS); /* *INDENT-EQLS* */ xpos = CDKparamValue (¶ms, 'X', CENTER); ypos = CDKparamValue (¶ms, 'Y', CENTER); boxWidget = CDKparamValue (¶ms, 'N', TRUE); shadowWidget = CDKparamValue (¶ms, 'S', FALSE); vrows = CDKparamValue (¶ms, 'v', -1); myColTitles = CDKparamString (¶ms, 'c'); defaultValue = CDKparamString (¶ms, 'd'); myRowTitles = CDKparamString (¶ms, 'r'); myColTypes = CDKparamString (¶ms, 't'); myColWidths = CDKparamString (¶ms, 'w'); buttons = CDKparamString (¶ms, 'B'); myFiller = CDKparamString (¶ms, 'F'); outputFile = CDKparamString (¶ms, 'O'); title = CDKparamString (¶ms, 'T'); /* If the user asked for an output file, try to open it. */ if (outputFile != 0) { if ((fp = fopen (outputFile, "w")) == 0) { fprintf (stderr, "%s: Can not open output file %s\n", argv[0], outputFile); ExitProgram (CLI_ERROR); } } /* Make sure all the needed command line parameters were provided. */ if ((myRowTitles == 0) || (myColTitles == 0) || (myColWidths == 0) || (vrows == -1)) { fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage); ExitProgram (CLI_ERROR); } /* Convert the char * titles to a char **, offset by one */ rowTemp = CDKsplitString (myRowTitles, '\n'); rows = (int)CDKcountStrings ((CDK_CSTRING2)rowTemp); rowTitles = (char **)calloc ((size_t) rows + 1, sizeof (char *)); for (x = 0; x < rows; x++) { rowTitles[x + 1] = rowTemp[x]; } colTemp = CDKsplitString (myColTitles, '\n'); cols = (int)CDKcountStrings ((CDK_CSTRING2)colTemp); colTitles = (char **)calloc ((size_t) cols + 1, sizeof (char *)); for (x = 0; x < cols; x++) { colTitles[x + 1] = colTemp[x]; } /* Convert the column widths. */ kolTemp = CDKsplitString (myColWidths, '\n'); count = (int)CDKcountStrings ((CDK_CSTRING2)kolTemp); colWidths = (int *)calloc ((size_t) count + 1, sizeof (int)); for (x = 0; x < count; x++) { colWidths[x + 1] = atoi (kolTemp[x]); } /* If they passed in the column types, convert them. */ if (myColTypes != 0) { char **ss = CDKsplitString (myColTypes, '\n'); count = (int)CDKcountStrings ((CDK_CSTRING2)ss); colTypes = (int *)calloc ((size_t) MAXIMUM (cols, count) + 1, sizeof (int)); for (x = 0; x < count; x++) { colTypes[x + 1] = char2DisplayType (ss[x]); } CDKfreeStrings (ss); } else { /* If they didn't set default values. */ colTypes = (int *)calloc ((size_t) cols + 1, sizeof (int)); for (x = 0; x < cols; x++) { colTypes[x + 1] = vMIXED; } } cdkScreen = initCDKScreen (NULL); /* Start color. */ initCDKColor (); /* Check if the user wants to set the background of the main screen. */ if ((temp = getenv ("CDK_SCREEN_COLOR")) != 0) { holder = char2Chtype (temp, &j1, &j2); wbkgd (cdkScreen->window, holder[0]); wrefresh (cdkScreen->window); freeChtype (holder); } /* Get the widget color background color. */ if ((CDK_WIDGET_COLOR = getenv ("CDK_WIDGET_COLOR")) == 0) { CDK_WIDGET_COLOR = 0; } /* If the set the filler character, set it now. */ if (myFiller != 0) { holder = char2Chtype (myFiller, &j1, &j2); filler = holder[0]; freeChtype (holder); } /* Create the matrix widget. */ widget = newCDKMatrix (cdkScreen, xpos, ypos, rows, cols, vrows, cols, title, (CDK_CSTRING2)rowTitles, (CDK_CSTRING2)colTitles, colWidths, colTypes, 1, 1, filler, COL, boxWidget, TRUE, shadowWidget); free (rowTitles); free (colTitles); /* Make sure we could create the widget. */ if (widget == 0) { /* Shut down curses and CDK. */ destroyCDKScreen (cdkScreen); endCDK (); fprintf (stderr, "Error: Cannot create the matrix. " "Is the window too small?\n"); ExitProgram (CLI_ERROR); } /* * If the user sent in a file of default values, read it and * stick the values read in from the file into the matrix. */ if (defaultValue != 0) { size_t limit = (size_t) ((rows + 1) * (cols + 1)); char **info = (char **)calloc (limit, sizeof (char *)); char **lineTemp = 0; /* Read the file. */ infoLines = CDKreadFile (defaultValue, &lineTemp); if (infoLines > 0) { int *subSize = (int *)calloc ((size_t) infoLines + 1, sizeof (int)); /* For each line, split on a CTRL-V. */ for (x = 0; x < infoLines; x++) { char **ss = CDKsplitString (lineTemp[x], CTRL ('V')); subSize[x + 1] = (int)CDKcountStrings ((CDK_CSTRING2)ss); for (y = 0; y < subSize[x + 1]; y++) { MY_INFO (x, y) = ss[y]; } free (ss); } CDKfreeStrings (lineTemp); setCDKMatrixCells (widget, (CDK_CSTRING2)info, rows, cols, subSize); for (x = 0; x < infoLines; x++) { for (y = 0; y < subSize[x + 1]; y++) { freeChar (MY_INFO (x, y)); } } free (info); free (subSize); } } /* Split the buttons if they supplied some. */ if (buttons != 0) { /* Split the button list up. */ buttonList = CDKsplitString (buttons, '\n'); buttonCount = (int)CDKcountStrings ((CDK_CSTRING2)buttonList); /* We need to create a buttonbox widget. */ buttonWidget = newCDKButtonbox (cdkScreen, getbegx (widget->win), (getbegy (widget->win) + widget->boxHeight - 1), 1, widget->boxWidth - 1, NULL, 1, buttonCount, (CDK_CSTRING2)buttonList, buttonCount, A_REVERSE, boxWidget, FALSE); setCDKButtonboxULChar (buttonWidget, ACS_LTEE); setCDKButtonboxURChar (buttonWidget, ACS_RTEE); /* * We need to set the lower left and right * characters of the widget. */ setCDKMatrixLLChar (widget, ACS_LTEE); setCDKMatrixLRChar (widget, ACS_RTEE); /* * Bind the Tab key in the widget to send a * Tab key to the button box widget. */ bindCDKObject (vMATRIX, widget, KEY_TAB, widgetCB, buttonWidget); bindCDKObject (vMATRIX, widget, CDK_NEXT, widgetCB, buttonWidget); bindCDKObject (vMATRIX, widget, CDK_PREV, widgetCB, buttonWidget); /* Check if the user wants to set the background of the widget. */ setCDKButtonboxBackgroundColor (buttonWidget, CDK_WIDGET_COLOR); /* Draw the button widget. */ drawCDKButtonbox (buttonWidget, boxWidget); } /* * If the user asked for a shadow, we need to create one. Do this instead * of using the shadow parameter because the button widget is not part of * the main widget and if the user asks for both buttons and a shadow, we * need to create a shadow big enough for both widgets. Create the shadow * window using the widgets shadowWin element, so screen refreshes will draw * them as well. */ if (shadowWidget == TRUE) { /* Determine the height of the shadow window. */ shadowHeight = (buttonWidget == (CDKBUTTONBOX *)NULL ? widget->boxHeight : widget->boxHeight + buttonWidget->boxHeight - 1); /* Create the shadow window. */ widget->shadowWin = newwin (shadowHeight, widget->boxWidth, getbegy (widget->win) + 1, getbegx (widget->win) + 1); /* Make sure we could have created the shadow window. */ if (widget->shadowWin != 0) { widget->shadow = TRUE; /* * We force the widget and buttonWidget to be drawn so the * buttonbox widget will be drawn when the widget is activated. * Otherwise the shadow window will draw over the button widget. */ drawCDKMatrix (widget, ObjOf (widget)->box); eraseCDKButtonbox (buttonWidget); drawCDKButtonbox (buttonWidget, ObjOf (buttonWidget)->box); } } /* Check if the user wants to set the background of the widget. */ setCDKMatrixBackgroundColor (widget, CDK_WIDGET_COLOR); /* Let them play. */ activateCDKMatrix (widget, 0); /* Print out the matrix cells. */ if (widget->exitType == vNORMAL) { for (x = 0; x < widget->rows; x++) { for (y = 0; y < widget->cols; y++) { char *data = getCDKMatrixCell (widget, x, y); if (data != 0) { fprintf (fp, "%s%c", data, CTRL ('V')); } else { fprintf (fp, "%c", CTRL ('V')); } } fprintf (fp, "\n"); } } /* If there were buttons, get the button selected. */ if (buttonWidget != 0) { selection = buttonWidget->currentButton; destroyCDKButtonbox (buttonWidget); } /* cleanup (not really needed) */ CDKfreeStrings (buttonList); free (colTypes); free (colWidths); CDKfreeStrings (rowTemp); CDKfreeStrings (colTemp); CDKfreeStrings (kolTemp); destroyCDKMatrix (widget); destroyCDKScreen (cdkScreen); endCDK (); /* do this late, in case it was stderr */ fclose (fp); ExitProgram (selection); }
/* * This function creates a dialog widget. */ CDKDIALOG *newCDKDialog (CDKSCREEN *cdkscreen, int xplace, int yplace, char **mesg, int rows, char **buttonLabel, int buttonCount, chtype highlight, boolean separator, boolean Box, boolean shadow) { /* Declare local variables. */ CDKDIALOG *dialog = newCDKObject(CDKDIALOG, &my_funcs); int boxWidth = MIN_DIALOG_WIDTH; int boxHeight = rows + 3 + separator; int maxmessagewidth = -1; int buttonwidth = 0; int xpos = xplace; int ypos = yplace; int temp = 0; int buttonadj = 0; int x = 0; /* Translate the char * message to a chtype * */ for (x=0; x < rows; x++) { dialog->info[x] = char2Chtype (mesg[x], &dialog->infoLen[x], &dialog->infoPos[x]); maxmessagewidth = MAXIMUM(maxmessagewidth, dialog->infoLen[x]); } /* Translate the button label char * to a chtype * */ for (x = 0; x < buttonCount; x++) { dialog->buttonLabel[x] = char2Chtype (buttonLabel[x], &dialog->buttonLen[x], &temp); buttonwidth += dialog->buttonLen[x] + 1; } buttonwidth--; /* Determine the final dimensions of the box. */ boxWidth = MAXIMUM(boxWidth, maxmessagewidth); boxWidth = MAXIMUM(boxWidth, buttonwidth); boxWidth = boxWidth + 4; /* Now we have to readjust the x and y positions. */ alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight); /* Set up the dialog box attributes. */ ScreenOf(dialog) = cdkscreen; dialog->parent = cdkscreen->window; dialog->win = newwin (boxHeight, boxWidth, ypos, xpos); dialog->shadowWin = 0; dialog->buttonCount = buttonCount; dialog->currentButton = 0; dialog->messageRows = rows; dialog->boxHeight = boxHeight; dialog->boxWidth = boxWidth; dialog->highlight = highlight; dialog->separator = separator; dialog->exitType = vNEVER_ACTIVATED; ObjOf(dialog)->box = Box; dialog->shadow = shadow; dialog->ULChar = ACS_ULCORNER; dialog->URChar = ACS_URCORNER; dialog->LLChar = ACS_LLCORNER; dialog->LRChar = ACS_LRCORNER; dialog->HChar = ACS_HLINE; dialog->VChar = ACS_VLINE; dialog->BoxAttrib = A_NORMAL; dialog->preProcessFunction = 0; dialog->preProcessData = 0; dialog->postProcessFunction = 0; dialog->postProcessData = 0; /* If we couldn't create the window, we should return a null value. */ if (dialog->win == 0) { /* Couldn't create the window. Clean up used memory. */ for (x=0; x < dialog->messageRows ; x++) { freeChtype (dialog->info[x]); } for (x=0; x < dialog->buttonCount; x++) { freeChtype (dialog->buttonLabel[x]); } /* Remove the memory used by the dialog pointer. */ free (dialog); /* Return a null dialog box. */ return (0); } keypad (dialog->win, TRUE); /* Find the button positions. */ buttonadj = ((int)((boxWidth-buttonwidth)/2)); for (x = 0; x < buttonCount; x++) { dialog->buttonPos[x] = buttonadj; buttonadj = buttonadj + dialog->buttonLen[x] + 1; } /* Create the string alignments. */ for (x=0; x < rows; x++) { dialog->infoPos[x] = justifyString (boxWidth, dialog->infoLen[x], dialog->infoPos[x]); } /* Was there a shadow? */ if (shadow) { dialog->shadowWin = newwin (boxHeight, boxWidth, ypos + 1, xpos + 1); } /* Empty the key bindings. */ cleanCDKObjectBindings (vDIALOG, dialog); /* Register this baby. */ registerCDKObject (cdkscreen, vDIALOG, dialog); /* Return the dialog box pointer. */ return (dialog); }
/* * 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); }
/* * This function creates a scale widget. */ CDKFSCALE *newCDKFScale (CDKSCREEN *cdkscreen, int xplace, int yplace, char *title, char *label, chtype fieldAttr, int fieldWidth, float start, float low, float high, float inc, float fastinc, int digits, boolean Box, boolean shadow) { /* Declare local variables. */ CDKFSCALE *scale = newCDKObject(CDKFSCALE, &my_funcs); chtype *holder = 0; int parentWidth = getmaxx(cdkscreen->window) - 1; int parentHeight = getmaxy(cdkscreen->window) - 1; int boxHeight = 3; int boxWidth = fieldWidth + 2; int maxWidth = INT_MIN; int horizontalAdjust = 0; int xpos = xplace; int ypos = yplace; char **temp = 0; int x, len, junk, junk2; /* Set some basic values of the scale field. */ scale->label = 0; scale->labelLen = 0; scale->labelWin = 0; scale->titleLines = 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; /* Translate the label char *pointer to a chtype pointer. */ if (label != 0) { scale->label = char2Chtype (label, &scale->labelLen, &junk); boxWidth = scale->labelLen + fieldWidth + 2; } /* Translate the char * items to chtype * */ if (title != 0) { temp = CDKsplitString (title, '\n'); scale->titleLines = CDKcountStrings (temp); /* We need to determine the widest title line. */ for (x=0; x < scale->titleLines; x++) { holder = char2Chtype (temp[x], &len, &junk2); maxWidth = MAXIMUM (maxWidth, len); freeChtype (holder); } /* * If one of the title lines is wider than the field and the label, * the box width will expand to accomodate. */ if (maxWidth > boxWidth) { horizontalAdjust = (int)((maxWidth - boxWidth) / 2) + 1; boxWidth = maxWidth + 2; } /* For each line in the title, convert from char * to chtype * */ for (x=0; x < scale->titleLines; x++) { scale->title[x] = char2Chtype (temp[x], &scale->titleLen[x], &scale->titlePos[x]); scale->titlePos[x] = justifyString (boxWidth, scale->titleLen[x], scale->titlePos[x]); } CDKfreeStrings(temp); } else { /* No title? Set the required variables. */ scale->titleLines = 0; } boxHeight += scale->titleLines; /* * 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 - scale->labelLen - 2) ? (boxWidth - scale->labelLen - 2) : fieldWidth); /* Rejustify the x and y positions if we need to. */ alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight); /* Make the scale window. */ scale->win = newwin (boxHeight, boxWidth, ypos, xpos); /* Is the main window null??? */ if (scale->win == 0) { freeChtype (scale->label); free (scale); /* Return a null pointer. */ return (0); } /* Create the scale label window. */ if (scale->label != 0) { scale->labelWin = subwin (scale->win, 1, scale->labelLen + 2, ypos + scale->titleLines + 1, xpos + horizontalAdjust + 1); } /* Create the scale field window. */ scale->fieldWin = subwin (scale->win, 1, fieldWidth, ypos + scale->titleLines + 1, xpos + scale->labelLen + horizontalAdjust + 1); keypad (scale->fieldWin, TRUE); keypad (scale->win, TRUE); /* Create the scale field. */ ScreenOf(scale) = cdkscreen; ObjOf(scale)->box = Box; scale->parent = cdkscreen->window; scale->shadowWin = 0; scale->boxWidth = boxWidth; scale->boxHeight = boxHeight; scale->fieldWidth = fieldWidth; scale->fieldAttr = (chtype)fieldAttr; scale->current = low; scale->low = low; scale->high = high; scale->current = start; scale->inc = inc; scale->fastinc = fastinc; scale->digits = digits; scale->exitType = vNEVER_ACTIVATED; scale->shadow = shadow; scale->preProcessFunction = 0; scale->preProcessData = 0; scale->postProcessFunction = 0; scale->postProcessData = 0; scale->ULChar = ACS_ULCORNER; scale->URChar = ACS_URCORNER; scale->LLChar = ACS_LLCORNER; scale->LRChar = ACS_LRCORNER; scale->HChar = ACS_HLINE; scale->VChar = ACS_VLINE; scale->BoxAttrib = A_NORMAL; /* Do we want a shadow??? */ if (shadow) { scale->shadowWin = newwin (boxHeight, boxWidth, ypos + 1, xpos + 1); } /* Clean the key bindings. */ cleanCDKObjectBindings (vFSCALE, scale); /* Register this baby. */ registerCDKObject (cdkscreen, vFSCALE, scale); /* Return the pointer. */ return (scale); }
int main (int argc, char **argv) { /* *INDENT-EQLS* */ CDKSCREEN *cdkScreen = 0; CDKSLIDER *widget = 0; CDKBUTTONBOX *buttonWidget = 0; WINDOW *cursesWindow = 0; char *CDK_WIDGET_COLOR = 0; char *temp = 0; chtype *holder = 0; chtype fieldAttr = A_REVERSE | ' '; int answer = 0; int buttonCount = 0; int selection = 0; int shadowHeight = 0; FILE *fp = stderr; char **buttonList = 0; int j1, j2, tmp; CDK_PARAMS params; boolean boxWidget; boolean shadowWidget; char *barAttribute; char *buttons; char *label; char *outputFile; char *title; int fieldWidth; int incrementStep; int acceleratedStep; int initValue; int lowValue; int highValue; int xpos; int ypos; CDKparseParams (argc, argv, ¶ms, "a:f:h:i:l:s:B:F:L:O:T:" CDK_MIN_PARAMS); /* *INDENT-EQLS* */ xpos = CDKparamValue (¶ms, 'X', CENTER); ypos = CDKparamValue (¶ms, 'Y', CENTER); boxWidget = CDKparamValue (¶ms, 'N', TRUE); shadowWidget = CDKparamValue (¶ms, 'S', FALSE); acceleratedStep = CDKparamValue (¶ms, 'a', -1); fieldWidth = CDKparamValue (¶ms, 'f', 0); highValue = CDKparamValue (¶ms, 'h', INT_MIN); incrementStep = CDKparamValue (¶ms, 'i', 1); lowValue = CDKparamValue (¶ms, 'l', INT_MAX); initValue = CDKparamValue (¶ms, 's', INT_MIN); buttons = CDKparamString (¶ms, 'B'); barAttribute = CDKparamString (¶ms, 'F'); label = CDKparamString (¶ms, 'L'); outputFile = CDKparamString (¶ms, 'O'); title = CDKparamString (¶ms, 'T'); incrementStep = abs (incrementStep); /* Make sure all the command line parameters were provided. */ if (fieldWidth <= 0) { fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage); ExitProgram (CLI_ERROR); } /* Make sure the user supplied the low/high values. */ if ((lowValue == INT_MAX) || (highValue == INT_MIN)) { fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage); ExitProgram (CLI_ERROR); } /* If the user asked for an output file, try to open it. */ if (outputFile != 0) { if ((fp = fopen (outputFile, "w")) == 0) { fprintf (stderr, "%s: Can not open output file %s\n", argv[0], outputFile); ExitProgram (CLI_ERROR); } } /* Make sure the low is lower than the high (and vice versa). */ if (lowValue > highValue) { tmp = lowValue; lowValue = highValue; highValue = tmp; } /* Make sure the starting value is in range. */ if (initValue < lowValue) { initValue = lowValue; } else if (initValue > highValue) { initValue = highValue; } /* Check if the accelerated incremnt value was set. */ if (acceleratedStep <= 0) { acceleratedStep = (int)((highValue - lowValue) / 10); acceleratedStep = MAXIMUM (1, acceleratedStep); } /* Set up CDK. */ cursesWindow = initscr (); cdkScreen = initCDKScreen (cursesWindow); /* Start color. */ initCDKColor (); /* Check if the user wants to set the background of the main screen. */ if ((temp = getenv ("CDK_SCREEN_COLOR")) != 0) { holder = char2Chtype (temp, &j1, &j2); wbkgd (cdkScreen->window, holder[0]); wrefresh (cdkScreen->window); freeChtype (holder); } /* Get the widget color background color. */ if ((CDK_WIDGET_COLOR = getenv ("CDK_WIDGET_COLOR")) == 0) { CDK_WIDGET_COLOR = 0; } /* Did the user ask to change the bar attribute? */ if (barAttribute != 0) { holder = char2Chtype (barAttribute, &j1, &j2); fieldAttr = holder[0]; freeChtype (holder); } /* Create the entry widget. */ widget = newCDKSlider (cdkScreen, xpos, ypos, title, label, fieldAttr, fieldWidth, initValue, lowValue, highValue, incrementStep, acceleratedStep, boxWidget, shadowWidget); /* Check to make sure we created the dialog box. */ if (widget == 0) { /* Shut down curses and CDK. */ destroyCDKScreen (cdkScreen); endCDK (); fprintf (stderr, "Error: Could not create the numeric slider field. " "Is the window too small?\n"); ExitProgram (CLI_ERROR); } /* Split the buttons if they supplied some. */ if (buttons != 0) { /* Split the button list up. */ buttonList = CDKsplitString (buttons, '\n'); buttonCount = (int)CDKcountStrings ((CDK_CSTRING2) buttonList); /* We need to create a buttonbox widget. */ buttonWidget = newCDKButtonbox (cdkScreen, getbegx (widget->win), (getbegy (widget->win) + widget->boxHeight - 1), 1, widget->boxWidth - 1, 0, 1, buttonCount, (CDK_CSTRING2) buttonList, buttonCount, A_REVERSE, boxWidget, FALSE); CDKfreeStrings (buttonList); setCDKButtonboxULChar (buttonWidget, ACS_LTEE); setCDKButtonboxURChar (buttonWidget, ACS_RTEE); /* * We need to set the lower left and right * characters of the widget. */ setCDKSliderLLChar (widget, ACS_LTEE); setCDKSliderLRChar (widget, ACS_RTEE); /* * Bind the Tab key in the widget to send a * Tab key to the button box widget. */ bindCDKObject (vSLIDER, widget, KEY_TAB, widgetCB, buttonWidget); bindCDKObject (vSLIDER, widget, CDK_NEXT, widgetCB, buttonWidget); bindCDKObject (vSLIDER, widget, CDK_PREV, widgetCB, buttonWidget); /* Check if the user wants to set the background of the widget. */ setCDKButtonboxBackgroundColor (buttonWidget, CDK_WIDGET_COLOR); /* Draw the button widget. */ drawCDKButtonbox (buttonWidget, boxWidget); } /* * If the user asked for a shadow, we need to create one. Do this instead * of using the shadow parameter because the button widget is not part of * the main widget and if the user asks for both buttons and a shadow, we * need to create a shadow big enough for both widgets. Create the shadow * window using the widgets shadowWin element, so screen refreshes will draw * them as well. */ if (shadowWidget == TRUE) { /* Determine the height of the shadow window. */ shadowHeight = (buttonWidget == 0 ? widget->boxHeight : widget->boxHeight + buttonWidget->boxHeight - 1); /* Create the shadow window. */ widget->shadowWin = newwin (shadowHeight, widget->boxWidth, getbegy (widget->win) + 1, getbegx (widget->win) + 1); /* Make sure we could have created the shadow window. */ if (widget->shadowWin != 0) { widget->shadow = TRUE; /* * We force the widget and buttonWidget to be drawn so the * buttonbox widget will be drawn when the widget is activated. * Otherwise the shadow window will draw over the button widget. */ drawCDKSlider (widget, ObjOf (widget)->box); eraseCDKButtonbox (buttonWidget); drawCDKButtonbox (buttonWidget, ObjOf (buttonWidget)->box); } } /* Check if the user wants to set the background of the widget. */ setCDKSliderBackgroundColor (widget, CDK_WIDGET_COLOR); /* Activate the widget. */ answer = activateCDKSlider (widget, 0); /* If there were buttons, get the button selected. */ if (buttonWidget != 0) { selection = buttonWidget->currentButton; destroyCDKButtonbox (buttonWidget); } /* End CDK. */ destroyCDKSlider (widget); destroyCDKScreen (cdkScreen); endCDK (); /* Print the value from the widget. */ fprintf (fp, "%d\n", answer); fclose (fp); /* Exit with the button selected. */ ExitProgram (selection); }
/* * 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); }
/* * This creates the alphalist widget. */ CDKALPHALIST *newCDKAlphalist (CDKSCREEN *cdkscreen, int xplace, int yplace, int height, int width, char *title, char *label, char *list[], int listSize, chtype fillerChar, chtype highlight, boolean Box, boolean shadow) { /* Set up some variables. */ CDKALPHALIST *alphalist = newCDKObject(CDKALPHALIST, &my_funcs); chtype *chtypeLabel = 0; int parentWidth = getmaxx(cdkscreen->window) - 1; int parentHeight = getmaxy(cdkscreen->window) - 1; int boxWidth = width; int boxHeight = height; int xpos = xplace; int ypos = yplace; int entryWidth = 0; int labelLen = 0; int x, junk2; /* * 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); /* Translate the label char *pointer to a chtype pointer. */ if (label != 0) { chtypeLabel = char2Chtype (label, &labelLen, &junk2); freeChtype (chtypeLabel); } /* Rejustify the x and y positions if we need to. */ alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight); /* Make the file selector window. */ alphalist->win = newwin (boxHeight, boxWidth, ypos, xpos); if (alphalist->win == 0) { return (0); } keypad (alphalist->win, TRUE); /* Set some variables. */ ScreenOf(alphalist) = cdkscreen; alphalist->parent = cdkscreen->window; alphalist->highlight = highlight; alphalist->fillerChar = fillerChar; alphalist->boxHeight = boxHeight; alphalist->boxWidth = boxWidth; alphalist->exitType = vNEVER_ACTIVATED; ObjOf(alphalist)->box = Box; alphalist->shadow = shadow; alphalist->shadowWin = 0; /* Do we want a shadow? */ if (shadow) { alphalist->shadowWin = newwin (boxHeight, boxWidth, ypos + 1, xpos + 1); } /* We need to sort the list before we use it. */ sortList (list, listSize); /* Copy the list information. */ for (x=0; x < listSize; x++) { alphalist->list[x] = copyChar (list[x]); } alphalist->listSize = listSize; /* Create the entry field. */ entryWidth = boxWidth - (labelLen + 4); alphalist->entryField = newCDKEntry (cdkscreen, getbegx(alphalist->win) + 1, getbegy(alphalist->win) + 1, title, label, A_NORMAL, fillerChar, vMIXED, entryWidth, 0, 512, Box, FALSE); setCDKEntryLLChar (alphalist->entryField, ACS_LTEE); setCDKEntryLRChar (alphalist->entryField, ACS_RTEE); /* Set the key bindings for the entry field. */ bindCDKObject (vENTRY, alphalist->entryField, KEY_UP, adjustAlphalistCB, alphalist); bindCDKObject (vENTRY, alphalist->entryField, KEY_DOWN, adjustAlphalistCB, alphalist); bindCDKObject (vENTRY, alphalist->entryField, KEY_NPAGE, adjustAlphalistCB, alphalist); bindCDKObject (vENTRY, alphalist->entryField, CONTROL('F'), adjustAlphalistCB, alphalist); bindCDKObject (vENTRY, alphalist->entryField, KEY_PPAGE, adjustAlphalistCB, alphalist); bindCDKObject (vENTRY, alphalist->entryField, CONTROL('B'), adjustAlphalistCB, alphalist); bindCDKObject (vENTRY, alphalist->entryField, KEY_TAB, completeWordCB, alphalist); /* Set up the post-process function for the entry field. */ setCDKEntryPreProcess (alphalist->entryField, preProcessEntryField, alphalist); /* Create the scrolling list. */ alphalist->scrollField = newCDKScroll (cdkscreen, getbegx(alphalist->win) + 1, getbegy(alphalist->win) + (alphalist->entryField)->titleLines + 3, RIGHT, boxHeight-((alphalist->entryField)->titleLines + 3), boxWidth-3, 0, list, listSize, NONUMBERS, A_REVERSE, Box, FALSE); setCDKScrollULChar (alphalist->scrollField, ACS_LTEE); setCDKScrollURChar (alphalist->scrollField, ACS_RTEE); /* Register this baby. */ registerCDKObject (cdkscreen, vALPHALIST, alphalist); /* Return the file selector pointer. */ return (alphalist); }
/* * This creates the alphalist widget. */ CDKALPHALIST *newCDKAlphalist (CDKSCREEN *cdkscreen, int xplace, int yplace, int height, int width, char *title, char *label, char **list, int listSize, chtype fillerChar, chtype highlight, boolean Box, boolean shadow) { CDKALPHALIST *alphalist = 0; chtype *chtypeLabel = 0; int parentWidth = getmaxx (cdkscreen->window); int parentHeight = getmaxy (cdkscreen->window); int boxWidth = width; int boxHeight = height; int xpos = xplace; int ypos = yplace; int tempWidth = 0; int tempHeight = 0; int labelLen = 0; int x, junk2; static const struct { int from; int to; } bindings[] = { { CDK_BACKCHAR, KEY_PPAGE }, { CDK_FORCHAR, KEY_NPAGE }, }; if ((alphalist = newCDKObject (CDKALPHALIST, &my_funcs)) == 0 || !createList (alphalist, list, listSize)) { destroyCDKObject (alphalist); return (0); } setCDKAlphalistBox (alphalist, 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); /* Translate the label char *pointer to a chtype pointer. */ if (label != 0) { chtypeLabel = char2Chtype (label, &labelLen, &junk2); freeChtype (chtypeLabel); } /* Rejustify the x and y positions if we need to. */ alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight); /* Make the file selector window. */ alphalist->win = newwin (boxHeight, boxWidth, ypos, xpos); if (alphalist->win == 0) { destroyCDKObject (alphalist); return (0); } keypad (alphalist->win, TRUE); /* Set some variables. */ ScreenOf (alphalist) = cdkscreen; alphalist->parent = cdkscreen->window; alphalist->highlight = highlight; alphalist->fillerChar = fillerChar; alphalist->boxHeight = boxHeight; alphalist->boxWidth = boxWidth; initExitType (alphalist); alphalist->shadow = shadow; alphalist->shadowWin = 0; /* Do we want a shadow? */ if (shadow) { alphalist->shadowWin = newwin (boxHeight, boxWidth, ypos + 1, xpos + 1); } /* Create the entry field. */ tempWidth = (isFullWidth (width) ? FULL : boxWidth - 2 - labelLen); alphalist->entryField = newCDKEntry (cdkscreen, getbegx (alphalist->win), getbegy (alphalist->win), title, label, A_NORMAL, fillerChar, vMIXED, tempWidth, 0, 512, Box, FALSE); if (alphalist->entryField == 0) { destroyCDKObject (alphalist); return (0); } setCDKEntryLLChar (alphalist->entryField, ACS_LTEE); setCDKEntryLRChar (alphalist->entryField, ACS_RTEE); /* Set the key bindings for the entry field. */ bindCDKObject (vENTRY, alphalist->entryField, KEY_UP, adjustAlphalistCB, alphalist); bindCDKObject (vENTRY, alphalist->entryField, KEY_DOWN, adjustAlphalistCB, alphalist); bindCDKObject (vENTRY, alphalist->entryField, KEY_NPAGE, adjustAlphalistCB, alphalist); bindCDKObject (vENTRY, alphalist->entryField, KEY_PPAGE, adjustAlphalistCB, alphalist); bindCDKObject (vENTRY, alphalist->entryField, KEY_TAB, completeWordCB, alphalist); /* Set up the post-process function for the entry field. */ setCDKEntryPreProcess (alphalist->entryField, preProcessEntryField, alphalist); /* * Create the scrolling list. It overlaps the entry field by one line if * we are using box-borders. */ tempHeight = getmaxy (alphalist->entryField->win) - BorderOf (alphalist); tempWidth = (isFullWidth (width) ? FULL : boxWidth - 1); alphalist->scrollField = newCDKScroll (cdkscreen, getbegx (alphalist->win), getbegy (alphalist->entryField->win) + tempHeight, RIGHT, boxHeight - tempHeight, tempWidth, 0, list, listSize, NONUMBERS, A_REVERSE, Box, FALSE); setCDKScrollULChar (alphalist->scrollField, ACS_LTEE); setCDKScrollURChar (alphalist->scrollField, ACS_RTEE); /* Setup the key bindings. */ for (x = 0; x < (int) SIZEOF (bindings); ++x) bindCDKObject (vALPHALIST, alphalist, bindings[x].from, getcCDKBind, (void *)(long)bindings[x].to); registerCDKObject (cdkscreen, vALPHALIST, alphalist); return (alphalist); }
int main (int argc, char **argv) { /* Declare variables. */ CDKSCREEN *cdkScreen = 0; CDKVIEWER *widget = 0; WINDOW *cursesWindow = 0; char *filename = 0; char *CDK_WIDGET_COLOR = 0; char *temp = 0; chtype *holder = 0; int answer = 0; int messageLines = -1; int buttonCount = 0; char **messageList = 0; char **buttonList = 0; char tempTitle[256]; int j1, j2; CDK_PARAMS params; boolean boxWidget; boolean interpret; boolean shadowWidget; boolean showInfoLine; char *buttons; char *title; int height; int width; int xpos; int ypos; CDKparseParams(argc, argv, ¶ms, "f:il:B:T:" CDK_CLI_PARAMS); xpos = CDKparamValue(¶ms, 'X', CENTER); ypos = CDKparamValue(¶ms, 'Y', CENTER); height = CDKparamValue(¶ms, 'H', 20); width = CDKparamValue(¶ms, 'W', 60); boxWidget = CDKparamValue(¶ms, 'N', TRUE); shadowWidget = CDKparamValue(¶ms, 'S', FALSE); interpret = CDKparamValue(¶ms, 'i', FALSE); showInfoLine = CDKparamValue(¶ms, 'l', FALSE); filename = CDKparamString(¶ms, 'f'); buttons = CDKparamString(¶ms, 'B'); title = CDKparamString(¶ms, 'T'); /* Make sure they gave us a file to read. */ if (filename == 0) { fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage); ExitProgram (CLI_ERROR); } /* Read the file in. */ messageLines = CDKreadFile (filename, &messageList); /* Check if there was an error. */ if (messageLines == -1) { fprintf (stderr, "Error: Could not open the file %s\n", filename); ExitProgram (CLI_ERROR); } /* Set up the buttons of the viewer. */ if (buttons == 0) { buttonList[0] = copyChar ("OK"); buttonList[1] = copyChar ("Cancel"); buttonCount = 2; } else { /* Split the button list up. */ buttonList = CDKsplitString (buttons, '\n'); buttonCount = CDKcountStrings (buttonList); } /* Set up the title of the viewer. */ if (title == 0) { sprintf (tempTitle, "<C>Filename: </U>%s<!U>", filename); title = copyChar (tempTitle); } /* Set up CDK. */ cursesWindow = initscr(); cdkScreen = initCDKScreen (cursesWindow); /* Start color. */ initCDKColor(); /* Check if the user wants to set the background of the main screen. */ if ((temp = getenv ("CDK_SCREEN_COLOR")) != 0) { holder = char2Chtype (temp, &j1, &j2); wbkgd (cdkScreen->window, holder[0]); wrefresh (cdkScreen->window); freeChtype (holder); } /* Get the widget color background color. */ if ((CDK_WIDGET_COLOR = getenv ("CDK_WIDGET_COLOR")) == 0) { CDK_WIDGET_COLOR = 0; } /* Create the viewer widget. */ widget = newCDKViewer (cdkScreen, xpos, ypos, height, width, buttonList, buttonCount, A_REVERSE, boxWidget, shadowWidget); /* Check to make sure we created the file viewer. */ if (widget == 0) { CDKfreeStrings (messageList); CDKfreeStrings (buttonList); /* Shut down curses and CDK. */ destroyCDKScreen (cdkScreen); endCDK(); fprintf (stderr, "Error: Could not create the file viewer. Is the window too small?\n"); ExitProgram (CLI_ERROR); } /* Check if the user wants to set the background of the widget. */ setCDKViewerBackgroundColor (widget, CDK_WIDGET_COLOR); /* Set a binding for saving the info. */ bindCDKObject (vVIEWER, widget, 'S', widgetCB, 0); /* Set the information needed for the viewer. */ setCDKViewer (widget, title, messageList, messageLines, A_REVERSE, interpret, showInfoLine, TRUE); /* Activate the viewer. */ answer = activateCDKViewer (widget, 0); CDKfreeStrings (messageList); CDKfreeStrings (buttonList); destroyCDKViewer (widget); destroyCDKScreen (cdkScreen); endCDK(); /* Exit with the button number picked. */ ExitProgram (answer); }
int main (int argc, char **argv) { /* *INDENT-EQLS* */ CDKSCREEN *cdkScreen = 0; CDKTEMPLATE *widget = 0; CDKBUTTONBOX *buttonWidget = 0; WINDOW *cursesWindow = 0; char *answer = 0; char *tmp = 0; char *CDK_WIDGET_COLOR = 0; char *temp = 0; chtype *holder = 0; int buttonCount = 0; int selection = 0; int shadowHeight = 0; FILE *fp = stderr; char **buttonList = 0; int j1, j2; CDK_PARAMS params; boolean boxWidget; boolean mixPlate; boolean shadowWidget; char *buttons; char *defaultAnswer; char *label; char *my_overlay; char *outputFile; char *plate; char *title; int minimum; int xpos; int ypos; CDKparseParams (argc, argv, ¶ms, "d:m:o:p:B:L:O:P:T:" CDK_MIN_PARAMS); /* *INDENT-EQLS* */ xpos = CDKparamValue (¶ms, 'X', CENTER); ypos = CDKparamValue (¶ms, 'Y', CENTER); boxWidget = CDKparamValue (¶ms, 'N', TRUE); shadowWidget = CDKparamValue (¶ms, 'S', FALSE); minimum = CDKparamValue (¶ms, 'm', 0); mixPlate = CDKparamValue (¶ms, 'P', FALSE); defaultAnswer = CDKparamString (¶ms, 'd'); my_overlay = CDKparamString (¶ms, 'o'); plate = CDKparamString (¶ms, 'p'); buttons = CDKparamString (¶ms, 'B'); label = CDKparamString (¶ms, 'L'); outputFile = CDKparamString (¶ms, 'O'); title = CDKparamString (¶ms, 'T'); /* Make sure all the command line parameters were provided. */ if (plate == 0) { fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage); ExitProgram (CLI_ERROR); } /* If the user asked for an output file, try to open it. */ if (outputFile != 0) { if ((fp = fopen (outputFile, "w")) == 0) { fprintf (stderr, "%s: Can not open output file %s\n", argv[0], outputFile); ExitProgram (CLI_ERROR); } } /* Set up CDK. */ cursesWindow = initscr (); cdkScreen = initCDKScreen (cursesWindow); /* Start color. */ initCDKColor (); /* Check if the user wants to set the background of the main screen. */ if ((temp = getenv ("CDK_SCREEN_COLOR")) != 0) { holder = char2Chtype (temp, &j1, &j2); wbkgd (cdkScreen->window, holder[0]); wrefresh (cdkScreen->window); freeChtype (holder); } /* Get the widget color background color. */ if ((CDK_WIDGET_COLOR = getenv ("CDK_WIDGET_COLOR")) == 0) { CDK_WIDGET_COLOR = 0; } /* Create the template widget. */ widget = newCDKTemplate (cdkScreen, xpos, ypos, title, label, plate, my_overlay, boxWidget, shadowWidget); /* Check to make sure we created the widget. */ if (widget == 0) { /* Shut down curses and CDK. */ destroyCDKScreen (cdkScreen); endCDK (); fprintf (stderr, "Error: Could not create the template field. " "Is the window too small?\n"); ExitProgram (CLI_ERROR); } /* Split the buttons if they supplied some. */ if (buttons != 0) { /* Split the button list up. */ buttonList = CDKsplitString (buttons, '\n'); buttonCount = (int)CDKcountStrings ((CDK_CSTRING2) buttonList); /* We need to create a buttonbox widget. */ buttonWidget = newCDKButtonbox (cdkScreen, getbegx (widget->win), (getbegy (widget->win) + widget->boxHeight - 1), 1, widget->boxWidth - 1, 0, 1, buttonCount, (CDK_CSTRING2) buttonList, buttonCount, A_REVERSE, boxWidget, FALSE); setCDKButtonboxULChar (buttonWidget, ACS_LTEE); setCDKButtonboxURChar (buttonWidget, ACS_RTEE); /* * We need to set the lower left and right * characters of the widget. */ setCDKTemplateLLChar (widget, ACS_LTEE); setCDKTemplateLRChar (widget, ACS_RTEE); /* * Bind the Tab key in the widget to send a * Tab key to the button box widget. */ bindCDKObject (vTEMPLATE, widget, KEY_TAB, widgetCB, buttonWidget); bindCDKObject (vTEMPLATE, widget, CDK_NEXT, widgetCB, buttonWidget); bindCDKObject (vTEMPLATE, widget, CDK_PREV, widgetCB, buttonWidget); /* Check if the user wants to set the background of the widget. */ setCDKButtonboxBackgroundColor (buttonWidget, CDK_WIDGET_COLOR); /* Draw the button widget. */ drawCDKButtonbox (buttonWidget, boxWidget); } /* * If the user asked for a shadow, we need to create one. Do this instead * of using the shadow parameter because the button widget is not part of * the main widget and if the user asks for both buttons and a shadow, we * need to create a shadow big enough for both widgets. Create the shadow * window using the widgets shadowWin element, so screen refreshes will draw * them as well. */ if (shadowWidget == TRUE) { /* Determine the height of the shadow window. */ shadowHeight = (buttonWidget == 0 ? widget->boxHeight : widget->boxHeight + buttonWidget->boxHeight - 1); /* Create the shadow window. */ widget->shadowWin = newwin (shadowHeight, widget->boxWidth, getbegy (widget->win) + 1, getbegx (widget->win) + 1); /* Make sure we could have created the shadow window. */ if (widget->shadowWin != 0) { widget->shadow = TRUE; /* * We force the widget and buttonWidget to be drawn so the * buttonbox widget will be drawn when the widget is activated. * Otherwise the shadow window will draw over the button widget. */ drawCDKTemplate (widget, ObjOf (widget)->box); eraseCDKButtonbox (buttonWidget); drawCDKButtonbox (buttonWidget, ObjOf (buttonWidget)->box); } } /* Check if the user wants to set the background of the widget. */ setCDKTemplateBackgroundColor (widget, CDK_WIDGET_COLOR); /* If a default answer were proivded, set it in the widget. */ if (defaultAnswer != 0) { setCDKTemplateValue (widget, defaultAnswer); } /* If the user asked for a minimum value, set it. */ setCDKTemplateMin (widget, minimum); /* Activate the widget. */ tmp = activateCDKTemplate (widget, 0); /* If the user asked for plate mixing, give it to them. */ if (mixPlate == TRUE) { answer = mixCDKTemplate (widget); } else { answer = copyChar (tmp); } /* If there were buttons, get the button selected. */ if (buttonWidget != 0) { selection = buttonWidget->currentButton; destroyCDKButtonbox (buttonWidget); } /* End CDK. */ destroyCDKTemplate (widget); destroyCDKScreen (cdkScreen); endCDK (); /* Print the value from the widget. */ if (answer != 0) { fprintf (fp, "%s\n", answer); freeChar (answer); } fclose (fp); /* Exit with the button number picked. */ ExitProgram (selection); }