chiark / gitweb /
Build instructions updated
[clg] / gtk / alien / glue.c
CommitLineData
3350ea74 1/* Common Lisp bindings for GTK+ v2.0
2 * Copyright (C) 1999-2002 Espen S. Johnsen <espen@users.sourceforge.net>
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: glue.c,v 1.1 2004-10-31 12:14:47 espen Exp $ */
20
21
22#include <gtk/gtk.h>
23
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
40void gtk_callback_marshal (GtkWidget *widget, gpointer data)
41{
42 GValue arg;
43
44 memset (&arg, 0, sizeof (GValue));
45 g_value_init (&arg, gtk_widget_get_type ());
46 g_value_set_object (&arg, widget);
47 callback_marshal ((guint)data, NULL, 1, &arg);
48}
49
50void gtk_menu_position_callback_marshal (GtkMenu *menu, gint x, gint y,
51 gboolean push_in, gpointer data)
52{
53 GValue args[3];
54
55 memset (args, 0, 3 * sizeof (GValue));
56 g_value_init (&args[0], G_TYPE_INT);
57 g_value_set_int (&args[0], x);
58 g_value_init (&args[1], G_TYPE_INT);
59 g_value_set_int (&args[1], y);
60 g_value_init (&args[2], G_TYPE_BOOLEAN);
61 g_value_set_boolean (&args[2], push_in);
62
63 callback_marshal ((guint)data, NULL, 3, args);
64}
65
66
67/* Widget */
68
69GdkWindow*
70gtk_widget_get_window (GtkWidget *widget)
71{
72 return widget->window;
73}
74
75GtkStateType
76gtk_widget_get_state (GtkWidget *widget)
77{
78 return widget->state;
79}
80
81gboolean
82gtk_widget_mapped_p (GtkWidget *widget)
83{
84 return GTK_WIDGET_MAPPED (widget);
85}
86
87void
88gtk_widget_get_size_allocation (GtkWidget *widget, int *width, int *height)
89{
90 *width = widget->allocation.width;
91 *height = widget->allocation.height;
92}
93
94
95/* Container */
96
97GtkWidget*
98gtk_container_get_focus_child (GtkContainer *container)
99{
100 return container->focus_child;
101}
102
103
104/* Dialog */
105
106GtkWidget*
107gtk_dialog_get_vbox (GtkDialog *dialog)
108{
109 return dialog->vbox;
110}
111
112GtkWidget*
113gtk_dialog_get_action_area (GtkDialog *dialog)
114{
115 return dialog->action_area;
116}
117
118
119
120/* Check menu item */
121
122gboolean
123gtk_check_menu_item_get_active (GtkCheckMenuItem* check_menu_item)
124{
125 return check_menu_item->active;
126}
127
128gboolean
129gtk_check_menu_item_get_show_toggle (GtkCheckMenuItem* check_menu_item)
130{
131 return check_menu_item->always_show_toggle;
132}
133
134
135
136/* Window */
137
138GtkWidget*
139gtk_window_get_default (GtkWindow *window)
140{
141 return window->default_widget;
142}
143
144
145/* File selection */
146
147GtkWidget*
148gtk_file_selection_get_action_area (GtkFileSelection *filesel)
149{
150 return filesel->action_area;
151}
152
153GtkWidget*
154gtk_file_selection_get_ok_button (GtkFileSelection *filesel)
155{
156 return filesel->ok_button;
157}
158
159GtkWidget*
160gtk_file_selection_get_cancel_button (GtkFileSelection *filesel)
161{
162 return filesel->cancel_button;
163}
164
165
166/* Color selection */
167
168gtk_color_selection_set_color_by_values (GtkColorSelection *colorsel,
169 gdouble red,
170 gdouble green,
171 gdouble blue,
172 gdouble opacity)
173{
174 gdouble color[4];
175
176 color[0] = red;
177 color[1] = green;
178 color[2] = blue;
179 color[3] = opacity;
180
181 gtk_color_selection_set_color (colorsel, color);
182}
183
184void
185gtk_color_selection_get_color_as_values (GtkColorSelection *colorsel,
186 gdouble *red,
187 gdouble *green,
188 gdouble *blue,
189 gdouble *opacity)
190{
191 gdouble color[4];
192
193 gtk_color_selection_get_color (colorsel, color);
194
195 *red = color[0];
196 *green = color[1];
197 *blue = color[2];
198 *opacity = color[3];
199}
200
201
202/* Combo */
203
204GtkWidget*
205gtk_combo_get_entry (GtkCombo *combo)
206{
207 return combo->entry;
208}
209
210gboolean
211gtk_combo_get_use_arrows (GtkCombo *combo)
212{
213 return combo->use_arrows;
214}
215
216gboolean
217gtk_combo_get_use_arrows_always (GtkCombo *combo)
218{
219 return combo->use_arrows_always;
220}
221
222gboolean
223gtk_combo_get_case_sensitive (GtkCombo *combo)
224{
225 return combo->case_sensitive;
226}
227
228
229/* Paned */
230
231GtkWidget*
232gtk_paned_child1 (GtkPaned *paned, guint *resize, guint *shrink)
233{
234 *resize = paned->child1_resize;
235 *shrink = paned->child1_shrink;
236
237 return paned->child1;
238}
239
240
241GtkWidget*
242gtk_paned_child2 (GtkPaned *paned, guint *resize, guint *shrink)
243{
244 *resize = paned->child2_resize;
245 *shrink = paned->child2_shrink;
246
247 return paned->child2;
248}
249
250
251/* Layout */
252
253GdkWindow*
254gtk_layout_get_bin_window (GtkLayout *layout)
255{
256 return layout->bin_window;
257}
258
259
260/* List */
261
262GList*
263gtk_list_selection (GtkList *list)
264{
265 return list->selection;
266}
267
268
269
270/* Toolbar */
271
272gint
273gtk_toolbar_get_tooltips (GtkToolbar *toolbar)
274{
275 return toolbar->tooltips->enabled;
276}
277
278
279/* Drawing area */
280
281void
282gtk_drawing_area_get_size (GtkDrawingArea *darea, gint *width, gint *height)
283{
284 GtkWidget *widget;
285
286 widget = GTK_WIDGET (darea);
287 *width = widget->allocation.width;
288 *height = widget->allocation.height;
289}
290
291
292/* Progress */
293
294gchar*
295gtk_progress_get_format_string (GtkProgress *progress)
296{
297 return progress->format;
298}
299
300GtkAdjustment*
301gtk_progress_get_adjustment (GtkProgress *progress)
302{
303 return progress->adjustment;
304}
305
306
307/* Tooltips */
308
309gboolean
310gtk_tooltips_get_enabled (GtkTooltips *tooltips)
311{
312 return tooltips->enabled;
313}
314
315
316/* GtkStyle accessor functions */
317
318typedef enum {
319 GTK_COLOR_FG,
320 GTK_COLOR_BG,
321 GTK_COLOR_LIGHT,
322 GTK_COLOR_DARK,
323 GTK_COLOR_MID,
324 GTK_COLOR_TEXT,
325 GTK_COLOR_BASE,
326 GTK_COLOR_WHITE,
327 GTK_COLOR_BLACK
328} GtkColorType;
329
330GdkColor*
331gtk_style_get_color (GtkStyle *style, GtkColorType color_type,
332 GtkStateType state)
333{
334 switch (color_type)
335 {
336 case GTK_COLOR_WHITE:
337 return &style->white;
338 case GTK_COLOR_BLACK:
339 return &style->black;
340 case GTK_COLOR_FG:
341 return &style->fg[state];
342 case GTK_COLOR_BG:
343 return &style->bg[state];
344 case GTK_COLOR_LIGHT:
345 return &style->light[state];
346 case GTK_COLOR_DARK:
347 return &style->dark[state];
348 case GTK_COLOR_MID:
349 return &style->mid[state];
350 case GTK_COLOR_TEXT:
351 return &style->text[state];
352 case GTK_COLOR_BASE:
353 return &style->base[state];
354 }
355}
356
357
358GdkColor*
359gtk_style_set_color (GtkStyle *style, GtkColorType color_type,
360 GtkStateType state, GdkColor *color)
361{
362 switch (color_type)
363 {
364 case GTK_COLOR_WHITE:
365 style->white = *color; break;
366 case GTK_COLOR_BLACK:
367 style->black = *color; break;
368 case GTK_COLOR_FG:
369 style->fg[state] = *color; break;
370 case GTK_COLOR_BG:
371 style->bg[state] = *color; break;
372 case GTK_COLOR_LIGHT:
373 style->light[state] = *color; break;
374 case GTK_COLOR_DARK:
375 style->dark[state] = *color; break;
376 case GTK_COLOR_MID:
377 style->mid[state] = *color; break;
378 case GTK_COLOR_TEXT:
379 style->text[state] = *color; break;
380 case GTK_COLOR_BASE:
381 style->base[state] = *color; break;
382 }
383
384 return gtk_style_get_color (style, color_type, state);
385}
386
387/*
388GdkFont*
389gtk_style_get_font (GtkStyle *style)
390{
391 return style->font;
392}
393
394
395GdkFont*
396gtk_style_set_font (GtkStyle *style, GdkFont *font)
397{
398 return style->font = font;
399}
400*/
401
402GdkGC*
403gtk_style_get_gc (GtkStyle *style, GtkColorType color_type, GtkStateType state)
404{
405 switch (color_type)
406 {
407 case GTK_COLOR_WHITE:
408 return style->white_gc;
409 case GTK_COLOR_BLACK:
410 return style->black_gc;
411 case GTK_COLOR_FG:
412 return style->fg_gc[state];
413 case GTK_COLOR_BG:
414 return style->bg_gc[state];
415 case GTK_COLOR_LIGHT:
416 return style->light_gc[state];
417 case GTK_COLOR_DARK:
418 return style->dark_gc[state];
419 case GTK_COLOR_MID:
420 return style->mid_gc[state];
421 case GTK_COLOR_TEXT:
422 return style->text_gc[state];
423 case GTK_COLOR_BASE:
424 return style->base_gc[state];
425 }
426}