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 <unotools/printwarningoptions.hxx>
23 #include <svtools/printoptions.hxx>
24 #include <svtools/restartdialog.hxx>
25 #include <svl/flagitem.hxx>
26
27 #include <comphelper/processfactory.hxx>
28
29 #include <sfx2/viewsh.hxx>
30 #include <sfx2/printopt.hxx>
31
32 static sal_uInt16 aDPIArray[] = { 72, 96, 150, 200, 300, 600 };
33 static bool bOutputForPrinter = true;
34
35 #define DPI_COUNT SAL_N_ELEMENTS(aDPIArray)
36
SfxCommonPrintOptionsTabPage(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet & rSet)37 SfxCommonPrintOptionsTabPage::SfxCommonPrintOptionsTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
38 : SfxTabPage(pPage, pController, "sfx/ui/optprintpage.ui", "OptPrintPage", &rSet)
39 , m_xPrinterOutputRB(m_xBuilder->weld_radio_button("printer"))
40 , m_xPrintFileOutputRB(m_xBuilder->weld_radio_button("file"))
41 , m_xReduceTransparencyCB(m_xBuilder->weld_check_button("reducetrans"))
42 , m_xReduceTransparencyAutoRB(m_xBuilder->weld_radio_button("reducetransauto"))
43 , m_xReduceTransparencyNoneRB(m_xBuilder->weld_radio_button("reducetransnone"))
44 , m_xReduceGradientsCB(m_xBuilder->weld_check_button("reducegrad"))
45 , m_xReduceGradientsStripesRB(m_xBuilder->weld_radio_button("reducegradstripes"))
46 , m_xReduceGradientsColorRB(m_xBuilder->weld_radio_button("reducegradcolor"))
47 , m_xReduceGradientsStepCountNF(m_xBuilder->weld_spin_button("reducegradstep"))
48 , m_xReduceBitmapsCB(m_xBuilder->weld_check_button("reducebitmap"))
49 , m_xReduceBitmapsOptimalRB(m_xBuilder->weld_radio_button("reducebitmapoptimal"))
50 , m_xReduceBitmapsNormalRB(m_xBuilder->weld_radio_button("reducebitmapnormal"))
51 , m_xReduceBitmapsResolutionRB(m_xBuilder->weld_radio_button("reducebitmapresol"))
52 , m_xReduceBitmapsResolutionLB(m_xBuilder->weld_combo_box("reducebitmapdpi"))
53 , m_xReduceBitmapsTransparencyCB(m_xBuilder->weld_check_button("reducebitmaptrans"))
54 , m_xConvertToGreyscalesCB(m_xBuilder->weld_check_button("converttogray"))
55 , m_xPDFCB(m_xBuilder->weld_check_button("pdf"))
56 , m_xPaperSizeCB(m_xBuilder->weld_check_button("papersize"))
57 , m_xPaperOrientationCB(m_xBuilder->weld_check_button("paperorient"))
58 , m_xTransparencyCB(m_xBuilder->weld_check_button("trans"))
59 {
60 #ifndef ENABLE_CUPS
61 m_xPDFCB->hide();
62 #endif
63
64 if( bOutputForPrinter )
65 {
66 m_xPrinterOutputRB->set_active(true);
67 }
68 else
69 {
70 m_xPrintFileOutputRB->set_active(true);
71 m_xPDFCB->set_sensitive(false);
72 }
73
74 m_xPrinterOutputRB->connect_toggled( LINK( this, SfxCommonPrintOptionsTabPage, ToggleOutputPrinterRBHdl ) );
75 m_xPrintFileOutputRB->connect_toggled( LINK( this, SfxCommonPrintOptionsTabPage, ToggleOutputPrintFileRBHdl ) );
76
77 m_xReduceTransparencyCB->connect_clicked( LINK( this, SfxCommonPrintOptionsTabPage, ClickReduceTransparencyCBHdl ) );
78 m_xReduceGradientsCB->connect_clicked( LINK( this, SfxCommonPrintOptionsTabPage, ClickReduceGradientsCBHdl ) );
79 m_xReduceBitmapsCB->connect_clicked( LINK( this, SfxCommonPrintOptionsTabPage, ClickReduceBitmapsCBHdl ) );
80
81 m_xReduceGradientsStripesRB->connect_toggled( LINK( this, SfxCommonPrintOptionsTabPage, ToggleReduceGradientsStripesRBHdl ) );
82 m_xReduceBitmapsResolutionRB->connect_toggled( LINK( this, SfxCommonPrintOptionsTabPage, ToggleReduceBitmapsResolutionRBHdl ) );
83 }
84
~SfxCommonPrintOptionsTabPage()85 SfxCommonPrintOptionsTabPage::~SfxCommonPrintOptionsTabPage()
86 {
87 }
88
Create(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet * rAttrSet)89 std::unique_ptr<SfxTabPage> SfxCommonPrintOptionsTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet)
90 {
91 return std::make_unique<SfxCommonPrintOptionsTabPage>(pPage, pController, *rAttrSet);
92 }
93
FillItemSet(SfxItemSet *)94 bool SfxCommonPrintOptionsTabPage::FillItemSet( SfxItemSet* /*rSet*/ )
95 {
96 SvtPrintWarningOptions aWarnOptions;
97 SvtPrinterOptions aPrinterOptions;
98 SvtPrintFileOptions aPrintFileOptions;
99
100
101 if( m_xPaperSizeCB->get_state_changed_from_saved())
102 aWarnOptions.SetPaperSize(m_xPaperSizeCB->get_active());
103 if( m_xPaperOrientationCB->get_state_changed_from_saved() )
104 aWarnOptions.SetPaperOrientation(m_xPaperOrientationCB->get_active());
105 if( m_xTransparencyCB->get_state_changed_from_saved() )
106 aWarnOptions.SetTransparency( m_xTransparencyCB->get_active() );
107
108 ImplSaveControls( m_xPrinterOutputRB->get_active() ? &maPrinterOptions : &maPrintFileOptions );
109
110 aPrinterOptions.SetPrinterOptions( maPrinterOptions );
111 aPrintFileOptions.SetPrinterOptions( maPrintFileOptions );
112
113 return false;
114 }
115
Reset(const SfxItemSet *)116 void SfxCommonPrintOptionsTabPage::Reset( const SfxItemSet* /*rSet*/ )
117 {
118 SvtPrintWarningOptions aWarnOptions;
119 SvtPrinterOptions aPrinterOptions;
120 SvtPrintFileOptions aPrintFileOptions;
121
122 m_xPaperSizeCB->set_active( aWarnOptions.IsPaperSize() );
123 m_xPaperOrientationCB->set_active( aWarnOptions.IsPaperOrientation() );
124
125 m_xTransparencyCB->set_active( aWarnOptions.IsTransparency() );
126
127 m_xPaperSizeCB->save_state();
128 m_xPaperOrientationCB->save_state();
129 m_xTransparencyCB->save_state();
130
131 aPrinterOptions.GetPrinterOptions( maPrinterOptions );
132 aPrintFileOptions.GetPrinterOptions( maPrintFileOptions );
133 if(m_xPrintFileOutputRB->get_active()){
134 m_xPrinterOutputRB->set_active(true);
135 }
136
137 ImplUpdateControls( m_xPrinterOutputRB->get_active() ? &maPrinterOptions : &maPrintFileOptions );
138 }
139
DeactivatePage(SfxItemSet * pItemSet)140 DeactivateRC SfxCommonPrintOptionsTabPage::DeactivatePage( SfxItemSet* pItemSet )
141 {
142 if( pItemSet )
143 FillItemSet( pItemSet );
144
145 return DeactivateRC::LeavePage;
146 }
147
ImplUpdateControls(const PrinterOptions * pCurrentOptions)148 void SfxCommonPrintOptionsTabPage::ImplUpdateControls( const PrinterOptions* pCurrentOptions )
149 {
150 m_xReduceTransparencyCB->set_active( pCurrentOptions->IsReduceTransparency() );
151
152 if( pCurrentOptions->GetReducedTransparencyMode() == PrinterTransparencyMode::Auto )
153 m_xReduceTransparencyAutoRB->set_active(true);
154 else
155 m_xReduceTransparencyNoneRB->set_active(true);
156
157 m_xReduceGradientsCB->set_active( pCurrentOptions->IsReduceGradients() );
158
159 if( pCurrentOptions->GetReducedGradientMode() == PrinterGradientMode::Stripes )
160 m_xReduceGradientsStripesRB->set_active(true);
161 else
162 m_xReduceGradientsColorRB->set_active(true);
163
164 m_xReduceGradientsStepCountNF->set_value(pCurrentOptions->GetReducedGradientStepCount());
165
166 m_xReduceBitmapsCB->set_active( pCurrentOptions->IsReduceBitmaps() );
167
168 if( pCurrentOptions->GetReducedBitmapMode() == PrinterBitmapMode::Optimal )
169 m_xReduceBitmapsOptimalRB->set_active(true);
170 else if( pCurrentOptions->GetReducedBitmapMode() == PrinterBitmapMode::Normal )
171 m_xReduceBitmapsNormalRB->set_active(true);
172 else
173 m_xReduceBitmapsResolutionRB->set_active(true);
174
175 const sal_uInt16 nDPI = pCurrentOptions->GetReducedBitmapResolution();
176
177 if( nDPI < aDPIArray[ 0 ] )
178 m_xReduceBitmapsResolutionLB->set_active(0);
179 else
180 {
181 for( int i = DPI_COUNT - 1; i >= 0; i-- )
182 {
183 if( nDPI >= aDPIArray[ i ] )
184 {
185 m_xReduceBitmapsResolutionLB->set_active(i);
186 i = -1;
187 }
188 }
189 }
190
191 m_xReduceBitmapsTransparencyCB->set_active( pCurrentOptions->IsReducedBitmapIncludesTransparency() );
192 m_xConvertToGreyscalesCB->set_active( pCurrentOptions->IsConvertToGreyscales() );
193 m_xPDFCB->set_active( pCurrentOptions->IsPDFAsStandardPrintJobFormat() );
194
195 ClickReduceTransparencyCBHdl(*m_xReduceTransparencyCB);
196 ClickReduceGradientsCBHdl(*m_xReduceGradientsCB);
197 ClickReduceBitmapsCBHdl(*m_xReduceBitmapsCB);
198 }
199
ImplSaveControls(PrinterOptions * pCurrentOptions)200 void SfxCommonPrintOptionsTabPage::ImplSaveControls( PrinterOptions* pCurrentOptions )
201 {
202 pCurrentOptions->SetReduceTransparency( m_xReduceTransparencyCB->get_active() );
203 pCurrentOptions->SetReducedTransparencyMode( m_xReduceTransparencyAutoRB->get_active() ? PrinterTransparencyMode::Auto : PrinterTransparencyMode::NONE );
204 pCurrentOptions->SetReduceGradients( m_xReduceGradientsCB->get_active() );
205 pCurrentOptions->SetReducedGradientMode( m_xReduceGradientsStripesRB->get_active() ? PrinterGradientMode::Stripes : PrinterGradientMode::Color );
206 pCurrentOptions->SetReducedGradientStepCount(m_xReduceGradientsStepCountNF->get_value());
207 pCurrentOptions->SetReduceBitmaps( m_xReduceBitmapsCB->get_active() );
208 pCurrentOptions->SetReducedBitmapMode( m_xReduceBitmapsOptimalRB->get_active() ? PrinterBitmapMode::Optimal :
209 ( m_xReduceBitmapsNormalRB->get_active() ? PrinterBitmapMode::Normal : PrinterBitmapMode::Resolution ) );
210 pCurrentOptions->SetReducedBitmapResolution( aDPIArray[ std::min<sal_uInt16>( m_xReduceBitmapsResolutionLB->get_active(),
211 SAL_N_ELEMENTS(aDPIArray) - 1 ) ] );
212 pCurrentOptions->SetReducedBitmapIncludesTransparency( m_xReduceBitmapsTransparencyCB->get_active() );
213 pCurrentOptions->SetConvertToGreyscales( m_xConvertToGreyscalesCB->get_active() );
214 bool bOrigBackEnd = pCurrentOptions->IsPDFAsStandardPrintJobFormat();
215 if (bOrigBackEnd != m_xPDFCB->get_active())
216 {
217 pCurrentOptions->SetPDFAsStandardPrintJobFormat( m_xPDFCB->get_active() );
218 svtools::executeRestartDialog(
219 comphelper::getProcessComponentContext(), nullptr,
220 svtools::RESTART_REASON_PDF_AS_STANDARD_JOB_FORMAT);
221 }
222 }
223
IMPL_LINK_NOARG(SfxCommonPrintOptionsTabPage,ClickReduceTransparencyCBHdl,weld::Button &,void)224 IMPL_LINK_NOARG( SfxCommonPrintOptionsTabPage, ClickReduceTransparencyCBHdl, weld::Button&, void )
225 {
226 const bool bReduceTransparency = m_xReduceTransparencyCB->get_active();
227
228 m_xReduceTransparencyAutoRB->set_sensitive( bReduceTransparency );
229 m_xReduceTransparencyNoneRB->set_sensitive( bReduceTransparency );
230
231 m_xTransparencyCB->set_sensitive( !bReduceTransparency );
232 }
233
IMPL_LINK_NOARG(SfxCommonPrintOptionsTabPage,ClickReduceGradientsCBHdl,weld::Button &,void)234 IMPL_LINK_NOARG( SfxCommonPrintOptionsTabPage, ClickReduceGradientsCBHdl, weld::Button&, void )
235 {
236 const bool bEnable = m_xReduceGradientsCB->get_active();
237
238 m_xReduceGradientsStripesRB->set_sensitive( bEnable );
239 m_xReduceGradientsColorRB->set_sensitive( bEnable );
240 m_xReduceGradientsStepCountNF->set_sensitive( bEnable );
241
242 ToggleReduceGradientsStripesRBHdl(*m_xReduceGradientsStripesRB);
243 }
244
IMPL_LINK_NOARG(SfxCommonPrintOptionsTabPage,ClickReduceBitmapsCBHdl,weld::Button &,void)245 IMPL_LINK_NOARG( SfxCommonPrintOptionsTabPage, ClickReduceBitmapsCBHdl, weld::Button&, void )
246 {
247 const bool bEnable = m_xReduceBitmapsCB->get_active();
248
249 m_xReduceBitmapsOptimalRB->set_sensitive( bEnable );
250 m_xReduceBitmapsNormalRB->set_sensitive( bEnable );
251 m_xReduceBitmapsResolutionRB->set_sensitive( bEnable );
252 m_xReduceBitmapsTransparencyCB->set_sensitive( bEnable );
253 m_xReduceBitmapsResolutionLB->set_sensitive( bEnable );
254
255 ToggleReduceBitmapsResolutionRBHdl(*m_xReduceBitmapsResolutionRB);
256 }
257
IMPL_LINK_NOARG(SfxCommonPrintOptionsTabPage,ToggleReduceGradientsStripesRBHdl,weld::ToggleButton &,void)258 IMPL_LINK_NOARG( SfxCommonPrintOptionsTabPage, ToggleReduceGradientsStripesRBHdl, weld::ToggleButton&, void )
259 {
260 const bool bEnable = m_xReduceGradientsCB->get_active() && m_xReduceGradientsStripesRB->get_active();
261
262 m_xReduceGradientsStepCountNF->set_sensitive(bEnable);
263 }
264
IMPL_LINK_NOARG(SfxCommonPrintOptionsTabPage,ToggleReduceBitmapsResolutionRBHdl,weld::ToggleButton &,void)265 IMPL_LINK_NOARG( SfxCommonPrintOptionsTabPage, ToggleReduceBitmapsResolutionRBHdl, weld::ToggleButton&, void )
266 {
267 const bool bEnable = m_xReduceBitmapsCB->get_active() && m_xReduceBitmapsResolutionRB->get_active();
268
269 m_xReduceBitmapsResolutionLB->set_sensitive(bEnable);
270 }
271
IMPL_LINK(SfxCommonPrintOptionsTabPage,ToggleOutputPrinterRBHdl,weld::ToggleButton &,rButton,void)272 IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleOutputPrinterRBHdl, weld::ToggleButton&, rButton, void )
273 {
274 if (rButton.get_active())
275 {
276 ImplUpdateControls( &maPrinterOptions );
277 bOutputForPrinter = true;
278 }
279 else
280 ImplSaveControls( &maPrinterOptions );
281 }
282
IMPL_LINK(SfxCommonPrintOptionsTabPage,ToggleOutputPrintFileRBHdl,weld::ToggleButton &,rButton,void)283 IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleOutputPrintFileRBHdl, weld::ToggleButton&, rButton, void )
284 {
285 if (rButton.get_active())
286 {
287 ImplUpdateControls( &maPrintFileOptions );
288 bOutputForPrinter = false;
289 m_xPDFCB->set_sensitive(false);
290 }
291 else
292 {
293 ImplSaveControls( &maPrintFileOptions );
294 m_xPDFCB->set_sensitive(true);
295 }
296 }
297
298 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
299