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 Library 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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "gdkprivate.h"
25 gdk_gc_new (GdkWindow *window)
27 return gdk_gc_new_with_values (window, NULL, 0);
31 gdk_gc_new_with_values (GdkWindow *window,
33 GdkGCValuesMask values_mask)
36 GdkGCPrivate *private;
39 unsigned long xvalues_mask;
41 private = g_new (GdkGCPrivate, 1);
42 gc = (GdkGC*) private;
44 xwindow = ((GdkWindowPrivate*) window)->xwindow;
45 private->xdisplay = ((GdkWindowPrivate*) window)->xdisplay;
47 xvalues.function = GXcopy;
48 xvalues.fill_style = FillSolid;
49 xvalues.arc_mode = ArcPieSlice;
50 xvalues.subwindow_mode = ClipByChildren;
51 xvalues.graphics_exposures = True;
52 xvalues_mask = GCFunction | GCFillStyle | GCArcMode | GCSubwindowMode | GCGraphicsExposures;
54 if (values_mask & GDK_GC_FOREGROUND)
56 xvalues.foreground = values->foreground.pixel;
57 xvalues_mask |= GCForeground;
59 if (values_mask & GDK_GC_BACKGROUND)
61 xvalues.background = values->background.pixel;
62 xvalues_mask |= GCBackground;
64 if ((values_mask & GDK_GC_FONT) && (values->font->type == GDK_FONT_FONT))
66 xvalues.font = ((XFontStruct *) ((GdkFontPrivate*) values->font)->xfont)->fid;
67 xvalues_mask |= GCFont;
69 if (values_mask & GDK_GC_FUNCTION)
71 switch (values->function)
74 xvalues.function = GXcopy;
77 xvalues.function = GXinvert;
80 xvalues.function = GXxor;
83 xvalues_mask |= GCFunction;
85 if (values_mask & GDK_GC_FILL)
90 xvalues.fill_style = FillSolid;
93 xvalues.fill_style = FillTiled;
96 xvalues.fill_style = FillStippled;
98 case GDK_OPAQUE_STIPPLED:
99 xvalues.fill_style = FillOpaqueStippled;
102 xvalues_mask |= GCFillStyle;
104 if (values_mask & GDK_GC_TILE)
106 xvalues.tile = ((GdkPixmapPrivate*) values->tile)->xwindow;
107 xvalues_mask |= GCTile;
109 if (values_mask & GDK_GC_STIPPLE)
111 xvalues.stipple = ((GdkPixmapPrivate*) values->stipple)->xwindow;
112 xvalues_mask |= GCStipple;
114 if (values_mask & GDK_GC_CLIP_MASK)
116 xvalues.clip_mask = ((GdkPixmapPrivate*) values->clip_mask)->xwindow;
117 xvalues_mask |= GCClipMask;
119 if (values_mask & GDK_GC_SUBWINDOW)
121 xvalues.subwindow_mode = values->subwindow_mode;
122 xvalues_mask |= GCSubwindowMode;
124 if (values_mask & GDK_GC_TS_X_ORIGIN)
126 xvalues.ts_x_origin = values->ts_x_origin;
127 xvalues_mask |= GCTileStipXOrigin;
129 if (values_mask & GDK_GC_TS_Y_ORIGIN)
131 xvalues.ts_y_origin = values->ts_y_origin;
132 xvalues_mask |= GCTileStipYOrigin;
134 if (values_mask & GDK_GC_CLIP_X_ORIGIN)
136 xvalues.clip_x_origin = values->clip_x_origin;
137 xvalues_mask |= GCClipXOrigin;
139 if (values_mask & GDK_GC_CLIP_Y_ORIGIN)
141 xvalues.clip_y_origin = values->clip_y_origin;
142 xvalues_mask |= GCClipYOrigin;
144 if (values_mask & GDK_GC_EXPOSURES)
146 xvalues.graphics_exposures = values->graphics_exposures;
147 xvalues_mask |= GCGraphicsExposures;
149 if (values_mask & GDK_GC_LINE_WIDTH)
151 xvalues.line_width = values->line_width;
152 xvalues_mask |= GCLineWidth;
154 if (values_mask & GDK_GC_LINE_STYLE)
156 switch (values->line_style)
159 xvalues.line_style = LineSolid;
161 case GDK_LINE_ON_OFF_DASH:
162 xvalues.line_style = LineOnOffDash;
164 case GDK_LINE_DOUBLE_DASH:
165 xvalues.line_style = LineDoubleDash;
168 xvalues_mask |= GCLineStyle;
170 if (values_mask & GDK_GC_CAP_STYLE)
172 switch (values->cap_style)
174 case GDK_CAP_NOT_LAST:
175 xvalues.cap_style = CapNotLast;
178 xvalues.cap_style = CapButt;
181 xvalues.cap_style = CapRound;
183 case GDK_CAP_PROJECTING:
184 xvalues.cap_style = CapProjecting;
187 xvalues_mask |= GCCapStyle;
189 if (values_mask & GDK_GC_JOIN_STYLE)
191 switch (values->join_style)
194 xvalues.join_style = JoinMiter;
197 xvalues.join_style = JoinRound;
200 xvalues.join_style = JoinBevel;
203 xvalues_mask |= GCJoinStyle;
206 private->xgc = XCreateGC (private->xdisplay, xwindow, xvalues_mask, &xvalues);
212 gdk_gc_destroy (GdkGC *gc)
214 GdkGCPrivate *private;
216 g_return_if_fail (gc != NULL);
218 private = (GdkGCPrivate*) gc;
219 XFreeGC (private->xdisplay, private->xgc);
221 memset (gc, 0, sizeof (GdkGCPrivate));
226 gdk_gc_get_values (GdkGC *gc,
229 GdkGCPrivate *private;
232 g_return_if_fail (gc != NULL);
233 g_return_if_fail (values != NULL);
235 private = (GdkGCPrivate*) gc;
237 if (XGetGCValues (private->xdisplay, private->xgc,
238 GCForeground | GCBackground | GCFont |
239 GCFunction | GCTile | GCStipple | /* GCClipMask | */
240 GCSubwindowMode | GCGraphicsExposures |
241 GCTileStipXOrigin | GCTileStipYOrigin |
242 GCClipXOrigin | GCClipYOrigin |
243 GCLineWidth | GCLineStyle | GCCapStyle |
244 GCFillStyle | GCJoinStyle, &xvalues))
246 values->foreground.pixel = xvalues.foreground;
247 values->background.pixel = xvalues.background;
248 values->font = gdk_font_lookup (xvalues.font);
250 switch (xvalues.function)
253 values->function = GDK_COPY;
256 values->function = GDK_INVERT;
259 values->function = GDK_XOR;
263 switch (xvalues.fill_style)
266 values->fill = GDK_SOLID;
269 values->fill = GDK_TILED;
272 values->fill = GDK_STIPPLED;
274 case FillOpaqueStippled:
275 values->fill = GDK_OPAQUE_STIPPLED;
279 values->tile = gdk_pixmap_lookup (xvalues.tile);
280 values->stipple = gdk_pixmap_lookup (xvalues.stipple);
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_gc_set_foreground (GdkGC *gc,
342 GdkGCPrivate *private;
344 g_return_if_fail (gc != NULL);
345 g_return_if_fail (color != NULL);
347 private = (GdkGCPrivate*) gc;
348 XSetForeground (private->xdisplay, private->xgc, color->pixel);
352 gdk_gc_set_background (GdkGC *gc,
355 GdkGCPrivate *private;
357 g_return_if_fail (gc != NULL);
358 g_return_if_fail (color != NULL);
360 private = (GdkGCPrivate*) gc;
361 XSetBackground (private->xdisplay, private->xgc, color->pixel);
365 gdk_gc_set_font (GdkGC *gc,
368 GdkGCPrivate *gc_private;
369 GdkFontPrivate *font_private;
371 g_return_if_fail (gc != NULL);
372 g_return_if_fail (font != NULL);
374 if (font->type == GDK_FONT_FONT)
376 gc_private = (GdkGCPrivate*) gc;
377 font_private = (GdkFontPrivate*) font;
379 XSetFont (gc_private->xdisplay, gc_private->xgc,
380 ((XFontStruct *) font_private->xfont)->fid);
385 gdk_gc_set_function (GdkGC *gc,
386 GdkFunction function)
388 GdkGCPrivate *private;
390 g_return_if_fail (gc != NULL);
392 private = (GdkGCPrivate*) gc;
397 XSetFunction (private->xdisplay, private->xgc, GXcopy);
400 XSetFunction (private->xdisplay, private->xgc, GXinvert);
403 XSetFunction (private->xdisplay, private->xgc, GXor);
409 gdk_gc_set_fill (GdkGC *gc,
412 GdkGCPrivate *private;
414 g_return_if_fail (gc != NULL);
416 private = (GdkGCPrivate*) gc;
421 XSetFillStyle (private->xdisplay, private->xgc, FillSolid);
424 XSetFillStyle (private->xdisplay, private->xgc, FillTiled);
427 XSetFillStyle (private->xdisplay, private->xgc, FillStippled);
429 case GDK_OPAQUE_STIPPLED:
430 XSetFillStyle (private->xdisplay, private->xgc, FillOpaqueStippled);
436 gdk_gc_set_tile (GdkGC *gc,
439 GdkGCPrivate *private;
440 GdkPixmapPrivate *pixmap_private;
443 g_return_if_fail (gc != NULL);
445 private = (GdkGCPrivate*) gc;
450 pixmap_private = (GdkPixmapPrivate*) tile;
451 pixmap = pixmap_private->xwindow;
454 XSetTile (private->xdisplay, private->xgc, pixmap);
458 gdk_gc_set_stipple (GdkGC *gc,
461 GdkGCPrivate *private;
462 GdkPixmapPrivate *pixmap_private;
465 g_return_if_fail (gc != NULL);
467 private = (GdkGCPrivate*) gc;
472 pixmap_private = (GdkPixmapPrivate*) stipple;
473 pixmap = pixmap_private->xwindow;
476 XSetStipple (private->xdisplay, private->xgc, pixmap);
480 gdk_gc_set_ts_origin (GdkGC *gc,
484 GdkGCPrivate *private;
486 g_return_if_fail (gc != NULL);
488 private = (GdkGCPrivate*) gc;
490 XSetTSOrigin (private->xdisplay, private->xgc, x, y);
494 gdk_gc_set_clip_origin (GdkGC *gc,
498 GdkGCPrivate *private;
500 g_return_if_fail (gc != NULL);
502 private = (GdkGCPrivate*) gc;
504 XSetClipOrigin (private->xdisplay, private->xgc, x, y);
508 gdk_gc_set_clip_mask (GdkGC *gc,
511 GdkGCPrivate *private;
514 g_return_if_fail (gc != NULL);
516 private = (GdkGCPrivate*) gc;
519 xmask = ((GdkWindowPrivate*) mask)->xwindow;
523 XSetClipMask (private->xdisplay, private->xgc, xmask);
528 gdk_gc_set_clip_rectangle (GdkGC *gc,
529 GdkRectangle *rectangle)
531 GdkGCPrivate *private;
532 XRectangle xrectangle;
534 g_return_if_fail (gc != NULL);
536 private = (GdkGCPrivate*) gc;
540 xrectangle.x = rectangle->x;
541 xrectangle.y = rectangle->y;
542 xrectangle.width = rectangle->width;
543 xrectangle.height = rectangle->height;
545 XSetClipRectangles (private->xdisplay, private->xgc, 0, 0,
546 &xrectangle, 1, Unsorted);
549 XSetClipMask (private->xdisplay, private->xgc, None);
553 gdk_gc_set_subwindow (GdkGC *gc,
554 GdkSubwindowMode mode)
556 GdkGCPrivate *private;
558 g_return_if_fail (gc != NULL);
560 private = (GdkGCPrivate*) gc;
562 XSetSubwindowMode (private->xdisplay, private->xgc, mode);
566 gdk_gc_set_exposures (GdkGC *gc,
569 GdkGCPrivate *private;
571 g_return_if_fail (gc != NULL);
573 private = (GdkGCPrivate*) gc;
575 XSetGraphicsExposures (private->xdisplay, private->xgc, exposures);
579 gdk_gc_set_line_attributes (GdkGC *gc,
581 GdkLineStyle line_style,
582 GdkCapStyle cap_style,
583 GdkJoinStyle join_style)
585 GdkGCPrivate *private;
590 g_return_if_fail (gc != NULL);
592 private = (GdkGCPrivate*) gc;
597 xline_style = LineSolid;
599 case GDK_LINE_ON_OFF_DASH:
600 xline_style = LineOnOffDash;
602 case GDK_LINE_DOUBLE_DASH:
603 xline_style = LineDoubleDash;
611 case GDK_CAP_NOT_LAST:
612 xcap_style = CapNotLast;
615 xcap_style = CapButt;
618 xcap_style = CapRound;
620 case GDK_CAP_PROJECTING:
621 xcap_style = CapProjecting;
630 xjoin_style = JoinMiter;
633 xjoin_style = JoinRound;
636 xjoin_style = JoinBevel;
642 XSetLineAttributes (private->xdisplay, private->xgc, line_width,
643 xline_style, xcap_style, xjoin_style);