1 /* ///////////////////////////////////////////////////////////////////////////
3 // Purpose: native GTK+ widget for wxWindows
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////// */
10 #include "wx/gtk/win_gtk.h"
11 #include <gtk/gtkfeatures.h>
13 /*-------------------------------------------------------------------------
14 // conditional compilation
15 //------------------------------------------------------------------------- */
17 #if (GTK_MINOR_VERSION == 1)
18 #if (GTK_MICRO_VERSION >= 5)
19 #define NEW_GTK_CONSTRUCT_CODE
25 #endif /* __cplusplus */
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
);
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
,
40 static void gtk_myfixed_draw (GtkWidget
*widget
,
42 static gint
gtk_myfixed_expose (GtkWidget
*widget
,
43 GdkEventExpose
*event
);
44 static void gtk_myfixed_add (GtkContainer
*container
,
46 static void gtk_myfixed_remove (GtkContainer
*container
,
48 static void gtk_myfixed_foreach (GtkContainer
*container
,
49 #if (GTK_MINOR_VERSION == 1)
50 gboolean include_internals
,
53 gpointer callback_data
);
54 #ifdef NEW_GTK_CONSTRUCT_CODE
55 static GtkType
gtk_myfixed_child_type (GtkContainer
*container
);
59 static GtkContainerClass
*parent_class
= NULL
;
63 gtk_myfixed_get_type ()
65 static guint myfixed_type
= 0;
69 GtkTypeInfo myfixed_info
=
73 sizeof (GtkMyFixedClass
),
74 (GtkClassInitFunc
) gtk_myfixed_class_init
,
75 (GtkObjectInitFunc
) gtk_myfixed_init
,
76 #ifndef NEW_GTK_CONSTRUCT_CODE
80 /* reserved_1 */ NULL
,
81 /* reserved_2 */ NULL
,
82 (GtkClassInitFunc
) NULL
,
86 myfixed_type
= gtk_type_unique (gtk_container_get_type (), &myfixed_info
);
93 gtk_myfixed_class_init (GtkMyFixedClass
*klass
)
95 GtkObjectClass
*object_class
;
96 GtkWidgetClass
*widget_class
;
97 GtkContainerClass
*container_class
;
99 object_class
= (GtkObjectClass
*) klass
;
100 widget_class
= (GtkWidgetClass
*) klass
;
101 container_class
= (GtkContainerClass
*) klass
;
103 #ifndef NEW_GTK_CONSTRUCT_CODE
104 parent_class
= gtk_type_class (gtk_container_get_type ());
106 parent_class
= gtk_type_class (GTK_TYPE_CONTAINER
);
109 widget_class
->map
= gtk_myfixed_map
;
110 #ifndef NEW_GTK_CONSTRUCT_CODE
111 widget_class
->unmap
= gtk_myfixed_unmap
;
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
;
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
;
124 container_class
->foreach
= gtk_myfixed_foreach
;
127 #ifdef NEW_GTK_CONSTRUCT_CODE
128 container_class
->child_type
= gtk_myfixed_child_type
;
132 #ifdef NEW_GTK_CONSTRUCT_CODE
134 gtk_myfixed_child_type (GtkContainer
*container
)
136 return GTK_TYPE_WIDGET
;
141 gtk_myfixed_init (GtkMyFixed
*myfixed
)
143 GTK_WIDGET_UNSET_FLAGS (myfixed
, GTK_NO_WINDOW
);
145 #ifndef NEW_GTK_CONSTRUCT_CODE
146 GTK_WIDGET_SET_FLAGS (myfixed
, GTK_BASIC
);
149 myfixed
->children
= NULL
;
157 myfixed
= gtk_type_new (gtk_myfixed_get_type ());
159 return GTK_WIDGET (myfixed
);
163 gtk_myfixed_put (GtkMyFixed
*myfixed
,
168 GtkMyFixedChild
*child_info
;
170 g_return_if_fail (myfixed
!= NULL
);
171 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
172 g_return_if_fail (widget
!= NULL
);
174 child_info
= g_new (GtkMyFixedChild
, 1);
175 child_info
->widget
= widget
;
179 gtk_widget_set_parent (widget
, GTK_WIDGET (myfixed
));
181 myfixed
->children
= g_list_append (myfixed
->children
, child_info
);
183 if (GTK_WIDGET_REALIZED (myfixed
) && !GTK_WIDGET_REALIZED (widget
))
184 gtk_widget_realize (widget
);
186 if (GTK_WIDGET_MAPPED (myfixed
) && !GTK_WIDGET_MAPPED (widget
))
187 gtk_widget_map (widget
);
189 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (myfixed
))
190 gtk_widget_queue_resize (GTK_WIDGET (myfixed
));
194 gtk_myfixed_move (GtkMyFixed
*myfixed
,
199 GtkMyFixedChild
*child
;
202 g_return_if_fail (myfixed
!= NULL
);
203 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
204 g_return_if_fail (widget
!= NULL
);
206 children
= myfixed
->children
;
209 child
= children
->data
;
210 children
= children
->next
;
212 if (child
->widget
== widget
)
214 if ((child
->x
== x
) && (child
->y
== y
)) return;
219 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (myfixed
))
220 gtk_widget_queue_resize (GTK_WIDGET (myfixed
));
228 gtk_myfixed_map (GtkWidget
*widget
)
231 GtkMyFixedChild
*child
;
234 g_return_if_fail (widget
!= NULL
);
235 g_return_if_fail (GTK_IS_MYFIXED (widget
));
237 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
238 myfixed
= GTK_MYFIXED (widget
);
240 gdk_window_show (widget
->window
);
242 children
= myfixed
->children
;
245 child
= children
->data
;
246 children
= children
->next
;
248 if (GTK_WIDGET_VISIBLE (child
->widget
) &&
249 !GTK_WIDGET_MAPPED (child
->widget
))
250 gtk_widget_map (child
->widget
);
254 #ifndef NEW_GTK_CONSTRUCT_CODE
256 gtk_myfixed_unmap (GtkWidget
*widget
)
258 g_return_if_fail (widget
!= NULL
);
259 g_return_if_fail (GTK_IS_MYFIXED (widget
));
261 GTK_WIDGET_UNSET_FLAGS (widget
, GTK_MAPPED
);
266 gtk_myfixed_realize (GtkWidget
*widget
)
269 GdkWindowAttr attributes
;
270 gint attributes_mask
;
272 g_return_if_fail (widget
!= NULL
);
273 g_return_if_fail (GTK_IS_MYFIXED (widget
));
275 myfixed
= GTK_MYFIXED (widget
);
277 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
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
|=
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
|
298 GDK_KEY_RELEASE_MASK
|
299 GDK_ENTER_NOTIFY_MASK
|
300 GDK_LEAVE_NOTIFY_MASK
|
301 GDK_FOCUS_CHANGE_MASK
;
303 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
305 widget
->window
= gdk_window_new (gtk_widget_get_parent_window (widget
), &attributes
,
307 gdk_window_set_user_data (widget
->window
, widget
);
309 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
310 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
314 gtk_myfixed_size_request (GtkWidget
*widget
,
315 GtkRequisition
*requisition
)
318 GtkMyFixedChild
*child
;
321 g_return_if_fail (widget
!= NULL
);
322 g_return_if_fail (GTK_IS_MYFIXED (widget
));
323 g_return_if_fail (requisition
!= NULL
);
325 myfixed
= GTK_MYFIXED (widget
);
327 requisition
->width
= 0;
328 requisition
->height
= 0;
330 children
= myfixed
->children
;
333 child
= children
->data
;
334 children
= children
->next
;
336 if (GTK_WIDGET_VISIBLE (child
->widget
))
338 gtk_widget_size_request (child
->widget
, &child
->widget
->requisition
);
344 gtk_myfixed_size_allocate (GtkWidget
*widget
,
345 GtkAllocation
*allocation
)
348 GtkMyFixedChild
*child
;
349 GtkAllocation child_allocation
;
351 guint16 border_width
;
353 g_return_if_fail (widget
!= NULL
);
354 g_return_if_fail (GTK_IS_MYFIXED(widget
));
355 g_return_if_fail (allocation
!= NULL
);
357 myfixed
= GTK_MYFIXED (widget
);
359 widget
->allocation
= *allocation
;
360 if (GTK_WIDGET_REALIZED (widget
))
361 gdk_window_move_resize (widget
->window
, allocation
->x
, allocation
->y
, 32000, 32000 );
363 border_width
= GTK_CONTAINER (myfixed
)->border_width
;
365 children
= myfixed
->children
;
368 child
= children
->data
;
369 children
= children
->next
;
371 if (GTK_WIDGET_VISIBLE (child
->widget
))
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
);
383 gtk_myfixed_paint (GtkWidget
*widget
,
386 g_return_if_fail (widget
!= NULL
);
387 g_return_if_fail (GTK_IS_MYFIXED (widget
));
388 g_return_if_fail (area
!= NULL
);
390 if (GTK_WIDGET_DRAWABLE (widget
))
391 gdk_window_clear_area (widget
->window
,
393 area
->width
, area
->height
);
397 gtk_myfixed_draw (GtkWidget
*widget
,
401 GtkMyFixedChild
*child
;
402 GdkRectangle child_area
;
405 g_return_if_fail (widget
!= NULL
);
406 g_return_if_fail (GTK_IS_MYFIXED (widget
));
408 if (GTK_WIDGET_DRAWABLE (widget
))
410 myfixed
= GTK_MYFIXED (widget
);
411 gtk_myfixed_paint (widget
, area
);
413 children
= myfixed
->children
;
416 child
= children
->data
;
417 children
= children
->next
;
419 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
420 gtk_widget_draw (child
->widget
, &child_area
);
426 gtk_myfixed_expose (GtkWidget
*widget
,
427 GdkEventExpose
*event
)
430 GtkMyFixedChild
*child
;
431 GdkEventExpose child_event
;
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
);
438 if (GTK_WIDGET_DRAWABLE (widget
))
440 myfixed
= GTK_MYFIXED (widget
);
442 child_event
= *event
;
444 children
= myfixed
->children
;
447 child
= children
->data
;
448 children
= children
->next
;
450 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
451 gtk_widget_intersect (child
->widget
, &event
->area
,
453 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
461 gtk_myfixed_add (GtkContainer
*container
,
464 g_return_if_fail (container
!= NULL
);
465 g_return_if_fail (GTK_IS_MYFIXED (container
));
466 g_return_if_fail (widget
!= NULL
);
468 gtk_myfixed_put (GTK_MYFIXED (container
), widget
, 0, 0);
472 gtk_myfixed_remove (GtkContainer
*container
,
476 GtkMyFixedChild
*child
;
479 g_return_if_fail (container
!= NULL
);
480 g_return_if_fail (GTK_IS_MYFIXED (container
));
481 g_return_if_fail (widget
!= NULL
);
483 myfixed
= GTK_MYFIXED (container
);
485 children
= myfixed
->children
;
488 child
= children
->data
;
490 if (child
->widget
== widget
)
492 gtk_widget_unparent (widget
);
494 myfixed
->children
= g_list_remove_link (myfixed
->children
, children
);
495 g_list_free (children
);
498 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (container
))
499 gtk_widget_queue_resize (GTK_WIDGET (container
));
504 children
= children
->next
;
509 gtk_myfixed_foreach (GtkContainer
*container
,
510 #if (GTK_MINOR_VERSION == 1)
511 gboolean include_internals
,
513 GtkCallback callback
,
514 gpointer callback_data
)
517 GtkMyFixedChild
*child
;
520 g_return_if_fail (container
!= NULL
);
521 g_return_if_fail (GTK_IS_MYFIXED (container
));
522 g_return_if_fail (callback
!= NULL
);
524 myfixed
= GTK_MYFIXED (container
);
526 children
= myfixed
->children
;
529 child
= children
->data
;
530 children
= children
->next
;
532 (* callback
) (child
->widget
, callback_data
);
539 #endif /* __cplusplus */