16 #ifdef DEBUG_ROOT_COCOA 28 #include <Availability.h> 36 #include "RConfigure.h" 50 #pragma mark - Create a window or a view. 61 winRect.size.width = w;
62 winRect.size.height =
h;
69 backing : NSBackingStoreBuffered
71 windowAttributes : attr];
73 throw std::runtime_error(
"CreateTopLevelWindow failed");
75 newWindow.fDepth = depth;
76 newWindow.fClass = clss;
86 viewRect.origin.x =
x;
87 viewRect.origin.y =
y;
88 viewRect.size.width = w;
89 viewRect.size.height =
h;
93 throw std::runtime_error(
"CreateChildView failed");
98 #pragma mark - root window (does not really exist, it's our desktop built of all screens). 104 assert(attr != 0 &&
"GetRootWindowAttributes, parameter 'attr' is null");
107 NSArray *
const screens = [NSScreen screens];
108 assert(screens != nil &&
"screens array is nil");
109 NSScreen *
const mainScreen = [screens objectAtIndex : 0];
110 assert(mainScreen != nil &&
"screen with index 0 is nil");
114 assert(dynamic_cast<TGCocoa *>(
gVirtualX) &&
115 "GetRootWindowAttributes, gVirtualX is either null or has a wrong type");
129 attr->
fDepth = NSBitsPerPixelFromDepth([mainScreen depth]);
135 #pragma mark - Coordinate conversions. 140 assert(window != nil &&
"ConvertPointFromBaseToScreen, parameter 'window' is nil");
146 tmpRect.origin = windowPoint;
147 tmpRect.size = NSMakeSize(1., 1.);
148 tmpRect = [window convertRectToScreen : tmpRect];
150 return tmpRect.origin;
156 assert(window != nil &&
"ConvertPointFromScreenToBase, parameter 'window' is nil");
162 tmpRect.origin = screenPoint;
163 tmpRect.size = NSMakeSize(1., 1.);
164 tmpRect = [window convertRectFromScreen : tmpRect];
166 return tmpRect.origin;
176 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
177 "GlobalYCocoaToROOT, gVirtualX is either nul or has a wrong type");
181 return int(frame.
fHeight - (yCocoa - frame.
fY));
187 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
188 "GlobalXCocoaToROOT, gVirtualX is either nul or has a wrong type");
191 return int(xCocoa - frame.
fX);
197 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
198 "GlobalYROOTToCocoa, gVirtualX is either nul or has a wrong type");
201 return int(frame.
fY + (frame.
fHeight - yROOT));
207 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
208 "GlobalXROOTToCocoa, gVirtualX is either nul or has a wrong type");
211 return int(frame.
fX + xROOT);
217 assert(parentView != nil &&
"LocalYCocoaToROOT, parent view is nil");
219 return int(parentView.frame.size.height - yCocoa);
226 assert(parentView != nil &&
"LocalYROOTToCocoa, parent view is nil");
228 return int(parentView.frame.size.height - yROOT);
236 assert(drawable != nil &&
"LocalYROOTToCocoa, drawable is nil");
238 return int(drawable.fHeight - yROOT);
244 assert(from != nil &&
"TranslateToScreen, parameter 'from' is nil");
246 const NSPoint winPoint = [from convertPoint : point toView : nil];
258 assert(to != nil &&
"TranslateFromScreen, parameter 'to' is nil");
264 return [to convertPoint : point fromView : nil];
271 assert(from != nil &&
"TranslateCoordinates, parameter 'from' is nil");
272 assert(to != nil &&
"TranslateCoordinates, parameter 'to' is nil");
274 if ([from window] == [to window]) {
276 return [to convertPoint : sourcePoint fromView : from];
284 const NSPoint win1Point = [from convertPoint : sourcePoint toView : nil];
288 return [to convertPoint : win2Point fromView : nil];
295 assert(view != nil &&
"ScreenPointIsInView, parameter 'view' is nil");
298 point.x =
x, point.y =
y;
300 const NSRect viewFrame = view.frame;
302 if (point.x < 0 || point.x > viewFrame.size.width)
304 if (point.y < 0 || point.y > viewFrame.size.height)
310 #pragma mark - Different FindView/Window functions iterating on the ROOT's windows/views. 318 NSArray *
const orderedWindows = [NSApp orderedWindows];
319 for (NSWindow *window in orderedWindows) {
322 QuartzWindow *
const qw = (QuartzWindow *)window;
337 assert(children != nil &&
"FindDNDAwareViewInPoint, parameter 'children' is nil");
342 NSEnumerator *
const reverseEnumerator = [children reverseObjectEnumerator];
343 for (NSView<X11Window> *child in reverseEnumerator) {
346 if (child.fIsDNDAware && child.fID != dragWinID && child.fID != inputWinID)
350 inputWinID, x, y, maxDepth - 1);
369 NSArray *
const orderedWindows = [NSApp orderedWindows];
370 for (NSWindow *window in orderedWindows) {
373 QuartzWindow *
const qw = (QuartzWindow *)window;
386 if (testView.fIsDNDAware && testView.fID != dragWinID && testView.fID != inputWinID)
390 NSArray *
const children = [testView subviews];
409 NSArray *
const orderedWindows = [NSApp orderedWindows];
410 for (NSWindow *nsWindow in orderedWindows) {
414 QuartzWindow *
const qWindow = (QuartzWindow *)nsWindow;
422 const NSPoint mousePosition = [qWindow mouseLocationOutsideOfEventStream];
423 const NSSize windowSize = qWindow.frame.size;
424 if (mousePosition.x >= 0 && mousePosition.x <= windowSize.width &&
425 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 &) {
531 NSLog(
@"DownscaledImageData, memory allocation failed");
536 if (!colorSpace.
Get()) {
537 NSLog(
@"DownscaledImageData, CGColorSpaceCreateDeviceRGB failed");
542 w * 4, colorSpace.
Get(),
543 kCGImageAlphaPremultipliedLast,
NULL, 0));
545 NSLog(
@"DownscaledImageData, CGBitmapContextCreateWithData failed");
549 CGContextDrawImage(ctx.
Get(), CGRectMake(0, 0, w, h), image);
554 #pragma mark - "Focus management" - just make another window key window. 560 if (![NSApp isActive])
565 NSArray *
const orderedWindows = [NSApp orderedWindows];
566 for (NSWindow *nsWindow in orderedWindows) {
570 QuartzWindow *
const qWindow = (QuartzWindow *)nsWindow;
578 [qWindow makeKeyAndOrderFront : qWindow];
583 #pragma mark - 'shape mask' - to create a window with arbitrary (probably non-rectangle) shape. 588 assert(view != nil &&
"ClipToShapeMask, parameter 'view' is nil");
589 assert(ctx != 0 &&
"ClipToShapeMask, parameter 'ctx' is null");
593 "ClipToShapeMask, fShapeCombineMask is nil on a top-level window");
595 "ClipToShapeMask, shape mask is null");
601 if (!view.fParentView) {
607 NSRect clipRect = view.frame;
609 clipRect.origin = [view.fParentView convertPoint : clipRect.origin
610 toView : [view window].contentView];
612 clipRect.origin.y + clipRect.size.height);
617 NSRectToCGRect(clipRect)));
618 clipRect.origin = NSPoint();
619 CGContextClipToMask(ctx, NSRectToCGRect(clipRect), clipImageGuard.
Get());
623 CGContextClipToRect(ctx, rect);
628 #pragma mark - Window's geometry and attributes. 633 assert(attr != 0 &&
"SetWindowAttributes, parameter 'attr' is null");
634 assert(window != nil &&
"SetWindowAttributes, parameter 'window' is nil");
651 if ([(NSObject *)window isKindOfClass : [
QuartzWindow class]]) {
652 QuartzWindow *
const qw = (QuartzWindow *)window;
654 [qw setAlphaValue : 0.95];
657 window.fOverrideRedirect = YES;
664 assert(win != nil &&
"GetWindowGeometry, parameter 'win' is nil");
665 assert(dst != 0 &&
"GetWindowGeometry, parameter 'dst' is null");
677 assert(window != nil &&
"GetWindowAttributes, parameter 'window' is nil");
678 assert(dst != 0 &&
"GetWindowAttributes, parameter 'attr' is null");
687 dst->
fDepth = window.fDepth;
692 dst->
fClass = window.fClass;
726 #pragma mark - Comparators (I need them when changing a window's z-order). 730 #ifdef MAC_OS_X_VERSION_10_11 731 NSComparisonResult
CompareViewsToLower(__kindof NSView *view1, __kindof NSView *view2,
void *context)
736 id topView = (id)context;
737 if (view1 == topView)
738 return NSOrderedAscending;
739 if (view2 == topView)
740 return NSOrderedDescending;
742 return NSOrderedSame;
747 #ifdef MAC_OS_X_VERSION_10_11 748 NSComparisonResult
CompareViewsToRaise(__kindof NSView *view1, __kindof NSView *view2,
void *context)
753 id topView = (id)context;
754 if (view1 == topView)
755 return NSOrderedDescending;
756 if (view2 == topView)
757 return NSOrderedAscending;
759 return NSOrderedSame;
762 #pragma mark - Cursor's area. 767 assert(image != nil &&
"CursroHotSpot, parameter 'image' is nil");
769 const NSSize imageSize = image.size;
772 return NSMakePoint(imageSize.width, imageSize.height / 2);
774 return NSMakePoint(imageSize.width / 2, imageSize.height / 2);
781 const char *pngFileName = 0;
783 switch (currentCursor) {
785 pngFileName =
"move_cursor.png";
788 pngFileName =
"hor_arrow_cursor.png";
791 pngFileName =
"ver_arrow_cursor.png";
794 pngFileName =
"right_arrow_cursor.png";
797 pngFileName =
"rotate.png";
801 pngFileName =
"top_right_cursor.png";
805 pngFileName =
"top_left_cursor.png";
814 if (!path || path[0] == 0) {
819 NSString *nsPath = [NSString stringWithFormat :
@"%s", path];
820 NSImage *
const cursorImage = [[NSImage alloc] initWithContentsOfFile : nsPath];
826 NSCursor *
const customCursor = [[[NSCursor alloc] initWithImage : cursorImage
827 hotSpot : hotSpot] autorelease];
829 [cursorImage release];
849 NSCursor *cursor = nil;
850 switch (currentCursor) {
852 cursor = [NSCursor crosshairCursor];
855 cursor = [NSCursor arrowCursor];
858 cursor = [NSCursor openHandCursor];
861 cursor = [NSCursor resizeLeftCursor];
864 cursor = [NSCursor resizeRightCursor];
867 cursor = [NSCursor resizeUpCursor];
870 cursor = [NSCursor resizeDownCursor];
873 cursor = [NSCursor IBeamCursor];
891 #pragma mark - Workarounds for a text view and its descendants. 905 assert(view != nil &&
"ViewIsTextView, parameter 'view' is nil");
913 assert(view != nil &&
"ViewIsTextViewFrame, parameter 'view' is nil");
925 if (!view.fParentView)
943 assert(view != nil &&
"ViewIsHtmlView, parameter 'view' is nil");
952 assert(view != nil &&
"ViewIsHtmlViewFrame, parameter 'view' is nil");
964 if (!view.fParentView)
973 assert(textView != nil &&
"FrameForTextView, parameter 'textView' is nil");
975 for (NSView<X11Window> *child in [textView subviews]) {
986 assert(htmlView != nil &&
"FrameForHtmlView, parameter 'htmlView' is nil");
988 for (NSView<X11Window> *child in [htmlView subviews]) {
996 #pragma mark - Workarounds for 'paint out of paint events'. 1001 assert(view != nil &&
"LockFocus, parameter 'view' is nil");
1002 assert([view isKindOfClass : [
QuartzView class]] &&
1003 "LockFocus, QuartzView is expected");
1005 if ([view lockFocusIfCanDraw]) {
1006 NSGraphicsContext *nsContext = [NSGraphicsContext currentContext];
1007 assert(nsContext != nil &&
"LockFocus, currentContext is nil");
1008 CGContextRef currContext = (CGContextRef)[nsContext graphicsPort];
1009 assert(currContext != 0 &&
"LockFocus, graphicsPort is null");
1022 assert(view != nil &&
"UnlockFocus, parameter 'view' is nil");
1023 assert([view isKindOfClass : [
QuartzView class]] &&
1024 "UnlockFocus, QuartzView is expected");
1039 #ifdef DEBUG_ROOT_COCOA 1041 #pragma mark - 'loggers'. 1051 static std::ofstream logfile(
"win_attr.txt");
1055 logfile<<
"win "<<winID<<
": BackPixmap\n";
1057 logfile<<
"win "<<winID<<
": BackPixel\n";
1059 logfile<<
"win "<<winID<<
": BorderPixmap\n";
1061 logfile<<
"win "<<winID<<
": BorderPixel\n";
1063 logfile<<
"win "<<winID<<
": BorderWidth\n";
1065 logfile<<
"win "<<winID<<
": BitGravity\n";
1067 logfile<<
"win "<<winID<<
": WinGravity\n";
1069 logfile<<
"win "<<winID<<
": BackingStore\n";
1071 logfile<<
"win "<<winID<<
": BackingPlanes\n";
1073 logfile<<
"win "<<winID<<
": BackingPixel\n";
1075 logfile<<
"win "<<winID<<
": OverrideRedirect\n";
1077 logfile<<
"win "<<winID<<
": SaveUnder\n";
1079 logfile<<
"win "<<winID<<
": EventMask\n";
1081 logfile<<
"win "<<winID<<
": DontPropagate\n";
1083 logfile<<
"win "<<winID<<
": Colormap\n";
1085 logfile<<
"win "<<winID<<
": Cursor\n";
1089 void print_mask_info(
ULong_t mask)
1092 NSLog(
@"button press mask");
1094 NSLog(
@"button release mask");
1096 NSLog(
@"exposure mask");
1098 NSLog(
@"pointer motion mask");
1100 NSLog(
@"button motion mask");
1102 NSLog(
@"enter notify mask");
1104 NSLog(
@"leave notify mask");
1116 #pragma mark - QuartzWindow's life cycle. 1119 - (id) initWithContentRect : (NSRect) contentRect styleMask : (NSUInteger) windowStyle
1120 backing : (NSBackingStoreType) bufferingType defer : (BOOL) deferCreation
1123 self = [
super initWithContentRect : contentRect styleMask : windowStyle
1124 backing : bufferingType defer : deferCreation];
1128 [
self setAllowsConcurrentViewDrawing : NO];
1130 self.delegate =
self;
1132 NSRect contentViewRect = contentRect;
1133 contentViewRect.origin.x = 0.f;
1134 contentViewRect.origin.y = 0.f;
1138 [
self setContentView : fContentView];
1158 assert(glView != nil &&
"-initWithGLView, parameter 'glView' is nil");
1163 NSRect contentRect = glView.frame;
1164 contentRect.origin = NSPoint();
1166 self = [
super initWithContentRect : contentRect styleMask : styleMask
1167 backing : NSBackingStoreBuffered defer : NO];
1171 [
self setAllowsConcurrentViewDrawing : NO];
1172 self.delegate =
self;
1174 [
self setContentView : fContentView];
1197 - (
void) setContentView:(NSView *)cv
1199 [
super setContentView:cv];
1207 - (
void) setFIsDeleted : (BOOL) deleted
1212 #pragma mark - Forwaring: I want to forward a lot of property setters/getters to the content view. 1215 - (
void) forwardInvocation : (NSInvocation *) anInvocation
1220 if ([
fContentView respondsToSelector : [anInvocation selector]]) {
1221 [anInvocation invokeWithTarget : fContentView];
1223 [
super forwardInvocation : anInvocation];
1228 - (NSMethodSignature*) methodSignatureForSelector : (
SEL) selector
1230 NSMethodSignature *signature = [
super methodSignatureForSelector : selector];
1234 signature = [
fContentView methodSignatureForSelector : selector];
1249 assert(window != nil &&
"-addTransientWindow:, parameter 'window' is nil");
1258 [
self addChildWindow : window ordered : NSWindowAbove];
1264 - (
void) makeKeyAndOrderFront : (
id) sender
1266 #pragma unused(sender) 1271 #ifdef MAC_OS_X_VERSION_10_9 1272 [
self setCollectionBehavior : NSWindowCollectionBehaviorMoveToActiveSpace];
1274 [
self setCollectionBehavior : NSWindowCollectionBehaviorCanJoinAllSpaces];
1277 [
super makeKeyAndOrderFront : self];
1279 [
self setCollectionBehavior : NSWindowCollectionBehaviorDefault];
1283 - (
void) setFDelayedTransient : (BOOL) d
1306 #pragma mark - X11Drawable's protocol. 1337 return self.frame.size.width;
1346 assert(
fContentView != nil &&
"-fHeight:, content view is nil");
1352 - (
void) setDrawableSize : (NSSize) newSize
1355 assert(!(newSize.width < 0) &&
"-setDrawableSize:, width is negative");
1356 assert(!(newSize.height < 0) &&
"-setDrawableSize:, height is negative");
1358 NSRect frame =
self.frame;
1362 frame.origin.y = frame.origin.y + frame.size.height - newSize.height - dY;
1363 frame.size = newSize;
1364 frame.size.height += dY;
1365 [
self setFrame : frame display : YES];
1369 - (
void) setX : (
int) x Y : (
int) y width : (
unsigned) w height : (
unsigned) h
1371 NSSize newSize = {};
1374 [
self setContentSize : newSize];
1377 NSPoint topLeft = {};
1381 [
self setFrameTopLeftPoint : topLeft];
1385 - (
void) setX : (
int) x Y : (
int) y
1387 NSPoint topLeft = {};
1391 [
self setFrameTopLeftPoint : topLeft];
1396 clipOrigin : (
X11::Point) clipXY toPoint : (
X11::Point) dstPoint
1401 [
fContentView copy : src area : area withMask : mask clipOrigin : clipXY toPoint : dstPoint];
1405 - (
unsigned char *) readColorBits : (
X11::Rectangle) area
1413 #pragma mark - X11Window protocol's implementation. 1424 #pragma unused(parent) 1442 - (
void) setFBackgroundPixel : (
unsigned long) backgroundColor
1448 CGFloat rgba[] = {0., 0., 0., 1.};
1451 [
self setBackgroundColor : [NSColor colorWithColorSpace : [NSColorSpace deviceRGBColorSpace] components : rgba count : 4]];
1480 - (
void) addChild : (NSView<X11Window> *) child
1482 assert(child != nil &&
"-addChild:, parameter 'child' is nil");
1486 assert([child isKindOfClass : [
QuartzView class]] &&
1487 "-addChild: gl view in a top-level window as content view is not supported");
1490 [
self setContentView : child];
1502 assert(attr &&
"-getAttributes:, parameter 'attr' is nil");
1510 assert(attr != 0 &&
"-setAttributes:, parameter 'attr' is null");
1512 #ifdef DEBUG_ROOT_COCOA 1513 log_attributes(attr,
self.fID);
1525 const Util::AutoreleasePool pool;
1528 [
self makeKeyAndOrderFront : self];
1533 [
fMainWindow addChildWindow : self ordered : NSWindowAbove];
1543 const Util::AutoreleasePool pool;
1546 [
self makeKeyAndOrderFront : self];
1551 [
fMainWindow addChildWindow : self ordered : NSWindowAbove];
1561 const Util::AutoreleasePool pool;
1574 [
self orderOut : self];
1582 #pragma mark - Events. 1585 - (
void) sendEvent : (NSEvent *) theEvent
1595 bool generateFakeRelease =
false;
1597 const NSPoint windowPoint = [theEvent locationInWindow];
1599 if (windowPoint.x <= 4 || windowPoint.x >=
self.fWidth - 4)
1600 generateFakeRelease =
true;
1602 if (windowPoint.y <= 4 || windowPoint.y >=
self.fHeight - 4)
1603 generateFakeRelease =
true;
1605 const NSPoint viewPoint = [
fContentView convertPoint : windowPoint fromView : nil];
1607 if (viewPoint.y <= 0 && windowPoint.y >= 0)
1608 generateFakeRelease =
true;
1610 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
1611 "-sendEvent:, gVirtualX is either null or not of TGCocoa type");
1625 [
super sendEvent : theEvent];
1628 #pragma mark - NSWindowDelegate's methods. 1631 - (BOOL) windowShouldClose : (
id) sender
1633 #pragma unused(sender) 1637 if ([[
self childWindows] count])
1648 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
1649 "-windowShouldClose:, gVirtualX is either null or has a type different from TGCocoa");
1658 - (
void) windowDidBecomeKey : (NSNotification *) aNotification
1660 #pragma unused(aNotification) 1668 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
1669 "-windowDidBecomeKey:, gVirtualX is null or not of TGCocoa type");
1677 - (
void) windowDidResignKey : (NSNotification *) aNotification
1679 #pragma unused(aNotification) 1685 #pragma mark - Passive key grab info. 1690 - (id) initWithKey : (unichar) keyCode modifiers : (NSUInteger) modifiers
1692 if (
self = [super
init]) {
1701 - (BOOL) matchKey : (unichar) keyCode modifiers : (NSUInteger) modifiers
1707 - (BOOL) matchKey : (unichar) keyCode
1726 #pragma mark - X11 property emulation. 1728 @interface QuartzWindowProperty : NSObject {
1729 NSData *fPropertyData;
1738 @implementation QuartzWindowProperty
1745 if (
self = [super
init]) {
1747 fPropertyData = nil;
1751 [
self resetPropertyData : data size : dataSize type : type format : format];
1760 [fPropertyData release];
1766 - (
void) resetPropertyData : (
unsigned char *)
data size : (unsigned) dataSize
1769 [fPropertyData release];
1777 fPropertyData = [[NSData dataWithBytes : data length : dataSize] retain];
1783 - (NSData *) fPropertyData
1785 return fPropertyData;
1789 - (unsigned) fFormat
1796 #pragma mark - QuartzView. 1829 #pragma mark - Lifetime. 1834 if (
self = [super initWithFrame : frame]) {
1846 [
self setCanDrawConcurrently : NO];
1848 [
self setHidden : YES];
1875 #pragma mark - Tracking area. 1880 - (
void) updateTrackingAreas
1882 [
super updateTrackingAreas];
1887 const Util::AutoreleasePool pool;
1889 if (NSArray *trackingArray = [
self trackingAreas]) {
1890 const NSUInteger size = [trackingArray count];
1891 for (NSUInteger i = 0; i < size; ++i) {
1892 NSTrackingArea *
const t = [trackingArray objectAtIndex : i];
1893 [
self removeTrackingArea : t];
1897 const NSUInteger trackerOptions = NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited |
1898 NSTrackingActiveInActiveApp | NSTrackingInVisibleRect |
1899 NSTrackingEnabledDuringMouseDrag | NSTrackingCursorUpdate;
1902 frame.size.width =
self.fWidth;
1903 frame.size.height =
self.fHeight;
1905 NSTrackingArea *
const tracker = [[NSTrackingArea alloc] initWithRect : frame
1906 options : trackerOptions owner : self userInfo : nil];
1907 [
self addTrackingArea : tracker];
1912 - (
void) updateTrackingAreasAfterRaise
1914 [
self updateTrackingAreas];
1916 for (
QuartzView *childView in [
self subviews])
1917 [childView updateTrackingAreasAfterRaise];
1920 #pragma mark - X11Drawable protocol. 1937 return self.frame.origin.x;
1943 return self.frame.origin.y;
1949 return self.frame.size.width;
1955 return self.frame.size.height;
1959 - (
void) setDrawableSize : (NSSize) newSize
1961 assert(!(newSize.width < 0) &&
"-setDrawableSize, width is negative");
1962 assert(!(newSize.height < 0) &&
"-setDrawableSize, height is negative");
1968 NSRect frame =
self.frame;
1969 frame.size = newSize;
1975 - (
void) setX : (
int) x Y : (
int) y width : (
unsigned) w height : (
unsigned) h
1977 NSRect newFrame = {};
1978 newFrame.origin.x =
x;
1979 newFrame.origin.y =
y;
1980 newFrame.size.width = w;
1981 newFrame.size.height =
h;
1983 self.frame = newFrame;
1987 - (
void) setX : (
int) x Y : (
int) y
1989 NSRect newFrame =
self.frame;
1990 newFrame.origin.x =
x;
1991 newFrame.origin.y =
y;
1993 self.frame = newFrame;
2002 assert(srcImage != nil &&
2003 "-copyImage:area:withMask:clipOrigin:toPoint:, parameter 'srcImage' is nil");
2004 assert(srcImage.fImage != nil &&
2005 "-copyImage:area:withMask:clipOrigin:toPoint:, srcImage.fImage is nil");
2009 "-copyImage:area:withMask:clipOrigin:toPoint:, self.fContext is null");
2012 NSLog(
@"QuartzView: -copyImage:area:withMask:clipOrigin:toPoint:," 2013 " srcRect and copyRect do not intersect");
2019 CGImageRef subImage = 0;
2020 bool needSubImage =
false;
2021 if (area.fX || area.fY || area.fWidth != srcImage.fWidth || area.fHeight != srcImage.fHeight) {
2022 needSubImage =
true;
2025 NSLog(
@"QuartzView: -copyImage:area:withMask:clipOrigin:toPoint:," 2026 " subimage creation failed");
2030 subImage = srcImage.fImage;
2037 CGContextScaleCTM(
self.
fContext, 1., -1.);
2041 assert(mask.
fImage != nil &&
2042 "-copyImage:area:withMask:clipOrigin:toPoint:, mask.fImage is nil");
2043 assert(CGImageIsMask(mask.
fImage) ==
true &&
2044 "-copyImage:area:withMask:clipOrigin:toPoint:, mask.fImage is not a mask");
2048 const CGRect clipRect = CGRectMake(clipXY.fX, clipY, mask.
fWidth, mask.
fHeight);
2056 const CGRect imageRect = CGRectMake(dstPoint.fX, dstY, area.fWidth, area.fHeight);
2057 CGContextDrawImage(
self.
fContext, imageRect, subImage);
2060 CGImageRelease(subImage);
2069 assert(srcView != nil &&
"-copyView:area:toPoint:, parameter 'srcView' is nil");
2071 const NSRect frame = [srcView frame];
2073 NSBitmapImageRep *
const imageRep = [srcView bitmapImageRepForCachingDisplayInRect : frame];
2075 NSLog(
@"QuartzView: -copyView:area:toPoint failed");
2079 assert(srcView != nil &&
"-copyView:area:toPoint:, parameter 'srcView' is nil");
2080 assert(
self.
fContext != 0 &&
"-copyView:area:toPoint, self.fContext is null");
2085 CGContextRef ctx = srcView.fContext;
2086 srcView.fSnapshotDraw = YES;
2087 [srcView cacheDisplayInRect : frame toBitmapImageRep : imageRep];
2088 srcView.fSnapshotDraw = NO;
2089 srcView.fContext = ctx;
2091 const CGRect subImageRect = CGRectMake(area.fX, area.fY, area.fWidth, area.fHeight);
2092 const Util::CFScopeGuard<CGImageRef> subImage(CGImageCreateWithImageInRect(imageRep.CGImage, subImageRect));
2094 if (!subImage.Get()) {
2095 NSLog(
@"QuartzView: -copyView:area:toPoint, CGImageCreateWithImageInRect failed");
2100 const CGRect imageRect = CGRectMake(dstPoint.fX,
2101 [
self visibleRect].size.height - (CGFloat(dstPoint.fY) + area.fHeight),
2102 area.fWidth, area.fHeight);
2104 CGContextTranslateCTM(
self.
fContext, 0., [
self visibleRect].size.height);
2105 CGContextScaleCTM(
self.
fContext, 1., -1.);
2107 CGContextDrawImage(
self.
fContext, imageRect, subImage.Get());
2115 assert(srcPixmap != nil &&
"-copyPixmap:area:withMask:clipOrigin:toPoint:, parameter 'srcPixmap' is nil");
2118 NSLog(
@"QuartzView: -copyPixmap:area:withMask:clipOrigin:toPoint," 2119 " no intersection between pixmap rectangle and cropArea");
2125 "-copyPixmap:area:withMask:clipOrigin:toPoint:, self.fContext is null");
2130 CGContextTranslateCTM(
self.
fContext, 0.,
self.frame.size.height);
2131 CGContextScaleCTM(
self.
fContext, 1., -1.);
2133 const Util::CFScopeGuard<CGImageRef> imageFromPixmap([srcPixmap createImageFromPixmap]);
2134 assert(imageFromPixmap.Get() != 0 &&
2135 "-copyPixmap:area:withMask:clipOrigin:toPoint:, createImageFromPixmap failed");
2137 CGImageRef subImage = 0;
2138 bool needSubImage =
false;
2139 if (area.fX || area.fY || area.fWidth != srcPixmap.fWidth || area.fHeight != srcPixmap.fHeight) {
2140 needSubImage =
true;
2141 const CGRect subImageRect = CGRectMake(area.fX, area.fY, area.fHeight, area.fWidth);
2142 subImage = CGImageCreateWithImageInRect(imageFromPixmap.Get(), subImageRect);
2144 NSLog(
@"QuartzView: -copyImage:area:withMask:clipOrigin:toPoint:," 2145 " subimage creation failed");
2149 subImage = imageFromPixmap.Get();
2152 assert(mask.
fImage != nil &&
2153 "-copyPixmap:area:withMask:clipOrigin:toPoint:, mask.fImage is nil");
2154 assert(CGImageIsMask(mask.
fImage) ==
true &&
2155 "-copyPixmap:area:withMask:clipOrigin:toPoint:, mask.fImage is not a mask");
2160 const CGRect clipRect = CGRectMake(clipXY.fX, clipY, mask.
fWidth, mask.
fHeight);
2166 const CGRect imageRect = CGRectMake(dstPoint.fX, dstY, area.fWidth, area.fHeight);
2167 CGContextDrawImage(
self.
fContext, imageRect, imageFromPixmap.Get());
2170 CGImageRelease(subImage);
2178 assert(srcImage != nil &&
"-copyImage:area:toPoint:, parameter 'srcImage' is nil");
2179 assert(srcImage.fImage != nil &&
"-copyImage:area:toPoint:, srcImage.fImage is nil");
2180 assert(
self.
fContext != 0 &&
"-copyImage:area:toPoint:, fContext is null");
2183 NSLog(
@"QuartzView: -copyImage:area:toPoint, image and copy area do not intersect");
2187 CGImageRef subImage = 0;
2188 bool needSubImage =
false;
2189 if (area.fX || area.fY || area.fWidth != srcImage.fWidth || area.fHeight != srcImage.fHeight) {
2190 needSubImage =
true;
2193 NSLog(
@"QuartzView: -copyImage:area:toPoint:, subimage creation failed");
2197 subImage = srcImage.fImage;
2202 CGContextScaleCTM(
self.
fContext, 1., -1.);
2207 const CGRect imageRect = CGRectMake(dstPoint.fX, dstY, area.fWidth, area.fHeight);
2208 CGContextDrawImage(
self.
fContext, imageRect, subImage);
2211 CGImageRelease(subImage);
2216 withMask : (
QuartzImage *)mask clipOrigin : (
X11::Point) clipXY toPoint : (
X11::Point) dstPoint
2218 assert(src != nil &&
"-copy:area:withMask:clipOrigin:toPoint:, parameter 'src' is nil");
2219 assert(area.fWidth && area.fHeight &&
"-copy:area:withMask:clipOrigin:toPoint:, area to copy is empty");
2225 [
self copyView : (QuartzView *)qw.fContentView area : area toPoint : dstPoint];
2226 }
else if ([src isKindOfClass : [
QuartzView class]]) {
2228 [
self copyView : (QuartzView *)src area : area toPoint : dstPoint];
2229 }
else if ([src isKindOfClass : [
QuartzPixmap class]]) {
2230 [
self copyPixmap : (QuartzPixmap *)src area : area withMask : mask clipOrigin : clipXY toPoint : dstPoint];
2231 }
else if ([src isKindOfClass : [
QuartzImage class]]) {
2232 [
self copyImage : (QuartzImage *)src area : area withMask : mask clipOrigin : clipXY toPoint : dstPoint];
2234 assert(0 &&
"-copy:area:withMask:clipOrigin:toPoint:, src is of unknown type");
2239 - (
unsigned char *) readColorBits : (
X11::Rectangle) area
2245 assert(area.fWidth && area.fHeight &&
"-readColorBits:, area to copy is empty");
2248 const NSRect visRect = [
self visibleRect];
2249 const X11::Rectangle srcRect(
int(visRect.origin.x),
int(visRect.origin.y),
2250 unsigned(visRect.size.width),
unsigned(visRect.size.height));
2253 NSLog(
@"QuartzView: -readColorBits:, visible rect of view and copy area do not intersect");
2258 NSBitmapImageRep *
const imageRep = [
self bitmapImageRepForCachingDisplayInRect : visRect];
2260 NSLog(
@"QuartzView: -readColorBits:, bitmapImageRepForCachingDisplayInRect failed");
2264 CGContextRef ctx =
self.fContext;
2265 [
self cacheDisplayInRect : visRect toBitmapImageRep : imageRep];
2266 self.fContext = ctx;
2268 const NSInteger bitsPerPixel = [imageRep bitsPerPixel];
2270 assert(bitsPerPixel == 32 &&
"-readColorBits:, no alpha channel???");
2271 const NSInteger bytesPerRow = [imageRep bytesPerRow];
2272 unsigned dataWidth = bytesPerRow / (bitsPerPixel / 8);
2274 unsigned char *srcData =
nullptr;
2275 std::vector<unsigned char> downscaled;
2276 if ([[NSScreen mainScreen] backingScaleFactor] > 1 && imageRep.CGImage) {
2278 if (downscaled.size())
2279 srcData = &downscaled[0];
2280 dataWidth = area.fWidth;
2282 srcData = [imageRep bitmapData];
2285 NSLog(
@"QuartzView: -readColorBits:, failed to obtain backing store contents");
2290 unsigned char *
data =
nullptr;
2293 data =
new unsigned char[area.fWidth * area.fHeight * 4];
2294 }
catch (
const std::bad_alloc &) {
2295 NSLog(
@"QuartzView: -readColorBits:, memory allocation failed");
2299 unsigned char *dstPixel =
data;
2300 const unsigned char *
line = srcData + area.fY * dataWidth * 4;
2301 const unsigned char *srcPixel =
line + area.fX * 4;
2303 for (
unsigned i = 0; i < area.fHeight; ++i) {
2304 for (
unsigned j = 0; j < area.fWidth; ++j, srcPixel += 4, dstPixel += 4) {
2305 dstPixel[0] = srcPixel[2];
2306 dstPixel[1] = srcPixel[1];
2307 dstPixel[2] = srcPixel[0];
2308 dstPixel[3] = srcPixel[3];
2311 line += dataWidth * 4;
2312 srcPixel =
line + area.fX * 4;
2341 if ([
self isHidden])
2345 if ([parent isHidden])
2363 - (
void) setFHasFocus : (BOOL) focus
2365 #pragma unused(focus) 2416 - (
void) activateGrab : (
unsigned) eventMask ownerEvents : (BOOL) ownerEvents
2432 - (BOOL) acceptsCrossingEvents : (
unsigned) eventMask
2451 - (
void) addChild : (NSView<X11Window> *) child
2453 assert(child != nil &&
"-addChild:, parameter 'child' is nil");
2455 [
self addSubview : child];
2456 child.fParentView =
self;
2462 assert(attr != 0 &&
"-getAttributes:, parameter 'attr' is null");
2470 assert(attr != 0 &&
"-setAttributes:, parameter 'attr' is null");
2472 #ifdef DEBUG_ROOT_COCOA 2473 log_attributes(attr,
fID);
2484 [
self removeFromSuperview];
2485 [parent addSubview : self];
2486 [
self setHidden : NO];
2492 [
self setHidden : NO];
2505 [
self setHidden : YES];
2515 - (
void) setOverlapped : (BOOL) overlap
2518 for (NSView<X11Window> *child in [
self subviews])
2519 [child setOverlapped : overlap];
2536 using namespace X11;
2539 if (
self == sibling)
2541 if ([sibling isHidden])
2544 if (NSEqualRects(sibling.frame,
self.frame)) {
2545 [sibling setOverlapped : YES];
2546 [sibling setHidden : YES];
2552 [
self setHidden : NO];
2554 [
fParentView sortSubviewsUsingFunction : CompareViewsToRaise context : (void *)self];
2556 [
self updateTrackingAreasAfterRaise];
2558 [
self setNeedsDisplay : YES];
2566 using namespace X11;
2568 NSEnumerator *
const reverseEnumerator = [[
fParentView subviews] reverseObjectEnumerator];
2569 for (
QuartzView *sibling in reverseEnumerator) {
2570 if (sibling ==
self)
2573 if (NSEqualRects(sibling.frame,
self.frame)) {
2574 [sibling setOverlapped : NO];
2576 [sibling setHidden : NO];
2578 [sibling setNeedsDisplay : YES];
2581 [
self setHidden : YES];
2587 [
fParentView sortSubviewsUsingFunction : CompareViewsToLower context : (void*)self];
2603 assert(dynamic_cast<TGCocoa *>(
gVirtualX) &&
2604 "-configureNotifyTree, gVirtualX is either null or has type different from TGCocoa");
2609 for (NSView<X11Window> *
v in [
self subviews])
2610 [v configureNotifyTree];
2614 #pragma mark - Key grabs. 2617 - (
void) addPassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers
2619 [
self removePassiveKeyGrab : keyCode modifiers : modifiers];
2621 modifiers : modifiers];
2627 - (
void) removePassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers
2630 for (NSUInteger i = 0; i < count; ++i) {
2632 if ([grab matchKey : keyCode modifiers : modifiers]) {
2640 - (
PassiveKeyGrab *) findPassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers
2644 if ([grab matchKey : keyCode modifiers : modifiers])
2657 if ([grab matchKey : keyCode])
2664 #pragma mark - Painting mechanics. 2667 - (
void) drawRect : (NSRect) dirtyRect
2669 #pragma unused(dirtyRect) 2671 using namespace X11;
2679 NSGraphicsContext *
const nsContext = [NSGraphicsContext currentContext];
2680 assert(nsContext != nil &&
"-drawRect:, currentContext returned nil");
2685 fContext = (CGContextRef)[nsContext graphicsPort];
2686 assert(
fContext != 0 &&
"-drawRect:, graphicsPort returned null");
2694 if (window->InheritsFrom(
"TGContainer"))
2717 gClient->CancelRedraw(window);
2725 [
self copy : fBackBuffer area : copyArea withMask : nil
2726 clipOrigin : X11::Point() toPoint : X11::Point()];
2730 #ifdef DEBUG_ROOT_COCOA 2731 CGContextSetRGBStrokeColor(
fContext, 1., 0., 0., 1.);
2732 CGContextStrokeRect(
fContext, dirtyRect);
2737 #ifdef DEBUG_ROOT_COCOA 2738 NSLog(
@"QuartzView: -drawRect: method, no window for id %u was found",
fID);
2744 #pragma mark - Geometry. 2747 - (
void) setFrame : (NSRect) newFrame
2752 if (NSEqualRects(newFrame,
self.frame))
2755 [
super setFrame : newFrame];
2759 - (
void) setFrameSize : (NSSize) newSize
2763 [
super setFrameSize : newSize];
2766 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2767 "setFrameSize:, gVirtualX is either null or has a type, different from TGCocoa");
2772 [
self setNeedsDisplay : YES];
2775 #pragma mark - Event handling. 2778 - (
void) mouseDown : (NSEvent *) theEvent
2780 assert(
fID != 0 &&
"-mouseDown:, fID is 0");
2782 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2783 "-mouseDown:, gVirtualX is either null or has a type, different from TGCocoa");
2789 - (
void) scrollWheel : (NSEvent*) theEvent
2791 assert(
fID != 0 &&
"-scrollWheel:, fID is 0");
2794 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2795 "-scrollWheel:, gVirtualX is either null or has a type, different from TGCocoa");
2798 const CGFloat deltaY = [theEvent deltaY];
2802 }
else if (deltaY > 0) {
2808 #ifdef DEBUG_ROOT_COCOA 2810 - (
void) printViewInformation
2812 assert(
fID != 0 &&
"-printWindowInformation, fID is 0");
2814 assert(window != 0 &&
"printWindowInformation, window not found");
2816 NSLog(
@"-----------------View %u info:---------------------",
fID);
2817 NSLog(
@"ROOT's window class is %s", window->IsA()->
GetName());
2818 NSLog(
@"event mask is:");
2820 NSLog(
@"grab mask is:");
2822 NSLog(
@"view's geometry: x == %g, y == %g, w == %g, h == %g",
self.frame.origin.x,
2823 self.frame.origin.y,
self.frame.size.width,
self.frame.size.height);
2824 NSLog(
@"----------------End of view info------------------");
2829 - (
void) rightMouseDown : (NSEvent *) theEvent
2831 assert(
fID != 0 &&
"-rightMouseDown:, fID is 0");
2833 #ifdef DEBUG_ROOT_COCOA 2834 [
self printViewInformation];
2837 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2838 "-rightMouseDown:, gVirtualX is either null or has type different from TGCocoa");
2844 - (
void) otherMouseDown : (NSEvent *) theEvent
2846 assert(
fID != 0 &&
"-otherMouseDown:, fID is 0");
2850 if ([theEvent buttonNumber] == 2) {
2853 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2854 "-otherMouseDown:, gVirtualX is either null or has type different from TGCocoa");
2861 - (
void) mouseUp : (NSEvent *) theEvent
2863 assert(
fID != 0 &&
"-mouseUp:, fID is 0");
2865 assert(dynamic_cast<TGCocoa *>(
gVirtualX) &&
2866 "-mouseUp:, gVirtualX is either null or has type different from TGCocoa");
2872 - (
void) rightMouseUp : (NSEvent *) theEvent
2875 assert(
fID != 0 &&
"-rightMouseUp:, fID is 0");
2877 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2878 "-rightMouseUp:, gVirtualX is either null or has type different from TGCocoa");
2885 - (
void) otherMouseUp : (NSEvent *) theEvent
2887 assert(
fID != 0 &&
"-otherMouseUp:, fID is 0");
2890 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2891 "-otherMouseUp:, gVirtualX is either null or has type different from TGCocoa");
2897 - (
void) mouseEntered : (NSEvent *) theEvent
2899 assert(
fID != 0 &&
"-mouseEntered:, fID is 0");
2900 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2901 "-mouseEntered:, gVirtualX is null or not of TGCocoa type");
2908 - (
void) mouseExited : (NSEvent *) theEvent
2910 assert(
fID != 0 &&
"-mouseExited:, fID is 0");
2912 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2913 "-mouseExited:, gVirtualX is null or not of TGCocoa type");
2920 - (
void) mouseMoved : (NSEvent *) theEvent
2922 assert(
fID != 0 &&
"-mouseMoved:, fID is 0");
2927 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2928 "-mouseMoved:, gVirtualX is null or not of TGCocoa type");
2935 - (
void) mouseDragged : (NSEvent *) theEvent
2937 assert(
fID != 0 &&
"-mouseDragged:, fID is 0");
2940 assert(vx != 0 &&
"-mouseDragged:, gVirtualX is null or not of TGCocoa type");
2946 - (
void) rightMouseDragged : (NSEvent *) theEvent
2948 assert(
fID != 0 &&
"-rightMouseDragged:, fID is 0");
2950 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2951 "-rightMouseDragged:, gVirtualX is null or not of TGCocoa type");
2958 - (
void) otherMouseDragged : (NSEvent *) theEvent
2960 assert(
fID != 0 &&
"-otherMouseDragged:, fID is 0");
2962 if ([theEvent buttonNumber] == 2) {
2963 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2964 "-otherMouseDragged:, gVirtualX is null or not of TGCocoa type");
2971 - (
void) keyDown : (NSEvent *) theEvent
2973 assert(
fID != 0 &&
"-keyDown:, fID is 0");
2975 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2976 "-keyDown:, gVirtualX is null or not of TGCocoa type");
2978 NSView<X11Window> *eventView =
self;
2980 eventView = pointerView;
2987 - (
void) keyUp : (NSEvent *) theEvent
2989 assert(
fID != 0 &&
"-keyUp:, fID is 0");
2991 assert(dynamic_cast<TGCocoa *>(
gVirtualX) != 0 &&
2992 "-keyUp:, gVirtualX is null or not of TGCocoa type");
2995 NSView<X11Window> *eventView =
self;
2997 eventView = pointerView;
3002 #pragma mark - First responder stuff. 3005 - (BOOL) acceptsFirstMouse : (NSEvent *) theEvent
3007 #pragma unused(theEvent) 3012 - (BOOL) acceptsFirstResponder
3017 #pragma mark - Cursors. 3024 [
self.fQuartzWindow invalidateCursorRectsForView : self];
3029 - (NSCursor *) createCustomCursor
3031 const char *pngFileName = 0;
3035 pngFileName =
"move_cursor.png";
3038 pngFileName =
"hor_arrow_cursor.png";
3041 pngFileName =
"ver_arrow_cursor.png";
3044 pngFileName =
"right_arrow_cursor.png";
3047 pngFileName =
"rotate.png";
3051 pngFileName =
"top_right_cursor.png";
3055 pngFileName =
"top_left_cursor.png";
3062 const Util::ScopedArray<const char> arrayGuard(path);
3064 if (!path || path[0] == 0) {
3069 NSString *nsPath = [NSString stringWithFormat : @"%s", path];
3070 NSImage *
const cursorImage = [[NSImage alloc] initWithContentsOfFile : nsPath];
3076 NSCursor *
const customCursor = [[[NSCursor alloc] initWithImage : cursorImage
3077 hotSpot : hotSpot] autorelease];
3079 [cursorImage release];
3081 return customCursor;
3088 - (
void) resetCursorRects
3091 [
self addCursorRect :
self.visibleRect cursor : cursor];
3095 - (
void) cursorUpdate
3105 - (
void) cursorUpdate : (NSEvent *)
event 3107 #pragma unused(event) 3119 [
self performSelector : @selector(cursorUpdate) withObject : nil afterDelay : 0.05f];
3122 #pragma mark - Emulated X11 properties. 3125 - (
void) setProperty : (const
char *) propName data : (
unsigned char *) propData
3126 size : (
unsigned) dataSize forType : (
Atom_t) dataType format : (
unsigned) format
3128 assert(propName != 0 &&
"-setProperty:data:size:forType:, parameter 'propName' is null");
3129 assert(propData != 0 &&
"-setProperty:data:size:forType:, parameter 'propData' is null");
3130 assert(dataSize != 0 &&
"-setProperty:data:size:forType:, parameter 'dataSize' is 0");
3132 NSString *
const key = [NSString stringWithCString : propName encoding : NSASCIIStringEncoding];
3133 QuartzWindowProperty *
property = (QuartzWindowProperty *)[
fX11Properties valueForKey : key];
3137 [property resetPropertyData : propData size : dataSize type : dataType format : format];
3140 property = [[QuartzWindowProperty alloc] initWithData : propData size : dataSize
3141 type : dataType format : format];
3148 - (BOOL) hasProperty : (const
char *) propName
3150 assert(propName != 0 &&
"-hasProperty:, propName parameter is null");
3152 NSString *
const key = [NSString stringWithCString : propName encoding : NSASCIIStringEncoding];
3153 QuartzWindowProperty *
const property = (QuartzWindowProperty *)[
fX11Properties valueForKey : key];
3155 return property != nil;
3159 - (
unsigned char *) getProperty : (const
char *) propName returnType : (
Atom_t *) type
3160 returnFormat : (
unsigned *) format nElements : (
unsigned *) nElements
3162 assert(propName != 0 &&
3163 "-getProperty:returnType:returnFormat:nElements:, parameter 'propName' is null");
3165 "-getProperty:returnType:returnFormat:nElements:, parameter 'type' is null");
3167 "-getProperty:returnType:returnFormat:nElements:, parameter 'format' is null");
3168 assert(nElements != 0 &&
3169 "-getProperty:returnType:returnFormat:nElements:, parameter 'nElements' is null");
3171 NSString *
const key = [NSString stringWithCString : propName encoding : NSASCIIStringEncoding];
3172 QuartzWindowProperty *
const property = (QuartzWindowProperty *)[
fX11Properties valueForKey : key];
3173 assert(property != 0 &&
3174 "-getProperty:returnType:returnFormat:nElements, property not found");
3176 NSData *
const propData =
property.fPropertyData;
3178 const NSUInteger dataSize = [propData length];
3179 unsigned char *buff = 0;
3181 buff =
new unsigned char[dataSize]();
3182 }
catch (
const std::bad_alloc &) {
3184 NSLog(
@"QuartzWindow: -getProperty:returnType:returnFormat:nElements:," 3185 " memory allocation failed");
3189 [propData getBytes : buff length : dataSize];
3190 *
format =
property.fFormat;
3192 *nElements = dataSize;
3195 *nElements= dataSize / 2;
3197 *nElements = dataSize / 4;
3199 *
type =
property.fType;
3205 - (
void) removeProperty : (const
char *) propName
3207 assert(propName != 0 &&
"-removeProperty:, parameter 'propName' is null");
3209 NSString *
const key = [NSString stringWithCString : propName
3210 encoding : NSASCIIStringEncoding];
3216 - (NSDragOperation) draggingEntered : (
id<NSDraggingInfo>) sender
3218 NSPasteboard *
const pasteBoard = [sender draggingPasteboard];
3219 const NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
3221 if ([[pasteBoard types] containsObject : NSFilenamesPboardType] && (sourceDragMask & NSDragOperationCopy))
3222 return NSDragOperationCopy;
3224 return NSDragOperationNone;
3228 - (BOOL) performDragOperation : (
id<NSDraggingInfo>) sender
3239 NSPasteboard *
const pasteBoard = [sender draggingPasteboard];
3240 const NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
3242 if ([[pasteBoard types] containsObject : NSFilenamesPboardType] && (sourceDragMask & NSDragOperationCopy)) {
3248 NSArray *
const files = [pasteBoard propertyListForType : NSFilenamesPboardType];
3249 for (NSString *path in files) {
3251 NSString *
const item = [@"file://" stringByAppendingString : path];
3253 const NSUInteger len = [item lengthOfBytesUsingEncoding : NSASCIIStringEncoding] + 1;
3255 std::vector<unsigned char> propertyData(len);
3256 [item getCString : (char *)&propertyData[0] maxLength : propertyData.size()
3257 encoding : NSASCIIStringEncoding];
3259 NSView<X11Window> *
const targetView =
self.fQuartzWindow.fContentView;
3260 [targetView setProperty : "_XC_DND_DATA" data : &propertyData[0]
3261 size : propertyData.size() forType : textUriAtom format : 8];
3262 }
catch (
const std::bad_alloc &) {
3264 NSLog(
@"QuartzView: -performDragOperation:, memory allocation failed");
3280 event1.
fUser[2] = textUriAtom;
3290 event2.
fUser[2] = 0;
3291 NSPoint dropPoint = [sender draggingLocation];
3294 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)
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)