]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/private/gtk2-compat.h
support SDK < 10.6, fixes #14902
[wxWidgets.git] / include / wx / gtk / private / gtk2-compat.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/private/compat.h
3 // Purpose: Compatibility code for older GTK+ versions
4 // Author: Vaclav Slavik
5 // Created: 2011-03-25
6 // RCS-ID: $Id$
7 // Copyright: (c) 2011 Vaclav Slavik <vslavik@fastmail.fm>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_GTK_PRIVATE_COMPAT_H_
12 #define _WX_GTK_PRIVATE_COMPAT_H_
13
14 // ----------------------------------------------------------------------------
15 // Implementations of new accessors for older GTK+ versions
16 // ----------------------------------------------------------------------------
17
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.
21 //
22 // Note: wx_ prefix is used to avoid symbol conflicts at runtime
23 //
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+.
28
29 #ifndef __WXGTK3__
30
31 // ----------------------------------------------------------------------------
32 // the following were introduced in GTK+ 2.8
33
34 static inline GtkWidget* wx_gtk_scrolled_window_get_hscrollbar(GtkScrolledWindow* scrolled_window)
35 {
36 return scrolled_window->hscrollbar;
37 }
38 #define gtk_scrolled_window_get_hscrollbar wx_gtk_scrolled_window_get_hscrollbar
39
40 static inline GtkWidget* wx_gtk_scrolled_window_get_vscrollbar(GtkScrolledWindow* scrolled_window)
41 {
42 return scrolled_window->vscrollbar;
43 }
44 #define gtk_scrolled_window_get_vscrollbar wx_gtk_scrolled_window_get_vscrollbar
45
46 // ----------------------------------------------------------------------------
47 // the following were introduced in GLib 2.10
48
49 static inline gpointer wx_g_object_ref_sink(gpointer object)
50 {
51 g_object_ref(object);
52 gtk_object_sink(GTK_OBJECT(object));
53 return object;
54 }
55 #define g_object_ref_sink wx_g_object_ref_sink
56
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)
61
62 static inline void wx_gtk_about_dialog_set_program_name(GtkAboutDialog* about, const gchar* name)
63 {
64 gtk_about_dialog_set_name(about, name);
65 }
66 #define gtk_about_dialog_set_program_name wx_gtk_about_dialog_set_program_name
67 #endif // 2.6.0
68
69 // ----------------------------------------------------------------------------
70 // the following were introduced in GTK+ 2.14
71
72 static inline gdouble wx_gtk_adjustment_get_lower(GtkAdjustment* adjustment)
73 {
74 return adjustment->lower;
75 }
76 #define gtk_adjustment_get_lower wx_gtk_adjustment_get_lower
77
78 static inline gdouble wx_gtk_adjustment_get_page_increment(GtkAdjustment* adjustment)
79 {
80 return adjustment->page_increment;
81 }
82 #define gtk_adjustment_get_page_increment wx_gtk_adjustment_get_page_increment
83
84 static inline gdouble wx_gtk_adjustment_get_page_size(GtkAdjustment* adjustment)
85 {
86 return adjustment->page_size;
87 }
88 #define gtk_adjustment_get_page_size wx_gtk_adjustment_get_page_size
89
90 static inline gdouble wx_gtk_adjustment_get_step_increment(GtkAdjustment* adjustment)
91 {
92 return adjustment->step_increment;
93 }
94 #define gtk_adjustment_get_step_increment wx_gtk_adjustment_get_step_increment
95
96 static inline gdouble wx_gtk_adjustment_get_upper(GtkAdjustment* adjustment)
97 {
98 return adjustment->upper;
99 }
100 #define gtk_adjustment_get_upper wx_gtk_adjustment_get_upper
101
102 static inline void wx_gtk_adjustment_set_page_size(GtkAdjustment* adjustment, gdouble page_size)
103 {
104 adjustment->page_size = page_size;
105 }
106 #define gtk_adjustment_set_page_size wx_gtk_adjustment_set_page_size
107
108 static inline GtkWidget* wx_gtk_color_selection_dialog_get_color_selection(GtkColorSelectionDialog* csd)
109 {
110 return csd->colorsel;
111 }
112 #define gtk_color_selection_dialog_get_color_selection wx_gtk_color_selection_dialog_get_color_selection
113
114 static inline GtkWidget* wx_gtk_dialog_get_content_area(GtkDialog* dialog)
115 {
116 return dialog->vbox;
117 }
118 #define gtk_dialog_get_content_area wx_gtk_dialog_get_content_area
119
120 static inline GtkWidget* wx_gtk_dialog_get_action_area(GtkDialog* dialog)
121 {
122 return dialog->action_area;
123 }
124 #define gtk_dialog_get_action_area wx_gtk_dialog_get_action_area
125
126 static inline guint16 wx_gtk_entry_get_text_length(GtkEntry* entry)
127 {
128 return entry->text_length;
129 }
130 #define gtk_entry_get_text_length wx_gtk_entry_get_text_length
131
132 static inline GtkWidget* wx_gtk_font_selection_dialog_get_cancel_button(GtkFontSelectionDialog* fsd)
133 {
134 return fsd->cancel_button;
135 }
136 #define gtk_font_selection_dialog_get_cancel_button wx_gtk_font_selection_dialog_get_cancel_button
137
138 static inline GtkWidget* wx_gtk_font_selection_dialog_get_ok_button(GtkFontSelectionDialog* fsd)
139 {
140 return fsd->ok_button;
141 }
142 #define gtk_font_selection_dialog_get_ok_button wx_gtk_font_selection_dialog_get_ok_button
143
144 static inline const guchar* wx_gtk_selection_data_get_data(GtkSelectionData* selection_data)
145 {
146 return selection_data->data;
147 }
148 #define gtk_selection_data_get_data wx_gtk_selection_data_get_data
149
150 static inline GdkAtom wx_gtk_selection_data_get_data_type(GtkSelectionData* selection_data)
151 {
152 return selection_data->type;
153 }
154 #define gtk_selection_data_get_data_type wx_gtk_selection_data_get_data_type
155
156 static inline gint wx_gtk_selection_data_get_format(GtkSelectionData* selection_data)
157 {
158 return selection_data->format;
159 }
160 #define gtk_selection_data_get_format wx_gtk_selection_data_get_format
161
162 static inline gint wx_gtk_selection_data_get_length(GtkSelectionData* selection_data)
163 {
164 return selection_data->length;
165 }
166 #define gtk_selection_data_get_length wx_gtk_selection_data_get_length
167
168 static inline GdkAtom wx_gtk_selection_data_get_target(GtkSelectionData* selection_data)
169 {
170 return selection_data->target;
171 }
172 #define gtk_selection_data_get_target wx_gtk_selection_data_get_target
173
174 static inline GdkWindow* wx_gtk_widget_get_window(GtkWidget* widget)
175 {
176 return widget->window;
177 }
178 #define gtk_widget_get_window wx_gtk_widget_get_window
179
180 static inline GtkWidget* wx_gtk_window_get_default_widget(GtkWindow* window)
181 {
182 return window->default_widget;
183 }
184 #define gtk_window_get_default_widget wx_gtk_window_get_default_widget
185
186 // ----------------------------------------------------------------------------
187 // the following were introduced in GTK+ 2.16
188
189 static inline GdkAtom wx_gtk_selection_data_get_selection(GtkSelectionData* selection_data)
190 {
191 return selection_data->selection;
192 }
193 #define gtk_selection_data_get_selection wx_gtk_selection_data_get_selection
194
195 // ----------------------------------------------------------------------------
196 // the following were introduced in GTK+ 2.18
197
198 static inline void wx_gtk_cell_renderer_get_alignment(GtkCellRenderer* cell, gfloat* xalign, gfloat* yalign)
199 {
200 *xalign = cell->xalign;
201 *yalign = cell->yalign;
202 }
203 #define gtk_cell_renderer_get_alignment wx_gtk_cell_renderer_get_alignment
204
205 static inline void wx_gtk_cell_renderer_get_padding(GtkCellRenderer* cell, gint* xpad, gint* ypad)
206 {
207 *xpad = cell->xpad;
208 *ypad = cell->ypad;
209 }
210 #define gtk_cell_renderer_get_padding wx_gtk_cell_renderer_get_padding
211
212 static inline void wx_gtk_widget_get_allocation(GtkWidget* widget, GtkAllocation* allocation)
213 {
214 *allocation = widget->allocation;
215 }
216 #define gtk_widget_get_allocation wx_gtk_widget_get_allocation
217
218 inline gboolean wx_gtk_widget_get_has_window(GtkWidget *widget)
219 {
220 return !GTK_WIDGET_NO_WINDOW(widget);
221 }
222 #define gtk_widget_get_has_window wx_gtk_widget_get_has_window
223
224
225 inline gboolean wx_gtk_widget_get_has_grab(GtkWidget *widget)
226 {
227 return GTK_WIDGET_HAS_GRAB(widget);
228 }
229 #define gtk_widget_get_has_grab wx_gtk_widget_get_has_grab
230
231
232 inline gboolean wx_gtk_widget_get_visible(GtkWidget *widget)
233 {
234 return GTK_WIDGET_VISIBLE(widget);
235 }
236 #define gtk_widget_get_visible wx_gtk_widget_get_visible
237
238
239 inline gboolean wx_gtk_widget_get_sensitive(GtkWidget *widget)
240 {
241 return GTK_WIDGET_SENSITIVE(widget);
242 }
243 #define gtk_widget_get_sensitive wx_gtk_widget_get_sensitive
244
245
246 inline gboolean wx_gtk_widget_is_drawable(GtkWidget *widget)
247 {
248 return GTK_WIDGET_DRAWABLE(widget);
249 }
250 #define gtk_widget_is_drawable wx_gtk_widget_is_drawable
251
252
253 inline gboolean wx_gtk_widget_get_can_focus(GtkWidget *widget)
254 {
255 return GTK_WIDGET_CAN_FOCUS(widget);
256 }
257 #define gtk_widget_get_can_focus wx_gtk_widget_get_can_focus
258
259 inline void wx_gtk_widget_set_can_focus(GtkWidget *widget, gboolean can)
260 {
261 if ( can )
262 GTK_WIDGET_SET_FLAGS(widget, GTK_CAN_FOCUS);
263 else
264 GTK_WIDGET_UNSET_FLAGS(widget, GTK_CAN_FOCUS);
265 }
266 #define gtk_widget_set_can_focus wx_gtk_widget_set_can_focus
267
268
269 inline gboolean wx_gtk_widget_get_can_default(GtkWidget *widget)
270 {
271 return GTK_WIDGET_CAN_DEFAULT(widget);
272 }
273 #define gtk_widget_get_can_default wx_gtk_widget_get_can_default
274
275 inline void wx_gtk_widget_set_can_default(GtkWidget *widget, gboolean can)
276 {
277 if ( can )
278 GTK_WIDGET_SET_FLAGS(widget, GTK_CAN_DEFAULT);
279 else
280 GTK_WIDGET_UNSET_FLAGS(widget, GTK_CAN_DEFAULT);
281 }
282 #define gtk_widget_set_can_default wx_gtk_widget_set_can_default
283
284
285 inline gboolean wx_gtk_widget_has_default(GtkWidget *widget)
286 {
287 return GTK_WIDGET_HAS_DEFAULT(widget);
288 }
289 #define gtk_widget_has_default wx_gtk_widget_has_default
290
291
292 inline GtkStateType wx_gtk_widget_get_state(GtkWidget *widget)
293 {
294 return (GtkStateType)GTK_WIDGET_STATE(widget);
295 }
296 #define gtk_widget_get_state wx_gtk_widget_get_state
297
298
299 inline gboolean wx_gtk_widget_get_double_buffered(GtkWidget *widget)
300 {
301 return GTK_WIDGET_DOUBLE_BUFFERED(widget);
302 }
303 #define gtk_widget_get_double_buffered wx_gtk_widget_get_double_buffered
304
305 static inline gboolean wx_gtk_widget_has_grab(GtkWidget* widget)
306 {
307 return GTK_WIDGET_HAS_GRAB(widget);
308 }
309 #define gtk_widget_has_grab wx_gtk_widget_has_grab
310
311 static inline void wx_gtk_widget_set_allocation(GtkWidget* widget, const GtkAllocation* allocation)
312 {
313 widget->allocation = *allocation;
314 }
315 #define gtk_widget_set_allocation wx_gtk_widget_set_allocation
316
317 // ----------------------------------------------------------------------------
318 // the following were introduced in GTK+ 2.20
319
320 inline gboolean wx_gtk_widget_get_realized(GtkWidget *widget)
321 {
322 return GTK_WIDGET_REALIZED(widget);
323 }
324 #define gtk_widget_get_realized wx_gtk_widget_get_realized
325
326
327 inline gboolean wx_gtk_widget_get_mapped(GtkWidget *widget)
328 {
329 return GTK_WIDGET_MAPPED(widget);
330 }
331 #define gtk_widget_get_mapped wx_gtk_widget_get_mapped
332
333 static inline void wx_gtk_widget_get_requisition(GtkWidget* widget, GtkRequisition* requisition)
334 {
335 *requisition = widget->requisition;
336 }
337 #define gtk_widget_get_requisition wx_gtk_widget_get_requisition
338
339 static inline GdkWindow* wx_gtk_entry_get_text_window(GtkEntry* entry)
340 {
341 return entry->text_area;
342 }
343 #define gtk_entry_get_text_window wx_gtk_entry_get_text_window
344
345 // ----------------------------------------------------------------------------
346 // the following were introduced in GTK+ 2.22
347
348 static inline GdkWindow* wx_gtk_button_get_event_window(GtkButton* button)
349 {
350 return button->event_window;
351 }
352 #define gtk_button_get_event_window wx_gtk_button_get_event_window
353
354 static inline GdkDragAction wx_gdk_drag_context_get_actions(GdkDragContext* context)
355 {
356 return context->actions;
357 }
358 #define gdk_drag_context_get_actions wx_gdk_drag_context_get_actions
359
360 static inline GdkDragAction wx_gdk_drag_context_get_selected_action(GdkDragContext* context)
361 {
362 return context->action;
363 }
364 #define gdk_drag_context_get_selected_action wx_gdk_drag_context_get_selected_action
365
366 static inline GdkDragAction wx_gdk_drag_context_get_suggested_action(GdkDragContext* context)
367 {
368 return context->suggested_action;
369 }
370 #define gdk_drag_context_get_suggested_action wx_gdk_drag_context_get_suggested_action
371
372 static inline GList* wx_gdk_drag_context_list_targets(GdkDragContext* context)
373 {
374 return context->targets;
375 }
376 #define gdk_drag_context_list_targets wx_gdk_drag_context_list_targets
377
378 static inline gint wx_gdk_visual_get_depth(GdkVisual* visual)
379 {
380 return visual->depth;
381 }
382 #define gdk_visual_get_depth wx_gdk_visual_get_depth
383
384 // ----------------------------------------------------------------------------
385 // the following were introduced in GTK+ 2.24
386
387 static inline GdkDisplay* wx_gdk_window_get_display(GdkWindow* window)
388 {
389 return gdk_drawable_get_display(window);
390 }
391 #define gdk_window_get_display wx_gdk_window_get_display
392
393 static inline GdkScreen* wx_gdk_window_get_screen(GdkWindow* window)
394 {
395 return gdk_drawable_get_screen(window);
396 }
397 #define gdk_window_get_screen wx_gdk_window_get_screen
398
399 static inline gint wx_gdk_window_get_height(GdkWindow* window)
400 {
401 int h;
402 gdk_drawable_get_size(window, NULL, &h);
403 return h;
404 }
405 #define gdk_window_get_height wx_gdk_window_get_height
406
407 static inline gint wx_gdk_window_get_width(GdkWindow* window)
408 {
409 int w;
410 gdk_drawable_get_size(window, &w, NULL);
411 return w;
412 }
413 #define gdk_window_get_width wx_gdk_window_get_width
414
415 #if GTK_CHECK_VERSION(2,10,0)
416 static inline void wx_gdk_cairo_set_source_window(cairo_t* cr, GdkWindow* window, gdouble x, gdouble y)
417 {
418 gdk_cairo_set_source_pixmap(cr, window, x, y);
419 }
420 #define gdk_cairo_set_source_window wx_gdk_cairo_set_source_window
421 #endif
422
423 // ----------------------------------------------------------------------------
424 // the following were introduced in GTK+ 3.0
425
426 static inline void wx_gdk_window_get_geometry(GdkWindow* window, gint* x, gint* y, gint* width, gint* height)
427 {
428 gdk_window_get_geometry(window, x, y, width, height, NULL);
429 }
430 #define gdk_window_get_geometry wx_gdk_window_get_geometry
431
432 static inline GtkWidget* wx_gtk_tree_view_column_get_button(GtkTreeViewColumn* tree_column)
433 {
434 return tree_column->button;
435 }
436 #define gtk_tree_view_column_get_button wx_gtk_tree_view_column_get_button
437
438 static inline GtkWidget* wx_gtk_box_new(GtkOrientation orientation, gint spacing)
439 {
440 GtkWidget* widget;
441 if (orientation == GTK_ORIENTATION_HORIZONTAL)
442 widget = gtk_hbox_new(false, spacing);
443 else
444 widget = gtk_vbox_new(false, spacing);
445 return widget;
446 }
447 #define gtk_box_new wx_gtk_box_new
448
449 static inline GtkWidget* wx_gtk_button_box_new(GtkOrientation orientation)
450 {
451 GtkWidget* widget;
452 if (orientation == GTK_ORIENTATION_HORIZONTAL)
453 widget = gtk_hbutton_box_new();
454 else
455 widget = gtk_vbutton_box_new();
456 return widget;
457 }
458 #define gtk_button_box_new wx_gtk_button_box_new
459
460 static inline GtkWidget* wx_gtk_scale_new(GtkOrientation orientation, GtkAdjustment* adjustment)
461 {
462 GtkWidget* widget;
463 if (orientation == GTK_ORIENTATION_HORIZONTAL)
464 widget = gtk_hscale_new(adjustment);
465 else
466 widget = gtk_vscale_new(adjustment);
467 return widget;
468 }
469 #define gtk_scale_new wx_gtk_scale_new
470
471 static inline GtkWidget* wx_gtk_scrollbar_new(GtkOrientation orientation, GtkAdjustment* adjustment)
472 {
473 GtkWidget* widget;
474 if (orientation == GTK_ORIENTATION_HORIZONTAL)
475 widget = gtk_hscrollbar_new(adjustment);
476 else
477 widget = gtk_vscrollbar_new(adjustment);
478 return widget;
479 }
480 #define gtk_scrollbar_new wx_gtk_scrollbar_new
481
482 static inline GtkWidget* wx_gtk_separator_new(GtkOrientation orientation)
483 {
484 GtkWidget* widget;
485 if (orientation == GTK_ORIENTATION_HORIZONTAL)
486 widget = gtk_hseparator_new();
487 else
488 widget = gtk_vseparator_new();
489 return widget;
490 }
491 #define gtk_separator_new wx_gtk_separator_new
492
493 static inline void wx_gtk_widget_get_preferred_height(GtkWidget* widget, gint* minimum, gint* natural)
494 {
495 GtkRequisition req;
496 gtk_widget_size_request(widget, &req);
497 if (minimum)
498 *minimum = req.height;
499 if (natural)
500 *natural = req.height;
501 }
502 #define gtk_widget_get_preferred_height wx_gtk_widget_get_preferred_height
503
504 static inline void wx_gtk_widget_get_preferred_width(GtkWidget* widget, gint* minimum, gint* natural)
505 {
506 GtkRequisition req;
507 gtk_widget_size_request(widget, &req);
508 if (minimum)
509 *minimum = req.width;
510 if (natural)
511 *natural = req.width;
512 }
513 #define gtk_widget_get_preferred_width wx_gtk_widget_get_preferred_width
514
515 static inline void wx_gtk_widget_get_preferred_size(GtkWidget* widget, GtkRequisition* minimum, GtkRequisition* natural)
516 {
517 GtkRequisition* req = minimum;
518 if (req == NULL)
519 req = natural;
520 gtk_widget_size_request(widget, req);
521 }
522 #define gtk_widget_get_preferred_size wx_gtk_widget_get_preferred_size
523
524 #endif // !__WXGTK3__
525 #endif // _WX_GTK_PRIVATE_COMPAT_H_