chiark / gitweb /
Bindings to lots of widgets updated and completed
[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.6 2004-12-29 21:17:37 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 /* Window */
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 /* Layout */
126
127 GdkWindow*
128 gtk_layout_get_bin_window (GtkLayout *layout)
129 {
130   return layout->bin_window;
131 }
132
133
134 /* GtkStyle accessor functions */
135
136 typedef enum {
137   GTK_COLOR_FG,
138   GTK_COLOR_BG,
139   GTK_COLOR_LIGHT,
140   GTK_COLOR_DARK,
141   GTK_COLOR_MID,
142   GTK_COLOR_TEXT,
143   GTK_COLOR_BASE,
144   GTK_COLOR_TEXT_AA,
145   GTK_COLOR_WHITE,
146   GTK_COLOR_BLACK
147 } GtkColorType;
148
149 GdkColor*
150 gtk_style_get_color (GtkStyle *style, GtkColorType color_type,
151                      GtkStateType state)
152 {
153   switch (color_type)
154     {
155     case GTK_COLOR_WHITE:
156       return &style->white;
157     case GTK_COLOR_BLACK:
158       return &style->black;
159     case GTK_COLOR_FG:
160       return &style->fg[state];
161     case GTK_COLOR_BG:
162       return &style->bg[state];
163     case GTK_COLOR_LIGHT:
164       return &style->light[state];
165     case GTK_COLOR_DARK:
166       return &style->dark[state];
167     case GTK_COLOR_MID:
168       return &style->mid[state];
169     case GTK_COLOR_TEXT:
170       return &style->text[state];
171     case GTK_COLOR_BASE:
172       return &style->base[state];
173     case GTK_COLOR_TEXT_AA:
174       return &style->text_aa[state];
175     }
176 }
177
178
179 void
180 gtk_style_set_color (GtkStyle *style, GtkColorType color_type,
181                      GtkStateType state, GdkColor *color)
182 {
183   switch (color_type)
184     {
185     case GTK_COLOR_WHITE:
186       style->white = *color; break;
187     case GTK_COLOR_BLACK:
188       style->black = *color; break;
189     case GTK_COLOR_FG:
190       style->fg[state] = *color; break;
191     case GTK_COLOR_BG:
192       style->bg[state]  = *color; break;
193     case GTK_COLOR_LIGHT:
194       style->light[state]  = *color; break;
195     case GTK_COLOR_DARK:
196       style->dark[state]  = *color; break;
197     case GTK_COLOR_MID:
198       style->mid[state]  = *color; break;
199     case GTK_COLOR_TEXT:
200       style->text[state]  = *color; break;
201     case GTK_COLOR_BASE:
202       style->base[state]  = *color; break;
203     case GTK_COLOR_TEXT_AA:
204       style->text_aa[state]  = *color; break;
205     }
206 }
207
208
209 GdkGC*
210 gtk_style_get_gc (GtkStyle *style, GtkColorType color_type, GtkStateType state)
211 {
212   switch (color_type)
213     {
214     case GTK_COLOR_WHITE:
215       return style->white_gc;
216     case GTK_COLOR_BLACK:
217       return style->black_gc;
218     case GTK_COLOR_FG:
219       return style->fg_gc[state];
220     case GTK_COLOR_BG:
221       return style->bg_gc[state];
222     case GTK_COLOR_LIGHT:
223       return style->light_gc[state];
224     case GTK_COLOR_DARK:
225       return style->dark_gc[state];
226     case GTK_COLOR_MID:
227       return style->mid_gc[state];
228     case GTK_COLOR_TEXT:
229       return style->text_gc[state];
230     case GTK_COLOR_BASE:
231       return style->base_gc[state];
232     case GTK_COLOR_TEXT_AA:
233       return style->text_aa_gc[state];
234     }
235 }
236
237 int
238 gtk_style_font_desc_offset ()
239 {
240   GtkStyle style;
241   
242   return (int)&style.font_desc - (int)&style;
243 }
244