8 #include <yui/Libyui_config.h> 11 #include "ygtkfixed.h" 13 G_DEFINE_TYPE (
YGtkFixed, ygtk_fixed, GTK_TYPE_CONTAINER)
15 static void ygtk_fixed_init (
YGtkFixed *fixed)
17 gtk_widget_set_has_window(GTK_WIDGET(fixed), FALSE);
18 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (fixed), FALSE);
21 void ygtk_fixed_setup (
YGtkFixed *fixed, YGtkPreferredWidth cb1, YGtkPreferredHeight cb2, YGtkSetSize cb3, gpointer data)
23 fixed->preferred_width_cb = cb1;
24 fixed->preferred_height_cb = cb2;
25 fixed->set_size_cb = cb3;
32 for (i = fixed->children; i; i = i->next) {
34 if (child->widget == widget)
37 g_warning (
"YGtkFixed: could not find child.");
41 void ygtk_fixed_set_child_pos (
YGtkFixed *fixed, GtkWidget *widget, gint x, gint y)
48 void ygtk_fixed_set_child_size (
YGtkFixed *fixed, GtkWidget *widget, gint width, gint height)
52 child->height = height;
55 static void ygtk_fixed_add (GtkContainer *container, GtkWidget *widget)
57 YGtkFixed *fixed = YGTK_FIXED (container);
59 child->widget = widget;
60 child->width = child->height = 50;
61 fixed->children = g_slist_append (fixed->children, child);
62 gtk_widget_set_parent (widget, GTK_WIDGET (fixed));
65 static void ygtk_fixed_remove (GtkContainer *container, GtkWidget *widget)
67 YGtkFixed *fixed = YGTK_FIXED (container);
69 for (i = fixed->children; i; i = i->next) {
71 if (child->widget == widget) {
72 gboolean was_visible = gtk_widget_get_visible (widget);
73 gtk_widget_unparent (widget);
74 fixed->children = g_slist_delete_link (fixed->children, i);
77 gtk_widget_queue_resize (GTK_WIDGET (container));
83 static void ygtk_fixed_forall (GtkContainer *container, gboolean include_internals,
84 GtkCallback callback, gpointer callback_data)
86 g_return_if_fail (callback != NULL);
87 YGtkFixed *fixed = YGTK_FIXED (container);
88 GSList *i = fixed->children;
92 (* callback) (child->widget, callback_data);
97 ygtk_fixed_get_preferred_width (GtkWidget *widget,
102 *natural_width = *minimum_width =
103 fixed->preferred_width_cb (fixed, fixed->data);
107 ygtk_fixed_get_preferred_height (GtkWidget *widget,
108 gint *minimum_height,
109 gint *natural_height)
112 *natural_height = *minimum_height =
113 fixed->preferred_height_cb (fixed, fixed->data);
116 static void ygtk_fixed_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
119 fixed->set_size_cb (fixed, allocation->width, allocation->height, fixed->data);
122 for (i = fixed->children; i; i = i->next) {
125 if (gtk_widget_get_default_direction() == GTK_TEXT_DIR_RTL)
126 x = allocation->width - (child->x + child->width);
128 int y = child->y + allocation->y;
129 GtkAllocation child_alloc =
130 { x, y, MAX (child->width, 1), MAX (child->height, 1) };
132 GtkRequisition min_child_req;
133 GtkRequisition nat_child_req;
134 gtk_widget_get_preferred_size (child->widget, &min_child_req, &nat_child_req);
136 gtk_widget_size_allocate (child->widget, &child_alloc);
138 GTK_WIDGET_CLASS (ygtk_fixed_parent_class)->size_allocate (widget, allocation);
141 static GType ygtk_fixed_child_type (GtkContainer *container)
142 {
return GTK_TYPE_WIDGET; }
146 ygtk_fixed_parent_class = g_type_class_peek_parent (klass);
148 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
149 container_class->add = ygtk_fixed_add;
150 container_class->remove = ygtk_fixed_remove;
151 container_class->forall = ygtk_fixed_forall;
152 container_class->child_type = ygtk_fixed_child_type;
154 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
155 widget_class->get_preferred_width = ygtk_fixed_get_preferred_width;
156 widget_class->get_preferred_height = ygtk_fixed_get_preferred_height;
157 widget_class->size_allocate = ygtk_fixed_size_allocate;