]> Pileus Git - ~andy/gtk/blob - gdk/gdkgc.c
f3ac9682026c6b65146be4216ae596f9b876874a
[~andy/gtk] / gdk / gdkgc.c
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU 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.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
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.
18  */
19
20 /*
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/. 
25  */
26
27 #include "config.h"
28 #include <string.h>
29
30 #include "gdkcairo.h"
31 #include "gdkgc.h"
32 #include "gdkinternals.h"
33 #include "gdkpixmap.h"
34 #include "gdkrgb.h"
35 #include "gdkprivate.h"
36 #include "gdkalias.h"
37
38 static void gdk_gc_finalize   (GObject      *object);
39
40 typedef struct _GdkGCPrivate GdkGCPrivate;
41
42 struct _GdkGCPrivate
43 {
44   GdkRegion *clip_region;
45
46   guint32 region_tag_applied;
47   int region_tag_offset_x;
48   int region_tag_offset_y;
49   
50   GdkRegion *old_clip_region;
51   GdkPixmap *old_clip_mask;
52   
53   GdkSubwindowMode subwindow_mode;
54   
55   GdkFill fill;
56   GdkBitmap *stipple;
57   GdkPixmap *tile;
58
59   GdkPixmap *clip_mask;
60   
61   guint32 fg_pixel;
62   guint32 bg_pixel;
63 };
64
65 #define GDK_GC_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDK_TYPE_GC, GdkGCPrivate))
66
67 G_DEFINE_TYPE (GdkGC, gdk_gc, G_TYPE_OBJECT)
68
69 static void
70 gdk_gc_class_init (GdkGCClass *class)
71 {
72   GObjectClass *object_class = G_OBJECT_CLASS (class);
73   
74   object_class->finalize = gdk_gc_finalize;
75
76   g_type_class_add_private (object_class, sizeof (GdkGCPrivate));
77 }
78
79 static void
80 gdk_gc_init (GdkGC *gc)
81 {
82   GdkGCPrivate *priv = GDK_GC_GET_PRIVATE (gc);
83
84   priv->fill = GDK_SOLID;
85
86   /* These are the default X11 value, which we match. They are clearly
87    * wrong for TrueColor displays, so apps have to change them.
88    */
89   priv->fg_pixel = 0;
90   priv->bg_pixel = 1;
91 }
92
93 /**
94  * gdk_gc_new:
95  * @drawable: a #GdkDrawable. The created GC must always be used
96  *   with drawables of the same depth as this one.
97  *
98  * Create a new graphics context with default values. 
99  *
100  * Returns: the new graphics context.
101  **/
102 GdkGC*
103 gdk_gc_new (GdkDrawable *drawable)
104 {
105   g_return_val_if_fail (drawable != NULL, NULL);
106
107   return gdk_gc_new_with_values (drawable, NULL, 0);
108 }
109
110 /**
111  * gdk_gc_new_with_values:
112  * @drawable: a #GdkDrawable. The created GC must always be used
113  *   with drawables of the same depth as this one.
114  * @values: a structure containing initial values for the GC.
115  * @values_mask: a bit mask indicating which fields in @values
116  *   are set.
117  * 
118  * Create a new GC with the given initial values.
119  * 
120  * Return value: the new graphics context.
121  **/
122 GdkGC*
123 gdk_gc_new_with_values (GdkDrawable     *drawable,
124                         GdkGCValues     *values,
125                         GdkGCValuesMask  values_mask)
126 {
127   g_return_val_if_fail (drawable != NULL, NULL);
128
129   return GDK_DRAWABLE_GET_CLASS (drawable)->create_gc (drawable,
130                                                        values,
131                                                        values_mask);
132 }
133
134 /**
135  * _gdk_gc_init:
136  * @gc: a #GdkGC
137  * @drawable: a #GdkDrawable.
138  * @values: a structure containing initial values for the GC.
139  * @values_mask: a bit mask indicating which fields in @values
140  *   are set.
141  * 
142  * Does initialization of the generic portions of a #GdkGC
143  * created with the specified values and values_mask. This
144  * should be called out of the implementation of
145  * GdkDrawable.create_gc() immediately after creating the
146  * #GdkGC object.
147  **/
148 void
149 _gdk_gc_init (GdkGC           *gc,
150               GdkDrawable     *drawable,
151               GdkGCValues     *values,
152               GdkGCValuesMask  values_mask)
153 {
154   GdkGCPrivate *priv;
155
156   g_return_if_fail (GDK_IS_GC (gc));
157
158   priv = GDK_GC_GET_PRIVATE (gc);
159
160   if (values_mask & GDK_GC_CLIP_X_ORIGIN)
161     gc->clip_x_origin = values->clip_x_origin;
162   if (values_mask & GDK_GC_CLIP_Y_ORIGIN)
163     gc->clip_y_origin = values->clip_y_origin;
164   if ((values_mask & GDK_GC_CLIP_MASK) && values->clip_mask)
165     priv->clip_mask = g_object_ref (values->clip_mask);
166   if (values_mask & GDK_GC_TS_X_ORIGIN)
167     gc->ts_x_origin = values->ts_x_origin;
168   if (values_mask & GDK_GC_TS_Y_ORIGIN)
169     gc->ts_y_origin = values->ts_y_origin;
170   if (values_mask & GDK_GC_FILL)
171     priv->fill = values->fill;
172   if (values_mask & GDK_GC_STIPPLE)
173     {
174       priv->stipple = values->stipple;
175       if (priv->stipple)
176         g_object_ref (priv->stipple);
177     }
178   if (values_mask & GDK_GC_TILE)
179     {
180       priv->tile = values->tile;
181       if (priv->tile)
182         g_object_ref (priv->tile);
183     }
184   if (values_mask & GDK_GC_FOREGROUND)
185     priv->fg_pixel = values->foreground.pixel;
186   if (values_mask & GDK_GC_BACKGROUND)
187     priv->bg_pixel = values->background.pixel;
188   if (values_mask & GDK_GC_SUBWINDOW)
189     priv->subwindow_mode = values->subwindow_mode;
190
191   gc->colormap = gdk_drawable_get_colormap (drawable);
192   if (gc->colormap)
193     g_object_ref (gc->colormap);
194 }
195
196 static void
197 gdk_gc_finalize (GObject *object)
198 {
199   GdkGC *gc = GDK_GC (object);
200   GdkGCPrivate *priv = GDK_GC_GET_PRIVATE (gc);
201
202   if (priv->clip_region)
203     gdk_region_destroy (priv->clip_region);
204   if (priv->old_clip_region)
205     gdk_region_destroy (priv->old_clip_region);
206   if (priv->clip_mask)
207     g_object_unref (priv->clip_mask);
208   if (priv->old_clip_mask)
209     g_object_unref (priv->old_clip_mask);
210   if (gc->colormap)
211     g_object_unref (gc->colormap);
212   if (priv->tile)
213     g_object_unref (priv->tile);
214   if (priv->stipple)
215     g_object_unref (priv->stipple);
216
217   G_OBJECT_CLASS (gdk_gc_parent_class)->finalize (object);
218 }
219
220 /**
221  * gdk_gc_ref:
222  * @gc: a #GdkGC
223  *
224  * Deprecated function; use g_object_ref() instead.
225  *
226  * Return value: the gc.
227  **/
228 GdkGC *
229 gdk_gc_ref (GdkGC *gc)
230 {
231   return (GdkGC *) g_object_ref (gc);
232 }
233
234 /**
235  * gdk_gc_unref:
236  * @gc: a #GdkGC
237  *
238  * Decrement the reference count of @gc.
239  *
240  * Deprecated: Use g_object_unref() instead.
241  **/
242 void
243 gdk_gc_unref (GdkGC *gc)
244 {
245   g_object_unref (gc);
246 }
247
248 /**
249  * gdk_gc_get_values:
250  * @gc:  a #GdkGC.
251  * @values: the #GdkGCValues structure in which to store the results.
252  * 
253  * Retrieves the current values from a graphics context. Note that 
254  * only the pixel values of the @values->foreground and @values->background
255  * are filled, use gdk_colormap_query_color() to obtain the rgb values
256  * if you need them.
257  **/
258 void
259 gdk_gc_get_values (GdkGC       *gc,
260                    GdkGCValues *values)
261 {
262   g_return_if_fail (GDK_IS_GC (gc));
263   g_return_if_fail (values != NULL);
264
265   GDK_GC_GET_CLASS (gc)->get_values (gc, values);
266 }
267
268 /**
269  * gdk_gc_set_values:
270  * @gc: a #GdkGC
271  * @values: struct containing the new values
272  * @values_mask: mask indicating which struct fields are to be used
273  *
274  * Sets attributes of a graphics context in bulk. For each flag set in
275  * @values_mask, the corresponding field will be read from @values and
276  * set as the new value for @gc. If you're only setting a few values
277  * on @gc, calling individual "setter" functions is likely more
278  * convenient.
279  * 
280  **/
281 void
282 gdk_gc_set_values (GdkGC           *gc,
283                    GdkGCValues     *values,
284                    GdkGCValuesMask  values_mask)
285 {
286   GdkGCPrivate *priv;
287
288   g_return_if_fail (GDK_IS_GC (gc));
289   g_return_if_fail (values != NULL);
290
291   priv = GDK_GC_GET_PRIVATE (gc);
292
293   if ((values_mask & GDK_GC_CLIP_X_ORIGIN) ||
294       (values_mask & GDK_GC_CLIP_Y_ORIGIN) ||
295       (values_mask & GDK_GC_CLIP_MASK) ||
296       (values_mask & GDK_GC_SUBWINDOW))
297     _gdk_gc_remove_drawable_clip (gc);
298   
299   if (values_mask & GDK_GC_CLIP_X_ORIGIN)
300     gc->clip_x_origin = values->clip_x_origin;
301   if (values_mask & GDK_GC_CLIP_Y_ORIGIN)
302     gc->clip_y_origin = values->clip_y_origin;
303   if (values_mask & GDK_GC_TS_X_ORIGIN)
304     gc->ts_x_origin = values->ts_x_origin;
305   if (values_mask & GDK_GC_TS_Y_ORIGIN)
306     gc->ts_y_origin = values->ts_y_origin;
307   if (values_mask & GDK_GC_CLIP_MASK)
308     {
309       if (priv->clip_mask)
310         {
311           g_object_unref (priv->clip_mask);
312           priv->clip_mask = NULL;
313         }
314       if (values->clip_mask)
315         priv->clip_mask = g_object_ref (values->clip_mask);
316       
317       if (priv->clip_region)
318         {
319           gdk_region_destroy (priv->clip_region);
320           priv->clip_region = NULL;
321         }
322     }
323   if (values_mask & GDK_GC_FILL)
324     priv->fill = values->fill;
325   if (values_mask & GDK_GC_STIPPLE)
326     {
327       if (priv->stipple != values->stipple)
328         {
329           if (priv->stipple)
330             g_object_unref (priv->stipple);
331           priv->stipple = values->stipple;
332           if (priv->stipple)
333             g_object_ref (priv->stipple);
334         }
335     }
336   if (values_mask & GDK_GC_TILE)
337     {
338       if (priv->tile != values->tile)
339         {
340           if (priv->tile)
341             g_object_unref (priv->tile);
342           priv->tile = values->tile;
343           if (priv->tile)
344             g_object_ref (priv->tile);
345         }
346     }
347   if (values_mask & GDK_GC_FOREGROUND)
348     priv->fg_pixel = values->foreground.pixel;
349   if (values_mask & GDK_GC_BACKGROUND)
350     priv->bg_pixel = values->background.pixel;
351   if (values_mask & GDK_GC_SUBWINDOW)
352     priv->subwindow_mode = values->subwindow_mode;
353   
354   GDK_GC_GET_CLASS (gc)->set_values (gc, values, values_mask);
355 }
356
357 /**
358  * gdk_gc_set_foreground:
359  * @gc: a #GdkGC.
360  * @color: the new foreground color.
361  * 
362  * Sets the foreground color for a graphics context.
363  * Note that this function uses @color->pixel, use 
364  * gdk_gc_set_rgb_fg_color() to specify the foreground 
365  * color as red, green, blue components.
366  **/
367 void
368 gdk_gc_set_foreground (GdkGC          *gc,
369                        const GdkColor *color)
370 {
371   GdkGCValues values;
372
373   g_return_if_fail (GDK_IS_GC (gc));
374   g_return_if_fail (color != NULL);
375
376   values.foreground = *color;
377   gdk_gc_set_values (gc, &values, GDK_GC_FOREGROUND);
378 }
379
380 /**
381  * gdk_gc_set_background:
382  * @gc: a #GdkGC.
383  * @color: the new background color.
384  * 
385  * Sets the background color for a graphics context.
386  * Note that this function uses @color->pixel, use 
387  * gdk_gc_set_rgb_bg_color() to specify the background 
388  * color as red, green, blue components.
389  **/
390 void
391 gdk_gc_set_background (GdkGC          *gc,
392                        const GdkColor *color)
393 {
394   GdkGCValues values;
395
396   g_return_if_fail (GDK_IS_GC (gc));
397   g_return_if_fail (color != NULL);
398
399   values.background = *color;
400   gdk_gc_set_values (gc, &values, GDK_GC_BACKGROUND);
401 }
402
403 /**
404  * gdk_gc_set_font:
405  * @gc: a #GdkGC.
406  * @font: the new font. 
407  * 
408  * Sets the font for a graphics context. (Note that
409  * all text-drawing functions in GDK take a @font
410  * argument; the value set here is used when that
411  * argument is %NULL.)
412  **/
413 void
414 gdk_gc_set_font (GdkGC   *gc,
415                  GdkFont *font)
416 {
417   GdkGCValues values;
418
419   g_return_if_fail (GDK_IS_GC (gc));
420   g_return_if_fail (font != NULL);
421
422   values.font = font;
423   gdk_gc_set_values (gc, &values, GDK_GC_FONT);
424 }
425
426 /**
427  * gdk_gc_set_function:
428  * @gc: a #GdkGC.
429  * @function: the #GdkFunction to use
430  * 
431  * Determines how the current pixel values and the
432  * pixel values being drawn are combined to produce
433  * the final pixel values.
434  **/
435 void
436 gdk_gc_set_function (GdkGC       *gc,
437                      GdkFunction  function)
438 {
439   GdkGCValues values;
440
441   g_return_if_fail (GDK_IS_GC (gc));
442
443   values.function = function;
444   gdk_gc_set_values (gc, &values, GDK_GC_FUNCTION);
445 }
446
447 /**
448  * gdk_gc_set_fill:
449  * @gc: a #GdkGC.
450  * @fill: the new fill mode.
451  * 
452  * Set the fill mode for a graphics context.
453  **/
454 void
455 gdk_gc_set_fill (GdkGC   *gc,
456                  GdkFill  fill)
457 {
458   GdkGCValues values;
459
460   g_return_if_fail (GDK_IS_GC (gc));
461
462   values.fill = fill;
463   gdk_gc_set_values (gc, &values, GDK_GC_FILL);
464 }
465
466 /**
467  * gdk_gc_set_tile:
468  * @gc:  a #GdkGC.
469  * @tile:  the new tile pixmap.
470  * 
471  * Set a tile pixmap for a graphics context.
472  * This will only be used if the fill mode
473  * is %GDK_TILED.
474  **/
475 void
476 gdk_gc_set_tile (GdkGC     *gc,
477                  GdkPixmap *tile)
478 {
479   GdkGCValues values;
480
481   g_return_if_fail (GDK_IS_GC (gc));
482
483   values.tile = tile;
484   gdk_gc_set_values (gc, &values, GDK_GC_TILE);
485 }
486
487 /**
488  * gdk_gc_set_stipple:
489  * @gc: a #GdkGC.
490  * @stipple: the new stipple bitmap.
491  * 
492  * Set the stipple bitmap for a graphics context. The
493  * stipple will only be used if the fill mode is
494  * %GDK_STIPPLED or %GDK_OPAQUE_STIPPLED.
495  **/
496 void
497 gdk_gc_set_stipple (GdkGC     *gc,
498                     GdkPixmap *stipple)
499 {
500   GdkGCValues values;
501
502   g_return_if_fail (GDK_IS_GC (gc));
503
504   values.stipple = stipple;
505   gdk_gc_set_values (gc, &values, GDK_GC_STIPPLE);
506 }
507
508 /**
509  * gdk_gc_set_ts_origin:
510  * @gc:  a #GdkGC.
511  * @x: the x-coordinate of the origin.
512  * @y: the y-coordinate of the origin.
513  * 
514  * Set the origin when using tiles or stipples with
515  * the GC. The tile or stipple will be aligned such
516  * that the upper left corner of the tile or stipple
517  * will coincide with this point.
518  **/
519 void
520 gdk_gc_set_ts_origin (GdkGC *gc,
521                       gint   x,
522                       gint   y)
523 {
524   GdkGCValues values;
525
526   g_return_if_fail (GDK_IS_GC (gc));
527
528   values.ts_x_origin = x;
529   values.ts_y_origin = y;
530   
531   gdk_gc_set_values (gc, &values,
532                      GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN);
533 }
534
535 /**
536  * gdk_gc_set_clip_origin:
537  * @gc: a #GdkGC.
538  * @x: the x-coordinate of the origin.
539  * @y: the y-coordinate of the origin.
540  * 
541  * Sets the origin of the clip mask. The coordinates are
542  * interpreted relative to the upper-left corner of
543  * the destination drawable of the current operation.
544  **/
545 void
546 gdk_gc_set_clip_origin (GdkGC *gc,
547                         gint   x,
548                         gint   y)
549 {
550   GdkGCValues values;
551
552   g_return_if_fail (GDK_IS_GC (gc));
553
554   values.clip_x_origin = x;
555   values.clip_y_origin = y;
556   
557   gdk_gc_set_values (gc, &values,
558                      GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN);
559 }
560
561 /**
562  * gdk_gc_set_clip_mask:
563  * @gc: the #GdkGC.
564  * @mask: a bitmap.
565  * 
566  * Sets the clip mask for a graphics context from a bitmap.
567  * The clip mask is interpreted relative to the clip
568  * origin. (See gdk_gc_set_clip_origin()).
569  **/
570 void
571 gdk_gc_set_clip_mask (GdkGC     *gc,
572                       GdkBitmap *mask)
573 {
574   GdkGCValues values;
575   
576   g_return_if_fail (GDK_IS_GC (gc));
577   
578   values.clip_mask = mask;
579   gdk_gc_set_values (gc, &values, GDK_GC_CLIP_MASK);
580 }
581
582 /* Takes ownership of passed in region */
583 static void
584 _gdk_gc_set_clip_region_real (GdkGC     *gc,
585                               GdkRegion *region,
586                               gboolean reset_origin)
587 {
588   GdkGCPrivate *priv = GDK_GC_GET_PRIVATE (gc);
589
590   if (priv->clip_mask)
591     {
592       g_object_unref (priv->clip_mask);
593       priv->clip_mask = NULL;
594     }
595   
596   if (priv->clip_region)
597     gdk_region_destroy (priv->clip_region);
598
599   priv->clip_region = region;
600
601   _gdk_windowing_gc_set_clip_region (gc, region, reset_origin);
602 }
603
604 /* Doesn't copy region, allows not to reset origin */
605 void
606 _gdk_gc_set_clip_region_internal (GdkGC     *gc,
607                                   GdkRegion *region,
608                                   gboolean reset_origin)
609 {
610   _gdk_gc_remove_drawable_clip (gc);
611   _gdk_gc_set_clip_region_real (gc, region, reset_origin);
612 }
613
614
615 /* returns old clip region */
616 void
617 _gdk_gc_add_drawable_clip (GdkGC     *gc,
618                            guint32    region_tag,
619                            GdkRegion *region,
620                            int        offset_x,
621                            int        offset_y)
622 {
623   GdkGCPrivate *priv = GDK_GC_GET_PRIVATE (gc);
624
625   if (priv->region_tag_applied == region_tag &&
626       offset_x == priv->region_tag_offset_x &&
627       offset_y == priv->region_tag_offset_y)
628     return; /* Already appied this drawable region */
629   
630   if (priv->region_tag_applied)
631     _gdk_gc_remove_drawable_clip (gc);
632
633   region = gdk_region_copy (region);
634   if (offset_x != 0 || offset_y != 0)
635     gdk_region_offset (region, offset_x, offset_y);
636
637   if (priv->clip_mask)
638     {
639       int w, h;
640       GdkPixmap *new_mask;
641       GdkGC *tmp_gc;
642       GdkColor black = {0, 0, 0, 0};
643       
644       priv->old_clip_mask = g_object_ref (priv->clip_mask);
645       gdk_drawable_get_size (priv->old_clip_mask, &w, &h);
646
647       new_mask = gdk_pixmap_new (priv->old_clip_mask, w, h, -1);
648       tmp_gc = _gdk_drawable_get_scratch_gc ((GdkDrawable *)new_mask, FALSE);
649
650       gdk_gc_set_foreground (tmp_gc, &black);
651       gdk_draw_rectangle (new_mask, tmp_gc, TRUE, 0, 0, -1, -1);
652       _gdk_gc_set_clip_region_internal (tmp_gc, region, TRUE); /* Takes ownership of region */
653       gdk_draw_drawable  (new_mask,
654                           tmp_gc,
655                           priv->old_clip_mask,
656                           0, 0,
657                           0, 0,
658                           -1, -1);
659       gdk_gc_set_clip_region (tmp_gc, NULL);
660       gdk_gc_set_clip_mask (gc, new_mask);
661     }
662   else
663     {
664       priv->old_clip_region = priv->clip_region;
665       priv->clip_region = region;
666       if (priv->old_clip_region)
667         gdk_region_intersect (region, priv->old_clip_region);
668       
669       _gdk_windowing_gc_set_clip_region (gc, priv->clip_region, FALSE);
670     }
671
672   priv->region_tag_applied = region_tag;
673   priv->region_tag_offset_x = offset_x;
674   priv->region_tag_offset_y = offset_y;
675 }
676
677 void
678 _gdk_gc_remove_drawable_clip (GdkGC *gc)
679 {
680   GdkGCPrivate *priv = GDK_GC_GET_PRIVATE (gc);
681
682   if (priv->region_tag_applied)
683     {
684       priv->region_tag_applied = 0;
685       if (priv->old_clip_mask)
686         {
687           gdk_gc_set_clip_mask (gc, priv->old_clip_mask);
688           g_object_unref (priv->old_clip_mask);
689           priv->old_clip_mask = NULL;
690         }
691       else
692         {
693           _gdk_gc_set_clip_region_real (gc, priv->old_clip_region, FALSE);
694           priv->old_clip_region = NULL;
695         }
696     }
697 }
698
699 /**
700  * gdk_gc_set_clip_rectangle:
701  * @gc: a #GdkGC.
702  * @rectangle: the rectangle to clip to.
703  * 
704  * Sets the clip mask for a graphics context from a
705  * rectangle. The clip mask is interpreted relative to the clip
706  * origin. (See gdk_gc_set_clip_origin()).
707  **/
708 void
709 gdk_gc_set_clip_rectangle (GdkGC              *gc,
710                            const GdkRectangle *rectangle)
711 {
712   GdkRegion *region;
713   
714   g_return_if_fail (GDK_IS_GC (gc));
715
716   _gdk_gc_remove_drawable_clip (gc);
717   
718   if (rectangle)
719     region = gdk_region_rectangle (rectangle);
720   else
721     region = NULL;
722
723   _gdk_gc_set_clip_region_real (gc, region, TRUE);
724 }
725
726 /**
727  * gdk_gc_set_clip_region:
728  * @gc: a #GdkGC.
729  * @region: the #GdkRegion. 
730  * 
731  * Sets the clip mask for a graphics context from a region structure.
732  * The clip mask is interpreted relative to the clip origin. (See
733  * gdk_gc_set_clip_origin()).
734  **/
735 void
736 gdk_gc_set_clip_region (GdkGC           *gc,
737                         const GdkRegion *region)
738 {
739   GdkRegion *copy;
740
741   g_return_if_fail (GDK_IS_GC (gc));
742
743   _gdk_gc_remove_drawable_clip (gc);
744   
745   if (region)
746     copy = gdk_region_copy (region);
747   else
748     copy = NULL;
749
750   _gdk_gc_set_clip_region_real (gc, copy, TRUE);
751 }
752
753 /**
754  * _gdk_gc_get_clip_region:
755  * @gc: a #GdkGC
756  * 
757  * Gets the current clip region for @gc, if any.
758  * 
759  * Return value: the clip region for the GC, or %NULL.
760  *   (if a clip mask is set, the return will be %NULL)
761  *   This value is owned by the GC and must not be freed.
762  **/
763 GdkRegion *
764 _gdk_gc_get_clip_region (GdkGC *gc)
765 {
766   g_return_val_if_fail (GDK_IS_GC (gc), NULL);
767
768   return GDK_GC_GET_PRIVATE (gc)->clip_region;
769 }
770
771 /**
772  * _gdk_gc_get_fill:
773  * @gc: a #GdkGC
774  * 
775  * Gets the current file style for the GC
776  * 
777  * Return value: the file style for the GC
778  **/
779 GdkFill
780 _gdk_gc_get_fill (GdkGC *gc)
781 {
782   g_return_val_if_fail (GDK_IS_GC (gc), GDK_SOLID);
783
784   return GDK_GC_GET_PRIVATE (gc)->fill;
785 }
786
787 /**
788  * _gdk_gc_get_tile:
789  * @gc: a #GdkGC
790  * 
791  * Gets the tile pixmap for @gc, if any
792  * 
793  * Return value: the tile set on the GC, or %NULL. The
794  *   value is owned by the GC and must not be freed.
795  **/
796 GdkPixmap *
797 _gdk_gc_get_tile (GdkGC *gc)
798 {
799   g_return_val_if_fail (GDK_IS_GC (gc), NULL);
800
801   return GDK_GC_GET_PRIVATE (gc)->tile;
802 }
803
804 /**
805  * _gdk_gc_get_stipple:
806  * @gc: a #GdkGC
807  * 
808  * Gets the stipple pixmap for @gc, if any
809  * 
810  * Return value: the stipple set on the GC, or %NULL. The
811  *   value is owned by the GC and must not be freed.
812  **/
813 GdkBitmap *
814 _gdk_gc_get_stipple (GdkGC *gc)
815 {
816   g_return_val_if_fail (GDK_IS_GC (gc), NULL);
817
818   return GDK_GC_GET_PRIVATE (gc)->stipple;
819 }
820
821 /**
822  * _gdk_gc_get_fg_pixel:
823  * @gc: a #GdkGC
824  * 
825  * Gets the foreground pixel value for @gc. If the
826  * foreground pixel has never been set, returns the
827  * default value 0.
828  * 
829  * Return value: the foreground pixel value of the GC
830  **/
831 guint32
832 _gdk_gc_get_fg_pixel (GdkGC *gc)
833 {
834   g_return_val_if_fail (GDK_IS_GC (gc), 0);
835   
836   return GDK_GC_GET_PRIVATE (gc)->fg_pixel;
837 }
838
839 /**
840  * _gdk_gc_get_bg_pixel:
841  * @gc: a #GdkGC
842  * 
843  * Gets the background pixel value for @gc.If the
844  * foreground pixel has never been set, returns the
845  * default value 1.
846  * 
847  * Return value: the foreground pixel value of the GC
848  **/
849 guint32
850 _gdk_gc_get_bg_pixel (GdkGC *gc)
851 {
852   g_return_val_if_fail (GDK_IS_GC (gc), 0);
853   
854   return GDK_GC_GET_PRIVATE (gc)->bg_pixel;
855 }
856
857 /**
858  * gdk_gc_set_subwindow:
859  * @gc: a #GdkGC.
860  * @mode: the subwindow mode.
861  * 
862  * Sets how drawing with this GC on a window will affect child
863  * windows of that window. 
864  **/
865 void
866 gdk_gc_set_subwindow (GdkGC            *gc,
867                       GdkSubwindowMode  mode)
868 {
869   GdkGCValues values;
870   GdkGCPrivate *priv = GDK_GC_GET_PRIVATE (gc);
871
872   g_return_if_fail (GDK_IS_GC (gc));
873
874   /* This could get called a lot to reset the subwindow mode in
875      the client side clipping, so bail out early */ 
876   if (priv->subwindow_mode == mode)
877     return;
878   
879   values.subwindow_mode = mode;
880   gdk_gc_set_values (gc, &values, GDK_GC_SUBWINDOW);
881 }
882
883 GdkSubwindowMode
884 _gdk_gc_get_subwindow (GdkGC *gc)
885 {
886   GdkGCPrivate *priv = GDK_GC_GET_PRIVATE (gc);
887
888   return priv->subwindow_mode;
889 }
890
891 /**
892  * gdk_gc_set_exposures:
893  * @gc: a #GdkGC.
894  * @exposures: if %TRUE, exposure events will be generated.
895  * 
896  * Sets whether copying non-visible portions of a drawable
897  * using this graphics context generate exposure events
898  * for the corresponding regions of the destination
899  * drawable. (See gdk_draw_drawable()).
900  **/
901 void
902 gdk_gc_set_exposures (GdkGC     *gc,
903                       gboolean   exposures)
904 {
905   GdkGCValues values;
906
907   g_return_if_fail (GDK_IS_GC (gc));
908
909   values.graphics_exposures = exposures;
910   gdk_gc_set_values (gc, &values, GDK_GC_EXPOSURES);
911 }
912
913 /**
914  * gdk_gc_set_line_attributes:
915  * @gc: a #GdkGC.
916  * @line_width: the width of lines.
917  * @line_style: the dash-style for lines.
918  * @cap_style: the manner in which the ends of lines are drawn.
919  * @join_style: the in which lines are joined together.
920  * 
921  * Sets various attributes of how lines are drawn. See
922  * the corresponding members of #GdkGCValues for full
923  * explanations of the arguments.
924  **/
925 void
926 gdk_gc_set_line_attributes (GdkGC       *gc,
927                             gint         line_width,
928                             GdkLineStyle line_style,
929                             GdkCapStyle  cap_style,
930                             GdkJoinStyle join_style)
931 {
932   GdkGCValues values;
933
934   values.line_width = line_width;
935   values.line_style = line_style;
936   values.cap_style = cap_style;
937   values.join_style = join_style;
938
939   gdk_gc_set_values (gc, &values,
940                      GDK_GC_LINE_WIDTH |
941                      GDK_GC_LINE_STYLE |
942                      GDK_GC_CAP_STYLE |
943                      GDK_GC_JOIN_STYLE);
944 }
945
946 /**
947  * gdk_gc_set_dashes:
948  * @gc: a #GdkGC.
949  * @dash_offset: the phase of the dash pattern.
950  * @dash_list: an array of dash lengths.
951  * @n: the number of elements in @dash_list.
952  * 
953  * Sets the way dashed-lines are drawn. Lines will be
954  * drawn with alternating on and off segments of the
955  * lengths specified in @dash_list. The manner in
956  * which the on and off segments are drawn is determined
957  * by the @line_style value of the GC. (This can
958  * be changed with gdk_gc_set_line_attributes().)
959  *
960  * The @dash_offset defines the phase of the pattern, 
961  * specifying how many pixels into the dash-list the pattern 
962  * should actually begin.
963  **/
964 void
965 gdk_gc_set_dashes (GdkGC *gc,
966                    gint   dash_offset,
967                    gint8  dash_list[],
968                    gint   n)
969 {
970   g_return_if_fail (GDK_IS_GC (gc));
971   g_return_if_fail (dash_list != NULL);
972
973   GDK_GC_GET_CLASS (gc)->set_dashes (gc, dash_offset, dash_list, n);
974 }
975
976 /**
977  * gdk_gc_offset:
978  * @gc: a #GdkGC
979  * @x_offset: amount by which to offset the GC in the X direction
980  * @y_offset: amount by which to offset the GC in the Y direction
981  * 
982  * Offset attributes such as the clip and tile-stipple origins
983  * of the GC so that drawing at x - x_offset, y - y_offset with
984  * the offset GC  has the same effect as drawing at x, y with the original
985  * GC.
986  **/
987 void
988 gdk_gc_offset (GdkGC *gc,
989                gint   x_offset,
990                gint   y_offset)
991 {
992   if (x_offset != 0 || y_offset != 0)
993     {
994       GdkGCValues values;
995
996       values.clip_x_origin = gc->clip_x_origin - x_offset;
997       values.clip_y_origin = gc->clip_y_origin - y_offset;
998       values.ts_x_origin = gc->ts_x_origin - x_offset;
999       values.ts_y_origin = gc->ts_y_origin - y_offset;
1000       
1001       gdk_gc_set_values (gc, &values,
1002                          GDK_GC_CLIP_X_ORIGIN |
1003                          GDK_GC_CLIP_Y_ORIGIN |
1004                          GDK_GC_TS_X_ORIGIN |
1005                          GDK_GC_TS_Y_ORIGIN);
1006     }
1007 }
1008
1009 /**
1010  * gdk_gc_copy:
1011  * @dst_gc: the destination graphics context.
1012  * @src_gc: the source graphics context.
1013  * 
1014  * Copy the set of values from one graphics context
1015  * onto another graphics context.
1016  **/
1017 void
1018 gdk_gc_copy (GdkGC *dst_gc,
1019              GdkGC *src_gc)
1020 {
1021   GdkGCPrivate *dst_priv, *src_priv;
1022   
1023   g_return_if_fail (GDK_IS_GC (dst_gc));
1024   g_return_if_fail (GDK_IS_GC (src_gc));
1025
1026   dst_priv = GDK_GC_GET_PRIVATE (dst_gc);
1027   src_priv = GDK_GC_GET_PRIVATE (src_gc);
1028
1029   _gdk_windowing_gc_copy (dst_gc, src_gc);
1030
1031   dst_gc->clip_x_origin = src_gc->clip_x_origin;
1032   dst_gc->clip_y_origin = src_gc->clip_y_origin;
1033   dst_gc->ts_x_origin = src_gc->ts_x_origin;
1034   dst_gc->ts_y_origin = src_gc->ts_y_origin;
1035
1036   if (src_gc->colormap)
1037     g_object_ref (src_gc->colormap);
1038
1039   if (dst_gc->colormap)
1040     g_object_unref (dst_gc->colormap);
1041
1042   dst_gc->colormap = src_gc->colormap;
1043
1044   if (dst_priv->clip_region)
1045     gdk_region_destroy (dst_priv->clip_region);
1046
1047   if (src_priv->clip_region)
1048     dst_priv->clip_region = gdk_region_copy (src_priv->clip_region);
1049   else
1050     dst_priv->clip_region = NULL;
1051
1052   dst_priv->region_tag_applied = src_priv->region_tag_applied;
1053   
1054   if (dst_priv->old_clip_region)
1055     gdk_region_destroy (dst_priv->old_clip_region);
1056
1057   if (src_priv->old_clip_region)
1058     dst_priv->old_clip_region = gdk_region_copy (src_priv->old_clip_region);
1059   else
1060     dst_priv->old_clip_region = NULL;
1061
1062   if (src_priv->clip_mask)
1063     dst_priv->clip_mask = g_object_ref (src_priv->clip_mask);
1064   else
1065     dst_priv->clip_mask = NULL;
1066   
1067   if (src_priv->old_clip_mask)
1068     dst_priv->old_clip_mask = g_object_ref (src_priv->old_clip_mask);
1069   else
1070     dst_priv->old_clip_mask = NULL;
1071   
1072   dst_priv->fill = src_priv->fill;
1073   
1074   if (dst_priv->stipple)
1075     g_object_unref (dst_priv->stipple);
1076   dst_priv->stipple = src_priv->stipple;
1077   if (dst_priv->stipple)
1078     g_object_ref (dst_priv->stipple);
1079   
1080   if (dst_priv->tile)
1081     g_object_unref (dst_priv->tile);
1082   dst_priv->tile = src_priv->tile;
1083   if (dst_priv->tile)
1084     g_object_ref (dst_priv->tile);
1085
1086   dst_priv->fg_pixel = src_priv->fg_pixel;
1087   dst_priv->bg_pixel = src_priv->bg_pixel;
1088   dst_priv->subwindow_mode = src_priv->subwindow_mode;
1089 }
1090
1091 /**
1092  * gdk_gc_set_colormap:
1093  * @gc: a #GdkGC
1094  * @colormap: a #GdkColormap
1095  * 
1096  * Sets the colormap for the GC to the given colormap. The depth
1097  * of the colormap's visual must match the depth of the drawable
1098  * for which the GC was created.
1099  **/
1100 void
1101 gdk_gc_set_colormap (GdkGC       *gc,
1102                      GdkColormap *colormap)
1103 {
1104   g_return_if_fail (GDK_IS_GC (gc));
1105   g_return_if_fail (GDK_IS_COLORMAP (colormap));
1106
1107   if (gc->colormap != colormap)
1108     {
1109       if (gc->colormap)
1110         g_object_unref (gc->colormap);
1111
1112       gc->colormap = colormap;
1113       g_object_ref (gc->colormap);
1114     }
1115     
1116 }
1117
1118 /**
1119  * gdk_gc_get_colormap:
1120  * @gc: a #GdkGC
1121  * 
1122  * Retrieves the colormap for a given GC, if it exists.
1123  * A GC will have a colormap if the drawable for which it was created
1124  * has a colormap, or if a colormap was set explicitely with
1125  * gdk_gc_set_colormap.
1126  * 
1127  * Return value: the colormap of @gc, or %NULL if @gc doesn't have one.
1128  **/
1129 GdkColormap *
1130 gdk_gc_get_colormap (GdkGC *gc)
1131 {
1132   g_return_val_if_fail (GDK_IS_GC (gc), NULL);
1133
1134   return gc->colormap;
1135 }
1136
1137 static GdkColormap *
1138 gdk_gc_get_colormap_warn (GdkGC *gc)
1139 {
1140   GdkColormap *colormap = gdk_gc_get_colormap (gc);
1141   if (!colormap)
1142     {
1143       g_warning ("gdk_gc_set_rgb_fg_color() and gdk_gc_set_rgb_bg_color() can\n"
1144                  "only be used on GC's with a colormap. A GC will have a colormap\n"
1145                  "if it is created for a drawable with a colormap, or if a\n"
1146                  "colormap has been set explicitly with gdk_gc_set_colormap.\n");
1147       return NULL;
1148     }
1149
1150   return colormap;
1151 }
1152
1153 /**
1154  * gdk_gc_set_rgb_fg_color:
1155  * @gc: a #GdkGC
1156  * @color: an unallocated #GdkColor.
1157  * 
1158  * Set the foreground color of a GC using an unallocated color. The
1159  * pixel value for the color will be determined using GdkRGB. If the
1160  * colormap for the GC has not previously been initialized for GdkRGB,
1161  * then for pseudo-color colormaps (colormaps with a small modifiable
1162  * number of colors), a colorcube will be allocated in the colormap.
1163  * 
1164  * Calling this function for a GC without a colormap is an error.
1165  **/
1166 void
1167 gdk_gc_set_rgb_fg_color (GdkGC          *gc,
1168                          const GdkColor *color)
1169 {
1170   GdkColormap *cmap;
1171   GdkColor tmp_color;
1172
1173   g_return_if_fail (GDK_IS_GC (gc));
1174   g_return_if_fail (color != NULL);
1175
1176   cmap = gdk_gc_get_colormap_warn (gc);
1177   if (!cmap)
1178     return;
1179
1180   tmp_color = *color;
1181   gdk_rgb_find_color (cmap, &tmp_color);
1182   gdk_gc_set_foreground (gc, &tmp_color);
1183 }
1184
1185 /**
1186  * gdk_gc_set_rgb_bg_color:
1187  * @gc: a #GdkGC
1188  * @color: an unallocated #GdkColor.
1189  * 
1190  * Set the background color of a GC using an unallocated color. The
1191  * pixel value for the color will be determined using GdkRGB. If the
1192  * colormap for the GC has not previously been initialized for GdkRGB,
1193  * then for pseudo-color colormaps (colormaps with a small modifiable
1194  * number of colors), a colorcube will be allocated in the colormap.
1195  * 
1196  * Calling this function for a GC without a colormap is an error.
1197  **/
1198 void
1199 gdk_gc_set_rgb_bg_color (GdkGC          *gc,
1200                          const GdkColor *color)
1201 {
1202   GdkColormap *cmap;
1203   GdkColor tmp_color;
1204
1205   g_return_if_fail (GDK_IS_GC (gc));
1206   g_return_if_fail (color != NULL);
1207
1208   cmap = gdk_gc_get_colormap_warn (gc);
1209   if (!cmap)
1210     return;
1211
1212   tmp_color = *color;
1213   gdk_rgb_find_color (cmap, &tmp_color);
1214   gdk_gc_set_background (gc, &tmp_color);
1215 }
1216
1217 static cairo_surface_t *
1218 make_stipple_tile_surface (cairo_t   *cr,
1219                            GdkBitmap *stipple,
1220                            GdkColor  *foreground,
1221                            GdkColor  *background)
1222 {
1223   cairo_t *tmp_cr;
1224   cairo_surface_t *surface; 
1225   cairo_surface_t *alpha_surface;
1226   gint width, height;
1227
1228   gdk_drawable_get_size (stipple,
1229                          &width, &height);
1230   
1231   alpha_surface = _gdk_drawable_ref_cairo_surface (stipple);
1232   
1233   surface = cairo_surface_create_similar (cairo_get_target (cr),
1234                                           CAIRO_CONTENT_COLOR_ALPHA,
1235                                           width, height);
1236
1237   tmp_cr = cairo_create (surface);
1238   
1239   cairo_set_operator (tmp_cr, CAIRO_OPERATOR_SOURCE);
1240  
1241   if (background)
1242       gdk_cairo_set_source_color (tmp_cr, background);
1243   else
1244       cairo_set_source_rgba (tmp_cr, 0, 0, 0 ,0);
1245
1246   cairo_paint (tmp_cr);
1247
1248   cairo_set_operator (tmp_cr, CAIRO_OPERATOR_OVER);
1249
1250   gdk_cairo_set_source_color (tmp_cr, foreground);
1251   cairo_mask_surface (tmp_cr, alpha_surface, 0, 0);
1252   
1253   cairo_destroy (tmp_cr);
1254   cairo_surface_destroy (alpha_surface);
1255
1256   return surface;
1257 }
1258
1259 static void
1260 gc_get_foreground (GdkGC    *gc,
1261                    GdkColor *color)
1262 {
1263   GdkGCPrivate *priv = GDK_GC_GET_PRIVATE (gc);
1264   
1265   color->pixel = priv->bg_pixel;
1266
1267   if (gc->colormap)
1268     gdk_colormap_query_color (gc->colormap, priv->fg_pixel, color);
1269   else
1270     g_warning ("No colormap in gc_get_foreground");
1271 }
1272
1273 static void
1274 gc_get_background (GdkGC    *gc,
1275                    GdkColor *color)
1276 {
1277   GdkGCPrivate *priv = GDK_GC_GET_PRIVATE (gc);
1278   
1279   color->pixel = priv->bg_pixel;
1280
1281   if (gc->colormap)
1282     gdk_colormap_query_color (gc->colormap, priv->bg_pixel, color);
1283   else
1284     g_warning ("No colormap in gc_get_background");
1285 }
1286
1287 /**
1288  * _gdk_gc_update_context:
1289  * @gc: a #GdkGC
1290  * @cr: a #cairo_t
1291  * @override_foreground: a foreground color to use to override the
1292  *   foreground color of the GC
1293  * @override_stipple: a stipple pattern to use to override the
1294  *   stipple from the GC. If this is present and the fill mode
1295  *   of the GC isn't %GDK_STIPPLED or %GDK_OPAQUE_STIPPLED
1296  *   the fill mode will be forced to %GDK_STIPPLED
1297  * @gc_changed: pass %FALSE if the @gc has not changed since the
1298  *     last call to this function
1299  * @target_drawable: The drawable you're drawing in. If passed in
1300  *     this is used for client side window clip emulation.
1301  * 
1302  * Set the attributes of a cairo context to match those of a #GdkGC
1303  * as far as possible. Some aspects of a #GdkGC, such as clip masks
1304  * and functions other than %GDK_COPY are not currently handled.
1305  **/
1306 void
1307 _gdk_gc_update_context (GdkGC          *gc,
1308                         cairo_t        *cr,
1309                         const GdkColor *override_foreground,
1310                         GdkBitmap      *override_stipple,
1311                         gboolean        gc_changed,
1312                         GdkDrawable    *target_drawable)
1313 {
1314   GdkGCPrivate *priv;
1315   GdkFill fill;
1316   GdkColor foreground;
1317   GdkColor background;
1318   cairo_surface_t *tile_surface = NULL;
1319   GdkBitmap *stipple = NULL;
1320
1321   g_return_if_fail (GDK_IS_GC (gc));
1322   g_return_if_fail (cr != NULL);
1323   g_return_if_fail (override_stipple == NULL || GDK_IS_PIXMAP (override_stipple));
1324
1325   priv = GDK_GC_GET_PRIVATE (gc);
1326
1327   fill = priv->fill;
1328   if (override_stipple && fill != GDK_OPAQUE_STIPPLED)
1329     fill = GDK_STIPPLED;
1330
1331   if (fill != GDK_TILED)
1332     {
1333       if (override_foreground)
1334         foreground = *override_foreground;
1335       else
1336         gc_get_foreground (gc, &foreground);
1337     }
1338
1339   if (fill == GDK_OPAQUE_STIPPLED)
1340     gc_get_background (gc, &background);
1341
1342
1343   switch (fill)
1344     {
1345     case GDK_SOLID:
1346       break;
1347     case GDK_TILED:
1348       if (!priv->tile)
1349         fill = GDK_SOLID;
1350       break;
1351     case GDK_STIPPLED:
1352     case GDK_OPAQUE_STIPPLED:
1353       if (override_stipple)
1354         stipple = override_stipple;
1355       else
1356         stipple = priv->stipple;
1357       
1358       if (!stipple)
1359         fill = GDK_SOLID;
1360       break;
1361     }
1362   
1363   switch (fill)
1364     {
1365     case GDK_SOLID:
1366       gdk_cairo_set_source_color (cr, &foreground);
1367       break;
1368     case GDK_TILED:
1369       tile_surface = _gdk_drawable_ref_cairo_surface (priv->tile);
1370       break;
1371     case GDK_STIPPLED:
1372       tile_surface = make_stipple_tile_surface (cr, stipple, &foreground, NULL);
1373       break;
1374     case GDK_OPAQUE_STIPPLED:
1375       tile_surface = make_stipple_tile_surface (cr, stipple, &foreground, &background);
1376       break;
1377     }
1378
1379   /* Tiles, stipples, and clip regions are all specified in device space,
1380    * not user space. For the clip region, we can simply change the matrix,
1381    * clip, then clip back, but for the source pattern, we need to
1382    * compute the right matrix.
1383    *
1384    * What we want is:
1385    *
1386    *     CTM_inverse * Pattern_matrix = Translate(- ts_x, - ts_y)
1387    *
1388    * (So that ts_x, ts_y in device space is taken to 0,0 in pattern
1389    * space). So, pattern_matrix = CTM * Translate(- ts_x, - tx_y);
1390    */
1391
1392   if (tile_surface)
1393     {
1394       cairo_pattern_t *pattern = cairo_pattern_create_for_surface (tile_surface);
1395       cairo_matrix_t user_to_device;
1396       cairo_matrix_t user_to_pattern;
1397       cairo_matrix_t device_to_pattern;
1398
1399       cairo_get_matrix (cr, &user_to_device);
1400       cairo_matrix_init_translate (&device_to_pattern,
1401                                    - gc->ts_x_origin, - gc->ts_y_origin);
1402       cairo_matrix_multiply (&user_to_pattern,
1403                              &user_to_device, &device_to_pattern);
1404       
1405       cairo_pattern_set_matrix (pattern, &user_to_pattern);
1406       cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
1407       cairo_set_source (cr, pattern);
1408       
1409       cairo_surface_destroy (tile_surface);
1410       cairo_pattern_destroy (pattern);
1411     }
1412
1413   if (!gc_changed)
1414     return;
1415
1416   cairo_reset_clip (cr);
1417   if (priv->clip_region)
1418     {
1419       cairo_save (cr);
1420
1421       cairo_identity_matrix (cr);
1422       cairo_translate (cr, gc->clip_x_origin, gc->clip_y_origin);
1423
1424       cairo_new_path (cr);
1425       gdk_cairo_region (cr, priv->clip_region);
1426
1427       cairo_restore (cr);
1428
1429       cairo_clip (cr);
1430     }
1431
1432   /* The reset above resets the window clip rect, so we want to re-set that */
1433   if (target_drawable && GDK_DRAWABLE_GET_CLASS (target_drawable)->set_cairo_clip)
1434     GDK_DRAWABLE_GET_CLASS (target_drawable)->set_cairo_clip (target_drawable, cr);
1435 }
1436
1437
1438 #define __GDK_GC_C__
1439 #include "gdkaliasdef.c"