]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/toolbar.cpp
updated setup.h for OpenVMS
[wxWidgets.git] / src / gtk / toolbar.cpp
index b25f775019f4743eeb74771cd5bc9ee1f682d005..6897592dd9449340629062169aaae3feec632451 100644 (file)
@@ -15,7 +15,9 @@
 
 #include "wx/toolbar.h"
 
 
 #include "wx/toolbar.h"
 
+#include <gtk/gtk.h>
 #include "wx/gtk/private.h"
 #include "wx/gtk/private.h"
+#include "wx/gtk/private/gtk2-compat.h"
 
 // ----------------------------------------------------------------------------
 // globals
 
 // ----------------------------------------------------------------------------
 // globals
@@ -168,40 +170,37 @@ enter_notify_event(GtkWidget*, GdkEventCrossing* event, wxToolBarTool* tool)
 }
 }
 
 }
 }
 
-//-----------------------------------------------------------------------------
-// "size_request" from m_toolbar
-//-----------------------------------------------------------------------------
-
-extern "C" {
-static void
-size_request(GtkWidget*, GtkRequisition* req, wxToolBar* win)
-{
-    const wxSize margins = win->GetMargins();
-    req->width  += margins.x;
-    req->height += 2 * margins.y;
-}
-}
-
 //-----------------------------------------------------------------------------
 // "expose_event" from GtkImage inside m_item
 //-----------------------------------------------------------------------------
 
 extern "C" {
 static gboolean
 //-----------------------------------------------------------------------------
 // "expose_event" from GtkImage inside m_item
 //-----------------------------------------------------------------------------
 
 extern "C" {
 static gboolean
+#ifdef __WXGTK3__
+image_draw(GtkWidget* widget, cairo_t* cr, wxToolBarTool* tool)
+#else
 image_expose_event(GtkWidget* widget, GdkEventExpose*, wxToolBarTool* tool)
 image_expose_event(GtkWidget* widget, GdkEventExpose*, wxToolBarTool* tool)
+#endif
 {
     const wxBitmap& bitmap = tool->GetDisabledBitmap();
     if (tool->IsEnabled() || !bitmap.IsOk())
         return false;
 
     // draw disabled bitmap ourselves, GtkImage has no way to specify it
 {
     const wxBitmap& bitmap = tool->GetDisabledBitmap();
     if (tool->IsEnabled() || !bitmap.IsOk())
         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);
+    const int x = alloc.x + (alloc.width - req.width) / 2;
+    const int y = alloc.y + (alloc.height - req.height) / 2;
+#ifdef __WXGTK3__
+    bitmap.Draw(cr, x, y);
+#else
     gdk_draw_pixbuf(
     gdk_draw_pixbuf(
-        widget->window, widget->style->black_gc, bitmap.GetPixbuf(),
-        0, 0,
-        alloc.x + (alloc.width - widget->requisition.width) / 2,
-        alloc.y + (alloc.height - widget->requisition.height) / 2,
+        gtk_widget_get_window(widget), gtk_widget_get_style(widget)->black_gc, bitmap.GetPixbuf(),
+        0, 0, x, y,
         -1, -1, GDK_RGB_DITHER_NORMAL, 0, 0);
         -1, -1, GDK_RGB_DITHER_NORMAL, 0, 0);
+#endif
     return true;
 }
 }
     return true;
 }
 }
@@ -250,7 +249,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
     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 +283,7 @@ void wxToolBarTool::CreateDropDown()
         box = gtk_hbox_new(false, 0);
         arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_NONE);
     }
         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),
     gtk_widget_reparent(tool_button, box);
     GtkWidget* arrow_button = gtk_toggle_button_new();
     gtk_button_set_relief(GTK_BUTTON(arrow_button),
@@ -308,7 +307,8 @@ void wxToolBarTool::ShowDropdown(GtkToggleButton* button)
         wxMenu* menu = GetDropdownMenu();
         if (menu)
         {
         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))
             int x = alloc.x;
             int y = alloc.y;
             if (toolbar->HasFlag(wxTB_LEFT | wxTB_RIGHT))
