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
,
82 myfixed_type
= gtk_type_unique (gtk_container_get_type (), &myfixed_info
);
89 gtk_myfixed_class_init (GtkMyFixedClass
*klass
)
91 GtkObjectClass
*object_class
;
92 GtkWidgetClass
*widget_class
;
93 GtkContainerClass
*container_class
;
95 object_class
= (GtkObjectClass
*) klass
;
96 widget_class
= (GtkWidgetClass
*) klass
;
97 container_class
= (GtkContainerClass
*) klass
;
99 #if (GTK_MINOR_VERSION > 0)
100 parent_class
= gtk_type_class (GTK_TYPE_CONTAINER
);
102 parent_class
= gtk_type_class (gtk_container_get_type ());
105 widget_class
->map
= gtk_myfixed_map
;
106 #if (GTK_MINOR_VERSION == 0)
107 widget_class
->unmap
= gtk_myfixed_unmap
;
109 widget_class
->realize
= gtk_myfixed_realize
;
110 widget_class
->size_request
= gtk_myfixed_size_request
;
111 widget_class
->size_allocate
= gtk_myfixed_size_allocate
;
112 widget_class
->draw
= gtk_myfixed_draw
;
113 widget_class
->expose_event
= gtk_myfixed_expose
;
115 container_class
->add
= gtk_myfixed_add
;
116 container_class
->remove
= gtk_myfixed_remove
;
117 #if (GTK_MINOR_VERSION > 0)
118 container_class
->forall
= gtk_myfixed_foreach
;
120 container_class
->foreach
= gtk_myfixed_foreach
;
123 #if (GTK_MINOR_VERSION > 0)
124 container_class
->child_type
= gtk_myfixed_child_type
;
127 #if (GTK_MINOR_VERSION > 0)
128 klass
->set_scroll_adjustments
= gtk_myfixed_scroll_set_adjustments
;
130 widget_class
->set_scroll_adjustments_signal
=
131 gtk_signal_new ("set_scroll_adjustments",
134 GTK_SIGNAL_OFFSET (GtkMyFixedClass
, set_scroll_adjustments
),
135 gtk_marshal_NONE__POINTER_POINTER
,
136 GTK_TYPE_NONE
, 2, GTK_TYPE_ADJUSTMENT
, GTK_TYPE_ADJUSTMENT
);
140 #if (GTK_MINOR_VERSION > 0)
142 gtk_myfixed_child_type (GtkContainer
*container
)
144 return GTK_TYPE_WIDGET
;
149 gtk_myfixed_init (GtkMyFixed
*myfixed
)
151 GTK_WIDGET_UNSET_FLAGS (myfixed
, GTK_NO_WINDOW
);
153 #if (GTK_MINOR_VERSION == 0)
154 GTK_WIDGET_SET_FLAGS (myfixed
, GTK_BASIC
);
157 #if (GTK_MINOR_VERSION > 0)
158 myfixed
->shadow_type
= GTK_SHADOW_NONE
;
161 myfixed
->children
= NULL
;
169 myfixed
= gtk_type_new (gtk_myfixed_get_type ());
171 return GTK_WIDGET (myfixed
);
174 #if (GTK_MINOR_VERSION > 0)
176 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
,
211 GtkMyFixedChild
*child_info
;
213 g_return_if_fail (myfixed
!= NULL
);
214 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
215 g_return_if_fail (widget
!= NULL
);
217 child_info
= g_new (GtkMyFixedChild
, 1);
218 child_info
->widget
= widget
;
221 child_info
->width
= width
;
222 child_info
->height
= height
;
224 gtk_widget_set_parent (widget
, GTK_WIDGET (myfixed
));
226 myfixed
->children
= g_list_append (myfixed
->children
, child_info
);
228 if (GTK_WIDGET_REALIZED (myfixed
))
229 gtk_widget_realize (widget
);
231 if (GTK_WIDGET_VISIBLE (myfixed
) && GTK_WIDGET_VISIBLE (widget
))
233 if (GTK_WIDGET_MAPPED (myfixed
))
234 gtk_widget_map (widget
);
236 gtk_widget_queue_resize (GTK_WIDGET (myfixed
));
241 gtk_myfixed_move (GtkMyFixed
*myfixed
,
246 GtkMyFixedChild
*child
;
249 g_return_if_fail (myfixed
!= NULL
);
250 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
251 g_return_if_fail (widget
!= NULL
);
253 children
= myfixed
->children
;
256 child
= children
->data
;
257 children
= children
->next
;
259 if (child
->widget
== widget
)
261 gtk_myfixed_set_size( myfixed
, widget
, x
, y
, child
->width
, child
->height
);
268 gtk_myfixed_resize (GtkMyFixed
*myfixed
,
273 GtkMyFixedChild
*child
;
276 g_return_if_fail (myfixed
!= NULL
);
277 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
278 g_return_if_fail (widget
!= NULL
);
280 children
= myfixed
->children
;
283 child
= children
->data
;
284 children
= children
->next
;
286 if (child
->widget
== widget
)
288 gtk_myfixed_set_size( myfixed
, widget
, child
->x
, child
->y
, width
, height
);
295 gtk_myfixed_set_size (GtkMyFixed
*myfixed
,
302 GtkMyFixedChild
*child
;
304 GtkAllocation child_allocation
;
306 g_return_if_fail (myfixed
!= NULL
);
307 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
308 g_return_if_fail (widget
!= NULL
);
310 children
= myfixed
->children
;
313 child
= children
->data
;
314 children
= children
->next
;
316 if (child
->widget
== widget
)
318 if ((child
->x
== x
) &&
320 (child
->width
== width
) &&
321 (child
->height
== height
)) return;
325 child
->width
= width
;
326 child
->height
= height
;
328 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (myfixed
))
330 if ((child
->width
> 1) && (child
->height
> 1) && (GTK_WIDGET_REALIZED(widget
)))
332 child_allocation
.x
= child
->x
;
333 child_allocation
.y
= child
->y
;
334 child_allocation
.width
= MAX( child
->width
, 1 );
335 child_allocation
.height
= MAX( child
->height
, 1 );
337 /* work around for GTK bug when moving widgets outside
338 the X window -> do NOT move them entirely outside */
339 if (child_allocation
.y
+ child_allocation
.height
< 0)
340 child_allocation
.y
= -child_allocation
.height
;
341 if (child_allocation
.x
+ child_allocation
.width
< 0)
342 child_allocation
.x
= -child_allocation
.width
;
344 gtk_widget_size_allocate (widget
, &child_allocation
);
348 gtk_widget_queue_resize (GTK_WIDGET (myfixed
));
357 gtk_myfixed_map (GtkWidget
*widget
)
360 GtkMyFixedChild
*child
;
363 g_return_if_fail (widget
!= NULL
);
364 g_return_if_fail (GTK_IS_MYFIXED (widget
));
366 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
367 myfixed
= GTK_MYFIXED (widget
);
369 children
= myfixed
->children
;
372 child
= children
->data
;
373 children
= children
->next
;
375 if (GTK_WIDGET_VISIBLE (child
->widget
) && !GTK_WIDGET_MAPPED (child
->widget
))
376 gtk_widget_map (child
->widget
);
379 gdk_window_show (widget
->window
);
382 #if (GTK_MINOR_VERSION == 0)
384 gtk_myfixed_unmap (GtkWidget
*widget
)
386 g_return_if_fail (widget
!= NULL
);
387 g_return_if_fail (GTK_IS_MYFIXED (widget
));
389 GTK_WIDGET_UNSET_FLAGS (widget
, GTK_MAPPED
);
394 gtk_myfixed_realize (GtkWidget
*widget
)
397 GdkWindowAttr attributes
;
398 gint attributes_mask
;
400 g_return_if_fail (widget
!= NULL
);
401 g_return_if_fail (GTK_IS_MYFIXED (widget
));
403 myfixed
= GTK_MYFIXED (widget
);
405 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
407 attributes
.window_type
= GDK_WINDOW_CHILD
;
409 #if (GTK_MINOR_VERSION > 0)
410 attributes
.x
= widget
->allocation
.x
;
411 attributes
.y
= widget
->allocation
.y
;
412 attributes
.width
= widget
->allocation
.width
;
413 attributes
.height
= widget
->allocation
.height
;
415 if (myfixed
->shadow_type
!= GTK_SHADOW_NONE
)
419 attributes
.width
-= 4;
420 attributes
.height
-= 4;
423 if (attributes
.width
< 2) attributes
.width
= 2;
424 if (attributes
.height
< 2) attributes
.height
= 2;
426 attributes
.x
= widget
->allocation
.x
;
427 attributes
.y
= widget
->allocation
.y
;
428 attributes
.width
= 32000;
429 attributes
.height
= 32000;
431 attributes
.wclass
= GDK_INPUT_OUTPUT
;
432 attributes
.visual
= gtk_widget_get_visual (widget
);
433 attributes
.colormap
= gtk_widget_get_colormap (widget
);
434 attributes
.event_mask
= gtk_widget_get_events (widget
);
435 attributes
.event_mask
|=
437 GDK_POINTER_MOTION_MASK
|
438 GDK_POINTER_MOTION_HINT_MASK
|
439 GDK_BUTTON_MOTION_MASK
|
440 GDK_BUTTON1_MOTION_MASK
|
441 GDK_BUTTON2_MOTION_MASK
|
442 GDK_BUTTON3_MOTION_MASK
|
443 GDK_BUTTON_PRESS_MASK
|
444 GDK_BUTTON_RELEASE_MASK
|
446 GDK_KEY_RELEASE_MASK
|
447 GDK_ENTER_NOTIFY_MASK
|
448 GDK_LEAVE_NOTIFY_MASK
|
449 GDK_FOCUS_CHANGE_MASK
;
450 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
452 widget
->window
= gdk_window_new( gtk_widget_get_parent_window (widget
), &attributes
,
454 gdk_window_set_user_data (widget
->window
, widget
);
456 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
457 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
461 gtk_myfixed_size_request (GtkWidget
*widget
,
462 GtkRequisition
*requisition
)
465 GtkMyFixedChild
*child
;
467 GtkRequisition child_requisition
;
469 g_return_if_fail (widget
!= NULL
);
470 g_return_if_fail (GTK_IS_MYFIXED (widget
));
471 g_return_if_fail (requisition
!= NULL
);
473 myfixed
= GTK_MYFIXED (widget
);
475 children
= myfixed
->children
;
478 child
= children
->data
;
479 children
= children
->next
;
481 if (GTK_WIDGET_VISIBLE (child
->widget
))
483 gtk_widget_size_request (child
->widget
, &child_requisition
);
487 /* request very little, I'm not sure if requesting nothing
488 will always have positive effects on stability... */
489 requisition
->width
= 2;
490 requisition
->height
= 2;
494 gtk_myfixed_size_allocate (GtkWidget
*widget
,
495 GtkAllocation
*allocation
)
499 GtkMyFixedChild
*child
;
500 GtkAllocation child_allocation
;
503 g_return_if_fail (widget
!= NULL
);
504 g_return_if_fail (GTK_IS_MYFIXED(widget
));
505 g_return_if_fail (allocation
!= NULL
);
507 myfixed
= GTK_MYFIXED (widget
);
509 widget
->allocation
= *allocation
;
510 #if (GTK_MINOR_VERSION > 0)
511 if (myfixed
->shadow_type
== GTK_SHADOW_NONE
)
519 if (GTK_WIDGET_REALIZED (widget
))
521 gdk_window_move_resize( widget
->window
,
522 allocation
->x
+border
, allocation
->y
+border
,
523 #if (GTK_MINOR_VERSION > 0)
524 allocation
->width
-border
*2, allocation
->height
-border
*2
531 children
= myfixed
->children
;
534 child
= children
->data
;
535 children
= children
->next
;
537 /* please look at the text in wxWindow::DoSetSize() on why the
538 test GTK_WIDGET_REALIZED() has to be here */
539 if (GTK_WIDGET_VISIBLE (child
->widget
))
541 /* if (GTK_IS_NOTEBOOK(child->widget) && !GTK_WIDGET_REALIZED(child->widget))
543 gtk_widget_queue_resize( child->widget );
547 child_allocation
.x
= child
->x
;
548 child_allocation
.y
= child
->y
;
549 child_allocation
.width
= MAX( child
->width
, 1 );
550 child_allocation
.height
= MAX( child
->height
, 1 );
552 /* work around for GTK bug when moving widgets outside
553 the X window -> do NOT move them entirely outside */
554 if (child_allocation
.y
+ child_allocation
.height
< 0)
555 child_allocation
.y
= -child_allocation
.height
;
556 if (child_allocation
.x
+ child_allocation
.width
< 0)
557 child_allocation
.x
= -child_allocation
.width
;
559 gtk_widget_size_allocate (child
->widget
, &child_allocation
);
566 gtk_myfixed_paint (GtkWidget
*widget
,
569 g_return_if_fail (widget
!= NULL
);
570 g_return_if_fail (GTK_IS_MYFIXED (widget
));
571 g_return_if_fail (area
!= NULL
);
573 if (GTK_WIDGET_DRAWABLE (widget
))
574 gdk_window_clear_area (widget
->window
,
576 area
->width
, area
->height
);
580 gtk_myfixed_draw (GtkWidget
*widget
,
584 GtkMyFixedChild
*child
;
585 GdkRectangle child_area
;
588 g_return_if_fail (widget
!= NULL
);
589 g_return_if_fail (GTK_IS_MYFIXED (widget
));
591 if (GTK_WIDGET_DRAWABLE (widget
))
593 myfixed
= GTK_MYFIXED (widget
);
594 gtk_myfixed_paint (widget
, area
);
596 children
= myfixed
->children
;
599 child
= children
->data
;
600 children
= children
->next
;
602 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
603 gtk_widget_draw (child
->widget
, &child_area
);
609 gtk_myfixed_expose (GtkWidget
*widget
,
610 GdkEventExpose
*event
)
613 GtkMyFixedChild
*child
;
614 GdkEventExpose child_event
;
617 g_return_val_if_fail (widget
!= NULL
, FALSE
);
618 g_return_val_if_fail (GTK_IS_MYFIXED (widget
), FALSE
);
619 g_return_val_if_fail (event
!= NULL
, FALSE
);
621 if (GTK_WIDGET_DRAWABLE (widget
))
623 myfixed
= GTK_MYFIXED (widget
);
625 child_event
= *event
;
627 children
= myfixed
->children
;
630 child
= children
->data
;
631 children
= children
->next
;
633 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
634 gtk_widget_intersect (child
->widget
, &event
->area
,
636 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
644 gtk_myfixed_add (GtkContainer
*container
,
647 g_return_if_fail (container
!= NULL
);
648 g_return_if_fail (GTK_IS_MYFIXED (container
));
649 g_return_if_fail (widget
!= NULL
);
651 gtk_myfixed_put (GTK_MYFIXED (container
), widget
, 0, 0, 20, 20 );
655 gtk_myfixed_remove (GtkContainer
*container
,
659 GtkMyFixedChild
*child
;
662 g_return_if_fail (container
!= NULL
);
663 g_return_if_fail (GTK_IS_MYFIXED (container
));
664 g_return_if_fail (widget
!= NULL
);
666 myfixed
= GTK_MYFIXED (container
);
668 children
= myfixed
->children
;
671 child
= children
->data
;
673 if (child
->widget
== widget
)
675 gboolean was_visible
= GTK_WIDGET_VISIBLE (widget
);
677 gtk_widget_unparent (widget
);
679 myfixed
->children
= g_list_remove_link (myfixed
->children
, children
);
680 g_list_free (children
);
683 if (was_visible
&& GTK_WIDGET_VISIBLE (container
))
684 gtk_widget_queue_resize (GTK_WIDGET (container
));
689 children
= children
->next
;
694 gtk_myfixed_foreach (GtkContainer
*container
,
695 #if (GTK_MINOR_VERSION > 0)
696 gboolean include_internals
,
698 GtkCallback callback
,
699 gpointer callback_data
)
702 GtkMyFixedChild
*child
;
705 g_return_if_fail (container
!= NULL
);
706 g_return_if_fail (GTK_IS_MYFIXED (container
));
707 g_return_if_fail (callback
!= NULL
);
709 myfixed
= GTK_MYFIXED (container
);
711 children
= myfixed
->children
;
714 child
= children
->data
;
715 children
= children
->next
;
717 (* callback
) (child
->widget
, callback_data
);
724 #endif /* __cplusplus */