source: trunk/third/rep-gtk/gtk-compat.c @ 21217

Revision 21217, 5.9 KB checked in by ghudson, 20 years ago (diff)
Adapt unholy redefinition of gtk functions to gtk 2.4.
Line 
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
8gchar*
9gtk_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
18static void
19menu_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
40void
41gtk_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
65GtkWidget*
66gtk_radio_menu_item_new_with_label_from_widget (GtkRadioMenuItem *group,
67                                                const gchar      *label)
68{
69  GSList *g = group? gtk_radio_menu_item_group (group) : NULL;
70  return gtk_radio_menu_item_new_with_label (g, label);
71}
72
73GtkWidget*
74gtk_radio_menu_item_new_with_mnemonic_from_widget (GtkRadioMenuItem *group,
75                                                   const gchar      *label)
76{
77  GSList *g = group? gtk_radio_menu_item_group (group) : NULL;
78  return gtk_radio_menu_item_new_with_mnemonic (g, label);
79}
80
81GtkWidget*
82gtk_radio_menu_item_new_from_widget (GtkRadioMenuItem *group)
83{
84  GSList *g = group? gtk_radio_menu_item_group (group) : NULL;
85  return gtk_radio_menu_item_new (g);
86}
87
88GtkWidget*
89gtk_pixmap_new_interp (gchar *file,
90                       GtkWidget *intended_parent)
91{
92  GtkStyle *style;
93  GdkPixmap *pixmap;
94  GdkBitmap *mask;
95
96  style = gtk_widget_get_style (intended_parent);
97  pixmap = gdk_pixmap_create_from_xpm (GDK_ROOT_PARENT(), &mask,
98                                       &style->bg[GTK_STATE_NORMAL],
99                                       file);
100  return gtk_pixmap_new (pixmap, mask);
101}
102
103#ifndef HAVE_GDK_COLOR_COPY
104/*
105 *--------------------------------------------------------------
106 * gdk_color_copy
107 *
108 *   Copy a color structure into new storage.
109 *
110 * Arguments:
111 *   "color" is the color struct to copy.
112 *
113 * Results:
114 *   A new color structure.  Free it with gdk_color_free.
115 *
116 *--------------------------------------------------------------
117 */
118
119static GMemChunk *color_chunk;
120
121GdkColor*
122gdk_color_copy (GdkColor *color)
123{
124  GdkColor *new_color;
125 
126  g_return_val_if_fail (color != NULL, NULL);
127
128  if (color_chunk == NULL)
129    color_chunk = g_mem_chunk_new ("colors",
130                                   sizeof (GdkColor),
131                                   4096,
132                                   G_ALLOC_AND_FREE);
133
134  new_color = g_chunk_new (GdkColor, color_chunk);
135  *new_color = *color;
136  return new_color;
137}
138
139/*
140 *--------------------------------------------------------------
141 * gdk_color_free
142 *
143 *   Free a color structure obtained from gdk_color_copy.  Do not use
144 *   with other color structures.
145 *
146 * Arguments:
147 *   "color" is the color struct to free.
148 *
149 *-------------------------------------------------------------- */
150
151void
152gdk_color_free (GdkColor *color)
153{
154  g_assert (color_chunk != NULL);
155  g_return_if_fail (color != NULL);
156
157  g_mem_chunk_free (color_chunk, color);
158}
159#endif
160
161GdkColor*
162gdk_color_parse_interp (char *spec)
163{
164  /* not reentrant */
165  static GdkColor color;
166  if (!gdk_color_parse (spec, &color))
167    return NULL;
168  return &color;
169}
170
171GdkColor*
172gtk_style_get_white_interp (GtkStyle *style)
173{
174  return &style->white;
175}
176
177#ifndef HAVE_GTK_WIDGET_PEEK_COLORMAP
178GdkColormap *
179gtk_widget_peek_colormap ()
180{
181  return gtk_widget_get_default_colormap ();
182}
183#endif
184
185void
186gtk_list_append_item (GtkList *list, GtkListItem *item)
187{
188  GList *items = g_list_alloc ();
189  items->data = item;
190  gtk_list_append_items (list, items);
191}
192
193void
194gtk_list_prepend_item (GtkList *list, GtkListItem *item)
195{
196  GList *items = g_list_alloc ();
197  items->data = item;
198  gtk_list_prepend_items (list, items);
199}
200
201#ifndef HAVE_GTK_TYPE_GET_INFO
202gboolean
203gtk_type_get_info (GtkType type, GtkTypeInfo *info)
204{
205  g_warning("Your version of Gtk+ does not support gtk_type_get_info");
206  return FALSE;
207}
208#endif
209
210#ifndef HAVE_GTK_SIGNAL_SET_CLASS_FUNCTION_FULL
211void
212gtk_signal_set_class_function_full (GtkType            type,
213                                    const gchar       *signal,
214                                    GtkSignalFunc      func,
215                                    GtkCallbackMarshal marshal,
216                                    gpointer           data,
217                                    GtkDestroyNotify   destroy_func)
218{
219  g_warning("Your version of Gtk+ does not support"
220            " gtk_signal_set_class_function_full");
221}
222#endif
223
224void
225gtk_color_selection_set_color_interp (GtkColorSelection *selection, GdkColor *color)
226{
227  gdouble vals[4];
228 
229  vals[0] = color->red / 65535.0;
230  vals[1] = color->green / 65535.0;
231  vals[2] = color->blue / 65535.0;
232  vals[3] = 1.0;
233
234  gtk_color_selection_set_color (selection, vals);
235}
236
237
238GdkColor *
239gtk_color_selection_get_color_interp (GtkColorSelection *selection)
240{
241  gdouble vals[4];
242  GdkColor dummy, *color;
243
244  gtk_color_selection_get_color (selection, vals);
245
246  /* XXX I don't know if this is a sensible way to obtain a new
247     GdkColor */
248  color = gdk_color_copy (&dummy);
249
250  /* Since this color is not part of a colormap, the pixel value is
251     pointless */
252  color->pixel = 0;
253  color->red = (gushort) (65535.0 * vals[0]);
254  color->green = (gushort) (65535.0 * vals[1]);
255  color->blue = (gushort) (65535.0 * vals[2]);
256
257  return color;
258}
259
260void
261gtk_widget_draw_interp (GtkWidget *widget)
262{
263    gtk_widget_draw (widget, NULL);
264}
Note: See TracBrowser for help on using the repository browser.