summaryrefslogtreecommitdiffstats
path: root/unix
diff options
context:
space:
mode:
authorgcramer <remarcg@gmx.net>2017-05-18 08:04:32 (GMT)
committergcramer <remarcg@gmx.net>2017-05-18 08:04:32 (GMT)
commit85b3b044c826c3239a2d6e5d5b7e1489f9ece5ee (patch)
tree41c7d3f18c4a545037e39964ba5a0cedcb6537b9 /unix
parentc257b74035bb102d5860b77c9484c8e7e5ee833c (diff)
parentddf5e6ae8f6240fdbee22b4db0c3a5a8575bd7f1 (diff)
downloadtk-85b3b044c826c3239a2d6e5d5b7e1489f9ece5ee.zip
tk-85b3b044c826c3239a2d6e5d5b7e1489f9ece5ee.tar.gz
tk-85b3b044c826c3239a2d6e5d5b7e1489f9ece5ee.tar.bz2
Fixed bug [2433781fff]
Diffstat (limited to 'unix')
-rw-r--r--unix/tkUnixButton.c81
1 files changed, 44 insertions, 37 deletions
diff --git a/unix/tkUnixButton.c b/unix/tkUnixButton.c
index 1aeefac..6a99124 100644
--- a/unix/tkUnixButton.c
+++ b/unix/tkUnixButton.c
@@ -351,6 +351,47 @@ TkpCreateButton(
*----------------------------------------------------------------------
*/
+static void
+ShiftByOffset(
+ TkButton *butPtr,
+ int relief,
+ int *x, /* shift this x coordinate */
+ int *y, /* shift this y coordinate */
+ int width, /* width of image/text */
+ int height) /* height of image/text */
+{
+ if (relief != TK_RELIEF_RAISED
+ && butPtr->type == TYPE_BUTTON
+ && !Tk_StrictMotif(butPtr->tkwin)) {
+ int shiftX;
+ int shiftY;
+
+ /*
+ * This is an (unraised) button widget, so we offset the text to make
+ * the button appear to move up and down as the relief changes.
+ */
+
+ shiftX = shiftY = (relief == TK_RELIEF_SUNKEN) ? 2 : 1;
+
+ if (relief != TK_RELIEF_RIDGE) {
+ /*
+ * Take back one pixel if the padding is even, otherwise the
+ * content will be displayed too far right/down.
+ */
+
+ if ((Tk_Width(butPtr->tkwin) - width) % 2 == 0) {
+ shiftX -= 1;
+ }
+ if ((Tk_Height(butPtr->tkwin) - height) % 2 == 0) {
+ shiftY -= 1;
+ }
+ }
+
+ *x += shiftX;
+ *y += shiftY;
+ }
+}
+
void
TkpDisplayButton(
ClientData clientData) /* Information about widget. */
@@ -366,10 +407,6 @@ TkpDisplayButton(
int width = 0, height = 0, fullWidth, fullHeight;
int textXOffset, textYOffset;
int haveImage = 0, haveText = 0;
- int offset; /* 1 means this is a button widget, so we
- * offset the text to make the button appear
- * to move up and down as the relief
- * changes. */
int imageWidth, imageHeight;
int imageXOffset = 0, imageYOffset = 0;
/* image information that will be used to
@@ -432,8 +469,6 @@ TkpDisplayButton(
}
}
- offset = (butPtr->type == TYPE_BUTTON) && !Tk_StrictMotif(butPtr->tkwin);
-
/*
* In order to avoid screen flashes, this function redraws the button in a
* pixmap, then copies the pixmap to the screen in a single operation.
@@ -525,17 +560,7 @@ TkpDisplayButton(
butPtr->indicatorSpace + fullWidth, fullHeight, &x, &y);
x += butPtr->indicatorSpace;
-
- x += offset;
- y += offset;
- if (relief == TK_RELIEF_RAISED) {
- x -= offset;
- y -= offset;
- } else if (relief == TK_RELIEF_SUNKEN) {
- x += offset;
- y += offset;
- }
-
+ ShiftByOffset(butPtr, relief, &x, &y, width, height);
imageXOffset += x;
imageYOffset += y;
@@ -593,16 +618,7 @@ TkpDisplayButton(
TkComputeAnchor(butPtr->anchor, tkwin, 0, 0,
butPtr->indicatorSpace + width, height, &x, &y);
x += butPtr->indicatorSpace;
-
- x += offset;
- y += offset;
- if (relief == TK_RELIEF_RAISED) {
- x -= offset;
- y -= offset;
- } else if (relief == TK_RELIEF_SUNKEN) {
- x += offset;
- y += offset;
- }
+ ShiftByOffset(butPtr, relief, &x, &y, width, height);
imageXOffset += x;
imageYOffset += y;
if (butPtr->image != NULL) {
@@ -655,16 +671,7 @@ TkpDisplayButton(
butPtr->textHeight, &x, &y);
x += butPtr->indicatorSpace;
-
- x += offset;
- y += offset;
- if (relief == TK_RELIEF_RAISED) {
- x -= offset;
- y -= offset;
- } else if (relief == TK_RELIEF_SUNKEN) {
- x += offset;
- y += offset;
- }
+ ShiftByOffset(butPtr, relief, &x, &y, width, height);
Tk_DrawTextLayout(butPtr->display, pixmap, gc, butPtr->textLayout,
x, y, 0, -1);
Tk_UnderlineTextLayout(butPtr->display, pixmap, gc,