chiark / gitweb /
Infra: Rudimentary setup system.
[clg] / gtk / alien / glue.c
1 /* Common Lisp bindings for GTK+ v2.x
2  * Copyright 1999-2005 Espen S. Johnsen <espen@users.sf.net>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining
5  * a copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sublicense, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23
24 /* $Id: glue.c,v 1.9 2007-09-06 14:27:07 espen Exp $ */
25
26
27 #include <gtk/gtk.h>
28
29
30 /*
31  *
32  * Gtk helper functions
33  *
34  */
35
36 void
37 gtk_query_version (guint *major, guint *minor, guint *micro)
38 {
39   *major = gtk_major_version;
40   *minor = gtk_minor_version;
41   *micro = gtk_micro_version;
42 }
43
44
45 /* Widget */
46
47 GdkWindow*
48 gtk_widget_get_window (GtkWidget *widget)
49 {
50   return widget->window;
51 }
52
53 GtkStateType
54 gtk_widget_get_state (GtkWidget *widget)
55 {
56   return widget->state;
57 }
58
59 gint32
60 gtk_widget_flags (GtkWidget *widget)
61 {
62   return GTK_WIDGET_FLAGS (widget);
63 }
64
65
66 void
67 gtk_widget_get_size_allocation (GtkWidget *widget, int *width, int *height)
68 {
69   *width = widget->allocation.width;
70   *height = widget->allocation.height;
71 }
72
73
74 /* Container */
75
76 GtkWidget*
77 gtk_container_get_focus_child (GtkContainer *container)
78 {
79   return container->focus_child;
80 }
81
82 gboolean
83 gtk_container_get_reallocate_redraws (GtkContainer *container)
84 {
85   return container->reallocate_redraws;
86 }
87
88
89 /* Dialog */
90
91 GtkWidget*
92 gtk_dialog_get_vbox (GtkDialog *dialog)
93 {
94   return dialog->vbox;
95 }
96
97 GtkWidget*
98 gtk_dialog_get_action_area (GtkDialog *dialog)
99 {
100   return dialog->action_area;
101 }
102
103
104
105 /* Window */
106
107 GtkWidget*
108 gtk_window_get_default (GtkWindow *window)
109 {
110   return window->default_widget;
111 }
112
113 GtkWindowGroup*
114 gtk_window_get_group (GtkWindow *window)
115 {
116   return window->group;
117 }
118
119
120
121 /* Menu */
122
123 GdkScreen*
124 gtk_menu_get_screen (GtkMenu *menu)
125 {
126   return (GdkScreen*)g_object_get_data (G_OBJECT (menu), "gtk-menu-explicit-screen");
127 }
128
129
130
131 /* Toolbar */
132
133 GtkTooltips*
134 gtk_toolbar_get_tooltips_object (GtkToolbar *toolbar)
135 {
136   return toolbar->tooltips;
137 }
138
139
140
141 /* Tooltips */
142
143 gint
144 gtk_tooltips_get_enabled (GtkTooltips *tooltips)
145 {
146   return tooltips->enabled;
147 }
148
149
150 /* Layout */
151
152 GdkWindow*
153 gtk_layout_get_bin_window (GtkLayout *layout)
154 {
155   return layout->bin_window;
156 }
157
158
159 /* GtkStyle accessor functions */
160
161 typedef enum {
162   GTK_COLOR_FG,
163   GTK_COLOR_BG,
164   GTK_COLOR_LIGHT,
165   GTK_COLOR_DARK,
166   GTK_COLOR_MID,
167   GTK_COLOR_TEXT,
168   GTK_COLOR_BASE,
169   GTK_COLOR_TEXT_AA,
170   GTK_COLOR_WHITE,
171   GTK_COLOR_BLACK
172 } GtkColorType;
173
174 GdkColor*
175 gtk_style_get_color (GtkStyle *style, GtkColorType color_type,
176                      GtkStateType state)
177 {
178   switch (color_type)
179     {
180     case GTK_COLOR_WHITE:
181       return &style->white;
182     case GTK_COLOR_BLACK:
183       return &style->black;
184     case GTK_COLOR_FG:
185       return &style->fg[state];
186     case GTK_COLOR_BG:
187       return &style->bg[state];
188     case GTK_COLOR_LIGHT:
189       return &style->light[state];
190     case GTK_COLOR_DARK:
191       return &style->dark[state];
192     case GTK_COLOR_MID:
193       return &style->mid[state];
194     case GTK_COLOR_TEXT:
195       return &style->text[state];
196     case GTK_COLOR_BASE:
197       return &style->base[state];
198     case GTK_COLOR_TEXT_AA:
199       return &style->text_aa[state];
200     }
201 }
202
203
204 void
205 gtk_style_set_color (GtkStyle *style, GtkColorType color_type,
206                      GtkStateType state, GdkColor *color)
207 {
208   switch (color_type)
209     {
210     case GTK_COLOR_WHITE:
211       style->white = *color; break;
212     case GTK_COLOR_BLACK:
213       style->black = *color; break;
214     case GTK_COLOR_FG:
215       style->fg[state] = *color; break;
216     case GTK_COLOR_BG:
217       style->bg[state]  = *color; break;
218     case GTK_COLOR_LIGHT:
219       style->light[state]  = *color; break;
220     case GTK_COLOR_DARK:
221       style->dark[state]  = *color; break;
222     case GTK_COLOR_MID:
223       style->mid[state]  = *color; break;
224     case GTK_COLOR_TEXT:
225       style->text[state]  = *color; break;
226     case GTK_COLOR_BASE:
227       style->base[state]  = *color; break;
228     case GTK_COLOR_TEXT_AA:
229       style->text_aa[state]  = *color; break;
230     }
231 }
232
233
234 GdkGC*
235 gtk_style_get_gc (GtkStyle *style, GtkColorType color_type, GtkStateType state)
236 {
237   switch (color_type)
238     {
239     case GTK_COLOR_WHITE:
240       return style->white_gc;
241     case GTK_COLOR_BLACK:
242       return style->black_gc;
243     case GTK_COLOR_FG:
244       return style->fg_gc[state];
245     case GTK_COLOR_BG:
246       return style->bg_gc[state];
247     case GTK_COLOR_LIGHT:
248       return style->light_gc[state];
249     case GTK_COLOR_DARK:
250       return style->dark_gc[state];
251     case GTK_COLOR_MID:
252       return style->mid_gc[state];
253     case GTK_COLOR_TEXT:
254       return style->text_gc[state];
255     case GTK_COLOR_BASE:
256       return style->base_gc[state];
257     case GTK_COLOR_TEXT_AA:
258       return style->text_aa_gc[state];
259     }
260 }
261
262 int
263 gtk_style_font_desc_offset ()
264 {
265   GtkStyle style;
266   
267   return (int)&style.font_desc - (int)&style;
268 }
269