summaryrefslogtreecommitdiffstats
path: root/generic/tkMenubutton.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tkMenubutton.c')
-rw-r--r--generic/tkMenubutton.c493
1 files changed, 246 insertions, 247 deletions
diff --git a/generic/tkMenubutton.c b/generic/tkMenubutton.c
index 0e85308..94ac8b2 100644
--- a/generic/tkMenubutton.c
+++ b/generic/tkMenubutton.c
@@ -1,115 +1,114 @@
-/*
+/*
* tkMenubutton.c --
*
- * This module implements button-like widgets that are used
- * to invoke pull-down menus.
+ * 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-1997 Sun Microsystems, Inc.
*
- * See the file "license.terms" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ * See the file "license.terms" for information on usage and redistribution of
+ * this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
+#include "tkInt.h"
#include "tkMenubutton.h"
-#include "tkPort.h"
#include "default.h"
/*
- * The following table defines the legal values for the -direction
- * option. It is used together with the "enum direction" declaration
- * in tkMenubutton.h.
+ * The following table defines the legal values for the -direction option. It
+ * is used together with the "enum direction" declaration in tkMenubutton.h.
*/
-static CONST char *CONST directionStrings[] = {
- "above", "below", "flush", "left", "right", (char *) NULL
+static const char *const directionStrings[] = {
+ "above", "below", "flush", "left", "right", NULL
};
/*
- * The following table defines the legal values for the -state option.
- * It is used together with the "enum state" declaration in tkMenubutton.h.
+ * The following table defines the legal values for the -state option. It is
+ * used together with the "enum state" declaration in tkMenubutton.h.
*/
-static CONST char *CONST stateStrings[] = {
- "active", "disabled", "normal", (char *) NULL
+static const char *const stateStrings[] = {
+ "active", "disabled", "normal", NULL
};
/*
- * The following table defines the legal values for the -compound option.
- * It is used with the "enum compound" declaration in tkMenuButton.h
+ * The following table defines the legal values for the -compound option. It
+ * is used with the "enum compound" declaration in tkMenuButton.h
*/
-static CONST char *CONST compoundStrings[] = {
- "bottom", "center", "left", "none", "right", "top", (char *) NULL
+static const char *const compoundStrings[] = {
+ "bottom", "center", "left", "none", "right", "top", NULL
};
/*
* Information used for parsing configuration specs:
*/
-static CONST Tk_OptionSpec optionSpecs[] = {
+static const Tk_OptionSpec optionSpecs[] = {
{TK_OPTION_BORDER, "-activebackground", "activeBackground", "Foreground",
- DEF_MENUBUTTON_ACTIVE_BG_COLOR, -1,
- Tk_Offset(TkMenuButton, activeBorder), 0,
- (ClientData) DEF_MENUBUTTON_ACTIVE_BG_MONO, 0},
+ DEF_MENUBUTTON_ACTIVE_BG_COLOR, -1,
+ Tk_Offset(TkMenuButton, activeBorder), 0,
+ (ClientData) DEF_MENUBUTTON_ACTIVE_BG_MONO, 0},
{TK_OPTION_COLOR, "-activeforeground", "activeForeground", "Background",
- DEF_MENUBUTTON_ACTIVE_FG_COLOR, -1,
- Tk_Offset(TkMenuButton, activeFg),
- 0, (ClientData) DEF_MENUBUTTON_ACTIVE_FG_MONO, 0},
+ DEF_MENUBUTTON_ACTIVE_FG_COLOR, -1,
+ Tk_Offset(TkMenuButton, activeFg),
+ 0, (ClientData) DEF_MENUBUTTON_ACTIVE_FG_MONO, 0},
{TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor",
- DEF_MENUBUTTON_ANCHOR, -1,
- Tk_Offset(TkMenuButton, anchor), 0, 0, 0},
+ DEF_MENUBUTTON_ANCHOR, -1,
+ Tk_Offset(TkMenuButton, anchor), 0, 0, 0},
{TK_OPTION_BORDER, "-background", "background", "Background",
DEF_MENUBUTTON_BG_COLOR, -1, Tk_Offset(TkMenuButton, normalBorder),
- 0, (ClientData) DEF_MENUBUTTON_BG_MONO, 0},
- {TK_OPTION_SYNONYM, "-bd", (char *) NULL, (char *) NULL,
- (char *) NULL, 0, -1, 0, (ClientData) "-borderwidth", 0},
- {TK_OPTION_SYNONYM, "-bg", (char *) NULL, (char *) NULL,
- (char *) NULL, 0, -1, 0, (ClientData) "-background", 0},
+ 0, (ClientData) DEF_MENUBUTTON_BG_MONO, 0},
+ {TK_OPTION_SYNONYM, "-bd", NULL, NULL, NULL, 0, -1, 0,
+ (ClientData) "-borderwidth", 0},
+ {TK_OPTION_SYNONYM, "-bg", NULL, NULL, NULL, 0, -1, 0,
+ (ClientData) "-background", 0},
{TK_OPTION_BITMAP, "-bitmap", "bitmap", "Bitmap",
DEF_MENUBUTTON_BITMAP, -1, Tk_Offset(TkMenuButton, bitmap),
TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
- DEF_MENUBUTTON_BORDER_WIDTH, -1,
- Tk_Offset(TkMenuButton, borderWidth), 0, 0, 0},
+ DEF_MENUBUTTON_BORDER_WIDTH, -1,
+ Tk_Offset(TkMenuButton, borderWidth), 0, 0, 0},
{TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor",
DEF_MENUBUTTON_CURSOR, -1, Tk_Offset(TkMenuButton, cursor),
TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_STRING_TABLE, "-direction", "direction", "Direction",
- DEF_MENUBUTTON_DIRECTION, -1, Tk_Offset(TkMenuButton, direction),
+ DEF_MENUBUTTON_DIRECTION, -1, Tk_Offset(TkMenuButton, direction),
0, (ClientData) directionStrings, 0},
{TK_OPTION_COLOR, "-disabledforeground", "disabledForeground",
"DisabledForeground", DEF_MENUBUTTON_DISABLED_FG_COLOR,
-1, Tk_Offset(TkMenuButton, disabledFg), TK_OPTION_NULL_OK,
(ClientData) DEF_MENUBUTTON_DISABLED_FG_MONO, 0},
- {TK_OPTION_SYNONYM, "-fg", "foreground", (char *) NULL,
- (char *) NULL, 0, -1, 0, (ClientData) "-foreground", 0},
+ {TK_OPTION_SYNONYM, "-fg", "foreground", NULL, NULL, 0, -1, 0,
+ (ClientData) "-foreground", 0},
{TK_OPTION_FONT, "-font", "font", "Font",
DEF_MENUBUTTON_FONT, -1, Tk_Offset(TkMenuButton, tkfont), 0, 0, 0},
{TK_OPTION_COLOR, "-foreground", "foreground", "Foreground",
DEF_MENUBUTTON_FG, -1, Tk_Offset(TkMenuButton, normalFg), 0, 0, 0},
{TK_OPTION_STRING, "-height", "height", "Height",
- DEF_MENUBUTTON_HEIGHT, -1, Tk_Offset(TkMenuButton, heightString),
- 0, 0, 0},
+ DEF_MENUBUTTON_HEIGHT, -1, Tk_Offset(TkMenuButton, heightString),
+ 0, 0, 0},
{TK_OPTION_COLOR, "-highlightbackground", "highlightBackground",
"HighlightBackground", DEF_MENUBUTTON_HIGHLIGHT_BG_COLOR,
-1, Tk_Offset(TkMenuButton, highlightBgColorPtr), 0, 0, 0},
{TK_OPTION_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
- DEF_MENUBUTTON_HIGHLIGHT, -1,
- Tk_Offset(TkMenuButton, highlightColorPtr), 0, 0, 0},
+ DEF_MENUBUTTON_HIGHLIGHT, -1,
+ Tk_Offset(TkMenuButton, highlightColorPtr), 0, 0, 0},
{TK_OPTION_PIXELS, "-highlightthickness", "highlightThickness",
"HighlightThickness", DEF_MENUBUTTON_HIGHLIGHT_WIDTH,
-1, Tk_Offset(TkMenuButton, highlightWidth), 0, 0, 0},
{TK_OPTION_STRING, "-image", "image", "Image",
- DEF_MENUBUTTON_IMAGE, -1, Tk_Offset(TkMenuButton, imageString),
+ DEF_MENUBUTTON_IMAGE, -1, Tk_Offset(TkMenuButton, imageString),
TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_BOOLEAN, "-indicatoron", "indicatorOn", "IndicatorOn",
DEF_MENUBUTTON_INDICATOR, -1, Tk_Offset(TkMenuButton, indicatorOn),
- 0, 0, 0},
+ 0, 0, 0},
{TK_OPTION_JUSTIFY, "-justify", "justify", "Justify",
- DEF_BUTTON_JUSTIFY, -1, Tk_Offset(TkMenuButton, justify), 0, 0, 0},
+ DEF_MENUBUTTON_JUSTIFY, -1, Tk_Offset(TkMenuButton, justify), 0, 0, 0},
{TK_OPTION_STRING, "-menu", "menu", "Menu",
- DEF_MENUBUTTON_MENU, -1, Tk_Offset(TkMenuButton, menuName),
+ DEF_MENUBUTTON_MENU, -1, Tk_Offset(TkMenuButton, menuName),
TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_PIXELS, "-padx", "padX", "Pad",
DEF_MENUBUTTON_PADX, -1, Tk_Offset(TkMenuButton, padX),
@@ -118,43 +117,42 @@ static CONST Tk_OptionSpec optionSpecs[] = {
DEF_MENUBUTTON_PADY, -1, Tk_Offset(TkMenuButton, padY),
0, 0, 0},
{TK_OPTION_RELIEF, "-relief", "relief", "Relief",
- DEF_MENUBUTTON_RELIEF, -1, Tk_Offset(TkMenuButton, relief),
- 0, 0, 0},
+ DEF_MENUBUTTON_RELIEF, -1, Tk_Offset(TkMenuButton, relief),
+ 0, 0, 0},
{TK_OPTION_STRING_TABLE, "-compound", "compound", "Compound",
- DEF_BUTTON_COMPOUND, -1, Tk_Offset(TkMenuButton, compound), 0,
- (ClientData) compoundStrings, 0},
+ DEF_BUTTON_COMPOUND, -1, Tk_Offset(TkMenuButton, compound), 0,
+ (ClientData) compoundStrings, 0},
{TK_OPTION_STRING_TABLE, "-state", "state", "State",
DEF_MENUBUTTON_STATE, -1, Tk_Offset(TkMenuButton, state),
0, (ClientData) stateStrings, 0},
{TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus",
- DEF_MENUBUTTON_TAKE_FOCUS, -1,
- Tk_Offset(TkMenuButton, takeFocus), TK_OPTION_NULL_OK, 0, 0},
+ DEF_MENUBUTTON_TAKE_FOCUS, -1,
+ Tk_Offset(TkMenuButton, takeFocus), TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_STRING, "-text", "text", "Text",
DEF_MENUBUTTON_TEXT, -1, Tk_Offset(TkMenuButton, text), 0, 0, 0},
{TK_OPTION_STRING, "-textvariable", "textVariable", "Variable",
- DEF_MENUBUTTON_TEXT_VARIABLE, -1,
- Tk_Offset(TkMenuButton, textVarName), TK_OPTION_NULL_OK, 0, 0},
+ DEF_MENUBUTTON_TEXT_VARIABLE, -1,
+ Tk_Offset(TkMenuButton, textVarName), TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_INT, "-underline", "underline", "Underline",
DEF_MENUBUTTON_UNDERLINE, -1, Tk_Offset(TkMenuButton, underline),
- 0, 0, 0},
+ 0, 0, 0},
{TK_OPTION_STRING, "-width", "width", "Width",
- DEF_MENUBUTTON_WIDTH, -1, Tk_Offset(TkMenuButton, widthString),
- 0, 0, 0},
+ DEF_MENUBUTTON_WIDTH, -1, Tk_Offset(TkMenuButton, widthString),
+ 0, 0, 0},
{TK_OPTION_PIXELS, "-wraplength", "wrapLength", "WrapLength",
DEF_MENUBUTTON_WRAP_LENGTH, -1, Tk_Offset(TkMenuButton, wrapLength),
- 0, 0, 0},
- {TK_OPTION_END, (char *) NULL, (char *) NULL, (char *) NULL,
- (char *) NULL, 0, 0}
+ 0, 0, 0},
+ {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0}
};
/*
- * The following tables define the menubutton widget commands and map the
- * indexes into the string tables into a single enumerated type used
- * to dispatch the scale widget command.
+ * The following tables define the menubutton widget commands and map the
+ * indexes into the string tables into a single enumerated type used to
+ * dispatch the scale widget command.
*/
-static CONST char *commandNames[] = {
- "cget", "configure", (char *) NULL
+static const char *commandNames[] = {
+ "cget", "configure", NULL
};
enum command {
@@ -162,35 +160,34 @@ enum command {
};
/*
- * Forward declarations for procedures defined later in this file:
+ * Forward declarations for functions defined later in this file:
*/
-static void MenuButtonCmdDeletedProc _ANSI_ARGS_((
- ClientData clientData));
-static void MenuButtonEventProc _ANSI_ARGS_((ClientData clientData,
- XEvent *eventPtr));
-static void MenuButtonImageProc _ANSI_ARGS_((ClientData clientData,
+static void MenuButtonCmdDeletedProc(ClientData clientData);
+static void MenuButtonEventProc(ClientData clientData,
+ XEvent *eventPtr);
+static void MenuButtonImageProc(ClientData clientData,
int x, int y, int width, int height, int imgWidth,
- int imgHeight));
-static char * MenuButtonTextVarProc _ANSI_ARGS_((
- ClientData clientData, Tcl_Interp *interp,
- CONST char *name1, CONST char *name2, int flags));
-static int MenuButtonWidgetObjCmd _ANSI_ARGS_((
- ClientData clientData, Tcl_Interp *interp,
- int objc, Tcl_Obj *CONST objv[]));
-static int ConfigureMenuButton _ANSI_ARGS_((Tcl_Interp *interp,
- TkMenuButton *mbPtr, int objc,
- Tcl_Obj *CONST objv[]));
-static void DestroyMenuButton _ANSI_ARGS_((char *memPtr));
+ int imgHeight);
+static char * MenuButtonTextVarProc(ClientData clientData,
+ Tcl_Interp *interp, const char *name1,
+ const char *name2, int flags);
+static int MenuButtonWidgetObjCmd(ClientData clientData,
+ Tcl_Interp *interp, int objc,
+ Tcl_Obj *const objv[]);
+static int ConfigureMenuButton(Tcl_Interp *interp,
+ TkMenuButton *mbPtr, int objc,
+ Tcl_Obj *const objv[]);
+static void DestroyMenuButton(char *memPtr);
/*
*--------------------------------------------------------------
*
* Tk_MenubuttonObjCmd --
*
- * This procedure is invoked to process the "button", "label",
- * "radiobutton", and "checkbutton" Tcl commands. See the
- * user documentation for details on what it does.
+ * This function 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.
@@ -202,11 +199,11 @@ static void DestroyMenuButton _ANSI_ARGS_((char *memPtr));
*/
int
-Tk_MenubuttonObjCmd(clientData, interp, objc, objv)
- ClientData clientData; /* NULL. */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
+Tk_MenubuttonObjCmd(
+ ClientData clientData, /* NULL. */
+ Tcl_Interp *interp, /* Current interpreter. */
+ int objc, /* Number of arguments. */
+ Tcl_Obj *const objv[]) /* Argument objects. */
{
register TkMenuButton *mbPtr;
Tk_OptionTable optionTable;
@@ -222,14 +219,14 @@ Tk_MenubuttonObjCmd(clientData, interp, objc, objv)
*/
tkwin = Tk_CreateWindowFromPath(interp, Tk_MainWindow(interp),
- Tcl_GetString(objv[1]), (char *) NULL);
+ Tcl_GetString(objv[1]), NULL);
if (tkwin == NULL) {
return TCL_ERROR;
}
/*
- * Create the option table for this widget class. If it has already
- * been created, the cached pointer will be returned.
+ * Create the option table for this widget class. If it has already been
+ * created, the cached pointer will be returned.
*/
optionTable = Tk_CreateOptionTable(interp, optionSpecs);
@@ -246,9 +243,9 @@ Tk_MenubuttonObjCmd(clientData, interp, objc, objv)
mbPtr->tkwin = tkwin;
mbPtr->display = Tk_Display (tkwin);
mbPtr->interp = interp;
- mbPtr->widgetCmd = Tcl_CreateObjCommand(interp,
- Tk_PathName(mbPtr->tkwin), MenuButtonWidgetObjCmd,
- (ClientData) mbPtr, MenuButtonCmdDeletedProc);
+ mbPtr->widgetCmd = Tcl_CreateObjCommand(interp,
+ Tk_PathName(mbPtr->tkwin), MenuButtonWidgetObjCmd,
+ (ClientData) mbPtr, MenuButtonCmdDeletedProc);
mbPtr->optionTable = optionTable;
mbPtr->menuName = NULL;
mbPtr->text = NULL;
@@ -318,9 +315,9 @@ Tk_MenubuttonObjCmd(clientData, interp, objc, objv)
*
* MenuButtonWidgetObjCmd --
*
- * 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.
+ * This function 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.
@@ -332,66 +329,62 @@ Tk_MenubuttonObjCmd(clientData, interp, objc, objv)
*/
static int
-MenuButtonWidgetObjCmd(clientData, interp, objc, objv)
- ClientData clientData; /* Information about button widget. */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
+MenuButtonWidgetObjCmd(
+ ClientData clientData, /* Information about button widget. */
+ Tcl_Interp *interp, /* Current interpreter. */
+ int objc, /* Number of arguments. */
+ Tcl_Obj *const objv[]) /* Argument objects. */
{
register TkMenuButton *mbPtr = (TkMenuButton *) clientData;
int result, index;
Tcl_Obj *objPtr;
if (objc < 2) {
- Tcl_WrongNumArgs(interp, 1, objv, "option ?arg arg ...?");
+ Tcl_WrongNumArgs(interp, 1, objv, "option ?arg arg ...?");
return TCL_ERROR;
}
- result = Tcl_GetIndexFromObj(interp, objv[1],
- commandNames, "option", 0, &index);
+ result = Tcl_GetIndexFromObj(interp, objv[1], commandNames, "option", 0,
+ &index);
if (result != TCL_OK) {
- return result;
+ return result;
}
Tcl_Preserve((ClientData) mbPtr);
switch (index) {
- case COMMAND_CGET: {
- if (objc != 3) {
- Tcl_WrongNumArgs(interp, 1, objv, "cget option");
+ case COMMAND_CGET:
+ if (objc != 3) {
+ Tcl_WrongNumArgs(interp, 1, objv, "cget option");
goto error;
- }
+ }
- objPtr = Tk_GetOptionValue(interp, (char *) mbPtr,
- mbPtr->optionTable, objv[2], mbPtr->tkwin);
- if (objPtr == NULL) {
- goto error;
- } else {
- Tcl_SetObjResult(interp, objPtr);
- }
- break;
+ objPtr = Tk_GetOptionValue(interp, (char *) mbPtr,
+ mbPtr->optionTable, objv[2], mbPtr->tkwin);
+ if (objPtr == NULL) {
+ goto error;
+ } else {
+ Tcl_SetObjResult(interp, objPtr);
}
+ break;
- case COMMAND_CONFIGURE: {
- if (objc <= 3) {
- objPtr = Tk_GetOptionInfo(interp, (char *) mbPtr,
- mbPtr->optionTable,
- (objc == 3) ? objv[2] : (Tcl_Obj *) NULL,
- mbPtr->tkwin);
- if (objPtr == NULL) {
- goto error;
- } else {
- Tcl_SetObjResult(interp, objPtr);
- }
+ case COMMAND_CONFIGURE:
+ if (objc <= 3) {
+ objPtr = Tk_GetOptionInfo(interp, (char *) mbPtr,
+ mbPtr->optionTable, (objc == 3) ? objv[2] : NULL,
+ mbPtr->tkwin);
+ if (objPtr == NULL) {
+ goto error;
} else {
- result = ConfigureMenuButton(interp, mbPtr, objc-2,
- objv+2);
+ Tcl_SetObjResult(interp, objPtr);
}
- break;
+ } else {
+ result = ConfigureMenuButton(interp, mbPtr, objc-2, objv+2);
}
+ break;
}
Tcl_Release((ClientData) mbPtr);
return result;
- error:
+ error:
Tcl_Release((ClientData) mbPtr);
return TCL_ERROR;
}
@@ -401,10 +394,10 @@ MenuButtonWidgetObjCmd(clientData, interp, objc, objv)
*
* DestroyMenuButton --
*
- * This procedure is invoked to recycle all of the resources
- * associated with a menubutton widget. It is invoked as a
- * when-idle handler in order to make sure that there is no
- * other use of the menubutton pending at the time of the deletion.
+ * This function is invoked to recycle all of the resources associated
+ * with a menubutton widget. It is invoked as a when-idle handler in
+ * order to make sure that there is no other use of the menubutton
+ * pending at the time of the deletion.
*
* Results:
* None.
@@ -416,20 +409,19 @@ MenuButtonWidgetObjCmd(clientData, interp, objc, objv)
*/
static void
-DestroyMenuButton(memPtr)
- char *memPtr; /* Info about button widget. */
+DestroyMenuButton(
+ char *memPtr) /* Info about button widget. */
{
register TkMenuButton *mbPtr = (TkMenuButton *) memPtr;
TkpDestroyMenuButton(mbPtr);
if (mbPtr->flags & REDRAW_PENDING) {
- Tcl_CancelIdleCall(TkpDisplayMenuButton, (ClientData) mbPtr);
+ Tcl_CancelIdleCall(TkpDisplayMenuButton, (ClientData) mbPtr);
}
/*
- * Free up all the stuff that requires special handling, then
- * let Tk_FreeOptions handle all the standard option-related
- * stuff.
+ * Free up all the stuff that requires special handling, then let
+ * Tk_FreeOptions handle all the standard option-related stuff.
*/
Tcl_DeleteCommandFromToken(mbPtr->interp, mbPtr->widgetCmd);
@@ -457,7 +449,7 @@ DestroyMenuButton(memPtr)
Tk_FreeBitmap(mbPtr->display, mbPtr->gray);
}
if (mbPtr->textLayout != NULL) {
- Tk_FreeTextLayout(mbPtr->textLayout);
+ Tk_FreeTextLayout(mbPtr->textLayout);
}
Tk_FreeConfigOptions((char *) mbPtr, mbPtr->optionTable, mbPtr->tkwin);
mbPtr->tkwin = NULL;
@@ -469,31 +461,30 @@ DestroyMenuButton(memPtr)
*
* ConfigureMenuButton --
*
- * This procedure is called to process an argv/argc list, plus
- * the Tk option database, in order to configure (or
- * reconfigure) a menubutton widget.
+ * This function is called to process an argv/argc list, plus 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 the interp's result contains an error message.
+ * The return value is a standard Tcl result. If TCL_ERROR is returned,
+ * then the interp's 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.
+ * 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
-ConfigureMenuButton(interp, mbPtr, objc, objv)
- Tcl_Interp *interp; /* Used for error reporting. */
- register TkMenuButton *mbPtr;
- /* Information about widget; may or may
- * not already have values for some
- * fields. */
- int objc; /* Number of valid entries in objv. */
- Tcl_Obj *CONST objv[]; /* Arguments. */
+ConfigureMenuButton(
+ Tcl_Interp *interp, /* Used for error reporting. */
+ register TkMenuButton *mbPtr,
+ /* Information about widget; may or may not
+ * already have values for some fields. */
+ int objc, /* Number of valid entries in objv. */
+ Tcl_Obj *const objv[]) /* Arguments. */
{
Tk_SavedOptions savedOptions;
Tcl_Obj *errorResult = NULL;
@@ -501,21 +492,20 @@ ConfigureMenuButton(interp, mbPtr, objc, objv)
Tk_Image image;
/*
- * Eliminate any existing trace on variables monitored by the
- * menubutton.
+ * Eliminate any existing trace on variables monitored by the menubutton.
*/
if (mbPtr->textVarName != NULL) {
- Tcl_UntraceVar(interp, mbPtr->textVarName,
+ Tcl_UntraceVar(interp, mbPtr->textVarName,
TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
MenuButtonTextVarProc, (ClientData) mbPtr);
}
/*
- * The following loop is potentially executed twice. During the
- * first pass configuration options get set to their new values.
- * If there is an error in this pass, we execute a second pass
- * to restore all the options to their previous values.
+ * The following loop is potentially executed twice. During the first pass
+ * configuration options get set to their new values. If there is an error
+ * in this pass, we execute a second pass to restore all the options to
+ * their previous values.
*/
for (error = 0; error <= 1; error++) {
@@ -526,7 +516,7 @@ ConfigureMenuButton(interp, mbPtr, objc, objv)
if (Tk_SetOptions(interp, (char *) mbPtr,
mbPtr->optionTable, objc, objv,
- mbPtr->tkwin, &savedOptions, (int *) NULL) != TCL_OK) {
+ mbPtr->tkwin, &savedOptions, NULL) != TCL_OK) {
continue;
}
} else {
@@ -541,8 +531,8 @@ ConfigureMenuButton(interp, mbPtr, objc, objv)
/*
* 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_SetOptions.
+ * background from a 3-D border, or filling in complicated defaults
+ * that couldn't be specified to Tk_SetOptions.
*/
if ((mbPtr->state == STATE_ACTIVE)
@@ -564,17 +554,17 @@ ConfigureMenuButton(interp, mbPtr, objc, objv)
}
/*
- * 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.
+ * 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.
*/
if (mbPtr->imageString != NULL) {
image = Tk_GetImage(mbPtr->interp, mbPtr->tkwin,
- mbPtr->imageString, MenuButtonImageProc,
+ mbPtr->imageString, MenuButtonImageProc,
(ClientData) mbPtr);
if (image == NULL) {
- return TCL_ERROR;
+ return TCL_ERROR;
}
} else {
image = NULL;
@@ -590,32 +580,32 @@ ConfigureMenuButton(interp, mbPtr, objc, objv)
if ((mbPtr->bitmap != None) || (mbPtr->image != NULL)) {
if (Tk_GetPixels(interp, mbPtr->tkwin, mbPtr->widthString,
- &mbPtr->width) != TCL_OK) {
- widthError:
- Tcl_AddErrorInfo(interp, "\n (processing -width option)");
+ &mbPtr->width) != TCL_OK) {
+ widthError:
+ Tcl_AddErrorInfo(interp, "\n (processing -width option)");
continue;
}
if (Tk_GetPixels(interp, mbPtr->tkwin, mbPtr->heightString,
&mbPtr->height) != TCL_OK) {
- heightError:
- Tcl_AddErrorInfo(interp, "\n (processing -height option)");
+ heightError:
+ Tcl_AddErrorInfo(interp, "\n (processing -height option)");
continue;
}
} else {
if (Tcl_GetInt(interp, mbPtr->widthString, &mbPtr->width)
!= TCL_OK) {
- goto widthError;
+ goto widthError;
}
if (Tcl_GetInt(interp, mbPtr->heightString, &mbPtr->height)
!= TCL_OK) {
- goto heightError;
+ goto heightError;
}
}
break;
}
if (!error) {
- Tk_FreeSavedOptions(&savedOptions);
+ Tk_FreeSavedOptions(&savedOptions);
}
if (mbPtr->textVarName != NULL) {
@@ -624,7 +614,7 @@ ConfigureMenuButton(interp, mbPtr, objc, objv)
* Set up a trace to watch for any changes in it, create the variable
* if it doesn't exist, and fetch its current value.
*/
- CONST char *value;
+ const char *value;
value = Tcl_GetVar(interp, mbPtr->textVarName, TCL_GLOBAL_ONLY);
if (value == NULL) {
@@ -646,10 +636,9 @@ ConfigureMenuButton(interp, mbPtr, objc, objv)
if (error) {
Tcl_SetObjResult(interp, errorResult);
Tcl_DecrRefCount(errorResult);
- return TCL_ERROR;
- } else {
- return TCL_OK;
+ return TCL_ERROR;
}
+ return TCL_OK;
}
/*
@@ -657,22 +646,22 @@ ConfigureMenuButton(interp, mbPtr, objc, objv)
*
* TkMenuButtonWorldChanged --
*
- * This procedure is called when the world has changed in some
- * way and the widget needs to recompute all its graphics contexts
- * and determine its new geometry.
+ * This function is called when the world has changed in some way and the
+ * widget needs to recompute all its graphics contexts and determine its
+ * new geometry.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * TkMenuButton will be relayed out and redisplayed.
+ * TkMenuButton will be relayed out and redisplayed.
*
*---------------------------------------------------------------------------
*/
-
+
void
-TkMenuButtonWorldChanged(instanceData)
- ClientData instanceData; /* Information about widget. */
+TkMenuButtonWorldChanged(
+ ClientData instanceData) /* Information about widget. */
{
XGCValues gcValues;
GC gc;
@@ -686,9 +675,9 @@ TkMenuButtonWorldChanged(instanceData)
gcValues.background = Tk_3DBorderColor(mbPtr->normalBorder)->pixel;
/*
- * 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).
+ * 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.graphics_exposures = False;
@@ -729,8 +718,8 @@ TkMenuButtonWorldChanged(instanceData)
}
/*
- * Allocate the disabled graphics context, for drawing text in
- * its disabled state.
+ * Allocate the disabled graphics context, for drawing text in its
+ * disabled state.
*/
mask = GCForeground | GCBackground | GCFont;
@@ -762,36 +751,36 @@ TkMenuButtonWorldChanged(instanceData)
*
* MenuButtonEventProc --
*
- * This procedure is invoked by the Tk dispatcher for various
- * events on buttons.
+ * This function 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.
+ * When the window gets deleted, internal structures get cleaned up.
+ * When it gets exposed, it is redisplayed.
*
*--------------------------------------------------------------
*/
static void
-MenuButtonEventProc(clientData, eventPtr)
- ClientData clientData; /* Information about window. */
- XEvent *eventPtr; /* Information about event. */
+MenuButtonEventProc(
+ ClientData clientData, /* Information about window. */
+ XEvent *eventPtr) /* Information about event. */
{
TkMenuButton *mbPtr = (TkMenuButton *) clientData;
if ((eventPtr->type == Expose) && (eventPtr->xexpose.count == 0)) {
goto redraw;
} else if (eventPtr->type == ConfigureNotify) {
/*
- * Must redraw after size changes, since layout could have changed
- * and borders will need to be redrawn.
+ * Must redraw after size changes, since layout could have changed and
+ * borders will need to be redrawn.
*/
goto redraw;
} else if (eventPtr->type == DestroyNotify) {
- DestroyMenuButton((char *) mbPtr);
+ DestroyMenuButton((char *) mbPtr);
} else if (eventPtr->type == FocusIn) {
if (eventPtr->xfocus.detail != NotifyInferior) {
mbPtr->flags |= GOT_FOCUS;
@@ -809,7 +798,7 @@ MenuButtonEventProc(clientData, eventPtr)
}
return;
- redraw:
+ redraw:
if ((mbPtr->tkwin != NULL) && !(mbPtr->flags & REDRAW_PENDING)) {
Tcl_DoWhenIdle(TkpDisplayMenuButton, (ClientData) mbPtr);
mbPtr->flags |= REDRAW_PENDING;
@@ -821,9 +810,9 @@ MenuButtonEventProc(clientData, eventPtr)
*
* 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.
+ * This function 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.
@@ -835,17 +824,17 @@ MenuButtonEventProc(clientData, eventPtr)
*/
static void
-MenuButtonCmdDeletedProc(clientData)
- ClientData clientData; /* Pointer to widget record for widget. */
+MenuButtonCmdDeletedProc(
+ ClientData clientData) /* Pointer to widget record for widget. */
{
TkMenuButton *mbPtr = (TkMenuButton *) clientData;
Tk_Window tkwin = mbPtr->tkwin;
/*
- * 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.
+ * This function 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 function destroys the
+ * widget.
*/
if (tkwin != NULL) {
@@ -858,8 +847,8 @@ MenuButtonCmdDeletedProc(clientData)
*
* MenuButtonTextVarProc --
*
- * This procedure is invoked when someone changes the variable
- * whose contents are to be displayed in a menu button.
+ * This function is invoked when someone changes the variable whose
+ * contents are to be displayed in a menu button.
*
* Results:
* NULL is always returned.
@@ -873,19 +862,20 @@ MenuButtonCmdDeletedProc(clientData)
/* ARGSUSED */
static char *
-MenuButtonTextVarProc(clientData, interp, name1, name2, flags)
- ClientData clientData; /* Information about button. */
- Tcl_Interp *interp; /* Interpreter containing variable. */
- CONST char *name1; /* Name of variable. */
- CONST char *name2; /* Second part of variable name. */
- int flags; /* Information about what happened. */
+MenuButtonTextVarProc(
+ ClientData clientData, /* Information about button. */
+ Tcl_Interp *interp, /* Interpreter containing variable. */
+ const char *name1, /* Name of variable. */
+ const char *name2, /* Second part of variable name. */
+ int flags) /* Information about what happened. */
{
register TkMenuButton *mbPtr = (TkMenuButton *) clientData;
- CONST char *value;
+ const char *value;
+ unsigned len;
/*
- * If the variable is unset, then immediately recreate it unless
- * the whole interpreter is going away.
+ * If the variable is unset, then immediately recreate it unless the whole
+ * interpreter is going away.
*/
if (flags & TCL_TRACE_UNSETS) {
@@ -896,7 +886,7 @@ MenuButtonTextVarProc(clientData, interp, name1, name2, flags)
TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
MenuButtonTextVarProc, clientData);
}
- return (char *) NULL;
+ return NULL;
}
value = Tcl_GetVar(interp, mbPtr->textVarName, TCL_GLOBAL_ONLY);
@@ -906,8 +896,9 @@ MenuButtonTextVarProc(clientData, interp, name1, name2, flags)
if (mbPtr->text != NULL) {
ckfree(mbPtr->text);
}
- mbPtr->text = (char *) ckalloc((unsigned) (strlen(value) + 1));
- strcpy(mbPtr->text, value);
+ len = 1 + (unsigned) strlen(value);
+ mbPtr->text = (char *) ckalloc(len);
+ memcpy(mbPtr->text, value, len);
TkpComputeMenuButtonGeometry(mbPtr);
if ((mbPtr->tkwin != NULL) && Tk_IsMapped(mbPtr->tkwin)
@@ -915,7 +906,7 @@ MenuButtonTextVarProc(clientData, interp, name1, name2, flags)
Tcl_DoWhenIdle(TkpDisplayMenuButton, (ClientData) mbPtr);
mbPtr->flags |= REDRAW_PENDING;
}
- return (char *) NULL;
+ return NULL;
}
/*
@@ -923,9 +914,9 @@ MenuButtonTextVarProc(clientData, interp, name1, name2, flags)
*
* 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.
+ * This function 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.
@@ -937,13 +928,13 @@ MenuButtonTextVarProc(clientData, interp, name1, name2, flags)
*/
static void
-MenuButtonImageProc(clientData, x, y, width, height, imgWidth, imgHeight)
- ClientData clientData; /* Pointer to widget record. */
- int x, y; /* Upper left pixel (within image)
- * that must be redisplayed. */
- int width, height; /* Dimensions of area to redisplay
- * (may be <= 0). */
- int imgWidth, imgHeight; /* New dimensions of image. */
+MenuButtonImageProc(
+ ClientData clientData, /* Pointer to widget record. */
+ int x, int y, /* Upper left pixel (within image) that must
+ * be redisplayed. */
+ int width, int height, /* Dimensions of area to redisplay (may be <=
+ * 0). */
+ int imgWidth, int imgHeight)/* New dimensions of image. */
{
register TkMenuButton *mbPtr = (TkMenuButton *) clientData;
@@ -955,3 +946,11 @@ MenuButtonImageProc(clientData, x, y, width, height, imgWidth, imgHeight)
}
}
}
+
+/*
+ * Local Variables:
+ * mode: c
+ * c-basic-offset: 4
+ * fill-column: 78
+ * End:
+ */