1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
28 #include "gdkwindow.h"
29 #include "gdkinternals.h"
30 #include "gdk.h" /* For gdk_rectangle_union() */
31 #include "gdkpixmap.h"
32 #include "gdkdrawable.h"
33 #include "gdkpixmap.h"
34 #include "gdkscreen.h"
36 #define USE_BACKING_STORE /* Appears to work on Win32, too, now. */
38 typedef struct _GdkWindowPaint GdkWindowPaint;
40 struct _GdkWindowPaint
48 static GdkGC *gdk_window_create_gc (GdkDrawable *drawable,
50 GdkGCValuesMask mask);
51 static void gdk_window_draw_rectangle (GdkDrawable *drawable,
58 static void gdk_window_draw_arc (GdkDrawable *drawable,
67 static void gdk_window_draw_polygon (GdkDrawable *drawable,
72 static void gdk_window_draw_text (GdkDrawable *drawable,
79 static void gdk_window_draw_text_wc (GdkDrawable *drawable,
86 static void gdk_window_draw_drawable (GdkDrawable *drawable,
95 static void gdk_window_draw_points (GdkDrawable *drawable,
99 static void gdk_window_draw_segments (GdkDrawable *drawable,
103 static void gdk_window_draw_lines (GdkDrawable *drawable,
107 static void gdk_window_draw_glyphs (GdkDrawable *drawable,
112 PangoGlyphString *glyphs);
114 static void gdk_window_draw_image (GdkDrawable *drawable,
124 static void gdk_window_draw_pixbuf (GdkDrawable *drawable,
137 static GdkImage* gdk_window_copy_to_image (GdkDrawable *drawable,
146 static void gdk_window_real_get_size (GdkDrawable *drawable,
150 static GdkVisual* gdk_window_real_get_visual (GdkDrawable *drawable);
151 static gint gdk_window_real_get_depth (GdkDrawable *drawable);
152 static GdkScreen* gdk_window_real_get_screen (GdkDrawable *drawable);
153 static void gdk_window_real_set_colormap (GdkDrawable *drawable,
155 static GdkColormap* gdk_window_real_get_colormap (GdkDrawable *drawable);
157 static GdkDrawable* gdk_window_get_composite_drawable (GdkDrawable *drawable,
162 gint *composite_x_offset,
163 gint *composite_y_offset);
164 static GdkRegion* gdk_window_get_clip_region (GdkDrawable *drawable);
165 static GdkRegion* gdk_window_get_visible_region (GdkDrawable *drawable);
167 static void gdk_window_free_paint_stack (GdkWindow *window);
169 static void gdk_window_init (GdkWindowObject *window);
170 static void gdk_window_class_init (GdkWindowObjectClass *klass);
171 static void gdk_window_finalize (GObject *object);
172 static void gdk_window_clear_backing_rect (GdkWindow *window,
178 static gpointer parent_class = NULL;
181 gdk_window_object_get_type (void)
183 static GType object_type = 0;
187 static const GTypeInfo object_info =
189 sizeof (GdkWindowObjectClass),
190 (GBaseInitFunc) NULL,
191 (GBaseFinalizeFunc) NULL,
192 (GClassInitFunc) gdk_window_class_init,
193 NULL, /* class_finalize */
194 NULL, /* class_data */
195 sizeof (GdkWindowObject),
197 (GInstanceInitFunc) gdk_window_init,
200 object_type = g_type_register_static (GDK_TYPE_DRAWABLE,
209 gdk_window_init (GdkWindowObject *window)
211 /* 0-initialization is good for all other fields. */
213 window->window_type = GDK_WINDOW_CHILD;
215 window->state = GDK_WINDOW_STATE_WITHDRAWN;
217 window->impl = g_object_new (_gdk_window_impl_get_type (), NULL);
221 gdk_window_class_init (GdkWindowObjectClass *klass)
223 GObjectClass *object_class = G_OBJECT_CLASS (klass);
224 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
226 parent_class = g_type_class_peek_parent (klass);
228 object_class->finalize = gdk_window_finalize;
230 drawable_class->create_gc = gdk_window_create_gc;
231 drawable_class->draw_rectangle = gdk_window_draw_rectangle;
232 drawable_class->draw_arc = gdk_window_draw_arc;
233 drawable_class->draw_polygon = gdk_window_draw_polygon;
234 drawable_class->draw_text = gdk_window_draw_text;
235 drawable_class->draw_text_wc = gdk_window_draw_text_wc;
236 drawable_class->draw_drawable = gdk_window_draw_drawable;
237 drawable_class->draw_points = gdk_window_draw_points;
238 drawable_class->draw_segments = gdk_window_draw_segments;
239 drawable_class->draw_lines = gdk_window_draw_lines;
240 drawable_class->draw_glyphs = gdk_window_draw_glyphs;
241 drawable_class->draw_image = gdk_window_draw_image;
242 drawable_class->draw_pixbuf = gdk_window_draw_pixbuf;
243 drawable_class->get_depth = gdk_window_real_get_depth;
244 drawable_class->get_screen = gdk_window_real_get_screen;
245 drawable_class->get_size = gdk_window_real_get_size;
246 drawable_class->set_colormap = gdk_window_real_set_colormap;
247 drawable_class->get_colormap = gdk_window_real_get_colormap;
248 drawable_class->get_visual = gdk_window_real_get_visual;
249 drawable_class->_copy_to_image = gdk_window_copy_to_image;
250 drawable_class->get_clip_region = gdk_window_get_clip_region;
251 drawable_class->get_visible_region = gdk_window_get_visible_region;
252 drawable_class->get_composite_drawable = gdk_window_get_composite_drawable;
256 gdk_window_finalize (GObject *object)
258 GdkWindow *window = GDK_WINDOW (object);
259 GdkWindowObject *obj = (GdkWindowObject *) object;
261 if (!GDK_WINDOW_DESTROYED (window))
263 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
265 g_warning ("losing last reference to undestroyed window\n");
266 _gdk_window_destroy (window, FALSE);
269 /* We use TRUE here, to keep us from actually calling
270 * XDestroyWindow() on the window
272 _gdk_window_destroy (window, TRUE);
275 g_object_unref (obj->impl);
278 G_OBJECT_CLASS (parent_class)->finalize (object);
282 * _gdk_window_destroy_hierarchy:
283 * @window: a #GdkWindow
284 * @recursing: If TRUE, then this is being called because a parent
285 * was destroyed. This generally means that the call to the
286 * windowing system to destroy the window can be omitted, since
287 * it will be destroyed as a result of the parent being destroyed.
288 * Unless @foreign_destroy.
289 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
290 * external agency. The window has already been destroyed and no
291 * windowing system calls should be made. (This may never happen
292 * for some windowing systems.)
294 * Internal function to destroy a window. Like gdk_window_destroy(),
295 * but does not drop the reference count created by gdk_window_new().
298 _gdk_window_destroy_hierarchy (GdkWindow *window,
300 gboolean foreign_destroy)
302 GdkWindowObject *private;
303 GdkWindowObject *temp_private;
304 GdkWindow *temp_window;
308 g_return_if_fail (window != NULL);
310 private = (GdkWindowObject*) window;
312 switch (GDK_WINDOW_TYPE (window))
314 case GDK_WINDOW_TOPLEVEL:
315 case GDK_WINDOW_CHILD:
316 case GDK_WINDOW_DIALOG:
317 case GDK_WINDOW_TEMP:
318 case GDK_WINDOW_FOREIGN:
319 if (!GDK_WINDOW_DESTROYED (window))
321 private->state |= GDK_WINDOW_STATE_WITHDRAWN;
325 GdkWindowObject *parent_private = (GdkWindowObject *)private->parent;
326 if (parent_private->children)
327 parent_private->children = g_list_remove (parent_private->children, window);
330 _gdk_window_clear_update_area (window);
331 gdk_window_free_paint_stack (window);
333 if (private->bg_pixmap &&
334 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
335 private->bg_pixmap != GDK_NO_BG)
337 g_object_unref (private->bg_pixmap);
338 private->bg_pixmap = NULL;
341 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_FOREIGN)
342 g_assert (private->children == NULL);
345 children = tmp = private->children;
346 private->children = NULL;
350 temp_window = tmp->data;
353 temp_private = (GdkWindowObject*) temp_window;
355 _gdk_window_destroy_hierarchy (temp_window,
356 TRUE, foreign_destroy);
359 g_list_free (children);
362 _gdk_windowing_window_destroy (window, recursing, foreign_destroy);
363 private->parent = NULL;
364 private->destroyed = TRUE;
366 if (private->filters)
368 tmp = private->filters;
376 g_list_free (private->filters);
377 private->filters = NULL;
380 gdk_drawable_set_colormap (GDK_DRAWABLE (window), NULL);
384 case GDK_WINDOW_ROOT:
385 g_error ("attempted to destroy root window");
391 * _gdk_window_destroy:
392 * @window: a #GdkWindow
393 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
394 * external agency. The window has already been destroyed and no
395 * windowing system calls should be made. (This may never happen
396 * for some windowing systems.)
398 * Internal function to destroy a window. Like gdk_window_destroy(),
399 * but does not drop the reference count created by gdk_window_new().
402 _gdk_window_destroy (GdkWindow *window,
403 gboolean foreign_destroy)
405 _gdk_window_destroy_hierarchy (window, FALSE, foreign_destroy);
409 * gdk_window_destroy:
410 * @window: a #GdkWindow
412 * Destroys the window system resources associated with @window and decrements @window's
413 * reference count. The window system resources for all children of @window are also
414 * destroyed, but the children's reference counts are not decremented.
416 * Note that a window will not be destroyed automatically when its reference count
417 * reaches zero. You must call this function yourself before that happens.
421 gdk_window_destroy (GdkWindow *window)
423 _gdk_window_destroy_hierarchy (window, FALSE, FALSE);
424 g_object_unref (window);
428 * gdk_window_set_user_data:
429 * @window: a #GdkWindow
430 * @user_data: user data
432 * For most purposes this function is deprecated in favor of
433 * g_object_set_data(). However, for historical reasons GTK+ stores
434 * the #GtkWidget that owns a #GdkWindow as user data on the
435 * #GdkWindow. So, custom widget implementations should use
436 * this function for that. If GTK+ receives an event for a #GdkWindow,
437 * and the user data for the window is non-%NULL, GTK+ will assume the
438 * user data is a #GtkWidget, and forward the event to that widget.
442 gdk_window_set_user_data (GdkWindow *window,
445 g_return_if_fail (window != NULL);
447 ((GdkWindowObject*)window)->user_data = user_data;
451 * gdk_window_get_user_data:
452 * @window: a #GdkWindow
453 * @data: return location for user data
455 * Retrieves the user data for @window, which is normally the widget
456 * that @window belongs to. See gdk_window_set_user_data().
460 gdk_window_get_user_data (GdkWindow *window,
463 g_return_if_fail (window != NULL);
465 *data = ((GdkWindowObject*)window)->user_data;
469 * gdk_window_get_window_type:
470 * @window: a #GdkWindow
472 * Gets the type of the window. See #GdkWindowType.
474 * Return value: type of window
477 gdk_window_get_window_type (GdkWindow *window)
479 g_return_val_if_fail (GDK_IS_WINDOW (window), (GdkWindowType) -1);
481 return GDK_WINDOW_TYPE (window);
485 * gdk_window_get_position:
486 * @window: a #GdkWindow
487 * @x: X coordinate of window
488 * @y: Y coordinate of window
490 * Obtains the position of the window as reported in the
491 * most-recently-processed #GdkEventConfigure. Contrast with
492 * gdk_window_get_geometry() which queries the X server for the
493 * current window position, regardless of which events have been
494 * received or processed.
496 * The position coordinates are relative to the window's parent window.
500 gdk_window_get_position (GdkWindow *window,
504 GdkWindowObject *obj;
506 g_return_if_fail (GDK_IS_WINDOW (window));
508 obj = (GdkWindowObject*) window;
517 * gdk_window_get_parent:
518 * @window: a #GdkWindow
520 * Obtains the parent of @window, as known to GDK. Does not query the
521 * X server; thus this returns the parent as passed to gdk_window_new(),
522 * not the actual parent. This should never matter unless you're using
523 * Xlib calls mixed with GDK calls on the X11 platform. It may also
524 * matter for toplevel windows, because the window manager may choose
527 * Return value: parent of @window
530 gdk_window_get_parent (GdkWindow *window)
532 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
534 return (GdkWindow*) ((GdkWindowObject*) window)->parent;
538 * gdk_window_get_toplevel:
539 * @window: a #GdkWindow
541 * Gets the toplevel window that's an ancestor of @window.
543 * Return value: the toplevel window containing @window
546 gdk_window_get_toplevel (GdkWindow *window)
548 GdkWindowObject *obj;
550 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
552 obj = (GdkWindowObject *)window;
553 while (GDK_WINDOW_TYPE (obj) == GDK_WINDOW_CHILD)
554 obj = (GdkWindowObject *)obj->parent;
556 return GDK_WINDOW (obj);
560 * gdk_window_get_children:
561 * @window: a #GdkWindow
563 * Gets the list of children of @window known to GDK.
564 * This function only returns children created via GDK,
565 * so for example it's useless when used with the root window;
566 * it only returns windows an application created itself.
568 * The returned list must be freed, but the elements in the
571 * Return value: list of child windows inside @window
574 gdk_window_get_children (GdkWindow *window)
576 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
578 if (GDK_WINDOW_DESTROYED (window))
581 return g_list_copy (GDK_WINDOW_OBJECT (window)->children);
585 * gdk_window_peek_children:
586 * @window: a #GdkWindow
588 * Like gdk_window_get_children(), but does not copy the list of
589 * children, so the list does not need to be freed.
591 * Return value: a reference to the list of child windows in @window
594 gdk_window_peek_children (GdkWindow *window)
596 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
598 if (GDK_WINDOW_DESTROYED (window))
601 return GDK_WINDOW_OBJECT (window)->children;
605 * gdk_window_add_filter:
606 * @window: a #GdkWindow
607 * @function: filter callback
608 * @data: data to pass to filter callback
610 * Adds an event filter to @window, allowing you to intercept events
611 * before they reach GDK. This is a low-level operation and makes it
612 * easy to break GDK and/or GTK+, so you have to know what you're
613 * doing. Pass %NULL for @window to get all events for all windows,
614 * instead of events for a specific window.
618 gdk_window_add_filter (GdkWindow *window,
619 GdkFilterFunc function,
622 GdkWindowObject *private;
624 GdkEventFilter *filter;
626 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
628 private = (GdkWindowObject*) window;
629 if (private && GDK_WINDOW_DESTROYED (window))
633 tmp_list = private->filters;
635 tmp_list = _gdk_default_filters;
639 filter = (GdkEventFilter *)tmp_list->data;
640 if ((filter->function == function) && (filter->data == data))
642 tmp_list = tmp_list->next;
645 filter = g_new (GdkEventFilter, 1);
646 filter->function = function;
650 private->filters = g_list_append (private->filters, filter);
652 _gdk_default_filters = g_list_append (_gdk_default_filters, filter);
656 * gdk_window_remove_filter:
657 * @window: a #GdkWindow
658 * @function: previously-added filter function
659 * @data: user data for previously-added filter function
661 * Remove a filter previously added with gdk_window_add_filter().
665 gdk_window_remove_filter (GdkWindow *window,
666 GdkFilterFunc function,
669 GdkWindowObject *private;
670 GList *tmp_list, *node;
671 GdkEventFilter *filter;
673 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
675 private = (GdkWindowObject*) window;
678 tmp_list = private->filters;
680 tmp_list = _gdk_default_filters;
684 filter = (GdkEventFilter *)tmp_list->data;
686 tmp_list = tmp_list->next;
688 if ((filter->function == function) && (filter->data == data))
691 private->filters = g_list_remove_link (private->filters, node);
693 _gdk_default_filters = g_list_remove_link (_gdk_default_filters, node);
694 g_list_free_1 (node);
703 * gdk_screen_get_toplevel_windows:
704 * @screen: The #GdkScreen where the toplevels are located.
706 * Obtains a list of all toplevel windows known to GDK on the screen @screen.
707 * A toplevel window is a child of the root window (see
708 * gdk_get_default_root_window()).
710 * The returned list should be freed with g_list_free(), but
711 * its elements need not be freed.
713 * Return value: list of toplevel windows, free with g_list_free()
718 gdk_screen_get_toplevel_windows (GdkScreen *screen)
720 GdkWindow * root_window;
721 GList *new_list = NULL;
724 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
726 root_window = gdk_screen_get_root_window (screen);
728 tmp_list = ((GdkWindowObject *)root_window)->children;
731 if (GDK_WINDOW_TYPE (tmp_list->data) != GDK_WINDOW_FOREIGN)
732 new_list = g_list_prepend (new_list, tmp_list->data);
733 tmp_list = tmp_list->next;
740 * gdk_window_get_toplevels:
742 * Obtains a list of all toplevel windows known to GDK on the default
743 * screen (see gdk_window_get_toplevels_for_screen()).
744 * A toplevel window is a child of the root window (see
745 * gdk_get_default_root_window()).
747 * The returned list should be freed with g_list_free(), but
748 * its elements need not be freed.
750 * Return value: list of toplevel windows, free with g_list_free()
753 gdk_window_get_toplevels (void)
755 return gdk_screen_get_toplevel_windows (gdk_screen_get_default ());
759 * gdk_window_is_visible:
760 * @window: a #GdkWindow
762 * Checks whether the window has been mapped (with gdk_window_show() or
763 * gdk_window_show_unraised()).
765 * Return value: %TRUE if the window is mapped
768 gdk_window_is_visible (GdkWindow *window)
770 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
772 return GDK_WINDOW_IS_MAPPED (window);
776 * gdk_window_is_viewable:
777 * @window: a #GdkWindow
779 * Check if the window and all ancestors of the window are
780 * mapped. (This is not necessarily "viewable" in the X sense, since
781 * we only check as far as we have GDK window parents, not to the root
784 * Return value: %TRUE if the window is viewable
787 gdk_window_is_viewable (GdkWindow *window)
789 GdkWindowObject *private = (GdkWindowObject *)window;
791 GdkWindow *root_window;
793 g_return_val_if_fail (window != NULL, FALSE);
794 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
796 screen = gdk_drawable_get_screen (window);
797 root_window = gdk_screen_get_root_window (screen);
800 (private != (GdkWindowObject *)root_window) &&
801 (GDK_WINDOW_TYPE (private) != GDK_WINDOW_FOREIGN))
803 if (GDK_WINDOW_DESTROYED (window) || !GDK_WINDOW_IS_MAPPED (window))
806 private = (GdkWindowObject *)private->parent;
813 * gdk_window_get_state:
814 * @window: a #GdkWindow
816 * Gets the bitwise OR of the currently active window state flags,
817 * from the #GdkWindowState enumeration.
819 * Return value: window state bitfield
822 gdk_window_get_state (GdkWindow *window)
824 GdkWindowObject *private = (GdkWindowObject *)window;
826 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
828 return private->state;
832 * gdk_window_begin_paint_rect:
833 * @window: a #GdkWindow
834 * @rectangle: rectangle you intend to draw to
836 * A convenience wrapper around gdk_window_begin_paint_region() which
837 * creates a rectangular region for you. See
838 * gdk_window_begin_paint_region() for details.
842 gdk_window_begin_paint_rect (GdkWindow *window,
843 GdkRectangle *rectangle)
847 g_return_if_fail (window != NULL);
848 g_return_if_fail (GDK_IS_WINDOW (window));
850 region = gdk_region_rectangle (rectangle);
851 gdk_window_begin_paint_region (window, region);
852 gdk_region_destroy (region);
855 #ifdef GDK_WINDOWING_X11
856 #include "x11/gdkx.h"
860 * gdk_window_begin_paint_region:
861 * @window: a #GdkWindow
862 * @region: region you intend to draw to
864 * Indicates that you are beginning the process of redrawing @region.
865 * A backing store (offscreen buffer) large enough to contain @region
866 * will be created. The backing store will be initialized with the
867 * background color or background pixmap for @window. Then, all
868 * drawing operations performed on @window will be diverted to the
869 * backing store. When you call gdk_window_end_paint(), the backing
870 * store will be copied to @window, making it visible onscreen. Only
871 * the part of @window contained in @region will be modified; that is,
872 * drawing operations are clipped to @region.
874 * The net result of all this is to remove flicker, because the user
875 * sees the finished product appear all at once when you call
876 * gdk_window_end_paint(). If you draw to @window directly without
877 * calling gdk_window_begin_paint_region(), the user may see flicker
878 * as individual drawing operations are performed in sequence. The
879 * clipping and background-initializing features of
880 * gdk_window_begin_paint_region() are conveniences for the
881 * programmer, so you can avoid doing that work yourself.
883 * When using GTK+, the widget system automatically places calls to
884 * gdk_window_begin_paint_region() and gdk_window_end_paint() around
885 * emissions of the expose_event signal. That is, if you're writing an
886 * expose event handler, you can assume that the exposed area in
887 * #GdkEventExpose has already been cleared to the window background,
888 * is already set as the clip region, and already has a backing store.
889 * Therefore in most cases, application code need not call
890 * gdk_window_begin_paint_region(). (You can disable the automatic
891 * calls around expose events on a widget-by-widget basis by calling
892 * gtk_widget_set_double_buffered().)
894 * If you call this function multiple times before calling the
895 * matching gdk_window_end_paint(), the backing stores are pushed onto
896 * a stack. gdk_window_end_paint() copies the topmost backing store
897 * onscreen, subtracts the topmost region from all other regions in
898 * the stack, and pops the stack. All drawing operations affect only
899 * the topmost backing store in the stack. One matching call to
900 * gdk_window_end_paint() is required for each call to
901 * gdk_window_begin_paint_region().
905 gdk_window_begin_paint_region (GdkWindow *window,
908 #ifdef USE_BACKING_STORE
909 GdkWindowObject *private = (GdkWindowObject *)window;
910 GdkRectangle clip_box;
911 GdkWindowPaint *paint;
914 g_return_if_fail (window != NULL);
915 g_return_if_fail (GDK_IS_WINDOW (window));
917 if (GDK_WINDOW_DESTROYED (window))
920 gdk_region_get_clipbox (region, &clip_box);
922 paint = g_new (GdkWindowPaint, 1);
923 paint->region = gdk_region_copy (region);
924 paint->x_offset = clip_box.x;
925 paint->y_offset = clip_box.y;
927 gdk_pixmap_new (window,
928 MAX (clip_box.width, 1), MAX (clip_box.height, 1), -1);
930 for (list = private->paint_stack; list != NULL; list = list->next)
932 GdkWindowPaint *tmp_paint = list->data;
934 gdk_region_subtract (tmp_paint->region, paint->region);
937 private->paint_stack = g_slist_prepend (private->paint_stack, paint);
939 if (!gdk_region_empty (region))
941 gdk_window_clear_backing_rect (window,
942 clip_box.x, clip_box.y,
943 clip_box.width, clip_box.height);
945 #endif /* USE_BACKING_STORE */
949 * gdk_window_end_paint:
950 * @window: a #GdkWindow
952 * Indicates that the backing store created by the most recent call to
953 * gdk_window_begin_paint_region() should be copied onscreen and
954 * deleted, leaving the next-most-recent backing store or no backing
955 * store at all as the active paint region. See
956 * gdk_window_begin_paint_region() for full details. It is an error to
957 * call this function without a matching
958 * gdk_window_begin_paint_region() first.
962 gdk_window_end_paint (GdkWindow *window)
964 #ifdef USE_BACKING_STORE
965 GdkWindowObject *private = (GdkWindowObject *)window;
966 GdkWindowPaint *paint;
968 GdkRectangle clip_box;
969 gint x_offset, y_offset;
971 g_return_if_fail (window != NULL);
972 g_return_if_fail (GDK_IS_WINDOW (window));
974 if (GDK_WINDOW_DESTROYED (window))
977 if (private->paint_stack == NULL)
979 g_warning (G_STRLOC": no preceding call to gdk_window_begin_paint_region(), see documentation");
983 paint = private->paint_stack->data;
984 private->paint_stack = g_slist_delete_link (private->paint_stack,
985 private->paint_stack);
987 gdk_region_get_clipbox (paint->region, &clip_box);
989 tmp_gc = _gdk_drawable_get_scratch_gc (window, FALSE);
991 _gdk_windowing_window_get_offsets (window, &x_offset, &y_offset);
993 gdk_gc_set_clip_region (tmp_gc, paint->region);
994 gdk_gc_set_clip_origin (tmp_gc, - x_offset, - y_offset);
996 gdk_draw_drawable (private->impl, tmp_gc, paint->pixmap,
997 clip_box.x - paint->x_offset,
998 clip_box.y - paint->y_offset,
999 clip_box.x - x_offset, clip_box.y - y_offset,
1000 clip_box.width, clip_box.height);
1002 /* Reset clip region of the cached GdkGC */
1003 gdk_gc_set_clip_region (tmp_gc, NULL);
1005 g_object_unref (paint->pixmap);
1006 gdk_region_destroy (paint->region);
1008 #endif /* USE_BACKING_STORE */
1012 gdk_window_free_paint_stack (GdkWindow *window)
1014 GdkWindowObject *private = (GdkWindowObject *)window;
1016 if (private->paint_stack)
1018 GSList *tmp_list = private->paint_stack;
1022 GdkWindowPaint *paint = tmp_list->data;
1024 if (tmp_list == private->paint_stack)
1025 g_object_unref (paint->pixmap);
1027 gdk_region_destroy (paint->region);
1030 tmp_list = tmp_list->next;
1033 g_slist_free (private->paint_stack);
1034 private->paint_stack = NULL;
1039 gdk_window_get_offsets (GdkWindow *window,
1043 GdkWindowObject *private = (GdkWindowObject *)window;
1045 if (private->paint_stack)
1047 GdkWindowPaint *paint = private->paint_stack->data;
1048 *x_offset = paint->x_offset;
1049 *y_offset = paint->y_offset;
1052 _gdk_windowing_window_get_offsets (window, x_offset, y_offset);
1056 * gdk_window_get_internal_paint_info:
1057 * @window: a #GdkWindow
1058 * @real_drawable: location to store the drawable to which drawing should be
1060 * @x_offset: location to store the X offset between coordinates in @window,
1061 * and the underlying window system primitive coordinates for
1063 * @y_offset: location to store the Y offset between coordinates in @window,
1064 * and the underlying window system primitive coordinates for
1067 * If you bypass the GDK layer and use windowing system primitives to
1068 * draw directly onto a #GdkWindow, then you need to deal with two
1069 * details: there may be an offset between GDK coordinates and windowing
1070 * system coordinates, and GDK may have redirected drawing to a offscreen
1071 * pixmap as the result of a gdk_window_begin_paint_region() calls.
1072 * This function allows retrieving the information you need to compensate
1073 * for these effects.
1075 * This function exposes details of the GDK implementation, and is thus
1076 * likely to change in future releases of GDK.
1079 gdk_window_get_internal_paint_info (GdkWindow *window,
1080 GdkDrawable **real_drawable,
1086 GdkWindowObject *private;
1088 g_return_if_fail (GDK_IS_WINDOW (window));
1090 private = (GdkWindowObject *)window;
1094 if (private->paint_stack)
1096 GdkWindowPaint *paint = private->paint_stack->data;
1097 *real_drawable = paint->pixmap;
1100 *real_drawable = window;
1103 gdk_window_get_offsets (window, &x_off, &y_off);
1111 #define OFFSET_GC(gc) \
1112 gint x_offset, y_offset; \
1113 gint old_clip_x = gc->clip_x_origin; \
1114 gint old_clip_y = gc->clip_y_origin; \
1115 gint old_ts_x = gc->ts_x_origin; \
1116 gint old_ts_y = gc->ts_y_origin; \
1117 gdk_window_get_offsets (drawable, &x_offset, &y_offset); \
1118 if (x_offset != 0 || y_offset != 0) \
1120 gdk_gc_set_clip_origin (gc, old_clip_x - x_offset, \
1121 old_clip_y - y_offset); \
1122 gdk_gc_set_ts_origin (gc, old_ts_x - x_offset, \
1123 old_ts_y - y_offset); \
1126 #define RESTORE_GC(gc) \
1127 if (x_offset != 0 || y_offset != 0) \
1129 gdk_gc_set_clip_origin (gc, old_clip_x, old_clip_y); \
1130 gdk_gc_set_ts_origin (gc, old_ts_x, old_ts_y); \
1134 gdk_window_create_gc (GdkDrawable *drawable,
1135 GdkGCValues *values,
1136 GdkGCValuesMask mask)
1138 g_return_val_if_fail (GDK_IS_WINDOW (drawable), NULL);
1140 if (GDK_WINDOW_DESTROYED (drawable))
1143 return gdk_gc_new_with_values (((GdkWindowObject *) drawable)->impl,
1148 gdk_window_draw_rectangle (GdkDrawable *drawable,
1156 GdkWindowObject *private = (GdkWindowObject *)drawable;
1159 if (GDK_WINDOW_DESTROYED (drawable))
1162 if (private->paint_stack)
1164 GdkWindowPaint *paint = private->paint_stack->data;
1165 gdk_draw_rectangle (paint->pixmap, gc, filled,
1166 x - x_offset, y - y_offset, width, height);
1169 gdk_draw_rectangle (private->impl, gc, filled,
1170 x - x_offset, y - y_offset, width, height);
1176 gdk_window_draw_arc (GdkDrawable *drawable,
1186 GdkWindowObject *private = (GdkWindowObject *)drawable;
1189 if (GDK_WINDOW_DESTROYED (drawable))
1192 if (private->paint_stack)
1194 GdkWindowPaint *paint = private->paint_stack->data;
1195 gdk_draw_arc (paint->pixmap, gc, filled,
1196 x - x_offset, y - y_offset,
1197 width, height, angle1, angle2);
1200 gdk_draw_arc (private->impl, gc, filled,
1201 x - x_offset, y - y_offset,
1202 width, height, angle1, angle2);
1207 gdk_window_draw_polygon (GdkDrawable *drawable,
1213 GdkWindowObject *private = (GdkWindowObject *)drawable;
1214 GdkPoint *new_points;
1218 if (GDK_WINDOW_DESTROYED (drawable))
1221 if (x_offset != 0 || y_offset != 0)
1225 new_points = g_new (GdkPoint, npoints);
1226 for (i=0; i<npoints; i++)
1228 new_points[i].x = points[i].x - x_offset;
1229 new_points[i].y = points[i].y - y_offset;
1233 new_points = points;
1235 if (private->paint_stack)
1237 GdkWindowPaint *paint = private->paint_stack->data;
1238 gdk_draw_polygon (paint->pixmap, gc, filled, new_points, npoints);
1242 gdk_draw_polygon (private->impl, gc, filled, new_points, npoints);
1244 if (new_points != points)
1245 g_free (new_points);
1251 gdk_window_draw_text (GdkDrawable *drawable,
1259 GdkWindowObject *private = (GdkWindowObject *)drawable;
1262 if (GDK_WINDOW_DESTROYED (drawable))
1265 if (private->paint_stack)
1267 GdkWindowPaint *paint = private->paint_stack->data;
1268 gdk_draw_text (paint->pixmap, font, gc,
1269 x - x_offset, y - y_offset, text, text_length);
1273 gdk_draw_text (private->impl, font, gc,
1274 x - x_offset, y - y_offset, text, text_length);
1280 gdk_window_draw_text_wc (GdkDrawable *drawable,
1285 const GdkWChar *text,
1288 GdkWindowObject *private = (GdkWindowObject *)drawable;
1291 if (GDK_WINDOW_DESTROYED (drawable))
1294 if (private->paint_stack)
1296 GdkWindowPaint *paint = private->paint_stack->data;
1297 gdk_draw_text_wc (paint->pixmap, font, gc,
1298 x - x_offset, y - y_offset, text, text_length);
1301 gdk_draw_text_wc (private->impl, font, gc,
1302 x - x_offset, y - y_offset, text, text_length);
1308 gdk_window_get_composite_drawable (GdkDrawable *drawable,
1313 gint *composite_x_offset,
1314 gint *composite_y_offset)
1316 GdkWindowObject *private = (GdkWindowObject *)drawable;
1318 GdkPixmap *tmp_pixmap;
1321 gboolean overlap_buffer;
1323 _gdk_windowing_window_get_offsets (drawable,
1325 composite_y_offset);
1327 if ((GDK_IS_WINDOW (drawable) && GDK_WINDOW_DESTROYED (drawable))
1328 || private->paint_stack == NULL)
1330 /* No backing store */
1331 return g_object_ref (drawable);
1334 /* See if the buffered part is overlapping the part we want
1340 rect.height = height;
1342 overlap_buffer = FALSE;
1344 for (list = private->paint_stack; list != NULL; list = list->next)
1346 GdkWindowPaint *paint = list->data;
1347 GdkOverlapType overlap;
1349 overlap = gdk_region_rect_in (paint->region, &rect);
1351 if (overlap == GDK_OVERLAP_RECTANGLE_IN)
1353 *composite_x_offset = paint->x_offset;
1354 *composite_y_offset = paint->y_offset;
1356 return g_object_ref (paint->pixmap);
1358 else if (overlap == GDK_OVERLAP_RECTANGLE_PART)
1360 overlap_buffer = TRUE;
1365 if (!overlap_buffer)
1366 return g_object_ref (drawable);
1368 tmp_pixmap = gdk_pixmap_new (drawable, width, height, -1);
1369 tmp_gc = _gdk_drawable_get_scratch_gc (tmp_pixmap, FALSE);
1371 /* Copy the current window contents */
1372 gdk_draw_drawable (tmp_pixmap,
1375 x - *composite_x_offset,
1376 y - *composite_y_offset,
1380 /* paint the backing stores */
1381 for (list = private->paint_stack; list != NULL; list = list->next)
1383 GdkWindowPaint *paint = list->data;
1385 gdk_gc_set_clip_region (tmp_gc, paint->region);
1386 gdk_gc_set_clip_origin (tmp_gc, -x, -y);
1388 gdk_draw_drawable (tmp_pixmap, tmp_gc, paint->pixmap,
1389 x - paint->x_offset,
1390 y - paint->y_offset,
1391 0, 0, width, height);
1394 /* Reset clip region of the cached GdkGC */
1395 gdk_gc_set_clip_region (tmp_gc, NULL);
1397 /* Set these to location of tmp_pixmap within the window */
1398 *composite_x_offset = x;
1399 *composite_y_offset = y;
1405 gdk_window_get_clip_region (GdkDrawable *drawable)
1407 GdkWindowObject *private = (GdkWindowObject *)drawable;
1410 result = gdk_drawable_get_clip_region (private->impl);
1412 if (private->paint_stack)
1414 GdkRegion *paint_region = gdk_region_new ();
1415 GSList *tmp_list = private->paint_stack;
1419 GdkWindowPaint *paint = tmp_list->data;
1421 gdk_region_union (paint_region, paint->region);
1423 tmp_list = tmp_list->next;
1426 gdk_region_intersect (result, paint_region);
1427 gdk_region_destroy (paint_region);
1434 gdk_window_get_visible_region (GdkDrawable *drawable)
1436 GdkWindowObject *private = (GdkWindowObject*) drawable;
1438 return gdk_drawable_get_visible_region (private->impl);
1442 gdk_window_draw_drawable (GdkDrawable *drawable,
1452 GdkWindowObject *private = (GdkWindowObject *)drawable;
1455 if (GDK_WINDOW_DESTROYED (drawable))
1458 /* If we have a backing pixmap draw to that */
1459 if (private->paint_stack)
1461 GdkWindowPaint *paint = private->paint_stack->data;
1462 gdk_draw_drawable (paint->pixmap, gc,
1464 xdest - x_offset, ydest - y_offset, width, height);
1468 gdk_draw_drawable (private->impl, gc,
1470 xdest - x_offset, ydest - y_offset,
1477 gdk_window_draw_points (GdkDrawable *drawable,
1482 GdkWindowObject *private = (GdkWindowObject *)drawable;
1483 GdkPoint *new_points;
1487 if (GDK_WINDOW_DESTROYED (drawable))
1490 if (x_offset != 0 || y_offset != 0)
1494 new_points = g_new (GdkPoint, npoints);
1495 for (i=0; i<npoints; i++)
1497 new_points[i].x = points[i].x - x_offset;
1498 new_points[i].y = points[i].y - y_offset;
1502 new_points = points;
1504 if (private->paint_stack)
1506 GdkWindowPaint *paint = private->paint_stack->data;
1507 gdk_draw_points (paint->pixmap, gc, new_points, npoints);
1510 gdk_draw_points (private->impl, gc, points, npoints);
1512 if (new_points != points)
1513 g_free (new_points);
1519 gdk_window_draw_segments (GdkDrawable *drawable,
1524 GdkWindowObject *private = (GdkWindowObject *)drawable;
1525 GdkSegment *new_segs;
1529 if (GDK_WINDOW_DESTROYED (drawable))
1532 if (x_offset != 0 || y_offset != 0)
1536 new_segs = g_new (GdkSegment, nsegs);
1537 for (i=0; i<nsegs; i++)
1539 new_segs[i].x1 = segs[i].x1 - x_offset;
1540 new_segs[i].y1 = segs[i].y1 - y_offset;
1541 new_segs[i].x2 = segs[i].x2 - x_offset;
1542 new_segs[i].y2 = segs[i].y2 - y_offset;
1548 if (private->paint_stack)
1550 GdkWindowPaint *paint = private->paint_stack->data;
1551 gdk_draw_segments (paint->pixmap, gc, new_segs, nsegs);
1554 gdk_draw_segments (private->impl, gc, new_segs, nsegs);
1556 if (new_segs != segs)
1563 gdk_window_draw_lines (GdkDrawable *drawable,
1568 GdkWindowObject *private = (GdkWindowObject *)drawable;
1569 GdkPoint *new_points;
1573 if (GDK_WINDOW_DESTROYED (drawable))
1576 if (x_offset != 0 || y_offset != 0)
1580 new_points = g_new (GdkPoint, npoints);
1581 for (i=0; i<npoints; i++)
1583 new_points[i].x = points[i].x - x_offset;
1584 new_points[i].y = points[i].y - y_offset;
1588 new_points = points;
1590 if (private->paint_stack)
1592 GdkWindowPaint *paint = private->paint_stack->data;
1593 gdk_draw_lines (paint->pixmap, gc, new_points, npoints);
1596 gdk_draw_lines (private->impl, gc, new_points, npoints);
1598 if (new_points != points)
1599 g_free (new_points);
1605 gdk_window_draw_glyphs (GdkDrawable *drawable,
1610 PangoGlyphString *glyphs)
1612 GdkWindowObject *private = (GdkWindowObject *)drawable;
1616 if (GDK_WINDOW_DESTROYED (drawable))
1619 if (private->paint_stack)
1621 GdkWindowPaint *paint = private->paint_stack->data;
1623 gdk_draw_glyphs (paint->pixmap, gc, font, x - x_offset, y - y_offset, glyphs);
1626 gdk_draw_glyphs (private->impl, gc, font,
1627 x - x_offset, y - y_offset, glyphs);
1633 gdk_window_get_bg_gc (GdkWindow *window,
1634 GdkWindowPaint *paint)
1636 GdkWindowObject *private = (GdkWindowObject *)window;
1639 GdkGCValues gc_values;
1641 if (private->bg_pixmap == GDK_PARENT_RELATIVE_BG && private->parent)
1643 GdkWindowPaint tmp_paint = *paint;
1644 tmp_paint.x_offset += private->x;
1645 tmp_paint.y_offset += private->y;
1647 return gdk_window_get_bg_gc (GDK_WINDOW (private->parent), &tmp_paint);
1649 else if (private->bg_pixmap &&
1650 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
1651 private->bg_pixmap != GDK_NO_BG)
1653 gc_values.fill = GDK_TILED;
1654 gc_values.tile = private->bg_pixmap;
1656 gc_mask = GDK_GC_FILL | GDK_GC_TILE;
1658 return gdk_gc_new_with_values (paint->pixmap, &gc_values, gc_mask);
1662 GdkGC *gc = _gdk_drawable_get_scratch_gc (paint->pixmap, FALSE);
1664 gdk_gc_set_foreground (gc, &(private->bg_color));
1666 return g_object_ref (gc);
1671 gdk_window_clear_backing_rect (GdkWindow *window,
1677 GdkWindowObject *private = (GdkWindowObject *)window;
1678 GdkWindowPaint *paint = private->paint_stack->data;
1681 if (GDK_WINDOW_DESTROYED (window))
1684 tmp_gc = gdk_window_get_bg_gc (window, paint);
1685 gdk_gc_set_clip_region (tmp_gc, paint->region);
1687 gdk_draw_rectangle (window, tmp_gc, TRUE,
1688 x, y, width, height);
1690 gdk_gc_set_clip_region (tmp_gc, NULL);
1692 g_object_unref (tmp_gc);
1697 * @window: a #GdkWindow
1699 * Clears an entire @window to the background color or background pixmap.
1702 gdk_window_clear (GdkWindow *window)
1706 g_return_if_fail (window != NULL);
1707 g_return_if_fail (GDK_IS_WINDOW (window));
1709 gdk_drawable_get_size (GDK_DRAWABLE (window), &width, &height);
1711 gdk_window_clear_area (window, 0, 0,
1716 * gdk_window_clear_area:
1717 * @window: a #GdkWindow
1718 * @x: x coordinate of rectangle to clear
1719 * @y: y coordinate of rectangle to clear
1720 * @width: width of rectangle to clear
1721 * @height: height of rectangle to clear
1723 * Clears an area of @window to the background color or background pixmap.
1727 gdk_window_clear_area (GdkWindow *window,
1733 GdkWindowObject *private = (GdkWindowObject *)window;
1735 g_return_if_fail (window != NULL);
1736 g_return_if_fail (GDK_IS_WINDOW (window));
1738 if (private->paint_stack)
1739 gdk_window_clear_backing_rect (window, x, y, width, height);
1741 _gdk_windowing_window_clear_area (window, x, y, width, height);
1745 * gdk_window_clear_area_e:
1746 * @window: a #GdkWindow
1747 * @x: x coordinate of rectangle to clear
1748 * @y: y coordinate of rectangle to clear
1749 * @width: width of rectangle to clear
1750 * @height: height of rectangle to clear
1752 * Like gdk_window_clear_area(), but also generates an expose event for
1755 * This function has a stupid name because it dates back to the mists
1756 * time, pre-GDK-1.0.
1760 gdk_window_clear_area_e (GdkWindow *window,
1766 GdkWindowObject *private = (GdkWindowObject *)window;
1768 g_return_if_fail (window != NULL);
1769 g_return_if_fail (GDK_IS_WINDOW (window));
1771 if (private->paint_stack)
1772 gdk_window_clear_backing_rect (window, x, y, width, height);
1774 _gdk_windowing_window_clear_area_e (window, x, y, width, height);
1778 gdk_window_draw_image (GdkDrawable *drawable,
1788 GdkWindowObject *private = (GdkWindowObject *)drawable;
1792 if (GDK_WINDOW_DESTROYED (drawable))
1795 if (private->paint_stack)
1797 GdkWindowPaint *paint = private->paint_stack->data;
1798 gdk_draw_image (paint->pixmap, gc, image, xsrc, ysrc,
1799 xdest - x_offset, ydest - y_offset,
1804 gdk_draw_image (private->impl, gc, image, xsrc, ysrc,
1805 xdest - x_offset, ydest - y_offset,
1812 gdk_window_draw_pixbuf (GdkDrawable *drawable,
1821 GdkRgbDither dither,
1825 GdkWindowObject *private = (GdkWindowObject *)drawable;
1827 if (GDK_WINDOW_DESTROYED (drawable))
1834 if (private->paint_stack)
1836 GdkWindowPaint *paint = private->paint_stack->data;
1837 gdk_draw_pixbuf (paint->pixmap, gc, pixbuf, src_x, src_y,
1838 dest_x - x_offset, dest_y - y_offset,
1840 dither, x_dither - x_offset, y_dither - y_offset);
1843 gdk_draw_pixbuf (private->impl, gc, pixbuf, src_x, src_y,
1844 dest_x - x_offset, dest_y - y_offset,
1846 dither, x_dither, y_dither);
1852 gint x_offset, y_offset;
1853 gdk_window_get_offsets (drawable, &x_offset, &y_offset);
1855 if (private->paint_stack)
1857 GdkWindowPaint *paint = private->paint_stack->data;
1858 gdk_draw_pixbuf (paint->pixmap, gc, pixbuf, src_x, src_y,
1859 dest_x - x_offset, dest_y - y_offset,
1861 dither, x_dither - x_offset, y_dither - y_offset);
1864 gdk_draw_pixbuf (private->impl, gc, pixbuf, src_x, src_y,
1865 dest_x - x_offset, dest_y - y_offset,
1867 dither, x_dither, y_dither);
1872 gdk_window_real_get_size (GdkDrawable *drawable,
1876 g_return_if_fail (GDK_IS_WINDOW (drawable));
1878 gdk_drawable_get_size (GDK_WINDOW_OBJECT (drawable)->impl,
1883 gdk_window_real_get_visual (GdkDrawable *drawable)
1885 GdkColormap *colormap;
1887 g_return_val_if_fail (GDK_IS_WINDOW (drawable), NULL);
1889 colormap = gdk_drawable_get_colormap (drawable);
1890 return colormap ? gdk_colormap_get_visual (colormap) : NULL;
1894 gdk_window_real_get_depth (GdkDrawable *drawable)
1896 g_return_val_if_fail (GDK_IS_WINDOW (drawable), 0);
1898 return ((GdkWindowObject *)GDK_WINDOW (drawable))->depth;
1902 gdk_window_real_get_screen (GdkDrawable *drawable)
1904 return gdk_drawable_get_screen (GDK_WINDOW_OBJECT (drawable)->impl);
1908 gdk_window_real_set_colormap (GdkDrawable *drawable,
1911 g_return_if_fail (GDK_IS_WINDOW (drawable));
1913 if (GDK_WINDOW_DESTROYED (drawable))
1916 gdk_drawable_set_colormap (((GdkWindowObject*)drawable)->impl, cmap);
1920 gdk_window_real_get_colormap (GdkDrawable *drawable)
1922 g_return_val_if_fail (GDK_IS_WINDOW (drawable), NULL);
1924 if (GDK_WINDOW_DESTROYED (drawable))
1927 return gdk_drawable_get_colormap (((GdkWindowObject*)drawable)->impl);
1931 gdk_window_copy_to_image (GdkDrawable *drawable,
1940 gint x_offset, y_offset;
1942 g_return_val_if_fail (GDK_IS_WINDOW (drawable), NULL);
1944 if (GDK_WINDOW_DESTROYED (drawable))
1947 /* If we're here, a composite image was not necessary, so
1948 * we can ignore the paint stack.
1951 _gdk_windowing_window_get_offsets (drawable, &x_offset, &y_offset);
1953 return gdk_drawable_copy_to_image (((GdkWindowObject*)drawable)->impl,
1961 /* Code for dirty-region queueing
1964 static GSList *update_windows = NULL;
1965 static guint update_idle = 0;
1966 static gboolean debug_updates = FALSE;
1969 gdk_window_process_updates_internal (GdkWindow *window)
1971 GdkWindowObject *private = (GdkWindowObject *)window;
1972 gboolean save_region = FALSE;
1974 /* If an update got queued during update processing, we can get a
1975 * window in the update queue that has an empty update_area.
1978 if (private->update_area)
1980 GdkRegion *update_area = private->update_area;
1981 private->update_area = NULL;
1983 if (_gdk_event_func && gdk_window_is_viewable (window) &&
1984 (private->event_mask & GDK_EXPOSURE_MASK))
1987 GdkRectangle window_rect;
1988 GdkRegion *expose_region;
1989 GdkRegion *window_region;
1994 /* Make sure we see the red invalid area before redrawing. */
1995 gdk_display_sync (gdk_drawable_get_display (window));
1999 gdk_drawable_get_size (GDK_DRAWABLE (private), &width, &height);
2003 window_rect.width = width;
2004 window_rect.height = height;
2006 save_region = _gdk_windowing_window_queue_antiexpose (window, update_area);
2008 event.expose.type = GDK_EXPOSE;
2009 event.expose.window = g_object_ref (window);
2010 event.expose.count = 0;
2013 expose_region = gdk_region_copy (update_area);
2015 expose_region = update_area;
2016 window_region = gdk_region_rectangle (&window_rect);
2017 gdk_region_intersect (expose_region,
2019 gdk_region_destroy (window_region);
2021 event.expose.region = expose_region;
2022 gdk_region_get_clipbox (expose_region, &event.expose.area);
2024 if (!gdk_region_empty (expose_region))
2026 (*_gdk_event_func) (&event, _gdk_event_data);
2029 if (expose_region != update_area)
2030 gdk_region_destroy (expose_region);
2031 g_object_unref (window);
2034 gdk_region_destroy (update_area);
2039 flush_all_displays (void)
2041 GSList *displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
2044 for (tmp_list = displays; tmp_list; tmp_list = tmp_list->next)
2045 gdk_display_flush (tmp_list->data);
2047 g_slist_free (displays);
2051 * gdk_window_process_all_updates:
2053 * Calls gdk_window_process_updates() for all windows (see #GdkWindow)
2054 * in the application.
2058 gdk_window_process_all_updates (void)
2060 GSList *old_update_windows = update_windows;
2061 GSList *tmp_list = update_windows;
2064 g_source_remove (update_idle);
2066 update_windows = NULL;
2069 g_slist_foreach (old_update_windows, (GFunc)g_object_ref, NULL);
2073 gdk_window_process_updates_internal (tmp_list->data);
2074 g_object_unref (tmp_list->data);
2075 tmp_list = tmp_list->next;
2078 g_slist_free (old_update_windows);
2080 flush_all_displays ();
2084 gdk_window_update_idle (gpointer data)
2086 GDK_THREADS_ENTER ();
2087 gdk_window_process_all_updates ();
2088 GDK_THREADS_LEAVE ();
2094 * gdk_window_process_updates:
2095 * @window: a #GdkWindow
2096 * @update_children: whether to also process updates for child windows
2098 * Sends one or more expose events to @window. The areas in each
2099 * expose event will cover the entire update area for the window (see
2100 * gdk_window_invalidate_region() for details). Normally GDK calls
2101 * gdk_window_process_all_updates() on your behalf, so there's no
2102 * need to call this function unless you want to force expose events
2103 * to be delivered immediately and synchronously (vs. the usual
2104 * case, where GDK delivers them in an idle handler). Occasionally
2105 * this is useful to produce nicer scrolling behavior, for example.
2109 gdk_window_process_updates (GdkWindow *window,
2110 gboolean update_children)
2112 GdkWindowObject *private = (GdkWindowObject *)window;
2114 g_return_if_fail (window != NULL);
2115 g_return_if_fail (GDK_IS_WINDOW (window));
2117 if (private->update_area)
2119 gdk_window_process_updates_internal (window);
2120 update_windows = g_slist_remove (update_windows, window);
2123 if (update_children)
2125 GList *tmp_list = private->children;
2128 gdk_window_process_updates (tmp_list->data, TRUE);
2129 tmp_list = tmp_list->next;
2135 * gdk_window_invalidate_rect:
2136 * @window: a #GdkWindow
2137 * @rect: rectangle to invalidate
2138 * @invalidate_children: whether to also invalidate child windows
2140 * A convenience wrapper around gdk_window_invalidate_region() which
2141 * invalidates a rectangular region. See
2142 * gdk_window_invalidate_region() for details.
2146 gdk_window_invalidate_rect (GdkWindow *window,
2148 gboolean invalidate_children)
2150 GdkRectangle window_rect;
2152 GdkWindowObject *private = (GdkWindowObject *)window;
2154 g_return_if_fail (window != NULL);
2155 g_return_if_fail (GDK_IS_WINDOW (window));
2157 if (GDK_WINDOW_DESTROYED (window))
2160 if (private->input_only || !GDK_WINDOW_IS_MAPPED (window))
2167 gdk_drawable_get_size (GDK_DRAWABLE (window),
2169 &window_rect.height);
2170 rect = &window_rect;
2173 region = gdk_region_rectangle (rect);
2174 gdk_window_invalidate_region (window, region, invalidate_children);
2175 gdk_region_destroy (region);
2179 draw_ugly_color (GdkWindow *window,
2182 /* Draw ugly color all over the newly-invalid region */
2183 GdkColor ugly_color = { 0, 50000, 10000, 10000 };
2185 GdkRectangle clipbox;
2187 ugly_gc = gdk_gc_new (window);
2188 gdk_gc_set_rgb_fg_color (ugly_gc, &ugly_color);
2189 gdk_gc_set_clip_region (ugly_gc, region);
2191 gdk_region_get_clipbox (region, &clipbox);
2193 gdk_draw_rectangle (window,
2196 clipbox.x, clipbox.y,
2197 clipbox.width, clipbox.height);
2199 g_object_unref (ugly_gc);
2203 * gdk_window_invalidate_maybe_recurse:
2204 * @window: a #GdkWindow
2205 * @region: a #GdkRegion
2206 * @child_func: function to use to decide if to recurse to a child,
2207 * %NULL means never recurse.
2208 * @user_data: data passed to @child_func
2210 * Adds @region to the update area for @window. The update area is the
2211 * region that needs to be redrawn, or "dirty region." The call
2212 * gdk_window_process_updates() sends one or more expose events to the
2213 * window, which together cover the entire update area. An
2214 * application would normally redraw the contents of @window in
2215 * response to those expose events.
2217 * GDK will call gdk_window_process_all_updates() on your behalf
2218 * whenever your program returns to the main loop and becomes idle, so
2219 * normally there's no need to do that manually, you just need to
2220 * invalidate regions that you know should be redrawn.
2222 * The @child_func parameter controls whether the region of
2223 * each child window that intersects @region will also be invalidated.
2224 * Only children for which @child_func returns TRUE will have the area
2228 gdk_window_invalidate_maybe_recurse (GdkWindow *window,
2230 gboolean (*child_func) (GdkWindow *, gpointer),
2233 GdkWindowObject *private = (GdkWindowObject *)window;
2234 GdkRegion *visible_region;
2236 g_return_if_fail (window != NULL);
2237 g_return_if_fail (GDK_IS_WINDOW (window));
2239 if (GDK_WINDOW_DESTROYED (window))
2242 if (private->input_only || !GDK_WINDOW_IS_MAPPED (window))
2245 visible_region = gdk_drawable_get_visible_region (window);
2246 gdk_region_intersect (visible_region, region);
2248 if (!gdk_region_empty (visible_region))
2251 draw_ugly_color (window, region);
2253 if (private->update_area)
2255 gdk_region_union (private->update_area, visible_region);
2259 update_windows = g_slist_prepend (update_windows, window);
2260 private->update_area = gdk_region_copy (visible_region);
2262 if (!private->update_freeze_count && !update_idle)
2263 update_idle = g_idle_add_full (GDK_PRIORITY_REDRAW,
2264 gdk_window_update_idle, NULL, NULL);
2271 tmp_list = private->children;
2274 GdkWindowObject *child = tmp_list->data;
2275 tmp_list = tmp_list->next;
2277 if (!child->input_only && (*child_func) ((GdkWindow *)child, user_data))
2279 GdkRegion *child_region;
2282 gdk_window_get_position ((GdkWindow *)child, &x, &y);
2284 /* This copy could be saved with a little more complexity */
2285 child_region = gdk_region_copy (visible_region);
2286 gdk_region_offset (child_region, - x, - y);
2288 gdk_window_invalidate_maybe_recurse ((GdkWindow *)child, child_region, child_func, user_data);
2290 gdk_region_destroy (child_region);
2296 gdk_region_destroy (visible_region);
2300 true_predicate (GdkWindow *window,
2307 * gdk_window_invalidate_region:
2308 * @window: a #GdkWindow
2309 * @region: a #GdkRegion
2310 * @invalidate_children: %TRUE to also invalidate child windows
2312 * Adds @region to the update area for @window. The update area is the
2313 * region that needs to be redrawn, or "dirty region." The call
2314 * gdk_window_process_updates() sends one or more expose events to the
2315 * window, which together cover the entire update area. An
2316 * application would normally redraw the contents of @window in
2317 * response to those expose events.
2319 * GDK will call gdk_window_process_all_updates() on your behalf
2320 * whenever your program returns to the main loop and becomes idle, so
2321 * normally there's no need to do that manually, you just need to
2322 * invalidate regions that you know should be redrawn.
2324 * The @invalidate_children parameter controls whether the region of
2325 * each child window that intersects @region will also be invalidated.
2326 * If %FALSE, then the update area for child windows will remain
2327 * unaffected. See gdk_window_invalidate_maybe_recurse if you need
2328 * fine grained control over which children are invalidated.
2331 gdk_window_invalidate_region (GdkWindow *window,
2333 gboolean invalidate_children)
2335 gdk_window_invalidate_maybe_recurse (window, region,
2336 invalidate_children ?
2337 true_predicate : (gboolean (*) (GdkWindow *, gpointer))NULL,
2342 * gdk_window_get_update_area:
2343 * @window: a #GdkWindow
2345 * Transfers ownership of the update area from @window to the caller
2346 * of the function. That is, after calling this function, @window will
2347 * no longer have an invalid/dirty region; the update area is removed
2348 * from @window and handed to you. If a window has no update area,
2349 * gdk_window_get_update_area() returns %NULL. You are responsible for
2350 * calling gdk_region_destroy() on the returned region if it's non-%NULL.
2352 * Return value: the update area for @window
2355 gdk_window_get_update_area (GdkWindow *window)
2357 GdkWindowObject *private = (GdkWindowObject *)window;
2358 GdkRegion *tmp_region;
2360 g_return_val_if_fail (window != NULL, NULL);
2361 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2363 if (private->update_area)
2365 tmp_region = private->update_area;
2366 private->update_area = NULL;
2368 update_windows = g_slist_remove (update_windows, window);
2377 * _gdk_window_clear_update_area:
2378 * @window: a #GdkWindow.
2380 * Internal function to clear the update area for a window. This
2381 * is called when the window is hidden or destroyed.
2384 _gdk_window_clear_update_area (GdkWindow *window)
2386 GdkWindowObject *private = (GdkWindowObject *)window;
2388 g_return_if_fail (window != NULL);
2389 g_return_if_fail (GDK_IS_WINDOW (window));
2391 if (private->update_area)
2393 update_windows = g_slist_remove (update_windows, window);
2395 gdk_region_destroy (private->update_area);
2396 private->update_area = NULL;
2401 * gdk_window_freeze_updates:
2402 * @window: a #GdkWindow
2404 * Temporarily freezes a window such that it won't receive expose
2405 * events. The window will begin receiving expose events again when
2406 * gdk_window_thaw_updates() is called. If gdk_window_freeze_updates()
2407 * has been called more than once, gdk_window_thaw_updates() must be called
2408 * an equal number of times to begin processing exposes.
2411 gdk_window_freeze_updates (GdkWindow *window)
2413 GdkWindowObject *private = (GdkWindowObject *)window;
2415 g_return_if_fail (window != NULL);
2416 g_return_if_fail (GDK_IS_WINDOW (window));
2418 private->update_freeze_count++;
2422 * gdk_window_thaw_updates:
2423 * @window: a #GdkWindow
2425 * Thaws a window frozen with gdk_window_freeze_updates().
2428 gdk_window_thaw_updates (GdkWindow *window)
2430 GdkWindowObject *private = (GdkWindowObject *)window;
2432 g_return_if_fail (window != NULL);
2433 g_return_if_fail (GDK_IS_WINDOW (window));
2434 g_return_if_fail (private->update_freeze_count > 0);
2436 private->update_freeze_count--;
2437 if (!private->update_freeze_count && private->update_area && !update_idle)
2438 update_idle = g_idle_add_full (GDK_PRIORITY_REDRAW,
2439 gdk_window_update_idle, NULL, NULL);
2443 * gdk_window_set_debug_updates:
2444 * @setting: %TRUE to turn on update debugging
2446 * With update debugging enabled, calls to
2447 * gdk_window_invalidate_region() clear the invalidated region of the
2448 * screen to a noticeable color, and GDK pauses for a short time
2449 * before sending exposes to windows during
2450 * gdk_window_process_updates(). The net effect is that you can see
2451 * the invalid region for each window and watch redraws as they
2452 * occur. This allows you to diagnose inefficiencies in your application.
2454 * In essence, because the GDK rendering model prevents all flicker,
2455 * if you are redrawing the same region 400 times you may never
2456 * notice, aside from noticing a speed problem. Enabling update
2457 * debugging causes GTK to flicker slowly and noticeably, so you can
2458 * see exactly what's being redrawn when, in what order.
2460 * The --gtk-debug=updates command line option passed to GTK+ programs
2461 * enables this debug option at application startup time. That's
2462 * usually more useful than calling gdk_window_set_debug_updates()
2463 * yourself, though you might want to use this function to enable
2464 * updates sometime after application startup time.
2468 gdk_window_set_debug_updates (gboolean setting)
2470 debug_updates = setting;
2474 * gdk_window_constrain_size:
2475 * @geometry: a #GdkGeometry structure
2476 * @flags: a mask indicating what portions of @geometry are set
2477 * @width: desired width of window
2478 * @height: desired height of the window
2479 * @new_width: location to store resulting width
2480 * @new_height: location to store resulting height
2482 * Constrains a desired width and height according to a
2483 * set of geometry hints (such as minimum and maximum size).
2486 gdk_window_constrain_size (GdkGeometry *geometry,
2493 /* This routine is partially borrowed from fvwm.
2495 * Copyright 1993, Robert Nation
2496 * You may use this code for any purpose, as long as the original
2497 * copyright remains in the source code and all documentation
2499 * which in turn borrows parts of the algorithm from uwm
2502 gint min_height = 0;
2503 gint base_width = 0;
2504 gint base_height = 0;
2507 gint max_width = G_MAXINT;
2508 gint max_height = G_MAXINT;
2510 #define FLOOR(value, base) ( ((gint) ((value) / (base))) * (base) )
2512 if ((flags & GDK_HINT_BASE_SIZE) && (flags & GDK_HINT_MIN_SIZE))
2514 base_width = geometry->base_width;
2515 base_height = geometry->base_height;
2516 min_width = geometry->min_width;
2517 min_height = geometry->min_height;
2519 else if (flags & GDK_HINT_BASE_SIZE)
2521 base_width = geometry->base_width;
2522 base_height = geometry->base_height;
2523 min_width = geometry->base_width;
2524 min_height = geometry->base_height;
2526 else if (flags & GDK_HINT_MIN_SIZE)
2528 base_width = geometry->min_width;
2529 base_height = geometry->min_height;
2530 min_width = geometry->min_width;
2531 min_height = geometry->min_height;
2534 if (flags & GDK_HINT_MAX_SIZE)
2536 max_width = geometry->max_width ;
2537 max_height = geometry->max_height;
2540 if (flags & GDK_HINT_RESIZE_INC)
2542 xinc = MAX (xinc, geometry->width_inc);
2543 yinc = MAX (yinc, geometry->height_inc);
2546 /* clamp width and height to min and max values
2548 width = CLAMP (width, min_width, max_width);
2549 height = CLAMP (height, min_height, max_height);
2551 /* shrink to base + N * inc
2553 width = base_width + FLOOR (width - base_width, xinc);
2554 height = base_height + FLOOR (height - base_height, yinc);
2556 /* constrain aspect ratio, according to:
2559 * min_aspect <= -------- <= max_aspect
2563 if (flags & GDK_HINT_ASPECT &&
2564 geometry->min_aspect > 0 &&
2565 geometry->max_aspect > 0)
2569 if (geometry->min_aspect * height > width)
2571 delta = FLOOR (height - width / geometry->min_aspect, yinc);
2572 if (height - delta >= min_height)
2576 delta = FLOOR (height * geometry->min_aspect - width, xinc);
2577 if (width + delta <= max_width)
2582 if (geometry->max_aspect * height < width)
2584 delta = FLOOR (width - height * geometry->max_aspect, xinc);
2585 if (width - delta >= min_width)
2589 delta = FLOOR (width / geometry->max_aspect - height, yinc);
2590 if (height + delta <= max_height)
2599 *new_height = height;
2603 * gdk_window_get_pointer:
2604 * @window: a #GdkWindow
2605 * @x: return location for X coordinate of pointer
2606 * @y: return location for Y coordinate of pointer
2607 * @mask: return location for modifier mask
2609 * Obtains the current pointer position and modifier state.
2610 * The position is given in coordinates relative to @window.
2612 * Return value: the window containing the pointer (as with
2613 * gdk_window_at_pointer()), or %NULL if the window containing the
2614 * pointer isn't known to GDK
2617 gdk_window_get_pointer (GdkWindow *window,
2620 GdkModifierType *mask)
2622 GdkDisplay *display;
2624 GdkModifierType tmp_mask;
2627 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
2631 display = gdk_drawable_get_display (window);
2635 GdkScreen *screen = gdk_screen_get_default ();
2637 display = gdk_screen_get_display (screen);
2638 window = gdk_screen_get_root_window (screen);
2640 GDK_NOTE (MULTIHEAD,
2641 g_message ("Passing NULL for window to gdk_window_get_pointer()\n"
2642 "is not multihead safe"));
2645 child = display->pointer_hooks->window_get_pointer (display, window, &tmp_x, &tmp_y, &tmp_mask);
2658 * gdk_window_at_pointer:
2659 * @win_x: return location for origin of the window under the pointer
2660 * @win_y: return location for origin of the window under the pointer
2662 * Obtains the window underneath the mouse pointer, returning the
2663 * location of that window in @win_x, @win_y. Returns %NULL if the
2664 * window under the mouse pointer is not known to GDK (if the window
2665 * belongs to another application and a #GdkWindow hasn't been created
2666 * for it with gdk_window_foreign_new())
2668 * NOTE: For multihead-aware widgets or applications use
2669 * gdk_display_get_window_at_pointer() instead.
2671 * Return value: window under the mouse pointer
2674 gdk_window_at_pointer (gint *win_x,
2677 return gdk_display_get_window_at_pointer (gdk_display_get_default (), win_x, win_y);
2681 * gdk_get_default_root_window:
2683 * Obtains the root window (parent all other windows are inside)
2684 * for the default display and screen.
2686 * Return value: the default root window
2689 gdk_get_default_root_window (void)
2691 return gdk_screen_get_root_window (gdk_screen_get_default ());
2695 * gdk_window_foreign_new:
2696 * @anid: a native window handle.
2698 * Wraps a native window for the default display in a #GdkWindow.
2699 * This may fail if the window has been destroyed.
2701 * For example in the X backend, a native window handle is an Xlib
2704 * Return value: the newly-created #GdkWindow wrapper for the
2705 * native window or %NULL if the window has been destroyed.
2708 gdk_window_foreign_new (GdkNativeWindow anid)
2710 return gdk_window_foreign_new_for_display (gdk_display_get_default (), anid);