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 <stdarg.h> |
---|
28 | #include <string.h> |
---|
29 | #include "gtkcontainer.h" |
---|
30 | #include "gtkmain.h" |
---|
31 | #include "gtkrc.h" |
---|
32 | #include "gtkselection.h" |
---|
33 | #include "gtksignal.h" |
---|
34 | #include "gtkwidget.h" |
---|
35 | #include "gtkwindow.h" |
---|
36 | #include "gtkbindings.h" |
---|
37 | #include "gtkprivate.h" |
---|
38 | #include "gdk/gdk.h" |
---|
39 | #include "gdk/gdkx.h" |
---|
40 | |
---|
41 | |
---|
42 | #define WIDGET_CLASS(w) GTK_WIDGET_CLASS (GTK_OBJECT (w)->klass) |
---|
43 | #define INIT_PATH_SIZE (512) |
---|
44 | |
---|
45 | |
---|
46 | enum { |
---|
47 | SHOW, |
---|
48 | HIDE, |
---|
49 | MAP, |
---|
50 | UNMAP, |
---|
51 | REALIZE, |
---|
52 | UNREALIZE, |
---|
53 | DRAW, |
---|
54 | DRAW_FOCUS, |
---|
55 | DRAW_DEFAULT, |
---|
56 | SIZE_REQUEST, |
---|
57 | SIZE_ALLOCATE, |
---|
58 | STATE_CHANGED, |
---|
59 | PARENT_SET, |
---|
60 | STYLE_SET, |
---|
61 | ADD_ACCELERATOR, |
---|
62 | REMOVE_ACCELERATOR, |
---|
63 | GRAB_FOCUS, |
---|
64 | EVENT, |
---|
65 | BUTTON_PRESS_EVENT, |
---|
66 | BUTTON_RELEASE_EVENT, |
---|
67 | MOTION_NOTIFY_EVENT, |
---|
68 | DELETE_EVENT, |
---|
69 | DESTROY_EVENT, |
---|
70 | EXPOSE_EVENT, |
---|
71 | KEY_PRESS_EVENT, |
---|
72 | KEY_RELEASE_EVENT, |
---|
73 | ENTER_NOTIFY_EVENT, |
---|
74 | LEAVE_NOTIFY_EVENT, |
---|
75 | CONFIGURE_EVENT, |
---|
76 | FOCUS_IN_EVENT, |
---|
77 | FOCUS_OUT_EVENT, |
---|
78 | MAP_EVENT, |
---|
79 | UNMAP_EVENT, |
---|
80 | PROPERTY_NOTIFY_EVENT, |
---|
81 | SELECTION_CLEAR_EVENT, |
---|
82 | SELECTION_REQUEST_EVENT, |
---|
83 | SELECTION_NOTIFY_EVENT, |
---|
84 | SELECTION_GET, |
---|
85 | SELECTION_RECEIVED, |
---|
86 | PROXIMITY_IN_EVENT, |
---|
87 | PROXIMITY_OUT_EVENT, |
---|
88 | DRAG_BEGIN, |
---|
89 | DRAG_END, |
---|
90 | DRAG_DATA_DELETE, |
---|
91 | DRAG_LEAVE, |
---|
92 | DRAG_MOTION, |
---|
93 | DRAG_DROP, |
---|
94 | DRAG_DATA_GET, |
---|
95 | DRAG_DATA_RECEIVED, |
---|
96 | CLIENT_EVENT, |
---|
97 | NO_EXPOSE_EVENT, |
---|
98 | VISIBILITY_NOTIFY_EVENT, |
---|
99 | DEBUG_MSG, |
---|
100 | LAST_SIGNAL |
---|
101 | }; |
---|
102 | |
---|
103 | enum { |
---|
104 | ARG_0, |
---|
105 | ARG_NAME, |
---|
106 | ARG_PARENT, |
---|
107 | ARG_X, |
---|
108 | ARG_Y, |
---|
109 | ARG_WIDTH, |
---|
110 | ARG_HEIGHT, |
---|
111 | ARG_VISIBLE, |
---|
112 | ARG_SENSITIVE, |
---|
113 | ARG_APP_PAINTABLE, |
---|
114 | ARG_CAN_FOCUS, |
---|
115 | ARG_HAS_FOCUS, |
---|
116 | ARG_CAN_DEFAULT, |
---|
117 | ARG_HAS_DEFAULT, |
---|
118 | ARG_RECEIVES_DEFAULT, |
---|
119 | ARG_COMPOSITE_CHILD, |
---|
120 | ARG_STYLE, |
---|
121 | ARG_EVENTS, |
---|
122 | ARG_EXTENSION_EVENTS |
---|
123 | }; |
---|
124 | |
---|
125 | typedef struct _GtkStateData GtkStateData; |
---|
126 | |
---|
127 | struct _GtkStateData |
---|
128 | { |
---|
129 | GtkStateType state; |
---|
130 | guint state_restoration : 1; |
---|
131 | guint parent_sensitive : 1; |
---|
132 | guint use_forall : 1; |
---|
133 | }; |
---|
134 | |
---|
135 | static void gtk_widget_class_init (GtkWidgetClass *klass); |
---|
136 | static void gtk_widget_init (GtkWidget *widget); |
---|
137 | static void gtk_widget_set_arg (GtkObject *object, |
---|
138 | GtkArg *arg, |
---|
139 | guint arg_id); |
---|
140 | static void gtk_widget_get_arg (GtkObject *object, |
---|
141 | GtkArg *arg, |
---|
142 | guint arg_id); |
---|
143 | static void gtk_widget_shutdown (GtkObject *object); |
---|
144 | static void gtk_widget_real_destroy (GtkObject *object); |
---|
145 | static void gtk_widget_finalize (GtkObject *object); |
---|
146 | static void gtk_widget_real_show (GtkWidget *widget); |
---|
147 | static void gtk_widget_real_hide (GtkWidget *widget); |
---|
148 | static void gtk_widget_real_map (GtkWidget *widget); |
---|
149 | static void gtk_widget_real_unmap (GtkWidget *widget); |
---|
150 | static void gtk_widget_real_realize (GtkWidget *widget); |
---|
151 | static void gtk_widget_real_unrealize (GtkWidget *widget); |
---|
152 | static void gtk_widget_real_draw (GtkWidget *widget, |
---|
153 | GdkRectangle *area); |
---|
154 | static void gtk_widget_real_size_request (GtkWidget *widget, |
---|
155 | GtkRequisition *requisition); |
---|
156 | static void gtk_widget_real_size_allocate (GtkWidget *widget, |
---|
157 | GtkAllocation *allocation); |
---|
158 | static gint gtk_widget_real_key_press_event (GtkWidget *widget, |
---|
159 | GdkEventKey *event); |
---|
160 | static gint gtk_widget_real_key_release_event (GtkWidget *widget, |
---|
161 | GdkEventKey *event); |
---|
162 | static void gtk_widget_style_set (GtkWidget *widget, |
---|
163 | GtkStyle *previous_style); |
---|
164 | static void gtk_widget_real_grab_focus (GtkWidget *focus_widget); |
---|
165 | |
---|
166 | static void gtk_widget_redraw_queue_remove (GtkWidget *widget); |
---|
167 | |
---|
168 | |
---|
169 | static GdkColormap* gtk_widget_peek_colormap (void); |
---|
170 | static GdkVisual* gtk_widget_peek_visual (void); |
---|
171 | static GtkStyle* gtk_widget_peek_style (void); |
---|
172 | |
---|
173 | static void gtk_widget_reparent_container_child (GtkWidget *widget, |
---|
174 | gpointer client_data); |
---|
175 | static void gtk_widget_propagate_state (GtkWidget *widget, |
---|
176 | GtkStateData *data); |
---|
177 | static void gtk_widget_set_style_internal (GtkWidget *widget, |
---|
178 | GtkStyle *style, |
---|
179 | gboolean initial_emission); |
---|
180 | static void gtk_widget_set_style_recurse (GtkWidget *widget, |
---|
181 | gpointer client_data); |
---|
182 | |
---|
183 | static gboolean gtk_widget_is_offscreen (GtkWidget *widget); |
---|
184 | |
---|
185 | static GtkWidgetAuxInfo* gtk_widget_aux_info_new (void); |
---|
186 | static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info); |
---|
187 | |
---|
188 | static GtkObjectClass *parent_class = NULL; |
---|
189 | static guint widget_signals[LAST_SIGNAL] = { 0 }; |
---|
190 | |
---|
191 | static GMemChunk *aux_info_mem_chunk = NULL; |
---|
192 | |
---|
193 | static GdkColormap *default_colormap = NULL; |
---|
194 | static GdkVisual *default_visual = NULL; |
---|
195 | static GtkStyle *gtk_default_style = NULL; |
---|
196 | |
---|
197 | static GSList *colormap_stack = NULL; |
---|
198 | static GSList *visual_stack = NULL; |
---|
199 | static GSList *style_stack = NULL; |
---|
200 | static guint composite_child_stack = 0; |
---|
201 | static GSList *gtk_widget_redraw_queue = NULL; |
---|
202 | |
---|
203 | static const gchar *aux_info_key = "gtk-aux-info"; |
---|
204 | static guint aux_info_key_id = 0; |
---|
205 | static const gchar *event_key = "gtk-event-mask"; |
---|
206 | static guint event_key_id = 0; |
---|
207 | static const gchar *extension_event_key = "gtk-extension-event-mode"; |
---|
208 | static guint extension_event_key_id = 0; |
---|
209 | static const gchar *parent_window_key = "gtk-parent-window"; |
---|
210 | static guint parent_window_key_id = 0; |
---|
211 | static const gchar *saved_default_style_key = "gtk-saved-default-style"; |
---|
212 | static guint saved_default_style_key_id = 0; |
---|
213 | static const gchar *shape_info_key = "gtk-shape-info"; |
---|
214 | static const gchar *colormap_key = "gtk-colormap"; |
---|
215 | static const gchar *visual_key = "gtk-visual"; |
---|
216 | |
---|
217 | static const gchar *rc_style_key = "gtk-rc-style"; |
---|
218 | static guint rc_style_key_id = 0; |
---|
219 | |
---|
220 | /***************************************** |
---|
221 | * gtk_widget_get_type: |
---|
222 | * |
---|
223 | * arguments: |
---|
224 | * |
---|
225 | * results: |
---|
226 | *****************************************/ |
---|
227 | |
---|
228 | GtkType |
---|
229 | gtk_widget_get_type (void) |
---|
230 | { |
---|
231 | static GtkType widget_type = 0; |
---|
232 | |
---|
233 | if (!widget_type) |
---|
234 | { |
---|
235 | static const GtkTypeInfo widget_info = |
---|
236 | { |
---|
237 | "GtkWidget", |
---|
238 | sizeof (GtkWidget), |
---|
239 | sizeof (GtkWidgetClass), |
---|
240 | (GtkClassInitFunc) gtk_widget_class_init, |
---|
241 | (GtkObjectInitFunc) gtk_widget_init, |
---|
242 | /* reserved_1 */ NULL, |
---|
243 | /* reserved_2 */ NULL, |
---|
244 | (GtkClassInitFunc) NULL, |
---|
245 | }; |
---|
246 | |
---|
247 | widget_type = gtk_type_unique (gtk_object_get_type (), &widget_info); |
---|
248 | } |
---|
249 | |
---|
250 | return widget_type; |
---|
251 | } |
---|
252 | |
---|
253 | /***************************************** |
---|
254 | * gtk_widget_class_init: |
---|
255 | * |
---|
256 | * arguments: |
---|
257 | * |
---|
258 | * results: |
---|
259 | *****************************************/ |
---|
260 | #include "stdio.h" |
---|
261 | static void |
---|
262 | gtk_widget_debug_msg (GtkWidget *widget, |
---|
263 | const gchar *string) |
---|
264 | { |
---|
265 | fprintf (stderr, "Gtk-DEBUG: %s\n", string); |
---|
266 | } |
---|
267 | |
---|
268 | static void |
---|
269 | gtk_widget_class_init (GtkWidgetClass *klass) |
---|
270 | { |
---|
271 | GtkObjectClass *object_class; |
---|
272 | |
---|
273 | object_class = (GtkObjectClass*) klass; |
---|
274 | |
---|
275 | parent_class = gtk_type_class (gtk_object_get_type ()); |
---|
276 | |
---|
277 | gtk_object_add_arg_type ("GtkWidget::name", GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_NAME); |
---|
278 | gtk_object_add_arg_type ("GtkWidget::parent", GTK_TYPE_CONTAINER, GTK_ARG_READWRITE, ARG_PARENT); |
---|
279 | gtk_object_add_arg_type ("GtkWidget::x", GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_X); |
---|
280 | gtk_object_add_arg_type ("GtkWidget::y", GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_Y); |
---|
281 | gtk_object_add_arg_type ("GtkWidget::width", GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_WIDTH); |
---|
282 | gtk_object_add_arg_type ("GtkWidget::height", GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_HEIGHT); |
---|
283 | gtk_object_add_arg_type ("GtkWidget::visible", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_VISIBLE); |
---|
284 | gtk_object_add_arg_type ("GtkWidget::sensitive", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_SENSITIVE); |
---|
285 | gtk_object_add_arg_type ("GtkWidget::app_paintable", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_APP_PAINTABLE); |
---|
286 | gtk_object_add_arg_type ("GtkWidget::can_focus", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_CAN_FOCUS); |
---|
287 | gtk_object_add_arg_type ("GtkWidget::has_focus", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_HAS_FOCUS); |
---|
288 | gtk_object_add_arg_type ("GtkWidget::can_default", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_CAN_DEFAULT); |
---|
289 | gtk_object_add_arg_type ("GtkWidget::has_default", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_HAS_DEFAULT); |
---|
290 | gtk_object_add_arg_type ("GtkWidget::receives_default", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_RECEIVES_DEFAULT); |
---|
291 | gtk_object_add_arg_type ("GtkWidget::composite_child", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_COMPOSITE_CHILD); |
---|
292 | gtk_object_add_arg_type ("GtkWidget::style", GTK_TYPE_STYLE, GTK_ARG_READWRITE, ARG_STYLE); |
---|
293 | gtk_object_add_arg_type ("GtkWidget::events", GTK_TYPE_GDK_EVENT_MASK, GTK_ARG_READWRITE, ARG_EVENTS); |
---|
294 | gtk_object_add_arg_type ("GtkWidget::extension_events", GTK_TYPE_GDK_EVENT_MASK, GTK_ARG_READWRITE, ARG_EXTENSION_EVENTS); |
---|
295 | |
---|
296 | widget_signals[SHOW] = |
---|
297 | gtk_signal_new ("show", |
---|
298 | GTK_RUN_FIRST, |
---|
299 | object_class->type, |
---|
300 | GTK_SIGNAL_OFFSET (GtkWidgetClass, show), |
---|
301 | gtk_marshal_NONE__NONE, |
---|
302 | GTK_TYPE_NONE, 0); |
---|
303 | widget_signals[HIDE] = |
---|
304 | gtk_signal_new ("hide", |
---|
305 | GTK_RUN_FIRST, |
---|
306 | object_class->type, |
---|
307 | GTK_SIGNAL_OFFSET (GtkWidgetClass, hide), |
---|
308 | gtk_marshal_NONE__NONE, |
---|
309 | GTK_TYPE_NONE, 0); |
---|
310 | widget_signals[MAP] = |
---|
311 | gtk_signal_new ("map", |
---|
312 | GTK_RUN_FIRST, |
---|
313 | object_class->type, |
---|
314 | GTK_SIGNAL_OFFSET (GtkWidgetClass, map), |
---|
315 | gtk_marshal_NONE__NONE, |
---|
316 | GTK_TYPE_NONE, 0); |
---|
317 | widget_signals[UNMAP] = |
---|
318 | gtk_signal_new ("unmap", |
---|
319 | GTK_RUN_FIRST, |
---|
320 | object_class->type, |
---|
321 | GTK_SIGNAL_OFFSET (GtkWidgetClass, unmap), |
---|
322 | gtk_marshal_NONE__NONE, |
---|
323 | GTK_TYPE_NONE, 0); |
---|
324 | widget_signals[REALIZE] = |
---|
325 | gtk_signal_new ("realize", |
---|
326 | GTK_RUN_FIRST, |
---|
327 | object_class->type, |
---|
328 | GTK_SIGNAL_OFFSET (GtkWidgetClass, realize), |
---|
329 | gtk_marshal_NONE__NONE, |
---|
330 | GTK_TYPE_NONE, 0); |
---|
331 | widget_signals[UNREALIZE] = |
---|
332 | gtk_signal_new ("unrealize", |
---|
333 | GTK_RUN_FIRST, |
---|
334 | object_class->type, |
---|
335 | GTK_SIGNAL_OFFSET (GtkWidgetClass, unrealize), |
---|
336 | gtk_marshal_NONE__NONE, |
---|
337 | GTK_TYPE_NONE, 0); |
---|
338 | widget_signals[DRAW] = |
---|
339 | gtk_signal_new ("draw", |
---|
340 | GTK_RUN_FIRST, |
---|
341 | object_class->type, |
---|
342 | GTK_SIGNAL_OFFSET (GtkWidgetClass, draw), |
---|
343 | gtk_marshal_NONE__POINTER, |
---|
344 | GTK_TYPE_NONE, 1, |
---|
345 | GTK_TYPE_POINTER); |
---|
346 | widget_signals[DRAW_FOCUS] = |
---|
347 | gtk_signal_new ("draw_focus", |
---|
348 | GTK_RUN_FIRST, |
---|
349 | object_class->type, |
---|
350 | GTK_SIGNAL_OFFSET (GtkWidgetClass, draw_focus), |
---|
351 | gtk_marshal_NONE__NONE, |
---|
352 | GTK_TYPE_NONE, 0); |
---|
353 | widget_signals[DRAW_DEFAULT] = |
---|
354 | gtk_signal_new ("draw_default", |
---|
355 | GTK_RUN_FIRST, |
---|
356 | object_class->type, |
---|
357 | GTK_SIGNAL_OFFSET (GtkWidgetClass, draw_default), |
---|
358 | gtk_marshal_NONE__NONE, |
---|
359 | GTK_TYPE_NONE, 0); |
---|
360 | widget_signals[SIZE_REQUEST] = |
---|
361 | gtk_signal_new ("size_request", |
---|
362 | GTK_RUN_FIRST, |
---|
363 | object_class->type, |
---|
364 | GTK_SIGNAL_OFFSET (GtkWidgetClass, size_request), |
---|
365 | gtk_marshal_NONE__POINTER, |
---|
366 | GTK_TYPE_NONE, 1, |
---|
367 | GTK_TYPE_POINTER); |
---|
368 | widget_signals[SIZE_ALLOCATE] = |
---|
369 | gtk_signal_new ("size_allocate", |
---|
370 | GTK_RUN_FIRST, |
---|
371 | object_class->type, |
---|
372 | GTK_SIGNAL_OFFSET (GtkWidgetClass, size_allocate), |
---|
373 | gtk_marshal_NONE__POINTER, |
---|
374 | GTK_TYPE_NONE, 1, |
---|
375 | GTK_TYPE_POINTER); |
---|
376 | widget_signals[STATE_CHANGED] = |
---|
377 | gtk_signal_new ("state_changed", |
---|
378 | GTK_RUN_FIRST, |
---|
379 | object_class->type, |
---|
380 | GTK_SIGNAL_OFFSET (GtkWidgetClass, state_changed), |
---|
381 | gtk_marshal_NONE__UINT, |
---|
382 | GTK_TYPE_NONE, 1, |
---|
383 | GTK_TYPE_STATE_TYPE); |
---|
384 | widget_signals[PARENT_SET] = |
---|
385 | gtk_signal_new ("parent_set", |
---|
386 | GTK_RUN_FIRST, |
---|
387 | object_class->type, |
---|
388 | GTK_SIGNAL_OFFSET (GtkWidgetClass, parent_set), |
---|
389 | gtk_marshal_NONE__OBJECT, |
---|
390 | GTK_TYPE_NONE, 1, |
---|
391 | GTK_TYPE_OBJECT); |
---|
392 | widget_signals[STYLE_SET] = |
---|
393 | gtk_signal_new ("style_set", |
---|
394 | GTK_RUN_FIRST, |
---|
395 | object_class->type, |
---|
396 | GTK_SIGNAL_OFFSET (GtkWidgetClass, style_set), |
---|
397 | gtk_marshal_NONE__POINTER, |
---|
398 | GTK_TYPE_NONE, 1, |
---|
399 | GTK_TYPE_STYLE); |
---|
400 | widget_signals[ADD_ACCELERATOR] = |
---|
401 | gtk_accel_group_create_add (object_class->type, GTK_RUN_LAST, |
---|
402 | GTK_SIGNAL_OFFSET (GtkWidgetClass, add_accelerator)); |
---|
403 | widget_signals[REMOVE_ACCELERATOR] = |
---|
404 | gtk_accel_group_create_remove (object_class->type, GTK_RUN_LAST, |
---|
405 | GTK_SIGNAL_OFFSET (GtkWidgetClass, remove_accelerator)); |
---|
406 | widget_signals[GRAB_FOCUS] = |
---|
407 | gtk_signal_new ("grab_focus", |
---|
408 | GTK_RUN_LAST | GTK_RUN_ACTION, |
---|
409 | object_class->type, |
---|
410 | GTK_SIGNAL_OFFSET (GtkWidgetClass, grab_focus), |
---|
411 | gtk_marshal_NONE__NONE, |
---|
412 | GTK_TYPE_NONE, 0); |
---|
413 | widget_signals[EVENT] = |
---|
414 | gtk_signal_new ("event", |
---|
415 | GTK_RUN_LAST, |
---|
416 | object_class->type, |
---|
417 | GTK_SIGNAL_OFFSET (GtkWidgetClass, event), |
---|
418 | gtk_marshal_BOOL__POINTER, |
---|
419 | GTK_TYPE_BOOL, 1, |
---|
420 | GTK_TYPE_GDK_EVENT); |
---|
421 | widget_signals[BUTTON_PRESS_EVENT] = |
---|
422 | gtk_signal_new ("button_press_event", |
---|
423 | GTK_RUN_LAST, |
---|
424 | object_class->type, |
---|
425 | GTK_SIGNAL_OFFSET (GtkWidgetClass, button_press_event), |
---|
426 | gtk_marshal_BOOL__POINTER, |
---|
427 | GTK_TYPE_BOOL, 1, |
---|
428 | GTK_TYPE_GDK_EVENT); |
---|
429 | widget_signals[BUTTON_RELEASE_EVENT] = |
---|
430 | gtk_signal_new ("button_release_event", |
---|
431 | GTK_RUN_LAST, |
---|
432 | object_class->type, |
---|
433 | GTK_SIGNAL_OFFSET (GtkWidgetClass, button_release_event), |
---|
434 | gtk_marshal_BOOL__POINTER, |
---|
435 | GTK_TYPE_BOOL, 1, |
---|
436 | GTK_TYPE_GDK_EVENT); |
---|
437 | widget_signals[MOTION_NOTIFY_EVENT] = |
---|
438 | gtk_signal_new ("motion_notify_event", |
---|
439 | GTK_RUN_LAST, |
---|
440 | object_class->type, |
---|
441 | GTK_SIGNAL_OFFSET (GtkWidgetClass, motion_notify_event), |
---|
442 | gtk_marshal_BOOL__POINTER, |
---|
443 | GTK_TYPE_BOOL, 1, |
---|
444 | GTK_TYPE_GDK_EVENT); |
---|
445 | widget_signals[DELETE_EVENT] = |
---|
446 | gtk_signal_new ("delete_event", |
---|
447 | GTK_RUN_LAST, |
---|
448 | object_class->type, |
---|
449 | GTK_SIGNAL_OFFSET (GtkWidgetClass, delete_event), |
---|
450 | gtk_marshal_BOOL__POINTER, |
---|
451 | GTK_TYPE_BOOL, 1, |
---|
452 | GTK_TYPE_GDK_EVENT); |
---|
453 | widget_signals[DESTROY_EVENT] = |
---|
454 | gtk_signal_new ("destroy_event", |
---|
455 | GTK_RUN_LAST, |
---|
456 | object_class->type, |
---|
457 | GTK_SIGNAL_OFFSET (GtkWidgetClass, destroy_event), |
---|
458 | gtk_marshal_BOOL__POINTER, |
---|
459 | GTK_TYPE_BOOL, 1, |
---|
460 | GTK_TYPE_GDK_EVENT); |
---|
461 | widget_signals[EXPOSE_EVENT] = |
---|
462 | gtk_signal_new ("expose_event", |
---|
463 | GTK_RUN_LAST, |
---|
464 | object_class->type, |
---|
465 | GTK_SIGNAL_OFFSET (GtkWidgetClass, expose_event), |
---|
466 | gtk_marshal_BOOL__POINTER, |
---|
467 | GTK_TYPE_BOOL, 1, |
---|
468 | GTK_TYPE_GDK_EVENT); |
---|
469 | widget_signals[KEY_PRESS_EVENT] = |
---|
470 | gtk_signal_new ("key_press_event", |
---|
471 | GTK_RUN_LAST, |
---|
472 | object_class->type, |
---|
473 | GTK_SIGNAL_OFFSET (GtkWidgetClass, key_press_event), |
---|
474 | gtk_marshal_BOOL__POINTER, |
---|
475 | GTK_TYPE_BOOL, 1, |
---|
476 | GTK_TYPE_GDK_EVENT); |
---|
477 | widget_signals[KEY_RELEASE_EVENT] = |
---|
478 | gtk_signal_new ("key_release_event", |
---|
479 | GTK_RUN_LAST, |
---|
480 | object_class->type, |
---|
481 | GTK_SIGNAL_OFFSET (GtkWidgetClass, key_release_event), |
---|
482 | gtk_marshal_BOOL__POINTER, |
---|
483 | GTK_TYPE_BOOL, 1, |
---|
484 | GTK_TYPE_GDK_EVENT); |
---|
485 | widget_signals[ENTER_NOTIFY_EVENT] = |
---|
486 | gtk_signal_new ("enter_notify_event", |
---|
487 | GTK_RUN_LAST, |
---|
488 | object_class->type, |
---|
489 | GTK_SIGNAL_OFFSET (GtkWidgetClass, enter_notify_event), |
---|
490 | gtk_marshal_BOOL__POINTER, |
---|
491 | GTK_TYPE_BOOL, 1, |
---|
492 | GTK_TYPE_GDK_EVENT); |
---|
493 | widget_signals[LEAVE_NOTIFY_EVENT] = |
---|
494 | gtk_signal_new ("leave_notify_event", |
---|
495 | GTK_RUN_LAST, |
---|
496 | object_class->type, |
---|
497 | GTK_SIGNAL_OFFSET (GtkWidgetClass, leave_notify_event), |
---|
498 | gtk_marshal_BOOL__POINTER, |
---|
499 | GTK_TYPE_BOOL, 1, |
---|
500 | GTK_TYPE_GDK_EVENT); |
---|
501 | widget_signals[CONFIGURE_EVENT] = |
---|
502 | gtk_signal_new ("configure_event", |
---|
503 | GTK_RUN_LAST, |
---|
504 | object_class->type, |
---|
505 | GTK_SIGNAL_OFFSET (GtkWidgetClass, configure_event), |
---|
506 | gtk_marshal_BOOL__POINTER, |
---|
507 | GTK_TYPE_BOOL, 1, |
---|
508 | GTK_TYPE_GDK_EVENT); |
---|
509 | widget_signals[FOCUS_IN_EVENT] = |
---|
510 | gtk_signal_new ("focus_in_event", |
---|
511 | GTK_RUN_LAST, |
---|
512 | object_class->type, |
---|
513 | GTK_SIGNAL_OFFSET (GtkWidgetClass, focus_in_event), |
---|
514 | gtk_marshal_BOOL__POINTER, |
---|
515 | GTK_TYPE_BOOL, 1, |
---|
516 | GTK_TYPE_GDK_EVENT); |
---|
517 | widget_signals[FOCUS_OUT_EVENT] = |
---|
518 | gtk_signal_new ("focus_out_event", |
---|
519 | GTK_RUN_LAST, |
---|
520 | object_class->type, |
---|
521 | GTK_SIGNAL_OFFSET (GtkWidgetClass, focus_out_event), |
---|
522 | gtk_marshal_BOOL__POINTER, |
---|
523 | GTK_TYPE_BOOL, 1, |
---|
524 | GTK_TYPE_GDK_EVENT); |
---|
525 | widget_signals[MAP_EVENT] = |
---|
526 | gtk_signal_new ("map_event", |
---|
527 | GTK_RUN_LAST, |
---|
528 | object_class->type, |
---|
529 | GTK_SIGNAL_OFFSET (GtkWidgetClass, map_event), |
---|
530 | gtk_marshal_BOOL__POINTER, |
---|
531 | GTK_TYPE_BOOL, 1, |
---|
532 | GTK_TYPE_GDK_EVENT); |
---|
533 | widget_signals[UNMAP_EVENT] = |
---|
534 | gtk_signal_new ("unmap_event", |
---|
535 | GTK_RUN_LAST, |
---|
536 | object_class->type, |
---|
537 | GTK_SIGNAL_OFFSET (GtkWidgetClass, unmap_event), |
---|
538 | gtk_marshal_BOOL__POINTER, |
---|
539 | GTK_TYPE_BOOL, 1, |
---|
540 | GTK_TYPE_GDK_EVENT); |
---|
541 | widget_signals[PROPERTY_NOTIFY_EVENT] = |
---|
542 | gtk_signal_new ("property_notify_event", |
---|
543 | GTK_RUN_LAST, |
---|
544 | object_class->type, |
---|
545 | GTK_SIGNAL_OFFSET (GtkWidgetClass, property_notify_event), |
---|
546 | gtk_marshal_BOOL__POINTER, |
---|
547 | GTK_TYPE_BOOL, 1, |
---|
548 | GTK_TYPE_GDK_EVENT); |
---|
549 | widget_signals[SELECTION_CLEAR_EVENT] = |
---|
550 | gtk_signal_new ("selection_clear_event", |
---|
551 | GTK_RUN_LAST, |
---|
552 | object_class->type, |
---|
553 | GTK_SIGNAL_OFFSET (GtkWidgetClass, selection_clear_event), |
---|
554 | gtk_marshal_BOOL__POINTER, |
---|
555 | GTK_TYPE_BOOL, 1, |
---|
556 | GTK_TYPE_GDK_EVENT); |
---|
557 | widget_signals[SELECTION_REQUEST_EVENT] = |
---|
558 | gtk_signal_new ("selection_request_event", |
---|
559 | GTK_RUN_LAST, |
---|
560 | object_class->type, |
---|
561 | GTK_SIGNAL_OFFSET (GtkWidgetClass, selection_request_event), |
---|
562 | gtk_marshal_BOOL__POINTER, |
---|
563 | GTK_TYPE_BOOL, 1, |
---|
564 | GTK_TYPE_GDK_EVENT); |
---|
565 | widget_signals[SELECTION_NOTIFY_EVENT] = |
---|
566 | gtk_signal_new ("selection_notify_event", |
---|
567 | GTK_RUN_LAST, |
---|
568 | object_class->type, |
---|
569 | GTK_SIGNAL_OFFSET (GtkWidgetClass, selection_notify_event), |
---|
570 | gtk_marshal_BOOL__POINTER, |
---|
571 | GTK_TYPE_BOOL, 1, |
---|
572 | GTK_TYPE_GDK_EVENT); |
---|
573 | widget_signals[SELECTION_RECEIVED] = |
---|
574 | gtk_signal_new ("selection_received", |
---|
575 | GTK_RUN_LAST, |
---|
576 | object_class->type, |
---|
577 | GTK_SIGNAL_OFFSET (GtkWidgetClass, selection_received), |
---|
578 | gtk_marshal_NONE__POINTER_UINT, |
---|
579 | GTK_TYPE_NONE, 2, |
---|
580 | GTK_TYPE_SELECTION_DATA, |
---|
581 | GTK_TYPE_UINT); |
---|
582 | widget_signals[SELECTION_GET] = |
---|
583 | gtk_signal_new ("selection_get", |
---|
584 | GTK_RUN_LAST, |
---|
585 | object_class->type, |
---|
586 | GTK_SIGNAL_OFFSET (GtkWidgetClass, selection_get), |
---|
587 | gtk_marshal_NONE__POINTER_UINT_UINT, |
---|
588 | GTK_TYPE_NONE, 3, |
---|
589 | GTK_TYPE_SELECTION_DATA, |
---|
590 | GTK_TYPE_UINT, |
---|
591 | GTK_TYPE_UINT); |
---|
592 | widget_signals[PROXIMITY_IN_EVENT] = |
---|
593 | gtk_signal_new ("proximity_in_event", |
---|
594 | GTK_RUN_LAST, |
---|
595 | object_class->type, |
---|
596 | GTK_SIGNAL_OFFSET (GtkWidgetClass, proximity_in_event), |
---|
597 | gtk_marshal_BOOL__POINTER, |
---|
598 | GTK_TYPE_BOOL, 1, |
---|
599 | GTK_TYPE_GDK_EVENT); |
---|
600 | widget_signals[PROXIMITY_OUT_EVENT] = |
---|
601 | gtk_signal_new ("proximity_out_event", |
---|
602 | GTK_RUN_LAST, |
---|
603 | object_class->type, |
---|
604 | GTK_SIGNAL_OFFSET (GtkWidgetClass, proximity_out_event), |
---|
605 | gtk_marshal_BOOL__POINTER, |
---|
606 | GTK_TYPE_BOOL, 1, |
---|
607 | GTK_TYPE_GDK_EVENT); |
---|
608 | widget_signals[DRAG_LEAVE] = |
---|
609 | gtk_signal_new ("drag_leave", |
---|
610 | GTK_RUN_LAST, |
---|
611 | object_class->type, |
---|
612 | GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_leave), |
---|
613 | gtk_marshal_NONE__POINTER_UINT, |
---|
614 | GTK_TYPE_NONE, 2, |
---|
615 | GTK_TYPE_GDK_DRAG_CONTEXT, |
---|
616 | GTK_TYPE_UINT); |
---|
617 | widget_signals[DRAG_BEGIN] = |
---|
618 | gtk_signal_new ("drag_begin", |
---|
619 | GTK_RUN_LAST, |
---|
620 | object_class->type, |
---|
621 | GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_begin), |
---|
622 | gtk_marshal_NONE__POINTER, |
---|
623 | GTK_TYPE_NONE, 1, |
---|
624 | GTK_TYPE_GDK_DRAG_CONTEXT); |
---|
625 | widget_signals[DRAG_END] = |
---|
626 | gtk_signal_new ("drag_end", |
---|
627 | GTK_RUN_LAST, |
---|
628 | object_class->type, |
---|
629 | GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_end), |
---|
630 | gtk_marshal_NONE__POINTER, |
---|
631 | GTK_TYPE_NONE, 1, |
---|
632 | GTK_TYPE_GDK_DRAG_CONTEXT); |
---|
633 | widget_signals[DRAG_DATA_DELETE] = |
---|
634 | gtk_signal_new ("drag_data_delete", |
---|
635 | GTK_RUN_LAST, |
---|
636 | object_class->type, |
---|
637 | GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_data_delete), |
---|
638 | gtk_marshal_NONE__POINTER, |
---|
639 | GTK_TYPE_NONE, 1, |
---|
640 | GTK_TYPE_GDK_DRAG_CONTEXT); |
---|
641 | widget_signals[DRAG_MOTION] = |
---|
642 | gtk_signal_new ("drag_motion", |
---|
643 | GTK_RUN_LAST, |
---|
644 | object_class->type, |
---|
645 | GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_motion), |
---|
646 | gtk_marshal_BOOL__POINTER_INT_INT_UINT, |
---|
647 | GTK_TYPE_BOOL, 4, |
---|
648 | GTK_TYPE_GDK_DRAG_CONTEXT, |
---|
649 | GTK_TYPE_INT, |
---|
650 | GTK_TYPE_INT, |
---|
651 | GTK_TYPE_UINT); |
---|
652 | widget_signals[DRAG_DROP] = |
---|
653 | gtk_signal_new ("drag_drop", |
---|
654 | GTK_RUN_LAST, |
---|
655 | object_class->type, |
---|
656 | GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_drop), |
---|
657 | gtk_marshal_BOOL__POINTER_INT_INT_UINT, |
---|
658 | GTK_TYPE_BOOL, 4, |
---|
659 | GTK_TYPE_GDK_DRAG_CONTEXT, |
---|
660 | GTK_TYPE_INT, |
---|
661 | GTK_TYPE_INT, |
---|
662 | GTK_TYPE_UINT); |
---|
663 | widget_signals[DRAG_DATA_GET] = |
---|
664 | gtk_signal_new ("drag_data_get", |
---|
665 | GTK_RUN_LAST, |
---|
666 | object_class->type, |
---|
667 | GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_data_get), |
---|
668 | gtk_marshal_NONE__POINTER_POINTER_UINT_UINT, |
---|
669 | GTK_TYPE_NONE, 4, |
---|
670 | GTK_TYPE_GDK_DRAG_CONTEXT, |
---|
671 | GTK_TYPE_SELECTION_DATA, |
---|
672 | GTK_TYPE_UINT, |
---|
673 | GTK_TYPE_UINT); |
---|
674 | widget_signals[DRAG_DATA_RECEIVED] = |
---|
675 | gtk_signal_new ("drag_data_received", |
---|
676 | GTK_RUN_LAST, |
---|
677 | object_class->type, |
---|
678 | GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_data_received), |
---|
679 | gtk_marshal_NONE__POINTER_INT_INT_POINTER_UINT_UINT, |
---|
680 | GTK_TYPE_NONE, 6, |
---|
681 | GTK_TYPE_GDK_DRAG_CONTEXT, |
---|
682 | GTK_TYPE_INT, |
---|
683 | GTK_TYPE_INT, |
---|
684 | GTK_TYPE_SELECTION_DATA, |
---|
685 | GTK_TYPE_UINT, |
---|
686 | GTK_TYPE_UINT); |
---|
687 | widget_signals[VISIBILITY_NOTIFY_EVENT] = |
---|
688 | gtk_signal_new ("visibility_notify_event", |
---|
689 | GTK_RUN_LAST, |
---|
690 | object_class->type, |
---|
691 | GTK_SIGNAL_OFFSET (GtkWidgetClass, visibility_notify_event), |
---|
692 | gtk_marshal_BOOL__POINTER, |
---|
693 | GTK_TYPE_BOOL, 1, |
---|
694 | GTK_TYPE_GDK_EVENT); |
---|
695 | widget_signals[CLIENT_EVENT] = |
---|
696 | gtk_signal_new ("client_event", |
---|
697 | GTK_RUN_LAST, |
---|
698 | object_class->type, |
---|
699 | GTK_SIGNAL_OFFSET (GtkWidgetClass, client_event), |
---|
700 | gtk_marshal_BOOL__POINTER, |
---|
701 | GTK_TYPE_BOOL, 1, |
---|
702 | GTK_TYPE_GDK_EVENT); |
---|
703 | widget_signals[NO_EXPOSE_EVENT] = |
---|
704 | gtk_signal_new ("no_expose_event", |
---|
705 | GTK_RUN_LAST, |
---|
706 | object_class->type, |
---|
707 | GTK_SIGNAL_OFFSET (GtkWidgetClass, no_expose_event), |
---|
708 | gtk_marshal_BOOL__POINTER, |
---|
709 | GTK_TYPE_BOOL, 1, |
---|
710 | GTK_TYPE_GDK_EVENT); |
---|
711 | widget_signals[DEBUG_MSG] = |
---|
712 | gtk_signal_new ("debug_msg", |
---|
713 | GTK_RUN_LAST | GTK_RUN_ACTION, |
---|
714 | object_class->type, |
---|
715 | GTK_SIGNAL_OFFSET (GtkWidgetClass, debug_msg), |
---|
716 | gtk_marshal_NONE__STRING, |
---|
717 | GTK_TYPE_NONE, 1, |
---|
718 | GTK_TYPE_STRING); |
---|
719 | |
---|
720 | gtk_object_class_add_signals (object_class, widget_signals, LAST_SIGNAL); |
---|
721 | |
---|
722 | object_class->set_arg = gtk_widget_set_arg; |
---|
723 | object_class->get_arg = gtk_widget_get_arg; |
---|
724 | object_class->shutdown = gtk_widget_shutdown; |
---|
725 | object_class->destroy = gtk_widget_real_destroy; |
---|
726 | object_class->finalize = gtk_widget_finalize; |
---|
727 | |
---|
728 | klass->activate_signal = 0; |
---|
729 | klass->set_scroll_adjustments_signal = 0; |
---|
730 | klass->show = gtk_widget_real_show; |
---|
731 | klass->show_all = gtk_widget_show; |
---|
732 | klass->hide = gtk_widget_real_hide; |
---|
733 | klass->hide_all = gtk_widget_hide; |
---|
734 | klass->map = gtk_widget_real_map; |
---|
735 | klass->unmap = gtk_widget_real_unmap; |
---|
736 | klass->realize = gtk_widget_real_realize; |
---|
737 | klass->unrealize = gtk_widget_real_unrealize; |
---|
738 | klass->draw = gtk_widget_real_draw; |
---|
739 | klass->draw_focus = NULL; |
---|
740 | klass->size_request = gtk_widget_real_size_request; |
---|
741 | klass->size_allocate = gtk_widget_real_size_allocate; |
---|
742 | klass->state_changed = NULL; |
---|
743 | klass->parent_set = NULL; |
---|
744 | klass->style_set = gtk_widget_style_set; |
---|
745 | klass->add_accelerator = (void*) gtk_accel_group_handle_add; |
---|
746 | klass->remove_accelerator = (void*) gtk_accel_group_handle_remove; |
---|
747 | klass->grab_focus = gtk_widget_real_grab_focus; |
---|
748 | klass->event = NULL; |
---|
749 | klass->button_press_event = NULL; |
---|
750 | klass->button_release_event = NULL; |
---|
751 | klass->motion_notify_event = NULL; |
---|
752 | klass->delete_event = NULL; |
---|
753 | klass->destroy_event = NULL; |
---|
754 | klass->expose_event = NULL; |
---|
755 | klass->key_press_event = gtk_widget_real_key_press_event; |
---|
756 | klass->key_release_event = gtk_widget_real_key_release_event; |
---|
757 | klass->enter_notify_event = NULL; |
---|
758 | klass->leave_notify_event = NULL; |
---|
759 | klass->configure_event = NULL; |
---|
760 | klass->focus_in_event = NULL; |
---|
761 | klass->focus_out_event = NULL; |
---|
762 | klass->map_event = NULL; |
---|
763 | klass->unmap_event = NULL; |
---|
764 | klass->property_notify_event = gtk_selection_property_notify; |
---|
765 | klass->selection_clear_event = gtk_selection_clear; |
---|
766 | klass->selection_request_event = gtk_selection_request; |
---|
767 | klass->selection_notify_event = gtk_selection_notify; |
---|
768 | klass->selection_received = NULL; |
---|
769 | klass->proximity_in_event = NULL; |
---|
770 | klass->proximity_out_event = NULL; |
---|
771 | klass->drag_begin = NULL; |
---|
772 | klass->drag_end = NULL; |
---|
773 | klass->drag_data_delete = NULL; |
---|
774 | klass->drag_leave = NULL; |
---|
775 | klass->drag_motion = NULL; |
---|
776 | klass->drag_drop = NULL; |
---|
777 | klass->drag_data_received = NULL; |
---|
778 | |
---|
779 | klass->no_expose_event = NULL; |
---|
780 | |
---|
781 | klass->debug_msg = gtk_widget_debug_msg; |
---|
782 | } |
---|
783 | |
---|
784 | static void |
---|
785 | gtk_widget_set_arg (GtkObject *object, |
---|
786 | GtkArg *arg, |
---|
787 | guint arg_id) |
---|
788 | { |
---|
789 | GtkWidget *widget; |
---|
790 | |
---|
791 | widget = GTK_WIDGET (object); |
---|
792 | |
---|
793 | switch (arg_id) |
---|
794 | { |
---|
795 | guint32 saved_flags; |
---|
796 | |
---|
797 | case ARG_NAME: |
---|
798 | gtk_widget_set_name (widget, GTK_VALUE_STRING (*arg)); |
---|
799 | break; |
---|
800 | case ARG_PARENT: |
---|
801 | gtk_container_add (GTK_CONTAINER (GTK_VALUE_OBJECT (*arg)), widget); |
---|
802 | break; |
---|
803 | case ARG_X: |
---|
804 | gtk_widget_set_uposition (widget, GTK_VALUE_INT (*arg), -2); |
---|
805 | break; |
---|
806 | case ARG_Y: |
---|
807 | gtk_widget_set_uposition (widget, -2, GTK_VALUE_INT (*arg)); |
---|
808 | break; |
---|
809 | case ARG_WIDTH: |
---|
810 | gtk_widget_set_usize (widget, GTK_VALUE_INT (*arg), -2); |
---|
811 | break; |
---|
812 | case ARG_HEIGHT: |
---|
813 | gtk_widget_set_usize (widget, -2, GTK_VALUE_INT (*arg)); |
---|
814 | break; |
---|
815 | case ARG_VISIBLE: |
---|
816 | if (GTK_VALUE_BOOL(*arg)) |
---|
817 | gtk_widget_show (widget); |
---|
818 | else |
---|
819 | gtk_widget_hide (widget); |
---|
820 | break; |
---|
821 | case ARG_SENSITIVE: |
---|
822 | gtk_widget_set_sensitive (widget, GTK_VALUE_BOOL (*arg)); |
---|
823 | break; |
---|
824 | case ARG_APP_PAINTABLE: |
---|
825 | gtk_widget_set_app_paintable (widget, GTK_VALUE_BOOL (*arg)); |
---|
826 | break; |
---|
827 | case ARG_CAN_FOCUS: |
---|
828 | saved_flags = GTK_WIDGET_FLAGS (widget); |
---|
829 | if (GTK_VALUE_BOOL (*arg)) |
---|
830 | GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS); |
---|
831 | else |
---|
832 | GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS); |
---|
833 | if (saved_flags != GTK_WIDGET_FLAGS (widget)) |
---|
834 | gtk_widget_queue_resize (widget); |
---|
835 | break; |
---|
836 | case ARG_HAS_FOCUS: |
---|
837 | if (GTK_VALUE_BOOL (*arg)) |
---|
838 | gtk_widget_grab_focus (widget); |
---|
839 | break; |
---|
840 | case ARG_CAN_DEFAULT: |
---|
841 | saved_flags = GTK_WIDGET_FLAGS (widget); |
---|
842 | if (GTK_VALUE_BOOL (*arg)) |
---|
843 | GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT); |
---|
844 | else |
---|
845 | GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT); |
---|
846 | if (saved_flags != GTK_WIDGET_FLAGS (widget)) |
---|
847 | gtk_widget_queue_resize (widget); |
---|
848 | break; |
---|
849 | case ARG_HAS_DEFAULT: |
---|
850 | if (GTK_VALUE_BOOL (*arg)) |
---|
851 | gtk_widget_grab_default (widget); |
---|
852 | break; |
---|
853 | case ARG_RECEIVES_DEFAULT: |
---|
854 | if (GTK_VALUE_BOOL (*arg)) |
---|
855 | GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT); |
---|
856 | else |
---|
857 | GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT); |
---|
858 | break; |
---|
859 | case ARG_COMPOSITE_CHILD: |
---|
860 | if (GTK_VALUE_BOOL(*arg)) |
---|
861 | GTK_WIDGET_SET_FLAGS (widget, GTK_COMPOSITE_CHILD); |
---|
862 | else |
---|
863 | GTK_WIDGET_UNSET_FLAGS (widget, GTK_COMPOSITE_CHILD); |
---|
864 | break; |
---|
865 | case ARG_STYLE: |
---|
866 | gtk_widget_set_style (widget, (GtkStyle*) GTK_VALUE_BOXED (*arg)); |
---|
867 | break; |
---|
868 | case ARG_EVENTS: |
---|
869 | if (!GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_NO_WINDOW (widget)) |
---|
870 | gtk_widget_set_events (widget, GTK_VALUE_FLAGS (*arg)); |
---|
871 | break; |
---|
872 | case ARG_EXTENSION_EVENTS: |
---|
873 | gtk_widget_set_extension_events (widget, GTK_VALUE_FLAGS (*arg)); |
---|
874 | break; |
---|
875 | default: |
---|
876 | break; |
---|
877 | } |
---|
878 | } |
---|
879 | |
---|
880 | /***************************************** |
---|
881 | * gtk_widget_get_arg: |
---|
882 | * |
---|
883 | * arguments: |
---|
884 | * |
---|
885 | * results: |
---|
886 | *****************************************/ |
---|
887 | |
---|
888 | static void |
---|
889 | gtk_widget_get_arg (GtkObject *object, |
---|
890 | GtkArg *arg, |
---|
891 | guint arg_id) |
---|
892 | { |
---|
893 | GtkWidget *widget; |
---|
894 | |
---|
895 | widget = GTK_WIDGET (object); |
---|
896 | |
---|
897 | switch (arg_id) |
---|
898 | { |
---|
899 | GtkWidgetAuxInfo *aux_info; |
---|
900 | gint *eventp; |
---|
901 | GdkExtensionMode *modep; |
---|
902 | |
---|
903 | case ARG_NAME: |
---|
904 | if (widget->name) |
---|
905 | GTK_VALUE_STRING (*arg) = g_strdup (widget->name); |
---|
906 | else |
---|
907 | GTK_VALUE_STRING (*arg) = g_strdup (""); |
---|
908 | break; |
---|
909 | case ARG_PARENT: |
---|
910 | GTK_VALUE_OBJECT (*arg) = (GtkObject*) widget->parent; |
---|
911 | break; |
---|
912 | case ARG_X: |
---|
913 | aux_info = gtk_object_get_data_by_id (GTK_OBJECT (widget), aux_info_key_id); |
---|
914 | if (!aux_info) |
---|
915 | GTK_VALUE_INT (*arg) = -1; |
---|
916 | else |
---|
917 | GTK_VALUE_INT (*arg) = aux_info->x; |
---|
918 | break; |
---|
919 | case ARG_Y: |
---|
920 | aux_info = gtk_object_get_data_by_id (GTK_OBJECT (widget), aux_info_key_id); |
---|
921 | if (!aux_info) |
---|
922 | GTK_VALUE_INT (*arg) = -1; |
---|
923 | else |
---|
924 | GTK_VALUE_INT (*arg) = aux_info->y; |
---|
925 | break; |
---|
926 | case ARG_WIDTH: |
---|
927 | aux_info = gtk_object_get_data_by_id (GTK_OBJECT (widget), aux_info_key_id); |
---|
928 | if (!aux_info) |
---|
929 | GTK_VALUE_INT (*arg) = -1; |
---|
930 | else |
---|
931 | GTK_VALUE_INT (*arg) = aux_info->width; |
---|
932 | break; |
---|
933 | case ARG_HEIGHT: |
---|
934 | aux_info = gtk_object_get_data_by_id (GTK_OBJECT (widget), aux_info_key_id); |
---|
935 | if (!aux_info) |
---|
936 | GTK_VALUE_INT (*arg) = -1; |
---|
937 | else |
---|
938 | GTK_VALUE_INT (*arg) = aux_info->height; |
---|
939 | break; |
---|
940 | case ARG_VISIBLE: |
---|
941 | GTK_VALUE_BOOL (*arg) = (GTK_WIDGET_VISIBLE (widget) != FALSE); |
---|
942 | break; |
---|
943 | case ARG_SENSITIVE: |
---|
944 | GTK_VALUE_BOOL (*arg) = (GTK_WIDGET_SENSITIVE (widget) != FALSE); |
---|
945 | break; |
---|
946 | case ARG_APP_PAINTABLE: |
---|
947 | GTK_VALUE_BOOL (*arg) = (GTK_WIDGET_APP_PAINTABLE (widget) != FALSE); |
---|
948 | break; |
---|
949 | case ARG_CAN_FOCUS: |
---|
950 | GTK_VALUE_BOOL (*arg) = (GTK_WIDGET_CAN_FOCUS (widget) != FALSE); |
---|
951 | break; |
---|
952 | case ARG_HAS_FOCUS: |
---|
953 | GTK_VALUE_BOOL (*arg) = (GTK_WIDGET_HAS_FOCUS (widget) != FALSE); |
---|
954 | break; |
---|
955 | case ARG_CAN_DEFAULT: |
---|
956 | GTK_VALUE_BOOL (*arg) = (GTK_WIDGET_CAN_DEFAULT (widget) != FALSE); |
---|
957 | break; |
---|
958 | case ARG_HAS_DEFAULT: |
---|
959 | GTK_VALUE_BOOL (*arg) = (GTK_WIDGET_HAS_DEFAULT (widget) != FALSE); |
---|
960 | break; |
---|
961 | case ARG_RECEIVES_DEFAULT: |
---|
962 | GTK_VALUE_BOOL (*arg) = (GTK_WIDGET_RECEIVES_DEFAULT (widget) != FALSE); |
---|
963 | break; |
---|
964 | case ARG_COMPOSITE_CHILD: |
---|
965 | GTK_VALUE_BOOL (*arg) = (GTK_WIDGET_COMPOSITE_CHILD (widget) != FALSE); |
---|
966 | break; |
---|
967 | case ARG_STYLE: |
---|
968 | GTK_VALUE_BOXED (*arg) = (gpointer) gtk_widget_get_style (widget); |
---|
969 | break; |
---|
970 | case ARG_EVENTS: |
---|
971 | eventp = gtk_object_get_data_by_id (GTK_OBJECT (widget), event_key_id); |
---|
972 | if (!eventp) |
---|
973 | GTK_VALUE_FLAGS (*arg) = 0; |
---|
974 | else |
---|
975 | GTK_VALUE_FLAGS (*arg) = *eventp; |
---|
976 | break; |
---|
977 | case ARG_EXTENSION_EVENTS: |
---|
978 | modep = gtk_object_get_data_by_id (GTK_OBJECT (widget), extension_event_key_id); |
---|
979 | if (!modep) |
---|
980 | GTK_VALUE_FLAGS (*arg) = 0; |
---|
981 | else |
---|
982 | GTK_VALUE_FLAGS (*arg) = *modep; |
---|
983 | break; |
---|
984 | default: |
---|
985 | arg->type = GTK_TYPE_INVALID; |
---|
986 | break; |
---|
987 | } |
---|
988 | } |
---|
989 | |
---|
990 | /***************************************** |
---|
991 | * gtk_widget_init: |
---|
992 | * |
---|
993 | * arguments: |
---|
994 | * |
---|
995 | * results: |
---|
996 | *****************************************/ |
---|
997 | |
---|
998 | static void |
---|
999 | gtk_widget_init (GtkWidget *widget) |
---|
1000 | { |
---|
1001 | GdkColormap *colormap; |
---|
1002 | GdkVisual *visual; |
---|
1003 | |
---|
1004 | GTK_PRIVATE_FLAGS (widget) = 0; |
---|
1005 | widget->state = GTK_STATE_NORMAL; |
---|
1006 | widget->saved_state = GTK_STATE_NORMAL; |
---|
1007 | widget->name = NULL; |
---|
1008 | widget->requisition.width = 0; |
---|
1009 | widget->requisition.height = 0; |
---|
1010 | widget->allocation.x = -1; |
---|
1011 | widget->allocation.y = -1; |
---|
1012 | widget->allocation.width = 1; |
---|
1013 | widget->allocation.height = 1; |
---|
1014 | widget->window = NULL; |
---|
1015 | widget->parent = NULL; |
---|
1016 | |
---|
1017 | GTK_WIDGET_SET_FLAGS (widget, |
---|
1018 | GTK_SENSITIVE | |
---|
1019 | GTK_PARENT_SENSITIVE | |
---|
1020 | (composite_child_stack ? GTK_COMPOSITE_CHILD : 0)); |
---|
1021 | |
---|
1022 | widget->style = gtk_widget_peek_style (); |
---|
1023 | gtk_style_ref (widget->style); |
---|
1024 | |
---|
1025 | colormap = gtk_widget_peek_colormap (); |
---|
1026 | visual = gtk_widget_peek_visual (); |
---|
1027 | |
---|
1028 | if (colormap != gtk_widget_get_default_colormap ()) |
---|
1029 | gtk_widget_set_colormap (widget, colormap); |
---|
1030 | |
---|
1031 | if (visual != gtk_widget_get_default_visual ()) |
---|
1032 | gtk_widget_set_visual (widget, visual); |
---|
1033 | } |
---|
1034 | |
---|
1035 | /***************************************** |
---|
1036 | * gtk_widget_new: |
---|
1037 | * |
---|
1038 | * arguments: |
---|
1039 | * |
---|
1040 | * results: |
---|
1041 | *****************************************/ |
---|
1042 | |
---|
1043 | GtkWidget* |
---|
1044 | gtk_widget_new (GtkType widget_type, |
---|
1045 | const gchar *first_arg_name, |
---|
1046 | ...) |
---|
1047 | { |
---|
1048 | GtkObject *object; |
---|
1049 | va_list var_args; |
---|
1050 | GSList *arg_list = NULL; |
---|
1051 | GSList *info_list = NULL; |
---|
1052 | gchar *error; |
---|
1053 | |
---|
1054 | g_return_val_if_fail (gtk_type_is_a (widget_type, GTK_TYPE_WIDGET), NULL); |
---|
1055 | |
---|
1056 | object = gtk_type_new (widget_type); |
---|
1057 | |
---|
1058 | va_start (var_args, first_arg_name); |
---|
1059 | error = gtk_object_args_collect (GTK_OBJECT_TYPE (object), |
---|
1060 | &arg_list, |
---|
1061 | &info_list, |
---|
1062 | first_arg_name, |
---|
1063 | var_args); |
---|
1064 | va_end (var_args); |
---|
1065 | |
---|
1066 | if (error) |
---|
1067 | { |
---|
1068 | g_warning ("gtk_widget_new(): %s", error); |
---|
1069 | g_free (error); |
---|
1070 | } |
---|
1071 | else |
---|
1072 | { |
---|
1073 | GSList *slist_arg; |
---|
1074 | GSList *slist_info; |
---|
1075 | |
---|
1076 | slist_arg = arg_list; |
---|
1077 | slist_info = info_list; |
---|
1078 | while (slist_arg) |
---|
1079 | { |
---|
1080 | gtk_object_arg_set (object, slist_arg->data, slist_info->data); |
---|
1081 | slist_arg = slist_arg->next; |
---|
1082 | slist_info = slist_info->next; |
---|
1083 | } |
---|
1084 | gtk_args_collect_cleanup (arg_list, info_list); |
---|
1085 | } |
---|
1086 | |
---|
1087 | if (!GTK_OBJECT_CONSTRUCTED (object)) |
---|
1088 | gtk_object_default_construct (object); |
---|
1089 | |
---|
1090 | return GTK_WIDGET (object); |
---|
1091 | } |
---|
1092 | |
---|
1093 | /***************************************** |
---|
1094 | * gtk_widget_newv: |
---|
1095 | * |
---|
1096 | * arguments: |
---|
1097 | * |
---|
1098 | * results: |
---|
1099 | *****************************************/ |
---|
1100 | |
---|
1101 | GtkWidget* |
---|
1102 | gtk_widget_newv (GtkType type, |
---|
1103 | guint nargs, |
---|
1104 | GtkArg *args) |
---|
1105 | { |
---|
1106 | g_return_val_if_fail (gtk_type_is_a (type, GTK_TYPE_WIDGET), NULL); |
---|
1107 | |
---|
1108 | return GTK_WIDGET (gtk_object_newv (type, nargs, args)); |
---|
1109 | } |
---|
1110 | |
---|
1111 | /***************************************** |
---|
1112 | * gtk_widget_get: |
---|
1113 | * |
---|
1114 | * arguments: |
---|
1115 | * |
---|
1116 | * results: |
---|
1117 | *****************************************/ |
---|
1118 | |
---|
1119 | void |
---|
1120 | gtk_widget_get (GtkWidget *widget, |
---|
1121 | GtkArg *arg) |
---|
1122 | { |
---|
1123 | g_return_if_fail (widget != NULL); |
---|
1124 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
1125 | g_return_if_fail (arg != NULL); |
---|
1126 | |
---|
1127 | gtk_object_getv (GTK_OBJECT (widget), 1, arg); |
---|
1128 | } |
---|
1129 | |
---|
1130 | /***************************************** |
---|
1131 | * gtk_widget_getv: |
---|
1132 | * |
---|
1133 | * arguments: |
---|
1134 | * |
---|
1135 | * results: |
---|
1136 | *****************************************/ |
---|
1137 | |
---|
1138 | void |
---|
1139 | gtk_widget_getv (GtkWidget *widget, |
---|
1140 | guint nargs, |
---|
1141 | GtkArg *args) |
---|
1142 | { |
---|
1143 | g_return_if_fail (widget != NULL); |
---|
1144 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
1145 | |
---|
1146 | gtk_object_getv (GTK_OBJECT (widget), nargs, args); |
---|
1147 | } |
---|
1148 | |
---|
1149 | /***************************************** |
---|
1150 | * gtk_widget_set: |
---|
1151 | * |
---|
1152 | * arguments: |
---|
1153 | * |
---|
1154 | * results: |
---|
1155 | *****************************************/ |
---|
1156 | |
---|
1157 | void |
---|
1158 | gtk_widget_set (GtkWidget *widget, |
---|
1159 | const gchar *first_arg_name, |
---|
1160 | ...) |
---|
1161 | { |
---|
1162 | GtkObject *object; |
---|
1163 | va_list var_args; |
---|
1164 | GSList *arg_list = NULL; |
---|
1165 | GSList *info_list = NULL; |
---|
1166 | gchar *error; |
---|
1167 | |
---|
1168 | g_return_if_fail (widget != NULL); |
---|
1169 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
1170 | |
---|
1171 | object = GTK_OBJECT (widget); |
---|
1172 | |
---|
1173 | va_start (var_args, first_arg_name); |
---|
1174 | error = gtk_object_args_collect (GTK_OBJECT_TYPE (object), |
---|
1175 | &arg_list, |
---|
1176 | &info_list, |
---|
1177 | first_arg_name, |
---|
1178 | var_args); |
---|
1179 | va_end (var_args); |
---|
1180 | |
---|
1181 | if (error) |
---|
1182 | { |
---|
1183 | g_warning ("gtk_widget_set(): %s", error); |
---|
1184 | g_free (error); |
---|
1185 | } |
---|
1186 | else |
---|
1187 | { |
---|
1188 | GSList *slist_arg; |
---|
1189 | GSList *slist_info; |
---|
1190 | |
---|
1191 | slist_arg = arg_list; |
---|
1192 | slist_info = info_list; |
---|
1193 | while (slist_arg) |
---|
1194 | { |
---|
1195 | gtk_object_arg_set (object, slist_arg->data, slist_info->data); |
---|
1196 | slist_arg = slist_arg->next; |
---|
1197 | slist_info = slist_info->next; |
---|
1198 | } |
---|
1199 | gtk_args_collect_cleanup (arg_list, info_list); |
---|
1200 | } |
---|
1201 | } |
---|
1202 | |
---|
1203 | /***************************************** |
---|
1204 | * gtk_widget_setv: |
---|
1205 | * |
---|
1206 | * arguments: |
---|
1207 | * |
---|
1208 | * results: |
---|
1209 | *****************************************/ |
---|
1210 | |
---|
1211 | void |
---|
1212 | gtk_widget_setv (GtkWidget *widget, |
---|
1213 | guint nargs, |
---|
1214 | GtkArg *args) |
---|
1215 | { |
---|
1216 | g_return_if_fail (widget != NULL); |
---|
1217 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
1218 | |
---|
1219 | gtk_object_setv (GTK_OBJECT (widget), nargs, args); |
---|
1220 | } |
---|
1221 | |
---|
1222 | static inline void |
---|
1223 | gtk_widget_queue_clear_child (GtkWidget *widget) |
---|
1224 | { |
---|
1225 | GtkWidget *parent; |
---|
1226 | |
---|
1227 | /* We check for GTK_WIDGET_IS_OFFSCREEN (widget), |
---|
1228 | * and queue_clear_area(parent...) will check the rest of |
---|
1229 | * way up the tree with gtk_widget_is_offscreen (parent) |
---|
1230 | */ |
---|
1231 | parent = widget->parent; |
---|
1232 | if (parent && GTK_WIDGET_DRAWABLE (parent) && |
---|
1233 | !GTK_WIDGET_IS_OFFSCREEN (widget)) |
---|
1234 | gtk_widget_queue_clear_area (parent, |
---|
1235 | widget->allocation.x, |
---|
1236 | widget->allocation.y, |
---|
1237 | widget->allocation.width, |
---|
1238 | widget->allocation.height); |
---|
1239 | } |
---|
1240 | |
---|
1241 | void |
---|
1242 | gtk_widget_unparent (GtkWidget *widget) |
---|
1243 | { |
---|
1244 | GtkWidget *toplevel; |
---|
1245 | GtkWidget *old_parent; |
---|
1246 | |
---|
1247 | g_return_if_fail (widget != NULL); |
---|
1248 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
1249 | if (widget->parent == NULL) |
---|
1250 | return; |
---|
1251 | |
---|
1252 | /* keep this function in sync with gtk_menu_detach() |
---|
1253 | */ |
---|
1254 | |
---|
1255 | /* unset focused and default children properly, this code |
---|
1256 | * should eventually move into some gtk_window_unparent_branch() or |
---|
1257 | * similar function. |
---|
1258 | */ |
---|
1259 | |
---|
1260 | toplevel = gtk_widget_get_toplevel (widget); |
---|
1261 | if (GTK_CONTAINER (widget->parent)->focus_child == widget) |
---|
1262 | { |
---|
1263 | gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL); |
---|
1264 | |
---|
1265 | if (GTK_IS_WINDOW (toplevel)) |
---|
1266 | { |
---|
1267 | GtkWidget *child; |
---|
1268 | |
---|
1269 | child = GTK_WINDOW (toplevel)->focus_widget; |
---|
1270 | |
---|
1271 | while (child && child != widget) |
---|
1272 | child = child->parent; |
---|
1273 | |
---|
1274 | if (child == widget) |
---|
1275 | gtk_window_set_focus (GTK_WINDOW (toplevel), NULL); |
---|
1276 | } |
---|
1277 | } |
---|
1278 | if (GTK_IS_WINDOW (toplevel)) |
---|
1279 | { |
---|
1280 | GtkWidget *child; |
---|
1281 | |
---|
1282 | child = GTK_WINDOW (toplevel)->default_widget; |
---|
1283 | |
---|
1284 | while (child && child != widget) |
---|
1285 | child = child->parent; |
---|
1286 | |
---|
1287 | if (child == widget) |
---|
1288 | gtk_window_set_default (GTK_WINDOW (toplevel), NULL); |
---|
1289 | } |
---|
1290 | |
---|
1291 | if (GTK_WIDGET_REDRAW_PENDING (widget)) |
---|
1292 | gtk_widget_redraw_queue_remove (widget); |
---|
1293 | |
---|
1294 | if (GTK_IS_RESIZE_CONTAINER (widget)) |
---|
1295 | gtk_container_clear_resize_widgets (GTK_CONTAINER (widget)); |
---|
1296 | |
---|
1297 | /* Remove the widget and all its children from any ->resize_widgets list |
---|
1298 | * of all the parents in our branch. This code should move into gtkcontainer.c |
---|
1299 | * somwhen, since we mess around with ->resize_widgets, which is |
---|
1300 | * actually not of our business. |
---|
1301 | * |
---|
1302 | * Two ways to make this prettier: |
---|
1303 | * Write a g_slist_conditional_remove (GSList, gboolean (*)(gpointer)) |
---|
1304 | * Change resize_widgets to a GList |
---|
1305 | */ |
---|
1306 | toplevel = widget->parent; |
---|
1307 | while (toplevel) |
---|
1308 | { |
---|
1309 | GSList *slist; |
---|
1310 | GSList *prev; |
---|
1311 | |
---|
1312 | if (!GTK_CONTAINER (toplevel)->resize_widgets) |
---|
1313 | { |
---|
1314 | toplevel = toplevel->parent; |
---|
1315 | continue; |
---|
1316 | } |
---|
1317 | |
---|
1318 | prev = NULL; |
---|
1319 | slist = GTK_CONTAINER (toplevel)->resize_widgets; |
---|
1320 | while (slist) |
---|
1321 | { |
---|
1322 | GtkWidget *child; |
---|
1323 | GtkWidget *parent; |
---|
1324 | GSList *last; |
---|
1325 | |
---|
1326 | last = slist; |
---|
1327 | slist = last->next; |
---|
1328 | child = last->data; |
---|
1329 | |
---|
1330 | parent = child; |
---|
1331 | while (parent && (parent != widget)) |
---|
1332 | parent = parent->parent; |
---|
1333 | |
---|
1334 | if (parent == widget) |
---|
1335 | { |
---|
1336 | GTK_PRIVATE_UNSET_FLAG (child, GTK_RESIZE_NEEDED); |
---|
1337 | |
---|
1338 | if (prev) |
---|
1339 | prev->next = slist; |
---|
1340 | else |
---|
1341 | GTK_CONTAINER (toplevel)->resize_widgets = slist; |
---|
1342 | |
---|
1343 | g_slist_free_1 (last); |
---|
1344 | } |
---|
1345 | else |
---|
1346 | prev = last; |
---|
1347 | } |
---|
1348 | |
---|
1349 | toplevel = toplevel->parent; |
---|
1350 | } |
---|
1351 | |
---|
1352 | gtk_widget_queue_clear_child (widget); |
---|
1353 | |
---|
1354 | /* Reset the width and height here, to force reallocation if we |
---|
1355 | * get added back to a new parent. This won't work if our new |
---|
1356 | * allocation is smaller than 1x1 and we actually want a size of 1x1... |
---|
1357 | * (would 0x0 be OK here?) |
---|
1358 | */ |
---|
1359 | widget->allocation.width = 1; |
---|
1360 | widget->allocation.height = 1; |
---|
1361 | |
---|
1362 | if (GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_IN_REPARENT (widget)) |
---|
1363 | gtk_widget_unrealize (widget); |
---|
1364 | |
---|
1365 | old_parent = widget->parent; |
---|
1366 | widget->parent = NULL; |
---|
1367 | gtk_widget_set_parent_window (widget, NULL); |
---|
1368 | gtk_signal_emit (GTK_OBJECT (widget), widget_signals[PARENT_SET], old_parent); |
---|
1369 | |
---|
1370 | gtk_widget_unref (widget); |
---|
1371 | } |
---|
1372 | |
---|
1373 | /***************************************** |
---|
1374 | * gtk_widget_destroy: |
---|
1375 | * |
---|
1376 | * arguments: |
---|
1377 | * |
---|
1378 | * results: |
---|
1379 | *****************************************/ |
---|
1380 | |
---|
1381 | void |
---|
1382 | gtk_widget_destroy (GtkWidget *widget) |
---|
1383 | { |
---|
1384 | g_return_if_fail (widget != NULL); |
---|
1385 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
1386 | g_return_if_fail (GTK_OBJECT_CONSTRUCTED (widget)); |
---|
1387 | |
---|
1388 | gtk_object_destroy ((GtkObject*) widget); |
---|
1389 | } |
---|
1390 | |
---|
1391 | /***************************************** |
---|
1392 | * gtk_widget_destroyed: |
---|
1393 | * Utility function: sets widget_pointer |
---|
1394 | * to NULL when widget is destroyed. |
---|
1395 | * |
---|
1396 | * arguments: |
---|
1397 | * |
---|
1398 | * results: |
---|
1399 | *****************************************/ |
---|
1400 | |
---|
1401 | void |
---|
1402 | gtk_widget_destroyed (GtkWidget *widget, |
---|
1403 | GtkWidget **widget_pointer) |
---|
1404 | { |
---|
1405 | /* Don't make any assumptions about the |
---|
1406 | * value of widget! |
---|
1407 | * Even check widget_pointer. |
---|
1408 | */ |
---|
1409 | if (widget_pointer) |
---|
1410 | *widget_pointer = NULL; |
---|
1411 | } |
---|
1412 | |
---|
1413 | /***************************************** |
---|
1414 | * gtk_widget_show: |
---|
1415 | * |
---|
1416 | * arguments: |
---|
1417 | * |
---|
1418 | * results: |
---|
1419 | *****************************************/ |
---|
1420 | |
---|
1421 | void |
---|
1422 | gtk_widget_show (GtkWidget *widget) |
---|
1423 | { |
---|
1424 | g_return_if_fail (widget != NULL); |
---|
1425 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
1426 | |
---|
1427 | if (!GTK_WIDGET_VISIBLE (widget)) |
---|
1428 | { |
---|
1429 | if (!GTK_WIDGET_TOPLEVEL (widget)) |
---|
1430 | gtk_widget_queue_resize (widget); |
---|
1431 | gtk_signal_emit (GTK_OBJECT (widget), widget_signals[SHOW]); |
---|
1432 | } |
---|
1433 | } |
---|
1434 | |
---|
1435 | static void |
---|
1436 | gtk_widget_real_show (GtkWidget *widget) |
---|
1437 | { |
---|
1438 | g_return_if_fail (widget != NULL); |
---|
1439 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
1440 | |
---|
1441 | if (!GTK_WIDGET_VISIBLE (widget)) |
---|
1442 | { |
---|
1443 | GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE); |
---|
1444 | |
---|
1445 | if (widget->parent && |
---|
1446 | GTK_WIDGET_MAPPED (widget->parent) && |
---|
1447 | !GTK_WIDGET_MAPPED (widget)) |
---|
1448 | gtk_widget_map (widget); |
---|
1449 | } |
---|
1450 | } |
---|
1451 | |
---|
1452 | /************************************************************* |
---|
1453 | * gtk_widget_show_now: |
---|
1454 | * Show a widget, and if it is an unmapped toplevel widget |
---|
1455 | * wait for the map_event before returning |
---|
1456 | * |
---|
1457 | * Warning: This routine will call the main loop recursively. |
---|
1458 | * |
---|
1459 | * arguments: |
---|
1460 | * |
---|
1461 | * results: |
---|
1462 | *************************************************************/ |
---|
1463 | |
---|
1464 | static void |
---|
1465 | gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag) |
---|
1466 | { |
---|
1467 | *flag = TRUE; |
---|
1468 | gtk_signal_disconnect_by_data (GTK_OBJECT (widget), flag); |
---|
1469 | } |
---|
1470 | |
---|
1471 | void |
---|
1472 | gtk_widget_show_now (GtkWidget *widget) |
---|
1473 | { |
---|
1474 | gint flag = FALSE; |
---|
1475 | |
---|
1476 | g_return_if_fail (widget != NULL); |
---|
1477 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
1478 | |
---|
1479 | /* make sure we will get event */ |
---|
1480 | if (!GTK_WIDGET_MAPPED (widget) && |
---|
1481 | GTK_WIDGET_TOPLEVEL (widget)) |
---|
1482 | { |
---|
1483 | gtk_widget_show (widget); |
---|
1484 | |
---|
1485 | gtk_signal_connect (GTK_OBJECT (widget), "map_event", |
---|
1486 | GTK_SIGNAL_FUNC (gtk_widget_show_map_callback), |
---|
1487 | &flag); |
---|
1488 | |
---|
1489 | while (!flag) |
---|
1490 | gtk_main_iteration(); |
---|
1491 | } |
---|
1492 | else |
---|
1493 | gtk_widget_show (widget); |
---|
1494 | } |
---|
1495 | |
---|
1496 | /***************************************** |
---|
1497 | * gtk_widget_hide: |
---|
1498 | * |
---|
1499 | * arguments: |
---|
1500 | * |
---|
1501 | * results: |
---|
1502 | *****************************************/ |
---|
1503 | |
---|
1504 | void |
---|
1505 | gtk_widget_hide (GtkWidget *widget) |
---|
1506 | { |
---|
1507 | g_return_if_fail (widget != NULL); |
---|
1508 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
1509 | |
---|
1510 | if (GTK_WIDGET_VISIBLE (widget)) |
---|
1511 | { |
---|
1512 | gtk_widget_ref (widget); |
---|
1513 | gtk_signal_emit (GTK_OBJECT (widget), widget_signals[HIDE]); |
---|
1514 | if (!GTK_WIDGET_TOPLEVEL (widget) && !GTK_OBJECT_DESTROYED (widget)) |
---|
1515 | gtk_widget_queue_resize (widget); |
---|
1516 | gtk_widget_unref (widget); |
---|
1517 | } |
---|
1518 | } |
---|
1519 | |
---|
1520 | static void |
---|
1521 | gtk_widget_real_hide (GtkWidget *widget) |
---|
1522 | { |
---|
1523 | g_return_if_fail (widget != NULL); |
---|
1524 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
1525 | |
---|
1526 | if (GTK_WIDGET_VISIBLE (widget)) |
---|
1527 | { |
---|
1528 | GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE); |
---|
1529 | |
---|
1530 | if (GTK_WIDGET_MAPPED (widget)) |
---|
1531 | gtk_widget_unmap (widget); |
---|
1532 | } |
---|
1533 | } |
---|
1534 | |
---|
1535 | gint |
---|
1536 | gtk_widget_hide_on_delete (GtkWidget *widget) |
---|
1537 | { |
---|
1538 | g_return_val_if_fail (widget != NULL, FALSE); |
---|
1539 | g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); |
---|
1540 | |
---|
1541 | gtk_widget_hide (widget); |
---|
1542 | |
---|
1543 | return TRUE; |
---|
1544 | } |
---|
1545 | |
---|
1546 | void |
---|
1547 | gtk_widget_show_all (GtkWidget *widget) |
---|
1548 | { |
---|
1549 | GtkWidgetClass *class; |
---|
1550 | |
---|
1551 | g_return_if_fail (widget != NULL); |
---|
1552 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
1553 | |
---|
1554 | class = GTK_WIDGET_CLASS (GTK_OBJECT (widget)->klass); |
---|
1555 | |
---|
1556 | if (class->show_all) |
---|
1557 | class->show_all (widget); |
---|
1558 | } |
---|
1559 | |
---|
1560 | void |
---|
1561 | gtk_widget_hide_all (GtkWidget *widget) |
---|
1562 | { |
---|
1563 | GtkWidgetClass *class; |
---|
1564 | |
---|
1565 | g_return_if_fail (widget != NULL); |
---|
1566 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
1567 | |
---|
1568 | class = GTK_WIDGET_CLASS (GTK_OBJECT (widget)->klass); |
---|
1569 | |
---|
1570 | if (class->hide_all) |
---|
1571 | class->hide_all (widget); |
---|
1572 | } |
---|
1573 | |
---|
1574 | /***************************************** |
---|
1575 | * gtk_widget_map: |
---|
1576 | * |
---|
1577 | * arguments: |
---|
1578 | * |
---|
1579 | * results: |
---|
1580 | *****************************************/ |
---|
1581 | |
---|
1582 | void |
---|
1583 | gtk_widget_map (GtkWidget *widget) |
---|
1584 | { |
---|
1585 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
1586 | g_return_if_fail (GTK_WIDGET_VISIBLE (widget) == TRUE); |
---|
1587 | |
---|
1588 | if (!GTK_WIDGET_MAPPED (widget)) |
---|
1589 | { |
---|
1590 | if (!GTK_WIDGET_REALIZED (widget)) |
---|
1591 | gtk_widget_realize (widget); |
---|
1592 | |
---|
1593 | gtk_signal_emit (GTK_OBJECT (widget), widget_signals[MAP]); |
---|
1594 | |
---|
1595 | if (GTK_WIDGET_NO_WINDOW (widget)) |
---|
1596 | gtk_widget_queue_draw (widget); |
---|
1597 | } |
---|
1598 | } |
---|
1599 | |
---|
1600 | /***************************************** |
---|
1601 | * gtk_widget_unmap: |
---|
1602 | * |
---|
1603 | * arguments: |
---|
1604 | * |
---|
1605 | * results: |
---|
1606 | *****************************************/ |
---|
1607 | |
---|
1608 | void |
---|
1609 | gtk_widget_unmap (GtkWidget *widget) |
---|
1610 | { |
---|
1611 | g_return_if_fail (widget != NULL); |
---|
1612 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
1613 | |
---|
1614 | if (GTK_WIDGET_MAPPED (widget)) |
---|
1615 | { |
---|
1616 | if (GTK_WIDGET_NO_WINDOW (widget)) |
---|
1617 | gtk_widget_queue_clear_child (widget); |
---|
1618 | gtk_signal_emit (GTK_OBJECT (widget), widget_signals[UNMAP]); |
---|
1619 | } |
---|
1620 | } |
---|
1621 | |
---|
1622 | /***************************************** |
---|
1623 | * gtk_widget_realize: |
---|
1624 | * |
---|
1625 | * arguments: |
---|
1626 | * |
---|
1627 | * results: |
---|
1628 | *****************************************/ |
---|
1629 | |
---|
1630 | void |
---|
1631 | gtk_widget_realize (GtkWidget *widget) |
---|
1632 | { |
---|
1633 | gint events; |
---|
1634 | GdkExtensionMode mode; |
---|
1635 | GtkWidgetShapeInfo *shape_info; |
---|
1636 | |
---|
1637 | g_return_if_fail (widget != NULL); |
---|
1638 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
1639 | |
---|
1640 | if (!GTK_WIDGET_REALIZED (widget)) |
---|
1641 | { |
---|
1642 | /* |
---|
1643 | if (GTK_IS_CONTAINER (widget) && !GTK_WIDGET_NO_WINDOW (widget)) |
---|
1644 | g_message ("gtk_widget_realize(%s)", gtk_type_name (GTK_WIDGET_TYPE (widget))); |
---|
1645 | */ |
---|
1646 | |
---|
1647 | if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent)) |
---|
1648 | gtk_widget_realize (widget->parent); |
---|
1649 | |
---|
1650 | gtk_widget_ensure_style (widget); |
---|
1651 | |
---|
1652 | gtk_signal_emit (GTK_OBJECT (widget), widget_signals[REALIZE]); |
---|
1653 | |
---|
1654 | if (GTK_WIDGET_HAS_SHAPE_MASK (widget)) |
---|
1655 | { |
---|
1656 | shape_info = gtk_object_get_data (GTK_OBJECT (widget), |
---|
1657 | shape_info_key); |
---|
1658 | gdk_window_shape_combine_mask (widget->window, |
---|
1659 | shape_info->shape_mask, |
---|
1660 | shape_info->offset_x, |
---|
1661 | shape_info->offset_y); |
---|
1662 | } |
---|
1663 | |
---|
1664 | if (!GTK_WIDGET_NO_WINDOW (widget)) |
---|
1665 | { |
---|
1666 | mode = gtk_widget_get_extension_events (widget); |
---|
1667 | if (mode != GDK_EXTENSION_EVENTS_NONE) |
---|
1668 | { |
---|
1669 | events = gtk_widget_get_events (widget); |
---|
1670 | gdk_input_set_extension_events (widget->window, events, mode); |
---|
1671 | } |
---|
1672 | } |
---|
1673 | |
---|
1674 | } |
---|
1675 | } |
---|
1676 | |
---|
1677 | /***************************************** |
---|
1678 | * gtk_widget_unrealize: |
---|
1679 | * |
---|
1680 | * arguments: |
---|
1681 | * |
---|
1682 | * results: |
---|
1683 | *****************************************/ |
---|
1684 | |
---|
1685 | void |
---|
1686 | gtk_widget_unrealize (GtkWidget *widget) |
---|
1687 | { |
---|
1688 | g_return_if_fail (widget != NULL); |
---|
1689 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
1690 | |
---|
1691 | if (GTK_WIDGET_REDRAW_PENDING (widget)) |
---|
1692 | gtk_widget_redraw_queue_remove (widget); |
---|
1693 | |
---|
1694 | if (GTK_WIDGET_HAS_SHAPE_MASK (widget)) |
---|
1695 | gtk_widget_shape_combine_mask (widget, NULL, -1, -1); |
---|
1696 | |
---|
1697 | if (GTK_WIDGET_REALIZED (widget)) |
---|
1698 | { |
---|
1699 | gtk_widget_ref (widget); |
---|
1700 | gtk_signal_emit (GTK_OBJECT (widget), widget_signals[UNREALIZE]); |
---|
1701 | GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED); |
---|
1702 | gtk_widget_unref (widget); |
---|
1703 | } |
---|
1704 | } |
---|
1705 | |
---|
1706 | /***************************************** |
---|
1707 | * gtk_widget_queue_draw: |
---|
1708 | * |
---|
1709 | * arguments: |
---|
1710 | * |
---|
1711 | * results: |
---|
1712 | *****************************************/ |
---|
1713 | |
---|
1714 | typedef struct _GtkDrawData GtkDrawData; |
---|
1715 | struct _GtkDrawData { |
---|
1716 | GdkRectangle rect; |
---|
1717 | GdkWindow *window; |
---|
1718 | }; |
---|
1719 | |
---|
1720 | static GMemChunk *draw_data_mem_chunk = NULL; |
---|
1721 | static GSList *draw_data_free_list = NULL; |
---|
1722 | static const gchar *draw_data_key = "gtk-draw-data"; |
---|
1723 | static GQuark draw_data_key_id = 0; |
---|
1724 | static const gchar *draw_data_tmp_key = "gtk-draw-data-tmp"; |
---|
1725 | static GQuark draw_data_tmp_key_id = 0; |
---|
1726 | |
---|
1727 | static gint gtk_widget_idle_draw (gpointer data); |
---|
1728 | |
---|
1729 | static void |
---|
1730 | gtk_widget_queue_draw_data (GtkWidget *widget, |
---|
1731 | gint x, |
---|
1732 | gint y, |
---|
1733 | gint width, |
---|
1734 | gint height, |
---|
1735 | GdkWindow *window) |
---|
1736 | { |
---|
1737 | GSList *node; |
---|
1738 | GtkDrawData *data; |
---|
1739 | |
---|
1740 | g_return_if_fail (widget != NULL); |
---|
1741 | g_return_if_fail (!(width < 0 || height < 0) || window == NULL); |
---|
1742 | |
---|
1743 | if ((width != 0) && (height != 0) && GTK_WIDGET_DRAWABLE (widget)) |
---|
1744 | { |
---|
1745 | if (!draw_data_key_id) |
---|
1746 | draw_data_key_id = g_quark_from_static_string (draw_data_key); |
---|
1747 | |
---|
1748 | if (draw_data_free_list) |
---|
1749 | { |
---|
1750 | node = draw_data_free_list; |
---|
1751 | data = node->data; |
---|
1752 | draw_data_free_list = draw_data_free_list->next; |
---|
1753 | } |
---|
1754 | else |
---|
1755 | { |
---|
1756 | if (!draw_data_mem_chunk) |
---|
1757 | draw_data_mem_chunk = g_mem_chunk_create (GtkDrawData, 64, |
---|
1758 | G_ALLOC_ONLY); |
---|
1759 | data = g_chunk_new (GtkDrawData, draw_data_mem_chunk); |
---|
1760 | node = g_slist_alloc(); |
---|
1761 | node->data = data; |
---|
1762 | } |
---|
1763 | |
---|
1764 | data->rect.x = x; |
---|
1765 | data->rect.y = y; |
---|
1766 | |
---|
1767 | if ((width < 1 && height < 1) || |
---|
1768 | (width >= widget->allocation.width && |
---|
1769 | height >= widget->allocation.height)) |
---|
1770 | GTK_PRIVATE_SET_FLAG (widget, GTK_FULLDRAW_PENDING); |
---|
1771 | |
---|
1772 | if ((width < 0) || (height < 0)) |
---|
1773 | { |
---|
1774 | data->rect.width = 0; |
---|
1775 | data->rect.height = 0; |
---|
1776 | } |
---|
1777 | else |
---|
1778 | { |
---|
1779 | data->rect.width = width; |
---|
1780 | data->rect.height = height; |
---|
1781 | } |
---|
1782 | data->window = window; |
---|
1783 | |
---|
1784 | if ((width < 0) || (height < 0)) |
---|
1785 | { |
---|
1786 | GSList *draw_data_list = |
---|
1787 | gtk_object_get_data_by_id (GTK_OBJECT (widget), |
---|
1788 | draw_data_key_id); |
---|
1789 | if (draw_data_list) |
---|
1790 | draw_data_free_list = g_slist_concat (draw_data_list, |
---|
1791 | draw_data_free_list); |
---|
1792 | node->next = NULL; |
---|
1793 | } |
---|
1794 | else |
---|
1795 | node->next = gtk_object_get_data_by_id (GTK_OBJECT (widget), |
---|
1796 | draw_data_key_id); |
---|
1797 | |
---|
1798 | if (!GTK_WIDGET_REDRAW_PENDING (widget)) |
---|
1799 | { |
---|
1800 | GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_PENDING); |
---|
1801 | if (gtk_widget_redraw_queue == NULL) |
---|
1802 | gtk_idle_add_priority (GTK_PRIORITY_REDRAW, |
---|
1803 | gtk_widget_idle_draw, |
---|
1804 | NULL); |
---|
1805 | gtk_widget_redraw_queue = g_slist_prepend (gtk_widget_redraw_queue, widget); |
---|
1806 | } |
---|
1807 | |
---|
1808 | gtk_object_set_data_by_id (GTK_OBJECT (widget), draw_data_key_id, node); |
---|
1809 | } |
---|
1810 | } |
---|
1811 | |
---|
1812 | void |
---|
1813 | gtk_widget_queue_draw_area (GtkWidget *widget, |
---|
1814 | gint x, |
---|
1815 | gint y, |
---|
1816 | gint width, |
---|
1817 | gint height) |
---|
1818 | { |
---|
1819 | g_return_if_fail (widget != NULL); |
---|
1820 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
1821 | |
---|
1822 | if (widget->window && gdk_window_is_viewable (widget->window) && |
---|
1823 | !gtk_widget_is_offscreen (widget)) |
---|
1824 | gtk_widget_queue_draw_data (widget, x, y, width, height, NULL); |
---|
1825 | } |
---|
1826 | |
---|
1827 | void |
---|
1828 | gtk_widget_queue_draw (GtkWidget *widget) |
---|
1829 | { |
---|
1830 | g_return_if_fail (widget != NULL); |
---|
1831 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
1832 | |
---|
1833 | if (widget->window && gdk_window_is_viewable (widget->window) && |
---|
1834 | !gtk_widget_is_offscreen (widget)) |
---|
1835 | gtk_widget_queue_draw_data (widget, 0, 0, -1, -1, NULL); |
---|
1836 | } |
---|
1837 | |
---|
1838 | void |
---|
1839 | gtk_widget_queue_clear_area (GtkWidget *widget, |
---|
1840 | gint x, |
---|
1841 | gint y, |
---|
1842 | gint width, |
---|
1843 | gint height) |
---|
1844 | { |
---|
1845 | GtkWidget *parent; |
---|
1846 | |
---|
1847 | g_return_if_fail (widget != NULL); |
---|
1848 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
1849 | |
---|
1850 | if (!(widget->window && gdk_window_is_viewable (widget->window)) || |
---|
1851 | gtk_widget_is_offscreen (widget)) |
---|
1852 | return; |
---|
1853 | |
---|
1854 | /* Find the correct widget */ |
---|
1855 | |
---|
1856 | if (GTK_WIDGET_NO_WINDOW (widget)) |
---|
1857 | { |
---|
1858 | /* The following deals with the fact that while we are in |
---|
1859 | * a reparent, the widget and window heirarchies |
---|
1860 | * may be different, and the redraw queing code will be utterly |
---|
1861 | * screwed by that. |
---|
1862 | * |
---|
1863 | * So, continuing at this point is a bad idea, and returning is |
---|
1864 | * generally harmless. (More redraws will be queued then necessary |
---|
1865 | * for a reparent in any case.) This can go away, when we |
---|
1866 | * make reparent simply ref/remove/add/unref. |
---|
1867 | */ |
---|
1868 | if (GTK_WIDGET_IN_REPARENT (widget)) |
---|
1869 | return; |
---|
1870 | |
---|
1871 | parent = widget; |
---|
1872 | while (parent && GTK_WIDGET_NO_WINDOW (parent)) |
---|
1873 | parent = parent->parent; |
---|
1874 | |
---|
1875 | if (parent) |
---|
1876 | gtk_widget_queue_draw_data (parent, x, y, width, height, widget->window); |
---|
1877 | } |
---|
1878 | else |
---|
1879 | { |
---|
1880 | if (widget->parent) |
---|
1881 | { |
---|
1882 | gint wx, wy, wwidth, wheight; |
---|
1883 | /* Translate widget relative to window-relative */ |
---|
1884 | |
---|
1885 | gdk_window_get_position (widget->window, &wx, &wy); |
---|
1886 | x -= wx - widget->allocation.x; |
---|
1887 | y -= wy - widget->allocation.y; |
---|
1888 | |
---|
1889 | gdk_window_get_size (widget->window, &wwidth, &wheight); |
---|
1890 | |
---|
1891 | if (x + width <= 0 || y + height <= 0 || |
---|
1892 | x >= wwidth || y >= wheight) |
---|
1893 | return; |
---|
1894 | |
---|
1895 | if (x < 0) |
---|
1896 | { |
---|
1897 | width += x; x = 0; |
---|
1898 | } |
---|
1899 | if (y < 0) |
---|
1900 | { |
---|
1901 | height += y; y = 0; |
---|
1902 | } |
---|
1903 | if (x + width > wwidth) |
---|
1904 | width = wwidth - x; |
---|
1905 | if (y + height > wheight) |
---|
1906 | height = wheight - y; |
---|
1907 | } |
---|
1908 | |
---|
1909 | gtk_widget_queue_draw_data (widget, x, y, width, height, widget->window); |
---|
1910 | } |
---|
1911 | } |
---|
1912 | |
---|
1913 | static void |
---|
1914 | gtk_widget_redraw_queue_remove (GtkWidget *widget) |
---|
1915 | { |
---|
1916 | GSList *draw_data_list; |
---|
1917 | GSList *tmp_list; |
---|
1918 | |
---|
1919 | g_return_if_fail (GTK_WIDGET_REDRAW_PENDING (widget)); |
---|
1920 | |
---|
1921 | gtk_widget_redraw_queue = g_slist_remove (gtk_widget_redraw_queue, widget); |
---|
1922 | |
---|
1923 | draw_data_list = gtk_object_get_data_by_id (GTK_OBJECT (widget), |
---|
1924 | draw_data_key_id); |
---|
1925 | tmp_list = g_slist_last (draw_data_list); |
---|
1926 | if (tmp_list) |
---|
1927 | { |
---|
1928 | tmp_list->next = draw_data_free_list; |
---|
1929 | draw_data_free_list = draw_data_list; |
---|
1930 | } |
---|
1931 | |
---|
1932 | gtk_object_set_data_by_id (GTK_OBJECT (widget), |
---|
1933 | draw_data_key_id, |
---|
1934 | NULL); |
---|
1935 | |
---|
1936 | GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_PENDING); |
---|
1937 | GTK_PRIVATE_UNSET_FLAG (widget, GTK_FULLDRAW_PENDING); |
---|
1938 | } |
---|
1939 | |
---|
1940 | void |
---|
1941 | gtk_widget_queue_clear (GtkWidget *widget) |
---|
1942 | { |
---|
1943 | g_return_if_fail (widget != NULL); |
---|
1944 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
1945 | |
---|
1946 | if (widget->allocation.width || widget->allocation.height) |
---|
1947 | { |
---|
1948 | if (GTK_WIDGET_NO_WINDOW (widget)) |
---|
1949 | gtk_widget_queue_clear_area (widget, widget->allocation.x, |
---|
1950 | widget->allocation.y, |
---|
1951 | widget->allocation.width, |
---|
1952 | widget->allocation.height); |
---|
1953 | else |
---|
1954 | gtk_widget_queue_clear_area (widget, 0, 0, |
---|
1955 | widget->allocation.width, |
---|
1956 | widget->allocation.height); |
---|
1957 | } |
---|
1958 | } |
---|
1959 | |
---|
1960 | static gint |
---|
1961 | gtk_widget_draw_data_combine (GtkDrawData *parent, GtkDrawData *child) |
---|
1962 | { |
---|
1963 | gint parent_x2, parent_y2; |
---|
1964 | gint child_x2, child_y2; |
---|
1965 | |
---|
1966 | /* Check for intersection */ |
---|
1967 | |
---|
1968 | parent_x2 = parent->rect.x + parent->rect.width; |
---|
1969 | child_x2 = child->rect.x + child->rect.width; |
---|
1970 | parent_y2 = parent->rect.y + parent->rect.height; |
---|
1971 | child_y2 = child->rect.y + child->rect.height; |
---|
1972 | |
---|
1973 | if ((child->rect.x > parent_x2) || (parent->rect.x > child_x2) || |
---|
1974 | (child->rect.y > parent_y2) || (parent->rect.y > child_y2)) |
---|
1975 | return FALSE; |
---|
1976 | else |
---|
1977 | { |
---|
1978 | parent->rect.x = MIN (parent->rect.x, child->rect.x); |
---|
1979 | parent->rect.y = MIN (parent->rect.y, child->rect.y); |
---|
1980 | parent->rect.width = MAX (parent_x2, child_x2) - parent->rect.x; |
---|
1981 | parent->rect.height = MAX (parent_y2, child_y2) - parent->rect.y; |
---|
1982 | } |
---|
1983 | |
---|
1984 | return TRUE; |
---|
1985 | } |
---|
1986 | |
---|
1987 | /* Take a rectangle with respect to window, and translate it |
---|
1988 | * to coordinates relative to widget's allocation, clipping through |
---|
1989 | * intermediate windows. Returns whether translation failed. If the |
---|
1990 | * translation failed, we have something like a handlebox, where |
---|
1991 | * the child widget's GdkWindow is not a child of the parents GdkWindow. |
---|
1992 | */ |
---|
1993 | static gboolean |
---|
1994 | gtk_widget_clip_rect (GtkWidget *widget, |
---|
1995 | GdkWindow *window, |
---|
1996 | GdkRectangle *rect, |
---|
1997 | gint *x_offset, |
---|
1998 | gint *y_offset) |
---|
1999 | { |
---|
2000 | gint x,y, width, height; |
---|
2001 | |
---|
2002 | while (window && (window != widget->window)) |
---|
2003 | { |
---|
2004 | gdk_window_get_position (window, &x, &y); |
---|
2005 | rect->x += x; |
---|
2006 | if (x_offset) |
---|
2007 | *x_offset += x; |
---|
2008 | rect->y += y; |
---|
2009 | if (y_offset) |
---|
2010 | *y_offset += y; |
---|
2011 | |
---|
2012 | window = gdk_window_get_parent (window); |
---|
2013 | if (!window) |
---|
2014 | return FALSE; |
---|
2015 | |
---|
2016 | gdk_window_get_size (window, &width, &height); |
---|
2017 | |
---|
2018 | if (rect->x < 0) |
---|
2019 | { |
---|
2020 | rect->width = (rect->width > -rect->x) ? rect->width + rect->x : 0; |
---|
2021 | rect->x = 0; |
---|
2022 | } |
---|
2023 | if (rect->y < 0) |
---|
2024 | { |
---|
2025 | rect->height = (rect->height > -rect->y) ? rect->height + rect->y : 0; |
---|
2026 | rect->y = 0; |
---|
2027 | } |
---|
2028 | if (rect->x + rect->width > width) |
---|
2029 | rect->width = (width > rect->x) ? width - rect->x : 0; |
---|
2030 | if (rect->y + rect->height > height) |
---|
2031 | rect->height = (height > rect->y) ? height - rect->y : 0; |
---|
2032 | } |
---|
2033 | |
---|
2034 | if (!window) |
---|
2035 | return FALSE; |
---|
2036 | |
---|
2037 | if (!GTK_WIDGET_NO_WINDOW (widget)) |
---|
2038 | { |
---|
2039 | if (gdk_window_get_toplevel (window) != window) |
---|
2040 | { |
---|
2041 | gdk_window_get_position (window, &x, &y); |
---|
2042 | rect->x += x - widget->allocation.x; |
---|
2043 | if (x_offset) |
---|
2044 | *x_offset += x - widget->allocation.x; |
---|
2045 | rect->y += y - widget->allocation.y; |
---|
2046 | if (y_offset) |
---|
2047 | *y_offset += y - widget->allocation.y; |
---|
2048 | } |
---|
2049 | } |
---|
2050 | |
---|
2051 | return TRUE; |
---|
2052 | } |
---|
2053 | |
---|
2054 | static gint |
---|
2055 | gtk_widget_idle_draw (gpointer cb_data) |
---|
2056 | { |
---|
2057 | GSList *widget_list; |
---|
2058 | GSList *old_queue; |
---|
2059 | GSList *draw_data_list; |
---|
2060 | GtkWidget *widget; |
---|
2061 | |
---|
2062 | if (!draw_data_tmp_key_id) |
---|
2063 | draw_data_tmp_key_id = g_quark_from_static_string (draw_data_tmp_key); |
---|
2064 | |
---|
2065 | GDK_THREADS_ENTER (); |
---|
2066 | |
---|
2067 | old_queue = gtk_widget_redraw_queue; |
---|
2068 | gtk_widget_redraw_queue = NULL; |
---|
2069 | |
---|
2070 | /* Translate all draw requests to be allocation-relative. |
---|
2071 | * At the same time, move all the data out of the way, |
---|
2072 | * so when we get down to the draw step, we can queue |
---|
2073 | * more information for "next time", if the application |
---|
2074 | * is that foolhardy. |
---|
2075 | */ |
---|
2076 | widget_list = old_queue; |
---|
2077 | |
---|
2078 | while (widget_list) |
---|
2079 | { |
---|
2080 | widget = widget_list->data; |
---|
2081 | draw_data_list = gtk_object_get_data_by_id (GTK_OBJECT (widget), |
---|
2082 | draw_data_key_id); |
---|
2083 | gtk_object_set_data_by_id (GTK_OBJECT (widget), |
---|
2084 | draw_data_key_id, |
---|
2085 | NULL); |
---|
2086 | gtk_object_set_data_by_id (GTK_OBJECT (widget), |
---|
2087 | draw_data_tmp_key_id, |
---|
2088 | draw_data_list); |
---|
2089 | |
---|
2090 | /* XXX: Since we are unsetting this flag here, further |
---|
2091 | * down the only way we can check if a redraw is queued |
---|
2092 | * on a given widget is by calling gtk_object_get_data. |
---|
2093 | * for speed purposes we might well want a private |
---|
2094 | * flag GTK_REDRAW_PROCESSING or something. |
---|
2095 | */ |
---|
2096 | GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_PENDING); |
---|
2097 | GTK_PRIVATE_UNSET_FLAG (widget, GTK_FULLDRAW_PENDING); |
---|
2098 | |
---|
2099 | while (draw_data_list) |
---|
2100 | { |
---|
2101 | gboolean full_allocation = FALSE; |
---|
2102 | GtkDrawData *data = draw_data_list->data; |
---|
2103 | |
---|
2104 | if (data->window) |
---|
2105 | { |
---|
2106 | /* If the translation fails, we have a handlebox, |
---|
2107 | * so redraw the whole widget. Could be done better? |
---|
2108 | */ |
---|
2109 | full_allocation = !gtk_widget_clip_rect (widget, |
---|
2110 | data->window, |
---|
2111 | &data->rect, |
---|
2112 | NULL, NULL); |
---|
2113 | data->window = NULL; |
---|
2114 | } |
---|
2115 | else if ((data->rect.width == 0) && (data->rect.height == 0)) |
---|
2116 | full_allocation = TRUE; |
---|
2117 | |
---|
2118 | if (full_allocation) |
---|
2119 | { |
---|
2120 | if (GTK_WIDGET_NO_WINDOW (widget)) |
---|
2121 | { |
---|
2122 | data->rect.x = widget->allocation.x; |
---|
2123 | data->rect.y = widget->allocation.y; |
---|
2124 | } |
---|
2125 | else |
---|
2126 | { |
---|
2127 | data->rect.x = 0; |
---|
2128 | data->rect.y = 0; |
---|
2129 | } |
---|
2130 | data->rect.width = widget->allocation.width; |
---|
2131 | data->rect.height = widget->allocation.height; |
---|
2132 | } |
---|
2133 | |
---|
2134 | draw_data_list = draw_data_list->next; |
---|
2135 | } |
---|
2136 | |
---|
2137 | widget_list = widget_list->next; |
---|
2138 | } |
---|
2139 | |
---|
2140 | /* Coalesce redraws. |
---|
2141 | */ |
---|
2142 | widget_list = old_queue; |
---|
2143 | while (widget_list) |
---|
2144 | { |
---|
2145 | GSList *prev_node = NULL; |
---|
2146 | widget = widget_list->data; |
---|
2147 | draw_data_list = gtk_object_get_data_by_id (GTK_OBJECT (widget), |
---|
2148 | draw_data_tmp_key_id); |
---|
2149 | |
---|
2150 | while (draw_data_list) |
---|
2151 | { |
---|
2152 | gint x_offset, y_offset; |
---|
2153 | GtkDrawData *data = draw_data_list->data; |
---|
2154 | GSList *parent_list = draw_data_list->next; |
---|
2155 | GtkWidget *parent; |
---|
2156 | GdkWindow *window; |
---|
2157 | |
---|
2158 | x_offset = 0; |
---|
2159 | y_offset = 0; |
---|
2160 | |
---|
2161 | parent = widget; |
---|
2162 | while (parent) |
---|
2163 | { |
---|
2164 | while (parent_list) |
---|
2165 | { |
---|
2166 | if (gtk_widget_draw_data_combine (parent_list->data, data)) |
---|
2167 | { |
---|
2168 | GSList *tmp; |
---|
2169 | if (prev_node) |
---|
2170 | prev_node->next = draw_data_list->next; |
---|
2171 | else |
---|
2172 | gtk_object_set_data_by_id (GTK_OBJECT (widget), |
---|
2173 | draw_data_tmp_key_id, |
---|
2174 | draw_data_list->next); |
---|
2175 | |
---|
2176 | tmp = draw_data_list->next; |
---|
2177 | draw_data_list->next = draw_data_free_list; |
---|
2178 | draw_data_free_list = draw_data_list; |
---|
2179 | draw_data_list = tmp; |
---|
2180 | |
---|
2181 | goto next_rect; |
---|
2182 | } |
---|
2183 | |
---|
2184 | parent_list = parent_list->next; |
---|
2185 | } |
---|
2186 | |
---|
2187 | window = parent->window; |
---|
2188 | |
---|
2189 | if (parent->parent && parent->parent->window != window) |
---|
2190 | { |
---|
2191 | if (!GTK_WIDGET_NO_WINDOW (parent)) |
---|
2192 | { |
---|
2193 | gint x, y; |
---|
2194 | gdk_window_get_position (window, &x, &y); |
---|
2195 | data->rect.x -= x - parent->allocation.x; |
---|
2196 | x_offset -= x - parent->allocation.x; |
---|
2197 | data->rect.y -= y - parent->allocation.y; |
---|
2198 | y_offset -= y - parent->allocation.y; |
---|
2199 | } |
---|
2200 | /* If we can't translate the rectangle, stop trying to |
---|
2201 | * merge. (This occurs for a handlebox) |
---|
2202 | */ |
---|
2203 | if (!gtk_widget_clip_rect (parent->parent, window, &data->rect, |
---|
2204 | &x_offset, &y_offset)) |
---|
2205 | parent = NULL; |
---|
2206 | } |
---|
2207 | |
---|
2208 | if (parent) |
---|
2209 | parent = parent->parent; |
---|
2210 | |
---|
2211 | if (parent) |
---|
2212 | parent_list = gtk_object_get_data_by_id (GTK_OBJECT (parent), |
---|
2213 | draw_data_tmp_key_id); |
---|
2214 | else |
---|
2215 | parent_list = NULL; |
---|
2216 | } |
---|
2217 | |
---|
2218 | /* OK, this rectangle stays around. But take advantage |
---|
2219 | * of the work we've done to clip it to the visible area - |
---|
2220 | * rect.width/height have already been appropriately |
---|
2221 | * decreased |
---|
2222 | */ |
---|
2223 | data->rect.x -= x_offset; |
---|
2224 | data->rect.y -= y_offset; |
---|
2225 | |
---|
2226 | |
---|
2227 | prev_node = draw_data_list; |
---|
2228 | |
---|
2229 | draw_data_list = draw_data_list->next; |
---|
2230 | next_rect: |
---|
2231 | continue; |
---|
2232 | } |
---|
2233 | widget_list = widget_list->next; |
---|
2234 | } |
---|
2235 | |
---|
2236 | /* Process the draws */ |
---|
2237 | |
---|
2238 | widget_list = old_queue; |
---|
2239 | |
---|
2240 | while (widget_list) |
---|
2241 | { |
---|
2242 | GSList *tmp_list; |
---|
2243 | |
---|
2244 | widget = widget_list->data; |
---|
2245 | draw_data_list = gtk_object_get_data_by_id (GTK_OBJECT (widget), |
---|
2246 | draw_data_tmp_key_id); |
---|
2247 | gtk_object_set_data_by_id (GTK_OBJECT (widget), |
---|
2248 | draw_data_tmp_key_id, |
---|
2249 | NULL); |
---|
2250 | |
---|
2251 | tmp_list = draw_data_list; |
---|
2252 | while (tmp_list) |
---|
2253 | { |
---|
2254 | GtkDrawData *data = tmp_list->data; |
---|
2255 | if ((data->rect.width != 0) && (data->rect.height != 0)) |
---|
2256 | gtk_widget_draw (widget, &data->rect); |
---|
2257 | |
---|
2258 | if (tmp_list->next) |
---|
2259 | tmp_list = tmp_list->next; |
---|
2260 | else |
---|
2261 | { |
---|
2262 | tmp_list->next = draw_data_free_list; |
---|
2263 | draw_data_free_list = draw_data_list; |
---|
2264 | break; |
---|
2265 | } |
---|
2266 | } |
---|
2267 | |
---|
2268 | widget_list = widget_list->next; |
---|
2269 | } |
---|
2270 | |
---|
2271 | g_slist_free (old_queue); |
---|
2272 | |
---|
2273 | GDK_THREADS_LEAVE (); |
---|
2274 | |
---|
2275 | return FALSE; |
---|
2276 | } |
---|
2277 | |
---|
2278 | void |
---|
2279 | gtk_widget_queue_resize (GtkWidget *widget) |
---|
2280 | { |
---|
2281 | g_return_if_fail (widget != NULL); |
---|
2282 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
2283 | |
---|
2284 | if (GTK_IS_RESIZE_CONTAINER (widget)) |
---|
2285 | gtk_container_clear_resize_widgets (GTK_CONTAINER (widget)); |
---|
2286 | |
---|
2287 | gtk_widget_queue_clear (widget); |
---|
2288 | |
---|
2289 | if (widget->parent) |
---|
2290 | gtk_container_queue_resize (GTK_CONTAINER (widget->parent)); |
---|
2291 | else if (GTK_WIDGET_TOPLEVEL (widget)) |
---|
2292 | gtk_container_queue_resize (GTK_CONTAINER (widget)); |
---|
2293 | } |
---|
2294 | |
---|
2295 | /***************************************** |
---|
2296 | * gtk_widget_draw: |
---|
2297 | * |
---|
2298 | * arguments: |
---|
2299 | * |
---|
2300 | * results: |
---|
2301 | *****************************************/ |
---|
2302 | |
---|
2303 | void |
---|
2304 | gtk_widget_draw (GtkWidget *widget, |
---|
2305 | GdkRectangle *area) |
---|
2306 | { |
---|
2307 | GdkRectangle temp_area; |
---|
2308 | |
---|
2309 | g_return_if_fail (widget != NULL); |
---|
2310 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
2311 | |
---|
2312 | if (GTK_WIDGET_DRAWABLE (widget)) |
---|
2313 | { |
---|
2314 | if (!area) |
---|
2315 | { |
---|
2316 | if (GTK_WIDGET_NO_WINDOW (widget)) |
---|
2317 | { |
---|
2318 | temp_area.x = widget->allocation.x; |
---|
2319 | temp_area.y = widget->allocation.y; |
---|
2320 | } |
---|
2321 | else |
---|
2322 | { |
---|
2323 | temp_area.x = 0; |
---|
2324 | temp_area.y = 0; |
---|
2325 | } |
---|
2326 | |
---|
2327 | temp_area.width = widget->allocation.width; |
---|
2328 | temp_area.height = widget->allocation.height; |
---|
2329 | area = &temp_area; |
---|
2330 | } |
---|
2331 | |
---|
2332 | gtk_signal_emit (GTK_OBJECT (widget), widget_signals[DRAW], area); |
---|
2333 | } |
---|
2334 | } |
---|
2335 | |
---|
2336 | /***************************************** |
---|
2337 | * gtk_widget_draw_focus: |
---|
2338 | * |
---|
2339 | * arguments: |
---|
2340 | * |
---|
2341 | * results: |
---|
2342 | *****************************************/ |
---|
2343 | |
---|
2344 | void |
---|
2345 | gtk_widget_draw_focus (GtkWidget *widget) |
---|
2346 | { |
---|
2347 | g_return_if_fail (widget != NULL); |
---|
2348 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
2349 | |
---|
2350 | gtk_signal_emit (GTK_OBJECT (widget), widget_signals[DRAW_FOCUS]); |
---|
2351 | } |
---|
2352 | |
---|
2353 | /***************************************** |
---|
2354 | * gtk_widget_draw_default: |
---|
2355 | * |
---|
2356 | * arguments: |
---|
2357 | * |
---|
2358 | * results: |
---|
2359 | *****************************************/ |
---|
2360 | |
---|
2361 | void |
---|
2362 | gtk_widget_draw_default (GtkWidget *widget) |
---|
2363 | { |
---|
2364 | g_return_if_fail (widget != NULL); |
---|
2365 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
2366 | |
---|
2367 | gtk_signal_emit (GTK_OBJECT (widget), widget_signals[DRAW_DEFAULT]); |
---|
2368 | } |
---|
2369 | |
---|
2370 | /***************************************** |
---|
2371 | * gtk_widget_size_request: |
---|
2372 | * |
---|
2373 | * arguments: |
---|
2374 | * |
---|
2375 | * results: |
---|
2376 | *****************************************/ |
---|
2377 | |
---|
2378 | void |
---|
2379 | gtk_widget_size_request (GtkWidget *widget, |
---|
2380 | GtkRequisition *requisition) |
---|
2381 | { |
---|
2382 | g_return_if_fail (widget != NULL); |
---|
2383 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
2384 | |
---|
2385 | #ifdef G_ENABLE_DEBUG |
---|
2386 | if (requisition == &widget->requisition) |
---|
2387 | g_warning ("gtk_widget_size_request() called on child widget with request equal\n to widget->requisition. gtk_widget_set_usize() may not work properly."); |
---|
2388 | #endif /* G_ENABLE_DEBUG */ |
---|
2389 | |
---|
2390 | gtk_widget_ref (widget); |
---|
2391 | gtk_widget_ensure_style (widget); |
---|
2392 | gtk_signal_emit (GTK_OBJECT (widget), widget_signals[SIZE_REQUEST], |
---|
2393 | &widget->requisition); |
---|
2394 | |
---|
2395 | if (requisition) |
---|
2396 | gtk_widget_get_child_requisition (widget, requisition); |
---|
2397 | |
---|
2398 | gtk_widget_unref (widget); |
---|
2399 | } |
---|
2400 | |
---|
2401 | /***************************************** |
---|
2402 | * gtk_widget_get_requesition: |
---|
2403 | * |
---|
2404 | * arguments: |
---|
2405 | * |
---|
2406 | * results: |
---|
2407 | *****************************************/ |
---|
2408 | |
---|
2409 | void |
---|
2410 | gtk_widget_get_child_requisition (GtkWidget *widget, |
---|
2411 | GtkRequisition *requisition) |
---|
2412 | { |
---|
2413 | GtkWidgetAuxInfo *aux_info; |
---|
2414 | |
---|
2415 | g_return_if_fail (widget != NULL); |
---|
2416 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
2417 | |
---|
2418 | *requisition = widget->requisition; |
---|
2419 | |
---|
2420 | aux_info = gtk_object_get_data_by_id (GTK_OBJECT (widget), aux_info_key_id); |
---|
2421 | if (aux_info) |
---|
2422 | { |
---|
2423 | if (aux_info->width > 0) |
---|
2424 | requisition->width = aux_info->width; |
---|
2425 | if (aux_info->height > 0) |
---|
2426 | requisition->height = aux_info->height; |
---|
2427 | } |
---|
2428 | } |
---|
2429 | |
---|
2430 | /***************************************** |
---|
2431 | * gtk_widget_size_allocate: |
---|
2432 | * |
---|
2433 | * arguments: |
---|
2434 | * |
---|
2435 | * results: |
---|
2436 | *****************************************/ |
---|
2437 | |
---|
2438 | void |
---|
2439 | gtk_widget_size_allocate (GtkWidget *widget, |
---|
2440 | GtkAllocation *allocation) |
---|
2441 | { |
---|
2442 | GtkWidgetAuxInfo *aux_info; |
---|
2443 | GtkAllocation real_allocation; |
---|
2444 | gboolean needs_draw = FALSE; |
---|
2445 | |
---|
2446 | g_return_if_fail (widget != NULL); |
---|
2447 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
2448 | |
---|
2449 | real_allocation = *allocation; |
---|
2450 | aux_info = gtk_object_get_data_by_id (GTK_OBJECT (widget), aux_info_key_id); |
---|
2451 | |
---|
2452 | if (aux_info) |
---|
2453 | { |
---|
2454 | if (aux_info->x != -1) |
---|
2455 | real_allocation.x = aux_info->x; |
---|
2456 | if (aux_info->y != -1) |
---|
2457 | real_allocation.y = aux_info->y; |
---|
2458 | } |
---|
2459 | |
---|
2460 | real_allocation.width = MAX (real_allocation.width, 1); |
---|
2461 | real_allocation.height = MAX (real_allocation.height, 1); |
---|
2462 | |
---|
2463 | if (real_allocation.width > 32767 || |
---|
2464 | real_allocation.height > 32767) |
---|
2465 | { |
---|
2466 | g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d", |
---|
2467 | real_allocation.width, |
---|
2468 | real_allocation.height); |
---|
2469 | real_allocation.width = MIN (real_allocation.width, 32767); |
---|
2470 | real_allocation.height = MIN (real_allocation.height, 32767); |
---|
2471 | } |
---|
2472 | |
---|
2473 | if (GTK_WIDGET_NO_WINDOW (widget)) |
---|
2474 | { |
---|
2475 | if (widget->allocation.x != real_allocation.x || |
---|
2476 | widget->allocation.y != real_allocation.y || |
---|
2477 | widget->allocation.width != real_allocation.width || |
---|
2478 | widget->allocation.height != real_allocation.height) |
---|
2479 | { |
---|
2480 | gtk_widget_queue_clear_child (widget); |
---|
2481 | needs_draw = TRUE; |
---|
2482 | } |
---|
2483 | } |
---|
2484 | else if (widget->allocation.width != real_allocation.width || |
---|
2485 | widget->allocation.height != real_allocation.height) |
---|
2486 | { |
---|
2487 | needs_draw = TRUE; |
---|
2488 | } |
---|
2489 | |
---|
2490 | if (GTK_IS_RESIZE_CONTAINER (widget)) |
---|
2491 | gtk_container_clear_resize_widgets (GTK_CONTAINER (widget)); |
---|
2492 | |
---|
2493 | gtk_signal_emit (GTK_OBJECT (widget), widget_signals[SIZE_ALLOCATE], &real_allocation); |
---|
2494 | |
---|
2495 | if (needs_draw) |
---|
2496 | { |
---|
2497 | gtk_widget_queue_draw (widget); |
---|
2498 | if (widget->parent && GTK_CONTAINER (widget->parent)->reallocate_redraws) |
---|
2499 | gtk_widget_queue_draw (widget->parent); |
---|
2500 | } |
---|
2501 | } |
---|
2502 | |
---|
2503 | static void |
---|
2504 | gtk_widget_real_size_allocate (GtkWidget *widget, |
---|
2505 | GtkAllocation *allocation) |
---|
2506 | { |
---|
2507 | g_return_if_fail (widget != NULL); |
---|
2508 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
2509 | |
---|
2510 | widget->allocation = *allocation; |
---|
2511 | |
---|
2512 | if (GTK_WIDGET_REALIZED (widget) && |
---|
2513 | !GTK_WIDGET_NO_WINDOW (widget)) |
---|
2514 | { |
---|
2515 | gdk_window_move_resize (widget->window, |
---|
2516 | allocation->x, allocation->y, |
---|
2517 | allocation->width, allocation->height); |
---|
2518 | } |
---|
2519 | } |
---|
2520 | |
---|
2521 | static void |
---|
2522 | gtk_widget_stop_add_accelerator (GtkWidget *widget) |
---|
2523 | { |
---|
2524 | g_return_if_fail (widget != NULL); |
---|
2525 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
2526 | |
---|
2527 | gtk_signal_emit_stop (GTK_OBJECT (widget), widget_signals[ADD_ACCELERATOR]); |
---|
2528 | } |
---|
2529 | |
---|
2530 | static void |
---|
2531 | gtk_widget_stop_remove_accelerator (GtkWidget *widget) |
---|
2532 | { |
---|
2533 | g_return_if_fail (widget != NULL); |
---|
2534 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
2535 | |
---|
2536 | gtk_signal_emit_stop (GTK_OBJECT (widget), widget_signals[REMOVE_ACCELERATOR]); |
---|
2537 | } |
---|
2538 | |
---|
2539 | void |
---|
2540 | gtk_widget_lock_accelerators (GtkWidget *widget) |
---|
2541 | { |
---|
2542 | g_return_if_fail (widget != NULL); |
---|
2543 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
2544 | |
---|
2545 | if (!gtk_widget_accelerators_locked (widget)) |
---|
2546 | { |
---|
2547 | gtk_signal_connect (GTK_OBJECT (widget), |
---|
2548 | "add_accelerator", |
---|
2549 | GTK_SIGNAL_FUNC (gtk_widget_stop_add_accelerator), |
---|
2550 | NULL); |
---|
2551 | gtk_signal_connect (GTK_OBJECT (widget), |
---|
2552 | "remove_accelerator", |
---|
2553 | GTK_SIGNAL_FUNC (gtk_widget_stop_remove_accelerator), |
---|
2554 | NULL); |
---|
2555 | } |
---|
2556 | } |
---|
2557 | |
---|
2558 | void |
---|
2559 | gtk_widget_unlock_accelerators (GtkWidget *widget) |
---|
2560 | { |
---|
2561 | g_return_if_fail (widget != NULL); |
---|
2562 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
2563 | |
---|
2564 | if (gtk_widget_accelerators_locked (widget)) |
---|
2565 | { |
---|
2566 | gtk_signal_disconnect_by_func (GTK_OBJECT (widget), |
---|
2567 | GTK_SIGNAL_FUNC (gtk_widget_stop_add_accelerator), |
---|
2568 | NULL); |
---|
2569 | gtk_signal_disconnect_by_func (GTK_OBJECT (widget), |
---|
2570 | GTK_SIGNAL_FUNC (gtk_widget_stop_remove_accelerator), |
---|
2571 | NULL); |
---|
2572 | } |
---|
2573 | } |
---|
2574 | |
---|
2575 | gboolean |
---|
2576 | gtk_widget_accelerators_locked (GtkWidget *widget) |
---|
2577 | { |
---|
2578 | g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); |
---|
2579 | |
---|
2580 | return gtk_signal_handler_pending_by_func (GTK_OBJECT (widget), |
---|
2581 | widget_signals[ADD_ACCELERATOR], |
---|
2582 | TRUE, |
---|
2583 | GTK_SIGNAL_FUNC (gtk_widget_stop_add_accelerator), |
---|
2584 | NULL) > 0; |
---|
2585 | } |
---|
2586 | |
---|
2587 | void |
---|
2588 | gtk_widget_add_accelerator (GtkWidget *widget, |
---|
2589 | const gchar *accel_signal, |
---|
2590 | GtkAccelGroup *accel_group, |
---|
2591 | guint accel_key, |
---|
2592 | guint accel_mods, |
---|
2593 | GtkAccelFlags accel_flags) |
---|
2594 | { |
---|
2595 | g_return_if_fail (widget != NULL); |
---|
2596 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
2597 | g_return_if_fail (accel_group != NULL); |
---|
2598 | |
---|
2599 | gtk_accel_group_add (accel_group, |
---|
2600 | accel_key, |
---|
2601 | accel_mods, |
---|
2602 | accel_flags, |
---|
2603 | (GtkObject*) widget, |
---|
2604 | accel_signal); |
---|
2605 | } |
---|
2606 | |
---|
2607 | void |
---|
2608 | gtk_widget_remove_accelerator (GtkWidget *widget, |
---|
2609 | GtkAccelGroup *accel_group, |
---|
2610 | guint accel_key, |
---|
2611 | guint accel_mods) |
---|
2612 | { |
---|
2613 | g_return_if_fail (widget != NULL); |
---|
2614 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
2615 | g_return_if_fail (accel_group != NULL); |
---|
2616 | |
---|
2617 | gtk_accel_group_remove (accel_group, |
---|
2618 | accel_key, |
---|
2619 | accel_mods, |
---|
2620 | (GtkObject*) widget); |
---|
2621 | } |
---|
2622 | |
---|
2623 | void |
---|
2624 | gtk_widget_remove_accelerators (GtkWidget *widget, |
---|
2625 | const gchar *accel_signal, |
---|
2626 | gboolean visible_only) |
---|
2627 | { |
---|
2628 | GSList *slist; |
---|
2629 | guint signal_id; |
---|
2630 | |
---|
2631 | g_return_if_fail (widget != NULL); |
---|
2632 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
2633 | g_return_if_fail (accel_signal != NULL); |
---|
2634 | |
---|
2635 | signal_id = gtk_signal_lookup (accel_signal, GTK_OBJECT_TYPE (widget)); |
---|
2636 | g_return_if_fail (signal_id != 0); |
---|
2637 | |
---|
2638 | slist = gtk_accel_group_entries_from_object (GTK_OBJECT (widget)); |
---|
2639 | while (slist) |
---|
2640 | { |
---|
2641 | GtkAccelEntry *ac_entry; |
---|
2642 | |
---|
2643 | ac_entry = slist->data; |
---|
2644 | slist = slist->next; |
---|
2645 | if (ac_entry->accel_flags & GTK_ACCEL_VISIBLE && |
---|
2646 | ac_entry->signal_id == signal_id) |
---|
2647 | gtk_widget_remove_accelerator (GTK_WIDGET (widget), |
---|
2648 | ac_entry->accel_group, |
---|
2649 | ac_entry->accelerator_key, |
---|
2650 | ac_entry->accelerator_mods); |
---|
2651 | } |
---|
2652 | } |
---|
2653 | |
---|
2654 | guint |
---|
2655 | gtk_widget_accelerator_signal (GtkWidget *widget, |
---|
2656 | GtkAccelGroup *accel_group, |
---|
2657 | guint accel_key, |
---|
2658 | guint accel_mods) |
---|
2659 | { |
---|
2660 | GtkAccelEntry *ac_entry; |
---|
2661 | |
---|
2662 | g_return_val_if_fail (widget != NULL, 0); |
---|
2663 | g_return_val_if_fail (GTK_IS_WIDGET (widget), 0); |
---|
2664 | g_return_val_if_fail (accel_group != NULL, 0); |
---|
2665 | |
---|
2666 | ac_entry = gtk_accel_group_get_entry (accel_group, accel_key, accel_mods); |
---|
2667 | |
---|
2668 | if (ac_entry && ac_entry->object == (GtkObject*) widget) |
---|
2669 | return ac_entry->signal_id; |
---|
2670 | return 0; |
---|
2671 | } |
---|
2672 | |
---|
2673 | static gint |
---|
2674 | gtk_widget_real_key_press_event (GtkWidget *widget, |
---|
2675 | GdkEventKey *event) |
---|
2676 | { |
---|
2677 | gboolean handled = FALSE; |
---|
2678 | |
---|
2679 | g_return_val_if_fail (widget != NULL, handled); |
---|
2680 | g_return_val_if_fail (GTK_IS_WIDGET (widget), handled); |
---|
2681 | g_return_val_if_fail (event != NULL, handled); |
---|
2682 | |
---|
2683 | if (!handled) |
---|
2684 | handled = gtk_bindings_activate (GTK_OBJECT (widget), |
---|
2685 | event->keyval, |
---|
2686 | event->state); |
---|
2687 | |
---|
2688 | return handled; |
---|
2689 | } |
---|
2690 | |
---|
2691 | static gint |
---|
2692 | gtk_widget_real_key_release_event (GtkWidget *widget, |
---|
2693 | GdkEventKey *event) |
---|
2694 | { |
---|
2695 | gboolean handled = FALSE; |
---|
2696 | |
---|
2697 | g_return_val_if_fail (widget != NULL, handled); |
---|
2698 | g_return_val_if_fail (GTK_IS_WIDGET (widget), handled); |
---|
2699 | g_return_val_if_fail (event != NULL, handled); |
---|
2700 | |
---|
2701 | if (!handled) |
---|
2702 | handled = gtk_bindings_activate (GTK_OBJECT (widget), |
---|
2703 | event->keyval, |
---|
2704 | event->state | GDK_RELEASE_MASK); |
---|
2705 | |
---|
2706 | return handled; |
---|
2707 | } |
---|
2708 | |
---|
2709 | /***************************************** |
---|
2710 | * gtk_widget_event: |
---|
2711 | * |
---|
2712 | * arguments: |
---|
2713 | * |
---|
2714 | * results: |
---|
2715 | *****************************************/ |
---|
2716 | |
---|
2717 | gint |
---|
2718 | gtk_widget_event (GtkWidget *widget, |
---|
2719 | GdkEvent *event) |
---|
2720 | { |
---|
2721 | gint return_val; |
---|
2722 | gint signal_num; |
---|
2723 | |
---|
2724 | g_return_val_if_fail (widget != NULL, TRUE); |
---|
2725 | g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE); |
---|
2726 | |
---|
2727 | gtk_widget_ref (widget); |
---|
2728 | return_val = FALSE; |
---|
2729 | gtk_signal_emit (GTK_OBJECT (widget), widget_signals[EVENT], event, |
---|
2730 | &return_val); |
---|
2731 | if (return_val || GTK_OBJECT_DESTROYED (widget)) |
---|
2732 | { |
---|
2733 | gtk_widget_unref (widget); |
---|
2734 | return TRUE; |
---|
2735 | } |
---|
2736 | |
---|
2737 | switch (event->type) |
---|
2738 | { |
---|
2739 | GtkWidget *parent; |
---|
2740 | case GDK_NOTHING: |
---|
2741 | signal_num = -1; |
---|
2742 | break; |
---|
2743 | case GDK_BUTTON_PRESS: |
---|
2744 | case GDK_2BUTTON_PRESS: |
---|
2745 | case GDK_3BUTTON_PRESS: |
---|
2746 | signal_num = BUTTON_PRESS_EVENT; |
---|
2747 | break; |
---|
2748 | case GDK_BUTTON_RELEASE: |
---|
2749 | signal_num = BUTTON_RELEASE_EVENT; |
---|
2750 | break; |
---|
2751 | case GDK_MOTION_NOTIFY: |
---|
2752 | signal_num = MOTION_NOTIFY_EVENT; |
---|
2753 | break; |
---|
2754 | case GDK_DELETE: |
---|
2755 | signal_num = DELETE_EVENT; |
---|
2756 | break; |
---|
2757 | case GDK_DESTROY: |
---|
2758 | signal_num = DESTROY_EVENT; |
---|
2759 | break; |
---|
2760 | case GDK_KEY_PRESS: |
---|
2761 | signal_num = KEY_PRESS_EVENT; |
---|
2762 | break; |
---|
2763 | case GDK_KEY_RELEASE: |
---|
2764 | signal_num = KEY_RELEASE_EVENT; |
---|
2765 | break; |
---|
2766 | case GDK_ENTER_NOTIFY: |
---|
2767 | signal_num = ENTER_NOTIFY_EVENT; |
---|
2768 | break; |
---|
2769 | case GDK_LEAVE_NOTIFY: |
---|
2770 | signal_num = LEAVE_NOTIFY_EVENT; |
---|
2771 | break; |
---|
2772 | case GDK_FOCUS_CHANGE: |
---|
2773 | if (event->focus_change.in) |
---|
2774 | signal_num = FOCUS_IN_EVENT; |
---|
2775 | else |
---|
2776 | signal_num = FOCUS_OUT_EVENT; |
---|
2777 | break; |
---|
2778 | case GDK_CONFIGURE: |
---|
2779 | signal_num = CONFIGURE_EVENT; |
---|
2780 | break; |
---|
2781 | case GDK_MAP: |
---|
2782 | signal_num = MAP_EVENT; |
---|
2783 | break; |
---|
2784 | case GDK_UNMAP: |
---|
2785 | signal_num = UNMAP_EVENT; |
---|
2786 | break; |
---|
2787 | case GDK_PROPERTY_NOTIFY: |
---|
2788 | signal_num = PROPERTY_NOTIFY_EVENT; |
---|
2789 | break; |
---|
2790 | case GDK_SELECTION_CLEAR: |
---|
2791 | signal_num = SELECTION_CLEAR_EVENT; |
---|
2792 | break; |
---|
2793 | case GDK_SELECTION_REQUEST: |
---|
2794 | signal_num = SELECTION_REQUEST_EVENT; |
---|
2795 | break; |
---|
2796 | case GDK_SELECTION_NOTIFY: |
---|
2797 | signal_num = SELECTION_NOTIFY_EVENT; |
---|
2798 | break; |
---|
2799 | case GDK_PROXIMITY_IN: |
---|
2800 | signal_num = PROXIMITY_IN_EVENT; |
---|
2801 | break; |
---|
2802 | case GDK_PROXIMITY_OUT: |
---|
2803 | signal_num = PROXIMITY_OUT_EVENT; |
---|
2804 | break; |
---|
2805 | case GDK_NO_EXPOSE: |
---|
2806 | signal_num = NO_EXPOSE_EVENT; |
---|
2807 | break; |
---|
2808 | case GDK_CLIENT_EVENT: |
---|
2809 | signal_num = CLIENT_EVENT; |
---|
2810 | break; |
---|
2811 | case GDK_EXPOSE: |
---|
2812 | /* there is no sense in providing a widget with bogus expose events. |
---|
2813 | * also we make the optimization to discard expose events for widgets |
---|
2814 | * that have a full redraw pending (given that the event is !send_event, |
---|
2815 | * otherwise we assume we can trust the event). |
---|
2816 | */ |
---|
2817 | if (event->any.send_event) |
---|
2818 | parent = NULL; |
---|
2819 | else if (event->any.window) |
---|
2820 | { |
---|
2821 | parent = widget; |
---|
2822 | while (parent) |
---|
2823 | { |
---|
2824 | if (GTK_WIDGET_FULLDRAW_PENDING (parent)) |
---|
2825 | break; |
---|
2826 | parent = parent->parent; |
---|
2827 | } |
---|
2828 | /* <HACK> gnome-dock didn't propagate draws to torn off |
---|
2829 | * children. So don't consider those ancestors. |
---|
2830 | */ |
---|
2831 | if (parent) |
---|
2832 | { |
---|
2833 | GdkWindow *parent_window = event->any.window; |
---|
2834 | |
---|
2835 | while (parent_window && parent_window != parent->window) |
---|
2836 | parent_window = gdk_window_get_parent (parent_window); |
---|
2837 | |
---|
2838 | if (!parent_window) |
---|
2839 | parent = NULL; |
---|
2840 | } |
---|
2841 | /* </HACK> */ |
---|
2842 | } |
---|
2843 | if (!event->any.window || parent) |
---|
2844 | { |
---|
2845 | gtk_widget_unref (widget); |
---|
2846 | return TRUE; |
---|
2847 | } |
---|
2848 | signal_num = EXPOSE_EVENT; |
---|
2849 | break; |
---|
2850 | case GDK_VISIBILITY_NOTIFY: |
---|
2851 | signal_num = VISIBILITY_NOTIFY_EVENT; |
---|
2852 | break; |
---|
2853 | default: |
---|
2854 | g_warning ("could not determine signal number for event: %d", event->type); |
---|
2855 | gtk_widget_unref (widget); |
---|
2856 | return TRUE; |
---|
2857 | } |
---|
2858 | |
---|
2859 | if (signal_num != -1) |
---|
2860 | gtk_signal_emit (GTK_OBJECT (widget), widget_signals[signal_num], event, &return_val); |
---|
2861 | |
---|
2862 | return_val |= GTK_OBJECT_DESTROYED (widget); |
---|
2863 | |
---|
2864 | gtk_widget_unref (widget); |
---|
2865 | |
---|
2866 | return return_val; |
---|
2867 | } |
---|
2868 | |
---|
2869 | /***************************************** |
---|
2870 | * gtk_widget_activate: |
---|
2871 | * |
---|
2872 | * arguments: |
---|
2873 | * |
---|
2874 | * results: |
---|
2875 | *****************************************/ |
---|
2876 | |
---|
2877 | gboolean |
---|
2878 | gtk_widget_activate (GtkWidget *widget) |
---|
2879 | { |
---|
2880 | g_return_val_if_fail (widget != NULL, FALSE); |
---|
2881 | g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); |
---|
2882 | |
---|
2883 | if (WIDGET_CLASS (widget)->activate_signal) |
---|
2884 | { |
---|
2885 | /* FIXME: we should eventually check the signals signature here */ |
---|
2886 | gtk_signal_emit (GTK_OBJECT (widget), WIDGET_CLASS (widget)->activate_signal); |
---|
2887 | |
---|
2888 | return TRUE; |
---|
2889 | } |
---|
2890 | else |
---|
2891 | return FALSE; |
---|
2892 | } |
---|
2893 | |
---|
2894 | gboolean |
---|
2895 | gtk_widget_set_scroll_adjustments (GtkWidget *widget, |
---|
2896 | GtkAdjustment *hadjustment, |
---|
2897 | GtkAdjustment *vadjustment) |
---|
2898 | { |
---|
2899 | g_return_val_if_fail (widget != NULL, FALSE); |
---|
2900 | g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); |
---|
2901 | if (hadjustment) |
---|
2902 | g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE); |
---|
2903 | if (vadjustment) |
---|
2904 | g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE); |
---|
2905 | |
---|
2906 | if (WIDGET_CLASS (widget)->set_scroll_adjustments_signal) |
---|
2907 | { |
---|
2908 | /* FIXME: we should eventually check the signals signature here */ |
---|
2909 | gtk_signal_emit (GTK_OBJECT (widget), |
---|
2910 | WIDGET_CLASS (widget)->set_scroll_adjustments_signal, |
---|
2911 | hadjustment, vadjustment); |
---|
2912 | return TRUE; |
---|
2913 | } |
---|
2914 | else |
---|
2915 | return FALSE; |
---|
2916 | } |
---|
2917 | |
---|
2918 | /***************************************** |
---|
2919 | * gtk_widget_reparent_container_child: |
---|
2920 | * assistent function to gtk_widget_reparent |
---|
2921 | * |
---|
2922 | * arguments: |
---|
2923 | * |
---|
2924 | * results: |
---|
2925 | *****************************************/ |
---|
2926 | |
---|
2927 | static void |
---|
2928 | gtk_widget_reparent_container_child (GtkWidget *widget, |
---|
2929 | gpointer client_data) |
---|
2930 | { |
---|
2931 | g_return_if_fail (widget != NULL); |
---|
2932 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
2933 | g_return_if_fail (client_data != NULL); |
---|
2934 | |
---|
2935 | if (GTK_WIDGET_NO_WINDOW (widget)) |
---|
2936 | { |
---|
2937 | if (widget->window) |
---|
2938 | gdk_window_unref (widget->window); |
---|
2939 | widget->window = (GdkWindow*) client_data; |
---|
2940 | if (widget->window) |
---|
2941 | gdk_window_ref (widget->window); |
---|
2942 | |
---|
2943 | if (GTK_IS_CONTAINER (widget)) |
---|
2944 | gtk_container_forall (GTK_CONTAINER (widget), |
---|
2945 | gtk_widget_reparent_container_child, |
---|
2946 | client_data); |
---|
2947 | } |
---|
2948 | else |
---|
2949 | gdk_window_reparent (widget->window, |
---|
2950 | (GdkWindow*) client_data, 0, 0); |
---|
2951 | } |
---|
2952 | |
---|
2953 | /***************************************** |
---|
2954 | * gtk_widget_reparent: |
---|
2955 | * |
---|
2956 | * arguments: |
---|
2957 | * |
---|
2958 | * results: |
---|
2959 | *****************************************/ |
---|
2960 | |
---|
2961 | void |
---|
2962 | gtk_widget_reparent (GtkWidget *widget, |
---|
2963 | GtkWidget *new_parent) |
---|
2964 | { |
---|
2965 | g_return_if_fail (widget != NULL); |
---|
2966 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
2967 | g_return_if_fail (new_parent != NULL); |
---|
2968 | g_return_if_fail (GTK_IS_CONTAINER (new_parent)); |
---|
2969 | g_return_if_fail (widget->parent != NULL); |
---|
2970 | |
---|
2971 | if (widget->parent != new_parent) |
---|
2972 | { |
---|
2973 | /* First try to see if we can get away without unrealizing |
---|
2974 | * the widget as we reparent it. if so we set a flag so |
---|
2975 | * that gtk_widget_unparent doesn't unrealize widget |
---|
2976 | */ |
---|
2977 | if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_REALIZED (new_parent)) |
---|
2978 | GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT); |
---|
2979 | |
---|
2980 | gtk_widget_ref (widget); |
---|
2981 | gtk_container_remove (GTK_CONTAINER (widget->parent), widget); |
---|
2982 | gtk_container_add (GTK_CONTAINER (new_parent), widget); |
---|
2983 | gtk_widget_unref (widget); |
---|
2984 | |
---|
2985 | if (GTK_WIDGET_IN_REPARENT (widget)) |
---|
2986 | { |
---|
2987 | GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT); |
---|
2988 | |
---|
2989 | gtk_widget_reparent_container_child (widget, |
---|
2990 | gtk_widget_get_parent_window (widget)); |
---|
2991 | } |
---|
2992 | } |
---|
2993 | } |
---|
2994 | |
---|
2995 | /***************************************** |
---|
2996 | * gtk_widget_popup: |
---|
2997 | * |
---|
2998 | * arguments: |
---|
2999 | * |
---|
3000 | * results: |
---|
3001 | *****************************************/ |
---|
3002 | |
---|
3003 | void |
---|
3004 | gtk_widget_popup (GtkWidget *widget, |
---|
3005 | gint x, |
---|
3006 | gint y) |
---|
3007 | { |
---|
3008 | g_return_if_fail (widget != NULL); |
---|
3009 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
3010 | |
---|
3011 | if (!GTK_WIDGET_VISIBLE (widget)) |
---|
3012 | { |
---|
3013 | if (!GTK_WIDGET_REALIZED (widget)) |
---|
3014 | gtk_widget_realize (widget); |
---|
3015 | if (!GTK_WIDGET_NO_WINDOW (widget)) |
---|
3016 | gdk_window_move (widget->window, x, y); |
---|
3017 | gtk_widget_show (widget); |
---|
3018 | } |
---|
3019 | } |
---|
3020 | |
---|
3021 | /***************************************** |
---|
3022 | * gtk_widget_intersect: |
---|
3023 | * |
---|
3024 | * arguments: |
---|
3025 | * |
---|
3026 | * results: |
---|
3027 | *****************************************/ |
---|
3028 | |
---|
3029 | gint |
---|
3030 | gtk_widget_intersect (GtkWidget *widget, |
---|
3031 | GdkRectangle *area, |
---|
3032 | GdkRectangle *intersection) |
---|
3033 | { |
---|
3034 | GdkRectangle *dest; |
---|
3035 | GdkRectangle tmp; |
---|
3036 | gint return_val; |
---|
3037 | |
---|
3038 | g_return_val_if_fail (widget != NULL, FALSE); |
---|
3039 | g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); |
---|
3040 | g_return_val_if_fail (area != NULL, FALSE); |
---|
3041 | |
---|
3042 | if (intersection) |
---|
3043 | dest = intersection; |
---|
3044 | else |
---|
3045 | dest = &tmp; |
---|
3046 | |
---|
3047 | return_val = gdk_rectangle_intersect ((GdkRectangle*) &widget->allocation, area, dest); |
---|
3048 | |
---|
3049 | if (return_val && intersection && !GTK_WIDGET_NO_WINDOW (widget)) |
---|
3050 | { |
---|
3051 | intersection->x -= widget->allocation.x; |
---|
3052 | intersection->y -= widget->allocation.y; |
---|
3053 | } |
---|
3054 | |
---|
3055 | return return_val; |
---|
3056 | } |
---|
3057 | |
---|
3058 | /***************************************** |
---|
3059 | * gtk_widget_grab_focus: |
---|
3060 | * |
---|
3061 | * arguments: |
---|
3062 | * |
---|
3063 | * results: |
---|
3064 | *****************************************/ |
---|
3065 | |
---|
3066 | void |
---|
3067 | gtk_widget_grab_focus (GtkWidget *widget) |
---|
3068 | { |
---|
3069 | g_return_if_fail (widget != NULL); |
---|
3070 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
3071 | |
---|
3072 | gtk_signal_emit (GTK_OBJECT (widget), widget_signals[GRAB_FOCUS]); |
---|
3073 | } |
---|
3074 | |
---|
3075 | static void |
---|
3076 | reset_focus_recurse (GtkWidget *widget, |
---|
3077 | gpointer data) |
---|
3078 | { |
---|
3079 | if (GTK_IS_CONTAINER (widget)) |
---|
3080 | { |
---|
3081 | GtkContainer *container; |
---|
3082 | |
---|
3083 | container = GTK_CONTAINER (widget); |
---|
3084 | gtk_container_set_focus_child (container, NULL); |
---|
3085 | |
---|
3086 | gtk_container_foreach (container, |
---|
3087 | reset_focus_recurse, |
---|
3088 | NULL); |
---|
3089 | } |
---|
3090 | } |
---|
3091 | |
---|
3092 | static void |
---|
3093 | gtk_widget_real_grab_focus (GtkWidget *focus_widget) |
---|
3094 | { |
---|
3095 | g_return_if_fail (focus_widget != NULL); |
---|
3096 | g_return_if_fail (GTK_IS_WIDGET (focus_widget)); |
---|
3097 | |
---|
3098 | if (GTK_WIDGET_CAN_FOCUS (focus_widget)) |
---|
3099 | { |
---|
3100 | GtkWidget *toplevel; |
---|
3101 | GtkWidget *widget; |
---|
3102 | |
---|
3103 | /* clear the current focus setting, break if the current widget |
---|
3104 | * is the focus widget's parent, since containers above that will |
---|
3105 | * be set by the next loop. |
---|
3106 | */ |
---|
3107 | toplevel = gtk_widget_get_toplevel (focus_widget); |
---|
3108 | if (GTK_IS_WINDOW (toplevel)) |
---|
3109 | { |
---|
3110 | widget = GTK_WINDOW (toplevel)->focus_widget; |
---|
3111 | |
---|
3112 | if (widget == focus_widget) |
---|
3113 | { |
---|
3114 | /* We call gtk_window_set_focus() here so that the |
---|
3115 | * toplevel window can request the focus if necessary. |
---|
3116 | * This is needed when the toplevel is a GtkPlug |
---|
3117 | */ |
---|
3118 | if (!GTK_WIDGET_HAS_FOCUS (widget)) |
---|
3119 | gtk_window_set_focus (GTK_WINDOW (toplevel), focus_widget); |
---|
3120 | |
---|
3121 | return; |
---|
3122 | } |
---|
3123 | |
---|
3124 | if (widget) |
---|
3125 | { |
---|
3126 | while (widget->parent && widget->parent != focus_widget->parent) |
---|
3127 | { |
---|
3128 | widget = widget->parent; |
---|
3129 | gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL); |
---|
3130 | } |
---|
3131 | } |
---|
3132 | } |
---|
3133 | else if (toplevel != focus_widget) |
---|
3134 | { |
---|
3135 | /* gtk_widget_grab_focus() operates on a tree without window... |
---|
3136 | * actually, this is very questionable behaviour. |
---|
3137 | */ |
---|
3138 | |
---|
3139 | gtk_container_foreach (GTK_CONTAINER (toplevel), |
---|
3140 | reset_focus_recurse, |
---|
3141 | NULL); |
---|
3142 | } |
---|
3143 | |
---|
3144 | /* now propagate the new focus up the widget tree and finally |
---|
3145 | * set it on the window |
---|
3146 | */ |
---|
3147 | widget = focus_widget; |
---|
3148 | while (widget->parent) |
---|
3149 | { |
---|
3150 | gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget); |
---|
3151 | widget = widget->parent; |
---|
3152 | } |
---|
3153 | if (GTK_IS_WINDOW (widget)) |
---|
3154 | gtk_window_set_focus (GTK_WINDOW (widget), focus_widget); |
---|
3155 | } |
---|
3156 | } |
---|
3157 | |
---|
3158 | /***************************************** |
---|
3159 | * gtk_widget_grab_default: |
---|
3160 | * |
---|
3161 | * arguments: |
---|
3162 | * |
---|
3163 | * results: |
---|
3164 | *****************************************/ |
---|
3165 | |
---|
3166 | void |
---|
3167 | gtk_widget_grab_default (GtkWidget *widget) |
---|
3168 | { |
---|
3169 | GtkWidget *window; |
---|
3170 | GtkType window_type; |
---|
3171 | |
---|
3172 | g_return_if_fail (widget != NULL); |
---|
3173 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
3174 | g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (widget)); |
---|
3175 | |
---|
3176 | window_type = gtk_window_get_type (); |
---|
3177 | window = widget->parent; |
---|
3178 | |
---|
3179 | while (window && !gtk_type_is_a (GTK_WIDGET_TYPE (window), window_type)) |
---|
3180 | window = window->parent; |
---|
3181 | |
---|
3182 | if (window && gtk_type_is_a (GTK_WIDGET_TYPE (window), window_type)) |
---|
3183 | gtk_window_set_default (GTK_WINDOW (window), widget); |
---|
3184 | } |
---|
3185 | |
---|
3186 | /***************************************** |
---|
3187 | * gtk_widget_set_name: |
---|
3188 | * |
---|
3189 | * arguments: |
---|
3190 | * |
---|
3191 | * results: |
---|
3192 | *****************************************/ |
---|
3193 | |
---|
3194 | void |
---|
3195 | gtk_widget_set_name (GtkWidget *widget, |
---|
3196 | const gchar *name) |
---|
3197 | { |
---|
3198 | g_return_if_fail (widget != NULL); |
---|
3199 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
3200 | |
---|
3201 | if (widget->name) |
---|
3202 | g_free (widget->name); |
---|
3203 | widget->name = g_strdup (name); |
---|
3204 | |
---|
3205 | if (GTK_WIDGET_RC_STYLE (widget)) |
---|
3206 | gtk_widget_set_rc_style (widget); |
---|
3207 | } |
---|
3208 | |
---|
3209 | /***************************************** |
---|
3210 | * gtk_widget_get_name: |
---|
3211 | * |
---|
3212 | * arguments: |
---|
3213 | * |
---|
3214 | * results: |
---|
3215 | *****************************************/ |
---|
3216 | |
---|
3217 | gchar* |
---|
3218 | gtk_widget_get_name (GtkWidget *widget) |
---|
3219 | { |
---|
3220 | g_return_val_if_fail (widget != NULL, NULL); |
---|
3221 | g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); |
---|
3222 | |
---|
3223 | if (widget->name) |
---|
3224 | return widget->name; |
---|
3225 | return gtk_type_name (GTK_WIDGET_TYPE (widget)); |
---|
3226 | } |
---|
3227 | |
---|
3228 | /***************************************** |
---|
3229 | * gtk_widget_set_state: |
---|
3230 | * |
---|
3231 | * arguments: |
---|
3232 | * widget |
---|
3233 | * state |
---|
3234 | * |
---|
3235 | * results: |
---|
3236 | *****************************************/ |
---|
3237 | |
---|
3238 | void |
---|
3239 | gtk_widget_set_state (GtkWidget *widget, |
---|
3240 | GtkStateType state) |
---|
3241 | { |
---|
3242 | g_return_if_fail (widget != NULL); |
---|
3243 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
3244 | |
---|
3245 | if (state == GTK_WIDGET_STATE (widget)) |
---|
3246 | return; |
---|
3247 | |
---|
3248 | if (state == GTK_STATE_INSENSITIVE) |
---|
3249 | gtk_widget_set_sensitive (widget, FALSE); |
---|
3250 | else |
---|
3251 | { |
---|
3252 | GtkStateData data; |
---|
3253 | |
---|
3254 | data.state = state; |
---|
3255 | data.state_restoration = FALSE; |
---|
3256 | data.use_forall = FALSE; |
---|
3257 | if (widget->parent) |
---|
3258 | data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE); |
---|
3259 | else |
---|
3260 | data.parent_sensitive = TRUE; |
---|
3261 | |
---|
3262 | gtk_widget_propagate_state (widget, &data); |
---|
3263 | |
---|
3264 | if (GTK_WIDGET_DRAWABLE (widget)) |
---|
3265 | gtk_widget_queue_clear (widget); |
---|
3266 | } |
---|
3267 | } |
---|
3268 | |
---|
3269 | void |
---|
3270 | gtk_widget_set_app_paintable (GtkWidget *widget, |
---|
3271 | gboolean app_paintable) |
---|
3272 | { |
---|
3273 | g_return_if_fail (widget != NULL); |
---|
3274 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
3275 | |
---|
3276 | app_paintable = (app_paintable != FALSE); |
---|
3277 | |
---|
3278 | if (GTK_WIDGET_APP_PAINTABLE (widget) != app_paintable) |
---|
3279 | { |
---|
3280 | if (app_paintable) |
---|
3281 | GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE); |
---|
3282 | else |
---|
3283 | GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE); |
---|
3284 | |
---|
3285 | if (GTK_WIDGET_DRAWABLE (widget)) |
---|
3286 | gtk_widget_queue_clear (widget); |
---|
3287 | } |
---|
3288 | } |
---|
3289 | |
---|
3290 | /***************************************** |
---|
3291 | * gtk_widget_set_sensitive: |
---|
3292 | * |
---|
3293 | * arguments: |
---|
3294 | * widget |
---|
3295 | * boolean value for sensitivity |
---|
3296 | * |
---|
3297 | * results: |
---|
3298 | *****************************************/ |
---|
3299 | |
---|
3300 | void |
---|
3301 | gtk_widget_set_sensitive (GtkWidget *widget, |
---|
3302 | gboolean sensitive) |
---|
3303 | { |
---|
3304 | GtkStateData data; |
---|
3305 | |
---|
3306 | g_return_if_fail (widget != NULL); |
---|
3307 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
3308 | |
---|
3309 | sensitive = (sensitive != FALSE); |
---|
3310 | |
---|
3311 | if (sensitive == (GTK_WIDGET_SENSITIVE (widget) != FALSE)) |
---|
3312 | return; |
---|
3313 | |
---|
3314 | if (sensitive) |
---|
3315 | { |
---|
3316 | GTK_WIDGET_SET_FLAGS (widget, GTK_SENSITIVE); |
---|
3317 | data.state = GTK_WIDGET_SAVED_STATE (widget); |
---|
3318 | } |
---|
3319 | else |
---|
3320 | { |
---|
3321 | GTK_WIDGET_UNSET_FLAGS (widget, GTK_SENSITIVE); |
---|
3322 | data.state = GTK_WIDGET_STATE (widget); |
---|
3323 | } |
---|
3324 | data.state_restoration = TRUE; |
---|
3325 | data.use_forall = TRUE; |
---|
3326 | |
---|
3327 | if (widget->parent) |
---|
3328 | data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE); |
---|
3329 | else |
---|
3330 | data.parent_sensitive = TRUE; |
---|
3331 | |
---|
3332 | gtk_widget_propagate_state (widget, &data); |
---|
3333 | if (GTK_WIDGET_DRAWABLE (widget)) |
---|
3334 | gtk_widget_queue_clear (widget); |
---|
3335 | } |
---|
3336 | |
---|
3337 | /***************************************** |
---|
3338 | * gtk_widget_set_parent: |
---|
3339 | * |
---|
3340 | * arguments: |
---|
3341 | * |
---|
3342 | * results: |
---|
3343 | *****************************************/ |
---|
3344 | |
---|
3345 | void |
---|
3346 | gtk_widget_set_parent (GtkWidget *widget, |
---|
3347 | GtkWidget *parent) |
---|
3348 | { |
---|
3349 | GtkStateData data; |
---|
3350 | |
---|
3351 | g_return_if_fail (widget != NULL); |
---|
3352 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
3353 | g_return_if_fail (widget->parent == NULL); |
---|
3354 | g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget)); |
---|
3355 | g_return_if_fail (parent != NULL); |
---|
3356 | g_return_if_fail (GTK_IS_WIDGET (parent)); |
---|
3357 | g_return_if_fail (widget != parent); |
---|
3358 | |
---|
3359 | /* keep this function in sync with gtk_menu_attach_to_widget() |
---|
3360 | */ |
---|
3361 | |
---|
3362 | gtk_widget_ref (widget); |
---|
3363 | gtk_object_sink (GTK_OBJECT (widget)); |
---|
3364 | widget->parent = parent; |
---|
3365 | |
---|
3366 | if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL) |
---|
3367 | data.state = GTK_WIDGET_STATE (parent); |
---|
3368 | else |
---|
3369 | data.state = GTK_WIDGET_STATE (widget); |
---|
3370 | data.state_restoration = FALSE; |
---|
3371 | data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (parent) != FALSE); |
---|
3372 | data.use_forall = GTK_WIDGET_IS_SENSITIVE (parent) != GTK_WIDGET_IS_SENSITIVE (widget); |
---|
3373 | |
---|
3374 | gtk_widget_propagate_state (widget, &data); |
---|
3375 | |
---|
3376 | gtk_widget_set_style_recurse (widget, NULL); |
---|
3377 | |
---|
3378 | gtk_signal_emit (GTK_OBJECT (widget), widget_signals[PARENT_SET], NULL); |
---|
3379 | } |
---|
3380 | |
---|
3381 | /***************************************** |
---|
3382 | * Widget styles |
---|
3383 | * see docs/styles.txt |
---|
3384 | *****************************************/ |
---|
3385 | void |
---|
3386 | gtk_widget_set_style (GtkWidget *widget, |
---|
3387 | GtkStyle *style) |
---|
3388 | { |
---|
3389 | GtkStyle *default_style; |
---|
3390 | gboolean initial_emission; |
---|
3391 | |
---|
3392 | g_return_if_fail (widget != NULL); |
---|
3393 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
3394 | g_return_if_fail (style != NULL); |
---|
3395 | |
---|
3396 | initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget); |
---|
3397 | |
---|
3398 | GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE); |
---|
3399 | GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE); |
---|
3400 | |
---|
3401 | default_style = gtk_object_get_data_by_id (GTK_OBJECT (widget), saved_default_style_key_id); |
---|
3402 | if (!default_style) |
---|
3403 | { |
---|
3404 | gtk_style_ref (widget->style); |
---|
3405 | if (!saved_default_style_key_id) |
---|
3406 | saved_default_style_key_id = g_quark_from_static_string (saved_default_style_key); |
---|
3407 | gtk_object_set_data_by_id (GTK_OBJECT (widget), saved_default_style_key_id, widget->style); |
---|
3408 | } |
---|
3409 | |
---|
3410 | gtk_widget_set_style_internal (widget, style, initial_emission); |
---|
3411 | } |
---|
3412 | |
---|
3413 | void |
---|
3414 | gtk_widget_ensure_style (GtkWidget *widget) |
---|
3415 | { |
---|
3416 | g_return_if_fail (widget != NULL); |
---|
3417 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
3418 | |
---|
3419 | if (!GTK_WIDGET_USER_STYLE (widget) && |
---|
3420 | !GTK_WIDGET_RC_STYLE (widget)) |
---|
3421 | gtk_widget_set_rc_style (widget); |
---|
3422 | } |
---|
3423 | |
---|
3424 | void |
---|
3425 | gtk_widget_set_rc_style (GtkWidget *widget) |
---|
3426 | { |
---|
3427 | GtkStyle *saved_style; |
---|
3428 | GtkStyle *new_style; |
---|
3429 | gboolean initial_emission; |
---|
3430 | |
---|
3431 | g_return_if_fail (widget != NULL); |
---|
3432 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
3433 | |
---|
3434 | initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget); |
---|
3435 | |
---|
3436 | GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE); |
---|
3437 | GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE); |
---|
3438 | |
---|
3439 | saved_style = gtk_object_get_data_by_id (GTK_OBJECT (widget), saved_default_style_key_id); |
---|
3440 | new_style = gtk_rc_get_style (widget); |
---|
3441 | if (new_style) |
---|
3442 | { |
---|
3443 | if (!saved_style) |
---|
3444 | { |
---|
3445 | gtk_style_ref (widget->style); |
---|
3446 | if (!saved_default_style_key_id) |
---|
3447 | saved_default_style_key_id = g_quark_from_static_string (saved_default_style_key); |
---|
3448 | gtk_object_set_data_by_id (GTK_OBJECT (widget), saved_default_style_key_id, widget->style); |
---|
3449 | } |
---|
3450 | gtk_widget_set_style_internal (widget, new_style, initial_emission); |
---|
3451 | } |
---|
3452 | else |
---|
3453 | { |
---|
3454 | if (saved_style) |
---|
3455 | { |
---|
3456 | g_assert (initial_emission == FALSE); /* FIXME: remove this line */ |
---|
3457 | |
---|
3458 | gtk_object_remove_data_by_id (GTK_OBJECT (widget), saved_default_style_key_id); |
---|
3459 | gtk_widget_set_style_internal (widget, saved_style, initial_emission); |
---|
3460 | gtk_style_unref (saved_style); |
---|
3461 | } |
---|
3462 | else |
---|
3463 | { |
---|
3464 | if (initial_emission) |
---|
3465 | gtk_widget_set_style_internal (widget, widget->style, TRUE); |
---|
3466 | } |
---|
3467 | } |
---|
3468 | } |
---|
3469 | |
---|
3470 | void |
---|
3471 | gtk_widget_restore_default_style (GtkWidget *widget) |
---|
3472 | { |
---|
3473 | GtkStyle *default_style; |
---|
3474 | |
---|
3475 | g_return_if_fail (widget != NULL); |
---|
3476 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
3477 | |
---|
3478 | GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE); |
---|
3479 | |
---|
3480 | default_style = gtk_object_get_data_by_id (GTK_OBJECT (widget), saved_default_style_key_id); |
---|
3481 | if (default_style) |
---|
3482 | { |
---|
3483 | gtk_object_remove_data_by_id (GTK_OBJECT (widget), saved_default_style_key_id); |
---|
3484 | gtk_widget_set_style_internal (widget, default_style, FALSE); |
---|
3485 | gtk_style_unref (default_style); |
---|
3486 | } |
---|
3487 | } |
---|
3488 | |
---|
3489 | GtkStyle* |
---|
3490 | gtk_widget_get_style (GtkWidget *widget) |
---|
3491 | { |
---|
3492 | g_return_val_if_fail (widget != NULL, NULL); |
---|
3493 | g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); |
---|
3494 | |
---|
3495 | return widget->style; |
---|
3496 | } |
---|
3497 | |
---|
3498 | void |
---|
3499 | gtk_widget_modify_style (GtkWidget *widget, |
---|
3500 | GtkRcStyle *style) |
---|
3501 | { |
---|
3502 | GtkRcStyle *old_style; |
---|
3503 | |
---|
3504 | if (!rc_style_key_id) |
---|
3505 | rc_style_key_id = g_quark_from_static_string (rc_style_key); |
---|
3506 | |
---|
3507 | old_style = gtk_object_get_data_by_id (GTK_OBJECT (widget), rc_style_key_id); |
---|
3508 | |
---|
3509 | if (style != old_style) |
---|
3510 | { |
---|
3511 | gtk_rc_style_ref (style); |
---|
3512 | |
---|
3513 | gtk_object_set_data_by_id_full (GTK_OBJECT (widget), |
---|
3514 | rc_style_key_id, |
---|
3515 | style, |
---|
3516 | (GtkDestroyNotify)gtk_rc_style_unref); |
---|
3517 | } |
---|
3518 | |
---|
3519 | if (GTK_WIDGET_RC_STYLE (widget)) |
---|
3520 | gtk_widget_set_rc_style (widget); |
---|
3521 | } |
---|
3522 | |
---|
3523 | static void |
---|
3524 | gtk_widget_style_set (GtkWidget *widget, |
---|
3525 | GtkStyle *previous_style) |
---|
3526 | { |
---|
3527 | if (GTK_WIDGET_REALIZED (widget) && |
---|
3528 | !GTK_WIDGET_NO_WINDOW (widget)) |
---|
3529 | gtk_style_set_background (widget->style, widget->window, widget->state); |
---|
3530 | } |
---|
3531 | |
---|
3532 | static void |
---|
3533 | gtk_widget_set_style_internal (GtkWidget *widget, |
---|
3534 | GtkStyle *style, |
---|
3535 | gboolean initial_emission) |
---|
3536 | { |
---|
3537 | g_return_if_fail (widget != NULL); |
---|
3538 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
3539 | g_return_if_fail (style != NULL); |
---|
3540 | |
---|
3541 | if (widget->style != style) |
---|
3542 | { |
---|
3543 | GtkStyle *previous_style; |
---|
3544 | |
---|
3545 | if (GTK_WIDGET_REALIZED (widget)) |
---|
3546 | { |
---|
3547 | gtk_widget_reset_shapes (widget); |
---|
3548 | gtk_style_detach (widget->style); |
---|
3549 | } |
---|
3550 | |
---|
3551 | previous_style = widget->style; |
---|
3552 | widget->style = style; |
---|
3553 | gtk_style_ref (widget->style); |
---|
3554 | |
---|
3555 | if (GTK_WIDGET_REALIZED (widget)) |
---|
3556 | widget->style = gtk_style_attach (widget->style, widget->window); |
---|
3557 | |
---|
3558 | gtk_signal_emit (GTK_OBJECT (widget), |
---|
3559 | widget_signals[STYLE_SET], |
---|
3560 | initial_emission ? NULL : previous_style); |
---|
3561 | gtk_style_unref (previous_style); |
---|
3562 | |
---|
3563 | if (widget->parent && !initial_emission) |
---|
3564 | { |
---|
3565 | GtkRequisition old_requisition; |
---|
3566 | |
---|
3567 | old_requisition = widget->requisition; |
---|
3568 | gtk_widget_size_request (widget, NULL); |
---|
3569 | |
---|
3570 | if ((old_requisition.width != widget->requisition.width) || |
---|
3571 | (old_requisition.height != widget->requisition.height)) |
---|
3572 | gtk_widget_queue_resize (widget); |
---|
3573 | else if (GTK_WIDGET_DRAWABLE (widget)) |
---|
3574 | gtk_widget_queue_clear (widget); |
---|
3575 | } |
---|
3576 | } |
---|
3577 | else if (initial_emission) |
---|
3578 | { |
---|
3579 | gtk_signal_emit (GTK_OBJECT (widget), |
---|
3580 | widget_signals[STYLE_SET], |
---|
3581 | NULL); |
---|
3582 | } |
---|
3583 | } |
---|
3584 | |
---|
3585 | static void |
---|
3586 | gtk_widget_set_style_recurse (GtkWidget *widget, |
---|
3587 | gpointer client_data) |
---|
3588 | { |
---|
3589 | if (GTK_WIDGET_RC_STYLE (widget)) |
---|
3590 | gtk_widget_set_rc_style (widget); |
---|
3591 | |
---|
3592 | if (GTK_IS_CONTAINER (widget)) |
---|
3593 | gtk_container_forall (GTK_CONTAINER (widget), |
---|
3594 | gtk_widget_set_style_recurse, |
---|
3595 | NULL); |
---|
3596 | } |
---|
3597 | |
---|
3598 | void |
---|
3599 | gtk_widget_reset_rc_styles (GtkWidget *widget) |
---|
3600 | { |
---|
3601 | g_return_if_fail (widget != NULL); |
---|
3602 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
3603 | |
---|
3604 | gtk_widget_set_style_recurse (widget, NULL); |
---|
3605 | } |
---|
3606 | |
---|
3607 | void |
---|
3608 | gtk_widget_set_default_style (GtkStyle *style) |
---|
3609 | { |
---|
3610 | if (style != gtk_default_style) |
---|
3611 | { |
---|
3612 | if (gtk_default_style) |
---|
3613 | gtk_style_unref (gtk_default_style); |
---|
3614 | gtk_default_style = style; |
---|
3615 | if (gtk_default_style) |
---|
3616 | gtk_style_ref (gtk_default_style); |
---|
3617 | } |
---|
3618 | } |
---|
3619 | |
---|
3620 | GtkStyle* |
---|
3621 | gtk_widget_get_default_style (void) |
---|
3622 | { |
---|
3623 | if (!gtk_default_style) |
---|
3624 | { |
---|
3625 | gtk_default_style = gtk_style_new (); |
---|
3626 | gtk_style_ref (gtk_default_style); |
---|
3627 | } |
---|
3628 | |
---|
3629 | return gtk_default_style; |
---|
3630 | } |
---|
3631 | |
---|
3632 | void |
---|
3633 | gtk_widget_push_style (GtkStyle *style) |
---|
3634 | { |
---|
3635 | g_return_if_fail (style != NULL); |
---|
3636 | |
---|
3637 | gtk_style_ref (style); |
---|
3638 | style_stack = g_slist_prepend (style_stack, style); |
---|
3639 | } |
---|
3640 | |
---|
3641 | static GtkStyle* |
---|
3642 | gtk_widget_peek_style (void) |
---|
3643 | { |
---|
3644 | if (style_stack) |
---|
3645 | return (GtkStyle*) style_stack->data; |
---|
3646 | else |
---|
3647 | return gtk_widget_get_default_style (); |
---|
3648 | } |
---|
3649 | |
---|
3650 | void |
---|
3651 | gtk_widget_pop_style (void) |
---|
3652 | { |
---|
3653 | GSList *tmp; |
---|
3654 | |
---|
3655 | if (style_stack) |
---|
3656 | { |
---|
3657 | tmp = style_stack; |
---|
3658 | style_stack = style_stack->next; |
---|
3659 | gtk_style_unref ((GtkStyle*) tmp->data); |
---|
3660 | g_slist_free_1 (tmp); |
---|
3661 | } |
---|
3662 | } |
---|
3663 | |
---|
3664 | /************************************************************* |
---|
3665 | * gtk_widget_set_parent_window: |
---|
3666 | * Set a non default parent window for widget |
---|
3667 | * |
---|
3668 | * arguments: |
---|
3669 | * widget: |
---|
3670 | * parent_window |
---|
3671 | * |
---|
3672 | * results: |
---|
3673 | *************************************************************/ |
---|
3674 | |
---|
3675 | void |
---|
3676 | gtk_widget_set_parent_window (GtkWidget *widget, |
---|
3677 | GdkWindow *parent_window) |
---|
3678 | { |
---|
3679 | GdkWindow *old_parent_window; |
---|
3680 | |
---|
3681 | g_return_if_fail (widget != NULL); |
---|
3682 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
3683 | |
---|
3684 | old_parent_window = gtk_object_get_data_by_id (GTK_OBJECT (widget), |
---|
3685 | parent_window_key_id); |
---|
3686 | |
---|
3687 | if (parent_window != old_parent_window) |
---|
3688 | { |
---|
3689 | if (!parent_window_key_id) |
---|
3690 | parent_window_key_id = g_quark_from_static_string (parent_window_key); |
---|
3691 | gtk_object_set_data_by_id (GTK_OBJECT (widget), parent_window_key_id, |
---|
3692 | parent_window); |
---|
3693 | if (old_parent_window) |
---|
3694 | gdk_window_unref (old_parent_window); |
---|
3695 | if (parent_window) |
---|
3696 | gdk_window_ref (parent_window); |
---|
3697 | } |
---|
3698 | } |
---|
3699 | |
---|
3700 | /************************************************************* |
---|
3701 | * gtk_widget_get_parent_window: |
---|
3702 | * Get widget's parent window |
---|
3703 | * |
---|
3704 | * arguments: |
---|
3705 | * widget: |
---|
3706 | * |
---|
3707 | * results: |
---|
3708 | * parent window |
---|
3709 | *************************************************************/ |
---|
3710 | |
---|
3711 | GdkWindow * |
---|
3712 | gtk_widget_get_parent_window (GtkWidget *widget) |
---|
3713 | { |
---|
3714 | GdkWindow *parent_window; |
---|
3715 | |
---|
3716 | g_return_val_if_fail (widget != NULL, NULL); |
---|
3717 | g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); |
---|
3718 | g_return_val_if_fail (widget->parent != NULL, NULL); |
---|
3719 | |
---|
3720 | parent_window = gtk_object_get_data_by_id (GTK_OBJECT (widget), |
---|
3721 | parent_window_key_id); |
---|
3722 | |
---|
3723 | return (parent_window != NULL) ? parent_window : widget->parent->window; |
---|
3724 | } |
---|
3725 | |
---|
3726 | /***************************************** |
---|
3727 | * gtk_widget_set_uposition: |
---|
3728 | * |
---|
3729 | * arguments: |
---|
3730 | * |
---|
3731 | * results: |
---|
3732 | *****************************************/ |
---|
3733 | |
---|
3734 | void |
---|
3735 | gtk_widget_set_uposition (GtkWidget *widget, |
---|
3736 | gint x, |
---|
3737 | gint y) |
---|
3738 | { |
---|
3739 | GtkWidgetAuxInfo *aux_info; |
---|
3740 | |
---|
3741 | g_return_if_fail (widget != NULL); |
---|
3742 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
3743 | |
---|
3744 | aux_info = gtk_object_get_data_by_id (GTK_OBJECT (widget), aux_info_key_id); |
---|
3745 | if (!aux_info) |
---|
3746 | { |
---|
3747 | if (!aux_info_key_id) |
---|
3748 | aux_info_key_id = g_quark_from_static_string (aux_info_key); |
---|
3749 | aux_info = gtk_widget_aux_info_new (); |
---|
3750 | gtk_object_set_data_by_id (GTK_OBJECT (widget), aux_info_key_id, aux_info); |
---|
3751 | } |
---|
3752 | |
---|
3753 | /* keep this in sync with gtk_window_compute_reposition() */ |
---|
3754 | |
---|
3755 | if (x > -2) |
---|
3756 | aux_info->x = x; |
---|
3757 | if (y > -2) |
---|
3758 | aux_info->y = y; |
---|
3759 | |
---|
3760 | if (GTK_IS_WINDOW (widget) && (aux_info->x != -1) && (aux_info->y != -1)) |
---|
3761 | gtk_window_reposition (GTK_WINDOW (widget), x, y); |
---|
3762 | |
---|
3763 | if (GTK_WIDGET_VISIBLE (widget) && widget->parent) |
---|
3764 | gtk_widget_size_allocate (widget, &widget->allocation); |
---|
3765 | } |
---|
3766 | |
---|
3767 | /***************************************** |
---|
3768 | * gtk_widget_set_usize: |
---|
3769 | * |
---|
3770 | * arguments: |
---|
3771 | * |
---|
3772 | * results: |
---|
3773 | *****************************************/ |
---|
3774 | |
---|
3775 | void |
---|
3776 | gtk_widget_set_usize (GtkWidget *widget, |
---|
3777 | gint width, |
---|
3778 | gint height) |
---|
3779 | { |
---|
3780 | GtkWidgetAuxInfo *aux_info; |
---|
3781 | |
---|
3782 | g_return_if_fail (widget != NULL); |
---|
3783 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
3784 | |
---|
3785 | aux_info = gtk_object_get_data_by_id (GTK_OBJECT (widget), aux_info_key_id); |
---|
3786 | if (!aux_info) |
---|
3787 | { |
---|
3788 | if (!aux_info_key_id) |
---|
3789 | aux_info_key_id = g_quark_from_static_string (aux_info_key); |
---|
3790 | aux_info = gtk_widget_aux_info_new (); |
---|
3791 | gtk_object_set_data_by_id (GTK_OBJECT (widget), aux_info_key_id, aux_info); |
---|
3792 | } |
---|
3793 | |
---|
3794 | if (width > -2) |
---|
3795 | aux_info->width = width; |
---|
3796 | if (height > -2) |
---|
3797 | aux_info->height = height; |
---|
3798 | |
---|
3799 | if (GTK_WIDGET_VISIBLE (widget)) |
---|
3800 | gtk_widget_queue_resize (widget); |
---|
3801 | } |
---|
3802 | |
---|
3803 | /***************************************** |
---|
3804 | * gtk_widget_set_events: |
---|
3805 | * |
---|
3806 | * arguments: |
---|
3807 | * |
---|
3808 | * results: |
---|
3809 | *****************************************/ |
---|
3810 | |
---|
3811 | void |
---|
3812 | gtk_widget_set_events (GtkWidget *widget, |
---|
3813 | gint events) |
---|
3814 | { |
---|
3815 | gint *eventp; |
---|
3816 | |
---|
3817 | g_return_if_fail (widget != NULL); |
---|
3818 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
3819 | g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget)); |
---|
3820 | g_return_if_fail (!GTK_WIDGET_REALIZED (widget)); |
---|
3821 | |
---|
3822 | eventp = gtk_object_get_data_by_id (GTK_OBJECT (widget), event_key_id); |
---|
3823 | |
---|
3824 | if (events) |
---|
3825 | { |
---|
3826 | if (!eventp) |
---|
3827 | eventp = g_new (gint, 1); |
---|
3828 | |
---|
3829 | *eventp = events; |
---|
3830 | if (!event_key_id) |
---|
3831 | event_key_id = g_quark_from_static_string (event_key); |
---|
3832 | gtk_object_set_data_by_id (GTK_OBJECT (widget), event_key_id, eventp); |
---|
3833 | } |
---|
3834 | else if (eventp) |
---|
3835 | { |
---|
3836 | g_free (eventp); |
---|
3837 | gtk_object_remove_data_by_id (GTK_OBJECT (widget), event_key_id); |
---|
3838 | } |
---|
3839 | } |
---|
3840 | |
---|
3841 | /***************************************** |
---|
3842 | * gtk_widget_add_events: |
---|
3843 | * |
---|
3844 | * arguments: |
---|
3845 | * |
---|
3846 | * results: |
---|
3847 | *****************************************/ |
---|
3848 | |
---|
3849 | void |
---|
3850 | gtk_widget_add_events (GtkWidget *widget, |
---|
3851 | gint events) |
---|
3852 | { |
---|
3853 | gint *eventp; |
---|
3854 | |
---|
3855 | g_return_if_fail (widget != NULL); |
---|
3856 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
3857 | g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget)); |
---|
3858 | |
---|
3859 | eventp = gtk_object_get_data_by_id (GTK_OBJECT (widget), event_key_id); |
---|
3860 | |
---|
3861 | if (events) |
---|
3862 | { |
---|
3863 | if (!eventp) |
---|
3864 | { |
---|
3865 | eventp = g_new (gint, 1); |
---|
3866 | *eventp = 0; |
---|
3867 | } |
---|
3868 | |
---|
3869 | *eventp |= events; |
---|
3870 | if (!event_key_id) |
---|
3871 | event_key_id = g_quark_from_static_string (event_key); |
---|
3872 | gtk_object_set_data_by_id (GTK_OBJECT (widget), event_key_id, eventp); |
---|
3873 | } |
---|
3874 | else if (eventp) |
---|
3875 | { |
---|
3876 | g_free (eventp); |
---|
3877 | gtk_object_remove_data_by_id (GTK_OBJECT (widget), event_key_id); |
---|
3878 | } |
---|
3879 | |
---|
3880 | if (GTK_WIDGET_REALIZED (widget)) |
---|
3881 | { |
---|
3882 | gdk_window_set_events (widget->window, |
---|
3883 | gdk_window_get_events (widget->window) | events); |
---|
3884 | } |
---|
3885 | } |
---|
3886 | |
---|
3887 | /***************************************** |
---|
3888 | * gtk_widget_set_extension_events: |
---|
3889 | * |
---|
3890 | * arguments: |
---|
3891 | * |
---|
3892 | * results: |
---|
3893 | *****************************************/ |
---|
3894 | |
---|
3895 | void |
---|
3896 | gtk_widget_set_extension_events (GtkWidget *widget, |
---|
3897 | GdkExtensionMode mode) |
---|
3898 | { |
---|
3899 | GdkExtensionMode *modep; |
---|
3900 | |
---|
3901 | g_return_if_fail (widget != NULL); |
---|
3902 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
3903 | |
---|
3904 | modep = gtk_object_get_data_by_id (GTK_OBJECT (widget), extension_event_key_id); |
---|
3905 | |
---|
3906 | if (!modep) |
---|
3907 | modep = g_new (GdkExtensionMode, 1); |
---|
3908 | |
---|
3909 | *modep = mode; |
---|
3910 | if (!extension_event_key_id) |
---|
3911 | extension_event_key_id = g_quark_from_static_string (extension_event_key); |
---|
3912 | gtk_object_set_data_by_id (GTK_OBJECT (widget), extension_event_key_id, modep); |
---|
3913 | } |
---|
3914 | |
---|
3915 | /***************************************** |
---|
3916 | * gtk_widget_get_toplevel: |
---|
3917 | * |
---|
3918 | * arguments: |
---|
3919 | * |
---|
3920 | * results: |
---|
3921 | *****************************************/ |
---|
3922 | |
---|
3923 | GtkWidget* |
---|
3924 | gtk_widget_get_toplevel (GtkWidget *widget) |
---|
3925 | { |
---|
3926 | g_return_val_if_fail (widget != NULL, NULL); |
---|
3927 | g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); |
---|
3928 | |
---|
3929 | while (widget->parent) |
---|
3930 | widget = widget->parent; |
---|
3931 | |
---|
3932 | return widget; |
---|
3933 | } |
---|
3934 | |
---|
3935 | /***************************************** |
---|
3936 | * gtk_widget_get_ancestor: |
---|
3937 | * |
---|
3938 | * arguments: |
---|
3939 | * |
---|
3940 | * results: |
---|
3941 | *****************************************/ |
---|
3942 | |
---|
3943 | GtkWidget* |
---|
3944 | gtk_widget_get_ancestor (GtkWidget *widget, |
---|
3945 | GtkType widget_type) |
---|
3946 | { |
---|
3947 | g_return_val_if_fail (widget != NULL, NULL); |
---|
3948 | g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); |
---|
3949 | |
---|
3950 | while (widget && !gtk_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)) |
---|
3951 | widget = widget->parent; |
---|
3952 | |
---|
3953 | if (!(widget && gtk_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))) |
---|
3954 | return NULL; |
---|
3955 | |
---|
3956 | return widget; |
---|
3957 | } |
---|
3958 | |
---|
3959 | /***************************************** |
---|
3960 | * gtk_widget_get_colormap: |
---|
3961 | * |
---|
3962 | * arguments: |
---|
3963 | * |
---|
3964 | * results: |
---|
3965 | *****************************************/ |
---|
3966 | |
---|
3967 | GdkColormap* |
---|
3968 | gtk_widget_get_colormap (GtkWidget *widget) |
---|
3969 | { |
---|
3970 | GdkColormap *colormap; |
---|
3971 | |
---|
3972 | g_return_val_if_fail (widget != NULL, NULL); |
---|
3973 | g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); |
---|
3974 | |
---|
3975 | if (widget->window) |
---|
3976 | { |
---|
3977 | colormap = gdk_window_get_colormap (widget->window); |
---|
3978 | /* If window was destroyed previously, we'll get NULL here */ |
---|
3979 | if (colormap) |
---|
3980 | return colormap; |
---|
3981 | } |
---|
3982 | |
---|
3983 | colormap = gtk_object_get_data (GTK_OBJECT (widget), colormap_key); |
---|
3984 | if (colormap) |
---|
3985 | return colormap; |
---|
3986 | |
---|
3987 | return gtk_widget_get_default_colormap (); |
---|
3988 | } |
---|
3989 | |
---|
3990 | /***************************************** |
---|
3991 | * gtk_widget_get_visual: |
---|
3992 | * |
---|
3993 | * arguments: |
---|
3994 | * |
---|
3995 | * results: |
---|
3996 | *****************************************/ |
---|
3997 | |
---|
3998 | GdkVisual* |
---|
3999 | gtk_widget_get_visual (GtkWidget *widget) |
---|
4000 | { |
---|
4001 | GdkVisual *visual; |
---|
4002 | |
---|
4003 | g_return_val_if_fail (widget != NULL, NULL); |
---|
4004 | g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); |
---|
4005 | |
---|
4006 | if (widget->window) |
---|
4007 | { |
---|
4008 | visual = gdk_window_get_visual (widget->window); |
---|
4009 | /* If window was destroyed previously, we'll get NULL here */ |
---|
4010 | if (visual) |
---|
4011 | return visual; |
---|
4012 | } |
---|
4013 | |
---|
4014 | visual = gtk_object_get_data (GTK_OBJECT (widget), visual_key); |
---|
4015 | if (visual) |
---|
4016 | return visual; |
---|
4017 | |
---|
4018 | return gtk_widget_get_default_visual (); |
---|
4019 | } |
---|
4020 | |
---|
4021 | /***************************************** |
---|
4022 | * gtk_widget_set_colormap: |
---|
4023 | * Set the colormap for the widget to the given |
---|
4024 | * value. Widget must not have been previously |
---|
4025 | * realized. This probably should only be used |
---|
4026 | * from an init() function. |
---|
4027 | * arguments: |
---|
4028 | * widget: |
---|
4029 | * colormap: |
---|
4030 | * results: |
---|
4031 | *****************************************/ |
---|
4032 | |
---|
4033 | void |
---|
4034 | gtk_widget_set_colormap (GtkWidget *widget, GdkColormap *colormap) |
---|
4035 | { |
---|
4036 | g_return_if_fail (widget != NULL); |
---|
4037 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
4038 | g_return_if_fail (!GTK_WIDGET_REALIZED (widget)); |
---|
4039 | g_return_if_fail (colormap != NULL); |
---|
4040 | |
---|
4041 | /* FIXME: reference count the colormap. |
---|
4042 | */ |
---|
4043 | |
---|
4044 | gtk_object_set_data (GTK_OBJECT (widget), |
---|
4045 | colormap_key, |
---|
4046 | colormap); |
---|
4047 | } |
---|
4048 | |
---|
4049 | /***************************************** |
---|
4050 | * gtk_widget_set_visual: |
---|
4051 | * Set the colormap for the widget to the given |
---|
4052 | * value. Widget must not have been previously |
---|
4053 | * realized. This probably should only be used |
---|
4054 | * from an init() function. |
---|
4055 | * arguments: |
---|
4056 | * widget: |
---|
4057 | * visual: |
---|
4058 | * results: |
---|
4059 | *****************************************/ |
---|
4060 | |
---|
4061 | void |
---|
4062 | gtk_widget_set_visual (GtkWidget *widget, GdkVisual *visual) |
---|
4063 | { |
---|
4064 | g_return_if_fail (widget != NULL); |
---|
4065 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
4066 | g_return_if_fail (!GTK_WIDGET_REALIZED (widget)); |
---|
4067 | g_return_if_fail (visual != NULL); |
---|
4068 | |
---|
4069 | gtk_object_set_data (GTK_OBJECT (widget), |
---|
4070 | visual_key, |
---|
4071 | visual); |
---|
4072 | } |
---|
4073 | |
---|
4074 | /***************************************** |
---|
4075 | * gtk_widget_get_events: |
---|
4076 | * |
---|
4077 | * arguments: |
---|
4078 | * |
---|
4079 | * results: |
---|
4080 | *****************************************/ |
---|
4081 | |
---|
4082 | gint |
---|
4083 | gtk_widget_get_events (GtkWidget *widget) |
---|
4084 | { |
---|
4085 | gint *events; |
---|
4086 | |
---|
4087 | g_return_val_if_fail (widget != NULL, 0); |
---|
4088 | g_return_val_if_fail (GTK_IS_WIDGET (widget), 0); |
---|
4089 | |
---|
4090 | events = gtk_object_get_data_by_id (GTK_OBJECT (widget), event_key_id); |
---|
4091 | if (events) |
---|
4092 | return *events; |
---|
4093 | |
---|
4094 | return 0; |
---|
4095 | } |
---|
4096 | |
---|
4097 | /***************************************** |
---|
4098 | * gtk_widget_get_extension_events: |
---|
4099 | * |
---|
4100 | * arguments: |
---|
4101 | * |
---|
4102 | * results: |
---|
4103 | *****************************************/ |
---|
4104 | |
---|
4105 | GdkExtensionMode |
---|
4106 | gtk_widget_get_extension_events (GtkWidget *widget) |
---|
4107 | { |
---|
4108 | GdkExtensionMode *mode; |
---|
4109 | |
---|
4110 | g_return_val_if_fail (widget != NULL, 0); |
---|
4111 | g_return_val_if_fail (GTK_IS_WIDGET (widget), 0); |
---|
4112 | |
---|
4113 | mode = gtk_object_get_data_by_id (GTK_OBJECT (widget), extension_event_key_id); |
---|
4114 | if (mode) |
---|
4115 | return *mode; |
---|
4116 | |
---|
4117 | return 0; |
---|
4118 | } |
---|
4119 | |
---|
4120 | /***************************************** |
---|
4121 | * gtk_widget_get_pointer: |
---|
4122 | * |
---|
4123 | * arguments: |
---|
4124 | * |
---|
4125 | * results: |
---|
4126 | *****************************************/ |
---|
4127 | |
---|
4128 | void |
---|
4129 | gtk_widget_get_pointer (GtkWidget *widget, |
---|
4130 | gint *x, |
---|
4131 | gint *y) |
---|
4132 | { |
---|
4133 | g_return_if_fail (widget != NULL); |
---|
4134 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
4135 | |
---|
4136 | if (x) |
---|
4137 | *x = -1; |
---|
4138 | if (y) |
---|
4139 | *y = -1; |
---|
4140 | |
---|
4141 | if (GTK_WIDGET_REALIZED (widget)) |
---|
4142 | { |
---|
4143 | gdk_window_get_pointer (widget->window, x, y, NULL); |
---|
4144 | |
---|
4145 | if (GTK_WIDGET_NO_WINDOW (widget)) |
---|
4146 | { |
---|
4147 | if (x) |
---|
4148 | *x -= widget->allocation.x; |
---|
4149 | if (y) |
---|
4150 | *y -= widget->allocation.y; |
---|
4151 | } |
---|
4152 | } |
---|
4153 | } |
---|
4154 | |
---|
4155 | /***************************************** |
---|
4156 | * gtk_widget_is_ancestor: |
---|
4157 | * |
---|
4158 | * arguments: |
---|
4159 | * |
---|
4160 | * results: |
---|
4161 | *****************************************/ |
---|
4162 | |
---|
4163 | gint |
---|
4164 | gtk_widget_is_ancestor (GtkWidget *widget, |
---|
4165 | GtkWidget *ancestor) |
---|
4166 | { |
---|
4167 | g_return_val_if_fail (widget != NULL, FALSE); |
---|
4168 | g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); |
---|
4169 | g_return_val_if_fail (ancestor != NULL, FALSE); |
---|
4170 | |
---|
4171 | while (widget) |
---|
4172 | { |
---|
4173 | if (widget->parent == ancestor) |
---|
4174 | return TRUE; |
---|
4175 | widget = widget->parent; |
---|
4176 | } |
---|
4177 | |
---|
4178 | return FALSE; |
---|
4179 | } |
---|
4180 | |
---|
4181 | static GQuark quark_composite_name = 0; |
---|
4182 | |
---|
4183 | void |
---|
4184 | gtk_widget_set_composite_name (GtkWidget *widget, |
---|
4185 | const gchar *name) |
---|
4186 | { |
---|
4187 | g_return_if_fail (widget != NULL); |
---|
4188 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
4189 | g_return_if_fail (GTK_WIDGET_COMPOSITE_CHILD (widget)); |
---|
4190 | g_return_if_fail (name != NULL); |
---|
4191 | |
---|
4192 | if (!quark_composite_name) |
---|
4193 | quark_composite_name = g_quark_from_static_string ("gtk-composite-name"); |
---|
4194 | |
---|
4195 | gtk_object_set_data_by_id_full (GTK_OBJECT (widget), |
---|
4196 | quark_composite_name, |
---|
4197 | g_strdup (name), |
---|
4198 | g_free); |
---|
4199 | } |
---|
4200 | |
---|
4201 | gchar* |
---|
4202 | gtk_widget_get_composite_name (GtkWidget *widget) |
---|
4203 | { |
---|
4204 | g_return_val_if_fail (widget != NULL, NULL); |
---|
4205 | g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); |
---|
4206 | |
---|
4207 | if (GTK_WIDGET_COMPOSITE_CHILD (widget) && widget->parent) |
---|
4208 | return gtk_container_child_composite_name (GTK_CONTAINER (widget->parent), |
---|
4209 | widget); |
---|
4210 | else |
---|
4211 | return NULL; |
---|
4212 | } |
---|
4213 | |
---|
4214 | void |
---|
4215 | gtk_widget_push_composite_child (void) |
---|
4216 | { |
---|
4217 | composite_child_stack++; |
---|
4218 | } |
---|
4219 | |
---|
4220 | void |
---|
4221 | gtk_widget_pop_composite_child (void) |
---|
4222 | { |
---|
4223 | if (composite_child_stack) |
---|
4224 | composite_child_stack--; |
---|
4225 | } |
---|
4226 | |
---|
4227 | /***************************************** |
---|
4228 | * gtk_widget_push_colormap: |
---|
4229 | * |
---|
4230 | * arguments: |
---|
4231 | * |
---|
4232 | * results: |
---|
4233 | *****************************************/ |
---|
4234 | |
---|
4235 | void |
---|
4236 | gtk_widget_push_colormap (GdkColormap *cmap) |
---|
4237 | { |
---|
4238 | g_return_if_fail (cmap != NULL); |
---|
4239 | |
---|
4240 | colormap_stack = g_slist_prepend (colormap_stack, cmap); |
---|
4241 | } |
---|
4242 | |
---|
4243 | /***************************************** |
---|
4244 | * gtk_widget_push_visual: |
---|
4245 | * |
---|
4246 | * arguments: |
---|
4247 | * |
---|
4248 | * results: |
---|
4249 | *****************************************/ |
---|
4250 | |
---|
4251 | void |
---|
4252 | gtk_widget_push_visual (GdkVisual *visual) |
---|
4253 | { |
---|
4254 | g_return_if_fail (visual != NULL); |
---|
4255 | |
---|
4256 | visual_stack = g_slist_prepend (visual_stack, visual); |
---|
4257 | } |
---|
4258 | |
---|
4259 | /***************************************** |
---|
4260 | * gtk_widget_pop_colormap: |
---|
4261 | * |
---|
4262 | * arguments: |
---|
4263 | * |
---|
4264 | * results: |
---|
4265 | *****************************************/ |
---|
4266 | |
---|
4267 | void |
---|
4268 | gtk_widget_pop_colormap (void) |
---|
4269 | { |
---|
4270 | GSList *tmp; |
---|
4271 | |
---|
4272 | if (colormap_stack) |
---|
4273 | { |
---|
4274 | tmp = colormap_stack; |
---|
4275 | colormap_stack = colormap_stack->next; |
---|
4276 | g_slist_free_1 (tmp); |
---|
4277 | } |
---|
4278 | } |
---|
4279 | |
---|
4280 | /***************************************** |
---|
4281 | * gtk_widget_pop_visual: |
---|
4282 | * |
---|
4283 | * arguments: |
---|
4284 | * |
---|
4285 | * results: |
---|
4286 | *****************************************/ |
---|
4287 | |
---|
4288 | void |
---|
4289 | gtk_widget_pop_visual (void) |
---|
4290 | { |
---|
4291 | GSList *tmp; |
---|
4292 | |
---|
4293 | if (visual_stack) |
---|
4294 | { |
---|
4295 | tmp = visual_stack; |
---|
4296 | visual_stack = visual_stack->next; |
---|
4297 | g_slist_free_1 (tmp); |
---|
4298 | } |
---|
4299 | } |
---|
4300 | |
---|
4301 | /***************************************** |
---|
4302 | * gtk_widget_set_default_colormap: |
---|
4303 | * |
---|
4304 | * arguments: |
---|
4305 | * |
---|
4306 | * results: |
---|
4307 | *****************************************/ |
---|
4308 | |
---|
4309 | void |
---|
4310 | gtk_widget_set_default_colormap (GdkColormap *colormap) |
---|
4311 | { |
---|
4312 | if (default_colormap != colormap) |
---|
4313 | { |
---|
4314 | if (default_colormap) |
---|
4315 | gdk_colormap_unref (default_colormap); |
---|
4316 | default_colormap = colormap; |
---|
4317 | if (default_colormap) |
---|
4318 | gdk_colormap_ref (default_colormap); |
---|
4319 | } |
---|
4320 | } |
---|
4321 | |
---|
4322 | /***************************************** |
---|
4323 | * gtk_widget_set_default_visual: |
---|
4324 | * |
---|
4325 | * arguments: |
---|
4326 | * |
---|
4327 | * results: |
---|
4328 | *****************************************/ |
---|
4329 | |
---|
4330 | void |
---|
4331 | gtk_widget_set_default_visual (GdkVisual *visual) |
---|
4332 | { |
---|
4333 | default_visual = visual; |
---|
4334 | } |
---|
4335 | |
---|
4336 | /***************************************** |
---|
4337 | * gtk_widget_get_default_colormap: |
---|
4338 | * |
---|
4339 | * arguments: |
---|
4340 | * |
---|
4341 | * results: |
---|
4342 | *****************************************/ |
---|
4343 | |
---|
4344 | GdkColormap* |
---|
4345 | gtk_widget_get_default_colormap (void) |
---|
4346 | { |
---|
4347 | if (!default_colormap) |
---|
4348 | default_colormap = gdk_colormap_get_system (); |
---|
4349 | |
---|
4350 | return default_colormap; |
---|
4351 | } |
---|
4352 | |
---|
4353 | /***************************************** |
---|
4354 | * gtk_widget_get_default_visual: |
---|
4355 | * |
---|
4356 | * arguments: |
---|
4357 | * |
---|
4358 | * results: |
---|
4359 | *****************************************/ |
---|
4360 | |
---|
4361 | GdkVisual* |
---|
4362 | gtk_widget_get_default_visual (void) |
---|
4363 | { |
---|
4364 | if (!default_visual) |
---|
4365 | default_visual = gdk_visual_get_system (); |
---|
4366 | |
---|
4367 | return default_visual; |
---|
4368 | } |
---|
4369 | |
---|
4370 | static void |
---|
4371 | gtk_widget_shutdown (GtkObject *object) |
---|
4372 | { |
---|
4373 | GtkWidget *widget; |
---|
4374 | |
---|
4375 | /* gtk_object_destroy() will already hold a refcount on object |
---|
4376 | */ |
---|
4377 | widget = GTK_WIDGET (object); |
---|
4378 | |
---|
4379 | if (widget->parent) |
---|
4380 | gtk_container_remove (GTK_CONTAINER (widget->parent), widget); |
---|
4381 | |
---|
4382 | GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE); |
---|
4383 | if (GTK_WIDGET_REALIZED (widget)) |
---|
4384 | gtk_widget_unrealize (widget); |
---|
4385 | |
---|
4386 | parent_class->shutdown (object); |
---|
4387 | } |
---|
4388 | |
---|
4389 | static void |
---|
4390 | gtk_widget_real_destroy (GtkObject *object) |
---|
4391 | { |
---|
4392 | GtkWidget *widget; |
---|
4393 | GtkStyle *saved_style; |
---|
4394 | |
---|
4395 | /* gtk_object_destroy() will already hold a refcount on object |
---|
4396 | */ |
---|
4397 | widget = GTK_WIDGET (object); |
---|
4398 | |
---|
4399 | gtk_grab_remove (widget); |
---|
4400 | gtk_selection_remove_all (widget); |
---|
4401 | |
---|
4402 | saved_style = gtk_object_get_data_by_id (object, saved_default_style_key_id); |
---|
4403 | if (saved_style) |
---|
4404 | { |
---|
4405 | gtk_style_unref (saved_style); |
---|
4406 | gtk_object_remove_data_by_id (object, saved_default_style_key_id); |
---|
4407 | } |
---|
4408 | |
---|
4409 | gtk_style_unref (widget->style); |
---|
4410 | widget->style = NULL; |
---|
4411 | |
---|
4412 | parent_class->destroy (object); |
---|
4413 | } |
---|
4414 | |
---|
4415 | static void |
---|
4416 | gtk_widget_finalize (GtkObject *object) |
---|
4417 | { |
---|
4418 | GtkWidget *widget; |
---|
4419 | GtkWidgetAuxInfo *aux_info; |
---|
4420 | gint *events; |
---|
4421 | GdkExtensionMode *mode; |
---|
4422 | |
---|
4423 | widget = GTK_WIDGET (object); |
---|
4424 | |
---|
4425 | if (widget->name) |
---|
4426 | g_free (widget->name); |
---|
4427 | |
---|
4428 | aux_info = gtk_object_get_data_by_id (GTK_OBJECT (widget), aux_info_key_id); |
---|
4429 | if (aux_info) |
---|
4430 | gtk_widget_aux_info_destroy (aux_info); |
---|
4431 | |
---|
4432 | events = gtk_object_get_data_by_id (GTK_OBJECT (widget), event_key_id); |
---|
4433 | if (events) |
---|
4434 | g_free (events); |
---|
4435 | |
---|
4436 | mode = gtk_object_get_data_by_id (GTK_OBJECT (widget), extension_event_key_id); |
---|
4437 | if (mode) |
---|
4438 | g_free (mode); |
---|
4439 | |
---|
4440 | parent_class->finalize (object); |
---|
4441 | } |
---|
4442 | |
---|
4443 | /***************************************** |
---|
4444 | * gtk_widget_real_map: |
---|
4445 | * |
---|
4446 | * arguments: |
---|
4447 | * |
---|
4448 | * results: |
---|
4449 | *****************************************/ |
---|
4450 | |
---|
4451 | static void |
---|
4452 | gtk_widget_real_map (GtkWidget *widget) |
---|
4453 | { |
---|
4454 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
4455 | g_return_if_fail (GTK_WIDGET_REALIZED (widget) == TRUE); |
---|
4456 | |
---|
4457 | if (!GTK_WIDGET_MAPPED (widget)) |
---|
4458 | { |
---|
4459 | GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED); |
---|
4460 | |
---|
4461 | if (!GTK_WIDGET_NO_WINDOW (widget)) |
---|
4462 | gdk_window_show (widget->window); |
---|
4463 | } |
---|
4464 | } |
---|
4465 | |
---|
4466 | /***************************************** |
---|
4467 | * gtk_widget_real_unmap: |
---|
4468 | * |
---|
4469 | * arguments: |
---|
4470 | * |
---|
4471 | * results: |
---|
4472 | *****************************************/ |
---|
4473 | |
---|
4474 | static void |
---|
4475 | gtk_widget_real_unmap (GtkWidget *widget) |
---|
4476 | { |
---|
4477 | g_return_if_fail (widget != NULL); |
---|
4478 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
4479 | |
---|
4480 | if (GTK_WIDGET_MAPPED (widget)) |
---|
4481 | { |
---|
4482 | GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED); |
---|
4483 | |
---|
4484 | if (!GTK_WIDGET_NO_WINDOW (widget)) |
---|
4485 | gdk_window_hide (widget->window); |
---|
4486 | } |
---|
4487 | } |
---|
4488 | |
---|
4489 | /***************************************** |
---|
4490 | * gtk_widget_real_realize: |
---|
4491 | * |
---|
4492 | * arguments: |
---|
4493 | * |
---|
4494 | * results: |
---|
4495 | *****************************************/ |
---|
4496 | |
---|
4497 | static void |
---|
4498 | gtk_widget_real_realize (GtkWidget *widget) |
---|
4499 | { |
---|
4500 | g_return_if_fail (widget != NULL); |
---|
4501 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
4502 | g_return_if_fail (GTK_WIDGET_NO_WINDOW (widget)); |
---|
4503 | |
---|
4504 | GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); |
---|
4505 | if (widget->parent) |
---|
4506 | { |
---|
4507 | widget->window = gtk_widget_get_parent_window (widget); |
---|
4508 | gdk_window_ref (widget->window); |
---|
4509 | } |
---|
4510 | widget->style = gtk_style_attach (widget->style, widget->window); |
---|
4511 | } |
---|
4512 | |
---|
4513 | /***************************************** |
---|
4514 | * gtk_widget_real_unrealize: |
---|
4515 | * |
---|
4516 | * arguments: |
---|
4517 | * |
---|
4518 | * results: |
---|
4519 | *****************************************/ |
---|
4520 | |
---|
4521 | static void |
---|
4522 | gtk_widget_real_unrealize (GtkWidget *widget) |
---|
4523 | { |
---|
4524 | g_return_if_fail (widget != NULL); |
---|
4525 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
4526 | |
---|
4527 | if (GTK_WIDGET_MAPPED (widget)) |
---|
4528 | gtk_widget_real_unmap (widget); |
---|
4529 | |
---|
4530 | GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED); |
---|
4531 | |
---|
4532 | /* printf ("unrealizing %s\n", gtk_type_name (GTK_OBJECT (widget)->klass->type)); |
---|
4533 | */ |
---|
4534 | |
---|
4535 | /* We must do unrealize child widget BEFORE container widget. |
---|
4536 | * gdk_window_destroy() destroys specified xwindow and its sub-xwindows. |
---|
4537 | * So, unrealizing container widget bofore its children causes the problem |
---|
4538 | * (for example, gdk_ic_destroy () with destroyed window causes crash. ) |
---|
4539 | */ |
---|
4540 | |
---|
4541 | if (GTK_IS_CONTAINER (widget)) |
---|
4542 | gtk_container_forall (GTK_CONTAINER (widget), |
---|
4543 | (GtkCallback) gtk_widget_unrealize, |
---|
4544 | NULL); |
---|
4545 | |
---|
4546 | gtk_style_detach (widget->style); |
---|
4547 | if (!GTK_WIDGET_NO_WINDOW (widget)) |
---|
4548 | { |
---|
4549 | gdk_window_set_user_data (widget->window, NULL); |
---|
4550 | gdk_window_destroy (widget->window); |
---|
4551 | widget->window = NULL; |
---|
4552 | } |
---|
4553 | else |
---|
4554 | { |
---|
4555 | gdk_window_unref (widget->window); |
---|
4556 | widget->window = NULL; |
---|
4557 | } |
---|
4558 | |
---|
4559 | GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED); |
---|
4560 | } |
---|
4561 | |
---|
4562 | static void |
---|
4563 | gtk_widget_real_draw (GtkWidget *widget, |
---|
4564 | GdkRectangle *area) |
---|
4565 | { |
---|
4566 | GdkEventExpose event; |
---|
4567 | |
---|
4568 | g_return_if_fail (widget != NULL); |
---|
4569 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
4570 | g_return_if_fail (area != NULL); |
---|
4571 | |
---|
4572 | if (GTK_WIDGET_DRAWABLE (widget)) |
---|
4573 | { |
---|
4574 | event.type = GDK_EXPOSE; |
---|
4575 | event.send_event = TRUE; |
---|
4576 | event.window = widget->window; |
---|
4577 | event.area = *area; |
---|
4578 | event.count = 0; |
---|
4579 | |
---|
4580 | gdk_window_ref (event.window); |
---|
4581 | gtk_widget_event (widget, (GdkEvent*) &event); |
---|
4582 | gdk_window_unref (event.window); |
---|
4583 | } |
---|
4584 | } |
---|
4585 | |
---|
4586 | static void |
---|
4587 | gtk_widget_real_size_request (GtkWidget *widget, |
---|
4588 | GtkRequisition *requisition) |
---|
4589 | { |
---|
4590 | g_return_if_fail (widget != NULL); |
---|
4591 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
4592 | |
---|
4593 | requisition->width = widget->requisition.width; |
---|
4594 | requisition->height = widget->requisition.height; |
---|
4595 | } |
---|
4596 | |
---|
4597 | /***************************************** |
---|
4598 | * gtk_widget_peek_colormap: |
---|
4599 | * |
---|
4600 | * arguments: |
---|
4601 | * |
---|
4602 | * results: |
---|
4603 | *****************************************/ |
---|
4604 | |
---|
4605 | static GdkColormap* |
---|
4606 | gtk_widget_peek_colormap (void) |
---|
4607 | { |
---|
4608 | if (colormap_stack) |
---|
4609 | return (GdkColormap*) colormap_stack->data; |
---|
4610 | return gtk_widget_get_default_colormap (); |
---|
4611 | } |
---|
4612 | |
---|
4613 | /***************************************** |
---|
4614 | * gtk_widget_peek_visual: |
---|
4615 | * |
---|
4616 | * arguments: |
---|
4617 | * |
---|
4618 | * results: |
---|
4619 | *****************************************/ |
---|
4620 | |
---|
4621 | static GdkVisual* |
---|
4622 | gtk_widget_peek_visual (void) |
---|
4623 | { |
---|
4624 | if (visual_stack) |
---|
4625 | return (GdkVisual*) visual_stack->data; |
---|
4626 | return gtk_widget_get_default_visual (); |
---|
4627 | } |
---|
4628 | |
---|
4629 | static void |
---|
4630 | gtk_widget_propagate_state (GtkWidget *widget, |
---|
4631 | GtkStateData *data) |
---|
4632 | { |
---|
4633 | guint8 old_state; |
---|
4634 | |
---|
4635 | /* don't call this function with state==GTK_STATE_INSENSITIVE, |
---|
4636 | * parent_sensitive==TRUE on a sensitive widget |
---|
4637 | */ |
---|
4638 | |
---|
4639 | old_state = GTK_WIDGET_STATE (widget); |
---|
4640 | |
---|
4641 | if (data->parent_sensitive) |
---|
4642 | { |
---|
4643 | GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE); |
---|
4644 | |
---|
4645 | if (GTK_WIDGET_IS_SENSITIVE (widget)) |
---|
4646 | { |
---|
4647 | if (data->state_restoration) |
---|
4648 | GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget); |
---|
4649 | else |
---|
4650 | GTK_WIDGET_STATE (widget) = data->state; |
---|
4651 | } |
---|
4652 | else |
---|
4653 | { |
---|
4654 | GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE; |
---|
4655 | if (!data->state_restoration && |
---|
4656 | data->state != GTK_STATE_INSENSITIVE) |
---|
4657 | GTK_WIDGET_SAVED_STATE (widget) = data->state; |
---|
4658 | } |
---|
4659 | } |
---|
4660 | else |
---|
4661 | { |
---|
4662 | GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE); |
---|
4663 | if (!data->state_restoration) |
---|
4664 | { |
---|
4665 | if (data->state != GTK_STATE_INSENSITIVE) |
---|
4666 | GTK_WIDGET_SAVED_STATE (widget) = data->state; |
---|
4667 | } |
---|
4668 | else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE) |
---|
4669 | GTK_WIDGET_SAVED_STATE (widget) = GTK_WIDGET_STATE (widget); |
---|
4670 | GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE; |
---|
4671 | } |
---|
4672 | |
---|
4673 | if (GTK_WIDGET_HAS_FOCUS (widget) && !GTK_WIDGET_IS_SENSITIVE (widget)) |
---|
4674 | { |
---|
4675 | GtkWidget *window; |
---|
4676 | |
---|
4677 | window = gtk_widget_get_ancestor (widget, gtk_window_get_type ()); |
---|
4678 | if (window) |
---|
4679 | gtk_window_set_focus (GTK_WINDOW (window), NULL); |
---|
4680 | } |
---|
4681 | |
---|
4682 | if (old_state != GTK_WIDGET_STATE (widget)) |
---|
4683 | { |
---|
4684 | gtk_widget_ref (widget); |
---|
4685 | gtk_signal_emit (GTK_OBJECT (widget), widget_signals[STATE_CHANGED], old_state); |
---|
4686 | |
---|
4687 | if (GTK_IS_CONTAINER (widget)) |
---|
4688 | { |
---|
4689 | data->parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget) != FALSE); |
---|
4690 | data->state = GTK_WIDGET_STATE (widget); |
---|
4691 | if (data->use_forall) |
---|
4692 | gtk_container_forall (GTK_CONTAINER (widget), |
---|
4693 | (GtkCallback) gtk_widget_propagate_state, |
---|
4694 | data); |
---|
4695 | else |
---|
4696 | gtk_container_foreach (GTK_CONTAINER (widget), |
---|
4697 | (GtkCallback) gtk_widget_propagate_state, |
---|
4698 | data); |
---|
4699 | } |
---|
4700 | gtk_widget_unref (widget); |
---|
4701 | } |
---|
4702 | } |
---|
4703 | |
---|
4704 | /************************************************************* |
---|
4705 | * gtk_widget_is_offscreen: |
---|
4706 | * Check if a widget is "offscreen" |
---|
4707 | * arguments: |
---|
4708 | * widget: a widget |
---|
4709 | * results: |
---|
4710 | * TRUE if the widget or any of ancestors has the |
---|
4711 | * PRIVATE_GTK_WIDGET_IS_OFFSCREEN set. |
---|
4712 | *************************************************************/ |
---|
4713 | |
---|
4714 | static gboolean |
---|
4715 | gtk_widget_is_offscreen (GtkWidget *widget) |
---|
4716 | { |
---|
4717 | while (widget) |
---|
4718 | { |
---|
4719 | if (GTK_WIDGET_IS_OFFSCREEN (widget)) |
---|
4720 | return TRUE; |
---|
4721 | widget = widget->parent; |
---|
4722 | } |
---|
4723 | |
---|
4724 | return FALSE; |
---|
4725 | } |
---|
4726 | |
---|
4727 | /***************************************** |
---|
4728 | * gtk_widget_aux_info_new: |
---|
4729 | * |
---|
4730 | * arguments: |
---|
4731 | * |
---|
4732 | * results: |
---|
4733 | *****************************************/ |
---|
4734 | |
---|
4735 | static GtkWidgetAuxInfo* |
---|
4736 | gtk_widget_aux_info_new (void) |
---|
4737 | { |
---|
4738 | GtkWidgetAuxInfo *aux_info; |
---|
4739 | |
---|
4740 | if (!aux_info_mem_chunk) |
---|
4741 | aux_info_mem_chunk = g_mem_chunk_new ("widget aux info mem chunk", |
---|
4742 | sizeof (GtkWidgetAuxInfo), |
---|
4743 | 1024, G_ALLOC_AND_FREE); |
---|
4744 | |
---|
4745 | aux_info = g_chunk_new (GtkWidgetAuxInfo, aux_info_mem_chunk); |
---|
4746 | |
---|
4747 | aux_info->x = -1; |
---|
4748 | aux_info->y = -1; |
---|
4749 | aux_info->width = 0; |
---|
4750 | aux_info->height = 0; |
---|
4751 | |
---|
4752 | return aux_info; |
---|
4753 | } |
---|
4754 | |
---|
4755 | /***************************************** |
---|
4756 | * gtk_widget_aux_info_destroy: |
---|
4757 | * |
---|
4758 | * arguments: |
---|
4759 | * |
---|
4760 | * results: |
---|
4761 | *****************************************/ |
---|
4762 | |
---|
4763 | static void |
---|
4764 | gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info) |
---|
4765 | { |
---|
4766 | g_return_if_fail (aux_info != NULL); |
---|
4767 | |
---|
4768 | g_mem_chunk_free (aux_info_mem_chunk, aux_info); |
---|
4769 | } |
---|
4770 | |
---|
4771 | /***************************************** |
---|
4772 | * gtk_widget_shape_combine_mask: |
---|
4773 | * set a shape for this widgets' gdk window, this allows for |
---|
4774 | * transparent windows etc., see gdk_window_shape_combine_mask |
---|
4775 | * for more information |
---|
4776 | * |
---|
4777 | * arguments: |
---|
4778 | * |
---|
4779 | * results: |
---|
4780 | *****************************************/ |
---|
4781 | void |
---|
4782 | gtk_widget_shape_combine_mask (GtkWidget *widget, |
---|
4783 | GdkBitmap *shape_mask, |
---|
4784 | gint offset_x, |
---|
4785 | gint offset_y) |
---|
4786 | { |
---|
4787 | GtkWidgetShapeInfo* shape_info; |
---|
4788 | |
---|
4789 | g_return_if_fail (widget != NULL); |
---|
4790 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
4791 | /* set_shape doesn't work on widgets without gdk window */ |
---|
4792 | g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget)); |
---|
4793 | |
---|
4794 | if (!shape_mask) |
---|
4795 | { |
---|
4796 | GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK); |
---|
4797 | |
---|
4798 | if (widget->window) |
---|
4799 | gdk_window_shape_combine_mask (widget->window, NULL, 0, 0); |
---|
4800 | |
---|
4801 | shape_info = gtk_object_get_data (GTK_OBJECT (widget), shape_info_key); |
---|
4802 | gtk_object_remove_data (GTK_OBJECT (widget), shape_info_key); |
---|
4803 | g_free (shape_info); |
---|
4804 | } |
---|
4805 | else |
---|
4806 | { |
---|
4807 | GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK); |
---|
4808 | |
---|
4809 | shape_info = gtk_object_get_data (GTK_OBJECT (widget), shape_info_key); |
---|
4810 | if (!shape_info) |
---|
4811 | { |
---|
4812 | shape_info = g_new (GtkWidgetShapeInfo, 1); |
---|
4813 | gtk_object_set_data (GTK_OBJECT (widget), shape_info_key, shape_info); |
---|
4814 | } |
---|
4815 | shape_info->shape_mask = shape_mask; |
---|
4816 | shape_info->offset_x = offset_x; |
---|
4817 | shape_info->offset_y = offset_y; |
---|
4818 | |
---|
4819 | /* set shape if widget has a gdk window allready. |
---|
4820 | * otherwise the shape is scheduled to be set by gtk_widget_realize. |
---|
4821 | */ |
---|
4822 | if (widget->window) |
---|
4823 | gdk_window_shape_combine_mask (widget->window, shape_mask, |
---|
4824 | offset_x, offset_y); |
---|
4825 | } |
---|
4826 | } |
---|
4827 | |
---|
4828 | static void |
---|
4829 | gtk_reset_shapes_recurse (GtkWidget *widget, |
---|
4830 | GdkWindow *window) |
---|
4831 | { |
---|
4832 | GdkWindowPrivate *private; |
---|
4833 | gpointer data; |
---|
4834 | GList *list; |
---|
4835 | |
---|
4836 | private = (GdkWindowPrivate*) window; |
---|
4837 | |
---|
4838 | if (private->destroyed) |
---|
4839 | return; |
---|
4840 | gdk_window_get_user_data (window, &data); |
---|
4841 | if (data != widget) |
---|
4842 | return; |
---|
4843 | |
---|
4844 | gdk_window_shape_combine_mask (window, NULL, 0, 0); |
---|
4845 | for (list = private->children; list; list = list->next) |
---|
4846 | gtk_reset_shapes_recurse (widget, list->data); |
---|
4847 | } |
---|
4848 | |
---|
4849 | void |
---|
4850 | gtk_widget_reset_shapes (GtkWidget *widget) |
---|
4851 | { |
---|
4852 | g_return_if_fail (widget != NULL); |
---|
4853 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
4854 | g_return_if_fail (GTK_WIDGET_REALIZED (widget)); |
---|
4855 | |
---|
4856 | if (!GTK_WIDGET_HAS_SHAPE_MASK (widget)) |
---|
4857 | gtk_reset_shapes_recurse (widget, widget->window); |
---|
4858 | } |
---|
4859 | |
---|
4860 | void |
---|
4861 | gtk_widget_ref (GtkWidget *widget) |
---|
4862 | { |
---|
4863 | g_return_if_fail (widget != NULL); |
---|
4864 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
4865 | |
---|
4866 | gtk_object_ref ((GtkObject*) widget); |
---|
4867 | } |
---|
4868 | |
---|
4869 | void |
---|
4870 | gtk_widget_unref (GtkWidget *widget) |
---|
4871 | { |
---|
4872 | g_return_if_fail (widget != NULL); |
---|
4873 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
4874 | |
---|
4875 | gtk_object_unref ((GtkObject*) widget); |
---|
4876 | } |
---|
4877 | |
---|
4878 | void |
---|
4879 | gtk_widget_path (GtkWidget *widget, |
---|
4880 | guint *path_length_p, |
---|
4881 | gchar **path_p, |
---|
4882 | gchar **path_reversed_p) |
---|
4883 | { |
---|
4884 | static gchar *rev_path = NULL; |
---|
4885 | static guint path_len = 0; |
---|
4886 | guint len; |
---|
4887 | |
---|
4888 | g_return_if_fail (widget != NULL); |
---|
4889 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
4890 | |
---|
4891 | len = 0; |
---|
4892 | do |
---|
4893 | { |
---|
4894 | gchar *string; |
---|
4895 | gchar *d, *s; |
---|
4896 | guint l; |
---|
4897 | |
---|
4898 | string = gtk_widget_get_name (widget); |
---|
4899 | l = strlen (string); |
---|
4900 | while (path_len <= len + l + 1) |
---|
4901 | { |
---|
4902 | path_len += INIT_PATH_SIZE; |
---|
4903 | rev_path = g_realloc (rev_path, path_len); |
---|
4904 | } |
---|
4905 | s = string + l - 1; |
---|
4906 | d = rev_path + len; |
---|
4907 | while (s >= string) |
---|
4908 | *(d++) = *(s--); |
---|
4909 | len += l; |
---|
4910 | |
---|
4911 | widget = widget->parent; |
---|
4912 | |
---|
4913 | if (widget) |
---|
4914 | rev_path[len++] = '.'; |
---|
4915 | else |
---|
4916 | rev_path[len++] = 0; |
---|
4917 | } |
---|
4918 | while (widget); |
---|
4919 | |
---|
4920 | if (path_length_p) |
---|
4921 | *path_length_p = len - 1; |
---|
4922 | if (path_reversed_p) |
---|
4923 | *path_reversed_p = g_strdup (rev_path); |
---|
4924 | if (path_p) |
---|
4925 | { |
---|
4926 | *path_p = g_strdup (rev_path); |
---|
4927 | g_strreverse (*path_p); |
---|
4928 | } |
---|
4929 | } |
---|
4930 | |
---|
4931 | void |
---|
4932 | gtk_widget_class_path (GtkWidget *widget, |
---|
4933 | guint *path_length_p, |
---|
4934 | gchar **path_p, |
---|
4935 | gchar **path_reversed_p) |
---|
4936 | { |
---|
4937 | static gchar *rev_path = NULL; |
---|
4938 | static guint path_len = 0; |
---|
4939 | guint len; |
---|
4940 | |
---|
4941 | g_return_if_fail (widget != NULL); |
---|
4942 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
---|
4943 | |
---|
4944 | len = 0; |
---|
4945 | do |
---|
4946 | { |
---|
4947 | gchar *string; |
---|
4948 | gchar *d, *s; |
---|
4949 | guint l; |
---|
4950 | |
---|
4951 | string = gtk_type_name (GTK_WIDGET_TYPE (widget)); |
---|
4952 | l = strlen (string); |
---|
4953 | while (path_len <= len + l + 1) |
---|
4954 | { |
---|
4955 | path_len += INIT_PATH_SIZE; |
---|
4956 | rev_path = g_realloc (rev_path, path_len); |
---|
4957 | } |
---|
4958 | s = string + l - 1; |
---|
4959 | d = rev_path + len; |
---|
4960 | while (s >= string) |
---|
4961 | *(d++) = *(s--); |
---|
4962 | len += l; |
---|
4963 | |
---|
4964 | widget = widget->parent; |
---|
4965 | |
---|
4966 | if (widget) |
---|
4967 | rev_path[len++] = '.'; |
---|
4968 | else |
---|
4969 | rev_path[len++] = 0; |
---|
4970 | } |
---|
4971 | while (widget); |
---|
4972 | |
---|
4973 | if (path_length_p) |
---|
4974 | *path_length_p = len - 1; |
---|
4975 | if (path_reversed_p) |
---|
4976 | *path_reversed_p = g_strdup (rev_path); |
---|
4977 | if (path_p) |
---|
4978 | { |
---|
4979 | *path_p = g_strdup (rev_path); |
---|
4980 | g_strreverse (*path_p); |
---|
4981 | } |
---|
4982 | } |
---|