Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
CocoaPrivate.h
Go to the documentation of this file.
1 // @(#)root/graf2d:$Id$
2 // Author: Timur Pocheptsov 29/11/2011
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 
13 #ifndef ROOT_CocoaPrivate
14 #define ROOT_CocoaPrivate
15 
16 #include <vector>
17 #include <map>
18 
19 #include "CocoaUtils.h"
20 #include "X11Colors.h"
21 #include "X11Events.h"
22 #include "X11Buffer.h"
23 #include "GuiTypes.h"
24 #include "FontCache.h"
25 
26 @protocol X11Drawable;
27 @protocol X11Window;
28 
29 @class ROOTApplicationDelegate;
30 @class NSOpenGLContext;
31 @class NSObject;
32 
33 @class QuartzWindow;
34 
35 class TGQuartz;
36 class TGCocoa;
37 
38 ///////////////////////////////////////////////
39 // //
40 // CocoaPrivate. Hidden implementation //
41 // details for TGCocoa. //
42 // //
43 ///////////////////////////////////////////////
44 
45 namespace ROOT {
46 namespace MacOSX {
47 namespace Details {
48 
49 class CocoaPrivate {
50  friend class ::TGCocoa;
51  friend class ::TGQuartz;
52  friend class X11::CommandBuffer;
53 public:
54  ~CocoaPrivate();
55 private:
56  CocoaPrivate();
57 
58  Window_t GetRootWindowID()const;
59  bool IsRootWindow(Window_t windowID)const;
60 
61  CocoaPrivate(const CocoaPrivate &rhs);
62  CocoaPrivate &operator = (const CocoaPrivate &rhs);
63 
64  Drawable_t RegisterDrawable(NSObject *nsObj);
65  NSObject<X11Drawable> *GetDrawable(Drawable_t drawableD)const;
66  NSObject<X11Window> *GetWindow(Window_t windowID)const;
67  void DeleteDrawable(Drawable_t drawableID);
68 
69  Handle_t RegisterGLContext(NSOpenGLContext *glContext);
70  void DeleteGLContext(Handle_t contextID);
71  NSOpenGLContext *GetGLContextForHandle(Handle_t contextID);
72  Handle_t GetHandleForGLContext(NSOpenGLContext *glContext);
73 
74  void SetFakeGLWindow(QuartzWindow *fakeWin);
75  QuartzWindow *GetFakeGLWindow();
76 
77  //This function resets strong reference, if you still want NSObject for drawableID to live,
78  //you have to retain the pointer (probably) and also drawableID will become id for nsObj (replacement).
79  void ReplaceDrawable(Drawable_t drawableID, NSObject *nsObj);
80 
81  //Color "parser": either parse string like "#ddeeaa", or
82  //search rgb.txt like table for named color.
83  X11::ColorParser fX11ColorParser;
84  //Event translator, converts Cocoa events into X11 events
85  //and generates X11 events.
86  X11::EventTranslator fX11EventTranslator;
87  //Command buffer - for "buffered" drawing commands.
88  X11::CommandBuffer fX11CommandBuffer;
89  //Font manager - cache CTFontRef for GUI.
90  FontCache fFontManager;
91 
92  //Id for the new registered drawable.
93  Drawable_t fCurrentDrawableID;
94  //"Cache" of ids.
95  std::vector<Drawable_t> fFreeDrawableIDs;
96  //Cocoa objects (views, windows, "pixmaps").
97  std::map<unsigned, Util::NSStrongReference<NSObject<X11Drawable> > > fDrawables;
98  typedef std::map<unsigned, Util::NSStrongReference<NSObject<X11Drawable> > >::iterator drawable_iterator;
99  typedef std::map<unsigned, Util::NSStrongReference<NSObject<X11Drawable> > >::const_iterator const_drawable_iterator;
100 
101  typedef std::map<Handle_t, Util::NSStrongReference<NSOpenGLContext> > handle2ctx_map;
102  typedef std::map<NSOpenGLContext *, Handle_t> ctx2handle_map;
103 
104  handle2ctx_map fHandleToGLContext;
105  ctx2handle_map fGLContextToHandle;
106 
107  Handle_t fFreeGLContextID;
108  Util::NSStrongReference<QuartzWindow> fFakeGLWindow;
109 
110  Util::NSScopeGuard<ROOTApplicationDelegate> fApplicationDelegate;
111 };
112 
113 }//Details
114 }//MacOSX
115 }//ROOT
116 
117 #endif