1/*
2 * tkMenubutton.h --
3 *
4 *	Declarations of types and functions used to implement
5 *	the menubutton widget.
6 *
7 * Copyright (c) 1996-1997 by Sun Microsystems, Inc.
8 *
9 * See the file "license.terms" for information on usage and redistribution
10 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 *
12 * RCS: @(#) $Id: tkMenubutton.h,v 1.8.4.1 2003/11/17 23:29:36 hobbs Exp $
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
50 * widget managed by this file:
51 */
52
53typedef struct {
54    Tk_Window tkwin;		/* Window that embodies the widget.  NULL
55				 * means that the window has been destroyed
56				 * but the data structures haven't yet been
57				 * cleaned 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)
73				 * or NULL. */
74    int underline;		/* Index of character to underline. */
75    char *textVarName;		/* Name of variable (malloc'ed) or NULL.
76				 * If non-NULL, button displays the contents
77				 * of this variable. */
78    Pixmap bitmap;		/* Bitmap to display or None.  If not None
79				 * then text and textVar and underline
80				 * are 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
94				 * border and background when window
95				 * isn't active.  NULL means no such
96				 * border exists. */
97    Tk_3DBorder activeBorder;	/* Structure used to draw 3-D
98				 * border and background when window
99				 * is active.  NULL means no such
100				 * border exists. */
101    int borderWidth;		/* Width of border. */
102    int relief;			/* 3-d effect: TK_RELIEF_RAISED, etc. */
103    int highlightWidth;		/* Width in pixels of highlight to draw
104				 * around widget when it has the focus.
105				 * <= 0 means don't draw a highlight. */
106    XColor *highlightBgColorPtr;
107				/* Color for drawing traversal highlight
108				 * area when highlight is off. */
109    XColor *highlightColorPtr;	/* Color for drawing traversal highlight. */
110    int inset;			/* Total width of all borders, including
111				 * traversal highlight and 3-D border.
112				 * Indicates how much interior stuff must
113				 * be offset from outside edges to leave
114				 * room for borders. */
115    Tk_Font tkfont;		/* Information about text font, or NULL. */
116    XColor *normalFg;		/* Foreground color in normal mode. */
117    XColor *activeFg;		/* Foreground color in active mode.  NULL
118				 * means use normalFg instead. */
119    XColor *disabledFg;		/* Foreground color when disabled.  NULL
120				 * means use normalFg with a 50% stipple
121				 * instead. */
122    GC normalTextGC;		/* GC for drawing text in normal mode. */
123    GC activeTextGC;		/* GC for drawing text in active mode (NULL
124				 * means use normalTextGC). */
125    Pixmap gray;		/* Pixmap for displaying disabled text/icon if
126				 * disabledFg is NULL. */
127    GC disabledGC;		/* Used to produce disabled effect for text. */
128    GC stippleGC;		/* Used to produce disabled stipple effect
129				 * for images when disabled. */
130    int leftBearing;		/* Distance from text origin to leftmost drawn
131				 * pixel (positive means to right). */
132    int rightBearing;		/* Amount text sticks right from its origin. */
133    char *widthString;		/* Value of -width option.  Malloc'ed. */
134    char *heightString;		/* Value of -height option.  Malloc'ed. */
135    int width, height;		/* If > 0, these specify dimensions to request
136				 * for window, in characters for text and in
137				 * pixels for bitmaps.  In this case the actual
138				 * size of the text string or bitmap is
139				 * ignored in computing desired window size. */
140    int wrapLength;		/* Line length (in pixels) at which to wrap
141				 * onto next line.  <= 0 means don't wrap
142				 * except at newlines. */
143    int padX, padY;		/* Extra space around text or bitmap (pixels
144				 * on each side). */
145    Tk_Anchor anchor;		/* Where text/bitmap should be displayed
146				 * inside window region. */
147    Tk_Justify justify;		/* Justification to use for multi-line 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 indicator. */
158    int indicatorWidth;		/* Width of indicator in pixels, including
159				 * indicatorHeight in padding on each side.
160				 * 0 if no indicator. */
161
162    /*
163     * Miscellaneous information:
164     */
165
166    int compound;               /* Value of -compound option; specifies whether
167                                 * the menubutton should show both an image and
168                                 * text, and, if so, how. */
169
170    enum direction direction;	/* Direction for where to pop the menu.
171    				 * Valid directions are "above", "below",
172    				 * "left", "right", and "flush". "flush"
173    				 * means that the upper left corner of the
174    				 * menubutton is where the menu pops up.
175    				 * "above" and "below" will attempt to pop
176    				 * the menu compleletly above or below
177    				 * the menu respectively.
178    				 * "left" and "right" will pop the menu
179    				 * left or right, and the active item
180    				 * will be next to the button. */
181    Tk_Cursor cursor;		/* Current cursor for window, or None. */
182    char *takeFocus;		/* Value of -takefocus option;  not used in
183				 * the C code, but used by keyboard traversal
184				 * scripts.  Malloc'ed, but may be NULL. */
185    int flags;			/* Various flags;  see below for
186				 * definitions. */
187} TkMenuButton;
188
189/*
190 * Flag bits for buttons:
191 *
192 * REDRAW_PENDING:		Non-zero means a DoWhenIdle handler
193 *				has already been queued to redraw
194 *				this window.
195 * POSTED:			Non-zero means that the menu associated
196 *				with this button has been posted (typically
197 *				because of an active button press).
198 * GOT_FOCUS:			Non-zero means this button currently
199 *				has the input focus.
200 */
201
202#define REDRAW_PENDING		1
203#define POSTED			2
204#define GOT_FOCUS		4
205
206/*
207 * The following constants define the dimensions of the cascade indicator,
208 * which is displayed if the "-indicatoron" option is true.  The units for
209 * these options are 1/10 millimeters.
210 */
211
212#define INDICATOR_WIDTH		40
213#define INDICATOR_HEIGHT	17
214
215/*
216 * Declaration of variables shared between the files in the button module.
217 */
218
219extern Tk_ClassProcs tkpMenubuttonClass;
220
221/*
222 * Declaration of procedures used in the implementation of the button
223 * widget.
224 */
225
226EXTERN void		TkpComputeMenuButtonGeometry _ANSI_ARGS_((
227			    TkMenuButton *mbPtr));
228EXTERN TkMenuButton *	TkpCreateMenuButton _ANSI_ARGS_((Tk_Window tkwin));
229EXTERN void		TkpDisplayMenuButton _ANSI_ARGS_((
230			    ClientData clientData));
231EXTERN void 		TkpDestroyMenuButton _ANSI_ARGS_((
232			    TkMenuButton *mbPtr));
233EXTERN void		TkMenuButtonWorldChanged _ANSI_ARGS_((
234			    ClientData instanceData));
235
236# undef TCL_STORAGE_CLASS
237# define TCL_STORAGE_CLASS DLLIMPORT
238
239#endif /* _TKMENUBUTTON */
240