diff options
author | culler <culler> | 2020-05-29 18:30:28 (GMT) |
---|---|---|
committer | culler <culler> | 2020-05-29 18:30:28 (GMT) |
commit | 4996dd8c53efd46d1b66d080e7c4a7faead1d373 (patch) | |
tree | 0e14390802c437353ff15164830fd8e242a0c535 | |
parent | 18fd1bf89685a067ea6ad92d6b1d7f260394ddce (diff) | |
parent | 9ba4c746ec344f1455e03c2f97ca0ae7c95d139f (diff) | |
download | tk-4996dd8c53efd46d1b66d080e7c4a7faead1d373.zip tk-4996dd8c53efd46d1b66d080e7c4a7faead1d373.tar.gz tk-4996dd8c53efd46d1b66d080e7c4a7faead1d373.tar.bz2 |
Remove some unnecessary macOS conditional code by using internal stubs.
-rw-r--r-- | generic/tkFont.c | 10 | ||||
-rw-r--r-- | generic/tkInt.decls | 8 | ||||
-rw-r--r-- | generic/tkIntDecls.h | 36 | ||||
-rw-r--r-- | generic/tkStubInit.c | 20 | ||||
-rw-r--r-- | generic/tkTextDisp.c | 40 | ||||
-rw-r--r-- | macosx/tkMacOSXInt.h | 2 | ||||
-rw-r--r-- | macosx/tkMacOSXSubwindows.c | 8 | ||||
-rw-r--r-- | macosx/tkMacOSXWindowEvent.c | 35 | ||||
-rw-r--r-- | macosx/tkMacOSXWm.c | 34 | ||||
-rw-r--r-- | unix/tkUnixPort.h | 2 | ||||
-rw-r--r-- | win/tkWinPort.h | 7 |
11 files changed, 150 insertions, 52 deletions
diff --git a/generic/tkFont.c b/generic/tkFont.c index 34f8921..289a4d0 100644 --- a/generic/tkFont.c +++ b/generic/tkFont.c @@ -13,9 +13,7 @@ #include "tkInt.h" #include "tkFont.h" -#if defined(MAC_OSX_TK) -#include "tkMacOSXInt.h" -#endif + /* * The following structure is used to keep track of all the fonts that exist * in the current application. It must be stored in the TkMainInfo for the @@ -875,18 +873,18 @@ TheWorldHasChanged( ClientData clientData) /* Info about application's fonts. */ { TkFontInfo *fiPtr = (TkFontInfo *)clientData; -#if defined(MAC_OSX_TK) /* * On macOS it is catastrophic to recompute all widgets while the * [NSView drawRect] method is drawing. The best that we can do in * that situation is to abort the recomputation and hope for the best. + * This is ignored on other platforms. */ - if (TkpAppIsDrawing()) { + if (TkpAppCanDraw(NULL)) { return; } -#endif + fiPtr->updatePending = 0; RecomputeWidgets(fiPtr->mainPtr->winPtr); } diff --git a/generic/tkInt.decls b/generic/tkInt.decls index b5e4d3c..04f7d7d 100644 --- a/generic/tkInt.decls +++ b/generic/tkInt.decls @@ -641,6 +641,14 @@ declare 185 { Tcl_Obj *formatString, int *widthPtr, int *heightPtr) } +# Support for aqua's inability to draw outside [NSView drawRect:] +declare 186 aqua { + void TkpRedrawWidget(Tk_Window tkwin) +} +declare 187 aqua { + int TkpAppCanDraw(Tk_Window tkwin) +} + ############################################################################## diff --git a/generic/tkIntDecls.h b/generic/tkIntDecls.h index 619e3cf..1274b71 100644 --- a/generic/tkIntDecls.h +++ b/generic/tkIntDecls.h @@ -562,6 +562,14 @@ EXTERN void TkDrawAngledChars(Display *display, EXTERN int TkDebugPhotoStringMatchDef(Tcl_Interp *inter, Tcl_Obj *data, Tcl_Obj *formatString, int *widthPtr, int *heightPtr); +#ifdef MAC_OSX_TK /* AQUA */ +/* 186 */ +EXTERN void TkpRedrawWidget(Tk_Window tkwin); +#endif /* AQUA */ +#ifdef MAC_OSX_TK /* AQUA */ +/* 187 */ +EXTERN int TkpAppCanDraw(Tk_Window tkwin); +#endif /* AQUA */ typedef struct TkIntStubs { int magic; @@ -780,6 +788,26 @@ typedef struct TkIntStubs { int (*tkIntersectAngledTextLayout) (Tk_TextLayout layout, int x, int y, int width, int height, double angle); /* 183 */ void (*tkDrawAngledChars) (Display *display, Drawable drawable, GC gc, Tk_Font tkfont, const char *source, int numBytes, double x, double y, double angle); /* 184 */ int (*tkDebugPhotoStringMatchDef) (Tcl_Interp *inter, Tcl_Obj *data, Tcl_Obj *formatString, int *widthPtr, int *heightPtr); /* 185 */ +#if !(defined(_WIN32) || defined(MAC_OSX_TK)) /* X11 */ + void (*reserved186)(void); +#endif /* X11 */ +#if defined(_WIN32) /* WIN */ + void (*reserved186)(void); +#endif /* WIN */ +#ifdef MAC_OSX_TK /* AQUA */ + void (*reserved186)(void); /* Dummy entry for stubs table backwards compatibility */ + void (*tkpRedrawWidget) (Tk_Window tkwin); /* 186 */ +#endif /* AQUA */ +#if !(defined(_WIN32) || defined(MAC_OSX_TK)) /* X11 */ + void (*reserved187)(void); +#endif /* X11 */ +#if defined(_WIN32) /* WIN */ + void (*reserved187)(void); +#endif /* WIN */ +#ifdef MAC_OSX_TK /* AQUA */ + void (*reserved187)(void); /* Dummy entry for stubs table backwards compatibility */ + int (*tkpAppCanDraw) (Tk_Window tkwin); /* 187 */ +#endif /* AQUA */ } TkIntStubs; extern const TkIntStubs *tkIntStubsPtr; @@ -1154,6 +1182,14 @@ extern const TkIntStubs *tkIntStubsPtr; (tkIntStubsPtr->tkDrawAngledChars) /* 184 */ #define TkDebugPhotoStringMatchDef \ (tkIntStubsPtr->tkDebugPhotoStringMatchDef) /* 185 */ +#ifdef MAC_OSX_TK /* AQUA */ +#define TkpRedrawWidget \ + (tkIntStubsPtr->tkpRedrawWidget) /* 186 */ +#endif /* AQUA */ +#ifdef MAC_OSX_TK /* AQUA */ +#define TkpAppCanDraw \ + (tkIntStubsPtr->tkpAppCanDraw) /* 187 */ +#endif /* AQUA */ #endif /* defined(USE_TK_STUBS) */ diff --git a/generic/tkStubInit.c b/generic/tkStubInit.c index 8b98928..9b6bb33 100644 --- a/generic/tkStubInit.c +++ b/generic/tkStubInit.c @@ -495,6 +495,26 @@ static const TkIntStubs tkIntStubs = { TkIntersectAngledTextLayout, /* 183 */ TkDrawAngledChars, /* 184 */ TkDebugPhotoStringMatchDef, /* 185 */ +#if !(defined(_WIN32) || defined(MAC_OSX_TK)) /* X11 */ + 0, /* 186 */ +#endif /* X11 */ +#if defined(_WIN32) /* WIN */ + 0, /* 186 */ +#endif /* WIN */ +#ifdef MAC_OSX_TK /* AQUA */ + 0, /* 186 */ /* Dummy entry for stubs table backwards compatibility */ + TkpRedrawWidget, /* 186 */ +#endif /* AQUA */ +#if !(defined(_WIN32) || defined(MAC_OSX_TK)) /* X11 */ + 0, /* 187 */ +#endif /* X11 */ +#if defined(_WIN32) /* WIN */ + 0, /* 187 */ +#endif /* WIN */ +#ifdef MAC_OSX_TK /* AQUA */ + 0, /* 187 */ /* Dummy entry for stubs table backwards compatibility */ + TkpAppCanDraw, /* 187 */ +#endif /* AQUA */ }; static const TkIntPlatStubs tkIntPlatStubs = { diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c index 8acf115..88ad4e6 100644 --- a/generic/tkTextDisp.c +++ b/generic/tkTextDisp.c @@ -16,13 +16,17 @@ #include "tkInt.h" #include "tkText.h" -#ifdef MAC_OSX_TK +#ifdef _WIN32 +#include "tkWinInt.h" +#elif defined(__CYGWIN__) +#include "tkUnixInt.h" +#elif defined(MAC_OSX_TK) #include "tkMacOSXInt.h" -#define OK_TO_LOG (!TkpAppIsDrawing()) -#define FORCE_DISPLAY(winPtr) TkpDisplayWindow(winPtr) -#else +#define OK_TO_LOG (!TkpAppCanDraw(textPtr->tkwin)) +#endif + +#if !defined(MAC_OSX_TK) #define OK_TO_LOG 1 -#define FORCE_DISPLAY(winPtr) #endif /* @@ -3151,7 +3155,7 @@ GenerateWidgetViewSyncEvent( */ if (!tkTextDebug) { - FORCE_DISPLAY(textPtr->tkwin); + TkpRedrawWidget(textPtr->tkwin); } if (NewSyncState != OldSyncState) { @@ -4171,11 +4175,23 @@ DisplayText( * warnings. */ Tcl_Interp *interp; + + if ((textPtr->tkwin == NULL) || (textPtr->flags & DESTROYED)) { + /* + * The widget has been deleted. Don't do anything. + */ + + return; + } + #ifdef MAC_OSX_TK /* - * If drawing is disabled, all we need to do is - * clear the REDRAW_PENDING flag. + * If the toplevel is being resized it would be dangerous to try redrawing + * the widget. But we can just clear the REDRAW_PENDING flag and return. + * This display proc will be called again after the widget has been + * reconfigured. */ + TkWindow *winPtr = (TkWindow *)(textPtr->tkwin); MacDrawable *macWin = winPtr->privatePtr; if (macWin && (macWin->flags & TK_DO_NOT_DRAW)){ @@ -4184,14 +4200,6 @@ DisplayText( } #endif - if ((textPtr->tkwin == NULL) || (textPtr->flags & DESTROYED)) { - /* - * The widget has been deleted. Don't do anything. - */ - - return; - } - interp = textPtr->interp; Tcl_Preserve(interp); diff --git a/macosx/tkMacOSXInt.h b/macosx/tkMacOSXInt.h index bd669c0..5d03746 100644 --- a/macosx/tkMacOSXInt.h +++ b/macosx/tkMacOSXInt.h @@ -196,8 +196,6 @@ MODULE_SCOPE void TkpClipDrawableToRect(Display *display, Drawable d, int x, MODULE_SCOPE void TkpRetainRegion(Region r); MODULE_SCOPE void TkpReleaseRegion(Region r); MODULE_SCOPE void TkpShiftButton(NSButton *button, NSPoint delta); -MODULE_SCOPE Bool TkpAppIsDrawing(void); -MODULE_SCOPE void TkpDisplayWindow(Tk_Window tkwin); MODULE_SCOPE Bool TkTestLogDisplay(void); MODULE_SCOPE Bool TkMacOSXInDarkMode(Tk_Window tkwin); diff --git a/macosx/tkMacOSXSubwindows.c b/macosx/tkMacOSXSubwindows.c index 611afd7..52927ab 100644 --- a/macosx/tkMacOSXSubwindows.c +++ b/macosx/tkMacOSXSubwindows.c @@ -699,16 +699,10 @@ XConfigureWindow( if (value_mask & CWStackMode) { NSView *view = TkMacOSXDrawableView(macWin); - Rect bounds; - NSRect r; if (view) { TkMacOSXInvalClipRgns((Tk_Window) winPtr->parentPtr); - TkMacOSXWinBounds(winPtr, &bounds); - r = NSMakeRect(bounds.left, - [view bounds].size.height - bounds.bottom, - bounds.right - bounds.left, bounds.bottom - bounds.top); - [view setNeedsDisplayInRect:r]; + TkpRedrawWidget((Tk_Window) winPtr); } } diff --git a/macosx/tkMacOSXWindowEvent.c b/macosx/tkMacOSXWindowEvent.c index 71e687b..322643e 100644 --- a/macosx/tkMacOSXWindowEvent.c +++ b/macosx/tkMacOSXWindowEvent.c @@ -394,26 +394,41 @@ extern NSString *NSWindowDidOrderOffScreenNotification; /* *---------------------------------------------------------------------- * - * TkpAppIsDrawing -- + * TkpAppCanDraw -- * * A widget display procedure can call this to determine whether it is - * being run inside of the drawRect method. This is needed for some tests, - * especially of the Text widget, which record data in a global Tcl - * variable and assume that display procedures will be run in a - * predictable sequence as Tcl idle tasks. + * being run inside of the drawRect method. If not, it may be desirable + * for the display procedure to simply clear the REDRAW_PENDING flag + * and return. The widget can be recorded in order to schedule a + * redraw, via and Expose event, from within drawRect. + * + * This is also needed for some tests, especially of the Text widget, + * which record data in a global Tcl variable and assume that display + * procedures will be run in a predictable sequence as Tcl idle tasks. * * Results: - * True only while running the drawRect method of a TKContentView; + * True if called from the drawRect method of a TKContentView with + * tkwin NULL or pointing to a widget in the current focusView. * * Side effects: - * None + * The tkwin parameter may be recorded to handle redrawing the widget + * later. * *---------------------------------------------------------------------- */ -MODULE_SCOPE Bool -TkpAppIsDrawing(void) { - return [NSApp isDrawing]; +int +TkpAppCanDraw(Tk_Window tkwin) { + if (![NSApp isDrawing]) { + return 0; + } + if (tkwin) { + TkWindow *winPtr = (TkWindow *)tkwin; + NSView *view = TkMacOSXDrawableView(winPtr->privatePtr); + return (view == [NSView focusView]); + } else { + return 1; + } } /* diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index f24b8d4..98100e9 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -6173,28 +6173,40 @@ TkMacOSXMakeRealWindowExist( /* *---------------------------------------------------------------------- * - * TkpDisplayWindow -- + * TkpRedrawWidget -- * - * Mark the contentView of this window as needing display so the window - * will be drawn by the window manager. If this is called within the - * drawRect method, do nothing. + * Mark the bounding rectangle of this widget as needing display so the + * widget will be drawn by [NSView drawRect:]. If this is called within + * the drawRect method, do nothing. * * Results: * None. * * Side effects: - * The window's contentView is marked as needing display. + * The widget's bounding rectangle is marked as dirty. * *---------------------------------------------------------------------- */ -MODULE_SCOPE void -TkpDisplayWindow(Tk_Window tkwin) { - if (![NSApp isDrawing]) { - TkWindow *winPtr = (TkWindow *) tkwin; - NSWindow *w = TkMacOSXDrawableWindow(winPtr->window); +void +TkpRedrawWidget(Tk_Window tkwin) { + TkWindow *winPtr = (TkWindow *) tkwin; + NSWindow *w; + Rect tkBounds; + NSRect bounds; - [[w contentView] setNeedsDisplay: YES]; + if ([NSApp isDrawing]) { + return; + } + w = TkMacOSXDrawableWindow(winPtr->window); + if (w) { + NSView *view = [w contentView]; + TkMacOSXWinBounds(winPtr, &tkBounds); + bounds = NSMakeRect(tkBounds.left, + [view bounds].size.height - tkBounds.bottom, + tkBounds.right - tkBounds.left, + tkBounds.bottom - tkBounds.top); + [view setNeedsDisplayInRect:bounds]; } } diff --git a/unix/tkUnixPort.h b/unix/tkUnixPort.h index 347c9d8..358a67c 100644 --- a/unix/tkUnixPort.h +++ b/unix/tkUnixPort.h @@ -149,6 +149,8 @@ #define TkpButtonSetDefaults() {} #define TkpDestroyButton(butPtr) {} +#define TkpAppCanDraw(tkwin) 1 +#define TkpRedrawWidget(tkwin) #define TkSelUpdateClipboard(a,b) {} #ifndef __CYGWIN__ #define TkSetPixmapColormap(p,c) {} diff --git a/win/tkWinPort.h b/win/tkWinPort.h index 11ecf21..86f212e 100644 --- a/win/tkWinPort.h +++ b/win/tkWinPort.h @@ -129,4 +129,11 @@ #define TkpCreateNativeBitmap(display, source) None #define TkpGetNativeAppBitmap(display, name, w, h) None +/* + * Other functions not used under Windows + */ + +#define TkpAppCanDraw(tkwin) 1 +#define TkpRedrawWidget(tkwin) + #endif /* _WINPORT */ |