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");
128 attr->fBorderWidth = 0;
129 attr->fYourEventMask = 0;
130 attr->fAllEventMasks = 0;
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;
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");
642 window.fBackgroundPixel =
attr->fBackgroundPixel;
645 window.fEventMask =
attr->fEventMask;
648 window.fBitGravity =
attr->fBitGravity;
651 window.fWinGravity =
attr->fWinGravity;
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];
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";
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 std::vector<ROOT::MacOSX::X11::Command *> xorOps;
1130- (
void) setXorOperations : (const std::vector<
ROOT::MacOSX::
X11::Command *> &) primitives
1132 xorOps = primitives;
1135- (
void) drawRect : (NSRect) dirtyRect
1137 [
super drawRect:dirtyRect];
1138 NSGraphicsContext *nsContext = [NSGraphicsContext currentContext];
1148 CGContextSetRGBStrokeColor(cgContext, 0., 0., 0., 1.);
1149 CGContextSetLineWidth(cgContext, 1.);
1151 for (
auto *command : xorOps) {
1152 command->Execute(cgContext);
1163- (instancetype)
init
1165 if (self = [super
init])
1167 self.styleMask = NSWindowStyleMaskBorderless;
1169 self.hasShadow = NO;
1170 self.backgroundColor = NSColor.clearColor;
1171 self.ignoresMouseEvents = YES;
1177#pragma mark - suppress the normal window behavior.
1178- (
BOOL)canBecomeKeyWindow
1182- (
BOOL)canBecomeMainWindow
1195#pragma mark - QuartzWindow's life cycle.
1198- (
id) initWithContentRect : (NSRect) contentRect styleMask : (NSUInteger) windowStyle
1199 backing : (NSBackingStoreType) bufferingType defer : (
BOOL) deferCreation
1202 self = [
super initWithContentRect : contentRect styleMask : windowStyle
1203 backing : bufferingType defer : deferCreation];
1207 [
self setAllowsConcurrentViewDrawing : NO];
1209 self.delegate = self;
1211 NSRect contentViewRect = contentRect;
1212 contentViewRect.origin.x = 0.f;
1213 contentViewRect.origin.y = 0.f;
1217 [
self setContentView : fContentView];
1219 [fContentView release];
1237 assert(glView != nil &&
"-initWithGLView, parameter 'glView' is nil");
1242 NSRect contentRect = glView.frame;
1243 contentRect.origin = NSPoint();
1245 self = [
super initWithContentRect : contentRect styleMask : styleMask
1246 backing : NSBackingStoreBuffered defer : NO];
1250 [
self setAllowsConcurrentViewDrawing : NO];
1251 self.delegate = self;
1253 [
self setContentView : fContentView];
1265 [fShapeCombineMask release];
1278 [
super setContentView:cv];
1286- (
void) setFIsDeleted : (
BOOL) deleted
1291#pragma mark - Forwaring: I want to forward a lot of property setters/getters to the content view.
1294- (
void) forwardInvocation : (NSInvocation *) anInvocation
1299 if ([
fContentView respondsToSelector : [anInvocation selector]]) {
1300 [anInvocation invokeWithTarget : fContentView];
1302 [
super forwardInvocation : anInvocation];
1307- (NSMethodSignature*) methodSignatureForSelector : (
SEL) selector
1309 NSMethodSignature *signature = [
super methodSignatureForSelector : selector];
1313 signature = [fContentView methodSignatureForSelector : selector];
1328 assert(window != nil &&
"-addTransientWindow:, parameter 'window' is nil");
1337 [
self addChildWindow : window ordered : NSWindowAbove];
1343- (
void) makeKeyAndOrderFront : (
id) sender
1345#pragma unused(sender)
1350#ifdef MAC_OS_X_VERSION_10_9
1351 [
self setCollectionBehavior : NSWindowCollectionBehaviorMoveToActiveSpace];
1353 [
self setCollectionBehavior : NSWindowCollectionBehaviorCanJoinAllSpaces];
1356 [
super makeKeyAndOrderFront : self];
1358 [
self setCollectionBehavior : NSWindowCollectionBehaviorDefault];
1362- (
void) setFDelayedTransient : (
BOOL) d
1377 [fShapeCombineMask release];
1385#pragma mark - X11Drawable's protocol.
1406 return self.screen.backingScaleFactor;
1424 return self.frame.size.width;
1433 assert(
fContentView != nil &&
"-fHeight:, content view is nil");
1439- (
void) setDrawableSize : (NSSize) newSize
1442 assert(!(newSize.width < 0) &&
"-setDrawableSize:, width is negative");
1443 assert(!(newSize.height < 0) &&
"-setDrawableSize:, height is negative");
1445 NSRect frame = self.frame;
1447 if (frame.origin.x < -100000. || frame.origin.x > 100000.) {
1449 NSLog(
@"Attempting to set a frame with X: %g", frame.origin.x);
1450 frame.origin.x = 0.;
1456 frame.size = newSize;
1457 frame.size.height += dY;
1458 [
self setFrame : frame display : YES];
1462- (
void) setX : (
int) x Y : (
int) y width : (
unsigned) w height : (
unsigned) h
1464 NSSize newSize = {};
1467 [
self setContentSize : newSize];
1470 NSPoint topLeft = {};
1474 [
self setFrameTopLeftPoint : topLeft];
1478- (
void) setX : (
int) x Y : (
int) y
1480 NSPoint topLeft = {};
1484 [
self setFrameTopLeftPoint : topLeft];
1489 clipOrigin : (
X11::Point) clipXY toPoint : (
X11::Point) dstPoint
1494 [fContentView copy : src area : area withMask : mask clipOrigin : clipXY toPoint : dstPoint];
1498- (
unsigned char *) readColorBits : (
X11::Rectangle) area
1503 return [fContentView readColorBits : area];
1506#pragma mark - XorDrawinWindow/View
1515 [
self adjustXorWindowGeometry:special];
1516 [
self addChildWindow : special ordered : NSWindowAbove];
1524 [
self adjustXorWindowGeometry:win];
1530 assert(
win &&
"invalid (nil) parameter 'win'");
1531 auto frame = self.contentView.frame;
1532 frame = [
self convertRectToScreen:frame];
1533 [win setFrame:frame display:NO];
1543 [
self removeChildWindow : win];
1550 auto children = [
self childWindows];
1559#pragma mark - X11Window protocol's implementation.
1570#pragma unused(parent)
1588- (
void) setFBackgroundPixel : (
unsigned long) backgroundColor
1594 CGFloat rgba[] = {0., 0., 0., 1.};
1597 [
self setBackgroundColor : [NSColor colorWithColorSpace : [NSColorSpace deviceRGBColorSpace] components : rgba count : 4]];
1626- (
void) addChild : (
NSView<X11Window> *) child
1628 assert(
child != nil &&
"-addChild:, parameter 'child' is nil");
1633 "-addChild: gl view in a top-level window as content view is not supported");
1636 [
self setContentView : child];
1639 [fContentView addChild : child];
1648 assert(
attr &&
"-getAttributes:, parameter 'attr' is nil");
1656 assert(
attr != 0 &&
"-setAttributes:, parameter 'attr' is null");
1658#ifdef DEBUG_ROOT_COCOA
1659 log_attributes(
attr, self.fID);
1673 [fContentView setHidden : NO];
1674 [
self makeKeyAndOrderFront : self];
1675 [fContentView configureNotifyTree];
1679 [fMainWindow addChildWindow : self ordered : NSWindowAbove];
1691 [fContentView setHidden : NO];
1692 [
self makeKeyAndOrderFront : self];
1693 [fContentView configureNotifyTree];
1697 [fMainWindow addChildWindow : self ordered : NSWindowAbove];
1709 [fContentView mapSubwindows];
1710 [fContentView configureNotifyTree];
1719 [fContentView setHidden : YES];
1720 [
self orderOut : self];
1723 [fMainWindow removeChildWindow : self];
1728#pragma mark - Events.
1741 bool generateFakeRelease =
false;
1743 const NSPoint windowPoint = [theEvent locationInWindow];
1745 if (windowPoint.x <= 4 || windowPoint.x >= self.fWidth - 4)
1746 generateFakeRelease =
true;
1748 if (windowPoint.y <= 4 || windowPoint.y >= self.fHeight - 4)
1749 generateFakeRelease =
true;
1751 const NSPoint viewPoint = [fContentView convertPoint : windowPoint fromView : nil];
1753 if (viewPoint.y <= 0 && windowPoint.y >= 0)
1754 generateFakeRelease =
true;
1757 "-sendEvent:, gVirtualX is either null or not of TGCocoa type");
1771 [
super sendEvent : theEvent];
1774#pragma mark - NSWindowDelegate's methods.
1777- (
BOOL) windowShouldClose : (
id) sender
1779#pragma unused(sender)
1783 if ([[self childWindows] count])
1795 "-windowShouldClose:, gVirtualX is either null or has a type different from TGCocoa");
1804- (
void) windowDidBecomeKey : (NSNotification *) aNotification
1806#pragma unused(aNotification)
1815 "-windowDidBecomeKey:, gVirtualX is null or not of TGCocoa type");
1823- (
void) windowDidResignKey : (NSNotification *) aNotification
1825#pragma unused(aNotification)
1831#pragma mark - Passive key grab info.
1836- (
id) initWithKey : (unichar) keyCode modifiers : (NSUInteger) modifiers
1838 if (self = [super init]) {
1847- (
BOOL) matchKey : (unichar) keyCode modifiers : (NSUInteger) modifiers
1853- (
BOOL) matchKey : (unichar) keyCode
1872#pragma mark - X11 property emulation.
1889- (
id) initWithData : (
unsigned char *) data size : (
unsigned) dataSize type : (
Atom_t) type format : (
unsigned) format
1891 if (self = [super init]) {
1897 [
self resetPropertyData : data size : dataSize type : type format : format];
1906 [fPropertyData release];
1912- (
void) resetPropertyData : (
unsigned char *) data size : (
unsigned) dataSize
1913 type : (
Atom_t) type format : (
unsigned) format
1915 [fPropertyData release];
1923 fPropertyData = [[NSData dataWithBytes : data length : dataSize] retain];
1942#pragma mark - QuartzView.
1975#pragma mark - Lifetime.
1980 if (self = [super initWithFrame : frame]) {
1992 [
self setCanDrawConcurrently : NO];
1994 [
self setHidden : YES];
2014 [fBackBuffer release];
2015 [fPassiveKeyGrabs release];
2016 [fX11Properties release];
2017 [fBackgroundPixmap release];
2021#pragma mark - Tracking area.
2026- (
void) updateTrackingAreas
2028 [
super updateTrackingAreas];
2035 if (NSArray *trackingArray = [self trackingAreas]) {
2036 const NSUInteger
size = [trackingArray count];
2037 for (NSUInteger i = 0; i <
size; ++i) {
2038 NSTrackingArea *
const t = [trackingArray objectAtIndex : i];
2039 [
self removeTrackingArea : t];
2043 const NSUInteger trackerOptions = NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited |
2044 NSTrackingActiveInActiveApp | NSTrackingInVisibleRect |
2045 NSTrackingEnabledDuringMouseDrag | NSTrackingCursorUpdate;
2048 frame.size.width = self.fWidth;
2049 frame.size.height = self.fHeight;
2051 NSTrackingArea *
const tracker = [[NSTrackingArea alloc] initWithRect : frame
2052 options : trackerOptions owner : self userInfo : nil];
2053 [
self addTrackingArea : tracker];
2058- (
void) updateTrackingAreasAfterRaise
2060 [
self updateTrackingAreas];
2062 for (
QuartzView *childView in [self subviews])
2063 [childView updateTrackingAreasAfterRaise];
2066#pragma mark - X11Drawable protocol.
2083 return self.fQuartzWindow.fScaleFactor;
2089 return self.frame.origin.x;
2095 return self.frame.origin.y;
2101 return self.frame.size.width;
2107 return self.frame.size.height;
2111- (
void) setDrawableSize : (NSSize) newSize
2113 assert(!(newSize.width < 0) &&
"-setDrawableSize, width is negative");
2114 assert(!(newSize.height < 0) &&
"-setDrawableSize, height is negative");
2120 NSRect frame = self.frame;
2121 frame.size = newSize;
2127- (
void) setX : (
int) x Y : (
int) y width : (
unsigned) w height : (
unsigned) h
2129 NSRect newFrame = {};
2130 newFrame.origin.x =
x;
2131 newFrame.origin.y =
y;
2132 newFrame.size.width =
w;
2133 newFrame.size.height =
h;
2135 self.frame = newFrame;
2139- (
void) setX : (
int) x Y : (
int) y
2141 NSRect newFrame = self.frame;
2142 newFrame.origin.x =
x;
2143 newFrame.origin.y =
y;
2145 self.frame = newFrame;
2151 toPoint : (
X11::Point) dstPoint
2154 assert(srcImage != nil &&
2155 "-copyImage:area:withMask:clipOrigin:toPoint:, parameter 'srcImage' is nil");
2156 assert(srcImage.
fImage != nil &&
2157 "-copyImage:area:withMask:clipOrigin:toPoint:, srcImage.fImage is nil");
2160 assert(self.fContext != 0 &&
2161 "-copyImage:area:withMask:clipOrigin:toPoint:, self.fContext is null");
2164 NSLog(
@"QuartzView: -copyImage:area:withMask:clipOrigin:toPoint:,"
2165 " srcRect and copyRect do not intersect");
2172 bool needSubImage =
false;
2173 if (area.fX || area.fY || area.fWidth != srcImage.
fWidth || area.fHeight != srcImage.
fHeight) {
2174 needSubImage =
true;
2177 NSLog(
@"QuartzView: -copyImage:area:withMask:clipOrigin:toPoint:,"
2178 " subimage creation failed");
2182 subImage = srcImage.
fImage;
2188 CGContextTranslateCTM(self.fContext, 0., self.fHeight);
2189 CGContextScaleCTM(self.fContext, 1., -1.);
2193 assert(
mask.fImage != nil &&
2194 "-copyImage:area:withMask:clipOrigin:toPoint:, mask.fImage is nil");
2195 assert(CGImageIsMask(
mask.fImage) ==
true &&
2196 "-copyImage:area:withMask:clipOrigin:toPoint:, mask.fImage is not a mask");
2200 const CGRect clipRect = CGRectMake(clipXY.fX, clipY,
mask.fWidth,
mask.fHeight);
2201 CGContextClipToMask(self.fContext, clipRect,
mask.fImage);
2208 const CGRect imageRect = CGRectMake(dstPoint.fX, dstY, area.fWidth, area.fHeight);
2209 CGContextDrawImage(self.fContext, imageRect, subImage);
2212 CGImageRelease(subImage);
2216- (
void) copyView : (
QuartzView *) srcView area : (
X11::Rectangle) area toPoint : (
X11::Point) dstPoint
2221 assert(srcView != nil &&
"-copyView:area:toPoint:, parameter 'srcView' is nil");
2223 const NSRect frame = [srcView frame];
2225 NSBitmapImageRep *
const imageRep = [srcView bitmapImageRepForCachingDisplayInRect : frame];
2227 NSLog(
@"QuartzView: -copyView:area:toPoint failed");
2231 assert(srcView != nil &&
"-copyView:area:toPoint:, parameter 'srcView' is nil");
2232 assert(self.fContext != 0 &&
"-copyView:area:toPoint, self.fContext is null");
2239 [srcView cacheDisplayInRect : frame toBitmapImageRep : imageRep];
2243 const CGRect subImageRect = CGRectMake(area.fX, area.fY, area.fWidth, area.fHeight);
2246 if (!subImage.Get()) {
2247 NSLog(
@"QuartzView: -copyView:area:toPoint, CGImageCreateWithImageInRect failed");
2252 const CGRect imageRect = CGRectMake(dstPoint.fX,
2253 [self visibleRect].size.height - (CGFloat(dstPoint.fY) + area.fHeight),
2254 area.fWidth, area.fHeight);
2256 CGContextTranslateCTM(self.fContext, 0., [self visibleRect].size.height);
2257 CGContextScaleCTM(self.fContext, 1., -1.);
2259 CGContextDrawImage(self.fContext, imageRect, subImage.Get());
2264 withMask : (
QuartzImage *) mask clipOrigin : (
X11::Point) clipXY toPoint : (
X11::Point) dstPoint
2267 assert(srcPixmap != nil &&
"-copyPixmap:area:withMask:clipOrigin:toPoint:, parameter 'srcPixmap' is nil");
2270 NSLog(
@"QuartzView: -copyPixmap:area:withMask:clipOrigin:toPoint,"
2271 " no intersection between pixmap rectangle and cropArea");
2276 assert(self.fContext != 0 &&
2277 "-copyPixmap:area:withMask:clipOrigin:toPoint:, self.fContext is null");
2282 CGContextTranslateCTM(self.fContext, 0., self.frame.size.height);
2283 CGContextScaleCTM(self.fContext, 1., -1.);
2286 assert(imageFromPixmap.Get() != 0 &&
2287 "-copyPixmap:area:withMask:clipOrigin:toPoint:, createImageFromPixmap failed");
2290 bool needSubImage =
false;
2291 if (area.fX || area.fY || area.fWidth != srcPixmap.
fWidth || area.fHeight != srcPixmap.
fHeight) {
2292 needSubImage =
true;
2293 const CGRect subImageRect = CGRectMake(area.fX, area.fY, area.fHeight, area.fWidth);
2294 subImage = CGImageCreateWithImageInRect(imageFromPixmap.Get(), subImageRect);
2296 NSLog(
@"QuartzView: -copyImage:area:withMask:clipOrigin:toPoint:,"
2297 " subimage creation failed");
2301 subImage = imageFromPixmap.Get();
2304 assert(
mask.fImage != nil &&
2305 "-copyPixmap:area:withMask:clipOrigin:toPoint:, mask.fImage is nil");
2306 assert(CGImageIsMask(
mask.fImage) ==
true &&
2307 "-copyPixmap:area:withMask:clipOrigin:toPoint:, mask.fImage is not a mask");
2312 const CGRect clipRect = CGRectMake(clipXY.fX, clipY,
mask.fWidth,
mask.fHeight);
2313 CGContextClipToMask(self.fContext, clipRect,
mask.fImage);
2318 const CGRect imageRect = CGRectMake(dstPoint.fX, dstY, area.fWidth, area.fHeight);
2319 CGContextDrawImage(self.fContext, imageRect, imageFromPixmap.Get());
2322 CGImageRelease(subImage);
2328 toPoint : (
X11::Point) dstPoint
2330 assert(srcImage != nil &&
"-copyImage:area:toPoint:, parameter 'srcImage' is nil");
2331 assert(srcImage.
fImage != nil &&
"-copyImage:area:toPoint:, srcImage.fImage is nil");
2332 assert(self.fContext != 0 &&
"-copyImage:area:toPoint:, fContext is null");
2335 NSLog(
@"QuartzView: -copyImage:area:toPoint, image and copy area do not intersect");
2340 bool needSubImage =
false;
2341 if (area.fX || area.fY || area.fWidth != srcImage.
fWidth || area.fHeight != srcImage.
fHeight) {
2342 needSubImage =
true;
2345 NSLog(
@"QuartzView: -copyImage:area:toPoint:, subimage creation failed");
2349 subImage = srcImage.
fImage;
2353 CGContextTranslateCTM(self.fContext, 0., self.fHeight);
2354 CGContextScaleCTM(self.fContext, 1., -1.);
2359 const CGRect imageRect = CGRectMake(dstPoint.fX, dstY, area.fWidth, area.fHeight);
2360 CGContextDrawImage(self.fContext, imageRect, subImage);
2363 CGImageRelease(subImage);
2367- (
void) copy : (
NSObject<X11Drawable> *) src area : (
X11::Rectangle) area
2368 withMask : (
QuartzImage *)mask clipOrigin : (
X11::Point) clipXY toPoint : (
X11::Point) dstPoint
2370 assert(
src != nil &&
"-copy:area:withMask:clipOrigin:toPoint:, parameter 'src' is nil");
2371 assert(area.fWidth && area.fHeight &&
"-copy:area:withMask:clipOrigin:toPoint:, area to copy is empty");
2377 [
self copyView : (QuartzView *)qw.fContentView area : area toPoint : dstPoint];
2380 [
self copyView : (QuartzView *)src area : area toPoint : dstPoint];
2382 [
self copyPixmap : (QuartzPixmap *)src area : area withMask : mask clipOrigin : clipXY toPoint : dstPoint];
2384 [
self copyImage : (QuartzImage *)src area : area withMask : mask clipOrigin : clipXY toPoint : dstPoint];
2386 assert(0 &&
"-copy:area:withMask:clipOrigin:toPoint:, src is of unknown type");
2391- (
unsigned char *) readColorBits : (
X11::Rectangle) area
2397 assert(area.fWidth && area.fHeight &&
"-readColorBits:, area to copy is empty");
2400 NSRect visRect = [
self visibleRect];
2405 if (visRect.origin.y < 0) {
2406 visRect.size.height += visRect.origin.
y;
2407 visRect.origin.y = 0.;
2409 if (visRect.origin.x < 0) {
2410 visRect.size.width += visRect.origin.
x;
2411 visRect.origin.x = 0.;
2414 const X11::Rectangle srcRect(
int(visRect.origin.x),
int(visRect.origin.y),
2415 unsigned(visRect.size.width),
unsigned(visRect.size.height));
2418 NSLog(
@"QuartzView: -readColorBits:, visible rect of view and copy area do not intersect");
2423 NSBitmapImageRep *
const imageRep = [
self bitmapImageRepForCachingDisplayInRect : visRect];
2425 NSLog(
@"QuartzView: -readColorBits:, bitmapImageRepForCachingDisplayInRect failed");
2430 [
self cacheDisplayInRect : visRect toBitmapImageRep : imageRep];
2431 self.fContext = ctx;
2433 const NSInteger bitsPerPixel = [imageRep bitsPerPixel];
2435 assert(bitsPerPixel == 32 &&
"-readColorBits:, no alpha channel???");
2436 const NSInteger bytesPerRow = [imageRep bytesPerRow];
2437 unsigned dataWidth = bytesPerRow / (bitsPerPixel / 8);
2439 unsigned char *srcData =
nullptr;
2440 std::vector<unsigned char> downscaled;
2441 if ([self.window.screen backingScaleFactor] > 1 && imageRep.CGImage) {
2443 if (downscaled.size())
2444 srcData = &downscaled[0];
2445 dataWidth = area.fWidth;
2447 srcData = [imageRep bitmapData];
2450 NSLog(
@"QuartzView: -readColorBits:, failed to obtain backing store contents");
2455 unsigned char *
data =
nullptr;
2458 data =
new unsigned char[area.fWidth * area.fHeight * 4];
2459 }
catch (
const std::bad_alloc &) {
2460 NSLog(
@"QuartzView: -readColorBits:, memory allocation failed");
2464 unsigned char *dstPixel =
data;
2465 const unsigned char *
line = srcData + area.
fY * dataWidth * 4;
2466 const unsigned char *srcPixel =
line + area.
fX * 4;
2468 for (
unsigned i = 0; i < area.fHeight; ++i) {
2469 for (
unsigned j = 0; j < area.fWidth; ++j, srcPixel += 4, dstPixel += 4) {
2470 dstPixel[0] = srcPixel[2];
2471 dstPixel[1] = srcPixel[1];
2472 dstPixel[2] = srcPixel[0];
2473 dstPixel[3] = srcPixel[3];
2476 line += dataWidth * 4;
2477 srcPixel =
line + area.
fX * 4;
2487 [fBackgroundPixmap release];
2506 if ([self isHidden])
2510 if ([parent isHidden])
2528- (
void) setFHasFocus : (
BOOL) focus
2530#pragma unused(focus)
2547 [fBackBuffer release];
2581- (
void) activateGrab : (
unsigned) eventMask ownerEvents : (
BOOL) ownerEvents
2597- (
BOOL) acceptsCrossingEvents : (
unsigned) eventMask
2616- (
void) addChild : (
NSView<X11Window> *) child
2618 assert(
child != nil &&
"-addChild:, parameter 'child' is nil");
2620 [
self addSubview : child];
2621 child.fParentView = self;
2627 assert(
attr != 0 &&
"-getAttributes:, parameter 'attr' is null");
2635 assert(
attr != 0 &&
"-setAttributes:, parameter 'attr' is null");
2637#ifdef DEBUG_ROOT_COCOA
2649 [
self removeFromSuperview];
2650 [parent addSubview : self];
2651 [
self setHidden : NO];
2657 [
self setHidden : NO];
2670 [
self setHidden : YES];
2680- (
void) setOverlapped : (
BOOL) overlap
2684 [child setOverlapped : overlap];
2701 using namespace X11;
2704 if (self == sibling)
2706 if ([sibling isHidden])
2709 if (NSEqualRects(sibling.frame, self.frame)) {
2710 [sibling setOverlapped : YES];
2711 [sibling setHidden : YES];
2715 [
self setOverlapped : NO];
2717 [
self setHidden : NO];
2719 [fParentView sortSubviewsUsingFunction : CompareViewsToRaise context : (void *)self];
2721 [
self updateTrackingAreasAfterRaise];
2723 [
self setNeedsDisplay : YES];
2731 using namespace X11;
2733 NSEnumerator *
const reverseEnumerator = [[fParentView subviews] reverseObjectEnumerator];
2734 for (
QuartzView *sibling in reverseEnumerator) {
2735 if (sibling == self)
2738 if (NSEqualRects(sibling.frame, self.frame)) {
2739 [sibling setOverlapped : NO];
2741 [sibling setHidden : NO];
2743 [sibling setNeedsDisplay : YES];
2744 [
self setOverlapped : YES];
2746 [
self setHidden : YES];
2752 [fParentView sortSubviewsUsingFunction : CompareViewsToLower context : (void*)self];
2769 "-configureNotifyTree, gVirtualX is either null or has type different from TGCocoa");
2775 [v configureNotifyTree];
2779#pragma mark - Key grabs.
2782- (
void) addPassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers
2784 [
self removePassiveKeyGrab : keyCode modifiers : modifiers];
2786 modifiers : modifiers];
2787 [fPassiveKeyGrabs addObject : newGrab];
2792- (
void) removePassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers
2794 const NSUInteger count = [fPassiveKeyGrabs count];
2795 for (NSUInteger i = 0; i < count; ++i) {
2797 if ([
grab matchKey : keyCode modifiers : modifiers]) {
2798 [fPassiveKeyGrabs removeObjectAtIndex : i];
2805- (
PassiveKeyGrab *) findPassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers
2807 NSEnumerator *
const enumerator = [fPassiveKeyGrabs objectEnumerator];
2809 if ([
grab matchKey : keyCode modifiers : modifiers])
2820 NSEnumerator *
const enumerator = [fPassiveKeyGrabs objectEnumerator];
2822 if ([
grab matchKey : keyCode])
2829#pragma mark - Painting mechanics.
2832- (
void) drawRect : (NSRect) dirtyRect
2834#pragma unused(dirtyRect)
2836 using namespace X11;
2844 NSGraphicsContext *
const nsContext = [NSGraphicsContext currentContext];
2845 assert(nsContext != nil &&
"-drawRect:, currentContext returned nil");
2851 assert(
fContext != 0 &&
"-drawRect:, graphicsPort returned null");
2856 if (self.fQuartzWindow.fShapeCombineMask)
2868 [NSColor.whiteColor setFill];
2869 NSRect frame = self.frame;
2889 gClient->CancelRedraw(window);
2897 [
self copy : fBackBuffer area : copyArea withMask : nil
2898 clipOrigin : X11::Point() toPoint : X11::Point()];
2902#ifdef DEBUG_ROOT_COCOA
2903 CGContextSetRGBStrokeColor(
fContext, 1., 0., 0., 1.);
2904 CGContextStrokeRect(
fContext, dirtyRect);
2909#ifdef DEBUG_ROOT_COCOA
2910 NSLog(
@"QuartzView: -drawRect: method, no window for id %u was found",
fID);
2916#pragma mark - Geometry.
2919- (
void) setFrame : (NSRect) newFrame
2924 if (NSEqualRects(newFrame, self.frame))
2927 [
super setFrame : newFrame];
2931- (
void) setFrameSize : (NSSize) newSize
2935 [
super setFrameSize : newSize];
2939 "setFrameSize:, gVirtualX is either null or has a type, different from TGCocoa");
2944 [
self setNeedsDisplay : YES];
2947#pragma mark - Event handling.
2952 assert(
fID != 0 &&
"-mouseDown:, fID is 0");
2955 "-mouseDown:, gVirtualX is either null or has a type, different from TGCocoa");
2963 assert(
fID != 0 &&
"-scrollWheel:, fID is 0");
2967 "-scrollWheel:, gVirtualX is either null or has a type, different from TGCocoa");
2970 const CGFloat deltaY = [theEvent deltaY];
2974 }
else if (deltaY > 0) {
2980#ifdef DEBUG_ROOT_COCOA
2982- (
void) printViewInformation
2984 assert(
fID != 0 &&
"-printWindowInformation, fID is 0");
2986 assert(window != 0 &&
"printWindowInformation, window not found");
2988 NSLog(
@"-----------------View %u info:---------------------",
fID);
2989 NSLog(
@"ROOT's window class is %s", window->
IsA()->
GetName());
2990 NSLog(
@"event mask is:");
2992 NSLog(
@"grab mask is:");
2994 NSLog(
@"view's geometry: x == %g, y == %g, w == %g, h == %g", self.frame.origin.x,
2995 self.frame.origin.y, self.frame.size.width, self.frame.size.height);
2996 NSLog(
@"----------------End of view info------------------");
3003 assert(
fID != 0 &&
"-rightMouseDown:, fID is 0");
3005#ifdef DEBUG_ROOT_COCOA
3006 [
self printViewInformation];
3010 "-rightMouseDown:, gVirtualX is either null or has type different from TGCocoa");
3018 assert(
fID != 0 &&
"-otherMouseDown:, fID is 0");
3022 if ([theEvent buttonNumber] == 2) {
3026 "-otherMouseDown:, gVirtualX is either null or has type different from TGCocoa");
3035 assert(
fID != 0 &&
"-mouseUp:, fID is 0");
3038 "-mouseUp:, gVirtualX is either null or has type different from TGCocoa");
3047 assert(
fID != 0 &&
"-rightMouseUp:, fID is 0");
3050 "-rightMouseUp:, gVirtualX is either null or has type different from TGCocoa");
3059 assert(
fID != 0 &&
"-otherMouseUp:, fID is 0");
3063 "-otherMouseUp:, gVirtualX is either null or has type different from TGCocoa");
3071 assert(
fID != 0 &&
"-mouseEntered:, fID is 0");
3073 "-mouseEntered:, gVirtualX is null or not of TGCocoa type");
3082 assert(
fID != 0 &&
"-mouseExited:, fID is 0");
3085 "-mouseExited:, gVirtualX is null or not of TGCocoa type");
3094 assert(
fID != 0 &&
"-mouseMoved:, fID is 0");
3100 "-mouseMoved:, gVirtualX is null or not of TGCocoa type");
3109 assert(
fID != 0 &&
"-mouseDragged:, fID is 0");
3112 assert(vx != 0 &&
"-mouseDragged:, gVirtualX is null or not of TGCocoa type");
3120 assert(
fID != 0 &&
"-rightMouseDragged:, fID is 0");
3123 "-rightMouseDragged:, gVirtualX is null or not of TGCocoa type");
3132 assert(
fID != 0 &&
"-otherMouseDragged:, fID is 0");
3134 if ([theEvent buttonNumber] == 2) {
3136 "-otherMouseDragged:, gVirtualX is null or not of TGCocoa type");
3145 assert(
fID != 0 &&
"-keyDown:, fID is 0");
3148 "-keyDown:, gVirtualX is null or not of TGCocoa type");
3152 eventView = pointerView;
3161 assert(
fID != 0 &&
"-keyUp:, fID is 0");
3164 "-keyUp:, gVirtualX is null or not of TGCocoa type");
3169 eventView = pointerView;
3174#pragma mark - First responder stuff.
3179#pragma unused(theEvent)
3184- (
BOOL) acceptsFirstResponder
3189#pragma mark - Cursors.
3196 [
self.fQuartzWindow invalidateCursorRectsForView : self];
3201- (NSCursor *) createCustomCursor
3203 const char *pngFileName = 0;
3207 pngFileName =
"move_cursor.png";
3210 pngFileName =
"hor_arrow_cursor.png";
3213 pngFileName =
"ver_arrow_cursor.png";
3216 pngFileName =
"right_arrow_cursor.png";
3219 pngFileName =
"rotate.png";
3223 pngFileName =
"top_right_cursor.png";
3227 pngFileName =
"top_left_cursor.png";
3236 if (!path || path[0] == 0) {
3241 NSString *nsPath = [NSString stringWithFormat : @"%s", path];
3242 NSImage *
const cursorImage = [[NSImage alloc] initWithContentsOfFile : nsPath];
3248 NSCursor *
const customCursor = [[[NSCursor alloc] initWithImage : cursorImage
3249 hotSpot : hotSpot] autorelease];
3251 [cursorImage release];
3253 return customCursor;
3260- (
void) resetCursorRects
3263 [
self addCursorRect : self.visibleRect cursor : cursor];
3267- (
void) cursorUpdate
3279#pragma unused(event)
3291 [
self performSelector : @selector(cursorUpdate) withObject : nil afterDelay : 0.05f];
3294#pragma mark - Emulated X11 properties.
3297- (
void) setProperty : (const
char *) propName data : (
unsigned char *) propData
3298 size : (
unsigned) dataSize forType : (
Atom_t) dataType format : (
unsigned) format
3300 assert(propName != 0 &&
"-setProperty:data:size:forType:, parameter 'propName' is null");
3301 assert(propData != 0 &&
"-setProperty:data:size:forType:, parameter 'propData' is null");
3302 assert(dataSize != 0 &&
"-setProperty:data:size:forType:, parameter 'dataSize' is 0");
3304 NSString *
const key = [NSString stringWithCString : propName encoding : NSASCIIStringEncoding];
3309 [property resetPropertyData : propData size : dataSize type : dataType format : format];
3313 type : dataType format : format];
3314 [fX11Properties setObject : property forKey : key];
3320- (
BOOL) hasProperty : (const
char *) propName
3322 assert(propName != 0 &&
"-hasProperty:, propName parameter is null");
3324 NSString *
const key = [NSString stringWithCString : propName encoding : NSASCIIStringEncoding];
3327 return property != nil;
3331- (
unsigned char *) getProperty : (const
char *) propName returnType : (
Atom_t *) type
3332 returnFormat : (
unsigned *) format nElements : (
unsigned *) nElements
3334 assert(propName != 0 &&
3335 "-getProperty:returnType:returnFormat:nElements:, parameter 'propName' is null");
3337 "-getProperty:returnType:returnFormat:nElements:, parameter 'type' is null");
3339 "-getProperty:returnType:returnFormat:nElements:, parameter 'format' is null");
3340 assert(nElements != 0 &&
3341 "-getProperty:returnType:returnFormat:nElements:, parameter 'nElements' is null");
3343 NSString *
const key = [NSString stringWithCString : propName encoding : NSASCIIStringEncoding];
3346 "-getProperty:returnType:returnFormat:nElements, property not found");
3348 NSData *
const propData =
property.fPropertyData;
3350 const NSUInteger dataSize = [propData length];
3351 unsigned char *buff = 0;
3353 buff =
new unsigned char[dataSize]();
3354 }
catch (
const std::bad_alloc &) {
3356 NSLog(
@"QuartzWindow: -getProperty:returnType:returnFormat:nElements:,"
3357 " memory allocation failed");
3361 [propData getBytes : buff length : dataSize];
3362 *
format =
property.fFormat;
3364 *nElements = dataSize;
3367 *nElements= dataSize / 2;
3369 *nElements = dataSize / 4;
3371 *
type =
property.fType;
3377- (
void) removeProperty : (const
char *) propName
3379 assert(propName != 0 &&
"-removeProperty:, parameter 'propName' is null");
3381 NSString *
const key = [NSString stringWithCString : propName
3382 encoding : NSASCIIStringEncoding];
3383 [fX11Properties removeObjectForKey : key];
3388- (NSDragOperation) draggingEntered : (
id<NSDraggingInfo>) sender
3390 NSPasteboard *
const pasteBoard = [sender draggingPasteboard];
3391 const NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
3393 if ([[pasteBoard types] containsObject : NSFilenamesPboardType] && (sourceDragMask & NSDragOperationCopy))
3394 return NSDragOperationCopy;
3396 return NSDragOperationNone;
3400- (
BOOL) performDragOperation : (
id<NSDraggingInfo>) sender
3411 NSPasteboard *
const pasteBoard = [sender draggingPasteboard];
3412 const NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
3414 if ([[pasteBoard types] containsObject : NSFilenamesPboardType] && (sourceDragMask & NSDragOperationCopy)) {
3420 NSArray *
const files = [pasteBoard propertyListForType : NSFilenamesPboardType];
3421 for (NSString *path in files) {
3423 NSString *
const item = [@"file://" stringByAppendingString : path];
3425 const NSUInteger
len = [item lengthOfBytesUsingEncoding : NSASCIIStringEncoding] + 1;
3427 std::vector<unsigned char> propertyData(
len);
3428 [item getCString : (char *)&propertyData[0] maxLength : propertyData.size()
3429 encoding : NSASCIIStringEncoding];
3432 [targetView setProperty : "_XC_DND_DATA" data : &propertyData[0]
3433 size : propertyData.size() forType : textUriAtom format : 8];
3434 }
catch (
const std::bad_alloc &) {
3436 NSLog(
@"QuartzView: -performDragOperation:, memory allocation failed");
3452 event1.
fUser[2] = textUriAtom;
3462 event2.
fUser[2] = 0;
3463 NSPoint dropPoint = [sender draggingLocation];
3466 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
Handle_t Window_t
Window handle.
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
const Mask_t kWABackPixmap
const Mask_t kWABorderWidth
const Mask_t kWABackingPlanes
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t mask
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t cursor
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t TranslateCoordinates
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t GetWindowAttributes
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t rect
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t child
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t win
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t attr
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name CreateCursor
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t grab
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t src
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t property
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
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
A TGTextView is a text viewer widget.
ROOT GUI Window base class.
TClass * IsA() const override
const char * GetName() const override
Returns name of object.
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
QuartzWindow * fQuartzWindow
void adjustXorWindowGeometry()
XorDrawingWindow * findXorWindow()
QuartzWindow * fMainWindow
QuartzView * fContentView
QuartzImage * fShapeCombineMask
void(off) SmallVectorTemplateBase< T
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)
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
Longptr_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.
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?