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 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.
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.
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.
18 #include "gtkdrawingarea.h"
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);
29 gtk_drawing_area_get_type ()
31 static guint drawing_area_type = 0;
33 if (!drawing_area_type)
35 GtkTypeInfo drawing_area_info =
38 sizeof (GtkDrawingArea),
39 sizeof (GtkDrawingAreaClass),
40 (GtkClassInitFunc) gtk_drawing_area_class_init,
41 (GtkObjectInitFunc) gtk_drawing_area_init,
46 drawing_area_type = gtk_type_unique (gtk_widget_get_type (), &drawing_area_info);
49 return drawing_area_type;
53 gtk_drawing_area_class_init (GtkDrawingAreaClass *class)
55 GtkWidgetClass *widget_class;
57 widget_class = (GtkWidgetClass*) class;
59 widget_class->realize = gtk_drawing_area_realize;
60 widget_class->size_allocate = gtk_drawing_area_size_allocate;
64 gtk_drawing_area_init (GtkDrawingArea *darea)
66 GTK_WIDGET_SET_FLAGS (darea, GTK_BASIC);
71 gtk_drawing_area_new ()
73 return GTK_WIDGET (gtk_type_new (gtk_drawing_area_get_type ()));
77 gtk_drawing_area_size (GtkDrawingArea *darea,
81 g_return_if_fail (darea != NULL);
82 g_return_if_fail (GTK_IS_DRAWING_AREA (darea));
84 GTK_WIDGET (darea)->requisition.width = width;
85 GTK_WIDGET (darea)->requisition.height = height;
89 gtk_drawing_area_realize (GtkWidget *widget)
91 GtkDrawingArea *darea;
92 GdkWindowAttr attributes;
95 g_return_if_fail (widget != NULL);
96 g_return_if_fail (GTK_IS_DRAWING_AREA (widget));
98 darea = GTK_DRAWING_AREA (widget);
99 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
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);
111 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
113 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
114 gdk_window_set_user_data (widget->window, darea);
116 widget->style = gtk_style_attach (widget->style, widget->window);
117 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
121 gtk_drawing_area_size_allocate (GtkWidget *widget,
122 GtkAllocation *allocation)
124 GdkEventConfigure event;
126 g_return_if_fail (widget != NULL);
127 g_return_if_fail (GTK_IS_DRAWING_AREA (widget));
128 g_return_if_fail (allocation != NULL);
130 widget->allocation = *allocation;
132 if (GTK_WIDGET_REALIZED (widget))
134 gdk_window_move_resize (widget->window,
135 allocation->x, allocation->y,
136 allocation->width, allocation->height);
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;
145 gtk_widget_event (widget, (GdkEvent*) &event);