fixed compilation with gtk 2.20
[geeqie.git] / src / compat.c
1 /*
2  * Geeqie
3  * Copyright (C) 2008 - 2012 The Geeqie Team
4  *
5  * Authors: Vladimir Nadvornik / Laurent Monin
6  *
7  * This software is released under the GNU General Public License (GNU GPL).
8  * Please read the included file COPYING for more information.
9  * This software comes with no warranty of any kind, use at your own risk!
10  */
11
12 #include "main.h"
13 #include "compat.h"
14
15 /* gtk_radio_action_set_current_value() replacement for GTK+ < 2.10 */
16 void radio_action_set_current_value(GtkRadioAction *action, gint current_value)
17 {
18 #if GTK_CHECK_VERSION(2, 10, 0)
19         gtk_radio_action_set_current_value(action, current_value);
20 #else
21         GSList *group;
22         gint value;
23
24         group = gtk_radio_action_get_group(action);
25         while (group)
26                 {
27                 action = GTK_RADIO_ACTION(group->data);
28                 g_object_get(G_OBJECT(action), "value", &value, NULL);
29                 if (value == current_value)
30                         {
31                         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), TRUE);
32                         return;
33                         }
34                 group = g_slist_next(group);
35                 }
36 #endif
37 }
38
39 #if !GLIB_CHECK_VERSION(2, 14, 0)
40 static void hash_table_add(gpointer key, gpointer value, gpointer user_data)
41 {
42         GList **list = user_data;
43         *list = g_list_prepend(*list, key);
44 }
45 #endif
46
47 GList* hash_table_get_keys(GHashTable *hash_table)
48 {
49 #if GLIB_CHECK_VERSION(2, 14, 0)
50         return g_hash_table_get_keys(hash_table);
51 #else
52         GList *list = NULL;
53         g_hash_table_foreach(hash_table, hash_table_add, &list);
54         return list;
55 #endif
56 }
57
58 #if !GTK_CHECK_VERSION(2,24,0)
59 gint compat_gdk_window_get_width(GdkWindow *window)
60 {
61         gint w, h;
62         gdk_drawable_get_size(window, &w, &h);
63         return w;
64 }
65
66 gint compat_gdk_window_get_height(GdkWindow *window)
67 {
68         gint w, h;
69         gdk_drawable_get_size(window, &w, &h);
70         return h;
71 }
72 #endif
73
74 #if !GTK_CHECK_VERSION(2,22,0)
75 cairo_surface_t *compat_gdk_window_create_similar_surface (GdkWindow *window, cairo_content_t content, gint width, gint height)
76 {
77         cairo_t *cr = gdk_cairo_create(window);
78         cairo_surface_t *ws = cairo_get_target(cr); 
79         cairo_surface_t *ret = cairo_surface_create_similar(ws, content, width, height);
80         cairo_destroy(cr);
81         return ret;
82 }
83 #endif
84 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */