]> Pileus Git - ~andy/gtk/blob - gtk/gtkdrawingarea.c
Remove an unused pointer from GtkDrawingArea
[~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
31
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);
36
37 G_DEFINE_TYPE (GtkDrawingArea, gtk_drawing_area, GTK_TYPE_WIDGET)
38
39 static void
40 gtk_drawing_area_class_init (GtkDrawingAreaClass *class)
41 {
42   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
43
44   widget_class->realize = gtk_drawing_area_realize;
45   widget_class->size_allocate = gtk_drawing_area_size_allocate;
46 }
47
48 static void
49 gtk_drawing_area_init (GtkDrawingArea *darea)
50 {
51 }
52
53
54 GtkWidget*
55 gtk_drawing_area_new (void)
56 {
57   return g_object_new (GTK_TYPE_DRAWING_AREA, NULL);
58 }
59
60 static void
61 gtk_drawing_area_realize (GtkWidget *widget)
62 {
63   GtkDrawingArea *darea = GTK_DRAWING_AREA (widget);
64   GtkAllocation allocation;
65   GdkWindow *window;
66   GdkWindowAttr attributes;
67   gint attributes_mask;
68
69   if (!gtk_widget_get_has_window (widget))
70     {
71       GTK_WIDGET_CLASS (gtk_drawing_area_parent_class)->realize (widget);
72     }
73   else
74     {
75       gtk_widget_set_realized (widget, TRUE);
76
77       gtk_widget_get_allocation (widget, &allocation);
78
79       attributes.window_type = GDK_WINDOW_CHILD;
80       attributes.x = allocation.x;
81       attributes.y = allocation.y;
82       attributes.width = allocation.width;
83       attributes.height = allocation.height;
84       attributes.wclass = GDK_INPUT_OUTPUT;
85       attributes.visual = gtk_widget_get_visual (widget);
86       attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
87
88       attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
89
90       window = gdk_window_new (gtk_widget_get_parent_window (widget),
91                                &attributes, attributes_mask);
92       gdk_window_set_user_data (window, darea);
93       gtk_widget_set_window (widget, window);
94
95       gtk_widget_style_attach (widget);
96       gtk_style_set_background (gtk_widget_get_style (widget), window, GTK_STATE_NORMAL);
97     }
98
99   gtk_drawing_area_send_configure (GTK_DRAWING_AREA (widget));
100 }
101
102 static void
103 gtk_drawing_area_size_allocate (GtkWidget     *widget,
104                                 GtkAllocation *allocation)
105 {
106   g_return_if_fail (GTK_IS_DRAWING_AREA (widget));
107   g_return_if_fail (allocation != NULL);
108
109   gtk_widget_set_allocation (widget, allocation);
110
111   if (gtk_widget_get_realized (widget))
112     {
113       if (gtk_widget_get_has_window (widget))
114         gdk_window_move_resize (gtk_widget_get_window (widget),
115                                 allocation->x, allocation->y,
116                                 allocation->width, allocation->height);
117
118       gtk_drawing_area_send_configure (GTK_DRAWING_AREA (widget));
119     }
120 }
121
122 static void
123 gtk_drawing_area_send_configure (GtkDrawingArea *darea)
124 {
125   GtkAllocation allocation;
126   GtkWidget *widget;
127   GdkEvent *event = gdk_event_new (GDK_CONFIGURE);
128
129   widget = GTK_WIDGET (darea);
130   gtk_widget_get_allocation (widget, &allocation);
131
132   event->configure.window = g_object_ref (gtk_widget_get_window (widget));
133   event->configure.send_event = TRUE;
134   event->configure.x = allocation.x;
135   event->configure.y = allocation.y;
136   event->configure.width = allocation.width;
137   event->configure.height = allocation.height;
138   
139   gtk_widget_event (widget, event);
140   gdk_event_free (event);
141 }