First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xprint / ps / PsWindow.c
blob1317fd704f5c9e3169d2744892d86b3d27d419f7
1 /*
3 Copyright 1996, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
27 * (c) Copyright 1996 Hewlett-Packard Company
28 * (c) Copyright 1996 International Business Machines Corp.
29 * (c) Copyright 1996 Sun Microsystems, Inc.
30 * (c) Copyright 1996 Novell, Inc.
31 * (c) Copyright 1996 Digital Equipment Corp.
32 * (c) Copyright 1996 Fujitsu Limited
33 * (c) Copyright 1996 Hitachi, Ltd.
35 * Permission is hereby granted, free of charge, to any person obtaining
36 * a copy of this software and associated documentation files (the
37 * "Software"), to deal in the Software without restriction, including
38 * without limitation the rights to use, copy, modify, merge, publish,
39 * distribute, sublicense, and/or sell copies of the Software, and to
40 * permit persons to whom the Software is furnished to do so, subject
41 * to the following conditions:
43 * The above copyright notice and this permission notice shall be included
44 * in all copies or substantial portions of the Software.
46 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
47 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
48 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
49 * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
50 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
51 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
52 * SOFTWARE.
54 * Except as contained in this notice, the names of the copyright holders
55 * shall not be used in advertising or otherwise to promote the sale, use
56 * or other dealings in this Software without prior written authorization
57 * from said copyright holders.
60 /*******************************************************************
62 ** *********************************************************
63 ** *
64 ** * File: PsWindow.c
65 ** *
66 ** * Contents: Window code for PS driver.
67 ** *
68 ** * Created By: Roger Helmendach (Liberty Systems)
69 ** *
70 ** * Copyright: Copyright 1996 The Open Group, Inc.
71 ** *
72 ** *********************************************************
73 **
74 ********************************************************************/
76 #ifdef HAVE_DIX_CONFIG_H
77 #include <dix-config.h>
78 #endif
80 #include <stdio.h>
81 #include <string.h>
82 #include <sys/wait.h>
84 #include "mistruct.h"
85 #include "regionstr.h"
86 #include "windowstr.h"
87 #include "gcstruct.h"
89 #include "Ps.h"
92 * The following list of strings defines the properties which will be
93 * placed on the screen's root window if the property was defined in
94 * the start-up configuration resource database.
96 #if 0
97 static char *propStrings[] = {
98 DT_PRINT_JOB_HEADER,
99 DT_PRINT_JOB_TRAILER,
100 DT_PRINT_JOB_COMMAND,
101 DT_PRINT_JOB_EXEC_COMMAND,
102 DT_PRINT_JOB_EXEC_OPTIONS,
103 DT_PRINT_PAGE_HEADER,
104 DT_PRINT_PAGE_TRAILER,
105 DT_PRINT_PAGE_COMMAND,
106 (char *)NULL
108 #endif
111 * PsCreateWindow - watch for the creation of the root window.
112 * When it's created, register the screen with the print extension,
113 * and put the default command/header properties on it.
115 /*ARGSUSED*/
117 Bool
118 PsCreateWindow(WindowPtr pWin)
120 PsWindowPrivPtr pPriv;
122 #if 0
123 Bool status = Success;
124 ScreenPtr pScreen = pWin->drawable.pScreen;
125 PsScreenPrivPtr pScreenPriv = (PsScreenPrivPtr)
126 pScreen->devPrivates[PsScreenPrivateIndex].ptr;
127 PsWindowPrivPtr pWinPriv = (PsWindowPrivPtr)
128 pWin->devPrivates[PsWindowPrivateIndex].ptr;
131 * Initialize this window's private struct.
133 pWinPriv->jobFileName = (char *)NULL;
134 pWinPriv->pJobFile = (FILE *)NULL;
135 pWinPriv->pageFileName = (char *)NULL;
136 pWinPriv->pPageFile = (FILE *)NULL;
138 if(pWin->parent == (WindowPtr)NULL) /* root window? */
140 Atom propName; /* type = XA_STRING */
141 char *propVal;
142 int i;
143 XrmDatabase rmdb = pScreenPriv->resDB;
146 * Put the defaults spec'd in the config files in properties on this
147 * screen's root window.
149 for(i = 0; propStrings[i] != (char *)NULL; i++)
151 if((propVal = _DtPrintGetPrinterResource(pWin, rmdb,
152 propStrings[i])) !=
153 (char *)NULL)
155 propName = MakeAtom(propStrings[i], strlen(propStrings[i]),
156 TRUE);
157 ChangeWindowProperty(pWin, propName, XA_STRING, 8,
158 PropModeReplace, strlen(propVal),
159 (pointer)propVal, FALSE);
160 xfree(propVal);
165 return status;
166 #endif
168 pPriv = (PsWindowPrivPtr)pWin->devPrivates[PsWindowPrivateIndex].ptr;
169 pPriv->validContext = 0;
171 return TRUE;
175 /*ARGSUSED*/
176 Bool PsMapWindow(WindowPtr pWindow)
178 return TRUE;
181 /*ARGSUSED*/
182 Bool
183 PsPositionWindow(
184 WindowPtr pWin,
185 int x,
186 int y)
188 return TRUE;
191 /*ARGSUSED*/
192 Bool
193 PsUnmapWindow(WindowPtr pWindow)
195 return TRUE;
198 /*ARGSUSED*/
199 void
200 PsCopyWindow(
201 WindowPtr pWin,
202 DDXPointRec ptOldOrg,
203 RegionPtr prgnSrc)
207 /*ARGSUSED*/
208 Bool
209 PsChangeWindowAttributes(
210 WindowPtr pWin,
211 unsigned long mask)
213 return TRUE;
217 void
218 PsPaintWindow(
219 WindowPtr pWin,
220 RegionPtr pRegion,
221 int what)
223 WindowPtr pRoot;
225 #define FUNCTION 0
226 #define FOREGROUND 1
227 #define TILE 2
228 #define FILLSTYLE 3
229 #define ABSX 4
230 #define ABSY 5
231 #define CLIPMASK 6
232 #define SUBWINDOW 7
233 #define COUNT_BITS 8
235 pointer gcval[7];
236 pointer newValues [COUNT_BITS];
238 BITS32 gcmask, index, mask;
239 RegionRec prgnWin;
240 DDXPointRec oldCorner;
241 BoxRec box;
242 WindowPtr pBgWin;
243 GCPtr pGC;
244 register int i;
245 register BoxPtr pbox;
246 register ScreenPtr pScreen = pWin->drawable.pScreen;
247 register xRectangle *prect;
248 int numRects;
250 gcmask = 0;
253 * We don't want to paint a window that has no place to put the
254 * PS output.
256 if( PsGetContextFromWindow(pWin)==(XpContextPtr)NULL ) return;
258 if( what==PW_BACKGROUND )
260 switch(pWin->backgroundState)
262 case None: return;
263 case ParentRelative:
264 (*pWin->parent->drawable.pScreen->PaintWindowBackground)
265 (pWin->parent, pRegion, what);
266 return;
267 case BackgroundPixel:
268 newValues[FOREGROUND] = (pointer)pWin->background.pixel;
269 newValues[FILLSTYLE] = (pointer)FillSolid;
270 gcmask |= GCForeground | GCFillStyle;
271 break;
272 case BackgroundPixmap:
273 newValues[TILE] = (pointer)pWin->background.pixmap;
274 newValues[FILLSTYLE] = (pointer)FillTiled;
275 gcmask |= GCTile | GCFillStyle | GCTileStipXOrigin | GCTileStipYOrigin;
276 break;
279 else
281 if( pWin->borderIsPixel )
283 newValues[FOREGROUND] = (pointer)pWin->border.pixel;
284 newValues[FILLSTYLE] = (pointer)FillSolid;
285 gcmask |= GCForeground | GCFillStyle;
287 else
289 newValues[TILE] = (pointer)pWin->border.pixmap;
290 newValues[FILLSTYLE] = (pointer)FillTiled;
291 gcmask |= GCTile | GCFillStyle | GCTileStipXOrigin | GCTileStipYOrigin;
295 prect = (xRectangle *)ALLOCATE_LOCAL(REGION_NUM_RECTS(pRegion) *
296 sizeof(xRectangle));
297 if( !prect ) return;
299 newValues[FUNCTION] = (pointer)GXcopy;
300 gcmask |= GCFunction | GCClipMask;
302 i = pScreen->myNum;
303 pRoot = WindowTable[i];
305 pBgWin = pWin;
306 if (what == PW_BORDER)
308 while( pBgWin->backgroundState==ParentRelative ) pBgWin = pBgWin->parent;
311 pGC = GetScratchGC(pWin->drawable.depth, pWin->drawable.pScreen);
312 if( !pGC )
314 DEALLOCATE_LOCAL(prect);
315 return;
318 * mash the clip list so we can paint the border by
319 * mangling the window in place, pretending it
320 * spans the entire screen
322 if( what==PW_BORDER )
324 prgnWin = pWin->clipList;
325 oldCorner.x = pWin->drawable.x;
326 oldCorner.y = pWin->drawable.y;
327 pWin->drawable.x = pWin->drawable.y = 0;
328 box.x1 = 0;
329 box.y1 = 0;
330 box.x2 = pScreen->width;
331 box.y2 = pScreen->height;
332 REGION_INIT(pScreen, &pWin->clipList, &box, 1);
333 pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER;
334 newValues[ABSX] = (pointer)(long)pBgWin->drawable.x;
335 newValues[ABSY] = (pointer)(long)pBgWin->drawable.y;
337 else
339 newValues[ABSX] = (pointer)0;
340 newValues[ABSY] = (pointer)0;
344 * XXX Backing store is turned off for the PS driver
346 if( pWin->backStorage )
347 (*pWin->drawable.pScreen->DrawGuarantee) (pWin, pGC, GuaranteeVisBack);
350 mask = gcmask;
351 gcmask = 0;
352 i = 0;
353 while( mask )
355 index = lowbit (mask);
356 mask &= ~index;
357 switch(index)
359 case GCFunction:
360 if( (pointer)(long)pGC->alu!=newValues[FUNCTION] )
362 gcmask |= index;
363 gcval[i++] = newValues[FUNCTION];
365 break;
366 case GCTileStipXOrigin:
367 if( (pointer)(long)pGC->patOrg.x!=newValues[ABSX] )
369 gcmask |= index;
370 gcval[i++] = newValues[ABSX];
372 break;
373 case GCTileStipYOrigin:
374 if( (pointer)(long)pGC->patOrg.y!=newValues[ABSY] )
376 gcmask |= index;
377 gcval[i++] = newValues[ABSY];
379 break;
380 case GCClipMask:
381 if( (pointer)pGC->clientClipType!=(pointer)CT_NONE )
383 gcmask |= index;
384 gcval[i++] = (pointer)CT_NONE;
386 break;
387 case GCSubwindowMode:
388 if( (pointer)pGC->subWindowMode!=newValues[SUBWINDOW] )
390 gcmask |= index;
391 gcval[i++] = newValues[SUBWINDOW];
393 break;
394 case GCTile:
395 if( pGC->tileIsPixel || (pointer)pGC->tile.pixmap!=newValues[TILE] )
397 gcmask |= index;
398 gcval[i++] = newValues[TILE];
400 break;
401 case GCFillStyle:
402 if( (pointer)pGC->fillStyle!=newValues[FILLSTYLE] )
404 gcmask |= index;
405 gcval[i++] = newValues[FILLSTYLE];
407 break;
408 case GCForeground:
409 if( (pointer)pGC->fgPixel!=newValues[FOREGROUND] )
411 gcmask |= index;
412 gcval[i++] = newValues[FOREGROUND];
414 break;
418 if( gcmask ) DoChangeGC(pGC, gcmask, (XID *)gcval, 1);
420 if( pWin->drawable.serialNumber!=pGC->serialNumber )
421 ValidateGC((DrawablePtr)pWin, pGC);
423 numRects = REGION_NUM_RECTS(pRegion);
424 pbox = REGION_RECTS(pRegion);
425 for( i=numRects ; --i >= 0 ; pbox++,prect++ )
427 prect->x = pbox->x1 - pWin->drawable.x;
428 prect->y = pbox->y1 - pWin->drawable.y;
429 prect->width = pbox->x2 - pbox->x1;
430 prect->height = pbox->y2 - pbox->y1;
432 prect -= numRects;
433 (*pGC->ops->PolyFillRect)((DrawablePtr)pWin, pGC, numRects, prect);
434 DEALLOCATE_LOCAL(prect);
437 * XXX Backing store is turned off for the PS driver
439 if( pWin->backStorage )
440 (*pWin->drawable.pScreen->DrawGuarantee) (pWin, pGC, GuaranteeNothing);
443 if( what==PW_BORDER )
445 REGION_UNINIT(pScreen, &pWin->clipList);
446 pWin->clipList = prgnWin;
447 pWin->drawable.x = oldCorner.x;
448 pWin->drawable.y = oldCorner.y;
449 pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER;
451 FreeScratchGC(pGC);
454 /*ARGSUSED*/
455 Bool
456 PsDestroyWindow(WindowPtr pWin)
458 return TRUE;