9ca23c9b4e17c635e8dd106a072e5f4525f4609b
[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.4 2000-11-09 20:30:16 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 /* Tree item */
132
133 GtkWidget*
134 gtk_tree_item_get_subtree (GtkTreeItem* tree_item)
135 {
136 return GTK_TREE_ITEM_SUBTREE (tree_item);
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 /* CList */
235
236 #ifdef CLIST
237 GList*
238 gtk_clist_selection (GtkCList *clist)
239 {
240 return clist->selection;
241 }
242
243 gint
244 gtk_clist_get_titles_visible (GtkCList *clist)
245 {
246 return (clist->title_window && GTK_WIDGET_VISIBLE (clist->title_window));
247 }
248
249 gint
250 gtk_clist_get_n_rows (GtkCList *clist)
251 {
252 return clist->rows;
253 }
254
255 gint
256 gtk_clist_get_focus_row (GtkCList *clist)
257 {
258 return clist->focus_row;
259 }
260
261 gint
262 gtk_clist_get_sort_column (GtkCList *clist)
263 {
264 return clist->sort_column;
265 }
266
267 GtkJustification
268 gtk_clist_column_justification (GtkCList *clist,
269 gint column)
270 {
271 return clist->column[column].justification;
272 }
273
274 gboolean
275 gtk_clist_column_visible_p (GtkCList *clist,
276 gint column)
277 {
278 return clist->column[column].visible;
279 }
280
281 gboolean
282 gtk_clist_column_resizeable_p (GtkCList *clist,
283 gint column)
284 {
285 return clist->column[column].resizeable;
286 }
287
288 gboolean
289 gtk_clist_column_auto_resize_p (GtkCList *clist,
290 gint column)
291 {
292 return clist->column[column].auto_resize;
293 }
294
295 gint
296 gtk_clist_column_width (GtkCList *clist,
297 gint column)
298 {
299 return clist->column[column].width;
300 }
301
302 gboolean
303 gtk_clist_auto_sort_p (GtkCList *clist)
304 {
305 return GTK_CLIST_AUTO_SORT (clist);
306 }
307 #endif
308
309 /* CTree */
310
311 #ifdef CTREE
312 gboolean
313 gtk_ctree_node_leaf_p (GtkCTreeNode* node)
314 {
315 return GTK_CTREE_ROW (node)->is_leaf;
316 }
317
318 GtkCTreeNode*
319 gtk_ctree_node_child (GtkCTreeNode* node)
320 {
321 return GTK_CTREE_ROW (node)->children;
322 }
323
324 GtkCTreeNode*
325 gtk_ctree_node_parent (GtkCTreeNode* node)
326 {
327 return GTK_CTREE_ROW (node)->parent;
328 }
329
330 GtkCTreeNode*
331 gtk_ctree_node_sibling (GtkCTreeNode* node)
332 {
333 return GTK_CTREE_ROW (node)->sibling;
334 }
335
336 gint
337 gtk_ctree_node_level (GtkCTreeNode* node)
338 {
339 return GTK_CTREE_ROW (node)->level;
340 }
341 #endif
342
343 /* Paned */
344
345 GtkWidget*
346 gtk_paned_child1 (GtkPaned *paned, guint *resize, guint *shrink)
347 {
348 *resize = paned->child1_resize;
349 *shrink = paned->child1_shrink;
350
351 return paned->child1;
352 }
353
354
355 GtkWidget*
356 gtk_paned_child2 (GtkPaned *paned, guint *resize, guint *shrink)
357 {
358 *resize = paned->child2_resize;
359 *shrink = paned->child2_shrink;
360
361 return paned->child2;
362 }
363
364 gint
365 gtk_paned_get_position (GtkPaned *paned)
366 {
367 if (paned->position_set == TRUE)
368 return paned->child1_size;
369 else
370 return -1;
371 }
372
373
374 /* Layout */
375
376 gint
377 gtk_layout_get_size (GtkLayout *layout, gint *width, gint *height)
378
379 {
380 *width = layout->width;
381 *height = layout->height;
382 }
383
384 GdkWindow*
385 gtk_layout_get_bin_window (GtkLayout *layout)
386 {
387 return layout->bin_window;
388 }
389
390
391 /* List */
392
393 GList*
394 gtk_list_selection (GtkList *list)
395 {
396 return list->selection;
397 }
398
399
400 /* Menu */
401
402 gboolean
403 gtk_menu_get_tearoff_state (GtkMenu *menu)
404 {
405 return menu->torn_off;
406 }
407
408 gchar*
409 gtk_menu_get_title (GtkMenu *menu)
410 {
411 return g_strdup (gtk_object_get_data (GTK_OBJECT (menu), "gtk-menu-title"));
412 }
413
414
415 /* Table */
416
417 guint
418 gtk_table_row_spacing (GtkTable *table,
419 guint row)
420 {
421 return table->rows[row].spacing;
422 }
423
424 guint
425 gtk_table_column_spacing (GtkTable *table,
426 guint col)
427 {
428 return table->cols[col].spacing;
429 }
430
431
432 /* Toolbar */
433
434 gint
435 gtk_toolbar_num_children (GtkToolbar *toolbar)
436 {
437 return toolbar->num_children;
438 }
439
440 gint
441 gtk_toolbar_get_tooltips (GtkToolbar *toolbar)
442 {
443 return toolbar->tooltips->enabled;
444 }
445
446
447 /* Tree */
448
449 GtkSelectionMode
450 gtk_tree_get_selection_mode (GtkTree *tree)
451 {
452 return tree->selection_mode;
453 }
454
455 GtkSelectionMode
456 gtk_tree_get_view_mode (GtkTree *tree)
457 {
458 return tree->view_mode;
459 }
460
461 GtkSelectionMode
462 gtk_tree_get_view_lines (GtkTree *tree)
463 {
464 return tree->view_mode;
465 }
466
467 GtkTree*
468 gtk_tree_get_root_tree (GtkTree *tree)
469 {
470 return GTK_TREE_ROOT_TREE (tree);
471 }
472
473 GList*
474 gtk_tree_selection (GtkTree *tree)
475 {
476 return GTK_TREE_SELECTION (tree);
477 }
478
479
480 /* Drawing area */
481
482 void
483 gtk_drawing_area_get_size (GtkDrawingArea *darea, gint *width, gint *height)
484 {
485 GtkWidget *widget;
486
487 widget = GTK_WIDGET (darea);
488 *width = widget->allocation.width;
489 *height = widget->allocation.height;
490 }
491
492
493 /* Progress */
494
495 gchar*
496 gtk_progress_get_format_string (GtkProgress *progress)
497 {
498 return progress->format;
499 }
500
501 GtkAdjustment*
502 gtk_progress_get_adjustment (GtkProgress *progress)
503 {
504 return progress->adjustment;
505 }
506
507
508 /* Scrolled window */
509
510 GtkWidget*
511 gtk_scrolled_window_get_hscrollbar (GtkScrolledWindow *window)
512 {
513 return window->hscrollbar;
514 }
515
516 GtkWidget*
517 gtk_scrolled_window_get_vscrollbar (GtkScrolledWindow *window)
518 {
519 return window->vscrollbar;
520 }
521
522
523
524 /* Tooltips */
525
526 guint
527 gtk_tooltips_get_delay (GtkTooltips *tooltips)
528 {
529 return tooltips->delay;
530 }
531
532 gboolean
533 gtk_tooltips_get_enabled (GtkTooltips *tooltips)
534 {
535 return tooltips->enabled;
536 }
537
538
539 /* GtkStyle accessor functions */
540
541 typedef enum {
542 GTK_COLOR_FG,
543 GTK_COLOR_BG,
544 GTK_COLOR_LIGHT,
545 GTK_COLOR_DARK,
546 GTK_COLOR_MID,
547 GTK_COLOR_TEXT,
548 GTK_COLOR_BASE,
549 GTK_COLOR_WHITE,
550 GTK_COLOR_BLACK
551 } GtkColorType;
552
553 GdkColor*
554 gtk_style_get_color (GtkStyle *style, GtkColorType color_type,
555 GtkStateType state)
556 {
557 switch (color_type)
558 {
559 case GTK_COLOR_WHITE:
560 return &style->white;
561 case GTK_COLOR_BLACK:
562 return &style->black;
563 case GTK_COLOR_FG:
564 return &style->fg[state];
565 case GTK_COLOR_BG:
566 return &style->bg[state];
567 case GTK_COLOR_LIGHT:
568 return &style->light[state];
569 case GTK_COLOR_DARK:
570 return &style->dark[state];
571 case GTK_COLOR_MID:
572 return &style->mid[state];
573 case GTK_COLOR_TEXT:
574 return &style->text[state];
575 case GTK_COLOR_BASE:
576 return &style->base[state];
577 }
578 }
579
580
581 GdkColor*
582 gtk_style_set_color (GtkStyle *style, GtkColorType color_type,
583 GtkStateType state, GdkColor *color)
584 {
585 switch (color_type)
586 {
587 case GTK_COLOR_WHITE:
588 style->white = *color; break;
589 case GTK_COLOR_BLACK:
590 style->black = *color; break;
591 case GTK_COLOR_FG:
592 style->fg[state] = *color; break;
593 case GTK_COLOR_BG:
594 style->bg[state] = *color; break;
595 case GTK_COLOR_LIGHT:
596 style->light[state] = *color; break;
597 case GTK_COLOR_DARK:
598 style->dark[state] = *color; break;
599 case GTK_COLOR_MID:
600 style->mid[state] = *color; break;
601 case GTK_COLOR_TEXT:
602 style->text[state] = *color; break;
603 case GTK_COLOR_BASE:
604 style->base[state] = *color; break;
605 }
606
607 return gtk_style_get_color (style, color_type, state);
608 }
609
610
611 GdkFont*
612 gtk_style_get_font (GtkStyle *style)
613 {
614 return style->font;
615 }
616
617
618 GdkFont*
619 gtk_style_set_font (GtkStyle *style, GdkFont *font)
620 {
621 return style->font = font;
622 }
623
624
625 GdkGC*
626 gtk_style_get_gc (GtkStyle *style, GtkColorType color_type, GtkStateType state)
627 {
628 switch (color_type)
629 {
630 case GTK_COLOR_WHITE:
631 return style->white_gc;
632 case GTK_COLOR_BLACK:
633 return style->black_gc;
634 case GTK_COLOR_FG:
635 return style->fg_gc[state];
636 case GTK_COLOR_BG:
637 return style->bg_gc[state];
638 case GTK_COLOR_LIGHT:
639 return style->light_gc[state];
640 case GTK_COLOR_DARK:
641 return style->dark_gc[state];
642 case GTK_COLOR_MID:
643 return style->mid_gc[state];
644 case GTK_COLOR_TEXT:
645 return style->text_gc[state];
646 case GTK_COLOR_BASE:
647 return style->base_gc[state];
648 }
649 }