From 615141502950531440c9f96d7f00ba2d4eb2cdc4 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sat, 4 Apr 2009 16:57:06 +0100 Subject: [PATCH] Implemented initial PanelManager implementation --- src/gui/Makefile.am | 2 + src/gui/panels/panel.hpp | 2 +- src/gui/panels/resources-panel.cpp | 8 +- src/gui/panels/resources-panel.hpp | 6 + src/gui/panels/timeline-panel.cpp | 8 +- src/gui/panels/timeline-panel.hpp | 6 + src/gui/panels/viewer-panel.cpp | 8 +- src/gui/panels/viewer-panel.hpp | 6 + src/gui/workspace/actions.cpp | 18 +-- src/gui/workspace/panel-manager.cpp | 163 ++++++++++++++++++++++++ src/gui/workspace/panel-manager.hpp | 165 +++++++++++++++++++++++++ src/gui/workspace/workspace-window.cpp | 63 ++-------- src/gui/workspace/workspace-window.hpp | 13 +- 13 files changed, 389 insertions(+), 79 deletions(-) create mode 100644 src/gui/workspace/panel-manager.cpp create mode 100644 src/gui/workspace/panel-manager.hpp diff --git a/src/gui/Makefile.am b/src/gui/Makefile.am index 3414c9f60..14cd4c8fe 100644 --- a/src/gui/Makefile.am +++ b/src/gui/Makefile.am @@ -61,6 +61,8 @@ gtk_gui_la_SOURCES = \ $(lumigui_srcdir)/window-manager.hpp \ $(lumigui_srcdir)/workspace/actions.cpp \ $(lumigui_srcdir)/workspace/actions.hpp \ + $(lumigui_srcdir)/workspace/panel-manager.cpp \ + $(lumigui_srcdir)/workspace/panel-manager.hpp \ $(lumigui_srcdir)/workspace/workspace-window.cpp \ $(lumigui_srcdir)/workspace/workspace-window.hpp \ $(lumigui_srcdir)/dialogs/dialog.hpp \ diff --git a/src/gui/panels/panel.hpp b/src/gui/panels/panel.hpp index 4cf306871..d6e72706f 100644 --- a/src/gui/panels/panel.hpp +++ b/src/gui/panels/panel.hpp @@ -69,12 +69,12 @@ protected: const gchar *name, const gchar *long_name, const gchar *stock_id, GdlDockItemBehavior behavior = GDL_DOCK_ITEM_BEH_NORMAL); +public: /** * Destructor **/ ~Panel(); -public: /** * Returns a pointer to the underlying GdlDockItem structure */ diff --git a/src/gui/panels/resources-panel.cpp b/src/gui/panels/resources-panel.cpp index 83f4e916a..041ba12e6 100644 --- a/src/gui/panels/resources-panel.cpp +++ b/src/gui/panels/resources-panel.cpp @@ -27,7 +27,7 @@ namespace gui { namespace panels { ResourcesPanel::ResourcesPanel(workspace::WorkspaceWindow &workspace_window) : - Panel(workspace_window, "resources", _("Resources"), "panel_resources") + Panel(workspace_window, "resources", get_title(), "panel_resources") { notebook.append_page(media, _("Media")); @@ -38,5 +38,11 @@ ResourcesPanel::ResourcesPanel(workspace::WorkspaceWindow &workspace_window) : pack_start(notebook); } +const char* +ResourcesPanel::get_title() +{ + return _("Resources"); +} + } // namespace panels } // namespace gui diff --git a/src/gui/panels/resources-panel.hpp b/src/gui/panels/resources-panel.hpp index 2f038fdf1..8c969e186 100644 --- a/src/gui/panels/resources-panel.hpp +++ b/src/gui/panels/resources-panel.hpp @@ -40,6 +40,12 @@ public: * @param workspace_window The window that owns this panel. **/ ResourcesPanel(workspace::WorkspaceWindow &workspace_window); + + /** + * Get the title of the panel. + * @return Returns a pointer to the string title of the panel. + **/ + static const char* get_title(); protected: Gtk::Notebook notebook; diff --git a/src/gui/panels/timeline-panel.cpp b/src/gui/panels/timeline-panel.cpp index db1c1759f..b42ab0194 100644 --- a/src/gui/panels/timeline-panel.cpp +++ b/src/gui/panels/timeline-panel.cpp @@ -48,7 +48,7 @@ const int TimelinePanel::ZoomToolSteps = 2; // 2 seems comfortable TimelinePanel::TimelinePanel(workspace::WorkspaceWindow &workspace_window) : - Panel(workspace_window, "timeline", _("Timeline"), "panel_timeline"), + Panel(workspace_window, "timeline", get_title(), "panel_timeline"), timeIndicator(), timeIndicatorButton(), previousButton(Stock::MEDIA_PREVIOUS), @@ -130,6 +130,12 @@ TimelinePanel::~TimelinePanel() } +const char* +TimelinePanel::get_title() +{ + return _("Timeline"); +} + void TimelinePanel::on_play_pause() { diff --git a/src/gui/panels/timeline-panel.hpp b/src/gui/panels/timeline-panel.hpp index 522206bbd..c181a0202 100644 --- a/src/gui/panels/timeline-panel.hpp +++ b/src/gui/panels/timeline-panel.hpp @@ -56,6 +56,12 @@ public: * Destructor **/ ~TimelinePanel(); + + /** + * Get the title of the panel. + * @return Returns a pointer to the string title of the panel. + **/ + static const char* get_title(); private: //----- Event Handlers -----// diff --git a/src/gui/panels/viewer-panel.cpp b/src/gui/panels/viewer-panel.cpp index f14ff2023..e876ae325 100644 --- a/src/gui/panels/viewer-panel.cpp +++ b/src/gui/panels/viewer-panel.cpp @@ -37,7 +37,7 @@ namespace gui { namespace panels { ViewerPanel::ViewerPanel(workspace::WorkspaceWindow &workspace_window) : - Panel(workspace_window, "viewer", _("Viewer"), "panel_viewer") + Panel(workspace_window, "viewer", get_title(), "panel_viewer") { //----- Pack in the Widgets -----// pack_start(display, PACK_EXPAND_WIDGET); @@ -49,6 +49,12 @@ ViewerPanel::ViewerPanel(workspace::WorkspaceWindow &workspace_window) : playback.use_display (DisplayService::setUp (outputDestination)); } +const char* +ViewerPanel::get_title() +{ + return _("Viewer"); +} + void ViewerPanel::on_frame(void *buffer) { diff --git a/src/gui/panels/viewer-panel.hpp b/src/gui/panels/viewer-panel.hpp index b56fb3701..1e7e6aea6 100644 --- a/src/gui/panels/viewer-panel.hpp +++ b/src/gui/panels/viewer-panel.hpp @@ -46,6 +46,12 @@ public: **/ ViewerPanel(workspace::WorkspaceWindow &owner_window); + /** + * Get the title of the panel. + * @return Returns a pointer to the string title of the panel. + **/ + static const char* get_title(); + protected: void on_frame(void *buffer); diff --git a/src/gui/workspace/actions.cpp b/src/gui/workspace/actions.cpp index b2cf555db..8ee8fc9b6 100644 --- a/src/gui/workspace/actions.cpp +++ b/src/gui/workspace/actions.cpp @@ -115,7 +115,7 @@ Actions::Actions(WorkspaceWindow &workspace_window) : void Actions::update_action_state() { - REQUIRE(workspaceWindow.resourcesPanel != NULL); + /*REQUIRE(workspaceWindow.resourcesPanel != NULL); REQUIRE(workspaceWindow.timelinePanel != NULL); REQUIRE(workspaceWindow.viewerPanel != NULL); @@ -126,7 +126,7 @@ Actions::update_action_state() workspaceWindow.timelinePanel->is_shown()); viewerPanelAction->set_active( workspaceWindow.viewerPanel->is_shown()); - is_updating_action_state = false; + is_updating_action_state = false;*/ } /* ===== File Menu Event Handlers ===== */ @@ -172,23 +172,23 @@ Actions::on_menu_edit_preferences() void Actions::on_menu_view_resources() { - if(!is_updating_action_state) - workspaceWindow.resourcesPanel->show( - assetsPanelAction->get_active()); + //if(!is_updating_action_state) + // workspaceWindow.resourcesPanel->show( + // assetsPanelAction->get_active()); } void Actions::on_menu_view_timeline() { - if(!is_updating_action_state) - workspaceWindow.timelinePanel->show(timelinePanelAction->get_active()); + //if(!is_updating_action_state) + // workspaceWindow.timelinePanel->show(timelinePanelAction->get_active()); } void Actions::on_menu_view_viewer() { - if(!is_updating_action_state) - workspaceWindow.viewerPanel->show(viewerPanelAction->get_active()); + //if(!is_updating_action_state) + // workspaceWindow.viewerPanel->show(viewerPanelAction->get_active()); } /* ===== Sequence Menu Event Handlers ===== */ diff --git a/src/gui/workspace/panel-manager.cpp b/src/gui/workspace/panel-manager.cpp new file mode 100644 index 000000000..62079d1e2 --- /dev/null +++ b/src/gui/workspace/panel-manager.cpp @@ -0,0 +1,163 @@ +/* + panel-manager.cpp - Definition of the panel manager object + + Copyright (C) Lumiera.org + 2008, Joel Holdsworth + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +* *****************************************************/ + +#include "panel-manager.hpp" + +#include "../panels/resources-panel.hpp" +#include "../panels/viewer-panel.hpp" +#include "../panels/timeline-panel.hpp" + +#include "include/logging.h" + +using namespace boost; +using namespace std; + +namespace gui { +namespace workspace { + +const PanelManager::PanelDescription + PanelManager::panelDescriptionList[] = { + PanelManager::Panel(), + PanelManager::Panel(), + PanelManager::Panel() + }; + +PanelManager::PanelManager(WorkspaceWindow &workspace_window) : + workspaceWindow(workspace_window), + dock(NULL), + dockBar(NULL), + dockLayout(NULL) +{ + memset(&dockPlaceholders, 0, sizeof(dockPlaceholders)); +} + +PanelManager::~PanelManager() +{ + if(dock) + g_object_unref(dock); + + if(dockBar) + g_object_unref(dockBar); + + if(dockLayout) + g_object_unref(dockLayout); + + for(int i = 0; i < 4; i++) + if(dockPlaceholders[i]) + g_object_unref(dockPlaceholders[i]); +} + +void +PanelManager::setup_dock() +{ + REQUIRE(dock == NULL); + dock = GDL_DOCK(gdl_dock_new()); + ENSURE(dock); + + REQUIRE(dockBar == NULL); + dockBar = GDL_DOCK_BAR(gdl_dock_bar_new(dock)); + ENSURE(dockBar); + + REQUIRE(dockLayout == NULL); + dockLayout = GDL_DOCK_LAYOUT(gdl_dock_layout_new(dock)); + ENSURE(dockLayout); + + REQUIRE(dockPlaceholders[0] == NULL && dockPlaceholders[1] == NULL && + dockPlaceholders[2] == NULL && dockPlaceholders[3] == NULL); + dockPlaceholders[0] = GDL_DOCK_PLACEHOLDER(gdl_dock_placeholder_new( + "ph1", GDL_DOCK_OBJECT(dock), GDL_DOCK_TOP, FALSE)); + dockPlaceholders[1] = GDL_DOCK_PLACEHOLDER(gdl_dock_placeholder_new( + "ph2", GDL_DOCK_OBJECT(dock), GDL_DOCK_BOTTOM, FALSE)); + dockPlaceholders[2] = GDL_DOCK_PLACEHOLDER(gdl_dock_placeholder_new( + "ph3", GDL_DOCK_OBJECT(dock), GDL_DOCK_LEFT, FALSE)); + dockPlaceholders[3] = GDL_DOCK_PLACEHOLDER(gdl_dock_placeholder_new( + "ph4", GDL_DOCK_OBJECT(dock), GDL_DOCK_RIGHT, FALSE)); + ENSURE(dockPlaceholders[0] && dockPlaceholders[1] && + dockPlaceholders[2] && dockPlaceholders[3]); + + create_panels(); +} + +GdlDock* +PanelManager::get_dock() const +{ + ENSURE(dock); + return dock; +} + +GdlDockBar* +PanelManager::get_dock_bar() const +{ + ENSURE(dockBar); + return dockBar; +} + +void +PanelManager::create_panels() +{ + shared_ptr resourcesPanel( + (panels::Panel*)new ResourcesPanel(workspaceWindow)); + shared_ptr viewerPanel( + (panels::Panel*)new ViewerPanel(workspaceWindow)); + shared_ptr timelinePanel( + (panels::Panel*)new TimelinePanel(workspaceWindow)); + + gdl_dock_add_item(dock, + resourcesPanel->get_dock_item(), GDL_DOCK_LEFT); + gdl_dock_add_item(dock, + timelinePanel->get_dock_item(), GDL_DOCK_BOTTOM); + gdl_dock_add_item(dock, + viewerPanel->get_dock_item(), GDL_DOCK_RIGHT); + + panels.push_back(timelinePanel); + panels.push_back(viewerPanel); + panels.push_back(resourcesPanel); + + const int panelDescriptionCount = + sizeof(panelDescriptionList) / + sizeof(PanelDescription); + for(int i = 0; i < panelDescriptionCount; i++) + { + g_message("%s", panelDescriptionList[i].get_title()); + } +} + +shared_ptr +PanelManager::create_panel_by_name(const char* class_name) +{ + const int panelDescriptionCount = + sizeof(panelDescriptionList) / + sizeof(PanelDescription); + + for(int i = 0; i < panelDescriptionCount; i++) + { + if(strstr(panelDescriptionList[i].get_class_name(), class_name)) + return shared_ptr(panelDescriptionList[i].create( + workspaceWindow)); + } + + ERROR(gui, "Unable to create a panel with class name %s", class_name); + return shared_ptr(); +} + +} // namespace workspace +} // namespace gui diff --git a/src/gui/workspace/panel-manager.hpp b/src/gui/workspace/panel-manager.hpp new file mode 100644 index 000000000..289107905 --- /dev/null +++ b/src/gui/workspace/panel-manager.hpp @@ -0,0 +1,165 @@ +/* + panel-manager.hpp - Definition of the panel manager object + + Copyright (C) Lumiera.org + 2008, Joel Holdsworth + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ +/** @file panel-manager.hpp + ** This file contains the definition of the panel manager object. + ** + ** @see actions.hpp + */ + +#ifndef PANEL_MANAGER_HPP +#define PANEL_MANAGER_HPP + +#include + +#include "../panels/panel.hpp" + +using namespace gui::panels; + +namespace gui { +namespace workspace { + +/** + * A class to managers DockItem objects for WorkspaceWindow. + **/ +class PanelManager +{ +public: + + /** + * Constructor + * @param workspace_window A reference to the owner WorkspaceWindow + * object. + **/ + PanelManager(WorkspaceWindow &workspace_window); + + /** + * Destructor. + **/ + ~PanelManager(); + + /** + * Initializes this dock manager and creates the dock and all it's + * widgets. + * @remarks This function must be called only once as the first call + * after construction. + **/ + void setup_dock(); + + /** + * Gets a pointer to the dock object. + * @remarks Note that this must not be called before setup_dock. + **/ + GdlDock* get_dock() const; + + GdlDockBar* get_dock_bar() const; + +private: + + void create_panels(); + + boost::shared_ptr create_panel_by_name( + const char* class_name); + +private: + + WorkspaceWindow &workspaceWindow; + + GdlDock *dock; + GdlDockBar *dockBar; + GdlDockLayout *dockLayout; + + GdlDockPlaceholder *dockPlaceholders[4]; + + std::list< boost::shared_ptr > panels; + + +private: + + /** + * A class to describe and instantiate Panel types. + **/ + class PanelDescription + { + protected: + PanelDescription(const char* class_name, const char *title, + boost::shared_ptr (*const create_panel_proc)( + WorkspaceWindow&)) : + className(class_name), + titleName(title), + createPanelProc(create_panel_proc) + { + REQUIRE(className); + REQUIRE(titleName); + } + + public: + const char* get_class_name() const + { + ENSURE(className); + return className; + } + + const char* get_title() const + { + ENSURE(titleName); + return titleName; + } + + boost::shared_ptr create( + WorkspaceWindow& owner_window) const + { + REQUIRE(createPanelProc); + return createPanelProc(owner_window); + } + + private: + const char* className; + const char* titleName; + boost::shared_ptr (*const createPanelProc)( + WorkspaceWindow&); + }; + + template class Panel : public PanelDescription + { + public: + Panel() : + PanelDescription(typeid(P).name(), P::get_title(), + Panel::create_panel) + {} + + private: + static boost::shared_ptr create_panel( + WorkspaceWindow &workspace_window) + { + return boost::shared_ptr( + new P(workspace_window)); + } + }; + + static const PanelDescription panelDescriptionList[]; + +}; + +} // namespace workspace +} // namespace gui + +#endif // PANEL_MANAGER_HPP diff --git a/src/gui/workspace/workspace-window.cpp b/src/gui/workspace/workspace-window.cpp index 1d872c5c9..1188cb469 100644 --- a/src/gui/workspace/workspace-window.cpp +++ b/src/gui/workspace/workspace-window.cpp @@ -47,27 +47,14 @@ WorkspaceWindow::WorkspaceWindow(Project &source_project, gui::controller::Controller &source_controller) : project(source_project), controller(source_controller), + panelManager(*this), actions(*this) { - layout = NULL; - resourcesPanel = NULL; - viewerPanel = NULL; - timelinePanel = NULL; - create_ui(); } WorkspaceWindow::~WorkspaceWindow() { - REQUIRE(layout != NULL); - g_object_unref(layout); - - REQUIRE(resourcesPanel != NULL); - resourcesPanel->unreference(); - REQUIRE(viewerPanel != NULL); - viewerPanel->unreference(); - REQUIRE(timelinePanel != NULL); - timelinePanel->unreference(); } Project& @@ -162,50 +149,16 @@ WorkspaceWindow::create_ui() toolbar->set_toolbar_style(TOOLBAR_ICONS); baseContainer.pack_start(*toolbar, Gtk::PACK_SHRINK); - //----- Create the Panels -----// - resourcesPanel = new ResourcesPanel(*this); - ENSURE(resourcesPanel != NULL); - viewerPanel = new ViewerPanel(*this); - ENSURE(viewerPanel != NULL); - timelinePanel = new TimelinePanel(*this); - ENSURE(timelinePanel != NULL); - - //----- Create the Dock -----// - dock = Glib::wrap(gdl_dock_new()); + //----- Create the Docks -----// + panelManager.setup_dock(); - layout = gdl_dock_layout_new((GdlDock*)dock->gobj()); + GdlDock const *dock = panelManager.get_dock(); - dockbar = Glib::wrap(gdl_dock_bar_new ((GdlDock*)dock->gobj())); - - dockContainer.pack_start(*dockbar, PACK_SHRINK); - dockContainer.pack_end(*dock, PACK_EXPAND_WIDGET); + gtk_box_pack_start(GTK_BOX(dockContainer.gobj()), + GTK_WIDGET(panelManager.get_dock_bar()), FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(dockContainer.gobj()), + GTK_WIDGET(dock), TRUE, TRUE, 0); baseContainer.pack_start(dockContainer, PACK_EXPAND_WIDGET); - - gdl_dock_add_item ((GdlDock*)dock->gobj(), - resourcesPanel->get_dock_item(), GDL_DOCK_LEFT); - gdl_dock_add_item ((GdlDock*)dock->gobj(), - viewerPanel->get_dock_item(), GDL_DOCK_RIGHT); - gdl_dock_add_item ((GdlDock*)dock->gobj(), - timelinePanel->get_dock_item(), GDL_DOCK_BOTTOM); - - // Manually dock and move around some of the items - gdl_dock_item_dock_to (timelinePanel->get_dock_item(), - resourcesPanel->get_dock_item(), GDL_DOCK_BOTTOM, -1); - gdl_dock_item_dock_to (viewerPanel->get_dock_item(), - resourcesPanel->get_dock_item(), GDL_DOCK_RIGHT, -1); - - gchar ph1[] = "ph1"; - gdl_dock_placeholder_new (ph1, (GdlDockObject*)dock->gobj(), - GDL_DOCK_TOP, FALSE); - gchar ph2[] = "ph2"; - gdl_dock_placeholder_new (ph2, (GdlDockObject*)dock->gobj(), - GDL_DOCK_BOTTOM, FALSE); - gchar ph3[] = "ph3"; - gdl_dock_placeholder_new (ph3, (GdlDockObject*)dock->gobj(), - GDL_DOCK_LEFT, FALSE); - gchar ph4[] = "ph4"; - gdl_dock_placeholder_new (ph4, (GdlDockObject*)dock->gobj(), - GDL_DOCK_RIGHT, FALSE); //----- Create the status bar -----// statusBar.set_has_resize_grip(); diff --git a/src/gui/workspace/workspace-window.hpp b/src/gui/workspace/workspace-window.hpp index 48c3c6916..e46acf6c1 100644 --- a/src/gui/workspace/workspace-window.hpp +++ b/src/gui/workspace/workspace-window.hpp @@ -30,9 +30,9 @@ #define WORKSPACE_WINDOW_HPP #include -#include #include "actions.hpp" +#include "panel-manager.hpp" #include "../panels/resources-panel.hpp" #include "../panels/viewer-panel.hpp" @@ -84,19 +84,10 @@ private: Gtk::VBox baseContainer; Gtk::HBox dockContainer; - //----- Dock Frame -----// - Gtk::Widget *dock; - Gtk::Widget *dockbar; - GdlDockLayout *layout; + PanelManager panelManager; //----- Status Bar -----// Gtk::Statusbar statusBar; - - /* ===== Panels ===== */ -private: - ResourcesPanel *resourcesPanel; - ViewerPanel *viewerPanel; - TimelinePanel *timelinePanel; /* ===== Helpers ===== */ private: