/*
* tkMenubutton.c --
*
* This module implements button-like widgets that are used
* to invoke pull-down menus.
*
* Copyright (c) 1990-1994 The Regents of the University of California.
* Copyright (c) 1994-1995 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* SCCS: @(#) tkMenubutton.c 1.77 96/02/15 18:52:22
*/
#include "tkInt.h"
#include "tkDefault.h"
/*
* A data structure of the following type is kept for each
* widget managed by this file:
*/
typedef struct {
* means that the window has been destroyed
* but the data structures haven't yet been
* cleaned up.*/
* other things, so that resources can bee
* freed up even after tkwin has gone away. */
* Malloc-ed. */
/*
* Information about what's displayed in the menu button:
*/
* or NULL. */
* If non-NULL, button displays the contents
* of this variable. */
* then text and textVar and underline
* are ignored. */
* NULL. If non-NULL, bitmap, text, and
* textVarName are ignored. */
* none. */
/*
* Information used when displaying widget:
*/
* normal, active, or disabled. */
* border and background when window
* isn't active. NULL means no such
* border exists. */
* border and background when window
* is active. NULL means no such
* border exists. */
* around widget when it has the focus.
* <= 0 means don't draw a highlight. */
/* Color for drawing traversal highlight
* area when highlight is off. */
* traversal highlight and 3-D border.
* Indicates how much interior stuff must
* be offset from outside edges to leave
* room for borders. */
* means use normalFg instead. */
* means use normalFg with a 50% stipple
* instead. */
* means use normalTextGC). */
* disabledFg is NULL. */
* disabledFg isn't NULL, this GC is used to
* draw button text or icon. Otherwise
* text or icon is drawn with normalGC and
* this GC is used to stipple background
* across it. */
* pixel (positive means to right). */
* for window, in characters for text and in
* pixels for bitmaps. In this case the actual
* size of the text string or bitmap is
* ignored in computing desired window size. */
* onto next line. <= 0 means don't wrap
* except at newlines. */
* on each side). */
* inside window region. */
* in pixels. */
* in pixels. */
* don't display. */
* amount of extra space is also left on each
* side of the indicator. 0 if no indicator. */
* indicatorHeight in padding on each side.
* 0 if no indicator. */
/*
* Miscellaneous information:
*/
* the C code, but used by keyboard traversal
* scripts. Malloc'ed, but may be NULL. */
* definitions. */
} MenuButton;
/*
* Flag bits for buttons:
*
* REDRAW_PENDING: Non-zero means a DoWhenIdle handler
* has already been queued to redraw
* this window.
* POSTED: Non-zero means that the menu associated
* with this button has been posted (typically
* because of an active button press).
* GOT_FOCUS: Non-zero means this button currently
* has the input focus.
*/
/*
* The following constants define the dimensions of the cascade indicator,
* which is displayed if the "-indicatoron" option is true. The units for
* these options are 1/10 millimeters.
*/
/*
* Information used for parsing configuration specs:
*/
(char *) NULL, 0, 0},
(char *) NULL, 0, 0},
"DisabledForeground", DEF_MENUBUTTON_DISABLED_FG_COLOR,
"DisabledForeground", DEF_MENUBUTTON_DISABLED_FG_MONO,
(char *) NULL, 0, 0},
"HighlightBackground", DEF_MENUBUTTON_HIGHLIGHT_BG,
"HighlightThickness", DEF_MENUBUTTON_HIGHLIGHT_WIDTH,
(char *) NULL, 0, 0}
};
/*
* Forward declarations for procedures defined later in this file:
*/
static void ComputeMenuButtonGeometry _ANSI_ARGS_((
MenuButton *mbPtr));
static void MenuButtonCmdDeletedProc _ANSI_ARGS_((
int imgHeight));
static char * MenuButtonTextVarProc _ANSI_ARGS_((
int flags));
/*
*--------------------------------------------------------------
*
* Tk_MenubuttonCmd --
*
* This procedure is invoked to process the "button", "label",
* "radiobutton", and "checkbutton" Tcl commands. See the
* user documentation for details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*--------------------------------------------------------------
*/
int
* interpreter. */
int argc; /* Number of arguments. */
char **argv; /* Argument strings. */
{
if (argc < 2) {
return TCL_ERROR;
}
/*
* Create the new window.
*/
return TCL_ERROR;
}
/*
* Initialize the data structure for the button.
*/
mbPtr->borderWidth = 0;
mbPtr->highlightWidth = 0;
mbPtr->leftBearing = 0;
mbPtr->rightBearing = 0;
mbPtr->wrapLength = 0;
mbPtr->indicatorOn = 0;
mbPtr->indicatorWidth = 0;
mbPtr->indicatorHeight = 0;
return TCL_ERROR;
}
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* MenuButtonWidgetCmd --
*
* This procedure is invoked to process the Tcl command
* that corresponds to a widget managed by this module.
* See the user documentation for details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*--------------------------------------------------------------
*/
static int
int argc; /* Number of arguments. */
char **argv; /* Argument strings. */
{
int c;
if (argc < 2) {
" option ?arg arg ...?\"", (char *) NULL);
return TCL_ERROR;
}
c = argv[1][0];
&& (length >= 2)) {
if (argc != 3) {
argv[0], " cget option\"",
(char *) NULL);
goto error;
}
&& (length >= 2)) {
if (argc == 2) {
} else if (argc == 3) {
} else {
}
} else {
"\": must be cget or configure",
(char *) NULL);
goto error;
}
return result;
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
*
* DestroyMenuButton --
*
* This procedure is invoked to recycle all of the resources
* associated with a button widget. It is invoked as a
* when-idle handler in order to make sure that there is no
* other use of the button pending at the time of the deletion.
*
* Results:
* None.
*
* Side effects:
* Everything associated with the widget is freed up.
*
*----------------------------------------------------------------------
*/
static void
char *memPtr; /* Info about button widget. */
{
/*
* Free up all the stuff that requires special handling, then
* let Tk_FreeOptions handle all the standard option-related
* stuff.
*/
}
}
}
}
}
}
}
/*
*----------------------------------------------------------------------
*
* ConfigureMenuButton --
*
* the Tk option database, in order to configure (or
* reconfigure) a menubutton widget.
*
* Results:
* The return value is a standard Tcl result. If TCL_ERROR is
* returned, then interp->result contains an error message.
*
* Side effects:
* Configuration information, such as text string, colors, font,
* etc. get set for mbPtr; old resources get freed, if there
* were any. The menubutton is redisplayed.
*
*----------------------------------------------------------------------
*/
static int
* not already have values for some fields. */
int argc; /* Number of valid entries in argv. */
char **argv; /* Arguments. */
int flags; /* Flags to pass to Tk_ConfigureWidget. */
{
unsigned long mask;
int result;
/*
* Eliminate any existing trace on variables monitored by the menubutton.
*/
}
return TCL_ERROR;
}
/*
* A few options need special processing, such as setting the
* background from a 3-D border, or filling in complicated
* defaults that couldn't be specified to Tk_ConfigureWidget.
*/
} else {
"\": must be normal, active, or disabled", (char *) NULL);
return TCL_ERROR;
}
}
if (mbPtr->highlightWidth < 0) {
mbPtr->highlightWidth = 0;
}
/*
* Note: GraphicsExpose events are disabled in GC's because they're
* used to copy stuff from an off-screen pixmap onto the screen (we know
* that there's no problem with obscured areas).
*/
}
&gcValues);
}
} else {
Tk_GetUid("gray50"));
return TCL_ERROR;
}
}
}
}
}
}
/*
* Get the image for the widget, if there is one. Allocate the
* new image before freeing the old one, so that the reference
* count doesn't go to zero and cause image data to be discarded.
*/
return TCL_ERROR;
}
} else {
}
}
/*
* The menubutton displays a variable. Set up a trace to watch
* for any changes in it.
*/
char *value;
} else {
}
}
}
/*
* Recompute the geometry for the button.
*/
return TCL_ERROR;
}
return TCL_ERROR;
}
} else {
!= TCL_OK) {
goto widthError;
}
!= TCL_OK) {
goto heightError;
}
}
/*
* Lastly, arrange for the button to be redisplayed.
*/
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* DisplayMenuButton --
*
* This procedure is invoked to display a menubutton widget.
*
* Results:
* None.
*
* Side effects:
* Commands are output to X to display the menubutton in its
* current mode.
*
*----------------------------------------------------------------------
*/
static void
{
int x = 0; /* Initialization needed only to stop
* compiler warning. */
int y;
return;
}
} else {
}
/*
* In order to avoid screen flashes, this procedure redraws
* the menu button in a pixmap, then copies the pixmap to the
* screen in a single operation. This means that there's no
* point in time where the on-sreen image has been cleared.
*/
/*
* Display image or bitmap or text for button.
*/
break;
break;
default:
- mbPtr->indicatorWidth;
break;
}
break;
break;
default:
break;
}
x, y);
} else {
}
goto imageOrBitmap;
} else {
break;
break;
default:
- mbPtr->indicatorWidth;
break;
}
break;
break;
default:
break;
}
}
/*
* If the menu button is disabled with a stipple rather than a special
* foreground color, generate the stippled effect.
*/
}
/*
* Draw the cascade indicator for the menu button on the
* right side of the window, if desired.
*/
if (mbPtr->indicatorOn) {
int borderWidth;
if (borderWidth < 1) {
borderWidth = 1;
}
+ mbPtr->indicatorHeight,
}
/*
* Draw the border and traversal highlight last. This way, if the
* menu button's contents overflow onto the border they'll be covered
* up by the border.
*/
}
if (mbPtr->highlightWidth != 0) {
} else {
}
}
/*
* Copy the information from the off-screen pixmap onto the screen,
* then delete the pixmap.
*/
}
/*
*--------------------------------------------------------------
*
* MenuButtonEventProc --
*
* This procedure is invoked by the Tk dispatcher for various
* events on buttons.
*
* Results:
* None.
*
* Side effects:
* When the window gets deleted, internal structures get
* cleaned up. When it gets exposed, it is redisplayed.
*
*--------------------------------------------------------------
*/
static void
{
goto redraw;
/*
* Must redraw after size changes, since layout could have changed
* and borders will need to be redrawn.
*/
goto redraw;
}
}
if (mbPtr->highlightWidth > 0) {
goto redraw;
}
}
if (mbPtr->highlightWidth > 0) {
goto redraw;
}
}
}
return;
}
}
/*
*----------------------------------------------------------------------
*
* MenuButtonCmdDeletedProc --
*
* This procedure is invoked when a widget command is deleted. If
* the widget isn't already in the process of being destroyed,
* this command destroys it.
*
* Results:
* None.
*
* Side effects:
* The widget is destroyed.
*
*----------------------------------------------------------------------
*/
static void
{
/*
* This procedure could be invoked either because the window was
* destroyed and the command was then deleted (in which case tkwin
* is NULL) or because the command was deleted, and then this procedure
* destroys the widget.
*/
}
}
/*
*----------------------------------------------------------------------
*
* ComputeMenuButtonGeometry --
*
* After changes in a menu button's text or bitmap, this procedure
* recomputes the menu button's geometry and passes this information
* along to the geometry manager for the window.
*
* Results:
* None.
*
* Side effects:
* The menu button's window may change size.
*
*----------------------------------------------------------------------
*/
static void
{
}
}
}
}
} else {
&mbPtr->textHeight);
}
}
}
if (mbPtr->indicatorOn) {
} else {
mbPtr->indicatorHeight = 0;
mbPtr->indicatorWidth = 0;
}
}
/*
*--------------------------------------------------------------
*
* MenuButtonTextVarProc --
*
* This procedure is invoked when someone changes the variable
* whose contents are to be displayed in a menu button.
*
* Results:
* NULL is always returned.
*
* Side effects:
* The text displayed in the menu button will change to match the
* variable.
*
*--------------------------------------------------------------
*/
/* ARGSUSED */
static char *
char *name1; /* Name of variable. */
char *name2; /* Second part of variable name. */
int flags; /* Information about what happened. */
{
char *value;
/*
* If the variable is unset, then immediately recreate it unless
* the whole interpreter is going away.
*/
if (flags & TCL_TRACE_UNSETS) {
}
return (char *) NULL;
}
value = "";
}
}
}
return (char *) NULL;
}
/*
*----------------------------------------------------------------------
*
* MenuButtonImageProc --
*
* This procedure is invoked by the image code whenever the manager
* for an image does something that affects the size of contents
* of an image displayed in a button.
*
* Results:
* None.
*
* Side effects:
* Arranges for the button to get redisplayed.
*
*----------------------------------------------------------------------
*/
static void
int x, y; /* Upper left pixel (within image)
* that must be redisplayed. */
* (may be <= 0). */
{
}
}
}