From 57e2e1198fabe68b9d53871aa35907d3254859ed Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 12 Sep 2024 22:49:20 +0000 Subject: Make a start at [f91aa24bbe] for "menubutton". WIP --- generic/tkCanvas.c | 9 +++ generic/tkMenubutton.c | 146 ++++++++++++++++++++++++++------------------ generic/tkMenubutton.h | 33 ++++------ macosx/tkMacOSXMenubutton.c | 81 +++++++++++++++--------- tests/menubut.test | 2 +- 5 files changed, 160 insertions(+), 111 deletions(-) diff --git a/generic/tkCanvas.c b/generic/tkCanvas.c index 947e9d7..81300f2 100644 --- a/generic/tkCanvas.c +++ b/generic/tkCanvas.c @@ -2347,6 +2347,15 @@ ConfigureCanvas( if (canvasPtr->highlightWidth < 0) { canvasPtr->highlightWidth = 0; } + if (canvasPtr->textInfo.insertBorderWidth < 0) { + canvasPtr->textInfo.insertBorderWidth = 0; + } + if (canvasPtr->textInfo.insertWidth < 0) { + canvasPtr->textInfo.insertWidth = 0; + } + if (canvasPtr->textInfo.selBorderWidth < 0) { + canvasPtr->textInfo.selBorderWidth = 0; + } if (canvasPtr->width < 0) { canvasPtr->width = 0; } diff --git a/generic/tkMenubutton.c b/generic/tkMenubutton.c index b9056e9..146b1c2 100644 --- a/generic/tkMenubutton.c +++ b/generic/tkMenubutton.c @@ -62,8 +62,8 @@ static const Tk_OptionSpec optionSpecs[] = { DEF_MENUBUTTON_BITMAP, TCL_INDEX_NONE, offsetof(TkMenuButton, bitmap), TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth", - DEF_MENUBUTTON_BORDER_WIDTH, TCL_INDEX_NONE, - offsetof(TkMenuButton, borderWidth), 0, 0, 0}, + DEF_MENUBUTTON_BORDER_WIDTH, offsetof(TkMenuButton, borderWidthObj), + TCL_INDEX_NONE, 0, 0, 0}, {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor", DEF_MENUBUTTON_CURSOR, TCL_INDEX_NONE, offsetof(TkMenuButton, cursor), TK_OPTION_NULL_OK, 0, 0}, @@ -81,8 +81,8 @@ static const Tk_OptionSpec optionSpecs[] = { {TK_OPTION_COLOR, "-foreground", "foreground", "Foreground", DEF_MENUBUTTON_FG, TCL_INDEX_NONE, offsetof(TkMenuButton, normalFg), 0, 0, 0}, {TK_OPTION_STRING, "-height", "height", "Height", - DEF_MENUBUTTON_HEIGHT, TCL_INDEX_NONE, offsetof(TkMenuButton, heightString), - 0, 0, 0}, + DEF_MENUBUTTON_HEIGHT, offsetof(TkMenuButton, heightObj), + TCL_INDEX_NONE, 0, 0, 0}, {TK_OPTION_COLOR, "-highlightbackground", "highlightBackground", "HighlightBackground", DEF_MENUBUTTON_HIGHLIGHT_BG_COLOR, TCL_INDEX_NONE, offsetof(TkMenuButton, highlightBgColorPtr), 0, 0, 0}, @@ -91,9 +91,9 @@ static const Tk_OptionSpec optionSpecs[] = { offsetof(TkMenuButton, highlightColorPtr), 0, 0, 0}, {TK_OPTION_PIXELS, "-highlightthickness", "highlightThickness", "HighlightThickness", DEF_MENUBUTTON_HIGHLIGHT_WIDTH, - TCL_INDEX_NONE, offsetof(TkMenuButton, highlightWidth), 0, 0, 0}, + offsetof(TkMenuButton, highlightWidthObj), TCL_INDEX_NONE, 0, 0, 0}, {TK_OPTION_STRING, "-image", "image", "Image", - DEF_MENUBUTTON_IMAGE, TCL_INDEX_NONE, offsetof(TkMenuButton, imageString), + DEF_MENUBUTTON_IMAGE, offsetof(TkMenuButton, imageObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_BOOLEAN, "-indicatoron", "indicatorOn", "IndicatorOn", DEF_MENUBUTTON_INDICATOR, TCL_INDEX_NONE, offsetof(TkMenuButton, indicatorOn), @@ -101,13 +101,13 @@ static const Tk_OptionSpec optionSpecs[] = { {TK_OPTION_JUSTIFY, "-justify", "justify", "Justify", DEF_MENUBUTTON_JUSTIFY, TCL_INDEX_NONE, offsetof(TkMenuButton, justify), TK_OPTION_ENUM_VAR, 0, 0}, {TK_OPTION_STRING, "-menu", "menu", "Menu", - DEF_MENUBUTTON_MENU, TCL_INDEX_NONE, offsetof(TkMenuButton, menuName), + DEF_MENUBUTTON_MENU, offsetof(TkMenuButton, menuNameObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_PIXELS, "-padx", "padX", "Pad", - DEF_MENUBUTTON_PADX, TCL_INDEX_NONE, offsetof(TkMenuButton, padX), + DEF_MENUBUTTON_PADX, offsetof(TkMenuButton, padXObj), TCL_INDEX_NONE, 0, 0, 0}, {TK_OPTION_PIXELS, "-pady", "padY", "Pad", - DEF_MENUBUTTON_PADY, TCL_INDEX_NONE, offsetof(TkMenuButton, padY), + DEF_MENUBUTTON_PADY, offsetof(TkMenuButton, padYObj), TCL_INDEX_NONE, 0, 0, 0}, {TK_OPTION_RELIEF, "-relief", "relief", "Relief", DEF_MENUBUTTON_RELIEF, TCL_INDEX_NONE, offsetof(TkMenuButton, relief), @@ -119,21 +119,21 @@ static const Tk_OptionSpec optionSpecs[] = { DEF_MENUBUTTON_STATE, TCL_INDEX_NONE, offsetof(TkMenuButton, state), TK_OPTION_ENUM_VAR, tkStateStrings, 0}, {TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus", - DEF_MENUBUTTON_TAKE_FOCUS, TCL_INDEX_NONE, - offsetof(TkMenuButton, takeFocus), TK_OPTION_NULL_OK, 0, 0}, + DEF_MENUBUTTON_TAKE_FOCUS, offsetof(TkMenuButton, takeFocusObj), + TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_STRING, "-text", "text", "Text", DEF_MENUBUTTON_TEXT, TCL_INDEX_NONE, offsetof(TkMenuButton, text), 0, 0, 0}, {TK_OPTION_STRING, "-textvariable", "textVariable", "Variable", - DEF_MENUBUTTON_TEXT_VARIABLE, TCL_INDEX_NONE, - offsetof(TkMenuButton, textVarName), TK_OPTION_NULL_OK, 0, 0}, + DEF_MENUBUTTON_TEXT_VARIABLE, offsetof(TkMenuButton, textVarNameObj), + TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_INDEX, "-underline", "underline", "Underline", TK_OPTION_UNDERLINE_DEF(TkMenuButton, underline), 0}, {TK_OPTION_STRING, "-width", "width", "Width", - DEF_MENUBUTTON_WIDTH, TCL_INDEX_NONE, offsetof(TkMenuButton, widthString), - 0, 0, 0}, + DEF_MENUBUTTON_WIDTH, offsetof(TkMenuButton, widthObj), + TCL_INDEX_NONE, 0, 0, 0}, {TK_OPTION_PIXELS, "-wraplength", "wrapLength", "WrapLength", - DEF_MENUBUTTON_WRAP_LENGTH, TCL_INDEX_NONE, offsetof(TkMenuButton, wrapLength), - 0, 0, 0}, + DEF_MENUBUTTON_WRAP_LENGTH, offsetof(TkMenuButton, wrapLengthObj), + TCL_INDEX_NONE, 0, 0, 0}, {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, 0} }; @@ -238,19 +238,19 @@ Tk_MenubuttonObjCmd( Tk_PathName(mbPtr->tkwin), MenuButtonWidgetObjCmd, mbPtr, MenuButtonCmdDeletedProc); mbPtr->optionTable = optionTable; - mbPtr->menuName = NULL; + mbPtr->menuNameObj = NULL; mbPtr->text = NULL; mbPtr->underline = INT_MIN; - mbPtr->textVarName = NULL; + mbPtr->textVarNameObj = NULL; mbPtr->bitmap = None; - mbPtr->imageString = NULL; + mbPtr->imageObj = NULL; mbPtr->image = NULL; mbPtr->state = STATE_NORMAL; mbPtr->normalBorder = NULL; mbPtr->activeBorder = NULL; - mbPtr->borderWidth = 0; + mbPtr->borderWidthObj = NULL; mbPtr->relief = TK_RELIEF_FLAT; - mbPtr->highlightWidth = 0; + mbPtr->highlightWidthObj = 0; mbPtr->highlightBgColorPtr = NULL; mbPtr->highlightColorPtr = NULL; mbPtr->inset = 0; @@ -265,13 +265,11 @@ Tk_MenubuttonObjCmd( mbPtr->stippleGC = NULL; mbPtr->leftBearing = 0; mbPtr->rightBearing = 0; - mbPtr->widthString = NULL; - mbPtr->heightString = NULL; - mbPtr->width = 0; - mbPtr->width = 0; - mbPtr->wrapLength = 0; - mbPtr->padX = 0; - mbPtr->padY = 0; + mbPtr->widthObj = NULL; + mbPtr->heightObj = NULL; + mbPtr->wrapLengthObj = 0; + mbPtr->padXObj = NULL; + mbPtr->padYObj = NULL; mbPtr->anchor = TK_ANCHOR_CENTER; mbPtr->justify = TK_JUSTIFY_CENTER; mbPtr->textLayout = NULL; @@ -280,7 +278,7 @@ Tk_MenubuttonObjCmd( mbPtr->indicatorHeight = 0; mbPtr->direction = DIRECTION_FLUSH; mbPtr->cursor = NULL; - mbPtr->takeFocus = NULL; + mbPtr->takeFocusObj = NULL; mbPtr->flags = 0; Tk_CreateEventHandler(mbPtr->tkwin, @@ -414,8 +412,8 @@ DestroyMenuButton( */ Tcl_DeleteCommandFromToken(mbPtr->interp, mbPtr->widgetCmd); - if (mbPtr->textVarName != NULL) { - Tcl_UntraceVar2(mbPtr->interp, mbPtr->textVarName, NULL, + if (mbPtr->textVarNameObj != NULL) { + Tcl_UntraceVar2(mbPtr->interp, Tcl_GetString(mbPtr->textVarNameObj), NULL, TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, MenuButtonTextVarProc, mbPtr); } @@ -479,13 +477,16 @@ ConfigureMenuButton( Tcl_Obj *errorResult = NULL; int error; Tk_Image image; + int borderWidth, highlightWidth; + int padX, padY; + int width, height; /* * Eliminate any existing trace on variables monitored by the menubutton. */ - if (mbPtr->textVarName != NULL) { - Tcl_UntraceVar2(interp, mbPtr->textVarName, NULL, + if (mbPtr->textVarNameObj != NULL) { + Tcl_UntraceVar2(interp, Tcl_GetString(mbPtr->textVarNameObj), NULL, TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, MenuButtonTextVarProc, mbPtr); } @@ -531,15 +532,37 @@ ConfigureMenuButton( Tk_SetBackgroundFromBorder(mbPtr->tkwin, mbPtr->normalBorder); } - if (mbPtr->highlightWidth < 0) { - mbPtr->highlightWidth = 0; + Tk_GetPixelsFromObj(NULL, mbPtr->tkwin, mbPtr->borderWidthObj, &borderWidth); + Tk_GetPixelsFromObj(NULL, mbPtr->tkwin, mbPtr->highlightWidthObj, &highlightWidth); + Tk_GetPixelsFromObj(NULL, mbPtr->tkwin, mbPtr->padXObj, &padX); + Tk_GetPixelsFromObj(NULL, mbPtr->tkwin, mbPtr->padYObj, &padY); + if (borderWidth < 0) { + borderWidth = 0; + Tcl_DecrRefCount(mbPtr->borderWidthObj); + mbPtr->borderWidthObj = Tcl_NewIntObj(0); + Tcl_IncrRefCount(mbPtr->borderWidthObj); } - - if (mbPtr->padX < 0) { - mbPtr->padX = 0; + if (highlightWidth < 0) { + highlightWidth = 0; + Tcl_DecrRefCount(mbPtr->highlightWidthObj); + mbPtr->highlightWidthObj = Tcl_NewIntObj(0); + Tcl_IncrRefCount(mbPtr->highlightWidthObj); } - if (mbPtr->padY < 0) { - mbPtr->padY = 0; + if (padX < 0) { + padX = 0; + if (mbPtr->padXObj) { + Tcl_DecrRefCount(mbPtr->padXObj); + } + mbPtr->padXObj = Tcl_NewIntObj(0); + Tcl_IncrRefCount(mbPtr->padXObj); + } + if (padY < 0) { + padY = 0; + if (mbPtr->padYObj) { + Tcl_DecrRefCount(mbPtr->padYObj); + } + mbPtr->padYObj = Tcl_NewIntObj(0); + Tcl_IncrRefCount(mbPtr->padYObj); } /* @@ -548,9 +571,9 @@ ConfigureMenuButton( * doesn't go to zero and cause image data to be discarded. */ - if (mbPtr->imageString != NULL) { + if (mbPtr->imageObj != NULL) { image = Tk_GetImage(mbPtr->interp, mbPtr->tkwin, - mbPtr->imageString, MenuButtonImageProc, mbPtr); + Tcl_GetString(mbPtr->imageObj), MenuButtonImageProc, mbPtr); if (image == NULL) { return TCL_ERROR; } @@ -567,24 +590,24 @@ ConfigureMenuButton( */ if ((mbPtr->bitmap != None) || (mbPtr->image != NULL)) { - if (Tk_GetPixels(interp, mbPtr->tkwin, mbPtr->widthString, - &mbPtr->width) != TCL_OK) { + if (Tk_GetPixelsFromObj(interp, mbPtr->tkwin, mbPtr->widthObj, + &width) != TCL_OK) { widthError: Tcl_AddErrorInfo(interp, "\n (processing \"-width\" option)"); continue; } - if (Tk_GetPixels(interp, mbPtr->tkwin, mbPtr->heightString, - &mbPtr->height) != TCL_OK) { + if (Tk_GetPixelsFromObj(interp, mbPtr->tkwin, mbPtr->heightObj, + &height) != TCL_OK) { heightError: Tcl_AddErrorInfo(interp, "\n (processing \"-height\" option)"); continue; } } else { - if (Tcl_GetInt(interp, mbPtr->widthString, &mbPtr->width) + if (Tcl_GetIntFromObj(interp, mbPtr->widthObj, &width) != TCL_OK) { goto widthError; } - if (Tcl_GetInt(interp, mbPtr->heightString, &mbPtr->height) + if (Tcl_GetIntFromObj(interp, mbPtr->heightObj, &height) != TCL_OK) { goto heightError; } @@ -596,7 +619,7 @@ ConfigureMenuButton( Tk_FreeSavedOptions(&savedOptions); } - if (mbPtr->textVarName != NULL) { + if (mbPtr->textVarNameObj != NULL) { /* * If no image or -compound is used, display the value of a variable. * Set up a trace to watch for any changes in it, create the variable @@ -604,9 +627,9 @@ ConfigureMenuButton( */ const char *value; - value = Tcl_GetVar2(interp, mbPtr->textVarName, NULL, TCL_GLOBAL_ONLY); + value = Tcl_GetVar2(interp, Tcl_GetString(mbPtr->textVarNameObj), NULL, TCL_GLOBAL_ONLY); if (value == NULL) { - Tcl_SetVar2(interp, mbPtr->textVarName, NULL, mbPtr->text, + Tcl_SetVar2(interp, Tcl_GetString(mbPtr->textVarNameObj), NULL, mbPtr->text, TCL_GLOBAL_ONLY); } else { if (mbPtr->text != NULL) { @@ -615,7 +638,7 @@ ConfigureMenuButton( mbPtr->text = (char *)ckalloc(strlen(value) + 1); strcpy(mbPtr->text, value); } - Tcl_TraceVar2(interp, mbPtr->textVarName, NULL, + Tcl_TraceVar2(interp, Tcl_GetString(mbPtr->textVarNameObj), NULL, TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, MenuButtonTextVarProc, mbPtr); } @@ -756,6 +779,7 @@ MenuButtonEventProc( XEvent *eventPtr) /* Information about event. */ { TkMenuButton *mbPtr = (TkMenuButton *)clientData; + int highlightWidth; if ((eventPtr->type == Expose) && (eventPtr->xexpose.count == 0)) { goto redraw; @@ -771,14 +795,16 @@ MenuButtonEventProc( } else if (eventPtr->type == FocusIn) { if (eventPtr->xfocus.detail != NotifyInferior) { mbPtr->flags |= GOT_FOCUS; - if (mbPtr->highlightWidth > 0) { + Tk_GetPixelsFromObj(NULL, mbPtr->tkwin, mbPtr->highlightWidthObj, &highlightWidth); + if (highlightWidth > 0) { goto redraw; } } } else if (eventPtr->type == FocusOut) { if (eventPtr->xfocus.detail != NotifyInferior) { mbPtr->flags &= ~GOT_FOCUS; - if (mbPtr->highlightWidth > 0) { + Tk_GetPixelsFromObj(NULL, mbPtr->tkwin, mbPtr->highlightWidthObj, &highlightWidth); + if (highlightWidth > 0) { goto redraw; } } @@ -867,12 +893,12 @@ MenuButtonTextVarProc( */ if (flags & TCL_TRACE_UNSETS) { - if (!Tcl_InterpDeleted(interp) && mbPtr->textVarName) { + if (!Tcl_InterpDeleted(interp) && mbPtr->textVarNameObj) { void *probe = NULL; do { probe = Tcl_VarTraceInfo(interp, - mbPtr->textVarName, + Tcl_GetString(mbPtr->textVarNameObj), TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, MenuButtonTextVarProc, probe); if (probe == (void *)mbPtr) { @@ -888,16 +914,16 @@ MenuButtonTextVarProc( */ return NULL; } - Tcl_SetVar2(interp, mbPtr->textVarName, NULL, mbPtr->text, + Tcl_SetVar2(interp, Tcl_GetString(mbPtr->textVarNameObj), NULL, mbPtr->text, TCL_GLOBAL_ONLY); - Tcl_TraceVar2(interp, mbPtr->textVarName, NULL, + Tcl_TraceVar2(interp, Tcl_GetString(mbPtr->textVarNameObj), NULL, TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, MenuButtonTextVarProc, clientData); } return NULL; } - value = Tcl_GetVar2(interp, mbPtr->textVarName, NULL, TCL_GLOBAL_ONLY); + value = Tcl_GetVar2(interp, Tcl_GetString(mbPtr->textVarNameObj), NULL, TCL_GLOBAL_ONLY); if (value == NULL) { value = ""; } diff --git a/generic/tkMenubutton.h b/generic/tkMenubutton.h index 16ed223..a7f2bb8 100644 --- a/generic/tkMenubutton.h +++ b/generic/tkMenubutton.h @@ -55,8 +55,7 @@ typedef struct { Tcl_Command widgetCmd; /* Token for menubutton's widget command. */ Tk_OptionTable optionTable; /* Table that defines configuration options * available for this widget. */ - char *menuName; /* Name of menu associated with widget. - * Malloc-ed. */ + Tcl_Obj *menuNameObj; /* Name of menu associated with widget. */ /* * Information about what's displayed in the menu button: @@ -65,13 +64,13 @@ typedef struct { char *text; /* Text to display in button (malloc'ed) or * NULL. */ int underline; /* Index of character to underline. INT_MIN means no underline */ - char *textVarName; /* Name of variable (malloc'ed) or NULL. If + Tcl_Obj *textVarNameObj; /* Name of variable or NULL. If * non-NULL, button displays the contents of * this variable. */ Pixmap bitmap; /* Bitmap to display or None. If not None then * text and textVar and underline are * ignored. */ - char *imageString; /* Name of image to display (malloc'ed), or + Tcl_Obj *imageObj; /* Name of image to display (malloc'ed), or * NULL. If non-NULL, bitmap, text, and * textVarName are ignored. */ Tk_Image image; /* Image to display in window, or NULL if @@ -89,10 +88,10 @@ typedef struct { Tk_3DBorder activeBorder; /* Structure used to draw 3-D border and * background when window is active. NULL * means no such border exists. */ - int borderWidth; /* Width of border. */ + Tcl_Obj *borderWidthObj; /* Width of border. */ int relief; /* 3-d effect: TK_RELIEF_RAISED, etc. */ - int highlightWidth; /* Width in pixels of highlight to draw around - * widget when it has the focus. <= 0 means + Tcl_Obj *highlightWidthObj; /* Width in pixels of highlight to draw around + * widget when it has the focus. 0 means * don't draw a highlight. */ XColor *highlightBgColorPtr;/* Color for drawing traversal highlight area * when highlight is off. */ @@ -121,18 +120,12 @@ typedef struct { * pixel (positive means to right). */ int rightBearing; /* Amount text sticks right from its * origin. */ - char *widthString; /* Value of -width option. Malloc'ed. */ - char *heightString; /* Value of -height option. Malloc'ed. */ - int width, height; /* If > 0, these specify dimensions to request - * 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. */ - int wrapLength; /* Line length (in pixels) at which to wrap - * onto next line. <= 0 means don't wrap + Tcl_Obj *widthObj; /* Value of -width option. */ + Tcl_Obj *heightObj; /* Value of -height option. */ + Tcl_Obj *wrapLengthObj; /* Line length (in pixels) at which to wrap + * onto next line. 0 means don't wrap * except at newlines. */ - int padX, padY; /* Extra space around text or bitmap (pixels + Tcl_Obj *padXObj, *padYObj; /* Extra space around text or bitmap (pixels * on each side). */ Tk_Anchor anchor; /* Where text/bitmap should be displayed * inside window region. */ @@ -171,9 +164,9 @@ typedef struct { * or right, and the active item will be next * to the button. */ Tk_Cursor cursor; /* Current cursor for window, or NULL. */ - char *takeFocus; /* Value of -takefocus option; not used in the + Tcl_Obj *takeFocusObj; /* Value of -takefocus option; not used in the * C code, but used by keyboard traversal - * scripts. Malloc'ed, but may be NULL. */ + * scripts. May be NULL. */ int flags; /* Various flags; see below for * definitions. */ } TkMenuButton; diff --git a/macosx/tkMacOSXMenubutton.c b/macosx/tkMacOSXMenubutton.c index 6d71ffc..cc781b5 100644 --- a/macosx/tkMacOSXMenubutton.c +++ b/macosx/tkMacOSXMenubutton.c @@ -170,6 +170,7 @@ TkpDisplayMenuButton( Tk_Window tkwin = butPtr->tkwin; Pixmap pixmap; DrawParams *dpPtr = &mbPtr->drawParams; + int highlightWidth; butPtr->flags &= ~REDRAW_PENDING; if ((butPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) { @@ -190,10 +191,11 @@ TkpDisplayMenuButton( * Draw highlight border, if needed. */ - if (butPtr->highlightWidth < 3) { + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->highlightWidthObj, &highlightWidth); + if (highlightWidth < 3) { if (butPtr->flags & GOT_FOCUS) { GC gc = Tk_GCForColor(butPtr->highlightColorPtr, pixmap); - TkMacOSXDrawSolidBorder(tkwin, gc, 0, butPtr->highlightWidth); + TkMacOSXDrawSolidBorder(tkwin, gc, 0, highlightWidth); } } } @@ -246,7 +248,9 @@ TkpComputeMenuButtonGeometry( int width, height, avgWidth, haveImage = 0, haveText = 0; int txtWidth, txtHeight; Tk_FontMetrics fm; - int highlightWidth = butPtr->highlightWidth > 0 ? butPtr->highlightWidth : 0; + int borderWidth, highlightWidth; + int padX, padY; + int butPtrWidth, butPtrHeight; /* * First compute the size of the contents of the button. @@ -267,10 +271,13 @@ TkpComputeMenuButtonGeometry( } if (butPtr->text && strlen(butPtr->text) > 0) { + int wrapLength; + haveText = 1; Tk_FreeTextLayout(butPtr->textLayout); + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->wrapLengthObj, &wrapLength); butPtr->textLayout = Tk_ComputeTextLayout(butPtr->tkfont, - butPtr->text, TCL_INDEX_NONE, butPtr->wrapLength, + butPtr->text, TCL_INDEX_NONE, wrapLength, butPtr->justify, 0, &butPtr->textWidth, &butPtr->textHeight); txtWidth = butPtr->textWidth; txtHeight = butPtr->textHeight; @@ -285,6 +292,10 @@ TkpComputeMenuButtonGeometry( * otherwise it is not really a compound button. */ + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->widthObj, &butPtrWidth); + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->heightObj, &butPtrHeight); + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->padXObj, &padX); + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->padYObj, &padY); if (haveImage && haveText) { switch ((enum compound) butPtr->compound) { case COMPOUND_TOP: @@ -293,7 +304,7 @@ TkpComputeMenuButtonGeometry( * Image is above or below text */ - height += txtHeight + butPtr->padY; + height += txtHeight + padY; width = (width > txtWidth ? width : txtWidth); break; case COMPOUND_LEFT: @@ -302,7 +313,7 @@ TkpComputeMenuButtonGeometry( * Image is left or right of text */ - width += txtWidth + butPtr->padX; + width += txtWidth + padX; height = (height > txtHeight ? height : txtHeight); break; case COMPOUND_CENTER: @@ -317,34 +328,36 @@ TkpComputeMenuButtonGeometry( break; } - if (butPtr->width > 0) { - width = butPtr->width; + if (butPtrWidth > 0) { + width = butPtrWidth; } - if (butPtr->height > 0) { - height = butPtr->height; + if (butPtrHeight > 0) { + height = butPtrHeight; } } else { if (haveImage) { /* Image only */ - if (butPtr->width > 0) { - width = butPtr->width; + if (butPtrWidth > 0) { + width = butPtrWidth; } - if (butPtr->height > 0) { - height = butPtr->height; + if (butPtrHeight > 0) { + height = butPtrHeight; } } else { /* Text only */ width = txtWidth; height = txtHeight; - if (butPtr->width > 0) { - width = butPtr->width * avgWidth + 2*butPtr->padX; + if (butPtrWidth > 0) { + width = butPtrWidth * avgWidth + 2 * padX; } - if (butPtr->height > 0) { - height = butPtr->height * fm.linespace + 2*butPtr->padY; + if (butPtrHeight > 0) { + height = butPtrHeight * fm.linespace + 2 * padY; } } } - butPtr->inset = highlightWidth + butPtr->borderWidth; + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->borderWidthObj, &borderWidth); + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->highlightWidthObj, &highlightWidth); + butPtr->inset = highlightWidth + borderWidth; width += LEFT_INSET + RIGHT_INSET + 2*butPtr->inset; height += 2*butPtr->inset; height = height < MIN_HEIGHT ? MIN_HEIGHT : height; @@ -379,6 +392,7 @@ DrawMenuButtonImageAndText( int textXOffset = 0, textYOffset = 0; int width = 0, height = 0; int fullWidth = 0, fullHeight = 0; + int padX, padY; if (tkwin == NULL || !Tk_IsMapped(tkwin)) { return; @@ -396,6 +410,8 @@ DrawMenuButtonImageAndText( } haveText = (butPtr->textWidth != 0 && butPtr->textHeight != 0); + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->padXObj, &padX); + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->padYObj, &padY); if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) { int x = 0, y = 0; @@ -412,11 +428,11 @@ DrawMenuButtonImageAndText( */ if (butPtr->compound == COMPOUND_TOP) { - textYOffset = height + butPtr->padY; + textYOffset = height + padY; } else { - imageYOffset = butPtr->textHeight + butPtr->padY; + imageYOffset = butPtr->textHeight + padY; } - fullHeight = height + butPtr->textHeight + butPtr->padY; + fullHeight = height + butPtr->textHeight + padY; fullWidth = (width > butPtr->textWidth ? width : butPtr->textWidth); textXOffset = (fullWidth - butPtr->textWidth)/2; @@ -429,11 +445,11 @@ DrawMenuButtonImageAndText( */ if (butPtr->compound == COMPOUND_LEFT) { - textXOffset = width + butPtr->padX - 2; + textXOffset = width + padX - 2; } else { - imageXOffset = butPtr->textWidth + butPtr->padX; + imageXOffset = butPtr->textWidth + padX; } - fullWidth = butPtr->textWidth + butPtr->padX + width; + fullWidth = butPtr->textWidth + padX + width; fullHeight = (height > butPtr->textHeight ? height : butPtr->textHeight); textYOffset = (fullHeight - butPtr->textHeight)/2; @@ -457,7 +473,7 @@ DrawMenuButtonImageAndText( } TkComputeAnchor(butPtr->anchor, tkwin, - butPtr->padX + butPtr->inset, butPtr->padY + butPtr->inset, + padX + butPtr->inset, padY + butPtr->inset, fullWidth, fullHeight, &x, &y); imageXOffset = LEFT_INSET; imageYOffset += y; @@ -485,9 +501,12 @@ DrawMenuButtonImageAndText( int x, y; if (haveImage) { + int borderWidth; + + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->borderWidthObj, &borderWidth); TkComputeAnchor(butPtr->anchor, tkwin, - butPtr->padX + butPtr->borderWidth, - butPtr->padY + butPtr->borderWidth, + padX + borderWidth, + padY + borderWidth, width, height, &x, &y); imageXOffset = LEFT_INSET; imageYOffset += y; @@ -505,7 +524,7 @@ DrawMenuButtonImageAndText( } } else { textXOffset = LEFT_INSET; - TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY, + TkComputeAnchor(butPtr->anchor, tkwin, padX, padY, butPtr->textWidth, butPtr->textHeight, &x, &y); Tk_DrawTextLayout(butPtr->display, pixmap, dpPtr->gc, butPtr->textLayout, textXOffset, y, 0, -1); @@ -730,6 +749,7 @@ TkMacOSXComputeMenuButtonParams( HIThemeButtonDrawInfo *drawinfo) { MacMenuButton *mbPtr = (MacMenuButton *) butPtr; + int highlightWidth; if (butPtr->image || butPtr->bitmap || butPtr->text) { /* TODO: allow for Small and Mini menubuttons. */ @@ -761,7 +781,8 @@ TkMacOSXComputeMenuButtonParams( } drawinfo->adornment = kThemeAdornmentNone; - if (butPtr->highlightWidth >= 3) { + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->highlightWidthObj, &highlightWidth); + if (highlightWidth >= 3) { if ((butPtr->flags & GOT_FOCUS)) { drawinfo->adornment |= kThemeAdornmentFocus; } diff --git a/tests/menubut.test b/tests/menubut.test index 8dd9872..e972ba5 100644 --- a/tests/menubut.test +++ b/tests/menubut.test @@ -98,7 +98,7 @@ test menubutton-1.15 {configuration options} -body { .mb cget -borderwidth } -cleanup { .mb configure -borderwidth [lindex [.mb configure -borderwidth] 3] -} -result 1 +} -result 1.3 test menubutton-1.16 {configuration options} -body { .mb configure -borderwidth badValue } -returnCodes error -result {expected screen distance but got "badValue"} -- cgit v0.12 From 3fcf89fea2d454976e49469e05f1ea9c591262e5 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 30 Sep 2024 21:16:14 +0000 Subject: Finish for "menubutton". Simplify -activerelief for "menu" --- generic/tkCanvas.c | 9 ---- generic/tkMenu.c | 4 +- generic/tkMenu.h | 2 +- generic/tkMenubutton.c | 100 ++++++++++++++++---------------------------- generic/tkMenubutton.h | 18 +++++--- macosx/tkMacOSXMenubutton.c | 77 +++++++++++++--------------------- tests/menubut.test | 2 +- unix/tkUnixMenu.c | 2 +- win/tkWinMenu.c | 2 +- 9 files changed, 81 insertions(+), 135 deletions(-) diff --git a/generic/tkCanvas.c b/generic/tkCanvas.c index b4d455e..db9a3fd 100644 --- a/generic/tkCanvas.c +++ b/generic/tkCanvas.c @@ -2347,15 +2347,6 @@ ConfigureCanvas( if (canvasPtr->highlightWidth < 0) { canvasPtr->highlightWidth = 0; } - if (canvasPtr->textInfo.insertBorderWidth < 0) { - canvasPtr->textInfo.insertBorderWidth = 0; - } - if (canvasPtr->textInfo.insertWidth < 0) { - canvasPtr->textInfo.insertWidth = 0; - } - if (canvasPtr->textInfo.selBorderWidth < 0) { - canvasPtr->textInfo.selBorderWidth = 0; - } if (canvasPtr->width < 0) { canvasPtr->width = 0; } diff --git a/generic/tkMenu.c b/generic/tkMenu.c index 66d919f..141364a 100644 --- a/generic/tkMenu.c +++ b/generic/tkMenu.c @@ -249,8 +249,8 @@ static const Tk_OptionSpec tkMenuConfigSpecs[] = { offsetof(TkMenu, activeFgPtr), TCL_INDEX_NONE, 0, DEF_MENU_ACTIVE_FG_MONO, 0}, {TK_OPTION_RELIEF, "-activerelief", "activeRelief", "Relief", - DEF_MENU_ACTIVE_RELIEF, offsetof(TkMenu, activeReliefPtr), - TCL_INDEX_NONE, 0, NULL, 0}, + DEF_MENU_ACTIVE_RELIEF, TCL_INDEX_NONE, + offsetof(TkMenu, activeRelief), 0, NULL, 0}, {TK_OPTION_BORDER, "-background", "background", "Background", DEF_MENU_BG_COLOR, offsetof(TkMenu, borderPtr), TCL_INDEX_NONE, 0, DEF_MENU_BG_MONO, 0}, diff --git a/generic/tkMenu.h b/generic/tkMenu.h index ffe6770..f17d8dc 100644 --- a/generic/tkMenu.h +++ b/generic/tkMenu.h @@ -379,7 +379,7 @@ typedef struct TkMenu { /* We actually have to allocate these because * multiple menus get changed during one * ConfigureMenu call. */ - Tcl_Obj *activeReliefPtr; /* 3-d effect for active element. */ + int activeRelief; /* 3-d effect for active element. */ Tcl_HashTable items; /* Map: id -> entry */ int serial; /* Next item # for autogenerated ids */ } TkMenu; diff --git a/generic/tkMenubutton.c b/generic/tkMenubutton.c index e1c3c33..72b8f70 100644 --- a/generic/tkMenubutton.c +++ b/generic/tkMenubutton.c @@ -62,8 +62,8 @@ static const Tk_OptionSpec optionSpecs[] = { DEF_MENUBUTTON_BITMAP, TCL_INDEX_NONE, offsetof(TkMenuButton, bitmap), TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth", - DEF_MENUBUTTON_BORDER_WIDTH, offsetof(TkMenuButton, borderWidthObj), - TCL_INDEX_NONE, 0, 0, 0}, + DEF_MENUBUTTON_BORDER_WIDTH, TCL_INDEX_NONE, + offsetof(TkMenuButton, borderWidth), 0, 0, 0}, {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor", DEF_MENUBUTTON_CURSOR, TCL_INDEX_NONE, offsetof(TkMenuButton, cursor), TK_OPTION_NULL_OK, 0, 0}, @@ -91,7 +91,7 @@ static const Tk_OptionSpec optionSpecs[] = { offsetof(TkMenuButton, highlightColorPtr), 0, 0, 0}, {TK_OPTION_PIXELS, "-highlightthickness", "highlightThickness", "HighlightThickness", DEF_MENUBUTTON_HIGHLIGHT_WIDTH, - offsetof(TkMenuButton, highlightWidthObj), TCL_INDEX_NONE, 0, 0, 0}, + TCL_INDEX_NONE, offsetof(TkMenuButton, highlightWidth), 0, 0, 0}, {TK_OPTION_STRING, "-image", "image", "Image", DEF_MENUBUTTON_IMAGE, offsetof(TkMenuButton, imageObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, @@ -104,10 +104,10 @@ static const Tk_OptionSpec optionSpecs[] = { DEF_MENUBUTTON_MENU, offsetof(TkMenuButton, menuNameObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_PIXELS, "-padx", "padX", "Pad", - DEF_MENUBUTTON_PADX, offsetof(TkMenuButton, padXObj), TCL_INDEX_NONE, + DEF_MENUBUTTON_PADX, TCL_INDEX_NONE, offsetof(TkMenuButton, padX), 0, 0, 0}, {TK_OPTION_PIXELS, "-pady", "padY", "Pad", - DEF_MENUBUTTON_PADY, offsetof(TkMenuButton, padYObj), TCL_INDEX_NONE, + DEF_MENUBUTTON_PADY, TCL_INDEX_NONE, offsetof(TkMenuButton, padY), 0, 0, 0}, {TK_OPTION_RELIEF, "-relief", "relief", "Relief", DEF_MENUBUTTON_RELIEF, TCL_INDEX_NONE, offsetof(TkMenuButton, relief), @@ -132,8 +132,8 @@ static const Tk_OptionSpec optionSpecs[] = { DEF_MENUBUTTON_WIDTH, offsetof(TkMenuButton, widthObj), TCL_INDEX_NONE, 0, 0, 0}, {TK_OPTION_PIXELS, "-wraplength", "wrapLength", "WrapLength", - DEF_MENUBUTTON_WRAP_LENGTH, offsetof(TkMenuButton, wrapLengthObj), - TCL_INDEX_NONE, 0, 0, 0}, + DEF_MENUBUTTON_WRAP_LENGTH, TCL_INDEX_NONE, + offsetof(TkMenuButton, wrapLength), 0, 0, 0}, {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, 0} }; @@ -190,7 +190,7 @@ static void DestroyMenuButton(void *memPtr); int Tk_MenubuttonObjCmd( - void *dummy, /* NULL. */ + TCL_UNUSED(void *), Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ @@ -198,7 +198,6 @@ Tk_MenubuttonObjCmd( TkMenuButton *mbPtr; Tk_OptionTable optionTable; Tk_Window tkwin; - (void)dummy; if (objc < 2) { Tcl_WrongNumArgs(interp, 1, objv, "pathName ?-option value ...?"); @@ -248,9 +247,9 @@ Tk_MenubuttonObjCmd( mbPtr->state = STATE_NORMAL; mbPtr->normalBorder = NULL; mbPtr->activeBorder = NULL; - mbPtr->borderWidthObj = NULL; + mbPtr->borderWidth = 0; mbPtr->relief = TK_RELIEF_FLAT; - mbPtr->highlightWidthObj = 0; + mbPtr->highlightWidth = 0; mbPtr->highlightBgColorPtr = NULL; mbPtr->highlightColorPtr = NULL; mbPtr->inset = 0; @@ -267,9 +266,11 @@ Tk_MenubuttonObjCmd( mbPtr->rightBearing = 0; mbPtr->widthObj = NULL; mbPtr->heightObj = NULL; - mbPtr->wrapLengthObj = 0; - mbPtr->padXObj = NULL; - mbPtr->padYObj = NULL; + mbPtr->width = 0; + mbPtr->height = 0; + mbPtr->wrapLength = 0; + mbPtr->padX = 0; + mbPtr->padY = 0; mbPtr->anchor = TK_ANCHOR_CENTER; mbPtr->justify = TK_JUSTIFY_CENTER; mbPtr->textLayout = NULL; @@ -477,9 +478,6 @@ ConfigureMenuButton( Tcl_Obj *errorResult = NULL; int error; Tk_Image image; - int borderWidth, highlightWidth; - int padX, padY; - int width, height; /* * Eliminate any existing trace on variables monitored by the menubutton. @@ -532,37 +530,17 @@ ConfigureMenuButton( Tk_SetBackgroundFromBorder(mbPtr->tkwin, mbPtr->normalBorder); } - Tk_GetPixelsFromObj(NULL, mbPtr->tkwin, mbPtr->borderWidthObj, &borderWidth); - Tk_GetPixelsFromObj(NULL, mbPtr->tkwin, mbPtr->highlightWidthObj, &highlightWidth); - Tk_GetPixelsFromObj(NULL, mbPtr->tkwin, mbPtr->padXObj, &padX); - Tk_GetPixelsFromObj(NULL, mbPtr->tkwin, mbPtr->padYObj, &padY); - if (borderWidth < 0) { - borderWidth = 0; - Tcl_DecrRefCount(mbPtr->borderWidthObj); - mbPtr->borderWidthObj = Tcl_NewIntObj(0); - Tcl_IncrRefCount(mbPtr->borderWidthObj); + if (mbPtr->borderWidth < 0) { + mbPtr->borderWidth = 0; } - if (highlightWidth < 0) { - highlightWidth = 0; - Tcl_DecrRefCount(mbPtr->highlightWidthObj); - mbPtr->highlightWidthObj = Tcl_NewIntObj(0); - Tcl_IncrRefCount(mbPtr->highlightWidthObj); + if (mbPtr->highlightWidth < 0) { + mbPtr->highlightWidth = 0; } - if (padX < 0) { - padX = 0; - if (mbPtr->padXObj) { - Tcl_DecrRefCount(mbPtr->padXObj); - } - mbPtr->padXObj = Tcl_NewIntObj(0); - Tcl_IncrRefCount(mbPtr->padXObj); + if (mbPtr->padX < 0) { + mbPtr->padX = 0; } - if (padY < 0) { - padY = 0; - if (mbPtr->padYObj) { - Tcl_DecrRefCount(mbPtr->padYObj); - } - mbPtr->padYObj = Tcl_NewIntObj(0); - Tcl_IncrRefCount(mbPtr->padYObj); + if (mbPtr->padY < 0) { + mbPtr->padY = 0; } /* @@ -591,23 +569,23 @@ ConfigureMenuButton( if ((mbPtr->bitmap != None) || (mbPtr->image != NULL)) { if (Tk_GetPixelsFromObj(interp, mbPtr->tkwin, mbPtr->widthObj, - &width) != TCL_OK) { + &mbPtr->width) != TCL_OK) { widthError: Tcl_AddErrorInfo(interp, "\n (processing \"-width\" option)"); continue; } if (Tk_GetPixelsFromObj(interp, mbPtr->tkwin, mbPtr->heightObj, - &height) != TCL_OK) { + &mbPtr->height) != TCL_OK) { heightError: Tcl_AddErrorInfo(interp, "\n (processing \"-height\" option)"); continue; } } else { - if (Tcl_GetIntFromObj(interp, mbPtr->widthObj, &width) + if (Tcl_GetIntFromObj(interp, mbPtr->widthObj, &mbPtr->width) != TCL_OK) { goto widthError; } - if (Tcl_GetIntFromObj(interp, mbPtr->heightObj, &height) + if (Tcl_GetIntFromObj(interp, mbPtr->heightObj, &mbPtr->height) != TCL_OK) { goto heightError; } @@ -779,7 +757,6 @@ MenuButtonEventProc( XEvent *eventPtr) /* Information about event. */ { TkMenuButton *mbPtr = (TkMenuButton *)clientData; - int highlightWidth; if ((eventPtr->type == Expose) && (eventPtr->xexpose.count == 0)) { goto redraw; @@ -795,16 +772,14 @@ MenuButtonEventProc( } else if (eventPtr->type == FocusIn) { if (eventPtr->xfocus.detail != NotifyInferior) { mbPtr->flags |= GOT_FOCUS; - Tk_GetPixelsFromObj(NULL, mbPtr->tkwin, mbPtr->highlightWidthObj, &highlightWidth); - if (highlightWidth > 0) { + if (mbPtr->highlightWidth > 0) { goto redraw; } } } else if (eventPtr->type == FocusOut) { if (eventPtr->xfocus.detail != NotifyInferior) { mbPtr->flags &= ~GOT_FOCUS; - Tk_GetPixelsFromObj(NULL, mbPtr->tkwin, mbPtr->highlightWidthObj, &highlightWidth); - if (highlightWidth > 0) { + if (mbPtr->highlightWidth > 0) { goto redraw; } } @@ -960,19 +935,14 @@ MenuButtonTextVarProc( static void MenuButtonImageProc( void *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. */ + TCL_UNUSED(int), /* x, Upper left pixel (within image) that must */ + TCL_UNUSED(int), /* y, be redisplayed. */ + TCL_UNUSED(int), /* width, Dimensions of area to redisplay (may be <= */ + TCL_UNUSED(int), /* height, 0). */ + TCL_UNUSED(int), /* imgWidth, New dimensions of image. */ + TCL_UNUSED(int)) /* imgHeight) */ { TkMenuButton *mbPtr = (TkMenuButton *)clientData; - (void)x; - (void)y; - (void)width; - (void)height; - (void)imgWidth; - (void)imgHeight; if (mbPtr->tkwin != NULL) { TkpComputeMenuButtonGeometry(mbPtr); diff --git a/generic/tkMenubutton.h b/generic/tkMenubutton.h index 3738317..5fb6815 100644 --- a/generic/tkMenubutton.h +++ b/generic/tkMenubutton.h @@ -87,10 +87,10 @@ typedef struct { Tk_3DBorder activeBorder; /* Structure used to draw 3-D border and * background when window is active. NULL * means no such border exists. */ - Tcl_Obj *borderWidthObj; /* Width of border. */ + int borderWidth; /* Width of border. */ int relief; /* 3-d effect: TK_RELIEF_RAISED, etc. */ - Tcl_Obj *highlightWidthObj; /* Width in pixels of highlight to draw around - * widget when it has the focus. 0 means + int highlightWidth; /* Width in pixels of highlight to draw around + * widget when it has the focus. <= 0 means * don't draw a highlight. */ XColor *highlightBgColorPtr;/* Color for drawing traversal highlight area * when highlight is off. */ @@ -121,10 +121,16 @@ typedef struct { * origin. */ Tcl_Obj *widthObj; /* Value of -width option. */ Tcl_Obj *heightObj; /* Value of -height option. */ - Tcl_Obj *wrapLengthObj; /* Line length (in pixels) at which to wrap - * onto next line. 0 means don't wrap + int width, height; /* If > 0, these specify dimensions to request + * 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. */ + int wrapLength; /* Line length (in pixels) at which to wrap + * onto next line. <= 0 means don't wrap * except at newlines. */ - Tcl_Obj *padXObj, *padYObj; /* Extra space around text or bitmap (pixels + int padX, padY; /* Extra space around text or bitmap (pixels * on each side). */ Tk_Anchor anchor; /* Where text/bitmap should be displayed * inside window region. */ diff --git a/macosx/tkMacOSXMenubutton.c b/macosx/tkMacOSXMenubutton.c index 3860542..8c408e6 100644 --- a/macosx/tkMacOSXMenubutton.c +++ b/macosx/tkMacOSXMenubutton.c @@ -170,7 +170,6 @@ TkpDisplayMenuButton( Tk_Window tkwin = butPtr->tkwin; Pixmap pixmap; DrawParams *dpPtr = &mbPtr->drawParams; - int highlightWidth; butPtr->flags &= ~REDRAW_PENDING; if ((butPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) { @@ -191,11 +190,10 @@ TkpDisplayMenuButton( * Draw highlight border, if needed. */ - Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->highlightWidthObj, &highlightWidth); - if (highlightWidth < 3) { + if (butPtr->highlightWidth < 3) { if (butPtr->flags & GOT_FOCUS) { GC gc = Tk_GCForColor(butPtr->highlightColorPtr, pixmap); - TkMacOSXDrawSolidBorder(tkwin, gc, 0, highlightWidth); + TkMacOSXDrawSolidBorder(tkwin, gc, 0, butPtr->highlightWidth); } } } @@ -248,9 +246,6 @@ TkpComputeMenuButtonGeometry( int width, height, avgWidth, haveImage = 0, haveText = 0; int txtWidth, txtHeight; Tk_FontMetrics fm; - int borderWidth, highlightWidth; - int padX, padY; - int butPtrWidth, butPtrHeight; /* * First compute the size of the contents of the button. @@ -271,11 +266,9 @@ TkpComputeMenuButtonGeometry( } if (butPtr->textObj && Tcl_GetString(butPtr->textObj)[0]) { - int wrapLength; haveText = 1; Tk_FreeTextLayout(butPtr->textLayout); - Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->wrapLengthObj, &wrapLength); butPtr->textLayout = Tk_ComputeTextLayout(butPtr->tkfont, Tcl_GetString(butPtr->textObj), TCL_INDEX_NONE, butPtr->wrapLength, butPtr->justify, 0, &butPtr->textWidth, &butPtr->textHeight); @@ -292,10 +285,6 @@ TkpComputeMenuButtonGeometry( * otherwise it is not really a compound button. */ - Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->widthObj, &butPtrWidth); - Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->heightObj, &butPtrHeight); - Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->padXObj, &padX); - Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->padYObj, &padY); if (haveImage && haveText) { switch ((enum compound) butPtr->compound) { case COMPOUND_TOP: @@ -304,7 +293,7 @@ TkpComputeMenuButtonGeometry( * Image is above or below text */ - height += txtHeight + padY; + height += txtHeight + butPtr->padY; width = (width > txtWidth ? width : txtWidth); break; case COMPOUND_LEFT: @@ -313,7 +302,7 @@ TkpComputeMenuButtonGeometry( * Image is left or right of text */ - width += txtWidth + padX; + width += txtWidth + butPtr->padX; height = (height > txtHeight ? height : txtHeight); break; case COMPOUND_CENTER: @@ -328,36 +317,34 @@ TkpComputeMenuButtonGeometry( break; } - if (butPtrWidth > 0) { - width = butPtrWidth; + if (butPtr->width > 0) { + width = butPtr->width; } - if (butPtrHeight > 0) { - height = butPtrHeight; + if (butPtr->height > 0) { + height = butPtr->height; } } else { if (haveImage) { /* Image only */ - if (butPtrWidth > 0) { - width = butPtrWidth; + if (butPtr->width > 0) { + width = butPtr->width; } - if (butPtrHeight > 0) { - height = butPtrHeight; + if (butPtr->height > 0) { + height = butPtr->height; } } else { /* Text only */ width = txtWidth; height = txtHeight; - if (butPtrWidth > 0) { - width = butPtrWidth * avgWidth + 2 * padX; + if (butPtr->width > 0) { + width = butPtr->width * avgWidth + 2 * butPtr->padX; } - if (butPtrHeight > 0) { - height = butPtrHeight * fm.linespace + 2 * padY; + if (butPtr->height > 0) { + height = butPtr->height * fm.linespace + 2 * butPtr->padY; } } } - Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->borderWidthObj, &borderWidth); - Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->highlightWidthObj, &highlightWidth); - butPtr->inset = highlightWidth + borderWidth; + butPtr->inset = butPtr->highlightWidth + butPtr->borderWidth; width += LEFT_INSET + RIGHT_INSET + 2*butPtr->inset; height += 2*butPtr->inset; height = height < MIN_HEIGHT ? MIN_HEIGHT : height; @@ -392,7 +379,6 @@ DrawMenuButtonImageAndText( int textXOffset = 0, textYOffset = 0; int width = 0, height = 0; int fullWidth = 0, fullHeight = 0; - int padX, padY; if (tkwin == NULL || !Tk_IsMapped(tkwin)) { return; @@ -410,8 +396,6 @@ DrawMenuButtonImageAndText( } haveText = (butPtr->textWidth != 0 && butPtr->textHeight != 0); - Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->padXObj, &padX); - Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->padYObj, &padY); if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) { int x = 0, y = 0; @@ -428,11 +412,11 @@ DrawMenuButtonImageAndText( */ if (butPtr->compound == COMPOUND_TOP) { - textYOffset = height + padY; + textYOffset = height + butPtr->padY; } else { - imageYOffset = butPtr->textHeight + padY; + imageYOffset = butPtr->textHeight + butPtr->padY; } - fullHeight = height + butPtr->textHeight + padY; + fullHeight = height + butPtr->textHeight + butPtr->padY; fullWidth = (width > butPtr->textWidth ? width : butPtr->textWidth); textXOffset = (fullWidth - butPtr->textWidth)/2; @@ -445,11 +429,11 @@ DrawMenuButtonImageAndText( */ if (butPtr->compound == COMPOUND_LEFT) { - textXOffset = width + padX - 2; + textXOffset = width + butPtr->padX - 2; } else { - imageXOffset = butPtr->textWidth + padX; + imageXOffset = butPtr->textWidth + butPtr->padX; } - fullWidth = butPtr->textWidth + padX + width; + fullWidth = butPtr->textWidth + butPtr->padX + width; fullHeight = (height > butPtr->textHeight ? height : butPtr->textHeight); textYOffset = (fullHeight - butPtr->textHeight)/2; @@ -473,7 +457,7 @@ DrawMenuButtonImageAndText( } TkComputeAnchor(butPtr->anchor, tkwin, - padX + butPtr->inset, padY + butPtr->inset, + butPtr->padX + butPtr->inset, butPtr->padY + butPtr->inset, fullWidth, fullHeight, &x, &y); imageXOffset = LEFT_INSET; imageYOffset += y; @@ -501,12 +485,9 @@ DrawMenuButtonImageAndText( int x, y; if (haveImage) { - int borderWidth; - - Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->borderWidthObj, &borderWidth); TkComputeAnchor(butPtr->anchor, tkwin, - padX + borderWidth, - padY + borderWidth, + butPtr->padX + butPtr->borderWidth, + butPtr->padY + butPtr->borderWidth, width, height, &x, &y); imageXOffset = LEFT_INSET; imageYOffset += y; @@ -524,7 +505,7 @@ DrawMenuButtonImageAndText( } } else { textXOffset = LEFT_INSET; - TkComputeAnchor(butPtr->anchor, tkwin, padX, padY, + TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY, butPtr->textWidth, butPtr->textHeight, &x, &y); Tk_DrawTextLayout(butPtr->display, pixmap, dpPtr->gc, butPtr->textLayout, textXOffset, y, 0, -1); @@ -749,7 +730,6 @@ TkMacOSXComputeMenuButtonParams( HIThemeButtonDrawInfo *drawinfo) { MacMenuButton *mbPtr = (MacMenuButton *) butPtr; - int highlightWidth; if (butPtr->image || butPtr->bitmap || butPtr->textObj) { /* TODO: allow for Small and Mini menubuttons. */ @@ -781,8 +761,7 @@ TkMacOSXComputeMenuButtonParams( } drawinfo->adornment = kThemeAdornmentNone; - Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->highlightWidthObj, &highlightWidth); - if (highlightWidth >= 3) { + if (butPtr->highlightWidth >= 3) { if ((butPtr->flags & GOT_FOCUS)) { drawinfo->adornment |= kThemeAdornmentFocus; } diff --git a/tests/menubut.test b/tests/menubut.test index e972ba5..8dd9872 100644 --- a/tests/menubut.test +++ b/tests/menubut.test @@ -98,7 +98,7 @@ test menubutton-1.15 {configuration options} -body { .mb cget -borderwidth } -cleanup { .mb configure -borderwidth [lindex [.mb configure -borderwidth] 3] -} -result 1.3 +} -result 1 test menubutton-1.16 {configuration options} -body { .mb configure -borderwidth badValue } -returnCodes error -result {expected screen distance but got "badValue"} diff --git a/unix/tkUnixMenu.c b/unix/tkUnixMenu.c index 08d45b0..7244cb5 100644 --- a/unix/tkUnixMenu.c +++ b/unix/tkUnixMenu.c @@ -444,7 +444,7 @@ DrawMenuEntryBackground( || (menuPtr->postedCascade != mePtr))) { relief = TK_RELIEF_FLAT; } else { - Tk_GetReliefFromObj(NULL, menuPtr->activeReliefPtr, &relief); + relief = menuPtr->activeRelief; } Tk_GetPixelsFromObj(NULL, menuPtr->tkwin, menuPtr->activeBorderWidthPtr, &activeBorderWidth); diff --git a/win/tkWinMenu.c b/win/tkWinMenu.c index 163566e..33874fc 100644 --- a/win/tkWinMenu.c +++ b/win/tkWinMenu.c @@ -2944,7 +2944,7 @@ DrawMenuEntryBackground( || (menuPtr->postedCascade != mePtr))) { relief = TK_RELIEF_FLAT; } else { - Tk_GetReliefFromObj(NULL, menuPtr->activeReliefPtr, &relief); + relief = menuPtr->activeRelief); } Tk_GetPixelsFromObj(NULL, menuPtr->tkwin, menuPtr->activeBorderWidthPtr, &activeBorderWidth); -- cgit v0.12 From 5d3e55622bcd82cfed01968ea6685eb69e0f9b60 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 1 Oct 2024 20:14:07 +0000 Subject: Revert part of [788c1c6615]: would be **potential incompatibility** --- generic/tkListbox.c | 116 ++++++++++++++++++++-------------------------------- tests/listbox.test | 4 +- 2 files changed, 47 insertions(+), 73 deletions(-) diff --git a/generic/tkListbox.c b/generic/tkListbox.c index be602d9..7d50360 100644 --- a/generic/tkListbox.c +++ b/generic/tkListbox.c @@ -57,9 +57,9 @@ typedef struct { Tk_3DBorder normalBorder; /* Used for drawing border around whole * window, plus used for background. */ - Tcl_Obj *borderWidthObj; /* Width of 3-D border around window. */ + int borderWidth; /* Width of 3-D border around window. */ int relief; /* 3-D effect: TK_RELIEF_RAISED, etc. */ - Tcl_Obj *highlightWidthObj; /* Width in pixels of highlight to draw around + int highlightWidth; /* Width in pixels of highlight to draw around * widget when it has the focus. <= 0 means * don't draw a highlight. */ XColor *highlightBgColorPtr; @@ -77,7 +77,7 @@ typedef struct { GC textGC; /* For drawing normal text. */ Tk_3DBorder selBorder; /* Borders and backgrounds for selected * elements. */ - Tcl_Obj *selBorderWidthObj; /* Width of border around selection. */ + int selBorderWidth; /* Width of border around selection. */ XColor *selFgColorPtr; /* Foreground color for selected elements. */ GC selTextGC; /* For drawing selected text. */ int width; /* Desired width of window, in characters. */ @@ -241,7 +241,7 @@ static const Tk_OptionSpec optionSpecs[] = { {TK_OPTION_SYNONYM, "-bg", NULL, NULL, NULL, 0, TCL_INDEX_NONE, 0, "-background", 0}, {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth", - DEF_LISTBOX_BORDER_WIDTH, offsetof(Listbox, borderWidthObj), TCL_INDEX_NONE, + DEF_LISTBOX_BORDER_WIDTH, TCL_INDEX_NONE, offsetof(Listbox, borderWidth), 0, 0, 0}, {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor", DEF_LISTBOX_CURSOR, TCL_INDEX_NONE, offsetof(Listbox, cursor), @@ -268,7 +268,7 @@ static const Tk_OptionSpec optionSpecs[] = { 0, 0, 0}, {TK_OPTION_PIXELS, "-highlightthickness", "highlightThickness", "HighlightThickness", DEF_LISTBOX_HIGHLIGHT_WIDTH, - offsetof(Listbox, highlightWidthObj), TCL_INDEX_NONE, 0, 0, 0}, + TCL_INDEX_NONE, offsetof(Listbox, highlightWidth), 0, 0, 0}, {TK_OPTION_JUSTIFY, "-justify", "justify", "Justify", DEF_LISTBOX_JUSTIFY, TCL_INDEX_NONE, offsetof(Listbox, justify), TK_OPTION_ENUM_VAR, 0, 0}, {TK_OPTION_RELIEF, "-relief", "relief", "Relief", @@ -277,8 +277,8 @@ static const Tk_OptionSpec optionSpecs[] = { DEF_LISTBOX_SELECT_COLOR, TCL_INDEX_NONE, offsetof(Listbox, selBorder), 0, DEF_LISTBOX_SELECT_MONO, 0}, {TK_OPTION_PIXELS, "-selectborderwidth", "selectBorderWidth", - "BorderWidth", DEF_LISTBOX_SELECT_BD, offsetof(Listbox, selBorderWidthObj), - TCL_INDEX_NONE, 0, 0, 0}, + "BorderWidth", DEF_LISTBOX_SELECT_BD, TCL_INDEX_NONE, + offsetof(Listbox, selBorderWidth), 0, 0, 0}, {TK_OPTION_COLOR, "-selectforeground", "selectForeground", "Background", DEF_LISTBOX_SELECT_FG_COLOR, TCL_INDEX_NONE, offsetof(Listbox, selFgColorPtr), TK_OPTION_NULL_OK, DEF_LISTBOX_SELECT_FG_MONO, 0}, @@ -1093,7 +1093,6 @@ ListboxBboxSubCmd( int pixelWidth, x, y, result; Tcl_Size stringLen; Tk_FontMetrics fm; - int selBorderWidth; /* * Compute the pixel width of the requested element. @@ -1108,18 +1107,17 @@ ListboxBboxSubCmd( Tk_GetFontMetrics(listPtr->tkfont, &fm); pixelWidth = Tk_TextWidth(listPtr->tkfont, stringRep, stringLen); - Tk_GetPixelsFromObj(NULL, listPtr->tkwin, listPtr->selBorderWidthObj, &selBorderWidth); if (listPtr->justify == TK_JUSTIFY_LEFT) { - x = (listPtr->inset + selBorderWidth) - listPtr->xOffset; + x = (listPtr->inset + listPtr->selBorderWidth) - listPtr->xOffset; } else if (listPtr->justify == TK_JUSTIFY_RIGHT) { - x = Tk_Width(tkwin) - (listPtr->inset + selBorderWidth) + x = Tk_Width(tkwin) - (listPtr->inset + listPtr->selBorderWidth) - pixelWidth - listPtr->xOffset + GetMaxOffset(listPtr); } else { x = (Tk_Width(tkwin) - pixelWidth) / 2 - listPtr->xOffset + GetMaxOffset(listPtr) / 2; } y = ((index - listPtr->topIndex)*listPtr->lineHeight) - + listPtr->inset + selBorderWidth; + + listPtr->inset + listPtr->selBorderWidth; results[0] = Tcl_NewWideIntObj(x); results[1] = Tcl_NewWideIntObj(y); results[2] = Tcl_NewWideIntObj(pixelWidth); @@ -1247,11 +1245,9 @@ ListboxXviewSubCmd( int index, count, windowWidth, windowUnits; int offset = 0; /* Initialized to stop gcc warnings. */ double fraction; - int selBorderWidth; - Tk_GetPixelsFromObj(NULL, listPtr->tkwin, listPtr->selBorderWidthObj, &selBorderWidth); windowWidth = Tk_Width(listPtr->tkwin) - - 2 * (listPtr->inset + selBorderWidth); + - 2 * (listPtr->inset + listPtr->selBorderWidth); if (objc == 2) { Tcl_Obj *results[2]; @@ -1562,7 +1558,6 @@ ConfigureListbox( Tcl_Obj *oldListObj = NULL; Tcl_Obj *errorResult = NULL; int oldExport, error; - int borderWidth, selBorderWidth, highlightWidth; oldExport = (listPtr->exportSelection) && (!Tcl_IsSafe(listPtr->interp)); if (listPtr->listVarNameObj != NULL) { @@ -1599,28 +1594,16 @@ ConfigureListbox( Tk_SetBackgroundFromBorder(listPtr->tkwin, listPtr->normalBorder); - Tk_GetPixelsFromObj(NULL, listPtr->tkwin, listPtr->borderWidthObj, &borderWidth); - if (borderWidth < 0) { - borderWidth = 0; - Tcl_DecrRefCount(listPtr->borderWidthObj); - listPtr->borderWidthObj = Tcl_NewIntObj(0); - Tcl_IncrRefCount(listPtr->borderWidthObj); - } - Tk_GetPixelsFromObj(NULL, listPtr->tkwin, listPtr->highlightWidthObj, &highlightWidth); - if (highlightWidth < 0) { - highlightWidth = 0; - Tcl_DecrRefCount(listPtr->highlightWidthObj); - listPtr->highlightWidthObj = Tcl_NewIntObj(0); - Tcl_IncrRefCount(listPtr->highlightWidthObj); - } - Tk_GetPixelsFromObj(NULL, listPtr->tkwin, listPtr->selBorderWidthObj, &selBorderWidth); - if (selBorderWidth < 0) { - selBorderWidth = 0; - Tcl_DecrRefCount(listPtr->selBorderWidthObj); - listPtr->selBorderWidthObj = Tcl_NewIntObj(0); - Tcl_IncrRefCount(listPtr->selBorderWidthObj); - } - listPtr->inset = highlightWidth + borderWidth; + if (listPtr->borderWidth < 0) { + listPtr->borderWidth = 0; + } + if (listPtr->highlightWidth < 0) { + listPtr->highlightWidth = 0; + } + if (listPtr->selBorderWidth < 0) { + listPtr->selBorderWidth = 0; + } + listPtr->inset = listPtr->highlightWidth + listPtr->borderWidth; /* * Claim the selection if we've suddenly started exporting it and @@ -1873,7 +1856,6 @@ DisplayListbox( * off-screen. */ Pixmap pixmap; int textWidth; - int borderWidth, selBorderWidth, highlightWidth; listPtr->flags &= ~REDRAW_PENDING; if (listPtr->flags & LISTBOX_DELETED) { @@ -1925,18 +1907,17 @@ DisplayListbox( * Display each item in the listbox. */ - Tk_GetPixelsFromObj(NULL, listPtr->tkwin, listPtr->selBorderWidthObj, &selBorderWidth); limit = listPtr->topIndex + listPtr->fullLines + listPtr->partialLine - 1; if (limit >= (int)listPtr->nElements) { limit = listPtr->nElements-1; } left = right = 0; if (listPtr->xOffset > 0) { - left = selBorderWidth + 1; + left = listPtr->selBorderWidth + 1; } if ((listPtr->maxWidth - listPtr->xOffset) > (Tk_Width(listPtr->tkwin) - - 2 * (listPtr->inset + selBorderWidth))) { - right = selBorderWidth + 1; + - 2 * (listPtr->inset + listPtr->selBorderWidth))) { + right = listPtr->selBorderWidth + 1; } prevSelected = 0; @@ -2025,29 +2006,29 @@ DisplayListbox( /* Draw left bevel */ if (left == 0) { Tk_3DVerticalBevel(tkwin, pixmap, selectedBg, - x, y, selBorderWidth, listPtr->lineHeight, + x, y, listPtr->selBorderWidth, listPtr->lineHeight, 1, TK_RELIEF_RAISED); } /* Draw right bevel */ if (right == 0) { Tk_3DVerticalBevel(tkwin, pixmap, selectedBg, - x + width - selBorderWidth, y, - selBorderWidth, listPtr->lineHeight, + x + width - listPtr->selBorderWidth, y, + listPtr->selBorderWidth, listPtr->lineHeight, 0, TK_RELIEF_RAISED); } /* Draw top bevel */ if (!prevSelected) { Tk_3DHorizontalBevel(tkwin, pixmap, selectedBg, x-left, y, width+left+right, - selBorderWidth, + listPtr->selBorderWidth, 1, 1, 1, TK_RELIEF_RAISED); } /* Draw bottom bevel */ if (i + 1 == (int)listPtr->nElements || !Tcl_FindHashEntry(listPtr->selection, KEY(i + 1))) { Tk_3DHorizontalBevel(tkwin, pixmap, selectedBg, x-left, - y + listPtr->lineHeight - selBorderWidth, - width+left+right, selBorderWidth, 0, 0, 0, + y + listPtr->lineHeight - listPtr->selBorderWidth, + width+left+right, listPtr->selBorderWidth, 0, 0, 0, TK_RELIEF_RAISED); } prevSelected = 1; @@ -2099,12 +2080,12 @@ DisplayListbox( textWidth = Tk_TextWidth(listPtr->tkfont, stringRep, stringLen); Tk_GetFontMetrics(listPtr->tkfont, &fm); - y += fm.ascent + selBorderWidth; + y += fm.ascent + listPtr->selBorderWidth; if (listPtr->justify == TK_JUSTIFY_LEFT) { - x = (listPtr->inset + selBorderWidth) - listPtr->xOffset; + x = (listPtr->inset + listPtr->selBorderWidth) - listPtr->xOffset; } else if (listPtr->justify == TK_JUSTIFY_RIGHT) { - x = Tk_Width(tkwin) - (listPtr->inset + selBorderWidth) + x = Tk_Width(tkwin) - (listPtr->inset + listPtr->selBorderWidth) - textWidth - listPtr->xOffset + GetMaxOffset(listPtr); } else { x = (Tk_Width(tkwin) - textWidth)/2 @@ -2160,24 +2141,22 @@ DisplayListbox( * of the text of the listbox entries. */ - Tk_GetPixelsFromObj(NULL, listPtr->tkwin, listPtr->borderWidthObj, &borderWidth); - Tk_GetPixelsFromObj(NULL, listPtr->tkwin, listPtr->highlightWidthObj, &highlightWidth); Tk_Draw3DRectangle(tkwin, pixmap, listPtr->normalBorder, - highlightWidth, highlightWidth, - Tk_Width(tkwin) - 2 * highlightWidth, - Tk_Height(tkwin) - 2 * highlightWidth, - borderWidth, listPtr->relief); - if (highlightWidth > 0) { + listPtr->highlightWidth, listPtr->highlightWidth, + Tk_Width(tkwin) - 2 * listPtr->highlightWidth, + Tk_Height(tkwin) - 2 * listPtr->highlightWidth, + listPtr->borderWidth, listPtr->relief); + if (listPtr->highlightWidth > 0) { GC fgGC, bgGC; bgGC = Tk_GCForColor(listPtr->highlightBgColorPtr, pixmap); if (listPtr->flags & GOT_FOCUS) { fgGC = Tk_GCForColor(listPtr->highlightColorPtr, pixmap); Tk_DrawHighlightBorder(tkwin, fgGC, bgGC, - highlightWidth, pixmap); + listPtr->highlightWidth, pixmap); } else { Tk_DrawHighlightBorder(tkwin, bgGC, bgGC, - highlightWidth, pixmap); + listPtr->highlightWidth, pixmap); } } #ifndef TK_NO_DOUBLE_BUFFERING @@ -2226,7 +2205,6 @@ ListboxComputeGeometry( Tk_FontMetrics fm; Tcl_Obj *element; const char *text; - int selBorderWidth; if (fontChanged || maxIsStale) { listPtr->xScrollUnit = Tk_TextWidth(listPtr->tkfont, "0", 1); @@ -2254,8 +2232,7 @@ ListboxComputeGeometry( } Tk_GetFontMetrics(listPtr->tkfont, &fm); - Tk_GetPixelsFromObj(NULL, listPtr->tkwin, listPtr->selBorderWidthObj, &selBorderWidth); - listPtr->lineHeight = fm.linespace + 1 + 2 * selBorderWidth; + listPtr->lineHeight = fm.linespace + 1 + 2 * listPtr->selBorderWidth; width = listPtr->width; if (width <= 0) { width = (listPtr->maxWidth + listPtr->xScrollUnit - 1) @@ -2265,7 +2242,7 @@ ListboxComputeGeometry( } } pixelWidth = width*listPtr->xScrollUnit + 2 * listPtr->inset - + 2 * selBorderWidth; + + 2 * listPtr->selBorderWidth; height = listPtr->height; if (listPtr->height <= 0) { height = (int)listPtr->nElements; @@ -3358,15 +3335,13 @@ ListboxUpdateHScrollbar( double first, last; Tcl_Interp *interp; Tcl_DString buf; - int selBorderWidth; if (listPtr->xScrollCmdObj == NULL) { return; } - Tk_GetPixelsFromObj(NULL, listPtr->tkwin, listPtr->selBorderWidthObj, &selBorderWidth); windowWidth = Tk_Width(listPtr->tkwin) - - 2 * (listPtr->inset + selBorderWidth); + - 2 * (listPtr->inset + listPtr->selBorderWidth); if (listPtr->maxWidth == 0) { first = 0; last = 1.0; @@ -3637,12 +3612,11 @@ MigrateHashEntries( static int GetMaxOffset( Listbox *listPtr) { - int maxOffset, selBorderWidth; + int maxOffset; - Tk_GetPixelsFromObj(NULL, listPtr->tkwin, listPtr->selBorderWidthObj, &selBorderWidth); maxOffset = listPtr->maxWidth - (Tk_Width(listPtr->tkwin) - 2 * listPtr->inset - - 2 * selBorderWidth) + listPtr->xScrollUnit - 1; + 2 * listPtr->selBorderWidth) + listPtr->xScrollUnit - 1; if (maxOffset < 0) { /* diff --git a/tests/listbox.test b/tests/listbox.test index 80461a3..be7e383 100644 --- a/tests/listbox.test +++ b/tests/listbox.test @@ -107,7 +107,7 @@ test listbox-1.9 {configuration options} -body { list [lindex [.l configure -borderwidth] 4] [.l cget -borderwidth] } -cleanup { .l configure -borderwidth [lindex [.l configure -borderwidth] 3] -} -result {1.3 1.3} +} -result {1 1} test listbox-1.10 {configuration options} -body { .l configure -borderwidth badValue } -returnCodes error -result {expected screen distance but got "badValue"} @@ -242,7 +242,7 @@ test listbox-1.37 {configuration options} -body { list [lindex [.l configure -selectborderwidth] 4] [.l cget -selectborderwidth] } -cleanup { .l configure -selectborderwidth [lindex [.l configure -selectborderwidth] 3] -} -result {1.3 1.3} +} -result {1 1} test listbox-1.38 {configuration options} -body { .l configure -selectborderwidth badValue } -returnCodes error -result {expected screen distance but got "badValue"} -- cgit v0.12