]> Pileus Git - ~andy/gtk/blob - gtk/gtkdrawingarea.c
More extensive debugging output
[~andy/gtk] / gtk / gtkdrawingarea.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the Free
16  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18 #include "gtkdrawingarea.h"
19
20
21 static void gtk_drawing_area_class_init    (GtkDrawingAreaClass *klass);
22 static void gtk_drawing_area_init          (GtkDrawingArea      *darea);
23 static void gtk_drawing_area_realize       (GtkWidget           *widget);
24 static void gtk_drawing_area_size_allocate (GtkWidget           *widget,
25                                             GtkAllocation       *allocation);
26 static void gtk_drawing_area_send_configure (GtkDrawingArea     *darea);
27
28
29 guint
30 gtk_drawing_area_get_type ()
31 {
32   static guint drawing_area_type = 0;
33
34   if (!drawing_area_type)
35     {
36       GtkTypeInfo drawing_area_info =
37       {
38         "GtkDrawingArea",
39         sizeof (GtkDrawingArea),
40         sizeof (GtkDrawingAreaClass),
41         (GtkClassInitFunc) gtk_drawing_area_class_init,
42         (GtkObjectInitFunc) gtk_drawing_area_init,
43         (GtkArgSetFunc) NULL,
44         (GtkArgGetFunc) NULL,
45       };
46
47       drawing_area_type = gtk_type_unique (gtk_widget_get_type (), &drawing_area_info);
48     }
49
50   return drawing_area_type;
51 }
52
53 static void
54 gtk_drawing_area_class_init (GtkDrawingAreaClass *class)
55 {
56   GtkWidgetClass *widget_class;
57
58   widget_class = (GtkWidgetClass*) class;
59
60   widget_class->realize = gtk_drawing_area_realize;
61   widget_class->size_allocate = gtk_drawing_area_size_allocate;
62 }
63
64 static void
65 gtk_drawing_area_init (GtkDrawingArea *darea)
66 {
67   GTK_WIDGET_SET_FLAGS (darea, GTK_BASIC);
68
69   darea->draw_data = NULL;
70 }
71
72
73 GtkWidget*
74 gtk_drawing_area_new ()
75 {
76   return GTK_WIDGET (gtk_type_new (gtk_drawing_area_get_type ()));
77 }
78
79 void
80 gtk_drawing_area_size (GtkDrawingArea *darea,
81                        gint            width,
82                        gint            height)
83 {
84   g_return_if_fail (darea != NULL);
85   g_return_if_fail (GTK_IS_DRAWING_AREA (darea));
86
87   GTK_WIDGET (darea)->requisition.width = width;
88   GTK_WIDGET (darea)->requisition.height = height;
89 }
90
91 static void
92 gtk_drawing_area_realize (GtkWidget *widget)
93 {
94   GtkDrawingArea *darea;
95   GdkWindowAttr attributes;
96   gint attributes_mask;
97
98   g_return_if_fail (widget != NULL);
99   g_return_if_fail (GTK_IS_DRAWING_AREA (widget));
100
101   darea = GTK_DRAWING_AREA (widget);
102   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
103
104   attributes.window_type = GDK_WINDOW_CHILD;
105   attributes.x = widget->allocation.x;
106   attributes.y = widget->allocation.y;
107   attributes.width = widget->allocation.width;
108   attributes.height = widget->allocation.height;
109   attributes.wclass = GDK_INPUT_OUTPUT;
110   attributes.visual = gtk_widget_get_visual (widget);
111   attributes.colormap = gtk_widget_get_colormap (widget);
112   attributes.event_mask = gtk_widget_get_events (widget);
113
114   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
115
116   widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
117   gdk_window_set_user_data (widget->window, darea);
118
119   widget->style = gtk_style_attach (widget->style, widget->window);
120   gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
121
122   gtk_drawing_area_send_configure (GTK_DRAWING_AREA (widget));
123 }
124
125 static void
126 gtk_drawing_area_size_allocate (GtkWidget     *widget,
127                                 GtkAllocation *allocation)
128 {
129   g_return_if_fail (widget != NULL);
130   g_return_if_fail (GTK_IS_DRAWING_AREA (widget));
131   g_return_if_fail (allocation != NULL);
132
133   widget->allocation = *allocation;
134
135   if (GTK_WIDGET_REALIZED (widget))
136     {
137       gdk_window_move_resize (widget->window,
138                               allocation->x, allocation->y,
139                               allocation->width, allocation->height);
140
141       gtk_drawing_area_send_configure (GTK_DRAWING_AREA (widget));
142     }
143 }
144
145 static void
146 gtk_drawing_area_send_configure (GtkDrawingArea *darea)
147 {
148   GtkWidget *widget;
149   GdkEventConfigure event;
150
151   widget = GTK_WIDGET (darea);
152
153   event.type = GDK_CONFIGURE;
154   event.window = widget->window;
155   event.x = widget->allocation.x;
156   event.y = widget->allocation.y;
157   event.width = widget->allocation.width;
158   event.height = widget->allocation.height;
159   
160   gtk_widget_event (widget, (GdkEvent*) &event);
161 }