]>
Commit | Line | Data |
---|---|---|
1 | /* /////////////////////////////////////////////////////////////////////////// | |
2 | // Name: win_gtk.c | |
3 | // Purpose: native GTK+ widget for wxWindows | |
4 | // Author: Robert Roebling | |
5 | // Id: $Id$ | |
6 | // Copyright: (c) 1998 Robert Roebling | |
7 | // Licence: wxWindows licence | |
8 | /////////////////////////////////////////////////////////////////////////// */ | |
9 | ||
10 | #include "wx/gtk/win_gtk.h" | |
11 | #include "gtk/gtksignal.h" | |
12 | #include "gtk/gtknotebook.h" | |
13 | #include "gtk/gtkscrolledwindow.h" | |
14 | ||
15 | #ifdef __cplusplus | |
16 | extern "C" { | |
17 | #endif /* __cplusplus */ | |
18 | ||
19 | static void gtk_myfixed_class_init (GtkMyFixedClass *klass); | |
20 | static void gtk_myfixed_init (GtkMyFixed *myfixed); | |
21 | static void gtk_myfixed_map (GtkWidget *widget); | |
22 | #if (GTK_MINOR_VERSION == 0) | |
23 | static void gtk_myfixed_unmap (GtkWidget *widget); | |
24 | #endif | |
25 | static void gtk_myfixed_realize (GtkWidget *widget); | |
26 | static void gtk_myfixed_size_request (GtkWidget *widget, | |
27 | GtkRequisition *requisition); | |
28 | static void gtk_myfixed_size_allocate (GtkWidget *widget, | |
29 | GtkAllocation *allocation); | |
30 | static void gtk_myfixed_paint (GtkWidget *widget, | |
31 | GdkRectangle *area); | |
32 | static void gtk_myfixed_draw (GtkWidget *widget, | |
33 | GdkRectangle *area); | |
34 | static gint gtk_myfixed_expose (GtkWidget *widget, | |
35 | GdkEventExpose *event); | |
36 | static void gtk_myfixed_add (GtkContainer *container, | |
37 | GtkWidget *widget); | |
38 | static void gtk_myfixed_remove (GtkContainer *container, | |
39 | GtkWidget *widget); | |
40 | static void gtk_myfixed_foreach (GtkContainer *container, | |
41 | #if (GTK_MINOR_VERSION > 0) | |
42 | gboolean include_internals, | |
43 | #endif | |
44 | GtkCallback callback, | |
45 | gpointer callback_data); | |
46 | #if (GTK_MINOR_VERSION > 0) | |
47 | static GtkType gtk_myfixed_child_type (GtkContainer *container); | |
48 | #endif | |
49 | ||
50 | #if (GTK_MINOR_VERSION > 0) | |
51 | static void gtk_myfixed_scroll_set_adjustments (GtkMyFixed *myfixed, | |
52 | GtkAdjustment *hadj, | |
53 | GtkAdjustment *vadj); | |
54 | #endif | |
55 | ||
56 | ||
57 | ||
58 | static GtkContainerClass *parent_class = NULL; | |
59 | ||
60 | guint | |
61 | gtk_myfixed_get_type () | |
62 | { | |
63 | static guint myfixed_type = 0; | |
64 | ||
65 | if (!myfixed_type) | |
66 | { | |
67 | GtkTypeInfo myfixed_info = | |
68 | { | |
69 | "GtkMyFixed", | |
70 | sizeof (GtkMyFixed), | |
71 | sizeof (GtkMyFixedClass), | |
72 | (GtkClassInitFunc) gtk_myfixed_class_init, | |
73 | (GtkObjectInitFunc) gtk_myfixed_init, | |
74 | #if (GTK_MINOR_VERSION > 0) | |
75 | /* reserved_1 */ NULL, | |
76 | /* reserved_2 */ NULL, | |
77 | (GtkClassInitFunc) NULL, | |
78 | #else | |
79 | (GtkArgSetFunc) NULL, | |
80 | (GtkArgGetFunc) NULL, | |
81 | #endif | |
82 | }; | |
83 | myfixed_type = gtk_type_unique (gtk_container_get_type (), &myfixed_info); | |
84 | } | |
85 | ||
86 | return myfixed_type; | |
87 | } | |
88 | ||
89 | static void | |
90 | gtk_myfixed_class_init (GtkMyFixedClass *klass) | |
91 | { | |
92 | GtkObjectClass *object_class; | |
93 | GtkWidgetClass *widget_class; | |
94 | GtkContainerClass *container_class; | |
95 | ||
96 | object_class = (GtkObjectClass*) klass; | |
97 | widget_class = (GtkWidgetClass*) klass; | |
98 | container_class = (GtkContainerClass*) klass; | |
99 | ||
100 | #if (GTK_MINOR_VERSION > 0) | |
101 | parent_class = gtk_type_class (GTK_TYPE_CONTAINER); | |
102 | #else | |
103 | parent_class = gtk_type_class (gtk_container_get_type ()); | |
104 | #endif | |
105 | ||
106 | widget_class->map = gtk_myfixed_map; | |
107 | #if (GTK_MINOR_VERSION == 0) | |
108 | widget_class->unmap = gtk_myfixed_unmap; | |
109 | #endif | |
110 | widget_class->realize = gtk_myfixed_realize; | |
111 | widget_class->size_request = gtk_myfixed_size_request; | |
112 | widget_class->size_allocate = gtk_myfixed_size_allocate; | |
113 | widget_class->draw = gtk_myfixed_draw; | |
114 | widget_class->expose_event = gtk_myfixed_expose; | |
115 | ||
116 | container_class->add = gtk_myfixed_add; | |
117 | container_class->remove = gtk_myfixed_remove; | |
118 | #if (GTK_MINOR_VERSION > 0) | |
119 | container_class->forall = gtk_myfixed_foreach; | |
120 | #else | |
121 | container_class->foreach = gtk_myfixed_foreach; | |
122 | #endif | |
123 | ||
124 | #if (GTK_MINOR_VERSION > 0) | |
125 | container_class->child_type = gtk_myfixed_child_type; | |
126 | #endif | |
127 | ||
128 | #if (GTK_MINOR_VERSION > 0) | |
129 | klass->set_scroll_adjustments = gtk_myfixed_scroll_set_adjustments; | |
130 | ||
131 | widget_class->set_scroll_adjustments_signal = | |
132 | gtk_signal_new ("set_scroll_adjustments", | |
133 | GTK_RUN_LAST, | |
134 | object_class->type, | |
135 | GTK_SIGNAL_OFFSET (GtkMyFixedClass, set_scroll_adjustments), | |
136 | gtk_marshal_NONE__POINTER_POINTER, | |
137 | GTK_TYPE_NONE, 2, GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT); | |
138 | #endif | |
139 | } | |
140 | ||
141 | #if (GTK_MINOR_VERSION > 0) | |
142 | static GtkType | |
143 | gtk_myfixed_child_type (GtkContainer *container) | |
144 | { | |
145 | return GTK_TYPE_WIDGET; | |
146 | } | |
147 | #endif | |
148 | ||
149 | static void | |
150 | gtk_myfixed_init (GtkMyFixed *myfixed) | |
151 | { | |
152 | GTK_WIDGET_UNSET_FLAGS (myfixed, GTK_NO_WINDOW); | |
153 | ||
154 | #if (GTK_MINOR_VERSION == 0) | |
155 | GTK_WIDGET_SET_FLAGS (myfixed, GTK_BASIC); | |
156 | #endif | |
157 | ||
158 | #if (GTK_MINOR_VERSION > 0) | |
159 | myfixed->shadow_type = GTK_MYSHADOW_NONE; | |
160 | #endif | |
161 | ||
162 | myfixed->children = NULL; | |
163 | } | |
164 | ||
165 | GtkWidget* | |
166 | gtk_myfixed_new () | |
167 | { | |
168 | GtkMyFixed *myfixed; | |
169 | ||
170 | myfixed = gtk_type_new (gtk_myfixed_get_type ()); | |
171 | ||
172 | return GTK_WIDGET (myfixed); | |
173 | } | |
174 | ||
175 | #if (GTK_MINOR_VERSION > 0) | |
176 | void | |
177 | gtk_myfixed_scroll_set_adjustments (GtkMyFixed *myfixed, | |
178 | GtkAdjustment *hadj, | |
179 | GtkAdjustment *vadj) | |
180 | { | |
181 | /* OK, this is embarassing, but this function has to be here */ | |
182 | } | |
183 | ||
184 | void | |
185 | gtk_myfixed_set_shadow_type (GtkMyFixed *myfixed, | |
186 | GtkMyShadowType type) | |
187 | { | |
188 | g_return_if_fail (myfixed != NULL); | |
189 | g_return_if_fail (GTK_IS_MYFIXED (myfixed)); | |
190 | ||
191 | if ((GtkMyShadowType) myfixed->shadow_type != type) | |
192 | { | |
193 | myfixed->shadow_type = type; | |
194 | ||
195 | if (GTK_WIDGET_VISIBLE (myfixed)) | |
196 | { | |
197 | gtk_widget_size_allocate (GTK_WIDGET (myfixed), &(GTK_WIDGET (myfixed)->allocation)); | |
198 | gtk_widget_queue_draw (GTK_WIDGET (myfixed)); | |
199 | } | |
200 | } | |
201 | } | |
202 | #endif | |
203 | ||
204 | void | |
205 | gtk_myfixed_put (GtkMyFixed *myfixed, | |
206 | GtkWidget *widget, | |
207 | gint16 x, | |
208 | gint16 y, | |
209 | gint16 width, | |
210 | gint16 height) | |
211 | { | |
212 | GtkMyFixedChild *child_info; | |
213 | ||
214 | g_return_if_fail (myfixed != NULL); | |
215 | g_return_if_fail (GTK_IS_MYFIXED (myfixed)); | |
216 | g_return_if_fail (widget != NULL); | |
217 | ||
218 | child_info = g_new (GtkMyFixedChild, 1); | |
219 | child_info->widget = widget; | |
220 | child_info->x = x; | |
221 | child_info->y = y; | |
222 | child_info->width = width; | |
223 | child_info->height = height; | |
224 | ||
225 | gtk_widget_set_parent (widget, GTK_WIDGET (myfixed)); | |
226 | ||
227 | myfixed->children = g_list_append (myfixed->children, child_info); | |
228 | ||
229 | if (GTK_WIDGET_REALIZED (myfixed)) | |
230 | gtk_widget_realize (widget); | |
231 | ||
232 | if (GTK_WIDGET_VISIBLE (myfixed) && GTK_WIDGET_VISIBLE (widget)) | |
233 | { | |
234 | if (GTK_WIDGET_MAPPED (myfixed)) | |
235 | gtk_widget_map (widget); | |
236 | ||
237 | gtk_widget_queue_resize (GTK_WIDGET (myfixed)); | |
238 | } | |
239 | } | |
240 | ||
241 | void | |
242 | gtk_myfixed_move (GtkMyFixed *myfixed, | |
243 | GtkWidget *widget, | |
244 | gint16 x, | |
245 | gint16 y) | |
246 | { | |
247 | GtkMyFixedChild *child; | |
248 | GList *children; | |
249 | ||
250 | g_return_if_fail (myfixed != NULL); | |
251 | g_return_if_fail (GTK_IS_MYFIXED (myfixed)); | |
252 | g_return_if_fail (widget != NULL); | |
253 | ||
254 | children = myfixed->children; | |
255 | while (children) | |
256 | { | |
257 | child = children->data; | |
258 | children = children->next; | |
259 | ||
260 | if (child->widget == widget) | |
261 | { | |
262 | gtk_myfixed_set_size( myfixed, widget, x, y, child->width, child->height ); | |
263 | break; | |
264 | } | |
265 | } | |
266 | } | |
267 | ||
268 | void | |
269 | gtk_myfixed_resize (GtkMyFixed *myfixed, | |
270 | GtkWidget *widget, | |
271 | gint16 width, | |
272 | gint16 height) | |
273 | { | |
274 | GtkMyFixedChild *child; | |
275 | GList *children; | |
276 | ||
277 | g_return_if_fail (myfixed != NULL); | |
278 | g_return_if_fail (GTK_IS_MYFIXED (myfixed)); | |
279 | g_return_if_fail (widget != NULL); | |
280 | ||
281 | children = myfixed->children; | |
282 | while (children) | |
283 | { | |
284 | child = children->data; | |
285 | children = children->next; | |
286 | ||
287 | if (child->widget == widget) | |
288 | { | |
289 | gtk_myfixed_set_size( myfixed, widget, child->x, child->y, width, height ); | |
290 | break; | |
291 | } | |
292 | } | |
293 | } | |
294 | ||
295 | void | |
296 | gtk_myfixed_set_size (GtkMyFixed *myfixed, | |
297 | GtkWidget *widget, | |
298 | gint16 x, | |
299 | gint16 y, | |
300 | gint16 width, | |
301 | gint16 height) | |
302 | { | |
303 | GtkMyFixedChild *child; | |
304 | GList *children; | |
305 | GtkAllocation child_allocation; | |
306 | ||
307 | g_return_if_fail (myfixed != NULL); | |
308 | g_return_if_fail (GTK_IS_MYFIXED (myfixed)); | |
309 | g_return_if_fail (widget != NULL); | |
310 | ||
311 | children = myfixed->children; | |
312 | while (children) | |
313 | { | |
314 | child = children->data; | |
315 | children = children->next; | |
316 | ||
317 | if (child->widget == widget) | |
318 | { | |
319 | if ((child->x == x) && | |
320 | (child->y == y) && | |
321 | (child->width == width) && | |
322 | (child->height == height)) return; | |
323 | ||
324 | child->x = x; | |
325 | child->y = y; | |
326 | child->width = width; | |
327 | child->height = height; | |
328 | ||
329 | if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (myfixed)) | |
330 | { | |
331 | if ( (child->width > 1) && | |
332 | (child->height > 1) && | |
333 | !(GTK_WIDGET_REALIZED(widget) && GTK_IS_NOTEBOOK(widget)) ) | |
334 | { | |
335 | child_allocation.x = child->x; | |
336 | child_allocation.y = child->y; | |
337 | child_allocation.width = MAX( child->width, 1 ); | |
338 | child_allocation.height = MAX( child->height, 1 ); | |
339 | ||
340 | /* work around for GTK bug when moving widgets outside | |
341 | the X window -> do NOT move them entirely outside */ | |
342 | if (child_allocation.y + child_allocation.height < 0) | |
343 | child_allocation.y = -child_allocation.height; | |
344 | if (child_allocation.x + child_allocation.width < 0) | |
345 | child_allocation.x = -child_allocation.width; | |
346 | ||
347 | gtk_widget_size_allocate (widget, &child_allocation); | |
348 | } | |
349 | else | |
350 | { | |
351 | gtk_widget_queue_resize (GTK_WIDGET (myfixed)); | |
352 | } | |
353 | } | |
354 | break; | |
355 | } | |
356 | } | |
357 | } | |
358 | ||
359 | static void | |
360 | gtk_myfixed_map (GtkWidget *widget) | |
361 | { | |
362 | GtkMyFixed *myfixed; | |
363 | GtkMyFixedChild *child; | |
364 | GList *children; | |
365 | ||
366 | g_return_if_fail (widget != NULL); | |
367 | g_return_if_fail (GTK_IS_MYFIXED (widget)); | |
368 | ||
369 | GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED); | |
370 | myfixed = GTK_MYFIXED (widget); | |
371 | ||
372 | children = myfixed->children; | |
373 | while (children) | |
374 | { | |
375 | child = children->data; | |
376 | children = children->next; | |
377 | ||
378 | if (GTK_WIDGET_VISIBLE (child->widget) && !GTK_WIDGET_MAPPED (child->widget)) | |
379 | gtk_widget_map (child->widget); | |
380 | } | |
381 | ||
382 | gdk_window_show (widget->window); | |
383 | } | |
384 | ||
385 | #if (GTK_MINOR_VERSION == 0) | |
386 | static void | |
387 | gtk_myfixed_unmap (GtkWidget *widget) | |
388 | { | |
389 | g_return_if_fail (widget != NULL); | |
390 | g_return_if_fail (GTK_IS_MYFIXED (widget)); | |
391 | ||
392 | GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED); | |
393 | } | |
394 | #endif | |
395 | ||
396 | static void | |
397 | gtk_myfixed_realize (GtkWidget *widget) | |
398 | { | |
399 | GtkMyFixed *myfixed; | |
400 | GdkWindowAttr attributes; | |
401 | gint attributes_mask; | |
402 | ||
403 | g_return_if_fail (widget != NULL); | |
404 | g_return_if_fail (GTK_IS_MYFIXED (widget)); | |
405 | ||
406 | myfixed = GTK_MYFIXED (widget); | |
407 | ||
408 | GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); | |
409 | ||
410 | attributes.window_type = GDK_WINDOW_CHILD; | |
411 | ||
412 | #if (GTK_MINOR_VERSION > 0) | |
413 | attributes.x = widget->allocation.x; | |
414 | attributes.y = widget->allocation.y; | |
415 | attributes.width = widget->allocation.width; | |
416 | attributes.height = widget->allocation.height; | |
417 | ||
418 | if (myfixed->shadow_type == GTK_MYSHADOW_NONE) | |
419 | { | |
420 | /* no border, no changes to sizes */ | |
421 | } else | |
422 | if (myfixed->shadow_type == GTK_MYSHADOW_THIN) | |
423 | { | |
424 | /* GTK_MYSHADOW_THIN == wxSIMPLE_BORDER */ | |
425 | attributes.x += 1; | |
426 | attributes.y += 1; | |
427 | attributes.width -= 2; | |
428 | attributes.height -= 2; | |
429 | } else | |
430 | { | |
431 | /* GTK_MYSHADOW_IN == wxSUNKEN_BORDER */ | |
432 | /* GTK_MYSHADOW_OUT == wxRAISED_BORDER */ | |
433 | attributes.x += 2; | |
434 | attributes.y += 2; | |
435 | attributes.width -= 4; | |
436 | attributes.height -= 4; | |
437 | } | |
438 | ||
439 | if (attributes.width < 2) attributes.width = 2; | |
440 | if (attributes.height < 2) attributes.height = 2; | |
441 | #else | |
442 | attributes.x = widget->allocation.x; | |
443 | attributes.y = widget->allocation.y; | |
444 | attributes.width = 32000; | |
445 | attributes.height = 32000; | |
446 | #endif | |
447 | attributes.wclass = GDK_INPUT_OUTPUT; | |
448 | attributes.visual = gtk_widget_get_visual (widget); | |
449 | attributes.colormap = gtk_widget_get_colormap (widget); | |
450 | attributes.event_mask = gtk_widget_get_events (widget); | |
451 | attributes.event_mask |= | |
452 | GDK_EXPOSURE_MASK | | |
453 | GDK_POINTER_MOTION_MASK | | |
454 | GDK_POINTER_MOTION_HINT_MASK | | |
455 | GDK_BUTTON_MOTION_MASK | | |
456 | GDK_BUTTON1_MOTION_MASK | | |
457 | GDK_BUTTON2_MOTION_MASK | | |
458 | GDK_BUTTON3_MOTION_MASK | | |
459 | GDK_BUTTON_PRESS_MASK | | |
460 | GDK_BUTTON_RELEASE_MASK | | |
461 | GDK_KEY_PRESS_MASK | | |
462 | GDK_KEY_RELEASE_MASK | | |
463 | GDK_ENTER_NOTIFY_MASK | | |
464 | GDK_LEAVE_NOTIFY_MASK | | |
465 | GDK_FOCUS_CHANGE_MASK; | |
466 | attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; | |
467 | ||
468 | widget->window = gdk_window_new( gtk_widget_get_parent_window (widget), &attributes, | |
469 | attributes_mask); | |
470 | gdk_window_set_user_data (widget->window, widget); | |
471 | ||
472 | widget->style = gtk_style_attach (widget->style, widget->window); | |
473 | gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); | |
474 | } | |
475 | ||
476 | static void | |
477 | gtk_myfixed_size_request (GtkWidget *widget, | |
478 | GtkRequisition *requisition) | |
479 | { | |
480 | GtkMyFixed *myfixed; | |
481 | GtkMyFixedChild *child; | |
482 | GList *children; | |
483 | GtkRequisition child_requisition; | |
484 | ||
485 | g_return_if_fail (widget != NULL); | |
486 | g_return_if_fail (GTK_IS_MYFIXED (widget)); | |
487 | g_return_if_fail (requisition != NULL); | |
488 | ||
489 | myfixed = GTK_MYFIXED (widget); | |
490 | ||
491 | children = myfixed->children; | |
492 | while (children) | |
493 | { | |
494 | child = children->data; | |
495 | children = children->next; | |
496 | ||
497 | if (GTK_WIDGET_VISIBLE (child->widget)) | |
498 | { | |
499 | gtk_widget_size_request (child->widget, &child_requisition); | |
500 | } | |
501 | } | |
502 | ||
503 | /* request very little, I'm not sure if requesting nothing | |
504 | will always have positive effects on stability... */ | |
505 | requisition->width = 2; | |
506 | requisition->height = 2; | |
507 | } | |
508 | ||
509 | static void | |
510 | gtk_myfixed_size_allocate (GtkWidget *widget, | |
511 | GtkAllocation *allocation) | |
512 | { | |
513 | GtkMyFixed *myfixed; | |
514 | gint border; | |
515 | GtkMyFixedChild *child; | |
516 | GtkAllocation child_allocation; | |
517 | GList *children; | |
518 | ||
519 | g_return_if_fail (widget != NULL); | |
520 | g_return_if_fail (GTK_IS_MYFIXED(widget)); | |
521 | g_return_if_fail (allocation != NULL); | |
522 | ||
523 | myfixed = GTK_MYFIXED (widget); | |
524 | ||
525 | widget->allocation = *allocation; | |
526 | #if (GTK_MINOR_VERSION > 0) | |
527 | if (myfixed->shadow_type == GTK_MYSHADOW_NONE) | |
528 | border = 0; | |
529 | else | |
530 | if (myfixed->shadow_type == GTK_MYSHADOW_THIN) | |
531 | border = 1; | |
532 | else | |
533 | border = 2; | |
534 | #else | |
535 | border = 0; | |
536 | #endif | |
537 | ||
538 | if (GTK_WIDGET_REALIZED (widget)) | |
539 | { | |
540 | gdk_window_move_resize( widget->window, | |
541 | allocation->x+border, allocation->y+border, | |
542 | #if (GTK_MINOR_VERSION > 0) | |
543 | allocation->width-border*2, allocation->height-border*2 | |
544 | #else | |
545 | 32000, 32000 | |
546 | #endif | |
547 | ); | |
548 | } | |
549 | ||
550 | children = myfixed->children; | |
551 | while (children) | |
552 | { | |
553 | child = children->data; | |
554 | children = children->next; | |
555 | ||
556 | if (GTK_WIDGET_VISIBLE (child->widget)) | |
557 | { | |
558 | /* please look at the text in wxWindow::DoSetSize() on why the | |
559 | test GTK_WIDGET_REALIZED() has to be here */ | |
560 | /* if (GTK_IS_NOTEBOOK(child->widget) && !GTK_WIDGET_REALIZED(child->widget)) | |
561 | { | |
562 | gtk_widget_queue_resize( child->widget ); | |
563 | } | |
564 | else */ | |
565 | { | |
566 | child_allocation.x = child->x; | |
567 | child_allocation.y = child->y; | |
568 | child_allocation.width = MAX( child->width, 1 ); | |
569 | child_allocation.height = MAX( child->height, 1 ); | |
570 | ||
571 | /* work around for GTK bug when moving widgets outside | |
572 | the X window -> do NOT move them entirely outside */ | |
573 | if (child_allocation.y + child_allocation.height < 0) | |
574 | child_allocation.y = -child_allocation.height; | |
575 | if (child_allocation.x + child_allocation.width < 0) | |
576 | child_allocation.x = -child_allocation.width; | |
577 | ||
578 | gtk_widget_size_allocate (child->widget, &child_allocation); | |
579 | } | |
580 | } | |
581 | } | |
582 | } | |
583 | ||
584 | static void | |
585 | gtk_myfixed_paint (GtkWidget *widget, | |
586 | GdkRectangle *area) | |
587 | { | |
588 | g_return_if_fail (widget != NULL); | |
589 | g_return_if_fail (GTK_IS_MYFIXED (widget)); | |
590 | g_return_if_fail (area != NULL); | |
591 | ||
592 | if (GTK_WIDGET_DRAWABLE (widget)) | |
593 | gdk_window_clear_area (widget->window, | |
594 | area->x, area->y, | |
595 | area->width, area->height); | |
596 | } | |
597 | ||
598 | static void | |
599 | gtk_myfixed_draw (GtkWidget *widget, | |
600 | GdkRectangle *area) | |
601 | { | |
602 | GtkMyFixed *myfixed; | |
603 | GtkMyFixedChild *child; | |
604 | GdkRectangle child_area; | |
605 | GList *children; | |
606 | ||
607 | g_return_if_fail (widget != NULL); | |
608 | g_return_if_fail (GTK_IS_MYFIXED (widget)); | |
609 | ||
610 | if (GTK_WIDGET_DRAWABLE (widget)) | |
611 | { | |
612 | myfixed = GTK_MYFIXED (widget); | |
613 | ||
614 | children = myfixed->children; | |
615 | if (children) /* mini optimisation */ | |
616 | gtk_myfixed_paint (widget, area); | |
617 | ||
618 | while (children) | |
619 | { | |
620 | child = children->data; | |
621 | children = children->next; | |
622 | ||
623 | if (gtk_widget_intersect (child->widget, area, &child_area)) | |
624 | gtk_widget_draw (child->widget, &child_area); | |
625 | } | |
626 | } | |
627 | } | |
628 | ||
629 | static gint | |
630 | gtk_myfixed_expose (GtkWidget *widget, | |
631 | GdkEventExpose *event) | |
632 | { | |
633 | GtkMyFixed *myfixed; | |
634 | GtkMyFixedChild *child; | |
635 | GdkEventExpose child_event; | |
636 | GList *children; | |
637 | ||
638 | g_return_val_if_fail (widget != NULL, FALSE); | |
639 | g_return_val_if_fail (GTK_IS_MYFIXED (widget), FALSE); | |
640 | g_return_val_if_fail (event != NULL, FALSE); | |
641 | ||
642 | if (GTK_WIDGET_DRAWABLE (widget)) | |
643 | { | |
644 | myfixed = GTK_MYFIXED (widget); | |
645 | ||
646 | child_event = *event; | |
647 | ||
648 | children = myfixed->children; | |
649 | while (children) | |
650 | { | |
651 | child = children->data; | |
652 | children = children->next; | |
653 | ||
654 | if (GTK_WIDGET_NO_WINDOW (child->widget) && | |
655 | gtk_widget_intersect (child->widget, &event->area, | |
656 | &child_event.area)) | |
657 | gtk_widget_event (child->widget, (GdkEvent*) &child_event); | |
658 | } | |
659 | } | |
660 | ||
661 | return FALSE; | |
662 | } | |
663 | ||
664 | static void | |
665 | gtk_myfixed_add (GtkContainer *container, | |
666 | GtkWidget *widget) | |
667 | { | |
668 | g_return_if_fail (container != NULL); | |
669 | g_return_if_fail (GTK_IS_MYFIXED (container)); | |
670 | g_return_if_fail (widget != NULL); | |
671 | ||
672 | gtk_myfixed_put (GTK_MYFIXED (container), widget, 0, 0, 20, 20 ); | |
673 | } | |
674 | ||
675 | static void | |
676 | gtk_myfixed_remove (GtkContainer *container, | |
677 | GtkWidget *widget) | |
678 | { | |
679 | GtkMyFixed *myfixed; | |
680 | GtkMyFixedChild *child; | |
681 | GList *children; | |
682 | ||
683 | g_return_if_fail (container != NULL); | |
684 | g_return_if_fail (GTK_IS_MYFIXED (container)); | |
685 | g_return_if_fail (widget != NULL); | |
686 | ||
687 | myfixed = GTK_MYFIXED (container); | |
688 | ||
689 | children = myfixed->children; | |
690 | while (children) | |
691 | { | |
692 | child = children->data; | |
693 | ||
694 | if (child->widget == widget) | |
695 | { | |
696 | gboolean was_visible = GTK_WIDGET_VISIBLE (widget); | |
697 | ||
698 | gtk_widget_unparent (widget); | |
699 | ||
700 | /* security checks */ | |
701 | g_return_if_fail (GTK_IS_WIDGET (widget)); | |
702 | ||
703 | myfixed->children = g_list_remove_link (myfixed->children, children); | |
704 | g_list_free (children); | |
705 | g_free (child); | |
706 | ||
707 | if (was_visible && GTK_WIDGET_VISIBLE (container)) | |
708 | gtk_widget_queue_resize (GTK_WIDGET (container)); | |
709 | ||
710 | /* security checks */ | |
711 | g_return_if_fail (GTK_IS_WIDGET (widget)); | |
712 | ||
713 | break; | |
714 | } | |
715 | ||
716 | children = children->next; | |
717 | } | |
718 | } | |
719 | ||
720 | static void | |
721 | gtk_myfixed_foreach (GtkContainer *container, | |
722 | #if (GTK_MINOR_VERSION > 0) | |
723 | gboolean include_internals, | |
724 | #endif | |
725 | GtkCallback callback, | |
726 | gpointer callback_data) | |
727 | { | |
728 | GtkMyFixed *myfixed; | |
729 | GtkMyFixedChild *child; | |
730 | GList *children; | |
731 | ||
732 | g_return_if_fail (container != NULL); | |
733 | g_return_if_fail (GTK_IS_MYFIXED (container)); | |
734 | g_return_if_fail (callback != NULL); | |
735 | ||
736 | myfixed = GTK_MYFIXED (container); | |
737 | ||
738 | children = myfixed->children; | |
739 | while (children) | |
740 | { | |
741 | child = children->data; | |
742 | children = children->next; | |
743 | ||
744 | (* callback) (child->widget, callback_data); | |
745 | } | |
746 | } | |
747 | ||
748 | ||
749 | #ifdef __cplusplus | |
750 | } | |
751 | #endif /* __cplusplus */ | |
752 |