16#ifdef DEBUG_ROOT_COCOA
28#include <Availability.h>
36#include "RConfigure.h"
53#pragma mark - Create a window or a view.
64 winRect.size.width = w;
65 winRect.size.height =
h;
72 backing : NSBackingStoreBuffered
74 windowAttributes : attr];
76 throw std::runtime_error(
"CreateTopLevelWindow failed");
89 viewRect.origin.x =
x;
90 viewRect.origin.y =
y;
91 viewRect.size.width = w;
92 viewRect.size.height =
h;
96 throw std::runtime_error(
"CreateChildView failed");
101#pragma mark - root window (does not really exist, it's our desktop built of all screens).
107 assert(attr != 0 &&
"GetRootWindowAttributes, parameter 'attr' is null");
110 NSArray *
const screens = [NSScreen screens];
111 assert(screens != nil &&
"screens array is nil");
112 NSScreen *
const mainScreen = [screens objectAtIndex : 0];
113 assert(mainScreen != nil &&
"screen with index 0 is nil");
118 "GetRootWindowAttributes, gVirtualX is either null or has a wrong type");
132 attr->
fDepth = NSBitsPerPixelFromDepth([mainScreen depth]);
138#pragma mark - Coordinate conversions.
143 assert(window != nil &&
"ConvertPointFromBaseToScreen, parameter 'window' is nil");
149 tmpRect.origin = windowPoint;
150 tmpRect.size = NSMakeSize(1., 1.);
151 tmpRect = [window convertRectToScreen : tmpRect];
153 return tmpRect.origin;
159 assert(window != nil &&
"ConvertPointFromScreenToBase, parameter 'window' is nil");
165 tmpRect.origin = screenPoint;
166 tmpRect.size = NSMakeSize(1., 1.);
167 tmpRect = [window convertRectFromScreen : tmpRect];
169 return tmpRect.origin;
180 "GlobalYCocoaToROOT, gVirtualX is either nul or has a wrong type");
184 return int(frame.
fHeight - (yCocoa - frame.
fY));
191 "GlobalXCocoaToROOT, gVirtualX is either nul or has a wrong type");
194 return int(xCocoa - frame.
fX);
201 "GlobalYROOTToCocoa, gVirtualX is either nul or has a wrong type");
204 return int(frame.
fY + (frame.
fHeight - yROOT));
211 "GlobalXROOTToCocoa, gVirtualX is either nul or has a wrong type");
214 return int(frame.
fX + xROOT);
220 assert(parentView != nil &&
"LocalYCocoaToROOT, parent view is nil");
222 return int(parentView.frame.size.height - yCocoa);
229 assert(parentView != nil &&
"LocalYROOTToCocoa, parent view is nil");
231 return int(parentView.frame.size.height - yROOT);
239 assert(drawable != nil &&
"LocalYROOTToCocoa, drawable is nil");
241 return int(drawable.fHeight - yROOT);
247 assert(from != nil &&
"TranslateToScreen, parameter 'from' is nil");
249 const NSPoint winPoint = [from convertPoint : point toView : nil];
261 assert(to != nil &&
"TranslateFromScreen, parameter 'to' is nil");
267 return [to convertPoint : point fromView : nil];
274 assert(from != nil &&
"TranslateCoordinates, parameter 'from' is nil");
275 assert(to != nil &&
"TranslateCoordinates, parameter 'to' is nil");
277 if ([from window] == [to window]) {
279 return [to convertPoint : sourcePoint fromView : from];
287 const NSPoint win1Point = [from convertPoint : sourcePoint toView : nil];
291 return [to convertPoint : win2Point fromView : nil];
298 assert(view != nil &&
"ScreenPointIsInView, parameter 'view' is nil");
301 point.x =
x, point.y =
y;
303 const NSRect viewFrame = view.frame;
305 if (point.x < 0 || point.x > viewFrame.size.width)
307 if (point.y < 0 || point.y > viewFrame.size.height)
313#pragma mark - Different FindView/Window functions iterating on the ROOT's windows/views.
321 NSArray *
const orderedWindows = [NSApp orderedWindows];
322 for (NSWindow *window in orderedWindows) {
340 assert(children != nil &&
"FindDNDAwareViewInPoint, parameter 'children' is nil");
345 NSEnumerator *
const reverseEnumerator = [children reverseObjectEnumerator];
346 for (NSView<X11Window> *child in reverseEnumerator) {
349 if (child.fIsDNDAware && child.fID != dragWinID && child.fID != inputWinID)
353 inputWinID,
x,
y, maxDepth - 1);
372 NSArray *
const orderedWindows = [NSApp orderedWindows];
373 for (NSWindow *window in orderedWindows) {
389 if (testView.fIsDNDAware && testView.fID != dragWinID && testView.fID != inputWinID)
393 NSArray *
const children = [testView subviews];
412 NSArray *
const orderedWindows = [NSApp orderedWindows];
413 for (NSWindow *nsWindow in orderedWindows) {
425 const NSPoint mousePosition = [qWindow mouseLocationOutsideOfEventStream];
426 const NSSize windowSize = qWindow.frame.size;
427 if (mousePosition.x >= 0 && mousePosition.x <= windowSize.width &&
428 mousePosition.y >= 0 && mousePosition.y <= windowSize.height)
441 const NSPoint mousePosition = [topLevel mouseLocationOutsideOfEventStream];
442 return (NSView<X11Window> *)[[topLevel contentView] hitTest : mousePosition];
455 assert(pointerEvent != nil &&
456 "FindWindowForPointerEvent, parameter 'pointerEvent' is nil");
460 NSArray *
const orderedWindows = [NSApp orderedWindows];
461 for (NSWindow *nsWindow in orderedWindows) {
474 NSPoint mousePosition = [pointerEvent locationInWindow];
477 if ([pointerEvent window]) {
487 const NSSize windowSize = qWindow.frame.size;
488 if (mousePosition.x >= 0 && mousePosition.x <= windowSize.width &&
489 mousePosition.y >= 0 && mousePosition.y <= windowSize.height)
502 assert(pointerEvent != nil &&
503 "FindViewForPointerEvent, parameter 'pointerEvent' is nil");
508 NSPoint mousePosition = [pointerEvent locationInWindow];
509 if ([pointerEvent window])
516 return (NSView<X11Window> *)[[topLevel contentView] hitTest : mousePosition];
522#pragma mark - Downscale image ("reading color bits" on retina macs).
527 assert(w != 0 &&
h != 0 &&
"DownscaledImageData, invalid geometry");
528 assert(image !=
nullptr &&
"DonwscaledImageData, invalid parameter 'image'");
530 std::vector<unsigned char> result;
532 result.resize(w *
h * 4);
533 }
catch (
const std::bad_alloc &) {
534 NSLog(
@"DownscaledImageData, memory allocation failed");
539 if (!colorSpace.
Get()) {
540 NSLog(
@"DownscaledImageData, CGColorSpaceCreateDeviceRGB failed");
545 w * 4, colorSpace.
Get(),
546 kCGImageAlphaPremultipliedLast, NULL, 0));
548 NSLog(
@"DownscaledImageData, CGBitmapContextCreateWithData failed");
552 CGContextDrawImage(ctx.
Get(), CGRectMake(0, 0, w,
h), image);
557#pragma mark - "Focus management" - just make another window key window.
563 if (![NSApp isActive])
568 NSArray *
const orderedWindows = [NSApp orderedWindows];
569 for (NSWindow *nsWindow in orderedWindows) {
581 [qWindow makeKeyAndOrderFront : qWindow];
586#pragma mark - 'shape mask' - to create a window with arbitrary (probably non-rectangle) shape.
591 assert(view != nil &&
"ClipToShapeMask, parameter 'view' is nil");
592 assert(ctx != 0 &&
"ClipToShapeMask, parameter 'ctx' is null");
596 "ClipToShapeMask, fShapeCombineMask is nil on a top-level window");
598 "ClipToShapeMask, shape mask is null");
604 if (!view.fParentView) {
610 NSRect clipRect = view.frame;
612 clipRect.origin = [view.fParentView convertPoint : clipRect.origin
613 toView : [view window].contentView];
615 clipRect.origin.y + clipRect.size.height);
620 NSRectToCGRect(clipRect)));
621 clipRect.origin = NSPoint();
622 CGContextClipToMask(ctx, NSRectToCGRect(clipRect), clipImageGuard.
Get());
626 CGContextClipToRect(ctx, rect);
631#pragma mark - Window's geometry and attributes.
636 assert(attr != 0 &&
"SetWindowAttributes, parameter 'attr' is null");
637 assert(window != nil &&
"SetWindowAttributes, parameter 'window' is nil");
654 if ([(NSObject *)window isKindOfClass : [
QuartzWindow class]]) {
657 [qw setAlphaValue : 0.95];
667 assert(win != nil &&
"GetWindowGeometry, parameter 'win' is nil");
668 assert(dst != 0 &&
"GetWindowGeometry, parameter 'dst' is null");
680 assert(window != nil &&
"GetWindowAttributes, parameter 'window' is nil");
681 assert(dst != 0 &&
"GetWindowAttributes, parameter 'attr' is null");
690 dst->
fDepth = window.fDepth;
695 dst->
fClass = window.fClass;
729#pragma mark - Comparators (I need them when changing a window's z-order).
733#ifdef MAC_OS_X_VERSION_10_11
734NSComparisonResult
CompareViewsToLower(__kindof NSView *view1, __kindof NSView *view2,
void *context)
739 id topView = (
id)context;
740 if (view1 == topView)
741 return NSOrderedAscending;
742 if (view2 == topView)
743 return NSOrderedDescending;
745 return NSOrderedSame;
750#ifdef MAC_OS_X_VERSION_10_11
751NSComparisonResult
CompareViewsToRaise(__kindof NSView *view1, __kindof NSView *view2,
void *context)
756 id topView = (
id)context;
757 if (view1 == topView)
758 return NSOrderedDescending;
759 if (view2 == topView)
760 return NSOrderedAscending;
762 return NSOrderedSame;
765#pragma mark - Cursor's area.
770 assert(image != nil &&
"CursroHotSpot, parameter 'image' is nil");
772 const NSSize imageSize = image.size;
775 return NSMakePoint(imageSize.width, imageSize.height / 2);
777 return NSMakePoint(imageSize.width / 2, imageSize.height / 2);
784 const char *pngFileName = 0;
786 switch (currentCursor) {
788 pngFileName =
"move_cursor.png";
791 pngFileName =
"hor_arrow_cursor.png";
794 pngFileName =
"ver_arrow_cursor.png";
797 pngFileName =
"right_arrow_cursor.png";
800 pngFileName =
"rotate.png";
804 pngFileName =
"top_right_cursor.png";
808 pngFileName =
"top_left_cursor.png";
817 if (!path || path[0] == 0) {
822 NSString *nsPath = [NSString stringWithFormat :
@"%s", path];
823 NSImage *
const cursorImage = [[NSImage alloc] initWithContentsOfFile : nsPath];
829 NSCursor *
const customCursor = [[[NSCursor alloc] initWithImage : cursorImage
830 hotSpot : hotSpot] autorelease];
832 [cursorImage release];
852 NSCursor *cursor = nil;
853 switch (currentCursor) {
855 cursor = [NSCursor crosshairCursor];
858 cursor = [NSCursor arrowCursor];
861 cursor = [NSCursor openHandCursor];
864 cursor = [NSCursor resizeLeftCursor];
867 cursor = [NSCursor resizeRightCursor];
870 cursor = [NSCursor resizeUpCursor];
873 cursor = [NSCursor resizeDownCursor];
876 cursor = [NSCursor IBeamCursor];
894#pragma mark - Workarounds for a text view and its descendants.
905 return dynamic_cast<const TGTextView*
>(window);
911 assert(view != nil &&
"ViewIsTextView, parameter 'view' is nil");
919 assert(view != nil &&
"ViewIsTextViewFrame, parameter 'view' is nil");
934 if (!view.fParentView)
955 assert(view != nil &&
"ViewIsHtmlView, parameter 'view' is nil");
964 assert(view != nil &&
"ViewIsHtmlViewFrame, parameter 'view' is nil");
979 if (!view.fParentView)
988 assert(textView != nil &&
"FrameForTextView, parameter 'textView' is nil");
990 for (NSView<X11Window> *child in [textView subviews]) {
1001 assert(htmlView != nil &&
"FrameForHtmlView, parameter 'htmlView' is nil");
1003 for (NSView<X11Window> *child in [htmlView subviews]) {
1011#pragma mark - Workarounds for 'paint out of paint events'.
1016 assert(view != nil &&
"LockFocus, parameter 'view' is nil");
1017 assert([view isKindOfClass : [
QuartzView class]] &&
1018 "LockFocus, QuartzView is expected");
1020 if ([view lockFocusIfCanDraw]) {
1021 NSGraphicsContext *nsContext = [NSGraphicsContext currentContext];
1022 assert(nsContext != nil &&
"LockFocus, currentContext is nil");
1023 CGContextRef currContext = (CGContextRef)[nsContext graphicsPort];
1024 assert(currContext != 0 &&
"LockFocus, graphicsPort is null");
1037 assert(view != nil &&
"UnlockFocus, parameter 'view' is nil");
1038 assert([view isKindOfClass : [
QuartzView class]] &&
1039 "UnlockFocus, QuartzView is expected");
1054#ifdef DEBUG_ROOT_COCOA
1056#pragma mark - 'loggers'.
1066 static std::ofstream logfile(
"win_attr.txt");
1070 logfile<<
"win "<<winID<<
": BackPixmap\n";
1072 logfile<<
"win "<<winID<<
": BackPixel\n";
1074 logfile<<
"win "<<winID<<
": BorderPixmap\n";
1076 logfile<<
"win "<<winID<<
": BorderPixel\n";
1078 logfile<<
"win "<<winID<<
": BorderWidth\n";
1080 logfile<<
"win "<<winID<<
": BitGravity\n";
1082 logfile<<
"win "<<winID<<
": WinGravity\n";
1084 logfile<<
"win "<<winID<<
": BackingStore\n";
1086 logfile<<
"win "<<winID<<
": BackingPlanes\n";
1088 logfile<<
"win "<<winID<<
": BackingPixel\n";
1090 logfile<<
"win "<<winID<<
": OverrideRedirect\n";
1092 logfile<<
"win "<<winID<<
": SaveUnder\n";
1094 logfile<<
"win "<<winID<<
": EventMask\n";
1096 logfile<<
"win "<<winID<<
": DontPropagate\n";
1098 logfile<<
"win "<<winID<<
": Colormap\n";
1100 logfile<<
"win "<<winID<<
": Cursor\n";
1104void print_mask_info(
ULong_t mask)
1107 NSLog(
@"button press mask");
1109 NSLog(
@"button release mask");
1111 NSLog(
@"exposure mask");
1113 NSLog(
@"pointer motion mask");
1115 NSLog(
@"button motion mask");
1117 NSLog(
@"enter notify mask");
1119 NSLog(
@"leave notify mask");
1131#pragma mark - QuartzWindow's life cycle.
1134- (
id) initWithContentRect : (NSRect) contentRect styleMask : (NSUInteger) windowStyle
1135 backing : (NSBackingStoreType) bufferingType defer : (BOOL) deferCreation
1138 self = [
super initWithContentRect : contentRect styleMask : windowStyle
1139 backing : bufferingType defer : deferCreation];
1143 [
self setAllowsConcurrentViewDrawing : NO];
1145 self.delegate = self;
1147 NSRect contentViewRect = contentRect;
1148 contentViewRect.origin.x = 0.f;
1149 contentViewRect.origin.y = 0.f;
1153 [
self setContentView : fContentView];
1155 [fContentView release];
1173 assert(glView != nil &&
"-initWithGLView, parameter 'glView' is nil");
1178 NSRect contentRect = glView.frame;
1179 contentRect.origin = NSPoint();
1181 self = [
super initWithContentRect : contentRect styleMask : styleMask
1182 backing : NSBackingStoreBuffered defer : NO];
1186 [
self setAllowsConcurrentViewDrawing : NO];
1187 self.delegate = self;
1189 [
self setContentView : fContentView];
1201 [fShapeCombineMask release];
1212- (
void) setContentView:(NSView *)cv
1214 [
super setContentView:cv];
1222- (
void) setFIsDeleted : (BOOL) deleted
1227#pragma mark - Forwaring: I want to forward a lot of property setters/getters to the content view.
1230- (
void) forwardInvocation : (NSInvocation *) anInvocation
1235 if ([
fContentView respondsToSelector : [anInvocation selector]]) {
1236 [anInvocation invokeWithTarget : fContentView];
1238 [
super forwardInvocation : anInvocation];
1243- (NSMethodSignature*) methodSignatureForSelector : (
SEL) selector
1245 NSMethodSignature *signature = [
super methodSignatureForSelector : selector];
1249 signature = [fContentView methodSignatureForSelector : selector];
1264 assert(window != nil &&
"-addTransientWindow:, parameter 'window' is nil");
1273 [
self addChildWindow : window ordered : NSWindowAbove];
1279- (
void) makeKeyAndOrderFront : (
id) sender
1281#pragma unused(sender)
1286#ifdef MAC_OS_X_VERSION_10_9
1287 [
self setCollectionBehavior : NSWindowCollectionBehaviorMoveToActiveSpace];
1289 [
self setCollectionBehavior : NSWindowCollectionBehaviorCanJoinAllSpaces];
1292 [
super makeKeyAndOrderFront : self];
1294 [
self setCollectionBehavior : NSWindowCollectionBehaviorDefault];
1298- (
void) setFDelayedTransient : (BOOL) d
1313 [fShapeCombineMask release];
1321#pragma mark - X11Drawable's protocol.
1342 return self.screen.backingScaleFactor;
1360 return self.frame.size.width;
1369 assert(
fContentView != nil &&
"-fHeight:, content view is nil");
1375- (
void) setDrawableSize : (NSSize) newSize
1378 assert(!(newSize.width < 0) &&
"-setDrawableSize:, width is negative");
1379 assert(!(newSize.height < 0) &&
"-setDrawableSize:, height is negative");
1381 NSRect frame = self.frame;
1385 frame.origin.y = frame.origin.y + frame.size.height - newSize.height - dY;
1386 frame.size = newSize;
1387 frame.size.height += dY;
1388 [
self setFrame : frame display : YES];
1392- (
void) setX : (
int) x Y : (
int) y width : (
unsigned) w height : (
unsigned) h
1394 NSSize newSize = {};
1397 [
self setContentSize : newSize];
1400 NSPoint topLeft = {};
1404 [
self setFrameTopLeftPoint : topLeft];
1408- (
void) setX : (
int) x Y : (
int) y
1410 NSPoint topLeft = {};
1414 [
self setFrameTopLeftPoint : topLeft];
1419 clipOrigin : (
X11::Point) clipXY toPoint : (
X11::Point) dstPoint
1424 [fContentView copy : src area : area withMask : mask clipOrigin : clipXY toPoint : dstPoint];
1428- (
unsigned char *) readColorBits : (
X11::Rectangle) area
1433 return [fContentView readColorBits : area];
1436#pragma mark - X11Window protocol's implementation.
1447#pragma unused(parent)
1465- (
void) setFBackgroundPixel : (
unsigned long) backgroundColor
1471 CGFloat rgba[] = {0., 0., 0., 1.};
1474 [
self setBackgroundColor : [NSColor colorWithColorSpace : [NSColorSpace deviceRGBColorSpace] components : rgba count : 4]];
1505 assert(child != nil &&
"-addChild:, parameter 'child' is nil");
1509 assert([child isKindOfClass : [
QuartzView class]] &&
1510 "-addChild: gl view in a top-level window as content view is not supported");
1513 [
self setContentView : child];
1516 [fContentView addChild : child];
1525 assert(attr &&
"-getAttributes:, parameter 'attr' is nil");
1533 assert(attr != 0 &&
"-setAttributes:, parameter 'attr' is null");
1535#ifdef DEBUG_ROOT_COCOA
1536 log_attributes(attr, self.fID);
1550 [fContentView setHidden : NO];
1551 [
self makeKeyAndOrderFront : self];
1552 [fContentView configureNotifyTree];
1556 [fMainWindow addChildWindow : self ordered : NSWindowAbove];
1568 [fContentView setHidden : NO];
1569 [
self makeKeyAndOrderFront : self];
1570 [fContentView configureNotifyTree];
1574 [fMainWindow addChildWindow : self ordered : NSWindowAbove];
1586 [fContentView mapSubwindows];
1587 [fContentView configureNotifyTree];
1596 [fContentView setHidden : YES];
1597 [
self orderOut : self];
1600 [fMainWindow removeChildWindow : self];
1605#pragma mark - Events.
1608- (
void) sendEvent : (NSEvent *) theEvent
1618 bool generateFakeRelease =
false;
1620 const NSPoint windowPoint = [theEvent locationInWindow];
1622 if (windowPoint.x <= 4 || windowPoint.x >= self.fWidth - 4)
1623 generateFakeRelease =
true;
1625 if (windowPoint.y <= 4 || windowPoint.y >= self.fHeight - 4)
1626 generateFakeRelease =
true;
1628 const NSPoint viewPoint = [fContentView convertPoint : windowPoint fromView : nil];
1630 if (viewPoint.y <= 0 && windowPoint.y >= 0)
1631 generateFakeRelease =
true;
1634 "-sendEvent:, gVirtualX is either null or not of TGCocoa type");
1648 [
super sendEvent : theEvent];
1651#pragma mark - NSWindowDelegate's methods.
1654- (BOOL) windowShouldClose : (
id) sender
1656#pragma unused(sender)
1660 if ([[self childWindows] count])
1672 "-windowShouldClose:, gVirtualX is either null or has a type different from TGCocoa");
1681- (
void) windowDidBecomeKey : (NSNotification *) aNotification
1683#pragma unused(aNotification)
1692 "-windowDidBecomeKey:, gVirtualX is null or not of TGCocoa type");
1700- (
void) windowDidResignKey : (NSNotification *) aNotification
1702#pragma unused(aNotification)
1708#pragma mark - Passive key grab info.
1713- (
id) initWithKey : (unichar) keyCode modifiers : (NSUInteger) modifiers
1715 if (self = [super
init]) {
1724- (BOOL) matchKey : (unichar) keyCode modifiers : (NSUInteger) modifiers
1730- (BOOL) matchKey : (unichar) keyCode
1749#pragma mark - X11 property emulation.
1751@interface QuartzWindowProperty : NSObject {
1752 NSData *fPropertyData;
1761@implementation QuartzWindowProperty
1766- (
id) initWithData : (
unsigned char *) data size : (
unsigned) dataSize type : (
Atom_t) type format : (
unsigned) format
1768 if (self = [super
init]) {
1770 fPropertyData = nil;
1774 [
self resetPropertyData : data size : dataSize type : type format : format];
1783 [fPropertyData release];
1789- (
void) resetPropertyData : (
unsigned char *) data size : (
unsigned) dataSize
1790 type : (
Atom_t) type format : (
unsigned) format
1792 [fPropertyData release];
1797 else if (format == 32)
1800 fPropertyData = [[NSData dataWithBytes : data length : dataSize] retain];
1806- (NSData *) fPropertyData
1808 return fPropertyData;
1819#pragma mark - QuartzView.
1852#pragma mark - Lifetime.
1857 if (self = [super initWithFrame : frame]) {
1869 [
self setCanDrawConcurrently : NO];
1871 [
self setHidden : YES];
1891 [fBackBuffer release];
1892 [fPassiveKeyGrabs release];
1893 [fX11Properties release];
1894 [fBackgroundPixmap release];
1898#pragma mark - Tracking area.
1903- (
void) updateTrackingAreas
1905 [
super updateTrackingAreas];
1912 if (NSArray *trackingArray = [self trackingAreas]) {
1913 const NSUInteger size = [trackingArray count];
1914 for (NSUInteger i = 0; i < size; ++i) {
1915 NSTrackingArea *
const t = [trackingArray objectAtIndex : i];
1916 [
self removeTrackingArea : t];
1920 const NSUInteger trackerOptions = NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited |
1921 NSTrackingActiveInActiveApp | NSTrackingInVisibleRect |
1922 NSTrackingEnabledDuringMouseDrag | NSTrackingCursorUpdate;
1925 frame.size.width = self.fWidth;
1926 frame.size.height = self.fHeight;
1928 NSTrackingArea *
const tracker = [[NSTrackingArea alloc] initWithRect : frame
1929 options : trackerOptions owner : self userInfo : nil];
1930 [
self addTrackingArea : tracker];
1935- (
void) updateTrackingAreasAfterRaise
1937 [
self updateTrackingAreas];
1939 for (
QuartzView *childView in [self subviews])
1940 [childView updateTrackingAreasAfterRaise];
1943#pragma mark - X11Drawable protocol.
1960 return self.fQuartzWindow.fScaleFactor;
1966 return self.frame.origin.x;
1972 return self.frame.origin.y;
1978 return self.frame.size.width;
1984 return self.frame.size.height;
1988- (
void) setDrawableSize : (NSSize) newSize
1990 assert(!(newSize.width < 0) &&
"-setDrawableSize, width is negative");
1991 assert(!(newSize.height < 0) &&
"-setDrawableSize, height is negative");
1997 NSRect frame = self.frame;
1998 frame.size = newSize;
2004- (
void) setX : (
int) x Y : (
int) y width : (
unsigned) w height : (
unsigned) h
2006 NSRect newFrame = {};
2007 newFrame.origin.x =
x;
2008 newFrame.origin.y =
y;
2009 newFrame.size.width = w;
2010 newFrame.size.height =
h;
2012 self.frame = newFrame;
2016- (
void) setX : (
int) x Y : (
int) y
2018 NSRect newFrame = self.frame;
2019 newFrame.origin.x =
x;
2020 newFrame.origin.y =
y;
2022 self.frame = newFrame;
2028 toPoint : (
X11::Point) dstPoint
2031 assert(srcImage != nil &&
2032 "-copyImage:area:withMask:clipOrigin:toPoint:, parameter 'srcImage' is nil");
2033 assert(srcImage.
fImage != nil &&
2034 "-copyImage:area:withMask:clipOrigin:toPoint:, srcImage.fImage is nil");
2037 assert(self.fContext != 0 &&
2038 "-copyImage:area:withMask:clipOrigin:toPoint:, self.fContext is null");
2041 NSLog(
@"QuartzView: -copyImage:area:withMask:clipOrigin:toPoint:,"
2042 " srcRect and copyRect do not intersect");
2048 CGImageRef subImage = 0;
2049 bool needSubImage =
false;
2050 if (area.fX || area.fY || area.fWidth != srcImage.
fWidth || area.fHeight != srcImage.
fHeight) {
2051 needSubImage =
true;
2054 NSLog(
@"QuartzView: -copyImage:area:withMask:clipOrigin:toPoint:,"
2055 " subimage creation failed");
2059 subImage = srcImage.
fImage;
2065 CGContextTranslateCTM(self.fContext, 0., self.fHeight);
2066 CGContextScaleCTM(self.fContext, 1., -1.);
2070 assert(mask.
fImage != nil &&
2071 "-copyImage:area:withMask:clipOrigin:toPoint:, mask.fImage is nil");
2072 assert(CGImageIsMask(mask.
fImage) ==
true &&
2073 "-copyImage:area:withMask:clipOrigin:toPoint:, mask.fImage is not a mask");
2077 const CGRect clipRect = CGRectMake(clipXY.fX, clipY, mask.
fWidth, mask.
fHeight);
2078 CGContextClipToMask(self.fContext, clipRect, mask.
fImage);
2085 const CGRect imageRect = CGRectMake(dstPoint.fX, dstY, area.fWidth, area.fHeight);
2086 CGContextDrawImage(self.fContext, imageRect, subImage);
2089 CGImageRelease(subImage);
2093- (
void) copyView : (
QuartzView *) srcView area : (
X11::Rectangle) area toPoint : (
X11::Point) dstPoint
2098 assert(srcView != nil &&
"-copyView:area:toPoint:, parameter 'srcView' is nil");
2100 const NSRect frame = [srcView frame];
2102 NSBitmapImageRep *
const imageRep = [srcView bitmapImageRepForCachingDisplayInRect : frame];
2104 NSLog(
@"QuartzView: -copyView:area:toPoint failed");
2108 assert(srcView != nil &&
"-copyView:area:toPoint:, parameter 'srcView' is nil");
2109 assert(self.fContext != 0 &&
"-copyView:area:toPoint, self.fContext is null");
2114 CGContextRef ctx = srcView.
fContext;
2116 [srcView cacheDisplayInRect : frame toBitmapImageRep : imageRep];
2120 const CGRect subImageRect = CGRectMake(area.fX, area.fY, area.fWidth, area.fHeight);
2123 if (!subImage.Get()) {
2124 NSLog(
@"QuartzView: -copyView:area:toPoint, CGImageCreateWithImageInRect failed");
2129 const CGRect imageRect = CGRectMake(dstPoint.fX,
2130 [self visibleRect].size.height - (CGFloat(dstPoint.fY) + area.fHeight),
2131 area.fWidth, area.fHeight);
2133 CGContextTranslateCTM(self.fContext, 0., [self visibleRect].size.height);
2134 CGContextScaleCTM(self.fContext, 1., -1.);
2136 CGContextDrawImage(self.fContext, imageRect, subImage.Get());
2141 withMask : (
QuartzImage *) mask clipOrigin : (
X11::Point) clipXY toPoint : (
X11::Point) dstPoint
2144 assert(srcPixmap != nil &&
"-copyPixmap:area:withMask:clipOrigin:toPoint:, parameter 'srcPixmap' is nil");
2147 NSLog(
@"QuartzView: -copyPixmap:area:withMask:clipOrigin:toPoint,"
2148 " no intersection between pixmap rectangle and cropArea");
2153 assert(self.fContext != 0 &&
2154 "-copyPixmap:area:withMask:clipOrigin:toPoint:, self.fContext is null");
2159 CGContextTranslateCTM(self.fContext, 0., self.frame.size.height);
2160 CGContextScaleCTM(self.fContext, 1., -1.);
2163 assert(imageFromPixmap.Get() != 0 &&
2164 "-copyPixmap:area:withMask:clipOrigin:toPoint:, createImageFromPixmap failed");
2166 CGImageRef subImage = 0;
2167 bool needSubImage =
false;
2168 if (area.fX || area.fY || area.fWidth != srcPixmap.
fWidth || area.fHeight != srcPixmap.
fHeight) {
2169 needSubImage =
true;
2170 const CGRect subImageRect = CGRectMake(area.fX, area.fY, area.fHeight, area.fWidth);
2171 subImage = CGImageCreateWithImageInRect(imageFromPixmap.Get(), subImageRect);
2173 NSLog(
@"QuartzView: -copyImage:area:withMask:clipOrigin:toPoint:,"
2174 " subimage creation failed");
2178 subImage = imageFromPixmap.Get();
2181 assert(mask.
fImage != nil &&
2182 "-copyPixmap:area:withMask:clipOrigin:toPoint:, mask.fImage is nil");
2183 assert(CGImageIsMask(mask.
fImage) ==
true &&
2184 "-copyPixmap:area:withMask:clipOrigin:toPoint:, mask.fImage is not a mask");
2189 const CGRect clipRect = CGRectMake(clipXY.fX, clipY, mask.
fWidth, mask.
fHeight);
2190 CGContextClipToMask(self.fContext, clipRect, mask.
fImage);
2195 const CGRect imageRect = CGRectMake(dstPoint.fX, dstY, area.fWidth, area.fHeight);
2196 CGContextDrawImage(self.fContext, imageRect, imageFromPixmap.Get());
2199 CGImageRelease(subImage);
2205 toPoint : (
X11::Point) dstPoint
2207 assert(srcImage != nil &&
"-copyImage:area:toPoint:, parameter 'srcImage' is nil");
2208 assert(srcImage.
fImage != nil &&
"-copyImage:area:toPoint:, srcImage.fImage is nil");
2209 assert(self.fContext != 0 &&
"-copyImage:area:toPoint:, fContext is null");
2212 NSLog(
@"QuartzView: -copyImage:area:toPoint, image and copy area do not intersect");
2216 CGImageRef subImage = 0;
2217 bool needSubImage =
false;
2218 if (area.fX || area.fY || area.fWidth != srcImage.
fWidth || area.fHeight != srcImage.
fHeight) {
2219 needSubImage =
true;
2222 NSLog(
@"QuartzView: -copyImage:area:toPoint:, subimage creation failed");
2226 subImage = srcImage.
fImage;
2230 CGContextTranslateCTM(self.fContext, 0., self.fHeight);
2231 CGContextScaleCTM(self.fContext, 1., -1.);
2236 const CGRect imageRect = CGRectMake(dstPoint.fX, dstY, area.fWidth, area.fHeight);
2237 CGContextDrawImage(self.fContext, imageRect, subImage);
2240 CGImageRelease(subImage);
2245 withMask : (
QuartzImage *)mask clipOrigin : (
X11::Point) clipXY toPoint : (
X11::Point) dstPoint
2247 assert(src != nil &&
"-copy:area:withMask:clipOrigin:toPoint:, parameter 'src' is nil");
2248 assert(area.fWidth && area.fHeight &&
"-copy:area:withMask:clipOrigin:toPoint:, area to copy is empty");
2254 [
self copyView : (QuartzView *)qw.fContentView area : area toPoint : dstPoint];
2255 }
else if ([src isKindOfClass : [
QuartzView class]]) {
2257 [
self copyView : (QuartzView *)src area : area toPoint : dstPoint];
2258 }
else if ([src isKindOfClass : [
QuartzPixmap class]]) {
2259 [
self copyPixmap : (QuartzPixmap *)src area : area withMask : mask clipOrigin : clipXY toPoint : dstPoint];
2260 }
else if ([src isKindOfClass : [
QuartzImage class]]) {
2261 [
self copyImage : (QuartzImage *)src area : area withMask : mask clipOrigin : clipXY toPoint : dstPoint];
2263 assert(0 &&
"-copy:area:withMask:clipOrigin:toPoint:, src is of unknown type");
2268- (
unsigned char *) readColorBits : (
X11::Rectangle) area
2274 assert(area.fWidth && area.fHeight &&
"-readColorBits:, area to copy is empty");
2277 const NSRect visRect = [
self visibleRect];
2278 const X11::Rectangle srcRect(
int(visRect.origin.x),
int(visRect.origin.y),
2279 unsigned(visRect.size.width),
unsigned(visRect.size.height));
2282 NSLog(
@"QuartzView: -readColorBits:, visible rect of view and copy area do not intersect");
2287 NSBitmapImageRep *
const imageRep = [
self bitmapImageRepForCachingDisplayInRect : visRect];
2289 NSLog(
@"QuartzView: -readColorBits:, bitmapImageRepForCachingDisplayInRect failed");
2293 CGContextRef ctx = self.fContext;
2294 [
self cacheDisplayInRect : visRect toBitmapImageRep : imageRep];
2295 self.fContext = ctx;
2297 const NSInteger bitsPerPixel = [imageRep bitsPerPixel];
2299 assert(bitsPerPixel == 32 &&
"-readColorBits:, no alpha channel???");
2300 const NSInteger bytesPerRow = [imageRep bytesPerRow];
2301 unsigned dataWidth = bytesPerRow / (bitsPerPixel / 8);
2303 unsigned char *srcData =
nullptr;
2304 std::vector<unsigned char> downscaled;
2305 if ([self.window.screen backingScaleFactor] > 1 && imageRep.CGImage) {
2307 if (downscaled.size())
2308 srcData = &downscaled[0];
2309 dataWidth = area.fWidth;
2311 srcData = [imageRep bitmapData];
2314 NSLog(
@"QuartzView: -readColorBits:, failed to obtain backing store contents");
2319 unsigned char *data =
nullptr;
2322 data =
new unsigned char[area.fWidth * area.fHeight * 4];
2323 }
catch (
const std::bad_alloc &) {
2324 NSLog(
@"QuartzView: -readColorBits:, memory allocation failed");
2328 unsigned char *dstPixel = data;
2329 const unsigned char *
line = srcData + area.
fY * dataWidth * 4;
2330 const unsigned char *srcPixel =
line + area.
fX * 4;
2332 for (
unsigned i = 0; i < area.fHeight; ++i) {
2333 for (
unsigned j = 0; j < area.fWidth; ++j, srcPixel += 4, dstPixel += 4) {
2334 dstPixel[0] = srcPixel[2];
2335 dstPixel[1] = srcPixel[1];
2336 dstPixel[2] = srcPixel[0];
2337 dstPixel[3] = srcPixel[3];
2340 line += dataWidth * 4;
2341 srcPixel =
line + area.
fX * 4;
2351 [fBackgroundPixmap release];
2370 if ([self isHidden])
2374 if ([parent isHidden])
2392- (
void) setFHasFocus : (BOOL) focus
2394#pragma unused(focus)
2411 [fBackBuffer release];
2445- (
void) activateGrab : (
unsigned) eventMask ownerEvents : (BOOL) ownerEvents
2461- (BOOL) acceptsCrossingEvents : (
unsigned) eventMask
2482 assert(child != nil &&
"-addChild:, parameter 'child' is nil");
2484 [
self addSubview : child];
2491 assert(attr != 0 &&
"-getAttributes:, parameter 'attr' is null");
2499 assert(attr != 0 &&
"-setAttributes:, parameter 'attr' is null");
2501#ifdef DEBUG_ROOT_COCOA
2502 log_attributes(attr,
fID);
2513 [
self removeFromSuperview];
2514 [parent addSubview : self];
2515 [
self setHidden : NO];
2521 [
self setHidden : NO];
2534 [
self setHidden : YES];
2544- (
void) setOverlapped : (BOOL) overlap
2547 for (NSView<X11Window> *child in [self subviews])
2548 [child setOverlapped : overlap];
2565 using namespace X11;
2568 if (self == sibling)
2570 if ([sibling isHidden])
2573 if (NSEqualRects(sibling.frame, self.frame)) {
2574 [sibling setOverlapped : YES];
2575 [sibling setHidden : YES];
2579 [
self setOverlapped : NO];
2581 [
self setHidden : NO];
2583 [fParentView sortSubviewsUsingFunction : CompareViewsToRaise context : (void *)self];
2585 [
self updateTrackingAreasAfterRaise];
2587 [
self setNeedsDisplay : YES];
2595 using namespace X11;
2597 NSEnumerator *
const reverseEnumerator = [[fParentView subviews] reverseObjectEnumerator];
2598 for (
QuartzView *sibling in reverseEnumerator) {
2599 if (sibling == self)
2602 if (NSEqualRects(sibling.frame, self.frame)) {
2603 [sibling setOverlapped : NO];
2605 [sibling setHidden : NO];
2607 [sibling setNeedsDisplay : YES];
2608 [
self setOverlapped : YES];
2610 [
self setHidden : YES];
2616 [fParentView sortSubviewsUsingFunction : CompareViewsToLower context : (void*)self];
2633 "-configureNotifyTree, gVirtualX is either null or has type different from TGCocoa");
2638 for (NSView<X11Window> *
v in [self subviews])
2639 [v configureNotifyTree];
2643#pragma mark - Key grabs.
2646- (
void) addPassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers
2648 [
self removePassiveKeyGrab : keyCode modifiers : modifiers];
2650 modifiers : modifiers];
2651 [fPassiveKeyGrabs addObject : newGrab];
2656- (
void) removePassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers
2658 const NSUInteger count = [fPassiveKeyGrabs count];
2659 for (NSUInteger i = 0; i < count; ++i) {
2661 if ([grab matchKey : keyCode modifiers : modifiers]) {
2662 [fPassiveKeyGrabs removeObjectAtIndex : i];
2669- (
PassiveKeyGrab *) findPassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers
2671 NSEnumerator *
const enumerator = [fPassiveKeyGrabs objectEnumerator];
2673 if ([grab matchKey : keyCode modifiers : modifiers])
2684 NSEnumerator *
const enumerator = [fPassiveKeyGrabs objectEnumerator];
2686 if ([grab matchKey : keyCode])
2693#pragma mark - Painting mechanics.
2696- (
void) drawRect : (NSRect) dirtyRect
2698#pragma unused(dirtyRect)
2700 using namespace X11;
2708 NSGraphicsContext *
const nsContext = [NSGraphicsContext currentContext];
2709 assert(nsContext != nil &&
"-drawRect:, currentContext returned nil");
2714 fContext = (CGContextRef)[nsContext graphicsPort];
2715 assert(
fContext != 0 &&
"-drawRect:, graphicsPort returned null");
2720 if (self.fQuartzWindow.fShapeCombineMask)
2732 [NSColor.whiteColor setFill];
2733 NSRectFill(dirtyRect);
2751 gClient->CancelRedraw(window);
2759 [
self copy : fBackBuffer area : copyArea withMask : nil
2760 clipOrigin : X11::Point() toPoint : X11::Point()];
2764#ifdef DEBUG_ROOT_COCOA
2765 CGContextSetRGBStrokeColor(
fContext, 1., 0., 0., 1.);
2766 CGContextStrokeRect(
fContext, dirtyRect);
2771#ifdef DEBUG_ROOT_COCOA
2772 NSLog(
@"QuartzView: -drawRect: method, no window for id %u was found",
fID);
2778#pragma mark - Geometry.
2781- (
void) setFrame : (NSRect) newFrame
2786 if (NSEqualRects(newFrame, self.frame))
2789 [
super setFrame : newFrame];
2793- (
void) setFrameSize : (NSSize) newSize
2797 [
super setFrameSize : newSize];
2801 "setFrameSize:, gVirtualX is either null or has a type, different from TGCocoa");
2806 [
self setNeedsDisplay : YES];
2809#pragma mark - Event handling.
2812- (
void) mouseDown : (NSEvent *) theEvent
2814 assert(
fID != 0 &&
"-mouseDown:, fID is 0");
2817 "-mouseDown:, gVirtualX is either null or has a type, different from TGCocoa");
2823- (
void) scrollWheel : (NSEvent*) theEvent
2825 assert(
fID != 0 &&
"-scrollWheel:, fID is 0");
2829 "-scrollWheel:, gVirtualX is either null or has a type, different from TGCocoa");
2832 const CGFloat deltaY = [theEvent deltaY];
2836 }
else if (deltaY > 0) {
2842#ifdef DEBUG_ROOT_COCOA
2844- (
void) printViewInformation
2846 assert(
fID != 0 &&
"-printWindowInformation, fID is 0");
2848 assert(window != 0 &&
"printWindowInformation, window not found");
2850 NSLog(
@"-----------------View %u info:---------------------",
fID);
2851 NSLog(
@"ROOT's window class is %s", window->IsA()->
GetName());
2852 NSLog(
@"event mask is:");
2854 NSLog(
@"grab mask is:");
2856 NSLog(
@"view's geometry: x == %g, y == %g, w == %g, h == %g", self.frame.origin.x,
2857 self.frame.origin.y, self.frame.size.width, self.frame.size.height);
2858 NSLog(
@"----------------End of view info------------------");
2863- (
void) rightMouseDown : (NSEvent *) theEvent
2865 assert(
fID != 0 &&
"-rightMouseDown:, fID is 0");
2867#ifdef DEBUG_ROOT_COCOA
2868 [
self printViewInformation];
2872 "-rightMouseDown:, gVirtualX is either null or has type different from TGCocoa");
2878- (
void) otherMouseDown : (NSEvent *) theEvent
2880 assert(
fID != 0 &&
"-otherMouseDown:, fID is 0");
2884 if ([theEvent buttonNumber] == 2) {
2888 "-otherMouseDown:, gVirtualX is either null or has type different from TGCocoa");
2895- (
void) mouseUp : (NSEvent *) theEvent
2897 assert(
fID != 0 &&
"-mouseUp:, fID is 0");
2900 "-mouseUp:, gVirtualX is either null or has type different from TGCocoa");
2906- (
void) rightMouseUp : (NSEvent *) theEvent
2909 assert(
fID != 0 &&
"-rightMouseUp:, fID is 0");
2912 "-rightMouseUp:, gVirtualX is either null or has type different from TGCocoa");
2919- (
void) otherMouseUp : (NSEvent *) theEvent
2921 assert(
fID != 0 &&
"-otherMouseUp:, fID is 0");
2925 "-otherMouseUp:, gVirtualX is either null or has type different from TGCocoa");
2931- (
void) mouseEntered : (NSEvent *) theEvent
2933 assert(
fID != 0 &&
"-mouseEntered:, fID is 0");
2935 "-mouseEntered:, gVirtualX is null or not of TGCocoa type");
2942- (
void) mouseExited : (NSEvent *) theEvent
2944 assert(
fID != 0 &&
"-mouseExited:, fID is 0");
2947 "-mouseExited:, gVirtualX is null or not of TGCocoa type");
2954- (
void) mouseMoved : (NSEvent *) theEvent
2956 assert(
fID != 0 &&
"-mouseMoved:, fID is 0");
2962 "-mouseMoved:, gVirtualX is null or not of TGCocoa type");
2969- (
void) mouseDragged : (NSEvent *) theEvent
2971 assert(
fID != 0 &&
"-mouseDragged:, fID is 0");
2974 assert(vx != 0 &&
"-mouseDragged:, gVirtualX is null or not of TGCocoa type");
2980- (
void) rightMouseDragged : (NSEvent *) theEvent
2982 assert(
fID != 0 &&
"-rightMouseDragged:, fID is 0");
2985 "-rightMouseDragged:, gVirtualX is null or not of TGCocoa type");
2992- (
void) otherMouseDragged : (NSEvent *) theEvent
2994 assert(
fID != 0 &&
"-otherMouseDragged:, fID is 0");
2996 if ([theEvent buttonNumber] == 2) {
2998 "-otherMouseDragged:, gVirtualX is null or not of TGCocoa type");
3005- (
void) keyDown : (NSEvent *) theEvent
3007 assert(
fID != 0 &&
"-keyDown:, fID is 0");
3010 "-keyDown:, gVirtualX is null or not of TGCocoa type");
3012 NSView<X11Window> *eventView = self;
3014 eventView = pointerView;
3021- (
void) keyUp : (NSEvent *) theEvent
3023 assert(
fID != 0 &&
"-keyUp:, fID is 0");
3026 "-keyUp:, gVirtualX is null or not of TGCocoa type");
3029 NSView<X11Window> *eventView = self;
3031 eventView = pointerView;
3036#pragma mark - First responder stuff.
3039- (BOOL) acceptsFirstMouse : (NSEvent *) theEvent
3041#pragma unused(theEvent)
3046- (BOOL) acceptsFirstResponder
3051#pragma mark - Cursors.
3058 [
self.fQuartzWindow invalidateCursorRectsForView : self];
3063- (NSCursor *) createCustomCursor
3065 const char *pngFileName = 0;
3069 pngFileName =
"move_cursor.png";
3072 pngFileName =
"hor_arrow_cursor.png";
3075 pngFileName =
"ver_arrow_cursor.png";
3078 pngFileName =
"right_arrow_cursor.png";
3081 pngFileName =
"rotate.png";
3085 pngFileName =
"top_right_cursor.png";
3089 pngFileName =
"top_left_cursor.png";
3098 if (!path || path[0] == 0) {
3103 NSString *nsPath = [NSString stringWithFormat : @"%s", path];
3104 NSImage *
const cursorImage = [[NSImage alloc] initWithContentsOfFile : nsPath];
3110 NSCursor *
const customCursor = [[[NSCursor alloc] initWithImage : cursorImage
3111 hotSpot : hotSpot] autorelease];
3113 [cursorImage release];
3115 return customCursor;
3122- (
void) resetCursorRects
3125 [
self addCursorRect : self.visibleRect cursor : cursor];
3129- (
void) cursorUpdate
3139- (
void) cursorUpdate : (NSEvent *) event
3141#pragma unused(event)
3153 [
self performSelector : @selector(cursorUpdate) withObject : nil afterDelay : 0.05f];
3156#pragma mark - Emulated X11 properties.
3159- (
void) setProperty : (const
char *) propName data : (
unsigned char *) propData
3160 size : (
unsigned) dataSize forType : (
Atom_t) dataType format : (
unsigned) format
3162 assert(propName != 0 &&
"-setProperty:data:size:forType:, parameter 'propName' is null");
3163 assert(propData != 0 &&
"-setProperty:data:size:forType:, parameter 'propData' is null");
3164 assert(dataSize != 0 &&
"-setProperty:data:size:forType:, parameter 'dataSize' is 0");
3166 NSString *
const key = [NSString stringWithCString : propName encoding : NSASCIIStringEncoding];
3167 QuartzWindowProperty *
property = (QuartzWindowProperty *)[
fX11Properties valueForKey : key];
3171 [property resetPropertyData : propData size : dataSize type : dataType format : format];
3174 property = [[QuartzWindowProperty alloc] initWithData : propData size : dataSize
3175 type : dataType format : format];
3176 [fX11Properties setObject : property forKey : key];
3182- (BOOL) hasProperty : (const
char *) propName
3184 assert(propName != 0 &&
"-hasProperty:, propName parameter is null");
3186 NSString *
const key = [NSString stringWithCString : propName encoding : NSASCIIStringEncoding];
3187 QuartzWindowProperty *
const property = (QuartzWindowProperty *)[
fX11Properties valueForKey : key];
3189 return property != nil;
3193- (
unsigned char *) getProperty : (const
char *) propName returnType : (
Atom_t *) type
3194 returnFormat : (
unsigned *) format nElements : (
unsigned *) nElements
3196 assert(propName != 0 &&
3197 "-getProperty:returnType:returnFormat:nElements:, parameter 'propName' is null");
3199 "-getProperty:returnType:returnFormat:nElements:, parameter 'type' is null");
3200 assert(format != 0 &&
3201 "-getProperty:returnType:returnFormat:nElements:, parameter 'format' is null");
3202 assert(nElements != 0 &&
3203 "-getProperty:returnType:returnFormat:nElements:, parameter 'nElements' is null");
3205 NSString *
const key = [NSString stringWithCString : propName encoding : NSASCIIStringEncoding];
3206 QuartzWindowProperty *
const property = (QuartzWindowProperty *)[
fX11Properties valueForKey : key];
3207 assert(property != 0 &&
3208 "-getProperty:returnType:returnFormat:nElements, property not found");
3210 NSData *
const propData =
property.fPropertyData;
3212 const NSUInteger dataSize = [propData length];
3213 unsigned char *buff = 0;
3215 buff =
new unsigned char[dataSize]();
3216 }
catch (
const std::bad_alloc &) {
3218 NSLog(
@"QuartzWindow: -getProperty:returnType:returnFormat:nElements:,"
3219 " memory allocation failed");
3223 [propData getBytes : buff length : dataSize];
3224 *format =
property.fFormat;
3226 *nElements = dataSize;
3229 *nElements= dataSize / 2;
3230 else if (*format == 32)
3231 *nElements = dataSize / 4;
3233 *
type =
property.fType;
3239- (
void) removeProperty : (const
char *) propName
3241 assert(propName != 0 &&
"-removeProperty:, parameter 'propName' is null");
3243 NSString *
const key = [NSString stringWithCString : propName
3244 encoding : NSASCIIStringEncoding];
3245 [fX11Properties removeObjectForKey : key];
3250- (NSDragOperation) draggingEntered : (
id<NSDraggingInfo>) sender
3252 NSPasteboard *
const pasteBoard = [sender draggingPasteboard];
3253 const NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
3255 if ([[pasteBoard types] containsObject : NSFilenamesPboardType] && (sourceDragMask & NSDragOperationCopy))
3256 return NSDragOperationCopy;
3258 return NSDragOperationNone;
3262- (BOOL) performDragOperation : (
id<NSDraggingInfo>) sender
3273 NSPasteboard *
const pasteBoard = [sender draggingPasteboard];
3274 const NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
3276 if ([[pasteBoard types] containsObject : NSFilenamesPboardType] && (sourceDragMask & NSDragOperationCopy)) {
3282 NSArray *
const files = [pasteBoard propertyListForType : NSFilenamesPboardType];
3283 for (NSString *path in files) {
3285 NSString *
const item = [@"file://" stringByAppendingString : path];
3287 const NSUInteger len = [item lengthOfBytesUsingEncoding : NSASCIIStringEncoding] + 1;
3289 std::vector<unsigned char> propertyData(len);
3290 [item getCString : (char *)&propertyData[0] maxLength : propertyData.size()
3291 encoding : NSASCIIStringEncoding];
3293 NSView<X11Window> *
const targetView = self.fQuartzWindow.fContentView;
3294 [targetView setProperty : "_XC_DND_DATA" data : &propertyData[0]
3295 size : propertyData.size() forType : textUriAtom format : 8];
3296 }
catch (
const std::bad_alloc &) {
3298 NSLog(
@"QuartzView: -performDragOperation:, memory allocation failed");
3314 event1.
fUser[2] = textUriAtom;
3324 event2.
fUser[2] = 0;
3325 NSPoint dropPoint = [sender draggingLocation];
3328 dropPoint = [
self convertPoint : dropPoint fromView : nil];
const Mask_t kWABorderPixel
const Mask_t kWAOverrideRedirect
const Mask_t kWABitGravity
const Mask_t kWADontPropagate
const Mask_t kButtonMotionMask
const Mask_t kWABackingStore
const Mask_t kButtonPressMask
const Mask_t kExposureMask
const Mask_t kWAEventMask
const Mask_t kWASaveUnder
const Mask_t kWABackPixel
const Mask_t kWAWinGravity
const Mask_t kWABackingPixel
const Mask_t kPointerMotionMask
const Mask_t kLeaveWindowMask
const Mask_t kStructureNotifyMask
const Mask_t kButtonReleaseMask
const Mask_t kWABorderPixmap
const Mask_t kEnterWindowMask
const Mask_t kWABackPixmap
const Mask_t kWABorderWidth
const Mask_t kWABackingPlanes
typedef void((*Func_t)())
R__EXTERN TSystem * gSystem
void RemoveGraphicsOperationsForWindow(Window_t wid)
void GenerateFocusChangeEvent(NSView< X11Window > *eventView)
void GenerateExposeEvent(NSView< X11Window > *view, const NSRect &exposedRect)
void GenerateConfigureNotifyEvent(NSView< X11Window > *view, const NSRect &newFrame)
void GenerateCrossingEvent(NSEvent *theEvent)
bool HasPointerGrab() const
void GenerateKeyReleaseEvent(NSView< X11Window > *eventView, NSEvent *theEvent)
void GenerateKeyPressEvent(NSView< X11Window > *eventView, NSEvent *theEvent)
void GenerateButtonPressEvent(NSView< X11Window > *eventView, NSEvent *theEvent, EMouseButton btn)
void GeneratePointerMotionEvent(NSEvent *theEvent)
void GenerateButtonReleaseEvent(NSView< X11Window > *eventView, NSEvent *theEvent, EMouseButton btn)
This class implements TVirtualX interface for MacOS X, using Cocoa and Quartz 2D.
ROOT::MacOSX::X11::CommandBuffer * GetCommandBuffer() const
static Atom_t fgDeleteWindowAtom
ROOT::MacOSX::X11::Rectangle GetDisplayGeometry() const
ROOT::MacOSX::X11::EventTranslator * GetEventTranslator() const
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
static const TString & GetIconPath()
Get the icon path in the installation. Static utility function.
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
ROOT::MacOSX::Util::CFScopeGuard< CGImageRef > fImage
QuartzPixmap * fBackBuffer
unsigned fPassiveGrabKeyModifiers
void activateImplicitGrab()
NSMutableArray * fPassiveKeyGrabs
BOOL fActiveGrabOwnerEvents
QuartzWindow * fQuartzWindow
void configureNotifyTree()
void activatePassiveGrab()
NSMutableDictionary * fX11Properties
BOOL fPassiveGrabOwnerEvents
unsigned fPassiveGrabEventMask
QuartzImage * fBackgroundPixmap
ROOT::MacOSX::X11::PointerGrab fCurrentGrabType
unsigned long fBackgroundPixel
unsigned fActiveGrabEventMask
NSView< X11Window > * fContentView
unsigned long fBackgroundPixel
QuartzWindow * fQuartzWindow
QuartzView * fContentView
QuartzWindow * fMainWindow
QuartzImage * fShapeCombineMask
const NSUInteger kMiniaturizableWindowMask
const NSEventType kLeftMouseDown
const NSEventType kRightMouseDown
const NSUInteger kTitledWindowMask
const NSUInteger kResizableWindowMask
const NSUInteger kClosableWindowMask
const NSUInteger kBorderlessWindowMask
NSCursor * CreateCustomCursor(ECursor currentCursor)
int GlobalYROOTToCocoa(CGFloat yROOT)
NSPoint ConvertPointFromScreenToBase(NSPoint screenPoint, NSWindow *window)
bool ViewIsHtmlViewFrame(NSView< X11Window > *view, bool checkParent)
int GlobalYCocoaToROOT(CGFloat yCocoa)
void PixelToRGB(Pixel_t pixelColor, CGFloat *rgb)
bool ViewIsTextView(NSView< X11Window > *view)
NSPoint ConvertPointFromBaseToScreen(NSWindow *window, NSPoint windowPoint)
NSPoint TranslateToScreen(NSView< X11Window > *from, NSPoint point)
CGImageRef CreateSubImage(QuartzImage *image, const Rectangle &area)
bool ScreenPointIsInView(NSView< X11Window > *view, Int_t x, Int_t y)
NSPoint GetCursorHotStop(NSImage *image, ECursor cursor)
void GetWindowGeometry(NSObject< X11Window > *win, WindowAttributes_t *dst)
void GetWindowAttributes(NSObject< X11Window > *window, WindowAttributes_t *dst)
NSView< X11Window > * FindDNDAwareViewInPoint(NSView *parentView, Window_t dragWinID, Window_t inputWinID, Int_t x, Int_t y, Int_t maxDepth)
NSView< X11Window > * FrameForHtmlView(NSView< X11Window > *htmlView)
QuartzWindow * FindWindowInPoint(Int_t x, Int_t y)
int GlobalXCocoaToROOT(CGFloat xCocoa)
void WindowLostFocus(Window_t winID)
int LocalYROOTToCocoa(NSView< X11Window > *parentView, CGFloat yROOT)
NSView< X11Window > * FindViewForPointerEvent(NSEvent *pointerEvent)
NSView< X11Window > * FrameForTextView(NSView< X11Window > *textView)
NSComparisonResult CompareViewsToLower(id view1, id view2, void *context)
int LocalYCocoaToROOT(NSView< X11Window > *parentView, CGFloat yCocoa)
NSPoint TranslateCoordinates(NSView< X11Window > *fromView, NSView< X11Window > *toView, NSPoint sourcePoint)
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 > * FindViewUnderPointer()
void UnlockFocus(NSView< X11Window > *view)
int GlobalXROOTToCocoa(CGFloat xROOT)
bool ViewIsHtmlView(NSView< X11Window > *view)
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)
bool AdjustCropArea(const Rectangle &srcRect, Rectangle &cropArea)
QuartzWindow * FindWindowForPointerEvent(NSEvent *pointerEvent)
bool ViewIsTextView(unsigned viewID)
void GetRootWindowAttributes(WindowAttributes_t *attr)
bool ViewIsHtmlView(unsigned viewID)
QuartzWindow * FindWindowUnderPointer()
bool ViewIsTextViewFrame(NSView< X11Window > *view, bool checkParent)
NSPoint TranslateFromScreen(NSPoint point, NSView< X11Window > *to)
void ClipToShapeMask(NSView< X11Window > *view, CGContextRef ctx)
void SetWindowAttributes(const SetWindowAttributes_t *attr, NSObject< X11Window > *window)
NSCursor * CreateCursor(ECursor currentCursor)
bool LockFocus(NSView< X11Window > *view)
NSComparisonResult CompareViewsToRaise(id view1, id view2, void *context)
std::vector< unsigned char > DownscaledImageData(unsigned w, unsigned h, CGImageRef image)
Namespace for new ROOT classes and functions.