From 013e787609043566d56a742e5fd5c12a95128e6d Mon Sep 17 00:00:00 2001
From: culler <culler>
Date: Fri, 29 Mar 2019 21:38:08 +0000
Subject: Fix bug [1001070]: Aqua labels do not display highlight background.

---
 macosx/tkMacOSXButton.c | 34 +++++++++++++++++++++++++++++++---
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/macosx/tkMacOSXButton.c b/macosx/tkMacOSXButton.c
index 484dcf2..705b214 100644
--- a/macosx/tkMacOSXButton.c
+++ b/macosx/tkMacOSXButton.c
@@ -67,9 +67,28 @@ typedef struct {
 } MacButton;
 
 /*
- * Forward declarations for procedures defined later in this file:
+ * When drawing highlight borders for Buttons or Labels, the function
+ * Tk_Draw3DRectangle is called with SOLID relief.  This in turn calls the
+ * stubs Tk_3DVerticalBevel and Tk_3DHorizontalBevel. The Mac port does not
+ * define these stubs itself, but instead uses the ones defined in tkUnix3d.c,
+ * which gets compiled and linked into the Mac Tk library.  One of the
+ * arguments to these stubs is a pointer to a UnixBorder struct, which is an
+ * extension of TkBorder containing one additional field which is a graphics
+ * context to be used when drawing the bevels.  The UnixBorder is declared in
+ * the file tkUnix3d.c and not in any header file.  We include the declaration
+ * here, so that we can draw highlight borders.  But this declaration must be
+ * kept in sync with the one in tkUnix3d.c.
  */
 
+#include "tk3d.h"
+typedef struct {
+    TkBorder info;
+    GC solidGC;         /* Used to draw solid relief. */
+} UnixBorder;
+
+/*
+ * Forward declarations for procedures defined later in this file:
+ */
 
 static void ButtonBackgroundDrawCB (const HIRect *btnbounds, MacButton *ptr,
         SInt16 depth, Boolean isColorDev);
