Tk Source Code

Changes On Branch mac-mojave
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch mac-mojave Excluding Merge-Ins

This is equivalent to a diff from 4c6cdfa4 to 1d33fb26

2018-10-21
13:00
Bugfix [6e8afe516d]: rework of tkBind.c. check-in: 67dd75c7 user: gcramer tags: bug6e8afe516d, tip-532
2018-10-16
02:34
Leaving stub prototypes for layers in Closed-Leaf check-in: 1d33fb26 user: kevin_walzer tags: mac-mojave
02:25
Removing layers, adding drawing context to NSView check-in: 30d60524 user: kevin_walzer tags: mac-mojave
2018-09-30
19:45
Branch to work on broken Tk display on macOS 10.14 Mojave check-in: 30ab59ea user: kevin_walzer tags: mac-mojave
10:00
Fix bitmap-4.1, color-4.1 and cursor-4.1 by cherrypicking the fix [ae13ed65] from trunk. Ticket [ad98f10b3a] dealt with trunk only, the problem appears to be seen in core-8-6-branch as well when running this Tk branch with core-8-branch of Tcl, on Linux Debian 8 at least. check-in: a1a0145c user: fvogel tags: core-8-6-branch
2018-09-29
14:44
Fix [4c84b11111]: Documentation error on page 'event' about <<ThemeChanged>> Closed-Leaf check-in: 919390e3 user: fvogel tags: bug-4c84b111113
2018-09-26
06:26
Fix [9658bc800c]: Right border calculated wrong in Tk menu if borderwidth != activeborderwidth. Patch provided by ingo_brunberg check-in: 2c451736 user: fvogel tags: bug-9658bc800c
2018-09-25
19:13
Fix [f792b457eb]: scrollbar-3.26, 3.27, 3.28, 3.35 tests fail on macOS. The fix consists in using the Linux code for the testmetrics command on macOS, instead of returning the width of the scrollbar (for both cxvscroll and cyvscroll requests). Closed-Leaf check-in: 62785e5e user: fvogel tags: bug-f792b457eb
2018-09-24
19:59
Fix [050d1ea747]: scrollbar-3.50, 6.11, 6.12, 6.25, 6.39 tests fail on macOS Closed-Leaf check-in: 3e32baa0 user: fvogel tags: bug-a84b20eddf, bug-050d1ea747
02:38
Restore some metrics from earlier Cocoa implementation of scorllbar because it seems to render more accurately and smoothly Closed-Leaf check-in: a978b090 user: kevin_walzer tags: mac-scrollbar-metrics-restore
2018-09-23
20:11
Create new branch named "fv-macos-scrollbar-tests" check-in: c514f967 user: fvogel tags: fv-macos-scrollbar-tests
19:57
Fix [874dca4873]: scrollbar-10.[12] fail on macOS check-in: bb66444f user: fvogel tags: bug-874dca4873
2018-09-22
17:59
Patch by Arjen sent to core 2018-09-21 Closed-Leaf check-in: 77c390ba user: oehhar tags: tip474-uniform-mouse-wheel
06:51
Fix [8229232472]: Cascade menu entry indicator wrong colour on Unix. Patch provided by cjmcdonald. check-in: 091bec93 user: fvogel tags: bug-8229232472
2018-09-09
16:04
Fix [719ae3991b]: ttk scrollbar-1.[23] tests fail (regression) Closed-Leaf check-in: 16fdad9d user: fvogel tags: bug-719ae3991b
2018-09-08
17:08
Fix [6fcaaa6f80]: ttk::entry insertion cursor not visible. Patch from Csaba Nemethi. check-in: 28b52309 user: fvogel tags: trunk
17:08
Fix [6fcaaa6f80]: ttk::entry insertion cursor not visible. Patch from Csaba Nemethi. check-in: 4c6cdfa4 user: fvogel tags: core-8-6-branch
16:41
Fix [382712ade6] (X11: 'event generate . <KeyPress>' segfaults) again with a different fix. Patch from Christian Werner. check-in: 1ada7439 user: fvogel tags: core-8-6-branch
2018-09-07
20:08
Ooops, one line should have been removed in previous commit. Plus: don't convert tab to spaces on otherwise unchanged lines Closed-Leaf check-in: 1eaf79fe user: fvogel tags: bug-6fcaaa6f80

