/src/libreoffice/vcl/source/gdi/print3.cxx
Line | Count | Source |
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 | | #include <sal/types.h> |
21 | | #include <sal/log.hxx> |
22 | | #include <comphelper/processfactory.hxx> |
23 | | #include <comphelper/propertyvalue.hxx> |
24 | | #include <comphelper/sequence.hxx> |
25 | | #include <o3tl/safeint.hxx> |
26 | | #include <officecfg/VCL.hxx> |
27 | | #include <comphelper/diagnose_ex.hxx> |
28 | | #include <tools/debug.hxx> |
29 | | #include <tools/urlobj.hxx> |
30 | | |
31 | | #include <utility> |
32 | | #include <vcl/metaact.hxx> |
33 | | #include <vcl/print.hxx> |
34 | | #include <vcl/printer/Options.hxx> |
35 | | #include <vcl/svapp.hxx> |
36 | | #include <vcl/weld.hxx> |
37 | | |
38 | | #include <printdlg.hxx> |
39 | | #include <salinst.hxx> |
40 | | #include <salprn.hxx> |
41 | | #include <strings.hrc> |
42 | | #include <svdata.hxx> |
43 | | |
44 | | #include <com/sun/star/awt/Size.hpp> |
45 | | #include <com/sun/star/lang/IllegalArgumentException.hpp> |
46 | | #include <com/sun/star/ui/dialogs/FilePicker.hpp> |
47 | | #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp> |
48 | | #include <com/sun/star/ui/dialogs/TemplateDescription.hpp> |
49 | | #include <com/sun/star/view/DuplexMode.hpp> |
50 | | #include <com/sun/star/view/PaperOrientation.hpp> |
51 | | |
52 | | #include <unordered_map> |
53 | | #include <unordered_set> |
54 | | |
55 | | #ifdef MACOSX |
56 | | #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp> |
57 | | #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp> |
58 | | #endif |
59 | | |
60 | | using namespace vcl; |
61 | | |
62 | | namespace { |
63 | | |
64 | | class ImplPageCache |
65 | | { |
66 | | struct CacheEntry |
67 | | { |
68 | | GDIMetaFile aPage; |
69 | | PrinterController::PageSize aSize; |
70 | | }; |
71 | | |
72 | | std::vector< CacheEntry > maPages; |
73 | | std::vector< sal_Int32 > maPageNumbers; |
74 | | std::vector< sal_Int32 > maCacheRanking; |
75 | | |
76 | | static const sal_Int32 nCacheSize = 6; |
77 | | |
78 | | void updateRanking( sal_Int32 nLastHit ) |
79 | 0 | { |
80 | 0 | if( maCacheRanking[0] != nLastHit ) |
81 | 0 | { |
82 | 0 | for( sal_Int32 i = nCacheSize-1; i > 0; i-- ) |
83 | 0 | maCacheRanking[i] = maCacheRanking[i-1]; |
84 | 0 | maCacheRanking[0] = nLastHit; |
85 | 0 | } |
86 | 0 | } |
87 | | |
88 | | public: |
89 | | ImplPageCache() |
90 | 0 | : maPages( nCacheSize ) |
91 | 0 | , maPageNumbers( nCacheSize, -1 ) |
92 | 0 | , maCacheRanking( nCacheSize ) |
93 | 0 | { |
94 | 0 | for( sal_Int32 i = 0; i < nCacheSize; i++ ) |
95 | 0 | maCacheRanking[i] = nCacheSize - i - 1; |
96 | 0 | } |
97 | | |
98 | | // caution: does not ensure uniqueness |
99 | | void insert( sal_Int32 i_nPageNo, const GDIMetaFile& i_rPage, const PrinterController::PageSize& i_rSize ) |
100 | 0 | { |
101 | 0 | sal_Int32 nReplacePage = maCacheRanking.back(); |
102 | 0 | maPages[ nReplacePage ].aPage = i_rPage; |
103 | 0 | maPages[ nReplacePage ].aSize = i_rSize; |
104 | 0 | maPageNumbers[ nReplacePage ] = i_nPageNo; |
105 | | // cache insertion means in our case, the page was just queried |
106 | | // so update the ranking |
107 | 0 | updateRanking( nReplacePage ); |
108 | 0 | } |
109 | | |
110 | | // caution: bad algorithm; should there ever be reason to increase the cache size beyond 6 |
111 | | // this needs to be urgently rewritten. However do NOT increase the cache size lightly, |
112 | | // whole pages can be rather memory intensive |
113 | | bool get( sal_Int32 i_nPageNo, GDIMetaFile& o_rPageFile, PrinterController::PageSize& o_rSize ) |
114 | 0 | { |
115 | 0 | for( sal_Int32 i = 0; i < nCacheSize; ++i ) |
116 | 0 | { |
117 | 0 | if( maPageNumbers[i] == i_nPageNo ) |
118 | 0 | { |
119 | 0 | updateRanking( i ); |
120 | 0 | o_rPageFile = maPages[i].aPage; |
121 | 0 | o_rSize = maPages[i].aSize; |
122 | 0 | return true; |
123 | 0 | } |
124 | 0 | } |
125 | 0 | return false; |
126 | 0 | } |
127 | | |
128 | | void invalidate() |
129 | 0 | { |
130 | 0 | for( sal_Int32 i = 0; i < nCacheSize; ++i ) |
131 | 0 | { |
132 | 0 | maPageNumbers[i] = -1; |
133 | 0 | maPages[i].aPage.Clear(); |
134 | 0 | maCacheRanking[i] = nCacheSize - i - 1; |
135 | 0 | } |
136 | 0 | } |
137 | | }; |
138 | | |
139 | | } |
140 | | |
141 | | class vcl::ImplPrinterControllerData |
142 | | { |
143 | | public: |
144 | | struct ControlDependency |
145 | | { |
146 | | OUString maDependsOnName; |
147 | | sal_Int32 mnDependsOnEntry; |
148 | | |
149 | 0 | ControlDependency() : mnDependsOnEntry( -1 ) {} |
150 | | }; |
151 | | |
152 | | typedef std::unordered_map< OUString, size_t > PropertyToIndexMap; |
153 | | typedef std::unordered_map< OUString, ControlDependency > ControlDependencyMap; |
154 | | typedef std::unordered_map< OUString, css::uno::Sequence< sal_Bool > > ChoiceDisableMap; |
155 | | |
156 | | VclPtr< Printer > mxPrinter; |
157 | | weld::Window* mpWindow; |
158 | | css::uno::Sequence< css::beans::PropertyValue > maUIOptions; |
159 | | std::vector< css::beans::PropertyValue > maUIProperties; |
160 | | std::vector< bool > maUIPropertyEnabled; |
161 | | PropertyToIndexMap maPropertyToIndex; |
162 | | ControlDependencyMap maControlDependencies; |
163 | | ChoiceDisableMap maChoiceDisableMap; |
164 | | bool mbFirstPage; |
165 | | bool mbLastPage; |
166 | | bool mbReversePageOrder; |
167 | | bool mbPapersizeFromSetup; |
168 | | bool mbPapersizeFromUser; |
169 | | bool mbOrientationFromUser; |
170 | | bool mbPrinterModified; |
171 | | css::view::PrintableState meJobState; |
172 | | |
173 | | vcl::PrinterController::MultiPageSetup maMultiPage; |
174 | | |
175 | | std::shared_ptr<vcl::PrintProgressDialog> mxProgress; |
176 | | |
177 | | ImplPageCache maPageCache; |
178 | | |
179 | | // set by user through printer properties subdialog of printer settings dialog |
180 | | Size maDefaultPageSize; |
181 | | // set by user through print dialog |
182 | | Size maUserPageSize; |
183 | | // set by user through print dialog |
184 | | Orientation meUserOrientation; |
185 | | // set by user through printer properties subdialog of printer settings dialog |
186 | | sal_Int32 mnDefaultPaperBin; |
187 | | // Set by user through printer properties subdialog of print dialog. |
188 | | // Overrides application-set tray for a page. |
189 | | sal_Int32 mnFixedPaperBin; |
190 | | |
191 | | // N.B. Apparently we have three levels of paper tray settings |
192 | | // (latter overrides former): |
193 | | // 1. default tray |
194 | | // 2. tray set for a concrete page by an application, e.g., writer |
195 | | // allows setting a printer tray (for the default printer) for a |
196 | | // page style. This setting can be overridden by user by selecting |
197 | | // "Use only paper tray from printer preferences" on the Options |
198 | | // page in the print dialog, in which case the default tray is |
199 | | // used for all pages. |
200 | | // 3. tray set in printer properties the printer dialog |
201 | | // I'm not quite sure why 1. and 3. are distinct, but the commit |
202 | | // history suggests this is intentional... |
203 | | |
204 | | ImplPrinterControllerData() : |
205 | 0 | mpWindow( nullptr ), |
206 | 0 | mbFirstPage( true ), |
207 | 0 | mbLastPage( false ), |
208 | 0 | mbReversePageOrder( false ), |
209 | 0 | mbPapersizeFromSetup( false ), |
210 | 0 | mbPapersizeFromUser( false ), |
211 | 0 | mbOrientationFromUser( false ), |
212 | 0 | mbPrinterModified( false ), |
213 | 0 | meJobState( css::view::PrintableState_JOB_STARTED ), |
214 | 0 | meUserOrientation( Orientation::Portrait ), |
215 | 0 | mnDefaultPaperBin( -1 ), |
216 | 0 | mnFixedPaperBin( -1 ) |
217 | 0 | {} |
218 | | |
219 | | ~ImplPrinterControllerData() |
220 | 0 | { |
221 | 0 | if (mxProgress) |
222 | 0 | { |
223 | 0 | mxProgress->response(RET_CANCEL); |
224 | 0 | mxProgress.reset(); |
225 | 0 | } |
226 | 0 | } |
227 | | |
228 | | Size getRealPaperSize( const Size& i_rPageSize, bool bNoNUP ) const |
229 | 0 | { |
230 | 0 | Size size; |
231 | 0 | if ( mbPapersizeFromUser ) |
232 | 0 | size = maUserPageSize; |
233 | 0 | else if( mbPapersizeFromSetup ) |
234 | 0 | size = maDefaultPageSize; |
235 | 0 | else if( maMultiPage.nRows * maMultiPage.nColumns > 1 && ! bNoNUP ) |
236 | 0 | size = maMultiPage.aPaperSize; |
237 | 0 | else |
238 | 0 | size = i_rPageSize; |
239 | |
|
240 | 0 | bool bSwap = false; |
241 | 0 | const bool bSizeIsLandscape = size.Width() > size.Height(); |
242 | 0 | if(mbOrientationFromUser) |
243 | 0 | { |
244 | 0 | bSwap = (bSizeIsLandscape && Orientation::Portrait == meUserOrientation) |
245 | 0 | || (!bSizeIsLandscape && Orientation::Landscape == meUserOrientation); |
246 | 0 | } |
247 | 0 | else if (mbPapersizeFromUser || mbPapersizeFromSetup) // automatic orientation |
248 | 0 | { |
249 | 0 | const bool bDocumentPageIsLandscape = i_rPageSize.Width() > i_rPageSize.Height(); |
250 | 0 | bSwap = bDocumentPageIsLandscape != bSizeIsLandscape; |
251 | 0 | } |
252 | 0 | if (bSwap) |
253 | 0 | { |
254 | | // coverity[swapped_arguments : FALSE] - this is in the correct order |
255 | 0 | size = Size(size.Height(), size.Width()); |
256 | 0 | } |
257 | |
|
258 | 0 | return size; |
259 | 0 | } |
260 | | PrinterController::PageSize modifyJobSetup( const css::uno::Sequence< css::beans::PropertyValue >& i_rProps ); |
261 | | void resetPaperToLastConfigured(); |
262 | | }; |
263 | | |
264 | | PrinterController::PrinterController(const VclPtr<Printer>& i_xPrinter, weld::Window* i_pWindow) |
265 | 0 | : mpImplData( new ImplPrinterControllerData ) |
266 | 0 | { |
267 | 0 | mpImplData->mxPrinter = i_xPrinter; |
268 | 0 | mpImplData->mpWindow = i_pWindow; |
269 | 0 | } |
270 | | |
271 | | static OUString queryFile( Printer const * pPrinter, const OUString & rJobName ) |
272 | 0 | { |
273 | 0 | OUString aResult; |
274 | |
|
275 | 0 | const css::uno::Reference< css::uno::XComponentContext >& xContext( ::comphelper::getProcessComponentContext() ); |
276 | 0 | css::uno::Reference< css::ui::dialogs::XFilePicker3 > xFilePicker = css::ui::dialogs::FilePicker::createWithMode(xContext, css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION); |
277 | |
|
278 | 0 | try |
279 | 0 | { |
280 | | #ifdef MACOSX |
281 | | // Try to mimic the save dialog behavior when using the native |
282 | | // print dialog to save to PDF. |
283 | | if( pPrinter ) |
284 | | { |
285 | | // Set the suggested file name if possible |
286 | | if( !rJobName.isEmpty() ) |
287 | | xFilePicker->setDefaultName( rJobName ); |
288 | | |
289 | | // macOS normally saves only to PDF |
290 | | if( pPrinter->GetCapabilities( PrinterCapType::PDF ) ) |
291 | | { |
292 | | xFilePicker->appendFilter( u"Portable Document Format"_ustr, u"*.pdf"_ustr ); |
293 | | |
294 | | css::uno::Reference< css::ui::dialogs::XFilePickerControlAccess > xControlAccess( xFilePicker, css::uno::UNO_QUERY ); |
295 | | if( xControlAccess.is() ) |
296 | | xControlAccess->setValue( css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, css::uno::Any( true ) ); |
297 | | } |
298 | | } |
299 | | #else |
300 | 0 | (void)rJobName; |
301 | 0 | #ifdef UNX |
302 | | // add PostScript and PDF |
303 | 0 | bool bPS = true, bPDF = true; |
304 | 0 | if( pPrinter ) |
305 | 0 | { |
306 | 0 | if( pPrinter->GetCapabilities( PrinterCapType::PDF ) ) |
307 | 0 | bPS = false; |
308 | 0 | else |
309 | 0 | bPDF = false; |
310 | 0 | } |
311 | 0 | if( bPS ) |
312 | 0 | xFilePicker->appendFilter( u"PostScript"_ustr, u"*.ps"_ustr ); |
313 | 0 | if( bPDF ) |
314 | 0 | xFilePicker->appendFilter( u"Portable Document Format"_ustr, u"*.pdf"_ustr ); |
315 | | #elif defined _WIN32 |
316 | | (void)pPrinter; |
317 | | xFilePicker->appendFilter( "*.PRN", "*.prn" ); |
318 | | #endif |
319 | | // add arbitrary files |
320 | 0 | xFilePicker->appendFilter(VclResId(SV_STDTEXT_ALLFILETYPES), u"*.*"_ustr); |
321 | 0 | #endif |
322 | 0 | } |
323 | 0 | catch (const css::lang::IllegalArgumentException&) |
324 | 0 | { |
325 | 0 | TOOLS_WARN_EXCEPTION( "vcl.gdi", "caught IllegalArgumentException when registering filter" ); |
326 | 0 | } |
327 | | |
328 | 0 | if( xFilePicker->execute() == css::ui::dialogs::ExecutableDialogResults::OK ) |
329 | 0 | { |
330 | 0 | css::uno::Sequence< OUString > aPathSeq( xFilePicker->getSelectedFiles() ); |
331 | 0 | INetURLObject aObj( aPathSeq[0] ); |
332 | 0 | aResult = aObj.PathToFileName(); |
333 | 0 | } |
334 | 0 | return aResult; |
335 | 0 | } |
336 | | |
337 | | namespace { |
338 | | |
339 | | struct PrintJobAsync |
340 | | { |
341 | | std::shared_ptr<PrinterController> mxController; |
342 | | JobSetup maInitSetup; |
343 | | |
344 | | PrintJobAsync(std::shared_ptr<PrinterController> i_xController, |
345 | | const JobSetup& i_rInitSetup) |
346 | 0 | : mxController(std::move( i_xController )), maInitSetup( i_rInitSetup ) |
347 | 0 | {} |
348 | | |
349 | | DECL_LINK( ExecJob, void*, void ); |
350 | | }; |
351 | | |
352 | | } |
353 | | |
354 | | IMPL_LINK_NOARG(PrintJobAsync, ExecJob, void*, void) |
355 | 0 | { |
356 | 0 | Printer::ImplPrintJob(mxController, maInitSetup); |
357 | | |
358 | | // clean up, do not access members after this |
359 | 0 | delete this; |
360 | 0 | } |
361 | | |
362 | | void Printer::PrintJob(const std::shared_ptr<PrinterController>& i_xController, |
363 | | const JobSetup& i_rInitSetup) |
364 | 0 | { |
365 | 0 | bool bSynchronous = false; |
366 | 0 | css::beans::PropertyValue* pVal = i_xController->getValue( u"Wait"_ustr ); |
367 | 0 | if( pVal ) |
368 | 0 | pVal->Value >>= bSynchronous; |
369 | |
|
370 | 0 | if( bSynchronous ) |
371 | 0 | ImplPrintJob(i_xController, i_rInitSetup); |
372 | 0 | else |
373 | 0 | { |
374 | 0 | PrintJobAsync* pAsync = new PrintJobAsync(i_xController, i_rInitSetup); |
375 | 0 | Application::PostUserEvent( LINK( pAsync, PrintJobAsync, ExecJob ) ); |
376 | 0 | } |
377 | 0 | } |
378 | | |
379 | | bool Printer::PreparePrintJob(std::shared_ptr<PrinterController> xController, |
380 | | const JobSetup& i_rInitSetup) |
381 | 0 | { |
382 | 0 | Printer::updatePrinters(); |
383 | | |
384 | | // check if there is a default printer; if not, show an error box (if appropriate) |
385 | 0 | if( GetDefaultPrinterName().isEmpty() ) |
386 | 0 | { |
387 | 0 | if (xController->isShowDialogs()) |
388 | 0 | { |
389 | 0 | std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(xController->getWindow(), u"vcl/ui/errornoprinterdialog.ui"_ustr)); |
390 | 0 | std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog(u"ErrorNoPrinterDialog"_ustr)); |
391 | 0 | xBox->run(); |
392 | 0 | } |
393 | 0 | xController->setValue( u"IsDirect"_ustr, |
394 | 0 | css::uno::Any( false ) ); |
395 | 0 | } |
396 | | |
397 | | // setup printer |
398 | | |
399 | | // #i114306# changed behavior back from persistence |
400 | | // if no specific printer is already set, create the default printer |
401 | 0 | if (!xController->getPrinter()) |
402 | 0 | { |
403 | 0 | OUString aPrinterName( i_rInitSetup.GetPrinterName() ); |
404 | 0 | VclPtrInstance<Printer> xPrinter( aPrinterName ); |
405 | 0 | xPrinter->SetJobSetup(i_rInitSetup); |
406 | 0 | xController->setPrinter(xPrinter); |
407 | 0 | xController->setPapersizeFromSetup(xPrinter->GetPrinterSettingsPreferred()); |
408 | 0 | } |
409 | | |
410 | | // reset last page property |
411 | 0 | xController->setLastPage(false); |
412 | | |
413 | | // update "PageRange" property inferring from other properties: |
414 | | // case 1: "Pages" set from UNO API -> |
415 | | // setup "Print Selection" and insert "PageRange" attribute |
416 | | // case 2: "All pages" is selected |
417 | | // update "Page range" attribute to have a sensible default, |
418 | | // but leave "All" as selected |
419 | | |
420 | | // "Pages" attribute from API is now equivalent to "PageRange" |
421 | | // AND "PrintContent" = 1 except calc where it is "PrintRange" = 1 |
422 | | // Argh ! That sure needs cleaning up |
423 | 0 | css::beans::PropertyValue* pContentVal = xController->getValue(u"PrintRange"_ustr); |
424 | 0 | if( ! pContentVal ) |
425 | 0 | pContentVal = xController->getValue(u"PrintContent"_ustr); |
426 | | |
427 | | // case 1: UNO API has set "Pages" |
428 | 0 | css::beans::PropertyValue* pPagesVal = xController->getValue(u"Pages"_ustr); |
429 | 0 | if( pPagesVal ) |
430 | 0 | { |
431 | 0 | OUString aPagesVal; |
432 | 0 | pPagesVal->Value >>= aPagesVal; |
433 | 0 | if( !aPagesVal.isEmpty() ) |
434 | 0 | { |
435 | | // "Pages" attribute from API is now equivalent to "PageRange" |
436 | | // AND "PrintContent" = 1 except calc where it is "PrintRange" = 1 |
437 | | // Argh ! That sure needs cleaning up |
438 | 0 | if( pContentVal ) |
439 | 0 | { |
440 | 0 | pContentVal->Value <<= sal_Int32( 1 ); |
441 | 0 | xController->setValue(u"PageRange"_ustr, pPagesVal->Value); |
442 | 0 | } |
443 | 0 | } |
444 | 0 | } |
445 | | // case 2: is "All" selected ? |
446 | 0 | else if( pContentVal ) |
447 | 0 | { |
448 | 0 | sal_Int32 nContent = -1; |
449 | 0 | if( pContentVal->Value >>= nContent ) |
450 | 0 | { |
451 | 0 | if( nContent == 0 ) |
452 | 0 | { |
453 | | // do not overwrite PageRange if it is already set |
454 | 0 | css::beans::PropertyValue* pRangeVal = xController->getValue(u"PageRange"_ustr); |
455 | 0 | OUString aRange; |
456 | 0 | if( pRangeVal ) |
457 | 0 | pRangeVal->Value >>= aRange; |
458 | 0 | if( aRange.isEmpty() ) |
459 | 0 | { |
460 | 0 | sal_Int32 nPages = xController->getPageCount(); |
461 | 0 | if( nPages > 0 ) |
462 | 0 | { |
463 | 0 | OUStringBuffer aBuf( 32 ); |
464 | 0 | aBuf.append( "1" ); |
465 | 0 | if( nPages > 1 ) |
466 | 0 | { |
467 | 0 | aBuf.append( "-" + OUString::number( nPages ) ); |
468 | 0 | } |
469 | 0 | xController->setValue(u"PageRange"_ustr, css::uno::Any(aBuf.makeStringAndClear())); |
470 | 0 | } |
471 | 0 | } |
472 | 0 | } |
473 | 0 | } |
474 | 0 | } |
475 | |
|
476 | 0 | css::beans::PropertyValue* pReverseVal = xController->getValue(u"PrintReverse"_ustr); |
477 | 0 | if( pReverseVal ) |
478 | 0 | { |
479 | 0 | bool bReverse = false; |
480 | 0 | pReverseVal->Value >>= bReverse; |
481 | 0 | xController->setReversePrint( bReverse ); |
482 | 0 | } |
483 | |
|
484 | 0 | css::beans::PropertyValue* pPapersizeFromSetupVal = xController->getValue(u"PapersizeFromSetup"_ustr); |
485 | 0 | if( pPapersizeFromSetupVal ) |
486 | 0 | { |
487 | 0 | bool bPapersizeFromSetup = false; |
488 | 0 | pPapersizeFromSetupVal->Value >>= bPapersizeFromSetup; |
489 | 0 | xController->setPapersizeFromSetup(bPapersizeFromSetup); |
490 | 0 | } |
491 | | |
492 | | // setup NUp printing from properties |
493 | 0 | sal_Int32 nRows = xController->getIntProperty(u"NUpRows"_ustr, 1); |
494 | 0 | sal_Int32 nCols = xController->getIntProperty(u"NUpColumns"_ustr, 1); |
495 | 0 | if( nRows > 1 || nCols > 1 ) |
496 | 0 | { |
497 | 0 | PrinterController::MultiPageSetup aMPS; |
498 | 0 | aMPS.nRows = std::max<sal_Int32>(nRows, 1); |
499 | 0 | aMPS.nColumns = std::max<sal_Int32>(nCols, 1); |
500 | 0 | sal_Int32 nValue = xController->getIntProperty(u"NUpPageMarginLeft"_ustr, aMPS.nLeftMargin); |
501 | 0 | if( nValue >= 0 ) |
502 | 0 | aMPS.nLeftMargin = nValue; |
503 | 0 | nValue = xController->getIntProperty(u"NUpPageMarginRight"_ustr, aMPS.nRightMargin); |
504 | 0 | if( nValue >= 0 ) |
505 | 0 | aMPS.nRightMargin = nValue; |
506 | 0 | nValue = xController->getIntProperty( u"NUpPageMarginTop"_ustr, aMPS.nTopMargin ); |
507 | 0 | if( nValue >= 0 ) |
508 | 0 | aMPS.nTopMargin = nValue; |
509 | 0 | nValue = xController->getIntProperty( u"NUpPageMarginBottom"_ustr, aMPS.nBottomMargin ); |
510 | 0 | if( nValue >= 0 ) |
511 | 0 | aMPS.nBottomMargin = nValue; |
512 | 0 | nValue = xController->getIntProperty( u"NUpHorizontalSpacing"_ustr, aMPS.nHorizontalSpacing ); |
513 | 0 | if( nValue >= 0 ) |
514 | 0 | aMPS.nHorizontalSpacing = nValue; |
515 | 0 | nValue = xController->getIntProperty( u"NUpVerticalSpacing"_ustr, aMPS.nVerticalSpacing ); |
516 | 0 | if( nValue >= 0 ) |
517 | 0 | aMPS.nVerticalSpacing = nValue; |
518 | 0 | aMPS.bDrawBorder = xController->getBoolProperty( u"NUpDrawBorder"_ustr, aMPS.bDrawBorder ); |
519 | 0 | aMPS.nOrder = static_cast<NupOrderType>(xController->getIntProperty( u"NUpSubPageOrder"_ustr, static_cast<sal_Int32>(aMPS.nOrder) )); |
520 | 0 | aMPS.aPaperSize = xController->getPrinter()->PixelToLogic( xController->getPrinter()->GetPaperSizePixel(), MapMode( MapUnit::Map100thMM ) ); |
521 | 0 | css::beans::PropertyValue* pPgSizeVal = xController->getValue( u"NUpPaperSize"_ustr ); |
522 | 0 | css::awt::Size aSizeVal; |
523 | 0 | if( pPgSizeVal && (pPgSizeVal->Value >>= aSizeVal) ) |
524 | 0 | { |
525 | 0 | aMPS.aPaperSize.setWidth( aSizeVal.Width ); |
526 | 0 | aMPS.aPaperSize.setHeight( aSizeVal.Height ); |
527 | 0 | } |
528 | |
|
529 | 0 | xController->setMultipage( aMPS ); |
530 | 0 | } |
531 | | |
532 | | // in direct print case check whether there is anything to print. |
533 | | // if not, show an errorbox (if appropriate) |
534 | 0 | if( xController->isShowDialogs() && xController->isDirectPrint() ) |
535 | 0 | { |
536 | 0 | if( xController->getFilteredPageCount() == 0 ) |
537 | 0 | { |
538 | 0 | std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(xController->getWindow(), u"vcl/ui/errornocontentdialog.ui"_ustr)); |
539 | 0 | std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog(u"ErrorNoContentDialog"_ustr)); |
540 | 0 | xBox->run(); |
541 | 0 | return false; |
542 | 0 | } |
543 | 0 | } |
544 | | |
545 | | // check if the printer brings up its own dialog |
546 | | // in that case leave the work to that dialog |
547 | 0 | if( ! xController->getPrinter()->GetCapabilities( PrinterCapType::ExternalDialog ) && |
548 | 0 | ! xController->isDirectPrint() && |
549 | 0 | xController->isShowDialogs() |
550 | 0 | ) |
551 | 0 | { |
552 | 0 | try |
553 | 0 | { |
554 | 0 | PrintDialog aDlg(xController->getWindow(), xController); |
555 | 0 | if (!aDlg.run()) |
556 | 0 | { |
557 | 0 | xController->abortJob(); |
558 | 0 | return false; |
559 | 0 | } |
560 | 0 | if (aDlg.isPrintToFile()) |
561 | 0 | { |
562 | 0 | OUString aJobName; |
563 | 0 | css::beans::PropertyValue* pJobNameVal = xController->getValue( u"JobName"_ustr ); |
564 | 0 | if( pJobNameVal ) |
565 | 0 | pJobNameVal->Value >>= aJobName; |
566 | 0 | OUString aFile = queryFile( xController->getPrinter().get(), aJobName ); |
567 | 0 | if( aFile.isEmpty() ) |
568 | 0 | { |
569 | 0 | xController->abortJob(); |
570 | 0 | return false; |
571 | 0 | } |
572 | 0 | xController->setValue( u"LocalFileName"_ustr, |
573 | 0 | css::uno::Any( aFile ) ); |
574 | 0 | } |
575 | 0 | else if (aDlg.isSingleJobs()) |
576 | 0 | { |
577 | 0 | xController->getPrinter()->SetSinglePrintJobs(true); |
578 | 0 | } |
579 | 0 | } |
580 | 0 | catch (const std::bad_alloc&) |
581 | 0 | { |
582 | 0 | } |
583 | 0 | } |
584 | | |
585 | 0 | xController->pushPropertiesToPrinter(); |
586 | 0 | return true; |
587 | 0 | } |
588 | | |
589 | | bool Printer::ExecutePrintJob(const std::shared_ptr<PrinterController>& xController) |
590 | 0 | { |
591 | 0 | OUString aJobName; |
592 | 0 | css::beans::PropertyValue* pJobNameVal = xController->getValue( u"JobName"_ustr ); |
593 | 0 | if( pJobNameVal ) |
594 | 0 | pJobNameVal->Value >>= aJobName; |
595 | |
|
596 | 0 | return xController->getPrinter()->StartJob( aJobName, xController ); |
597 | 0 | } |
598 | | |
599 | | void Printer::FinishPrintJob(const std::shared_ptr<PrinterController>& xController) |
600 | 0 | { |
601 | 0 | xController->resetPaperToLastConfigured(); |
602 | 0 | xController->jobFinished( xController->getJobState() ); |
603 | 0 | } |
604 | | |
605 | | void Printer::ImplPrintJob(const std::shared_ptr<PrinterController>& xController, |
606 | | const JobSetup& i_rInitSetup) |
607 | 0 | { |
608 | 0 | if (PreparePrintJob(xController, i_rInitSetup)) |
609 | 0 | { |
610 | 0 | ExecutePrintJob(xController); |
611 | 0 | } |
612 | 0 | FinishPrintJob(xController); |
613 | 0 | } |
614 | | |
615 | | bool Printer::StartJob( const OUString& i_rJobName, std::shared_ptr<vcl::PrinterController> const & i_xController) |
616 | 0 | { |
617 | 0 | mnError = ERRCODE_NONE; |
618 | |
|
619 | 0 | if ( IsDisplayPrinter() ) |
620 | 0 | return false; |
621 | | |
622 | 0 | if ( IsJobActive() || IsPrinting() ) |
623 | 0 | return false; |
624 | | |
625 | 0 | sal_uInt32 nCopies = mnCopyCount; |
626 | 0 | bool bCollateCopy = mbCollateCopy; |
627 | 0 | bool bUserCopy = false; |
628 | |
|
629 | 0 | if ( nCopies > 1 ) |
630 | 0 | { |
631 | 0 | const sal_uInt32 nDevCopy = GetCapabilities( bCollateCopy |
632 | 0 | ? PrinterCapType::CollateCopies |
633 | 0 | : PrinterCapType::Copies ); |
634 | | |
635 | | // need to do copies by hand ? |
636 | 0 | if ( nCopies > nDevCopy ) |
637 | 0 | { |
638 | 0 | bUserCopy = true; |
639 | 0 | nCopies = 1; |
640 | 0 | bCollateCopy = false; |
641 | 0 | } |
642 | 0 | } |
643 | 0 | else |
644 | 0 | bCollateCopy = false; |
645 | |
|
646 | 0 | ImplSVData* pSVData = ImplGetSVData(); |
647 | 0 | mpPrinter = pSVData->mpDefInst->CreatePrinter( mpInfoPrinter ); |
648 | |
|
649 | 0 | if (!mpPrinter) |
650 | 0 | return false; |
651 | | |
652 | 0 | bool bSinglePrintJobs = i_xController->getPrinter()->IsSinglePrintJobs(); |
653 | |
|
654 | 0 | css::beans::PropertyValue* pFileValue = i_xController->getValue(u"LocalFileName"_ustr); |
655 | 0 | if( pFileValue ) |
656 | 0 | { |
657 | 0 | OUString aFile; |
658 | 0 | pFileValue->Value >>= aFile; |
659 | 0 | if( !aFile.isEmpty() ) |
660 | 0 | { |
661 | 0 | mbPrintFile = true; |
662 | 0 | maPrintFile = aFile; |
663 | 0 | bSinglePrintJobs = false; |
664 | 0 | } |
665 | 0 | } |
666 | |
|
667 | 0 | OUString* pPrintFile = nullptr; |
668 | 0 | if ( mbPrintFile ) |
669 | 0 | pPrintFile = &maPrintFile; |
670 | 0 | mpPrinterOptions->ReadFromConfig( mbPrintFile ); |
671 | |
|
672 | 0 | mbPrinting = true; |
673 | 0 | if( GetCapabilities( PrinterCapType::UsePullModel ) ) |
674 | 0 | { |
675 | 0 | mbJobActive = true; |
676 | | // SAL layer does all necessary page printing |
677 | | // and also handles showing a dialog |
678 | | // that also means it must call jobStarted when the dialog is finished |
679 | | // it also must set the JobState of the Controller |
680 | 0 | if( mpPrinter->StartJob( pPrintFile, |
681 | 0 | i_rJobName, |
682 | 0 | Application::GetDisplayName(), |
683 | 0 | &maJobSetup.ImplGetData(), |
684 | 0 | *i_xController) ) |
685 | 0 | { |
686 | 0 | EndJob(); |
687 | 0 | } |
688 | 0 | else |
689 | 0 | { |
690 | 0 | mnError = ImplSalPrinterErrorCodeToVCL(mpPrinter->GetErrorCode()); |
691 | 0 | if ( !mnError ) |
692 | 0 | mnError = PRINTER_GENERALERROR; |
693 | 0 | mbPrinting = false; |
694 | 0 | mpPrinter.reset(); |
695 | 0 | mbJobActive = false; |
696 | |
|
697 | 0 | GDIMetaFile aDummyFile; |
698 | 0 | i_xController->setLastPage(true); |
699 | 0 | i_xController->getFilteredPageFile(0, aDummyFile); |
700 | |
|
701 | 0 | return false; |
702 | 0 | } |
703 | 0 | } |
704 | 0 | else |
705 | 0 | { |
706 | | // possibly a dialog has been shown |
707 | | // now the real job starts |
708 | 0 | i_xController->setJobState( css::view::PrintableState_JOB_STARTED ); |
709 | 0 | i_xController->jobStarted(); |
710 | |
|
711 | 0 | int nJobs = 1; |
712 | 0 | int nOuterRepeatCount = 1; |
713 | 0 | int nInnerRepeatCount = 1; |
714 | 0 | if( bUserCopy ) |
715 | 0 | { |
716 | 0 | if( mbCollateCopy ) |
717 | 0 | nOuterRepeatCount = mnCopyCount; |
718 | 0 | else |
719 | 0 | nInnerRepeatCount = mnCopyCount; |
720 | 0 | } |
721 | 0 | if( bSinglePrintJobs ) |
722 | 0 | { |
723 | 0 | nJobs = mnCopyCount; |
724 | 0 | nCopies = 1; |
725 | 0 | nOuterRepeatCount = nInnerRepeatCount = 1; |
726 | 0 | } |
727 | |
|
728 | 0 | for( int nJobIteration = 0; nJobIteration < nJobs; nJobIteration++ ) |
729 | 0 | { |
730 | 0 | bool bError = false; |
731 | 0 | if( mpPrinter->StartJob( pPrintFile, |
732 | 0 | i_rJobName, |
733 | 0 | Application::GetDisplayName(), |
734 | 0 | nCopies, |
735 | 0 | bCollateCopy, |
736 | 0 | i_xController->isDirectPrint(), |
737 | 0 | &maJobSetup.ImplGetData() ) ) |
738 | 0 | { |
739 | 0 | bool bAborted = false; |
740 | 0 | mbJobActive = true; |
741 | 0 | i_xController->createProgressDialog(); |
742 | 0 | const int nPages = i_xController->getFilteredPageCount(); |
743 | | // abort job, if no pages will be printed. |
744 | 0 | if ( nPages == 0 ) |
745 | 0 | { |
746 | 0 | i_xController->abortJob(); |
747 | 0 | bAborted = true; |
748 | 0 | } |
749 | 0 | for( int nOuterIteration = 0; nOuterIteration < nOuterRepeatCount && ! bAborted; nOuterIteration++ ) |
750 | 0 | { |
751 | 0 | for( int nPage = 0; nPage < nPages && ! bAborted; nPage++ ) |
752 | 0 | { |
753 | 0 | for( int nInnerIteration = 0; nInnerIteration < nInnerRepeatCount && ! bAborted; nInnerIteration++ ) |
754 | 0 | { |
755 | 0 | if( nPage == nPages-1 && |
756 | 0 | nOuterIteration == nOuterRepeatCount-1 && |
757 | 0 | nInnerIteration == nInnerRepeatCount-1 && |
758 | 0 | nJobIteration == nJobs-1 ) |
759 | 0 | { |
760 | 0 | i_xController->setLastPage(true); |
761 | 0 | } |
762 | 0 | i_xController->printFilteredPage(nPage); |
763 | 0 | if (i_xController->isProgressCanceled()) |
764 | 0 | { |
765 | 0 | i_xController->abortJob(); |
766 | 0 | } |
767 | 0 | if (i_xController->getJobState() == |
768 | 0 | css::view::PrintableState_JOB_ABORTED) |
769 | 0 | { |
770 | 0 | bAborted = true; |
771 | 0 | } |
772 | 0 | } |
773 | 0 | } |
774 | | // FIXME: duplex ? |
775 | 0 | } |
776 | 0 | EndJob(); |
777 | |
|
778 | 0 | if( nJobIteration < nJobs-1 ) |
779 | 0 | { |
780 | 0 | mpPrinter = pSVData->mpDefInst->CreatePrinter( mpInfoPrinter ); |
781 | |
|
782 | 0 | if ( mpPrinter ) |
783 | 0 | mbPrinting = true; |
784 | 0 | else |
785 | 0 | bError = true; |
786 | 0 | } |
787 | 0 | } |
788 | 0 | else |
789 | 0 | bError = true; |
790 | |
|
791 | 0 | if( bError ) |
792 | 0 | { |
793 | 0 | mnError = mpPrinter ? ImplSalPrinterErrorCodeToVCL(mpPrinter->GetErrorCode()) : ERRCODE_NONE; |
794 | 0 | if ( !mnError ) |
795 | 0 | mnError = PRINTER_GENERALERROR; |
796 | 0 | i_xController->setJobState( mnError == PRINTER_ABORT |
797 | 0 | ? css::view::PrintableState_JOB_ABORTED |
798 | 0 | : css::view::PrintableState_JOB_FAILED ); |
799 | 0 | mbPrinting = false; |
800 | 0 | mpPrinter.reset(); |
801 | |
|
802 | 0 | return false; |
803 | 0 | } |
804 | 0 | } |
805 | | |
806 | 0 | if (i_xController->getJobState() == css::view::PrintableState_JOB_STARTED) |
807 | 0 | i_xController->setJobState(css::view::PrintableState_JOB_SPOOLED); |
808 | 0 | } |
809 | | |
810 | | // make last used printer persistent for UI jobs |
811 | 0 | if (i_xController->isShowDialogs() && !i_xController->isDirectPrint()) |
812 | 0 | { |
813 | 0 | std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create()); |
814 | 0 | officecfg::VCL::VCLSettings::PrintDialog::LastPrinter::set( GetName(), batch ); |
815 | 0 | batch->commit(); |
816 | 0 | } |
817 | |
|
818 | 0 | return true; |
819 | 0 | } |
820 | | |
821 | | PrinterController::~PrinterController() |
822 | 0 | { |
823 | 0 | } |
824 | | |
825 | | css::view::PrintableState PrinterController::getJobState() const |
826 | 0 | { |
827 | 0 | return mpImplData->meJobState; |
828 | 0 | } |
829 | | |
830 | | void PrinterController::setJobState( css::view::PrintableState i_eState ) |
831 | 0 | { |
832 | 0 | mpImplData->meJobState = i_eState; |
833 | 0 | } |
834 | | |
835 | | const VclPtr<Printer>& PrinterController::getPrinter() const |
836 | 0 | { |
837 | 0 | return mpImplData->mxPrinter; |
838 | 0 | } |
839 | | |
840 | | weld::Window* PrinterController::getWindow() const |
841 | 0 | { |
842 | 0 | return mpImplData->mpWindow; |
843 | 0 | } |
844 | | |
845 | | void PrinterController::dialogsParentClosing() |
846 | 0 | { |
847 | 0 | mpImplData->mpWindow = nullptr; |
848 | 0 | if (mpImplData->mxProgress) |
849 | 0 | { |
850 | | // close the dialog without doing anything, just get rid of it |
851 | 0 | mpImplData->mxProgress->response(RET_OK); |
852 | 0 | mpImplData->mxProgress.reset(); |
853 | 0 | } |
854 | 0 | } |
855 | | |
856 | | void PrinterController::setPrinter( const VclPtr<Printer>& i_rPrinter ) |
857 | 0 | { |
858 | 0 | VclPtr<Printer> xPrinter = mpImplData->mxPrinter; |
859 | |
|
860 | 0 | Size aPaperSize; // Save current paper size |
861 | 0 | Orientation eOrientation = Orientation::Portrait; // Save current paper orientation |
862 | 0 | bool bSavedSizeOrientation = false; |
863 | | |
864 | | // #tdf 126744 Transfer paper size and orientation settings to newly selected printer |
865 | 0 | if ( xPrinter ) |
866 | 0 | { |
867 | 0 | aPaperSize = xPrinter->GetPaperSize(); |
868 | 0 | eOrientation = xPrinter->GetOrientation(); |
869 | 0 | bSavedSizeOrientation = true; |
870 | 0 | } |
871 | |
|
872 | 0 | mpImplData->mxPrinter = i_rPrinter; |
873 | 0 | setValue( u"Name"_ustr, |
874 | 0 | css::uno::Any( i_rPrinter->GetName() ) ); |
875 | 0 | mpImplData->mnDefaultPaperBin = mpImplData->mxPrinter->GetPaperBin(); |
876 | 0 | auto popIt = mpImplData->mxPrinter->ScopedPush(); |
877 | 0 | mpImplData->mxPrinter->SetMapMode(MapMode(MapUnit::Map100thMM)); |
878 | 0 | mpImplData->maDefaultPageSize = mpImplData->mxPrinter->GetPaperSize(); |
879 | |
|
880 | 0 | if ( bSavedSizeOrientation ) |
881 | 0 | { |
882 | 0 | mpImplData->mxPrinter->SetPaperSizeUser(aPaperSize); |
883 | 0 | mpImplData->mxPrinter->SetOrientation(eOrientation); |
884 | 0 | } |
885 | |
|
886 | 0 | mpImplData->mbPapersizeFromUser = false; |
887 | 0 | mpImplData->mbOrientationFromUser = false; |
888 | 0 | mpImplData->mnFixedPaperBin = -1; |
889 | 0 | } |
890 | | |
891 | | void PrinterController::resetPrinterOptions( bool i_bFileOutput ) |
892 | 0 | { |
893 | 0 | vcl::printer::Options aOpt; |
894 | 0 | aOpt.ReadFromConfig( i_bFileOutput ); |
895 | 0 | mpImplData->mxPrinter->SetPrinterOptions( aOpt ); |
896 | 0 | } |
897 | | |
898 | | void PrinterController::invalidatePageCache() |
899 | 0 | { |
900 | 0 | mpImplData->maPageCache.invalidate(); |
901 | 0 | } |
902 | | |
903 | | void PrinterController::setupPrinter( weld::Window* i_pParent ) |
904 | 0 | { |
905 | 0 | bool bRet = false; |
906 | | |
907 | | // Important to hold printer alive while doing setup etc. |
908 | 0 | VclPtr< Printer > xPrinter = mpImplData->mxPrinter; |
909 | |
|
910 | 0 | if( !xPrinter ) |
911 | 0 | return; |
912 | | |
913 | 0 | auto popIt = xPrinter->ScopedPush(); |
914 | 0 | xPrinter->SetMapMode(MapMode(MapUnit::Map100thMM)); |
915 | | |
916 | | // get current data |
917 | 0 | Size aPaperSize(xPrinter->GetPaperSize()); |
918 | 0 | Orientation eOrientation = xPrinter->GetOrientation(); |
919 | 0 | sal_uInt16 nPaperBin = xPrinter->GetPaperBin(); |
920 | | |
921 | | // reset paper size back to last configured size, not |
922 | | // whatever happens to be the current page |
923 | | // (but only if the printer config has changed, otherwise |
924 | | // don't override printer page auto-detection - tdf#91362) |
925 | 0 | if (getPrinterModified() || getPapersizeFromSetup()) |
926 | 0 | { |
927 | 0 | resetPaperToLastConfigured(); |
928 | 0 | } |
929 | | |
930 | | // call driver setup |
931 | 0 | bRet = xPrinter->Setup( i_pParent, PrinterSetupMode::SingleJob ); |
932 | 0 | SAL_WARN_IF(xPrinter != mpImplData->mxPrinter, "vcl.gdi", |
933 | 0 | "Printer changed underneath us during setup"); |
934 | 0 | xPrinter = mpImplData->mxPrinter; |
935 | |
|
936 | 0 | Size aNewPaperSize(xPrinter->GetPaperSize()); |
937 | 0 | if (bRet) |
938 | 0 | { |
939 | 0 | bool bInvalidateCache = false; |
940 | 0 | setPapersizeFromSetup(xPrinter->GetPrinterSettingsPreferred()); |
941 | | |
942 | | // was papersize overridden ? if so we need to take action if we're |
943 | | // configured to use the driver papersize |
944 | 0 | if (aNewPaperSize != mpImplData->maDefaultPageSize) |
945 | 0 | { |
946 | 0 | mpImplData->maDefaultPageSize = aNewPaperSize; |
947 | 0 | bInvalidateCache = getPapersizeFromSetup(); |
948 | 0 | } |
949 | | |
950 | | // was bin overridden ? if so we need to take action |
951 | 0 | sal_uInt16 nNewPaperBin = xPrinter->GetPaperBin(); |
952 | 0 | if (nNewPaperBin != nPaperBin) |
953 | 0 | { |
954 | 0 | mpImplData->mnFixedPaperBin = nNewPaperBin; |
955 | 0 | bInvalidateCache = true; |
956 | 0 | } |
957 | |
|
958 | 0 | if (bInvalidateCache) |
959 | 0 | invalidatePageCache(); |
960 | 0 | } |
961 | 0 | else |
962 | 0 | { |
963 | | //restore to whatever it was before we entered this method |
964 | 0 | xPrinter->SetOrientation( eOrientation ); |
965 | 0 | if (aPaperSize != aNewPaperSize) |
966 | 0 | xPrinter->SetPaperSizeUser(aPaperSize); |
967 | 0 | } |
968 | 0 | } |
969 | | |
970 | | PrinterController::PageSize vcl::ImplPrinterControllerData::modifyJobSetup( const css::uno::Sequence< css::beans::PropertyValue >& i_rProps ) |
971 | 0 | { |
972 | 0 | PrinterController::PageSize aPageSize; |
973 | 0 | aPageSize.aSize = mxPrinter->GetPaperSize(); |
974 | 0 | css::awt::Size aSetSize, aIsSize; |
975 | 0 | sal_Int32 nPaperBin = mnDefaultPaperBin; |
976 | 0 | for( const auto& rProp : i_rProps ) |
977 | 0 | { |
978 | 0 | if ( rProp.Name == "PreferredPageSize" ) |
979 | 0 | { |
980 | 0 | rProp.Value >>= aSetSize; |
981 | 0 | } |
982 | 0 | else if ( rProp.Name == "PageSize" ) |
983 | 0 | { |
984 | 0 | rProp.Value >>= aIsSize; |
985 | 0 | } |
986 | 0 | else if ( rProp.Name == "PageIncludesNonprintableArea" ) |
987 | 0 | { |
988 | 0 | bool bVal = false; |
989 | 0 | rProp.Value >>= bVal; |
990 | 0 | aPageSize.bFullPaper = bVal; |
991 | 0 | } |
992 | 0 | else if ( rProp.Name == "PrinterPaperTray" ) |
993 | 0 | { |
994 | 0 | sal_Int32 nBin = -1; |
995 | 0 | rProp.Value >>= nBin; |
996 | 0 | if( nBin >= 0 && o3tl::make_unsigned(nBin) < mxPrinter->GetPaperBinCount() ) |
997 | 0 | nPaperBin = nBin; |
998 | 0 | } |
999 | 0 | else if ( rProp.Name == "PaperOrientation" ) |
1000 | 0 | { |
1001 | 0 | css::view::PaperOrientation nOrientation = css::view::PaperOrientation::PaperOrientation_PORTRAIT; |
1002 | 0 | rProp.Value >>= nOrientation; |
1003 | 0 | mxPrinter->SetOrientation( nOrientation == css::view::PaperOrientation::PaperOrientation_LANDSCAPE ? Orientation::Landscape : Orientation::Portrait ); |
1004 | 0 | } |
1005 | 0 | } |
1006 | |
|
1007 | 0 | Size aCurSize( mxPrinter->GetPaperSize() ); |
1008 | 0 | if( aSetSize.Width && aSetSize.Height ) |
1009 | 0 | { |
1010 | 0 | Size aSetPaperSize( aSetSize.Width, aSetSize.Height ); |
1011 | 0 | Size aRealPaperSize( getRealPaperSize( aSetPaperSize, true/*bNoNUP*/ ) ); |
1012 | 0 | if( aRealPaperSize != aCurSize ) |
1013 | 0 | aIsSize = aSetSize; |
1014 | 0 | } |
1015 | |
|
1016 | 0 | if( aIsSize.Width && aIsSize.Height ) |
1017 | 0 | { |
1018 | 0 | aPageSize.aSize.setWidth( aIsSize.Width ); |
1019 | 0 | aPageSize.aSize.setHeight( aIsSize.Height ); |
1020 | |
|
1021 | 0 | Size aRealPaperSize( getRealPaperSize( aPageSize.aSize, true/*bNoNUP*/ ) ); |
1022 | 0 | if( aRealPaperSize != aCurSize ) |
1023 | 0 | mxPrinter->SetPaperSizeUser( aRealPaperSize ); |
1024 | 0 | } |
1025 | | |
1026 | | // paper bin set from properties in print dialog overrides |
1027 | | // application default for a page |
1028 | 0 | if ( mnFixedPaperBin != -1 ) |
1029 | 0 | nPaperBin = mnFixedPaperBin; |
1030 | |
|
1031 | 0 | if( nPaperBin != -1 && nPaperBin != mxPrinter->GetPaperBin() ) |
1032 | 0 | mxPrinter->SetPaperBin( nPaperBin ); |
1033 | |
|
1034 | 0 | return aPageSize; |
1035 | 0 | } |
1036 | | |
1037 | | //fdo#61886 |
1038 | | |
1039 | | //when printing is finished, set the paper size of the printer to either what |
1040 | | //the user explicitly set as the desired paper size, or fallback to whatever |
1041 | | //the printer had before printing started. That way it doesn't contain the last |
1042 | | //paper size of a multiple paper size using document when we are in our normal |
1043 | | //auto accept document paper size mode and end up overwriting the original |
1044 | | //paper size setting for file->printer_settings just by pressing "ok" in the |
1045 | | //print dialog |
1046 | | void vcl::ImplPrinterControllerData::resetPaperToLastConfigured() |
1047 | 0 | { |
1048 | 0 | auto popIt = mxPrinter->ScopedPush(); |
1049 | 0 | mxPrinter->SetMapMode(MapMode(MapUnit::Map100thMM)); |
1050 | 0 | Size aCurSize(mxPrinter->GetPaperSize()); |
1051 | 0 | if (aCurSize != maDefaultPageSize) |
1052 | 0 | mxPrinter->SetPaperSizeUser(maDefaultPageSize); |
1053 | 0 | } |
1054 | | |
1055 | | int PrinterController::getPageCountProtected() const |
1056 | 0 | { |
1057 | 0 | const MapMode aMapMode( MapUnit::Map100thMM ); |
1058 | |
|
1059 | 0 | auto popIt = mpImplData->mxPrinter->ScopedPush(); |
1060 | 0 | mpImplData->mxPrinter->SetMapMode( aMapMode ); |
1061 | 0 | return getPageCount(); |
1062 | 0 | } |
1063 | | |
1064 | | css::uno::Sequence< css::beans::PropertyValue > PrinterController::getPageParametersProtected( int i_nPage ) const |
1065 | 0 | { |
1066 | 0 | const MapMode aMapMode( MapUnit::Map100thMM ); |
1067 | |
|
1068 | 0 | auto popIt = mpImplData->mxPrinter->ScopedPush(); |
1069 | 0 | mpImplData->mxPrinter->SetMapMode( aMapMode ); |
1070 | 0 | return getPageParameters(i_nPage); |
1071 | 0 | } |
1072 | | |
1073 | | PrinterController::PageSize PrinterController::getPageFile( int i_nUnfilteredPage, GDIMetaFile& o_rMtf, bool i_bMayUseCache ) |
1074 | 0 | { |
1075 | | // update progress if necessary |
1076 | 0 | if( mpImplData->mxProgress ) |
1077 | 0 | { |
1078 | | // do nothing if printing is canceled |
1079 | 0 | if( mpImplData->mxProgress->isCanceled() ) |
1080 | 0 | return PrinterController::PageSize(); |
1081 | 0 | mpImplData->mxProgress->tick(); |
1082 | 0 | Application::Reschedule( true ); |
1083 | 0 | } |
1084 | | |
1085 | 0 | if( i_bMayUseCache ) |
1086 | 0 | { |
1087 | 0 | PrinterController::PageSize aPageSize; |
1088 | 0 | if( mpImplData->maPageCache.get( i_nUnfilteredPage, o_rMtf, aPageSize ) ) |
1089 | 0 | { |
1090 | 0 | return aPageSize; |
1091 | 0 | } |
1092 | 0 | } |
1093 | 0 | else |
1094 | 0 | invalidatePageCache(); |
1095 | | |
1096 | 0 | o_rMtf.Clear(); |
1097 | | |
1098 | | // get page parameters |
1099 | 0 | css::uno::Sequence< css::beans::PropertyValue > aPageParm( getPageParametersProtected( i_nUnfilteredPage ) ); |
1100 | 0 | const MapMode aMapMode( MapUnit::Map100thMM ); |
1101 | |
|
1102 | 0 | mpImplData->mxPrinter->Push(); |
1103 | 0 | mpImplData->mxPrinter->SetMapMode( aMapMode ); |
1104 | | |
1105 | | // modify job setup if necessary |
1106 | 0 | PrinterController::PageSize aPageSize = mpImplData->modifyJobSetup( aPageParm ); |
1107 | |
|
1108 | 0 | o_rMtf.SetPrefSize( aPageSize.aSize ); |
1109 | 0 | o_rMtf.SetPrefMapMode( aMapMode ); |
1110 | |
|
1111 | 0 | mpImplData->mxPrinter->EnableOutput( false ); |
1112 | |
|
1113 | 0 | o_rMtf.Record( mpImplData->mxPrinter.get() ); |
1114 | |
|
1115 | 0 | printPage( i_nUnfilteredPage ); |
1116 | |
|
1117 | 0 | o_rMtf.Stop(); |
1118 | 0 | o_rMtf.WindStart(); |
1119 | 0 | mpImplData->mxPrinter->Pop(); |
1120 | |
|
1121 | 0 | if( i_bMayUseCache ) |
1122 | 0 | mpImplData->maPageCache.insert( i_nUnfilteredPage, o_rMtf, aPageSize ); |
1123 | | |
1124 | | // reset "FirstPage" property to false now we've gotten at least our first one |
1125 | 0 | mpImplData->mbFirstPage = false; |
1126 | |
|
1127 | 0 | return aPageSize; |
1128 | 0 | } |
1129 | | |
1130 | | static void appendSubPage( GDIMetaFile& o_rMtf, const tools::Rectangle& i_rClipRect, GDIMetaFile& io_rSubPage, bool i_bDrawBorder ) |
1131 | 0 | { |
1132 | | // intersect all clipregion actions with our clip rect |
1133 | 0 | io_rSubPage.WindStart(); |
1134 | 0 | io_rSubPage.Clip( i_rClipRect ); |
1135 | | |
1136 | | // save gstate |
1137 | 0 | o_rMtf.AddAction( new MetaPushAction( PushFlags::ALL ) ); |
1138 | | |
1139 | | // clip to page rect |
1140 | 0 | o_rMtf.AddAction( new MetaClipRegionAction( vcl::Region( i_rClipRect ), true ) ); |
1141 | | |
1142 | | // append the subpage |
1143 | 0 | io_rSubPage.WindStart(); |
1144 | 0 | io_rSubPage.Play( o_rMtf ); |
1145 | | |
1146 | | // restore gstate |
1147 | 0 | o_rMtf.AddAction( new MetaPopAction() ); |
1148 | | |
1149 | | // draw a border |
1150 | 0 | if( !i_bDrawBorder ) |
1151 | 0 | return; |
1152 | | |
1153 | | // save gstate |
1154 | 0 | o_rMtf.AddAction( new MetaPushAction( PushFlags::LINECOLOR | PushFlags::FILLCOLOR | PushFlags::CLIPREGION | PushFlags::MAPMODE ) ); |
1155 | 0 | o_rMtf.AddAction( new MetaMapModeAction( MapMode( MapUnit::Map100thMM ) ) ); |
1156 | |
|
1157 | 0 | tools::Rectangle aBorderRect( i_rClipRect ); |
1158 | 0 | o_rMtf.AddAction( new MetaLineColorAction( COL_BLACK, true ) ); |
1159 | 0 | o_rMtf.AddAction( new MetaFillColorAction( COL_TRANSPARENT, false ) ); |
1160 | 0 | o_rMtf.AddAction( new MetaRectAction( aBorderRect ) ); |
1161 | | |
1162 | | // restore gstate |
1163 | 0 | o_rMtf.AddAction( new MetaPopAction() ); |
1164 | 0 | } |
1165 | | |
1166 | | PrinterController::PageSize PrinterController::getFilteredPageFile( int i_nFilteredPage, GDIMetaFile& o_rMtf, bool i_bMayUseCache ) |
1167 | 0 | { |
1168 | 0 | const MultiPageSetup& rMPS( mpImplData->maMultiPage ); |
1169 | 0 | int nSubPages = rMPS.nRows * rMPS.nColumns; |
1170 | 0 | if( nSubPages < 1 ) |
1171 | 0 | nSubPages = 1; |
1172 | | |
1173 | | // reverse sheet order |
1174 | 0 | if( mpImplData->mbReversePageOrder ) |
1175 | 0 | { |
1176 | 0 | int nDocPages = getFilteredPageCount(); |
1177 | 0 | i_nFilteredPage = nDocPages - 1 - i_nFilteredPage; |
1178 | 0 | } |
1179 | | |
1180 | | // there is no filtering to be done (and possibly the page size of the |
1181 | | // original page is to be set), when N-Up is "neutral" that is there is |
1182 | | // only one subpage and the margins are 0 |
1183 | 0 | if( nSubPages == 1 && |
1184 | 0 | rMPS.nLeftMargin == 0 && rMPS.nRightMargin == 0 && |
1185 | 0 | rMPS.nTopMargin == 0 && rMPS.nBottomMargin == 0 ) |
1186 | 0 | { |
1187 | 0 | PrinterController::PageSize aPageSize = getPageFile( i_nFilteredPage, o_rMtf, i_bMayUseCache ); |
1188 | 0 | if (mpImplData->meJobState != css::view::PrintableState_JOB_STARTED) |
1189 | 0 | { // rhbz#657394: check that we are still printing... |
1190 | 0 | return PrinterController::PageSize(); |
1191 | 0 | } |
1192 | 0 | Size aPaperSize = mpImplData->getRealPaperSize( aPageSize.aSize, true ); |
1193 | 0 | mpImplData->mxPrinter->SetMapMode( MapMode( MapUnit::Map100thMM ) ); |
1194 | 0 | mpImplData->mxPrinter->SetPaperSizeUser( aPaperSize ); |
1195 | 0 | if( aPaperSize != aPageSize.aSize ) |
1196 | 0 | { |
1197 | | // user overridden page size, center Metafile |
1198 | 0 | o_rMtf.WindStart(); |
1199 | 0 | tools::Long nDX = (aPaperSize.Width() - aPageSize.aSize.Width()) / 2; |
1200 | 0 | tools::Long nDY = (aPaperSize.Height() - aPageSize.aSize.Height()) / 2; |
1201 | | |
1202 | | // if the printout is larger than the paper: instead of centering, start at the top |
1203 | 0 | const bool bHeigher = aPageSize.aSize.Height() > aPaperSize.Height(); |
1204 | 0 | if (aPageSize.bFullPaper && bHeigher) |
1205 | 0 | { |
1206 | | // try to cram as much of the content onto the page as possible |
1207 | 0 | Point aOffset(mpImplData->mxPrinter->GetPageOffset()); |
1208 | 0 | if (aPageSize.aSize.Height() - aPaperSize.Height() > aOffset.Y() * 2) |
1209 | 0 | nDY = -aOffset.Y(); |
1210 | 0 | } |
1211 | |
|
1212 | 0 | o_rMtf.Move( nDX, nDY, mpImplData->mxPrinter->GetDPIX(), mpImplData->mxPrinter->GetDPIY() ); |
1213 | 0 | o_rMtf.WindStart(); |
1214 | 0 | o_rMtf.SetPrefSize( aPaperSize ); |
1215 | 0 | aPageSize.aSize = aPaperSize; |
1216 | 0 | } |
1217 | 0 | return aPageSize; |
1218 | 0 | } |
1219 | | |
1220 | | // set last page property really only on the very last page to be rendered |
1221 | | // that is on the last subpage of a NUp run |
1222 | 0 | bool bIsLastPage = mpImplData->mbLastPage; |
1223 | 0 | mpImplData->mbLastPage = false; |
1224 | |
|
1225 | 0 | Size aPaperSize( mpImplData->getRealPaperSize( mpImplData->maMultiPage.aPaperSize, false ) ); |
1226 | | |
1227 | | // multi page area: page size minus margins + one time spacing right and down |
1228 | | // the added spacing is so each subpage can be calculated including its spacing |
1229 | 0 | Size aMPArea( aPaperSize ); |
1230 | 0 | aMPArea.AdjustWidth( -(rMPS.nLeftMargin + rMPS.nRightMargin) ); |
1231 | 0 | aMPArea.AdjustWidth(rMPS.nHorizontalSpacing ); |
1232 | 0 | aMPArea.AdjustHeight( -(rMPS.nTopMargin + rMPS.nBottomMargin) ); |
1233 | 0 | aMPArea.AdjustHeight(rMPS.nVerticalSpacing ); |
1234 | | |
1235 | | // determine offsets |
1236 | 0 | tools::Long nAdvX = aMPArea.Width() / rMPS.nColumns; |
1237 | 0 | tools::Long nAdvY = aMPArea.Height() / rMPS.nRows; |
1238 | | |
1239 | | // determine size of a "cell" subpage, leave a little space around pages |
1240 | 0 | Size aSubPageSize( nAdvX - rMPS.nHorizontalSpacing, nAdvY - rMPS.nVerticalSpacing ); |
1241 | |
|
1242 | 0 | o_rMtf.Clear(); |
1243 | 0 | o_rMtf.SetPrefSize( aPaperSize ); |
1244 | 0 | o_rMtf.SetPrefMapMode( MapMode( MapUnit::Map100thMM ) ); |
1245 | 0 | o_rMtf.AddAction( new MetaMapModeAction( MapMode( MapUnit::Map100thMM ) ) ); |
1246 | |
|
1247 | 0 | int nDocPages = getPageCountProtected(); |
1248 | 0 | if (mpImplData->meJobState != css::view::PrintableState_JOB_STARTED) |
1249 | 0 | { // rhbz#657394: check that we are still printing... |
1250 | 0 | return PrinterController::PageSize(); |
1251 | 0 | } |
1252 | 0 | for( int nSubPage = 0; nSubPage < nSubPages; nSubPage++ ) |
1253 | 0 | { |
1254 | | // map current sub page to real page |
1255 | 0 | int nPage = i_nFilteredPage * nSubPages + nSubPage; |
1256 | 0 | if( nSubPage == nSubPages-1 || |
1257 | 0 | nPage == nDocPages-1 ) |
1258 | 0 | { |
1259 | 0 | mpImplData->mbLastPage = bIsLastPage; |
1260 | 0 | } |
1261 | 0 | if( nPage >= 0 && nPage < nDocPages ) |
1262 | 0 | { |
1263 | 0 | GDIMetaFile aPageFile; |
1264 | 0 | PrinterController::PageSize aPageSize = getPageFile( nPage, aPageFile, i_bMayUseCache ); |
1265 | 0 | if( aPageSize.aSize.Width() && aPageSize.aSize.Height() ) |
1266 | 0 | { |
1267 | 0 | tools::Long nCellX = 0, nCellY = 0; |
1268 | 0 | switch( rMPS.nOrder ) |
1269 | 0 | { |
1270 | 0 | case NupOrderType::LRTB: |
1271 | 0 | nCellX = (nSubPage % rMPS.nColumns); |
1272 | 0 | nCellY = (nSubPage / rMPS.nColumns); |
1273 | 0 | break; |
1274 | 0 | case NupOrderType::TBLR: |
1275 | 0 | nCellX = (nSubPage / rMPS.nRows); |
1276 | 0 | nCellY = (nSubPage % rMPS.nRows); |
1277 | 0 | break; |
1278 | 0 | case NupOrderType::RLTB: |
1279 | 0 | nCellX = rMPS.nColumns - 1 - (nSubPage % rMPS.nColumns); |
1280 | 0 | nCellY = (nSubPage / rMPS.nColumns); |
1281 | 0 | break; |
1282 | 0 | case NupOrderType::TBRL: |
1283 | 0 | nCellX = rMPS.nColumns - 1 - (nSubPage / rMPS.nRows); |
1284 | 0 | nCellY = (nSubPage % rMPS.nRows); |
1285 | 0 | break; |
1286 | 0 | } |
1287 | | // scale the metafile down to a sub page size |
1288 | 0 | double fScaleX = double(aSubPageSize.Width())/double(aPageSize.aSize.Width()); |
1289 | 0 | double fScaleY = double(aSubPageSize.Height())/double(aPageSize.aSize.Height()); |
1290 | 0 | double fScale = std::min( fScaleX, fScaleY ); |
1291 | 0 | aPageFile.Scale( fScale, fScale ); |
1292 | 0 | aPageFile.WindStart(); |
1293 | | |
1294 | | // move the subpage so it is centered in its "cell" |
1295 | 0 | tools::Long nOffX = (aSubPageSize.Width() - tools::Long(double(aPageSize.aSize.Width()) * fScale)) / 2; |
1296 | 0 | tools::Long nOffY = (aSubPageSize.Height() - tools::Long(double(aPageSize.aSize.Height()) * fScale)) / 2; |
1297 | 0 | tools::Long nX = rMPS.nLeftMargin + nOffX + nAdvX * nCellX; |
1298 | 0 | tools::Long nY = rMPS.nTopMargin + nOffY + nAdvY * nCellY; |
1299 | 0 | aPageFile.Move( nX, nY, mpImplData->mxPrinter->GetDPIX(), mpImplData->mxPrinter->GetDPIY() ); |
1300 | 0 | aPageFile.WindStart(); |
1301 | | // calculate border rectangle |
1302 | 0 | tools::Rectangle aSubPageRect( Point( nX, nY ), |
1303 | 0 | Size( tools::Long(double(aPageSize.aSize.Width())*fScale), |
1304 | 0 | tools::Long(double(aPageSize.aSize.Height())*fScale) ) ); |
1305 | | |
1306 | | // append subpage to page |
1307 | 0 | appendSubPage( o_rMtf, aSubPageRect, aPageFile, rMPS.bDrawBorder ); |
1308 | 0 | } |
1309 | 0 | } |
1310 | 0 | } |
1311 | 0 | o_rMtf.WindStart(); |
1312 | | |
1313 | | // subsequent getPageFile calls have changed the paper, reset it to current value |
1314 | 0 | mpImplData->mxPrinter->SetMapMode( MapMode( MapUnit::Map100thMM ) ); |
1315 | 0 | mpImplData->mxPrinter->SetPaperSizeUser( aPaperSize ); |
1316 | |
|
1317 | 0 | return PrinterController::PageSize( aPaperSize, true ); |
1318 | 0 | } |
1319 | | |
1320 | | int PrinterController::getFilteredPageCount() const |
1321 | 0 | { |
1322 | 0 | int nDiv = mpImplData->maMultiPage.nRows * mpImplData->maMultiPage.nColumns; |
1323 | 0 | if( nDiv < 1 ) |
1324 | 0 | nDiv = 1; |
1325 | 0 | return (getPageCountProtected() + (nDiv-1)) / nDiv; |
1326 | 0 | } |
1327 | | |
1328 | | DrawModeFlags PrinterController::removeTransparencies( GDIMetaFile const & i_rIn, GDIMetaFile& o_rOut ) |
1329 | 0 | { |
1330 | 0 | DrawModeFlags nRestoreDrawMode = mpImplData->mxPrinter->GetDrawMode(); |
1331 | 0 | sal_Int32 nMaxBmpDPIX = mpImplData->mxPrinter->GetDPIX(); |
1332 | 0 | sal_Int32 nMaxBmpDPIY = mpImplData->mxPrinter->GetDPIY(); |
1333 | |
|
1334 | 0 | const vcl::printer::Options& rPrinterOptions = mpImplData->mxPrinter->GetPrinterOptions(); |
1335 | |
|
1336 | 0 | static const sal_Int32 OPTIMAL_BMP_RESOLUTION = 300; |
1337 | 0 | static const sal_Int32 NORMAL_BMP_RESOLUTION = 200; |
1338 | |
|
1339 | 0 | if( rPrinterOptions.IsReduceBitmaps() ) |
1340 | 0 | { |
1341 | | // calculate maximum resolution for bitmap graphics |
1342 | 0 | if( printer::BitmapMode::Optimal == rPrinterOptions.GetReducedBitmapMode() ) |
1343 | 0 | { |
1344 | 0 | nMaxBmpDPIX = std::min( sal_Int32(OPTIMAL_BMP_RESOLUTION), nMaxBmpDPIX ); |
1345 | 0 | nMaxBmpDPIY = std::min( sal_Int32(OPTIMAL_BMP_RESOLUTION), nMaxBmpDPIY ); |
1346 | 0 | } |
1347 | 0 | else if( printer::BitmapMode::Normal == rPrinterOptions.GetReducedBitmapMode() ) |
1348 | 0 | { |
1349 | 0 | nMaxBmpDPIX = std::min( sal_Int32(NORMAL_BMP_RESOLUTION), nMaxBmpDPIX ); |
1350 | 0 | nMaxBmpDPIY = std::min( sal_Int32(NORMAL_BMP_RESOLUTION), nMaxBmpDPIY ); |
1351 | 0 | } |
1352 | 0 | else |
1353 | 0 | { |
1354 | 0 | nMaxBmpDPIX = std::min( sal_Int32(rPrinterOptions.GetReducedBitmapResolution()), nMaxBmpDPIX ); |
1355 | 0 | nMaxBmpDPIY = std::min( sal_Int32(rPrinterOptions.GetReducedBitmapResolution()), nMaxBmpDPIY ); |
1356 | 0 | } |
1357 | 0 | } |
1358 | | |
1359 | | // convert to greyscales |
1360 | 0 | if( rPrinterOptions.IsConvertToGreyscales() ) |
1361 | 0 | { |
1362 | 0 | mpImplData->mxPrinter->SetDrawMode( mpImplData->mxPrinter->GetDrawMode() | |
1363 | 0 | ( DrawModeFlags::GrayLine | DrawModeFlags::GrayFill | DrawModeFlags::GrayText | |
1364 | 0 | DrawModeFlags::GrayBitmap | DrawModeFlags::GrayGradient ) ); |
1365 | 0 | } |
1366 | | |
1367 | | // disable transparency output |
1368 | 0 | if( rPrinterOptions.IsReduceTransparency() && ( vcl::printer::TransparencyMode::NONE == rPrinterOptions.GetReducedTransparencyMode() ) ) |
1369 | 0 | { |
1370 | 0 | mpImplData->mxPrinter->SetDrawMode( mpImplData->mxPrinter->GetDrawMode() | DrawModeFlags::NoTransparency ); |
1371 | 0 | } |
1372 | |
|
1373 | 0 | Color aBg( COL_TRANSPARENT ); // default: let RemoveTransparenciesFromMetaFile do its own background logic |
1374 | 0 | if( mpImplData->maMultiPage.nRows * mpImplData->maMultiPage.nColumns > 1 ) |
1375 | 0 | { |
1376 | | // in N-Up printing we have no "page" background operation |
1377 | | // we also have no way to determine the paper color |
1378 | | // so let's go for white, which will kill 99.9% of the real cases |
1379 | 0 | aBg = COL_WHITE; |
1380 | 0 | } |
1381 | 0 | mpImplData->mxPrinter->RemoveTransparenciesFromMetaFile( i_rIn, o_rOut, nMaxBmpDPIX, nMaxBmpDPIY, |
1382 | 0 | rPrinterOptions.IsReduceTransparency(), |
1383 | 0 | rPrinterOptions.GetReducedTransparencyMode() == vcl::printer::TransparencyMode::Auto, |
1384 | 0 | rPrinterOptions.IsReduceBitmaps() && rPrinterOptions.IsReducedBitmapIncludesTransparency(), |
1385 | 0 | aBg |
1386 | 0 | ); |
1387 | 0 | return nRestoreDrawMode; |
1388 | 0 | } |
1389 | | |
1390 | | void PrinterController::printFilteredPage( int i_nPage ) |
1391 | 0 | { |
1392 | 0 | if( mpImplData->meJobState != css::view::PrintableState_JOB_STARTED ) |
1393 | 0 | return; // rhbz#657394: check that we are still printing... |
1394 | | |
1395 | 0 | GDIMetaFile aPageFile; |
1396 | 0 | PrinterController::PageSize aPageSize = getFilteredPageFile( i_nPage, aPageFile ); |
1397 | |
|
1398 | 0 | if( mpImplData->mxProgress ) |
1399 | 0 | { |
1400 | | // do nothing if printing is canceled |
1401 | 0 | if( mpImplData->mxProgress->isCanceled() ) |
1402 | 0 | { |
1403 | 0 | setJobState( css::view::PrintableState_JOB_ABORTED ); |
1404 | 0 | return; |
1405 | 0 | } |
1406 | 0 | } |
1407 | | |
1408 | | // in N-Up printing set the correct page size |
1409 | 0 | mpImplData->mxPrinter->SetMapMode(MapMode(MapUnit::Map100thMM)); |
1410 | | // aPageSize was filtered through mpImplData->getRealPaperSize already by getFilteredPageFile() |
1411 | 0 | mpImplData->mxPrinter->SetPaperSizeUser( aPageSize.aSize ); |
1412 | 0 | if( mpImplData->mnFixedPaperBin != -1 && |
1413 | 0 | mpImplData->mxPrinter->GetPaperBin() != mpImplData->mnFixedPaperBin ) |
1414 | 0 | { |
1415 | 0 | mpImplData->mxPrinter->SetPaperBin( mpImplData->mnFixedPaperBin ); |
1416 | 0 | } |
1417 | | |
1418 | | // if full paper is meant to be used, move the output to accommodate for pageoffset |
1419 | 0 | if( aPageSize.bFullPaper ) |
1420 | 0 | { |
1421 | 0 | Point aPageOffset( mpImplData->mxPrinter->GetPageOffset() ); |
1422 | 0 | aPageFile.WindStart(); |
1423 | 0 | aPageFile.Move( -aPageOffset.X(), -aPageOffset.Y(), mpImplData->mxPrinter->GetDPIX(), mpImplData->mxPrinter->GetDPIY() ); |
1424 | 0 | } |
1425 | |
|
1426 | 0 | GDIMetaFile aCleanedFile; |
1427 | 0 | DrawModeFlags nRestoreDrawMode = removeTransparencies( aPageFile, aCleanedFile ); |
1428 | |
|
1429 | 0 | mpImplData->mxPrinter->EnableOutput(); |
1430 | | |
1431 | | // actually print the page |
1432 | 0 | mpImplData->mxPrinter->ImplStartPage(); |
1433 | |
|
1434 | 0 | mpImplData->mxPrinter->Push(); |
1435 | 0 | aCleanedFile.WindStart(); |
1436 | 0 | aCleanedFile.Play(*mpImplData->mxPrinter); |
1437 | 0 | mpImplData->mxPrinter->Pop(); |
1438 | |
|
1439 | 0 | mpImplData->mxPrinter->ImplEndPage(); |
1440 | |
|
1441 | 0 | mpImplData->mxPrinter->SetDrawMode( nRestoreDrawMode ); |
1442 | 0 | } |
1443 | | |
1444 | | void PrinterController::jobStarted() |
1445 | 0 | { |
1446 | 0 | } |
1447 | | |
1448 | | void PrinterController::jobFinished( css::view::PrintableState ) |
1449 | 0 | { |
1450 | 0 | } |
1451 | | |
1452 | | void PrinterController::abortJob() |
1453 | 0 | { |
1454 | 0 | setJobState( css::view::PrintableState_JOB_ABORTED ); |
1455 | | // applications (well, sw) depend on a page request with "IsLastPage" = true |
1456 | | // to free resources, else they (well, sw) will crash eventually |
1457 | 0 | setLastPage( true ); |
1458 | |
|
1459 | 0 | if (mpImplData->mxProgress) |
1460 | 0 | { |
1461 | 0 | mpImplData->mxProgress->response(RET_CANCEL); |
1462 | 0 | mpImplData->mxProgress.reset(); |
1463 | 0 | } |
1464 | |
|
1465 | 0 | GDIMetaFile aMtf; |
1466 | 0 | getPageFile( 0, aMtf ); |
1467 | 0 | } |
1468 | | |
1469 | | void PrinterController::setLastPage( bool i_bLastPage ) |
1470 | 0 | { |
1471 | 0 | mpImplData->mbLastPage = i_bLastPage; |
1472 | 0 | } |
1473 | | |
1474 | | void PrinterController::setReversePrint( bool i_bReverse ) |
1475 | 0 | { |
1476 | 0 | mpImplData->mbReversePageOrder = i_bReverse; |
1477 | 0 | } |
1478 | | |
1479 | | void PrinterController::setPapersizeFromSetup( bool i_bPapersizeFromSetup ) |
1480 | 0 | { |
1481 | 0 | mpImplData->mbPapersizeFromSetup = i_bPapersizeFromSetup; |
1482 | 0 | mpImplData->mxPrinter->SetPrinterSettingsPreferred( i_bPapersizeFromSetup ); |
1483 | 0 | if ( i_bPapersizeFromSetup ) |
1484 | 0 | { |
1485 | 0 | mpImplData->mbPapersizeFromUser = false; |
1486 | 0 | mpImplData->mbOrientationFromUser = false; |
1487 | 0 | } |
1488 | 0 | } |
1489 | | |
1490 | | bool PrinterController::getPapersizeFromSetup() const |
1491 | 0 | { |
1492 | 0 | return mpImplData->mbPapersizeFromSetup; |
1493 | 0 | } |
1494 | | |
1495 | | void PrinterController::setPaperSizeFromUser( Size i_aUserSize ) |
1496 | 0 | { |
1497 | 0 | mpImplData->mbPapersizeFromUser = true; |
1498 | 0 | mpImplData->mbPapersizeFromSetup = false; |
1499 | 0 | mpImplData->mxPrinter->SetPrinterSettingsPreferred( false ); |
1500 | |
|
1501 | 0 | mpImplData->maUserPageSize = i_aUserSize; |
1502 | 0 | } |
1503 | | |
1504 | | void PrinterController::setOrientationFromUser( Orientation eOrientation, bool set ) |
1505 | 0 | { |
1506 | 0 | mpImplData->mbOrientationFromUser = set; |
1507 | 0 | mpImplData->meUserOrientation = eOrientation; |
1508 | 0 | } |
1509 | | |
1510 | | void PrinterController::setPrinterModified( bool i_bPrinterModified ) |
1511 | 0 | { |
1512 | 0 | mpImplData->mbPrinterModified = i_bPrinterModified; |
1513 | 0 | } |
1514 | | |
1515 | | bool PrinterController::getPrinterModified() const |
1516 | 0 | { |
1517 | 0 | return mpImplData->mbPrinterModified; |
1518 | 0 | } |
1519 | | |
1520 | | css::uno::Sequence< css::beans::PropertyValue > PrinterController::getJobProperties( const css::uno::Sequence< css::beans::PropertyValue >& i_rMergeList ) const |
1521 | 0 | { |
1522 | 0 | std::unordered_set< OUString > aMergeSet; |
1523 | 0 | size_t nResultLen = size_t(i_rMergeList.getLength()) + mpImplData->maUIProperties.size() + 3; |
1524 | 0 | for( const auto& rPropVal : i_rMergeList ) |
1525 | 0 | aMergeSet.insert( rPropVal.Name ); |
1526 | |
|
1527 | 0 | css::uno::Sequence< css::beans::PropertyValue > aResult( nResultLen ); |
1528 | 0 | auto pResult = aResult.getArray(); |
1529 | 0 | std::copy(i_rMergeList.begin(), i_rMergeList.end(), pResult); |
1530 | 0 | int nCur = i_rMergeList.getLength(); |
1531 | 0 | for(const css::beans::PropertyValue & rPropVal : mpImplData->maUIProperties) |
1532 | 0 | { |
1533 | 0 | if( aMergeSet.find( rPropVal.Name ) == aMergeSet.end() ) |
1534 | 0 | pResult[nCur++] = rPropVal; |
1535 | 0 | } |
1536 | | // append IsFirstPage |
1537 | 0 | if( aMergeSet.find( u"IsFirstPage"_ustr ) == aMergeSet.end() ) |
1538 | 0 | { |
1539 | 0 | css::beans::PropertyValue aVal; |
1540 | 0 | aVal.Name = "IsFirstPage"; |
1541 | 0 | aVal.Value <<= mpImplData->mbFirstPage; |
1542 | 0 | pResult[nCur++] = std::move(aVal); |
1543 | 0 | } |
1544 | | // append IsLastPage |
1545 | 0 | if( aMergeSet.find( u"IsLastPage"_ustr ) == aMergeSet.end() ) |
1546 | 0 | { |
1547 | 0 | css::beans::PropertyValue aVal; |
1548 | 0 | aVal.Name = "IsLastPage"; |
1549 | 0 | aVal.Value <<= mpImplData->mbLastPage; |
1550 | 0 | pResult[nCur++] = std::move(aVal); |
1551 | 0 | } |
1552 | | // append IsPrinter |
1553 | 0 | if( aMergeSet.find( u"IsPrinter"_ustr ) == aMergeSet.end() ) |
1554 | 0 | { |
1555 | 0 | css::beans::PropertyValue aVal; |
1556 | 0 | aVal.Name = "IsPrinter"; |
1557 | 0 | aVal.Value <<= true; |
1558 | 0 | pResult[nCur++] = std::move(aVal); |
1559 | 0 | } |
1560 | 0 | aResult.realloc( nCur ); |
1561 | 0 | return aResult; |
1562 | 0 | } |
1563 | | |
1564 | | const css::uno::Sequence< css::beans::PropertyValue >& PrinterController::getUIOptions() const |
1565 | 0 | { |
1566 | 0 | return mpImplData->maUIOptions; |
1567 | 0 | } |
1568 | | |
1569 | | css::beans::PropertyValue* PrinterController::getValue( const OUString& i_rProperty ) |
1570 | 0 | { |
1571 | 0 | std::unordered_map< OUString, size_t >::const_iterator it = |
1572 | 0 | mpImplData->maPropertyToIndex.find( i_rProperty ); |
1573 | 0 | return it != mpImplData->maPropertyToIndex.end() ? &mpImplData->maUIProperties[it->second] : nullptr; |
1574 | 0 | } |
1575 | | |
1576 | | const css::beans::PropertyValue* PrinterController::getValue( const OUString& i_rProperty ) const |
1577 | 0 | { |
1578 | 0 | std::unordered_map< OUString, size_t >::const_iterator it = |
1579 | 0 | mpImplData->maPropertyToIndex.find( i_rProperty ); |
1580 | 0 | return it != mpImplData->maPropertyToIndex.end() ? &mpImplData->maUIProperties[it->second] : nullptr; |
1581 | 0 | } |
1582 | | |
1583 | | void PrinterController::setValue( const OUString& i_rPropertyName, const css::uno::Any& i_rValue ) |
1584 | 0 | { |
1585 | 0 | css::beans::PropertyValue aVal; |
1586 | 0 | aVal.Name = i_rPropertyName; |
1587 | 0 | aVal.Value = i_rValue; |
1588 | |
|
1589 | 0 | setValue( aVal ); |
1590 | 0 | } |
1591 | | |
1592 | | void PrinterController::setValue( const css::beans::PropertyValue& i_rPropertyValue ) |
1593 | 0 | { |
1594 | 0 | std::unordered_map< OUString, size_t >::const_iterator it = |
1595 | 0 | mpImplData->maPropertyToIndex.find( i_rPropertyValue.Name ); |
1596 | 0 | if( it != mpImplData->maPropertyToIndex.end() ) |
1597 | 0 | mpImplData->maUIProperties[ it->second ] = i_rPropertyValue; |
1598 | 0 | else |
1599 | 0 | { |
1600 | | // insert correct index into property map |
1601 | 0 | mpImplData->maPropertyToIndex[ i_rPropertyValue.Name ] = mpImplData->maUIProperties.size(); |
1602 | 0 | mpImplData->maUIProperties.push_back( i_rPropertyValue ); |
1603 | 0 | mpImplData->maUIPropertyEnabled.push_back( true ); |
1604 | 0 | } |
1605 | 0 | } |
1606 | | |
1607 | | void PrinterController::setUIOptions( const css::uno::Sequence< css::beans::PropertyValue >& i_rOptions ) |
1608 | 0 | { |
1609 | 0 | SAL_WARN_IF( mpImplData->maUIOptions.hasElements(), "vcl.gdi", "setUIOptions called twice !" ); |
1610 | | |
1611 | 0 | mpImplData->maUIOptions = i_rOptions; |
1612 | |
|
1613 | 0 | for( const auto& rOpt : i_rOptions ) |
1614 | 0 | { |
1615 | 0 | css::uno::Sequence< css::beans::PropertyValue > aOptProp; |
1616 | 0 | rOpt.Value >>= aOptProp; |
1617 | 0 | bool bIsEnabled = true; |
1618 | 0 | bool bHaveProperty = false; |
1619 | 0 | OUString aPropName; |
1620 | 0 | vcl::ImplPrinterControllerData::ControlDependency aDep; |
1621 | 0 | css::uno::Sequence< sal_Bool > aChoicesDisabled; |
1622 | 0 | for (const css::beans::PropertyValue& rEntry : aOptProp) |
1623 | 0 | { |
1624 | 0 | if ( rEntry.Name == "Property" ) |
1625 | 0 | { |
1626 | 0 | css::beans::PropertyValue aVal; |
1627 | 0 | rEntry.Value >>= aVal; |
1628 | 0 | DBG_ASSERT( mpImplData->maPropertyToIndex.find( aVal.Name ) |
1629 | 0 | == mpImplData->maPropertyToIndex.end(), "duplicate property entry" ); |
1630 | 0 | setValue( aVal ); |
1631 | 0 | aPropName = aVal.Name; |
1632 | 0 | bHaveProperty = true; |
1633 | 0 | } |
1634 | 0 | else if ( rEntry.Name == "Enabled" ) |
1635 | 0 | { |
1636 | 0 | bool bValue = true; |
1637 | 0 | rEntry.Value >>= bValue; |
1638 | 0 | bIsEnabled = bValue; |
1639 | 0 | } |
1640 | 0 | else if ( rEntry.Name == "DependsOnName" ) |
1641 | 0 | { |
1642 | 0 | rEntry.Value >>= aDep.maDependsOnName; |
1643 | 0 | } |
1644 | 0 | else if ( rEntry.Name == "DependsOnEntry" ) |
1645 | 0 | { |
1646 | 0 | rEntry.Value >>= aDep.mnDependsOnEntry; |
1647 | 0 | } |
1648 | 0 | else if ( rEntry.Name == "ChoicesDisabled" ) |
1649 | 0 | { |
1650 | 0 | rEntry.Value >>= aChoicesDisabled; |
1651 | 0 | } |
1652 | 0 | } |
1653 | 0 | if( bHaveProperty ) |
1654 | 0 | { |
1655 | 0 | vcl::ImplPrinterControllerData::PropertyToIndexMap::const_iterator it = |
1656 | 0 | mpImplData->maPropertyToIndex.find( aPropName ); |
1657 | | // sanity check |
1658 | 0 | if( it != mpImplData->maPropertyToIndex.end() ) |
1659 | 0 | { |
1660 | 0 | mpImplData->maUIPropertyEnabled[ it->second ] = bIsEnabled; |
1661 | 0 | } |
1662 | 0 | if( !aDep.maDependsOnName.isEmpty() ) |
1663 | 0 | mpImplData->maControlDependencies[ aPropName ] = std::move(aDep); |
1664 | 0 | if( aChoicesDisabled.hasElements() ) |
1665 | 0 | mpImplData->maChoiceDisableMap[ aPropName ] = std::move(aChoicesDisabled); |
1666 | 0 | } |
1667 | 0 | } |
1668 | 0 | } |
1669 | | |
1670 | | bool PrinterController::isUIOptionEnabled( const OUString& i_rProperty ) const |
1671 | 0 | { |
1672 | 0 | bool bEnabled = false; |
1673 | 0 | std::unordered_map< OUString, size_t >::const_iterator prop_it = |
1674 | 0 | mpImplData->maPropertyToIndex.find( i_rProperty ); |
1675 | 0 | if( prop_it != mpImplData->maPropertyToIndex.end() ) |
1676 | 0 | { |
1677 | 0 | bEnabled = mpImplData->maUIPropertyEnabled[prop_it->second]; |
1678 | |
|
1679 | 0 | if( bEnabled ) |
1680 | 0 | { |
1681 | | // check control dependencies |
1682 | 0 | vcl::ImplPrinterControllerData::ControlDependencyMap::const_iterator it = |
1683 | 0 | mpImplData->maControlDependencies.find( i_rProperty ); |
1684 | 0 | if( it != mpImplData->maControlDependencies.end() ) |
1685 | 0 | { |
1686 | | // check if the dependency is enabled |
1687 | | // if the dependency is disabled, we are too |
1688 | 0 | bEnabled = isUIOptionEnabled( it->second.maDependsOnName ); |
1689 | |
|
1690 | 0 | if( bEnabled ) |
1691 | 0 | { |
1692 | | // does the dependency have the correct value ? |
1693 | 0 | const css::beans::PropertyValue* pVal = getValue( it->second.maDependsOnName ); |
1694 | 0 | OSL_ENSURE( pVal, "unknown property in dependency" ); |
1695 | 0 | if( pVal ) |
1696 | 0 | { |
1697 | 0 | sal_Int32 nDepVal = 0; |
1698 | 0 | bool bDepVal = false; |
1699 | 0 | if( pVal->Value >>= nDepVal ) |
1700 | 0 | { |
1701 | 0 | bEnabled = (nDepVal == it->second.mnDependsOnEntry) || (it->second.mnDependsOnEntry == -1); |
1702 | 0 | } |
1703 | 0 | else if( pVal->Value >>= bDepVal ) |
1704 | 0 | { |
1705 | | // could be a dependency on a checked boolean |
1706 | | // in this case the dependency is on a non zero for checked value |
1707 | 0 | bEnabled = ( bDepVal && it->second.mnDependsOnEntry != 0) || |
1708 | 0 | ( ! bDepVal && it->second.mnDependsOnEntry == 0); |
1709 | 0 | } |
1710 | 0 | else |
1711 | 0 | { |
1712 | | // if the type does not match something is awry |
1713 | 0 | OSL_FAIL( "strange type in control dependency" ); |
1714 | 0 | bEnabled = false; |
1715 | 0 | } |
1716 | 0 | } |
1717 | 0 | } |
1718 | 0 | } |
1719 | 0 | } |
1720 | 0 | } |
1721 | 0 | return bEnabled; |
1722 | 0 | } |
1723 | | |
1724 | | void PrinterController::setUIChoicesDisabled(const OUString& rPropName, css::uno::Sequence<sal_Bool>& rChoicesDisabled) |
1725 | 0 | { |
1726 | 0 | mpImplData->maChoiceDisableMap[rPropName] = std::move(rChoicesDisabled); |
1727 | 0 | } |
1728 | | |
1729 | | bool PrinterController::isUIChoiceEnabled( const OUString& i_rProperty, sal_Int32 i_nValue ) const |
1730 | 0 | { |
1731 | 0 | bool bEnabled = true; |
1732 | 0 | ImplPrinterControllerData::ChoiceDisableMap::const_iterator it = |
1733 | 0 | mpImplData->maChoiceDisableMap.find( i_rProperty ); |
1734 | 0 | if(it != mpImplData->maChoiceDisableMap.end() ) |
1735 | 0 | { |
1736 | 0 | const css::uno::Sequence< sal_Bool >& rDisabled( it->second ); |
1737 | 0 | if( i_nValue >= 0 && i_nValue < rDisabled.getLength() ) |
1738 | 0 | bEnabled = ! rDisabled[i_nValue]; |
1739 | 0 | } |
1740 | 0 | return bEnabled; |
1741 | 0 | } |
1742 | | |
1743 | | OUString PrinterController::makeEnabled( const OUString& i_rProperty ) |
1744 | 0 | { |
1745 | 0 | OUString aDependency; |
1746 | |
|
1747 | 0 | vcl::ImplPrinterControllerData::ControlDependencyMap::const_iterator it = |
1748 | 0 | mpImplData->maControlDependencies.find( i_rProperty ); |
1749 | 0 | if( it != mpImplData->maControlDependencies.end() ) |
1750 | 0 | { |
1751 | 0 | if( isUIOptionEnabled( it->second.maDependsOnName ) ) |
1752 | 0 | { |
1753 | 0 | aDependency = it->second.maDependsOnName; |
1754 | 0 | const css::beans::PropertyValue* pVal = getValue( aDependency ); |
1755 | 0 | OSL_ENSURE( pVal, "unknown property in dependency" ); |
1756 | 0 | if( pVal ) |
1757 | 0 | { |
1758 | 0 | sal_Int32 nDepVal = 0; |
1759 | 0 | bool bDepVal = false; |
1760 | 0 | if( pVal->Value >>= nDepVal ) |
1761 | 0 | { |
1762 | 0 | if( it->second.mnDependsOnEntry != -1 ) |
1763 | 0 | { |
1764 | 0 | setValue( aDependency, css::uno::Any( sal_Int32( it->second.mnDependsOnEntry ) ) ); |
1765 | 0 | } |
1766 | 0 | } |
1767 | 0 | else if( pVal->Value >>= bDepVal ) |
1768 | 0 | { |
1769 | 0 | setValue( aDependency, css::uno::Any( it->second.mnDependsOnEntry != 0 ) ); |
1770 | 0 | } |
1771 | 0 | else |
1772 | 0 | { |
1773 | | // if the type does not match something is awry |
1774 | 0 | OSL_FAIL( "strange type in control dependency" ); |
1775 | 0 | } |
1776 | 0 | } |
1777 | 0 | } |
1778 | 0 | } |
1779 | |
|
1780 | 0 | return aDependency; |
1781 | 0 | } |
1782 | | |
1783 | | void PrinterController::createProgressDialog() |
1784 | 0 | { |
1785 | 0 | if (!mpImplData->mxProgress) |
1786 | 0 | { |
1787 | 0 | bool bShow = true; |
1788 | 0 | css::beans::PropertyValue* pMonitor = getValue( u"MonitorVisible"_ustr ); |
1789 | 0 | if( pMonitor ) |
1790 | 0 | pMonitor->Value >>= bShow; |
1791 | 0 | else |
1792 | 0 | { |
1793 | 0 | const css::beans::PropertyValue* pVal = getValue( u"IsApi"_ustr ); |
1794 | 0 | if( pVal ) |
1795 | 0 | { |
1796 | 0 | bool bApi = false; |
1797 | 0 | pVal->Value >>= bApi; |
1798 | 0 | bShow = ! bApi; |
1799 | 0 | } |
1800 | 0 | } |
1801 | |
|
1802 | 0 | if( bShow && ! Application::IsHeadlessModeEnabled() ) |
1803 | 0 | { |
1804 | 0 | mpImplData->mxProgress = std::make_shared<PrintProgressDialog>(getWindow(), getPageCountProtected()); |
1805 | 0 | weld::DialogController::runAsync(mpImplData->mxProgress, [](sal_Int32 /*nResult*/){}); |
1806 | 0 | } |
1807 | 0 | } |
1808 | 0 | else |
1809 | 0 | { |
1810 | 0 | mpImplData->mxProgress->response(RET_CANCEL); |
1811 | 0 | mpImplData->mxProgress.reset(); |
1812 | 0 | } |
1813 | 0 | } |
1814 | | |
1815 | | bool PrinterController::isProgressCanceled() const |
1816 | 0 | { |
1817 | 0 | return mpImplData->mxProgress && mpImplData->mxProgress->isCanceled(); |
1818 | 0 | } |
1819 | | |
1820 | | void PrinterController::setMultipage( const MultiPageSetup& i_rMPS ) |
1821 | 0 | { |
1822 | 0 | mpImplData->maMultiPage = i_rMPS; |
1823 | 0 | } |
1824 | | |
1825 | | const PrinterController::MultiPageSetup& PrinterController::getMultipage() const |
1826 | 0 | { |
1827 | 0 | return mpImplData->maMultiPage; |
1828 | 0 | } |
1829 | | |
1830 | | void PrinterController::resetPaperToLastConfigured() |
1831 | 0 | { |
1832 | 0 | mpImplData->resetPaperToLastConfigured(); |
1833 | 0 | } |
1834 | | |
1835 | | void PrinterController::pushPropertiesToPrinter() |
1836 | 0 | { |
1837 | 0 | sal_Int32 nCopyCount = 1; |
1838 | | // set copycount and collate |
1839 | 0 | const css::beans::PropertyValue* pVal = getValue( u"CopyCount"_ustr ); |
1840 | 0 | if( pVal ) |
1841 | 0 | pVal->Value >>= nCopyCount; |
1842 | 0 | bool bCollate = false; |
1843 | 0 | pVal = getValue( u"Collate"_ustr ); |
1844 | 0 | if( pVal ) |
1845 | 0 | pVal->Value >>= bCollate; |
1846 | 0 | mpImplData->mxPrinter->SetCopyCount( static_cast<sal_uInt16>(nCopyCount), bCollate ); |
1847 | |
|
1848 | 0 | pVal = getValue(u"SinglePrintJobs"_ustr); |
1849 | 0 | bool bSinglePrintJobs = false; |
1850 | 0 | if (pVal) |
1851 | 0 | pVal->Value >>= bSinglePrintJobs; |
1852 | 0 | mpImplData->mxPrinter->SetSinglePrintJobs(bSinglePrintJobs); |
1853 | | |
1854 | | // duplex mode |
1855 | 0 | pVal = getValue( u"DuplexMode"_ustr ); |
1856 | 0 | if( pVal ) |
1857 | 0 | { |
1858 | 0 | sal_Int16 nDuplex = css::view::DuplexMode::UNKNOWN; |
1859 | 0 | pVal->Value >>= nDuplex; |
1860 | 0 | switch( nDuplex ) |
1861 | 0 | { |
1862 | 0 | case css::view::DuplexMode::OFF: mpImplData->mxPrinter->SetDuplexMode( DuplexMode::Off ); break; |
1863 | 0 | case css::view::DuplexMode::LONGEDGE: mpImplData->mxPrinter->SetDuplexMode( DuplexMode::LongEdge ); break; |
1864 | 0 | case css::view::DuplexMode::SHORTEDGE: mpImplData->mxPrinter->SetDuplexMode( DuplexMode::ShortEdge ); break; |
1865 | 0 | } |
1866 | 0 | } |
1867 | 0 | } |
1868 | | |
1869 | | bool PrinterController::isShowDialogs() const |
1870 | 0 | { |
1871 | 0 | bool bApi = getBoolProperty( u"IsApi"_ustr, false ); |
1872 | 0 | return ! bApi && ! Application::IsHeadlessModeEnabled(); |
1873 | 0 | } |
1874 | | |
1875 | | bool PrinterController::isDirectPrint() const |
1876 | 0 | { |
1877 | 0 | bool bDirect = getBoolProperty( u"IsDirect"_ustr, false ); |
1878 | 0 | return bDirect; |
1879 | 0 | } |
1880 | | |
1881 | | bool PrinterController::getBoolProperty( const OUString& i_rProperty, bool i_bFallback ) const |
1882 | 0 | { |
1883 | 0 | bool bRet = i_bFallback; |
1884 | 0 | const css::beans::PropertyValue* pVal = getValue( i_rProperty ); |
1885 | 0 | if( pVal ) |
1886 | 0 | pVal->Value >>= bRet; |
1887 | 0 | return bRet; |
1888 | 0 | } |
1889 | | |
1890 | | sal_Int32 PrinterController::getIntProperty( const OUString& i_rProperty, sal_Int32 i_nFallback ) const |
1891 | 0 | { |
1892 | 0 | sal_Int32 nRet = i_nFallback; |
1893 | 0 | const css::beans::PropertyValue* pVal = getValue( i_rProperty ); |
1894 | 0 | if( pVal ) |
1895 | 0 | pVal->Value >>= nRet; |
1896 | 0 | return nRet; |
1897 | 0 | } |
1898 | | |
1899 | | /* |
1900 | | * PrinterOptionsHelper |
1901 | | **/ |
1902 | | css::uno::Any PrinterOptionsHelper::getValue( const OUString& i_rPropertyName ) const |
1903 | 681k | { |
1904 | 681k | css::uno::Any aRet; |
1905 | 681k | std::unordered_map< OUString, css::uno::Any >::const_iterator it = |
1906 | 681k | m_aPropertyMap.find( i_rPropertyName ); |
1907 | 681k | if( it != m_aPropertyMap.end() ) |
1908 | 378k | aRet = it->second; |
1909 | 681k | return aRet; |
1910 | 681k | } |
1911 | | |
1912 | | bool PrinterOptionsHelper::getBoolValue( const OUString& i_rPropertyName, bool i_bDefault ) const |
1913 | 519k | { |
1914 | 519k | bool bRet = false; |
1915 | 519k | css::uno::Any aVal( getValue( i_rPropertyName ) ); |
1916 | 519k | return (aVal >>= bRet) ? bRet : i_bDefault; |
1917 | 519k | } |
1918 | | |
1919 | | sal_Int64 PrinterOptionsHelper::getIntValue( const OUString& i_rPropertyName, sal_Int64 i_nDefault ) const |
1920 | 36.7k | { |
1921 | 36.7k | sal_Int64 nRet = 0; |
1922 | 36.7k | css::uno::Any aVal( getValue( i_rPropertyName ) ); |
1923 | 36.7k | return (aVal >>= nRet) ? nRet : i_nDefault; |
1924 | 36.7k | } |
1925 | | |
1926 | | OUString PrinterOptionsHelper::getStringValue( const OUString& i_rPropertyName ) const |
1927 | 60.5k | { |
1928 | 60.5k | OUString aRet; |
1929 | 60.5k | css::uno::Any aVal( getValue( i_rPropertyName ) ); |
1930 | 60.5k | return (aVal >>= aRet) ? aRet : OUString(); |
1931 | 60.5k | } |
1932 | | |
1933 | | bool PrinterOptionsHelper::processProperties( const css::uno::Sequence< css::beans::PropertyValue >& i_rNewProp ) |
1934 | 124k | { |
1935 | 124k | bool bChanged = false; |
1936 | | |
1937 | 124k | for( const auto& rVal : i_rNewProp ) |
1938 | 1.12M | { |
1939 | 1.12M | std::unordered_map< OUString, css::uno::Any >::iterator it = |
1940 | 1.12M | m_aPropertyMap.find( rVal.Name ); |
1941 | | |
1942 | 1.12M | bool bElementChanged = (it == m_aPropertyMap.end()) || (it->second != rVal.Value); |
1943 | 1.12M | if( bElementChanged ) |
1944 | 38.2k | { |
1945 | 38.2k | m_aPropertyMap[ rVal.Name ] = rVal.Value; |
1946 | 38.2k | bChanged = true; |
1947 | 38.2k | } |
1948 | 1.12M | } |
1949 | 124k | return bChanged; |
1950 | 124k | } |
1951 | | |
1952 | | void PrinterOptionsHelper::appendPrintUIOptions( css::uno::Sequence< css::beans::PropertyValue >& io_rProps ) const |
1953 | 60.5k | { |
1954 | 60.5k | if( !m_aUIProperties.empty() ) |
1955 | 0 | { |
1956 | 0 | sal_Int32 nIndex = io_rProps.getLength(); |
1957 | 0 | io_rProps.realloc( nIndex+1 ); |
1958 | 0 | io_rProps.getArray()[ nIndex ] = comphelper::makePropertyValue( |
1959 | 0 | u"ExtraPrintUIOptions"_ustr, comphelper::containerToSequence(m_aUIProperties)); |
1960 | 0 | } |
1961 | 60.5k | } |
1962 | | |
1963 | | css::uno::Any PrinterOptionsHelper::setUIControlOpt(const css::uno::Sequence< OUString >& i_rIDs, |
1964 | | const OUString& i_rTitle, |
1965 | | const css::uno::Sequence< OUString >& i_rHelpIds, |
1966 | | const OUString& i_rType, |
1967 | | const css::beans::PropertyValue* i_pVal, |
1968 | | const PrinterOptionsHelper::UIControlOptions& i_rControlOptions) |
1969 | 0 | { |
1970 | 0 | sal_Int32 nElements = |
1971 | 0 | 2 // ControlType + ID |
1972 | 0 | + (i_rTitle.isEmpty() ? 0 : 1) // Text |
1973 | 0 | + (i_rHelpIds.hasElements() ? 1 : 0) // HelpId |
1974 | 0 | + (i_pVal ? 1 : 0) // Property |
1975 | 0 | + i_rControlOptions.maAddProps.size() // additional props |
1976 | 0 | + (i_rControlOptions.maGroupHint.isEmpty() ? 0 : 1) // grouping |
1977 | 0 | + (i_rControlOptions.mbInternalOnly ? 1 : 0) // internal hint |
1978 | 0 | + (i_rControlOptions.mbEnabled ? 0 : 1) // enabled |
1979 | 0 | ; |
1980 | 0 | if( !i_rControlOptions.maDependsOnName.isEmpty() ) |
1981 | 0 | { |
1982 | 0 | nElements += 1; |
1983 | 0 | if( i_rControlOptions.mnDependsOnEntry != -1 ) |
1984 | 0 | nElements += 1; |
1985 | 0 | if( i_rControlOptions.mbAttachToDependency ) |
1986 | 0 | nElements += 1; |
1987 | 0 | } |
1988 | |
|
1989 | 0 | css::uno::Sequence< css::beans::PropertyValue > aCtrl( nElements ); |
1990 | 0 | auto pCtrl = aCtrl.getArray(); |
1991 | 0 | sal_Int32 nUsed = 0; |
1992 | 0 | if( !i_rTitle.isEmpty() ) |
1993 | 0 | { |
1994 | 0 | pCtrl[nUsed ].Name = "Text"; |
1995 | 0 | pCtrl[nUsed++].Value <<= i_rTitle; |
1996 | 0 | } |
1997 | 0 | if( i_rHelpIds.hasElements() ) |
1998 | 0 | { |
1999 | 0 | pCtrl[nUsed ].Name = "HelpId"; |
2000 | 0 | pCtrl[nUsed++].Value <<= i_rHelpIds; |
2001 | 0 | } |
2002 | 0 | pCtrl[nUsed ].Name = "ControlType"; |
2003 | 0 | pCtrl[nUsed++].Value <<= i_rType; |
2004 | 0 | pCtrl[nUsed ].Name = "ID"; |
2005 | 0 | pCtrl[nUsed++].Value <<= i_rIDs; |
2006 | 0 | if( i_pVal ) |
2007 | 0 | { |
2008 | 0 | pCtrl[nUsed ].Name = "Property"; |
2009 | 0 | pCtrl[nUsed++].Value <<= *i_pVal; |
2010 | 0 | } |
2011 | 0 | if( !i_rControlOptions.maDependsOnName.isEmpty() ) |
2012 | 0 | { |
2013 | 0 | pCtrl[nUsed ].Name = "DependsOnName"; |
2014 | 0 | pCtrl[nUsed++].Value <<= i_rControlOptions.maDependsOnName; |
2015 | 0 | if( i_rControlOptions.mnDependsOnEntry != -1 ) |
2016 | 0 | { |
2017 | 0 | pCtrl[nUsed ].Name = "DependsOnEntry"; |
2018 | 0 | pCtrl[nUsed++].Value <<= i_rControlOptions.mnDependsOnEntry; |
2019 | 0 | } |
2020 | 0 | if( i_rControlOptions.mbAttachToDependency ) |
2021 | 0 | { |
2022 | 0 | pCtrl[nUsed ].Name = "AttachToDependency"; |
2023 | 0 | pCtrl[nUsed++].Value <<= i_rControlOptions.mbAttachToDependency; |
2024 | 0 | } |
2025 | 0 | } |
2026 | 0 | if( !i_rControlOptions.maGroupHint.isEmpty() ) |
2027 | 0 | { |
2028 | 0 | pCtrl[nUsed ].Name = "GroupingHint"; |
2029 | 0 | pCtrl[nUsed++].Value <<= i_rControlOptions.maGroupHint; |
2030 | 0 | } |
2031 | 0 | if( i_rControlOptions.mbInternalOnly ) |
2032 | 0 | { |
2033 | 0 | pCtrl[nUsed ].Name = "InternalUIOnly"; |
2034 | 0 | pCtrl[nUsed++].Value <<= true; |
2035 | 0 | } |
2036 | 0 | if( ! i_rControlOptions.mbEnabled ) |
2037 | 0 | { |
2038 | 0 | pCtrl[nUsed ].Name = "Enabled"; |
2039 | 0 | pCtrl[nUsed++].Value <<= false; |
2040 | 0 | } |
2041 | |
|
2042 | 0 | sal_Int32 nAddProps = i_rControlOptions.maAddProps.size(); |
2043 | 0 | for( sal_Int32 i = 0; i < nAddProps; i++ ) |
2044 | 0 | pCtrl[ nUsed++ ] = i_rControlOptions.maAddProps[i]; |
2045 | |
|
2046 | 0 | SAL_WARN_IF( nUsed != nElements, "vcl.gdi", "nUsed != nElements, probable heap corruption" ); |
2047 | | |
2048 | 0 | return css::uno::Any( aCtrl ); |
2049 | 0 | } |
2050 | | |
2051 | | css::uno::Any PrinterOptionsHelper::setGroupControlOpt(const OUString& i_rID, |
2052 | | const OUString& i_rTitle, |
2053 | | const OUString& i_rHelpId) |
2054 | 0 | { |
2055 | 0 | css::uno::Sequence< OUString > aHelpId; |
2056 | 0 | if( !i_rHelpId.isEmpty() ) |
2057 | 0 | { |
2058 | 0 | aHelpId.realloc( 1 ); |
2059 | 0 | *aHelpId.getArray() = i_rHelpId; |
2060 | 0 | } |
2061 | 0 | css::uno::Sequence< OUString > aIds { i_rID }; |
2062 | 0 | return setUIControlOpt(aIds, i_rTitle, aHelpId, u"Group"_ustr); |
2063 | 0 | } |
2064 | | |
2065 | | css::uno::Any PrinterOptionsHelper::setSubgroupControlOpt(const OUString& i_rID, |
2066 | | const OUString& i_rTitle, |
2067 | | const OUString& i_rHelpId, |
2068 | | const PrinterOptionsHelper::UIControlOptions& i_rControlOptions) |
2069 | 0 | { |
2070 | 0 | css::uno::Sequence< OUString > aHelpId; |
2071 | 0 | if( !i_rHelpId.isEmpty() ) |
2072 | 0 | { |
2073 | 0 | aHelpId.realloc( 1 ); |
2074 | 0 | *aHelpId.getArray() = i_rHelpId; |
2075 | 0 | } |
2076 | 0 | css::uno::Sequence< OUString > aIds { i_rID }; |
2077 | 0 | return setUIControlOpt(aIds, i_rTitle, aHelpId, u"Subgroup"_ustr, nullptr, i_rControlOptions); |
2078 | 0 | } |
2079 | | |
2080 | | css::uno::Any PrinterOptionsHelper::setBoolControlOpt(const OUString& i_rID, |
2081 | | const OUString& i_rTitle, |
2082 | | const OUString& i_rHelpId, |
2083 | | const OUString& i_rProperty, |
2084 | | bool i_bValue, |
2085 | | const PrinterOptionsHelper::UIControlOptions& i_rControlOptions) |
2086 | 0 | { |
2087 | 0 | css::uno::Sequence< OUString > aHelpId; |
2088 | 0 | if( !i_rHelpId.isEmpty() ) |
2089 | 0 | { |
2090 | 0 | aHelpId.realloc( 1 ); |
2091 | 0 | *aHelpId.getArray() = i_rHelpId; |
2092 | 0 | } |
2093 | 0 | css::beans::PropertyValue aVal; |
2094 | 0 | aVal.Name = i_rProperty; |
2095 | 0 | aVal.Value <<= i_bValue; |
2096 | 0 | css::uno::Sequence< OUString > aIds { i_rID }; |
2097 | 0 | return setUIControlOpt(aIds, i_rTitle, aHelpId, u"Bool"_ustr, &aVal, i_rControlOptions); |
2098 | 0 | } |
2099 | | |
2100 | | css::uno::Any PrinterOptionsHelper::setChoiceRadiosControlOpt(const css::uno::Sequence< OUString >& i_rIDs, |
2101 | | const OUString& i_rTitle, |
2102 | | const css::uno::Sequence< OUString >& i_rHelpId, |
2103 | | const OUString& i_rProperty, |
2104 | | const css::uno::Sequence< OUString >& i_rChoices, |
2105 | | sal_Int32 i_nValue, |
2106 | | const css::uno::Sequence< sal_Bool >& i_rDisabledChoices, |
2107 | | const PrinterOptionsHelper::UIControlOptions& i_rControlOptions) |
2108 | 0 | { |
2109 | 0 | UIControlOptions aOpt( i_rControlOptions ); |
2110 | 0 | sal_Int32 nUsed = aOpt.maAddProps.size(); |
2111 | 0 | aOpt.maAddProps.resize( nUsed + 1 + (i_rDisabledChoices.hasElements() ? 1 : 0) ); |
2112 | 0 | aOpt.maAddProps[nUsed].Name = "Choices"; |
2113 | 0 | aOpt.maAddProps[nUsed].Value <<= i_rChoices; |
2114 | 0 | if( i_rDisabledChoices.hasElements() ) |
2115 | 0 | { |
2116 | 0 | aOpt.maAddProps[nUsed+1].Name = "ChoicesDisabled"; |
2117 | 0 | aOpt.maAddProps[nUsed+1].Value <<= i_rDisabledChoices; |
2118 | 0 | } |
2119 | |
|
2120 | 0 | css::beans::PropertyValue aVal; |
2121 | 0 | aVal.Name = i_rProperty; |
2122 | 0 | aVal.Value <<= i_nValue; |
2123 | 0 | return setUIControlOpt(i_rIDs, i_rTitle, i_rHelpId, u"Radio"_ustr, &aVal, aOpt); |
2124 | 0 | } |
2125 | | |
2126 | | css::uno::Any PrinterOptionsHelper::setChoiceListControlOpt(const OUString& i_rID, |
2127 | | const OUString& i_rTitle, |
2128 | | const css::uno::Sequence< OUString >& i_rHelpId, |
2129 | | const OUString& i_rProperty, |
2130 | | const css::uno::Sequence< OUString >& i_rChoices, |
2131 | | sal_Int32 i_nValue, |
2132 | | const css::uno::Sequence< sal_Bool >& i_rDisabledChoices, |
2133 | | const PrinterOptionsHelper::UIControlOptions& i_rControlOptions) |
2134 | 0 | { |
2135 | 0 | UIControlOptions aOpt( i_rControlOptions ); |
2136 | 0 | sal_Int32 nUsed = aOpt.maAddProps.size(); |
2137 | 0 | aOpt.maAddProps.resize( nUsed + 1 + (i_rDisabledChoices.hasElements() ? 1 : 0) ); |
2138 | 0 | aOpt.maAddProps[nUsed].Name = "Choices"; |
2139 | 0 | aOpt.maAddProps[nUsed].Value <<= i_rChoices; |
2140 | 0 | if( i_rDisabledChoices.hasElements() ) |
2141 | 0 | { |
2142 | 0 | aOpt.maAddProps[nUsed+1].Name = "ChoicesDisabled"; |
2143 | 0 | aOpt.maAddProps[nUsed+1].Value <<= i_rDisabledChoices; |
2144 | 0 | } |
2145 | |
|
2146 | 0 | css::beans::PropertyValue aVal; |
2147 | 0 | aVal.Name = i_rProperty; |
2148 | 0 | aVal.Value <<= i_nValue; |
2149 | 0 | css::uno::Sequence< OUString > aIds { i_rID }; |
2150 | 0 | return setUIControlOpt(aIds, i_rTitle, i_rHelpId, u"List"_ustr, &aVal, aOpt); |
2151 | 0 | } |
2152 | | |
2153 | | css::uno::Any PrinterOptionsHelper::setRangeControlOpt(const OUString& i_rID, |
2154 | | const OUString& i_rTitle, |
2155 | | const OUString& i_rHelpId, |
2156 | | const OUString& i_rProperty, |
2157 | | sal_Int32 i_nValue, |
2158 | | sal_Int32 i_nMinValue, |
2159 | | sal_Int32 i_nMaxValue, |
2160 | | const PrinterOptionsHelper::UIControlOptions& i_rControlOptions) |
2161 | 0 | { |
2162 | 0 | UIControlOptions aOpt( i_rControlOptions ); |
2163 | 0 | if( i_nMaxValue >= i_nMinValue ) |
2164 | 0 | { |
2165 | 0 | sal_Int32 nUsed = aOpt.maAddProps.size(); |
2166 | 0 | aOpt.maAddProps.resize( nUsed + 2 ); |
2167 | 0 | aOpt.maAddProps[nUsed ].Name = "MinValue"; |
2168 | 0 | aOpt.maAddProps[nUsed++].Value <<= i_nMinValue; |
2169 | 0 | aOpt.maAddProps[nUsed ].Name = "MaxValue"; |
2170 | 0 | aOpt.maAddProps[nUsed++].Value <<= i_nMaxValue; |
2171 | 0 | } |
2172 | |
|
2173 | 0 | css::uno::Sequence< OUString > aHelpId; |
2174 | 0 | if( !i_rHelpId.isEmpty() ) |
2175 | 0 | { |
2176 | 0 | aHelpId.realloc( 1 ); |
2177 | 0 | *aHelpId.getArray() = i_rHelpId; |
2178 | 0 | } |
2179 | 0 | css::beans::PropertyValue aVal; |
2180 | 0 | aVal.Name = i_rProperty; |
2181 | 0 | aVal.Value <<= i_nValue; |
2182 | 0 | css::uno::Sequence< OUString > aIds { i_rID }; |
2183 | 0 | return setUIControlOpt(aIds, i_rTitle, aHelpId, u"Range"_ustr, &aVal, aOpt); |
2184 | 0 | } |
2185 | | |
2186 | | css::uno::Any PrinterOptionsHelper::setEditControlOpt(const OUString& i_rID, |
2187 | | const OUString& i_rTitle, |
2188 | | const OUString& i_rHelpId, |
2189 | | const OUString& i_rProperty, |
2190 | | const OUString& i_rValue, |
2191 | | const PrinterOptionsHelper::UIControlOptions& i_rControlOptions) |
2192 | 0 | { |
2193 | 0 | css::uno::Sequence< OUString > aHelpId; |
2194 | 0 | if( !i_rHelpId.isEmpty() ) |
2195 | 0 | { |
2196 | 0 | aHelpId.realloc( 1 ); |
2197 | 0 | *aHelpId.getArray() = i_rHelpId; |
2198 | 0 | } |
2199 | 0 | css::beans::PropertyValue aVal; |
2200 | 0 | aVal.Name = i_rProperty; |
2201 | 0 | aVal.Value <<= i_rValue; |
2202 | 0 | css::uno::Sequence< OUString > aIds { i_rID }; |
2203 | 0 | return setUIControlOpt(aIds, i_rTitle, aHelpId, u"Edit"_ustr, &aVal, i_rControlOptions); |
2204 | 0 | } |
2205 | | |
2206 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |