16 #ifdef DEBUG_ROOT_COCOA 28 #include <Availability.h> 35 #include "RConfigure.h" 48 #pragma mark - Create a window or a view. 57 winRect.size.width = w;
58 winRect.size.height =
h;
60 const NSUInteger styleMask = NSTitledWindowMask | NSClosableWindowMask |
61 NSMiniaturizableWindowMask | NSResizableWindowMask;
65 backing : NSBackingStoreBuffered
67 windowAttributes :
attr];
69 throw std::runtime_error(
"CreateTopLevelWindow failed");
71 newWindow.fDepth = depth;
72 newWindow.fClass = clss;
82 viewRect.origin.x =
x;
83 viewRect.origin.y =
y;
84 viewRect.size.width = w;
85 viewRect.size.height =
h;
89 throw std::runtime_error(
"CreateChildView failed");
94 #pragma mark - root window (does not really exist, it's our desktop built of all screens). 100 assert(attr != 0 &&
"GetRootWindowAttributes, parameter 'attr' is null");
103 NSArray *
const screens = [NSScreen screens];
104 assert(screens != nil &&
"screens array is nil");
105 NSScreen *
const mainScreen = [screens objectAtIndex : 0];
106 assert(mainScreen != nil &&
"screen with index 0 is nil");
111 "GetRootWindowAttributes, gVirtualX is either null or has a wrong type");
125 attr->
fDepth = NSBitsPerPixelFromDepth([mainScreen depth]);
131 #pragma mark - Coordinate conversions. 136 assert(window != nil &&
"ConvertPointFromBaseToScreen, parameter 'window' is nil");
142 tmpRect.origin = windowPoint;
143 tmpRect.size = NSMakeSize(1., 1.);
144 tmpRect = [window convertRectToScreen : tmpRect];
146 return tmpRect.origin;
152 assert(window != nil &&
"ConvertPointFromScreenToBase, parameter 'window' is nil");
158 tmpRect.origin = screenPoint;
159 tmpRect.size = NSMakeSize(1., 1.);
160 tmpRect = [window convertRectFromScreen : tmpRect];
162 return tmpRect.origin;
173 "GlobalYCocoaToROOT, gVirtualX is either nul or has a wrong type");
177 return int(frame.
fHeight - (yCocoa - frame.
fY));
184 "GlobalXCocoaToROOT, gVirtualX is either nul or has a wrong type");
187 return int(xCocoa - frame.
fX);
194 "GlobalYROOTToCocoa, gVirtualX is either nul or has a wrong type");
197 return int(frame.
fY + (frame.
fHeight - yROOT));
204 "GlobalXROOTToCocoa, gVirtualX is either nul or has a wrong type");
207 return int(frame.
fX + xROOT);
213 assert(parentView != nil &&
"LocalYCocoaToROOT, parent view is nil");
215 return int(parentView.frame.size.height - yCocoa);
222 assert(parentView != nil &&
"LocalYROOTToCocoa, parent view is nil");
224 return int(parentView.frame.size.height - yROOT);
232 assert(drawable != nil &&
"LocalYROOTToCocoa, drawable is nil");
234 return int(drawable.fHeight - yROOT);
240 assert(from != nil &&
"TranslateToScreen, parameter 'from' is nil");
242 const NSPoint winPoint = [from convertPoint : point toView : nil];
254 assert(to != nil &&
"TranslateFromScreen, parameter 'to' is nil");
260 return [to convertPoint : point fromView : nil];
267 assert(from != nil &&
"TranslateCoordinates, parameter 'from' is nil");
268 assert(to != nil &&
"TranslateCoordinates, parameter 'to' is nil");
270 if ([from window] == [to window]) {
272 return [to convertPoint : sourcePoint fromView : from];
280 const NSPoint win1Point = [from convertPoint : sourcePoint toView : nil];
284 return [to convertPoint : win2Point fromView : nil];
291 assert(view != nil &&
"ScreenPointIsInView, parameter 'view' is nil");
294 point.x =
x, point.y =
y;
296 const NSRect viewFrame = view.frame;
298 if (point.x < 0 || point.x > viewFrame.size.width)
300 if (point.y < 0 || point.y > viewFrame.size.height)
306 #pragma mark - Different FindView/Window functions iterating on the ROOT's windows/views. 314 NSArray *
const orderedWindows = [NSApp orderedWindows];
315 for (NSWindow *window in orderedWindows) {
318 QuartzWindow *
const qw = (QuartzWindow *)window;
333 assert(children != nil &&
"FindDNDAwareViewInPoint, parameter 'children' is nil");
338 NSEnumerator *
const reverseEnumerator = [children reverseObjectEnumerator];
339 for (NSView<X11Window> *child in reverseEnumerator) {
342 if (child.fIsDNDAware && child.fID != dragWinID && child.fID != inputWinID)
346 inputWinID, x, y, maxDepth - 1);
365 NSArray *
const orderedWindows = [NSApp orderedWindows];
366 for (NSWindow *window in orderedWindows) {
369 QuartzWindow *
const qw = (QuartzWindow *)window;
382 if (testView.fIsDNDAware && testView.fID != dragWinID && testView.fID != inputWinID)
386 NSArray *
const children = [testView subviews];
405 NSArray *
const orderedWindows = [NSApp orderedWindows];
406 for (NSWindow *nsWindow in orderedWindows) {
410 QuartzWindow *
const qWindow = (QuartzWindow *)nsWindow;
418 const NSPoint mousePosition = [qWindow mouseLocationOutsideOfEventStream];
419 const NSSize windowSize = qWindow.frame.size;
420 if (mousePosition.x >= 0 && mousePosition.x <= windowSize.width &&
421 mousePosition.y >= 0 && mousePosition.y <= windowSize.height)
435 const NSPoint mousePosition = [topLevel mouseLocationOutsideOfEventStream];
436 return (NSView<X11Window> *)[[topLevel contentView] hitTest : mousePosition];
449 assert(pointerEvent != nil &&
450 "FindWindowForPointerEvent, parameter 'pointerEvent' is nil");
454 NSArray *
const orderedWindows = [NSApp orderedWindows];
455 for (NSWindow *nsWindow in orderedWindows) {
459 QuartzWindow *
const qWindow = (QuartzWindow *)nsWindow;
468 NSPoint mousePosition = [pointerEvent locationInWindow];
471 if ([pointerEvent window]) {
481 const NSSize windowSize = qWindow.frame.size;
482 if (mousePosition.x >= 0 && mousePosition.x <= windowSize.width &&
483 mousePosition.y >= 0 && mousePosition.y <= windowSize.height)
496 assert(pointerEvent != nil &&
497 "FindViewForPointerEvent, parameter 'pointerEvent' is nil");
502 NSPoint mousePosition = [pointerEvent locationInWindow];
503 if ([pointerEvent window])
510 return (NSView<X11Window> *)[[topLevel contentView] hitTest : mousePosition];
516 #pragma mark - Downscale image ("reading color bits" on retina macs). 521 assert(w != 0 && h != 0 &&
"DownscaledImageData, invalid geometry");
522 assert(image !=
nullptr &&
"DonwscaledImageData, invalid parameter 'image'");
524 std::vector<unsigned char>
result;
526 result.resize(w * h * 4);
527 }
catch (
const std::bad_alloc &) {
529 NSLog(
@"DownscaledImageData, memory allocation failed");
535 if (!colorSpace.
Get()) {
536 NSLog(
@"DownscaledImageData, CGColorSpaceCreateDeviceRGB failed");
541 w * 4, colorSpace.
Get(),
542 kCGImageAlphaPremultipliedLast,
NULL, 0));
544 NSLog(
@"DownscaledImageData, CGBitmapContextCreateWithData failed");
548 CGContextDrawImage(ctx.
Get(), CGRectMake(0, 0, w, h), image);
553 #pragma mark - "Focus management" - just make another window key window. 559 if (![NSApp isActive])
564 NSArray *
const orderedWindows = [NSApp orderedWindows];
565 for (NSWindow *nsWindow in orderedWindows) {
569 QuartzWindow *
const qWindow = (QuartzWindow *)nsWindow;
577 [qWindow makeKeyAndOrderFront : qWindow];
582 #pragma mark - 'shape mask' - to create a window with arbitrary (probably non-rectangle) shape. 587 assert(view != nil &&
"ClipToShapeMask, parameter 'view' is nil");
588 assert(ctx != 0 &&
"ClipToShapeMask, parameter 'ctx' is null");
592 "ClipToShapeMask, fShapeCombineMask is nil on a top-level window");
594 "ClipToShapeMask, shape mask is null");
600 if (!view.fParentView) {
606 NSRect clipRect = view.frame;
608 clipRect.origin = [view.fParentView convertPoint : clipRect.origin
609 toView : [view window].contentView];
611 clipRect.origin.y + clipRect.size.height);
616 NSRectToCGRect(clipRect)));
617 clipRect.origin = NSPoint();
618 CGContextClipToMask(ctx, NSRectToCGRect(clipRect), clipImageGuard.
Get());
622 CGContextClipToRect(ctx, rect);
627 #pragma mark - Window's geometry and attributes. 632 assert(attr != 0 &&
"SetWindowAttributes, parameter 'attr' is null");
633 assert(window != nil &&
"SetWindowAttributes, parameter 'window' is nil");
654 if ([(NSObject *)window isKindOfClass : [
QuartzWindow class]]) {
655 QuartzWindow *
const qw = (QuartzWindow *)window;
656 [qw setStyleMask : NSBorderlessWindowMask];
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];
898 #pragma mark - Workarounds for a text view and its descendants. 912 assert(view != nil &&
"ViewIsTextView, parameter 'view' is nil");
920 assert(view != nil &&
"ViewIsTextViewFrame, parameter 'view' is nil");
932 if (!view.fParentView)
950 assert(view != nil &&
"ViewIsHtmlView, parameter 'view' is nil");
959 assert(view != nil &&
"ViewIsHtmlViewFrame, parameter 'view' is nil");
971 if (!view.fParentView)
980 assert(textView != nil &&
"FrameForTextView, parameter 'textView' is nil");
982 for (NSView<X11Window> *child in [textView subviews]) {
993 assert(htmlView != nil &&
"FrameForHtmlView, parameter 'htmlView' is nil");
995 for (NSView<X11Window> *child in [htmlView subviews]) {
1003 #pragma mark - Workarounds for 'paint out of paint events'. 1008 assert(view != nil &&
"LockFocus, parameter 'view' is nil");
1010 "LockFocus, QuartzView is expected");
1012 if ([view lockFocusIfCanDraw]) {
1013 NSGraphicsContext *nsContext = [NSGraphicsContext currentContext];
1014 assert(nsContext != nil &&
"LockFocus, currentContext is nil");
1015 CGContextRef currContext = (CGContextRef)[nsContext graphicsPort];
1016 assert(currContext != 0 &&
"LockFocus, graphicsPort is null");
1029 assert(view != nil &&
"UnlockFocus, parameter 'view' is nil");
1031 "UnlockFocus, QuartzView is expected");
1045 #ifdef DEBUG_ROOT_COCOA 1047 #pragma mark - 'loggers'. 1057 static std::ofstream logfile(
"win_attr.txt");
1061 logfile<<
"win "<<winID<<
": BackPixmap\n";
1063 logfile<<
"win "<<winID<<
": BackPixel\n";
1065 logfile<<
"win "<<winID<<
": BorderPixmap\n";
1067 logfile<<
"win "<<winID<<
": BorderPixel\n";
1069 logfile<<
"win "<<winID<<
": BorderWidth\n";
1071 logfile<<
"win "<<winID<<
": BitGravity\n";
1073 logfile<<
"win "<<winID<<
": WinGravity\n";
1075 logfile<<
"win "<<winID<<
": BackingStore\n";
1077 logfile<<
"win "<<winID<<
": BackingPlanes\n";
1079 logfile<<
"win "<<winID<<
": BackingPixel\n";
1081 logfile<<
"win "<<winID<<
": OverrideRedirect\n";
1083 logfile<<
"win "<<winID<<
": SaveUnder\n";
1085 logfile<<
"win "<<winID<<
": EventMask\n";
1087 logfile<<
"win "<<winID<<
": DontPropagate\n";
1089 logfile<<
"win "<<winID<<
": Colormap\n";
1091 logfile<<
"win "<<winID<<
": Cursor\n";
1095 void print_mask_info(
ULong_t mask)
1098 NSLog(
@"button press mask");
1100 NSLog(
@"button release mask");
1102 NSLog(
@"exposure mask");
1104 NSLog(
@"pointer motion mask");
1106 NSLog(
@"button motion mask");
1108 NSLog(
@"enter notify mask");
1110 NSLog(
@"leave notify mask");
1122 #pragma mark - QuartzWindow's life cycle. 1125 - (
id) initWithContentRect : (NSRect) contentRect styleMask : (NSUInteger) windowStyle
1126 backing : (NSBackingStoreType) bufferingType defer : (BOOL) deferCreation
1129 self = [
super initWithContentRect : contentRect styleMask : windowStyle
1130 backing : bufferingType defer : deferCreation];
1134 [
self setAllowsConcurrentViewDrawing : NO];
1136 self.delegate =
self;
1138 NSRect contentViewRect = contentRect;
1139 contentViewRect.origin.x = 0.f;
1140 contentViewRect.origin.y = 0.f;
1146 [
self setContentView : fContentView];
1164 assert(glView != nil &&
"-initWithGLView, parameter 'glView' is nil");
1166 const NSUInteger styleMask = NSTitledWindowMask | NSClosableWindowMask |
1167 NSMiniaturizableWindowMask | NSResizableWindowMask;
1169 NSRect contentRect = glView.frame;
1170 contentRect.origin = NSPoint();
1172 self = [
super initWithContentRect : contentRect styleMask : styleMask
1173 backing : NSBackingStoreBuffered defer : NO];
1177 [
self setAllowsConcurrentViewDrawing : NO];
1178 self.delegate =
self;
1180 [
self setContentView : fContentView];
1203 - (
void) setContentView:(NSView *)cv
1205 [
super setContentView:cv];
1213 - (
void) setFIsDeleted : (BOOL) deleted
1218 #pragma mark - Forwaring: I want to forward a lot of property setters/getters to the content view. 1221 - (
void) forwardInvocation : (NSInvocation *) anInvocation
1226 if ([
fContentView respondsToSelector : [anInvocation selector]]) {
1227 [anInvocation invokeWithTarget : fContentView];
1229 [
super forwardInvocation : anInvocation];
1234 - (NSMethodSignature*) methodSignatureForSelector : (
SEL) selector
1236 NSMethodSignature *signature = [
super methodSignatureForSelector : selector];
1240 signature = [
fContentView methodSignatureForSelector : selector];
1255 assert(window != nil &&
"-addTransientWindow:, parameter 'window' is nil");
1264 [
self addChildWindow : window ordered : NSWindowAbove];
1270 - (
void) makeKeyAndOrderFront : (
id) sender
1272 #pragma unused(sender) 1277 #ifdef MAC_OS_X_VERSION_10_9 1278 [
self setCollectionBehavior : NSWindowCollectionBehaviorMoveToActiveSpace];
1280 [
self setCollectionBehavior : NSWindowCollectionBehaviorCanJoinAllSpaces];
1283 [
super makeKeyAndOrderFront : self];
1285 [
self setCollectionBehavior : NSWindowCollectionBehaviorDefault];
1289 - (
void) setFDelayedTransient : (BOOL) d
1313 #pragma mark - X11Drawable's protocol. 1344 return self.frame.size.width;
1359 - (
void) setDrawableSize : (NSSize) newSize
1362 assert(!(newSize.width < 0) &&
"-setDrawableSize:, width is negative");
1363 assert(!(newSize.height < 0) &&
"-setDrawableSize:, height is negative");
1365 NSRect frame =
self.frame;
1369 frame.origin.y = frame.origin.y + frame.size.height - newSize.height - dY;
1370 frame.size = newSize;
1371 frame.size.height += dY;
1372 [
self setFrame : frame display : YES];
1376 - (
void) setX : (
int) x Y : (
int) y width : (
unsigned) w height : (
unsigned) h
1378 NSSize newSize = {};
1381 [
self setContentSize : newSize];
1384 NSPoint topLeft = {};
1388 [
self setFrameTopLeftPoint : topLeft];
1392 - (
void) setX : (
int) x Y : (
int) y
1394 NSPoint topLeft = {};
1398 [
self setFrameTopLeftPoint : topLeft];
1403 clipOrigin : (
X11::Point) clipXY toPoint : (
X11::Point) dstPoint
1408 [
fContentView copy : src area : area withMask : mask clipOrigin : clipXY toPoint : dstPoint];
1412 - (
unsigned char *) readColorBits : (
X11::Rectangle) area
1420 #pragma mark - X11Window protocol's implementation. 1431 #pragma unused(parent) 1449 - (
void) setFBackgroundPixel : (
unsigned long) backgroundColor
1455 CGFloat rgba[] = {0., 0., 0., 1.};
1458 [
self setBackgroundColor : [NSColor colorWithColorSpace : [NSColorSpace deviceRGBColorSpace] components : rgba count : 4]];
1487 - (
void) addChild : (NSView<X11Window> *) child
1489 assert(child != nil &&
"-addChild:, parameter 'child' is nil");
1494 "-addChild: gl view in a top-level window as content view is not supported");
1497 [
self setContentView : child];
1509 assert(attr &&
"-getAttributes:, parameter 'attr' is nil");
1517 assert(attr != 0 &&
"-setAttributes:, parameter 'attr' is null");
1519 #ifdef DEBUG_ROOT_COCOA 1520 log_attributes(attr,
self.fID);
1532 const Util::AutoreleasePool pool;
1535 [
self makeKeyAndOrderFront : self];
1540 [
fMainWindow addChildWindow : self ordered : NSWindowAbove];
1550 const Util::AutoreleasePool pool;
1553 [
self makeKeyAndOrderFront : self];
1558 [
fMainWindow addChildWindow : self ordered : NSWindowAbove];
1568 const Util::AutoreleasePool pool;
1581 [
self orderOut : self];
1589 #pragma mark - Events. 1592 - (
void) sendEvent : (NSEvent *) theEvent
1601 if (theEvent.type == NSLeftMouseDown || theEvent.type == NSRightMouseDown) {
1602 bool generateFakeRelease =
false;
1604 const NSPoint windowPoint = [theEvent locationInWindow];
1606 if (windowPoint.x <= 4 || windowPoint.x >=
self.fWidth - 4)
1607 generateFakeRelease =
true;
1609 if (windowPoint.y <= 4 || windowPoint.y >=
self.fHeight - 4)
1610 generateFakeRelease =
true;
1612 const NSPoint viewPoint = [
fContentView convertPoint : windowPoint fromView : nil];
1614 if (viewPoint.y <= 0 && windowPoint.y >= 0)
1615 generateFakeRelease =
true;
1618 "-sendEvent:, gVirtualX is either null or not of TGCocoa type");
1623 theEvent.type == NSLeftMouseDown ?
1632 [
super sendEvent : theEvent];
1635 #pragma mark - NSWindowDelegate's methods. 1638 - (BOOL) windowShouldClose : (
id) sender
1640 #pragma unused(sender) 1649 if ([[
self childWindows] count])
1661 "-windowShouldClose:, gVirtualX is either null or has a type different from TGCocoa");
1670 - (
void) windowDidBecomeKey : (NSNotification *) aNotification
1672 #pragma unused(aNotification) 1681 "-windowDidBecomeKey:, gVirtualX is null or not of TGCocoa type");
1689 - (
void) windowDidResignKey : (NSNotification *) aNotification
1691 #pragma unused(aNotification) 1697 #pragma mark - Passive key grab info. 1702 - (
id) initWithKey : (unichar) keyCode modifiers : (NSUInteger) modifiers
1704 if (
self = [super
init]) {
1713 - (BOOL) matchKey : (unichar) keyCode modifiers : (NSUInteger) modifiers
1719 - (BOOL) matchKey : (unichar) keyCode
1738 #pragma mark - X11 property emulation. 1740 @interface QuartzWindowProperty : NSObject {
1741 NSData *fPropertyData;
1750 @implementation QuartzWindowProperty
1757 if (
self = [super
init]) {
1759 fPropertyData = nil;
1763 [
self resetPropertyData : data size : dataSize type : type format : format];
1772 [fPropertyData release];
1778 - (
void) resetPropertyData : (
unsigned char *) data size : (unsigned) dataSize
1781 [fPropertyData release];
1789 fPropertyData = [[NSData dataWithBytes : data length : dataSize] retain];
1795 - (NSData *) fPropertyData
1797 return fPropertyData;
1801 - (unsigned) fFormat
1808 #pragma mark - QuartzView. 1841 #pragma mark - Lifetime. 1846 if (
self = [super initWithFrame : frame]) {
1858 [
self setCanDrawConcurrently : NO];
1860 [
self setHidden : YES];
1887 #pragma mark - Tracking area. 1892 - (
void) updateTrackingAreas
1894 [
super updateTrackingAreas];
1899 const Util::AutoreleasePool pool;
1901 if (NSArray *trackingArray = [
self trackingAreas]) {
1902 const NSUInteger size = [trackingArray count];
1903 for (NSUInteger i = 0; i < size; ++i) {
1904 NSTrackingArea *
const t = [trackingArray objectAtIndex : i];
1905 [
self removeTrackingArea : t];
1909 const NSUInteger trackerOptions = NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited |
1910 NSTrackingActiveInActiveApp | NSTrackingInVisibleRect |
1911 NSTrackingEnabledDuringMouseDrag | NSTrackingCursorUpdate;
1914 frame.size.width =
self.fWidth;
1915 frame.size.height =
self.fHeight;
1917 NSTrackingArea *
const tracker = [[NSTrackingArea alloc] initWithRect : frame
1918 options : trackerOptions owner : self userInfo : nil];
1919 [
self addTrackingArea : tracker];
1924 - (
void) updateTrackingAreasAfterRaise
1926 [
self updateTrackingAreas];
1928 for (
QuartzView *childView in [
self subviews])
1929 [childView updateTrackingAreasAfterRaise];
1932 #pragma mark - X11Drawable protocol. 1949 return self.frame.origin.x;
1955 return self.frame.origin.y;
1961 return self.frame.size.width;
1967 return self.frame.size.height;
1971 - (
void) setDrawableSize : (NSSize) newSize
1973 assert(!(newSize.width < 0) &&
"-setDrawableSize, width is negative");
1974 assert(!(newSize.height < 0) &&
"-setDrawableSize, height is negative");
1980 NSRect frame =
self.frame;
1981 frame.size = newSize;
1987 - (
void) setX : (
int) x Y : (
int) y width : (
unsigned) w height : (
unsigned) h
1989 NSRect newFrame = {};
1990 newFrame.origin.x =
x;
1991 newFrame.origin.y =
y;
1992 newFrame.size.width = w;
1993 newFrame.size.height =
h;
1995 self.frame = newFrame;
1999 - (
void) setX : (
int) x Y : (
int) y
2001 NSRect newFrame =
self.frame;
2002 newFrame.origin.x =
x;
2003 newFrame.origin.y =
y;
2005 self.frame = newFrame;
2014 assert(srcImage != nil &&
2015 "-copyImage:area:withMask:clipOrigin:toPoint:, parameter 'srcImage' is nil");
2016 assert(srcImage.fImage != nil &&
2017 "-copyImage:area:withMask:clipOrigin:toPoint:, srcImage.fImage is nil");
2021 "-copyImage:area:withMask:clipOrigin:toPoint:, self.fContext is null");
2024 NSLog(
@"QuartzView: -copyImage:area:withMask:clipOrigin:toPoint:," 2025 " srcRect and copyRect do not intersect");
2031 CGImageRef subImage = 0;
2032 bool needSubImage =
false;
2033 if (area.fX || area.fY || area.fWidth != srcImage.fWidth || area.fHeight != srcImage.fHeight) {
2034 needSubImage =
true;
2037 NSLog(
@"QuartzView: -copyImage:area:withMask:clipOrigin:toPoint:," 2038 " subimage creation failed");
2042 subImage = srcImage.fImage;
2049 CGContextScaleCTM(
self.
fContext, 1., -1.);
2054 "-copyImage:area:withMask:clipOrigin:toPoint:, mask.fImage is nil");
2056 "-copyImage:area:withMask:clipOrigin:toPoint:, mask.fImage is not a mask");
2060 const CGRect clipRect = CGRectMake(clipXY.fX, clipY, mask.
fWidth, mask.
fHeight);
2068 const CGRect imageRect = CGRectMake(dstPoint.fX, dstY, area.fWidth, area.fHeight);
2069 CGContextDrawImage(
self.
fContext, imageRect, subImage);
2072 CGImageRelease(subImage);
2083 assert(srcView != nil &&
"-copyView:area:toPoint:, parameter 'srcView' is nil");
2085 const NSRect frame = [srcView frame];
2087 NSBitmapImageRep *
const imageRep = [srcView bitmapImageRepForCachingDisplayInRect : frame];
2089 NSLog(
@"QuartzView: -copyView:area:toPoint failed");
2093 assert(srcView != nil &&
"-copyView:area:toPoint:, parameter 'srcView' is nil");
2094 assert(
self.
fContext != 0 &&
"-copyView:area:toPoint, self.fContext is null");
2099 CGContextRef ctx = srcView.fContext;
2100 srcView.fSnapshotDraw = YES;
2101 [srcView cacheDisplayInRect : frame toBitmapImageRep : imageRep];
2102 srcView.fSnapshotDraw = NO;
2103 srcView.fContext = ctx;
2105 const CGRect subImageRect = CGRectMake(area.fX, area.fY, area.fWidth, area.fHeight);
2106 const Util::CFScopeGuard<CGImageRef> subImage(CGImageCreateWithImageInRect(imageRep.CGImage, subImageRect));
2108 if (!subImage.Get()) {
2109 NSLog(
@"QuartzView: -copyView:area:toPoint, CGImageCreateWithImageInRect failed");
2114 const CGRect imageRect = CGRectMake(dstPoint.fX,
2115 [
self visibleRect].size.height - (CGFloat(dstPoint.fY) + area.fHeight),
2116 area.fWidth, area.fHeight);
2118 CGContextTranslateCTM(
self.
fContext, 0., [
self visibleRect].size.height);
2119 CGContextScaleCTM(
self.
fContext, 1., -1.);
2121 CGContextDrawImage(
self.
fContext, imageRect, subImage.Get());
2129 assert(srcPixmap != nil &&
"-copyPixmap:area:withMask:clipOrigin:toPoint:, parameter 'srcPixmap' is nil");
2132 NSLog(
@"QuartzView: -copyPixmap:area:withMask:clipOrigin:toPoint," 2133 " no intersection between pixmap rectangle and cropArea");
2139 "-copyPixmap:area:withMask:clipOrigin:toPoint:, self.fContext is null");
2144 CGContextTranslateCTM(
self.
fContext, 0.,
self.frame.size.height);
2145 CGContextScaleCTM(
self.
fContext, 1., -1.);
2147 const Util::CFScopeGuard<CGImageRef> imageFromPixmap([srcPixmap createImageFromPixmap]);
2148 assert(imageFromPixmap.Get() != 0 &&
2149 "-copyPixmap:area:withMask:clipOrigin:toPoint:, createImageFromPixmap failed");
2151 CGImageRef subImage = 0;
2152 bool needSubImage =
false;
2153 if (area.fX || area.fY || area.fWidth != srcPixmap.fWidth || area.fHeight != srcPixmap.fHeight) {
2154 needSubImage =
true;
2155 const CGRect subImageRect = CGRectMake(area.fX, area.fY, area.fHeight, area.fWidth);
2156 subImage = CGImageCreateWithImageInRect(imageFromPixmap.Get(), subImageRect);
2158 NSLog(
@"QuartzView: -copyImage:area:withMask:clipOrigin:toPoint:," 2159 " subimage creation failed");
2163 subImage = imageFromPixmap.Get();
2167 "-copyPixmap:area:withMask:clipOrigin:toPoint:, mask.fImage is nil");
2169 "-copyPixmap:area:withMask:clipOrigin:toPoint:, mask.fImage is not a mask");
2174 const CGRect clipRect = CGRectMake(clipXY.fX, clipY, mask.
fWidth, mask.
fHeight);
2180 const CGRect imageRect = CGRectMake(dstPoint.fX, dstY, area.fWidth, area.fHeight);
2181 CGContextDrawImage(
self.
fContext, imageRect, imageFromPixmap.Get());
2184 CGImageRelease(subImage);
2192 assert(srcImage != nil &&
"-copyImage:area:toPoint:, parameter 'srcImage' is nil");
2193 assert(srcImage.fImage != nil &&
"-copyImage:area:toPoint:, srcImage.fImage is nil");
2194 assert(
self.
fContext != 0 &&
"-copyImage:area:toPoint:, fContext is null");
2197 NSLog(
@"QuartzView: -copyImage:area:toPoint, image and copy area do not intersect");
2201 CGImageRef subImage = 0;
2202 bool needSubImage =
false;
2203 if (area.fX || area.fY || area.fWidth != srcImage.fWidth || area.fHeight != srcImage.fHeight) {
2204 needSubImage =
true;
2207 NSLog(
@"QuartzView: -copyImage:area:toPoint:, subimage creation failed");
2211 subImage = srcImage.fImage;
2216 CGContextScaleCTM(
self.
fContext, 1., -1.);
2221 const CGRect imageRect = CGRectMake(dstPoint.fX, dstY, area.fWidth, area.fHeight);
2222 CGContextDrawImage(
self.
fContext, imageRect, subImage);
2225 CGImageRelease(subImage);
2230 withMask : (
QuartzImage *)mask clipOrigin : (
X11::Point) clipXY toPoint : (
X11::Point) dstPoint
2232 assert(src != nil &&
"-copy:area:withMask:clipOrigin:toPoint:, parameter 'src' is nil");
2233 assert(area.fWidth && area.fHeight &&
"-copy:area:withMask:clipOrigin:toPoint:, area to copy is empty");
2239 [
self copyView : (QuartzView *)qw.fContentView area : area toPoint : dstPoint];
2240 }
else if ([src isKindOfClass : [
QuartzView class]]) {
2242 [
self copyView : (QuartzView *)src area : area toPoint : dstPoint];
2243 }
else if ([src isKindOfClass : [
QuartzPixmap class]]) {
2244 [
self copyPixmap : (QuartzPixmap *)src area : area withMask : mask clipOrigin : clipXY toPoint : dstPoint];
2245 }
else if ([src isKindOfClass : [
QuartzImage class]]) {
2246 [
self copyImage : (QuartzImage *)src area : area withMask : mask clipOrigin : clipXY toPoint : dstPoint];
2248 assert(0 &&
"-copy:area:withMask:clipOrigin:toPoint:, src is of unknown type");
2253 - (
unsigned char *) readColorBits : (
X11::Rectangle) area
2259 assert(area.fWidth && area.fHeight &&
"-readColorBits:, area to copy is empty");
2262 const NSRect visRect = [
self visibleRect];
2263 const X11::Rectangle srcRect(
int(visRect.origin.x),
int(visRect.origin.y),
2264 unsigned(visRect.size.width),
unsigned(visRect.size.height));
2267 NSLog(
@"QuartzView: -readColorBits:, visible rect of view and copy area do not intersect");
2272 NSBitmapImageRep *
const imageRep = [
self bitmapImageRepForCachingDisplayInRect : visRect];
2274 NSLog(
@"QuartzView: -readColorBits:, bitmapImageRepForCachingDisplayInRect failed");
2278 CGContextRef ctx =
self.fContext;
2279 [
self cacheDisplayInRect : visRect toBitmapImageRep : imageRep];
2280 self.fContext = ctx;
2282 const NSInteger bitsPerPixel = [imageRep bitsPerPixel];
2284 assert(bitsPerPixel == 32 &&
"-readColorBits:, no alpha channel???");
2285 const NSInteger bytesPerRow = [imageRep bytesPerRow];
2286 unsigned dataWidth = bytesPerRow / (bitsPerPixel / 8);
2288 unsigned char *srcData =
nullptr;
2289 std::vector<unsigned char> downscaled;
2290 if ([[NSScreen mainScreen] backingScaleFactor] > 1 && imageRep.CGImage) {
2292 if (downscaled.size())
2293 srcData = &downscaled[0];
2294 dataWidth = area.fWidth;
2296 srcData = [imageRep bitmapData];
2299 NSLog(
@"QuartzView: -readColorBits:, failed to obtain backing store contents");
2304 unsigned char *data =
nullptr;
2307 data =
new unsigned char[area.fWidth * area.fHeight * 4];
2308 }
catch (
const std::bad_alloc &) {
2309 NSLog(
@"QuartzView: -readColorBits:, memory allocation failed");
2313 unsigned char *dstPixel = data;
2314 const unsigned char *
line = srcData + area.fY * dataWidth * 4;
2315 const unsigned char *srcPixel =
line + area.fX * 4;
2317 for (
unsigned i = 0; i < area.fHeight; ++i) {
2318 for (
unsigned j = 0; j < area.fWidth; ++j, srcPixel += 4, dstPixel += 4) {
2319 dstPixel[0] = srcPixel[2];
2320 dstPixel[1] = srcPixel[1];
2321 dstPixel[2] = srcPixel[0];
2322 dstPixel[3] = srcPixel[3];
2325 line += dataWidth * 4;
2326 srcPixel =
line + area.fX * 4;
2355 if ([
self isHidden])
2359 if ([parent isHidden])
2377 - (
void) setFHasFocus : (BOOL) focus
2379 #pragma unused(focus) 2430 - (
void) activateGrab : (
unsigned) eventMask ownerEvents : (BOOL) ownerEvents
2446 - (BOOL) acceptsCrossingEvents : (
unsigned) eventMask
2465 - (
void) addChild : (NSView<X11Window> *) child
2467 assert(child != nil &&
"-addChild:, parameter 'child' is nil");
2469 [
self addSubview : child];
2470 child.fParentView =
self;
2476 assert(attr != 0 &&
"-getAttributes:, parameter 'attr' is null");
2484 assert(attr != 0 &&
"-setAttributes:, parameter 'attr' is null");
2486 #ifdef DEBUG_ROOT_COCOA 2487 log_attributes(attr,
fID);
2498 [
self removeFromSuperview];
2499 [parent addSubview : self];
2500 [
self setHidden : NO];
2506 [
self setHidden : NO];
2519 [
self setHidden : YES];
2529 - (
void) setOverlapped : (BOOL) overlap
2532 for (NSView<X11Window> *child in [
self subviews])
2533 [child setOverlapped : overlap];
2550 using namespace X11;
2553 if (
self == sibling)
2555 if ([sibling isHidden])
2558 if (NSEqualRects(sibling.frame,
self.frame)) {
2559 [sibling setOverlapped : YES];
2560 [sibling setHidden : YES];
2566 [
self setHidden : NO];
2568 [
fParentView sortSubviewsUsingFunction : CompareViewsToRaise context : (void *)self];
2570 [
self updateTrackingAreasAfterRaise];
2572 [
self setNeedsDisplay : YES];
2580 using namespace X11;
2582 NSEnumerator *
const reverseEnumerator = [[
fParentView subviews] reverseObjectEnumerator];
2583 for (
QuartzView *sibling in reverseEnumerator) {
2584 if (sibling ==
self)
2588 if (NSEqualRects(sibling.frame,
self.frame)) {
2589 [sibling setOverlapped : NO];
2591 [sibling setHidden : NO];
2593 [sibling setNeedsDisplay : YES];
2596 [
self setHidden : YES];
2602 [
fParentView sortSubviewsUsingFunction : CompareViewsToLower context : (void*)self];
2619 "-configureNotifyTree, gVirtualX is either null or has type different from TGCocoa");
2624 for (NSView<X11Window> *
v in [
self subviews])
2625 [v configureNotifyTree];
2629 #pragma mark - Key grabs. 2632 - (
void) addPassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers
2634 [
self removePassiveKeyGrab : keyCode modifiers : modifiers];
2636 modifiers : modifiers];
2642 - (
void) removePassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers
2645 for (NSUInteger i = 0; i < count; ++i) {
2647 if ([grab matchKey : keyCode modifiers : modifiers]) {
2655 - (
PassiveKeyGrab *) findPassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers
2659 if ([grab matchKey : keyCode modifiers : modifiers])
2672 if ([grab matchKey : keyCode])
2679 #pragma mark - Painting mechanics. 2682 - (
void) drawRect : (NSRect) dirtyRect
2684 #pragma unused(dirtyRect) 2686 using namespace X11;
2694 NSGraphicsContext *
const nsContext = [NSGraphicsContext currentContext];
2695 assert(nsContext != nil &&
"-drawRect:, currentContext returned nil");
2700 fContext = (CGContextRef)[nsContext graphicsPort];
2701 assert(
fContext != 0 &&
"-drawRect:, graphicsPort returned null");
2709 if (window->InheritsFrom(
"TGContainer"))
2732 gClient->CancelRedraw(window);
2740 [
self copy : fBackBuffer area : copyArea withMask : nil
2741 clipOrigin : X11::Point() toPoint : X11::Point()];
2745 #ifdef DEBUG_ROOT_COCOA 2746 CGContextSetRGBStrokeColor(
fContext, 1., 0., 0., 1.);
2747 CGContextStrokeRect(
fContext, dirtyRect);
2752 #ifdef DEBUG_ROOT_COCOA 2753 NSLog(
@"QuartzView: -drawRect: method, no window for id %u was found",
fID);
2759 #pragma mark - Geometry. 2762 - (
void) setFrame : (NSRect) newFrame
2767 if (NSEqualRects(newFrame,
self.frame))
2770 [
super setFrame : newFrame];
2774 - (
void) setFrameSize : (NSSize) newSize
2778 [
super setFrameSize : newSize];
2782 "setFrameSize:, gVirtualX is either null or has a type, different from TGCocoa");
2787 [
self setNeedsDisplay : YES];
2790 #pragma mark - Event handling. 2793 - (
void) mouseDown : (NSEvent *) theEvent
2795 assert(
fID != 0 &&
"-mouseDown:, fID is 0");
2798 "-mouseDown:, gVirtualX is either null or has a type, different from TGCocoa");
2804 - (
void) scrollWheel : (NSEvent*) theEvent
2806 assert(
fID != 0 &&
"-scrollWheel:, fID is 0");
2810 "-scrollWheel:, gVirtualX is either null or has a type, different from TGCocoa");
2813 const CGFloat deltaY = [theEvent deltaY];
2817 }
else if (deltaY > 0) {
2823 #ifdef DEBUG_ROOT_COCOA 2825 - (
void) printViewInformation
2827 assert(
fID != 0 &&
"-printWindowInformation, fID is 0");
2829 assert(window != 0 &&
"printWindowInformation, window not found");
2831 NSLog(
@"-----------------View %u info:---------------------",
fID);
2832 NSLog(
@"ROOT's window class is %s", window->IsA()->
GetName());
2833 NSLog(
@"event mask is:");
2835 NSLog(
@"grab mask is:");
2837 NSLog(
@"view's geometry: x == %g, y == %g, w == %g, h == %g",
self.frame.origin.x,
2838 self.frame.origin.y,
self.frame.size.width,
self.frame.size.height);
2839 NSLog(
@"----------------End of view info------------------");
2844 - (
void) rightMouseDown : (NSEvent *) theEvent
2846 assert(
fID != 0 &&
"-rightMouseDown:, fID is 0");
2848 #ifdef DEBUG_ROOT_COCOA 2849 [
self printViewInformation];
2853 "-rightMouseDown:, gVirtualX is either null or has type different from TGCocoa");
2859 - (
void) otherMouseDown : (NSEvent *) theEvent
2861 assert(
fID != 0 &&
"-otherMouseDown:, fID is 0");
2865 if ([theEvent buttonNumber] == 2) {
2869 "-otherMouseDown:, gVirtualX is either null or has type different from TGCocoa");
2876 - (
void) mouseUp : (NSEvent *) theEvent
2878 assert(
fID != 0 &&
"-mouseUp:, fID is 0");
2881 "-mouseUp:, gVirtualX is either null or has type different from TGCocoa");
2887 - (
void) rightMouseUp : (NSEvent *) theEvent
2890 assert(
fID != 0 &&
"-rightMouseUp:, fID is 0");
2893 "-rightMouseUp:, gVirtualX is either null or has type different from TGCocoa");
2900 - (
void) otherMouseUp : (NSEvent *) theEvent
2902 assert(
fID != 0 &&
"-otherMouseUp:, fID is 0");
2906 "-otherMouseUp:, gVirtualX is either null or has type different from TGCocoa");
2912 - (
void) mouseEntered : (NSEvent *) theEvent
2914 assert(
fID != 0 &&
"-mouseEntered:, fID is 0");
2916 "-mouseEntered:, gVirtualX is null or not of TGCocoa type");
2923 - (
void) mouseExited : (NSEvent *) theEvent
2925 assert(
fID != 0 &&
"-mouseExited:, fID is 0");
2928 "-mouseExited:, gVirtualX is null or not of TGCocoa type");
2935 - (
void) mouseMoved : (NSEvent *) theEvent
2937 assert(
fID != 0 &&
"-mouseMoved:, fID is 0");
2943 "-mouseMoved:, gVirtualX is null or not of TGCocoa type");
2950 - (
void) mouseDragged : (NSEvent *) theEvent
2952 assert(
fID != 0 &&
"-mouseDragged:, fID is 0");
2955 assert(vx != 0 &&
"-mouseDragged:, gVirtualX is null or not of TGCocoa type");
2961 - (
void) rightMouseDragged : (NSEvent *) theEvent
2963 assert(
fID != 0 &&
"-rightMouseDragged:, fID is 0");
2966 "-rightMouseDragged:, gVirtualX is null or not of TGCocoa type");
2973 - (
void) otherMouseDragged : (NSEvent *) theEvent
2975 assert(
fID != 0 &&
"-otherMouseDragged:, fID is 0");
2977 if ([theEvent buttonNumber] == 2) {
2979 "-otherMouseDragged:, gVirtualX is null or not of TGCocoa type");
2986 - (
void) keyDown : (NSEvent *) theEvent
2988 assert(
fID != 0 &&
"-keyDown:, fID is 0");
2991 "-keyDown:, gVirtualX is null or not of TGCocoa type");
2993 NSView<X11Window> *eventView =
self;
2995 eventView = pointerView;
3002 - (
void) keyUp : (NSEvent *) theEvent
3004 assert(
fID != 0 &&
"-keyUp:, fID is 0");
3007 "-keyUp:, gVirtualX is null or not of TGCocoa type");
3010 NSView<X11Window> *eventView =
self;
3012 eventView = pointerView;
3017 #pragma mark - First responder stuff. 3020 - (BOOL) acceptsFirstMouse : (NSEvent *) theEvent
3022 #pragma unused(theEvent) 3027 - (BOOL) acceptsFirstResponder
3032 #pragma mark - Cursors. 3039 [
self.fQuartzWindow invalidateCursorRectsForView : self];
3044 - (NSCursor *) createCustomCursor
3046 const char *pngFileName = 0;
3050 pngFileName =
"move_cursor.png";
3053 pngFileName =
"hor_arrow_cursor.png";
3056 pngFileName =
"ver_arrow_cursor.png";
3059 pngFileName =
"right_arrow_cursor.png";
3062 pngFileName =
"rotate.png";
3066 pngFileName =
"top_right_cursor.png";
3070 pngFileName =
"top_left_cursor.png";
3077 const Util::ScopedArray<const char> arrayGuard(path);
3079 if (!path || path[0] == 0) {
3084 NSString *nsPath = [NSString stringWithFormat : @"%s", path];
3085 NSImage *
const cursorImage = [[NSImage alloc] initWithContentsOfFile : nsPath];
3091 NSCursor *
const customCursor = [[[NSCursor alloc] initWithImage : cursorImage
3092 hotSpot : hotSpot] autorelease];
3094 [cursorImage release];
3096 return customCursor;
3103 - (
void) resetCursorRects
3106 [
self addCursorRect :
self.visibleRect cursor : cursor];
3110 - (
void) cursorUpdate
3120 - (
void) cursorUpdate : (NSEvent *)
event 3122 #pragma unused(event) 3134 [
self performSelector : @selector(cursorUpdate) withObject : nil afterDelay : 0.05f];
3137 #pragma mark - Emulated X11 properties. 3140 - (
void) setProperty : (const
char *) propName data : (
unsigned char *) propData
3141 size : (
unsigned) dataSize forType : (
Atom_t) dataType format : (
unsigned) format
3143 assert(propName != 0 &&
"-setProperty:data:size:forType:, parameter 'propName' is null");
3144 assert(propData != 0 &&
"-setProperty:data:size:forType:, parameter 'propData' is null");
3145 assert(dataSize != 0 &&
"-setProperty:data:size:forType:, parameter 'dataSize' is 0");
3147 NSString *
const key = [NSString stringWithCString : propName encoding : NSASCIIStringEncoding];
3148 QuartzWindowProperty *
property = (QuartzWindowProperty *)[
fX11Properties valueForKey : key];
3152 [property resetPropertyData : propData size : dataSize type : dataType format : format];
3155 property = [[QuartzWindowProperty alloc] initWithData : propData size : dataSize
3156 type : dataType format : format];
3163 - (BOOL) hasProperty : (const
char *) propName
3165 assert(propName != 0 &&
"-hasProperty:, propName parameter is null");
3167 NSString *
const key = [NSString stringWithCString : propName encoding : NSASCIIStringEncoding];
3168 QuartzWindowProperty *
const property = (QuartzWindowProperty *)[
fX11Properties valueForKey : key];
3170 return property != nil;
3174 - (
unsigned char *) getProperty : (const
char *) propName returnType : (
Atom_t *) type
3175 returnFormat : (
unsigned *) format nElements : (
unsigned *) nElements
3178 "-getProperty:returnType:returnFormat:nElements:, parameter 'propName' is null");
3180 "-getProperty:returnType:returnFormat:nElements:, parameter 'type' is null");
3182 "-getProperty:returnType:returnFormat:nElements:, parameter 'format' is null");
3184 "-getProperty:returnType:returnFormat:nElements:, parameter 'nElements' is null");
3186 NSString *
const key = [NSString stringWithCString : propName encoding : NSASCIIStringEncoding];
3187 QuartzWindowProperty *
const property = (QuartzWindowProperty *)[
fX11Properties valueForKey : key];
3189 "-getProperty:returnType:returnFormat:nElements, property not found");
3191 NSData *
const propData =
property.fPropertyData;
3193 const NSUInteger dataSize = [propData length];
3194 unsigned char *buff = 0;
3196 buff =
new unsigned char[dataSize]();
3197 }
catch (
const std::bad_alloc &) {
3199 NSLog(
@"QuartzWindow: -getProperty:returnType:returnFormat:nElements:," 3200 " memory allocation failed");
3204 [propData getBytes : buff length : dataSize];
3205 *
format =
property.fFormat;
3207 *nElements = dataSize;
3210 *nElements= dataSize / 2;
3212 *nElements = dataSize / 4;
3214 *
type =
property.fType;
3220 - (
void) removeProperty : (const
char *) propName
3222 assert(propName != 0 &&
"-removeProperty:, parameter 'propName' is null");
3224 NSString *
const key = [NSString stringWithCString : propName
3225 encoding : NSASCIIStringEncoding];
3231 - (NSDragOperation) draggingEntered : (
id<NSDraggingInfo>) sender
3233 NSPasteboard *
const pasteBoard = [sender draggingPasteboard];
3234 const NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
3236 if ([[pasteBoard types] containsObject : NSFilenamesPboardType] && (sourceDragMask & NSDragOperationCopy))
3237 return NSDragOperationCopy;
3239 return NSDragOperationNone;
3243 - (BOOL) performDragOperation : (
id<NSDraggingInfo>) sender
3254 NSPasteboard *
const pasteBoard = [sender draggingPasteboard];
3255 const NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
3257 if ([[pasteBoard types] containsObject : NSFilenamesPboardType] && (sourceDragMask & NSDragOperationCopy)) {
3263 NSArray *
const files = [pasteBoard propertyListForType : NSFilenamesPboardType];
3264 for (NSString *path in files) {
3266 NSString *
const item = [@"file://" stringByAppendingString : path];
3268 const NSUInteger len = [item lengthOfBytesUsingEncoding : NSASCIIStringEncoding] + 1;
3270 std::vector<unsigned char> propertyData(len);
3271 [item getCString : (char *)&propertyData[0] maxLength : propertyData.size()
3272 encoding : NSASCIIStringEncoding];
3274 NSView<X11Window> *
const targetView =
self.fQuartzWindow.fContentView;
3275 [targetView setProperty : "_XC_DND_DATA" data : &propertyData[0]
3276 size : propertyData.size() forType : textUriAtom format : 8];
3277 }
catch (
const std::bad_alloc &) {
3279 NSLog(
@"QuartzView: -performDragOperation:, memory allocation failed");
3295 event1.
fUser[2] = textUriAtom;
3305 event2.
fUser[2] = 0;
3306 NSPoint dropPoint = [sender draggingLocation];
3309 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)
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)
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 Mask_t kWABackingPlanes
int GlobalXROOTToCocoa(CGFloat xROOT)
const Mask_t kButtonPressMask
NSView< X11Window > * FindViewUnderPointer()
NSPoint TranslateToScreen(NSView< X11Window > *from, NSPoint point)
NSView< X11Window > * FrameForTextView(NSView< X11Window > *textView)
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 Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
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 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
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)