Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / sfx2 / source / dialog / printopt.cxx
blob2df1151feea1f68452f2585bfd1d738be283c55f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <sal/macros.h>
31 #include <vcl/msgbox.hxx>
32 #include <unotools/printwarningoptions.hxx>
33 #include <svtools/printoptions.hxx>
34 #include <svl/flagitem.hxx>
37 #include "printopt.hrc"
38 #include "dialog.hrc"
39 #include "sfx2/sfxresid.hxx"
40 #include <sfx2/viewsh.hxx>
41 #include <sfx2/printopt.hxx>
43 static sal_uInt16 aDPIArray[] = { 72, 96, 150, 200, 300, 600 };
44 static sal_Bool bOutputForPrinter = sal_True;
46 #define DPI_COUNT (sizeof(aDPIArray)/sizeof(aDPIArray[0 ]))
48 SfxCommonPrintOptionsTabPage::SfxCommonPrintOptionsTabPage( Window* pParent, const SfxItemSet& rSet ) :
49 SfxTabPage( pParent, SfxResId( TP_COMMONPRINTOPTIONS ), rSet ),
51 aReduceGB( this, SfxResId( GB_REDUCE ) ),
52 aOutputTypeFT( this, SfxResId( FT_OUTPUTTYPE ) ),
53 aPrinterOutputRB( this, SfxResId( RB_PRINTEROUTPUT ) ),
54 aPrintFileOutputRB( this, SfxResId( RB_PRINTFILEOUTPUT ) ),
55 aOutputGB( this, SfxResId( GB_OUTPUT ) ),
56 aReduceTransparencyCB( this, SfxResId( CB_REDUCETRANSPARENCY ) ),
57 aReduceTransparencyAutoRB( this, SfxResId( RB_REDUCETRANSPARENCY_AUTO ) ),
58 aReduceTransparencyNoneRB( this, SfxResId( RB_REDUCETRANSPARENCY_NONE ) ),
59 aReduceGradientsCB( this, SfxResId( CB_REDUCEGRADIENTS ) ),
60 aReduceGradientsStripesRB( this, SfxResId( RB_REDUCEGRADIENTS_STRIPES ) ),
61 aReduceGradientsColorRB( this, SfxResId( RB_REDUCEGRADIENTS_COLOR ) ),
62 aReduceGradientsStepCountNF( this, SfxResId( NF_REDUCEGRADIENTS_STEPCOUNT ) ),
63 aReduceBitmapsCB( this, SfxResId( CB_REDUCEBITMAPS ) ),
64 aReduceBitmapsOptimalRB( this, SfxResId( RB_REDUCEBITMAPS_OPTIMAL ) ),
65 aReduceBitmapsNormalRB( this, SfxResId( RB_REDUCEBITMAPS_NORMAL ) ),
66 aReduceBitmapsResolutionRB( this, SfxResId( RB_REDUCEBITMAPS_RESOLUTION ) ),
67 aReduceBitmapsResolutionLB( this, SfxResId( LB_REDUCEBITMAPS_RESOLUTION ) ),
68 aReduceBitmapsTransparencyCB( this, SfxResId( CB_REDUCEBITMAPS_TRANSPARENCY ) ),
69 aConvertToGreyscalesCB( this, SfxResId( CB_CONVERTTOGREYSCALES ) ),
70 aWarnGB( this, SfxResId( GB_PRINT_WARN ) ),
71 aPaperSizeCB( this, SfxResId( CB_PAPERSIZE ) ),
72 aPaperOrientationCB( this, SfxResId( CB_PAPERORIENTATION ) ),
73 aTransparencyCB( this, SfxResId( CB_TRANSPARENCY ) )
75 FreeResource();
77 aOutputGB.SetStyle( aOutputGB.GetStyle() | WB_NOLABEL );
79 if( bOutputForPrinter )
81 aPrinterOutputRB.Check( sal_True );
82 aOutputGB.SetText( OutputDevice::GetNonMnemonicString( aPrinterOutputRB.GetText() ) );
84 else
86 aPrintFileOutputRB.Check( sal_True );
87 aOutputGB.SetText( OutputDevice::GetNonMnemonicString( aPrintFileOutputRB.GetText() ) );
90 aPrinterOutputRB.SetToggleHdl( LINK( this, SfxCommonPrintOptionsTabPage, ToggleOutputPrinterRBHdl ) );
91 aPrintFileOutputRB.SetToggleHdl( LINK( this, SfxCommonPrintOptionsTabPage, ToggleOutputPrintFileRBHdl ) );
93 aReduceTransparencyCB.SetClickHdl( LINK( this, SfxCommonPrintOptionsTabPage, ClickReduceTransparencyCBHdl ) );
94 aReduceGradientsCB.SetClickHdl( LINK( this, SfxCommonPrintOptionsTabPage, ClickReduceGradientsCBHdl ) );
95 aReduceBitmapsCB.SetClickHdl( LINK( this, SfxCommonPrintOptionsTabPage, ClickReduceBitmapsCBHdl ) );
97 aReduceGradientsStripesRB.SetToggleHdl( LINK( this, SfxCommonPrintOptionsTabPage, ToggleReduceGradientsStripesRBHdl ) );
98 aReduceBitmapsResolutionRB.SetToggleHdl( LINK( this, SfxCommonPrintOptionsTabPage, ToggleReduceBitmapsResolutionRBHdl ) );
100 // #i89164# calculate dynamically the width of radiobutton and listbox
101 const long nOffset = 10;
102 Size aOldSize = aReduceBitmapsResolutionRB.GetSizePixel();
103 Size aNewSize = aReduceBitmapsResolutionRB.GetOptimalSize( WINDOWSIZE_PREFERRED );
104 aNewSize.Width() += nOffset;
105 aNewSize.Height() = aOldSize.Height();
106 long nDelta = aOldSize.Width() - aNewSize.Width();
107 aReduceBitmapsResolutionRB.SetSizePixel( aNewSize );
108 Point aPos = aReduceBitmapsResolutionLB.GetPosPixel();
109 aPos.X() -= nDelta;
110 aOldSize = aReduceBitmapsResolutionLB.GetSizePixel();
111 aNewSize = aReduceBitmapsResolutionLB.GetOptimalSize( WINDOWSIZE_PREFERRED );
112 aNewSize.Width() += nOffset;
113 aNewSize.Height() = aOldSize.Height();
114 aReduceBitmapsResolutionLB.SetPosSizePixel( aPos, aNewSize );
117 SfxCommonPrintOptionsTabPage::~SfxCommonPrintOptionsTabPage()
121 SfxTabPage* SfxCommonPrintOptionsTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
123 return( new SfxCommonPrintOptionsTabPage( pParent, rAttrSet ) );
126 Window* SfxCommonPrintOptionsTabPage::GetParentLabeledBy( const Window* pWindow ) const
128 if ( pWindow == (Window *)&aReduceGradientsStepCountNF )
129 return (Window *)&aReduceGradientsStripesRB;
130 else if ( pWindow == (Window *)&aReduceBitmapsResolutionLB )
131 return (Window *)&aReduceBitmapsResolutionRB;
132 else
133 return SfxTabPage::GetParentLabeledBy( pWindow );
136 Window* SfxCommonPrintOptionsTabPage::GetParentLabelFor( const Window* pWindow ) const
138 if ( pWindow == (Window *)&aReduceGradientsStripesRB )
139 return (Window *)&aReduceGradientsStepCountNF;
140 else if ( pWindow == (Window *)&aReduceBitmapsResolutionRB )
141 return (Window *)&aReduceBitmapsResolutionLB;
142 else
143 return SfxTabPage::GetParentLabelFor( pWindow );
146 sal_Bool SfxCommonPrintOptionsTabPage::FillItemSet( SfxItemSet& /*rSet*/ )
148 SvtPrintWarningOptions aWarnOptions;
149 SvtPrinterOptions aPrinterOptions;
150 SvtPrintFileOptions aPrintFileOptions;
151 sal_Bool bModified = sal_False;
154 if( aPaperSizeCB.IsChecked() != aPaperSizeCB.GetSavedValue())
155 aWarnOptions.SetPaperSize(aPaperSizeCB.IsChecked());
156 if( aPaperOrientationCB.IsChecked() != aPaperOrientationCB.GetSavedValue() )
157 aWarnOptions.SetPaperOrientation(aPaperOrientationCB.IsChecked());
159 if( aTransparencyCB.IsChecked() != aTransparencyCB.GetSavedValue() )
160 aWarnOptions.SetTransparency( aTransparencyCB.IsChecked() );
162 ImplSaveControls( aPrinterOutputRB.IsChecked() ? &maPrinterOptions : &maPrintFileOptions );
164 aPrinterOptions.SetPrinterOptions( maPrinterOptions );
165 aPrintFileOptions.SetPrinterOptions( maPrintFileOptions );
167 return bModified;
170 void SfxCommonPrintOptionsTabPage::Reset( const SfxItemSet& /*rSet*/ )
172 SvtPrintWarningOptions aWarnOptions;
173 SvtPrinterOptions aPrinterOptions;
174 SvtPrintFileOptions aPrintFileOptions;
176 aPaperSizeCB.Check( aWarnOptions.IsPaperSize() );
177 aPaperOrientationCB.Check( aWarnOptions.IsPaperOrientation() );
179 aTransparencyCB.Check( aWarnOptions.IsTransparency() );
181 aPaperSizeCB.SaveValue();
182 aPaperOrientationCB.SaveValue();
183 aTransparencyCB.SaveValue();
185 aPrinterOptions.GetPrinterOptions( maPrinterOptions );
186 aPrintFileOptions.GetPrinterOptions( maPrintFileOptions );
188 ImplUpdateControls( aPrinterOutputRB.IsChecked() ? &maPrinterOptions : &maPrintFileOptions );
190 // #i63982#
191 ImplSetAccessibleNames();
194 int SfxCommonPrintOptionsTabPage::DeactivatePage( SfxItemSet* pItemSet )
196 if( pItemSet )
197 FillItemSet( *pItemSet );
199 return LEAVE_PAGE;
202 void SfxCommonPrintOptionsTabPage::ImplUpdateControls( const PrinterOptions* pCurrentOptions )
204 aReduceTransparencyCB.Check( pCurrentOptions->IsReduceTransparency() );
206 if( pCurrentOptions->GetReducedTransparencyMode() == PRINTER_TRANSPARENCY_AUTO )
207 aReduceTransparencyAutoRB.Check( sal_True );
208 else
209 aReduceTransparencyNoneRB.Check( sal_True );
211 aReduceGradientsCB.Check( pCurrentOptions->IsReduceGradients() );
213 if( pCurrentOptions->GetReducedGradientMode() == PRINTER_GRADIENT_STRIPES )
214 aReduceGradientsStripesRB.Check( sal_True );
215 else
216 aReduceGradientsColorRB.Check( sal_True );
218 aReduceGradientsStepCountNF.SetValue( pCurrentOptions->GetReducedGradientStepCount() );
220 aReduceBitmapsCB.Check( pCurrentOptions->IsReduceBitmaps() );
222 if( pCurrentOptions->GetReducedBitmapMode() == PRINTER_BITMAP_OPTIMAL )
223 aReduceBitmapsOptimalRB.Check( sal_True );
224 else if( pCurrentOptions->GetReducedBitmapMode() == PRINTER_BITMAP_NORMAL )
225 aReduceBitmapsNormalRB.Check( sal_True );
226 else
227 aReduceBitmapsResolutionRB.Check( sal_True );
229 const sal_uInt16 nDPI = pCurrentOptions->GetReducedBitmapResolution();
231 if( nDPI < aDPIArray[ 0 ] )
232 aReduceBitmapsResolutionLB.SelectEntryPos( 0 );
233 else
235 for( long i = ( DPI_COUNT - 1 ); i >= 0; i-- )
237 if( nDPI >= aDPIArray[ i ] )
239 aReduceBitmapsResolutionLB.SelectEntryPos( (sal_uInt16) i );
240 i = -1;
245 aReduceBitmapsResolutionLB.SetText( aReduceBitmapsResolutionLB.GetEntry( aReduceBitmapsResolutionLB.GetSelectEntryPos() ) );
247 aReduceBitmapsTransparencyCB.Check( pCurrentOptions->IsReducedBitmapIncludesTransparency() );
248 aConvertToGreyscalesCB.Check( pCurrentOptions->IsConvertToGreyscales() );
250 ClickReduceTransparencyCBHdl( &aReduceTransparencyCB );
251 ClickReduceGradientsCBHdl( &aReduceGradientsCB );
252 ClickReduceBitmapsCBHdl( &aReduceBitmapsCB );
255 void SfxCommonPrintOptionsTabPage::ImplSetAccessibleNames()
257 static const String cSeparator = String::CreateFromAscii( " - " );
259 String sReduceText = aReduceGB.GetDisplayText();
260 sReduceText += cSeparator;
262 String sAccessibleName = sReduceText;
263 sAccessibleName += aPrinterOutputRB.GetDisplayText();
264 aPrinterOutputRB.SetAccessibleName( sAccessibleName );
266 sAccessibleName = sReduceText;
267 sAccessibleName += aPrintFileOutputRB.GetDisplayText();
268 aPrintFileOutputRB.SetAccessibleName( sAccessibleName );
270 String sOutputText = sReduceText;
271 sOutputText += aOutputGB.GetDisplayText();
272 sOutputText += cSeparator;
274 sAccessibleName = sOutputText;
275 sAccessibleName += aReduceTransparencyCB.GetDisplayText();
276 aReduceTransparencyCB.SetAccessibleName( sAccessibleName );
278 String sTransparencyText = aReduceTransparencyCB.GetAccessibleName();
279 sTransparencyText += cSeparator;
281 sAccessibleName = sTransparencyText;
282 sAccessibleName += aReduceTransparencyAutoRB.GetDisplayText();
283 aReduceTransparencyAutoRB.SetAccessibleName( sAccessibleName );
285 sAccessibleName = sTransparencyText;
286 sAccessibleName += aReduceTransparencyNoneRB.GetDisplayText();
287 aReduceTransparencyNoneRB.SetAccessibleName( sAccessibleName );
289 sAccessibleName = sOutputText;
290 sAccessibleName += aReduceGradientsCB.GetDisplayText();
291 aReduceGradientsCB.SetAccessibleName( sAccessibleName );
293 String sGradientText = aReduceGradientsCB.GetAccessibleName();
294 sGradientText += cSeparator;
296 sAccessibleName = sGradientText;
297 sAccessibleName += aReduceGradientsStripesRB.GetDisplayText();
298 aReduceGradientsStripesRB.SetAccessibleName( sAccessibleName );
300 sAccessibleName = aReduceGradientsStripesRB.GetAccessibleName();
301 aReduceGradientsStepCountNF.SetAccessibleName( sAccessibleName );
303 sAccessibleName = sGradientText;
304 sAccessibleName += aReduceGradientsColorRB.GetDisplayText();
305 aReduceGradientsColorRB.SetAccessibleName( sAccessibleName );
307 sAccessibleName = sOutputText;
308 sAccessibleName += aReduceBitmapsCB.GetDisplayText();
309 aReduceBitmapsCB.SetAccessibleName( sAccessibleName );
311 String sBitmapText = aReduceBitmapsCB.GetAccessibleName();
312 sBitmapText += cSeparator;
314 sAccessibleName = sBitmapText;
315 sAccessibleName += aReduceBitmapsOptimalRB.GetDisplayText();
316 aReduceBitmapsOptimalRB.SetAccessibleName( sAccessibleName );
318 sAccessibleName = sBitmapText;
319 sAccessibleName += aReduceBitmapsNormalRB.GetDisplayText();
320 aReduceBitmapsNormalRB.SetAccessibleName( sAccessibleName );
322 sAccessibleName = sBitmapText;
323 sAccessibleName += aReduceBitmapsResolutionRB.GetDisplayText();
324 aReduceBitmapsResolutionRB.SetAccessibleName( sAccessibleName );
326 sAccessibleName = aReduceBitmapsResolutionRB.GetAccessibleName();
327 aReduceBitmapsResolutionLB.SetAccessibleName( sAccessibleName );
329 sAccessibleName = sBitmapText;
330 sAccessibleName += aReduceBitmapsTransparencyCB.GetDisplayText();
331 aReduceBitmapsTransparencyCB.SetAccessibleName( sAccessibleName );
333 sAccessibleName = sOutputText;
334 sAccessibleName += aConvertToGreyscalesCB.GetDisplayText();
335 aConvertToGreyscalesCB.SetAccessibleName( sAccessibleName );
337 String sWarnText = aWarnGB.GetDisplayText();
338 sWarnText += cSeparator;
340 sAccessibleName = sWarnText;
341 sAccessibleName += aPaperSizeCB.GetDisplayText();
342 aPaperSizeCB.SetAccessibleName( sAccessibleName );
344 sAccessibleName = sWarnText;
345 sAccessibleName += aPaperOrientationCB.GetDisplayText();
346 aPaperOrientationCB.SetAccessibleName( sAccessibleName );
348 sAccessibleName = sWarnText;
349 sAccessibleName += aTransparencyCB.GetDisplayText();
350 aTransparencyCB.SetAccessibleName( sAccessibleName );
353 void SfxCommonPrintOptionsTabPage::ImplSaveControls( PrinterOptions* pCurrentOptions )
355 pCurrentOptions->SetReduceTransparency( aReduceTransparencyCB.IsChecked() );
356 pCurrentOptions->SetReducedTransparencyMode( aReduceTransparencyAutoRB.IsChecked() ? PRINTER_TRANSPARENCY_AUTO : PRINTER_TRANSPARENCY_NONE );
357 pCurrentOptions->SetReduceGradients( aReduceGradientsCB.IsChecked() );
358 pCurrentOptions->SetReducedGradientMode( aReduceGradientsStripesRB.IsChecked() ? PRINTER_GRADIENT_STRIPES : PRINTER_GRADIENT_COLOR );
359 pCurrentOptions->SetReducedGradientStepCount( (sal_uInt16) aReduceGradientsStepCountNF.GetValue() );
360 pCurrentOptions->SetReduceBitmaps( aReduceBitmapsCB.IsChecked() );
361 pCurrentOptions->SetReducedBitmapMode( aReduceBitmapsOptimalRB.IsChecked() ? PRINTER_BITMAP_OPTIMAL :
362 ( aReduceBitmapsNormalRB.IsChecked() ? PRINTER_BITMAP_NORMAL : PRINTER_BITMAP_RESOLUTION ) );
363 pCurrentOptions->SetReducedBitmapResolution( aDPIArray[ Min( (sal_uInt16) aReduceBitmapsResolutionLB.GetSelectEntryPos(),
364 (sal_uInt16)( (sizeof (aDPIArray) / sizeof (aDPIArray[0])) - 1 ) ) ] );
365 pCurrentOptions->SetReducedBitmapIncludesTransparency( aReduceBitmapsTransparencyCB.IsChecked() );
366 pCurrentOptions->SetConvertToGreyscales( aConvertToGreyscalesCB.IsChecked() );
369 IMPL_LINK( SfxCommonPrintOptionsTabPage, ClickReduceTransparencyCBHdl, CheckBox*, pBox )
371 (void)pBox; //unused
372 const sal_Bool bReduceTransparency = aReduceTransparencyCB.IsChecked();
374 aReduceTransparencyAutoRB.Enable( bReduceTransparency );
375 aReduceTransparencyNoneRB.Enable( bReduceTransparency );
377 aTransparencyCB.Enable( !bReduceTransparency );
379 return 0;
382 IMPL_LINK( SfxCommonPrintOptionsTabPage, ClickReduceGradientsCBHdl, CheckBox*, pBox )
384 (void)pBox; //unused
385 const sal_Bool bEnable = aReduceGradientsCB.IsChecked();
387 aReduceGradientsStripesRB.Enable( bEnable );
388 aReduceGradientsColorRB.Enable( bEnable );
389 aReduceGradientsStepCountNF.Enable( bEnable );
391 ToggleReduceGradientsStripesRBHdl( &aReduceGradientsStripesRB );
393 return 0;
396 IMPL_LINK( SfxCommonPrintOptionsTabPage, ClickReduceBitmapsCBHdl, CheckBox*, pBox )
398 (void)pBox; //unused
399 const sal_Bool bEnable = aReduceBitmapsCB.IsChecked();
401 aReduceBitmapsOptimalRB.Enable( bEnable );
402 aReduceBitmapsNormalRB.Enable( bEnable );
403 aReduceBitmapsResolutionRB.Enable( bEnable );
404 aReduceBitmapsTransparencyCB.Enable( bEnable );
405 aReduceBitmapsResolutionLB.Enable( bEnable );
407 ToggleReduceBitmapsResolutionRBHdl( &aReduceBitmapsResolutionRB );
409 return 0;
412 IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleReduceGradientsStripesRBHdl, RadioButton*, pButton )
414 (void)pButton; //unused
415 const sal_Bool bEnable = aReduceGradientsCB.IsChecked() && aReduceGradientsStripesRB.IsChecked();
417 aReduceGradientsStepCountNF.Enable( bEnable );
419 return 0;
422 IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleReduceBitmapsResolutionRBHdl, RadioButton*, pButton )
424 (void)pButton; //unused
425 const sal_Bool bEnable = aReduceBitmapsCB.IsChecked() && aReduceBitmapsResolutionRB.IsChecked();
427 aReduceBitmapsResolutionLB.Enable( bEnable );
429 return 0;
432 IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleOutputPrinterRBHdl, RadioButton*, pButton )
434 if( pButton->IsChecked() )
436 aOutputGB.SetText( OutputDevice::GetNonMnemonicString( pButton->GetText() ) );
437 ImplUpdateControls( &maPrinterOptions );
438 bOutputForPrinter = sal_True;
439 // #i63982#
440 ImplSetAccessibleNames();
442 else
443 ImplSaveControls( &maPrinterOptions );
445 return 0;
448 IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleOutputPrintFileRBHdl, RadioButton*, pButton )
450 if( pButton->IsChecked() )
452 aOutputGB.SetText( OutputDevice::GetNonMnemonicString( pButton->GetText() ) );
453 ImplUpdateControls( &maPrintFileOptions );
454 bOutputForPrinter = sal_False;
455 // #i63982#
456 ImplSetAccessibleNames();
458 else
459 ImplSaveControls( &maPrintFileOptions );
461 return 0;
464 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */