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>
15 #endif /* __cplusplus */
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
,
28 static void gtk_myfixed_draw (GtkWidget
*widget
,
30 static gint
gtk_myfixed_expose (GtkWidget
*widget
,
31 GdkEventExpose
*event
);
32 static void gtk_myfixed_add (GtkContainer
*container
,
34 static void gtk_myfixed_remove (GtkContainer
*container
,
36 static void gtk_myfixed_foreach (GtkContainer
*container
,
37 #if (GTK_MINOR_VERSION == 1)
38 gboolean include_internals
,
41 gpointer callback_data
);
44 static GtkContainerClass
*parent_class
= NULL
;
48 gtk_myfixed_get_type ()
50 static guint myfixed_type
= 0;
54 GtkTypeInfo myfixed_info
=
58 sizeof (GtkMyFixedClass
),
59 (GtkClassInitFunc
) gtk_myfixed_class_init
,
60 (GtkObjectInitFunc
) gtk_myfixed_init
,
65 myfixed_type
= gtk_type_unique (gtk_container_get_type (), &myfixed_info
);
72 gtk_myfixed_class_init (GtkMyFixedClass
*klass
)
74 GtkObjectClass
*object_class
;
75 GtkWidgetClass
*widget_class
;
76 GtkContainerClass
*container_class
;
78 object_class
= (GtkObjectClass
*) klass
;
79 widget_class
= (GtkWidgetClass
*) klass
;
80 container_class
= (GtkContainerClass
*) klass
;
82 parent_class
= gtk_type_class (gtk_container_get_type ());
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
;
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
;
97 container_class
->foreach
= gtk_myfixed_foreach
;
102 gtk_myfixed_init (GtkMyFixed
*myfixed
)
104 GTK_WIDGET_UNSET_FLAGS (myfixed
, GTK_NO_WINDOW
);
105 GTK_WIDGET_SET_FLAGS (myfixed
, GTK_BASIC
);
107 #if (GTK_MINOR_VERSION == 1)
108 gtk_container_set_resize_mode( GTK_CONTAINER(myfixed
), GTK_RESIZE_PARENT
);
111 myfixed
->children
= NULL
;
119 myfixed
= gtk_type_new (gtk_myfixed_get_type ());
121 return GTK_WIDGET (myfixed
);
125 gtk_myfixed_put (GtkMyFixed
*myfixed
,
130 GtkMyFixedChild
*child_info
;
132 g_return_if_fail (myfixed
!= NULL
);
133 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
134 g_return_if_fail (widget
!= NULL
);
136 child_info
= g_new (GtkMyFixedChild
, 1);
137 child_info
->widget
= widget
;
141 gtk_widget_set_parent (widget
, GTK_WIDGET (myfixed
));
143 myfixed
->children
= g_list_append (myfixed
->children
, child_info
);
145 if (GTK_WIDGET_REALIZED (myfixed
) && !GTK_WIDGET_REALIZED (widget
))
146 gtk_widget_realize (widget
);
148 if (GTK_WIDGET_MAPPED (myfixed
) && !GTK_WIDGET_MAPPED (widget
))
149 gtk_widget_map (widget
);
151 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (myfixed
))
152 gtk_widget_queue_resize (GTK_WIDGET (myfixed
));
156 gtk_myfixed_move (GtkMyFixed
*myfixed
,
161 GtkMyFixedChild
*child
;
164 g_return_if_fail (myfixed
!= NULL
);
165 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
166 g_return_if_fail (widget
!= NULL
);
168 children
= myfixed
->children
;
171 child
= children
->data
;
172 children
= children
->next
;
174 if (child
->widget
== widget
)
176 if ((child
->x
== x
) && (child
->y
== y
)) return;
181 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (myfixed
))
182 gtk_widget_queue_resize (GTK_WIDGET (myfixed
));
190 gtk_myfixed_map (GtkWidget
*widget
)
193 GtkMyFixedChild
*child
;
196 g_return_if_fail (widget
!= NULL
);
197 g_return_if_fail (GTK_IS_MYFIXED (widget
));
199 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
200 myfixed
= GTK_MYFIXED (widget
);
202 gdk_window_show (widget
->window
);
204 children
= myfixed
->children
;
207 child
= children
->data
;
208 children
= children
->next
;
210 if (GTK_WIDGET_VISIBLE (child
->widget
) &&
211 !GTK_WIDGET_MAPPED (child
->widget
))
212 gtk_widget_map (child
->widget
);
217 gtk_myfixed_unmap (GtkWidget
*widget
)
219 g_return_if_fail (widget
!= NULL
);
220 g_return_if_fail (GTK_IS_MYFIXED (widget
));
222 GTK_WIDGET_UNSET_FLAGS (widget
, GTK_MAPPED
);
226 gtk_myfixed_realize (GtkWidget
*widget
)
229 GdkWindowAttr attributes
;
230 gint attributes_mask
;
232 g_return_if_fail (widget
!= NULL
);
233 g_return_if_fail (GTK_IS_MYFIXED (widget
));
235 myfixed
= GTK_MYFIXED (widget
);
237 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
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
|=
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
|
258 GDK_KEY_RELEASE_MASK
|
259 GDK_ENTER_NOTIFY_MASK
|
260 GDK_LEAVE_NOTIFY_MASK
|
261 GDK_FOCUS_CHANGE_MASK
;
263 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
265 widget
->window
= gdk_window_new (gtk_widget_get_parent_window (widget
), &attributes
,
267 gdk_window_set_user_data (widget
->window
, widget
);
269 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
270 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
274 gtk_myfixed_size_request (GtkWidget
*widget
,
275 GtkRequisition
*requisition
)
278 GtkMyFixedChild
*child
;
281 g_return_if_fail (widget
!= NULL
);
282 g_return_if_fail (GTK_IS_MYFIXED (widget
));
283 g_return_if_fail (requisition
!= NULL
);
285 myfixed
= GTK_MYFIXED (widget
);
287 requisition
->width
= 0;
288 requisition
->height
= 0;
290 children
= myfixed
->children
;
293 child
= children
->data
;
294 children
= children
->next
;
296 if (GTK_WIDGET_VISIBLE (child
->widget
))
298 gtk_widget_size_request (child
->widget
, &child
->widget
->requisition
);
304 gtk_myfixed_size_allocate (GtkWidget
*widget
,
305 GtkAllocation
*allocation
)
308 GtkMyFixedChild
*child
;
309 GtkAllocation child_allocation
;
311 guint16 border_width
;
313 g_return_if_fail (widget
!= NULL
);
314 g_return_if_fail (GTK_IS_MYFIXED(widget
));
315 g_return_if_fail (allocation
!= NULL
);
317 myfixed
= GTK_MYFIXED (widget
);
319 widget
->allocation
= *allocation
;
320 if (GTK_WIDGET_REALIZED (widget
))
321 gdk_window_move_resize (widget
->window
, allocation
->x
, allocation
->y
, 32000, 32000 );
323 border_width
= GTK_CONTAINER (myfixed
)->border_width
;
325 children
= myfixed
->children
;
328 child
= children
->data
;
329 children
= children
->next
;
331 if (GTK_WIDGET_VISIBLE (child
->widget
))
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
);
343 gtk_myfixed_paint (GtkWidget
*widget
,
346 g_return_if_fail (widget
!= NULL
);
347 g_return_if_fail (GTK_IS_MYFIXED (widget
));
348 g_return_if_fail (area
!= NULL
);
350 if (GTK_WIDGET_DRAWABLE (widget
))
351 gdk_window_clear_area (widget
->window
,
353 area
->width
, area
->height
);
357 gtk_myfixed_draw (GtkWidget
*widget
,
361 GtkMyFixedChild
*child
;
362 GdkRectangle child_area
;
365 g_return_if_fail (widget
!= NULL
);
366 g_return_if_fail (GTK_IS_MYFIXED (widget
));
368 if (GTK_WIDGET_DRAWABLE (widget
))
370 myfixed
= GTK_MYFIXED (widget
);
371 gtk_myfixed_paint (widget
, area
);
373 children
= myfixed
->children
;
376 child
= children
->data
;
377 children
= children
->next
;
379 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
380 gtk_widget_draw (child
->widget
, &child_area
);
386 gtk_myfixed_expose (GtkWidget
*widget
,
387 GdkEventExpose
*event
)
390 GtkMyFixedChild
*child
;
391 GdkEventExpose child_event
;
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
);
398 if (GTK_WIDGET_DRAWABLE (widget
))
400 myfixed
= GTK_MYFIXED (widget
);
402 child_event
= *event
;
404 children
= myfixed
->children
;
407 child
= children
->data
;
408 children
= children
->next
;
410 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
411 gtk_widget_intersect (child
->widget
, &event
->area
,
413 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
421 gtk_myfixed_add (GtkContainer
*container
,
424 g_return_if_fail (container
!= NULL
);
425 g_return_if_fail (GTK_IS_MYFIXED (container
));
426 g_return_if_fail (widget
!= NULL
);
428 gtk_myfixed_put (GTK_MYFIXED (container
), widget
, 0, 0);
432 gtk_myfixed_remove (GtkContainer
*container
,
436 GtkMyFixedChild
*child
;
439 g_return_if_fail (container
!= NULL
);
440 g_return_if_fail (GTK_IS_MYFIXED (container
));
441 g_return_if_fail (widget
!= NULL
);
443 myfixed
= GTK_MYFIXED (container
);
445 children
= myfixed
->children
;
448 child
= children
->data
;
450 if (child
->widget
== widget
)
452 gtk_widget_unparent (widget
);
454 myfixed
->children
= g_list_remove_link (myfixed
->children
, children
);
455 g_list_free (children
);
458 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (container
))
459 gtk_widget_queue_resize (GTK_WIDGET (container
));
464 children
= children
->next
;
469 gtk_myfixed_foreach (GtkContainer
*container
,
470 #if (GTK_MINOR_VERSION == 1)
471 gboolean include_internals
,
473 GtkCallback callback
,
474 gpointer callback_data
)
477 GtkMyFixedChild
*child
;
480 g_return_if_fail (container
!= NULL
);
481 g_return_if_fail (GTK_IS_MYFIXED (container
));
482 g_return_if_fail (callback
!= NULL
);
484 myfixed
= GTK_MYFIXED (container
);
486 children
= myfixed
->children
;
489 child
= children
->data
;
490 children
= children
->next
;
492 (* callback
) (child
->widget
, callback_data
);
499 #endif /* __cplusplus */