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 myfixed
->children
= NULL
;
115 myfixed
= gtk_type_new (gtk_myfixed_get_type ());
117 return GTK_WIDGET (myfixed
);
121 gtk_myfixed_put (GtkMyFixed
*myfixed
,
126 GtkMyFixedChild
*child_info
;
128 g_return_if_fail (myfixed
!= NULL
);
129 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
130 g_return_if_fail (widget
!= NULL
);
132 child_info
= g_new (GtkMyFixedChild
, 1);
133 child_info
->widget
= widget
;
137 gtk_widget_set_parent (widget
, GTK_WIDGET (myfixed
));
139 myfixed
->children
= g_list_append (myfixed
->children
, child_info
);
141 if (GTK_WIDGET_REALIZED (myfixed
) && !GTK_WIDGET_REALIZED (widget
))
142 gtk_widget_realize (widget
);
144 if (GTK_WIDGET_MAPPED (myfixed
) && !GTK_WIDGET_MAPPED (widget
))
145 gtk_widget_map (widget
);
147 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (myfixed
))
148 gtk_widget_queue_resize (GTK_WIDGET (myfixed
));
152 gtk_myfixed_move (GtkMyFixed
*myfixed
,
157 GtkMyFixedChild
*child
;
160 g_return_if_fail (myfixed
!= NULL
);
161 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
162 g_return_if_fail (widget
!= NULL
);
164 children
= myfixed
->children
;
167 child
= children
->data
;
168 children
= children
->next
;
170 if (child
->widget
== widget
)
175 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (myfixed
))
176 gtk_widget_queue_resize (GTK_WIDGET (myfixed
));
184 gtk_myfixed_map (GtkWidget
*widget
)
187 GtkMyFixedChild
*child
;
190 g_return_if_fail (widget
!= NULL
);
191 g_return_if_fail (GTK_IS_MYFIXED (widget
));
193 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
194 myfixed
= GTK_MYFIXED (widget
);
196 gdk_window_show (widget
->window
);
198 children
= myfixed
->children
;
201 child
= children
->data
;
202 children
= children
->next
;
204 if (GTK_WIDGET_VISIBLE (child
->widget
) &&
205 !GTK_WIDGET_MAPPED (child
->widget
))
206 gtk_widget_map (child
->widget
);
211 gtk_myfixed_unmap (GtkWidget
*widget
)
213 g_return_if_fail (widget
!= NULL
);
214 g_return_if_fail (GTK_IS_MYFIXED (widget
));
216 GTK_WIDGET_UNSET_FLAGS (widget
, GTK_MAPPED
);
220 gtk_myfixed_realize (GtkWidget
*widget
)
223 GdkWindowAttr attributes
;
224 gint attributes_mask
;
226 g_return_if_fail (widget
!= NULL
);
227 g_return_if_fail (GTK_IS_MYFIXED (widget
));
229 myfixed
= GTK_MYFIXED (widget
);
231 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
233 attributes
.window_type
= GDK_WINDOW_CHILD
;
234 attributes
.x
= widget
->allocation
.x
;
235 attributes
.y
= widget
->allocation
.y
;
236 attributes
.width
= 32000;
237 attributes
.height
= 32000;
238 attributes
.wclass
= GDK_INPUT_OUTPUT
;
239 attributes
.visual
= gtk_widget_get_visual (widget
);
240 attributes
.colormap
= gtk_widget_get_colormap (widget
);
241 attributes
.event_mask
= gtk_widget_get_events (widget
);
242 attributes
.event_mask
|=
244 GDK_POINTER_MOTION_MASK
|
245 GDK_BUTTON_MOTION_MASK
|
246 GDK_BUTTON1_MOTION_MASK
|
247 GDK_BUTTON2_MOTION_MASK
|
248 GDK_BUTTON3_MOTION_MASK
|
249 GDK_BUTTON_PRESS_MASK
|
250 GDK_BUTTON_RELEASE_MASK
|
252 GDK_KEY_RELEASE_MASK
|
253 GDK_ENTER_NOTIFY_MASK
|
254 GDK_LEAVE_NOTIFY_MASK
|
255 GDK_FOCUS_CHANGE_MASK
;
257 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
259 widget
->window
= gdk_window_new (gtk_widget_get_parent_window (widget
), &attributes
,
261 gdk_window_set_user_data (widget
->window
, widget
);
263 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
264 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
268 gtk_myfixed_size_request (GtkWidget
*widget
,
269 GtkRequisition
*requisition
)
272 GtkMyFixedChild
*child
;
275 g_return_if_fail (widget
!= NULL
);
276 g_return_if_fail (GTK_IS_MYFIXED (widget
));
277 g_return_if_fail (requisition
!= NULL
);
279 myfixed
= GTK_MYFIXED (widget
);
281 requisition
->width
= 0;
282 requisition
->height
= 0;
284 children
= myfixed
->children
;
287 child
= children
->data
;
288 children
= children
->next
;
290 if (GTK_WIDGET_VISIBLE (child
->widget
))
292 gtk_widget_size_request (child
->widget
, &child
->widget
->requisition
);
298 gtk_myfixed_size_allocate (GtkWidget
*widget
,
299 GtkAllocation
*allocation
)
302 GtkMyFixedChild
*child
;
303 GtkAllocation child_allocation
;
305 guint16 border_width
;
307 g_return_if_fail (widget
!= NULL
);
308 g_return_if_fail (GTK_IS_MYFIXED(widget
));
309 g_return_if_fail (allocation
!= NULL
);
311 myfixed
= GTK_MYFIXED (widget
);
313 widget
->allocation
= *allocation
;
314 if (GTK_WIDGET_REALIZED (widget
))
315 gdk_window_move_resize (widget
->window
, allocation
->x
, allocation
->y
, 32000, 32000 );
317 border_width
= GTK_CONTAINER (myfixed
)->border_width
;
319 children
= myfixed
->children
;
322 child
= children
->data
;
323 children
= children
->next
;
325 if (GTK_WIDGET_VISIBLE (child
->widget
))
327 child_allocation
.x
= child
->x
+ border_width
;
328 child_allocation
.y
= child
->y
+ border_width
;
329 child_allocation
.width
= child
->widget
->requisition
.width
;
330 child_allocation
.height
= child
->widget
->requisition
.height
;
331 gtk_widget_size_allocate (child
->widget
, &child_allocation
);
337 gtk_myfixed_paint (GtkWidget
*widget
,
340 g_return_if_fail (widget
!= NULL
);
341 g_return_if_fail (GTK_IS_MYFIXED (widget
));
342 g_return_if_fail (area
!= NULL
);
344 if (GTK_WIDGET_DRAWABLE (widget
))
345 gdk_window_clear_area (widget
->window
,
347 area
->width
, area
->height
);
351 gtk_myfixed_draw (GtkWidget
*widget
,
355 GtkMyFixedChild
*child
;
356 GdkRectangle child_area
;
359 g_return_if_fail (widget
!= NULL
);
360 g_return_if_fail (GTK_IS_MYFIXED (widget
));
362 if (GTK_WIDGET_DRAWABLE (widget
))
364 myfixed
= GTK_MYFIXED (widget
);
365 gtk_myfixed_paint (widget
, area
);
367 children
= myfixed
->children
;
370 child
= children
->data
;
371 children
= children
->next
;
373 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
374 gtk_widget_draw (child
->widget
, &child_area
);
380 gtk_myfixed_expose (GtkWidget
*widget
,
381 GdkEventExpose
*event
)
384 GtkMyFixedChild
*child
;
385 GdkEventExpose child_event
;
388 g_return_val_if_fail (widget
!= NULL
, FALSE
);
389 g_return_val_if_fail (GTK_IS_MYFIXED (widget
), FALSE
);
390 g_return_val_if_fail (event
!= NULL
, FALSE
);
392 if (GTK_WIDGET_DRAWABLE (widget
))
394 myfixed
= GTK_MYFIXED (widget
);
396 child_event
= *event
;
398 children
= myfixed
->children
;
401 child
= children
->data
;
402 children
= children
->next
;
404 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
405 gtk_widget_intersect (child
->widget
, &event
->area
,
407 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
415 gtk_myfixed_add (GtkContainer
*container
,
418 g_return_if_fail (container
!= NULL
);
419 g_return_if_fail (GTK_IS_MYFIXED (container
));
420 g_return_if_fail (widget
!= NULL
);
422 gtk_myfixed_put (GTK_MYFIXED (container
), widget
, 0, 0);
426 gtk_myfixed_remove (GtkContainer
*container
,
430 GtkMyFixedChild
*child
;
433 g_return_if_fail (container
!= NULL
);
434 g_return_if_fail (GTK_IS_MYFIXED (container
));
435 g_return_if_fail (widget
!= NULL
);
437 myfixed
= GTK_MYFIXED (container
);
439 children
= myfixed
->children
;
442 child
= children
->data
;
444 if (child
->widget
== widget
)
446 gtk_widget_unparent (widget
);
448 myfixed
->children
= g_list_remove_link (myfixed
->children
, children
);
449 g_list_free (children
);
452 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (container
))
453 gtk_widget_queue_resize (GTK_WIDGET (container
));
458 children
= children
->next
;
463 gtk_myfixed_foreach (GtkContainer
*container
,
464 #if (GTK_MINOR_VERSION == 1)
465 gboolean include_internals
,
467 GtkCallback callback
,
468 gpointer callback_data
)
471 GtkMyFixedChild
*child
;
474 g_return_if_fail (container
!= NULL
);
475 g_return_if_fail (GTK_IS_MYFIXED (container
));
476 g_return_if_fail (callback
!= NULL
);
478 myfixed
= GTK_MYFIXED (container
);
480 children
= myfixed
->children
;
483 child
= children
->data
;
484 children
= children
->next
;
486 (* callback
) (child
->widget
, callback_data
);
493 #endif /* __cplusplus */