@@ -227,8 +246,17 @@ TkpDisplayButton(
 
     /* Draw highlight border, if needed. */
     if (needhighlight) {
-        if ((butPtr->flags & GOT_FOCUS)) {
-            Tk_Draw3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0,
+        if ((butPtr->flags & GOT_FOCUS || butPtr->type == TYPE_LABEL)) {
+	    GC gc;
+	    UnixBorder border;
+	    if (butPtr->highlightColorPtr) {
+		gc = Tk_GCForColor(butPtr->highlightColorPtr, pixmap);
+	    } else {
+		gc = Tk_GCForColor(Tk_3DBorderColor(butPtr->highlightBorder),
+                    pixmap);
+	    }
+	    border.solidGC = gc;
+            Tk_Draw3DRectangle(tkwin, pixmap, &border, 0, 0,
                 Tk_Width(tkwin), Tk_Height(tkwin),
                 butPtr->highlightWidth, TK_RELIEF_SOLID);
         }
-- 
cgit v0.12


From f3cda13076d3cb843499495810340da272036737 Mon Sep 17 00:00:00 2001
From: fvogel <fvogelnew1@free.fr>
Date: Fri, 29 Mar 2019 22:05:26 +0000
Subject: Cross-reference UnixBorder structs in different files.

---
 unix/tkUnix3d.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/unix/tkUnix3d.c b/unix/tkUnix3d.c
index 2969de1..3dbd45e 100644
--- a/unix/tkUnix3d.c
+++ b/unix/tkUnix3d.c
@@ -19,7 +19,8 @@
 
 /*
  * This structure is used to keep track of the extra colors used by Unix 3D
- * borders.
+ * borders. Warning: The structure of the same name in tkMacOSXButton.c must
+ * be kept in sync with this one. 
  */
 
 typedef struct {
-- 
cgit v0.12


From ab7aa7d7f951b4cc5821e902bb952901b5b9bf9c Mon Sep 17 00:00:00 2001
From: culler <culler>
Date: Sat, 30 Mar 2019 14:26:46 +0000
Subject: Keep It Safe and Simple.  Just draw the border.  Do not use
 tkUnix3d.c.  Also update the manual to document this behavior.

---
 doc/label.n              |  5 +++++
 macosx/tkMacOSXButton.c  | 41 ++++++++--------------------------------
 macosx/tkMacOSXDraw.c    | 49 ++++++++++++++++++++++++++++++++++++++++++++++++
 macosx/tkMacOSXPrivate.h |  2 ++
 unix/tkUnix3d.c          |  3 +--
 5 files changed, 65 insertions(+), 35 deletions(-)

diff --git a/doc/label.n b/doc/label.n
index f2ba88c..e4b4749 100644
--- a/doc/label.n
+++ b/doc/label.n
@@ -68,6 +68,11 @@ one of the characters may optionally be underlined using the
 \fB\-underline\fR option.
 The label can be manipulated in a few simple ways, such as
 changing its relief or text, using the commands described below.
+.PP
+With respect to the \fB-highlightbackground\fR option, a label is
+considered to always have focus, meaning that the highlight border
+will always be drawn, provided that \fB-highllightthickness\fR is
+positive.
 .SH "WIDGET COMMAND"
 .PP
 The \fBlabel\fR command creates a new Tcl command whose
diff --git a/macosx/tkMacOSXButton.c b/macosx/tkMacOSXButton.c
index 705b214..23596d4 100644
--- a/macosx/tkMacOSXButton.c
+++ b/macosx/tkMacOSXButton.c
@@ -67,26 +67,6 @@ typedef struct {
 } MacButton;
 
 /*
- * When drawing highlight borders for Buttons or Labels, the function
- * Tk_Draw3DRectangle is called with SOLID relief.  This in turn calls the
- * stubs Tk_3DVerticalBevel and Tk_3DHorizontalBevel. The Mac port does not
- * define these stubs itself, but instead uses the ones defined in tkUnix3d.c,
- * which gets compiled and linked into the Mac Tk library.  One of the
- * arguments to these stubs is a pointer to a UnixBorder struct, which is an
- * extension of TkBorder containing one additional field which is a graphics
- * context to be used when drawing the bevels.  The UnixBorder is declared in
- * the file tkUnix3d.c and not in any header file.  We include the declaration
- * here, so that we can draw highlight borders.  But this declaration must be
- * kept in sync with the one in tkUnix3d.c.
- */
-
-#include "tk3d.h"
-typedef struct {
-    TkBorder info;
-    GC solidGC;         /* Used to draw solid relief. */
-} UnixBorder;
-
-/*
  * Forward declarations for procedures defined later in this file:
  */
 
@@ -208,6 +188,12 @@ TkpDisplayButton(
 	return;
     }
     pixmap = (Pixmap) Tk_WindowId(tkwin);
+
+    /*
+     * Set up clipping region. Make sure the we are using the port
+     * for this button, or we will set the wrong window's clip.
+     */
+    
     TkMacOSXSetUpClippingRgn(Tk_WindowId(tkwin));
 
     if (TkMacOSXComputeButtonDrawParams(butPtr, dpPtr) ) {
@@ -215,13 +201,6 @@ TkpDisplayButton(
     } else {
 	macButtonPtr->useTkText = 1;
     }
-
-
-    /*
-     * Set up clipping region. Make sure the we are using the port
-     * for this button, or we will set the wrong window's clip.
-     */
-
     if (macButtonPtr->useTkText) {
 	if (butPtr->type == TYPE_BUTTON) {
 	    Tk_Fill3DRectangle(tkwin, pixmap, butPtr->highlightBorder, 0, 0,
@@ -248,17 +227,13 @@ TkpDisplayButton(
     if (needhighlight) {
         if ((butPtr->flags & GOT_FOCUS || butPtr->type == TYPE_LABEL)) {
 	    GC gc;
-	    UnixBorder border;
 	    if (butPtr->highlightColorPtr) {
-		gc = Tk_GCForColor(butPtr->highlightColorPtr, pixmap);
+	    	gc = Tk_GCForColor(butPtr->highlightColorPtr, pixmap);
 	    } else {
 		gc = Tk_GCForColor(Tk_3DBorderColor(butPtr->highlightBorder),
                     pixmap);
 	    }
-	    border.solidGC = gc;
-            Tk_Draw3DRectangle(tkwin, pixmap, &border, 0, 0,
-                Tk_Width(tkwin), Tk_Height(tkwin),
-                butPtr->highlightWidth, TK_RELIEF_SOLID);
+	    TkMacOSXDrawSolidBorder(tkwin, gc, 0, butPtr->highlightWidth);
         }
     }
 }
diff --git a/macosx/tkMacOSXDraw.c b/macosx/tkMacOSXDraw.c
index faad137..598b581 100644
--- a/macosx/tkMacOSXDraw.c
+++ b/macosx/tkMacOSXDraw.c
@@ -1027,6 +1027,55 @@ XFillRectangles(
 /*
  *----------------------------------------------------------------------
  *
+ * TkMacOSXDrawSolidBorder --
+ *
+ *	Draws a border rectangle of specified thickness inside the bounding
+ *      rectangle of a Tk Window.  The border rectangle can be inset within the
+ *      bounding rectangle.  For a highlight border the inset should be 0, but
+ *      for a solid border around the actual window the inset should equal the
+ *      thickness of the highlight border.  The color of the border rectangle
+ *      is the foreground color of the graphics context passed to the function.
+ *
+ * Results:
+ *	None.
+ *
+ * Side effects:
+ *	Draws a rectangular border inside the bounding rectangle of a window.
+ *
+ *----------------------------------------------------------------------
+ */
+
+MODULE_SCOPE void
+TkMacOSXDrawSolidBorder(
+    Tk_Window tkwin,
+    GC gc,
+    int inset,
+    int thickness)
+{
+    Drawable d = Tk_WindowId(tkwin);
+    MacDrawable *macWin = (MacDrawable *) d;
+    TkMacOSXDrawingContext dc;
+    CGRect outerRect, innerRect;
+
+    if (!TkMacOSXSetupDrawingContext(d, gc, 1, &dc)) {
+	return;
+    }
+    if (dc.context) {
+	outerRect = CGRectMake(Tk_X(tkwin), Tk_Y(tkwin),
+			       Tk_Width(tkwin), Tk_Height(tkwin));
+	outerRect = CGRectInset(outerRect, inset, inset);
+	innerRect = CGRectInset(outerRect, thickness, thickness);
+	CGContextBeginPath(dc.context);
+	CGContextAddRect(dc.context, outerRect);
+	CGContextAddRect(dc.context, innerRect);
+	CGContextEOFillPath(dc.context);
+    }
+    TkMacOSXRestoreDrawingContext(&dc);
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
  * XDrawArc --
  *
  *	Draw an arc.
diff --git a/macosx/tkMacOSXPrivate.h b/macosx/tkMacOSXPrivate.h
index 105317d..668562a 100644
--- a/macosx/tkMacOSXPrivate.h
+++ b/macosx/tkMacOSXPrivate.h
@@ -233,6 +233,8 @@ MODULE_SCOPE int	TkMacOSXStandardAboutPanelObjCmd(ClientData clientData,
 MODULE_SCOPE int	TkMacOSXIconBitmapObjCmd(ClientData clientData,
 			    Tcl_Interp *interp, int objc,
 			    Tcl_Obj *const objv[]);
+MODULE_SCOPE void       TkMacOSXDrawSolidBorder(Tk_Window tkwin, GC gc,
+						int inset, int thickness);
 
 #pragma mark Private Objective-C Classes
 
diff --git a/unix/tkUnix3d.c b/unix/tkUnix3d.c
index 3dbd45e..2969de1 100644
--- a/unix/tkUnix3d.c
+++ b/unix/tkUnix3d.c
@@ -19,8 +19,7 @@
 
 /*
  * This structure is used to keep track of the extra colors used by Unix 3D
- * borders. Warning: The structure of the same name in tkMacOSXButton.c must
- * be kept in sync with this one. 
+ * borders.
  */
 
 typedef struct {
-- 
cgit v0.12


From 761cdb86562088f0dd44c45d314dce97acd38a79 Mon Sep 17 00:00:00 2001
From: culler <culler>
Date: Sat, 30 Mar 2019 17:29:31 +0000
Subject: Correctly distinguish between -highlightcolor and
 -highlightbackground and revert unnecessary changes to the label manual.

---
 doc/label.n             |  5 -----
 macosx/tkMacOSXButton.c | 15 +++++++--------
 2 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/doc/label.n b/doc/label.n
index e4b4749..f2ba88c 100644
--- a/doc/label.n
+++ b/doc/label.n
@@ -68,11 +68,6 @@ one of the characters may optionally be underlined using the
 \fB\-underline\fR option.
 The label can be manipulated in a few simple ways, such as
 changing its relief or text, using the commands described below.
-.PP
-With respect to the \fB-highlightbackground\fR option, a label is
-considered to always have focus, meaning that the highlight border
-will always be drawn, provided that \fB-highllightthickness\fR is
-positive.
 .SH "WIDGET COMMAND"
 .PP
 The \fBlabel\fR command creates a new Tcl command whose
diff --git a/macosx/tkMacOSXButton.c b/macosx/tkMacOSXButton.c
index 23596d4..8ccfdb3 100644
--- a/macosx/tkMacOSXButton.c
+++ b/macosx/tkMacOSXButton.c
@@ -225,14 +225,13 @@ TkpDisplayButton(
 
     /* Draw highlight border, if needed. */
     if (needhighlight) {
-        if ((butPtr->flags & GOT_FOCUS || butPtr->type == TYPE_LABEL)) {
-	    GC gc;
-	    if (butPtr->highlightColorPtr) {
-	    	gc = Tk_GCForColor(butPtr->highlightColorPtr, pixmap);
-	    } else {
-		gc = Tk_GCForColor(Tk_3DBorderColor(butPtr->highlightBorder),
-                    pixmap);
-	    }
+	GC gc = NULL;
+        if ((butPtr->flags & GOT_FOCUS) && butPtr->highlightColorPtr) {
+	    gc = Tk_GCForColor(butPtr->highlightColorPtr, pixmap);
+	} else if (butPtr->type == TYPE_LABEL) {
+	    gc = Tk_GCForColor(Tk_3DBorderColor(butPtr->highlightBorder), pixmap);
+	}
+	if (gc) {
 	    TkMacOSXDrawSolidBorder(tkwin, gc, 0, butPtr->highlightWidth);
         }
     }
-- 
cgit v0.12


From 8139b018a833b0ef8c1263ff3e6b90a45fcbaf99 Mon Sep 17 00:00:00 2001
From: fvogel <fvogelnew1@free.fr>
Date: Sun, 31 Mar 2019 11:01:32 +0000
Subject: Remove an unused variable, squelching a compiler warning.

---
 macosx/tkMacOSXDraw.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/macosx/tkMacOSXDraw.c b/macosx/tkMacOSXDraw.c
index 598b581..013f654 100644
--- a/macosx/tkMacOSXDraw.c
+++ b/macosx/tkMacOSXDraw.c
@@ -1053,7 +1053,6 @@ TkMacOSXDrawSolidBorder(
     int thickness)
 {
     Drawable d = Tk_WindowId(tkwin);
-    MacDrawable *macWin = (MacDrawable *) d;
     TkMacOSXDrawingContext dc;
     CGRect outerRect, innerRect;
 
-- 
cgit v0.12


From d84fefbe9128b55dfa168232174559c52e11011e Mon Sep 17 00:00:00 2001
From: fvogel <fvogelnew1@free.fr>
Date: Sun, 31 Mar 2019 12:52:10 +0000
Subject: Make labels, checkbuttons and radiobuttons honor -highlightbackground
 and -highlightcolor options on Windows.

---
 win/tkWinButton.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/win/tkWinButton.c b/win/tkWinButton.c
index ee0ce82..f101f89 100644
--- a/win/tkWinButton.c
+++ b/win/tkWinButton.c
@@ -410,7 +410,7 @@ TkpDisplayButton(
 		? butPtr->highlightWidth : 0);
 	offset = 1;
     } else {
-	defaultWidth = 0;
+	defaultWidth = butPtr->highlightWidth;;
 	if ((butPtr->type >= TYPE_CHECK_BUTTON) && !butPtr->indicatorOn) {
 	    offset = 1;
 	} else {
@@ -759,17 +759,23 @@ TkpDisplayButton(
 		butPtr->borderWidth, relief);
     }
     if (defaultWidth != 0) {
+        int highlightColor =
+                (int) Tk_3DBorderColor(butPtr->highlightBorder)->pixel;
+
 	dc = TkWinGetDrawableDC(butPtr->display, pixmap, &state);
+        if (butPtr->flags & GOT_FOCUS) {
+            highlightColor = (int) butPtr->highlightColorPtr->pixel;
+        }
 	TkWinFillRect(dc, 0, 0, Tk_Width(tkwin), defaultWidth,
-		(int) butPtr->highlightColorPtr->pixel);
+		highlightColor);
 	TkWinFillRect(dc, 0, 0, defaultWidth, Tk_Height(tkwin),
-		(int) butPtr->highlightColorPtr->pixel);
+		highlightColor);
 	TkWinFillRect(dc, 0, Tk_Height(tkwin) - defaultWidth,
 		Tk_Width(tkwin), defaultWidth,
-		(int) butPtr->highlightColorPtr->pixel);
+		highlightColor);
 	TkWinFillRect(dc, Tk_Width(tkwin) - defaultWidth, 0,
 		defaultWidth, Tk_Height(tkwin),
-		(int) butPtr->highlightColorPtr->pixel);
+		highlightColor);
 	TkWinReleaseDrawableDC(pixmap, dc, &state);
     }
 
-- 
cgit v0.12


From 8cf4a9bdbf03c6a9b09e09554c470e7f2e13abdf Mon Sep 17 00:00:00 2001
From: fvogel <fvogelnew1@free.fr>
Date: Sun, 31 Mar 2019 14:34:16 +0000
Subject: Restore behavior of checkbuttons and radiobuttons on Windows. They
 again do not take -highlightbackground into account, in an attempt to follow
 platform specific conventions. The code now only changes this for labels.

---
 win/tkWinButton.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/win/tkWinButton.c b/win/tkWinButton.c
index f101f89..6024b02 100644
--- a/win/tkWinButton.c
+++ b/win/tkWinButton.c
@@ -405,12 +405,15 @@ TkpDisplayButton(
      * Compute width of default ring and offset for pushed buttons.
      */
 
-    if (butPtr->type == TYPE_BUTTON) {
+    if (butPtr->type == TYPE_LABEL) {
+	defaultWidth = butPtr->highlightWidth;
+        offset = 0;
+    } else if (butPtr->type == TYPE_BUTTON) {
 	defaultWidth = ((butPtr->defaultState == DEFAULT_ACTIVE)
 		? butPtr->highlightWidth : 0);
 	offset = 1;
     } else {
-	defaultWidth = butPtr->highlightWidth;;
+	defaultWidth = 0;
 	if ((butPtr->type >= TYPE_CHECK_BUTTON) && !butPtr->indicatorOn) {
 	    offset = 1;
 	} else {
-- 
cgit v0.12


From a46a024f97912319754e4dae155b18f796b56b0d Mon Sep 17 00:00:00 2001
From: fvogel <fvogelnew1@free.fr>
Date: Sun, 31 Mar 2019 14:43:09 +0000
Subject: *Really* don't change the behavior for *buttons, even with they have
 -default active

---
 win/tkWinButton.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/win/tkWinButton.c b/win/tkWinButton.c
index 6024b02..d03a391 100644
--- a/win/tkWinButton.c
+++ b/win/tkWinButton.c
@@ -762,11 +762,12 @@ TkpDisplayButton(
 		butPtr->borderWidth, relief);
     }
     if (defaultWidth != 0) {
-        int highlightColor =
-                (int) Tk_3DBorderColor(butPtr->highlightBorder)->pixel;
+        int highlightColor;
 
 	dc = TkWinGetDrawableDC(butPtr->display, pixmap, &state);
-        if (butPtr->flags & GOT_FOCUS) {
+        if (butPtr->type == TYPE_LABEL) {
+            highlightColor = (int) Tk_3DBorderColor(butPtr->highlightBorder)->pixel;
+        } else {
             highlightColor = (int) butPtr->highlightColorPtr->pixel;
         }
 	TkWinFillRect(dc, 0, 0, Tk_Width(tkwin), defaultWidth,
-- 
cgit v0.12


From 1203c84117410cd64aba7bee09446665f14792f9 Mon Sep 17 00:00:00 2001
From: culler <culler>
Date: Sun, 31 Mar 2019 16:33:50 +0000
Subject: Make menubuttons honor the -highlightcolor option on macOS.

---
 macosx/tkMacOSXMenubutton.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/macosx/tkMacOSXMenubutton.c b/macosx/tkMacOSXMenubutton.c
index b2b4b76..5b39e19 100644
--- a/macosx/tkMacOSXMenubutton.c
+++ b/macosx/tkMacOSXMenubutton.c
@@ -190,11 +190,10 @@ TkpDisplayMenuButton(
 
     /* Draw highlight border, if needed. */
     if (butPtr->highlightWidth < 3) {
-        if ((butPtr->flags & GOT_FOCUS)) {
-            Tk_Draw3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0,
-                Tk_Width(tkwin), Tk_Height(tkwin),
-                butPtr->highlightWidth, TK_RELIEF_SOLID);
-        }
+        if (butPtr->flags & GOT_FOCUS) {
+	GC gc = Tk_GCForColor(butPtr->highlightColorPtr, pixmap);
+	TkMacOSXDrawSolidBorder(tkwin, gc, 0, butPtr->highlightWidth);
+	}
     }
 }
 
-- 
cgit v0.12


From 992e83396570dcf0c161abd79226964eb535ad57 Mon Sep 17 00:00:00 2001
From: culler <culler>
Date: Sun, 31 Mar 2019 16:34:59 +0000
Subject: Fix indentation.

---
 macosx/tkMacOSXMenubutton.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/macosx/tkMacOSXMenubutton.c b/macosx/tkMacOSXMenubutton.c
index 5b39e19..f52b98e 100644
--- a/macosx/tkMacOSXMenubutton.c
+++ b/macosx/tkMacOSXMenubutton.c
@@ -191,8 +191,8 @@ TkpDisplayMenuButton(
     /* Draw highlight border, if needed. */
     if (butPtr->highlightWidth < 3) {
         if (butPtr->flags & GOT_FOCUS) {
-	GC gc = Tk_GCForColor(butPtr->highlightColorPtr, pixmap);
-	TkMacOSXDrawSolidBorder(tkwin, gc, 0, butPtr->highlightWidth);
+	    GC gc = Tk_GCForColor(butPtr->highlightColorPtr, pixmap);
+	    TkMacOSXDrawSolidBorder(tkwin, gc, 0, butPtr->highlightWidth);
 	}
     }
 }
-- 
cgit v0.12