Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / lib / site_perl / 5.8.0 / sun4-solaris / Tk / pTk / tkMenu.h
CommitLineData
86530b38
AT
1/*
2 * tkMenu.h --
3 *
4 * Declarations shared among all of the files that implement menu widgets.
5 *
6 * Copyright (c) 1996-1997 by Sun Microsystems, Inc.
7 *
8 * See the file "license.terms" for information on usage and redistribution
9 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10 *
11 * RCS: @(#) $Id: tkMenu.h,v 1.4 1998/09/14 18:23:14 stanton Exp $
12 */
13
14#ifndef _TKMENU
15#define _TKMENU
16
17#ifndef _TK
18#include "tk.h"
19#endif
20
21#ifndef _TKINT
22#include "tkInt.h"
23#endif
24
25#ifndef _DEFAULT
26#include "default.h"
27#endif
28
29#ifdef BUILD_tk
30# undef TCL_STORAGE_CLASS
31# define TCL_STORAGE_CLASS DLLEXPORT
32#endif
33
34/*
35 * Dummy types used by the platform menu code.
36 */
37
38typedef struct TkMenuPlatformData_ *TkMenuPlatformData;
39typedef struct TkMenuPlatformEntryData_ *TkMenuPlatformEntryData;
40
41/*
42 * One of the following data structures is kept for each entry of each
43 * menu managed by this file:
44 */
45
46typedef struct TkMenuEntry {
47 int type; /* Type of menu entry; see below for
48 * valid types. */
49 struct TkMenu *menuPtr; /* Menu with which this entry is associated. */
50 char *label; /* Main text label displayed in entry (NULL
51 * if no label). Malloc'ed. */
52 int labelLength; /* Number of non-NULL characters in label. */
53 Tk_State state; /* State of button for display purposes:
54 * normal, active, or disabled. */
55 int underline; /* Index of character to underline. */
56 Pixmap bitmap; /* Bitmap to display in menu entry, or None.
57 * If not None then label is ignored. */
58 char *imageString; /* Name of image to display (malloc'ed), or
59 * NULL. If non-NULL, bitmap, text, and
60 * textVarName are ignored. */
61 Tk_Image image; /* Image to display in menu entry, or NULL if
62 * none. */
63 char *selectImageString; /* Name of image to display when selected
64 * (malloc'ed), or NULL. */
65 Tk_Image selectImage; /* Image to display in entry when selected,
66 * or NULL if none. Ignored if image is
67 * NULL. */
68 char *accel; /* Accelerator string displayed at right
69 * of menu entry. NULL means no such
70 * accelerator. Malloc'ed. */
71 int accelLength; /* Number of non-NULL characters in
72 * accelerator. */
73 int indicatorOn; /* True means draw indicator, false means
74 * don't draw it. */
75 /*
76 * Display attributes
77 */
78
79 Tk_3DBorder border; /* Structure used to draw background for
80 * entry. NULL means use overall border
81 * for menu. */
82 XColor *fg; /* Foreground color to use for entry. NULL
83 * means use foreground color from menu. */
84 Tk_3DBorder activeBorder; /* Used to draw background and border when
85 * element is active. NULL means use
86 * activeBorder from menu. */
87 XColor *activeFg; /* Foreground color to use when entry is
88 * active. NULL means use active foreground
89 * from menu. */
90 XColor *indicatorFg; /* Color for indicators in radio and check
91 * button entries. NULL means use indicatorFg
92 * GC from menu. */
93 Tk_Font tkfont; /* Text font for menu entries. NULL means
94 * use overall font for menu. */
95 int columnBreak; /* If this is 0, this item appears below
96 * the item in front of it. If this is
97 * 1, this item starts a new column. */
98 int hideMargin; /* If this is 0, then the item has enough
99 * margin to accomodate a standard check
100 * mark and a default right margin. If this
101 * is 1, then the item has no such margins.
102 * and checkbuttons and radiobuttons with
103 * this set will have a rectangle drawn
104 * in the indicator around the item if
105 * the item is checked.
106 * This is useful palette menus.*/
107 int indicatorSpace; /* The width of the indicator space for this
108 * entry.
109 */
110 int labelWidth; /* Number of pixels to allow for displaying
111 * labels in menu entries. */
112
113 /*
114 * Information used to implement this entry's action:
115 */
116
117 LangCallback *command; /* Command to invoke when entry is invoked.
118 * Malloc'ed. */
119 Arg name; /* Name of (for cascade entries). Malloc'ed.*/
120 Var variable; /* Name of variable (for check buttons and
121 * radio buttons). Malloc'ed.*/
122 Arg onValue; /* Value to store in variable when selected
123 * (only for radio and check buttons).
124 * Malloc'ed. */
125 Arg offValue; /* Value to store in variable when not
126 * selected (only for check buttons).
127 * Malloc'ed. */
128
129 /*
130 * Information used for drawing this menu entry.
131 */
132
133 int width; /* Number of pixels occupied by entry in
134 * horizontal dimension. Not used except
135 * in menubars. The width of norma menus
136 * is dependent on the rest of the menu. */
137 int x; /* X-coordinate of leftmost pixel in entry */
138 int height; /* Number of pixels occupied by entry in
139 * vertical dimension, including raised
140 * border drawn around entry when active. */
141 int y; /* Y-coordinate of topmost pixel in entry. */
142 GC textGC; /* GC for drawing text in entry. NULL means
143 * use overall textGC for menu. */
144 GC activeGC; /* GC for drawing text in entry when active.
145 * NULL means use overall activeGC for
146 * menu. */
147 GC disabledGC; /* Used to produce disabled effect for entry.
148 * NULL means use overall disabledGC from
149 * menu structure. See comments for
150 * disabledFg in menu structure for more
151 * information. */
152 GC indicatorGC; /* For drawing indicators. None means use
153 * GC from menu. */
154
155 /*
156 * Miscellaneous fields.
157 */
158
159 int entryFlags; /* Various flags. See below for
160 definitions. */
161 int index; /* Need to know which index we are. This
162 * is zero-based. This is the top-left entry
163 * of the menu. */
164
165 /*
166 * Bookeeping for master menus and cascade menus.
167 */
168
169 struct TkMenuReferences *childMenuRefPtr;
170 /* A pointer to the hash table entry for
171 * the child menu. Stored here when the menu
172 * entry is configured so that a hash lookup
173 * is not necessary later.*/
174 struct TkMenuEntry *nextCascadePtr;
175 /* The next cascade entry that is a parent of
176 * this entry's child cascade menu. NULL
177 * end of list, this is not a cascade entry,
178 * or the menu that this entry point to
179 * does not yet exist. */
180 TkMenuPlatformEntryData platformEntryData;
181 /* The data for the specific type of menu.
182 * Depends on platform and menu type what
183 * kind of options are in this structure.
184 */
185 Tk_Tile tile, activeTile, disabledTile;
186 Tk_TSOffset tsoffset;
187 GC tileGC, activeTileGC, disabledTileGC;
188} TkMenuEntry;
189
190/*
191 * Flag values defined for menu entries:
192 *
193 * ENTRY_SELECTED: Non-zero means this is a radio or check
194 * button and that it should be drawn in
195 * the "selected" state.
196 * ENTRY_NEEDS_REDISPLAY: Non-zero means the entry should be redisplayed.
197 * ENTRY_LAST_COLUMN: Used by the drawing code. If the entry is in the
198 * last column, the space to its right needs to
199 * be filled.
200 * ENTRY_PLATFORM_FLAG1 - 4 These flags are reserved for use by the
201 * platform-dependent implementation of menus
202 * and should not be used by anything else.
203 */
204
205#define ENTRY_SELECTED 1
206#define ENTRY_NEEDS_REDISPLAY 2
207#define ENTRY_LAST_COLUMN 4
208#define ENTRY_PLATFORM_FLAG1 (1 << 30)
209#define ENTRY_PLATFORM_FLAG2 (1 << 29)
210#define ENTRY_PLATFORM_FLAG3 (1 << 28)
211#define ENTRY_PLATFORM_FLAG4 (1 << 27)
212
213/*
214 * Types defined for MenuEntries:
215 */
216
217#define COMMAND_ENTRY 0
218#define SEPARATOR_ENTRY 1
219#define CHECK_BUTTON_ENTRY 2
220#define RADIO_BUTTON_ENTRY 3
221#define CASCADE_ENTRY 4
222#define TEAROFF_ENTRY 5
223
224/*
225 * Mask bits for above types:
226 */
227
228#define COMMAND_MASK TK_CONFIG_USER_BIT
229#define SEPARATOR_MASK (TK_CONFIG_USER_BIT << 1)
230#define CHECK_BUTTON_MASK (TK_CONFIG_USER_BIT << 2)
231#define RADIO_BUTTON_MASK (TK_CONFIG_USER_BIT << 3)
232#define CASCADE_MASK (TK_CONFIG_USER_BIT << 4)
233#define TEAROFF_MASK (TK_CONFIG_USER_BIT << 5)
234#define ALL_MASK (COMMAND_MASK | SEPARATOR_MASK \
235 | CHECK_BUTTON_MASK | RADIO_BUTTON_MASK | CASCADE_MASK | TEAROFF_MASK)
236
237/*
238 * A data structure of the following type is kept for each
239 * menu widget:
240 */
241
242typedef struct TkMenu {
243 Tk_Window tkwin; /* Window that embodies the pane. NULL
244 * means that the window has been destroyed
245 * but the data structures haven't yet been
246 * cleaned up.*/
247 Display *display; /* Display containing widget. Needed, among
248 * other things, so that resources can be
249 * freed up even after tkwin has gone away. */
250 Tcl_Interp *interp; /* Interpreter associated with menu. */
251 Tcl_Command widgetCmd; /* Token for menu's widget command. */
252 TkMenuEntry **entries; /* Array of pointers to all the entries
253 * in the menu. NULL means no entries. */
254 int numEntries; /* Number of elements in entries. */
255 int active; /* Index of active entry. -1 means
256 * nothing active. */
257 int menuType; /* MASTER_MENU, TEAROFF_MENU, or MENUBAR.
258 * See below for definitions. */
259 char *menuTypeName; /* Used to control whether created tkwin
260 * is a toplevel or not. "normal", "menubar",
261 * or "toplevel" */
262
263 /*
264 * Information used when displaying widget:
265 */
266
267 Tk_3DBorder border; /* Structure used to draw 3-D
268 * border and background for menu. */
269 int borderWidth; /* Width of border around whole menu. */
270 Tk_3DBorder activeBorder; /* Used to draw background and border for
271 * active element (if any). */
272 int activeBorderWidth; /* Width of border around active element. */
273 int relief; /* 3-d effect: TK_RELIEF_RAISED, etc. */
274 Tk_Font tkfont; /* Text font for menu entries. */
275 XColor *fg; /* Foreground color for entries. */
276 XColor *disabledFg; /* Foreground color when disabled. NULL
277 * means use normalFg with a 50% stipple
278 * instead. */
279 XColor *activeFg; /* Foreground color for active entry. */
280 XColor *indicatorFg; /* Color for indicators in radio and check
281 * button entries. */
282 Pixmap gray; /* Bitmap for drawing disabled entries in
283 * a stippled fashion. None means not
284 * allocated yet. */
285 GC textGC; /* GC for drawing text and other features
286 * of menu entries. */
287 GC disabledGC; /* Used to produce disabled effect. If
288 * disabledFg isn't NULL, this GC is used to
289 * draw text and icons for disabled entries.
290 * Otherwise text and icons are drawn with
291 * normalGC and this GC is used to stipple
292 * background across them. */
293 GC activeGC; /* GC for drawing active entry. */
294 GC indicatorGC; /* For drawing indicators. */
295 GC disabledImageGC; /* Used for drawing disabled images. They
296 * have to be stippled. This is created
297 * when the image is about to be drawn the
298 * first time. */
299
300 /*
301 * Information about geometry of menu.
302 */
303
304 int totalWidth; /* Width of entire menu */
305 int totalHeight; /* Height of entire menu */
306
307 /*
308 * Miscellaneous information:
309 */
310
311 int tearOff; /* 1 means this menu can be torn off. On some
312 * platforms, the user can drag an outline
313 * of the menu by just dragging outside of
314 * the menu, and the tearoff is created where
315 * the mouse is released. On others, an
316 * indicator (such as a dashed stripe) is
317 * drawn, and when the menu is selected, the
318 * tearoff is created. */
319 char *title; /* The title to use when this menu is torn
320 * off. If this is NULL, a default scheme
321 * will be used to generate a title for
322 * tearoff. */
323 LangCallback *tearOffCommand;/* If non-NULL, points to a command to
324 * run whenever the menu is torn-off. */
325 char *takeFocus; /* Value of -takefocus option; not used in
326 * the C code, but used by keyboard traversal
327 * scripts. Malloc'ed, but may be NULL. */
328 Tk_Cursor cursor; /* Current cursor for window, or None. */
329 LangCallback *postCommand; /* Used to detect cycles in cascade hierarchy
330 * trees when preprocessing postcommands
331 * on some platforms. See PostMenu for
332 * more details. */
333 int postCommandGeneration; /* Need to do pre-invocation post command
334 * traversal */
335 int menuFlags; /* Flags for use by X; see below for
336 definition */
337 TkMenuEntry *postedCascade; /* Points to menu entry for cascaded submenu
338 * that is currently posted or NULL if no
339 * submenu posted. */
340 struct TkMenu *nextInstancePtr;
341 /* The next instance of this menu in the
342 * chain. */
343 struct TkMenu *masterMenuPtr;
344 /* A pointer to the original menu for this
345 * clone chain. Points back to this structure
346 * if this menu is a master menu. */
347 Tk_Window parentTopLevelPtr;/* If this menu is a menubar, this is the
348 * toplevel that owns the menu. Only applicable
349 * for menubar clones.
350 */
351 struct TkMenuReferences *menuRefPtr;
352 /* Each menu is hashed into a table with the
353 * name of the menu's window as the key.
354 * The information in this hash table includes
355 * a pointer to the menu (so that cascades
356 * can find this menu), a pointer to the
357 * list of toplevel widgets that have this
358 * menu as its menubar, and a list of menu
359 * entries that have this menu specified
360 * as a cascade. */
361 TkMenuPlatformData platformData;
362 /* The data for the specific type of menu.
363 * Depends on platform and menu type what
364 * kind of options are in this structure.
365 */
366 Tk_Tile tile, activeTile, disabledTile;
367 Tk_TSOffset tsoffset;
368 GC tileGC, activeTileGC, disabledTileGC;
369} TkMenu;
370
371/*
372 * When the toplevel configure -menu command is executed, the menu may not
373 * exist yet. We need to keep a linked list of windows that reference
374 * a particular menu.
375 */
376
377typedef struct TkMenuTopLevelList {
378 struct TkMenuTopLevelList *nextPtr;
379 /* The next window in the list */
380 Tk_Window tkwin; /* The window that has this menu as its
381 * menubar. */
382} TkMenuTopLevelList;
383
384/*
385 * The following structure is used to keep track of things which
386 * reference a menu. It is created when:
387 * - a menu is created.
388 * - a cascade entry is added to a menu with a non-null name
389 * - the "-menu" configuration option is used on a toplevel widget
390 * with a non-null parameter.
391 *
392 * One of these three fields must be non-NULL, but any of the fields may
393 * be NULL. This structure makes it easy to determine whether or not
394 * anything like recalculating platform data or geometry is necessary
395 * when one of the three actions above is performed.
396 */
397
398typedef struct TkMenuReferences {
399 struct TkMenu *menuPtr; /* The menu data structure. This is NULL
400 * if the menu does not exist. */
401 TkMenuTopLevelList *topLevelListPtr;
402 /* First in the list of all toplevels that
403 * have this menu as its menubar. NULL if no
404 * toplevel widgets have this menu as its
405 * menubar. */
406 TkMenuEntry *parentEntryPtr;/* First in the list of all cascade menu
407 * entries that have this menu as their child.
408 * NULL means no cascade entries. */
409 Tcl_HashEntry *hashEntryPtr;/* This is needed because the pathname of the
410 * window (which is what we hash on) may not
411 * be around when we are deleting.
412 */
413} TkMenuReferences;
414
415/*
416 * Flag bits for menus:
417 *
418 * REDRAW_PENDING: Non-zero means a DoWhenIdle handler
419 * has already been queued to redraw
420 * this window.
421 * RESIZE_PENDING: Non-zero means a call to ComputeMenuGeometry
422 * has already been scheduled.
423 * MENU_DELETION_PENDING Non-zero means that we are currently destroying
424 * this menu. This is useful when we are in the
425 * middle of cleaning this master menu's chain of
426 * menus up when TkDestroyMenu was called again on
427 * this menu (via a destroy binding or somesuch).
428 * MENU_PLATFORM_FLAG1... Reserved for use by the platform-specific menu
429 * code.
430 */
431
432#define REDRAW_PENDING 1
433#define RESIZE_PENDING 2
434#define MENU_DELETION_PENDING 4
435#define MENU_PLATFORM_FLAG1 (1 << 30)
436#define MENU_PLATFORM_FLAG2 (1 << 29)
437#define MENU_PLATFORM_FLAG3 (1 << 28)
438
439/*
440 * Each menu created by the user is a MASTER_MENU. When a menu is torn off,
441 * a TEAROFF_MENU instance is created. When a menu is assigned to a toplevel
442 * as a menu bar, a MENUBAR instance is created. All instances have the same
443 * configuration information. If the master instance is deleted, all instances
444 * are deleted. If one of the other instances is deleted, only that instance
445 * is deleted.
446 */
447
448#define UNKNOWN_TYPE -1
449#define MASTER_MENU 0
450#define TEAROFF_MENU 1
451#define MENUBAR 2
452
453/*
454 * Various geometry definitions:
455 */
456
457#define CASCADE_ARROW_HEIGHT 10
458#define CASCADE_ARROW_WIDTH 8
459#define DECORATION_BORDER_WIDTH 2
460
461/*
462 * Configuration specs. Needed for platform-specific default initializations.
463 */
464
465EXTERN Tk_ConfigSpec tkMenuEntryConfigSpecs[];
466EXTERN Tk_ConfigSpec tkMenuConfigSpecs[];
467
468/*
469 * Menu-related procedures that are shared among Tk modules but not exported
470 * to the outside world:
471 */
472
473EXTERN int TkActivateMenuEntry _ANSI_ARGS_((TkMenu *menuPtr,
474 int index));
475EXTERN void TkBindMenu _ANSI_ARGS_((
476 Tk_Window tkwin, TkMenu *menuPtr));
477EXTERN TkMenuReferences *
478 TkCreateMenuReferences _ANSI_ARGS_((Tcl_Interp *interp,
479 char *pathName));
480EXTERN void TkDestroyMenu _ANSI_ARGS_((TkMenu *menuPtr));
481EXTERN void TkEventuallyRecomputeMenu _ANSI_ARGS_((TkMenu *menuPtr));
482EXTERN void TkEventuallyRedrawMenu _ANSI_ARGS_((
483 TkMenu *menuPtr, TkMenuEntry *mePtr));
484EXTERN TkMenuReferences *
485 TkFindMenuReferences _ANSI_ARGS_((Tcl_Interp *interp,
486 char *pathName));
487EXTERN void TkFreeMenuReferences _ANSI_ARGS_((
488 TkMenuReferences *menuRefPtr));
489EXTERN Tcl_HashTable * TkGetMenuHashTable _ANSI_ARGS_((Tcl_Interp *interp));
490EXTERN int TkGetMenuIndex _ANSI_ARGS_((Tcl_Interp *interp,
491 TkMenu *menuPtr, Arg string, int lastOK,
492 int *indexPtr));
493EXTERN void TkMenuInitializeDrawingFields _ANSI_ARGS_((TkMenu *menuPtr));
494EXTERN void TkMenuInitializeEntryDrawingFields _ANSI_ARGS_((
495 TkMenuEntry *mePtr));
496EXTERN int TkInvokeMenu _ANSI_ARGS_((Tcl_Interp *interp,
497 TkMenu *menuPtr, int index));
498EXTERN void TkMenuConfigureDrawOptions _ANSI_ARGS_((
499 TkMenu *menuPtr));
500EXTERN int TkMenuConfigureEntryDrawOptions _ANSI_ARGS_((
501 TkMenuEntry *mePtr, int index));
502EXTERN void TkMenuFreeDrawOptions _ANSI_ARGS_((TkMenu *menuPtr));
503EXTERN void TkMenuEntryFreeDrawOptions _ANSI_ARGS_((
504 TkMenuEntry *mePtr));
505EXTERN void TkMenuEventProc _ANSI_ARGS_((ClientData clientData,
506 XEvent *eventPtr));
507EXTERN void TkMenuImageProc _ANSI_ARGS_((
508 ClientData clientData, int x, int y, int width,
509 int height, int imgWidth, int imgHeight));
510EXTERN void TkMenuInit _ANSI_ARGS_((void));
511EXTERN void TkMenuSelectImageProc _ANSI_ARGS_
512 ((ClientData clientData, int x, int y,
513 int width, int height, int imgWidth,
514 int imgHeight));
515EXTERN Arg TkNewMenuName _ANSI_ARGS_((Tcl_Interp *interp,
516 char *parentName, TkMenu *menuPtr));
517EXTERN int TkPostCommand _ANSI_ARGS_((TkMenu *menuPtr));
518EXTERN int TkPostSubmenu _ANSI_ARGS_((Tcl_Interp *interp,
519 TkMenu *menuPtr, TkMenuEntry *mePtr));
520EXTERN int TkPostTearoffMenu _ANSI_ARGS_((Tcl_Interp *interp,
521 TkMenu *menuPtr, int x, int y));
522EXTERN int TkPreprocessMenu _ANSI_ARGS_((TkMenu *menuPtr));
523EXTERN void TkRecomputeMenu _ANSI_ARGS_((TkMenu *menuPtr));
524
525/*
526 * These routines are the platform-dependent routines called by the
527 * common code.
528 */
529
530EXTERN void TkpComputeMenubarGeometry _ANSI_ARGS_((TkMenu *menuPtr));
531EXTERN void TkpComputeStandardMenuGeometry _ANSI_ARGS_
532 ((TkMenu *menuPtr));
533EXTERN int TkpConfigureMenuEntry
534 _ANSI_ARGS_((TkMenuEntry *mePtr));
535EXTERN void TkpDestroyMenu _ANSI_ARGS_((TkMenu *menuPtr));
536EXTERN void TkpDestroyMenuEntry
537 _ANSI_ARGS_((TkMenuEntry *mEntryPtr));
538EXTERN void TkpDrawMenuEntry _ANSI_ARGS_((TkMenuEntry *mePtr,
539 Drawable d, Tk_Font tkfont,
540 CONST Tk_FontMetrics *menuMetricsPtr, int x,
541 int y, int width, int height, int strictMotif,
542 int drawArrow));
543EXTERN void TkpMenuInit _ANSI_ARGS_((void));
544EXTERN int TkpMenuNewEntry _ANSI_ARGS_((TkMenuEntry *mePtr));
545EXTERN int TkpNewMenu _ANSI_ARGS_((TkMenu *menuPtr));
546EXTERN int TkpPostMenu _ANSI_ARGS_((Tcl_Interp *interp,
547 TkMenu *menuPtr, int x, int y));
548EXTERN void TkpSetWindowMenuBar _ANSI_ARGS_((Tk_Window tkwin,
549 TkMenu *menuPtr));
550
551# undef TCL_STORAGE_CLASS
552# define TCL_STORAGE_CLASS DLLIMPORT
553
554#endif /* _TKMENU */
555