16 #ifdef DEBUG_ROOT_COCOA 28 #include <Availability.h> 36 #include "RConfigure.h" 49 #pragma mark - Create a window or a view. 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;
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";
824 if (!path || path[0] == 0) {
829 NSString *nsPath = [NSString stringWithFormat :
@"%s", path];
830 NSImage *
const cursorImage = [[NSImage alloc] initWithContentsOfFile : nsPath];
836 NSCursor *
const customCursor = [[[NSCursor alloc] initWithImage : cursorImage
837 hotSpot : hotSpot] autorelease];
839 [cursorImage release];
859 NSCursor *cursor = nil;
860 switch (currentCursor) {
862 cursor = [NSCursor crosshairCursor];
865 cursor = [NSCursor arrowCursor];
868 cursor = [NSCursor openHandCursor];
871 cursor = [NSCursor resizeLeftCursor];
874 cursor = [NSCursor resizeRightCursor];
877 cursor = [NSCursor resizeUpCursor];
880 cursor = [NSCursor resizeDownCursor];
883 cursor = [NSCursor IBeamCursor];
905 #pragma mark - Workarounds for a text view and its descendants. 919 assert(view != nil &&
"ViewIsTextView, parameter 'view' is nil");
927 assert(view != nil &&
"ViewIsTextViewFrame, parameter 'view' is nil");
939 if (!view.fParentView)
957 assert(view != nil &&
"ViewIsHtmlView, parameter 'view' is nil");
966 assert(view != nil &&
"ViewIsHtmlViewFrame, parameter 'view' is nil");
978 if (!view.fParentView)
987 assert(textView != nil &&
"FrameForTextView, parameter 'textView' is nil");
989 for (NSView<X11Window> *child in [textView subviews]) {
1000 assert(htmlView != nil &&
"FrameForHtmlView, parameter 'htmlView' is nil");
1002 for (NSView<X11Window> *child in [htmlView subviews]) {
1010 #pragma mark - Workarounds for 'paint out of paint events'. 1015 assert(view != nil &&
"LockFocus, parameter 'view' is nil");
1016 assert([view isKindOfClass : [
QuartzView class]] &&
1017 "LockFocus, QuartzView is expected");
1019 if ([view lockFocusIfCanDraw]) {
1020 NSGraphicsContext *nsContext = [NSGraphicsContext currentContext];
1021 assert(nsContext != nil &&
"LockFocus, currentContext is nil");
1022 CGContextRef currContext = (CGContextRef)[nsContext graphicsPort];
1023 assert(currContext != 0 &&
"LockFocus, graphicsPort is null");
1036 assert(view != nil &&
"UnlockFocus, parameter 'view' is nil");
1037 assert([view isKindOfClass : [
QuartzView class]] &&
1038 "UnlockFocus, QuartzView is expected");
1053 #ifdef DEBUG_ROOT_COCOA 1055 #pragma mark - 'loggers'. 1065 static std::ofstream logfile(
"win_attr.txt");
1069 logfile<<
"win "<<winID<<
": BackPixmap\n";
1071 logfile<<
"win "<<winID<<
": BackPixel\n";
1073 logfile<<
"win "<<winID<<
": BorderPixmap\n";
1075 logfile<<
"win "<<winID<<
": BorderPixel\n";
1077 logfile<<
"win "<<winID<<
": BorderWidth\n";
1079 logfile<<
"win "<<winID<<
": BitGravity\n";
1081 logfile<<
"win "<<winID<<
": WinGravity\n";
1083 logfile<<
"win "<<winID<<
": BackingStore\n";
1085 logfile<<
"win "<<winID<<
": BackingPlanes\n";
1087 logfile<<
"win "<<winID<<
": BackingPixel\n";
1089 logfile<<
"win "<<winID<<
": OverrideRedirect\n";
1091 logfile<<
"win "<<winID<<
": SaveUnder\n";
1093 logfile<<
"win "<<winID<<
": EventMask\n";
1095 logfile<<
"win "<<winID<<
": DontPropagate\n";
1097 logfile<<
"win "<<winID<<
": Colormap\n";
1099 logfile<<
"win "<<winID<<
": Cursor\n";
1103 void print_mask_info(
ULong_t mask)
1106 NSLog(
@"button press mask");
1108 NSLog(
@"button release mask");
1110 NSLog(
@"exposure mask");
1112 NSLog(
@"pointer motion mask");
1114 NSLog(
@"button motion mask");
1116 NSLog(
@"enter notify mask");
1118 NSLog(
@"leave notify mask");
1130 #pragma mark - QuartzWindow's life cycle. 1133 - (
id) initWithContentRect : (NSRect) contentRect styleMask : (NSUInteger) windowStyle
1134 backing : (NSBackingStoreType) bufferingType defer : (BOOL) deferCreation
1137 self = [
super initWithContentRect : contentRect styleMask : windowStyle
1138 backing : bufferingType defer : deferCreation];
1142 [
self setAllowsConcurrentViewDrawing : NO];
1144 self.delegate =
self;
1146 NSRect contentViewRect = contentRect;
1147 contentViewRect.origin.x = 0.f;
1148 contentViewRect.origin.y = 0.f;
1154 [
self setContentView : fContentView];
1174 assert(glView != nil &&
"-initWithGLView, parameter 'glView' is nil");
1179 NSRect contentRect = glView.frame;
1180 contentRect.origin = NSPoint();
1182 self = [
super initWithContentRect : contentRect styleMask : styleMask
1183 backing : NSBackingStoreBuffered defer : NO];
1187 [
self setAllowsConcurrentViewDrawing : NO];
1188 self.delegate =
self;
1190 [
self setContentView : fContentView];
1213 - (
void) setContentView:(NSView *)cv
1215 [
super setContentView:cv];
1223 - (
void) setFIsDeleted : (BOOL) deleted
1228 #pragma mark - Forwaring: I want to forward a lot of property setters/getters to the content view. 1231 - (
void) forwardInvocation : (NSInvocation *) anInvocation
1236 if ([
fContentView respondsToSelector : [anInvocation selector]]) {
1237 [anInvocation invokeWithTarget : fContentView];
1239 [
super forwardInvocation : anInvocation];
1244 - (NSMethodSignature*) methodSignatureForSelector : (
SEL) selector
1246 NSMethodSignature *signature = [
super methodSignatureForSelector : selector];
1250 signature = [
fContentView methodSignatureForSelector : selector];
1265 assert(window != nil &&
"-addTransientWindow:, parameter 'window' is nil");
1274 [
self addChildWindow : window ordered : NSWindowAbove];
1280 - (
void) makeKeyAndOrderFront : (
id) sender
1282 #pragma unused(sender) 1287 #ifdef MAC_OS_X_VERSION_10_9 1288 [
self setCollectionBehavior : NSWindowCollectionBehaviorMoveToActiveSpace];
1290 [
self setCollectionBehavior : NSWindowCollectionBehaviorCanJoinAllSpaces];
1293 [
super makeKeyAndOrderFront : self];
1295 [
self setCollectionBehavior : NSWindowCollectionBehaviorDefault];
1299 - (
void) setFDelayedTransient : (BOOL) d
1323 #pragma mark - X11Drawable's protocol. 1354 return self.frame.size.width;
1363 assert(
fContentView != nil &&
"-fHeight:, content view is nil");
1369 - (
void) setDrawableSize : (NSSize) newSize
1372 assert(!(newSize.width < 0) &&
"-setDrawableSize:, width is negative");
1373 assert(!(newSize.height < 0) &&
"-setDrawableSize:, height is negative");
1375 NSRect frame =
self.frame;
1379 frame.origin.y = frame.origin.y + frame.size.height - newSize.height - dY;
1380 frame.size = newSize;
1381 frame.size.height += dY;
1382 [
self setFrame : frame display : YES];
1386 - (
void) setX : (
int) x Y : (
int) y width : (
unsigned) w height : (
unsigned) h
1388 NSSize newSize = {};
1391 [
self setContentSize : newSize];
1394 NSPoint topLeft = {};
1398 [
self setFrameTopLeftPoint : topLeft];
1402 - (
void) setX : (
int) x Y : (
int) y
1404 NSPoint topLeft = {};
1408 [
self setFrameTopLeftPoint : topLeft];
1413 clipOrigin : (
X11::Point) clipXY toPoint : (
X11::Point) dstPoint
1418 [
fContentView copy : src area : area withMask : mask clipOrigin : clipXY toPoint : dstPoint];
1422 - (
unsigned char *) readColorBits : (
X11::Rectangle) area
1430 #pragma mark - X11Window protocol's implementation. 1441 #pragma unused(parent) 1459 - (
void) setFBackgroundPixel : (
unsigned long) backgroundColor
1465 CGFloat rgba[] = {0., 0., 0., 1.};
1468 [
self setBackgroundColor : [NSColor colorWithColorSpace : [NSColorSpace deviceRGBColorSpace] components : rgba count : 4]];
1497 - (
void) addChild : (NSView<X11Window> *) child
1499 assert(child != nil &&
"-addChild:, parameter 'child' is nil");
1503 assert([child isKindOfClass : [
QuartzView class]] &&
1504 "-addChild: gl view in a top-level window as content view is not supported");
1507 [
self setContentView : child];
1519 assert(attr &&
"-getAttributes:, parameter 'attr' is nil");
1527 assert(attr != 0 &&
"-setAttributes:, parameter 'attr' is null");
1529 #ifdef DEBUG_ROOT_COCOA 1530 log_attributes(attr,
self.fID);
1542 const Util::AutoreleasePool pool;
1545 [
self makeKeyAndOrderFront : self];
1550 [
fMainWindow addChildWindow : self ordered : NSWindowAbove];
1560 const Util::AutoreleasePool pool;
1563 [
self makeKeyAndOrderFront : self];
1568 [
fMainWindow addChildWindow : self ordered : NSWindowAbove];
1578 const Util::AutoreleasePool pool;
1591 [
self orderOut : self];
1599 #pragma mark - Events. 1602 - (
void) sendEvent : (NSEvent *) theEvent
1612 bool generateFakeRelease =
false;
1614 const NSPoint windowPoint = [theEvent locationInWindow];
1616 if (windowPoint.x <= 4 || windowPoint.x >=
self.fWidth - 4)
1617 generateFakeRelease =
true;
1619 if (windowPoint.y <= 4 || windowPoint.y >=
self.fHeight - 4)
1620 generateFakeRelease =
true;
1622 const NSPoint viewPoint = [
fContentView convertPoint : windowPoint fromView : nil];
1624 if (viewPoint.y <= 0 && windowPoint.y >= 0)
1625 generateFakeRelease =
true;
1627 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
1628 "-sendEvent:, gVirtualX is either null or not of TGCocoa type");
1642 [
super sendEvent : theEvent];
1645 #pragma mark - NSWindowDelegate's methods. 1648 - (BOOL) windowShouldClose : (
id) sender
1650 #pragma unused(sender) 1659 if ([[
self childWindows] count])
1670 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
1671 "-windowShouldClose:, gVirtualX is either null or has a type different from TGCocoa");
1680 - (
void) windowDidBecomeKey : (NSNotification *) aNotification
1682 #pragma unused(aNotification) 1690 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
1691 "-windowDidBecomeKey:, gVirtualX is null or not of TGCocoa type");
1699 - (
void) windowDidResignKey : (NSNotification *) aNotification
1701 #pragma unused(aNotification) 1707 #pragma mark - Passive key grab info. 1712 - (
id) initWithKey : (unichar) keyCode modifiers : (NSUInteger) modifiers
1714 if (
self = [super
init]) {
1723 - (BOOL) matchKey : (unichar) keyCode modifiers : (NSUInteger) modifiers
1729 - (BOOL) matchKey : (unichar) keyCode
1748 #pragma mark - X11 property emulation. 1750 @interface QuartzWindowProperty : NSObject {
1751 NSData *fPropertyData;
1760 @implementation QuartzWindowProperty
1767 if (
self = [super
init]) {
1769 fPropertyData = nil;
1773 [
self resetPropertyData : data size : dataSize type : type format : format];
1782 [fPropertyData release];
1788 - (
void) resetPropertyData : (
unsigned char *)
data size : (unsigned) dataSize
1791 [fPropertyData release];
1799 fPropertyData = [[NSData dataWithBytes : data length : dataSize] retain];
1805 - (NSData *) fPropertyData
1807 return fPropertyData;
1811 - (unsigned) fFormat
1818 #pragma mark - QuartzView. 1851 #pragma mark - Lifetime. 1856 if (
self = [super initWithFrame : frame]) {
1868 [
self setCanDrawConcurrently : NO];
1870 [
self setHidden : YES];
1897 #pragma mark - Tracking area. 1902 - (
void) updateTrackingAreas
1904 [
super updateTrackingAreas];
1909 const Util::AutoreleasePool pool;
1911 if (NSArray *trackingArray = [
self trackingAreas]) {
1912 const NSUInteger size = [trackingArray count];
1913 for (NSUInteger i = 0; i < size; ++i) {
1914 NSTrackingArea *
const t = [trackingArray objectAtIndex : i];
1915 [
self removeTrackingArea : t];
1919 const NSUInteger trackerOptions = NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited |
1920 NSTrackingActiveInActiveApp | NSTrackingInVisibleRect |
1921 NSTrackingEnabledDuringMouseDrag | NSTrackingCursorUpdate;
1924 frame.size.width =
self.fWidth;
1925 frame.size.height =
self.fHeight;
1927 NSTrackingArea *
const tracker = [[NSTrackingArea alloc] initWithRect : frame
1928 options : trackerOptions owner : self userInfo : nil];
1929 [
self addTrackingArea : tracker];
1934 - (
void) updateTrackingAreasAfterRaise
1936 [
self updateTrackingAreas];
1938 for (
QuartzView *childView in [
self subviews])
1939 [childView updateTrackingAreasAfterRaise];
1942 #pragma mark - X11Drawable protocol. 1959 return self.frame.origin.x;
1965 return self.frame.origin.y;
1971 return self.frame.size.width;
1977 return self.frame.size.height;
1981 - (
void) setDrawableSize : (NSSize) newSize
1983 assert(!(newSize.width < 0) &&
"-setDrawableSize, width is negative");
1984 assert(!(newSize.height < 0) &&
"-setDrawableSize, height is negative");
1990 NSRect frame =
self.frame;
1991 frame.size = newSize;
1997 - (
void) setX : (
int) x Y : (
int) y width : (
unsigned) w height : (
unsigned) h
1999 NSRect newFrame = {};
2000 newFrame.origin.x =
x;
2001 newFrame.origin.y =
y;
2002 newFrame.size.width = w;
2003 newFrame.size.height =
h;
2005 self.frame = newFrame;
2009 - (
void) setX : (
int) x Y : (
int) y
2011 NSRect newFrame =
self.frame;
2012 newFrame.origin.x =
x;
2013 newFrame.origin.y =
y;
2015 self.frame = newFrame;
2024 assert(srcImage != nil &&
2025 "-copyImage:area:withMask:clipOrigin:toPoint:, parameter 'srcImage' is nil");
2026 assert(srcImage.fImage != nil &&
2027 "-copyImage:area:withMask:clipOrigin:toPoint:, srcImage.fImage is nil");
2031 "-copyImage:area:withMask:clipOrigin:toPoint:, self.fContext is null");
2034 NSLog(
@"QuartzView: -copyImage:area:withMask:clipOrigin:toPoint:," 2035 " srcRect and copyRect do not intersect");
2041 CGImageRef subImage = 0;
2042 bool needSubImage =
false;
2043 if (area.fX || area.fY || area.fWidth != srcImage.fWidth || area.fHeight != srcImage.fHeight) {
2044 needSubImage =
true;
2047 NSLog(
@"QuartzView: -copyImage:area:withMask:clipOrigin:toPoint:," 2048 " subimage creation failed");
2052 subImage = srcImage.fImage;
2059 CGContextScaleCTM(
self.
fContext, 1., -1.);
2063 assert(mask.
fImage != nil &&
2064 "-copyImage:area:withMask:clipOrigin:toPoint:, mask.fImage is nil");
2065 assert(CGImageIsMask(mask.
fImage) ==
true &&
2066 "-copyImage:area:withMask:clipOrigin:toPoint:, mask.fImage is not a mask");
2070 const CGRect clipRect = CGRectMake(clipXY.fX, clipY, mask.
fWidth, mask.
fHeight);
2078 const CGRect imageRect = CGRectMake(dstPoint.fX, dstY, area.fWidth, area.fHeight);
2079 CGContextDrawImage(
self.
fContext, imageRect, subImage);
2082 CGImageRelease(subImage);
2093 assert(srcView != nil &&
"-copyView:area:toPoint:, parameter 'srcView' is nil");
2095 const NSRect frame = [srcView frame];
2097 NSBitmapImageRep *
const imageRep = [srcView bitmapImageRepForCachingDisplayInRect : frame];
2099 NSLog(
@"QuartzView: -copyView:area:toPoint failed");
2103 assert(srcView != nil &&
"-copyView:area:toPoint:, parameter 'srcView' is nil");
2104 assert(
self.
fContext != 0 &&
"-copyView:area:toPoint, self.fContext is null");
2109 CGContextRef ctx = srcView.fContext;
2110 srcView.fSnapshotDraw = YES;
2111 [srcView cacheDisplayInRect : frame toBitmapImageRep : imageRep];
2112 srcView.fSnapshotDraw = NO;
2113 srcView.fContext = ctx;
2115 const CGRect subImageRect = CGRectMake(area.fX, area.fY, area.fWidth, area.fHeight);
2116 const Util::CFScopeGuard<CGImageRef> subImage(CGImageCreateWithImageInRect(imageRep.CGImage, subImageRect));
2118 if (!subImage.Get()) {
2119 NSLog(
@"QuartzView: -copyView:area:toPoint, CGImageCreateWithImageInRect failed");
2124 const CGRect imageRect = CGRectMake(dstPoint.fX,
2125 [
self visibleRect].size.height - (CGFloat(dstPoint.fY) + area.fHeight),
2126 area.fWidth, area.fHeight);
2128 CGContextTranslateCTM(
self.
fContext, 0., [
self visibleRect].size.height);
2129 CGContextScaleCTM(
self.
fContext, 1., -1.);
2131 CGContextDrawImage(
self.
fContext, imageRect, subImage.Get());
2139 assert(srcPixmap != nil &&
"-copyPixmap:area:withMask:clipOrigin:toPoint:, parameter 'srcPixmap' is nil");
2142 NSLog(
@"QuartzView: -copyPixmap:area:withMask:clipOrigin:toPoint," 2143 " no intersection between pixmap rectangle and cropArea");
2149 "-copyPixmap:area:withMask:clipOrigin:toPoint:, self.fContext is null");
2154 CGContextTranslateCTM(
self.
fContext, 0.,
self.frame.size.height);
2155 CGContextScaleCTM(
self.
fContext, 1., -1.);
2157 const Util::CFScopeGuard<CGImageRef> imageFromPixmap([srcPixmap createImageFromPixmap]);
2158 assert(imageFromPixmap.Get() != 0 &&
2159 "-copyPixmap:area:withMask:clipOrigin:toPoint:, createImageFromPixmap failed");
2161 CGImageRef subImage = 0;
2162 bool needSubImage =
false;
2163 if (area.fX || area.fY || area.fWidth != srcPixmap.fWidth || area.fHeight != srcPixmap.fHeight) {
2164 needSubImage =
true;
2165 const CGRect subImageRect = CGRectMake(area.fX, area.fY, area.fHeight, area.fWidth);
2166 subImage = CGImageCreateWithImageInRect(imageFromPixmap.Get(), subImageRect);
2168 NSLog(
@"QuartzView: -copyImage:area:withMask:clipOrigin:toPoint:," 2169 " subimage creation failed");
2173 subImage = imageFromPixmap.Get();
2176 assert(mask.
fImage != nil &&
2177 "-copyPixmap:area:withMask:clipOrigin:toPoint:, mask.fImage is nil");
2178 assert(CGImageIsMask(mask.
fImage) ==
true &&
2179 "-copyPixmap:area:withMask:clipOrigin:toPoint:, mask.fImage is not a mask");
2184 const CGRect clipRect = CGRectMake(clipXY.fX, clipY, mask.
fWidth, mask.
fHeight);
2190 const CGRect imageRect = CGRectMake(dstPoint.fX, dstY, area.fWidth, area.fHeight);
2191 CGContextDrawImage(
self.
fContext, imageRect, imageFromPixmap.Get());
2194 CGImageRelease(subImage);
2202 assert(srcImage != nil &&
"-copyImage:area:toPoint:, parameter 'srcImage' is nil");
2203 assert(srcImage.fImage != nil &&
"-copyImage:area:toPoint:, srcImage.fImage is nil");
2204 assert(
self.
fContext != 0 &&
"-copyImage:area:toPoint:, fContext is null");
2207 NSLog(
@"QuartzView: -copyImage:area:toPoint, image and copy area do not intersect");
2211 CGImageRef subImage = 0;
2212 bool needSubImage =
false;
2213 if (area.fX || area.fY || area.fWidth != srcImage.fWidth || area.fHeight != srcImage.fHeight) {
2214 needSubImage =
true;
2217 NSLog(
@"QuartzView: -copyImage:area:toPoint:, subimage creation failed");
2221 subImage = srcImage.fImage;
2226 CGContextScaleCTM(
self.
fContext, 1., -1.);
2231 const CGRect imageRect = CGRectMake(dstPoint.fX, dstY, area.fWidth, area.fHeight);
2232 CGContextDrawImage(
self.
fContext, imageRect, subImage);
2235 CGImageRelease(subImage);
2240 withMask : (
QuartzImage *)mask clipOrigin : (
X11::Point) clipXY toPoint : (
X11::Point) dstPoint
2242 assert(src != nil &&
"-copy:area:withMask:clipOrigin:toPoint:, parameter 'src' is nil");
2243 assert(area.fWidth && area.fHeight &&
"-copy:area:withMask:clipOrigin:toPoint:, area to copy is empty");
2249 [
self copyView : (QuartzView *)qw.fContentView area : area toPoint : dstPoint];
2250 }
else if ([src isKindOfClass : [
QuartzView class]]) {
2252 [
self copyView : (QuartzView *)src area : area toPoint : dstPoint];
2253 }
else if ([src isKindOfClass : [
QuartzPixmap class]]) {
2254 [
self copyPixmap : (QuartzPixmap *)src area : area withMask : mask clipOrigin : clipXY toPoint : dstPoint];
2255 }
else if ([src isKindOfClass : [
QuartzImage class]]) {
2256 [
self copyImage : (QuartzImage *)src area : area withMask : mask clipOrigin : clipXY toPoint : dstPoint];
2258 assert(0 &&
"-copy:area:withMask:clipOrigin:toPoint:, src is of unknown type");
2263 - (
unsigned char *) readColorBits : (
X11::Rectangle) area
2269 assert(area.fWidth && area.fHeight &&
"-readColorBits:, area to copy is empty");
2272 const NSRect visRect = [
self visibleRect];
2273 const X11::Rectangle srcRect(
int(visRect.origin.x),
int(visRect.origin.y),
2274 unsigned(visRect.size.width),
unsigned(visRect.size.height));
2277 NSLog(
@"QuartzView: -readColorBits:, visible rect of view and copy area do not intersect");
2282 NSBitmapImageRep *
const imageRep = [
self bitmapImageRepForCachingDisplayInRect : visRect];
2284 NSLog(
@"QuartzView: -readColorBits:, bitmapImageRepForCachingDisplayInRect failed");
2288 CGContextRef ctx =
self.fContext;
2289 [
self cacheDisplayInRect : visRect toBitmapImageRep : imageRep];
2290 self.fContext = ctx;
2292 const NSInteger bitsPerPixel = [imageRep bitsPerPixel];
2294 assert(bitsPerPixel == 32 &&
"-readColorBits:, no alpha channel???");
2295 const NSInteger bytesPerRow = [imageRep bytesPerRow];
2296 unsigned dataWidth = bytesPerRow / (bitsPerPixel / 8);
2298 unsigned char *srcData =
nullptr;
2299 std::vector<unsigned char> downscaled;
2300 if ([[NSScreen mainScreen] backingScaleFactor] > 1 && imageRep.CGImage) {
2302 if (downscaled.size())
2303 srcData = &downscaled[0];
2304 dataWidth = area.fWidth;
2306 srcData = [imageRep bitmapData];
2309 NSLog(
@"QuartzView: -readColorBits:, failed to obtain backing store contents");
2314 unsigned char *
data =
nullptr;
2317 data =
new unsigned char[area.fWidth * area.fHeight * 4];
2318 }
catch (
const std::bad_alloc &) {
2319 NSLog(
@"QuartzView: -readColorBits:, memory allocation failed");
2323 unsigned char *dstPixel =
data;
2324 const unsigned char *
line = srcData + area.fY * dataWidth * 4;
2325 const unsigned char *srcPixel =
line + area.fX * 4;
2327 for (
unsigned i = 0; i < area.fHeight; ++i) {
2328 for (
unsigned j = 0; j < area.fWidth; ++j, srcPixel += 4, dstPixel += 4) {
2329 dstPixel[0] = srcPixel[2];
2330 dstPixel[1] = srcPixel[1];
2331 dstPixel[2] = srcPixel[0];
2332 dstPixel[3] = srcPixel[3];
2335 line += dataWidth * 4;
2336 srcPixel =
line + area.fX * 4;
2365 if ([
self isHidden])
2369 if ([parent isHidden])
2387 - (
void) setFHasFocus : (BOOL) focus
2389 #pragma unused(focus) 2440 - (
void) activateGrab : (
unsigned) eventMask ownerEvents : (BOOL) ownerEvents
2456 - (BOOL) acceptsCrossingEvents : (
unsigned) eventMask
2475 - (
void) addChild : (NSView<X11Window> *) child
2477 assert(child != nil &&
"-addChild:, parameter 'child' is nil");
2479 [
self addSubview : child];
2480 child.fParentView =
self;
2486 assert(attr != 0 &&
"-getAttributes:, parameter 'attr' is null");
2494 assert(attr != 0 &&
"-setAttributes:, parameter 'attr' is null");
2496 #ifdef DEBUG_ROOT_COCOA 2497 log_attributes(attr,
fID);
2508 [
self removeFromSuperview];
2509 [parent addSubview : self];
2510 [
self setHidden : NO];
2516 [
self setHidden : NO];
2529 [
self setHidden : YES];
2539 - (
void) setOverlapped : (BOOL) overlap
2542 for (NSView<X11Window> *child in [
self subviews])
2543 [child setOverlapped : overlap];
2560 using namespace X11;
2563 if (
self == sibling)
2565 if ([sibling isHidden])
2568 if (NSEqualRects(sibling.frame,
self.frame)) {
2569 [sibling setOverlapped : YES];
2570 [sibling setHidden : YES];
2576 [
self setHidden : NO];
2578 [
fParentView sortSubviewsUsingFunction : CompareViewsToRaise context : (void *)self];
2580 [
self updateTrackingAreasAfterRaise];
2582 [
self setNeedsDisplay : YES];
2590 using namespace X11;
2592 NSEnumerator *
const reverseEnumerator = [[
fParentView subviews] reverseObjectEnumerator];
2593 for (
QuartzView *sibling in reverseEnumerator) {
2594 if (sibling ==
self)
2598 if (NSEqualRects(sibling.frame,
self.frame)) {
2599 [sibling setOverlapped : NO];
2601 [sibling setHidden : NO];
2603 [sibling setNeedsDisplay : YES];
2606 [
self setHidden : YES];
2612 [
fParentView sortSubviewsUsingFunction : CompareViewsToLower context : (void*)self];
2628 assert(dynamic_cast<TGCocoa *>(
gVirtualX) &&
2629 "-configureNotifyTree, gVirtualX is either null or has type different from TGCocoa");
2634 for (NSView<X11Window> *
v in [
self subviews])
2635 [v configureNotifyTree];
2639 #pragma mark - Key grabs. 2642 - (
void) addPassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers
2644 [
self removePassiveKeyGrab : keyCode modifiers : modifiers];
2646 modifiers : modifiers];
2652 - (
void) removePassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers
2655 for (NSUInteger i = 0; i < count; ++i) {
2657 if ([grab matchKey : keyCode modifiers : modifiers]) {
2665 - (
PassiveKeyGrab *) findPassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers
2669 if ([grab matchKey : keyCode modifiers : modifiers])
2682 if ([grab matchKey : keyCode])
2689 #pragma mark - Painting mechanics. 2692 - (
void) drawRect : (NSRect) dirtyRect
2694 #pragma unused(dirtyRect) 2696 using namespace X11;
2704 NSGraphicsContext *
const nsContext = [NSGraphicsContext currentContext];
2705 assert(nsContext != nil &&
"-drawRect:, currentContext returned nil");
2710 fContext = (CGContextRef)[nsContext graphicsPort];
2711 assert(
fContext != 0 &&
"-drawRect:, graphicsPort returned null");
2719 if (window->InheritsFrom(
"TGContainer"))
2742 gClient->CancelRedraw(window);
2750 [
self copy : fBackBuffer area : copyArea withMask : nil
2751 clipOrigin : X11::Point() toPoint : X11::Point()];
2755 #ifdef DEBUG_ROOT_COCOA 2756 CGContextSetRGBStrokeColor(
fContext, 1., 0., 0., 1.);
2757 CGContextStrokeRect(
fContext, dirtyRect);
2762 #ifdef DEBUG_ROOT_COCOA 2763 NSLog(
@"QuartzView: -drawRect: method, no window for id %u was found",
fID);
2769 #pragma mark - Geometry. 2772 - (
void) setFrame : (NSRect) newFrame
2777 if (NSEqualRects(newFrame,
self.frame))
2780 [
super setFrame : newFrame];
2784 - (
void) setFrameSize : (NSSize) newSize
2788 [
super setFrameSize : newSize];
2791 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2792 "setFrameSize:, gVirtualX is either null or has a type, different from TGCocoa");
2797 [
self setNeedsDisplay : YES];
2800 #pragma mark - Event handling. 2803 - (
void) mouseDown : (NSEvent *) theEvent
2805 assert(
fID != 0 &&
"-mouseDown:, fID is 0");
2807 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2808 "-mouseDown:, gVirtualX is either null or has a type, different from TGCocoa");
2814 - (
void) scrollWheel : (NSEvent*) theEvent
2816 assert(
fID != 0 &&
"-scrollWheel:, fID is 0");
2819 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2820 "-scrollWheel:, gVirtualX is either null or has a type, different from TGCocoa");
2823 const CGFloat deltaY = [theEvent deltaY];
2827 }
else if (deltaY > 0) {
2833 #ifdef DEBUG_ROOT_COCOA 2835 - (
void) printViewInformation
2837 assert(
fID != 0 &&
"-printWindowInformation, fID is 0");
2839 assert(window != 0 &&
"printWindowInformation, window not found");
2841 NSLog(
@"-----------------View %u info:---------------------",
fID);
2842 NSLog(
@"ROOT's window class is %s", window->IsA()->
GetName());
2843 NSLog(
@"event mask is:");
2845 NSLog(
@"grab mask is:");
2847 NSLog(
@"view's geometry: x == %g, y == %g, w == %g, h == %g",
self.frame.origin.x,
2848 self.frame.origin.y,
self.frame.size.width,
self.frame.size.height);
2849 NSLog(
@"----------------End of view info------------------");
2854 - (
void) rightMouseDown : (NSEvent *) theEvent
2856 assert(
fID != 0 &&
"-rightMouseDown:, fID is 0");
2858 #ifdef DEBUG_ROOT_COCOA 2859 [
self printViewInformation];
2862 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2863 "-rightMouseDown:, gVirtualX is either null or has type different from TGCocoa");
2869 - (
void) otherMouseDown : (NSEvent *) theEvent
2871 assert(
fID != 0 &&
"-otherMouseDown:, fID is 0");
2875 if ([theEvent buttonNumber] == 2) {
2878 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2879 "-otherMouseDown:, gVirtualX is either null or has type different from TGCocoa");
2886 - (
void) mouseUp : (NSEvent *) theEvent
2888 assert(
fID != 0 &&
"-mouseUp:, fID is 0");
2890 assert(dynamic_cast<TGCocoa *>(
gVirtualX) &&
2891 "-mouseUp:, gVirtualX is either null or has type different from TGCocoa");
2897 - (
void) rightMouseUp : (NSEvent *) theEvent
2900 assert(
fID != 0 &&
"-rightMouseUp:, fID is 0");
2902 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2903 "-rightMouseUp:, gVirtualX is either null or has type different from TGCocoa");
2910 - (
void) otherMouseUp : (NSEvent *) theEvent
2912 assert(
fID != 0 &&
"-otherMouseUp:, fID is 0");
2915 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2916 "-otherMouseUp:, gVirtualX is either null or has type different from TGCocoa");
2922 - (
void) mouseEntered : (NSEvent *) theEvent
2924 assert(
fID != 0 &&
"-mouseEntered:, fID is 0");
2925 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2926 "-mouseEntered:, gVirtualX is null or not of TGCocoa type");
2933 - (
void) mouseExited : (NSEvent *) theEvent
2935 assert(
fID != 0 &&
"-mouseExited:, fID is 0");
2937 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2938 "-mouseExited:, gVirtualX is null or not of TGCocoa type");
2945 - (
void) mouseMoved : (NSEvent *) theEvent
2947 assert(
fID != 0 &&
"-mouseMoved:, fID is 0");
2952 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2953 "-mouseMoved:, gVirtualX is null or not of TGCocoa type");
2960 - (
void) mouseDragged : (NSEvent *) theEvent
2962 assert(
fID != 0 &&
"-mouseDragged:, fID is 0");
2965 assert(vx != 0 &&
"-mouseDragged:, gVirtualX is null or not of TGCocoa type");
2971 - (
void) rightMouseDragged : (NSEvent *) theEvent
2973 assert(
fID != 0 &&
"-rightMouseDragged:, fID is 0");
2975 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2976 "-rightMouseDragged:, gVirtualX is null or not of TGCocoa type");
2983 - (
void) otherMouseDragged : (NSEvent *) theEvent
2985 assert(
fID != 0 &&
"-otherMouseDragged:, fID is 0");
2987 if ([theEvent buttonNumber] == 2) {
2988 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2989 "-otherMouseDragged:, gVirtualX is null or not of TGCocoa type");
2996 - (
void) keyDown : (NSEvent *) theEvent
2998 assert(
fID != 0 &&
"-keyDown:, fID is 0");
3000 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
3001 "-keyDown:, gVirtualX is null or not of TGCocoa type");
3003 NSView<X11Window> *eventView =
self;
3005 eventView = pointerView;
3012 - (
void) keyUp : (NSEvent *) theEvent
3014 assert(
fID != 0 &&
"-keyUp:, fID is 0");
3016 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
3017 "-keyUp:, gVirtualX is null or not of TGCocoa type");
3020 NSView<X11Window> *eventView =
self;
3022 eventView = pointerView;
3027 #pragma mark - First responder stuff. 3030 - (BOOL) acceptsFirstMouse : (NSEvent *) theEvent
3032 #pragma unused(theEvent) 3037 - (BOOL) acceptsFirstResponder
3042 #pragma mark - Cursors. 3049 [
self.fQuartzWindow invalidateCursorRectsForView : self];
3054 - (NSCursor *) createCustomCursor
3056 const char *pngFileName = 0;
3060 pngFileName =
"move_cursor.png";
3063 pngFileName =
"hor_arrow_cursor.png";
3066 pngFileName =
"ver_arrow_cursor.png";
3069 pngFileName =
"right_arrow_cursor.png";
3072 pngFileName =
"rotate.png";
3076 pngFileName =
"top_right_cursor.png";
3080 pngFileName =
"top_left_cursor.png";
3091 const Util::ScopedArray<const char> arrayGuard(path);
3093 if (!path || path[0] == 0) {
3098 NSString *nsPath = [NSString stringWithFormat : @"%s", path];
3099 NSImage *
const cursorImage = [[NSImage alloc] initWithContentsOfFile : nsPath];
3105 NSCursor *
const customCursor = [[[NSCursor alloc] initWithImage : cursorImage
3106 hotSpot : hotSpot] autorelease];
3108 [cursorImage release];
3110 return customCursor;
3117 - (
void) resetCursorRects
3120 [
self addCursorRect :
self.visibleRect cursor : cursor];
3124 - (
void) cursorUpdate
3134 - (
void) cursorUpdate : (NSEvent *)
event 3136 #pragma unused(event) 3148 [
self performSelector : @selector(cursorUpdate) withObject : nil afterDelay : 0.05f];
3151 #pragma mark - Emulated X11 properties. 3154 - (
void) setProperty : (const
char *) propName data : (
unsigned char *) propData
3155 size : (
unsigned) dataSize forType : (
Atom_t) dataType format : (
unsigned) format
3157 assert(propName != 0 &&
"-setProperty:data:size:forType:, parameter 'propName' is null");
3158 assert(propData != 0 &&
"-setProperty:data:size:forType:, parameter 'propData' is null");
3159 assert(dataSize != 0 &&
"-setProperty:data:size:forType:, parameter 'dataSize' is 0");
3161 NSString *
const key = [NSString stringWithCString : propName encoding : NSASCIIStringEncoding];
3162 QuartzWindowProperty *
property = (QuartzWindowProperty *)[
fX11Properties valueForKey : key];
3166 [property resetPropertyData : propData size : dataSize type : dataType format : format];
3169 property = [[QuartzWindowProperty alloc] initWithData : propData size : dataSize
3170 type : dataType format : format];
3177 - (BOOL) hasProperty : (const
char *) propName
3179 assert(propName != 0 &&
"-hasProperty:, propName parameter is null");
3181 NSString *
const key = [NSString stringWithCString : propName encoding : NSASCIIStringEncoding];
3182 QuartzWindowProperty *
const property = (QuartzWindowProperty *)[
fX11Properties valueForKey : key];
3184 return property != nil;
3188 - (
unsigned char *) getProperty : (const
char *) propName returnType : (
Atom_t *) type
3189 returnFormat : (
unsigned *) format nElements : (
unsigned *) nElements
3191 assert(propName != 0 &&
3192 "-getProperty:returnType:returnFormat:nElements:, parameter 'propName' is null");
3194 "-getProperty:returnType:returnFormat:nElements:, parameter 'type' is null");
3196 "-getProperty:returnType:returnFormat:nElements:, parameter 'format' is null");
3197 assert(nElements != 0 &&
3198 "-getProperty:returnType:returnFormat:nElements:, parameter 'nElements' is null");
3200 NSString *
const key = [NSString stringWithCString : propName encoding : NSASCIIStringEncoding];
3201 QuartzWindowProperty *
const property = (QuartzWindowProperty *)[
fX11Properties valueForKey : key];
3202 assert(property != 0 &&
3203 "-getProperty:returnType:returnFormat:nElements, property not found");
3205 NSData *
const propData =
property.fPropertyData;
3207 const NSUInteger dataSize = [propData length];
3208 unsigned char *buff = 0;
3210 buff =
new unsigned char[dataSize]();
3211 }
catch (
const std::bad_alloc &) {
3213 NSLog(
@"QuartzWindow: -getProperty:returnType:returnFormat:nElements:," 3214 " memory allocation failed");
3218 [propData getBytes : buff length : dataSize];
3219 *
format =
property.fFormat;
3221 *nElements = dataSize;
3224 *nElements= dataSize / 2;
3226 *nElements = dataSize / 4;
3228 *
type =
property.fType;
3234 - (
void) removeProperty : (const
char *) propName
3236 assert(propName != 0 &&
"-removeProperty:, parameter 'propName' is null");
3238 NSString *
const key = [NSString stringWithCString : propName
3239 encoding : NSASCIIStringEncoding];
3245 - (NSDragOperation) draggingEntered : (
id<NSDraggingInfo>) sender
3247 NSPasteboard *
const pasteBoard = [sender draggingPasteboard];
3248 const NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
3250 if ([[pasteBoard types] containsObject : NSFilenamesPboardType] && (sourceDragMask & NSDragOperationCopy))
3251 return NSDragOperationCopy;
3253 return NSDragOperationNone;
3257 - (BOOL) performDragOperation : (
id<NSDraggingInfo>) sender
3268 NSPasteboard *
const pasteBoard = [sender draggingPasteboard];
3269 const NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
3271 if ([[pasteBoard types] containsObject : NSFilenamesPboardType] && (sourceDragMask & NSDragOperationCopy)) {
3277 NSArray *
const files = [pasteBoard propertyListForType : NSFilenamesPboardType];
3278 for (NSString *path in files) {
3280 NSString *
const item = [@"file://" stringByAppendingString : path];
3282 const NSUInteger len = [item lengthOfBytesUsingEncoding : NSASCIIStringEncoding] + 1;
3284 std::vector<unsigned char> propertyData(len);
3285 [item getCString : (char *)&propertyData[0] maxLength : propertyData.size()
3286 encoding : NSASCIIStringEncoding];
3288 NSView<X11Window> *
const targetView =
self.fQuartzWindow.fContentView;
3289 [targetView setProperty : "_XC_DND_DATA" data : &propertyData[0]
3290 size : propertyData.size() forType : textUriAtom format : 8];
3291 }
catch (
const std::bad_alloc &) {
3293 NSLog(
@"QuartzView: -performDragOperation:, memory allocation failed");
3309 event1.
fUser[2] = textUriAtom;
3319 event2.
fUser[2] = 0;
3320 NSPoint dropPoint = [sender draggingLocation];
3323 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
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
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)
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)
const NSUInteger kTitledWindowMask
const NSUInteger kResizableWindowMask
int GlobalYROOTToCocoa(CGFloat yROOT)
void GenerateButtonPressEvent(NSView< X11Window > *eventView, NSEvent *theEvent, EMouseButton btn)
const Mask_t kWABorderPixmap
const Mask_t kPointerMotionMask
void addChild:(NSView< X11Window > *child)
void SetWindowAttributes(const SetWindowAttributes_t *attr, NSObject< X11Window > *window)
NSMutableDictionary * fX11Properties
NSPoint GetCursorHotStop(NSImage *image, ECursor cursor)
NSPoint TranslateCoordinates(NSView< X11Window > *fromView, NSView< X11Window > *toView, NSPoint sourcePoint)
QuartzImage * fBackgroundPixmap
NSPoint ConvertPointFromBaseToScreen(NSWindow *window, NSPoint windowPoint)
QuartzWindow * FindWindowForPointerEvent(NSEvent *pointerEvent)
ROOT::MacOSX::X11::PointerGrab fCurrentGrabType
QuartzWindow * fQuartzWindow
CGImageRef CreateSubImage(QuartzImage *image, const Rectangle &area)
ROOT::MacOSX::X11::Rectangle GetDisplayGeometry() const
NSPoint TranslateFromScreen(NSPoint point, NSView< X11Window > *to)
NSPoint ConvertPointFromScreenToBase(NSPoint screenPoint, NSWindow *window)
const NSUInteger kClosableWindowMask
const Mask_t kWABackingPlanes
const NSUInteger kMiniaturizableWindowMask
int GlobalXROOTToCocoa(CGFloat xROOT)
const Mask_t kButtonPressMask
NSView< X11Window > * FindViewUnderPointer()
NSPoint TranslateToScreen(NSView< X11Window > *from, NSPoint point)
NSView< X11Window > * FrameForTextView(NSView< X11Window > *textView)
const NSEventType kLeftMouseDown
int GlobalYCocoaToROOT(CGFloat yCocoa)
bool ViewIsHtmlViewFrame(NSView< X11Window > *view, bool checkParent)
void activatePassiveGrab()
void GenerateExposeEvent(NSView< X11Window > *view, const NSRect &exposedRect)
void setOverlapped:(BOOL overlap)
const Mask_t kWAEventMask
R__EXTERN TSystem * gSystem
const Mask_t kWASaveUnder
static Atom_t fgDeleteWindowAtom
QuartzWindow * FindWindowUnderPointer()
virtual 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 NSEventType kRightMouseDown
const Mask_t kWAOverrideRedirect
void GenerateCrossingEvent(NSEvent *theEvent)
const Mask_t kWAWinGravity
void WindowLostFocus(Window_t winID)
void ClipToShapeMask(NSView< X11Window > *view, CGContextRef ctx)
const NSUInteger kBorderlessWindowMask
NSCursor * CreateCursor(ECursor currentCursor)
unsigned long fBackgroundPixel
unsigned fPassiveGrabKeyModifiers
ROOT::MacOSX::X11::CommandBuffer * GetCommandBuffer() const
typedef void((*Func_t)())
This class implements TVirtualX interface for MacOS X, using Cocoa and Quartz 2D. ...
NSComparisonResult CompareViewsToLower(id view1, id view2, void *context)
QuartzView * fContentView
const Mask_t kWABorderWidth
void GenerateKeyPressEvent(NSView< X11Window > *eventView, NSEvent *theEvent)
NSComparisonResult CompareViewsToRaise(id view1, id view2, void *context)
BOOL fActiveGrabOwnerEvents
const Mask_t kWABackPixel
const Mask_t kWABackingPixel
const Mask_t kWADontPropagate
bool ViewIsTextViewFrame(NSView< X11Window > *view, bool checkParent)
unsigned fActiveGrabEventMask
ROOT::MacOSX::X11::EventTranslator * GetEventTranslator() const
void GenerateFocusChangeEvent(NSView< X11Window > *eventView)
void GetWindowGeometry(NSObject< X11Window > *win, WindowAttributes_t *dst)
NSMutableArray * fPassiveKeyGrabs
void activateImplicitGrab()
void GenerateButtonReleaseEvent(NSView< X11Window > *eventView, NSEvent *theEvent, EMouseButton btn)