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/.
30 #include "gdkprivate-x11.h"
31 #include "gdkregion-generic.h"
38 GDK_GC_DIRTY_CLIP = 1 << 0,
39 GDK_GC_DIRTY_TS = 1 << 1
42 static void gdk_x11_gc_values_to_xvalues (GdkGCValues *values,
45 unsigned long *xvalues_mask);
47 static void gdk_x11_gc_get_values (GdkGC *gc,
49 static void gdk_x11_gc_set_values (GdkGC *gc,
51 GdkGCValuesMask values_mask);
52 static void gdk_x11_gc_set_dashes (GdkGC *gc,
57 static void gdk_gc_x11_finalize (GObject *object);
59 G_DEFINE_TYPE (GdkGCX11, _gdk_gc_x11, GDK_TYPE_GC)
62 _gdk_gc_x11_class_init (GdkGCX11Class *klass)
64 GObjectClass *object_class = G_OBJECT_CLASS (klass);
65 GdkGCClass *gc_class = GDK_GC_CLASS (klass);
67 object_class->finalize = gdk_gc_x11_finalize;
69 gc_class->get_values = gdk_x11_gc_get_values;
70 gc_class->set_values = gdk_x11_gc_set_values;
71 gc_class->set_dashes = gdk_x11_gc_set_dashes;
75 _gdk_gc_x11_init (GdkGCX11 *gc)
80 gdk_gc_x11_finalize (GObject *object)
82 GdkGCX11 *x11_gc = GDK_GC_X11 (object);
84 XFreeGC (GDK_GC_XDISPLAY (x11_gc), GDK_GC_XGC (x11_gc));
86 G_OBJECT_CLASS (_gdk_gc_x11_parent_class)->finalize (object);
91 _gdk_x11_gc_new (GdkDrawable *drawable,
93 GdkGCValuesMask values_mask)
99 unsigned long xvalues_mask;
101 /* NOTICE that the drawable here has to be the impl drawable,
102 * not the publically-visible drawables.
104 g_return_val_if_fail (GDK_IS_DRAWABLE_IMPL_X11 (drawable), NULL);
106 gc = g_object_new (_gdk_gc_x11_get_type (), NULL);
107 private = GDK_GC_X11 (gc);
109 _gdk_gc_init (gc, drawable, values, values_mask);
111 private->dirty_mask = 0;
112 private->have_clip_mask = FALSE;
114 private->screen = GDK_DRAWABLE_IMPL_X11 (drawable)->screen;
116 private->depth = gdk_drawable_get_depth (drawable);
118 if (values_mask & (GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN))
120 values_mask &= ~(GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN);
121 private->dirty_mask |= GDK_GC_DIRTY_CLIP;
124 if (values_mask & (GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN))
126 values_mask &= ~(GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN);
127 private->dirty_mask |= GDK_GC_DIRTY_TS;
130 if ((values_mask & GDK_GC_CLIP_MASK) && values->clip_mask)
131 private->have_clip_mask = TRUE;
133 xvalues.function = GXcopy;
134 xvalues.fill_style = FillSolid;
135 xvalues.arc_mode = ArcPieSlice;
136 xvalues.subwindow_mode = ClipByChildren;
137 xvalues.graphics_exposures = False;
138 xvalues_mask = GCFunction | GCFillStyle | GCArcMode | GCSubwindowMode | GCGraphicsExposures;
140 gdk_x11_gc_values_to_xvalues (values, values_mask, &xvalues, &xvalues_mask);
142 private->xgc = XCreateGC (GDK_GC_XDISPLAY (gc),
143 GDK_DRAWABLE_IMPL_X11 (drawable)->xid,
144 xvalues_mask, &xvalues);
150 _gdk_x11_gc_flush (GdkGC *gc)
152 Display *xdisplay = GDK_GC_XDISPLAY (gc);
153 GdkGCX11 *private = GDK_GC_X11 (gc);
154 GC xgc = private->xgc;
156 if (private->dirty_mask & GDK_GC_DIRTY_CLIP)
158 GdkRegion *clip_region = _gdk_gc_get_clip_region (gc);
161 XSetClipOrigin (xdisplay, xgc,
162 gc->clip_x_origin, gc->clip_y_origin);
165 XRectangle *rectangles;
168 _gdk_region_get_xrectangles (clip_region,
174 XSetClipRectangles (xdisplay, xgc, 0, 0,
182 if (private->dirty_mask & GDK_GC_DIRTY_TS)
184 XSetTSOrigin (xdisplay, xgc,
185 gc->ts_x_origin, gc->ts_y_origin);
188 private->dirty_mask = 0;
193 gdk_x11_gc_get_values (GdkGC *gc,
198 if (XGetGCValues (GDK_GC_XDISPLAY (gc), GDK_GC_XGC (gc),
199 GCForeground | GCBackground | GCFont |
200 GCFunction | GCTile | GCStipple | /* GCClipMask | */
201 GCSubwindowMode | GCGraphicsExposures |
202 GCTileStipXOrigin | GCTileStipYOrigin |
203 GCClipXOrigin | GCClipYOrigin |
204 GCLineWidth | GCLineStyle | GCCapStyle |
205 GCFillStyle | GCJoinStyle, &xvalues))
207 values->foreground.pixel = xvalues.foreground;
208 values->background.pixel = xvalues.background;
210 switch (xvalues.function)
213 values->function = GDK_COPY;
216 values->function = GDK_INVERT;
219 values->function = GDK_XOR;
222 values->function = GDK_CLEAR;
225 values->function = GDK_AND;
228 values->function = GDK_AND_REVERSE;
231 values->function = GDK_AND_INVERT;
234 values->function = GDK_NOOP;
237 values->function = GDK_OR;
240 values->function = GDK_EQUIV;
243 values->function = GDK_OR_REVERSE;
246 values->function =GDK_COPY_INVERT;
249 values->function = GDK_OR_INVERT;
252 values->function = GDK_NAND;
255 values->function = GDK_SET;
258 values->function = GDK_NOR;
262 switch (xvalues.fill_style)
265 values->fill = GDK_SOLID;
268 values->fill = GDK_TILED;
271 values->fill = GDK_STIPPLED;
273 case FillOpaqueStippled:
274 values->fill = GDK_OPAQUE_STIPPLED;
278 values->tile = gdk_pixmap_lookup_for_display (GDK_GC_DISPLAY (gc),
280 values->stipple = gdk_pixmap_lookup_for_display (GDK_GC_DISPLAY (gc),
282 values->clip_mask = NULL;
283 values->subwindow_mode = xvalues.subwindow_mode;
284 values->ts_x_origin = xvalues.ts_x_origin;
285 values->ts_y_origin = xvalues.ts_y_origin;
286 values->clip_x_origin = xvalues.clip_x_origin;
287 values->clip_y_origin = xvalues.clip_y_origin;
288 values->graphics_exposures = xvalues.graphics_exposures;
289 values->line_width = xvalues.line_width;
291 switch (xvalues.line_style)
294 values->line_style = GDK_LINE_SOLID;
297 values->line_style = GDK_LINE_ON_OFF_DASH;
300 values->line_style = GDK_LINE_DOUBLE_DASH;
304 switch (xvalues.cap_style)
307 values->cap_style = GDK_CAP_NOT_LAST;
310 values->cap_style = GDK_CAP_BUTT;
313 values->cap_style = GDK_CAP_ROUND;
316 values->cap_style = GDK_CAP_PROJECTING;
320 switch (xvalues.join_style)
323 values->join_style = GDK_JOIN_MITER;
326 values->join_style = GDK_JOIN_ROUND;
329 values->join_style = GDK_JOIN_BEVEL;
335 memset (values, 0, sizeof (GdkGCValues));
340 gdk_x11_gc_set_values (GdkGC *gc,
342 GdkGCValuesMask values_mask)
346 unsigned long xvalues_mask = 0;
348 x11_gc = GDK_GC_X11 (gc);
350 if (values_mask & (GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN))
352 values_mask &= ~(GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN);
353 x11_gc->dirty_mask |= GDK_GC_DIRTY_CLIP;
356 if (values_mask & (GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN))
358 values_mask &= ~(GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN);
359 x11_gc->dirty_mask |= GDK_GC_DIRTY_TS;
362 if (values_mask & GDK_GC_CLIP_MASK)
364 x11_gc->have_clip_region = FALSE;
365 x11_gc->have_clip_mask = values->clip_mask != NULL;
368 gdk_x11_gc_values_to_xvalues (values, values_mask, &xvalues, &xvalues_mask);
370 XChangeGC (GDK_GC_XDISPLAY (gc),
377 gdk_x11_gc_set_dashes (GdkGC *gc,
382 g_return_if_fail (GDK_IS_GC (gc));
383 g_return_if_fail (dash_list != NULL);
385 XSetDashes (GDK_GC_XDISPLAY (gc), GDK_GC_XGC (gc),
386 dash_offset, (char *)dash_list, n);
390 gdk_x11_gc_values_to_xvalues (GdkGCValues *values,
391 GdkGCValuesMask mask,
393 unsigned long *xvalues_mask)
395 /* Optimization for the common case (gdk_gc_new()) */
396 if (values == NULL || mask == 0)
399 if (mask & GDK_GC_FOREGROUND)
401 xvalues->foreground = values->foreground.pixel;
402 *xvalues_mask |= GCForeground;
404 if (mask & GDK_GC_BACKGROUND)
406 xvalues->background = values->background.pixel;
407 *xvalues_mask |= GCBackground;
409 if (mask & GDK_GC_FUNCTION)
411 switch (values->function)
414 xvalues->function = GXcopy;
417 xvalues->function = GXinvert;
420 xvalues->function = GXxor;
423 xvalues->function = GXclear;
426 xvalues->function = GXand;
428 case GDK_AND_REVERSE:
429 xvalues->function = GXandReverse;
432 xvalues->function = GXandInverted;
435 xvalues->function = GXnoop;
438 xvalues->function = GXor;
441 xvalues->function = GXequiv;
444 xvalues->function = GXorReverse;
446 case GDK_COPY_INVERT:
447 xvalues->function = GXcopyInverted;
450 xvalues->function = GXorInverted;
453 xvalues->function = GXnand;
456 xvalues->function = GXset;
459 xvalues->function = GXnor;
462 *xvalues_mask |= GCFunction;
464 if (mask & GDK_GC_FILL)
466 switch (values->fill)
469 xvalues->fill_style = FillSolid;
472 xvalues->fill_style = FillTiled;
475 xvalues->fill_style = FillStippled;
477 case GDK_OPAQUE_STIPPLED:
478 xvalues->fill_style = FillOpaqueStippled;
481 *xvalues_mask |= GCFillStyle;
483 if (mask & GDK_GC_TILE)
486 xvalues->tile = GDK_DRAWABLE_XID (values->tile);
488 xvalues->tile = None;
490 *xvalues_mask |= GCTile;
492 if (mask & GDK_GC_STIPPLE)
495 xvalues->stipple = GDK_DRAWABLE_XID (values->stipple);
497 xvalues->stipple = None;
499 *xvalues_mask |= GCStipple;
501 if (mask & GDK_GC_CLIP_MASK)
503 if (values->clip_mask)
504 xvalues->clip_mask = GDK_DRAWABLE_XID (values->clip_mask);
506 xvalues->clip_mask = None;
508 *xvalues_mask |= GCClipMask;
511 if (mask & GDK_GC_SUBWINDOW)
513 xvalues->subwindow_mode = values->subwindow_mode;
514 *xvalues_mask |= GCSubwindowMode;
516 if (mask & GDK_GC_TS_X_ORIGIN)
518 xvalues->ts_x_origin = values->ts_x_origin;
519 *xvalues_mask |= GCTileStipXOrigin;
521 if (mask & GDK_GC_TS_Y_ORIGIN)
523 xvalues->ts_y_origin = values->ts_y_origin;
524 *xvalues_mask |= GCTileStipYOrigin;
526 if (mask & GDK_GC_CLIP_X_ORIGIN)
528 xvalues->clip_x_origin = values->clip_x_origin;
529 *xvalues_mask |= GCClipXOrigin;
531 if (mask & GDK_GC_CLIP_Y_ORIGIN)
533 xvalues->clip_y_origin = values->clip_y_origin;
534 *xvalues_mask |= GCClipYOrigin;
537 if (mask & GDK_GC_EXPOSURES)
539 xvalues->graphics_exposures = values->graphics_exposures;
540 *xvalues_mask |= GCGraphicsExposures;
543 if (mask & GDK_GC_LINE_WIDTH)
545 xvalues->line_width = values->line_width;
546 *xvalues_mask |= GCLineWidth;
548 if (mask & GDK_GC_LINE_STYLE)
550 switch (values->line_style)
553 xvalues->line_style = LineSolid;
555 case GDK_LINE_ON_OFF_DASH:
556 xvalues->line_style = LineOnOffDash;
558 case GDK_LINE_DOUBLE_DASH:
559 xvalues->line_style = LineDoubleDash;
562 *xvalues_mask |= GCLineStyle;
564 if (mask & GDK_GC_CAP_STYLE)
566 switch (values->cap_style)
568 case GDK_CAP_NOT_LAST:
569 xvalues->cap_style = CapNotLast;
572 xvalues->cap_style = CapButt;
575 xvalues->cap_style = CapRound;
577 case GDK_CAP_PROJECTING:
578 xvalues->cap_style = CapProjecting;
581 *xvalues_mask |= GCCapStyle;
583 if (mask & GDK_GC_JOIN_STYLE)
585 switch (values->join_style)
588 xvalues->join_style = JoinMiter;
591 xvalues->join_style = JoinRound;
594 xvalues->join_style = JoinBevel;
597 *xvalues_mask |= GCJoinStyle;
603 _gdk_windowing_gc_set_clip_region (GdkGC *gc,
604 const GdkRegion *region,
605 gboolean reset_origin)
607 GdkGCX11 *x11_gc = GDK_GC_X11 (gc);
609 /* Unset immediately, to make sure Xlib doesn't keep the
610 * XID of an old clip mask cached
612 if ((x11_gc->have_clip_region && !region) || x11_gc->have_clip_mask)
614 XSetClipMask (GDK_GC_XDISPLAY (gc), GDK_GC_XGC (gc), None);
615 x11_gc->have_clip_mask = FALSE;
618 x11_gc->have_clip_region = region != NULL;
622 gc->clip_x_origin = 0;
623 gc->clip_y_origin = 0;
626 x11_gc->dirty_mask |= GDK_GC_DIRTY_CLIP;
630 _gdk_windowing_gc_copy (GdkGC *dst_gc,
633 GdkGCX11 *x11_src_gc = GDK_GC_X11 (src_gc);
634 GdkGCX11 *x11_dst_gc = GDK_GC_X11 (dst_gc);
636 XCopyGC (GDK_GC_XDISPLAY (src_gc), GDK_GC_XGC (src_gc), ~((~1) << GCLastBit),
637 GDK_GC_XGC (dst_gc));
639 x11_dst_gc->dirty_mask = x11_src_gc->dirty_mask;
640 x11_dst_gc->have_clip_region = x11_src_gc->have_clip_region;
641 x11_dst_gc->have_clip_mask = x11_src_gc->have_clip_mask;
648 * Gets the #GdkScreen for which @gc was created
650 * Returns: the #GdkScreen for @gc.
655 gdk_gc_get_screen (GdkGC *gc)
657 g_return_val_if_fail (GDK_IS_GC_X11 (gc), NULL);
659 return GDK_GC_X11 (gc)->screen;
663 * gdk_x11_gc_get_xdisplay:
666 * Returns the display of a #GdkGC.
668 * Return value: an Xlib <type>Display*</type>.
671 gdk_x11_gc_get_xdisplay (GdkGC *gc)
673 g_return_val_if_fail (GDK_IS_GC_X11 (gc), NULL);
675 return GDK_SCREEN_XDISPLAY (gdk_gc_get_screen (gc));
679 * gdk_x11_gc_get_xgc:
682 * Returns the X GC of a #GdkGC.
684 * Return value: an Xlib <type>GC</type>.
687 gdk_x11_gc_get_xgc (GdkGC *gc)
691 g_return_val_if_fail (GDK_IS_GC_X11 (gc), NULL);
693 gc_x11 = GDK_GC_X11 (gc);
695 if (gc_x11->dirty_mask)
696 _gdk_x11_gc_flush (gc);
701 #define __GDK_GC_X11_C__
702 #include "gdkaliasdef.c"