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/gtksignal.h"
12 #include "gtk/gtknotebook.h"
16 #endif /* __cplusplus */
18 static void gtk_myfixed_class_init (GtkMyFixedClass
*klass
);
19 static void gtk_myfixed_init (GtkMyFixed
*myfixed
);
20 static void gtk_myfixed_map (GtkWidget
*widget
);
21 #if (GTK_MINOR_VERSION == 0)
22 static void gtk_myfixed_unmap (GtkWidget
*widget
);
24 static void gtk_myfixed_realize (GtkWidget
*widget
);
25 static void gtk_myfixed_size_request (GtkWidget
*widget
,
26 GtkRequisition
*requisition
);
27 static void gtk_myfixed_size_allocate (GtkWidget
*widget
,
28 GtkAllocation
*allocation
);
29 static void gtk_myfixed_paint (GtkWidget
*widget
,
31 static void gtk_myfixed_draw (GtkWidget
*widget
,
33 static gint
gtk_myfixed_expose (GtkWidget
*widget
,
34 GdkEventExpose
*event
);
35 static void gtk_myfixed_add (GtkContainer
*container
,
37 static void gtk_myfixed_remove (GtkContainer
*container
,
39 static void gtk_myfixed_foreach (GtkContainer
*container
,
40 #if (GTK_MINOR_VERSION > 0)
41 gboolean include_internals
,
44 gpointer callback_data
);
45 #if (GTK_MINOR_VERSION > 0)
46 static GtkType
gtk_myfixed_child_type (GtkContainer
*container
);
49 #if (GTK_MINOR_VERSION > 0)
50 static void gtk_myfixed_scroll_set_adjustments (GtkMyFixed
*myfixed
,
57 static GtkContainerClass
*parent_class
= NULL
;
60 gtk_myfixed_get_type ()
62 static guint myfixed_type
= 0;
66 GtkTypeInfo myfixed_info
=
70 sizeof (GtkMyFixedClass
),
71 (GtkClassInitFunc
) gtk_myfixed_class_init
,
72 (GtkObjectInitFunc
) gtk_myfixed_init
,
73 #if (GTK_MINOR_VERSION > 0)
74 /* reserved_1 */ NULL
,
75 /* reserved_2 */ NULL
,
76 (GtkClassInitFunc
) NULL
,
83 myfixed_type
= gtk_type_unique (gtk_container_get_type (), &myfixed_info
);
90 gtk_myfixed_class_init (GtkMyFixedClass
*klass
)
92 GtkObjectClass
*object_class
;
93 GtkWidgetClass
*widget_class
;
94 GtkContainerClass
*container_class
;
96 object_class
= (GtkObjectClass
*) klass
;
97 widget_class
= (GtkWidgetClass
*) klass
;
98 container_class
= (GtkContainerClass
*) klass
;
100 #if (GTK_MINOR_VERSION > 0)
101 parent_class
= gtk_type_class (GTK_TYPE_CONTAINER
);
103 parent_class
= gtk_type_class (gtk_container_get_type ());
106 widget_class
->map
= gtk_myfixed_map
;
107 #if (GTK_MINOR_VERSION == 0)
108 widget_class
->unmap
= gtk_myfixed_unmap
;
110 widget_class
->realize
= gtk_myfixed_realize
;
111 widget_class
->size_request
= gtk_myfixed_size_request
;
112 widget_class
->size_allocate
= gtk_myfixed_size_allocate
;
113 widget_class
->draw
= gtk_myfixed_draw
;
114 widget_class
->expose_event
= gtk_myfixed_expose
;
116 container_class
->add
= gtk_myfixed_add
;
117 container_class
->remove
= gtk_myfixed_remove
;
118 #if (GTK_MINOR_VERSION > 0)
119 container_class
->forall
= gtk_myfixed_foreach
;
121 container_class
->foreach
= gtk_myfixed_foreach
;
124 #if (GTK_MINOR_VERSION > 0)
125 container_class
->child_type
= gtk_myfixed_child_type
;
128 #if (GTK_MINOR_VERSION > 0)
129 klass
->set_scroll_adjustments
= gtk_myfixed_scroll_set_adjustments
;
131 widget_class
->set_scroll_adjustments_signal
=
132 gtk_signal_new ("set_scroll_adjustments",
135 GTK_SIGNAL_OFFSET (GtkMyFixedClass
, set_scroll_adjustments
),
136 gtk_marshal_NONE__POINTER_POINTER
,
137 GTK_TYPE_NONE
, 2, GTK_TYPE_ADJUSTMENT
, GTK_TYPE_ADJUSTMENT
);
141 #if (GTK_MINOR_VERSION > 0)
143 gtk_myfixed_child_type (GtkContainer
*container
)
145 return GTK_TYPE_WIDGET
;
150 gtk_myfixed_init (GtkMyFixed
*myfixed
)
152 GTK_WIDGET_UNSET_FLAGS (myfixed
, GTK_NO_WINDOW
);
154 #if (GTK_MINOR_VERSION == 0)
155 GTK_WIDGET_SET_FLAGS (myfixed
, GTK_BASIC
);
158 #if (GTK_MINOR_VERSION > 0)
159 myfixed
->shadow_type
= GTK_SHADOW_NONE
;
162 myfixed
->children
= NULL
;
170 myfixed
= gtk_type_new (gtk_myfixed_get_type ());
172 return GTK_WIDGET (myfixed
);
175 #if (GTK_MINOR_VERSION > 0)
176 void gtk_myfixed_scroll_set_adjustments (GtkMyFixed
*myfixed
,
180 /* OK, this is embarassing, but this function has to be here */
184 gtk_myfixed_set_shadow_type (GtkMyFixed
*myfixed
,
187 g_return_if_fail (myfixed
!= NULL
);
188 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
190 if ((GtkShadowType
) myfixed
->shadow_type
!= type
)
192 myfixed
->shadow_type
= type
;
194 if (GTK_WIDGET_VISIBLE (myfixed
))
196 gtk_widget_size_allocate (GTK_WIDGET (myfixed
), &(GTK_WIDGET (myfixed
)->allocation
));
197 gtk_widget_queue_draw (GTK_WIDGET (myfixed
));
204 gtk_myfixed_put (GtkMyFixed
*myfixed
,
209 GtkMyFixedChild
*child_info
;
211 g_return_if_fail (myfixed
!= NULL
);
212 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
213 g_return_if_fail (widget
!= NULL
);
215 child_info
= g_new (GtkMyFixedChild
, 1);
216 child_info
->widget
= widget
;
220 gtk_widget_set_parent (widget
, GTK_WIDGET (myfixed
));
222 myfixed
->children
= g_list_append (myfixed
->children
, child_info
);
224 if (GTK_WIDGET_REALIZED (myfixed
) && !GTK_WIDGET_REALIZED (widget
))
225 gtk_widget_realize (widget
);
227 if (GTK_WIDGET_MAPPED (myfixed
) && !GTK_WIDGET_MAPPED (widget
))
228 gtk_widget_map (widget
);
230 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (myfixed
))
231 gtk_widget_queue_resize (GTK_WIDGET (myfixed
));
235 gtk_myfixed_move (GtkMyFixed
*myfixed
,
240 GtkMyFixedChild
*child
;
243 g_return_if_fail (myfixed
!= NULL
);
244 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
245 g_return_if_fail (widget
!= NULL
);
247 children
= myfixed
->children
;
250 child
= children
->data
;
251 children
= children
->next
;
253 if (child
->widget
== widget
)
255 if ((child
->x
== x
) && (child
->y
== y
)) return;
260 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (myfixed
))
261 gtk_widget_queue_resize (GTK_WIDGET (myfixed
));
269 gtk_myfixed_map (GtkWidget
*widget
)
272 GtkMyFixedChild
*child
;
275 g_return_if_fail (widget
!= NULL
);
276 g_return_if_fail (GTK_IS_MYFIXED (widget
));
278 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
279 myfixed
= GTK_MYFIXED (widget
);
281 gdk_window_show (widget
->window
);
283 children
= myfixed
->children
;
286 child
= children
->data
;
287 children
= children
->next
;
289 if (GTK_WIDGET_VISIBLE (child
->widget
) &&
290 !GTK_WIDGET_MAPPED (child
->widget
))
291 gtk_widget_map (child
->widget
);
295 #if (GTK_MINOR_VERSION == 0)
297 gtk_myfixed_unmap (GtkWidget
*widget
)
299 g_return_if_fail (widget
!= NULL
);
300 g_return_if_fail (GTK_IS_MYFIXED (widget
));
302 GTK_WIDGET_UNSET_FLAGS (widget
, GTK_MAPPED
);
307 gtk_myfixed_realize (GtkWidget
*widget
)
310 GdkWindowAttr attributes
;
311 gint attributes_mask
;
313 g_return_if_fail (widget
!= NULL
);
314 g_return_if_fail (GTK_IS_MYFIXED (widget
));
316 myfixed
= GTK_MYFIXED (widget
);
318 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
320 attributes
.window_type
= GDK_WINDOW_CHILD
;
322 #if (GTK_MINOR_VERSION > 0)
323 attributes
.x
= widget
->allocation
.x
;
324 attributes
.y
= widget
->allocation
.y
;
325 attributes
.width
= widget
->allocation
.width
;
326 attributes
.height
= widget
->allocation
.height
;
328 if (myfixed
->shadow_type
!= GTK_SHADOW_NONE
)
332 attributes
.width
-= 4;
333 attributes
.height
-= 4;
336 if (attributes
.width
< 2) attributes
.width
= 2;
337 if (attributes
.height
< 2) attributes
.height
= 2;
339 attributes
.x
= widget
->allocation
.x
;
340 attributes
.y
= widget
->allocation
.y
;
341 attributes
.width
= 32000;
342 attributes
.height
= 32000;
344 attributes
.wclass
= GDK_INPUT_OUTPUT
;
345 attributes
.visual
= gtk_widget_get_visual (widget
);
346 attributes
.colormap
= gtk_widget_get_colormap (widget
);
347 attributes
.event_mask
= gtk_widget_get_events (widget
);
348 attributes
.event_mask
|=
350 GDK_POINTER_MOTION_MASK
|
351 GDK_POINTER_MOTION_HINT_MASK
|
352 GDK_BUTTON_MOTION_MASK
|
353 GDK_BUTTON1_MOTION_MASK
|
354 GDK_BUTTON2_MOTION_MASK
|
355 GDK_BUTTON3_MOTION_MASK
|
356 GDK_BUTTON_PRESS_MASK
|
357 GDK_BUTTON_RELEASE_MASK
|
359 GDK_KEY_RELEASE_MASK
|
360 GDK_ENTER_NOTIFY_MASK
|
361 GDK_LEAVE_NOTIFY_MASK
|
362 GDK_FOCUS_CHANGE_MASK
;
364 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
366 widget
->window
= gdk_window_new (gtk_widget_get_parent_window (widget
), &attributes
,
368 gdk_window_set_user_data (widget
->window
, widget
);
370 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
371 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
375 gtk_myfixed_size_request (GtkWidget
*widget
,
376 GtkRequisition
*requisition
)
379 GtkMyFixedChild
*child
;
382 g_return_if_fail (widget
!= NULL
);
383 g_return_if_fail (GTK_IS_MYFIXED (widget
));
384 g_return_if_fail (requisition
!= NULL
);
386 myfixed
= GTK_MYFIXED (widget
);
389 requisition->width = 0;
390 requisition->height = 0;
392 requisition
->width
= widget
->requisition
.width
;
393 requisition
->height
= widget
->requisition
.height
;
395 children
= myfixed
->children
;
398 child
= children
->data
;
399 children
= children
->next
;
401 if (GTK_WIDGET_VISIBLE (child
->widget
))
403 gtk_widget_size_request (child
->widget
, &child
->widget
->requisition
);
409 gtk_myfixed_size_allocate (GtkWidget
*widget
,
410 GtkAllocation
*allocation
)
414 GtkMyFixedChild
*child
;
415 GtkAllocation child_allocation
;
418 g_return_if_fail (widget
!= NULL
);
419 g_return_if_fail (GTK_IS_MYFIXED(widget
));
420 g_return_if_fail (allocation
!= NULL
);
422 myfixed
= GTK_MYFIXED (widget
);
424 widget
->allocation
= *allocation
;
425 #if (GTK_MINOR_VERSION > 0)
426 if (myfixed
->shadow_type
== GTK_SHADOW_NONE
)
434 if (GTK_WIDGET_REALIZED (widget
))
436 gdk_window_move_resize( widget
->window
,
437 allocation
->x
+border
, allocation
->y
+border
,
438 #if (GTK_MINOR_VERSION > 0)
439 allocation
->width
-border
*2, allocation
->height
-border
*2
446 children
= myfixed
->children
;
449 child
= children
->data
;
450 children
= children
->next
;
452 /* please look at the text in wxWindow::DoSetSize() on why the
453 test GTK_WIDGET_REALIZED() has to be here */
454 if (GTK_WIDGET_VISIBLE (child
->widget
) &&
455 !(!GTK_WIDGET_REALIZED(child
->widget
) &&
456 GTK_IS_NOTEBOOK(child
->widget
) ))
458 child_allocation
.x
= child
->x
;
459 child_allocation
.y
= child
->y
;
460 child_allocation
.width
= child
->widget
->requisition
.width
;
461 child_allocation
.height
= child
->widget
->requisition
.height
;
462 gtk_widget_size_allocate (child
->widget
, &child_allocation
);
468 gtk_myfixed_paint (GtkWidget
*widget
,
471 g_return_if_fail (widget
!= NULL
);
472 g_return_if_fail (GTK_IS_MYFIXED (widget
));
473 g_return_if_fail (area
!= NULL
);
475 if (GTK_WIDGET_DRAWABLE (widget
))
476 gdk_window_clear_area (widget
->window
,
478 area
->width
, area
->height
);
482 gtk_myfixed_draw (GtkWidget
*widget
,
486 GtkMyFixedChild
*child
;
487 GdkRectangle child_area
;
490 g_return_if_fail (widget
!= NULL
);
491 g_return_if_fail (GTK_IS_MYFIXED (widget
));
493 if (GTK_WIDGET_DRAWABLE (widget
))
495 myfixed
= GTK_MYFIXED (widget
);
496 gtk_myfixed_paint (widget
, area
);
498 children
= myfixed
->children
;
501 child
= children
->data
;
502 children
= children
->next
;
504 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
505 gtk_widget_draw (child
->widget
, &child_area
);
511 gtk_myfixed_expose (GtkWidget
*widget
,
512 GdkEventExpose
*event
)
515 GtkMyFixedChild
*child
;
516 GdkEventExpose child_event
;
519 g_return_val_if_fail (widget
!= NULL
, FALSE
);
520 g_return_val_if_fail (GTK_IS_MYFIXED (widget
), FALSE
);
521 g_return_val_if_fail (event
!= NULL
, FALSE
);
523 if (GTK_WIDGET_DRAWABLE (widget
))
525 myfixed
= GTK_MYFIXED (widget
);
527 child_event
= *event
;
529 children
= myfixed
->children
;
532 child
= children
->data
;
533 children
= children
->next
;
535 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
536 gtk_widget_intersect (child
->widget
, &event
->area
,
538 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
546 gtk_myfixed_add (GtkContainer
*container
,
549 g_return_if_fail (container
!= NULL
);
550 g_return_if_fail (GTK_IS_MYFIXED (container
));
551 g_return_if_fail (widget
!= NULL
);
553 gtk_myfixed_put (GTK_MYFIXED (container
), widget
, 0, 0);
557 gtk_myfixed_remove (GtkContainer
*container
,
561 GtkMyFixedChild
*child
;
564 g_return_if_fail (container
!= NULL
);
565 g_return_if_fail (GTK_IS_MYFIXED (container
));
566 g_return_if_fail (widget
!= NULL
);
568 myfixed
= GTK_MYFIXED (container
);
570 children
= myfixed
->children
;
573 child
= children
->data
;
575 if (child
->widget
== widget
)
577 gtk_widget_unparent (widget
);
579 myfixed
->children
= g_list_remove_link (myfixed
->children
, children
);
580 g_list_free (children
);
583 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (container
))
584 gtk_widget_queue_resize (GTK_WIDGET (container
));
589 children
= children
->next
;
594 gtk_myfixed_foreach (GtkContainer
*container
,
595 #if (GTK_MINOR_VERSION > 0)
596 gboolean include_internals
,
598 GtkCallback callback
,
599 gpointer callback_data
)
602 GtkMyFixedChild
*child
;
605 g_return_if_fail (container
!= NULL
);
606 g_return_if_fail (GTK_IS_MYFIXED (container
));
607 g_return_if_fail (callback
!= NULL
);
609 myfixed
= GTK_MYFIXED (container
);
611 children
= myfixed
->children
;
614 child
= children
->data
;
615 children
= children
->next
;
617 (* callback
) (child
->widget
, callback_data
);
624 #endif /* __cplusplus */