summaryrefslogtreecommitdiffstats
path: root/generic/ttk
diff options
context:
space:
mode:
authorculler <culler>2018-11-20 19:49:24 (GMT)
committerculler <culler>2018-11-20 19:49:24 (GMT)
commit2cb045114a45384942c633c911748643d7f5fe1b (patch)
tree24215e85aaea2b7fa227506f7d2bb76560b91ada /generic/ttk
parent45ed0ac3a06b97229909bda4c11cade4881adfb6 (diff)
parent05b49a9826205148598325c51b795d782dac0481 (diff)
downloadtk-2cb045114a45384942c633c911748643d7f5fe1b.zip
tk-2cb045114a45384942c633c911748643d7f5fe1b.tar.gz
tk-2cb045114a45384942c633c911748643d7f5fe1b.tar.bz2
Fix the bug that caused a crash on macOS when switching to the Alt theme.
Diffstat (limited to 'generic/ttk')
-rw-r--r--generic/ttk/ttkDefaultTheme.c56
-rw-r--r--generic/ttk/ttkTheme.c8
2 files changed, 55 insertions, 9 deletions
diff --git a/generic/ttk/ttkDefaultTheme.c b/generic/ttk/ttkDefaultTheme.c
index 2118704..803d254 100644
--- a/generic/ttk/ttkDefaultTheme.c
+++ b/generic/ttk/ttkDefaultTheme.c
@@ -15,6 +15,10 @@ static const int WIN32_XDRAWLINE_HACK = 1;
static const int WIN32_XDRAWLINE_HACK = 0;
#endif
+#if defined(MAC_OSX_TK)
+ #define IGNORES_VISUAL
+#endif
+
#define BORDERWIDTH 2
#define SCROLLBAR_WIDTH 14
#define MIN_THUMB_SIZE 8
@@ -507,7 +511,7 @@ static void IndicatorElementDraw(
XGCValues gcValues;
GC copyGC;
unsigned long imgColors[8];
- XImage *img;
+ XImage *img = NULL;
Ttk_GetPaddingFromObj(NULL, tkwin, indicator->marginObj, &padding);
b = Ttk_PadBox(b, padding);
@@ -547,15 +551,48 @@ static void IndicatorElementDraw(
/*
* Create a scratch buffer to store the image:
*/
- img = XGetImage(display,d, 0, 0,
- (unsigned int)spec->width, (unsigned int)spec->height,
- AllPlanes, ZPixmap);
- if (img == NULL)
+
+#if defined(IGNORES_VISUAL)
+
+ /*
+ * Platforms which ignore the VisualInfo can use XCreateImage to get the
+ * scratch image. This is essential on macOS, where it is not safe to call
+ * XGetImage in a display procedure.
+ */
+
+ img = XCreateImage(display, NULL, 32, ZPixmap, 0, NULL,
+ (unsigned int)spec->width, (unsigned int)spec->height,
+ 0, 0);
+#else
+
+ /*
+ * This trick allows creating the scratch XImage without having to
+ * construct a VisualInfo.
+ */
+
+ img = XGetImage(display, d, 0, 0,
+ (unsigned int)spec->width, (unsigned int)spec->height,
+ AllPlanes, ZPixmap);
+#endif
+
+ if (img == NULL) {
+ return;
+ }
+
+#if defined(IGNORES_VISUAL)
+
+ img->data = ckalloc(img->bytes_per_line * img->height);
+ if (img->data == NULL) {
+ XDestroyImage(img);
return;
+ }
+
+#endif
/*
- * Create the image, painting it into an XImage one pixel at a time.
+ * Create the image, painting it into the XImage one pixel at a time.
*/
+
index = Ttk_StateTableLookup(spec->map, state);
for (iy=0 ; iy<spec->height ; iy++) {
for (ix=0 ; ix<spec->width ; ix++) {
@@ -565,17 +602,18 @@ static void IndicatorElementDraw(
}
/*
- * Copy onto our target drawable surface.
+ * Copy the image onto our target drawable surface.
*/
+
memset(&gcValues, 0, sizeof(gcValues));
copyGC = Tk_GetGC(tkwin, 0, &gcValues);
-
TkPutImage(NULL, 0, display, d, copyGC, img, 0, 0, b.x, b.y,
spec->width, spec->height);
/*
- * Tidy up.
+ * Tidy up. Note that XDestroyImage frees img->data.
*/
+
Tk_FreeGC(display, copyGC);
XDestroyImage(img);
}
diff --git a/generic/ttk/ttkTheme.c b/generic/ttk/ttkTheme.c
index f98cc26..8640d13 100644
--- a/generic/ttk/ttkTheme.c
+++ b/generic/ttk/ttkTheme.c
@@ -15,6 +15,13 @@
#define PKG_ASSOC_KEY "Ttk"
+#ifdef MAC_OSX_TK
+ extern void TkMacOSXFlushWindows(void);
+ #define UPDATE_WINDOWS() TkMacOSXFlushWindows()
+#else
+ #define UPDATE_WINDOWS()
+#endif
+
/*------------------------------------------------------------------------
* +++ Styles.
*
@@ -510,6 +517,7 @@ static void ThemeChangedProc(ClientData clientData)
Tcl_BackgroundException(pkgPtr->interp, code);
}
pkgPtr->themeChangePending = 0;
+ UPDATE_WINDOWS();
}
/*