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;
67 const NSUInteger styleMask = kTitledWindowMask | kClosableWindowMask |
68 kMiniaturizableWindowMask | kResizableWindowMask;
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");
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");
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];
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];
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])
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");
594 QuartzWindow *
const topLevelParent = view.fQuartzWindow;
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");
657 [qw setAlphaValue : 0.95];
660 window.fOverrideRedirect = YES;
667 assert(win != nil &&
"GetWindowGeometry, parameter 'win' is nil");
668 assert(dst != 0 &&
"GetWindowGeometry, parameter 'dst' is null");
680 assert(window != nil &&
"GetWindowAttributes, parameter 'window' is nil");
681 assert(dst != 0 &&
"GetWindowAttributes, parameter 'attr' is null");
690 dst->
fDepth = window.fDepth;
695 dst->
fClass = window.fClass;
729#pragma mark - Comparators (I need them when changing a window's z-order).
733#ifdef MAC_OS_X_VERSION_10_11
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
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");
1001 assert(htmlView != nil &&
"FrameForHtmlView, parameter 'htmlView' is nil");
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");
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'.
1061void log_attributes(
const SetWindowAttributes_t *attr,
unsigned winID)
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");
1127 std::vector<ROOT::MacOSX::X11::Command *> xorOps;
1130- (void) addXorCommand : (
ROOT::MacOSX::
X11::Command *) cmd
1132 xorOps.push_back(cmd);
1135- (void) drawRect : (NSRect) dirtyRect
1137 [
super drawRect:dirtyRect];
1138 NSGraphicsContext *nsContext = [NSGraphicsContext currentContext];
1148 CGContextSetRGBStrokeColor(cgContext, 0., 0., 0., 1.);
1149 CGContextSetLineWidth(cgContext, 1.);
1151 for (
auto *command : xorOps) {
1152 command->Execute(cgContext);
1165 if (self = [super
init])
1167 self.styleMask = NSWindowStyleMaskBorderless;
1169 self.hasShadow = NO;
1170 self.backgroundColor = NSColor.clearColor;
1171 self.ignoresMouseEvents = YES;
1177#pragma mark - suppress the normal window behavior.
1178- (BOOL)canBecomeKeyWindow
1182- (BOOL)canBecomeMainWindow
1195#pragma mark - QuartzWindow's life cycle.
1198- (
id) initWithContentRect : (NSRect) contentRect styleMask : (NSUInteger) windowStyle
1199 backing : (NSBackingStoreType) bufferingType defer : (BOOL) deferCreation
1202 self = [
super initWithContentRect : contentRect styleMask : windowStyle
1203 backing : bufferingType defer : deferCreation];
1207 [
self setAllowsConcurrentViewDrawing : NO];
1209 self.delegate = self;
1211 NSRect contentViewRect = contentRect;
1212 contentViewRect.origin.x = 0.f;
1213 contentViewRect.origin.y = 0.f;
1217 [
self setContentView : fContentView];
1238 assert(glView != nil &&
"-initWithGLView, parameter 'glView' is nil");
1240 const NSUInteger styleMask = kTitledWindowMask | kClosableWindowMask |
1241 kMiniaturizableWindowMask | kResizableWindowMask;
1243 NSRect contentRect = glView.frame;
1244 contentRect.origin = NSPoint();
1246 self = [
super initWithContentRect : contentRect styleMask : styleMask
1247 backing : NSBackingStoreBuffered defer : NO];
1251 [
self setAllowsConcurrentViewDrawing : NO];
1252 self.delegate = self;
1254 [
self setContentView : fContentView];
1278- (void) setContentView:(
NSView *)cv
1280 [
super setContentView:cv];
1288- (void) setFIsDeleted : (BOOL) deleted
1293#pragma mark - Forwaring: I want to forward a lot of property setters/getters to the content view.
1296- (void) forwardInvocation : (NSInvocation *) anInvocation
1301 if ([
fContentView respondsToSelector : [anInvocation selector]]) {
1304 [
super forwardInvocation : anInvocation];
1309- (NSMethodSignature*) methodSignatureForSelector : (
SEL) selector
1311 NSMethodSignature *signature = [
super methodSignatureForSelector : selector];
1315 signature = [
fContentView methodSignatureForSelector : selector];
1330 assert(window != nil &&
"-addTransientWindow:, parameter 'window' is nil");
1339 [
self addChildWindow : window ordered : NSWindowAbove];
1345- (void) makeKeyAndOrderFront : (
id) sender
1347#pragma unused(sender)
1352#ifdef MAC_OS_X_VERSION_10_9
1353 [
self setCollectionBehavior : NSWindowCollectionBehaviorMoveToActiveSpace];
1355 [
self setCollectionBehavior : NSWindowCollectionBehaviorCanJoinAllSpaces];
1358 [
super makeKeyAndOrderFront :
self];
1360 [
self setCollectionBehavior : NSWindowCollectionBehaviorDefault];
1364- (void) setFDelayedTransient : (BOOL) d
1376- (void) setFShapeCombineMask : (
QuartzImage *) mask
1379 [fShapeCombineMask release];
1387#pragma mark - X11Drawable's protocol.
1408 return self.screen.backingScaleFactor;
1426 return self.frame.size.width;
1435 assert(
fContentView != nil &&
"-fHeight:, content view is nil");
1441- (void) setDrawableSize : (NSSize) newSize
1444 assert(!(newSize.width < 0) &&
"-setDrawableSize:, width is negative");
1445 assert(!(newSize.height < 0) &&
"-setDrawableSize:, height is negative");
1447 NSRect frame = self.frame;
1449 if (frame.origin.x < -100000. || frame.origin.x > 100000.) {
1451 NSLog(
@"Attempting to set a frame with X: %g", frame.origin.x);
1452 frame.origin.x = 0.;
1457 frame.origin.y = frame.origin.y + frame.size.height - newSize.height - dY;
1458 frame.size = newSize;
1459 frame.size.height += dY;
1460 [
self setFrame : frame display : YES];
1464- (void) setX : (
int) x Y : (
int) y width : (
unsigned) w height : (
unsigned) h
1466 NSSize newSize = {};
1469 [
self setContentSize : newSize];
1472 NSPoint topLeft = {};
1476 [
self setFrameTopLeftPoint : topLeft];
1480- (void) setX : (
int) x Y : (
int) y
1482 NSPoint topLeft = {};
1486 [
self setFrameTopLeftPoint : topLeft];
1491 clipOrigin : (
X11::Point) clipXY toPoint : (
X11::Point) dstPoint
1500- (
unsigned char *) readColorBits : (
X11::Rectangle) area
1508#pragma mark - XorDrawinWindow/View
1520 [
self addChildWindow : special ordered : NSWindowAbove];
1528 assert(win &&
"invalid (nil) parameter 'win'");
1529 auto frame = self.contentView.frame;
1530 frame = [
self convertRectToScreen:frame];
1531 [
win setFrame:frame display:NO];
1541 [
self removeChildWindow : win];
1548 auto children = [
self childWindows];
1549 for (
NSWindow *child in children) {
1566 [
cv addXorCommand : cmd.get()];
1568 [
cv setNeedsDisplay : YES];
1570 }
catch (
const std::exception &) {
1585 [
cv addXorCommand : cmd.get()];
1587 [
cv setNeedsDisplay : YES];
1588 }
catch (
const std::exception &) {
1610#pragma mark - X11Window protocol's implementation.
1619- (void) setFParentView : (
QuartzView *) parent
1621#pragma unused(parent)
1639- (void) setFBackgroundPixel : (
unsigned long) backgroundColor
1645 CGFloat rgba[] = {0., 0., 0., 1.};
1648 [
self setBackgroundColor : [NSColor colorWithColorSpace : [NSColorSpace deviceRGBColorSpace] components : rgba count : 4]];
1677- (void) addChild : (
NSView<X11Window> *) child
1679 assert(child != nil &&
"-addChild:, parameter 'child' is nil");
1683 assert([child isKindOfClass : [
QuartzView class]] &&
1684 "-addChild: gl view in a top-level window as content view is not supported");
1687 [
self setContentView : child];
1699 assert(attr &&
"-getAttributes:, parameter 'attr' is nil");
1707 assert(attr != 0 &&
"-setAttributes:, parameter 'attr' is null");
1709#ifdef DEBUG_ROOT_COCOA
1710 log_attributes(attr, self.fID);
1725 [
self makeKeyAndOrderFront :
self];
1730 [
fMainWindow addChildWindow :
self ordered : NSWindowAbove];
1743 [
self makeKeyAndOrderFront :
self];
1748 [
fMainWindow addChildWindow :
self ordered : NSWindowAbove];
1771 [
self orderOut :
self];
1779#pragma mark - Events.
1782- (void) sendEvent : (
NSEvent *) theEvent
1792 bool generateFakeRelease =
false;
1794 const NSPoint windowPoint = [theEvent locationInWindow];
1796 if (windowPoint.x <= 4 || windowPoint.x >= self.fWidth - 4)
1797 generateFakeRelease =
true;
1799 if (windowPoint.y <= 4 || windowPoint.y >= self.fHeight - 4)
1800 generateFakeRelease =
true;
1802 const NSPoint viewPoint = [fContentView convertPoint : windowPoint fromView : nil];
1804 if (viewPoint.y <= 0 && windowPoint.y >= 0)
1805 generateFakeRelease =
true;
1808 "-sendEvent:, gVirtualX is either null or not of TGCocoa type");
1822 [
super sendEvent : theEvent];
1825#pragma mark - NSWindowDelegate's methods.
1828- (BOOL) windowShouldClose : (
id) sender
1830#pragma unused(sender)
1834 if ([[self childWindows] count])
1838 Event_t closeEvent = {};
1845 assert(
dynamic_cast<TGCocoa *
>(
gVirtualX) != 0 &&
1846 "-windowShouldClose:, gVirtualX is either null or has a type different from TGCocoa");
1855- (void) windowDidBecomeKey : (NSNotification *) aNotification
1857#pragma unused(aNotification)
1865 assert(
dynamic_cast<TGCocoa *
>(
gVirtualX) != 0 &&
1866 "-windowDidBecomeKey:, gVirtualX is null or not of TGCocoa type");
1867 TGCocoa *
const vx =
static_cast<TGCocoa *
>(
gVirtualX);
1874- (void) windowDidResignKey : (NSNotification *) aNotification
1876#pragma unused(aNotification)
1882#pragma mark - Passive key grab info.
1887- (
id) initWithKey : (unichar) keyCode modifiers : (NSUInteger) modifiers
1889 if (self = [super init]) {
1898- (BOOL) matchKey : (unichar) keyCode modifiers : (NSUInteger) modifiers
1904- (BOOL) matchKey : (unichar) keyCode
1923#pragma mark - X11 property emulation.
1931@property (nonatomic, readonly)
Atom_t fType;
1940- (
id) initWithData : (
unsigned char *) data size : (
unsigned) dataSize type : (
Atom_t) type format : (
unsigned) format
1942 if (self = [super init]) {
1948 [
self resetPropertyData : data size : dataSize type : type format : format];
1957 [fPropertyData release];
1963- (void) resetPropertyData : (
unsigned char *) data size : (
unsigned) dataSize
1964 type : (
Atom_t) type format : (
unsigned) format
1966 [fPropertyData release];
1971 else if (format == 32)
1974 fPropertyData = [[NSData dataWithBytes : data length : dataSize] retain];
1993#pragma mark - QuartzView.
2026#pragma mark - Lifetime.
2031 if (self = [super initWithFrame : frame]) {
2045 [
self setCanDrawConcurrently : NO];
2047 [
self setHidden : YES];
2067 [fBackBuffer release];
2068 [fPassiveKeyGrabs release];
2069 [fX11Properties release];
2070 [fBackgroundPixmap release];
2074#pragma mark - Tracking area.
2079- (void) updateTrackingAreas
2081 [
super updateTrackingAreas];
2086 const Util::AutoreleasePool pool;
2088 if (NSArray *trackingArray = [self trackingAreas]) {
2089 const NSUInteger
size = [trackingArray count];
2090 for (NSUInteger i = 0; i <
size; ++i) {
2091 NSTrackingArea *
const t = [trackingArray objectAtIndex : i];
2092 [
self removeTrackingArea : t];
2096 const NSUInteger trackerOptions = NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited |
2097 NSTrackingActiveInActiveApp | NSTrackingInVisibleRect |
2098 NSTrackingEnabledDuringMouseDrag | NSTrackingCursorUpdate;
2101 frame.size.width = self.fWidth;
2102 frame.size.height = self.fHeight;
2104 NSTrackingArea *
const tracker = [[NSTrackingArea alloc] initWithRect : frame
2105 options : trackerOptions owner :
self userInfo : nil];
2106 [
self addTrackingArea : tracker];
2111- (void) updateTrackingAreasAfterRaise
2113 [
self updateTrackingAreas];
2115 for (QuartzView *childView in [self subviews])
2116 [childView updateTrackingAreasAfterRaise];
2119#pragma mark - X11Drawable protocol.
2136 return self.fQuartzWindow.fScaleFactor;
2142 return self.frame.origin.x;
2148 return self.frame.origin.y;
2154 return self.frame.size.width;
2160 return self.frame.size.height;
2164- (void) setDrawableSize : (NSSize) newSize
2166 assert(!(newSize.width < 0) &&
"-setDrawableSize, width is negative");
2167 assert(!(newSize.height < 0) &&
"-setDrawableSize, height is negative");
2173 NSRect frame = self.frame;
2174 frame.size = newSize;
2216- (void) setDirectDraw : (BOOL) mode
2232- (void) setX : (
int) x Y : (
int) y width : (
unsigned) w height : (
unsigned) h
2234 NSRect newFrame = {};
2235 newFrame.origin.x =
x;
2236 newFrame.origin.y =
y;
2237 newFrame.size.width = w;
2238 newFrame.size.height =
h;
2240 self.frame = newFrame;
2244- (void) setX : (
int) x Y : (
int) y
2246 NSRect newFrame = self.frame;
2247 newFrame.origin.x =
x;
2248 newFrame.origin.y =
y;
2250 self.frame = newFrame;
2254- (void) copyImage : (
QuartzImage *) srcImage area : (
X11::Rectangle) area
2256 toPoint : (
X11::Point) dstPoint
2259 assert(srcImage != nil &&
2260 "-copyImage:area:withMask:clipOrigin:toPoint:, parameter 'srcImage' is nil");
2261 assert(srcImage.
fImage != nil &&
2262 "-copyImage:area:withMask:clipOrigin:toPoint:, srcImage.fImage is nil");
2265 assert(self.fContext != 0 &&
2266 "-copyImage:area:withMask:clipOrigin:toPoint:, self.fContext is null");
2269 NSLog(
@"QuartzView: -copyImage:area:withMask:clipOrigin:toPoint:,"
2270 " srcRect and copyRect do not intersect");
2276 CGImageRef subImage = 0;
2277 bool needSubImage =
false;
2278 if (area.fX || area.fY || area.fWidth != srcImage.
fWidth || area.fHeight != srcImage.
fHeight) {
2279 needSubImage =
true;
2282 NSLog(
@"QuartzView: -copyImage:area:withMask:clipOrigin:toPoint:,"
2283 " subimage creation failed");
2287 subImage = srcImage.
fImage;
2290 const Quartz::CGStateGuard ctxGuard(self.fContext);
2293 CGContextTranslateCTM(self.fContext, 0., self.fHeight);
2294 CGContextScaleCTM(self.fContext, 1., -1.);
2298 assert(mask.
fImage != nil &&
2299 "-copyImage:area:withMask:clipOrigin:toPoint:, mask.fImage is nil");
2300 assert(CGImageIsMask(mask.
fImage) ==
true &&
2301 "-copyImage:area:withMask:clipOrigin:toPoint:, mask.fImage is not a mask");
2305 const CGRect clipRect = CGRectMake(clipXY.fX, clipY, mask.
fWidth, mask.
fHeight);
2306 CGContextClipToMask(self.fContext, clipRect, mask.
fImage);
2313 const CGRect imageRect = CGRectMake(dstPoint.fX, dstY, area.fWidth, area.fHeight);
2314 CGContextDrawImage(self.fContext, imageRect, subImage);
2317 CGImageRelease(subImage);
2321- (void) copyView : (
QuartzView *) srcView area : (
X11::Rectangle) area toPoint : (
X11::Point) dstPoint
2326 assert(srcView != nil &&
"-copyView:area:toPoint:, parameter 'srcView' is nil");
2328 const NSRect frame = [srcView frame];
2330 NSBitmapImageRep *
const imageRep = [srcView bitmapImageRepForCachingDisplayInRect : frame];
2332 NSLog(
@"QuartzView: -copyView:area:toPoint failed");
2336 assert(srcView != nil &&
"-copyView:area:toPoint:, parameter 'srcView' is nil");
2337 assert(self.fContext != 0 &&
"-copyView:area:toPoint, self.fContext is null");
2342 CGContextRef ctx = srcView.
fContext;
2344 [srcView cacheDisplayInRect : frame toBitmapImageRep : imageRep];
2348 const CGRect subImageRect = CGRectMake(area.fX, area.fY, area.fWidth, area.fHeight);
2349 const Util::CFScopeGuard<CGImageRef> subImage(CGImageCreateWithImageInRect(imageRep.CGImage, subImageRect));
2351 if (!subImage.Get()) {
2352 NSLog(
@"QuartzView: -copyView:area:toPoint, CGImageCreateWithImageInRect failed");
2356 const Quartz::CGStateGuard ctxGuard(self.fContext);
2357 const CGRect imageRect = CGRectMake(dstPoint.fX,
2358 [self visibleRect].size.height - (CGFloat(dstPoint.fY) + area.fHeight),
2359 area.fWidth, area.fHeight);
2361 CGContextTranslateCTM(self.fContext, 0., [self visibleRect].size.height);
2362 CGContextScaleCTM(self.fContext, 1., -1.);
2364 CGContextDrawImage(self.fContext, imageRect, subImage.Get());
2368- (void) copyPixmap : (
QuartzPixmap *) srcPixmap area : (
X11::Rectangle) area
2369 withMask : (
QuartzImage *) mask clipOrigin : (
X11::Point) clipXY toPoint : (
X11::Point) dstPoint
2372 assert(srcPixmap != nil &&
"-copyPixmap:area:withMask:clipOrigin:toPoint:, parameter 'srcPixmap' is nil");
2375 NSLog(
@"QuartzView: -copyPixmap:area:withMask:clipOrigin:toPoint,"
2376 " no intersection between pixmap rectangle and cropArea");
2381 assert(self.fContext != 0 &&
2382 "-copyPixmap:area:withMask:clipOrigin:toPoint:, self.fContext is null");
2385 const Quartz::CGStateGuard ctxGuard(self.fContext);
2387 CGContextTranslateCTM(self.fContext, 0., self.frame.size.height);
2388 CGContextScaleCTM(self.fContext, 1., -1.);
2390 const Util::CFScopeGuard<CGImageRef> imageFromPixmap([srcPixmap createImageFromPixmap]);
2391 assert(imageFromPixmap.Get() != 0 &&
2392 "-copyPixmap:area:withMask:clipOrigin:toPoint:, createImageFromPixmap failed");
2394 CGImageRef subImage = 0;
2395 bool needSubImage =
false;
2396 if (area.fX || area.fY || area.fWidth != srcPixmap.
fWidth || area.fHeight != srcPixmap.
fHeight) {
2397 needSubImage =
true;
2398 const CGRect subImageRect = CGRectMake(area.fX, area.fY, area.fHeight, area.fWidth);
2399 subImage = CGImageCreateWithImageInRect(imageFromPixmap.Get(), subImageRect);
2401 NSLog(
@"QuartzView: -copyImage:area:withMask:clipOrigin:toPoint:,"
2402 " subimage creation failed");
2406 subImage = imageFromPixmap.Get();
2409 assert(mask.
fImage != nil &&
2410 "-copyPixmap:area:withMask:clipOrigin:toPoint:, mask.fImage is nil");
2411 assert(CGImageIsMask(mask.
fImage) ==
true &&
2412 "-copyPixmap:area:withMask:clipOrigin:toPoint:, mask.fImage is not a mask");
2417 const CGRect clipRect = CGRectMake(clipXY.fX, clipY, mask.
fWidth, mask.
fHeight);
2418 CGContextClipToMask(self.fContext, clipRect, mask.
fImage);
2423 const CGRect imageRect = CGRectMake(dstPoint.fX, dstY, area.fWidth, area.fHeight);
2424 CGContextDrawImage(self.fContext, imageRect, imageFromPixmap.Get());
2427 CGImageRelease(subImage);
2432- (void) copyImage : (
QuartzImage *) srcImage area : (
X11::Rectangle) area
2433 toPoint : (
X11::Point) dstPoint
2435 assert(srcImage != nil &&
"-copyImage:area:toPoint:, parameter 'srcImage' is nil");
2436 assert(srcImage.
fImage != nil &&
"-copyImage:area:toPoint:, srcImage.fImage is nil");
2437 assert(self.fContext != 0 &&
"-copyImage:area:toPoint:, fContext is null");
2440 NSLog(
@"QuartzView: -copyImage:area:toPoint, image and copy area do not intersect");
2444 CGImageRef subImage = 0;
2445 bool needSubImage =
false;
2446 if (area.fX || area.fY || area.fWidth != srcImage.
fWidth || area.fHeight != srcImage.
fHeight) {
2447 needSubImage =
true;
2450 NSLog(
@"QuartzView: -copyImage:area:toPoint:, subimage creation failed");
2454 subImage = srcImage.
fImage;
2456 const Quartz::CGStateGuard ctxGuard(self.fContext);
2458 CGContextTranslateCTM(self.fContext, 0., self.fHeight);
2459 CGContextScaleCTM(self.fContext, 1., -1.);
2464 const CGRect imageRect = CGRectMake(dstPoint.fX, dstY, area.fWidth, area.fHeight);
2465 CGContextDrawImage(self.fContext, imageRect, subImage);
2468 CGImageRelease(subImage);
2472- (void) copy : (
NSObject<X11Drawable> *) src area : (
X11::Rectangle) area
2473 withMask : (
QuartzImage *)mask clipOrigin : (
X11::Point) clipXY toPoint : (
X11::Point) dstPoint
2475 assert(src != nil &&
"-copy:area:withMask:clipOrigin:toPoint:, parameter 'src' is nil");
2476 assert(area.fWidth && area.fHeight &&
"-copy:area:withMask:clipOrigin:toPoint:, area to copy is empty");
2482 [
self copyView : (QuartzView *)qw.fContentView area : area toPoint : dstPoint];
2483 }
else if ([src isKindOfClass : [
QuartzView class]]) {
2485 [
self copyView : (QuartzView *)src area : area toPoint : dstPoint];
2486 }
else if ([src isKindOfClass : [
QuartzPixmap class]]) {
2487 [
self copyPixmap : (QuartzPixmap *)src area : area withMask : mask clipOrigin : clipXY toPoint : dstPoint];
2488 }
else if ([src isKindOfClass : [
QuartzImage class]]) {
2489 [
self copyImage : (QuartzImage *)src area : area withMask : mask clipOrigin : clipXY toPoint : dstPoint];
2491 assert(0 &&
"-copy:area:withMask:clipOrigin:toPoint:, src is of unknown type");
2496- (
unsigned char *) readColorBits : (
X11::Rectangle) area
2502 assert(area.fWidth && area.fHeight &&
"-readColorBits:, area to copy is empty");
2505 NSRect visRect = [
self visibleRect];
2510 if (visRect.origin.y < 0) {
2511 visRect.size.height += visRect.origin.y;
2512 visRect.origin.y = 0.;
2514 if (visRect.origin.x < 0) {
2515 visRect.size.width += visRect.origin.x;
2516 visRect.origin.x = 0.;
2519 const X11::Rectangle srcRect(
int(visRect.origin.x),
int(visRect.origin.y),
2520 unsigned(visRect.size.width),
unsigned(visRect.size.height));
2523 NSLog(
@"QuartzView: -readColorBits:, visible rect of view and copy area do not intersect");
2528 NSBitmapImageRep *
const imageRep = [
self bitmapImageRepForCachingDisplayInRect : visRect];
2530 NSLog(
@"QuartzView: -readColorBits:, bitmapImageRepForCachingDisplayInRect failed");
2535 [
self cacheDisplayInRect : visRect toBitmapImageRep : imageRep];
2536 self.fContext = ctx;
2538 const NSInteger bitsPerPixel = [
imageRep bitsPerPixel];
2540 assert(bitsPerPixel == 32 &&
"-readColorBits:, no alpha channel???");
2541 const NSInteger bytesPerRow = [
imageRep bytesPerRow];
2542 unsigned dataWidth = bytesPerRow / (bitsPerPixel / 8);
2544 unsigned char *srcData =
nullptr;
2545 std::vector<unsigned char> downscaled;
2546 if ([self.window.screen backingScaleFactor] > 1 && imageRep.CGImage) {
2548 if (downscaled.size())
2549 srcData = &downscaled[0];
2550 dataWidth = area.fWidth;
2555 NSLog(
@"QuartzView: -readColorBits:, failed to obtain backing store contents");
2560 unsigned char *data =
nullptr;
2563 data =
new unsigned char[
area.
fWidth * area.fHeight * 4];
2564 }
catch (
const std::bad_alloc &) {
2565 NSLog(
@"QuartzView: -readColorBits:, memory allocation failed");
2569 unsigned char *dstPixel = data;
2570 const unsigned char *
line = srcData + area.fY * dataWidth * 4;
2571 const unsigned char *srcPixel =
line + area.fX * 4;
2573 for (
unsigned i = 0; i < area.fHeight; ++i) {
2574 for (
unsigned j = 0; j < area.fWidth; ++j, srcPixel += 4, dstPixel += 4) {
2575 dstPixel[0] = srcPixel[2];
2576 dstPixel[1] = srcPixel[1];
2577 dstPixel[2] = srcPixel[0];
2578 dstPixel[3] = srcPixel[3];
2581 line += dataWidth * 4;
2582 srcPixel =
line + area.fX * 4;
2589- (void) setFBackgroundPixmap : (
QuartzImage *) pixmap
2592 [fBackgroundPixmap release];
2611 if ([self isHidden])
2615 if ([parent isHidden])
2633- (void) setFHasFocus : (BOOL) focus
2635#pragma unused(focus)
2652 [fBackBuffer release];
2686- (void) activateGrab : (
unsigned) eventMask ownerEvents : (BOOL) ownerEvents
2702- (BOOL) acceptsCrossingEvents : (
unsigned) eventMask
2721- (void)didAddSubview:(
NSView *)subview
2723 [
super didAddSubview:subview];
2724 self.wantsLayer = YES;
2725 self.layer.masksToBounds = YES;
2729- (void)willRemoveSubview:(
NSView *)subview
2731 [
super willRemoveSubview:subview];
2732 self.wantsLayer = YES;
2733 self.layer.masksToBounds = self.subviews.count > 1;
2737- (void) addChild : (
NSView<X11Window> *) child
2739 assert(child != nil &&
"-addChild:, parameter 'child' is nil");
2741 [
self addSubview : child];
2742 child.fParentView = self;
2748 assert(attr != 0 &&
"-getAttributes:, parameter 'attr' is null");
2756 assert(attr != 0 &&
"-setAttributes:, parameter 'attr' is null");
2758#ifdef DEBUG_ROOT_COCOA
2759 log_attributes(attr,
fID);
2770 [
self removeFromSuperview];
2771 [
parent addSubview :
self];
2772 [
self setHidden : NO];
2778 [
self setHidden : NO];
2791 [
self setHidden : YES];
2801- (void) setOverlapped : (BOOL) overlap
2805 [
child setOverlapped : overlap];
2822 using namespace X11;
2825 if (self == sibling)
2827 if ([sibling isHidden])
2830 if (NSEqualRects(sibling.frame, self.frame)) {
2831 [
sibling setOverlapped : YES];
2838 [
self setHidden : NO];
2840 [
fParentView sortSubviewsUsingFunction : CompareViewsToRaise context : (void *)
self];
2842 [
self updateTrackingAreasAfterRaise];
2844 [
self setNeedsDisplay : YES];
2852 using namespace X11;
2854 NSEnumerator *
const reverseEnumerator = [[
fParentView subviews] reverseObjectEnumerator];
2855 for (
QuartzView *sibling in reverseEnumerator) {
2856 if (sibling == self)
2859 if (NSEqualRects(sibling.frame, self.frame)) {
2864 [
sibling setNeedsDisplay : YES];
2867 [
self setHidden : YES];
2873 [
fParentView sortSubviewsUsingFunction : CompareViewsToLower context : (void*)
self];
2890 "-configureNotifyTree, gVirtualX is either null or has type different from TGCocoa");
2896 [v configureNotifyTree];
2900#pragma mark - Key grabs.
2903- (void) addPassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers
2907 modifiers : modifiers];
2908 [fPassiveKeyGrabs addObject : newGrab];
2913- (void) removePassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers
2915 const NSUInteger count = [fPassiveKeyGrabs count];
2916 for (NSUInteger i = 0; i < count; ++i) {
2918 if ([grab matchKey : keyCode modifiers : modifiers]) {
2919 [fPassiveKeyGrabs removeObjectAtIndex : i];
2926- (
PassiveKeyGrab *) findPassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers
2928 NSEnumerator *
const enumerator = [fPassiveKeyGrabs objectEnumerator];
2930 if ([grab matchKey : keyCode modifiers : modifiers])
2941 NSEnumerator *
const enumerator = [fPassiveKeyGrabs objectEnumerator];
2943 if ([grab matchKey : keyCode])
2950#pragma mark - Painting mechanics.
2953- (void) drawRect : (NSRect) dirtyRect
2955#pragma unused(dirtyRect)
2957 using namespace X11;
2962 if (ViewIsTextViewFrame(self,
true) ||ViewIsHtmlViewFrame(self,
true))
2965 NSGraphicsContext *
const nsContext = [NSGraphicsContext currentContext];
2966 assert(nsContext != nil &&
"-drawRect:, currentContext returned nil");
2972 assert(
fContext != 0 &&
"-drawRect:, graphicsPort returned null");
2977 if (self.fQuartzWindow.fShapeCombineMask)
2987 if (ViewIsTextView(self)) {
2989 [NSColor.whiteColor setFill];
2990 NSRect frame = self.frame;
3010 gClient->CancelRedraw(window);
3018 [
self copy : fBackBuffer area : copyArea withMask : nil
3019 clipOrigin : X11::Point() toPoint : X11::Point()];
3023#ifdef DEBUG_ROOT_COCOA
3024 CGContextSetRGBStrokeColor(
fContext, 1., 0., 0., 1.);
3025 CGContextStrokeRect(
fContext, dirtyRect);
3030#ifdef DEBUG_ROOT_COCOA
3031 NSLog(
@"QuartzView: -drawRect: method, no window for id %u was found",
fID);
3037#pragma mark - Geometry.
3040- (void) setFrame : (NSRect) newFrame
3045 if (NSEqualRects(newFrame, self.frame))
3048 [
super setFrame : newFrame];
3052- (void) setFrameSize : (NSSize) newSize
3056 [
super setFrameSize : newSize];
3059 assert(
dynamic_cast<TGCocoa *
>(
gVirtualX) != 0 &&
3060 "setFrameSize:, gVirtualX is either null or has a type, different from TGCocoa");
3061 TGCocoa *
const vx =
static_cast<TGCocoa *
>(
gVirtualX);
3065 [
self setNeedsDisplay : YES];
3068#pragma mark - Event handling.
3071- (void) mouseDown : (
NSEvent *) theEvent
3073 assert(
fID != 0 &&
"-mouseDown:, fID is 0");
3075 assert(
dynamic_cast<TGCocoa *
>(
gVirtualX) != 0 &&
3076 "-mouseDown:, gVirtualX is either null or has a type, different from TGCocoa");
3077 TGCocoa *
const vx =
static_cast<TGCocoa *
>(
gVirtualX);
3082- (void) scrollWheel : (
NSEvent*) theEvent
3084 assert(
fID != 0 &&
"-scrollWheel:, fID is 0");
3087 assert(
dynamic_cast<TGCocoa *
>(
gVirtualX) != 0 &&
3088 "-scrollWheel:, gVirtualX is either null or has a type, different from TGCocoa");
3090 TGCocoa *
const vx =
static_cast<TGCocoa *
>(
gVirtualX);
3091 const CGFloat deltaY = [theEvent deltaY];
3095 }
else if (deltaY > 0) {
3101#ifdef DEBUG_ROOT_COCOA
3103- (void) printViewInformation
3105 assert(
fID != 0 &&
"-printWindowInformation, fID is 0");
3106 const TGWindow *
const window =
gClient->GetWindowById(
fID);
3107 assert(window != 0 &&
"printWindowInformation, window not found");
3109 NSLog(
@"-----------------View %u info:---------------------",
fID);
3110 NSLog(
@"ROOT's window class is %s", window->
IsA()->
GetName());
3111 NSLog(
@"event mask is:");
3113 NSLog(
@"grab mask is:");
3115 NSLog(
@"view's geometry: x == %g, y == %g, w == %g, h == %g", self.frame.origin.x,
3116 self.frame.origin.y, self.frame.size.width, self.frame.size.height);
3117 NSLog(
@"----------------End of view info------------------");
3122- (void) rightMouseDown : (
NSEvent *) theEvent
3124 assert(
fID != 0 &&
"-rightMouseDown:, fID is 0");
3126#ifdef DEBUG_ROOT_COCOA
3127 [
self printViewInformation];
3130 assert(
dynamic_cast<TGCocoa *
>(
gVirtualX) != 0 &&
3131 "-rightMouseDown:, gVirtualX is either null or has type different from TGCocoa");
3132 TGCocoa *
const vx =
static_cast<TGCocoa *
>(
gVirtualX);
3137- (void) otherMouseDown : (
NSEvent *) theEvent
3139 assert(
fID != 0 &&
"-otherMouseDown:, fID is 0");
3143 if ([theEvent buttonNumber] == 2) {
3146 assert(
dynamic_cast<TGCocoa *
>(
gVirtualX) != 0 &&
3147 "-otherMouseDown:, gVirtualX is either null or has type different from TGCocoa");
3148 TGCocoa *
const vx =
static_cast<TGCocoa *
>(
gVirtualX);
3154- (void) mouseUp : (
NSEvent *) theEvent
3156 assert(
fID != 0 &&
"-mouseUp:, fID is 0");
3158 assert(
dynamic_cast<TGCocoa *
>(
gVirtualX) &&
3159 "-mouseUp:, gVirtualX is either null or has type different from TGCocoa");
3160 TGCocoa *
const vx =
static_cast<TGCocoa *
>(
gVirtualX);
3165- (void) rightMouseUp : (
NSEvent *) theEvent
3168 assert(
fID != 0 &&
"-rightMouseUp:, fID is 0");
3170 assert(
dynamic_cast<TGCocoa *
>(
gVirtualX) != 0 &&
3171 "-rightMouseUp:, gVirtualX is either null or has type different from TGCocoa");
3173 TGCocoa *
const vx =
static_cast<TGCocoa *
>(
gVirtualX);
3178- (void) otherMouseUp : (
NSEvent *) theEvent
3180 assert(
fID != 0 &&
"-otherMouseUp:, fID is 0");
3183 assert(
dynamic_cast<TGCocoa *
>(
gVirtualX) != 0 &&
3184 "-otherMouseUp:, gVirtualX is either null or has type different from TGCocoa");
3185 TGCocoa *
const vx =
static_cast<TGCocoa *
>(
gVirtualX);
3190- (void) mouseEntered : (
NSEvent *) theEvent
3192 assert(
fID != 0 &&
"-mouseEntered:, fID is 0");
3193 assert(
dynamic_cast<TGCocoa *
>(
gVirtualX) != 0 &&
3194 "-mouseEntered:, gVirtualX is null or not of TGCocoa type");
3196 TGCocoa *
const vx =
static_cast<TGCocoa *
>(
gVirtualX);
3201- (void) mouseExited : (
NSEvent *) theEvent
3203 assert(
fID != 0 &&
"-mouseExited:, fID is 0");
3205 assert(
dynamic_cast<TGCocoa *
>(
gVirtualX) != 0 &&
3206 "-mouseExited:, gVirtualX is null or not of TGCocoa type");
3208 TGCocoa *
const vx =
static_cast<TGCocoa *
>(
gVirtualX);
3213- (void) mouseMoved : (
NSEvent *) theEvent
3215 assert(
fID != 0 &&
"-mouseMoved:, fID is 0");
3220 assert(
dynamic_cast<TGCocoa *
>(
gVirtualX) != 0 &&
3221 "-mouseMoved:, gVirtualX is null or not of TGCocoa type");
3223 TGCocoa *vx =
static_cast<TGCocoa *
>(
gVirtualX);
3228- (void) mouseDragged : (
NSEvent *) theEvent
3230 assert(
fID != 0 &&
"-mouseDragged:, fID is 0");
3232 TGCocoa *
const vx =
dynamic_cast<TGCocoa *
>(
gVirtualX);
3233 assert(vx != 0 &&
"-mouseDragged:, gVirtualX is null or not of TGCocoa type");
3239- (void) rightMouseDragged : (
NSEvent *) theEvent
3241 assert(
fID != 0 &&
"-rightMouseDragged:, fID is 0");
3243 assert(
dynamic_cast<TGCocoa *
>(
gVirtualX) != 0 &&
3244 "-rightMouseDragged:, gVirtualX is null or not of TGCocoa type");
3246 TGCocoa *
const vx =
static_cast<TGCocoa *
>(
gVirtualX);
3251- (void) otherMouseDragged : (
NSEvent *) theEvent
3253 assert(
fID != 0 &&
"-otherMouseDragged:, fID is 0");
3255 if ([theEvent buttonNumber] == 2) {
3256 assert(
dynamic_cast<TGCocoa *
>(
gVirtualX) != 0 &&
3257 "-otherMouseDragged:, gVirtualX is null or not of TGCocoa type");
3258 TGCocoa *
const vx =
static_cast<TGCocoa *
>(
gVirtualX);
3264- (void) keyDown : (
NSEvent *) theEvent
3266 assert(
fID != 0 &&
"-keyDown:, fID is 0");
3268 assert(
dynamic_cast<TGCocoa *
>(
gVirtualX) != 0 &&
3269 "-keyDown:, gVirtualX is null or not of TGCocoa type");
3271 NSView<X11Window> *eventView = self;
3273 eventView = pointerView;
3275 TGCocoa *
const vx =
static_cast<TGCocoa *
>(
gVirtualX);
3280- (void) keyUp : (
NSEvent *) theEvent
3282 assert(
fID != 0 &&
"-keyUp:, fID is 0");
3284 assert(
dynamic_cast<TGCocoa *
>(
gVirtualX) != 0 &&
3285 "-keyUp:, gVirtualX is null or not of TGCocoa type");
3287 TGCocoa *
const vx =
static_cast<TGCocoa *
>(
gVirtualX);
3288 NSView<X11Window> *eventView = self;
3290 eventView = pointerView;
3295#pragma mark - First responder stuff.
3298- (BOOL) acceptsFirstMouse : (
NSEvent *) theEvent
3300#pragma unused(theEvent)
3305- (BOOL) acceptsFirstResponder
3310#pragma mark - Cursors.
3313- (void) setFCurrentCursor : (
ECursor) cursor
3317 [
self.fQuartzWindow invalidateCursorRectsForView :
self];
3322- (NSCursor *) createCustomCursor
3324 const char *pngFileName = 0;
3328 pngFileName =
"move_cursor.png";
3331 pngFileName =
"hor_arrow_cursor.png";
3334 pngFileName =
"ver_arrow_cursor.png";
3337 pngFileName =
"right_arrow_cursor.png";
3340 pngFileName =
"rotate.png";
3344 pngFileName =
"top_right_cursor.png";
3348 pngFileName =
"top_left_cursor.png";
3355 const Util::ScopedArray<const char> arrayGuard(path);
3357 if (!path || path[0] == 0) {
3362 NSString *nsPath = [NSString stringWithFormat : @"%s", path];
3363 NSImage *
const cursorImage = [[NSImage alloc] initWithContentsOfFile : nsPath];
3369 NSCursor *
const customCursor = [[[NSCursor alloc] initWithImage : cursorImage
3370 hotSpot : hotSpot] autorelease];
3372 [cursorImage release];
3374 return customCursor;
3381- (void) resetCursorRects
3384 [
self addCursorRect :
self.visibleRect cursor : cursor];
3388- (void) cursorUpdate
3398- (void) cursorUpdate : (
NSEvent *) event
3400#pragma unused(event)
3412 [
self performSelector : @selector(cursorUpdate) withObject : nil afterDelay : 0.05f];
3415#pragma mark - Emulated X11 properties.
3418- (void) setProperty : (const
char *) propName data : (
unsigned char *) propData
3419 size : (
unsigned) dataSize forType : (
Atom_t) dataType format : (
unsigned) format
3421 assert(propName != 0 &&
"-setProperty:data:size:forType:, parameter 'propName' is null");
3422 assert(propData != 0 &&
"-setProperty:data:size:forType:, parameter 'propData' is null");
3423 assert(dataSize != 0 &&
"-setProperty:data:size:forType:, parameter 'dataSize' is 0");
3425 NSString *
const key = [
NSString stringWithCString : propName encoding : NSASCIIStringEncoding];
3430 [
property resetPropertyData : propData size : dataSize type : dataType format : format];
3434 type : dataType format : format];
3435 [fX11Properties setObject : property forKey : key];
3441- (BOOL) hasProperty : (const
char *) propName
3443 assert(propName != 0 &&
"-hasProperty:, propName parameter is null");
3445 NSString *
const key = [
NSString stringWithCString : propName encoding : NSASCIIStringEncoding];
3448 return property != nil;
3452- (
unsigned char *) getProperty : (const
char *) propName returnType : (
Atom_t *) type
3453 returnFormat : (
unsigned *) format nElements : (
unsigned *) nElements
3455 assert(propName != 0 &&
3456 "-getProperty:returnType:returnFormat:nElements:, parameter 'propName' is null");
3458 "-getProperty:returnType:returnFormat:nElements:, parameter 'type' is null");
3459 assert(format != 0 &&
3460 "-getProperty:returnType:returnFormat:nElements:, parameter 'format' is null");
3461 assert(nElements != 0 &&
3462 "-getProperty:returnType:returnFormat:nElements:, parameter 'nElements' is null");
3464 NSString *
const key = [
NSString stringWithCString : propName encoding : NSASCIIStringEncoding];
3466 assert(property != 0 &&
3467 "-getProperty:returnType:returnFormat:nElements, property not found");
3469 NSData *
const propData =
property.fPropertyData;
3471 const NSUInteger dataSize = [
propData length];
3472 unsigned char *buff = 0;
3474 buff =
new unsigned char[
dataSize]();
3475 }
catch (
const std::bad_alloc &) {
3477 NSLog(
@"QuartzWindow: -getProperty:returnType:returnFormat:nElements:,"
3478 " memory allocation failed");
3482 [
propData getBytes : buff length : dataSize];
3483 *format =
property.fFormat;
3485 *nElements = dataSize;
3488 *nElements= dataSize / 2;
3489 else if (*format == 32)
3490 *nElements = dataSize / 4;
3492 *type =
property.fType;
3498- (void) removeProperty : (const
char *) propName
3500 assert(propName != 0 &&
"-removeProperty:, parameter 'propName' is null");
3502 NSString *
const key = [
NSString stringWithCString : propName
3503 encoding : NSASCIIStringEncoding];
3504 [fX11Properties removeObjectForKey : key];
3509- (NSDragOperation) draggingEntered : (
id<NSDraggingInfo>) sender
3511 NSPasteboard *
const pasteBoard = [
sender draggingPasteboard];
3512 const NSDragOperation sourceDragMask = [
sender draggingSourceOperationMask];
3514 if ([[pasteBoard types] containsObject : NSFilenamesPboardType] && (sourceDragMask & NSDragOperationCopy))
3515 return NSDragOperationCopy;
3517 return NSDragOperationNone;
3521- (BOOL) performDragOperation : (
id<NSDraggingInfo>) sender
3532 NSPasteboard *
const pasteBoard = [
sender draggingPasteboard];
3533 const NSDragOperation sourceDragMask = [
sender draggingSourceOperationMask];
3535 if ([[pasteBoard types] containsObject : NSFilenamesPboardType] && (sourceDragMask & NSDragOperationCopy)) {
3541 NSArray *
const files = [
pasteBoard propertyListForType : NSFilenamesPboardType];
3542 for (NSString *path in files) {
3546 const NSUInteger len = [
item lengthOfBytesUsingEncoding : NSASCIIStringEncoding] + 1;
3548 std::vector<unsigned char> propertyData(len);
3549 [
item getCString : (char *)&propertyData[0] maxLength : propertyData.size()
3550 encoding : NSASCIIStringEncoding];
3553 [
targetView setProperty : "_XC_DND_DATA" data : &propertyData[0]
3554 size : propertyData.size() forType : textUriAtom format : 8];
3555 }
catch (
const std::bad_alloc &) {
3557 NSLog(
@"QuartzView: -performDragOperation:, memory allocation failed");
3573 event1.
fUser[2] = textUriAtom;
3583 event2.
fUser[2] = 0;
3584 NSPoint dropPoint = [
sender draggingLocation];
3587 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
UInt_t Mask_t
Structure mask type.
const Mask_t kButtonReleaseMask
const Mask_t kWABorderPixmap
const Mask_t kEnterWindowMask
Handle_t Window_t
Window handle.
const Mask_t kWABackPixmap
const Mask_t kWABorderWidth
const Mask_t kWABackingPlanes
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
unsigned short UShort_t
Unsigned Short integer 2 bytes (unsigned short).
int Int_t
Signed integer 4 bytes (int).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
unsigned long ULong_t
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
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
A TGTextView is a text viewer widget.
ROOT GUI Window base class.
TClass * IsA() const override
const char * GetName() const override
Returns name of object.
Bool_t TestBit(UInt_t f) const
Semi-Abstract base class defining a generic interface to the underlying, low level,...
ROOT::MacOSX::Util::CFScopeGuard< CGImageRef > fImage
void setDirectDraw:(BOOL mode)
QuartzPixmap * fBackBuffer
unsigned char * readColorBits:(ROOT::MacOSX::X11::Rectangle area)
unsigned fPassiveGrabKeyModifiers
void activateImplicitGrab()
NSMutableArray * fPassiveKeyGrabs
TAttFill fAttFill
current fill attributes
BOOL fActiveGrabOwnerEvents
TAttText fAttText
current text attribute
QuartzWindow * fQuartzWindow
void setOverlapped:(BOOL overlap)
void configureNotifyTree()
void activatePassiveGrab()
NSMutableDictionary * fX11Properties
BOOL fPassiveGrabOwnerEvents
void removePassiveKeyGrab:modifiers:(unichar keyCode,[modifiers] NSUInteger modifiers)
TAttMarker fAttMarker
current marker attribute
unsigned fPassiveGrabEventMask
QuartzImage * fBackgroundPixmap
ROOT::MacOSX::X11::PointerGrab fCurrentGrabType
unsigned long fBackgroundPixel
unsigned fActiveGrabEventMask
void addChild:(NSView< X11Window > *child)
NSView< X11Window > * fContentView
void copy:area:withMask:clipOrigin:toPoint:(NSObject< X11Drawable > *src,[area] ROOT::MacOSX::X11::Rectangle area,[withMask] QuartzImage *mask,[clipOrigin] ROOT::MacOSX::X11::Point origin,[toPoint] ROOT::MacOSX::X11::Point dstPoint)
TAttLine fAttLine
current line attributes
unsigned long fBackgroundPixel
QuartzWindow * fQuartzWindow
XorDrawingWindow * findXorWindow()
TVirtualX::EDrawMode getDrawMode()
XorDrawingWindow * addXorWindow()
QuartzWindow * fMainWindow
void setDrawMode:(TVirtualX::EDrawMode newMode)
TVirtualX::EDrawMode fDrawMode
void adjustXorWindowGeometry:(XorDrawingWindow *win)
QuartzView * fContentView
QuartzImage * fShapeCombineMask
const NSEventType kLeftMouseDown
const NSEventType kRightMouseDown
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)
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)
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)
EGEventType fType
of event (see EGEventType)
Handle_t fHandle
general resource handle (used for atoms or windows)
Int_t fFormat
Next fields only used by kClientMessageEvent.
Window_t fWindow
window reported event is relative to
Longptr_t fUser[5]
5 longs can be used by client message events NOTE: only [0], [1] and [2] may be used.
Attributes that can be used when creating or changing a window.
Long_t fEventMask
set of events that should be saved
Mask_t fMask
bit mask specifying which fields are valid
Int_t fWinGravity
one of the window gravity values
ULong_t fBackgroundPixel
background pixel
Int_t fBitGravity
one of bit gravity values
Window attributes that can be inquired.
Window_t fRoot
root of screen containing window
Int_t fMapState
kIsUnmapped, kIsUnviewable, kIsViewable
ULong_t fBackingPlanes
planes to be preserved if possible
Long_t fAllEventMasks
set of events all people have interest in
ULong_t fBackingPixel
value to be used when restoring planes
Long_t fYourEventMask
my event mask
Int_t fHeight
width and height of window
Bool_t fMapInstalled
boolean, is color map currently installed
Int_t fBorderWidth
border width of window
Int_t fWinGravity
one of the window gravity values
void * fScreen
back pointer to correct screen
Colormap_t fColormap
color map to be associated with window
Int_t fClass
kInputOutput, kInputOnly
Int_t fBitGravity
one of bit gravity values
void * fVisual
the associated visual structure
Int_t fBackingStore
kNotUseful, kWhenMapped, kAlways
Int_t fY
location of window
Int_t fDepth
depth of window
Bool_t fOverrideRedirect
boolean value for override-redirect
Bool_t fSaveUnder
boolean, should bits under be saved?