Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TEveWindowManager.cxx
Go to the documentation of this file.
1 // @(#)root/eve:$Id$
2 // Author: Matevz Tadel 2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, 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 #include "TEveWindowManager.h"
13 #include "TEveWindow.h"
14 
15 /** \class TEveWindowManager
16 \ingroup TEve
17 Manager for EVE windows.
18 
19 Provides the concept of the current window and takes care for proper
20 destruction of the windows.
21 
22 It is also the EVE-parent of windows that are not attached into the
23 hierarchy of EVE-windows.
24 
25 Window-manager is created by the EVE-manager and can be retrieved via:
26 ~~~ {.cpp}
27  gEve->GetWindowManager.
28 ~~~
29 */
30 
31 ClassImp(TEveWindowManager);
32 
33 ////////////////////////////////////////////////////////////////////////////////
34 /// Constructor.
35 
36 TEveWindowManager::TEveWindowManager(const char* n, const char* t) :
37  TEveElementList(n, t),
38  TQObject (),
39  fCurrentWindow (0),
40  fDefaultContainer (0)
41 {
42 }
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// Destructor.
46 
47 TEveWindowManager::~TEveWindowManager()
48 {
49 }
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Entry-point for communicating the fact that a window was acted
53 /// upon in such a way that it should become the current window.
54 /// If the passed window is already the current one, it is deselected.
55 ///
56 /// For example, this is called from title-bar, when creating a new
57 /// window slot, etc.
58 ///
59 /// If the change is accepted (the manager can refuse to make a
60 /// window current), the state of window is changed accordingly and
61 /// WindowSelected() signal is emitted.
62 
63 void TEveWindowManager::SelectWindow(TEveWindow* window)
64 {
65  if (window == fCurrentWindow)
66  window = 0;
67 
68  if (fCurrentWindow)
69  fCurrentWindow->SetCurrent(kFALSE);
70 
71  fCurrentWindow = window;
72 
73  if (fCurrentWindow)
74  fCurrentWindow->SetCurrent(kTRUE);
75 
76  WindowSelected(fCurrentWindow);
77 }
78 
79 ////////////////////////////////////////////////////////////////////////////////
80 /// Called by a window before it gets deleted.
81 
82 void TEveWindowManager::DeleteWindow(TEveWindow* window)
83 {
84  if (window == fCurrentWindow)
85  {
86  fCurrentWindow = 0;
87  WindowSelected(fCurrentWindow);
88  }
89  WindowDeleted(window);
90 }
91 
92 ////////////////////////////////////////////////////////////////////////////////
93 /// Emit the "WindowDocked(TEveWindow*)" signal.
94 
95 void TEveWindowManager::WindowDocked(TEveWindow* window)
96 {
97  Emit("WindowDocked(TEveWindow*)", (Long_t)window);
98 }
99 
100 ////////////////////////////////////////////////////////////////////////////////
101 /// Emit the "WindowUndocked(TEveWindow*)" signal.
102 
103 void TEveWindowManager::WindowUndocked(TEveWindow* window)
104 {
105  Emit("WindowUndocked(TEveWindow*)", (Long_t)window);
106 }
107 
108 ////////////////////////////////////////////////////////////////////////////////
109 /// Emit the "WindowSelected(TEveWindow*)" signal.
110 
111 void TEveWindowManager::WindowSelected(TEveWindow* window)
112 {
113  Emit("WindowSelected(TEveWindow*)", (Long_t)window);
114 }
115 
116 ////////////////////////////////////////////////////////////////////////////////
117 /// Emit the "WindowDeleted(TEveWindow*)" signal.
118 
119 void TEveWindowManager::WindowDeleted(TEveWindow* window)
120 {
121  Emit("WindowDeleted(TEveWindow*)", (Long_t)window);
122 }
123 
124 ////////////////////////////////////////////////////////////////////////////////
125 /// Return current window dynamic-casted to TEveWindowSlot.
126 
127 TEveWindowSlot* TEveWindowManager::GetCurrentWindowAsSlot() const
128 {
129  return dynamic_cast<TEveWindowSlot*>(fCurrentWindow);
130 }
131 
132 void TEveWindowManager::SetDefaultContainer(TEveWindow* w)
133 {
134  // Set default container window.
135  // It has to be able to create new slots.
136  // When main-frames are closed they will place the windows here.
137 
138  static const TEveException kEH("TEveWindowManager::SetDefaultContainer ");
139 
140  if ( ! w->CanMakeNewSlots())
141  throw kEH + "Given window can not make new slots.";
142 
143  fDefaultContainer = w;
144 }
145 
146 ////////////////////////////////////////////////////////////////////////////////
147 /// Destroy window's children and then the window itself.
148 /// Protected method used during shutdown.
149 
150 void TEveWindowManager::DestroyWindowRecursively(TEveWindow* window)
151 {
152  while (window->HasChildren())
153  {
154  TEveWindow* w = dynamic_cast<TEveWindow*>(window->FirstChild());
155  if (w)
156  DestroyWindowRecursively(w);
157  else
158  window->RemoveElement(window->FirstChild());
159  }
160  window->DestroyWindowAndSlot();
161 }
162 
163 ////////////////////////////////////////////////////////////////////////////////
164 /// Wait for all windows to shut-down.
165 
166 void TEveWindowManager::DestroyWindows()
167 {
168  while (HasChildren())
169  {
170  TEveWindow* w = dynamic_cast<TEveWindow*>(FirstChild());
171  if (w)
172  DestroyWindowRecursively(w);
173  else
174  RemoveElement(FirstChild());
175  }
176 
177 }
178 
179 ////////////////////////////////////////////////////////////////////////////////
180 /// Hide all eve decorations (title-bar and mini-bar) on all frames.
181 
182 void TEveWindowManager::HideAllEveDecorations()
183 {
184  TEveCompositeFrame *ecf = 0;
185  TIter wins(TEveCompositeFrame::fgFrameList);
186  while ((ecf = (TEveCompositeFrame*) wins()))
187  {
188  ecf->HideAllDecorations();
189  ecf->Layout();
190  }
191 }
192 
193 ////////////////////////////////////////////////////////////////////////////////
194 /// Show eve decorations (title-bar or mini-bar) as specified for
195 /// the contained window on all frames.
196 
197 void TEveWindowManager::ShowNormalEveDecorations()
198 {
199  TEveCompositeFrame *ecf = 0;
200  TIter wins(TEveCompositeFrame::fgFrameList);
201  while ((ecf = (TEveCompositeFrame*) wins()))
202  {
203  ecf->ShowNormalDecorations();
204  ecf->Layout();
205  }
206 }
207 
208 ////////////////////////////////////////////////////////////////////////////////
209 /// Set show title-bar state on all frames.
210 /// This does not modify the per-window settings - call
211 /// ShowNormalEveDecorations() to restore them.
212 
213 void TEveWindowManager::SetShowTitleBars(Bool_t state)
214 {
215  TEveCompositeFrame *ecf = 0;
216  TIter wins(TEveCompositeFrame::fgFrameList);
217  while ((ecf = (TEveCompositeFrame*) wins()))
218  {
219  ecf->SetShowTitleBar(state);
220  ecf->Layout();
221  }
222 }