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_realize (GtkWidget *widget);
34 static void gtk_drawing_area_size_allocate (GtkWidget *widget,
35 GtkAllocation *allocation);
36 static void gtk_drawing_area_send_configure (GtkDrawingArea *darea);
38 G_DEFINE_TYPE (GtkDrawingArea, gtk_drawing_area, GTK_TYPE_WIDGET)
41 gtk_drawing_area_class_init (GtkDrawingAreaClass *class)
43 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
45 widget_class->realize = gtk_drawing_area_realize;
46 widget_class->size_allocate = gtk_drawing_area_size_allocate;
50 gtk_drawing_area_init (GtkDrawingArea *darea)
52 darea->draw_data = NULL;
57 gtk_drawing_area_new (void)
59 return g_object_new (GTK_TYPE_DRAWING_AREA, NULL);
63 gtk_drawing_area_size (GtkDrawingArea *darea,
67 g_return_if_fail (GTK_IS_DRAWING_AREA (darea));
69 GTK_WIDGET (darea)->requisition.width = width;
70 GTK_WIDGET (darea)->requisition.height = height;
72 gtk_widget_queue_resize (GTK_WIDGET (darea));
76 gtk_drawing_area_realize (GtkWidget *widget)
78 GtkDrawingArea *darea = GTK_DRAWING_AREA (widget);
79 GdkWindowAttr attributes;
82 if (!gtk_widget_get_has_window (widget))
84 GTK_WIDGET_CLASS (gtk_drawing_area_parent_class)->realize (widget);
88 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
90 attributes.window_type = GDK_WINDOW_CHILD;
91 attributes.x = widget->allocation.x;
92 attributes.y = widget->allocation.y;
93 attributes.width = widget->allocation.width;
94 attributes.height = widget->allocation.height;
95 attributes.wclass = GDK_INPUT_OUTPUT;
96 attributes.visual = gtk_widget_get_visual (widget);
97 attributes.colormap = gtk_widget_get_colormap (widget);
98 attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
100 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
102 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
103 &attributes, attributes_mask);
104 gdk_window_set_user_data (widget->window, darea);
106 widget->style = gtk_style_attach (widget->style, widget->window);
107 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
110 gtk_drawing_area_send_configure (GTK_DRAWING_AREA (widget));
114 gtk_drawing_area_size_allocate (GtkWidget *widget,
115 GtkAllocation *allocation)
117 g_return_if_fail (GTK_IS_DRAWING_AREA (widget));
118 g_return_if_fail (allocation != NULL);
120 widget->allocation = *allocation;
122 if (GTK_WIDGET_REALIZED (widget))
124 if (gtk_widget_get_has_window (widget))
125 gdk_window_move_resize (widget->window,
126 allocation->x, allocation->y,
127 allocation->width, allocation->height);
129 gtk_drawing_area_send_configure (GTK_DRAWING_AREA (widget));
134 gtk_drawing_area_send_configure (GtkDrawingArea *darea)
137 GdkEvent *event = gdk_event_new (GDK_CONFIGURE);
139 widget = GTK_WIDGET (darea);
141 event->configure.window = g_object_ref (widget->window);
142 event->configure.send_event = TRUE;
143 event->configure.x = widget->allocation.x;
144 event->configure.y = widget->allocation.y;
145 event->configure.width = widget->allocation.width;
146 event->configure.height = widget->allocation.height;
148 gtk_widget_event (widget, event);
149 gdk_event_free (event);
152 #define __GTK_DRAWING_AREA_C__
153 #include "gtkaliasdef.c"