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/.
29 #include "gdkwindow.h"
30 #include "gdkinternals.h"
31 #include "gdk.h" /* For gdk_rectangle_union() */
32 #include "gdkpixmap.h"
33 #include "gdkdrawable.h"
34 #include "gdkpixmap.h"
35 #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_real_get_size (GdkDrawable *drawable,
164 static GdkVisual* gdk_window_real_get_visual (GdkDrawable *drawable);
165 static gint gdk_window_real_get_depth (GdkDrawable *drawable);
166 static GdkScreen* gdk_window_real_get_screen (GdkDrawable *drawable);
167 static void gdk_window_real_set_colormap (GdkDrawable *drawable,
169 static GdkColormap* gdk_window_real_get_colormap (GdkDrawable *drawable);
171 static GdkDrawable* gdk_window_get_composite_drawable (GdkDrawable *drawable,
176 gint *composite_x_offset,
177 gint *composite_y_offset);
178 static GdkRegion* gdk_window_get_clip_region (GdkDrawable *drawable);
179 static GdkRegion* gdk_window_get_visible_region (GdkDrawable *drawable);
181 static void gdk_window_free_paint_stack (GdkWindow *window);
183 static void gdk_window_init (GdkWindowObject *window);
184 static void gdk_window_class_init (GdkWindowObjectClass *klass);
185 static void gdk_window_finalize (GObject *object);
186 static void gdk_window_clear_backing_rect (GdkWindow *window,
192 static gpointer parent_class = NULL;
195 gdk_window_object_get_type (void)
197 static GType object_type = 0;
201 static const GTypeInfo object_info =
203 sizeof (GdkWindowObjectClass),
204 (GBaseInitFunc) NULL,
205 (GBaseFinalizeFunc) NULL,
206 (GClassInitFunc) gdk_window_class_init,
207 NULL, /* class_finalize */
208 NULL, /* class_data */
209 sizeof (GdkWindowObject),
211 (GInstanceInitFunc) gdk_window_init,
214 object_type = g_type_register_static (GDK_TYPE_DRAWABLE,
223 gdk_window_init (GdkWindowObject *window)
225 /* 0-initialization is good for all other fields. */
227 window->window_type = GDK_WINDOW_CHILD;
229 window->state = GDK_WINDOW_STATE_WITHDRAWN;
231 window->impl = g_object_new (_gdk_window_impl_get_type (), NULL);
235 gdk_window_class_init (GdkWindowObjectClass *klass)
237 GObjectClass *object_class = G_OBJECT_CLASS (klass);
238 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
240 parent_class = g_type_class_peek_parent (klass);
242 object_class->finalize = gdk_window_finalize;
244 drawable_class->create_gc = gdk_window_create_gc;
245 drawable_class->draw_rectangle = gdk_window_draw_rectangle;
246 drawable_class->draw_arc = gdk_window_draw_arc;
247 drawable_class->draw_polygon = gdk_window_draw_polygon;
248 drawable_class->draw_text = gdk_window_draw_text;
249 drawable_class->draw_text_wc = gdk_window_draw_text_wc;
250 drawable_class->draw_drawable = gdk_window_draw_drawable;
251 drawable_class->draw_points = gdk_window_draw_points;
252 drawable_class->draw_segments = gdk_window_draw_segments;
253 drawable_class->draw_lines = gdk_window_draw_lines;
254 drawable_class->draw_glyphs = gdk_window_draw_glyphs;
255 drawable_class->draw_glyphs_transformed = gdk_window_draw_glyphs_transformed;
256 drawable_class->draw_image = gdk_window_draw_image;
257 drawable_class->draw_pixbuf = gdk_window_draw_pixbuf;
258 drawable_class->draw_trapezoids = gdk_window_draw_trapezoids;
259 drawable_class->get_depth = gdk_window_real_get_depth;
260 drawable_class->get_screen = gdk_window_real_get_screen;
261 drawable_class->get_size = gdk_window_real_get_size;
262 drawable_class->set_colormap = gdk_window_real_set_colormap;
263 drawable_class->get_colormap = gdk_window_real_get_colormap;
264 drawable_class->get_visual = gdk_window_real_get_visual;
265 drawable_class->_copy_to_image = gdk_window_copy_to_image;
266 drawable_class->get_clip_region = gdk_window_get_clip_region;
267 drawable_class->get_visible_region = gdk_window_get_visible_region;
268 drawable_class->get_composite_drawable = gdk_window_get_composite_drawable;
272 gdk_window_finalize (GObject *object)
274 GdkWindow *window = GDK_WINDOW (object);
275 GdkWindowObject *obj = (GdkWindowObject *) object;
277 if (!GDK_WINDOW_DESTROYED (window))
279 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
281 g_warning ("losing last reference to undestroyed window\n");
282 _gdk_window_destroy (window, FALSE);
285 /* We use TRUE here, to keep us from actually calling
286 * XDestroyWindow() on the window
288 _gdk_window_destroy (window, TRUE);
291 g_object_unref (obj->impl);
294 G_OBJECT_CLASS (parent_class)->finalize (object);
298 window_remove_filters (GdkWindow *window)
300 GdkWindowObject *obj = (GdkWindowObject*) window;
306 for (tmp_list = obj->filters; tmp_list; tmp_list = tmp_list->next)
307 g_free (tmp_list->data);
309 g_list_free (obj->filters);
315 * _gdk_window_destroy_hierarchy:
316 * @window: a #GdkWindow
317 * @recursing: If TRUE, then this is being called because a parent
318 * was destroyed. This generally means that the call to the
319 * windowing system to destroy the window can be omitted, since
320 * it will be destroyed as a result of the parent being destroyed.
321 * Unless @foreign_destroy.
322 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
323 * external agency. The window has already been destroyed and no
324 * windowing system calls should be made. (This may never happen
325 * for some windowing systems.)
327 * Internal function to destroy a window. Like gdk_window_destroy(),
328 * but does not drop the reference count created by gdk_window_new().
331 _gdk_window_destroy_hierarchy (GdkWindow *window,
333 gboolean foreign_destroy)
335 GdkWindowObject *private;
336 GdkWindowObject *temp_private;
337 GdkWindow *temp_window;
341 g_return_if_fail (window != NULL);
343 private = (GdkWindowObject*) window;
345 if (GDK_WINDOW_DESTROYED (window))
348 switch (GDK_WINDOW_TYPE (window))
350 case GDK_WINDOW_TOPLEVEL:
351 case GDK_WINDOW_CHILD:
352 case GDK_WINDOW_DIALOG:
353 case GDK_WINDOW_TEMP:
354 case GDK_WINDOW_FOREIGN:
355 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_FOREIGN && !foreign_destroy)
357 /* Logically, it probably makes more sense to send
358 * a "destroy yourself" message to the foreign window
359 * whether or not it's in our heirarchy; but for historical
360 * reasons, we only send "destroy yourself" messages to
361 * foreign windows in our heirarchy.
364 _gdk_windowing_window_destroy_foreign (window);
366 /* Also for historical reasons, we remove any filters
367 * on a foreign window when it or a parent is destroyed;
368 * this likely causes problems if two separate portions
369 * of code are maintaining filter lists on a foreign window.
371 window_remove_filters (window);
375 private->state |= GDK_WINDOW_STATE_WITHDRAWN;
379 GdkWindowObject *parent_private = (GdkWindowObject *)private->parent;
380 if (parent_private->children)
381 parent_private->children = g_list_remove (parent_private->children, window);
384 _gdk_window_clear_update_area (window);
385 gdk_window_free_paint_stack (window);
387 if (private->bg_pixmap &&
388 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
389 private->bg_pixmap != GDK_NO_BG)
391 g_object_unref (private->bg_pixmap);
392 private->bg_pixmap = NULL;
395 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_FOREIGN)
396 g_assert (private->children == NULL);
399 children = tmp = private->children;
400 private->children = NULL;
404 temp_window = tmp->data;
407 temp_private = (GdkWindowObject*) temp_window;
409 _gdk_window_destroy_hierarchy (temp_window,
410 TRUE, foreign_destroy);
413 g_list_free (children);
416 _gdk_windowing_window_destroy (window, recursing, foreign_destroy);
417 private->parent = NULL;
418 private->destroyed = TRUE;
420 window_remove_filters (window);
422 gdk_drawable_set_colormap (GDK_DRAWABLE (window), NULL);
426 case GDK_WINDOW_ROOT:
427 g_error ("attempted to destroy root window");
433 * _gdk_window_destroy:
434 * @window: a #GdkWindow
435 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
436 * external agency. The window has already been destroyed and no
437 * windowing system calls should be made. (This may never happen
438 * for some windowing systems.)
440 * Internal function to destroy a window. Like gdk_window_destroy(),
441 * but does not drop the reference count created by gdk_window_new().
444 _gdk_window_destroy (GdkWindow *window,
445 gboolean foreign_destroy)
447 _gdk_window_destroy_hierarchy (window, FALSE, foreign_destroy);
451 * gdk_window_destroy:
452 * @window: a #GdkWindow
454 * Destroys the window system resources associated with @window and decrements @window's
455 * reference count. The window system resources for all children of @window are also
456 * destroyed, but the children's reference counts are not decremented.
458 * Note that a window will not be destroyed automatically when its reference count
459 * reaches zero. You must call this function yourself before that happens.
463 gdk_window_destroy (GdkWindow *window)
465 _gdk_window_destroy_hierarchy (window, FALSE, FALSE);
466 g_object_unref (window);
470 * gdk_window_set_user_data:
471 * @window: a #GdkWindow
472 * @user_data: user data
474 * For most purposes this function is deprecated in favor of
475 * g_object_set_data(). However, for historical reasons GTK+ stores
476 * the #GtkWidget that owns a #GdkWindow as user data on the
477 * #GdkWindow. So, custom widget implementations should use
478 * this function for that. If GTK+ receives an event for a #GdkWindow,
479 * and the user data for the window is non-%NULL, GTK+ will assume the
480 * user data is a #GtkWidget, and forward the event to that widget.
484 gdk_window_set_user_data (GdkWindow *window,
487 g_return_if_fail (window != NULL);
489 ((GdkWindowObject*)window)->user_data = user_data;
493 * gdk_window_get_user_data:
494 * @window: a #GdkWindow
495 * @data: return location for user data
497 * Retrieves the user data for @window, which is normally the widget
498 * that @window belongs to. See gdk_window_set_user_data().
502 gdk_window_get_user_data (GdkWindow *window,
505 g_return_if_fail (window != NULL);
507 *data = ((GdkWindowObject*)window)->user_data;
511 * gdk_window_get_window_type:
512 * @window: a #GdkWindow
514 * Gets the type of the window. See #GdkWindowType.
516 * Return value: type of window
519 gdk_window_get_window_type (GdkWindow *window)
521 g_return_val_if_fail (GDK_IS_WINDOW (window), (GdkWindowType) -1);
523 return GDK_WINDOW_TYPE (window);
527 * gdk_window_get_position:
528 * @window: a #GdkWindow
529 * @x: X coordinate of window
530 * @y: Y coordinate of window
532 * Obtains the position of the window as reported in the
533 * most-recently-processed #GdkEventConfigure. Contrast with
534 * gdk_window_get_geometry() which queries the X server for the
535 * current window position, regardless of which events have been
536 * received or processed.
538 * The position coordinates are relative to the window's parent window.
542 gdk_window_get_position (GdkWindow *window,
546 GdkWindowObject *obj;
548 g_return_if_fail (GDK_IS_WINDOW (window));
550 obj = (GdkWindowObject*) window;
559 * gdk_window_get_parent:
560 * @window: a #GdkWindow
562 * Obtains the parent of @window, as known to GDK. Does not query the
563 * X server; thus this returns the parent as passed to gdk_window_new(),
564 * not the actual parent. This should never matter unless you're using
565 * Xlib calls mixed with GDK calls on the X11 platform. It may also
566 * matter for toplevel windows, because the window manager may choose
569 * Return value: parent of @window
572 gdk_window_get_parent (GdkWindow *window)
574 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
576 return (GdkWindow*) ((GdkWindowObject*) window)->parent;
580 * gdk_window_get_toplevel:
581 * @window: a #GdkWindow
583 * Gets the toplevel window that's an ancestor of @window.
585 * Return value: the toplevel window containing @window
588 gdk_window_get_toplevel (GdkWindow *window)
590 GdkWindowObject *obj;
592 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
594 obj = (GdkWindowObject *)window;
595 while (GDK_WINDOW_TYPE (obj) == GDK_WINDOW_CHILD)
596 obj = (GdkWindowObject *)obj->parent;
598 return GDK_WINDOW (obj);
602 * gdk_window_get_children:
603 * @window: a #GdkWindow
605 * Gets the list of children of @window known to GDK.
606 * This function only returns children created via GDK,
607 * so for example it's useless when used with the root window;
608 * it only returns windows an application created itself.
610 * The returned list must be freed, but the elements in the
613 * Return value: list of child windows inside @window
616 gdk_window_get_children (GdkWindow *window)
618 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
620 if (GDK_WINDOW_DESTROYED (window))
623 return g_list_copy (GDK_WINDOW_OBJECT (window)->children);
627 * gdk_window_peek_children:
628 * @window: a #GdkWindow
630 * Like gdk_window_get_children(), but does not copy the list of
631 * children, so the list does not need to be freed.
633 * Return value: a reference to the list of child windows in @window
636 gdk_window_peek_children (GdkWindow *window)
638 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
640 if (GDK_WINDOW_DESTROYED (window))
643 return GDK_WINDOW_OBJECT (window)->children;
647 * gdk_window_add_filter:
648 * @window: a #GdkWindow
649 * @function: filter callback
650 * @data: data to pass to filter callback
652 * Adds an event filter to @window, allowing you to intercept events
653 * before they reach GDK. This is a low-level operation and makes it
654 * easy to break GDK and/or GTK+, so you have to know what you're
655 * doing. Pass %NULL for @window to get all events for all windows,
656 * instead of events for a specific window.
660 gdk_window_add_filter (GdkWindow *window,
661 GdkFilterFunc function,
664 GdkWindowObject *private;
666 GdkEventFilter *filter;
668 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
670 private = (GdkWindowObject*) window;
671 if (private && GDK_WINDOW_DESTROYED (window))
675 tmp_list = private->filters;
677 tmp_list = _gdk_default_filters;
681 filter = (GdkEventFilter *)tmp_list->data;
682 if ((filter->function == function) && (filter->data == data))
684 tmp_list = tmp_list->next;
687 filter = g_new (GdkEventFilter, 1);
688 filter->function = function;
692 private->filters = g_list_append (private->filters, filter);
694 _gdk_default_filters = g_list_append (_gdk_default_filters, filter);
698 * gdk_window_remove_filter:
699 * @window: a #GdkWindow
700 * @function: previously-added filter function
701 * @data: user data for previously-added filter function
703 * Remove a filter previously added with gdk_window_add_filter().
707 gdk_window_remove_filter (GdkWindow *window,
708 GdkFilterFunc function,
711 GdkWindowObject *private;
712 GList *tmp_list, *node;
713 GdkEventFilter *filter;
715 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
717 private = (GdkWindowObject*) window;
720 tmp_list = private->filters;
722 tmp_list = _gdk_default_filters;
726 filter = (GdkEventFilter *)tmp_list->data;
728 tmp_list = tmp_list->next;
730 if ((filter->function == function) && (filter->data == data))
733 private->filters = g_list_remove_link (private->filters, node);
735 _gdk_default_filters = g_list_remove_link (_gdk_default_filters, node);
736 g_list_free_1 (node);
745 * gdk_screen_get_toplevel_windows:
746 * @screen: The #GdkScreen where the toplevels are located.
748 * Obtains a list of all toplevel windows known to GDK on the screen @screen.
749 * A toplevel window is a child of the root window (see
750 * gdk_get_default_root_window()).
752 * The returned list should be freed with g_list_free(), but
753 * its elements need not be freed.
755 * Return value: list of toplevel windows, free with g_list_free()
760 gdk_screen_get_toplevel_windows (GdkScreen *screen)
762 GdkWindow * root_window;
763 GList *new_list = NULL;
766 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
768 root_window = gdk_screen_get_root_window (screen);
770 tmp_list = ((GdkWindowObject *)root_window)->children;
773 if (GDK_WINDOW_TYPE (tmp_list->data) != GDK_WINDOW_FOREIGN)
774 new_list = g_list_prepend (new_list, tmp_list->data);
775 tmp_list = tmp_list->next;
782 * gdk_window_get_toplevels:
784 * Obtains a list of all toplevel windows known to GDK on the default
785 * screen (see gdk_window_get_toplevels_for_screen()).
786 * A toplevel window is a child of the root window (see
787 * gdk_get_default_root_window()).
789 * The returned list should be freed with g_list_free(), but
790 * its elements need not be freed.
792 * Return value: list of toplevel windows, free with g_list_free()
795 gdk_window_get_toplevels (void)
797 return gdk_screen_get_toplevel_windows (gdk_screen_get_default ());
801 * gdk_window_is_visible:
802 * @window: a #GdkWindow
804 * Checks whether the window has been mapped (with gdk_window_show() or
805 * gdk_window_show_unraised()).
807 * Return value: %TRUE if the window is mapped
810 gdk_window_is_visible (GdkWindow *window)
812 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
814 return GDK_WINDOW_IS_MAPPED (window);
818 * gdk_window_is_viewable:
819 * @window: a #GdkWindow
821 * Check if the window and all ancestors of the window are
822 * mapped. (This is not necessarily "viewable" in the X sense, since
823 * we only check as far as we have GDK window parents, not to the root
826 * Return value: %TRUE if the window is viewable
829 gdk_window_is_viewable (GdkWindow *window)
831 GdkWindowObject *private = (GdkWindowObject *)window;
833 GdkWindow *root_window;
835 g_return_val_if_fail (window != NULL, FALSE);
836 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
838 screen = gdk_drawable_get_screen (window);
839 root_window = gdk_screen_get_root_window (screen);
842 (private != (GdkWindowObject *)root_window) &&
843 (GDK_WINDOW_TYPE (private) != GDK_WINDOW_FOREIGN))
845 if (GDK_WINDOW_DESTROYED (private) || !GDK_WINDOW_IS_MAPPED (private))
848 private = (GdkWindowObject *)private->parent;
855 * gdk_window_get_state:
856 * @window: a #GdkWindow
858 * Gets the bitwise OR of the currently active window state flags,
859 * from the #GdkWindowState enumeration.
861 * Return value: window state bitfield
864 gdk_window_get_state (GdkWindow *window)
866 GdkWindowObject *private = (GdkWindowObject *)window;
868 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
870 return private->state;
874 * gdk_window_begin_paint_rect:
875 * @window: a #GdkWindow
876 * @rectangle: rectangle you intend to draw to
878 * A convenience wrapper around gdk_window_begin_paint_region() which
879 * creates a rectangular region for you. See
880 * gdk_window_begin_paint_region() for details.
884 gdk_window_begin_paint_rect (GdkWindow *window,
885 GdkRectangle *rectangle)
889 g_return_if_fail (window != NULL);
890 g_return_if_fail (GDK_IS_WINDOW (window));
892 region = gdk_region_rectangle (rectangle);
893 gdk_window_begin_paint_region (window, region);
894 gdk_region_destroy (region);
897 #ifdef GDK_WINDOWING_X11
898 #include "x11/gdkx.h"
902 * gdk_window_begin_paint_region:
903 * @window: a #GdkWindow
904 * @region: region you intend to draw to
906 * Indicates that you are beginning the process of redrawing @region.
907 * A backing store (offscreen buffer) large enough to contain @region
908 * will be created. The backing store will be initialized with the
909 * background color or background pixmap for @window. Then, all
910 * drawing operations performed on @window will be diverted to the
911 * backing store. When you call gdk_window_end_paint(), the backing
912 * store will be copied to @window, making it visible onscreen. Only
913 * the part of @window contained in @region will be modified; that is,
914 * drawing operations are clipped to @region.
916 * The net result of all this is to remove flicker, because the user
917 * sees the finished product appear all at once when you call
918 * gdk_window_end_paint(). If you draw to @window directly without
919 * calling gdk_window_begin_paint_region(), the user may see flicker
920 * as individual drawing operations are performed in sequence. The
921 * clipping and background-initializing features of
922 * gdk_window_begin_paint_region() are conveniences for the
923 * programmer, so you can avoid doing that work yourself.
925 * When using GTK+, the widget system automatically places calls to
926 * gdk_window_begin_paint_region() and gdk_window_end_paint() around
927 * emissions of the expose_event signal. That is, if you're writing an
928 * expose event handler, you can assume that the exposed area in
929 * #GdkEventExpose has already been cleared to the window background,
930 * is already set as the clip region, and already has a backing store.
931 * Therefore in most cases, application code need not call
932 * gdk_window_begin_paint_region(). (You can disable the automatic
933 * calls around expose events on a widget-by-widget basis by calling
934 * gtk_widget_set_double_buffered().)
936 * If you call this function multiple times before calling the
937 * matching gdk_window_end_paint(), the backing stores are pushed onto
938 * a stack. gdk_window_end_paint() copies the topmost backing store
939 * onscreen, subtracts the topmost region from all other regions in
940 * the stack, and pops the stack. All drawing operations affect only
941 * the topmost backing store in the stack. One matching call to
942 * gdk_window_end_paint() is required for each call to
943 * gdk_window_begin_paint_region().
947 gdk_window_begin_paint_region (GdkWindow *window,
950 #ifdef USE_BACKING_STORE
951 GdkWindowObject *private = (GdkWindowObject *)window;
952 GdkRectangle clip_box;
953 GdkWindowPaint *paint;
956 g_return_if_fail (window != NULL);
957 g_return_if_fail (GDK_IS_WINDOW (window));
959 if (GDK_WINDOW_DESTROYED (window))
962 gdk_region_get_clipbox (region, &clip_box);
964 paint = g_new (GdkWindowPaint, 1);
965 paint->region = gdk_region_copy (region);
966 paint->x_offset = clip_box.x;
967 paint->y_offset = clip_box.y;
969 gdk_pixmap_new (window,
970 MAX (clip_box.width, 1), MAX (clip_box.height, 1), -1);
972 for (list = private->paint_stack; list != NULL; list = list->next)
974 GdkWindowPaint *tmp_paint = list->data;
976 gdk_region_subtract (tmp_paint->region, paint->region);
979 private->paint_stack = g_slist_prepend (private->paint_stack, paint);
981 if (!gdk_region_empty (region))
983 gdk_window_clear_backing_rect (window,
984 clip_box.x, clip_box.y,
985 clip_box.width, clip_box.height);
987 #endif /* USE_BACKING_STORE */
991 * gdk_window_end_paint:
992 * @window: a #GdkWindow
994 * Indicates that the backing store created by the most recent call to
995 * gdk_window_begin_paint_region() should be copied onscreen and
996 * deleted, leaving the next-most-recent backing store or no backing
997 * store at all as the active paint region. See
998 * gdk_window_begin_paint_region() for full details. It is an error to
999 * call this function without a matching
1000 * gdk_window_begin_paint_region() first.
1004 gdk_window_end_paint (GdkWindow *window)
1006 #ifdef USE_BACKING_STORE
1007 GdkWindowObject *private = (GdkWindowObject *)window;
1008 GdkWindowPaint *paint;
1010 GdkRectangle clip_box;
1011 gint x_offset, y_offset;
1013 g_return_if_fail (window != NULL);
1014 g_return_if_fail (GDK_IS_WINDOW (window));
1016 if (GDK_WINDOW_DESTROYED (window))
1019 if (private->paint_stack == NULL)
1021 g_warning (G_STRLOC": no preceding call to gdk_window_begin_paint_region(), see documentation");
1025 paint = private->paint_stack->data;
1026 private->paint_stack = g_slist_delete_link (private->paint_stack,
1027 private->paint_stack);
1029 gdk_region_get_clipbox (paint->region, &clip_box);
1031 tmp_gc = _gdk_drawable_get_scratch_gc (window, FALSE);
1033 _gdk_windowing_window_get_offsets (window, &x_offset, &y_offset);
1035 gdk_gc_set_clip_region (tmp_gc, paint->region);
1036 gdk_gc_set_clip_origin (tmp_gc, - x_offset, - y_offset);
1038 gdk_draw_drawable (private->impl, tmp_gc, paint->pixmap,
1039 clip_box.x - paint->x_offset,
1040 clip_box.y - paint->y_offset,
1041 clip_box.x - x_offset, clip_box.y - y_offset,
1042 clip_box.width, clip_box.height);
1044 /* Reset clip region of the cached GdkGC */
1045 gdk_gc_set_clip_region (tmp_gc, NULL);
1047 g_object_unref (paint->pixmap);
1048 gdk_region_destroy (paint->region);
1050 #endif /* USE_BACKING_STORE */
1054 gdk_window_free_paint_stack (GdkWindow *window)
1056 GdkWindowObject *private = (GdkWindowObject *)window;
1058 if (private->paint_stack)
1060 GSList *tmp_list = private->paint_stack;
1064 GdkWindowPaint *paint = tmp_list->data;
1066 if (tmp_list == private->paint_stack)
1067 g_object_unref (paint->pixmap);
1069 gdk_region_destroy (paint->region);
1072 tmp_list = tmp_list->next;
1075 g_slist_free (private->paint_stack);
1076 private->paint_stack = NULL;
1081 gdk_window_get_offsets (GdkWindow *window,
1085 GdkWindowObject *private = (GdkWindowObject *)window;
1087 if (private->paint_stack)
1089 GdkWindowPaint *paint = private->paint_stack->data;
1090 *x_offset = paint->x_offset;
1091 *y_offset = paint->y_offset;
1094 _gdk_windowing_window_get_offsets (window, x_offset, y_offset);
1098 * gdk_window_get_internal_paint_info:
1099 * @window: a #GdkWindow
1100 * @real_drawable: location to store the drawable to which drawing should be
1102 * @x_offset: location to store the X offset between coordinates in @window,
1103 * and the underlying window system primitive coordinates for
1105 * @y_offset: location to store the Y offset between coordinates in @window,
1106 * and the underlying window system primitive coordinates for
1109 * If you bypass the GDK layer and use windowing system primitives to
1110 * draw directly onto a #GdkWindow, then you need to deal with two
1111 * details: there may be an offset between GDK coordinates and windowing
1112 * system coordinates, and GDK may have redirected drawing to a offscreen
1113 * pixmap as the result of a gdk_window_begin_paint_region() calls.
1114 * This function allows retrieving the information you need to compensate
1115 * for these effects.
1117 * This function exposes details of the GDK implementation, and is thus
1118 * likely to change in future releases of GDK.
1121 gdk_window_get_internal_paint_info (GdkWindow *window,
1122 GdkDrawable **real_drawable,
1128 GdkWindowObject *private;
1130 g_return_if_fail (GDK_IS_WINDOW (window));
1132 private = (GdkWindowObject *)window;
1136 if (private->paint_stack)
1138 GdkWindowPaint *paint = private->paint_stack->data;
1139 *real_drawable = paint->pixmap;
1142 *real_drawable = window;
1145 gdk_window_get_offsets (window, &x_off, &y_off);
1153 #define OFFSET_GC(gc) \
1154 gint x_offset, y_offset; \
1155 gint old_clip_x = gc->clip_x_origin; \
1156 gint old_clip_y = gc->clip_y_origin; \
1157 gint old_ts_x = gc->ts_x_origin; \
1158 gint old_ts_y = gc->ts_y_origin; \
1159 gdk_window_get_offsets (drawable, &x_offset, &y_offset); \
1160 if (x_offset != 0 || y_offset != 0) \
1162 gdk_gc_set_clip_origin (gc, old_clip_x - x_offset, \
1163 old_clip_y - y_offset); \
1164 gdk_gc_set_ts_origin (gc, old_ts_x - x_offset, \
1165 old_ts_y - y_offset); \
1168 #define RESTORE_GC(gc) \
1169 if (x_offset != 0 || y_offset != 0) \
1171 gdk_gc_set_clip_origin (gc, old_clip_x, old_clip_y); \
1172 gdk_gc_set_ts_origin (gc, old_ts_x, old_ts_y); \
1176 gdk_window_create_gc (GdkDrawable *drawable,
1177 GdkGCValues *values,
1178 GdkGCValuesMask mask)
1180 g_return_val_if_fail (GDK_IS_WINDOW (drawable), NULL);
1182 if (GDK_WINDOW_DESTROYED (drawable))
1185 return gdk_gc_new_with_values (((GdkWindowObject *) drawable)->impl,
1190 gdk_window_draw_rectangle (GdkDrawable *drawable,
1198 GdkWindowObject *private = (GdkWindowObject *)drawable;
1201 if (GDK_WINDOW_DESTROYED (drawable))
1204 if (private->paint_stack)
1206 GdkWindowPaint *paint = private->paint_stack->data;
1207 gdk_draw_rectangle (paint->pixmap, gc, filled,
1208 x - x_offset, y - y_offset, width, height);
1211 gdk_draw_rectangle (private->impl, gc, filled,
1212 x - x_offset, y - y_offset, width, height);
1218 gdk_window_draw_arc (GdkDrawable *drawable,
1228 GdkWindowObject *private = (GdkWindowObject *)drawable;
1231 if (GDK_WINDOW_DESTROYED (drawable))
1234 if (private->paint_stack)
1236 GdkWindowPaint *paint = private->paint_stack->data;
1237 gdk_draw_arc (paint->pixmap, gc, filled,
1238 x - x_offset, y - y_offset,
1239 width, height, angle1, angle2);
1242 gdk_draw_arc (private->impl, gc, filled,
1243 x - x_offset, y - y_offset,
1244 width, height, angle1, angle2);
1249 gdk_window_draw_polygon (GdkDrawable *drawable,
1255 GdkWindowObject *private = (GdkWindowObject *)drawable;
1256 GdkPoint *new_points;
1260 if (GDK_WINDOW_DESTROYED (drawable))
1263 if (x_offset != 0 || y_offset != 0)
1267 new_points = g_new (GdkPoint, npoints);
1268 for (i=0; i<npoints; i++)
1270 new_points[i].x = points[i].x - x_offset;
1271 new_points[i].y = points[i].y - y_offset;
1275 new_points = points;
1277 if (private->paint_stack)
1279 GdkWindowPaint *paint = private->paint_stack->data;
1280 gdk_draw_polygon (paint->pixmap, gc, filled, new_points, npoints);
1284 gdk_draw_polygon (private->impl, gc, filled, new_points, npoints);
1286 if (new_points != points)
1287 g_free (new_points);
1293 gdk_window_draw_text (GdkDrawable *drawable,
1301 GdkWindowObject *private = (GdkWindowObject *)drawable;
1304 if (GDK_WINDOW_DESTROYED (drawable))
1307 if (private->paint_stack)
1309 GdkWindowPaint *paint = private->paint_stack->data;
1310 gdk_draw_text (paint->pixmap, font, gc,
1311 x - x_offset, y - y_offset, text, text_length);
1315 gdk_draw_text (private->impl, font, gc,
1316 x - x_offset, y - y_offset, text, text_length);
1322 gdk_window_draw_text_wc (GdkDrawable *drawable,
1327 const GdkWChar *text,
1330 GdkWindowObject *private = (GdkWindowObject *)drawable;
1333 if (GDK_WINDOW_DESTROYED (drawable))
1336 if (private->paint_stack)
1338 GdkWindowPaint *paint = private->paint_stack->data;
1339 gdk_draw_text_wc (paint->pixmap, font, gc,
1340 x - x_offset, y - y_offset, text, text_length);
1343 gdk_draw_text_wc (private->impl, font, gc,
1344 x - x_offset, y - y_offset, text, text_length);
1350 gdk_window_get_composite_drawable (GdkDrawable *drawable,
1355 gint *composite_x_offset,
1356 gint *composite_y_offset)
1358 GdkWindowObject *private = (GdkWindowObject *)drawable;
1360 GdkPixmap *tmp_pixmap;
1363 gboolean overlap_buffer;
1365 _gdk_windowing_window_get_offsets (drawable,
1367 composite_y_offset);
1369 if ((GDK_IS_WINDOW (drawable) && GDK_WINDOW_DESTROYED (drawable))
1370 || private->paint_stack == NULL)
1372 /* No backing store */
1373 return g_object_ref (drawable);
1376 /* See if the buffered part is overlapping the part we want
1382 rect.height = height;
1384 overlap_buffer = FALSE;
1386 for (list = private->paint_stack; list != NULL; list = list->next)
1388 GdkWindowPaint *paint = list->data;
1389 GdkOverlapType overlap;
1391 overlap = gdk_region_rect_in (paint->region, &rect);
1393 if (overlap == GDK_OVERLAP_RECTANGLE_IN)
1395 *composite_x_offset = paint->x_offset;
1396 *composite_y_offset = paint->y_offset;
1398 return g_object_ref (paint->pixmap);
1400 else if (overlap == GDK_OVERLAP_RECTANGLE_PART)
1402 overlap_buffer = TRUE;
1407 if (!overlap_buffer)
1408 return g_object_ref (drawable);
1410 tmp_pixmap = gdk_pixmap_new (drawable, width, height, -1);
1411 tmp_gc = _gdk_drawable_get_scratch_gc (tmp_pixmap, FALSE);
1413 /* Copy the current window contents */
1414 gdk_draw_drawable (tmp_pixmap,
1417 x - *composite_x_offset,
1418 y - *composite_y_offset,
1422 /* paint the backing stores */
1423 for (list = private->paint_stack; list != NULL; list = list->next)
1425 GdkWindowPaint *paint = list->data;
1427 gdk_gc_set_clip_region (tmp_gc, paint->region);
1428 gdk_gc_set_clip_origin (tmp_gc, -x, -y);
1430 gdk_draw_drawable (tmp_pixmap, tmp_gc, paint->pixmap,
1431 x - paint->x_offset,
1432 y - paint->y_offset,
1433 0, 0, width, height);
1436 /* Reset clip region of the cached GdkGC */
1437 gdk_gc_set_clip_region (tmp_gc, NULL);
1439 /* Set these to location of tmp_pixmap within the window */
1440 *composite_x_offset = x;
1441 *composite_y_offset = y;
1447 gdk_window_get_clip_region (GdkDrawable *drawable)
1449 GdkWindowObject *private = (GdkWindowObject *)drawable;
1452 result = gdk_drawable_get_clip_region (private->impl);
1454 if (private->paint_stack)
1456 GdkRegion *paint_region = gdk_region_new ();
1457 GSList *tmp_list = private->paint_stack;
1461 GdkWindowPaint *paint = tmp_list->data;
1463 gdk_region_union (paint_region, paint->region);
1465 tmp_list = tmp_list->next;
1468 gdk_region_intersect (result, paint_region);
1469 gdk_region_destroy (paint_region);
1476 gdk_window_get_visible_region (GdkDrawable *drawable)
1478 GdkWindowObject *private = (GdkWindowObject*) drawable;
1480 return gdk_drawable_get_visible_region (private->impl);
1484 gdk_window_draw_drawable (GdkDrawable *drawable,
1494 GdkWindowObject *private = (GdkWindowObject *)drawable;
1497 if (GDK_WINDOW_DESTROYED (drawable))
1500 /* If we have a backing pixmap draw to that */
1501 if (private->paint_stack)
1503 GdkWindowPaint *paint = private->paint_stack->data;
1504 gdk_draw_drawable (paint->pixmap, gc,
1506 xdest - x_offset, ydest - y_offset, width, height);
1510 gdk_draw_drawable (private->impl, gc,
1512 xdest - x_offset, ydest - y_offset,
1519 gdk_window_draw_points (GdkDrawable *drawable,
1524 GdkWindowObject *private = (GdkWindowObject *)drawable;
1525 GdkPoint *new_points;
1529 if (GDK_WINDOW_DESTROYED (drawable))
1532 if (x_offset != 0 || y_offset != 0)
1536 new_points = g_new (GdkPoint, npoints);
1537 for (i=0; i<npoints; i++)
1539 new_points[i].x = points[i].x - x_offset;
1540 new_points[i].y = points[i].y - y_offset;
1544 new_points = points;
1546 if (private->paint_stack)
1548 GdkWindowPaint *paint = private->paint_stack->data;
1549 gdk_draw_points (paint->pixmap, gc, new_points, npoints);
1552 gdk_draw_points (private->impl, gc, points, npoints);
1554 if (new_points != points)
1555 g_free (new_points);
1561 gdk_window_draw_segments (GdkDrawable *drawable,
1566 GdkWindowObject *private = (GdkWindowObject *)drawable;
1567 GdkSegment *new_segs;
1571 if (GDK_WINDOW_DESTROYED (drawable))
1574 if (x_offset != 0 || y_offset != 0)
1578 new_segs = g_new (GdkSegment, nsegs);
1579 for (i=0; i<nsegs; i++)
1581 new_segs[i].x1 = segs[i].x1 - x_offset;
1582 new_segs[i].y1 = segs[i].y1 - y_offset;
1583 new_segs[i].x2 = segs[i].x2 - x_offset;
1584 new_segs[i].y2 = segs[i].y2 - y_offset;
1590 if (private->paint_stack)
1592 GdkWindowPaint *paint = private->paint_stack->data;
1593 gdk_draw_segments (paint->pixmap, gc, new_segs, nsegs);
1596 gdk_draw_segments (private->impl, gc, new_segs, nsegs);
1598 if (new_segs != segs)
1605 gdk_window_draw_lines (GdkDrawable *drawable,
1610 GdkWindowObject *private = (GdkWindowObject *)drawable;
1611 GdkPoint *new_points;
1615 if (GDK_WINDOW_DESTROYED (drawable))
1618 if (x_offset != 0 || y_offset != 0)
1622 new_points = g_new (GdkPoint, npoints);
1623 for (i=0; i<npoints; i++)
1625 new_points[i].x = points[i].x - x_offset;
1626 new_points[i].y = points[i].y - y_offset;
1630 new_points = points;
1632 if (private->paint_stack)
1634 GdkWindowPaint *paint = private->paint_stack->data;
1635 gdk_draw_lines (paint->pixmap, gc, new_points, npoints);
1638 gdk_draw_lines (private->impl, gc, new_points, npoints);
1640 if (new_points != points)
1641 g_free (new_points);
1647 gdk_window_draw_glyphs (GdkDrawable *drawable,
1652 PangoGlyphString *glyphs)
1654 GdkWindowObject *private = (GdkWindowObject *)drawable;
1658 if (GDK_WINDOW_DESTROYED (drawable))
1661 if (private->paint_stack)
1663 GdkWindowPaint *paint = private->paint_stack->data;
1665 gdk_draw_glyphs (paint->pixmap, gc, font, x - x_offset, y - y_offset, glyphs);
1668 gdk_draw_glyphs (private->impl, gc, font,
1669 x - x_offset, y - y_offset, glyphs);
1675 gdk_window_draw_glyphs_transformed (GdkDrawable *drawable,
1677 PangoMatrix *matrix,
1681 PangoGlyphString *glyphs)
1683 GdkWindowObject *private = (GdkWindowObject *)drawable;
1684 PangoMatrix tmp_matrix;
1688 if (GDK_WINDOW_DESTROYED (drawable))
1691 if (x_offset != 0 || y_offset != 0)
1695 tmp_matrix = *matrix;
1696 tmp_matrix.x0 -= x_offset;
1697 tmp_matrix.y0 -= y_offset;
1698 matrix = &tmp_matrix;
1702 x -= x_offset * PANGO_SCALE;
1703 y -= y_offset * PANGO_SCALE;
1707 if (private->paint_stack)
1709 GdkWindowPaint *paint = private->paint_stack->data;
1711 gdk_draw_glyphs_transformed (paint->pixmap, gc, matrix, font, x, y, glyphs);
1714 gdk_draw_glyphs_transformed (private->impl, gc, matrix, font, x, y, glyphs);
1720 gdk_window_get_bg_gc (GdkWindow *window,
1721 GdkWindowPaint *paint)
1723 GdkWindowObject *private = (GdkWindowObject *)window;
1726 GdkGCValues gc_values;
1728 if (private->bg_pixmap == GDK_PARENT_RELATIVE_BG && private->parent)
1730 GdkWindowPaint tmp_paint = *paint;
1731 tmp_paint.x_offset += private->x;
1732 tmp_paint.y_offset += private->y;
1734 return gdk_window_get_bg_gc (GDK_WINDOW (private->parent), &tmp_paint);
1736 else if (private->bg_pixmap &&
1737 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
1738 private->bg_pixmap != GDK_NO_BG)
1740 gc_values.fill = GDK_TILED;
1741 gc_values.tile = private->bg_pixmap;
1743 gc_mask = GDK_GC_FILL | GDK_GC_TILE;
1745 return gdk_gc_new_with_values (paint->pixmap, &gc_values, gc_mask);
1749 GdkGC *gc = _gdk_drawable_get_scratch_gc (paint->pixmap, FALSE);
1751 gdk_gc_set_foreground (gc, &(private->bg_color));
1753 return g_object_ref (gc);
1758 gdk_window_clear_backing_rect (GdkWindow *window,
1764 GdkWindowObject *private = (GdkWindowObject *)window;
1765 GdkWindowPaint *paint = private->paint_stack->data;
1768 if (GDK_WINDOW_DESTROYED (window))
1771 tmp_gc = gdk_window_get_bg_gc (window, paint);
1772 gdk_gc_set_clip_region (tmp_gc, paint->region);
1774 gdk_draw_rectangle (window, tmp_gc, TRUE,
1775 x, y, width, height);
1777 gdk_gc_set_clip_region (tmp_gc, NULL);
1779 g_object_unref (tmp_gc);
1784 * @window: a #GdkWindow
1786 * Clears an entire @window to the background color or background pixmap.
1789 gdk_window_clear (GdkWindow *window)
1793 g_return_if_fail (window != NULL);
1794 g_return_if_fail (GDK_IS_WINDOW (window));
1796 gdk_drawable_get_size (GDK_DRAWABLE (window), &width, &height);
1798 gdk_window_clear_area (window, 0, 0,
1803 * gdk_window_clear_area:
1804 * @window: a #GdkWindow
1805 * @x: x coordinate of rectangle to clear
1806 * @y: y coordinate of rectangle to clear
1807 * @width: width of rectangle to clear
1808 * @height: height of rectangle to clear
1810 * Clears an area of @window to the background color or background pixmap.
1814 gdk_window_clear_area (GdkWindow *window,
1820 GdkWindowObject *private = (GdkWindowObject *)window;
1822 g_return_if_fail (window != NULL);
1823 g_return_if_fail (GDK_IS_WINDOW (window));
1825 if (private->paint_stack)
1826 gdk_window_clear_backing_rect (window, x, y, width, height);
1828 _gdk_windowing_window_clear_area (window, x, y, width, height);
1832 * gdk_window_clear_area_e:
1833 * @window: a #GdkWindow
1834 * @x: x coordinate of rectangle to clear
1835 * @y: y coordinate of rectangle to clear
1836 * @width: width of rectangle to clear
1837 * @height: height of rectangle to clear
1839 * Like gdk_window_clear_area(), but also generates an expose event for
1842 * This function has a stupid name because it dates back to the mists
1843 * time, pre-GDK-1.0.
1847 gdk_window_clear_area_e (GdkWindow *window,
1853 GdkWindowObject *private = (GdkWindowObject *)window;
1855 g_return_if_fail (window != NULL);
1856 g_return_if_fail (GDK_IS_WINDOW (window));
1858 if (private->paint_stack)
1859 gdk_window_clear_backing_rect (window, x, y, width, height);
1861 _gdk_windowing_window_clear_area_e (window, x, y, width, height);
1865 gdk_window_draw_image (GdkDrawable *drawable,
1875 GdkWindowObject *private = (GdkWindowObject *)drawable;
1879 if (GDK_WINDOW_DESTROYED (drawable))
1882 if (private->paint_stack)
1884 GdkWindowPaint *paint = private->paint_stack->data;
1885 gdk_draw_image (paint->pixmap, gc, image, xsrc, ysrc,
1886 xdest - x_offset, ydest - y_offset,
1891 gdk_draw_image (private->impl, gc, image, xsrc, ysrc,
1892 xdest - x_offset, ydest - y_offset,
1899 gdk_window_draw_pixbuf (GdkDrawable *drawable,
1908 GdkRgbDither dither,
1912 GdkWindowObject *private = (GdkWindowObject *)drawable;
1914 if (GDK_WINDOW_DESTROYED (drawable))
1921 if (private->paint_stack)
1923 GdkWindowPaint *paint = private->paint_stack->data;
1924 gdk_draw_pixbuf (paint->pixmap, gc, pixbuf, src_x, src_y,
1925 dest_x - x_offset, dest_y - y_offset,
1927 dither, x_dither - x_offset, y_dither - y_offset);
1930 gdk_draw_pixbuf (private->impl, gc, pixbuf, src_x, src_y,
1931 dest_x - x_offset, dest_y - y_offset,
1933 dither, x_dither, y_dither);
1939 gint x_offset, y_offset;
1940 gdk_window_get_offsets (drawable, &x_offset, &y_offset);
1942 if (private->paint_stack)
1944 GdkWindowPaint *paint = private->paint_stack->data;
1945 gdk_draw_pixbuf (paint->pixmap, gc, pixbuf, src_x, src_y,
1946 dest_x - x_offset, dest_y - y_offset,
1948 dither, x_dither - x_offset, y_dither - y_offset);
1951 gdk_draw_pixbuf (private->impl, gc, pixbuf, src_x, src_y,
1952 dest_x - x_offset, dest_y - y_offset,
1954 dither, x_dither, y_dither);
1959 gdk_window_draw_trapezoids (GdkDrawable *drawable,
1961 GdkTrapezoid *trapezoids,
1964 GdkWindowObject *private = (GdkWindowObject *)drawable;
1965 GdkTrapezoid *new_trapezoids = NULL;
1969 if (GDK_WINDOW_DESTROYED (drawable))
1972 if (x_offset != 0 || y_offset != 0)
1976 new_trapezoids = g_new (GdkTrapezoid, n_trapezoids);
1977 for (i=0; i < n_trapezoids; i++)
1979 new_trapezoids[i].y1 = trapezoids[i].y1 - y_offset;
1980 new_trapezoids[i].x11 = trapezoids[i].x11 - x_offset;
1981 new_trapezoids[i].x21 = trapezoids[i].x21 - x_offset;
1982 new_trapezoids[i].y2 = trapezoids[i].y2 - y_offset;
1983 new_trapezoids[i].x12 = trapezoids[i].x12 - x_offset;
1984 new_trapezoids[i].x22 = trapezoids[i].x22 - x_offset;
1987 trapezoids = new_trapezoids;
1990 if (private->paint_stack)
1992 GdkWindowPaint *paint = private->paint_stack->data;
1993 gdk_draw_trapezoids (paint->pixmap, gc, trapezoids, n_trapezoids);
1996 gdk_draw_trapezoids (private->impl, gc, trapezoids, n_trapezoids);
1999 g_free (new_trapezoids);
2005 gdk_window_real_get_size (GdkDrawable *drawable,
2009 g_return_if_fail (GDK_IS_WINDOW (drawable));
2011 gdk_drawable_get_size (GDK_WINDOW_OBJECT (drawable)->impl,
2016 gdk_window_real_get_visual (GdkDrawable *drawable)
2018 GdkColormap *colormap;
2020 g_return_val_if_fail (GDK_IS_WINDOW (drawable), NULL);
2022 colormap = gdk_drawable_get_colormap (drawable);
2023 return colormap ? gdk_colormap_get_visual (colormap) : NULL;
2027 gdk_window_real_get_depth (GdkDrawable *drawable)
2029 g_return_val_if_fail (GDK_IS_WINDOW (drawable), 0);
2031 return ((GdkWindowObject *)GDK_WINDOW (drawable))->depth;
2035 gdk_window_real_get_screen (GdkDrawable *drawable)
2037 return gdk_drawable_get_screen (GDK_WINDOW_OBJECT (drawable)->impl);
2041 gdk_window_real_set_colormap (GdkDrawable *drawable,
2044 g_return_if_fail (GDK_IS_WINDOW (drawable));
2046 if (GDK_WINDOW_DESTROYED (drawable))
2049 gdk_drawable_set_colormap (((GdkWindowObject*)drawable)->impl, cmap);
2053 gdk_window_real_get_colormap (GdkDrawable *drawable)
2055 g_return_val_if_fail (GDK_IS_WINDOW (drawable), NULL);
2057 if (GDK_WINDOW_DESTROYED (drawable))
2060 return gdk_drawable_get_colormap (((GdkWindowObject*)drawable)->impl);
2064 gdk_window_copy_to_image (GdkDrawable *drawable,
2073 gint x_offset, y_offset;
2075 g_return_val_if_fail (GDK_IS_WINDOW (drawable), NULL);
2077 if (GDK_WINDOW_DESTROYED (drawable))
2080 /* If we're here, a composite image was not necessary, so
2081 * we can ignore the paint stack.
2084 _gdk_windowing_window_get_offsets (drawable, &x_offset, &y_offset);
2086 return gdk_drawable_copy_to_image (((GdkWindowObject*)drawable)->impl,
2094 /* Code for dirty-region queueing
2096 static GSList *update_windows = NULL;
2097 static guint update_idle = 0;
2098 static gboolean debug_updates = FALSE;
2101 gdk_window_update_idle (gpointer data)
2103 GDK_THREADS_ENTER ();
2104 gdk_window_process_all_updates ();
2105 GDK_THREADS_LEAVE ();
2111 gdk_window_schedule_update (GdkWindow *window)
2113 if (window && GDK_WINDOW_OBJECT (window)->update_freeze_count)
2118 update_idle = g_idle_add_full (GDK_PRIORITY_REDRAW,
2119 gdk_window_update_idle, NULL, NULL);
2124 gdk_window_process_updates_internal (GdkWindow *window)
2126 GdkWindowObject *private = (GdkWindowObject *)window;
2127 gboolean save_region = FALSE;
2129 /* If an update got queued during update processing, we can get a
2130 * window in the update queue that has an empty update_area.
2133 if (private->update_area)
2135 GdkRegion *update_area = private->update_area;
2136 private->update_area = NULL;
2138 if (_gdk_event_func && gdk_window_is_viewable (window))
2140 GdkRectangle window_rect;
2141 GdkRegion *expose_region;
2142 GdkRegion *window_region;
2147 /* Make sure we see the red invalid area before redrawing. */
2148 gdk_display_sync (gdk_drawable_get_display (window));
2152 save_region = _gdk_windowing_window_queue_antiexpose (window, update_area);
2155 expose_region = gdk_region_copy (update_area);
2157 expose_region = update_area;
2159 gdk_drawable_get_size (GDK_DRAWABLE (private), &width, &height);
2163 window_rect.width = width;
2164 window_rect.height = height;
2166 window_region = gdk_region_rectangle (&window_rect);
2167 gdk_region_intersect (expose_region,
2169 gdk_region_destroy (window_region);
2171 if (!gdk_region_empty (expose_region) &&
2172 (private->event_mask & GDK_EXPOSURE_MASK))
2176 event.expose.type = GDK_EXPOSE;
2177 event.expose.window = g_object_ref (window);
2178 event.expose.count = 0;
2179 event.expose.region = expose_region;
2180 gdk_region_get_clipbox (expose_region, &event.expose.area);
2182 (*_gdk_event_func) (&event, _gdk_event_data);
2184 g_object_unref (window);
2187 if (expose_region != update_area)
2188 gdk_region_destroy (expose_region);
2191 gdk_region_destroy (update_area);
2196 flush_all_displays (void)
2198 GSList *displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
2201 for (tmp_list = displays; tmp_list; tmp_list = tmp_list->next)
2202 gdk_display_flush (tmp_list->data);
2204 g_slist_free (displays);
2208 * gdk_window_process_all_updates:
2210 * Calls gdk_window_process_updates() for all windows (see #GdkWindow)
2211 * in the application.
2215 gdk_window_process_all_updates (void)
2217 GSList *old_update_windows = update_windows;
2218 GSList *tmp_list = update_windows;
2221 g_source_remove (update_idle);
2223 update_windows = NULL;
2226 g_slist_foreach (old_update_windows, (GFunc)g_object_ref, NULL);
2230 GdkWindowObject *private = (GdkWindowObject *)tmp_list->data;
2232 if (private->update_freeze_count)
2233 update_windows = g_slist_prepend (update_windows, private);
2235 gdk_window_process_updates_internal (tmp_list->data);
2237 g_object_unref (tmp_list->data);
2238 tmp_list = tmp_list->next;
2241 g_slist_free (old_update_windows);
2243 flush_all_displays ();
2247 * gdk_window_process_updates:
2248 * @window: a #GdkWindow
2249 * @update_children: whether to also process updates for child windows
2251 * Sends one or more expose events to @window. The areas in each
2252 * expose event will cover the entire update area for the window (see
2253 * gdk_window_invalidate_region() for details). Normally GDK calls
2254 * gdk_window_process_all_updates() on your behalf, so there's no
2255 * need to call this function unless you want to force expose events
2256 * to be delivered immediately and synchronously (vs. the usual
2257 * case, where GDK delivers them in an idle handler). Occasionally
2258 * this is useful to produce nicer scrolling behavior, for example.
2262 gdk_window_process_updates (GdkWindow *window,
2263 gboolean update_children)
2265 GdkWindowObject *private = (GdkWindowObject *)window;
2267 g_return_if_fail (window != NULL);
2268 g_return_if_fail (GDK_IS_WINDOW (window));
2270 if (private->update_area && !private->update_freeze_count)
2272 gdk_window_process_updates_internal (window);
2273 update_windows = g_slist_remove (update_windows, window);
2276 if (update_children)
2278 GList *tmp_list = private->children;
2281 gdk_window_process_updates (tmp_list->data, TRUE);
2282 tmp_list = tmp_list->next;
2288 * gdk_window_invalidate_rect:
2289 * @window: a #GdkWindow
2290 * @rect: rectangle to invalidate
2291 * @invalidate_children: whether to also invalidate child windows
2293 * A convenience wrapper around gdk_window_invalidate_region() which
2294 * invalidates a rectangular region. See
2295 * gdk_window_invalidate_region() for details.
2299 gdk_window_invalidate_rect (GdkWindow *window,
2301 gboolean invalidate_children)
2303 GdkRectangle window_rect;
2305 GdkWindowObject *private = (GdkWindowObject *)window;
2307 g_return_if_fail (window != NULL);
2308 g_return_if_fail (GDK_IS_WINDOW (window));
2310 if (GDK_WINDOW_DESTROYED (window))
2313 if (private->input_only || !GDK_WINDOW_IS_MAPPED (window))
2320 gdk_drawable_get_size (GDK_DRAWABLE (window),
2322 &window_rect.height);
2323 rect = &window_rect;
2326 region = gdk_region_rectangle (rect);
2327 gdk_window_invalidate_region (window, region, invalidate_children);
2328 gdk_region_destroy (region);
2332 draw_ugly_color (GdkWindow *window,
2335 /* Draw ugly color all over the newly-invalid region */
2336 GdkColor ugly_color = { 0, 50000, 10000, 10000 };
2338 GdkRectangle clipbox;
2340 ugly_gc = gdk_gc_new (window);
2341 gdk_gc_set_rgb_fg_color (ugly_gc, &ugly_color);
2342 gdk_gc_set_clip_region (ugly_gc, region);
2344 gdk_region_get_clipbox (region, &clipbox);
2346 gdk_draw_rectangle (window,
2349 clipbox.x, clipbox.y,
2350 clipbox.width, clipbox.height);
2352 g_object_unref (ugly_gc);
2356 * gdk_window_invalidate_maybe_recurse:
2357 * @window: a #GdkWindow
2358 * @region: a #GdkRegion
2359 * @child_func: function to use to decide if to recurse to a child,
2360 * %NULL means never recurse.
2361 * @user_data: data passed to @child_func
2363 * Adds @region to the update area for @window. The update area is the
2364 * region that needs to be redrawn, or "dirty region." The call
2365 * gdk_window_process_updates() sends one or more expose events to the
2366 * window, which together cover the entire update area. An
2367 * application would normally redraw the contents of @window in
2368 * response to those expose events.
2370 * GDK will call gdk_window_process_all_updates() on your behalf
2371 * whenever your program returns to the main loop and becomes idle, so
2372 * normally there's no need to do that manually, you just need to
2373 * invalidate regions that you know should be redrawn.
2375 * The @child_func parameter controls whether the region of
2376 * each child window that intersects @region will also be invalidated.
2377 * Only children for which @child_func returns TRUE will have the area
2381 gdk_window_invalidate_maybe_recurse (GdkWindow *window,
2383 gboolean (*child_func) (GdkWindow *, gpointer),
2386 GdkWindowObject *private = (GdkWindowObject *)window;
2387 GdkRegion *visible_region;
2389 g_return_if_fail (window != NULL);
2390 g_return_if_fail (GDK_IS_WINDOW (window));
2392 if (GDK_WINDOW_DESTROYED (window))
2395 if (private->input_only || !GDK_WINDOW_IS_MAPPED (window))
2398 visible_region = gdk_drawable_get_visible_region (window);
2399 gdk_region_intersect (visible_region, region);
2401 if (!gdk_region_empty (visible_region))
2404 draw_ugly_color (window, region);
2406 if (private->update_area)
2408 gdk_region_union (private->update_area, visible_region);
2412 update_windows = g_slist_prepend (update_windows, window);
2413 private->update_area = gdk_region_copy (visible_region);
2415 gdk_window_schedule_update (window);
2422 tmp_list = private->children;
2425 GdkWindowObject *child = tmp_list->data;
2426 tmp_list = tmp_list->next;
2428 if (!child->input_only && (*child_func) ((GdkWindow *)child, user_data))
2430 GdkRegion *child_region;
2433 gdk_window_get_position ((GdkWindow *)child, &x, &y);
2435 /* This copy could be saved with a little more complexity */
2436 child_region = gdk_region_copy (visible_region);
2437 gdk_region_offset (child_region, - x, - y);
2439 gdk_window_invalidate_maybe_recurse ((GdkWindow *)child, child_region, child_func, user_data);
2441 gdk_region_destroy (child_region);
2447 gdk_region_destroy (visible_region);
2451 true_predicate (GdkWindow *window,
2458 * gdk_window_invalidate_region:
2459 * @window: a #GdkWindow
2460 * @region: a #GdkRegion
2461 * @invalidate_children: %TRUE to also invalidate child windows
2463 * Adds @region to the update area for @window. The update area is the
2464 * region that needs to be redrawn, or "dirty region." The call
2465 * gdk_window_process_updates() sends one or more expose events to the
2466 * window, which together cover the entire update area. An
2467 * application would normally redraw the contents of @window in
2468 * response to those expose events.
2470 * GDK will call gdk_window_process_all_updates() on your behalf
2471 * whenever your program returns to the main loop and becomes idle, so
2472 * normally there's no need to do that manually, you just need to
2473 * invalidate regions that you know should be redrawn.
2475 * The @invalidate_children parameter controls whether the region of
2476 * each child window that intersects @region will also be invalidated.
2477 * If %FALSE, then the update area for child windows will remain
2478 * unaffected. See gdk_window_invalidate_maybe_recurse if you need
2479 * fine grained control over which children are invalidated.
2482 gdk_window_invalidate_region (GdkWindow *window,
2484 gboolean invalidate_children)
2486 gdk_window_invalidate_maybe_recurse (window, region,
2487 invalidate_children ?
2488 true_predicate : (gboolean (*) (GdkWindow *, gpointer))NULL,
2493 * gdk_window_get_update_area:
2494 * @window: a #GdkWindow
2496 * Transfers ownership of the update area from @window to the caller
2497 * of the function. That is, after calling this function, @window will
2498 * no longer have an invalid/dirty region; the update area is removed
2499 * from @window and handed to you. If a window has no update area,
2500 * gdk_window_get_update_area() returns %NULL. You are responsible for
2501 * calling gdk_region_destroy() on the returned region if it's non-%NULL.
2503 * Return value: the update area for @window
2506 gdk_window_get_update_area (GdkWindow *window)
2508 GdkWindowObject *private = (GdkWindowObject *)window;
2509 GdkRegion *tmp_region;
2511 g_return_val_if_fail (window != NULL, NULL);
2512 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2514 if (private->update_area)
2516 tmp_region = private->update_area;
2517 private->update_area = NULL;
2519 update_windows = g_slist_remove (update_windows, window);
2528 * _gdk_window_clear_update_area:
2529 * @window: a #GdkWindow.
2531 * Internal function to clear the update area for a window. This
2532 * is called when the window is hidden or destroyed.
2535 _gdk_window_clear_update_area (GdkWindow *window)
2537 GdkWindowObject *private = (GdkWindowObject *)window;
2539 g_return_if_fail (window != NULL);
2540 g_return_if_fail (GDK_IS_WINDOW (window));
2542 if (private->update_area)
2544 update_windows = g_slist_remove (update_windows, window);
2546 gdk_region_destroy (private->update_area);
2547 private->update_area = NULL;
2552 * gdk_window_freeze_updates:
2553 * @window: a #GdkWindow
2555 * Temporarily freezes a window such that it won't receive expose
2556 * events. The window will begin receiving expose events again when
2557 * gdk_window_thaw_updates() is called. If gdk_window_freeze_updates()
2558 * has been called more than once, gdk_window_thaw_updates() must be called
2559 * an equal number of times to begin processing exposes.
2562 gdk_window_freeze_updates (GdkWindow *window)
2564 GdkWindowObject *private = (GdkWindowObject *)window;
2566 g_return_if_fail (window != NULL);
2567 g_return_if_fail (GDK_IS_WINDOW (window));
2569 private->update_freeze_count++;
2573 * gdk_window_thaw_updates:
2574 * @window: a #GdkWindow
2576 * Thaws a window frozen with gdk_window_freeze_updates().
2579 gdk_window_thaw_updates (GdkWindow *window)
2581 GdkWindowObject *private = (GdkWindowObject *)window;
2583 g_return_if_fail (window != NULL);
2584 g_return_if_fail (GDK_IS_WINDOW (window));
2585 g_return_if_fail (private->update_freeze_count > 0);
2587 if (--private->update_freeze_count == 0)
2588 gdk_window_schedule_update (window);
2592 * gdk_window_set_debug_updates:
2593 * @setting: %TRUE to turn on update debugging
2595 * With update debugging enabled, calls to
2596 * gdk_window_invalidate_region() clear the invalidated region of the
2597 * screen to a noticeable color, and GDK pauses for a short time
2598 * before sending exposes to windows during
2599 * gdk_window_process_updates(). The net effect is that you can see
2600 * the invalid region for each window and watch redraws as they
2601 * occur. This allows you to diagnose inefficiencies in your application.
2603 * In essence, because the GDK rendering model prevents all flicker,
2604 * if you are redrawing the same region 400 times you may never
2605 * notice, aside from noticing a speed problem. Enabling update
2606 * debugging causes GTK to flicker slowly and noticeably, so you can
2607 * see exactly what's being redrawn when, in what order.
2609 * The --gtk-debug=updates command line option passed to GTK+ programs
2610 * enables this debug option at application startup time. That's
2611 * usually more useful than calling gdk_window_set_debug_updates()
2612 * yourself, though you might want to use this function to enable
2613 * updates sometime after application startup time.
2617 gdk_window_set_debug_updates (gboolean setting)
2619 debug_updates = setting;
2623 * gdk_window_constrain_size:
2624 * @geometry: a #GdkGeometry structure
2625 * @flags: a mask indicating what portions of @geometry are set
2626 * @width: desired width of window
2627 * @height: desired height of the window
2628 * @new_width: location to store resulting width
2629 * @new_height: location to store resulting height
2631 * Constrains a desired width and height according to a
2632 * set of geometry hints (such as minimum and maximum size).
2635 gdk_window_constrain_size (GdkGeometry *geometry,
2642 /* This routine is partially borrowed from fvwm.
2644 * Copyright 1993, Robert Nation
2645 * You may use this code for any purpose, as long as the original
2646 * copyright remains in the source code and all documentation
2648 * which in turn borrows parts of the algorithm from uwm
2651 gint min_height = 0;
2652 gint base_width = 0;
2653 gint base_height = 0;
2656 gint max_width = G_MAXINT;
2657 gint max_height = G_MAXINT;
2659 #define FLOOR(value, base) ( ((gint) ((value) / (base))) * (base) )
2661 if ((flags & GDK_HINT_BASE_SIZE) && (flags & GDK_HINT_MIN_SIZE))
2663 base_width = geometry->base_width;
2664 base_height = geometry->base_height;
2665 min_width = geometry->min_width;
2666 min_height = geometry->min_height;
2668 else if (flags & GDK_HINT_BASE_SIZE)
2670 base_width = geometry->base_width;
2671 base_height = geometry->base_height;
2672 min_width = geometry->base_width;
2673 min_height = geometry->base_height;
2675 else if (flags & GDK_HINT_MIN_SIZE)
2677 base_width = geometry->min_width;
2678 base_height = geometry->min_height;
2679 min_width = geometry->min_width;
2680 min_height = geometry->min_height;
2683 if (flags & GDK_HINT_MAX_SIZE)
2685 max_width = geometry->max_width ;
2686 max_height = geometry->max_height;
2689 if (flags & GDK_HINT_RESIZE_INC)
2691 xinc = MAX (xinc, geometry->width_inc);
2692 yinc = MAX (yinc, geometry->height_inc);
2695 /* clamp width and height to min and max values
2697 width = CLAMP (width, min_width, max_width);
2698 height = CLAMP (height, min_height, max_height);
2700 /* shrink to base + N * inc
2702 width = base_width + FLOOR (width - base_width, xinc);
2703 height = base_height + FLOOR (height - base_height, yinc);
2705 /* constrain aspect ratio, according to:
2708 * min_aspect <= -------- <= max_aspect
2712 if (flags & GDK_HINT_ASPECT &&
2713 geometry->min_aspect > 0 &&
2714 geometry->max_aspect > 0)
2718 if (geometry->min_aspect * height > width)
2720 delta = FLOOR (height - width / geometry->min_aspect, yinc);
2721 if (height - delta >= min_height)
2725 delta = FLOOR (height * geometry->min_aspect - width, xinc);
2726 if (width + delta <= max_width)
2731 if (geometry->max_aspect * height < width)
2733 delta = FLOOR (width - height * geometry->max_aspect, xinc);
2734 if (width - delta >= min_width)
2738 delta = FLOOR (width / geometry->max_aspect - height, yinc);
2739 if (height + delta <= max_height)
2748 *new_height = height;
2752 * gdk_window_get_pointer:
2753 * @window: a #GdkWindow
2754 * @x: return location for X coordinate of pointer
2755 * @y: return location for Y coordinate of pointer
2756 * @mask: return location for modifier mask
2758 * Obtains the current pointer position and modifier state.
2759 * The position is given in coordinates relative to @window.
2761 * Return value: the window containing the pointer (as with
2762 * gdk_window_at_pointer()), or %NULL if the window containing the
2763 * pointer isn't known to GDK
2766 gdk_window_get_pointer (GdkWindow *window,
2769 GdkModifierType *mask)
2771 GdkDisplay *display;
2773 GdkModifierType tmp_mask;
2776 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
2780 display = gdk_drawable_get_display (window);
2784 GdkScreen *screen = gdk_screen_get_default ();
2786 display = gdk_screen_get_display (screen);
2787 window = gdk_screen_get_root_window (screen);
2789 GDK_NOTE (MULTIHEAD,
2790 g_message ("Passing NULL for window to gdk_window_get_pointer()\n"
2791 "is not multihead safe"));
2794 child = display->pointer_hooks->window_get_pointer (display, window, &tmp_x, &tmp_y, &tmp_mask);
2807 * gdk_window_at_pointer:
2808 * @win_x: return location for origin of the window under the pointer
2809 * @win_y: return location for origin of the window under the pointer
2811 * Obtains the window underneath the mouse pointer, returning the
2812 * location of that window in @win_x, @win_y. Returns %NULL if the
2813 * window under the mouse pointer is not known to GDK (if the window
2814 * belongs to another application and a #GdkWindow hasn't been created
2815 * for it with gdk_window_foreign_new())
2817 * NOTE: For multihead-aware widgets or applications use
2818 * gdk_display_get_window_at_pointer() instead.
2820 * Return value: window under the mouse pointer
2823 gdk_window_at_pointer (gint *win_x,
2826 return gdk_display_get_window_at_pointer (gdk_display_get_default (), win_x, win_y);
2830 * gdk_get_default_root_window:
2832 * Obtains the root window (parent all other windows are inside)
2833 * for the default display and screen.
2835 * Return value: the default root window
2838 gdk_get_default_root_window (void)
2840 return gdk_screen_get_root_window (gdk_screen_get_default ());
2844 * gdk_window_foreign_new:
2845 * @anid: a native window handle.
2847 * Wraps a native window for the default display in a #GdkWindow.
2848 * This may fail if the window has been destroyed.
2850 * For example in the X backend, a native window handle is an Xlib
2853 * Return value: the newly-created #GdkWindow wrapper for the
2854 * native window or %NULL if the window has been destroyed.
2857 gdk_window_foreign_new (GdkNativeWindow anid)
2859 return gdk_window_foreign_new_for_display (gdk_display_get_default (), anid);