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