]> Pileus Git - ~andy/gtk/blob - gtk/gtkdrawingarea.c
gtkbutton.c gtkclist.c gtkdrawingarea.c gtkentry.c gtkeventbox.c
[~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
27
28 guint
29 gtk_drawing_area_get_type ()
30 {
31   static guint drawing_area_type = 0;
32
33   if (!drawing_area_type)
34     {
35       GtkTypeInfo drawing_area_info =
36       {
37         "GtkDrawingArea",
38         sizeof (GtkDrawingArea),
39         sizeof (GtkDrawingAreaClass),
40         (GtkClassInitFunc) gtk_drawing_area_class_init,
41         (GtkObjectInitFunc) gtk_drawing_area_init,
42         (GtkArgSetFunc) NULL,
43         (GtkArgGetFunc) NULL,
44       };
45
46       drawing_area_type = gtk_type_unique (gtk_widget_get_type (), &drawing_area_info);
47     }
48
49   return drawing_area_type;
50 }
51
52 static void
53 gtk_drawing_area_class_init (GtkDrawingAreaClass *class)
54 {
55   GtkWidgetClass *widget_class;
56
57   widget_class = (GtkWidgetClass*) class;
58
59   widget_class->realize = gtk_drawing_area_realize;
60   widget_class->size_allocate = gtk_drawing_area_size_allocate;
61 }
62
63 static void
64 gtk_drawing_area_init (GtkDrawingArea *darea)
65 {
66   GTK_WIDGET_SET_FLAGS (darea, GTK_BASIC);
67 }
68
69
70 GtkWidget*
71 gtk_drawing_area_new ()
72 {
73   return GTK_WIDGET (gtk_type_new (gtk_drawing_area_get_type ()));
74 }
75
76 void
77 gtk_drawing_area_size (GtkDrawingArea *darea,
78                        gint            width,
79                        gint            height)
80 {
81   g_return_if_fail (darea != NULL);
82   g_return_if_fail (GTK_IS_DRAWING_AREA (darea));
83
84   GTK_WIDGET (darea)->requisition.width = width;
85   GTK_WIDGET (darea)->requisition.height = height;
86 }
87
88 static void
89 gtk_drawing_area_realize (GtkWidget *widget)
90 {
91   GtkDrawingArea *darea;
92   GdkWindowAttr attributes;
93   gint attributes_mask;
94
95   g_return_if_fail (widget != NULL);
96   g_return_if_fail (GTK_IS_DRAWING_AREA (widget));
97
98   darea = GTK_DRAWING_AREA (widget);
99   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
100
101   attributes.window_type = GDK_WINDOW_CHILD;
102   attributes.x = widget->allocation.x;
103   attributes.y = widget->allocation.y;
104   attributes.width = widget->allocation.width;
105   attributes.height = widget->allocation.height;
106   attributes.wclass = GDK_INPUT_OUTPUT;
107   attributes.visual = gtk_widget_get_visual (widget);
108   attributes.colormap = gtk_widget_get_colormap (widget);
109   attributes.event_mask = gtk_widget_get_events (widget);
110
111   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
112
113   widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
114   gdk_window_set_user_data (widget->window, darea);
115
116   widget->style = gtk_style_attach (widget->style, widget->window);
117   gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
118 }
119
120 static void
121 gtk_drawing_area_size_allocate (GtkWidget     *widget,
122                                 GtkAllocation *allocation)
123 {
124   GdkEventConfigure event;
125
126   g_return_if_fail (widget != NULL);
127   g_return_if_fail (GTK_IS_DRAWING_AREA (widget));
128   g_return_if_fail (allocation != NULL);
129
130   widget->allocation = *allocation;
131
132   if (GTK_WIDGET_REALIZED (widget))
133     {
134       gdk_window_move_resize (widget->window,
135                               allocation->x, allocation->y,
136                               allocation->width, allocation->height);
137
138       event.type = GDK_CONFIGURE;
139       event.window = widget->window;
140       event.x = allocation->x;
141       event.y = allocation->y;
142       event.width = allocation->width;
143       event.height = allocation->height;
144
145       gtk_widget_event (widget, (GdkEvent*) &event);
146     }
147 }