Modify Panel hiding for PanelManager compatibility

This commit is contained in:
Joel Holdsworth 2009-04-15 20:12:06 +01:00
parent 08fd135a98
commit 303a6f2ce4
4 changed files with 121 additions and 14 deletions

View file

@ -36,6 +36,7 @@ Panel::Panel(workspace::PanelManager &panel_manager,
const gchar *stock_id) :
panelManager(panel_manager),
dockItem(dock_item),
hide_panel_handler_id(0),
panelBar(*this, stock_id)
{
REQUIRE(dockItem);
@ -56,6 +57,10 @@ Panel::Panel(workspace::PanelManager &panel_manager,
gtk_container_add ((GtkContainer*)dockItem, (GtkWidget*)gobj());
gtk_widget_show ((GtkWidget*)dockItem);
// Connect the signals
hide_panel_handler_id = g_signal_connect (GTK_OBJECT(dockItem),
"hide", G_CALLBACK(on_item_hidden), this);
}
Panel::~Panel()
@ -67,6 +72,10 @@ Panel::~Panel()
gdl_dock_item_get_grip(dockItem));
gtk_container_remove (GTK_CONTAINER(grip),
((Widget&)panelBar).gobj());
// Detach the signals
g_signal_handler_disconnect(
GTK_OBJECT(dockItem), hide_panel_handler_id);
// Unref the dock item
g_object_unref(dockItem);
@ -88,10 +97,24 @@ Panel::show(bool show)
}
bool
Panel::is_locked() const
Panel::is_shown() const
{
REQUIRE(dockItem != NULL);
return !GDL_DOCK_ITEM_NOT_LOCKED(dockItem);
return GTK_WIDGET_VISIBLE((GtkWidget*)dockItem);
}
void
Panel::iconify()
{
REQUIRE(dockItem != NULL);
gdl_dock_item_iconify_item(dockItem);
}
bool
Panel::is_iconified() const
{
REQUIRE(dockItem != NULL);
return GDL_DOCK_ITEM_ICONIFIED(dockItem);
}
void
@ -102,6 +125,13 @@ Panel::lock(bool lock)
else gdl_dock_item_unlock (dockItem);
}
bool
Panel::is_locked() const
{
REQUIRE(dockItem != NULL);
return !GDL_DOCK_ITEM_NOT_LOCKED(dockItem);
}
workspace::PanelManager&
Panel::get_panel_manager()
{
@ -126,5 +156,18 @@ Panel::get_controller()
return panelManager.get_workspace_window().get_controller();
}
sigc::signal<void>&
Panel::signal_hide_panel()
{
return hidePanelSignal;
}
void
Panel::on_item_hidden(GdlDockItem*, Panel *panel)
{
REQUIRE(panel);
panel->hidePanelSignal();
}
} // namespace panels
} // namespace gui

View file

@ -81,6 +81,16 @@ public:
*/
bool is_shown() const;
/**
* Iconifys the panel.
**/
void iconify();
/**
* Returns true if the panel is currently iconified.
**/
bool is_iconified() const;
/**
* Locks or unlocks the panel.
* @param show A value of true will lock the panel, false will unlock
@ -98,6 +108,13 @@ public:
**/
workspace::PanelManager& get_panel_manager();
public:
/**
* A signal that fires when the dock item is hidden.
**/
sigc::signal<void>& signal_hide_panel();
protected:
/**
@ -114,6 +131,14 @@ protected:
* Returns a reference to the controller
**/
controller::Controller& get_controller();
private:
/**
* An event handler for when dockItem is hidden.
* @param func_data A pointer to the panel that owns dock_item
**/
static void on_item_hidden(GdlDockItem*, Panel *panel);
protected:
@ -128,6 +153,16 @@ protected:
**/
GdlDockItem* dockItem;
/**
* A signal that fires when the dock item is hidden.
**/
sigc::signal<void> hidePanelSignal;
/**
* The id of the hide panel handler.
**/
gulong hide_panel_handler_id;
/**
* The panel bar to attach to the panel grip.
**/

View file

@ -130,6 +130,8 @@ PanelManager::show_panel(const int description_index)
const shared_ptr<panels::Panel> panel = *i;
if(get_panel_type(panel.get()) == description_index)
{
panel->show();
GdlDockItem *dock_item = panel->get_dock_item();
ENSURE(dock_item);
gdl_dock_object_present(GDL_DOCK_OBJECT(dock_item), NULL);
@ -141,9 +143,6 @@ PanelManager::show_panel(const int description_index)
shared_ptr<panels::Panel> new_panel =
create_panel_by_index(description_index);
// Add it to the list
panels.push_back(new_panel);
// Dock the item
gdl_dock_add_item(dock, new_panel->get_dock_item(),
GDL_DOCK_FLOATING);
@ -174,8 +173,6 @@ void PanelManager::switch_panel(panels::Panel &old_panel,
shared_ptr<panels::Panel> new_panel(
panelDescriptionList[description_index].create(*this, dock_item));
g_object_unref(dock_item);
panels.push_back(new_panel);
}
void
@ -186,9 +183,6 @@ PanelManager::split_panel(panels::Panel &panel,
const int index = get_panel_type(&panel);
shared_ptr<panels::Panel> new_panel = create_panel_by_index(index);
// Add it to the list
panels.push_back(new_panel);
// Dock the panel
GdlDockPlacement placement = GDL_DOCK_NONE;
switch(split_direction)
@ -245,10 +239,6 @@ PanelManager::create_panels()
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);
}
int
@ -287,6 +277,13 @@ PanelManager::create_panel_by_index(const int index)
ENSURE(panel);
panel->show_all();
// Connect event handlers
panel->signal_hide_panel().connect(bind(
mem_fun(*this, &PanelManager::on_panel_shown), panel));
// Add the panel to the list
panels.push_back(panel);
return panel;
}
@ -315,5 +312,29 @@ PanelManager::get_panel_type(panels::Panel *panel) const
return -1;
}
void
PanelManager::on_panel_shown(boost::weak_ptr<panels::Panel> panel_ptr)
{
if(panel_ptr.expired())
return;
shared_ptr<panels::Panel> panel(panel_ptr);
REQUIRE(panel);
if(panel->is_shown() || panel->is_iconified())
return;
// Release the panel
list< boost::shared_ptr<panels::Panel> >::iterator i;
for(i = panels.begin(); i != panels.end(); i++)
{
if((*i) == panel)
{
panels.erase(i);
break;
}
}
}
} // namespace workspace
} // namespace gui

View file

@ -165,6 +165,14 @@ private:
* if no description was found for this type.
**/
int get_panel_type(panels::Panel *panel) const;
private:
/**
* An event handler for when the panel is shown or hidden.
* @param panel_ptr A weak pointer to the panel that was hidden.
**/
void on_panel_shown(boost::weak_ptr<panels::Panel> panel_ptr);
private: