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