summaryrefslogtreecommitdiffstats
path: root/generic/tkMenubutton.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tkMenubutton.c')
-rw-r--r--generic/tkMenubutton.c96
1 files changed, 52 insertions, 44 deletions
diff --git a/generic/tkMenubutton.c b/generic/tkMenubutton.c
index 94ac8b2..31dbfbb 100644
--- a/generic/tkMenubutton.c
+++ b/generic/tkMenubutton.c
@@ -16,6 +16,18 @@
#include "default.h"
/*
+ * The structure below defines menubutton class behavior by means of
+ * procedures that can be invoked from generic window code.
+ */
+
+static const Tk_ClassProcs menubuttonClass = {
+ sizeof(Tk_ClassProcs), /* size */
+ TkMenuButtonWorldChanged, /* worldChangedProc */
+ NULL, /* createProc */
+ NULL /* modalProc */
+};
+
+/*
* The following table defines the legal values for the -direction option. It
* is used together with the "enum direction" declaration in tkMenubutton.h.
*/
@@ -54,13 +66,13 @@ static const Tk_OptionSpec optionSpecs[] = {
{TK_OPTION_COLOR, "-activeforeground", "activeForeground", "Background",
DEF_MENUBUTTON_ACTIVE_FG_COLOR, -1,
Tk_Offset(TkMenuButton, activeFg),
- 0, (ClientData) DEF_MENUBUTTON_ACTIVE_FG_MONO, 0},
+ 0, DEF_MENUBUTTON_ACTIVE_FG_MONO, 0},
{TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor",
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},
+ 0, 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,
@@ -76,7 +88,7 @@ static const Tk_OptionSpec optionSpecs[] = {
TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_STRING_TABLE, "-direction", "direction", "Direction",
DEF_MENUBUTTON_DIRECTION, -1, Tk_Offset(TkMenuButton, direction),
- 0, (ClientData) directionStrings, 0},
+ 0, directionStrings, 0},
{TK_OPTION_COLOR, "-disabledforeground", "disabledForeground",
"DisabledForeground", DEF_MENUBUTTON_DISABLED_FG_COLOR,
-1, Tk_Offset(TkMenuButton, disabledFg), TK_OPTION_NULL_OK,
@@ -121,10 +133,10 @@ static const Tk_OptionSpec optionSpecs[] = {
0, 0, 0},
{TK_OPTION_STRING_TABLE, "-compound", "compound", "Compound",
DEF_BUTTON_COMPOUND, -1, Tk_Offset(TkMenuButton, compound), 0,
- (ClientData) compoundStrings, 0},
+ compoundStrings, 0},
{TK_OPTION_STRING_TABLE, "-state", "state", "State",
DEF_MENUBUTTON_STATE, -1, Tk_Offset(TkMenuButton, state),
- 0, (ClientData) stateStrings, 0},
+ 0, stateStrings, 0},
{TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus",
DEF_MENUBUTTON_TAKE_FOCUS, -1,
Tk_Offset(TkMenuButton, takeFocus), TK_OPTION_NULL_OK, 0, 0},
@@ -142,7 +154,7 @@ static const Tk_OptionSpec optionSpecs[] = {
{TK_OPTION_PIXELS, "-wraplength", "wrapLength", "WrapLength",
DEF_MENUBUTTON_WRAP_LENGTH, -1, Tk_Offset(TkMenuButton, wrapLength),
0, 0, 0},
- {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0}
+ {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, 0}
};
/*
@@ -151,7 +163,7 @@ static const Tk_OptionSpec optionSpecs[] = {
* dispatch the scale widget command.
*/
-static const char *commandNames[] = {
+static const char *const commandNames[] = {
"cget", "configure", NULL
};
@@ -210,7 +222,7 @@ Tk_MenubuttonObjCmd(
Tk_Window tkwin;
if (objc < 2) {
- Tcl_WrongNumArgs(interp, 1, objv, "pathName ?options?");
+ Tcl_WrongNumArgs(interp, 1, objv, "pathName ?-option value ...?");
return TCL_ERROR;
}
@@ -234,18 +246,18 @@ Tk_MenubuttonObjCmd(
Tk_SetClass(tkwin, "Menubutton");
mbPtr = TkpCreateMenuButton(tkwin);
- Tk_SetClassProcs(tkwin, &tkpMenubuttonClass, (ClientData) mbPtr);
+ Tk_SetClassProcs(tkwin, &menubuttonClass, mbPtr);
/*
* Initialize the data structure for the button.
*/
mbPtr->tkwin = tkwin;
- mbPtr->display = Tk_Display (tkwin);
+ mbPtr->display = Tk_Display(tkwin);
mbPtr->interp = interp;
mbPtr->widgetCmd = Tcl_CreateObjCommand(interp,
- Tk_PathName(mbPtr->tkwin), MenuButtonWidgetObjCmd,
- (ClientData) mbPtr, MenuButtonCmdDeletedProc);
+ Tk_PathName(mbPtr->tkwin), MenuButtonWidgetObjCmd, mbPtr,
+ MenuButtonCmdDeletedProc);
mbPtr->optionTable = optionTable;
mbPtr->menuName = NULL;
mbPtr->text = NULL;
@@ -294,7 +306,7 @@ Tk_MenubuttonObjCmd(
Tk_CreateEventHandler(mbPtr->tkwin,
ExposureMask|StructureNotifyMask|FocusChangeMask,
- MenuButtonEventProc, (ClientData) mbPtr);
+ MenuButtonEventProc, mbPtr);
if (Tk_InitOptions(interp, (char *) mbPtr, optionTable, tkwin) != TCL_OK) {
Tk_DestroyWindow(mbPtr->tkwin);
@@ -306,7 +318,7 @@ Tk_MenubuttonObjCmd(
return TCL_ERROR;
}
- Tcl_SetStringObj(Tcl_GetObjResult(interp), Tk_PathName(mbPtr->tkwin), -1);
+ Tcl_SetObjResult(interp, TkNewWindowObj(mbPtr->tkwin));
return TCL_OK;
}
@@ -335,12 +347,12 @@ MenuButtonWidgetObjCmd(
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
- register TkMenuButton *mbPtr = (TkMenuButton *) clientData;
+ register TkMenuButton *mbPtr = 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 ...?");
return TCL_ERROR;
}
result = Tcl_GetIndexFromObj(interp, objv[1], commandNames, "option", 0,
@@ -348,7 +360,7 @@ MenuButtonWidgetObjCmd(
if (result != TCL_OK) {
return result;
}
- Tcl_Preserve((ClientData) mbPtr);
+ Tcl_Preserve(mbPtr);
switch (index) {
case COMMAND_CGET:
@@ -361,9 +373,8 @@ MenuButtonWidgetObjCmd(
mbPtr->optionTable, objv[2], mbPtr->tkwin);
if (objPtr == NULL) {
goto error;
- } else {
- Tcl_SetObjResult(interp, objPtr);
}
+ Tcl_SetObjResult(interp, objPtr);
break;
case COMMAND_CONFIGURE:
@@ -373,19 +384,18 @@ MenuButtonWidgetObjCmd(
mbPtr->tkwin);
if (objPtr == NULL) {
goto error;
- } else {
- Tcl_SetObjResult(interp, objPtr);
}
+ Tcl_SetObjResult(interp, objPtr);
} else {
result = ConfigureMenuButton(interp, mbPtr, objc-2, objv+2);
}
break;
}
- Tcl_Release((ClientData) mbPtr);
+ Tcl_Release(mbPtr);
return result;
error:
- Tcl_Release((ClientData) mbPtr);
+ Tcl_Release(mbPtr);
return TCL_ERROR;
}
@@ -416,7 +426,7 @@ DestroyMenuButton(
TkpDestroyMenuButton(mbPtr);
if (mbPtr->flags & REDRAW_PENDING) {
- Tcl_CancelIdleCall(TkpDisplayMenuButton, (ClientData) mbPtr);
+ Tcl_CancelIdleCall(TkpDisplayMenuButton, mbPtr);
}
/*
@@ -428,7 +438,7 @@ DestroyMenuButton(
if (mbPtr->textVarName != NULL) {
Tcl_UntraceVar(mbPtr->interp, mbPtr->textVarName,
TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
- MenuButtonTextVarProc, (ClientData) mbPtr);
+ MenuButtonTextVarProc, mbPtr);
}
if (mbPtr->image != NULL) {
Tk_FreeImage(mbPtr->image);
@@ -453,7 +463,7 @@ DestroyMenuButton(
}
Tk_FreeConfigOptions((char *) mbPtr, mbPtr->optionTable, mbPtr->tkwin);
mbPtr->tkwin = NULL;
- Tcl_EventuallyFree((ClientData) mbPtr, TCL_DYNAMIC);
+ Tcl_EventuallyFree(mbPtr, TCL_DYNAMIC);
}
/*
@@ -498,7 +508,7 @@ ConfigureMenuButton(
if (mbPtr->textVarName != NULL) {
Tcl_UntraceVar(interp, mbPtr->textVarName,
TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
- MenuButtonTextVarProc, (ClientData) mbPtr);
+ MenuButtonTextVarProc, mbPtr);
}
/*
@@ -561,8 +571,7 @@ ConfigureMenuButton(
if (mbPtr->imageString != NULL) {
image = Tk_GetImage(mbPtr->interp, mbPtr->tkwin,
- mbPtr->imageString, MenuButtonImageProc,
- (ClientData) mbPtr);
+ mbPtr->imageString, MenuButtonImageProc, mbPtr);
if (image == NULL) {
return TCL_ERROR;
}
@@ -624,15 +633,15 @@ ConfigureMenuButton(
if (mbPtr->text != NULL) {
ckfree(mbPtr->text);
}
- mbPtr->text = (char *) ckalloc((unsigned) (strlen(value) + 1));
+ mbPtr->text = ckalloc(strlen(value) + 1);
strcpy(mbPtr->text, value);
}
Tcl_TraceVar(interp, mbPtr->textVarName,
TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
- MenuButtonTextVarProc, (ClientData) mbPtr);
+ MenuButtonTextVarProc, mbPtr);
}
- TkMenuButtonWorldChanged((ClientData) mbPtr);
+ TkMenuButtonWorldChanged(mbPtr);
if (error) {
Tcl_SetObjResult(interp, errorResult);
Tcl_DecrRefCount(errorResult);
@@ -666,9 +675,7 @@ TkMenuButtonWorldChanged(
XGCValues gcValues;
GC gc;
unsigned long mask;
- TkMenuButton *mbPtr;
-
- mbPtr = (TkMenuButton *) instanceData;
+ TkMenuButton *mbPtr = instanceData;
gcValues.font = Tk_FontId(mbPtr->tkfont);
gcValues.foreground = mbPtr->normalFg->pixel;
@@ -741,7 +748,7 @@ TkMenuButtonWorldChanged(
*/
if (Tk_IsMapped(mbPtr->tkwin) && !(mbPtr->flags & REDRAW_PENDING)) {
- Tcl_DoWhenIdle(TkpDisplayMenuButton, (ClientData) mbPtr);
+ Tcl_DoWhenIdle(TkpDisplayMenuButton, mbPtr);
mbPtr->flags |= REDRAW_PENDING;
}
}
@@ -769,7 +776,8 @@ MenuButtonEventProc(
ClientData clientData, /* Information about window. */
XEvent *eventPtr) /* Information about event. */
{
- TkMenuButton *mbPtr = (TkMenuButton *) clientData;
+ TkMenuButton *mbPtr = clientData;
+
if ((eventPtr->type == Expose) && (eventPtr->xexpose.count == 0)) {
goto redraw;
} else if (eventPtr->type == ConfigureNotify) {
@@ -800,7 +808,7 @@ MenuButtonEventProc(
redraw:
if ((mbPtr->tkwin != NULL) && !(mbPtr->flags & REDRAW_PENDING)) {
- Tcl_DoWhenIdle(TkpDisplayMenuButton, (ClientData) mbPtr);
+ Tcl_DoWhenIdle(TkpDisplayMenuButton, mbPtr);
mbPtr->flags |= REDRAW_PENDING;
}
}
@@ -827,7 +835,7 @@ static void
MenuButtonCmdDeletedProc(
ClientData clientData) /* Pointer to widget record for widget. */
{
- TkMenuButton *mbPtr = (TkMenuButton *) clientData;
+ TkMenuButton *mbPtr = clientData;
Tk_Window tkwin = mbPtr->tkwin;
/*
@@ -869,7 +877,7 @@ MenuButtonTextVarProc(
const char *name2, /* Second part of variable name. */
int flags) /* Information about what happened. */
{
- register TkMenuButton *mbPtr = (TkMenuButton *) clientData;
+ register TkMenuButton *mbPtr = clientData;
const char *value;
unsigned len;
@@ -897,13 +905,13 @@ MenuButtonTextVarProc(
ckfree(mbPtr->text);
}
len = 1 + (unsigned) strlen(value);
- mbPtr->text = (char *) ckalloc(len);
+ mbPtr->text = ckalloc(len);
memcpy(mbPtr->text, value, len);
TkpComputeMenuButtonGeometry(mbPtr);
if ((mbPtr->tkwin != NULL) && Tk_IsMapped(mbPtr->tkwin)
&& !(mbPtr->flags & REDRAW_PENDING)) {
- Tcl_DoWhenIdle(TkpDisplayMenuButton, (ClientData) mbPtr);
+ Tcl_DoWhenIdle(TkpDisplayMenuButton, mbPtr);
mbPtr->flags |= REDRAW_PENDING;
}
return NULL;
@@ -936,12 +944,12 @@ MenuButtonImageProc(
* 0). */
int imgWidth, int imgHeight)/* New dimensions of image. */
{
- register TkMenuButton *mbPtr = (TkMenuButton *) clientData;
+ register TkMenuButton *mbPtr = clientData;
if (mbPtr->tkwin != NULL) {
TkpComputeMenuButtonGeometry(mbPtr);
if (Tk_IsMapped(mbPtr->tkwin) && !(mbPtr->flags & REDRAW_PENDING)) {
- Tcl_DoWhenIdle(TkpDisplayMenuButton, (ClientData) mbPtr);
+ Tcl_DoWhenIdle(TkpDisplayMenuButton, mbPtr);
mbPtr->flags |= REDRAW_PENDING;
}
}