@@ -351,11 +351,13 @@ void wxToolBar::Init()
 
 wxToolBar::~wxToolBar()
 {
 
 wxToolBar::~wxToolBar()
 {
+#ifndef __WXGTK3__
     if (m_tooltips) // always NULL if GTK >= 2.12
     {
         gtk_object_destroy(GTK_OBJECT(m_tooltips));
         g_object_unref(m_tooltips);
     }
     if (m_tooltips) // always NULL if GTK >= 2.12
     {
         gtk_object_destroy(GTK_OBJECT(m_tooltips));
         g_object_unref(m_tooltips);
     }
+#endif
 }
 
 bool wxToolBar::Create( wxWindow *parent,
 }
 
 bool wxToolBar::Create( wxWindow *parent,
@@ -376,12 +378,14 @@ bool wxToolBar::Create( wxWindow *parent,
     FixupStyle();
 
     m_toolbar = GTK_TOOLBAR( gtk_toolbar_new() );
     FixupStyle();
 
     m_toolbar = GTK_TOOLBAR( gtk_toolbar_new() );
+#ifndef __WXGTK3__
     if (gtk_check_version(2, 12, 0))
     {
         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));
     }
+#endif
     GtkSetStyle();
 
     if (style & wxTB_DOCKABLE)
     GtkSetStyle();
 
     if (style & wxTB_DOCKABLE)
@@ -409,15 +413,12 @@ bool wxToolBar::Create( wxWindow *parent,
 
     PostCreation(size);
 
 
     PostCreation(size);
 
-    g_signal_connect_after(m_toolbar, "size_request",
-        G_CALLBACK(size_request), this);
-
     return true;
 }
 
 GdkWindow *wxToolBar::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const
 {
     return true;
 }
 
 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()
 }
 
 void wxToolBar::GtkSetStyle()
@@ -436,7 +437,11 @@ void wxToolBar::GtkSetStyle()
             style = GTK_TOOLBAR_BOTH_HORIZ;
     }
 
             style = GTK_TOOLBAR_BOTH_HORIZ;
     }
 
+#ifdef __WXGTK3__
+    gtk_orientable_set_orientation(GTK_ORIENTABLE(m_toolbar), orient);
+#else
     gtk_toolbar_set_orientation(m_toolbar, orient);
     gtk_toolbar_set_orientation(m_toolbar, orient);
+#endif
     gtk_toolbar_set_style(m_toolbar, style);
 }
 
     gtk_toolbar_set_style(m_toolbar, style);
 }
 
@@ -479,6 +484,7 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
     wxToolBarTool* tool = static_cast<wxToolBarTool*>(toolBase);
 
     GSList* radioGroup;
     wxToolBarTool* tool = static_cast<wxToolBarTool*>(toolBase);
 
     GSList* radioGroup;
+    GtkWidget* bin_child;
     switch ( tool->GetStyle() )
     {
         case wxTOOL_STYLE_BUTTON:
     switch ( tool->GetStyle() )
     {
         case wxTOOL_STYLE_BUTTON:
@@ -491,7 +497,7 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
                     break;
                 case wxITEM_RADIO:
                     radioGroup = GetRadioGroup(pos);
                     break;
                 case wxITEM_RADIO:
                     radioGroup = GetRadioGroup(pos);
-                    if (radioGroup)
+                    if (!radioGroup)
                     {
                         // this is the first button in the radio button group,
                         // it will be toggled automatically by GTK so bring the
                     {
                         // this is the first button in the radio button group,
                         // it will be toggled automatically by GTK so bring the
@@ -519,8 +525,13 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
                     GTK_TOOL_BUTTON(tool->m_item), image);
                 tool->SetImage();
                 gtk_widget_show(image);
                     GTK_TOOL_BUTTON(tool->m_item), image);
                 tool->SetImage();
                 gtk_widget_show(image);
+#ifdef __WXGTK3__
+                g_signal_connect(image, "draw",
+                    G_CALLBACK(image_draw), tool);
+#else
                 g_signal_connect(image, "expose_event",
                     G_CALLBACK(image_expose_event), tool);
                 g_signal_connect(image, "expose_event",
                     G_CALLBACK(image_expose_event), tool);
+#endif
             }
             if (!tool->GetLabel().empty())
             {
             }
             if (!tool->GetLabel().empty())
             {
@@ -532,7 +543,7 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
             if (!HasFlag(wxTB_NO_TOOLTIPS) && !tool->GetShortHelp().empty())
             {
 #if GTK_CHECK_VERSION(2, 12, 0)
             if (!HasFlag(wxTB_NO_TOOLTIPS) && !tool->GetShortHelp().empty())
             {
 #if GTK_CHECK_VERSION(2, 12, 0)
-                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()));
                 {
                     gtk_tool_item_set_tooltip_text(tool->m_item,
                         wxGTK_CONV(tool->GetShortHelp()));
@@ -540,15 +551,18 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
                 else
 #endif
                 {
                 else
 #endif
                 {
+#ifndef __WXGTK3__
                     gtk_tool_item_set_tooltip(tool->m_item,
                         m_tooltips, wxGTK_CONV(tool->GetShortHelp()), "");
                     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_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_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)
                 G_CALLBACK(enter_notify_event), tool);
 
             if (tool->GetKind() == wxITEM_DROPDOWN)
@@ -572,9 +586,9 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
 
         case wxTOOL_STYLE_CONTROL:
             wxWindow* control = tool->GetControl();
 
         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);
                 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);
             if (gtk_toolbar_get_item_index(m_toolbar, tool->m_item) != int(pos))
             {
                 g_object_ref(tool->m_item);
@@ -583,12 +597,6 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
                 gtk_toolbar_insert(m_toolbar, tool->m_item, int(pos));
                 g_object_unref(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
-            // first of these size events.
-            const wxSize size = control->GetSize();
-            gtk_widget_set_size_request(control->m_widget, size.x, size.y);
             break;
     }
     gtk_widget_show(GTK_WIDGET(tool->m_item));
             break;
     }
     gtk_widget_show(GTK_WIDGET(tool->m_item));
@@ -609,9 +617,9 @@ 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;
         // 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));
+    gtk_widget_destroy(GTK_WIDGET(tool->m_item));
     tool->m_item = NULL;
 
     InvalidateBestSize();
     tool->m_item = NULL;
 
     InvalidateBestSize();
@@ -709,7 +717,7 @@ void wxToolBar::SetToolShortHelp( int id, const wxString& helpString )
         if (tool->m_item)
         {
 #if GTK_CHECK_VERSION(2, 12, 0)
         if (tool->m_item)
         {
 #if GTK_CHECK_VERSION(2, 12, 0)
-            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));
             {
                 gtk_tool_item_set_tooltip_text(tool->m_item,
                     wxGTK_CONV(helpString));
@@ -717,8 +725,10 @@ void wxToolBar::SetToolShortHelp( int id, const wxString& helpString )
             else
 #endif
             {
             else
 #endif
             {
+#ifndef __WXGTK3__
                 gtk_tool_item_set_tooltip(tool->m_item,
                     m_tooltips, wxGTK_CONV(helpString), "");
                 gtk_tool_item_set_tooltip(tool->m_item,
                     m_tooltips, wxGTK_CONV(helpString), "");
+#endif
             }
         }
     }
             }
         }
     }
@@ -747,20 +757,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;
-
-    if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
-        UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
-}
-
-
 // ----------------------------------------------------------------------------
 
 // static
 // ----------------------------------------------------------------------------
 
 // static