1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
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"
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 )
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
);
74 maPageVDev
.SetBackground( Color( COL_WHITE
) );
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;
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());
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
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
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());
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
,
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
;
227 if( rLocWrap
.getMeasurementSystemEnum() == MEASURE_US
)
229 eUnit
= MAP_100TH_INCH
;
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
);
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() );
250 preparePreviewBitmap();
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());
270 maPageVDev
.SetMapMode( MAP_100TH_MM
);
271 sal_uLong nOldDrawMode
= maPageVDev
.GetDrawMode();
273 maPageVDev
.SetDrawMode( maPageVDev
.GetDrawMode() |
274 ( DRAWMODE_GRAYLINE
| DRAWMODE_GRAYFILL
| DRAWMODE_GRAYTEXT
|
275 DRAWMODE_GRAYBITMAP
| DRAWMODE_GRAYGRADIENT
) );
277 aMtf
.Scale( fScale
, fScale
);
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
);
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
)
304 PrintDialog::ShowNupOrderWindow::~ShowNupOrderWindow()
308 void PrintDialog::ShowNupOrderWindow::ImplInitSettings()
310 SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetFieldColor() ) );
313 Size
PrintDialog::ShowNupOrderWindow::GetOptimalSize() const
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 ) );
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 )
339 aFont
.SetSize( Size( 0, nFontHeight
) );
341 long nTextHeight
= GetTextHeight();
342 for( int i
= 0; i
< nPages
; i
++ )
344 OUString
aPageText( OUString::number( i
+1 ) );
346 switch( mnOrderMode
)
348 case SV_PRINT_PRT_NUP_ORDER_LRTB
:
349 nX
= (i
% mnColumns
); nY
= (i
/ mnColumns
);
351 case SV_PRINT_PRT_NUP_ORDER_TBLR
:
352 nX
= (i
/ mnRows
); nY
= (i
% mnRows
);
354 case SV_PRINT_PRT_NUP_ORDER_RLTB
:
355 nX
= mnColumns
- 1 - (i
% mnColumns
); nY
= (i
/ mnColumns
);
357 case SV_PRINT_PRT_NUP_ORDER_TBRL
:
358 nX
= mnColumns
- 1 - (i
/ mnRows
); nY
= (i
% mnRows
);
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
),
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
)
449 mpPageMarginEdt
->SetUnit( eUnit
);
450 mpSheetMarginEdt
->SetUnit( eUnit
);
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();
504 aValue
= pItem
->getValue( OUString( "PrintDialog" ),
505 OUString( "CollateBox" ) );
506 if( aValue
.equalsIgnoreAsciiCase("alwaysoff") )
509 mpCollateBox
->Check( sal_False
);
510 mpCollateBox
->Enable( sal_False
);
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") :
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();
544 aValue
= pItem
->getValue( OUString( "PrintDialog" ),
545 OUString( "CollateSingleJobs" ) );
546 if ( aValue
.equalsIgnoreAsciiCase("true") )
548 mpCollateSingleJobsBox
->Check( sal_True
);
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") :
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() )
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() );
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
) ) );
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
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() );
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
) );
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
) );
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
) );
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
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
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
);
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
)
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();
827 Sequence
< beans::PropertyValue
> aOptProp
;
828 rOptions
[i
].Value
>>= aOptProp
;
830 // extract ui element
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" )
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
) )
910 if( (rEntry
.Value
>>= aHelpText
) )
912 aHelpTexts
.realloc( 1 );
913 *aHelpTexts
.getArray() = aHelpText
;
917 else if ( rEntry
.Name
== "HelpId" )
919 if( ! (rEntry
.Value
>>= aHelpIds
) )
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
);
947 if (aHelpIds
.getLength() > 0)
948 mpTabCtrl
->SetHelpId(nPageId
, OUStringToOString(aHelpIds
.getConstArray()[0], RTL_TEXTENCODING_UTF8
));
951 if (aHelpTexts
.getLength() > 0)
952 mpTabCtrl
->SetHelpText(nPageId
, aHelpTexts
.getConstArray()[0]);
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
);
965 setHelpId(pFrame
, aHelpIds
, 0);
967 setHelpText(pFrame
, aHelpTexts
, 0);
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
);
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
;
989 setHelpId( maNUpPage
.mpBrochureBtn
, aHelpIds
, 0 );
991 setHelpText( maNUpPage
.mpBrochureBtn
, aHelpTexts
, 0 );
993 else if (aCtrlType
== "Bool")
996 CheckBox
* pNewBox
= get
<CheckBox
>(aID
);
997 if (!pNewBox
&& mpCustomOptionsUIBuilder
)
998 pNewBox
= mpCustomOptionsUIBuilder
->get
<CheckBox
>(aID
);
1000 pNewBox
->SetText( aText
);
1003 sal_Bool bVal
= sal_False
;
1004 PropertyValue
* pVal
= maPController
->getValue( aPropertyName
);
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
;
1014 setHelpId( pNewBox
, aHelpIds
, 0 );
1016 setHelpText( pNewBox
, aHelpTexts
, 0 );
1018 else if (aCtrlType
== "Radio")
1020 sal_Int32 nCurHelpText
= 0;
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
);
1040 maPropertyToWindowMap
[ aPropertyName
].push_back( pBtn
);
1041 maControlToPropertyMap
[pBtn
] = aPropertyName
;
1042 maControlToNumValMap
[pBtn
] = m
;
1045 setHelpId( pBtn
, aHelpIds
, nCurHelpText
);
1047 setHelpText( pBtn
, aHelpTexts
, nCurHelpText
);
1051 else if ( aCtrlType
== "List" )
1053 ListBox
* pList
= get
<ListBox
>(aID
);
1054 if (!pList
&& mpCustomOptionsUIBuilder
)
1055 pList
= mpCustomOptionsUIBuilder
->get
<ListBox
>(aID
);
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()) );
1072 setHelpId( pList
, aHelpIds
, 0 );
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
) );
1100 setHelpId( pField
, aHelpIds
, 0 );
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
);
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
) );
1122 setHelpId( pField
, aHelpIds
, 0 );
1124 setHelpText( pField
, aHelpTexts
, 0 );
1126 maPropertyToWindowMap
[ aPropertyName
].push_back( pField
);
1127 maControlToPropertyMap
[pField
] = aPropertyName
;
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 );
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
);
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();
1248 void PrintDialog::updatePrinterText()
1250 const OUString
aDefPrt( Printer::GetDefaultPrinterName() );
1251 const QueueInfo
* pInfo
= Printer::GetQueueInfo( maJobPage
.mpPrinters
->GetSelectEntry(), true );
1254 maJobPage
.mpLocationTxt
->SetText( pInfo
->GetLocation() );
1255 maJobPage
.mpCommentTxt
->SetText( pInfo
->GetComment() );
1256 // FIXME: status text
1258 if( aDefPrt
== pInfo
->GetPrinterName() )
1259 aStatus
= maDefPrtText
;
1260 maJobPage
.mpStatusTxt
->SetText( aStatus
);
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;
1287 setPreviewText( mnCurPage
);
1289 mpPageEdit
->SetMin( 1 );
1290 mpPageEdit
->SetMax( nPages
);
1294 const MapMode
aMapMode( MAP_100TH_MM
);
1296 boost::shared_ptr
<Printer
> aPrt( maPController
->getPrinter() );
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
;
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;
1352 else if( nPages
== 2 || nPages
== 4 || nPages
== 6 || nPages
== 9 || nPages
== 16 )
1354 Size
aJobPageSize( getJobPageSize() );
1355 bool bPortrait
= aJobPageSize
.Width() < aJobPageSize
.Height();
1359 nRows
= 1, nCols
= 2;
1361 nRows
= 2, nCols
= 1;
1363 else if( nPages
== 4 )
1365 else if( nPages
== 6 )
1368 nRows
= 2, nCols
= 3;
1370 nRows
= 3, nCols
= 2;
1372 else if( nPages
== 9 )
1374 else if( nPages
== 16 )
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
);
1402 nHorzMax
/= (nCols
-1);
1403 nVertMax
= (aSize
.Height() - 2*nSheetMargin
);
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
);
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
;
1436 aMPS
.nColumns
= nCols
;
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
;
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() );
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
)
1499 else if( pBox
== maNUpPage
.mpNupPagesBox
)
1501 if( !maNUpPage
.mpPagesBtn
->IsChecked() )
1502 maNUpPage
.mpPagesBtn
->Check();
1503 updateNupFromPages();
1509 IMPL_LINK( PrintDialog
, ClickHdl
, Button
*, pButton
)
1511 if( pButton
== mpOKButton
|| pButton
== mpCancelButton
)
1514 EndDialog( pButton
== mpOKButton
);
1516 else if( pButton
== mpHelpButton
)
1518 // start help system
1519 Help
* pHelp
= Application::GetHelp();
1522 pHelp
->Start( OUString("vcl/ui/printdialog"), mpOKButton
);
1525 else if( pButton
== mpForwardBtn
)
1529 else if( pButton
== mpBackwardBtn
)
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
);
1552 sal_Bool bVal
= maNUpPage
.mpBrochureBtn
->IsChecked();
1553 pVal
->Value
<<= bVal
;
1555 checkOptionalControlDependencies();
1557 // update preview and page settings
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
)
1593 if( pButton
== maJobPage
.mpSetupButton
)
1595 maPController
->setupPrinter( this );
1596 preparePreview( true, true );
1598 checkControlDependencies();
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()) ) );
1627 IMPL_LINK_NOARG(PrintDialog
, UIOptionsChanged
)
1629 checkOptionalControlDependencies();
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" );
1644 OSL_FAIL( "changed control not in property map" );
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() );
1666 pBox
->Check( bVal
);
1668 else if ( i_rProperty
== "PrintProspect" )
1670 // EVIL special case
1672 maNUpPage
.mpBrochureBtn
->Check();
1674 maNUpPage
.mpPagesBtn
->Check();
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() );
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" );
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
);
1717 makeEnabled( i_pBox
);
1719 sal_Bool bVal
= i_pBox
->IsChecked();
1720 pVal
->Value
<<= bVal
;
1722 checkOptionalControlDependencies();
1724 // update preview and page settings
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
1755 IMPL_LINK( PrintDialog
, UIOption_SelectHdl
, ListBox
*, i_pBox
)
1757 PropertyValue
* pVal
= getValueForWindow( i_pBox
);
1760 makeEnabled( i_pBox
);
1762 sal_Int32
nVal( i_pBox
->GetSelectEntryPos() );
1763 pVal
->Value
<<= nVal
;
1765 checkOptionalControlDependencies();
1767 // update preview and page settings
1773 IMPL_LINK( PrintDialog
, UIOption_ModifyHdl
, Edit
*, i_pBox
)
1775 PropertyValue
* pVal
= getValueForWindow( i_pBox
);
1778 makeEnabled( i_pBox
);
1780 NumericField
* pNum
= dynamic_cast<NumericField
*>(i_pBox
);
1781 MetricField
* pMetric
= dynamic_cast<MetricField
*>(i_pBox
);
1784 sal_Int64 nVal
= pNum
->GetValue();
1785 pVal
->Value
<<= nVal
;
1789 sal_Int64 nVal
= pMetric
->GetValue();
1790 pVal
->Value
<<= nVal
;
1794 OUString
aVal( i_pBox
->GetText() );
1795 pVal
->Value
<<= aVal
;
1798 checkOptionalControlDependencies();
1800 // update preview and page settings
1806 void PrintDialog::Command( const CommandEvent
& rEvt
)
1808 if( rEvt
.GetCommand() == COMMAND_WHEEL
)
1810 const CommandWheelData
* pWheelData
= rEvt
.GetWheelData();
1811 if( pWheelData
->GetDelta() > 0 )
1813 else if( pWheelData
->GetDelta() < 0 )
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 );
1827 void PrintDialog::previewForward()
1832 void PrintDialog::previewBackward()
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 ),
1850 mnProgressHeight( 15 ),
1851 mbNativeProgress( false )
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
)
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();
1907 OUString
aNewText( searchAndReplace( maStr
, "%p", 2, OUString::number( mnCur
) ) );
1908 aNewText
= searchAndReplace( aNewText
, "%n", 2, OUString::number( mnMax
) );
1909 maText
.SetText( aNewText
);
1912 Invalidate( maProgressRect
, INVALIDATE_UPDATE
);
1915 void PrintProgressDialog::tick()
1918 setProgress( ++mnCur
);
1921 void PrintProgressDialog::reset()
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();
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(),
1948 static_cast<sal_uInt16
>(0),
1949 static_cast<sal_uInt16
>(10000*mnCur
/mnMax
),
1950 static_cast<sal_uInt16
>(10000/nMaxCount
),
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: */