chiark / gitweb /
Updated for glib-1.3.4
[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.5 2001-04-29 20:12:12 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
88 /* Menu item */
89
90 GtkWidget*
91 gtk_menu_item_get_submenu (GtkMenuItem* menu_item)
92 {
93   return menu_item->submenu;
94 }
95
96 GtkSubmenuPlacement
97 gtk_menu_item_get_placement (GtkMenuItem* menu_item)
98 {
99   return menu_item->submenu_placement;
100 }
101
102 gint
103 gtk_menu_item_get_show_toggle (GtkMenuItem* menu_item)
104 {
105   return menu_item->show_toggle_indicator;
106 }
107
108 gint
109 gtk_menu_item_get_show_submenu (GtkMenuItem* menu_item)
110 {
111   return menu_item->show_submenu_indicator;
112 }
113
114
115
116 /* Check menu item */
117
118 gboolean
119 gtk_check_menu_item_get_active (GtkCheckMenuItem* check_menu_item)
120 {
121   return check_menu_item->active;
122 }
123
124 gboolean
125 gtk_check_menu_item_get_show_toggle (GtkCheckMenuItem* check_menu_item)
126 {
127   return check_menu_item->always_show_toggle;
128 }
129
130
131 /* Window */
132
133 void
134 gtk_window_wmclass (GtkWindow* window, gchar* name, gchar* class)
135 {
136   name = window->wmclass_name;
137   class = window->wmclass_class;
138 }
139
140
141 /* File selection */
142
143 GtkWidget*
144 gtk_file_selection_get_action_area (GtkFileSelection *filesel)
145 {
146   return filesel->action_area;
147 }
148
149 GtkWidget*
150 gtk_file_selection_get_ok_button (GtkFileSelection *filesel)
151 {
152   return filesel->ok_button;
153 }
154
155 GtkWidget*
156 gtk_file_selection_get_cancel_button (GtkFileSelection *filesel)
157 {
158   return filesel->cancel_button;
159 }
160
161
162 /* Color selection */
163
164 gtk_color_selection_set_color_by_values (GtkColorSelection *colorsel,
165                                          gdouble red,
166                                          gdouble green,
167                                          gdouble blue,
168                                          gdouble opacity)
169 {
170   gdouble color[4];
171
172   color[0] = red;
173   color[1] = green;
174   color[2] = blue;
175   color[3] = opacity;
176
177   gtk_color_selection_set_color (colorsel, color);
178 }
179
180 void
181 gtk_color_selection_get_color_as_values (GtkColorSelection *colorsel,
182                                          gdouble *red,
183                                          gdouble *green,
184                                          gdouble *blue,
185                                          gdouble *opacity)
186 {
187   gdouble color[4];
188
189   gtk_color_selection_get_color (colorsel, color);
190
191   *red = color[0];
192   *green = color[1];
193   *blue = color[2];
194   *opacity = color[3];
195 }
196
197
198 /* Combo */
199
200 GtkWidget*
201 gtk_combo_get_entry (GtkCombo *combo)
202 {
203   return combo->entry;
204 }
205
206 gboolean
207 gtk_combo_get_use_arrows (GtkCombo *combo)
208 {
209   return combo->use_arrows;
210 }
211
212 gboolean
213 gtk_combo_get_use_arrows_always (GtkCombo *combo)
214 {
215   return combo->use_arrows_always;
216 }
217
218 gboolean
219 gtk_combo_get_case_sensitive (GtkCombo *combo)
220 {
221   return combo->case_sensitive;
222 }
223
224
225 /* CList */
226
227 #ifdef CLIST
228 GList*
229 gtk_clist_selection (GtkCList *clist)
230 {
231   return clist->selection;
232 }
233
234 gint
235 gtk_clist_get_titles_visible (GtkCList *clist)
236 {
237   return (clist->title_window && GTK_WIDGET_VISIBLE (clist->title_window));
238 }
239
240 gint
241 gtk_clist_get_n_rows (GtkCList *clist)
242 {
243   return clist->rows;
244 }
245
246 gint
247 gtk_clist_get_focus_row (GtkCList *clist)
248 {
249   return clist->focus_row;
250 }
251
252 gint
253 gtk_clist_get_sort_column (GtkCList *clist)
254 {
255   return clist->sort_column;
256 }
257
258 GtkJustification
259 gtk_clist_column_justification (GtkCList *clist,
260                                  gint column)
261 {
262   return clist->column[column].justification;
263 }
264
265 gboolean
266 gtk_clist_column_visible_p (GtkCList *clist,
267                            gint column)
268 {
269   return clist->column[column].visible;
270 }
271
272 gboolean
273 gtk_clist_column_resizeable_p (GtkCList *clist,
274                              gint column)
275 {
276   return clist->column[column].resizeable;
277 }
278
279 gboolean
280 gtk_clist_column_auto_resize_p (GtkCList *clist,
281                                 gint column)
282 {
283   return clist->column[column].auto_resize;
284 }
285
286 gint
287 gtk_clist_column_width (GtkCList *clist,
288                         gint column)
289 {
290   return clist->column[column].width;
291 }
292
293 gboolean
294 gtk_clist_auto_sort_p (GtkCList *clist)
295 {
296   return GTK_CLIST_AUTO_SORT (clist);
297 }
298 #endif
299
300 /* CTree */
301
302 #ifdef CTREE
303 gboolean
304 gtk_ctree_node_leaf_p (GtkCTreeNode* node)
305 {
306   return GTK_CTREE_ROW (node)->is_leaf;
307 }
308
309 GtkCTreeNode*
310 gtk_ctree_node_child (GtkCTreeNode* node)
311 {
312   return GTK_CTREE_ROW (node)->children;
313 }
314
315 GtkCTreeNode*
316 gtk_ctree_node_parent (GtkCTreeNode* node)
317 {
318   return GTK_CTREE_ROW (node)->parent;
319 }
320
321 GtkCTreeNode*
322 gtk_ctree_node_sibling (GtkCTreeNode* node)
323 {
324   return GTK_CTREE_ROW (node)->sibling;
325 }
326
327 gint
328 gtk_ctree_node_level (GtkCTreeNode* node)
329 {
330   return GTK_CTREE_ROW (node)->level;
331 }
332 #endif
333
334 /* Paned */
335
336 GtkWidget*
337 gtk_paned_child1 (GtkPaned *paned, guint *resize, guint *shrink)
338 {
339   *resize = paned->child1_resize;
340   *shrink = paned->child1_shrink;
341   
342   return paned->child1;
343 }
344
345
346 GtkWidget*
347 gtk_paned_child2 (GtkPaned *paned, guint *resize, guint *shrink)
348 {
349   *resize = paned->child2_resize;
350   *shrink = paned->child2_shrink;
351   
352   return paned->child2;
353 }
354
355 gint
356 gtk_paned_get_position (GtkPaned *paned)
357 {
358   if (paned->position_set == TRUE) 
359     return paned->child1_size;
360   else
361     return -1;
362 }
363
364
365 /* Layout */
366
367 gint
368 gtk_layout_get_size (GtkLayout *layout, gint *width, gint *height)
369                  
370 {
371   *width =  layout->width;
372   *height = layout->height;
373 }
374
375 GdkWindow*
376 gtk_layout_get_bin_window (GtkLayout *layout)
377 {
378   return layout->bin_window;
379 }
380
381
382 /* List */
383
384 GList*
385 gtk_list_selection (GtkList *list)
386 {
387   return list->selection;
388 }
389
390
391 /* Menu */
392
393 gboolean
394 gtk_menu_get_tearoff_state (GtkMenu *menu)
395 {
396   return menu->torn_off;
397 }
398
399 gchar*
400 gtk_menu_get_title (GtkMenu *menu)
401 {
402   return g_strdup (gtk_object_get_data (GTK_OBJECT (menu), "gtk-menu-title"));
403 }
404
405
406 /* Table */
407
408 guint
409 gtk_table_row_spacing (GtkTable *table,
410                        guint row)
411 {
412   return table->rows[row].spacing;
413 }
414
415 guint
416 gtk_table_column_spacing (GtkTable *table,
417                           guint col)
418 {
419   return table->cols[col].spacing;
420 }
421
422
423 /* Toolbar */
424
425 gint
426 gtk_toolbar_num_children (GtkToolbar *toolbar)
427 {
428   return toolbar->num_children;
429 }
430
431 gint
432 gtk_toolbar_get_tooltips (GtkToolbar *toolbar)
433 {
434   return toolbar->tooltips->enabled;
435 }
436
437
438 /* Drawing area */
439
440 void
441 gtk_drawing_area_get_size (GtkDrawingArea *darea, gint *width, gint *height)
442 {
443   GtkWidget *widget;
444
445   widget = GTK_WIDGET (darea);
446   *width = widget->allocation.width;
447   *height = widget->allocation.height;
448 }
449
450
451 /* Progress */
452
453 gchar*
454 gtk_progress_get_format_string (GtkProgress *progress)
455 {
456   return progress->format;
457 }
458
459 GtkAdjustment*
460 gtk_progress_get_adjustment (GtkProgress *progress)
461 {
462   return progress->adjustment;
463 }
464
465
466 /* Scrolled window */
467      
468 GtkWidget*
469 gtk_scrolled_window_get_hscrollbar (GtkScrolledWindow *window)
470 {
471   return window->hscrollbar;
472 }
473
474 GtkWidget*
475 gtk_scrolled_window_get_vscrollbar (GtkScrolledWindow *window)
476 {
477   return window->vscrollbar;
478 }
479
480
481
482 /* Tooltips */
483
484 guint
485 gtk_tooltips_get_delay (GtkTooltips *tooltips)
486 {
487   return tooltips->delay;
488 }
489
490 gboolean
491 gtk_tooltips_get_enabled (GtkTooltips *tooltips)
492 {
493   return tooltips->enabled;
494 }
495
496
497 /* GtkStyle accessor functions */
498
499 typedef enum {
500   GTK_COLOR_FG,
501   GTK_COLOR_BG,
502   GTK_COLOR_LIGHT,
503   GTK_COLOR_DARK,
504   GTK_COLOR_MID,
505   GTK_COLOR_TEXT,
506   GTK_COLOR_BASE,
507   GTK_COLOR_WHITE,
508   GTK_COLOR_BLACK
509 } GtkColorType;
510
511 GdkColor*
512 gtk_style_get_color (GtkStyle *style, GtkColorType color_type,
513                      GtkStateType state)
514 {
515   switch (color_type)
516     {
517     case GTK_COLOR_WHITE:
518       return &style->white;
519     case GTK_COLOR_BLACK:
520       return &style->black;
521     case GTK_COLOR_FG:
522       return &style->fg[state];
523     case GTK_COLOR_BG:
524       return &style->bg[state];
525     case GTK_COLOR_LIGHT:
526       return &style->light[state];
527     case GTK_COLOR_DARK:
528       return &style->dark[state];
529     case GTK_COLOR_MID:
530       return &style->mid[state];
531     case GTK_COLOR_TEXT:
532       return &style->text[state];
533     case GTK_COLOR_BASE:
534       return &style->base[state];
535     }
536 }
537
538
539 GdkColor*
540 gtk_style_set_color (GtkStyle *style, GtkColorType color_type,
541                      GtkStateType state, GdkColor *color)
542 {
543   switch (color_type)
544     {
545     case GTK_COLOR_WHITE:
546       style->white = *color; break;
547     case GTK_COLOR_BLACK:
548       style->black = *color; break;
549     case GTK_COLOR_FG:
550       style->fg[state] = *color; break;
551     case GTK_COLOR_BG:
552       style->bg[state]  = *color; break;
553     case GTK_COLOR_LIGHT:
554       style->light[state]  = *color; break;
555     case GTK_COLOR_DARK:
556       style->dark[state]  = *color; break;
557     case GTK_COLOR_MID:
558       style->mid[state]  = *color; break;
559     case GTK_COLOR_TEXT:
560       style->text[state]  = *color; break;
561     case GTK_COLOR_BASE:
562       style->base[state]  = *color; break;
563     }
564
565   return gtk_style_get_color (style, color_type, state);
566 }
567
568
569 GdkFont*
570 gtk_style_get_font (GtkStyle *style)
571 {
572   return style->font;
573 }
574
575
576 GdkFont*
577 gtk_style_set_font (GtkStyle *style, GdkFont *font)
578 {
579   return style->font = font;
580 }
581
582
583 GdkGC*
584 gtk_style_get_gc (GtkStyle *style, GtkColorType color_type, GtkStateType state)
585 {
586   switch (color_type)
587     {
588     case GTK_COLOR_WHITE:
589       return style->white_gc;
590     case GTK_COLOR_BLACK:
591       return style->black_gc;
592     case GTK_COLOR_FG:
593       return style->fg_gc[state];
594     case GTK_COLOR_BG:
595       return style->bg_gc[state];
596     case GTK_COLOR_LIGHT:
597       return style->light_gc[state];
598     case GTK_COLOR_DARK:
599       return style->dark_gc[state];
600     case GTK_COLOR_MID:
601       return style->mid_gc[state];
602     case GTK_COLOR_TEXT:
603       return style->text_gc[state];
604     case GTK_COLOR_BASE:
605       return style->base_gc[state];
606     }
607 }