14
14
static void cleanUpMenu (CDKMENU *menu);
16
DeclareCDKObjects(MENU, Menu, setCdk, Int);
16
DeclareCDKObjects (MENU, Menu, setCdk, Int);
19
19
* This creates a new menu widget.
21
CDKMENU *newCDKMenu (CDKSCREEN *cdkscreen, char *menulist[MAX_MENU_ITEMS][MAX_SUB_ITEMS], int menuItems, int *subsize, int *menuloc, int menuPos, chtype titleAttr, chtype subtitleAttr)
21
CDKMENU *newCDKMenu (CDKSCREEN *cdkscreen,
22
char *menulist[MAX_MENU_ITEMS][MAX_SUB_ITEMS],
24
31
int rightcount = menuItems - 1;
25
int rightloc = getmaxx(cdkscreen->window);
32
int rightloc = getmaxx (cdkscreen->window);
27
34
int x, y, max, junk;
28
int xpos = getbegx(cdkscreen->window);
29
int ypos = getbegy(cdkscreen->window);
30
int ymax = getmaxy(cdkscreen->window);
35
int xpos = getbegx (cdkscreen->window);
36
int ypos = getbegy (cdkscreen->window);
37
int ymax = getmaxy (cdkscreen->window);
32
if ((menu = newCDKObject(CDKMENU, &my_funcs)) == 0)
39
if ((menu = newCDKObject (CDKMENU, &my_funcs)) == 0)
35
42
/* Start making a copy of the information. */
36
ScreenOf(menu) = cdkscreen;
37
ObjOf(menu)->box = FALSE;
38
ObjOf(menu)->acceptsFocus = FALSE;
43
ScreenOf (menu) = cdkscreen;
44
ObjOf (menu)->box = FALSE;
45
ObjOf (menu)->acceptsFocus = FALSE;
39
46
rightcount = menuItems-1;
40
47
menu->parent = cdkscreen->window;
41
48
menu->menuItems = menuItems;
45
52
menu->currentSubtitle = 0;
46
53
menu->lastSelection = -1;
47
54
menu->menuPos = menuPos;
50
57
/* Create the pull down menus. */
51
for (x=0; x < menuItems; x++)
58
for (x = 0; x < menuItems; x++)
53
int x1 = (menuloc[x] == LEFT) ? x : rightcount--;
60
int x1 = (menuLocation[x] == LEFT) ? x : rightcount--;
55
62
int y1 = (menuPos == BOTTOM) ? (ymax - 1) : 0;
56
63
int y2 = (menuPos == BOTTOM) ? (ymax - subsize[x] - 2) : TITLELINES;
68
for (y = TITLELINES; y < subsize[x] ; y++)
75
for (y = TITLELINES; y < subsize[x]; y++)
70
77
int y0 = y - TITLELINES;
71
menu->sublist[x1][y0] = char2Chtype (menulist[x][y], &menu->sublistLen[x1][y0], &junk);
79
menu->sublist[x1][y0] = char2Chtype (menulist[x][y],
80
&menu->sublistLen[x1][y0],
72
82
max = MAXIMUM (max, menu->sublistLen[x1][y0]);
75
if (menuloc[x] == LEFT)
85
if (menuLocation[x] == LEFT)
95
105
keypad (menu->titleWin[x1], TRUE);
96
106
keypad (menu->pullWin[x1], TRUE);
98
ObjOf(menu)->inputWindow = menu->titleWin[menu->currentTitle];
100
/* Clean the key bindings. */
101
cleanCDKObjectBindings (vMENU, menu);
108
ObjOf (menu)->inputWindow = menu->titleWin[menu->currentTitle];
103
110
/* Register this baby. */
104
111
registerCDKObject (cdkscreen, vMENU, menu);
113
120
int activateCDKMenu (CDKMENU *menu, chtype *actions)
118
126
/* Draw in the screen. */
119
refreshCDKScreen (ScreenOf(menu));
127
refreshCDKScreen (ScreenOf (menu));
121
129
/* Display the menu titles. */
122
drawCDKMenu(menu, ObjOf(menu)->box);
130
drawCDKMenu (menu, ObjOf (menu)->box);
124
132
/* Highlight the current title and window. */
125
133
drawCDKMenuSubwin (menu);
127
135
/* If the input string is null, this is an interactive activate. */
128
136
if (actions == 0)
130
ObjOf(menu)->inputWindow = menu->titleWin[menu->currentTitle];
138
ObjOf (menu)->inputWindow = menu->titleWin[menu->currentTitle];
132
140
/* Start taking input from the keyboard. */
135
input = getcCDKObject (ObjOf(menu));
143
input = getchCDKObject (ObjOf (menu), &functionKey);
137
145
/* Inject the character into the widget. */
138
146
ret = injectCDKMenu (menu, input);
185
193
static void drawItem (CDKMENU *menu, int item, int offset)
187
195
writeChtype (menu->pullWin[menu->currentTitle],
188
1, item + TITLELINES - offset,
189
menu->sublist[menu->currentTitle][item],
191
0, menu->sublistLen[menu->currentTitle][item]);
196
1, item + TITLELINES - offset,
197
menu->sublist[menu->currentTitle][item],
199
0, menu->sublistLen[menu->currentTitle][item]);
194
202
/* Highlight the current sub-menu item. */
195
203
static void selectItem (CDKMENU *menu, int item, int offset)
197
205
writeChtypeAttrib (menu->pullWin[menu->currentTitle],
198
1, item + TITLELINES - offset,
199
menu->sublist[menu->currentTitle][item],
202
0, menu->sublistLen[menu->currentTitle][item]);
206
1, item + TITLELINES - offset,
207
menu->sublist[menu->currentTitle][item],
210
0, menu->sublistLen[menu->currentTitle][item]);
205
213
static void withinSubmenu (CDKMENU *menu, int step)
207
int next = wrapped(menu->currentSubtitle + step, menu->subsize[menu->currentTitle]);
215
int next = wrapped (menu->currentSubtitle + step, menu->subsize[menu->currentTitle]);
209
217
if (next != menu->currentSubtitle)
211
CDKSCREEN *screen = ScreenOf(menu);
212
int ymax = getmaxy(screen->window);
219
CDKSCREEN *screen = ScreenOf (menu);
220
int ymax = getmaxy (screen->window);
215
getbegy (menu->pullWin[menu->currentTitle]) +
216
menu->subsize[menu->currentTitle] >= ymax)
223
getbegy (menu->pullWin[menu->currentTitle]) +
224
menu->subsize[menu->currentTitle]) >= ymax)
218
226
menu->currentSubtitle = next;
219
227
drawCDKMenuSubwin (menu);
232
240
wrefresh (menu->pullWin[menu->currentTitle]);
235
ObjOf(menu)->inputWindow = menu->titleWin[menu->currentTitle];
243
ObjOf (menu)->inputWindow = menu->titleWin[menu->currentTitle];
239
247
static void acrossSubmenus (CDKMENU *menu, int step)
241
int next = wrapped(menu->currentTitle + step, menu->menuItems);
249
int next = wrapped (menu->currentTitle + step, menu->menuItems);
243
251
if (next != menu->currentTitle)
245
253
/* Erase the menu sub-window. */
246
254
eraseCDKMenuSubwin (menu);
247
refreshCDKScreen (ScreenOf(menu));
255
refreshCDKScreen (ScreenOf (menu));
249
257
/* Set the values. */
250
258
menu->currentTitle = next;
253
261
/* Draw the new menu sub-window. */
254
262
drawCDKMenuSubwin (menu);
255
ObjOf(menu)->inputWindow = menu->titleWin[menu->currentTitle];
263
ObjOf (menu)->inputWindow = menu->titleWin[menu->currentTitle];
260
* This injects a character into the menu widget.
268
* Inject a character into the menu widget.
262
270
static int _injectCDKMenu (CDKOBJS *object, chtype input)
267
275
bool complete = FALSE;
269
277
/* Set the exit type. */
270
setExitType(menu, 0);
278
setExitType (menu, 0);
272
280
/* Check if there is a pre-process function to be called. */
273
if (PreProcessFuncOf(menu) != 0)
281
if (PreProcessFuncOf (menu) != 0)
275
283
/* Call the pre-process function. */
276
ppReturn = PreProcessFuncOf(menu) (vMENU, menu, PreProcessDataOf(menu), input);
284
ppReturn = PreProcessFuncOf (menu) (vMENU,
286
PreProcessDataOf (menu),
279
290
/* Should we continue? */
282
293
/* Check for key bindings. */
283
294
if (checkCDKObjectBind (vMENU, menu, input) != 0)
285
checkEarlyExit(menu);
296
checkEarlyExit (menu);
293
acrossSubmenus(menu, -1);
296
case KEY_RIGHT : case KEY_TAB :
297
acrossSubmenus(menu, 1);
301
withinSubmenu (menu, -1);
304
case KEY_DOWN : case SPACE :
305
withinSubmenu (menu, 1);
310
setExitType(menu, input);
311
menu->lastSelection = ((menu->currentTitle * 100) + menu->currentSubtitle);
312
ret = menu->lastSelection;
318
setExitType(menu, input);
319
menu->lastSelection = -1;
320
ret = menu->lastSelection;
325
eraseCDKScreen (ScreenOf(menu));
326
refreshCDKScreen (ScreenOf(menu));
304
acrossSubmenus (menu, -1);
309
acrossSubmenus (menu, 1);
313
withinSubmenu (menu, -1);
318
withinSubmenu (menu, 1);
323
setExitType (menu, input);
324
menu->lastSelection = ((menu->currentTitle * 100) + menu->currentSubtitle);
325
ret = menu->lastSelection;
331
setExitType (menu, input);
332
menu->lastSelection = -1;
333
ret = menu->lastSelection;
338
eraseCDKScreen (ScreenOf (menu));
339
refreshCDKScreen (ScreenOf (menu));
331
344
/* Should we call a post-process? */
332
if (!complete && (PostProcessFuncOf(menu) != 0))
345
if (!complete && (PostProcessFuncOf (menu) != 0))
334
PostProcessFuncOf(menu) (vMENU, menu, PostProcessDataOf(menu), input);
347
PostProcessFuncOf (menu) (vMENU, menu, PostProcessDataOf (menu), input);
340
setExitType(menu, 0);
353
setExitType (menu, 0);
343
ResultOf(menu).valueInt = ret;
356
ResultOf (menu).valueInt = ret;
344
357
return (ret != unknownInt);
348
* This draws a menu item subwindow.
361
* Draw a menu item subwindow.
350
363
void drawCDKMenuSubwin (CDKMENU *menu)
353
int high = getmaxy(menu->pullWin[menu->currentTitle]) - 2;
366
int high = getmaxy (menu->pullWin[menu->currentTitle]) - 2;
355
368
int x1 = menu->subsize[menu->currentTitle];
366
379
/* Box the window. */
367
werase(menu->pullWin[menu->currentTitle]);
380
werase (menu->pullWin[menu->currentTitle]);
368
381
box (menu->pullWin[menu->currentTitle], ACS_VLINE, ACS_HLINE);
369
383
if (menu->menuPos == BOTTOM)
371
385
mvwaddch (menu->pullWin[menu->currentTitle],
372
menu->subsize[menu->currentTitle]+1, 0, ACS_LTEE);
386
menu->subsize[menu->currentTitle] + 1, 0, ACS_LTEE);
376
390
mvwaddch (menu->pullWin[menu->currentTitle], 0, 0, ACS_LTEE);
379
/* Draw in the items. */
380
for (x = x0; x < x1 ; x++)
393
/* Draw the items. */
394
for (x = x0; x < x1; x++)
382
396
drawItem (menu, x, x0);
385
399
selectItem (menu, menu->currentSubtitle, x0);
386
refreshCDKWindow (menu->pullWin[menu->currentTitle]);
400
wrefresh (menu->pullWin[menu->currentTitle]);
388
402
/* Highlight the title. */
389
403
writeChtypeAttrib (menu->titleWin[menu->currentTitle],
390
0, 0, menu->title[menu->currentTitle],
391
menu->titleAttr, HORIZONTAL, 0,
392
menu->titleLen[menu->currentTitle]);
393
refreshCDKWindow (menu->titleWin[menu->currentTitle]);
404
0, 0, menu->title[menu->currentTitle],
405
menu->titleAttr, HORIZONTAL, 0,
406
menu->titleLen[menu->currentTitle]);
407
wrefresh (menu->titleWin[menu->currentTitle]);
397
* This erases a menu item subwindow.
411
* Erase a menu item subwindow.
399
413
void eraseCDKMenuSubwin (CDKMENU *menu)
403
417
/* Redraw the sub-menu title. */
404
418
drawTitle (menu, menu->currentTitle);
405
refreshCDKWindow (menu->titleWin[menu->currentTitle]);
419
wrefresh (menu->titleWin[menu->currentTitle]);
409
* This function draws the menu.
411
425
static void _drawCDKMenu (CDKOBJS *object, boolean Box GCC_UNUSED)
416
430
/* Draw in the menu titles. */
417
for (x=0; x < menu->menuItems; x++)
431
for (x = 0; x < menu->menuItems; x++)
419
433
drawTitle (menu, x);
420
refreshCDKWindow (menu->titleWin[x]);
434
wrefresh (menu->titleWin[x]);
425
* This moves the menu to the given location.
439
* Move the menu to the given location.
427
static void _moveCDKMenu (CDKOBJS *object, int xplace, int yplace, boolean relative, boolean refresh_flag)
441
static void _moveCDKMenu (CDKOBJS *object,
445
boolean refresh_flag)
429
447
CDKMENU *menu = (CDKMENU *)object;
430
int currentX = getbegx(WindowOf(menu));
431
int currentY = getbegy(WindowOf(menu));
448
int currentX = getbegx (WindowOf (menu));
449
int currentY = getbegy (WindowOf (menu));
432
450
int xpos = xplace;
433
451
int ypos = yplace;
444
xpos = getbegx(WindowOf(menu)) + xplace;
445
ypos = getbegy(WindowOf(menu)) + yplace;
462
xpos = getbegx (WindowOf (menu)) + xplace;
463
ypos = getbegy (WindowOf (menu)) + yplace;
448
466
/* Adjust the window if we need to. */
449
alignxy (WindowOf(menu), &xpos, &ypos, getmaxx(WindowOf(menu)), getmaxy(WindowOf(menu)));
467
alignxy (WindowOf (menu),
470
getmaxx (WindowOf (menu)),
471
getmaxy (WindowOf (menu)));
451
473
/* Get the difference. */
452
474
xdiff = currentX - xpos;
453
475
ydiff = currentY - ypos;
455
477
/* Move the windows to the new location. */
456
moveCursesWindow(WindowOf(menu), -xdiff, -ydiff);
457
for (x=0; x < menu->menuItems; x++)
478
moveCursesWindow (WindowOf (menu), -xdiff, -ydiff);
479
for (x = 0; x < menu->menuItems; x++)
459
moveCursesWindow(menu->titleWin[x], -xdiff, -ydiff);
481
moveCursesWindow (menu->titleWin[x], -xdiff, -ydiff);
462
484
/* Touch the windows so they 'move'. */
463
refreshCDKWindow (WindowOf(menu));
485
refreshCDKWindow (WindowOf (menu));
465
487
/* Redraw the window, if they asked for it. */
466
488
if (refresh_flag)
468
drawCDKMenu (menu, ObjOf(menu)->box);
490
drawCDKMenu (menu, ObjOf (menu)->box);
473
* This sets the background attribute of the widget.
495
* Set the background attribute of the widget.
475
497
static void _setBKattrMenu (CDKOBJS *object, chtype attrib)
507
529
/* Delete the character pointers. */
508
530
freeChtype (menu->title[x]);
509
for (y=0; y < menu->subsize[x] ; y++)
531
for (y = 0; y < menu->subsize[x]; y++)
511
533
freeChtype (menu->sublist[x][y]);
537
/* Clean the key bindings. */
538
cleanCDKObjectBindings (vMENU, menu);
515
540
/* Unregister this object. */
516
541
unregisterCDKObject (vMENU, menu);
521
* This function erases the menu widget from the screen.
546
* Erase the menu widget from the screen.
523
548
static void _eraseCDKMenu (CDKOBJS *object)
527
552
CDKMENU *menu = (CDKMENU *)object;
530
/* Erase the menu items. */
531
for (x=0 ; x < menu->menuItems; x++)
555
for (x = 0; x < menu->menuItems; x++)
533
557
werase (menu->titleWin[x]);
534
558
wrefresh (menu->titleWin[x]);
542
* This sets multiple features of the menu.
566
* Set multiple features of the menu.
544
void setCDKMenu (CDKMENU *menu, int menuItem, int subMenuItem, chtype titleHighlight, chtype subTitleHighlight)
568
void setCDKMenu (CDKMENU *menu,
571
chtype titleHighlight,
572
chtype subTitleHighlight)
546
574
setCDKMenuCurrentItem (menu, menuItem, subMenuItem);
547
575
setCDKMenuTitleHighlight (menu, titleHighlight);
552
* This sets the current menu item to highlight.
580
* Set the current menu item to highlight.
554
582
void setCDKMenuCurrentItem (CDKMENU *menu, int menuitem, int submenuitem)
556
menu->currentTitle = wrapped(menuitem, menu->menuItems);
557
menu->currentSubtitle = wrapped(submenuitem, menu->subsize[menu->currentTitle]);
584
menu->currentTitle = wrapped (menuitem, menu->menuItems);
585
menu->currentSubtitle = wrapped (submenuitem, menu->subsize[menu->currentTitle]);
559
587
void getCDKMenuCurrentItem (CDKMENU *menu, int *menuItem, int *subMenuItem)
596
624
wrefresh (menu->pullWin[menu->currentTitle]);
598
626
/* Refresh the screen. */
599
refreshCDKScreen (ScreenOf(menu));
627
refreshCDKScreen (ScreenOf (menu));
602
static void _focusCDKMenu(CDKOBJS *object)
630
static void _focusCDKMenu (CDKOBJS *object)
604
632
CDKMENU *menu = (CDKMENU *)object;
606
drawCDKMenuSubwin(menu);
607
ObjOf(menu)->inputWindow = menu->titleWin[menu->currentTitle];
634
drawCDKMenuSubwin (menu);
635
ObjOf (menu)->inputWindow = menu->titleWin[menu->currentTitle];
612
dummyRefreshData(Menu)
640
dummyRefreshData (Menu)