Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / vcl / source / window / printdlg.cxx
blobb8cb188bde4dd315ead52d535c7360104509b865
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include "printdlg.hxx"
21 #include "svdata.hxx"
22 #include "svids.hrc"
23 #include "jobset.h"
25 #include "vcl/print.hxx"
26 #include "vcl/dialog.hxx"
27 #include "vcl/button.hxx"
28 #include "vcl/wall.hxx"
29 #include "vcl/status.hxx"
30 #include "vcl/decoview.hxx"
31 #include "vcl/configsettings.hxx"
32 #include "vcl/help.hxx"
33 #include "vcl/layout.hxx"
34 #include "vcl/svapp.hxx"
35 #include "vcl/unohelp.hxx"
37 #include "unotools/localedatawrapper.hxx"
39 #include "rtl/strbuf.hxx"
41 #include "com/sun/star/lang/XMultiServiceFactory.hpp"
42 #include "com/sun/star/container/XNameAccess.hpp"
43 #include "com/sun/star/beans/PropertyValue.hpp"
44 #include "com/sun/star/awt/Size.hpp"
46 using namespace vcl;
47 using namespace com::sun::star;
48 using namespace com::sun::star::uno;
49 using namespace com::sun::star::lang;
50 using namespace com::sun::star::container;
51 using namespace com::sun::star::beans;
53 extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makePrintPreviewWindow(Window *pParent, VclBuilder::stringmap &)
55 return new PrintDialog::PrintPreviewWindow(pParent);
58 extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeShowNupOrderWindow(Window *pParent, VclBuilder::stringmap &)
60 return new PrintDialog::ShowNupOrderWindow(pParent);
63 PrintDialog::PrintPreviewWindow::PrintPreviewWindow( Window* i_pParent )
64 : Window( i_pParent, 0 )
65 , maOrigSize( 10, 10 )
66 , maPageVDev( *this )
67 , maToolTipString(VclResId( SV_PRINT_PRINTPREVIEW_TXT).toString())
68 , mbGreyscale( false )
69 , maHorzDim( this, WB_HORZ | WB_CENTER )
70 , maVertDim( this, WB_VERT | WB_VCENTER )
72 SetPaintTransparent( sal_True );
73 SetBackground();
74 maPageVDev.SetBackground( Color( COL_WHITE ) );
75 maHorzDim.Show();
76 maVertDim.Show();
78 maHorzDim.SetText( OUString( "2.0in" ) );
79 maVertDim.SetText( OUString( "2.0in" ) );
82 PrintDialog::PrintPreviewWindow::~PrintPreviewWindow()
86 const sal_Int32 PrintDialog::PrintPreviewWindow::PREVIEW_BITMAP_WIDTH = 1600;
88 void PrintDialog::PrintPreviewWindow::DataChanged( const DataChangedEvent& i_rDCEvt )
90 // react on settings changed
91 if( i_rDCEvt.GetType() == DATACHANGED_SETTINGS )
93 maPageVDev.SetBackground( Color( COL_WHITE ) );
95 Window::DataChanged( i_rDCEvt );
98 void PrintDialog::PrintPreviewWindow::Resize()
100 Size aNewSize( GetSizePixel() );
101 long nTextHeight = maHorzDim.GetTextHeight();
102 // leave small space for decoration
103 aNewSize.Width() -= nTextHeight + 2;
104 aNewSize.Height() -= nTextHeight + 2;
105 Size aScaledSize;
106 double fScale = 1.0;
108 // #i106435# catch corner case of Size(0,0)
109 Size aOrigSize( maOrigSize );
110 if( aOrigSize.Width() < 1 )
111 aOrigSize.Width() = aNewSize.Width();
112 if( aOrigSize.Height() < 1 )
113 aOrigSize.Height() = aNewSize.Height();
114 if( aOrigSize.Width() > aOrigSize.Height() )
116 aScaledSize = Size( aNewSize.Width(), aNewSize.Width() * aOrigSize.Height() / aOrigSize.Width() );
117 if( aScaledSize.Height() > aNewSize.Height() )
118 fScale = double(aNewSize.Height())/double(aScaledSize.Height());
120 else
122 aScaledSize = Size( aNewSize.Height() * aOrigSize.Width() / aOrigSize.Height(), aNewSize.Height() );
123 if( aScaledSize.Width() > aNewSize.Width() )
124 fScale = double(aNewSize.Width())/double(aScaledSize.Width());
126 aScaledSize.Width() = long(aScaledSize.Width()*fScale);
127 aScaledSize.Height() = long(aScaledSize.Height()*fScale);
129 maPreviewSize = aScaledSize;
131 // #i104784# if we render the page too small then rounding issues result in
132 // layout artifacts looking really bad. So scale the page unto a device that is not
133 // full page size but not too small either. This also results in much better visual
134 // quality of the preview, e.g. when its height approaches the number of text lines
135 // find a good scaling factor
137 double aAspectRatio = aScaledSize.Height() / (double) aScaledSize.Width();
139 aScaledSize.Width() = PREVIEW_BITMAP_WIDTH;
140 aScaledSize.Height() = PREVIEW_BITMAP_WIDTH * aAspectRatio;
142 maPageVDev.SetOutputSizePixel( aScaledSize, sal_False );
144 // position dimension lines
145 Point aRef( nTextHeight + (aNewSize.Width() - maPreviewSize.Width())/2,
146 nTextHeight + (aNewSize.Height() - maPreviewSize.Height())/2 );
147 maHorzDim.SetPosSizePixel( Point( aRef.X(), aRef.Y() - nTextHeight ),
148 Size( maPreviewSize.Width(), nTextHeight ) );
149 maVertDim.SetPosSizePixel( Point( aRef.X() - nTextHeight, aRef.Y() ),
150 Size( nTextHeight, maPreviewSize.Height() ) );
154 void PrintDialog::PrintPreviewWindow::Paint( const Rectangle& )
156 long nTextHeight = maHorzDim.GetTextHeight();
157 Size aSize( GetSizePixel() );
158 Point aOffset( (aSize.Width() - maPreviewSize.Width() + nTextHeight) / 2 ,
159 (aSize.Height() - maPreviewSize.Height() + nTextHeight) / 2 );
161 if( !maReplacementString.isEmpty() )
163 // replacement is active
164 Push();
165 Font aFont( GetSettings().GetStyleSettings().GetLabelFont() );
166 SetZoomedPointFont( aFont );
167 Rectangle aTextRect( aOffset + Point( 2, 2 ),
168 Size( maPreviewSize.Width() - 4, maPreviewSize.Height() - 4 ) );
169 DrawText( aTextRect, maReplacementString,
170 TEXT_DRAW_CENTER | TEXT_DRAW_VCENTER | TEXT_DRAW_WORDBREAK | TEXT_DRAW_MULTILINE
172 Pop();
174 else
176 Bitmap aPreviewBitmap(maPreviewBitmap);
177 aPreviewBitmap.Scale(maPreviewSize, BMP_SCALE_BESTQUALITY);
178 DrawBitmap(aOffset, aPreviewBitmap);
181 Rectangle aFrameRect( aOffset + Point( -1, -1 ),
182 Size( maPreviewSize.Width() + 2, maPreviewSize.Height() + 2 ) );
183 DecorationView aVw( this );
184 aVw.DrawFrame( aFrameRect, FRAME_DRAW_GROUP );
187 void PrintDialog::PrintPreviewWindow::Command( const CommandEvent& rEvt )
189 if( rEvt.GetCommand() == COMMAND_WHEEL )
191 const CommandWheelData* pWheelData = rEvt.GetWheelData();
192 PrintDialog* pDlg = dynamic_cast<PrintDialog*>(GetParentDialog());
193 if( pDlg )
195 if( pWheelData->GetDelta() > 0 )
196 pDlg->previewForward();
197 else if( pWheelData->GetDelta() < 0 )
198 pDlg->previewBackward();
203 void PrintDialog::PrintPreviewWindow::setPreview( const GDIMetaFile& i_rNewPreview,
204 const Size& i_rOrigSize,
205 const OUString& i_rPaperName,
206 const OUString& i_rReplacement,
207 sal_Int32 i_nDPIX,
208 sal_Int32 i_nDPIY,
209 bool i_bGreyscale
212 OUStringBuffer aBuf( 256 );
213 aBuf.append( maToolTipString );
214 SetQuickHelpText( aBuf.makeStringAndClear() );
215 maMtf = i_rNewPreview;
217 maOrigSize = i_rOrigSize;
218 maReplacementString = i_rReplacement;
219 mbGreyscale = i_bGreyscale;
220 maPageVDev.SetReferenceDevice( i_nDPIX, i_nDPIY );
221 maPageVDev.EnableOutput( sal_True );
223 // use correct measurements
224 const LocaleDataWrapper& rLocWrap( GetSettings().GetLocaleDataWrapper() );
225 MapUnit eUnit = MAP_MM;
226 int nDigits = 0;
227 if( rLocWrap.getMeasurementSystemEnum() == MEASURE_US )
229 eUnit = MAP_100TH_INCH;
230 nDigits = 2;
232 Size aLogicPaperSize( LogicToLogic( i_rOrigSize, MapMode( MAP_100TH_MM ), MapMode( eUnit ) ) );
233 OUString aNumText( rLocWrap.getNum( aLogicPaperSize.Width(), nDigits ) );
234 aBuf.append( aNumText );
235 aBuf.appendAscii( eUnit == MAP_MM ? "mm" : "in" );
236 if( !i_rPaperName.isEmpty() )
238 aBuf.appendAscii( " (" );
239 aBuf.append( i_rPaperName );
240 aBuf.append( ')' );
242 maHorzDim.SetText( aBuf.makeStringAndClear() );
244 aNumText = rLocWrap.getNum( aLogicPaperSize.Height(), nDigits );
245 aBuf.append( aNumText );
246 aBuf.appendAscii( eUnit == MAP_MM ? "mm" : "in" );
247 maVertDim.SetText( aBuf.makeStringAndClear() );
249 Resize();
250 preparePreviewBitmap();
251 Invalidate();
254 void PrintDialog::PrintPreviewWindow::preparePreviewBitmap()
256 GDIMetaFile aMtf( maMtf );
258 Size aVDevSize( maPageVDev.GetOutputSizePixel() );
259 const Size aLogicSize( maPageVDev.PixelToLogic( aVDevSize, MapMode( MAP_100TH_MM ) ) );
260 Size aOrigSize( maOrigSize );
261 if( aOrigSize.Width() < 1 )
262 aOrigSize.Width() = aLogicSize.Width();
263 if( aOrigSize.Height() < 1 )
264 aOrigSize.Height() = aLogicSize.Height();
265 double fScale = double(aLogicSize.Width())/double(aOrigSize.Width());
268 maPageVDev.Erase();
269 maPageVDev.Push();
270 maPageVDev.SetMapMode( MAP_100TH_MM );
271 sal_uLong nOldDrawMode = maPageVDev.GetDrawMode();
272 if( mbGreyscale )
273 maPageVDev.SetDrawMode( maPageVDev.GetDrawMode() |
274 ( DRAWMODE_GRAYLINE | DRAWMODE_GRAYFILL | DRAWMODE_GRAYTEXT |
275 DRAWMODE_GRAYBITMAP | DRAWMODE_GRAYGRADIENT ) );
276 aMtf.WindStart();
277 aMtf.Scale( fScale, fScale );
278 aMtf.WindStart();
280 const sal_uInt16 nOriginalAA(maPageVDev.GetAntialiasing());
281 maPageVDev.SetAntialiasing(nOriginalAA | ANTIALIASING_ENABLE_B2DDRAW);
282 aMtf.Play( &maPageVDev, Point( 0, 0 ), aLogicSize );
283 maPageVDev.SetAntialiasing(nOriginalAA);
285 maPageVDev.Pop();
287 SetMapMode( MAP_PIXEL );
288 maPageVDev.SetMapMode( MAP_PIXEL );
290 maPreviewBitmap = Bitmap(maPageVDev.GetBitmap(Point(0, 0), aVDevSize));
292 maPageVDev.SetDrawMode( nOldDrawMode );
295 PrintDialog::ShowNupOrderWindow::ShowNupOrderWindow( Window* i_pParent )
296 : Window( i_pParent, WB_NOBORDER )
297 , mnOrderMode( 0 )
298 , mnRows( 1 )
299 , mnColumns( 1 )
301 ImplInitSettings();
304 PrintDialog::ShowNupOrderWindow::~ShowNupOrderWindow()
308 void PrintDialog::ShowNupOrderWindow::ImplInitSettings()
310 SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetFieldColor() ) );
313 Size PrintDialog::ShowNupOrderWindow::GetOptimalSize() const
315 return Size(70, 70);
318 void PrintDialog::ShowNupOrderWindow::Paint( const Rectangle& i_rRect )
320 Window::Paint( i_rRect );
321 SetMapMode( MAP_PIXEL );
322 SetTextColor( GetSettings().GetStyleSettings().GetFieldTextColor() );
324 int nPages = mnRows * mnColumns;
325 Font aFont( GetSettings().GetStyleSettings().GetFieldFont() );
326 aFont.SetSize( Size( 0, 24 ) );
327 SetFont( aFont );
328 Size aSampleTextSize( GetTextWidth( OUString::number( nPages+1 ) ), GetTextHeight() );
330 Size aOutSize( GetOutputSizePixel() );
331 Size aSubSize( aOutSize.Width() / mnColumns, aOutSize.Height() / mnRows );
332 // calculate font size: shrink the sample text so it fits
333 double fX = double(aSubSize.Width())/double(aSampleTextSize.Width());
334 double fY = double(aSubSize.Height())/double(aSampleTextSize.Height());
335 double fScale = (fX < fY) ? fX : fY;
336 long nFontHeight = long(24.0*fScale) - 3;
337 if( nFontHeight < 5 )
338 nFontHeight = 5;
339 aFont.SetSize( Size( 0, nFontHeight ) );
340 SetFont( aFont );
341 long nTextHeight = GetTextHeight();
342 for( int i = 0; i < nPages; i++ )
344 OUString aPageText( OUString::number( i+1 ) );
345 int nX = 0, nY = 0;
346 switch( mnOrderMode )
348 case SV_PRINT_PRT_NUP_ORDER_LRTB:
349 nX = (i % mnColumns); nY = (i / mnColumns);
350 break;
351 case SV_PRINT_PRT_NUP_ORDER_TBLR:
352 nX = (i / mnRows); nY = (i % mnRows);
353 break;
354 case SV_PRINT_PRT_NUP_ORDER_RLTB:
355 nX = mnColumns - 1 - (i % mnColumns); nY = (i / mnColumns);
356 break;
357 case SV_PRINT_PRT_NUP_ORDER_TBRL:
358 nX = mnColumns - 1 - (i / mnRows); nY = (i % mnRows);
359 break;
361 Size aTextSize( GetTextWidth( aPageText ), nTextHeight );
362 int nDeltaX = (aSubSize.Width() - aTextSize.Width()) / 2;
363 int nDeltaY = (aSubSize.Height() - aTextSize.Height()) / 2;
364 DrawText( Point( nX * aSubSize.Width() + nDeltaX,
365 nY * aSubSize.Height() + nDeltaY ),
366 aPageText );
368 DecorationView aVw( this );
369 aVw.DrawFrame( Rectangle( Point( 0, 0), aOutSize ), FRAME_DRAW_GROUP );
372 PrintDialog::NUpTabPage::NUpTabPage( VclBuilder *pUIBuilder )
374 pUIBuilder->get(mpPagesBtn, "pagespersheetbtn");
375 pUIBuilder->get(mpBrochureBtn, "brochure");
376 pUIBuilder->get(mpPagesBoxTitleTxt, "pagespersheettxt");
377 pUIBuilder->get(mpNupPagesBox, "paperspersheetlb");
378 pUIBuilder->get(mpNupNumPagesTxt, "pagestxt");
379 pUIBuilder->get(mpNupColEdt, "pagecols");
380 pUIBuilder->get(mpNupTimesTxt, "by");
381 pUIBuilder->get(mpNupRowsEdt, "pagerows");
382 pUIBuilder->get(mpPageMarginTxt1, "pagemargintxt1");
383 pUIBuilder->get(mpPageMarginEdt, "pagemarginsb");
384 pUIBuilder->get(mpPageMarginTxt2, "pagemargintxt2");
385 pUIBuilder->get(mpSheetMarginTxt1, "sheetmargintxt1");
386 pUIBuilder->get(mpSheetMarginEdt, "sheetmarginsb");
387 pUIBuilder->get(mpSheetMarginTxt2, "sheetmargintxt2");
388 pUIBuilder->get(mpNupOrientationTxt, "orientationtxt");
389 pUIBuilder->get(mpNupOrientationBox, "orientationlb");
390 pUIBuilder->get(mpNupOrderTxt, "ordertxt");
391 pUIBuilder->get(mpNupOrderBox, "orderlb");
392 pUIBuilder->get(mpNupOrderWin, "orderpreview");
393 pUIBuilder->get(mpBorderCB, "bordercb");
396 void PrintDialog::NUpTabPage::enableNupControls( bool bEnable )
398 mpNupPagesBox->Enable( bEnable );
399 mpNupNumPagesTxt->Enable( bEnable );
400 mpNupColEdt->Enable( bEnable );
401 mpNupTimesTxt->Enable( bEnable );
402 mpNupRowsEdt->Enable( bEnable );
403 mpPageMarginTxt1->Enable( bEnable );
404 mpPageMarginEdt->Enable( bEnable );
405 mpPageMarginTxt2->Enable( bEnable );
406 mpSheetMarginTxt1->Enable( bEnable );
407 mpSheetMarginEdt->Enable( bEnable );
408 mpSheetMarginTxt2->Enable( bEnable );
409 mpNupOrientationTxt->Enable( bEnable );
410 mpNupOrientationBox->Enable( bEnable );
411 mpNupOrderTxt->Enable( bEnable );
412 mpNupOrderBox->Enable( bEnable );
413 mpNupOrderWin->Enable( bEnable );
414 mpBorderCB->Enable( bEnable );
417 void PrintDialog::NUpTabPage::showAdvancedControls( bool i_bShow )
419 mpNupNumPagesTxt->Show( i_bShow );
420 mpNupColEdt->Show( i_bShow );
421 mpNupTimesTxt->Show( i_bShow );
422 mpNupRowsEdt->Show( i_bShow );
423 mpPageMarginTxt1->Show( i_bShow );
424 mpPageMarginEdt->Show( i_bShow );
425 mpPageMarginTxt2->Show( i_bShow );
426 mpSheetMarginTxt1->Show( i_bShow );
427 mpSheetMarginEdt->Show( i_bShow );
428 mpSheetMarginTxt2->Show( i_bShow );
429 mpNupOrientationTxt->Show( i_bShow );
430 mpNupOrientationBox->Show( i_bShow );
433 void PrintDialog::NUpTabPage::initFromMultiPageSetup( const vcl::PrinterController::MultiPageSetup& i_rMPS )
435 mpNupOrderWin->Show();
436 mpPagesBtn->Check( sal_True );
437 mpBrochureBtn->Show( sal_False );
439 // setup field units for metric fields
440 const LocaleDataWrapper& rLocWrap( mpPageMarginEdt->GetLocaleDataWrapper() );
441 FieldUnit eUnit = FUNIT_MM;
442 sal_uInt16 nDigits = 0;
443 if( rLocWrap.getMeasurementSystemEnum() == MEASURE_US )
445 eUnit = FUNIT_INCH;
446 nDigits = 2;
448 // set units
449 mpPageMarginEdt->SetUnit( eUnit );
450 mpSheetMarginEdt->SetUnit( eUnit );
452 // set precision
453 mpPageMarginEdt->SetDecimalDigits( nDigits );
454 mpSheetMarginEdt->SetDecimalDigits( nDigits );
456 mpSheetMarginEdt->SetValue( mpSheetMarginEdt->Normalize( i_rMPS.nLeftMargin ), FUNIT_100TH_MM );
457 mpPageMarginEdt->SetValue( mpPageMarginEdt->Normalize( i_rMPS.nHorizontalSpacing ), FUNIT_100TH_MM );
458 mpBorderCB->Check( i_rMPS.bDrawBorder );
459 mpNupRowsEdt->SetValue( i_rMPS.nRows );
460 mpNupColEdt->SetValue( i_rMPS.nColumns );
461 mpNupOrderBox->SelectEntryPos( i_rMPS.nOrder );
462 if( i_rMPS.nRows != 1 || i_rMPS.nColumns != 1 )
464 mpNupPagesBox->SelectEntryPos( mpNupPagesBox->GetEntryCount()-1 );
465 showAdvancedControls( true );
466 mpNupOrderWin->setValues( i_rMPS.nOrder, i_rMPS.nColumns, i_rMPS.nRows );
470 void PrintDialog::NUpTabPage::readFromSettings()
474 void PrintDialog::NUpTabPage::storeToSettings()
478 PrintDialog::JobTabPage::JobTabPage( VclBuilder* pUIBuilder )
479 : maCollateImg( VclResId( SV_PRINT_COLLATE_IMG ) )
480 , maNoCollateImg( VclResId( SV_PRINT_NOCOLLATE_IMG ) )
481 , mnCollateUIMode( 0 )
483 pUIBuilder->get(mpPrinters, "printers");
484 mpPrinters->SetStyle(mpPrinters->GetStyle() | WB_SORT);
485 pUIBuilder->get(mpStatusTxt, "status");
486 pUIBuilder->get(mpLocationTxt, "location");
487 pUIBuilder->get(mpCommentTxt, "comment");
488 pUIBuilder->get(mpSetupButton, "setup");
489 pUIBuilder->get(mpCopySpacer, "copyspacer");
490 pUIBuilder->get(mpCopyCountField, "copycount");
491 pUIBuilder->get(mpCollateBox, "collate");
492 pUIBuilder->get(mpCollateImage, "collateimage");
493 pUIBuilder->get(mpReverseOrderBox, "reverseorder");
494 // HACK: this is not a dropdown box, but the dropdown line count
495 // sets the results of GetOptimalSize in a normal ListBox
496 mpPrinters->SetDropDownLineCount( 4 );
499 void PrintDialog::JobTabPage::readFromSettings()
501 SettingsConfigItem* pItem = SettingsConfigItem::get();
502 OUString aValue;
504 aValue = pItem->getValue( OUString( "PrintDialog" ),
505 OUString( "CollateBox" ) );
506 if( aValue.equalsIgnoreAsciiCase("alwaysoff") )
508 mnCollateUIMode = 1;
509 mpCollateBox->Check( sal_False );
510 mpCollateBox->Enable( sal_False );
512 else
514 mnCollateUIMode = 0;
515 aValue = pItem->getValue( OUString( "PrintDialog" ),
516 OUString( "Collate" ) );
517 mpCollateBox->Check( aValue.equalsIgnoreAsciiCase("true") );
521 void PrintDialog::JobTabPage::storeToSettings()
523 SettingsConfigItem* pItem = SettingsConfigItem::get();
524 pItem->setValue( OUString( "PrintDialog" ),
525 OUString( "CopyCount" ),
526 mpCopyCountField->GetText() );
527 pItem->setValue( OUString( "PrintDialog" ),
528 OUString( "Collate" ),
529 mpCollateBox->IsChecked() ? OUString("true") :
530 OUString("false") );
533 PrintDialog::OutputOptPage::OutputOptPage( VclBuilder *pUIBuilder )
535 pUIBuilder->get(mpToFileBox, "printtofile");
536 pUIBuilder->get(mpCollateSingleJobsBox, "singleprintjob");
537 pUIBuilder->get(mpPapersizeFromSetup, "papersizefromsetup");
540 void PrintDialog::OutputOptPage::readFromSettings()
542 SettingsConfigItem* pItem = SettingsConfigItem::get();
543 OUString aValue;
544 aValue = pItem->getValue( OUString( "PrintDialog" ),
545 OUString( "CollateSingleJobs" ) );
546 if ( aValue.equalsIgnoreAsciiCase("true") )
548 mpCollateSingleJobsBox->Check( sal_True );
550 else
552 mpCollateSingleJobsBox->Check( sal_False );
556 void PrintDialog::OutputOptPage::storeToSettings()
558 SettingsConfigItem* pItem = SettingsConfigItem::get();
559 pItem->setValue( OUString( "PrintDialog" ),
560 OUString( "ToFile" ),
561 mpToFileBox->IsChecked() ? OUString("true")
562 : OUString("false") );
563 pItem->setValue( OUString( "PrintDialog" ),
564 OUString( "CollateSingleJobs" ),
565 mpCollateSingleJobsBox->IsChecked() ? OUString("true") :
566 OUString("false") );
569 PrintDialog::PrintDialog( Window* i_pParent, const boost::shared_ptr<PrinterController>& i_rController )
570 : ModalDialog(i_pParent, "PrintDialog", "vcl/ui/printdialog.ui")
571 , mpCustomOptionsUIBuilder(NULL)
572 , maPController( i_rController )
573 , maNUpPage(m_pUIBuilder)
574 , maJobPage(m_pUIBuilder)
575 , maOptionsPage(m_pUIBuilder)
576 , maNoPageStr( VclResId( SV_PRINT_NOPAGES ).toString() )
577 , mnCurPage( 0 )
578 , mnCachedPages( 0 )
579 , maPrintToFileText( VclResId( SV_PRINT_TOFILE_TXT ).toString() )
580 , maDefPrtText( VclResId( SV_PRINT_DEFPRT_TXT ).toString() )
581 , mbShowLayoutPage( sal_True )
583 get(mpOKButton, "ok");
584 get(mpCancelButton, "cancel");
585 get(mpHelpButton, "help");
586 get(mpForwardBtn, "forward");
587 get(mpBackwardBtn, "backward");
588 get(mpNumPagesText, "totalnumpages");
589 get(mpPageEdit, "pageedit-nospin");
590 get(mpTabCtrl, "tabcontrol");
591 get(mpPreviewWindow, "preview");
593 // save printbutton text, gets exchanged occasionally with print to file
594 maPrintText = mpOKButton->GetText();
596 // setup preview controls
597 mpForwardBtn->SetStyle( mpForwardBtn->GetStyle() | WB_BEVELBUTTON );
598 mpBackwardBtn->SetStyle( mpBackwardBtn->GetStyle() | WB_BEVELBUTTON );
600 maPageStr = mpNumPagesText->GetText();
602 // init reverse print
603 maJobPage.mpReverseOrderBox->Check( maPController->getReversePrint() );
605 // fill printer listbox
606 const std::vector< OUString >& rQueues( Printer::GetPrinterQueues() );
607 for( std::vector< OUString >::const_iterator it = rQueues.begin();
608 it != rQueues.end(); ++it )
610 maJobPage.mpPrinters->InsertEntry( *it );
612 // select current printer
613 if( maJobPage.mpPrinters->GetEntryPos( maPController->getPrinter()->GetName() ) != LISTBOX_ENTRY_NOTFOUND )
615 maJobPage.mpPrinters->SelectEntry( maPController->getPrinter()->GetName() );
617 else
619 // fall back to last printer
620 SettingsConfigItem* pItem = SettingsConfigItem::get();
621 OUString aValue( pItem->getValue( OUString( "PrintDialog" ),
622 OUString( "LastPrinter" ) ) );
623 if( maJobPage.mpPrinters->GetEntryPos( aValue ) != LISTBOX_ENTRY_NOTFOUND )
625 maJobPage.mpPrinters->SelectEntry( aValue );
626 maPController->setPrinter( boost::shared_ptr<Printer>( new Printer( aValue ) ) );
628 else
630 // fall back to default printer
631 maJobPage.mpPrinters->SelectEntry( Printer::GetDefaultPrinterName() );
632 maPController->setPrinter( boost::shared_ptr<Printer>( new Printer( Printer::GetDefaultPrinterName() ) ) );
635 // not printing to file
636 maPController->resetPrinterOptions( false );
638 // get the first page
639 preparePreview( true, true );
641 // update the text fields for the printer
642 updatePrinterText();
644 // set a select handler
645 maJobPage.mpPrinters->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) );
647 // setup sizes for N-Up
648 Size aNupSize( maPController->getPrinter()->PixelToLogic(
649 maPController->getPrinter()->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) ) );
650 if( maPController->getPrinter()->GetOrientation() == ORIENTATION_LANDSCAPE )
652 maNupLandscapeSize = aNupSize;
653 maNupPortraitSize = Size( aNupSize.Height(), aNupSize.Width() );
655 else
657 maNupPortraitSize = aNupSize;
658 maNupLandscapeSize = Size( aNupSize.Height(), aNupSize.Width() );
660 maNUpPage.initFromMultiPageSetup( maPController->getMultipage() );
662 // setup click handler on the various buttons
663 mpOKButton->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
664 #if OSL_DEBUG_LEVEL > 1
665 mpCancelButton->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
666 #endif
667 mpHelpButton->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
668 mpForwardBtn->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
669 mpBackwardBtn->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
671 maJobPage.mpCollateBox->SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
672 maJobPage.mpSetupButton->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
673 maNUpPage.mpBorderCB->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
674 maOptionsPage.mpToFileBox->SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
675 maOptionsPage.mpPapersizeFromSetup->SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
676 maJobPage.mpReverseOrderBox->SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
677 maOptionsPage.mpCollateSingleJobsBox->SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
678 maNUpPage.mpPagesBtn->SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
679 // setup modify hdl
680 mpPageEdit->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
681 maJobPage.mpCopyCountField->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
682 maNUpPage.mpNupRowsEdt->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
683 maNUpPage.mpNupColEdt->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
684 maNUpPage.mpPageMarginEdt->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
685 maNUpPage.mpSheetMarginEdt->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
687 // setup select hdl
688 maNUpPage.mpNupPagesBox->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) );
689 maNUpPage.mpNupOrientationBox->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) );
690 maNUpPage.mpNupOrderBox->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) );
692 // setup optional UI options set by application
693 setupOptionalUI();
695 // set change handler for UI options
696 maPController->setOptionChangeHdl( LINK( this, PrintDialog, UIOptionsChanged ) );
698 // remove layout page if unwanted
699 if (!mbShowLayoutPage)
700 mpTabCtrl->RemovePage(mpTabCtrl->GetPageId(2));
702 // restore settings from last run
703 readFromSettings();
705 // setup dependencies
706 checkControlDependencies();
708 if ( maPController->getBoolProperty( OUString( "HideHelpButton" ), sal_False ) )
709 mpHelpButton->Hide();
710 // set initial focus to "Number of copies"
711 maJobPage.mpCopyCountField->GrabFocus();
712 maJobPage.mpCopyCountField->SetSelection( Selection(0, 0xFFFF) );
714 updateNupFromPages();
717 PrintDialog::~PrintDialog()
719 delete mpCustomOptionsUIBuilder;
722 void PrintDialog::readFromSettings()
724 maJobPage.readFromSettings();
725 maNUpPage.readFromSettings();
726 maOptionsPage.readFromSettings();
728 // read last selected tab page; if it exists, activate it
729 SettingsConfigItem* pItem = SettingsConfigItem::get();
730 OUString aValue = pItem->getValue( OUString( "PrintDialog" ),
731 OUString( "LastPage" ) );
732 sal_uInt16 nCount = mpTabCtrl->GetPageCount();
733 for( sal_uInt16 i = 0; i < nCount; i++ )
735 sal_uInt16 nPageId = mpTabCtrl->GetPageId( i );
736 if( aValue.equals( mpTabCtrl->GetPageText( nPageId ) ) )
738 mpTabCtrl->SelectTabPage( nPageId );
739 break;
742 mpOKButton->SetText( maOptionsPage.mpToFileBox->IsChecked() ? maPrintToFileText : maPrintText );
744 // persistent window state
745 OUString aWinState( pItem->getValue( OUString( "PrintDialog" ),
746 OUString( "WindowState" ) ) );
747 if( !aWinState.isEmpty() )
748 SetWindowState( OUStringToOString( aWinState, RTL_TEXTENCODING_UTF8 ) );
750 if( maOptionsPage.mpToFileBox->IsChecked() )
752 maPController->resetPrinterOptions( true );
753 preparePreview( true, true );
757 void PrintDialog::storeToSettings()
759 maJobPage.storeToSettings();
760 maNUpPage.storeToSettings();
761 maOptionsPage.storeToSettings();
763 // store last selected printer
764 SettingsConfigItem* pItem = SettingsConfigItem::get();
765 pItem->setValue( OUString( "PrintDialog" ),
766 OUString( "LastPrinter" ),
767 maJobPage.mpPrinters->GetSelectEntry() );
769 pItem->setValue( OUString( "PrintDialog" ),
770 OUString( "LastPage" ),
771 mpTabCtrl->GetPageText( mpTabCtrl->GetCurPageId() ) );
772 pItem->setValue( OUString( "PrintDialog" ),
773 OUString( "WindowState" ),
774 OStringToOUString( GetWindowState(), RTL_TEXTENCODING_UTF8 )
776 pItem->Commit();
779 bool PrintDialog::isPrintToFile()
781 return maOptionsPage.mpToFileBox->IsChecked();
784 bool PrintDialog::isCollate()
786 return maJobPage.mpCopyCountField->GetValue() > 1 ? maJobPage.mpCollateBox->IsChecked() : sal_False;
789 bool PrintDialog::isSingleJobs()
791 return maOptionsPage.mpCollateSingleJobsBox->IsChecked();
794 void setHelpId( Window* i_pWindow, const Sequence< OUString >& i_rHelpIds, sal_Int32 i_nIndex )
796 if( i_nIndex >= 0 && i_nIndex < i_rHelpIds.getLength() )
797 i_pWindow->SetHelpId( OUStringToOString( i_rHelpIds.getConstArray()[i_nIndex], RTL_TEXTENCODING_UTF8 ) );
800 static void setHelpText( Window* i_pWindow, const Sequence< OUString >& i_rHelpTexts, sal_Int32 i_nIndex )
802 // without a help text set and the correct smartID,
803 // help texts will be retrieved from the online help system
804 if( i_nIndex >= 0 && i_nIndex < i_rHelpTexts.getLength() )
805 i_pWindow->SetHelpText( i_rHelpTexts.getConstArray()[i_nIndex] );
808 void PrintDialog::setupOptionalUI()
810 const Sequence< PropertyValue >& rOptions( maPController->getUIOptions() );
811 for( int i = 0; i < rOptions.getLength(); i++ )
813 if (rOptions[i].Name == "OptionsUIFile")
815 OUString sOptionsUIFile;
816 rOptions[i].Value >>= sOptionsUIFile;
818 Window *pCustom = get<Window>("customcontents");
820 delete mpCustomOptionsUIBuilder;
821 mpCustomOptionsUIBuilder = new VclBuilder(pCustom, getUIRootDir(), sOptionsUIFile);
822 Window *pWindow = mpCustomOptionsUIBuilder->get_widget_root();
823 pWindow->Show();
824 continue;
827 Sequence< beans::PropertyValue > aOptProp;
828 rOptions[i].Value >>= aOptProp;
830 // extract ui element
831 OUString aCtrlType;
832 OString aID;
833 OUString aText;
834 OUString aPropertyName;
835 Sequence< OUString > aChoices;
836 Sequence< sal_Bool > aChoicesDisabled;
837 Sequence< OUString > aHelpTexts;
838 Sequence< OUString > aIDs;
839 Sequence< OUString > aHelpIds;
840 sal_Int64 nMinValue = 0, nMaxValue = 0;
841 OUString aGroupingHint;
842 OUString aDependsOnName;
843 sal_Int32 nDependsOnValue = 0;
844 sal_Bool bUseDependencyRow = sal_False;
846 for( int n = 0; n < aOptProp.getLength(); n++ )
848 const beans::PropertyValue& rEntry( aOptProp[ n ] );
849 if ( rEntry.Name == "ID" )
851 rEntry.Value >>= aIDs;
852 aID = OUStringToOString(aIDs[0], RTL_TEXTENCODING_UTF8);
854 if ( rEntry.Name == "Text" )
856 rEntry.Value >>= aText;
858 else if ( rEntry.Name == "ControlType" )
860 rEntry.Value >>= aCtrlType;
862 else if ( rEntry.Name == "Choices" )
864 rEntry.Value >>= aChoices;
866 else if ( rEntry.Name == "ChoicesDisabled" )
868 rEntry.Value >>= aChoicesDisabled;
870 else if ( rEntry.Name == "Property" )
872 PropertyValue aVal;
873 rEntry.Value >>= aVal;
874 aPropertyName = aVal.Name;
876 else if ( rEntry.Name == "Enabled" )
878 sal_Bool bValue = sal_True;
879 rEntry.Value >>= bValue;
881 else if ( rEntry.Name == "GroupingHint" )
883 rEntry.Value >>= aGroupingHint;
885 else if ( rEntry.Name == "DependsOnName" )
887 rEntry.Value >>= aDependsOnName;
889 else if ( rEntry.Name == "DependsOnEntry" )
891 rEntry.Value >>= nDependsOnValue;
893 else if ( rEntry.Name == "AttachToDependency" )
895 rEntry.Value >>= bUseDependencyRow;
897 else if ( rEntry.Name == "MinValue" )
899 rEntry.Value >>= nMinValue;
901 else if ( rEntry.Name == "MaxValue" )
903 rEntry.Value >>= nMaxValue;
905 else if ( rEntry.Name == "HelpText" )
907 if( ! (rEntry.Value >>= aHelpTexts) )
909 OUString aHelpText;
910 if( (rEntry.Value >>= aHelpText) )
912 aHelpTexts.realloc( 1 );
913 *aHelpTexts.getArray() = aHelpText;
917 else if ( rEntry.Name == "HelpId" )
919 if( ! (rEntry.Value >>= aHelpIds ) )
921 OUString aHelpId;
922 if( (rEntry.Value >>= aHelpId) )
924 aHelpIds.realloc( 1 );
925 *aHelpIds.getArray() = aHelpId;
929 else if ( rEntry.Name == "HintNoLayoutPage" )
931 sal_Bool bNoLayoutPage = sal_False;
932 rEntry.Value >>= bNoLayoutPage;
933 mbShowLayoutPage = ! bNoLayoutPage;
937 if (aCtrlType == "Group" && !aID.isEmpty())
939 TabPage *pPage = get<TabPage>(aID);
940 if (!pPage && mpCustomOptionsUIBuilder)
941 pPage = mpCustomOptionsUIBuilder->get<TabPage>(aID);
942 sal_uInt16 nPageId = mpTabCtrl->GetPageId(*pPage);
944 mpTabCtrl->SetPageText(nPageId, aText);
946 // set help id
947 if (aHelpIds.getLength() > 0)
948 mpTabCtrl->SetHelpId(nPageId, OUStringToOString(aHelpIds.getConstArray()[0], RTL_TEXTENCODING_UTF8));
950 // set help text
951 if (aHelpTexts.getLength() > 0)
952 mpTabCtrl->SetHelpText(nPageId, aHelpTexts.getConstArray()[0]);
954 pPage->Show();
956 else if (aCtrlType == "Subgroup" && !aID.isEmpty())
958 Window *pFrame = get<Window>(aID);
959 if (!pFrame && mpCustomOptionsUIBuilder)
960 pFrame = mpCustomOptionsUIBuilder->get<Window>(aID);
962 pFrame->SetText(aText);
964 // set help id
965 setHelpId(pFrame, aHelpIds, 0);
966 // set help text
967 setHelpText(pFrame, aHelpTexts, 0);
969 pFrame->Show();
971 // EVIL
972 else if( aCtrlType == "Bool" && aGroupingHint == "LayoutPage" && aPropertyName == "PrintProspect" )
974 maNUpPage.mpBrochureBtn->SetText( aText );
975 maNUpPage.mpBrochureBtn->Show();
977 sal_Bool bVal = sal_False;
978 PropertyValue* pVal = maPController->getValue( aPropertyName );
979 if( pVal )
980 pVal->Value >>= bVal;
981 maNUpPage.mpBrochureBtn->Check( bVal );
982 maNUpPage.mpBrochureBtn->Enable( maPController->isUIOptionEnabled( aPropertyName ) && pVal != NULL );
983 maNUpPage.mpBrochureBtn->SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
985 maPropertyToWindowMap[ aPropertyName ].push_back( maNUpPage.mpBrochureBtn );
986 maControlToPropertyMap[maNUpPage.mpBrochureBtn] = aPropertyName;
988 // set help id
989 setHelpId( maNUpPage.mpBrochureBtn, aHelpIds, 0 );
990 // set help text
991 setHelpText( maNUpPage.mpBrochureBtn, aHelpTexts, 0 );
993 else if (aCtrlType == "Bool")
995 // add a check box
996 CheckBox* pNewBox = get<CheckBox>(aID);
997 if (!pNewBox && mpCustomOptionsUIBuilder)
998 pNewBox = mpCustomOptionsUIBuilder->get<CheckBox>(aID);
1000 pNewBox->SetText( aText );
1001 pNewBox->Show();
1003 sal_Bool bVal = sal_False;
1004 PropertyValue* pVal = maPController->getValue( aPropertyName );
1005 if( pVal )
1006 pVal->Value >>= bVal;
1007 pNewBox->Check( bVal );
1008 pNewBox->SetToggleHdl( LINK( this, PrintDialog, UIOption_CheckHdl ) );
1010 maPropertyToWindowMap[ aPropertyName ].push_back( pNewBox );
1011 maControlToPropertyMap[pNewBox] = aPropertyName;
1013 // set help id
1014 setHelpId( pNewBox, aHelpIds, 0 );
1015 // set help text
1016 setHelpText( pNewBox, aHelpTexts, 0 );
1018 else if (aCtrlType == "Radio")
1020 sal_Int32 nCurHelpText = 0;
1022 // iterate options
1023 sal_Int32 nSelectVal = 0;
1024 PropertyValue* pVal = maPController->getValue( aPropertyName );
1025 if( pVal && pVal->Value.hasValue() )
1026 pVal->Value >>= nSelectVal;
1027 for( sal_Int32 m = 0; m < aChoices.getLength(); m++ )
1029 aID = OUStringToOString(aIDs[m], RTL_TEXTENCODING_UTF8);
1030 RadioButton* pBtn = get<RadioButton>(aID);
1031 if (!pBtn && mpCustomOptionsUIBuilder)
1032 pBtn = mpCustomOptionsUIBuilder->get<RadioButton>(aID);
1034 pBtn->SetText( aChoices[m] );
1035 pBtn->Check( m == nSelectVal );
1036 pBtn->SetToggleHdl( LINK( this, PrintDialog, UIOption_RadioHdl ) );
1037 if( aChoicesDisabled.getLength() > m && aChoicesDisabled[m] == sal_True )
1038 pBtn->Enable( sal_False );
1039 pBtn->Show();
1040 maPropertyToWindowMap[ aPropertyName ].push_back( pBtn );
1041 maControlToPropertyMap[pBtn] = aPropertyName;
1042 maControlToNumValMap[pBtn] = m;
1044 // set help id
1045 setHelpId( pBtn, aHelpIds, nCurHelpText );
1046 // set help text
1047 setHelpText( pBtn, aHelpTexts, nCurHelpText );
1048 nCurHelpText++;
1051 else if ( aCtrlType == "List" )
1053 ListBox* pList = get<ListBox>(aID);
1054 if (!pList && mpCustomOptionsUIBuilder)
1055 pList = mpCustomOptionsUIBuilder->get<ListBox>(aID);
1057 // iterate options
1058 for( sal_Int32 m = 0; m < aChoices.getLength(); m++ )
1060 pList->InsertEntry( aChoices[m] );
1062 sal_Int32 nSelectVal = 0;
1063 PropertyValue* pVal = maPController->getValue( aPropertyName );
1064 if( pVal && pVal->Value.hasValue() )
1065 pVal->Value >>= nSelectVal;
1066 pList->SelectEntryPos( static_cast<sal_uInt16>(nSelectVal) );
1067 pList->SetSelectHdl( LINK( this, PrintDialog, UIOption_SelectHdl ) );
1068 pList->SetDropDownLineCount( static_cast<sal_uInt16>(aChoices.getLength()) );
1069 pList->Show();
1071 // set help id
1072 setHelpId( pList, aHelpIds, 0 );
1073 // set help text
1074 setHelpText( pList, aHelpTexts, 0 );
1076 maPropertyToWindowMap[ aPropertyName ].push_back( pList );
1077 maControlToPropertyMap[pList] = aPropertyName;
1079 else if ( aCtrlType == "Range" )
1081 NumericField* pField = get<NumericField>(aID);
1082 if (!pField && mpCustomOptionsUIBuilder)
1083 pField = mpCustomOptionsUIBuilder->get<NumericField>(aID);
1085 // set min/max and current value
1086 if( nMinValue != nMaxValue )
1088 pField->SetMin( nMinValue );
1089 pField->SetMax( nMaxValue );
1091 sal_Int64 nCurVal = 0;
1092 PropertyValue* pVal = maPController->getValue( aPropertyName );
1093 if( pVal && pVal->Value.hasValue() )
1094 pVal->Value >>= nCurVal;
1095 pField->SetValue( nCurVal );
1096 pField->SetModifyHdl( LINK( this, PrintDialog, UIOption_ModifyHdl ) );
1097 pField->Show();
1099 // set help id
1100 setHelpId( pField, aHelpIds, 0 );
1101 // set help text
1102 setHelpText( pField, aHelpTexts, 0 );
1104 maPropertyToWindowMap[ aPropertyName ].push_back( pField );
1105 maControlToPropertyMap[pField] = aPropertyName;
1107 else if (aCtrlType == "Edit")
1109 Edit *pField = get<Edit>(aID);
1110 if (!pField && mpCustomOptionsUIBuilder)
1111 pField = mpCustomOptionsUIBuilder->get<Edit>(aID);
1113 OUString aCurVal;
1114 PropertyValue* pVal = maPController->getValue( aPropertyName );
1115 if( pVal && pVal->Value.hasValue() )
1116 pVal->Value >>= aCurVal;
1117 pField->SetText( aCurVal );
1118 pField->SetModifyHdl( LINK( this, PrintDialog, UIOption_ModifyHdl ) );
1119 pField->Show();
1121 // set help id
1122 setHelpId( pField, aHelpIds, 0 );
1123 // set help text
1124 setHelpText( pField, aHelpTexts, 0 );
1126 maPropertyToWindowMap[ aPropertyName ].push_back( pField );
1127 maControlToPropertyMap[pField] = aPropertyName;
1129 else
1131 OStringBuffer sMessage;
1132 sMessage.append("Unsupported UI option: \"");
1133 sMessage.append(OUStringToOString(aCtrlType, RTL_TEXTENCODING_UTF8));
1134 sMessage.append('"');
1135 OSL_FAIL( sMessage.getStr() );
1139 // #i106506# if no brochure button, then the singular Pages radio button
1140 // makes no sense, so replace it by a FixedText label
1141 if (!maNUpPage.mpBrochureBtn->IsVisible() && maNUpPage.mpPagesBtn->IsVisible())
1143 maNUpPage.mpPagesBoxTitleTxt->SetText( maNUpPage.mpPagesBtn->GetText() );
1144 maNUpPage.mpPagesBoxTitleTxt->Show( sal_True );
1145 maNUpPage.mpPagesBtn->Show( sal_False );
1148 // update enable states
1149 checkOptionalControlDependencies();
1151 Window *pPageRange = get<Window>("pagerange");
1153 // print range not shown (currently math only) -> hide spacer line and reverse order
1154 if (!pPageRange || !pPageRange->IsVisible())
1156 maJobPage.mpCopySpacer->Show( sal_False );
1157 maJobPage.mpReverseOrderBox->Show( sal_False );
1160 if (!mpCustomOptionsUIBuilder)
1161 mpTabCtrl->RemovePage(mpTabCtrl->GetPageId(1));
1164 void PrintDialog::DataChanged( const DataChangedEvent& i_rDCEvt )
1166 // react on settings changed
1167 if( i_rDCEvt.GetType() == DATACHANGED_SETTINGS )
1168 checkControlDependencies();
1169 ModalDialog::DataChanged( i_rDCEvt );
1172 void PrintDialog::checkControlDependencies()
1174 if( maJobPage.mpCopyCountField->GetValue() > 1 )
1175 maJobPage.mpCollateBox->Enable( maJobPage.mnCollateUIMode == 0 );
1176 else
1177 maJobPage.mpCollateBox->Enable( sal_False );
1179 Image aImg( maJobPage.mpCollateBox->IsChecked() ? maJobPage.maCollateImg : maJobPage.maNoCollateImg );
1181 Size aImgSize( aImg.GetSizePixel() );
1183 // adjust size of image
1184 maJobPage.mpCollateImage->SetSizePixel( aImgSize );
1185 maJobPage.mpCollateImage->SetImage( aImg );
1187 // enable setup button only for printers that can be setup
1188 bool bHaveSetup = maPController->getPrinter()->HasSupport( SUPPORT_SETUPDIALOG );
1189 maJobPage.mpSetupButton->Enable(bHaveSetup);
1192 void PrintDialog::checkOptionalControlDependencies()
1194 for( std::map< Window*, OUString >::iterator it = maControlToPropertyMap.begin();
1195 it != maControlToPropertyMap.end(); ++it )
1197 bool bShouldbeEnabled = maPController->isUIOptionEnabled( it->second );
1198 if( ! bShouldbeEnabled )
1200 // enable controls that are directly attached to a dependency anyway
1201 // if the normally disabled controls get modified, change the dependency
1202 // so the control would be enabled
1203 // example: in print range "Print All" is selected, "Page Range" is then of course
1204 // not selected and the Edit for the Page Range would be disabled
1205 // as a convenience we should enable the Edit anyway and automatically select
1206 // "Page Range" instead of "Print All" if the Edit gets modified
1207 if( maReverseDependencySet.find( it->second ) != maReverseDependencySet.end() )
1209 OUString aDep( maPController->getDependency( it->second ) );
1210 // if the dependency is at least enabled, then enable this control anyway
1211 if( !aDep.isEmpty() && maPController->isUIOptionEnabled( aDep ) )
1212 bShouldbeEnabled = true;
1216 if( bShouldbeEnabled && dynamic_cast<RadioButton*>(it->first) )
1218 std::map< Window*, sal_Int32 >::const_iterator r_it = maControlToNumValMap.find( it->first );
1219 if( r_it != maControlToNumValMap.end() )
1221 bShouldbeEnabled = maPController->isUIChoiceEnabled( it->second, r_it->second );
1226 bool bIsEnabled = it->first->IsEnabled();
1227 // Enable does not do a change check first, so can be less cheap than expected
1228 if( bShouldbeEnabled != bIsEnabled )
1229 it->first->Enable( bShouldbeEnabled );
1233 static OUString searchAndReplace( const OUString& i_rOrig, const char* i_pRepl, sal_Int32 i_nReplLen, const OUString& i_rRepl )
1235 sal_Int32 nPos = i_rOrig.indexOfAsciiL( i_pRepl, i_nReplLen );
1236 if( nPos != -1 )
1238 OUStringBuffer aBuf( i_rOrig.getLength() );
1239 aBuf.append( i_rOrig.getStr(), nPos );
1240 aBuf.append( i_rRepl );
1241 if( nPos + i_nReplLen < i_rOrig.getLength() )
1242 aBuf.append( i_rOrig.getStr() + nPos + i_nReplLen );
1243 return aBuf.makeStringAndClear();
1245 return i_rOrig;
1248 void PrintDialog::updatePrinterText()
1250 const OUString aDefPrt( Printer::GetDefaultPrinterName() );
1251 const QueueInfo* pInfo = Printer::GetQueueInfo( maJobPage.mpPrinters->GetSelectEntry(), true );
1252 if( pInfo )
1254 maJobPage.mpLocationTxt->SetText( pInfo->GetLocation() );
1255 maJobPage.mpCommentTxt->SetText( pInfo->GetComment() );
1256 // FIXME: status text
1257 OUString aStatus;
1258 if( aDefPrt == pInfo->GetPrinterName() )
1259 aStatus = maDefPrtText;
1260 maJobPage.mpStatusTxt->SetText( aStatus );
1262 else
1264 maJobPage.mpLocationTxt->SetText( OUString() );
1265 maJobPage.mpCommentTxt->SetText( OUString() );
1266 maJobPage.mpStatusTxt->SetText( OUString() );
1270 void PrintDialog::setPreviewText( sal_Int32 )
1272 OUString aNewText( searchAndReplace( maPageStr, "%n", 2, OUString::number( mnCachedPages ) ) );
1273 mpNumPagesText->SetText( aNewText );
1276 void PrintDialog::preparePreview( bool i_bNewPage, bool i_bMayUseCache )
1278 // page range may have changed depending on options
1279 sal_Int32 nPages = maPController->getFilteredPageCount();
1280 mnCachedPages = nPages;
1282 if( mnCurPage >= nPages )
1283 mnCurPage = nPages-1;
1284 if( mnCurPage < 0 )
1285 mnCurPage = 0;
1287 setPreviewText( mnCurPage );
1289 mpPageEdit->SetMin( 1 );
1290 mpPageEdit->SetMax( nPages );
1292 if( i_bNewPage )
1294 const MapMode aMapMode( MAP_100TH_MM );
1295 GDIMetaFile aMtf;
1296 boost::shared_ptr<Printer> aPrt( maPController->getPrinter() );
1297 if( nPages > 0 )
1299 PrinterController::PageSize aPageSize =
1300 maPController->getFilteredPageFile( mnCurPage, aMtf, i_bMayUseCache );
1301 if( ! aPageSize.bFullPaper )
1303 Point aOff( aPrt->PixelToLogic( aPrt->GetPageOffsetPixel(), aMapMode ) );
1304 aMtf.Move( aOff.X(), aOff.Y() );
1308 Size aCurPageSize = aPrt->PixelToLogic( aPrt->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) );
1309 mpPreviewWindow->setPreview( aMtf, aCurPageSize,
1310 aPrt->GetPaperName( false ),
1311 nPages > 0 ? OUString() : maNoPageStr,
1312 aPrt->ImplGetDPIX(), aPrt->ImplGetDPIY(),
1313 aPrt->GetPrinterOptions().IsConvertToGreyscales()
1316 mpForwardBtn->Enable( mnCurPage < nPages-1 );
1317 mpBackwardBtn->Enable( mnCurPage != 0 );
1318 mpPageEdit->Enable( nPages > 1 );
1322 Size PrintDialog::getJobPageSize()
1324 if( maFirstPageSize.Width() == 0 && maFirstPageSize.Height() == 0)
1326 maFirstPageSize = maNupPortraitSize;
1327 GDIMetaFile aMtf;
1328 if( maPController->getPageCountProtected() > 0 )
1330 PrinterController::PageSize aPageSize = maPController->getPageFile( 0, aMtf, true );
1331 maFirstPageSize = aPageSize.aSize;
1334 return maFirstPageSize;
1337 void PrintDialog::updateNupFromPages()
1339 sal_IntPtr nPages = sal_IntPtr(maNUpPage.mpNupPagesBox->GetEntryData(maNUpPage.mpNupPagesBox->GetSelectEntryPos()));
1340 int nRows = int(maNUpPage.mpNupRowsEdt->GetValue());
1341 int nCols = int(maNUpPage.mpNupColEdt->GetValue());
1342 long nPageMargin = long(maNUpPage.mpPageMarginEdt->Denormalize(maNUpPage.mpPageMarginEdt->GetValue( FUNIT_100TH_MM )));
1343 long nSheetMargin = long(maNUpPage.mpSheetMarginEdt->Denormalize(maNUpPage.mpSheetMarginEdt->GetValue( FUNIT_100TH_MM )));
1344 bool bCustom = false;
1346 if( nPages == 1 )
1348 nRows = nCols = 1;
1349 nSheetMargin = 0;
1350 nPageMargin = 0;
1352 else if( nPages == 2 || nPages == 4 || nPages == 6 || nPages == 9 || nPages == 16 )
1354 Size aJobPageSize( getJobPageSize() );
1355 bool bPortrait = aJobPageSize.Width() < aJobPageSize.Height();
1356 if( nPages == 2 )
1358 if( bPortrait )
1359 nRows = 1, nCols = 2;
1360 else
1361 nRows = 2, nCols = 1;
1363 else if( nPages == 4 )
1364 nRows = nCols = 2;
1365 else if( nPages == 6 )
1367 if( bPortrait )
1368 nRows = 2, nCols = 3;
1369 else
1370 nRows = 3, nCols = 2;
1372 else if( nPages == 9 )
1373 nRows = nCols = 3;
1374 else if( nPages == 16 )
1375 nRows = nCols = 4;
1376 nPageMargin = 0;
1377 nSheetMargin = 0;
1379 else
1380 bCustom = true;
1382 if( nPages > 1 )
1384 // set upper limits for margins based on job page size and rows/columns
1385 Size aSize( getJobPageSize() );
1387 // maximum sheet distance: 1/2 sheet
1388 long nHorzMax = aSize.Width()/2;
1389 long nVertMax = aSize.Height()/2;
1390 if( nSheetMargin > nHorzMax )
1391 nSheetMargin = nHorzMax;
1392 if( nSheetMargin > nVertMax )
1393 nSheetMargin = nVertMax;
1395 maNUpPage.mpSheetMarginEdt->SetMax(
1396 maNUpPage.mpSheetMarginEdt->Normalize(
1397 nHorzMax > nVertMax ? nVertMax : nHorzMax ), FUNIT_100TH_MM );
1399 // maximum page distance
1400 nHorzMax = (aSize.Width() - 2*nSheetMargin);
1401 if( nCols > 1 )
1402 nHorzMax /= (nCols-1);
1403 nVertMax = (aSize.Height() - 2*nSheetMargin);
1404 if( nRows > 1 )
1405 nHorzMax /= (nRows-1);
1407 if( nPageMargin > nHorzMax )
1408 nPageMargin = nHorzMax;
1409 if( nPageMargin > nVertMax )
1410 nPageMargin = nVertMax;
1412 maNUpPage.mpPageMarginEdt->SetMax(
1413 maNUpPage.mpSheetMarginEdt->Normalize(
1414 nHorzMax > nVertMax ? nVertMax : nHorzMax ), FUNIT_100TH_MM );
1417 maNUpPage.mpNupRowsEdt->SetValue( nRows );
1418 maNUpPage.mpNupColEdt->SetValue( nCols );
1419 maNUpPage.mpPageMarginEdt->SetValue( maNUpPage.mpPageMarginEdt->Normalize( nPageMargin ), FUNIT_100TH_MM );
1420 maNUpPage.mpSheetMarginEdt->SetValue( maNUpPage.mpSheetMarginEdt->Normalize( nSheetMargin ), FUNIT_100TH_MM );
1422 maNUpPage.showAdvancedControls( bCustom );
1424 updateNup();
1427 void PrintDialog::updateNup()
1429 int nRows = int(maNUpPage.mpNupRowsEdt->GetValue());
1430 int nCols = int(maNUpPage.mpNupColEdt->GetValue());
1431 long nPageMargin = long(maNUpPage.mpPageMarginEdt->Denormalize(maNUpPage.mpPageMarginEdt->GetValue( FUNIT_100TH_MM )));
1432 long nSheetMargin = long(maNUpPage.mpSheetMarginEdt->Denormalize(maNUpPage.mpSheetMarginEdt->GetValue( FUNIT_100TH_MM )));
1434 PrinterController::MultiPageSetup aMPS;
1435 aMPS.nRows = nRows;
1436 aMPS.nColumns = nCols;
1437 aMPS.nRepeat = 1;
1438 aMPS.nLeftMargin =
1439 aMPS.nTopMargin =
1440 aMPS.nRightMargin =
1441 aMPS.nBottomMargin = nSheetMargin;
1443 aMPS.nHorizontalSpacing =
1444 aMPS.nVerticalSpacing = nPageMargin;
1446 aMPS.bDrawBorder = maNUpPage.mpBorderCB->IsChecked();
1448 int nOrderMode = maNUpPage.mpNupOrderBox->GetSelectEntryPos();
1449 if( nOrderMode == SV_PRINT_PRT_NUP_ORDER_LRTB )
1450 aMPS.nOrder = PrinterController::LRTB;
1451 else if( nOrderMode == SV_PRINT_PRT_NUP_ORDER_TBLR )
1452 aMPS.nOrder = PrinterController::TBLR;
1453 else if( nOrderMode == SV_PRINT_PRT_NUP_ORDER_RLTB )
1454 aMPS.nOrder = PrinterController::RLTB;
1455 else if( nOrderMode == SV_PRINT_PRT_NUP_ORDER_TBRL )
1456 aMPS.nOrder = PrinterController::TBRL;
1458 int nOrientationMode = maNUpPage.mpNupOrientationBox->GetSelectEntryPos();
1459 if( nOrientationMode == SV_PRINT_PRT_NUP_ORIENTATION_LANDSCAPE )
1460 aMPS.aPaperSize = maNupLandscapeSize;
1461 else if( nOrientationMode == SV_PRINT_PRT_NUP_ORIENTATION_PORTRAIT )
1462 aMPS.aPaperSize = maNupPortraitSize;
1463 else // automatic mode
1465 // get size of first real page to see if it is portrait or landscape
1466 // we assume same page sizes for all the pages for this
1467 Size aPageSize = getJobPageSize();
1469 Size aMultiSize( aPageSize.Width() * nCols, aPageSize.Height() * nRows );
1470 if( aMultiSize.Width() > aMultiSize.Height() ) // fits better on landscape
1471 aMPS.aPaperSize = maNupLandscapeSize;
1472 else
1473 aMPS.aPaperSize = maNupPortraitSize;
1476 maPController->setMultipage( aMPS );
1478 maNUpPage.mpNupOrderWin->setValues( nOrderMode, nCols, nRows );
1480 preparePreview( true, true );
1483 IMPL_LINK( PrintDialog, SelectHdl, ListBox*, pBox )
1485 if( pBox == maJobPage.mpPrinters )
1487 OUString aNewPrinter( pBox->GetSelectEntry() );
1488 // set new printer
1489 maPController->setPrinter( boost::shared_ptr<Printer>( new Printer( aNewPrinter ) ) );
1490 maPController->resetPrinterOptions( maOptionsPage.mpToFileBox->IsChecked() );
1491 // update text fields
1492 updatePrinterText();
1493 preparePreview( true, false );
1495 else if( pBox == maNUpPage.mpNupOrientationBox || pBox == maNUpPage.mpNupOrderBox )
1497 updateNup();
1499 else if( pBox == maNUpPage.mpNupPagesBox )
1501 if( !maNUpPage.mpPagesBtn->IsChecked() )
1502 maNUpPage.mpPagesBtn->Check();
1503 updateNupFromPages();
1506 return 0;
1509 IMPL_LINK( PrintDialog, ClickHdl, Button*, pButton )
1511 if( pButton == mpOKButton || pButton == mpCancelButton )
1513 storeToSettings();
1514 EndDialog( pButton == mpOKButton );
1516 else if( pButton == mpHelpButton )
1518 // start help system
1519 Help* pHelp = Application::GetHelp();
1520 if( pHelp )
1522 pHelp->Start( OUString("vcl/ui/printdialog"), mpOKButton );
1525 else if( pButton == mpForwardBtn )
1527 previewForward();
1529 else if( pButton == mpBackwardBtn )
1531 previewBackward();
1533 else if( pButton == maOptionsPage.mpToFileBox )
1535 mpOKButton->SetText( maOptionsPage.mpToFileBox->IsChecked() ? maPrintToFileText : maPrintText );
1536 maPController->resetPrinterOptions( maOptionsPage.mpToFileBox->IsChecked() );
1537 preparePreview( true, true );
1539 else if( pButton == maOptionsPage.mpPapersizeFromSetup )
1541 sal_Bool bChecked = maOptionsPage.mpPapersizeFromSetup->IsChecked();
1542 maPController->setPapersizeFromSetup( bChecked );
1543 maPController->setValue( OUString( "PapersizeFromSetup" ),
1544 makeAny( bChecked ) );
1545 preparePreview( true, true );
1547 else if( pButton == maNUpPage.mpBrochureBtn )
1549 PropertyValue* pVal = getValueForWindow( pButton );
1550 if( pVal )
1552 sal_Bool bVal = maNUpPage.mpBrochureBtn->IsChecked();
1553 pVal->Value <<= bVal;
1555 checkOptionalControlDependencies();
1557 // update preview and page settings
1558 preparePreview();
1560 if( maNUpPage.mpBrochureBtn->IsChecked() )
1562 maNUpPage.mpNupPagesBox->SelectEntryPos( 0 );
1563 updateNupFromPages();
1564 maNUpPage.showAdvancedControls( false );
1565 maNUpPage.enableNupControls( false );
1568 else if( pButton == maNUpPage.mpPagesBtn )
1570 maNUpPage.enableNupControls( true );
1571 updateNupFromPages();
1573 else if( pButton == maJobPage.mpCollateBox )
1575 maPController->setValue( OUString( "Collate" ),
1576 makeAny( sal_Bool(isCollate()) ) );
1577 checkControlDependencies();
1579 else if( pButton == maJobPage.mpReverseOrderBox )
1581 sal_Bool bChecked = maJobPage.mpReverseOrderBox->IsChecked();
1582 maPController->setReversePrint( bChecked );
1583 maPController->setValue( OUString( "PrintReverse" ),
1584 makeAny( bChecked ) );
1585 preparePreview( true, true );
1587 else if( pButton == maNUpPage.mpBorderCB )
1589 updateNup();
1591 else
1593 if( pButton == maJobPage.mpSetupButton )
1595 maPController->setupPrinter( this );
1596 preparePreview( true, true );
1598 checkControlDependencies();
1600 return 0;
1603 IMPL_LINK( PrintDialog, ModifyHdl, Edit*, pEdit )
1605 checkControlDependencies();
1606 if( pEdit == maNUpPage.mpNupRowsEdt || pEdit == maNUpPage.mpNupColEdt ||
1607 pEdit == maNUpPage.mpSheetMarginEdt || pEdit == maNUpPage.mpPageMarginEdt
1610 updateNupFromPages();
1612 else if( pEdit == mpPageEdit )
1614 mnCurPage = sal_Int32( mpPageEdit->GetValue() - 1 );
1615 preparePreview( true, true );
1617 else if( pEdit == maJobPage.mpCopyCountField )
1619 maPController->setValue( OUString( "CopyCount" ),
1620 makeAny( sal_Int32(maJobPage.mpCopyCountField->GetValue()) ) );
1621 maPController->setValue( OUString( "Collate" ),
1622 makeAny( sal_Bool(isCollate()) ) );
1624 return 0;
1627 IMPL_LINK_NOARG(PrintDialog, UIOptionsChanged)
1629 checkOptionalControlDependencies();
1630 return 0;
1633 PropertyValue* PrintDialog::getValueForWindow( Window* i_pWindow ) const
1635 PropertyValue* pVal = NULL;
1636 std::map< Window*, OUString >::const_iterator it = maControlToPropertyMap.find( i_pWindow );
1637 if( it != maControlToPropertyMap.end() )
1639 pVal = maPController->getValue( it->second );
1640 DBG_ASSERT( pVal, "property value not found" );
1642 else
1644 OSL_FAIL( "changed control not in property map" );
1646 return pVal;
1649 void PrintDialog::updateWindowFromProperty( const OUString& i_rProperty )
1651 beans::PropertyValue* pValue = maPController->getValue( i_rProperty );
1652 std::map< OUString, std::vector< Window* > >::const_iterator it = maPropertyToWindowMap.find( i_rProperty );
1653 if( pValue && it != maPropertyToWindowMap.end() )
1655 const std::vector< Window* >& rWindows( it->second );
1656 if( ! rWindows.empty() )
1658 sal_Bool bVal = sal_False;
1659 sal_Int32 nVal = -1;
1660 if( pValue->Value >>= bVal )
1662 // we should have a CheckBox for this one
1663 CheckBox* pBox = dynamic_cast< CheckBox* >( rWindows.front() );
1664 if( pBox )
1666 pBox->Check( bVal );
1668 else if ( i_rProperty == "PrintProspect" )
1670 // EVIL special case
1671 if( bVal )
1672 maNUpPage.mpBrochureBtn->Check();
1673 else
1674 maNUpPage.mpPagesBtn->Check();
1676 else
1678 DBG_ASSERT( 0, "missing a checkbox" );
1681 else if( pValue->Value >>= nVal )
1683 // this could be a ListBox or a RadioButtonGroup
1684 ListBox* pList = dynamic_cast< ListBox* >( rWindows.front() );
1685 if( pList )
1687 pList->SelectEntryPos( static_cast< sal_uInt16 >(nVal) );
1689 else if( nVal >= 0 && nVal < sal_Int32(rWindows.size() ) )
1691 RadioButton* pBtn = dynamic_cast< RadioButton* >( rWindows[nVal] );
1692 DBG_ASSERT( pBtn, "unexpected control for property" );
1693 if( pBtn )
1694 pBtn->Check();
1701 void PrintDialog::makeEnabled( Window* i_pWindow )
1703 std::map< Window*, OUString >::const_iterator it = maControlToPropertyMap.find( i_pWindow );
1704 if( it != maControlToPropertyMap.end() )
1706 OUString aDependency( maPController->makeEnabled( it->second ) );
1707 if( !aDependency.isEmpty() )
1708 updateWindowFromProperty( aDependency );
1712 IMPL_LINK( PrintDialog, UIOption_CheckHdl, CheckBox*, i_pBox )
1714 PropertyValue* pVal = getValueForWindow( i_pBox );
1715 if( pVal )
1717 makeEnabled( i_pBox );
1719 sal_Bool bVal = i_pBox->IsChecked();
1720 pVal->Value <<= bVal;
1722 checkOptionalControlDependencies();
1724 // update preview and page settings
1725 preparePreview();
1727 return 0;
1730 IMPL_LINK( PrintDialog, UIOption_RadioHdl, RadioButton*, i_pBtn )
1732 // this handler gets called for all radiobuttons that get unchecked, too
1733 // however we only want one notificaction for the new value (that is for
1734 // the button that gets checked)
1735 if( i_pBtn->IsChecked() )
1737 PropertyValue* pVal = getValueForWindow( i_pBtn );
1738 std::map< Window*, sal_Int32 >::const_iterator it = maControlToNumValMap.find( i_pBtn );
1739 if( pVal && it != maControlToNumValMap.end() )
1741 makeEnabled( i_pBtn );
1743 sal_Int32 nVal = it->second;
1744 pVal->Value <<= nVal;
1746 checkOptionalControlDependencies();
1748 // update preview and page settings
1749 preparePreview();
1752 return 0;
1755 IMPL_LINK( PrintDialog, UIOption_SelectHdl, ListBox*, i_pBox )
1757 PropertyValue* pVal = getValueForWindow( i_pBox );
1758 if( pVal )
1760 makeEnabled( i_pBox );
1762 sal_Int32 nVal( i_pBox->GetSelectEntryPos() );
1763 pVal->Value <<= nVal;
1765 checkOptionalControlDependencies();
1767 // update preview and page settings
1768 preparePreview();
1770 return 0;
1773 IMPL_LINK( PrintDialog, UIOption_ModifyHdl, Edit*, i_pBox )
1775 PropertyValue* pVal = getValueForWindow( i_pBox );
1776 if( pVal )
1778 makeEnabled( i_pBox );
1780 NumericField* pNum = dynamic_cast<NumericField*>(i_pBox);
1781 MetricField* pMetric = dynamic_cast<MetricField*>(i_pBox);
1782 if( pNum )
1784 sal_Int64 nVal = pNum->GetValue();
1785 pVal->Value <<= nVal;
1787 else if( pMetric )
1789 sal_Int64 nVal = pMetric->GetValue();
1790 pVal->Value <<= nVal;
1792 else
1794 OUString aVal( i_pBox->GetText() );
1795 pVal->Value <<= aVal;
1798 checkOptionalControlDependencies();
1800 // update preview and page settings
1801 preparePreview();
1803 return 0;
1806 void PrintDialog::Command( const CommandEvent& rEvt )
1808 if( rEvt.GetCommand() == COMMAND_WHEEL )
1810 const CommandWheelData* pWheelData = rEvt.GetWheelData();
1811 if( pWheelData->GetDelta() > 0 )
1812 previewForward();
1813 else if( pWheelData->GetDelta() < 0 )
1814 previewBackward();
1818 void PrintDialog::Resize()
1820 // maLayout.setManagedArea( Rectangle( Point( 0, 0 ), GetSizePixel() ) );
1821 // and do the preview; however the metafile does not need to be gotten anew
1822 preparePreview( false );
1824 Dialog::Resize();
1827 void PrintDialog::previewForward()
1829 mpPageEdit->Up();
1832 void PrintDialog::previewBackward()
1834 mpPageEdit->Down();
1837 // -----------------------------------------------------------------------------
1839 // PrintProgressDialog
1841 // -----------------------------------------------------------------------------
1843 PrintProgressDialog::PrintProgressDialog( Window* i_pParent, int i_nMax ) :
1844 ModelessDialog( i_pParent, VclResId( SV_DLG_PRINT_PROGRESS ) ),
1845 maText( this, VclResId( SV_PRINT_PROGRESS_TEXT ) ),
1846 maButton( this, VclResId( SV_PRINT_PROGRESS_CANCEL ) ),
1847 mbCanceled( false ),
1848 mnCur( 0 ),
1849 mnMax( i_nMax ),
1850 mnProgressHeight( 15 ),
1851 mbNativeProgress( false )
1853 FreeResource();
1855 if( mnMax < 1 )
1856 mnMax = 1;
1858 maStr = maText.GetText();
1860 maButton.SetClickHdl( LINK( this, PrintProgressDialog, ClickHdl ) );
1864 PrintProgressDialog::~PrintProgressDialog()
1868 IMPL_LINK( PrintProgressDialog, ClickHdl, Button*, pButton )
1870 if( pButton == &maButton )
1871 mbCanceled = true;
1873 return 0;
1876 void PrintProgressDialog::implCalcProgressRect()
1878 if( IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) )
1880 ImplControlValue aValue;
1881 Rectangle aControlRegion( Point(), Size( 100, mnProgressHeight ) );
1882 Rectangle aNativeControlRegion, aNativeContentRegion;
1883 if( GetNativeControlRegion( CTRL_PROGRESS, PART_ENTIRE_CONTROL, aControlRegion,
1884 CTRL_STATE_ENABLED, aValue, OUString(),
1885 aNativeControlRegion, aNativeContentRegion ) )
1887 mnProgressHeight = aNativeControlRegion.GetHeight();
1889 mbNativeProgress = true;
1891 maProgressRect = Rectangle( Point( 10, maText.GetPosPixel().Y() + maText.GetSizePixel().Height() + 8 ),
1892 Size( GetSizePixel().Width() - 20, mnProgressHeight ) );
1895 void PrintProgressDialog::setProgress( int i_nCurrent, int i_nMax )
1897 if( maProgressRect.IsEmpty() )
1898 implCalcProgressRect();
1900 mnCur = i_nCurrent;
1901 if( i_nMax != -1 )
1902 mnMax = i_nMax;
1904 if( mnMax < 1 )
1905 mnMax = 1;
1907 OUString aNewText( searchAndReplace( maStr, "%p", 2, OUString::number( mnCur ) ) );
1908 aNewText = searchAndReplace( aNewText, "%n", 2, OUString::number( mnMax ) );
1909 maText.SetText( aNewText );
1911 // update progress
1912 Invalidate( maProgressRect, INVALIDATE_UPDATE );
1915 void PrintProgressDialog::tick()
1917 if( mnCur < mnMax )
1918 setProgress( ++mnCur );
1921 void PrintProgressDialog::reset()
1923 mbCanceled = false;
1924 setProgress( 0 );
1927 void PrintProgressDialog::Paint( const Rectangle& )
1929 if( maProgressRect.IsEmpty() )
1930 implCalcProgressRect();
1932 Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
1933 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1934 Color aPrgsColor = rStyleSettings.GetHighlightColor();
1935 if ( aPrgsColor == rStyleSettings.GetFaceColor() )
1936 aPrgsColor = rStyleSettings.GetDarkShadowColor();
1937 SetLineColor();
1938 SetFillColor( aPrgsColor );
1940 const long nOffset = 3;
1941 const long nWidth = 3*mnProgressHeight/2;
1942 const long nFullWidth = nWidth + nOffset;
1943 const long nMaxCount = maProgressRect.GetWidth() / nFullWidth;
1944 DrawProgress( this, maProgressRect.TopLeft(),
1945 nOffset,
1946 nWidth,
1947 mnProgressHeight,
1948 static_cast<sal_uInt16>(0),
1949 static_cast<sal_uInt16>(10000*mnCur/mnMax),
1950 static_cast<sal_uInt16>(10000/nMaxCount),
1951 maProgressRect
1953 Pop();
1955 if( ! mbNativeProgress )
1957 DecorationView aDecoView( this );
1958 Rectangle aFrameRect( maProgressRect );
1959 aFrameRect.Left() -= nOffset;
1960 aFrameRect.Right() += nOffset;
1961 aFrameRect.Top() -= nOffset;
1962 aFrameRect.Bottom() += nOffset;
1963 aDecoView.DrawFrame( aFrameRect );
1967 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */