LCOV - code coverage report
Current view: top level - libreoffice/vcl/source/window - printdlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 1116 0.1 %
Date: 2012-12-27 Functions: 2 84 2.4 %
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 "printdlg.hxx"
      21             : #include "svdata.hxx"
      22             : #include "svids.hrc"
      23             : #include "jobset.h"
      24             : 
      25             : #include "vcl/print.hxx"
      26             : #include "vcl/dialog.hxx"
      27             : #include "vcl/button.hxx"
      28             : #include "vcl/wall.hxx"
      29             : #include "vcl/status.hxx"
      30             : #include "vcl/decoview.hxx"
      31             : #include "vcl/configsettings.hxx"
      32             : #include "vcl/help.hxx"
      33             : #include "vcl/decoview.hxx"
      34             : #include "vcl/layout.hxx"
      35             : #include "vcl/svapp.hxx"
      36             : #include "vcl/unohelp.hxx"
      37             : 
      38             : #include "unotools/localedatawrapper.hxx"
      39             : 
      40             : #include "rtl/strbuf.hxx"
      41             : 
      42             : #include "com/sun/star/lang/XMultiServiceFactory.hpp"
      43             : #include "com/sun/star/container/XNameAccess.hpp"
      44             : #include "com/sun/star/beans/PropertyValue.hpp"
      45             : #include "com/sun/star/awt/Size.hpp"
      46             : 
      47             : using namespace vcl;
      48             : using namespace com::sun::star;
      49             : using namespace com::sun::star::uno;
      50             : using namespace com::sun::star::lang;
      51             : using namespace com::sun::star::container;
      52             : using namespace com::sun::star::beans;
      53             : 
      54           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makePrintPreviewWindow(Window *pParent, VclBuilder::stringmap &)
      55             : {
      56           0 :     return new PrintDialog::PrintPreviewWindow(pParent);
      57             : }
      58             : 
      59           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeShowNupOrderWindow(Window *pParent, VclBuilder::stringmap &)
      60             : {
      61           0 :     return new PrintDialog::ShowNupOrderWindow(pParent);
      62             : }
      63             : 
      64           0 : PrintDialog::PrintPreviewWindow::PrintPreviewWindow( Window* i_pParent )
      65             :     : Window( i_pParent, 0 )
      66             :     , maOrigSize( 10, 10 )
      67             :     , maPageVDev( *this )
      68             :     , maToolTipString(VclResId( SV_PRINT_PRINTPREVIEW_TXT).toString())
      69             :     , mbGreyscale( false )
      70             :     , maHorzDim( this, WB_HORZ | WB_CENTER  )
      71           0 :     , maVertDim( this, WB_VERT | WB_VCENTER )
      72             : {
      73           0 :     SetPaintTransparent( sal_True );
      74           0 :     SetBackground();
      75           0 :     maPageVDev.SetBackground( Color( COL_WHITE ) );
      76           0 :     maHorzDim.Show();
      77           0 :     maVertDim.Show();
      78             : 
      79           0 :     maHorzDim.SetText( String( RTL_CONSTASCII_USTRINGPARAM( "2.0in" ) ) );
      80           0 :     maVertDim.SetText( String( RTL_CONSTASCII_USTRINGPARAM( "2.0in" ) ) );
      81           0 : }
      82             : 
      83           0 : PrintDialog::PrintPreviewWindow::~PrintPreviewWindow()
      84             : {
      85           0 : }
      86             : 
      87           0 : void PrintDialog::PrintPreviewWindow::DataChanged( const DataChangedEvent& i_rDCEvt )
      88             : {
      89             :     // react on settings changed
      90           0 :     if( i_rDCEvt.GetType() == DATACHANGED_SETTINGS )
      91             :     {
      92           0 :         maPageVDev.SetBackground( Color( COL_WHITE ) );
      93             :     }
      94           0 :     Window::DataChanged( i_rDCEvt );
      95           0 : }
      96             : 
      97           0 : void PrintDialog::PrintPreviewWindow::Resize()
      98             : {
      99           0 :     Size aNewSize( GetSizePixel() );
     100           0 :     long nTextHeight = maHorzDim.GetTextHeight();
     101             :     // leave small space for decoration
     102           0 :     aNewSize.Width() -= nTextHeight + 2;
     103           0 :     aNewSize.Height() -= nTextHeight + 2;
     104           0 :     Size aScaledSize;
     105           0 :     double fScale = 1.0;
     106             : 
     107             :     // #i106435# catch corner case of Size(0,0)
     108           0 :     Size aOrigSize( maOrigSize );
     109           0 :     if( aOrigSize.Width() < 1 )
     110           0 :         aOrigSize.Width() = aNewSize.Width();
     111           0 :     if( aOrigSize.Height() < 1 )
     112           0 :         aOrigSize.Height() = aNewSize.Height();
     113           0 :     if( aOrigSize.Width() > aOrigSize.Height() )
     114             :     {
     115           0 :         aScaledSize = Size( aNewSize.Width(), aNewSize.Width() * aOrigSize.Height() / aOrigSize.Width() );
     116           0 :         if( aScaledSize.Height() > aNewSize.Height() )
     117           0 :             fScale = double(aNewSize.Height())/double(aScaledSize.Height());
     118             :     }
     119             :     else
     120             :     {
     121           0 :         aScaledSize = Size( aNewSize.Height() * aOrigSize.Width() / aOrigSize.Height(), aNewSize.Height() );
     122           0 :         if( aScaledSize.Width() > aNewSize.Width() )
     123           0 :             fScale = double(aNewSize.Width())/double(aScaledSize.Width());
     124             :     }
     125           0 :     aScaledSize.Width() = long(aScaledSize.Width()*fScale);
     126           0 :     aScaledSize.Height() = long(aScaledSize.Height()*fScale);
     127             : 
     128           0 :     maPreviewSize = aScaledSize;
     129             : 
     130             :     // #i104784# if we render the page too small then rounding issues result in
     131             :     // layout artifacts looking really bad. So scale the page unto a device that is not
     132             :     // full page size but not too small either. This also results in much better visual
     133             :     // quality of the preview, e.g. when its height approaches the number of text lines
     134             :     // find a good scaling factor
     135           0 :     Size aPreviewMMSize( maPageVDev.PixelToLogic( aScaledSize, MapMode( MAP_100TH_MM ) ) );
     136           0 :     double fZoom = double(maOrigSize.Height())/double(aPreviewMMSize.Height());
     137           0 :     while( fZoom > 10 )
     138             :     {
     139           0 :         aScaledSize.Width() *= 2;
     140           0 :         aScaledSize.Height() *= 2;
     141           0 :         fZoom /= 2.0;
     142             :     }
     143             : 
     144           0 :     maPageVDev.SetOutputSizePixel( aScaledSize, sal_False );
     145             : 
     146             :     // position dimension lines
     147           0 :     Point aRef( nTextHeight + (aNewSize.Width() - maPreviewSize.Width())/2,
     148           0 :                 nTextHeight + (aNewSize.Height() - maPreviewSize.Height())/2 );
     149           0 :     maHorzDim.SetPosSizePixel( Point( aRef.X(), aRef.Y() - nTextHeight ),
     150           0 :                                Size( maPreviewSize.Width(), nTextHeight ) );
     151           0 :     maVertDim.SetPosSizePixel( Point( aRef.X() - nTextHeight, aRef.Y() ),
     152           0 :                                Size( nTextHeight, maPreviewSize.Height() ) );
     153             : 
     154           0 : }
     155             : 
     156           0 : void PrintDialog::PrintPreviewWindow::Paint( const Rectangle& )
     157             : {
     158           0 :     long nTextHeight = maHorzDim.GetTextHeight();
     159           0 :     Size aSize( GetSizePixel() );
     160           0 :     Point aOffset( (aSize.Width()  - maPreviewSize.Width()  + nTextHeight) / 2 ,
     161           0 :                    (aSize.Height() - maPreviewSize.Height() + nTextHeight) / 2 );
     162             : 
     163           0 :     if( !maReplacementString.isEmpty() )
     164             :     {
     165             :         // replacement is active
     166           0 :         Push();
     167           0 :         Font aFont( GetSettings().GetStyleSettings().GetLabelFont() );
     168           0 :         SetZoomedPointFont( aFont );
     169           0 :         Rectangle aTextRect( aOffset + Point( 2, 2 ),
     170           0 :             Size( maPreviewSize.Width() - 4, maPreviewSize.Height() - 4 ) );
     171             :         DrawText( aTextRect, maReplacementString,
     172             :                   TEXT_DRAW_CENTER | TEXT_DRAW_VCENTER | TEXT_DRAW_WORDBREAK | TEXT_DRAW_MULTILINE
     173           0 :                  );
     174           0 :         Pop();
     175             :     }
     176             :     else
     177             :     {
     178           0 :         GDIMetaFile aMtf( maMtf );
     179             : 
     180           0 :         Size aVDevSize( maPageVDev.GetOutputSizePixel() );
     181           0 :         const Size aLogicSize( maPageVDev.PixelToLogic( aVDevSize, MapMode( MAP_100TH_MM ) ) );
     182           0 :         Size aOrigSize( maOrigSize );
     183           0 :         if( aOrigSize.Width() < 1 )
     184           0 :             aOrigSize.Width() = aLogicSize.Width();
     185           0 :         if( aOrigSize.Height() < 1 )
     186           0 :             aOrigSize.Height() = aLogicSize.Height();
     187           0 :         double fScale = double(aLogicSize.Width())/double(aOrigSize.Width());
     188             : 
     189             : 
     190           0 :         maPageVDev.Erase();
     191           0 :         maPageVDev.Push();
     192           0 :         maPageVDev.SetMapMode( MAP_100TH_MM );
     193           0 :         sal_uLong nOldDrawMode = maPageVDev.GetDrawMode();
     194           0 :         if( mbGreyscale )
     195           0 :             maPageVDev.SetDrawMode( maPageVDev.GetDrawMode() |
     196             :                                     ( DRAWMODE_GRAYLINE | DRAWMODE_GRAYFILL | DRAWMODE_GRAYTEXT |
     197           0 :                                       DRAWMODE_GRAYBITMAP | DRAWMODE_GRAYGRADIENT ) );
     198           0 :         aMtf.WindStart();
     199           0 :         aMtf.Scale( fScale, fScale );
     200           0 :         aMtf.WindStart();
     201           0 :         aMtf.Play( &maPageVDev, Point( 0, 0 ), aLogicSize );
     202           0 :         maPageVDev.Pop();
     203             : 
     204           0 :         SetMapMode( MAP_PIXEL );
     205           0 :         maPageVDev.SetMapMode( MAP_PIXEL );
     206           0 :         DrawOutDev( aOffset, maPreviewSize, Point( 0, 0 ), aVDevSize, maPageVDev );
     207           0 :         maPageVDev.SetDrawMode( nOldDrawMode );
     208             :     }
     209             : 
     210           0 :     Rectangle aFrameRect( aOffset + Point( -1, -1 ),
     211           0 :         Size( maPreviewSize.Width() + 2, maPreviewSize.Height() + 2 ) );
     212           0 :     DecorationView aVw( this );
     213           0 :     aVw.DrawFrame( aFrameRect, FRAME_DRAW_GROUP );
     214           0 : }
     215             : 
     216           0 : void PrintDialog::PrintPreviewWindow::Command( const CommandEvent& rEvt )
     217             : {
     218           0 :     if( rEvt.GetCommand() == COMMAND_WHEEL )
     219             :     {
     220           0 :         const CommandWheelData* pWheelData = rEvt.GetWheelData();
     221           0 :         PrintDialog* pDlg = dynamic_cast<PrintDialog*>(GetParent());
     222           0 :         if( pDlg )
     223             :         {
     224           0 :             if( pWheelData->GetDelta() > 0 )
     225           0 :                 pDlg->previewForward();
     226           0 :             else if( pWheelData->GetDelta() < 0 )
     227           0 :                 pDlg->previewBackward();
     228             :             /*
     229             :             else
     230             :                 huh ?
     231             :             */
     232             :         }
     233             :     }
     234           0 : }
     235             : 
     236           0 : void PrintDialog::PrintPreviewWindow::setPreview( const GDIMetaFile& i_rNewPreview,
     237             :                                                   const Size& i_rOrigSize,
     238             :                                                   const rtl::OUString& i_rPaperName,
     239             :                                                   const rtl::OUString& i_rReplacement,
     240             :                                                   sal_Int32 i_nDPIX,
     241             :                                                   sal_Int32 i_nDPIY,
     242             :                                                   bool i_bGreyscale
     243             :                                                  )
     244             : {
     245           0 :     rtl::OUStringBuffer aBuf( 256 );
     246           0 :     aBuf.append( maToolTipString );
     247           0 :     SetQuickHelpText( aBuf.makeStringAndClear() );
     248           0 :     maMtf = i_rNewPreview;
     249             : 
     250           0 :     maOrigSize = i_rOrigSize;
     251           0 :     maReplacementString = i_rReplacement;
     252           0 :     mbGreyscale = i_bGreyscale;
     253           0 :     maPageVDev.SetReferenceDevice( i_nDPIX, i_nDPIY );
     254           0 :     maPageVDev.EnableOutput( sal_True );
     255             : 
     256             :     // use correct measurements
     257           0 :     const LocaleDataWrapper& rLocWrap( GetSettings().GetLocaleDataWrapper() );
     258           0 :     MapUnit eUnit = MAP_MM;
     259           0 :     int nDigits = 0;
     260           0 :     if( rLocWrap.getMeasurementSystemEnum() == MEASURE_US )
     261             :     {
     262           0 :         eUnit = MAP_100TH_INCH;
     263           0 :         nDigits = 2;
     264             :     }
     265           0 :     Size aLogicPaperSize( LogicToLogic( i_rOrigSize, MapMode( MAP_100TH_MM ), MapMode( eUnit ) ) );
     266           0 :     String aNumText( rLocWrap.getNum( aLogicPaperSize.Width(), nDigits ) );
     267           0 :     aBuf.append( aNumText );
     268           0 :     aBuf.appendAscii( eUnit == MAP_MM ? "mm" : "in" );
     269           0 :     if( !i_rPaperName.isEmpty() )
     270             :     {
     271           0 :         aBuf.appendAscii( " (" );
     272           0 :         aBuf.append( i_rPaperName );
     273           0 :         aBuf.append( sal_Unicode(')') );
     274             :     }
     275           0 :     maHorzDim.SetText( aBuf.makeStringAndClear() );
     276             : 
     277           0 :     aNumText = rLocWrap.getNum( aLogicPaperSize.Height(), nDigits );
     278           0 :     aBuf.append( aNumText );
     279           0 :     aBuf.appendAscii( eUnit == MAP_MM ? "mm" : "in" );
     280           0 :     maVertDim.SetText( aBuf.makeStringAndClear() );
     281             : 
     282           0 :     Resize();
     283           0 :     Invalidate();
     284           0 : }
     285             : 
     286           0 : PrintDialog::ShowNupOrderWindow::ShowNupOrderWindow( Window* i_pParent )
     287             :     : Window( i_pParent, WB_NOBORDER )
     288             :     , mnOrderMode( 0 )
     289             :     , mnRows( 1 )
     290           0 :     , mnColumns( 1 )
     291             : {
     292           0 :     ImplInitSettings();
     293           0 : }
     294             : 
     295           0 : PrintDialog::ShowNupOrderWindow::~ShowNupOrderWindow()
     296             : {
     297           0 : }
     298             : 
     299           0 : void PrintDialog::ShowNupOrderWindow::ImplInitSettings()
     300             : {
     301           0 :     SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetFieldColor() ) );
     302           0 : }
     303             : 
     304           0 : Size PrintDialog::ShowNupOrderWindow::GetOptimalSize(WindowSizeType) const
     305             : {
     306           0 :     return Size(70, 70);
     307             : }
     308             : 
     309           0 : void PrintDialog::ShowNupOrderWindow::Paint( const Rectangle& i_rRect )
     310             : {
     311           0 :     Window::Paint( i_rRect );
     312           0 :     SetMapMode( MAP_PIXEL );
     313           0 :     SetTextColor( GetSettings().GetStyleSettings().GetFieldTextColor() );
     314             : 
     315           0 :     int nPages = mnRows * mnColumns;
     316           0 :     Font aFont( GetSettings().GetStyleSettings().GetFieldFont() );
     317           0 :     aFont.SetSize( Size( 0, 24 ) );
     318           0 :     SetFont( aFont );
     319           0 :     Size aSampleTextSize( GetTextWidth( rtl::OUString::valueOf( sal_Int32(nPages+1) ) ), GetTextHeight() );
     320             : 
     321           0 :     Size aOutSize( GetOutputSizePixel() );
     322           0 :     Size aSubSize( aOutSize.Width() / mnColumns, aOutSize.Height() / mnRows );
     323             :     // calculate font size: shrink the sample text so it fits
     324           0 :     double fX = double(aSubSize.Width())/double(aSampleTextSize.Width());
     325           0 :     double fY = double(aSubSize.Height())/double(aSampleTextSize.Height());
     326           0 :     double fScale = (fX < fY) ? fX : fY;
     327           0 :     long nFontHeight = long(24.0*fScale) - 3;
     328           0 :     if( nFontHeight < 5 )
     329           0 :         nFontHeight = 5;
     330           0 :     aFont.SetSize( Size( 0, nFontHeight ) );
     331           0 :     SetFont( aFont );
     332           0 :     long nTextHeight = GetTextHeight();
     333           0 :     for( int i = 0; i < nPages; i++ )
     334             :     {
     335           0 :         rtl::OUString aPageText( rtl::OUString::valueOf( sal_Int32(i+1) ) );
     336           0 :         int nX = 0, nY = 0;
     337           0 :         switch( mnOrderMode )
     338             :         {
     339             :         case SV_PRINT_PRT_NUP_ORDER_LRTB:
     340           0 :             nX = (i % mnColumns); nY = (i / mnColumns);
     341           0 :             break;
     342             :         case SV_PRINT_PRT_NUP_ORDER_TBLR:
     343           0 :             nX = (i / mnRows); nY = (i % mnRows);
     344           0 :             break;
     345             :         case SV_PRINT_PRT_NUP_ORDER_RLTB:
     346           0 :             nX = mnColumns - 1 - (i % mnColumns); nY = (i / mnColumns);
     347           0 :             break;
     348             :         case SV_PRINT_PRT_NUP_ORDER_TBRL:
     349           0 :             nX = mnColumns - 1 - (i / mnRows); nY = (i % mnRows);
     350           0 :             break;
     351             :         }
     352           0 :         Size aTextSize( GetTextWidth( aPageText ), nTextHeight );
     353           0 :         int nDeltaX = (aSubSize.Width() - aTextSize.Width()) / 2;
     354           0 :         int nDeltaY = (aSubSize.Height() - aTextSize.Height()) / 2;
     355           0 :         DrawText( Point( nX * aSubSize.Width() + nDeltaX,
     356           0 :                          nY * aSubSize.Height() + nDeltaY ),
     357           0 :                   aPageText );
     358           0 :     }
     359           0 :     DecorationView aVw( this );
     360           0 :     aVw.DrawFrame( Rectangle( Point( 0, 0), aOutSize ), FRAME_DRAW_GROUP );
     361           0 : }
     362             : 
     363           0 : PrintDialog::NUpTabPage::NUpTabPage( VclBuilder *pUIBuilder )
     364             : {
     365           0 :     pUIBuilder->get(mpPagesBtn, "pagespersheetbtn");
     366           0 :     pUIBuilder->get(mpBrochureBtn, "brochure");
     367           0 :     pUIBuilder->get(mpPagesBoxTitleTxt, "pagespersheettxt");
     368           0 :     pUIBuilder->get(mpNupPagesBox, "paperspersheetlb");
     369           0 :     pUIBuilder->get(mpNupNumPagesTxt, "pagestxt");
     370           0 :     pUIBuilder->get(mpNupColEdt, "pagecols");
     371           0 :     pUIBuilder->get(mpNupTimesTxt, "by");
     372           0 :     pUIBuilder->get(mpNupRowsEdt, "pagerows");
     373           0 :     pUIBuilder->get(mpPageMarginTxt1, "pagemargintxt1");
     374           0 :     pUIBuilder->get(mpPageMarginEdt, "pagemarginsb");
     375           0 :     pUIBuilder->get(mpPageMarginTxt2, "pagemargintxt2");
     376           0 :     pUIBuilder->get(mpSheetMarginTxt1, "sheetmargintxt1");
     377           0 :     pUIBuilder->get(mpSheetMarginEdt, "sheetmarginsb");
     378           0 :     pUIBuilder->get(mpSheetMarginTxt2, "sheetmargintxt2");
     379           0 :     pUIBuilder->get(mpNupOrientationTxt, "orientationtxt");
     380           0 :     pUIBuilder->get(mpNupOrientationBox, "orientationlb");
     381           0 :     pUIBuilder->get(mpNupOrderTxt, "ordertxt");
     382           0 :     pUIBuilder->get(mpNupOrderBox, "orderlb");
     383           0 :     pUIBuilder->get(mpNupOrderWin, "orderpreview");
     384           0 :     pUIBuilder->get(mpBorderCB, "bordercb");
     385           0 : }
     386             : 
     387           0 : void PrintDialog::NUpTabPage::enableNupControls( bool bEnable )
     388             : {
     389           0 :     mpNupPagesBox->Enable( bEnable );
     390           0 :     mpNupNumPagesTxt->Enable( bEnable );
     391           0 :     mpNupColEdt->Enable( bEnable );
     392           0 :     mpNupTimesTxt->Enable( bEnable );
     393           0 :     mpNupRowsEdt->Enable( bEnable );
     394           0 :     mpPageMarginTxt1->Enable( bEnable );
     395           0 :     mpPageMarginEdt->Enable( bEnable );
     396           0 :     mpPageMarginTxt2->Enable( bEnable );
     397           0 :     mpSheetMarginTxt1->Enable( bEnable );
     398           0 :     mpSheetMarginEdt->Enable( bEnable );
     399           0 :     mpSheetMarginTxt2->Enable( bEnable );
     400           0 :     mpNupOrientationTxt->Enable( bEnable );
     401           0 :     mpNupOrientationBox->Enable( bEnable );
     402           0 :     mpNupOrderTxt->Enable( bEnable );
     403           0 :     mpNupOrderBox->Enable( bEnable );
     404           0 :     mpNupOrderWin->Enable( bEnable );
     405           0 :     mpBorderCB->Enable( bEnable );
     406           0 : }
     407             : 
     408           0 : void PrintDialog::NUpTabPage::showAdvancedControls( bool i_bShow )
     409             : {
     410           0 :     mpNupNumPagesTxt->Show( i_bShow );
     411           0 :     mpNupColEdt->Show( i_bShow );
     412           0 :     mpNupTimesTxt->Show( i_bShow );
     413           0 :     mpNupRowsEdt->Show( i_bShow );
     414           0 :     mpPageMarginTxt1->Show( i_bShow );
     415           0 :     mpPageMarginEdt->Show( i_bShow );
     416           0 :     mpPageMarginTxt2->Show( i_bShow );
     417           0 :     mpSheetMarginTxt1->Show( i_bShow );
     418           0 :     mpSheetMarginEdt->Show( i_bShow );
     419           0 :     mpSheetMarginTxt2->Show( i_bShow );
     420           0 :     mpNupOrientationTxt->Show( i_bShow );
     421           0 :     mpNupOrientationBox->Show( i_bShow );
     422           0 : }
     423             : 
     424           0 : void PrintDialog::NUpTabPage::initFromMultiPageSetup( const vcl::PrinterController::MultiPageSetup& i_rMPS )
     425             : {
     426           0 :     mpNupOrderWin->Show();
     427           0 :     mpPagesBtn->Check( sal_True );
     428           0 :     mpBrochureBtn->Show( sal_False );
     429             : 
     430             :     // setup field units for metric fields
     431           0 :     const LocaleDataWrapper& rLocWrap( mpPageMarginEdt->GetLocaleDataWrapper() );
     432           0 :     FieldUnit eUnit = FUNIT_MM;
     433           0 :     sal_uInt16 nDigits = 0;
     434           0 :     if( rLocWrap.getMeasurementSystemEnum() == MEASURE_US )
     435             :     {
     436           0 :         eUnit = FUNIT_INCH;
     437           0 :         nDigits = 2;
     438             :     }
     439             :     // set units
     440           0 :     mpPageMarginEdt->SetUnit( eUnit );
     441           0 :     mpSheetMarginEdt->SetUnit( eUnit );
     442             : 
     443             :     // set precision
     444           0 :     mpPageMarginEdt->SetDecimalDigits( nDigits );
     445           0 :     mpSheetMarginEdt->SetDecimalDigits( nDigits );
     446             : 
     447           0 :     mpSheetMarginEdt->SetValue( mpSheetMarginEdt->Normalize( i_rMPS.nLeftMargin ), FUNIT_100TH_MM );
     448           0 :     mpPageMarginEdt->SetValue( mpPageMarginEdt->Normalize( i_rMPS.nHorizontalSpacing ), FUNIT_100TH_MM );
     449           0 :     mpBorderCB->Check( i_rMPS.bDrawBorder );
     450           0 :     mpNupRowsEdt->SetValue( i_rMPS.nRows );
     451           0 :     mpNupColEdt->SetValue( i_rMPS.nColumns );
     452           0 :     for( sal_uInt16 i = 0; i < mpNupOrderBox->GetEntryCount(); i++ )
     453             :     {
     454           0 :         if( int(sal_IntPtr(mpNupOrderBox->GetEntryData( i ))) == i_rMPS.nOrder )
     455           0 :             mpNupOrderBox->SelectEntryPos( i );
     456             :     }
     457           0 :     if( i_rMPS.nRows != 1 || i_rMPS.nColumns != 1 )
     458             :     {
     459           0 :         mpNupPagesBox->SelectEntryPos( mpNupPagesBox->GetEntryCount()-1 );
     460           0 :         showAdvancedControls( true );
     461           0 :         mpNupOrderWin->setValues( i_rMPS.nOrder, i_rMPS.nColumns, i_rMPS.nRows );
     462             :     }
     463           0 : }
     464             : 
     465           0 : void PrintDialog::NUpTabPage::readFromSettings()
     466             : {
     467           0 : }
     468             : 
     469           0 : void PrintDialog::NUpTabPage::storeToSettings()
     470             : {
     471           0 : }
     472             : 
     473           0 : PrintDialog::JobTabPage::JobTabPage( VclBuilder* pUIBuilder )
     474             :     : maCollateImg( VclResId( SV_PRINT_COLLATE_IMG ) )
     475             :     , maNoCollateImg( VclResId( SV_PRINT_NOCOLLATE_IMG ) )
     476           0 :     , mnCollateUIMode( 0 )
     477             : {
     478           0 :     pUIBuilder->get(mpPrinters, "printers");
     479           0 :     mpPrinters->SetStyle(mpPrinters->GetStyle() | WB_SORT);
     480           0 :     pUIBuilder->get(mpStatusTxt, "status");
     481           0 :     pUIBuilder->get(mpLocationTxt, "location");
     482           0 :     pUIBuilder->get(mpCommentTxt, "comment");
     483           0 :     pUIBuilder->get(mpSetupButton, "setup");
     484           0 :     pUIBuilder->get(mpCopySpacer, "copyspacer");
     485           0 :     pUIBuilder->get(mpCopyCountField, "copycount");
     486           0 :     pUIBuilder->get(mpCollateBox, "collate");
     487           0 :     pUIBuilder->get(mpCollateImage, "collateimage");
     488           0 :     pUIBuilder->get(mpReverseOrderBox, "reverseorder");
     489             :     // HACK: this is not a dropdown box, but the dropdown line count
     490             :     // sets the results of GetOptimalSize in a normal ListBox
     491           0 :     mpPrinters->SetDropDownLineCount( 4 );
     492           0 : }
     493             : 
     494           0 : void PrintDialog::JobTabPage::readFromSettings()
     495             : {
     496           0 :     SettingsConfigItem* pItem = SettingsConfigItem::get();
     497           0 :     rtl::OUString aValue;
     498             : 
     499             :     aValue = pItem->getValue( rtl::OUString( "PrintDialog"  ),
     500           0 :                               rtl::OUString( "CollateBox"  ) );
     501           0 :     if( aValue.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("alwaysoff")) )
     502             :     {
     503           0 :         mnCollateUIMode = 1;
     504           0 :         mpCollateBox->Check( sal_False );
     505           0 :         mpCollateBox->Enable( sal_False );
     506             :     }
     507             :     else
     508             :     {
     509           0 :         mnCollateUIMode = 0;
     510             :         aValue = pItem->getValue( rtl::OUString( "PrintDialog"  ),
     511           0 :                                   rtl::OUString( "Collate"  ) );
     512           0 :         mpCollateBox->Check( aValue.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("true")) );
     513           0 :     }
     514           0 : }
     515             : 
     516           0 : void PrintDialog::JobTabPage::storeToSettings()
     517             : {
     518           0 :     SettingsConfigItem* pItem = SettingsConfigItem::get();
     519             :     pItem->setValue( rtl::OUString( "PrintDialog"  ),
     520             :                      rtl::OUString( "CopyCount"  ),
     521           0 :                      mpCopyCountField->GetText() );
     522             :     pItem->setValue( rtl::OUString( "PrintDialog"  ),
     523             :                      rtl::OUString( "Collate"  ),
     524           0 :                      mpCollateBox->IsChecked() ? rtl::OUString("true") :
     525           0 :                                                  rtl::OUString("false") );
     526           0 : }
     527             : 
     528           0 : PrintDialog::OutputOptPage::OutputOptPage( VclBuilder *pUIBuilder )
     529             : {
     530           0 :     pUIBuilder->get(mpToFileBox, "printtofile");
     531           0 :     pUIBuilder->get(mpCollateSingleJobsBox, "singleprintjob");
     532           0 : }
     533             : 
     534           0 : void PrintDialog::OutputOptPage::readFromSettings()
     535             : {
     536           0 :     SettingsConfigItem* pItem = SettingsConfigItem::get();
     537           0 :     rtl::OUString aValue;
     538             :     aValue = pItem->getValue( rtl::OUString( "PrintDialog"  ),
     539           0 :                               rtl::OUString( "CollateSingleJobs"  ) );
     540           0 :     if ( aValue.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("true")) )
     541             :     {
     542           0 :         mpCollateSingleJobsBox->Check( sal_True );
     543             :     }
     544             :     else
     545             :     {
     546           0 :         mpCollateSingleJobsBox->Check( sal_False );
     547           0 :     }
     548           0 : }
     549             : 
     550           0 : void PrintDialog::OutputOptPage::storeToSettings()
     551             : {
     552           0 :     SettingsConfigItem* pItem = SettingsConfigItem::get();
     553             :     pItem->setValue( rtl::OUString( "PrintDialog"  ),
     554             :                      rtl::OUString( "ToFile"  ),
     555           0 :                      mpToFileBox->IsChecked() ? rtl::OUString("true")
     556           0 :                                              : rtl::OUString("false") );
     557             :     pItem->setValue( rtl::OUString( "PrintDialog"  ),
     558             :                      rtl::OUString( "CollateSingleJobs"  ),
     559           0 :                      mpCollateSingleJobsBox->IsChecked() ? rtl::OUString("true") :
     560           0 :                                                 rtl::OUString("false") );
     561           0 : }
     562             : 
     563           0 : PrintDialog::PrintDialog( Window* i_pParent, const boost::shared_ptr<PrinterController>& i_rController )
     564             :     : ModalDialog(i_pParent, "PrintDialog", "vcl/ui/printdialog.ui")
     565             :     , mpCustomOptionsUIBuilder(NULL)
     566             :     , maPController( i_rController )
     567             :     , maNUpPage(m_pUIBuilder)
     568             :     , maJobPage(m_pUIBuilder)
     569             :     , maOptionsPage(m_pUIBuilder)
     570             :     , maNoPageStr( VclResId( SV_PRINT_NOPAGES ).toString() )
     571             :     , mnCurPage( 0 )
     572             :     , mnCachedPages( 0 )
     573             :     , maPrintToFileText( VclResId( SV_PRINT_TOFILE_TXT ).toString() )
     574             :     , maDefPrtText( VclResId( SV_PRINT_DEFPRT_TXT ).toString() )
     575           0 :     , mbShowLayoutPage( sal_True )
     576             : {
     577           0 :     get(mpOKButton, "ok");
     578           0 :     get(mpCancelButton, "cancel");
     579           0 :     get(mpHelpButton, "help");
     580           0 :     get(mpForwardBtn, "forward");
     581           0 :     get(mpBackwardBtn, "backward");
     582           0 :     get(mpNumPagesText, "totalnumpages");
     583           0 :     get(mpPageEdit, "pageedit-nospin");
     584           0 :     get(mpTabCtrl, "tabcontrol");
     585           0 :     get(mpPreviewWindow, "preview");
     586             : 
     587             :     // save printbutton text, gets exchanged occasionally with print to file
     588           0 :     maPrintText = mpOKButton->GetText();
     589             : 
     590             :     // setup preview controls
     591           0 :     mpForwardBtn->SetStyle( mpForwardBtn->GetStyle() | WB_BEVELBUTTON );
     592           0 :     mpBackwardBtn->SetStyle( mpBackwardBtn->GetStyle() | WB_BEVELBUTTON );
     593             : 
     594           0 :     maPageStr = mpNumPagesText->GetText();
     595             : 
     596             :     // init reverse print
     597           0 :     maJobPage.mpReverseOrderBox->Check( maPController->getReversePrint() );
     598             : 
     599             :     // fill printer listbox
     600           0 :     const std::vector< rtl::OUString >& rQueues( Printer::GetPrinterQueues() );
     601           0 :     for( std::vector< rtl::OUString >::const_iterator it = rQueues.begin();
     602           0 :          it != rQueues.end(); ++it )
     603             :     {
     604           0 :         maJobPage.mpPrinters->InsertEntry( *it );
     605             :     }
     606             :     // select current printer
     607           0 :     if( maJobPage.mpPrinters->GetEntryPos( maPController->getPrinter()->GetName() ) != LISTBOX_ENTRY_NOTFOUND )
     608             :     {
     609           0 :         maJobPage.mpPrinters->SelectEntry( maPController->getPrinter()->GetName() );
     610             :     }
     611             :     else
     612             :     {
     613             :         // fall back to last printer
     614           0 :         SettingsConfigItem* pItem = SettingsConfigItem::get();
     615             :         String aValue( pItem->getValue( rtl::OUString( "PrintDialog"  ),
     616           0 :                                         rtl::OUString( "LastPrinter"  ) ) );
     617           0 :         if( maJobPage.mpPrinters->GetEntryPos( aValue ) != LISTBOX_ENTRY_NOTFOUND )
     618             :         {
     619           0 :             maJobPage.mpPrinters->SelectEntry( aValue );
     620           0 :             maPController->setPrinter( boost::shared_ptr<Printer>( new Printer( aValue ) ) );
     621             :         }
     622             :         else
     623             :         {
     624             :             // fall back to default printer
     625           0 :             maJobPage.mpPrinters->SelectEntry( Printer::GetDefaultPrinterName() );
     626           0 :             maPController->setPrinter( boost::shared_ptr<Printer>( new Printer( Printer::GetDefaultPrinterName() ) ) );
     627           0 :         }
     628             :     }
     629             :     // not printing to file
     630           0 :     maPController->resetPrinterOptions( false );
     631             : 
     632             :     // get the first page
     633           0 :     preparePreview( true, true );
     634             : 
     635             :     // update the text fields for the printer
     636           0 :     updatePrinterText();
     637             : 
     638             :     // set a select handler
     639           0 :     maJobPage.mpPrinters->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) );
     640             : 
     641             :     // setup sizes for N-Up
     642           0 :     Size aNupSize( maPController->getPrinter()->PixelToLogic(
     643           0 :                          maPController->getPrinter()->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) ) );
     644           0 :     if( maPController->getPrinter()->GetOrientation() == ORIENTATION_LANDSCAPE )
     645             :     {
     646           0 :         maNupLandscapeSize = aNupSize;
     647           0 :         maNupPortraitSize = Size( aNupSize.Height(), aNupSize.Width() );
     648             :     }
     649             :     else
     650             :     {
     651           0 :         maNupPortraitSize = aNupSize;
     652           0 :         maNupLandscapeSize = Size( aNupSize.Height(), aNupSize.Width() );
     653             :     }
     654           0 :     maNUpPage.initFromMultiPageSetup( maPController->getMultipage() );
     655             : 
     656             :     // setup click handler on the various buttons
     657           0 :     mpOKButton->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
     658             :     #if OSL_DEBUG_LEVEL > 1
     659             :     mpCancelButton->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
     660             :     #endif
     661           0 :     mpHelpButton->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
     662           0 :     mpForwardBtn->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
     663           0 :     mpBackwardBtn->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
     664             : 
     665           0 :     maJobPage.mpCollateBox->SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
     666           0 :     maJobPage.mpSetupButton->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
     667           0 :     maNUpPage.mpBorderCB->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
     668           0 :     maOptionsPage.mpToFileBox->SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
     669           0 :     maJobPage.mpReverseOrderBox->SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
     670           0 :     maOptionsPage.mpCollateSingleJobsBox->SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
     671           0 :     maNUpPage.mpPagesBtn->SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
     672             :     // setup modify hdl
     673           0 :     mpPageEdit->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
     674           0 :     maJobPage.mpCopyCountField->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
     675           0 :     maNUpPage.mpNupRowsEdt->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
     676           0 :     maNUpPage.mpNupColEdt->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
     677           0 :     maNUpPage.mpPageMarginEdt->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
     678           0 :     maNUpPage.mpSheetMarginEdt->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
     679             : 
     680             :     // setup select hdl
     681           0 :     maNUpPage.mpNupPagesBox->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) );
     682           0 :     maNUpPage.mpNupOrientationBox->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) );
     683           0 :     maNUpPage.mpNupOrderBox->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) );
     684             : 
     685             :     // setup optional UI options set by application
     686           0 :     setupOptionalUI();
     687             : 
     688             :     // set change handler for UI options
     689           0 :     maPController->setOptionChangeHdl( LINK( this, PrintDialog, UIOptionsChanged ) );
     690             : 
     691             :     // remove layout page if unwanted
     692           0 :     if (!mbShowLayoutPage)
     693           0 :         mpTabCtrl->RemovePage(mpTabCtrl->GetPageId(2));
     694             : 
     695             :     // restore settings from last run
     696           0 :     readFromSettings();
     697             : 
     698             :     // setup dependencies
     699           0 :     checkControlDependencies();
     700             : 
     701           0 :     if ( maPController->getBoolProperty( rtl::OUString( "HideHelpButton" ), sal_False ) )
     702           0 :         mpHelpButton->Hide();
     703             :     // set initial focus to "Number of copies"
     704           0 :     maJobPage.mpCopyCountField->GrabFocus();
     705           0 :     maJobPage.mpCopyCountField->SetSelection( Selection(0, 0xFFFF) );
     706             : 
     707           0 :     updateNupFromPages();
     708           0 : }
     709             : 
     710           0 : PrintDialog::~PrintDialog()
     711             : {
     712           0 :     delete mpCustomOptionsUIBuilder;
     713           0 : }
     714             : 
     715           0 : void PrintDialog::readFromSettings()
     716             : {
     717           0 :     maJobPage.readFromSettings();
     718           0 :     maNUpPage.readFromSettings();
     719           0 :     maOptionsPage.readFromSettings();
     720             : 
     721             :     // read last selected tab page; if it exists, actiavte it
     722           0 :     SettingsConfigItem* pItem = SettingsConfigItem::get();
     723             :     rtl::OUString aValue = pItem->getValue( rtl::OUString( "PrintDialog"  ),
     724           0 :                                             rtl::OUString( "LastPage"  ) );
     725           0 :     sal_uInt16 nCount = mpTabCtrl->GetPageCount();
     726           0 :     for( sal_uInt16 i = 0; i < nCount; i++ )
     727             :     {
     728           0 :         sal_uInt16 nPageId = mpTabCtrl->GetPageId( i );
     729           0 :         if( aValue.equals( mpTabCtrl->GetPageText( nPageId ) ) )
     730             :         {
     731           0 :             mpTabCtrl->SelectTabPage( nPageId );
     732           0 :             break;
     733             :         }
     734             :     }
     735           0 :     mpOKButton->SetText( maOptionsPage.mpToFileBox->IsChecked() ? maPrintToFileText : maPrintText );
     736             : 
     737             :     // persistent window state
     738             :     rtl::OUString aWinState( pItem->getValue( rtl::OUString( "PrintDialog"  ),
     739           0 :                                               rtl::OUString( "WindowState"  ) ) );
     740           0 :     if( !aWinState.isEmpty() )
     741           0 :         SetWindowState( rtl::OUStringToOString( aWinState, RTL_TEXTENCODING_UTF8 ) );
     742             : 
     743           0 :     if( maOptionsPage.mpToFileBox->IsChecked() )
     744             :     {
     745           0 :         maPController->resetPrinterOptions( true );
     746           0 :         preparePreview( true, true );
     747           0 :     }
     748           0 : }
     749             : 
     750           0 : void PrintDialog::storeToSettings()
     751             : {
     752           0 :     maJobPage.storeToSettings();
     753           0 :     maNUpPage.storeToSettings();
     754           0 :     maOptionsPage.storeToSettings();
     755             : 
     756             :     // store last selected printer
     757           0 :     SettingsConfigItem* pItem = SettingsConfigItem::get();
     758             :     pItem->setValue( rtl::OUString( "PrintDialog"  ),
     759             :                      rtl::OUString( "LastPrinter"  ),
     760           0 :                      maJobPage.mpPrinters->GetSelectEntry() );
     761             : 
     762             :     pItem->setValue( rtl::OUString( "PrintDialog"  ),
     763             :                      rtl::OUString( "LastPage"  ),
     764           0 :                      mpTabCtrl->GetPageText( mpTabCtrl->GetCurPageId() ) );
     765             :     pItem->setValue( rtl::OUString( "PrintDialog"  ),
     766             :                      rtl::OUString( "WindowState"  ),
     767             :                      rtl::OStringToOUString( GetWindowState(), RTL_TEXTENCODING_UTF8 )
     768           0 :                      );
     769           0 :     pItem->Commit();
     770           0 : }
     771             : 
     772           0 : bool PrintDialog::isPrintToFile()
     773             : {
     774           0 :     return maOptionsPage.mpToFileBox->IsChecked();
     775             : }
     776             : 
     777           0 : bool PrintDialog::isCollate()
     778             : {
     779           0 :     return maJobPage.mpCopyCountField->GetValue() > 1 ? maJobPage.mpCollateBox->IsChecked() : sal_False;
     780             : }
     781             : 
     782           0 : bool PrintDialog::isSingleJobs()
     783             : {
     784           0 :     return maOptionsPage.mpCollateSingleJobsBox->IsChecked();
     785             : }
     786             : 
     787           0 : void setHelpId( Window* i_pWindow, const Sequence< rtl::OUString >& i_rHelpIds, sal_Int32 i_nIndex )
     788             : {
     789           0 :     if( i_nIndex >= 0 && i_nIndex < i_rHelpIds.getLength() )
     790           0 :         i_pWindow->SetHelpId( rtl::OUStringToOString( i_rHelpIds.getConstArray()[i_nIndex], RTL_TEXTENCODING_UTF8 ) );
     791           0 : }
     792             : 
     793           0 : static void setHelpText( Window* i_pWindow, const Sequence< rtl::OUString >& i_rHelpTexts, sal_Int32 i_nIndex )
     794             : {
     795             :     // without a help text set and the correct smartID,
     796             :     // help texts will be retrieved from the online help system
     797           0 :     if( i_nIndex >= 0 && i_nIndex < i_rHelpTexts.getLength() )
     798           0 :         i_pWindow->SetHelpText( i_rHelpTexts.getConstArray()[i_nIndex] );
     799           0 : }
     800             : 
     801           0 : void PrintDialog::setupOptionalUI()
     802             : {
     803           0 :     const Sequence< PropertyValue >& rOptions( maPController->getUIOptions() );
     804           0 :     for( int i = 0; i < rOptions.getLength(); i++ )
     805             :     {
     806           0 :         if (rOptions[i].Name == "OptionsUIFile")
     807             :         {
     808           0 :             rtl::OUString sOptionsUIFile;
     809           0 :             rOptions[i].Value >>= sOptionsUIFile;
     810             : 
     811           0 :             Window *pCustom = get<Window>("customcontents");
     812             : 
     813           0 :             delete mpCustomOptionsUIBuilder;
     814           0 :             mpCustomOptionsUIBuilder = new VclBuilder(pCustom, getUIRootDir(), sOptionsUIFile);
     815           0 :             Window *pWindow = mpCustomOptionsUIBuilder->get_widget_root();
     816           0 :             pWindow->Show();
     817           0 :             continue;
     818             :         }
     819             : 
     820           0 :         Sequence< beans::PropertyValue > aOptProp;
     821           0 :         rOptions[i].Value >>= aOptProp;
     822             : 
     823             :         // extract ui element
     824           0 :         rtl::OUString aCtrlType;
     825           0 :         rtl::OString aID;
     826           0 :         rtl::OUString aText;
     827           0 :         rtl::OUString aPropertyName;
     828           0 :         Sequence< rtl::OUString > aChoices;
     829           0 :         Sequence< sal_Bool > aChoicesDisabled;
     830           0 :         Sequence< rtl::OUString > aHelpTexts;
     831           0 :         Sequence< rtl::OUString > aIDs;
     832           0 :         Sequence< rtl::OUString > aHelpIds;
     833           0 :         sal_Int64 nMinValue = 0, nMaxValue = 0;
     834           0 :         rtl::OUString aGroupingHint;
     835           0 :         rtl::OUString aDependsOnName;
     836           0 :         sal_Int32 nDependsOnValue = 0;
     837           0 :         sal_Bool bUseDependencyRow = sal_False;
     838             : 
     839           0 :         for( int n = 0; n < aOptProp.getLength(); n++ )
     840             :         {
     841           0 :             const beans::PropertyValue& rEntry( aOptProp[ n ] );
     842           0 :             if ( rEntry.Name == "ID" )
     843             :             {
     844           0 :                 rEntry.Value >>= aIDs;
     845           0 :                 aID = rtl::OUStringToOString(aIDs[0], RTL_TEXTENCODING_UTF8);
     846             :             }
     847           0 :             if ( rEntry.Name == "Text" )
     848             :             {
     849           0 :                 rEntry.Value >>= aText;
     850             :             }
     851           0 :             else if ( rEntry.Name == "ControlType" )
     852             :             {
     853           0 :                 rEntry.Value >>= aCtrlType;
     854             :             }
     855           0 :             else if ( rEntry.Name == "Choices" )
     856             :             {
     857           0 :                 rEntry.Value >>= aChoices;
     858             :             }
     859           0 :             else if ( rEntry.Name == "ChoicesDisabled" )
     860             :             {
     861           0 :                 rEntry.Value >>= aChoicesDisabled;
     862             :             }
     863           0 :             else if ( rEntry.Name == "Property" )
     864             :             {
     865           0 :                 PropertyValue aVal;
     866           0 :                 rEntry.Value >>= aVal;
     867           0 :                 aPropertyName = aVal.Name;
     868             :             }
     869           0 :             else if ( rEntry.Name == "Enabled" )
     870             :             {
     871           0 :                 sal_Bool bValue = sal_True;
     872           0 :                 rEntry.Value >>= bValue;
     873             :             }
     874           0 :             else if ( rEntry.Name == "GroupingHint" )
     875             :             {
     876           0 :                 rEntry.Value >>= aGroupingHint;
     877             :             }
     878           0 :             else if ( rEntry.Name == "DependsOnName" )
     879             :             {
     880           0 :                 rEntry.Value >>= aDependsOnName;
     881             :             }
     882           0 :             else if ( rEntry.Name == "DependsOnEntry" )
     883             :             {
     884           0 :                 rEntry.Value >>= nDependsOnValue;
     885             :             }
     886           0 :             else if ( rEntry.Name == "AttachToDependency" )
     887             :             {
     888           0 :                 rEntry.Value >>= bUseDependencyRow;
     889             :             }
     890           0 :             else if ( rEntry.Name == "MinValue" )
     891             :             {
     892           0 :                 rEntry.Value >>= nMinValue;
     893             :             }
     894           0 :             else if ( rEntry.Name == "MaxValue" )
     895             :             {
     896           0 :                 rEntry.Value >>= nMaxValue;
     897             :             }
     898           0 :             else if ( rEntry.Name == "HelpText" )
     899             :             {
     900           0 :                 if( ! (rEntry.Value >>= aHelpTexts) )
     901             :                 {
     902           0 :                     rtl::OUString aHelpText;
     903           0 :                     if( (rEntry.Value >>= aHelpText) )
     904             :                     {
     905           0 :                         aHelpTexts.realloc( 1 );
     906           0 :                         *aHelpTexts.getArray() = aHelpText;
     907           0 :                     }
     908             :                 }
     909             :             }
     910           0 :             else if ( rEntry.Name == "HelpId" )
     911             :             {
     912           0 :                 if( ! (rEntry.Value >>= aHelpIds ) )
     913             :                 {
     914           0 :                     rtl::OUString aHelpId;
     915           0 :                     if( (rEntry.Value >>= aHelpId) )
     916             :                     {
     917           0 :                         aHelpIds.realloc( 1 );
     918           0 :                         *aHelpIds.getArray() = aHelpId;
     919           0 :                     }
     920             :                 }
     921             :             }
     922           0 :             else if ( rEntry.Name == "HintNoLayoutPage" )
     923             :             {
     924           0 :                 sal_Bool bNoLayoutPage = sal_False;
     925           0 :                 rEntry.Value >>= bNoLayoutPage;
     926           0 :                 mbShowLayoutPage = ! bNoLayoutPage;
     927             :             }
     928             :         }
     929             : 
     930           0 :         if (aCtrlType == "Group" && !aID.isEmpty())
     931             :         {
     932           0 :             TabPage *pPage = get<TabPage>(aID);
     933           0 :             if (!pPage && mpCustomOptionsUIBuilder)
     934           0 :                 pPage = mpCustomOptionsUIBuilder->get<TabPage>(aID);
     935           0 :             sal_uInt16 nPageId = mpTabCtrl->GetPageId(*pPage);
     936             : 
     937           0 :             mpTabCtrl->SetPageText(nPageId, aText);
     938             : 
     939             :             // set help id
     940           0 :             if (aHelpIds.getLength() > 0)
     941           0 :                 mpTabCtrl->SetHelpId(nPageId, rtl::OUStringToOString(aHelpIds.getConstArray()[0], RTL_TEXTENCODING_UTF8));
     942             : 
     943             :             // set help text
     944           0 :             if (aHelpTexts.getLength() > 0)
     945           0 :                 mpTabCtrl->SetHelpText(nPageId, aHelpTexts.getConstArray()[0]);
     946             : 
     947           0 :             pPage->Show();
     948             :         }
     949           0 :         else if (aCtrlType == "Subgroup" && !aID.isEmpty())
     950             :         {
     951           0 :             Window *pFrame = get<Window>(aID);
     952           0 :             if (!pFrame && mpCustomOptionsUIBuilder)
     953           0 :                 pFrame = mpCustomOptionsUIBuilder->get<Window>(aID);
     954             : 
     955           0 :             pFrame->SetText(aText);
     956             : 
     957             :             // set help id
     958           0 :             setHelpId(pFrame, aHelpIds, 0);
     959             :             // set help text
     960           0 :             setHelpText(pFrame, aHelpTexts, 0);
     961             : 
     962           0 :             pFrame->Show();
     963             :         }
     964             :         // EVIL
     965           0 :         else if( aCtrlType == "Bool" && aGroupingHint == "LayoutPage" && aPropertyName == "PrintProspect" )
     966             :         {
     967           0 :             maNUpPage.mpBrochureBtn->SetText( aText );
     968           0 :             maNUpPage.mpBrochureBtn->Show();
     969             : 
     970           0 :             sal_Bool bVal = sal_False;
     971           0 :             PropertyValue* pVal = maPController->getValue( aPropertyName );
     972           0 :             if( pVal )
     973           0 :                 pVal->Value >>= bVal;
     974           0 :             maNUpPage.mpBrochureBtn->Check( bVal );
     975           0 :             maNUpPage.mpBrochureBtn->Enable( maPController->isUIOptionEnabled( aPropertyName ) && pVal != NULL );
     976           0 :             maNUpPage.mpBrochureBtn->SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
     977             : 
     978           0 :             maPropertyToWindowMap[ aPropertyName ].push_back( maNUpPage.mpBrochureBtn );
     979           0 :             maControlToPropertyMap[maNUpPage.mpBrochureBtn] = aPropertyName;
     980             : 
     981             :             // set help id
     982           0 :             setHelpId( maNUpPage.mpBrochureBtn, aHelpIds, 0 );
     983             :             // set help text
     984           0 :             setHelpText( maNUpPage.mpBrochureBtn, aHelpTexts, 0 );
     985             :         }
     986           0 :         else if (aCtrlType == "Bool")
     987             :         {
     988             :             // add a check box
     989           0 :             CheckBox* pNewBox = get<CheckBox>(aID);
     990           0 :             if (!pNewBox && mpCustomOptionsUIBuilder)
     991           0 :                 pNewBox = mpCustomOptionsUIBuilder->get<CheckBox>(aID);
     992             : 
     993           0 :             pNewBox->SetText( aText );
     994           0 :             pNewBox->Show();
     995             : 
     996           0 :             sal_Bool bVal = sal_False;
     997           0 :             PropertyValue* pVal = maPController->getValue( aPropertyName );
     998           0 :             if( pVal )
     999           0 :                 pVal->Value >>= bVal;
    1000           0 :             pNewBox->Check( bVal );
    1001           0 :             pNewBox->SetToggleHdl( LINK( this, PrintDialog, UIOption_CheckHdl ) );
    1002             : 
    1003           0 :             maPropertyToWindowMap[ aPropertyName ].push_back( pNewBox );
    1004           0 :             maControlToPropertyMap[pNewBox] = aPropertyName;
    1005             : 
    1006             :             // set help id
    1007           0 :             setHelpId( pNewBox, aHelpIds, 0 );
    1008             :             // set help text
    1009           0 :             setHelpText( pNewBox, aHelpTexts, 0 );
    1010             :         }
    1011           0 :         else if (aCtrlType == "Radio")
    1012             :         {
    1013           0 :             sal_Int32 nCurHelpText = 0;
    1014             : 
    1015             :             // iterate options
    1016           0 :             sal_Int32 nSelectVal = 0;
    1017           0 :             PropertyValue* pVal = maPController->getValue( aPropertyName );
    1018           0 :             if( pVal && pVal->Value.hasValue() )
    1019           0 :                 pVal->Value >>= nSelectVal;
    1020           0 :             for( sal_Int32 m = 0; m < aChoices.getLength(); m++ )
    1021             :             {
    1022           0 :                 aID = rtl::OUStringToOString(aIDs[m], RTL_TEXTENCODING_UTF8);
    1023           0 :                 RadioButton* pBtn = get<RadioButton>(aID);
    1024           0 :                 if (!pBtn && mpCustomOptionsUIBuilder)
    1025           0 :                     pBtn = mpCustomOptionsUIBuilder->get<RadioButton>(aID);
    1026             : 
    1027           0 :                 pBtn->SetText( aChoices[m] );
    1028           0 :                 pBtn->Check( m == nSelectVal );
    1029           0 :                 pBtn->SetToggleHdl( LINK( this, PrintDialog, UIOption_RadioHdl ) );
    1030           0 :                 if( aChoicesDisabled.getLength() > m && aChoicesDisabled[m] == sal_True )
    1031           0 :                     pBtn->Enable( sal_False );
    1032           0 :                 pBtn->Show();
    1033           0 :                 maPropertyToWindowMap[ aPropertyName ].push_back( pBtn );
    1034           0 :                 maControlToPropertyMap[pBtn] = aPropertyName;
    1035           0 :                 maControlToNumValMap[pBtn] = m;
    1036             : 
    1037             :                 // set help id
    1038           0 :                 setHelpId( pBtn, aHelpIds, nCurHelpText );
    1039             :                 // set help text
    1040           0 :                 setHelpText( pBtn, aHelpTexts, nCurHelpText );
    1041           0 :                 nCurHelpText++;
    1042             :             }
    1043             :         }
    1044           0 :         else if ( aCtrlType == "List" )
    1045             :         {
    1046           0 :             ListBox* pList = get<ListBox>(aID);
    1047           0 :             if (!pList && mpCustomOptionsUIBuilder)
    1048           0 :                 pList = mpCustomOptionsUIBuilder->get<ListBox>(aID);
    1049             : 
    1050             :             // iterate options
    1051           0 :             for( sal_Int32 m = 0; m < aChoices.getLength(); m++ )
    1052             :             {
    1053           0 :                 pList->InsertEntry( aChoices[m] );
    1054             :             }
    1055           0 :             sal_Int32 nSelectVal = 0;
    1056           0 :             PropertyValue* pVal = maPController->getValue( aPropertyName );
    1057           0 :             if( pVal && pVal->Value.hasValue() )
    1058           0 :                 pVal->Value >>= nSelectVal;
    1059           0 :             pList->SelectEntryPos( static_cast<sal_uInt16>(nSelectVal) );
    1060           0 :             pList->SetSelectHdl( LINK( this, PrintDialog, UIOption_SelectHdl ) );
    1061           0 :             pList->SetDropDownLineCount( static_cast<sal_uInt16>(aChoices.getLength()) );
    1062           0 :             pList->Show();
    1063             : 
    1064             :             // set help id
    1065           0 :             setHelpId( pList, aHelpIds, 0 );
    1066             :             // set help text
    1067           0 :             setHelpText( pList, aHelpTexts, 0 );
    1068             : 
    1069           0 :             maPropertyToWindowMap[ aPropertyName ].push_back( pList );
    1070           0 :             maControlToPropertyMap[pList] = aPropertyName;
    1071             :         }
    1072           0 :         else if ( aCtrlType == "Range" )
    1073             :         {
    1074           0 :             NumericField* pField = get<NumericField>(aID);
    1075           0 :             if (!pField && mpCustomOptionsUIBuilder)
    1076           0 :                 pField = mpCustomOptionsUIBuilder->get<NumericField>(aID);
    1077             : 
    1078             :             // set min/max and current value
    1079           0 :             if( nMinValue != nMaxValue )
    1080             :             {
    1081           0 :                 pField->SetMin( nMinValue );
    1082           0 :                 pField->SetMax( nMaxValue );
    1083             :             }
    1084           0 :             sal_Int64 nCurVal = 0;
    1085           0 :             PropertyValue* pVal = maPController->getValue( aPropertyName );
    1086           0 :             if( pVal && pVal->Value.hasValue() )
    1087           0 :                 pVal->Value >>= nCurVal;
    1088           0 :             pField->SetValue( nCurVal );
    1089           0 :             pField->SetModifyHdl( LINK( this, PrintDialog, UIOption_ModifyHdl ) );
    1090           0 :             pField->Show();
    1091             : 
    1092             :             // set help id
    1093           0 :             setHelpId( pField, aHelpIds, 0 );
    1094             :             // set help text
    1095           0 :             setHelpText( pField, aHelpTexts, 0 );
    1096             : 
    1097           0 :             maPropertyToWindowMap[ aPropertyName ].push_back( pField );
    1098           0 :             maControlToPropertyMap[pField] = aPropertyName;
    1099             :         }
    1100           0 :         else if (aCtrlType == "Edit")
    1101             :         {
    1102           0 :             Edit *pField = get<Edit>(aID);
    1103           0 :             if (!pField && mpCustomOptionsUIBuilder)
    1104           0 :                 pField = mpCustomOptionsUIBuilder->get<Edit>(aID);
    1105             : 
    1106           0 :             rtl::OUString aCurVal;
    1107           0 :             PropertyValue* pVal = maPController->getValue( aPropertyName );
    1108           0 :             if( pVal && pVal->Value.hasValue() )
    1109           0 :                 pVal->Value >>= aCurVal;
    1110           0 :             pField->SetText( aCurVal );
    1111           0 :             pField->SetModifyHdl( LINK( this, PrintDialog, UIOption_ModifyHdl ) );
    1112           0 :             pField->Show();
    1113             : 
    1114             :             // set help id
    1115           0 :             setHelpId( pField, aHelpIds, 0 );
    1116             :             // set help text
    1117           0 :             setHelpText( pField, aHelpTexts, 0 );
    1118             : 
    1119           0 :             maPropertyToWindowMap[ aPropertyName ].push_back( pField );
    1120           0 :             maControlToPropertyMap[pField] = aPropertyName;
    1121             :         }
    1122             :         else
    1123             :         {
    1124           0 :             rtl::OStringBuffer sMessage;
    1125           0 :             sMessage.append(RTL_CONSTASCII_STRINGPARAM("Unsupported UI option: \""));
    1126           0 :             sMessage.append(rtl::OUStringToOString(aCtrlType, RTL_TEXTENCODING_UTF8));
    1127           0 :             sMessage.append('"');
    1128           0 :             OSL_FAIL( sMessage.getStr() );
    1129             :         }
    1130           0 :     }
    1131             : 
    1132             :     // #i106506# if no brochure button, then the singular Pages radio button
    1133             :     // makes no sense, so replace it by a FixedText label
    1134           0 :     if (!maNUpPage.mpBrochureBtn->IsVisible() && maNUpPage.mpPagesBtn->IsVisible())
    1135             :     {
    1136           0 :         maNUpPage.mpPagesBoxTitleTxt->SetText( maNUpPage.mpPagesBtn->GetText() );
    1137           0 :         maNUpPage.mpPagesBoxTitleTxt->Show( sal_True );
    1138           0 :         maNUpPage.mpPagesBtn->Show( sal_False );
    1139             :     }
    1140             : 
    1141             :     // update enable states
    1142           0 :     checkOptionalControlDependencies();
    1143             : 
    1144           0 :     Window *pPageRange = get<Window>("pagerange");
    1145             : 
    1146             :     // print range not shown (currently math only) -> hide spacer line and reverse order
    1147           0 :     if (!pPageRange || !pPageRange->IsVisible())
    1148             :     {
    1149           0 :         maJobPage.mpCopySpacer->Show( sal_False );
    1150           0 :         maJobPage.mpReverseOrderBox->Show( sal_False );
    1151             :     }
    1152             : 
    1153           0 :     if (!mpCustomOptionsUIBuilder)
    1154           0 :         mpTabCtrl->RemovePage(mpTabCtrl->GetPageId(1));
    1155           0 : }
    1156             : 
    1157           0 : void PrintDialog::DataChanged( const DataChangedEvent& i_rDCEvt )
    1158             : {
    1159             :     // react on settings changed
    1160           0 :     if( i_rDCEvt.GetType() == DATACHANGED_SETTINGS )
    1161           0 :         checkControlDependencies();
    1162           0 :     ModalDialog::DataChanged( i_rDCEvt );
    1163           0 : }
    1164             : 
    1165           0 : void PrintDialog::checkControlDependencies()
    1166             : {
    1167           0 :     if( maJobPage.mpCopyCountField->GetValue() > 1 )
    1168           0 :         maJobPage.mpCollateBox->Enable( maJobPage.mnCollateUIMode == 0 );
    1169             :     else
    1170           0 :         maJobPage.mpCollateBox->Enable( sal_False );
    1171             : 
    1172           0 :     Image aImg( maJobPage.mpCollateBox->IsChecked() ? maJobPage.maCollateImg : maJobPage.maNoCollateImg );
    1173             : 
    1174           0 :     Size aImgSize( aImg.GetSizePixel() );
    1175             : 
    1176             :     // adjust size of image
    1177           0 :     maJobPage.mpCollateImage->SetSizePixel( aImgSize );
    1178           0 :     maJobPage.mpCollateImage->SetImage( aImg );
    1179             : 
    1180             :     // enable setup button only for printers that can be setup
    1181           0 :     bool bHaveSetup = maPController->getPrinter()->HasSupport( SUPPORT_SETUPDIALOG );
    1182           0 :     maJobPage.mpSetupButton->Enable(bHaveSetup);
    1183           0 : }
    1184             : 
    1185           0 : void PrintDialog::checkOptionalControlDependencies()
    1186             : {
    1187           0 :     for( std::map< Window*, rtl::OUString >::iterator it = maControlToPropertyMap.begin();
    1188           0 :          it != maControlToPropertyMap.end(); ++it )
    1189             :     {
    1190           0 :         bool bShouldbeEnabled = maPController->isUIOptionEnabled( it->second );
    1191           0 :         if( ! bShouldbeEnabled )
    1192             :         {
    1193             :             // enable controls that are directly attached to a dependency anyway
    1194             :             // if the normally disabled controls get modified, change the dependency
    1195             :             // so the control would be enabled
    1196             :             // example: in print range "Print All" is selected, "Page Range" is then of course
    1197             :             // not selected and the Edit for the Page Range would be disabled
    1198             :             // as a convenience we should enable the Edit anyway and automatically select
    1199             :             // "Page Range" instead of "Print All" if the Edit gets modified
    1200           0 :             if( maReverseDependencySet.find( it->second ) != maReverseDependencySet.end() )
    1201             :             {
    1202           0 :                 rtl::OUString aDep( maPController->getDependency( it->second ) );
    1203             :                 // if the dependency is at least enabled, then enable this control anyway
    1204           0 :                 if( !aDep.isEmpty() && maPController->isUIOptionEnabled( aDep ) )
    1205           0 :                     bShouldbeEnabled = true;
    1206             :             }
    1207             :         }
    1208             : 
    1209           0 :         if( bShouldbeEnabled && dynamic_cast<RadioButton*>(it->first) )
    1210             :         {
    1211           0 :             std::map< Window*, sal_Int32 >::const_iterator r_it = maControlToNumValMap.find( it->first );
    1212           0 :             if( r_it != maControlToNumValMap.end() )
    1213             :             {
    1214           0 :                 bShouldbeEnabled = maPController->isUIChoiceEnabled( it->second, r_it->second );
    1215             :             }
    1216             :         }
    1217             : 
    1218             : 
    1219           0 :         bool bIsEnabled = it->first->IsEnabled();
    1220             :         // Enable does not do a change check first, so can be less cheap than expected
    1221           0 :         if( bShouldbeEnabled != bIsEnabled )
    1222           0 :             it->first->Enable( bShouldbeEnabled );
    1223             :     }
    1224           0 : }
    1225             : 
    1226           0 : static rtl::OUString searchAndReplace( const rtl::OUString& i_rOrig, const char* i_pRepl, sal_Int32 i_nReplLen, const rtl::OUString& i_rRepl )
    1227             : {
    1228           0 :     sal_Int32 nPos = i_rOrig.indexOfAsciiL( i_pRepl, i_nReplLen );
    1229           0 :     if( nPos != -1 )
    1230             :     {
    1231           0 :         rtl::OUStringBuffer aBuf( i_rOrig.getLength() );
    1232           0 :         aBuf.append( i_rOrig.getStr(), nPos );
    1233           0 :         aBuf.append( i_rRepl );
    1234           0 :         if( nPos + i_nReplLen < i_rOrig.getLength() )
    1235           0 :             aBuf.append( i_rOrig.getStr() + nPos + i_nReplLen );
    1236           0 :         return aBuf.makeStringAndClear();
    1237             :     }
    1238           0 :     return i_rOrig;
    1239             : }
    1240             : 
    1241           0 : void PrintDialog::updatePrinterText()
    1242             : {
    1243           0 :     const rtl::OUString aDefPrt( Printer::GetDefaultPrinterName() );
    1244           0 :     const QueueInfo* pInfo = Printer::GetQueueInfo( maJobPage.mpPrinters->GetSelectEntry(), true );
    1245           0 :     if( pInfo )
    1246             :     {
    1247           0 :         maJobPage.mpLocationTxt->SetText( pInfo->GetLocation() );
    1248           0 :         maJobPage.mpCommentTxt->SetText( pInfo->GetComment() );
    1249             :         // FIXME: status text
    1250           0 :         rtl::OUString aStatus;
    1251           0 :         if( aDefPrt == pInfo->GetPrinterName() )
    1252           0 :             aStatus = maDefPrtText;
    1253           0 :         maJobPage.mpStatusTxt->SetText( aStatus );
    1254             :     }
    1255             :     else
    1256             :     {
    1257           0 :         maJobPage.mpLocationTxt->SetText( String() );
    1258           0 :         maJobPage.mpCommentTxt->SetText( String() );
    1259           0 :         maJobPage.mpStatusTxt->SetText( String() );
    1260           0 :     }
    1261           0 : }
    1262             : 
    1263           0 : void PrintDialog::setPreviewText( sal_Int32 )
    1264             : {
    1265           0 :     rtl::OUString aNewText( searchAndReplace( maPageStr, "%n", 2, rtl::OUString::valueOf( mnCachedPages )  ) );
    1266           0 :     mpNumPagesText->SetText( aNewText );
    1267           0 : }
    1268             : 
    1269           0 : void PrintDialog::preparePreview( bool i_bNewPage, bool i_bMayUseCache )
    1270             : {
    1271             :     // page range may have changed depending on options
    1272           0 :     sal_Int32 nPages = maPController->getFilteredPageCount();
    1273           0 :     mnCachedPages = nPages;
    1274             : 
    1275           0 :     if( mnCurPage >= nPages )
    1276           0 :         mnCurPage = nPages-1;
    1277           0 :     if( mnCurPage < 0 )
    1278           0 :         mnCurPage = 0;
    1279             : 
    1280           0 :     setPreviewText( mnCurPage );
    1281             : 
    1282           0 :     mpPageEdit->SetMin( 1 );
    1283           0 :     mpPageEdit->SetMax( nPages );
    1284             : 
    1285           0 :     if( i_bNewPage )
    1286             :     {
    1287           0 :         const MapMode aMapMode( MAP_100TH_MM );
    1288           0 :         GDIMetaFile aMtf;
    1289           0 :         boost::shared_ptr<Printer> aPrt( maPController->getPrinter() );
    1290           0 :         if( nPages > 0 )
    1291             :         {
    1292             :             PrinterController::PageSize aPageSize =
    1293           0 :                 maPController->getFilteredPageFile( mnCurPage, aMtf, i_bMayUseCache );
    1294           0 :             if( ! aPageSize.bFullPaper )
    1295             :             {
    1296           0 :                 Point aOff( aPrt->PixelToLogic( aPrt->GetPageOffsetPixel(), aMapMode ) );
    1297           0 :                 aMtf.Move( aOff.X(), aOff.Y() );
    1298             :             }
    1299             :         }
    1300             : 
    1301           0 :         Size aCurPageSize = aPrt->PixelToLogic( aPrt->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) );
    1302             :         mpPreviewWindow->setPreview( aMtf, aCurPageSize,
    1303             :                                     aPrt->GetPaperName( false ),
    1304             :                                     nPages > 0 ? rtl::OUString() : maNoPageStr,
    1305           0 :                                     aPrt->ImplGetDPIX(), aPrt->ImplGetDPIY(),
    1306           0 :                                     aPrt->GetPrinterOptions().IsConvertToGreyscales()
    1307           0 :                                    );
    1308             : 
    1309           0 :         mpForwardBtn->Enable( mnCurPage < nPages-1 );
    1310           0 :         mpBackwardBtn->Enable( mnCurPage != 0 );
    1311           0 :         mpPageEdit->Enable( nPages > 1 );
    1312             :     }
    1313           0 : }
    1314             : 
    1315           0 : Size PrintDialog::getJobPageSize()
    1316             : {
    1317           0 :     if( maFirstPageSize.Width() == 0 && maFirstPageSize.Height() == 0)
    1318             :     {
    1319           0 :         maFirstPageSize = maNupPortraitSize;
    1320           0 :         GDIMetaFile aMtf;
    1321           0 :         if( maPController->getPageCountProtected() > 0 )
    1322             :         {
    1323           0 :             PrinterController::PageSize aPageSize = maPController->getPageFile( 0, aMtf, true );
    1324           0 :             maFirstPageSize = aPageSize.aSize;
    1325           0 :         }
    1326             :     }
    1327           0 :     return maFirstPageSize;
    1328             : }
    1329             : 
    1330           0 : void PrintDialog::updateNupFromPages()
    1331             : {
    1332           0 :     long nPages = long(maNUpPage.mpNupPagesBox->GetEntryData(maNUpPage.mpNupPagesBox->GetSelectEntryPos()));
    1333           0 :     int nRows   = int(maNUpPage.mpNupRowsEdt->GetValue());
    1334           0 :     int nCols   = int(maNUpPage.mpNupColEdt->GetValue());
    1335           0 :     long nPageMargin  = long(maNUpPage.mpPageMarginEdt->Denormalize(maNUpPage.mpPageMarginEdt->GetValue( FUNIT_100TH_MM )));
    1336           0 :     long nSheetMargin = long(maNUpPage.mpSheetMarginEdt->Denormalize(maNUpPage.mpSheetMarginEdt->GetValue( FUNIT_100TH_MM )));
    1337           0 :     bool bCustom = false;
    1338             : 
    1339           0 :     if( nPages == 1 )
    1340             :     {
    1341           0 :         nRows = nCols = 1;
    1342           0 :         nSheetMargin = 0;
    1343           0 :         nPageMargin = 0;
    1344             :     }
    1345           0 :     else if( nPages == 2 || nPages == 4 || nPages == 6 || nPages == 9 || nPages == 16 )
    1346             :     {
    1347           0 :         Size aJobPageSize( getJobPageSize() );
    1348           0 :         bool bPortrait = aJobPageSize.Width() < aJobPageSize.Height();
    1349           0 :         if( nPages == 2 )
    1350             :         {
    1351           0 :             if( bPortrait )
    1352           0 :                 nRows = 1, nCols = 2;
    1353             :             else
    1354           0 :                 nRows = 2, nCols = 1;
    1355             :         }
    1356           0 :         else if( nPages == 4 )
    1357           0 :             nRows = nCols = 2;
    1358           0 :         else if( nPages == 6 )
    1359             :         {
    1360           0 :             if( bPortrait )
    1361           0 :                 nRows = 2, nCols = 3;
    1362             :             else
    1363           0 :                 nRows = 3, nCols = 2;
    1364             :         }
    1365           0 :         else if( nPages == 9 )
    1366           0 :             nRows = nCols = 3;
    1367           0 :         else if( nPages == 16 )
    1368           0 :             nRows = nCols = 4;
    1369           0 :         nPageMargin = 0;
    1370           0 :         nSheetMargin = 0;
    1371             :     }
    1372             :     else
    1373           0 :         bCustom = true;
    1374             : 
    1375           0 :     if( nPages > 1 )
    1376             :     {
    1377             :         // set upper limits for margins based on job page size and rows/columns
    1378           0 :         Size aSize( getJobPageSize() );
    1379             : 
    1380             :         // maximum sheet distance: 1/2 sheet
    1381           0 :         long nHorzMax = aSize.Width()/2;
    1382           0 :         long nVertMax = aSize.Height()/2;
    1383           0 :         if( nSheetMargin > nHorzMax )
    1384           0 :             nSheetMargin = nHorzMax;
    1385           0 :         if( nSheetMargin > nVertMax )
    1386           0 :             nSheetMargin = nVertMax;
    1387             : 
    1388             :         maNUpPage.mpSheetMarginEdt->SetMax(
    1389             :                   maNUpPage.mpSheetMarginEdt->Normalize(
    1390           0 :                            nHorzMax > nVertMax ? nVertMax : nHorzMax ), FUNIT_100TH_MM );
    1391             : 
    1392             :         // maximum page distance
    1393           0 :         nHorzMax = (aSize.Width() - 2*nSheetMargin);
    1394           0 :         if( nCols > 1 )
    1395           0 :             nHorzMax /= (nCols-1);
    1396           0 :         nVertMax = (aSize.Height() - 2*nSheetMargin);
    1397           0 :         if( nRows > 1 )
    1398           0 :             nHorzMax /= (nRows-1);
    1399             : 
    1400           0 :         if( nPageMargin > nHorzMax )
    1401           0 :             nPageMargin = nHorzMax;
    1402           0 :         if( nPageMargin > nVertMax )
    1403           0 :             nPageMargin = nVertMax;
    1404             : 
    1405             :         maNUpPage.mpPageMarginEdt->SetMax(
    1406             :                  maNUpPage.mpSheetMarginEdt->Normalize(
    1407           0 :                            nHorzMax > nVertMax ? nVertMax : nHorzMax ), FUNIT_100TH_MM );
    1408             :     }
    1409             : 
    1410           0 :     maNUpPage.mpNupRowsEdt->SetValue( nRows );
    1411           0 :     maNUpPage.mpNupColEdt->SetValue( nCols );
    1412           0 :     maNUpPage.mpPageMarginEdt->SetValue( maNUpPage.mpPageMarginEdt->Normalize( nPageMargin ), FUNIT_100TH_MM );
    1413           0 :     maNUpPage.mpSheetMarginEdt->SetValue( maNUpPage.mpSheetMarginEdt->Normalize( nSheetMargin ), FUNIT_100TH_MM );
    1414             : 
    1415           0 :     maNUpPage.showAdvancedControls( bCustom );
    1416             : 
    1417           0 :     updateNup();
    1418           0 : }
    1419             : 
    1420           0 : void PrintDialog::updateNup()
    1421             : {
    1422           0 :     int nRows         = int(maNUpPage.mpNupRowsEdt->GetValue());
    1423           0 :     int nCols         = int(maNUpPage.mpNupColEdt->GetValue());
    1424           0 :     long nPageMargin  = long(maNUpPage.mpPageMarginEdt->Denormalize(maNUpPage.mpPageMarginEdt->GetValue( FUNIT_100TH_MM )));
    1425           0 :     long nSheetMargin = long(maNUpPage.mpSheetMarginEdt->Denormalize(maNUpPage.mpSheetMarginEdt->GetValue( FUNIT_100TH_MM )));
    1426             : 
    1427           0 :     PrinterController::MultiPageSetup aMPS;
    1428           0 :     aMPS.nRows         = nRows;
    1429           0 :     aMPS.nColumns      = nCols;
    1430           0 :     aMPS.nRepeat       = 1;
    1431             :     aMPS.nLeftMargin   =
    1432             :     aMPS.nTopMargin    =
    1433             :     aMPS.nRightMargin  =
    1434           0 :     aMPS.nBottomMargin = nSheetMargin;
    1435             : 
    1436             :     aMPS.nHorizontalSpacing =
    1437           0 :     aMPS.nVerticalSpacing   = nPageMargin;
    1438             : 
    1439           0 :     aMPS.bDrawBorder        = maNUpPage.mpBorderCB->IsChecked();
    1440             : 
    1441             :     int nOrderMode = int(sal_IntPtr(maNUpPage.mpNupOrderBox->GetEntryData(
    1442           0 :                            maNUpPage.mpNupOrderBox->GetSelectEntryPos() )));
    1443           0 :     if( nOrderMode == SV_PRINT_PRT_NUP_ORDER_LRTB )
    1444           0 :         aMPS.nOrder = PrinterController::LRTB;
    1445           0 :     else if( nOrderMode == SV_PRINT_PRT_NUP_ORDER_TBLR )
    1446           0 :         aMPS.nOrder = PrinterController::TBLR;
    1447           0 :     else if( nOrderMode == SV_PRINT_PRT_NUP_ORDER_RLTB )
    1448           0 :         aMPS.nOrder = PrinterController::RLTB;
    1449           0 :     else if( nOrderMode == SV_PRINT_PRT_NUP_ORDER_TBRL )
    1450           0 :         aMPS.nOrder = PrinterController::TBRL;
    1451             : 
    1452             :     int nOrientationMode = int(sal_IntPtr(maNUpPage.mpNupOrientationBox->GetEntryData(
    1453           0 :                                  maNUpPage.mpNupOrientationBox->GetSelectEntryPos() )));
    1454           0 :     if( nOrientationMode == SV_PRINT_PRT_NUP_ORIENTATION_LANDSCAPE )
    1455           0 :         aMPS.aPaperSize = maNupLandscapeSize;
    1456           0 :     else if( nOrientationMode == SV_PRINT_PRT_NUP_ORIENTATION_PORTRAIT )
    1457           0 :         aMPS.aPaperSize = maNupPortraitSize;
    1458             :     else // automatic mode
    1459             :     {
    1460             :         // get size of first real page to see if it is portrait or landscape
    1461             :         // we assume same page sizes for all the pages for this
    1462           0 :         Size aPageSize = getJobPageSize();
    1463             : 
    1464           0 :         Size aMultiSize( aPageSize.Width() * nCols, aPageSize.Height() * nRows );
    1465           0 :         if( aMultiSize.Width() > aMultiSize.Height() ) // fits better on landscape
    1466           0 :             aMPS.aPaperSize = maNupLandscapeSize;
    1467             :         else
    1468           0 :             aMPS.aPaperSize = maNupPortraitSize;
    1469             :     }
    1470             : 
    1471           0 :     maPController->setMultipage( aMPS );
    1472             : 
    1473           0 :     maNUpPage.mpNupOrderWin->setValues( nOrderMode, nCols, nRows );
    1474             : 
    1475           0 :     preparePreview( true, true );
    1476           0 : }
    1477             : 
    1478           0 : IMPL_LINK( PrintDialog, SelectHdl, ListBox*, pBox )
    1479             : {
    1480           0 :     if(  pBox == maJobPage.mpPrinters )
    1481             :     {
    1482           0 :         String aNewPrinter( pBox->GetSelectEntry() );
    1483             :         // set new printer
    1484           0 :         maPController->setPrinter( boost::shared_ptr<Printer>( new Printer( aNewPrinter ) ) );
    1485           0 :         maPController->resetPrinterOptions( maOptionsPage.mpToFileBox->IsChecked() );
    1486             :         // update text fields
    1487           0 :         updatePrinterText();
    1488           0 :         preparePreview( true, false );
    1489             :     }
    1490           0 :     else if( pBox == maNUpPage.mpNupOrientationBox || pBox == maNUpPage.mpNupOrderBox )
    1491             :     {
    1492           0 :         updateNup();
    1493             :     }
    1494           0 :     else if( pBox == maNUpPage.mpNupPagesBox )
    1495             :     {
    1496           0 :         if( !maNUpPage.mpPagesBtn->IsChecked() )
    1497           0 :             maNUpPage.mpPagesBtn->Check();
    1498           0 :         updateNupFromPages();
    1499             :     }
    1500             : 
    1501           0 :     return 0;
    1502             : }
    1503             : 
    1504           0 : IMPL_LINK( PrintDialog, ClickHdl, Button*, pButton )
    1505             : {
    1506           0 :     if( pButton == mpOKButton || pButton == mpCancelButton )
    1507             :     {
    1508           0 :         storeToSettings();
    1509           0 :         EndDialog( pButton == mpOKButton );
    1510             :     }
    1511           0 :     else if( pButton == mpHelpButton )
    1512             :     {
    1513             :         // start help system
    1514           0 :         Help* pHelp = Application::GetHelp();
    1515           0 :         if( pHelp )
    1516             :         {
    1517           0 :             pHelp->Start( rtl::OUString("vcl/ui/printdialog"), mpOKButton );
    1518             :         }
    1519             :     }
    1520           0 :     else if( pButton == mpForwardBtn )
    1521             :     {
    1522           0 :         previewForward();
    1523             :     }
    1524           0 :     else if( pButton == mpBackwardBtn )
    1525             :     {
    1526           0 :         previewBackward();
    1527             :     }
    1528           0 :     else if( pButton == maOptionsPage.mpToFileBox )
    1529             :     {
    1530           0 :         mpOKButton->SetText( maOptionsPage.mpToFileBox->IsChecked() ? maPrintToFileText : maPrintText );
    1531           0 :         maPController->resetPrinterOptions( maOptionsPage.mpToFileBox->IsChecked() );
    1532           0 :         preparePreview( true, true );
    1533             :     }
    1534           0 :     else if( pButton == maNUpPage.mpBrochureBtn )
    1535             :     {
    1536           0 :         PropertyValue* pVal = getValueForWindow( pButton );
    1537           0 :         if( pVal )
    1538             :         {
    1539           0 :             sal_Bool bVal = maNUpPage.mpBrochureBtn->IsChecked();
    1540           0 :             pVal->Value <<= bVal;
    1541             : 
    1542           0 :             checkOptionalControlDependencies();
    1543             : 
    1544             :             // update preview and page settings
    1545           0 :             preparePreview();
    1546             :         }
    1547           0 :         if( maNUpPage.mpBrochureBtn->IsChecked() )
    1548             :         {
    1549           0 :             maNUpPage.mpNupPagesBox->SelectEntryPos( 0 );
    1550           0 :             updateNupFromPages();
    1551           0 :             maNUpPage.showAdvancedControls( false );
    1552           0 :             maNUpPage.enableNupControls( false );
    1553             :         }
    1554             :     }
    1555           0 :     else if( pButton == maNUpPage.mpPagesBtn )
    1556             :     {
    1557           0 :         maNUpPage.enableNupControls( true );
    1558           0 :         updateNupFromPages();
    1559             :     }
    1560           0 :     else if( pButton == maJobPage.mpCollateBox )
    1561             :     {
    1562             :         maPController->setValue( rtl::OUString( "Collate"  ),
    1563           0 :                                  makeAny( sal_Bool(isCollate()) ) );
    1564           0 :         checkControlDependencies();
    1565             :     }
    1566           0 :     else if( pButton == maJobPage.mpReverseOrderBox )
    1567             :     {
    1568           0 :         sal_Bool bChecked = maJobPage.mpReverseOrderBox->IsChecked();
    1569           0 :         maPController->setReversePrint( bChecked );
    1570             :         maPController->setValue( rtl::OUString( "PrintReverse"  ),
    1571           0 :                                  makeAny( bChecked ) );
    1572           0 :         preparePreview( true, true );
    1573             :     }
    1574           0 :     else if( pButton == maNUpPage.mpBorderCB )
    1575             :     {
    1576           0 :         updateNup();
    1577             :     }
    1578             :     else
    1579             :     {
    1580           0 :         if( pButton == maJobPage.mpSetupButton )
    1581             :         {
    1582           0 :             maPController->setupPrinter( this );
    1583           0 :             preparePreview( true, true );
    1584             :         }
    1585           0 :         checkControlDependencies();
    1586             :     }
    1587           0 :     return 0;
    1588             : }
    1589             : 
    1590           0 : IMPL_LINK( PrintDialog, ModifyHdl, Edit*, pEdit )
    1591             : {
    1592           0 :     checkControlDependencies();
    1593           0 :     if( pEdit == maNUpPage.mpNupRowsEdt || pEdit == maNUpPage.mpNupColEdt ||
    1594             :         pEdit == maNUpPage.mpSheetMarginEdt || pEdit == maNUpPage.mpPageMarginEdt
    1595             :        )
    1596             :     {
    1597           0 :         updateNupFromPages();
    1598             :     }
    1599           0 :     else if( pEdit == mpPageEdit )
    1600             :     {
    1601           0 :         mnCurPage = sal_Int32( mpPageEdit->GetValue() - 1 );
    1602           0 :         preparePreview( true, true );
    1603             :     }
    1604           0 :     else if( pEdit == maJobPage.mpCopyCountField )
    1605             :     {
    1606             :         maPController->setValue( rtl::OUString( "CopyCount"  ),
    1607           0 :                                makeAny( sal_Int32(maJobPage.mpCopyCountField->GetValue()) ) );
    1608             :         maPController->setValue( rtl::OUString( "Collate"  ),
    1609           0 :                                makeAny( sal_Bool(isCollate()) ) );
    1610             :     }
    1611           0 :     return 0;
    1612             : }
    1613             : 
    1614           0 : IMPL_LINK_NOARG(PrintDialog, UIOptionsChanged)
    1615             : {
    1616           0 :     checkOptionalControlDependencies();
    1617           0 :     return 0;
    1618             : }
    1619             : 
    1620           0 : PropertyValue* PrintDialog::getValueForWindow( Window* i_pWindow ) const
    1621             : {
    1622           0 :     PropertyValue* pVal = NULL;
    1623           0 :     std::map< Window*, rtl::OUString >::const_iterator it = maControlToPropertyMap.find( i_pWindow );
    1624           0 :     if( it != maControlToPropertyMap.end() )
    1625             :     {
    1626           0 :         pVal = maPController->getValue( it->second );
    1627             :         DBG_ASSERT( pVal, "property value not found" );
    1628             :     }
    1629             :     else
    1630             :     {
    1631             :         OSL_FAIL( "changed control not in property map" );
    1632             :     }
    1633           0 :     return pVal;
    1634             : }
    1635             : 
    1636           0 : void PrintDialog::updateWindowFromProperty( const rtl::OUString& i_rProperty )
    1637             : {
    1638           0 :     beans::PropertyValue* pValue = maPController->getValue( i_rProperty );
    1639           0 :     std::map< rtl::OUString, std::vector< Window* > >::const_iterator it = maPropertyToWindowMap.find( i_rProperty );
    1640           0 :     if( pValue && it != maPropertyToWindowMap.end() )
    1641             :     {
    1642           0 :         const std::vector< Window* >& rWindows( it->second );
    1643           0 :         if( ! rWindows.empty() )
    1644             :         {
    1645           0 :             sal_Bool bVal = sal_False;
    1646           0 :             sal_Int32 nVal = -1;
    1647           0 :             if( pValue->Value >>= bVal )
    1648             :             {
    1649             :                 // we should have a CheckBox for this one
    1650           0 :                 CheckBox* pBox = dynamic_cast< CheckBox* >( rWindows.front() );
    1651           0 :                 if( pBox )
    1652             :                 {
    1653           0 :                     pBox->Check( bVal );
    1654             :                 }
    1655           0 :                 else if ( i_rProperty == "PrintProspect" )
    1656             :                 {
    1657             :                     // EVIL special case
    1658           0 :                     if( bVal )
    1659           0 :                         maNUpPage.mpBrochureBtn->Check();
    1660             :                     else
    1661           0 :                         maNUpPage.mpPagesBtn->Check();
    1662             :                 }
    1663             :                 else
    1664             :                 {
    1665             :                     DBG_ASSERT( 0, "missing a checkbox" );
    1666             :                 }
    1667             :             }
    1668           0 :             else if( pValue->Value >>= nVal )
    1669             :             {
    1670             :                 // this could be a ListBox or a RadioButtonGroup
    1671           0 :                 ListBox* pList = dynamic_cast< ListBox* >( rWindows.front() );
    1672           0 :                 if( pList )
    1673             :                 {
    1674           0 :                     pList->SelectEntryPos( static_cast< sal_uInt16 >(nVal) );
    1675             :                 }
    1676           0 :                 else if( nVal >= 0 && nVal < sal_Int32(rWindows.size() ) )
    1677             :                 {
    1678           0 :                     RadioButton* pBtn = dynamic_cast< RadioButton* >( rWindows[nVal] );
    1679             :                     DBG_ASSERT( pBtn, "unexpected control for property" );
    1680           0 :                     if( pBtn )
    1681           0 :                         pBtn->Check();
    1682             :                 }
    1683             :             }
    1684             :         }
    1685             :     }
    1686           0 : }
    1687             : 
    1688           0 : void PrintDialog::makeEnabled( Window* i_pWindow )
    1689             : {
    1690           0 :     std::map< Window*, rtl::OUString >::const_iterator it = maControlToPropertyMap.find( i_pWindow );
    1691           0 :     if( it != maControlToPropertyMap.end() )
    1692             :     {
    1693           0 :         rtl::OUString aDependency( maPController->makeEnabled( it->second ) );
    1694           0 :         if( !aDependency.isEmpty() )
    1695           0 :             updateWindowFromProperty( aDependency );
    1696             :     }
    1697           0 : }
    1698             : 
    1699           0 : IMPL_LINK( PrintDialog, UIOption_CheckHdl, CheckBox*, i_pBox )
    1700             : {
    1701           0 :     PropertyValue* pVal = getValueForWindow( i_pBox );
    1702           0 :     if( pVal )
    1703             :     {
    1704           0 :         makeEnabled( i_pBox );
    1705             : 
    1706           0 :         sal_Bool bVal = i_pBox->IsChecked();
    1707           0 :         pVal->Value <<= bVal;
    1708             : 
    1709           0 :         checkOptionalControlDependencies();
    1710             : 
    1711             :         // update preview and page settings
    1712           0 :         preparePreview();
    1713             :     }
    1714           0 :     return 0;
    1715             : }
    1716             : 
    1717           0 : IMPL_LINK( PrintDialog, UIOption_RadioHdl, RadioButton*, i_pBtn )
    1718             : {
    1719             :     // this handler gets called for all radiobuttons that get unchecked, too
    1720             :     // however we only want one notificaction for the new value (that is for
    1721             :     // the button that gets checked)
    1722           0 :     if( i_pBtn->IsChecked() )
    1723             :     {
    1724           0 :         PropertyValue* pVal = getValueForWindow( i_pBtn );
    1725           0 :         std::map< Window*, sal_Int32 >::const_iterator it = maControlToNumValMap.find( i_pBtn );
    1726           0 :         if( pVal && it != maControlToNumValMap.end() )
    1727             :         {
    1728           0 :             makeEnabled( i_pBtn );
    1729             : 
    1730           0 :             sal_Int32 nVal = it->second;
    1731           0 :             pVal->Value <<= nVal;
    1732             : 
    1733           0 :             checkOptionalControlDependencies();
    1734             : 
    1735             :             // update preview and page settings
    1736           0 :             preparePreview();
    1737             :         }
    1738             :     }
    1739           0 :     return 0;
    1740             : }
    1741             : 
    1742           0 : IMPL_LINK( PrintDialog, UIOption_SelectHdl, ListBox*, i_pBox )
    1743             : {
    1744           0 :     PropertyValue* pVal = getValueForWindow( i_pBox );
    1745           0 :     if( pVal )
    1746             :     {
    1747           0 :         makeEnabled( i_pBox );
    1748             : 
    1749           0 :         sal_Int32 nVal( i_pBox->GetSelectEntryPos() );
    1750           0 :         pVal->Value <<= nVal;
    1751             : 
    1752           0 :         checkOptionalControlDependencies();
    1753             : 
    1754             :         // update preview and page settings
    1755           0 :         preparePreview();
    1756             :     }
    1757           0 :     return 0;
    1758             : }
    1759             : 
    1760           0 : IMPL_LINK( PrintDialog, UIOption_ModifyHdl, Edit*, i_pBox )
    1761             : {
    1762           0 :     PropertyValue* pVal = getValueForWindow( i_pBox );
    1763           0 :     if( pVal )
    1764             :     {
    1765           0 :         makeEnabled( i_pBox );
    1766             : 
    1767           0 :         NumericField* pNum = dynamic_cast<NumericField*>(i_pBox);
    1768           0 :         MetricField* pMetric = dynamic_cast<MetricField*>(i_pBox);
    1769           0 :         if( pNum )
    1770             :         {
    1771           0 :             sal_Int64 nVal = pNum->GetValue();
    1772           0 :             pVal->Value <<= nVal;
    1773             :         }
    1774           0 :         else if( pMetric )
    1775             :         {
    1776           0 :             sal_Int64 nVal = pMetric->GetValue();
    1777           0 :             pVal->Value <<= nVal;
    1778             :         }
    1779             :         else
    1780             :         {
    1781           0 :             rtl::OUString aVal( i_pBox->GetText() );
    1782           0 :             pVal->Value <<= aVal;
    1783             :         }
    1784             : 
    1785           0 :         checkOptionalControlDependencies();
    1786             : 
    1787             :         // update preview and page settings
    1788           0 :         preparePreview();
    1789             :     }
    1790           0 :     return 0;
    1791             : }
    1792             : 
    1793           0 : void PrintDialog::Command( const CommandEvent& rEvt )
    1794             : {
    1795           0 :     if( rEvt.GetCommand() == COMMAND_WHEEL )
    1796             :     {
    1797           0 :         const CommandWheelData* pWheelData = rEvt.GetWheelData();
    1798           0 :         if( pWheelData->GetDelta() > 0 )
    1799           0 :             previewForward();
    1800           0 :         else if( pWheelData->GetDelta() < 0 )
    1801           0 :             previewBackward();
    1802             :     }
    1803           0 : }
    1804             : 
    1805           0 : void PrintDialog::Resize()
    1806             : {
    1807             :     // maLayout.setManagedArea( Rectangle( Point( 0, 0 ), GetSizePixel() ) );
    1808             :     // and do the preview; however the metafile does not need to be gotten anew
    1809           0 :     preparePreview( false );
    1810             : 
    1811           0 :     Dialog::Resize();
    1812           0 : }
    1813             : 
    1814           0 : void PrintDialog::previewForward()
    1815             : {
    1816           0 :     mpPageEdit->Up();
    1817           0 : }
    1818             : 
    1819           0 : void PrintDialog::previewBackward()
    1820             : {
    1821           0 :     mpPageEdit->Down();
    1822           0 : }
    1823             : 
    1824             : // -----------------------------------------------------------------------------
    1825             : //
    1826             : // PrintProgressDialog
    1827             : //
    1828             : // -----------------------------------------------------------------------------
    1829             : 
    1830           0 : PrintProgressDialog::PrintProgressDialog( Window* i_pParent, int i_nMax ) :
    1831             :     ModelessDialog( i_pParent, VclResId( SV_DLG_PRINT_PROGRESS ) ),
    1832             :     maText( this, VclResId( SV_PRINT_PROGRESS_TEXT ) ),
    1833             :     maButton( this, VclResId( SV_PRINT_PROGRESS_CANCEL ) ),
    1834             :     mbCanceled( false ),
    1835             :     mnCur( 0 ),
    1836             :     mnMax( i_nMax ),
    1837             :     mnProgressHeight( 15 ),
    1838           0 :     mbNativeProgress( false )
    1839             : {
    1840           0 :     FreeResource();
    1841             : 
    1842           0 :     if( mnMax < 1 )
    1843           0 :         mnMax = 1;
    1844             : 
    1845           0 :     maStr = maText.GetText();
    1846             : 
    1847           0 :     maButton.SetClickHdl( LINK( this, PrintProgressDialog, ClickHdl ) );
    1848             : 
    1849           0 : }
    1850             : 
    1851           0 : PrintProgressDialog::~PrintProgressDialog()
    1852             : {
    1853           0 : }
    1854             : 
    1855           0 : IMPL_LINK( PrintProgressDialog, ClickHdl, Button*, pButton )
    1856             : {
    1857           0 :     if( pButton == &maButton )
    1858           0 :         mbCanceled = true;
    1859             : 
    1860           0 :     return 0;
    1861             : }
    1862             : 
    1863           0 : void PrintProgressDialog::implCalcProgressRect()
    1864             : {
    1865           0 :     if( IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) )
    1866             :     {
    1867           0 :         ImplControlValue aValue;
    1868           0 :         Rectangle aControlRegion( Point(), Size( 100, mnProgressHeight ) );
    1869           0 :         Rectangle aNativeControlRegion, aNativeContentRegion;
    1870           0 :         if( GetNativeControlRegion( CTRL_PROGRESS, PART_ENTIRE_CONTROL, aControlRegion,
    1871             :                                     CTRL_STATE_ENABLED, aValue, rtl::OUString(),
    1872           0 :                                     aNativeControlRegion, aNativeContentRegion ) )
    1873             :         {
    1874           0 :             mnProgressHeight = aNativeControlRegion.GetHeight();
    1875             :         }
    1876           0 :         mbNativeProgress = true;
    1877             :     }
    1878           0 :     maProgressRect = Rectangle( Point( 10, maText.GetPosPixel().Y() + maText.GetSizePixel().Height() + 8 ),
    1879           0 :                                 Size( GetSizePixel().Width() - 20, mnProgressHeight ) );
    1880           0 : }
    1881             : 
    1882           0 : void PrintProgressDialog::setProgress( int i_nCurrent, int i_nMax )
    1883             : {
    1884           0 :     if( maProgressRect.IsEmpty() )
    1885           0 :         implCalcProgressRect();
    1886             : 
    1887           0 :     mnCur = i_nCurrent;
    1888           0 :     if( i_nMax != -1 )
    1889           0 :         mnMax = i_nMax;
    1890             : 
    1891           0 :     if( mnMax < 1 )
    1892           0 :         mnMax = 1;
    1893             : 
    1894           0 :     rtl::OUString aNewText( searchAndReplace( maStr, "%p", 2, rtl::OUString::valueOf( mnCur ) ) );
    1895           0 :     aNewText = searchAndReplace( aNewText, "%n", 2, rtl::OUString::valueOf( mnMax ) );
    1896           0 :     maText.SetText( aNewText );
    1897             : 
    1898             :     // update progress
    1899           0 :     Invalidate( maProgressRect, INVALIDATE_UPDATE );
    1900           0 : }
    1901             : 
    1902           0 : void PrintProgressDialog::tick()
    1903             : {
    1904           0 :     if( mnCur < mnMax )
    1905           0 :         setProgress( ++mnCur );
    1906           0 : }
    1907             : 
    1908           0 : void PrintProgressDialog::reset()
    1909             : {
    1910           0 :     mbCanceled = false;
    1911           0 :     setProgress( 0 );
    1912           0 : }
    1913             : 
    1914           0 : void PrintProgressDialog::Paint( const Rectangle& )
    1915             : {
    1916           0 :     if( maProgressRect.IsEmpty() )
    1917           0 :         implCalcProgressRect();
    1918             : 
    1919           0 :     Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
    1920           0 :     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
    1921           0 :     Color aPrgsColor = rStyleSettings.GetHighlightColor();
    1922           0 :     if ( aPrgsColor == rStyleSettings.GetFaceColor() )
    1923           0 :         aPrgsColor = rStyleSettings.GetDarkShadowColor();
    1924           0 :     SetLineColor();
    1925           0 :     SetFillColor( aPrgsColor );
    1926             : 
    1927           0 :     const long nOffset = 3;
    1928           0 :     const long nWidth = 3*mnProgressHeight/2;
    1929           0 :     const long nFullWidth = nWidth + nOffset;
    1930           0 :     const long nMaxCount = maProgressRect.GetWidth() / nFullWidth;
    1931           0 :     DrawProgress( this, maProgressRect.TopLeft(),
    1932             :                         nOffset,
    1933             :                         nWidth,
    1934             :                         mnProgressHeight,
    1935             :                         static_cast<sal_uInt16>(0),
    1936             :                         static_cast<sal_uInt16>(10000*mnCur/mnMax),
    1937             :                         static_cast<sal_uInt16>(10000/nMaxCount),
    1938             :                         maProgressRect
    1939           0 :                         );
    1940           0 :     Pop();
    1941             : 
    1942           0 :     if( ! mbNativeProgress )
    1943             :     {
    1944           0 :         DecorationView aDecoView( this );
    1945           0 :         Rectangle aFrameRect( maProgressRect );
    1946           0 :         aFrameRect.Left() -= nOffset;
    1947           0 :         aFrameRect.Right() += nOffset;
    1948           0 :         aFrameRect.Top() -= nOffset;
    1949           0 :         aFrameRect.Bottom() += nOffset;
    1950           0 :         aDecoView.DrawFrame( aFrameRect );
    1951             :     }
    1952         108 : }
    1953             : 
    1954             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10