forked from RealDeuce/OpenDoors
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathODPopup.c
More file actions
716 lines (631 loc) · 22.6 KB
/
Copy pathODPopup.c
File metadata and controls
716 lines (631 loc) · 22.6 KB
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
/* OpenDoors Online Software Programming Toolkit
* (C) Copyright 1991 - 1999 by Brian Pirie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* File: ODPopUp.c
*
* Description: Implements od_popup_menu(), for displaying a menu in
* a window, allowing the user to make a selection using
* "hot keys" or by using arrow keys.
*
* Revisions: Date Ver Who Change
* ---------------------------------------------------------------
* Oct 13, 1994 6.00 BP New file header format.
* Dec 09, 1994 6.00 BP Standardized coding style.
* Jan 15, 1995 6.00 BP Free menu structure on menu destroy.
* Feb 02, 1995 6.00 BP Added od_yield() call in for(;;) loop.
* Aug 19, 1995 6.00 BP 32-bit portability.
* Nov 11, 1995 6.00 BP Removed register keyword.
* Nov 14, 1995 6.00 BP Change valid range of nLevel to 0-10.
* Nov 16, 1995 6.00 BP Removed oddoor.h, added odcore.h.
* Nov 17, 1995 6.00 BP Use new input queue mechanism.
* Dec 12, 1995 6.00 BP Added entry, exit and kernel macros.
* Dec 23, 1995 6.00 BP Restore original color on exit.
* Dec 30, 1995 6.00 BP Added ODCALL for calling convention.
* Jan 04, 1996 6.00 BP Use od_get_input().
* Jan 12, 1996 6.00 BP Claim exclusive use of arrow keys.
* Jan 30, 1996 6.00 BP Replaced od_yield() with od_sleep().
* Jan 31, 1996 6.00 BP Added timeout for od_get_input().
* Jan 31, 1996 6.00 BP Add ODPopupCheckForKey() wait param.
* Jan 31, 1996 6.00 BP Ignore left & right if !MENU_PULLDOWN.
* Feb 13, 1996 6.00 BP Added od_get_input() flags parameter.
* Feb 19, 1996 6.00 BP Changed version number to 6.00.
* Mar 03, 1996 6.10 BP Begin version 6.10.
* Aug 10, 2003 6.23 SH *nix support
*/
#define BUILDING_OPENDOORS
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include "OpenDoor.h"
#include "ODCore.h"
#include "ODGen.h"
#include "ODPlat.h"
#include "ODKrnl.h"
#include "ODStat.h"
/* Configurable od_popup_menu() parameters. */
/* Maximum menu level. */
#define MENU_LEVELS 11
/* Maximum number of items in a menu. */
#define MAX_MENU_ITEMS 21
/* Maximum width of any menu item. */
#define MAX_ITEM_WIDTH 76
/* Other manifest constants. */
#define NO_COMMAND -10
/* Local data types. */
/* Information on an individual menu item. */
typedef struct
{
char szItemText[MAX_ITEM_WIDTH + 1];
BYTE btKeyIndex;
} tMenuItem;
/* Information on a popup menu level. */
typedef struct
{
tMenuItem *paMenuItems;
BYTE btNumMenuItems;
BYTE btWidth;
BYTE btRight;
BYTE btBottom;
BYTE btCursor;
BYTE btLeft;
BYTE btTop;
WORD wFlags;
void *pWindow;
} tMenuLevelInfo;
/* Private variables. */
/* Array of information on each menu level. */
tMenuLevelInfo MenuLevelInfo[MENU_LEVELS];
/* Current menu settings. */
static BYTE btCorrectItem;
static INT nCommand;
static WORD wCurrentFlags;
static BYTE btCurrentNumMenuItems;
static INT nCurrentLevel;
/* Private helper functions used by od_popup_menu(). */
static void ODPopupCheckForKey(BOOL bWaitForInput);
static void ODPopupDisplayMenuItem(BYTE btLeft, BYTE btTop,
tMenuItem *paMenuItems, BYTE btItemIndex, BOOL bHighlighted, BYTE btWidth,
BOOL bPositionCursor);
/* ----------------------------------------------------------------------------
* od_popup_menu()
*
* Displays a popup menu on the local and remote screens.
*
* Parameters: pszTitle - Text to show as the window title of the popup menu.
* If no title is desired, this parameter should be set
* to either "" or NULL.
*
* pszText - String which contains the menu definition. In the
* menu definition string, individual menu items are
* separated by a pipe ('|') character, and hotkeys are
* proceeded by a carat ('^') character.
*
* nLeft - The 1-based column number of the upper right corner
* of the menu.
*
* nTop - The 1-based row number of the upper right corner of
* the menu.
*
* nLevel - Menu level, which must be a value between 0 and
* MENU_LEVELS.
*
* uFlags - One or more flags, combined by the bitwise or (|)
* operator.
*
* Return: POPUP_ERROR on error, POPUP_ESCAPE if user pressed the Escape
* key, POPUP_LEFT if the user choose to move to the next menu to
* the left, POPUP_RIGHT if the user choose to move to the next
* menu to the right, or a postive value if the user choose an item
* from the menu. In this case, the return value is the 1-based
* index of the selected menu item.
*/
ODAPIDEF INT ODCALL od_popup_menu(char *pszTitle, char *pszText, INT nLeft,
INT nTop, INT nLevel, WORD uFlags)
{
tMenuItem *paMenuItems = NULL;
BYTE btCount;
BYTE btWidth;
BYTE btRight;
BYTE btBottom;
BYTE btCursor;
BYTE btLeft;
BYTE btTop;
void *pWindow;
BYTE btBetweenSize;
BYTE btTitleSize;
BYTE btRemaining;
BYTE btLineCount;
INT16 nOriginalAttrib;
/* Log function entry if running in trace mode. */
TRACE(TRACE_API, "od_popup_menu()");
/* Initialize OpenDoors, if not already done. */
if(!bODInitialized) od_init();
OD_API_ENTRY();
/* Setup od_box_chars appropriately. */
if(od_control.od_box_chars[BOX_BOTTOM] == 0)
{
od_control.od_box_chars[BOX_BOTTOM] = od_control.od_box_chars[BOX_TOP];
}
if(od_control.od_box_chars[BOX_RIGHT] == 0)
{
od_control.od_box_chars[BOX_RIGHT] = od_control.od_box_chars[BOX_LEFT];
}
/* Store initial display color. */
nOriginalAttrib = od_control.od_cur_attrib;
/* check level bounds */
if(nLevel < 0 || nLevel > MENU_LEVELS)
{
od_control.od_error = ERR_LIMIT;
OD_API_EXIT();
return(POPUP_ERROR);
}
/* normalize level */
nCurrentLevel = nLevel;
if(MenuLevelInfo[nLevel].pWindow == NULL)
{
btLeft = nLeft;
btTop = nTop;
wCurrentFlags = uFlags;
if(pszText == NULL)
{
od_control.od_error = ERR_PARAMETER;
OD_API_EXIT();
return(POPUP_ERROR);
}
if(paMenuItems == NULL)
{
if((paMenuItems = malloc(sizeof(tMenuItem) * MAX_MENU_ITEMS)) == NULL)
{
od_control.od_error = ERR_PARAMETER;
OD_API_EXIT();
return(POPUP_ERROR);
}
}
MenuLevelInfo[nLevel].paMenuItems = paMenuItems;
btCurrentNumMenuItems = 0;
btWidth = 0;
btCount = 0;
nCommand = NO_COMMAND;
paMenuItems[0].btKeyIndex = 0;
while(*pszText && btCurrentNumMenuItems < MAX_MENU_ITEMS)
{
switch(*pszText)
{
case '|':
paMenuItems[btCurrentNumMenuItems++].szItemText[btCount]
= '\0';
if(btCount > btWidth) btWidth = btCount;
btCount = 0;
paMenuItems[btCurrentNumMenuItems].btKeyIndex = 0;
break;
case '^':
if(btCount < MAX_ITEM_WIDTH)
{
paMenuItems[btCurrentNumMenuItems].btKeyIndex = btCount;
}
break;
default:
if(btCount < MAX_ITEM_WIDTH)
{
paMenuItems[btCurrentNumMenuItems].szItemText[btCount++] =
*pszText;
}
}
++pszText;
}
/* If we were in the middle of a menu item when we encountered the end */
/* of the string, then it should form an additional menu entry. This */
/* handles the case of a menu string to no terminating | for the last */
/* entry. */
if(btCount != 0)
{
/* null-terminate current menu entry string */
paMenuItems[btCurrentNumMenuItems++].szItemText[btCount] = '\0';
/* If this is the widest entry, update he menu width appropriately */
if(btCount > btWidth) btWidth = btCount;
}
/* If the menu description string does not contain any menu items */
if(btCurrentNumMenuItems == 0)
{
/* Return with parameter error */
od_control.od_error = ERR_PARAMETER;
OD_API_EXIT();
return(POPUP_ERROR);
}
/* Adjust menu width to allow title to fit, if possible */
/* If a title string was passed, and that string is wider than widest */
/* menu entry ... */
if(pszTitle != NULL && strlen(pszTitle) + 2 > btWidth)
{
/* Then width of menu window should be large enough to allow up to */
/* the first 76 characters of the title to fit. */
btWidth = strlen(pszTitle) + 2 > MAX_ITEM_WIDTH
? MAX_ITEM_WIDTH : strlen(pszTitle) + 2;
}
/* Based on number and size of menu items, and width of title, */
/* determine the bottom, right and inside width of the menu. */
btBottom = btTop + btCurrentNumMenuItems + 1;
btRight = btLeft + btWidth + 3;
btBetweenSize = (btRight - btLeft) - 1;
/* If neither ANSI nor AVATAR mode is available, return with an error */
if(!(od_control.user_ansi || od_control.user_avatar))
{
od_control.od_error = ERR_NOGRAPHICS;
OD_API_EXIT();
return(POPUP_ERROR);
}
/* If menu would "fall off" edge of screen, return with an error */
if(btLeft < 1 || btTop < 1 || btRight > OD_SCREEN_WIDTH
|| btBottom > OD_SCREEN_HEIGHT || btRight - btLeft < 2
|| btBottom - btTop < 2)
{
od_control.od_error = ERR_PARAMETER;
OD_API_EXIT();
return(POPUP_ERROR);
}
/* Allocate space to store window information. If unable to allocate */
/* enough space, return with an error. */
if((pWindow = malloc((btRight - btLeft + 1) * 2
+ (btBottom - btTop + 1) * 160)) == NULL)
{
od_control.od_error = ERR_MEMORY;
OD_API_EXIT();
return(POPUP_ERROR);
}
/* Store contents of screen where memu will be drawn in the temporary */
/* buffer. */
if(!od_gettext(btLeft, btTop, btRight, btBottom, pWindow))
{
free(pWindow);
pWindow = NULL;
/* Note that od_error code has been set in od_gettext(). */
OD_API_EXIT();
return(POPUP_ERROR);
}
/* Determine number of characters of title to be displayed */
if(pszTitle == NULL)
{
btTitleSize = 0;
}
else
{
if((btTitleSize = strlen(pszTitle)) > (btBetweenSize - 4))
{
btTitleSize = btBetweenSize - 4;
}
}
od_set_cursor(btTop,btLeft);
od_set_attrib(od_control.od_menu_border_col);
od_putch(od_control.od_box_chars[BOX_UPPERLEFT]);
if(btTitleSize == 0)
{
od_repeat(od_control.od_box_chars[BOX_TOP], btBetweenSize);
}
else
{
od_repeat(od_control.od_box_chars[BOX_TOP],
btRemaining = ((btBetweenSize - btTitleSize - 2) / 2));
od_set_attrib(od_control.od_menu_title_col);
od_putch(' ');
od_disp(pszTitle,btTitleSize, TRUE);
od_putch(' ');
od_set_attrib(od_control.od_menu_border_col);
od_repeat(od_control.od_box_chars[BOX_TOP],
(BYTE)(btBetweenSize - btRemaining - btTitleSize - 2));
}
od_putch(od_control.od_box_chars[BOX_UPPERRIGHT]);
btLineCount = btTop + 1;
btCorrectItem = 0;
ODPopupCheckForKey(FALSE);
btCursor = btCorrectItem;
for(btCount = 0; btCount < btCurrentNumMenuItems
&& btLineCount < btBottom; ++btCount)
{
ODPopupCheckForKey(FALSE);
if(nCommand != NO_COMMAND && !(wCurrentFlags & MENU_KEEP))
{
goto exit_now;
}
od_set_cursor(btLineCount,btLeft);
od_putch(od_control.od_box_chars[BOX_LEFT]);
od_set_attrib(od_control.od_menu_text_col);
if(btCount == btCursor)
{
ODPopupDisplayMenuItem(btLeft, btTop, paMenuItems, btCount,
TRUE, btWidth, FALSE);
}
else
{
ODPopupDisplayMenuItem(btLeft, btTop, paMenuItems, btCount,
FALSE, btWidth, FALSE);
}
od_set_attrib(od_control.od_menu_border_col);
od_putch(od_control.od_box_chars[BOX_RIGHT]);
++btLineCount;
}
od_set_cursor(btBottom, btLeft);
od_putch(od_control.od_box_chars[BOX_LOWERLEFT]);
od_repeat(od_control.od_box_chars[BOX_BOTTOM], btBetweenSize);
od_putch(od_control.od_box_chars[BOX_LOWERRIGHT]);
od_set_cursor(btTop + 1, btLeft + 1);
}
else
{
paMenuItems = MenuLevelInfo[nLevel].paMenuItems;
btCurrentNumMenuItems = MenuLevelInfo[nLevel].btNumMenuItems;
btWidth = MenuLevelInfo[nLevel].btWidth;
btRight = MenuLevelInfo[nLevel].btRight;
btBottom = MenuLevelInfo[nLevel].btBottom;
btLeft = MenuLevelInfo[nLevel].btLeft;
btTop = MenuLevelInfo[nLevel].btTop;
wCurrentFlags = MenuLevelInfo[nLevel].wFlags;
pWindow = MenuLevelInfo[nLevel].pWindow;
btCorrectItem = btCursor = MenuLevelInfo[nLevel].btCursor;
nCommand = NO_COMMAND;
if(uFlags & MENU_DESTROY)
{
nCommand = POPUP_ESCAPE;
goto destroy;
}
/* Otherwise, position flashing hardware cursor appropriately */
od_set_cursor(btTop + btCursor + 1, btLeft + 1);
}
/* Claim exclusive use of arrow keys. */
ODStatStartArrowUse();
for(;;)
{
ODPopupCheckForKey(TRUE);
if(btCorrectItem != btCursor)
{
ODPopupDisplayMenuItem(btLeft, btTop, paMenuItems, btCursor,
FALSE, btWidth, TRUE);
btCursor = btCorrectItem;
ODWaitDrain(25);
ODPopupCheckForKey(FALSE);
ODPopupDisplayMenuItem(btLeft, btTop, paMenuItems, btCursor,
TRUE, btWidth, TRUE);
}
if(nCommand != NO_COMMAND)
{
goto exit_now;
}
}
exit_now:
if((!(wCurrentFlags & MENU_KEEP)) || nCommand <= 0)
{
destroy:
od_puttext(btLeft, btTop, btRight, btBottom, pWindow);
free(pWindow);
MenuLevelInfo[nLevel].pWindow = NULL;
if(paMenuItems != NULL)
{
free(paMenuItems);
MenuLevelInfo[nLevel].paMenuItems = NULL;
}
}
else if(wCurrentFlags & MENU_KEEP)
{
MenuLevelInfo[nLevel].paMenuItems = paMenuItems;
MenuLevelInfo[nLevel].btNumMenuItems = btCurrentNumMenuItems;
MenuLevelInfo[nLevel].btWidth = btWidth;
MenuLevelInfo[nLevel].btRight = btRight;
MenuLevelInfo[nLevel].btBottom = btBottom;
MenuLevelInfo[nLevel].btCursor = btCursor;
MenuLevelInfo[nLevel].btLeft = btLeft;
MenuLevelInfo[nLevel].btTop = btTop;
MenuLevelInfo[nLevel].wFlags = wCurrentFlags;
MenuLevelInfo[nLevel].pWindow = pWindow;
}
/* Restore original display color. */
od_set_attrib(nOriginalAttrib);
/* Release exclusive use of arrow keys. */
ODStatEndArrowUse();
OD_API_EXIT();
return(nCommand);
}
/* ----------------------------------------------------------------------------
* ODPopupCheckForKey() *** PRIVATE FUNCTION ***
*
* Checks whether or not the user has pressed any key. If one or more keys
* have been pressed, then these keystrokes are processed. This function
* returns when no more keys are waiting in the inbound buffer, or when a key
* has been pressed that requires immediate action (such as the [ENTER] key).
*
* Parameters: bWaitForInput - Indicates whether this function should return
* immediately if no input is waiting (FALSE), or
* wait for the next input even before returning
* (TRUE).
*
* Return: void
*/
static void ODPopupCheckForKey(BOOL bWaitForInput)
{
BYTE btCount;
tODInputEvent InputEvent;
BOOL bDoneAnythingYet = FALSE;
/* Loop, processing keys. If a command has been selected, stop looping */
/* immediately. If there are no more keys waiting, stop looping */
while(nCommand == NO_COMMAND)
{
CALL_KERNEL_IF_NEEDED();
if(!od_get_input(&InputEvent, bWaitForInput && !bDoneAnythingYet
? OD_NO_TIMEOUT : 0, GETIN_NORMAL))
{
/* Return right away if no input event is waiting. */
return;
}
bDoneAnythingYet = TRUE;
if(InputEvent.EventType == EVENT_EXTENDED_KEY)
{
switch(InputEvent.chKeyPress)
{
case OD_KEY_UP:
up_arrow:
if(btCorrectItem == 0)
{
btCorrectItem = btCurrentNumMenuItems - 1;
}
else
{
--btCorrectItem;
}
break;
case OD_KEY_DOWN:
down_arrow:
if(++btCorrectItem >= btCurrentNumMenuItems)
{
btCorrectItem = 0;
}
break;
case OD_KEY_LEFT:
left_arrow:
if(wCurrentFlags & MENU_PULLDOWN)
{
nCommand = POPUP_LEFT;
return;
}
break;
case OD_KEY_RIGHT:
right_arrow:
if(wCurrentFlags & MENU_PULLDOWN)
{
nCommand = POPUP_RIGHT;
return;
}
break;
}
}
else if(InputEvent.EventType == EVENT_CHARACTER)
{
if(InputEvent.chKeyPress == '\n' || InputEvent.chKeyPress == '\r')
{
nCommand = btCorrectItem + 1;
return;
}
else if(InputEvent.chKeyPress == 27)
{
if(wCurrentFlags & MENU_ALLOW_CANCEL)
{
nCommand = POPUP_ESCAPE;
return;
}
}
else
{
/* Check whether key is a menu "hot key" */
for(btCount = 0; btCount < btCurrentNumMenuItems; ++btCount)
{
if(toupper(MenuLevelInfo[nCurrentLevel].paMenuItems[btCount]
.szItemText[MenuLevelInfo[nCurrentLevel].paMenuItems[btCount]
.btKeyIndex]) == toupper(InputEvent.chKeyPress))
{
btCorrectItem = btCount;
nCommand = btCorrectItem + 1;
return;
}
}
/* At this point, we know that key was not one of the "hot keys" */
/* Check for 4, 6, 8 and 2 keys as arrow keys. */
if(InputEvent.chKeyPress == '4')
{
goto left_arrow;
}
else if(InputEvent.chKeyPress == '6')
{
goto right_arrow;
}
else if(InputEvent.chKeyPress == '8')
{
goto up_arrow;
}
else if(InputEvent.chKeyPress == '2')
{
goto down_arrow;
}
}
}
}
}
/* ----------------------------------------------------------------------------
* ODPopupDisplayMenuItem() *** PRIVATE FUNCTION ***
*
* Displays an individual menu item.
*
* Parameters: btLeft - Column number where the menu item will be
* displayed.
*
* btTop - Row number where the menu item will be
* displayed.
*
* paMenuItems - Pointer to array of available menu items.
*
* btItemIndex - Index into paMenuItems of the menu item that
* is to be displayed.
*
* bHighlighted - TRUE if the items is to be displayed as
* highlighted, FALSE if it is to be displayed as
* non-highlighted.
*
* btWidth - Width of the menu item, in characters.
*
* bPositionCursor - TRUE if the cursor needs to be positioned
* prior to drawing the menu item, FALSE if the
* cursor is already in the required position.
*
* Return: void
*/
static void ODPopupDisplayMenuItem(BYTE btLeft, BYTE btTop,
tMenuItem *paMenuItems, BYTE btItemIndex, BOOL bHighlighted, BYTE btWidth,
BOOL bPositionCursor)
{
BYTE btCount;
char *pchItemText;
BYTE btKeyPosition;
BYTE btTextColor;
BYTE btKeyColor;
/* Check that parameters are reasonable when operating in debug mode. */
ASSERT(paMenuItems != NULL);
ASSERT(btItemIndex < MAX_MENU_ITEMS);
ASSERT(btWidth < OD_SCREEN_WIDTH);
++btLeft;
++btTop;
btTextColor = bHighlighted ? od_control.od_menu_highlight_col
: od_control.od_menu_text_col;
btKeyColor = bHighlighted ? od_control.od_menu_highkey_col
: od_control.od_menu_key_col;
pchItemText = (char *)(paMenuItems[btItemIndex].szItemText);
btKeyPosition = paMenuItems[btItemIndex].btKeyIndex;
if(bPositionCursor) od_set_cursor(btTop + btItemIndex, btLeft);
od_set_attrib(btTextColor);
od_putch(' ');
for(btCount = 0; btCount < btWidth && *pchItemText; ++btCount)
{
if(btCount == btKeyPosition)
{
od_set_attrib(btKeyColor);
od_putch(*pchItemText++);
od_set_attrib(btTextColor);
}
else
{
od_putch(*pchItemText++);
}
}
od_repeat(' ', (BYTE)((btWidth - btCount) + 1));
if(bPositionCursor) od_set_cursor(btTop + btItemIndex, btLeft);
}