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
;
153 child_info
->x
= x
- myfixed
->scroll_offset_x
;
154 child_info
->y
= y
- myfixed
->scroll_offset_y
;
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
)
191 child
->x
= x
- myfixed
->scroll_offset_x
;
192 child
->y
= y
- myfixed
->scroll_offset_y
;
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
)
242 GdkWindowAttr attributes
;
243 gint attributes_mask
;
245 g_return_if_fail (widget
!= NULL
);
246 g_return_if_fail (GTK_IS_MYFIXED (widget
));
248 myfixed
= GTK_MYFIXED (widget
);
250 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
252 attributes
.window_type
= GDK_WINDOW_CHILD
;
253 attributes
.x
= widget
->allocation
.x
+ myfixed
->scroll_offset_x
;
254 attributes
.y
= widget
->allocation
.y
+ myfixed
->scroll_offset_x
;
255 attributes
.width
= 32000;
256 attributes
.height
= 32000;
257 attributes
.wclass
= GDK_INPUT_OUTPUT
;
258 attributes
.visual
= gtk_widget_get_visual (widget
);
259 attributes
.colormap
= gtk_widget_get_colormap (widget
);
260 attributes
.event_mask
= gtk_widget_get_events (widget
);
261 attributes
.event_mask
|=
263 GDK_POINTER_MOTION_MASK
|
264 GDK_BUTTON_MOTION_MASK
|
265 GDK_BUTTON1_MOTION_MASK
|
266 GDK_BUTTON2_MOTION_MASK
|
267 GDK_BUTTON3_MOTION_MASK
|
268 GDK_BUTTON_PRESS_MASK
|
269 GDK_BUTTON_RELEASE_MASK
|
271 GDK_KEY_RELEASE_MASK
|
272 GDK_ENTER_NOTIFY_MASK
|
273 GDK_LEAVE_NOTIFY_MASK
|
274 GDK_FOCUS_CHANGE_MASK
;
276 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
278 widget
->window
= gdk_window_new (gtk_widget_get_parent_window (widget
), &attributes
,
280 gdk_window_set_user_data (widget
->window
, widget
);
282 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
283 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
287 gtk_myfixed_size_request (GtkWidget
*widget
,
288 GtkRequisition
*requisition
)
291 GtkMyFixedChild
*child
;
294 g_return_if_fail (widget
!= NULL
);
295 g_return_if_fail (GTK_IS_MYFIXED (widget
));
296 g_return_if_fail (requisition
!= NULL
);
298 myfixed
= GTK_MYFIXED (widget
);
300 requisition
->width
= 0;
301 requisition
->height
= 0;
303 children
= myfixed
->children
;
306 child
= children
->data
;
307 children
= children
->next
;
309 if (GTK_WIDGET_VISIBLE (child
->widget
))
311 gtk_widget_size_request (child
->widget
, &child
->widget
->requisition
);
317 gtk_myfixed_size_allocate (GtkWidget
*widget
,
318 GtkAllocation
*allocation
)
321 GtkMyFixedChild
*child
;
322 GtkAllocation child_allocation
;
324 guint16 border_width
;
326 g_return_if_fail (widget
!= NULL
);
327 g_return_if_fail (GTK_IS_MYFIXED(widget
));
328 g_return_if_fail (allocation
!= NULL
);
330 myfixed
= GTK_MYFIXED (widget
);
332 widget
->allocation
= *allocation
;
333 if (GTK_WIDGET_REALIZED (widget
))
334 gdk_window_move_resize (widget
->window
,
335 allocation
->x
+ myfixed
->scroll_offset_x
,
336 allocation
->y
+ myfixed
->scroll_offset_y
,
341 border_width
= GTK_CONTAINER (myfixed
)->border_width
;
343 children
= myfixed
->children
;
346 child
= children
->data
;
347 children
= children
->next
;
349 if (GTK_WIDGET_VISIBLE (child
->widget
))
351 child_allocation
.x
= child
->x
+ border_width
;
352 child_allocation
.y
= child
->y
+ border_width
;
353 child_allocation
.width
= child
->widget
->requisition
.width
;
354 child_allocation
.height
= child
->widget
->requisition
.height
;
355 gtk_widget_size_allocate (child
->widget
, &child_allocation
);
361 gtk_myfixed_paint (GtkWidget
*widget
,
364 g_return_if_fail (widget
!= NULL
);
365 g_return_if_fail (GTK_IS_MYFIXED (widget
));
366 g_return_if_fail (area
!= NULL
);
368 if (GTK_WIDGET_DRAWABLE (widget
))
369 gdk_window_clear_area (widget
->window
,
371 area
->width
, area
->height
);
375 gtk_myfixed_draw (GtkWidget
*widget
,
379 GtkMyFixedChild
*child
;
380 GdkRectangle child_area
;
383 g_return_if_fail (widget
!= NULL
);
384 g_return_if_fail (GTK_IS_MYFIXED (widget
));
386 if (GTK_WIDGET_DRAWABLE (widget
))
388 myfixed
= GTK_MYFIXED (widget
);
389 gtk_myfixed_paint (widget
, area
);
391 children
= myfixed
->children
;
394 child
= children
->data
;
395 children
= children
->next
;
397 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
398 gtk_widget_draw (child
->widget
, &child_area
);
404 gtk_myfixed_expose (GtkWidget
*widget
,
405 GdkEventExpose
*event
)
408 GtkMyFixedChild
*child
;
409 GdkEventExpose child_event
;
412 g_return_val_if_fail (widget
!= NULL
, FALSE
);
413 g_return_val_if_fail (GTK_IS_MYFIXED (widget
), FALSE
);
414 g_return_val_if_fail (event
!= NULL
, FALSE
);
416 if (GTK_WIDGET_DRAWABLE (widget
))
418 myfixed
= GTK_MYFIXED (widget
);
420 child_event
= *event
;
422 children
= myfixed
->children
;
425 child
= children
->data
;
426 children
= children
->next
;
428 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
429 gtk_widget_intersect (child
->widget
, &event
->area
,
431 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
439 gtk_myfixed_add (GtkContainer
*container
,
442 g_return_if_fail (container
!= NULL
);
443 g_return_if_fail (GTK_IS_MYFIXED (container
));
444 g_return_if_fail (widget
!= NULL
);
446 gtk_myfixed_put (GTK_MYFIXED (container
), widget
, 0, 0);
450 gtk_myfixed_remove (GtkContainer
*container
,
454 GtkMyFixedChild
*child
;
457 g_return_if_fail (container
!= NULL
);
458 g_return_if_fail (GTK_IS_MYFIXED (container
));
459 g_return_if_fail (widget
!= NULL
);
461 myfixed
= GTK_MYFIXED (container
);
463 children
= myfixed
->children
;
466 child
= children
->data
;
468 if (child
->widget
== widget
)
470 gtk_widget_unparent (widget
);
472 myfixed
->children
= g_list_remove_link (myfixed
->children
, children
);
473 g_list_free (children
);
476 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (container
))
477 gtk_widget_queue_resize (GTK_WIDGET (container
));
482 children
= children
->next
;
487 gtk_myfixed_foreach (GtkContainer
*container
,
488 GtkCallback callback
,
489 gpointer callback_data
)
492 GtkMyFixedChild
*child
;
495 g_return_if_fail (container
!= NULL
);
496 g_return_if_fail (GTK_IS_MYFIXED (container
));
497 g_return_if_fail (callback
!= NULL
);
499 myfixed
= GTK_MYFIXED (container
);
501 children
= myfixed
->children
;
504 child
= children
->data
;
505 children
= children
->next
;
507 (* callback
) (child
->widget
, callback_data
);
514 #endif /* __cplusplus */