chiark / gitweb /
Added some accessor functions
[clg] / gtk / gtkglue.c
CommitLineData
560af5c5 1/* Common Lisp bindings for GTK+ v2.0
2 * Copyright (C) 1999-2000 Espen S. Johnsen <espejohn@online.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
c11e33f7 19/* $Id: gtkglue.c,v 1.2 2000-08-15 19:41:26 espen Exp $ */
560af5c5 20
21
22#include <gtk/gtk.h>
23
24#ifdef CMUCL
25#include "lisp.h"
26
27extern lispobj funcall1(lispobj function, lispobj arg0);
28extern lispobj funcall3(lispobj function, lispobj arg0,
29 lispobj arg1, lispobj arg2);
30
31lispobj callback_trampoline;
32lispobj destroy_user_data;
33#endif
34
35
36void callback_marshal (GtkObject *object,
37 gpointer data,
38 guint n_args,
39 GtkArg *args)
40{
41#ifdef CMUCL
42 funcall3 (callback_trampoline, alloc_number ((unsigned long)data),
43 alloc_number (n_args), alloc_sap (args));
44
45 /* lispobj lisp_args[4];
46
47 lisp_args[0] = alloc_sap (object);
48 lisp_args[1] = alloc_number ((unsigned long)data);
49 lisp_args[2] = alloc_number (n_args);
50 lisp_args[3] = alloc_sap (args);
51
52 call_into_lisp (callback_trampoline, lisp_args, 4);*/
53#elif defined(CLISP)
54 callback_trampoline ((unsigned long)data, n_args, (unsigned int) args);
55#endif
56}
57
58
59void destroy_marshal (gpointer data)
60{
61#ifdef CMUCL
62 funcall1 (destroy_user_data, alloc_number ((unsigned long)data));
63#elif defined(CLISP)
64 destroy_user_data ((unsigned long)data);
65#endif
66}
67
68#ifndef CMUCL
69void*
70callback_marshal_address ()
71{
72 return (void*)callback_marshal;
73}
74
75void*
76destroy_marshal_address ()
77{
78 return (void*)destroy_marshal;
79}
80#endif
81
82
83/*
84 *
85 * Gtk helper functions
86 *
87 */
88
89void
90gtk_query_version (guint *major, guint *minor, guint *micro)
91{
92 *major = gtk_major_version;
93 *minor = gtk_minor_version;
94 *micro = gtk_micro_version;
95}
96
97
98/* Is this necessary? */
99
100GtkType
101gtk_object_type (GtkObject *obj)
102{
103 return GTK_OBJECT_TYPE (obj);
104}
105
106
107
108/* Widget */
109
110GdkWindow*
111gtk_widget_get_window (GtkWidget *widget)
112{
113 return widget->window;
114}
115
116GtkStateType
117gtk_widget_get_state (GtkWidget *widget)
118{
119 return widget->state;
120}
121
122gboolean
123gtk_widget_mapped_p (GtkWidget *widget)
124{
125 return GTK_WIDGET_MAPPED (widget);
126}
127
128void
129gtk_widget_allocation (GtkWidget *widget, int *width, int *height)
130{
131 *width = widget->allocation.width;
132 *height = widget->allocation.height;
133}
134
135
136/* Container */
137
138GtkWidget*
139gtk_container_get_focus_child (GtkContainer *container)
140{
141 return container->focus_child;
142}
143
144
145
146/* Menu item */
147
148GtkWidget*
149gtk_menu_item_get_submenu (GtkMenuItem* menu_item)
150{
151 return menu_item->submenu;
152}
153
c11e33f7 154GtkSubmenuPlacement
155gtk_menu_item_get_placement (GtkMenuItem* menu_item)
156{
157 return menu_item->submenu_placement;
158}
159
560af5c5 160gint
161gtk_menu_item_get_show_toggle (GtkMenuItem* menu_item)
162{
163 return menu_item->show_toggle_indicator;
164}
165
166gint
167gtk_menu_item_get_show_submenu (GtkMenuItem* menu_item)
168{
169 return menu_item->show_submenu_indicator;
170}
171
172
173
174/* Check menu item */
175
176gboolean
177gtk_check_menu_item_get_active (GtkCheckMenuItem* check_menu_item)
178{
179 return check_menu_item->active;
180}
181
182gboolean
183gtk_check_menu_item_get_show_toggle (GtkCheckMenuItem* check_menu_item)
184{
185 return check_menu_item->always_show_toggle;
186}
187
188
189/* Tree item */
190
191GtkWidget*
192gtk_tree_item_get_subtree (GtkTreeItem* tree_item)
193{
194 return GTK_TREE_ITEM_SUBTREE (tree_item);
195}
196
197
198/* Window */
199
200void
201gtk_window_wmclass (GtkWindow* window, gchar* name, gchar* class)
202{
203 name = window->wmclass_name;
204 class = window->wmclass_class;
205}
206
207
208/* Color selection dialog */
209
210GtkWidget*
211gtk_color_selection_dialog_get_colorsel (GtkColorSelectionDialog* dialog)
212{
213 return dialog->colorsel;
214}
215
216/* GtkWidget* */
217/* gtk_color_selection_dialog_get_main_vbox (GtkColorSelectionDialog* dialog) */
218/* { */
219/* return dialog->main_vbox; */
220/* } */
221
222GtkWidget*
223gtk_color_selection_dialog_get_ok_button (GtkColorSelectionDialog* dialog)
224{
225 return dialog->ok_button;
226}
227
228/* GtkWidget* */
229/* gtk_color_selection_dialog_get_reset_button (GtkColorSelectionDialog* dialog) */
230/* { */
231/* return dialog->reset_button; */
232/* } */
233
234GtkWidget*
235gtk_color_selection_dialog_get_cancel_button (GtkColorSelectionDialog* dialog)
236{
237 return dialog->cancel_button;
238}
239
240GtkWidget*
241gtk_color_selection_dialog_get_help_button (GtkColorSelectionDialog* dialog)
242{
243 return dialog->help_button;
244}
245
246
247/* Dialog */
248
249GtkWidget*
250gtk_dialog_get_action_area (GtkDialog *dialog)
251{
252 return dialog->action_area;
253}
254
255
256GtkWidget*
257gtk_dialog_get_vbox (GtkDialog *dialog)
258{
259 return dialog->vbox;
260}
261
262
263/* File selection */
264
265GtkWidget*
266gtk_file_selection_get_action_area (GtkFileSelection *filesel)
267{
268 return filesel->action_area;
269}
270
271GtkWidget*
272gtk_file_selection_get_ok_button (GtkFileSelection *filesel)
273{
274 return filesel->ok_button;
275}
276
277GtkWidget*
278gtk_file_selection_get_cancel_button (GtkFileSelection *filesel)
279{
280 return filesel->cancel_button;
281}
282
283
284/* Color selection */
285
286void
287gtk_color_selection_set_color_by_values (GtkColorSelection *colorsel,
288 gdouble red,
289 gdouble green,
290 gdouble blue,
291 gdouble opacity)
292{
293 gdouble color[4];
294
295 color[0] = red;
296 color[1] = green;
297 color[2] = blue;
298 color[3] = opacity;
299
300 gtk_color_selection_set_color (colorsel, color);
301}
302
303void
304gtk_color_selection_get_color_as_values (GtkColorSelection *colorsel,
305 gdouble *red,
306 gdouble *green,
307 gdouble *blue,
308 gdouble *opacity)
309{
310 gdouble color[4];
311
312 gtk_color_selection_get_color (colorsel, color);
313
314 *red = color[0];
315 *green = color[1];
316 *blue = color[2];
317 *opacity = color[3];
318}
319
320
321/* Combo */
322
323GtkWidget*
324gtk_combo_get_entry (GtkCombo *combo)
325{
326 return combo->entry;
327}
328
329gboolean
330gtk_combo_get_use_arrows (GtkCombo *combo)
331{
332 return combo->use_arrows;
333}
334
335gboolean
336gtk_combo_get_use_arrows_always (GtkCombo *combo)
337{
338 return combo->use_arrows_always;
339}
340
341gboolean
342gtk_combo_get_case_sensitive (GtkCombo *combo)
343{
344 return combo->case_sensitive;
345}
346
347
348/* CList */
349
350#ifdef CLIST
351GList*
352gtk_clist_selection (GtkCList *clist)
353{
354 return clist->selection;
355}
356
357gint
358gtk_clist_get_titles_visible (GtkCList *clist)
359{
360 return (clist->title_window && GTK_WIDGET_VISIBLE (clist->title_window));
361}
362
363gint
364gtk_clist_get_n_rows (GtkCList *clist)
365{
366 return clist->rows;
367}
368
369gint
370gtk_clist_get_focus_row (GtkCList *clist)
371{
372 return clist->focus_row;
373}
374
375gint
376gtk_clist_get_sort_column (GtkCList *clist)
377{
378 return clist->sort_column;
379}
380
381GtkJustification
382gtk_clist_column_justification (GtkCList *clist,
383 gint column)
384{
385 return clist->column[column].justification;
386}
387
388gboolean
389gtk_clist_column_visible_p (GtkCList *clist,
390 gint column)
391{
392 return clist->column[column].visible;
393}
394
395gboolean
396gtk_clist_column_resizeable_p (GtkCList *clist,
397 gint column)
398{
399 return clist->column[column].resizeable;
400}
401
402gboolean
403gtk_clist_column_auto_resize_p (GtkCList *clist,
404 gint column)
405{
406 return clist->column[column].auto_resize;
407}
408
409gint
410gtk_clist_column_width (GtkCList *clist,
411 gint column)
412{
413 return clist->column[column].width;
414}
415
416gboolean
417gtk_clist_auto_sort_p (GtkCList *clist)
418{
419 return GTK_CLIST_AUTO_SORT (clist);
420}
421#endif
422
423/* CTree */
424
425#ifdef CTREE
426gboolean
427gtk_ctree_node_leaf_p (GtkCTreeNode* node)
428{
429 return GTK_CTREE_ROW (node)->is_leaf;
430}
431
432GtkCTreeNode*
433gtk_ctree_node_child (GtkCTreeNode* node)
434{
435 return GTK_CTREE_ROW (node)->children;
436}
437
438GtkCTreeNode*
439gtk_ctree_node_parent (GtkCTreeNode* node)
440{
441 return GTK_CTREE_ROW (node)->parent;
442}
443
444GtkCTreeNode*
445gtk_ctree_node_sibling (GtkCTreeNode* node)
446{
447 return GTK_CTREE_ROW (node)->sibling;
448}
449
450gint
451gtk_ctree_node_level (GtkCTreeNode* node)
452{
453 return GTK_CTREE_ROW (node)->level;
454}
455#endif
456
457/* Paned */
458
459GtkWidget*
460gtk_paned_child1 (GtkPaned *paned, guint *resize, guint *shrink)
461{
462 *resize = paned->child1_resize;
463 *shrink = paned->child1_shrink;
464
465 return paned->child1;
466}
467
468
469GtkWidget*
470gtk_paned_child2 (GtkPaned *paned, guint *resize, guint *shrink)
471{
472 *resize = paned->child2_resize;
473 *shrink = paned->child2_shrink;
474
475 return paned->child2;
476}
477
478gint
479gtk_paned_get_position (GtkPaned *paned)
480{
481 if (paned->position_set == TRUE)
482 return paned->child1_size;
483 else
484 return -1;
485}
486
487
488/* Layout */
489
490gint
491gtk_layout_size (GtkLayout *layout, gint *width, gint *height)
492
493{
494 *width = layout->width;
495 *height = layout->height;
496}
497
498void
499gtk_layout_offset (GtkLayout *layout, gint *x, gint *y)
500{
501 *x = layout->xoffset;
502 *y = layout->yoffset;
503}
504
505
506GdkWindow*
507gtk_layout_get_bin_window (GtkLayout *layout)
508{
509 return layout->bin_window;
510}
511
512
513/* List */
514
515GList*
516gtk_list_selection (GtkList *list)
517{
518 return list->selection;
519}
520
521
c11e33f7 522/* Menu */
523
524gboolean
525gtk_menu_get_tearoff_state (GtkMenu *menu)
526{
527 return menu->torn_off;
528}
529
530gchar*
531gtk_menu_get_title (GtkMenu *menu)
532{
533 return g_strdup (gtk_object_get_data (GTK_OBJECT (menu), "gtk-menu-title"));
534}
535
536
560af5c5 537/* Table */
538
539guint
540gtk_table_row_spacing (GtkTable *table,
541 guint row)
542{
543 return table->rows[row].spacing;
544}
545
546guint
547gtk_table_column_spacing (GtkTable *table,
548 guint col)
549{
550 return table->cols[col].spacing;
551}
552
553
554/* Toolbar */
555
556gint
557gtk_toolbar_num_children (GtkToolbar *toolbar)
558{
559 return toolbar->num_children;
560}
561
c11e33f7 562gint
563gtk_toolbar_get_tooltips (GtkToolbar *toolbar)
564{
565 return toolbar->tooltips->enabled;
566}
567
560af5c5 568
569/* Tree */
570
571GtkSelectionMode
572gtk_tree_get_selection_mode (GtkTree *tree)
573{
574 return tree->selection_mode;
575}
576
577GtkSelectionMode
578gtk_tree_get_view_mode (GtkTree *tree)
579{
580 return tree->view_mode;
581}
582
583GtkSelectionMode
584gtk_tree_get_view_lines (GtkTree *tree)
585{
586 return tree->view_mode;
587}
588
589GtkTree*
590gtk_tree_get_root_tree (GtkTree *tree)
591{
592 return GTK_TREE_ROOT_TREE (tree);
593}
594
595GList*
596gtk_tree_selection (GtkTree *tree)
597{
598 return GTK_TREE_SELECTION (tree);
599}
600
601
602/* Drawing area */
603
604void
605gtk_drawing_area_get_size (GtkDrawingArea *darea, gint *width, gint *height)
606{
607 GtkWidget *widget;
608
609 widget = GTK_WIDGET (darea);
610 *width = widget->allocation.width;
611 *height = widget->allocation.height;
612}
613
614
615/* Progress */
616
617gchar*
618gtk_progress_get_format_string (GtkProgress *progress)
619{
620 return progress->format;
621}
622
623GtkAdjustment*
624gtk_progress_get_adjustment (GtkProgress *progress)
625{
626 return progress->adjustment;
627}
628
629
630/* Scrolled window */
631
632GtkWidget*
633gtk_scrolled_window_get_hscrollbar (GtkScrolledWindow *window)
634{
635 return window->hscrollbar;
636}
637
638GtkWidget*
639gtk_scrolled_window_get_vscrollbar (GtkScrolledWindow *window)
640{
641 return window->vscrollbar;
642}
643
644
645
646/* Tooltips */
647
648guint
649gtk_tooltips_get_delay (GtkTooltips *tooltips)
650{
651 return tooltips->delay;
652}
653
c11e33f7 654gboolean
655gtk_tooltips_get_enabled (GtkTooltips *tooltips)
656{
657 return tooltips->enabled;
658}
560af5c5 659
660
661/* GtkStyle accessor functions */
662
663typedef enum {
664 GTK_COLOR_FG,
665 GTK_COLOR_BG,
666 GTK_COLOR_LIGHT,
667 GTK_COLOR_DARK,
668 GTK_COLOR_MID,
669 GTK_COLOR_TEXT,
670 GTK_COLOR_BASE,
671 GTK_COLOR_WHITE,
672 GTK_COLOR_BLACK
673} GtkColorType;
674
675GdkColor*
676gtk_style_get_color (GtkStyle *style, GtkColorType color_type,
677 GtkStateType state)
678{
679 switch (color_type)
680 {
681 case GTK_COLOR_WHITE:
682 return &style->white;
683 case GTK_COLOR_BLACK:
684 return &style->black;
685 case GTK_COLOR_FG:
686 return &style->fg[state];
687 case GTK_COLOR_BG:
688 return &style->bg[state];
689 case GTK_COLOR_LIGHT:
690 return &style->light[state];
691 case GTK_COLOR_DARK:
692 return &style->dark[state];
693 case GTK_COLOR_MID:
694 return &style->mid[state];
695 case GTK_COLOR_TEXT:
696 return &style->text[state];
697 case GTK_COLOR_BASE:
698 return &style->base[state];
699 }
700}
701
702
703GdkColor*
704gtk_style_set_color (GtkStyle *style, GtkColorType color_type,
705 GtkStateType state, GdkColor *color)
706{
707 switch (color_type)
708 {
709 case GTK_COLOR_WHITE:
710 style->white = *color; break;
711 case GTK_COLOR_BLACK:
712 style->black = *color; break;
713 case GTK_COLOR_FG:
714 style->fg[state] = *color; break;
715 case GTK_COLOR_BG:
716 style->bg[state] = *color; break;
717 case GTK_COLOR_LIGHT:
718 style->light[state] = *color; break;
719 case GTK_COLOR_DARK:
720 style->dark[state] = *color; break;
721 case GTK_COLOR_MID:
722 style->mid[state] = *color; break;
723 case GTK_COLOR_TEXT:
724 style->text[state] = *color; break;
725 case GTK_COLOR_BASE:
726 style->base[state] = *color; break;
727 }
728
729 return gtk_style_get_color (style, color_type, state);
730}
731
732
733GdkFont*
734gtk_style_get_font (GtkStyle *style)
735{
736 return style->font;
737}
738
739
740GdkFont*
741gtk_style_set_font (GtkStyle *style, GdkFont *font)
742{
743 return style->font = font;
744}
745
746
747GdkGC*
748gtk_style_get_gc (GtkStyle *style, GtkColorType color_type, GtkStateType state)
749{
750 switch (color_type)
751 {
752 case GTK_COLOR_WHITE:
753 return style->white_gc;
754 case GTK_COLOR_BLACK:
755 return style->black_gc;
756 case GTK_COLOR_FG:
757 return style->fg_gc[state];
758 case GTK_COLOR_BG:
759 return style->bg_gc[state];
760 case GTK_COLOR_LIGHT:
761 return style->light_gc[state];
762 case GTK_COLOR_DARK:
763 return style->dark_gc[state];
764 case GTK_COLOR_MID:
765 return style->mid_gc[state];
766 case GTK_COLOR_TEXT:
767 return style->text_gc[state];
768 case GTK_COLOR_BASE:
769 return style->base_gc[state];
770 }
771}