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