Changes to macosx/tkMacOSXDraw.c.

1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
	    /* Convert to Tk coordinates, offset by the window origin. */
	    TkMacOSXSetWithNativeRegion(damageRgn, dmgRgn);
	    if (extraRgn) {
		CFRelease(extraRgn);
	    }

 	    /* Scroll the rectangle. */
 	    [view scrollRect:scrollSrc by:NSMakeSize(dx, -dy)];
  	}
    } else {
	dmgRgn = HIShapeCreateEmpty();
	TkMacOSXSetWithNativeRegion(damageRgn, dmgRgn);
    }

    if (dmgRgn) {







|







1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
	    /* Convert to Tk coordinates, offset by the window origin. */
	    TkMacOSXSetWithNativeRegion(damageRgn, dmgRgn);
	    if (extraRgn) {
		CFRelease(extraRgn);
	    }

 	    /* Scroll the rectangle. */
	    [view scrollRect:scrollSrc by:NSMakeSize(dx, -dy)];
  	}
    } else {
	dmgRgn = HIShapeCreateEmpty();
	TkMacOSXSetWithNativeRegion(damageRgn, dmgRgn);
    }

    if (dmgRgn) {

Changes to macosx/tkMacOSXNotify.c.

273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
	    modalSession = TkMacOSXGetModalSession();
	    	    testEvent = [NSApp nextEventMatchingMask:NSAnyEventMask
					      untilDate:[NSDate distantPast]
						 inMode:GetRunLoopMode(modalSession)
						dequeue:NO];
	    /* We must not steal any events during LiveResize. */
	    if (testEvent && [[testEvent window] inLiveResize]) {
		break;
	    }
	    currentEvent = [NSApp nextEventMatchingMask:NSAnyEventMask
					      untilDate:[NSDate distantPast]
						 inMode:GetRunLoopMode(modalSession)
						dequeue:YES];
	    if (currentEvent) {
		/* Generate Xevents. */
		int oldServiceMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
		NSEvent *processedEvent = [NSApp tkProcessEvent:currentEvent];
		Tcl_SetServiceMode(oldServiceMode);
		if (processedEvent) { /* Should always be non-NULL. */
#ifdef TK_MAC_DEBUG_EVENTS
		    TKLog(@"   event: %@", currentEvent);
#endif
		    if (modalSession) {
			[NSApp _modalSession:modalSession sendEvent:currentEvent];
		    } else {
			[NSApp sendEvent:currentEvent];
		    }
		}
		[currentEvent release];







|











|

|







273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
	    modalSession = TkMacOSXGetModalSession();
	    	    testEvent = [NSApp nextEventMatchingMask:NSAnyEventMask
					      untilDate:[NSDate distantPast]
						 inMode:GetRunLoopMode(modalSession)
						dequeue:NO];
	    /* We must not steal any events during LiveResize. */
	    if (testEvent && [[testEvent window] inLiveResize]) {
	    	break;
	    }
	    currentEvent = [NSApp nextEventMatchingMask:NSAnyEventMask
					      untilDate:[NSDate distantPast]
						 inMode:GetRunLoopMode(modalSession)
						dequeue:YES];
	    if (currentEvent) {
		/* Generate Xevents. */
		int oldServiceMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
		NSEvent *processedEvent = [NSApp tkProcessEvent:currentEvent];
		Tcl_SetServiceMode(oldServiceMode);
		if (processedEvent) { /* Should always be non-NULL. */
		    //#ifdef TK_MAC_DEBUG_EVENTS
		    TKLog(@"   event: %@", currentEvent);
		    //#endif
		    if (modalSession) {
			[NSApp _modalSession:modalSession sendEvent:currentEvent];
		    } else {
			[NSApp sendEvent:currentEvent];
		    }
		}
		[currentEvent release];

Changes to macosx/tkMacOSXPrivate.h.

327
328
329
330
331
332
333
334
335







336
337
338
339
340
341
342
- (void) deleteWorkingText;
@end

@interface TKContentView(TKWindowEvent)
- (void) drawRect: (NSRect) rect;
- (void) generateExposeEvents: (HIShapeRef) shape;
- (void) viewDidEndLiveResize;
- (void) tkToolbarButton: (id) sender;
- (BOOL) isOpaque;







- (BOOL) wantsDefaultClipping;
- (BOOL) acceptsFirstResponder;
- (void) keyDown: (NSEvent *) theEvent;
@end

VISIBILITY_HIDDEN
@interface TKWindow : NSWindow







<

>
>
>
>
>
>
>







327
328
329
330
331
332
333

334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
- (void) deleteWorkingText;
@end

@interface TKContentView(TKWindowEvent)
- (void) drawRect: (NSRect) rect;
- (void) generateExposeEvents: (HIShapeRef) shape;
- (void) viewDidEndLiveResize;

- (BOOL) isOpaque;
/* Prototypes for layer-backed drawing.*/
#if 0
- (BOOL) wantsLayer;
- (BOOL) wantsUpdateLayer;
- (id) layerContentsRedrawPolicy;
- (BOOL) canDrawSubviewsIntoLayer;
#endif
- (BOOL) wantsDefaultClipping;
- (BOOL) acceptsFirstResponder;
- (void) keyDown: (NSEvent *) theEvent;
@end

VISIBILITY_HIDDEN
@interface TKWindow : NSWindow

Changes to macosx/tkMacOSXWindowEvent.c.

328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
	return 0;
    }
    if (!HIShapeIntersectsRect(updateRgn, &bounds)) {
	return 0;
    }

    /*
     * Compute the bounding box of the area that the damage occured in.
     */

    boundsRgn = HIShapeCreateWithRect(&bounds);
    damageRgn = HIShapeCreateIntersection(updateRgn, boundsRgn);
    if (HIShapeIsEmpty(damageRgn)) {
	CFRelease(damageRgn);
	CFRelease(boundsRgn);







|







328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
	return 0;
    }
    if (!HIShapeIntersectsRect(updateRgn, &bounds)) {
	return 0;
    }

    /*
     * Compute the bounding box of the area that the damage occurred in.
     */

    boundsRgn = HIShapeCreateWithRect(&bounds);
    damageRgn = HIShapeCreateIntersection(updateRgn, boundsRgn);
    if (HIShapeIsEmpty(damageRgn)) {
	CFRelease(damageRgn);
	CFRelease(boundsRgn);
353
354
355
356
357
358
359
360

361
362
363
364
365
366
367
368
369
370
371
372
    event.xany.display = Tk_Display(winPtr);
    event.type = Expose;
    event.xexpose.x = damageBounds.origin.x - bounds.origin.x;
    event.xexpose.y = damageBounds.origin.y - bounds.origin.y;
    event.xexpose.width = damageBounds.size.width;
    event.xexpose.height = damageBounds.size.height;
    event.xexpose.count = 0;
    Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);


#ifdef TK_MAC_DEBUG_DRAWING
    NSLog(@"Expose %p {{%d, %d}, {%d, %d}}", event.xany.window, event.xexpose.x,
	event.xexpose.y, event.xexpose.width, event.xexpose.height);
#endif

    /*
     * Generate updates for the children of this window
     */

    for (childPtr = winPtr->childList; childPtr != NULL;
	    childPtr = childPtr->nextPtr) {







|
>

|


|







353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
    event.xany.display = Tk_Display(winPtr);
    event.type = Expose;
    event.xexpose.x = damageBounds.origin.x - bounds.origin.x;
    event.xexpose.y = damageBounds.origin.y - bounds.origin.y;
    event.xexpose.width = damageBounds.size.width;
    event.xexpose.height = damageBounds.size.height;
    event.xexpose.count = 0;
    // Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
    Tk_HandleEvent(&event);

    #ifdef TK_MAC_DEBUG_DRAWING
    NSLog(@"Expose %p {{%d, %d}, {%d, %d}}", event.xany.window, event.xexpose.x,
	event.xexpose.y, event.xexpose.width, event.xexpose.height);
    #endif

    /*
     * Generate updates for the children of this window
     */

    for (childPtr = winPtr->childList; childPtr != NULL;
	    childPtr = childPtr->nextPtr) {
387
388
389
390
391
392
393

394
395
396
397
398
399
400
	}

	/*
	 * TODO: Here we should handle out of process embedding.
	 */
    }


    return 1;
}

/*
 *----------------------------------------------------------------------
 *
 * GenerateActivateEvents --







>







388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
	}

	/*
	 * TODO: Here we should handle out of process embedding.
	 */
    }

    Tcl_SetServiceMode(TCL_SERVICE_ALL);
    return 1;
}

