fix tool referencing, remove dropdown element in DoDeleteTool, ticket #4102
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53913 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -101,17 +101,12 @@ public:
|
|||||||
: wxToolBarToolBase(tbar, control, label)
|
: wxToolBarToolBase(tbar, control, label)
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
}
|
// Hold a reference to keep control alive until DoInsertTool() is
|
||||||
|
// called, or if RemoveTool() is called (see DoDeleteTool)
|
||||||
virtual ~wxToolBarTool()
|
g_object_ref(control->m_widget);
|
||||||
{
|
// release reference when gtk_widget_destroy() is called on control
|
||||||
if ( IsControl() && !m_item )
|
g_signal_connect(
|
||||||
{
|
control->m_widget, "destroy", G_CALLBACK(g_object_unref), NULL);
|
||||||
// if we're a control which is not currently attached to the
|
|
||||||
// toolbar (as indicated by NULL m_item), we must undo the extra
|
|
||||||
// reference we added in DoDeleteTool()
|
|
||||||
g_object_unref(GetControl()->m_widget);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// is this a radio button?
|
// is this a radio button?
|
||||||
@@ -153,6 +148,8 @@ public:
|
|||||||
// the toolbar element for button tools or a GtkAlignment containing the
|
// the toolbar element for button tools or a GtkAlignment containing the
|
||||||
// control for control tools
|
// control for control tools
|
||||||
GtkWidget *m_item;
|
GtkWidget *m_item;
|
||||||
|
// dropdown element for button tools
|
||||||
|
GtkWidget *m_itemDropdown;
|
||||||
|
|
||||||
// a GtkImage containing the image for a button-type tool, may be NULL
|
// a GtkImage containing the image for a button-type tool, may be NULL
|
||||||
GtkWidget *m_image;
|
GtkWidget *m_image;
|
||||||
@@ -359,11 +356,9 @@ size_request(GtkWidget*, GtkRequisition* req, wxToolBar* win)
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
static void wxInsertChildInToolBar( wxWindow* WXUNUSED(parent),
|
static void wxInsertChildInToolBar( wxWindow* WXUNUSED(parent),
|
||||||
wxWindow* child)
|
wxWindow* /* child */)
|
||||||
{
|
{
|
||||||
// Child widget will be inserted into GtkToolbar by DoInsertTool. Ref it
|
// Child widget will be inserted into GtkToolbar by DoInsertTool()
|
||||||
// here so reparenting into wxToolBar doesn't delete it.
|
|
||||||
g_object_ref(child->m_widget);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -373,6 +368,7 @@ static void wxInsertChildInToolBar( wxWindow* WXUNUSED(parent),
|
|||||||
void wxToolBarTool::Init()
|
void wxToolBarTool::Init()
|
||||||
{
|
{
|
||||||
m_item =
|
m_item =
|
||||||
|
m_itemDropdown =
|
||||||
m_image = NULL;
|
m_image = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -605,6 +601,7 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
|
|||||||
GtkWidget *image = gtk_image_new_from_pixbuf( pixbuf );
|
GtkWidget *image = gtk_image_new_from_pixbuf( pixbuf );
|
||||||
gtk_widget_show( image );
|
gtk_widget_show( image );
|
||||||
gtk_container_add( GTK_CONTAINER(dropdown), image );
|
gtk_container_add( GTK_CONTAINER(dropdown), image );
|
||||||
|
g_object_unref(pixbuf);
|
||||||
|
|
||||||
if (GetWindowStyle() & wxTB_FLAT)
|
if (GetWindowStyle() & wxTB_FLAT)
|
||||||
gtk_button_set_relief( GTK_BUTTON(dropdown), GTK_RELIEF_NONE );
|
gtk_button_set_relief( GTK_BUTTON(dropdown), GTK_RELIEF_NONE );
|
||||||
@@ -628,6 +625,7 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
|
|||||||
|
|
||||||
gtk_toolbar_insert_widget(m_toolbar, dropdown, NULL, NULL,
|
gtk_toolbar_insert_widget(m_toolbar, dropdown, NULL, NULL,
|
||||||
posGtk + 1);
|
posGtk + 1);
|
||||||
|
tool->m_itemDropdown = dropdown;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -643,9 +641,6 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
|
|||||||
tool->GetControl()->m_widget);
|
tool->GetControl()->m_widget);
|
||||||
gtk_toolbar_insert_widget(m_toolbar, align, NULL, NULL, posGtk);
|
gtk_toolbar_insert_widget(m_toolbar, align, NULL, NULL, posGtk);
|
||||||
|
|
||||||
// release reference obtained by wxInsertChildInToolBar
|
|
||||||
g_object_unref(tool->GetControl()->m_widget);
|
|
||||||
|
|
||||||
// remember the container we're in so that we could remove
|
// remember the container we're in so that we could remove
|
||||||
// ourselves from it when we're detached from the toolbar
|
// ourselves from it when we're detached from the toolbar
|
||||||
tool->m_item = align;
|
tool->m_item = align;
|
||||||
@@ -668,16 +663,18 @@ bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *toolBase)
|
|||||||
// RemoveTool() and then we need to keep the control alive;
|
// RemoveTool() and then we need to keep the control alive;
|
||||||
// while if we're called from DeleteTool() the control will
|
// while if we're called from DeleteTool() the control will
|
||||||
// be destroyed when wxToolBarToolBase itself is deleted
|
// be destroyed when wxToolBarToolBase itself is deleted
|
||||||
{
|
gtk_container_remove(
|
||||||
GtkWidget * const w = tool->GetControl()->m_widget;
|
GTK_CONTAINER(tool->m_item), tool->GetControl()->m_widget);
|
||||||
g_object_ref(w);
|
|
||||||
gtk_container_remove(GTK_CONTAINER(tool->m_item), w);
|
|
||||||
}
|
|
||||||
// fall through
|
// fall through
|
||||||
|
|
||||||
case wxTOOL_STYLE_BUTTON:
|
case wxTOOL_STYLE_BUTTON:
|
||||||
gtk_widget_destroy( tool->m_item );
|
gtk_widget_destroy( tool->m_item );
|
||||||
tool->m_item = NULL;
|
tool->m_item = NULL;
|
||||||
|
if (tool->m_itemDropdown)
|
||||||
|
{
|
||||||
|
gtk_widget_destroy(tool->m_itemDropdown);
|
||||||
|
tool->m_itemDropdown = NULL;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case wxTOOL_STYLE_SEPARATOR:
|
case wxTOOL_STYLE_SEPARATOR:
|
||||||
|
Reference in New Issue
Block a user