]> Pileus Git - ~andy/gtk/blob - gtk/gtkdrawingarea.c
deprecation cleanup
[~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 Lesser 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  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GTK+ Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
25  */
26
27 #include "gtkdrawingarea.h"
28
29
30 static void gtk_drawing_area_class_init    (GtkDrawingAreaClass *klass);
31 static void gtk_drawing_area_init          (GtkDrawingArea      *darea);
32 static void gtk_drawing_area_realize       (GtkWidget           *widget);
33 static void gtk_drawing_area_size_allocate (GtkWidget           *widget,
34                                             GtkAllocation       *allocation);
35 static void gtk_drawing_area_send_configure (GtkDrawingArea     *darea);
36
37
38 GType
39 gtk_drawing_area_get_type (void)
40 {
41   static GType drawing_area_type = 0;
42
43   if (!drawing_area_type)
44     {
45       static const GTypeInfo drawing_area_info =
46       {
47         sizeof (GtkDrawingAreaClass),
48         NULL,           /* base_init */
49         NULL,           /* base_finalize */
50         (GClassInitFunc) gtk_drawing_area_class_init,
51         NULL,           /* class_finalize */
52         NULL,           /* class_data */
53         sizeof (GtkDrawingArea),
54         0,              /* n_preallocs */
55         (GInstanceInitFunc) gtk_drawing_area_init,
56       };
57
58       drawing_area_type =
59         g_type_register_static (GTK_TYPE_WIDGET, "GtkDrawingArea",
60                                 &drawing_area_info, 0);
61     }
62
63   return drawing_area_type;
64 }
65
66 static void
67 gtk_drawing_area_class_init (GtkDrawingAreaClass *class)
68 {
69   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
70
71   widget_class->realize = gtk_drawing_area_realize;
72   widget_class->size_allocate = gtk_drawing_area_size_allocate;
73 }
74
75 static void
76 gtk_drawing_area_init (GtkDrawingArea *darea)
77 {
78   darea->draw_data = NULL;
79 }
80
81
82 GtkWidget*
83 gtk_drawing_area_new (void)
84 {
85   return g_object_new (GTK_TYPE_DRAWING_AREA, NULL);
86 }
87
88 void
89 gtk_drawing_area_size (GtkDrawingArea *darea,
90                        gint            width,
91                        gint            height)
92 {
93   g_return_if_fail (GTK_IS_DRAWING_AREA (darea));
94
95   GTK_WIDGET (darea)->requisition.width = width;
96   GTK_WIDGET (darea)->requisition.height = height;
97
98   gtk_widget_queue_resize (GTK_WIDGET (darea));
99 }
100
101 static void
102 gtk_drawing_area_realize (GtkWidget *widget)
103 {
104   GtkDrawingArea *darea;
105   GdkWindowAttr attributes;
106   gint attributes_mask;
107
108   g_return_if_fail (GTK_IS_DRAWING_AREA (widget));
109
110   darea = GTK_DRAWING_AREA (widget);
111   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
112
113   attributes.window_type = GDK_WINDOW_CHILD;
114   attributes.x = widget->allocation.x;
115   attributes.y = widget->allocation.y;
116   attributes.width = widget->allocation.width;
117   attributes.height = widget->allocation.height;
118   attributes.wclass = GDK_INPUT_OUTPUT;
119   attributes.visual = gtk_widget_get_visual (widget);
120   attributes.colormap = gtk_widget_get_colormap (widget);
121   attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
122
123   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
124
125   widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
126   gdk_window_set_user_data (widget->window, darea);
127
128   widget->style = gtk_style_attach (widget->style, widget->window);
129   gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
130
131   gtk_drawing_area_send_configure (GTK_DRAWING_AREA (widget));
132 }
133
134 static void
135 gtk_drawing_area_size_allocate (GtkWidget     *widget,
136                                 GtkAllocation *allocation)
137 {
138   g_return_if_fail (GTK_IS_DRAWING_AREA (widget));
139   g_return_if_fail (allocation != NULL);
140
141   widget->allocation = *allocation;
142
143   if (GTK_WIDGET_REALIZED (widget))
144     {
145       gdk_window_move_resize (widget->window,
146                               allocation->x, allocation->y,
147                               allocation->width, allocation->height);
148
149       gtk_drawing_area_send_configure (GTK_DRAWING_AREA (widget));
150     }
151 }
152
153 static void
154 gtk_drawing_area_send_configure (GtkDrawingArea *darea)
155 {
156   GtkWidget *widget;
157   GdkEvent *event = gdk_event_new (GDK_CONFIGURE);
158
159   widget = GTK_WIDGET (darea);
160
161   event->configure.window = g_object_ref (widget->window);
162   event->configure.send_event = TRUE;
163   event->configure.x = widget->allocation.x;
164   event->configure.y = widget->allocation.y;
165   event->configure.width = widget->allocation.width;
166   event->configure.height = widget->allocation.height;
167   
168   gtk_widget_event (widget, event);
169   gdk_event_free (event);
170 }