summaryrefslogtreecommitdiff
path: root/vcl/inc/vcl/print.hxx
blob: b9176f4106dc961f014ce7b0207aee5c20344706 (plain)
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
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: print.hxx,v $
 * $Revision: 1.6.86.1 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef _SV_PRINT_HXX
#define _SV_PRINT_HXX

#include <tools/errcode.hxx>
#include <vcl/sv.h>
#include <vcl/dllapi.h>
#include <vcl/outdev.hxx>
#include <vcl/prntypes.hxx>
#include <vcl/jobset.hxx>
#include <vcl/gdimtf.hxx>
#include <tools/stream.hxx>

struct SalPrinterInfoQueue;
class SalInfoPrinter;
struct SalPrinterQueueInfo;
class SalPrinter;
class VirtualDevice;
class Window;
class ImplQPrinter;
struct ImplPrivatePrinterData;

namespace com { namespace sun { namespace star { namespace uno {
    class Any;
} } } }

// -----------------
// - Printer-Types -
// -----------------

#define PAGEQUEUE_ALLPAGES   0xFFFF

enum PrinterSupport { SUPPORT_SET_ORIENTATION, SUPPORT_SET_PAPERBIN,
                      SUPPORT_SET_PAPERSIZE, SUPPORT_SET_PAPER,
                      SUPPORT_COPY, SUPPORT_COLLATECOPY,
                      SUPPORT_SETUPDIALOG, SUPPORT_FAX, SUPPORT_PDF };

// ---------------
// - PrinterPage -
// ---------------

class VCL_DLLPUBLIC PrinterPage
{
    GDIMetaFile*    mpMtf;
    JobSetup        maJobSetup;
    UINT16          mbNewJobSetup;

public:

    PrinterPage() : mpMtf( new GDIMetaFile() ) {}
    PrinterPage( GDIMetaFile* pMtf, BOOL bNewJobSetup, const JobSetup& rSetup ) :
           mpMtf( pMtf ), maJobSetup( rSetup ), mbNewJobSetup( bNewJobSetup ) {}
    ~PrinterPage() { delete mpMtf; }

    GDIMetaFile*    GetGDIMetaFile() const { return mpMtf; }
    const JobSetup& GetJobSetup() const { return maJobSetup; }
    BOOL            IsNewJobSetup() const { return (mbNewJobSetup != 0); }

    friend VCL_DLLPUBLIC SvStream& operator<<( SvStream& rOStm, const PrinterPage& rPage )
    { rOStm << rPage.mbNewJobSetup; rOStm << rPage.maJobSetup; rPage.mpMtf->Write( rOStm ); return rOStm; }
    friend VCL_DLLPUBLIC SvStream& operator>>( SvStream& rIStm, PrinterPage& rPage )
    { return rIStm >> rPage.mbNewJobSetup >> rPage.maJobSetup >> *rPage.mpMtf; }
};


// -------------
// - QueueInfo -
// -------------

class VCL_DLLPUBLIC QueueInfo
{
    friend class Printer;

private:
    XubString                   maPrinterName;
    XubString                   maDriver;
    XubString                   maLocation;
    XubString                   maComment;
    sal_uInt32                  mnStatus;
    sal_uInt32                  mnJobs;

public:
                                QueueInfo();
                                QueueInfo( const QueueInfo& rInfo );
                                ~QueueInfo();

    const XubString&            GetPrinterName() const { return maPrinterName; }
    const XubString&            GetDriver() const { return maDriver; }
    const XubString&            GetLocation() const { return maLocation; }
    const XubString&            GetComment() const { return maComment; }
    sal_uInt32                  GetStatus() const { return mnStatus; }
    sal_uInt32                  GetJobs() const { return mnJobs; }

    bool operator==( const QueueInfo& rInfo ) const;

    friend VCL_DLLPUBLIC SvStream&          operator>>( SvStream& rIStream, QueueInfo& rInfo );
    friend VCL_DLLPUBLIC SvStream&          operator<<( SvStream& rOStream, const QueueInfo& rInfo );
};

// ------------------
// - PrinterOptions -
// ------------------

enum PrinterTransparencyMode
{
    PRINTER_TRANSPARENCY_AUTO = 0,
    PRINTER_TRANSPARENCY_NONE = 1
};

// -----------------------------------------------------------------------------

enum PrinterGradientMode
{
    PRINTER_GRADIENT_STRIPES = 0,
    PRINTER_GRADIENT_COLOR = 1
};

// -----------------------------------------------------------------------------

enum PrinterBitmapMode
{
    PRINTER_BITMAP_OPTIMAL = 0,
    PRINTER_BITMAP_NORMAL = 1,
    PRINTER_BITMAP_RESOLUTION = 2
};

// -----------------------------------------------------------------------------

class VCL_DLLPUBLIC PrinterOptions
{
private:

    BOOL                        mbReduceTransparency;
    PrinterTransparencyMode     meReducedTransparencyMode;
    BOOL                        mbReduceGradients;
    PrinterGradientMode         meReducedGradientsMode;
    USHORT                      mnReducedGradientStepCount;
    BOOL                        mbReduceBitmaps;
    PrinterBitmapMode           meReducedBitmapMode;
    USHORT                      mnReducedBitmapResolution;
    BOOL                        mbReducedBitmapsIncludeTransparency;
    BOOL                        mbConvertToGreyscales;

public:

                                PrinterOptions();
                                ~PrinterOptions();

    BOOL                        IsReduceTransparency() const { return mbReduceTransparency; }
    void                        SetReduceTransparency( BOOL bSet ) { mbReduceTransparency = bSet; }

    PrinterTransparencyMode     GetReducedTransparencyMode() const { return meReducedTransparencyMode; }
    void                        SetReducedTransparencyMode( PrinterTransparencyMode eMode ) { meReducedTransparencyMode = eMode; }

    BOOL                        IsReduceGradients() const { return mbReduceGradients; }
    void                        SetReduceGradients( BOOL bSet ) { mbReduceGradients = bSet; }

    PrinterGradientMode         GetReducedGradientMode() const { return meReducedGradientsMode; }
    void                        SetReducedGradientMode( PrinterGradientMode eMode ) { meReducedGradientsMode = eMode; }

    USHORT                      GetReducedGradientStepCount() const { return mnReducedGradientStepCount; }
    void                        SetReducedGradientStepCount( USHORT nStepCount ) { mnReducedGradientStepCount = nStepCount; }

    BOOL                        IsReduceBitmaps() const { return mbReduceBitmaps; }
    void                        SetReduceBitmaps( BOOL bSet ) { mbReduceBitmaps = bSet; }

    PrinterBitmapMode           GetReducedBitmapMode() const { return meReducedBitmapMode; }
    void                        SetReducedBitmapMode( PrinterBitmapMode eMode ) { meReducedBitmapMode = eMode; }

    USHORT                      GetReducedBitmapResolution() const { return mnReducedBitmapResolution; }
    void                        SetReducedBitmapResolution( USHORT nResolution ) { mnReducedBitmapResolution = nResolution; }

    BOOL                        IsReducedBitmapIncludesTransparency() const { return mbReducedBitmapsIncludeTransparency; }
    void                        SetReducedBitmapIncludesTransparency( BOOL bSet ) { mbReducedBitmapsIncludeTransparency = bSet; }

    BOOL                        IsConvertToGreyscales() const { return mbConvertToGreyscales; }
    void                        SetConvertToGreyscales( BOOL bSet ) { mbConvertToGreyscales = bSet; }
};

// -----------
// - Printer -
// -----------

class VCL_DLLPUBLIC Printer : public OutputDevice
{
    friend class OutputDevice;
    friend class ImplQPrinter;

private:
    ImplPrivatePrinterData*     mpPrinterData;
    SalInfoPrinter*             mpInfoPrinter;
    SalPrinter*                 mpPrinter;
    Printer*                    mpJobPrinter;
    SalGraphics*                mpJobGraphics;
    Printer*                    mpPrev;
    Printer*                    mpNext;
    VirtualDevice*              mpDisplayDev;
    ImplQPrinter*               mpQPrinter;
    GDIMetaFile*                mpQMtf;
    PrinterOptions*             mpPrinterOptions;
    XubString                   maPrinterName;
    XubString                   maDriver;
    XubString                   maPrintFile;
    XubString                   maJobName;
    JobSetup                    maJobSetup;
    Point                       maPageOffset;
    Size                        maPaperSize;
    ULONG                       mnError;
    USHORT                      mnCurPage;
    USHORT                      mnCurPrintPage;
    USHORT                      mnPageQueueSize;
    USHORT                      mnCopyCount;
    BOOL                        mbDefPrinter;
    BOOL                        mbPrinting;
    BOOL                        mbJobActive;
    BOOL                        mbCollateCopy;
    BOOL                        mbPrintFile;
    BOOL                        mbInPrintPage;
    BOOL                        mbNewJobSetup;
    BOOL                        mbIsQueuePrinter;
    BOOL                        mbUserSetupCompleted;
    BOOL                        mbUserSetupResult;
    Link                        maErrorHdl;
    Link                        maStartPrintHdl;
    Link                        maEndPrintHdl;
    Link                        maPrintPageHdl;

