Lumiera  0.pre.03
»edit your freedom«
panel-manager.hpp
Go to the documentation of this file.
1 /*
2  PANEL-MANAGER.hpp - management of dockable GDL panels
3 
4  Copyright (C) Lumiera.org
5  2008, Joel Holdsworth <joel@airwebreathe.org.uk>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
34 #ifndef STAGE_WORKSPACE_PANEL_MANAGER_H
35 #define STAGE_WORKSPACE_PANEL_MANAGER_H
36 
37 #include "stage/panel/panel.hpp"
38 
39 #include <gdlmm.h>
40 #include <typeinfo>
41 
42 
43 using namespace stage::panel;
44 
45 namespace stage {
46 namespace workspace {
47 
48 
54  {
57 
61  Gdl::Dock dock_;
62 
66  Gdl::DockBar dockBar_;
67 
71  Glib::RefPtr<Gdl::DockLayout> dockLayout_;
72 
76  GdlDockPlaceholder *dockPlaceholders_[4];
77 
79  std::list<panel::Panel*> panels_;
80 
84  static unsigned short panelID;
85 
86 
87  public:
89  ~PanelManager();
90 
95  void setupDock();
96 
101  Gdl::Dock& getDock();
102 
107  Gdl::DockBar& getDockBar();
108 
112  WorkspaceWindow& getWorkspaceWindow();
113 
119  panel::Panel& showPanel (const int description_index);
120 
122  bool hasPanel (const int description_index);
123 
131  void switchPanel (panel::Panel& old_panel, const int description_index);
132 
138  void splitPanel (panel::Panel& panel, Gtk::Orientation split_direction);
139 
140 
141  public:
147  template<class P>
148  static int findPanelID();
149 
151  static int getPanelDescriptionCount();
152 
158  static const gchar* getPanelStockID (const int index);
159 
165  static const char* getPanelTitle (int index);
166 
167 
168  private:
170  void createPanels();
171 
178  static int findPanelDescription (const char* class_name);
179 
185  panel::Panel* createPanel_by_index (const int index);
186 
193  panel::Panel* createPanel_by_index (const int index, Gdl::DockItem& dock_item);
194 
200  panel::Panel* createPanel_by_name (const char* class_name);
201 
208  int getPanelType (panel::Panel* const panel) const;
209 
214  void removePanel (panel::Panel* const panel);
215 
217  void clearPanels();
218 
219 
220  private:
225  void on_panel_shown (panel::Panel *panel);
226 
227 
228 
229  private:
230 
235  {
236  protected:
237  typedef panel::Panel* (*const CreatePanelProc)(PanelManager&, Gdl::DockItem&);
239  private:
241  const std::type_info& classInfo_;
242 
244  const char* const titleName_;
245 
247  const gchar* const stockID_;
248 
250  CreatePanelProc createPanelProc_;
251 
252 
253  protected:
260  PanelDescription (std::type_info const& classInfo
261  ,const char* title
262  ,const gchar* stockID
263  ,CreatePanelProc createPanelProc)
264  : classInfo_(classInfo)
265  , titleName_(title)
266  , stockID_(stockID)
267  , createPanelProc_(createPanelProc)
268  {
269  REQUIRE(titleName_);
270  }
271 
272 
273  public:
274  const std::type_info& getClassInfo() const
275  {
276  return classInfo_;
277  }
278 
279  const char* getClassName() const
280  {
281  return classInfo_.name();
282  }
283 
285  const char* getTitle() const
286  {
287  ENSURE(titleName_);
288  return titleName_;
289  }
290 
291  const gchar* getStockID() const
292  {
293  ENSURE(stockID_);
294  return stockID_;
295  }
296 
297 
304  panel::Panel*
305  create (PanelManager& panelManager, Gdl::DockItem& dockItem) const
306  {
307  REQUIRE(createPanelProc_);
308  return createPanelProc_ (panelManager, dockItem);
309  }
310  };
311 
312 
313 
318  template<class P>
319  class Panel
320  : public PanelDescription
321  {
322  public:
323  Panel()
324  : PanelDescription (typeid(P)
325  ,P::getTitle()
326  ,P::getStockID()
327  ,Panel::createPanel)
328  { }
329 
330  private:
336  static panel::Panel*
337  createPanel (PanelManager& panelManager, Gdl::DockItem& dockItem)
338  {
339  return new P(panelManager, dockItem);
340  }
341  };
342 
343 
345  static const PanelDescription panelDescriptionList[];
346  };
347 
348 
349 
350 
351  template<class P>
352  inline int
353  PanelManager::findPanelID()
354  {
355  return PanelManager::findPanelDescription (typeid(P).name());
356  }
357 
358 
359 
360 }}// namespace stage::workspace
361 #endif /*STAGE_WORKSPACE_PANEL_MANAGER_H*/
const char *const titleName_
localised title that will be shown on the panel.
WorkspaceWindow & workspaceWindow_
reference to the owner workspace window object
std::list< panel::Panel * > panels_
list of all panels created
const std::type_info & classInfo_
reference to the typeID of this class
Docking panel classes.
CreatePanelProc createPanelProc_
pointer to a function that will instantiate the panel object
static unsigned short panelID
An accumulator for the panel id.
PanelDescription(std::type_info const &classInfo, const char *title, const gchar *stockID, CreatePanelProc createPanelProc)
A class to manage DockItem objects for WorkspaceWindow.
Gdl::DockBar dockBar_
The pointer to GDL dock bar widget.
The base class for all dockable panels.
Definition: panel.hpp:49
Base class and interface for all dockable panels.
A helper class that will create PanelDescription objects.
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:46
Gdl::Dock dock_
The pointer to GDL dock widget.
Glib::RefPtr< Gdl::DockLayout > dockLayout_
The pointer to GDL dock layout object.
panel::Panel * create(PanelManager &panelManager, Gdl::DockItem &dockItem) const
Creates an instance of this panel.
The main Lumiera workspace window.
static panel::Panel * createPanel(PanelManager &panelManager, Gdl::DockItem &dockItem)
helper function to create a panel of type P
const gchar *const stockID_
Stock ID for this type of panel.
const char * getTitle() const
the localised title that will be shown on the panel
ElementBoxWidget::Config::Qualifier name(string id)
define the name-ID displayed in the caption
A class to describe and instantiate Panel types.