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 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. |
---|
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 | * Library General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU Library 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-1999. 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 "gtkdrawingarea.h" |
---|
28 | |
---|
29 | |
---|
30 | static void gtk_drawing_area_class_init (GtkDrawingAreaClass *klass); |
---|
31 | static void gtk_drawing_area_init (GtkDrawingArea *darea); |
---|
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 | |
---|
38 | GtkType |
---|
39 | gtk_drawing_area_get_type (void) |
---|
40 | { |
---|
41 | static GtkType drawing_area_type = 0; |
---|
42 | |
---|
43 | if (!drawing_area_type) |
---|
44 | { |
---|
45 | static const GtkTypeInfo drawing_area_info = |
---|
46 | { |
---|
47 | "GtkDrawingArea", |
---|
48 | sizeof (GtkDrawingArea), |
---|
49 | sizeof (GtkDrawingAreaClass), |
---|
50 | (GtkClassInitFunc) gtk_drawing_area_class_init, |
---|
51 | (GtkObjectInitFunc) gtk_drawing_area_init, |
---|
52 | /* reserved_1 */ NULL, |
---|
53 | /* reserved_2 */ NULL, |
---|
54 | (GtkClassInitFunc) NULL, |
---|
55 | }; |
---|
56 | |
---|
57 | drawing_area_type = gtk_type_unique (GTK_TYPE_WIDGET, &drawing_area_info); |
---|
58 | } |
---|
59 | |
---|
60 | return drawing_area_type; |
---|
61 | } |
---|
62 | |
---|
63 | static void |
---|
64 | gtk_drawing_area_class_init (GtkDrawingAreaClass *class) |
---|
65 | { |
---|
66 | GtkWidgetClass *widget_class; |
---|
67 | |
---|
68 | widget_class = GTK_WIDGET_CLASS (class); |
---|
69 | |
---|
70 | widget_class->realize = gtk_drawing_area_realize; |
---|
71 | widget_class->size_allocate = gtk_drawing_area_size_allocate; |
---|
72 | } |
---|
73 | |
---|
74 | static void |
---|
75 | gtk_drawing_area_init (GtkDrawingArea *darea) |
---|
76 | { |
---|
77 | darea->draw_data = NULL; |
---|
78 | } |
---|
79 | |
---|
80 | |
---|
81 | GtkWidget* |
---|
82 | gtk_drawing_area_new (void) |
---|
83 | { |
---|
84 | return GTK_WIDGET (gtk_type_new (gtk_drawing_area_get_type ())); |
---|
85 | } |
---|
86 | |
---|
87 | void |
---|
88 | gtk_drawing_area_size (GtkDrawingArea *darea, |
---|
89 | gint width, |
---|
90 | gint height) |
---|
91 | { |
---|
92 | g_return_if_fail (GTK_IS_DRAWING_AREA (darea)); |
---|
93 | |
---|
94 | GTK_WIDGET (darea)->requisition.width = width; |
---|
95 | GTK_WIDGET (darea)->requisition.height = height; |
---|
96 | |
---|
97 | gtk_widget_queue_resize (GTK_WIDGET (darea)); |
---|
98 | } |
---|
99 | |
---|
100 | static void |
---|
101 | gtk_drawing_area_realize (GtkWidget *widget) |
---|
102 | { |
---|
103 | GtkDrawingArea *darea; |
---|
104 | GdkWindowAttr attributes; |
---|
105 | gint attributes_mask; |
---|
106 | |
---|
107 | g_return_if_fail (widget != NULL); |
---|
108 | g_return_if_fail (GTK_IS_DRAWING_AREA (widget)); |
---|
109 | |
---|
110 | darea = GTK_DRAWING_AREA (widget); |
---|
111 | GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); |
---|
112 | |
---|
113 | attributes.window_type = GDK_WINDOW_CHILD; |
---|
114 | attributes.x = widget->allocation.x; |
---|
115 | attributes.y = widget->allocation.y; |
---|
116 | attributes.width = widget->allocation.width; |
---|
117 | attributes.height = widget->allocation.height; |
---|
118 | attributes.wclass = GDK_INPUT_OUTPUT; |
---|
119 | attributes.visual = gtk_widget_get_visual (widget); |
---|
120 | attributes.colormap = gtk_widget_get_colormap (widget); |
---|
121 | attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK; |
---|
122 | |
---|
123 | attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; |
---|
124 | |
---|
125 | widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); |
---|
126 | gdk_window_set_user_data (widget->window, darea); |
---|
127 | |
---|
128 | widget->style = gtk_style_attach (widget->style, widget->window); |
---|
129 | gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); |
---|
130 | |
---|
131 | gtk_drawing_area_send_configure (GTK_DRAWING_AREA (widget)); |
---|
132 | } |
---|
133 | |
---|
134 | static void |
---|
135 | gtk_drawing_area_size_allocate (GtkWidget *widget, |
---|
136 | GtkAllocation *allocation) |
---|
137 | { |
---|
138 | g_return_if_fail (widget != NULL); |
---|
139 | g_return_if_fail (GTK_IS_DRAWING_AREA (widget)); |
---|
140 | g_return_if_fail (allocation != NULL); |
---|
141 | |
---|
142 | widget->allocation = *allocation; |
---|
143 | /* FIXME, TODO-1.3: back out the MAX() statements */ |
---|
144 | widget->allocation.width = MAX (1, widget->allocation.width); |
---|
145 | widget->allocation.height = MAX (1, widget->allocation.height); |
---|
146 | |
---|
147 | if (GTK_WIDGET_REALIZED (widget)) |
---|
148 | { |
---|
149 | gdk_window_move_resize (widget->window, |
---|
150 | allocation->x, allocation->y, |
---|
151 | allocation->width, allocation->height); |
---|
152 | |
---|
153 | gtk_drawing_area_send_configure (GTK_DRAWING_AREA (widget)); |
---|
154 | } |
---|
155 | } |
---|
156 | |
---|
157 | static void |
---|
158 | gtk_drawing_area_send_configure (GtkDrawingArea *darea) |
---|
159 | { |
---|
160 | GtkWidget *widget; |
---|
161 | GdkEventConfigure event; |
---|
162 | |
---|
163 | widget = GTK_WIDGET (darea); |
---|
164 | |
---|
165 | event.type = GDK_CONFIGURE; |
---|
166 | event.window = widget->window; |
---|
167 | event.send_event = TRUE; |
---|
168 | event.x = widget->allocation.x; |
---|
169 | event.y = widget->allocation.y; |
---|
170 | event.width = widget->allocation.width; |
---|
171 | event.height = widget->allocation.height; |
---|
172 | |
---|
173 | gtk_widget_event (widget, (GdkEvent*) &event); |
---|
174 | } |
---|