]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/toolbar.cpp
adding raw_control for osx
[wxWidgets.git] / src / gtk / toolbar.cpp
index 701ec64a8451abc73bbb15df3a939dbc13105ce1..aeb1dff25172ee8db0b14984d4d1d16a0a56373f 100644 (file)
@@ -195,12 +195,15 @@ image_expose_event(GtkWidget* widget, GdkEventExpose*, wxToolBarTool* tool)
         return false;
 
     // draw disabled bitmap ourselves, GtkImage has no way to specify it
-    const GtkAllocation& alloc = widget->allocation;
+    GtkAllocation alloc;
+    gtk_widget_get_allocation(widget, &alloc);
+    GtkRequisition req;
+    gtk_widget_get_requisition(widget, &req);
     gdk_draw_pixbuf(
-        widget->window, widget->style->black_gc, bitmap.GetPixbuf(),
+        gtk_widget_get_window(widget), gtk_widget_get_style(widget)->black_gc, bitmap.GetPixbuf(),
         0, 0,
-        alloc.x + (alloc.width - widget->requisition.width) / 2,
-        alloc.y + (alloc.height - widget->requisition.height) / 2,
+        alloc.x + (alloc.width - req.width) / 2,
+        alloc.y + (alloc.height - req.height) / 2,
         -1, -1, GDK_RGB_DITHER_NORMAL, 0, 0);
     return true;
 }
@@ -250,7 +253,7 @@ void wxToolBar::AddChildGTK(wxWindowGTK* child)
     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);
+    gtk_toolbar_insert(GTK_TOOLBAR(gtk_bin_get_child(GTK_BIN(m_widget))), item, -1);
 }
 
 // ----------------------------------------------------------------------------
@@ -284,7 +287,7 @@ void wxToolBarTool::CreateDropDown()
         box = gtk_hbox_new(false, 0);
         arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_NONE);
     }
-    GtkWidget* tool_button = GTK_BIN(m_item)->child;
+    GtkWidget* tool_button = gtk_bin_get_child(GTK_BIN(m_item));
     gtk_widget_reparent(tool_button, box);
     GtkWidget* arrow_button = gtk_toggle_button_new();
     gtk_button_set_relief(GTK_BUTTON(arrow_button),
@@ -308,7 +311,8 @@ void wxToolBarTool::ShowDropdown(GtkToggleButton* button)
         wxMenu* menu = GetDropdownMenu();
         if (menu)
         {
-            const GtkAllocation& alloc = GTK_WIDGET(button)->allocation;
+            GtkAllocation alloc;
+            gtk_widget_get_allocation(GTK_WIDGET(button), &alloc);
             int x = alloc.x;
             int y = alloc.y;
             if (toolbar->HasFlag(wxTB_LEFT | wxTB_RIGHT))
@@ -351,7 +355,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 +380,14 @@ 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(3,0,0) && !defined(GTK_DISABLE_DEPRECATED)
+    if (gtk_check_version(2, 12, 0))
+    {
+        m_tooltips = gtk_tooltips_new();
+        g_object_ref(m_tooltips);
+        gtk_object_sink(GTK_OBJECT(m_tooltips));
+    }
+#endif
     GtkSetStyle();
 
     if (style & wxTB_DOCKABLE)
@@ -414,7 +423,7 @@ bool wxToolBar::Create( wxWindow *parent,
 
 GdkWindow *wxToolBar::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const
 {
-    return GTK_WIDGET(m_toolbar)->window;
+    return gtk_widget_get_window(GTK_WIDGET(m_toolbar));
 }
 
 void wxToolBar::GtkSetStyle()
@@ -433,7 +442,11 @@ void wxToolBar::GtkSetStyle()
             style = GTK_TOOLBAR_BOTH_HORIZ;
     }
 
+#if GTK_CHECK_VERSION(3,0,0) || defined(GTK_DISABLE_DEPRECATED)
+    gtk_orientable_set_orientation(GTK_ORIENTABLE(m_toolbar), orient);
+#else
     gtk_toolbar_set_orientation(m_toolbar, orient);
+#endif
     gtk_toolbar_set_style(m_toolbar, style);
 }
 
@@ -445,11 +458,38 @@ 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);
 
     GSList* radioGroup;
+    GtkWidget* bin_child;
     switch ( tool->GetStyle() )
     {
         case wxTOOL_STYLE_BUTTON:
@@ -502,14 +542,27 @@ 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(3,0,0) || gtk_check_version(2,12,0) == NULL)
+                {
+                    gtk_tool_item_set_tooltip_text(tool->m_item,
+                        wxGTK_CONV(tool->GetShortHelp()));
+                }
+                else
+#endif
+                {
+#if !GTK_CHECK_VERSION(3,0,0) && !defined(GTK_DISABLE_DEPRECATED)
+                    gtk_tool_item_set_tooltip(tool->m_item,
+                        m_tooltips, wxGTK_CONV(tool->GetShortHelp()), "");
+#endif
+                }
             }
-            g_signal_connect(GTK_BIN(tool->m_item)->child, "button_press_event",
+            bin_child = gtk_bin_get_child(GTK_BIN(tool->m_item));
+            g_signal_connect(bin_child, "button_press_event",
                 G_CALLBACK(button_press_event), tool);
-            g_signal_connect(tool->m_item, "enter_notify_event",
+            g_signal_connect(bin_child, "enter_notify_event",
                 G_CALLBACK(enter_notify_event), tool);
-            g_signal_connect(tool->m_item, "leave_notify_event",
+            g_signal_connect(bin_child, "leave_notify_event",
                 G_CALLBACK(enter_notify_event), tool);
 
             if (tool->GetKind() == wxITEM_DROPDOWN)
@@ -519,14 +572,23 @@ 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;
 
         case wxTOOL_STYLE_CONTROL:
             wxWindow* control = tool->GetControl();
-            if (control->m_widget->parent == NULL)
+            if (gtk_widget_get_parent(control->m_widget) == NULL)
                 AddChildGTK(control);
-            tool->m_item = GTK_TOOL_ITEM(control->m_widget->parent->parent);
+            tool->m_item = GTK_TOOL_ITEM(gtk_widget_get_parent(gtk_widget_get_parent(control->m_widget)));
             if (gtk_toolbar_get_item_index(m_toolbar, tool->m_item) != int(pos))
             {
                 g_object_ref(tool->m_item);
@@ -561,7 +623,7 @@ bool wxToolBar::DoDeleteTool(size_t /* pos */, wxToolBarToolBase* toolBase)
         // while if we're called from DeleteTool() the control will
         // be destroyed when wxToolBarToolBase itself is deleted
         GtkWidget* widget = tool->GetControl()->m_widget;
-        gtk_container_remove(GTK_CONTAINER(widget->parent), widget);
+        gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(widget)), widget);
     }
     gtk_object_destroy(GTK_OBJECT(tool->m_item));
     tool->m_item = NULL;
@@ -660,8 +722,20 @@ 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(3,0,0) || gtk_check_version(2,12,0) == NULL)
+            {
+                gtk_tool_item_set_tooltip_text(tool->m_item,
+                    wxGTK_CONV(helpString));
+            }
+            else
+#endif
+            {
+#if !GTK_CHECK_VERSION(3,0,0) && !defined(GTK_DISABLE_DEPRECATED)
+                gtk_tool_item_set_tooltip(tool->m_item,
+                    m_tooltips, wxGTK_CONV(helpString), "");
+#endif
+            }
         }
     }
 }
@@ -689,59 +763,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