/* * This demonstrates the Cdk preprocess feature. */ int main (void) { /* *INDENT-EQLS* */ CDKSCREEN *cdkscreen = 0; CDKENTRY *widget = 0; const char *title = "<C>Type in anything you want\n<C>but the dreaded letter </B>G<!B>!"; char *info; const char *mesg[10]; char temp[256]; cdkscreen = initCDKScreen (NULL); /* Start CDK colors. */ initCDKColor (); /* Create the entry field widget. */ widget = newCDKEntry (cdkscreen, CENTER, CENTER, title, 0, A_NORMAL, '.', vMIXED, 40, 0, 256, TRUE, FALSE); /* Is the widget null? */ if (widget == 0) { /* Clean up. */ destroyCDKScreen (cdkscreen); endCDK (); printf ("Cannot create the entry box. Is the window too small?\n"); ExitProgram (EXIT_FAILURE); } setCDKEntryPreProcess (widget, entryPreProcessCB, 0); /* Activate the entry field. */ info = activateCDKEntry (widget, 0); /* Tell them what they typed. */ if (widget->exitType == vESCAPE_HIT) { mesg[0] = "<C>You hit escape. No information passed back."; mesg[1] = "", mesg[2] = "<C>Press any key to continue."; popupLabel (cdkscreen, (CDK_CSTRING2)mesg, 3); } else if (widget->exitType == vNORMAL) { mesg[0] = "<C>You typed in the following"; sprintf (temp, "<C>(%.*s)", (int)(sizeof (temp) - 20), info); mesg[1] = temp; mesg[2] = ""; mesg[3] = "<C>Press any key to continue."; popupLabel (cdkscreen, (CDK_CSTRING2)mesg, 4); } /* Clean up and exit. */ destroyCDKEntry (widget); destroyCDKScreen (cdkscreen); endCDK (); ExitProgram (EXIT_SUCCESS); }
static int show_text (CmdConfig *cmd_config, CameraWidget *text) { CDKENTRY *entry = NULL; const char *label, *value; char title[1024], *info; CHECK (gp_widget_get_value (text, &value)); CHECK (gp_widget_get_label (text, &label)); snprintf (title, sizeof (title), "<C></5>%s", label); entry = newCDKEntry (cmd_config->screen, CENTER, CENTER, title, _("Value: "), A_NORMAL, ' ', vMIXED, 40, 0, 256, TRUE, FALSE); if (!entry) return (GP_ERROR); setCDKEntryValue (entry, (char*) value); info = activateCDKEntry (entry, 0); if (entry->exitType == vNORMAL) { gp_widget_set_value (text, info); set_config (cmd_config); } destroyCDKEntry (entry); return (GP_OK); }
string Simpletui::inputString(string text,int maxlen, bool password) { CDKENTRY *entry=newCDKEntry(reinterpret_cast<CDKSCREEN*>(cdk),CENTER,CENTER,const_cast<char*>(text.c_str()),const_cast<char*>(""),A_NORMAL,'_',password?vHMIXED:vMIXED,maxlen,0 , maxlen,TRUE,FALSE); char* resulttext=activateCDKEntry(entry,NULL); if(resulttext==NULL) { destroyCDKEntry(entry); throw STActionAborted(); } string result(resulttext); destroyCDKEntry(entry); return result; }
/* * Run the Add Device Group dialog */ void addDevGrpDialog(CDKSCREEN *main_cdk_screen) { CDKENTRY *dev_grp_name_entry = 0; char attr_path[MAX_SYSFS_PATH_SIZE] = {0}, attr_value[MAX_SYSFS_ATTR_SIZE] = {0}; char *dev_grp_name = NULL, *error_msg = NULL; int temp_int = 0; while (1) { /* Get new device group name (entry widget) */ dev_grp_name_entry = newCDKEntry(main_cdk_screen, CENTER, CENTER, "<C></31/B>Add New Device Group\n", "</B>New Group Name (no spaces): ", COLOR_DIALOG_SELECT, '_' | COLOR_DIALOG_INPUT, vMIXED, SCST_DEV_GRP_NAME_LEN, 0, SCST_DEV_GRP_NAME_LEN, TRUE, FALSE); if (!dev_grp_name_entry) { errorDialog(main_cdk_screen, ENTRY_ERR_MSG, NULL); break; } setCDKEntryBoxAttribute(dev_grp_name_entry, COLOR_DIALOG_BOX); setCDKEntryBackgroundAttrib(dev_grp_name_entry, COLOR_DIALOG_TEXT); /* Draw the entry widget */ curs_set(1); dev_grp_name = activateCDKEntry(dev_grp_name_entry, 0); /* Check exit from widget */ if (dev_grp_name_entry->exitType == vNORMAL) { /* Check group name for bad characters */ if (!checkInputStr(main_cdk_screen, NAME_CHARS, dev_grp_name)) break; /* Add the new device group */ snprintf(attr_path, MAX_SYSFS_PATH_SIZE, "%s/device_groups/mgmt", SYSFS_SCST_TGT); snprintf(attr_value, MAX_SYSFS_ATTR_SIZE, "create %s", dev_grp_name); if ((temp_int = writeAttribute(attr_path, attr_value)) != 0) { SAFE_ASPRINTF(&error_msg, "Couldn't add SCST (ALUA) device group: %s", strerror(temp_int)); errorDialog(main_cdk_screen, error_msg, NULL); FREE_NULL(error_msg); } } break; } /* Done */ destroyCDKEntry(dev_grp_name_entry); return; }
void CDKEntry::setparm(char *title, char *label, int fieldwidth, int xpos, int ypos, bool box, chtype fillerchar) { entry = newCDKEntry (cdkscreen, xpos, ypos, title, label, A_NORMAL, fillerchar, vMIXED, fieldwidth, 0, 255, box, FALSE ); }
void CDKEntry::setparm(char *title, char *label, int fieldwidth, int xpos, int ypos) { entry = newCDKEntry (cdkscreen, xpos, ypos, title, label, A_NORMAL, ' ', vMIXED, fieldwidth, 0, 255, TRUE, FALSE ); }
void CDKEntry::setparm(char *title, char *label, int fieldwidth, int xpos, int ypos, bool box, chtype fillerchar, chtype fieldattribute, EDisplayType displayType) { entry = newCDKEntry (cdkscreen, xpos, ypos, title, label, fieldattribute, fillerchar, displayType, fieldwidth, 0, 255, box, FALSE ); }
static int show_time (CmdConfig *cmd_config, CameraWidget *date) { CDKENTRY *entry = NULL; const char *label, *info; char title[1024], time_string[9]; time_t time; struct tm *date_info; gp_widget_get_label (date, &label); snprintf (title, sizeof (title), "<C></5>%s", label); entry = newCDKEntry (cmd_config->screen, CENTER, CENTER, title, _("Time: "), A_NORMAL, ' ', vMIXED, 40, 0, 8, TRUE, FALSE); if (!entry) return (GP_ERROR); gp_widget_get_value (date, &time); date_info = localtime (&time); snprintf (time_string, sizeof (time_string), "%2i:%02i:%02i", date_info->tm_hour, date_info->tm_min, date_info->tm_sec); setCDKEntryValue (entry, time_string); setCDKEntryPreProcess (entry, time_preprocess, NULL); info = activateCDKEntry (entry, 0); if (entry->exitType == vNORMAL) { date_info = localtime (&time); sscanf (info, "%d:%d:%d", &date_info->tm_hour, &date_info->tm_min, &date_info->tm_sec); time = mktime (date_info); gp_widget_set_value (date, &time); set_config (cmd_config); } destroyCDKEntry (entry); return (GP_OK); }
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); }
/* * This program demonstrates the Cdk buttonbox widget. */ int main (void) { /* *INDENT-EQLS* */ CDKSCREEN *cdkscreen = 0; CDKBUTTONBOX *buttonWidget = 0; CDKENTRY *entry = 0; WINDOW *cursesWin = 0; const char *buttons[] = { " OK ", " Cancel " }; char *info = 0; int selection; /* Set up CDK. */ cursesWin = initscr (); cdkscreen = initCDKScreen (cursesWin); /* Start color. */ initCDKColor (); /* Create the entry widget. */ entry = newCDKEntry (cdkscreen, CENTER, CENTER, "<C>Enter a name", "Name ", A_NORMAL, '.', vMIXED, 40, 0, 256, TRUE, FALSE); if (entry == 0) { destroyCDKScreen (cdkscreen); endCDK (); fprintf (stderr, "Cannot create entry-widget\n"); ExitProgram (EXIT_FAILURE); } /* Create the button box widget. */ buttonWidget = newCDKButtonbox (cdkscreen, getbegx (entry->win), getbegy (entry->win) + entry->boxHeight - 1, 1, entry->boxWidth - 1, 0, 1, 2, (CDK_CSTRING2) buttons, 2, A_REVERSE, TRUE, FALSE); if (buttonWidget == 0) { destroyCDKScreen (cdkscreen); endCDK (); fprintf (stderr, "Cannot create buttonbox-widget\n"); ExitProgram (EXIT_FAILURE); } /* Set the lower left and right characters of the box. */ setCDKEntryLLChar (entry, ACS_LTEE); setCDKEntryLRChar (entry, ACS_RTEE); setCDKButtonboxULChar (buttonWidget, ACS_LTEE); setCDKButtonboxURChar (buttonWidget, ACS_RTEE); /* * Bind the Tab key in the entry field to send a * Tab key to the button box widget. */ bindCDKObject (vENTRY, entry, KEY_TAB, entryCB, buttonWidget); /* Activate the entry field. */ drawCDKButtonbox (buttonWidget, TRUE); info = copyChar (activateCDKEntry (entry, 0)); selection = buttonWidget->currentButton; /* Clean up. */ destroyCDKButtonbox (buttonWidget); destroyCDKEntry (entry); destroyCDKScreen (cdkscreen); endCDK (); printf ("You typed in (%s) and selected button (%s)\n", (info != 0) ? info : "<null>", buttons[selection]); freeChar (info); ExitProgram (EXIT_SUCCESS); }
CCDKEntry::CCDKEntry(CDKSCREEN *pScreen, int x, int y, char *title, char *label, int fwidth, int min, int max, EDisplayType DispType, chtype fillch, chtype fieldattr, bool box, bool shadow) : CBaseCDKWidget(box) { m_pEntry = newCDKEntry(pScreen, x, y, title, label, fieldattr, fillch, DispType, fwidth, min, max, box, shadow); if (!m_pEntry) throwerror(false, "Could not create input entry"); }
/* * 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); }
/* * 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); }
char *pedir_datos (char *tipo) { /* Declare variables. */ CDKBUTTONBOX *buttonWidget = 0; CDKENTRY *entry = 0; CDKENTRY *pass = 0; WINDOW *cursesWin = 0; char *info = 0; CDKSCREEN *cdkscreen = 0; int selection=0; char *buttons[] = {" OK ", " Cancel "}; /* Set up CDK. */ cursesWin = initscr (); cdkscreen = initCDKScreen (cursesWin); box(cursesWin,0,0); /* Start color. */ initCDKColor (); /* Create the entry widget. */ if(strcmp(tipo,"usuario")==0) { entry = newCDKEntry (cdkscreen, CENTER, CENTER, "<C>Usuario", "", A_NORMAL, '.', vMIXED, 40, 0, 256, TRUE, FALSE); } else { entry = newCDKEntry (cdkscreen, CENTER, CENTER, "<C>Contrasenia:", "", A_INVIS, '.', vMIXED, 40, 0, 256, TRUE, FALSE); } if (entry == 0) { destroyCDKScreen (cdkscreen); endCDK(); fprintf(stderr, "Cannot create entry-widget\n"); // ExitProgram (EXIT_FAILURE); } /* Create the button box widget. */ buttonWidget = newCDKButtonbox (cdkscreen, getbegx (entry->win), getbegy (entry->win) + entry->boxHeight - 1, 1, entry->boxWidth - 1, 0, 1, 2, buttons, 2, A_REVERSE, TRUE, FALSE); if (buttonWidget == 0) { destroyCDKScreen (cdkscreen); endCDK(); fprintf(stderr, "Cannot create buttonbox-widget\n"); // ExitProgram (EXIT_FAILURE); } /* Set the lower left and right characters of the box. */ setCDKEntryLLChar (entry, ACS_LTEE); setCDKEntryLRChar (entry, ACS_RTEE); setCDKButtonboxULChar (buttonWidget, ACS_LTEE); setCDKButtonboxURChar (buttonWidget, ACS_RTEE); /* * Bind the Tab key in the entry field to send a * Tab key to the button box widget. */ bindCDKObject (vENTRY, entry, KEY_TAB, entryCB, buttonWidget); /* Activate the entry field. */ drawCDKButtonbox (buttonWidget, TRUE); info = copyChar (activateCDKEntry (entry, 0)); selection = buttonWidget->currentButton; /* Clean up. */ destroyCDKButtonbox (buttonWidget); destroyCDKEntry (entry); destroyCDKScreen (cdkscreen); endCDK (); /* Spit out some info. */ /* printf ("You typed in (%s) and selected button (%s)\n", (info != 0) ? info : "<null>", buttons[selection]); */ // freeChar (info); return info; // ExitProgram (EXIT_SUCCESS); }
/* * This adds a marker to the calendar. */ static int createCalendarMarkCB (EObjectType objectType GCC_UNUSED, void *object, void *clientData, chtype key GCC_UNUSED) { /* *INDENT-EQLS* */ CDKCALENDAR *calendar = (CDKCALENDAR *)object; CDKENTRY *entry = 0; CDKITEMLIST *itemlist = 0; const char *items[] = { "Birthday", "Anniversary", "Appointment", "Other" }; char *description = 0; struct AppointmentInfo *appointmentInfo = (struct AppointmentInfo *)clientData; int current = appointmentInfo->appointmentCount; chtype marker; int selection; /* Create the itemlist widget. */ itemlist = newCDKItemlist (ScreenOf (calendar), CENTER, CENTER, 0, "Select Appointment Type: ", (CDK_CSTRING2)items, 4, 0, TRUE, FALSE); /* Get the appointment tye from the user. */ selection = activateCDKItemlist (itemlist, 0); /* They hit escape, kill the itemlist widget and leave. */ if (selection == -1) { destroyCDKItemlist (itemlist); drawCDKCalendar (calendar, ObjOf (calendar)->box); return (FALSE); } /* Destroy the itemlist and set the marker. */ destroyCDKItemlist (itemlist); drawCDKCalendar (calendar, ObjOf (calendar)->box); marker = GPAppointmentAttributes[selection]; /* Create the entry field for the description. */ entry = newCDKEntry (ScreenOf (calendar), CENTER, CENTER, "<C>Enter a description of the appointment.", "Description: ", A_NORMAL, (chtype)'.', vMIXED, 40, 1, 512, TRUE, FALSE); /* Get the description. */ description = activateCDKEntry (entry, 0); if (description == 0) { destroyCDKEntry (entry); drawCDKCalendar (calendar, ObjOf (calendar)->box); return (FALSE); } /* Destroy the entry and set the marker. */ description = copyChar (entry->info); destroyCDKEntry (entry); drawCDKCalendar (calendar, ObjOf (calendar)->box); /* Set the marker. */ setCDKCalendarMarker (calendar, calendar->day, calendar->month, calendar->year, marker); /* Keep the marker. */ appointmentInfo->appointment[current].day = calendar->day; appointmentInfo->appointment[current].month = calendar->month; appointmentInfo->appointment[current].year = calendar->year; appointmentInfo->appointment[current].type = (EAppointmentType) selection; appointmentInfo->appointment[current].description = description; appointmentInfo->appointmentCount++; /* Redraw the calendar. */ drawCDKCalendar (calendar, ObjOf (calendar)->box); return (FALSE); }
/* * 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); }
/* * Run the Add Target to Group dialog */ void addTgtToGrpDialog(CDKSCREEN *main_cdk_screen) { WINDOW *add_tgt_window = 0; CDKSCREEN *add_tgt_screen = 0; CDKLABEL *add_tgt_info = 0; CDKENTRY *tgt_name = 0; CDKSCALE *rel_tgt_id = 0; CDKBUTTON *ok_button = 0, *cancel_button = 0; tButtonCallback ok_cb = &okButtonCB, cancel_cb = &cancelButtonCB; char dev_grp_name[MAX_SYSFS_ATTR_SIZE] = {0}, tgt_grp_name[MAX_SYSFS_ATTR_SIZE] = {0}, attr_path[MAX_SYSFS_PATH_SIZE] = {0}, attr_value[MAX_SYSFS_ATTR_SIZE] = {0}; char *error_msg = NULL; char *add_tgt_info_msg[TGT_GRP_INFO_LINES] = {NULL}; int add_tgt_window_lines = 0, add_tgt_window_cols = 0, window_y = 0, window_x = 0, temp_int = 0, i = 0, traverse_ret = 0; /* Have the user choose a SCST device group */ getSCSTDevGrpChoice(main_cdk_screen, dev_grp_name); if (dev_grp_name[0] == '\0') return; /* Get target group choice from user (based on previously * selected device group) */ getSCSTTgtGrpChoice(main_cdk_screen, dev_grp_name, tgt_grp_name); if (tgt_grp_name[0] == '\0') return; /* New CDK screen */ add_tgt_window_lines = 11; add_tgt_window_cols = 55; window_y = ((LINES / 2) - (add_tgt_window_lines / 2)); window_x = ((COLS / 2) - (add_tgt_window_cols / 2)); add_tgt_window = newwin(add_tgt_window_lines, add_tgt_window_cols, window_y, window_x); if (add_tgt_window == NULL) { errorDialog(main_cdk_screen, NEWWIN_ERR_MSG, NULL); return; } add_tgt_screen = initCDKScreen(add_tgt_window); if (add_tgt_screen == NULL) { errorDialog(main_cdk_screen, CDK_SCR_ERR_MSG, NULL); return; } boxWindow(add_tgt_window, COLOR_DIALOG_BOX); wbkgd(add_tgt_window, COLOR_DIALOG_TEXT); wrefresh(add_tgt_window); while (1) { /* Information label */ SAFE_ASPRINTF(&add_tgt_info_msg[0], "</31/B>Adding SCST target to target group..."); SAFE_ASPRINTF(&add_tgt_info_msg[1], " "); SAFE_ASPRINTF(&add_tgt_info_msg[2], "</B>Device group:<!B>\t%s", dev_grp_name); SAFE_ASPRINTF(&add_tgt_info_msg[3], "</B>Target group:<!B>\t%s", tgt_grp_name); add_tgt_info = newCDKLabel(add_tgt_screen, (window_x + 1), (window_y + 1), add_tgt_info_msg, ADD_TGT_INFO_LINES, FALSE, FALSE); if (!add_tgt_info) { errorDialog(main_cdk_screen, LABEL_ERR_MSG, NULL); break; } setCDKLabelBackgroundAttrib(add_tgt_info, COLOR_DIALOG_TEXT); /* Target name (entry) */ tgt_name = newCDKEntry(add_tgt_screen, (window_x + 1), (window_y + 6), NULL, "</B>Target Name: ", COLOR_DIALOG_SELECT, '_' | COLOR_DIALOG_INPUT, vMIXED, 20, 0, SCST_TGT_NAME_LEN, FALSE, FALSE); if (!tgt_name) { errorDialog(main_cdk_screen, ENTRY_ERR_MSG, NULL); break; } setCDKEntryBoxAttribute(tgt_name, COLOR_DIALOG_INPUT); /* Relative target ID (scale) */ rel_tgt_id = newCDKScale(add_tgt_screen, (window_x + 1), (window_y + 7), NULL, "</B>Relative Target ID: ", COLOR_DIALOG_SELECT, 7, 0, MIN_SCST_REL_TGT_ID, MAX_SCST_REL_TGT_ID, 1, 100, FALSE, FALSE); if (!rel_tgt_id) { errorDialog(main_cdk_screen, SCALE_ERR_MSG, NULL); break; } setCDKScaleBackgroundAttrib(rel_tgt_id, COLOR_DIALOG_TEXT); /* Buttons */ ok_button = newCDKButton(add_tgt_screen, (window_x + 16), (window_y + 9), g_ok_cancel_msg[0], ok_cb, FALSE, FALSE); if (!ok_button) { errorDialog(main_cdk_screen, BUTTON_ERR_MSG, NULL); break; } setCDKButtonBackgroundAttrib(ok_button, COLOR_DIALOG_INPUT); cancel_button = newCDKButton(add_tgt_screen, (window_x + 26), (window_y + 9), g_ok_cancel_msg[1], cancel_cb, FALSE, FALSE); if (!cancel_button) { errorDialog(main_cdk_screen, BUTTON_ERR_MSG, NULL); break; } setCDKButtonBackgroundAttrib(cancel_button, COLOR_DIALOG_INPUT); /* Allow user to traverse the screen */ refreshCDKScreen(add_tgt_screen); traverse_ret = traverseCDKScreen(add_tgt_screen); /* User hit 'OK' button */ if (traverse_ret == 1) { /* Turn the cursor off (pretty) */ curs_set(0); /* Check the entry field for bad characters */ if (!checkInputStr(main_cdk_screen, INIT_CHARS, getCDKEntryValue(tgt_name))) break; /* Add the target to the target group */ snprintf(attr_path, MAX_SYSFS_PATH_SIZE, "%s/device_groups/%s/target_groups/%s/mgmt", SYSFS_SCST_TGT, dev_grp_name, tgt_grp_name); snprintf(attr_value, MAX_SYSFS_ATTR_SIZE, "add %s", getCDKEntryValue(tgt_name)); if ((temp_int = writeAttribute(attr_path, attr_value)) != 0) { SAFE_ASPRINTF(&error_msg, "Couldn't add SCST (ALUA) target to target group: %s", strerror(temp_int)); errorDialog(main_cdk_screen, error_msg, NULL); FREE_NULL(error_msg); break; } /* Set the relative target ID */ snprintf(attr_path, MAX_SYSFS_PATH_SIZE, "%s/device_groups/%s/target_groups/%s/%s/rel_tgt_id", SYSFS_SCST_TGT, dev_grp_name, tgt_grp_name, getCDKEntryValue(tgt_name)); snprintf(attr_value, MAX_SYSFS_ATTR_SIZE, "%d", getCDKScaleValue(rel_tgt_id)); if ((temp_int = writeAttribute(attr_path, attr_value)) != 0) { SAFE_ASPRINTF(&error_msg, SET_REL_TGT_ID_ERR, strerror(temp_int)); errorDialog(main_cdk_screen, error_msg, NULL); FREE_NULL(error_msg); break; } } break; } /* Done */ for (i = 0; i < ADD_TGT_INFO_LINES; i++) FREE_NULL(add_tgt_info_msg[i]); if (add_tgt_screen != NULL) { destroyCDKScreenObjects(add_tgt_screen); destroyCDKScreen(add_tgt_screen); delwin(add_tgt_window); } return; }
/* * 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 demonstrates the Cdk preprocess feature. */ int main (void) { /* Declare local variables. */ CDKSCREEN *cdkscreen = 0; CDKENTRY *widget = 0; WINDOW *cursesWin = 0; char *title = "<C>Type in anything you want\n<C>but the dreaded letter </B>G<!B>!"; char *info, *mesg[10], temp[256]; /* Set up CDK. */ cursesWin = initscr(); cdkscreen = initCDKScreen (cursesWin); /* Start CDK colors. */ initCDKColor(); /* Create the entry field widget. */ widget = newCDKEntry (cdkscreen, CENTER, CENTER, title, 0, A_NORMAL, '.', vMIXED, 40, 0, 256, TRUE, FALSE); /* Is the widget null? */ if (widget == 0) { /* Clean up. */ destroyCDKScreen (cdkscreen); endCDK(); /* Print out a little message. */ printf ("Oops. Can't seem to create the entry box. Is the window too small?\n"); ExitProgram (EXIT_FAILURE); } setCDKEntryPreProcess (widget, entryPreProcessCB, 0); /* Activate the entry field. */ info = activateCDKEntry (widget, 0); /* Tell them what they typed. */ if (widget->exitType == vESCAPE_HIT) { mesg[0] = "<C>You hit escape. No information passed back."; mesg[1] = "", mesg[2] = "<C>Press any key to continue."; popupLabel (cdkscreen, mesg, 3); } else if (widget->exitType == vNORMAL) { mesg[0] = "<C>You typed in the following"; sprintf (temp, "<C>(%.*s)", (int)(sizeof(temp) - 20), info); mesg[1] = copyChar (temp); mesg[2] = ""; mesg[3] = "<C>Press any key to continue."; popupLabel (cdkscreen, mesg, 4); freeChar (mesg[1]); } /* Clean up and exit. */ destroyCDKEntry (widget); destroyCDKScreen (cdkscreen); endCDK(); ExitProgram (EXIT_SUCCESS); }