2 /* Copyright (c) Mark J. Kilgard, 1994, 1997. */
4 /* This program is freely distributable without licensing fees
5 and is provided without guarantee or warrantee expressed or
6 implied. This program is -not- in the public domain. */
8 /* glut_menu2.c implements the little used GLUT menu calls in
9 a distinct file from glut_menu.c for slim static linking. */
11 /* The Win32 GLUT file win32_menu.c completely re-implements all
12 the menuing functionality implemented. This file is used only by
13 the X Window System version of GLUT. */
16 #include <GL/vms_x_fix.h>
30 /* DEPRICATED, use glutMenuStatusFunc instead. */
32 glutMenuStateFunc(GLUTmenuStateCB menuStateFunc
)
34 __glutMenuStatusFunc
= (GLUTmenuStatusCB
) menuStateFunc
;
38 glutMenuStatusFunc(GLUTmenuStatusCB menuStatusFunc
)
40 __glutMenuStatusFunc
= menuStatusFunc
;
44 glutDestroyMenu(int menunum
)
46 GLUTmenu
*menu
= __glutGetMenuByNum(menunum
);
47 GLUTmenuItem
*item
, *next
;
50 __glutMenuModificationError();
51 assert(menu
->id
== menunum
- 1);
52 XDestroySubwindows(__glutDisplay
, menu
->win
);
53 XDestroyWindow(__glutDisplay
, menu
->win
);
54 __glutMenuList
[menunum
- 1] = NULL
;
55 /* free all menu entries */
58 assert(item
->menu
== menu
);
64 if (__glutCurrentMenu
== menu
) {
65 __glutCurrentMenu
= NULL
;
71 glutChangeToMenuEntry(int num
, const char *label
, int value
)
77 __glutMenuModificationError();
78 i
= __glutCurrentMenu
->num
;
79 item
= __glutCurrentMenu
->list
;
82 if (item
->isTrigger
) {
83 /* If changing a submenu trigger to a menu entry, we
84 need to account for submenus. */
85 item
->menu
->submenus
--;
88 __glutSetMenuItem(item
, label
, value
, False
);
94 __glutWarning("Current menu has no %d item.", num
);
98 glutChangeToSubMenu(int num
, const char *label
, int menu
)
103 if (__glutMappedMenu
)
104 __glutMenuModificationError();
105 i
= __glutCurrentMenu
->num
;
106 item
= __glutCurrentMenu
->list
;
109 if (!item
->isTrigger
) {
110 /* If changing a menu entry to as submenu trigger, we
111 need to account for submenus. */
112 item
->menu
->submenus
++;
115 __glutSetMenuItem(item
, label
, /* base 0 */ menu
- 1, True
);
121 __glutWarning("Current menu has no %d item.", num
);
125 glutRemoveMenuItem(int num
)
127 GLUTmenuItem
*item
, **prev
, *remaining
;
130 if (__glutMappedMenu
)
131 __glutMenuModificationError();
132 i
= __glutCurrentMenu
->num
;
133 prev
= &__glutCurrentMenu
->list
;
134 item
= __glutCurrentMenu
->list
;
135 /* If menu item is removed, the menu's pixwidth may need to
140 /* If this menu item's pixwidth is as wide as the menu's
141 pixwidth, removing this menu item will necessitate
142 shrinking the menu's pixwidth. */
143 if (item
->pixwidth
>= __glutCurrentMenu
->pixwidth
) {
144 /* Continue recalculating menu pixwidth, first skipping
146 remaining
= item
->next
;
148 if (remaining
->pixwidth
> pixwidth
) {
149 pixwidth
= remaining
->pixwidth
;
151 remaining
= remaining
->next
;
153 __glutCurrentMenu
->pixwidth
= pixwidth
;
155 __glutCurrentMenu
->num
--;
156 __glutCurrentMenu
->managed
= False
;
158 /* Patch up menu's item list. */
165 if (item
->pixwidth
> pixwidth
) {
166 pixwidth
= item
->pixwidth
;
172 __glutWarning("Current menu has no %d item.", num
);
176 glutDetachMenu(int button
)
178 if (__glutMappedMenu
)
179 __glutMenuModificationError();
180 if (__glutCurrentWindow
->menu
[button
] > 0) {
181 __glutCurrentWindow
->buttonUses
--;
182 __glutChangeWindowEventMask(ButtonPressMask
| ButtonReleaseMask
,
183 __glutCurrentWindow
->buttonUses
> 0);
184 __glutCurrentWindow
->menu
[button
] = 0;