Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sfx2 / source / dialog / printopt.cxx
blobd804bdf8f202c9389e33743e8a5dce7def03a97e
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_xPaperSizeCB(m_xBuilder->weld_check_button("papersize"))
54 , m_xPaperOrientationCB(m_xBuilder->weld_check_button("paperorient"))
55 , m_xTransparencyCB(m_xBuilder->weld_check_button("trans"))
57 if (bOutputForPrinter)
58 m_xPrinterOutputRB->set_active(true);
59 else
60 m_xPrintFileOutputRB->set_active(true);
62 m_xPrinterOutputRB->connect_toggled( LINK( this, SfxCommonPrintOptionsTabPage, ToggleOutputPrinterRBHdl ) );
63 m_xPrintFileOutputRB->connect_toggled( LINK( this, SfxCommonPrintOptionsTabPage, ToggleOutputPrintFileRBHdl ) );
65 m_xReduceTransparencyCB->connect_toggled( LINK( this, SfxCommonPrintOptionsTabPage, ClickReduceTransparencyCBHdl ) );
66 m_xReduceGradientsCB->connect_toggled( LINK( this, SfxCommonPrintOptionsTabPage, ClickReduceGradientsCBHdl ) );
67 m_xReduceBitmapsCB->connect_toggled( LINK( this, SfxCommonPrintOptionsTabPage, ClickReduceBitmapsCBHdl ) );
69 m_xReduceGradientsStripesRB->connect_toggled( LINK( this, SfxCommonPrintOptionsTabPage, ToggleReduceGradientsStripesRBHdl ) );
70 m_xReduceBitmapsResolutionRB->connect_toggled( LINK( this, SfxCommonPrintOptionsTabPage, ToggleReduceBitmapsResolutionRBHdl ) );
73 SfxCommonPrintOptionsTabPage::~SfxCommonPrintOptionsTabPage()
77 std::unique_ptr<SfxTabPage> SfxCommonPrintOptionsTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet)
79 return std::make_unique<SfxCommonPrintOptionsTabPage>(pPage, pController, *rAttrSet);
82 bool SfxCommonPrintOptionsTabPage::FillItemSet( SfxItemSet* /*rSet*/ )
84 std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
86 if( m_xPaperSizeCB->get_state_changed_from_saved())
87 officecfg::Office::Common::Print::Warning::PaperSize::set(m_xPaperSizeCB->get_active(), batch);
88 if( m_xPaperOrientationCB->get_state_changed_from_saved() )
89 officecfg::Office::Common::Print::Warning::PaperOrientation::set(m_xPaperOrientationCB->get_active(), batch);
90 if( m_xTransparencyCB->get_state_changed_from_saved() )
91 officecfg::Office::Common::Print::Warning::Transparency::set(m_xTransparencyCB->get_active(), batch);
93 batch->commit();
95 ImplSaveControls( m_xPrinterOutputRB->get_active() ? &maPrinterOptions : &maPrintFileOptions );
97 svtools::SetPrinterOptions(maPrinterOptions, /*bFile*/false);
98 svtools::SetPrinterOptions(maPrintFileOptions, /*bFile*/true);
100 return false;
103 void SfxCommonPrintOptionsTabPage::Reset( const SfxItemSet* /*rSet*/ )
105 m_xPaperSizeCB->set_active(officecfg::Office::Common::Print::Warning::PaperSize::get());
106 m_xPaperOrientationCB->set_active(officecfg::Office::Common::Print::Warning::PaperOrientation::get());
107 m_xTransparencyCB->set_active(officecfg::Office::Common::Print::Warning::Transparency::get());
109 m_xPaperSizeCB->save_state();
110 m_xPaperOrientationCB->save_state();
111 m_xTransparencyCB->save_state();
113 svtools::GetPrinterOptions( maPrinterOptions, /*bFile*/false );
114 svtools::GetPrinterOptions( maPrintFileOptions, /*bFile*/true );
115 if(m_xPrintFileOutputRB->get_active()){
116 m_xPrinterOutputRB->set_active(true);
119 ImplUpdateControls( m_xPrinterOutputRB->get_active() ? &maPrinterOptions : &maPrintFileOptions );
122 DeactivateRC SfxCommonPrintOptionsTabPage::DeactivatePage( SfxItemSet* pItemSet )
124 if( pItemSet )
125 FillItemSet( pItemSet );
127 return DeactivateRC::LeavePage;
130 void SfxCommonPrintOptionsTabPage::ImplUpdateControls( const vcl::printer::Options* pCurrentOptions )
132 m_xReduceTransparencyCB->set_active( pCurrentOptions->IsReduceTransparency() );
134 if( pCurrentOptions->GetReducedTransparencyMode() == vcl::printer::TransparencyMode::Auto )
135 m_xReduceTransparencyAutoRB->set_active(true);
136 else
137 m_xReduceTransparencyNoneRB->set_active(true);
139 m_xReduceGradientsCB->set_active( pCurrentOptions->IsReduceGradients() );
141 if( pCurrentOptions->GetReducedGradientMode() == vcl::printer::GradientMode::Stripes )
142 m_xReduceGradientsStripesRB->set_active(true);
143 else
144 m_xReduceGradientsColorRB->set_active(true);
146 m_xReduceGradientsStepCountNF->set_value(pCurrentOptions->GetReducedGradientStepCount());
148 m_xReduceBitmapsCB->set_active( pCurrentOptions->IsReduceBitmaps() );
150 if( pCurrentOptions->GetReducedBitmapMode() == vcl::printer::BitmapMode::Optimal )
151 m_xReduceBitmapsOptimalRB->set_active(true);
152 else if( pCurrentOptions->GetReducedBitmapMode() == vcl::printer::BitmapMode::Normal )
153 m_xReduceBitmapsNormalRB->set_active(true);
154 else
155 m_xReduceBitmapsResolutionRB->set_active(true);
157 const sal_uInt16 nDPI = pCurrentOptions->GetReducedBitmapResolution();
159 if( nDPI < aDPIArray[ 0 ] )
160 m_xReduceBitmapsResolutionLB->set_active(0);
161 else
163 for( int i = DPI_COUNT - 1; i >= 0; i-- )
165 if( nDPI >= aDPIArray[ i ] )
167 m_xReduceBitmapsResolutionLB->set_active(i);
168 i = -1;
173 m_xReduceBitmapsTransparencyCB->set_active( pCurrentOptions->IsReducedBitmapIncludesTransparency() );
174 m_xConvertToGreyscalesCB->set_active( pCurrentOptions->IsConvertToGreyscales() );
176 ClickReduceTransparencyCBHdl(*m_xReduceTransparencyCB);
177 ClickReduceGradientsCBHdl(*m_xReduceGradientsCB);
178 ClickReduceBitmapsCBHdl(*m_xReduceBitmapsCB);
181 void SfxCommonPrintOptionsTabPage::ImplSaveControls( vcl::printer::Options* pCurrentOptions )
183 pCurrentOptions->SetReduceTransparency( m_xReduceTransparencyCB->get_active() );
184 pCurrentOptions->SetReducedTransparencyMode( m_xReduceTransparencyAutoRB->get_active() ? vcl::printer::TransparencyMode::Auto : vcl::printer::TransparencyMode::NONE );
185 pCurrentOptions->SetReduceGradients( m_xReduceGradientsCB->get_active() );
186 pCurrentOptions->SetReducedGradientMode( m_xReduceGradientsStripesRB->get_active() ? vcl::printer::GradientMode::Stripes : vcl::printer::GradientMode::Color );
187 pCurrentOptions->SetReducedGradientStepCount(m_xReduceGradientsStepCountNF->get_value());
188 pCurrentOptions->SetReduceBitmaps( m_xReduceBitmapsCB->get_active() );
189 pCurrentOptions->SetReducedBitmapMode( m_xReduceBitmapsOptimalRB->get_active() ? vcl::printer::BitmapMode::Optimal :
190 ( m_xReduceBitmapsNormalRB->get_active() ? vcl::printer::BitmapMode::Normal : vcl::printer::BitmapMode::Resolution ) );
191 pCurrentOptions->SetReducedBitmapResolution( aDPIArray[ std::min<sal_uInt16>( m_xReduceBitmapsResolutionLB->get_active(),
192 SAL_N_ELEMENTS(aDPIArray) - 1 ) ] );
193 pCurrentOptions->SetReducedBitmapIncludesTransparency( m_xReduceBitmapsTransparencyCB->get_active() );
194 pCurrentOptions->SetConvertToGreyscales( m_xConvertToGreyscalesCB->get_active() );
197 IMPL_LINK_NOARG( SfxCommonPrintOptionsTabPage, ClickReduceTransparencyCBHdl, weld::Toggleable&, void )
199 const bool bReduceTransparency = m_xReduceTransparencyCB->get_active();
201 m_xReduceTransparencyAutoRB->set_sensitive( bReduceTransparency );
202 m_xReduceTransparencyNoneRB->set_sensitive( bReduceTransparency );
204 m_xTransparencyCB->set_sensitive( !bReduceTransparency );
207 IMPL_LINK_NOARG( SfxCommonPrintOptionsTabPage, ClickReduceGradientsCBHdl, weld::Toggleable&, void )
209 const bool bEnable = m_xReduceGradientsCB->get_active();
211 m_xReduceGradientsStripesRB->set_sensitive( bEnable );
212 m_xReduceGradientsColorRB->set_sensitive( bEnable );
213 m_xReduceGradientsStepCountNF->set_sensitive( bEnable );
215 ToggleReduceGradientsStripesRBHdl(*m_xReduceGradientsStripesRB);
218 IMPL_LINK_NOARG( SfxCommonPrintOptionsTabPage, ClickReduceBitmapsCBHdl, weld::Toggleable&, void )
220 const bool bEnable = m_xReduceBitmapsCB->get_active();
222 m_xReduceBitmapsOptimalRB->set_sensitive( bEnable );
223 m_xReduceBitmapsNormalRB->set_sensitive( bEnable );
224 m_xReduceBitmapsResolutionRB->set_sensitive( bEnable );
225 m_xReduceBitmapsTransparencyCB->set_sensitive( bEnable );
226 m_xReduceBitmapsResolutionLB->set_sensitive( bEnable );
228 ToggleReduceBitmapsResolutionRBHdl(*m_xReduceBitmapsResolutionRB);
231 IMPL_LINK_NOARG( SfxCommonPrintOptionsTabPage, ToggleReduceGradientsStripesRBHdl, weld::Toggleable&, void )
233 const bool bEnable = m_xReduceGradientsCB->get_active() && m_xReduceGradientsStripesRB->get_active();
235 m_xReduceGradientsStepCountNF->set_sensitive(bEnable);
238 IMPL_LINK_NOARG( SfxCommonPrintOptionsTabPage, ToggleReduceBitmapsResolutionRBHdl, weld::Toggleable&, void )
240 const bool bEnable = m_xReduceBitmapsCB->get_active() && m_xReduceBitmapsResolutionRB->get_active();
242 m_xReduceBitmapsResolutionLB->set_sensitive(bEnable);
245 IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleOutputPrinterRBHdl, weld::Toggleable&, rButton, void )
247 if (rButton.get_active())
249 ImplUpdateControls( &maPrinterOptions );
250 bOutputForPrinter = true;
252 else
253 ImplSaveControls( &maPrinterOptions );
256 IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleOutputPrintFileRBHdl, weld::Toggleable&, rButton, void )
258 if (rButton.get_active())
260 ImplUpdateControls( &maPrintFileOptions );
261 bOutputForPrinter = false;
263 else
265 ImplSaveControls( &maPrintFileOptions );
269 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */