]>
Commit | Line | Data |
---|---|---|
c67daf87 | 1 | /* /////////////////////////////////////////////////////////////////////////// |
0ba6a836 | 2 | // Name: src/gtk/win_gtk.c |
77ffb593 | 3 | // Purpose: Native GTK+ widget for wxWidgets, based on GtkLayout and |
ed673c6a RR |
4 | // GtkFixed. It makes use of the gravity window property and |
5 | // therefore does not work with GTK 1.0. | |
c801d85f | 6 | // Author: Robert Roebling |
c67d8618 | 7 | // Id: $Id$ |
01111366 | 8 | // Copyright: (c) 1998 Robert Roebling |
77ffb593 | 9 | // Licence: wxWidgets licence |
c67daf87 | 10 | /////////////////////////////////////////////////////////////////////////// */ |
c801d85f | 11 | |
d02af7bb JJ |
12 | #ifdef VMS |
13 | #define XCheckIfEvent XCHECKIFEVENT | |
3fa056ab | 14 | #endif |
27df579a | 15 | |
79918119 | 16 | #include "wx/platform.h" |
27df579a | 17 | #include "wx/gtk/win_gtk.h" |
38c7b3d3 | 18 | |
c801d85f KB |
19 | #ifdef __cplusplus |
20 | extern "C" { | |
21 | #endif /* __cplusplus */ | |
22 | ||
da048e3d | 23 | typedef struct _GtkPizzaAdjData GtkPizzaAdjData; |
ed673c6a | 24 | |
bf3dab48 | 25 | struct _GtkPizzaAdjData |
ed673c6a RR |
26 | { |
27 | gint dx; | |
28 | gint dy; | |
29 | }; | |
30 | ||
b6fa52db RR |
31 | static void gtk_pizza_class_init (GtkPizzaClass *klass); |
32 | static void gtk_pizza_init (GtkPizza *pizza); | |
ed673c6a | 33 | |
b6fa52db RR |
34 | static void gtk_pizza_realize (GtkWidget *widget); |
35 | static void gtk_pizza_unrealize (GtkWidget *widget); | |
ed673c6a | 36 | |
b6fa52db | 37 | static void gtk_pizza_map (GtkWidget *widget); |
ed673c6a | 38 | |
da048e3d | 39 | static void gtk_pizza_size_request (GtkWidget *widget, |
bf3dab48 | 40 | GtkRequisition *requisition); |
da048e3d | 41 | static void gtk_pizza_size_allocate (GtkWidget *widget, |
bf3dab48 | 42 | GtkAllocation *allocation); |
22aff579 VS |
43 | static void gtk_pizza_style_set (GtkWidget *widget, |
44 | GtkStyle *previous_style); | |
da048e3d | 45 | static void gtk_pizza_add (GtkContainer *container, |
bf3dab48 | 46 | GtkWidget *widget); |
da048e3d | 47 | static void gtk_pizza_remove (GtkContainer *container, |
bf3dab48 | 48 | GtkWidget *widget); |
b6fa52db RR |
49 | static void gtk_pizza_forall (GtkContainer *container, |
50 | gboolean include_internals, | |
51 | GtkCallback callback, | |
52 | gpointer callback_data); | |
17a1ebd1 | 53 | |
67d78217 RR |
54 | static void gtk_pizza_allocate_child (GtkPizza *pizza, |
55 | GtkPizzaChild *child); | |
3fc6e5fa RR |
56 | static void gtk_pizza_adjust_allocations_recurse (GtkWidget *widget, |
57 | gpointer cb_data); | |
ed673c6a | 58 | |
da048e3d | 59 | static GtkType gtk_pizza_child_type (GtkContainer *container); |
c801d85f | 60 | |
b6fa52db | 61 | static void gtk_pizza_scroll_set_adjustments (GtkPizza *pizza, |
bf3dab48 VZ |
62 | GtkAdjustment *hadj, |
63 | GtkAdjustment *vadj); | |
c801d85f | 64 | |
c764029c | 65 | static GtkWidgetClass* pizza_parent_class; |
034be888 | 66 | |
e1ff9329 | 67 | GtkType |
da048e3d | 68 | gtk_pizza_get_type () |
c801d85f | 69 | { |
e1ff9329 | 70 | static GtkType pizza_type = 0; |
c801d85f | 71 | |
da048e3d | 72 | if (!pizza_type) |
c801d85f | 73 | { |
67d78217 RR |
74 | static const GTypeInfo pizza_info = |
75 | { | |
76 | sizeof (GtkPizzaClass), | |
77 | NULL, /* base_init */ | |
78 | NULL, /* base_finalize */ | |
79 | (GClassInitFunc) gtk_pizza_class_init, | |
80 | NULL, /* class_finalize */ | |
81 | NULL, /* class_data */ | |
82 | sizeof (GtkPizza), | |
83 | 16, /* n_preallocs */ | |
84 | (GInstanceInitFunc) gtk_pizza_init, | |
4eb8ef2d | 85 | NULL |
67d78217 | 86 | }; |
17a1ebd1 | 87 | pizza_type = g_type_register_static (GTK_TYPE_CONTAINER, "GtkPizza", &pizza_info, (GTypeFlags)0); |
c801d85f | 88 | } |
bf3dab48 | 89 | |
da048e3d | 90 | return pizza_type; |
c801d85f KB |
91 | } |
92 | ||
02a525b3 VZ |
93 | /* Marshaller needed for set_scroll_adjustments signal, |
94 | generated with GLib-2.4.6 glib-genmarshal */ | |
143318dd RR |
95 | #define g_marshal_value_peek_object(v) g_value_get_object (v) |
96 | static void | |
97 | g_cclosure_user_marshal_VOID__OBJECT_OBJECT (GClosure *closure, | |
98 | GValue *return_value, | |
99 | guint n_param_values, | |
100 | const GValue *param_values, | |
101 | gpointer invocation_hint, | |
102 | gpointer marshal_data) | |
103 | { | |
104 | typedef void (*GMarshalFunc_VOID__OBJECT_OBJECT) (gpointer data1, | |
105 | gpointer arg_1, | |
106 | gpointer arg_2, | |
107 | gpointer data2); | |
108 | register GMarshalFunc_VOID__OBJECT_OBJECT callback; | |
109 | register GCClosure *cc = (GCClosure*) closure; | |
110 | register gpointer data1, data2; | |
111 | ||
112 | g_return_if_fail (n_param_values == 3); | |
113 | ||
114 | if (G_CCLOSURE_SWAP_DATA (closure)) | |
115 | { | |
116 | data1 = closure->data; | |
117 | data2 = g_value_peek_pointer (param_values + 0); | |
118 | } | |
119 | else | |
120 | { | |
121 | data1 = g_value_peek_pointer (param_values + 0); | |
122 | data2 = closure->data; | |
123 | } | |
124 | callback = (GMarshalFunc_VOID__OBJECT_OBJECT) (marshal_data ? marshal_data : cc->callback); | |
125 | ||
126 | callback (data1, | |
127 | g_marshal_value_peek_object (param_values + 1), | |
128 | g_marshal_value_peek_object (param_values + 2), | |
129 | data2); | |
130 | } | |
143318dd | 131 | |
c801d85f | 132 | static void |
da048e3d | 133 | gtk_pizza_class_init (GtkPizzaClass *klass) |
c801d85f | 134 | { |
053f9cc1 RR |
135 | GtkObjectClass *object_class; |
136 | GtkWidgetClass *widget_class; | |
137 | GtkContainerClass *container_class; | |
c801d85f | 138 | |
053f9cc1 RR |
139 | object_class = (GtkObjectClass*) klass; |
140 | widget_class = (GtkWidgetClass*) klass; | |
141 | container_class = (GtkContainerClass*) klass; | |
67d78217 | 142 | pizza_parent_class = gtk_type_class (GTK_TYPE_CONTAINER); |
c801d85f | 143 | |
da048e3d RR |
144 | widget_class->map = gtk_pizza_map; |
145 | widget_class->realize = gtk_pizza_realize; | |
146 | widget_class->unrealize = gtk_pizza_unrealize; | |
147 | widget_class->size_request = gtk_pizza_size_request; | |
148 | widget_class->size_allocate = gtk_pizza_size_allocate; | |
22aff579 | 149 | widget_class->style_set = gtk_pizza_style_set; |
053f9cc1 | 150 | |
da048e3d RR |
151 | container_class->add = gtk_pizza_add; |
152 | container_class->remove = gtk_pizza_remove; | |
153 | container_class->forall = gtk_pizza_forall; | |
38c7b3d3 | 154 | |
da048e3d | 155 | container_class->child_type = gtk_pizza_child_type; |
034be888 | 156 | |
da048e3d | 157 | klass->set_scroll_adjustments = gtk_pizza_scroll_set_adjustments; |
034be888 | 158 | |
053f9cc1 | 159 | widget_class->set_scroll_adjustments_signal = |
143318dd RR |
160 | g_signal_new( |
161 | "set_scroll_adjustments", | |
162 | G_TYPE_FROM_CLASS(object_class), | |
163 | G_SIGNAL_RUN_LAST, | |
164 | G_STRUCT_OFFSET(GtkPizzaClass, set_scroll_adjustments), | |
165 | NULL, | |
166 | NULL, | |
167 | g_cclosure_user_marshal_VOID__OBJECT_OBJECT, | |
168 | G_TYPE_NONE, | |
169 | 2, | |
170 | GTK_TYPE_ADJUSTMENT, | |
171 | GTK_TYPE_ADJUSTMENT); | |
38c7b3d3 RR |
172 | } |
173 | ||
38c7b3d3 | 174 | static GtkType |
da048e3d | 175 | gtk_pizza_child_type (GtkContainer *container) |
38c7b3d3 | 176 | { |
053f9cc1 | 177 | return GTK_TYPE_WIDGET; |
c801d85f KB |
178 | } |
179 | ||
180 | static void | |
da048e3d | 181 | gtk_pizza_init (GtkPizza *pizza) |
c801d85f | 182 | { |
da048e3d | 183 | GTK_WIDGET_UNSET_FLAGS (pizza, GTK_NO_WINDOW); |
bf3dab48 | 184 | |
da048e3d | 185 | pizza->children = NULL; |
bf3dab48 | 186 | |
da048e3d | 187 | pizza->bin_window = NULL; |
3dd9b88a | 188 | |
a31bb944 RR |
189 | pizza->m_xoffset = 0; |
190 | pizza->m_yoffset = 0; | |
c801d85f KB |
191 | } |
192 | ||
193 | GtkWidget* | |
da048e3d | 194 | gtk_pizza_new () |
c801d85f | 195 | { |
da048e3d | 196 | GtkPizza *pizza; |
c801d85f | 197 | |
efc8ab7c | 198 | pizza = g_object_new (gtk_pizza_get_type (), NULL); |
bf3dab48 | 199 | |
da048e3d | 200 | return GTK_WIDGET (pizza); |
c801d85f KB |
201 | } |
202 | ||
a31bb944 RR |
203 | gint gtk_pizza_get_xoffset (GtkPizza *pizza) |
204 | { | |
205 | g_return_val_if_fail ( (pizza != NULL), -1 ); | |
206 | g_return_val_if_fail ( (GTK_IS_PIZZA (pizza)), -1 ); | |
207 | ||
208 | return pizza->m_xoffset; | |
209 | } | |
210 | ||
211 | gint gtk_pizza_get_yoffset (GtkPizza *pizza) | |
212 | { | |
213 | g_return_val_if_fail ( (pizza != NULL), -1 ); | |
214 | g_return_val_if_fail ( (GTK_IS_PIZZA (pizza)), -1 ); | |
215 | ||
216 | return pizza->m_yoffset; | |
217 | } | |
218 | ||
219 | void gtk_pizza_set_xoffset (GtkPizza *pizza, gint xoffset) | |
220 | { | |
221 | g_return_if_fail (pizza != NULL); | |
222 | g_return_if_fail (GTK_IS_PIZZA (pizza)); | |
223 | ||
224 | pizza->m_xoffset = xoffset; | |
225 | // do something | |
226 | } | |
227 | ||
228 | void gtk_pizza_set_yoffset (GtkPizza *pizza, gint yoffset) | |
229 | { | |
230 | g_return_if_fail (pizza != NULL); | |
231 | g_return_if_fail (GTK_IS_PIZZA (pizza)); | |
232 | ||
233 | pizza->m_xoffset = yoffset; | |
234 | // do something | |
235 | } | |
236 | ||
428f4657 RR |
237 | gint gtk_pizza_get_rtl_offset (GtkPizza *pizza) |
238 | { | |
39b5648e | 239 | gint border; |
428f4657 RR |
240 | |
241 | g_return_val_if_fail ( (pizza != NULL), 0 ); | |
242 | g_return_val_if_fail ( (GTK_IS_PIZZA (pizza)), 0 ); | |
243 | ||
244 | if (!pizza->bin_window) return 0; | |
245 | ||
af05af4d | 246 | border = pizza->container.border_width; |
39b5648e | 247 | |
55dc8e18 | 248 | return GTK_WIDGET(pizza)->allocation.width - border*2; |
428f4657 RR |
249 | } |
250 | ||
251 | ||
bf3dab48 | 252 | static void |
da048e3d | 253 | gtk_pizza_scroll_set_adjustments (GtkPizza *pizza, |
bf3dab48 VZ |
254 | GtkAdjustment *hadj, |
255 | GtkAdjustment *vadj) | |
034be888 | 256 | { |
ed673c6a | 257 | /* We handle scrolling in the wxScrolledWindow, not here. */ |
034be888 RR |
258 | } |
259 | ||
c801d85f | 260 | void |
b6fa52db RR |
261 | gtk_pizza_put (GtkPizza *pizza, |
262 | GtkWidget *widget, | |
263 | gint x, | |
264 | gint y, | |
265 | gint width, | |
266 | gint height) | |
c801d85f | 267 | { |
da048e3d | 268 | GtkPizzaChild *child_info; |
053f9cc1 | 269 | |
da048e3d RR |
270 | g_return_if_fail (pizza != NULL); |
271 | g_return_if_fail (GTK_IS_PIZZA (pizza)); | |
053f9cc1 RR |
272 | g_return_if_fail (widget != NULL); |
273 | ||
da048e3d | 274 | child_info = g_new (GtkPizzaChild, 1); |
bf3dab48 | 275 | |
053f9cc1 RR |
276 | child_info->widget = widget; |
277 | child_info->x = x; | |
278 | child_info->y = y; | |
279 | child_info->width = width; | |
280 | child_info->height = height; | |
bf3dab48 VZ |
281 | |
282 | pizza->children = g_list_append (pizza->children, child_info); | |
ed673c6a | 283 | |
da048e3d | 284 | if (GTK_WIDGET_REALIZED (pizza)) |
8db7faf2 | 285 | gtk_widget_set_parent_window (widget, pizza->bin_window); |
bf3dab48 | 286 | |
2b5f62a0 VZ |
287 | gtk_widget_set_parent (widget, GTK_WIDGET (pizza)); |
288 | ||
d218e518 | 289 | gtk_widget_set_size_request( widget, width, height ); |
8db7faf2 RR |
290 | if (GTK_WIDGET_REALIZED (pizza)) |
291 | gtk_pizza_allocate_child (pizza, child_info); | |
c801d85f KB |
292 | } |
293 | ||
fdd3ed7a | 294 | void |
b6fa52db RR |
295 | gtk_pizza_set_size (GtkPizza *pizza, |
296 | GtkWidget *widget, | |
297 | gint x, | |
298 | gint y, | |
299 | gint width, | |
300 | gint height) | |
fdd3ed7a | 301 | { |
da048e3d | 302 | GtkPizzaChild *child; |
053f9cc1 | 303 | GList *children; |
fdd3ed7a | 304 | |
da048e3d RR |
305 | g_return_if_fail (pizza != NULL); |
306 | g_return_if_fail (GTK_IS_PIZZA (pizza)); | |
053f9cc1 | 307 | g_return_if_fail (widget != NULL); |
fdd3ed7a | 308 | |
aaf53059 | 309 | #ifndef WX_WARN_ILLEGAL_SETSIZE |
6b71411a | 310 | /* this really shouldn't happen -- but it does, a lot, right now and we |
aaf53059 MR |
311 | can't pass negative values to gtk_widget_set_size_request() without getting |
312 | a warning printed out, so filter them out here */ | |
6b71411a VZ |
313 | if ( width < 0 ) |
314 | width = 0; | |
315 | if ( height < 0 ) | |
316 | height = 0; | |
aaf53059 | 317 | #endif |
6b71411a | 318 | |
da048e3d | 319 | children = pizza->children; |
053f9cc1 | 320 | while (children) |
c801d85f | 321 | { |
053f9cc1 RR |
322 | child = children->data; |
323 | children = children->next; | |
c801d85f | 324 | |
053f9cc1 | 325 | if (child->widget == widget) |
c801d85f | 326 | { |
db71eb06 | 327 | if ((child->x == x) && |
bf3dab48 VZ |
328 | (child->y == y) && |
329 | (child->width == width) && | |
330 | (child->height == height)) return; | |
331 | ||
db71eb06 | 332 | child->x = x; |
053f9cc1 RR |
333 | child->y = y; |
334 | child->width = width; | |
335 | child->height = height; | |
69597639 | 336 | |
370dc79c | 337 | gtk_widget_set_size_request (widget, width, height); |
bf3dab48 | 338 | |
6d693bb4 | 339 | return; |
c801d85f KB |
340 | } |
341 | } | |
342 | } | |
343 | ||
344 | static void | |
da048e3d | 345 | gtk_pizza_map (GtkWidget *widget) |
c801d85f | 346 | { |
da048e3d RR |
347 | GtkPizza *pizza; |
348 | GtkPizzaChild *child; | |
053f9cc1 | 349 | GList *children; |
c801d85f | 350 | |
053f9cc1 | 351 | g_return_if_fail (widget != NULL); |
da048e3d | 352 | g_return_if_fail (GTK_IS_PIZZA (widget)); |
c801d85f | 353 | |
053f9cc1 | 354 | GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED); |
da048e3d | 355 | pizza = GTK_PIZZA (widget); |
c801d85f | 356 | |
da048e3d | 357 | children = pizza->children; |
053f9cc1 | 358 | while (children) |
c801d85f | 359 | { |
053f9cc1 RR |
360 | child = children->data; |
361 | children = children->next; | |
c801d85f | 362 | |
bf3dab48 | 363 | if ( GTK_WIDGET_VISIBLE (child->widget) && |
efc8ab7c | 364 | !GTK_WIDGET_MAPPED (child->widget) ) |
bf3dab48 VZ |
365 | { |
366 | gtk_widget_map (child->widget); | |
367 | } | |
c801d85f | 368 | } |
bf3dab48 | 369 | |
053f9cc1 | 370 | gdk_window_show (widget->window); |
da048e3d | 371 | gdk_window_show (pizza->bin_window); |
c801d85f KB |
372 | } |
373 | ||
c801d85f | 374 | static void |
da048e3d | 375 | gtk_pizza_realize (GtkWidget *widget) |
c801d85f | 376 | { |
da048e3d | 377 | GtkPizza *pizza; |
053f9cc1 RR |
378 | GdkWindowAttr attributes; |
379 | gint attributes_mask; | |
da048e3d | 380 | GtkPizzaChild *child; |
ed673c6a | 381 | GList *children; |
af05af4d | 382 | int border; |
c801d85f | 383 | |
053f9cc1 | 384 | g_return_if_fail (widget != NULL); |
da048e3d | 385 | g_return_if_fail (GTK_IS_PIZZA (widget)); |
c801d85f | 386 | |
da048e3d | 387 | pizza = GTK_PIZZA (widget); |
053f9cc1 | 388 | GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); |
c801d85f | 389 | |
053f9cc1 | 390 | attributes.window_type = GDK_WINDOW_CHILD; |
bf3dab48 | 391 | |
053f9cc1 RR |
392 | attributes.x = widget->allocation.x; |
393 | attributes.y = widget->allocation.y; | |
394 | attributes.width = widget->allocation.width; | |
395 | attributes.height = widget->allocation.height; | |
396 | ||
af05af4d PC |
397 | border = pizza->container.border_width; |
398 | attributes.x += border; | |
399 | attributes.y += border; | |
400 | attributes.width -= 2 * border; | |
401 | attributes.height -= 2 * border; | |
bf3dab48 | 402 | |
ed673c6a | 403 | /* minimal size */ |
053f9cc1 RR |
404 | if (attributes.width < 2) attributes.width = 2; |
405 | if (attributes.height < 2) attributes.height = 2; | |
bf3dab48 | 406 | |
053f9cc1 RR |
407 | attributes.wclass = GDK_INPUT_OUTPUT; |
408 | attributes.visual = gtk_widget_get_visual (widget); | |
409 | attributes.colormap = gtk_widget_get_colormap (widget); | |
3dd9b88a | 410 | attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK; |
ed673c6a | 411 | attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; |
bf3dab48 | 412 | |
c916e13b | 413 | widget->window = gdk_window_new(gtk_widget_get_parent_window (widget), |
bf3dab48 | 414 | &attributes, attributes_mask); |
ed673c6a RR |
415 | gdk_window_set_user_data (widget->window, widget); |
416 | ||
417 | attributes.x = 0; | |
418 | attributes.y = 0; | |
bf3dab48 | 419 | |
053f9cc1 | 420 | attributes.event_mask = gtk_widget_get_events (widget); |
3dd9b88a | 421 | attributes.event_mask |= GDK_EXPOSURE_MASK | |
67d78217 | 422 | GDK_SCROLL_MASK | |
3dd9b88a VZ |
423 | GDK_POINTER_MOTION_MASK | |
424 | GDK_POINTER_MOTION_HINT_MASK | | |
425 | GDK_BUTTON_MOTION_MASK | | |
426 | GDK_BUTTON1_MOTION_MASK | | |
427 | GDK_BUTTON2_MOTION_MASK | | |
428 | GDK_BUTTON3_MOTION_MASK | | |
429 | GDK_BUTTON_PRESS_MASK | | |
430 | GDK_BUTTON_RELEASE_MASK | | |
431 | GDK_KEY_PRESS_MASK | | |
432 | GDK_KEY_RELEASE_MASK | | |
433 | GDK_ENTER_NOTIFY_MASK | | |
434 | GDK_LEAVE_NOTIFY_MASK | | |
435 | GDK_FOCUS_CHANGE_MASK; | |
053f9cc1 | 436 | |
c916e13b | 437 | pizza->bin_window = gdk_window_new(widget->window, |
bf3dab48 | 438 | &attributes, attributes_mask); |
da048e3d | 439 | gdk_window_set_user_data (pizza->bin_window, widget); |
bf3dab48 | 440 | |
053f9cc1 RR |
441 | widget->style = gtk_style_attach (widget->style, widget->window); |
442 | gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); | |
b6fa52db | 443 | gtk_style_set_background (widget->style, pizza->bin_window, GTK_STATE_NORMAL ); |
17a1ebd1 | 444 | |
33611ebb RR |
445 | /* |
446 | gdk_window_set_back_pixmap( widget->window, NULL, FALSE ); | |
447 | gdk_window_set_back_pixmap( pizza->bin_window, NULL, FALSE ); | |
448 | */ | |
bf3dab48 | 449 | |
ed673c6a | 450 | /* cannot be done before realisation */ |
da048e3d | 451 | children = pizza->children; |
ed673c6a RR |
452 | while (children) |
453 | { | |
454 | child = children->data; | |
455 | children = children->next; | |
456 | ||
da048e3d | 457 | gtk_widget_set_parent_window (child->widget, pizza->bin_window); |
ed673c6a RR |
458 | } |
459 | } | |
460 | ||
bf3dab48 | 461 | static void |
da048e3d | 462 | gtk_pizza_unrealize (GtkWidget *widget) |
ed673c6a | 463 | { |
d5ab387d | 464 | GtkPizza *pizza; |
ed673c6a | 465 | |
d5ab387d RR |
466 | g_return_if_fail (widget != NULL); |
467 | g_return_if_fail (GTK_IS_PIZZA (widget)); | |
ed673c6a | 468 | |
d5ab387d | 469 | pizza = GTK_PIZZA (widget); |
ed673c6a | 470 | |
d5ab387d RR |
471 | gdk_window_set_user_data (pizza->bin_window, NULL); |
472 | gdk_window_destroy (pizza->bin_window); | |
473 | pizza->bin_window = NULL; | |
ed673c6a | 474 | |
c764029c PC |
475 | if (pizza_parent_class->unrealize) |
476 | pizza_parent_class->unrealize(widget); | |
c801d85f KB |
477 | } |
478 | ||
479 | static void | |
da048e3d | 480 | gtk_pizza_size_request (GtkWidget *widget, |
b6fa52db | 481 | GtkRequisition *requisition) |
c801d85f | 482 | { |
da048e3d RR |
483 | GtkPizza *pizza; |
484 | GtkPizzaChild *child; | |
053f9cc1 RR |
485 | GList *children; |
486 | GtkRequisition child_requisition; | |
bf3dab48 | 487 | |
053f9cc1 | 488 | g_return_if_fail (widget != NULL); |
da048e3d | 489 | g_return_if_fail (GTK_IS_PIZZA (widget)); |
053f9cc1 | 490 | g_return_if_fail (requisition != NULL); |
c801d85f | 491 | |
da048e3d | 492 | pizza = GTK_PIZZA (widget); |
bf3dab48 | 493 | |
da048e3d | 494 | children = pizza->children; |
053f9cc1 | 495 | while (children) |
c801d85f | 496 | { |
053f9cc1 RR |
497 | child = children->data; |
498 | children = children->next; | |
c801d85f | 499 | |
053f9cc1 | 500 | if (GTK_WIDGET_VISIBLE (child->widget)) |
bf3dab48 | 501 | { |
053f9cc1 | 502 | gtk_widget_size_request (child->widget, &child_requisition); |
bf3dab48 | 503 | } |
c801d85f | 504 | } |
bf3dab48 | 505 | |
053f9cc1 RR |
506 | /* request very little, I'm not sure if requesting nothing |
507 | will always have positive effects on stability... */ | |
508 | requisition->width = 2; | |
509 | requisition->height = 2; | |
c801d85f KB |
510 | } |
511 | ||
512 | static void | |
da048e3d | 513 | gtk_pizza_size_allocate (GtkWidget *widget, |
b6fa52db | 514 | GtkAllocation *allocation) |
c801d85f | 515 | { |
da048e3d | 516 | GtkPizza *pizza; |
053f9cc1 | 517 | gint border; |
ed673c6a | 518 | gint x,y,w,h; |
da048e3d | 519 | GtkPizzaChild *child; |
ed673c6a | 520 | GList *children; |
db71eb06 | 521 | gboolean only_resize; |
c801d85f | 522 | |
053f9cc1 | 523 | g_return_if_fail (widget != NULL); |
da048e3d | 524 | g_return_if_fail (GTK_IS_PIZZA(widget)); |
053f9cc1 | 525 | g_return_if_fail (allocation != NULL); |
c801d85f | 526 | |
da048e3d | 527 | pizza = GTK_PIZZA (widget); |
bf3dab48 | 528 | |
db71eb06 RR |
529 | only_resize = ((widget->allocation.x == allocation->x) && |
530 | (widget->allocation.y == allocation->y)); | |
227e5e99 | 531 | widget->allocation = *allocation; |
bf3dab48 | 532 | |
af05af4d | 533 | border = pizza->container.border_width; |
8db7faf2 | 534 | |
ed673c6a RR |
535 | x = allocation->x + border; |
536 | y = allocation->y + border; | |
537 | w = allocation->width - border*2; | |
538 | h = allocation->height - border*2; | |
69346023 PC |
539 | if (w < 0) |
540 | w = 0; | |
541 | if (h < 0) | |
542 | h = 0; | |
034be888 | 543 | |
053f9cc1 RR |
544 | if (GTK_WIDGET_REALIZED (widget)) |
545 | { | |
db71eb06 RR |
546 | if (only_resize) |
547 | gdk_window_resize( widget->window, w, h ); | |
548 | else | |
549 | gdk_window_move_resize( widget->window, x, y, w, h ); | |
02ae785a PC |
550 | |
551 | gdk_window_resize( pizza->bin_window, w, h ); | |
053f9cc1 | 552 | } |
bf3dab48 | 553 | |
da048e3d | 554 | children = pizza->children; |
6d693bb4 RR |
555 | while (children) |
556 | { | |
557 | child = children->data; | |
558 | children = children->next; | |
bf3dab48 | 559 | |
da048e3d | 560 | gtk_pizza_allocate_child (pizza, child); |
6d693bb4 | 561 | } |
c801d85f KB |
562 | } |
563 | ||
22aff579 VS |
564 | static void |
565 | gtk_pizza_style_set(GtkWidget *widget, GtkStyle *previous_style) | |
566 | { | |
567 | if (GTK_WIDGET_REALIZED(widget)) | |
568 | { | |
569 | gtk_style_set_background(widget->style, widget->window, GTK_STATE_NORMAL); | |
570 | gtk_style_set_background(widget->style, GTK_PIZZA(widget)->bin_window, GTK_STATE_NORMAL ); | |
571 | } | |
572 | ||
c764029c | 573 | pizza_parent_class->style_set(widget, previous_style); |
22aff579 VS |
574 | } |
575 | ||
c801d85f | 576 | static void |
da048e3d | 577 | gtk_pizza_add (GtkContainer *container, |
bf3dab48 | 578 | GtkWidget *widget) |
c801d85f | 579 | { |
ed673c6a | 580 | g_return_if_fail (container != NULL); |
da048e3d | 581 | g_return_if_fail (GTK_IS_PIZZA (container)); |
ed673c6a | 582 | g_return_if_fail (widget != NULL); |
c801d85f | 583 | |
da048e3d | 584 | gtk_pizza_put (GTK_PIZZA (container), widget, 0, 0, 20, 20 ); |
c801d85f KB |
585 | } |
586 | ||
587 | static void | |
da048e3d | 588 | gtk_pizza_remove (GtkContainer *container, |
b6fa52db | 589 | GtkWidget *widget) |
c801d85f | 590 | { |
da048e3d RR |
591 | GtkPizza *pizza; |
592 | GtkPizzaChild *child; | |
ed673c6a | 593 | GList *children; |
c801d85f | 594 | |
ed673c6a | 595 | g_return_if_fail (container != NULL); |
da048e3d | 596 | g_return_if_fail (GTK_IS_PIZZA (container)); |
ed673c6a | 597 | g_return_if_fail (widget != NULL); |
c801d85f | 598 | |
da048e3d | 599 | pizza = GTK_PIZZA (container); |
c801d85f | 600 | |
da048e3d | 601 | children = pizza->children; |
ed673c6a | 602 | while (children) |
c801d85f | 603 | { |
ed673c6a | 604 | child = children->data; |
c801d85f | 605 | |
ed673c6a | 606 | if (child->widget == widget) |
bf3dab48 VZ |
607 | { |
608 | gtk_widget_unparent (widget); | |
c801d85f | 609 | |
ed673c6a RR |
610 | /* security checks */ |
611 | g_return_if_fail (GTK_IS_WIDGET (widget)); | |
bf3dab48 VZ |
612 | |
613 | pizza->children = g_list_remove_link (pizza->children, children); | |
614 | g_list_free (children); | |
615 | g_free (child); | |
c801d85f | 616 | |
ed673c6a | 617 | /* security checks */ |
bf3dab48 VZ |
618 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
619 | ||
bf3dab48 VZ |
620 | break; |
621 | } | |
c801d85f | 622 | |
ed673c6a | 623 | children = children->next; |
c801d85f KB |
624 | } |
625 | } | |
626 | ||
627 | static void | |
da048e3d | 628 | gtk_pizza_forall (GtkContainer *container, |
b6fa52db RR |
629 | gboolean include_internals, |
630 | GtkCallback callback, | |
631 | gpointer callback_data) | |
c801d85f | 632 | { |
da048e3d RR |
633 | GtkPizza *pizza; |
634 | GtkPizzaChild *child; | |
6d693bb4 | 635 | GList *children; |
c801d85f | 636 | |
6d693bb4 | 637 | g_return_if_fail (container != NULL); |
da048e3d | 638 | g_return_if_fail (GTK_IS_PIZZA (container)); |
90350682 | 639 | g_return_if_fail (callback != (GtkCallback)NULL); |
c801d85f | 640 | |
da048e3d | 641 | pizza = GTK_PIZZA (container); |
c801d85f | 642 | |
da048e3d | 643 | children = pizza->children; |
6d693bb4 | 644 | while (children) |
c801d85f | 645 | { |
6d693bb4 RR |
646 | child = children->data; |
647 | children = children->next; | |
c801d85f | 648 | |
6d693bb4 | 649 | (* callback) (child->widget, callback_data); |
c801d85f KB |
650 | } |
651 | } | |
652 | ||
67d78217 RR |
653 | static void |
654 | gtk_pizza_allocate_child (GtkPizza *pizza, | |
655 | GtkPizzaChild *child) | |
656 | { | |
657 | GtkAllocation allocation; | |
658 | GtkRequisition requisition; | |
c801d85f | 659 | |
a31bb944 RR |
660 | allocation.x = child->x - pizza->m_xoffset; |
661 | allocation.y = child->y - pizza->m_yoffset; | |
67d78217 RR |
662 | gtk_widget_get_child_requisition (child->widget, &requisition); |
663 | allocation.width = requisition.width; | |
664 | allocation.height = requisition.height; | |
665 | ||
db71eb06 RR |
666 | if (gtk_widget_get_direction( GTK_WIDGET(pizza) ) == GTK_TEXT_DIR_RTL) |
667 | { | |
668 | /* reverse horizontal placement */ | |
39b5648e RR |
669 | gint offset,border; |
670 | ||
671 | offset = GTK_WIDGET(pizza)->allocation.width; | |
af05af4d | 672 | border = pizza->container.border_width; |
39b5648e RR |
673 | offset -= border*2; |
674 | ||
34445cc7 | 675 | allocation.x = offset - child->x - allocation.width + pizza->m_xoffset; |
db71eb06 RR |
676 | } |
677 | ||
67d78217 RR |
678 | gtk_widget_size_allocate (child->widget, &allocation); |
679 | } | |
ed673c6a | 680 | |
ed673c6a | 681 | static void |
da048e3d | 682 | gtk_pizza_adjust_allocations_recurse (GtkWidget *widget, |
bf3dab48 | 683 | gpointer cb_data) |
ed673c6a | 684 | { |
da048e3d | 685 | GtkPizzaAdjData *data = cb_data; |
ed673c6a | 686 | |
6d693bb4 RR |
687 | widget->allocation.x += data->dx; |
688 | widget->allocation.y += data->dy; | |
ed673c6a | 689 | |
6d693bb4 RR |
690 | if (GTK_WIDGET_NO_WINDOW (widget) && GTK_IS_CONTAINER (widget)) |
691 | { | |
bf3dab48 VZ |
692 | gtk_container_forall (GTK_CONTAINER (widget), |
693 | gtk_pizza_adjust_allocations_recurse, | |
694 | cb_data); | |
6d693bb4 | 695 | } |
ed673c6a RR |
696 | } |
697 | ||
698 | static void | |
da048e3d | 699 | gtk_pizza_adjust_allocations (GtkPizza *pizza, |
bf3dab48 VZ |
700 | gint dx, |
701 | gint dy) | |
ed673c6a | 702 | { |
0e09f76e RR |
703 | GList *tmp_list; |
704 | GtkPizzaAdjData data; | |
ed673c6a | 705 | |
0e09f76e RR |
706 | data.dx = dx; |
707 | data.dy = dy; | |
ed673c6a | 708 | |
0e09f76e RR |
709 | tmp_list = pizza->children; |
710 | while (tmp_list) | |
ed673c6a | 711 | { |
0e09f76e RR |
712 | GtkPizzaChild *child = tmp_list->data; |
713 | tmp_list = tmp_list->next; | |
bf3dab48 | 714 | |
0e09f76e RR |
715 | child->widget->allocation.x += dx; |
716 | child->widget->allocation.y += dy; | |
ed673c6a | 717 | |
0e09f76e RR |
718 | if (GTK_WIDGET_NO_WINDOW (child->widget) && |
719 | GTK_IS_CONTAINER (child->widget)) | |
720 | { | |
721 | gtk_container_forall (GTK_CONTAINER (child->widget), | |
722 | gtk_pizza_adjust_allocations_recurse, | |
723 | &data); | |
724 | } | |
ed673c6a RR |
725 | } |
726 | } | |
bf3dab48 | 727 | |
ed673c6a | 728 | void |
da048e3d | 729 | gtk_pizza_scroll (GtkPizza *pizza, gint dx, gint dy) |
ed673c6a | 730 | { |
a31bb944 RR |
731 | pizza->m_xoffset += dx; |
732 | pizza->m_yoffset += dy; | |
3fc6e5fa RR |
733 | |
734 | gtk_pizza_adjust_allocations (pizza, -dx, -dy); | |
735 | ||
736 | if (pizza->bin_window) | |
737 | gdk_window_scroll( pizza->bin_window, -dx, -dy ); | |
ed673c6a RR |
738 | } |
739 | ||
c801d85f KB |
740 | #ifdef __cplusplus |
741 | } | |
742 | #endif /* __cplusplus */ |