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