/*
 *----------------------------------------------------------------------
 *
 * GenerateActivateEvents --
764
765
766
767
768
769
770



771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798







799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815

816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910

911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961

























962
963
964
965
966
967
968
 * basis for Tk widgets.  These would then appear as subviews of the
 * TKContentView.  To prevent the AppKit from redrawing and corrupting the Tk
 * Widgets it was necessary to use Apple private API calls.  In order to avoid
 * using private API calls, the NSView-based widgets have been replaced with
 * normal Tk widgets which draw themselves as native widgets by using the
 * HITheme API.
 *



 */

/*Restrict event processing to Expose events.*/
static Tk_RestrictAction
ExposeRestrictProc(
    ClientData arg,
    XEvent *eventPtr)
{
    return (eventPtr->type==Expose && eventPtr->xany.serial==PTR2UINT(arg)
	    ? TK_PROCESS_EVENT : TK_DEFER_EVENT);
}

/*Restrict event processing to ConfigureNotify events.*/
static Tk_RestrictAction
ConfigureRestrictProc(
    ClientData arg,
    XEvent *eventPtr)
{
    return (eventPtr->type==ConfigureNotify ? TK_PROCESS_EVENT : TK_DEFER_EVENT);
}

@implementation TKContentView(TKWindowEvent)

