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 #ifndef INCLUDED_VCL_PRINT_HXX 21 #define INCLUDED_VCL_PRINT_HXX 22 23 #include <rtl/ustring.hxx> 24 #include <i18nutil/paper.hxx> 25 26 #include <vcl/errcode.hxx> 27 #include <vcl/dllapi.h> 28 #include <vcl/outdev.hxx> 29 #include <vcl/prntypes.hxx> 30 #include <vcl/jobset.hxx> 31 32 #include <com/sun/star/beans/PropertyValue.hpp> 33 #include <com/sun/star/uno/Sequence.hxx> 34 #include <com/sun/star/view/PrintableState.hpp> 35 36 #include <memory> 37 #include <unordered_map> 38 39 class GDIMetaFile; 40 class SalInfoPrinter; 41 struct SalPrinterQueueInfo; 42 class SalPrinter; 43 class VirtualDevice; 44 enum class SalPrinterError; 45 46 namespace vcl { 47 class PrinterController; 48 class Window; 49 } 50 51 namespace weld { class Window; } 52 53 enum class PrinterSupport 54 { 55 SetOrientation, 56 SetPaperSize, SetPaper, 57 CollateCopy, 58 SetupDialog 59 }; 60 61 62 class VCL_DLLPUBLIC QueueInfo 63 { 64 friend class Printer; 65 66 private: 67 OUString maPrinterName; 68 OUString maDriver; 69 OUString maLocation; 70 OUString maComment; 71 PrintQueueFlags mnStatus; 72 sal_uInt32 mnJobs; 73 74 public: 75 QueueInfo(); 76 GetPrinterName() const77 const OUString& GetPrinterName() const { return maPrinterName; } GetDriver() const78 const OUString& GetDriver() const { return maDriver; } GetLocation() const79 const OUString& GetLocation() const { return maLocation; } GetComment() const80 const OUString& GetComment() const { return maComment; } GetStatus() const81 PrintQueueFlags GetStatus() const { return mnStatus; } GetJobs() const82 sal_uInt32 GetJobs() const { return mnJobs; } 83 }; 84 85 86 enum class PrinterTransparencyMode 87 { 88 Auto = 0, 89 NONE = 1 90 }; 91 92 93 enum class PrinterGradientMode 94 { 95 Stripes = 0, 96 Color = 1 97 }; 98 99 100 enum class PrinterBitmapMode 101 { 102 Optimal = 0, 103 Normal = 1, 104 Resolution = 2 105 }; 106 107 108 class VCL_DLLPUBLIC PrinterOptions 109 { 110 private: 111 112 bool mbReduceTransparency; 113 PrinterTransparencyMode meReducedTransparencyMode; 114 bool mbReduceGradients; 115 PrinterGradientMode meReducedGradientsMode; 116 sal_uInt16 mnReducedGradientStepCount; 117 bool mbReduceBitmaps; 118 PrinterBitmapMode meReducedBitmapMode; 119 sal_uInt16 mnReducedBitmapResolution; 120 bool mbReducedBitmapsIncludeTransparency; 121 bool mbConvertToGreyscales; 122 bool mbPDFAsStandardPrintJobFormat; 123 124 public: 125 PrinterOptions(); 126 IsReduceTransparency() const127 bool IsReduceTransparency() const { return mbReduceTransparency; } SetReduceTransparency(bool bSet)128 void SetReduceTransparency( bool bSet ) { mbReduceTransparency = bSet; } 129 GetReducedTransparencyMode() const130 PrinterTransparencyMode GetReducedTransparencyMode() const { return meReducedTransparencyMode; } SetReducedTransparencyMode(PrinterTransparencyMode eMode)131 void SetReducedTransparencyMode( PrinterTransparencyMode eMode ) 132 { meReducedTransparencyMode = eMode; } 133 IsReduceGradients() const134 bool IsReduceGradients() const { return mbReduceGradients; } SetReduceGradients(bool bSet)135 void SetReduceGradients( bool bSet ) { mbReduceGradients = bSet; } 136 GetReducedGradientMode() const137 PrinterGradientMode GetReducedGradientMode() const { return meReducedGradientsMode; } SetReducedGradientMode(PrinterGradientMode eMode)138 void SetReducedGradientMode( PrinterGradientMode eMode ) { meReducedGradientsMode = eMode; } 139 GetReducedGradientStepCount() const140 sal_uInt16 GetReducedGradientStepCount() const { return mnReducedGradientStepCount; } SetReducedGradientStepCount(sal_uInt16 nStepCount)141 void SetReducedGradientStepCount( sal_uInt16 nStepCount ) 142 { mnReducedGradientStepCount = nStepCount; } 143 IsReduceBitmaps() const144 bool IsReduceBitmaps() const { return mbReduceBitmaps; } SetReduceBitmaps(bool bSet)145 void SetReduceBitmaps( bool bSet ) { mbReduceBitmaps = bSet; } 146 GetReducedBitmapMode() const147 PrinterBitmapMode GetReducedBitmapMode() const { return meReducedBitmapMode; } SetReducedBitmapMode(PrinterBitmapMode eMode)148 void SetReducedBitmapMode( PrinterBitmapMode eMode ) { meReducedBitmapMode = eMode; } 149 GetReducedBitmapResolution() const150 sal_uInt16 GetReducedBitmapResolution() const { return mnReducedBitmapResolution; } SetReducedBitmapResolution(sal_uInt16 nResolution)151 void SetReducedBitmapResolution( sal_uInt16 nResolution ) 152 { mnReducedBitmapResolution = nResolution; } 153 IsReducedBitmapIncludesTransparency() const154 bool IsReducedBitmapIncludesTransparency() const { return mbReducedBitmapsIncludeTransparency; } SetReducedBitmapIncludesTransparency(bool bSet)155 void SetReducedBitmapIncludesTransparency( bool bSet ) 156 { mbReducedBitmapsIncludeTransparency = bSet; } 157 IsConvertToGreyscales() const158 bool IsConvertToGreyscales() const { return mbConvertToGreyscales; } SetConvertToGreyscales(bool bSet)159 void SetConvertToGreyscales( bool bSet ) { mbConvertToGreyscales = bSet; } 160 IsPDFAsStandardPrintJobFormat() const161 bool IsPDFAsStandardPrintJobFormat() const { return mbPDFAsStandardPrintJobFormat; } SetPDFAsStandardPrintJobFormat(bool bSet)162 void SetPDFAsStandardPrintJobFormat( bool bSet ) { mbPDFAsStandardPrintJobFormat = bSet; } 163 164 /** Read printer options from configuration 165 166 parameter decides whether the set for 167 print "to printer" or "to file" should be read. 168 */ 169 void ReadFromConfig( bool bFile ); 170 }; 171 172 173 class VCL_DLLPUBLIC Printer : public OutputDevice 174 { 175 friend class ::OutputDevice; 176 177 private: 178 SalInfoPrinter* mpInfoPrinter; 179 std::unique_ptr<SalPrinter> mpPrinter; 180 SalGraphics* mpJobGraphics; 181 VclPtr<Printer> mpPrev; 182 VclPtr<Printer> mpNext; 183 VclPtr<VirtualDevice> mpDisplayDev; 184 std::unique_ptr<PrinterOptions> mpPrinterOptions; 185 OUString maPrinterName; 186 OUString maDriver; 187 OUString maPrintFile; 188 JobSetup maJobSetup; 189 Point maPageOffset; 190 Size maPaperSize; 191 ErrCode mnError; 192 sal_uInt16 mnPageQueueSize; 193 sal_uInt16 mnCopyCount; 194 bool mbDefPrinter; 195 bool mbPrinting; 196 bool mbJobActive; 197 bool mbCollateCopy; 198 bool mbPrintFile; 199 bool mbInPrintPage; 200 bool mbNewJobSetup; 201 202 VCL_DLLPRIVATE void ImplInitData(); 203 VCL_DLLPRIVATE void ImplInit( SalPrinterQueueInfo* pInfo ); 204 VCL_DLLPRIVATE void ImplInitDisplay(); 205 VCL_DLLPRIVATE static SalPrinterQueueInfo* 206 ImplGetQueueInfo( const OUString& rPrinterName, const OUString* pDriver ); 207 VCL_DLLPRIVATE void ImplUpdatePageData(); 208 VCL_DLLPRIVATE void ImplUpdateFontList(); 209 VCL_DLLPRIVATE void ImplFindPaperFormatForUserSize( JobSetup&, bool bMatchNearest ); 210 211 VCL_DLLPRIVATE bool StartJob( const OUString& rJobName, std::shared_ptr<vcl::PrinterController> const & ); 212 213 static VCL_DLLPRIVATE ErrCode 214 ImplSalPrinterErrorCodeToVCL( SalPrinterError nError ); 215 216 private: 217 VCL_DLLPRIVATE void EndJob(); 218 Printer( const Printer& rPrinter ) = delete; 219 Printer& operator =( const Printer& rPrinter ) = delete; 220 221 public: 222 VCL_DLLPRIVATE void ImplStartPage(); 223 VCL_DLLPRIVATE void ImplEndPage(); 224 225 protected: 226 virtual bool AcquireGraphics() const override; 227 virtual void ReleaseGraphics( bool bRelease = true ) override; 228 virtual void ImplReleaseFonts() override; 229 230 virtual long GetGradientStepCount( long nMinRect ) override; 231 virtual bool UsePolyPolygonForComplexGradient() override; 232 virtual void ClipAndDrawGradientMetafile ( const Gradient &rGradient, 233 const tools::PolyPolygon &rPolyPoly ) override; 234 ScaleBitmap(Bitmap &,SalTwoRect &)235 void ScaleBitmap ( Bitmap&, SalTwoRect& ) override { }; 236 vcl::Region ClipToDeviceBounds(vcl::Region aRegion) const override; 237 238 public: 239 void DrawGradientEx( OutputDevice* pOut, const tools::Rectangle& rRect, 240 const Gradient& rGradient ); 241 virtual Bitmap GetBitmap( const Point& rSrcPt, const Size& rSize ) const override; 242 243 protected: 244 virtual void DrawDeviceMask( const Bitmap& rMask, const Color& rMaskColor, 245 const Point& rDestPt, const Size& rDestSize, 246 const Point& rSrcPtPixel, const Size& rSrcSizePixel) override; 247 248 bool DrawTransformBitmapExDirect( const basegfx::B2DHomMatrix& aFullTransform, 249 const BitmapEx& rBitmapEx) override; 250 251 bool TransformAndReduceBitmapExToTargetRange( const basegfx::B2DHomMatrix& aFullTransform, 252 basegfx::B2DRange &aVisibleRange, double &fMaximumArea) override; 253 254 void DrawDeviceBitmap( const Point& rDestPt, const Size& rDestSize, 255 const Point& rSrcPtPixel, const Size& rSrcSizePixel, 256 BitmapEx& rBitmapEx ) override; 257 258 virtual void EmulateDrawTransparent( const tools::PolyPolygon& rPolyPoly, 259 sal_uInt16 nTransparencePercent ) override; 260 261 virtual void SetFontOrientation( LogicalFontInstance* const pFontInstance ) const override; 262 263 public: 264 Printer(); 265 Printer( const JobSetup& rJobSetup ); 266 Printer( const QueueInfo& rQueueInfo ); 267 Printer( const OUString& rPrinterName ); 268 virtual ~Printer() override; 269 virtual void dispose() override; 270 271 static const std::vector< OUString >& 272 GetPrinterQueues(); 273 static const QueueInfo* GetQueueInfo( const OUString& rPrinterName, bool bStatusUpdate ); 274 static OUString GetDefaultPrinterName(); 275 GetName() const276 const OUString& GetName() const { return maPrinterName; } GetDriverName() const277 const OUString& GetDriverName() const { return maDriver; } IsDefPrinter() const278 bool IsDefPrinter() const { return mbDefPrinter; } IsDisplayPrinter() const279 bool IsDisplayPrinter() const { return mpDisplayDev != nullptr; } IsValid() const280 bool IsValid() const { return !IsDisplayPrinter(); } 281 282 sal_uInt32 GetCapabilities( PrinterCapType nType ) const; 283 bool HasSupport( PrinterSupport eFeature ) const; 284 285 bool SetJobSetup( const JobSetup& rSetup ); GetJobSetup() const286 const JobSetup& GetJobSetup() const { return maJobSetup; } 287 288 bool Setup(weld::Window* pWindow, 289 PrinterSetupMode eMode = PrinterSetupMode::DocumentGlobal); 290 bool SetPrinterProps( const Printer* pPrinter ); 291 GetBackgroundColor() const292 Color GetBackgroundColor() const override { return COL_WHITE; } GetReadableFontColor(const Color &,const Color &) const293 Color GetReadableFontColor(const Color&, const Color&) const override { return COL_BLACK; } 294 295 /** SetPrinterOptions is used internally only now 296 297 in earlier times it was used only to set the options loaded directly from the configuration 298 in SfxPrinter::InitJob, this is now handled internally 299 should the need arise to set the printer options outside vcl, also a method would have to be devised 300 to not override these again internally 301 */ 302 VCL_DLLPRIVATE void SetPrinterOptions( const PrinterOptions& rOptions ); GetPrinterOptions() const303 const PrinterOptions& GetPrinterOptions() const { return( *mpPrinterOptions ); } 304 305 bool SetOrientation( Orientation eOrient ); 306 Orientation GetOrientation() const; 307 void SetDuplexMode( DuplexMode ); 308 DuplexMode GetDuplexMode() const; 309 310 bool SetPaperBin( sal_uInt16 nPaperBin ); 311 sal_uInt16 GetPaperBin() const; 312 void SetPaper( Paper ePaper ); 313 bool SetPaperSizeUser( const Size& rSize ); 314 bool SetPaperSizeUser( const Size& rSize, bool bMatchNearest ); 315 Paper GetPaper() const; 316 static OUString GetPaperName( Paper ePaper ); 317 318 /** @return Number of available paper formats */ 319 int GetPaperInfoCount() const; 320 321 /** @return Info about paper format nPaper */ 322 const PaperInfo& GetPaperInfo( int nPaper ) const; 323 sal_uInt16 GetPaperBinCount() const; 324 OUString GetPaperBinName( sal_uInt16 nPaperBin ) const; 325 326 bool GetPrinterSettingsPreferred() const; 327 void SetPrinterSettingsPreferred( bool bPaperSizeFromSetup ); 328 GetPaperSizePixel() const329 const Size& GetPaperSizePixel() const { return maPaperSize; } GetPaperSize() const330 Size GetPaperSize() const { return PixelToLogic( maPaperSize ); } 331 Size GetPaperSize( int nPaper ); GetPageOffsetPixel() const332 const Point& GetPageOffsetPixel() const { return maPageOffset; } GetPageOffset() const333 Point GetPageOffset() const { return PixelToLogic( maPageOffset ); } 334 335 void SetCopyCount( sal_uInt16 nCopy, bool bCollate ); GetCopyCount() const336 sal_uInt16 GetCopyCount() const { return mnCopyCount; } IsCollateCopy() const337 bool IsCollateCopy() const { return mbCollateCopy; } 338 IsPrinting() const339 bool IsPrinting() const { return mbPrinting; } 340 IsJobActive() const341 bool IsJobActive() const { return mbJobActive; } 342 343 /** Checks the printer list and updates it necessary 344 345 sends a DataChanged event of type DataChangedEventType::PRINTER if the printer list changed 346 */ 347 static void updatePrinters(); 348 349 /** Execute a print job 350 351 starts a print job asynchronously that is will return 352 */ 353 static void PrintJob( const std::shared_ptr<vcl::PrinterController>& i_pController, 354 const JobSetup& i_rInitSetup ); 355 356 virtual bool HasMirroredGraphics() const override; 357 358 virtual void DrawOutDev( const Point& rDestPt, const Size& rDestSize, 359 const Point& rSrcPt, const Size& rSrcSize ) override; 360 361 virtual void DrawOutDev( const Point& rDestPt, const Size& rDestSize, 362 const Point& rSrcPt, const Size& rSrcSize, 363 const OutputDevice& rOutDev ) override; 364 365 virtual void CopyArea( const Point& rDestPt, const Point& rSrcPt, 366 const Size& rSrcSize, bool bWindowInvalidate = false ) override; 367 368 // These 3 together are more modular PrintJob(), allowing printing more documents as one print job 369 // by repeated calls to ExecutePrintJob(). Used by mailmerge. 370 static bool PreparePrintJob( std::shared_ptr<vcl::PrinterController> i_pController, 371 const JobSetup& i_rInitSetup ); 372 static bool ExecutePrintJob(const std::shared_ptr<vcl::PrinterController>& i_pController); 373 static void FinishPrintJob( const std::shared_ptr<vcl::PrinterController>& i_pController ); 374 375 /** Implementation detail of PrintJob being asynchronous 376 377 not exported, not usable outside vcl 378 */ 379 static void VCL_DLLPRIVATE ImplPrintJob( const std::shared_ptr<vcl::PrinterController>& i_pController, 380 const JobSetup& i_rInitSetup ); 381 }; 382 383 namespace vcl 384 { 385 class ImplPrinterControllerData; 386 387 enum class NupOrderType 388 { 389 LRTB, TBLR, TBRL, RLTB 390 }; 391 392 class VCL_DLLPUBLIC PrinterController 393 { 394 std::unique_ptr<ImplPrinterControllerData> 395 mpImplData; 396 protected: 397 PrinterController(const VclPtr<Printer>&, weld::Window*); 398 public: 399 struct MultiPageSetup 400 { 401 // all metrics in 100th mm 402 int nRows; 403 int nColumns; 404 Size aPaperSize; 405 long nLeftMargin; 406 long nTopMargin; 407 long nRightMargin; 408 long nBottomMargin; 409 long nHorizontalSpacing; 410 long nVerticalSpacing; 411 bool bDrawBorder; 412 NupOrderType nOrder; 413 MultiPageSetupvcl::PrinterController::MultiPageSetup414 MultiPageSetup() 415 : nRows( 1 ), nColumns( 1 ), aPaperSize( 21000, 29700 ) 416 , nLeftMargin( 0 ), nTopMargin( 0 ) 417 , nRightMargin( 0 ), nBottomMargin( 0 ) 418 , nHorizontalSpacing( 0 ), nVerticalSpacing( 0 ) 419 , bDrawBorder( false ) 420 , nOrder( NupOrderType::LRTB ) {} 421 }; 422 423 struct PageSize 424 { 425 /// In 100th mm 426 Size aSize; 427 428 /// Full paper, not only imageable area is printed 429 bool bFullPaper; 430 PageSizevcl::PrinterController::PageSize431 PageSize( const Size& i_rSize = Size( 21000, 29700 ), 432 bool i_bFullPaper = false) 433 : aSize( i_rSize ), bFullPaper( i_bFullPaper ) {} 434 }; 435 436 virtual ~PrinterController(); 437 438 const VclPtr<Printer>& getPrinter() const; 439 weld::Window* getWindow() const; 440 441 /** For implementations: get current job properties as changed by e.g. print dialog 442 443 this gets the current set of properties initially told to Printer::PrintJob 444 445 For convenience a second sequence will be merged in to get a combined sequence. 446 In case of duplicate property names, the value of i_MergeList wins. 447 */ 448 css::uno::Sequence< css::beans::PropertyValue > 449 getJobProperties(const css::uno::Sequence< css::beans::PropertyValue >& i_rMergeList ) const; 450 451 /// Get the PropertyValue of a Property 452 css::beans::PropertyValue* getValue( const OUString& i_rPropertyName ); 453 const css::beans::PropertyValue* getValue( const OUString& i_rPropertyName ) const; 454 455 /** Get a bool property 456 457 in case the property is unknown or not convertible to bool, i_bFallback is returned 458 */ 459 bool getBoolProperty( const OUString& i_rPropertyName, bool i_bFallback ) const; 460 461 /** Get an int property 462 463 in case the property is unknown or not convertible to bool, i_nFallback is returned 464 */ 465 sal_Int32 getIntProperty( const OUString& i_rPropertyName, sal_Int32 i_nFallback ) const; 466 467 /// Set a property value - can also be used to add another UI property 468 void setValue( const OUString& i_rPropertyName, const css::uno::Any& i_rValue ); 469 void setValue( const css::beans::PropertyValue& i_rValue ); 470 471 /** @return The currently active UI options. These are the same that were passed to setUIOptions. */ 472 const css::uno::Sequence< css::beans::PropertyValue >& 473 getUIOptions() const; 474 475 /** Set possible UI options. 476 477 should only be done once before passing the PrinterListener to Printer::PrintJob 478 */ 479 void setUIOptions( const css::uno::Sequence< css::beans::PropertyValue >& ); 480 481 /// Enable/disable an option; this can be used to implement dialog logic. 482 bool isUIOptionEnabled( const OUString& rPropName ) const; 483 bool isUIChoiceEnabled( const OUString& rPropName, sal_Int32 nChoice ) const; 484 485 /** MakeEnabled will change the property rPropName depends on to the value 486 487 that makes rPropName enabled. If the dependency itself is also disabled, 488 no action will be performed. 489 490 @return The property name rPropName depends on or an empty string if no change was made. 491 */ 492 OUString makeEnabled( const OUString& rPropName ); 493 494 /// App must override this 495 virtual int getPageCount() const = 0; 496 497 /** Get the page parameters 498 499 namely the jobsetup that should be active for the page 500 (describing among others the physical page size) and the "page size". In writer 501 case this would probably be the same as the JobSetup since writer sets the page size 502 draw/impress for example print their page on the paper set on the printer, 503 possibly adjusting the page size to fit. That means the page size can be different from 504 the paper size. 505 506 App must override this 507 508 @return Page size in 1/100th mm 509 */ 510 virtual css::uno::Sequence< css::beans::PropertyValue > 511 getPageParameters( int i_nPage ) const = 0; 512 /// App must override this 513 virtual void printPage(int i_nPage) const = 0; 514 515 /// Will be called after a possible dialog has been shown and the real printjob starts 516 virtual void jobStarted(); 517 virtual void jobFinished( css::view::PrintableState ); 518 519 css::view::PrintableState getJobState() const; 520 521 void abortJob(); 522 523 bool isShowDialogs() const; 524 bool isDirectPrint() const; 525 526 // implementation details, not usable outside vcl 527 // don't use outside vcl. Some of these are exported for 528 // the benefit of vcl's plugins. 529 // Still: DO NOT USE OUTSIDE VCL 530 int getFilteredPageCount() const; 531 VCL_DLLPRIVATE PageSize getPageFile( int i_inUnfilteredPage, GDIMetaFile& rMtf, 532 bool i_bMayUseCache = false ); 533 PageSize getFilteredPageFile( int i_nFilteredPage, GDIMetaFile& o_rMtf, 534 bool i_bMayUseCache = false ); 535 void printFilteredPage( int i_nPage ); 536 VCL_DLLPRIVATE void setPrinter( const VclPtr<Printer>& ); 537 void createProgressDialog(); 538 bool isProgressCanceled() const; 539 VCL_DLLPRIVATE void setMultipage( const MultiPageSetup& ); 540 VCL_DLLPRIVATE const MultiPageSetup& 541 getMultipage() const; 542 void setLastPage( bool i_bLastPage ); 543 VCL_DLLPRIVATE void setReversePrint( bool i_bReverse ); 544 VCL_DLLPRIVATE void setPapersizeFromSetup( bool i_bPapersizeFromSetup ); 545 VCL_DLLPRIVATE bool getPapersizeFromSetup() const; 546 VCL_DLLPRIVATE Size& getPaperSizeSetup() const; 547 VCL_DLLPRIVATE void setPaperSizeFromUser( Size i_aUserSize ); 548 VCL_DLLPRIVATE Size& getPaperSizeFromUser() const; 549 VCL_DLLPRIVATE bool isPaperSizeFromUser() const; 550 void setPrinterModified( bool i_bPapersizeFromSetup ); 551 bool getPrinterModified() const; 552 VCL_DLLPRIVATE void pushPropertiesToPrinter(); 553 VCL_DLLPRIVATE void resetPaperToLastConfigured(); 554 void setJobState( css::view::PrintableState ); 555 VCL_DLLPRIVATE void setupPrinter( weld::Window* i_pDlgParent ); 556 557 VCL_DLLPRIVATE int getPageCountProtected() const; 558 VCL_DLLPRIVATE css::uno::Sequence< css::beans::PropertyValue > 559 getPageParametersProtected( int i_nPage ) const; 560 561 VCL_DLLPRIVATE DrawModeFlags removeTransparencies( GDIMetaFile const & i_rIn, GDIMetaFile& o_rOut ); 562 VCL_DLLPRIVATE void resetPrinterOptions( bool i_bFileOutput ); 563 }; 564 565 class VCL_DLLPUBLIC PrinterOptionsHelper 566 { 567 protected: 568 std::unordered_map< OUString, css::uno::Any > 569 m_aPropertyMap; 570 std::vector< css::beans::PropertyValue > 571 m_aUIProperties; 572 573 public: 574 575 /// Create without ui properties PrinterOptionsHelper()576 PrinterOptionsHelper() {} 577 578 /** Process a new set of properties 579 580 merges changed properties and returns "true" if any occurred 581 */ 582 bool processProperties( const css::uno::Sequence< css::beans::PropertyValue >& i_rNewProp ); 583 584 /** Append to a sequence of property values the ui property sequence passed at creation 585 586 as the "ExtraPrintUIOptions" property. if that sequence was empty, no "ExtraPrintUIOptions" property 587 will be appended. 588 */ 589 void appendPrintUIOptions( css::uno::Sequence< css::beans::PropertyValue >& io_rProps ) const; 590 591 /** @return An empty Any for not existing properties */ 592 css::uno::Any getValue( const OUString& i_rPropertyName ) const; 593 594 bool getBoolValue( const OUString& i_rPropertyName, bool i_bDefault ) const; 595 // convenience for fixed strings getBoolValue(const char * i_pPropName,bool i_bDefault=false) const596 bool getBoolValue( const char* i_pPropName, bool i_bDefault = false ) const 597 { return getBoolValue( OUString::createFromAscii( i_pPropName ), i_bDefault ); } 598 599 sal_Int64 getIntValue( const OUString& i_rPropertyName, sal_Int64 i_nDefault ) const; 600 // convenience for fixed strings getIntValue(const char * i_pPropName,sal_Int64 i_nDefault) const601 sal_Int64 getIntValue( const char* i_pPropName, sal_Int64 i_nDefault ) const 602 { return getIntValue( OUString::createFromAscii( i_pPropName ), i_nDefault ); } 603 604 OUString getStringValue( const OUString& i_rPropertyName ) const; 605 // convenience for fixed strings getStringValue(const char * i_pPropName) const606 OUString getStringValue( const char* i_pPropName ) const 607 { return getStringValue( OUString::createFromAscii( i_pPropName ) ); } 608 609 // helper functions for user to create a single control 610 struct UIControlOptions 611 { 612 OUString const maDependsOnName; 613 sal_Int32 const mnDependsOnEntry; 614 bool const mbAttachToDependency; 615 OUString maGroupHint; 616 bool mbInternalOnly; 617 bool mbEnabled; 618 std::vector< css::beans::PropertyValue > 619 maAddProps; 620 UIControlOptionsvcl::PrinterOptionsHelper::UIControlOptions621 UIControlOptions( const OUString& i_rDependsOnName = OUString(), 622 sal_Int32 i_nDependsOnEntry = -1, bool i_bAttachToDependency = false) 623 : maDependsOnName( i_rDependsOnName ) 624 , mnDependsOnEntry( i_nDependsOnEntry ) 625 , mbAttachToDependency( i_bAttachToDependency ) 626 , mbInternalOnly( false ) 627 , mbEnabled( true ) {} 628 }; 629 630 // note: in the following helper functions HelpIds are expected as an OUString 631 // the normal HelpId form is OString (byte string instead of UTF16 string) 632 // this is because the whole interface is base on UNO properties; in fact the structures 633 // are passed over UNO interfaces. UNO does not know a byte string, hence the string is 634 // transported via UTF16 strings. 635 636 /// Show general control 637 static css::uno::Any setUIControlOpt( const css::uno::Sequence< OUString >& i_rIDs, const OUString& i_rTitle, 638 const css::uno::Sequence< OUString >& i_rHelpId, const OUString& i_rType, 639 const css::beans::PropertyValue* i_pValue = nullptr, 640 const UIControlOptions& i_rControlOptions = UIControlOptions()); 641 642 /// Show and set the title of a TagPage of id i_rID 643 static css::uno::Any setGroupControlOpt( const OUString& i_rID, const OUString& i_rTitle, 644 const OUString& i_rHelpId); 645 646 /// Show and set the label of a VclFrame of id i_rID 647 static css::uno::Any setSubgroupControlOpt( const OUString& i_rID, const OUString& i_rTitle, const OUString& i_rHelpId, 648 const UIControlOptions& i_rControlOptions = UIControlOptions()); 649 650 /// Show a bool option as a checkbox 651 static css::uno::Any setBoolControlOpt( const OUString& i_rID, const OUString& i_rTitle, const OUString& i_rHelpId, 652 const OUString& i_rProperty, bool i_bValue, 653 const UIControlOptions& i_rControlOptions = UIControlOptions()); 654 655 /// Show a set of choices in a list box 656 static css::uno::Any setChoiceListControlOpt( const OUString& i_rID, const OUString& i_rTitle, 657 const css::uno::Sequence< OUString >& i_rHelpId, const OUString& i_rProperty, 658 const css::uno::Sequence< OUString >& i_rChoices, sal_Int32 i_nValue, 659 const css::uno::Sequence< sal_Bool >& i_rDisabledChoices = css::uno::Sequence< sal_Bool >(), 660 const UIControlOptions& i_rControlOptions = UIControlOptions()); 661 662 /// Show a set of choices as radio buttons 663 static css::uno::Any setChoiceRadiosControlOpt( const css::uno::Sequence< OUString >& i_rIDs, 664 const OUString& i_rTitle, const css::uno::Sequence< OUString >& i_rHelpId, 665 const OUString& i_rProperty, const css::uno::Sequence< OUString >& i_rChoices, 666 sal_Int32 i_nValue, 667 const css::uno::Sequence< sal_Bool >& i_rDisabledChoices = css::uno::Sequence< sal_Bool >(), 668 const UIControlOptions& i_rControlOptions = UIControlOptions()); 669 670 /** Show an integer range (e.g. a spin field) 671 672 note: max value < min value means do not apply min/max values 673 */ 674 static css::uno::Any setRangeControlOpt( const OUString& i_rID, const OUString& i_rTitle, const OUString& i_rHelpId, 675 const OUString& i_rProperty, sal_Int32 i_nValue, sal_Int32 i_nMinValue, 676 sal_Int32 i_nMaxValue, const UIControlOptions& i_rControlOptions); 677 678 /** Show a string field 679 680 note: max value < min value means do not apply min/max values 681 */ 682 static css::uno::Any setEditControlOpt( const OUString& i_rID, const OUString& i_rTitle, const OUString& i_rHelpId, 683 const OUString& i_rProperty, const OUString& i_rValue, 684 const UIControlOptions& i_rControlOptions); 685 }; // class PrinterOptionsHelper 686 687 } // namespace vcl 688 689 690 #endif // INCLUDED_VCL_PRINT_HXX 691 692 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 693