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>
28 #include "layerutil.h"
31 /* DEPRICATED, use glutMenuStatusFunc instead. */
33 glutMenuStateFunc(GLUTmenuStateCB menuStateFunc
)
35 __glutMenuStatusFunc
= (GLUTmenuStatusCB
) menuStateFunc
;
39 glutMenuStatusFunc(GLUTmenuStatusCB menuStatusFunc
)
41 __glutMenuStatusFunc
= menuStatusFunc
;
45 glutDestroyMenu(int menunum
)
47 GLUTmenu
*menu
= __glutGetMenuByNum(menunum
);
48 GLUTmenuItem
*item
, *next
;
51 __glutMenuModificationError();
52 assert(menu
->id
== menunum
- 1);
53 XDestroySubwindows(__glutDisplay
, menu
->win
);
54 XDestroyWindow(__glutDisplay
, menu
->win
);
55 __glutMenuList
[menunum
- 1] = NULL
;
56 /* free all menu entries */
59 assert(item
->menu
== menu
);
65 if (__glutCurrentMenu
== menu
) {
66 __glutCurrentMenu
= NULL
;
72 glutChangeToMenuEntry(int num
, const char *label
, int value
)
78 __glutMenuModificationError();
79 i
= __glutCurrentMenu
->num
;
80 item
= __glutCurrentMenu
->list
;
83 if (item
->isTrigger
) {
84 /* If changing a submenu trigger to a menu entry, we
85 need to account for submenus. */
86 item
->menu
->submenus
--;
89 __glutSetMenuItem(item
, label
, value
, False
);
95 __glutWarning("Current menu has no %d item.", num
);
99 glutChangeToSubMenu(int num
, const char *label
, int menu
)
104 if (__glutMappedMenu
)
105 __glutMenuModificationError();
106 i
= __glutCurrentMenu
->num
;
107 item
= __glutCurrentMenu
->list
;
110 if (!item
->isTrigger
) {
111 /* If changing a menu entry to as submenu trigger, we
112 need to account for submenus. */
113 item
->menu
->submenus
++;
116 __glutSetMenuItem(item
, label
, /* base 0 */ menu
- 1, True
);
122 __glutWarning("Current menu has no %d item.", num
);
126 glutRemoveMenuItem(int num
)
128 GLUTmenuItem
*item
, **prev
, *remaining
;
131 if (__glutMappedMenu
)
132 __glutMenuModificationError();
133 i
= __glutCurrentMenu
->num
;
134 prev
= &__glutCurrentMenu
->list
;
135 item
= __glutCurrentMenu
->list
;
136 /* If menu item is removed, the menu's pixwidth may need to
141 /* If this menu item's pixwidth is as wide as the menu's
142 pixwidth, removing this menu item will necessitate
143 shrinking the menu's pixwidth. */
144 if (item
->pixwidth
>= __glutCurrentMenu
->pixwidth
) {
145 /* Continue recalculating menu pixwidth, first skipping
147 remaining
= item
->next
;
149 if (remaining
->pixwidth
> pixwidth
) {
150 pixwidth
= remaining
->pixwidth
;
152 remaining
= remaining
->next
;
154 __glutCurrentMenu
->pixwidth
= pixwidth
;
156 __glutCurrentMenu
->num
--;
157 __glutCurrentMenu
->managed
= False
;
159 /* Patch up menu's item list. */
166 if (item
->pixwidth
> pixwidth
) {
167 pixwidth
= item
->pixwidth
;
173 __glutWarning("Current menu has no %d item.", num
);
177 glutDetachMenu(int button
)
179 if (__glutMappedMenu
)
180 __glutMenuModificationError();
181 if (__glutCurrentWindow
->menu
[button
] > 0) {
182 __glutCurrentWindow
->buttonUses
--;
183 __glutChangeWindowEventMask(ButtonPressMask
| ButtonReleaseMask
,
184 __glutCurrentWindow
->buttonUses
> 0);
185 __glutCurrentWindow
->menu
[button
] = 0;