2009-04-04 17:57:06 +02:00
|
|
|
/*
|
|
|
|
|
panel-manager.hpp - Definition of the panel manager object
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2009-04-04 17:57:06 +02:00
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2008, Joel Holdsworth <joel@airwebreathe.org.uk>
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2009-04-04 17:57:06 +02:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
2010-12-17 23:28:49 +01:00
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
2009-04-04 17:57:06 +02:00
|
|
|
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.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2009-04-04 17:57:06 +02:00
|
|
|
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.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2009-04-04 17:57:06 +02:00
|
|
|
*/
|
|
|
|
|
/** @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
|
|
|
|
|
|
2014-08-17 07:02:48 +02:00
|
|
|
#include "gui/panels/panel.hpp"
|
|
|
|
|
|
2011-10-16 08:43:03 +02:00
|
|
|
#include <gdlmm.h>
|
2009-04-15 13:24:34 +02:00
|
|
|
#include <typeinfo>
|
2009-04-04 17:57:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
using namespace gui::panels;
|
|
|
|
|
|
|
|
|
|
namespace gui {
|
|
|
|
|
namespace workspace {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A class to managers DockItem objects for WorkspaceWindow.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-04 17:57:06 +02:00
|
|
|
class PanelManager
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor
|
|
|
|
|
* @param workspace_window A reference to the owner WorkspaceWindow
|
|
|
|
|
* object.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-04 17:57:06 +02:00
|
|
|
PanelManager(WorkspaceWindow &workspace_window);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Destructor.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-04 17:57:06 +02:00
|
|
|
~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.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-04 17:57:06 +02:00
|
|
|
void setup_dock();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets a pointer to the dock object.
|
|
|
|
|
* @remarks Note that this must not be called before setup_dock.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2011-10-16 16:43:59 +02:00
|
|
|
Gdl::Dock& get_dock();
|
2009-04-04 17:57:06 +02:00
|
|
|
|
2009-04-04 18:22:46 +02:00
|
|
|
/**
|
|
|
|
|
* Gets a pointer to the dock bar.
|
|
|
|
|
* @remarks Note that this must not be called before setup_dock.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2011-10-16 16:43:59 +02:00
|
|
|
Gdl::DockBar& get_dock_bar();
|
2009-04-04 19:53:09 +02:00
|
|
|
|
2009-04-13 17:11:50 +02:00
|
|
|
/**
|
|
|
|
|
* Returns a reference to the owner workspace window.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-13 17:11:50 +02:00
|
|
|
WorkspaceWindow& get_workspace_window();
|
|
|
|
|
|
2009-04-15 19:14:16 +02:00
|
|
|
/**
|
|
|
|
|
* Shows a panel given a description index.
|
|
|
|
|
* @param description_index The index of the panel type to show.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-15 19:14:16 +02:00
|
|
|
void show_panel(const int description_index);
|
|
|
|
|
|
2009-04-15 12:13:27 +02:00
|
|
|
/**
|
|
|
|
|
* Switches a panel from one type to another, without touching the
|
|
|
|
|
* underlying GdlDockItem.
|
|
|
|
|
* @param old_panel The panel which will be transofrmed to a new type.
|
2009-04-15 19:05:45 +02:00
|
|
|
* @param description_index The index of the panel description that
|
|
|
|
|
* will be instantiated.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-05 00:01:50 +02:00
|
|
|
void switch_panel(panels::Panel &old_panel,
|
2009-04-15 19:05:45 +02:00
|
|
|
const int description_index);
|
2009-04-15 13:24:34 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Splits a panel into two panels of the same type.
|
|
|
|
|
* @param panel The panel to split.
|
|
|
|
|
* @param split_direction The direction to split the panel in.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-15 13:24:34 +02:00
|
|
|
void split_panel(panels::Panel &panel,
|
|
|
|
|
Gtk::Orientation split_direction);
|
2009-04-05 00:01:50 +02:00
|
|
|
|
2009-04-04 19:53:09 +02:00
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the number of panel descriptions.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-04 19:53:09 +02:00
|
|
|
static int get_panel_description_count();
|
|
|
|
|
|
|
|
|
|
/**
|
2009-04-15 19:14:16 +02:00
|
|
|
* Gets a panel description's stock id.
|
2009-04-04 19:53:09 +02:00
|
|
|
* @param index The index of the panel to retrieve.
|
|
|
|
|
* @return Returns the stock id of a panel at this index.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-15 19:05:45 +02:00
|
|
|
static const gchar* get_panel_stock_id(const int index);
|
2009-04-15 19:14:16 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets a panel description's title.
|
|
|
|
|
* @param index The index of the panel to retrieve.
|
|
|
|
|
* @return Returns the title of a panel at this index.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-15 19:14:16 +02:00
|
|
|
static const char* get_panel_title(int index);
|
2009-04-04 17:57:06 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
2009-04-04 18:22:46 +02:00
|
|
|
/**
|
|
|
|
|
* Creates the standard panel layout.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-04 17:57:06 +02:00
|
|
|
void create_panels();
|
2009-04-15 13:24:34 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Find the index of a panel description given the class name.
|
|
|
|
|
* @param class_name The name of the object class to search for.
|
|
|
|
|
* @return Returns the index of the panel description found, or -1
|
|
|
|
|
* if no description was found for this type.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-15 13:24:34 +02:00
|
|
|
int find_panel_description(const char* class_name) const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a panel by description index.
|
|
|
|
|
* @param index The index of the description to instantiate.
|
|
|
|
|
* @return Returns a pointer to the new instantiated panel object.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-16 11:02:53 +02:00
|
|
|
panels::Panel* create_panel_by_index(const int index);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a panel by description index with a given GdlDockItem
|
|
|
|
|
* @param index The index of the description to instantiate.
|
|
|
|
|
* @param dock_item The GdlDockItem to attach this panel to
|
|
|
|
|
* @return Returns a pointer to the new instantiated panel object.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-16 11:02:53 +02:00
|
|
|
panels::Panel* create_panel_by_index(
|
2011-10-16 16:43:59 +02:00
|
|
|
const int index, Gdl::DockItem &dock_item);
|
2009-04-04 17:57:06 +02:00
|
|
|
|
2009-04-04 18:22:46 +02:00
|
|
|
/**
|
|
|
|
|
* Creates a panel by class name.
|
|
|
|
|
* @param class_name The name of the object class to create.
|
2009-04-15 13:24:34 +02:00
|
|
|
* @return Returns a pointer to the new instantiated panel object.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-16 11:02:53 +02:00
|
|
|
panels::Panel* create_panel_by_name(const char* class_name);
|
2009-04-04 17:57:06 +02:00
|
|
|
|
2009-04-15 13:24:34 +02:00
|
|
|
/**
|
|
|
|
|
* Gets the type of a given panel.
|
|
|
|
|
* @param panel The Panel to get the type of
|
|
|
|
|
* @return Returns the index of the panel description found, or -1
|
|
|
|
|
* if no description was found for this type.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-16 11:02:53 +02:00
|
|
|
int get_panel_type(panels::Panel* const panel) const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes a panel from the panel list and deletes it.
|
|
|
|
|
* @param panel The panel to remove and delete.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-16 11:02:53 +02:00
|
|
|
void remove_panel(panels::Panel* const panel);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes all panels from the panel list and deletes them.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-16 11:02:53 +02:00
|
|
|
void clear_panels();
|
2009-04-15 21:12:06 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An event handler for when the panel is shown or hidden.
|
2009-04-16 11:02:53 +02:00
|
|
|
* @param panel A pointer to the panel that was hidden.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-16 11:02:53 +02:00
|
|
|
void on_panel_shown(panels::Panel *panel);
|
2009-04-15 13:24:34 +02:00
|
|
|
|
2009-04-04 17:57:06 +02:00
|
|
|
private:
|
|
|
|
|
|
2009-04-04 18:22:46 +02:00
|
|
|
/**
|
|
|
|
|
* A reference to the owner workspace window object.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-04 17:57:06 +02:00
|
|
|
WorkspaceWindow &workspaceWindow;
|
|
|
|
|
|
2009-04-04 18:22:46 +02:00
|
|
|
/**
|
|
|
|
|
* The pointer to GDL dock widget.
|
|
|
|
|
* @remarks This value is NULL until setup_dock has been called.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2011-10-16 08:43:03 +02:00
|
|
|
Gdl::Dock dock;
|
|
|
|
|
|
2009-04-04 18:22:46 +02:00
|
|
|
/**
|
|
|
|
|
* The pointer to GDL dock bar widget.
|
|
|
|
|
* @remarks This value is NULL until setup_dock has been called.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2011-10-16 08:43:03 +02:00
|
|
|
Gdl::DockBar dockBar;
|
2009-04-04 18:22:46 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The pointer to GDL dock layout object.
|
|
|
|
|
* @remarks This value is NULL until setup_dock has been called.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2011-10-16 08:43:03 +02:00
|
|
|
Glib::RefPtr<Gdl::DockLayout> dockLayout;
|
2009-04-04 17:57:06 +02:00
|
|
|
|
2009-04-04 18:22:46 +02:00
|
|
|
/**
|
|
|
|
|
* Pointers to the 4 root place holders.
|
|
|
|
|
* @remarks All 4 entries are NULL until setup_dock has been called.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-04 17:57:06 +02:00
|
|
|
GdlDockPlaceholder *dockPlaceholders[4];
|
|
|
|
|
|
2009-04-04 18:22:46 +02:00
|
|
|
/**
|
|
|
|
|
* The list of created panels.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-16 11:02:53 +02:00
|
|
|
std::list< panels::Panel* > panels;
|
2009-04-13 17:11:50 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An accumulator for the panel id.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-13 17:11:50 +02:00
|
|
|
static unsigned short panelID;
|
2009-04-04 17:57:06 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A class to describe and instantiate Panel types.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-04 17:57:06 +02:00
|
|
|
class PanelDescription
|
|
|
|
|
{
|
2009-04-13 17:11:50 +02:00
|
|
|
protected:
|
|
|
|
|
|
2009-04-16 11:02:53 +02:00
|
|
|
typedef panels::Panel* (*const CreatePanelProc)(
|
2011-10-16 16:43:59 +02:00
|
|
|
PanelManager&, Gdl::DockItem&);
|
2009-04-13 17:11:50 +02:00
|
|
|
|
2009-04-04 17:57:06 +02:00
|
|
|
protected:
|
2009-04-04 18:22:46 +02:00
|
|
|
/**
|
|
|
|
|
* Constructor
|
2009-04-15 13:24:34 +02:00
|
|
|
* @param classInfo The typeid of the Panel class
|
2009-04-04 18:22:46 +02:00
|
|
|
* @param title The localized title that will be shown on the
|
|
|
|
|
* panel.
|
2009-04-04 19:53:09 +02:00
|
|
|
* @param stock_id The Stock ID for this type of panel.
|
2009-04-04 18:22:46 +02:00
|
|
|
* @param create_panel_proc A pointer to a function that will
|
|
|
|
|
* instantiate the panel object.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-15 13:24:34 +02:00
|
|
|
PanelDescription(const std::type_info &class_info,
|
|
|
|
|
const char *title, const gchar *stock_id,
|
|
|
|
|
CreatePanelProc create_panel_proc) :
|
|
|
|
|
classInfo(class_info),
|
2009-04-04 17:57:06 +02:00
|
|
|
titleName(title),
|
2009-04-04 19:53:09 +02:00
|
|
|
stockID(stock_id),
|
2009-04-04 17:57:06 +02:00
|
|
|
createPanelProc(create_panel_proc)
|
|
|
|
|
{
|
|
|
|
|
REQUIRE(titleName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
2009-04-04 18:22:46 +02:00
|
|
|
/**
|
2009-04-15 13:24:34 +02:00
|
|
|
* Returns a reference to the typeid of the class.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-15 13:24:34 +02:00
|
|
|
const std::type_info& get_class_info() const
|
|
|
|
|
{
|
|
|
|
|
return classInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a pointer to the string name of the class.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-04 17:57:06 +02:00
|
|
|
const char* get_class_name() const
|
|
|
|
|
{
|
2009-04-15 13:24:34 +02:00
|
|
|
return classInfo.name();
|
2009-04-04 17:57:06 +02:00
|
|
|
}
|
2009-04-04 18:22:46 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the localized title that will be shown on the panel.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-04 17:57:06 +02:00
|
|
|
const char* get_title() const
|
|
|
|
|
{
|
|
|
|
|
ENSURE(titleName);
|
|
|
|
|
return titleName;
|
|
|
|
|
}
|
2009-04-04 19:53:09 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the Stock ID for this type of panel.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-04 19:53:09 +02:00
|
|
|
const gchar* get_stock_id() const
|
|
|
|
|
{
|
|
|
|
|
ENSURE(stockID);
|
|
|
|
|
return stockID;
|
|
|
|
|
}
|
2009-04-04 17:57:06 +02:00
|
|
|
|
2009-04-04 18:22:46 +02:00
|
|
|
/**
|
|
|
|
|
* Creates an instance of this panel.
|
2009-04-13 17:11:50 +02:00
|
|
|
* @param panel_manager The owner panel manager.
|
|
|
|
|
* @param dock_item The GdlDockItem that will host this panel.
|
2009-04-16 11:02:53 +02:00
|
|
|
* @return Returns a pointer to the panel object.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-16 11:02:53 +02:00
|
|
|
panels::Panel* create(
|
2011-10-16 16:43:59 +02:00
|
|
|
PanelManager &panel_manager, Gdl::DockItem &dock_item) const
|
2009-04-04 17:57:06 +02:00
|
|
|
{
|
|
|
|
|
REQUIRE(createPanelProc);
|
2009-04-13 17:11:50 +02:00
|
|
|
return createPanelProc(panel_manager, dock_item);
|
2009-04-04 17:57:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2009-04-04 18:22:46 +02:00
|
|
|
/**
|
2009-04-15 13:24:34 +02:00
|
|
|
* A reference to the typeid of this class
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-15 13:24:34 +02:00
|
|
|
const std::type_info &classInfo;
|
2009-04-04 18:22:46 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The localized title that will be shown on the panel.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-04 19:53:09 +02:00
|
|
|
const char* const titleName;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The Stock ID for this type of panel.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-04 19:53:09 +02:00
|
|
|
const gchar* const stockID;
|
2009-04-04 18:22:46 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A pointer to a function that will instantiate the panel object.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-13 17:11:50 +02:00
|
|
|
CreatePanelProc createPanelProc;
|
2009-04-04 17:57:06 +02:00
|
|
|
};
|
|
|
|
|
|
2009-04-04 18:22:46 +02:00
|
|
|
/**
|
|
|
|
|
* A helper class that will create PanelDescription objects.
|
|
|
|
|
* @param P The type of panels::Panel that the PanelDescription will
|
|
|
|
|
* describe.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-04 17:57:06 +02:00
|
|
|
template<class P> class Panel : public PanelDescription
|
|
|
|
|
{
|
|
|
|
|
public:
|
2009-04-04 18:22:46 +02:00
|
|
|
/**
|
|
|
|
|
* Constructor
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-04 17:57:06 +02:00
|
|
|
Panel() :
|
2009-04-15 13:24:34 +02:00
|
|
|
PanelDescription(typeid(P), P::get_title(),
|
2009-04-04 19:53:09 +02:00
|
|
|
P::get_stock_id(), Panel::create_panel)
|
2009-04-04 17:57:06 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
private:
|
2009-04-04 18:22:46 +02:00
|
|
|
/**
|
|
|
|
|
* A helper function that will create a panel of type P
|
2009-04-13 17:11:50 +02:00
|
|
|
* @param panel_manager The owner panel manager.
|
2011-10-16 16:43:59 +02:00
|
|
|
* @param dock_item The Gdl::DockItem that will host this panel.
|
2009-04-16 11:02:53 +02:00
|
|
|
* @return Returns a pointer to the panel object.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-16 11:02:53 +02:00
|
|
|
static panels::Panel* create_panel(
|
2011-10-16 16:43:59 +02:00
|
|
|
PanelManager &panel_manager, Gdl::DockItem &dock_item)
|
2009-04-04 17:57:06 +02:00
|
|
|
{
|
2009-04-16 11:02:53 +02:00
|
|
|
return new P(panel_manager, dock_item);
|
2009-04-04 17:57:06 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2009-04-04 18:22:46 +02:00
|
|
|
/**
|
|
|
|
|
* The list of panel descriptions.
|
2011-01-03 10:30:45 +01:00
|
|
|
*/
|
2009-04-04 17:57:06 +02:00
|
|
|
static const PanelDescription panelDescriptionList[];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace workspace
|
|
|
|
|
} // namespace gui
|
|
|
|
|
|
|
|
|
|
#endif // PANEL_MANAGER_HPP
|