summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorculler <culler>2020-05-29 18:21:55 (GMT)
committerculler <culler>2020-05-29 18:21:55 (GMT)
commit9ba4c746ec344f1455e03c2f97ca0ae7c95d139f (patch)
treec2f3dab350bf3a9bd83fa139c24f9432b31eac06
parentbd0d1fd4d2137bebd775874b705c061a7e13aa7f (diff)
downloadtk-9ba4c746ec344f1455e03c2f97ca0ae7c95d139f.zip
tk-9ba4c746ec344f1455e03c2f97ca0ae7c95d139f.tar.gz
tk-9ba4c746ec344f1455e03c2f97ca0ae7c95d139f.tar.bz2
Remove some unnecessary macOS conditional code by using internal stubs.
-rw-r--r--generic/tkFont.c10
-rw-r--r--generic/tkInt.decls9
-rw-r--r--generic/tkIntDecls.h36
-rw-r--r--generic/tkStubInit.c20
-rw-r--r--generic/tkTextDisp.c36
-rw-r--r--macosx/tkMacOSXInt.h2
-rw-r--r--macosx/tkMacOSXSubwindows.c8
-rw-r--r--macosx/tkMacOSXWindowEvent.c35
-rw-r--r--macosx/tkMacOSXWm.c34
-rw-r--r--unix/tkUnixPort.h2
-rw-r--r--win/tkWinPort.h7
11 files changed, 146 insertions, 53 deletions
diff --git a/generic/tkFont.c b/generic/tkFont.c
index 53855ac..448f918 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
@@ -874,18 +872,18 @@ TheWorldHasChanged(
ClientData clientData) /* Info about application's fonts. */
{
TkFontInfo *fiPtr = 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 bb2057b..da591cb 100644
--- a/generic/tkInt.decls
+++ b/generic/tkInt.decls
@@ -634,6 +634,15 @@ declare 184 {
Tk_Font tkfont, const char *source, int numBytes, double x,
double y, double angle)
}
+
+# Support for aqua's inability to draw outside [NSView drawRect:]
+declare 185 aqua {
+ void TkpRedrawWidget(Tk_Window tkwin)
+}
+declare 186 aqua {
+ int TkpAppCanDraw(Tk_Window tkwin)
+}
+
##############################################################################
diff --git a/generic/tkIntDecls.h b/generic/tkIntDecls.h
index fa1833e..7bf9bd7 100644
--- a/generic/tkIntDecls.h
+++ b/generic/tkIntDecls.h
@@ -550,6 +550,14 @@ EXTERN void TkDrawAngledChars(Display *display,
Drawable drawable, GC gc, Tk_Font tkfont,
const char *source, int numBytes, double x,
double y, double angle);
+#ifdef MAC_OSX_TK /* AQUA */
+/* 185 */
+EXTERN void TkpRedrawWidget(Tk_Window tkwin);
+#endif /* AQUA */
+#ifdef MAC_OSX_TK /* AQUA */
+/* 186 */
+EXTERN int TkpAppCanDraw(Tk_Window tkwin);
+#endif /* AQUA */
typedef struct TkIntStubs {
int magic;
@@ -767,6 +775,26 @@ typedef struct TkIntStubs {
void (*tkUnderlineAngledTextLayout) (Display *display, Drawable drawable, GC gc, Tk_TextLayout layout, int x, int y, double angle, int underline); /* 182 */
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 */
+#if !(defined(_WIN32) || defined(MAC_OSX_TK)) /* X11 */
+ void (*reserved185)(void);
+#endif /* X11 */
+#if defined(_WIN32) /* WIN */
+ void (*reserved185)(void);
+#endif /* WIN */
+#ifdef MAC_OSX_TK /* AQUA */
+ void (*reserved185)(void); /* Dummy entry for stubs table backwards compatibility */
+ void (*tkpRedrawWidget) (Tk_Window tkwin); /* 185 */
+#endif /* AQUA */
+#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 */
+ int (*tkpAppCanDraw) (Tk_Window tkwin); /* 186 */
+#endif /* AQUA */
} TkIntStubs;
extern const TkIntStubs *tkIntStubsPtr;
@@ -1139,6 +1167,14 @@ extern const TkIntStubs *tkIntStubsPtr;
(tkIntStubsPtr->tkIntersectAngledTextLayout) /* 183 */
#define TkDrawAngledChars \
(tkIntStubsPtr->tkDrawAngledChars) /* 184 */
+#ifdef MAC_OSX_TK /* AQUA */
+#define TkpRedrawWidget \
+ (tkIntStubsPtr->tkpRedrawWidget) /* 185 */
+#endif /* AQUA */
+#ifdef MAC_OSX_TK /* AQUA */
+#define TkpAppCanDraw \
+ (tkIntStubsPtr->tkpAppCanDraw) /* 186 */
+#endif /* AQUA */
#endif /* defined(USE_TK_STUBS) */
diff --git a/generic/tkStubInit.c b/generic/tkStubInit.c
index 61c698a..045c86e 100644
--- a/generic/tkStubInit.c
+++ b/generic/tkStubInit.c
@@ -485,6 +485,26 @@ static const TkIntStubs tkIntStubs = {
TkUnderlineAngledTextLayout, /* 182 */
TkIntersectAngledTextLayout, /* 183 */
TkDrawAngledChars, /* 184 */
+#if !(defined(_WIN32) || defined(MAC_OSX_TK)) /* X11 */
+ 0, /* 185 */
+#endif /* X11 */
+#if defined(_WIN32) /* WIN */
+ 0, /* 185 */
+#endif /* WIN */
+#ifdef MAC_OSX_TK /* AQUA */
+ 0, /* 185 */ /* Dummy entry for stubs table backwards compatibility */
+ TkpRedrawWidget, /* 185 */
+#endif /* AQUA */
+#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 */
+ TkpAppCanDraw, /* 186 */
+#endif /* AQUA */
};
static const TkIntPlatStubs tkIntPlatStubs = {
diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c
index c848fd2..084fd64 100644
--- a/generic/tkTextDisp.c
+++ b/generic/tkTextDisp.c
@@ -20,15 +20,13 @@
#include "tkWinInt.h"
#elif defined(__CYGWIN__)
#include "tkUnixInt.h"
+#elif defined(MAC_OSX_TK)
+#include "tkMacOSXInt.h"
+#define OK_TO_LOG (!TkpAppCanDraw(textPtr->tkwin))
#endif
-#ifdef MAC_OSX_TK
-#include "tkMacOSXInt.h"
-#define OK_TO_LOG (!TkpAppIsDrawing())
-#define FORCE_DISPLAY(winPtr) TkpDisplayWindow(winPtr)
-#else
+#if !defined(MAC_OSX_TK)
#define OK_TO_LOG 1
-#define FORCE_DISPLAY(winPtr)
#endif
/*
@@ -3157,7 +3155,7 @@ GenerateWidgetViewSyncEvent(
*/
if (!tkTextDebug) {
- FORCE_DISPLAY(textPtr->tkwin);
+ TkpRedrawWidget(textPtr->tkwin);
}
if (NewSyncState != OldSyncState) {
@@ -4176,11 +4174,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)){
@@ -4189,14 +4199,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 9cb75d2..58761d5 100644
--- a/macosx/tkMacOSXInt.h
+++ b/macosx/tkMacOSXInt.h
@@ -200,8 +200,6 @@ MODULE_SCOPE void TkpClipDrawableToRect(Display *display, Drawable d, int x,
MODULE_SCOPE void TkpRetainRegion(TkRegion r);
MODULE_SCOPE void TkpReleaseRegion(TkRegion 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 5063fa3..6602564 100644
--- a/macosx/tkMacOSXSubwindows.c
+++ b/macosx/tkMacOSXSubwindows.c
@@ -698,16 +698,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 cb4ffd1..76b2b04 100644
--- a/macosx/tkMacOSXWindowEvent.c
+++ b/macosx/tkMacOSXWindowEvent.c
@@ -382,26 +382,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 9117159..cab2b9a 100644
--- a/macosx/tkMacOSXWm.c
+++ b/macosx/tkMacOSXWm.c
@@ -6174,28 +6174,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 09ff558..8fd56fe 100644
--- a/unix/tkUnixPort.h
+++ b/unix/tkUnixPort.h
@@ -167,6 +167,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 8cc5677..4ef8680 100644
--- a/win/tkWinPort.h
+++ b/win/tkWinPort.h
@@ -125,4 +125,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 */