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

Generated by: LCOV version 1.11