X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/385e8575dd1f9219fb0e3f7fa26ffe4c24d2fdbb..7d6a4d96961eac84d05db8bb24c64d39003f6e54:/src/gtk/toolbar.cpp diff --git a/src/gtk/toolbar.cpp b/src/gtk/toolbar.cpp index 2c2e60441b..6897592dd9 100644 --- a/src/gtk/toolbar.cpp +++ b/src/gtk/toolbar.cpp @@ -15,7 +15,9 @@ #include "wx/toolbar.h" +#include #include "wx/gtk/private.h" +#include "wx/gtk/private/gtk2-compat.h" // ---------------------------------------------------------------------------- // globals @@ -168,27 +170,17 @@ 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 +#ifdef __WXGTK3__ +image_draw(GtkWidget* widget, cairo_t* cr, wxToolBarTool* tool) +#else image_expose_event(GtkWidget* widget, GdkEventExpose*, wxToolBarTool* tool) +#endif { const wxBitmap& bitmap = tool->GetDisabledBitmap(); if (tool->IsEnabled() || !bitmap.IsOk()) @@ -199,12 +191,16 @@ image_expose_event(GtkWidget* widget, GdkEventExpose*, wxToolBarTool* tool) 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( gtk_widget_get_window(widget), gtk_widget_get_style(widget)->black_gc, bitmap.GetPixbuf(), - 0, 0, - alloc.x + (alloc.width - req.width) / 2, - alloc.y + (alloc.height - req.height) / 2, + 0, 0, x, y, -1, -1, GDK_RGB_DITHER_NORMAL, 0, 0); +#endif return true; } } @@ -312,7 +308,7 @@ void wxToolBarTool::ShowDropdown(GtkToggleButton* button) if (menu) { GtkAllocation alloc; - gtk_widget_set_allocation(GTK_WIDGET(button), &alloc); + gtk_widget_get_allocation(GTK_WIDGET(button), &alloc); int x = alloc.x; int y = alloc.y; if (toolbar->HasFlag(wxTB_LEFT | wxTB_RIGHT)) @@ -355,11 +351,13 @@ void wxToolBar::Init() 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); } +#endif } bool wxToolBar::Create( wxWindow *parent, @@ -380,7 +378,7 @@ bool wxToolBar::Create( wxWindow *parent, FixupStyle(); m_toolbar = GTK_TOOLBAR( gtk_toolbar_new() ); -#if !GTK_CHECK_VERSION(3,0,0) && !defined(GTK_DISABLE_DEPRECATED) +#ifndef __WXGTK3__ if (gtk_check_version(2, 12, 0)) { m_tooltips = gtk_tooltips_new(); @@ -415,9 +413,6 @@ bool wxToolBar::Create( wxWindow *parent, PostCreation(size); - g_signal_connect_after(m_toolbar, "size_request", - G_CALLBACK(size_request), this); - return true; } @@ -442,7 +437,7 @@ void wxToolBar::GtkSetStyle() style = GTK_TOOLBAR_BOTH_HORIZ; } -#if GTK_CHECK_VERSION(3,0,0) || defined(GTK_DISABLE_DEPRECATED) +#ifdef __WXGTK3__ gtk_orientable_set_orientation(GTK_ORIENTABLE(m_toolbar), orient); #else gtk_toolbar_set_orientation(m_toolbar, orient); @@ -502,7 +497,7 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase) 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 @@ -530,8 +525,13 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase) 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); +#endif } if (!tool->GetLabel().empty()) { @@ -551,7 +551,7 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase) else #endif { -#if !GTK_CHECK_VERSION(3,0,0) && !defined(GTK_DISABLE_DEPRECATED) +#ifndef __WXGTK3__ gtk_tool_item_set_tooltip(tool->m_item, m_tooltips, wxGTK_CONV(tool->GetShortHelp()), ""); #endif @@ -597,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); } - // 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)); @@ -625,7 +619,7 @@ bool wxToolBar::DoDeleteTool(size_t /* pos */, wxToolBarToolBase* toolBase) GtkWidget* widget = tool->GetControl()->m_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(); @@ -731,7 +725,7 @@ void wxToolBar::SetToolShortHelp( int id, const wxString& helpString ) else #endif { -#if !GTK_CHECK_VERSION(3,0,0) && !defined(GTK_DISABLE_DEPRECATED) +#ifndef __WXGTK3__ gtk_tool_item_set_tooltip(tool->m_item, m_tooltips, wxGTK_CONV(helpString), ""); #endif