Line data Source code
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 <vcl/msgbox.hxx>
23 : #include <unotools/printwarningoptions.hxx>
24 : #include <svtools/printoptions.hxx>
25 : #include <svtools/restartdialog.hxx>
26 : #include <svl/flagitem.hxx>
27 :
28 : #include <comphelper/processfactory.hxx>
29 :
30 : #include <sfx2/sfxresid.hxx>
31 : #include <sfx2/viewsh.hxx>
32 : #include <sfx2/printopt.hxx>
33 :
34 : static sal_uInt16 aDPIArray[] = { 72, 96, 150, 200, 300, 600 };
35 : static bool bOutputForPrinter = true;
36 :
37 : #define DPI_COUNT (sizeof(aDPIArray)/sizeof(aDPIArray[0 ]))
38 :
39 0 : SfxCommonPrintOptionsTabPage::SfxCommonPrintOptionsTabPage( vcl::Window* pParent, const SfxItemSet& rSet )
40 0 : : SfxTabPage(pParent, "OptPrintPage", "sfx/ui/optprintpage.ui", &rSet)
41 : {
42 0 : get(m_pPrinterOutputRB, "printer");
43 0 : get(m_pPrintFileOutputRB, "file");
44 0 : get(m_pReduceTransparencyCB, "reducetrans");
45 0 : get(m_pReduceTransparencyAutoRB, "reducetransauto");
46 0 : get(m_pReduceTransparencyNoneRB, "reducetransnone");
47 0 : get(m_pReduceGradientsCB, "reducegrad");
48 0 : get(m_pReduceGradientsStripesRB, "reducegradstripes");
49 0 : get(m_pReduceGradientsColorRB, "reducegradcolor");
50 0 : get(m_pReduceGradientsStepCountNF, "reducegradstep");
51 0 : get(m_pReduceBitmapsCB, "reducebitmap");
52 0 : get(m_pReduceBitmapsOptimalRB, "reducebitmapoptimal");
53 0 : get(m_pReduceBitmapsNormalRB, "reducebitmapnormal");
54 0 : get(m_pReduceBitmapsResolutionRB, "reducebitmapresol");
55 0 : get(m_pReduceBitmapsResolutionLB, "reducebitmapdpi");
56 0 : get(m_pReduceBitmapsTransparencyCB, "reducebitmaptrans");
57 0 : get(m_pConvertToGreyscalesCB, "converttogray");
58 0 : get(m_pPDFCB, "pdf");
59 0 : get(m_pPaperSizeCB, "papersize");
60 0 : get(m_pPaperOrientationCB, "paperorient");
61 0 : get(m_pTransparencyCB, "trans");
62 :
63 : #ifndef ENABLE_CUPS
64 : m_pPDFCB->Hide();
65 : #endif
66 :
67 0 : if( bOutputForPrinter )
68 : {
69 0 : m_pPrinterOutputRB->Check( true );
70 : }
71 : else
72 : {
73 0 : m_pPrintFileOutputRB->Check( true );
74 0 : m_pPDFCB->Disable();
75 : }
76 :
77 0 : m_pPrinterOutputRB->SetToggleHdl( LINK( this, SfxCommonPrintOptionsTabPage, ToggleOutputPrinterRBHdl ) );
78 0 : m_pPrintFileOutputRB->SetToggleHdl( LINK( this, SfxCommonPrintOptionsTabPage, ToggleOutputPrintFileRBHdl ) );
79 :
80 0 : m_pReduceTransparencyCB->SetClickHdl( LINK( this, SfxCommonPrintOptionsTabPage, ClickReduceTransparencyCBHdl ) );
81 0 : m_pReduceGradientsCB->SetClickHdl( LINK( this, SfxCommonPrintOptionsTabPage, ClickReduceGradientsCBHdl ) );
82 0 : m_pReduceBitmapsCB->SetClickHdl( LINK( this, SfxCommonPrintOptionsTabPage, ClickReduceBitmapsCBHdl ) );
83 :
84 0 : m_pReduceGradientsStripesRB->SetToggleHdl( LINK( this, SfxCommonPrintOptionsTabPage, ToggleReduceGradientsStripesRBHdl ) );
85 0 : m_pReduceBitmapsResolutionRB->SetToggleHdl( LINK( this, SfxCommonPrintOptionsTabPage, ToggleReduceBitmapsResolutionRBHdl ) );
86 0 : }
87 :
88 0 : SfxCommonPrintOptionsTabPage::~SfxCommonPrintOptionsTabPage()
89 : {
90 0 : disposeOnce();
91 0 : }
92 :
93 0 : void SfxCommonPrintOptionsTabPage::dispose()
94 : {
95 0 : m_pPrinterOutputRB.clear();
96 0 : m_pPrintFileOutputRB.clear();
97 0 : m_pReduceTransparencyCB.clear();
98 0 : m_pReduceTransparencyAutoRB.clear();
99 0 : m_pReduceTransparencyNoneRB.clear();
100 0 : m_pReduceGradientsCB.clear();
101 0 : m_pReduceGradientsStripesRB.clear();
102 0 : m_pReduceGradientsColorRB.clear();
103 0 : m_pReduceGradientsStepCountNF.clear();
104 0 : m_pReduceBitmapsCB.clear();
105 0 : m_pReduceBitmapsOptimalRB.clear();
106 0 : m_pReduceBitmapsNormalRB.clear();
107 0 : m_pReduceBitmapsResolutionRB.clear();
108 0 : m_pReduceBitmapsResolutionLB.clear();
109 0 : m_pReduceBitmapsTransparencyCB.clear();
110 0 : m_pConvertToGreyscalesCB.clear();
111 0 : m_pPDFCB.clear();
112 0 : m_pPaperSizeCB.clear();
113 0 : m_pPaperOrientationCB.clear();
114 0 : m_pTransparencyCB.clear();
115 0 : SfxTabPage::dispose();
116 0 : }
117 :
118 0 : VclPtr<SfxTabPage> SfxCommonPrintOptionsTabPage::Create( vcl::Window* pParent, const SfxItemSet* rAttrSet )
119 : {
120 0 : return VclPtr<SfxCommonPrintOptionsTabPage>::Create( pParent, *rAttrSet );
121 : }
122 :
123 0 : vcl::Window* SfxCommonPrintOptionsTabPage::GetParentLabeledBy( const vcl::Window* pWindow ) const
124 : {
125 0 : if ( pWindow == static_cast<vcl::Window *>(m_pReduceGradientsStepCountNF) )
126 0 : return m_pReduceGradientsStripesRB;
127 0 : else if ( pWindow == static_cast<vcl::Window *>(m_pReduceBitmapsResolutionLB) )
128 0 : return m_pReduceBitmapsResolutionRB;
129 : else
130 0 : return SfxTabPage::GetParentLabeledBy( pWindow );
131 : }
132 :
133 0 : vcl::Window* SfxCommonPrintOptionsTabPage::GetParentLabelFor( const vcl::Window* pWindow ) const
134 : {
135 0 : if ( pWindow == static_cast<vcl::Window *>(m_pReduceGradientsStripesRB) )
136 0 : return m_pReduceGradientsStepCountNF;
137 0 : else if ( pWindow == static_cast<vcl::Window *>(m_pReduceBitmapsResolutionRB) )
138 0 : return m_pReduceBitmapsResolutionLB;
139 : else
140 0 : return SfxTabPage::GetParentLabelFor( pWindow );
141 : }
142 :
143 0 : bool SfxCommonPrintOptionsTabPage::FillItemSet( SfxItemSet* /*rSet*/ )
144 : {
145 0 : SvtPrintWarningOptions aWarnOptions;
146 0 : SvtPrinterOptions aPrinterOptions;
147 0 : SvtPrintFileOptions aPrintFileOptions;
148 0 : bool bModified = false;
149 :
150 :
151 0 : if( m_pPaperSizeCB->IsValueChangedFromSaved())
152 0 : aWarnOptions.SetPaperSize(m_pPaperSizeCB->IsChecked());
153 0 : if( m_pPaperOrientationCB->IsValueChangedFromSaved() )
154 0 : aWarnOptions.SetPaperOrientation(m_pPaperOrientationCB->IsChecked());
155 :
156 0 : if( m_pTransparencyCB->IsValueChangedFromSaved() )
157 0 : aWarnOptions.SetTransparency( m_pTransparencyCB->IsChecked() );
158 :
159 0 : ImplSaveControls( m_pPrinterOutputRB->IsChecked() ? &maPrinterOptions : &maPrintFileOptions );
160 :
161 0 : aPrinterOptions.SetPrinterOptions( maPrinterOptions );
162 0 : aPrintFileOptions.SetPrinterOptions( maPrintFileOptions );
163 :
164 0 : return bModified;
165 : }
166 :
167 0 : void SfxCommonPrintOptionsTabPage::Reset( const SfxItemSet* /*rSet*/ )
168 : {
169 0 : SvtPrintWarningOptions aWarnOptions;
170 0 : SvtPrinterOptions aPrinterOptions;
171 0 : SvtPrintFileOptions aPrintFileOptions;
172 :
173 0 : m_pPaperSizeCB->Check( aWarnOptions.IsPaperSize() );
174 0 : m_pPaperOrientationCB->Check( aWarnOptions.IsPaperOrientation() );
175 :
176 0 : m_pTransparencyCB->Check( aWarnOptions.IsTransparency() );
177 :
178 0 : m_pPaperSizeCB->SaveValue();
179 0 : m_pPaperOrientationCB->SaveValue();
180 0 : m_pTransparencyCB->SaveValue();
181 :
182 0 : aPrinterOptions.GetPrinterOptions( maPrinterOptions );
183 0 : aPrintFileOptions.GetPrinterOptions( maPrintFileOptions );
184 :
185 0 : ImplUpdateControls( m_pPrinterOutputRB->IsChecked() ? &maPrinterOptions : &maPrintFileOptions );
186 0 : }
187 :
188 0 : SfxTabPage::sfxpg SfxCommonPrintOptionsTabPage::DeactivatePage( SfxItemSet* pItemSet )
189 : {
190 0 : if( pItemSet )
191 0 : FillItemSet( pItemSet );
192 :
193 0 : return LEAVE_PAGE;
194 : }
195 :
196 0 : void SfxCommonPrintOptionsTabPage::ImplUpdateControls( const PrinterOptions* pCurrentOptions )
197 : {
198 0 : m_pReduceTransparencyCB->Check( pCurrentOptions->IsReduceTransparency() );
199 :
200 0 : if( pCurrentOptions->GetReducedTransparencyMode() == PRINTER_TRANSPARENCY_AUTO )
201 0 : m_pReduceTransparencyAutoRB->Check( true );
202 : else
203 0 : m_pReduceTransparencyNoneRB->Check( true );
204 :
205 0 : m_pReduceGradientsCB->Check( pCurrentOptions->IsReduceGradients() );
206 :
207 0 : if( pCurrentOptions->GetReducedGradientMode() == PRINTER_GRADIENT_STRIPES )
208 0 : m_pReduceGradientsStripesRB->Check( true );
209 : else
210 0 : m_pReduceGradientsColorRB->Check( true );
211 :
212 0 : m_pReduceGradientsStepCountNF->SetValue( pCurrentOptions->GetReducedGradientStepCount() );
213 :
214 0 : m_pReduceBitmapsCB->Check( pCurrentOptions->IsReduceBitmaps() );
215 :
216 0 : if( pCurrentOptions->GetReducedBitmapMode() == PRINTER_BITMAP_OPTIMAL )
217 0 : m_pReduceBitmapsOptimalRB->Check( true );
218 0 : else if( pCurrentOptions->GetReducedBitmapMode() == PRINTER_BITMAP_NORMAL )
219 0 : m_pReduceBitmapsNormalRB->Check( true );
220 : else
221 0 : m_pReduceBitmapsResolutionRB->Check( true );
222 :
223 0 : const sal_uInt16 nDPI = pCurrentOptions->GetReducedBitmapResolution();
224 :
225 0 : if( nDPI < aDPIArray[ 0 ] )
226 0 : m_pReduceBitmapsResolutionLB->SelectEntryPos( 0 );
227 : else
228 : {
229 0 : for( long i = ( DPI_COUNT - 1 ); i >= 0; i-- )
230 : {
231 0 : if( nDPI >= aDPIArray[ i ] )
232 : {
233 0 : m_pReduceBitmapsResolutionLB->SelectEntryPos( (sal_uInt16) i );
234 0 : i = -1;
235 : }
236 : }
237 : }
238 :
239 0 : m_pReduceBitmapsResolutionLB->SetText( m_pReduceBitmapsResolutionLB->GetSelectEntry() );
240 :
241 0 : m_pReduceBitmapsTransparencyCB->Check( pCurrentOptions->IsReducedBitmapIncludesTransparency() );
242 0 : m_pConvertToGreyscalesCB->Check( pCurrentOptions->IsConvertToGreyscales() );
243 0 : m_pPDFCB->Check( pCurrentOptions->IsPDFAsStandardPrintJobFormat() );
244 :
245 0 : ClickReduceTransparencyCBHdl(m_pReduceTransparencyCB);
246 0 : ClickReduceGradientsCBHdl(m_pReduceGradientsCB);
247 0 : ClickReduceBitmapsCBHdl(m_pReduceBitmapsCB);
248 0 : }
249 :
250 0 : void SfxCommonPrintOptionsTabPage::ImplSaveControls( PrinterOptions* pCurrentOptions )
251 : {
252 0 : pCurrentOptions->SetReduceTransparency( m_pReduceTransparencyCB->IsChecked() );
253 0 : pCurrentOptions->SetReducedTransparencyMode( m_pReduceTransparencyAutoRB->IsChecked() ? PRINTER_TRANSPARENCY_AUTO : PRINTER_TRANSPARENCY_NONE );
254 0 : pCurrentOptions->SetReduceGradients( m_pReduceGradientsCB->IsChecked() );
255 0 : pCurrentOptions->SetReducedGradientMode( m_pReduceGradientsStripesRB->IsChecked() ? PRINTER_GRADIENT_STRIPES : PRINTER_GRADIENT_COLOR );
256 0 : pCurrentOptions->SetReducedGradientStepCount( (sal_uInt16) m_pReduceGradientsStepCountNF->GetValue() );
257 0 : pCurrentOptions->SetReduceBitmaps( m_pReduceBitmapsCB->IsChecked() );
258 0 : pCurrentOptions->SetReducedBitmapMode( m_pReduceBitmapsOptimalRB->IsChecked() ? PRINTER_BITMAP_OPTIMAL :
259 0 : ( m_pReduceBitmapsNormalRB->IsChecked() ? PRINTER_BITMAP_NORMAL : PRINTER_BITMAP_RESOLUTION ) );
260 0 : pCurrentOptions->SetReducedBitmapResolution( aDPIArray[ std::min( (sal_uInt16) m_pReduceBitmapsResolutionLB->GetSelectEntryPos(),
261 0 : (sal_uInt16)( (sizeof (aDPIArray) / sizeof (aDPIArray[0])) - 1 ) ) ] );
262 0 : pCurrentOptions->SetReducedBitmapIncludesTransparency( m_pReduceBitmapsTransparencyCB->IsChecked() );
263 0 : pCurrentOptions->SetConvertToGreyscales( m_pConvertToGreyscalesCB->IsChecked() );
264 0 : bool bOrigBackEnd = pCurrentOptions->IsPDFAsStandardPrintJobFormat();
265 0 : if (bOrigBackEnd != m_pPDFCB->IsChecked())
266 : {
267 0 : pCurrentOptions->SetPDFAsStandardPrintJobFormat( m_pPDFCB->IsChecked() );
268 : svtools::executeRestartDialog(
269 : comphelper::getProcessComponentContext(), 0,
270 0 : svtools::RESTART_REASON_PDF_AS_STANDARD_JOB_FORMAT);
271 : }
272 0 : }
273 :
274 0 : IMPL_LINK( SfxCommonPrintOptionsTabPage, ClickReduceTransparencyCBHdl, CheckBox*, pBox )
275 : {
276 : (void)pBox; //unused
277 0 : const bool bReduceTransparency = m_pReduceTransparencyCB->IsChecked();
278 :
279 0 : m_pReduceTransparencyAutoRB->Enable( bReduceTransparency );
280 0 : m_pReduceTransparencyNoneRB->Enable( bReduceTransparency );
281 :
282 0 : m_pTransparencyCB->Enable( !bReduceTransparency );
283 :
284 0 : return 0;
285 : }
286 :
287 0 : IMPL_LINK( SfxCommonPrintOptionsTabPage, ClickReduceGradientsCBHdl, CheckBox*, pBox )
288 : {
289 : (void)pBox; //unused
290 0 : const bool bEnable = m_pReduceGradientsCB->IsChecked();
291 :
292 0 : m_pReduceGradientsStripesRB->Enable( bEnable );
293 0 : m_pReduceGradientsColorRB->Enable( bEnable );
294 0 : m_pReduceGradientsStepCountNF->Enable( bEnable );
295 :
296 0 : ToggleReduceGradientsStripesRBHdl(m_pReduceGradientsStripesRB);
297 :
298 0 : return 0;
299 : }
300 :
301 0 : IMPL_LINK( SfxCommonPrintOptionsTabPage, ClickReduceBitmapsCBHdl, CheckBox*, pBox )
302 : {
303 : (void)pBox; //unused
304 0 : const bool bEnable = m_pReduceBitmapsCB->IsChecked();
305 :
306 0 : m_pReduceBitmapsOptimalRB->Enable( bEnable );
307 0 : m_pReduceBitmapsNormalRB->Enable( bEnable );
308 0 : m_pReduceBitmapsResolutionRB->Enable( bEnable );
309 0 : m_pReduceBitmapsTransparencyCB->Enable( bEnable );
310 0 : m_pReduceBitmapsResolutionLB->Enable( bEnable );
311 :
312 0 : ToggleReduceBitmapsResolutionRBHdl(m_pReduceBitmapsResolutionRB);
313 :
314 0 : return 0;
315 : }
316 :
317 0 : IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleReduceGradientsStripesRBHdl, RadioButton*, pButton )
318 : {
319 : (void)pButton; //unused
320 0 : const bool bEnable = m_pReduceGradientsCB->IsChecked() && m_pReduceGradientsStripesRB->IsChecked();
321 :
322 0 : m_pReduceGradientsStepCountNF->Enable( bEnable );
323 :
324 0 : return 0;
325 : }
326 :
327 0 : IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleReduceBitmapsResolutionRBHdl, RadioButton*, pButton )
328 : {
329 : (void)pButton; //unused
330 0 : const bool bEnable = m_pReduceBitmapsCB->IsChecked() && m_pReduceBitmapsResolutionRB->IsChecked();
331 :
332 0 : m_pReduceBitmapsResolutionLB->Enable( bEnable );
333 :
334 0 : return 0;
335 : }
336 :
337 0 : IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleOutputPrinterRBHdl, RadioButton*, pButton )
338 : {
339 0 : if( pButton->IsChecked() )
340 : {
341 0 : ImplUpdateControls( &maPrinterOptions );
342 0 : bOutputForPrinter = true;
343 : }
344 : else
345 0 : ImplSaveControls( &maPrinterOptions );
346 :
347 0 : return 0;
348 : }
349 :
350 0 : IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleOutputPrintFileRBHdl, RadioButton*, pButton )
351 : {
352 0 : if( pButton->IsChecked() )
353 : {
354 0 : ImplUpdateControls( &maPrintFileOptions );
355 0 : bOutputForPrinter = false;
356 0 : m_pPDFCB->Disable();
357 : }
358 : else
359 : {
360 0 : ImplSaveControls( &maPrintFileOptions );
361 0 : m_pPDFCB->Enable();
362 : }
363 :
364 0 : return 0;
365 648 : }
366 :
367 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|