~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to Xprint/ps/PsWindow.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

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