Cleanups
[clg] / gtk / gtkglue.c
CommitLineData
560af5c5 1/* Common Lisp bindings for GTK+ v2.0
c8c48a4c 2 * Copyright (C) 1999-2000 Espen S. Johnsen <esj@stud.cs.uit.no>
560af5c5 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
c8c48a4c 19/* $Id: gtkglue.c,v 1.4 2000-11-09 20:30:16 espen Exp $ */
560af5c5 20
21
22#include <gtk/gtk.h>
23
560af5c5 24
25/*
26 *
27 * Gtk helper functions
28 *
29 */
30
31void
32gtk_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
42GtkType
43gtk_object_type (GtkObject *obj)
44{
45 return GTK_OBJECT_TYPE (obj);
46}
47
48
49
50/* Widget */
51
52GdkWindow*
53gtk_widget_get_window (GtkWidget *widget)
54{
55 return widget->window;
56}
57
58GtkStateType
59gtk_widget_get_state (GtkWidget *widget)
60{
61 return widget->state;
62}
63
64gboolean
65gtk_widget_mapped_p (GtkWidget *widget)
66{
67 return GTK_WIDGET_MAPPED (widget);
68}
69
70void
71gtk_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
80GtkWidget*
81gtk_container_get_focus_child (GtkContainer *container)
82{
83 return container->focus_child;
84}
85
86
87
88/* Menu item */
89
90GtkWidget*
91gtk_menu_item_get_submenu (GtkMenuItem* menu_item)
92{
93 return menu_item->submenu;
94}
95
c11e33f7 96GtkSubmenuPlacement
97gtk_menu_item_get_placement (GtkMenuItem* menu_item)
98{
99 return menu_item->submenu_placement;
100}
101
560af5c5 102gint
103gtk_menu_item_get_show_toggle (GtkMenuItem* menu_item)
104{
105 return menu_item->show_toggle_indicator;
106}
107
108gint
109gtk_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
118gboolean
119gtk_check_menu_item_get_active (GtkCheckMenuItem* check_menu_item)
120{
121 return check_menu_item->active;
122}
123
124gboolean
125gtk_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
133GtkWidget*
134gtk_tree_item_get_subtree (GtkTreeItem* tree_item)
135{
136 return GTK_TREE_ITEM_SUBTREE (tree_item);
137}
138
139
140/* Window */
141
142void
143gtk_window_wmclass (GtkWindow* window, gchar* name, gchar* class)
144{
145 name = window->wmclass_name;
146 class = window->wmclass_class;
147}
148
149
560af5c5 150/* File selection */
151
152GtkWidget*
153gtk_file_selection_get_action_area (GtkFileSelection *filesel)
154{
155 return filesel->action_area;
156}
157
158GtkWidget*
159gtk_file_selection_get_ok_button (GtkFileSelection *filesel)
160{
161 return filesel->ok_button;
162}
163
164GtkWidget*
165gtk_file_selection_get_cancel_button (GtkFileSelection *filesel)
166{
167 return filesel->cancel_button;
168}
169
170
171/* Color selection */
172
560af5c5 173gtk_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
189void
190gtk_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
209GtkWidget*
210gtk_combo_get_entry (GtkCombo *combo)
211{
212 return combo->entry;
213}
214
215gboolean
216gtk_combo_get_use_arrows (GtkCombo *combo)
217{
218 return combo->use_arrows;
219}
220
221gboolean
222gtk_combo_get_use_arrows_always (GtkCombo *combo)
223{
224 return combo->use_arrows_always;
225}
226
227gboolean
228gtk_combo_get_case_sensitive (GtkCombo *combo)
229{
230 return combo->case_sensitive;
231}
232
233
234/* CList */
235
236#ifdef CLIST
237GList*
238gtk_clist_selection (GtkCList *clist)
239{
240 return clist->selection;
241}
242
243gint
244gtk_clist_get_titles_visible (GtkCList *clist)
245{
246 return (clist->title_window && GTK_WIDGET_VISIBLE (clist->title_window));
247}
248
249gint
250gtk_clist_get_n_rows (GtkCList *clist)
251{
252 return clist->rows;
253}
254
255gint
256gtk_clist_get_focus_row (GtkCList *clist)
257{
258 return clist->focus_row;
259}
260
261gint
262gtk_clist_get_sort_column (GtkCList *clist)
263{
264 return clist->sort_column;
265}
266
267GtkJustification
268gtk_clist_column_justification (GtkCList *clist,
269 gint column)
270{
271 return clist->column[column].justification;
272}
273
274gboolean
275gtk_clist_column_visible_p (GtkCList *clist,
276 gint column)
277{
278 return clist->column[column].visible;
279}
280
281gboolean
282gtk_clist_column_resizeable_p (GtkCList *clist,
283 gint column)
284{
285 return clist->column[column].resizeable;
286}
287
288gboolean
289gtk_clist_column_auto_resize_p (GtkCList *clist,
290 gint column)
291{
292 return clist->column[column].auto_resize;
293}
294
295gint
296gtk_clist_column_width (GtkCList *clist,
297 gint column)
298{
299 return clist->column[column].width;
300}
301
302gboolean
303gtk_clist_auto_sort_p (GtkCList *clist)
304{
305 return GTK_CLIST_AUTO_SORT (clist);
306}
307#endif
308
309/* CTree */
310
311#ifdef CTREE
312gboolean
313gtk_ctree_node_leaf_p (GtkCTreeNode* node)
314{
315 return GTK_CTREE_ROW (node)->is_leaf;
316}
317
318GtkCTreeNode*
319gtk_ctree_node_child (GtkCTreeNode* node)
320{
321 return GTK_CTREE_ROW (node)->children;
322}
323
324GtkCTreeNode*
325gtk_ctree_node_parent (GtkCTreeNode* node)
326{
327 return GTK_CTREE_ROW (node)->parent;
328}
329
330GtkCTreeNode*
331gtk_ctree_node_sibling (GtkCTreeNode* node)
332{
333 return GTK_CTREE_ROW (node)->sibling;
334}
335
336gint
337gtk_ctree_node_level (GtkCTreeNode* node)
338{
339 return GTK_CTREE_ROW (node)->level;
340}
341#endif
342
343/* Paned */
344
345GtkWidget*
346gtk_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
355GtkWidget*
356gtk_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
364gint
365gtk_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
376gint
2f779f71 377gtk_layout_get_size (GtkLayout *layout, gint *width, gint *height)
560af5c5 378
379{
380 *width = layout->width;
381 *height = layout->height;
382}
383
560af5c5 384GdkWindow*
385gtk_layout_get_bin_window (GtkLayout *layout)
386{
387 return layout->bin_window;
388}
389
390
391/* List */
392
393GList*
394gtk_list_selection (GtkList *list)
395{
396 return list->selection;
397}
398
399
c11e33f7 400/* Menu */
401
402gboolean
403gtk_menu_get_tearoff_state (GtkMenu *menu)
404{
405 return menu->torn_off;
406}
407
408gchar*
409gtk_menu_get_title (GtkMenu *menu)
410{
411 return g_strdup (gtk_object_get_data (GTK_OBJECT (menu), "gtk-menu-title"));
412}
413
414
560af5c5 415/* Table */
416
417guint
418gtk_table_row_spacing (GtkTable *table,
419 guint row)
420{
421 return table->rows[row].spacing;
422}
423
424guint
425gtk_table_column_spacing (GtkTable *table,
426 guint col)
427{
428 return table->cols[col].spacing;
429}
430
431
432/* Toolbar */
433
434gint
435gtk_toolbar_num_children (GtkToolbar *toolbar)
436{
437 return toolbar->num_children;
438}
439
c11e33f7 440gint
441gtk_toolbar_get_tooltips (GtkToolbar *toolbar)
442{
443 return toolbar->tooltips->enabled;
444}
445
560af5c5 446
447/* Tree */
448
449GtkSelectionMode
450gtk_tree_get_selection_mode (GtkTree *tree)
451{
452 return tree->selection_mode;
453}
454
455GtkSelectionMode
456gtk_tree_get_view_mode (GtkTree *tree)
457{
458 return tree->view_mode;
459}
460
461GtkSelectionMode
462gtk_tree_get_view_lines (GtkTree *tree)
463{
464 return tree->view_mode;
465}
466
467GtkTree*
468gtk_tree_get_root_tree (GtkTree *tree)
469{
470 return GTK_TREE_ROOT_TREE (tree);
471}
472
473GList*
474gtk_tree_selection (GtkTree *tree)
475{
476 return GTK_TREE_SELECTION (tree);
477}
478
479
480/* Drawing area */
481
482void
483gtk_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
495gchar*
496gtk_progress_get_format_string (GtkProgress *progress)
497{
498 return progress->format;
499}
500
501GtkAdjustment*
502gtk_progress_get_adjustment (GtkProgress *progress)
503{
504 return progress->adjustment;
505}
506
507
508/* Scrolled window */
509
510GtkWidget*
511gtk_scrolled_window_get_hscrollbar (GtkScrolledWindow *window)
512{
513 return window->hscrollbar;
514}
515
516GtkWidget*
517gtk_scrolled_window_get_vscrollbar (GtkScrolledWindow *window)
518{
519 return window->vscrollbar;
520}
521
522
523
524/* Tooltips */
525
526guint
527gtk_tooltips_get_delay (GtkTooltips *tooltips)
528{
529 return tooltips->delay;
530}
531
c11e33f7 532gboolean
533gtk_tooltips_get_enabled (GtkTooltips *tooltips)
534{
535 return tooltips->enabled;
536}
560af5c5 537
538
539/* GtkStyle accessor functions */
540
541typedef 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
553GdkColor*
554gtk_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
581GdkColor*
582gtk_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
611GdkFont*
612gtk_style_get_font (GtkStyle *style)
613{
614 return style->font;
615}
616
617
618GdkFont*
619gtk_style_set_font (GtkStyle *style, GdkFont *font)
620{
621 return style->font = font;
622}
623
624
625GdkGC*
626gtk_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}