]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/win_gtk.c
some feeble attempts at making wxBeginBusyCursor work
[wxWidgets.git] / src / gtk1 / win_gtk.c
CommitLineData
c67daf87 1/* ///////////////////////////////////////////////////////////////////////////
c67d8618 2// Name: win_gtk.c
01111366 3// Purpose: native GTK+ widget for wxWindows
c801d85f 4// Author: Robert Roebling
c67d8618 5// Id: $Id$
01111366 6// Copyright: (c) 1998 Robert Roebling
c801d85f 7// Licence: wxWindows licence
c67daf87 8/////////////////////////////////////////////////////////////////////////// */
c801d85f
KB
9
10#include "wx/gtk/win_gtk.h"
75ed1d15 11#include <gtk/gtkfeatures.h>
c801d85f 12
38c7b3d3
RR
13/*-------------------------------------------------------------------------
14// conditional compilation
15//------------------------------------------------------------------------- */
16
17#if (GTK_MINOR_VERSION == 1)
18#if (GTK_MICRO_VERSION >= 5)
19#define NEW_GTK_CONSTRUCT_CODE
20#endif
21#endif
22
c801d85f
KB
23#ifdef __cplusplus
24extern "C" {
25#endif /* __cplusplus */
26
27static void gtk_myfixed_class_init (GtkMyFixedClass *klass);
28static void gtk_myfixed_init (GtkMyFixed *myfixed);
29static void gtk_myfixed_map (GtkWidget *widget);
38c7b3d3 30#ifndef NEW_GTK_CONSTRUCT_CODE
c801d85f 31static void gtk_myfixed_unmap (GtkWidget *widget);
38c7b3d3 32#endif
c801d85f
KB
33static void gtk_myfixed_realize (GtkWidget *widget);
34static void gtk_myfixed_size_request (GtkWidget *widget,
35 GtkRequisition *requisition);
36static void gtk_myfixed_size_allocate (GtkWidget *widget,
37 GtkAllocation *allocation);
38static void gtk_myfixed_paint (GtkWidget *widget,
39 GdkRectangle *area);
40static void gtk_myfixed_draw (GtkWidget *widget,
41 GdkRectangle *area);
42static gint gtk_myfixed_expose (GtkWidget *widget,
43 GdkEventExpose *event);
44static void gtk_myfixed_add (GtkContainer *container,
45 GtkWidget *widget);
46static void gtk_myfixed_remove (GtkContainer *container,
47 GtkWidget *widget);
48static void gtk_myfixed_foreach (GtkContainer *container,
75ed1d15
GL
49#if (GTK_MINOR_VERSION == 1)
50 gboolean include_internals,
51#endif
c801d85f
KB
52 GtkCallback callback,
53 gpointer callback_data);
38c7b3d3
RR
54#ifdef NEW_GTK_CONSTRUCT_CODE
55static GtkType gtk_myfixed_child_type (GtkContainer *container);
56#endif
c801d85f
KB
57
58
59static GtkContainerClass *parent_class = NULL;
60
61
62guint
63gtk_myfixed_get_type ()
64{
65 static guint myfixed_type = 0;
66
67 if (!myfixed_type)
68 {
69 GtkTypeInfo myfixed_info =
70 {
71 "GtkMyFixed",
72 sizeof (GtkMyFixed),
73 sizeof (GtkMyFixedClass),
74 (GtkClassInitFunc) gtk_myfixed_class_init,
75 (GtkObjectInitFunc) gtk_myfixed_init,
38c7b3d3
RR
76#ifndef NEW_GTK_CONSTRUCT_CODE
77 (GtkArgSetFunc) NULL,
c801d85f 78 (GtkArgGetFunc) NULL,
38c7b3d3
RR
79#else
80 /* reserved_1 */ NULL,
81 /* reserved_2 */ NULL,
82 (GtkClassInitFunc) NULL,
83#endif
c801d85f
KB
84 };
85
86 myfixed_type = gtk_type_unique (gtk_container_get_type (), &myfixed_info);
87 }
88
89 return myfixed_type;
90}
91
92static void
93gtk_myfixed_class_init (GtkMyFixedClass *klass)
94{
95 GtkObjectClass *object_class;
96 GtkWidgetClass *widget_class;
97 GtkContainerClass *container_class;
98
99 object_class = (GtkObjectClass*) klass;
100 widget_class = (GtkWidgetClass*) klass;
101 container_class = (GtkContainerClass*) klass;
f5368809 102
38c7b3d3 103#ifndef NEW_GTK_CONSTRUCT_CODE
c801d85f 104 parent_class = gtk_type_class (gtk_container_get_type ());
38c7b3d3
RR
105#else
106 parent_class = gtk_type_class (GTK_TYPE_CONTAINER);
107#endif
c801d85f
KB
108
109 widget_class->map = gtk_myfixed_map;
38c7b3d3 110#ifndef NEW_GTK_CONSTRUCT_CODE
c801d85f 111 widget_class->unmap = gtk_myfixed_unmap;
38c7b3d3 112#endif
c801d85f
KB
113 widget_class->realize = gtk_myfixed_realize;
114 widget_class->size_request = gtk_myfixed_size_request;
115 widget_class->size_allocate = gtk_myfixed_size_allocate;
116 widget_class->draw = gtk_myfixed_draw;
117 widget_class->expose_event = gtk_myfixed_expose;
118
119 container_class->add = gtk_myfixed_add;
120 container_class->remove = gtk_myfixed_remove;
75ed1d15
GL
121#if (GTK_MINOR_VERSION == 1)
122 container_class->forall = gtk_myfixed_foreach;
123#else
c801d85f 124 container_class->foreach = gtk_myfixed_foreach;
75ed1d15 125#endif
38c7b3d3
RR
126
127#ifdef NEW_GTK_CONSTRUCT_CODE
128 container_class->child_type = gtk_myfixed_child_type;
129#endif
130}
131
132#ifdef NEW_GTK_CONSTRUCT_CODE
133static GtkType
134gtk_myfixed_child_type (GtkContainer *container)
135{
136 return GTK_TYPE_WIDGET;
c801d85f 137}
38c7b3d3 138#endif
c801d85f
KB
139
140static void
141gtk_myfixed_init (GtkMyFixed *myfixed)
142{
143 GTK_WIDGET_UNSET_FLAGS (myfixed, GTK_NO_WINDOW);
38c7b3d3
RR
144
145#ifndef NEW_GTK_CONSTRUCT_CODE
c801d85f 146 GTK_WIDGET_SET_FLAGS (myfixed, GTK_BASIC);
38c7b3d3 147#endif
f5368809 148
c801d85f
KB
149 myfixed->children = NULL;
150}
151
152GtkWidget*
153gtk_myfixed_new ()
154{
155 GtkMyFixed *myfixed;
156
157 myfixed = gtk_type_new (gtk_myfixed_get_type ());
158
c801d85f
KB
159 return GTK_WIDGET (myfixed);
160}
161
c801d85f
KB
162void
163gtk_myfixed_put (GtkMyFixed *myfixed,
164 GtkWidget *widget,
165 gint16 x,
166 gint16 y)
167{
168 GtkMyFixedChild *child_info;
169
170 g_return_if_fail (myfixed != NULL);
171 g_return_if_fail (GTK_IS_MYFIXED (myfixed));
172 g_return_if_fail (widget != NULL);
173
174 child_info = g_new (GtkMyFixedChild, 1);
175 child_info->widget = widget;
11026f7b
RR
176 child_info->x = x;
177 child_info->y = y;
d4c99d6f 178
c801d85f
KB
179 gtk_widget_set_parent (widget, GTK_WIDGET (myfixed));
180
181 myfixed->children = g_list_append (myfixed->children, child_info);
182
183 if (GTK_WIDGET_REALIZED (myfixed) && !GTK_WIDGET_REALIZED (widget))
184 gtk_widget_realize (widget);
185
186 if (GTK_WIDGET_MAPPED (myfixed) && !GTK_WIDGET_MAPPED (widget))
187 gtk_widget_map (widget);
188
189 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (myfixed))
190 gtk_widget_queue_resize (GTK_WIDGET (myfixed));
191}
192
193void
194gtk_myfixed_move (GtkMyFixed *myfixed,
195 GtkWidget *widget,
196 gint16 x,
197 gint16 y)
198{
199 GtkMyFixedChild *child;
200 GList *children;
201
202 g_return_if_fail (myfixed != NULL);
203 g_return_if_fail (GTK_IS_MYFIXED (myfixed));
204 g_return_if_fail (widget != NULL);
205
206 children = myfixed->children;
207 while (children)
208 {
209 child = children->data;
210 children = children->next;
211
212 if (child->widget == widget)
213 {
463c1fa1 214 if ((child->x == x) && (child->y == y)) return;
fb1585ae 215
11026f7b
RR
216 child->x = x;
217 child->y = y;
c801d85f
KB
218
219 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (myfixed))
220 gtk_widget_queue_resize (GTK_WIDGET (myfixed));
221
222 break;
223 }
224 }
225}
226
227static void
228gtk_myfixed_map (GtkWidget *widget)
229{
230 GtkMyFixed *myfixed;
231 GtkMyFixedChild *child;
232 GList *children;
233
234 g_return_if_fail (widget != NULL);
235 g_return_if_fail (GTK_IS_MYFIXED (widget));
236
237 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
238 myfixed = GTK_MYFIXED (widget);
239
240 gdk_window_show (widget->window);
241
242 children = myfixed->children;
243 while (children)
244 {
245 child = children->data;
246 children = children->next;
247
248 if (GTK_WIDGET_VISIBLE (child->widget) &&
249 !GTK_WIDGET_MAPPED (child->widget))
250 gtk_widget_map (child->widget);
251 }
252}
253
38c7b3d3 254#ifndef NEW_GTK_CONSTRUCT_CODE
c801d85f
KB
255static void
256gtk_myfixed_unmap (GtkWidget *widget)
257{
258 g_return_if_fail (widget != NULL);
259 g_return_if_fail (GTK_IS_MYFIXED (widget));
260
261 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
262}
38c7b3d3 263#endif
c801d85f
KB
264
265static void
266gtk_myfixed_realize (GtkWidget *widget)
267{
d4c99d6f 268 GtkMyFixed *myfixed;
c801d85f
KB
269 GdkWindowAttr attributes;
270 gint attributes_mask;
271
272 g_return_if_fail (widget != NULL);
273 g_return_if_fail (GTK_IS_MYFIXED (widget));
274
d4c99d6f
RR
275 myfixed = GTK_MYFIXED (widget);
276
c801d85f
KB
277 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
278
279 attributes.window_type = GDK_WINDOW_CHILD;
11026f7b
RR
280 attributes.x = widget->allocation.x;
281 attributes.y = widget->allocation.y;
c801d85f
KB
282 attributes.width = 32000;
283 attributes.height = 32000;
284 attributes.wclass = GDK_INPUT_OUTPUT;
285 attributes.visual = gtk_widget_get_visual (widget);
286 attributes.colormap = gtk_widget_get_colormap (widget);
287 attributes.event_mask = gtk_widget_get_events (widget);
288 attributes.event_mask |=
289 GDK_EXPOSURE_MASK |
290 GDK_POINTER_MOTION_MASK |
aae24d21 291 GDK_POINTER_MOTION_HINT_MASK |
c801d85f
KB
292 GDK_BUTTON_MOTION_MASK |
293 GDK_BUTTON1_MOTION_MASK |
294 GDK_BUTTON2_MOTION_MASK |
295 GDK_BUTTON3_MOTION_MASK |
296 GDK_BUTTON_PRESS_MASK |
297 GDK_BUTTON_RELEASE_MASK |
298 GDK_KEY_PRESS_MASK |
299 GDK_KEY_RELEASE_MASK |
300 GDK_ENTER_NOTIFY_MASK |
301 GDK_LEAVE_NOTIFY_MASK |
302 GDK_FOCUS_CHANGE_MASK;
303
304 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
305
306 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes,
307 attributes_mask);
308 gdk_window_set_user_data (widget->window, widget);
309
310 widget->style = gtk_style_attach (widget->style, widget->window);
311 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
312}
313
314static void
315gtk_myfixed_size_request (GtkWidget *widget,
316 GtkRequisition *requisition)
317{
318 GtkMyFixed *myfixed;
319 GtkMyFixedChild *child;
320 GList *children;
321
322 g_return_if_fail (widget != NULL);
323 g_return_if_fail (GTK_IS_MYFIXED (widget));
324 g_return_if_fail (requisition != NULL);
325
326 myfixed = GTK_MYFIXED (widget);
327
328 requisition->width = 0;
329 requisition->height = 0;
330
331 children = myfixed->children;
332 while (children)
333 {
334 child = children->data;
335 children = children->next;
336
337 if (GTK_WIDGET_VISIBLE (child->widget))
338 {
339 gtk_widget_size_request (child->widget, &child->widget->requisition);
340 }
341 }
342}
343
344static void
345gtk_myfixed_size_allocate (GtkWidget *widget,
346 GtkAllocation *allocation)
347{
348 GtkMyFixed *myfixed;
349 GtkMyFixedChild *child;
350 GtkAllocation child_allocation;
351 GList *children;
352 guint16 border_width;
353
354 g_return_if_fail (widget != NULL);
355 g_return_if_fail (GTK_IS_MYFIXED(widget));
356 g_return_if_fail (allocation != NULL);
357
358 myfixed = GTK_MYFIXED (widget);
359
360 widget->allocation = *allocation;
361 if (GTK_WIDGET_REALIZED (widget))
11026f7b 362 gdk_window_move_resize (widget->window, allocation->x, allocation->y, 32000, 32000 );
c801d85f
KB
363
364 border_width = GTK_CONTAINER (myfixed)->border_width;
365
366 children = myfixed->children;
367 while (children)
368 {
369 child = children->data;
370 children = children->next;
371
372 if (GTK_WIDGET_VISIBLE (child->widget))
373 {
374 child_allocation.x = child->x + border_width;
375 child_allocation.y = child->y + border_width;
376 child_allocation.width = child->widget->requisition.width;
377 child_allocation.height = child->widget->requisition.height;
378 gtk_widget_size_allocate (child->widget, &child_allocation);
379 }
380 }
381}
382
383static void
384gtk_myfixed_paint (GtkWidget *widget,
385 GdkRectangle *area)
386{
387 g_return_if_fail (widget != NULL);
388 g_return_if_fail (GTK_IS_MYFIXED (widget));
389 g_return_if_fail (area != NULL);
390
391 if (GTK_WIDGET_DRAWABLE (widget))
392 gdk_window_clear_area (widget->window,
393 area->x, area->y,
394 area->width, area->height);
395}
396
397static void
398gtk_myfixed_draw (GtkWidget *widget,
399 GdkRectangle *area)
400{
401 GtkMyFixed *myfixed;
402 GtkMyFixedChild *child;
403 GdkRectangle child_area;
404 GList *children;
405
406 g_return_if_fail (widget != NULL);
407 g_return_if_fail (GTK_IS_MYFIXED (widget));
408
409 if (GTK_WIDGET_DRAWABLE (widget))
410 {
411 myfixed = GTK_MYFIXED (widget);
412 gtk_myfixed_paint (widget, area);
413
414 children = myfixed->children;
415 while (children)
416 {
417 child = children->data;
418 children = children->next;
419
420 if (gtk_widget_intersect (child->widget, area, &child_area))
421 gtk_widget_draw (child->widget, &child_area);
422 }
423 }
424}
425
426static gint
427gtk_myfixed_expose (GtkWidget *widget,
428 GdkEventExpose *event)
429{
430 GtkMyFixed *myfixed;
431 GtkMyFixedChild *child;
432 GdkEventExpose child_event;
433 GList *children;
434
435 g_return_val_if_fail (widget != NULL, FALSE);
436 g_return_val_if_fail (GTK_IS_MYFIXED (widget), FALSE);
437 g_return_val_if_fail (event != NULL, FALSE);
438
439 if (GTK_WIDGET_DRAWABLE (widget))
440 {
441 myfixed = GTK_MYFIXED (widget);
442
443 child_event = *event;
444
445 children = myfixed->children;
446 while (children)
447 {
448 child = children->data;
449 children = children->next;
450
451 if (GTK_WIDGET_NO_WINDOW (child->widget) &&
452 gtk_widget_intersect (child->widget, &event->area,
453 &child_event.area))
454 gtk_widget_event (child->widget, (GdkEvent*) &child_event);
455 }
456 }
457
458 return FALSE;
459}
460
461static void
462gtk_myfixed_add (GtkContainer *container,
463 GtkWidget *widget)
464{
465 g_return_if_fail (container != NULL);
466 g_return_if_fail (GTK_IS_MYFIXED (container));
467 g_return_if_fail (widget != NULL);
468
469 gtk_myfixed_put (GTK_MYFIXED (container), widget, 0, 0);
470}
471
472static void
473gtk_myfixed_remove (GtkContainer *container,
474 GtkWidget *widget)
475{
476 GtkMyFixed *myfixed;
477 GtkMyFixedChild *child;
478 GList *children;
479
480 g_return_if_fail (container != NULL);
481 g_return_if_fail (GTK_IS_MYFIXED (container));
482 g_return_if_fail (widget != NULL);
483
484 myfixed = GTK_MYFIXED (container);
485
486 children = myfixed->children;
487 while (children)
488 {
489 child = children->data;
490
491 if (child->widget == widget)
492 {
493 gtk_widget_unparent (widget);
494
495 myfixed->children = g_list_remove_link (myfixed->children, children);
496 g_list_free (children);
497 g_free (child);
498
499 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (container))
500 gtk_widget_queue_resize (GTK_WIDGET (container));
501
502 break;
503 }
504
505 children = children->next;
506 }
507}
508
509static void
510gtk_myfixed_foreach (GtkContainer *container,
75ed1d15
GL
511#if (GTK_MINOR_VERSION == 1)
512 gboolean include_internals,
513#endif
c801d85f
KB
514 GtkCallback callback,
515 gpointer callback_data)
516{
517 GtkMyFixed *myfixed;
518 GtkMyFixedChild *child;
519 GList *children;
520
521 g_return_if_fail (container != NULL);
522 g_return_if_fail (GTK_IS_MYFIXED (container));
523 g_return_if_fail (callback != NULL);
524
525 myfixed = GTK_MYFIXED (container);
526
527 children = myfixed->children;
528 while (children)
529 {
530 child = children->data;
531 children = children->next;
532
533 (* callback) (child->widget, callback_data);
534 }
535}
536
537
538#ifdef __cplusplus
539}
540#endif /* __cplusplus */
541