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