]> Pileus Git - ~andy/gtk/blob - gtk/gtkdrawingarea.c
gtk/gtkaction.c gtk/gtkassistant.c gtk/gtkbin.c gtk/gtkbox.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 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.
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  * Lesser General Public License for more details.
13  *
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.
18  */
19
20 /*
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/. 
25  */
26
27 #include <config.h>
28 #include "gtkdrawingarea.h"
29 #include "gtkintl.h"
30 #include "gtkalias.h"
31
32
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);
37
38 G_DEFINE_TYPE (GtkDrawingArea, gtk_drawing_area, GTK_TYPE_WIDGET)
39
40 static void
41 gtk_drawing_area_class_init (GtkDrawingAreaClass *class)
42 {
43   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
44
45   widget_class->realize = gtk_drawing_area_realize;
46   widget_class->size_allocate = gtk_drawing_area_size_allocate;
47 }
48
49 static void
50 gtk_drawing_area_init (GtkDrawingArea *darea)
51 {
52   darea->draw_data = NULL;
53 }
54
55
56 GtkWidget*
57 gtk_drawing_area_new (void)
58 {
59   return g_object_new (GTK_TYPE_DRAWING_AREA, NULL);
60 }
61
62 void
63 gtk_drawing_area_size (GtkDrawingArea *darea,
64                        gint            width,
65                        gint            height)
66 {
67   g_return_if_fail (GTK_IS_DRAWING_AREA (darea));
68
69   GTK_WIDGET (darea)->requisition.width = width;
70   GTK_WIDGET (darea)->requisition.height = height;
71
72   gtk_widget_queue_resize (GTK_WIDGET (darea));
73 }
74
75 static void
76 gtk_drawing_area_realize (GtkWidget *widget)
77 {
78   GtkDrawingArea *darea = GTK_DRAWING_AREA (widget);
79   GdkWindowAttr attributes;
80   gint attributes_mask;
81
82   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
83
84   attributes.window_type = GDK_WINDOW_CHILD;
85   attributes.x = widget->allocation.x;
86   attributes.y = widget->allocation.y;
87   attributes.width = widget->allocation.width;
88   attributes.height = widget->allocation.height;
89   attributes.wclass = GDK_INPUT_OUTPUT;
90   attributes.visual = gtk_widget_get_visual (widget);
91   attributes.colormap = gtk_widget_get_colormap (widget);
92   attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
93
94   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
95
96   widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
97   gdk_window_set_user_data (widget->window, darea);
98
99   widget->style = gtk_style_attach (widget->style, widget->window);
100   gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
101
102   gtk_drawing_area_send_configure (GTK_DRAWING_AREA (widget));
103 }
104
105 static void
106 gtk_drawing_area_size_allocate (GtkWidget     *widget,
107                                 GtkAllocation *allocation)
108 {
109   g_return_if_fail (GTK_IS_DRAWING_AREA (widget));
110   g_return_if_fail (allocation != NULL);
111
112   widget->allocation = *allocation;
113
114   if (GTK_WIDGET_REALIZED (widget))
115     {
116       gdk_window_move_resize (widget->window,
117                               allocation->x, allocation->y,
118                               allocation->width, allocation->height);
119
120       gtk_drawing_area_send_configure (GTK_DRAWING_AREA (widget));
121     }
122 }
123
124 static void
125 gtk_drawing_area_send_configure (GtkDrawingArea *darea)
126 {
127   GtkWidget *widget;
128   GdkEvent *event = gdk_event_new (GDK_CONFIGURE);
129
130   widget = GTK_WIDGET (darea);
131
132   event->configure.window = g_object_ref (widget->window);
133   event->configure.send_event = TRUE;
134   event->configure.x = widget->allocation.x;
135   event->configure.y = widget->allocation.y;
136   event->configure.width = widget->allocation.width;
137   event->configure.height = widget->allocation.height;
138   
139   gtk_widget_event (widget, event);
140   gdk_event_free (event);
141 }
142
143 #define __GTK_DRAWING_AREA_C__
144 #include "gtkaliasdef.c"