]> Pileus Git - ~andy/gtk/blob - gtk/gtkdrawingarea.c
changed reversed_[12] to reserved_[12] in gtk_*_get_type functions.
[~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
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19 #include "gtkdrawingarea.h"
20
21
22 static void gtk_drawing_area_class_init    (GtkDrawingAreaClass *klass);
23 static void gtk_drawing_area_init          (GtkDrawingArea      *darea);
24 static void gtk_drawing_area_realize       (GtkWidget           *widget);
25 static void gtk_drawing_area_size_allocate (GtkWidget           *widget,
26                                             GtkAllocation       *allocation);
27 static void gtk_drawing_area_send_configure (GtkDrawingArea     *darea);
28
29
30 guint
31 gtk_drawing_area_get_type (void)
32 {
33   static guint drawing_area_type = 0;
34
35   if (!drawing_area_type)
36     {
37       GtkTypeInfo drawing_area_info =
38       {
39         "GtkDrawingArea",
40         sizeof (GtkDrawingArea),
41         sizeof (GtkDrawingAreaClass),
42         (GtkClassInitFunc) gtk_drawing_area_class_init,
43         (GtkObjectInitFunc) gtk_drawing_area_init,
44         /* reserved_1 */ NULL,
45         /* reserved_2 */ NULL,
46         (GtkClassInitFunc) NULL,
47       };
48
49       drawing_area_type = gtk_type_unique (gtk_widget_get_type (), &drawing_area_info);
50     }
51
52   return drawing_area_type;
53 }
54
55 static void
56 gtk_drawing_area_class_init (GtkDrawingAreaClass *class)
57 {
58   GtkWidgetClass *widget_class;
59
60   widget_class = (GtkWidgetClass*) class;
61
62   widget_class->realize = gtk_drawing_area_realize;
63   widget_class->size_allocate = gtk_drawing_area_size_allocate;
64 }
65
66 static void
67 gtk_drawing_area_init (GtkDrawingArea *darea)
68 {
69   GTK_WIDGET_SET_FLAGS (darea, GTK_BASIC);
70
71   darea->draw_data = NULL;
72 }
73
74
75 GtkWidget*
76 gtk_drawing_area_new (void)
77 {
78   return GTK_WIDGET (gtk_type_new (gtk_drawing_area_get_type ()));
79 }
80
81 void
82 gtk_drawing_area_size (GtkDrawingArea *darea,
83                        gint            width,
84                        gint            height)
85 {
86   g_return_if_fail (darea != NULL);
87   g_return_if_fail (GTK_IS_DRAWING_AREA (darea));
88
89   GTK_WIDGET (darea)->requisition.width = width;
90   GTK_WIDGET (darea)->requisition.height = height;
91 }
92
93 static void
94 gtk_drawing_area_realize (GtkWidget *widget)
95 {
96   GtkDrawingArea *darea;
97   GdkWindowAttr attributes;
98   gint attributes_mask;
99
100   g_return_if_fail (widget != NULL);
101   g_return_if_fail (GTK_IS_DRAWING_AREA (widget));
102
103   darea = GTK_DRAWING_AREA (widget);
104   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
105
106   attributes.window_type = GDK_WINDOW_CHILD;
107   attributes.x = widget->allocation.x;
108   attributes.y = widget->allocation.y;
109   attributes.width = widget->allocation.width;
110   attributes.height = widget->allocation.height;
111   attributes.wclass = GDK_INPUT_OUTPUT;
112   attributes.visual = gtk_widget_get_visual (widget);
113   attributes.colormap = gtk_widget_get_colormap (widget);
114   attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
115
116   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
117
118   widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
119   gdk_window_set_user_data (widget->window, darea);
120
121   widget->style = gtk_style_attach (widget->style, widget->window);
122   gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
123
124   gtk_drawing_area_send_configure (GTK_DRAWING_AREA (widget));
125 }
126
127 static void
128 gtk_drawing_area_size_allocate (GtkWidget     *widget,
129                                 GtkAllocation *allocation)
130 {
131   g_return_if_fail (widget != NULL);
132   g_return_if_fail (GTK_IS_DRAWING_AREA (widget));
133   g_return_if_fail (allocation != NULL);
134
135   widget->allocation = *allocation;
136
137   if (GTK_WIDGET_REALIZED (widget))
138     {
139       gdk_window_move_resize (widget->window,
140                               allocation->x, allocation->y,
141                               allocation->width, allocation->height);
142
143       gtk_drawing_area_send_configure (GTK_DRAWING_AREA (widget));
144     }
145 }
146
147 static void
148 gtk_drawing_area_send_configure (GtkDrawingArea *darea)
149 {
150   GtkWidget *widget;
151   GdkEventConfigure event;
152
153   widget = GTK_WIDGET (darea);
154
155   event.type = GDK_CONFIGURE;
156   event.window = widget->window;
157   event.x = widget->allocation.x;
158   event.y = widget->allocation.y;
159   event.width = widget->allocation.width;
160   event.height = widget->allocation.height;
161   
162   gtk_widget_event (widget, (GdkEvent*) &event);
163 }