- (void) drawRect: (NSRect) rect
{
    const NSRect *rectsBeingDrawn;
    NSInteger rectsBeingDrawnCount;








    [self getRectsBeingDrawn:&rectsBeingDrawn count:&rectsBeingDrawnCount];

#ifdef TK_MAC_DEBUG_DRAWING
    TKLog(@"-[%@(%p) %s%@]", [self class], self, _cmd, NSStringFromRect(rect));
    [[NSColor colorWithDeviceRed:0.0 green:1.0 blue:0.0 alpha:.1] setFill];
    NSRectFillListUsingOperation(rectsBeingDrawn, rectsBeingDrawnCount,
	    NSCompositeSourceOver);
#endif

    CGFloat height = [self bounds].size.height;
    HIMutableShapeRef drawShape = HIShapeCreateMutable();

    while (rectsBeingDrawnCount--) {
	CGRect r = NSRectToCGRect(*rectsBeingDrawn++);
	r.origin.y = height - (r.origin.y + r.size.height);
	HIShapeUnionWithRect(drawShape, &r);
    }

    if (CFRunLoopGetMain() == CFRunLoopGetCurrent()) {
	[self generateExposeEvents:(HIShapeRef)drawShape];
    } else {
	[self performSelectorOnMainThread:@selector(generateExposeEvents:)
		withObject:(id)drawShape waitUntilDone:NO
		modes:[NSArray arrayWithObjects:NSRunLoopCommonModes,

			NSEventTrackingRunLoopMode, NSModalPanelRunLoopMode,
			nil]];
    }

    CFRelease(drawShape);
}

-(void) setFrameSize: (NSSize)newsize
{
    [super setFrameSize: newsize];
    if ([self inLiveResize]) {
	NSWindow *w = [self window];
	TkWindow *winPtr = TkMacOSXGetTkWindow(w);
	Tk_Window tkwin = (Tk_Window) winPtr;
	unsigned int width = (unsigned int)newsize.width;
	unsigned int height=(unsigned int)newsize.height;
	ClientData oldArg;
    	Tk_RestrictProc *oldProc;

	/* This can be called from outside the Tk event loop.
	 * Since it calls Tcl_DoOneEvent, we need to make sure we
	 * don't clobber the AutoreleasePool set up by the caller.
	 */
	[NSApp _lockAutoreleasePool];

	/*
	 * Try to prevent flickers and flashes.
	 */
	NSDisableScreenUpdates();

	/* Disable Tk drawing until the window has been completely configured.*/
	TkMacOSXSetDrawingEnabled(winPtr, 0);

	 /* Generate and handle a ConfigureNotify event for the new size.*/
	TkGenWMConfigureEvent(tkwin, Tk_X(tkwin), Tk_Y(tkwin), width, height,
			      TK_SIZE_CHANGED | TK_MACOSX_HANDLE_EVENT_IMMEDIATELY);
    	oldProc = Tk_RestrictEvents(ConfigureRestrictProc, NULL, &oldArg);
	while (Tk_DoOneEvent(TK_X_EVENTS|TK_DONT_WAIT)) {}
    	Tk_RestrictEvents(oldProc, oldArg, &oldArg);

	/* Now that Tk has configured all subwindows we can create the clip regions. */
	TkMacOSXSetDrawingEnabled(winPtr, 1);
	TkMacOSXInvalClipRgns(tkwin);
	TkMacOSXUpdateClipRgn(winPtr);

	 /* Finally, generate and process expose events to redraw the window. */
	HIRect bounds = NSRectToCGRect([self bounds]);
	HIShapeRef shape = HIShapeCreateWithRect(&bounds);
	[self generateExposeEvents: shape];
	while (Tk_DoOneEvent(TK_ALL_EVENTS|TK_DONT_WAIT)) {}
	[w displayIfNeeded];
	NSEnableScreenUpdates();
	[NSApp _unlockAutoreleasePool];
    }
}

