LCOV - code coverage report
Current view: top level - vcl/source/gdi - print3.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 1 1051 0.1 %
Date: 2014-04-14 Functions: 2 88 2.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10