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"
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
,
38 gpointer callback_data
);
41 static GtkContainerClass
*parent_class
= NULL
;
45 gtk_myfixed_get_type ()
47 static guint myfixed_type
= 0;
51 GtkTypeInfo myfixed_info
=
55 sizeof (GtkMyFixedClass
),
56 (GtkClassInitFunc
) gtk_myfixed_class_init
,
57 (GtkObjectInitFunc
) gtk_myfixed_init
,
62 myfixed_type
= gtk_type_unique (gtk_container_get_type (), &myfixed_info
);
69 gtk_myfixed_class_init (GtkMyFixedClass
*klass
)
71 GtkObjectClass
*object_class
;
72 GtkWidgetClass
*widget_class
;
73 GtkContainerClass
*container_class
;
75 object_class
= (GtkObjectClass
*) klass
;
76 widget_class
= (GtkWidgetClass
*) klass
;
77 container_class
= (GtkContainerClass
*) klass
;
79 parent_class
= gtk_type_class (gtk_container_get_type ());
81 widget_class
->map
= gtk_myfixed_map
;
82 widget_class
->unmap
= gtk_myfixed_unmap
;
83 widget_class
->realize
= gtk_myfixed_realize
;
84 widget_class
->size_request
= gtk_myfixed_size_request
;
85 widget_class
->size_allocate
= gtk_myfixed_size_allocate
;
86 widget_class
->draw
= gtk_myfixed_draw
;
87 widget_class
->expose_event
= gtk_myfixed_expose
;
89 container_class
->add
= gtk_myfixed_add
;
90 container_class
->remove
= gtk_myfixed_remove
;
91 container_class
->foreach
= gtk_myfixed_foreach
;
95 gtk_myfixed_init (GtkMyFixed
*myfixed
)
97 GTK_WIDGET_UNSET_FLAGS (myfixed
, GTK_NO_WINDOW
);
98 GTK_WIDGET_SET_FLAGS (myfixed
, GTK_BASIC
);
100 myfixed
->children
= NULL
;
108 myfixed
= gtk_type_new (gtk_myfixed_get_type ());
110 return GTK_WIDGET (myfixed
);
114 gtk_myfixed_put (GtkMyFixed
*myfixed
,
119 GtkMyFixedChild
*child_info
;
121 g_return_if_fail (myfixed
!= NULL
);
122 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
123 g_return_if_fail (widget
!= NULL
);
125 child_info
= g_new (GtkMyFixedChild
, 1);
126 child_info
->widget
= widget
;
130 gtk_widget_set_parent (widget
, GTK_WIDGET (myfixed
));
132 myfixed
->children
= g_list_append (myfixed
->children
, child_info
);
134 if (GTK_WIDGET_REALIZED (myfixed
) && !GTK_WIDGET_REALIZED (widget
))
135 gtk_widget_realize (widget
);
137 if (GTK_WIDGET_MAPPED (myfixed
) && !GTK_WIDGET_MAPPED (widget
))
138 gtk_widget_map (widget
);
140 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (myfixed
))
141 gtk_widget_queue_resize (GTK_WIDGET (myfixed
));
145 gtk_myfixed_move (GtkMyFixed
*myfixed
,
150 GtkMyFixedChild
*child
;
153 g_return_if_fail (myfixed
!= NULL
);
154 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
155 g_return_if_fail (widget
!= NULL
);
157 children
= myfixed
->children
;
160 child
= children
->data
;
161 children
= children
->next
;
163 if (child
->widget
== widget
)
168 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (myfixed
))
169 gtk_widget_queue_resize (GTK_WIDGET (myfixed
));
177 gtk_myfixed_map (GtkWidget
*widget
)
180 GtkMyFixedChild
*child
;
183 g_return_if_fail (widget
!= NULL
);
184 g_return_if_fail (GTK_IS_MYFIXED (widget
));
186 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
187 myfixed
= GTK_MYFIXED (widget
);
189 gdk_window_show (widget
->window
);
191 children
= myfixed
->children
;
194 child
= children
->data
;
195 children
= children
->next
;
197 if (GTK_WIDGET_VISIBLE (child
->widget
) &&
198 !GTK_WIDGET_MAPPED (child
->widget
))
199 gtk_widget_map (child
->widget
);
204 gtk_myfixed_unmap (GtkWidget
*widget
)
206 g_return_if_fail (widget
!= NULL
);
207 g_return_if_fail (GTK_IS_MYFIXED (widget
));
209 GTK_WIDGET_UNSET_FLAGS (widget
, GTK_MAPPED
);
213 gtk_myfixed_realize (GtkWidget
*widget
)
216 GdkWindowAttr attributes
;
217 gint attributes_mask
;
219 g_return_if_fail (widget
!= NULL
);
220 g_return_if_fail (GTK_IS_MYFIXED (widget
));
222 myfixed
= GTK_MYFIXED (widget
);
224 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
226 attributes
.window_type
= GDK_WINDOW_CHILD
;
227 attributes
.x
= widget
->allocation
.x
;
228 attributes
.y
= widget
->allocation
.y
;
229 attributes
.width
= 32000;
230 attributes
.height
= 32000;
231 attributes
.wclass
= GDK_INPUT_OUTPUT
;
232 attributes
.visual
= gtk_widget_get_visual (widget
);
233 attributes
.colormap
= gtk_widget_get_colormap (widget
);
234 attributes
.event_mask
= gtk_widget_get_events (widget
);
235 attributes
.event_mask
|=
237 GDK_POINTER_MOTION_MASK
|
238 GDK_BUTTON_MOTION_MASK
|
239 GDK_BUTTON1_MOTION_MASK
|
240 GDK_BUTTON2_MOTION_MASK
|
241 GDK_BUTTON3_MOTION_MASK
|
242 GDK_BUTTON_PRESS_MASK
|
243 GDK_BUTTON_RELEASE_MASK
|
245 GDK_KEY_RELEASE_MASK
|
246 GDK_ENTER_NOTIFY_MASK
|
247 GDK_LEAVE_NOTIFY_MASK
|
248 GDK_FOCUS_CHANGE_MASK
;
250 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
252 widget
->window
= gdk_window_new (gtk_widget_get_parent_window (widget
), &attributes
,
254 gdk_window_set_user_data (widget
->window
, widget
);
256 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
257 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
261 gtk_myfixed_size_request (GtkWidget
*widget
,
262 GtkRequisition
*requisition
)
265 GtkMyFixedChild
*child
;
268 g_return_if_fail (widget
!= NULL
);
269 g_return_if_fail (GTK_IS_MYFIXED (widget
));
270 g_return_if_fail (requisition
!= NULL
);
272 myfixed
= GTK_MYFIXED (widget
);
274 requisition
->width
= 0;
275 requisition
->height
= 0;
277 children
= myfixed
->children
;
280 child
= children
->data
;
281 children
= children
->next
;
283 if (GTK_WIDGET_VISIBLE (child
->widget
))
285 gtk_widget_size_request (child
->widget
, &child
->widget
->requisition
);
291 gtk_myfixed_size_allocate (GtkWidget
*widget
,
292 GtkAllocation
*allocation
)
295 GtkMyFixedChild
*child
;
296 GtkAllocation child_allocation
;
298 guint16 border_width
;
300 g_return_if_fail (widget
!= NULL
);
301 g_return_if_fail (GTK_IS_MYFIXED(widget
));
302 g_return_if_fail (allocation
!= NULL
);
304 myfixed
= GTK_MYFIXED (widget
);
306 widget
->allocation
= *allocation
;
307 if (GTK_WIDGET_REALIZED (widget
))
308 gdk_window_move_resize (widget
->window
, allocation
->x
, allocation
->y
, 32000, 32000 );
310 border_width
= GTK_CONTAINER (myfixed
)->border_width
;
312 children
= myfixed
->children
;
315 child
= children
->data
;
316 children
= children
->next
;
318 if (GTK_WIDGET_VISIBLE (child
->widget
))
320 child_allocation
.x
= child
->x
+ border_width
;
321 child_allocation
.y
= child
->y
+ border_width
;
322 child_allocation
.width
= child
->widget
->requisition
.width
;
323 child_allocation
.height
= child
->widget
->requisition
.height
;
324 gtk_widget_size_allocate (child
->widget
, &child_allocation
);
330 gtk_myfixed_paint (GtkWidget
*widget
,
333 g_return_if_fail (widget
!= NULL
);
334 g_return_if_fail (GTK_IS_MYFIXED (widget
));
335 g_return_if_fail (area
!= NULL
);
337 if (GTK_WIDGET_DRAWABLE (widget
))
338 gdk_window_clear_area (widget
->window
,
340 area
->width
, area
->height
);
344 gtk_myfixed_draw (GtkWidget
*widget
,
348 GtkMyFixedChild
*child
;
349 GdkRectangle child_area
;
352 g_return_if_fail (widget
!= NULL
);
353 g_return_if_fail (GTK_IS_MYFIXED (widget
));
355 if (GTK_WIDGET_DRAWABLE (widget
))
357 myfixed
= GTK_MYFIXED (widget
);
358 gtk_myfixed_paint (widget
, area
);
360 children
= myfixed
->children
;
363 child
= children
->data
;
364 children
= children
->next
;
366 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
367 gtk_widget_draw (child
->widget
, &child_area
);
373 gtk_myfixed_expose (GtkWidget
*widget
,
374 GdkEventExpose
*event
)
377 GtkMyFixedChild
*child
;
378 GdkEventExpose child_event
;
381 g_return_val_if_fail (widget
!= NULL
, FALSE
);
382 g_return_val_if_fail (GTK_IS_MYFIXED (widget
), FALSE
);
383 g_return_val_if_fail (event
!= NULL
, FALSE
);
385 if (GTK_WIDGET_DRAWABLE (widget
))
387 myfixed
= GTK_MYFIXED (widget
);
389 child_event
= *event
;
391 children
= myfixed
->children
;
394 child
= children
->data
;
395 children
= children
->next
;
397 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
398 gtk_widget_intersect (child
->widget
, &event
->area
,
400 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
408 gtk_myfixed_add (GtkContainer
*container
,
411 g_return_if_fail (container
!= NULL
);
412 g_return_if_fail (GTK_IS_MYFIXED (container
));
413 g_return_if_fail (widget
!= NULL
);
415 gtk_myfixed_put (GTK_MYFIXED (container
), widget
, 0, 0);
419 gtk_myfixed_remove (GtkContainer
*container
,
423 GtkMyFixedChild
*child
;
426 g_return_if_fail (container
!= NULL
);
427 g_return_if_fail (GTK_IS_MYFIXED (container
));
428 g_return_if_fail (widget
!= NULL
);
430 myfixed
= GTK_MYFIXED (container
);
432 children
= myfixed
->children
;
435 child
= children
->data
;
437 if (child
->widget
== widget
)
439 gtk_widget_unparent (widget
);
441 myfixed
->children
= g_list_remove_link (myfixed
->children
, children
);
442 g_list_free (children
);
445 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (container
))
446 gtk_widget_queue_resize (GTK_WIDGET (container
));
451 children
= children
->next
;
456 gtk_myfixed_foreach (GtkContainer
*container
,
457 GtkCallback callback
,
458 gpointer callback_data
)
461 GtkMyFixedChild
*child
;
464 g_return_if_fail (container
!= NULL
);
465 g_return_if_fail (GTK_IS_MYFIXED (container
));
466 g_return_if_fail (callback
!= NULL
);
468 myfixed
= GTK_MYFIXED (container
);
470 children
= myfixed
->children
;
473 child
= children
->data
;
474 children
= children
->next
;
476 (* callback
) (child
->widget
, callback_data
);
483 #endif /* __cplusplus */