jpayne@69
|
1 /*
|
jpayne@69
|
2 * tkMenubutton.h --
|
jpayne@69
|
3 *
|
jpayne@69
|
4 * Declarations of types and functions used to implement the menubutton
|
jpayne@69
|
5 * widget.
|
jpayne@69
|
6 *
|
jpayne@69
|
7 * Copyright (c) 1996-1997 by Sun Microsystems, Inc.
|
jpayne@69
|
8 *
|
jpayne@69
|
9 * See the file "license.terms" for information on usage and redistribution of
|
jpayne@69
|
10 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
jpayne@69
|
11 */
|
jpayne@69
|
12
|
jpayne@69
|
13 #ifndef _TKMENUBUTTON
|
jpayne@69
|
14 #define _TKMENUBUTTON
|
jpayne@69
|
15
|
jpayne@69
|
16 #ifndef _TKINT
|
jpayne@69
|
17 #include "tkInt.h"
|
jpayne@69
|
18 #endif
|
jpayne@69
|
19
|
jpayne@69
|
20 #ifndef _TKMENU
|
jpayne@69
|
21 #include "tkMenu.h"
|
jpayne@69
|
22 #endif
|
jpayne@69
|
23
|
jpayne@69
|
24 /*
|
jpayne@69
|
25 * Legal values for the "orient" field of TkMenubutton records.
|
jpayne@69
|
26 */
|
jpayne@69
|
27
|
jpayne@69
|
28 enum direction {
|
jpayne@69
|
29 DIRECTION_ABOVE, DIRECTION_BELOW, DIRECTION_FLUSH,
|
jpayne@69
|
30 DIRECTION_LEFT, DIRECTION_RIGHT
|
jpayne@69
|
31 };
|
jpayne@69
|
32
|
jpayne@69
|
33 /*
|
jpayne@69
|
34 * Legal values for the "state" field of TkMenubutton records.
|
jpayne@69
|
35 */
|
jpayne@69
|
36
|
jpayne@69
|
37 enum state {
|
jpayne@69
|
38 STATE_ACTIVE, STATE_DISABLED, STATE_NORMAL
|
jpayne@69
|
39 };
|
jpayne@69
|
40
|
jpayne@69
|
41 /*
|
jpayne@69
|
42 * A data structure of the following type is kept for each widget managed by
|
jpayne@69
|
43 * this file:
|
jpayne@69
|
44 */
|
jpayne@69
|
45
|
jpayne@69
|
46 typedef struct {
|
jpayne@69
|
47 Tk_Window tkwin; /* Window that embodies the widget. NULL means
|
jpayne@69
|
48 * that the window has been destroyed but the
|
jpayne@69
|
49 * data structures haven't yet been cleaned
|
jpayne@69
|
50 * up. */
|
jpayne@69
|
51 Display *display; /* Display containing widget. Needed, among
|
jpayne@69
|
52 * other things, so that resources can bee
|
jpayne@69
|
53 * freed up even after tkwin has gone away. */
|
jpayne@69
|
54 Tcl_Interp *interp; /* Interpreter associated with menubutton. */
|
jpayne@69
|
55 Tcl_Command widgetCmd; /* Token for menubutton's widget command. */
|
jpayne@69
|
56 Tk_OptionTable optionTable; /* Table that defines configuration options
|
jpayne@69
|
57 * available for this widget. */
|
jpayne@69
|
58 char *menuName; /* Name of menu associated with widget.
|
jpayne@69
|
59 * Malloc-ed. */
|
jpayne@69
|
60
|
jpayne@69
|
61 /*
|
jpayne@69
|
62 * Information about what's displayed in the menu button:
|
jpayne@69
|
63 */
|
jpayne@69
|
64
|
jpayne@69
|
65 char *text; /* Text to display in button (malloc'ed) or
|
jpayne@69
|
66 * NULL. */
|
jpayne@69
|
67 int underline; /* Index of character to underline. */
|
jpayne@69
|
68 char *textVarName; /* Name of variable (malloc'ed) or NULL. If
|
jpayne@69
|
69 * non-NULL, button displays the contents of
|
jpayne@69
|
70 * this variable. */
|
jpayne@69
|
71 Pixmap bitmap; /* Bitmap to display or None. If not None then
|
jpayne@69
|
72 * text and textVar and underline are
|
jpayne@69
|
73 * ignored. */
|
jpayne@69
|
74 char *imageString; /* Name of image to display (malloc'ed), or
|
jpayne@69
|
75 * NULL. If non-NULL, bitmap, text, and
|
jpayne@69
|
76 * textVarName are ignored. */
|
jpayne@69
|
77 Tk_Image image; /* Image to display in window, or NULL if
|
jpayne@69
|
78 * none. */
|
jpayne@69
|
79
|
jpayne@69
|
80 /*
|
jpayne@69
|
81 * Information used when displaying widget:
|
jpayne@69
|
82 */
|
jpayne@69
|
83
|
jpayne@69
|
84 enum state state; /* State of button for display purposes:
|
jpayne@69
|
85 * normal, active, or disabled. */
|
jpayne@69
|
86 Tk_3DBorder normalBorder; /* Structure used to draw 3-D border and
|
jpayne@69
|
87 * background when window isn't active. NULL
|
jpayne@69
|
88 * means no such border exists. */
|
jpayne@69
|
89 Tk_3DBorder activeBorder; /* Structure used to draw 3-D border and
|
jpayne@69
|
90 * background when window is active. NULL
|
jpayne@69
|
91 * means no such border exists. */
|
jpayne@69
|
92 int borderWidth; /* Width of border. */
|
jpayne@69
|
93 int relief; /* 3-d effect: TK_RELIEF_RAISED, etc. */
|
jpayne@69
|
94 int highlightWidth; /* Width in pixels of highlight to draw around
|
jpayne@69
|
95 * widget when it has the focus. <= 0 means
|
jpayne@69
|
96 * don't draw a highlight. */
|
jpayne@69
|
97 XColor *highlightBgColorPtr;/* Color for drawing traversal highlight area
|
jpayne@69
|
98 * when highlight is off. */
|
jpayne@69
|
99 XColor *highlightColorPtr; /* Color for drawing traversal highlight. */
|
jpayne@69
|
100 int inset; /* Total width of all borders, including
|
jpayne@69
|
101 * traversal highlight and 3-D border.
|
jpayne@69
|
102 * Indicates how much interior stuff must be
|
jpayne@69
|
103 * offset from outside edges to leave room for
|
jpayne@69
|
104 * borders. */
|
jpayne@69
|
105 Tk_Font tkfont; /* Information about text font, or NULL. */
|
jpayne@69
|
106 XColor *normalFg; /* Foreground color in normal mode. */
|
jpayne@69
|
107 XColor *activeFg; /* Foreground color in active mode. NULL means
|
jpayne@69
|
108 * use normalFg instead. */
|
jpayne@69
|
109 XColor *disabledFg; /* Foreground color when disabled. NULL means
|
jpayne@69
|
110 * use normalFg with a 50% stipple instead. */
|
jpayne@69
|
111 GC normalTextGC; /* GC for drawing text in normal mode. */
|
jpayne@69
|
112 GC activeTextGC; /* GC for drawing text in active mode (NULL
|
jpayne@69
|
113 * means use normalTextGC). */
|
jpayne@69
|
114 Pixmap gray; /* Pixmap for displaying disabled text/icon if
|
jpayne@69
|
115 * disabledFg is NULL. */
|
jpayne@69
|
116 GC disabledGC; /* Used to produce disabled effect for
|
jpayne@69
|
117 * text. */
|
jpayne@69
|
118 GC stippleGC; /* Used to produce disabled stipple effect for
|
jpayne@69
|
119 * images when disabled. */
|
jpayne@69
|
120 int leftBearing; /* Distance from text origin to leftmost drawn
|
jpayne@69
|
121 * pixel (positive means to right). */
|
jpayne@69
|
122 int rightBearing; /* Amount text sticks right from its
|
jpayne@69
|
123 * origin. */
|
jpayne@69
|
124 char *widthString; /* Value of -width option. Malloc'ed. */
|
jpayne@69
|
125 char *heightString; /* Value of -height option. Malloc'ed. */
|
jpayne@69
|
126 int width, height; /* If > 0, these specify dimensions to request
|
jpayne@69
|
127 * for window, in characters for text and in
|
jpayne@69
|
128 * pixels for bitmaps. In this case the actual
|
jpayne@69
|
129 * size of the text string or bitmap is
|
jpayne@69
|
130 * ignored in computing desired window
|
jpayne@69
|
131 * size. */
|
jpayne@69
|
132 int wrapLength; /* Line length (in pixels) at which to wrap
|
jpayne@69
|
133 * onto next line. <= 0 means don't wrap
|
jpayne@69
|
134 * except at newlines. */
|
jpayne@69
|
135 int padX, padY; /* Extra space around text or bitmap (pixels
|
jpayne@69
|
136 * on each side). */
|
jpayne@69
|
137 Tk_Anchor anchor; /* Where text/bitmap should be displayed
|
jpayne@69
|
138 * inside window region. */
|
jpayne@69
|
139 Tk_Justify justify; /* Justification to use for multi-line
|
jpayne@69
|
140 * text. */
|
jpayne@69
|
141 int textWidth; /* Width needed to display text as requested,
|
jpayne@69
|
142 * in pixels. */
|
jpayne@69
|
143 int textHeight; /* Height needed to display text as requested,
|
jpayne@69
|
144 * in pixels. */
|
jpayne@69
|
145 Tk_TextLayout textLayout; /* Saved text layout information. */
|
jpayne@69
|
146 int indicatorOn; /* Non-zero means display indicator; 0 means
|
jpayne@69
|
147 * don't display. */
|
jpayne@69
|
148 int indicatorHeight; /* Height of indicator in pixels. This same
|
jpayne@69
|
149 * amount of extra space is also left on each
|
jpayne@69
|
150 * side of the indicator. 0 if no
|
jpayne@69
|
151 * indicator. */
|
jpayne@69
|
152 int indicatorWidth; /* Width of indicator in pixels, including
|
jpayne@69
|
153 * indicatorHeight in padding on each side. 0
|
jpayne@69
|
154 * if no indicator. */
|
jpayne@69
|
155
|
jpayne@69
|
156 /*
|
jpayne@69
|
157 * Miscellaneous information:
|
jpayne@69
|
158 */
|
jpayne@69
|
159
|
jpayne@69
|
160 int compound; /* Value of -compound option; specifies
|
jpayne@69
|
161 * whether the menubutton should show both an
|
jpayne@69
|
162 * image and text, and, if so, how. */
|
jpayne@69
|
163 enum direction direction; /* Direction for where to pop the menu. Valid
|
jpayne@69
|
164 * directions are "above", "below", "left",
|
jpayne@69
|
165 * "right", and "flush". "flush" means that
|
jpayne@69
|
166 * the upper left corner of the menubutton is
|
jpayne@69
|
167 * where the menu pops up. "above" and "below"
|
jpayne@69
|
168 * will attempt to pop the menu compleletly
|
jpayne@69
|
169 * above or below the menu respectively.
|
jpayne@69
|
170 * "left" and "right" will pop the menu left
|
jpayne@69
|
171 * or right, and the active item will be next
|
jpayne@69
|
172 * to the button. */
|
jpayne@69
|
173 Tk_Cursor cursor; /* Current cursor for window, or NULL. */
|
jpayne@69
|
174 char *takeFocus; /* Value of -takefocus option; not used in the
|
jpayne@69
|
175 * C code, but used by keyboard traversal
|
jpayne@69
|
176 * scripts. Malloc'ed, but may be NULL. */
|
jpayne@69
|
177 int flags; /* Various flags; see below for
|
jpayne@69
|
178 * definitions. */
|
jpayne@69
|
179 } TkMenuButton;
|
jpayne@69
|
180
|
jpayne@69
|
181 /*
|
jpayne@69
|
182 * Flag bits for buttons:
|
jpayne@69
|
183 *
|
jpayne@69
|
184 * REDRAW_PENDING: Non-zero means a DoWhenIdle handler has
|
jpayne@69
|
185 * already been queued to redraw this window.
|
jpayne@69
|
186 * POSTED: Non-zero means that the menu associated with
|
jpayne@69
|
187 * this button has been posted (typically because
|
jpayne@69
|
188 * of an active button press).
|
jpayne@69
|
189 * GOT_FOCUS: Non-zero means this button currently has the
|
jpayne@69
|
190 * input focus.
|
jpayne@69
|
191 */
|
jpayne@69
|
192
|
jpayne@69
|
193 #define REDRAW_PENDING 1
|
jpayne@69
|
194 #define POSTED 2
|
jpayne@69
|
195 #define GOT_FOCUS 4
|
jpayne@69
|
196
|
jpayne@69
|
197 /*
|
jpayne@69
|
198 * The following constants define the dimensions of the cascade indicator,
|
jpayne@69
|
199 * which is displayed if the "-indicatoron" option is true. The units for
|
jpayne@69
|
200 * these options are 1/10 millimeters.
|
jpayne@69
|
201 */
|
jpayne@69
|
202
|
jpayne@69
|
203 #define INDICATOR_WIDTH 40
|
jpayne@69
|
204 #define INDICATOR_HEIGHT 17
|
jpayne@69
|
205
|
jpayne@69
|
206 /*
|
jpayne@69
|
207 * Declaration of procedures used in the implementation of the button widget.
|
jpayne@69
|
208 */
|
jpayne@69
|
209
|
jpayne@69
|
210 MODULE_SCOPE void TkpComputeMenuButtonGeometry(TkMenuButton *mbPtr);
|
jpayne@69
|
211 MODULE_SCOPE TkMenuButton *TkpCreateMenuButton(Tk_Window tkwin);
|
jpayne@69
|
212 MODULE_SCOPE void TkpDisplayMenuButton(ClientData clientData);
|
jpayne@69
|
213 MODULE_SCOPE void TkpDestroyMenuButton(TkMenuButton *mbPtr);
|
jpayne@69
|
214 MODULE_SCOPE void TkMenuButtonWorldChanged(ClientData instanceData);
|
jpayne@69
|
215
|
jpayne@69
|
216 #endif /* _TKMENUBUTTON */
|