Coompilation fixes for GTK 1.1.3
[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 #if (GTK_MINOR_VERSION == 1)
108 gtk_container_set_resize_mode( GTK_CONTAINER(myfixed), GTK_RESIZE_PARENT );
109 #endif
110
111 myfixed->children = NULL;
112 }
113
114 GtkWidget*
115 gtk_myfixed_new ()
116 {
117 GtkMyFixed *myfixed;
118
119 myfixed = gtk_type_new (gtk_myfixed_get_type ());
120
121 return GTK_WIDGET (myfixed);
122 }
123
124 void
125 gtk_myfixed_put (GtkMyFixed *myfixed,
126 GtkWidget *widget,
127 gint16 x,
128 gint16 y)
129 {
130 GtkMyFixedChild *child_info;
131
132 g_return_if_fail (myfixed != NULL);
133 g_return_if_fail (GTK_IS_MYFIXED (myfixed));
134 g_return_if_fail (widget != NULL);
135
136 child_info = g_new (GtkMyFixedChild, 1);
137 child_info->widget = widget;
138 child_info->x = x;
139 child_info->y = y;
140
141 gtk_widget_set_parent (widget, GTK_WIDGET (myfixed));
142
143 myfixed->children = g_list_append (myfixed->children, child_info);
144
145 if (GTK_WIDGET_REALIZED (myfixed) && !GTK_WIDGET_REALIZED (widget))
146 gtk_widget_realize (widget);
147
148 if (GTK_WIDGET_MAPPED (myfixed) && !GTK_WIDGET_MAPPED (widget))
149 gtk_widget_map (widget);
150
151 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (myfixed))
152 gtk_widget_queue_resize (GTK_WIDGET (myfixed));
153 }
154
155 void
156 gtk_myfixed_move (GtkMyFixed *myfixed,
157 GtkWidget *widget,
158 gint16 x,
159 gint16 y)
160 {
161 GtkMyFixedChild *child;
162 GList *children;
163
164 g_return_if_fail (myfixed != NULL);
165 g_return_if_fail (GTK_IS_MYFIXED (myfixed));
166 g_return_if_fail (widget != NULL);
167
168 children = myfixed->children;
169 while (children)
170 {
171 child = children->data;
172 children = children->next;
173
174 if (child->widget == widget)
175 {
176 if ((child->x == x) && (child->y == y)) return;
177
178 child->x = x;
179 child->y = y;
180
181 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (myfixed))
182 gtk_widget_queue_resize (GTK_WIDGET (myfixed));
183
184 break;
185 }
186 }
187 }
188
189 static void
190 gtk_myfixed_map (GtkWidget *widget)
191 {
192 GtkMyFixed *myfixed;
193 GtkMyFixedChild *child;
194 GList *children;
195
196 g_return_if_fail (widget != NULL);
197 g_return_if_fail (GTK_IS_MYFIXED (widget));
198
199 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
200 myfixed = GTK_MYFIXED (widget);
201
202 gdk_window_show (widget->window);
203
204 children = myfixed->children;
205 while (children)
206 {
207 child = children->data;
208 children = children->next;
209
210 if (GTK_WIDGET_VISIBLE (child->widget) &&
211 !GTK_WIDGET_MAPPED (child->widget))
212 gtk_widget_map (child->widget);
213 }
214 }
215
216 static void
217 gtk_myfixed_unmap (GtkWidget *widget)
218 {
219 g_return_if_fail (widget != NULL);
220 g_return_if_fail (GTK_IS_MYFIXED (widget));
221
222 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
223 }
224
225 static void
226 gtk_myfixed_realize (GtkWidget *widget)
227 {
228 GtkMyFixed *myfixed;
229 GdkWindowAttr attributes;
230 gint attributes_mask;
231
232 g_return_if_fail (widget != NULL);
233 g_return_if_fail (GTK_IS_MYFIXED (widget));
234
235 myfixed = GTK_MYFIXED (widget);
236
237 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
238
239 attributes.window_type = GDK_WINDOW_CHILD;
240 attributes.x = widget->allocation.x;
241 attributes.y = widget->allocation.y;
242 attributes.width = 32000;
243 attributes.height = 32000;
244 attributes.wclass = GDK_INPUT_OUTPUT;
245 attributes.visual = gtk_widget_get_visual (widget);
246 attributes.colormap = gtk_widget_get_colormap (widget);
247 attributes.event_mask = gtk_widget_get_events (widget);
248 attributes.event_mask |=
249 GDK_EXPOSURE_MASK |
250 GDK_POINTER_MOTION_MASK |
251 GDK_BUTTON_MOTION_MASK |
252 GDK_BUTTON1_MOTION_MASK |
253 GDK_BUTTON2_MOTION_MASK |
254 GDK_BUTTON3_MOTION_MASK |
255 GDK_BUTTON_PRESS_MASK |
256 GDK_BUTTON_RELEASE_MASK |
257 GDK_KEY_PRESS_MASK |
258 GDK_KEY_RELEASE_MASK |
259 GDK_ENTER_NOTIFY_MASK |
260 GDK_LEAVE_NOTIFY_MASK |
261 GDK_FOCUS_CHANGE_MASK;
262
263 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
264
265 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes,
266 attributes_mask);
267 gdk_window_set_user_data (widget->window, widget);
268
269 widget->style = gtk_style_attach (widget->style, widget->window);
270 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
271 }
272
273 static void
274 gtk_myfixed_size_request (GtkWidget *widget,
275 GtkRequisition *requisition)
276 {
277 GtkMyFixed *myfixed;
278 GtkMyFixedChild *child;
279 GList *children;
280
281 g_return_if_fail (widget != NULL);
282 g_return_if_fail (GTK_IS_MYFIXED (widget));
283 g_return_if_fail (requisition != NULL);
284
285 myfixed = GTK_MYFIXED (widget);
286
287 requisition->width = 0;
288 requisition->height = 0;
289
290 children = myfixed->children;
291 while (children)
292 {
293 child = children->data;
294 children = children->next;
295
296 if (GTK_WIDGET_VISIBLE (child->widget))
297 {
298 gtk_widget_size_request (child->widget, &child->widget->requisition);
299 }
300 }
301 }
302
303 static void
304 gtk_myfixed_size_allocate (GtkWidget *widget,
305 GtkAllocation *allocation)
306 {
307 GtkMyFixed *myfixed;
308 GtkMyFixedChild *child;
309 GtkAllocation child_allocation;
310 GList *children;
311 guint16 border_width;
312
313 g_return_if_fail (widget != NULL);
314 g_return_if_fail (GTK_IS_MYFIXED(widget));
315 g_return_if_fail (allocation != NULL);
316
317 myfixed = GTK_MYFIXED (widget);
318
319 widget->allocation = *allocation;
320 if (GTK_WIDGET_REALIZED (widget))
321 gdk_window_move_resize (widget->window, allocation->x, allocation->y, 32000, 32000 );
322
323 border_width = GTK_CONTAINER (myfixed)->border_width;
324
325 children = myfixed->children;
326 while (children)
327 {
328 child = children->data;
329 children = children->next;
330
331 if (GTK_WIDGET_VISIBLE (child->widget))
332 {
333 child_allocation.x = child->x + border_width;
334 child_allocation.y = child->y + border_width;
335 child_allocation.width = child->widget->requisition.width;
336 child_allocation.height = child->widget->requisition.height;
337 gtk_widget_size_allocate (child->widget, &child_allocation);
338 }
339 }
340 }
341
342 static void
343 gtk_myfixed_paint (GtkWidget *widget,
344 GdkRectangle *area)
345 {
346 g_return_if_fail (widget != NULL);
347 g_return_if_fail (GTK_IS_MYFIXED (widget));
348 g_return_if_fail (area != NULL);
349
350 if (GTK_WIDGET_DRAWABLE (widget))
351 gdk_window_clear_area (widget->window,
352 area->x, area->y,
353 area->width, area->height);
354 }
355
356 static void
357 gtk_myfixed_draw (GtkWidget *widget,
358 GdkRectangle *area)
359 {
360 GtkMyFixed *myfixed;
361 GtkMyFixedChild *child;
362 GdkRectangle child_area;
363 GList *children;
364
365 g_return_if_fail (widget != NULL);
366 g_return_if_fail (GTK_IS_MYFIXED (widget));
367
368 if (GTK_WIDGET_DRAWABLE (widget))
369 {
370 myfixed = GTK_MYFIXED (widget);
371 gtk_myfixed_paint (widget, area);
372
373 children = myfixed->children;
374 while (children)
375 {
376 child = children->data;
377 children = children->next;
378
379 if (gtk_widget_intersect (child->widget, area, &child_area))
380 gtk_widget_draw (child->widget, &child_area);
381 }
382 }
383 }
384
385 static gint
386 gtk_myfixed_expose (GtkWidget *widget,
387 GdkEventExpose *event)
388 {
389 GtkMyFixed *myfixed;
390 GtkMyFixedChild *child;
391 GdkEventExpose child_event;
392 GList *children;
393
394 g_return_val_if_fail (widget != NULL, FALSE);
395 g_return_val_if_fail (GTK_IS_MYFIXED (widget), FALSE);
396 g_return_val_if_fail (event != NULL, FALSE);
397
398 if (GTK_WIDGET_DRAWABLE (widget))
399 {
400 myfixed = GTK_MYFIXED (widget);
401
402 child_event = *event;
403
404 children = myfixed->children;
405 while (children)
406 {
407 child = children->data;
408 children = children->next;
409
410 if (GTK_WIDGET_NO_WINDOW (child->widget) &&
411 gtk_widget_intersect (child->widget, &event->area,
412 &child_event.area))
413 gtk_widget_event (child->widget, (GdkEvent*) &child_event);
414 }
415 }
416
417 return FALSE;
418 }
419
420 static void
421 gtk_myfixed_add (GtkContainer *container,
422 GtkWidget *widget)
423 {
424 g_return_if_fail (container != NULL);
425 g_return_if_fail (GTK_IS_MYFIXED (container));
426 g_return_if_fail (widget != NULL);
427
428 gtk_myfixed_put (GTK_MYFIXED (container), widget, 0, 0);
429 }
430
431 static void
432 gtk_myfixed_remove (GtkContainer *container,
433 GtkWidget *widget)
434 {
435 GtkMyFixed *myfixed;
436 GtkMyFixedChild *child;
437 GList *children;
438
439 g_return_if_fail (container != NULL);
440 g_return_if_fail (GTK_IS_MYFIXED (container));
441 g_return_if_fail (widget != NULL);
442
443 myfixed = GTK_MYFIXED (container);
444
445 children = myfixed->children;
446 while (children)
447 {
448 child = children->data;
449
450 if (child->widget == widget)
451 {
452 gtk_widget_unparent (widget);
453
454 myfixed->children = g_list_remove_link (myfixed->children, children);
455 g_list_free (children);
456 g_free (child);
457
458 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (container))
459 gtk_widget_queue_resize (GTK_WIDGET (container));
460
461 break;
462 }
463
464 children = children->next;
465 }
466 }
467
468 static void
469 gtk_myfixed_foreach (GtkContainer *container,
470 #if (GTK_MINOR_VERSION == 1)
471 gboolean include_internals,
472 #endif
473 GtkCallback callback,
474 gpointer callback_data)
475 {
476 GtkMyFixed *myfixed;
477 GtkMyFixedChild *child;
478 GList *children;
479
480 g_return_if_fail (container != NULL);
481 g_return_if_fail (GTK_IS_MYFIXED (container));
482 g_return_if_fail (callback != NULL);
483
484 myfixed = GTK_MYFIXED (container);
485
486 children = myfixed->children;
487 while (children)
488 {
489 child = children->data;
490 children = children->next;
491
492 (* callback) (child->widget, callback_data);
493 }
494 }
495
496
497 #ifdef __cplusplus
498 }
499 #endif /* __cplusplus */
500