16#ifdef DEBUG_ROOT_COCOA
28#include <Availability.h>
36#include "RConfigure.h"
53#pragma mark - Create a window or a view.
64 winRect.size.width = w;
65 winRect.size.height =
h;
67 const NSUInteger styleMask = kTitledWindowMask | kClosableWindowMask |
68 kMiniaturizableWindowMask | kResizableWindowMask;
72 backing : NSBackingStoreBuffered
74 windowAttributes : attr];
76 throw std::runtime_error(
"CreateTopLevelWindow failed");
89 viewRect.origin.x =
x;
90 viewRect.origin.y =
y;
91 viewRect.size.width = w;
92 viewRect.size.height =
h;
96 throw std::runtime_error(
"CreateChildView failed");
101#pragma mark - root window (does not really exist, it's our desktop built of all screens).
107 assert(attr != 0 &&
"GetRootWindowAttributes, parameter 'attr' is null");
110 NSArray *
const screens = [NSScreen screens];
111 assert(screens != nil &&
"screens array is nil");
112 NSScreen *
const mainScreen = [screens objectAtIndex : 0];
113 assert(mainScreen != nil &&
"screen with index 0 is nil");
118 "GetRootWindowAttributes, gVirtualX is either null or has a wrong type");
132 attr->
fDepth = NSBitsPerPixelFromDepth([mainScreen depth]);
138#pragma mark - Coordinate conversions.
143 assert(window != nil &&
"ConvertPointFromBaseToScreen, parameter 'window' is nil");
149 tmpRect.origin = windowPoint;
150 tmpRect.size = NSMakeSize(1., 1.);
151 tmpRect = [window convertRectToScreen : tmpRect];
153 return tmpRect.origin;
159 assert(window != nil &&
"ConvertPointFromScreenToBase, parameter 'window' is nil");
165 tmpRect.origin = screenPoint;
166 tmpRect.size = NSMakeSize(1., 1.);
167 tmpRect = [window convertRectFromScreen : tmpRect];
169 return tmpRect.origin;
180 "GlobalYCocoaToROOT, gVirtualX is either nul or has a wrong type");
191 "GlobalXCocoaToROOT, gVirtualX is either nul or has a wrong type");
194 return int(xCocoa - frame.
fX);
201 "GlobalYROOTToCocoa, gVirtualX is either nul or has a wrong type");
211 "GlobalXROOTToCocoa, gVirtualX is either nul or has a wrong type");
214 return int(frame.
fX + xROOT);
220 assert(parentView != nil &&
"LocalYCocoaToROOT, parent view is nil");
222 return int(parentView.frame.size.height - yCocoa);
229 assert(parentView != nil &&
"LocalYROOTToCocoa, parent view is nil");
231 return int(parentView.frame.size.height - yROOT);
239 assert(drawable != nil &&
"LocalYROOTToCocoa, drawable is nil");
241 return int(drawable.fHeight - yROOT);
247 assert(from != nil &&
"TranslateToScreen, parameter 'from' is nil");
249 const NSPoint winPoint = [from convertPoint : point toView : nil];
261 assert(to != nil &&
"TranslateFromScreen, parameter 'to' is nil");
267 return [to convertPoint : point fromView : nil];
274 assert(from != nil &&
"TranslateCoordinates, parameter 'from' is nil");
275 assert(to != nil &&
"TranslateCoordinates, parameter 'to' is nil");
277 if ([from window] == [to window]) {
279 return [to convertPoint : sourcePoint fromView : from];
287 const NSPoint win1Point = [from convertPoint : sourcePoint toView : nil];
291 return [to convertPoint : win2Point fromView : nil];
298 assert(view != nil &&
"ScreenPointIsInView, parameter 'view' is nil");
301 point.x =
x, point.y =
y;
303 const NSRect viewFrame = view.frame;
305 if (point.x < 0 || point.x > viewFrame.size.width)
307 if (point.y < 0 || point.y > viewFrame.size.height)
313#pragma mark - Different FindView/Window functions iterating on the ROOT's windows/views.
321 NSArray *
const orderedWindows = [NSApp orderedWindows];
322 for (
NSWindow *window in orderedWindows) {
340 assert(children != nil &&
"FindDNDAwareViewInPoint, parameter 'children' is nil");
345 NSEnumerator *
const reverseEnumerator = [children reverseObjectEnumerator];
349 if (child.fIsDNDAware && child.fID != dragWinID && child.fID != inputWinID)
353 inputWinID,
x,
y, maxDepth - 1);
372 NSArray *
const orderedWindows = [NSApp orderedWindows];
373 for (
NSWindow *window in orderedWindows) {
389 if (testView.fIsDNDAware && testView.fID != dragWinID && testView.fID != inputWinID)
393 NSArray *
const children = [testView subviews];
412 NSArray *
const orderedWindows = [NSApp orderedWindows];
413 for (
NSWindow *nsWindow in orderedWindows) {
425 const NSPoint mousePosition = [qWindow mouseLocationOutsideOfEventStream];
426 const NSSize windowSize = qWindow.frame.size;
427 if (mousePosition.x >= 0 && mousePosition.x <= windowSize.width &&
428 mousePosition.y >= 0 && mousePosition.y <= windowSize.height)
441 const NSPoint mousePosition = [topLevel mouseLocationOutsideOfEventStream];
455 assert(pointerEvent != nil &&
456 "FindWindowForPointerEvent, parameter 'pointerEvent' is nil");
460 NSArray *
const orderedWindows = [NSApp orderedWindows];
461 for (
NSWindow *nsWindow in orderedWindows) {
474 NSPoint mousePosition = [pointerEvent locationInWindow];
477 if ([pointerEvent window]) {
487 const NSSize windowSize = qWindow.frame.size;
488 if (mousePosition.x >= 0 && mousePosition.x <= windowSize.width &&
489 mousePosition.y >= 0 && mousePosition.y <= windowSize.height)
502 assert(pointerEvent != nil &&
503 "FindViewForPointerEvent, parameter 'pointerEvent' is nil");
508 NSPoint mousePosition = [pointerEvent locationInWindow];
509 if ([pointerEvent window])
522#pragma mark - Downscale image ("reading color bits" on retina macs).
527 assert(w != 0 &&
h != 0 &&
"DownscaledImageData, invalid geometry");
528 assert(image !=
nullptr &&
"DonwscaledImageData, invalid parameter 'image'");
530 std::vector<unsigned char> result;
532 result.resize(w *
h * 4);
533 }
catch (
const std::bad_alloc &) {
534 NSLog(
@"DownscaledImageData, memory allocation failed");
539 if (!colorSpace.
Get()) {
540 NSLog(
@"DownscaledImageData, CGColorSpaceCreateDeviceRGB failed");
545 w * 4, colorSpace.
Get(),
546 kCGImageAlphaPremultipliedLast, NULL, 0));
548 NSLog(
@"DownscaledImageData, CGBitmapContextCreateWithData failed");
552 CGContextDrawImage(ctx.
Get(), CGRectMake(0, 0, w,
h), image);
557#pragma mark - "Focus management" - just make another window key window.
563 if (![NSApp isActive])
568 NSArray *
const orderedWindows = [NSApp orderedWindows];
569 for (
NSWindow *nsWindow in orderedWindows) {
581 [qWindow makeKeyAndOrderFront : qWindow];
586#pragma mark - 'shape mask' - to create a window with arbitrary (probably non-rectangle) shape.
591 assert(view != nil &&
"ClipToShapeMask, parameter 'view' is nil");
592 assert(ctx != 0 &&
"ClipToShapeMask, parameter 'ctx' is null");
594 QuartzWindow *
const topLevelParent = view.fQuartzWindow;
596 "ClipToShapeMask, fShapeCombineMask is nil on a top-level window");
598 "ClipToShapeMask, shape mask is null");
604 if (!view.fParentView) {
610 NSRect clipRect = view.frame;
612 clipRect.origin = [view.fParentView convertPoint : clipRect.origin
613 toView : [view window].contentView];
615 clipRect.origin.y + clipRect.size.height);
620 NSRectToCGRect(clipRect)));
621 clipRect.origin = NSPoint();
622 CGContextClipToMask(ctx, NSRectToCGRect(clipRect), clipImageGuard.
Get());
626 CGContextClipToRect(ctx, rect);
631#pragma mark - Window's geometry and attributes.
636 assert(attr != 0 &&
"SetWindowAttributes, parameter 'attr' is null");
637 assert(window != nil &&
"SetWindowAttributes, parameter 'window' is nil");
657 [qw setAlphaValue : 0.95];
660 window.fOverrideRedirect = YES;
667 assert(win != nil &&
"GetWindowGeometry, parameter 'win' is nil");
668 assert(dst != 0 &&
"GetWindowGeometry, parameter 'dst' is null");
680 assert(window != nil &&
"GetWindowAttributes, parameter 'window' is nil");
681 assert(dst != 0 &&
"GetWindowAttributes, parameter 'attr' is null");
690 dst->
fDepth = window.fDepth;
695 dst->
fClass = window.fClass;
729#pragma mark - Comparators (I need them when changing a window's z-order).
733#ifdef MAC_OS_X_VERSION_10_11
739 id topView = (
id)context;
740 if (view1 == topView)
741 return NSOrderedAscending;
742 if (view2 == topView)
743 return NSOrderedDescending;
745 return NSOrderedSame;
750#ifdef MAC_OS_X_VERSION_10_11
756 id topView = (
id)context;
757 if (view1 == topView)
758 return NSOrderedDescending;
759 if (view2 == topView)
760 return NSOrderedAscending;
762 return NSOrderedSame;
765#pragma mark - Cursor's area.
770 assert(image != nil &&
"CursroHotSpot, parameter 'image' is nil");
772 const NSSize imageSize = image.size;
775 return NSMakePoint(imageSize.width, imageSize.height / 2);
777 return NSMakePoint(imageSize.width / 2, imageSize.height / 2);
784 const char *pngFileName = 0;
786 switch (currentCursor) {
788 pngFileName =
"move_cursor.png";
791 pngFileName =
"hor_arrow_cursor.png";
794 pngFileName =
"ver_arrow_cursor.png";
797 pngFileName =
"right_arrow_cursor.png";
800 pngFileName =
"rotate.png";
804 pngFileName =
"top_right_cursor.png";
808 pngFileName =
"top_left_cursor.png";
817 if (!path || path[0] == 0) {
822 NSString *nsPath = [NSString stringWithFormat :
@"%s", path];
823 NSImage *
const cursorImage = [[NSImage alloc] initWithContentsOfFile : nsPath];
829 NSCursor *
const customCursor = [[[NSCursor alloc] initWithImage : cursorImage
830 hotSpot : hotSpot] autorelease];
832 [cursorImage release];
852 NSCursor *cursor = nil;
853 switch (currentCursor) {
855 cursor = [NSCursor crosshairCursor];
858 cursor = [NSCursor arrowCursor];
861 cursor = [NSCursor openHandCursor];
864 cursor = [NSCursor resizeLeftCursor];
867 cursor = [NSCursor resizeRightCursor];
870 cursor = [NSCursor resizeUpCursor];
873 cursor = [NSCursor resizeDownCursor];
876 cursor = [NSCursor IBeamCursor];
894#pragma mark - Workarounds for a text view and its descendants.
905 return dynamic_cast<const TGTextView*
>(window);
911 assert(view != nil &&
"ViewIsTextView, parameter 'view' is nil");
919 assert(view != nil &&
"ViewIsTextViewFrame, parameter 'view' is nil");
934 if (!view.fParentView)
955 assert(view != nil &&
"ViewIsHtmlView, parameter 'view' is nil");
964 assert(view != nil &&
"ViewIsHtmlViewFrame, parameter 'view' is nil");
979 if (!view.fParentView)
988 assert(textView != nil &&
"FrameForTextView, parameter 'textView' is nil");
1001 assert(htmlView != nil &&
"FrameForHtmlView, parameter 'htmlView' is nil");
1011#pragma mark - Workarounds for 'paint out of paint events'.
1016 assert(view != nil &&
"LockFocus, parameter 'view' is nil");
1017 assert([view isKindOfClass : [
QuartzView class]] &&
1018 "LockFocus, QuartzView is expected");
1020 if ([view lockFocusIfCanDraw]) {
1021 NSGraphicsContext *nsContext = [NSGraphicsContext currentContext];
1022 assert(nsContext != nil &&
"LockFocus, currentContext is nil");
1024 assert(currContext != 0 &&
"LockFocus, graphicsPort is null");
1037 assert(view != nil &&
"UnlockFocus, parameter 'view' is nil");
1038 assert([view isKindOfClass : [
QuartzView class]] &&
1039 "UnlockFocus, QuartzView is expected");
1054#ifdef DEBUG_ROOT_COCOA
1056#pragma mark - 'loggers'.
1066 static std::ofstream logfile(
"win_attr.txt");
1070 logfile<<
"win "<<winID<<
": BackPixmap\n";
1072 logfile<<
"win "<<winID<<
": BackPixel\n";
1074 logfile<<
"win "<<winID<<
": BorderPixmap\n";
1076 logfile<<
"win "<<winID<<
": BorderPixel\n";
1078 logfile<<
"win "<<winID<<
": BorderWidth\n";
1080 logfile<<
"win "<<winID<<
": BitGravity\n";
1082 logfile<<
"win "<<winID<<
": WinGravity\n";
1084 logfile<<
"win "<<winID<<
": BackingStore\n";
1086 logfile<<
"win "<<winID<<
": BackingPlanes\n";
1088 logfile<<
"win "<<winID<<
": BackingPixel\n";
1090 logfile<<
"win "<<winID<<
": OverrideRedirect\n";
1092 logfile<<
"win "<<winID<<
": SaveUnder\n";
1094 logfile<<
"win "<<winID<<
": EventMask\n";
1096 logfile<<
"win "<<winID<<
": DontPropagate\n";
1098 logfile<<
"win "<<winID<<
": Colormap\n";
1100 logfile<<
"win "<<winID<<
": Cursor\n";
1104void print_mask_info(
ULong_t mask)
1107 NSLog(
@"button press mask");
1109 NSLog(
@"button release mask");
1111 NSLog(
@"exposure mask");
1113 NSLog(
@"pointer motion mask");
1115 NSLog(
@"button motion mask");
1117 NSLog(
@"enter notify mask");
1119 NSLog(
@"leave notify mask");
1127- (
void) drawRect : (NSRect) dirtyRect
1129 [
super drawRect:dirtyRect];
1131 NSGraphicsContext *nsContext = [NSGraphicsContext currentContext];
1141 CGContextSetRGBStrokeColor(cgContext, 0., 0., 0., 1.);
1142 CGContextSetLineWidth(cgContext, 1.);
1144 CGContextBeginPath(cgContext);
1145 CGContextMoveToPoint(cgContext, self.start1.x, self.start1.y);
1146 CGContextAddLineToPoint(cgContext, self.end1.x, self.end1.y);
1147 CGContextStrokePath(cgContext);
1149 CGContextBeginPath(cgContext);
1150 CGContextMoveToPoint(cgContext, self.start2.x, self.start2.y);
1151 CGContextAddLineToPoint(cgContext, self.end2.x, self.end2.y);
1152 CGContextStrokePath(cgContext);
1159- (instancetype)
init
1161 if (self = [super
init])
1163 self.styleMask = NSWindowStyleMaskBorderless;
1165 self.hasShadow = NO;
1166 self.backgroundColor = NSColor.clearColor;
1167 self.ignoresMouseEvents = YES;
1173#pragma mark - suppress the normal window behavior.
1174- (BOOL)canBecomeKeyWindow
1178- (BOOL)canBecomeMainWindow
1191#pragma mark - QuartzWindow's life cycle.
1194- (
id) initWithContentRect : (NSRect) contentRect styleMask : (NSUInteger) windowStyle
1195 backing : (NSBackingStoreType) bufferingType defer : (BOOL) deferCreation
1198 self = [
super initWithContentRect : contentRect styleMask : windowStyle
1199 backing : bufferingType defer : deferCreation];
1203 [
self setAllowsConcurrentViewDrawing : NO];
1205 self.delegate = self;
1207 NSRect contentViewRect = contentRect;
1208 contentViewRect.origin.x = 0.f;
1209 contentViewRect.origin.y = 0.f;
1213 [
self setContentView : fContentView];
1215 [fContentView release];
1233 assert(glView != nil &&
"-initWithGLView, parameter 'glView' is nil");
1238 NSRect contentRect = glView.frame;
1239 contentRect.origin = NSPoint();
1241 self = [
super initWithContentRect : contentRect styleMask : styleMask
1242 backing : NSBackingStoreBuffered defer : NO];
1246 [
self setAllowsConcurrentViewDrawing : NO];
1247 self.delegate = self;
1249 [
self setContentView : fContentView];
1261 [fShapeCombineMask release];
1274 [
super setContentView:cv];
1282- (
void) setFIsDeleted : (BOOL) deleted
1287#pragma mark - Forwaring: I want to forward a lot of property setters/getters to the content view.
1290- (
void) forwardInvocation : (NSInvocation *) anInvocation
1295 if ([
fContentView respondsToSelector : [anInvocation selector]]) {
1296 [anInvocation invokeWithTarget : fContentView];
1298 [
super forwardInvocation : anInvocation];
1303- (NSMethodSignature*) methodSignatureForSelector : (
SEL) selector
1305 NSMethodSignature *signature = [
super methodSignatureForSelector : selector];
1309 signature = [fContentView methodSignatureForSelector : selector];
1324 assert(window != nil &&
"-addTransientWindow:, parameter 'window' is nil");
1333 [
self addChildWindow : window ordered : NSWindowAbove];
1339- (
void) makeKeyAndOrderFront : (
id) sender
1341#pragma unused(sender)
1346#ifdef MAC_OS_X_VERSION_10_9
1347 [
self setCollectionBehavior : NSWindowCollectionBehaviorMoveToActiveSpace];
1349 [
self setCollectionBehavior : NSWindowCollectionBehaviorCanJoinAllSpaces];
1352 [
super makeKeyAndOrderFront : self];
1354 [
self setCollectionBehavior : NSWindowCollectionBehaviorDefault];
1358- (
void) setFDelayedTransient : (BOOL) d
1373 [fShapeCombineMask release];
1381#pragma mark - X11Drawable's protocol.
1402 return self.screen.backingScaleFactor;
1420 return self.frame.size.width;
1429 assert(
fContentView != nil &&
"-fHeight:, content view is nil");
1435- (
void) setDrawableSize : (NSSize) newSize
1438 assert(!(newSize.width < 0) &&
"-setDrawableSize:, width is negative");
1439 assert(!(newSize.height < 0) &&
"-setDrawableSize:, height is negative");
1441 NSRect frame = self.frame;
1445 frame.origin.y = frame.origin.y + frame.size.height - newSize.height - dY;
1446 frame.size = newSize;
1447 frame.size.height += dY;
1448 [
self setFrame : frame display : YES];
1452- (
void) setX : (
int) x Y : (
int) y width : (
unsigned) w height : (
unsigned) h
1454 NSSize newSize = {};
1457 [
self setContentSize : newSize];
1460 NSPoint topLeft = {};
1464 [
self setFrameTopLeftPoint : topLeft];
1468- (
void) setX : (
int) x Y : (
int) y
1470 NSPoint topLeft = {};
1474 [
self setFrameTopLeftPoint : topLeft];
1479 clipOrigin : (
X11::Point) clipXY toPoint : (
X11::Point) dstPoint
1484 [fContentView copy : src area : area withMask : mask clipOrigin : clipXY toPoint : dstPoint];
1488- (
unsigned char *) readColorBits : (
X11::Rectangle) area
1493 return [fContentView readColorBits : area];
1496#pragma mark - CrosshairWindow/View
1505 [
self adjustCrosshairWindowGeometry:special];
1506 [
self addChildWindow : special ordered : NSWindowAbove];
1514 [
self adjustCrosshairWindowGeometry:win];
1520 assert(win &&
"invalid (nil) parameter 'win'");
1521 auto frame = self.contentView.frame;
1522 frame = [
self convertRectToScreen:frame];
1523 [win setFrame:frame display:NO];
1533 [
self removeChildWindow : win];
1540 auto children = [
self childWindows];
1541 for (
NSWindow *child in children) {
1549#pragma mark - X11Window protocol's implementation.
1560#pragma unused(parent)
1578- (
void) setFBackgroundPixel : (
unsigned long) backgroundColor
1584 CGFloat rgba[] = {0., 0., 0., 1.};
1587 [
self setBackgroundColor : [NSColor colorWithColorSpace : [NSColorSpace deviceRGBColorSpace] components : rgba count : 4]];
1616- (
void) addChild : (
NSView<X11Window> *) child
1618 assert(child != nil &&
"-addChild:, parameter 'child' is nil");
1622 assert([child isKindOfClass : [
QuartzView class]] &&
1623 "-addChild: gl view in a top-level window as content view is not supported");
1626 [
self setContentView : child];
1629 [fContentView addChild : child];
1638 assert(attr &&
"-getAttributes:, parameter 'attr' is nil");
1646 assert(attr != 0 &&
"-setAttributes:, parameter 'attr' is null");
1648#ifdef DEBUG_ROOT_COCOA
1649 log_attributes(attr, self.fID);
1663 [fContentView setHidden : NO];
1664 [
self makeKeyAndOrderFront : self];
1665 [fContentView configureNotifyTree];
1669 [fMainWindow addChildWindow : self ordered : NSWindowAbove];
1681 [fContentView setHidden : NO];
1682 [
self makeKeyAndOrderFront : self];
1683 [fContentView configureNotifyTree];
1687 [fMainWindow addChildWindow : self ordered : NSWindowAbove];
1699 [fContentView mapSubwindows];
1700 [fContentView configureNotifyTree];
1709 [fContentView setHidden : YES];
1710 [
self orderOut : self];
1713 [fMainWindow removeChildWindow : self];
1718#pragma mark - Events.
1721- (
void) sendEvent : (NSEvent *) theEvent
1731 bool generateFakeRelease =
false;
1733 const NSPoint windowPoint = [theEvent locationInWindow];
1735 if (windowPoint.x <= 4 || windowPoint.x >= self.fWidth - 4)
1736 generateFakeRelease =
true;
1738 if (windowPoint.y <= 4 || windowPoint.y >= self.fHeight - 4)
1739 generateFakeRelease =
true;
1741 const NSPoint viewPoint = [fContentView convertPoint : windowPoint fromView : nil];
1743 if (viewPoint.y <= 0 && windowPoint.y >= 0)
1744 generateFakeRelease =
true;
1747 "-sendEvent:, gVirtualX is either null or not of TGCocoa type");
1761 [
super sendEvent : theEvent];
1764#pragma mark - NSWindowDelegate's methods.
1767- (BOOL) windowShouldClose : (
id) sender
1769#pragma unused(sender)
1773 if ([[self childWindows] count])
1785 "-windowShouldClose:, gVirtualX is either null or has a type different from TGCocoa");
1794- (
void) windowDidBecomeKey : (NSNotification *) aNotification
1796#pragma unused(aNotification)
1805 "-windowDidBecomeKey:, gVirtualX is null or not of TGCocoa type");
1813- (
void) windowDidResignKey : (NSNotification *) aNotification
1815#pragma unused(aNotification)
1821#pragma mark - Passive key grab info.
1826- (
id) initWithKey : (unichar) keyCode modifiers : (NSUInteger) modifiers
1828 if (self = [super init]) {
1837- (BOOL) matchKey : (unichar) keyCode modifiers : (NSUInteger) modifiers
1843- (BOOL) matchKey : (unichar) keyCode
1862#pragma mark - X11 property emulation.
1864@interface QuartzWindowProperty :
NSObject {
1865 NSData *fPropertyData;
1874@implementation QuartzWindowProperty
1879- (
id) initWithData : (
unsigned char *) data size : (
unsigned) dataSize type : (
Atom_t) type format : (
unsigned) format
1881 if (self = [super init]) {
1883 fPropertyData = nil;
1887 [
self resetPropertyData : data size : dataSize type : type format : format];
1896 [fPropertyData release];
1902- (
void) resetPropertyData : (
unsigned char *) data size : (
unsigned) dataSize
1903 type : (
Atom_t) type format : (
unsigned) format
1905 [fPropertyData release];
1910 else if (format == 32)
1913 fPropertyData = [[NSData dataWithBytes : data length : dataSize] retain];
1919- (NSData *) fPropertyData
1921 return fPropertyData;
1932#pragma mark - QuartzView.
1965#pragma mark - Lifetime.
1970 if (self = [super initWithFrame : frame]) {
1982 [
self setCanDrawConcurrently : NO];
1984 [
self setHidden : YES];
2004 [fBackBuffer release];
2005 [fPassiveKeyGrabs release];
2006 [fX11Properties release];
2007 [fBackgroundPixmap release];
2011#pragma mark - Tracking area.
2016- (
void) updateTrackingAreas
2018 [
super updateTrackingAreas];
2025 if (NSArray *trackingArray = [self trackingAreas]) {
2026 const NSUInteger size = [trackingArray count];
2027 for (NSUInteger i = 0; i < size; ++i) {
2028 NSTrackingArea *
const t = [trackingArray objectAtIndex : i];
2029 [
self removeTrackingArea : t];
2033 const NSUInteger trackerOptions = NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited |
2034 NSTrackingActiveInActiveApp | NSTrackingInVisibleRect |
2035 NSTrackingEnabledDuringMouseDrag | NSTrackingCursorUpdate;
2038 frame.size.width = self.fWidth;
2039 frame.size.height = self.fHeight;
2041 NSTrackingArea *
const tracker = [[NSTrackingArea alloc] initWithRect : frame
2042 options : trackerOptions owner : self userInfo : nil];
2043 [
self addTrackingArea : tracker];
2048- (
void) updateTrackingAreasAfterRaise
2050 [
self updateTrackingAreas];
2052 for (
QuartzView *childView in [self subviews])
2053 [childView updateTrackingAreasAfterRaise];
2056#pragma mark - X11Drawable protocol.
2073 return self.fQuartzWindow.fScaleFactor;
2079 return self.frame.origin.x;
2085 return self.frame.origin.y;
2091 return self.frame.size.width;
2097 return self.frame.size.height;
2101- (
void) setDrawableSize : (NSSize) newSize
2103 assert(!(newSize.width < 0) &&
"-setDrawableSize, width is negative");
2104 assert(!(newSize.height < 0) &&
"-setDrawableSize, height is negative");
2110 NSRect frame = self.frame;
2111 frame.size = newSize;
2117- (
void) setX : (
int) x Y : (
int) y width : (
unsigned) w height : (
unsigned) h
2119 NSRect newFrame = {};
2120 newFrame.origin.x =
x;
2121 newFrame.origin.y =
y;
2122 newFrame.size.width = w;
2123 newFrame.size.height =
h;
2125 self.frame = newFrame;
2129- (
void) setX : (
int) x Y : (
int) y
2131 NSRect newFrame = self.frame;
2132 newFrame.origin.x =
x;
2133 newFrame.origin.y =
y;
2135 self.frame = newFrame;
2141 toPoint : (
X11::Point) dstPoint
2144 assert(srcImage != nil &&
2145 "-copyImage:area:withMask:clipOrigin:toPoint:, parameter 'srcImage' is nil");
2146 assert(srcImage.
fImage != nil &&
2147 "-copyImage:area:withMask:clipOrigin:toPoint:, srcImage.fImage is nil");
2150 assert(self.fContext != 0 &&
2151 "-copyImage:area:withMask:clipOrigin:toPoint:, self.fContext is null");
2154 NSLog(
@"QuartzView: -copyImage:area:withMask:clipOrigin:toPoint:,"
2155 " srcRect and copyRect do not intersect");
2162 bool needSubImage =
false;
2163 if (area.fX || area.fY || area.fWidth != srcImage.
fWidth || area.fHeight != srcImage.
fHeight) {
2164 needSubImage =
true;
2167 NSLog(
@"QuartzView: -copyImage:area:withMask:clipOrigin:toPoint:,"
2168 " subimage creation failed");
2172 subImage = srcImage.
fImage;
2178 CGContextTranslateCTM(self.fContext, 0., self.fHeight);
2179 CGContextScaleCTM(self.fContext, 1., -1.);
2183 assert(mask.
fImage != nil &&
2184 "-copyImage:area:withMask:clipOrigin:toPoint:, mask.fImage is nil");
2185 assert(CGImageIsMask(mask.
fImage) ==
true &&
2186 "-copyImage:area:withMask:clipOrigin:toPoint:, mask.fImage is not a mask");
2190 const CGRect clipRect = CGRectMake(clipXY.fX, clipY, mask.
fWidth, mask.
fHeight);
2191 CGContextClipToMask(self.fContext, clipRect, mask.
fImage);
2198 const CGRect imageRect = CGRectMake(dstPoint.fX, dstY, area.fWidth, area.fHeight);
2199 CGContextDrawImage(self.fContext, imageRect, subImage);
2202 CGImageRelease(subImage);
2206- (
void) copyView : (
QuartzView *) srcView area : (
X11::Rectangle) area toPoint : (
X11::Point) dstPoint
2211 assert(srcView != nil &&
"-copyView:area:toPoint:, parameter 'srcView' is nil");
2213 const NSRect frame = [srcView frame];
2215 NSBitmapImageRep *
const imageRep = [srcView bitmapImageRepForCachingDisplayInRect : frame];
2217 NSLog(
@"QuartzView: -copyView:area:toPoint failed");
2221 assert(srcView != nil &&
"-copyView:area:toPoint:, parameter 'srcView' is nil");
2222 assert(self.fContext != 0 &&
"-copyView:area:toPoint, self.fContext is null");
2229 [srcView cacheDisplayInRect : frame toBitmapImageRep : imageRep];
2233 const CGRect subImageRect = CGRectMake(area.fX, area.fY, area.fWidth, area.fHeight);
2236 if (!subImage.Get()) {
2237 NSLog(
@"QuartzView: -copyView:area:toPoint, CGImageCreateWithImageInRect failed");
2242 const CGRect imageRect = CGRectMake(dstPoint.fX,
2243 [self visibleRect].size.height - (CGFloat(dstPoint.fY) + area.fHeight),
2244 area.fWidth, area.fHeight);
2246 CGContextTranslateCTM(self.fContext, 0., [self visibleRect].size.height);
2247 CGContextScaleCTM(self.fContext, 1., -1.);
2249 CGContextDrawImage(self.fContext, imageRect, subImage.Get());
2254 withMask : (
QuartzImage *) mask clipOrigin : (
X11::Point) clipXY toPoint : (
X11::Point) dstPoint
2257 assert(srcPixmap != nil &&
"-copyPixmap:area:withMask:clipOrigin:toPoint:, parameter 'srcPixmap' is nil");
2260 NSLog(
@"QuartzView: -copyPixmap:area:withMask:clipOrigin:toPoint,"
2261 " no intersection between pixmap rectangle and cropArea");
2266 assert(self.fContext != 0 &&
2267 "-copyPixmap:area:withMask:clipOrigin:toPoint:, self.fContext is null");
2272 CGContextTranslateCTM(self.fContext, 0., self.frame.size.height);
2273 CGContextScaleCTM(self.fContext, 1., -1.);
2276 assert(imageFromPixmap.Get() != 0 &&
2277 "-copyPixmap:area:withMask:clipOrigin:toPoint:, createImageFromPixmap failed");
2280 bool needSubImage =
false;
2281 if (area.fX || area.fY || area.fWidth != srcPixmap.
fWidth || area.fHeight != srcPixmap.
fHeight) {
2282 needSubImage =
true;
2283 const CGRect subImageRect = CGRectMake(area.fX, area.fY, area.fHeight, area.fWidth);
2284 subImage = CGImageCreateWithImageInRect(imageFromPixmap.Get(), subImageRect);
2286 NSLog(
@"QuartzView: -copyImage:area:withMask:clipOrigin:toPoint:,"
2287 " subimage creation failed");
2291 subImage = imageFromPixmap.Get();
2294 assert(mask.
fImage != nil &&
2295 "-copyPixmap:area:withMask:clipOrigin:toPoint:, mask.fImage is nil");
2296 assert(CGImageIsMask(mask.
fImage) ==
true &&
2297 "-copyPixmap:area:withMask:clipOrigin:toPoint:, mask.fImage is not a mask");
2302 const CGRect clipRect = CGRectMake(clipXY.fX, clipY, mask.
fWidth, mask.
fHeight);
2303 CGContextClipToMask(self.fContext, clipRect, mask.
fImage);
2308 const CGRect imageRect = CGRectMake(dstPoint.fX, dstY, area.fWidth, area.fHeight);
2309 CGContextDrawImage(self.fContext, imageRect, imageFromPixmap.Get());
2312 CGImageRelease(subImage);
2318 toPoint : (
X11::Point) dstPoint
2320 assert(srcImage != nil &&
"-copyImage:area:toPoint:, parameter 'srcImage' is nil");
2321 assert(srcImage.
fImage != nil &&
"-copyImage:area:toPoint:, srcImage.fImage is nil");
2322 assert(self.fContext != 0 &&
"-copyImage:area:toPoint:, fContext is null");
2325 NSLog(
@"QuartzView: -copyImage:area:toPoint, image and copy area do not intersect");
2330 bool needSubImage =
false;
2331 if (area.fX || area.fY || area.fWidth != srcImage.
fWidth || area.fHeight != srcImage.
fHeight) {
2332 needSubImage =
true;
2335 NSLog(
@"QuartzView: -copyImage:area:toPoint:, subimage creation failed");
2339 subImage = srcImage.
fImage;
2343 CGContextTranslateCTM(self.fContext, 0., self.fHeight);
2344 CGContextScaleCTM(self.fContext, 1., -1.);
2349 const CGRect imageRect = CGRectMake(dstPoint.fX, dstY, area.fWidth, area.fHeight);
2350 CGContextDrawImage(self.fContext, imageRect, subImage);
2353 CGImageRelease(subImage);
2357- (
void) copy : (
NSObject<X11Drawable> *) src area : (
X11::Rectangle) area
2358 withMask : (
QuartzImage *)mask clipOrigin : (
X11::Point) clipXY toPoint : (
X11::Point) dstPoint
2360 assert(src != nil &&
"-copy:area:withMask:clipOrigin:toPoint:, parameter 'src' is nil");
2361 assert(area.fWidth && area.fHeight &&
"-copy:area:withMask:clipOrigin:toPoint:, area to copy is empty");
2367 [
self copyView : (QuartzView *)qw.fContentView area : area toPoint : dstPoint];
2368 }
else if ([src isKindOfClass : [
QuartzView class]]) {
2370 [
self copyView : (QuartzView *)src area : area toPoint : dstPoint];
2371 }
else if ([src isKindOfClass : [
QuartzPixmap class]]) {
2372 [
self copyPixmap : (QuartzPixmap *)src area : area withMask : mask clipOrigin : clipXY toPoint : dstPoint];
2373 }
else if ([src isKindOfClass : [
QuartzImage class]]) {
2374 [
self copyImage : (QuartzImage *)src area : area withMask : mask clipOrigin : clipXY toPoint : dstPoint];
2376 assert(0 &&
"-copy:area:withMask:clipOrigin:toPoint:, src is of unknown type");
2381- (
unsigned char *) readColorBits : (
X11::Rectangle) area
2387 assert(area.fWidth && area.fHeight &&
"-readColorBits:, area to copy is empty");
2390 const NSRect visRect = [
self visibleRect];
2391 const X11::Rectangle srcRect(
int(visRect.origin.x),
int(visRect.origin.y),
2392 unsigned(visRect.size.width),
unsigned(visRect.size.height));
2395 NSLog(
@"QuartzView: -readColorBits:, visible rect of view and copy area do not intersect");
2400 NSBitmapImageRep *
const imageRep = [
self bitmapImageRepForCachingDisplayInRect : visRect];
2402 NSLog(
@"QuartzView: -readColorBits:, bitmapImageRepForCachingDisplayInRect failed");
2407 [
self cacheDisplayInRect : visRect toBitmapImageRep : imageRep];
2408 self.fContext = ctx;
2410 const NSInteger bitsPerPixel = [imageRep bitsPerPixel];
2412 assert(bitsPerPixel == 32 &&
"-readColorBits:, no alpha channel???");
2413 const NSInteger bytesPerRow = [imageRep bytesPerRow];
2414 unsigned dataWidth = bytesPerRow / (bitsPerPixel / 8);
2416 unsigned char *srcData =
nullptr;
2417 std::vector<unsigned char> downscaled;
2418 if ([self.window.screen backingScaleFactor] > 1 && imageRep.CGImage) {
2420 if (downscaled.size())
2421 srcData = &downscaled[0];
2422 dataWidth = area.fWidth;
2424 srcData = [imageRep bitmapData];
2427 NSLog(
@"QuartzView: -readColorBits:, failed to obtain backing store contents");
2432 unsigned char *data =
nullptr;
2435 data =
new unsigned char[area.fWidth * area.fHeight * 4];
2436 }
catch (
const std::bad_alloc &) {
2437 NSLog(
@"QuartzView: -readColorBits:, memory allocation failed");
2441 unsigned char *dstPixel = data;
2442 const unsigned char *
line = srcData + area.
fY * dataWidth * 4;
2443 const unsigned char *srcPixel =
line + area.
fX * 4;
2445 for (
unsigned i = 0; i < area.fHeight; ++i) {
2446 for (
unsigned j = 0; j < area.fWidth; ++j, srcPixel += 4, dstPixel += 4) {
2447 dstPixel[0] = srcPixel[2];
2448 dstPixel[1] = srcPixel[1];
2449 dstPixel[2] = srcPixel[0];
2450 dstPixel[3] = srcPixel[3];
2453 line += dataWidth * 4;
2454 srcPixel =
line + area.
fX * 4;
2464 [fBackgroundPixmap release];
2483 if ([self isHidden])
2487 if ([parent isHidden])
2505- (
void) setFHasFocus : (BOOL) focus
2507#pragma unused(focus)
2524 [fBackBuffer release];
2558- (
void) activateGrab : (
unsigned) eventMask ownerEvents : (BOOL) ownerEvents
2574- (BOOL) acceptsCrossingEvents : (
unsigned) eventMask
2593- (
void) addChild : (
NSView<X11Window> *) child
2595 assert(child != nil &&
"-addChild:, parameter 'child' is nil");
2597 [
self addSubview : child];
2598 child.fParentView = self;
2604 assert(attr != 0 &&
"-getAttributes:, parameter 'attr' is null");
2612 assert(attr != 0 &&
"-setAttributes:, parameter 'attr' is null");
2614#ifdef DEBUG_ROOT_COCOA
2615 log_attributes(attr,
fID);
2626 [
self removeFromSuperview];
2627 [parent addSubview : self];
2628 [
self setHidden : NO];
2634 [
self setHidden : NO];
2647 [
self setHidden : YES];
2657- (
void) setOverlapped : (BOOL) overlap
2661 [child setOverlapped : overlap];
2678 using namespace X11;
2681 if (self == sibling)
2683 if ([sibling isHidden])
2686 if (NSEqualRects(sibling.frame, self.frame)) {
2687 [sibling setOverlapped : YES];
2688 [sibling setHidden : YES];
2692 [
self setOverlapped : NO];
2694 [
self setHidden : NO];
2696 [fParentView sortSubviewsUsingFunction : CompareViewsToRaise context : (void *)self];
2698 [
self updateTrackingAreasAfterRaise];
2700 [
self setNeedsDisplay : YES];
2708 using namespace X11;
2710 NSEnumerator *
const reverseEnumerator = [[fParentView subviews] reverseObjectEnumerator];
2711 for (
QuartzView *sibling in reverseEnumerator) {
2712 if (sibling == self)
2715 if (NSEqualRects(sibling.frame, self.frame)) {
2716 [sibling setOverlapped : NO];
2718 [sibling setHidden : NO];
2720 [sibling setNeedsDisplay : YES];
2721 [
self setOverlapped : YES];
2723 [
self setHidden : YES];
2729 [fParentView sortSubviewsUsingFunction : CompareViewsToLower context : (void*)self];
2746 "-configureNotifyTree, gVirtualX is either null or has type different from TGCocoa");
2752 [v configureNotifyTree];
2756#pragma mark - Key grabs.
2759- (
void) addPassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers
2761 [
self removePassiveKeyGrab : keyCode modifiers : modifiers];
2763 modifiers : modifiers];
2764 [fPassiveKeyGrabs addObject : newGrab];
2769- (
void) removePassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers
2771 const NSUInteger count = [fPassiveKeyGrabs count];
2772 for (NSUInteger i = 0; i < count; ++i) {
2774 if ([grab matchKey : keyCode modifiers : modifiers]) {
2775 [fPassiveKeyGrabs removeObjectAtIndex : i];
2782- (
PassiveKeyGrab *) findPassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers
2784 NSEnumerator *
const enumerator = [fPassiveKeyGrabs objectEnumerator];
2786 if ([grab matchKey : keyCode modifiers : modifiers])
2797 NSEnumerator *
const enumerator = [fPassiveKeyGrabs objectEnumerator];
2799 if ([grab matchKey : keyCode])
2806#pragma mark - Painting mechanics.
2809- (
void) drawRect : (NSRect) dirtyRect
2811#pragma unused(dirtyRect)
2813 using namespace X11;
2821 NSGraphicsContext *
const nsContext = [NSGraphicsContext currentContext];
2822 assert(nsContext != nil &&
"-drawRect:, currentContext returned nil");
2828 assert(
fContext != 0 &&
"-drawRect:, graphicsPort returned null");
2833 if (self.fQuartzWindow.fShapeCombineMask)
2845 [NSColor.whiteColor setFill];
2846 NSRectFill(dirtyRect);
2864 gClient->CancelRedraw(window);
2872 [
self copy : fBackBuffer area : copyArea withMask : nil
2873 clipOrigin : X11::Point() toPoint : X11::Point()];
2877#ifdef DEBUG_ROOT_COCOA
2878 CGContextSetRGBStrokeColor(
fContext, 1., 0., 0., 1.);
2879 CGContextStrokeRect(
fContext, dirtyRect);
2884#ifdef DEBUG_ROOT_COCOA
2885 NSLog(
@"QuartzView: -drawRect: method, no window for id %u was found",
fID);
2891#pragma mark - Geometry.
2894- (
void) setFrame : (NSRect) newFrame
2899 if (NSEqualRects(newFrame, self.frame))
2902 [
super setFrame : newFrame];
2906- (
void) setFrameSize : (NSSize) newSize
2910 [
super setFrameSize : newSize];
2914 "setFrameSize:, gVirtualX is either null or has a type, different from TGCocoa");
2919 [
self setNeedsDisplay : YES];
2922#pragma mark - Event handling.
2925- (
void) mouseDown : (NSEvent *) theEvent
2927 assert(
fID != 0 &&
"-mouseDown:, fID is 0");
2930 "-mouseDown:, gVirtualX is either null or has a type, different from TGCocoa");
2936- (
void) scrollWheel : (NSEvent*) theEvent
2938 assert(
fID != 0 &&
"-scrollWheel:, fID is 0");
2942 "-scrollWheel:, gVirtualX is either null or has a type, different from TGCocoa");
2945 const CGFloat deltaY = [theEvent deltaY];
2949 }
else if (deltaY > 0) {
2955#ifdef DEBUG_ROOT_COCOA
2957- (
void) printViewInformation
2959 assert(
fID != 0 &&
"-printWindowInformation, fID is 0");
2961 assert(window != 0 &&
"printWindowInformation, window not found");
2963 NSLog(
@"-----------------View %u info:---------------------",
fID);
2964 NSLog(
@"ROOT's window class is %s", window->IsA()->
GetName());
2965 NSLog(
@"event mask is:");
2967 NSLog(
@"grab mask is:");
2969 NSLog(
@"view's geometry: x == %g, y == %g, w == %g, h == %g", self.frame.origin.x,
2970 self.frame.origin.y, self.frame.size.width, self.frame.size.height);
2971 NSLog(
@"----------------End of view info------------------");
2976- (
void) rightMouseDown : (NSEvent *) theEvent
2978 assert(
fID != 0 &&
"-rightMouseDown:, fID is 0");
2980#ifdef DEBUG_ROOT_COCOA
2981 [
self printViewInformation];
2985 "-rightMouseDown:, gVirtualX is either null or has type different from TGCocoa");
2991- (
void) otherMouseDown : (NSEvent *) theEvent
2993 assert(
fID != 0 &&
"-otherMouseDown:, fID is 0");
2997 if ([theEvent buttonNumber] == 2) {
3001 "-otherMouseDown:, gVirtualX is either null or has type different from TGCocoa");
3008- (
void) mouseUp : (NSEvent *) theEvent
3010 assert(
fID != 0 &&
"-mouseUp:, fID is 0");
3013 "-mouseUp:, gVirtualX is either null or has type different from TGCocoa");
3019- (
void) rightMouseUp : (NSEvent *) theEvent
3022 assert(
fID != 0 &&
"-rightMouseUp:, fID is 0");
3025 "-rightMouseUp:, gVirtualX is either null or has type different from TGCocoa");
3032- (
void) otherMouseUp : (NSEvent *) theEvent
3034 assert(
fID != 0 &&
"-otherMouseUp:, fID is 0");
3038 "-otherMouseUp:, gVirtualX is either null or has type different from TGCocoa");
3044- (
void) mouseEntered : (NSEvent *) theEvent
3046 assert(
fID != 0 &&
"-mouseEntered:, fID is 0");
3048 "-mouseEntered:, gVirtualX is null or not of TGCocoa type");
3055- (
void) mouseExited : (NSEvent *) theEvent
3057 assert(
fID != 0 &&
"-mouseExited:, fID is 0");
3060 "-mouseExited:, gVirtualX is null or not of TGCocoa type");
3067- (
void) mouseMoved : (NSEvent *) theEvent
3069 assert(
fID != 0 &&
"-mouseMoved:, fID is 0");
3075 "-mouseMoved:, gVirtualX is null or not of TGCocoa type");
3082- (
void) mouseDragged : (NSEvent *) theEvent
3084 assert(
fID != 0 &&
"-mouseDragged:, fID is 0");
3087 assert(vx != 0 &&
"-mouseDragged:, gVirtualX is null or not of TGCocoa type");
3093- (
void) rightMouseDragged : (NSEvent *) theEvent
3095 assert(
fID != 0 &&
"-rightMouseDragged:, fID is 0");
3098 "-rightMouseDragged:, gVirtualX is null or not of TGCocoa type");
3105- (
void) otherMouseDragged : (NSEvent *) theEvent
3107 assert(
fID != 0 &&
"-otherMouseDragged:, fID is 0");
3109 if ([theEvent buttonNumber] == 2) {
3111 "-otherMouseDragged:, gVirtualX is null or not of TGCocoa type");
3118- (
void) keyDown : (NSEvent *) theEvent
3120 assert(
fID != 0 &&
"-keyDown:, fID is 0");
3123 "-keyDown:, gVirtualX is null or not of TGCocoa type");
3127 eventView = pointerView;
3134- (
void) keyUp : (NSEvent *) theEvent
3136 assert(
fID != 0 &&
"-keyUp:, fID is 0");
3139 "-keyUp:, gVirtualX is null or not of TGCocoa type");
3144 eventView = pointerView;
3149#pragma mark - First responder stuff.
3152- (BOOL) acceptsFirstMouse : (NSEvent *) theEvent
3154#pragma unused(theEvent)
3159- (BOOL) acceptsFirstResponder
3164#pragma mark - Cursors.
3171 [
self.fQuartzWindow invalidateCursorRectsForView : self];
3176- (NSCursor *) createCustomCursor
3178 const char *pngFileName = 0;
3182 pngFileName =
"move_cursor.png";
3185 pngFileName =
"hor_arrow_cursor.png";
3188 pngFileName =
"ver_arrow_cursor.png";
3191 pngFileName =
"right_arrow_cursor.png";
3194 pngFileName =
"rotate.png";
3198 pngFileName =
"top_right_cursor.png";
3202 pngFileName =
"top_left_cursor.png";
3211 if (!path || path[0] == 0) {
3216 NSString *nsPath = [NSString stringWithFormat : @"%s", path];
3217 NSImage *
const cursorImage = [[NSImage alloc] initWithContentsOfFile : nsPath];
3223 NSCursor *
const customCursor = [[[NSCursor alloc] initWithImage : cursorImage
3224 hotSpot : hotSpot] autorelease];
3226 [cursorImage release];
3228 return customCursor;
3235- (
void) resetCursorRects
3238 [
self addCursorRect : self.visibleRect cursor : cursor];
3242- (
void) cursorUpdate
3252- (
void) cursorUpdate : (NSEvent *) event
3254#pragma unused(event)
3266 [
self performSelector : @selector(cursorUpdate) withObject : nil afterDelay : 0.05f];
3269#pragma mark - Emulated X11 properties.
3272- (
void) setProperty : (const
char *) propName data : (
unsigned char *) propData
3273 size : (
unsigned) dataSize forType : (
Atom_t) dataType format : (
unsigned) format
3275 assert(propName != 0 &&
"-setProperty:data:size:forType:, parameter 'propName' is null");
3276 assert(propData != 0 &&
"-setProperty:data:size:forType:, parameter 'propData' is null");
3277 assert(dataSize != 0 &&
"-setProperty:data:size:forType:, parameter 'dataSize' is 0");
3279 NSString *
const key = [NSString stringWithCString : propName encoding : NSASCIIStringEncoding];
3280 QuartzWindowProperty *
property = (QuartzWindowProperty *)[
fX11Properties valueForKey : key];
3284 [property resetPropertyData : propData size : dataSize type : dataType format : format];
3287 property = [[QuartzWindowProperty alloc] initWithData : propData size : dataSize
3288 type : dataType format : format];
3289 [fX11Properties setObject : property forKey : key];
3295- (BOOL) hasProperty : (const
char *) propName
3297 assert(propName != 0 &&
"-hasProperty:, propName parameter is null");
3299 NSString *
const key = [NSString stringWithCString : propName encoding : NSASCIIStringEncoding];
3300 QuartzWindowProperty *
const property = (QuartzWindowProperty *)[
fX11Properties valueForKey : key];
3302 return property != nil;
3306- (
unsigned char *) getProperty : (const
char *) propName returnType : (
Atom_t *) type
3307 returnFormat : (
unsigned *) format nElements : (
unsigned *) nElements
3309 assert(propName != 0 &&
3310 "-getProperty:returnType:returnFormat:nElements:, parameter 'propName' is null");
3312 "-getProperty:returnType:returnFormat:nElements:, parameter 'type' is null");
3313 assert(format != 0 &&
3314 "-getProperty:returnType:returnFormat:nElements:, parameter 'format' is null");
3315 assert(nElements != 0 &&
3316 "-getProperty:returnType:returnFormat:nElements:, parameter 'nElements' is null");
3318 NSString *
const key = [NSString stringWithCString : propName encoding : NSASCIIStringEncoding];
3319 QuartzWindowProperty *
const property = (QuartzWindowProperty *)[
fX11Properties valueForKey : key];
3320 assert(property != 0 &&
3321 "-getProperty:returnType:returnFormat:nElements, property not found");
3323 NSData *
const propData =
property.fPropertyData;
3325 const NSUInteger dataSize = [propData length];
3326 unsigned char *buff = 0;
3328 buff =
new unsigned char[dataSize]();
3329 }
catch (
const std::bad_alloc &) {
3331 NSLog(
@"QuartzWindow: -getProperty:returnType:returnFormat:nElements:,"
3332 " memory allocation failed");
3336 [propData getBytes : buff length : dataSize];
3337 *format =
property.fFormat;
3339 *nElements = dataSize;
3342 *nElements= dataSize / 2;
3343 else if (*format == 32)
3344 *nElements = dataSize / 4;
3346 *
type =
property.fType;
3352- (
void) removeProperty : (const
char *) propName
3354 assert(propName != 0 &&
"-removeProperty:, parameter 'propName' is null");
3356 NSString *
const key = [NSString stringWithCString : propName
3357 encoding : NSASCIIStringEncoding];
3358 [fX11Properties removeObjectForKey : key];
3363- (NSDragOperation) draggingEntered : (
id<NSDraggingInfo>) sender
3365 NSPasteboard *
const pasteBoard = [sender draggingPasteboard];
3366 const NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
3368 if ([[pasteBoard types] containsObject : NSFilenamesPboardType] && (sourceDragMask & NSDragOperationCopy))
3369 return NSDragOperationCopy;
3371 return NSDragOperationNone;
3375- (BOOL) performDragOperation : (
id<NSDraggingInfo>) sender
3386 NSPasteboard *
const pasteBoard = [sender draggingPasteboard];
3387 const NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
3389 if ([[pasteBoard types] containsObject : NSFilenamesPboardType] && (sourceDragMask & NSDragOperationCopy)) {
3395 NSArray *
const files = [pasteBoard propertyListForType : NSFilenamesPboardType];
3396 for (NSString *path in files) {
3398 NSString *
const item = [@"file://" stringByAppendingString : path];
3400 const NSUInteger len = [item lengthOfBytesUsingEncoding : NSASCIIStringEncoding] + 1;
3402 std::vector<unsigned char> propertyData(len);
3403 [item getCString : (char *)&propertyData[0] maxLength : propertyData.size()
3404 encoding : NSASCIIStringEncoding];
3407 [targetView setProperty : "_XC_DND_DATA" data : &propertyData[0]
3408 size : propertyData.size() forType : textUriAtom format : 8];
3409 }
catch (
const std::bad_alloc &) {
3411 NSLog(
@"QuartzView: -performDragOperation:, memory allocation failed");
3427 event1.
fUser[2] = textUriAtom;
3437 event2.
fUser[2] = 0;
3438 NSPoint dropPoint = [sender draggingLocation];
3441 dropPoint = [
self convertPoint : dropPoint fromView : nil];
const Mask_t kWABorderPixel
const Mask_t kWAOverrideRedirect
const Mask_t kWABitGravity
const Mask_t kWADontPropagate
const Mask_t kButtonMotionMask
const Mask_t kWABackingStore
const Mask_t kButtonPressMask
const Mask_t kExposureMask
const Mask_t kWAEventMask
const Mask_t kWASaveUnder
const Mask_t kWABackPixel
const Mask_t kWAWinGravity
const Mask_t kWABackingPixel
const Mask_t kPointerMotionMask
const Mask_t kLeaveWindowMask
const Mask_t kStructureNotifyMask
const Mask_t kButtonReleaseMask
const Mask_t kWABorderPixmap
const Mask_t kEnterWindowMask
Handle_t Window_t
Window handle.
const Mask_t kWABackPixmap
const Mask_t kWABorderWidth
const Mask_t kWABackingPlanes
typedef void((*Func_t)())
R__EXTERN TSystem * gSystem
void RemoveGraphicsOperationsForWindow(Window_t wid)
void GenerateFocusChangeEvent(NSView< X11Window > *eventView)
void GenerateExposeEvent(NSView< X11Window > *view, const NSRect &exposedRect)
void GenerateConfigureNotifyEvent(NSView< X11Window > *view, const NSRect &newFrame)
void GenerateCrossingEvent(NSEvent *theEvent)
bool HasPointerGrab() const
void GenerateKeyReleaseEvent(NSView< X11Window > *eventView, NSEvent *theEvent)
void GenerateKeyPressEvent(NSView< X11Window > *eventView, NSEvent *theEvent)
void GenerateButtonPressEvent(NSView< X11Window > *eventView, NSEvent *theEvent, EMouseButton btn)
void GeneratePointerMotionEvent(NSEvent *theEvent)
void GenerateButtonReleaseEvent(NSView< X11Window > *eventView, NSEvent *theEvent, EMouseButton btn)
This class implements TVirtualX interface for MacOS X, using Cocoa and Quartz 2D.
ROOT::MacOSX::X11::CommandBuffer * GetCommandBuffer() const
static Atom_t fgDeleteWindowAtom
ROOT::MacOSX::X11::Rectangle GetDisplayGeometry() const
ROOT::MacOSX::X11::EventTranslator * GetEventTranslator() const
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
static const TString & GetIconPath()
Get the icon path in the installation. Static utility function.
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
ROOT::MacOSX::Util::CFScopeGuard< CGImageRef > fImage
QuartzPixmap * fBackBuffer
unsigned fPassiveGrabKeyModifiers
void activateImplicitGrab()
NSMutableArray * fPassiveKeyGrabs
BOOL fActiveGrabOwnerEvents
QuartzWindow * fQuartzWindow
void configureNotifyTree()
void activatePassiveGrab()
NSMutableDictionary * fX11Properties
BOOL fPassiveGrabOwnerEvents
unsigned fPassiveGrabEventMask
QuartzImage * fBackgroundPixmap
ROOT::MacOSX::X11::PointerGrab fCurrentGrabType
unsigned long fBackgroundPixel
unsigned fActiveGrabEventMask
NSView< X11Window > * fContentView
unsigned long fBackgroundPixel
void addCrosshairWindow()
QuartzWindow * fQuartzWindow
CrosshairWindow * findCrosshairWindow()
QuartzWindow * fMainWindow
void adjustCrosshairWindowGeometry()
void removeCrosshairWindow()
QuartzView * fContentView
QuartzImage * fShapeCombineMask
const NSUInteger kMiniaturizableWindowMask
const NSEventType kLeftMouseDown
const NSEventType kRightMouseDown
const NSUInteger kTitledWindowMask
const NSUInteger kResizableWindowMask
const NSUInteger kClosableWindowMask
const NSUInteger kBorderlessWindowMask
NSCursor * CreateCustomCursor(ECursor currentCursor)
int GlobalYROOTToCocoa(CGFloat yROOT)
NSPoint ConvertPointFromScreenToBase(NSPoint screenPoint, NSWindow *window)
bool ViewIsHtmlViewFrame(NSView< X11Window > *view, bool checkParent)
int GlobalYCocoaToROOT(CGFloat yCocoa)
void PixelToRGB(Pixel_t pixelColor, CGFloat *rgb)
NSPoint ConvertPointFromBaseToScreen(NSWindow *window, NSPoint windowPoint)
NSPoint TranslateToScreen(NSView< X11Window > *from, NSPoint point)
CGImageRef CreateSubImage(QuartzImage *image, const Rectangle &area)
bool ScreenPointIsInView(NSView< X11Window > *view, Int_t x, Int_t y)
NSPoint GetCursorHotStop(NSImage *image, ECursor cursor)
void GetWindowGeometry(NSObject< X11Window > *win, WindowAttributes_t *dst)
void GetWindowAttributes(NSObject< X11Window > *window, WindowAttributes_t *dst)
NSView< X11Window > * FindDNDAwareViewInPoint(NSView *parentView, Window_t dragWinID, Window_t inputWinID, Int_t x, Int_t y, Int_t maxDepth)
NSView< X11Window > * FrameForHtmlView(NSView< X11Window > *htmlView)
QuartzWindow * FindWindowInPoint(Int_t x, Int_t y)
int GlobalXCocoaToROOT(CGFloat xCocoa)
void WindowLostFocus(Window_t winID)
int LocalYROOTToCocoa(NSView< X11Window > *parentView, CGFloat yROOT)
NSView< X11Window > * FindViewForPointerEvent(NSEvent *pointerEvent)
NSView< X11Window > * FrameForTextView(NSView< X11Window > *textView)
NSComparisonResult CompareViewsToLower(id view1, id view2, void *context)
int LocalYCocoaToROOT(NSView< X11Window > *parentView, CGFloat yCocoa)
NSPoint TranslateCoordinates(NSView< X11Window > *fromView, NSView< X11Window > *toView, NSPoint sourcePoint)
QuartzWindow * CreateTopLevelWindow(Int_t x, Int_t y, UInt_t w, UInt_t h, UInt_t border, Int_t depth, UInt_t clss, void *visual, SetWindowAttributes_t *attr, UInt_t)
NSView< X11Window > * FindViewUnderPointer()
void UnlockFocus(NSView< X11Window > *view)
int GlobalXROOTToCocoa(CGFloat xROOT)
QuartzView * CreateChildView(QuartzView *parent, Int_t x, Int_t y, UInt_t w, UInt_t h, UInt_t border, Int_t depth, UInt_t clss, void *visual, SetWindowAttributes_t *attr, UInt_t wtype)
bool AdjustCropArea(const Rectangle &srcRect, Rectangle &cropArea)
QuartzWindow * FindWindowForPointerEvent(NSEvent *pointerEvent)
bool ViewIsTextView(unsigned viewID)
void GetRootWindowAttributes(WindowAttributes_t *attr)
bool ViewIsHtmlView(unsigned viewID)
QuartzWindow * FindWindowUnderPointer()
bool ViewIsTextViewFrame(NSView< X11Window > *view, bool checkParent)
NSPoint TranslateFromScreen(NSPoint point, NSView< X11Window > *to)
void ClipToShapeMask(NSView< X11Window > *view, CGContextRef ctx)
void SetWindowAttributes(const SetWindowAttributes_t *attr, NSObject< X11Window > *window)
NSCursor * CreateCursor(ECursor currentCursor)
bool LockFocus(NSView< X11Window > *view)
NSComparisonResult CompareViewsToRaise(id view1, id view2, void *context)
std::vector< unsigned char > DownscaledImageData(unsigned w, unsigned h, CGImageRef image)
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
EGEventType fType
of event (see EGEventType)
Handle_t fHandle
general resource handle (used for atoms or windows)
Int_t fFormat
Next fields only used by kClientMessageEvent.
Window_t fWindow
window reported event is relative to
Long_t fUser[5]
5 longs can be used by client message events NOTE: only [0], [1] and [2] may be used.
Attributes that can be used when creating or changing a window.
Long_t fEventMask
set of events that should be saved
Mask_t fMask
bit mask specifying which fields are valid
Int_t fWinGravity
one of the window gravity values
ULong_t fBackgroundPixel
background pixel
Int_t fBitGravity
one of bit gravity values
Window attributes that can be inquired.
Window_t fRoot
root of screen containing window
Int_t fMapState
kIsUnmapped, kIsUnviewable, kIsViewable
ULong_t fBackingPlanes
planes to be preserved if possible
Long_t fAllEventMasks
set of events all people have interest in
ULong_t fBackingPixel
value to be used when restoring planes
Long_t fYourEventMask
my event mask
Int_t fHeight
width and height of window
Bool_t fMapInstalled
boolean, is color map currently installed
Int_t fBorderWidth
border width of window
Int_t fWinGravity
one of the window gravity values
void * fScreen
back pointer to correct screen
Colormap_t fColormap
color map to be associated with window
Int_t fClass
kInputOutput, kInputOnly
Int_t fBitGravity
one of bit gravity values
void * fVisual
the associated visual structure
Int_t fBackingStore
kNotUseful, kWhenMapped, kAlways
Int_t fY
location of window
Int_t fDepth
depth of window
Bool_t fOverrideRedirect
boolean value for override-redirect
Bool_t fSaveUnder
boolean, should bits under be saved?