]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/RenderElement.h
Implemented proper reference management accross render-elements, render-element-lists...
[u/mrichter/AliRoot.git] / EVE / Reve / RenderElement.h
1 // $Header$
2
3 #ifndef REVE_RenderElement_H
4 #define REVE_RenderElement_H
5
6 #include <Reve/Reve.h>
7
8 #include <TNamed.h>
9 #include <TRef.h>
10
11 #include <Gtypes.h>
12 #include <GuiTypes.h>
13
14 #include <list>
15 #include <set>
16
17 class TGListTree;
18 class TGListTreeItem;
19
20 namespace Reve {
21
22 class RenderElement
23 {
24   friend class RGTopFrame;
25
26 public:
27   struct ListTreeInfo {
28     TGListTree*     fTree;
29     TGListTreeItem* fItem;
30
31     ListTreeInfo() {}
32     ListTreeInfo(TGListTree* lt, TGListTreeItem* lti) : fTree(lt), fItem(lti) {}
33     virtual ~ListTreeInfo() {}
34
35     bool operator==(const ListTreeInfo& x) const
36     { return fTree == x.fTree && fItem == x.fItem; }
37     bool operator<(const ListTreeInfo& x) const
38     { return fTree == x.fTree ? fItem < x.fItem : fTree < x.fTree; }
39
40     ClassDef(ListTreeInfo, 0);
41   };
42   typedef std::set<ListTreeInfo>               sLTI_t;
43   typedef std::set<ListTreeInfo>::iterator     sLTI_i;
44
45   typedef std::list<RenderElement*>            lpRE_t;
46   typedef std::list<RenderElement*>::iterator  lpRE_i;
47
48 protected:
49   // TRef     fSource;
50
51   Bool_t   fRnrElement;
52   Color_t* fMainColorPtr;
53
54   sLTI_t fItems;
55   lpRE_t fParents;
56
57   Bool_t fDestroyOnZeroRefCnt;
58   Bool_t fDenyDestroy;
59
60 public:
61   RenderElement();
62   RenderElement(Color_t& main_color);
63   virtual ~RenderElement();
64
65   virtual void AddParent(RenderElement* re);
66   virtual void RemoveParent(RenderElement* re);
67
68   Bool_t GetDestroyOnZeroRefCnt() const   { return fDestroyOnZeroRefCnt; }
69   void   SetDestroyOnZeroRefCnt(Bool_t d) { fDestroyOnZeroRefCnt = d; }
70
71   Bool_t GetDenyDestroy() const   { return fDenyDestroy; }
72   void   SetDenyDestroy(Bool_t d) { fDenyDestroy = d; }
73
74   virtual TObject* GetObject(Reve::Exc_t eh="RenderElement::GetObject ");
75
76   /*
77     TRef&    GetSource() { return fSource; }
78     TObject* GetSourceObject() const { return fSource.GetObject(); }
79     void SetSourceObject(TObject* o) { fSource.SetObject(o); }
80
81     void DumpSourceObject();    // *MENU*
82     void InspectSourceObject(); // *MENU*
83   */
84
85   virtual TGListTreeItem* AddIntoListTree(TGListTree* ltree,
86                                           TGListTreeItem* parent_lti);
87   virtual TGListTreeItem* AddIntoListTree(TGListTree* ltree,
88                                           RenderElement* parent);
89   virtual Bool_t          RemoveFromListTree(TGListTree* ltree);
90   virtual Bool_t          RemoveFromListTree(TGListTree* ltree,
91                                              TGListTreeItem* parent_lti);
92
93   virtual sLTI_i          FindItem(TGListTree* ltree);
94   virtual sLTI_i          FindItem(TGListTree* ltree,
95                                    TGListTreeItem* parent_lti);
96   virtual TGListTreeItem* FindListTreeItem(TGListTree* ltree);
97   virtual TGListTreeItem* FindListTreeItem(TGListTree* ltree,
98                                            TGListTreeItem* parent_lti);
99
100   virtual void UpdateItems();
101
102   void SpawnEditor();                  // *MENU*
103   void ExportToCINT(Text_t* var_name); // *MENU*
104
105   virtual void Destroy();              // *MENU*
106
107   virtual Bool_t CanEditRnrElement()   { return kTRUE; }
108   virtual Bool_t GetRnrElement() const { return fRnrElement; }
109   virtual void   SetRnrElement(Bool_t rnr);
110
111   virtual Bool_t CanEditMainColor()        { return kFALSE; }
112   Color_t* GetMainColorPtr()               { return fMainColorPtr; }
113   void     SetMainColorPtr(Color_t* color) { fMainColorPtr = color; }
114
115   virtual Color_t GetMainColor() const { return fMainColorPtr ? *fMainColorPtr : 0; }
116   virtual void    SetMainColor(Color_t color);
117           void    SetMainColor(Pixel_t pixel);
118
119   ClassDef(RenderElement, 1);
120 }; // endclass RenderElement
121
122 /**************************************************************************/
123
124 class RenderElementObjPtr : public RenderElement,
125                             public TObject
126 {
127 protected:
128   TObject* fObject;
129   Bool_t   fOwnObject;
130
131 public:
132   RenderElementObjPtr(TObject* obj, Bool_t own=kTRUE);
133   RenderElementObjPtr(TObject* obj, Color_t& mainColor, Bool_t own=kTRUE);
134   virtual ~RenderElementObjPtr();
135
136   virtual TObject* GetObject(Exc_t eh="RenderElementObjPtr::GetObject ");
137
138   Bool_t GetOwnObject() const   { return fOwnObject; }
139   void   SetOwnObject(Bool_t o) { fOwnObject = o; }
140
141   ClassDef(RenderElementObjPtr, 1);
142 }; // endclass RenderElementObjPtr
143
144 /**************************************************************************/
145
146 class RenderElementListBase : public RenderElement
147 {
148 protected:
149   lpRE_t fChildren;
150
151   void PaintElements(Option_t* option="");
152
153 public:
154   RenderElementListBase() {}
155   RenderElementListBase(Color_t& col) : RenderElement(col) {}
156   virtual ~RenderElementListBase();
157
158   virtual void AddElement(RenderElement* el);
159   virtual void RemoveElement(RenderElement* el);
160   virtual void RemoveElementLocal(RenderElement* el);
161   virtual void RemoveElements();
162
163   virtual Int_t ExpandIntoListTree(TGListTree* ltree, TGListTreeItem* parent);
164   virtual Int_t DestroyListSubTree(TGListTree* ltree, TGListTreeItem* parent);
165
166   void EnableListElements();   // *MENU*
167   void DisableListElements();  // *MENU*
168
169   virtual void SetMainColor(Color_t color);
170   virtual void SetMainColor(Pixel_t pixel);
171
172   ClassDef(RenderElementListBase, 1);
173 };
174
175 /**************************************************************************/
176
177 class RenderElementList : public RenderElementListBase,
178                           public TNamed
179 {
180 protected:
181   Color_t   fColor;
182   Bool_t    fDoColor;
183
184 public:
185   RenderElementList(const Text_t* n="RenderElementList", const Text_t* t="",
186                     Bool_t doColor=kFALSE);
187   virtual ~RenderElementList() {}
188
189   virtual Bool_t CanEditMainColor()  { return fDoColor; }
190
191   virtual void Paint(Option_t* option = "") { PaintElements(option); }
192
193   ClassDef(RenderElementList, 1);
194 };
195
196 }
197
198 #endif