1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/private/compat.h
3 // Purpose: Compatibility code for older GTK+ versions
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2011 Vaclav Slavik <vslavik@fastmail.fm>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_GTK_PRIVATE_COMPAT_H_
12 #define _WX_GTK_PRIVATE_COMPAT_H_
14 // ----------------------------------------------------------------------------
15 // Implementations of new accessors for older GTK+ versions
16 // ----------------------------------------------------------------------------
18 // GTK+ deprecated direct access to struct members and some other stuff,
19 // replacing them with simple accessor functions. These aren't available in
20 // older versions, though, so we have to provide them for compatibility.
22 // Note: wx_ prefix is used to avoid symbol conflicts at runtime
24 // Note 2: We support building against newer GTK+ version and using an older
25 // one at runtime, so we must provide our implementations of these
26 // functions even if GTK_CHECK_VERSION would indicate the function is
27 // already available in GTK+.
31 // ----------------------------------------------------------------------------
32 // the following were introduced in GTK+ 2.8
34 static inline GtkWidget
* wx_gtk_scrolled_window_get_hscrollbar(GtkScrolledWindow
* scrolled_window
)
36 return scrolled_window
->hscrollbar
;
38 #define gtk_scrolled_window_get_hscrollbar wx_gtk_scrolled_window_get_hscrollbar
40 static inline GtkWidget
* wx_gtk_scrolled_window_get_vscrollbar(GtkScrolledWindow
* scrolled_window
)
42 return scrolled_window
->vscrollbar
;
44 #define gtk_scrolled_window_get_vscrollbar wx_gtk_scrolled_window_get_vscrollbar
46 // ----------------------------------------------------------------------------
47 // the following were introduced in GLib 2.10
49 static inline gpointer
wx_g_object_ref_sink(gpointer object
)
52 gtk_object_sink(GTK_OBJECT(object
));
55 #define g_object_ref_sink wx_g_object_ref_sink
57 // ----------------------------------------------------------------------------
58 // the following were introduced in GTK+ 2.12 and GtkAboutDialog itself is not
59 // in 2.4 so skip this if we don't have it.
60 #if GTK_CHECK_VERSION(2,6,0)
62 static inline void wx_gtk_about_dialog_set_program_name(GtkAboutDialog
* about
, const gchar
* name
)
64 gtk_about_dialog_set_name(about
, name
);
66 #define gtk_about_dialog_set_program_name wx_gtk_about_dialog_set_program_name
69 // ----------------------------------------------------------------------------
70 // the following were introduced in GTK+ 2.14
72 static inline gdouble
wx_gtk_adjustment_get_lower(GtkAdjustment
* adjustment
)
74 return adjustment
->lower
;
76 #define gtk_adjustment_get_lower wx_gtk_adjustment_get_lower
78 static inline gdouble
wx_gtk_adjustment_get_page_increment(GtkAdjustment
* adjustment
)
80 return adjustment
->page_increment
;
82 #define gtk_adjustment_get_page_increment wx_gtk_adjustment_get_page_increment
84 static inline gdouble
wx_gtk_adjustment_get_page_size(GtkAdjustment
* adjustment
)
86 return adjustment
->page_size
;
88 #define gtk_adjustment_get_page_size wx_gtk_adjustment_get_page_size
90 static inline gdouble
wx_gtk_adjustment_get_step_increment(GtkAdjustment
* adjustment
)
92 return adjustment
->step_increment
;
94 #define gtk_adjustment_get_step_increment wx_gtk_adjustment_get_step_increment
96 static inline gdouble
wx_gtk_adjustment_get_upper(GtkAdjustment
* adjustment
)
98 return adjustment
->upper
;
100 #define gtk_adjustment_get_upper wx_gtk_adjustment_get_upper
102 static inline void wx_gtk_adjustment_set_page_size(GtkAdjustment
* adjustment
, gdouble page_size
)
104 adjustment
->page_size
= page_size
;
106 #define gtk_adjustment_set_page_size wx_gtk_adjustment_set_page_size
108 static inline GtkWidget
* wx_gtk_color_selection_dialog_get_color_selection(GtkColorSelectionDialog
* csd
)
110 return csd
->colorsel
;
112 #define gtk_color_selection_dialog_get_color_selection wx_gtk_color_selection_dialog_get_color_selection
114 static inline GtkWidget
* wx_gtk_dialog_get_content_area(GtkDialog
* dialog
)
118 #define gtk_dialog_get_content_area wx_gtk_dialog_get_content_area
120 static inline GtkWidget
* wx_gtk_dialog_get_action_area(GtkDialog
* dialog
)
122 return dialog
->action_area
;
124 #define gtk_dialog_get_action_area wx_gtk_dialog_get_action_area
126 static inline guint16
wx_gtk_entry_get_text_length(GtkEntry
* entry
)
128 return entry
->text_length
;
130 #define gtk_entry_get_text_length wx_gtk_entry_get_text_length
132 static inline GtkWidget
* wx_gtk_font_selection_dialog_get_cancel_button(GtkFontSelectionDialog
* fsd
)
134 return fsd
->cancel_button
;
136 #define gtk_font_selection_dialog_get_cancel_button wx_gtk_font_selection_dialog_get_cancel_button
138 static inline GtkWidget
* wx_gtk_font_selection_dialog_get_ok_button(GtkFontSelectionDialog
* fsd
)
140 return fsd
->ok_button
;
142 #define gtk_font_selection_dialog_get_ok_button wx_gtk_font_selection_dialog_get_ok_button
144 static inline const guchar
* wx_gtk_selection_data_get_data(GtkSelectionData
* selection_data
)
146 return selection_data
->data
;
148 #define gtk_selection_data_get_data wx_gtk_selection_data_get_data
150 static inline GdkAtom
wx_gtk_selection_data_get_data_type(GtkSelectionData
* selection_data
)
152 return selection_data
->type
;
154 #define gtk_selection_data_get_data_type wx_gtk_selection_data_get_data_type
156 static inline gint
wx_gtk_selection_data_get_format(GtkSelectionData
* selection_data
)
158 return selection_data
->format
;
160 #define gtk_selection_data_get_format wx_gtk_selection_data_get_format
162 static inline gint
wx_gtk_selection_data_get_length(GtkSelectionData
* selection_data
)
164 return selection_data
->length
;
166 #define gtk_selection_data_get_length wx_gtk_selection_data_get_length
168 static inline GdkAtom
wx_gtk_selection_data_get_target(GtkSelectionData
* selection_data
)
170 return selection_data
->target
;
172 #define gtk_selection_data_get_target wx_gtk_selection_data_get_target
174 static inline GdkWindow
* wx_gtk_widget_get_window(GtkWidget
* widget
)
176 return widget
->window
;
178 #define gtk_widget_get_window wx_gtk_widget_get_window
180 static inline GtkWidget
* wx_gtk_window_get_default_widget(GtkWindow
* window
)
182 return window
->default_widget
;
184 #define gtk_window_get_default_widget wx_gtk_window_get_default_widget
186 // ----------------------------------------------------------------------------
187 // the following were introduced in GTK+ 2.16
189 static inline GdkAtom
wx_gtk_selection_data_get_selection(GtkSelectionData
* selection_data
)
191 return selection_data
->selection
;
193 #define gtk_selection_data_get_selection wx_gtk_selection_data_get_selection
195 // ----------------------------------------------------------------------------
196 // the following were introduced in GTK+ 2.18
198 static inline void wx_gtk_cell_renderer_get_alignment(GtkCellRenderer
* cell
, gfloat
* xalign
, gfloat
* yalign
)
200 *xalign
= cell
->xalign
;
201 *yalign
= cell
->yalign
;
203 #define gtk_cell_renderer_get_alignment wx_gtk_cell_renderer_get_alignment
205 static inline void wx_gtk_cell_renderer_get_padding(GtkCellRenderer
* cell
, gint
* xpad
, gint
* ypad
)
210 #define gtk_cell_renderer_get_padding wx_gtk_cell_renderer_get_padding
212 static inline void wx_gtk_widget_get_allocation(GtkWidget
* widget
, GtkAllocation
* allocation
)
214 *allocation
= widget
->allocation
;
216 #define gtk_widget_get_allocation wx_gtk_widget_get_allocation
218 inline gboolean
wx_gtk_widget_get_has_window(GtkWidget
*widget
)
220 return !GTK_WIDGET_NO_WINDOW(widget
);
222 #define gtk_widget_get_has_window wx_gtk_widget_get_has_window
225 inline gboolean
wx_gtk_widget_get_has_grab(GtkWidget
*widget
)
227 return GTK_WIDGET_HAS_GRAB(widget
);
229 #define gtk_widget_get_has_grab wx_gtk_widget_get_has_grab
232 inline gboolean
wx_gtk_widget_get_visible(GtkWidget
*widget
)
234 return GTK_WIDGET_VISIBLE(widget
);
236 #define gtk_widget_get_visible wx_gtk_widget_get_visible
239 inline gboolean
wx_gtk_widget_get_sensitive(GtkWidget
*widget
)
241 return GTK_WIDGET_SENSITIVE(widget
);
243 #define gtk_widget_get_sensitive wx_gtk_widget_get_sensitive
246 inline gboolean
wx_gtk_widget_is_drawable(GtkWidget
*widget
)
248 return GTK_WIDGET_DRAWABLE(widget
);
250 #define gtk_widget_is_drawable wx_gtk_widget_is_drawable
253 inline gboolean
wx_gtk_widget_get_can_focus(GtkWidget
*widget
)
255 return GTK_WIDGET_CAN_FOCUS(widget
);
257 #define gtk_widget_get_can_focus wx_gtk_widget_get_can_focus
259 inline void wx_gtk_widget_set_can_focus(GtkWidget
*widget
, gboolean can
)
262 GTK_WIDGET_SET_FLAGS(widget
, GTK_CAN_FOCUS
);
264 GTK_WIDGET_UNSET_FLAGS(widget
, GTK_CAN_FOCUS
);
266 #define gtk_widget_set_can_focus wx_gtk_widget_set_can_focus
269 inline gboolean
wx_gtk_widget_get_can_default(GtkWidget
*widget
)
271 return GTK_WIDGET_CAN_DEFAULT(widget
);
273 #define gtk_widget_get_can_default wx_gtk_widget_get_can_default
275 inline void wx_gtk_widget_set_can_default(GtkWidget
*widget
, gboolean can
)
278 GTK_WIDGET_SET_FLAGS(widget
, GTK_CAN_DEFAULT
);
280 GTK_WIDGET_UNSET_FLAGS(widget
, GTK_CAN_DEFAULT
);
282 #define gtk_widget_set_can_default wx_gtk_widget_set_can_default
285 inline gboolean
wx_gtk_widget_has_default(GtkWidget
*widget
)
287 return GTK_WIDGET_HAS_DEFAULT(widget
);
289 #define gtk_widget_has_default wx_gtk_widget_has_default
292 inline GtkStateType
wx_gtk_widget_get_state(GtkWidget
*widget
)
294 return (GtkStateType
)GTK_WIDGET_STATE(widget
);
296 #define gtk_widget_get_state wx_gtk_widget_get_state
299 inline gboolean
wx_gtk_widget_get_double_buffered(GtkWidget
*widget
)
301 return GTK_WIDGET_DOUBLE_BUFFERED(widget
);
303 #define gtk_widget_get_double_buffered wx_gtk_widget_get_double_buffered
305 static inline gboolean
wx_gtk_widget_has_grab(GtkWidget
* widget
)
307 return GTK_WIDGET_HAS_GRAB(widget
);
309 #define gtk_widget_has_grab wx_gtk_widget_has_grab
311 static inline void wx_gtk_widget_set_allocation(GtkWidget
* widget
, const GtkAllocation
* allocation
)
313 widget
->allocation
= *allocation
;
315 #define gtk_widget_set_allocation wx_gtk_widget_set_allocation
317 // ----------------------------------------------------------------------------
318 // the following were introduced in GTK+ 2.20
320 inline gboolean
wx_gtk_widget_get_realized(GtkWidget
*widget
)
322 return GTK_WIDGET_REALIZED(widget
);
324 #define gtk_widget_get_realized wx_gtk_widget_get_realized
327 inline gboolean
wx_gtk_widget_get_mapped(GtkWidget
*widget
)
329 return GTK_WIDGET_MAPPED(widget
);
331 #define gtk_widget_get_mapped wx_gtk_widget_get_mapped
333 static inline void wx_gtk_widget_get_requisition(GtkWidget
* widget
, GtkRequisition
* requisition
)
335 *requisition
= widget
->requisition
;
337 #define gtk_widget_get_requisition wx_gtk_widget_get_requisition
339 static inline GdkWindow
* wx_gtk_entry_get_text_window(GtkEntry
* entry
)
341 return entry
->text_area
;
343 #define gtk_entry_get_text_window wx_gtk_entry_get_text_window
345 // ----------------------------------------------------------------------------
346 // the following were introduced in GTK+ 2.22
348 static inline GdkWindow
* wx_gtk_button_get_event_window(GtkButton
* button
)
350 return button
->event_window
;
352 #define gtk_button_get_event_window wx_gtk_button_get_event_window
354 static inline GdkDragAction
wx_gdk_drag_context_get_actions(GdkDragContext
* context
)
356 return context
->actions
;
358 #define gdk_drag_context_get_actions wx_gdk_drag_context_get_actions
360 static inline GdkDragAction
wx_gdk_drag_context_get_selected_action(GdkDragContext
* context
)
362 return context
->action
;
364 #define gdk_drag_context_get_selected_action wx_gdk_drag_context_get_selected_action
366 static inline GdkDragAction
wx_gdk_drag_context_get_suggested_action(GdkDragContext
* context
)
368 return context
->suggested_action
;
370 #define gdk_drag_context_get_suggested_action wx_gdk_drag_context_get_suggested_action
372 static inline GList
* wx_gdk_drag_context_list_targets(GdkDragContext
* context
)
374 return context
->targets
;
376 #define gdk_drag_context_list_targets wx_gdk_drag_context_list_targets
378 static inline gint
wx_gdk_visual_get_depth(GdkVisual
* visual
)
380 return visual
->depth
;
382 #define gdk_visual_get_depth wx_gdk_visual_get_depth
384 static inline gboolean
wx_gtk_window_has_group(GtkWindow
* window
)
386 return window
->group
!= NULL
;
388 #define gtk_window_has_group wx_gtk_window_has_group
390 // ----------------------------------------------------------------------------
391 // the following were introduced in GTK+ 2.24
393 static inline GdkDisplay
* wx_gdk_window_get_display(GdkWindow
* window
)
395 return gdk_drawable_get_display(window
);
397 #define gdk_window_get_display wx_gdk_window_get_display
399 static inline GdkScreen
* wx_gdk_window_get_screen(GdkWindow
* window
)
401 return gdk_drawable_get_screen(window
);
403 #define gdk_window_get_screen wx_gdk_window_get_screen
405 static inline gint
wx_gdk_window_get_height(GdkWindow
* window
)
408 gdk_drawable_get_size(window
, NULL
, &h
);
411 #define gdk_window_get_height wx_gdk_window_get_height
413 static inline gint
wx_gdk_window_get_width(GdkWindow
* window
)
416 gdk_drawable_get_size(window
, &w
, NULL
);
419 #define gdk_window_get_width wx_gdk_window_get_width
421 #if GTK_CHECK_VERSION(2,10,0)
422 static inline void wx_gdk_cairo_set_source_window(cairo_t
* cr
, GdkWindow
* window
, gdouble x
, gdouble y
)
424 gdk_cairo_set_source_pixmap(cr
, window
, x
, y
);
426 #define gdk_cairo_set_source_window wx_gdk_cairo_set_source_window
429 // ----------------------------------------------------------------------------
430 // the following were introduced in GTK+ 3.0
432 static inline void wx_gdk_window_get_geometry(GdkWindow
* window
, gint
* x
, gint
* y
, gint
* width
, gint
* height
)
434 gdk_window_get_geometry(window
, x
, y
, width
, height
, NULL
);
436 #define gdk_window_get_geometry wx_gdk_window_get_geometry
438 static inline GtkWidget
* wx_gtk_tree_view_column_get_button(GtkTreeViewColumn
* tree_column
)
440 return tree_column
->button
;
442 #define gtk_tree_view_column_get_button wx_gtk_tree_view_column_get_button
444 static inline GtkWidget
* wx_gtk_box_new(GtkOrientation orientation
, gint spacing
)
447 if (orientation
== GTK_ORIENTATION_HORIZONTAL
)
448 widget
= gtk_hbox_new(false, spacing
);
450 widget
= gtk_vbox_new(false, spacing
);
453 #define gtk_box_new wx_gtk_box_new
455 static inline GtkWidget
* wx_gtk_button_box_new(GtkOrientation orientation
)
458 if (orientation
== GTK_ORIENTATION_HORIZONTAL
)
459 widget
= gtk_hbutton_box_new();
461 widget
= gtk_vbutton_box_new();
464 #define gtk_button_box_new wx_gtk_button_box_new
466 static inline GtkWidget
* wx_gtk_scale_new(GtkOrientation orientation
, GtkAdjustment
* adjustment
)
469 if (orientation
== GTK_ORIENTATION_HORIZONTAL
)
470 widget
= gtk_hscale_new(adjustment
);
472 widget
= gtk_vscale_new(adjustment
);
475 #define gtk_scale_new wx_gtk_scale_new
477 static inline GtkWidget
* wx_gtk_scrollbar_new(GtkOrientation orientation
, GtkAdjustment
* adjustment
)
480 if (orientation
== GTK_ORIENTATION_HORIZONTAL
)
481 widget
= gtk_hscrollbar_new(adjustment
);
483 widget
= gtk_vscrollbar_new(adjustment
);
486 #define gtk_scrollbar_new wx_gtk_scrollbar_new
488 static inline GtkWidget
* wx_gtk_separator_new(GtkOrientation orientation
)
491 if (orientation
== GTK_ORIENTATION_HORIZONTAL
)
492 widget
= gtk_hseparator_new();
494 widget
= gtk_vseparator_new();
497 #define gtk_separator_new wx_gtk_separator_new
499 static inline void wx_gtk_widget_get_preferred_height(GtkWidget
* widget
, gint
* minimum
, gint
* natural
)
502 gtk_widget_size_request(widget
, &req
);
504 *minimum
= req
.height
;
506 *natural
= req
.height
;
508 #define gtk_widget_get_preferred_height wx_gtk_widget_get_preferred_height
510 static inline void wx_gtk_widget_get_preferred_width(GtkWidget
* widget
, gint
* minimum
, gint
* natural
)
513 gtk_widget_size_request(widget
, &req
);
515 *minimum
= req
.width
;
517 *natural
= req
.width
;
519 #define gtk_widget_get_preferred_width wx_gtk_widget_get_preferred_width
521 static inline void wx_gtk_widget_get_preferred_size(GtkWidget
* widget
, GtkRequisition
* minimum
, GtkRequisition
* natural
)
523 GtkRequisition
* req
= minimum
;
526 gtk_widget_size_request(widget
, req
);
528 #define gtk_widget_get_preferred_size wx_gtk_widget_get_preferred_size
530 #endif // !__WXGTK3__
531 #endif // _WX_GTK_PRIVATE_COMPAT_H_