diff options
Diffstat (limited to 'generic/tkFrame.c')
-rw-r--r-- | generic/tkFrame.c | 363 |
1 files changed, 191 insertions, 172 deletions
diff --git a/generic/tkFrame.c b/generic/tkFrame.c index e38fe87..057b4b8 100644 --- a/generic/tkFrame.c +++ b/generic/tkFrame.c @@ -162,7 +162,7 @@ enum labelanchor { LABELANCHOR_W, LABELANCHOR_WN, LABELANCHOR_WS }; -static CONST char *labelAnchorStrings[] = { +static const char *const labelAnchorStrings[] = { "e", "en", "es", "n", "ne", "nw", "s", "se", "sw", "w", "wn", "ws", NULL }; @@ -175,9 +175,9 @@ static CONST char *labelAnchorStrings[] = { static const Tk_OptionSpec commonOptSpec[] = { {TK_OPTION_BORDER, "-background", "background", "Background", DEF_FRAME_BG_COLOR, -1, Tk_Offset(Frame, border), - TK_OPTION_NULL_OK, (ClientData) DEF_FRAME_BG_MONO, 0}, + TK_OPTION_NULL_OK, DEF_FRAME_BG_MONO, 0}, {TK_OPTION_SYNONYM, "-bg", NULL, NULL, - NULL, 0, -1, 0, (ClientData) "-background", 0}, + NULL, 0, -1, 0, "-background", 0}, {TK_OPTION_STRING, "-colormap", "colormap", "Colormap", DEF_FRAME_COLORMAP, -1, Tk_Offset(Frame, colormapName), TK_OPTION_NULL_OK, 0, 0}, @@ -220,7 +220,7 @@ static const Tk_OptionSpec commonOptSpec[] = { static const Tk_OptionSpec frameOptSpec[] = { {TK_OPTION_SYNONYM, "-bd", NULL, NULL, - NULL, 0, -1, 0, (ClientData) "-borderwidth", 0}, + NULL, 0, -1, 0, "-borderwidth", 0}, {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth", DEF_FRAME_BORDER_WIDTH, -1, Tk_Offset(Frame, borderWidth), 0, 0, 0}, {TK_OPTION_STRING, "-class", "class", "Class", @@ -228,12 +228,12 @@ static const Tk_OptionSpec frameOptSpec[] = { {TK_OPTION_RELIEF, "-relief", "relief", "Relief", DEF_FRAME_RELIEF, -1, Tk_Offset(Frame, relief), 0, 0, 0}, {TK_OPTION_END, NULL, NULL, NULL, - NULL, 0, 0, 0, (ClientData) commonOptSpec, 0} + NULL, 0, 0, 0, commonOptSpec, 0} }; static const Tk_OptionSpec toplevelOptSpec[] = { {TK_OPTION_SYNONYM, "-bd", NULL, NULL, - NULL, 0, -1, 0, (ClientData) "-borderwidth", 0}, + NULL, 0, -1, 0, "-borderwidth", 0}, {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth", DEF_FRAME_BORDER_WIDTH, -1, Tk_Offset(Frame, borderWidth), 0, 0, 0}, {TK_OPTION_STRING, "-class", "class", "Class", @@ -250,26 +250,26 @@ static const Tk_OptionSpec toplevelOptSpec[] = { DEF_TOPLEVEL_USE, -1, Tk_Offset(Frame, useThis), TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_END, NULL, NULL, NULL, - NULL, 0, 0, 0, (ClientData) commonOptSpec, 0} + NULL, 0, 0, 0, commonOptSpec, 0} }; static const Tk_OptionSpec labelframeOptSpec[] = { {TK_OPTION_SYNONYM, "-bd", NULL, NULL, - NULL, 0, -1, 0, (ClientData) "-borderwidth", 0}, + NULL, 0, -1, 0, "-borderwidth", 0}, {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth", DEF_LABELFRAME_BORDER_WIDTH, -1, Tk_Offset(Frame, borderWidth), 0, 0, 0}, {TK_OPTION_STRING, "-class", "class", "Class", DEF_LABELFRAME_CLASS, -1, Tk_Offset(Frame, className), 0, 0, 0}, {TK_OPTION_SYNONYM, "-fg", "foreground", NULL, - NULL, 0, -1, 0, (ClientData) "-foreground", 0}, + NULL, 0, -1, 0, "-foreground", 0}, {TK_OPTION_FONT, "-font", "font", "Font", DEF_LABELFRAME_FONT, -1, Tk_Offset(Labelframe, tkfont), 0, 0, 0}, {TK_OPTION_COLOR, "-foreground", "foreground", "Foreground", DEF_LABELFRAME_FG, -1, Tk_Offset(Labelframe, textColorPtr), 0, 0, 0}, {TK_OPTION_STRING_TABLE, "-labelanchor", "labelAnchor", "LabelAnchor", DEF_LABELFRAME_LABELANCHOR, -1, Tk_Offset(Labelframe, labelAnchor), - 0, (ClientData) labelAnchorStrings, 0}, + 0, labelAnchorStrings, 0}, {TK_OPTION_WINDOW, "-labelwidget", "labelWidget", "LabelWidget", NULL, -1, Tk_Offset(Labelframe, labelWin), TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_RELIEF, "-relief", "relief", "Relief", @@ -278,24 +278,24 @@ static const Tk_OptionSpec labelframeOptSpec[] = { DEF_LABELFRAME_TEXT, Tk_Offset(Labelframe, textPtr), -1, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_END, NULL, NULL, NULL, - NULL, 0, 0, 0, (ClientData) commonOptSpec, 0} + NULL, 0, 0, 0, commonOptSpec, 0} }; /* * Class names for widgets, indexed by FrameType. */ -static CONST char *classNames[] = {"Frame", "Toplevel", "Labelframe"}; +static const char *const classNames[] = {"Frame", "Toplevel", "Labelframe"}; /* * The following table maps from FrameType to the option template for that * class of widgets. */ -static const Tk_OptionSpec * const optionSpecs[] = { +static const Tk_OptionSpec *const optionSpecs[] = { frameOptSpec, toplevelOptSpec, - labelframeOptSpec + labelframeOptSpec, }; /* @@ -304,11 +304,11 @@ static const Tk_OptionSpec * const optionSpecs[] = { static void ComputeFrameGeometry(Frame *framePtr); static int ConfigureFrame(Tcl_Interp *interp, Frame *framePtr, - int objc, Tcl_Obj *CONST objv[]); + int objc, Tcl_Obj *const objv[]); static int CreateFrame(ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST argv[], - enum FrameType type, char *appName); -static void DestroyFrame(char *memPtr); + int objc, Tcl_Obj *const argv[], + enum FrameType type, const char *appName); +static void DestroyFrame(void *memPtr); static void DestroyFramePartly(Frame *framePtr); static void DisplayFrame(ClientData clientData); static void FrameCmdDeletedProc(ClientData clientData); @@ -322,7 +322,7 @@ static void FrameStructureProc(ClientData clientData, XEvent *eventPtr); static int FrameWidgetObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, - Tcl_Obj *CONST objv[]); + Tcl_Obj *const objv[]); static void FrameWorldChanged(ClientData instanceData); static void MapFrame(ClientData clientData); @@ -331,9 +331,11 @@ static void MapFrame(ClientData clientData); * can be invoked from generic window code. */ -static Tk_ClassProcs frameClass = { +static const Tk_ClassProcs frameClass = { sizeof(Tk_ClassProcs), /* size */ - FrameWorldChanged /* worldChangedProc */ + FrameWorldChanged, /* worldChangedProc */ + NULL, /* createProc */ + NULL /* modalProc */ }; /* @@ -371,7 +373,7 @@ Tk_FrameObjCmd( ClientData clientData, /* Either NULL or pointer to option table. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ - Tcl_Obj *CONST objv[]) /* Argument objects. */ + Tcl_Obj *const objv[]) /* Argument objects. */ { return CreateFrame(clientData, interp, objc, objv, TYPE_FRAME, NULL); } @@ -381,7 +383,7 @@ Tk_ToplevelObjCmd( ClientData clientData, /* Either NULL or pointer to option table. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ - Tcl_Obj *CONST objv[]) /* Argument objects. */ + Tcl_Obj *const objv[]) /* Argument objects. */ { return CreateFrame(clientData, interp, objc, objv, TYPE_TOPLEVEL, NULL); } @@ -391,7 +393,7 @@ Tk_LabelframeObjCmd( ClientData clientData, /* Either NULL or pointer to option table. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ - Tcl_Obj *CONST objv[]) /* Argument objects. */ + Tcl_Obj *const objv[]) /* Argument objects. */ { return CreateFrame(clientData, interp, objc, objv, TYPE_LABELFRAME, NULL); } @@ -420,16 +422,16 @@ TkCreateFrame( ClientData clientData, /* Either NULL or pointer to option table. */ Tcl_Interp *interp, /* Current interpreter. */ int argc, /* Number of arguments. */ - char **argv, /* Argument strings. */ + const char *const *argv, /* Argument strings. */ int toplevel, /* Non-zero means create a toplevel window, * zero means create a frame. */ - char *appName) /* Should only be non-NULL if there is no main + const char *appName) /* Should only be non-NULL if there is no main * window associated with the interpreter. * Gives the base name to use for the new * application. */ { int result, i; - Tcl_Obj **objv = (Tcl_Obj **) ckalloc((argc+1) * sizeof(Tcl_Obj **)); + Tcl_Obj **objv = ckalloc((argc+1) * sizeof(Tcl_Obj **)); for (i=0; i<argc; i++) { objv[i] = Tcl_NewStringObj(argv[i], -1); @@ -441,7 +443,7 @@ TkCreateFrame( for (i=0; i<argc; i++) { Tcl_DecrRefCount(objv[i]); } - ckfree((char *) objv); + ckfree(objv); return result; } @@ -450,9 +452,9 @@ CreateFrame( ClientData clientData, /* NULL. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ - Tcl_Obj *CONST objv[], /* Argument objects. */ + Tcl_Obj *const objv[], /* Argument objects. */ enum FrameType type, /* What widget type to create. */ - char *appName) /* Should only be non-NULL if there are no + const char *appName) /* Should only be non-NULL if there are no * Main window associated with the * interpreter. Gives the base name to use for * the new application. */ @@ -461,14 +463,15 @@ CreateFrame( Frame *framePtr; Tk_OptionTable optionTable; Tk_Window newWin; - CONST char *className, *screenName, *visualName, *colormapName, *arg, *useOption; - int i, c, length, depth; + const char *className, *screenName, *visualName, *colormapName; + const char *arg, *useOption; + int i, length, depth; unsigned int mask; Colormap colormap; Visual *visual; if (objc < 2) { - Tcl_WrongNumArgs(interp, 1, objv, "pathName ?options?"); + Tcl_WrongNumArgs(interp, 1, objv, "pathName ?-option value ...?"); return TCL_ERROR; } @@ -493,20 +496,19 @@ CreateFrame( if (length < 2) { continue; } - c = arg[1]; - if ((c == 'c') && (length >= 3) + if ((arg[1] == 'c') && (length >= 3) && (strncmp(arg, "-class", (unsigned) length) == 0)) { className = Tcl_GetString(objv[i+1]); - } else if ((c == 'c') + } else if ((arg[1] == 'c') && (length >= 3) && (strncmp(arg, "-colormap", (unsigned) length) == 0)) { colormapName = Tcl_GetString(objv[i+1]); - } else if ((c == 's') && (type == TYPE_TOPLEVEL) + } else if ((arg[1] == 's') && (type == TYPE_TOPLEVEL) && (strncmp(arg, "-screen", (unsigned) length) == 0)) { screenName = Tcl_GetString(objv[i+1]); - } else if ((c == 'u') && (type == TYPE_TOPLEVEL) + } else if ((arg[1] == 'u') && (type == TYPE_TOPLEVEL) && (strncmp(arg, "-use", (unsigned) length) == 0)) { useOption = Tcl_GetString(objv[i+1]); - } else if ((c == 'v') + } else if ((arg[1] == 'v') && (strncmp(arg, "-visual", (unsigned) length) == 0)) { visualName = Tcl_GetString(objv[i+1]); } @@ -545,9 +547,10 @@ CreateFrame( * are being destroyed. Let an error be thrown. */ - Tcl_AppendResult(interp, "unable to create widget \"", - Tcl_GetString(objv[1]), "\"", NULL); - newWin = NULL; + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "unable to create widget \"%s\"", Tcl_GetString(objv[1]))); + Tcl_SetErrorCode(interp, "TK", "APPLICATION_GONE", NULL); + return TCL_ERROR; } else { /* * We were called from Tk_Init; create a new application. @@ -557,13 +560,14 @@ CreateFrame( } if (newWin == NULL) { goto error; - } else { - /* - * Mark Tk frames as suitable candidates for [wm manage] - */ - TkWindow *winPtr = (TkWindow *)newWin; - winPtr->flags |= TK_WM_MANAGEABLE; } + + /* + * Mark Tk frames as suitable candidates for [wm manage]. + */ + + ((TkWindow *) newWin)->flags |= TK_WM_MANAGEABLE; + if (className == NULL) { className = Tk_GetOption(newWin, "class", "Class"); if (className == NULL) { @@ -574,10 +578,9 @@ CreateFrame( if (useOption == NULL) { useOption = Tk_GetOption(newWin, "use", "Use"); } - if ((useOption != NULL) && (*useOption != 0)) { - if (TkpUseWindow(interp, newWin, useOption) != TCL_OK) { - goto error; - } + if ((useOption != NULL) && (*useOption != 0) + && (TkpUseWindow(interp, newWin, useOption) != TCL_OK)) { + goto error; } if (visualName == NULL) { visualName = Tk_GetOption(newWin, "visual", "Visual"); @@ -621,18 +624,17 @@ CreateFrame( */ if (type == TYPE_LABELFRAME) { - framePtr = (Frame *) ckalloc(sizeof(Labelframe)); - memset((void *) framePtr, 0, (sizeof(Labelframe))); + framePtr = ckalloc(sizeof(Labelframe)); + memset(framePtr, 0, sizeof(Labelframe)); } else { - framePtr = (Frame *) ckalloc(sizeof(Frame)); - memset((void *) framePtr, 0, (sizeof(Frame))); - } - framePtr->tkwin = newWin; - framePtr->display = Tk_Display(newWin); - framePtr->interp = interp; - framePtr->widgetCmd = Tcl_CreateObjCommand(interp, - Tk_PathName(newWin), FrameWidgetObjCmd, - (ClientData) framePtr, FrameCmdDeletedProc); + framePtr = ckalloc(sizeof(Frame)); + memset(framePtr, 0, sizeof(Frame)); + } + framePtr->tkwin = newWin; + framePtr->display = Tk_Display(newWin); + framePtr->interp = interp; + framePtr->widgetCmd = Tcl_CreateObjCommand(interp, Tk_PathName(newWin), + FrameWidgetObjCmd, framePtr, FrameCmdDeletedProc); framePtr->optionTable = optionTable; framePtr->type = type; framePtr->colormap = colormap; @@ -641,6 +643,7 @@ CreateFrame( if (framePtr->type == TYPE_LABELFRAME) { Labelframe *labelframePtr = (Labelframe *) framePtr; + labelframePtr->labelAnchor = LABELANCHOR_NW; labelframePtr->textGC = None; } @@ -649,31 +652,32 @@ CreateFrame( * Store backreference to frame widget in window structure. */ - Tk_SetClassProcs(newWin, &frameClass, (ClientData) framePtr); + Tk_SetClassProcs(newWin, &frameClass, framePtr); mask = ExposureMask | StructureNotifyMask | FocusChangeMask; if (type == TYPE_TOPLEVEL) { mask |= ActivateMask; } - Tk_CreateEventHandler(newWin, mask, FrameEventProc, (ClientData) framePtr); + Tk_CreateEventHandler(newWin, mask, FrameEventProc, framePtr); if ((Tk_InitOptions(interp, (char *) framePtr, optionTable, newWin) != TCL_OK) || (ConfigureFrame(interp, framePtr, objc-2, objv+2) != TCL_OK)) { goto error; } - if ((framePtr->isContainer)) { - if (framePtr->useThis == NULL) { - TkpMakeContainer(framePtr->tkwin); - } else { - Tcl_AppendResult(interp, "A window cannot have both the -use ", - "and the -container option set.", NULL); + if (framePtr->isContainer) { + if (framePtr->useThis != NULL) { + Tcl_SetObjResult(interp, Tcl_NewStringObj( + "windows cannot have both the -use and the -container" + " option set", -1)); + Tcl_SetErrorCode(interp, "TK", "FRAME", "CONTAINMENT", NULL); goto error; } + TkpMakeContainer(framePtr->tkwin); } if (type == TYPE_TOPLEVEL) { - Tcl_DoWhenIdle(MapFrame, (ClientData) framePtr); + Tcl_DoWhenIdle(MapFrame, framePtr); } - Tcl_SetResult(interp, Tk_PathName(newWin), TCL_STATIC); + Tcl_SetObjResult(interp, TkNewWindowObj(newWin)); return TCL_OK; error: @@ -706,28 +710,28 @@ FrameWidgetObjCmd( ClientData clientData, /* Information about frame widget. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ - Tcl_Obj *CONST objv[]) /* Argument objects. */ + Tcl_Obj *const objv[]) /* Argument objects. */ { - static CONST char *frameOptions[] = { + static const char *const frameOptions[] = { "cget", "configure", NULL }; enum options { FRAME_CGET, FRAME_CONFIGURE }; - register Frame *framePtr = (Frame *) clientData; + register Frame *framePtr = clientData; int result = TCL_OK, index; int c, i, length; Tcl_Obj *objPtr; if (objc < 2) { - Tcl_WrongNumArgs(interp, 1, objv, "option ?arg arg ...?"); + Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?"); return TCL_ERROR; } - if (Tcl_GetIndexFromObj(interp, objv[1], frameOptions, "option", 0, - &index) != TCL_OK) { + if (Tcl_GetIndexFromObjStruct(interp, objv[1], frameOptions, + sizeof(char *), "option", 0, &index) != TCL_OK) { return TCL_ERROR; } - Tcl_Preserve((ClientData) framePtr); + Tcl_Preserve(framePtr); switch ((enum options) index) { case FRAME_CGET: if (objc != 3) { @@ -740,22 +744,19 @@ FrameWidgetObjCmd( if (objPtr == NULL) { result = TCL_ERROR; goto done; - } else { - Tcl_SetObjResult(interp, objPtr); } + Tcl_SetObjResult(interp, objPtr); break; case FRAME_CONFIGURE: if (objc <= 3) { objPtr = Tk_GetOptionInfo(interp, (char *) framePtr, - framePtr->optionTable, - (objc == 3) ? objv[2] : NULL, + framePtr->optionTable, (objc == 3) ? objv[2] : NULL, framePtr->tkwin); if (objPtr == NULL) { result = TCL_ERROR; goto done; - } else { - Tcl_SetObjResult(interp, objPtr); } + Tcl_SetObjResult(interp, objPtr); } else { /* * Don't allow the options -class, -colormap, -container, -screen, @@ -763,7 +764,8 @@ FrameWidgetObjCmd( */ for (i = 2; i < objc; i++) { - char *arg = Tcl_GetStringFromObj(objv[i], &length); + const char *arg = Tcl_GetStringFromObj(objv[i], &length); + if (length < 2) { continue; } @@ -781,26 +783,25 @@ FrameWidgetObjCmd( || ((c == 'v') && (strncmp(arg, "-visual", (unsigned)length) == 0))) { - #ifdef SUPPORT_CONFIG_EMBEDDED +#ifdef SUPPORT_CONFIG_EMBEDDED if (c == 'u') { - CONST char *string = Tcl_GetString(objv[i+1]); + const char *string = Tcl_GetString(objv[i+1]); + if (TkpUseWindow(interp, framePtr->tkwin, string) != TCL_OK) { result = TCL_ERROR; goto done; } - } else { - Tcl_AppendResult(interp, "can't modify ", arg, - " option after widget is created", NULL); - result = TCL_ERROR; - goto done; + continue; } - #else - Tcl_AppendResult(interp, "can't modify ", arg, - " option after widget is created", NULL); - result = TCL_ERROR; - goto done; - #endif +#endif + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "can't modify %s option after widget is created", + arg)); + Tcl_SetErrorCode(interp, "TK", "FRAME", "CREATE_ONLY", + NULL); + result = TCL_ERROR; + goto done; } } result = ConfigureFrame(interp, framePtr, objc-2, objv+2); @@ -809,7 +810,7 @@ FrameWidgetObjCmd( } done: - Tcl_Release((ClientData) framePtr); + Tcl_Release(framePtr); return result; } @@ -833,10 +834,10 @@ FrameWidgetObjCmd( static void DestroyFrame( - char *memPtr) /* Info about frame widget. */ + void *memPtr) /* Info about frame widget. */ { - register Frame *framePtr = (Frame *) memPtr; - register Labelframe *labelframePtr = (Labelframe *) memPtr; + register Frame *framePtr = memPtr; + register Labelframe *labelframePtr = memPtr; if (framePtr->type == TYPE_LABELFRAME) { Tk_FreeTextLayout(labelframePtr->textLayout); @@ -847,7 +848,7 @@ DestroyFrame( if (framePtr->colormap != None) { Tk_FreeColormap(framePtr->display, framePtr->colormap); } - ckfree((char *) framePtr); + ckfree(framePtr); } /* @@ -876,8 +877,8 @@ DestroyFramePartly( if (framePtr->type == TYPE_LABELFRAME && labelframePtr->labelWin != NULL) { Tk_DeleteEventHandler(labelframePtr->labelWin, StructureNotifyMask, - FrameStructureProc, (ClientData) framePtr); - Tk_ManageGeometry(labelframePtr->labelWin, NULL, (ClientData) NULL); + FrameStructureProc, framePtr); + Tk_ManageGeometry(labelframePtr->labelWin, NULL, NULL); if (framePtr->tkwin != Tk_Parent(labelframePtr->labelWin)) { Tk_UnmaintainGeometry(labelframePtr->labelWin, framePtr->tkwin); } @@ -915,7 +916,7 @@ ConfigureFrame( register Frame *framePtr, /* 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. */ + Tcl_Obj *const objv[]) /* Arguments. */ { Tk_SavedOptions savedOptions; char *oldMenuName; @@ -943,9 +944,8 @@ ConfigureFrame( ckfree(oldMenuName); } return TCL_ERROR; - } else { - Tk_FreeSavedOptions(&savedOptions); } + Tk_FreeSavedOptions(&savedOptions); /* * A few of the options require additional processing. @@ -955,7 +955,7 @@ ConfigureFrame( || ((oldMenuName != NULL) && (framePtr->menuName == NULL)) || ((oldMenuName != NULL) && (framePtr->menuName != NULL) && strcmp(oldMenuName, framePtr->menuName) != 0)) - && framePtr->type == TYPE_TOPLEVEL) { + && framePtr->type == TYPE_TOPLEVEL) { TkSetWindowMenuBar(interp, framePtr->tkwin, oldMenuName, framePtr->menuName); } @@ -989,8 +989,8 @@ ConfigureFrame( if (oldWindow != labelframePtr->labelWin) { if (oldWindow != NULL) { Tk_DeleteEventHandler(oldWindow, StructureNotifyMask, - FrameStructureProc, (ClientData) framePtr); - Tk_ManageGeometry(oldWindow, NULL, (ClientData) NULL); + FrameStructureProc, framePtr); + Tk_ManageGeometry(oldWindow, NULL, NULL); Tk_UnmaintainGeometry(oldWindow, framePtr->tkwin); Tk_UnmapWindow(oldWindow); } @@ -1011,25 +1011,19 @@ ConfigureFrame( } sibling = ancestor; if (Tk_IsTopLevel(ancestor)) { - badWindow: - Tcl_AppendResult(interp, "can't use ", - Tk_PathName(labelframePtr->labelWin), - " as label in this frame", NULL); - labelframePtr->labelWin = NULL; - return TCL_ERROR; + goto badLabelWindow; } } if (Tk_IsTopLevel(labelframePtr->labelWin)) { - goto badWindow; + goto badLabelWindow; } if (labelframePtr->labelWin == framePtr->tkwin) { - goto badWindow; + goto badLabelWindow; } Tk_CreateEventHandler(labelframePtr->labelWin, - StructureNotifyMask, FrameStructureProc, - (ClientData) framePtr); + StructureNotifyMask, FrameStructureProc, framePtr); Tk_ManageGeometry(labelframePtr->labelWin, &frameGeomType, - (ClientData) framePtr); + framePtr); /* * If the frame is not parent to the label, make sure the @@ -1043,9 +1037,16 @@ ConfigureFrame( } } - FrameWorldChanged((ClientData) framePtr); - + FrameWorldChanged(framePtr); return TCL_OK; + + badLabelWindow: + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "can't use %s as label in this frame", + Tk_PathName(labelframePtr->labelWin))); + Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "HIERARCHY", NULL); + labelframePtr->labelWin = NULL; + return TCL_ERROR; } /* @@ -1070,14 +1071,14 @@ static void FrameWorldChanged( ClientData instanceData) /* Information about widget. */ { - Frame *framePtr = (Frame *) instanceData; - Labelframe *labelframePtr = (Labelframe *) framePtr; + Frame *framePtr = instanceData; + Labelframe *labelframePtr = instanceData; Tk_Window tkwin = framePtr->tkwin; XGCValues gcValues; GC gc; int anyTextLabel, anyWindowLabel; int bWidthLeft, bWidthRight, bWidthTop, bWidthBottom; - char *labelText; + const char *labelText; anyTextLabel = (framePtr->type == TYPE_LABELFRAME) && (labelframePtr->textPtr != NULL) && @@ -1110,14 +1111,17 @@ FrameWorldChanged( if (anyTextLabel) { labelText = Tcl_GetString(labelframePtr->textPtr); Tk_FreeTextLayout(labelframePtr->textLayout); - labelframePtr->textLayout = Tk_ComputeTextLayout(labelframePtr->tkfont, + labelframePtr->textLayout = + Tk_ComputeTextLayout(labelframePtr->tkfont, labelText, -1, 0, TK_JUSTIFY_CENTER, 0, - &labelframePtr->labelReqWidth, &labelframePtr->labelReqHeight); + &labelframePtr->labelReqWidth, + &labelframePtr->labelReqHeight); labelframePtr->labelReqWidth += 2 * LABELSPACING; labelframePtr->labelReqHeight += 2 * LABELSPACING; } else if (anyWindowLabel) { labelframePtr->labelReqWidth = Tk_ReqWidth(labelframePtr->labelWin); - labelframePtr->labelReqHeight = Tk_ReqHeight(labelframePtr->labelWin); + labelframePtr->labelReqHeight = + Tk_ReqHeight(labelframePtr->labelWin); } /* @@ -1210,7 +1214,7 @@ FrameWorldChanged( if (Tk_IsMapped(tkwin)) { if (!(framePtr->flags & REDRAW_PENDING)) { - Tcl_DoWhenIdle(DisplayFrame, (ClientData) framePtr); + Tcl_DoWhenIdle(DisplayFrame, framePtr); } framePtr->flags |= REDRAW_PENDING; } @@ -1247,7 +1251,9 @@ ComputeFrameGeometry( * We have nothing to do here unless there is a label. */ - if (framePtr->type != TYPE_LABELFRAME) return; + if (framePtr->type != TYPE_LABELFRAME) { + return; + } if (labelframePtr->textPtr == NULL && labelframePtr->labelWin == NULL) { return; } @@ -1273,10 +1279,14 @@ ComputeFrameGeometry( if ((labelframePtr->labelAnchor >= LABELANCHOR_N) && (labelframePtr->labelAnchor <= LABELANCHOR_SW)) { maxWidth -= padding; - if (maxWidth < 1) maxWidth = 1; + if (maxWidth < 1) { + maxWidth = 1; + } } else { maxHeight -= padding; - if (maxHeight < 1) maxHeight = 1; + if (maxHeight < 1) { + maxHeight = 1; + } } if (labelframePtr->labelBox.width > maxWidth) { labelframePtr->labelBox.width = maxWidth; @@ -1379,7 +1389,7 @@ static void DisplayFrame( ClientData clientData) /* Information about widget. */ { - register Frame *framePtr = (Frame *) clientData; + register Frame *framePtr = clientData; register Tk_Window tkwin = framePtr->tkwin; int bdX1, bdY1, bdX2, bdY2, hlWidth; Pixmap pixmap; @@ -1416,7 +1426,9 @@ DisplayFrame( * If -background is set to "", no interior is drawn. */ - if (framePtr->border == NULL) return; + if (framePtr->border == NULL) { + return; + } if (framePtr->type != TYPE_LABELFRAME) { /* @@ -1547,7 +1559,8 @@ DisplayFrame( || (labelframePtr->labelBox.height != Tk_Height(labelframePtr->labelWin))) { Tk_MoveResizeWindow(labelframePtr->labelWin, - labelframePtr->labelBox.x, labelframePtr->labelBox.y, + labelframePtr->labelBox.x, + labelframePtr->labelBox.y, labelframePtr->labelBox.width, labelframePtr->labelBox.height); } @@ -1560,7 +1573,6 @@ DisplayFrame( } } - #ifndef TK_NO_DOUBLE_BUFFERING /* * Everything's been redisplayed; now copy the pixmap onto the screen @@ -1602,7 +1614,7 @@ FrameEventProc( ClientData clientData, /* Information about window. */ register XEvent *eventPtr) /* Information about event. */ { - register Frame *framePtr = (Frame *) clientData; + register Frame *framePtr = clientData; if ((eventPtr->type == Expose) && (eventPtr->xexpose.count == 0)) { goto redraw; @@ -1636,15 +1648,15 @@ FrameEventProc( Tk_DeleteEventHandler(framePtr->tkwin, ExposureMask|StructureNotifyMask|FocusChangeMask, - FrameEventProc, (ClientData) framePtr); + FrameEventProc, framePtr); framePtr->tkwin = NULL; Tcl_DeleteCommandFromToken(framePtr->interp, framePtr->widgetCmd); } if (framePtr->flags & REDRAW_PENDING) { - Tcl_CancelIdleCall(DisplayFrame, (ClientData) framePtr); + Tcl_CancelIdleCall(DisplayFrame, framePtr); } - Tcl_CancelIdleCall(MapFrame, (ClientData) framePtr); - Tcl_EventuallyFree((ClientData) framePtr, DestroyFrame); + Tcl_CancelIdleCall(MapFrame, framePtr); + Tcl_EventuallyFree(framePtr, (Tcl_FreeProc *) DestroyFrame); } else if (eventPtr->type == FocusIn) { if (eventPtr->xfocus.detail != NotifyInferior) { framePtr->flags |= GOT_FOCUS; @@ -1667,7 +1679,7 @@ FrameEventProc( redraw: if ((framePtr->tkwin != NULL) && !(framePtr->flags & REDRAW_PENDING)) { - Tcl_DoWhenIdle(DisplayFrame, (ClientData) framePtr); + Tcl_DoWhenIdle(DisplayFrame, framePtr); framePtr->flags |= REDRAW_PENDING; } } @@ -1694,7 +1706,7 @@ static void FrameCmdDeletedProc( ClientData clientData) /* Pointer to widget record for widget. */ { - Frame *framePtr = (Frame *) clientData; + Frame *framePtr = clientData; Tk_Window tkwin = framePtr->tkwin; if (framePtr->menuName != NULL) { @@ -1745,7 +1757,7 @@ static void MapFrame( ClientData clientData) /* Pointer to frame structure. */ { - Frame *framePtr = (Frame *) clientData; + Frame *framePtr = clientData; /* * Wait for all other background events to be processed before mapping @@ -1754,7 +1766,7 @@ MapFrame( * doesn't get a false idea of its desired geometry. */ - Tcl_Preserve((ClientData) framePtr); + Tcl_Preserve(framePtr); while (1) { if (Tcl_DoOneEvent(TCL_IDLE_EVENTS) == 0) { break; @@ -1766,12 +1778,12 @@ MapFrame( */ if (framePtr->tkwin == NULL) { - Tcl_Release((ClientData) framePtr); + Tcl_Release(framePtr); return; } } Tk_MapWindow(framePtr->tkwin); - Tcl_Release((ClientData) framePtr); + Tcl_Release(framePtr); } /* @@ -1800,8 +1812,8 @@ TkInstallFrameMenu( TkWindow *winPtr = (TkWindow *) tkwin; if (winPtr->mainPtr != NULL) { - Frame *framePtr; - framePtr = (Frame*) winPtr->instanceData; + Frame *framePtr = winPtr->instanceData; + if (framePtr == NULL) { Tcl_Panic("TkInstallFrameMenu couldn't get frame pointer"); } @@ -1833,7 +1845,7 @@ FrameStructureProc( ClientData clientData, /* Pointer to record describing frame. */ XEvent *eventPtr) /* Describes what just happened. */ { - Labelframe *labelframePtr = (Labelframe *) clientData; + Labelframe *labelframePtr = clientData; if (eventPtr->type == DestroyNotify) { /* @@ -1843,7 +1855,7 @@ FrameStructureProc( if (labelframePtr->frame.type == TYPE_LABELFRAME) { labelframePtr->labelWin = NULL; - FrameWorldChanged((ClientData) labelframePtr); + FrameWorldChanged(labelframePtr); } } } @@ -1871,9 +1883,9 @@ FrameRequestProc( ClientData clientData, /* Pointer to record for frame. */ Tk_Window tkwin) /* Window that changed its desired size. */ { - Frame *framePtr = (Frame *) clientData; + Frame *framePtr = clientData; - FrameWorldChanged((ClientData) framePtr); + FrameWorldChanged(framePtr); } /* @@ -1899,8 +1911,8 @@ FrameLostSlaveProc( * stolen away. */ Tk_Window tkwin) /* Tk's handle for the slave window. */ { - Frame *framePtr = (Frame *) clientData; - Labelframe *labelframePtr = (Labelframe *) clientData; + Frame *framePtr = clientData; + Labelframe *labelframePtr = clientData; /* * This should only happen in a labelframe but it doesn't hurt to be @@ -1909,40 +1921,47 @@ FrameLostSlaveProc( if (labelframePtr->frame.type == TYPE_LABELFRAME) { Tk_DeleteEventHandler(labelframePtr->labelWin, StructureNotifyMask, - FrameStructureProc, (ClientData) labelframePtr); + FrameStructureProc, labelframePtr); if (framePtr->tkwin != Tk_Parent(labelframePtr->labelWin)) { Tk_UnmaintainGeometry(labelframePtr->labelWin, framePtr->tkwin); } Tk_UnmapWindow(labelframePtr->labelWin); labelframePtr->labelWin = NULL; } - FrameWorldChanged((ClientData) framePtr); + FrameWorldChanged(framePtr); } void -TkMapTopFrame (tkwin) - Tk_Window tkwin; +TkMapTopFrame( + Tk_Window tkwin) { - Frame *framePtr = ((TkWindow*)tkwin)->instanceData; + Frame *framePtr = ((TkWindow *) tkwin)->instanceData; Tk_OptionTable optionTable; + if (Tk_IsTopLevel(tkwin) && framePtr->type == TYPE_FRAME) { framePtr->type = TYPE_TOPLEVEL; - Tcl_DoWhenIdle(MapFrame, (ClientData)framePtr); + Tcl_DoWhenIdle(MapFrame, framePtr); if (framePtr->menuName != NULL) { TkSetWindowMenuBar(framePtr->interp, framePtr->tkwin, NULL, - framePtr->menuName); + framePtr->menuName); } } else if (!Tk_IsTopLevel(tkwin) && framePtr->type == TYPE_TOPLEVEL) { framePtr->type = TYPE_FRAME; } else { - /* Not a frame or toplevel, skip it */ + /* + * Not a frame or toplevel, skip it. + */ + return; } + /* - * The option table has already been created so - * the cached pointer will be returned. + * The option table has already been created so the cached pointer will be + * returned. */ - optionTable = Tk_CreateOptionTable(framePtr->interp, optionSpecs[framePtr->type]); + + optionTable = Tk_CreateOptionTable(framePtr->interp, + optionSpecs[framePtr->type]); framePtr->optionTable = optionTable; } @@ -1969,7 +1988,7 @@ TkMapTopFrame (tkwin) Tk_Window TkToplevelWindowForCommand( Tcl_Interp *interp, - CONST char *cmdName) + const char *cmdName) { Tcl_CmdInfo cmdInfo; Frame *framePtr; @@ -1980,7 +1999,7 @@ TkToplevelWindowForCommand( if (cmdInfo.objProc != FrameWidgetObjCmd) { return NULL; } - framePtr = (Frame *) cmdInfo.objClientData; + framePtr = cmdInfo.objClientData; if (framePtr->type != TYPE_TOPLEVEL) { return NULL; } |