summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorculler <culler>2024-06-15 12:36:28 (GMT)
committerculler <culler>2024-06-15 12:36:28 (GMT)
commit4ef53d757fa6987eeb638dfc02192c2afd1899c1 (patch)
tree66d8f84648f9383034e844b6364345f9f98cb398 /generic
parent5daf3d269c59e298355817203585c172cf488d07 (diff)
parent032de5de9365d1a516ca8c42818f96419e5737cb (diff)
downloadtk-4ef53d757fa6987eeb638dfc02192c2afd1899c1.zip
tk-4ef53d757fa6987eeb638dfc02192c2afd1899c1.tar.gz
tk-4ef53d757fa6987eeb638dfc02192c2afd1899c1.tar.bz2
Merge main
Diffstat (limited to 'generic')
-rw-r--r--generic/tkButton.c54
-rw-r--r--generic/tkImgGIF.c15
-rw-r--r--generic/tkImgPNG.c74
-rw-r--r--generic/tkInt.h3
-rw-r--r--generic/tkMenubutton.c4
-rw-r--r--generic/tkMessage.c230
-rw-r--r--generic/tkText.h9
7 files changed, 242 insertions, 147 deletions
diff --git a/generic/tkButton.c b/generic/tkButton.c
index cbbe880..9d033e4 100644
--- a/generic/tkButton.c
+++ b/generic/tkButton.c
@@ -783,7 +783,7 @@ ButtonWidgetObjCmd(
Tcl_Obj *objPtr;
if (objc < 2) {
- Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
+ Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
return TCL_ERROR;
}
result = Tcl_GetIndexFromObjStruct(interp, objv[1], commandNames[butPtr->type],
@@ -1097,17 +1097,45 @@ ConfigureButton(
} else {
Tk_SetBackgroundFromBorder(butPtr->tkwin, butPtr->normalBorder);
}
+ if (butPtr->wrapLength < 0) {
+ butPtr->wrapLength = 0;
+ if (butPtr->wrapLengthPtr) {
+ Tcl_DecrRefCount(butPtr->wrapLengthPtr);
+ }
+ butPtr->wrapLengthPtr = Tcl_NewIntObj(0);
+ Tcl_IncrRefCount(butPtr->wrapLengthPtr);
+ }
if (butPtr->borderWidth < 0) {
butPtr->borderWidth = 0;
+ if (butPtr->borderWidthPtr) {
+ Tcl_DecrRefCount(butPtr->borderWidthPtr);
+ }
+ butPtr->borderWidthPtr = Tcl_NewIntObj(0);
+ Tcl_IncrRefCount(butPtr->borderWidthPtr);
}
if (butPtr->highlightWidth < 0) {
butPtr->highlightWidth = 0;
+ if (butPtr->highlightWidthPtr) {
+ Tcl_DecrRefCount(butPtr->highlightWidthPtr);
+ }
+ butPtr->highlightWidthPtr = Tcl_NewIntObj(0);
+ Tcl_IncrRefCount(butPtr->highlightWidthPtr);
}
if (butPtr->padX < 0) {
butPtr->padX = 0;
+ if (butPtr->padXPtr) {
+ Tcl_DecrRefCount(butPtr->padXPtr);
+ }
+ butPtr->padXPtr = Tcl_NewIntObj(0);
+ Tcl_IncrRefCount(butPtr->padXPtr);
}
if (butPtr->padY < 0) {
butPtr->padY = 0;
+ if (butPtr->padYPtr) {
+ Tcl_DecrRefCount(butPtr->padYPtr);
+ }
+ butPtr->padYPtr = Tcl_NewIntObj(0);
+ Tcl_IncrRefCount(butPtr->padYPtr);
}
if (butPtr->type >= TYPE_CHECK_BUTTON) {
@@ -1129,13 +1157,13 @@ ConfigureButton(
valuePtr = Tcl_ObjGetVar2(interp, namePtr, NULL, TCL_GLOBAL_ONLY);
butPtr->flags &= ~SELECTED;
- butPtr->flags &= ~TRISTATED;
+ butPtr->flags &= ~TRISTATED;
if (valuePtr != NULL) {
const char *value = Tcl_GetString(valuePtr);
if (strcmp(value, Tcl_GetString(butPtr->onValuePtr)) == 0) {
butPtr->flags |= SELECTED;
} else if (strcmp(value,
- Tcl_GetString(butPtr->tristateValuePtr)) == 0) {
+ Tcl_GetString(butPtr->tristateValuePtr)) == 0) {
butPtr->flags |= TRISTATED;
/*
@@ -1148,7 +1176,7 @@ ConfigureButton(
Tcl_GetString(butPtr->offValuePtr)) == 0) {
butPtr->flags &= ~TRISTATED;
}
- }
+ }
} else {
if (Tcl_ObjSetVar2(interp, namePtr, NULL,
(butPtr->type == TYPE_CHECK_BUTTON)
@@ -1258,13 +1286,13 @@ ConfigureButton(
if (Tk_GetPixelsFromObj(interp, butPtr->tkwin, butPtr->widthPtr,
&butPtr->width) != TCL_OK) {
widthError:
- Tcl_AddErrorInfo(interp, "\n (processing -width option)");
+ Tcl_AddErrorInfo(interp, "\n (processing \"-width\" option)");
continue;
}
if (Tk_GetPixelsFromObj(interp, butPtr->tkwin, butPtr->heightPtr,
&butPtr->height) != TCL_OK) {
heightError:
- Tcl_AddErrorInfo(interp, "\n (processing -height option)");
+ Tcl_AddErrorInfo(interp, "\n (processing \"-height\" option)");
continue;
}
} else {
@@ -1463,6 +1491,7 @@ ButtonEventProc(
} else if (eventPtr->type == FocusIn) {
if (eventPtr->xfocus.detail != NotifyInferior) {
butPtr->flags |= GOT_FOCUS;
+ Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->highlightWidthPtr, &butPtr->highlightWidth);
if (butPtr->highlightWidth > 0) {
goto redraw;
}
@@ -1470,6 +1499,7 @@ ButtonEventProc(
} else if (eventPtr->type == FocusOut) {
if (eventPtr->xfocus.detail != NotifyInferior) {
butPtr->flags &= ~GOT_FOCUS;
+ Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->highlightWidthPtr, &butPtr->highlightWidth);
if (butPtr->highlightWidth > 0) {
goto redraw;
}
@@ -1656,7 +1686,7 @@ ButtonVarProc(
return NULL;
}
butPtr->flags |= SELECTED;
- butPtr->flags &= ~TRISTATED;
+ butPtr->flags &= ~TRISTATED;
} else if (butPtr->offValuePtr
&& strcmp(value, Tcl_GetString(butPtr->offValuePtr)) == 0) {
if (!(butPtr->flags & (SELECTED | TRISTATED))) {
@@ -1664,11 +1694,11 @@ ButtonVarProc(
}
butPtr->flags &= ~(SELECTED | TRISTATED);
} else if (strcmp(value, Tcl_GetString(butPtr->tristateValuePtr)) == 0) {
- if (butPtr->flags & TRISTATED) {
- return NULL;
- }
- butPtr->flags |= TRISTATED;
- butPtr->flags &= ~SELECTED;
+ if (butPtr->flags & TRISTATED) {
+ return NULL;
+ }
+ butPtr->flags |= TRISTATED;
+ butPtr->flags &= ~SELECTED;
} else if (butPtr->flags & (SELECTED | TRISTATED)) {
butPtr->flags &= ~(SELECTED | TRISTATED);
} else {
diff --git a/generic/tkImgGIF.c b/generic/tkImgGIF.c
index 9b70344..6368972 100644
--- a/generic/tkImgGIF.c
+++ b/generic/tkImgGIF.c
@@ -704,6 +704,7 @@ FileReadGIF(
}
if ((width > 0) && (height > 0)) {
+ unsigned char* pixelPtr;
Tk_PhotoImageBlock block;
int transparent = -1;
if (gifGraphicControlExtensionBlock.blockPresent) {
@@ -729,23 +730,25 @@ FileReadGIF(
goto error;
}
nBytes = block.pitch * imageHeight;
- block.pixelPtr = (unsigned char *)ckalloc(nBytes);
- if (block.pixelPtr) {
- memset(block.pixelPtr, 0, nBytes);
+ pixelPtr = (unsigned char*)ckalloc(nBytes);
+ if (pixelPtr) {
+ memset(pixelPtr, 0, nBytes);
}
+ block.pixelPtr = pixelPtr;
if (ReadImage(gifConfPtr, interp, block.pixelPtr, chan, imageWidth,
imageHeight, colorMap, srcX, srcY, BitSet(buf[8], INTERLACE),
transparent) != TCL_OK) {
- ckfree(block.pixelPtr);
+ ckfree(pixelPtr);
goto error;
}
+ block.pixelPtr += srcX * block.pixelSize + srcY * block.pitch;
if (Tk_PhotoPutBlock(interp, imageHandle, &block, destX, destY,
width, height, TK_PHOTO_COMPOSITE_SET) != TCL_OK) {
- ckfree(block.pixelPtr);
+ ckfree(pixelPtr);
goto error;
}
- ckfree(block.pixelPtr);
+ ckfree(pixelPtr);
}
/*
diff --git a/generic/tkImgPNG.c b/generic/tkImgPNG.c
index 5eb85a7..2879ae2 100644
--- a/generic/tkImgPNG.c
+++ b/generic/tkImgPNG.c
@@ -205,7 +205,8 @@ static void CleanupPNGImage(PNGImage *pngPtr);
static int DecodeLine(Tcl_Interp *interp, PNGImage *pngPtr);
static int DecodePNG(Tcl_Interp *interp, PNGImage *pngPtr,
Tcl_Obj *fmtObj, Tk_PhotoHandle imageHandle,
- int destX, int destY);
+ int destX, int destY, int width, int height,
+ int srcX, int srcY);
static int EncodePNG(Tcl_Interp *interp,
Tk_PhotoImageBlock *blockPtr, PNGImage *pngPtr,
Tcl_Obj *metadataInObj);
@@ -2476,14 +2477,19 @@ ParseFormat(
static int
DecodePNG(
- Tcl_Interp *interp,
- PNGImage *pngPtr,
- Tcl_Obj *fmtObj,
- Tk_PhotoHandle imageHandle,
- int destX,
- int destY)
+ Tcl_Interp *interp, /* Interpreter to use for reporting errors. */
+ PNGImage *pngPtr, /* PNG image information record. */
+ Tcl_Obj *fmtObj, /* User-specified format object, or NULL. */
+ Tk_PhotoHandle imageHandle, /* The photo image to write into. */
+ int destX, int destY, /* Coordinates of top-left pixel in photo
+ * image to be written to. */
+ int width, int height, /* Dimensions of block of photo image to be
+ * written to. */
+ int srcX, int srcY) /* Coordinates of top-left pixel to be used in
+ * image being read. */
{
unsigned long chunkType;
+ int result;
Tcl_Size chunkSz;
unsigned long crc;
@@ -2631,8 +2637,8 @@ DecodePNG(
* to negative here: Tk will not shrink the image.
*/
- if (Tk_PhotoExpand(interp, imageHandle, destX + pngPtr->block.width,
- destY + pngPtr->block.height) == TCL_ERROR) {
+ if (Tk_PhotoExpand(interp, imageHandle, destX + width,
+ destY + height) == TCL_ERROR) {
return TCL_ERROR;
}
@@ -2786,13 +2792,12 @@ DecodePNG(
* Copy the decoded image block into the Tk photo image.
*/
- if (Tk_PhotoPutBlock(interp, imageHandle, &pngPtr->block, destX, destY,
- pngPtr->block.width, pngPtr->block.height,
- TK_PHOTO_COMPOSITE_SET) == TCL_ERROR) {
- return TCL_ERROR;
- }
+ pngPtr->block.pixelPtr += srcX * pngPtr->block.pixelSize + srcY * pngPtr->block.pitch;
+ result = Tk_PhotoPutBlock(interp, imageHandle, &pngPtr->block, destX, destY,
+ width, height, TK_PHOTO_COMPOSITE_SET);
+ pngPtr->block.pixelPtr -= srcX * pngPtr->block.pixelSize + srcY * pngPtr->block.pitch;
- return TCL_OK;
+ return result;
}
/*
@@ -2862,21 +2867,19 @@ FileMatchPNG(
static int
FileReadPNG(
- Tcl_Interp *interp, /* Interpreter to use for reporting errors. */
+ Tcl_Interp* interp, /* Interpreter to use for reporting errors. */
Tcl_Channel chan, /* The image file, open for reading. */
- TCL_UNUSED(const char *), /* The name of the image file. */
+ TCL_UNUSED(const char*), /* The name of the image file. */
Tcl_Obj *fmtObj, /* User-specified format object, or NULL. */
- TCL_UNUSED(Tcl_Obj *), /* metadata input, may be NULL */
+ TCL_UNUSED(Tcl_Obj*), /* metadata input, may be NULL */
Tk_PhotoHandle imageHandle, /* The photo image to write into. */
int destX, int destY, /* Coordinates of top-left pixel in photo
* image to be written to. */
- TCL_UNUSED(int), /* Dimensions of block of photo image to be
+ int width, int height, /* Dimensions of block of photo image to be
* written to. */
- TCL_UNUSED(int),
- TCL_UNUSED(int), /* Coordinates of top-left pixel to be used in
+ int srcX, int srcY, /* Coordinates of top-left pixel to be used in
* image being read. */
- TCL_UNUSED(int),
- Tcl_Obj *metadataOutObj) /* metadata return dict, may be NULL */
+ Tcl_Obj* metadataOutObj) /* metadata return dict, may be NULL */
{
PNGImage png;
int result = TCL_ERROR;
@@ -2884,7 +2887,7 @@ FileReadPNG(
result = InitPNGImage(interp, &png, chan, NULL, TCL_ZLIB_STREAM_INFLATE);
if (TCL_OK == result) {
- result = DecodePNG(interp, &png, fmtObj, imageHandle, destX, destY);
+ result = DecodePNG(interp, &png, fmtObj, imageHandle, destX, destY, width, height, srcX, srcY);
}
if (TCL_OK == result && metadataOutObj != NULL && png.DPI != -1) {
@@ -2968,16 +2971,17 @@ StringMatchPNG(
static int
StringReadPNG(
- Tcl_Interp *interp, /* interpreter for reporting errors in */
- Tcl_Obj *pObjData, /* object containing the image */
- Tcl_Obj *fmtObj, /* format object, or NULL */
- TCL_UNUSED(Tcl_Obj *), /* metadata input, may be NULL */
- Tk_PhotoHandle imageHandle, /* the image to write this data into */
- int destX, int destY, /* The rectangular region of the */
- TCL_UNUSED(int), /* image to copy */
- TCL_UNUSED(int),
- TCL_UNUSED(int),
- TCL_UNUSED(int),
+ Tcl_Interp* interp, /* Interpreter to use for reporting errors. */
+ Tcl_Obj *pObjData,
+ Tcl_Obj *fmtObj, /* User-specified format object, or NULL. */
+ TCL_UNUSED(Tcl_Obj*), /* metadata input, may be NULL */
+ Tk_PhotoHandle imageHandle, /* The photo image to write into. */
+ int destX, int destY, /* Coordinates of top-left pixel in photo
+ * image to be written to. */
+ int width, int height, /* Dimensions of block of photo image to be
+ * written to. */
+ int srcX, int srcY, /* Coordinates of top-left pixel to be used in
+ * image being read. */
Tcl_Obj *metadataOutObj) /* metadata return dict, may be NULL */
{
PNGImage png;
@@ -2987,7 +2991,7 @@ StringReadPNG(
TCL_ZLIB_STREAM_INFLATE);
if (TCL_OK == result) {
- result = DecodePNG(interp, &png, fmtObj, imageHandle, destX, destY);
+ result = DecodePNG(interp, &png, fmtObj, imageHandle, destX, destY, width, height, srcX, srcY);
}
if (TCL_OK == result && metadataOutObj != NULL && png.DPI != -1) {
diff --git a/generic/tkInt.h b/generic/tkInt.h
index a216b17..c293306 100644
--- a/generic/tkInt.h
+++ b/generic/tkInt.h
@@ -917,8 +917,7 @@ typedef struct {
# ifndef XMaxTransChars
# define XMaxTransChars 7
# endif
- char trans_chars[XMaxTransChars];
- /* translated characters */
+ char trans_chars[XMaxTransChars]; /* translated characters */
unsigned char nbytes;
#elif !defined(MAC_OSX_TK)
char *charValuePtr; /* A pointer to a string that holds the key's
diff --git a/generic/tkMenubutton.c b/generic/tkMenubutton.c
index 3f1f4e7..0dd8396 100644
--- a/generic/tkMenubutton.c
+++ b/generic/tkMenubutton.c
@@ -570,13 +570,13 @@ ConfigureMenuButton(
if (Tk_GetPixels(interp, mbPtr->tkwin, mbPtr->widthString,
&mbPtr->width) != TCL_OK) {
widthError:
- Tcl_AddErrorInfo(interp, "\n (processing -width option)");
+ Tcl_AddErrorInfo(interp, "\n (processing \"-width\" option)");
continue;
}
if (Tk_GetPixels(interp, mbPtr->tkwin, mbPtr->heightString,
&mbPtr->height) != TCL_OK) {
heightError:
- Tcl_AddErrorInfo(interp, "\n (processing -height option)");
+ Tcl_AddErrorInfo(interp, "\n (processing \"-height\" option)");
continue;
}
} else {
diff --git a/generic/tkMessage.c b/generic/tkMessage.c
index ec44fcb..75caf7c 100644
--- a/generic/tkMessage.c
+++ b/generic/tkMessage.c
@@ -47,21 +47,20 @@ typedef struct {
Tk_3DBorder border; /* Structure used to draw 3-D border and
* background. NULL means a border hasn't been
* created yet. */
- 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
+ Tcl_Obj *highlightWidthObj; /* Width in pixels of highlight to draw
* around widget when it has the focus.
- * <= 0 means don't draw a highlight. */
+ * 0 means don't draw a highlight. */
XColor *highlightBgColorPtr;
/* Color for drawing traversal highlight
* area when highlight is off. */
XColor *highlightColorPtr; /* Color for drawing traversal highlight. */
Tk_Font tkfont; /* Information about text font, or NULL. */
XColor *fgColorPtr; /* Foreground color in normal mode. */
- Tcl_Obj *padXPtr, *padYPtr; /* Tcl_Obj rep's of padX, padY values. */
- int padX, padY; /* User-requested extra space around text. */
- int width; /* User-requested width, in pixels. 0 means
- * compute width using aspect ratio below. */
+ Tcl_Obj *padXObj, *padYObj; /* Tcl_Obj rep's of padX, padY values. */
+ Tcl_Obj *widthObj; /* User-requested width, in pixels. 0 means
+ * compute width using aspect ratio. */
int aspect; /* Desired aspect ratio for window
* (100*width/height). */
int msgWidth; /* Width in pixels needed to display
@@ -86,11 +85,6 @@ typedef struct {
* scripts. Malloc'ed, but may be NULL. */
int flags; /* Various flags; see below for
* definitions. */
- Tcl_Obj *borderWidthObj; /* Width of border. */
- Tcl_Obj *highlightWidthObj; /* Width in pixels of highlight to draw
- * around widget when it has the focus. <= 0 means don't draw a highlight. */
- Tcl_Obj *widthObj; /* User-requested width, in pixels. 0 means
- * compute width using aspect ratio. */
} Message;
/*
@@ -114,45 +108,45 @@ typedef struct {
static const Tk_OptionSpec optionSpecs[] = {
{TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor", DEF_MESSAGE_ANCHOR,
- TCL_INDEX_NONE, offsetof(Message, anchor), TK_OPTION_ENUM_VAR, 0, 0},
+ TCL_INDEX_NONE, offsetof(Message, anchor), TK_OPTION_ENUM_VAR, 0, 0},
{TK_OPTION_INT, "-aspect", "aspect", "Aspect", DEF_MESSAGE_ASPECT,
- TCL_INDEX_NONE, offsetof(Message, aspect), 0, 0, 0},
+ TCL_INDEX_NONE, offsetof(Message, aspect), 0, 0, 0},
{TK_OPTION_BORDER, "-background", "background", "Background",
- DEF_MESSAGE_BG_COLOR, TCL_INDEX_NONE, offsetof(Message, border), 0,
- DEF_MESSAGE_BG_MONO, 0},
+ DEF_MESSAGE_BG_COLOR, TCL_INDEX_NONE, offsetof(Message, border), 0,
+ DEF_MESSAGE_BG_MONO, 0},
{TK_OPTION_SYNONYM, "-bd", NULL, NULL, NULL,
- 0, TCL_INDEX_NONE, 0, "-borderwidth", 0},
+ 0, TCL_INDEX_NONE, 0, "-borderwidth", 0},
{TK_OPTION_SYNONYM, "-bg", NULL, NULL, NULL,
- 0, TCL_INDEX_NONE, 0, "-background", 0},
+ 0, TCL_INDEX_NONE, 0, "-background", 0},
{TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
- DEF_MESSAGE_BORDER_WIDTH, offsetof(Message, borderWidthObj),
- offsetof(Message, borderWidth), 0, 0, 0},
+ DEF_MESSAGE_BORDER_WIDTH, offsetof(Message, borderWidthObj),
+ TCL_INDEX_NONE, 0, 0, 0},
{TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor",
- DEF_MESSAGE_CURSOR, TCL_INDEX_NONE, offsetof(Message, cursor),
- TK_OPTION_NULL_OK, 0, 0},
+ DEF_MESSAGE_CURSOR, TCL_INDEX_NONE, offsetof(Message, cursor),
+ TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_SYNONYM, "-fg", NULL, NULL, NULL,
- 0, TCL_INDEX_NONE, 0, "-foreground", 0},
+ 0, TCL_INDEX_NONE, 0, "-foreground", 0},
{TK_OPTION_FONT, "-font", "font", "Font",
DEF_MESSAGE_FONT, TCL_INDEX_NONE, offsetof(Message, tkfont), 0, 0, 0},
{TK_OPTION_COLOR, "-foreground", "foreground", "Foreground",
DEF_MESSAGE_FG, TCL_INDEX_NONE, offsetof(Message, fgColorPtr), 0, 0, 0},
{TK_OPTION_COLOR, "-highlightbackground", "highlightBackground",
- "HighlightBackground", DEF_MESSAGE_HIGHLIGHT_BG, TCL_INDEX_NONE,
- offsetof(Message, highlightBgColorPtr), 0, 0, 0},
+ "HighlightBackground", DEF_MESSAGE_HIGHLIGHT_BG, TCL_INDEX_NONE,
+ offsetof(Message, highlightBgColorPtr), 0, 0, 0},
{TK_OPTION_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
- DEF_MESSAGE_HIGHLIGHT, TCL_INDEX_NONE, offsetof(Message, highlightColorPtr),
- 0, 0, 0},
+ DEF_MESSAGE_HIGHLIGHT, TCL_INDEX_NONE, offsetof(Message, highlightColorPtr),
+ 0, 0, 0},
{TK_OPTION_PIXELS, "-highlightthickness", "highlightThickness",
"HighlightThickness", DEF_MESSAGE_HIGHLIGHT_WIDTH, offsetof(Message, highlightWidthObj),
- offsetof(Message, highlightWidth), 0, 0, 0},
+ TCL_INDEX_NONE, 0, 0, 0},
{TK_OPTION_JUSTIFY, "-justify", "justify", "Justify",
DEF_MESSAGE_JUSTIFY, TCL_INDEX_NONE, offsetof(Message, justify), TK_OPTION_ENUM_VAR, 0, 0},
{TK_OPTION_PIXELS, "-padx", "padX", "Pad",
- DEF_MESSAGE_PADX, offsetof(Message, padXPtr),
- offsetof(Message, padX), TK_OPTION_NULL_OK, 0, 0},
+ DEF_MESSAGE_PADX, offsetof(Message, padXObj),
+ TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_PIXELS, "-pady", "padY", "Pad",
- DEF_MESSAGE_PADY, offsetof(Message, padYPtr),
- offsetof(Message, padY), TK_OPTION_NULL_OK, 0, 0},
+ DEF_MESSAGE_PADY, offsetof(Message, padYObj),
+ TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_RELIEF, "-relief", "relief", "Relief",
DEF_MESSAGE_RELIEF, TCL_INDEX_NONE, offsetof(Message, relief), 0, 0, 0},
{TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus",
@@ -164,7 +158,7 @@ static const Tk_OptionSpec optionSpecs[] = {
DEF_MESSAGE_TEXT_VARIABLE, TCL_INDEX_NONE, offsetof(Message, textVarName),
TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_PIXELS, "-width", "width", "Width",
- DEF_MESSAGE_WIDTH, offsetof(Message, widthObj), offsetof(Message, width), 0, 0 ,0},
+ DEF_MESSAGE_WIDTH, offsetof(Message, widthObj), TCL_INDEX_NONE, 0, 0 ,0},
{TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0}
};
@@ -447,6 +441,7 @@ ConfigureMessage(
TCL_UNUSED(int)) /* Flags to pass to Tk_ConfigureWidget. */
{
Tk_SavedOptions savedOptions;
+ int width, borderWidth, highlightWidth, padX, padY;
/*
* Eliminate any existing trace on a variable monitored by the message.
@@ -496,8 +491,43 @@ ConfigureMessage(
msgPtr->numChars = Tcl_NumUtfChars(msgPtr->string, TCL_INDEX_NONE);
- if (msgPtr->highlightWidth < 0) {
- msgPtr->highlightWidth = 0;
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->widthObj, &width);
+ if (width < 0) {
+ if (msgPtr->widthObj) {
+ Tcl_DecrRefCount(msgPtr->widthObj);
+ }
+ msgPtr->widthObj = Tcl_NewIntObj(0);
+ Tcl_IncrRefCount(msgPtr->widthObj);
+ }
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->borderWidthObj, &borderWidth);
+ if (borderWidth < 0) {
+ if (msgPtr->borderWidthObj) {
+ Tcl_DecrRefCount(msgPtr->borderWidthObj);
+ }
+ msgPtr->borderWidthObj = Tcl_NewIntObj(0);
+ Tcl_IncrRefCount(msgPtr->borderWidthObj);
+ }
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->highlightWidthObj, &highlightWidth);
+ if (highlightWidth < 0) {
+ if (msgPtr->highlightWidthObj) {
+ Tcl_DecrRefCount(msgPtr->highlightWidthObj);
+ }
+ msgPtr->highlightWidthObj = Tcl_NewIntObj(0);
+ Tcl_IncrRefCount(msgPtr->highlightWidthObj);
+ }
+ if (msgPtr->padXObj) {
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->padXObj, &padX);
+ if (padX < 0) {
+ Tcl_DecrRefCount(msgPtr->padXObj);
+ msgPtr->padXObj = NULL;
+ }
+ }
+ if (msgPtr->padYObj) {
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->padYObj, &padY);
+ if (padY < 0) {
+ Tcl_DecrRefCount(msgPtr->padYObj);
+ msgPtr->padYObj = NULL;
+ }
}
Tk_FreeSavedOptions(&savedOptions);
@@ -529,7 +559,6 @@ MessageWorldChanged(
{
XGCValues gcValues;
GC gc = NULL;
- Tk_FontMetrics fm;
Message *msgPtr = (Message *)instanceData;
if (msgPtr->border != NULL) {
@@ -544,14 +573,6 @@ MessageWorldChanged(
}
msgPtr->textGC = gc;
- Tk_GetFontMetrics(msgPtr->tkfont, &fm);
- if (msgPtr->padX < 0) {
- msgPtr->padX = fm.ascent / 2;
- }
- if (msgPtr->padY < 0) {
- msgPtr->padY = fm.ascent / 4;
- }
-
/*
* Recompute the desired geometry for the window, and arrange for the
* window to be redisplayed.
@@ -590,10 +611,26 @@ ComputeMessageGeometry(
int width, inc, height;
int thisWidth, thisHeight, maxWidth;
int aspect, lowerBound, upperBound, inset;
+ int borderWidth, highlightWidth, padX, padY;
+ Tk_FontMetrics fm;
Tk_FreeTextLayout(msgPtr->textLayout);
- inset = msgPtr->borderWidth + msgPtr->highlightWidth;
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->borderWidthObj, &borderWidth);
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->highlightWidthObj, &highlightWidth);
+ Tk_GetFontMetrics(msgPtr->tkfont, &fm);
+ if (msgPtr->padXObj) {
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->padXObj, &padX);
+ } else {
+ padX = fm.ascent / 2;
+ }
+ if (msgPtr->padYObj) {
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->padYObj, &padY);
+ } else {
+ padY = fm.ascent / 4;
+ }
+
+ inset = borderWidth + highlightWidth;
/*
* Compute acceptable bounds for the final aspect ratio.
@@ -614,8 +651,8 @@ ComputeMessageGeometry(
* explicit width then just use that.
*/
- if (msgPtr->width > 0) {
- width = msgPtr->width;
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->widthObj, &width);
+ if (width > 0) {
inc = 0;
} else {
width = WidthOfScreen(Tk_Screen(msgPtr->tkwin))/2;
@@ -626,8 +663,8 @@ ComputeMessageGeometry(
msgPtr->textLayout = Tk_ComputeTextLayout(msgPtr->tkfont,
msgPtr->string, msgPtr->numChars, width, msgPtr->justify,
0, &thisWidth, &thisHeight);
- maxWidth = thisWidth + 2 * (inset + msgPtr->padX);
- height = thisHeight + 2 * (inset + msgPtr->padY);
+ maxWidth = thisWidth + 2 * (inset + padX);
+ height = thisHeight + 2 * (inset + padY);
if (inc <= 2) {
break;
@@ -672,22 +709,38 @@ DisplayMessage(
Message *msgPtr = (Message *)clientData;
Tk_Window tkwin = msgPtr->tkwin;
int x, y;
- int borderWidth = msgPtr->highlightWidth;
+ int width, borderWidth, highlightWidth, padX, padY;
+ Tk_FontMetrics fm;
+
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->borderWidthObj, &borderWidth);
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->highlightWidthObj, &highlightWidth);
+ Tk_GetFontMetrics(msgPtr->tkfont, &fm);
+ if (msgPtr->padXObj) {
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->padXObj, &padX);
+ } else {
+ padX = fm.ascent / 2;
+ }
+ if (msgPtr->padYObj) {
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->padYObj, &padY);
+ } else {
+ padY = fm.ascent / 4;
+ }
+ width = highlightWidth;
msgPtr->flags &= ~REDRAW_PENDING;
if ((msgPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
return;
}
if (msgPtr->border != NULL) {
- borderWidth += msgPtr->borderWidth;
+ width += borderWidth;
}
if (msgPtr->relief == TK_RELIEF_FLAT) {
- borderWidth = msgPtr->highlightWidth;
+ width = highlightWidth;
}
Tk_Fill3DRectangle(tkwin, Tk_WindowId(tkwin), msgPtr->border,
- borderWidth, borderWidth,
- Tk_Width(tkwin) - 2 * borderWidth,
- Tk_Height(tkwin) - 2 * borderWidth,
+ width, width,
+ Tk_Width(tkwin) - 2 * width,
+ Tk_Height(tkwin) - 2 * width,
0, TK_RELIEF_FLAT);
/*
@@ -695,28 +748,28 @@ DisplayMessage(
* anchor option.
*/
- TkComputeAnchor(msgPtr->anchor, tkwin, msgPtr->padX, msgPtr->padY,
+ TkComputeAnchor(msgPtr->anchor, tkwin, padX, padY,
msgPtr->msgWidth, msgPtr->msgHeight, &x, &y);
Tk_DrawTextLayout(Tk_Display(tkwin), Tk_WindowId(tkwin), msgPtr->textGC,
msgPtr->textLayout, x, y, 0, -1);
- if (borderWidth > msgPtr->highlightWidth) {
+ if (width > highlightWidth) {
Tk_Draw3DRectangle(tkwin, Tk_WindowId(tkwin), msgPtr->border,
- msgPtr->highlightWidth, msgPtr->highlightWidth,
- Tk_Width(tkwin) - 2*msgPtr->highlightWidth,
- Tk_Height(tkwin) - 2*msgPtr->highlightWidth,
- msgPtr->borderWidth, msgPtr->relief);
+ highlightWidth, highlightWidth,
+ Tk_Width(tkwin) - 2 * highlightWidth,
+ Tk_Height(tkwin) - 2 * highlightWidth,
+ borderWidth, msgPtr->relief);
}
- if (msgPtr->highlightWidth != 0) {
+ if (highlightWidth > 0) {
GC fgGC, bgGC;
bgGC = Tk_GCForColor(msgPtr->highlightBgColorPtr, Tk_WindowId(tkwin));
if (msgPtr->flags & GOT_FOCUS) {
fgGC = Tk_GCForColor(msgPtr->highlightColorPtr,Tk_WindowId(tkwin));
- Tk_DrawHighlightBorder(tkwin, fgGC, bgGC, msgPtr->highlightWidth,
+ Tk_DrawHighlightBorder(tkwin, fgGC, bgGC, highlightWidth,
Tk_WindowId(tkwin));
} else {
- Tk_DrawHighlightBorder(tkwin, bgGC, bgGC, msgPtr->highlightWidth,
+ Tk_DrawHighlightBorder(tkwin, bgGC, bgGC, highlightWidth,
Tk_WindowId(tkwin));
}
}
@@ -746,6 +799,7 @@ MessageEventProc(
XEvent *eventPtr) /* Information about event. */
{
Message *msgPtr = (Message *)clientData;
+ int highlightWidth;
if (((eventPtr->type == Expose) && (eventPtr->xexpose.count == 0))
|| (eventPtr->type == ConfigureNotify)) {
@@ -755,14 +809,16 @@ MessageEventProc(
} else if (eventPtr->type == FocusIn) {
if (eventPtr->xfocus.detail != NotifyInferior) {
msgPtr->flags |= GOT_FOCUS;
- if (msgPtr->highlightWidth > 0) {
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->highlightWidthObj, &highlightWidth);
+ if (highlightWidth > 0) {
goto redraw;
}
}
} else if (eventPtr->type == FocusOut) {
if (eventPtr->xfocus.detail != NotifyInferior) {
msgPtr->flags &= ~GOT_FOCUS;
- if (msgPtr->highlightWidth > 0) {
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->highlightWidthObj, &highlightWidth);
+ if (highlightWidth > 0) {
goto redraw;
}
}
@@ -846,27 +902,27 @@ MessageTextVarProc(
*/
if (flags & TCL_TRACE_UNSETS) {
- if (!Tcl_InterpDeleted(interp) && msgPtr->textVarName) {
- void *probe = NULL;
-
- do {
- probe = Tcl_VarTraceInfo(interp,
- msgPtr->textVarName,
- TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
- MessageTextVarProc, probe);
- if (probe == (void *)msgPtr) {
- break;
- }
- } while (probe);
- if (probe) {
- /*
- * We were able to fetch the unset trace for our
- * textVarName, which means it is not unset and not
- * the cause of this unset trace. Instead some outdated
- * former variable must be, and we should ignore it.
- */
- return NULL;
- }
+ if (!Tcl_InterpDeleted(interp) && msgPtr->textVarName) {
+ void *probe = NULL;
+
+ do {
+ probe = Tcl_VarTraceInfo(interp,
+ msgPtr->textVarName,
+ TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
+ MessageTextVarProc, probe);
+ if (probe == (void *)msgPtr) {
+ break;
+ }
+ } while (probe);
+ if (probe) {
+ /*
+ * We were able to fetch the unset trace for our
+ * textVarName, which means it is not unset and not
+ * the cause of this unset trace. Instead some outdated
+ * former variable must be, and we should ignore it.
+ */
+ return NULL;
+ }
Tcl_SetVar2(interp, msgPtr->textVarName, NULL, msgPtr->string,
TCL_GLOBAL_ONLY);
Tcl_TraceVar2(interp, msgPtr->textVarName, NULL,
diff --git a/generic/tkText.h b/generic/tkText.h
index 0ccced2..e29a8ac 100644
--- a/generic/tkText.h
+++ b/generic/tkText.h
@@ -172,9 +172,12 @@ typedef struct TkTextSegment {
Tcl_Size size; /* Size of this segment (# of bytes of index
* space it occupies). */
union {
- char chars[4]; /* Characters that make up character info.
- * Actual length varies to hold as many
- * characters as needed.*/
+ /* The TKFLEXARRAY macro - unfortunately - doesn't work inside a union. */
+#if defined(__GNUC__) && (__GNUC__ > 2)
+ char chars[0]; /* Characters that make up character info. */
+#else /* Actual length varies to hold as many */
+ char chars[1]; /* characters as needed. See [dacd18294b] */
+#endif
TkTextToggle toggle; /* Information about tag toggle. */
TkTextMark mark; /* Information about mark. */
TkTextEmbWindow ew; /* Information about embedded window. */