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 115 116 117 118 119 120 121 122 123
|
/* $Id: selection_ex.c,v 1.15 2005/12/28 01:46:34 tom Exp $ */
#include <cdk_test.h>
#ifdef HAVE_XCURSES
char *XCursesProgramName = "selection_ex";
#endif
/*
* This program demonstrates the Cdk selection widget.
*
* Options (in addition to normal CLI parameters):
* -c create the data after the widget
* -s SPOS location for the scrollbar
* -t TEXT title for the widget
*
*/
int main (int argc, char **argv)
{
/* Declare variables. */
CDKSCREEN *cdkscreen = 0;
CDKSELECTION *selection = 0;
WINDOW *cursesWin = 0;
char *title = "<C></5>Pick one or more accounts.";
char *choices[] = {" ", "-->"};
char **item = 0;
char temp[256], *mesg[200];
struct passwd *ent;
unsigned x, y;
unsigned used = 0;
unsigned count = 0;
CDK_PARAMS params;
CDKparseParams(argc, argv, ¶ms, "cs:t:" CDK_CLI_PARAMS);
/* Use the account names to create a list. */
count = 0;
while ((ent = getpwent ()) != 0)
{
used = CDKallocStrings(&item, ent->pw_name, count++, used);
}
endpwent();
count--;
/* Set up CDK. */
cursesWin = initscr();
cdkscreen = initCDKScreen (cursesWin);
/* Set up CDK Colors. */
initCDKColor();
/* Create the selection list. */
selection = newCDKSelection (cdkscreen,
CDKparamValue(¶ms, 'X', CENTER),
CDKparamValue(¶ms, 'Y', CENTER),
CDKparsePosition(CDKparamString2(¶ms, 's', "RIGHT")),
CDKparamValue(¶ms, 'H', 10),
CDKparamValue(¶ms, 'W', 50),
CDKparamString2(¶ms, 't', title),
CDKparamNumber(¶ms, 'c') ? 0 : item,
CDKparamNumber(¶ms, 'c') ? 0 : count,
choices, 2,
A_REVERSE,
CDKparamValue(¶ms, 'N', TRUE),
CDKparamValue(¶ms, 'S', FALSE));
/* Is the selection list null? */
if (selection == 0)
{
/* Exit CDK. */
destroyCDKScreen (cdkscreen);
endCDK();
/* Print out a message and exit. */
printf ("Oops. Can;t seem to create the selection list. Is the window too small?\n");
ExitProgram (EXIT_FAILURE);
}
if (CDKparamNumber(¶ms, 'c'))
{
setCDKSelectionItems (selection, item, count);
}
/* Activate the selection list. */
activateCDKSelection (selection, 0);
/* Check the exit status of the widget. */
if (selection->exitType == vESCAPE_HIT)
{
mesg[0] = "<C>You hit escape. No items selected.";
mesg[1] = "",
mesg[2] = "<C>Press any key to continue.";
popupLabel (cdkscreen, mesg, 3);
}
else if (selection->exitType == vNORMAL)
{
mesg[0] = "<C>Here are the accounts you selected.";
y = 1;
for (x=0; x < count; x++)
{
if (selection->selections[x] == 1)
{
sprintf (temp, "<C></5>%.*s", (int)(sizeof(temp) - 20), item[x]);
mesg[y++] = copyChar (temp);
}
}
popupLabel (cdkscreen, mesg, y);
/* Clean up. */
for (x=1; x < y; x++)
{
freeChar (mesg[x]);
}
}
/* Clean up. */
CDKfreeStrings (item);
destroyCDKSelection (selection);
destroyCDKScreen (cdkscreen);
endCDK();
ExitProgram (EXIT_SUCCESS);
}
|