bump product version to 5.0.4.1
[LibreOffice.git] / sfx2 / source / dialog / printopt.cxx
blob8515099418890db3e8c786ffc2878d82ac32e1cc
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 bool bOutputForPrinter = true;
37 #define DPI_COUNT (sizeof(aDPIArray)/sizeof(aDPIArray[0 ]))
39 SfxCommonPrintOptionsTabPage::SfxCommonPrintOptionsTabPage( vcl::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( true );
71 else
73 m_pPrintFileOutputRB->Check( 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()
90 disposeOnce();
93 void SfxCommonPrintOptionsTabPage::dispose()
95 m_pPrinterOutputRB.clear();
96 m_pPrintFileOutputRB.clear();
97 m_pReduceTransparencyCB.clear();
98 m_pReduceTransparencyAutoRB.clear();
99 m_pReduceTransparencyNoneRB.clear();
100 m_pReduceGradientsCB.clear();
101 m_pReduceGradientsStripesRB.clear();
102 m_pReduceGradientsColorRB.clear();
103 m_pReduceGradientsStepCountNF.clear();
104 m_pReduceBitmapsCB.clear();
105 m_pReduceBitmapsOptimalRB.clear();
106 m_pReduceBitmapsNormalRB.clear();
107 m_pReduceBitmapsResolutionRB.clear();
108 m_pReduceBitmapsResolutionLB.clear();
109 m_pReduceBitmapsTransparencyCB.clear();
110 m_pConvertToGreyscalesCB.clear();
111 m_pPDFCB.clear();
112 m_pPaperSizeCB.clear();
113 m_pPaperOrientationCB.clear();
114 m_pTransparencyCB.clear();
115 SfxTabPage::dispose();
118 VclPtr<SfxTabPage> SfxCommonPrintOptionsTabPage::Create( vcl::Window* pParent, const SfxItemSet* rAttrSet )
120 return VclPtr<SfxCommonPrintOptionsTabPage>::Create( pParent, *rAttrSet );
123 vcl::Window* SfxCommonPrintOptionsTabPage::GetParentLabeledBy( const vcl::Window* pWindow ) const
125 if ( pWindow == (vcl::Window *)m_pReduceGradientsStepCountNF )
126 return m_pReduceGradientsStripesRB;
127 else if ( pWindow == (vcl::Window *)m_pReduceBitmapsResolutionLB )
128 return m_pReduceBitmapsResolutionRB;
129 else
130 return SfxTabPage::GetParentLabeledBy( pWindow );
133 vcl::Window* SfxCommonPrintOptionsTabPage::GetParentLabelFor( const vcl::Window* pWindow ) const
135 if ( pWindow == (vcl::Window *)m_pReduceGradientsStripesRB )
136 return m_pReduceGradientsStepCountNF;
137 else if ( pWindow == (vcl::Window *)m_pReduceBitmapsResolutionRB )
138 return m_pReduceBitmapsResolutionLB;
139 else
140 return SfxTabPage::GetParentLabelFor( pWindow );
143 bool SfxCommonPrintOptionsTabPage::FillItemSet( SfxItemSet* /*rSet*/ )
145 SvtPrintWarningOptions aWarnOptions;
146 SvtPrinterOptions aPrinterOptions;
147 SvtPrintFileOptions aPrintFileOptions;
148 bool bModified = false;
151 if( m_pPaperSizeCB->IsValueChangedFromSaved())
152 aWarnOptions.SetPaperSize(m_pPaperSizeCB->IsChecked());
153 if( m_pPaperOrientationCB->IsValueChangedFromSaved() )
154 aWarnOptions.SetPaperOrientation(m_pPaperOrientationCB->IsChecked());
156 if( m_pTransparencyCB->IsValueChangedFromSaved() )
157 aWarnOptions.SetTransparency( m_pTransparencyCB->IsChecked() );
159 ImplSaveControls( m_pPrinterOutputRB->IsChecked() ? &maPrinterOptions : &maPrintFileOptions );
161 aPrinterOptions.SetPrinterOptions( maPrinterOptions );
162 aPrintFileOptions.SetPrinterOptions( maPrintFileOptions );
164 return bModified;
167 void SfxCommonPrintOptionsTabPage::Reset( const SfxItemSet* /*rSet*/ )
169 SvtPrintWarningOptions aWarnOptions;
170 SvtPrinterOptions aPrinterOptions;
171 SvtPrintFileOptions aPrintFileOptions;
173 m_pPaperSizeCB->Check( aWarnOptions.IsPaperSize() );
174 m_pPaperOrientationCB->Check( aWarnOptions.IsPaperOrientation() );
176 m_pTransparencyCB->Check( aWarnOptions.IsTransparency() );
178 m_pPaperSizeCB->SaveValue();
179 m_pPaperOrientationCB->SaveValue();
180 m_pTransparencyCB->SaveValue();
182 aPrinterOptions.GetPrinterOptions( maPrinterOptions );
183 aPrintFileOptions.GetPrinterOptions( maPrintFileOptions );
185 ImplUpdateControls( m_pPrinterOutputRB->IsChecked() ? &maPrinterOptions : &maPrintFileOptions );
188 SfxTabPage::sfxpg SfxCommonPrintOptionsTabPage::DeactivatePage( SfxItemSet* pItemSet )
190 if( pItemSet )
191 FillItemSet( pItemSet );
193 return LEAVE_PAGE;
196 void SfxCommonPrintOptionsTabPage::ImplUpdateControls( const PrinterOptions* pCurrentOptions )
198 m_pReduceTransparencyCB->Check( pCurrentOptions->IsReduceTransparency() );
200 if( pCurrentOptions->GetReducedTransparencyMode() == PRINTER_TRANSPARENCY_AUTO )
201 m_pReduceTransparencyAutoRB->Check( true );
202 else
203 m_pReduceTransparencyNoneRB->Check( true );
205 m_pReduceGradientsCB->Check( pCurrentOptions->IsReduceGradients() );
207 if( pCurrentOptions->GetReducedGradientMode() == PRINTER_GRADIENT_STRIPES )
208 m_pReduceGradientsStripesRB->Check( true );
209 else
210 m_pReduceGradientsColorRB->Check( true );
212 m_pReduceGradientsStepCountNF->SetValue( pCurrentOptions->GetReducedGradientStepCount() );
214 m_pReduceBitmapsCB->Check( pCurrentOptions->IsReduceBitmaps() );
216 if( pCurrentOptions->GetReducedBitmapMode() == PRINTER_BITMAP_OPTIMAL )
217 m_pReduceBitmapsOptimalRB->Check( true );
218 else if( pCurrentOptions->GetReducedBitmapMode() == PRINTER_BITMAP_NORMAL )
219 m_pReduceBitmapsNormalRB->Check( true );
220 else
221 m_pReduceBitmapsResolutionRB->Check( true );
223 const sal_uInt16 nDPI = pCurrentOptions->GetReducedBitmapResolution();
225 if( nDPI < aDPIArray[ 0 ] )
226 m_pReduceBitmapsResolutionLB->SelectEntryPos( 0 );
227 else
229 for( long i = ( DPI_COUNT - 1 ); i >= 0; i-- )
231 if( nDPI >= aDPIArray[ i ] )
233 m_pReduceBitmapsResolutionLB->SelectEntryPos( (sal_uInt16) i );
234 i = -1;
239 m_pReduceBitmapsResolutionLB->SetText( m_pReduceBitmapsResolutionLB->GetSelectEntry() );
241 m_pReduceBitmapsTransparencyCB->Check( pCurrentOptions->IsReducedBitmapIncludesTransparency() );
242 m_pConvertToGreyscalesCB->Check( pCurrentOptions->IsConvertToGreyscales() );
243 m_pPDFCB->Check( pCurrentOptions->IsPDFAsStandardPrintJobFormat() );
245 ClickReduceTransparencyCBHdl(m_pReduceTransparencyCB);
246 ClickReduceGradientsCBHdl(m_pReduceGradientsCB);
247 ClickReduceBitmapsCBHdl(m_pReduceBitmapsCB);
250 void SfxCommonPrintOptionsTabPage::ImplSaveControls( PrinterOptions* pCurrentOptions )
252 pCurrentOptions->SetReduceTransparency( m_pReduceTransparencyCB->IsChecked() );
253 pCurrentOptions->SetReducedTransparencyMode( m_pReduceTransparencyAutoRB->IsChecked() ? PRINTER_TRANSPARENCY_AUTO : PRINTER_TRANSPARENCY_NONE );
254 pCurrentOptions->SetReduceGradients( m_pReduceGradientsCB->IsChecked() );
255 pCurrentOptions->SetReducedGradientMode( m_pReduceGradientsStripesRB->IsChecked() ? PRINTER_GRADIENT_STRIPES : PRINTER_GRADIENT_COLOR );
256 pCurrentOptions->SetReducedGradientStepCount( (sal_uInt16) m_pReduceGradientsStepCountNF->GetValue() );
257 pCurrentOptions->SetReduceBitmaps( m_pReduceBitmapsCB->IsChecked() );
258 pCurrentOptions->SetReducedBitmapMode( m_pReduceBitmapsOptimalRB->IsChecked() ? PRINTER_BITMAP_OPTIMAL :
259 ( m_pReduceBitmapsNormalRB->IsChecked() ? PRINTER_BITMAP_NORMAL : PRINTER_BITMAP_RESOLUTION ) );
260 pCurrentOptions->SetReducedBitmapResolution( aDPIArray[ std::min( (sal_uInt16) m_pReduceBitmapsResolutionLB->GetSelectEntryPos(),
261 (sal_uInt16)( (sizeof (aDPIArray) / sizeof (aDPIArray[0])) - 1 ) ) ] );
262 pCurrentOptions->SetReducedBitmapIncludesTransparency( m_pReduceBitmapsTransparencyCB->IsChecked() );
263 pCurrentOptions->SetConvertToGreyscales( m_pConvertToGreyscalesCB->IsChecked() );
264 bool bOrigBackEnd = pCurrentOptions->IsPDFAsStandardPrintJobFormat();
265 if (bOrigBackEnd != m_pPDFCB->IsChecked())
267 pCurrentOptions->SetPDFAsStandardPrintJobFormat( m_pPDFCB->IsChecked() );
268 svtools::executeRestartDialog(
269 comphelper::getProcessComponentContext(), 0,
270 svtools::RESTART_REASON_PDF_AS_STANDARD_JOB_FORMAT);
274 IMPL_LINK( SfxCommonPrintOptionsTabPage, ClickReduceTransparencyCBHdl, CheckBox*, pBox )
276 (void)pBox; //unused
277 const bool bReduceTransparency = m_pReduceTransparencyCB->IsChecked();
279 m_pReduceTransparencyAutoRB->Enable( bReduceTransparency );
280 m_pReduceTransparencyNoneRB->Enable( bReduceTransparency );
282 m_pTransparencyCB->Enable( !bReduceTransparency );
284 return 0;
287 IMPL_LINK( SfxCommonPrintOptionsTabPage, ClickReduceGradientsCBHdl, CheckBox*, pBox )
289 (void)pBox; //unused
290 const bool bEnable = m_pReduceGradientsCB->IsChecked();
292 m_pReduceGradientsStripesRB->Enable( bEnable );
293 m_pReduceGradientsColorRB->Enable( bEnable );
294 m_pReduceGradientsStepCountNF->Enable( bEnable );
296 ToggleReduceGradientsStripesRBHdl(m_pReduceGradientsStripesRB);
298 return 0;
301 IMPL_LINK( SfxCommonPrintOptionsTabPage, ClickReduceBitmapsCBHdl, CheckBox*, pBox )
303 (void)pBox; //unused
304 const bool bEnable = m_pReduceBitmapsCB->IsChecked();
306 m_pReduceBitmapsOptimalRB->Enable( bEnable );
307 m_pReduceBitmapsNormalRB->Enable( bEnable );
308 m_pReduceBitmapsResolutionRB->Enable( bEnable );
309 m_pReduceBitmapsTransparencyCB->Enable( bEnable );
310 m_pReduceBitmapsResolutionLB->Enable( bEnable );
312 ToggleReduceBitmapsResolutionRBHdl(m_pReduceBitmapsResolutionRB);
314 return 0;
317 IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleReduceGradientsStripesRBHdl, RadioButton*, pButton )
319 (void)pButton; //unused
320 const bool bEnable = m_pReduceGradientsCB->IsChecked() && m_pReduceGradientsStripesRB->IsChecked();
322 m_pReduceGradientsStepCountNF->Enable( bEnable );
324 return 0;
327 IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleReduceBitmapsResolutionRBHdl, RadioButton*, pButton )
329 (void)pButton; //unused
330 const bool bEnable = m_pReduceBitmapsCB->IsChecked() && m_pReduceBitmapsResolutionRB->IsChecked();
332 m_pReduceBitmapsResolutionLB->Enable( bEnable );
334 return 0;
337 IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleOutputPrinterRBHdl, RadioButton*, pButton )
339 if( pButton->IsChecked() )
341 ImplUpdateControls( &maPrinterOptions );
342 bOutputForPrinter = true;
344 else
345 ImplSaveControls( &maPrinterOptions );
347 return 0;
350 IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleOutputPrintFileRBHdl, RadioButton*, pButton )
352 if( pButton->IsChecked() )
354 ImplUpdateControls( &maPrintFileOptions );
355 bOutputForPrinter = false;
356 m_pPDFCB->Disable();
358 else
360 ImplSaveControls( &maPrintFileOptions );
361 m_pPDFCB->Enable();
364 return 0;
367 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */