Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <list>
22 :
23 : #include <tools/debug.hxx>
24 : #include <tools/resary.hxx>
25 : #include <tools/stream.hxx>
26 : #include <tools/vcompat.hxx>
27 :
28 : #include <vcl/unohelp.hxx>
29 : #include <vcl/svapp.hxx>
30 : #include <vcl/wrkwin.hxx>
31 : #include <vcl/virdev.hxx>
32 : #include <vcl/window.hxx>
33 : #include <vcl/gdimtf.hxx>
34 : #include <vcl/metaact.hxx>
35 : #include <vcl/print.hxx>
36 :
37 : #include <salinst.hxx>
38 : #include <salgdi.hxx>
39 : #include <salptype.hxx>
40 : #include <salprn.hxx>
41 : #include <svdata.hxx>
42 : #include <svids.hrc>
43 : #include <jobset.h>
44 : #include <outdev.h>
45 : #include <print.h>
46 :
47 : #include <comphelper/processfactory.hxx>
48 :
49 : #include "com/sun/star/beans/XPropertySet.hpp"
50 : #include "com/sun/star/configuration/theDefaultProvider.hpp"
51 : #include "com/sun/star/container/XNameAccess.hpp"
52 : #include "com/sun/star/lang/XMultiServiceFactory.hpp"
53 :
54 : using namespace com::sun::star::uno;
55 : using namespace com::sun::star::lang;
56 : using namespace com::sun::star::beans;
57 : using namespace com::sun::star::container;
58 : using namespace com::sun::star::configuration;
59 :
60 : int nImplSysDialog = 0;
61 :
62 : namespace
63 : {
64 0 : static Paper ImplGetPaperFormat( long nWidth100thMM, long nHeight100thMM )
65 : {
66 0 : PaperInfo aInfo(nWidth100thMM, nHeight100thMM);
67 0 : aInfo.doSloppyFit();
68 0 : return aInfo.getPaper();
69 : }
70 :
71 0 : static const PaperInfo& ImplGetEmptyPaper()
72 : {
73 0 : static PaperInfo aInfo(PAPER_USER);
74 0 : return aInfo;
75 : }
76 : }
77 :
78 :
79 80 : void ImplUpdateJobSetupPaper( JobSetup& rJobSetup )
80 : {
81 80 : const ImplJobSetup* pConstData = rJobSetup.ImplGetConstData();
82 :
83 80 : if ( !pConstData->mnPaperWidth || !pConstData->mnPaperHeight )
84 : {
85 80 : if ( pConstData->mePaperFormat != PAPER_USER )
86 : {
87 80 : ImplJobSetup* pData = rJobSetup.ImplGetData();
88 80 : PaperInfo aInfo(pConstData->mePaperFormat);
89 80 : pData->mnPaperWidth = aInfo.getWidth();
90 80 : pData->mnPaperHeight = aInfo.getHeight();
91 80 : }
92 : }
93 0 : else if ( pConstData->mePaperFormat == PAPER_USER )
94 : {
95 0 : Paper ePaper = ImplGetPaperFormat( pConstData->mnPaperWidth, pConstData->mnPaperHeight );
96 0 : if ( ePaper != PAPER_USER )
97 0 : rJobSetup.ImplGetData()->mePaperFormat = ePaper;
98 : }
99 80 : }
100 :
101 : // PrinterOptions
102 220 : PrinterOptions::PrinterOptions() :
103 : mbReduceTransparency( sal_False ),
104 : meReducedTransparencyMode( PRINTER_TRANSPARENCY_AUTO ),
105 : mbReduceGradients( sal_False ),
106 : meReducedGradientsMode( PRINTER_GRADIENT_STRIPES ),
107 : mnReducedGradientStepCount( 64 ),
108 : mbReduceBitmaps( sal_False ),
109 : meReducedBitmapMode( PRINTER_BITMAP_NORMAL ),
110 : mnReducedBitmapResolution( 200 ),
111 : mbReducedBitmapsIncludeTransparency( sal_True ),
112 : mbConvertToGreyscales( sal_False ),
113 220 : mbPDFAsStandardPrintJobFormat( sal_False )
114 : {
115 220 : }
116 :
117 :
118 208 : PrinterOptions::~PrinterOptions()
119 : {
120 208 : }
121 :
122 : #define PROPERTYNAME_REDUCETRANSPARENCY OUString("ReduceTransparency")
123 : #define PROPERTYNAME_REDUCEDTRANSPARENCYMODE OUString("ReducedTransparencyMode")
124 : #define PROPERTYNAME_REDUCEGRADIENTS OUString("ReduceGradients")
125 : #define PROPERTYNAME_REDUCEDGRADIENTMODE OUString("ReducedGradientMode")
126 : #define PROPERTYNAME_REDUCEDGRADIENTSTEPCOUNT OUString("ReducedGradientStepCount")
127 : #define PROPERTYNAME_REDUCEBITMAPS OUString("ReduceBitmaps")
128 : #define PROPERTYNAME_REDUCEDBITMAPMODE OUString("ReducedBitmapMode")
129 : #define PROPERTYNAME_REDUCEDBITMAPRESOLUTION OUString("ReducedBitmapResolution")
130 : #define PROPERTYNAME_REDUCEDBITMAPINCLUDESTRANSPARENCY OUString("ReducedBitmapIncludesTransparency")
131 : #define PROPERTYNAME_CONVERTTOGREYSCALES OUString("ConvertToGreyscales")
132 : #define PROPERTYNAME_PDFASSTANDARDPRINTJOBFORMAT OUString("PDFAsStandardPrintJobFormat")
133 :
134 0 : bool PrinterOptions::ReadFromConfig( bool i_bFile )
135 : {
136 0 : bool bSuccess = false;
137 : // save old state in case something goes wrong
138 0 : PrinterOptions aOldValues( *this );
139 :
140 : // get the configuration service
141 0 : Reference< XMultiServiceFactory > xConfigProvider;
142 0 : Reference< XNameAccess > xConfigAccess;
143 : try
144 : {
145 : // get service provider
146 0 : Reference< XComponentContext > xContext( comphelper::getProcessComponentContext() );
147 : // create configuration hierachical access name
148 : try
149 : {
150 0 : xConfigProvider = theDefaultProvider::get( xContext );
151 :
152 0 : Sequence< Any > aArgs(1);
153 0 : PropertyValue aVal;
154 0 : aVal.Name = OUString( "nodepath" );
155 0 : if( i_bFile )
156 0 : aVal.Value <<= OUString( "/org.openoffice.Office.Common/Print/Option/File" );
157 : else
158 0 : aVal.Value <<= OUString( "/org.openoffice.Office.Common/Print/Option/Printer" );
159 0 : aArgs.getArray()[0] <<= aVal;
160 0 : xConfigAccess = Reference< XNameAccess >(
161 0 : xConfigProvider->createInstanceWithArguments(
162 0 : OUString( "com.sun.star.configuration.ConfigurationAccess" ), aArgs ),
163 0 : UNO_QUERY );
164 0 : if( xConfigAccess.is() )
165 : {
166 0 : Reference< XPropertySet > xSet( xConfigAccess, UNO_QUERY );
167 0 : if( xSet.is() )
168 : {
169 0 : sal_Int32 nValue = 0;
170 0 : sal_Bool bValue = 0;
171 0 : if( xSet->getPropertyValue(PROPERTYNAME_REDUCETRANSPARENCY) >>= bValue )
172 0 : SetReduceTransparency( bValue );
173 0 : if( xSet->getPropertyValue(PROPERTYNAME_REDUCEDTRANSPARENCYMODE) >>= nValue )
174 0 : SetReducedTransparencyMode( (PrinterTransparencyMode)nValue );
175 0 : if( xSet->getPropertyValue(PROPERTYNAME_REDUCEGRADIENTS) >>= bValue )
176 0 : SetReduceGradients( bValue );
177 0 : if( xSet->getPropertyValue(PROPERTYNAME_REDUCEDGRADIENTMODE) >>= nValue )
178 0 : SetReducedGradientMode( (PrinterGradientMode)nValue );
179 0 : if( xSet->getPropertyValue(PROPERTYNAME_REDUCEDGRADIENTSTEPCOUNT) >>= nValue )
180 0 : SetReducedGradientStepCount( (sal_uInt16)nValue );
181 0 : if( xSet->getPropertyValue(PROPERTYNAME_REDUCEBITMAPS) >>= bValue )
182 0 : SetReduceBitmaps( bValue );
183 0 : if( xSet->getPropertyValue(PROPERTYNAME_REDUCEDBITMAPMODE) >>= nValue )
184 0 : SetReducedBitmapMode( (PrinterBitmapMode)nValue );
185 0 : if( xSet->getPropertyValue(PROPERTYNAME_REDUCEDBITMAPRESOLUTION) >>= nValue )
186 0 : SetReducedBitmapResolution( (sal_uInt16)nValue );
187 0 : if( xSet->getPropertyValue(PROPERTYNAME_REDUCEDBITMAPINCLUDESTRANSPARENCY) >>= bValue )
188 0 : SetReducedBitmapIncludesTransparency( bValue );
189 0 : if( xSet->getPropertyValue(PROPERTYNAME_CONVERTTOGREYSCALES) >>= bValue )
190 0 : SetConvertToGreyscales( bValue );
191 0 : if( xSet->getPropertyValue(PROPERTYNAME_PDFASSTANDARDPRINTJOBFORMAT) >>= bValue )
192 0 : SetPDFAsStandardPrintJobFormat( bValue );
193 :
194 0 : bSuccess = true;
195 0 : }
196 0 : }
197 : }
198 0 : catch( const Exception& )
199 : {
200 0 : }
201 : }
202 0 : catch( const WrappedTargetException& )
203 : {
204 : }
205 :
206 0 : if( ! bSuccess )
207 0 : *this = aOldValues;
208 0 : return bSuccess;
209 : }
210 :
211 0 : void Printer::SetPrinterOptions( const PrinterOptions& i_rOptions )
212 : {
213 0 : *mpPrinterOptions = i_rOptions;
214 0 : }
215 :
216 : // QueueInfo
217 0 : QueueInfo::QueueInfo()
218 : {
219 0 : mnStatus = 0;
220 0 : mnJobs = 0;
221 0 : }
222 :
223 :
224 0 : QueueInfo::QueueInfo( const QueueInfo& rInfo ) :
225 : maPrinterName( rInfo.maPrinterName ),
226 : maDriver( rInfo.maDriver ),
227 : maLocation( rInfo.maLocation ),
228 : maComment( rInfo.maComment ),
229 : mnStatus( rInfo.mnStatus ),
230 0 : mnJobs( rInfo.mnJobs )
231 : {
232 0 : }
233 :
234 :
235 0 : QueueInfo::~QueueInfo()
236 : {
237 0 : }
238 :
239 :
240 0 : bool QueueInfo::operator==( const QueueInfo& rInfo ) const
241 : {
242 : return
243 0 : maPrinterName == rInfo.maPrinterName &&
244 0 : maDriver == rInfo.maDriver &&
245 0 : maLocation == rInfo.maLocation &&
246 0 : maComment == rInfo.maComment &&
247 0 : mnStatus == rInfo.mnStatus &&
248 0 : mnJobs == rInfo.mnJobs;
249 : }
250 :
251 :
252 0 : SvStream& operator<<( SvStream& rOStream, const QueueInfo& rInfo )
253 : {
254 0 : VersionCompat aCompat( rOStream, STREAM_WRITE, 1 );
255 :
256 0 : write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rOStream, rInfo.maPrinterName, RTL_TEXTENCODING_UTF8);
257 0 : write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rOStream, rInfo.maDriver, RTL_TEXTENCODING_UTF8);
258 0 : write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rOStream, rInfo.maLocation, RTL_TEXTENCODING_UTF8);
259 0 : write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rOStream, rInfo.maComment, RTL_TEXTENCODING_UTF8);
260 0 : rOStream << rInfo.mnStatus;
261 0 : rOStream << rInfo.mnJobs;
262 :
263 0 : return rOStream;
264 : }
265 :
266 :
267 0 : SvStream& operator>>( SvStream& rIStream, QueueInfo& rInfo )
268 : {
269 0 : VersionCompat aCompat( rIStream, STREAM_READ );
270 :
271 0 : rInfo.maPrinterName = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rIStream, RTL_TEXTENCODING_UTF8);
272 0 : rInfo.maDriver = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rIStream, RTL_TEXTENCODING_UTF8);
273 0 : rInfo.maLocation = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rIStream, RTL_TEXTENCODING_UTF8);
274 0 : rInfo.maComment = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rIStream, RTL_TEXTENCODING_UTF8);
275 0 : rIStream >> rInfo.mnStatus;
276 0 : rIStream >> rInfo.mnJobs;
277 :
278 0 : return rIStream;
279 : }
280 :
281 :
282 7 : SalPrinterQueueInfo::SalPrinterQueueInfo()
283 : {
284 7 : mnStatus = 0;
285 7 : mnJobs = QUEUE_JOBS_DONTKNOW;
286 7 : mpSysData = NULL;
287 7 : }
288 :
289 :
290 6 : SalPrinterQueueInfo::~SalPrinterQueueInfo()
291 : {
292 6 : }
293 :
294 :
295 12 : ImplPrnQueueList::~ImplPrnQueueList()
296 : {
297 6 : ImplSVData* pSVData = ImplGetSVData();
298 12 : for( unsigned int i = 0; i < m_aQueueInfos.size(); i++ )
299 : {
300 6 : delete m_aQueueInfos[i].mpQueueInfo;
301 6 : pSVData->mpDefInst->DeletePrinterQueueInfo( m_aQueueInfos[i].mpSalQueueInfo );
302 : }
303 6 : }
304 :
305 :
306 7 : void ImplPrnQueueList::Add( SalPrinterQueueInfo* pData )
307 : {
308 : boost::unordered_map< OUString, sal_Int32, OUStringHash >::iterator it =
309 7 : m_aNameToIndex.find( pData->maPrinterName );
310 7 : if( it == m_aNameToIndex.end() )
311 : {
312 7 : m_aNameToIndex[ pData->maPrinterName ] = m_aQueueInfos.size();
313 7 : m_aQueueInfos.push_back( ImplPrnQueueData() );
314 7 : m_aQueueInfos.back().mpQueueInfo = NULL;
315 7 : m_aQueueInfos.back().mpSalQueueInfo = pData;
316 7 : m_aPrinterList.push_back( pData->maPrinterName );
317 : }
318 : else // this should not happen, but ...
319 : {
320 0 : ImplPrnQueueData& rData = m_aQueueInfos[ it->second ];
321 0 : delete rData.mpQueueInfo;
322 0 : rData.mpQueueInfo = NULL;
323 0 : ImplGetSVData()->mpDefInst->DeletePrinterQueueInfo( rData.mpSalQueueInfo );
324 0 : rData.mpSalQueueInfo = pData;
325 : }
326 7 : }
327 :
328 :
329 88 : ImplPrnQueueData* ImplPrnQueueList::Get( const OUString& rPrinter )
330 : {
331 88 : ImplPrnQueueData* pData = NULL;
332 : boost::unordered_map<OUString,sal_Int32,OUStringHash>::iterator it =
333 88 : m_aNameToIndex.find( rPrinter );
334 88 : if( it != m_aNameToIndex.end() )
335 77 : pData = &m_aQueueInfos[it->second];
336 88 : return pData;
337 : }
338 :
339 :
340 31 : static void ImplInitPrnQueueList()
341 : {
342 31 : ImplSVData* pSVData = ImplGetSVData();
343 :
344 31 : pSVData->maGDIData.mpPrinterQueueList = new ImplPrnQueueList;
345 :
346 31 : static const char* pEnv = getenv( "SAL_DISABLE_PRINTERLIST" );
347 31 : if( !pEnv || !*pEnv )
348 31 : pSVData->mpDefInst->GetPrinterQueueInfo( pSVData->maGDIData.mpPrinterQueueList );
349 31 : }
350 :
351 :
352 94 : void ImplDeletePrnQueueList()
353 : {
354 94 : ImplSVData* pSVData = ImplGetSVData();
355 94 : ImplPrnQueueList* pPrnList = pSVData->maGDIData.mpPrinterQueueList;
356 :
357 94 : if ( pPrnList )
358 : {
359 6 : delete pPrnList;
360 6 : pSVData->maGDIData.mpPrinterQueueList = NULL;
361 : }
362 94 : }
363 :
364 :
365 0 : const std::vector<OUString>& Printer::GetPrinterQueues()
366 : {
367 0 : ImplSVData* pSVData = ImplGetSVData();
368 0 : if ( !pSVData->maGDIData.mpPrinterQueueList )
369 0 : ImplInitPrnQueueList();
370 0 : return pSVData->maGDIData.mpPrinterQueueList->m_aPrinterList;
371 : }
372 :
373 0 : const QueueInfo* Printer::GetQueueInfo( const OUString& rPrinterName, bool bStatusUpdate )
374 : {
375 0 : ImplSVData* pSVData = ImplGetSVData();
376 :
377 0 : if ( !pSVData->maGDIData.mpPrinterQueueList )
378 0 : ImplInitPrnQueueList();
379 :
380 0 : ImplPrnQueueData* pInfo = pSVData->maGDIData.mpPrinterQueueList->Get( rPrinterName );
381 0 : if( pInfo )
382 : {
383 0 : if( !pInfo->mpQueueInfo || bStatusUpdate )
384 0 : pSVData->mpDefInst->GetPrinterQueueState( pInfo->mpSalQueueInfo );
385 :
386 0 : if ( !pInfo->mpQueueInfo )
387 0 : pInfo->mpQueueInfo = new QueueInfo;
388 :
389 0 : pInfo->mpQueueInfo->maPrinterName = pInfo->mpSalQueueInfo->maPrinterName;
390 0 : pInfo->mpQueueInfo->maDriver = pInfo->mpSalQueueInfo->maDriver;
391 0 : pInfo->mpQueueInfo->maLocation = pInfo->mpSalQueueInfo->maLocation;
392 0 : pInfo->mpQueueInfo->maComment = pInfo->mpSalQueueInfo->maComment;
393 0 : pInfo->mpQueueInfo->mnStatus = pInfo->mpSalQueueInfo->mnStatus;
394 0 : pInfo->mpQueueInfo->mnJobs = pInfo->mpSalQueueInfo->mnJobs;
395 0 : return pInfo->mpQueueInfo;
396 : }
397 0 : return NULL;
398 : }
399 :
400 :
401 1648 : OUString Printer::GetDefaultPrinterName()
402 : {
403 1648 : static const char* pEnv = getenv( "SAL_DISABLE_DEFAULTPRINTER" );
404 1648 : if( !pEnv || !*pEnv )
405 : {
406 1648 : ImplSVData* pSVData = ImplGetSVData();
407 :
408 1648 : return pSVData->mpDefInst->GetDefaultPrinter();
409 : }
410 0 : return OUString();
411 : }
412 :
413 :
414 220 : void Printer::ImplInitData()
415 : {
416 220 : mbDevOutput = sal_False;
417 220 : meOutDevType = OUTDEV_PRINTER;
418 220 : mbDefPrinter = sal_False;
419 220 : mnError = 0;
420 220 : mnCurPage = 0;
421 220 : mnCurPrintPage = 0;
422 220 : mnPageQueueSize = 0;
423 220 : mnCopyCount = 1;
424 220 : mbCollateCopy = sal_False;
425 220 : mbPrinting = sal_False;
426 220 : mbJobActive = sal_False;
427 220 : mbPrintFile = sal_False;
428 220 : mbInPrintPage = sal_False;
429 220 : mbNewJobSetup = sal_False;
430 220 : mpInfoPrinter = NULL;
431 220 : mpPrinter = NULL;
432 220 : mpDisplayDev = NULL;
433 220 : mbIsQueuePrinter = sal_False;
434 220 : mpPrinterOptions = new PrinterOptions;
435 :
436 : // Add printer to the list
437 220 : ImplSVData* pSVData = ImplGetSVData();
438 220 : mpNext = pSVData->maGDIData.mpFirstPrinter;
439 220 : mpPrev = NULL;
440 220 : if ( mpNext )
441 68 : mpNext->mpPrev = this;
442 : else
443 152 : pSVData->maGDIData.mpLastPrinter = this;
444 220 : pSVData->maGDIData.mpFirstPrinter = this;
445 220 : }
446 :
447 :
448 77 : void Printer::ImplInit( SalPrinterQueueInfo* pInfo )
449 : {
450 77 : ImplSVData* pSVData = ImplGetSVData();
451 : // #i74084# update info for this specific SalPrinterQueueInfo
452 77 : pSVData->mpDefInst->GetPrinterQueueState( pInfo );
453 :
454 : // Test whether the driver actually matches the JobSetup
455 77 : ImplJobSetup* pJobSetup = maJobSetup.ImplGetData();
456 :
457 77 : if ( pJobSetup->mpDriverData )
458 : {
459 0 : if ( (pJobSetup->maPrinterName != pInfo->maPrinterName) ||
460 0 : (pJobSetup->maDriver != pInfo->maDriver) )
461 : {
462 0 : rtl_freeMemory( pJobSetup->mpDriverData );
463 0 : pJobSetup->mpDriverData = NULL;
464 0 : pJobSetup->mnDriverDataLen = 0;
465 : }
466 : }
467 :
468 : // Remember printer name
469 77 : maPrinterName = pInfo->maPrinterName;
470 77 : maDriver = pInfo->maDriver;
471 :
472 : // Add printer name to JobSetup
473 77 : pJobSetup->maPrinterName = maPrinterName;
474 77 : pJobSetup->maDriver = maDriver;
475 :
476 77 : mpInfoPrinter = pSVData->mpDefInst->CreateInfoPrinter( pInfo, pJobSetup );
477 77 : mpPrinter = NULL;
478 77 : mpJobGraphics = NULL;
479 77 : ImplUpdateJobSetupPaper( maJobSetup );
480 :
481 77 : if ( !mpInfoPrinter )
482 : {
483 0 : ImplInitDisplay( NULL );
484 0 : return;
485 : }
486 :
487 : // we need a graphics
488 77 : if ( !ImplGetGraphics() )
489 : {
490 0 : ImplInitDisplay( NULL );
491 0 : return;
492 : }
493 :
494 : // Init data
495 77 : ImplUpdatePageData();
496 77 : mpFontList = new ImplDevFontList();
497 77 : mpFontCache = new ImplFontCache( sal_True );
498 77 : mpGraphics->GetDevFontList( mpFontList );
499 : }
500 :
501 :
502 143 : void Printer::ImplInitDisplay( const Window* pWindow )
503 : {
504 143 : ImplSVData* pSVData = ImplGetSVData();
505 :
506 143 : mpInfoPrinter = NULL;
507 143 : mpPrinter = NULL;
508 143 : mpJobGraphics = NULL;
509 :
510 143 : if ( pWindow )
511 0 : mpDisplayDev = new VirtualDevice( *pWindow );
512 : else
513 143 : mpDisplayDev = new VirtualDevice();
514 143 : mpFontList = pSVData->maGDIData.mpScreenFontList;
515 143 : mpFontCache = pSVData->maGDIData.mpScreenFontCache;
516 143 : mnDPIX = mpDisplayDev->mnDPIX;
517 143 : mnDPIY = mpDisplayDev->mnDPIY;
518 143 : }
519 :
520 :
521 220 : SalPrinterQueueInfo* Printer::ImplGetQueueInfo( const OUString& rPrinterName,
522 : const OUString* pDriver )
523 : {
524 220 : ImplSVData* pSVData = ImplGetSVData();
525 220 : if ( !pSVData->maGDIData.mpPrinterQueueList )
526 31 : ImplInitPrnQueueList();
527 :
528 220 : ImplPrnQueueList* pPrnList = pSVData->maGDIData.mpPrinterQueueList;
529 220 : if ( pPrnList && pPrnList->m_aQueueInfos.size() )
530 : {
531 : // first search for the printer name driectly
532 77 : ImplPrnQueueData* pInfo = pPrnList->Get( rPrinterName );
533 77 : if( pInfo )
534 66 : return pInfo->mpSalQueueInfo;
535 :
536 : // then search case insensitive
537 22 : for( unsigned int i = 0; i < pPrnList->m_aQueueInfos.size(); i++ )
538 : {
539 11 : if( pPrnList->m_aQueueInfos[i].mpSalQueueInfo->maPrinterName.equalsIgnoreAsciiCase( rPrinterName ) )
540 0 : return pPrnList->m_aQueueInfos[i].mpSalQueueInfo;
541 : }
542 :
543 : // then search for driver name
544 11 : if ( pDriver )
545 : {
546 0 : for( unsigned int i = 0; i < pPrnList->m_aQueueInfos.size(); i++ )
547 : {
548 0 : if( pPrnList->m_aQueueInfos[i].mpSalQueueInfo->maDriver == *pDriver )
549 0 : return pPrnList->m_aQueueInfos[i].mpSalQueueInfo;
550 : }
551 : }
552 :
553 : // then the default printer
554 11 : pInfo = pPrnList->Get( GetDefaultPrinterName() );
555 11 : if( pInfo )
556 11 : return pInfo->mpSalQueueInfo;
557 :
558 : // last chance: the first available printer
559 0 : return pPrnList->m_aQueueInfos[0].mpSalQueueInfo;
560 : }
561 :
562 143 : return NULL;
563 : }
564 :
565 :
566 80 : void Printer::ImplUpdatePageData()
567 : {
568 : // we need a graphics
569 80 : if ( !ImplGetGraphics() )
570 80 : return;
571 :
572 80 : mpGraphics->GetResolution( mnDPIX, mnDPIY );
573 80 : mpInfoPrinter->GetPageInfo( maJobSetup.ImplGetConstData(),
574 : mnOutWidth, mnOutHeight,
575 80 : maPageOffset.X(), maPageOffset.Y(),
576 240 : maPaperSize.Width(), maPaperSize.Height() );
577 : }
578 :
579 :
580 3 : void Printer::ImplUpdateFontList()
581 : {
582 3 : ImplUpdateFontData( sal_True );
583 3 : }
584 :
585 :
586 166 : Printer::Printer()
587 : {
588 166 : ImplInitData();
589 166 : SalPrinterQueueInfo* pInfo = ImplGetQueueInfo( GetDefaultPrinterName(), NULL );
590 166 : if ( pInfo )
591 : {
592 63 : ImplInit( pInfo );
593 63 : if ( !IsDisplayPrinter() )
594 63 : mbDefPrinter = sal_True;
595 : }
596 : else
597 103 : ImplInitDisplay( NULL );
598 166 : }
599 :
600 :
601 0 : Printer::Printer( const JobSetup& rJobSetup ) :
602 0 : maJobSetup( rJobSetup )
603 : {
604 0 : ImplInitData();
605 : SalPrinterQueueInfo* pInfo = ImplGetQueueInfo( rJobSetup.mpData->maPrinterName,
606 0 : &rJobSetup.mpData->maDriver );
607 0 : if ( pInfo )
608 : {
609 0 : ImplInit( pInfo );
610 0 : SetJobSetup( rJobSetup );
611 : }
612 : else
613 : {
614 0 : ImplInitDisplay( NULL );
615 0 : maJobSetup = JobSetup();
616 : }
617 0 : }
618 :
619 :
620 0 : Printer::Printer( const QueueInfo& rQueueInfo )
621 : {
622 0 : ImplInitData();
623 0 : SalPrinterQueueInfo* pInfo = ImplGetQueueInfo( rQueueInfo.GetPrinterName(),
624 0 : &rQueueInfo.GetDriver() );
625 0 : if ( pInfo )
626 0 : ImplInit( pInfo );
627 : else
628 0 : ImplInitDisplay( NULL );
629 0 : }
630 :
631 :
632 54 : Printer::Printer( const OUString& rPrinterName )
633 : {
634 54 : ImplInitData();
635 54 : SalPrinterQueueInfo* pInfo = ImplGetQueueInfo( rPrinterName, NULL );
636 54 : if ( pInfo )
637 14 : ImplInit( pInfo );
638 : else
639 40 : ImplInitDisplay( NULL );
640 54 : }
641 :
642 :
643 416 : Printer::~Printer()
644 : {
645 : DBG_ASSERT( !IsPrinting(), "Printer::~Printer() - Job is printing" );
646 : DBG_ASSERT( !IsJobActive(), "Printer::~Printer() - Job is active" );
647 :
648 208 : delete mpPrinterOptions;
649 :
650 208 : ImplReleaseGraphics();
651 208 : if ( mpInfoPrinter )
652 76 : ImplGetSVData()->mpDefInst->DestroyInfoPrinter( mpInfoPrinter );
653 208 : if ( mpDisplayDev )
654 132 : delete mpDisplayDev;
655 : else
656 : {
657 : // OutputDevice Dtor is tryig the same thing; that why we need to set
658 : // the FontEntry to NULL here
659 : // TODO: consolidate duplicate cleanup by Printer and OutputDevice
660 76 : if ( mpFontEntry )
661 : {
662 0 : mpFontCache->Release( mpFontEntry );
663 0 : mpFontEntry = NULL;
664 : }
665 76 : if ( mpGetDevFontList )
666 : {
667 0 : delete mpGetDevFontList;
668 0 : mpGetDevFontList = NULL;
669 : }
670 76 : if ( mpGetDevSizeList )
671 : {
672 0 : delete mpGetDevSizeList;
673 0 : mpGetDevSizeList = NULL;
674 : }
675 76 : delete mpFontCache;
676 76 : mpFontCache = NULL;
677 : // font list deleted by OutputDevice dtor
678 : }
679 :
680 : // Add printer from the list
681 208 : ImplSVData* pSVData = ImplGetSVData();
682 208 : if ( mpPrev )
683 5 : mpPrev->mpNext = mpNext;
684 : else
685 203 : pSVData->maGDIData.mpFirstPrinter = mpNext;
686 208 : if ( mpNext )
687 59 : mpNext->mpPrev = mpPrev;
688 : else
689 149 : pSVData->maGDIData.mpLastPrinter = mpPrev;
690 208 : }
691 :
692 0 : sal_uLong Printer::GetCapabilities( sal_uInt16 nType ) const
693 : {
694 0 : if ( IsDisplayPrinter() )
695 0 : return sal_False;
696 :
697 0 : if( mpInfoPrinter )
698 0 : return mpInfoPrinter->GetCapabilities( maJobSetup.ImplGetConstData(), nType );
699 : else
700 0 : return sal_False;
701 : }
702 :
703 :
704 0 : sal_Bool Printer::HasSupport( PrinterSupport eFeature ) const
705 : {
706 0 : switch ( eFeature )
707 : {
708 : case SUPPORT_SET_ORIENTATION:
709 0 : return (sal_Bool)GetCapabilities( PRINTER_CAPABILITIES_SETORIENTATION );
710 : case SUPPORT_SET_PAPERBIN:
711 0 : return (sal_Bool)GetCapabilities( PRINTER_CAPABILITIES_SETPAPERBIN );
712 : case SUPPORT_SET_PAPERSIZE:
713 0 : return (sal_Bool)GetCapabilities( PRINTER_CAPABILITIES_SETPAPERSIZE );
714 : case SUPPORT_SET_PAPER:
715 0 : return (sal_Bool)GetCapabilities( PRINTER_CAPABILITIES_SETPAPER );
716 : case SUPPORT_COPY:
717 0 : return (GetCapabilities( PRINTER_CAPABILITIES_COPIES ) != 0);
718 : case SUPPORT_COLLATECOPY:
719 0 : return (GetCapabilities( PRINTER_CAPABILITIES_COLLATECOPIES ) != 0);
720 : case SUPPORT_SETUPDIALOG:
721 0 : return (sal_Bool)GetCapabilities( PRINTER_CAPABILITIES_SUPPORTDIALOG );
722 : case SUPPORT_FAX:
723 0 : return (sal_Bool) GetCapabilities( PRINTER_CAPABILITIES_FAX );
724 : case SUPPORT_PDF:
725 0 : return (sal_Bool) GetCapabilities( PRINTER_CAPABILITIES_PDF );
726 : }
727 :
728 0 : return sal_True;
729 : }
730 :
731 :
732 7 : sal_Bool Printer::SetJobSetup( const JobSetup& rSetup )
733 : {
734 7 : if ( IsDisplayPrinter() || mbInPrintPage )
735 4 : return sal_False;
736 :
737 3 : JobSetup aJobSetup = rSetup;
738 :
739 3 : ImplReleaseGraphics();
740 3 : if ( mpInfoPrinter->SetPrinterData( aJobSetup.ImplGetData() ) )
741 : {
742 3 : ImplUpdateJobSetupPaper( aJobSetup );
743 3 : mbNewJobSetup = sal_True;
744 3 : maJobSetup = aJobSetup;
745 3 : ImplUpdatePageData();
746 3 : ImplUpdateFontList();
747 3 : return sal_True;
748 : }
749 :
750 0 : return sal_False;
751 : }
752 :
753 :
754 :
755 0 : sal_Bool Printer::Setup( Window* pWindow )
756 : {
757 0 : if ( IsDisplayPrinter() )
758 0 : return sal_False;
759 :
760 0 : if ( IsJobActive() || IsPrinting() )
761 0 : return sal_False;
762 :
763 0 : JobSetup aJobSetup = maJobSetup;
764 : SalFrame* pFrame;
765 0 : if ( !pWindow )
766 0 : pWindow = ImplGetDefaultWindow();
767 0 : if( !pWindow )
768 0 : return sal_False;
769 :
770 0 : pFrame = pWindow->ImplGetFrame();
771 0 : ImplReleaseGraphics();
772 0 : ImplSVData* pSVData = ImplGetSVData();
773 0 : pSVData->maAppData.mnModalMode++;
774 0 : nImplSysDialog++;
775 0 : sal_Bool bSetup = mpInfoPrinter->Setup( pFrame, aJobSetup.ImplGetData() );
776 0 : pSVData->maAppData.mnModalMode--;
777 0 : nImplSysDialog--;
778 0 : if ( bSetup )
779 : {
780 0 : ImplUpdateJobSetupPaper( aJobSetup );
781 0 : mbNewJobSetup = sal_True;
782 0 : maJobSetup = aJobSetup;
783 0 : ImplUpdatePageData();
784 0 : ImplUpdateFontList();
785 0 : return sal_True;
786 : }
787 0 : return sal_False;
788 : }
789 :
790 :
791 0 : sal_Bool Printer::SetPrinterProps( const Printer* pPrinter )
792 : {
793 0 : if ( IsJobActive() || IsPrinting() )
794 0 : return sal_False;
795 :
796 0 : ImplSVData* pSVData = ImplGetSVData();
797 :
798 0 : mbDefPrinter = pPrinter->mbDefPrinter;
799 0 : maPrintFile = pPrinter->maPrintFile;
800 0 : mbPrintFile = pPrinter->mbPrintFile;
801 0 : mnCopyCount = pPrinter->mnCopyCount;
802 0 : mbCollateCopy = pPrinter->mbCollateCopy;
803 0 : mnPageQueueSize = pPrinter->mnPageQueueSize;
804 0 : *mpPrinterOptions = *pPrinter->mpPrinterOptions;
805 :
806 0 : if ( pPrinter->IsDisplayPrinter() )
807 : {
808 : // Destroy old printer
809 0 : if ( !IsDisplayPrinter() )
810 : {
811 0 : ImplReleaseGraphics();
812 0 : pSVData->mpDefInst->DestroyInfoPrinter( mpInfoPrinter );
813 0 : if ( mpFontEntry )
814 : {
815 0 : mpFontCache->Release( mpFontEntry );
816 0 : mpFontEntry = NULL;
817 : }
818 0 : if ( mpGetDevFontList )
819 : {
820 0 : delete mpGetDevFontList;
821 0 : mpGetDevFontList = NULL;
822 : }
823 0 : if ( mpGetDevSizeList )
824 : {
825 0 : delete mpGetDevSizeList;
826 0 : mpGetDevSizeList = NULL;
827 : }
828 : // clean up font list
829 0 : delete mpFontCache;
830 0 : delete mpFontList;
831 0 : mpFontCache = NULL;
832 0 : mpFontList = NULL;
833 :
834 0 : mbInitFont = sal_True;
835 0 : mbNewFont = sal_True;
836 0 : mpInfoPrinter = NULL;
837 : }
838 :
839 : // Construct new printer
840 0 : ImplInitDisplay( NULL );
841 0 : return sal_True;
842 : }
843 :
844 : // Destroy old printer?
845 0 : if ( GetName() != pPrinter->GetName() )
846 : {
847 0 : ImplReleaseGraphics();
848 0 : if ( mpDisplayDev )
849 : {
850 0 : delete mpDisplayDev;
851 0 : mpDisplayDev = NULL;
852 : }
853 : else
854 : {
855 0 : pSVData->mpDefInst->DestroyInfoPrinter( mpInfoPrinter );
856 :
857 0 : if ( mpFontEntry )
858 : {
859 0 : mpFontCache->Release( mpFontEntry );
860 0 : mpFontEntry = NULL;
861 : }
862 0 : if ( mpGetDevFontList )
863 : {
864 0 : delete mpGetDevFontList;
865 0 : mpGetDevFontList = NULL;
866 : }
867 0 : if ( mpGetDevSizeList )
868 : {
869 0 : delete mpGetDevSizeList;
870 0 : mpGetDevSizeList = NULL;
871 : }
872 0 : delete mpFontCache;
873 0 : delete mpFontList;
874 0 : mpFontCache = NULL;
875 0 : mpFontList = NULL;
876 0 : mbInitFont = sal_True;
877 0 : mbNewFont = sal_True;
878 0 : mpInfoPrinter = NULL;
879 : }
880 :
881 : // Construct new printer
882 0 : OUString aDriver = pPrinter->GetDriverName();
883 0 : SalPrinterQueueInfo* pInfo = ImplGetQueueInfo( pPrinter->GetName(), &aDriver );
884 0 : if ( pInfo )
885 : {
886 0 : ImplInit( pInfo );
887 0 : SetJobSetup( pPrinter->GetJobSetup() );
888 : }
889 : else
890 0 : ImplInitDisplay( NULL );
891 : }
892 : else
893 0 : SetJobSetup( pPrinter->GetJobSetup() );
894 :
895 0 : return sal_False;
896 : }
897 :
898 :
899 0 : sal_Bool Printer::SetOrientation( Orientation eOrientation )
900 : {
901 0 : if ( mbInPrintPage )
902 0 : return sal_False;
903 :
904 0 : if ( maJobSetup.ImplGetConstData()->meOrientation != eOrientation )
905 : {
906 0 : JobSetup aJobSetup = maJobSetup;
907 0 : ImplJobSetup* pSetupData = aJobSetup.ImplGetData();
908 0 : pSetupData->meOrientation = eOrientation;
909 :
910 0 : if ( IsDisplayPrinter() )
911 : {
912 0 : mbNewJobSetup = sal_True;
913 0 : maJobSetup = aJobSetup;
914 0 : return sal_True;
915 : }
916 :
917 0 : ImplReleaseGraphics();
918 0 : if ( mpInfoPrinter->SetData( SAL_JOBSET_ORIENTATION, pSetupData ) )
919 : {
920 0 : ImplUpdateJobSetupPaper( aJobSetup );
921 0 : mbNewJobSetup = sal_True;
922 0 : maJobSetup = aJobSetup;
923 0 : ImplUpdatePageData();
924 0 : ImplUpdateFontList();
925 0 : return sal_True;
926 : }
927 : else
928 0 : return sal_False;
929 : }
930 :
931 0 : return sal_True;
932 : }
933 :
934 :
935 49 : Orientation Printer::GetOrientation() const
936 : {
937 49 : return maJobSetup.ImplGetConstData()->meOrientation;
938 : }
939 :
940 :
941 0 : sal_Bool Printer::SetPaperBin( sal_uInt16 nPaperBin )
942 : {
943 0 : if ( mbInPrintPage )
944 0 : return sal_False;
945 :
946 0 : if ( (maJobSetup.ImplGetConstData()->mnPaperBin != nPaperBin) &&
947 0 : (nPaperBin < GetPaperBinCount()) )
948 : {
949 0 : JobSetup aJobSetup = maJobSetup;
950 0 : ImplJobSetup* pSetupData = aJobSetup.ImplGetData();
951 0 : pSetupData->mnPaperBin = nPaperBin;
952 :
953 0 : if ( IsDisplayPrinter() )
954 : {
955 0 : mbNewJobSetup = sal_True;
956 0 : maJobSetup = aJobSetup;
957 0 : return sal_True;
958 : }
959 :
960 0 : ImplReleaseGraphics();
961 0 : if ( mpInfoPrinter->SetData( SAL_JOBSET_PAPERBIN, pSetupData ) )
962 : {
963 0 : ImplUpdateJobSetupPaper( aJobSetup );
964 0 : mbNewJobSetup = sal_True;
965 0 : maJobSetup = aJobSetup;
966 0 : ImplUpdatePageData();
967 0 : ImplUpdateFontList();
968 0 : return sal_True;
969 : }
970 : else
971 0 : return sal_False;
972 : }
973 :
974 0 : return sal_True;
975 : }
976 :
977 :
978 0 : sal_uInt16 Printer::GetPaperBin() const
979 : {
980 0 : return maJobSetup.ImplGetConstData()->mnPaperBin;
981 : }
982 :
983 :
984 : // Map user paper format to a available printer paper formats
985 0 : void Printer::ImplFindPaperFormatForUserSize( JobSetup& aJobSetup, bool bMatchNearest )
986 : {
987 0 : ImplJobSetup* pSetupData = aJobSetup.ImplGetData();
988 :
989 0 : int nLandscapeAngle = GetLandscapeAngle();
990 0 : int nPaperCount = GetPaperInfoCount();
991 0 : bool bFound = false;
992 :
993 0 : PaperInfo aInfo(pSetupData->mnPaperWidth, pSetupData->mnPaperHeight);
994 :
995 : // Compare all paper formats and get the appropriate one
996 0 : for ( int i = 0; i < nPaperCount; i++ )
997 : {
998 0 : const PaperInfo& rPaperInfo = GetPaperInfo( i );
999 :
1000 0 : if ( aInfo.sloppyEqual(rPaperInfo) )
1001 : {
1002 : pSetupData->mePaperFormat = ImplGetPaperFormat( rPaperInfo.getWidth(),
1003 0 : rPaperInfo.getHeight() );
1004 0 : pSetupData->meOrientation = ORIENTATION_PORTRAIT;
1005 0 : bFound = true;
1006 0 : break;
1007 : }
1008 : }
1009 :
1010 : // If the printer supports landscape orientation, check paper sizes again
1011 : // with landscape orientation. This is necessary as a printer driver provides
1012 : // all paper sizes with portrait orientation only!!
1013 0 : if ( pSetupData->mePaperFormat == PAPER_USER &&
1014 0 : nLandscapeAngle != 0 &&
1015 0 : HasSupport( SUPPORT_SET_ORIENTATION ))
1016 : {
1017 :
1018 0 : PaperInfo aRotatedInfo(pSetupData->mnPaperHeight, pSetupData->mnPaperWidth);
1019 :
1020 0 : for ( int i = 0; i < nPaperCount; i++ )
1021 : {
1022 0 : const PaperInfo& rPaperInfo = GetPaperInfo( i );
1023 :
1024 0 : if ( aRotatedInfo.sloppyEqual( rPaperInfo ) )
1025 : {
1026 : pSetupData->mePaperFormat = ImplGetPaperFormat( rPaperInfo.getWidth(),
1027 0 : rPaperInfo.getHeight() );
1028 0 : pSetupData->meOrientation = ORIENTATION_LANDSCAPE;
1029 0 : bFound = true;
1030 0 : break;
1031 : }
1032 : }
1033 : }
1034 :
1035 0 : if( ! bFound && bMatchNearest )
1036 : {
1037 0 : sal_Int64 nBestMatch = SAL_MAX_INT64;
1038 0 : int nBestIndex = 0;
1039 0 : Orientation eBestOrientation = ORIENTATION_PORTRAIT;
1040 0 : for( int i = 0; i < nPaperCount; i++ )
1041 : {
1042 0 : const PaperInfo& rPaperInfo = GetPaperInfo( i );
1043 :
1044 : // check portrait match
1045 0 : sal_Int64 nDX = pSetupData->mnPaperWidth - rPaperInfo.getWidth();
1046 0 : sal_Int64 nDY = pSetupData->mnPaperHeight - rPaperInfo.getHeight();
1047 0 : sal_Int64 nMatch = nDX*nDX + nDY*nDY;
1048 0 : if( nMatch < nBestMatch )
1049 : {
1050 0 : nBestMatch = nMatch;
1051 0 : nBestIndex = i;
1052 0 : eBestOrientation = ORIENTATION_PORTRAIT;
1053 : }
1054 :
1055 : // check landscape match
1056 0 : nDX = pSetupData->mnPaperWidth - rPaperInfo.getHeight();
1057 0 : nDY = pSetupData->mnPaperHeight - rPaperInfo.getWidth();
1058 0 : nMatch = nDX*nDX + nDY*nDY;
1059 0 : if( nMatch < nBestMatch )
1060 : {
1061 0 : nBestMatch = nMatch;
1062 0 : nBestIndex = i;
1063 0 : eBestOrientation = ORIENTATION_LANDSCAPE;
1064 : }
1065 : }
1066 0 : const PaperInfo& rBestInfo = GetPaperInfo( nBestIndex );
1067 : pSetupData->mePaperFormat = ImplGetPaperFormat( rBestInfo.getWidth(),
1068 0 : rBestInfo.getHeight() );
1069 0 : pSetupData->meOrientation = eBestOrientation;
1070 : }
1071 0 : }
1072 :
1073 :
1074 0 : sal_Bool Printer::SetPaper( Paper ePaper )
1075 : {
1076 0 : if ( mbInPrintPage )
1077 0 : return sal_False;
1078 :
1079 0 : if ( maJobSetup.ImplGetConstData()->mePaperFormat != ePaper )
1080 : {
1081 0 : JobSetup aJobSetup = maJobSetup;
1082 0 : ImplJobSetup* pSetupData = aJobSetup.ImplGetData();
1083 0 : pSetupData->mePaperFormat = ePaper;
1084 0 : if ( ePaper != PAPER_USER )
1085 : {
1086 0 : PaperInfo aInfo(ePaper);
1087 0 : pSetupData->mnPaperWidth = aInfo.getWidth();
1088 0 : pSetupData->mnPaperHeight = aInfo.getHeight();
1089 : }
1090 :
1091 0 : if ( IsDisplayPrinter() )
1092 : {
1093 0 : mbNewJobSetup = sal_True;
1094 0 : maJobSetup = aJobSetup;
1095 0 : return sal_True;
1096 : }
1097 :
1098 0 : ImplReleaseGraphics();
1099 0 : if ( ePaper == PAPER_USER )
1100 0 : ImplFindPaperFormatForUserSize( aJobSetup, false );
1101 0 : if ( mpInfoPrinter->SetData( SAL_JOBSET_PAPERSIZE|SAL_JOBSET_ORIENTATION, pSetupData ) )
1102 : {
1103 0 : ImplUpdateJobSetupPaper( aJobSetup );
1104 0 : mbNewJobSetup = sal_True;
1105 0 : maJobSetup = aJobSetup;
1106 0 : ImplUpdatePageData();
1107 0 : ImplUpdateFontList();
1108 0 : return sal_True;
1109 : }
1110 : else
1111 0 : return sal_False;
1112 : }
1113 :
1114 0 : return sal_True;
1115 : }
1116 :
1117 :
1118 0 : sal_Bool Printer::SetPaperSizeUser( const Size& rSize )
1119 : {
1120 0 : return SetPaperSizeUser( rSize, false );
1121 : }
1122 :
1123 0 : sal_Bool Printer::SetPaperSizeUser( const Size& rSize, bool bMatchNearest )
1124 : {
1125 0 : if ( mbInPrintPage )
1126 0 : return sal_False;
1127 :
1128 0 : Size aPixSize = LogicToPixel( rSize );
1129 0 : Size aPageSize = PixelToLogic( aPixSize, MAP_100TH_MM );
1130 0 : if ( (maJobSetup.ImplGetConstData()->mePaperFormat != PAPER_USER) ||
1131 0 : (maJobSetup.ImplGetConstData()->mnPaperWidth != aPageSize.Width()) ||
1132 0 : (maJobSetup.ImplGetConstData()->mnPaperHeight != aPageSize.Height()) )
1133 : {
1134 0 : JobSetup aJobSetup = maJobSetup;
1135 0 : ImplJobSetup* pSetupData = aJobSetup.ImplGetData();
1136 0 : pSetupData->mePaperFormat = PAPER_USER;
1137 0 : pSetupData->mnPaperWidth = aPageSize.Width();
1138 0 : pSetupData->mnPaperHeight = aPageSize.Height();
1139 :
1140 0 : if ( IsDisplayPrinter() )
1141 : {
1142 0 : mbNewJobSetup = sal_True;
1143 0 : maJobSetup = aJobSetup;
1144 0 : return sal_True;
1145 : }
1146 :
1147 0 : ImplReleaseGraphics();
1148 0 : ImplFindPaperFormatForUserSize( aJobSetup, bMatchNearest );
1149 :
1150 : // Changing the paper size can also change the orientation!
1151 0 : if ( mpInfoPrinter->SetData( SAL_JOBSET_PAPERSIZE|SAL_JOBSET_ORIENTATION, pSetupData ) )
1152 : {
1153 0 : ImplUpdateJobSetupPaper( aJobSetup );
1154 0 : mbNewJobSetup = sal_True;
1155 0 : maJobSetup = aJobSetup;
1156 0 : ImplUpdatePageData();
1157 0 : ImplUpdateFontList();
1158 0 : return sal_True;
1159 : }
1160 : else
1161 0 : return sal_False;
1162 : }
1163 :
1164 0 : return sal_True;
1165 : }
1166 :
1167 :
1168 0 : int Printer::GetPaperInfoCount() const
1169 : {
1170 0 : if( ! mpInfoPrinter )
1171 0 : return 0;
1172 0 : if( ! mpInfoPrinter->m_bPapersInit )
1173 0 : mpInfoPrinter->InitPaperFormats( maJobSetup.ImplGetConstData() );
1174 0 : return mpInfoPrinter->m_aPaperFormats.size();
1175 : }
1176 :
1177 :
1178 0 : OUString Printer::GetPaperName( Paper ePaper )
1179 : {
1180 0 : ImplSVData* pSVData = ImplGetSVData();
1181 0 : if( ! pSVData->mpPaperNames )
1182 : {
1183 0 : pSVData->mpPaperNames = new boost::unordered_map< int, OUString >();
1184 0 : if( ImplGetResMgr() )
1185 : {
1186 0 : ResStringArray aPaperStrings( VclResId( RID_STR_PAPERNAMES ) );
1187 : static const int PaperIndex[] =
1188 : {
1189 : PAPER_A0, PAPER_A1, PAPER_A2, PAPER_A3, PAPER_A4, PAPER_A5,
1190 : PAPER_B4_ISO, PAPER_B5_ISO, PAPER_LETTER, PAPER_LEGAL, PAPER_TABLOID,
1191 : PAPER_USER, PAPER_B6_ISO, PAPER_ENV_C4, PAPER_ENV_C5, PAPER_ENV_C6, PAPER_ENV_C65,
1192 : PAPER_ENV_DL, PAPER_SLIDE_DIA, PAPER_C, PAPER_D, PAPER_E,
1193 : PAPER_EXECUTIVE, PAPER_FANFOLD_LEGAL_DE, PAPER_ENV_MONARCH, PAPER_ENV_PERSONAL,
1194 : PAPER_ENV_9, PAPER_ENV_10, PAPER_ENV_11, PAPER_ENV_12, PAPER_KAI16,
1195 : PAPER_KAI32, PAPER_KAI32BIG, PAPER_B4_JIS, PAPER_B5_JIS, PAPER_B6_JIS,
1196 : PAPER_POSTCARD_JP
1197 : };
1198 : OSL_ENSURE( sal_uInt32(SAL_N_ELEMENTS(PaperIndex)) == aPaperStrings.Count(), "localized paper name count wrong" );
1199 0 : for( int i = 0; i < int(SAL_N_ELEMENTS(PaperIndex)); i++ )
1200 0 : (*pSVData->mpPaperNames)[PaperIndex[i]] = aPaperStrings.GetString(i);
1201 : }
1202 : }
1203 :
1204 0 : boost::unordered_map<int,OUString>::const_iterator it = pSVData->mpPaperNames->find( (int)ePaper );
1205 0 : return (it != pSVData->mpPaperNames->end()) ? it->second : OUString();
1206 : }
1207 :
1208 :
1209 0 : OUString Printer::GetPaperName( bool i_bPaperUser ) const
1210 : {
1211 0 : Size aPageSize = PixelToLogic( GetPaperSizePixel(), MAP_100TH_MM );
1212 0 : Paper ePaper = ImplGetPaperFormat( aPageSize.Width(), aPageSize.Height() );
1213 0 : if( ePaper == PAPER_USER )
1214 0 : ePaper = ImplGetPaperFormat( aPageSize.Height(), aPageSize.Width() );
1215 0 : return (ePaper != PAPER_USER || i_bPaperUser ) ? GetPaperName( ePaper ) : OUString();
1216 : }
1217 :
1218 :
1219 0 : const PaperInfo& Printer::GetPaperInfo( int nPaper ) const
1220 : {
1221 0 : if( ! mpInfoPrinter )
1222 0 : return ImplGetEmptyPaper();
1223 0 : if( ! mpInfoPrinter->m_bPapersInit )
1224 0 : mpInfoPrinter->InitPaperFormats( maJobSetup.ImplGetConstData() );
1225 0 : if( mpInfoPrinter->m_aPaperFormats.empty() || nPaper < 0 || nPaper >= int(mpInfoPrinter->m_aPaperFormats.size()) )
1226 0 : return ImplGetEmptyPaper();
1227 0 : return mpInfoPrinter->m_aPaperFormats[nPaper];
1228 : }
1229 :
1230 :
1231 0 : sal_Bool Printer::SetDuplexMode( DuplexMode eDuplex )
1232 : {
1233 0 : if ( mbInPrintPage )
1234 0 : return sal_False;
1235 :
1236 0 : if ( maJobSetup.ImplGetConstData()->meDuplexMode != eDuplex )
1237 : {
1238 0 : JobSetup aJobSetup = maJobSetup;
1239 0 : ImplJobSetup* pSetupData = aJobSetup.ImplGetData();
1240 0 : pSetupData->meDuplexMode = eDuplex;
1241 :
1242 0 : if ( IsDisplayPrinter() )
1243 : {
1244 0 : mbNewJobSetup = sal_True;
1245 0 : maJobSetup = aJobSetup;
1246 0 : return sal_True;
1247 : }
1248 :
1249 0 : ImplReleaseGraphics();
1250 0 : if ( mpInfoPrinter->SetData( SAL_JOBSET_DUPLEXMODE, pSetupData ) )
1251 : {
1252 0 : ImplUpdateJobSetupPaper( aJobSetup );
1253 0 : mbNewJobSetup = sal_True;
1254 0 : maJobSetup = aJobSetup;
1255 0 : ImplUpdatePageData();
1256 0 : ImplUpdateFontList();
1257 0 : return sal_True;
1258 : }
1259 : else
1260 0 : return sal_False;
1261 : }
1262 :
1263 0 : return sal_True;
1264 : }
1265 :
1266 :
1267 0 : int Printer::GetLandscapeAngle() const
1268 : {
1269 0 : return mpInfoPrinter ? mpInfoPrinter->GetLandscapeAngle( maJobSetup.ImplGetConstData() ) : 900;
1270 : }
1271 :
1272 :
1273 11 : Paper Printer::GetPaper() const
1274 : {
1275 11 : return maJobSetup.ImplGetConstData()->mePaperFormat;
1276 : }
1277 :
1278 :
1279 0 : sal_uInt16 Printer::GetPaperBinCount() const
1280 : {
1281 0 : if ( IsDisplayPrinter() )
1282 0 : return 0;
1283 :
1284 0 : return (sal_uInt16)mpInfoPrinter->GetPaperBinCount( maJobSetup.ImplGetConstData() );
1285 : }
1286 :
1287 :
1288 0 : OUString Printer::GetPaperBinName( sal_uInt16 nPaperBin ) const
1289 : {
1290 0 : if ( IsDisplayPrinter() )
1291 0 : return ImplGetSVEmptyStr();
1292 :
1293 0 : if ( nPaperBin < GetPaperBinCount() )
1294 0 : return mpInfoPrinter->GetPaperBinName( maJobSetup.ImplGetConstData(), nPaperBin );
1295 : else
1296 0 : return ImplGetSVEmptyStr();
1297 : }
1298 :
1299 :
1300 0 : sal_Bool Printer::SetCopyCount( sal_uInt16 nCopy, sal_Bool bCollate )
1301 : {
1302 0 : mnCopyCount = nCopy;
1303 0 : mbCollateCopy = bCollate;
1304 0 : return sal_True;
1305 : }
1306 :
1307 :
1308 0 : void Printer::Error()
1309 : {
1310 0 : maErrorHdl.Call( this );
1311 0 : }
1312 :
1313 :
1314 :
1315 0 : sal_uLong Printer::ImplSalPrinterErrorCodeToVCL( sal_uLong nError )
1316 : {
1317 : sal_uLong nVCLError;
1318 0 : switch ( nError )
1319 : {
1320 : case 0:
1321 0 : nVCLError = PRINTER_OK;
1322 0 : break;
1323 : case SAL_PRINTER_ERROR_ABORT:
1324 0 : nVCLError = PRINTER_ABORT;
1325 0 : break;
1326 : default:
1327 0 : nVCLError = PRINTER_GENERALERROR;
1328 0 : break;
1329 : }
1330 :
1331 0 : return nVCLError;
1332 : }
1333 :
1334 :
1335 0 : sal_Bool Printer::EndJob()
1336 : {
1337 0 : sal_Bool bRet = sal_False;
1338 0 : if ( !IsJobActive() )
1339 0 : return bRet;
1340 :
1341 : DBG_ASSERT( !mbInPrintPage, "Printer::EndJob() - StartPage() without EndPage() called" );
1342 :
1343 0 : mbJobActive = sal_False;
1344 :
1345 0 : if ( mpPrinter )
1346 : {
1347 0 : ImplReleaseGraphics();
1348 :
1349 0 : mnCurPage = 0;
1350 :
1351 0 : mbPrinting = sal_False;
1352 0 : mnCurPrintPage = 0;
1353 0 : maJobName = OUString();
1354 :
1355 0 : mbDevOutput = sal_False;
1356 0 : bRet = mpPrinter->EndJob();
1357 : // FIXME: Do not destroy the printer asynchronously as Win95
1358 : // can't handle destroying a printer object and printing
1359 : // at the same time
1360 0 : ImplGetSVData()->mpDefInst->DestroyPrinter( mpPrinter );
1361 0 : mpPrinter = NULL;
1362 : }
1363 :
1364 0 : return bRet;
1365 : }
1366 :
1367 :
1368 0 : void Printer::ImplStartPage()
1369 : {
1370 0 : if ( !IsJobActive() )
1371 0 : return;
1372 :
1373 0 : if ( mpPrinter )
1374 : {
1375 0 : SalGraphics* pGraphics = mpPrinter->StartPage( maJobSetup.ImplGetConstData(), mbNewJobSetup );
1376 0 : if ( pGraphics )
1377 : {
1378 0 : ImplReleaseGraphics();
1379 0 : mpJobGraphics = pGraphics;
1380 : }
1381 0 : mbDevOutput = sal_True;
1382 :
1383 : // PrintJob not aborted ???
1384 0 : if ( IsJobActive() )
1385 : {
1386 0 : mbInPrintPage = sal_True;
1387 0 : mnCurPage++;
1388 0 : mnCurPrintPage++;
1389 : }
1390 : }
1391 : }
1392 :
1393 :
1394 0 : void Printer::ImplEndPage()
1395 : {
1396 0 : if ( !IsJobActive() )
1397 0 : return;
1398 :
1399 0 : mbInPrintPage = sal_False;
1400 :
1401 0 : if ( mpPrinter )
1402 : {
1403 0 : mpPrinter->EndPage();
1404 0 : ImplReleaseGraphics();
1405 0 : mbDevOutput = sal_False;
1406 :
1407 0 : mpJobGraphics = NULL;
1408 0 : mbNewJobSetup = sal_False;
1409 : }
1410 : }
1411 :
1412 :
1413 0 : void Printer::updatePrinters()
1414 : {
1415 0 : ImplSVData* pSVData = ImplGetSVData();
1416 0 : ImplPrnQueueList* pPrnList = pSVData->maGDIData.mpPrinterQueueList;
1417 :
1418 0 : if ( pPrnList )
1419 : {
1420 0 : ImplPrnQueueList* pNewList = new ImplPrnQueueList;
1421 0 : pSVData->mpDefInst->GetPrinterQueueInfo( pNewList );
1422 :
1423 0 : bool bChanged = pPrnList->m_aQueueInfos.size() != pNewList->m_aQueueInfos.size();
1424 0 : for( unsigned int i = 0; ! bChanged && i < pPrnList->m_aQueueInfos.size(); i++ )
1425 : {
1426 0 : ImplPrnQueueData& rInfo = pPrnList->m_aQueueInfos[i];
1427 0 : ImplPrnQueueData& rNewInfo = pNewList->m_aQueueInfos[i];
1428 0 : if( ! rInfo.mpSalQueueInfo || ! rNewInfo.mpSalQueueInfo || // sanity check
1429 0 : rInfo.mpSalQueueInfo->maPrinterName != rNewInfo.mpSalQueueInfo->maPrinterName )
1430 : {
1431 0 : bChanged = true;
1432 : }
1433 : }
1434 0 : if( bChanged )
1435 : {
1436 0 : ImplDeletePrnQueueList();
1437 0 : pSVData->maGDIData.mpPrinterQueueList = pNewList;
1438 :
1439 0 : Application* pApp = GetpApp();
1440 0 : if( pApp )
1441 : {
1442 0 : DataChangedEvent aDCEvt( DATACHANGED_PRINTER );
1443 0 : pApp->DataChanged( aDCEvt );
1444 0 : pApp->NotifyAllWindows( aDCEvt );
1445 : }
1446 : }
1447 : else
1448 0 : delete pNewList;
1449 : }
1450 465 : }
1451 :
1452 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|