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