Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "printdlg.hxx"
21 : #include "svdata.hxx"
22 : #include "svids.hrc"
23 : #include "jobset.h"
24 :
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/decoview.hxx"
34 : #include "vcl/layout.hxx"
35 : #include "vcl/svapp.hxx"
36 : #include "vcl/unohelp.hxx"
37 :
38 : #include "unotools/localedatawrapper.hxx"
39 :
40 : #include "rtl/strbuf.hxx"
41 :
42 : #include "com/sun/star/lang/XMultiServiceFactory.hpp"
43 : #include "com/sun/star/container/XNameAccess.hpp"
44 : #include "com/sun/star/beans/PropertyValue.hpp"
45 : #include "com/sun/star/awt/Size.hpp"
46 :
47 : using namespace vcl;
48 : using namespace com::sun::star;
49 : using namespace com::sun::star::uno;
50 : using namespace com::sun::star::lang;
51 : using namespace com::sun::star::container;
52 : using namespace com::sun::star::beans;
53 :
54 0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makePrintPreviewWindow(Window *pParent, VclBuilder::stringmap &)
55 : {
56 0 : return new PrintDialog::PrintPreviewWindow(pParent);
57 : }
58 :
59 0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeShowNupOrderWindow(Window *pParent, VclBuilder::stringmap &)
60 : {
61 0 : return new PrintDialog::ShowNupOrderWindow(pParent);
62 : }
63 :
64 0 : PrintDialog::PrintPreviewWindow::PrintPreviewWindow( Window* i_pParent )
65 : : Window( i_pParent, 0 )
66 : , maOrigSize( 10, 10 )
67 : , maPageVDev( *this )
68 : , maToolTipString(VclResId( SV_PRINT_PRINTPREVIEW_TXT).toString())
69 : , mbGreyscale( false )
70 : , maHorzDim( this, WB_HORZ | WB_CENTER )
71 0 : , maVertDim( this, WB_VERT | WB_VCENTER )
72 : {
73 0 : SetPaintTransparent( sal_True );
74 0 : SetBackground();
75 0 : maPageVDev.SetBackground( Color( COL_WHITE ) );
76 0 : maHorzDim.Show();
77 0 : maVertDim.Show();
78 :
79 0 : maHorzDim.SetText( String( RTL_CONSTASCII_USTRINGPARAM( "2.0in" ) ) );
80 0 : maVertDim.SetText( String( RTL_CONSTASCII_USTRINGPARAM( "2.0in" ) ) );
81 0 : }
82 :
83 0 : PrintDialog::PrintPreviewWindow::~PrintPreviewWindow()
84 : {
85 0 : }
86 :
87 0 : void PrintDialog::PrintPreviewWindow::DataChanged( const DataChangedEvent& i_rDCEvt )
88 : {
89 : // react on settings changed
90 0 : if( i_rDCEvt.GetType() == DATACHANGED_SETTINGS )
91 : {
92 0 : maPageVDev.SetBackground( Color( COL_WHITE ) );
93 : }
94 0 : Window::DataChanged( i_rDCEvt );
95 0 : }
96 :
97 0 : void PrintDialog::PrintPreviewWindow::Resize()
98 : {
99 0 : Size aNewSize( GetSizePixel() );
100 0 : long nTextHeight = maHorzDim.GetTextHeight();
101 : // leave small space for decoration
102 0 : aNewSize.Width() -= nTextHeight + 2;
103 0 : aNewSize.Height() -= nTextHeight + 2;
104 0 : Size aScaledSize;
105 0 : double fScale = 1.0;
106 :
107 : // #i106435# catch corner case of Size(0,0)
108 0 : Size aOrigSize( maOrigSize );
109 0 : if( aOrigSize.Width() < 1 )
110 0 : aOrigSize.Width() = aNewSize.Width();
111 0 : if( aOrigSize.Height() < 1 )
112 0 : aOrigSize.Height() = aNewSize.Height();
113 0 : if( aOrigSize.Width() > aOrigSize.Height() )
114 : {
115 0 : aScaledSize = Size( aNewSize.Width(), aNewSize.Width() * aOrigSize.Height() / aOrigSize.Width() );
116 0 : if( aScaledSize.Height() > aNewSize.Height() )
117 0 : fScale = double(aNewSize.Height())/double(aScaledSize.Height());
118 : }
119 : else
120 : {
121 0 : aScaledSize = Size( aNewSize.Height() * aOrigSize.Width() / aOrigSize.Height(), aNewSize.Height() );
122 0 : if( aScaledSize.Width() > aNewSize.Width() )
123 0 : fScale = double(aNewSize.Width())/double(aScaledSize.Width());
124 : }
125 0 : aScaledSize.Width() = long(aScaledSize.Width()*fScale);
126 0 : aScaledSize.Height() = long(aScaledSize.Height()*fScale);
127 :
128 0 : maPreviewSize = aScaledSize;
129 :
130 : // #i104784# if we render the page too small then rounding issues result in
131 : // layout artifacts looking really bad. So scale the page unto a device that is not
132 : // full page size but not too small either. This also results in much better visual
133 : // quality of the preview, e.g. when its height approaches the number of text lines
134 : // find a good scaling factor
135 0 : Size aPreviewMMSize( maPageVDev.PixelToLogic( aScaledSize, MapMode( MAP_100TH_MM ) ) );
136 0 : double fZoom = double(maOrigSize.Height())/double(aPreviewMMSize.Height());
137 0 : while( fZoom > 10 )
138 : {
139 0 : aScaledSize.Width() *= 2;
140 0 : aScaledSize.Height() *= 2;
141 0 : fZoom /= 2.0;
142 : }
143 :
144 0 : maPageVDev.SetOutputSizePixel( aScaledSize, sal_False );
145 :
146 : // position dimension lines
147 0 : Point aRef( nTextHeight + (aNewSize.Width() - maPreviewSize.Width())/2,
148 0 : nTextHeight + (aNewSize.Height() - maPreviewSize.Height())/2 );
149 0 : maHorzDim.SetPosSizePixel( Point( aRef.X(), aRef.Y() - nTextHeight ),
150 0 : Size( maPreviewSize.Width(), nTextHeight ) );
151 0 : maVertDim.SetPosSizePixel( Point( aRef.X() - nTextHeight, aRef.Y() ),
152 0 : Size( nTextHeight, maPreviewSize.Height() ) );
153 :
154 0 : }
155 :
156 0 : void PrintDialog::PrintPreviewWindow::Paint( const Rectangle& )
157 : {
158 0 : long nTextHeight = maHorzDim.GetTextHeight();
159 0 : Size aSize( GetSizePixel() );
160 0 : Point aOffset( (aSize.Width() - maPreviewSize.Width() + nTextHeight) / 2 ,
161 0 : (aSize.Height() - maPreviewSize.Height() + nTextHeight) / 2 );
162 :
163 0 : if( !maReplacementString.isEmpty() )
164 : {
165 : // replacement is active
166 0 : Push();
167 0 : Font aFont( GetSettings().GetStyleSettings().GetLabelFont() );
168 0 : SetZoomedPointFont( aFont );
169 0 : Rectangle aTextRect( aOffset + Point( 2, 2 ),
170 0 : Size( maPreviewSize.Width() - 4, maPreviewSize.Height() - 4 ) );
171 : DrawText( aTextRect, maReplacementString,
172 : TEXT_DRAW_CENTER | TEXT_DRAW_VCENTER | TEXT_DRAW_WORDBREAK | TEXT_DRAW_MULTILINE
173 0 : );
174 0 : Pop();
175 : }
176 : else
177 : {
178 0 : GDIMetaFile aMtf( maMtf );
179 :
180 0 : Size aVDevSize( maPageVDev.GetOutputSizePixel() );
181 0 : const Size aLogicSize( maPageVDev.PixelToLogic( aVDevSize, MapMode( MAP_100TH_MM ) ) );
182 0 : Size aOrigSize( maOrigSize );
183 0 : if( aOrigSize.Width() < 1 )
184 0 : aOrigSize.Width() = aLogicSize.Width();
185 0 : if( aOrigSize.Height() < 1 )
186 0 : aOrigSize.Height() = aLogicSize.Height();
187 0 : double fScale = double(aLogicSize.Width())/double(aOrigSize.Width());
188 :
189 :
190 0 : maPageVDev.Erase();
191 0 : maPageVDev.Push();
192 0 : maPageVDev.SetMapMode( MAP_100TH_MM );
193 0 : sal_uLong nOldDrawMode = maPageVDev.GetDrawMode();
194 0 : if( mbGreyscale )
195 0 : maPageVDev.SetDrawMode( maPageVDev.GetDrawMode() |
196 : ( DRAWMODE_GRAYLINE | DRAWMODE_GRAYFILL | DRAWMODE_GRAYTEXT |
197 0 : DRAWMODE_GRAYBITMAP | DRAWMODE_GRAYGRADIENT ) );
198 0 : aMtf.WindStart();
199 0 : aMtf.Scale( fScale, fScale );
200 0 : aMtf.WindStart();
201 0 : aMtf.Play( &maPageVDev, Point( 0, 0 ), aLogicSize );
202 0 : maPageVDev.Pop();
203 :
204 0 : SetMapMode( MAP_PIXEL );
205 0 : maPageVDev.SetMapMode( MAP_PIXEL );
206 0 : DrawOutDev( aOffset, maPreviewSize, Point( 0, 0 ), aVDevSize, maPageVDev );
207 0 : maPageVDev.SetDrawMode( nOldDrawMode );
208 : }
209 :
210 0 : Rectangle aFrameRect( aOffset + Point( -1, -1 ),
211 0 : Size( maPreviewSize.Width() + 2, maPreviewSize.Height() + 2 ) );
212 0 : DecorationView aVw( this );
213 0 : aVw.DrawFrame( aFrameRect, FRAME_DRAW_GROUP );
214 0 : }
215 :
216 0 : void PrintDialog::PrintPreviewWindow::Command( const CommandEvent& rEvt )
217 : {
218 0 : if( rEvt.GetCommand() == COMMAND_WHEEL )
219 : {
220 0 : const CommandWheelData* pWheelData = rEvt.GetWheelData();
221 0 : PrintDialog* pDlg = dynamic_cast<PrintDialog*>(GetParent());
222 0 : if( pDlg )
223 : {
224 0 : if( pWheelData->GetDelta() > 0 )
225 0 : pDlg->previewForward();
226 0 : else if( pWheelData->GetDelta() < 0 )
227 0 : pDlg->previewBackward();
228 : /*
229 : else
230 : huh ?
231 : */
232 : }
233 : }
234 0 : }
235 :
236 0 : void PrintDialog::PrintPreviewWindow::setPreview( const GDIMetaFile& i_rNewPreview,
237 : const Size& i_rOrigSize,
238 : const rtl::OUString& i_rPaperName,
239 : const rtl::OUString& i_rReplacement,
240 : sal_Int32 i_nDPIX,
241 : sal_Int32 i_nDPIY,
242 : bool i_bGreyscale
243 : )
244 : {
245 0 : rtl::OUStringBuffer aBuf( 256 );
246 0 : aBuf.append( maToolTipString );
247 0 : SetQuickHelpText( aBuf.makeStringAndClear() );
248 0 : maMtf = i_rNewPreview;
249 :
250 0 : maOrigSize = i_rOrigSize;
251 0 : maReplacementString = i_rReplacement;
252 0 : mbGreyscale = i_bGreyscale;
253 0 : maPageVDev.SetReferenceDevice( i_nDPIX, i_nDPIY );
254 0 : maPageVDev.EnableOutput( sal_True );
255 :
256 : // use correct measurements
257 0 : const LocaleDataWrapper& rLocWrap( GetSettings().GetLocaleDataWrapper() );
258 0 : MapUnit eUnit = MAP_MM;
259 0 : int nDigits = 0;
260 0 : if( rLocWrap.getMeasurementSystemEnum() == MEASURE_US )
261 : {
262 0 : eUnit = MAP_100TH_INCH;
263 0 : nDigits = 2;
264 : }
265 0 : Size aLogicPaperSize( LogicToLogic( i_rOrigSize, MapMode( MAP_100TH_MM ), MapMode( eUnit ) ) );
266 0 : String aNumText( rLocWrap.getNum( aLogicPaperSize.Width(), nDigits ) );
267 0 : aBuf.append( aNumText );
268 0 : aBuf.appendAscii( eUnit == MAP_MM ? "mm" : "in" );
269 0 : if( !i_rPaperName.isEmpty() )
270 : {
271 0 : aBuf.appendAscii( " (" );
272 0 : aBuf.append( i_rPaperName );
273 0 : aBuf.append( sal_Unicode(')') );
274 : }
275 0 : maHorzDim.SetText( aBuf.makeStringAndClear() );
276 :
277 0 : aNumText = rLocWrap.getNum( aLogicPaperSize.Height(), nDigits );
278 0 : aBuf.append( aNumText );
279 0 : aBuf.appendAscii( eUnit == MAP_MM ? "mm" : "in" );
280 0 : maVertDim.SetText( aBuf.makeStringAndClear() );
281 :
282 0 : Resize();
283 0 : Invalidate();
284 0 : }
285 :
286 0 : PrintDialog::ShowNupOrderWindow::ShowNupOrderWindow( Window* i_pParent )
287 : : Window( i_pParent, WB_NOBORDER )
288 : , mnOrderMode( 0 )
289 : , mnRows( 1 )
290 0 : , mnColumns( 1 )
291 : {
292 0 : ImplInitSettings();
293 0 : }
294 :
295 0 : PrintDialog::ShowNupOrderWindow::~ShowNupOrderWindow()
296 : {
297 0 : }
298 :
299 0 : void PrintDialog::ShowNupOrderWindow::ImplInitSettings()
300 : {
301 0 : SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetFieldColor() ) );
302 0 : }
303 :
304 0 : Size PrintDialog::ShowNupOrderWindow::GetOptimalSize(WindowSizeType) const
305 : {
306 0 : return Size(70, 70);
307 : }
308 :
309 0 : void PrintDialog::ShowNupOrderWindow::Paint( const Rectangle& i_rRect )
310 : {
311 0 : Window::Paint( i_rRect );
312 0 : SetMapMode( MAP_PIXEL );
313 0 : SetTextColor( GetSettings().GetStyleSettings().GetFieldTextColor() );
314 :
315 0 : int nPages = mnRows * mnColumns;
316 0 : Font aFont( GetSettings().GetStyleSettings().GetFieldFont() );
317 0 : aFont.SetSize( Size( 0, 24 ) );
318 0 : SetFont( aFont );
319 0 : Size aSampleTextSize( GetTextWidth( rtl::OUString::valueOf( sal_Int32(nPages+1) ) ), GetTextHeight() );
320 :
321 0 : Size aOutSize( GetOutputSizePixel() );
322 0 : Size aSubSize( aOutSize.Width() / mnColumns, aOutSize.Height() / mnRows );
323 : // calculate font size: shrink the sample text so it fits
324 0 : double fX = double(aSubSize.Width())/double(aSampleTextSize.Width());
325 0 : double fY = double(aSubSize.Height())/double(aSampleTextSize.Height());
326 0 : double fScale = (fX < fY) ? fX : fY;
327 0 : long nFontHeight = long(24.0*fScale) - 3;
328 0 : if( nFontHeight < 5 )
329 0 : nFontHeight = 5;
330 0 : aFont.SetSize( Size( 0, nFontHeight ) );
331 0 : SetFont( aFont );
332 0 : long nTextHeight = GetTextHeight();
333 0 : for( int i = 0; i < nPages; i++ )
334 : {
335 0 : rtl::OUString aPageText( rtl::OUString::valueOf( sal_Int32(i+1) ) );
336 0 : int nX = 0, nY = 0;
337 0 : switch( mnOrderMode )
338 : {
339 : case SV_PRINT_PRT_NUP_ORDER_LRTB:
340 0 : nX = (i % mnColumns); nY = (i / mnColumns);
341 0 : break;
342 : case SV_PRINT_PRT_NUP_ORDER_TBLR:
343 0 : nX = (i / mnRows); nY = (i % mnRows);
344 0 : break;
345 : case SV_PRINT_PRT_NUP_ORDER_RLTB:
346 0 : nX = mnColumns - 1 - (i % mnColumns); nY = (i / mnColumns);
347 0 : break;
348 : case SV_PRINT_PRT_NUP_ORDER_TBRL:
349 0 : nX = mnColumns - 1 - (i / mnRows); nY = (i % mnRows);
350 0 : break;
351 : }
352 0 : Size aTextSize( GetTextWidth( aPageText ), nTextHeight );
353 0 : int nDeltaX = (aSubSize.Width() - aTextSize.Width()) / 2;
354 0 : int nDeltaY = (aSubSize.Height() - aTextSize.Height()) / 2;
355 0 : DrawText( Point( nX * aSubSize.Width() + nDeltaX,
356 0 : nY * aSubSize.Height() + nDeltaY ),
357 0 : aPageText );
358 0 : }
359 0 : DecorationView aVw( this );
360 0 : aVw.DrawFrame( Rectangle( Point( 0, 0), aOutSize ), FRAME_DRAW_GROUP );
361 0 : }
362 :
363 0 : PrintDialog::NUpTabPage::NUpTabPage( VclBuilder *pUIBuilder )
364 : {
365 0 : pUIBuilder->get(mpPagesBtn, "pagespersheetbtn");
366 0 : pUIBuilder->get(mpBrochureBtn, "brochure");
367 0 : pUIBuilder->get(mpPagesBoxTitleTxt, "pagespersheettxt");
368 0 : pUIBuilder->get(mpNupPagesBox, "paperspersheetlb");
369 0 : pUIBuilder->get(mpNupNumPagesTxt, "pagestxt");
370 0 : pUIBuilder->get(mpNupColEdt, "pagecols");
371 0 : pUIBuilder->get(mpNupTimesTxt, "by");
372 0 : pUIBuilder->get(mpNupRowsEdt, "pagerows");
373 0 : pUIBuilder->get(mpPageMarginTxt1, "pagemargintxt1");
374 0 : pUIBuilder->get(mpPageMarginEdt, "pagemarginsb");
375 0 : pUIBuilder->get(mpPageMarginTxt2, "pagemargintxt2");
376 0 : pUIBuilder->get(mpSheetMarginTxt1, "sheetmargintxt1");
377 0 : pUIBuilder->get(mpSheetMarginEdt, "sheetmarginsb");
378 0 : pUIBuilder->get(mpSheetMarginTxt2, "sheetmargintxt2");
379 0 : pUIBuilder->get(mpNupOrientationTxt, "orientationtxt");
380 0 : pUIBuilder->get(mpNupOrientationBox, "orientationlb");
381 0 : pUIBuilder->get(mpNupOrderTxt, "ordertxt");
382 0 : pUIBuilder->get(mpNupOrderBox, "orderlb");
383 0 : pUIBuilder->get(mpNupOrderWin, "orderpreview");
384 0 : pUIBuilder->get(mpBorderCB, "bordercb");
385 0 : }
386 :
387 0 : void PrintDialog::NUpTabPage::enableNupControls( bool bEnable )
388 : {
389 0 : mpNupPagesBox->Enable( bEnable );
390 0 : mpNupNumPagesTxt->Enable( bEnable );
391 0 : mpNupColEdt->Enable( bEnable );
392 0 : mpNupTimesTxt->Enable( bEnable );
393 0 : mpNupRowsEdt->Enable( bEnable );
394 0 : mpPageMarginTxt1->Enable( bEnable );
395 0 : mpPageMarginEdt->Enable( bEnable );
396 0 : mpPageMarginTxt2->Enable( bEnable );
397 0 : mpSheetMarginTxt1->Enable( bEnable );
398 0 : mpSheetMarginEdt->Enable( bEnable );
399 0 : mpSheetMarginTxt2->Enable( bEnable );
400 0 : mpNupOrientationTxt->Enable( bEnable );
401 0 : mpNupOrientationBox->Enable( bEnable );
402 0 : mpNupOrderTxt->Enable( bEnable );
403 0 : mpNupOrderBox->Enable( bEnable );
404 0 : mpNupOrderWin->Enable( bEnable );
405 0 : mpBorderCB->Enable( bEnable );
406 0 : }
407 :
408 0 : void PrintDialog::NUpTabPage::showAdvancedControls( bool i_bShow )
409 : {
410 0 : mpNupNumPagesTxt->Show( i_bShow );
411 0 : mpNupColEdt->Show( i_bShow );
412 0 : mpNupTimesTxt->Show( i_bShow );
413 0 : mpNupRowsEdt->Show( i_bShow );
414 0 : mpPageMarginTxt1->Show( i_bShow );
415 0 : mpPageMarginEdt->Show( i_bShow );
416 0 : mpPageMarginTxt2->Show( i_bShow );
417 0 : mpSheetMarginTxt1->Show( i_bShow );
418 0 : mpSheetMarginEdt->Show( i_bShow );
419 0 : mpSheetMarginTxt2->Show( i_bShow );
420 0 : mpNupOrientationTxt->Show( i_bShow );
421 0 : mpNupOrientationBox->Show( i_bShow );
422 0 : }
423 :
424 0 : void PrintDialog::NUpTabPage::initFromMultiPageSetup( const vcl::PrinterController::MultiPageSetup& i_rMPS )
425 : {
426 0 : mpNupOrderWin->Show();
427 0 : mpPagesBtn->Check( sal_True );
428 0 : mpBrochureBtn->Show( sal_False );
429 :
430 : // setup field units for metric fields
431 0 : const LocaleDataWrapper& rLocWrap( mpPageMarginEdt->GetLocaleDataWrapper() );
432 0 : FieldUnit eUnit = FUNIT_MM;
433 0 : sal_uInt16 nDigits = 0;
434 0 : if( rLocWrap.getMeasurementSystemEnum() == MEASURE_US )
435 : {
436 0 : eUnit = FUNIT_INCH;
437 0 : nDigits = 2;
438 : }
439 : // set units
440 0 : mpPageMarginEdt->SetUnit( eUnit );
441 0 : mpSheetMarginEdt->SetUnit( eUnit );
442 :
443 : // set precision
444 0 : mpPageMarginEdt->SetDecimalDigits( nDigits );
445 0 : mpSheetMarginEdt->SetDecimalDigits( nDigits );
446 :
447 0 : mpSheetMarginEdt->SetValue( mpSheetMarginEdt->Normalize( i_rMPS.nLeftMargin ), FUNIT_100TH_MM );
448 0 : mpPageMarginEdt->SetValue( mpPageMarginEdt->Normalize( i_rMPS.nHorizontalSpacing ), FUNIT_100TH_MM );
449 0 : mpBorderCB->Check( i_rMPS.bDrawBorder );
450 0 : mpNupRowsEdt->SetValue( i_rMPS.nRows );
451 0 : mpNupColEdt->SetValue( i_rMPS.nColumns );
452 0 : for( sal_uInt16 i = 0; i < mpNupOrderBox->GetEntryCount(); i++ )
453 : {
454 0 : if( int(sal_IntPtr(mpNupOrderBox->GetEntryData( i ))) == i_rMPS.nOrder )
455 0 : mpNupOrderBox->SelectEntryPos( i );
456 : }
457 0 : if( i_rMPS.nRows != 1 || i_rMPS.nColumns != 1 )
458 : {
459 0 : mpNupPagesBox->SelectEntryPos( mpNupPagesBox->GetEntryCount()-1 );
460 0 : showAdvancedControls( true );
461 0 : mpNupOrderWin->setValues( i_rMPS.nOrder, i_rMPS.nColumns, i_rMPS.nRows );
462 : }
463 0 : }
464 :
465 0 : void PrintDialog::NUpTabPage::readFromSettings()
466 : {
467 0 : }
468 :
469 0 : void PrintDialog::NUpTabPage::storeToSettings()
470 : {
471 0 : }
472 :
473 0 : PrintDialog::JobTabPage::JobTabPage( VclBuilder* pUIBuilder )
474 : : maCollateImg( VclResId( SV_PRINT_COLLATE_IMG ) )
475 : , maNoCollateImg( VclResId( SV_PRINT_NOCOLLATE_IMG ) )
476 0 : , mnCollateUIMode( 0 )
477 : {
478 0 : pUIBuilder->get(mpPrinters, "printers");
479 0 : mpPrinters->SetStyle(mpPrinters->GetStyle() | WB_SORT);
480 0 : pUIBuilder->get(mpStatusTxt, "status");
481 0 : pUIBuilder->get(mpLocationTxt, "location");
482 0 : pUIBuilder->get(mpCommentTxt, "comment");
483 0 : pUIBuilder->get(mpSetupButton, "setup");
484 0 : pUIBuilder->get(mpCopySpacer, "copyspacer");
485 0 : pUIBuilder->get(mpCopyCountField, "copycount");
486 0 : pUIBuilder->get(mpCollateBox, "collate");
487 0 : pUIBuilder->get(mpCollateImage, "collateimage");
488 0 : pUIBuilder->get(mpReverseOrderBox, "reverseorder");
489 : // HACK: this is not a dropdown box, but the dropdown line count
490 : // sets the results of GetOptimalSize in a normal ListBox
491 0 : mpPrinters->SetDropDownLineCount( 4 );
492 0 : }
493 :
494 0 : void PrintDialog::JobTabPage::readFromSettings()
495 : {
496 0 : SettingsConfigItem* pItem = SettingsConfigItem::get();
497 0 : rtl::OUString aValue;
498 :
499 : aValue = pItem->getValue( rtl::OUString( "PrintDialog" ),
500 0 : rtl::OUString( "CollateBox" ) );
501 0 : if( aValue.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("alwaysoff")) )
502 : {
503 0 : mnCollateUIMode = 1;
504 0 : mpCollateBox->Check( sal_False );
505 0 : mpCollateBox->Enable( sal_False );
506 : }
507 : else
508 : {
509 0 : mnCollateUIMode = 0;
510 : aValue = pItem->getValue( rtl::OUString( "PrintDialog" ),
511 0 : rtl::OUString( "Collate" ) );
512 0 : mpCollateBox->Check( aValue.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("true")) );
513 0 : }
514 0 : }
515 :
516 0 : void PrintDialog::JobTabPage::storeToSettings()
517 : {
518 0 : SettingsConfigItem* pItem = SettingsConfigItem::get();
519 : pItem->setValue( rtl::OUString( "PrintDialog" ),
520 : rtl::OUString( "CopyCount" ),
521 0 : mpCopyCountField->GetText() );
522 : pItem->setValue( rtl::OUString( "PrintDialog" ),
523 : rtl::OUString( "Collate" ),
524 0 : mpCollateBox->IsChecked() ? rtl::OUString("true") :
525 0 : rtl::OUString("false") );
526 0 : }
527 :
528 0 : PrintDialog::OutputOptPage::OutputOptPage( VclBuilder *pUIBuilder )
529 : {
530 0 : pUIBuilder->get(mpToFileBox, "printtofile");
531 0 : pUIBuilder->get(mpCollateSingleJobsBox, "singleprintjob");
532 0 : }
533 :
534 0 : void PrintDialog::OutputOptPage::readFromSettings()
535 : {
536 0 : SettingsConfigItem* pItem = SettingsConfigItem::get();
537 0 : rtl::OUString aValue;
538 : aValue = pItem->getValue( rtl::OUString( "PrintDialog" ),
539 0 : rtl::OUString( "CollateSingleJobs" ) );
540 0 : if ( aValue.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("true")) )
541 : {
542 0 : mpCollateSingleJobsBox->Check( sal_True );
543 : }
544 : else
545 : {
546 0 : mpCollateSingleJobsBox->Check( sal_False );
547 0 : }
548 0 : }
549 :
550 0 : void PrintDialog::OutputOptPage::storeToSettings()
551 : {
552 0 : SettingsConfigItem* pItem = SettingsConfigItem::get();
553 : pItem->setValue( rtl::OUString( "PrintDialog" ),
554 : rtl::OUString( "ToFile" ),
555 0 : mpToFileBox->IsChecked() ? rtl::OUString("true")
556 0 : : rtl::OUString("false") );
557 : pItem->setValue( rtl::OUString( "PrintDialog" ),
558 : rtl::OUString( "CollateSingleJobs" ),
559 0 : mpCollateSingleJobsBox->IsChecked() ? rtl::OUString("true") :
560 0 : rtl::OUString("false") );
561 0 : }
562 :
563 0 : PrintDialog::PrintDialog( Window* i_pParent, const boost::shared_ptr<PrinterController>& i_rController )
564 : : ModalDialog(i_pParent, "PrintDialog", "vcl/ui/printdialog.ui")
565 : , mpCustomOptionsUIBuilder(NULL)
566 : , maPController( i_rController )
567 : , maNUpPage(m_pUIBuilder)
568 : , maJobPage(m_pUIBuilder)
569 : , maOptionsPage(m_pUIBuilder)
570 : , maNoPageStr( VclResId( SV_PRINT_NOPAGES ).toString() )
571 : , mnCurPage( 0 )
572 : , mnCachedPages( 0 )
573 : , maPrintToFileText( VclResId( SV_PRINT_TOFILE_TXT ).toString() )
574 : , maDefPrtText( VclResId( SV_PRINT_DEFPRT_TXT ).toString() )
575 0 : , mbShowLayoutPage( sal_True )
576 : {
577 0 : get(mpOKButton, "ok");
578 0 : get(mpCancelButton, "cancel");
579 0 : get(mpHelpButton, "help");
580 0 : get(mpForwardBtn, "forward");
581 0 : get(mpBackwardBtn, "backward");
582 0 : get(mpNumPagesText, "totalnumpages");
583 0 : get(mpPageEdit, "pageedit-nospin");
584 0 : get(mpTabCtrl, "tabcontrol");
585 0 : get(mpPreviewWindow, "preview");
586 :
587 : // save printbutton text, gets exchanged occasionally with print to file
588 0 : maPrintText = mpOKButton->GetText();
589 :
590 : // setup preview controls
591 0 : mpForwardBtn->SetStyle( mpForwardBtn->GetStyle() | WB_BEVELBUTTON );
592 0 : mpBackwardBtn->SetStyle( mpBackwardBtn->GetStyle() | WB_BEVELBUTTON );
593 :
594 : // set symbols on forward and backward button
595 0 : mpBackwardBtn->SetSymbol( SYMBOL_PREV );
596 0 : mpForwardBtn->SetSymbol( SYMBOL_NEXT );
597 0 : mpBackwardBtn->ImplSetSmallSymbol( sal_True );
598 0 : mpForwardBtn->ImplSetSmallSymbol( sal_True );
599 :
600 0 : maPageStr = mpNumPagesText->GetText();
601 :
602 : // init reverse print
603 0 : maJobPage.mpReverseOrderBox->Check( maPController->getReversePrint() );
604 :
605 : // fill printer listbox
606 0 : const std::vector< rtl::OUString >& rQueues( Printer::GetPrinterQueues() );
607 0 : for( std::vector< rtl::OUString >::const_iterator it = rQueues.begin();
608 0 : it != rQueues.end(); ++it )
609 : {
610 0 : maJobPage.mpPrinters->InsertEntry( *it );
611 : }
612 : // select current printer
613 0 : if( maJobPage.mpPrinters->GetEntryPos( maPController->getPrinter()->GetName() ) != LISTBOX_ENTRY_NOTFOUND )
614 : {
615 0 : maJobPage.mpPrinters->SelectEntry( maPController->getPrinter()->GetName() );
616 : }
617 : else
618 : {
619 : // fall back to last printer
620 0 : SettingsConfigItem* pItem = SettingsConfigItem::get();
621 : String aValue( pItem->getValue( rtl::OUString( "PrintDialog" ),
622 0 : rtl::OUString( "LastPrinter" ) ) );
623 0 : if( maJobPage.mpPrinters->GetEntryPos( aValue ) != LISTBOX_ENTRY_NOTFOUND )
624 : {
625 0 : maJobPage.mpPrinters->SelectEntry( aValue );
626 0 : maPController->setPrinter( boost::shared_ptr<Printer>( new Printer( aValue ) ) );
627 : }
628 : else
629 : {
630 : // fall back to default printer
631 0 : maJobPage.mpPrinters->SelectEntry( Printer::GetDefaultPrinterName() );
632 0 : maPController->setPrinter( boost::shared_ptr<Printer>( new Printer( Printer::GetDefaultPrinterName() ) ) );
633 0 : }
634 : }
635 : // not printing to file
636 0 : maPController->resetPrinterOptions( false );
637 :
638 : // get the first page
639 0 : preparePreview( true, true );
640 :
641 : // update the text fields for the printer
642 0 : updatePrinterText();
643 :
644 : // set a select handler
645 0 : maJobPage.mpPrinters->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) );
646 :
647 : // setup sizes for N-Up
648 0 : Size aNupSize( maPController->getPrinter()->PixelToLogic(
649 0 : maPController->getPrinter()->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) ) );
650 0 : if( maPController->getPrinter()->GetOrientation() == ORIENTATION_LANDSCAPE )
651 : {
652 0 : maNupLandscapeSize = aNupSize;
653 0 : maNupPortraitSize = Size( aNupSize.Height(), aNupSize.Width() );
654 : }
655 : else
656 : {
657 0 : maNupPortraitSize = aNupSize;
658 0 : maNupLandscapeSize = Size( aNupSize.Height(), aNupSize.Width() );
659 : }
660 0 : maNUpPage.initFromMultiPageSetup( maPController->getMultipage() );
661 :
662 : // setup click handler on the various buttons
663 0 : mpOKButton->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
664 : #if OSL_DEBUG_LEVEL > 1
665 : mpCancelButton->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
666 : #endif
667 0 : mpHelpButton->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
668 0 : mpForwardBtn->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
669 0 : mpBackwardBtn->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
670 :
671 0 : maJobPage.mpCollateBox->SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
672 0 : maJobPage.mpSetupButton->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
673 0 : maNUpPage.mpBorderCB->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
674 0 : maOptionsPage.mpToFileBox->SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
675 0 : maJobPage.mpReverseOrderBox->SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
676 0 : maOptionsPage.mpCollateSingleJobsBox->SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
677 0 : maNUpPage.mpPagesBtn->SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
678 : // setup modify hdl
679 0 : mpPageEdit->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
680 0 : maJobPage.mpCopyCountField->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
681 0 : maNUpPage.mpNupRowsEdt->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
682 0 : maNUpPage.mpNupColEdt->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
683 0 : maNUpPage.mpPageMarginEdt->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
684 0 : maNUpPage.mpSheetMarginEdt->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
685 :
686 : // setup select hdl
687 0 : maNUpPage.mpNupPagesBox->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) );
688 0 : maNUpPage.mpNupOrientationBox->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) );
689 0 : maNUpPage.mpNupOrderBox->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) );
690 :
691 : // setup optional UI options set by application
692 0 : setupOptionalUI();
693 :
694 : // set change handler for UI options
695 0 : maPController->setOptionChangeHdl( LINK( this, PrintDialog, UIOptionsChanged ) );
696 :
697 : // remove layout page if unwanted
698 0 : if (!mbShowLayoutPage)
699 0 : mpTabCtrl->RemovePage(mpTabCtrl->GetPageId(2));
700 :
701 : // restore settings from last run
702 0 : readFromSettings();
703 :
704 : // setup dependencies
705 0 : checkControlDependencies();
706 :
707 0 : if ( maPController->getBoolProperty( rtl::OUString( "HideHelpButton" ), sal_False ) )
708 0 : mpHelpButton->Hide();
709 : // set initial focus to "Number of copies"
710 0 : maJobPage.mpCopyCountField->GrabFocus();
711 0 : maJobPage.mpCopyCountField->SetSelection( Selection(0, 0xFFFF) );
712 :
713 0 : updateNupFromPages();
714 0 : }
715 :
716 0 : PrintDialog::~PrintDialog()
717 : {
718 0 : delete mpCustomOptionsUIBuilder;
719 0 : }
720 :
721 0 : void PrintDialog::readFromSettings()
722 : {
723 0 : maJobPage.readFromSettings();
724 0 : maNUpPage.readFromSettings();
725 0 : maOptionsPage.readFromSettings();
726 :
727 : // read last selected tab page; if it exists, actiavte it
728 0 : SettingsConfigItem* pItem = SettingsConfigItem::get();
729 : rtl::OUString aValue = pItem->getValue( rtl::OUString( "PrintDialog" ),
730 0 : rtl::OUString( "LastPage" ) );
731 0 : sal_uInt16 nCount = mpTabCtrl->GetPageCount();
732 0 : for( sal_uInt16 i = 0; i < nCount; i++ )
733 : {
734 0 : sal_uInt16 nPageId = mpTabCtrl->GetPageId( i );
735 0 : if( aValue.equals( mpTabCtrl->GetPageText( nPageId ) ) )
736 : {
737 0 : mpTabCtrl->SelectTabPage( nPageId );
738 0 : break;
739 : }
740 : }
741 0 : mpOKButton->SetText( maOptionsPage.mpToFileBox->IsChecked() ? maPrintToFileText : maPrintText );
742 :
743 : // persistent window state
744 : rtl::OUString aWinState( pItem->getValue( rtl::OUString( "PrintDialog" ),
745 0 : rtl::OUString( "WindowState" ) ) );
746 0 : if( !aWinState.isEmpty() )
747 0 : SetWindowState( rtl::OUStringToOString( aWinState, RTL_TEXTENCODING_UTF8 ) );
748 :
749 0 : if( maOptionsPage.mpToFileBox->IsChecked() )
750 : {
751 0 : maPController->resetPrinterOptions( true );
752 0 : preparePreview( true, true );
753 0 : }
754 0 : }
755 :
756 0 : void PrintDialog::storeToSettings()
757 : {
758 0 : maJobPage.storeToSettings();
759 0 : maNUpPage.storeToSettings();
760 0 : maOptionsPage.storeToSettings();
761 :
762 : // store last selected printer
763 0 : SettingsConfigItem* pItem = SettingsConfigItem::get();
764 : pItem->setValue( rtl::OUString( "PrintDialog" ),
765 : rtl::OUString( "LastPrinter" ),
766 0 : maJobPage.mpPrinters->GetSelectEntry() );
767 :
768 : pItem->setValue( rtl::OUString( "PrintDialog" ),
769 : rtl::OUString( "LastPage" ),
770 0 : mpTabCtrl->GetPageText( mpTabCtrl->GetCurPageId() ) );
771 : pItem->setValue( rtl::OUString( "PrintDialog" ),
772 : rtl::OUString( "WindowState" ),
773 : rtl::OStringToOUString( GetWindowState(), RTL_TEXTENCODING_UTF8 )
774 0 : );
775 0 : pItem->Commit();
776 0 : }
777 :
778 0 : bool PrintDialog::isPrintToFile()
779 : {
780 0 : return maOptionsPage.mpToFileBox->IsChecked();
781 : }
782 :
783 0 : bool PrintDialog::isCollate()
784 : {
785 0 : return maJobPage.mpCopyCountField->GetValue() > 1 ? maJobPage.mpCollateBox->IsChecked() : sal_False;
786 : }
787 :
788 0 : bool PrintDialog::isSingleJobs()
789 : {
790 0 : return maOptionsPage.mpCollateSingleJobsBox->IsChecked();
791 : }
792 :
793 0 : void setHelpId( Window* i_pWindow, const Sequence< rtl::OUString >& i_rHelpIds, sal_Int32 i_nIndex )
794 : {
795 0 : if( i_nIndex >= 0 && i_nIndex < i_rHelpIds.getLength() )
796 0 : i_pWindow->SetHelpId( rtl::OUStringToOString( i_rHelpIds.getConstArray()[i_nIndex], RTL_TEXTENCODING_UTF8 ) );
797 0 : }
798 :
799 0 : static void setHelpText( Window* i_pWindow, const Sequence< rtl::OUString >& i_rHelpTexts, sal_Int32 i_nIndex )
800 : {
801 : // without a help text set and the correct smartID,
802 : // help texts will be retrieved from the online help system
803 0 : if( i_nIndex >= 0 && i_nIndex < i_rHelpTexts.getLength() )
804 0 : i_pWindow->SetHelpText( i_rHelpTexts.getConstArray()[i_nIndex] );
805 0 : }
806 :
807 0 : void PrintDialog::setupOptionalUI()
808 : {
809 0 : const Sequence< PropertyValue >& rOptions( maPController->getUIOptions() );
810 0 : for( int i = 0; i < rOptions.getLength(); i++ )
811 : {
812 0 : if (rOptions[i].Name == "OptionsUIFile")
813 : {
814 0 : rtl::OUString sOptionsUIFile;
815 0 : rOptions[i].Value >>= sOptionsUIFile;
816 :
817 0 : Window *pCustom = get<Window>("customcontents");
818 :
819 0 : delete mpCustomOptionsUIBuilder;
820 0 : mpCustomOptionsUIBuilder = new VclBuilder(pCustom, getUIRootDir(), sOptionsUIFile);
821 0 : Window *pWindow = mpCustomOptionsUIBuilder->get_widget_root();
822 0 : pWindow->Show();
823 0 : continue;
824 : }
825 :
826 0 : Sequence< beans::PropertyValue > aOptProp;
827 0 : rOptions[i].Value >>= aOptProp;
828 :
829 : // extract ui element
830 0 : rtl::OUString aCtrlType;
831 0 : rtl::OString aID;
832 0 : rtl::OUString aText;
833 0 : rtl::OUString aPropertyName;
834 0 : Sequence< rtl::OUString > aChoices;
835 0 : Sequence< sal_Bool > aChoicesDisabled;
836 0 : Sequence< rtl::OUString > aHelpTexts;
837 0 : Sequence< rtl::OUString > aIDs;
838 0 : Sequence< rtl::OUString > aHelpIds;
839 0 : sal_Int64 nMinValue = 0, nMaxValue = 0;
840 0 : rtl::OUString aGroupingHint;
841 0 : rtl::OUString aDependsOnName;
842 0 : sal_Int32 nDependsOnValue = 0;
843 0 : sal_Bool bUseDependencyRow = sal_False;
844 :
845 0 : for( int n = 0; n < aOptProp.getLength(); n++ )
846 : {
847 0 : const beans::PropertyValue& rEntry( aOptProp[ n ] );
848 0 : if ( rEntry.Name == "ID" )
849 : {
850 0 : rEntry.Value >>= aIDs;
851 0 : aID = rtl::OUStringToOString(aIDs[0], RTL_TEXTENCODING_UTF8);
852 : }
853 0 : if ( rEntry.Name == "Text" )
854 : {
855 0 : rEntry.Value >>= aText;
856 : }
857 0 : else if ( rEntry.Name == "ControlType" )
858 : {
859 0 : rEntry.Value >>= aCtrlType;
860 : }
861 0 : else if ( rEntry.Name == "Choices" )
862 : {
863 0 : rEntry.Value >>= aChoices;
864 : }
865 0 : else if ( rEntry.Name == "ChoicesDisabled" )
866 : {
867 0 : rEntry.Value >>= aChoicesDisabled;
868 : }
869 0 : else if ( rEntry.Name == "Property" )
870 : {
871 0 : PropertyValue aVal;
872 0 : rEntry.Value >>= aVal;
873 0 : aPropertyName = aVal.Name;
874 : }
875 0 : else if ( rEntry.Name == "Enabled" )
876 : {
877 0 : sal_Bool bValue = sal_True;
878 0 : rEntry.Value >>= bValue;
879 : }
880 0 : else if ( rEntry.Name == "GroupingHint" )
881 : {
882 0 : rEntry.Value >>= aGroupingHint;
883 : }
884 0 : else if ( rEntry.Name == "DependsOnName" )
885 : {
886 0 : rEntry.Value >>= aDependsOnName;
887 : }
888 0 : else if ( rEntry.Name == "DependsOnEntry" )
889 : {
890 0 : rEntry.Value >>= nDependsOnValue;
891 : }
892 0 : else if ( rEntry.Name == "AttachToDependency" )
893 : {
894 0 : rEntry.Value >>= bUseDependencyRow;
895 : }
896 0 : else if ( rEntry.Name == "MinValue" )
897 : {
898 0 : rEntry.Value >>= nMinValue;
899 : }
900 0 : else if ( rEntry.Name == "MaxValue" )
901 : {
902 0 : rEntry.Value >>= nMaxValue;
903 : }
904 0 : else if ( rEntry.Name == "HelpText" )
905 : {
906 0 : if( ! (rEntry.Value >>= aHelpTexts) )
907 : {
908 0 : rtl::OUString aHelpText;
909 0 : if( (rEntry.Value >>= aHelpText) )
910 : {
911 0 : aHelpTexts.realloc( 1 );
912 0 : *aHelpTexts.getArray() = aHelpText;
913 0 : }
914 : }
915 : }
916 0 : else if ( rEntry.Name == "HelpId" )
917 : {
918 0 : if( ! (rEntry.Value >>= aHelpIds ) )
919 : {
920 0 : rtl::OUString aHelpId;
921 0 : if( (rEntry.Value >>= aHelpId) )
922 : {
923 0 : aHelpIds.realloc( 1 );
924 0 : *aHelpIds.getArray() = aHelpId;
925 0 : }
926 : }
927 : }
928 0 : else if ( rEntry.Name == "HintNoLayoutPage" )
929 : {
930 0 : sal_Bool bNoLayoutPage = sal_False;
931 0 : rEntry.Value >>= bNoLayoutPage;
932 0 : mbShowLayoutPage = ! bNoLayoutPage;
933 : }
934 : }
935 :
936 0 : if (aCtrlType == "Group" && !aID.isEmpty())
937 : {
938 0 : TabPage *pPage = get<TabPage>(aID);
939 0 : if (!pPage && mpCustomOptionsUIBuilder)
940 0 : pPage = mpCustomOptionsUIBuilder->get<TabPage>(aID);
941 0 : sal_uInt16 nPageId = mpTabCtrl->GetPageId(*pPage);
942 :
943 0 : mpTabCtrl->SetPageText(nPageId, aText);
944 :
945 : // set help id
946 0 : if (aHelpIds.getLength() > 0)
947 0 : mpTabCtrl->SetHelpId(nPageId, rtl::OUStringToOString(aHelpIds.getConstArray()[0], RTL_TEXTENCODING_UTF8));
948 :
949 : // set help text
950 0 : if (aHelpTexts.getLength() > 0)
951 0 : mpTabCtrl->SetHelpText(nPageId, aHelpTexts.getConstArray()[0]);
952 :
953 0 : pPage->Show();
954 : }
955 0 : else if (aCtrlType == "Subgroup" && !aID.isEmpty())
956 : {
957 0 : Window *pFrame = get<Window>(aID);
958 0 : if (!pFrame && mpCustomOptionsUIBuilder)
959 0 : pFrame = mpCustomOptionsUIBuilder->get<Window>(aID);
960 :
961 0 : pFrame->SetText(aText);
962 :
963 : // set help id
964 0 : setHelpId(pFrame, aHelpIds, 0);
965 : // set help text
966 0 : setHelpText(pFrame, aHelpTexts, 0);
967 :
968 0 : pFrame->Show();
969 : }
970 : // EVIL
971 0 : else if( aCtrlType == "Bool" && aGroupingHint == "LayoutPage" && aPropertyName == "PrintProspect" )
972 : {
973 0 : maNUpPage.mpBrochureBtn->SetText( aText );
974 0 : maNUpPage.mpBrochureBtn->Show();
975 :
976 0 : sal_Bool bVal = sal_False;
977 0 : PropertyValue* pVal = maPController->getValue( aPropertyName );
978 0 : if( pVal )
979 0 : pVal->Value >>= bVal;
980 0 : maNUpPage.mpBrochureBtn->Check( bVal );
981 0 : maNUpPage.mpBrochureBtn->Enable( maPController->isUIOptionEnabled( aPropertyName ) && pVal != NULL );
982 0 : maNUpPage.mpBrochureBtn->SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
983 :
984 0 : maPropertyToWindowMap[ aPropertyName ].push_back( maNUpPage.mpBrochureBtn );
985 0 : maControlToPropertyMap[maNUpPage.mpBrochureBtn] = aPropertyName;
986 :
987 : // set help id
988 0 : setHelpId( maNUpPage.mpBrochureBtn, aHelpIds, 0 );
989 : // set help text
990 0 : setHelpText( maNUpPage.mpBrochureBtn, aHelpTexts, 0 );
991 : }
992 0 : else if (aCtrlType == "Bool")
993 : {
994 : // add a check box
995 0 : CheckBox* pNewBox = get<CheckBox>(aID);
996 0 : if (!pNewBox && mpCustomOptionsUIBuilder)
997 0 : pNewBox = mpCustomOptionsUIBuilder->get<CheckBox>(aID);
998 :
999 0 : pNewBox->SetText( aText );
1000 0 : pNewBox->Show();
1001 :
1002 0 : sal_Bool bVal = sal_False;
1003 0 : PropertyValue* pVal = maPController->getValue( aPropertyName );
1004 0 : if( pVal )
1005 0 : pVal->Value >>= bVal;
1006 0 : pNewBox->Check( bVal );
1007 0 : pNewBox->SetToggleHdl( LINK( this, PrintDialog, UIOption_CheckHdl ) );
1008 :
1009 0 : maPropertyToWindowMap[ aPropertyName ].push_back( pNewBox );
1010 0 : maControlToPropertyMap[pNewBox] = aPropertyName;
1011 :
1012 : // set help id
1013 0 : setHelpId( pNewBox, aHelpIds, 0 );
1014 : // set help text
1015 0 : setHelpText( pNewBox, aHelpTexts, 0 );
1016 : }
1017 0 : else if (aCtrlType == "Radio")
1018 : {
1019 0 : sal_Int32 nCurHelpText = 0;
1020 :
1021 : // iterate options
1022 0 : sal_Int32 nSelectVal = 0;
1023 0 : PropertyValue* pVal = maPController->getValue( aPropertyName );
1024 0 : if( pVal && pVal->Value.hasValue() )
1025 0 : pVal->Value >>= nSelectVal;
1026 0 : for( sal_Int32 m = 0; m < aChoices.getLength(); m++ )
1027 : {
1028 0 : aID = rtl::OUStringToOString(aIDs[m], RTL_TEXTENCODING_UTF8);
1029 0 : RadioButton* pBtn = get<RadioButton>(aID);
1030 0 : if (!pBtn && mpCustomOptionsUIBuilder)
1031 0 : pBtn = mpCustomOptionsUIBuilder->get<RadioButton>(aID);
1032 :
1033 0 : pBtn->SetText( aChoices[m] );
1034 0 : pBtn->Check( m == nSelectVal );
1035 0 : pBtn->SetToggleHdl( LINK( this, PrintDialog, UIOption_RadioHdl ) );
1036 0 : if( aChoicesDisabled.getLength() > m && aChoicesDisabled[m] == sal_True )
1037 0 : pBtn->Enable( sal_False );
1038 0 : pBtn->Show();
1039 0 : maPropertyToWindowMap[ aPropertyName ].push_back( pBtn );
1040 0 : maControlToPropertyMap[pBtn] = aPropertyName;
1041 0 : maControlToNumValMap[pBtn] = m;
1042 :
1043 : // set help id
1044 0 : setHelpId( pBtn, aHelpIds, nCurHelpText );
1045 : // set help text
1046 0 : setHelpText( pBtn, aHelpTexts, nCurHelpText );
1047 0 : nCurHelpText++;
1048 : }
1049 : }
1050 0 : else if ( aCtrlType == "List" )
1051 : {
1052 0 : ListBox* pList = get<ListBox>(aID);
1053 0 : if (!pList && mpCustomOptionsUIBuilder)
1054 0 : pList = mpCustomOptionsUIBuilder->get<ListBox>(aID);
1055 :
1056 : // iterate options
1057 0 : for( sal_Int32 m = 0; m < aChoices.getLength(); m++ )
1058 : {
1059 0 : pList->InsertEntry( aChoices[m] );
1060 : }
1061 0 : sal_Int32 nSelectVal = 0;
1062 0 : PropertyValue* pVal = maPController->getValue( aPropertyName );
1063 0 : if( pVal && pVal->Value.hasValue() )
1064 0 : pVal->Value >>= nSelectVal;
1065 0 : pList->SelectEntryPos( static_cast<sal_uInt16>(nSelectVal) );
1066 0 : pList->SetSelectHdl( LINK( this, PrintDialog, UIOption_SelectHdl ) );
1067 0 : pList->SetDropDownLineCount( static_cast<sal_uInt16>(aChoices.getLength()) );
1068 0 : pList->Show();
1069 :
1070 : // set help id
1071 0 : setHelpId( pList, aHelpIds, 0 );
1072 : // set help text
1073 0 : setHelpText( pList, aHelpTexts, 0 );
1074 :
1075 0 : maPropertyToWindowMap[ aPropertyName ].push_back( pList );
1076 0 : maControlToPropertyMap[pList] = aPropertyName;
1077 : }
1078 0 : else if ( aCtrlType == "Range" )
1079 : {
1080 0 : NumericField* pField = get<NumericField>(aID);
1081 0 : if (!pField && mpCustomOptionsUIBuilder)
1082 0 : pField = mpCustomOptionsUIBuilder->get<NumericField>(aID);
1083 :
1084 : // set min/max and current value
1085 0 : if( nMinValue != nMaxValue )
1086 : {
1087 0 : pField->SetMin( nMinValue );
1088 0 : pField->SetMax( nMaxValue );
1089 : }
1090 0 : sal_Int64 nCurVal = 0;
1091 0 : PropertyValue* pVal = maPController->getValue( aPropertyName );
1092 0 : if( pVal && pVal->Value.hasValue() )
1093 0 : pVal->Value >>= nCurVal;
1094 0 : pField->SetValue( nCurVal );
1095 0 : pField->SetModifyHdl( LINK( this, PrintDialog, UIOption_ModifyHdl ) );
1096 0 : pField->Show();
1097 :
1098 : // set help id
1099 0 : setHelpId( pField, aHelpIds, 0 );
1100 : // set help text
1101 0 : setHelpText( pField, aHelpTexts, 0 );
1102 :
1103 0 : maPropertyToWindowMap[ aPropertyName ].push_back( pField );
1104 0 : maControlToPropertyMap[pField] = aPropertyName;
1105 : }
1106 0 : else if (aCtrlType == "Edit")
1107 : {
1108 0 : Edit *pField = get<Edit>(aID);
1109 0 : if (!pField && mpCustomOptionsUIBuilder)
1110 0 : pField = mpCustomOptionsUIBuilder->get<Edit>(aID);
1111 :
1112 0 : rtl::OUString aCurVal;
1113 0 : PropertyValue* pVal = maPController->getValue( aPropertyName );
1114 0 : if( pVal && pVal->Value.hasValue() )
1115 0 : pVal->Value >>= aCurVal;
1116 0 : pField->SetText( aCurVal );
1117 0 : pField->SetModifyHdl( LINK( this, PrintDialog, UIOption_ModifyHdl ) );
1118 0 : pField->Show();
1119 :
1120 : // set help id
1121 0 : setHelpId( pField, aHelpIds, 0 );
1122 : // set help text
1123 0 : setHelpText( pField, aHelpTexts, 0 );
1124 :
1125 0 : maPropertyToWindowMap[ aPropertyName ].push_back( pField );
1126 0 : maControlToPropertyMap[pField] = aPropertyName;
1127 : }
1128 : else
1129 : {
1130 0 : rtl::OStringBuffer sMessage;
1131 0 : sMessage.append(RTL_CONSTASCII_STRINGPARAM("Unsupported UI option: \""));
1132 0 : sMessage.append(rtl::OUStringToOString(aCtrlType, RTL_TEXTENCODING_UTF8));
1133 0 : sMessage.append('"');
1134 0 : OSL_FAIL( sMessage.getStr() );
1135 : }
1136 0 : }
1137 :
1138 : // #i106506# if no brochure button, then the singular Pages radio button
1139 : // makes no sense, so replace it by a FixedText label
1140 0 : if (!maNUpPage.mpBrochureBtn->IsVisible() && maNUpPage.mpPagesBtn->IsVisible())
1141 : {
1142 0 : maNUpPage.mpPagesBoxTitleTxt->SetText( maNUpPage.mpPagesBtn->GetText() );
1143 0 : maNUpPage.mpPagesBoxTitleTxt->Show( sal_True );
1144 0 : maNUpPage.mpPagesBtn->Show( sal_False );
1145 : }
1146 :
1147 : // update enable states
1148 0 : checkOptionalControlDependencies();
1149 :
1150 0 : Window *pPageRange = get<Window>("pagerange");
1151 :
1152 : // print range not shown (currently math only) -> hide spacer line and reverse order
1153 0 : if (!pPageRange || !pPageRange->IsVisible())
1154 : {
1155 0 : maJobPage.mpCopySpacer->Show( sal_False );
1156 0 : maJobPage.mpReverseOrderBox->Show( sal_False );
1157 : }
1158 :
1159 0 : if (!mpCustomOptionsUIBuilder)
1160 0 : mpTabCtrl->RemovePage(mpTabCtrl->GetPageId(1));
1161 0 : }
1162 :
1163 0 : void PrintDialog::DataChanged( const DataChangedEvent& i_rDCEvt )
1164 : {
1165 : // react on settings changed
1166 0 : if( i_rDCEvt.GetType() == DATACHANGED_SETTINGS )
1167 0 : checkControlDependencies();
1168 0 : ModalDialog::DataChanged( i_rDCEvt );
1169 0 : }
1170 :
1171 0 : void PrintDialog::checkControlDependencies()
1172 : {
1173 0 : if( maJobPage.mpCopyCountField->GetValue() > 1 )
1174 0 : maJobPage.mpCollateBox->Enable( maJobPage.mnCollateUIMode == 0 );
1175 : else
1176 0 : maJobPage.mpCollateBox->Enable( sal_False );
1177 :
1178 0 : Image aImg( maJobPage.mpCollateBox->IsChecked() ? maJobPage.maCollateImg : maJobPage.maNoCollateImg );
1179 :
1180 0 : Size aImgSize( aImg.GetSizePixel() );
1181 :
1182 : // adjust size of image
1183 0 : maJobPage.mpCollateImage->SetSizePixel( aImgSize );
1184 0 : maJobPage.mpCollateImage->SetImage( aImg );
1185 :
1186 : // enable setup button only for printers that can be setup
1187 0 : bool bHaveSetup = maPController->getPrinter()->HasSupport( SUPPORT_SETUPDIALOG );
1188 0 : maJobPage.mpSetupButton->Enable(bHaveSetup);
1189 0 : }
1190 :
1191 0 : void PrintDialog::checkOptionalControlDependencies()
1192 : {
1193 0 : for( std::map< Window*, rtl::OUString >::iterator it = maControlToPropertyMap.begin();
1194 0 : it != maControlToPropertyMap.end(); ++it )
1195 : {
1196 0 : bool bShouldbeEnabled = maPController->isUIOptionEnabled( it->second );
1197 0 : if( ! bShouldbeEnabled )
1198 : {
1199 : // enable controls that are directly attached to a dependency anyway
1200 : // if the normally disabled controls get modified, change the dependency
1201 : // so the control would be enabled
1202 : // example: in print range "Print All" is selected, "Page Range" is then of course
1203 : // not selected and the Edit for the Page Range would be disabled
1204 : // as a convenience we should enable the Edit anyway and automatically select
1205 : // "Page Range" instead of "Print All" if the Edit gets modified
1206 0 : if( maReverseDependencySet.find( it->second ) != maReverseDependencySet.end() )
1207 : {
1208 0 : rtl::OUString aDep( maPController->getDependency( it->second ) );
1209 : // if the dependency is at least enabled, then enable this control anyway
1210 0 : if( !aDep.isEmpty() && maPController->isUIOptionEnabled( aDep ) )
1211 0 : bShouldbeEnabled = true;
1212 : }
1213 : }
1214 :
1215 0 : if( bShouldbeEnabled && dynamic_cast<RadioButton*>(it->first) )
1216 : {
1217 0 : std::map< Window*, sal_Int32 >::const_iterator r_it = maControlToNumValMap.find( it->first );
1218 0 : if( r_it != maControlToNumValMap.end() )
1219 : {
1220 0 : bShouldbeEnabled = maPController->isUIChoiceEnabled( it->second, r_it->second );
1221 : }
1222 : }
1223 :
1224 :
1225 0 : bool bIsEnabled = it->first->IsEnabled();
1226 : // Enable does not do a change check first, so can be less cheap than expected
1227 0 : if( bShouldbeEnabled != bIsEnabled )
1228 0 : it->first->Enable( bShouldbeEnabled );
1229 : }
1230 0 : }
1231 :
1232 0 : static rtl::OUString searchAndReplace( const rtl::OUString& i_rOrig, const char* i_pRepl, sal_Int32 i_nReplLen, const rtl::OUString& i_rRepl )
1233 : {
1234 0 : sal_Int32 nPos = i_rOrig.indexOfAsciiL( i_pRepl, i_nReplLen );
1235 0 : if( nPos != -1 )
1236 : {
1237 0 : rtl::OUStringBuffer aBuf( i_rOrig.getLength() );
1238 0 : aBuf.append( i_rOrig.getStr(), nPos );
1239 0 : aBuf.append( i_rRepl );
1240 0 : if( nPos + i_nReplLen < i_rOrig.getLength() )
1241 0 : aBuf.append( i_rOrig.getStr() + nPos + i_nReplLen );
1242 0 : return aBuf.makeStringAndClear();
1243 : }
1244 0 : return i_rOrig;
1245 : }
1246 :
1247 0 : void PrintDialog::updatePrinterText()
1248 : {
1249 0 : const rtl::OUString aDefPrt( Printer::GetDefaultPrinterName() );
1250 0 : const QueueInfo* pInfo = Printer::GetQueueInfo( maJobPage.mpPrinters->GetSelectEntry(), true );
1251 0 : if( pInfo )
1252 : {
1253 0 : maJobPage.mpLocationTxt->SetText( pInfo->GetLocation() );
1254 0 : maJobPage.mpCommentTxt->SetText( pInfo->GetComment() );
1255 : // FIXME: status text
1256 0 : rtl::OUString aStatus;
1257 0 : if( aDefPrt == pInfo->GetPrinterName() )
1258 0 : aStatus = maDefPrtText;
1259 0 : maJobPage.mpStatusTxt->SetText( aStatus );
1260 : }
1261 : else
1262 : {
1263 0 : maJobPage.mpLocationTxt->SetText( String() );
1264 0 : maJobPage.mpCommentTxt->SetText( String() );
1265 0 : maJobPage.mpStatusTxt->SetText( String() );
1266 0 : }
1267 0 : }
1268 :
1269 0 : void PrintDialog::setPreviewText( sal_Int32 )
1270 : {
1271 0 : rtl::OUString aNewText( searchAndReplace( maPageStr, "%n", 2, rtl::OUString::valueOf( mnCachedPages ) ) );
1272 0 : mpNumPagesText->SetText( aNewText );
1273 0 : }
1274 :
1275 0 : void PrintDialog::preparePreview( bool i_bNewPage, bool i_bMayUseCache )
1276 : {
1277 : // page range may have changed depending on options
1278 0 : sal_Int32 nPages = maPController->getFilteredPageCount();
1279 0 : mnCachedPages = nPages;
1280 :
1281 0 : if( mnCurPage >= nPages )
1282 0 : mnCurPage = nPages-1;
1283 0 : if( mnCurPage < 0 )
1284 0 : mnCurPage = 0;
1285 :
1286 0 : setPreviewText( mnCurPage );
1287 :
1288 0 : mpPageEdit->SetMin( 1 );
1289 0 : mpPageEdit->SetMax( nPages );
1290 :
1291 0 : if( i_bNewPage )
1292 : {
1293 0 : const MapMode aMapMode( MAP_100TH_MM );
1294 0 : GDIMetaFile aMtf;
1295 0 : boost::shared_ptr<Printer> aPrt( maPController->getPrinter() );
1296 0 : if( nPages > 0 )
1297 : {
1298 : PrinterController::PageSize aPageSize =
1299 0 : maPController->getFilteredPageFile( mnCurPage, aMtf, i_bMayUseCache );
1300 0 : if( ! aPageSize.bFullPaper )
1301 : {
1302 0 : Point aOff( aPrt->PixelToLogic( aPrt->GetPageOffsetPixel(), aMapMode ) );
1303 0 : aMtf.Move( aOff.X(), aOff.Y() );
1304 : }
1305 : }
1306 :
1307 0 : Size aCurPageSize = aPrt->PixelToLogic( aPrt->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) );
1308 : mpPreviewWindow->setPreview( aMtf, aCurPageSize,
1309 : aPrt->GetPaperName( false ),
1310 : nPages > 0 ? rtl::OUString() : maNoPageStr,
1311 0 : aPrt->ImplGetDPIX(), aPrt->ImplGetDPIY(),
1312 0 : aPrt->GetPrinterOptions().IsConvertToGreyscales()
1313 0 : );
1314 :
1315 0 : mpForwardBtn->Enable( mnCurPage < nPages-1 );
1316 0 : mpBackwardBtn->Enable( mnCurPage != 0 );
1317 0 : mpPageEdit->Enable( nPages > 1 );
1318 : }
1319 0 : }
1320 :
1321 0 : Size PrintDialog::getJobPageSize()
1322 : {
1323 0 : if( maFirstPageSize.Width() == 0 && maFirstPageSize.Height() == 0)
1324 : {
1325 0 : maFirstPageSize = maNupPortraitSize;
1326 0 : GDIMetaFile aMtf;
1327 0 : if( maPController->getPageCountProtected() > 0 )
1328 : {
1329 0 : PrinterController::PageSize aPageSize = maPController->getPageFile( 0, aMtf, true );
1330 0 : maFirstPageSize = aPageSize.aSize;
1331 0 : }
1332 : }
1333 0 : return maFirstPageSize;
1334 : }
1335 :
1336 0 : void PrintDialog::updateNupFromPages()
1337 : {
1338 0 : long nPages = long(maNUpPage.mpNupPagesBox->GetEntryData(maNUpPage.mpNupPagesBox->GetSelectEntryPos()));
1339 0 : int nRows = int(maNUpPage.mpNupRowsEdt->GetValue());
1340 0 : int nCols = int(maNUpPage.mpNupColEdt->GetValue());
1341 0 : long nPageMargin = long(maNUpPage.mpPageMarginEdt->Denormalize(maNUpPage.mpPageMarginEdt->GetValue( FUNIT_100TH_MM )));
1342 0 : long nSheetMargin = long(maNUpPage.mpSheetMarginEdt->Denormalize(maNUpPage.mpSheetMarginEdt->GetValue( FUNIT_100TH_MM )));
1343 0 : bool bCustom = false;
1344 :
1345 0 : if( nPages == 1 )
1346 : {
1347 0 : nRows = nCols = 1;
1348 0 : nSheetMargin = 0;
1349 0 : nPageMargin = 0;
1350 : }
1351 0 : else if( nPages == 2 || nPages == 4 || nPages == 6 || nPages == 9 || nPages == 16 )
1352 : {
1353 0 : Size aJobPageSize( getJobPageSize() );
1354 0 : bool bPortrait = aJobPageSize.Width() < aJobPageSize.Height();
1355 0 : if( nPages == 2 )
1356 : {
1357 0 : if( bPortrait )
1358 0 : nRows = 1, nCols = 2;
1359 : else
1360 0 : nRows = 2, nCols = 1;
1361 : }
1362 0 : else if( nPages == 4 )
1363 0 : nRows = nCols = 2;
1364 0 : else if( nPages == 6 )
1365 : {
1366 0 : if( bPortrait )
1367 0 : nRows = 2, nCols = 3;
1368 : else
1369 0 : nRows = 3, nCols = 2;
1370 : }
1371 0 : else if( nPages == 9 )
1372 0 : nRows = nCols = 3;
1373 0 : else if( nPages == 16 )
1374 0 : nRows = nCols = 4;
1375 0 : nPageMargin = 0;
1376 0 : nSheetMargin = 0;
1377 : }
1378 : else
1379 0 : bCustom = true;
1380 :
1381 0 : if( nPages > 1 )
1382 : {
1383 : // set upper limits for margins based on job page size and rows/columns
1384 0 : Size aSize( getJobPageSize() );
1385 :
1386 : // maximum sheet distance: 1/2 sheet
1387 0 : long nHorzMax = aSize.Width()/2;
1388 0 : long nVertMax = aSize.Height()/2;
1389 0 : if( nSheetMargin > nHorzMax )
1390 0 : nSheetMargin = nHorzMax;
1391 0 : if( nSheetMargin > nVertMax )
1392 0 : nSheetMargin = nVertMax;
1393 :
1394 : maNUpPage.mpSheetMarginEdt->SetMax(
1395 : maNUpPage.mpSheetMarginEdt->Normalize(
1396 0 : nHorzMax > nVertMax ? nVertMax : nHorzMax ), FUNIT_100TH_MM );
1397 :
1398 : // maximum page distance
1399 0 : nHorzMax = (aSize.Width() - 2*nSheetMargin);
1400 0 : if( nCols > 1 )
1401 0 : nHorzMax /= (nCols-1);
1402 0 : nVertMax = (aSize.Height() - 2*nSheetMargin);
1403 0 : if( nRows > 1 )
1404 0 : nHorzMax /= (nRows-1);
1405 :
1406 0 : if( nPageMargin > nHorzMax )
1407 0 : nPageMargin = nHorzMax;
1408 0 : if( nPageMargin > nVertMax )
1409 0 : nPageMargin = nVertMax;
1410 :
1411 : maNUpPage.mpPageMarginEdt->SetMax(
1412 : maNUpPage.mpSheetMarginEdt->Normalize(
1413 0 : nHorzMax > nVertMax ? nVertMax : nHorzMax ), FUNIT_100TH_MM );
1414 : }
1415 :
1416 0 : maNUpPage.mpNupRowsEdt->SetValue( nRows );
1417 0 : maNUpPage.mpNupColEdt->SetValue( nCols );
1418 0 : maNUpPage.mpPageMarginEdt->SetValue( maNUpPage.mpPageMarginEdt->Normalize( nPageMargin ), FUNIT_100TH_MM );
1419 0 : maNUpPage.mpSheetMarginEdt->SetValue( maNUpPage.mpSheetMarginEdt->Normalize( nSheetMargin ), FUNIT_100TH_MM );
1420 :
1421 0 : maNUpPage.showAdvancedControls( bCustom );
1422 :
1423 0 : updateNup();
1424 0 : }
1425 :
1426 0 : void PrintDialog::updateNup()
1427 : {
1428 0 : int nRows = int(maNUpPage.mpNupRowsEdt->GetValue());
1429 0 : int nCols = int(maNUpPage.mpNupColEdt->GetValue());
1430 0 : long nPageMargin = long(maNUpPage.mpPageMarginEdt->Denormalize(maNUpPage.mpPageMarginEdt->GetValue( FUNIT_100TH_MM )));
1431 0 : long nSheetMargin = long(maNUpPage.mpSheetMarginEdt->Denormalize(maNUpPage.mpSheetMarginEdt->GetValue( FUNIT_100TH_MM )));
1432 :
1433 0 : PrinterController::MultiPageSetup aMPS;
1434 0 : aMPS.nRows = nRows;
1435 0 : aMPS.nColumns = nCols;
1436 0 : aMPS.nRepeat = 1;
1437 : aMPS.nLeftMargin =
1438 : aMPS.nTopMargin =
1439 : aMPS.nRightMargin =
1440 0 : aMPS.nBottomMargin = nSheetMargin;
1441 :
1442 : aMPS.nHorizontalSpacing =
1443 0 : aMPS.nVerticalSpacing = nPageMargin;
1444 :
1445 0 : aMPS.bDrawBorder = maNUpPage.mpBorderCB->IsChecked();
1446 :
1447 : int nOrderMode = int(sal_IntPtr(maNUpPage.mpNupOrderBox->GetEntryData(
1448 0 : maNUpPage.mpNupOrderBox->GetSelectEntryPos() )));
1449 0 : if( nOrderMode == SV_PRINT_PRT_NUP_ORDER_LRTB )
1450 0 : aMPS.nOrder = PrinterController::LRTB;
1451 0 : else if( nOrderMode == SV_PRINT_PRT_NUP_ORDER_TBLR )
1452 0 : aMPS.nOrder = PrinterController::TBLR;
1453 0 : else if( nOrderMode == SV_PRINT_PRT_NUP_ORDER_RLTB )
1454 0 : aMPS.nOrder = PrinterController::RLTB;
1455 0 : else if( nOrderMode == SV_PRINT_PRT_NUP_ORDER_TBRL )
1456 0 : aMPS.nOrder = PrinterController::TBRL;
1457 :
1458 : int nOrientationMode = int(sal_IntPtr(maNUpPage.mpNupOrientationBox->GetEntryData(
1459 0 : maNUpPage.mpNupOrientationBox->GetSelectEntryPos() )));
1460 0 : if( nOrientationMode == SV_PRINT_PRT_NUP_ORIENTATION_LANDSCAPE )
1461 0 : aMPS.aPaperSize = maNupLandscapeSize;
1462 0 : else if( nOrientationMode == SV_PRINT_PRT_NUP_ORIENTATION_PORTRAIT )
1463 0 : aMPS.aPaperSize = maNupPortraitSize;
1464 : else // automatic mode
1465 : {
1466 : // get size of first real page to see if it is portrait or landscape
1467 : // we assume same page sizes for all the pages for this
1468 0 : Size aPageSize = getJobPageSize();
1469 :
1470 0 : Size aMultiSize( aPageSize.Width() * nCols, aPageSize.Height() * nRows );
1471 0 : if( aMultiSize.Width() > aMultiSize.Height() ) // fits better on landscape
1472 0 : aMPS.aPaperSize = maNupLandscapeSize;
1473 : else
1474 0 : aMPS.aPaperSize = maNupPortraitSize;
1475 : }
1476 :
1477 0 : maPController->setMultipage( aMPS );
1478 :
1479 0 : maNUpPage.mpNupOrderWin->setValues( nOrderMode, nCols, nRows );
1480 :
1481 0 : preparePreview( true, true );
1482 0 : }
1483 :
1484 0 : IMPL_LINK( PrintDialog, SelectHdl, ListBox*, pBox )
1485 : {
1486 0 : if( pBox == maJobPage.mpPrinters )
1487 : {
1488 0 : String aNewPrinter( pBox->GetSelectEntry() );
1489 : // set new printer
1490 0 : maPController->setPrinter( boost::shared_ptr<Printer>( new Printer( aNewPrinter ) ) );
1491 0 : maPController->resetPrinterOptions( maOptionsPage.mpToFileBox->IsChecked() );
1492 : // update text fields
1493 0 : updatePrinterText();
1494 0 : preparePreview( true, false );
1495 : }
1496 0 : else if( pBox == maNUpPage.mpNupOrientationBox || pBox == maNUpPage.mpNupOrderBox )
1497 : {
1498 0 : updateNup();
1499 : }
1500 0 : else if( pBox == maNUpPage.mpNupPagesBox )
1501 : {
1502 0 : if( !maNUpPage.mpPagesBtn->IsChecked() )
1503 0 : maNUpPage.mpPagesBtn->Check();
1504 0 : updateNupFromPages();
1505 : }
1506 :
1507 0 : return 0;
1508 : }
1509 :
1510 0 : IMPL_LINK( PrintDialog, ClickHdl, Button*, pButton )
1511 : {
1512 0 : if( pButton == mpOKButton || pButton == mpCancelButton )
1513 : {
1514 0 : storeToSettings();
1515 0 : EndDialog( pButton == mpOKButton );
1516 : }
1517 0 : else if( pButton == mpHelpButton )
1518 : {
1519 : // start help system
1520 0 : Help* pHelp = Application::GetHelp();
1521 0 : if( pHelp )
1522 : {
1523 0 : pHelp->Start( rtl::OUString("vcl/ui/printdialog"), mpOKButton );
1524 : }
1525 : }
1526 0 : else if( pButton == mpForwardBtn )
1527 : {
1528 0 : previewForward();
1529 : }
1530 0 : else if( pButton == mpBackwardBtn )
1531 : {
1532 0 : previewBackward();
1533 : }
1534 0 : else if( pButton == maOptionsPage.mpToFileBox )
1535 : {
1536 0 : mpOKButton->SetText( maOptionsPage.mpToFileBox->IsChecked() ? maPrintToFileText : maPrintText );
1537 0 : maPController->resetPrinterOptions( maOptionsPage.mpToFileBox->IsChecked() );
1538 0 : preparePreview( true, true );
1539 : }
1540 0 : else if( pButton == maNUpPage.mpBrochureBtn )
1541 : {
1542 0 : PropertyValue* pVal = getValueForWindow( pButton );
1543 0 : if( pVal )
1544 : {
1545 0 : sal_Bool bVal = maNUpPage.mpBrochureBtn->IsChecked();
1546 0 : pVal->Value <<= bVal;
1547 :
1548 0 : checkOptionalControlDependencies();
1549 :
1550 : // update preview and page settings
1551 0 : preparePreview();
1552 : }
1553 0 : if( maNUpPage.mpBrochureBtn->IsChecked() )
1554 : {
1555 0 : maNUpPage.mpNupPagesBox->SelectEntryPos( 0 );
1556 0 : updateNupFromPages();
1557 0 : maNUpPage.showAdvancedControls( false );
1558 0 : maNUpPage.enableNupControls( false );
1559 : }
1560 : }
1561 0 : else if( pButton == maNUpPage.mpPagesBtn )
1562 : {
1563 0 : maNUpPage.enableNupControls( true );
1564 0 : updateNupFromPages();
1565 : }
1566 0 : else if( pButton == maJobPage.mpCollateBox )
1567 : {
1568 : maPController->setValue( rtl::OUString( "Collate" ),
1569 0 : makeAny( sal_Bool(isCollate()) ) );
1570 0 : checkControlDependencies();
1571 : }
1572 0 : else if( pButton == maJobPage.mpReverseOrderBox )
1573 : {
1574 0 : sal_Bool bChecked = maJobPage.mpReverseOrderBox->IsChecked();
1575 0 : maPController->setReversePrint( bChecked );
1576 : maPController->setValue( rtl::OUString( "PrintReverse" ),
1577 0 : makeAny( bChecked ) );
1578 0 : preparePreview( true, true );
1579 : }
1580 0 : else if( pButton == maNUpPage.mpBorderCB )
1581 : {
1582 0 : updateNup();
1583 : }
1584 : else
1585 : {
1586 0 : if( pButton == maJobPage.mpSetupButton )
1587 : {
1588 0 : maPController->setupPrinter( this );
1589 0 : preparePreview( true, true );
1590 : }
1591 0 : checkControlDependencies();
1592 : }
1593 0 : return 0;
1594 : }
1595 :
1596 0 : IMPL_LINK( PrintDialog, ModifyHdl, Edit*, pEdit )
1597 : {
1598 0 : checkControlDependencies();
1599 0 : if( pEdit == maNUpPage.mpNupRowsEdt || pEdit == maNUpPage.mpNupColEdt ||
1600 : pEdit == maNUpPage.mpSheetMarginEdt || pEdit == maNUpPage.mpPageMarginEdt
1601 : )
1602 : {
1603 0 : updateNupFromPages();
1604 : }
1605 0 : else if( pEdit == mpPageEdit )
1606 : {
1607 0 : mnCurPage = sal_Int32( mpPageEdit->GetValue() - 1 );
1608 0 : preparePreview( true, true );
1609 : }
1610 0 : else if( pEdit == maJobPage.mpCopyCountField )
1611 : {
1612 : maPController->setValue( rtl::OUString( "CopyCount" ),
1613 0 : makeAny( sal_Int32(maJobPage.mpCopyCountField->GetValue()) ) );
1614 : maPController->setValue( rtl::OUString( "Collate" ),
1615 0 : makeAny( sal_Bool(isCollate()) ) );
1616 : }
1617 0 : return 0;
1618 : }
1619 :
1620 0 : IMPL_LINK_NOARG(PrintDialog, UIOptionsChanged)
1621 : {
1622 0 : checkOptionalControlDependencies();
1623 0 : return 0;
1624 : }
1625 :
1626 0 : PropertyValue* PrintDialog::getValueForWindow( Window* i_pWindow ) const
1627 : {
1628 0 : PropertyValue* pVal = NULL;
1629 0 : std::map< Window*, rtl::OUString >::const_iterator it = maControlToPropertyMap.find( i_pWindow );
1630 0 : if( it != maControlToPropertyMap.end() )
1631 : {
1632 0 : pVal = maPController->getValue( it->second );
1633 : DBG_ASSERT( pVal, "property value not found" );
1634 : }
1635 : else
1636 : {
1637 : OSL_FAIL( "changed control not in property map" );
1638 : }
1639 0 : return pVal;
1640 : }
1641 :
1642 0 : void PrintDialog::updateWindowFromProperty( const rtl::OUString& i_rProperty )
1643 : {
1644 0 : beans::PropertyValue* pValue = maPController->getValue( i_rProperty );
1645 0 : std::map< rtl::OUString, std::vector< Window* > >::const_iterator it = maPropertyToWindowMap.find( i_rProperty );
1646 0 : if( pValue && it != maPropertyToWindowMap.end() )
1647 : {
1648 0 : const std::vector< Window* >& rWindows( it->second );
1649 0 : if( ! rWindows.empty() )
1650 : {
1651 0 : sal_Bool bVal = sal_False;
1652 0 : sal_Int32 nVal = -1;
1653 0 : if( pValue->Value >>= bVal )
1654 : {
1655 : // we should have a CheckBox for this one
1656 0 : CheckBox* pBox = dynamic_cast< CheckBox* >( rWindows.front() );
1657 0 : if( pBox )
1658 : {
1659 0 : pBox->Check( bVal );
1660 : }
1661 0 : else if ( i_rProperty == "PrintProspect" )
1662 : {
1663 : // EVIL special case
1664 0 : if( bVal )
1665 0 : maNUpPage.mpBrochureBtn->Check();
1666 : else
1667 0 : maNUpPage.mpPagesBtn->Check();
1668 : }
1669 : else
1670 : {
1671 : DBG_ASSERT( 0, "missing a checkbox" );
1672 : }
1673 : }
1674 0 : else if( pValue->Value >>= nVal )
1675 : {
1676 : // this could be a ListBox or a RadioButtonGroup
1677 0 : ListBox* pList = dynamic_cast< ListBox* >( rWindows.front() );
1678 0 : if( pList )
1679 : {
1680 0 : pList->SelectEntryPos( static_cast< sal_uInt16 >(nVal) );
1681 : }
1682 0 : else if( nVal >= 0 && nVal < sal_Int32(rWindows.size() ) )
1683 : {
1684 0 : RadioButton* pBtn = dynamic_cast< RadioButton* >( rWindows[nVal] );
1685 : DBG_ASSERT( pBtn, "unexpected control for property" );
1686 0 : if( pBtn )
1687 0 : pBtn->Check();
1688 : }
1689 : }
1690 : }
1691 : }
1692 0 : }
1693 :
1694 0 : void PrintDialog::makeEnabled( Window* i_pWindow )
1695 : {
1696 0 : std::map< Window*, rtl::OUString >::const_iterator it = maControlToPropertyMap.find( i_pWindow );
1697 0 : if( it != maControlToPropertyMap.end() )
1698 : {
1699 0 : rtl::OUString aDependency( maPController->makeEnabled( it->second ) );
1700 0 : if( !aDependency.isEmpty() )
1701 0 : updateWindowFromProperty( aDependency );
1702 : }
1703 0 : }
1704 :
1705 0 : IMPL_LINK( PrintDialog, UIOption_CheckHdl, CheckBox*, i_pBox )
1706 : {
1707 0 : PropertyValue* pVal = getValueForWindow( i_pBox );
1708 0 : if( pVal )
1709 : {
1710 0 : makeEnabled( i_pBox );
1711 :
1712 0 : sal_Bool bVal = i_pBox->IsChecked();
1713 0 : pVal->Value <<= bVal;
1714 :
1715 0 : checkOptionalControlDependencies();
1716 :
1717 : // update preview and page settings
1718 0 : preparePreview();
1719 : }
1720 0 : return 0;
1721 : }
1722 :
1723 0 : IMPL_LINK( PrintDialog, UIOption_RadioHdl, RadioButton*, i_pBtn )
1724 : {
1725 : // this handler gets called for all radiobuttons that get unchecked, too
1726 : // however we only want one notificaction for the new value (that is for
1727 : // the button that gets checked)
1728 0 : if( i_pBtn->IsChecked() )
1729 : {
1730 0 : PropertyValue* pVal = getValueForWindow( i_pBtn );
1731 0 : std::map< Window*, sal_Int32 >::const_iterator it = maControlToNumValMap.find( i_pBtn );
1732 0 : if( pVal && it != maControlToNumValMap.end() )
1733 : {
1734 0 : makeEnabled( i_pBtn );
1735 :
1736 0 : sal_Int32 nVal = it->second;
1737 0 : pVal->Value <<= nVal;
1738 :
1739 0 : checkOptionalControlDependencies();
1740 :
1741 : // update preview and page settings
1742 0 : preparePreview();
1743 : }
1744 : }
1745 0 : return 0;
1746 : }
1747 :
1748 0 : IMPL_LINK( PrintDialog, UIOption_SelectHdl, ListBox*, i_pBox )
1749 : {
1750 0 : PropertyValue* pVal = getValueForWindow( i_pBox );
1751 0 : if( pVal )
1752 : {
1753 0 : makeEnabled( i_pBox );
1754 :
1755 0 : sal_Int32 nVal( i_pBox->GetSelectEntryPos() );
1756 0 : pVal->Value <<= nVal;
1757 :
1758 0 : checkOptionalControlDependencies();
1759 :
1760 : // update preview and page settings
1761 0 : preparePreview();
1762 : }
1763 0 : return 0;
1764 : }
1765 :
1766 0 : IMPL_LINK( PrintDialog, UIOption_ModifyHdl, Edit*, i_pBox )
1767 : {
1768 0 : PropertyValue* pVal = getValueForWindow( i_pBox );
1769 0 : if( pVal )
1770 : {
1771 0 : makeEnabled( i_pBox );
1772 :
1773 0 : NumericField* pNum = dynamic_cast<NumericField*>(i_pBox);
1774 0 : MetricField* pMetric = dynamic_cast<MetricField*>(i_pBox);
1775 0 : if( pNum )
1776 : {
1777 0 : sal_Int64 nVal = pNum->GetValue();
1778 0 : pVal->Value <<= nVal;
1779 : }
1780 0 : else if( pMetric )
1781 : {
1782 0 : sal_Int64 nVal = pMetric->GetValue();
1783 0 : pVal->Value <<= nVal;
1784 : }
1785 : else
1786 : {
1787 0 : rtl::OUString aVal( i_pBox->GetText() );
1788 0 : pVal->Value <<= aVal;
1789 : }
1790 :
1791 0 : checkOptionalControlDependencies();
1792 :
1793 : // update preview and page settings
1794 0 : preparePreview();
1795 : }
1796 0 : return 0;
1797 : }
1798 :
1799 0 : void PrintDialog::Command( const CommandEvent& rEvt )
1800 : {
1801 0 : if( rEvt.GetCommand() == COMMAND_WHEEL )
1802 : {
1803 0 : const CommandWheelData* pWheelData = rEvt.GetWheelData();
1804 0 : if( pWheelData->GetDelta() > 0 )
1805 0 : previewForward();
1806 0 : else if( pWheelData->GetDelta() < 0 )
1807 0 : previewBackward();
1808 : }
1809 0 : }
1810 :
1811 0 : void PrintDialog::Resize()
1812 : {
1813 : // maLayout.setManagedArea( Rectangle( Point( 0, 0 ), GetSizePixel() ) );
1814 : // and do the preview; however the metafile does not need to be gotten anew
1815 0 : preparePreview( false );
1816 :
1817 0 : Dialog::Resize();
1818 0 : }
1819 :
1820 0 : void PrintDialog::previewForward()
1821 : {
1822 0 : mpPageEdit->Up();
1823 0 : }
1824 :
1825 0 : void PrintDialog::previewBackward()
1826 : {
1827 0 : mpPageEdit->Down();
1828 0 : }
1829 :
1830 : // -----------------------------------------------------------------------------
1831 : //
1832 : // PrintProgressDialog
1833 : //
1834 : // -----------------------------------------------------------------------------
1835 :
1836 0 : PrintProgressDialog::PrintProgressDialog( Window* i_pParent, int i_nMax ) :
1837 : ModelessDialog( i_pParent, VclResId( SV_DLG_PRINT_PROGRESS ) ),
1838 : maText( this, VclResId( SV_PRINT_PROGRESS_TEXT ) ),
1839 : maButton( this, VclResId( SV_PRINT_PROGRESS_CANCEL ) ),
1840 : mbCanceled( false ),
1841 : mnCur( 0 ),
1842 : mnMax( i_nMax ),
1843 : mnProgressHeight( 15 ),
1844 0 : mbNativeProgress( false )
1845 : {
1846 0 : FreeResource();
1847 :
1848 0 : if( mnMax < 1 )
1849 0 : mnMax = 1;
1850 :
1851 0 : maStr = maText.GetText();
1852 :
1853 0 : maButton.SetClickHdl( LINK( this, PrintProgressDialog, ClickHdl ) );
1854 :
1855 0 : }
1856 :
1857 0 : PrintProgressDialog::~PrintProgressDialog()
1858 : {
1859 0 : }
1860 :
1861 0 : IMPL_LINK( PrintProgressDialog, ClickHdl, Button*, pButton )
1862 : {
1863 0 : if( pButton == &maButton )
1864 0 : mbCanceled = true;
1865 :
1866 0 : return 0;
1867 : }
1868 :
1869 0 : void PrintProgressDialog::implCalcProgressRect()
1870 : {
1871 0 : if( IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) )
1872 : {
1873 0 : ImplControlValue aValue;
1874 0 : Rectangle aControlRegion( Point(), Size( 100, mnProgressHeight ) );
1875 0 : Rectangle aNativeControlRegion, aNativeContentRegion;
1876 0 : if( GetNativeControlRegion( CTRL_PROGRESS, PART_ENTIRE_CONTROL, aControlRegion,
1877 : CTRL_STATE_ENABLED, aValue, rtl::OUString(),
1878 0 : aNativeControlRegion, aNativeContentRegion ) )
1879 : {
1880 0 : mnProgressHeight = aNativeControlRegion.GetHeight();
1881 : }
1882 0 : mbNativeProgress = true;
1883 : }
1884 0 : maProgressRect = Rectangle( Point( 10, maText.GetPosPixel().Y() + maText.GetSizePixel().Height() + 8 ),
1885 0 : Size( GetSizePixel().Width() - 20, mnProgressHeight ) );
1886 0 : }
1887 :
1888 0 : void PrintProgressDialog::setProgress( int i_nCurrent, int i_nMax )
1889 : {
1890 0 : if( maProgressRect.IsEmpty() )
1891 0 : implCalcProgressRect();
1892 :
1893 0 : mnCur = i_nCurrent;
1894 0 : if( i_nMax != -1 )
1895 0 : mnMax = i_nMax;
1896 :
1897 0 : if( mnMax < 1 )
1898 0 : mnMax = 1;
1899 :
1900 0 : rtl::OUString aNewText( searchAndReplace( maStr, "%p", 2, rtl::OUString::valueOf( mnCur ) ) );
1901 0 : aNewText = searchAndReplace( aNewText, "%n", 2, rtl::OUString::valueOf( mnMax ) );
1902 0 : maText.SetText( aNewText );
1903 :
1904 : // update progress
1905 0 : Invalidate( maProgressRect, INVALIDATE_UPDATE );
1906 0 : }
1907 :
1908 0 : void PrintProgressDialog::tick()
1909 : {
1910 0 : if( mnCur < mnMax )
1911 0 : setProgress( ++mnCur );
1912 0 : }
1913 :
1914 0 : void PrintProgressDialog::reset()
1915 : {
1916 0 : mbCanceled = false;
1917 0 : setProgress( 0 );
1918 0 : }
1919 :
1920 0 : void PrintProgressDialog::Paint( const Rectangle& )
1921 : {
1922 0 : if( maProgressRect.IsEmpty() )
1923 0 : implCalcProgressRect();
1924 :
1925 0 : Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
1926 0 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1927 0 : Color aPrgsColor = rStyleSettings.GetHighlightColor();
1928 0 : if ( aPrgsColor == rStyleSettings.GetFaceColor() )
1929 0 : aPrgsColor = rStyleSettings.GetDarkShadowColor();
1930 0 : SetLineColor();
1931 0 : SetFillColor( aPrgsColor );
1932 :
1933 0 : const long nOffset = 3;
1934 0 : const long nWidth = 3*mnProgressHeight/2;
1935 0 : const long nFullWidth = nWidth + nOffset;
1936 0 : const long nMaxCount = maProgressRect.GetWidth() / nFullWidth;
1937 0 : DrawProgress( this, maProgressRect.TopLeft(),
1938 : nOffset,
1939 : nWidth,
1940 : mnProgressHeight,
1941 : static_cast<sal_uInt16>(0),
1942 : static_cast<sal_uInt16>(10000*mnCur/mnMax),
1943 : static_cast<sal_uInt16>(10000/nMaxCount),
1944 : maProgressRect
1945 0 : );
1946 0 : Pop();
1947 :
1948 0 : if( ! mbNativeProgress )
1949 : {
1950 0 : DecorationView aDecoView( this );
1951 0 : Rectangle aFrameRect( maProgressRect );
1952 0 : aFrameRect.Left() -= nOffset;
1953 0 : aFrameRect.Right() += nOffset;
1954 0 : aFrameRect.Top() -= nOffset;
1955 0 : aFrameRect.Bottom() += nOffset;
1956 0 : aDecoView.DrawFrame( aFrameRect );
1957 : }
1958 318 : }
1959 :
1960 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|