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) &&
331 (child
->height
> 1) &&
332 !(GTK_WIDGET_REALIZED(widget
) && GTK_IS_NOTEBOOK(widget
)) )
334 child_allocation
.x
= child
->x
;
335 child_allocation
.y
= child
->y
;
336 child_allocation
.width
= MAX( child
->width
, 1 );
337 child_allocation
.height
= MAX( child
->height
, 1 );
339 /* work around for GTK bug when moving widgets outside
340 the X window -> do NOT move them entirely outside */
341 if (child_allocation
.y
+ child_allocation
.height
< 0)
342 child_allocation
.y
= -child_allocation
.height
;
343 if (child_allocation
.x
+ child_allocation
.width
< 0)
344 child_allocation
.x
= -child_allocation
.width
;
346 gtk_widget_size_allocate (widget
, &child_allocation
);
350 gtk_widget_queue_resize (GTK_WIDGET (myfixed
));
359 gtk_myfixed_map (GtkWidget
*widget
)
362 GtkMyFixedChild
*child
;
365 g_return_if_fail (widget
!= NULL
);
366 g_return_if_fail (GTK_IS_MYFIXED (widget
));
368 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
369 myfixed
= GTK_MYFIXED (widget
);
371 children
= myfixed
->children
;
374 child
= children
->data
;
375 children
= children
->next
;
377 if (GTK_WIDGET_VISIBLE (child
->widget
) && !GTK_WIDGET_MAPPED (child
->widget
))
378 gtk_widget_map (child
->widget
);
381 gdk_window_show (widget
->window
);
384 #if (GTK_MINOR_VERSION == 0)
386 gtk_myfixed_unmap (GtkWidget
*widget
)
388 g_return_if_fail (widget
!= NULL
);
389 g_return_if_fail (GTK_IS_MYFIXED (widget
));
391 GTK_WIDGET_UNSET_FLAGS (widget
, GTK_MAPPED
);
396 gtk_myfixed_realize (GtkWidget
*widget
)
399 GdkWindowAttr attributes
;
400 gint attributes_mask
;
402 g_return_if_fail (widget
!= NULL
);
403 g_return_if_fail (GTK_IS_MYFIXED (widget
));
405 myfixed
= GTK_MYFIXED (widget
);
407 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
409 attributes
.window_type
= GDK_WINDOW_CHILD
;
411 #if (GTK_MINOR_VERSION > 0)
412 attributes
.x
= widget
->allocation
.x
;
413 attributes
.y
= widget
->allocation
.y
;
414 attributes
.width
= widget
->allocation
.width
;
415 attributes
.height
= widget
->allocation
.height
;
417 if (myfixed
->shadow_type
!= GTK_SHADOW_NONE
)
421 attributes
.width
-= 4;
422 attributes
.height
-= 4;
425 if (attributes
.width
< 2) attributes
.width
= 2;
426 if (attributes
.height
< 2) attributes
.height
= 2;
428 attributes
.x
= widget
->allocation
.x
;
429 attributes
.y
= widget
->allocation
.y
;
430 attributes
.width
= 32000;
431 attributes
.height
= 32000;
433 attributes
.wclass
= GDK_INPUT_OUTPUT
;
434 attributes
.visual
= gtk_widget_get_visual (widget
);
435 attributes
.colormap
= gtk_widget_get_colormap (widget
);
436 attributes
.event_mask
= gtk_widget_get_events (widget
);
437 attributes
.event_mask
|=
439 GDK_POINTER_MOTION_MASK
|
440 GDK_POINTER_MOTION_HINT_MASK
|
441 GDK_BUTTON_MOTION_MASK
|
442 GDK_BUTTON1_MOTION_MASK
|
443 GDK_BUTTON2_MOTION_MASK
|
444 GDK_BUTTON3_MOTION_MASK
|
445 GDK_BUTTON_PRESS_MASK
|
446 GDK_BUTTON_RELEASE_MASK
|
448 GDK_KEY_RELEASE_MASK
|
449 GDK_ENTER_NOTIFY_MASK
|
450 GDK_LEAVE_NOTIFY_MASK
|
451 GDK_FOCUS_CHANGE_MASK
;
452 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
454 widget
->window
= gdk_window_new( gtk_widget_get_parent_window (widget
), &attributes
,
456 gdk_window_set_user_data (widget
->window
, widget
);
458 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
459 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
463 gtk_myfixed_size_request (GtkWidget
*widget
,
464 GtkRequisition
*requisition
)
467 GtkMyFixedChild
*child
;
469 GtkRequisition child_requisition
;
471 g_return_if_fail (widget
!= NULL
);
472 g_return_if_fail (GTK_IS_MYFIXED (widget
));
473 g_return_if_fail (requisition
!= NULL
);
475 myfixed
= GTK_MYFIXED (widget
);
477 children
= myfixed
->children
;
480 child
= children
->data
;
481 children
= children
->next
;
483 if (GTK_WIDGET_VISIBLE (child
->widget
))
485 gtk_widget_size_request (child
->widget
, &child_requisition
);
489 /* request very little, I'm not sure if requesting nothing
490 will always have positive effects on stability... */
491 requisition
->width
= 2;
492 requisition
->height
= 2;
496 gtk_myfixed_size_allocate (GtkWidget
*widget
,
497 GtkAllocation
*allocation
)
501 GtkMyFixedChild
*child
;
502 GtkAllocation child_allocation
;
505 g_return_if_fail (widget
!= NULL
);
506 g_return_if_fail (GTK_IS_MYFIXED(widget
));
507 g_return_if_fail (allocation
!= NULL
);
509 myfixed
= GTK_MYFIXED (widget
);
511 widget
->allocation
= *allocation
;
512 #if (GTK_MINOR_VERSION > 0)
513 if (myfixed
->shadow_type
== GTK_SHADOW_NONE
)
521 if (GTK_WIDGET_REALIZED (widget
))
523 gdk_window_move_resize( widget
->window
,
524 allocation
->x
+border
, allocation
->y
+border
,
525 #if (GTK_MINOR_VERSION > 0)
526 allocation
->width
-border
*2, allocation
->height
-border
*2
533 children
= myfixed
->children
;
536 child
= children
->data
;
537 children
= children
->next
;
539 /* please look at the text in wxWindow::DoSetSize() on why the
540 test GTK_WIDGET_REALIZED() has to be here */
541 if (GTK_WIDGET_VISIBLE (child
->widget
))
543 /* if (GTK_IS_NOTEBOOK(child->widget) && !GTK_WIDGET_REALIZED(child->widget))
545 gtk_widget_queue_resize( child->widget );
549 child_allocation
.x
= child
->x
;
550 child_allocation
.y
= child
->y
;
551 child_allocation
.width
= MAX( child
->width
, 1 );
552 child_allocation
.height
= MAX( child
->height
, 1 );
554 /* work around for GTK bug when moving widgets outside
555 the X window -> do NOT move them entirely outside */
556 if (child_allocation
.y
+ child_allocation
.height
< 0)
557 child_allocation
.y
= -child_allocation
.height
;
558 if (child_allocation
.x
+ child_allocation
.width
< 0)
559 child_allocation
.x
= -child_allocation
.width
;
561 gtk_widget_size_allocate (child
->widget
, &child_allocation
);
568 gtk_myfixed_paint (GtkWidget
*widget
,
571 g_return_if_fail (widget
!= NULL
);
572 g_return_if_fail (GTK_IS_MYFIXED (widget
));
573 g_return_if_fail (area
!= NULL
);
575 if (GTK_WIDGET_DRAWABLE (widget
))
576 gdk_window_clear_area (widget
->window
,
578 area
->width
, area
->height
);
582 gtk_myfixed_draw (GtkWidget
*widget
,
586 GtkMyFixedChild
*child
;
587 GdkRectangle child_area
;
590 g_return_if_fail (widget
!= NULL
);
591 g_return_if_fail (GTK_IS_MYFIXED (widget
));
593 if (GTK_WIDGET_DRAWABLE (widget
))
595 myfixed
= GTK_MYFIXED (widget
);
596 gtk_myfixed_paint (widget
, area
);
598 children
= myfixed
->children
;
601 child
= children
->data
;
602 children
= children
->next
;
604 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
605 gtk_widget_draw (child
->widget
, &child_area
);
611 gtk_myfixed_expose (GtkWidget
*widget
,
612 GdkEventExpose
*event
)
615 GtkMyFixedChild
*child
;
616 GdkEventExpose child_event
;
619 g_return_val_if_fail (widget
!= NULL
, FALSE
);
620 g_return_val_if_fail (GTK_IS_MYFIXED (widget
), FALSE
);
621 g_return_val_if_fail (event
!= NULL
, FALSE
);
623 if (GTK_WIDGET_DRAWABLE (widget
))
625 myfixed
= GTK_MYFIXED (widget
);
627 child_event
= *event
;
629 children
= myfixed
->children
;
632 child
= children
->data
;
633 children
= children
->next
;
635 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
636 gtk_widget_intersect (child
->widget
, &event
->area
,
638 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
646 gtk_myfixed_add (GtkContainer
*container
,
649 g_return_if_fail (container
!= NULL
);
650 g_return_if_fail (GTK_IS_MYFIXED (container
));
651 g_return_if_fail (widget
!= NULL
);
653 gtk_myfixed_put (GTK_MYFIXED (container
), widget
, 0, 0, 20, 20 );
657 gtk_myfixed_remove (GtkContainer
*container
,
661 GtkMyFixedChild
*child
;
664 g_return_if_fail (container
!= NULL
);
665 g_return_if_fail (GTK_IS_MYFIXED (container
));
666 g_return_if_fail (widget
!= NULL
);
668 myfixed
= GTK_MYFIXED (container
);
670 children
= myfixed
->children
;
673 child
= children
->data
;
675 if (child
->widget
== widget
)
677 gboolean was_visible
= GTK_WIDGET_VISIBLE (widget
);
679 gtk_widget_unparent (widget
);
681 myfixed
->children
= g_list_remove_link (myfixed
->children
, children
);
682 g_list_free (children
);
685 if (was_visible
&& GTK_WIDGET_VISIBLE (container
))
686 gtk_widget_queue_resize (GTK_WIDGET (container
));
691 children
= children
->next
;
696 gtk_myfixed_foreach (GtkContainer
*container
,
697 #if (GTK_MINOR_VERSION > 0)
698 gboolean include_internals
,
700 GtkCallback callback
,
701 gpointer callback_data
)
704 GtkMyFixedChild
*child
;
707 g_return_if_fail (container
!= NULL
);
708 g_return_if_fail (GTK_IS_MYFIXED (container
));
709 g_return_if_fail (callback
!= NULL
);
711 myfixed
= GTK_MYFIXED (container
);
713 children
= myfixed
->children
;
716 child
= children
->data
;
717 children
= children
->next
;
719 (* callback
) (child
->widget
, callback_data
);
726 #endif /* __cplusplus */