LibreOffice Module sfx2 (master) 1
printopt.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include <sal/macros.h>
22#include <officecfg/Office/Common.hxx>
25
27
28#include <sfx2/printopt.hxx>
29
30static sal_uInt16 aDPIArray[] = { 72, 96, 150, 200, 300, 600 };
31static bool bOutputForPrinter = true;
32
33#define DPI_COUNT SAL_N_ELEMENTS(aDPIArray)
34
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"))
56{
58 m_xPrinterOutputRB->set_active(true);
59 else
60 m_xPrintFileOutputRB->set_active(true);
61
62 m_xPrinterOutputRB->connect_toggled( LINK( this, SfxCommonPrintOptionsTabPage, ToggleOutputPrinterRBHdl ) );
63 m_xPrintFileOutputRB->connect_toggled( LINK( this, SfxCommonPrintOptionsTabPage, ToggleOutputPrintFileRBHdl ) );
64
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 ) );
68
69 m_xReduceGradientsStripesRB->connect_toggled( LINK( this, SfxCommonPrintOptionsTabPage, ToggleReduceGradientsStripesRBHdl ) );
70 m_xReduceBitmapsResolutionRB->connect_toggled( LINK( this, SfxCommonPrintOptionsTabPage, ToggleReduceBitmapsResolutionRBHdl ) );
71}
72
74{
75}
76
77std::unique_ptr<SfxTabPage> SfxCommonPrintOptionsTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet)
78{
79 return std::make_unique<SfxCommonPrintOptionsTabPage>(pPage, pController, *rAttrSet);
80}
81
83{
84 std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
85
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);
92
93 batch->commit();
94
96
99
100 return false;
101}
102
104{
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());
108
109 m_xPaperSizeCB->save_state();
110 m_xPaperOrientationCB->save_state();
111 m_xTransparencyCB->save_state();
112
115 if(m_xPrintFileOutputRB->get_active()){
116 m_xPrinterOutputRB->set_active(true);
117 }
118
120}
121
123{
124 if( pItemSet )
125 FillItemSet( pItemSet );
126
128}
129
130void SfxCommonPrintOptionsTabPage::ImplUpdateControls( const vcl::printer::Options* pCurrentOptions )
131{
132 m_xReduceTransparencyCB->set_active( pCurrentOptions->IsReduceTransparency() );
133
134 if( pCurrentOptions->GetReducedTransparencyMode() == vcl::printer::TransparencyMode::Auto )
135 m_xReduceTransparencyAutoRB->set_active(true);
136 else
137 m_xReduceTransparencyNoneRB->set_active(true);
138
139 m_xReduceGradientsCB->set_active( pCurrentOptions->IsReduceGradients() );
140
141 if( pCurrentOptions->GetReducedGradientMode() == vcl::printer::GradientMode::Stripes )
142 m_xReduceGradientsStripesRB->set_active(true);
143 else
144 m_xReduceGradientsColorRB->set_active(true);
145
146 m_xReduceGradientsStepCountNF->set_value(pCurrentOptions->GetReducedGradientStepCount());
147
148 m_xReduceBitmapsCB->set_active( pCurrentOptions->IsReduceBitmaps() );
149
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);
156
157 const sal_uInt16 nDPI = pCurrentOptions->GetReducedBitmapResolution();
158
159 if( nDPI < aDPIArray[ 0 ] )
160 m_xReduceBitmapsResolutionLB->set_active(0);
161 else
162 {
163 for( int i = DPI_COUNT - 1; i >= 0; i-- )
164 {
165 if( nDPI >= aDPIArray[ i ] )
166 {
167 m_xReduceBitmapsResolutionLB->set_active(i);
168 i = -1;
169 }
170 }
171 }
172
173 m_xReduceBitmapsTransparencyCB->set_active( pCurrentOptions->IsReducedBitmapIncludesTransparency() );
174 m_xConvertToGreyscalesCB->set_active( pCurrentOptions->IsConvertToGreyscales() );
175
176 ClickReduceTransparencyCBHdl(*m_xReduceTransparencyCB);
177 ClickReduceGradientsCBHdl(*m_xReduceGradientsCB);
178 ClickReduceBitmapsCBHdl(*m_xReduceBitmapsCB);
179}
180
181void SfxCommonPrintOptionsTabPage::ImplSaveControls( vcl::printer::Options* pCurrentOptions )
182{
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 :
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() );
195}
196
197IMPL_LINK_NOARG( SfxCommonPrintOptionsTabPage, ClickReduceTransparencyCBHdl, weld::Toggleable&, void )
198{
199 const bool bReduceTransparency = m_xReduceTransparencyCB->get_active();
200
201 m_xReduceTransparencyAutoRB->set_sensitive( bReduceTransparency );
202 m_xReduceTransparencyNoneRB->set_sensitive( bReduceTransparency );
203
204 m_xTransparencyCB->set_sensitive( !bReduceTransparency );
205}
206
208{
209 const bool bEnable = m_xReduceGradientsCB->get_active();
210
211 m_xReduceGradientsStripesRB->set_sensitive( bEnable );
212 m_xReduceGradientsColorRB->set_sensitive( bEnable );
213 m_xReduceGradientsStepCountNF->set_sensitive( bEnable );
214
215 ToggleReduceGradientsStripesRBHdl(*m_xReduceGradientsStripesRB);
216}
217
219{
220 const bool bEnable = m_xReduceBitmapsCB->get_active();
221
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 );
227
228 ToggleReduceBitmapsResolutionRBHdl(*m_xReduceBitmapsResolutionRB);
229}
230
231IMPL_LINK_NOARG( SfxCommonPrintOptionsTabPage, ToggleReduceGradientsStripesRBHdl, weld::Toggleable&, void )
232{
233 const bool bEnable = m_xReduceGradientsCB->get_active() && m_xReduceGradientsStripesRB->get_active();
234
235 m_xReduceGradientsStepCountNF->set_sensitive(bEnable);
236}
237
238IMPL_LINK_NOARG( SfxCommonPrintOptionsTabPage, ToggleReduceBitmapsResolutionRBHdl, weld::Toggleable&, void )
239{
240 const bool bEnable = m_xReduceBitmapsCB->get_active() && m_xReduceBitmapsResolutionRB->get_active();
241
242 m_xReduceBitmapsResolutionLB->set_sensitive(bEnable);
243}
244
245IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleOutputPrinterRBHdl, weld::Toggleable&, rButton, void )
246{
247 if (rButton.get_active())
248 {
249 ImplUpdateControls( &maPrinterOptions );
250 bOutputForPrinter = true;
251 }
252 else
253 ImplSaveControls( &maPrinterOptions );
254}
255
256IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleOutputPrintFileRBHdl, weld::Toggleable&, rButton, void )
257{
258 if (rButton.get_active())
259 {
260 ImplUpdateControls( &maPrintFileOptions );
261 bOutputForPrinter = false;
262 }
263 else
264 {
265 ImplSaveControls( &maPrintFileOptions );
266 }
267}
268
269/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::CheckButton > m_xConvertToGreyscalesCB
Definition: printopt.hxx:48
std::unique_ptr< weld::ComboBox > m_xReduceBitmapsResolutionLB
Definition: printopt.hxx:46
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: printopt.cxx:82
std::unique_ptr< weld::RadioButton > m_xReduceTransparencyAutoRB
Definition: printopt.hxx:36
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: printopt.cxx:122
std::unique_ptr< weld::CheckButton > m_xReduceTransparencyCB
Definition: printopt.hxx:35
std::unique_ptr< weld::RadioButton > m_xReduceBitmapsResolutionRB
Definition: printopt.hxx:45
SAL_DLLPRIVATE void ImplUpdateControls(const vcl::printer::Options *pCurrentOptions)
Definition: printopt.cxx:130
std::unique_ptr< weld::RadioButton > m_xPrintFileOutputRB
Definition: printopt.hxx:34
vcl::printer::Options maPrintFileOptions
Definition: printopt.hxx:56
std::unique_ptr< weld::RadioButton > m_xReduceGradientsStripesRB
Definition: printopt.hxx:39
std::unique_ptr< weld::RadioButton > m_xReduceTransparencyNoneRB
Definition: printopt.hxx:37
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: printopt.cxx:77
SAL_DLLPRIVATE void ImplSaveControls(vcl::printer::Options *pCurrentOptions)
Definition: printopt.cxx:181
std::unique_ptr< weld::CheckButton > m_xReduceBitmapsCB
Definition: printopt.hxx:42
virtual ~SfxCommonPrintOptionsTabPage() override
Definition: printopt.cxx:73
std::unique_ptr< weld::RadioButton > m_xReduceBitmapsNormalRB
Definition: printopt.hxx:44
std::unique_ptr< weld::CheckButton > m_xPaperSizeCB
Definition: printopt.hxx:49
virtual void Reset(const SfxItemSet *rSet) override
Definition: printopt.cxx:103
vcl::printer::Options maPrinterOptions
Definition: printopt.hxx:55
std::unique_ptr< weld::SpinButton > m_xReduceGradientsStepCountNF
Definition: printopt.hxx:41
std::unique_ptr< weld::CheckButton > m_xReduceBitmapsTransparencyCB
Definition: printopt.hxx:47
std::unique_ptr< weld::RadioButton > m_xReduceGradientsColorRB
Definition: printopt.hxx:40
std::unique_ptr< weld::CheckButton > m_xReduceGradientsCB
Definition: printopt.hxx:38
SfxCommonPrintOptionsTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: printopt.cxx:35
std::unique_ptr< weld::RadioButton > m_xReduceBitmapsOptimalRB
Definition: printopt.hxx:43
std::unique_ptr< weld::CheckButton > m_xPaperOrientationCB
Definition: printopt.hxx:50
std::unique_ptr< weld::CheckButton > m_xTransparencyCB
Definition: printopt.hxx:51
std::unique_ptr< weld::RadioButton > m_xPrinterOutputRB
Definition: printopt.hxx:33
static std::shared_ptr< ConfigurationChanges > create()
#define SAL_N_ELEMENTS(arr)
int i
void GetPrinterOptions(vcl::printer::Options &rOptions, bool bFile)
void SetPrinterOptions(const vcl::printer::Options &rOptions, bool bFile)
static bool bOutputForPrinter
Definition: printopt.cxx:31
IMPL_LINK_NOARG(SfxCommonPrintOptionsTabPage, ClickReduceTransparencyCBHdl, weld::Toggleable &, void)
Definition: printopt.cxx:197
#define DPI_COUNT
Definition: printopt.cxx:33
static sal_uInt16 aDPIArray[]
Definition: printopt.cxx:30
IMPL_LINK(SfxCommonPrintOptionsTabPage, ToggleOutputPrinterRBHdl, weld::Toggleable &, rButton, void)
Definition: printopt.cxx:245
static SfxItemSet & rSet
Definition: shell.cxx:534
DeactivateRC
Definition: tabdlg.hxx:173