1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
, u
"sfx/ui/optprintpage.ui"_ustr
, u
"OptPrintPage"_ustr
, &rSet
)
37 , m_xPrinterOutputRB(m_xBuilder
->weld_radio_button(u
"printer"_ustr
))
38 , m_xPrintFileOutputRB(m_xBuilder
->weld_radio_button(u
"file"_ustr
))
39 , m_xReduceTransparencyCB(m_xBuilder
->weld_check_button(u
"reducetrans"_ustr
))
40 , m_xReduceTransparencyImg(m_xBuilder
->weld_widget(u
"lockreducetrans"_ustr
))
41 , m_xReduceTransparencyAutoRB(m_xBuilder
->weld_radio_button(u
"reducetransauto"_ustr
))
42 , m_xReduceTransparencyNoneRB(m_xBuilder
->weld_radio_button(u
"reducetransnone"_ustr
))
43 , m_xReduceTransparencyModeImg(m_xBuilder
->weld_widget(u
"lockreducetransmode"_ustr
))
44 , m_xReduceGradientsCB(m_xBuilder
->weld_check_button(u
"reducegrad"_ustr
))
45 , m_xReduceGradientsImg(m_xBuilder
->weld_widget(u
"lockreducegrad"_ustr
))
46 , m_xReduceGradientsStripesRB(m_xBuilder
->weld_radio_button(u
"reducegradstripes"_ustr
))
47 , m_xReduceGradientsColorRB(m_xBuilder
->weld_radio_button(u
"reducegradcolor"_ustr
))
48 , m_xReduceGradientsModeImg(m_xBuilder
->weld_widget(u
"lockreducegradmode"_ustr
))
49 , m_xReduceGradientsStepCountNF(m_xBuilder
->weld_spin_button(u
"reducegradstep"_ustr
))
50 , m_xReduceBitmapsCB(m_xBuilder
->weld_check_button(u
"reducebitmap"_ustr
))
51 , m_xReduceBitmapsImg(m_xBuilder
->weld_widget(u
"lockreducebitmap"_ustr
))
52 , m_xReduceBitmapsOptimalRB(m_xBuilder
->weld_radio_button(u
"reducebitmapoptimal"_ustr
))
53 , m_xReduceBitmapsNormalRB(m_xBuilder
->weld_radio_button(u
"reducebitmapnormal"_ustr
))
54 , m_xReduceBitmapsResolutionRB(m_xBuilder
->weld_radio_button(u
"reducebitmapresol"_ustr
))
55 , m_xReduceBitmapsModeImg(m_xBuilder
->weld_widget(u
"lockreducebitmapmode"_ustr
))
56 , m_xReduceBitmapsResolutionLB(m_xBuilder
->weld_combo_box(u
"reducebitmapdpi"_ustr
))
57 , m_xReduceBitmapsTransparencyCB(m_xBuilder
->weld_check_button(u
"reducebitmaptrans"_ustr
))
58 , m_xReduceBitmapsTransparencyImg(m_xBuilder
->weld_widget(u
"lockreducebitmaptrans"_ustr
))
59 , m_xConvertToGreyscalesCB(m_xBuilder
->weld_check_button(u
"converttogray"_ustr
))
60 , m_xConvertToGreyscalesImg(m_xBuilder
->weld_widget(u
"lockconverttogray"_ustr
))
61 , m_xPaperSizeCB(m_xBuilder
->weld_check_button(u
"papersize"_ustr
))
62 , m_xPaperSizeImg(m_xBuilder
->weld_widget(u
"lockpapersize"_ustr
))
63 , m_xPaperOrientationCB(m_xBuilder
->weld_check_button(u
"paperorient"_ustr
))
64 , m_xPaperOrientationImg(m_xBuilder
->weld_widget(u
"lockpaperorient"_ustr
))
65 , m_xTransparencyCB(m_xBuilder
->weld_check_button(u
"trans"_ustr
))
66 , m_xTransparencyImg(m_xBuilder
->weld_widget(u
"locktrans"_ustr
))
68 if (bOutputForPrinter
)
69 m_xPrinterOutputRB
->set_active(true);
71 m_xPrintFileOutputRB
->set_active(true);
73 m_xPrinterOutputRB
->connect_toggled( LINK( this, SfxCommonPrintOptionsTabPage
, ToggleOutputPrinterRBHdl
) );
74 m_xPrintFileOutputRB
->connect_toggled( LINK( this, SfxCommonPrintOptionsTabPage
, ToggleOutputPrintFileRBHdl
) );
76 m_xReduceTransparencyCB
->connect_toggled( LINK( this, SfxCommonPrintOptionsTabPage
, ClickReduceTransparencyCBHdl
) );
77 m_xReduceGradientsCB
->connect_toggled( LINK( this, SfxCommonPrintOptionsTabPage
, ClickReduceGradientsCBHdl
) );
78 m_xReduceBitmapsCB
->connect_toggled( LINK( this, SfxCommonPrintOptionsTabPage
, ClickReduceBitmapsCBHdl
) );
80 m_xReduceGradientsStripesRB
->connect_toggled( LINK( this, SfxCommonPrintOptionsTabPage
, ToggleReduceGradientsStripesRBHdl
) );
81 m_xReduceBitmapsResolutionRB
->connect_toggled( LINK( this, SfxCommonPrintOptionsTabPage
, ToggleReduceBitmapsResolutionRBHdl
) );
84 SfxCommonPrintOptionsTabPage::~SfxCommonPrintOptionsTabPage()
88 std::unique_ptr
<SfxTabPage
> SfxCommonPrintOptionsTabPage::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rAttrSet
)
90 return std::make_unique
<SfxCommonPrintOptionsTabPage
>(pPage
, pController
, *rAttrSet
);
93 OUString
SfxCommonPrintOptionsTabPage::GetAllStrings()
96 OUString labels
[] = { u
"label4"_ustr
, u
"label6"_ustr
, u
"label2"_ustr
, u
"label3"_ustr
, u
"label1"_ustr
, u
"label5"_ustr
};
98 for (const auto& label
: labels
)
100 if (const auto pString
= m_xBuilder
->weld_label(label
))
101 sAllStrings
+= pString
->get_label() + " ";
104 OUString checkButton
[] = { u
"converttogray"_ustr
, u
"reducebitmaptrans"_ustr
, u
"reducebitmap"_ustr
, u
"reducetrans"_ustr
,
105 u
"papersize"_ustr
, u
"paperorient"_ustr
, u
"trans"_ustr
, u
"reducegrad"_ustr
};
107 for (const auto& check
: checkButton
)
109 if (const auto pString
= m_xBuilder
->weld_check_button(check
))
110 sAllStrings
+= pString
->get_label() + " ";
113 OUString radioButton
[] = { u
"printer"_ustr
,
115 u
"reducebitmapresol"_ustr
,
116 u
"reducebitmapnormal"_ustr
,
117 u
"reducebitmapoptimal"_ustr
,
118 u
"reducetransauto"_ustr
,
119 u
"reducetransnone"_ustr
,
120 u
"reducegradstripes"_ustr
,
121 u
"reducegradcolor"_ustr
};
123 for (const auto& radio
: radioButton
)
125 if (const auto pString
= m_xBuilder
->weld_radio_button(radio
))
126 sAllStrings
+= pString
->get_label() + " ";
129 return sAllStrings
.replaceAll("_", "");
132 bool SfxCommonPrintOptionsTabPage::FillItemSet( SfxItemSet
* /*rSet*/ )
134 std::shared_ptr
<comphelper::ConfigurationChanges
> batch(comphelper::ConfigurationChanges::create());
136 if( m_xPaperSizeCB
->get_state_changed_from_saved())
137 officecfg::Office::Common::Print::Warning::PaperSize::set(m_xPaperSizeCB
->get_active(), batch
);
138 if( m_xPaperOrientationCB
->get_state_changed_from_saved() )
139 officecfg::Office::Common::Print::Warning::PaperOrientation::set(m_xPaperOrientationCB
->get_active(), batch
);
140 if( m_xTransparencyCB
->get_state_changed_from_saved() )
141 officecfg::Office::Common::Print::Warning::Transparency::set(m_xTransparencyCB
->get_active(), batch
);
145 ImplSaveControls( m_xPrinterOutputRB
->get_active() ? &maPrinterOptions
: &maPrintFileOptions
);
147 svtools::SetPrinterOptions(maPrinterOptions
, /*bFile*/false);
148 svtools::SetPrinterOptions(maPrintFileOptions
, /*bFile*/true);
153 void SfxCommonPrintOptionsTabPage::Reset( const SfxItemSet
* /*rSet*/ )
155 m_xPaperSizeCB
->set_active(officecfg::Office::Common::Print::Warning::PaperSize::get());
156 m_xPaperSizeCB
->set_sensitive(!officecfg::Office::Common::Print::Warning::PaperSize::isReadOnly());
157 m_xPaperSizeImg
->set_visible(officecfg::Office::Common::Print::Warning::PaperSize::isReadOnly());
159 m_xPaperOrientationCB
->set_active(officecfg::Office::Common::Print::Warning::PaperOrientation::get());
160 m_xPaperOrientationCB
->set_sensitive(!officecfg::Office::Common::Print::Warning::PaperOrientation::isReadOnly());
161 m_xPaperOrientationImg
->set_visible(officecfg::Office::Common::Print::Warning::PaperOrientation::isReadOnly());
163 m_xTransparencyCB
->set_active(officecfg::Office::Common::Print::Warning::Transparency::get());
164 m_xTransparencyCB
->set_sensitive(!officecfg::Office::Common::Print::Warning::Transparency::isReadOnly());
165 m_xTransparencyImg
->set_visible(officecfg::Office::Common::Print::Warning::Transparency::isReadOnly());
167 m_xPaperSizeCB
->save_state();
168 m_xPaperOrientationCB
->save_state();
169 m_xTransparencyCB
->save_state();
171 svtools::GetPrinterOptions( maPrinterOptions
, /*bFile*/false );
172 svtools::GetPrinterOptions( maPrintFileOptions
, /*bFile*/true );
173 if(m_xPrintFileOutputRB
->get_active()){
174 m_xPrinterOutputRB
->set_active(true);
177 ImplUpdateControls( m_xPrinterOutputRB
->get_active() ? &maPrinterOptions
: &maPrintFileOptions
);
180 DeactivateRC
SfxCommonPrintOptionsTabPage::DeactivatePage( SfxItemSet
* pItemSet
)
183 FillItemSet( pItemSet
);
185 return DeactivateRC::LeavePage
;
188 void SfxCommonPrintOptionsTabPage::ImplUpdateControls( const vcl::printer::Options
* pCurrentOptions
)
192 bEnable
= !officecfg::Office::Common::Print::Option::File::ReduceTransparency::isReadOnly();
193 m_xReduceTransparencyCB
->set_active( pCurrentOptions
->IsReduceTransparency() );
194 m_xReduceTransparencyCB
->set_sensitive(bEnable
);
195 m_xReduceTransparencyImg
->set_visible(!bEnable
);
197 if( pCurrentOptions
->GetReducedTransparencyMode() == vcl::printer::TransparencyMode::Auto
)
198 m_xReduceTransparencyAutoRB
->set_active(true);
200 m_xReduceTransparencyNoneRB
->set_active(true);
202 bEnable
= !officecfg::Office::Common::Print::Option::File::ReducedTransparencyMode::isReadOnly();
203 m_xReduceTransparencyAutoRB
->set_sensitive(bEnable
);
204 m_xReduceTransparencyNoneRB
->set_sensitive(bEnable
);
205 m_xReduceTransparencyModeImg
->set_visible(!bEnable
);
207 bEnable
= !officecfg::Office::Common::Print::Option::Printer::ReduceGradients::isReadOnly();
208 m_xReduceGradientsCB
->set_active( pCurrentOptions
->IsReduceGradients() );
209 m_xReduceGradientsCB
->set_sensitive(bEnable
);
210 m_xReduceGradientsImg
->set_visible(!bEnable
);
212 if( pCurrentOptions
->GetReducedGradientMode() == vcl::printer::GradientMode::Stripes
)
213 m_xReduceGradientsStripesRB
->set_active(true);
215 m_xReduceGradientsColorRB
->set_active(true);
217 bEnable
= !officecfg::Office::Common::Print::Option::Printer::ReducedGradientMode::isReadOnly();
218 m_xReduceGradientsStripesRB
->set_sensitive(bEnable
);
219 m_xReduceGradientsColorRB
->set_sensitive(bEnable
);
220 m_xReduceGradientsModeImg
->set_visible(!bEnable
);
222 bEnable
= !officecfg::Office::Common::Print::Option::Printer::ReducedGradientStepCount::isReadOnly();
223 m_xReduceGradientsStepCountNF
->set_value(pCurrentOptions
->GetReducedGradientStepCount());
224 m_xReduceGradientsStepCountNF
->set_sensitive(bEnable
);
226 bEnable
= !officecfg::Office::Common::Print::Option::Printer::ReduceBitmaps::isReadOnly();
227 m_xReduceBitmapsCB
->set_active( pCurrentOptions
->IsReduceBitmaps() );
228 m_xReduceBitmapsCB
->set_sensitive(bEnable
);
229 m_xReduceBitmapsImg
->set_visible(!bEnable
);
231 if( pCurrentOptions
->GetReducedBitmapMode() == vcl::printer::BitmapMode::Optimal
)
232 m_xReduceBitmapsOptimalRB
->set_active(true);
233 else if( pCurrentOptions
->GetReducedBitmapMode() == vcl::printer::BitmapMode::Normal
)
234 m_xReduceBitmapsNormalRB
->set_active(true);
236 m_xReduceBitmapsResolutionRB
->set_active(true);
238 bEnable
= !officecfg::Office::Common::Print::Option::Printer::ReducedBitmapMode::isReadOnly();
239 m_xReduceBitmapsOptimalRB
->set_sensitive(bEnable
);
240 m_xReduceBitmapsNormalRB
->set_sensitive(bEnable
);
241 m_xReduceBitmapsResolutionRB
->set_sensitive(bEnable
);
242 m_xReduceBitmapsModeImg
->set_visible(!bEnable
);
244 const sal_uInt16 nDPI
= pCurrentOptions
->GetReducedBitmapResolution();
246 if( nDPI
< aDPIArray
[ 0 ] )
247 m_xReduceBitmapsResolutionLB
->set_active(0);
250 for( int i
= DPI_COUNT
- 1; i
>= 0; i
-- )
252 if( nDPI
>= aDPIArray
[ i
] )
254 m_xReduceBitmapsResolutionLB
->set_active(i
);
259 bEnable
= !officecfg::Office::Common::Print::Option::File::ReducedBitmapResolution::isReadOnly();
260 m_xReduceBitmapsResolutionLB
->set_sensitive(bEnable
);
262 bEnable
= !officecfg::Office::Common::Print::Option::Printer::ReducedBitmapIncludesTransparency::isReadOnly();
263 m_xReduceBitmapsTransparencyCB
->set_active( pCurrentOptions
->IsReducedBitmapIncludesTransparency() );
264 m_xReduceBitmapsTransparencyCB
->set_sensitive(bEnable
);
265 m_xReduceBitmapsTransparencyImg
->set_visible(!bEnable
);
267 bEnable
= !officecfg::Office::Common::Print::Option::Printer::ConvertToGreyscales::isReadOnly();
268 m_xConvertToGreyscalesCB
->set_active( pCurrentOptions
->IsConvertToGreyscales() );
269 m_xConvertToGreyscalesCB
->set_sensitive(bEnable
);
270 m_xConvertToGreyscalesImg
->set_visible(!bEnable
);
272 ClickReduceTransparencyCBHdl(*m_xReduceTransparencyCB
);
273 ClickReduceGradientsCBHdl(*m_xReduceGradientsCB
);
274 ClickReduceBitmapsCBHdl(*m_xReduceBitmapsCB
);
277 void SfxCommonPrintOptionsTabPage::ImplSaveControls( vcl::printer::Options
* pCurrentOptions
)
279 pCurrentOptions
->SetReduceTransparency( m_xReduceTransparencyCB
->get_active() );
280 pCurrentOptions
->SetReducedTransparencyMode( m_xReduceTransparencyAutoRB
->get_active() ? vcl::printer::TransparencyMode::Auto
: vcl::printer::TransparencyMode::NONE
);
281 pCurrentOptions
->SetReduceGradients( m_xReduceGradientsCB
->get_active() );
282 pCurrentOptions
->SetReducedGradientMode( m_xReduceGradientsStripesRB
->get_active() ? vcl::printer::GradientMode::Stripes
: vcl::printer::GradientMode::Color
);
283 pCurrentOptions
->SetReducedGradientStepCount(m_xReduceGradientsStepCountNF
->get_value());
284 pCurrentOptions
->SetReduceBitmaps( m_xReduceBitmapsCB
->get_active() );
285 pCurrentOptions
->SetReducedBitmapMode( m_xReduceBitmapsOptimalRB
->get_active() ? vcl::printer::BitmapMode::Optimal
:
286 ( m_xReduceBitmapsNormalRB
->get_active() ? vcl::printer::BitmapMode::Normal
: vcl::printer::BitmapMode::Resolution
) );
287 pCurrentOptions
->SetReducedBitmapResolution( aDPIArray
[ std::min
<sal_uInt16
>( m_xReduceBitmapsResolutionLB
->get_active(),
288 SAL_N_ELEMENTS(aDPIArray
) - 1 ) ] );
289 pCurrentOptions
->SetReducedBitmapIncludesTransparency( m_xReduceBitmapsTransparencyCB
->get_active() );
290 pCurrentOptions
->SetConvertToGreyscales( m_xConvertToGreyscalesCB
->get_active() );
293 IMPL_LINK_NOARG( SfxCommonPrintOptionsTabPage
, ClickReduceTransparencyCBHdl
, weld::Toggleable
&, void )
295 const bool bReduceTransparency
= m_xReduceTransparencyCB
->get_active();
296 bool bReadOnly
= officecfg::Office::Common::Print::Option::File::ReducedTransparencyMode::isReadOnly();
298 m_xReduceTransparencyAutoRB
->set_sensitive( bReduceTransparency
&& !bReadOnly
);
299 m_xReduceTransparencyNoneRB
->set_sensitive( bReduceTransparency
&& !bReadOnly
);
301 bReadOnly
= officecfg::Office::Common::Print::Warning::Transparency::isReadOnly();
302 m_xTransparencyCB
->set_sensitive( !bReduceTransparency
&& !bReadOnly
);
305 IMPL_LINK_NOARG( SfxCommonPrintOptionsTabPage
, ClickReduceGradientsCBHdl
, weld::Toggleable
&, void )
307 const bool bEnable
= m_xReduceGradientsCB
->get_active();
308 bool bReadOnly
= officecfg::Office::Common::Print::Option::Printer::ReducedGradientMode::isReadOnly();
310 m_xReduceGradientsStripesRB
->set_sensitive( bEnable
&& !bReadOnly
);
311 m_xReduceGradientsColorRB
->set_sensitive( bEnable
&& !bReadOnly
);
313 bReadOnly
= officecfg::Office::Common::Print::Option::Printer::ReducedGradientStepCount::isReadOnly();
314 m_xReduceGradientsStepCountNF
->set_sensitive( bEnable
&& !bReadOnly
);
316 ToggleReduceGradientsStripesRBHdl(*m_xReduceGradientsStripesRB
);
319 IMPL_LINK_NOARG( SfxCommonPrintOptionsTabPage
, ClickReduceBitmapsCBHdl
, weld::Toggleable
&, void )
321 const bool bEnable
= m_xReduceBitmapsCB
->get_active();
322 bool bReadOnly
= officecfg::Office::Common::Print::Option::Printer::ReducedBitmapMode::isReadOnly();
324 m_xReduceBitmapsOptimalRB
->set_sensitive( bEnable
&& !bReadOnly
);
325 m_xReduceBitmapsNormalRB
->set_sensitive( bEnable
&& !bReadOnly
);
326 m_xReduceBitmapsResolutionRB
->set_sensitive( bEnable
&& !bReadOnly
);
327 m_xReduceBitmapsTransparencyCB
->set_sensitive( bEnable
&&
328 !officecfg::Office::Common::Print::Option::Printer::ReducedBitmapIncludesTransparency::isReadOnly() );
329 m_xReduceBitmapsResolutionLB
->set_sensitive( bEnable
&&
330 !officecfg::Office::Common::Print::Option::File::ReducedBitmapResolution::isReadOnly() );
332 ToggleReduceBitmapsResolutionRBHdl(*m_xReduceBitmapsResolutionRB
);
335 IMPL_LINK_NOARG( SfxCommonPrintOptionsTabPage
, ToggleReduceGradientsStripesRBHdl
, weld::Toggleable
&, void )
337 const bool bEnable
= m_xReduceGradientsCB
->get_active() && m_xReduceGradientsStripesRB
->get_active();
339 m_xReduceGradientsStepCountNF
->set_sensitive(bEnable
);
342 IMPL_LINK_NOARG( SfxCommonPrintOptionsTabPage
, ToggleReduceBitmapsResolutionRBHdl
, weld::Toggleable
&, void )
344 const bool bEnable
= m_xReduceBitmapsCB
->get_active() && m_xReduceBitmapsResolutionRB
->get_active();
346 m_xReduceBitmapsResolutionLB
->set_sensitive(bEnable
);
349 IMPL_LINK( SfxCommonPrintOptionsTabPage
, ToggleOutputPrinterRBHdl
, weld::Toggleable
&, rButton
, void )
351 if (rButton
.get_active())
353 ImplUpdateControls( &maPrinterOptions
);
354 bOutputForPrinter
= true;
357 ImplSaveControls( &maPrinterOptions
);
360 IMPL_LINK( SfxCommonPrintOptionsTabPage
, ToggleOutputPrintFileRBHdl
, weld::Toggleable
&, rButton
, void )
362 if (rButton
.get_active())
364 ImplUpdateControls( &maPrintFileOptions
);
365 bOutputForPrinter
= false;
369 ImplSaveControls( &maPrintFileOptions
);
373 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */