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