/*
 * As insurance against bugs that might cause layout glitches during a live
 * resize, we redraw the window one more time at the end of the resize
 * operation.
 */

- (void)viewDidEndLiveResize
{
    HIRect bounds = NSRectToCGRect([self bounds]);
    HIShapeRef shape = HIShapeCreateWithRect(&bounds);
    [super viewDidEndLiveResize];
    [self generateExposeEvents: shape];
}

/* Core method of this class: generates expose events for redrawing.  If the
 * Tcl_ServiceMode is set to TCL_SERVICE_ALL then the expose events will be
 * immediately removed from the Tcl event loop and processed.  Typically, they
 * should be queued, however.
 */
- (void) generateExposeEvents: (HIShapeRef) shape
{
    unsigned long serial;
    CGRect updateBounds;
    int updatesNeeded;
    TkWindow *winPtr = TkMacOSXGetTkWindow([self window]);

    if (!winPtr) {
		return;
    }

    /* Generate Tk Expose events. */
    HIShapeGetBounds(shape, &updateBounds);

    /* All of these events will share the same serial number. */
    serial = LastKnownRequestProcessed(Tk_Display(winPtr));
    updatesNeeded = GenerateUpdates(shape, &updateBounds, winPtr);

    /* Process the Expose events if the service mode is TCL_SERVICE_ALL */
    if (updatesNeeded && Tcl_GetServiceMode() == TCL_SERVICE_ALL) {
	ClientData oldArg;
    	Tk_RestrictProc *oldProc = Tk_RestrictEvents(ExposeRestrictProc,
						     UINT2PTR(serial), &oldArg);
    	while (Tcl_ServiceEvent(TCL_WINDOW_EVENTS)) {}
    	Tk_RestrictEvents(oldProc, oldArg, &oldArg);
    }
}

/*
 * This is no-op on 10.7 and up because Apple has removed this widget,
 * but we are leaving it here for backwards compatibility.
 */
- (void) tkToolbarButton: (id) sender
{
#ifdef TK_MAC_DEBUG_EVENTS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd);
#endif
    XVirtualEvent event;
    int x, y;
    TkWindow *winPtr = TkMacOSXGetTkWindow([self window]);
    Tk_Window tkwin = (Tk_Window) winPtr;
    bzero(&event, sizeof(XVirtualEvent));
    event.type = VirtualEvent;
    event.serial = LastKnownRequestProcessed(Tk_Display(tkwin));
    event.send_event = false;
    event.display = Tk_Display(tkwin);
    event.event = Tk_WindowId(tkwin);
    event.root = XRootWindow(Tk_Display(tkwin), 0);
    event.subwindow = None;
    event.time = TkpGetMS();
    XQueryPointer(NULL, winPtr->window, NULL, NULL,
	    &event.x_root, &event.y_root, &x, &y, &event.state);
    Tk_TopCoordsToWindow(tkwin, x, y, &event.x, &event.y);
    event.same_screen = true;
    event.name = Tk_GetUid("ToolbarButton");
    Tk_QueueWindowEvent((XEvent *) &event, TCL_QUEUE_TAIL);
}

- (BOOL) isOpaque
{
    NSWindow *w = [self window];

      return (w && (([w styleMask] & NSTexturedBackgroundWindowMask) ||
    	    ![w isOpaque]) ? NO : YES);
}


























- (BOOL) wantsDefaultClipping
{
    return NO;
}

- (BOOL) acceptsFirstResponder







>
>
>









|


















