chiark / gitweb /
Updated for gtk-1.3.11
[clg] / gtk / gtkglue.c
1 /* Common Lisp bindings for GTK+ v2.0
2  * Copyright (C) 1999-2000 Espen S. Johnsen <esj@stud.cs.uit.no>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 /* $Id: gtkglue.c,v 1.8 2001-12-12 20:24:41 espen Exp $ */
20
21
22 #include <gtk/gtk.h>
23
24
25 /*
26  *
27  * Gtk helper functions
28  *
29  */
30
31 void
32 gtk_query_version (guint *major, guint *minor, guint *micro)
33 {
34   *major = gtk_major_version;
35   *minor = gtk_minor_version;
36   *micro = gtk_micro_version;
37 }
38
39
40 /* Is this necessary? */
41
42 GtkType
43 gtk_object_type (GtkObject *obj)
44 {
45   return GTK_OBJECT_TYPE (obj);
46 }
47
48
49
50 /* Widget */
51
52 GdkWindow*
53 gtk_widget_get_window (GtkWidget *widget)
54 {
55   return widget->window;
56 }
57
58 GtkStateType
59 gtk_widget_get_state (GtkWidget *widget)
60 {
61   return widget->state;
62 }
63
64 gboolean
65 gtk_widget_mapped_p (GtkWidget *widget)
66 {
67   return GTK_WIDGET_MAPPED (widget);
68 }
69
70 void
71 gtk_widget_allocation (GtkWidget *widget, int *width, int *height)
72 {
73   *width = widget->allocation.width;
74   *height = widget->allocation.height;
75 }
76
77
78 /* Container */
79
80 GtkWidget*
81 gtk_container_get_focus_child (GtkContainer *container)
82 {
83   return container->focus_child;
84 }
85
86
87 /* Dialog */
88
89 GtkWidget*
90 gtk_dialog_get_vbox (GtkDialog *dialog)
91 {
92   return dialog->vbox;
93 }
94
95 GtkWidget*
96 gtk_dialog_get_action_area (GtkDialog *dialog)
97 {
98   return dialog->action_area;
99 }
100
101
102
103 /* Menu item */
104
105 GtkSubmenuPlacement
106 gtk_menu_item_get_placement (GtkMenuItem* menu_item)
107 {
108   return menu_item->submenu_placement;
109 }
110
111 gint
112 gtk_menu_item_get_show_submenu (GtkMenuItem* menu_item)
113 {
114   return menu_item->show_submenu_indicator;
115 }
116
117 void
118 gtk_menu_item_set_show_submenu (GtkMenuItem* menu_item, guint show)
119 {
120   menu_item->show_submenu_indicator = show;
121 }
122
123
124
125 /* Check menu item */
126
127 gboolean
128 gtk_check_menu_item_get_active (GtkCheckMenuItem* check_menu_item)
129 {
130   return check_menu_item->active;
131 }
132
133 gboolean
134 gtk_check_menu_item_get_show_toggle (GtkCheckMenuItem* check_menu_item)
135 {
136   return check_menu_item->always_show_toggle;
137 }
138
139
140 /* Window */
141
142 void
143 gtk_window_wmclass (GtkWindow* window, gchar* name, gchar* class)
144 {
145   name = window->wmclass_name;
146   class = window->wmclass_class;
147 }
148
149
150 /* File selection */
151
152 GtkWidget*
153 gtk_file_selection_get_action_area (GtkFileSelection *filesel)
154 {
155   return filesel->action_area;
156 }
157
158 GtkWidget*
159 gtk_file_selection_get_ok_button (GtkFileSelection *filesel)
160 {
161   return filesel->ok_button;
162 }
163
164 GtkWidget*
165 gtk_file_selection_get_cancel_button (GtkFileSelection *filesel)
166 {
167   return filesel->cancel_button;
168 }
169
170
171 /* Color selection */
172
173 gtk_color_selection_set_color_by_values (GtkColorSelection *colorsel,
174                                          gdouble red,
175                                          gdouble green,
176                                          gdouble blue,
177                                          gdouble opacity)
178 {
179   gdouble color[4];
180
181   color[0] = red;
182   color[1] = green;
183   color[2] = blue;
184   color[3] = opacity;
185
186   gtk_color_selection_set_color (colorsel, color);
187 }
188
189 void
190 gtk_color_selection_get_color_as_values (GtkColorSelection *colorsel,
191                                          gdouble *red,
192                                          gdouble *green,
193                                          gdouble *blue,
194                                          gdouble *opacity)
195 {
196   gdouble color[4];
197
198   gtk_color_selection_get_color (colorsel, color);
199
200   *red = color[0];
201   *green = color[1];
202   *blue = color[2];
203   *opacity = color[3];
204 }
205
206
207 /* Combo */
208
209 GtkWidget*
210 gtk_combo_get_entry (GtkCombo *combo)
211 {
212   return combo->entry;
213 }
214
215 gboolean
216 gtk_combo_get_use_arrows (GtkCombo *combo)
217 {
218   return combo->use_arrows;
219 }
220
221 gboolean
222 gtk_combo_get_use_arrows_always (GtkCombo *combo)
223 {
224   return combo->use_arrows_always;
225 }
226
227 gboolean
228 gtk_combo_get_case_sensitive (GtkCombo *combo)
229 {
230   return combo->case_sensitive;
231 }
232
233
234 /* Paned */
235
236 GtkWidget*
237 gtk_paned_child1 (GtkPaned *paned, guint *resize, guint *shrink)
238 {
239   *resize = paned->child1_resize;
240   *shrink = paned->child1_shrink;
241   
242   return paned->child1;
243 }
244
245
246 GtkWidget*
247 gtk_paned_child2 (GtkPaned *paned, guint *resize, guint *shrink)
248 {
249   *resize = paned->child2_resize;
250   *shrink = paned->child2_shrink;
251   
252   return paned->child2;
253 }
254
255 gint
256 gtk_paned_get_position (GtkPaned *paned)
257 {
258   if (paned->position_set == TRUE) 
259     return paned->child1_size;
260   else
261     return -1;
262 }
263
264
265 /* Layout */
266
267 GdkWindow*
268 gtk_layout_get_bin_window (GtkLayout *layout)
269 {
270   return layout->bin_window;
271 }
272
273
274 /* List */
275
276 GList*
277 gtk_list_selection (GtkList *list)
278 {
279   return list->selection;
280 }
281
282
283
284 /* Toolbar */
285
286 gint
287 gtk_toolbar_num_children (GtkToolbar *toolbar)
288 {
289   return toolbar->num_children;
290 }
291
292 gint
293 gtk_toolbar_get_tooltips (GtkToolbar *toolbar)
294 {
295   return toolbar->tooltips->enabled;
296 }
297
298
299 /* Drawing area */
300
301 void
302 gtk_drawing_area_get_size (GtkDrawingArea *darea, gint *width, gint *height)
303 {
304   GtkWidget *widget;
305
306   widget = GTK_WIDGET (darea);
307   *width = widget->allocation.width;
308   *height = widget->allocation.height;
309 }
310
311
312 /* Progress */
313
314 gchar*
315 gtk_progress_get_format_string (GtkProgress *progress)
316 {
317   return progress->format;
318 }
319
320 GtkAdjustment*
321 gtk_progress_get_adjustment (GtkProgress *progress)
322 {
323   return progress->adjustment;
324 }
325
326
327 /* Tooltips */
328
329 gboolean
330 gtk_tooltips_get_enabled (GtkTooltips *tooltips)
331 {
332   return tooltips->enabled;
333 }
334
335
336 /* GtkStyle accessor functions */
337
338 typedef enum {
339   GTK_COLOR_FG,
340   GTK_COLOR_BG,
341   GTK_COLOR_LIGHT,
342   GTK_COLOR_DARK,
343   GTK_COLOR_MID,
344   GTK_COLOR_TEXT,
345   GTK_COLOR_BASE,
346   GTK_COLOR_WHITE,
347   GTK_COLOR_BLACK
348 } GtkColorType;
349
350 GdkColor*
351 gtk_style_get_color (GtkStyle *style, GtkColorType color_type,
352                      GtkStateType state)
353 {
354   switch (color_type)
355     {
356     case GTK_COLOR_WHITE:
357       return &style->white;
358     case GTK_COLOR_BLACK:
359       return &style->black;
360     case GTK_COLOR_FG:
361       return &style->fg[state];
362     case GTK_COLOR_BG:
363       return &style->bg[state];
364     case GTK_COLOR_LIGHT:
365       return &style->light[state];
366     case GTK_COLOR_DARK:
367       return &style->dark[state];
368     case GTK_COLOR_MID:
369       return &style->mid[state];
370     case GTK_COLOR_TEXT:
371       return &style->text[state];
372     case GTK_COLOR_BASE:
373       return &style->base[state];
374     }
375 }
376
377
378 GdkColor*
379 gtk_style_set_color (GtkStyle *style, GtkColorType color_type,
380                      GtkStateType state, GdkColor *color)
381 {
382   switch (color_type)
383     {
384     case GTK_COLOR_WHITE:
385       style->white = *color; break;
386     case GTK_COLOR_BLACK:
387       style->black = *color; break;
388     case GTK_COLOR_FG:
389       style->fg[state] = *color; break;
390     case GTK_COLOR_BG:
391       style->bg[state]  = *color; break;
392     case GTK_COLOR_LIGHT:
393       style->light[state]  = *color; break;
394     case GTK_COLOR_DARK:
395       style->dark[state]  = *color; break;
396     case GTK_COLOR_MID:
397       style->mid[state]  = *color; break;
398     case GTK_COLOR_TEXT:
399       style->text[state]  = *color; break;
400     case GTK_COLOR_BASE:
401       style->base[state]  = *color; break;
402     }
403
404   return gtk_style_get_color (style, color_type, state);
405 }
406
407 /*
408 GdkFont*
409 gtk_style_get_font (GtkStyle *style)
410 {
411   return style->font;
412 }
413
414
415 GdkFont*
416 gtk_style_set_font (GtkStyle *style, GdkFont *font)
417 {
418   return style->font = font;
419 }
420 */
421
422 GdkGC*
423 gtk_style_get_gc (GtkStyle *style, GtkColorType color_type, GtkStateType state)
424 {
425   switch (color_type)
426     {
427     case GTK_COLOR_WHITE:
428       return style->white_gc;
429     case GTK_COLOR_BLACK:
430       return style->black_gc;
431     case GTK_COLOR_FG:
432       return style->fg_gc[state];
433     case GTK_COLOR_BG:
434       return style->bg_gc[state];
435     case GTK_COLOR_LIGHT:
436       return style->light_gc[state];
437     case GTK_COLOR_DARK:
438       return style->dark_gc[state];
439     case GTK_COLOR_MID:
440       return style->mid_gc[state];
441     case GTK_COLOR_TEXT:
442       return style->text_gc[state];
443     case GTK_COLOR_BASE:
444       return style->base_gc[state];
445     }
446 }