#include <gtk/gtk.h>
#include "wx/gtk/private/string.h"
+#include "wx/gtk/private/compat.h"
// pango_version_check symbol is quite recent ATM (4/2007)... so we
// use our own wrapper which implements a smart trick.
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// Name: wx/gtk/private/compat.h
+// Purpose: Compatibility code for older GTK+ versions
+// Author: Vaclav Slavik
+// Created: 2011-03-25
+// RCS-ID: $Id$
+// Copyright: (c) 2011 Vaclav Slavik <vslavik@fastmail.fm>
+// Licence: wxWindows licence
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef _WX_GTK_PRIVATE_COMPAT_H_
+#define _WX_GTK_PRIVATE_COMPAT_H_
+
+// ----------------------------------------------------------------------------
+// Implementations of new accessors for older GTK+ versions
+// ----------------------------------------------------------------------------
+
+// GTK+ deprecated direct access to struct members and some other stuff,
+// replacing them with simple accessor functions. These aren't available in
+// older versions, though, so we have to provide them for compatibility.
+//
+// Note: wx_ prefix is used to avoid symbol conflicts at runtime
+
+
+#if !GTK_CHECK_VERSION(2,18,0)
+ inline gboolean wx_gtk_widget_get_has_window(GtkWidget *widget)
+ {
+ return !GTK_WIDGET_NO_WINDOW(widget);
+ }
+ #define gtk_widget_get_has_window wx_gtk_widget_get_has_window
+#endif
+
+
+#if !GTK_CHECK_VERSION(2,18,0)
+ inline gboolean wx_gtk_widget_get_has_grab(GtkWidget *widget)
+ {
+ return GTK_WIDGET_HAS_GRAB(widget);
+ }
+ #define gtk_widget_get_has_grab wx_gtk_widget_get_has_grab
+#endif
+
+
+#if !GTK_CHECK_VERSION(2,18,0)
+ inline gboolean wx_gtk_widget_get_visible(GtkWidget *widget)
+ {
+ return GTK_WIDGET_VISIBLE(widget);
+ }
+ #define gtk_widget_get_visible wx_gtk_widget_get_visible
+#endif
+
+
+#if !GTK_CHECK_VERSION(2,18,0)
+ inline gboolean wx_gtk_widget_get_sensitive(GtkWidget *widget)
+ {
+ return GTK_WIDGET_VISIBLE(widget);
+ }
+ #define gtk_widget_get_sensitive wx_gtk_widget_get_sensitive
+#endif
+
+
+#if !GTK_CHECK_VERSION(2,18,0)
+ inline gboolean wx_gtk_widget_is_drawable(GtkWidget *widget)
+ {
+ return GTK_WIDGET_DRAWABLE(widget);
+ }
+ #define gtk_widget_is_drawable wx_gtk_widget_is_drawable
+#endif
+
+
+#if !GTK_CHECK_VERSION(2,18,0)
+ inline gboolean wx_gtk_widget_get_can_focus(GtkWidget *widget)
+ {
+ return GTK_WIDGET_CAN_FOCUS(widget);
+ }
+ #define gtk_widget_get_can_focus wx_gtk_widget_get_can_focus
+
+ inline void wx_gtk_widset_set_can_focus(GtkWidget *widget, gboolean can)
+ {
+ if ( can )
+ GTK_WIDGET_SET_FLAGS(widget, GTK_CAN_FOCUS);
+ else
+ GTK_WIDGET_UNSET_FLAGS(widget, GTK_CAN_FOCUS);
+ }
+ #define gtk_widset_set_can_focus wx_gtk_widset_set_can_focus
+#endif
+
+
+#if !GTK_CHECK_VERSION(2,18,0)
+ inline gboolean wx_gtk_widget_get_can_default(GtkWidget *widget)
+ {
+ return GTK_WIDGET_CAN_DEFAULT(widget);
+ }
+ #define gtk_widget_get_can_default wx_gtk_widget_get_can_default
+
+ inline void wx_gtk_widget_set_can_default(GtkWidget *widget, gboolean can)
+ {
+ if ( can )
+ GTK_WIDGET_SET_FLAGS(widget, GTK_CAN_DEFAULT);
+ else
+ GTK_WIDGET_UNSET_FLAGS(widget, GTK_CAN_DEFAULT);
+ }
+ #define gtk_widget_set_can_default wx_gtk_widget_set_can_default
+#endif
+
+
+#if !GTK_CHECK_VERSION(2,18,0)
+ inline gboolean wx_gtk_widget_has_default(GtkWidget *widget)
+ {
+ return GTK_WIDGET_HAS_DEFAULT(widget);
+ }
+ #define gtk_widget_has_default wx_gtk_widget_has_default
+#endif
+
+
+#if !GTK_CHECK_VERSION(2,18,0)
+ inline GtkStateType wx_gtk_widget_get_state(GtkWidget *widget)
+ {
+ return GTK_WIDGET_STATE(widget);
+ }
+ #define gtk_widget_get_state wx_gtk_widget_get_state
+#endif
+
+
+#if !GTK_CHECK_VERSION(2,18,0)
+ inline gboolean wx_gtk_widget_get_double_buffered(GtkWidget *widget)
+ {
+ return GTK_WIDGET_DOUBLE_BUFFERED(widget);
+ }
+ #define gtk_widget_get_double_buffered wx_gtk_widget_get_double_buffered
+#endif
+
+
+#if !GTK_CHECK_VERSION(2,20,0)
+ inline gboolean wx_gtk_widget_get_realized(GtkWidget *widget)
+ {
+ return GTK_WIDGET_REALIZED(widget);
+ }
+ #define gtk_widget_get_realized wx_gtk_widget_get_realized
+#endif
+
+
+#if !GTK_CHECK_VERSION(2,20,0)
+ inline gboolean wx_gtk_widget_get_mapped(GtkWidget *widget)
+ {
+ return GTK_WIDGET_MAPPED(widget);
+ }
+ #define gtk_widget_get_mapped wx_gtk_widget_get_mapped
+#endif
+
+
+#endif // _WX_GTK_PRIVATE_COMPAT_H_
+
if (!window) return;
if (!window->m_wxwindow) return;
- if (!GTK_WIDGET_DRAWABLE(window->m_wxwindow)) return;
+ if (!gtk_widget_is_drawable(window->m_wxwindow)) return;
gtk_paint_handle
(
GDK_WINDOW_EDGE_SOUTH_EAST;
gtk_paint_resize_grip( m_widget->style,
GTKGetDrawingWindow(),
- (GtkStateType) GTK_WIDGET_STATE (m_widget),
+ gtk_widget_get_state(m_widget),
NULL,
m_widget,
"statusbar",
{
/* the default button has a border around it */
wxWindow* parent = win->GetParent();
- if (parent && parent->m_wxwindow && GTK_WIDGET_CAN_DEFAULT(widget))
+ if (parent && parent->m_wxwindow && gtk_widget_get_can_default(widget))
{
GtkBorder* border = NULL;
gtk_widget_style_get(widget, "default_border", &border, NULL);
{
wxWindow *oldDefault = wxButtonBase::SetDefault();
- GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
+ gtk_widget_set_can_default(m_widget, TRUE);
gtk_widget_grab_default( m_widget );
// resize for default border
// extra border around it, but we don't want to take it into account in
// our size calculations (otherwise the result is visually ugly), so
// always return the size of non default button from here
- const bool isDefault = GTK_WIDGET_HAS_DEFAULT(m_widget);
+ const bool isDefault = gtk_widget_has_default(m_widget);
if ( isDefault )
{
// temporarily unset default flag
- GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_DEFAULT );
+ gtk_widget_set_can_default(m_widget, FALSE);
}
wxSize ret( wxControl::DoGetBestSize() );
if ( isDefault )
{
// set it back again
- GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
+ gtk_widget_set_can_default(m_widget, TRUE);
}
if (!HasFlag(wxBU_EXACTFIT))
if (m_isConnected)
return;
- if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview))
+ if (gtk_widget_get_realized(GetOwner()->m_treeview))
{
GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
if (column->button)
static void
wxdataview_selection_changed_callback( GtkTreeSelection* WXUNUSED(selection), wxDataViewCtrl *dv )
{
- if (!GTK_WIDGET_REALIZED(dv->m_widget))
+ if (!gtk_widget_get_realized(dv->m_widget))
return;
wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, dv->GetId() );
GtkWidget* treeview = GtkGetTreeView();
// Insert widget in GtkTreeView
- if (GTK_WIDGET_REALIZED(treeview))
+ if (gtk_widget_get_realized(treeview))
gtk_widget_set_parent_window( child->m_widget,
gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview) ) );
gtk_widget_set_parent( child->m_widget, treeview );
wxCHECK_RET(widget, "DC needs a widget");
m_gdkwindow = widget->window;
- if (GTK_WIDGET_NO_WINDOW(widget))
+ if (!gtk_widget_get_has_window(widget))
SetDeviceLocalOrigin(widget->allocation.x, widget->allocation.y);
}
// if our parent window is already visible, we had been realized before we
// connected to the "realize" signal and hence our m_glContext hasn't been
// initialized yet and we have to do it now
- if (GTK_WIDGET_REALIZED(m_wxwindow))
+ if (gtk_widget_get_realized(m_wxwindow))
gtk_glwindow_realized_callback( m_wxwindow, this );
#endif // WXWIN_COMPATIBILITY_2_8
- if (GTK_WIDGET_MAPPED(m_wxwindow))
+ if (gtk_widget_get_mapped(m_wxwindow))
gtk_glwindow_map_callback( m_wxwindow, this );
return true;
wxCHECK_RET( IsValid(n), wxT("invalid index"));
//RN: I have no idea why this line is needed...
- if (gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_GRAB (m_treeview))
+ if (gdk_pointer_is_grabbed () && gtk_widget_has_grab(GTK_WIDGET(m_treeview)))
return;
GtkTreeIter iter;
// don't use GTK_WIDGET_IS_SENSITIVE() here, we want to return true even if
// the parent radiobox is disabled
- return GTK_WIDGET_SENSITIVE(GTK_WIDGET(button));
+ return gtk_widget_is_sensitive(GTK_WIDGET(button));
}
bool wxRadioBox::Show(unsigned int item, bool show)
GtkButton *button = GTK_BUTTON( node->GetData()->button );
- return GTK_WIDGET_VISIBLE(GTK_WIDGET(button));
+ return gtk_widget_get_visible(GTK_WIDGET(button));
}
unsigned int wxRadioBox::GetCount() const
int wxSystemSettingsNative::GetMetric( wxSystemMetric index, wxWindow* win )
{
GdkWindow *window = NULL;
- if(win && GTK_WIDGET_REALIZED(win->GetHandle()))
+ if(win && gtk_widget_get_realized(win->GetHandle()))
window = win->GetHandle()->window;
switch (index)
gtk_widget_add_events( GTK_WIDGET(m_text), GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK );
- GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
+ gtk_widget_set_can_focus(m_widget, FALSE);
}
else
{
static void wxgtk_window_set_urgency_hint (GtkWindow *win,
gboolean setting)
{
- wxASSERT_MSG( GTK_WIDGET_REALIZED(win), wxT("wxgtk_window_set_urgency_hint: GdkWindow not realized") );
+ wxASSERT_MSG( gtk_widget_get_realized(GTK_WIDGET(win)),
+ wxT("wxgtk_window_set_urgency_hint: GdkWindow not realized") );
GdkWindow *window = GTK_WIDGET(win)->window;
XWMHints *wm_hints;
else
m_gdkFunc &= ~GDK_FUNC_CLOSE;
- if (GTK_WIDGET_REALIZED(m_widget) && (m_widget->window))
+ if (gtk_widget_get_realized(m_widget) && (m_widget->window))
gdk_window_set_functions( m_widget->window, (GdkWMFunction)m_gdkFunc );
return true;
bool deferShow = show && !m_isShown && m_deferShow;
if (deferShow)
{
- deferShow = m_deferShowAllowed && !GTK_WIDGET_REALIZED(m_widget);
+ deferShow = m_deferShowAllowed && !gtk_widget_get_realized(m_widget);
if (deferShow)
{
deferShow = g_signal_handler_find(m_widget,
return true;
}
- if (show && !GTK_WIDGET_REALIZED(m_widget))
+ if (show && !gtk_widget_get_realized(m_widget))
{
// size_allocate signals occur in reverse order (bottom to top).
// Things work better if the initial wxSizeEvents are sent (from the
// Setting icons before window is realized can cause a GTK assertion if
// another TLW is realized before this one, and it has this one as it's
// transient parent. The life demo exibits this problem.
- if (GTK_WIDGET_REALIZED(m_widget))
+ if (gtk_widget_get_realized(m_widget))
{
GList* list = NULL;
for (size_t i = icons.GetIconCount(); i--;)
wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), false,
wxT("Shaped windows must be created with the wxFRAME_SHAPED style."));
- if ( GTK_WIDGET_REALIZED(m_widget) )
+ if ( gtk_widget_get_realized(m_widget) )
{
if ( m_wxwindow )
do_shape_combine_region(m_wxwindow->window, region);
m_urgency_hint = -2;
- if( GTK_WIDGET_REALIZED(m_widget) && !IsActive() )
+ if( gtk_widget_get_realized(m_widget) && !IsActive() )
{
new_hint_value = true;
int w = alloc->width - 2 * border_x;
if (w < 0) w = 0;
- if (GTK_WIDGET_REALIZED(widget) && (is_move || is_resize))
+ if (gtk_widget_get_realized(widget) && (is_move || is_resize))
{
int h = alloc->height - 2 * border_y;
if (h < 0) h = 0;
for (const GList* list = pizza->m_fixed.children; list; list = list->next)
{
const GtkFixedChild* child = static_cast<GtkFixedChild*>(list->data);
- if (GTK_WIDGET_VISIBLE(child->widget))
+ if (gtk_widget_get_visible(child->widget))
{
GtkAllocation child_alloc;
// note that child positions do not take border into
pizza->m_is_scrollable = (windowStyle & (wxHSCROLL | wxVSCROLL)) != 0;
// mask off border styles not useable with wxPizza
pizza->m_border_style = int(windowStyle & BORDER_STYLES);
+#if GTK_CHECK_VERSION(2,20,0)
+ gtk_widget_set_has_window(widget, true);
+#else
gtk_fixed_set_has_window(GTK_FIXED(widget), true);
+#endif
gtk_widget_add_events(widget,
GDK_EXPOSURE_MASK |
GDK_SCROLL_MASK |
GtkRange *range = win->m_scrollBar[wxWindow::ScrollDir_Horz];
if (!range) return FALSE;
- if (range && GTK_WIDGET_VISIBLE (range))
+ if (range && gtk_widget_get_visible(GTK_WIDGET(range)))
{
GtkAdjustment *adj = range->adjustment;
gdouble delta = adj->step_increment * 3;
GtkRange *range = win->m_scrollBar[wxWindow::ScrollDir_Vert];
if (!range) return FALSE;
- if (range && GTK_WIDGET_VISIBLE (range))
+ if (range && gtk_widget_get_visible(GTK_WIDGET(range)))
{
GtkAdjustment *adj = range->adjustment;
gdouble delta = adj->step_increment * 3;
int bottom_border = 0;
/* the default button has a border around it */
- if (GTK_WIDGET_CAN_DEFAULT(m_widget))
+ if (gtk_widget_get_can_default(m_widget))
{
GtkBorder *default_border = NULL;
gtk_widget_style_get( m_widget, "default_border", &default_border, NULL );
bool wxWindowGTK::GTKShowFromOnIdle()
{
- if (IsShown() && m_showOnIdle && !GTK_WIDGET_VISIBLE (m_widget))
+ if (IsShown() && m_showOnIdle && !gtk_widget_get_visible (m_widget))
{
GtkAllocation alloc;
alloc.x = m_x;
if (!m_wxwindow)
{
- if (GTK_WIDGET_NO_WINDOW (m_widget))
+ if (!gtk_widget_get_has_window(m_widget))
{
org_x += m_widget->allocation.x;
org_y += m_widget->allocation.y;
if (!m_wxwindow)
{
- if (GTK_WIDGET_NO_WINDOW (m_widget))
+ if (!gtk_widget_get_has_window(m_widget))
{
org_x += m_widget->allocation.x;
org_y += m_widget->allocation.y;
GtkWidget *widget = m_wxwindow ? m_wxwindow : m_focusWidget;
if ( GTK_IS_CONTAINER(widget) &&
- !GTK_WIDGET_CAN_FOCUS(widget) )
+ !gtk_widget_get_can_focus(widget) )
{
wxLogTrace(TRACE_FOCUS,
wxT("Setting focus to a child of %s(%p, %s)"),
void wxWindowGTK::SetCanFocus(bool canFocus)
{
- if ( canFocus )
- GTK_WIDGET_SET_FLAGS(m_widget, GTK_CAN_FOCUS);
- else
- GTK_WIDGET_UNSET_FLAGS(m_widget, GTK_CAN_FOCUS);
+ gtk_widget_set_can_focus(m_widget, canFocus);
if ( m_wxwindow && (m_widget != m_wxwindow) )
{
- if ( canFocus )
- GTK_WIDGET_SET_FLAGS(m_wxwindow, GTK_CAN_FOCUS);
- else
- GTK_WIDGET_UNSET_FLAGS(m_wxwindow, GTK_CAN_FOCUS);
+ gtk_widget_set_can_focus(m_wxwindow, canFocus);
}
}
if (newParent)
{
- if (GTK_WIDGET_VISIBLE (newParent->m_widget))
+ if (gtk_widget_get_visible (newParent->m_widget))
{
m_showOnIdle = true;
gtk_widget_hide( m_widget );
// widget than m_widget, so if the main widget isn't
// focusable try the connect widget
GtkWidget* w = win->m_widget;
- if ( !GTK_WIDGET_CAN_FOCUS(w) )
+ if ( !gtk_widget_get_can_focus(w) )
{
w = win->GetConnectWidget();
- if ( !GTK_WIDGET_CAN_FOCUS(w) )
+ if ( !gtk_widget_get_can_focus(w) )
w = NULL;
}
// Just return if the widget or one of its ancestors isn't mapped
GtkWidget *w;
for (w = m_wxwindow; w != NULL; w = w->parent)
- if (!GTK_WIDGET_MAPPED (w))
+ if (!gtk_widget_get_mapped (w))
return;
GdkWindow* window = GTKGetDrawingWindow();
void wxWindowGTK::Update()
{
- if (m_widget && GTK_WIDGET_MAPPED(m_widget))
+ if (m_widget && gtk_widget_get_mapped(m_widget))
{
GdkDisplay* display = gtk_widget_get_display(m_widget);
// Flush everything out to the server, and wait for it to finish.
if (!parent)
parent = (wxWindow*)this;
- if (GTK_WIDGET_MAPPED(parent->m_widget))
+ if (gtk_widget_get_mapped(parent->m_widget))
{
wxRegionIterator upd( m_nativeUpdateRegion );
while (upd)
gtk_paint_flat_box( parent->m_widget->style,
GTKGetDrawingWindow(),
- (GtkStateType)GTK_WIDGET_STATE(m_wxwindow),
+ (GtkStateType)gtk_widget_get_state(m_wxwindow),
GTK_SHADOW_NONE,
&rect,
parent->m_widget,
bool wxWindowGTK::IsDoubleBuffered() const
{
- return GTK_WIDGET_DOUBLE_BUFFERED( m_wxwindow );
+ return gtk_widget_get_double_buffered( m_wxwindow );
}
void wxWindowGTK::ClearBackground()
// is realized (and so can be frozen):
static void wx_frozen_widget_realize(GtkWidget* w, wxWindowGTK* win)
{
- wxASSERT( w && !GTK_WIDGET_NO_WINDOW(w) );
- wxASSERT( GTK_WIDGET_REALIZED(w) );
+ wxASSERT( w && gtk_widget_get_has_window(w) );
+ wxASSERT( gtk_widget_get_realized(w) );
g_signal_handlers_disconnect_by_func
(
void wxWindowGTK::GTKFreezeWidget(GtkWidget *w)
{
- if ( !w || GTK_WIDGET_NO_WINDOW(w) )
+ if ( !w || !gtk_widget_get_has_window(w) )
return; // window-less widget, cannot be frozen
- if ( !GTK_WIDGET_REALIZED(w) )
+ if ( !gtk_widget_get_realized(w) )
{
// we can't thaw unrealized widgets because they don't have GdkWindow,
// so set it up to be done immediately after realization:
void wxWindowGTK::GTKThawWidget(GtkWidget *w)
{
- if ( !w || GTK_WIDGET_NO_WINDOW(w) )
+ if ( !w || !gtk_widget_get_has_window(w) )
return; // window-less widget, cannot be frozen
- if ( !GTK_WIDGET_REALIZED(w) )
+ if ( !gtk_widget_get_realized(w) )
{
// the widget wasn't realized yet, no need to thaw
g_signal_handlers_disconnect_by_func