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 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
|
/* $Id: cdkentry.c,v 1.8 2005/03/08 19:51:33 tom Exp $ */
#include <cdk.h>
#ifdef XCURSES
char *XCursesProgramName="cdkentry";
#endif
/*
* Declare file local prototypes.
*/
static int widgetCB (EObjectType cdktype, void *object, void *clientData, chtype key);
/*
* Define file local variables.
*/
static char *FPUsage = "-f Field Width [-d Display Type] [-F Field Character] [-i Initial Value] [-m Minimum Length] [-M Maximum Length] [-T Title] [-L Label] [-B Buttons] [-O Output file] [-X X Position] [-Y Y Position] [-N] [-S]";
/*
*
*/
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);
exit (-1);
}
/* 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);
exit (-1);
}
}
/* 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();
/* Spit out the message. */
fprintf (stderr, "Error: Could not create the entry field. Is the window too small?\n");
/* Exit with an error. */
exit (-1);
}
/* Split the buttons if they supplied some. */
if (buttons != 0)
{
/* Split the button list up. */
buttonList = CDKsplitString (buttons, '\n');
buttonCount = CDKcountStrings (buttonList);
/* We need to create a buttonbox widget. */
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);
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.
* I do this instead of using the shadow parameter because
* the button widget sin't 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. We'll 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);
}
/* Exit with the button number picked. */
exit (selection);
}
static int widgetCB (EObjectType cdktype GCC_UNUSED, void *object GCC_UNUSED, void *clientData, chtype key)
{
CDKBUTTONBOX *buttonbox = (CDKBUTTONBOX *)clientData;
injectCDKButtonbox (buttonbox, key);
return (TRUE);
}
|