Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
panel-manager.cpp
Go to the documentation of this file.
1/*
2 PanelManager - management of dockable GDL panels
3
4 Copyright (C)
5 2008, Joel Holdsworth <joel@airwebreathe.org.uk>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12* *****************************************************************/
13
14
23
29
30#include "include/logging.h"
31#include "lib/util-foreach.hpp"
32
33using namespace boost;
34using namespace std;
35using namespace Gtk;
36
37namespace stage {
38namespace workspace {
39
40 const PanelManager::PanelDescription
42 PanelManager::Panel<TimelinePanel>(),
43 PanelManager::Panel<InfoBoxPanel>(),
44 PanelManager::Panel<ViewerPanel>(),
45 PanelManager::Panel<PlayPanel>(),
46 PanelManager::Panel<AssetsPanel>()
47 };
48
49 unsigned short PanelManager::panelID = 0;
50
51
52
54 : workspaceWindow_(owner)
55 , dock_()
56 , dockBar_(dock_)
57 , dockLayout_()
58 {
59 /* Create the DockLayout */
60 dockLayout_ = Gdl::DockLayout::create(dock_);
61
62 /* Setup the Switcher Style */
63 Glib::RefPtr<Gdl::DockMaster> dock_master = dock_.property_master();
64 dock_master->property_switcher_style() = Gdl::SWITCHER_STYLE_ICON;
65
66 memset(&dockPlaceholders_, 0, sizeof(dockPlaceholders_));
67 }
68
69
70
72 {
75
76#if false
78 for(int i = 0; i < 4; i++)
80 g_object_unref(dockPlaceholders_[i]);
81
83#endif
84 }
85
86
87
88 void
90 {
92
93 REQUIRE(dockPlaceholders_[0] == NULL && dockPlaceholders_[1] == NULL &&
95 dockPlaceholders_[0] = GDL_DOCK_PLACEHOLDER(gdl_dock_placeholder_new(
96 "ph1", GDL_DOCK_OBJECT(dock_.gobj()), GDL_DOCK_TOP, FALSE));
97 dockPlaceholders_[1] = GDL_DOCK_PLACEHOLDER(gdl_dock_placeholder_new(
98 "ph2", GDL_DOCK_OBJECT(dock_.gobj()), GDL_DOCK_BOTTOM, FALSE));
99 dockPlaceholders_[2] = GDL_DOCK_PLACEHOLDER(gdl_dock_placeholder_new(
100 "ph3", GDL_DOCK_OBJECT(dock_.gobj()), GDL_DOCK_LEFT, FALSE));
101 dockPlaceholders_[3] = GDL_DOCK_PLACEHOLDER(gdl_dock_placeholder_new(
102 "ph4", GDL_DOCK_OBJECT(dock_.gobj()), GDL_DOCK_RIGHT, FALSE));
103 ENSURE(dockPlaceholders_[0] and dockPlaceholders_[1] and
105
106 createPanels();
107 }
108
109
110 Gdl::Dock&
112 {
113 return dock_;
114 }
115
116
117 Gdl::DockBar&
119 {
120 return dockBar_;
121 }
122
123
129
130
131 bool
132 PanelManager::hasPanel (const int description_index)
133 {
134 return util::has_any (panels_, [&](panel::Panel* panel)
135 {
136 return getPanelType(panel) == description_index;
137 });
138 }
139
141 PanelManager::showPanel (const int description_index)
142 {
143 // Try and find the panel and present it if possible
144 list< panel::Panel* >::iterator i;
145 for(i = panels_.begin(); i != panels_.end(); i++)
146 {
147 panel::Panel* const panel = *i;
148 if (getPanelType(panel) == description_index)
149 {
150 if (!panel->is_shown()) panel->show();
151
152 Gdl::DockItem &dock_item = panel->getDockItem();
153 dock_item.present(dock_);
154 ENSURE (panel);
155 return *panel;
156 }
157 }
158
159 // Create the new panel
160 panel::Panel *new_panel = createPanel_by_index (description_index);
161
162 // Dock the item
163 dock_.add_item(new_panel->getDockItem(), Gdl::DOCK_FLOATING);
164
165 ENSURE (new_panel);
166 return *new_panel;
167 }
168
169
170 void
171 PanelManager::switchPanel (panel::Panel& old_panel, const int description_index)
172 {
173 REQUIRE (description_index >= 0);
174 REQUIRE (description_index < getPanelDescriptionCount());
175
176 // Get the dock item
177 Gdl::DockItem &dock_item = old_panel.getDockItem();
178
179 // Release the old panel
180 removePanel (&old_panel);
181
182 // Create the new panel
183 createPanel_by_index (description_index, dock_item);
184 }
185
186
187 void
188 PanelManager::splitPanel (panel::Panel& panel, Gtk::Orientation split_direction, panel::Panel* toAdd)
189 {
190 if (not toAdd)
191 {// then duplicate the panel to split...
192 int index = getPanelType(&panel);
193 toAdd = createPanel_by_index(index);
194 }
195 // Dock the panel
196 Gdl::DockPlacement placement = Gdl::DOCK_NONE;
197 switch(split_direction)
198 {
199 case ORIENTATION_HORIZONTAL:
200 placement = Gdl::DOCK_RIGHT;
201 break;
202
203 case ORIENTATION_VERTICAL:
204 placement = Gdl::DOCK_BOTTOM;
205 break;
206
207 default:
208 ERROR (stage, "Unknown split_direction: %d", split_direction);
209 return;
210 break;
211 }
212
213 panel.getDockItem().dock(
214 toAdd->getDockItem(),placement);
215 }
216
217
218 int
223
224
225 const gchar*
227 {
228 REQUIRE (index >= 0);
229 REQUIRE (index < getPanelDescriptionCount());
230 return panelDescriptionList[index].getStockID();
231 }
232
233
234 const char*
236 {
237 REQUIRE (index >= 0);
238 REQUIRE (index < getPanelDescriptionCount());
239 return panelDescriptionList[index].getTitle();
240 }
241
242
243 void
245 {
247 panel::Panel* playPanel = createPanel_by_name("PlayPanel");
248 panel::Panel* viewerPanel = createPanel_by_name("ViewerPanel");
249 panel::Panel* infoBoxPanel = createPanel_by_name("InfoBoxPanel");
250 panel::Panel* timelinePanel = createPanel_by_name("TimelinePanel");
251
252 dock_.add_item(viewerPanel->getDockItem(),Gdl::DOCK_LEFT);
253 dock_.add_item(timelinePanel->getDockItem(),Gdl::DOCK_BOTTOM);
254 dock_.add_item(infoBoxPanel->getDockItem(),Gdl::DOCK_RIGHT);
255 splitPanel(*infoBoxPanel, ORIENTATION_VERTICAL, playPanel);
256 }
257
258
259 int
260 PanelManager::findPanelDescription (const char* class_name)
261 {
262 REQUIRE(class_name);
263
264 const int count = getPanelDescriptionCount();
265 for(int i = 0; i < count; i++)
266 {
267 if (strstr(panelDescriptionList[i].getClassName(), class_name))
268 return i;
269 }
270
271 ERROR (stage, "Unable to find a description with class name %s", class_name);
272 return -1;
273 }
274
275
278 {
279 REQUIRE(index >= 0 && index < getPanelDescriptionCount());
280
281 // Make a unique name for the panel
282 char name[5];
283 snprintf(name, sizeof(name), "%X", panelID++);
284
285 // Create a dock item
286 return createPanel_by_index(index,
287 *new Gdl::DockItem(name,"",Gdl::DOCK_ITEM_BEH_NORMAL));
288 }
289
290
292 PanelManager::createPanel_by_index (const int index, Gdl::DockItem &dock_item)
293 {
294 // Create the panel object
295 panel::Panel *panel = panelDescriptionList[index].create(*this, dock_item);
296 ENSURE(panel);
297 panel->show_all();
298
299 // Connect event handlers
300 panel->signal_hidePanel().connect(sigc::bind(
301 sigc::mem_fun(*this, &PanelManager::on_panel_shown), panel));
302
303 // Add the panel to the list
304 panels_.push_back(panel);
305
306 return panel;
307 }
308
309
311 PanelManager::createPanel_by_name (const char* class_name)
312 {
313 REQUIRE(class_name);
314 const int index = findPanelDescription(class_name);
315 return createPanel_by_index(index);
316 }
317
318
319 int
321 {
322 REQUIRE(panel);
323
324 const type_info &info = typeid(*panel);
325 const int count = getPanelDescriptionCount();
326 for(int i = 0; i < count; i++)
327 {
328 if(info == panelDescriptionList[i].getClassInfo())
329 return i;
330 }
331
332 ERROR (stage, "Unable to find a description with with this class type");
333 return -1;
334 }
335
336
337 void
339 {
340 REQUIRE(panel);
341
342 list< panel::Panel* >::iterator i;
343 for(i = panels_.begin(); i != panels_.end(); i++)
344 {
345 if(*i == panel)
346 {
347 delete panel;
348 panels_.erase(i);
349 break;
350 }
351 }
352 }
353
354
355 void
357 {
359
360 list< panel::Panel* >::iterator i;
361 for(i = panels_.begin(); i != panels_.end(); i++)
362 delete *i;
363 panels_.clear();
364 }
365
366
367 void
369 {
370 REQUIRE(panel);
371 if(panel->is_shown() || panel->is_iconified()) return;
372
373 removePanel(panel);
374 }
375
376
377
378}}// namespace stage::workspace
A (dockable) panel to organise the assets of a project.
The base class for all dockable panels.
Definition panel.hpp:42
bool is_iconified() const
Definition panel.cpp:113
Gdl::DockItem & getDockItem()
Definition panel.cpp:86
sigc::signal< void > & signal_hidePanel()
fires when the dock item gets hidden.
Definition panel.cpp:151
void show(bool show=true)
Shows or hides the panel.
Definition panel.cpp:92
bool is_shown() const
Definition panel.cpp:100
A class to describe and instantiate Panel types.
const char * getTitle() const
the localised title that will be shown on the panel
panel::Panel * create(PanelManager &panelManager, Gdl::DockItem &dockItem) const
Creates an instance of this panel.
std::list< panel::Panel * > panels_
list of all panels created
void createPanels()
Creates the standard panel layout.
Glib::RefPtr< Gdl::DockLayout > dockLayout_
The pointer to GDL dock layout object.
panel::Panel * createPanel_by_name(CStr class_name)
Creates a panel by class name.
Gdl::Dock & getDock()
Gets a pointer to the dock object.
panel::Panel * createPanel_by_index(const int index)
Creates a panel by description index.
WorkspaceWindow & workspaceWindow_
reference to the owner workspace window object
WorkspaceWindow & getWorkspaceWindow()
Returns a reference to the owner workspace window.
GdlDockPlaceholder * dockPlaceholders_[4]
Pointers to the 4 root place holders.
static const PanelDescription panelDescriptionList[]
The list of panel descriptions.
static int getPanelDescriptionCount()
Gets the number of panel descriptions.
static const char * getPanelTitle(int index)
Gets a panel description's title.
void on_panel_shown(panel::Panel *panel)
An event handler for when the panel is shown or hidden.
static unsigned short panelID
An accumulator for the panel id.
void splitPanel(panel::Panel &panel, Gtk::Orientation split_direction, panel::Panel *toAdd=nullptr)
Splits a panel into two panels of the same type.
bool hasPanel(const int description_index)
was the indicated panel already allocated within this PanelManager's realm?
Gdl::DockBar & getDockBar()
Gets a pointer to the dock bar.
void setupDock()
Initialises this dock manager and creates the dock and all it's widgets.
static int findPanelDescription(CStr class_name)
Find the index of a panel description given the class name.
panel::Panel & showPanel(const int description_index)
Shows a panel given a description index.
void removePanel(panel::Panel *const panel)
Removes a panel from the panel list and deletes it.
int getPanelType(panel::Panel *const panel) const
Gets the type of a given panel.
Gdl::Dock dock_
The pointer to GDL dock widget.
void switchPanel(panel::Panel &old_panel, const int description_index)
Switches a panel from one type to another, without touching the underlying GdlDockItem.
Gdl::DockBar dockBar_
The pointer to GDL dock bar widget.
void clearPanels()
Removes all panels from the panel list and deletes them.
static const gchar * getPanelStockID(const int index)
Gets a panel description's stock id.
The main Lumiera workspace window.
A (dockable) panel to display and manage information and parameters.
return NULL
Definition llist.h:586
This header is for including and configuring NoBug.
Lumiera GTK UI implementation root.
Definition guifacade.cpp:37
STL namespace.
bool has_any(IT i, IT end, FUN predicate)
Existential quantification: check if any element of a collection satisfies the given predicate.
Management of dockable panels.
Definition of a dockable panel for playback control //////////////////////////////////////////////TIC...
A dockable container to hold a notebook of timeline displays.
Perform operations "for each element" of a collection.
Definition of a dockable panel to hold a video viewer.