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"
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 #if (GTK_MINOR_VERSION == 0)
21 static void gtk_myfixed_unmap (GtkWidget
*widget
);
23 static void gtk_myfixed_realize (GtkWidget
*widget
);
24 static void gtk_myfixed_size_request (GtkWidget
*widget
,
25 GtkRequisition
*requisition
);
26 static void gtk_myfixed_size_allocate (GtkWidget
*widget
,
27 GtkAllocation
*allocation
);
28 static void gtk_myfixed_paint (GtkWidget
*widget
,
30 static void gtk_myfixed_draw (GtkWidget
*widget
,
32 static gint
gtk_myfixed_expose (GtkWidget
*widget
,
33 GdkEventExpose
*event
);
34 static void gtk_myfixed_add (GtkContainer
*container
,
36 static void gtk_myfixed_remove (GtkContainer
*container
,
38 static void gtk_myfixed_foreach (GtkContainer
*container
,
39 #if (GTK_MINOR_VERSION > 0)
40 gboolean include_internals
,
43 gpointer callback_data
);
44 #if (GTK_MINOR_VERSION > 0)
45 static GtkType
gtk_myfixed_child_type (GtkContainer
*container
);
48 #if (GTK_MINOR_VERSION > 0)
49 static void gtk_myfixed_scroll_set_adjustments (GtkMyFixed
*myfixed
,
56 static GtkContainerClass
*parent_class
= NULL
;
59 gtk_myfixed_get_type ()
61 static guint myfixed_type
= 0;
65 GtkTypeInfo myfixed_info
=
69 sizeof (GtkMyFixedClass
),
70 (GtkClassInitFunc
) gtk_myfixed_class_init
,
71 (GtkObjectInitFunc
) gtk_myfixed_init
,
72 #if (GTK_MINOR_VERSION > 0)
73 /* reserved_1 */ NULL
,
74 /* reserved_2 */ NULL
,
75 (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)
175 void gtk_myfixed_scroll_set_adjustments (GtkMyFixed
*myfixed
,
179 /* OK, this is embarassing, but this function has to be here */
183 gtk_myfixed_set_shadow_type (GtkMyFixed
*myfixed
,
186 g_return_if_fail (myfixed
!= NULL
);
187 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
189 if ((GtkShadowType
) myfixed
->shadow_type
!= type
)
191 myfixed
->shadow_type
= type
;
193 if (GTK_WIDGET_VISIBLE (myfixed
))
195 gtk_widget_size_allocate (GTK_WIDGET (myfixed
), &(GTK_WIDGET (myfixed
)->allocation
));
196 gtk_widget_queue_draw (GTK_WIDGET (myfixed
));
203 gtk_myfixed_put (GtkMyFixed
*myfixed
,
208 GtkMyFixedChild
*child_info
;
210 g_return_if_fail (myfixed
!= NULL
);
211 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
212 g_return_if_fail (widget
!= NULL
);
214 child_info
= g_new (GtkMyFixedChild
, 1);
215 child_info
->widget
= widget
;
219 gtk_widget_set_parent (widget
, GTK_WIDGET (myfixed
));
221 myfixed
->children
= g_list_append (myfixed
->children
, child_info
);
223 if (GTK_WIDGET_REALIZED (myfixed
) && !GTK_WIDGET_REALIZED (widget
))
224 gtk_widget_realize (widget
);
226 if (GTK_WIDGET_MAPPED (myfixed
) && !GTK_WIDGET_MAPPED (widget
))
227 gtk_widget_map (widget
);
229 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (myfixed
))
230 gtk_widget_queue_resize (GTK_WIDGET (myfixed
));
234 gtk_myfixed_move (GtkMyFixed
*myfixed
,
239 GtkMyFixedChild
*child
;
242 g_return_if_fail (myfixed
!= NULL
);
243 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
244 g_return_if_fail (widget
!= NULL
);
246 children
= myfixed
->children
;
249 child
= children
->data
;
250 children
= children
->next
;
252 if (child
->widget
== widget
)
254 if ((child
->x
== x
) && (child
->y
== y
)) return;
259 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (myfixed
))
260 gtk_widget_queue_resize (GTK_WIDGET (myfixed
));
268 gtk_myfixed_map (GtkWidget
*widget
)
271 GtkMyFixedChild
*child
;
274 g_return_if_fail (widget
!= NULL
);
275 g_return_if_fail (GTK_IS_MYFIXED (widget
));
277 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
278 myfixed
= GTK_MYFIXED (widget
);
280 gdk_window_show (widget
->window
);
282 children
= myfixed
->children
;
285 child
= children
->data
;
286 children
= children
->next
;
288 if (GTK_WIDGET_VISIBLE (child
->widget
) &&
289 !GTK_WIDGET_MAPPED (child
->widget
))
290 gtk_widget_map (child
->widget
);
294 #if (GTK_MINOR_VERSION == 0)
296 gtk_myfixed_unmap (GtkWidget
*widget
)
298 g_return_if_fail (widget
!= NULL
);
299 g_return_if_fail (GTK_IS_MYFIXED (widget
));
301 GTK_WIDGET_UNSET_FLAGS (widget
, GTK_MAPPED
);
306 gtk_myfixed_realize (GtkWidget
*widget
)
309 GdkWindowAttr attributes
;
310 gint attributes_mask
;
312 g_return_if_fail (widget
!= NULL
);
313 g_return_if_fail (GTK_IS_MYFIXED (widget
));
315 myfixed
= GTK_MYFIXED (widget
);
317 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
319 attributes
.window_type
= GDK_WINDOW_CHILD
;
321 #if (GTK_MINOR_VERSION > 0)
322 attributes
.x
= widget
->allocation
.x
;
323 attributes
.y
= widget
->allocation
.y
;
324 attributes
.width
= widget
->allocation
.width
;
325 attributes
.height
= widget
->allocation
.height
;
327 if (myfixed
->shadow_type
!= GTK_SHADOW_NONE
)
331 attributes
.width
-= 4;
332 attributes
.height
-= 4;
335 if (attributes
.width
< 2) attributes
.width
= 2;
336 if (attributes
.height
< 2) attributes
.height
= 2;
338 attributes
.x
= widget
->allocation
.x
;
339 attributes
.y
= widget
->allocation
.y
;
340 attributes
.width
= 32000;
341 attributes
.height
= 32000;
343 attributes
.wclass
= GDK_INPUT_OUTPUT
;
344 attributes
.visual
= gtk_widget_get_visual (widget
);
345 attributes
.colormap
= gtk_widget_get_colormap (widget
);
346 attributes
.event_mask
= gtk_widget_get_events (widget
);
347 attributes
.event_mask
|=
349 GDK_POINTER_MOTION_MASK
|
350 GDK_POINTER_MOTION_HINT_MASK
|
351 GDK_BUTTON_MOTION_MASK
|
352 GDK_BUTTON1_MOTION_MASK
|
353 GDK_BUTTON2_MOTION_MASK
|
354 GDK_BUTTON3_MOTION_MASK
|
355 GDK_BUTTON_PRESS_MASK
|
356 GDK_BUTTON_RELEASE_MASK
|
358 GDK_KEY_RELEASE_MASK
|
359 GDK_ENTER_NOTIFY_MASK
|
360 GDK_LEAVE_NOTIFY_MASK
|
361 GDK_FOCUS_CHANGE_MASK
;
363 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
365 widget
->window
= gdk_window_new (gtk_widget_get_parent_window (widget
), &attributes
,
367 gdk_window_set_user_data (widget
->window
, widget
);
369 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
370 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
374 gtk_myfixed_size_request (GtkWidget
*widget
,
375 GtkRequisition
*requisition
)
378 GtkMyFixedChild
*child
;
381 g_return_if_fail (widget
!= NULL
);
382 g_return_if_fail (GTK_IS_MYFIXED (widget
));
383 g_return_if_fail (requisition
!= NULL
);
385 myfixed
= GTK_MYFIXED (widget
);
387 requisition
->width
= 0;
388 requisition
->height
= 0;
390 children
= myfixed
->children
;
393 child
= children
->data
;
394 children
= children
->next
;
396 if (GTK_WIDGET_VISIBLE (child
->widget
))
398 gtk_widget_size_request (child
->widget
, &child
->widget
->requisition
);
404 gtk_myfixed_size_allocate (GtkWidget
*widget
,
405 GtkAllocation
*allocation
)
409 GtkMyFixedChild
*child
;
410 GtkAllocation child_allocation
;
413 g_return_if_fail (widget
!= NULL
);
414 g_return_if_fail (GTK_IS_MYFIXED(widget
));
415 g_return_if_fail (allocation
!= NULL
);
417 myfixed
= GTK_MYFIXED (widget
);
419 widget
->allocation
= *allocation
;
420 #if (GTK_MINOR_VERSION > 0)
421 if (myfixed
->shadow_type
== GTK_SHADOW_NONE
)
429 if (GTK_WIDGET_REALIZED (widget
))
431 gdk_window_move_resize( widget
->window
,
432 allocation
->x
+border
, allocation
->y
+border
,
433 #if (GTK_MINOR_VERSION > 0)
434 allocation
->width
-border
*2, allocation
->height
-border
*2
441 children
= myfixed
->children
;
444 child
= children
->data
;
445 children
= children
->next
;
447 if (GTK_WIDGET_VISIBLE (child
->widget
))
449 child_allocation
.x
= child
->x
;
450 child_allocation
.y
= child
->y
;
451 child_allocation
.width
= child
->widget
->requisition
.width
;
452 child_allocation
.height
= child
->widget
->requisition
.height
;
453 gtk_widget_size_allocate (child
->widget
, &child_allocation
);
459 gtk_myfixed_paint (GtkWidget
*widget
,
462 g_return_if_fail (widget
!= NULL
);
463 g_return_if_fail (GTK_IS_MYFIXED (widget
));
464 g_return_if_fail (area
!= NULL
);
466 if (GTK_WIDGET_DRAWABLE (widget
))
467 gdk_window_clear_area (widget
->window
,
469 area
->width
, area
->height
);
473 gtk_myfixed_draw (GtkWidget
*widget
,
477 GtkMyFixedChild
*child
;
478 GdkRectangle child_area
;
481 g_return_if_fail (widget
!= NULL
);
482 g_return_if_fail (GTK_IS_MYFIXED (widget
));
484 if (GTK_WIDGET_DRAWABLE (widget
))
486 myfixed
= GTK_MYFIXED (widget
);
487 gtk_myfixed_paint (widget
, area
);
489 children
= myfixed
->children
;
492 child
= children
->data
;
493 children
= children
->next
;
495 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
496 gtk_widget_draw (child
->widget
, &child_area
);
502 gtk_myfixed_expose (GtkWidget
*widget
,
503 GdkEventExpose
*event
)
506 GtkMyFixedChild
*child
;
507 GdkEventExpose child_event
;
510 g_return_val_if_fail (widget
!= NULL
, FALSE
);
511 g_return_val_if_fail (GTK_IS_MYFIXED (widget
), FALSE
);
512 g_return_val_if_fail (event
!= NULL
, FALSE
);
514 if (GTK_WIDGET_DRAWABLE (widget
))
516 myfixed
= GTK_MYFIXED (widget
);
518 child_event
= *event
;
520 children
= myfixed
->children
;
523 child
= children
->data
;
524 children
= children
->next
;
526 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
527 gtk_widget_intersect (child
->widget
, &event
->area
,
529 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
537 gtk_myfixed_add (GtkContainer
*container
,
540 g_return_if_fail (container
!= NULL
);
541 g_return_if_fail (GTK_IS_MYFIXED (container
));
542 g_return_if_fail (widget
!= NULL
);
544 gtk_myfixed_put (GTK_MYFIXED (container
), widget
, 0, 0);
548 gtk_myfixed_remove (GtkContainer
*container
,
552 GtkMyFixedChild
*child
;
555 g_return_if_fail (container
!= NULL
);
556 g_return_if_fail (GTK_IS_MYFIXED (container
));
557 g_return_if_fail (widget
!= NULL
);
559 myfixed
= GTK_MYFIXED (container
);
561 children
= myfixed
->children
;
564 child
= children
->data
;
566 if (child
->widget
== widget
)
568 gtk_widget_unparent (widget
);
570 myfixed
->children
= g_list_remove_link (myfixed
->children
, children
);
571 g_list_free (children
);
574 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (container
))
575 gtk_widget_queue_resize (GTK_WIDGET (container
));
580 children
= children
->next
;
585 gtk_myfixed_foreach (GtkContainer
*container
,
586 #if (GTK_MINOR_VERSION > 0)
587 gboolean include_internals
,
589 GtkCallback callback
,
590 gpointer callback_data
)
593 GtkMyFixedChild
*child
;
596 g_return_if_fail (container
!= NULL
);
597 g_return_if_fail (GTK_IS_MYFIXED (container
));
598 g_return_if_fail (callback
!= NULL
);
600 myfixed
= GTK_MYFIXED (container
);
602 children
= myfixed
->children
;
605 child
= children
->data
;
606 children
= children
->next
;
608 (* callback
) (child
->widget
, callback_data
);
615 #endif /* __cplusplus */