Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
dock-area.cpp
Go to the documentation of this file.
1/*
2 DockArea - maintain a docking area within the WorkspaceWindow
3
4 Copyright (C)
5 2008, Joel Holdsworth <joel@airwebreathe.org.uk>
6 2018, Hermann Vosseler <Ichthyostega@web.de>
7
8  **Lumiera** is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by the
10  Free Software Foundation; either version 2 of the License, or (at your
11  option) any later version. See the file COPYING for further details.
12
13* *****************************************************************/
14
15
26
28
33
34#include "include/logging.h"
35#include "lib/util-foreach.hpp"
36
37using namespace boost;
38using namespace std;
39using namespace Gtk;
40
41namespace stage {
42namespace workspace {
43
44 const DockArea::PanelDescription
46#if false
47 DockArea::Panel<TimelinePanel>(),
48 DockArea::Panel<InfoBoxPanel>(),
49 DockArea::Panel<ViewerPanel>(),
50 DockArea::Panel<AssetsPanel>()
51#endif
52 };
53
54 unsigned short DockArea::panelID = 0;
55
56
57
59 : workspaceWindow_(owner)
60 , dock_()
61 , dockBar_(dock_)
62 , dockLayout_()
63 {
64 /* Create the DockLayout */
65 dockLayout_ = Gdl::DockLayout::create(dock_);
66
67 /* Setup the Switcher Style */
68 Glib::RefPtr<Gdl::DockMaster> dock_master = dock_.property_master();
69 dock_master->property_switcher_style() = Gdl::SWITCHER_STYLE_ICON;
70
71 memset(&dockPlaceholders_, 0, sizeof(dockPlaceholders_));
72 }
73
74
75
77 {
80
81#if false
83 for(int i = 0; i < 4; i++)
85 g_object_unref(dockPlaceholders_[i]);
86
88#endif
89 }
90
91
92
93 void
95 {
97
98 REQUIRE(dockPlaceholders_[0] == NULL && dockPlaceholders_[1] == NULL &&
100 dockPlaceholders_[0] = GDL_DOCK_PLACEHOLDER(gdl_dock_placeholder_new(
101 "ph1", GDL_DOCK_OBJECT(dock_.gobj()), GDL_DOCK_TOP, FALSE));
102 dockPlaceholders_[1] = GDL_DOCK_PLACEHOLDER(gdl_dock_placeholder_new(
103 "ph2", GDL_DOCK_OBJECT(dock_.gobj()), GDL_DOCK_BOTTOM, FALSE));
104 dockPlaceholders_[2] = GDL_DOCK_PLACEHOLDER(gdl_dock_placeholder_new(
105 "ph3", GDL_DOCK_OBJECT(dock_.gobj()), GDL_DOCK_LEFT, FALSE));
106 dockPlaceholders_[3] = GDL_DOCK_PLACEHOLDER(gdl_dock_placeholder_new(
107 "ph4", GDL_DOCK_OBJECT(dock_.gobj()), GDL_DOCK_RIGHT, FALSE));
108 ENSURE(dockPlaceholders_[0] and dockPlaceholders_[1] and
110
111 createPanels();
112 }
113
114
115 Gdl::Dock&
117 {
118 return dock_;
119 }
120
121
122 Gdl::DockBar&
124 {
125 return dockBar_;
126 }
127
128
134
135
136 bool
137 DockArea::hasPanel (const int description_index)
138 {
139 return util::has_any (panels_, [&](panel::Panel* panel)
140 {
141 return getPanelType(panel) == description_index;
142 });
143 }
144
146 DockArea::showPanel (const int description_index)
147 {
148 // Try and find the panel and present it if possible
149 list< panel::Panel* >::iterator i;
150 for(i = panels_.begin(); i != panels_.end(); i++)
151 {
152 panel::Panel* const panel = *i;
153 if (getPanelType(panel) == description_index)
154 {
155 if (!panel->is_shown()) panel->show();
156
157 Gdl::DockItem &dock_item = panel->getDockItem();
158 // ENSURE(dock_item);
159 dock_item.present(dock_);
160 ENSURE (panel);
161 return *panel;
162 }
163 }
164
165 // Create the new panel
166 panel::Panel *new_panel = createPanel_by_index (description_index);
167
168 // Dock the item
169 dock_.add_item(new_panel->getDockItem(), Gdl::DOCK_FLOATING);
170
171 ENSURE (new_panel);
172 return *new_panel;
173 }
174
175
176 void
177 DockArea::switchPanel (panel::Panel& old_panel, const int description_index)
178 {
179 REQUIRE (description_index >= 0);
180 REQUIRE (description_index < getPanelDescriptionCount());
181
182 // Get the dock item
183 Gdl::DockItem &dock_item = old_panel.getDockItem();
184
185 // Release the old panel
186 removePanel (&old_panel);
187
188 // Create the new panel
189 createPanel_by_index (description_index, dock_item);
190 }
191
192
193 void
194 DockArea::splitPanel (panel::Panel& panel, Gtk::Orientation split_direction)
195 {
196
197 // Create the new panel
198 const int index = getPanelType(&panel);
199 panel::Panel *new_panel = createPanel_by_index(index);
200
201 // Dock the panel
202 Gdl::DockPlacement placement = Gdl::DOCK_NONE;
203 switch(split_direction)
204 {
205 case ORIENTATION_HORIZONTAL:
206 placement = Gdl::DOCK_RIGHT;
207 break;
208
209 case ORIENTATION_VERTICAL:
210 placement = Gdl::DOCK_BOTTOM;
211 break;
212
213 default:
214 ERROR(stage, "Unknown split_direction: %d", split_direction);
215 return;
216 break;
217 }
218
219 panel.getDockItem().dock(
220 new_panel->getDockItem(),placement);
221 }
222
223
224 int
229
230
231 const gchar*
233 {
234 REQUIRE (index >= 0);
235 REQUIRE (index < getPanelDescriptionCount());
236 return panelDescriptionList[index].getStockID();
237 }
238
239
240 const char*
242 {
243 REQUIRE (index >= 0);
244 REQUIRE (index < getPanelDescriptionCount());
245 return panelDescriptionList[index].getTitle();
246 }
247
248
249 void
251 {
253 panel::Panel* assetsPanel = createPanel_by_name("AssetsPanel");
254 panel::Panel* viewerPanel = createPanel_by_name("InfoBoxPanel");
255 panel::Panel* timelinePanel = createPanel_by_name("TimelinePanel");
256
257 dock_.add_item(assetsPanel->getDockItem(),Gdl::DOCK_LEFT);
258 dock_.add_item(timelinePanel->getDockItem(),Gdl::DOCK_BOTTOM);
259 dock_.add_item(viewerPanel->getDockItem(),Gdl::DOCK_RIGHT);
260 }
261
262
263 int
265 {
266 REQUIRE(class_name);
267
268 const int count = getPanelDescriptionCount();
269 for(int i = 0; i < count; i++)
270 {
271 if (strstr(panelDescriptionList[i].getClassName(), class_name))
272 return i;
273 }
274
275 ERROR (stage, "Unable to find a description with class name %s", class_name);
276 return -1;
277 }
278
279
282 {
283 REQUIRE (index >= 0);
284 REQUIRE (index < getPanelDescriptionCount());
285
286 // Make a unique name for the panel
287 char name[5];
288 snprintf(name, sizeof(name), "%X", panelID++);
289
290 // Create a dock item
291 return createPanel_by_index(index,
292 *new Gdl::DockItem(name,"",Gdl::DOCK_ITEM_BEH_NORMAL));
293 }
294
295
297 DockArea::createPanel_by_index (const int index, Gdl::DockItem &dock_item)
298 {
299 // Create the panel object
300 panel::Panel *panel = panelDescriptionList[index].create(*this, dock_item);
301 ENSURE(panel);
302 panel->show_all();
303
304 // Connect event handlers
305 panel->signal_hidePanel().connect(sigc::bind(
306 sigc::mem_fun(*this, &DockArea::on_panel_shown), panel));
307
308 // Add the panel to the list
309 panels_.push_back(panel);
310
311 return panel;
312 }
313
314
317 {
318 REQUIRE(class_name);
319 const int index = findPanelDescription(class_name);
320 return createPanel_by_index(index);
321 }
322
323
324 int
326 {
327 REQUIRE(panel);
328
329 const type_info &info = typeid(*panel);
330 const int count = getPanelDescriptionCount();
331 for(int i = 0; i < count; i++)
332 {
333 if(info == panelDescriptionList[i].getClassInfo())
334 return i;
335 }
336
337 ERROR(stage, "Unable to find a description with with this class type");
338 return -1;
339 }
340
341
342 void
344 {
345 REQUIRE(panel);
346
347 list< panel::Panel* >::iterator i;
348 for(i = panels_.begin(); i != panels_.end(); i++)
349 {
350 if(*i == panel)
351 {
352 delete panel;
353 panels_.erase(i);
354 break;
355 }
356 }
357 }
358
359
360 void
362 {
364
365 list< panel::Panel* >::iterator i;
366 for(i = panels_.begin(); i != panels_.end(); i++)
367 delete *i;
368 panels_.clear();
369 }
370
371
372 void
374 {
375 REQUIRE(panel);
376 if (panel->is_shown() or panel->is_iconified()) return;
377
378 removePanel(panel);
379 }
380
381
382
383}}// 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(DockArea &panelManager, Gdl::DockItem &dockItem) const
Creates an instance of this panel.
std::list< panel::Panel * > panels_
list of all panels created
Definition dock-area.hpp:75
void createPanels()
Creates the standard panel layout.
Glib::RefPtr< Gdl::DockLayout > dockLayout_
The pointer to GDL dock layout object.
Definition dock-area.hpp:67
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
Definition dock-area.hpp:52
WorkspaceWindow & getWorkspaceWindow()
Returns a reference to the owner workspace window.
GdlDockPlaceholder * dockPlaceholders_[4]
Pointers to the 4 root place holders.
Definition dock-area.hpp:72
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.
Definition dock-area.hpp:80
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.
Definition dock-area.cpp:94
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.
Definition dock-area.hpp:57
static const PanelDescription panelDescriptionList[]
The list of panel descriptions.
void splitPanel(panel::Panel &panel, Gtk::Orientation split_direction)
Splits a panel into two panels of the same type.
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.
Definition dock-area.hpp:62
void clearPanels()
Removes all panels from the panel list and deletes them.
DockArea(WorkspaceWindow &)
Definition dock-area.cpp:58
static const gchar * getPanelStockID(const int index)
Gets a panel description's stock id.
The main Lumiera workspace window.
Management of dockable panels within each top-level WorkspaceWindow.
const char * CStr
Definition error.hpp:42
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.
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.