X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a1cb0b110e2463648853ca3ba67d355a0e679cc7..f51723055aa4334a355a19e87bb2b478b4204d15:/src/gtk/tbargtk.cpp diff --git a/src/gtk/tbargtk.cpp b/src/gtk/tbargtk.cpp index b6de3f5c02..179f2aecf9 100644 --- a/src/gtk/tbargtk.cpp +++ b/src/gtk/tbargtk.cpp @@ -51,12 +51,6 @@ public: : wxToolBarToolBase(tbar, control, label) { m_item = NULL; - // Hold a reference to keep control alive until DoInsertTool() is - // called, or if RemoveTool() is called (see DoDeleteTool) - g_object_ref(control->m_widget); - // release reference when gtk_widget_destroy() is called on control - g_signal_connect( - control->m_widget, "destroy", G_CALLBACK(g_object_unref), NULL); } void SetImage(); @@ -248,14 +242,15 @@ arrow_button_press_event(GtkToggleButton* button, GdkEventButton* event, wxToolB } } -//----------------------------------------------------------------------------- -// InsertChild callback for wxToolBar -//----------------------------------------------------------------------------- - -static void wxInsertChildInToolBar( wxWindow* WXUNUSED(parent), - wxWindow* /* child */) +void wxToolBar::AddChildGTK(wxWindowGTK* child) { - // Child widget will be inserted into GtkToolbar by DoInsertTool() + GtkWidget* align = gtk_alignment_new(0.5, 0.5, 0, 0); + gtk_widget_show(align); + gtk_container_add(GTK_CONTAINER(align), child->m_widget); + GtkToolItem* item = gtk_tool_item_new(); + gtk_container_add(GTK_CONTAINER(item), align); + // position will be corrected in DoInsertTool if necessary + gtk_toolbar_insert(GTK_TOOLBAR(GTK_BIN(m_widget)->child), item, -1); } // ---------------------------------------------------------------------------- @@ -350,7 +345,7 @@ wxToolBar::CreateTool(wxControl *control, const wxString& label) void wxToolBar::Init() { - m_toolbar = (GtkToolbar *)NULL; + m_toolbar = NULL; m_tooltips = NULL; } @@ -370,8 +365,6 @@ bool wxToolBar::Create( wxWindow *parent, long style, const wxString& name ) { - m_insertCallback = wxInsertChildInToolBar; - if ( !PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) { @@ -405,6 +398,7 @@ bool wxToolBar::Create( wxWindow *parent, m_widget = gtk_event_box_new(); ConnectWidget( m_widget ); } + g_object_ref(m_widget); gtk_container_add(GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar)); gtk_widget_show(GTK_WIDGET(m_toolbar)); @@ -453,7 +447,7 @@ void wxToolBar::SetWindowStyleFlag( long style ) bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase) { - wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase); + wxToolBarTool* tool = static_cast(toolBase); GSList* radioGroup; switch ( tool->GetStyle() ) @@ -520,19 +514,27 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase) if (tool->GetKind() == wxITEM_DROPDOWN) tool->CreateDropDown(); + gtk_toolbar_insert(m_toolbar, tool->m_item, int(pos)); break; case wxTOOL_STYLE_SEPARATOR: tool->m_item = gtk_separator_tool_item_new(); + gtk_toolbar_insert(m_toolbar, tool->m_item, int(pos)); break; case wxTOOL_STYLE_CONTROL: - GtkWidget * const align = gtk_alignment_new(0.5, 0.5, 0, 0); - gtk_widget_show(align); wxWindow* control = tool->GetControl(); - gtk_container_add(GTK_CONTAINER(align), control->m_widget); - tool->m_item = gtk_tool_item_new(); - gtk_container_add(GTK_CONTAINER(tool->m_item), align); + if (control->m_widget->parent == NULL) + AddChildGTK(control); + tool->m_item = GTK_TOOL_ITEM(control->m_widget->parent->parent); + if (gtk_toolbar_get_item_index(m_toolbar, tool->m_item) != int(pos)) + { + g_object_ref(tool->m_item); + gtk_container_remove( + GTK_CONTAINER(m_toolbar), GTK_WIDGET(tool->m_item)); + gtk_toolbar_insert(m_toolbar, tool->m_item, int(pos)); + g_object_unref(tool->m_item); + } // Inserted items "slide" into place using an animated effect that // causes multiple size events on the item. Must set size request // to keep item size from getting permanently set too small by the @@ -542,7 +544,6 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase) break; } gtk_widget_show(GTK_WIDGET(tool->m_item)); - gtk_toolbar_insert(m_toolbar, tool->m_item, int(pos)); InvalidateBestSize(); @@ -551,7 +552,7 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase) bool wxToolBar::DoDeleteTool(size_t /* pos */, wxToolBarToolBase* toolBase) { - wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase); + wxToolBarTool* tool = static_cast(toolBase); if (tool->GetStyle() == wxTOOL_STYLE_CONTROL) { @@ -596,7 +597,7 @@ GSList* wxToolBar::GetRadioGroup(size_t pos) void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable) { - wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase); + wxToolBarTool* tool = static_cast(toolBase); if (tool->m_item) gtk_widget_set_sensitive(GTK_WIDGET(tool->m_item), enable); @@ -604,7 +605,7 @@ void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable) void wxToolBar::DoToggleTool( wxToolBarToolBase *toolBase, bool toggle ) { - wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase); + wxToolBarTool* tool = static_cast(toolBase); if (tool->m_item) { @@ -647,12 +648,12 @@ wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x), // VZ: GTK+ doesn't seem to have such thing wxFAIL_MSG( _T("wxToolBar::FindToolForPosition() not implemented") ); - return (wxToolBarToolBase *)NULL; + return NULL; } void wxToolBar::SetToolShortHelp( int id, const wxString& helpString ) { - wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id)); + wxToolBarTool* tool = static_cast(FindById(id)); if ( tool ) { @@ -667,7 +668,7 @@ void wxToolBar::SetToolShortHelp( int id, const wxString& helpString ) void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap ) { - wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id)); + wxToolBarTool* tool = static_cast(FindById(id)); if ( tool ) { wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools.")); @@ -679,7 +680,7 @@ void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap ) void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap ) { - wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id)); + wxToolBarTool* tool = static_cast(FindById(id)); if ( tool ) { wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools.")); @@ -695,7 +696,7 @@ void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap ) void wxToolBar::OnInternalIdle() { // Check if we have to show window now - if (GtkShowFromOnIdle()) return; + if (GTKShowFromOnIdle()) return; wxCursor cursor = m_cursor; if (g_globalCursor.Ok()) cursor = g_globalCursor;