Logo ROOT   6.12/07
Reference Guide
QuartzWindow.h
Go to the documentation of this file.
1 // @(#)root/graf2d:$Id$
2 // Author: Timur Pocheptsov 16/02/2012
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2012, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_QuartzWindow
13 #define ROOT_QuartzWindow
14 
15 #include <Cocoa/Cocoa.h>
16 
17 #include "CocoaGuiTypes.h"
18 #include "X11Drawable.h"
19 #include "X11Events.h"
20 #include "GuiTypes.h"
21 
22 ////////////////////////////////////////////////
23 // //
24 // QuartzWindow class : top-level window. //
25 // //
26 ////////////////////////////////////////////////
27 
28 @class ROOTOpenGLView;
29 @class QuartzImage;
30 
31 @interface QuartzWindow : NSWindow<X11Window, NSWindowDelegate> {
32 @private
34  BOOL fHasFocus;
35 
39  BOOL fIsDeleted;
40 }
41 
42 - (id) initWithContentRect : (NSRect) contentRect styleMask : (NSUInteger) windowStyle
43  backing : (NSBackingStoreType) bufferingType defer : (BOOL) deferCreation
44  windowAttributes : (const SetWindowAttributes_t *) attr;
45 
46 - (id) initWithGLView : (ROOTOpenGLView *) glView;
47 
48 - (void) dealloc;
49 
50 //With reference counting and autorelease pools, it's possible that
51 //TGCocoa::DestroyWindow was called and window was correctly deleted,
52 //but it's still on screen and if used in some functions (like FindWindowForPointerEvent)
53 //and this ends in a segmentation fault.
54 //fIsDeleted property is here to solve this problem.
55 - (BOOL) fIsDeleted;
56 - (void) setFIsDeleted : (BOOL) deleted;
57 
58 //Many properties in QuartzWindow just forwards to fContentView.
59 - (void) forwardInvocation : (NSInvocation *) anInvocation;
60 - (NSMethodSignature*) methodSignatureForSelector : (SEL) selector;
61 
62 //This is to emulate "transient" window/main window relationship:
63 @property (nonatomic, assign) QuartzWindow *fMainWindow;
64 - (void) addTransientWindow : (QuartzWindow *) window;
65 
66 //Shape mask - non-rectangular window.
67 @property (nonatomic, assign) QuartzImage *fShapeCombineMask;
68 //@property (nonatomic, assign) NSPoint fShapeMaskShift;
69 
70 //1. X11Drawable protocol.
71 
72 - (BOOL) fIsPixmap;
73 - (BOOL) fIsOpenGLWidget;
74 - (CGFloat) fScaleFactor;
75 
76 //Geometry.
77 - (int) fX;
78 - (int) fY;
79 
80 - (unsigned) fWidth;
81 - (unsigned) fHeight;
82 
83 - (void) setDrawableSize : (NSSize) newSize;
84 - (void) setX : (int) x Y : (int) y width : (unsigned) w height : (unsigned) h;
85 - (void) setX : (int) x Y : (int) y;
86 
87 //
88 - (void) copy : (NSObject<X11Drawable> *) src area : (ROOT::MacOSX::X11::Rectangle) area withMask : (QuartzImage *) mask
89  clipOrigin : (ROOT::MacOSX::X11::Point) origin toPoint : (ROOT::MacOSX::X11::Point) dstPoint;
90 
91 - (unsigned char *) readColorBits : (ROOT::MacOSX::X11::Rectangle) area;
92 
93 
94 //X11Window protocol.
95 
96 /////////////////////////////////////////////////////////////////
97 //SetWindowAttributes_t/WindowAttributes_t
98 @property (nonatomic, assign) unsigned long fBackgroundPixel;
99 @property (nonatomic, readonly) int fMapState;
100 
101 //End of SetWindowAttributes_t/WindowAttributes_t
102 /////////////////////////////////////////////////////////////////
103 
104 @property (nonatomic, assign) BOOL fHasFocus;
105 
106 //"Back buffer" is a bitmap, attached to a window by TCanvas.
107 @property (nonatomic, assign) QuartzView *fParentView;
108 @property (nonatomic, readonly) NSView<X11Window> *fContentView;
109 @property (nonatomic, readonly) QuartzWindow *fQuartzWindow;
110 
111 //Children subviews.
112 - (void) addChild : (NSView<X11Window> *) child;
113 
114 //X11/ROOT GUI's attributes.
115 - (void) getAttributes : (WindowAttributes_t *) attr;
116 - (void) setAttributes : (const SetWindowAttributes_t *) attr;
117 
118 //X11's XMapWindow etc.
119 - (void) mapRaised;
120 - (void) mapWindow;
121 - (void) mapSubwindows;
122 - (void) unmapWindow;
123 
124 @end
125 
126 //////////////////////////////////////////////////////////////
127 // //
128 // I have to attach passive key grabs to a view. //
129 // //
130 //////////////////////////////////////////////////////////////
131 
132 @interface PassiveKeyGrab : NSObject {
133 @private
134  unichar fKeyCode;
135  NSUInteger fModifiers;
136 }
137 - (unichar) fKeyCode;
138 - (NSUInteger) fModifiers;
139 - (id) initWithKey : (unichar) keyCode modifiers : (NSUInteger) modifiers;
140 - (BOOL) matchKey : (unichar) keyCode modifiers : (NSUInteger) modifiers;
141 - (BOOL) matchKey : (unichar) keyCode;
142 @end
143 
144 ////////////////////////////////////////
145 // //
146 // QuartzView class - child window. //
147 // //
148 ////////////////////////////////////////
149 
150 @class QuartzImage;
151 
152 @interface QuartzView : NSView<X11Window> {
153 @protected
154  unsigned fID;
155  CGContextRef fContext;
157  int fClass;
158  int fDepth;
161  unsigned long fBackgroundPixel;
163 
164  BOOL fHasFocus;
166 
175 
177  NSMutableArray *fPassiveKeyGrabs;
179 
180  NSMutableDictionary *fX11Properties;
182 
184 
186 }
187 
188 //Life-cycle.
189 - (id) initWithFrame : (NSRect) frame windowAttributes : (const SetWindowAttributes_t *) attr;
190 
191 //X11Drawable protocol.
192 
193 @property (nonatomic, assign) unsigned fID;
194 
195 - (BOOL) fIsPixmap;
196 - (BOOL) fIsOpenGLWidget;
197 - (CGFloat) fScaleFactor;
198 
199 @property (nonatomic, assign) CGContextRef fContext;
200 
201 //Geometry.
202 - (int) fX;
203 - (int) fY;
204 - (unsigned) fWidth;
205 - (unsigned) fHeight;
206 - (void) setDrawableSize : (NSSize) newSize;
207 - (void) setX : (int) x Y : (int) y width : (unsigned) w height : (unsigned) h;
208 - (void) setX : (int) x Y : (int) y;
209 
210 - (void) copy : (NSObject<X11Drawable> *) src area : (ROOT::MacOSX::X11::Rectangle) area withMask : (QuartzImage *)mask
211  clipOrigin : (ROOT::MacOSX::X11::Point) origin toPoint : (ROOT::MacOSX::X11::Point) dstPoint;
212 - (unsigned char *) readColorBits : (ROOT::MacOSX::X11::Rectangle) area;
213 
214 //X11Window protocol.
215 
216 /////////////////////////////////////////////////////////////////
217 //SetWindowAttributes_t/WindowAttributes_t
218 
219 @property (nonatomic, assign) long fEventMask;
220 @property (nonatomic, assign) int fClass;
221 @property (nonatomic, assign) int fDepth;
222 @property (nonatomic, assign) int fBitGravity;
223 @property (nonatomic, assign) int fWinGravity;
224 @property (nonatomic, assign) unsigned long fBackgroundPixel;
225 @property (nonatomic, retain) QuartzImage *fBackgroundPixmap;
226 @property (nonatomic, readonly) int fMapState;
227 @property (nonatomic, assign) BOOL fOverrideRedirect;
228 
229 //End of SetWindowAttributes_t/WindowAttributes_t
230 /////////////////////////////////////////////////////////////////
231 
232 @property (nonatomic, assign) BOOL fHasFocus;
233 
234 
235 @property (nonatomic, retain) QuartzPixmap *fBackBuffer;
236 @property (nonatomic, assign) QuartzView *fParentView;
237 @property (nonatomic, readonly) NSView<X11Window> *fContentView;
238 @property (nonatomic, readonly) QuartzWindow *fQuartzWindow;
239 
240 @property (nonatomic, assign) int fPassiveGrabButton;
241 @property (nonatomic, assign) unsigned fPassiveGrabEventMask;
242 @property (nonatomic, assign) unsigned fPassiveGrabKeyModifiers;
243 
244 @property (nonatomic, assign) BOOL fPassiveGrabOwnerEvents;
245 
246 - (void) activatePassiveGrab;
247 - (void) activateImplicitGrab;
248 - (void) activateGrab : (unsigned) eventMask ownerEvents : (BOOL) ownerEvents;
249 - (void) cancelGrab;
250 
251 - (BOOL) acceptsCrossingEvents : (unsigned) eventMask;
252 
253 //Children subviews.
254 - (void) addChild : (NSView<X11Window> *)child;
255 
256 //X11/ROOT GUI's attributes.
257 - (void) getAttributes : (WindowAttributes_t *) attr;
258 - (void) setAttributes : (const SetWindowAttributes_t *) attr;
259 
260 - (void) mapRaised;
261 - (void) mapWindow;
262 - (void) mapSubwindows;
263 
264 - (void) unmapWindow;
265 
266 - (void) raiseWindow;
267 - (void) lowerWindow;
268 
269 - (BOOL) fIsOverlapped;
270 - (void) setOverlapped : (BOOL) overlap;
271 - (void) configureNotifyTree;
272 
273 //Additional methods and properties.
274 
275 @property (nonatomic, assign) BOOL fSnapshotDraw;
276 - (BOOL) isFlipped;//override method from NSView.
277 
278 //Keyboard:
279 - (void) addPassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers;
280 - (void) removePassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers;
281 - (PassiveKeyGrab *) findPassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers;
282 - (PassiveKeyGrab *) findPassiveKeyGrab : (unichar) keyCode;
283 
284 //Cursors.
285 @property (nonatomic, assign) ECursor fCurrentCursor;
286 
287 //X11 "properties".
288 - (void) setProperty : (const char *) propName data : (unsigned char *) propData size : (unsigned) dataSize
289  forType : (Atom_t) dataType format : (unsigned) format;
290 - (BOOL) hasProperty : (const char *) propName;
291 - (unsigned char *) getProperty : (const char *) propName returnType : (Atom_t *) type
292  returnFormat : (unsigned *) format nElements : (unsigned *) nElements;
293 - (void) removeProperty : (const char *) propName;
294 
295 //DND
296 @property (nonatomic, assign) BOOL fIsDNDAware;
297 
298 - (NSDragOperation) draggingEntered : (id<NSDraggingInfo>) sender;
299 - (BOOL) performDragOperation : (id<NSDraggingInfo>) sender;
300 
301 @end
302 
303 namespace ROOT {
304 namespace MacOSX {
305 namespace X11 {
306 
308  UInt_t clss, void *visual, SetWindowAttributes_t *attr, UInt_t);
309 QuartzView *CreateChildView(QuartzView *parent, Int_t x, Int_t y, UInt_t w, UInt_t h, UInt_t border, Int_t depth,
310  UInt_t clss, void *visual, SetWindowAttributes_t *attr, UInt_t wtype);
311 
313 void GetWindowAttributes(NSObject<X11Window> *window, WindowAttributes_t *dst);
314 
315 //Coordinate conversion.
316 
317 //This two functions operate with Cocoa's coordinate system (so, 'to screen' will return Cocoa's
318 //point, and 'from screen' expects Cocoa's point (not ROOT)).
319 NSPoint ConvertPointFromBaseToScreen(NSWindow *window, NSPoint windowPoint);
320 NSPoint ConvertPointFromScreenToBase(NSPoint screenPoint, NSWindow *window);
321 
322 int GlobalXCocoaToROOT(CGFloat xCocoa);
323 int GlobalYCocoaToROOT(CGFloat yCocoa);
324 int GlobalXROOTToCocoa(CGFloat xROOT);
325 int GlobalYROOTToCocoa(CGFloat yROOT);
326 
327 int LocalYCocoaToROOT(NSView<X11Window> *parentView, CGFloat yCocoa);
328 int LocalYROOTToCocoa(NSView<X11Window> *parentView, CGFloat yROOT);
329 int LocalYROOTToCocoa(NSObject<X11Drawable> *parentView, CGFloat yROOT);
330 
331 NSPoint TranslateToScreen(NSView<X11Window> *from, NSPoint point);
332 NSPoint TranslateFromScreen(NSPoint point, NSView<X11Window> *to);
333 NSPoint TranslateCoordinates(NSView<X11Window> *fromView, NSView<X11Window> *toView, NSPoint sourcePoint);
334 
335 bool ViewIsTextViewFrame(NSView<X11Window> *view, bool checkParent);
336 bool ViewIsHtmlViewFrame(NSView<X11Window> *view, bool checkParent);
337 bool LockFocus(NSView<X11Window> *view);
338 void UnlockFocus(NSView<X11Window> *view);
339 
340 bool ScreenPointIsInView(NSView<X11Window> *view, Int_t x, Int_t y);
342 NSView<X11Window> *FindDNDAwareViewInPoint(NSView *parentView, Window_t dragWinID, Window_t inputWinID, Int_t x, Int_t y, Int_t maxDepth);
343 
344 //Pointer == cursor in X11's terms.
345 
346 //These two functions use "mouse location outside of event stream" - simply
347 //asks for the current cursor location
348 //("regardless of the current event being handled or of any events pending").
350 NSView<X11Window> *FindViewUnderPointer();
351 
352 //These two functions use coordinates from the event to find a window/view.
353 QuartzWindow *FindWindowForPointerEvent(NSEvent *pointerEvent);
354 NSView<X11Window> *FindViewForPointerEvent(NSEvent *pointerEvent);
355 void WindowLostFocus(Window_t winID);
356 
357 //Add shape mask to context.
358 void ClipToShapeMask(NSView<X11Window> *view, CGContextRef ctx);
359 
360 }//X11
361 }//MacOSX
362 }//ROOT
363 
364 #endif
int GlobalXCocoaToROOT(CGFloat xCocoa)
unichar fKeyCode
Definition: QuartzWindow.h:134
BOOL fOverrideRedirect
Definition: QuartzWindow.h:162
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)
Definition: QuartzWindow.mm:56
NSView< X11Window > * FindViewForPointerEvent(NSEvent *pointerEvent)
void GetRootWindowAttributes(WindowAttributes_t *attr)
unsigned long fBackgroundPixel
Definition: QuartzWindow.h:98
CGFloat fScaleFactor()
unsigned fPassiveGrabEventMask
Definition: QuartzWindow.h:168
bool LockFocus(NSView< X11Window > *view)
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
void GetWindowAttributes(NSObject< X11Window > *window, WindowAttributes_t *dst)
QuartzWindow * fQuartzWindow
Definition: QuartzWindow.h:109
ECursor fCurrentCursor
Definition: QuartzWindow.h:173
QuartzWindow * FindWindowInPoint(Int_t x, Int_t y)
NSView< X11Window > * FindDNDAwareViewInPoint(NSView *parentView, Window_t dragWinID, Window_t inputWinID, Int_t x, Int_t y, Int_t maxDepth)
TH1 * h
Definition: legend2.C:5
BOOL fIsDNDAware
Definition: QuartzWindow.h:174
int LocalYCocoaToROOT(NSView< X11Window > *parentView, CGFloat yCocoa)
QuartzImage * fShapeCombineMask
Definition: QuartzWindow.h:38
int Int_t
Definition: RtypesCore.h:41
QuartzPixmap * fBackBuffer
Definition: QuartzWindow.h:176
ECursor
Definition: TVirtualX.h:44
BOOL fIsOpenGLWidget()
int GlobalYROOTToCocoa(CGFloat yROOT)
QuartzView * fParentView
Definition: QuartzWindow.h:165
NSMutableDictionary * fX11Properties
Definition: QuartzWindow.h:180
Double_t x[n]
Definition: legend1.C:17
NSPoint TranslateCoordinates(NSView< X11Window > *fromView, NSView< X11Window > *toView, NSPoint sourcePoint)
QuartzImage * fBackgroundPixmap
Definition: QuartzWindow.h:181
NSPoint ConvertPointFromBaseToScreen(NSWindow *window, NSPoint windowPoint)
QuartzWindow * FindWindowForPointerEvent(NSEvent *pointerEvent)
Handle_t Atom_t
Definition: GuiTypes.h:36
ROOT::MacOSX::X11::PointerGrab fCurrentGrabType
Definition: QuartzWindow.h:183
XFontStruct * id
Definition: TGX11.cxx:108
NSPoint TranslateFromScreen(NSPoint point, NSView< X11Window > *to)
NSPoint ConvertPointFromScreenToBase(NSPoint screenPoint, NSWindow *window)
int GlobalXROOTToCocoa(CGFloat xROOT)
NSView< X11Window > * FindViewUnderPointer()
BOOL fHasFocus
Definition: QuartzWindow.h:164
NSPoint TranslateToScreen(NSView< X11Window > *from, NSPoint point)
int GlobalYCocoaToROOT(CGFloat yCocoa)
bool ViewIsHtmlViewFrame(NSView< X11Window > *view, bool checkParent)
QuartzWindow * FindWindowUnderPointer()
unsigned fHeight()
unsigned int UInt_t
Definition: RtypesCore.h:42
QuartzView * fParentView
Definition: QuartzWindow.h:107
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)
Definition: QuartzWindow.mm:85
void UnlockFocus(NSView< X11Window > *view)
long fEventMask
Definition: QuartzWindow.h:156
unsigned fID
Definition: QuartzWindow.h:154
NSUInteger fModifiers
Definition: QuartzWindow.h:135
BOOL fPassiveGrabOwnerEvents
Definition: QuartzWindow.h:171
CGContextRef fContext
Definition: QuartzWindow.h:155
unsigned fWidth()
QuartzWindow * fMainWindow
Definition: QuartzWindow.h:33
BOOL fSnapshotDraw
Definition: QuartzWindow.h:172
bool ScreenPointIsInView(NSView< X11Window > *view, Int_t x, Int_t y)
Double_t y[n]
Definition: legend1.C:17
void WindowLostFocus(Window_t winID)
int LocalYROOTToCocoa(NSObject< X11Drawable > *parentView, CGFloat yROOT)
void ClipToShapeMask(NSView< X11Window > *view, CGContextRef ctx)
unsigned long fBackgroundPixel
Definition: QuartzWindow.h:161
unsigned fPassiveGrabKeyModifiers
Definition: QuartzWindow.h:169
BOOL fDelayedTransient
Definition: QuartzWindow.h:37
typedef void((*Func_t)())
Handle_t Window_t
Definition: GuiTypes.h:28
QuartzView * fContentView
Definition: QuartzWindow.h:36
BOOL fActiveGrabOwnerEvents
Definition: QuartzWindow.h:185
bool ViewIsTextViewFrame(NSView< X11Window > *view, bool checkParent)
unsigned fActiveGrabEventMask
Definition: QuartzWindow.h:170
int fPassiveGrabButton
Definition: QuartzWindow.h:167
NSMutableArray * fPassiveKeyGrabs
Definition: QuartzWindow.h:177
BOOL fIsOverlapped
Definition: QuartzWindow.h:178