nss: upgrade to release 3.73
[LibreOffice.git] / sfx2 / source / dialog / printopt.cxx
blob5f4025fb57c00901549845f8e574e5f3d9b0877d
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 <officecfg/Office/Common.hxx>
23 #include <svtools/printoptions.hxx>
24 #include <svtools/restartdialog.hxx>
26 #include <comphelper/processfactory.hxx>
28 #include <sfx2/printopt.hxx>
30 static sal_uInt16 aDPIArray[] = { 72, 96, 150, 200, 300, 600 };
31 static bool bOutputForPrinter = true;
33 #define DPI_COUNT SAL_N_ELEMENTS(aDPIArray)
35 SfxCommonPrintOptionsTabPage::SfxCommonPrintOptionsTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
36 : SfxTabPage(pPage, pController, "sfx/ui/optprintpage.ui", "OptPrintPage", &rSet)
37 , m_xPrinterOutputRB(m_xBuilder->weld_radio_button("printer"))
38 , m_xPrintFileOutputRB(m_xBuilder->weld_radio_button("file"))
39 , m_xReduceTransparencyCB(m_xBuilder->weld_check_button("reducetrans"))
40 , m_xReduceTransparencyAutoRB(m_xBuilder->weld_radio_button("reducetransauto"))
41 , m_xReduceTransparencyNoneRB(m_xBuilder->weld_radio_button("reducetransnone"))
42 , m_xReduceGradientsCB(m_xBuilder->weld_check_button("reducegrad"))
43 , m_xReduceGradientsStripesRB(m_xBuilder->weld_radio_button("reducegradstripes"))
44 , m_xReduceGradientsColorRB(m_xBuilder->weld_radio_button("reducegradcolor"))
45 , m_xReduceGradientsStepCountNF(m_xBuilder->weld_spin_button("reducegradstep"))
46 , m_xReduceBitmapsCB(m_xBuilder->weld_check_button("reducebitmap"))
47 , m_xReduceBitmapsOptimalRB(m_xBuilder->weld_radio_button("reducebitmapoptimal"))
48 , m_xReduceBitmapsNormalRB(m_xBuilder->weld_radio_button("reducebitmapnormal"))
49 , m_xReduceBitmapsResolutionRB(m_xBuilder->weld_radio_button("reducebitmapresol"))
50 , m_xReduceBitmapsResolutionLB(m_xBuilder->weld_combo_box("reducebitmapdpi"))
51 , m_xReduceBitmapsTransparencyCB(m_xBuilder->weld_check_button("reducebitmaptrans"))
52 , m_xConvertToGreyscalesCB(m_xBuilder->weld_check_button("converttogray"))
53 , m_xPDFCB(m_xBuilder->weld_check_button("pdf"))
54 , m_xPaperSizeCB(m_xBuilder->weld_check_button("papersize"))
55 , m_xPaperOrientationCB(m_xBuilder->weld_check_button("paperorient"))
56 , m_xTransparencyCB(m_xBuilder->weld_check_button("trans"))
58 #ifndef ENABLE_CUPS
59 m_xPDFCB->hide();
60 #endif
62 if( bOutputForPrinter )
64 m_xPrinterOutputRB->set_active(true);
66 else
68 m_xPrintFileOutputRB->set_active(true);
69 m_xPDFCB->set_sensitive(false);
72 m_xPrinterOutputRB->connect_toggled( LINK( this, SfxCommonPrintOptionsTabPage, ToggleOutputPrinterRBHdl ) );
73 m_xPrintFileOutputRB->connect_toggled( LINK( this, SfxCommonPrintOptionsTabPage, ToggleOutputPrintFileRBHdl ) );
75 m_xReduceTransparencyCB->connect_clicked( LINK( this, SfxCommonPrintOptionsTabPage, ClickReduceTransparencyCBHdl ) );
76 m_xReduceGradientsCB->connect_clicked( LINK( this, SfxCommonPrintOptionsTabPage, ClickReduceGradientsCBHdl ) );
77 m_xReduceBitmapsCB->connect_clicked( LINK( this, SfxCommonPrintOptionsTabPage, ClickReduceBitmapsCBHdl ) );
79 m_xReduceGradientsStripesRB->connect_toggled( LINK( this, SfxCommonPrintOptionsTabPage, ToggleReduceGradientsStripesRBHdl ) );
80 m_xReduceBitmapsResolutionRB->connect_toggled( LINK( this, SfxCommonPrintOptionsTabPage, ToggleReduceBitmapsResolutionRBHdl ) );
83 SfxCommonPrintOptionsTabPage::~SfxCommonPrintOptionsTabPage()
87 std::unique_ptr<SfxTabPage> SfxCommonPrintOptionsTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet)
89 return std::make_unique<SfxCommonPrintOptionsTabPage>(pPage, pController, *rAttrSet);
92 bool SfxCommonPrintOptionsTabPage::FillItemSet( SfxItemSet* /*rSet*/ )
94 SvtPrinterOptions aPrinterOptions;
95 SvtPrintFileOptions aPrintFileOptions;
97 std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
99 if( m_xPaperSizeCB->get_state_changed_from_saved())
100 officecfg::Office::Common::Print::Warning::PaperSize::set(m_xPaperSizeCB->get_active(), batch);
101 if( m_xPaperOrientationCB->get_state_changed_from_saved() )
102 officecfg::Office::Common::Print::Warning::PaperOrientation::set(m_xPaperOrientationCB->get_active(), batch);
103 if( m_xTransparencyCB->get_state_changed_from_saved() )
104 officecfg::Office::Common::Print::Warning::Transparency::set(m_xTransparencyCB->get_active(), batch);
106 batch->commit();
108 ImplSaveControls( m_xPrinterOutputRB->get_active() ? &maPrinterOptions : &maPrintFileOptions );
110 aPrinterOptions.SetPrinterOptions( maPrinterOptions );
111 aPrintFileOptions.SetPrinterOptions( maPrintFileOptions );
113 return false;
116 void SfxCommonPrintOptionsTabPage::Reset( const SfxItemSet* /*rSet*/ )
118 m_xPaperSizeCB->set_active(officecfg::Office::Common::Print::Warning::PaperSize::get());
119 m_xPaperOrientationCB->set_active(officecfg::Office::Common::Print::Warning::PaperOrientation::get());
120 m_xTransparencyCB->set_active(officecfg::Office::Common::Print::Warning::Transparency::get());
122 m_xPaperSizeCB->save_state();
123 m_xPaperOrientationCB->save_state();
124 m_xTransparencyCB->save_state();
126 SvtBasePrintOptions::GetPrinterOptions( maPrinterOptions );
127 SvtBasePrintOptions::GetPrinterOptions( maPrintFileOptions );
128 if(m_xPrintFileOutputRB->get_active()){
129 m_xPrinterOutputRB->set_active(true);
132 ImplUpdateControls( m_xPrinterOutputRB->get_active() ? &maPrinterOptions : &maPrintFileOptions );
135 DeactivateRC SfxCommonPrintOptionsTabPage::DeactivatePage( SfxItemSet* pItemSet )
137 if( pItemSet )
138 FillItemSet( pItemSet );
140 return DeactivateRC::LeavePage;
143 void SfxCommonPrintOptionsTabPage::ImplUpdateControls( const PrinterOptions* pCurrentOptions )
145 m_xReduceTransparencyCB->set_active( pCurrentOptions->IsReduceTransparency() );
147 if( pCurrentOptions->GetReducedTransparencyMode() == PrinterTransparencyMode::Auto )
148 m_xReduceTransparencyAutoRB->set_active(true);
149 else
150 m_xReduceTransparencyNoneRB->set_active(true);
152 m_xReduceGradientsCB->set_active( pCurrentOptions->IsReduceGradients() );
154 if( pCurrentOptions->GetReducedGradientMode() == PrinterGradientMode::Stripes )
155 m_xReduceGradientsStripesRB->set_active(true);
156 else
157 m_xReduceGradientsColorRB->set_active(true);
159 m_xReduceGradientsStepCountNF->set_value(pCurrentOptions->GetReducedGradientStepCount());
161 m_xReduceBitmapsCB->set_active( pCurrentOptions->IsReduceBitmaps() );
163 if( pCurrentOptions->GetReducedBitmapMode() == PrinterBitmapMode::Optimal )
164 m_xReduceBitmapsOptimalRB->set_active(true);
165 else if( pCurrentOptions->GetReducedBitmapMode() == PrinterBitmapMode::Normal )
166 m_xReduceBitmapsNormalRB->set_active(true);
167 else
168 m_xReduceBitmapsResolutionRB->set_active(true);
170 const sal_uInt16 nDPI = pCurrentOptions->GetReducedBitmapResolution();
172 if( nDPI < aDPIArray[ 0 ] )
173 m_xReduceBitmapsResolutionLB->set_active(0);
174 else
176 for( int i = DPI_COUNT - 1; i >= 0; i-- )
178 if( nDPI >= aDPIArray[ i ] )
180 m_xReduceBitmapsResolutionLB->set_active(i);
181 i = -1;
186 m_xReduceBitmapsTransparencyCB->set_active( pCurrentOptions->IsReducedBitmapIncludesTransparency() );
187 m_xConvertToGreyscalesCB->set_active( pCurrentOptions->IsConvertToGreyscales() );
188 m_xPDFCB->set_active( pCurrentOptions->IsPDFAsStandardPrintJobFormat() );
190 ClickReduceTransparencyCBHdl(*m_xReduceTransparencyCB);
191 ClickReduceGradientsCBHdl(*m_xReduceGradientsCB);
192 ClickReduceBitmapsCBHdl(*m_xReduceBitmapsCB);
195 void SfxCommonPrintOptionsTabPage::ImplSaveControls( PrinterOptions* pCurrentOptions )
197 pCurrentOptions->SetReduceTransparency( m_xReduceTransparencyCB->get_active() );
198 pCurrentOptions->SetReducedTransparencyMode( m_xReduceTransparencyAutoRB->get_active() ? PrinterTransparencyMode::Auto : PrinterTransparencyMode::NONE );
199 pCurrentOptions->SetReduceGradients( m_xReduceGradientsCB->get_active() );
200 pCurrentOptions->SetReducedGradientMode( m_xReduceGradientsStripesRB->get_active() ? PrinterGradientMode::Stripes : PrinterGradientMode::Color );
201 pCurrentOptions->SetReducedGradientStepCount(m_xReduceGradientsStepCountNF->get_value());
202 pCurrentOptions->SetReduceBitmaps( m_xReduceBitmapsCB->get_active() );
203 pCurrentOptions->SetReducedBitmapMode( m_xReduceBitmapsOptimalRB->get_active() ? PrinterBitmapMode::Optimal :
204 ( m_xReduceBitmapsNormalRB->get_active() ? PrinterBitmapMode::Normal : PrinterBitmapMode::Resolution ) );
205 pCurrentOptions->SetReducedBitmapResolution( aDPIArray[ std::min<sal_uInt16>( m_xReduceBitmapsResolutionLB->get_active(),
206 SAL_N_ELEMENTS(aDPIArray) - 1 ) ] );
207 pCurrentOptions->SetReducedBitmapIncludesTransparency( m_xReduceBitmapsTransparencyCB->get_active() );
208 pCurrentOptions->SetConvertToGreyscales( m_xConvertToGreyscalesCB->get_active() );
209 bool bOrigBackEnd = pCurrentOptions->IsPDFAsStandardPrintJobFormat();
210 if (bOrigBackEnd != m_xPDFCB->get_active())
212 pCurrentOptions->SetPDFAsStandardPrintJobFormat( m_xPDFCB->get_active() );
213 svtools::executeRestartDialog(
214 comphelper::getProcessComponentContext(), nullptr,
215 svtools::RESTART_REASON_PDF_AS_STANDARD_JOB_FORMAT);
219 IMPL_LINK_NOARG( SfxCommonPrintOptionsTabPage, ClickReduceTransparencyCBHdl, weld::Button&, void )
221 const bool bReduceTransparency = m_xReduceTransparencyCB->get_active();
223 m_xReduceTransparencyAutoRB->set_sensitive( bReduceTransparency );
224 m_xReduceTransparencyNoneRB->set_sensitive( bReduceTransparency );
226 m_xTransparencyCB->set_sensitive( !bReduceTransparency );
229 IMPL_LINK_NOARG( SfxCommonPrintOptionsTabPage, ClickReduceGradientsCBHdl, weld::Button&, void )
231 const bool bEnable = m_xReduceGradientsCB->get_active();
233 m_xReduceGradientsStripesRB->set_sensitive( bEnable );
234 m_xReduceGradientsColorRB->set_sensitive( bEnable );
235 m_xReduceGradientsStepCountNF->set_sensitive( bEnable );
237 ToggleReduceGradientsStripesRBHdl(*m_xReduceGradientsStripesRB);
240 IMPL_LINK_NOARG( SfxCommonPrintOptionsTabPage, ClickReduceBitmapsCBHdl, weld::Button&, void )
242 const bool bEnable = m_xReduceBitmapsCB->get_active();
244 m_xReduceBitmapsOptimalRB->set_sensitive( bEnable );
245 m_xReduceBitmapsNormalRB->set_sensitive( bEnable );
246 m_xReduceBitmapsResolutionRB->set_sensitive( bEnable );
247 m_xReduceBitmapsTransparencyCB->set_sensitive( bEnable );
248 m_xReduceBitmapsResolutionLB->set_sensitive( bEnable );
250 ToggleReduceBitmapsResolutionRBHdl(*m_xReduceBitmapsResolutionRB);
253 IMPL_LINK_NOARG( SfxCommonPrintOptionsTabPage, ToggleReduceGradientsStripesRBHdl, weld::ToggleButton&, void )
255 const bool bEnable = m_xReduceGradientsCB->get_active() && m_xReduceGradientsStripesRB->get_active();
257 m_xReduceGradientsStepCountNF->set_sensitive(bEnable);
260 IMPL_LINK_NOARG( SfxCommonPrintOptionsTabPage, ToggleReduceBitmapsResolutionRBHdl, weld::ToggleButton&, void )
262 const bool bEnable = m_xReduceBitmapsCB->get_active() && m_xReduceBitmapsResolutionRB->get_active();
264 m_xReduceBitmapsResolutionLB->set_sensitive(bEnable);
267 IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleOutputPrinterRBHdl, weld::ToggleButton&, rButton, void )
269 if (rButton.get_active())
271 ImplUpdateControls( &maPrinterOptions );
272 bOutputForPrinter = true;
274 else
275 ImplSaveControls( &maPrinterOptions );
278 IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleOutputPrintFileRBHdl, weld::ToggleButton&, rButton, void )
280 if (rButton.get_active())
282 ImplUpdateControls( &maPrintFileOptions );
283 bOutputForPrinter = false;
284 m_xPDFCB->set_sensitive(false);
286 else
288 ImplSaveControls( &maPrintFileOptions );
289 m_xPDFCB->set_sensitive(true);
293 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */