]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/toolbar.cpp
always skip OnSize
[wxWidgets.git] / src / gtk / toolbar.cpp
index 701ec64a8451abc73bbb15df3a939dbc13105ce1..969c7f9f360f55b806ea72b459a3e10d662d4bff 100644 (file)
@@ -351,7 +351,7 @@ void wxToolBar::Init()
 
 wxToolBar::~wxToolBar()
 {
-    if (m_tooltips)
+    if (m_tooltips) // always NULL if GTK >= 2.12
     {
         gtk_object_destroy(GTK_OBJECT(m_tooltips));
         g_object_unref(m_tooltips);
@@ -376,9 +376,12 @@ bool wxToolBar::Create( wxWindow *parent,
     FixupStyle();
 
     m_toolbar = GTK_TOOLBAR( gtk_toolbar_new() );
-    m_tooltips = gtk_tooltips_new();
-    g_object_ref(m_tooltips);
-    gtk_object_sink(GTK_OBJECT(m_tooltips));
+    if (gtk_check_version(2, 12, 0))
+    {
+        m_tooltips = gtk_tooltips_new();
+        g_object_ref(m_tooltips);
+        gtk_object_sink(GTK_OBJECT(m_tooltips));
+    }
     GtkSetStyle();
 
     if (style & wxTB_DOCKABLE)
@@ -445,6 +448,32 @@ void wxToolBar::SetWindowStyleFlag( long style )
         GtkSetStyle();
 }
 
+bool wxToolBar::Realize()
+{
+    if ( !wxToolBarBase::Realize() )
+        return false;
+
+    // bring the initial state of all the toolbar items in line with the
+    // internal state if the latter was changed by calling wxToolBarTool::
+    // Enable(): this works under MSW, where the toolbar items are only created
+    // in Realize() which uses the internal state to determine the initial
+    // button state, so make it work under GTK too
+    for ( wxToolBarToolsList::const_iterator i = m_tools.begin();
+          i != m_tools.end();
+          ++i )
+    {
+        // by default the toolbar items are enabled and not toggled, so we only
+        // have to do something if their internal state doesn't correspond to
+        // this
+        if ( !(*i)->IsEnabled() )
+            DoEnableTool(*i, false);
+        if ( (*i)->IsToggled() )
+            DoToggleTool(*i, true);
+    }
+
+    return true;
+}
+
 bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
 {
     wxToolBarTool* tool = static_cast<wxToolBarTool*>(toolBase);
@@ -502,8 +531,18 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
             }
             if (!HasFlag(wxTB_NO_TOOLTIPS) && !tool->GetShortHelp().empty())
             {
-                gtk_tool_item_set_tooltip(tool->m_item,
-                    m_tooltips, wxGTK_CONV(tool->GetShortHelp()), "");
+#if GTK_CHECK_VERSION(2, 12, 0)
+                if (!gtk_check_version(2, 12, 0))
+                {
+                    gtk_tool_item_set_tooltip_text(tool->m_item,
+                        wxGTK_CONV(tool->GetShortHelp()));
+                }
+                else
+#endif
+                {
+                    gtk_tool_item_set_tooltip(tool->m_item,
+                        m_tooltips, wxGTK_CONV(tool->GetShortHelp()), "");
+                }
             }
             g_signal_connect(GTK_BIN(tool->m_item)->child, "button_press_event",
                 G_CALLBACK(button_press_event), tool);
@@ -519,6 +558,15 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
 
         case wxTOOL_STYLE_SEPARATOR:
             tool->m_item = gtk_separator_tool_item_new();
+            if ( tool->IsStretchable() )
+            {
+                gtk_separator_tool_item_set_draw
+                (
+                    GTK_SEPARATOR_TOOL_ITEM(tool->m_item),
+                    FALSE
+                );
+                gtk_tool_item_set_expand(tool->m_item, TRUE);
+            }
             gtk_toolbar_insert(m_toolbar, tool->m_item, int(pos));
             break;
 
@@ -660,8 +708,18 @@ void wxToolBar::SetToolShortHelp( int id, const wxString& helpString )
         (void)tool->SetShortHelp(helpString);
         if (tool->m_item)
         {
-            gtk_tool_item_set_tooltip(tool->m_item,
-                m_tooltips, wxGTK_CONV(helpString), "");
+#if GTK_CHECK_VERSION(2, 12, 0)
+            if (!gtk_check_version(2, 12, 0))
+            {
+                gtk_tool_item_set_tooltip_text(tool->m_item,
+                    wxGTK_CONV(helpString));
+            }
+            else
+#endif
+            {
+                gtk_tool_item_set_tooltip(tool->m_item,
+                    m_tooltips, wxGTK_CONV(helpString), "");
+            }
         }
     }
 }
@@ -689,59 +747,6 @@ void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap )
     }
 }
 
-// ----------------------------------------------------------------------------
-// wxToolBar idle handling
-// ----------------------------------------------------------------------------
-
-void wxToolBar::OnInternalIdle()
-{
-    // Check if we have to show window now
-    if (GTKShowFromOnIdle()) return;
-
-    wxCursor cursor = m_cursor;
-    if (g_globalCursor.Ok()) cursor = g_globalCursor;
-
-    if (cursor.Ok())
-    {
-        /* I now set the cursor the anew in every OnInternalIdle call
-           as setting the cursor in a parent window also effects the
-           windows above so that checking for the current cursor is
-           not possible. */
-
-        if (HasFlag(wxTB_DOCKABLE) && (m_widget->window))
-        {
-            /* if the toolbar is dockable, then m_widget stands for the
-               GtkHandleBox widget, which uses its own window so that we
-               can set the cursor for it. if the toolbar is not dockable,
-               m_widget comes from m_toolbar which uses its parent's
-               window ("windowless windows") and thus we cannot set the
-               cursor. */
-            gdk_window_set_cursor( m_widget->window, cursor.GetCursor() );
-        }
-
-        wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
-        while ( node )
-        {
-            wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
-            node = node->GetNext();
-
-            if (tool->m_item)
-            {
-                GdkWindow* window = GTK_WIDGET(tool->m_item)->window;
-
-                if ( window )
-                {
-                    gdk_window_set_cursor( window, cursor.GetCursor() );
-                }
-            }
-        }
-    }
-
-    if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
-        UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
-}
-
-
 // ----------------------------------------------------------------------------
 
 // static