>
>
>
>
>
>
>
|


|
|
|
|


|
|

|
|
|
|
|
>
|
|
|
|
|
|
<
|
|
|

|
<
|
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
|
<
<
<
<

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<



















>




|
|
|

|
|

|


<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<






|

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834

835
836
837
838
839

840











841





842




843







































844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877





























878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
 * basis for Tk widgets.  These would then appear as subviews of the
 * TKContentView.  To prevent the AppKit from redrawing and corrupting the Tk
 * Widgets it was necessary to use Apple private API calls.  In order to avoid
 * using private API calls, the NSView-based widgets have been replaced with
 * normal Tk widgets which draw themselves as native widgets by using the
 * HITheme API.
 *
 * We are using layer-backed views, which are more efficient than legacy NSViews
 * because Core Animation handles much more of the work in drawing. The layer    * is updated through the drawRect method. 
 *  
 */

/*Restrict event processing to Expose events.*/
static Tk_RestrictAction
ExposeRestrictProc(
    ClientData arg,
    XEvent *eventPtr)
{
    return (eventPtr->type==Expose && eventPtr->xany.serial==PTR2UINT(arg)
    	    ? TK_PROCESS_EVENT : TK_DEFER_EVENT);
}

/*Restrict event processing to ConfigureNotify events.*/
static Tk_RestrictAction
ConfigureRestrictProc(
    ClientData arg,
    XEvent *eventPtr)
{
    return (eventPtr->type==ConfigureNotify ? TK_PROCESS_EVENT : TK_DEFER_EVENT);
}

@implementation TKContentView(TKWindowEvent)

- (void) drawRect: (NSRect) rect
{
    const NSRect *rectsBeingDrawn;
    NSInteger rectsBeingDrawnCount;

    TkWindow *win = TkMacOSXGetTkWindow([self window]);
    MacDrawable *macwin = (MacDrawable *) win;
    TkMacOSXDrawingContext dc;
    CGContextRef context = dc.context;

    if (context) {
	CGContextSaveGState(context);
	[self getRectsBeingDrawn:&rectsBeingDrawn count:&rectsBeingDrawnCount];

#ifdef TK_MAC_DEBUG_DRAWING
	TKLog(@"-[%@(%p) %s%@]", [self class], self, _cmd, NSStringFromRect(rect));
	[[NSColor colorWithDeviceRed:0.0 green:1.0 blue:0.0 alpha:.1] setFill];
	NSRectFillListUsingOperation(rectsBeingDrawn, rectsBeingDrawnCount,
				     NSCompositeSourceOver);
#endif

	CGFloat height = [self bounds].size.height;
	HIMutableShapeRef drawShape = HIShapeCreateMutable();

	while (rectsBeingDrawnCount--) {
	    CGRect r = NSRectToCGRect(*rectsBeingDrawn++);
	    r.origin.y = height - (r.origin.y + r.size.height);
	    HIShapeUnionWithRect(drawShape, &r);
	}

	if (CFRunLoopGetMain() == CFRunLoopGetCurrent()) {
	    [self generateExposeEvents:(HIShapeRef)drawShape];
	} else {
	    [self performSelectorOnMainThread:@selector(generateExposeEvents:)
				   withObject:(id)drawShape waitUntilDone:NO
					modes:[NSArray arrayWithObjects:NSRunLoopCommonModes,

						       NSEventTrackingRunLoopMode, NSModalPanelRunLoopMode,
						       nil]];
	}

	CFRelease(drawShape);

	CGContextRestoreGState(context);











    }





}













































/* Core method of this class: generates expose events for redrawing.  If the
 * Tcl_ServiceMode is set to TCL_SERVICE_ALL then the expose events will be
 * immediately removed from the Tcl event loop and processed.  Typically, they
 * should be queued, however.
 */
