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