Replaced shared_ptrs with normal pointers in PanelManager

This commit is contained in:
Joel Holdsworth 2009-04-16 10:02:53 +01:00
parent 303a6f2ce4
commit 0fbfd169df
2 changed files with 85 additions and 56 deletions

View file

@ -67,6 +67,8 @@ PanelManager::~PanelManager()
for(int i = 0; i < 4; i++)
if(dockPlaceholders[i])
g_object_unref(dockPlaceholders[i]);
clear_panels();
}
void
@ -124,11 +126,11 @@ void
PanelManager::show_panel(const int description_index)
{
// Try and find the panel and present it if possible
list< boost::shared_ptr<panels::Panel> >::iterator i;
list< panels::Panel* >::iterator i;
for(i = panels.begin(); i != panels.end(); i++)
{
const shared_ptr<panels::Panel> panel = *i;
if(get_panel_type(panel.get()) == description_index)
panels::Panel* const panel = *i;
if(get_panel_type(panel) == description_index)
{
panel->show();
@ -140,8 +142,7 @@ PanelManager::show_panel(const int description_index)
}
// Create the new panel
shared_ptr<panels::Panel> new_panel =
create_panel_by_index(description_index);
panels::Panel *new_panel = create_panel_by_index(description_index);
// Dock the item
gdl_dock_add_item(dock, new_panel->get_dock_item(),
@ -157,21 +158,12 @@ void PanelManager::switch_panel(panels::Panel &old_panel,
// Get the dock item
GdlDockItem *dock_item = old_panel.get_dock_item();
g_object_ref(dock_item);
// Release the old panel
list< boost::shared_ptr<panels::Panel> >::iterator i;
for(i = panels.begin(); i != panels.end(); i++)
{
if((*i).get() == &old_panel)
{
panels.erase(i);
break;
}
}
remove_panel(&old_panel);
// Create the new panel
shared_ptr<panels::Panel> new_panel(
panelDescriptionList[description_index].create(*this, dock_item));
create_panel_by_index(description_index, dock_item);
g_object_unref(dock_item);
}
@ -181,7 +173,7 @@ PanelManager::split_panel(panels::Panel &panel,
{
// Create the new panel
const int index = get_panel_type(&panel);
shared_ptr<panels::Panel> new_panel = create_panel_by_index(index);
panels::Panel *new_panel = create_panel_by_index(index);
// Dock the panel
GdlDockPlacement placement = GDL_DOCK_NONE;
@ -226,12 +218,12 @@ PanelManager::get_panel_title(int index)
void
PanelManager::create_panels()
{
shared_ptr<panels::Panel> resourcesPanel(
create_panel_by_name("ResourcesPanel"));
shared_ptr<panels::Panel> viewerPanel(
create_panel_by_name("ViewerPanel"));
shared_ptr<panels::Panel> timelinePanel(
create_panel_by_name("TimelinePanel"));
panels::Panel* resourcesPanel =
create_panel_by_name("ResourcesPanel");
panels::Panel* viewerPanel =
create_panel_by_name("ViewerPanel");
panels::Panel* timelinePanel =
create_panel_by_name("TimelinePanel");
gdl_dock_add_item(dock,
resourcesPanel->get_dock_item(), GDL_DOCK_LEFT);
@ -258,7 +250,7 @@ PanelManager::find_panel_description(const char* class_name) const
return -1;
}
shared_ptr<panels::Panel>
panels::Panel*
PanelManager::create_panel_by_index(const int index)
{
REQUIRE(index >= 0 && index < get_panel_description_count());
@ -270,10 +262,17 @@ PanelManager::create_panel_by_index(const int index)
// Create a dock item
GdlDockItem *dock_item = GDL_DOCK_ITEM(
gdl_dock_item_new(name, "", GDL_DOCK_ITEM_BEH_NORMAL));
return create_panel_by_index(index, dock_item);
}
panels::Panel*
PanelManager::create_panel_by_index(
const int index, GdlDockItem *dock_item)
{
// Create the panel object
shared_ptr<panels::Panel> panel(
panelDescriptionList[index].create(*this, dock_item));
panels::Panel *panel =
panelDescriptionList[index].create(*this, dock_item);
ENSURE(panel);
panel->show_all();
@ -287,7 +286,7 @@ PanelManager::create_panel_by_index(const int index)
return panel;
}
shared_ptr<panels::Panel>
panels::Panel*
PanelManager::create_panel_by_name(const char* class_name)
{
REQUIRE(class_name);
@ -296,7 +295,7 @@ PanelManager::create_panel_by_name(const char* class_name)
}
int
PanelManager::get_panel_type(panels::Panel *panel) const
PanelManager::get_panel_type(panels::Panel* const panel) const
{
REQUIRE(panel);
@ -313,28 +312,41 @@ PanelManager::get_panel_type(panels::Panel *panel) const
}
void
PanelManager::on_panel_shown(boost::weak_ptr<panels::Panel> panel_ptr)
{
if(panel_ptr.expired())
return;
shared_ptr<panels::Panel> panel(panel_ptr);
PanelManager::remove_panel(panels::Panel* const panel)
{
REQUIRE(panel);
if(panel->is_shown() || panel->is_iconified())
return;
// Release the panel
list< boost::shared_ptr<panels::Panel> >::iterator i;
list< panels::Panel* >::iterator i;
for(i = panels.begin(); i != panels.end(); i++)
{
if((*i) == panel)
if(*i == panel)
{
delete panel;
panels.erase(i);
break;
}
}
}
void
PanelManager::clear_panels()
{
list< panels::Panel* >::iterator i;
for(i = panels.begin(); i != panels.end(); i++)
delete *i;
panels.clear();
}
void
PanelManager::on_panel_shown(panels::Panel *panel)
{
REQUIRE(panel);
if(panel->is_shown() || panel->is_iconified())
return;
remove_panel(panel);
}
} // namespace workspace
} // namespace gui

View file

@ -147,16 +147,23 @@ private:
* @param index The index of the description to instantiate.
* @return Returns a pointer to the new instantiated panel object.
**/
boost::shared_ptr<panels::Panel> create_panel_by_index(
const int index);
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.
**/
panels::Panel* create_panel_by_index(
const int index, GdlDockItem *dock_item);
/**
* Creates a panel by class name.
* @param class_name The name of the object class to create.
* @return Returns a pointer to the new instantiated panel object.
**/
boost::shared_ptr<panels::Panel> create_panel_by_name(
const char* class_name);
panels::Panel* create_panel_by_name(const char* class_name);
/**
* Gets the type of a given panel.
@ -164,15 +171,26 @@ private:
* @return Returns the index of the panel description found, or -1
* if no description was found for this type.
**/
int get_panel_type(panels::Panel *panel) const;
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.
**/
void remove_panel(panels::Panel* const panel);
/**
* Removes all panels from the panel list and deletes them.
**/
void clear_panels();
private:
/**
* An event handler for when the panel is shown or hidden.
* @param panel_ptr A weak pointer to the panel that was hidden.
* @param panel A pointer to the panel that was hidden.
**/
void on_panel_shown(boost::weak_ptr<panels::Panel> panel_ptr);
void on_panel_shown(panels::Panel *panel);
private:
@ -208,7 +226,7 @@ private:
/**
* The list of created panels.
**/
std::list< boost::shared_ptr<panels::Panel> > panels;
std::list< panels::Panel* > panels;
/**
* An accumulator for the panel id.
@ -224,7 +242,7 @@ private:
{
protected:
typedef boost::shared_ptr<panels::Panel> (*const CreatePanelProc)(
typedef panels::Panel* (*const CreatePanelProc)(
PanelManager&, GdlDockItem*);
protected:
@ -287,9 +305,9 @@ private:
* Creates an instance of this panel.
* @param panel_manager The owner panel manager.
* @param dock_item The GdlDockItem that will host this panel.
* @return Returns a shared pointer to the panel object.
* @return Returns a pointer to the panel object.
**/
boost::shared_ptr<panels::Panel> create(
panels::Panel* create(
PanelManager &panel_manager, GdlDockItem* dock_item) const
{
REQUIRE(createPanelProc);
@ -339,13 +357,12 @@ private:
* A helper function that will create a panel of type P
* @param panel_manager The owner panel manager.
* @param dock_item The GdlDockItem that will host this panel.
* @return Returns a shared pointer to the panel object.
* @return Returns a pointer to the panel object.
**/
static boost::shared_ptr<panels::Panel> create_panel(
static panels::Panel* create_panel(
PanelManager &panel_manager, GdlDockItem* dock_item)
{
return boost::shared_ptr<panels::Panel>(
new P(panel_manager, dock_item));
return new P(panel_manager, dock_item);
}
};