Logo ROOT   6.10/09
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 
75 //Geometry.
76 - (int) fX;
77 - (int) fY;
78 
79 - (unsigned) fWidth;
80 - (unsigned) fHeight;
81 
82 - (void) setDrawableSize : (NSSize) newSize;
83 - (void) setX : (int) x Y : (int) y width : (unsigned) w height : (unsigned) h;
84 - (void) setX : (int) x Y : (int) y;
85 
86 //
87 - (void) copy : (NSObject<X11Drawable> *) src area : (ROOT::MacOSX::X11::Rectangle) area withMask : (QuartzImage *) mask
88  clipOrigin : (ROOT::MacOSX::X11::Point) origin toPoint : (ROOT::MacOSX::X11::Point) dstPoint;
89 
90 - (unsigned char *) readColorBits : (ROOT::MacOSX::X11::Rectangle) area;
91 
92 
93 //X11Window protocol.
94 
95 /////////////////////////////////////////////////////////////////
96 //SetWindowAttributes_t/WindowAttributes_t
97 @property (nonatomic, assign) unsigned long fBackgroundPixel;
98 @property (nonatomic, readonly) int fMapState;
99 
100 //End of SetWindowAttributes_t/WindowAttributes_t
101 /////////////////////////////////////////////////////////////////
102 
103 @property (nonatomic, assign) BOOL fHasFocus;
104 
105 //"Back buffer" is a bitmap, attached to a window by TCanvas.
106 @property (nonatomic, assign) QuartzView *fParentView;
107 @property (nonatomic, readonly) NSView<X11Window> *fContentView;
108 @property (nonatomic, readonly) QuartzWindow *fQuartzWindow;
109 
110 //Children subviews.
111 - (void) addChild : (NSView<X11Window> *) child;
112 
113 //X11/ROOT GUI's attributes.
114 - (void) getAttributes : (WindowAttributes_t *) attr;
115 - (void) setAttributes : (const SetWindowAttributes_t *) attr;
116 
117 //X11's XMapWindow etc.
118 - (void) mapRaised;
119 - (void) mapWindow;
120 - (void) mapSubwindows;
121 - (void) unmapWindow;
122 
123 @end
124 
125 //////////////////////////////////////////////////////////////
126 // //
127 // I have to attach passive key grabs to a view. //
128 // //
129 //////////////////////////////////////////////////////////////
130 
131 @interface PassiveKeyGrab : NSObject {
132 @private
133  unichar fKeyCode;
134  NSUInteger fModifiers;
135 }
136 - (unichar) fKeyCode;
137 - (NSUInteger) fModifiers;
138 - (id) initWithKey : (unichar) keyCode modifiers : (NSUInteger) modifiers;
139 - (BOOL) matchKey : (unichar) keyCode modifiers : (NSUInteger) modifiers;
140 - (BOOL) matchKey : (unichar) keyCode;
141 @end
142 
143 ////////////////////////////////////////
144 // //
145 // QuartzView class - child window. //
146 // //
147 ////////////////////////////////////////
148 
149 @class QuartzImage;
150 
151 @interface QuartzView : NSView<X11Window> {
152 @protected
153  unsigned fID;
154  CGContextRef fContext;
156  int fClass;
157  int fDepth;
160  unsigned long fBackgroundPixel;
162 
163  BOOL fHasFocus;
165 
174 
176  NSMutableArray *fPassiveKeyGrabs;
178 
179  NSMutableDictionary *fX11Properties;
181 
183 
185 }
186 
187 //Life-cycle.
188 - (id) initWithFrame : (NSRect) frame windowAttributes : (const SetWindowAttributes_t *) attr;
189 
190 //X11Drawable protocol.
191 
192 @property (nonatomic, assign) unsigned fID;
193 
194 - (BOOL) fIsPixmap;
195 - (BOOL) fIsOpenGLWidget;
196 
197 @property (nonatomic, assign) CGContextRef fContext;
198 
199 //Geometry.
200 - (int) fX;
201 - (int) fY;
202 - (unsigned) fWidth;
203 - (unsigned) fHeight;
204 - (void) setDrawableSize : (NSSize) newSize;
205 - (void) setX : (int) x Y : (int) y width : (unsigned) w height : (unsigned) h;
206 - (void) setX : (int) x Y : (int) y;
207 
208 - (void) copy : (NSObject<X11Drawable> *) src area : (ROOT::MacOSX::X11::Rectangle) area withMask : (QuartzImage *)mask
209  clipOrigin : (ROOT::MacOSX::X11::Point) origin toPoint : (ROOT::MacOSX::X11::Point) dstPoint;
210 - (unsigned char *) readColorBits : (ROOT::MacOSX::X11::Rectangle) area;
211 
212 //X11Window protocol.
213 
214 /////////////////////////////////////////////////////////////////
215 //SetWindowAttributes_t/WindowAttributes_t
216 
217 @property (nonatomic, assign) long fEventMask;
218 @property (nonatomic, assign) int fClass;
219 @property (nonatomic, assign) int fDepth;
220 @property (nonatomic, assign) int fBitGravity;
221 @property (nonatomic, assign) int fWinGravity;
222 @property (nonatomic, assign) unsigned long fBackgroundPixel;
223 @property (nonatomic, retain) QuartzImage *fBackgroundPixmap;
224 @property (nonatomic, readonly) int fMapState;
225 @property (nonatomic, assign) BOOL fOverrideRedirect;
226 
227 //End of SetWindowAttributes_t/WindowAttributes_t
228 /////////////////////////////////////////////////////////////////
229 
230 @property (nonatomic, assign) BOOL fHasFocus;
231 
232 
233 @property (nonatomic, retain) QuartzPixmap *fBackBuffer;
234 @property (nonatomic, assign) QuartzView *fParentView;
235 @property (nonatomic, readonly) NSView<X11Window> *fContentView;
236 @property (nonatomic, readonly) QuartzWindow *fQuartzWindow;
237 
238 @property (nonatomic, assign) int fPassiveGrabButton;
239 @property (nonatomic, assign) unsigned fPassiveGrabEventMask;
240 @property (nonatomic, assign) unsigned fPassiveGrabKeyModifiers;
241 
242 @property (nonatomic, assign) BOOL fPassiveGrabOwnerEvents;
243 
244 - (void) activatePassiveGrab;
245 - (void) activateImplicitGrab;
246 - (void) activateGrab : (unsigned) eventMask ownerEvents : (BOOL) ownerEvents;
247 - (void) cancelGrab;
248 
249 - (BOOL) acceptsCrossingEvents : (unsigned) eventMask;
250 
251 //Children subviews.
252 - (void) addChild : (NSView<X11Window> *)child;
253 
254 //X11/ROOT GUI's attributes.
255 - (void) getAttributes : (WindowAttributes_t *) attr;
256 - (void) setAttributes : (const SetWindowAttributes_t *) attr;
257 
258 - (void) mapRaised;
259 - (void) mapWindow;
260 - (void) mapSubwindows;
261 
262 - (void) unmapWindow;
263 
264 - (void) raiseWindow;
265 - (void) lowerWindow;
266 
267 - (BOOL) fIsOverlapped;
268 - (void) setOverlapped : (BOOL) overlap;
269 - (void) configureNotifyTree;
270 
271 //Additional methods and properties.
272 
273 @property (nonatomic, assign) BOOL fSnapshotDraw;
274 - (BOOL) isFlipped;//override method from NSView.
275 
276 //Keyboard:
277 - (void) addPassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers;
278 - (void) removePassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers;
279 - (PassiveKeyGrab *) findPassiveKeyGrab : (unichar) keyCode modifiers : (NSUInteger) modifiers;
280 - (PassiveKeyGrab *) findPassiveKeyGrab : (unichar) keyCode;
281 
282 //Cursors.
283 @property (nonatomic, assign) ECursor fCurrentCursor;
284 
285 //X11 "properties".
286 - (void) setProperty : (const char *) propName data : (unsigned char *) propData size : (unsigned) dataSize
287  forType : (Atom_t) dataType format : (unsigned) format;
288 - (BOOL) hasProperty : (const char *) propName;
289 - (unsigned char *) getProperty : (const char *) propName returnType : (Atom_t *) type
290  returnFormat : (unsigned *) format nElements : (unsigned *) nElements;
291 - (void) removeProperty : (const char *) propName;
292 
293 //DND
294 @property (nonatomic, assign) BOOL fIsDNDAware;
295 
296 - (NSDragOperation) draggingEntered : (id<NSDraggingInfo>) sender;
297 - (BOOL) performDragOperation : (id<NSDraggingInfo>) sender;
298 
299 @end
300 
301 namespace ROOT {
302 namespace MacOSX {
303 namespace X11 {
304 
306  UInt_t clss, void *visual, SetWindowAttributes_t *attr, UInt_t);
307 QuartzView *CreateChildView(QuartzView *parent, Int_t x, Int_t y, UInt_t w, UInt_t h, UInt_t border, Int_t depth,
308  UInt_t clss, void *visual, SetWindowAttributes_t *attr, UInt_t wtype);
309 
311 void GetWindowAttributes(NSObject<X11Window> *window, WindowAttributes_t *dst);
312 
313 //Coordinate conversion.
314 
315 //This two functions operate with Cocoa's coordinate system (so, 'to screen' will return Cocoa's
316 //point, and 'from screen' expects Cocoa's point (not ROOT)).
317 NSPoint ConvertPointFromBaseToScreen(NSWindow *window, NSPoint windowPoint);
318 NSPoint ConvertPointFromScreenToBase(NSPoint screenPoint, NSWindow *window);
319 
320 int GlobalXCocoaToROOT(CGFloat xCocoa);
321 int GlobalYCocoaToROOT(CGFloat yCocoa);
322 int GlobalXROOTToCocoa(CGFloat xROOT);
323 int GlobalYROOTToCocoa(CGFloat yROOT);
324 
325 int LocalYCocoaToROOT(NSView<X11Window> *parentView, CGFloat yCocoa);
326 int LocalYROOTToCocoa(NSView<X11Window> *parentView, CGFloat yROOT);
327 int LocalYROOTToCocoa(NSObject<X11Drawable> *parentView, CGFloat yROOT);
328 
329 NSPoint TranslateToScreen(NSView<X11Window> *from, NSPoint point);
330 NSPoint TranslateFromScreen(NSPoint point, NSView<X11Window> *to);
331 NSPoint TranslateCoordinates(NSView<X11Window> *fromView, NSView<X11Window> *toView, NSPoint sourcePoint);
332 
333 bool ViewIsTextViewFrame(NSView<X11Window> *view, bool checkParent);
334 bool ViewIsHtmlViewFrame(NSView<X11Window> *view, bool checkParent);
335 bool LockFocus(NSView<X11Window> *view);
336 void UnlockFocus(NSView<X11Window> *view);
337 
338 bool ScreenPointIsInView(NSView<X11Window> *view, Int_t x, Int_t y);
340 NSView<X11Window> *FindDNDAwareViewInPoint(NSView *parentView, Window_t dragWinID, Window_t inputWinID, Int_t x, Int_t y, Int_t maxDepth);
341 
342 //Pointer == cursor in X11's terms.
343 
344 //These two functions use "mouse location outside of event stream" - simply
345 //asks for the current cursor location
346 //("regardless of the current event being handled or of any events pending").
348 NSView<X11Window> *FindViewUnderPointer();
349 
350 //These two functions use coordinates from the event to find a window/view.
351 QuartzWindow *FindWindowForPointerEvent(NSEvent *pointerEvent);
352 NSView<X11Window> *FindViewForPointerEvent(NSEvent *pointerEvent);
353 void WindowLostFocus(Window_t winID);
354 
355 //Add shape mask to context.
356 void ClipToShapeMask(NSView<X11Window> *view, CGContextRef ctx);
357 
358 }//X11
359 }//MacOSX
360 }//ROOT
361 
362 #endif
int GlobalXCocoaToROOT(CGFloat xCocoa)
unichar fKeyCode
Definition: QuartzWindow.h:133
BOOL fOverrideRedirect
Definition: QuartzWindow.h:161
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:53
NSView< X11Window > * FindViewForPointerEvent(NSEvent *pointerEvent)
void GetRootWindowAttributes(WindowAttributes_t *attr)
unsigned long fBackgroundPixel
Definition: QuartzWindow.h:97
unsigned fPassiveGrabEventMask
Definition: QuartzWindow.h:167
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:108
ECursor fCurrentCursor
Definition: QuartzWindow.h:172
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:173
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:175
ECursor
Definition: TVirtualX.h:44
BOOL fIsOpenGLWidget()
int GlobalYROOTToCocoa(CGFloat yROOT)
QuartzView * fParentView
Definition: QuartzWindow.h:164
NSMutableDictionary * fX11Properties
Definition: QuartzWindow.h:179
Double_t x[n]
Definition: legend1.C:17
NSPoint TranslateCoordinates(NSView< X11Window > *fromView, NSView< X11Window > *toView, NSPoint sourcePoint)
QuartzImage * fBackgroundPixmap
Definition: QuartzWindow.h:180
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:182
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:163
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:106
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:82
void UnlockFocus(NSView< X11Window > *view)
long fEventMask
Definition: QuartzWindow.h:155
unsigned fID
Definition: QuartzWindow.h:153
NSUInteger fModifiers
Definition: QuartzWindow.h:134
BOOL fPassiveGrabOwnerEvents
Definition: QuartzWindow.h:170
CGContextRef fContext
Definition: QuartzWindow.h:154
unsigned fWidth()
QuartzWindow * fMainWindow
Definition: QuartzWindow.h:33
BOOL fSnapshotDraw
Definition: QuartzWindow.h:171
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:160
unsigned fPassiveGrabKeyModifiers
Definition: QuartzWindow.h:168
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:184
bool ViewIsTextViewFrame(NSView< X11Window > *view, bool checkParent)
unsigned fActiveGrabEventMask
Definition: QuartzWindow.h:169
int fPassiveGrabButton
Definition: QuartzWindow.h:166
NSMutableArray * fPassiveKeyGrabs
Definition: QuartzWindow.h:176
BOOL fIsOverlapped
Definition: QuartzWindow.h:177