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;
72 backing : NSBackingStoreBuffered
74 windowAttributes : attr];
76 throw std::runtime_error(
"CreateTopLevelWindow failed");
78 newWindow.fDepth = depth;
79 newWindow.fClass = clss;
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");
117 assert(dynamic_cast<TGCocoa *>(
gVirtualX) &&
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;
179 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
180 "GlobalYCocoaToROOT, gVirtualX is either nul or has a wrong type");
184 return int(frame.
fHeight - (yCocoa - frame.
fY));
190 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
191 "GlobalXCocoaToROOT, gVirtualX is either nul or has a wrong type");
194 return int(xCocoa - frame.
fX);
200 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
201 "GlobalYROOTToCocoa, gVirtualX is either nul or has a wrong type");
204 return int(frame.
fY + (frame.
fHeight - yROOT));
210 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
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) {
325 QuartzWindow *
const qw = (QuartzWindow *)window;
340 assert(children != nil &&
"FindDNDAwareViewInPoint, parameter 'children' is nil");
345 NSEnumerator *
const reverseEnumerator = [children reverseObjectEnumerator];
346 for (NSView<X11Window> *child in reverseEnumerator) {
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) {
376 QuartzWindow *
const qw = (QuartzWindow *)window;
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) {
417 QuartzWindow *
const qWindow = (QuartzWindow *)nsWindow;
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];
442 return (NSView<X11Window> *)[[topLevel contentView] hitTest : mousePosition];
455 assert(pointerEvent != nil &&
456 "FindWindowForPointerEvent, parameter 'pointerEvent' is nil");
460 NSArray *
const orderedWindows = [NSApp orderedWindows];
461 for (NSWindow *nsWindow in orderedWindows) {
465 QuartzWindow *
const qWindow = (QuartzWindow *)nsWindow;
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])
516 return (NSView<X11Window> *)[[topLevel contentView] hitTest : mousePosition];
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) {
573 QuartzWindow *
const qWindow = (QuartzWindow *)nsWindow;
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");
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");
654 if ([(NSObject *)window isKindOfClass : [
QuartzWindow class]]) {
655 QuartzWindow *
const qw = (QuartzWindow *)window;
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 734 NSComparisonResult
CompareViewsToLower(__kindof NSView *view1, __kindof NSView *view2,
void *context)
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 751 NSComparisonResult
CompareViewsToRaise(__kindof NSView *view1, __kindof NSView *view2,
void *context)
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");
928 if (!dynamic_cast<const TGViewFrame*>(window))
934 if (!view.fParentView)
955 assert(view != nil &&
"ViewIsHtmlView, parameter 'view' is nil");
964 assert(view != nil &&
"ViewIsHtmlViewFrame, parameter 'view' is nil");
973 if (!dynamic_cast<const TGViewFrame*>(window))
979 if (!view.fParentView)
988 assert(textView != nil &&
"FrameForTextView, parameter 'textView' is nil");
990 for (NSView<X11Window> *child in [textView subviews]) {
1001 assert(htmlView != nil &&
"FrameForHtmlView, parameter 'htmlView' is nil");
1003 for (NSView<X11Window> *child in [htmlView subviews]) {
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");
1023 CGContextRef currContext = (CGContextRef)[nsContext graphicsPort];
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";
1104 void 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");
1131 #pragma mark - QuartzWindow's life cycle. 1134 - (
id) initWithContentRect : (NSRect) contentRect styleMask : (NSUInteger) windowStyle
1135 backing : (NSBackingStoreType) bufferingType defer : (BOOL) deferCreation
1138 self = [
super initWithContentRect : contentRect styleMask : windowStyle
1139 backing : bufferingType defer : deferCreation];
1143 [
self setAllowsConcurrentViewDrawing : NO];
1145 self.delegate =
self;
1147 NSRect contentViewRect = contentRect;
1148 contentViewRect.origin.x = 0.f;
1149 contentViewRect.origin.y = 0.f;
1153 [
self setContentView : fContentView];
1173 assert(glView != nil &&
"-initWithGLView, parameter 'glView' is nil");
1178 NSRect contentRect = glView.frame;
1179 contentRect.origin = NSPoint();
1181 self = [
super initWithContentRect : contentRect styleMask : styleMask
1182 backing : NSBackingStoreBuffered defer : NO];
1186 [
self setAllowsConcurrentViewDrawing : NO];
1187 self.delegate =
self;
1189 [
self setContentView : fContentView];
1212 - (
void) setContentView:(NSView *)cv
1214 [
super setContentView:cv];
1222 - (
void) setFIsDeleted : (BOOL) deleted
1227 #pragma mark - Forwaring: I want to forward a lot of property setters/getters to the content view. 1230 - (
void) forwardInvocation : (NSInvocation *) anInvocation
1235 if ([
fContentView respondsToSelector : [anInvocation selector]]) {
1236 [anInvocation invokeWithTarget : fContentView];
1238 [
super forwardInvocation : anInvocation];
1243 - (NSMethodSignature*) methodSignatureForSelector : (
SEL) selector
1245 NSMethodSignature *signature = [
super methodSignatureForSelector : selector];
1249 signature = [
fContentView methodSignatureForSelector : selector];
1264 assert(window != nil &&
"-addTransientWindow:, parameter 'window' is nil");
1273 [
self addChildWindow : window ordered : NSWindowAbove];
1279 - (
void) makeKeyAndOrderFront : (
id) sender
1281 #pragma unused(sender) 1286 #ifdef MAC_OS_X_VERSION_10_9 1287 [
self setCollectionBehavior : NSWindowCollectionBehaviorMoveToActiveSpace];
1289 [
self setCollectionBehavior : NSWindowCollectionBehaviorCanJoinAllSpaces];
1292 [
super makeKeyAndOrderFront : self];
1294 [
self setCollectionBehavior : NSWindowCollectionBehaviorDefault];
1298 - (
void) setFDelayedTransient : (BOOL)
d 1321 #pragma mark - X11Drawable's protocol. 1342 return self.screen.backingScaleFactor;
1360 return self.frame.size.width;
1369 assert(
fContentView != nil &&
"-fHeight:, content view is nil");
1375 - (
void) setDrawableSize : (NSSize) newSize
1378 assert(!(newSize.width < 0) &&
"-setDrawableSize:, width is negative");
1379 assert(!(newSize.height < 0) &&
"-setDrawableSize:, height is negative");
1381 NSRect frame =
self.frame;
1385 frame.origin.y = frame.origin.y + frame.size.height - newSize.height - dY;
1386 frame.size = newSize;
1387 frame.size.height += dY;
1388 [
self setFrame : frame display : YES];
1392 - (
void) setX : (
int) x Y : (
int) y width : (
unsigned) w height : (
unsigned) h
1394 NSSize newSize = {};
1397 [
self setContentSize : newSize];
1400 NSPoint topLeft = {};
1404 [
self setFrameTopLeftPoint : topLeft];
1408 - (
void) setX : (
int) x Y : (
int) y
1410 NSPoint topLeft = {};
1414 [
self setFrameTopLeftPoint : topLeft];
1419 clipOrigin : (
X11::Point) clipXY toPoint : (
X11::Point) dstPoint
1424 [
fContentView copy : src area : area withMask : mask clipOrigin : clipXY toPoint : dstPoint];
1428 - (
unsigned char *) readColorBits : (
X11::Rectangle) area
1436 #pragma mark - X11Window protocol's implementation. 1447 #pragma unused(parent) 1465 - (
void) setFBackgroundPixel : (
unsigned long) backgroundColor
1471 CGFloat rgba[] = {0., 0., 0., 1.};
1474 [
self setBackgroundColor : [NSColor colorWithColorSpace : [NSColorSpace deviceRGBColorSpace] components : rgba count : 4]];
1503 - (
void) addChild : (NSView<X11Window> *) child
1505 assert(child != nil &&
"-addChild:, parameter 'child' is nil");
1509 assert([child isKindOfClass : [
QuartzView class]] &&
1510 "-addChild: gl view in a top-level window as content view is not supported");
1513 [
self setContentView : child];
1525 assert(attr &&
"-getAttributes:, parameter 'attr' is nil");
1533 assert(attr != 0 &&
"-setAttributes:, parameter 'attr' is null");
1535 #ifdef DEBUG_ROOT_COCOA 1536 log_attributes(attr,
self.fID);
1548 const Util::AutoreleasePool pool;
1551 [
self makeKeyAndOrderFront : self];
1556 [
fMainWindow addChildWindow : self ordered : NSWindowAbove];
1566 const Util::AutoreleasePool pool;
1569 [
self makeKeyAndOrderFront : self];
1574 [
fMainWindow addChildWindow : self ordered : NSWindowAbove];
1584 const Util::AutoreleasePool pool;
1597 [
self orderOut : self];
1605 #pragma mark - Events. 1608 - (
void) sendEvent : (NSEvent *) theEvent
1618 bool generateFakeRelease =
false;
1620 const NSPoint windowPoint = [theEvent locationInWindow];
1622 if (windowPoint.x <= 4 || windowPoint.x >=
self.fWidth - 4)
1623 generateFakeRelease =
true;
1625 if (windowPoint.y <= 4 || windowPoint.y >=
self.fHeight - 4)
1626 generateFakeRelease =
true;
1628 const NSPoint viewPoint = [
fContentView convertPoint : windowPoint fromView : nil];
1630 if (viewPoint.y <= 0 && windowPoint.y >= 0)
1631 generateFakeRelease =
true;
1633 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
1634 "-sendEvent:, gVirtualX is either null or not of TGCocoa type");
1648 [
super sendEvent : theEvent];
1651 #pragma mark - NSWindowDelegate's methods. 1654 - (BOOL) windowShouldClose : (
id) sender
1656 #pragma unused(sender) 1660 if ([[
self childWindows] count])
1671 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
1672 "-windowShouldClose:, gVirtualX is either null or has a type different from TGCocoa");
1681 - (
void) windowDidBecomeKey : (NSNotification *) aNotification
1683 #pragma unused(aNotification) 1691 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
1692 "-windowDidBecomeKey:, gVirtualX is null or not of TGCocoa type");
1700 - (
void) windowDidResignKey : (NSNotification *) aNotification
1702 #pragma unused(aNotification) 1708 #pragma mark - Passive key grab info. 1713 - (
id) initWithKey : (unichar) keyCode modifiers : (NSUInteger) modifiers
1715 if (
self = [super
init]) {
1724 - (BOOL) matchKey : (unichar) keyCode modifiers : (NSUInteger) modifiers
1730 - (BOOL) matchKey : (unichar) keyCode
1749 #pragma mark - X11 property emulation. 1751 @interface QuartzWindowProperty : NSObject {
1752 NSData *fPropertyData;
1761 @implementation QuartzWindowProperty
1766 - (
id) initWithData : (
unsigned char *)
data size : (unsigned) dataSize
type : (
Atom_t)
type format : (unsigned) format
1768 if (
self = [super
init]) {
1770 fPropertyData = nil;
1774 [
self resetPropertyData : data size : dataSize type : type format : format];
1783 [fPropertyData release];
1789 - (
void) resetPropertyData : (
unsigned char *)
data size : (unsigned) dataSize
1792 [fPropertyData release];
1797 else if (format == 32)
1800 fPropertyData = [[NSData dataWithBytes : data length : dataSize] retain];
1806 - (NSData *) fPropertyData
1808 return fPropertyData;
1812 - (unsigned) fFormat
1819 #pragma mark - QuartzView. 1852 #pragma mark - Lifetime. 1857 if (
self = [super initWithFrame : frame]) {
1869 [
self setCanDrawConcurrently : NO];
1871 [
self setHidden : YES];
1898 #pragma mark - Tracking area. 1903 - (
void) updateTrackingAreas
1905 [
super updateTrackingAreas];
1910 const Util::AutoreleasePool pool;
1912 if (NSArray *trackingArray = [
self trackingAreas]) {
1913 const NSUInteger size = [trackingArray count];
1914 for (NSUInteger i = 0; i < size; ++i) {
1915 NSTrackingArea *
const t = [trackingArray objectAtIndex : i];
1916 [
self removeTrackingArea : t];
1920 const NSUInteger trackerOptions = NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited |
1921 NSTrackingActiveInActiveApp | NSTrackingInVisibleRect |
1922 NSTrackingEnabledDuringMouseDrag | NSTrackingCursorUpdate;
1925 frame.size.width =
self.fWidth;
1926 frame.size.height =
self.fHeight;
1928 NSTrackingArea *
const tracker = [[NSTrackingArea alloc] initWithRect : frame
1929 options : trackerOptions owner : self userInfo : nil];
1930 [
self addTrackingArea : tracker];
1935 - (
void) updateTrackingAreasAfterRaise
1937 [
self updateTrackingAreas];
1939 for (
QuartzView *childView in [
self subviews])
1940 [childView updateTrackingAreasAfterRaise];
1943 #pragma mark - X11Drawable protocol. 1960 return self.fQuartzWindow.fScaleFactor;
1966 return self.frame.origin.x;
1972 return self.frame.origin.y;
1978 return self.frame.size.width;
1984 return self.frame.size.height;
1988 - (
void) setDrawableSize : (NSSize) newSize
1990 assert(!(newSize.width < 0) &&
"-setDrawableSize, width is negative");
1991 assert(!(newSize.height < 0) &&
"-setDrawableSize, height is negative");
1997 NSRect frame =
self.frame;
1998 frame.size = newSize;
2004 - (
void) setX : (
int) x Y : (
int) y width : (
unsigned) w height : (
unsigned) h
2006 NSRect newFrame = {};
2007 newFrame.origin.x =
x;
2008 newFrame.origin.y =
y;
2009 newFrame.size.width = w;
2010 newFrame.size.height =
h;
2012 self.frame = newFrame;
2016 - (
void) setX : (
int) x Y : (
int) y
2018 NSRect newFrame =
self.frame;
2019 newFrame.origin.x =
x;
2020 newFrame.origin.y =
y;
2022 self.frame = newFrame;
2031 assert(srcImage != nil &&
2032 "-copyImage:area:withMask:clipOrigin:toPoint:, parameter 'srcImage' is nil");
2033 assert(srcImage.fImage != nil &&
2034 "-copyImage:area:withMask:clipOrigin:toPoint:, srcImage.fImage is nil");
2038 "-copyImage:area:withMask:clipOrigin:toPoint:, self.fContext is null");
2041 NSLog(
@"QuartzView: -copyImage:area:withMask:clipOrigin:toPoint:," 2042 " srcRect and copyRect do not intersect");
2048 CGImageRef subImage = 0;
2049 bool needSubImage =
false;
2050 if (area.fX || area.fY || area.fWidth != srcImage.fWidth || area.fHeight != srcImage.fHeight) {
2051 needSubImage =
true;
2054 NSLog(
@"QuartzView: -copyImage:area:withMask:clipOrigin:toPoint:," 2055 " subimage creation failed");
2059 subImage = srcImage.fImage;
2066 CGContextScaleCTM(
self.
fContext, 1., -1.);
2070 assert(mask.
fImage != nil &&
2071 "-copyImage:area:withMask:clipOrigin:toPoint:, mask.fImage is nil");
2072 assert(CGImageIsMask(mask.
fImage) ==
true &&
2073 "-copyImage:area:withMask:clipOrigin:toPoint:, mask.fImage is not a mask");
2077 const CGRect clipRect = CGRectMake(clipXY.fX, clipY, mask.
fWidth, mask.
fHeight);
2085 const CGRect imageRect = CGRectMake(dstPoint.fX, dstY, area.fWidth, area.fHeight);
2086 CGContextDrawImage(
self.
fContext, imageRect, subImage);
2089 CGImageRelease(subImage);
2098 assert(srcView != nil &&
"-copyView:area:toPoint:, parameter 'srcView' is nil");
2100 const NSRect frame = [srcView frame];
2102 NSBitmapImageRep *
const imageRep = [srcView bitmapImageRepForCachingDisplayInRect : frame];
2104 NSLog(
@"QuartzView: -copyView:area:toPoint failed");
2108 assert(srcView != nil &&
"-copyView:area:toPoint:, parameter 'srcView' is nil");
2109 assert(
self.
fContext != 0 &&
"-copyView:area:toPoint, self.fContext is null");
2114 CGContextRef ctx = srcView.fContext;
2115 srcView.fSnapshotDraw = YES;
2116 [srcView cacheDisplayInRect : frame toBitmapImageRep : imageRep];
2117 srcView.fSnapshotDraw = NO;
2118 srcView.fContext = ctx;
2120 const CGRect subImageRect = CGRectMake(area.fX, area.fY, area.fWidth, area.fHeight);
2121 const Util::CFScopeGuard<CGImageRef> subImage(CGImageCreateWithImageInRect(imageRep.CGImage, subImageRect));
2123 if (!subImage.Get()) {
2124 NSLog(
@"QuartzView: -copyView:area:toPoint, CGImageCreateWithImageInRect failed");
2129 const CGRect imageRect = CGRectMake(dstPoint.fX,
2130 [
self visibleRect].size.height - (CGFloat(dstPoint.fY) + area.fHeight),
2131 area.fWidth, area.fHeight);
2133 CGContextTranslateCTM(
self.
fContext, 0., [
self visibleRect].size.height);
2134 CGContextScaleCTM(
self.
fContext, 1., -1.);
2136 CGContextDrawImage(
self.
fContext, imageRect, subImage.Get());
2144 assert(srcPixmap != nil &&
"-copyPixmap:area:withMask:clipOrigin:toPoint:, parameter 'srcPixmap' is nil");
2147 NSLog(
@"QuartzView: -copyPixmap:area:withMask:clipOrigin:toPoint," 2148 " no intersection between pixmap rectangle and cropArea");
2154 "-copyPixmap:area:withMask:clipOrigin:toPoint:, self.fContext is null");
2159 CGContextTranslateCTM(
self.
fContext, 0.,
self.frame.size.height);
2160 CGContextScaleCTM(
self.
fContext, 1., -1.);
2162 const Util::CFScopeGuard<CGImageRef> imageFromPixmap([srcPixmap createImageFromPixmap]);
2163 assert(imageFromPixmap.Get() != 0 &&
2164 "-copyPixmap:area:withMask:clipOrigin:toPoint:, createImageFromPixmap failed");
2166 CGImageRef subImage = 0;
2167 bool needSubImage =
false;
2168 if (area.fX || area.fY || area.fWidth != srcPixmap.fWidth || area.fHeight != srcPixmap.fHeight) {
2169 needSubImage =
true;
2170 const CGRect subImageRect = CGRectMake(area.fX, area.fY, area.fHeight, area.fWidth);
2171 subImage = CGImageCreateWithImageInRect(imageFromPixmap.Get(), subImageRect);
2173 NSLog(
@"QuartzView: -copyImage:area:withMask:clipOrigin:toPoint:," 2174 " subimage creation failed");
2178 subImage = imageFromPixmap.Get();
2181 assert(mask.
fImage != nil &&
2182 "-copyPixmap:area:withMask:clipOrigin:toPoint:, mask.fImage is nil");
2183 assert(CGImageIsMask(mask.
fImage) ==
true &&
2184 "-copyPixmap:area:withMask:clipOrigin:toPoint:, mask.fImage is not a mask");
2189 const CGRect clipRect = CGRectMake(clipXY.fX, clipY, mask.
fWidth, mask.
fHeight);
2195 const CGRect imageRect = CGRectMake(dstPoint.fX, dstY, area.fWidth, area.fHeight);
2196 CGContextDrawImage(
self.
fContext, imageRect, imageFromPixmap.Get());
2199 CGImageRelease(subImage);
2207 assert(srcImage != nil &&
"-copyImage:area:toPoint:, parameter 'srcImage' is nil");
2208 assert(srcImage.fImage != nil &&
"-copyImage:area:toPoint:, srcImage.fImage is nil");
2209 assert(
self.
fContext != 0 &&
"-copyImage:area:toPoint:, fContext is null");
2212 NSLog(
@"QuartzView: -copyImage:area:toPoint, image and copy area do not intersect");
2216 CGImageRef subImage = 0;
2217 bool needSubImage =
false;
2218 if (area.fX || area.fY || area.fWidth != srcImage.fWidth || area.fHeight != srcImage.fHeight) {
2219 needSubImage =
true;
2222 NSLog(
@"QuartzView: -copyImage:area:toPoint:, subimage creation failed");
2226 subImage = srcImage.fImage;
2231 CGContextScaleCTM(
self.
fContext, 1., -1.);
2236 const CGRect imageRect = CGRectMake(dstPoint.fX, dstY, area.fWidth, area.fHeight);
2237 CGContextDrawImage(
self.
fContext, imageRect, subImage);
2240 CGImageRelease(subImage);
2245 withMask : (
QuartzImage *)mask clipOrigin : (
X11::Point) clipXY toPoint : (
X11::Point) dstPoint
2247 assert(src != nil &&
"-copy:area:withMask:clipOrigin:toPoint:, parameter 'src' is nil");
2248 assert(area.fWidth && area.fHeight &&
"-copy:area:withMask:clipOrigin:toPoint:, area to copy is empty");
2254 [
self copyView : (QuartzView *)qw.fContentView area : area toPoint : dstPoint];
2255 }
else if ([src isKindOfClass : [
QuartzView class]]) {
2257 [
self copyView : (QuartzView *)src area : area toPoint : dstPoint];
2258 }
else if ([src isKindOfClass : [
QuartzPixmap class]]) {
2259 [
self copyPixmap : (QuartzPixmap *)src area : area withMask : mask clipOrigin : clipXY toPoint : dstPoint];
2260 }
else if ([src isKindOfClass : [
QuartzImage class]]) {
2261 [
self copyImage : (QuartzImage *)src area : area withMask : mask clipOrigin : clipXY toPoint : dstPoint];
2263 assert(0 &&
"-copy:area:withMask:clipOrigin:toPoint:, src is of unknown type");
2268 - (
unsigned char *) readColorBits : (
X11::Rectangle) area
2274 assert(area.fWidth && area.fHeight &&
"-readColorBits:, area to copy is empty");
2277 const NSRect visRect = [
self visibleRect];
2278 const X11::Rectangle srcRect(
int(visRect.origin.x),
int(visRect.origin.y),
2279 unsigned(visRect.size.width),
unsigned(visRect.size.height));
2282 NSLog(
@"QuartzView: -readColorBits:, visible rect of view and copy area do not intersect");
2287 NSBitmapImageRep *
const imageRep = [
self bitmapImageRepForCachingDisplayInRect : visRect];
2289 NSLog(
@"QuartzView: -readColorBits:, bitmapImageRepForCachingDisplayInRect failed");
2293 CGContextRef ctx =
self.fContext;
2294 [
self cacheDisplayInRect : visRect toBitmapImageRep : imageRep];
2295 self.fContext = ctx;
2297 const NSInteger bitsPerPixel = [imageRep bitsPerPixel];
2299 assert(bitsPerPixel == 32 &&
"-readColorBits:, no alpha channel???");
2300 const NSInteger bytesPerRow = [imageRep bytesPerRow];
2301 unsigned dataWidth = bytesPerRow / (bitsPerPixel / 8);
2303 unsigned char *srcData =
nullptr;
2304 std::vector<unsigned char> downscaled;
2305 if ([
self.window.screen backingScaleFactor] > 1 && imageRep.CGImage) {
2307 if (downscaled.size())
2308 srcData = &downscaled[0];
2309 dataWidth = area.fWidth;
2311 srcData = [imageRep bitmapData];
2314 NSLog(
@"QuartzView: -readColorBits:, failed to obtain backing store contents");
2319 unsigned char *
data =
nullptr;
2322 data =
new unsigned char[area.fWidth * area.fHeight * 4];
2323 }
catch (
const std::bad_alloc &) {
2324 NSLog(
@"QuartzView: -readColorBits:, memory allocation failed");
2328 unsigned char *dstPixel =
data;
2329 const unsigned char *
line = srcData + area.fY * dataWidth * 4;
2330 const unsigned char *srcPixel =
line + area.fX * 4;
2332 for (
unsigned i = 0; i < area.fHeight; ++i) {
2333 for (
unsigned j = 0; j < area.fWidth; ++j, srcPixel += 4, dstPixel += 4) {
2334 dstPixel[0] = srcPixel[2];
2335 dstPixel[1] = srcPixel[1];
2336 dstPixel[2] = srcPixel[0];
2337 dstPixel[3] = srcPixel[3];
2340 line += dataWidth * 4;
2341 srcPixel =
line + area.fX * 4;
2370 if ([
self isHidden])
2374 if ([parent isHidden])
2392 - (
void) setFHasFocus : (BOOL) focus
2394 #pragma unused(focus) 2445 - (
void) activateGrab : (
unsigned) eventMask ownerEvents : (BOOL) ownerEvents
2461 - (BOOL) acceptsCrossingEvents : (
unsigned) eventMask
2480 - (
void) addChild : (NSView<X11Window> *) child
2482 assert(child != nil &&
"-addChild:, parameter 'child' is nil");
2484 [
self addSubview : child];
2485 child.fParentView =
self;
2491 assert(attr != 0 &&
"-getAttributes:, parameter 'attr' is null");
2499 assert(attr != 0 &&
"-setAttributes:, parameter 'attr' is null");
2501 #ifdef DEBUG_ROOT_COCOA 2502 log_attributes(attr,
fID);
2513 [
self removeFromSuperview];
2514 [parent addSubview : self];
2515 [
self setHidden : NO];
2521 [
self setHidden : NO];
2534 [
self setHidden : YES];
2544 - (
void) setOverlapped : (BOOL) overlap
2547 for (NSView<X11Window> *child in [
self subviews])
2548 [child setOverlapped : overlap];
2565 using namespace X11;
2568 if (
self == sibling)
2570 if ([sibling isHidden])
2573 if (NSEqualRects(sibling.frame,
self.frame)) {
2574 [sibling setOverlapped : YES];
2575 [sibling setHidden : YES];
2581 [
self setHidden : NO];
2583 [
fParentView sortSubviewsUsingFunction : CompareViewsToRaise context : (void *)self];
2585 [
self updateTrackingAreasAfterRaise];
2587 [
self setNeedsDisplay : YES];
2595 using namespace X11;
2597 NSEnumerator *
const reverseEnumerator = [[
fParentView subviews] reverseObjectEnumerator];
2598 for (
QuartzView *sibling in reverseEnumerator) {
2599 if (sibling ==
self)
2602 if (NSEqualRects(sibling.frame,
self.frame)) {
2603 [sibling setOverlapped : NO];
2605 [sibling setHidden : NO];
2607 [sibling setNeedsDisplay : YES];
2610 [
self setHidden : YES];
2616 [
fParentView sortSubviewsUsingFunction : CompareViewsToLower context : (void*)self];
2632 assert(dynamic_cast<TGCocoa *>(
gVirtualX) &&
2633 "-configureNotifyTree, gVirtualX is either null or has type different from TGCocoa");
2638 for (NSView<X11Window> *
v in [
self subviews])
2639 [v configureNotifyTree];
2643 #pragma mark - Key grabs. 2646 - (
void) addPassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers
2648 [
self removePassiveKeyGrab : keyCode modifiers : modifiers];
2650 modifiers : modifiers];
2656 - (
void) removePassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers
2659 for (NSUInteger i = 0; i < count; ++i) {
2661 if ([grab matchKey : keyCode modifiers : modifiers]) {
2669 - (
PassiveKeyGrab *) findPassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers
2673 if ([grab matchKey : keyCode modifiers : modifiers])
2686 if ([grab matchKey : keyCode])
2693 #pragma mark - Painting mechanics. 2696 - (
void) drawRect : (NSRect) dirtyRect
2698 #pragma unused(dirtyRect) 2700 using namespace X11;
2708 NSGraphicsContext *
const nsContext = [NSGraphicsContext currentContext];
2709 assert(nsContext != nil &&
"-drawRect:, currentContext returned nil");
2714 fContext = (CGContextRef)[nsContext graphicsPort];
2715 assert(
fContext != 0 &&
"-drawRect:, graphicsPort returned null");
2726 if (dynamic_cast<const TGContainer*>(window))
2749 gClient->CancelRedraw(window);
2757 [
self copy : fBackBuffer area : copyArea withMask : nil
2758 clipOrigin : X11::Point() toPoint : X11::Point()];
2762 #ifdef DEBUG_ROOT_COCOA 2763 CGContextSetRGBStrokeColor(
fContext, 1., 0., 0., 1.);
2764 CGContextStrokeRect(
fContext, dirtyRect);
2769 #ifdef DEBUG_ROOT_COCOA 2770 NSLog(
@"QuartzView: -drawRect: method, no window for id %u was found",
fID);
2776 #pragma mark - Geometry. 2779 - (
void) setFrame : (NSRect) newFrame
2784 if (NSEqualRects(newFrame,
self.frame))
2787 [
super setFrame : newFrame];
2791 - (
void) setFrameSize : (NSSize) newSize
2795 [
super setFrameSize : newSize];
2798 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2799 "setFrameSize:, gVirtualX is either null or has a type, different from TGCocoa");
2804 [
self setNeedsDisplay : YES];
2807 #pragma mark - Event handling. 2810 - (
void) mouseDown : (NSEvent *) theEvent
2812 assert(
fID != 0 &&
"-mouseDown:, fID is 0");
2814 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2815 "-mouseDown:, gVirtualX is either null or has a type, different from TGCocoa");
2821 - (
void) scrollWheel : (NSEvent*) theEvent
2823 assert(
fID != 0 &&
"-scrollWheel:, fID is 0");
2826 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2827 "-scrollWheel:, gVirtualX is either null or has a type, different from TGCocoa");
2830 const CGFloat deltaY = [theEvent deltaY];
2834 }
else if (deltaY > 0) {
2840 #ifdef DEBUG_ROOT_COCOA 2842 - (
void) printViewInformation
2844 assert(
fID != 0 &&
"-printWindowInformation, fID is 0");
2846 assert(window != 0 &&
"printWindowInformation, window not found");
2848 NSLog(
@"-----------------View %u info:---------------------",
fID);
2849 NSLog(
@"ROOT's window class is %s", window->IsA()->
GetName());
2850 NSLog(
@"event mask is:");
2852 NSLog(
@"grab mask is:");
2854 NSLog(
@"view's geometry: x == %g, y == %g, w == %g, h == %g",
self.frame.origin.x,
2855 self.frame.origin.y,
self.frame.size.width,
self.frame.size.height);
2856 NSLog(
@"----------------End of view info------------------");
2861 - (
void) rightMouseDown : (NSEvent *) theEvent
2863 assert(
fID != 0 &&
"-rightMouseDown:, fID is 0");
2865 #ifdef DEBUG_ROOT_COCOA 2866 [
self printViewInformation];
2869 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2870 "-rightMouseDown:, gVirtualX is either null or has type different from TGCocoa");
2876 - (
void) otherMouseDown : (NSEvent *) theEvent
2878 assert(
fID != 0 &&
"-otherMouseDown:, fID is 0");
2882 if ([theEvent buttonNumber] == 2) {
2885 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2886 "-otherMouseDown:, gVirtualX is either null or has type different from TGCocoa");
2893 - (
void) mouseUp : (NSEvent *) theEvent
2895 assert(
fID != 0 &&
"-mouseUp:, fID is 0");
2897 assert(dynamic_cast<TGCocoa *>(
gVirtualX) &&
2898 "-mouseUp:, gVirtualX is either null or has type different from TGCocoa");
2904 - (
void) rightMouseUp : (NSEvent *) theEvent
2907 assert(
fID != 0 &&
"-rightMouseUp:, fID is 0");
2909 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2910 "-rightMouseUp:, gVirtualX is either null or has type different from TGCocoa");
2917 - (
void) otherMouseUp : (NSEvent *) theEvent
2919 assert(
fID != 0 &&
"-otherMouseUp:, fID is 0");
2922 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2923 "-otherMouseUp:, gVirtualX is either null or has type different from TGCocoa");
2929 - (
void) mouseEntered : (NSEvent *) theEvent
2931 assert(
fID != 0 &&
"-mouseEntered:, fID is 0");
2932 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2933 "-mouseEntered:, gVirtualX is null or not of TGCocoa type");
2940 - (
void) mouseExited : (NSEvent *) theEvent
2942 assert(
fID != 0 &&
"-mouseExited:, fID is 0");
2944 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2945 "-mouseExited:, gVirtualX is null or not of TGCocoa type");
2952 - (
void) mouseMoved : (NSEvent *) theEvent
2954 assert(
fID != 0 &&
"-mouseMoved:, fID is 0");
2959 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2960 "-mouseMoved:, gVirtualX is null or not of TGCocoa type");
2967 - (
void) mouseDragged : (NSEvent *) theEvent
2969 assert(
fID != 0 &&
"-mouseDragged:, fID is 0");
2972 assert(vx != 0 &&
"-mouseDragged:, gVirtualX is null or not of TGCocoa type");
2978 - (
void) rightMouseDragged : (NSEvent *) theEvent
2980 assert(
fID != 0 &&
"-rightMouseDragged:, fID is 0");
2982 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2983 "-rightMouseDragged:, gVirtualX is null or not of TGCocoa type");
2990 - (
void) otherMouseDragged : (NSEvent *) theEvent
2992 assert(
fID != 0 &&
"-otherMouseDragged:, fID is 0");
2994 if ([theEvent buttonNumber] == 2) {
2995 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2996 "-otherMouseDragged:, gVirtualX is null or not of TGCocoa type");
3003 - (
void) keyDown : (NSEvent *) theEvent
3005 assert(
fID != 0 &&
"-keyDown:, fID is 0");
3007 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
3008 "-keyDown:, gVirtualX is null or not of TGCocoa type");
3010 NSView<X11Window> *eventView =
self;
3012 eventView = pointerView;
3019 - (
void) keyUp : (NSEvent *) theEvent
3021 assert(
fID != 0 &&
"-keyUp:, fID is 0");
3023 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
3024 "-keyUp:, gVirtualX is null or not of TGCocoa type");
3027 NSView<X11Window> *eventView =
self;
3029 eventView = pointerView;
3034 #pragma mark - First responder stuff. 3037 - (BOOL) acceptsFirstMouse : (NSEvent *) theEvent
3039 #pragma unused(theEvent) 3044 - (BOOL) acceptsFirstResponder
3049 #pragma mark - Cursors. 3056 [
self.fQuartzWindow invalidateCursorRectsForView : self];
3061 - (NSCursor *) createCustomCursor
3063 const char *pngFileName = 0;
3067 pngFileName =
"move_cursor.png";
3070 pngFileName =
"hor_arrow_cursor.png";
3073 pngFileName =
"ver_arrow_cursor.png";
3076 pngFileName =
"right_arrow_cursor.png";
3079 pngFileName =
"rotate.png";
3083 pngFileName =
"top_right_cursor.png";
3087 pngFileName =
"top_left_cursor.png";
3094 const Util::ScopedArray<const char> arrayGuard(path);
3096 if (!path || path[0] == 0) {
3101 NSString *nsPath = [NSString stringWithFormat : @"%s", path];
3102 NSImage *
const cursorImage = [[NSImage alloc] initWithContentsOfFile : nsPath];
3108 NSCursor *
const customCursor = [[[NSCursor alloc] initWithImage : cursorImage
3109 hotSpot : hotSpot] autorelease];
3111 [cursorImage release];
3113 return customCursor;
3120 - (
void) resetCursorRects
3123 [
self addCursorRect :
self.visibleRect cursor : cursor];
3127 - (
void) cursorUpdate
3137 - (
void) cursorUpdate : (NSEvent *)
event 3139 #pragma unused(event) 3151 [
self performSelector : @selector(cursorUpdate) withObject : nil afterDelay : 0.05f];
3154 #pragma mark - Emulated X11 properties. 3157 - (
void) setProperty : (const
char *) propName data : (
unsigned char *) propData
3158 size : (
unsigned) dataSize forType : (
Atom_t) dataType format : (
unsigned) format
3160 assert(propName != 0 &&
"-setProperty:data:size:forType:, parameter 'propName' is null");
3161 assert(propData != 0 &&
"-setProperty:data:size:forType:, parameter 'propData' is null");
3162 assert(dataSize != 0 &&
"-setProperty:data:size:forType:, parameter 'dataSize' is 0");
3164 NSString *
const key = [NSString stringWithCString : propName encoding : NSASCIIStringEncoding];
3165 QuartzWindowProperty *
property = (QuartzWindowProperty *)[
fX11Properties valueForKey : key];
3169 [property resetPropertyData : propData size : dataSize type : dataType format : format];
3172 property = [[QuartzWindowProperty alloc] initWithData : propData size : dataSize
3173 type : dataType format : format];
3180 - (BOOL) hasProperty : (const
char *) propName
3182 assert(propName != 0 &&
"-hasProperty:, propName parameter is null");
3184 NSString *
const key = [NSString stringWithCString : propName encoding : NSASCIIStringEncoding];
3185 QuartzWindowProperty *
const property = (QuartzWindowProperty *)[
fX11Properties valueForKey : key];
3187 return property != nil;
3191 - (
unsigned char *) getProperty : (const
char *) propName returnType : (
Atom_t *) type
3192 returnFormat : (
unsigned *) format nElements : (
unsigned *) nElements
3194 assert(propName != 0 &&
3195 "-getProperty:returnType:returnFormat:nElements:, parameter 'propName' is null");
3197 "-getProperty:returnType:returnFormat:nElements:, parameter 'type' is null");
3198 assert(format != 0 &&
3199 "-getProperty:returnType:returnFormat:nElements:, parameter 'format' is null");
3200 assert(nElements != 0 &&
3201 "-getProperty:returnType:returnFormat:nElements:, parameter 'nElements' is null");
3203 NSString *
const key = [NSString stringWithCString : propName encoding : NSASCIIStringEncoding];
3204 QuartzWindowProperty *
const property = (QuartzWindowProperty *)[
fX11Properties valueForKey : key];
3205 assert(property != 0 &&
3206 "-getProperty:returnType:returnFormat:nElements, property not found");
3208 NSData *
const propData =
property.fPropertyData;
3210 const NSUInteger dataSize = [propData length];
3211 unsigned char *buff = 0;
3213 buff =
new unsigned char[dataSize]();
3214 }
catch (
const std::bad_alloc &) {
3216 NSLog(
@"QuartzWindow: -getProperty:returnType:returnFormat:nElements:," 3217 " memory allocation failed");
3221 [propData getBytes : buff length : dataSize];
3222 *format =
property.fFormat;
3224 *nElements = dataSize;
3227 *nElements= dataSize / 2;
3228 else if (*format == 32)
3229 *nElements = dataSize / 4;
3231 *
type =
property.fType;
3237 - (
void) removeProperty : (const
char *) propName
3239 assert(propName != 0 &&
"-removeProperty:, parameter 'propName' is null");
3241 NSString *
const key = [NSString stringWithCString : propName
3242 encoding : NSASCIIStringEncoding];
3248 - (NSDragOperation) draggingEntered : (
id<NSDraggingInfo>) sender
3250 NSPasteboard *
const pasteBoard = [sender draggingPasteboard];
3251 const NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
3253 if ([[pasteBoard types] containsObject : NSFilenamesPboardType] && (sourceDragMask & NSDragOperationCopy))
3254 return NSDragOperationCopy;
3256 return NSDragOperationNone;
3260 - (BOOL) performDragOperation : (
id<NSDraggingInfo>) sender
3271 NSPasteboard *
const pasteBoard = [sender draggingPasteboard];
3272 const NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
3274 if ([[pasteBoard types] containsObject : NSFilenamesPboardType] && (sourceDragMask & NSDragOperationCopy)) {
3280 NSArray *
const files = [pasteBoard propertyListForType : NSFilenamesPboardType];
3281 for (NSString *path in files) {
3283 NSString *
const item = [@"file://" stringByAppendingString : path];
3285 const NSUInteger len = [item lengthOfBytesUsingEncoding : NSASCIIStringEncoding] + 1;
3287 std::vector<unsigned char> propertyData(len);
3288 [item getCString : (char *)&propertyData[0] maxLength : propertyData.size()
3289 encoding : NSASCIIStringEncoding];
3291 NSView<X11Window> *
const targetView =
self.fQuartzWindow.fContentView;
3292 [targetView setProperty : "_XC_DND_DATA" data : &propertyData[0]
3293 size : propertyData.size() forType : textUriAtom format : 8];
3294 }
catch (
const std::bad_alloc &) {
3296 NSLog(
@"QuartzView: -performDragOperation:, memory allocation failed");
3312 event1.
fUser[2] = textUriAtom;
3322 event2.
fUser[2] = 0;
3323 NSPoint dropPoint = [sender draggingLocation];
3326 dropPoint = [
self convertPoint : dropPoint fromView : nil];
std::vector< unsigned char > DownscaledImageData(unsigned w, unsigned h, CGImageRef image)
int GlobalXCocoaToROOT(CGFloat xCocoa)
void GenerateConfigureNotifyEvent(NSView< X11Window > *view, const NSRect &newFrame)
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 > * FindViewForPointerEvent(NSEvent *pointerEvent)
void GetRootWindowAttributes(WindowAttributes_t *attr)
unsigned long fBackgroundPixel
void GeneratePointerMotionEvent(NSEvent *theEvent)
void configureNotifyTree()
unsigned fPassiveGrabEventMask
bool LockFocus(NSView< X11Window > *view)
ROOT::MacOSX::Util::CFScopeGuard< CGImageRef > fImage
Namespace for new ROOT classes and functions.
void GetWindowAttributes(NSObject< X11Window > *window, WindowAttributes_t *dst)
QuartzWindow * fQuartzWindow
QuartzWindow * FindWindowInPoint(Int_t x, Int_t y)
void GenerateKeyReleaseEvent(NSView< X11Window > *eventView, NSEvent *theEvent)
static const TString & GetIconPath()
Get the icon path in the installation. Static utility function.
const Mask_t kButtonMotionMask
NSView< X11Window > * FindDNDAwareViewInPoint(NSView *parentView, Window_t dragWinID, Window_t inputWinID, Int_t x, Int_t y, Int_t maxDepth)
bool AdjustCropArea(const Rectangle &srcRect, Rectangle &cropArea)
const Mask_t kLeaveWindowMask
const Mask_t kWABackPixmap
const Mask_t kWABorderPixel
const Mask_t kWABitGravity
int LocalYCocoaToROOT(NSView< X11Window > *parentView, CGFloat yCocoa)
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
QuartzImage * fShapeCombineMask
const Mask_t kWABackingStore
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
NSView< X11Window > * fContentView
unsigned char * readColorBits:(ROOT::MacOSX::X11::Rectangle area)
QuartzPixmap * fBackBuffer
NSCursor * CreateCustomCursor(ECursor currentCursor)
const NSUInteger kTitledWindowMask
const NSUInteger kResizableWindowMask
int GlobalYROOTToCocoa(CGFloat yROOT)
void GenerateButtonPressEvent(NSView< X11Window > *eventView, NSEvent *theEvent, EMouseButton btn)
const Mask_t kWABorderPixmap
const Mask_t kPointerMotionMask
void addChild:(NSView< X11Window > *child)
void SetWindowAttributes(const SetWindowAttributes_t *attr, NSObject< X11Window > *window)
NSMutableDictionary * fX11Properties
NSPoint GetCursorHotStop(NSImage *image, ECursor cursor)
NSPoint TranslateCoordinates(NSView< X11Window > *fromView, NSView< X11Window > *toView, NSPoint sourcePoint)
QuartzImage * fBackgroundPixmap
NSPoint ConvertPointFromBaseToScreen(NSWindow *window, NSPoint windowPoint)
QuartzWindow * FindWindowForPointerEvent(NSEvent *pointerEvent)
ROOT::MacOSX::X11::PointerGrab fCurrentGrabType
QuartzWindow * fQuartzWindow
CGImageRef CreateSubImage(QuartzImage *image, const Rectangle &area)
ROOT::MacOSX::X11::Rectangle GetDisplayGeometry() const
NSPoint TranslateFromScreen(NSPoint point, NSView< X11Window > *to)
NSPoint ConvertPointFromScreenToBase(NSPoint screenPoint, NSWindow *window)
const NSUInteger kClosableWindowMask
const Mask_t kWABackingPlanes
const NSUInteger kMiniaturizableWindowMask
int GlobalXROOTToCocoa(CGFloat xROOT)
const Mask_t kButtonPressMask
NSView< X11Window > * FindViewUnderPointer()
NSPoint TranslateToScreen(NSView< X11Window > *from, NSPoint point)
NSView< X11Window > * FrameForTextView(NSView< X11Window > *textView)
const NSEventType kLeftMouseDown
int GlobalYCocoaToROOT(CGFloat yCocoa)
bool ViewIsHtmlViewFrame(NSView< X11Window > *view, bool checkParent)
void activatePassiveGrab()
void GenerateExposeEvent(NSView< X11Window > *view, const NSRect &exposedRect)
void setOverlapped:(BOOL overlap)
const Mask_t kWAEventMask
R__EXTERN TSystem * gSystem
const Mask_t kWASaveUnder
static Atom_t fgDeleteWindowAtom
QuartzWindow * FindWindowUnderPointer()
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
const Mask_t kExposureMask
bool HasPointerGrab() const
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)
void UnlockFocus(NSView< X11Window > *view)
void PixelToRGB(Pixel_t pixelColor, CGFloat *rgb)
void RemoveGraphicsOperationsForWindow(Window_t wid)
int LocalYROOTToCocoa(NSView< X11Window > *parentView, CGFloat yROOT)
bool ViewIsTextView(unsigned viewID)
const Mask_t kEnterWindowMask
BOOL fPassiveGrabOwnerEvents
QuartzWindow * fMainWindow
const Mask_t kStructureNotifyMask
bool ViewIsHtmlView(unsigned viewID)
NSView< X11Window > * FrameForHtmlView(NSView< X11Window > *htmlView)
bool ScreenPointIsInView(NSView< X11Window > *view, Int_t x, Int_t y)
const Mask_t kButtonReleaseMask
const NSEventType kRightMouseDown
const Mask_t kWAOverrideRedirect
void GenerateCrossingEvent(NSEvent *theEvent)
const Mask_t kWAWinGravity
void WindowLostFocus(Window_t winID)
void ClipToShapeMask(NSView< X11Window > *view, CGContextRef ctx)
const NSUInteger kBorderlessWindowMask
NSCursor * CreateCursor(ECursor currentCursor)
unsigned long fBackgroundPixel
unsigned fPassiveGrabKeyModifiers
ROOT::MacOSX::X11::CommandBuffer * GetCommandBuffer() const
typedef void((*Func_t)())
This class implements TVirtualX interface for MacOS X, using Cocoa and Quartz 2D. ...
NSComparisonResult CompareViewsToLower(id view1, id view2, void *context)
QuartzView * fContentView
const Mask_t kWABorderWidth
void GenerateKeyPressEvent(NSView< X11Window > *eventView, NSEvent *theEvent)
NSComparisonResult CompareViewsToRaise(id view1, id view2, void *context)
BOOL fActiveGrabOwnerEvents
const Mask_t kWABackPixel
const Mask_t kWABackingPixel
const Mask_t kWADontPropagate
bool ViewIsTextViewFrame(NSView< X11Window > *view, bool checkParent)
unsigned fActiveGrabEventMask
ROOT::MacOSX::X11::EventTranslator * GetEventTranslator() const
void GenerateFocusChangeEvent(NSView< X11Window > *eventView)
void GetWindowGeometry(NSObject< X11Window > *win, WindowAttributes_t *dst)
NSMutableArray * fPassiveKeyGrabs
void activateImplicitGrab()
void GenerateButtonReleaseEvent(NSView< X11Window > *eventView, NSEvent *theEvent, EMouseButton btn)