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"
37 #define USE_BACKING_STORE /* Appears to work on Win32, too, now. */
39 typedef struct _GdkWindowPaint GdkWindowPaint;
41 struct _GdkWindowPaint
49 static GdkGC *gdk_window_create_gc (GdkDrawable *drawable,
51 GdkGCValuesMask mask);
52 static void gdk_window_draw_rectangle (GdkDrawable *drawable,
59 static void gdk_window_draw_arc (GdkDrawable *drawable,
68 static void gdk_window_draw_polygon (GdkDrawable *drawable,
73 static void gdk_window_draw_text (GdkDrawable *drawable,
80 static void gdk_window_draw_text_wc (GdkDrawable *drawable,
87 static void gdk_window_draw_drawable (GdkDrawable *drawable,
96 static void gdk_window_draw_points (GdkDrawable *drawable,
100 static void gdk_window_draw_segments (GdkDrawable *drawable,
104 static void gdk_window_draw_lines (GdkDrawable *drawable,
109 static void gdk_window_draw_glyphs (GdkDrawable *drawable,
114 PangoGlyphString *glyphs);
115 static void gdk_window_draw_glyphs_transformed (GdkDrawable *drawable,
121 PangoGlyphString *glyphs);
123 static void gdk_window_draw_image (GdkDrawable *drawable,
133 static void gdk_window_draw_pixbuf (GdkDrawable *drawable,
146 static void gdk_window_draw_trapezoids (GdkDrawable *drawable,
148 GdkTrapezoid *trapezoids,
151 static GdkImage* gdk_window_copy_to_image (GdkDrawable *drawable,
160 static void gdk_window_set_cairo_target (GdkDrawable *drawable,
163 static void gdk_window_real_get_size (GdkDrawable *drawable,
167 static GdkVisual* gdk_window_real_get_visual (GdkDrawable *drawable);
168 static gint gdk_window_real_get_depth (GdkDrawable *drawable);
169 static GdkScreen* gdk_window_real_get_screen (GdkDrawable *drawable);
170 static void gdk_window_real_set_colormap (GdkDrawable *drawable,
172 static GdkColormap* gdk_window_real_get_colormap (GdkDrawable *drawable);
174 static GdkDrawable* gdk_window_get_composite_drawable (GdkDrawable *drawable,
179 gint *composite_x_offset,
180 gint *composite_y_offset);
181 static GdkRegion* gdk_window_get_clip_region (GdkDrawable *drawable);
182 static GdkRegion* gdk_window_get_visible_region (GdkDrawable *drawable);
184 static void gdk_window_free_paint_stack (GdkWindow *window);
186 static void gdk_window_init (GdkWindowObject *window);
187 static void gdk_window_class_init (GdkWindowObjectClass *klass);
188 static void gdk_window_finalize (GObject *object);
189 static void gdk_window_clear_backing_rect (GdkWindow *window,
195 static gpointer parent_class = NULL;
198 gdk_window_object_get_type (void)
200 static GType object_type = 0;
204 static const GTypeInfo object_info =
206 sizeof (GdkWindowObjectClass),
207 (GBaseInitFunc) NULL,
208 (GBaseFinalizeFunc) NULL,
209 (GClassInitFunc) gdk_window_class_init,
210 NULL, /* class_finalize */
211 NULL, /* class_data */
212 sizeof (GdkWindowObject),
214 (GInstanceInitFunc) gdk_window_init,
217 object_type = g_type_register_static (GDK_TYPE_DRAWABLE,
226 gdk_window_init (GdkWindowObject *window)
228 /* 0-initialization is good for all other fields. */
230 window->window_type = GDK_WINDOW_CHILD;
232 window->state = GDK_WINDOW_STATE_WITHDRAWN;
234 window->impl = g_object_new (_gdk_window_impl_get_type (), NULL);
238 gdk_window_class_init (GdkWindowObjectClass *klass)
240 GObjectClass *object_class = G_OBJECT_CLASS (klass);
241 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
243 parent_class = g_type_class_peek_parent (klass);
245 object_class->finalize = gdk_window_finalize;
247 drawable_class->create_gc = gdk_window_create_gc;
248 drawable_class->draw_rectangle = gdk_window_draw_rectangle;
249 drawable_class->draw_arc = gdk_window_draw_arc;
250 drawable_class->draw_polygon = gdk_window_draw_polygon;
251 drawable_class->draw_text = gdk_window_draw_text;
252 drawable_class->draw_text_wc = gdk_window_draw_text_wc;
253 drawable_class->draw_drawable = gdk_window_draw_drawable;
254 drawable_class->draw_points = gdk_window_draw_points;
255 drawable_class->draw_segments = gdk_window_draw_segments;
256 drawable_class->draw_lines = gdk_window_draw_lines;
257 drawable_class->draw_glyphs = gdk_window_draw_glyphs;
258 drawable_class->draw_glyphs_transformed = gdk_window_draw_glyphs_transformed;
259 drawable_class->draw_image = gdk_window_draw_image;
260 drawable_class->draw_pixbuf = gdk_window_draw_pixbuf;
261 drawable_class->draw_trapezoids = gdk_window_draw_trapezoids;
262 drawable_class->get_depth = gdk_window_real_get_depth;
263 drawable_class->get_screen = gdk_window_real_get_screen;
264 drawable_class->get_size = gdk_window_real_get_size;
265 drawable_class->set_colormap = gdk_window_real_set_colormap;
266 drawable_class->get_colormap = gdk_window_real_get_colormap;
267 drawable_class->get_visual = gdk_window_real_get_visual;
268 drawable_class->_copy_to_image = gdk_window_copy_to_image;
269 drawable_class->set_cairo_target = gdk_window_set_cairo_target;
270 drawable_class->get_clip_region = gdk_window_get_clip_region;
271 drawable_class->get_visible_region = gdk_window_get_visible_region;
272 drawable_class->get_composite_drawable = gdk_window_get_composite_drawable;
276 gdk_window_finalize (GObject *object)
278 GdkWindow *window = GDK_WINDOW (object);
279 GdkWindowObject *obj = (GdkWindowObject *) object;
281 if (!GDK_WINDOW_DESTROYED (window))
283 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
285 g_warning ("losing last reference to undestroyed window\n");
286 _gdk_window_destroy (window, FALSE);
289 /* We use TRUE here, to keep us from actually calling
290 * XDestroyWindow() on the window
292 _gdk_window_destroy (window, TRUE);
295 g_object_unref (obj->impl);
298 G_OBJECT_CLASS (parent_class)->finalize (object);
302 window_remove_filters (GdkWindow *window)
304 GdkWindowObject *obj = (GdkWindowObject*) window;
310 for (tmp_list = obj->filters; tmp_list; tmp_list = tmp_list->next)
311 g_free (tmp_list->data);
313 g_list_free (obj->filters);
319 * _gdk_window_destroy_hierarchy:
320 * @window: a #GdkWindow
321 * @recursing: If TRUE, then this is being called because a parent
322 * was destroyed. This generally means that the call to the
323 * windowing system to destroy the window can be omitted, since
324 * it will be destroyed as a result of the parent being destroyed.
325 * Unless @foreign_destroy.
326 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
327 * external agency. The window has already been destroyed and no
328 * windowing system calls should be made. (This may never happen
329 * for some windowing systems.)
331 * Internal function to destroy a window. Like gdk_window_destroy(),
332 * but does not drop the reference count created by gdk_window_new().
335 _gdk_window_destroy_hierarchy (GdkWindow *window,
337 gboolean foreign_destroy)
339 GdkWindowObject *private;
340 GdkWindowObject *temp_private;
341 GdkWindow *temp_window;
345 g_return_if_fail (window != NULL);
347 private = (GdkWindowObject*) window;
349 if (GDK_WINDOW_DESTROYED (window))
352 switch (GDK_WINDOW_TYPE (window))
354 case GDK_WINDOW_TOPLEVEL:
355 case GDK_WINDOW_CHILD:
356 case GDK_WINDOW_DIALOG:
357 case GDK_WINDOW_TEMP:
358 case GDK_WINDOW_FOREIGN:
359 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_FOREIGN && !foreign_destroy)
361 /* Logically, it probably makes more sense to send
362 * a "destroy yourself" message to the foreign window
363 * whether or not it's in our heirarchy; but for historical
364 * reasons, we only send "destroy yourself" messages to
365 * foreign windows in our heirarchy.
368 _gdk_windowing_window_destroy_foreign (window);
370 /* Also for historical reasons, we remove any filters
371 * on a foreign window when it or a parent is destroyed;
372 * this likely causes problems if two separate portions
373 * of code are maintaining filter lists on a foreign window.
375 window_remove_filters (window);
379 private->state |= GDK_WINDOW_STATE_WITHDRAWN;
383 GdkWindowObject *parent_private = (GdkWindowObject *)private->parent;
384 if (parent_private->children)
385 parent_private->children = g_list_remove (parent_private->children, window);
388 _gdk_window_clear_update_area (window);
389 gdk_window_free_paint_stack (window);
391 if (private->bg_pixmap &&
392 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
393 private->bg_pixmap != GDK_NO_BG)
395 g_object_unref (private->bg_pixmap);
396 private->bg_pixmap = NULL;
399 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_FOREIGN)
400 g_assert (private->children == NULL);
403 children = tmp = private->children;
404 private->children = NULL;
408 temp_window = tmp->data;
411 temp_private = (GdkWindowObject*) temp_window;
413 _gdk_window_destroy_hierarchy (temp_window,
414 TRUE, foreign_destroy);
417 g_list_free (children);
420 _gdk_windowing_window_destroy (window, recursing, foreign_destroy);
421 private->parent = NULL;
422 private->destroyed = TRUE;
424 window_remove_filters (window);
426 gdk_drawable_set_colormap (GDK_DRAWABLE (window), NULL);
430 case GDK_WINDOW_ROOT:
431 g_error ("attempted to destroy root window");
437 * _gdk_window_destroy:
438 * @window: a #GdkWindow
439 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
440 * external agency. The window has already been destroyed and no
441 * windowing system calls should be made. (This may never happen
442 * for some windowing systems.)
444 * Internal function to destroy a window. Like gdk_window_destroy(),
445 * but does not drop the reference count created by gdk_window_new().
448 _gdk_window_destroy (GdkWindow *window,
449 gboolean foreign_destroy)
451 _gdk_window_destroy_hierarchy (window, FALSE, foreign_destroy);
455 * gdk_window_destroy:
456 * @window: a #GdkWindow
458 * Destroys the window system resources associated with @window and decrements @window's
459 * reference count. The window system resources for all children of @window are also
460 * destroyed, but the children's reference counts are not decremented.
462 * Note that a window will not be destroyed automatically when its reference count
463 * reaches zero. You must call this function yourself before that happens.
467 gdk_window_destroy (GdkWindow *window)
469 _gdk_window_destroy_hierarchy (window, FALSE, FALSE);
470 g_object_unref (window);
474 * gdk_window_set_user_data:
475 * @window: a #GdkWindow
476 * @user_data: user data
478 * For most purposes this function is deprecated in favor of
479 * g_object_set_data(). However, for historical reasons GTK+ stores
480 * the #GtkWidget that owns a #GdkWindow as user data on the
481 * #GdkWindow. So, custom widget implementations should use
482 * this function for that. If GTK+ receives an event for a #GdkWindow,
483 * and the user data for the window is non-%NULL, GTK+ will assume the
484 * user data is a #GtkWidget, and forward the event to that widget.
488 gdk_window_set_user_data (GdkWindow *window,
491 g_return_if_fail (window != NULL);
493 ((GdkWindowObject*)window)->user_data = user_data;
497 * gdk_window_get_user_data:
498 * @window: a #GdkWindow
499 * @data: return location for user data
501 * Retrieves the user data for @window, which is normally the widget
502 * that @window belongs to. See gdk_window_set_user_data().
506 gdk_window_get_user_data (GdkWindow *window,
509 g_return_if_fail (window != NULL);
511 *data = ((GdkWindowObject*)window)->user_data;
515 * gdk_window_get_window_type:
516 * @window: a #GdkWindow
518 * Gets the type of the window. See #GdkWindowType.
520 * Return value: type of window
523 gdk_window_get_window_type (GdkWindow *window)
525 g_return_val_if_fail (GDK_IS_WINDOW (window), (GdkWindowType) -1);
527 return GDK_WINDOW_TYPE (window);
531 * gdk_window_get_position:
532 * @window: a #GdkWindow
533 * @x: X coordinate of window
534 * @y: Y coordinate of window
536 * Obtains the position of the window as reported in the
537 * most-recently-processed #GdkEventConfigure. Contrast with
538 * gdk_window_get_geometry() which queries the X server for the
539 * current window position, regardless of which events have been
540 * received or processed.
542 * The position coordinates are relative to the window's parent window.
546 gdk_window_get_position (GdkWindow *window,
550 GdkWindowObject *obj;
552 g_return_if_fail (GDK_IS_WINDOW (window));
554 obj = (GdkWindowObject*) window;
563 * gdk_window_get_parent:
564 * @window: a #GdkWindow
566 * Obtains the parent of @window, as known to GDK. Does not query the
567 * X server; thus this returns the parent as passed to gdk_window_new(),
568 * not the actual parent. This should never matter unless you're using
569 * Xlib calls mixed with GDK calls on the X11 platform. It may also
570 * matter for toplevel windows, because the window manager may choose
573 * Return value: parent of @window
576 gdk_window_get_parent (GdkWindow *window)
578 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
580 return (GdkWindow*) ((GdkWindowObject*) window)->parent;
584 * gdk_window_get_toplevel:
585 * @window: a #GdkWindow
587 * Gets the toplevel window that's an ancestor of @window.
589 * Return value: the toplevel window containing @window
592 gdk_window_get_toplevel (GdkWindow *window)
594 GdkWindowObject *obj;
596 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
598 obj = (GdkWindowObject *)window;
599 while (GDK_WINDOW_TYPE (obj) == GDK_WINDOW_CHILD)
600 obj = (GdkWindowObject *)obj->parent;
602 return GDK_WINDOW (obj);
606 * gdk_window_get_children:
607 * @window: a #GdkWindow
609 * Gets the list of children of @window known to GDK.
610 * This function only returns children created via GDK,
611 * so for example it's useless when used with the root window;
612 * it only returns windows an application created itself.
614 * The returned list must be freed, but the elements in the
617 * Return value: list of child windows inside @window
620 gdk_window_get_children (GdkWindow *window)
622 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
624 if (GDK_WINDOW_DESTROYED (window))
627 return g_list_copy (GDK_WINDOW_OBJECT (window)->children);
631 * gdk_window_peek_children:
632 * @window: a #GdkWindow
634 * Like gdk_window_get_children(), but does not copy the list of
635 * children, so the list does not need to be freed.
637 * Return value: a reference to the list of child windows in @window
640 gdk_window_peek_children (GdkWindow *window)
642 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
644 if (GDK_WINDOW_DESTROYED (window))
647 return GDK_WINDOW_OBJECT (window)->children;
651 * gdk_window_add_filter:
652 * @window: a #GdkWindow
653 * @function: filter callback
654 * @data: data to pass to filter callback
656 * Adds an event filter to @window, allowing you to intercept events
657 * before they reach GDK. This is a low-level operation and makes it
658 * easy to break GDK and/or GTK+, so you have to know what you're
659 * doing. Pass %NULL for @window to get all events for all windows,
660 * instead of events for a specific window.
664 gdk_window_add_filter (GdkWindow *window,
665 GdkFilterFunc function,
668 GdkWindowObject *private;
670 GdkEventFilter *filter;
672 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
674 private = (GdkWindowObject*) window;
675 if (private && GDK_WINDOW_DESTROYED (window))
679 tmp_list = private->filters;
681 tmp_list = _gdk_default_filters;
685 filter = (GdkEventFilter *)tmp_list->data;
686 if ((filter->function == function) && (filter->data == data))
688 tmp_list = tmp_list->next;
691 filter = g_new (GdkEventFilter, 1);
692 filter->function = function;
696 private->filters = g_list_append (private->filters, filter);
698 _gdk_default_filters = g_list_append (_gdk_default_filters, filter);
702 * gdk_window_remove_filter:
703 * @window: a #GdkWindow
704 * @function: previously-added filter function
705 * @data: user data for previously-added filter function
707 * Remove a filter previously added with gdk_window_add_filter().
711 gdk_window_remove_filter (GdkWindow *window,
712 GdkFilterFunc function,
715 GdkWindowObject *private;
716 GList *tmp_list, *node;
717 GdkEventFilter *filter;
719 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
721 private = (GdkWindowObject*) window;
724 tmp_list = private->filters;
726 tmp_list = _gdk_default_filters;
730 filter = (GdkEventFilter *)tmp_list->data;
732 tmp_list = tmp_list->next;
734 if ((filter->function == function) && (filter->data == data))
737 private->filters = g_list_remove_link (private->filters, node);
739 _gdk_default_filters = g_list_remove_link (_gdk_default_filters, node);
740 g_list_free_1 (node);
749 * gdk_screen_get_toplevel_windows:
750 * @screen: The #GdkScreen where the toplevels are located.
752 * Obtains a list of all toplevel windows known to GDK on the screen @screen.
753 * A toplevel window is a child of the root window (see
754 * gdk_get_default_root_window()).
756 * The returned list should be freed with g_list_free(), but
757 * its elements need not be freed.
759 * Return value: list of toplevel windows, free with g_list_free()
764 gdk_screen_get_toplevel_windows (GdkScreen *screen)
766 GdkWindow * root_window;
767 GList *new_list = NULL;
770 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
772 root_window = gdk_screen_get_root_window (screen);
774 tmp_list = ((GdkWindowObject *)root_window)->children;
777 if (GDK_WINDOW_TYPE (tmp_list->data) != GDK_WINDOW_FOREIGN)
778 new_list = g_list_prepend (new_list, tmp_list->data);
779 tmp_list = tmp_list->next;
786 * gdk_window_get_toplevels:
788 * Obtains a list of all toplevel windows known to GDK on the default
789 * screen (see gdk_window_get_toplevels_for_screen()).
790 * A toplevel window is a child of the root window (see
791 * gdk_get_default_root_window()).
793 * The returned list should be freed with g_list_free(), but
794 * its elements need not be freed.
796 * Return value: list of toplevel windows, free with g_list_free()
799 gdk_window_get_toplevels (void)
801 return gdk_screen_get_toplevel_windows (gdk_screen_get_default ());
805 * gdk_window_is_visible:
806 * @window: a #GdkWindow
808 * Checks whether the window has been mapped (with gdk_window_show() or
809 * gdk_window_show_unraised()).
811 * Return value: %TRUE if the window is mapped
814 gdk_window_is_visible (GdkWindow *window)
816 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
818 return GDK_WINDOW_IS_MAPPED (window);
822 * gdk_window_is_viewable:
823 * @window: a #GdkWindow
825 * Check if the window and all ancestors of the window are
826 * mapped. (This is not necessarily "viewable" in the X sense, since
827 * we only check as far as we have GDK window parents, not to the root
830 * Return value: %TRUE if the window is viewable
833 gdk_window_is_viewable (GdkWindow *window)
835 GdkWindowObject *private = (GdkWindowObject *)window;
837 GdkWindow *root_window;
839 g_return_val_if_fail (window != NULL, FALSE);
840 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
842 screen = gdk_drawable_get_screen (window);
843 root_window = gdk_screen_get_root_window (screen);
846 (private != (GdkWindowObject *)root_window) &&
847 (GDK_WINDOW_TYPE (private) != GDK_WINDOW_FOREIGN))
849 if (GDK_WINDOW_DESTROYED (private) || !GDK_WINDOW_IS_MAPPED (private))
852 private = (GdkWindowObject *)private->parent;
859 * gdk_window_get_state:
860 * @window: a #GdkWindow
862 * Gets the bitwise OR of the currently active window state flags,
863 * from the #GdkWindowState enumeration.
865 * Return value: window state bitfield
868 gdk_window_get_state (GdkWindow *window)
870 GdkWindowObject *private = (GdkWindowObject *)window;
872 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
874 return private->state;
878 * gdk_window_begin_paint_rect:
879 * @window: a #GdkWindow
880 * @rectangle: rectangle you intend to draw to
882 * A convenience wrapper around gdk_window_begin_paint_region() which
883 * creates a rectangular region for you. See
884 * gdk_window_begin_paint_region() for details.
888 gdk_window_begin_paint_rect (GdkWindow *window,
889 GdkRectangle *rectangle)
893 g_return_if_fail (window != NULL);
894 g_return_if_fail (GDK_IS_WINDOW (window));
896 region = gdk_region_rectangle (rectangle);
897 gdk_window_begin_paint_region (window, region);
898 gdk_region_destroy (region);
901 #ifdef GDK_WINDOWING_X11
902 #include "x11/gdkx.h"
906 * gdk_window_begin_paint_region:
907 * @window: a #GdkWindow
908 * @region: region you intend to draw to
910 * Indicates that you are beginning the process of redrawing @region.
911 * A backing store (offscreen buffer) large enough to contain @region
912 * will be created. The backing store will be initialized with the
913 * background color or background pixmap for @window. Then, all
914 * drawing operations performed on @window will be diverted to the
915 * backing store. When you call gdk_window_end_paint(), the backing
916 * store will be copied to @window, making it visible onscreen. Only
917 * the part of @window contained in @region will be modified; that is,
918 * drawing operations are clipped to @region.
920 * The net result of all this is to remove flicker, because the user
921 * sees the finished product appear all at once when you call
922 * gdk_window_end_paint(). If you draw to @window directly without
923 * calling gdk_window_begin_paint_region(), the user may see flicker
924 * as individual drawing operations are performed in sequence. The
925 * clipping and background-initializing features of
926 * gdk_window_begin_paint_region() are conveniences for the
927 * programmer, so you can avoid doing that work yourself.
929 * When using GTK+, the widget system automatically places calls to
930 * gdk_window_begin_paint_region() and gdk_window_end_paint() around
931 * emissions of the expose_event signal. That is, if you're writing an
932 * expose event handler, you can assume that the exposed area in
933 * #GdkEventExpose has already been cleared to the window background,
934 * is already set as the clip region, and already has a backing store.
935 * Therefore in most cases, application code need not call
936 * gdk_window_begin_paint_region(). (You can disable the automatic
937 * calls around expose events on a widget-by-widget basis by calling
938 * gtk_widget_set_double_buffered().)
940 * If you call this function multiple times before calling the
941 * matching gdk_window_end_paint(), the backing stores are pushed onto
942 * a stack. gdk_window_end_paint() copies the topmost backing store
943 * onscreen, subtracts the topmost region from all other regions in
944 * the stack, and pops the stack. All drawing operations affect only
945 * the topmost backing store in the stack. One matching call to
946 * gdk_window_end_paint() is required for each call to
947 * gdk_window_begin_paint_region().
951 gdk_window_begin_paint_region (GdkWindow *window,
954 #ifdef USE_BACKING_STORE
955 GdkWindowObject *private = (GdkWindowObject *)window;
956 GdkRectangle clip_box;
957 GdkWindowPaint *paint;
960 g_return_if_fail (window != NULL);
961 g_return_if_fail (GDK_IS_WINDOW (window));
963 if (GDK_WINDOW_DESTROYED (window))
966 gdk_region_get_clipbox (region, &clip_box);
968 paint = g_new (GdkWindowPaint, 1);
969 paint->region = gdk_region_copy (region);
970 paint->x_offset = clip_box.x;
971 paint->y_offset = clip_box.y;
973 gdk_pixmap_new (window,
974 MAX (clip_box.width, 1), MAX (clip_box.height, 1), -1);
976 for (list = private->paint_stack; list != NULL; list = list->next)
978 GdkWindowPaint *tmp_paint = list->data;
980 gdk_region_subtract (tmp_paint->region, paint->region);
983 private->paint_stack = g_slist_prepend (private->paint_stack, paint);
985 if (!gdk_region_empty (region))
987 gdk_window_clear_backing_rect (window,
988 clip_box.x, clip_box.y,
989 clip_box.width, clip_box.height);
991 #endif /* USE_BACKING_STORE */
995 * gdk_window_end_paint:
996 * @window: a #GdkWindow
998 * Indicates that the backing store created by the most recent call to
999 * gdk_window_begin_paint_region() should be copied onscreen and
1000 * deleted, leaving the next-most-recent backing store or no backing
1001 * store at all as the active paint region. See
1002 * gdk_window_begin_paint_region() for full details. It is an error to
1003 * call this function without a matching
1004 * gdk_window_begin_paint_region() first.
1008 gdk_window_end_paint (GdkWindow *window)
1010 #ifdef USE_BACKING_STORE
1011 GdkWindowObject *private = (GdkWindowObject *)window;
1012 GdkWindowPaint *paint;
1014 GdkRectangle clip_box;
1015 gint x_offset, y_offset;
1017 g_return_if_fail (window != NULL);
1018 g_return_if_fail (GDK_IS_WINDOW (window));
1020 if (GDK_WINDOW_DESTROYED (window))
1023 if (private->paint_stack == NULL)
1025 g_warning (G_STRLOC": no preceding call to gdk_window_begin_paint_region(), see documentation");
1029 paint = private->paint_stack->data;
1030 private->paint_stack = g_slist_delete_link (private->paint_stack,
1031 private->paint_stack);
1033 gdk_region_get_clipbox (paint->region, &clip_box);
1035 tmp_gc = _gdk_drawable_get_scratch_gc (window, FALSE);
1037 _gdk_windowing_window_get_offsets (window, &x_offset, &y_offset);
1039 gdk_gc_set_clip_region (tmp_gc, paint->region);
1040 gdk_gc_set_clip_origin (tmp_gc, - x_offset, - y_offset);
1042 gdk_draw_drawable (private->impl, tmp_gc, paint->pixmap,
1043 clip_box.x - paint->x_offset,
1044 clip_box.y - paint->y_offset,
1045 clip_box.x - x_offset, clip_box.y - y_offset,
1046 clip_box.width, clip_box.height);
1048 /* Reset clip region of the cached GdkGC */
1049 gdk_gc_set_clip_region (tmp_gc, NULL);
1051 g_object_unref (paint->pixmap);
1052 gdk_region_destroy (paint->region);
1054 #endif /* USE_BACKING_STORE */
1058 gdk_window_free_paint_stack (GdkWindow *window)
1060 GdkWindowObject *private = (GdkWindowObject *)window;
1062 if (private->paint_stack)
1064 GSList *tmp_list = private->paint_stack;
1068 GdkWindowPaint *paint = tmp_list->data;
1070 if (tmp_list == private->paint_stack)
1071 g_object_unref (paint->pixmap);
1073 gdk_region_destroy (paint->region);
1076 tmp_list = tmp_list->next;
1079 g_slist_free (private->paint_stack);
1080 private->paint_stack = NULL;
1085 gdk_window_get_offsets (GdkWindow *window,
1089 GdkWindowObject *private = (GdkWindowObject *)window;
1091 if (private->paint_stack)
1093 GdkWindowPaint *paint = private->paint_stack->data;
1094 *x_offset = paint->x_offset;
1095 *y_offset = paint->y_offset;
1098 _gdk_windowing_window_get_offsets (window, x_offset, y_offset);
1102 * gdk_window_get_internal_paint_info:
1103 * @window: a #GdkWindow
1104 * @real_drawable: location to store the drawable to which drawing should be
1106 * @x_offset: location to store the X offset between coordinates in @window,
1107 * and the underlying window system primitive coordinates for
1109 * @y_offset: location to store the Y offset between coordinates in @window,
1110 * and the underlying window system primitive coordinates for
1113 * If you bypass the GDK layer and use windowing system primitives to
1114 * draw directly onto a #GdkWindow, then you need to deal with two
1115 * details: there may be an offset between GDK coordinates and windowing
1116 * system coordinates, and GDK may have redirected drawing to a offscreen
1117 * pixmap as the result of a gdk_window_begin_paint_region() calls.
1118 * This function allows retrieving the information you need to compensate
1119 * for these effects.
1121 * This function exposes details of the GDK implementation, and is thus
1122 * likely to change in future releases of GDK.
1125 gdk_window_get_internal_paint_info (GdkWindow *window,
1126 GdkDrawable **real_drawable,
1132 GdkWindowObject *private;
1134 g_return_if_fail (GDK_IS_WINDOW (window));
1136 private = (GdkWindowObject *)window;
1140 if (private->paint_stack)
1142 GdkWindowPaint *paint = private->paint_stack->data;
1143 *real_drawable = paint->pixmap;
1146 *real_drawable = window;
1149 gdk_window_get_offsets (window, &x_off, &y_off);
1157 #define OFFSET_GC(gc) \
1158 gint x_offset, y_offset; \
1159 gint old_clip_x = gc->clip_x_origin; \
1160 gint old_clip_y = gc->clip_y_origin; \
1161 gint old_ts_x = gc->ts_x_origin; \
1162 gint old_ts_y = gc->ts_y_origin; \
1163 gdk_window_get_offsets (drawable, &x_offset, &y_offset); \
1164 if (x_offset != 0 || y_offset != 0) \
1166 gdk_gc_set_clip_origin (gc, old_clip_x - x_offset, \
1167 old_clip_y - y_offset); \
1168 gdk_gc_set_ts_origin (gc, old_ts_x - x_offset, \
1169 old_ts_y - y_offset); \
1172 #define RESTORE_GC(gc) \
1173 if (x_offset != 0 || y_offset != 0) \
1175 gdk_gc_set_clip_origin (gc, old_clip_x, old_clip_y); \
1176 gdk_gc_set_ts_origin (gc, old_ts_x, old_ts_y); \
1180 gdk_window_create_gc (GdkDrawable *drawable,
1181 GdkGCValues *values,
1182 GdkGCValuesMask mask)
1184 g_return_val_if_fail (GDK_IS_WINDOW (drawable), NULL);
1186 if (GDK_WINDOW_DESTROYED (drawable))
1189 return gdk_gc_new_with_values (((GdkWindowObject *) drawable)->impl,
1194 gdk_window_draw_rectangle (GdkDrawable *drawable,
1202 GdkWindowObject *private = (GdkWindowObject *)drawable;
1205 if (GDK_WINDOW_DESTROYED (drawable))
1208 if (private->paint_stack)
1210 GdkWindowPaint *paint = private->paint_stack->data;
1211 gdk_draw_rectangle (paint->pixmap, gc, filled,
1212 x - x_offset, y - y_offset, width, height);
1215 gdk_draw_rectangle (private->impl, gc, filled,
1216 x - x_offset, y - y_offset, width, height);
1222 gdk_window_draw_arc (GdkDrawable *drawable,
1232 GdkWindowObject *private = (GdkWindowObject *)drawable;
1235 if (GDK_WINDOW_DESTROYED (drawable))
1238 if (private->paint_stack)
1240 GdkWindowPaint *paint = private->paint_stack->data;
1241 gdk_draw_arc (paint->pixmap, gc, filled,
1242 x - x_offset, y - y_offset,
1243 width, height, angle1, angle2);
1246 gdk_draw_arc (private->impl, gc, filled,
1247 x - x_offset, y - y_offset,
1248 width, height, angle1, angle2);
1253 gdk_window_draw_polygon (GdkDrawable *drawable,
1259 GdkWindowObject *private = (GdkWindowObject *)drawable;
1260 GdkPoint *new_points;
1264 if (GDK_WINDOW_DESTROYED (drawable))
1267 if (x_offset != 0 || y_offset != 0)
1271 new_points = g_new (GdkPoint, npoints);
1272 for (i=0; i<npoints; i++)
1274 new_points[i].x = points[i].x - x_offset;
1275 new_points[i].y = points[i].y - y_offset;
1279 new_points = points;
1281 if (private->paint_stack)
1283 GdkWindowPaint *paint = private->paint_stack->data;
1284 gdk_draw_polygon (paint->pixmap, gc, filled, new_points, npoints);
1288 gdk_draw_polygon (private->impl, gc, filled, new_points, npoints);
1290 if (new_points != points)
1291 g_free (new_points);
1297 gdk_window_draw_text (GdkDrawable *drawable,
1305 GdkWindowObject *private = (GdkWindowObject *)drawable;
1308 if (GDK_WINDOW_DESTROYED (drawable))
1311 if (private->paint_stack)
1313 GdkWindowPaint *paint = private->paint_stack->data;
1314 gdk_draw_text (paint->pixmap, font, gc,
1315 x - x_offset, y - y_offset, text, text_length);
1319 gdk_draw_text (private->impl, font, gc,
1320 x - x_offset, y - y_offset, text, text_length);
1326 gdk_window_draw_text_wc (GdkDrawable *drawable,
1331 const GdkWChar *text,
1334 GdkWindowObject *private = (GdkWindowObject *)drawable;
1337 if (GDK_WINDOW_DESTROYED (drawable))
1340 if (private->paint_stack)
1342 GdkWindowPaint *paint = private->paint_stack->data;
1343 gdk_draw_text_wc (paint->pixmap, font, gc,
1344 x - x_offset, y - y_offset, text, text_length);
1347 gdk_draw_text_wc (private->impl, font, gc,
1348 x - x_offset, y - y_offset, text, text_length);
1354 gdk_window_get_composite_drawable (GdkDrawable *drawable,
1359 gint *composite_x_offset,
1360 gint *composite_y_offset)
1362 GdkWindowObject *private = (GdkWindowObject *)drawable;
1364 GdkPixmap *tmp_pixmap;
1367 gboolean overlap_buffer;
1369 _gdk_windowing_window_get_offsets (drawable,
1371 composite_y_offset);
1373 if ((GDK_IS_WINDOW (drawable) && GDK_WINDOW_DESTROYED (drawable))
1374 || private->paint_stack == NULL)
1376 /* No backing store */
1377 return g_object_ref (drawable);
1380 /* See if the buffered part is overlapping the part we want
1386 rect.height = height;
1388 overlap_buffer = FALSE;
1390 for (list = private->paint_stack; list != NULL; list = list->next)
1392 GdkWindowPaint *paint = list->data;
1393 GdkOverlapType overlap;
1395 overlap = gdk_region_rect_in (paint->region, &rect);
1397 if (overlap == GDK_OVERLAP_RECTANGLE_IN)
1399 *composite_x_offset = paint->x_offset;
1400 *composite_y_offset = paint->y_offset;
1402 return g_object_ref (paint->pixmap);
1404 else if (overlap == GDK_OVERLAP_RECTANGLE_PART)
1406 overlap_buffer = TRUE;
1411 if (!overlap_buffer)
1412 return g_object_ref (drawable);
1414 tmp_pixmap = gdk_pixmap_new (drawable, width, height, -1);
1415 tmp_gc = _gdk_drawable_get_scratch_gc (tmp_pixmap, FALSE);
1417 /* Copy the current window contents */
1418 gdk_draw_drawable (tmp_pixmap,
1421 x - *composite_x_offset,
1422 y - *composite_y_offset,
1426 /* paint the backing stores */
1427 for (list = private->paint_stack; list != NULL; list = list->next)
1429 GdkWindowPaint *paint = list->data;
1431 gdk_gc_set_clip_region (tmp_gc, paint->region);
1432 gdk_gc_set_clip_origin (tmp_gc, -x, -y);
1434 gdk_draw_drawable (tmp_pixmap, tmp_gc, paint->pixmap,
1435 x - paint->x_offset,
1436 y - paint->y_offset,
1437 0, 0, width, height);
1440 /* Reset clip region of the cached GdkGC */
1441 gdk_gc_set_clip_region (tmp_gc, NULL);
1443 /* Set these to location of tmp_pixmap within the window */
1444 *composite_x_offset = x;
1445 *composite_y_offset = y;
1451 gdk_window_get_clip_region (GdkDrawable *drawable)
1453 GdkWindowObject *private = (GdkWindowObject *)drawable;
1456 result = gdk_drawable_get_clip_region (private->impl);
1458 if (private->paint_stack)
1460 GdkRegion *paint_region = gdk_region_new ();
1461 GSList *tmp_list = private->paint_stack;
1465 GdkWindowPaint *paint = tmp_list->data;
1467 gdk_region_union (paint_region, paint->region);
1469 tmp_list = tmp_list->next;
1472 gdk_region_intersect (result, paint_region);
1473 gdk_region_destroy (paint_region);
1480 gdk_window_get_visible_region (GdkDrawable *drawable)
1482 GdkWindowObject *private = (GdkWindowObject*) drawable;
1484 return gdk_drawable_get_visible_region (private->impl);
1488 gdk_window_draw_drawable (GdkDrawable *drawable,
1498 GdkWindowObject *private = (GdkWindowObject *)drawable;
1501 if (GDK_WINDOW_DESTROYED (drawable))
1504 /* If we have a backing pixmap draw to that */
1505 if (private->paint_stack)
1507 GdkWindowPaint *paint = private->paint_stack->data;
1508 gdk_draw_drawable (paint->pixmap, gc,
1510 xdest - x_offset, ydest - y_offset, width, height);
1514 gdk_draw_drawable (private->impl, gc,
1516 xdest - x_offset, ydest - y_offset,
1523 gdk_window_draw_points (GdkDrawable *drawable,
1528 GdkWindowObject *private = (GdkWindowObject *)drawable;
1529 GdkPoint *new_points;
1533 if (GDK_WINDOW_DESTROYED (drawable))
1536 if (x_offset != 0 || y_offset != 0)
1540 new_points = g_new (GdkPoint, npoints);
1541 for (i=0; i<npoints; i++)
1543 new_points[i].x = points[i].x - x_offset;
1544 new_points[i].y = points[i].y - y_offset;
1548 new_points = points;
1550 if (private->paint_stack)
1552 GdkWindowPaint *paint = private->paint_stack->data;
1553 gdk_draw_points (paint->pixmap, gc, new_points, npoints);
1556 gdk_draw_points (private->impl, gc, points, npoints);
1558 if (new_points != points)
1559 g_free (new_points);
1565 gdk_window_draw_segments (GdkDrawable *drawable,
1570 GdkWindowObject *private = (GdkWindowObject *)drawable;
1571 GdkSegment *new_segs;
1575 if (GDK_WINDOW_DESTROYED (drawable))
1578 if (x_offset != 0 || y_offset != 0)
1582 new_segs = g_new (GdkSegment, nsegs);
1583 for (i=0; i<nsegs; i++)
1585 new_segs[i].x1 = segs[i].x1 - x_offset;
1586 new_segs[i].y1 = segs[i].y1 - y_offset;
1587 new_segs[i].x2 = segs[i].x2 - x_offset;
1588 new_segs[i].y2 = segs[i].y2 - y_offset;
1594 if (private->paint_stack)
1596 GdkWindowPaint *paint = private->paint_stack->data;
1597 gdk_draw_segments (paint->pixmap, gc, new_segs, nsegs);
1600 gdk_draw_segments (private->impl, gc, new_segs, nsegs);
1602 if (new_segs != segs)
1609 gdk_window_draw_lines (GdkDrawable *drawable,
1614 GdkWindowObject *private = (GdkWindowObject *)drawable;
1615 GdkPoint *new_points;
1619 if (GDK_WINDOW_DESTROYED (drawable))
1622 if (x_offset != 0 || y_offset != 0)
1626 new_points = g_new (GdkPoint, npoints);
1627 for (i=0; i<npoints; i++)
1629 new_points[i].x = points[i].x - x_offset;
1630 new_points[i].y = points[i].y - y_offset;
1634 new_points = points;
1636 if (private->paint_stack)
1638 GdkWindowPaint *paint = private->paint_stack->data;
1639 gdk_draw_lines (paint->pixmap, gc, new_points, npoints);
1642 gdk_draw_lines (private->impl, gc, new_points, npoints);
1644 if (new_points != points)
1645 g_free (new_points);
1651 gdk_window_draw_glyphs (GdkDrawable *drawable,
1656 PangoGlyphString *glyphs)
1658 GdkWindowObject *private = (GdkWindowObject *)drawable;
1662 if (GDK_WINDOW_DESTROYED (drawable))
1665 if (private->paint_stack)
1667 GdkWindowPaint *paint = private->paint_stack->data;
1669 gdk_draw_glyphs (paint->pixmap, gc, font, x - x_offset, y - y_offset, glyphs);
1672 gdk_draw_glyphs (private->impl, gc, font,
1673 x - x_offset, y - y_offset, glyphs);
1679 gdk_window_draw_glyphs_transformed (GdkDrawable *drawable,
1681 PangoMatrix *matrix,
1685 PangoGlyphString *glyphs)
1687 GdkWindowObject *private = (GdkWindowObject *)drawable;
1688 PangoMatrix tmp_matrix;
1692 if (GDK_WINDOW_DESTROYED (drawable))
1695 if (x_offset != 0 || y_offset != 0)
1699 tmp_matrix = *matrix;
1700 tmp_matrix.x0 -= x_offset;
1701 tmp_matrix.y0 -= y_offset;
1702 matrix = &tmp_matrix;
1706 x -= x_offset * PANGO_SCALE;
1707 y -= y_offset * PANGO_SCALE;
1711 if (private->paint_stack)
1713 GdkWindowPaint *paint = private->paint_stack->data;
1715 gdk_draw_glyphs_transformed (paint->pixmap, gc, matrix, font, x, y, glyphs);
1718 gdk_draw_glyphs_transformed (private->impl, gc, matrix, font, x, y, glyphs);
1724 gdk_window_get_bg_gc (GdkWindow *window,
1725 GdkWindowPaint *paint)
1727 GdkWindowObject *private = (GdkWindowObject *)window;
1730 GdkGCValues gc_values;
1732 if (private->bg_pixmap == GDK_PARENT_RELATIVE_BG && private->parent)
1734 GdkWindowPaint tmp_paint = *paint;
1735 tmp_paint.x_offset += private->x;
1736 tmp_paint.y_offset += private->y;
1738 return gdk_window_get_bg_gc (GDK_WINDOW (private->parent), &tmp_paint);
1740 else if (private->bg_pixmap &&
1741 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
1742 private->bg_pixmap != GDK_NO_BG)
1744 gc_values.fill = GDK_TILED;
1745 gc_values.tile = private->bg_pixmap;
1747 gc_mask = GDK_GC_FILL | GDK_GC_TILE;
1749 return gdk_gc_new_with_values (paint->pixmap, &gc_values, gc_mask);
1753 GdkGC *gc = _gdk_drawable_get_scratch_gc (paint->pixmap, FALSE);
1755 gdk_gc_set_foreground (gc, &(private->bg_color));
1757 return g_object_ref (gc);
1762 gdk_window_clear_backing_rect (GdkWindow *window,
1768 GdkWindowObject *private = (GdkWindowObject *)window;
1769 GdkWindowPaint *paint = private->paint_stack->data;
1772 if (GDK_WINDOW_DESTROYED (window))
1775 tmp_gc = gdk_window_get_bg_gc (window, paint);
1776 gdk_gc_set_clip_region (tmp_gc, paint->region);
1778 gdk_draw_rectangle (window, tmp_gc, TRUE,
1779 x, y, width, height);
1781 gdk_gc_set_clip_region (tmp_gc, NULL);
1783 g_object_unref (tmp_gc);
1788 * @window: a #GdkWindow
1790 * Clears an entire @window to the background color or background pixmap.
1793 gdk_window_clear (GdkWindow *window)
1797 g_return_if_fail (window != NULL);
1798 g_return_if_fail (GDK_IS_WINDOW (window));
1800 gdk_drawable_get_size (GDK_DRAWABLE (window), &width, &height);
1802 gdk_window_clear_area (window, 0, 0,
1807 * gdk_window_clear_area:
1808 * @window: a #GdkWindow
1809 * @x: x coordinate of rectangle to clear
1810 * @y: y coordinate of rectangle to clear
1811 * @width: width of rectangle to clear
1812 * @height: height of rectangle to clear
1814 * Clears an area of @window to the background color or background pixmap.
1818 gdk_window_clear_area (GdkWindow *window,
1824 GdkWindowObject *private = (GdkWindowObject *)window;
1826 g_return_if_fail (window != NULL);
1827 g_return_if_fail (GDK_IS_WINDOW (window));
1829 if (private->paint_stack)
1830 gdk_window_clear_backing_rect (window, x, y, width, height);
1832 _gdk_windowing_window_clear_area (window, x, y, width, height);
1836 * gdk_window_clear_area_e:
1837 * @window: a #GdkWindow
1838 * @x: x coordinate of rectangle to clear
1839 * @y: y coordinate of rectangle to clear
1840 * @width: width of rectangle to clear
1841 * @height: height of rectangle to clear
1843 * Like gdk_window_clear_area(), but also generates an expose event for
1846 * This function has a stupid name because it dates back to the mists
1847 * time, pre-GDK-1.0.
1851 gdk_window_clear_area_e (GdkWindow *window,
1857 GdkWindowObject *private = (GdkWindowObject *)window;
1859 g_return_if_fail (window != NULL);
1860 g_return_if_fail (GDK_IS_WINDOW (window));
1862 if (private->paint_stack)
1863 gdk_window_clear_backing_rect (window, x, y, width, height);
1865 _gdk_windowing_window_clear_area_e (window, x, y, width, height);
1869 gdk_window_draw_image (GdkDrawable *drawable,
1879 GdkWindowObject *private = (GdkWindowObject *)drawable;
1883 if (GDK_WINDOW_DESTROYED (drawable))
1886 if (private->paint_stack)
1888 GdkWindowPaint *paint = private->paint_stack->data;
1889 gdk_draw_image (paint->pixmap, gc, image, xsrc, ysrc,
1890 xdest - x_offset, ydest - y_offset,
1895 gdk_draw_image (private->impl, gc, image, xsrc, ysrc,
1896 xdest - x_offset, ydest - y_offset,
1903 gdk_window_draw_pixbuf (GdkDrawable *drawable,
1912 GdkRgbDither dither,
1916 GdkWindowObject *private = (GdkWindowObject *)drawable;
1918 if (GDK_WINDOW_DESTROYED (drawable))
1925 if (private->paint_stack)
1927 GdkWindowPaint *paint = private->paint_stack->data;
1928 gdk_draw_pixbuf (paint->pixmap, gc, pixbuf, src_x, src_y,
1929 dest_x - x_offset, dest_y - y_offset,
1931 dither, x_dither - x_offset, y_dither - y_offset);
1934 gdk_draw_pixbuf (private->impl, gc, pixbuf, src_x, src_y,
1935 dest_x - x_offset, dest_y - y_offset,
1937 dither, x_dither, y_dither);
1943 gint x_offset, y_offset;
1944 gdk_window_get_offsets (drawable, &x_offset, &y_offset);
1946 if (private->paint_stack)
1948 GdkWindowPaint *paint = private->paint_stack->data;
1949 gdk_draw_pixbuf (paint->pixmap, gc, pixbuf, src_x, src_y,
1950 dest_x - x_offset, dest_y - y_offset,
1952 dither, x_dither - x_offset, y_dither - y_offset);
1955 gdk_draw_pixbuf (private->impl, gc, pixbuf, src_x, src_y,
1956 dest_x - x_offset, dest_y - y_offset,
1958 dither, x_dither, y_dither);
1963 gdk_window_draw_trapezoids (GdkDrawable *drawable,
1965 GdkTrapezoid *trapezoids,
1968 GdkWindowObject *private = (GdkWindowObject *)drawable;
1969 GdkTrapezoid *new_trapezoids = NULL;
1973 if (GDK_WINDOW_DESTROYED (drawable))
1976 if (x_offset != 0 || y_offset != 0)
1980 new_trapezoids = g_new (GdkTrapezoid, n_trapezoids);
1981 for (i=0; i < n_trapezoids; i++)
1983 new_trapezoids[i].y1 = trapezoids[i].y1 - y_offset;
1984 new_trapezoids[i].x11 = trapezoids[i].x11 - x_offset;
1985 new_trapezoids[i].x21 = trapezoids[i].x21 - x_offset;
1986 new_trapezoids[i].y2 = trapezoids[i].y2 - y_offset;
1987 new_trapezoids[i].x12 = trapezoids[i].x12 - x_offset;
1988 new_trapezoids[i].x22 = trapezoids[i].x22 - x_offset;
1991 trapezoids = new_trapezoids;
1994 if (private->paint_stack)
1996 GdkWindowPaint *paint = private->paint_stack->data;
1997 gdk_draw_trapezoids (paint->pixmap, gc, trapezoids, n_trapezoids);
2000 gdk_draw_trapezoids (private->impl, gc, trapezoids, n_trapezoids);
2003 g_free (new_trapezoids);
2009 gdk_window_real_get_size (GdkDrawable *drawable,
2013 g_return_if_fail (GDK_IS_WINDOW (drawable));
2015 gdk_drawable_get_size (GDK_WINDOW_OBJECT (drawable)->impl,
2020 gdk_window_real_get_visual (GdkDrawable *drawable)
2022 GdkColormap *colormap;
2024 g_return_val_if_fail (GDK_IS_WINDOW (drawable), NULL);
2026 colormap = gdk_drawable_get_colormap (drawable);
2027 return colormap ? gdk_colormap_get_visual (colormap) : NULL;
2031 gdk_window_real_get_depth (GdkDrawable *drawable)
2033 g_return_val_if_fail (GDK_IS_WINDOW (drawable), 0);
2035 return ((GdkWindowObject *)GDK_WINDOW (drawable))->depth;
2039 gdk_window_real_get_screen (GdkDrawable *drawable)
2041 return gdk_drawable_get_screen (GDK_WINDOW_OBJECT (drawable)->impl);
2045 gdk_window_real_set_colormap (GdkDrawable *drawable,
2048 g_return_if_fail (GDK_IS_WINDOW (drawable));
2050 if (GDK_WINDOW_DESTROYED (drawable))
2053 gdk_drawable_set_colormap (((GdkWindowObject*)drawable)->impl, cmap);
2057 gdk_window_real_get_colormap (GdkDrawable *drawable)
2059 g_return_val_if_fail (GDK_IS_WINDOW (drawable), NULL);
2061 if (GDK_WINDOW_DESTROYED (drawable))
2064 return gdk_drawable_get_colormap (((GdkWindowObject*)drawable)->impl);
2068 gdk_window_copy_to_image (GdkDrawable *drawable,
2077 gint x_offset, y_offset;
2079 g_return_val_if_fail (GDK_IS_WINDOW (drawable), NULL);
2081 if (GDK_WINDOW_DESTROYED (drawable))
2084 /* If we're here, a composite image was not necessary, so
2085 * we can ignore the paint stack.
2088 _gdk_windowing_window_get_offsets (drawable, &x_offset, &y_offset);
2090 return gdk_drawable_copy_to_image (((GdkWindowObject*)drawable)->impl,
2099 gdk_window_set_cairo_target (GdkDrawable *drawable,
2102 GdkWindowObject *private = (GdkWindowObject*) drawable;
2103 gint x_offset, y_offset;
2105 gdk_window_get_offsets (GDK_WINDOW (drawable), &x_offset, &y_offset);
2107 if (private->paint_stack)
2109 GdkWindowPaint *paint = private->paint_stack->data;
2110 gdk_drawable_set_cairo_target (paint->pixmap, cr);
2113 gdk_drawable_set_cairo_target (private->impl, cr);
2115 cairo_translate (cr, - x_offset, - y_offset);
2118 /* Code for dirty-region queueing
2120 static GSList *update_windows = NULL;
2121 static guint update_idle = 0;
2122 static gboolean debug_updates = FALSE;
2125 gdk_window_update_idle (gpointer data)
2127 GDK_THREADS_ENTER ();
2128 gdk_window_process_all_updates ();
2129 GDK_THREADS_LEAVE ();
2135 gdk_window_schedule_update (GdkWindow *window)
2137 if (window && GDK_WINDOW_OBJECT (window)->update_freeze_count)
2142 update_idle = g_idle_add_full (GDK_PRIORITY_REDRAW,
2143 gdk_window_update_idle, NULL, NULL);
2148 gdk_window_process_updates_internal (GdkWindow *window)
2150 GdkWindowObject *private = (GdkWindowObject *)window;
2151 gboolean save_region = FALSE;
2153 /* If an update got queued during update processing, we can get a
2154 * window in the update queue that has an empty update_area.
2157 if (private->update_area)
2159 GdkRegion *update_area = private->update_area;
2160 private->update_area = NULL;
2162 if (_gdk_event_func && gdk_window_is_viewable (window))
2164 GdkRectangle window_rect;
2165 GdkRegion *expose_region;
2166 GdkRegion *window_region;
2171 /* Make sure we see the red invalid area before redrawing. */
2172 gdk_display_sync (gdk_drawable_get_display (window));
2176 save_region = _gdk_windowing_window_queue_antiexpose (window, update_area);
2179 expose_region = gdk_region_copy (update_area);
2181 expose_region = update_area;
2183 gdk_drawable_get_size (GDK_DRAWABLE (private), &width, &height);
2187 window_rect.width = width;
2188 window_rect.height = height;
2190 window_region = gdk_region_rectangle (&window_rect);
2191 gdk_region_intersect (expose_region,
2193 gdk_region_destroy (window_region);
2195 if (!gdk_region_empty (expose_region) &&
2196 (private->event_mask & GDK_EXPOSURE_MASK))
2200 event.expose.type = GDK_EXPOSE;
2201 event.expose.window = g_object_ref (window);
2202 event.expose.count = 0;
2203 event.expose.region = expose_region;
2204 gdk_region_get_clipbox (expose_region, &event.expose.area);
2206 (*_gdk_event_func) (&event, _gdk_event_data);
2208 g_object_unref (window);
2211 if (expose_region != update_area)
2212 gdk_region_destroy (expose_region);
2215 gdk_region_destroy (update_area);
2220 flush_all_displays (void)
2222 GSList *displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
2225 for (tmp_list = displays; tmp_list; tmp_list = tmp_list->next)
2226 gdk_display_flush (tmp_list->data);
2228 g_slist_free (displays);
2232 * gdk_window_process_all_updates:
2234 * Calls gdk_window_process_updates() for all windows (see #GdkWindow)
2235 * in the application.
2239 gdk_window_process_all_updates (void)
2241 GSList *old_update_windows = update_windows;
2242 GSList *tmp_list = update_windows;
2245 g_source_remove (update_idle);
2247 update_windows = NULL;
2250 g_slist_foreach (old_update_windows, (GFunc)g_object_ref, NULL);
2254 GdkWindowObject *private = (GdkWindowObject *)tmp_list->data;
2256 if (private->update_freeze_count)
2257 update_windows = g_slist_prepend (update_windows, private);
2259 gdk_window_process_updates_internal (tmp_list->data);
2261 g_object_unref (tmp_list->data);
2262 tmp_list = tmp_list->next;
2265 g_slist_free (old_update_windows);
2267 flush_all_displays ();
2271 * gdk_window_process_updates:
2272 * @window: a #GdkWindow
2273 * @update_children: whether to also process updates for child windows
2275 * Sends one or more expose events to @window. The areas in each
2276 * expose event will cover the entire update area for the window (see
2277 * gdk_window_invalidate_region() for details). Normally GDK calls
2278 * gdk_window_process_all_updates() on your behalf, so there's no
2279 * need to call this function unless you want to force expose events
2280 * to be delivered immediately and synchronously (vs. the usual
2281 * case, where GDK delivers them in an idle handler). Occasionally
2282 * this is useful to produce nicer scrolling behavior, for example.
2286 gdk_window_process_updates (GdkWindow *window,
2287 gboolean update_children)
2289 GdkWindowObject *private = (GdkWindowObject *)window;
2291 g_return_if_fail (window != NULL);
2292 g_return_if_fail (GDK_IS_WINDOW (window));
2294 if (private->update_area && !private->update_freeze_count)
2296 gdk_window_process_updates_internal (window);
2297 update_windows = g_slist_remove (update_windows, window);
2300 if (update_children)
2302 GList *tmp_list = private->children;
2305 gdk_window_process_updates (tmp_list->data, TRUE);
2306 tmp_list = tmp_list->next;
2312 * gdk_window_invalidate_rect:
2313 * @window: a #GdkWindow
2314 * @rect: rectangle to invalidate
2315 * @invalidate_children: whether to also invalidate child windows
2317 * A convenience wrapper around gdk_window_invalidate_region() which
2318 * invalidates a rectangular region. See
2319 * gdk_window_invalidate_region() for details.
2323 gdk_window_invalidate_rect (GdkWindow *window,
2325 gboolean invalidate_children)
2327 GdkRectangle window_rect;
2329 GdkWindowObject *private = (GdkWindowObject *)window;
2331 g_return_if_fail (window != NULL);
2332 g_return_if_fail (GDK_IS_WINDOW (window));
2334 if (GDK_WINDOW_DESTROYED (window))
2337 if (private->input_only || !GDK_WINDOW_IS_MAPPED (window))
2344 gdk_drawable_get_size (GDK_DRAWABLE (window),
2346 &window_rect.height);
2347 rect = &window_rect;
2350 region = gdk_region_rectangle (rect);
2351 gdk_window_invalidate_region (window, region, invalidate_children);
2352 gdk_region_destroy (region);
2356 draw_ugly_color (GdkWindow *window,
2359 /* Draw ugly color all over the newly-invalid region */
2360 GdkColor ugly_color = { 0, 50000, 10000, 10000 };
2362 GdkRectangle clipbox;
2364 ugly_gc = gdk_gc_new (window);
2365 gdk_gc_set_rgb_fg_color (ugly_gc, &ugly_color);
2366 gdk_gc_set_clip_region (ugly_gc, region);
2368 gdk_region_get_clipbox (region, &clipbox);
2370 gdk_draw_rectangle (window,
2373 clipbox.x, clipbox.y,
2374 clipbox.width, clipbox.height);
2376 g_object_unref (ugly_gc);
2380 * gdk_window_invalidate_maybe_recurse:
2381 * @window: a #GdkWindow
2382 * @region: a #GdkRegion
2383 * @child_func: function to use to decide if to recurse to a child,
2384 * %NULL means never recurse.
2385 * @user_data: data passed to @child_func
2387 * Adds @region to the update area for @window. The update area is the
2388 * region that needs to be redrawn, or "dirty region." The call
2389 * gdk_window_process_updates() sends one or more expose events to the
2390 * window, which together cover the entire update area. An
2391 * application would normally redraw the contents of @window in
2392 * response to those expose events.
2394 * GDK will call gdk_window_process_all_updates() on your behalf
2395 * whenever your program returns to the main loop and becomes idle, so
2396 * normally there's no need to do that manually, you just need to
2397 * invalidate regions that you know should be redrawn.
2399 * The @child_func parameter controls whether the region of
2400 * each child window that intersects @region will also be invalidated.
2401 * Only children for which @child_func returns TRUE will have the area
2405 gdk_window_invalidate_maybe_recurse (GdkWindow *window,
2407 gboolean (*child_func) (GdkWindow *, gpointer),
2410 GdkWindowObject *private = (GdkWindowObject *)window;
2411 GdkRegion *visible_region;
2413 g_return_if_fail (window != NULL);
2414 g_return_if_fail (GDK_IS_WINDOW (window));
2416 if (GDK_WINDOW_DESTROYED (window))
2419 if (private->input_only || !GDK_WINDOW_IS_MAPPED (window))
2422 visible_region = gdk_drawable_get_visible_region (window);
2423 gdk_region_intersect (visible_region, region);
2425 if (!gdk_region_empty (visible_region))
2428 draw_ugly_color (window, region);
2430 if (private->update_area)
2432 gdk_region_union (private->update_area, visible_region);
2436 update_windows = g_slist_prepend (update_windows, window);
2437 private->update_area = gdk_region_copy (visible_region);
2439 gdk_window_schedule_update (window);
2446 tmp_list = private->children;
2449 GdkWindowObject *child = tmp_list->data;
2450 tmp_list = tmp_list->next;
2452 if (!child->input_only && (*child_func) ((GdkWindow *)child, user_data))
2454 GdkRegion *child_region;
2457 gdk_window_get_position ((GdkWindow *)child, &x, &y);
2459 /* This copy could be saved with a little more complexity */
2460 child_region = gdk_region_copy (visible_region);
2461 gdk_region_offset (child_region, - x, - y);
2463 gdk_window_invalidate_maybe_recurse ((GdkWindow *)child, child_region, child_func, user_data);
2465 gdk_region_destroy (child_region);
2471 gdk_region_destroy (visible_region);
2475 true_predicate (GdkWindow *window,
2482 * gdk_window_invalidate_region:
2483 * @window: a #GdkWindow
2484 * @region: a #GdkRegion
2485 * @invalidate_children: %TRUE to also invalidate child windows
2487 * Adds @region to the update area for @window. The update area is the
2488 * region that needs to be redrawn, or "dirty region." The call
2489 * gdk_window_process_updates() sends one or more expose events to the
2490 * window, which together cover the entire update area. An
2491 * application would normally redraw the contents of @window in
2492 * response to those expose events.
2494 * GDK will call gdk_window_process_all_updates() on your behalf
2495 * whenever your program returns to the main loop and becomes idle, so
2496 * normally there's no need to do that manually, you just need to
2497 * invalidate regions that you know should be redrawn.
2499 * The @invalidate_children parameter controls whether the region of
2500 * each child window that intersects @region will also be invalidated.
2501 * If %FALSE, then the update area for child windows will remain
2502 * unaffected. See gdk_window_invalidate_maybe_recurse if you need
2503 * fine grained control over which children are invalidated.
2506 gdk_window_invalidate_region (GdkWindow *window,
2508 gboolean invalidate_children)
2510 gdk_window_invalidate_maybe_recurse (window, region,
2511 invalidate_children ?
2512 true_predicate : (gboolean (*) (GdkWindow *, gpointer))NULL,
2517 * gdk_window_get_update_area:
2518 * @window: a #GdkWindow
2520 * Transfers ownership of the update area from @window to the caller
2521 * of the function. That is, after calling this function, @window will
2522 * no longer have an invalid/dirty region; the update area is removed
2523 * from @window and handed to you. If a window has no update area,
2524 * gdk_window_get_update_area() returns %NULL. You are responsible for
2525 * calling gdk_region_destroy() on the returned region if it's non-%NULL.
2527 * Return value: the update area for @window
2530 gdk_window_get_update_area (GdkWindow *window)
2532 GdkWindowObject *private = (GdkWindowObject *)window;
2533 GdkRegion *tmp_region;
2535 g_return_val_if_fail (window != NULL, NULL);
2536 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2538 if (private->update_area)
2540 tmp_region = private->update_area;
2541 private->update_area = NULL;
2543 update_windows = g_slist_remove (update_windows, window);
2552 * _gdk_window_clear_update_area:
2553 * @window: a #GdkWindow.
2555 * Internal function to clear the update area for a window. This
2556 * is called when the window is hidden or destroyed.
2559 _gdk_window_clear_update_area (GdkWindow *window)
2561 GdkWindowObject *private = (GdkWindowObject *)window;
2563 g_return_if_fail (window != NULL);
2564 g_return_if_fail (GDK_IS_WINDOW (window));
2566 if (private->update_area)
2568 update_windows = g_slist_remove (update_windows, window);
2570 gdk_region_destroy (private->update_area);
2571 private->update_area = NULL;
2576 * gdk_window_freeze_updates:
2577 * @window: a #GdkWindow
2579 * Temporarily freezes a window such that it won't receive expose
2580 * events. The window will begin receiving expose events again when
2581 * gdk_window_thaw_updates() is called. If gdk_window_freeze_updates()
2582 * has been called more than once, gdk_window_thaw_updates() must be called
2583 * an equal number of times to begin processing exposes.
2586 gdk_window_freeze_updates (GdkWindow *window)
2588 GdkWindowObject *private = (GdkWindowObject *)window;
2590 g_return_if_fail (window != NULL);
2591 g_return_if_fail (GDK_IS_WINDOW (window));
2593 private->update_freeze_count++;
2597 * gdk_window_thaw_updates:
2598 * @window: a #GdkWindow
2600 * Thaws a window frozen with gdk_window_freeze_updates().
2603 gdk_window_thaw_updates (GdkWindow *window)
2605 GdkWindowObject *private = (GdkWindowObject *)window;
2607 g_return_if_fail (window != NULL);
2608 g_return_if_fail (GDK_IS_WINDOW (window));
2609 g_return_if_fail (private->update_freeze_count > 0);
2611 if (--private->update_freeze_count == 0)
2612 gdk_window_schedule_update (window);
2616 * gdk_window_set_debug_updates:
2617 * @setting: %TRUE to turn on update debugging
2619 * With update debugging enabled, calls to
2620 * gdk_window_invalidate_region() clear the invalidated region of the
2621 * screen to a noticeable color, and GDK pauses for a short time
2622 * before sending exposes to windows during
2623 * gdk_window_process_updates(). The net effect is that you can see
2624 * the invalid region for each window and watch redraws as they
2625 * occur. This allows you to diagnose inefficiencies in your application.
2627 * In essence, because the GDK rendering model prevents all flicker,
2628 * if you are redrawing the same region 400 times you may never
2629 * notice, aside from noticing a speed problem. Enabling update
2630 * debugging causes GTK to flicker slowly and noticeably, so you can
2631 * see exactly what's being redrawn when, in what order.
2633 * The --gtk-debug=updates command line option passed to GTK+ programs
2634 * enables this debug option at application startup time. That's
2635 * usually more useful than calling gdk_window_set_debug_updates()
2636 * yourself, though you might want to use this function to enable
2637 * updates sometime after application startup time.
2641 gdk_window_set_debug_updates (gboolean setting)
2643 debug_updates = setting;
2647 * gdk_window_constrain_size:
2648 * @geometry: a #GdkGeometry structure
2649 * @flags: a mask indicating what portions of @geometry are set
2650 * @width: desired width of window
2651 * @height: desired height of the window
2652 * @new_width: location to store resulting width
2653 * @new_height: location to store resulting height
2655 * Constrains a desired width and height according to a
2656 * set of geometry hints (such as minimum and maximum size).
2659 gdk_window_constrain_size (GdkGeometry *geometry,
2666 /* This routine is partially borrowed from fvwm.
2668 * Copyright 1993, Robert Nation
2669 * You may use this code for any purpose, as long as the original
2670 * copyright remains in the source code and all documentation
2672 * which in turn borrows parts of the algorithm from uwm
2675 gint min_height = 0;
2676 gint base_width = 0;
2677 gint base_height = 0;
2680 gint max_width = G_MAXINT;
2681 gint max_height = G_MAXINT;
2683 #define FLOOR(value, base) ( ((gint) ((value) / (base))) * (base) )
2685 if ((flags & GDK_HINT_BASE_SIZE) && (flags & GDK_HINT_MIN_SIZE))
2687 base_width = geometry->base_width;
2688 base_height = geometry->base_height;
2689 min_width = geometry->min_width;
2690 min_height = geometry->min_height;
2692 else if (flags & GDK_HINT_BASE_SIZE)
2694 base_width = geometry->base_width;
2695 base_height = geometry->base_height;
2696 min_width = geometry->base_width;
2697 min_height = geometry->base_height;
2699 else if (flags & GDK_HINT_MIN_SIZE)
2701 base_width = geometry->min_width;
2702 base_height = geometry->min_height;
2703 min_width = geometry->min_width;
2704 min_height = geometry->min_height;
2707 if (flags & GDK_HINT_MAX_SIZE)
2709 max_width = geometry->max_width ;
2710 max_height = geometry->max_height;
2713 if (flags & GDK_HINT_RESIZE_INC)
2715 xinc = MAX (xinc, geometry->width_inc);
2716 yinc = MAX (yinc, geometry->height_inc);
2719 /* clamp width and height to min and max values
2721 width = CLAMP (width, min_width, max_width);
2722 height = CLAMP (height, min_height, max_height);
2724 /* shrink to base + N * inc
2726 width = base_width + FLOOR (width - base_width, xinc);
2727 height = base_height + FLOOR (height - base_height, yinc);
2729 /* constrain aspect ratio, according to:
2732 * min_aspect <= -------- <= max_aspect
2736 if (flags & GDK_HINT_ASPECT &&
2737 geometry->min_aspect > 0 &&
2738 geometry->max_aspect > 0)
2742 if (geometry->min_aspect * height > width)
2744 delta = FLOOR (height - width / geometry->min_aspect, yinc);
2745 if (height - delta >= min_height)
2749 delta = FLOOR (height * geometry->min_aspect - width, xinc);
2750 if (width + delta <= max_width)
2755 if (geometry->max_aspect * height < width)
2757 delta = FLOOR (width - height * geometry->max_aspect, xinc);
2758 if (width - delta >= min_width)
2762 delta = FLOOR (width / geometry->max_aspect - height, yinc);
2763 if (height + delta <= max_height)
2772 *new_height = height;
2776 * gdk_window_get_pointer:
2777 * @window: a #GdkWindow
2778 * @x: return location for X coordinate of pointer
2779 * @y: return location for Y coordinate of pointer
2780 * @mask: return location for modifier mask
2782 * Obtains the current pointer position and modifier state.
2783 * The position is given in coordinates relative to @window.
2785 * Return value: the window containing the pointer (as with
2786 * gdk_window_at_pointer()), or %NULL if the window containing the
2787 * pointer isn't known to GDK
2790 gdk_window_get_pointer (GdkWindow *window,
2793 GdkModifierType *mask)
2795 GdkDisplay *display;
2797 GdkModifierType tmp_mask;
2800 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
2804 display = gdk_drawable_get_display (window);
2808 GdkScreen *screen = gdk_screen_get_default ();
2810 display = gdk_screen_get_display (screen);
2811 window = gdk_screen_get_root_window (screen);
2813 GDK_NOTE (MULTIHEAD,
2814 g_message ("Passing NULL for window to gdk_window_get_pointer()\n"
2815 "is not multihead safe"));
2818 child = display->pointer_hooks->window_get_pointer (display, window, &tmp_x, &tmp_y, &tmp_mask);
2831 * gdk_window_at_pointer:
2832 * @win_x: return location for origin of the window under the pointer
2833 * @win_y: return location for origin of the window under the pointer
2835 * Obtains the window underneath the mouse pointer, returning the
2836 * location of that window in @win_x, @win_y. Returns %NULL if the
2837 * window under the mouse pointer is not known to GDK (if the window
2838 * belongs to another application and a #GdkWindow hasn't been created
2839 * for it with gdk_window_foreign_new())
2841 * NOTE: For multihead-aware widgets or applications use
2842 * gdk_display_get_window_at_pointer() instead.
2844 * Return value: window under the mouse pointer
2847 gdk_window_at_pointer (gint *win_x,
2850 return gdk_display_get_window_at_pointer (gdk_display_get_default (), win_x, win_y);
2854 * gdk_get_default_root_window:
2856 * Obtains the root window (parent all other windows are inside)
2857 * for the default display and screen.
2859 * Return value: the default root window
2862 gdk_get_default_root_window (void)
2864 return gdk_screen_get_root_window (gdk_screen_get_default ());
2868 * gdk_window_foreign_new:
2869 * @anid: a native window handle.
2871 * Wraps a native window for the default display in a #GdkWindow.
2872 * This may fail if the window has been destroyed.
2874 * For example in the X backend, a native window handle is an Xlib
2877 * Return value: the newly-created #GdkWindow wrapper for the
2878 * native window or %NULL if the window has been destroyed.
2881 gdk_window_foreign_new (GdkNativeWindow anid)
2883 return gdk_window_foreign_new_for_display (gdk_display_get_default (), anid);
2886 #define __GDK_WINDOW_C__
2887 #include "gdkaliasdef.c"