16 #ifdef DEBUG_ROOT_COCOA
28 #include <Availability.h>
36 #include "RConfigure.h"
49 #pragma mark - Create a window or a view.
55 using namespace Details;
60 winRect.size.width = w;
61 winRect.size.height =
h;
68 backing : NSBackingStoreBuffered
70 windowAttributes : attr];
72 throw std::runtime_error(
"CreateTopLevelWindow failed");
74 newWindow.fDepth = depth;
75 newWindow.fClass = clss;
85 viewRect.origin.x =
x;
86 viewRect.origin.y =
y;
87 viewRect.size.width = w;
88 viewRect.size.height =
h;
92 throw std::runtime_error(
"CreateChildView failed");
97 #pragma mark - root window (does not really exist, it's our desktop built of all screens).
103 assert(attr != 0 &&
"GetRootWindowAttributes, parameter 'attr' is null");
106 NSArray *
const screens = [NSScreen screens];
107 assert(screens != nil &&
"screens array is nil");
108 NSScreen *
const mainScreen = [screens objectAtIndex : 0];
109 assert(mainScreen != nil &&
"screen with index 0 is nil");
113 assert(dynamic_cast<TGCocoa *>(
gVirtualX) &&
114 "GetRootWindowAttributes, gVirtualX is either null or has a wrong type");
128 attr->
fDepth = NSBitsPerPixelFromDepth([mainScreen depth]);
134 #pragma mark - Coordinate conversions.
139 assert(window != nil &&
"ConvertPointFromBaseToScreen, parameter 'window' is nil");
145 tmpRect.origin = windowPoint;
146 tmpRect.size = NSMakeSize(1., 1.);
147 tmpRect = [window convertRectToScreen : tmpRect];
149 return tmpRect.origin;
155 assert(window != nil &&
"ConvertPointFromScreenToBase, parameter 'window' is nil");
161 tmpRect.origin = screenPoint;
162 tmpRect.size = NSMakeSize(1., 1.);
163 tmpRect = [window convertRectFromScreen : tmpRect];
165 return tmpRect.origin;
175 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
176 "GlobalYCocoaToROOT, gVirtualX is either nul or has a wrong type");
180 return int(frame.
fHeight - (yCocoa - frame.
fY));
186 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
187 "GlobalXCocoaToROOT, gVirtualX is either nul or has a wrong type");
190 return int(xCocoa - frame.
fX);
196 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
197 "GlobalYROOTToCocoa, gVirtualX is either nul or has a wrong type");
200 return int(frame.
fY + (frame.
fHeight - yROOT));
206 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
207 "GlobalXROOTToCocoa, gVirtualX is either nul or has a wrong type");
210 return int(frame.
fX + xROOT);
216 assert(parentView != nil &&
"LocalYCocoaToROOT, parent view is nil");
218 return int(parentView.frame.size.height - yCocoa);
225 assert(parentView != nil &&
"LocalYROOTToCocoa, parent view is nil");
227 return int(parentView.frame.size.height - yROOT);
235 assert(drawable != nil &&
"LocalYROOTToCocoa, drawable is nil");
237 return int(drawable.fHeight - yROOT);
243 assert(from != nil &&
"TranslateToScreen, parameter 'from' is nil");
245 const NSPoint winPoint = [from convertPoint : point toView : nil];
257 assert(to != nil &&
"TranslateFromScreen, parameter 'to' is nil");
263 return [to convertPoint : point fromView : nil];
270 assert(from != nil &&
"TranslateCoordinates, parameter 'from' is nil");
271 assert(to != nil &&
"TranslateCoordinates, parameter 'to' is nil");
273 if ([from window] == [to window]) {
275 return [to convertPoint : sourcePoint fromView : from];
283 const NSPoint win1Point = [from convertPoint : sourcePoint toView : nil];
287 return [to convertPoint : win2Point fromView : nil];
294 assert(view != nil &&
"ScreenPointIsInView, parameter 'view' is nil");
297 point.x =
x, point.y =
y;
299 const NSRect viewFrame = view.frame;
301 if (point.x < 0 || point.x > viewFrame.size.width)
303 if (point.y < 0 || point.y > viewFrame.size.height)
309 #pragma mark - Different FindView/Window functions iterating on the ROOT's windows/views.
317 NSArray *
const orderedWindows = [NSApp orderedWindows];
318 for (NSWindow *window in orderedWindows) {
321 QuartzWindow *
const qw = (QuartzWindow *)window;
336 assert(children != nil &&
"FindDNDAwareViewInPoint, parameter 'children' is nil");
341 NSEnumerator *
const reverseEnumerator = [children reverseObjectEnumerator];
342 for (NSView<X11Window> *child in reverseEnumerator) {
345 if (child.fIsDNDAware && child.fID != dragWinID && child.fID != inputWinID)
349 inputWinID, x, y, maxDepth - 1);
368 NSArray *
const orderedWindows = [NSApp orderedWindows];
369 for (NSWindow *window in orderedWindows) {
372 QuartzWindow *
const qw = (QuartzWindow *)window;
385 if (testView.fIsDNDAware && testView.fID != dragWinID && testView.fID != inputWinID)
389 NSArray *
const children = [testView subviews];
408 NSArray *
const orderedWindows = [NSApp orderedWindows];
409 for (NSWindow *nsWindow in orderedWindows) {
413 QuartzWindow *
const qWindow = (QuartzWindow *)nsWindow;
421 const NSPoint mousePosition = [qWindow mouseLocationOutsideOfEventStream];
422 const NSSize windowSize = qWindow.frame.size;
423 if (mousePosition.x >= 0 && mousePosition.x <= windowSize.width &&
424 mousePosition.y >= 0 && mousePosition.y <= windowSize.height)
438 const NSPoint mousePosition = [topLevel mouseLocationOutsideOfEventStream];
439 return (NSView<X11Window> *)[[topLevel contentView] hitTest : mousePosition];
452 assert(pointerEvent != nil &&
453 "FindWindowForPointerEvent, parameter 'pointerEvent' is nil");
457 NSArray *
const orderedWindows = [NSApp orderedWindows];
458 for (NSWindow *nsWindow in orderedWindows) {
462 QuartzWindow *
const qWindow = (QuartzWindow *)nsWindow;
471 NSPoint mousePosition = [pointerEvent locationInWindow];
474 if ([pointerEvent window]) {
484 const NSSize windowSize = qWindow.frame.size;
485 if (mousePosition.x >= 0 && mousePosition.x <= windowSize.width &&
486 mousePosition.y >= 0 && mousePosition.y <= windowSize.height)
499 assert(pointerEvent != nil &&
500 "FindViewForPointerEvent, parameter 'pointerEvent' is nil");
505 NSPoint mousePosition = [pointerEvent locationInWindow];
506 if ([pointerEvent window])
513 return (NSView<X11Window> *)[[topLevel contentView] hitTest : mousePosition];
519 #pragma mark - Downscale image ("reading color bits" on retina macs).
524 assert(w != 0 && h != 0 &&
"DownscaledImageData, invalid geometry");
525 assert(image !=
nullptr &&
"DonwscaledImageData, invalid parameter 'image'");
527 std::vector<unsigned char>
result;
529 result.resize(w * h * 4);
530 }
catch (
const std::bad_alloc &) {
532 NSLog(
@"DownscaledImageData, memory allocation failed");
538 if (!colorSpace.
Get()) {
539 NSLog(
@"DownscaledImageData, CGColorSpaceCreateDeviceRGB failed");
544 w * 4, colorSpace.
Get(),
545 kCGImageAlphaPremultipliedLast,
NULL, 0));
547 NSLog(
@"DownscaledImageData, CGBitmapContextCreateWithData failed");
551 CGContextDrawImage(ctx.
Get(), CGRectMake(0, 0, w, h), image);
556 #pragma mark - "Focus management" - just make another window key window.
562 if (![NSApp isActive])
567 NSArray *
const orderedWindows = [NSApp orderedWindows];
568 for (NSWindow *nsWindow in orderedWindows) {
572 QuartzWindow *
const qWindow = (QuartzWindow *)nsWindow;
580 [qWindow makeKeyAndOrderFront : qWindow];
585 #pragma mark - 'shape mask' - to create a window with arbitrary (probably non-rectangle) shape.
590 assert(view != nil &&
"ClipToShapeMask, parameter 'view' is nil");
591 assert(ctx != 0 &&
"ClipToShapeMask, parameter 'ctx' is null");
595 "ClipToShapeMask, fShapeCombineMask is nil on a top-level window");
597 "ClipToShapeMask, shape mask is null");
603 if (!view.fParentView) {
609 NSRect clipRect = view.frame;
611 clipRect.origin = [view.fParentView convertPoint : clipRect.origin
612 toView : [view window].contentView];
614 clipRect.origin.y + clipRect.size.height);
619 NSRectToCGRect(clipRect)));
620 clipRect.origin = NSPoint();
621 CGContextClipToMask(ctx, NSRectToCGRect(clipRect), clipImageGuard.
Get());
625 CGContextClipToRect(ctx, rect);
630 #pragma mark - Window's geometry and attributes.
635 assert(attr != 0 &&
"SetWindowAttributes, parameter 'attr' is null");
636 assert(window != nil &&
"SetWindowAttributes, parameter 'window' is nil");
657 if ([(NSObject *)window isKindOfClass : [
QuartzWindow class]]) {
658 QuartzWindow *
const qw = (QuartzWindow *)window;
659 [qw setStyleMask : Details::kBorderlessWindowMask];
660 [qw setAlphaValue : 0.95];
663 window.fOverrideRedirect = YES;
670 assert(win != nil &&
"GetWindowGeometry, parameter 'win' is nil");
671 assert(dst != 0 &&
"GetWindowGeometry, parameter 'dst' is null");
683 assert(window != nil &&
"GetWindowAttributes, parameter 'window' is nil");
684 assert(dst != 0 &&
"GetWindowAttributes, parameter 'attr' is null");
693 dst->
fDepth = window.fDepth;
698 dst->
fClass = window.fClass;
732 #pragma mark - Comparators (I need them when changing a window's z-order).
736 #ifdef MAC_OS_X_VERSION_10_11
737 NSComparisonResult
CompareViewsToLower(__kindof NSView *view1, __kindof NSView *view2,
void *context)
742 id topView = (
id)context;
743 if (view1 == topView)
744 return NSOrderedAscending;
745 if (view2 == topView)
746 return NSOrderedDescending;
748 return NSOrderedSame;
753 #ifdef MAC_OS_X_VERSION_10_11
754 NSComparisonResult
CompareViewsToRaise(__kindof NSView *view1, __kindof NSView *view2,
void *context)
759 id topView = (
id)context;
760 if (view1 == topView)
761 return NSOrderedDescending;
762 if (view2 == topView)
763 return NSOrderedAscending;
765 return NSOrderedSame;
768 #pragma mark - Cursor's area.
773 assert(image != nil &&
"CursroHotSpot, parameter 'image' is nil");
775 const NSSize imageSize = image.size;
778 return NSMakePoint(imageSize.width, imageSize.height / 2);
780 return NSMakePoint(imageSize.width / 2, imageSize.height / 2);
787 const char *pngFileName = 0;
789 switch (currentCursor) {
791 pngFileName =
"move_cursor.png";
794 pngFileName =
"hor_arrow_cursor.png";
797 pngFileName =
"ver_arrow_cursor.png";
800 pngFileName =
"right_arrow_cursor.png";
803 pngFileName =
"rotate.png";
807 pngFileName =
"top_right_cursor.png";
811 pngFileName =
"top_left_cursor.png";
820 if (!path || path[0] == 0) {
825 NSString *nsPath = [NSString stringWithFormat : @"%s", path];
826 NSImage *
const cursorImage = [[NSImage alloc] initWithContentsOfFile : nsPath];
832 NSCursor *
const customCursor = [[[NSCursor alloc] initWithImage : cursorImage
833 hotSpot : hotSpot] autorelease];
835 [cursorImage release];
855 NSCursor *cursor = nil;
856 switch (currentCursor) {
858 cursor = [NSCursor crosshairCursor];
861 cursor = [NSCursor arrowCursor];
864 cursor = [NSCursor openHandCursor];
867 cursor = [NSCursor resizeLeftCursor];
870 cursor = [NSCursor resizeRightCursor];
873 cursor = [NSCursor resizeUpCursor];
876 cursor = [NSCursor resizeDownCursor];
879 cursor = [NSCursor IBeamCursor];
901 #pragma mark - Workarounds for a text view and its descendants.
915 assert(view != nil &&
"ViewIsTextView, parameter 'view' is nil");
923 assert(view != nil &&
"ViewIsTextViewFrame, parameter 'view' is nil");
935 if (!view.fParentView)
953 assert(view != nil &&
"ViewIsHtmlView, parameter 'view' is nil");
962 assert(view != nil &&
"ViewIsHtmlViewFrame, parameter 'view' is nil");
974 if (!view.fParentView)
983 assert(textView != nil &&
"FrameForTextView, parameter 'textView' is nil");
985 for (NSView<X11Window> *child in [textView subviews]) {
996 assert(htmlView != nil &&
"FrameForHtmlView, parameter 'htmlView' is nil");
998 for (NSView<X11Window> *child in [htmlView subviews]) {
1006 #pragma mark - Workarounds for 'paint out of paint events'.
1011 assert(view != nil &&
"LockFocus, parameter 'view' is nil");
1012 assert([view isKindOfClass : [
QuartzView class]] &&
1013 "LockFocus, QuartzView is expected");
1015 if ([view lockFocusIfCanDraw]) {
1016 NSGraphicsContext *nsContext = [NSGraphicsContext currentContext];
1017 assert(nsContext != nil &&
"LockFocus, currentContext is nil");
1018 CGContextRef currContext = (CGContextRef)[nsContext graphicsPort];
1019 assert(currContext != 0 &&
"LockFocus, graphicsPort is null");
1032 assert(view != nil &&
"UnlockFocus, parameter 'view' is nil");
1033 assert([view isKindOfClass : [
QuartzView class]] &&
1034 "UnlockFocus, QuartzView is expected");
1044 namespace Quartz = ROOT::Quartz;
1045 namespace Util = ROOT::MacOSX::Util;
1046 namespace X11 = ROOT::MacOSX::X11;
1047 namespace Details = ROOT::MacOSX::Details;
1049 #ifdef DEBUG_ROOT_COCOA
1051 #pragma mark - 'loggers'.
1061 static std::ofstream logfile(
"win_attr.txt");
1065 logfile<<
"win "<<winID<<
": BackPixmap\n";
1067 logfile<<
"win "<<winID<<
": BackPixel\n";
1069 logfile<<
"win "<<winID<<
": BorderPixmap\n";
1071 logfile<<
"win "<<winID<<
": BorderPixel\n";
1073 logfile<<
"win "<<winID<<
": BorderWidth\n";
1075 logfile<<
"win "<<winID<<
": BitGravity\n";
1077 logfile<<
"win "<<winID<<
": WinGravity\n";
1079 logfile<<
"win "<<winID<<
": BackingStore\n";
1081 logfile<<
"win "<<winID<<
": BackingPlanes\n";
1083 logfile<<
"win "<<winID<<
": BackingPixel\n";
1085 logfile<<
"win "<<winID<<
": OverrideRedirect\n";
1087 logfile<<
"win "<<winID<<
": SaveUnder\n";
1089 logfile<<
"win "<<winID<<
": EventMask\n";
1091 logfile<<
"win "<<winID<<
": DontPropagate\n";
1093 logfile<<
"win "<<winID<<
": Colormap\n";
1095 logfile<<
"win "<<winID<<
": Cursor\n";
1099 void print_mask_info(
ULong_t mask)
1102 NSLog(
@"button press mask");
1104 NSLog(
@"button release mask");
1106 NSLog(
@"exposure mask");
1108 NSLog(
@"pointer motion mask");
1110 NSLog(
@"button motion mask");
1112 NSLog(
@"enter notify mask");
1114 NSLog(
@"leave notify mask");
1126 #pragma mark - QuartzWindow's life cycle.
1129 - (
id) initWithContentRect : (NSRect) contentRect styleMask : (NSUInteger) windowStyle
1130 backing : (NSBackingStoreType) bufferingType defer : (BOOL) deferCreation
1133 self = [
super initWithContentRect : contentRect styleMask : windowStyle
1134 backing : bufferingType defer : deferCreation];
1138 [
self setAllowsConcurrentViewDrawing : NO];
1140 self.delegate =
self;
1142 NSRect contentViewRect = contentRect;
1143 contentViewRect.origin.x = 0.f;
1144 contentViewRect.origin.y = 0.f;
1150 [
self setContentView : fContentView];
1168 using namespace Details;
1170 assert(glView != nil &&
"-initWithGLView, parameter 'glView' is nil");
1175 NSRect contentRect = glView.frame;
1176 contentRect.origin = NSPoint();
1178 self = [
super initWithContentRect : contentRect styleMask : styleMask
1179 backing : NSBackingStoreBuffered defer : NO];
1183 [
self setAllowsConcurrentViewDrawing : NO];
1184 self.delegate =
self;
1186 [
self setContentView : fContentView];
1209 - (
void) setContentView:(NSView *)cv
1211 [
super setContentView:cv];
1219 - (
void) setFIsDeleted : (BOOL) deleted
1224 #pragma mark - Forwaring: I want to forward a lot of property setters/getters to the content view.
1227 - (
void) forwardInvocation : (NSInvocation *) anInvocation
1232 if ([
fContentView respondsToSelector : [anInvocation selector]]) {
1233 [anInvocation invokeWithTarget : fContentView];
1235 [
super forwardInvocation : anInvocation];
1240 - (NSMethodSignature*) methodSignatureForSelector : (
SEL) selector
1242 NSMethodSignature *signature = [
super methodSignatureForSelector : selector];
1246 signature = [
fContentView methodSignatureForSelector : selector];
1261 assert(window != nil &&
"-addTransientWindow:, parameter 'window' is nil");
1270 [
self addChildWindow : window ordered : NSWindowAbove];
1276 - (
void) makeKeyAndOrderFront : (
id) sender
1278 #pragma unused(sender)
1283 #ifdef MAC_OS_X_VERSION_10_9
1284 [
self setCollectionBehavior : NSWindowCollectionBehaviorMoveToActiveSpace];
1286 [
self setCollectionBehavior : NSWindowCollectionBehaviorCanJoinAllSpaces];
1289 [
super makeKeyAndOrderFront : self];
1291 [
self setCollectionBehavior : NSWindowCollectionBehaviorDefault];
1295 - (
void) setFDelayedTransient : (BOOL) d
1310 [fShapeCombineMask release];
1319 #pragma mark - X11Drawable's protocol.
1350 return self.frame.size.width;
1359 assert(
fContentView != nil &&
"-fHeight:, content view is nil");
1365 - (
void) setDrawableSize : (NSSize) newSize
1368 assert(!(newSize.width < 0) &&
"-setDrawableSize:, width is negative");
1369 assert(!(newSize.height < 0) &&
"-setDrawableSize:, height is negative");
1371 NSRect frame =
self.frame;
1375 frame.origin.y = frame.origin.y + frame.size.height - newSize.height - dY;
1376 frame.size = newSize;
1377 frame.size.height += dY;
1378 [
self setFrame : frame display : YES];
1382 - (
void) setX : (
int) x Y : (
int) y width : (
unsigned) w height : (
unsigned) h
1384 NSSize newSize = {};
1387 [
self setContentSize : newSize];
1390 NSPoint topLeft = {};
1394 [
self setFrameTopLeftPoint : topLeft];
1398 - (
void) setX : (
int) x Y : (
int) y
1400 NSPoint topLeft = {};
1404 [
self setFrameTopLeftPoint : topLeft];
1409 clipOrigin : (X11::Point) clipXY toPoint : (X11::Point) dstPoint
1414 [
fContentView copy : src area : area withMask : mask clipOrigin : clipXY toPoint : dstPoint];
1418 - (
unsigned char *) readColorBits : (X11::Rectangle) area
1426 #pragma mark - X11Window protocol's implementation.
1437 #pragma unused(parent)
1455 - (
void) setFBackgroundPixel : (
unsigned long) backgroundColor
1461 CGFloat rgba[] = {0., 0., 0., 1.};
1464 [
self setBackgroundColor : [NSColor colorWithColorSpace : [NSColorSpace deviceRGBColorSpace] components : rgba count : 4]];
1495 assert(child != nil &&
"-addChild:, parameter 'child' is nil");
1499 assert([child isKindOfClass : [
QuartzView class]] &&
1500 "-addChild: gl view in a top-level window as content view is not supported");
1503 [
self setContentView : child];
1515 assert(attr &&
"-getAttributes:, parameter 'attr' is nil");
1523 assert(attr != 0 &&
"-setAttributes:, parameter 'attr' is null");
1525 #ifdef DEBUG_ROOT_COCOA
1526 log_attributes(attr,
self.
fID);
1538 const Util::AutoreleasePool pool;
1541 [
self makeKeyAndOrderFront : self];
1546 [
fMainWindow addChildWindow : self ordered : NSWindowAbove];
1556 const Util::AutoreleasePool pool;
1559 [
self makeKeyAndOrderFront : self];
1564 [
fMainWindow addChildWindow : self ordered : NSWindowAbove];
1574 const Util::AutoreleasePool pool;
1587 [
self orderOut : self];
1595 #pragma mark - Events.
1598 - (
void) sendEvent : (NSEvent *) theEvent
1608 bool generateFakeRelease =
false;
1610 const NSPoint windowPoint = [theEvent locationInWindow];
1612 if (windowPoint.x <= 4 || windowPoint.x >=
self.fWidth - 4)
1613 generateFakeRelease =
true;
1615 if (windowPoint.y <= 4 || windowPoint.y >=
self.fHeight - 4)
1616 generateFakeRelease =
true;
1618 const NSPoint viewPoint = [fContentView convertPoint : windowPoint fromView : nil];
1620 if (viewPoint.y <= 0 && windowPoint.y >= 0)
1621 generateFakeRelease =
true;
1623 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
1624 "-sendEvent:, gVirtualX is either null or not of TGCocoa type");
1638 [
super sendEvent : theEvent];
1641 #pragma mark - NSWindowDelegate's methods.
1644 - (BOOL) windowShouldClose : (
id) sender
1646 #pragma unused(sender)
1655 if ([[
self childWindows] count])
1666 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
1667 "-windowShouldClose:, gVirtualX is either null or has a type different from TGCocoa");
1676 - (
void) windowDidBecomeKey : (NSNotification *) aNotification
1678 #pragma unused(aNotification)
1686 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
1687 "-windowDidBecomeKey:, gVirtualX is null or not of TGCocoa type");
1695 - (
void) windowDidResignKey : (NSNotification *) aNotification
1697 #pragma unused(aNotification)
1703 #pragma mark - Passive key grab info.
1708 - (
id) initWithKey : (unichar) keyCode modifiers : (NSUInteger) modifiers
1710 if (
self = [super
init]) {
1719 - (BOOL) matchKey : (unichar) keyCode modifiers : (NSUInteger) modifiers
1725 - (BOOL) matchKey : (unichar) keyCode
1744 #pragma mark - X11 property emulation.
1746 @interface QuartzWindowProperty : NSObject {
1747 NSData *fPropertyData;
1756 @implementation QuartzWindowProperty
1761 - (
id) initWithData : (
unsigned char *) data size : (
unsigned) dataSize type : (
Atom_t) type format : (
unsigned) format
1763 if (
self = [super
init]) {
1765 fPropertyData = nil;
1769 [
self resetPropertyData : data size : dataSize type : type format : format];
1778 [fPropertyData release];
1784 - (
void) resetPropertyData : (
unsigned char *) data size : (
unsigned) dataSize
1785 type : (
Atom_t) type format : (
unsigned) format
1787 [fPropertyData release];
1792 else if (format == 32)
1795 fPropertyData = [[NSData dataWithBytes : data length : dataSize] retain];
1801 - (NSData *) fPropertyData
1803 return fPropertyData;
1807 - (unsigned) fFormat
1814 #pragma mark - QuartzView.
1847 #pragma mark - Lifetime.
1852 if (
self = [super initWithFrame : frame]) {
1864 [
self setCanDrawConcurrently : NO];
1866 [
self setHidden : YES];
1886 [fBackBuffer release];
1887 [fPassiveKeyGrabs release];
1888 [fX11Properties release];
1889 [fBackgroundPixmap release];
1893 #pragma mark - Tracking area.
1898 - (
void) updateTrackingAreas
1900 [
super updateTrackingAreas];
1905 const Util::AutoreleasePool pool;
1907 if (NSArray *trackingArray = [
self trackingAreas]) {
1908 const NSUInteger size = [trackingArray count];
1909 for (NSUInteger i = 0; i < size; ++i) {
1910 NSTrackingArea *
const t = [trackingArray objectAtIndex : i];
1911 [
self removeTrackingArea : t];
1915 const NSUInteger trackerOptions = NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited |
1916 NSTrackingActiveInActiveApp | NSTrackingInVisibleRect |
1917 NSTrackingEnabledDuringMouseDrag | NSTrackingCursorUpdate;
1920 frame.size.width =
self.fWidth;
1921 frame.size.height =
self.fHeight;
1923 NSTrackingArea *
const tracker = [[NSTrackingArea alloc] initWithRect : frame
1924 options : trackerOptions owner : self userInfo : nil];
1925 [
self addTrackingArea : tracker];
1930 - (
void) updateTrackingAreasAfterRaise
1932 [
self updateTrackingAreas];
1934 for (
QuartzView *childView in [
self subviews])
1935 [childView updateTrackingAreasAfterRaise];
1938 #pragma mark - X11Drawable protocol.
1955 return self.frame.origin.x;
1961 return self.frame.origin.y;
1967 return self.frame.size.width;
1973 return self.frame.size.height;
1977 - (
void) setDrawableSize : (NSSize) newSize
1979 assert(!(newSize.width < 0) &&
"-setDrawableSize, width is negative");
1980 assert(!(newSize.height < 0) &&
"-setDrawableSize, height is negative");
1986 NSRect frame =
self.frame;
1987 frame.size = newSize;
1993 - (
void) setX : (
int) x Y : (
int) y width : (
unsigned) w height : (
unsigned) h
1995 NSRect newFrame = {};
1996 newFrame.origin.x =
x;
1997 newFrame.origin.y =
y;
1998 newFrame.size.width = w;
1999 newFrame.size.height =
h;
2001 self.frame = newFrame;
2005 - (
void) setX : (
int) x Y : (
int) y
2007 NSRect newFrame =
self.frame;
2008 newFrame.origin.x =
x;
2009 newFrame.origin.y =
y;
2011 self.frame = newFrame;
2015 - (
void) copyImage : (
QuartzImage *) srcImage area : (X11::Rectangle) area
2016 withMask : (
QuartzImage *) mask clipOrigin : (X11::Point) clipXY
2017 toPoint : (X11::Point) dstPoint
2020 assert(srcImage != nil &&
2021 "-copyImage:area:withMask:clipOrigin:toPoint:, parameter 'srcImage' is nil");
2022 assert(srcImage.
fImage != nil &&
2023 "-copyImage:area:withMask:clipOrigin:toPoint:, srcImage.fImage is nil");
2027 "-copyImage:area:withMask:clipOrigin:toPoint:, self.fContext is null");
2030 NSLog(
@"QuartzView: -copyImage:area:withMask:clipOrigin:toPoint:,"
2031 " srcRect and copyRect do not intersect");
2037 CGImageRef subImage = 0;
2038 bool needSubImage =
false;
2039 if (area.fX || area.fY || area.fWidth != srcImage.
fWidth || area.fHeight != srcImage.
fHeight) {
2040 needSubImage =
true;
2043 NSLog(
@"QuartzView: -copyImage:area:withMask:clipOrigin:toPoint:,"
2044 " subimage creation failed");
2048 subImage = srcImage.
fImage;
2055 CGContextScaleCTM(
self.
fContext, 1., -1.);
2059 assert(mask.
fImage != nil &&
2060 "-copyImage:area:withMask:clipOrigin:toPoint:, mask.fImage is nil");
2061 assert(CGImageIsMask(mask.
fImage) ==
true &&
2062 "-copyImage:area:withMask:clipOrigin:toPoint:, mask.fImage is not a mask");
2066 const CGRect clipRect = CGRectMake(clipXY.fX, clipY, mask.
fWidth, mask.
fHeight);
2074 const CGRect imageRect = CGRectMake(dstPoint.fX, dstY, area.fWidth, area.fHeight);
2075 CGContextDrawImage(
self.
fContext, imageRect, subImage);
2078 CGImageRelease(subImage);
2082 - (
void) copyView : (
QuartzView *) srcView area : (X11::Rectangle) area toPoint : (X11::Point) dstPoint
2089 assert(srcView != nil &&
"-copyView:area:toPoint:, parameter 'srcView' is nil");
2091 const NSRect frame = [srcView frame];
2093 NSBitmapImageRep *
const imageRep = [srcView bitmapImageRepForCachingDisplayInRect : frame];
2095 NSLog(
@"QuartzView: -copyView:area:toPoint failed");
2099 assert(srcView != nil &&
"-copyView:area:toPoint:, parameter 'srcView' is nil");
2100 assert(
self.
fContext != 0 &&
"-copyView:area:toPoint, self.fContext is null");
2105 CGContextRef ctx = srcView.
fContext;
2107 [srcView cacheDisplayInRect : frame toBitmapImageRep : imageRep];
2111 const CGRect subImageRect = CGRectMake(area.fX, area.fY, area.fWidth, area.fHeight);
2112 const Util::CFScopeGuard<CGImageRef> subImage(CGImageCreateWithImageInRect(imageRep.CGImage, subImageRect));
2114 if (!subImage.Get()) {
2115 NSLog(
@"QuartzView: -copyView:area:toPoint, CGImageCreateWithImageInRect failed");
2120 const CGRect imageRect = CGRectMake(dstPoint.fX,
2121 [
self visibleRect].size.height - (CGFloat(dstPoint.fY) + area.fHeight),
2122 area.fWidth, area.fHeight);
2124 CGContextTranslateCTM(
self.
fContext, 0., [
self visibleRect].size.height);
2125 CGContextScaleCTM(
self.
fContext, 1., -1.);
2127 CGContextDrawImage(
self.
fContext, imageRect, subImage.Get());
2131 - (
void) copyPixmap : (
QuartzPixmap *) srcPixmap area : (X11::Rectangle) area
2132 withMask : (
QuartzImage *) mask clipOrigin : (X11::Point) clipXY toPoint : (X11::Point) dstPoint
2135 assert(srcPixmap != nil &&
"-copyPixmap:area:withMask:clipOrigin:toPoint:, parameter 'srcPixmap' is nil");
2138 NSLog(
@"QuartzView: -copyPixmap:area:withMask:clipOrigin:toPoint,"
2139 " no intersection between pixmap rectangle and cropArea");
2145 "-copyPixmap:area:withMask:clipOrigin:toPoint:, self.fContext is null");
2150 CGContextTranslateCTM(
self.
fContext, 0.,
self.frame.size.height);
2151 CGContextScaleCTM(
self.
fContext, 1., -1.);
2153 const Util::CFScopeGuard<CGImageRef> imageFromPixmap([srcPixmap createImageFromPixmap]);
2154 assert(imageFromPixmap.Get() != 0 &&
2155 "-copyPixmap:area:withMask:clipOrigin:toPoint:, createImageFromPixmap failed");
2157 CGImageRef subImage = 0;
2158 bool needSubImage =
false;
2159 if (area.fX || area.fY || area.fWidth != srcPixmap.
fWidth || area.fHeight != srcPixmap.
fHeight) {
2160 needSubImage =
true;
2161 const CGRect subImageRect = CGRectMake(area.fX, area.fY, area.fHeight, area.fWidth);
2162 subImage = CGImageCreateWithImageInRect(imageFromPixmap.Get(), subImageRect);
2164 NSLog(
@"QuartzView: -copyImage:area:withMask:clipOrigin:toPoint:,"
2165 " subimage creation failed");
2169 subImage = imageFromPixmap.Get();
2172 assert(mask.
fImage != nil &&
2173 "-copyPixmap:area:withMask:clipOrigin:toPoint:, mask.fImage is nil");
2174 assert(CGImageIsMask(mask.
fImage) ==
true &&
2175 "-copyPixmap:area:withMask:clipOrigin:toPoint:, mask.fImage is not a mask");
2180 const CGRect clipRect = CGRectMake(clipXY.fX, clipY, mask.
fWidth, mask.
fHeight);
2186 const CGRect imageRect = CGRectMake(dstPoint.fX, dstY, area.fWidth, area.fHeight);
2187 CGContextDrawImage(
self.
fContext, imageRect, imageFromPixmap.Get());
2190 CGImageRelease(subImage);
2195 - (
void) copyImage : (
QuartzImage *) srcImage area : (X11::Rectangle) area
2196 toPoint : (X11::Point) dstPoint
2198 assert(srcImage != nil &&
"-copyImage:area:toPoint:, parameter 'srcImage' is nil");
2199 assert(srcImage.
fImage != nil &&
"-copyImage:area:toPoint:, srcImage.fImage is nil");
2200 assert(
self.
fContext != 0 &&
"-copyImage:area:toPoint:, fContext is null");
2203 NSLog(
@"QuartzView: -copyImage:area:toPoint, image and copy area do not intersect");
2207 CGImageRef subImage = 0;
2208 bool needSubImage =
false;
2209 if (area.fX || area.fY || area.fWidth != srcImage.
fWidth || area.fHeight != srcImage.
fHeight) {
2210 needSubImage =
true;
2213 NSLog(
@"QuartzView: -copyImage:area:toPoint:, subimage creation failed");
2217 subImage = srcImage.
fImage;
2222 CGContextScaleCTM(
self.
fContext, 1., -1.);
2227 const CGRect imageRect = CGRectMake(dstPoint.fX, dstY, area.fWidth, area.fHeight);
2228 CGContextDrawImage(
self.
fContext, imageRect, subImage);
2231 CGImageRelease(subImage);
2236 withMask : (
QuartzImage *)mask clipOrigin : (X11::Point) clipXY toPoint : (X11::Point) dstPoint
2238 assert(src != nil &&
"-copy:area:withMask:clipOrigin:toPoint:, parameter 'src' is nil");
2239 assert(area.fWidth && area.fHeight &&
"-copy:area:withMask:clipOrigin:toPoint:, area to copy is empty");
2243 QuartzWindow *
const qw = (QuartzWindow *)src;
2245 [
self copyView : (QuartzView *)qw.fContentView area : area toPoint : dstPoint];
2246 }
else if ([src isKindOfClass : [
QuartzView class]]) {
2248 [
self copyView : (QuartzView *)src area : area toPoint : dstPoint];
2249 }
else if ([src isKindOfClass : [
QuartzPixmap class]]) {
2250 [
self copyPixmap : (QuartzPixmap *)src area : area withMask : mask clipOrigin : clipXY toPoint : dstPoint];
2251 }
else if ([src isKindOfClass : [
QuartzImage class]]) {
2252 [
self copyImage : (QuartzImage *)src area : area withMask : mask clipOrigin : clipXY toPoint : dstPoint];
2254 assert(0 &&
"-copy:area:withMask:clipOrigin:toPoint:, src is of unknown type");
2259 - (
unsigned char *) readColorBits : (X11::Rectangle) area
2265 assert(area.fWidth && area.fHeight &&
"-readColorBits:, area to copy is empty");
2268 const NSRect visRect = [
self visibleRect];
2269 const X11::Rectangle srcRect(
int(visRect.origin.x),
int(visRect.origin.y),
2270 unsigned(visRect.size.width),
unsigned(visRect.size.height));
2273 NSLog(
@"QuartzView: -readColorBits:, visible rect of view and copy area do not intersect");
2278 NSBitmapImageRep *
const imageRep = [
self bitmapImageRepForCachingDisplayInRect : visRect];
2280 NSLog(
@"QuartzView: -readColorBits:, bitmapImageRepForCachingDisplayInRect failed");
2284 CGContextRef ctx =
self.fContext;
2285 [
self cacheDisplayInRect : visRect toBitmapImageRep : imageRep];
2286 self.fContext = ctx;
2288 const NSInteger bitsPerPixel = [imageRep bitsPerPixel];
2290 assert(bitsPerPixel == 32 &&
"-readColorBits:, no alpha channel???");
2291 const NSInteger bytesPerRow = [imageRep bytesPerRow];
2292 unsigned dataWidth = bytesPerRow / (bitsPerPixel / 8);
2294 unsigned char *srcData =
nullptr;
2295 std::vector<unsigned char> downscaled;
2296 if ([[NSScreen mainScreen] backingScaleFactor] > 1 && imageRep.CGImage) {
2298 if (downscaled.size())
2299 srcData = &downscaled[0];
2300 dataWidth = area.fWidth;
2302 srcData = [imageRep bitmapData];
2305 NSLog(
@"QuartzView: -readColorBits:, failed to obtain backing store contents");
2310 unsigned char *
data =
nullptr;
2313 data =
new unsigned char[area.fWidth * area.fHeight * 4];
2314 }
catch (
const std::bad_alloc &) {
2315 NSLog(
@"QuartzView: -readColorBits:, memory allocation failed");
2319 unsigned char *dstPixel =
data;
2320 const unsigned char *
line = srcData + area.fY * dataWidth * 4;
2321 const unsigned char *srcPixel = line + area.fX * 4;
2323 for (
unsigned i = 0; i < area.fHeight; ++i) {
2324 for (
unsigned j = 0; j < area.fWidth; ++j, srcPixel += 4, dstPixel += 4) {
2325 dstPixel[0] = srcPixel[2];
2326 dstPixel[1] = srcPixel[1];
2327 dstPixel[2] = srcPixel[0];
2328 dstPixel[3] = srcPixel[3];
2331 line += dataWidth * 4;
2332 srcPixel = line + area.fX * 4;
2342 [fBackgroundPixmap release];
2361 if ([
self isHidden])
2365 if ([parent isHidden])
2383 - (
void) setFHasFocus : (BOOL) focus
2385 #pragma unused(focus)
2402 [fBackBuffer release];
2436 - (
void) activateGrab : (
unsigned) eventMask ownerEvents : (BOOL) ownerEvents
2452 - (BOOL) acceptsCrossingEvents : (
unsigned) eventMask
2473 assert(child != nil &&
"-addChild:, parameter 'child' is nil");
2475 [
self addSubview : child];
2482 assert(attr != 0 &&
"-getAttributes:, parameter 'attr' is null");
2490 assert(attr != 0 &&
"-setAttributes:, parameter 'attr' is null");
2492 #ifdef DEBUG_ROOT_COCOA
2493 log_attributes(attr,
fID);
2504 [
self removeFromSuperview];
2505 [parent addSubview : self];
2506 [
self setHidden : NO];
2512 [
self setHidden : NO];
2525 [
self setHidden : YES];
2535 - (
void) setOverlapped : (BOOL) overlap
2538 for (NSView<X11Window> *child in [
self subviews])
2539 [child setOverlapped : overlap];
2556 using namespace X11;
2559 if (
self == sibling)
2561 if ([sibling isHidden])
2564 if (NSEqualRects(sibling.frame,
self.frame)) {
2565 [sibling setOverlapped : YES];
2566 [sibling setHidden : YES];
2572 [
self setHidden : NO];
2574 [
fParentView sortSubviewsUsingFunction : CompareViewsToRaise context : (void *)self];
2576 [
self updateTrackingAreasAfterRaise];
2578 [
self setNeedsDisplay : YES];
2586 using namespace X11;
2588 NSEnumerator *
const reverseEnumerator = [[
fParentView subviews] reverseObjectEnumerator];
2589 for (
QuartzView *sibling in reverseEnumerator) {
2590 if (sibling ==
self)
2594 if (NSEqualRects(sibling.frame,
self.frame)) {
2595 [sibling setOverlapped : NO];
2597 [sibling setHidden : NO];
2599 [sibling setNeedsDisplay : YES];
2602 [
self setHidden : YES];
2608 [
fParentView sortSubviewsUsingFunction : CompareViewsToLower context : (void*)self];
2624 assert(dynamic_cast<TGCocoa *>(
gVirtualX) &&
2625 "-configureNotifyTree, gVirtualX is either null or has type different from TGCocoa");
2630 for (NSView<X11Window> *
v in [
self subviews])
2631 [v configureNotifyTree];
2635 #pragma mark - Key grabs.
2638 - (
void) addPassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers
2640 [
self removePassiveKeyGrab : keyCode modifiers : modifiers];
2642 modifiers : modifiers];
2648 - (
void) removePassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers
2651 for (NSUInteger i = 0; i < count; ++i) {
2653 if ([grab matchKey : keyCode modifiers : modifiers]) {
2661 - (
PassiveKeyGrab *) findPassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers
2665 if ([grab matchKey : keyCode modifiers : modifiers])
2678 if ([grab matchKey : keyCode])
2685 #pragma mark - Painting mechanics.
2688 - (
void) drawRect : (NSRect) dirtyRect
2690 #pragma unused(dirtyRect)
2692 using namespace X11;
2700 NSGraphicsContext *
const nsContext = [NSGraphicsContext currentContext];
2701 assert(nsContext != nil &&
"-drawRect:, currentContext returned nil");
2706 fContext = (CGContextRef)[nsContext graphicsPort];
2707 assert(
fContext != 0 &&
"-drawRect:, graphicsPort returned null");
2715 if (window->InheritsFrom(
"TGContainer"))
2738 gClient->CancelRedraw(window);
2746 [
self copy : fBackBuffer area : copyArea withMask : nil
2747 clipOrigin : X11::Point() toPoint : X11::Point()];
2751 #ifdef DEBUG_ROOT_COCOA
2752 CGContextSetRGBStrokeColor(
fContext, 1., 0., 0., 1.);
2753 CGContextStrokeRect(
fContext, dirtyRect);
2758 #ifdef DEBUG_ROOT_COCOA
2759 NSLog(
@"QuartzView: -drawRect: method, no window for id %u was found",
fID);
2765 #pragma mark - Geometry.
2768 - (
void) setFrame : (NSRect) newFrame
2773 if (NSEqualRects(newFrame,
self.frame))
2776 [
super setFrame : newFrame];
2780 - (
void) setFrameSize : (NSSize) newSize
2784 [
super setFrameSize : newSize];
2787 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2788 "setFrameSize:, gVirtualX is either null or has a type, different from TGCocoa");
2793 [
self setNeedsDisplay : YES];
2796 #pragma mark - Event handling.
2799 - (
void) mouseDown : (NSEvent *) theEvent
2801 assert(
fID != 0 &&
"-mouseDown:, fID is 0");
2803 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2804 "-mouseDown:, gVirtualX is either null or has a type, different from TGCocoa");
2810 - (
void) scrollWheel : (NSEvent*) theEvent
2812 assert(
fID != 0 &&
"-scrollWheel:, fID is 0");
2815 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2816 "-scrollWheel:, gVirtualX is either null or has a type, different from TGCocoa");
2819 const CGFloat deltaY = [theEvent deltaY];
2823 }
else if (deltaY > 0) {
2829 #ifdef DEBUG_ROOT_COCOA
2831 - (
void) printViewInformation
2833 assert(
fID != 0 &&
"-printWindowInformation, fID is 0");
2835 assert(window != 0 &&
"printWindowInformation, window not found");
2837 NSLog(
@"-----------------View %u info:---------------------",
fID);
2838 NSLog(
@"ROOT's window class is %s", window->IsA()->
GetName());
2839 NSLog(
@"event mask is:");
2841 NSLog(
@"grab mask is:");
2843 NSLog(
@"view's geometry: x == %g, y == %g, w == %g, h == %g",
self.frame.origin.x,
2844 self.frame.origin.y,
self.frame.size.width,
self.frame.size.height);
2845 NSLog(
@"----------------End of view info------------------");
2850 - (
void) rightMouseDown : (NSEvent *) theEvent
2852 assert(
fID != 0 &&
"-rightMouseDown:, fID is 0");
2854 #ifdef DEBUG_ROOT_COCOA
2855 [
self printViewInformation];
2858 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2859 "-rightMouseDown:, gVirtualX is either null or has type different from TGCocoa");
2865 - (
void) otherMouseDown : (NSEvent *) theEvent
2867 assert(
fID != 0 &&
"-otherMouseDown:, fID is 0");
2871 if ([theEvent buttonNumber] == 2) {
2874 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2875 "-otherMouseDown:, gVirtualX is either null or has type different from TGCocoa");
2882 - (
void) mouseUp : (NSEvent *) theEvent
2884 assert(
fID != 0 &&
"-mouseUp:, fID is 0");
2886 assert(dynamic_cast<TGCocoa *>(
gVirtualX) &&
2887 "-mouseUp:, gVirtualX is either null or has type different from TGCocoa");
2893 - (
void) rightMouseUp : (NSEvent *) theEvent
2896 assert(
fID != 0 &&
"-rightMouseUp:, fID is 0");
2898 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2899 "-rightMouseUp:, gVirtualX is either null or has type different from TGCocoa");
2906 - (
void) otherMouseUp : (NSEvent *) theEvent
2908 assert(
fID != 0 &&
"-otherMouseUp:, fID is 0");
2911 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2912 "-otherMouseUp:, gVirtualX is either null or has type different from TGCocoa");
2918 - (
void) mouseEntered : (NSEvent *) theEvent
2920 assert(
fID != 0 &&
"-mouseEntered:, fID is 0");
2921 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2922 "-mouseEntered:, gVirtualX is null or not of TGCocoa type");
2929 - (
void) mouseExited : (NSEvent *) theEvent
2931 assert(
fID != 0 &&
"-mouseExited:, fID is 0");
2933 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2934 "-mouseExited:, gVirtualX is null or not of TGCocoa type");
2941 - (
void) mouseMoved : (NSEvent *) theEvent
2943 assert(
fID != 0 &&
"-mouseMoved:, fID is 0");
2948 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2949 "-mouseMoved:, gVirtualX is null or not of TGCocoa type");
2956 - (
void) mouseDragged : (NSEvent *) theEvent
2958 assert(
fID != 0 &&
"-mouseDragged:, fID is 0");
2961 assert(vx != 0 &&
"-mouseDragged:, gVirtualX is null or not of TGCocoa type");
2967 - (
void) rightMouseDragged : (NSEvent *) theEvent
2969 assert(
fID != 0 &&
"-rightMouseDragged:, fID is 0");
2971 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2972 "-rightMouseDragged:, gVirtualX is null or not of TGCocoa type");
2979 - (
void) otherMouseDragged : (NSEvent *) theEvent
2981 assert(
fID != 0 &&
"-otherMouseDragged:, fID is 0");
2983 if ([theEvent buttonNumber] == 2) {
2984 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2985 "-otherMouseDragged:, gVirtualX is null or not of TGCocoa type");
2992 - (
void) keyDown : (NSEvent *) theEvent
2994 assert(
fID != 0 &&
"-keyDown:, fID is 0");
2996 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2997 "-keyDown:, gVirtualX is null or not of TGCocoa type");
2999 NSView<X11Window> *eventView =
self;
3001 eventView = pointerView;
3008 - (
void) keyUp : (NSEvent *) theEvent
3010 assert(
fID != 0 &&
"-keyUp:, fID is 0");
3012 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
3013 "-keyUp:, gVirtualX is null or not of TGCocoa type");
3016 NSView<X11Window> *eventView =
self;
3018 eventView = pointerView;
3023 #pragma mark - First responder stuff.
3026 - (BOOL) acceptsFirstMouse : (NSEvent *) theEvent
3028 #pragma unused(theEvent)
3033 - (BOOL) acceptsFirstResponder
3038 #pragma mark - Cursors.
3045 [
self.fQuartzWindow invalidateCursorRectsForView : self];
3050 - (NSCursor *) createCustomCursor
3052 const char *pngFileName = 0;
3056 pngFileName =
"move_cursor.png";
3059 pngFileName =
"hor_arrow_cursor.png";
3062 pngFileName =
"ver_arrow_cursor.png";
3065 pngFileName =
"right_arrow_cursor.png";
3068 pngFileName =
"rotate.png";
3072 pngFileName =
"top_right_cursor.png";
3076 pngFileName =
"top_left_cursor.png";
3083 const Util::ScopedArray<const char> arrayGuard(path);
3085 if (!path || path[0] == 0) {
3090 NSString *nsPath = [NSString stringWithFormat : @"%s", path];
3091 NSImage *
const cursorImage = [[NSImage alloc] initWithContentsOfFile : nsPath];
3097 NSCursor *
const customCursor = [[[NSCursor alloc] initWithImage : cursorImage
3098 hotSpot : hotSpot] autorelease];
3100 [cursorImage release];
3102 return customCursor;
3109 - (
void) resetCursorRects
3112 [
self addCursorRect : self.visibleRect cursor : cursor];
3116 - (
void) cursorUpdate
3126 - (
void) cursorUpdate : (NSEvent *) event
3128 #pragma unused(event)
3140 [
self performSelector : @selector(cursorUpdate) withObject : nil afterDelay : 0.05f];
3143 #pragma mark - Emulated X11 properties.
3146 - (
void) setProperty : (const
char *) propName data : (
unsigned char *) propData
3147 size : (
unsigned) dataSize forType : (
Atom_t) dataType format : (
unsigned) format
3149 assert(propName != 0 &&
"-setProperty:data:size:forType:, parameter 'propName' is null");
3150 assert(propData != 0 &&
"-setProperty:data:size:forType:, parameter 'propData' is null");
3151 assert(dataSize != 0 &&
"-setProperty:data:size:forType:, parameter 'dataSize' is 0");
3153 NSString *
const key = [NSString stringWithCString : propName encoding : NSASCIIStringEncoding];
3154 QuartzWindowProperty *
property = (QuartzWindowProperty *)[
fX11Properties valueForKey : key];
3158 [property resetPropertyData : propData size : dataSize type : dataType format : format];
3161 property = [[QuartzWindowProperty alloc] initWithData : propData size : dataSize
3162 type : dataType format : format];
3169 - (BOOL) hasProperty : (const
char *) propName
3171 assert(propName != 0 &&
"-hasProperty:, propName parameter is null");
3173 NSString *
const key = [NSString stringWithCString : propName encoding : NSASCIIStringEncoding];
3174 QuartzWindowProperty *
const property = (QuartzWindowProperty *)[
fX11Properties valueForKey : key];
3176 return property != nil;
3180 - (
unsigned char *) getProperty : (const
char *) propName returnType : (
Atom_t *) type
3181 returnFormat : (
unsigned *) format nElements : (
unsigned *) nElements
3183 assert(propName != 0 &&
3184 "-getProperty:returnType:returnFormat:nElements:, parameter 'propName' is null");
3186 "-getProperty:returnType:returnFormat:nElements:, parameter 'type' is null");
3187 assert(format != 0 &&
3188 "-getProperty:returnType:returnFormat:nElements:, parameter 'format' is null");
3189 assert(nElements != 0 &&
3190 "-getProperty:returnType:returnFormat:nElements:, parameter 'nElements' is null");
3192 NSString *
const key = [NSString stringWithCString : propName encoding : NSASCIIStringEncoding];
3193 QuartzWindowProperty *
const property = (QuartzWindowProperty *)[
fX11Properties valueForKey : key];
3194 assert(property != 0 &&
3195 "-getProperty:returnType:returnFormat:nElements, property not found");
3197 NSData *
const propData =
property.fPropertyData;
3199 const NSUInteger dataSize = [propData length];
3200 unsigned char *buff = 0;
3202 buff =
new unsigned char[dataSize]();
3203 }
catch (
const std::bad_alloc &) {
3205 NSLog(
@"QuartzWindow: -getProperty:returnType:returnFormat:nElements:,"
3206 " memory allocation failed");
3210 [propData getBytes : buff length : dataSize];
3211 *format =
property.fFormat;
3213 *nElements = dataSize;
3216 *nElements= dataSize / 2;
3217 else if (*format == 32)
3218 *nElements = dataSize / 4;
3220 *type =
property.fType;
3226 - (
void) removeProperty : (const
char *) propName
3228 assert(propName != 0 &&
"-removeProperty:, parameter 'propName' is null");
3230 NSString *
const key = [NSString stringWithCString : propName
3231 encoding : NSASCIIStringEncoding];
3237 - (NSDragOperation) draggingEntered : (
id<NSDraggingInfo>) sender
3239 NSPasteboard *
const pasteBoard = [sender draggingPasteboard];
3240 const NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
3242 if ([[pasteBoard types] containsObject : NSFilenamesPboardType] && (sourceDragMask & NSDragOperationCopy))
3243 return NSDragOperationCopy;
3245 return NSDragOperationNone;
3249 - (BOOL) performDragOperation : (
id<NSDraggingInfo>) sender
3260 NSPasteboard *
const pasteBoard = [sender draggingPasteboard];
3261 const NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
3263 if ([[pasteBoard types] containsObject : NSFilenamesPboardType] && (sourceDragMask & NSDragOperationCopy)) {
3269 NSArray *
const files = [pasteBoard propertyListForType : NSFilenamesPboardType];
3270 for (NSString *path in files) {
3272 NSString *
const item = [@"file://" stringByAppendingString : path];
3274 const NSUInteger len = [item lengthOfBytesUsingEncoding : NSASCIIStringEncoding] + 1;
3276 std::vector<unsigned char> propertyData(len);
3277 [item getCString : (char *)&propertyData[0] maxLength : propertyData.size()
3278 encoding : NSASCIIStringEncoding];
3280 NSView<X11Window> *
const targetView =
self.fQuartzWindow.fContentView;
3281 [targetView setProperty : "_XC_DND_DATA" data : &propertyData[0]
3282 size : propertyData.size() forType : textUriAtom format : 8];
3283 }
catch (
const std::bad_alloc &) {
3285 NSLog(
@"QuartzView: -performDragOperation:, memory allocation failed");
3301 event1.
fUser[2] = textUriAtom;
3311 event2.
fUser[2] = 0;
3312 NSPoint dropPoint = [sender draggingLocation];
3315 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)
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
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
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
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
ROOT::MacOSX::X11::CommandBuffer * GetCommandBuffer() const
const Mask_t kWABitGravity
int LocalYCocoaToROOT(NSView< X11Window > *parentView, CGFloat yCocoa)
QuartzView * fContentView
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
static std::string format(double x, double y, int digits, int width)
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)
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
ROOT::MacOSX::X11::Rectangle GetDisplayGeometry() const
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()
const Mask_t kExposureMask
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)
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)
NSCursor * CreateCursor(ECursor currentCursor)
unsigned long fBackgroundPixel
unsigned fPassiveGrabKeyModifiers
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)
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
ROOT::MacOSX::X11::EventTranslator * GetEventTranslator() const
bool ViewIsTextViewFrame(NSView< X11Window > *view, bool checkParent)
unsigned fActiveGrabEventMask
bool HasPointerGrab() 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)