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"
37 GDK_GC_DIRTY_CLIP = 1 << 0,
38 GDK_GC_DIRTY_TS = 1 << 1
41 static void gdk_x11_gc_values_to_xvalues (GdkGCValues *values,
44 unsigned long *xvalues_mask);
46 static void gdk_x11_gc_get_values (GdkGC *gc,
48 static void gdk_x11_gc_set_values (GdkGC *gc,
50 GdkGCValuesMask values_mask);
51 static void gdk_x11_gc_set_dashes (GdkGC *gc,
56 static void gdk_gc_x11_finalize (GObject *object);
58 G_DEFINE_TYPE (GdkGCX11, _gdk_gc_x11, GDK_TYPE_GC)
61 _gdk_gc_x11_class_init (GdkGCX11Class *klass)
63 GObjectClass *object_class = G_OBJECT_CLASS (klass);
64 GdkGCClass *gc_class = GDK_GC_CLASS (klass);
66 object_class->finalize = gdk_gc_x11_finalize;
68 gc_class->get_values = gdk_x11_gc_get_values;
69 gc_class->set_values = gdk_x11_gc_set_values;
70 gc_class->set_dashes = gdk_x11_gc_set_dashes;
74 _gdk_gc_x11_init (GdkGCX11 *gc)
79 gdk_gc_x11_finalize (GObject *object)
81 GdkGCX11 *x11_gc = GDK_GC_X11 (object);
83 XFreeGC (GDK_GC_XDISPLAY (x11_gc), GDK_GC_XGC (x11_gc));
85 G_OBJECT_CLASS (_gdk_gc_x11_parent_class)->finalize (object);
90 _gdk_x11_gc_new (GdkDrawable *drawable,
92 GdkGCValuesMask values_mask)
98 unsigned long xvalues_mask;
100 /* NOTICE that the drawable here has to be the impl drawable,
101 * not the publically-visible drawables.
103 g_return_val_if_fail (GDK_IS_DRAWABLE_IMPL_X11 (drawable), NULL);
105 gc = g_object_new (_gdk_gc_x11_get_type (), NULL);
106 private = GDK_GC_X11 (gc);
108 _gdk_gc_init (gc, drawable, values, values_mask);
110 private->dirty_mask = 0;
111 private->have_clip_mask = FALSE;
113 private->screen = GDK_DRAWABLE_IMPL_X11 (drawable)->screen;
115 private->depth = gdk_drawable_get_depth (drawable);
117 if (values_mask & (GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN))
119 values_mask &= ~(GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN);
120 private->dirty_mask |= GDK_GC_DIRTY_CLIP;
123 if (values_mask & (GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN))
125 values_mask &= ~(GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN);
126 private->dirty_mask |= GDK_GC_DIRTY_TS;
129 if ((values_mask & GDK_GC_CLIP_MASK) && values->clip_mask)
130 private->have_clip_mask = TRUE;
132 xvalues.function = GXcopy;
133 xvalues.fill_style = FillSolid;
134 xvalues.arc_mode = ArcPieSlice;
135 xvalues.subwindow_mode = ClipByChildren;
136 xvalues.graphics_exposures = False;
137 xvalues_mask = GCFunction | GCFillStyle | GCArcMode | GCSubwindowMode | GCGraphicsExposures;
139 gdk_x11_gc_values_to_xvalues (values, values_mask, &xvalues, &xvalues_mask);
141 private->xgc = XCreateGC (GDK_GC_XDISPLAY (gc),
142 GDK_DRAWABLE_IMPL_X11 (drawable)->xid,
143 xvalues_mask, &xvalues);
149 _gdk_x11_gc_flush (GdkGC *gc)
151 Display *xdisplay = GDK_GC_XDISPLAY (gc);
152 GdkGCX11 *private = GDK_GC_X11 (gc);
153 GC xgc = private->xgc;
155 if (private->dirty_mask & GDK_GC_DIRTY_CLIP)
157 GdkRegion *clip_region = _gdk_gc_get_clip_region (gc);
160 XSetClipOrigin (xdisplay, xgc,
161 gc->clip_x_origin, gc->clip_y_origin);
164 XRectangle *rectangles;
167 _gdk_region_get_xrectangles (clip_region,
173 XSetClipRectangles (xdisplay, xgc, 0, 0,
181 if (private->dirty_mask & GDK_GC_DIRTY_TS)
183 XSetTSOrigin (xdisplay, xgc,
184 gc->ts_x_origin, gc->ts_y_origin);
187 private->dirty_mask = 0;
192 gdk_x11_gc_get_values (GdkGC *gc,
197 if (XGetGCValues (GDK_GC_XDISPLAY (gc), GDK_GC_XGC (gc),
198 GCForeground | GCBackground | GCFont |
199 GCFunction | GCTile | GCStipple | /* GCClipMask | */
200 GCSubwindowMode | GCGraphicsExposures |
201 GCTileStipXOrigin | GCTileStipYOrigin |
202 GCClipXOrigin | GCClipYOrigin |
203 GCLineWidth | GCLineStyle | GCCapStyle |
204 GCFillStyle | GCJoinStyle, &xvalues))
206 values->foreground.pixel = xvalues.foreground;
207 values->background.pixel = xvalues.background;
209 switch (xvalues.function)
212 values->function = GDK_COPY;
215 values->function = GDK_INVERT;
218 values->function = GDK_XOR;
221 values->function = GDK_CLEAR;
224 values->function = GDK_AND;
227 values->function = GDK_AND_REVERSE;
230 values->function = GDK_AND_INVERT;
233 values->function = GDK_NOOP;
236 values->function = GDK_OR;
239 values->function = GDK_EQUIV;
242 values->function = GDK_OR_REVERSE;
245 values->function =GDK_COPY_INVERT;
248 values->function = GDK_OR_INVERT;
251 values->function = GDK_NAND;
254 values->function = GDK_SET;
257 values->function = GDK_NOR;
261 switch (xvalues.fill_style)
264 values->fill = GDK_SOLID;
267 values->fill = GDK_TILED;
270 values->fill = GDK_STIPPLED;
272 case FillOpaqueStippled:
273 values->fill = GDK_OPAQUE_STIPPLED;
277 values->tile = gdk_pixmap_lookup_for_display (GDK_GC_DISPLAY (gc),
279 values->stipple = gdk_pixmap_lookup_for_display (GDK_GC_DISPLAY (gc),
281 values->clip_mask = NULL;
282 values->subwindow_mode = xvalues.subwindow_mode;
283 values->ts_x_origin = xvalues.ts_x_origin;
284 values->ts_y_origin = xvalues.ts_y_origin;
285 values->clip_x_origin = xvalues.clip_x_origin;
286 values->clip_y_origin = xvalues.clip_y_origin;
287 values->graphics_exposures = xvalues.graphics_exposures;
288 values->line_width = xvalues.line_width;
290 switch (xvalues.line_style)
293 values->line_style = GDK_LINE_SOLID;
296 values->line_style = GDK_LINE_ON_OFF_DASH;
299 values->line_style = GDK_LINE_DOUBLE_DASH;
303 switch (xvalues.cap_style)
306 values->cap_style = GDK_CAP_NOT_LAST;
309 values->cap_style = GDK_CAP_BUTT;
312 values->cap_style = GDK_CAP_ROUND;
315 values->cap_style = GDK_CAP_PROJECTING;
319 switch (xvalues.join_style)
322 values->join_style = GDK_JOIN_MITER;
325 values->join_style = GDK_JOIN_ROUND;
328 values->join_style = GDK_JOIN_BEVEL;
334 memset (values, 0, sizeof (GdkGCValues));
339 gdk_x11_gc_set_values (GdkGC *gc,
341 GdkGCValuesMask values_mask)
345 unsigned long xvalues_mask = 0;
347 x11_gc = GDK_GC_X11 (gc);
349 if (values_mask & (GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN))
351 values_mask &= ~(GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN);
352 x11_gc->dirty_mask |= GDK_GC_DIRTY_CLIP;
355 if (values_mask & (GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN))
357 values_mask &= ~(GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN);
358 x11_gc->dirty_mask |= GDK_GC_DIRTY_TS;
361 if (values_mask & GDK_GC_CLIP_MASK)
363 x11_gc->have_clip_region = FALSE;
364 x11_gc->have_clip_mask = values->clip_mask != NULL;
367 gdk_x11_gc_values_to_xvalues (values, values_mask, &xvalues, &xvalues_mask);
369 XChangeGC (GDK_GC_XDISPLAY (gc),
376 gdk_x11_gc_set_dashes (GdkGC *gc,
381 g_return_if_fail (GDK_IS_GC (gc));
382 g_return_if_fail (dash_list != NULL);
384 XSetDashes (GDK_GC_XDISPLAY (gc), GDK_GC_XGC (gc),
385 dash_offset, (char *)dash_list, n);
389 gdk_x11_gc_values_to_xvalues (GdkGCValues *values,
390 GdkGCValuesMask mask,
392 unsigned long *xvalues_mask)
394 /* Optimization for the common case (gdk_gc_new()) */
395 if (values == NULL || mask == 0)
398 if (mask & GDK_GC_FOREGROUND)
400 xvalues->foreground = values->foreground.pixel;
401 *xvalues_mask |= GCForeground;
403 if (mask & GDK_GC_BACKGROUND)
405 xvalues->background = values->background.pixel;
406 *xvalues_mask |= GCBackground;
408 if (mask & GDK_GC_FUNCTION)
410 switch (values->function)
413 xvalues->function = GXcopy;
416 xvalues->function = GXinvert;
419 xvalues->function = GXxor;
422 xvalues->function = GXclear;
425 xvalues->function = GXand;
427 case GDK_AND_REVERSE:
428 xvalues->function = GXandReverse;
431 xvalues->function = GXandInverted;
434 xvalues->function = GXnoop;
437 xvalues->function = GXor;
440 xvalues->function = GXequiv;
443 xvalues->function = GXorReverse;
445 case GDK_COPY_INVERT:
446 xvalues->function = GXcopyInverted;
449 xvalues->function = GXorInverted;
452 xvalues->function = GXnand;
455 xvalues->function = GXset;
458 xvalues->function = GXnor;
461 *xvalues_mask |= GCFunction;
463 if (mask & GDK_GC_FILL)
465 switch (values->fill)
468 xvalues->fill_style = FillSolid;
471 xvalues->fill_style = FillTiled;
474 xvalues->fill_style = FillStippled;
476 case GDK_OPAQUE_STIPPLED:
477 xvalues->fill_style = FillOpaqueStippled;
480 *xvalues_mask |= GCFillStyle;
482 if (mask & GDK_GC_TILE)
485 xvalues->tile = GDK_DRAWABLE_XID (values->tile);
487 xvalues->tile = None;
489 *xvalues_mask |= GCTile;
491 if (mask & GDK_GC_STIPPLE)
494 xvalues->stipple = GDK_DRAWABLE_XID (values->stipple);
496 xvalues->stipple = None;
498 *xvalues_mask |= GCStipple;
500 if (mask & GDK_GC_CLIP_MASK)
502 if (values->clip_mask)
503 xvalues->clip_mask = GDK_DRAWABLE_XID (values->clip_mask);
505 xvalues->clip_mask = None;
507 *xvalues_mask |= GCClipMask;
510 if (mask & GDK_GC_SUBWINDOW)
512 xvalues->subwindow_mode = values->subwindow_mode;
513 *xvalues_mask |= GCSubwindowMode;
515 if (mask & GDK_GC_TS_X_ORIGIN)
517 xvalues->ts_x_origin = values->ts_x_origin;
518 *xvalues_mask |= GCTileStipXOrigin;
520 if (mask & GDK_GC_TS_Y_ORIGIN)
522 xvalues->ts_y_origin = values->ts_y_origin;
523 *xvalues_mask |= GCTileStipYOrigin;
525 if (mask & GDK_GC_CLIP_X_ORIGIN)
527 xvalues->clip_x_origin = values->clip_x_origin;
528 *xvalues_mask |= GCClipXOrigin;
530 if (mask & GDK_GC_CLIP_Y_ORIGIN)
532 xvalues->clip_y_origin = values->clip_y_origin;
533 *xvalues_mask |= GCClipYOrigin;
536 if (mask & GDK_GC_EXPOSURES)
538 xvalues->graphics_exposures = values->graphics_exposures;
539 *xvalues_mask |= GCGraphicsExposures;
542 if (mask & GDK_GC_LINE_WIDTH)
544 xvalues->line_width = values->line_width;
545 *xvalues_mask |= GCLineWidth;
547 if (mask & GDK_GC_LINE_STYLE)
549 switch (values->line_style)
552 xvalues->line_style = LineSolid;
554 case GDK_LINE_ON_OFF_DASH:
555 xvalues->line_style = LineOnOffDash;
557 case GDK_LINE_DOUBLE_DASH:
558 xvalues->line_style = LineDoubleDash;
561 *xvalues_mask |= GCLineStyle;
563 if (mask & GDK_GC_CAP_STYLE)
565 switch (values->cap_style)
567 case GDK_CAP_NOT_LAST:
568 xvalues->cap_style = CapNotLast;
571 xvalues->cap_style = CapButt;
574 xvalues->cap_style = CapRound;
576 case GDK_CAP_PROJECTING:
577 xvalues->cap_style = CapProjecting;
580 *xvalues_mask |= GCCapStyle;
582 if (mask & GDK_GC_JOIN_STYLE)
584 switch (values->join_style)
587 xvalues->join_style = JoinMiter;
590 xvalues->join_style = JoinRound;
593 xvalues->join_style = JoinBevel;
596 *xvalues_mask |= GCJoinStyle;
602 _gdk_windowing_gc_set_clip_region (GdkGC *gc,
603 const GdkRegion *region,
604 gboolean reset_origin)
606 GdkGCX11 *x11_gc = GDK_GC_X11 (gc);
608 /* Unset immediately, to make sure Xlib doesn't keep the
609 * XID of an old clip mask cached
611 if ((x11_gc->have_clip_region && !region) || x11_gc->have_clip_mask)
613 XSetClipMask (GDK_GC_XDISPLAY (gc), GDK_GC_XGC (gc), None);
614 x11_gc->have_clip_mask = FALSE;
617 x11_gc->have_clip_region = region != NULL;
621 gc->clip_x_origin = 0;
622 gc->clip_y_origin = 0;
625 x11_gc->dirty_mask |= GDK_GC_DIRTY_CLIP;
629 _gdk_windowing_gc_copy (GdkGC *dst_gc,
632 GdkGCX11 *x11_src_gc = GDK_GC_X11 (src_gc);
633 GdkGCX11 *x11_dst_gc = GDK_GC_X11 (dst_gc);
635 XCopyGC (GDK_GC_XDISPLAY (src_gc), GDK_GC_XGC (src_gc), ~((~1) << GCLastBit),
636 GDK_GC_XGC (dst_gc));
638 x11_dst_gc->dirty_mask = x11_src_gc->dirty_mask;
639 x11_dst_gc->have_clip_region = x11_src_gc->have_clip_region;
640 x11_dst_gc->have_clip_mask = x11_src_gc->have_clip_mask;
647 * Gets the #GdkScreen for which @gc was created
649 * Returns: the #GdkScreen for @gc.
654 gdk_gc_get_screen (GdkGC *gc)
656 g_return_val_if_fail (GDK_IS_GC_X11 (gc), NULL);
658 return GDK_GC_X11 (gc)->screen;
662 * gdk_x11_gc_get_xdisplay:
665 * Returns the display of a #GdkGC.
667 * Return value: an Xlib <type>Display*</type>.
670 gdk_x11_gc_get_xdisplay (GdkGC *gc)
672 g_return_val_if_fail (GDK_IS_GC_X11 (gc), NULL);
674 return GDK_SCREEN_XDISPLAY (gdk_gc_get_screen (gc));
678 * gdk_x11_gc_get_xgc:
681 * Returns the X GC of a #GdkGC.
683 * Return value: an Xlib <type>GC</type>.
686 gdk_x11_gc_get_xgc (GdkGC *gc)
690 g_return_val_if_fail (GDK_IS_GC_X11 (gc), NULL);
692 gc_x11 = GDK_GC_X11 (gc);
694 if (gc_x11->dirty_mask)
695 _gdk_x11_gc_flush (gc);
700 #define __GDK_GC_X11_C__
701 #include "gdkaliasdef.c"