1 #include <config.h>
2 #include <gtk/gtk.h>
3 #include <gdk/gdkx.h>
4 #include "rep-gtk.h"
5
6 /* This whole file is rated XXX. */
7
8 gchar*
gtk_label_get_interp(GtkLabel * label)9 gtk_label_get_interp (GtkLabel *label)
10 {
11 gchar *str;
12 gtk_label_get (label, &str);
13 return str;
14 }
15
16 /* cheap cop-out. */
17
18 static void
menu_popup_position(GtkMenu * menu,gint * xp,gint * yp,gboolean * p,gpointer data)19 menu_popup_position (GtkMenu *menu, gint *xp, gint *yp, gboolean *p, gpointer data)
20 {
21 gulong coded = (gulong) data;
22 gint x = coded & 0xffff;
23 gint y = coded >> 16;
24
25 /* copied from gtkmenu.c:gtk_menu_position () */
26
27 GtkRequisition requisition;
28 gint screen_width = gdk_screen_width ();
29 gint screen_height = gdk_screen_height ();
30
31 gtk_widget_size_request (GTK_WIDGET (menu), &requisition);
32
33 x = CLAMP (x - 2, 0, MAX (0, screen_width - requisition.width));
34 y = CLAMP (y - 2, 0, MAX (0, screen_height - requisition.height));
35
36 *xp = x;
37 *yp = y;
38 }
39
40 void
gtk_menu_popup_interp(GtkMenu * menu,GtkWidget * parent_menu_shell,GtkWidget * parent_menu_item,gint button,guint32 activate_time,repv position)41 gtk_menu_popup_interp (GtkMenu *menu,
42 GtkWidget *parent_menu_shell,
43 GtkWidget *parent_menu_item,
44 gint button,
45 guint32 activate_time,
46 repv position)
47 {
48 GtkMenuPositionFunc func = 0;
49 gpointer func_data = 0;
50
51 if (rep_CONSP (position)
52 && rep_INTP(rep_CAR(position)) && rep_INTP(rep_CDR(position)))
53 {
54 gulong coded = (rep_INT(rep_CAR(position))
55 | (rep_INT(rep_CDR(position)) << 16));
56
57 func = menu_popup_position;
58 func_data = (void *) coded;
59 }
60
61 gtk_menu_popup (menu, parent_menu_shell, parent_menu_item,
62 func, func_data, button, activate_time);
63 }
64
65 #if 1 /* || (GTK_MAJOR_VERSION < 2 || (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 4)) */
66 GtkWidget*
gtk_radio_menu_item_new_with_label_from_widget(GtkRadioMenuItem * group,const gchar * label)67 gtk_radio_menu_item_new_with_label_from_widget (GtkRadioMenuItem *group,
68 const gchar *label)
69 {
70 GSList *g = group? gtk_radio_menu_item_group (group) : NULL;
71 return gtk_radio_menu_item_new_with_label (g, label);
72 }
73
74 GtkWidget*
gtk_radio_menu_item_new_with_mnemonic_from_widget(GtkRadioMenuItem * group,const gchar * label)75 gtk_radio_menu_item_new_with_mnemonic_from_widget (GtkRadioMenuItem *group,
76 const gchar *label)
77 {
78 GSList *g = group? gtk_radio_menu_item_group (group) : NULL;
79 return gtk_radio_menu_item_new_with_mnemonic (g, label);
80 }
81
82 GtkWidget*
gtk_radio_menu_item_new_from_widget(GtkRadioMenuItem * group)83 gtk_radio_menu_item_new_from_widget (GtkRadioMenuItem *group)
84 {
85 GSList *g = group? gtk_radio_menu_item_group (group) : NULL;
86 return gtk_radio_menu_item_new (g);
87 }
88 #endif /* < 2.4 */
89
90 GtkWidget*
gtk_pixmap_new_interp(gchar * file,GtkWidget * intended_parent)91 gtk_pixmap_new_interp (gchar *file,
92 GtkWidget *intended_parent)
93 {
94 GtkStyle *style;
95 GdkPixmap *pixmap;
96 GdkBitmap *mask;
97
98 style = gtk_widget_get_style (intended_parent);
99 pixmap = gdk_pixmap_create_from_xpm (GDK_ROOT_PARENT(), &mask,
100 &style->bg[GTK_STATE_NORMAL],
101 file);
102 return gtk_pixmap_new (pixmap, mask);
103 }
104
105 GdkColor*
gdk_color_parse_interp(char * spec)106 gdk_color_parse_interp (char *spec)
107 {
108 /* not reentrant */
109 static GdkColor color;
110 if (!gdk_color_parse (spec, &color))
111 return NULL;
112 return &color;
113 }
114
115 GdkColor*
gtk_style_get_white_interp(GtkStyle * style)116 gtk_style_get_white_interp (GtkStyle *style)
117 {
118 return &style->white;
119 }
120
121 #ifndef HAVE_GTK_WIDGET_PEEK_COLORMAP
122 GdkColormap *
gtk_widget_peek_colormap()123 gtk_widget_peek_colormap ()
124 {
125 return gtk_widget_get_default_colormap ();
126 }
127 #endif
128
129 void
gtk_list_append_item(GtkList * list,GtkListItem * item)130 gtk_list_append_item (GtkList *list, GtkListItem *item)
131 {
132 GList *items = g_list_alloc ();
133 items->data = item;
134 gtk_list_append_items (list, items);
135 }
136
137 void
gtk_list_prepend_item(GtkList * list,GtkListItem * item)138 gtk_list_prepend_item (GtkList *list, GtkListItem *item)
139 {
140 GList *items = g_list_alloc ();
141 items->data = item;
142 gtk_list_prepend_items (list, items);
143 }
144
145 #ifndef HAVE_GTK_TYPE_GET_INFO
146 gboolean
gtk_type_get_info(GtkType type,GtkTypeInfo * info)147 gtk_type_get_info (GtkType type, GtkTypeInfo *info)
148 {
149 g_warning("Your version of Gtk+ does not support gtk_type_get_info");
150 return FALSE;
151 }
152 #endif
153
154 #ifndef HAVE_GTK_SIGNAL_SET_CLASS_FUNCTION_FULL
155 void
gtk_signal_set_class_function_full(GtkType type,const gchar * signal,GtkSignalFunc func,GtkCallbackMarshal marshal,gpointer data,GtkDestroyNotify destroy_func)156 gtk_signal_set_class_function_full (GtkType type,
157 const gchar *signal,
158 GtkSignalFunc func,
159 GtkCallbackMarshal marshal,
160 gpointer data,
161 GtkDestroyNotify destroy_func)
162 {
163 g_warning("Your version of Gtk+ does not support"
164 " gtk_signal_set_class_function_full");
165 }
166 #endif
167
168 void
gtk_color_selection_set_color_interp(GtkColorSelection * selection,GdkColor * color)169 gtk_color_selection_set_color_interp (GtkColorSelection *selection, GdkColor *color)
170 {
171 gdouble vals[4];
172
173 vals[0] = color->red / 65535.0;
174 vals[1] = color->green / 65535.0;
175 vals[2] = color->blue / 65535.0;
176 vals[3] = 1.0;
177
178 gtk_color_selection_set_color (selection, vals);
179 }
180
181
182 GdkColor *
gtk_color_selection_get_color_interp(GtkColorSelection * selection)183 gtk_color_selection_get_color_interp (GtkColorSelection *selection)
184 {
185 gdouble vals[4];
186 GdkColor dummy, *color;
187
188 gtk_color_selection_get_color (selection, vals);
189
190 /* XXX I don't know if this is a sensible way to obtain a new
191 GdkColor */
192 color = gdk_color_copy (&dummy);
193
194 /* Since this color is not part of a colormap, the pixel value is
195 pointless */
196 color->pixel = 0;
197 color->red = (gushort) (65535.0 * vals[0]);
198 color->green = (gushort) (65535.0 * vals[1]);
199 color->blue = (gushort) (65535.0 * vals[2]);
200
201 return color;
202 }
203
204 char *
gtk_color_button_get_color_interp(GtkColorButton * button)205 gtk_color_button_get_color_interp (GtkColorButton *button)
206 {
207 GdkColor color;
208 gchar *str;
209
210 gtk_color_button_get_color (button, &color);
211
212 str = g_strdup_printf ("#%02x%02x%02x", color.red >> 8,
213 color.green >> 8, color.blue >> 8);
214
215 return str;
216 }
217
218 void
gtk_widget_draw_interp(GtkWidget * widget)219 gtk_widget_draw_interp (GtkWidget *widget)
220 {
221 gtk_widget_draw (widget, NULL);
222 }
223
224 /* status icon hack */
225
226 void
gtk_status_icon_popup_menu(GtkStatusIcon * status_icon,GtkMenu * menu,guint button,guint32 activate_time)227 gtk_status_icon_popup_menu(GtkStatusIcon *status_icon,
228 GtkMenu *menu,
229 guint button,
230 guint32 activate_time)
231 {
232 GtkMenuPositionFunc pos_func = gtk_status_icon_position_menu;
233 gpointer user_data = status_icon;
234 gtk_menu_popup (menu, NULL, NULL,
235 pos_func, user_data, button, activate_time);
236 }
237
238 gboolean
gtk_status_icon_get_geometry_interp(GtkStatusIcon * status_icon,gint * x,gint * y,GtkOrientation * orientation)239 gtk_status_icon_get_geometry_interp(GtkStatusIcon *status_icon,
240 gint *x,
241 gint *y,
242 GtkOrientation *orientation)
243 {
244 GdkRectangle area;
245 gboolean ret = gtk_status_icon_get_geometry(status_icon,
246 NULL,
247 &area,
248 orientation);
249 if(!ret)
250 return ret;
251 *x = area.x;
252 *y = area.y;
253 return ret;
254 }
255