3 Copyright 1993 by Davor Matic
5 Permission to use, copy, modify, distribute, and sell this software
6 and its documentation for any purpose is hereby granted without fee,
7 provided that the above copyright notice appear in all copies and that
8 both that copyright notice and this permission notice appear in
9 supporting documentation. Davor Matic makes no representations about
10 the suitability of this software for any purpose. It is provided "as
11 is" without express or implied warranty.
15 #ifdef HAVE_XNEST_CONFIG_H
16 #include <xnest-config.h>
20 #include <X11/Xproto.h>
22 #include "windowstr.h"
23 #include "pixmapstr.h"
24 #include "scrnintstr.h"
25 #include <X11/fonts/fontstruct.h>
38 DevPrivateKeyRec xnestGCPrivateKeyRec
;
40 static GCFuncs xnestFuncs
= {
50 static GCOps xnestOps
= {
74 xnestCreateGC(GCPtr pGC
)
76 pGC
->funcs
= &xnestFuncs
;
81 xnestGCPriv(pGC
)->gc
= XCreateGC(xnestDisplay
,
82 xnestDefaultDrawables
[pGC
->depth
],
89 xnestValidateGC(GCPtr pGC
, unsigned long changes
, DrawablePtr pDrawable
)
94 xnestChangeGC(GCPtr pGC
, unsigned long mask
)
98 if (mask
& GCFunction
)
99 values
.function
= pGC
->alu
;
101 if (mask
& GCPlaneMask
)
102 values
.plane_mask
= pGC
->planemask
;
104 if (mask
& GCForeground
)
105 values
.foreground
= xnestPixel(pGC
->fgPixel
);
107 if (mask
& GCBackground
)
108 values
.background
= xnestPixel(pGC
->bgPixel
);
110 if (mask
& GCLineWidth
)
111 values
.line_width
= pGC
->lineWidth
;
113 if (mask
& GCLineStyle
)
114 values
.line_style
= pGC
->lineStyle
;
116 if (mask
& GCCapStyle
)
117 values
.cap_style
= pGC
->capStyle
;
119 if (mask
& GCJoinStyle
)
120 values
.join_style
= pGC
->joinStyle
;
122 if (mask
& GCFillStyle
)
123 values
.fill_style
= pGC
->fillStyle
;
125 if (mask
& GCFillRule
)
126 values
.fill_rule
= pGC
->fillRule
;
129 if (pGC
->tileIsPixel
)
132 values
.tile
= xnestPixmap(pGC
->tile
.pixmap
);
135 if (mask
& GCStipple
)
136 values
.stipple
= xnestPixmap(pGC
->stipple
);
138 if (mask
& GCTileStipXOrigin
)
139 values
.ts_x_origin
= pGC
->patOrg
.x
;
141 if (mask
& GCTileStipYOrigin
)
142 values
.ts_y_origin
= pGC
->patOrg
.y
;
145 values
.font
= xnestFont(pGC
->font
);
147 if (mask
& GCSubwindowMode
)
148 values
.subwindow_mode
= pGC
->subWindowMode
;
150 if (mask
& GCGraphicsExposures
)
151 values
.graphics_exposures
= pGC
->graphicsExposures
;
153 if (mask
& GCClipXOrigin
)
154 values
.clip_x_origin
= pGC
->clipOrg
.x
;
156 if (mask
& GCClipYOrigin
)
157 values
.clip_y_origin
= pGC
->clipOrg
.y
;
159 if (mask
& GCClipMask
) /* this is handled in change clip */
162 if (mask
& GCDashOffset
)
163 values
.dash_offset
= pGC
->dashOffset
;
165 if (mask
& GCDashList
) {
167 XSetDashes(xnestDisplay
, xnestGC(pGC
),
168 pGC
->dashOffset
, (char *) pGC
->dash
, pGC
->numInDashList
);
171 if (mask
& GCArcMode
)
172 values
.arc_mode
= pGC
->arcMode
;
175 XChangeGC(xnestDisplay
, xnestGC(pGC
), mask
, &values
);
179 xnestCopyGC(GCPtr pGCSrc
, unsigned long mask
, GCPtr pGCDst
)
181 XCopyGC(xnestDisplay
, xnestGC(pGCSrc
), mask
, xnestGC(pGCDst
));
185 xnestDestroyGC(GCPtr pGC
)
187 XFreeGC(xnestDisplay
, xnestGC(pGC
));
191 xnestChangeClip(GCPtr pGC
, int type
, pointer pValue
, int nRects
)
197 xnestDestroyClipHelper(pGC
);
201 XSetClipMask(xnestDisplay
, xnestGC(pGC
), None
);
205 nRects
= RegionNumRects((RegionPtr
) pValue
);
206 size
= nRects
* sizeof(*pRects
);
207 pRects
= (XRectangle
*) malloc(size
);
208 pBox
= RegionRects((RegionPtr
) pValue
);
209 for (i
= nRects
; i
-- > 0;) {
210 pRects
[i
].x
= pBox
[i
].x1
;
211 pRects
[i
].y
= pBox
[i
].y1
;
212 pRects
[i
].width
= pBox
[i
].x2
- pBox
[i
].x1
;
213 pRects
[i
].height
= pBox
[i
].y2
- pBox
[i
].y1
;
215 XSetClipRectangles(xnestDisplay
, xnestGC(pGC
), 0, 0,
216 pRects
, nRects
, Unsorted
);
217 free((char *) pRects
);
221 XSetClipMask(xnestDisplay
, xnestGC(pGC
),
222 xnestPixmap((PixmapPtr
) pValue
));
224 * Need to change into region, so subsequent uses are with
225 * current pixmap contents.
228 (pointer
) (*pGC
->pScreen
->BitmapToRegion
) ((PixmapPtr
) pValue
);
229 (*pGC
->pScreen
->DestroyPixmap
) ((PixmapPtr
) pValue
);
230 pValue
= pGC
->clientClip
;
235 XSetClipRectangles(xnestDisplay
, xnestGC(pGC
),
236 pGC
->clipOrg
.x
, pGC
->clipOrg
.y
,
237 (XRectangle
*) pValue
, nRects
, Unsorted
);
241 XSetClipRectangles(xnestDisplay
, xnestGC(pGC
),
242 pGC
->clipOrg
.x
, pGC
->clipOrg
.y
,
243 (XRectangle
*) pValue
, nRects
, YSorted
);
247 XSetClipRectangles(xnestDisplay
, xnestGC(pGC
),
248 pGC
->clipOrg
.x
, pGC
->clipOrg
.y
,
249 (XRectangle
*) pValue
, nRects
, YXSorted
);
253 XSetClipRectangles(xnestDisplay
, xnestGC(pGC
),
254 pGC
->clipOrg
.x
, pGC
->clipOrg
.y
,
255 (XRectangle
*) pValue
, nRects
, YXBanded
);
269 * other parts of server can only deal with CT_NONE,
270 * CT_PIXMAP and CT_REGION client clips.
272 pGC
->clientClip
= (pointer
) RegionFromRects(nRects
,
273 (xRectangle
*) pValue
,
276 pValue
= pGC
->clientClip
;
282 pGC
->clientClipType
= type
;
283 pGC
->clientClip
= pValue
;
287 xnestDestroyClip(GCPtr pGC
)
289 xnestDestroyClipHelper(pGC
);
291 XSetClipMask(xnestDisplay
, xnestGC(pGC
), None
);
293 pGC
->clientClipType
= CT_NONE
;
294 pGC
->clientClip
= NULL
;
298 xnestDestroyClipHelper(GCPtr pGC
)
300 switch (pGC
->clientClipType
) {
306 RegionDestroy(pGC
->clientClip
);
312 xnestCopyClip(GCPtr pGCDst
, GCPtr pGCSrc
)
316 switch (pGCSrc
->clientClipType
) {
319 xnestDestroyClip(pGCDst
);
323 pRgn
= RegionCreate(NULL
, 1);
324 RegionCopy(pRgn
, pGCSrc
->clientClip
);
325 xnestChangeClip(pGCDst
, CT_REGION
, pRgn
, 0);