From ddb5db1e6f025f1852420243feca27d491051596 Mon Sep 17 00:00:00 2001 From: culler Date: Wed, 24 Oct 2018 16:43:45 +0000 Subject: Added a boolean state variable so a displayProc can check if it is being run by drawRect. --- generic/tkTextDisp.c | 22 ++++++++++++++++++++-- macosx/tkMacOSXInit.c | 28 +++++++++------------------- macosx/tkMacOSXInt.h | 2 ++ macosx/tkMacOSXPrivate.h | 2 ++ macosx/tkMacOSXWindowEvent.c | 27 +++++++++++++++++++++++++++ 5 files changed, 60 insertions(+), 21 deletions(-) diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c index 32ce558..35a43d4 100644 --- a/generic/tkTextDisp.c +++ b/generic/tkTextDisp.c @@ -206,10 +206,28 @@ typedef struct TextStyle { * Macro to make debugging/testing logging a little easier. */ +#ifndef MAC_OSX_TK #define LOG(toVar,what) \ Tcl_SetVar2(textPtr->interp, toVar, NULL, (what), \ TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT) +#define CLEAR(var) \ + Tcl_SetVar2(interp, var, NULL, "", TCL_GLOBAL_ONLY) +#else +/* + * Drawing procedures are sometimes run because the system has decided + * to redraw the window. This can corrupt the data that a test is + * trying to collect. So we don't write to the logging variables when + * the drawing procedure is being run that way. + */ +#define LOG(toVar,what) \ + if (!TkpMacOSXAppIsDrawing()) \ + Tcl_SetVar2(textPtr->interp, toVar, NULL, (what), \ + TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT) +#define CLEAR(var) \ + if (!TkpMacOSXAppIsDrawing()) \ + Tcl_SetVar2(interp, var, NULL, "", TCL_GLOBAL_ONLY) +#endif /* * The following structure describes one line of the display, which may be * either part or all of one line of the text. @@ -4136,7 +4154,7 @@ DisplayText( Tcl_Preserve(interp); if (tkTextDebug) { - Tcl_SetVar2(interp, "tk_textRelayout", NULL, "", TCL_GLOBAL_ONLY); + CLEAR("tk_textRelayout"); } if (!Tk_IsMapped(textPtr->tkwin) || (dInfoPtr->maxX <= dInfoPtr->x) @@ -4147,7 +4165,7 @@ DisplayText( } numRedisplays++; if (tkTextDebug) { - Tcl_SetVar2(interp, "tk_textRedraw", NULL, "", TCL_GLOBAL_ONLY); + CLEAR("tk_textRedraw"); } /* diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c index c12c394..b85b66d 100644 --- a/macosx/tkMacOSXInit.c +++ b/macosx/tkMacOSXInit.c @@ -16,7 +16,6 @@ #include "tkMacOSXPrivate.h" #include -#include #include #include @@ -29,8 +28,6 @@ static char tkLibPath[PATH_MAX + 1] = ""; static char scriptPath[PATH_MAX + 1] = ""; -long tkMacOSXMacOSXVersion = 0; - #pragma mark TKApplication(TKInit) @interface TKApplication(TKKeyboard) @@ -48,6 +45,8 @@ long tkMacOSXMacOSXVersion = 0; @implementation TKApplication @synthesize poolLock = _poolLock; +@synthesize macMinorVersion = _macMinorVersion; +@synthesize isDrawing = _isDrawing; @end /* @@ -164,7 +163,13 @@ long tkMacOSXMacOSXVersion = 0; minorVersion = systemVersion.minorVersion; #endif [NSApp setMacMinorVersion: minorVersion]; - + + /* + * We are not drawing yet. + */ + + [NSApp setIsDrawing: NO]; + /* * Be our own delegate. */ @@ -268,7 +273,6 @@ TkpInit( */ if (!initialized) { - struct utsname name; struct stat st; initialized = 1; @@ -281,20 +285,6 @@ TkpInit( # error Mac OS X 10.6 required #endif - if (!uname(&name)) { - tkMacOSXMacOSXVersion = (strtod(name.release, NULL) + 96) * 10; - } - /*Check for new versioning scheme on Yosemite (10.10) and later.*/ - if (MAC_OS_X_VERSION_MIN_REQUIRED > 100000) { - tkMacOSXMacOSXVersion = MAC_OS_X_VERSION_MIN_REQUIRED/100; - } - if (tkMacOSXMacOSXVersion && MAC_OS_X_VERSION_MIN_REQUIRED < 100000 && - tkMacOSXMacOSXVersion/10 < MAC_OS_X_VERSION_MIN_REQUIRED/10) { - Tcl_Panic("Mac OS X 10.%d or later required !", - (MAC_OS_X_VERSION_MIN_REQUIRED/10)-100); - } - - #ifdef TK_FRAMEWORK /* * When Tk is in a framework, force tcl_findLibrary to look in the diff --git a/macosx/tkMacOSXInt.h b/macosx/tkMacOSXInt.h index 52be0e1..2972d46 100644 --- a/macosx/tkMacOSXInt.h +++ b/macosx/tkMacOSXInt.h @@ -199,6 +199,8 @@ 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 TkpMacOSXAppIsDrawing(void); + /* * Include the stubbed internal platform-specific API. */ diff --git a/macosx/tkMacOSXPrivate.h b/macosx/tkMacOSXPrivate.h index 7337400..ea4c750 100644 --- a/macosx/tkMacOSXPrivate.h +++ b/macosx/tkMacOSXPrivate.h @@ -266,10 +266,12 @@ VISIBILITY_HIDDEN /* The Objective C runtime used on i386 requires this. */ int _poolLock; int _macMinorVersion; + Bool _isDrawing; #endif } @property int poolLock; @property int macMinorVersion; +@property Bool isDrawing; @end @interface TKApplication(TKInit) diff --git a/macosx/tkMacOSXWindowEvent.c b/macosx/tkMacOSXWindowEvent.c index 6e9948a..f659ad5 100644 --- a/macosx/tkMacOSXWindowEvent.c +++ b/macosx/tkMacOSXWindowEvent.c @@ -297,6 +297,31 @@ extern NSString *NSWindowDidOrderOffScreenNotification; /* *---------------------------------------------------------------------- * + * TkpMacOSXAppIsDrawing -- + * + * 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. + * + * Results: + * True only while running the drawRect method of a TKContentView; + * + * Side effects: + * None + * + *---------------------------------------------------------------------- + */ +MODULE_SCOPE Bool +TkpMacOSXAppIsDrawing(void) { + return [NSApp isDrawing]; +} + + +/* + *---------------------------------------------------------------------- + * * GenerateUpdates -- * * Given a Macintosh update region and a Tk window this function geneates @@ -801,6 +826,7 @@ ConfigureRestrictProc( const NSRect *rectsBeingDrawn; NSInteger rectsBeingDrawnCount; + [NSApp setIsDrawing: YES]; [self getRectsBeingDrawn:&rectsBeingDrawn count:&rectsBeingDrawnCount]; #ifdef TK_MAC_DEBUG_DRAWING @@ -820,6 +846,7 @@ ConfigureRestrictProc( } [self generateExposeEvents:(HIShapeRef)drawShape]; CFRelease(drawShape); + [NSApp setIsDrawing: NO]; } -(void) setFrameSize: (NSSize)newsize -- cgit v0.12