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 myfixed
->scroll_offset_x
= 0;
111 myfixed
->scroll_offset_y
= 0;
113 return GTK_WIDGET (myfixed
);
117 gtk_myfixed_set_offset (GtkMyFixed
*myfixed
,
123 g_return_if_fail (myfixed
!= NULL
);
124 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
126 myfixed
->scroll_offset_x
= x
;
127 myfixed
->scroll_offset_y
= y
;
129 widget
= GTK_WIDGET( myfixed
);
131 if (GTK_WIDGET_REALIZED( GTK_WIDGET(myfixed
) ))
132 gdk_window_move_resize (widget
->window
,
133 widget
->allocation
.x
+ x
,
134 widget
->allocation
.y
+ y
,
140 gtk_myfixed_put (GtkMyFixed
*myfixed
,
145 GtkMyFixedChild
*child_info
;
147 g_return_if_fail (myfixed
!= NULL
);
148 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
149 g_return_if_fail (widget
!= NULL
);
151 child_info
= g_new (GtkMyFixedChild
, 1);
152 child_info
->widget
= widget
;
156 gtk_widget_set_parent (widget
, GTK_WIDGET (myfixed
));
158 myfixed
->children
= g_list_append (myfixed
->children
, child_info
);
160 if (GTK_WIDGET_REALIZED (myfixed
) && !GTK_WIDGET_REALIZED (widget
))
161 gtk_widget_realize (widget
);
163 if (GTK_WIDGET_MAPPED (myfixed
) && !GTK_WIDGET_MAPPED (widget
))
164 gtk_widget_map (widget
);
166 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (myfixed
))
167 gtk_widget_queue_resize (GTK_WIDGET (myfixed
));
171 gtk_myfixed_move (GtkMyFixed
*myfixed
,
176 GtkMyFixedChild
*child
;
179 g_return_if_fail (myfixed
!= NULL
);
180 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
181 g_return_if_fail (widget
!= NULL
);
183 children
= myfixed
->children
;
186 child
= children
->data
;
187 children
= children
->next
;
189 if (child
->widget
== widget
)
194 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (myfixed
))
195 gtk_widget_queue_resize (GTK_WIDGET (myfixed
));
203 gtk_myfixed_map (GtkWidget
*widget
)
206 GtkMyFixedChild
*child
;
209 g_return_if_fail (widget
!= NULL
);
210 g_return_if_fail (GTK_IS_MYFIXED (widget
));
212 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
213 myfixed
= GTK_MYFIXED (widget
);
215 gdk_window_show (widget
->window
);
217 children
= myfixed
->children
;
220 child
= children
->data
;
221 children
= children
->next
;
223 if (GTK_WIDGET_VISIBLE (child
->widget
) &&
224 !GTK_WIDGET_MAPPED (child
->widget
))
225 gtk_widget_map (child
->widget
);
230 gtk_myfixed_unmap (GtkWidget
*widget
)
232 g_return_if_fail (widget
!= NULL
);
233 g_return_if_fail (GTK_IS_MYFIXED (widget
));
235 GTK_WIDGET_UNSET_FLAGS (widget
, GTK_MAPPED
);
239 gtk_myfixed_realize (GtkWidget
*widget
)
241 GdkWindowAttr attributes
;
242 gint attributes_mask
;
244 g_return_if_fail (widget
!= NULL
);
245 g_return_if_fail (GTK_IS_MYFIXED (widget
));
247 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
249 attributes
.window_type
= GDK_WINDOW_CHILD
;
250 attributes
.x
= widget
->allocation
.x
;
251 attributes
.y
= widget
->allocation
.y
;
252 attributes
.width
= 32000;
253 attributes
.height
= 32000;
254 attributes
.wclass
= GDK_INPUT_OUTPUT
;
255 attributes
.visual
= gtk_widget_get_visual (widget
);
256 attributes
.colormap
= gtk_widget_get_colormap (widget
);
257 attributes
.event_mask
= gtk_widget_get_events (widget
);
258 attributes
.event_mask
|=
260 GDK_POINTER_MOTION_MASK
|
261 GDK_BUTTON_MOTION_MASK
|
262 GDK_BUTTON1_MOTION_MASK
|
263 GDK_BUTTON2_MOTION_MASK
|
264 GDK_BUTTON3_MOTION_MASK
|
265 GDK_BUTTON_PRESS_MASK
|
266 GDK_BUTTON_RELEASE_MASK
|
268 GDK_KEY_RELEASE_MASK
|
269 GDK_ENTER_NOTIFY_MASK
|
270 GDK_LEAVE_NOTIFY_MASK
|
271 GDK_FOCUS_CHANGE_MASK
;
273 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
275 widget
->window
= gdk_window_new (gtk_widget_get_parent_window (widget
), &attributes
,
277 gdk_window_set_user_data (widget
->window
, widget
);
279 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
280 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
284 gtk_myfixed_size_request (GtkWidget
*widget
,
285 GtkRequisition
*requisition
)
288 GtkMyFixedChild
*child
;
291 g_return_if_fail (widget
!= NULL
);
292 g_return_if_fail (GTK_IS_MYFIXED (widget
));
293 g_return_if_fail (requisition
!= NULL
);
295 myfixed
= GTK_MYFIXED (widget
);
297 requisition
->width
= 0;
298 requisition
->height
= 0;
300 children
= myfixed
->children
;
303 child
= children
->data
;
304 children
= children
->next
;
306 if (GTK_WIDGET_VISIBLE (child
->widget
))
308 gtk_widget_size_request (child
->widget
, &child
->widget
->requisition
);
314 gtk_myfixed_size_allocate (GtkWidget
*widget
,
315 GtkAllocation
*allocation
)
318 GtkMyFixedChild
*child
;
319 GtkAllocation child_allocation
;
321 guint16 border_width
;
323 g_return_if_fail (widget
!= NULL
);
324 g_return_if_fail (GTK_IS_MYFIXED(widget
));
325 g_return_if_fail (allocation
!= NULL
);
327 myfixed
= GTK_MYFIXED (widget
);
329 widget
->allocation
= *allocation
;
330 if (GTK_WIDGET_REALIZED (widget
))
331 gdk_window_move_resize (widget
->window
,
332 allocation
->x
+ myfixed
->scroll_offset_x
,
333 allocation
->y
+ myfixed
->scroll_offset_y
,
338 border_width
= GTK_CONTAINER (myfixed
)->border_width
;
340 children
= myfixed
->children
;
343 child
= children
->data
;
344 children
= children
->next
;
346 if (GTK_WIDGET_VISIBLE (child
->widget
))
348 child_allocation
.x
= child
->x
+ border_width
;
349 child_allocation
.y
= child
->y
+ border_width
;
350 child_allocation
.width
= child
->widget
->requisition
.width
;
351 child_allocation
.height
= child
->widget
->requisition
.height
;
352 gtk_widget_size_allocate (child
->widget
, &child_allocation
);
358 gtk_myfixed_paint (GtkWidget
*widget
,
361 g_return_if_fail (widget
!= NULL
);
362 g_return_if_fail (GTK_IS_MYFIXED (widget
));
363 g_return_if_fail (area
!= NULL
);
365 if (GTK_WIDGET_DRAWABLE (widget
))
366 gdk_window_clear_area (widget
->window
,
368 area
->width
, area
->height
);
372 gtk_myfixed_draw (GtkWidget
*widget
,
376 GtkMyFixedChild
*child
;
377 GdkRectangle child_area
;
380 g_return_if_fail (widget
!= NULL
);
381 g_return_if_fail (GTK_IS_MYFIXED (widget
));
383 if (GTK_WIDGET_DRAWABLE (widget
))
385 myfixed
= GTK_MYFIXED (widget
);
386 gtk_myfixed_paint (widget
, area
);
388 children
= myfixed
->children
;
391 child
= children
->data
;
392 children
= children
->next
;
394 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
395 gtk_widget_draw (child
->widget
, &child_area
);
401 gtk_myfixed_expose (GtkWidget
*widget
,
402 GdkEventExpose
*event
)
405 GtkMyFixedChild
*child
;
406 GdkEventExpose child_event
;
409 g_return_val_if_fail (widget
!= NULL
, FALSE
);
410 g_return_val_if_fail (GTK_IS_MYFIXED (widget
), FALSE
);
411 g_return_val_if_fail (event
!= NULL
, FALSE
);
413 if (GTK_WIDGET_DRAWABLE (widget
))
415 myfixed
= GTK_MYFIXED (widget
);
417 child_event
= *event
;
419 children
= myfixed
->children
;
422 child
= children
->data
;
423 children
= children
->next
;
425 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
426 gtk_widget_intersect (child
->widget
, &event
->area
,
428 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
436 gtk_myfixed_add (GtkContainer
*container
,
439 g_return_if_fail (container
!= NULL
);
440 g_return_if_fail (GTK_IS_MYFIXED (container
));
441 g_return_if_fail (widget
!= NULL
);
443 gtk_myfixed_put (GTK_MYFIXED (container
), widget
, 0, 0);
447 gtk_myfixed_remove (GtkContainer
*container
,
451 GtkMyFixedChild
*child
;
454 g_return_if_fail (container
!= NULL
);
455 g_return_if_fail (GTK_IS_MYFIXED (container
));
456 g_return_if_fail (widget
!= NULL
);
458 myfixed
= GTK_MYFIXED (container
);
460 children
= myfixed
->children
;
463 child
= children
->data
;
465 if (child
->widget
== widget
)
467 gtk_widget_unparent (widget
);
469 myfixed
->children
= g_list_remove_link (myfixed
->children
, children
);
470 g_list_free (children
);
473 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (container
))
474 gtk_widget_queue_resize (GTK_WIDGET (container
));
479 children
= children
->next
;
484 gtk_myfixed_foreach (GtkContainer
*container
,
485 GtkCallback callback
,
486 gpointer callback_data
)
489 GtkMyFixedChild
*child
;
492 g_return_if_fail (container
!= NULL
);
493 g_return_if_fail (GTK_IS_MYFIXED (container
));
494 g_return_if_fail (callback
!= NULL
);
496 myfixed
= GTK_MYFIXED (container
);
498 children
= myfixed
->children
;
501 child
= children
->data
;
502 children
= children
->next
;
504 (* callback
) (child
->widget
, callback_data
);
511 #endif /* __cplusplus */