1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/private/compat.h
3 // Purpose: Compatibility code for older GTK+ versions
4 // Author: Vaclav Slavik
6 // Copyright: (c) 2011 Vaclav Slavik <vslavik@fastmail.fm>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_GTK_PRIVATE_COMPAT_H_
11 #define _WX_GTK_PRIVATE_COMPAT_H_
13 // ----------------------------------------------------------------------------
14 // Implementations of new accessors for older GTK+ versions
15 // ----------------------------------------------------------------------------
17 // GTK+ deprecated direct access to struct members and some other stuff,
18 // replacing them with simple accessor functions. These aren't available in
19 // older versions, though, so we have to provide them for compatibility.
21 // Note: wx_ prefix is used to avoid symbol conflicts at runtime
23 // Note 2: We support building against newer GTK+ version and using an older
24 // one at runtime, so we must provide our implementations of these
25 // functions even if GTK_CHECK_VERSION would indicate the function is
26 // already available in GTK+.
30 // ----------------------------------------------------------------------------
31 // the following were introduced in GTK+ 2.8
33 static inline GtkWidget
* wx_gtk_scrolled_window_get_hscrollbar(GtkScrolledWindow
* scrolled_window
)
35 return scrolled_window
->hscrollbar
;
37 #define gtk_scrolled_window_get_hscrollbar wx_gtk_scrolled_window_get_hscrollbar
39 static inline GtkWidget
* wx_gtk_scrolled_window_get_vscrollbar(GtkScrolledWindow
* scrolled_window
)
41 return scrolled_window
->vscrollbar
;
43 #define gtk_scrolled_window_get_vscrollbar wx_gtk_scrolled_window_get_vscrollbar
45 // ----------------------------------------------------------------------------
46 // the following were introduced in GLib 2.10
48 static inline gpointer
wx_g_object_ref_sink(gpointer object
)
51 gtk_object_sink(GTK_OBJECT(object
));
54 #define g_object_ref_sink wx_g_object_ref_sink
56 // ----------------------------------------------------------------------------
57 // the following were introduced in GTK+ 2.12
59 static inline void wx_gtk_about_dialog_set_program_name(GtkAboutDialog
* about
, const gchar
* name
)
61 gtk_about_dialog_set_name(about
, name
);
63 #define gtk_about_dialog_set_program_name wx_gtk_about_dialog_set_program_name
65 // ----------------------------------------------------------------------------
66 // the following were introduced in GTK+ 2.14
68 static inline gdouble
wx_gtk_adjustment_get_lower(GtkAdjustment
* adjustment
)
70 return adjustment
->lower
;
72 #define gtk_adjustment_get_lower wx_gtk_adjustment_get_lower
74 static inline gdouble
wx_gtk_adjustment_get_page_increment(GtkAdjustment
* adjustment
)
76 return adjustment
->page_increment
;
78 #define gtk_adjustment_get_page_increment wx_gtk_adjustment_get_page_increment
80 static inline gdouble
wx_gtk_adjustment_get_page_size(GtkAdjustment
* adjustment
)
82 return adjustment
->page_size
;
84 #define gtk_adjustment_get_page_size wx_gtk_adjustment_get_page_size
86 static inline gdouble
wx_gtk_adjustment_get_step_increment(GtkAdjustment
* adjustment
)
88 return adjustment
->step_increment
;
90 #define gtk_adjustment_get_step_increment wx_gtk_adjustment_get_step_increment
92 static inline gdouble
wx_gtk_adjustment_get_upper(GtkAdjustment
* adjustment
)
94 return adjustment
->upper
;
96 #define gtk_adjustment_get_upper wx_gtk_adjustment_get_upper
98 static inline void wx_gtk_adjustment_set_page_size(GtkAdjustment
* adjustment
, gdouble page_size
)
100 adjustment
->page_size
= page_size
;
102 #define gtk_adjustment_set_page_size wx_gtk_adjustment_set_page_size
104 static inline GtkWidget
* wx_gtk_color_selection_dialog_get_color_selection(GtkColorSelectionDialog
* csd
)
106 return csd
->colorsel
;
108 #define gtk_color_selection_dialog_get_color_selection wx_gtk_color_selection_dialog_get_color_selection
110 static inline GtkWidget
* wx_gtk_dialog_get_content_area(GtkDialog
* dialog
)
114 #define gtk_dialog_get_content_area wx_gtk_dialog_get_content_area
116 static inline GtkWidget
* wx_gtk_dialog_get_action_area(GtkDialog
* dialog
)
118 return dialog
->action_area
;
120 #define gtk_dialog_get_action_area wx_gtk_dialog_get_action_area
122 static inline guint16
wx_gtk_entry_get_text_length(GtkEntry
* entry
)
124 return entry
->text_length
;
126 #define gtk_entry_get_text_length wx_gtk_entry_get_text_length
128 static inline const guchar
* wx_gtk_selection_data_get_data(GtkSelectionData
* selection_data
)
130 return selection_data
->data
;
132 #define gtk_selection_data_get_data wx_gtk_selection_data_get_data
134 static inline GdkAtom
wx_gtk_selection_data_get_data_type(GtkSelectionData
* selection_data
)
136 return selection_data
->type
;
138 #define gtk_selection_data_get_data_type wx_gtk_selection_data_get_data_type
140 static inline gint
wx_gtk_selection_data_get_format(GtkSelectionData
* selection_data
)
142 return selection_data
->format
;
144 #define gtk_selection_data_get_format wx_gtk_selection_data_get_format
146 static inline gint
wx_gtk_selection_data_get_length(GtkSelectionData
* selection_data
)
148 return selection_data
->length
;
150 #define gtk_selection_data_get_length wx_gtk_selection_data_get_length
152 static inline GdkAtom
wx_gtk_selection_data_get_target(GtkSelectionData
* selection_data
)
154 return selection_data
->target
;
156 #define gtk_selection_data_get_target wx_gtk_selection_data_get_target
158 static inline GdkWindow
* wx_gtk_widget_get_window(GtkWidget
* widget
)
160 return widget
->window
;
162 #define gtk_widget_get_window wx_gtk_widget_get_window
164 static inline GtkWidget
* wx_gtk_window_get_default_widget(GtkWindow
* window
)
166 return window
->default_widget
;
168 #define gtk_window_get_default_widget wx_gtk_window_get_default_widget
170 // ----------------------------------------------------------------------------
171 // the following were introduced in GTK+ 2.16
173 static inline GdkAtom
wx_gtk_selection_data_get_selection(GtkSelectionData
* selection_data
)
175 return selection_data
->selection
;
177 #define gtk_selection_data_get_selection wx_gtk_selection_data_get_selection
179 // ----------------------------------------------------------------------------
180 // the following were introduced in GTK+ 2.18
182 static inline void wx_gtk_cell_renderer_get_alignment(GtkCellRenderer
* cell
, gfloat
* xalign
, gfloat
* yalign
)
184 *xalign
= cell
->xalign
;
185 *yalign
= cell
->yalign
;
187 #define gtk_cell_renderer_get_alignment wx_gtk_cell_renderer_get_alignment
189 static inline void wx_gtk_cell_renderer_get_padding(GtkCellRenderer
* cell
, gint
* xpad
, gint
* ypad
)
194 #define gtk_cell_renderer_get_padding wx_gtk_cell_renderer_get_padding
196 static inline void wx_gtk_widget_get_allocation(GtkWidget
* widget
, GtkAllocation
* allocation
)
198 *allocation
= widget
->allocation
;
200 #define gtk_widget_get_allocation wx_gtk_widget_get_allocation
202 inline gboolean
wx_gtk_widget_get_has_window(GtkWidget
*widget
)
204 return !GTK_WIDGET_NO_WINDOW(widget
);
206 #define gtk_widget_get_has_window wx_gtk_widget_get_has_window
209 inline gboolean
wx_gtk_widget_get_has_grab(GtkWidget
*widget
)
211 return GTK_WIDGET_HAS_GRAB(widget
);
213 #define gtk_widget_get_has_grab wx_gtk_widget_get_has_grab
216 inline gboolean
wx_gtk_widget_get_visible(GtkWidget
*widget
)
218 return GTK_WIDGET_VISIBLE(widget
);
220 #define gtk_widget_get_visible wx_gtk_widget_get_visible
223 inline gboolean
wx_gtk_widget_get_sensitive(GtkWidget
*widget
)
225 return GTK_WIDGET_SENSITIVE(widget
);
227 #define gtk_widget_get_sensitive wx_gtk_widget_get_sensitive
230 inline gboolean
wx_gtk_widget_is_drawable(GtkWidget
*widget
)
232 return GTK_WIDGET_DRAWABLE(widget
);
234 #define gtk_widget_is_drawable wx_gtk_widget_is_drawable
237 inline gboolean
wx_gtk_widget_get_can_focus(GtkWidget
*widget
)
239 return GTK_WIDGET_CAN_FOCUS(widget
);
241 #define gtk_widget_get_can_focus wx_gtk_widget_get_can_focus
243 inline void wx_gtk_widget_set_can_focus(GtkWidget
*widget
, gboolean can
)
246 GTK_WIDGET_SET_FLAGS(widget
, GTK_CAN_FOCUS
);
248 GTK_WIDGET_UNSET_FLAGS(widget
, GTK_CAN_FOCUS
);
250 #define gtk_widget_set_can_focus wx_gtk_widget_set_can_focus
253 inline gboolean
wx_gtk_widget_get_can_default(GtkWidget
*widget
)
255 return GTK_WIDGET_CAN_DEFAULT(widget
);
257 #define gtk_widget_get_can_default wx_gtk_widget_get_can_default
259 inline void wx_gtk_widget_set_can_default(GtkWidget
*widget
, gboolean can
)
262 GTK_WIDGET_SET_FLAGS(widget
, GTK_CAN_DEFAULT
);
264 GTK_WIDGET_UNSET_FLAGS(widget
, GTK_CAN_DEFAULT
);
266 #define gtk_widget_set_can_default wx_gtk_widget_set_can_default
269 inline gboolean
wx_gtk_widget_has_default(GtkWidget
*widget
)
271 return GTK_WIDGET_HAS_DEFAULT(widget
);
273 #define gtk_widget_has_default wx_gtk_widget_has_default
276 inline GtkStateType
wx_gtk_widget_get_state(GtkWidget
*widget
)
278 return (GtkStateType
)GTK_WIDGET_STATE(widget
);
280 #define gtk_widget_get_state wx_gtk_widget_get_state
283 inline gboolean
wx_gtk_widget_get_double_buffered(GtkWidget
*widget
)
285 return GTK_WIDGET_DOUBLE_BUFFERED(widget
);
287 #define gtk_widget_get_double_buffered wx_gtk_widget_get_double_buffered
289 static inline gboolean
wx_gtk_widget_has_grab(GtkWidget
* widget
)
291 return GTK_WIDGET_HAS_GRAB(widget
);
293 #define gtk_widget_has_grab wx_gtk_widget_has_grab
295 static inline void wx_gtk_widget_set_allocation(GtkWidget
* widget
, const GtkAllocation
* allocation
)
297 widget
->allocation
= *allocation
;
299 #define gtk_widget_set_allocation wx_gtk_widget_set_allocation
301 // ----------------------------------------------------------------------------
302 // the following were introduced in GTK+ 2.20
304 inline gboolean
wx_gtk_widget_get_realized(GtkWidget
*widget
)
306 return GTK_WIDGET_REALIZED(widget
);
308 #define gtk_widget_get_realized wx_gtk_widget_get_realized
311 inline gboolean
wx_gtk_widget_get_mapped(GtkWidget
*widget
)
313 return GTK_WIDGET_MAPPED(widget
);
315 #define gtk_widget_get_mapped wx_gtk_widget_get_mapped
317 static inline void wx_gtk_widget_get_requisition(GtkWidget
* widget
, GtkRequisition
* requisition
)
319 *requisition
= widget
->requisition
;
321 #define gtk_widget_get_requisition wx_gtk_widget_get_requisition
323 static inline GdkWindow
* wx_gtk_entry_get_text_window(GtkEntry
* entry
)
325 return entry
->text_area
;
327 #define gtk_entry_get_text_window wx_gtk_entry_get_text_window
329 // ----------------------------------------------------------------------------
330 // the following were introduced in GTK+ 2.22
332 static inline GdkWindow
* wx_gtk_button_get_event_window(GtkButton
* button
)
334 return button
->event_window
;
336 #define gtk_button_get_event_window wx_gtk_button_get_event_window
338 static inline GdkDragAction
wx_gdk_drag_context_get_actions(GdkDragContext
* context
)
340 return context
->actions
;
342 #define gdk_drag_context_get_actions wx_gdk_drag_context_get_actions
344 static inline GdkDragAction
wx_gdk_drag_context_get_selected_action(GdkDragContext
* context
)
346 return context
->action
;
348 #define gdk_drag_context_get_selected_action wx_gdk_drag_context_get_selected_action
350 static inline GdkDragAction
wx_gdk_drag_context_get_suggested_action(GdkDragContext
* context
)
352 return context
->suggested_action
;
354 #define gdk_drag_context_get_suggested_action wx_gdk_drag_context_get_suggested_action
356 static inline GList
* wx_gdk_drag_context_list_targets(GdkDragContext
* context
)
358 return context
->targets
;
360 #define gdk_drag_context_list_targets wx_gdk_drag_context_list_targets
362 static inline gint
wx_gdk_visual_get_depth(GdkVisual
* visual
)
364 return visual
->depth
;
366 #define gdk_visual_get_depth wx_gdk_visual_get_depth
368 static inline gboolean
wx_gtk_window_has_group(GtkWindow
* window
)
370 return window
->group
!= NULL
;
372 #define gtk_window_has_group wx_gtk_window_has_group
374 // ----------------------------------------------------------------------------
375 // the following were introduced in GTK+ 2.24
377 static inline GdkDisplay
* wx_gdk_window_get_display(GdkWindow
* window
)
379 return gdk_drawable_get_display(window
);
381 #define gdk_window_get_display wx_gdk_window_get_display
383 static inline GdkScreen
* wx_gdk_window_get_screen(GdkWindow
* window
)
385 return gdk_drawable_get_screen(window
);
387 #define gdk_window_get_screen wx_gdk_window_get_screen
389 static inline gint
wx_gdk_window_get_height(GdkWindow
* window
)
392 gdk_drawable_get_size(window
, NULL
, &h
);
395 #define gdk_window_get_height wx_gdk_window_get_height
397 static inline gint
wx_gdk_window_get_width(GdkWindow
* window
)
400 gdk_drawable_get_size(window
, &w
, NULL
);
403 #define gdk_window_get_width wx_gdk_window_get_width
405 #if GTK_CHECK_VERSION(2,10,0)
406 static inline void wx_gdk_cairo_set_source_window(cairo_t
* cr
, GdkWindow
* window
, gdouble x
, gdouble y
)
408 gdk_cairo_set_source_pixmap(cr
, window
, x
, y
);
410 #define gdk_cairo_set_source_window wx_gdk_cairo_set_source_window
413 // ----------------------------------------------------------------------------
414 // the following were introduced in GTK+ 3.0
416 static inline void wx_gdk_window_get_geometry(GdkWindow
* window
, gint
* x
, gint
* y
, gint
* width
, gint
* height
)
418 gdk_window_get_geometry(window
, x
, y
, width
, height
, NULL
);
420 #define gdk_window_get_geometry wx_gdk_window_get_geometry
422 static inline GtkWidget
* wx_gtk_tree_view_column_get_button(GtkTreeViewColumn
* tree_column
)
424 return tree_column
->button
;
426 #define gtk_tree_view_column_get_button wx_gtk_tree_view_column_get_button
428 static inline GtkWidget
* wx_gtk_box_new(GtkOrientation orientation
, gint spacing
)
431 if (orientation
== GTK_ORIENTATION_HORIZONTAL
)
432 widget
= gtk_hbox_new(false, spacing
);
434 widget
= gtk_vbox_new(false, spacing
);
437 #define gtk_box_new wx_gtk_box_new
439 static inline GtkWidget
* wx_gtk_button_box_new(GtkOrientation orientation
)
442 if (orientation
== GTK_ORIENTATION_HORIZONTAL
)
443 widget
= gtk_hbutton_box_new();
445 widget
= gtk_vbutton_box_new();
448 #define gtk_button_box_new wx_gtk_button_box_new
450 static inline GtkWidget
* wx_gtk_scale_new(GtkOrientation orientation
, GtkAdjustment
* adjustment
)
453 if (orientation
== GTK_ORIENTATION_HORIZONTAL
)
454 widget
= gtk_hscale_new(adjustment
);
456 widget
= gtk_vscale_new(adjustment
);
459 #define gtk_scale_new wx_gtk_scale_new
461 static inline GtkWidget
* wx_gtk_scrollbar_new(GtkOrientation orientation
, GtkAdjustment
* adjustment
)
464 if (orientation
== GTK_ORIENTATION_HORIZONTAL
)
465 widget
= gtk_hscrollbar_new(adjustment
);
467 widget
= gtk_vscrollbar_new(adjustment
);
470 #define gtk_scrollbar_new wx_gtk_scrollbar_new
472 static inline GtkWidget
* wx_gtk_separator_new(GtkOrientation orientation
)
475 if (orientation
== GTK_ORIENTATION_HORIZONTAL
)
476 widget
= gtk_hseparator_new();
478 widget
= gtk_vseparator_new();
481 #define gtk_separator_new wx_gtk_separator_new
483 static inline void wx_gtk_widget_get_preferred_height(GtkWidget
* widget
, gint
* minimum
, gint
* natural
)
486 gtk_widget_size_request(widget
, &req
);
488 *minimum
= req
.height
;
490 *natural
= req
.height
;
492 #define gtk_widget_get_preferred_height wx_gtk_widget_get_preferred_height
494 static inline void wx_gtk_widget_get_preferred_width(GtkWidget
* widget
, gint
* minimum
, gint
* natural
)
497 gtk_widget_size_request(widget
, &req
);
499 *minimum
= req
.width
;
501 *natural
= req
.width
;
503 #define gtk_widget_get_preferred_width wx_gtk_widget_get_preferred_width
505 static inline void wx_gtk_widget_get_preferred_size(GtkWidget
* widget
, GtkRequisition
* minimum
, GtkRequisition
* natural
)
507 GtkRequisition
* req
= minimum
;
510 gtk_widget_size_request(widget
, req
);
512 #define gtk_widget_get_preferred_size wx_gtk_widget_get_preferred_size
514 #endif // !__WXGTK3__
515 #endif // _WX_GTK_PRIVATE_COMPAT_H_