]>
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 | { |
28e88942 | 201 | GTK_WIDGET_SET_FLAGS (pizza, GTK_CAN_FOCUS); |
da048e3d | 202 | GTK_WIDGET_UNSET_FLAGS (pizza, GTK_NO_WINDOW); |
bf3dab48 | 203 | |
da048e3d | 204 | pizza->children = NULL; |
bf3dab48 | 205 | |
da048e3d | 206 | pizza->bin_window = NULL; |
3dd9b88a | 207 | |
a31bb944 RR |
208 | pizza->m_xoffset = 0; |
209 | pizza->m_yoffset = 0; | |
c801d85f KB |
210 | } |
211 | ||
212 | GtkWidget* | |
da048e3d | 213 | gtk_pizza_new () |
c801d85f | 214 | { |
da048e3d | 215 | GtkPizza *pizza; |
c801d85f | 216 | |
efc8ab7c | 217 | pizza = g_object_new (gtk_pizza_get_type (), NULL); |
bf3dab48 | 218 | |
da048e3d | 219 | return GTK_WIDGET (pizza); |
c801d85f KB |
220 | } |
221 | ||
a31bb944 RR |
222 | gint gtk_pizza_get_xoffset (GtkPizza *pizza) |
223 | { | |
224 | g_return_val_if_fail ( (pizza != NULL), -1 ); | |
225 | g_return_val_if_fail ( (GTK_IS_PIZZA (pizza)), -1 ); | |
226 | ||
227 | return pizza->m_xoffset; | |
228 | } | |
229 | ||
230 | gint gtk_pizza_get_yoffset (GtkPizza *pizza) | |
231 | { | |
232 | g_return_val_if_fail ( (pizza != NULL), -1 ); | |
233 | g_return_val_if_fail ( (GTK_IS_PIZZA (pizza)), -1 ); | |
234 | ||
235 | return pizza->m_yoffset; | |
236 | } | |
237 | ||
238 | void gtk_pizza_set_xoffset (GtkPizza *pizza, gint xoffset) | |
239 | { | |
240 | g_return_if_fail (pizza != NULL); | |
241 | g_return_if_fail (GTK_IS_PIZZA (pizza)); | |
242 | ||
243 | pizza->m_xoffset = xoffset; | |
244 | // do something | |
245 | } | |
246 | ||
247 | void gtk_pizza_set_yoffset (GtkPizza *pizza, gint yoffset) | |
248 | { | |
249 | g_return_if_fail (pizza != NULL); | |
250 | g_return_if_fail (GTK_IS_PIZZA (pizza)); | |
251 | ||
252 | pizza->m_xoffset = yoffset; | |
253 | // do something | |
254 | } | |
255 | ||
428f4657 RR |
256 | gint gtk_pizza_get_rtl_offset (GtkPizza *pizza) |
257 | { | |
39b5648e | 258 | gint border; |
428f4657 RR |
259 | |
260 | g_return_val_if_fail ( (pizza != NULL), 0 ); | |
261 | g_return_val_if_fail ( (GTK_IS_PIZZA (pizza)), 0 ); | |
f4322df6 | 262 | |
428f4657 | 263 | if (!pizza->bin_window) return 0; |
f4322df6 | 264 | |
af05af4d | 265 | border = pizza->container.border_width; |
f4322df6 | 266 | |
55dc8e18 | 267 | return GTK_WIDGET(pizza)->allocation.width - border*2; |
428f4657 RR |
268 | } |
269 | ||
270 | ||
bf3dab48 | 271 | static void |
da048e3d | 272 | gtk_pizza_scroll_set_adjustments (GtkPizza *pizza, |
bf3dab48 VZ |
273 | GtkAdjustment *hadj, |
274 | GtkAdjustment *vadj) | |
034be888 | 275 | { |
ed673c6a | 276 | /* We handle scrolling in the wxScrolledWindow, not here. */ |
034be888 RR |
277 | } |
278 | ||
c801d85f | 279 | void |
b6fa52db RR |
280 | gtk_pizza_put (GtkPizza *pizza, |
281 | GtkWidget *widget, | |
282 | gint x, | |
283 | gint y, | |
284 | gint width, | |
285 | gint height) | |
c801d85f | 286 | { |
da048e3d | 287 | GtkPizzaChild *child_info; |
053f9cc1 | 288 | |
da048e3d RR |
289 | g_return_if_fail (pizza != NULL); |
290 | g_return_if_fail (GTK_IS_PIZZA (pizza)); | |
053f9cc1 RR |
291 | g_return_if_fail (widget != NULL); |
292 | ||
da048e3d | 293 | child_info = g_new (GtkPizzaChild, 1); |
bf3dab48 | 294 | |
053f9cc1 RR |
295 | child_info->widget = widget; |
296 | child_info->x = x; | |
297 | child_info->y = y; | |
bf3dab48 VZ |
298 | |
299 | pizza->children = g_list_append (pizza->children, child_info); | |
ed673c6a | 300 | |
da048e3d | 301 | if (GTK_WIDGET_REALIZED (pizza)) |
8db7faf2 | 302 | gtk_widget_set_parent_window (widget, pizza->bin_window); |
bf3dab48 | 303 | |
2b5f62a0 VZ |
304 | gtk_widget_set_parent (widget, GTK_WIDGET (pizza)); |
305 | ||
d218e518 | 306 | gtk_widget_set_size_request( widget, width, height ); |
8db7faf2 RR |
307 | if (GTK_WIDGET_REALIZED (pizza)) |
308 | gtk_pizza_allocate_child (pizza, child_info); | |
c801d85f KB |
309 | } |
310 | ||
fdd3ed7a | 311 | void |
b6fa52db RR |
312 | gtk_pizza_set_size (GtkPizza *pizza, |
313 | GtkWidget *widget, | |
314 | gint x, | |
315 | gint y, | |
316 | gint width, | |
317 | gint height) | |
fdd3ed7a | 318 | { |
da048e3d | 319 | GtkPizzaChild *child; |
053f9cc1 | 320 | GList *children; |
fdd3ed7a | 321 | |
da048e3d RR |
322 | g_return_if_fail (pizza != NULL); |
323 | g_return_if_fail (GTK_IS_PIZZA (pizza)); | |
053f9cc1 | 324 | g_return_if_fail (widget != NULL); |
fdd3ed7a | 325 | |
aaf53059 | 326 | #ifndef WX_WARN_ILLEGAL_SETSIZE |
6b71411a | 327 | /* this really shouldn't happen -- but it does, a lot, right now and we |
aaf53059 MR |
328 | can't pass negative values to gtk_widget_set_size_request() without getting |
329 | a warning printed out, so filter them out here */ | |
6b71411a VZ |
330 | if ( width < 0 ) |
331 | width = 0; | |
332 | if ( height < 0 ) | |
333 | height = 0; | |
aaf53059 | 334 | #endif |
6b71411a | 335 | |
da048e3d | 336 | children = pizza->children; |
053f9cc1 | 337 | while (children) |
c801d85f | 338 | { |
053f9cc1 RR |
339 | child = children->data; |
340 | children = children->next; | |
c801d85f | 341 | |
053f9cc1 | 342 | if (child->widget == widget) |
c801d85f | 343 | { |
bc9e85a3 PC |
344 | if (child->x != x || child->y != y) |
345 | { | |
346 | child->x = x; | |
347 | child->y = y; | |
348 | gtk_widget_queue_resize(widget); | |
349 | } | |
91641d04 | 350 | |
370dc79c | 351 | gtk_widget_set_size_request (widget, width, height); |
bf3dab48 | 352 | |
6d693bb4 | 353 | return; |
c801d85f KB |
354 | } |
355 | } | |
356 | } | |
357 | ||
358 | static void | |
da048e3d | 359 | gtk_pizza_map (GtkWidget *widget) |
c801d85f | 360 | { |
da048e3d RR |
361 | GtkPizza *pizza; |
362 | GtkPizzaChild *child; | |
053f9cc1 | 363 | GList *children; |
c801d85f | 364 | |
053f9cc1 | 365 | g_return_if_fail (widget != NULL); |
da048e3d | 366 | g_return_if_fail (GTK_IS_PIZZA (widget)); |
c801d85f | 367 | |
053f9cc1 | 368 | GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED); |
da048e3d | 369 | pizza = GTK_PIZZA (widget); |
c801d85f | 370 | |
da048e3d | 371 | children = pizza->children; |
053f9cc1 | 372 | while (children) |
c801d85f | 373 | { |
053f9cc1 RR |
374 | child = children->data; |
375 | children = children->next; | |
c801d85f | 376 | |
bf3dab48 | 377 | if ( GTK_WIDGET_VISIBLE (child->widget) && |
efc8ab7c | 378 | !GTK_WIDGET_MAPPED (child->widget) ) |
bf3dab48 VZ |
379 | { |
380 | gtk_widget_map (child->widget); | |
381 | } | |
c801d85f | 382 | } |
bf3dab48 | 383 | |
053f9cc1 | 384 | gdk_window_show (widget->window); |
da048e3d | 385 | gdk_window_show (pizza->bin_window); |
c801d85f KB |
386 | } |
387 | ||
c801d85f | 388 | static void |
da048e3d | 389 | gtk_pizza_realize (GtkWidget *widget) |
c801d85f | 390 | { |
da048e3d | 391 | GtkPizza *pizza; |
053f9cc1 RR |
392 | GdkWindowAttr attributes; |
393 | gint attributes_mask; | |
da048e3d | 394 | GtkPizzaChild *child; |
ed673c6a | 395 | GList *children; |
af05af4d | 396 | int border; |
c801d85f | 397 | |
053f9cc1 | 398 | g_return_if_fail (widget != NULL); |
da048e3d | 399 | g_return_if_fail (GTK_IS_PIZZA (widget)); |
c801d85f | 400 | |
da048e3d | 401 | pizza = GTK_PIZZA (widget); |
053f9cc1 | 402 | GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); |
c801d85f | 403 | |
053f9cc1 | 404 | attributes.window_type = GDK_WINDOW_CHILD; |
bf3dab48 | 405 | |
053f9cc1 RR |
406 | attributes.x = widget->allocation.x; |
407 | attributes.y = widget->allocation.y; | |
408 | attributes.width = widget->allocation.width; | |
409 | attributes.height = widget->allocation.height; | |
410 | ||
af05af4d PC |
411 | border = pizza->container.border_width; |
412 | attributes.x += border; | |
413 | attributes.y += border; | |
414 | attributes.width -= 2 * border; | |
415 | attributes.height -= 2 * border; | |
bf3dab48 | 416 | |
ed673c6a | 417 | /* minimal size */ |
053f9cc1 RR |
418 | if (attributes.width < 2) attributes.width = 2; |
419 | if (attributes.height < 2) attributes.height = 2; | |
bf3dab48 | 420 | |
053f9cc1 RR |
421 | attributes.wclass = GDK_INPUT_OUTPUT; |
422 | attributes.visual = gtk_widget_get_visual (widget); | |
423 | attributes.colormap = gtk_widget_get_colormap (widget); | |
3dd9b88a | 424 | attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK; |
ed673c6a | 425 | attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; |
bf3dab48 | 426 | |
c916e13b | 427 | widget->window = gdk_window_new(gtk_widget_get_parent_window (widget), |
bf3dab48 | 428 | &attributes, attributes_mask); |
ed673c6a RR |
429 | gdk_window_set_user_data (widget->window, widget); |
430 | ||
431 | attributes.x = 0; | |
432 | attributes.y = 0; | |
bf3dab48 | 433 | |
053f9cc1 | 434 | attributes.event_mask = gtk_widget_get_events (widget); |
3dd9b88a | 435 | attributes.event_mask |= GDK_EXPOSURE_MASK | |
67d78217 | 436 | GDK_SCROLL_MASK | |
3dd9b88a VZ |
437 | GDK_POINTER_MOTION_MASK | |
438 | GDK_POINTER_MOTION_HINT_MASK | | |
439 | GDK_BUTTON_MOTION_MASK | | |
440 | GDK_BUTTON1_MOTION_MASK | | |
441 | GDK_BUTTON2_MOTION_MASK | | |
442 | GDK_BUTTON3_MOTION_MASK | | |
443 | GDK_BUTTON_PRESS_MASK | | |
444 | GDK_BUTTON_RELEASE_MASK | | |
445 | GDK_KEY_PRESS_MASK | | |
446 | GDK_KEY_RELEASE_MASK | | |
447 | GDK_ENTER_NOTIFY_MASK | | |
448 | GDK_LEAVE_NOTIFY_MASK | | |
449 | GDK_FOCUS_CHANGE_MASK; | |
053f9cc1 | 450 | |
c916e13b | 451 | pizza->bin_window = gdk_window_new(widget->window, |
bf3dab48 | 452 | &attributes, attributes_mask); |
da048e3d | 453 | gdk_window_set_user_data (pizza->bin_window, widget); |
bf3dab48 | 454 | |
053f9cc1 RR |
455 | widget->style = gtk_style_attach (widget->style, widget->window); |
456 | gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); | |
b6fa52db | 457 | gtk_style_set_background (widget->style, pizza->bin_window, GTK_STATE_NORMAL ); |
17a1ebd1 | 458 | |
33611ebb RR |
459 | /* |
460 | gdk_window_set_back_pixmap( widget->window, NULL, FALSE ); | |
461 | gdk_window_set_back_pixmap( pizza->bin_window, NULL, FALSE ); | |
462 | */ | |
bf3dab48 | 463 | |
ed673c6a | 464 | /* cannot be done before realisation */ |
da048e3d | 465 | children = pizza->children; |
ed673c6a RR |
466 | while (children) |
467 | { | |
468 | child = children->data; | |
469 | children = children->next; | |
470 | ||
da048e3d | 471 | gtk_widget_set_parent_window (child->widget, pizza->bin_window); |
ed673c6a RR |
472 | } |
473 | } | |
474 | ||
bf3dab48 | 475 | static void |
da048e3d | 476 | gtk_pizza_unrealize (GtkWidget *widget) |
ed673c6a | 477 | { |
d5ab387d | 478 | GtkPizza *pizza; |
ed673c6a | 479 | |
d5ab387d RR |
480 | g_return_if_fail (widget != NULL); |
481 | g_return_if_fail (GTK_IS_PIZZA (widget)); | |
ed673c6a | 482 | |
d5ab387d | 483 | pizza = GTK_PIZZA (widget); |
ed673c6a | 484 | |
d5ab387d RR |
485 | gdk_window_set_user_data (pizza->bin_window, NULL); |
486 | gdk_window_destroy (pizza->bin_window); | |
487 | pizza->bin_window = NULL; | |
ed673c6a | 488 | |
c764029c PC |
489 | if (pizza_parent_class->unrealize) |
490 | pizza_parent_class->unrealize(widget); | |
c801d85f KB |
491 | } |
492 | ||
493 | static void | |
da048e3d | 494 | gtk_pizza_size_request (GtkWidget *widget, |
b6fa52db | 495 | GtkRequisition *requisition) |
c801d85f | 496 | { |
da048e3d RR |
497 | GtkPizza *pizza; |
498 | GtkPizzaChild *child; | |
053f9cc1 RR |
499 | GList *children; |
500 | GtkRequisition child_requisition; | |
bf3dab48 | 501 | |
053f9cc1 | 502 | g_return_if_fail (widget != NULL); |
da048e3d | 503 | g_return_if_fail (GTK_IS_PIZZA (widget)); |
053f9cc1 | 504 | g_return_if_fail (requisition != NULL); |
c801d85f | 505 | |
da048e3d | 506 | pizza = GTK_PIZZA (widget); |
bf3dab48 | 507 | |
da048e3d | 508 | children = pizza->children; |
053f9cc1 | 509 | while (children) |
c801d85f | 510 | { |
053f9cc1 RR |
511 | child = children->data; |
512 | children = children->next; | |
c801d85f | 513 | |
053f9cc1 | 514 | if (GTK_WIDGET_VISIBLE (child->widget)) |
bf3dab48 | 515 | { |
053f9cc1 | 516 | gtk_widget_size_request (child->widget, &child_requisition); |
bf3dab48 | 517 | } |
c801d85f | 518 | } |
bf3dab48 | 519 | |
053f9cc1 RR |
520 | /* request very little, I'm not sure if requesting nothing |
521 | will always have positive effects on stability... */ | |
522 | requisition->width = 2; | |
523 | requisition->height = 2; | |
c801d85f KB |
524 | } |
525 | ||
526 | static void | |
da048e3d | 527 | gtk_pizza_size_allocate (GtkWidget *widget, |
b6fa52db | 528 | GtkAllocation *allocation) |
c801d85f | 529 | { |
da048e3d | 530 | GtkPizza *pizza; |
053f9cc1 | 531 | gint border; |
ed673c6a | 532 | gint x,y,w,h; |
da048e3d | 533 | GtkPizzaChild *child; |
ed673c6a | 534 | GList *children; |
db71eb06 | 535 | gboolean only_resize; |
c801d85f | 536 | |
053f9cc1 | 537 | g_return_if_fail (widget != NULL); |
da048e3d | 538 | g_return_if_fail (GTK_IS_PIZZA(widget)); |
053f9cc1 | 539 | g_return_if_fail (allocation != NULL); |
c801d85f | 540 | |
da048e3d | 541 | pizza = GTK_PIZZA (widget); |
bf3dab48 | 542 | |
db71eb06 RR |
543 | only_resize = ((widget->allocation.x == allocation->x) && |
544 | (widget->allocation.y == allocation->y)); | |
227e5e99 | 545 | widget->allocation = *allocation; |
bf3dab48 | 546 | |
af05af4d | 547 | border = pizza->container.border_width; |
f4322df6 | 548 | |
ed673c6a RR |
549 | x = allocation->x + border; |
550 | y = allocation->y + border; | |
551 | w = allocation->width - border*2; | |
552 | h = allocation->height - border*2; | |
69346023 PC |
553 | if (w < 0) |
554 | w = 0; | |
555 | if (h < 0) | |
556 | h = 0; | |
034be888 | 557 | |
053f9cc1 RR |
558 | if (GTK_WIDGET_REALIZED (widget)) |
559 | { | |
db71eb06 RR |
560 | if (only_resize) |
561 | gdk_window_resize( widget->window, w, h ); | |
562 | else | |
563 | gdk_window_move_resize( widget->window, x, y, w, h ); | |
02ae785a PC |
564 | |
565 | gdk_window_resize( pizza->bin_window, w, h ); | |
053f9cc1 | 566 | } |
bf3dab48 | 567 | |
da048e3d | 568 | children = pizza->children; |
6d693bb4 RR |
569 | while (children) |
570 | { | |
571 | child = children->data; | |
572 | children = children->next; | |
bf3dab48 | 573 | |
da048e3d | 574 | gtk_pizza_allocate_child (pizza, child); |
6d693bb4 | 575 | } |
c801d85f KB |
576 | } |
577 | ||
22aff579 VS |
578 | static void |
579 | gtk_pizza_style_set(GtkWidget *widget, GtkStyle *previous_style) | |
580 | { | |
581 | if (GTK_WIDGET_REALIZED(widget)) | |
582 | { | |
583 | gtk_style_set_background(widget->style, widget->window, GTK_STATE_NORMAL); | |
584 | gtk_style_set_background(widget->style, GTK_PIZZA(widget)->bin_window, GTK_STATE_NORMAL ); | |
585 | } | |
586 | ||
c764029c | 587 | pizza_parent_class->style_set(widget, previous_style); |
22aff579 VS |
588 | } |
589 | ||
c801d85f | 590 | static void |
da048e3d | 591 | gtk_pizza_add (GtkContainer *container, |
bf3dab48 | 592 | GtkWidget *widget) |
c801d85f | 593 | { |
ed673c6a | 594 | g_return_if_fail (container != NULL); |
da048e3d | 595 | g_return_if_fail (GTK_IS_PIZZA (container)); |
ed673c6a | 596 | g_return_if_fail (widget != NULL); |
c801d85f | 597 | |
da048e3d | 598 | gtk_pizza_put (GTK_PIZZA (container), widget, 0, 0, 20, 20 ); |
c801d85f KB |
599 | } |
600 | ||
601 | static void | |
da048e3d | 602 | gtk_pizza_remove (GtkContainer *container, |
b6fa52db | 603 | GtkWidget *widget) |
c801d85f | 604 | { |
da048e3d RR |
605 | GtkPizza *pizza; |
606 | GtkPizzaChild *child; | |
ed673c6a | 607 | GList *children; |
c801d85f | 608 | |
ed673c6a | 609 | g_return_if_fail (container != NULL); |
da048e3d | 610 | g_return_if_fail (GTK_IS_PIZZA (container)); |
ed673c6a | 611 | g_return_if_fail (widget != NULL); |
c801d85f | 612 | |
da048e3d | 613 | pizza = GTK_PIZZA (container); |
c801d85f | 614 | |
da048e3d | 615 | children = pizza->children; |
ed673c6a | 616 | while (children) |
c801d85f | 617 | { |
ed673c6a | 618 | child = children->data; |
c801d85f | 619 | |
ed673c6a | 620 | if (child->widget == widget) |
bf3dab48 VZ |
621 | { |
622 | gtk_widget_unparent (widget); | |
c801d85f | 623 | |
ed673c6a RR |
624 | /* security checks */ |
625 | g_return_if_fail (GTK_IS_WIDGET (widget)); | |
bf3dab48 VZ |
626 | |
627 | pizza->children = g_list_remove_link (pizza->children, children); | |
628 | g_list_free (children); | |
629 | g_free (child); | |
c801d85f | 630 | |
ed673c6a | 631 | /* security checks */ |
bf3dab48 VZ |
632 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
633 | ||
bf3dab48 VZ |
634 | break; |
635 | } | |
c801d85f | 636 | |
ed673c6a | 637 | children = children->next; |
c801d85f KB |
638 | } |
639 | } | |
640 | ||
641 | static void | |
da048e3d | 642 | gtk_pizza_forall (GtkContainer *container, |
b6fa52db RR |
643 | gboolean include_internals, |
644 | GtkCallback callback, | |
645 | gpointer callback_data) | |
c801d85f | 646 | { |
da048e3d RR |
647 | GtkPizza *pizza; |
648 | GtkPizzaChild *child; | |
6d693bb4 | 649 | GList *children; |
c801d85f | 650 | |
6d693bb4 | 651 | g_return_if_fail (container != NULL); |
da048e3d | 652 | g_return_if_fail (GTK_IS_PIZZA (container)); |
90350682 | 653 | g_return_if_fail (callback != (GtkCallback)NULL); |
c801d85f | 654 | |
da048e3d | 655 | pizza = GTK_PIZZA (container); |
c801d85f | 656 | |
da048e3d | 657 | children = pizza->children; |
6d693bb4 | 658 | while (children) |
c801d85f | 659 | { |
6d693bb4 RR |
660 | child = children->data; |
661 | children = children->next; | |
c801d85f | 662 | |
6d693bb4 | 663 | (* callback) (child->widget, callback_data); |
c801d85f KB |
664 | } |
665 | } | |
666 | ||
67d78217 RR |
667 | static void |
668 | gtk_pizza_allocate_child (GtkPizza *pizza, | |
669 | GtkPizzaChild *child) | |
670 | { | |
671 | GtkAllocation allocation; | |
672 | GtkRequisition requisition; | |
c801d85f | 673 | |
a31bb944 RR |
674 | allocation.x = child->x - pizza->m_xoffset; |
675 | allocation.y = child->y - pizza->m_yoffset; | |
67d78217 RR |
676 | gtk_widget_get_child_requisition (child->widget, &requisition); |
677 | allocation.width = requisition.width; | |
678 | allocation.height = requisition.height; | |
679 | ||
db71eb06 RR |
680 | if (gtk_widget_get_direction( GTK_WIDGET(pizza) ) == GTK_TEXT_DIR_RTL) |
681 | { | |
682 | /* reverse horizontal placement */ | |
f4322df6 VZ |
683 | gint offset,border; |
684 | ||
39b5648e | 685 | offset = GTK_WIDGET(pizza)->allocation.width; |
af05af4d | 686 | border = pizza->container.border_width; |
39b5648e | 687 | offset -= border*2; |
f4322df6 VZ |
688 | |
689 | allocation.x = offset - child->x - allocation.width + pizza->m_xoffset; | |
db71eb06 | 690 | } |
f4322df6 | 691 | |
67d78217 RR |
692 | gtk_widget_size_allocate (child->widget, &allocation); |
693 | } | |
ed673c6a | 694 | |
ed673c6a | 695 | static void |
da048e3d | 696 | gtk_pizza_adjust_allocations_recurse (GtkWidget *widget, |
bf3dab48 | 697 | gpointer cb_data) |
ed673c6a | 698 | { |
da048e3d | 699 | GtkPizzaAdjData *data = cb_data; |
ed673c6a | 700 | |
6d693bb4 RR |
701 | widget->allocation.x += data->dx; |
702 | widget->allocation.y += data->dy; | |
ed673c6a | 703 | |
6d693bb4 RR |
704 | if (GTK_WIDGET_NO_WINDOW (widget) && GTK_IS_CONTAINER (widget)) |
705 | { | |
bf3dab48 VZ |
706 | gtk_container_forall (GTK_CONTAINER (widget), |
707 | gtk_pizza_adjust_allocations_recurse, | |
708 | cb_data); | |
6d693bb4 | 709 | } |
ed673c6a RR |
710 | } |
711 | ||
712 | static void | |
da048e3d | 713 | gtk_pizza_adjust_allocations (GtkPizza *pizza, |
bf3dab48 VZ |
714 | gint dx, |
715 | gint dy) | |
ed673c6a | 716 | { |
0e09f76e RR |
717 | GList *tmp_list; |
718 | GtkPizzaAdjData data; | |
ed673c6a | 719 | |
0e09f76e RR |
720 | data.dx = dx; |
721 | data.dy = dy; | |
ed673c6a | 722 | |
0e09f76e RR |
723 | tmp_list = pizza->children; |
724 | while (tmp_list) | |
ed673c6a | 725 | { |
0e09f76e RR |
726 | GtkPizzaChild *child = tmp_list->data; |
727 | tmp_list = tmp_list->next; | |
bf3dab48 | 728 | |
0e09f76e RR |
729 | child->widget->allocation.x += dx; |
730 | child->widget->allocation.y += dy; | |
ed673c6a | 731 | |
0e09f76e RR |
732 | if (GTK_WIDGET_NO_WINDOW (child->widget) && |
733 | GTK_IS_CONTAINER (child->widget)) | |
734 | { | |
735 | gtk_container_forall (GTK_CONTAINER (child->widget), | |
736 | gtk_pizza_adjust_allocations_recurse, | |
737 | &data); | |
738 | } | |
ed673c6a RR |
739 | } |
740 | } | |
bf3dab48 | 741 | |
ed673c6a | 742 | void |
da048e3d | 743 | gtk_pizza_scroll (GtkPizza *pizza, gint dx, gint dy) |
ed673c6a | 744 | { |
a31bb944 RR |
745 | pizza->m_xoffset += dx; |
746 | pizza->m_yoffset += dy; | |
3fc6e5fa RR |
747 | |
748 | gtk_pizza_adjust_allocations (pizza, -dx, -dy); | |
749 | ||
750 | if (pizza->bin_window) | |
751 | gdk_window_scroll( pizza->bin_window, -dx, -dy ); | |
ed673c6a RR |
752 | } |
753 | ||
c801d85f KB |
754 | #ifdef __cplusplus |
755 | } | |
756 | #endif /* __cplusplus */ |