]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk1/win_gtk.c
Added window resize patch to wxFrame
[wxWidgets.git] / src / gtk1 / win_gtk.c
... / ...
CommitLineData
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
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);
20#if (GTK_MINOR_VERSION == 0)
21static void gtk_myfixed_unmap (GtkWidget *widget);
22#endif
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,
39#if (GTK_MINOR_VERSION > 0)
40 gboolean include_internals,
41#endif
42 GtkCallback callback,
43 gpointer callback_data);
44#if (GTK_MINOR_VERSION > 0)
45static GtkType gtk_myfixed_child_type (GtkContainer *container);
46#endif
47
48#if (GTK_MINOR_VERSION > 0)
49static void gtk_myfixed_scroll_set_adjustments (GtkMyFixed *myfixed,
50 GtkAdjustment *hadj,
51 GtkAdjustment *vadj);
52#endif
53
54
55
56static GtkContainerClass *parent_class = NULL;
57
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,
72#if (GTK_MINOR_VERSION > 0)
73 /* reserved_1 */ NULL,
74 /* reserved_2 */ NULL,
75 (GtkClassInitFunc) NULL,
76#else
77 (GtkArgSetFunc) NULL,
78 (GtkArgGetFunc) NULL,
79#endif
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;
98
99#if (GTK_MINOR_VERSION > 0)
100 parent_class = gtk_type_class (GTK_TYPE_CONTAINER);
101#else
102 parent_class = gtk_type_class (gtk_container_get_type ());
103#endif
104
105 widget_class->map = gtk_myfixed_map;
106#if (GTK_MINOR_VERSION == 0)
107 widget_class->unmap = gtk_myfixed_unmap;
108#endif
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;
117#if (GTK_MINOR_VERSION > 0)
118 container_class->forall = gtk_myfixed_foreach;
119#else
120 container_class->foreach = gtk_myfixed_foreach;
121#endif
122
123#if (GTK_MINOR_VERSION > 0)
124 container_class->child_type = gtk_myfixed_child_type;
125#endif
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
138}
139
140#if (GTK_MINOR_VERSION > 0)
141static GtkType
142gtk_myfixed_child_type (GtkContainer *container)
143{
144 return GTK_TYPE_WIDGET;
145}
146#endif
147
148static void
149gtk_myfixed_init (GtkMyFixed *myfixed)
150{
151 GTK_WIDGET_UNSET_FLAGS (myfixed, GTK_NO_WINDOW);
152
153#if (GTK_MINOR_VERSION == 0)
154 GTK_WIDGET_SET_FLAGS (myfixed, GTK_BASIC);
155#endif
156
157#if (GTK_MINOR_VERSION > 0)
158 myfixed->shadow_type = GTK_SHADOW_NONE;
159#endif
160
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
171 return GTK_WIDGET (myfixed);
172}
173
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
202void
203gtk_myfixed_put (GtkMyFixed *myfixed,
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;
216 child_info->x = x;
217 child_info->y = y;
218
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 {
254 if ((child->x == x) && (child->y == y)) return;
255
256 child->x = x;
257 child->y = y;
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
294#if (GTK_MINOR_VERSION == 0)
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}
303#endif
304
305static void
306gtk_myfixed_realize (GtkWidget *widget)
307{
308 GtkMyFixed *myfixed;
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
315 myfixed = GTK_MYFIXED (widget);
316
317 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
318
319 attributes.window_type = GDK_WINDOW_CHILD;
320
321#if (GTK_MINOR_VERSION > 0)
322 attributes.x = widget->allocation.x;
323 attributes.y = widget->allocation.y;
324 attributes.width = widget->allocation.width;
325 attributes.height = widget->allocation.height;
326
327 if (myfixed->shadow_type != GTK_SHADOW_NONE)
328 {
329 attributes.x += 2;
330 attributes.y += 2;
331 attributes.width -= 4;
332 attributes.height -= 4;
333 }
334
335 if (attributes.width < 2) attributes.width = 2;
336 if (attributes.height < 2) attributes.height = 2;
337#else
338 attributes.x = widget->allocation.x;
339 attributes.y = widget->allocation.y;
340 attributes.width = 32000;
341 attributes.height = 32000;
342#endif
343 attributes.wclass = GDK_INPUT_OUTPUT;
344 attributes.visual = gtk_widget_get_visual (widget);
345 attributes.colormap = gtk_widget_get_colormap (widget);
346 attributes.event_mask = gtk_widget_get_events (widget);
347 attributes.event_mask |=
348 GDK_EXPOSURE_MASK |
349 GDK_POINTER_MOTION_MASK |
350 GDK_POINTER_MOTION_HINT_MASK |
351 GDK_BUTTON_MOTION_MASK |
352 GDK_BUTTON1_MOTION_MASK |
353 GDK_BUTTON2_MOTION_MASK |
354 GDK_BUTTON3_MOTION_MASK |
355 GDK_BUTTON_PRESS_MASK |
356 GDK_BUTTON_RELEASE_MASK |
357 GDK_KEY_PRESS_MASK |
358 GDK_KEY_RELEASE_MASK |
359 GDK_ENTER_NOTIFY_MASK |
360 GDK_LEAVE_NOTIFY_MASK |
361 GDK_FOCUS_CHANGE_MASK;
362
363 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
364
365 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes,
366 attributes_mask);
367 gdk_window_set_user_data (widget->window, widget);
368
369 widget->style = gtk_style_attach (widget->style, widget->window);
370 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
371}
372
373static void
374gtk_myfixed_size_request (GtkWidget *widget,
375 GtkRequisition *requisition)
376{
377 GtkMyFixed *myfixed;
378 GtkMyFixedChild *child;
379 GList *children;
380
381 g_return_if_fail (widget != NULL);
382 g_return_if_fail (GTK_IS_MYFIXED (widget));
383 g_return_if_fail (requisition != NULL);
384
385 myfixed = GTK_MYFIXED (widget);
386
387/*
388 requisition->width = 0;
389 requisition->height = 0;
390*/
391 requisition->width = widget->requisition.width;
392 requisition->height = widget->requisition.height;
393
394 children = myfixed->children;
395 while (children)
396 {
397 child = children->data;
398 children = children->next;
399
400 if (GTK_WIDGET_VISIBLE (child->widget))
401 {
402 gtk_widget_size_request (child->widget, &child->widget->requisition);
403 }
404 }
405}
406
407static void
408gtk_myfixed_size_allocate (GtkWidget *widget,
409 GtkAllocation *allocation)
410{
411 GtkMyFixed *myfixed;
412 gint border;
413 GtkMyFixedChild *child;
414 GtkAllocation child_allocation;
415 GList *children;
416
417 g_return_if_fail (widget != NULL);
418 g_return_if_fail (GTK_IS_MYFIXED(widget));
419 g_return_if_fail (allocation != NULL);
420
421 myfixed = GTK_MYFIXED (widget);
422
423 widget->allocation = *allocation;
424#if (GTK_MINOR_VERSION > 0)
425 if (myfixed->shadow_type == GTK_SHADOW_NONE)
426 border = 0;
427 else
428 border = 2;
429#else
430 border = 0;
431#endif
432
433 if (GTK_WIDGET_REALIZED (widget))
434 {
435 gdk_window_move_resize( widget->window,
436 allocation->x+border, allocation->y+border,
437#if (GTK_MINOR_VERSION > 0)
438 allocation->width-border*2, allocation->height-border*2
439#else
440 32000, 32000
441#endif
442 );
443 }
444
445 children = myfixed->children;
446 while (children)
447 {
448 child = children->data;
449 children = children->next;
450
451 if (GTK_WIDGET_VISIBLE (child->widget))
452 {
453 child_allocation.x = child->x;
454 child_allocation.y = child->y;
455 child_allocation.width = child->widget->requisition.width;
456 child_allocation.height = child->widget->requisition.height;
457 gtk_widget_size_allocate (child->widget, &child_allocation);
458 }
459 }
460}
461
462static void
463gtk_myfixed_paint (GtkWidget *widget,
464 GdkRectangle *area)
465{
466 g_return_if_fail (widget != NULL);
467 g_return_if_fail (GTK_IS_MYFIXED (widget));
468 g_return_if_fail (area != NULL);
469
470 if (GTK_WIDGET_DRAWABLE (widget))
471 gdk_window_clear_area (widget->window,
472 area->x, area->y,
473 area->width, area->height);
474}
475
476static void
477gtk_myfixed_draw (GtkWidget *widget,
478 GdkRectangle *area)
479{
480 GtkMyFixed *myfixed;
481 GtkMyFixedChild *child;
482 GdkRectangle child_area;
483 GList *children;
484
485 g_return_if_fail (widget != NULL);
486 g_return_if_fail (GTK_IS_MYFIXED (widget));
487
488 if (GTK_WIDGET_DRAWABLE (widget))
489 {
490 myfixed = GTK_MYFIXED (widget);
491 gtk_myfixed_paint (widget, area);
492
493 children = myfixed->children;
494 while (children)
495 {
496 child = children->data;
497 children = children->next;
498
499 if (gtk_widget_intersect (child->widget, area, &child_area))
500 gtk_widget_draw (child->widget, &child_area);
501 }
502 }
503}
504
505static gint
506gtk_myfixed_expose (GtkWidget *widget,
507 GdkEventExpose *event)
508{
509 GtkMyFixed *myfixed;
510 GtkMyFixedChild *child;
511 GdkEventExpose child_event;
512 GList *children;
513
514 g_return_val_if_fail (widget != NULL, FALSE);
515 g_return_val_if_fail (GTK_IS_MYFIXED (widget), FALSE);
516 g_return_val_if_fail (event != NULL, FALSE);
517
518 if (GTK_WIDGET_DRAWABLE (widget))
519 {
520 myfixed = GTK_MYFIXED (widget);
521
522 child_event = *event;
523
524 children = myfixed->children;
525 while (children)
526 {
527 child = children->data;
528 children = children->next;
529
530 if (GTK_WIDGET_NO_WINDOW (child->widget) &&
531 gtk_widget_intersect (child->widget, &event->area,
532 &child_event.area))
533 gtk_widget_event (child->widget, (GdkEvent*) &child_event);
534 }
535 }
536
537 return FALSE;
538}
539
540static void
541gtk_myfixed_add (GtkContainer *container,
542 GtkWidget *widget)
543{
544 g_return_if_fail (container != NULL);
545 g_return_if_fail (GTK_IS_MYFIXED (container));
546 g_return_if_fail (widget != NULL);
547
548 gtk_myfixed_put (GTK_MYFIXED (container), widget, 0, 0);
549}
550
551static void
552gtk_myfixed_remove (GtkContainer *container,
553 GtkWidget *widget)
554{
555 GtkMyFixed *myfixed;
556 GtkMyFixedChild *child;
557 GList *children;
558
559 g_return_if_fail (container != NULL);
560 g_return_if_fail (GTK_IS_MYFIXED (container));
561 g_return_if_fail (widget != NULL);
562
563 myfixed = GTK_MYFIXED (container);
564
565 children = myfixed->children;
566 while (children)
567 {
568 child = children->data;
569
570 if (child->widget == widget)
571 {
572 gtk_widget_unparent (widget);
573
574 myfixed->children = g_list_remove_link (myfixed->children, children);
575 g_list_free (children);
576 g_free (child);
577
578 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (container))
579 gtk_widget_queue_resize (GTK_WIDGET (container));
580
581 break;
582 }
583
584 children = children->next;
585 }
586}
587
588static void
589gtk_myfixed_foreach (GtkContainer *container,
590#if (GTK_MINOR_VERSION > 0)
591 gboolean include_internals,
592#endif
593 GtkCallback callback,
594 gpointer callback_data)
595{
596 GtkMyFixed *myfixed;
597 GtkMyFixedChild *child;
598 GList *children;
599
600 g_return_if_fail (container != NULL);
601 g_return_if_fail (GTK_IS_MYFIXED (container));
602 g_return_if_fail (callback != NULL);
603
604 myfixed = GTK_MYFIXED (container);
605
606 children = myfixed->children;
607 while (children)
608 {
609 child = children->data;
610 children = children->next;
611
612 (* callback) (child->widget, callback_data);
613 }
614}
615
616
617#ifdef __cplusplus
618}
619#endif /* __cplusplus */
620