diff options
author | culler <culler> | 2018-11-20 18:52:42 (GMT) |
---|---|---|
committer | culler <culler> | 2018-11-20 18:52:42 (GMT) |
commit | 13f6c367a6b4413a8ae0bdda8eb77bf1c98534d7 (patch) | |
tree | eab6201072f6ddb7ca2d6b976e857e8957c7594f /generic/ttk | |
parent | 11dcff268e1d978ba036f5ea7c88b32f09330bfd (diff) | |
download | tk-13f6c367a6b4413a8ae0bdda8eb77bf1c98534d7.zip tk-13f6c367a6b4413a8ae0bdda8eb77bf1c98534d7.tar.gz tk-13f6c367a6b4413a8ae0bdda8eb77bf1c98534d7.tar.bz2 |
Only use XCreateImage when drawing the Alt theme indicator on macOS, not on UNIX or Windows.
Diffstat (limited to 'generic/ttk')
-rw-r--r-- | generic/ttk/ttkDefaultTheme.c | 43 | ||||
-rw-r--r-- | generic/ttk/ttkTheme.c | 12 |
2 files changed, 46 insertions, 9 deletions
diff --git a/generic/ttk/ttkDefaultTheme.c b/generic/ttk/ttkDefaultTheme.c index 20ba013..473caba 100644 --- a/generic/ttk/ttkDefaultTheme.c +++ b/generic/ttk/ttkDefaultTheme.c @@ -18,6 +18,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 @@ -551,20 +555,47 @@ static void IndicatorElementDraw( * Create a scratch buffer to store the image: */ +#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; + return; } + +#if defined(IGNORES_VISUAL) + img->data = ckalloc(img->bytes_per_line * img->height); if (img->data == NULL) { - return; + 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++) { @@ -574,16 +605,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 ac52595..c0bd784 100644 --- a/generic/ttk/ttkTheme.c +++ b/generic/ttk/ttkTheme.c @@ -18,6 +18,13 @@ #define PKG_ASSOC_KEY "Ttk" +#ifdef MAC_OSX_TK + extern void TkMacOSXFlushWindows(void); + #define UPDATE_WINDOWS() TkMacOSXFlushWindows() +#else + #define UPDATE_WINDOWS() +#endif + /*------------------------------------------------------------------------ * +++ Styles. * @@ -513,10 +520,7 @@ static void ThemeChangedProc(ClientData clientData) Tcl_BackgroundException(pkgPtr->interp, code); } pkgPtr->themeChangePending = 0; -#ifdef MAC_OSX_TK - extern void TkMacOSXFlushWindows(void); - TkMacOSXFlushWindows(); -#endif + UPDATE_WINDOWS(); } /* |