- (void) generateExposeEvents: (HIShapeRef) shape
{
    unsigned long serial;
    CGRect updateBounds;
    int updatesNeeded;
    TkWindow *winPtr = TkMacOSXGetTkWindow([self window]);

    if (!winPtr) {
		return;
    }

    /* Generate Tk Expose events. */
    HIShapeGetBounds(shape, &updateBounds);
    
    /* All of these events will share the same serial number. */
    serial = LastKnownRequestProcessed(Tk_Display(winPtr));
    updatesNeeded = GenerateUpdates(shape, &updateBounds, winPtr);

    /*Process the Expose events if the service mode is TCL_SERVICE_ALL*/
    if ((updatesNeeded) && (Tcl_GetServiceMode() == TCL_SERVICE_ALL)) {
    	ClientData oldArg;
    	Tk_RestrictProc *oldProc = Tk_RestrictEvents(ExposeRestrictProc,
    						     UINT2PTR(serial), &oldArg);
        while (Tcl_ServiceEvent(TCL_WINDOW_EVENTS)) {}
    	Tk_RestrictEvents(oldProc, oldArg, &oldArg);
     }
}































- (BOOL) isOpaque
{
    NSWindow *w = [self window];

      return (w && (([w styleMask] & NSTexturedBackgroundWindowMask) ||
       ![w isOpaque]) ? NO : YES);
}

/* Prototypes for layer-backed drawing.*/
#if 0
- (BOOL) wantsLayer
{
    return YES;

}

- (BOOL) wantsUpdateLayer
{
    return YES;
}


- (id) layerContentsRedrawPolicy
{
    return NSViewLayerContentsRedrawOnSetNeedsDisplay;
}

- (BOOL) canDrawSubviewsIntoLayer
{
    return YES;
}
#endif

- (BOOL) wantsDefaultClipping
{
    return NO;
}

- (BOOL) acceptsFirstResponder

Changes to macosx/tkMacOSXWm.c.

242
243
244
245
246
247
248


249
250
251
252
253
254
255
	}
	if (winPtr->wmInfoPtr->flags & WM_HEIGHT_NOT_RESIZABLE) {
	    frameSize.height = currentFrame.size.height;
	}
    }
    return frameSize;
}


@end

#pragma mark -


