chiark / gitweb /
initial checkin
[clg] / gtk / gtkglue.c
CommitLineData
0d07716f 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
ecb4e7dc 19/* $Id: gtkglue.c,v 1.1.1.1 2000/08/14 16:45:01 espen Exp $ */
0d07716f 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
154gint
155gtk_menu_item_get_show_toggle (GtkMenuItem* menu_item)
156{
157 return menu_item->show_toggle_indicator;
158}
159
160gint
161gtk_menu_item_get_show_submenu (GtkMenuItem* menu_item)
162{
163 return menu_item->show_submenu_indicator;
164}
165
166
167
168/* Check menu item */
169
170gboolean
171gtk_check_menu_item_get_active (GtkCheckMenuItem* check_menu_item)
172{
173 return check_menu_item->active;
174}
175
176gboolean
177gtk_check_menu_item_get_show_toggle (GtkCheckMenuItem* check_menu_item)
178{
179 return check_menu_item->always_show_toggle;
180}
181
182
183/* Tree item */
184
185GtkWidget*
186gtk_tree_item_get_subtree (GtkTreeItem* tree_item)
187{
188 return GTK_TREE_ITEM_SUBTREE (tree_item);
189}
190
191
192/* Window */
193
194void
195gtk_window_wmclass (GtkWindow* window, gchar* name, gchar* class)
196{
197 name = window->wmclass_name;
198 class = window->wmclass_class;
199}
200
201
202/* Color selection dialog */
203
204GtkWidget*
205gtk_color_selection_dialog_get_colorsel (GtkColorSelectionDialog* dialog)
206{
207 return dialog->colorsel;
208}
209
210/* GtkWidget* */
211/* gtk_color_selection_dialog_get_main_vbox (GtkColorSelectionDialog* dialog) */
212/* { */
213/* return dialog->main_vbox; */
214/* } */
215
216GtkWidget*
217gtk_color_selection_dialog_get_ok_button (GtkColorSelectionDialog* dialog)
218{
219 return dialog->ok_button;
220}
221
222/* GtkWidget* */
223/* gtk_color_selection_dialog_get_reset_button (GtkColorSelectionDialog* dialog) */
224/* { */
225/* return dialog->reset_button; */
226/* } */
227
228GtkWidget*
229gtk_color_selection_dialog_get_cancel_button (GtkColorSelectionDialog* dialog)
230{
231 return dialog->cancel_button;
232}
233
234GtkWidget*
235gtk_color_selection_dialog_get_help_button (GtkColorSelectionDialog* dialog)
236{
237 return dialog->help_button;
238}
239
240
241/* Dialog */
242
243GtkWidget*
244gtk_dialog_get_action_area (GtkDialog *dialog)
245{
246 return dialog->action_area;
247}
248
249
250GtkWidget*
251gtk_dialog_get_vbox (GtkDialog *dialog)
252{
253 return dialog->vbox;
254}
255
256
257/* File selection */
258
259GtkWidget*
260gtk_file_selection_get_action_area (GtkFileSelection *filesel)
261{
262 return filesel->action_area;
263}
264
265GtkWidget*
266gtk_file_selection_get_ok_button (GtkFileSelection *filesel)
267{
268 return filesel->ok_button;
269}
270
271GtkWidget*
272gtk_file_selection_get_cancel_button (GtkFileSelection *filesel)
273{
274 return filesel->cancel_button;
275}
276
277
278/* Color selection */
279
280void
281gtk_color_selection_set_color_by_values (GtkColorSelection *colorsel,
282 gdouble red,
283 gdouble green,
284 gdouble blue,
285 gdouble opacity)
286{
287 gdouble color[4];
288
289 color[0] = red;
290 color[1] = green;
291 color[2] = blue;
292 color[3] = opacity;
293
294 gtk_color_selection_set_color (colorsel, color);
295}
296
297void
298gtk_color_selection_get_color_as_values (GtkColorSelection *colorsel,
299 gdouble *red,
300 gdouble *green,
301 gdouble *blue,
302 gdouble *opacity)
303{
304 gdouble color[4];
305
306 gtk_color_selection_get_color (colorsel, color);
307
308 *red = color[0];
309 *green = color[1];
310 *blue = color[2];
311 *opacity = color[3];
312}
313
314
315/* Combo */
316
317GtkWidget*
318gtk_combo_get_entry (GtkCombo *combo)
319{
320 return combo->entry;
321}
322
323gboolean
324gtk_combo_get_use_arrows (GtkCombo *combo)
325{
326 return combo->use_arrows;
327}
328
329gboolean
330gtk_combo_get_use_arrows_always (GtkCombo *combo)
331{
332 return combo->use_arrows_always;
333}
334
335gboolean
336gtk_combo_get_case_sensitive (GtkCombo *combo)
337{
338 return combo->case_sensitive;
339}
340
341
342/* CList */
343
344#ifdef CLIST
345GList*
346gtk_clist_selection (GtkCList *clist)
347{
348 return clist->selection;
349}
350
351gint
352gtk_clist_get_titles_visible (GtkCList *clist)
353{
354 return (clist->title_window && GTK_WIDGET_VISIBLE (clist->title_window));
355}
356
357gint
358gtk_clist_get_n_rows (GtkCList *clist)
359{
360 return clist->rows;
361}
362
363gint
364gtk_clist_get_focus_row (GtkCList *clist)
365{
366 return clist->focus_row;
367}
368
369gint
370gtk_clist_get_sort_column (GtkCList *clist)
371{
372 return clist->sort_column;
373}
374
375GtkJustification
376gtk_clist_column_justification (GtkCList *clist,
377 gint column)
378{
379 return clist->column[column].justification;
380}
381
382gboolean
383gtk_clist_column_visible_p (GtkCList *clist,
384 gint column)
385{
386 return clist->column[column].visible;
387}
388
389gboolean
390gtk_clist_column_resizeable_p (GtkCList *clist,
391 gint column)
392{
393 return clist->column[column].resizeable;
394}
395
396gboolean
397gtk_clist_column_auto_resize_p (GtkCList *clist,
398 gint column)
399{
400 return clist->column[column].auto_resize;
401}
402
403gint
404gtk_clist_column_width (GtkCList *clist,
405 gint column)
406{
407 return clist->column[column].width;
408}
409
410gboolean
411gtk_clist_auto_sort_p (GtkCList *clist)
412{
413 return GTK_CLIST_AUTO_SORT (clist);
414}
415#endif
416
417/* CTree */
418
419#ifdef CTREE
420gboolean
421gtk_ctree_node_leaf_p (GtkCTreeNode* node)
422{
423 return GTK_CTREE_ROW (node)->is_leaf;
424}
425
426GtkCTreeNode*
427gtk_ctree_node_child (GtkCTreeNode* node)
428{
429 return GTK_CTREE_ROW (node)->children;
430}
431
432GtkCTreeNode*
433gtk_ctree_node_parent (GtkCTreeNode* node)
434{
435 return GTK_CTREE_ROW (node)->parent;
436}
437
438GtkCTreeNode*
439gtk_ctree_node_sibling (GtkCTreeNode* node)
440{
441 return GTK_CTREE_ROW (node)->sibling;
442}
443
444gint
445gtk_ctree_node_level (GtkCTreeNode* node)
446{
447 return GTK_CTREE_ROW (node)->level;
448}
449#endif
450
451/* Paned */
452
453GtkWidget*
454gtk_paned_child1 (GtkPaned *paned, guint *resize, guint *shrink)
455{
456 *resize = paned->child1_resize;
457 *shrink = paned->child1_shrink;
458
459 return paned->child1;
460}
461
462
463GtkWidget*
464gtk_paned_child2 (GtkPaned *paned, guint *resize, guint *shrink)
465{
466 *resize = paned->child2_resize;
467 *shrink = paned->child2_shrink;
468
469 return paned->child2;
470}
471
472gint
473gtk_paned_get_position (GtkPaned *paned)
474{
475 if (paned->position_set == TRUE)
476 return paned->child1_size;
477 else
478 return -1;
479}
480
481
482/* Layout */
483
484gint
485gtk_layout_size (GtkLayout *layout, gint *width, gint *height)
486
487{
488 *width = layout->width;
489 *height = layout->height;
490}
491
492void
493gtk_layout_offset (GtkLayout *layout, gint *x, gint *y)
494{
495 *x = layout->xoffset;
496 *y = layout->yoffset;
497}
498
499
500GdkWindow*
501gtk_layout_get_bin_window (GtkLayout *layout)
502{
503 return layout->bin_window;
504}
505
506
507/* List */
508
509GList*
510gtk_list_selection (GtkList *list)
511{
512 return list->selection;
513}
514
515
516/* Table */
517
518guint
519gtk_table_row_spacing (GtkTable *table,
520 guint row)
521{
522 return table->rows[row].spacing;
523}
524
525guint
526gtk_table_column_spacing (GtkTable *table,
527 guint col)
528{
529 return table->cols[col].spacing;
530}
531
532
533/* Toolbar */
534
535gint
536gtk_toolbar_num_children (GtkToolbar *toolbar)
537{
538 return toolbar->num_children;
539}
540
541
542/* Tree */
543
544GtkSelectionMode
545gtk_tree_get_selection_mode (GtkTree *tree)
546{
547 return tree->selection_mode;
548}
549
550GtkSelectionMode
551gtk_tree_get_view_mode (GtkTree *tree)
552{
553 return tree->view_mode;
554}
555
556GtkSelectionMode
557gtk_tree_get_view_lines (GtkTree *tree)
558{
559 return tree->view_mode;
560}
561
562GtkTree*
563gtk_tree_get_root_tree (GtkTree *tree)
564{
565 return GTK_TREE_ROOT_TREE (tree);
566}
567
568GList*
569gtk_tree_selection (GtkTree *tree)
570{
571 return GTK_TREE_SELECTION (tree);
572}
573
574
575/* Drawing area */
576
577void
578gtk_drawing_area_get_size (GtkDrawingArea *darea, gint *width, gint *height)
579{
580 GtkWidget *widget;
581
582 widget = GTK_WIDGET (darea);
583 *width = widget->allocation.width;
584 *height = widget->allocation.height;
585}
586
587
588/* Progress */
589
590gchar*
591gtk_progress_get_format_string (GtkProgress *progress)
592{
593 return progress->format;
594}
595
596GtkAdjustment*
597gtk_progress_get_adjustment (GtkProgress *progress)
598{
599 return progress->adjustment;
600}
601
602
603/* Scrolled window */
604
605GtkWidget*
606gtk_scrolled_window_get_hscrollbar (GtkScrolledWindow *window)
607{
608 return window->hscrollbar;
609}
610
611GtkWidget*
612gtk_scrolled_window_get_vscrollbar (GtkScrolledWindow *window)
613{
614 return window->vscrollbar;
615}
616
617
618
619/* Tooltips */
620
621guint
622gtk_tooltips_get_delay (GtkTooltips *tooltips)
623{
624 return tooltips->delay;
625}
626
627
628
629
630
631/* GtkStyle accessor functions */
632
633typedef enum {
634 GTK_COLOR_FG,
635 GTK_COLOR_BG,
636 GTK_COLOR_LIGHT,
637 GTK_COLOR_DARK,
638 GTK_COLOR_MID,
639 GTK_COLOR_TEXT,
640 GTK_COLOR_BASE,
641 GTK_COLOR_WHITE,
642 GTK_COLOR_BLACK
643} GtkColorType;
644
645GdkColor*
646gtk_style_get_color (GtkStyle *style, GtkColorType color_type,
647 GtkStateType state)
648{
649 switch (color_type)
650 {
651 case GTK_COLOR_WHITE:
652 return &style->white;
653 case GTK_COLOR_BLACK:
654 return &style->black;
655 case GTK_COLOR_FG:
656 return &style->fg[state];
657 case GTK_COLOR_BG:
658 return &style->bg[state];
659 case GTK_COLOR_LIGHT:
660 return &style->light[state];
661 case GTK_COLOR_DARK:
662 return &style->dark[state];
663 case GTK_COLOR_MID:
664 return &style->mid[state];
665 case GTK_COLOR_TEXT:
666 return &style->text[state];
667 case GTK_COLOR_BASE:
668 return &style->base[state];
669 }
670}
671
672
673GdkColor*
674gtk_style_set_color (GtkStyle *style, GtkColorType color_type,
675 GtkStateType state, GdkColor *color)
676{
677 switch (color_type)
678 {
679 case GTK_COLOR_WHITE:
680 style->white = *color; break;
681 case GTK_COLOR_BLACK:
682 style->black = *color; break;
683 case GTK_COLOR_FG:
684 style->fg[state] = *color; break;
685 case GTK_COLOR_BG:
686 style->bg[state] = *color; break;
687 case GTK_COLOR_LIGHT:
688 style->light[state] = *color; break;
689 case GTK_COLOR_DARK:
690 style->dark[state] = *color; break;
691 case GTK_COLOR_MID:
692 style->mid[state] = *color; break;
693 case GTK_COLOR_TEXT:
694 style->text[state] = *color; break;
695 case GTK_COLOR_BASE:
696 style->base[state] = *color; break;
697 }
698
699 return gtk_style_get_color (style, color_type, state);
700}
701
702
703GdkFont*
704gtk_style_get_font (GtkStyle *style)
705{
706 return style->font;
707}
708
709
710GdkFont*
711gtk_style_set_font (GtkStyle *style, GdkFont *font)
712{
713 return style->font = font;
714}
715
716
717GdkGC*
718gtk_style_get_gc (GtkStyle *style, GtkColorType color_type, GtkStateType state)
719{
720 switch (color_type)
721 {
722 case GTK_COLOR_WHITE:
723 return style->white_gc;
724 case GTK_COLOR_BLACK:
725 return style->black_gc;
726 case GTK_COLOR_FG:
727 return style->fg_gc[state];
728 case GTK_COLOR_BG:
729 return style->bg_gc[state];
730 case GTK_COLOR_LIGHT:
731 return style->light_gc[state];
732 case GTK_COLOR_DARK:
733 return style->dark_gc[state];
734 case GTK_COLOR_MID:
735 return style->mid_gc[state];
736 case GTK_COLOR_TEXT:
737 return style->text_gc[state];
738 case GTK_COLOR_BASE:
739 return style->base_gc[state];
740 }
741}