Bump version to 4.1-6
[LibreOffice.git] / sfx2 / source / dialog / printopt.cxx
blobdedd23f6ffcee97673623d21e42753e231ff6b20
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
28 #include <comphelper/processfactory.hxx>
30 #include "sfx2/sfxresid.hxx"
31 #include <sfx2/viewsh.hxx>
32 #include <sfx2/printopt.hxx>
34 static sal_uInt16 aDPIArray[] = { 72, 96, 150, 200, 300, 600 };
35 static sal_Bool bOutputForPrinter = sal_True;
37 #define DPI_COUNT (sizeof(aDPIArray)/sizeof(aDPIArray[0 ]))
39 SfxCommonPrintOptionsTabPage::SfxCommonPrintOptionsTabPage( Window* pParent, const SfxItemSet& rSet )
40 : SfxTabPage(pParent, "OptPrintPage", "sfx/ui/optprintpage.ui", rSet)
42 get(m_pPrinterOutputRB, "printer");
43 get(m_pPrintFileOutputRB, "file");
44 get(m_pReduceTransparencyCB, "reducetrans");
45 get(m_pReduceTransparencyAutoRB, "reducetransauto");
46 get(m_pReduceTransparencyNoneRB, "reducetransnone");
47 get(m_pReduceGradientsCB, "reducegrad");
48 get(m_pReduceGradientsStripesRB, "reducegradstripes");
49 get(m_pReduceGradientsColorRB, "reducegradcolor");
50 get(m_pReduceGradientsStepCountNF, "reducegradstep");
51 get(m_pReduceBitmapsCB, "reducebitmap");
52 get(m_pReduceBitmapsOptimalRB, "reducebitmapoptimal");
53 get(m_pReduceBitmapsNormalRB, "reducebitmapnormal");
54 get(m_pReduceBitmapsResolutionRB, "reducebitmapresol");
55 get(m_pReduceBitmapsResolutionLB, "reducebitmapdpi");
56 get(m_pReduceBitmapsTransparencyCB, "reducebitmaptrans");
57 get(m_pConvertToGreyscalesCB, "converttogray");
58 get(m_pPDFCB, "pdf");
59 get(m_pPaperSizeCB, "papersize");
60 get(m_pPaperOrientationCB, "paperorient");
61 get(m_pTransparencyCB, "trans");
63 #ifndef ENABLE_CUPS
64 m_pPDFCB->Hide();
65 #endif
67 if( bOutputForPrinter )
69 m_pPrinterOutputRB->Check( sal_True );
71 else
73 m_pPrintFileOutputRB->Check( sal_True );
74 m_pPDFCB->Disable();
77 m_pPrinterOutputRB->SetToggleHdl( LINK( this, SfxCommonPrintOptionsTabPage, ToggleOutputPrinterRBHdl ) );
78 m_pPrintFileOutputRB->SetToggleHdl( LINK( this, SfxCommonPrintOptionsTabPage, ToggleOutputPrintFileRBHdl ) );
80 m_pReduceTransparencyCB->SetClickHdl( LINK( this, SfxCommonPrintOptionsTabPage, ClickReduceTransparencyCBHdl ) );
81 m_pReduceGradientsCB->SetClickHdl( LINK( this, SfxCommonPrintOptionsTabPage, ClickReduceGradientsCBHdl ) );
82 m_pReduceBitmapsCB->SetClickHdl( LINK( this, SfxCommonPrintOptionsTabPage, ClickReduceBitmapsCBHdl ) );
84 m_pReduceGradientsStripesRB->SetToggleHdl( LINK( this, SfxCommonPrintOptionsTabPage, ToggleReduceGradientsStripesRBHdl ) );
85 m_pReduceBitmapsResolutionRB->SetToggleHdl( LINK( this, SfxCommonPrintOptionsTabPage, ToggleReduceBitmapsResolutionRBHdl ) );
88 SfxCommonPrintOptionsTabPage::~SfxCommonPrintOptionsTabPage()
92 SfxTabPage* SfxCommonPrintOptionsTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
94 return( new SfxCommonPrintOptionsTabPage( pParent, rAttrSet ) );
97 Window* SfxCommonPrintOptionsTabPage::GetParentLabeledBy( const Window* pWindow ) const
99 if ( pWindow == (Window *)m_pReduceGradientsStepCountNF )
100 return m_pReduceGradientsStripesRB;
101 else if ( pWindow == (Window *)m_pReduceBitmapsResolutionLB )
102 return m_pReduceBitmapsResolutionRB;
103 else
104 return SfxTabPage::GetParentLabeledBy( pWindow );
107 Window* SfxCommonPrintOptionsTabPage::GetParentLabelFor( const Window* pWindow ) const
109 if ( pWindow == (Window *)m_pReduceGradientsStripesRB )
110 return m_pReduceGradientsStepCountNF;
111 else if ( pWindow == (Window *)m_pReduceBitmapsResolutionRB )
112 return m_pReduceBitmapsResolutionLB;
113 else
114 return SfxTabPage::GetParentLabelFor( pWindow );
117 sal_Bool SfxCommonPrintOptionsTabPage::FillItemSet( SfxItemSet& /*rSet*/ )
119 SvtPrintWarningOptions aWarnOptions;
120 SvtPrinterOptions aPrinterOptions;
121 SvtPrintFileOptions aPrintFileOptions;
122 sal_Bool bModified = sal_False;
125 if( m_pPaperSizeCB->IsChecked() != m_pPaperSizeCB->GetSavedValue())
126 aWarnOptions.SetPaperSize(m_pPaperSizeCB->IsChecked());
127 if( m_pPaperOrientationCB->IsChecked() != m_pPaperOrientationCB->GetSavedValue() )
128 aWarnOptions.SetPaperOrientation(m_pPaperOrientationCB->IsChecked());
130 if( m_pTransparencyCB->IsChecked() != m_pTransparencyCB->GetSavedValue() )
131 aWarnOptions.SetTransparency( m_pTransparencyCB->IsChecked() );
133 ImplSaveControls( m_pPrinterOutputRB->IsChecked() ? &maPrinterOptions : &maPrintFileOptions );
135 aPrinterOptions.SetPrinterOptions( maPrinterOptions );
136 aPrintFileOptions.SetPrinterOptions( maPrintFileOptions );
138 return bModified;
141 void SfxCommonPrintOptionsTabPage::Reset( const SfxItemSet& /*rSet*/ )
143 SvtPrintWarningOptions aWarnOptions;
144 SvtPrinterOptions aPrinterOptions;
145 SvtPrintFileOptions aPrintFileOptions;
147 m_pPaperSizeCB->Check( aWarnOptions.IsPaperSize() );
148 m_pPaperOrientationCB->Check( aWarnOptions.IsPaperOrientation() );
150 m_pTransparencyCB->Check( aWarnOptions.IsTransparency() );
152 m_pPaperSizeCB->SaveValue();
153 m_pPaperOrientationCB->SaveValue();
154 m_pTransparencyCB->SaveValue();
156 aPrinterOptions.GetPrinterOptions( maPrinterOptions );
157 aPrintFileOptions.GetPrinterOptions( maPrintFileOptions );
159 ImplUpdateControls( m_pPrinterOutputRB->IsChecked() ? &maPrinterOptions : &maPrintFileOptions );
162 int SfxCommonPrintOptionsTabPage::DeactivatePage( SfxItemSet* pItemSet )
164 if( pItemSet )
165 FillItemSet( *pItemSet );
167 return LEAVE_PAGE;
170 void SfxCommonPrintOptionsTabPage::ImplUpdateControls( const PrinterOptions* pCurrentOptions )
172 m_pReduceTransparencyCB->Check( pCurrentOptions->IsReduceTransparency() );
174 if( pCurrentOptions->GetReducedTransparencyMode() == PRINTER_TRANSPARENCY_AUTO )
175 m_pReduceTransparencyAutoRB->Check( sal_True );
176 else
177 m_pReduceTransparencyNoneRB->Check( sal_True );
179 m_pReduceGradientsCB->Check( pCurrentOptions->IsReduceGradients() );
181 if( pCurrentOptions->GetReducedGradientMode() == PRINTER_GRADIENT_STRIPES )
182 m_pReduceGradientsStripesRB->Check( sal_True );
183 else
184 m_pReduceGradientsColorRB->Check( sal_True );
186 m_pReduceGradientsStepCountNF->SetValue( pCurrentOptions->GetReducedGradientStepCount() );
188 m_pReduceBitmapsCB->Check( pCurrentOptions->IsReduceBitmaps() );
190 if( pCurrentOptions->GetReducedBitmapMode() == PRINTER_BITMAP_OPTIMAL )
191 m_pReduceBitmapsOptimalRB->Check( sal_True );
192 else if( pCurrentOptions->GetReducedBitmapMode() == PRINTER_BITMAP_NORMAL )
193 m_pReduceBitmapsNormalRB->Check( sal_True );
194 else
195 m_pReduceBitmapsResolutionRB->Check( sal_True );
197 const sal_uInt16 nDPI = pCurrentOptions->GetReducedBitmapResolution();
199 if( nDPI < aDPIArray[ 0 ] )
200 m_pReduceBitmapsResolutionLB->SelectEntryPos( 0 );
201 else
203 for( long i = ( DPI_COUNT - 1 ); i >= 0; i-- )
205 if( nDPI >= aDPIArray[ i ] )
207 m_pReduceBitmapsResolutionLB->SelectEntryPos( (sal_uInt16) i );
208 i = -1;
213 m_pReduceBitmapsResolutionLB->SetText( m_pReduceBitmapsResolutionLB->GetEntry( m_pReduceBitmapsResolutionLB->GetSelectEntryPos() ) );
215 m_pReduceBitmapsTransparencyCB->Check( pCurrentOptions->IsReducedBitmapIncludesTransparency() );
216 m_pConvertToGreyscalesCB->Check( pCurrentOptions->IsConvertToGreyscales() );
217 m_pPDFCB->Check( pCurrentOptions->IsPDFAsStandardPrintJobFormat() );
219 ClickReduceTransparencyCBHdl(m_pReduceTransparencyCB);
220 ClickReduceGradientsCBHdl(m_pReduceGradientsCB);
221 ClickReduceBitmapsCBHdl(m_pReduceBitmapsCB);
224 void SfxCommonPrintOptionsTabPage::ImplSaveControls( PrinterOptions* pCurrentOptions )
226 pCurrentOptions->SetReduceTransparency( m_pReduceTransparencyCB->IsChecked() );
227 pCurrentOptions->SetReducedTransparencyMode( m_pReduceTransparencyAutoRB->IsChecked() ? PRINTER_TRANSPARENCY_AUTO : PRINTER_TRANSPARENCY_NONE );
228 pCurrentOptions->SetReduceGradients( m_pReduceGradientsCB->IsChecked() );
229 pCurrentOptions->SetReducedGradientMode( m_pReduceGradientsStripesRB->IsChecked() ? PRINTER_GRADIENT_STRIPES : PRINTER_GRADIENT_COLOR );
230 pCurrentOptions->SetReducedGradientStepCount( (sal_uInt16) m_pReduceGradientsStepCountNF->GetValue() );
231 pCurrentOptions->SetReduceBitmaps( m_pReduceBitmapsCB->IsChecked() );
232 pCurrentOptions->SetReducedBitmapMode( m_pReduceBitmapsOptimalRB->IsChecked() ? PRINTER_BITMAP_OPTIMAL :
233 ( m_pReduceBitmapsNormalRB->IsChecked() ? PRINTER_BITMAP_NORMAL : PRINTER_BITMAP_RESOLUTION ) );
234 pCurrentOptions->SetReducedBitmapResolution( aDPIArray[ std::min( (sal_uInt16) m_pReduceBitmapsResolutionLB->GetSelectEntryPos(),
235 (sal_uInt16)( (sizeof (aDPIArray) / sizeof (aDPIArray[0])) - 1 ) ) ] );
236 pCurrentOptions->SetReducedBitmapIncludesTransparency( m_pReduceBitmapsTransparencyCB->IsChecked() );
237 pCurrentOptions->SetConvertToGreyscales( m_pConvertToGreyscalesCB->IsChecked() );
238 sal_Bool bOrigBackEnd = pCurrentOptions->IsPDFAsStandardPrintJobFormat();
239 if (bOrigBackEnd != m_pPDFCB->IsChecked())
241 pCurrentOptions->SetPDFAsStandardPrintJobFormat( m_pPDFCB->IsChecked() );
242 svtools::executeRestartDialog(
243 comphelper::getProcessComponentContext(), 0,
244 svtools::RESTART_REASON_PDF_AS_STANDARD_JOB_FORMAT);
248 IMPL_LINK( SfxCommonPrintOptionsTabPage, ClickReduceTransparencyCBHdl, CheckBox*, pBox )
250 (void)pBox; //unused
251 const sal_Bool bReduceTransparency = m_pReduceTransparencyCB->IsChecked();
253 m_pReduceTransparencyAutoRB->Enable( bReduceTransparency );
254 m_pReduceTransparencyNoneRB->Enable( bReduceTransparency );
256 m_pTransparencyCB->Enable( !bReduceTransparency );
258 return 0;
261 IMPL_LINK( SfxCommonPrintOptionsTabPage, ClickReduceGradientsCBHdl, CheckBox*, pBox )
263 (void)pBox; //unused
264 const sal_Bool bEnable = m_pReduceGradientsCB->IsChecked();
266 m_pReduceGradientsStripesRB->Enable( bEnable );
267 m_pReduceGradientsColorRB->Enable( bEnable );
268 m_pReduceGradientsStepCountNF->Enable( bEnable );
270 ToggleReduceGradientsStripesRBHdl(m_pReduceGradientsStripesRB);
272 return 0;
275 IMPL_LINK( SfxCommonPrintOptionsTabPage, ClickReduceBitmapsCBHdl, CheckBox*, pBox )
277 (void)pBox; //unused
278 const sal_Bool bEnable = m_pReduceBitmapsCB->IsChecked();
280 m_pReduceBitmapsOptimalRB->Enable( bEnable );
281 m_pReduceBitmapsNormalRB->Enable( bEnable );
282 m_pReduceBitmapsResolutionRB->Enable( bEnable );
283 m_pReduceBitmapsTransparencyCB->Enable( bEnable );
284 m_pReduceBitmapsResolutionLB->Enable( bEnable );
286 ToggleReduceBitmapsResolutionRBHdl(m_pReduceBitmapsResolutionRB);
288 return 0;
291 IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleReduceGradientsStripesRBHdl, RadioButton*, pButton )
293 (void)pButton; //unused
294 const sal_Bool bEnable = m_pReduceGradientsCB->IsChecked() && m_pReduceGradientsStripesRB->IsChecked();
296 m_pReduceGradientsStepCountNF->Enable( bEnable );
298 return 0;
301 IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleReduceBitmapsResolutionRBHdl, RadioButton*, pButton )
303 (void)pButton; //unused
304 const sal_Bool bEnable = m_pReduceBitmapsCB->IsChecked() && m_pReduceBitmapsResolutionRB->IsChecked();
306 m_pReduceBitmapsResolutionLB->Enable( bEnable );
308 return 0;
311 IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleOutputPrinterRBHdl, RadioButton*, pButton )
313 if( pButton->IsChecked() )
315 ImplUpdateControls( &maPrinterOptions );
316 bOutputForPrinter = sal_True;
318 else
319 ImplSaveControls( &maPrinterOptions );
321 return 0;
324 IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleOutputPrintFileRBHdl, RadioButton*, pButton )
326 if( pButton->IsChecked() )
328 ImplUpdateControls( &maPrintFileOptions );
329 bOutputForPrinter = sal_False;
330 m_pPDFCB->Disable();
332 else
334 ImplSaveControls( &maPrintFileOptions );
335 m_pPDFCB->Enable();
338 return 0;
341 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */