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
,
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
) && !GTK_WIDGET_REALIZED (widget
))
229 gtk_widget_realize (widget
);
231 if (GTK_WIDGET_MAPPED (myfixed
) && !GTK_WIDGET_MAPPED (widget
))
232 gtk_widget_map (widget
);
234 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (myfixed
))
235 gtk_widget_queue_resize (GTK_WIDGET (myfixed
));
239 gtk_myfixed_move (GtkMyFixed
*myfixed
,
244 GtkMyFixedChild
*child
;
247 g_return_if_fail (myfixed
!= NULL
);
248 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
249 g_return_if_fail (widget
!= NULL
);
251 children
= myfixed
->children
;
254 child
= children
->data
;
255 children
= children
->next
;
257 if (child
->widget
== widget
)
259 gtk_myfixed_set_size( myfixed
, widget
, x
, y
, child
->width
, child
->height
);
266 gtk_myfixed_resize (GtkMyFixed
*myfixed
,
271 GtkMyFixedChild
*child
;
274 g_return_if_fail (myfixed
!= NULL
);
275 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
276 g_return_if_fail (widget
!= NULL
);
278 children
= myfixed
->children
;
281 child
= children
->data
;
282 children
= children
->next
;
284 if (child
->widget
== widget
)
286 gtk_myfixed_set_size( myfixed
, widget
, child
->x
, child
->y
, width
, height
);
293 gtk_myfixed_set_size (GtkMyFixed
*myfixed
,
300 GtkMyFixedChild
*child
;
302 GtkAllocation child_allocation
;
304 g_return_if_fail (myfixed
!= NULL
);
305 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
306 g_return_if_fail (widget
!= NULL
);
308 children
= myfixed
->children
;
311 child
= children
->data
;
312 children
= children
->next
;
314 if (child
->widget
== widget
)
316 if ((child
->x
== x
) &&
318 (child
->width
== width
) &&
319 (child
->height
== height
)) return;
323 child
->width
= width
;
324 child
->height
= height
;
326 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (myfixed
))
328 if ((child
->width
> 1) && (child
->height
> 1) && (GTK_WIDGET_REALIZED(widget
)))
330 child_allocation
.x
= child
->x
;
331 child_allocation
.y
= child
->y
;
332 child_allocation
.width
= child
->width
;
333 child_allocation
.height
= child
->height
;
334 gtk_widget_size_allocate (widget
, &child_allocation
);
338 gtk_widget_queue_resize (GTK_WIDGET (myfixed
));
348 gtk_myfixed_map (GtkWidget
*widget
)
351 GtkMyFixedChild
*child
;
354 g_return_if_fail (widget
!= NULL
);
355 g_return_if_fail (GTK_IS_MYFIXED (widget
));
357 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
358 myfixed
= GTK_MYFIXED (widget
);
360 gdk_window_show (widget
->window
);
362 children
= myfixed
->children
;
365 child
= children
->data
;
366 children
= children
->next
;
368 if (GTK_WIDGET_VISIBLE (child
->widget
) &&
369 !GTK_WIDGET_MAPPED (child
->widget
))
370 gtk_widget_map (child
->widget
);
374 #if (GTK_MINOR_VERSION == 0)
376 gtk_myfixed_unmap (GtkWidget
*widget
)
378 g_return_if_fail (widget
!= NULL
);
379 g_return_if_fail (GTK_IS_MYFIXED (widget
));
381 GTK_WIDGET_UNSET_FLAGS (widget
, GTK_MAPPED
);
386 gtk_myfixed_realize (GtkWidget
*widget
)
389 GdkWindowAttr attributes
;
390 gint attributes_mask
;
392 g_return_if_fail (widget
!= NULL
);
393 g_return_if_fail (GTK_IS_MYFIXED (widget
));
395 myfixed
= GTK_MYFIXED (widget
);
397 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
399 attributes
.window_type
= GDK_WINDOW_CHILD
;
401 #if (GTK_MINOR_VERSION > 0)
402 attributes
.x
= widget
->allocation
.x
;
403 attributes
.y
= widget
->allocation
.y
;
404 attributes
.width
= widget
->allocation
.width
;
405 attributes
.height
= widget
->allocation
.height
;
407 if (myfixed
->shadow_type
!= GTK_SHADOW_NONE
)
411 attributes
.width
-= 4;
412 attributes
.height
-= 4;
415 if (attributes
.width
< 2) attributes
.width
= 2;
416 if (attributes
.height
< 2) attributes
.height
= 2;
418 attributes
.x
= widget
->allocation
.x
;
419 attributes
.y
= widget
->allocation
.y
;
420 attributes
.width
= 32000;
421 attributes
.height
= 32000;
423 attributes
.wclass
= GDK_INPUT_OUTPUT
;
424 attributes
.visual
= gtk_widget_get_visual (widget
);
425 attributes
.colormap
= gtk_widget_get_colormap (widget
);
426 attributes
.event_mask
= gtk_widget_get_events (widget
);
427 attributes
.event_mask
|=
429 GDK_POINTER_MOTION_MASK
|
430 GDK_POINTER_MOTION_HINT_MASK
|
431 GDK_BUTTON_MOTION_MASK
|
432 GDK_BUTTON1_MOTION_MASK
|
433 GDK_BUTTON2_MOTION_MASK
|
434 GDK_BUTTON3_MOTION_MASK
|
435 GDK_BUTTON_PRESS_MASK
|
436 GDK_BUTTON_RELEASE_MASK
|
438 GDK_KEY_RELEASE_MASK
|
439 GDK_ENTER_NOTIFY_MASK
|
440 GDK_LEAVE_NOTIFY_MASK
|
441 GDK_FOCUS_CHANGE_MASK
;
443 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
445 widget
->window
= gdk_window_new (gtk_widget_get_parent_window (widget
), &attributes
,
447 gdk_window_set_user_data (widget
->window
, widget
);
449 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
450 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
454 gtk_myfixed_size_request (GtkWidget
*widget
,
455 GtkRequisition
*requisition
)
458 GtkMyFixedChild
*child
;
461 g_return_if_fail (widget
!= NULL
);
462 g_return_if_fail (GTK_IS_MYFIXED (widget
));
463 g_return_if_fail (requisition
!= NULL
);
465 myfixed
= GTK_MYFIXED (widget
);
467 /* request very little, I'm not sure if requesting nothing
468 will always have positive effects on stability... */
469 requisition
->width
= 2;
470 requisition
->height
= 2;
472 children
= myfixed
->children
;
475 child
= children
->data
;
476 children
= children
->next
;
478 if (GTK_WIDGET_VISIBLE (child
->widget
))
480 gtk_widget_size_request (child
->widget
, &child
->widget
->requisition
);
486 gtk_myfixed_size_allocate (GtkWidget
*widget
,
487 GtkAllocation
*allocation
)
491 GtkMyFixedChild
*child
;
492 GtkAllocation child_allocation
;
495 g_return_if_fail (widget
!= NULL
);
496 g_return_if_fail (GTK_IS_MYFIXED(widget
));
497 g_return_if_fail (allocation
!= NULL
);
499 myfixed
= GTK_MYFIXED (widget
);
501 widget
->allocation
= *allocation
;
502 #if (GTK_MINOR_VERSION > 0)
503 if (myfixed
->shadow_type
== GTK_SHADOW_NONE
)
511 if (GTK_WIDGET_REALIZED (widget
))
513 gdk_window_move_resize( widget
->window
,
514 allocation
->x
+border
, allocation
->y
+border
,
515 #if (GTK_MINOR_VERSION > 0)
516 allocation
->width
-border
*2, allocation
->height
-border
*2
523 children
= myfixed
->children
;
526 child
= children
->data
;
527 children
= children
->next
;
529 /* please look at the text in wxWindow::DoSetSize() on why the
530 test GTK_WIDGET_REALIZED() has to be here */
531 if (GTK_WIDGET_VISIBLE (child
->widget
) &&
532 !(!GTK_WIDGET_REALIZED(child
->widget
) &&
533 GTK_IS_NOTEBOOK(child
->widget
) ))
535 child_allocation
.x
= child
->x
;
536 child_allocation
.y
= child
->y
;
537 child_allocation
.width
= child
->width
;
538 child_allocation
.height
= child
->height
;
539 gtk_widget_size_allocate (child
->widget
, &child_allocation
);
545 gtk_myfixed_paint (GtkWidget
*widget
,
548 g_return_if_fail (widget
!= NULL
);
549 g_return_if_fail (GTK_IS_MYFIXED (widget
));
550 g_return_if_fail (area
!= NULL
);
552 if (GTK_WIDGET_DRAWABLE (widget
))
553 gdk_window_clear_area (widget
->window
,
555 area
->width
, area
->height
);
559 gtk_myfixed_draw (GtkWidget
*widget
,
563 GtkMyFixedChild
*child
;
564 GdkRectangle child_area
;
567 g_return_if_fail (widget
!= NULL
);
568 g_return_if_fail (GTK_IS_MYFIXED (widget
));
570 if (GTK_WIDGET_DRAWABLE (widget
))
572 myfixed
= GTK_MYFIXED (widget
);
573 gtk_myfixed_paint (widget
, area
);
575 children
= myfixed
->children
;
578 child
= children
->data
;
579 children
= children
->next
;
581 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
582 gtk_widget_draw (child
->widget
, &child_area
);
588 gtk_myfixed_expose (GtkWidget
*widget
,
589 GdkEventExpose
*event
)
592 GtkMyFixedChild
*child
;
593 GdkEventExpose child_event
;
596 g_return_val_if_fail (widget
!= NULL
, FALSE
);
597 g_return_val_if_fail (GTK_IS_MYFIXED (widget
), FALSE
);
598 g_return_val_if_fail (event
!= NULL
, FALSE
);
600 if (GTK_WIDGET_DRAWABLE (widget
))
602 myfixed
= GTK_MYFIXED (widget
);
604 child_event
= *event
;
606 children
= myfixed
->children
;
609 child
= children
->data
;
610 children
= children
->next
;
612 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
613 gtk_widget_intersect (child
->widget
, &event
->area
,
615 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
623 gtk_myfixed_add (GtkContainer
*container
,
626 g_return_if_fail (container
!= NULL
);
627 g_return_if_fail (GTK_IS_MYFIXED (container
));
628 g_return_if_fail (widget
!= NULL
);
630 gtk_myfixed_put (GTK_MYFIXED (container
), widget
, 0, 0, 20, 20 );
634 gtk_myfixed_remove (GtkContainer
*container
,
638 GtkMyFixedChild
*child
;
641 g_return_if_fail (container
!= NULL
);
642 g_return_if_fail (GTK_IS_MYFIXED (container
));
643 g_return_if_fail (widget
!= NULL
);
645 myfixed
= GTK_MYFIXED (container
);
647 children
= myfixed
->children
;
650 child
= children
->data
;
652 if (child
->widget
== widget
)
654 gtk_widget_unparent (widget
);
656 myfixed
->children
= g_list_remove_link (myfixed
->children
, children
);
657 g_list_free (children
);
660 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (container
))
661 gtk_widget_queue_resize (GTK_WIDGET (container
));
666 children
= children
->next
;
671 gtk_myfixed_foreach (GtkContainer
*container
,
672 #if (GTK_MINOR_VERSION > 0)
673 gboolean include_internals
,
675 GtkCallback callback
,
676 gpointer callback_data
)
679 GtkMyFixedChild
*child
;
682 g_return_if_fail (container
!= NULL
);
683 g_return_if_fail (GTK_IS_MYFIXED (container
));
684 g_return_if_fail (callback
!= NULL
);
686 myfixed
= GTK_MYFIXED (container
);
688 children
= myfixed
->children
;
691 child
= children
->data
;
692 children
= children
->next
;
694 (* callback
) (child
->widget
, callback_data
);
701 #endif /* __cplusplus */