1 /* ///////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////// */
11 #include "wx/gtk/win_gtk.h"
12 #include <gtk/gtkfeatures.h>
16 #endif /* __cplusplus */
18 static void gtk_myfixed_class_init (GtkMyFixedClass
*klass
);
19 static void gtk_myfixed_init (GtkMyFixed
*myfixed
);
20 static void gtk_myfixed_map (GtkWidget
*widget
);
21 static void gtk_myfixed_unmap (GtkWidget
*widget
);
22 static void gtk_myfixed_realize (GtkWidget
*widget
);
23 static void gtk_myfixed_size_request (GtkWidget
*widget
,
24 GtkRequisition
*requisition
);
25 static void gtk_myfixed_size_allocate (GtkWidget
*widget
,
26 GtkAllocation
*allocation
);
27 static void gtk_myfixed_paint (GtkWidget
*widget
,
29 static void gtk_myfixed_draw (GtkWidget
*widget
,
31 static gint
gtk_myfixed_expose (GtkWidget
*widget
,
32 GdkEventExpose
*event
);
33 static void gtk_myfixed_add (GtkContainer
*container
,
35 static void gtk_myfixed_remove (GtkContainer
*container
,
37 static void gtk_myfixed_foreach (GtkContainer
*container
,
38 #if (GTK_MINOR_VERSION == 1)
39 gboolean include_internals
,
42 gpointer callback_data
);
45 static GtkContainerClass
*parent_class
= NULL
;
49 gtk_myfixed_get_type ()
51 static guint myfixed_type
= 0;
55 GtkTypeInfo myfixed_info
=
59 sizeof (GtkMyFixedClass
),
60 (GtkClassInitFunc
) gtk_myfixed_class_init
,
61 (GtkObjectInitFunc
) gtk_myfixed_init
,
66 myfixed_type
= gtk_type_unique (gtk_container_get_type (), &myfixed_info
);
73 gtk_myfixed_class_init (GtkMyFixedClass
*klass
)
75 GtkObjectClass
*object_class
;
76 GtkWidgetClass
*widget_class
;
77 GtkContainerClass
*container_class
;
79 object_class
= (GtkObjectClass
*) klass
;
80 widget_class
= (GtkWidgetClass
*) klass
;
81 container_class
= (GtkContainerClass
*) klass
;
83 parent_class
= gtk_type_class (gtk_container_get_type ());
85 widget_class
->map
= gtk_myfixed_map
;
86 widget_class
->unmap
= gtk_myfixed_unmap
;
87 widget_class
->realize
= gtk_myfixed_realize
;
88 widget_class
->size_request
= gtk_myfixed_size_request
;
89 widget_class
->size_allocate
= gtk_myfixed_size_allocate
;
90 widget_class
->draw
= gtk_myfixed_draw
;
91 widget_class
->expose_event
= gtk_myfixed_expose
;
93 container_class
->add
= gtk_myfixed_add
;
94 container_class
->remove
= gtk_myfixed_remove
;
95 #if (GTK_MINOR_VERSION == 1)
96 container_class
->forall
= gtk_myfixed_foreach
;
98 container_class
->foreach
= gtk_myfixed_foreach
;
103 gtk_myfixed_init (GtkMyFixed
*myfixed
)
105 GTK_WIDGET_UNSET_FLAGS (myfixed
, GTK_NO_WINDOW
);
106 GTK_WIDGET_SET_FLAGS (myfixed
, GTK_BASIC
);
108 myfixed
->children
= NULL
;
116 myfixed
= gtk_type_new (gtk_myfixed_get_type ());
118 return GTK_WIDGET (myfixed
);
122 gtk_myfixed_put (GtkMyFixed
*myfixed
,
127 GtkMyFixedChild
*child_info
;
129 g_return_if_fail (myfixed
!= NULL
);
130 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
131 g_return_if_fail (widget
!= NULL
);
133 child_info
= g_new (GtkMyFixedChild
, 1);
134 child_info
->widget
= widget
;
138 gtk_widget_set_parent (widget
, GTK_WIDGET (myfixed
));
140 myfixed
->children
= g_list_append (myfixed
->children
, child_info
);
142 if (GTK_WIDGET_REALIZED (myfixed
) && !GTK_WIDGET_REALIZED (widget
))
143 gtk_widget_realize (widget
);
145 if (GTK_WIDGET_MAPPED (myfixed
) && !GTK_WIDGET_MAPPED (widget
))
146 gtk_widget_map (widget
);
148 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (myfixed
))
149 gtk_widget_queue_resize (GTK_WIDGET (myfixed
));
153 gtk_myfixed_move (GtkMyFixed
*myfixed
,
158 GtkMyFixedChild
*child
;
161 g_return_if_fail (myfixed
!= NULL
);
162 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
163 g_return_if_fail (widget
!= NULL
);
165 children
= myfixed
->children
;
168 child
= children
->data
;
169 children
= children
->next
;
171 if (child
->widget
== widget
)
176 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (myfixed
))
177 gtk_widget_queue_resize (GTK_WIDGET (myfixed
));
185 gtk_myfixed_map (GtkWidget
*widget
)
188 GtkMyFixedChild
*child
;
191 g_return_if_fail (widget
!= NULL
);
192 g_return_if_fail (GTK_IS_MYFIXED (widget
));
194 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
195 myfixed
= GTK_MYFIXED (widget
);
197 gdk_window_show (widget
->window
);
199 children
= myfixed
->children
;
202 child
= children
->data
;
203 children
= children
->next
;
205 if (GTK_WIDGET_VISIBLE (child
->widget
) &&
206 !GTK_WIDGET_MAPPED (child
->widget
))
207 gtk_widget_map (child
->widget
);
212 gtk_myfixed_unmap (GtkWidget
*widget
)
214 g_return_if_fail (widget
!= NULL
);
215 g_return_if_fail (GTK_IS_MYFIXED (widget
));
217 GTK_WIDGET_UNSET_FLAGS (widget
, GTK_MAPPED
);
221 gtk_myfixed_realize (GtkWidget
*widget
)
224 GdkWindowAttr attributes
;
225 gint attributes_mask
;
227 g_return_if_fail (widget
!= NULL
);
228 g_return_if_fail (GTK_IS_MYFIXED (widget
));
230 myfixed
= GTK_MYFIXED (widget
);
232 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
234 attributes
.window_type
= GDK_WINDOW_CHILD
;
235 attributes
.x
= widget
->allocation
.x
;
236 attributes
.y
= widget
->allocation
.y
;
237 attributes
.width
= 32000;
238 attributes
.height
= 32000;
239 attributes
.wclass
= GDK_INPUT_OUTPUT
;
240 attributes
.visual
= gtk_widget_get_visual (widget
);
241 attributes
.colormap
= gtk_widget_get_colormap (widget
);
242 attributes
.event_mask
= gtk_widget_get_events (widget
);
243 attributes
.event_mask
|=
245 GDK_POINTER_MOTION_MASK
|
246 GDK_BUTTON_MOTION_MASK
|
247 GDK_BUTTON1_MOTION_MASK
|
248 GDK_BUTTON2_MOTION_MASK
|
249 GDK_BUTTON3_MOTION_MASK
|
250 GDK_BUTTON_PRESS_MASK
|
251 GDK_BUTTON_RELEASE_MASK
|
253 GDK_KEY_RELEASE_MASK
|
254 GDK_ENTER_NOTIFY_MASK
|
255 GDK_LEAVE_NOTIFY_MASK
|
256 GDK_FOCUS_CHANGE_MASK
;
258 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
260 widget
->window
= gdk_window_new (gtk_widget_get_parent_window (widget
), &attributes
,
262 gdk_window_set_user_data (widget
->window
, widget
);
264 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
265 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
269 gtk_myfixed_size_request (GtkWidget
*widget
,
270 GtkRequisition
*requisition
)
273 GtkMyFixedChild
*child
;
276 g_return_if_fail (widget
!= NULL
);
277 g_return_if_fail (GTK_IS_MYFIXED (widget
));
278 g_return_if_fail (requisition
!= NULL
);
280 myfixed
= GTK_MYFIXED (widget
);
282 requisition
->width
= 0;
283 requisition
->height
= 0;
285 children
= myfixed
->children
;
288 child
= children
->data
;
289 children
= children
->next
;
291 if (GTK_WIDGET_VISIBLE (child
->widget
))
293 gtk_widget_size_request (child
->widget
, &child
->widget
->requisition
);
299 gtk_myfixed_size_allocate (GtkWidget
*widget
,
300 GtkAllocation
*allocation
)
303 GtkMyFixedChild
*child
;
304 GtkAllocation child_allocation
;
306 guint16 border_width
;
308 g_return_if_fail (widget
!= NULL
);
309 g_return_if_fail (GTK_IS_MYFIXED(widget
));
310 g_return_if_fail (allocation
!= NULL
);
312 myfixed
= GTK_MYFIXED (widget
);
314 widget
->allocation
= *allocation
;
315 if (GTK_WIDGET_REALIZED (widget
))
316 gdk_window_move_resize (widget
->window
, allocation
->x
, allocation
->y
, 32000, 32000 );
318 border_width
= GTK_CONTAINER (myfixed
)->border_width
;
320 children
= myfixed
->children
;
323 child
= children
->data
;
324 children
= children
->next
;
326 if (GTK_WIDGET_VISIBLE (child
->widget
))
328 child_allocation
.x
= child
->x
+ border_width
;
329 child_allocation
.y
= child
->y
+ border_width
;
330 child_allocation
.width
= child
->widget
->requisition
.width
;
331 child_allocation
.height
= child
->widget
->requisition
.height
;
332 gtk_widget_size_allocate (child
->widget
, &child_allocation
);
338 gtk_myfixed_paint (GtkWidget
*widget
,
341 g_return_if_fail (widget
!= NULL
);
342 g_return_if_fail (GTK_IS_MYFIXED (widget
));
343 g_return_if_fail (area
!= NULL
);
345 if (GTK_WIDGET_DRAWABLE (widget
))
346 gdk_window_clear_area (widget
->window
,
348 area
->width
, area
->height
);
352 gtk_myfixed_draw (GtkWidget
*widget
,
356 GtkMyFixedChild
*child
;
357 GdkRectangle child_area
;
360 g_return_if_fail (widget
!= NULL
);
361 g_return_if_fail (GTK_IS_MYFIXED (widget
));
363 if (GTK_WIDGET_DRAWABLE (widget
))
365 myfixed
= GTK_MYFIXED (widget
);
366 gtk_myfixed_paint (widget
, area
);
368 children
= myfixed
->children
;
371 child
= children
->data
;
372 children
= children
->next
;
374 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
375 gtk_widget_draw (child
->widget
, &child_area
);
381 gtk_myfixed_expose (GtkWidget
*widget
,
382 GdkEventExpose
*event
)
385 GtkMyFixedChild
*child
;
386 GdkEventExpose child_event
;
389 g_return_val_if_fail (widget
!= NULL
, FALSE
);
390 g_return_val_if_fail (GTK_IS_MYFIXED (widget
), FALSE
);
391 g_return_val_if_fail (event
!= NULL
, FALSE
);
393 if (GTK_WIDGET_DRAWABLE (widget
))
395 myfixed
= GTK_MYFIXED (widget
);
397 child_event
= *event
;
399 children
= myfixed
->children
;
402 child
= children
->data
;
403 children
= children
->next
;
405 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
406 gtk_widget_intersect (child
->widget
, &event
->area
,
408 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
416 gtk_myfixed_add (GtkContainer
*container
,
419 g_return_if_fail (container
!= NULL
);
420 g_return_if_fail (GTK_IS_MYFIXED (container
));
421 g_return_if_fail (widget
!= NULL
);
423 gtk_myfixed_put (GTK_MYFIXED (container
), widget
, 0, 0);
427 gtk_myfixed_remove (GtkContainer
*container
,
431 GtkMyFixedChild
*child
;
434 g_return_if_fail (container
!= NULL
);
435 g_return_if_fail (GTK_IS_MYFIXED (container
));
436 g_return_if_fail (widget
!= NULL
);
438 myfixed
= GTK_MYFIXED (container
);
440 children
= myfixed
->children
;
443 child
= children
->data
;
445 if (child
->widget
== widget
)
447 gtk_widget_unparent (widget
);
449 myfixed
->children
= g_list_remove_link (myfixed
->children
, children
);
450 g_list_free (children
);
453 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (container
))
454 gtk_widget_queue_resize (GTK_WIDGET (container
));
459 children
= children
->next
;
464 gtk_myfixed_foreach (GtkContainer
*container
,
465 #if (GTK_MINOR_VERSION == 1)
466 gboolean include_internals
,
468 GtkCallback callback
,
469 gpointer callback_data
)
472 GtkMyFixedChild
*child
;
475 g_return_if_fail (container
!= NULL
);
476 g_return_if_fail (GTK_IS_MYFIXED (container
));
477 g_return_if_fail (callback
!= NULL
);
479 myfixed
= GTK_MYFIXED (container
);
481 children
= myfixed
->children
;
484 child
= children
->data
;
485 children
= children
->next
;
487 (* callback
) (child
->widget
, callback_data
);
494 #endif /* __cplusplus */