Skip to content

Commit

Permalink
Fix [f91aa24bbe] for "menubutton". Simplify -activerelief for "menu"
Browse files Browse the repository at this point in the history
  • Loading branch information
jan.nijtmans committed Oct 1, 2024
2 parents 8eb1894 + 018572a commit df21e8d
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 38 deletions.
4 changes: 2 additions & 2 deletions generic/tkMenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
2 changes: 1 addition & 1 deletion generic/tkMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
50 changes: 23 additions & 27 deletions generic/tkMenubutton.c
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -129,11 +129,11 @@ static const Tk_OptionSpec optionSpecs[] = {
{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, offsetof(TkMenuButton, wrapLengthObj), offsetof(TkMenuButton, wrapLength),
0, 0, 0},
DEF_MENUBUTTON_WRAP_LENGTH, offsetof(TkMenuButton, wrapLengthObj),
offsetof(TkMenuButton, wrapLength), 0, 0, 0},
{TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, 0}
};

Expand Down Expand Up @@ -190,15 +190,14 @@ 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. */
{
TkMenuButton *mbPtr;
Tk_OptionTable optionTable;
Tk_Window tkwin;
(void)dummy;

if (objc < 2) {
Tcl_WrongNumArgs(interp, 1, objv, "pathName ?-option value ...?");
Expand Down Expand Up @@ -265,10 +264,10 @@ Tk_MenubuttonObjCmd(
mbPtr->stippleGC = NULL;
mbPtr->leftBearing = 0;
mbPtr->rightBearing = 0;
mbPtr->widthString = NULL;
mbPtr->heightString = NULL;
mbPtr->width = 0;
mbPtr->widthObj = NULL;
mbPtr->heightObj = NULL;
mbPtr->width = 0;
mbPtr->height = 0;
mbPtr->wrapLength = 0;
mbPtr->padX = 0;
mbPtr->padY = 0;
Expand Down Expand Up @@ -536,6 +535,9 @@ ConfigureMenuButton(
Tk_SetBackgroundFromBorder(mbPtr->tkwin, mbPtr->normalBorder);
}

if (mbPtr->borderWidth < 0) {
mbPtr->borderWidth = 0;
}
if (mbPtr->highlightWidth < 0) {
mbPtr->highlightWidth = 0;
if (mbPtr->highlightWidthObj) {
Expand All @@ -544,7 +546,6 @@ ConfigureMenuButton(
mbPtr->highlightWidthObj = Tcl_NewIntObj(0);
Tcl_IncrRefCount(mbPtr->highlightWidthObj);
}

if (mbPtr->padX < 0) {
mbPtr->padX = 0;
if (mbPtr->padXObj) {
Expand Down Expand Up @@ -587,24 +588,24 @@ ConfigureMenuButton(
*/

if ((mbPtr->bitmap != None) || (mbPtr->image != NULL)) {
if (Tk_GetPixels(interp, mbPtr->tkwin, mbPtr->widthString,
if (Tk_GetPixelsFromObj(interp, mbPtr->tkwin, mbPtr->widthObj,
&mbPtr->width) != TCL_OK) {
widthError:
Tcl_AddErrorInfo(interp, "\n (processing \"-width\" option)");
continue;
}
if (Tk_GetPixels(interp, mbPtr->tkwin, mbPtr->heightString,
if (Tk_GetPixelsFromObj(interp, mbPtr->tkwin, mbPtr->heightObj,
&mbPtr->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, &mbPtr->width)
!= TCL_OK) {
goto widthError;
}
if (Tcl_GetInt(interp, mbPtr->heightString, &mbPtr->height)
if (Tcl_GetIntFromObj(interp, mbPtr->heightObj, &mbPtr->height)
!= TCL_OK) {
goto heightError;
}
Expand Down Expand Up @@ -954,19 +955,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);
Expand Down
4 changes: 2 additions & 2 deletions generic/tkMenubutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ 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. */
Tcl_Obj *widthObj; /* Value of -width option. */
Tcl_Obj *heightObj; /* Value of -height option. */
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
Expand Down
7 changes: 3 additions & 4 deletions macosx/tkMacOSXMenubutton.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ TkpComputeMenuButtonGeometry(
int width, height, avgWidth, haveImage = 0, haveText = 0;
int txtWidth, txtHeight;
Tk_FontMetrics fm;
int highlightWidth = butPtr->highlightWidth > 0 ? butPtr->highlightWidth : 0;

/*
* First compute the size of the contents of the button.
Expand Down Expand Up @@ -336,15 +335,15 @@ TkpComputeMenuButtonGeometry(
width = txtWidth;
height = txtHeight;
if (butPtr->width > 0) {
width = butPtr->width * avgWidth + 2*butPtr->padX;
width = butPtr->width * avgWidth + 2 * butPtr->padX;
}
if (butPtr->height > 0) {
height = butPtr->height * fm.linespace + 2*butPtr->padY;
height = butPtr->height * fm.linespace + 2 * butPtr->padY;
}
}
}

butPtr->inset = highlightWidth + butPtr->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;
Expand Down
2 changes: 1 addition & 1 deletion unix/tkUnixMenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion win/tkWinMenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2944,7 +2944,7 @@ DrawMenuEntryBackground(
|| (menuPtr->postedCascade != mePtr))) {
relief = TK_RELIEF_FLAT;
} else {
Tk_GetReliefFromObj(NULL, menuPtr->activeReliefPtr, &relief);
relief = menuPtr->activeRelief);

This comment has been minimized.

Copy link
@OgreTransporter

OgreTransporter Oct 2, 2024

Bug! There is a ) left!

}
Tk_GetPixelsFromObj(NULL, menuPtr->tkwin,
menuPtr->activeBorderWidthPtr, &activeBorderWidth);
Expand Down

0 comments on commit df21e8d

Please sign in to comment.