    SAL_DLLPRIVATE void         ImplInitData();
    SAL_DLLPRIVATE void         ImplInit( SalPrinterQueueInfo* pInfo );
    SAL_DLLPRIVATE void         ImplInitDisplay( const Window* pWindow );
    SAL_DLLPRIVATE static SalPrinterQueueInfo* ImplGetQueueInfo( const XubString& rPrinterName,
                                                  const XubString* pDriver );
    SAL_DLLPRIVATE void         ImplUpdatePageData();
    SAL_DLLPRIVATE void         ImplUpdateFontList();
    SAL_DLLPRIVATE void         ImplFindPaperFormatForUserSize( JobSetup& );
    DECL_DLLPRIVATE_LINK(       ImplDestroyPrinterAsync, void* );
public:
    SAL_DLLPRIVATE void         ImplEndPrint();
    SAL_DLLPRIVATE void         ImplUpdateQuickStatus();
private:
    SAL_DLLPRIVATE              Printer( const Printer& rPrinter );
    SAL_DLLPRIVATE Printer&     operator =( const Printer& rPrinter );

#ifdef _SPOOLPRINTER_EXT
public:
    void                        DrawGradientEx( OutputDevice* pOut, const Rectangle& rRect, const Gradient& rGradient );
    void                        DrawGradientEx( OutputDevice* pOut, const PolyPolygon& rPolyPoly, const Gradient& rGradient );

#endif // _SPOOLPRINTER_EXT

protected:

    void                        SetSelfAsQueuePrinter( BOOL bQueuePrinter ) { mbIsQueuePrinter = bQueuePrinter; }
    BOOL                        IsQueuePrinter() const { return mbIsQueuePrinter; }

public:
                                Printer();
                                Printer( const Window* pWindow );
                                Printer( const JobSetup& rJobSetup );
                                Printer( const QueueInfo& rQueueInfo );
                                Printer( const XubString& rPrinterName );
    virtual                     ~Printer();

    static const std::vector< rtl::OUString >& GetPrinterQueues();
    static const QueueInfo*     GetQueueInfo( const String& rPrinterName, bool bStatusUpdate );
    static XubString            GetDefaultPrinterName();

    virtual void                Error();
    virtual void                StartPrint();
    virtual void                EndPrint();
    virtual void                PrintPage();

    const XubString&            GetName() const             { return maPrinterName; }
    const XubString&            GetDriverName() const       { return maDriver; }
    BOOL                        IsDefPrinter() const        { return mbDefPrinter; }
    BOOL                        IsDisplayPrinter() const    { return mpDisplayDev != NULL; }
    BOOL                        IsValid() const             { return !IsDisplayPrinter(); }

    ULONG                       GetCapabilities( USHORT nType ) const;
    BOOL                        HasSupport( PrinterSupport eFeature ) const;

    BOOL                        SetJobSetup( const JobSetup& rSetup );
    const JobSetup&             GetJobSetup() const { return maJobSetup; }
    String                      GetJobValue( const String& rKey ) const { return maJobSetup.GetValue( rKey ); }
    void                        SetJobValue( const String& rKey, const String& rValue ) { maJobSetup.SetValue( rKey, rValue ); }

    BOOL                        Setup( Window* pWindow = NULL );
    BOOL                        SetPrinterProps( const Printer* pPrinter );

    void                        SetPrinterOptions( const PrinterOptions& rOptions ) { *mpPrinterOptions = rOptions; }
    const PrinterOptions&       GetPrinterOptions() const { return( *mpPrinterOptions ); }

