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; }
/* * This destroys the file selector. */ void destroyCDKFselect (CDKFSELECT *fselect) { /* Erase the file selector. */ eraseCDKFselect (fselect); /* Free up the character pointers. */ freeChar (fselect->pwd); freeChar (fselect->pathname); freeChar (fselect->dirAttribute); freeChar (fselect->fileAttribute); freeChar (fselect->linkAttribute); freeChar (fselect->sockAttribute); freeCharList (fselect->dirContents, fselect->fileCounter); /* Destroy the other Cdk objects. */ destroyCDKScroll (fselect->scrollField); destroyCDKEntry (fselect->entryField); /* Free up the window pointers. */ deleteCursesWindow (fselect->shadowWin); deleteCursesWindow (fselect->win); /* Unregister the object. */ unregisterCDKObject (vFSELECT, fselect); /* Free up the object pointer. */ free (fselect); }
/* * 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); }
void CCDKEntry::Destroy() { if (!m_pEntry) return; CBaseCDKWidget::Destroy(); destroyCDKEntry(m_pEntry); m_pEntry = NULL; }
CDKEntry::~CDKEntry() { warning ("CDKEntry::~CDKEntry"); if (entry) { destroyCDKEntry (entry); } entry=NULL; };
void CDKEntry::destroy() { warning ("CDKEntry::destroy () at %p", entry); if (entry) { destroyCDKEntry (entry); } entry=NULL; warning ("end CDKEntry::destroy ()"); }
/* * 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; }
/* * This destroys the file selector. */ void destroyCDKAlphalist (CDKALPHALIST *alphalist) { /* Erase the file selector. */ eraseCDKAlphalist (alphalist); freeCharList (alphalist->list, alphalist->listSize); /* Destroy the other Cdk objects. */ destroyCDKEntry (alphalist->entryField); destroyCDKScroll (alphalist->scrollField); /* Free up the window pointers. */ deleteCursesWindow (alphalist->shadowWin); deleteCursesWindow (alphalist->win); /* Unregister the object. */ unregisterCDKObject (vALPHALIST, alphalist); /* Free up the object pointer. */ free (alphalist); }
/* * This destroys the file selector. */ static void _destroyCDKAlphalist (CDKOBJS *object) { if (object != 0) { CDKALPHALIST *alphalist = (CDKALPHALIST *)object; destroyInfo (alphalist); /* Clean the key bindings. */ cleanCDKObjectBindings (vALPHALIST, alphalist); destroyCDKEntry (alphalist->entryField); destroyCDKScroll (alphalist->scrollField); /* Free up the window pointers. */ deleteCursesWindow (alphalist->shadowWin); deleteCursesWindow (alphalist->win); /* Unregister the object. */ unregisterCDKObject (vALPHALIST, alphalist); } }
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); }
/* * 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); }
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); }
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 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); }
/* * 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); }