1/*
2
3Copyright 1986, 1998  The Open Group
4
5Permission to use, copy, modify, distribute, and sell this software and its
6documentation for any purpose is hereby granted without fee, provided that
7the above copyright notice appear in all copies and that both that
8copyright notice and this permission notice appear in supporting
9documentation.
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21Except as contained in this notice, the name of The Open Group shall not be
22used in advertising or otherwise to promote the sale, use or other dealings
23in this Software without prior written authorization from The Open Group.
24
25*/
26
27#ifdef HAVE_CONFIG_H
28#include <config.h>
29#endif
30#include "Xlibint.h"
31
32int
33XCopyGC (
34     register Display *dpy,
35     GC srcGC,
36     unsigned long mask,		/* which ones to set initially */
37     GC destGC)
38{
39    register XGCValues *destgv = &destGC->values,
40    		       *srcgv = &srcGC->values;
41    register xCopyGCReq *req;
42    register _XExtension *ext;
43
44    LockDisplay(dpy);
45
46    mask &= (1L << (GCLastBit + 1)) - 1;
47    /* if some of the source values to be copied are "dirty", flush them
48       out before sending the CopyGC request. */
49    if (srcGC->dirty & mask)
50         _XFlushGCCache(dpy, srcGC);
51
52    /* mark the copied values "not dirty" in the destination. */
53    destGC->dirty &= ~mask;
54
55    GetReq(CopyGC, req);
56    req->srcGC = srcGC->gid;
57    req->dstGC = destGC->gid;
58    req->mask = mask;
59
60    if (mask & GCFunction)
61    	destgv->function = srcgv->function;
62
63    if (mask & GCPlaneMask)
64        destgv->plane_mask = srcgv->plane_mask;
65
66    if (mask & GCForeground)
67        destgv->foreground = srcgv->foreground;
68
69    if (mask & GCBackground)
70        destgv->background = srcgv->background;
71
72    if (mask & GCLineWidth)
73        destgv->line_width = srcgv->line_width;
74
75    if (mask & GCLineStyle)
76        destgv->line_style = srcgv->line_style;
77
78    if (mask & GCCapStyle)
79        destgv->cap_style = srcgv->cap_style;
80
81    if (mask & GCJoinStyle)
82        destgv->join_style = srcgv->join_style;
83
84    if (mask & GCFillStyle)
85    	destgv->fill_style = srcgv->fill_style;
86
87    if (mask & GCFillRule)
88        destgv->fill_rule = srcgv->fill_rule;
89
90    if (mask & GCArcMode)
91        destgv->arc_mode = srcgv->arc_mode;
92
93    if (mask & GCTile)
94        destgv->tile = srcgv->tile;
95
96    if (mask & GCStipple)
97        destgv->stipple = srcgv->stipple;
98
99    if (mask & GCTileStipXOrigin)
100        destgv->ts_x_origin = srcgv->ts_x_origin;
101
102    if (mask & GCTileStipYOrigin)
103        destgv->ts_y_origin = srcgv->ts_y_origin;
104
105    if (mask & GCFont)
106        destgv->font = srcgv->font;
107
108    if (mask & GCSubwindowMode)
109        destgv->subwindow_mode = srcgv->subwindow_mode;
110
111    if (mask & GCGraphicsExposures)
112        destgv->graphics_exposures = srcgv->graphics_exposures;
113
114    if (mask & GCClipXOrigin)
115        destgv->clip_x_origin = srcgv->clip_x_origin;
116
117    if (mask & GCClipYOrigin)
118        destgv->clip_y_origin = srcgv->clip_y_origin;
119
120    if (mask & GCClipMask) {
121	destGC->rects = srcGC->rects;
122        destgv->clip_mask = srcgv->clip_mask;
123	}
124
125    if (mask & GCDashOffset)
126        destgv->dash_offset = srcgv->dash_offset;
127
128    if (mask & GCDashList) {
129	destGC->dashes = srcGC->dashes;
130        destgv->dashes = srcgv->dashes;
131	}
132    /* call out to any extensions interested */
133    for (ext = dpy->ext_procs; ext; ext = ext->next)
134	if (ext->copy_GC) (*ext->copy_GC)(dpy, destGC, &ext->codes);
135    UnlockDisplay(dpy);
136    SyncHandle();
137    return 1;
138    }
139