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

« back to all changes in this revision

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