]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/win_gtk.c
support for incorrect entries in .mime.types added (world is not perfect, alas)
[wxWidgets.git] / src / gtk1 / win_gtk.c
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/gtkfeatures.h>
12
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
23 #ifdef __cplusplus
24 extern "C" {
25 #endif /* __cplusplus */
26
27 static void gtk_myfixed_class_init (GtkMyFixedClass *klass);
28 static void gtk_myfixed_init (GtkMyFixed *myfixed);
29 static void gtk_myfixed_map (GtkWidget *widget);
30 #ifndef NEW_GTK_CONSTRUCT_CODE
31 static void gtk_myfixed_unmap (GtkWidget *widget);
32 #endif
33 static void gtk_myfixed_realize (GtkWidget *widget);
34 static void gtk_myfixed_size_request (GtkWidget *widget,
35 GtkRequisition *requisition);
36 static void gtk_myfixed_size_allocate (GtkWidget *widget,
37 GtkAllocation *allocation);
38 static void gtk_myfixed_paint (GtkWidget *widget,
39 GdkRectangle *area);
40 static void gtk_myfixed_draw (GtkWidget *widget,
41 GdkRectangle *area);
42 static gint gtk_myfixed_expose (GtkWidget *widget,
43 GdkEventExpose *event);
44 static void gtk_myfixed_add (GtkContainer *container,
45 GtkWidget *widget);
46 static void gtk_myfixed_remove (GtkContainer *container,
47 GtkWidget *widget);
48 static void gtk_myfixed_foreach (GtkContainer *container,
49 #if (GTK_MINOR_VERSION == 1)
50 gboolean include_internals,
51 #endif
52 GtkCallback callback,
53 gpointer callback_data);
54 #ifdef NEW_GTK_CONSTRUCT_CODE
55 static GtkType gtk_myfixed_child_type (GtkContainer *container);
56 #endif
57
58
59 static GtkContainerClass *parent_class = NULL;
60
61
62 guint
63 gtk_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,
76 #ifndef NEW_GTK_CONSTRUCT_CODE
77 (GtkArgSetFunc) NULL,
78 (GtkArgGetFunc) NULL,
79 #else
80 /* reserved_1 */ NULL,
81 /* reserved_2 */ NULL,
82 (GtkClassInitFunc) NULL,
83 #endif
84 };
85
86 myfixed_type = gtk_type_unique (gtk_container_get_type (), &myfixed_info);
87 }
88
89 return myfixed_type;
90 }
91
92 static void
93 gtk_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;
102
103 #ifndef NEW_GTK_CONSTRUCT_CODE
104 parent_class = gtk_type_class (gtk_container_get_type ());
105 #else
106 parent_class = gtk_type_class (GTK_TYPE_CONTAINER);
107 #endif
108
109 widget_class->map = gtk_myfixed_map;
110 #ifndef NEW_GTK_CONSTRUCT_CODE
111 widget_class->unmap = gtk_myfixed_unmap;
112 #endif
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;
121 #if (GTK_MINOR_VERSION == 1)
122 container_class->forall = gtk_myfixed_foreach;
123 #else
124 container_class->foreach = gtk_myfixed_foreach;
125 #endif
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
133 static GtkType
134 gtk_myfixed_child_type (GtkContainer *container)
135 {
136 return GTK_TYPE_WIDGET;
137 }
138 #endif
139
140 static void
141 gtk_myfixed_init (GtkMyFixed *myfixed)
142 {
143 GTK_WIDGET_UNSET_FLAGS (myfixed, GTK_NO_WINDOW);
144
145 #ifndef NEW_GTK_CONSTRUCT_CODE
146 GTK_WIDGET_SET_FLAGS (myfixed, GTK_BASIC);
147 #endif
148
149 myfixed->children = NULL;
150 }
151
152 GtkWidget*
153 gtk_myfixed_new ()
154 {
155 GtkMyFixed *myfixed;
156
157 myfixed = gtk_type_new (gtk_myfixed_get_type ());
158
159 return GTK_WIDGET (myfixed);
160 }
161
162 void
163 gtk_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;
176 child_info->x = x;
177 child_info->y = y;
178
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
193 void
194 gtk_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 {
214 if ((child->x == x) && (child->y == y)) return;
215
216 child->x = x;
217 child->y = y;
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
227 static void
228 gtk_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
254 #ifndef NEW_GTK_CONSTRUCT_CODE
255 static void
256 gtk_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 }
263 #endif
264
265 static void
266 gtk_myfixed_realize (GtkWidget *widget)
267 {
268 GtkMyFixed *myfixed;
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
275 myfixed = GTK_MYFIXED (widget);
276
277 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
278
279 attributes.window_type = GDK_WINDOW_CHILD;
280 attributes.x = widget->allocation.x;
281 attributes.y = widget->allocation.y;
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 |
291 GDK_POINTER_MOTION_HINT_MASK |
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
314 static void
315 gtk_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
344 static void
345 gtk_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))
362 gdk_window_move_resize (widget->window, allocation->x, allocation->y, 32000, 32000 );
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
383 static void
384 gtk_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
397 static void
398 gtk_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
426 static gint
427 gtk_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
461 static void
462 gtk_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
472 static void
473 gtk_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
509 static void
510 gtk_myfixed_foreach (GtkContainer *container,
511 #if (GTK_MINOR_VERSION == 1)
512 gboolean include_internals,
513 #endif
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