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