1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
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.
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/.
27 #include "gtkdrawingarea.h"
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);
39 gtk_drawing_area_get_type (void)
41 static GType drawing_area_type = 0;
43 if (!drawing_area_type)
45 static const GTypeInfo drawing_area_info =
47 sizeof (GtkDrawingAreaClass),
49 NULL, /* base_finalize */
50 (GClassInitFunc) gtk_drawing_area_class_init,
51 NULL, /* class_finalize */
52 NULL, /* class_data */
53 sizeof (GtkDrawingArea),
55 (GInstanceInitFunc) gtk_drawing_area_init,
59 g_type_register_static (GTK_TYPE_WIDGET, "GtkDrawingArea",
60 &drawing_area_info, 0);
63 return drawing_area_type;
67 gtk_drawing_area_class_init (GtkDrawingAreaClass *class)
69 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
71 widget_class->realize = gtk_drawing_area_realize;
72 widget_class->size_allocate = gtk_drawing_area_size_allocate;
76 gtk_drawing_area_init (GtkDrawingArea *darea)
78 darea->draw_data = NULL;
83 gtk_drawing_area_new (void)
85 return g_object_new (GTK_TYPE_DRAWING_AREA, NULL);
89 gtk_drawing_area_size (GtkDrawingArea *darea,
93 g_return_if_fail (GTK_IS_DRAWING_AREA (darea));
95 GTK_WIDGET (darea)->requisition.width = width;
96 GTK_WIDGET (darea)->requisition.height = height;
98 gtk_widget_queue_resize (GTK_WIDGET (darea));
102 gtk_drawing_area_realize (GtkWidget *widget)
104 GtkDrawingArea *darea;
105 GdkWindowAttr attributes;
106 gint attributes_mask;
108 g_return_if_fail (GTK_IS_DRAWING_AREA (widget));
110 darea = GTK_DRAWING_AREA (widget);
111 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
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;
123 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
125 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
126 gdk_window_set_user_data (widget->window, darea);
128 widget->style = gtk_style_attach (widget->style, widget->window);
129 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
131 gtk_drawing_area_send_configure (GTK_DRAWING_AREA (widget));
135 gtk_drawing_area_size_allocate (GtkWidget *widget,
136 GtkAllocation *allocation)
138 g_return_if_fail (GTK_IS_DRAWING_AREA (widget));
139 g_return_if_fail (allocation != NULL);
141 widget->allocation = *allocation;
143 if (GTK_WIDGET_REALIZED (widget))
145 gdk_window_move_resize (widget->window,
146 allocation->x, allocation->y,
147 allocation->width, allocation->height);
149 gtk_drawing_area_send_configure (GTK_DRAWING_AREA (widget));
154 gtk_drawing_area_send_configure (GtkDrawingArea *darea)
157 GdkEvent *event = gdk_event_new (GDK_CONFIGURE);
159 widget = GTK_WIDGET (darea);
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;
168 gtk_widget_event (widget, event);
169 gdk_event_free (event);