/* * This allows the user to view information. */ int viewInfo (CDKSCREEN *screen, char *title, char **info, int count, char **buttons, int buttonCount, boolean interpret) { CDKVIEWER *viewer = 0; int selected = -1; /* Create the file viewer to view the file selected.*/ viewer = newCDKViewer (screen, CENTER, CENTER, -6, -16, buttons, buttonCount, A_REVERSE, TRUE, TRUE); /* Set up the viewer title, and the contents to the widget. */ setCDKViewer (viewer, title, info, count, A_REVERSE, interpret, TRUE, TRUE); /* Activate the viewer widget. */ selected = activateCDKViewer (viewer, 0); /* Make sure they exited normally. */ if (viewer->exitType != vNORMAL) { destroyCDKViewer (viewer); return (-1); } /* Clean up and return the button index selected. */ destroyCDKViewer (viewer); return selected; }
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* */ CDKVIEWER *example = 0; CDKFSELECT *fSelect = 0; WINDOW *cursesWin = 0; const char *title = "<C>Pick\n<C>A\n<C>File"; const char *label = "File: "; char **info = 0; const char *button[5]; const char *mesg[4]; char *filename; char vTitle[256]; char temp[256]; int selected, lines; CDK_PARAMS params; char *directory; CDKparseParams (argc, argv, ¶ms, "d:" CDK_CLI_PARAMS); directory = CDKparamString2 (¶ms, 'd', "."); /* Create the viewer buttons. */ button[0] = "</5><OK><!5>"; button[1] = "</5><Cancel><!5>"; /* Set up CDK. */ cursesWin = initscr (); cdkscreen = initCDKScreen (cursesWin); /* Start color. */ initCDKColor (); /* Get the filename. */ fSelect = newCDKFselect (cdkscreen, CDKparamValue (¶ms, 'X', CENTER), CDKparamValue (¶ms, 'Y', CENTER), CDKparamValue (¶ms, 'H', 20), CDKparamValue (¶ms, 'W', 65), title, label, A_NORMAL, '_', A_REVERSE, "</5>", "</48>", "</N>", "</N>", CDKparamValue (¶ms, 'N', TRUE), CDKparamValue (¶ms, 'S', FALSE)); if (fSelect == 0) { destroyCDKScreen (cdkscreen); endCDK (); fprintf (stderr, "Cannot create widget\n"); ExitProgram (EXIT_FAILURE); } bindCDKObject (vFSELECT, fSelect, '?', do_help, NULL); bindCDKObject (vFSELECT, fSelect, KEY_F1, do_help, NULL); bindCDKObject (vFSELECT, fSelect, KEY_F2, do_delete, fSelect); bindCDKObject (vFSELECT, fSelect, KEY_F3, do_delete1, fSelect); bindCDKObject (vFSELECT, fSelect, KEY_F4, do_reload, fSelect); bindCDKObject (vFSELECT, fSelect, KEY_F5, do_undo, fSelect); /* * Set the starting directory. This is not necessary because when * the file selector starts it uses the present directory as a default. */ setCDKFselect (fSelect, directory, A_NORMAL, ' ', A_REVERSE, "</5>", "</48>", "</N>", "</N>", ObjOf (fSelect)->box); myUserList = copyCharList ((const char **)getCDKFselectContents (fSelect, &userSize)); myUndoList = (UNDO *) malloc ((size_t) userSize * sizeof (UNDO)); undoSize = 0; /* Activate the file selector. */ filename = activateCDKFselect (fSelect, 0); /* Check how the person exited from the widget. */ if (fSelect->exitType == vESCAPE_HIT) { /* Pop up a message for the user. */ mesg[0] = "<C>Escape hit. No file selected."; mesg[1] = ""; mesg[2] = "<C>Press any key to continue."; popupLabel (cdkscreen, (CDK_CSTRING2)mesg, 3); /* Exit CDK. */ destroyCDKFselect (fSelect); destroyCDKScreen (cdkscreen); endCDK (); ExitProgram (EXIT_SUCCESS); } /* Create the file viewer to view the file selected. */ example = newCDKViewer (cdkscreen, CENTER, CENTER, 20, -2, (CDK_CSTRING2)button, 2, A_REVERSE, TRUE, FALSE); /* Could we create the viewer widget? */ if (example == 0) { /* Exit CDK. */ destroyCDKFselect (fSelect); destroyCDKScreen (cdkscreen); endCDK (); printf ("Can't seem to create viewer. Is the window too small?\n"); ExitProgram (EXIT_SUCCESS); } /* Open the file and read the contents. */ lines = CDKreadFile (filename, &info); if (lines == -1) { filename = copyChar (filename); destroyCDKFselect (fSelect); destroyCDKScreen (cdkscreen); endCDK (); printf ("Could not open \"%s\"\n", filename); ExitProgram (EXIT_FAILURE); } /* Set up the viewer title, and the contents to the widget. */ sprintf (vTitle, "<C></B/21>Filename:<!21></22>%20s<!22!B>", filename); setCDKViewer (example, vTitle, (CDK_CSTRING2)info, lines, A_REVERSE, TRUE, TRUE, TRUE); CDKfreeStrings (info); /* Destroy the file selector widget. */ destroyCDKFselect (fSelect); /* Activate the viewer widget. */ selected = activateCDKViewer (example, 0); /* Check how the person exited from the widget. */ if (example->exitType == vESCAPE_HIT) { mesg[0] = "<C>Escape hit. No Button selected."; mesg[1] = ""; mesg[2] = "<C>Press any key to continue."; popupLabel (cdkscreen, (CDK_CSTRING2)mesg, 3); } else if (example->exitType == vNORMAL) { sprintf (temp, "<C>You selected button %d", selected); mesg[0] = temp; mesg[1] = ""; mesg[2] = "<C>Press any key to continue."; popupLabel (cdkscreen, (CDK_CSTRING2)mesg, 3); } /* Clean up. */ destroyCDKViewer (example); destroyCDKScreen (cdkscreen); endCDK (); ExitProgram (EXIT_SUCCESS); }
/* * This program demonstrates the file selector and the viewer widget. */ int main (int argc, char **argv) { /* *INDENT-EQLS* */ CDKSCREEN *cdkscreen = 0; CDKVIEWER *example = 0; CDKFSELECT *fSelect = 0; WINDOW *cursesWin = 0; const char *title = "<C>Pick a file."; const char *label = "File: "; const char *directory = "."; char *filename = 0; char **info = 0; const char *button[5]; const char *mesg[4]; char vtitle[256]; char temp[256]; int selected, lines, ret; /* Parse up the command line. */ while (1) { ret = getopt (argc, argv, "d:f:"); if (ret == -1) { break; } switch (ret) { case 'd': directory = strdup (optarg); break; case 'f': filename = strdup (optarg); break; } } /* Create the viewer buttons. */ button[0] = "</5><OK><!5>"; button[1] = "</5><Cancel><!5>"; /* Set up CDK. */ cursesWin = initscr (); cdkscreen = initCDKScreen (cursesWin); /* Start color. */ initCDKColor (); /* Get the filename. */ if (filename == 0) { fSelect = newCDKFselect (cdkscreen, CENTER, CENTER, 20, 65, title, label, A_NORMAL, '_', A_REVERSE, "</5>", "</48>", "</N>", "</N>", TRUE, FALSE); /* * Set the starting directory. This is not neccessary because when * the file selector starts it uses the present directory as a default. */ setCDKFselect (fSelect, directory, A_NORMAL, '.', A_REVERSE, "</5>", "</48>", "</N>", "</N>", ObjOf (fSelect)->box); /* Activate the file selector. */ filename = copyChar (activateCDKFselect (fSelect, 0)); /* Check how the person exited from the widget. */ if (fSelect->exitType == vESCAPE_HIT) { /* Pop up a message for the user. */ mesg[0] = "<C>Escape hit. No file selected."; mesg[1] = ""; mesg[2] = "<C>Press any key to continue."; popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 3); /* Destroy the file selector. */ destroyCDKFselect (fSelect); /* Exit CDK. */ destroyCDKScreen (cdkscreen); endCDK (); ExitProgram (EXIT_SUCCESS); } } /* Destroy the file selector. */ destroyCDKFselect (fSelect); /* Create the file viewer to view the file selected. */ example = newCDKViewer (cdkscreen, CENTER, CENTER, 20, -2, (CDK_CSTRING2) button, 2, A_REVERSE, TRUE, FALSE); /* Could we create the viewer widget? */ if (example == 0) { /* Exit CDK. */ destroyCDKScreen (cdkscreen); endCDK (); /* Print out a message and exit. */ printf ("Cannot create viewer. Is the window too small?\n"); ExitProgram (EXIT_SUCCESS); } /* Open the file and read the contents. */ lines = CDKreadFile (filename, &info); if (lines == -1) { printf ("Could not open %s\n", filename); ExitProgram (EXIT_FAILURE); } /* Set up the viewer title, and the contents to the widget. */ sprintf (vtitle, "<C></B/22>%20s<!22!B>", filename); setCDKViewer (example, vtitle, (CDK_CSTRING2) info, lines, A_REVERSE, TRUE, TRUE, TRUE); /* Activate the viewer widget. */ selected = activateCDKViewer (example, 0); /* Check how the person exited from the widget. */ if (example->exitType == vESCAPE_HIT) { mesg[0] = "<C>Escape hit. No Button selected."; mesg[1] = ""; mesg[2] = "<C>Press any key to continue."; popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 3); } else if (example->exitType == vNORMAL) { sprintf (temp, "<C>You selected button %d", selected); mesg[0] = temp; mesg[1] = ""; mesg[2] = "<C>Press any key to continue."; popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 3); } /* Clean up. */ destroyCDKViewer (example); destroyCDKScreen (cdkscreen); CDKfreeStrings (info); freeChar (filename); endCDK (); ExitProgram (EXIT_SUCCESS); }
/* * This program demonstrates the file selector and the viewer widget. */ int main (int argc, char **argv) { /* *INDENT-EQLS* */ CDKSCREEN *cdkscreen = 0; CDKVIEWER *example = 0; CDKFSELECT *fSelect = 0; char **info = 0; const char *button[5]; char vTitle[256]; const char *mesg[4]; char temp[256]; int selected, lines; CDK_PARAMS params; char *filename; /* specify filename, bypassing fselect */ char *directory; /* specify starting directory for fselect */ int interp_it; /* interpret embedded markup */ int link_it; /* load file via embedded link */ CDKparseParams (argc, argv, ¶ms, "f:d:il" CDK_CLI_PARAMS); /* *INDENT-EQLS* */ filename = CDKparamString (¶ms, 'f'); directory = CDKparamString2 (¶ms, 'd', "."); interp_it = CDKparamNumber2 (¶ms, 'i', FALSE); link_it = CDKparamNumber2 (¶ms, 'l', FALSE); /* Create the viewer buttons. */ button[0] = "</5><OK><!5>"; button[1] = "</5><Cancel><!5>"; cdkscreen = initCDKScreen (NULL); /* Start color. */ initCDKColor (); /* Get the filename. */ if (filename == 0) { const char *title = "<C>Pick\n<C>A\n<C>File"; const char *label = "File: "; fSelect = newCDKFselect (cdkscreen, CDKparamValue (¶ms, 'X', CENTER), CDKparamValue (¶ms, 'Y', CENTER), CDKparamValue (¶ms, 'H', 20), CDKparamValue (¶ms, 'W', 65), title, label, A_NORMAL, '_', A_REVERSE, "</5>", "</48>", "</N>", "</N>", CDKparamValue (¶ms, 'N', TRUE), CDKparamValue (¶ms, 'S', FALSE)); if (fSelect == 0) { destroyCDKScreen (cdkscreen); endCDK (); fprintf (stderr, "Cannot create fselect-widget\n"); ExitProgram (EXIT_FAILURE); } /* * Set the starting directory. This is not necessary because when * the file selector starts it uses the present directory as a default. */ setCDKFselect (fSelect, directory, A_NORMAL, '.', A_REVERSE, "</5>", "</48>", "</N>", "</N>", ObjOf (fSelect)->box); /* Activate the file selector. */ filename = activateCDKFselect (fSelect, 0); /* Check how the person exited from the widget. */ if (fSelect->exitType == vESCAPE_HIT) { /* Pop up a message for the user. */ mesg[0] = "<C>Escape hit. No file selected."; mesg[1] = ""; mesg[2] = "<C>Press any key to continue."; popupLabel (cdkscreen, (CDK_CSTRING2)mesg, 3); /* Exit CDK. */ destroyCDKFselect (fSelect); destroyCDKScreen (cdkscreen); endCDK (); ExitProgram (EXIT_SUCCESS); } } /* Create the file viewer to view the file selected. */ example = newCDKViewer (cdkscreen, CDKparamValue (¶ms, 'X', CENTER), CDKparamValue (¶ms, 'Y', CENTER), CDKparamValue (¶ms, 'H', 20), CDKparamValue (¶ms, 'W', -2), (CDK_CSTRING2)button, 2, A_REVERSE, CDKparamValue (¶ms, 'N', TRUE), CDKparamValue (¶ms, 'S', FALSE)); /* Could we create the viewer widget? */ if (example == 0) { /* Exit CDK. */ destroyCDKFselect (fSelect); destroyCDKScreen (cdkscreen); endCDK (); printf ("Cannot create viewer. Is the window too small?\n"); ExitProgram (EXIT_SUCCESS); } if (link_it) { info = (char **)calloc (2, sizeof (char *)); info[0] = (char *)malloc (5 + strlen (filename)); sprintf (info[0], "<F=%s>", filename); lines = -1; interp_it = TRUE; } else { setCDKViewer (example, "reading...", 0, 0, A_REVERSE, TRUE, TRUE, TRUE); /* Open the file and read the contents. */ lines = CDKreadFile (filename, &info); if (lines == -1) { endCDK (); printf ("Could not open \"%s\"\n", filename); ExitProgram (EXIT_FAILURE); } } /* Set up the viewer title, and the contents to the widget. */ sprintf (vTitle, "<C></B/21>Filename:<!21></22>%20s<!22!B>", filename); setCDKViewer (example, vTitle, (CDK_CSTRING2)info, lines, A_REVERSE, interp_it, TRUE, TRUE); CDKfreeStrings (info); /* Destroy the file selector widget. */ destroyCDKFselect (fSelect); /* Activate the viewer widget. */ selected = activateCDKViewer (example, 0); /* Check how the person exited from the widget. */ if (example->exitType == vESCAPE_HIT) { mesg[0] = "<C>Escape hit. No Button selected."; mesg[1] = ""; mesg[2] = "<C>Press any key to continue."; popupLabel (cdkscreen, (CDK_CSTRING2)mesg, 3); } else if (example->exitType == vNORMAL) { sprintf (temp, "<C>You selected button %d", selected); mesg[0] = temp; mesg[1] = ""; mesg[2] = "<C>Press any key to continue."; popupLabel (cdkscreen, (CDK_CSTRING2)mesg, 3); } /* Clean up. */ destroyCDKViewer (example); destroyCDKScreen (cdkscreen); endCDK (); ExitProgram (EXIT_SUCCESS); }