    BOOL                        SetOrientation( Orientation eOrient );
    Orientation                 GetOrientation() const;
    DuplexMode                  GetDuplexMode() const;
    // returns the angle that a landscape page will be turned counterclockwise
    // wrt to portrait. The return value may be only valid for
    // the current paper
    int                         GetLandscapeAngle() const;
    BOOL                        SetPaperBin( USHORT nPaperBin );
    USHORT                      GetPaperBin() const;
    BOOL                        SetPaper( Paper ePaper );
    BOOL                        SetPaperSizeUser( const Size& rSize );
    Paper                   GetPaper() const;

    // returns number of available paper formats
    int                         GetPaperInfoCount() const;
    // returns info about paper format nPaper
    const PaperInfo&            GetPaperInfo( int nPaper ) const;
    USHORT                      GetPaperBinCount() const;
    XubString                   GetPaperBinName( USHORT nPaperBin ) const;

    const Size&                 GetPaperSizePixel() const { return maPaperSize; }
    Size                        GetPaperSize() const { return PixelToLogic( maPaperSize ); }
    const Point&                GetPageOffsetPixel() const { return maPageOffset; }
    Point                       GetPageOffset() const { return PixelToLogic( maPageOffset ); }

    BOOL                        SetCopyCount( USHORT nCopy, BOOL bCollate = FALSE );
    USHORT                      GetCopyCount() const { return mnCopyCount; }
    BOOL                        IsCollateCopy() const { return mbCollateCopy; }

    USHORT                      GetCurPrintPage() const { return mnCurPrintPage; }
    BOOL                        IsPrinting() const { return mbPrinting; }

    void                        SetPrintFile( const XubString& rFileName ) { maPrintFile = rFileName; }
    const XubString&            GetPrintFile() const { return maPrintFile; }
    void                        EnablePrintFile( BOOL bEnable ) { mbPrintFile = bEnable; }
    BOOL                        IsPrintFileEnabled() const { return mbPrintFile; }
    BOOL                        StartJob( const XubString& rJobName );
    BOOL                        EndJob();
    BOOL                        AbortJob();
    const XubString&            GetCurJobName() const { return maJobName; }
    USHORT                      GetCurPage() const { return mnCurPage; }
    BOOL                        IsJobActive() const { return mbJobActive; }
    BOOL                        StartPage();
    BOOL                        EndPage();

    void                        SetPageQueueSize( USHORT nPages ) { mnPageQueueSize = nPages; }
    USHORT                      GetPageQueueSize() const { return mnPageQueueSize; }

    ULONG                       GetError() const { return ERRCODE_TOERROR(mnError); }
    ULONG                       GetErrorCode() const { return mnError; }

    void                        SetErrorHdl( const Link& rLink ) { maErrorHdl = rLink; }
    const Link&                 GetErrorHdl() const { return maErrorHdl; }
    void                        SetStartPrintHdl( const Link& rLink ) { maStartPrintHdl = rLink; }
    const Link&                 GetStartPrintHdl() const { return maStartPrintHdl; }
    void                        SetEndPrintHdl( const Link& rLink ) { maEndPrintHdl = rLink; }
    const Link&                 GetEndPrintHdl() const   { return maEndPrintHdl;   }
    void                        SetPrintPageHdl( const Link& rLink ) { maPrintPageHdl = rLink; }
    const Link&                 GetPrintPageHdl() const  { return maPrintPageHdl;  }

    void                        Compat_OldPrinterMetrics( bool bSet );

    /** Notify that the next StartJob belongs to a UI less "direct print" job
    *
    *   deprecated: the canonical way to notify a UI less job is to set the
    *   JobSetup value "IsQuickJob" to "true". If set at all, the "IsQuickJob" value
    *   on JobSetup will be preferred. However if no "IsQuickJob" value is set,
    *   setting SetNextJobIsQuick will cause the following StartJob to set this value
    *   to "true" in the current JobSetup.
    *
    *   the paramter can be set to "false" again in case a job was not started and the
    *   printer is to be reused.
    */
    void                        SetNextJobIsQuick( bool bQuick = true );

    /** checks the printer list and updates it necessary
    *
    *   sends a DataChanged event of type DATACHANGED_PRINTER
    *   if the printer list changed
    */
    static void updatePrinters();
};

#endif  // _SV_PRINT_HXX