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_POINTER_MOTION_HINT_MASK
|
292 GDK_BUTTON_MOTION_MASK
|
293 GDK_BUTTON1_MOTION_MASK
|
294 GDK_BUTTON2_MOTION_MASK
|
295 GDK_BUTTON3_MOTION_MASK
|
296 GDK_BUTTON_PRESS_MASK
|
297 GDK_BUTTON_RELEASE_MASK
|
299 GDK_KEY_RELEASE_MASK
|
300 GDK_ENTER_NOTIFY_MASK
|
301 GDK_LEAVE_NOTIFY_MASK
|
302 GDK_FOCUS_CHANGE_MASK
;
304 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
306 widget
->window
= gdk_window_new (gtk_widget_get_parent_window (widget
), &attributes
,
308 gdk_window_set_user_data (widget
->window
, widget
);
310 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
311 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
315 gtk_myfixed_size_request (GtkWidget
*widget
,
316 GtkRequisition
*requisition
)
319 GtkMyFixedChild
*child
;
322 g_return_if_fail (widget
!= NULL
);
323 g_return_if_fail (GTK_IS_MYFIXED (widget
));
324 g_return_if_fail (requisition
!= NULL
);
326 myfixed
= GTK_MYFIXED (widget
);
328 requisition
->width
= 0;
329 requisition
->height
= 0;
331 children
= myfixed
->children
;
334 child
= children
->data
;
335 children
= children
->next
;
337 if (GTK_WIDGET_VISIBLE (child
->widget
))
339 gtk_widget_size_request (child
->widget
, &child
->widget
->requisition
);
345 gtk_myfixed_size_allocate (GtkWidget
*widget
,
346 GtkAllocation
*allocation
)
349 GtkMyFixedChild
*child
;
350 GtkAllocation child_allocation
;
352 guint16 border_width
;
354 g_return_if_fail (widget
!= NULL
);
355 g_return_if_fail (GTK_IS_MYFIXED(widget
));
356 g_return_if_fail (allocation
!= NULL
);
358 myfixed
= GTK_MYFIXED (widget
);
360 widget
->allocation
= *allocation
;
361 if (GTK_WIDGET_REALIZED (widget
))
362 gdk_window_move_resize (widget
->window
, allocation
->x
, allocation
->y
, 32000, 32000 );
364 border_width
= GTK_CONTAINER (myfixed
)->border_width
;
366 children
= myfixed
->children
;
369 child
= children
->data
;
370 children
= children
->next
;
372 if (GTK_WIDGET_VISIBLE (child
->widget
))
374 child_allocation
.x
= child
->x
+ border_width
;
375 child_allocation
.y
= child
->y
+ border_width
;
376 child_allocation
.width
= child
->widget
->requisition
.width
;
377 child_allocation
.height
= child
->widget
->requisition
.height
;
378 gtk_widget_size_allocate (child
->widget
, &child_allocation
);
384 gtk_myfixed_paint (GtkWidget
*widget
,
387 g_return_if_fail (widget
!= NULL
);
388 g_return_if_fail (GTK_IS_MYFIXED (widget
));
389 g_return_if_fail (area
!= NULL
);
391 if (GTK_WIDGET_DRAWABLE (widget
))
392 gdk_window_clear_area (widget
->window
,
394 area
->width
, area
->height
);
398 gtk_myfixed_draw (GtkWidget
*widget
,
402 GtkMyFixedChild
*child
;
403 GdkRectangle child_area
;
406 g_return_if_fail (widget
!= NULL
);
407 g_return_if_fail (GTK_IS_MYFIXED (widget
));
409 if (GTK_WIDGET_DRAWABLE (widget
))
411 myfixed
= GTK_MYFIXED (widget
);
412 gtk_myfixed_paint (widget
, area
);
414 children
= myfixed
->children
;
417 child
= children
->data
;
418 children
= children
->next
;
420 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
421 gtk_widget_draw (child
->widget
, &child_area
);
427 gtk_myfixed_expose (GtkWidget
*widget
,
428 GdkEventExpose
*event
)
431 GtkMyFixedChild
*child
;
432 GdkEventExpose child_event
;
435 g_return_val_if_fail (widget
!= NULL
, FALSE
);
436 g_return_val_if_fail (GTK_IS_MYFIXED (widget
), FALSE
);
437 g_return_val_if_fail (event
!= NULL
, FALSE
);
439 if (GTK_WIDGET_DRAWABLE (widget
))
441 myfixed
= GTK_MYFIXED (widget
);
443 child_event
= *event
;
445 children
= myfixed
->children
;
448 child
= children
->data
;
449 children
= children
->next
;
451 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
452 gtk_widget_intersect (child
->widget
, &event
->area
,
454 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
462 gtk_myfixed_add (GtkContainer
*container
,
465 g_return_if_fail (container
!= NULL
);
466 g_return_if_fail (GTK_IS_MYFIXED (container
));
467 g_return_if_fail (widget
!= NULL
);
469 gtk_myfixed_put (GTK_MYFIXED (container
), widget
, 0, 0);
473 gtk_myfixed_remove (GtkContainer
*container
,
477 GtkMyFixedChild
*child
;
480 g_return_if_fail (container
!= NULL
);
481 g_return_if_fail (GTK_IS_MYFIXED (container
));
482 g_return_if_fail (widget
!= NULL
);
484 myfixed
= GTK_MYFIXED (container
);
486 children
= myfixed
->children
;
489 child
= children
->data
;
491 if (child
->widget
== widget
)
493 gtk_widget_unparent (widget
);
495 myfixed
->children
= g_list_remove_link (myfixed
->children
, children
);
496 g_list_free (children
);
499 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (container
))
500 gtk_widget_queue_resize (GTK_WIDGET (container
));
505 children
= children
->next
;
510 gtk_myfixed_foreach (GtkContainer
*container
,
511 #if (GTK_MINOR_VERSION == 1)
512 gboolean include_internals
,
514 GtkCallback callback
,
515 gpointer callback_data
)
518 GtkMyFixedChild
*child
;
521 g_return_if_fail (container
!= NULL
);
522 g_return_if_fail (GTK_IS_MYFIXED (container
));
523 g_return_if_fail (callback
!= NULL
);
525 myfixed
= GTK_MYFIXED (container
);
527 children
= myfixed
->children
;
530 child
= children
->data
;
531 children
= children
->next
;
533 (* callback
) (child
->widget
, callback_data
);
540 #endif /* __cplusplus */