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/.
28 #include "gtkdrawingarea.h"
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);
42 gtk_drawing_area_get_type (void)
44 static GType drawing_area_type = 0;
46 if (!drawing_area_type)
48 static const GTypeInfo drawing_area_info =
50 sizeof (GtkDrawingAreaClass),
52 NULL, /* base_finalize */
53 (GClassInitFunc) gtk_drawing_area_class_init,
54 NULL, /* class_finalize */
55 NULL, /* class_data */
56 sizeof (GtkDrawingArea),
58 (GInstanceInitFunc) gtk_drawing_area_init,
62 g_type_register_static (GTK_TYPE_WIDGET, I_("GtkDrawingArea"),
63 &drawing_area_info, 0);
66 return drawing_area_type;
70 gtk_drawing_area_class_init (GtkDrawingAreaClass *class)
72 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
74 widget_class->realize = gtk_drawing_area_realize;
75 widget_class->size_allocate = gtk_drawing_area_size_allocate;
79 gtk_drawing_area_init (GtkDrawingArea *darea)
81 darea->draw_data = NULL;
86 gtk_drawing_area_new (void)
88 return g_object_new (GTK_TYPE_DRAWING_AREA, NULL);
92 gtk_drawing_area_size (GtkDrawingArea *darea,
96 g_return_if_fail (GTK_IS_DRAWING_AREA (darea));
98 GTK_WIDGET (darea)->requisition.width = width;
99 GTK_WIDGET (darea)->requisition.height = height;
101 gtk_widget_queue_resize (GTK_WIDGET (darea));
105 gtk_drawing_area_realize (GtkWidget *widget)
107 GtkDrawingArea *darea;
108 GdkWindowAttr attributes;
109 gint attributes_mask;
111 g_return_if_fail (GTK_IS_DRAWING_AREA (widget));
113 darea = GTK_DRAWING_AREA (widget);
114 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
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;
126 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
128 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
129 gdk_window_set_user_data (widget->window, darea);
131 widget->style = gtk_style_attach (widget->style, widget->window);
132 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
134 gtk_drawing_area_send_configure (GTK_DRAWING_AREA (widget));
138 gtk_drawing_area_size_allocate (GtkWidget *widget,
139 GtkAllocation *allocation)
141 g_return_if_fail (GTK_IS_DRAWING_AREA (widget));
142 g_return_if_fail (allocation != NULL);
144 widget->allocation = *allocation;
146 if (GTK_WIDGET_REALIZED (widget))
148 gdk_window_move_resize (widget->window,
149 allocation->x, allocation->y,
150 allocation->width, allocation->height);
152 gtk_drawing_area_send_configure (GTK_DRAWING_AREA (widget));
157 gtk_drawing_area_send_configure (GtkDrawingArea *darea)
160 GdkEvent *event = gdk_event_new (GDK_CONFIGURE);
162 widget = GTK_WIDGET (darea);
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;
171 gtk_widget_event (widget, event);
172 gdk_event_free (event);
175 #define __GTK_DRAWING_AREA_C__
176 #include "gtkaliasdef.c"