LCOV - code coverage report
Current view: top level - sfx2/source/dialog - printopt.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 177 0.6 %
Date: 2014-11-03 Functions: 2 27 7.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             : 
      21             : #include <sal/macros.h>
      22             : #include <vcl/msgbox.hxx>
      23             : #include <unotools/printwarningoptions.hxx>
      24             : #include <svtools/printoptions.hxx>
      25             : #include <svtools/restartdialog.hxx>
      26             : #include <svl/flagitem.hxx>
      27             : 
      28             : #include <comphelper/processfactory.hxx>
      29             : 
      30             : #include <sfx2/sfxresid.hxx>
      31             : #include <sfx2/viewsh.hxx>
      32             : #include <sfx2/printopt.hxx>
      33             : 
      34             : static sal_uInt16   aDPIArray[] = { 72, 96, 150, 200, 300, 600 };
      35             : static bool     bOutputForPrinter = true;
      36             : 
      37             : #define DPI_COUNT (sizeof(aDPIArray)/sizeof(aDPIArray[0 ]))
      38             : 
      39           0 : SfxCommonPrintOptionsTabPage::SfxCommonPrintOptionsTabPage( vcl::Window* pParent, const SfxItemSet& rSet )
      40           0 :     : SfxTabPage(pParent, "OptPrintPage", "sfx/ui/optprintpage.ui", &rSet)
      41             : {
      42           0 :     get(m_pPrinterOutputRB, "printer");
      43           0 :     get(m_pPrintFileOutputRB, "file");
      44           0 :     get(m_pReduceTransparencyCB, "reducetrans");
      45           0 :     get(m_pReduceTransparencyAutoRB, "reducetransauto");
      46           0 :     get(m_pReduceTransparencyNoneRB, "reducetransnone");
      47           0 :     get(m_pReduceGradientsCB, "reducegrad");
      48           0 :     get(m_pReduceGradientsStripesRB, "reducegradstripes");
      49           0 :     get(m_pReduceGradientsColorRB, "reducegradcolor");
      50           0 :     get(m_pReduceGradientsStepCountNF, "reducegradstep");
      51           0 :     get(m_pReduceBitmapsCB, "reducebitmap");
      52           0 :     get(m_pReduceBitmapsOptimalRB, "reducebitmapoptimal");
      53           0 :     get(m_pReduceBitmapsNormalRB, "reducebitmapnormal");
      54           0 :     get(m_pReduceBitmapsResolutionRB, "reducebitmapresol");
      55           0 :     get(m_pReduceBitmapsResolutionLB, "reducebitmapdpi");
      56           0 :     get(m_pReduceBitmapsTransparencyCB, "reducebitmaptrans");
      57           0 :     get(m_pConvertToGreyscalesCB, "converttogray");
      58           0 :     get(m_pPDFCB, "pdf");
      59           0 :     get(m_pPaperSizeCB, "papersize");
      60           0 :     get(m_pPaperOrientationCB, "paperorient");
      61           0 :     get(m_pTransparencyCB, "trans");
      62             : 
      63             : #ifndef ENABLE_CUPS
      64             :     m_pPDFCB->Hide();
      65             : #endif
      66             : 
      67           0 :     if( bOutputForPrinter )
      68             :     {
      69           0 :         m_pPrinterOutputRB->Check( true );
      70             :     }
      71             :     else
      72             :     {
      73           0 :         m_pPrintFileOutputRB->Check( true );
      74           0 :         m_pPDFCB->Disable();
      75             :     }
      76             : 
      77           0 :     m_pPrinterOutputRB->SetToggleHdl( LINK( this, SfxCommonPrintOptionsTabPage, ToggleOutputPrinterRBHdl ) );
      78           0 :     m_pPrintFileOutputRB->SetToggleHdl( LINK( this, SfxCommonPrintOptionsTabPage, ToggleOutputPrintFileRBHdl ) );
      79             : 
      80           0 :     m_pReduceTransparencyCB->SetClickHdl( LINK( this, SfxCommonPrintOptionsTabPage, ClickReduceTransparencyCBHdl ) );
      81           0 :     m_pReduceGradientsCB->SetClickHdl( LINK( this, SfxCommonPrintOptionsTabPage, ClickReduceGradientsCBHdl ) );
      82           0 :     m_pReduceBitmapsCB->SetClickHdl( LINK( this, SfxCommonPrintOptionsTabPage, ClickReduceBitmapsCBHdl ) );
      83             : 
      84           0 :     m_pReduceGradientsStripesRB->SetToggleHdl( LINK( this, SfxCommonPrintOptionsTabPage, ToggleReduceGradientsStripesRBHdl ) );
      85           0 :     m_pReduceBitmapsResolutionRB->SetToggleHdl( LINK( this, SfxCommonPrintOptionsTabPage, ToggleReduceBitmapsResolutionRBHdl ) );
      86           0 : }
      87             : 
      88           0 : SfxCommonPrintOptionsTabPage::~SfxCommonPrintOptionsTabPage()
      89             : {
      90           0 : }
      91             : 
      92           0 : SfxTabPage* SfxCommonPrintOptionsTabPage::Create( vcl::Window* pParent, const SfxItemSet* rAttrSet )
      93             : {
      94           0 :     return( new SfxCommonPrintOptionsTabPage( pParent, *rAttrSet ) );
      95             : }
      96             : 
      97           0 : vcl::Window* SfxCommonPrintOptionsTabPage::GetParentLabeledBy( const vcl::Window* pWindow ) const
      98             : {
      99           0 :     if ( pWindow == (vcl::Window *)m_pReduceGradientsStepCountNF )
     100           0 :         return m_pReduceGradientsStripesRB;
     101           0 :     else if ( pWindow == (vcl::Window *)m_pReduceBitmapsResolutionLB )
     102           0 :         return m_pReduceBitmapsResolutionRB;
     103             :     else
     104           0 :         return SfxTabPage::GetParentLabeledBy( pWindow );
     105             : }
     106             : 
     107           0 : vcl::Window* SfxCommonPrintOptionsTabPage::GetParentLabelFor( const vcl::Window* pWindow ) const
     108             : {
     109           0 :     if ( pWindow == (vcl::Window *)m_pReduceGradientsStripesRB )
     110           0 :         return m_pReduceGradientsStepCountNF;
     111           0 :     else if ( pWindow == (vcl::Window *)m_pReduceBitmapsResolutionRB )
     112           0 :         return m_pReduceBitmapsResolutionLB;
     113             :     else
     114           0 :         return SfxTabPage::GetParentLabelFor( pWindow );
     115             : }
     116             : 
     117           0 : bool SfxCommonPrintOptionsTabPage::FillItemSet( SfxItemSet* /*rSet*/ )
     118             : {
     119           0 :     SvtPrintWarningOptions  aWarnOptions;
     120           0 :     SvtPrinterOptions       aPrinterOptions;
     121           0 :     SvtPrintFileOptions     aPrintFileOptions;
     122           0 :     bool                    bModified = false;
     123             : 
     124             : 
     125           0 :     if( m_pPaperSizeCB->IsValueChangedFromSaved())
     126           0 :         aWarnOptions.SetPaperSize(m_pPaperSizeCB->IsChecked());
     127           0 :     if( m_pPaperOrientationCB->IsValueChangedFromSaved() )
     128           0 :         aWarnOptions.SetPaperOrientation(m_pPaperOrientationCB->IsChecked());
     129             : 
     130           0 :     if( m_pTransparencyCB->IsValueChangedFromSaved() )
     131           0 :         aWarnOptions.SetTransparency( m_pTransparencyCB->IsChecked() );
     132             : 
     133           0 :     ImplSaveControls( m_pPrinterOutputRB->IsChecked() ? &maPrinterOptions : &maPrintFileOptions );
     134             : 
     135           0 :     aPrinterOptions.SetPrinterOptions( maPrinterOptions );
     136           0 :     aPrintFileOptions.SetPrinterOptions( maPrintFileOptions );
     137             : 
     138           0 :     return bModified;
     139             : }
     140             : 
     141           0 : void SfxCommonPrintOptionsTabPage::Reset( const SfxItemSet* /*rSet*/ )
     142             : {
     143           0 :     SvtPrintWarningOptions  aWarnOptions;
     144           0 :     SvtPrinterOptions       aPrinterOptions;
     145           0 :     SvtPrintFileOptions     aPrintFileOptions;
     146             : 
     147           0 :     m_pPaperSizeCB->Check( aWarnOptions.IsPaperSize() );
     148           0 :     m_pPaperOrientationCB->Check( aWarnOptions.IsPaperOrientation() );
     149             : 
     150           0 :     m_pTransparencyCB->Check( aWarnOptions.IsTransparency() );
     151             : 
     152           0 :     m_pPaperSizeCB->SaveValue();
     153           0 :     m_pPaperOrientationCB->SaveValue();
     154           0 :     m_pTransparencyCB->SaveValue();
     155             : 
     156           0 :     aPrinterOptions.GetPrinterOptions( maPrinterOptions );
     157           0 :     aPrintFileOptions.GetPrinterOptions( maPrintFileOptions );
     158             : 
     159           0 :     ImplUpdateControls( m_pPrinterOutputRB->IsChecked() ? &maPrinterOptions : &maPrintFileOptions );
     160           0 : }
     161             : 
     162           0 : int SfxCommonPrintOptionsTabPage::DeactivatePage( SfxItemSet* pItemSet )
     163             : {
     164           0 :     if( pItemSet )
     165           0 :         FillItemSet( pItemSet );
     166             : 
     167           0 :     return LEAVE_PAGE;
     168             : }
     169             : 
     170           0 : void SfxCommonPrintOptionsTabPage::ImplUpdateControls( const PrinterOptions* pCurrentOptions )
     171             : {
     172           0 :     m_pReduceTransparencyCB->Check( pCurrentOptions->IsReduceTransparency() );
     173             : 
     174           0 :     if( pCurrentOptions->GetReducedTransparencyMode() == PRINTER_TRANSPARENCY_AUTO )
     175           0 :         m_pReduceTransparencyAutoRB->Check( true );
     176             :     else
     177           0 :         m_pReduceTransparencyNoneRB->Check( true );
     178             : 
     179           0 :     m_pReduceGradientsCB->Check( pCurrentOptions->IsReduceGradients() );
     180             : 
     181           0 :     if( pCurrentOptions->GetReducedGradientMode() == PRINTER_GRADIENT_STRIPES )
     182           0 :         m_pReduceGradientsStripesRB->Check( true );
     183             :     else
     184           0 :         m_pReduceGradientsColorRB->Check( true );
     185             : 
     186           0 :     m_pReduceGradientsStepCountNF->SetValue( pCurrentOptions->GetReducedGradientStepCount() );
     187             : 
     188           0 :     m_pReduceBitmapsCB->Check( pCurrentOptions->IsReduceBitmaps() );
     189             : 
     190           0 :     if( pCurrentOptions->GetReducedBitmapMode() == PRINTER_BITMAP_OPTIMAL )
     191           0 :         m_pReduceBitmapsOptimalRB->Check( true );
     192           0 :     else if( pCurrentOptions->GetReducedBitmapMode() == PRINTER_BITMAP_NORMAL )
     193           0 :         m_pReduceBitmapsNormalRB->Check( true );
     194             :     else
     195           0 :         m_pReduceBitmapsResolutionRB->Check( true );
     196             : 
     197           0 :     const sal_uInt16 nDPI = pCurrentOptions->GetReducedBitmapResolution();
     198             : 
     199           0 :     if( nDPI < aDPIArray[ 0 ] )
     200           0 :         m_pReduceBitmapsResolutionLB->SelectEntryPos( 0 );
     201             :     else
     202             :     {
     203           0 :         for( long i = ( DPI_COUNT - 1 ); i >= 0; i-- )
     204             :         {
     205           0 :             if( nDPI >= aDPIArray[ i ] )
     206             :             {
     207           0 :                 m_pReduceBitmapsResolutionLB->SelectEntryPos( (sal_uInt16) i );
     208           0 :                 i = -1;
     209             :             }
     210             :         }
     211             :     }
     212             : 
     213           0 :     m_pReduceBitmapsResolutionLB->SetText( m_pReduceBitmapsResolutionLB->GetEntry( m_pReduceBitmapsResolutionLB->GetSelectEntryPos() ) );
     214             : 
     215           0 :     m_pReduceBitmapsTransparencyCB->Check( pCurrentOptions->IsReducedBitmapIncludesTransparency() );
     216           0 :     m_pConvertToGreyscalesCB->Check( pCurrentOptions->IsConvertToGreyscales() );
     217           0 :     m_pPDFCB->Check( pCurrentOptions->IsPDFAsStandardPrintJobFormat() );
     218             : 
     219           0 :     ClickReduceTransparencyCBHdl(m_pReduceTransparencyCB);
     220           0 :     ClickReduceGradientsCBHdl(m_pReduceGradientsCB);
     221           0 :     ClickReduceBitmapsCBHdl(m_pReduceBitmapsCB);
     222           0 : }
     223             : 
     224           0 : void SfxCommonPrintOptionsTabPage::ImplSaveControls( PrinterOptions* pCurrentOptions )
     225             : {
     226           0 :     pCurrentOptions->SetReduceTransparency( m_pReduceTransparencyCB->IsChecked() );
     227           0 :     pCurrentOptions->SetReducedTransparencyMode( m_pReduceTransparencyAutoRB->IsChecked() ? PRINTER_TRANSPARENCY_AUTO : PRINTER_TRANSPARENCY_NONE );
     228           0 :     pCurrentOptions->SetReduceGradients( m_pReduceGradientsCB->IsChecked() );
     229           0 :     pCurrentOptions->SetReducedGradientMode( m_pReduceGradientsStripesRB->IsChecked() ? PRINTER_GRADIENT_STRIPES : PRINTER_GRADIENT_COLOR  );
     230           0 :     pCurrentOptions->SetReducedGradientStepCount( (sal_uInt16) m_pReduceGradientsStepCountNF->GetValue() );
     231           0 :     pCurrentOptions->SetReduceBitmaps( m_pReduceBitmapsCB->IsChecked() );
     232           0 :     pCurrentOptions->SetReducedBitmapMode( m_pReduceBitmapsOptimalRB->IsChecked() ? PRINTER_BITMAP_OPTIMAL :
     233           0 :                                            ( m_pReduceBitmapsNormalRB->IsChecked() ? PRINTER_BITMAP_NORMAL : PRINTER_BITMAP_RESOLUTION ) );
     234           0 :     pCurrentOptions->SetReducedBitmapResolution( aDPIArray[ std::min( (sal_uInt16) m_pReduceBitmapsResolutionLB->GetSelectEntryPos(),
     235           0 :                                                             (sal_uInt16)( (sizeof (aDPIArray) / sizeof (aDPIArray[0])) - 1 ) ) ] );
     236           0 :     pCurrentOptions->SetReducedBitmapIncludesTransparency( m_pReduceBitmapsTransparencyCB->IsChecked() );
     237           0 :     pCurrentOptions->SetConvertToGreyscales( m_pConvertToGreyscalesCB->IsChecked() );
     238           0 :     bool bOrigBackEnd = pCurrentOptions->IsPDFAsStandardPrintJobFormat();
     239           0 :     if (bOrigBackEnd != m_pPDFCB->IsChecked())
     240             :     {
     241           0 :         pCurrentOptions->SetPDFAsStandardPrintJobFormat( m_pPDFCB->IsChecked() );
     242             :             svtools::executeRestartDialog(
     243             :                 comphelper::getProcessComponentContext(), 0,
     244           0 :                 svtools::RESTART_REASON_PDF_AS_STANDARD_JOB_FORMAT);
     245             :     }
     246           0 : }
     247             : 
     248           0 : IMPL_LINK( SfxCommonPrintOptionsTabPage, ClickReduceTransparencyCBHdl, CheckBox*, pBox )
     249             : {
     250             :     (void)pBox; //unused
     251           0 :     const bool bReduceTransparency = m_pReduceTransparencyCB->IsChecked();
     252             : 
     253           0 :     m_pReduceTransparencyAutoRB->Enable( bReduceTransparency );
     254           0 :     m_pReduceTransparencyNoneRB->Enable( bReduceTransparency );
     255             : 
     256           0 :     m_pTransparencyCB->Enable( !bReduceTransparency );
     257             : 
     258           0 :     return 0;
     259             : }
     260             : 
     261           0 : IMPL_LINK( SfxCommonPrintOptionsTabPage, ClickReduceGradientsCBHdl, CheckBox*, pBox )
     262             : {
     263             :     (void)pBox; //unused
     264           0 :     const bool bEnable = m_pReduceGradientsCB->IsChecked();
     265             : 
     266           0 :     m_pReduceGradientsStripesRB->Enable( bEnable );
     267           0 :     m_pReduceGradientsColorRB->Enable( bEnable );
     268           0 :     m_pReduceGradientsStepCountNF->Enable( bEnable );
     269             : 
     270           0 :     ToggleReduceGradientsStripesRBHdl(m_pReduceGradientsStripesRB);
     271             : 
     272           0 :     return 0;
     273             : }
     274             : 
     275           0 : IMPL_LINK( SfxCommonPrintOptionsTabPage, ClickReduceBitmapsCBHdl, CheckBox*, pBox )
     276             : {
     277             :     (void)pBox; //unused
     278           0 :     const bool bEnable = m_pReduceBitmapsCB->IsChecked();
     279             : 
     280           0 :     m_pReduceBitmapsOptimalRB->Enable( bEnable );
     281           0 :     m_pReduceBitmapsNormalRB->Enable( bEnable );
     282           0 :     m_pReduceBitmapsResolutionRB->Enable( bEnable );
     283           0 :     m_pReduceBitmapsTransparencyCB->Enable( bEnable );
     284           0 :     m_pReduceBitmapsResolutionLB->Enable( bEnable );
     285             : 
     286           0 :     ToggleReduceBitmapsResolutionRBHdl(m_pReduceBitmapsResolutionRB);
     287             : 
     288           0 :     return 0;
     289             : }
     290             : 
     291           0 : IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleReduceGradientsStripesRBHdl, RadioButton*, pButton )
     292             : {
     293             :     (void)pButton; //unused
     294           0 :     const bool bEnable = m_pReduceGradientsCB->IsChecked() && m_pReduceGradientsStripesRB->IsChecked();
     295             : 
     296           0 :     m_pReduceGradientsStepCountNF->Enable( bEnable );
     297             : 
     298           0 :     return 0;
     299             : }
     300             : 
     301           0 : IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleReduceBitmapsResolutionRBHdl, RadioButton*, pButton )
     302             : {
     303             :     (void)pButton; //unused
     304           0 :     const bool bEnable = m_pReduceBitmapsCB->IsChecked() && m_pReduceBitmapsResolutionRB->IsChecked();
     305             : 
     306           0 :     m_pReduceBitmapsResolutionLB->Enable( bEnable );
     307             : 
     308           0 :     return 0;
     309             : }
     310             : 
     311           0 : IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleOutputPrinterRBHdl, RadioButton*, pButton )
     312             : {
     313           0 :     if( pButton->IsChecked() )
     314             :     {
     315           0 :         ImplUpdateControls( &maPrinterOptions );
     316           0 :         bOutputForPrinter = true;
     317             :     }
     318             :     else
     319           0 :         ImplSaveControls( &maPrinterOptions );
     320             : 
     321           0 :     return 0;
     322             : }
     323             : 
     324           0 : IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleOutputPrintFileRBHdl, RadioButton*, pButton )
     325             : {
     326           0 :     if( pButton->IsChecked() )
     327             :     {
     328           0 :         ImplUpdateControls( &maPrintFileOptions );
     329           0 :         bOutputForPrinter = false;
     330           0 :         m_pPDFCB->Disable();
     331             :     }
     332             :     else
     333             :     {
     334           0 :         ImplSaveControls( &maPrintFileOptions );
     335           0 :         m_pPDFCB->Enable();
     336             :     }
     337             : 
     338           0 :     return 0;
     339         951 : }
     340             : 
     341             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10