]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/win_gtk.c
Changed m_font to * GetFont() since m_font isn't in all implementations.
[wxWidgets.git] / src / gtk1 / win_gtk.c
1 /* ///////////////////////////////////////////////////////////////////////////
2 // Name: win_gtk.c
3 // Purpose: native GTK+ widget for wxWindows
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////// */
9
10 #include "wx/gtk/win_gtk.h"
11 #include <gtk/gtkfeatures.h>
12
13 #ifdef __cplusplus
14 extern "C" {
15 #endif /* __cplusplus */
16
17 static void gtk_myfixed_class_init (GtkMyFixedClass *klass);
18 static void gtk_myfixed_init (GtkMyFixed *myfixed);
19 static void gtk_myfixed_map (GtkWidget *widget);
20 static void gtk_myfixed_unmap (GtkWidget *widget);
21 static void gtk_myfixed_realize (GtkWidget *widget);
22 static void gtk_myfixed_size_request (GtkWidget *widget,
23 GtkRequisition *requisition);
24 static void gtk_myfixed_size_allocate (GtkWidget *widget,
25 GtkAllocation *allocation);
26 static void gtk_myfixed_paint (GtkWidget *widget,
27 GdkRectangle *area);
28 static void gtk_myfixed_draw (GtkWidget *widget,
29 GdkRectangle *area);
30 static gint gtk_myfixed_expose (GtkWidget *widget,
31 GdkEventExpose *event);
32 static void gtk_myfixed_add (GtkContainer *container,
33 GtkWidget *widget);
34 static void gtk_myfixed_remove (GtkContainer *container,
35 GtkWidget *widget);
36 static void gtk_myfixed_foreach (GtkContainer *container,
37 #if (GTK_MINOR_VERSION == 1)
38 gboolean include_internals,
39 #endif
40 GtkCallback callback,
41 gpointer callback_data);
42
43
44 static GtkContainerClass *parent_class = NULL;
45
46
47 guint
48 gtk_myfixed_get_type ()
49 {
50 static guint myfixed_type = 0;
51
52 if (!myfixed_type)
53 {
54 GtkTypeInfo myfixed_info =
55 {
56 "GtkMyFixed",
57 sizeof (GtkMyFixed),
58 sizeof (GtkMyFixedClass),
59 (GtkClassInitFunc) gtk_myfixed_class_init,
60 (GtkObjectInitFunc) gtk_myfixed_init,
61 (GtkArgSetFunc) NULL,
62 (GtkArgGetFunc) NULL,
63 };
64
65 myfixed_type = gtk_type_unique (gtk_container_get_type (), &myfixed_info);
66 }
67
68 return myfixed_type;
69 }
70
71 static void
72 gtk_myfixed_class_init (GtkMyFixedClass *klass)
73 {
74 GtkObjectClass *object_class;
75 GtkWidgetClass *widget_class;
76 GtkContainerClass *container_class;
77
78 object_class = (GtkObjectClass*) klass;
79 widget_class = (GtkWidgetClass*) klass;
80 container_class = (GtkContainerClass*) klass;
81
82 parent_class = gtk_type_class (gtk_container_get_type ());
83
84 widget_class->map = gtk_myfixed_map;
85 widget_class->unmap = gtk_myfixed_unmap;
86 widget_class->realize = gtk_myfixed_realize;
87 widget_class->size_request = gtk_myfixed_size_request;
88 widget_class->size_allocate = gtk_myfixed_size_allocate;
89 widget_class->draw = gtk_myfixed_draw;
90 widget_class->expose_event = gtk_myfixed_expose;
91
92 container_class->add = gtk_myfixed_add;
93 container_class->remove = gtk_myfixed_remove;
94 #if (GTK_MINOR_VERSION == 1)
95 container_class->forall = gtk_myfixed_foreach;
96 #else
97 container_class->foreach = gtk_myfixed_foreach;
98 #endif
99 }
100
101 static void
102 gtk_myfixed_init (GtkMyFixed *myfixed)
103 {
104 GTK_WIDGET_UNSET_FLAGS (myfixed, GTK_NO_WINDOW);
105 GTK_WIDGET_SET_FLAGS (myfixed, GTK_BASIC);
106
107 myfixed->children = NULL;
108 }
109
110 GtkWidget*
111 gtk_myfixed_new ()
112 {
113 GtkMyFixed *myfixed;
114
115 myfixed = gtk_type_new (gtk_myfixed_get_type ());
116
117 return GTK_WIDGET (myfixed);
118 }
119
120 void
121 gtk_myfixed_put (GtkMyFixed *myfixed,
122 GtkWidget *widget,
123 gint16 x,
124 gint16 y)
125 {
126 GtkMyFixedChild *child_info;
127
128 g_return_if_fail (myfixed != NULL);
129 g_return_if_fail (GTK_IS_MYFIXED (myfixed));
130 g_return_if_fail (widget != NULL);
131
132 child_info = g_new (GtkMyFixedChild, 1);
133 child_info->widget = widget;
134 child_info->x = x;
135 child_info->y = y;
136
137 gtk_widget_set_parent (widget, GTK_WIDGET (myfixed));
138
139 myfixed->children = g_list_append (myfixed->children, child_info);
140
141 if (GTK_WIDGET_REALIZED (myfixed) && !GTK_WIDGET_REALIZED (widget))
142 gtk_widget_realize (widget);
143
144 if (GTK_WIDGET_MAPPED (myfixed) && !GTK_WIDGET_MAPPED (widget))
145 gtk_widget_map (widget);
146
147 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (myfixed))
148 gtk_widget_queue_resize (GTK_WIDGET (myfixed));
149 }
150
151 void
152 gtk_myfixed_move (GtkMyFixed *myfixed,
153 GtkWidget *widget,
154 gint16 x,
155 gint16 y)
156 {
157 GtkMyFixedChild *child;
158 GList *children;
159
160 g_return_if_fail (myfixed != NULL);
161 g_return_if_fail (GTK_IS_MYFIXED (myfixed));
162 g_return_if_fail (widget != NULL);
163
164 children = myfixed->children;
165 while (children)
166 {
167 child = children->data;
168 children = children->next;
169
170 if (child->widget == widget)
171 {
172 child->x = x;
173 child->y = y;
174
175 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (myfixed))
176 gtk_widget_queue_resize (GTK_WIDGET (myfixed));
177
178 break;
179 }
180 }
181 }
182
183 static void
184 gtk_myfixed_map (GtkWidget *widget)
185 {
186 GtkMyFixed *myfixed;
187 GtkMyFixedChild *child;
188 GList *children;
189
190 g_return_if_fail (widget != NULL);
191 g_return_if_fail (GTK_IS_MYFIXED (widget));
192
193 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
194 myfixed = GTK_MYFIXED (widget);
195
196 gdk_window_show (widget->window);
197
198 children = myfixed->children;
199 while (children)
200 {
201 child = children->data;
202 children = children->next;
203
204 if (GTK_WIDGET_VISIBLE (child->widget) &&
205 !GTK_WIDGET_MAPPED (child->widget))
206 gtk_widget_map (child->widget);
207 }
208 }
209
210 static void
211 gtk_myfixed_unmap (GtkWidget *widget)
212 {
213 g_return_if_fail (widget != NULL);
214 g_return_if_fail (GTK_IS_MYFIXED (widget));
215
216 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
217 }
218
219 static void
220 gtk_myfixed_realize (GtkWidget *widget)
221 {
222 GtkMyFixed *myfixed;
223 GdkWindowAttr attributes;
224 gint attributes_mask;
225
226 g_return_if_fail (widget != NULL);
227 g_return_if_fail (GTK_IS_MYFIXED (widget));
228
229 myfixed = GTK_MYFIXED (widget);
230
231 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
232
233 attributes.window_type = GDK_WINDOW_CHILD;
234 attributes.x = widget->allocation.x;
235 attributes.y = widget->allocation.y;
236 attributes.width = 32000;
237 attributes.height = 32000;
238 attributes.wclass = GDK_INPUT_OUTPUT;
239 attributes.visual = gtk_widget_get_visual (widget);
240 attributes.colormap = gtk_widget_get_colormap (widget);
241 attributes.event_mask = gtk_widget_get_events (widget);
242 attributes.event_mask |=
243 GDK_EXPOSURE_MASK |
244 GDK_POINTER_MOTION_MASK |
245 GDK_BUTTON_MOTION_MASK |
246 GDK_BUTTON1_MOTION_MASK |
247 GDK_BUTTON2_MOTION_MASK |
248 GDK_BUTTON3_MOTION_MASK |
249 GDK_BUTTON_PRESS_MASK |
250 GDK_BUTTON_RELEASE_MASK |
251 GDK_KEY_PRESS_MASK |
252 GDK_KEY_RELEASE_MASK |
253 GDK_ENTER_NOTIFY_MASK |
254 GDK_LEAVE_NOTIFY_MASK |
255 GDK_FOCUS_CHANGE_MASK;
256
257 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
258
259 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes,
260 attributes_mask);
261 gdk_window_set_user_data (widget->window, widget);
262
263 widget->style = gtk_style_attach (widget->style, widget->window);
264 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
265 }
266
267 static void
268 gtk_myfixed_size_request (GtkWidget *widget,
269 GtkRequisition *requisition)
270 {
271 GtkMyFixed *myfixed;
272 GtkMyFixedChild *child;
273 GList *children;
274
275 g_return_if_fail (widget != NULL);
276 g_return_if_fail (GTK_IS_MYFIXED (widget));
277 g_return_if_fail (requisition != NULL);
278
279 myfixed = GTK_MYFIXED (widget);
280
281 requisition->width = 0;
282 requisition->height = 0;
283
284 children = myfixed->children;
285 while (children)
286 {
287 child = children->data;
288 children = children->next;
289
290 if (GTK_WIDGET_VISIBLE (child->widget))
291 {
292 gtk_widget_size_request (child->widget, &child->widget->requisition);
293 }
294 }
295 }
296
297 static void
298 gtk_myfixed_size_allocate (GtkWidget *widget,
299 GtkAllocation *allocation)
300 {
301 GtkMyFixed *myfixed;
302 GtkMyFixedChild *child;
303 GtkAllocation child_allocation;
304 GList *children;
305 guint16 border_width;
306
307 g_return_if_fail (widget != NULL);
308 g_return_if_fail (GTK_IS_MYFIXED(widget));
309 g_return_if_fail (allocation != NULL);
310
311 myfixed = GTK_MYFIXED (widget);
312
313 widget->allocation = *allocation;
314 if (GTK_WIDGET_REALIZED (widget))
315 gdk_window_move_resize (widget->window, allocation->x, allocation->y, 32000, 32000 );
316
317 border_width = GTK_CONTAINER (myfixed)->border_width;
318
319 children = myfixed->children;
320 while (children)
321 {
322 child = children->data;
323 children = children->next;
324
325 if (GTK_WIDGET_VISIBLE (child->widget))
326 {
327 child_allocation.x = child->x + border_width;
328 child_allocation.y = child->y + border_width;
329 child_allocation.width = child->widget->requisition.width;
330 child_allocation.height = child->widget->requisition.height;
331 gtk_widget_size_allocate (child->widget, &child_allocation);
332 }
333 }
334 }
335
336 static void
337 gtk_myfixed_paint (GtkWidget *widget,
338 GdkRectangle *area)
339 {
340 g_return_if_fail (widget != NULL);
341 g_return_if_fail (GTK_IS_MYFIXED (widget));
342 g_return_if_fail (area != NULL);
343
344 if (GTK_WIDGET_DRAWABLE (widget))
345 gdk_window_clear_area (widget->window,
346 area->x, area->y,
347 area->width, area->height);
348 }
349
350 static void
351 gtk_myfixed_draw (GtkWidget *widget,
352 GdkRectangle *area)
353 {
354 GtkMyFixed *myfixed;
355 GtkMyFixedChild *child;
356 GdkRectangle child_area;
357 GList *children;
358
359 g_return_if_fail (widget != NULL);
360 g_return_if_fail (GTK_IS_MYFIXED (widget));
361
362 if (GTK_WIDGET_DRAWABLE (widget))
363 {
364 myfixed = GTK_MYFIXED (widget);
365 gtk_myfixed_paint (widget, area);
366
367 children = myfixed->children;
368 while (children)
369 {
370 child = children->data;
371 children = children->next;
372
373 if (gtk_widget_intersect (child->widget, area, &child_area))
374 gtk_widget_draw (child->widget, &child_area);
375 }
376 }
377 }
378
379 static gint
380 gtk_myfixed_expose (GtkWidget *widget,
381 GdkEventExpose *event)
382 {
383 GtkMyFixed *myfixed;
384 GtkMyFixedChild *child;
385 GdkEventExpose child_event;
386 GList *children;
387
388 g_return_val_if_fail (widget != NULL, FALSE);
389 g_return_val_if_fail (GTK_IS_MYFIXED (widget), FALSE);
390 g_return_val_if_fail (event != NULL, FALSE);
391
392 if (GTK_WIDGET_DRAWABLE (widget))
393 {
394 myfixed = GTK_MYFIXED (widget);
395
396 child_event = *event;
397
398 children = myfixed->children;
399 while (children)
400 {
401 child = children->data;
402 children = children->next;
403
404 if (GTK_WIDGET_NO_WINDOW (child->widget) &&
405 gtk_widget_intersect (child->widget, &event->area,
406 &child_event.area))
407 gtk_widget_event (child->widget, (GdkEvent*) &child_event);
408 }
409 }
410
411 return FALSE;
412 }
413
414 static void
415 gtk_myfixed_add (GtkContainer *container,
416 GtkWidget *widget)
417 {
418 g_return_if_fail (container != NULL);
419 g_return_if_fail (GTK_IS_MYFIXED (container));
420 g_return_if_fail (widget != NULL);
421
422 gtk_myfixed_put (GTK_MYFIXED (container), widget, 0, 0);
423 }
424
425 static void
426 gtk_myfixed_remove (GtkContainer *container,
427 GtkWidget *widget)
428 {
429 GtkMyFixed *myfixed;
430 GtkMyFixedChild *child;
431 GList *children;
432
433 g_return_if_fail (container != NULL);
434 g_return_if_fail (GTK_IS_MYFIXED (container));
435 g_return_if_fail (widget != NULL);
436
437 myfixed = GTK_MYFIXED (container);
438
439 children = myfixed->children;
440 while (children)
441 {
442 child = children->data;
443
444 if (child->widget == widget)
445 {
446 gtk_widget_unparent (widget);
447
448 myfixed->children = g_list_remove_link (myfixed->children, children);
449 g_list_free (children);
450 g_free (child);
451
452 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (container))
453 gtk_widget_queue_resize (GTK_WIDGET (container));
454
455 break;
456 }
457
458 children = children->next;
459 }
460 }
461
462 static void
463 gtk_myfixed_foreach (GtkContainer *container,
464 #if (GTK_MINOR_VERSION == 1)
465 gboolean include_internals,
466 #endif
467 GtkCallback callback,
468 gpointer callback_data)
469 {
470 GtkMyFixed *myfixed;
471 GtkMyFixedChild *child;
472 GList *children;
473
474 g_return_if_fail (container != NULL);
475 g_return_if_fail (GTK_IS_MYFIXED (container));
476 g_return_if_fail (callback != NULL);
477
478 myfixed = GTK_MYFIXED (container);
479
480 children = myfixed->children;
481 while (children)
482 {
483 child = children->data;
484 children = children->next;
485
486 (* callback) (child->widget, callback_data);
487 }
488 }
489
490
491 #ifdef __cplusplus
492 }
493 #endif /* __cplusplus */
494