1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
/* $Id: viewer_ex2.c,v 1.8 2016/12/04 15:22:16 tom Exp $ */
#include <cdk_test.h>
#ifdef HAVE_XCURSES
char *XCursesProgramName = "viewer_ex";
#endif
/*
* This program demonstrates the viewFile() function.
*/
int main (int argc, char **argv)
{
/* *INDENT-EQLS* */
CDKSCREEN *cdkscreen = 0;
CDKFSELECT *fSelect = 0;
const char *button[5];
char vTitle[256];
const char *mesg[4];
char temp[256];
int selected;
CDK_PARAMS params;
char *filename; /* specify filename, bypassing fselect */
char *directory; /* specify starting directory for fselect */
int interp_it; /* interpret embedded markup */
CDKparseParams (argc, argv, ¶ms, "f:d:i" CDK_CLI_PARAMS);
/* *INDENT-EQLS* */
filename = CDKparamString (¶ms, 'f');
directory = CDKparamString2 (¶ms, 'd', ".");
interp_it = CDKparamNumber2 (¶ms, 'i', 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);
}
}
/* Set up the viewer title, and the contents to the widget. */
sprintf (vTitle, "<C></B/21>Filename:<!21></22>%20s<!22!B>", filename);
selected = viewFile (cdkscreen, vTitle, filename, (CDK_CSTRING2)button, 2);
/* Destroy the file selector widget (do not need filename anymore) */
destroyCDKFselect (fSelect);
/* Check how the person exited from the widget. */
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. */
destroyCDKScreen (cdkscreen);
endCDK ();
ExitProgram (EXIT_SUCCESS);
}
|