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