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