Added dependency to the gtk system and a couple of bug fixes
[clg] / gtk / alien / glue.c
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.7 2005-01-06 21:54:19 espen Exp $ */
20
21
22 #include <gtk/gtk.h>
23
24
25 /*
26 *
27 * Gtk helper functions
28 *
29 */
30
31 void
32 gtk_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
40 /* Widget */
41
42 GdkWindow*
43 gtk_widget_get_window (GtkWidget *widget)
44 {
45 return widget->window;
46 }
47
48 GtkStateType
49 gtk_widget_get_state (GtkWidget *widget)
50 {
51 return widget->state;
52 }
53
54 gboolean
55 gtk_widget_mapped_p (GtkWidget *widget)
56 {
57 return GTK_WIDGET_MAPPED (widget);
58 }
59
60 void
61 gtk_widget_get_size_allocation (GtkWidget *widget, int *width, int *height)
62 {
63 *width = widget->allocation.width;
64 *height = widget->allocation.height;
65 }
66
67
68 /* Container */
69
70 GtkWidget*
71 gtk_container_get_focus_child (GtkContainer *container)
72 {
73 return container->focus_child;
74 }
75
76 gboolean
77 gtk_container_get_reallocate_redraws (GtkContainer *container)
78 {
79 return container->reallocate_redraws;
80 }
81
82
83 /* Dialog */
84
85 GtkWidget*
86 gtk_dialog_get_vbox (GtkDialog *dialog)
87 {
88 return dialog->vbox;
89 }
90
91 GtkWidget*
92 gtk_dialog_get_action_area (GtkDialog *dialog)
93 {
94 return dialog->action_area;
95 }
96
97
98
99 /* Window */
100
101 GtkWidget*
102 gtk_window_get_default (GtkWindow *window)
103 {
104 return window->default_widget;
105 }
106
107 GtkWindowGroup*
108 gtk_window_get_group (GtkWindow *window)
109 {
110 return window->group;
111 }
112
113
114
115 /* Menu */
116
117 GdkScreen*
118 gtk_menu_get_screen (GtkMenu *menu)
119 {
120 return (GdkScreen*)g_object_get_data (G_OBJECT (menu), "gtk-menu-explicit-screen");
121 }
122
123
124
125 /* Toolbar */
126
127 GtkTooltips*
128 gtk_toolbar_get_tooltips_object (GtkToolbar *toolbar)
129 {
130 return toolbar->tooltips;
131 }
132
133
134
135 /* Tooltips */
136
137 gint
138 gtk_tooltips_get_enabled (GtkTooltips *tooltips)
139 {
140 return tooltips->enabled;
141 }
142
143
144 /* Layout */
145
146 GdkWindow*
147 gtk_layout_get_bin_window (GtkLayout *layout)
148 {
149 return layout->bin_window;
150 }
151
152
153 /* GtkStyle accessor functions */
154
155 typedef enum {
156 GTK_COLOR_FG,
157 GTK_COLOR_BG,
158 GTK_COLOR_LIGHT,
159 GTK_COLOR_DARK,
160 GTK_COLOR_MID,
161 GTK_COLOR_TEXT,
162 GTK_COLOR_BASE,
163 GTK_COLOR_TEXT_AA,
164 GTK_COLOR_WHITE,
165 GTK_COLOR_BLACK
166 } GtkColorType;
167
168 GdkColor*
169 gtk_style_get_color (GtkStyle *style, GtkColorType color_type,
170 GtkStateType state)
171 {
172 switch (color_type)
173 {
174 case GTK_COLOR_WHITE:
175 return &style->white;
176 case GTK_COLOR_BLACK:
177 return &style->black;
178 case GTK_COLOR_FG:
179 return &style->fg[state];
180 case GTK_COLOR_BG:
181 return &style->bg[state];
182 case GTK_COLOR_LIGHT:
183 return &style->light[state];
184 case GTK_COLOR_DARK:
185 return &style->dark[state];
186 case GTK_COLOR_MID:
187 return &style->mid[state];
188 case GTK_COLOR_TEXT:
189 return &style->text[state];
190 case GTK_COLOR_BASE:
191 return &style->base[state];
192 case GTK_COLOR_TEXT_AA:
193 return &style->text_aa[state];
194 }
195 }
196
197
198 void
199 gtk_style_set_color (GtkStyle *style, GtkColorType color_type,
200 GtkStateType state, GdkColor *color)
201 {
202 switch (color_type)
203 {
204 case GTK_COLOR_WHITE:
205 style->white = *color; break;
206 case GTK_COLOR_BLACK:
207 style->black = *color; break;
208 case GTK_COLOR_FG:
209 style->fg[state] = *color; break;
210 case GTK_COLOR_BG:
211 style->bg[state] = *color; break;
212 case GTK_COLOR_LIGHT:
213 style->light[state] = *color; break;
214 case GTK_COLOR_DARK:
215 style->dark[state] = *color; break;
216 case GTK_COLOR_MID:
217 style->mid[state] = *color; break;
218 case GTK_COLOR_TEXT:
219 style->text[state] = *color; break;
220 case GTK_COLOR_BASE:
221 style->base[state] = *color; break;
222 case GTK_COLOR_TEXT_AA:
223 style->text_aa[state] = *color; break;
224 }
225 }
226
227
228 GdkGC*
229 gtk_style_get_gc (GtkStyle *style, GtkColorType color_type, GtkStateType state)
230 {
231 switch (color_type)
232 {
233 case GTK_COLOR_WHITE:
234 return style->white_gc;
235 case GTK_COLOR_BLACK:
236 return style->black_gc;
237 case GTK_COLOR_FG:
238 return style->fg_gc[state];
239 case GTK_COLOR_BG:
240 return style->bg_gc[state];
241 case GTK_COLOR_LIGHT:
242 return style->light_gc[state];
243 case GTK_COLOR_DARK:
244 return style->dark_gc[state];
245 case GTK_COLOR_MID:
246 return style->mid_gc[state];
247 case GTK_COLOR_TEXT:
248 return style->text_gc[state];
249 case GTK_COLOR_BASE:
250 return style->base_gc[state];
251 case GTK_COLOR_TEXT_AA:
252 return style->text_aa_gc[state];
253 }
254 }
255
256 int
257 gtk_style_font_desc_offset ()
258 {
259 GtkStyle style;
260
261 return (int)&style.font_desc - (int)&style;
262 }
263