summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorculler <culler>2019-01-18 18:05:15 (GMT)
committerculler <culler>2019-01-18 18:05:15 (GMT)
commit93e3655d5f1cab943b7ba36ee59f2b44f36f6553 (patch)
tree1246fa6d1307ac684ac8d80fa3b58d7ca31ac75b
parent5cb97cd301ec4db2dde21a900ddf3593b5998aeb (diff)
parentbf838a24f35ee704ccdc9b8538c32a1559f4c3e7 (diff)
downloadtk-93e3655d5f1cab943b7ba36ee59f2b44f36f6553.zip
tk-93e3655d5f1cab943b7ba36ee59f2b44f36f6553.tar.gz
tk-93e3655d5f1cab943b7ba36ee59f2b44f36f6553.tar.bz2
Clean up Aqua button geometry code so unixButton tests pass, and make
a few small adjustments to the appearance.
-rw-r--r--library/demos/puzzle.tcl2
-rw-r--r--macosx/tkMacOSXButton.c144
-rw-r--r--tests/unixButton.test24
3 files changed, 76 insertions, 94 deletions
diff --git a/library/demos/puzzle.tcl b/library/demos/puzzle.tcl
index 4f7f955..eebe87a 100644
--- a/library/demos/puzzle.tcl
+++ b/library/demos/puzzle.tcl
@@ -73,7 +73,7 @@ for {set i 0} {$i < 15} {set i [expr {$i+1}]} {
set num [lindex $order $i]
set xpos($num) [expr {($i%4)*.25}]
set ypos($num) [expr {($i/4)*.25}]
- button $w.frame.$num -relief raised -text $num -highlightthickness 0 \
+ button $w.frame.$num -relief raised -text $num -bd 0 -highlightthickness 0 \
-command "puzzleSwitch $w $num"
place $w.frame.$num -relx $xpos($num) -rely $ypos($num) \
-relwidth .25 -relheight .25
diff --git a/macosx/tkMacOSXButton.c b/macosx/tkMacOSXButton.c
index ea78d43..c0b83f2 100644
--- a/macosx/tkMacOSXButton.c
+++ b/macosx/tkMacOSXButton.c
@@ -29,19 +29,10 @@
* be allowed when drawing the HITheme button.
*/
-#define HI_PADX 2
+#define HI_PADX 14
#define HI_PADY 1
/*
- * Some defines used to control what type of control is drawn.
- */
-
-#define DRAW_LABEL 0 /* Labels are treated genericly. */
-#define DRAW_CONTROL 1 /* Draw using the Native control. */
-#define DRAW_CUSTOM 2 /* Make our own button drawing. */
-#define DRAW_BEVEL 3
-
-/*
* The delay in milliseconds between pulsing default button redraws.
*/
#define PULSE_TIMER_MSECS 62 /* Largest value that didn't look stuttery */
@@ -52,7 +43,6 @@
typedef struct {
- int drawType;
Tk_3DBorder border;
int relief;
int offset; /* 0 means this is a normal widget. 1 means
@@ -271,11 +261,7 @@ TkpComputeButtonGeometry(
int txtWidth = 0, txtHeight = 0;
MacButton *mbPtr = (MacButton*)butPtr;
Tk_FontMetrics fm;
- DrawParams drawParams;
-
- /*
- * First figure out the size of the contents of the button.
- */
+ char *text = Tcl_GetString(butPtr->textPtr);
TkMacOSXComputeButtonParams(butPtr, &mbPtr->btnkind, &mbPtr->drawinfo);
@@ -283,7 +269,7 @@ TkpComputeButtonGeometry(
* If the indicator is on, get its size.
*/
- if ( butPtr->indicatorOn ) {
+ if (butPtr->indicatorOn) {
switch (butPtr->type) {
case TYPE_RADIO_BUTTON:
GetThemeMetric(kThemeMetricRadioButtonWidth, (SInt32 *)&butPtr->indicatorDiameter);
@@ -309,23 +295,22 @@ TkpComputeButtonGeometry(
haveImage = 1;
}
- if (haveImage == 0 || butPtr->compound != COMPOUND_NONE) {
+ if (strlen(text) > 0) {
Tk_FreeTextLayout(butPtr->textLayout);
butPtr->textLayout = Tk_ComputeTextLayout(butPtr->tkfont,
Tcl_GetString(butPtr->textPtr), -1, butPtr->wrapLength,
butPtr->justify, 0, &butPtr->textWidth, &butPtr->textHeight);
- txtWidth = butPtr->textWidth;
- txtHeight = butPtr->textHeight;
- charWidth = Tk_TextWidth(butPtr->tkfont, "0", 1);
- Tk_GetFontMetrics(butPtr->tkfont, &fm);
- haveText = (txtWidth != 0 && txtHeight != 0);
+ txtWidth = butPtr->textWidth + 2*butPtr->padX;
+ txtHeight = butPtr->textHeight + 2*butPtr->padY;
+ haveText = 1;
}
if (haveImage && haveText) { /* Image and Text */
switch ((enum compound) butPtr->compound) {
case COMPOUND_TOP:
case COMPOUND_BOTTOM:
+
/*
* Image is above or below text.
*/
@@ -335,14 +320,16 @@ TkpComputeButtonGeometry(
break;
case COMPOUND_LEFT:
case COMPOUND_RIGHT:
+
/*
* Image is left or right of text.
*/
- width += txtWidth + butPtr->padX;
+ width += txtWidth + 2*butPtr->padX;
height = (height > txtHeight ? height : txtHeight);
break;
case COMPOUND_CENTER:
+
/*
* Image and text are superimposed.
*/
@@ -354,26 +341,27 @@ TkpComputeButtonGeometry(
break;
}
width += butPtr->indicatorSpace;
-
} else if (haveImage) { /* Image only */
- width = butPtr->width > 0 ? butPtr->width : width + butPtr->indicatorSpace;
- height = butPtr->height > 0 ? butPtr->height : height;
-
+ width = butPtr->width > 0 ? butPtr->width : width + butPtr->indicatorSpace;
+ height = butPtr->height > 0 ? butPtr->height : height;
+ if (butPtr->type == TYPE_BUTTON) {
+ /* Allow room to shift the image. */
+ width += 2;
+ height += 2;
+ }
} else { /* Text only */
width = txtWidth + butPtr->indicatorSpace;
height = txtHeight;
if (butPtr->width > 0) {
- width = butPtr->width * charWidth;
+ charWidth = Tk_TextWidth(butPtr->tkfont, "0", 1);
+ width = butPtr->width * charWidth + 2*butPtr->padX;
}
if (butPtr->height > 0) {
- height = butPtr->height * fm.linespace;
+ Tk_GetFontMetrics(butPtr->tkfont, &fm);
+ height = butPtr->height * fm.linespace + 2*butPtr->padY;
}
}
- /* Add padding */
- width += 2 * butPtr->padX;
- height += 2 * butPtr->padY;
-
/*
* Now figure out the size of the border decorations for the button.
*/
@@ -382,48 +370,35 @@ TkpComputeButtonGeometry(
butPtr->highlightWidth = 0;
}
- butPtr->inset = 0;
- butPtr->inset += butPtr->highlightWidth;
+ butPtr->inset = butPtr->borderWidth + butPtr->highlightWidth;
- if (TkMacOSXComputeButtonDrawParams(butPtr,&drawParams)) {
+ width += butPtr->inset*2;
+ height += butPtr->inset*2;
+ if ([NSApp macMinorVersion] == 6) {
+ width += 12;
+ }
+ if (mbPtr->btnkind == kThemePushButton) {
HIRect tmpRect;
HIRect contBounds;
- int paddingx = 0;
- int paddingy = 0;
+ /*
+ * A PushButton has a minimum size. We make sure that we
+ * are not underestimating the size by requesting the content
+ * size of a Pushbutton whose overall size is our content size
+ * expanded by the standard padding.
+ */
+
tmpRect = CGRectMake(0, 0, width + 2*HI_PADX, height + 2*HI_PADY);
-
HIThemeGetButtonContentBounds(&tmpRect, &mbPtr->drawinfo, &contBounds);
- /* If the content region has a minimum height, match it. */
if (height < contBounds.size.height) {
- height = contBounds.size.height;
+ height = contBounds.size.height;
}
-
- /* If the content region has a minimum width, match it. */
if (width < contBounds.size.width) {
- width = contBounds.size.width;
+ width = contBounds.size.width;
}
-
- /* Pad to fill difference between content bounds and button bounds. */
- paddingx = contBounds.origin.x;
- paddingy = contBounds.origin.y;
-
- if (height < paddingx - 4) {
- /* can't have buttons much shorter than button side diameter. */
- height = paddingx - 4;
- }
-
- } else {
- height += butPtr->borderWidth*2;
- width += butPtr->borderWidth*2;
- }
-
- width += butPtr->inset*2;
- height += butPtr->inset*2;
- if ([NSApp macMinorVersion] == 6) {
- width += 12;
+ height += 2*HI_PADY;
+ width += 2*HI_PADX;
}
-
Tk_GeometryRequest(butPtr->tkwin, width, height);
Tk_SetInternalBorder(butPtr->tkwin, butPtr->inset);
}
@@ -570,7 +545,6 @@ DrawButtonImageAndText(
}
imageXOffset += x;
imageYOffset += y;
- textYOffset -= 1;
if (butPtr->image != NULL) {
if ((butPtr->selectImage != NULL) &&
@@ -594,6 +568,7 @@ DrawButtonImageAndText(
XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0);
}
+ y += 1; /* Tweak to match native buttons. */
Tk_DrawTextLayout(butPtr->display, pixmap,
dpPtr->gc, butPtr->textLayout,
x + textXOffset, y + textYOffset, 0, -1);
@@ -646,6 +621,7 @@ DrawButtonImageAndText(
butPtr->textWidth + butPtr->indicatorSpace,
butPtr->textHeight, &x, &y);
x += butPtr->indicatorSpace;
+ y += 1; /* Tweak to match native buttons */
Tk_DrawTextLayout(butPtr->display, pixmap, dpPtr->gc, butPtr->textLayout,
x, y, 0, -1);
}
@@ -1119,7 +1095,6 @@ TkMacOSXComputeButtonDrawParams(
}
}
-
dpPtr->border = butPtr->normalBorder;
if ((butPtr->state == STATE_DISABLED) && (butPtr->disabledFg != NULL)) {
dpPtr->gc = butPtr->disabledGC;
@@ -1149,29 +1124,22 @@ TkMacOSXComputeButtonDrawParams(
}
}
- /*
- * Determine the draw type
- */
-
- if (butPtr->type == TYPE_LABEL) {
- dpPtr->drawType = DRAW_LABEL;
- } else if (butPtr->type == TYPE_BUTTON) {
- if (!dpPtr->hasImageOrBitmap) {
- dpPtr->drawType = DRAW_CONTROL;
- } else {
- dpPtr->drawType = DRAW_BEVEL;
- }
- } else if (butPtr->indicatorOn) {
- dpPtr->drawType = DRAW_CONTROL;
- } else if (dpPtr->hasImageOrBitmap) {
- dpPtr->drawType = DRAW_BEVEL;
- } else {
- dpPtr->drawType = DRAW_CUSTOM;
- }
-
- if ((dpPtr->drawType == DRAW_CONTROL) || (dpPtr->drawType == DRAW_BEVEL)) {
+ if (butPtr->type != TYPE_LABEL &&
+ (butPtr->type == TYPE_BUTTON ||
+ butPtr->indicatorOn ||
+ dpPtr->hasImageOrBitmap)) {
+
+ /*
+ * Draw this widget as a native control.
+ */
+
return 1;
} else {
+
+ /*
+ * Draw this widget from scratch.
+ */
+
return 0;
}
}
diff --git a/tests/unixButton.test b/tests/unixButton.test
index 137ef33..c7b7b1d 100644
--- a/tests/unixButton.test
+++ b/tests/unixButton.test
@@ -35,7 +35,15 @@ proc bogusTrace args {
error "trace aborted"
}
-
+if {[tk windowingsystem] eq "aqua"} {
+ set smallIndicator 20
+ set bigIndicator 20
+ set defaultBorder 10
+} else {
+ set smallIndicator 27
+ set bigindicator 40
+ set defaultBorder 20
+}
test unixbutton-1.1 {TkpComputeButtonGeometry procedure} -constraints {
unix testImageType
} -setup {
@@ -57,7 +65,10 @@ test unixbutton-1.1 {TkpComputeButtonGeometry procedure} -constraints {
} -cleanup {
deleteWindows
image delete image1
-} -result {68 48 74 54 112 52 112 52}
+} -result [list 68 48 \
+ 74 54 \
+ [expr {72 + $bigIndicator}] 52 \
+ [expr {72 + $bigIndicator}] 52]
test unixbutton-1.2 {TkpComputeButtonGeometry procedure} -constraints {
unix
} -setup {
@@ -75,7 +86,10 @@ test unixbutton-1.2 {TkpComputeButtonGeometry procedure} -constraints {
[winfo reqwidth .b4] [winfo reqheight .b4]
} -cleanup {
deleteWindows
-} -result {23 33 29 39 54 37 54 37}
+} -result [list 23 33 \
+ 29 39 \
+ [expr {27 + $smallIndicator}] 37 \
+ [expr {27 + $smallIndicator}] 37]
test unixbutton-1.3 {TkpComputeButtonGeometry procedure} -constraints {
unix
} -setup {
@@ -186,7 +200,7 @@ test unixbutton-1.9 {TkpComputeButtonGeometry procedure} -constraints {
list [winfo reqwidth .b2] [winfo reqheight .b2]
} -cleanup {
deleteWindows
-} -result {37 47}
+} -result [list [expr {17 + $defaultBorder}] [expr {27 + $defaultBorder}]]
test unixbutton-1.10 {TkpComputeButtonGeometry procedure} -constraints {
unix
} -setup {
@@ -196,7 +210,7 @@ test unixbutton-1.10 {TkpComputeButtonGeometry procedure} -constraints {
list [winfo reqwidth .b2] [winfo reqheight .b2]
} -cleanup {
deleteWindows
-} -result {37 47}
+} -result [list [expr {17 + $defaultBorder}] [expr {27 + $defaultBorder}]]
test unixbutton-1.11 {TkpComputeButtonGeometry procedure} -constraints {
unix
} -setup {