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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
/* $Id: scroll_ex.c,v 1.25 2016/12/04 15:22:16 tom Exp $ */
#include <cdk_test.h>
#ifdef HAVE_XCURSES
char *XCursesProgramName = "scroll_ex";
#endif
static char *newLabel (const char *prefix)
{
static int count;
static char result[80];
sprintf (result, "%s%d", prefix, ++count);
return result;
}
static int addItemCB (EObjectType cdktype GCC_UNUSED,
void *object,
void *clientData GCC_UNUSED,
chtype input GCC_UNUSED)
{
CDKSCROLL *s = (CDKSCROLL *)object;
addCDKScrollItem (s, newLabel ("add"));
refreshCDKScreen (ScreenOf (s));
return (TRUE);
}
static int insItemCB (EObjectType cdktype GCC_UNUSED,
void *object,
void *clientData GCC_UNUSED,
chtype input GCC_UNUSED)
{
CDKSCROLL *s = (CDKSCROLL *)object;
insertCDKScrollItem (s, newLabel ("insert"));
refreshCDKScreen (ScreenOf (s));
return (TRUE);
}
static int delItemCB (EObjectType cdktype GCC_UNUSED,
void *object,
void *clientData GCC_UNUSED,
chtype input GCC_UNUSED)
{
CDKSCROLL *s = (CDKSCROLL *)object;
deleteCDKScrollItem (s, getCDKScrollCurrent (s));
refreshCDKScreen (ScreenOf (s));
return (TRUE);
}
/*
* This program demonstrates the Cdk scrolling list 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;
CDKSCROLL *scrollList = 0;
const char *title = "<C></5>Pick a file";
char **item = 0;
const char *mesg[5];
char temp[256];
int selection, count;
CDK_PARAMS params;
CDKparseParams (argc, argv, ¶ms, "cs:t:" CDK_CLI_PARAMS);
cdkscreen = initCDKScreen (NULL);
/* Set up CDK Colors. */
initCDKColor ();
/* Use the current diretory list to fill the radio list. */
count = CDKgetDirectoryContents (".", &item);
/* Create the scrolling list. */
scrollList = newCDKScroll (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
: (CDK_CSTRING2) item),
(CDKparamNumber (¶ms, 'c')
? 0
: count),
TRUE,
A_REVERSE,
CDKparamValue (¶ms, 'N', TRUE),
CDKparamValue (¶ms, 'S', FALSE));
/* Is the scrolling list null? */
if (scrollList == 0)
{
/* Exit CDK. */
destroyCDKScreen (cdkscreen);
endCDK ();
printf ("Cannot make scrolling list. Is the window too small?\n");
ExitProgram (EXIT_FAILURE);
}
if (CDKparamNumber (¶ms, 'c'))
{
setCDKScrollItems (scrollList, (CDK_CSTRING2) item, count, TRUE);
}
#if 0
drawCDKScroll (scrollList, 1);
setCDKScrollPosition (scrollList, 10);
drawCDKScroll (scrollList, 1);
sleep (3);
setCDKScrollPosition (scrollList, 20);
drawCDKScroll (scrollList, 1);
sleep (3);
setCDKScrollPosition (scrollList, 30);
drawCDKScroll (scrollList, 1);
sleep (3);
setCDKScrollPosition (scrollList, 70);
drawCDKScroll (scrollList, 1);
sleep (3);
#endif
bindCDKObject (vSCROLL, scrollList, 'a', addItemCB, NULL);
bindCDKObject (vSCROLL, scrollList, 'i', insItemCB, NULL);
bindCDKObject (vSCROLL, scrollList, 'd', delItemCB, NULL);
/* Activate the scrolling list. */
selection = activateCDKScroll (scrollList, 0);
/* Determine how the widget was exited. */
if (scrollList->exitType == vESCAPE_HIT)
{
mesg[0] = "<C>You hit escape. No file selected.";
mesg[1] = "";
mesg[2] = "<C>Press any key to continue.";
popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 3);
}
else if (scrollList->exitType == vNORMAL)
{
char *theItem = chtype2Char (scrollList->item[selection]);
mesg[0] = "<C>You selected the following file";
sprintf (temp, "<C>%.*s", (int)(sizeof (temp) - 20), theItem);
mesg[1] = temp;
mesg[2] = "<C>Press any key to continue.";
popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 3);
freeChar (theItem);
}
/* Clean up. */
CDKfreeStrings (item);
destroyCDKScroll (scrollList);
destroyCDKScreen (cdkscreen);
endCDK ();
ExitProgram (EXIT_SUCCESS);
}
|