]> Pileus Git - ~andy/gtk/blob - gtk/gtkdrawingarea.c
Add hidden aliases for exported symbols which are used internally in order
[~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 <config.h>
28 #include "gtkalias.h"
29 #include "gtkdrawingarea.h"
30
31
32 static void gtk_drawing_area_class_init    (GtkDrawingAreaClass *klass);
33 static void gtk_drawing_area_init          (GtkDrawingArea      *darea);
34 static void gtk_drawing_area_realize       (GtkWidget           *widget);
35 static void gtk_drawing_area_size_allocate (GtkWidget           *widget,
36                                             GtkAllocation       *allocation);
37 static void gtk_drawing_area_send_configure (GtkDrawingArea     *darea);
38
39
40 GType
41 gtk_drawing_area_get_type (void)
42 {
43   static GType drawing_area_type = 0;
44
45   if (!drawing_area_type)
46     {
47       static const GTypeInfo drawing_area_info =
48       {
49         sizeof (GtkDrawingAreaClass),
50         NULL,           /* base_init */
51         NULL,           /* base_finalize */
52         (GClassInitFunc) gtk_drawing_area_class_init,
53         NULL,           /* class_finalize */
54         NULL,           /* class_data */
55         sizeof (GtkDrawingArea),
56         0,              /* n_preallocs */
57         (GInstanceInitFunc) gtk_drawing_area_init,
58       };
59
60       drawing_area_type =
61         g_type_register_static (GTK_TYPE_WIDGET, "GtkDrawingArea",
62                                 &drawing_area_info, 0);
63     }
64
65   return drawing_area_type;
66 }
67
68 static void
69 gtk_drawing_area_class_init (GtkDrawingAreaClass *class)
70 {
71   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
72
73   widget_class->realize = gtk_drawing_area_realize;
74   widget_class->size_allocate = gtk_drawing_area_size_allocate;
75 }
76
77 static void
78 gtk_drawing_area_init (GtkDrawingArea *darea)
79 {
80   darea->draw_data = NULL;
81 }
82
83
84 GtkWidget*
85 gtk_drawing_area_new (void)
86 {
87   return g_object_new (GTK_TYPE_DRAWING_AREA, NULL);
88 }
89
90 void
91 gtk_drawing_area_size (GtkDrawingArea *darea,
92                        gint            width,
93                        gint            height)
94 {
95   g_return_if_fail (GTK_IS_DRAWING_AREA (darea));
96
97   GTK_WIDGET (darea)->requisition.width = width;
98   GTK_WIDGET (darea)->requisition.height = height;
99
100   gtk_widget_queue_resize (GTK_WIDGET (darea));
101 }
102
103 static void
104 gtk_drawing_area_realize (GtkWidget *widget)
105 {
106   GtkDrawingArea *darea;
107   GdkWindowAttr attributes;
108   gint attributes_mask;
109
110   g_return_if_fail (GTK_IS_DRAWING_AREA (widget));
111
112   darea = GTK_DRAWING_AREA (widget);
113   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
114
115   attributes.window_type = GDK_WINDOW_CHILD;
116   attributes.x = widget->allocation.x;
117   attributes.y = widget->allocation.y;
118   attributes.width = widget->allocation.width;
119   attributes.height = widget->allocation.height;
120   attributes.wclass = GDK_INPUT_OUTPUT;
121   attributes.visual = gtk_widget_get_visual (widget);
122   attributes.colormap = gtk_widget_get_colormap (widget);
123   attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
124
125   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
126
127   widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
128   gdk_window_set_user_data (widget->window, darea);
129
130   widget->style = gtk_style_attach (widget->style, widget->window);
131   gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
132
133   gtk_drawing_area_send_configure (GTK_DRAWING_AREA (widget));
134 }
135
136 static void
137 gtk_drawing_area_size_allocate (GtkWidget     *widget,
138                                 GtkAllocation *allocation)
139 {
140   g_return_if_fail (GTK_IS_DRAWING_AREA (widget));
141   g_return_if_fail (allocation != NULL);
142
143   widget->allocation = *allocation;
144
145   if (GTK_WIDGET_REALIZED (widget))
146     {
147       gdk_window_move_resize (widget->window,
148                               allocation->x, allocation->y,
149                               allocation->width, allocation->height);
150
151       gtk_drawing_area_send_configure (GTK_DRAWING_AREA (widget));
152     }
153 }
154
155 static void
156 gtk_drawing_area_send_configure (GtkDrawingArea *darea)
157 {
158   GtkWidget *widget;
159   GdkEvent *event = gdk_event_new (GDK_CONFIGURE);
160
161   widget = GTK_WIDGET (darea);
162
163   event->configure.window = g_object_ref (widget->window);
164   event->configure.send_event = TRUE;
165   event->configure.x = widget->allocation.x;
166   event->configure.y = widget->allocation.y;
167   event->configure.width = widget->allocation.width;
168   event->configure.height = widget->allocation.height;
169   
170   gtk_widget_event (widget, event);
171   gdk_event_free (event);
172 }