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 and GtkAboutDialog itself is not
58 // in 2.4 so skip this if we don't have it.
59 #if GTK_CHECK_VERSION(2,6,0)
61 static inline void wx_gtk_about_dialog_set_program_name(GtkAboutDialog
* about
, const gchar
* name
)
63 gtk_about_dialog_set_name(about
, name
);
65 #define gtk_about_dialog_set_program_name wx_gtk_about_dialog_set_program_name
68 // ----------------------------------------------------------------------------
69 // the following were introduced in GTK+ 2.14
71 static inline gdouble
wx_gtk_adjustment_get_lower(GtkAdjustment
* adjustment
)
73 return adjustment
->lower
;
75 #define gtk_adjustment_get_lower wx_gtk_adjustment_get_lower
77 static inline gdouble
wx_gtk_adjustment_get_page_increment(GtkAdjustment
* adjustment
)
79 return adjustment
->page_increment
;
81 #define gtk_adjustment_get_page_increment wx_gtk_adjustment_get_page_increment
83 static inline gdouble
wx_gtk_adjustment_get_page_size(GtkAdjustment
* adjustment
)
85 return adjustment
->page_size
;
87 #define gtk_adjustment_get_page_size wx_gtk_adjustment_get_page_size
89 static inline gdouble
wx_gtk_adjustment_get_step_increment(GtkAdjustment
* adjustment
)
91 return adjustment
->step_increment
;
93 #define gtk_adjustment_get_step_increment wx_gtk_adjustment_get_step_increment
95 static inline gdouble
wx_gtk_adjustment_get_upper(GtkAdjustment
* adjustment
)
97 return adjustment
->upper
;
99 #define gtk_adjustment_get_upper wx_gtk_adjustment_get_upper
101 static inline void wx_gtk_adjustment_set_page_size(GtkAdjustment
* adjustment
, gdouble page_size
)
103 adjustment
->page_size
= page_size
;
105 #define gtk_adjustment_set_page_size wx_gtk_adjustment_set_page_size
107 static inline GtkWidget
* wx_gtk_color_selection_dialog_get_color_selection(GtkColorSelectionDialog
* csd
)
109 return csd
->colorsel
;
111 #define gtk_color_selection_dialog_get_color_selection wx_gtk_color_selection_dialog_get_color_selection
113 static inline GtkWidget
* wx_gtk_dialog_get_content_area(GtkDialog
* dialog
)
117 #define gtk_dialog_get_content_area wx_gtk_dialog_get_content_area
119 static inline GtkWidget
* wx_gtk_dialog_get_action_area(GtkDialog
* dialog
)
121 return dialog
->action_area
;
123 #define gtk_dialog_get_action_area wx_gtk_dialog_get_action_area
125 static inline guint16
wx_gtk_entry_get_text_length(GtkEntry
* entry
)
127 return entry
->text_length
;
129 #define gtk_entry_get_text_length wx_gtk_entry_get_text_length
131 static inline const guchar
* wx_gtk_selection_data_get_data(GtkSelectionData
* selection_data
)
133 return selection_data
->data
;
135 #define gtk_selection_data_get_data wx_gtk_selection_data_get_data
137 static inline GdkAtom
wx_gtk_selection_data_get_data_type(GtkSelectionData
* selection_data
)
139 return selection_data
->type
;
141 #define gtk_selection_data_get_data_type wx_gtk_selection_data_get_data_type
143 static inline gint
wx_gtk_selection_data_get_format(GtkSelectionData
* selection_data
)
145 return selection_data
->format
;
147 #define gtk_selection_data_get_format wx_gtk_selection_data_get_format
149 static inline gint
wx_gtk_selection_data_get_length(GtkSelectionData
* selection_data
)
151 return selection_data
->length
;
153 #define gtk_selection_data_get_length wx_gtk_selection_data_get_length
155 static inline GdkAtom
wx_gtk_selection_data_get_target(GtkSelectionData
* selection_data
)
157 return selection_data
->target
;
159 #define gtk_selection_data_get_target wx_gtk_selection_data_get_target
161 static inline GdkWindow
* wx_gtk_widget_get_window(GtkWidget
* widget
)
163 return widget
->window
;
165 #define gtk_widget_get_window wx_gtk_widget_get_window
167 static inline GtkWidget
* wx_gtk_window_get_default_widget(GtkWindow
* window
)
169 return window
->default_widget
;
171 #define gtk_window_get_default_widget wx_gtk_window_get_default_widget
173 // ----------------------------------------------------------------------------
174 // the following were introduced in GTK+ 2.16
176 static inline GdkAtom
wx_gtk_selection_data_get_selection(GtkSelectionData
* selection_data
)
178 return selection_data
->selection
;
180 #define gtk_selection_data_get_selection wx_gtk_selection_data_get_selection
182 // ----------------------------------------------------------------------------
183 // the following were introduced in GTK+ 2.18
185 static inline void wx_gtk_cell_renderer_get_alignment(GtkCellRenderer
* cell
, gfloat
* xalign
, gfloat
* yalign
)
187 *xalign
= cell
->xalign
;
188 *yalign
= cell
->yalign
;
190 #define gtk_cell_renderer_get_alignment wx_gtk_cell_renderer_get_alignment
192 static inline void wx_gtk_cell_renderer_get_padding(GtkCellRenderer
* cell
, gint
* xpad
, gint
* ypad
)
197 #define gtk_cell_renderer_get_padding wx_gtk_cell_renderer_get_padding
199 static inline void wx_gtk_widget_get_allocation(GtkWidget
* widget
, GtkAllocation
* allocation
)
201 *allocation
= widget
->allocation
;
203 #define gtk_widget_get_allocation wx_gtk_widget_get_allocation
205 inline gboolean
wx_gtk_widget_get_has_window(GtkWidget
*widget
)
207 return !GTK_WIDGET_NO_WINDOW(widget
);
209 #define gtk_widget_get_has_window wx_gtk_widget_get_has_window
212 inline gboolean
wx_gtk_widget_get_has_grab(GtkWidget
*widget
)
214 return GTK_WIDGET_HAS_GRAB(widget
);
216 #define gtk_widget_get_has_grab wx_gtk_widget_get_has_grab
219 inline gboolean
wx_gtk_widget_get_visible(GtkWidget
*widget
)
221 return GTK_WIDGET_VISIBLE(widget
);
223 #define gtk_widget_get_visible wx_gtk_widget_get_visible
226 inline gboolean
wx_gtk_widget_get_sensitive(GtkWidget
*widget
)
228 return GTK_WIDGET_SENSITIVE(widget
);
230 #define gtk_widget_get_sensitive wx_gtk_widget_get_sensitive
233 inline gboolean
wx_gtk_widget_is_drawable(GtkWidget
*widget
)
235 return GTK_WIDGET_DRAWABLE(widget
);
237 #define gtk_widget_is_drawable wx_gtk_widget_is_drawable
240 inline gboolean
wx_gtk_widget_get_can_focus(GtkWidget
*widget
)
242 return GTK_WIDGET_CAN_FOCUS(widget
);
244 #define gtk_widget_get_can_focus wx_gtk_widget_get_can_focus
246 inline void wx_gtk_widget_set_can_focus(GtkWidget
*widget
, gboolean can
)
249 GTK_WIDGET_SET_FLAGS(widget
, GTK_CAN_FOCUS
);
251 GTK_WIDGET_UNSET_FLAGS(widget
, GTK_CAN_FOCUS
);
253 #define gtk_widget_set_can_focus wx_gtk_widget_set_can_focus
256 inline gboolean
wx_gtk_widget_get_can_default(GtkWidget
*widget
)
258 return GTK_WIDGET_CAN_DEFAULT(widget
);
260 #define gtk_widget_get_can_default wx_gtk_widget_get_can_default
262 inline void wx_gtk_widget_set_can_default(GtkWidget
*widget
, gboolean can
)
265 GTK_WIDGET_SET_FLAGS(widget
, GTK_CAN_DEFAULT
);
267 GTK_WIDGET_UNSET_FLAGS(widget
, GTK_CAN_DEFAULT
);
269 #define gtk_widget_set_can_default wx_gtk_widget_set_can_default
272 inline gboolean
wx_gtk_widget_has_default(GtkWidget
*widget
)
274 return GTK_WIDGET_HAS_DEFAULT(widget
);
276 #define gtk_widget_has_default wx_gtk_widget_has_default
279 inline GtkStateType
wx_gtk_widget_get_state(GtkWidget
*widget
)
281 return (GtkStateType
)GTK_WIDGET_STATE(widget
);
283 #define gtk_widget_get_state wx_gtk_widget_get_state
286 inline gboolean
wx_gtk_widget_get_double_buffered(GtkWidget
*widget
)
288 return GTK_WIDGET_DOUBLE_BUFFERED(widget
);
290 #define gtk_widget_get_double_buffered wx_gtk_widget_get_double_buffered
292 static inline gboolean
wx_gtk_widget_has_grab(GtkWidget
* widget
)
294 return GTK_WIDGET_HAS_GRAB(widget
);
296 #define gtk_widget_has_grab wx_gtk_widget_has_grab
298 static inline void wx_gtk_widget_set_allocation(GtkWidget
* widget
, const GtkAllocation
* allocation
)
300 widget
->allocation
= *allocation
;
302 #define gtk_widget_set_allocation wx_gtk_widget_set_allocation
304 // ----------------------------------------------------------------------------
305 // the following were introduced in GTK+ 2.20
307 inline gboolean
wx_gtk_widget_get_realized(GtkWidget
*widget
)
309 return GTK_WIDGET_REALIZED(widget
);
311 #define gtk_widget_get_realized wx_gtk_widget_get_realized
314 inline gboolean
wx_gtk_widget_get_mapped(GtkWidget
*widget
)
316 return GTK_WIDGET_MAPPED(widget
);
318 #define gtk_widget_get_mapped wx_gtk_widget_get_mapped
320 static inline void wx_gtk_widget_get_requisition(GtkWidget
* widget
, GtkRequisition
* requisition
)
322 *requisition
= widget
->requisition
;
324 #define gtk_widget_get_requisition wx_gtk_widget_get_requisition
326 static inline GdkWindow
* wx_gtk_entry_get_text_window(GtkEntry
* entry
)
328 return entry
->text_area
;
330 #define gtk_entry_get_text_window wx_gtk_entry_get_text_window
332 // ----------------------------------------------------------------------------
333 // the following were introduced in GTK+ 2.22
335 static inline GdkWindow
* wx_gtk_button_get_event_window(GtkButton
* button
)
337 return button
->event_window
;
339 #define gtk_button_get_event_window wx_gtk_button_get_event_window
341 static inline GdkDragAction
wx_gdk_drag_context_get_actions(GdkDragContext
* context
)
343 return context
->actions
;
345 #define gdk_drag_context_get_actions wx_gdk_drag_context_get_actions
347 static inline GdkDragAction
wx_gdk_drag_context_get_selected_action(GdkDragContext
* context
)
349 return context
->action
;
351 #define gdk_drag_context_get_selected_action wx_gdk_drag_context_get_selected_action
353 static inline GdkDragAction
wx_gdk_drag_context_get_suggested_action(GdkDragContext
* context
)
355 return context
->suggested_action
;
357 #define gdk_drag_context_get_suggested_action wx_gdk_drag_context_get_suggested_action
359 static inline GList
* wx_gdk_drag_context_list_targets(GdkDragContext
* context
)
361 return context
->targets
;
363 #define gdk_drag_context_list_targets wx_gdk_drag_context_list_targets
365 static inline gint
wx_gdk_visual_get_depth(GdkVisual
* visual
)
367 return visual
->depth
;
369 #define gdk_visual_get_depth wx_gdk_visual_get_depth
371 static inline gboolean
wx_gtk_window_has_group(GtkWindow
* window
)
373 return window
->group
!= NULL
;
375 #define gtk_window_has_group wx_gtk_window_has_group
377 // ----------------------------------------------------------------------------
378 // the following were introduced in GTK+ 2.24
380 static inline GdkDisplay
* wx_gdk_window_get_display(GdkWindow
* window
)
382 return gdk_drawable_get_display(window
);
384 #define gdk_window_get_display wx_gdk_window_get_display
386 static inline GdkScreen
* wx_gdk_window_get_screen(GdkWindow
* window
)
388 return gdk_drawable_get_screen(window
);
390 #define gdk_window_get_screen wx_gdk_window_get_screen
392 static inline gint
wx_gdk_window_get_height(GdkWindow
* window
)
395 gdk_drawable_get_size(window
, NULL
, &h
);
398 #define gdk_window_get_height wx_gdk_window_get_height
400 static inline gint
wx_gdk_window_get_width(GdkWindow
* window
)
403 gdk_drawable_get_size(window
, &w
, NULL
);
406 #define gdk_window_get_width wx_gdk_window_get_width
408 #if GTK_CHECK_VERSION(2,10,0)
409 static inline void wx_gdk_cairo_set_source_window(cairo_t
* cr
, GdkWindow
* window
, gdouble x
, gdouble y
)
411 gdk_cairo_set_source_pixmap(cr
, window
, x
, y
);
413 #define gdk_cairo_set_source_window wx_gdk_cairo_set_source_window
416 // ----------------------------------------------------------------------------
417 // the following were introduced in GTK+ 3.0
419 static inline void wx_gdk_window_get_geometry(GdkWindow
* window
, gint
* x
, gint
* y
, gint
* width
, gint
* height
)
421 gdk_window_get_geometry(window
, x
, y
, width
, height
, NULL
);
423 #define gdk_window_get_geometry wx_gdk_window_get_geometry
425 static inline GtkWidget
* wx_gtk_tree_view_column_get_button(GtkTreeViewColumn
* tree_column
)
427 return tree_column
->button
;
429 #define gtk_tree_view_column_get_button wx_gtk_tree_view_column_get_button
431 static inline GtkWidget
* wx_gtk_box_new(GtkOrientation orientation
, gint spacing
)
434 if (orientation
== GTK_ORIENTATION_HORIZONTAL
)
435 widget
= gtk_hbox_new(false, spacing
);
437 widget
= gtk_vbox_new(false, spacing
);
440 #define gtk_box_new wx_gtk_box_new
442 static inline GtkWidget
* wx_gtk_button_box_new(GtkOrientation orientation
)
445 if (orientation
== GTK_ORIENTATION_HORIZONTAL
)
446 widget
= gtk_hbutton_box_new();
448 widget
= gtk_vbutton_box_new();
451 #define gtk_button_box_new wx_gtk_button_box_new
453 static inline GtkWidget
* wx_gtk_scale_new(GtkOrientation orientation
, GtkAdjustment
* adjustment
)
456 if (orientation
== GTK_ORIENTATION_HORIZONTAL
)
457 widget
= gtk_hscale_new(adjustment
);
459 widget
= gtk_vscale_new(adjustment
);
462 #define gtk_scale_new wx_gtk_scale_new
464 static inline GtkWidget
* wx_gtk_scrollbar_new(GtkOrientation orientation
, GtkAdjustment
* adjustment
)
467 if (orientation
== GTK_ORIENTATION_HORIZONTAL
)
468 widget
= gtk_hscrollbar_new(adjustment
);
470 widget
= gtk_vscrollbar_new(adjustment
);
473 #define gtk_scrollbar_new wx_gtk_scrollbar_new
475 static inline GtkWidget
* wx_gtk_separator_new(GtkOrientation orientation
)
478 if (orientation
== GTK_ORIENTATION_HORIZONTAL
)
479 widget
= gtk_hseparator_new();
481 widget
= gtk_vseparator_new();
484 #define gtk_separator_new wx_gtk_separator_new
486 static inline void wx_gtk_widget_get_preferred_height(GtkWidget
* widget
, gint
* minimum
, gint
* natural
)
489 gtk_widget_size_request(widget
, &req
);
491 *minimum
= req
.height
;
493 *natural
= req
.height
;
495 #define gtk_widget_get_preferred_height wx_gtk_widget_get_preferred_height
497 static inline void wx_gtk_widget_get_preferred_width(GtkWidget
* widget
, gint
* minimum
, gint
* natural
)
500 gtk_widget_size_request(widget
, &req
);
502 *minimum
= req
.width
;
504 *natural
= req
.width
;
506 #define gtk_widget_get_preferred_width wx_gtk_widget_get_preferred_width
508 static inline void wx_gtk_widget_get_preferred_size(GtkWidget
* widget
, GtkRequisition
* minimum
, GtkRequisition
* natural
)
510 GtkRequisition
* req
= minimum
;
513 gtk_widget_size_request(widget
, req
);
515 #define gtk_widget_get_preferred_size wx_gtk_widget_get_preferred_size
517 #endif // !__WXGTK3__
518 #endif // _WX_GTK_PRIVATE_COMPAT_H_