/*
 * Forward declarations for procedures defined in this file:







>
>







242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
	}
	if (winPtr->wmInfoPtr->flags & WM_HEIGHT_NOT_RESIZABLE) {
	    frameSize.height = currentFrame.size.height;
	}
    }
    return frameSize;
}


@end

#pragma mark -


/*
 * Forward declarations for procedures defined in this file:
414
415
416
417
418
419
420
421




422

423
424
425
426
427
428
429
    TkWindow *winPtr = TkMacOSXGetTkWindow(self);
    Tk_Window tkwin = (TkWindow*)winPtr;
    Tcl_Interp *interp = Tk_Interp(tkwin);

    TkMacOSXMakeFullscreen(winPtr, self, 0, interp);
    [[NSStatusBar systemStatusBar] removeStatusItem: exitFullScreen];
}





#endif

@end

@implementation TKWindow(TKWm)

- (BOOL) canBecomeKeyWindow
{
    TkWindow *winPtr = TkMacOSXGetTkWindow(self);








>
>
>
>

>







416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
    TkWindow *winPtr = TkMacOSXGetTkWindow(self);
    Tk_Window tkwin = (TkWindow*)winPtr;
    Tcl_Interp *interp = Tk_Interp(tkwin);

    TkMacOSXMakeFullscreen(winPtr, self, 0, interp);
    [[NSStatusBar systemStatusBar] removeStatusItem: exitFullScreen];
}

-(BOOL) isOpaque {
    return YES;
}

#endif

@end

@implementation TKWindow(TKWm)

- (BOOL) canBecomeKeyWindow
{
    TkWindow *winPtr = TkMacOSXGetTkWindow(self);
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
	{ "ignoreClicks",	kWindowIgnoreClicksAttribute		     },
	{ "noConstrain",	kWindowNoConstrainAttribute		     },
	{ "doesNotHide",	tkWindowDoesNotHideAttribute		     },
	{ "canJoinAllSpaces",	tkCanJoinAllSpacesAttribute		     },
	{ "moveToActiveSpace",	tkMoveToActiveSpaceAttribute		     },
	{ "nonActivating",	tkNonactivatingPanelAttribute		     },
	{ "hud",		tkHUDWindowAttribute			     },
	{ "black",		0			                     },
	{ "dark",		0			                     },
	{ "light",		0			                     },
	{ "gray",		0			                     },
	{ "red",		0 			                     },
	{ "green",		0                			     },
	{ "blue",		0           			             },
	{ "cyan",		0			                     },
	{ "yellow",		0			                     },
	{ "magenta",		0  			                     },
	{ "orange",		0 			                     },
	{ "purple",		0			                     },
	{ "brown",		0			                     },
	{ "clear",		0			                     },
	{ "opacity",		0			                     },
	{ NULL }
    };

    int index, i;
    WmInfo *wmPtr = winPtr->wmInfoPtr;

    if (objc == 3) {







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







5405
5406
5407
5408
5409
5410
5411















5412
5413
5414
5415
5416
5417
5418
	{ "ignoreClicks",	kWindowIgnoreClicksAttribute		     },
	{ "noConstrain",	kWindowNoConstrainAttribute		     },
	{ "doesNotHide",	tkWindowDoesNotHideAttribute		     },
	{ "canJoinAllSpaces",	tkCanJoinAllSpacesAttribute		     },
	{ "moveToActiveSpace",	tkMoveToActiveSpaceAttribute		     },
	{ "nonActivating",	tkNonactivatingPanelAttribute		     },
	{ "hud",		tkHUDWindowAttribute			     },















	{ NULL }
    };

    int index, i;
    WmInfo *wmPtr = winPtr->wmInfoPtr;

    if (objc == 3) {
5640
5641
5642
5643
5644
5645
5646

5647
5648


5649


5650
5651
5652
5653
5654
5655
5656
	    tkMacOSXZeroScreenHeight - (tkMacOSXZeroScreenTop + 5 +
	    structureRect.origin.y + structureRect.size.height + 200), 200, 200);
    NSWindow *window = [[winClass alloc] initWithContentRect:contentRect
	    styleMask:styleMask backing:NSBackingStoreBuffered defer:YES];
    if (!window) {
    	Tcl_Panic("couldn't allocate new Mac window");
    }

    TKContentView *contentView = [[TKContentView alloc]
				     initWithFrame:NSZeroRect];


    [window setColorSpace:[NSColorSpace deviceRGBColorSpace]];


    [window setContentView:contentView];
    [contentView release];
    [window setDelegate:NSApp];
    [window setAcceptsMouseMovedEvents:YES];
    [window setReleasedWhenClosed:NO];
    [window setAutodisplay:NO];
    if (styleMask & NSUtilityWindowMask) {







>
|
|
>
>

>
>







5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
	    tkMacOSXZeroScreenHeight - (tkMacOSXZeroScreenTop + 5 +
	    structureRect.origin.y + structureRect.size.height + 200), 200, 200);
    NSWindow *window = [[winClass alloc] initWithContentRect:contentRect
	    styleMask:styleMask backing:NSBackingStoreBuffered defer:YES];
    if (!window) {
    	Tcl_Panic("couldn't allocate new Mac window");
    }
 
     TKContentView *contentView = [[TKContentView alloc]
        initWithFrame:NSZeroRect];
    /*Remove hard-coded colorspace on 10.14 and later for Dark Mode.*/
    #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_14
    [window setColorSpace:[NSColorSpace deviceRGBColorSpace]];
    #endif
  
    [window setContentView:contentView];
    [contentView release];
    [window setDelegate:NSApp];
    [window setAcceptsMouseMovedEvents:YES];
    [window setReleasedWhenClosed:NO];
    [window setAutodisplay:NO];
    if (styleMask & NSUtilityWindowMask) {
5674
5675
5676
5677
5678
5679
5680


5681
5682
5683
5684
5685
5686
5687
    geometry.size.width +=  structureRect.size.width;
    geometry.size.height += structureRect.size.height;
    geometry.origin.y = tkMacOSXZeroScreenHeight - (geometry.origin.y +
	    geometry.size.height);
    [window setFrame:geometry display:NO];
    TkMacOSXRegisterOffScreenWindow((Window) macWin, window);
    macWin->flags |= TK_HOST_EXISTS;


}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXRegisterOffScreenWindow --
 *







>
>







5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
    geometry.size.width +=  structureRect.size.width;
    geometry.size.height += structureRect.size.height;
    geometry.origin.y = tkMacOSXZeroScreenHeight - (geometry.origin.y +
	    geometry.size.height);
    [window setFrame:geometry display:NO];
    TkMacOSXRegisterOffScreenWindow((Window) macWin, window);
    macWin->flags |= TK_HOST_EXISTS;
    /*Make sure service mode is set to process events.*/
    Tcl_SetServiceMode(TCL_SERVICE_ALL);
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXRegisterOffScreenWindow --
 *