xref: /AOO41X/main/vcl/source/window/printdlg.cxx (revision 0dccdc5d37eabe0993ebf77c7d2d73a82d9fad9c)
1cdf0e10cSrcweir /*************************************************************************
2cdf0e10cSrcweir  *
3cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4cdf0e10cSrcweir  *
5cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6cdf0e10cSrcweir  *
7cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8cdf0e10cSrcweir  *
9cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10cdf0e10cSrcweir  *
11cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14cdf0e10cSrcweir  *
15cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20cdf0e10cSrcweir  *
21cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25cdf0e10cSrcweir  *
26cdf0e10cSrcweir  ************************************************************************/
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "precompiled_vcl.hxx"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include "printdlg.hxx"
31cdf0e10cSrcweir #include "svdata.hxx"
32cdf0e10cSrcweir #include "svids.hrc"
33cdf0e10cSrcweir #include "jobset.h"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include "vcl/print.hxx"
36cdf0e10cSrcweir #include "vcl/dialog.hxx"
37cdf0e10cSrcweir #include "vcl/button.hxx"
38cdf0e10cSrcweir #include "vcl/wall.hxx"
39cdf0e10cSrcweir #include "vcl/status.hxx"
40cdf0e10cSrcweir #include "vcl/decoview.hxx"
41cdf0e10cSrcweir #include "vcl/arrange.hxx"
42cdf0e10cSrcweir #include "vcl/configsettings.hxx"
43cdf0e10cSrcweir #include "vcl/help.hxx"
44cdf0e10cSrcweir #include "vcl/decoview.hxx"
45cdf0e10cSrcweir #include "vcl/svapp.hxx"
46cdf0e10cSrcweir #include "vcl/unohelp.hxx"
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #include "unotools/localedatawrapper.hxx"
49cdf0e10cSrcweir 
50cdf0e10cSrcweir #include "rtl/strbuf.hxx"
51cdf0e10cSrcweir 
52cdf0e10cSrcweir #include "com/sun/star/lang/XMultiServiceFactory.hpp"
53cdf0e10cSrcweir #include "com/sun/star/container/XNameAccess.hpp"
54cdf0e10cSrcweir #include "com/sun/star/beans/PropertyValue.hpp"
55cdf0e10cSrcweir #include "com/sun/star/awt/Size.hpp"
56cdf0e10cSrcweir 
57cdf0e10cSrcweir using namespace vcl;
58cdf0e10cSrcweir using namespace com::sun::star;
59cdf0e10cSrcweir using namespace com::sun::star::uno;
60cdf0e10cSrcweir using namespace com::sun::star::lang;
61cdf0e10cSrcweir using namespace com::sun::star::container;
62cdf0e10cSrcweir using namespace com::sun::star::beans;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir PrintDialog::PrintPreviewWindow::PrintPreviewWindow( Window* i_pParent, const ResId& i_rId )
65cdf0e10cSrcweir     : Window( i_pParent, i_rId )
66cdf0e10cSrcweir     , maOrigSize( 10, 10 )
67cdf0e10cSrcweir     , maPageVDev( *this )
68cdf0e10cSrcweir     , maToolTipString( String( VclResId( SV_PRINT_PRINTPREVIEW_TXT ) ) )
69cdf0e10cSrcweir     , mbGreyscale( false )
70cdf0e10cSrcweir     , maHorzDim( this, WB_HORZ | WB_CENTER  )
71cdf0e10cSrcweir     , maVertDim( this, WB_VERT | WB_VCENTER )
72cdf0e10cSrcweir {
73cdf0e10cSrcweir     SetPaintTransparent( sal_True );
74cdf0e10cSrcweir     SetBackground();
75cdf0e10cSrcweir     if( useHCColorReplacement() )
76cdf0e10cSrcweir         maPageVDev.SetBackground( GetSettings().GetStyleSettings().GetWindowColor() );
77cdf0e10cSrcweir     else
78cdf0e10cSrcweir         maPageVDev.SetBackground( Color( COL_WHITE ) );
79cdf0e10cSrcweir     maHorzDim.Show();
80cdf0e10cSrcweir     maVertDim.Show();
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     maHorzDim.SetText( String( RTL_CONSTASCII_USTRINGPARAM( "2.0in" ) ) );
83cdf0e10cSrcweir     maVertDim.SetText( String( RTL_CONSTASCII_USTRINGPARAM( "2.0in" ) ) );
84cdf0e10cSrcweir }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir PrintDialog::PrintPreviewWindow::~PrintPreviewWindow()
87cdf0e10cSrcweir {
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
90cdf0e10cSrcweir bool PrintDialog::PrintPreviewWindow::useHCColorReplacement() const
91cdf0e10cSrcweir {
92cdf0e10cSrcweir     bool bRet = false;
93cdf0e10cSrcweir     if( GetSettings().GetStyleSettings().GetHighContrastMode() )
94cdf0e10cSrcweir     {
95cdf0e10cSrcweir         try
96cdf0e10cSrcweir         {
97cdf0e10cSrcweir             // get service provider
98cdf0e10cSrcweir             Reference< XMultiServiceFactory > xSMgr( unohelper::GetMultiServiceFactory() );
99cdf0e10cSrcweir             // create configuration hierachical access name
100cdf0e10cSrcweir             if( xSMgr.is() )
101cdf0e10cSrcweir             {
102cdf0e10cSrcweir                 try
103cdf0e10cSrcweir                 {
104cdf0e10cSrcweir                     Reference< XMultiServiceFactory > xConfigProvider(
105cdf0e10cSrcweir                         Reference< XMultiServiceFactory >(
106cdf0e10cSrcweir                             xSMgr->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
107cdf0e10cSrcweir                                             "com.sun.star.configuration.ConfigurationProvider" ))),
108cdf0e10cSrcweir                             UNO_QUERY )
109cdf0e10cSrcweir                         );
110cdf0e10cSrcweir                     if( xConfigProvider.is() )
111cdf0e10cSrcweir                     {
112cdf0e10cSrcweir                         Sequence< Any > aArgs(1);
113cdf0e10cSrcweir                         PropertyValue aVal;
114cdf0e10cSrcweir                         aVal.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) );
115cdf0e10cSrcweir                         aVal.Value <<= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common/Accessibility" ) );
116cdf0e10cSrcweir                         aArgs.getArray()[0] <<= aVal;
117cdf0e10cSrcweir                         Reference< XNameAccess > xConfigAccess(
118cdf0e10cSrcweir                             Reference< XNameAccess >(
119cdf0e10cSrcweir                                 xConfigProvider->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
120cdf0e10cSrcweir                                                     "com.sun.star.configuration.ConfigurationAccess" )),
121cdf0e10cSrcweir                                                                                 aArgs ),
122cdf0e10cSrcweir                                 UNO_QUERY )
123cdf0e10cSrcweir                             );
124cdf0e10cSrcweir                         if( xConfigAccess.is() )
125cdf0e10cSrcweir                         {
126cdf0e10cSrcweir                             try
127cdf0e10cSrcweir                             {
128cdf0e10cSrcweir                                 sal_Bool bValue = sal_False;
129cdf0e10cSrcweir                                 Any aAny = xConfigAccess->getByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsForPagePreviews" ) ) );
130cdf0e10cSrcweir                                 if( aAny >>= bValue )
131cdf0e10cSrcweir                                     bRet = bool(bValue);
132cdf0e10cSrcweir                             }
133cdf0e10cSrcweir                             catch( NoSuchElementException& )
134cdf0e10cSrcweir                             {
135cdf0e10cSrcweir                             }
136cdf0e10cSrcweir                             catch( WrappedTargetException& )
137cdf0e10cSrcweir                             {
138cdf0e10cSrcweir                             }
139cdf0e10cSrcweir                         }
140cdf0e10cSrcweir                     }
141cdf0e10cSrcweir                 }
142cdf0e10cSrcweir                 catch( Exception& )
143cdf0e10cSrcweir                 {
144cdf0e10cSrcweir                 }
145cdf0e10cSrcweir             }
146cdf0e10cSrcweir         }
147cdf0e10cSrcweir         catch( WrappedTargetException& )
148cdf0e10cSrcweir         {
149cdf0e10cSrcweir         }
150cdf0e10cSrcweir     }
151cdf0e10cSrcweir     return bRet;
152cdf0e10cSrcweir }
153cdf0e10cSrcweir 
154cdf0e10cSrcweir void PrintDialog::PrintPreviewWindow::DataChanged( const DataChangedEvent& i_rDCEvt )
155cdf0e10cSrcweir {
156cdf0e10cSrcweir     // react on settings changed
157cdf0e10cSrcweir     if( i_rDCEvt.GetType() == DATACHANGED_SETTINGS )
158cdf0e10cSrcweir     {
159cdf0e10cSrcweir         if( useHCColorReplacement() )
160cdf0e10cSrcweir             maPageVDev.SetBackground( GetSettings().GetStyleSettings().GetWindowColor() );
161cdf0e10cSrcweir         else
162cdf0e10cSrcweir             maPageVDev.SetBackground( Color( COL_WHITE ) );
163cdf0e10cSrcweir     }
164cdf0e10cSrcweir     Window::DataChanged( i_rDCEvt );
165cdf0e10cSrcweir }
166cdf0e10cSrcweir 
167cdf0e10cSrcweir void PrintDialog::PrintPreviewWindow::Resize()
168cdf0e10cSrcweir {
169cdf0e10cSrcweir     Size aNewSize( GetSizePixel() );
170cdf0e10cSrcweir     long nTextHeight = maHorzDim.GetTextHeight();
171cdf0e10cSrcweir     // leave small space for decoration
172cdf0e10cSrcweir     aNewSize.Width() -= nTextHeight + 2;
173cdf0e10cSrcweir     aNewSize.Height() -= nTextHeight + 2;
174cdf0e10cSrcweir     Size aScaledSize;
175cdf0e10cSrcweir     double fScale = 1.0;
176cdf0e10cSrcweir 
177cdf0e10cSrcweir     // #i106435# catch corner case of Size(0,0)
178cdf0e10cSrcweir     Size aOrigSize( maOrigSize );
179cdf0e10cSrcweir     if( aOrigSize.Width() < 1 )
180cdf0e10cSrcweir         aOrigSize.Width() = aNewSize.Width();
181cdf0e10cSrcweir     if( aOrigSize.Height() < 1 )
182cdf0e10cSrcweir         aOrigSize.Height() = aNewSize.Height();
183cdf0e10cSrcweir     if( aOrigSize.Width() > aOrigSize.Height() )
184cdf0e10cSrcweir     {
185cdf0e10cSrcweir         aScaledSize = Size( aNewSize.Width(), aNewSize.Width() * aOrigSize.Height() / aOrigSize.Width() );
186cdf0e10cSrcweir         if( aScaledSize.Height() > aNewSize.Height() )
187cdf0e10cSrcweir             fScale = double(aNewSize.Height())/double(aScaledSize.Height());
188cdf0e10cSrcweir     }
189cdf0e10cSrcweir     else
190cdf0e10cSrcweir     {
191cdf0e10cSrcweir         aScaledSize = Size( aNewSize.Height() * aOrigSize.Width() / aOrigSize.Height(), aNewSize.Height() );
192cdf0e10cSrcweir         if( aScaledSize.Width() > aNewSize.Width() )
193cdf0e10cSrcweir             fScale = double(aNewSize.Width())/double(aScaledSize.Width());
194cdf0e10cSrcweir     }
195cdf0e10cSrcweir     aScaledSize.Width() = long(aScaledSize.Width()*fScale);
196cdf0e10cSrcweir     aScaledSize.Height() = long(aScaledSize.Height()*fScale);
197cdf0e10cSrcweir 
198cdf0e10cSrcweir     maPreviewSize = aScaledSize;
199cdf0e10cSrcweir 
200cdf0e10cSrcweir     // #i104784# if we render the page too small then rounding issues result in
201cdf0e10cSrcweir     // layout artifacts looking really bad. So scale the page unto a device that is not
202cdf0e10cSrcweir     // full page size but not too small either. This also results in much better visual
203cdf0e10cSrcweir     // quality of the preview, e.g. when its height approaches the number of text lines
204cdf0e10cSrcweir     // find a good scaling factor
205cdf0e10cSrcweir     Size aPreviewMMSize( maPageVDev.PixelToLogic( aScaledSize, MapMode( MAP_100TH_MM ) ) );
206cdf0e10cSrcweir     double fZoom = double(maOrigSize.Height())/double(aPreviewMMSize.Height());
207cdf0e10cSrcweir     while( fZoom > 10 )
208cdf0e10cSrcweir     {
209cdf0e10cSrcweir         aScaledSize.Width() *= 2;
210cdf0e10cSrcweir         aScaledSize.Height() *= 2;
211cdf0e10cSrcweir         fZoom /= 2.0;
212cdf0e10cSrcweir     }
213cdf0e10cSrcweir 
214cdf0e10cSrcweir     maPageVDev.SetOutputSizePixel( aScaledSize, sal_False );
215cdf0e10cSrcweir 
216cdf0e10cSrcweir     // position dimension lines
217cdf0e10cSrcweir     Point aRef( nTextHeight + (aNewSize.Width() - maPreviewSize.Width())/2,
218cdf0e10cSrcweir                 nTextHeight + (aNewSize.Height() - maPreviewSize.Height())/2 );
219cdf0e10cSrcweir     maHorzDim.SetPosSizePixel( Point( aRef.X(), aRef.Y() - nTextHeight ),
220cdf0e10cSrcweir                                Size( maPreviewSize.Width(), nTextHeight ) );
221cdf0e10cSrcweir     maVertDim.SetPosSizePixel( Point( aRef.X() - nTextHeight, aRef.Y() ),
222cdf0e10cSrcweir                                Size( nTextHeight, maPreviewSize.Height() ) );
223cdf0e10cSrcweir 
224cdf0e10cSrcweir }
225cdf0e10cSrcweir 
226cdf0e10cSrcweir void PrintDialog::PrintPreviewWindow::Paint( const Rectangle& )
227cdf0e10cSrcweir {
228cdf0e10cSrcweir     long nTextHeight = maHorzDim.GetTextHeight();
229cdf0e10cSrcweir     Size aSize( GetSizePixel() );
230cdf0e10cSrcweir     aSize.Width()  -= nTextHeight;
231cdf0e10cSrcweir     aSize.Height() -= nTextHeight;
232cdf0e10cSrcweir     if( maReplacementString.getLength() != 0 )
233cdf0e10cSrcweir     {
234cdf0e10cSrcweir         // replacement is active
235cdf0e10cSrcweir         Push();
236cdf0e10cSrcweir         Rectangle aTextRect( Point( nTextHeight, nTextHeight ), aSize );
237cdf0e10cSrcweir         DecorationView aVw( this );
238cdf0e10cSrcweir         aVw.DrawFrame( aTextRect, FRAME_DRAW_GROUP );
239cdf0e10cSrcweir         aTextRect.Left()   += 2;
240cdf0e10cSrcweir         aTextRect.Top()    += 2;
241cdf0e10cSrcweir         aTextRect.Right()  -= 2;
242cdf0e10cSrcweir         aTextRect.Bottom() -= 2;
243cdf0e10cSrcweir         Font aFont( GetSettings().GetStyleSettings().GetLabelFont() );
244cdf0e10cSrcweir         SetZoomedPointFont( aFont );
245cdf0e10cSrcweir         DrawText( aTextRect, maReplacementString,
246cdf0e10cSrcweir                   TEXT_DRAW_CENTER | TEXT_DRAW_VCENTER | TEXT_DRAW_WORDBREAK | TEXT_DRAW_MULTILINE
247cdf0e10cSrcweir                  );
248cdf0e10cSrcweir         Pop();
249cdf0e10cSrcweir     }
250cdf0e10cSrcweir     else
251cdf0e10cSrcweir     {
252cdf0e10cSrcweir         GDIMetaFile aMtf( maMtf );
253cdf0e10cSrcweir 
254cdf0e10cSrcweir         Point aOffset( (aSize.Width() - maPreviewSize.Width()) / 2 + nTextHeight,
255cdf0e10cSrcweir                        (aSize.Height() - maPreviewSize.Height()) / 2 + nTextHeight );
256cdf0e10cSrcweir 
257cdf0e10cSrcweir         Size aVDevSize( maPageVDev.GetOutputSizePixel() );
258cdf0e10cSrcweir         const Size aLogicSize( maPageVDev.PixelToLogic( aVDevSize, MapMode( MAP_100TH_MM ) ) );
259cdf0e10cSrcweir         Size aOrigSize( maOrigSize );
260cdf0e10cSrcweir         if( aOrigSize.Width() < 1 )
261cdf0e10cSrcweir             aOrigSize.Width() = aLogicSize.Width();
262cdf0e10cSrcweir         if( aOrigSize.Height() < 1 )
263cdf0e10cSrcweir             aOrigSize.Height() = aLogicSize.Height();
264cdf0e10cSrcweir         double fScale = double(aLogicSize.Width())/double(aOrigSize.Width());
265cdf0e10cSrcweir 
266cdf0e10cSrcweir 
267cdf0e10cSrcweir         maPageVDev.Erase();
268cdf0e10cSrcweir         maPageVDev.Push();
269cdf0e10cSrcweir         maPageVDev.SetMapMode( MAP_100TH_MM );
270cdf0e10cSrcweir         sal_uLong nOldDrawMode = maPageVDev.GetDrawMode();
271cdf0e10cSrcweir         if( mbGreyscale )
272cdf0e10cSrcweir             maPageVDev.SetDrawMode( maPageVDev.GetDrawMode() |
273cdf0e10cSrcweir                                     ( DRAWMODE_GRAYLINE | DRAWMODE_GRAYFILL | DRAWMODE_GRAYTEXT |
274cdf0e10cSrcweir                                       DRAWMODE_GRAYBITMAP | DRAWMODE_GRAYGRADIENT ) );
275cdf0e10cSrcweir         aMtf.WindStart();
276cdf0e10cSrcweir         aMtf.Scale( fScale, fScale );
277cdf0e10cSrcweir         aMtf.WindStart();
278cdf0e10cSrcweir         aMtf.Play( &maPageVDev, Point( 0, 0 ), aLogicSize );
279cdf0e10cSrcweir         maPageVDev.Pop();
280cdf0e10cSrcweir 
281cdf0e10cSrcweir         SetMapMode( MAP_PIXEL );
282cdf0e10cSrcweir         maPageVDev.SetMapMode( MAP_PIXEL );
283cdf0e10cSrcweir         DrawOutDev( aOffset, maPreviewSize, Point( 0, 0 ), aVDevSize, maPageVDev );
284cdf0e10cSrcweir         maPageVDev.SetDrawMode( nOldDrawMode );
285cdf0e10cSrcweir 
286cdf0e10cSrcweir         DecorationView aVw( this );
287cdf0e10cSrcweir         Rectangle aFrame( aOffset + Point( -1, -1 ), Size( maPreviewSize.Width() + 2, maPreviewSize.Height() + 2 ) );
288cdf0e10cSrcweir         aVw.DrawFrame( aFrame, FRAME_DRAW_GROUP );
289cdf0e10cSrcweir     }
290cdf0e10cSrcweir }
291cdf0e10cSrcweir 
292cdf0e10cSrcweir void PrintDialog::PrintPreviewWindow::Command( const CommandEvent& rEvt )
293cdf0e10cSrcweir {
294cdf0e10cSrcweir     if( rEvt.GetCommand() == COMMAND_WHEEL )
295cdf0e10cSrcweir     {
296cdf0e10cSrcweir         const CommandWheelData* pWheelData = rEvt.GetWheelData();
297cdf0e10cSrcweir         PrintDialog* pDlg = dynamic_cast<PrintDialog*>(GetParent());
298cdf0e10cSrcweir         if( pDlg )
299cdf0e10cSrcweir         {
300cdf0e10cSrcweir             if( pWheelData->GetDelta() > 0 )
301cdf0e10cSrcweir                 pDlg->previewForward();
302cdf0e10cSrcweir             else if( pWheelData->GetDelta() < 0 )
303cdf0e10cSrcweir                 pDlg->previewBackward();
304cdf0e10cSrcweir             /*
305cdf0e10cSrcweir             else
306cdf0e10cSrcweir                 huh ?
307cdf0e10cSrcweir             */
308cdf0e10cSrcweir         }
309cdf0e10cSrcweir     }
310cdf0e10cSrcweir }
311cdf0e10cSrcweir 
312cdf0e10cSrcweir void PrintDialog::PrintPreviewWindow::setPreview( const GDIMetaFile& i_rNewPreview,
313cdf0e10cSrcweir                                                   const Size& i_rOrigSize,
314cdf0e10cSrcweir                                                   const rtl::OUString& i_rPaperName,
315cdf0e10cSrcweir                                                   const rtl::OUString& i_rReplacement,
316cdf0e10cSrcweir                                                   sal_Int32 i_nDPIX,
317cdf0e10cSrcweir                                                   sal_Int32 i_nDPIY,
318cdf0e10cSrcweir                                                   bool i_bGreyscale
319cdf0e10cSrcweir                                                  )
320cdf0e10cSrcweir {
321cdf0e10cSrcweir     rtl::OUStringBuffer aBuf( 256 );
322cdf0e10cSrcweir     aBuf.append( maToolTipString );
323cdf0e10cSrcweir     SetQuickHelpText( aBuf.makeStringAndClear() );
324cdf0e10cSrcweir     maMtf = i_rNewPreview;
325cdf0e10cSrcweir     if( useHCColorReplacement() )
326cdf0e10cSrcweir     {
327cdf0e10cSrcweir         maMtf.ReplaceColors( Color( COL_BLACK ), Color( COL_WHITE ), 30 );
328cdf0e10cSrcweir     }
329cdf0e10cSrcweir 
330cdf0e10cSrcweir     maOrigSize = i_rOrigSize;
331cdf0e10cSrcweir     maReplacementString = i_rReplacement;
332cdf0e10cSrcweir     mbGreyscale = i_bGreyscale;
333cdf0e10cSrcweir     maPageVDev.SetReferenceDevice( i_nDPIX, i_nDPIY );
334cdf0e10cSrcweir     maPageVDev.EnableOutput( sal_True );
335cdf0e10cSrcweir 
336cdf0e10cSrcweir     // use correct measurements
337cdf0e10cSrcweir     const LocaleDataWrapper& rLocWrap( GetSettings().GetLocaleDataWrapper() );
338cdf0e10cSrcweir     MapUnit eUnit = MAP_MM;
339cdf0e10cSrcweir     int nDigits = 0;
340cdf0e10cSrcweir     if( rLocWrap.getMeasurementSystemEnum() == MEASURE_US )
341cdf0e10cSrcweir     {
342cdf0e10cSrcweir         eUnit = MAP_100TH_INCH;
343cdf0e10cSrcweir         nDigits = 2;
344cdf0e10cSrcweir     }
345cdf0e10cSrcweir     Size aLogicPaperSize( LogicToLogic( i_rOrigSize, MapMode( MAP_100TH_MM ), MapMode( eUnit ) ) );
346cdf0e10cSrcweir     String aNumText( rLocWrap.getNum( aLogicPaperSize.Width(), nDigits ) );
347cdf0e10cSrcweir     aBuf.append( aNumText );
348cdf0e10cSrcweir     aBuf.appendAscii( eUnit == MAP_MM ? "mm" : "in" );
349cdf0e10cSrcweir     if( i_rPaperName.getLength() )
350cdf0e10cSrcweir     {
351cdf0e10cSrcweir         aBuf.appendAscii( " (" );
352cdf0e10cSrcweir         aBuf.append( i_rPaperName );
353cdf0e10cSrcweir         aBuf.append( sal_Unicode(')') );
354cdf0e10cSrcweir     }
355cdf0e10cSrcweir     maHorzDim.SetText( aBuf.makeStringAndClear() );
356cdf0e10cSrcweir 
357cdf0e10cSrcweir     aNumText = rLocWrap.getNum( aLogicPaperSize.Height(), nDigits );
358cdf0e10cSrcweir     aBuf.append( aNumText );
359cdf0e10cSrcweir     aBuf.appendAscii( eUnit == MAP_MM ? "mm" : "in" );
360cdf0e10cSrcweir     maVertDim.SetText( aBuf.makeStringAndClear() );
361cdf0e10cSrcweir 
362cdf0e10cSrcweir     Resize();
363cdf0e10cSrcweir     Invalidate();
364cdf0e10cSrcweir }
365cdf0e10cSrcweir 
366cdf0e10cSrcweir PrintDialog::ShowNupOrderWindow::ShowNupOrderWindow( Window* i_pParent )
367cdf0e10cSrcweir     : Window( i_pParent, WB_NOBORDER )
368cdf0e10cSrcweir     , mnOrderMode( 0 )
369cdf0e10cSrcweir     , mnRows( 1 )
370cdf0e10cSrcweir     , mnColumns( 1 )
371cdf0e10cSrcweir {
372cdf0e10cSrcweir     ImplInitSettings();
373cdf0e10cSrcweir }
374cdf0e10cSrcweir 
375cdf0e10cSrcweir PrintDialog::ShowNupOrderWindow::~ShowNupOrderWindow()
376cdf0e10cSrcweir {
377cdf0e10cSrcweir }
378cdf0e10cSrcweir 
379cdf0e10cSrcweir void PrintDialog::ShowNupOrderWindow::ImplInitSettings()
380cdf0e10cSrcweir {
381cdf0e10cSrcweir     SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetFieldColor() ) );
382cdf0e10cSrcweir }
383cdf0e10cSrcweir 
384cdf0e10cSrcweir void PrintDialog::ShowNupOrderWindow::Paint( const Rectangle& i_rRect )
385cdf0e10cSrcweir {
386cdf0e10cSrcweir     Window::Paint( i_rRect );
387cdf0e10cSrcweir     SetMapMode( MAP_PIXEL );
388cdf0e10cSrcweir     SetTextColor( GetSettings().GetStyleSettings().GetFieldTextColor() );
389cdf0e10cSrcweir 
390cdf0e10cSrcweir     int nPages = mnRows * mnColumns;
391cdf0e10cSrcweir     Font aFont( GetSettings().GetStyleSettings().GetFieldFont() );
392cdf0e10cSrcweir     aFont.SetSize( Size( 0, 24 ) );
393cdf0e10cSrcweir     SetFont( aFont );
394cdf0e10cSrcweir     Size aSampleTextSize( GetTextWidth( rtl::OUString::valueOf( sal_Int32(nPages+1) ) ), GetTextHeight() );
395cdf0e10cSrcweir 
396cdf0e10cSrcweir     Size aOutSize( GetOutputSizePixel() );
397cdf0e10cSrcweir     Size aSubSize( aOutSize.Width() / mnColumns, aOutSize.Height() / mnRows );
398cdf0e10cSrcweir     // calculate font size: shrink the sample text so it fits
399cdf0e10cSrcweir     double fX = double(aSubSize.Width())/double(aSampleTextSize.Width());
400cdf0e10cSrcweir     double fY = double(aSubSize.Height())/double(aSampleTextSize.Height());
401cdf0e10cSrcweir     double fScale = (fX < fY) ? fX : fY;
402cdf0e10cSrcweir     long nFontHeight = long(24.0*fScale) - 3;
403cdf0e10cSrcweir     if( nFontHeight < 5 )
404cdf0e10cSrcweir         nFontHeight = 5;
405cdf0e10cSrcweir     aFont.SetSize( Size( 0, nFontHeight ) );
406cdf0e10cSrcweir     SetFont( aFont );
407cdf0e10cSrcweir     long nTextHeight = GetTextHeight();
408cdf0e10cSrcweir     for( int i = 0; i < nPages; i++ )
409cdf0e10cSrcweir     {
410cdf0e10cSrcweir         rtl::OUString aPageText( rtl::OUString::valueOf( sal_Int32(i+1) ) );
411cdf0e10cSrcweir         int nX = 0, nY = 0;
412cdf0e10cSrcweir         switch( mnOrderMode )
413cdf0e10cSrcweir         {
414cdf0e10cSrcweir         case SV_PRINT_PRT_NUP_ORDER_LRTB:
415cdf0e10cSrcweir             nX = (i % mnColumns); nY = (i / mnColumns);
416cdf0e10cSrcweir             break;
417cdf0e10cSrcweir         case SV_PRINT_PRT_NUP_ORDER_TBLR:
418cdf0e10cSrcweir             nX = (i / mnRows); nY = (i % mnRows);
419cdf0e10cSrcweir             break;
420cdf0e10cSrcweir         case SV_PRINT_PRT_NUP_ORDER_RLTB:
421cdf0e10cSrcweir             nX = mnColumns - 1 - (i % mnColumns); nY = (i / mnColumns);
422cdf0e10cSrcweir             break;
423cdf0e10cSrcweir         case SV_PRINT_PRT_NUP_ORDER_TBRL:
424cdf0e10cSrcweir             nX = mnColumns - 1 - (i / mnRows); nY = (i % mnRows);
425cdf0e10cSrcweir             break;
426cdf0e10cSrcweir         }
427cdf0e10cSrcweir         Size aTextSize( GetTextWidth( aPageText ), nTextHeight );
428cdf0e10cSrcweir         int nDeltaX = (aSubSize.Width() - aTextSize.Width()) / 2;
429cdf0e10cSrcweir         int nDeltaY = (aSubSize.Height() - aTextSize.Height()) / 2;
430cdf0e10cSrcweir         DrawText( Point( nX * aSubSize.Width() + nDeltaX,
431cdf0e10cSrcweir                          nY * aSubSize.Height() + nDeltaY ),
432cdf0e10cSrcweir                   aPageText );
433cdf0e10cSrcweir     }
434cdf0e10cSrcweir     DecorationView aVw( this );
435cdf0e10cSrcweir     aVw.DrawFrame( Rectangle( Point( 0, 0), aOutSize ), FRAME_DRAW_GROUP );
436cdf0e10cSrcweir }
437cdf0e10cSrcweir 
438cdf0e10cSrcweir PrintDialog::NUpTabPage::NUpTabPage( Window* i_pParent, const ResId& rResId )
439cdf0e10cSrcweir     : TabPage( i_pParent, rResId )
440cdf0e10cSrcweir     , maNupLine( this, VclResId( SV_PRINT_PRT_NUP_LAYOUT_FL ) )
441cdf0e10cSrcweir     , maPagesBtn( this, VclResId( SV_PRINT_PRT_NUP_PAGES_BTN ) )
442cdf0e10cSrcweir     , maBrochureBtn( this, VclResId( SV_PRINT_PRT_NUP_BROCHURE_BTN ) )
443cdf0e10cSrcweir     , maPagesBoxTitleTxt( this, 0 )
444cdf0e10cSrcweir     , maNupPagesBox( this, VclResId( SV_PRINT_PRT_NUP_PAGES_BOX ) )
445cdf0e10cSrcweir     , maNupNumPagesTxt( this, VclResId( SV_PRINT_PRT_NUP_NUM_PAGES_TXT ) )
446cdf0e10cSrcweir     , maNupColEdt( this, VclResId( SV_PRINT_PRT_NUP_COLS_EDT ) )
447cdf0e10cSrcweir     , maNupTimesTxt( this, VclResId( SV_PRINT_PRT_NUP_TIMES_TXT ) )
448cdf0e10cSrcweir     , maNupRowsEdt( this, VclResId( SV_PRINT_PRT_NUP_ROWS_EDT ) )
449cdf0e10cSrcweir     , maPageMarginTxt1( this, VclResId( SV_PRINT_PRT_NUP_MARGINS_PAGES_1_TXT ) )
450cdf0e10cSrcweir     , maPageMarginEdt( this, VclResId( SV_PRINT_PRT_NUP_MARGINS_PAGES_EDT ) )
451cdf0e10cSrcweir     , maPageMarginTxt2( this, VclResId( SV_PRINT_PRT_NUP_MARGINS_PAGES_2_TXT ) )
452cdf0e10cSrcweir     , maSheetMarginTxt1( this, VclResId( SV_PRINT_PRT_NUP_MARGINS_SHEET_1_TXT ) )
453cdf0e10cSrcweir     , maSheetMarginEdt( this, VclResId( SV_PRINT_PRT_NUP_MARGINS_SHEET_EDT ) )
454cdf0e10cSrcweir     , maSheetMarginTxt2( this, VclResId( SV_PRINT_PRT_NUP_MARGINS_SHEET_2_TXT ) )
455cdf0e10cSrcweir     , maNupOrientationTxt( this, VclResId( SV_PRINT_PRT_NUP_ORIENTATION_TXT ) )
456cdf0e10cSrcweir     , maNupOrientationBox( this, VclResId( SV_PRINT_PRT_NUP_ORIENTATION_BOX ) )
457cdf0e10cSrcweir     , maNupOrderTxt( this, VclResId( SV_PRINT_PRT_NUP_ORDER_TXT ) )
458cdf0e10cSrcweir     , maNupOrderBox( this, VclResId( SV_PRINT_PRT_NUP_ORDER_BOX ) )
459cdf0e10cSrcweir     , maNupOrderWin( this )
460cdf0e10cSrcweir     , maBorderCB( this, VclResId( SV_PRINT_PRT_NUP_BORDER_CB ) )
461cdf0e10cSrcweir {
462cdf0e10cSrcweir     FreeResource();
463cdf0e10cSrcweir 
464cdf0e10cSrcweir     maNupOrderWin.Show();
465cdf0e10cSrcweir     maPagesBtn.Check( sal_True );
466cdf0e10cSrcweir     maBrochureBtn.Show( sal_False );
467cdf0e10cSrcweir 
468cdf0e10cSrcweir     // setup field units for metric fields
469cdf0e10cSrcweir     const LocaleDataWrapper& rLocWrap( maPageMarginEdt.GetLocaleDataWrapper() );
470cdf0e10cSrcweir     FieldUnit eUnit = FUNIT_MM;
471cdf0e10cSrcweir     sal_uInt16 nDigits = 0;
472cdf0e10cSrcweir     if( rLocWrap.getMeasurementSystemEnum() == MEASURE_US )
473cdf0e10cSrcweir     {
474cdf0e10cSrcweir         eUnit = FUNIT_INCH;
475cdf0e10cSrcweir         nDigits = 2;
476cdf0e10cSrcweir     }
477cdf0e10cSrcweir     // set units
478cdf0e10cSrcweir     maPageMarginEdt.SetUnit( eUnit );
479cdf0e10cSrcweir     maSheetMarginEdt.SetUnit( eUnit );
480cdf0e10cSrcweir 
481cdf0e10cSrcweir     // set precision
482cdf0e10cSrcweir     maPageMarginEdt.SetDecimalDigits( nDigits );
483cdf0e10cSrcweir     maSheetMarginEdt.SetDecimalDigits( nDigits );
484cdf0e10cSrcweir 
485cdf0e10cSrcweir     setupLayout();
486cdf0e10cSrcweir }
487cdf0e10cSrcweir 
488cdf0e10cSrcweir PrintDialog::NUpTabPage::~NUpTabPage()
489cdf0e10cSrcweir {
490cdf0e10cSrcweir }
491cdf0e10cSrcweir 
492cdf0e10cSrcweir void PrintDialog::NUpTabPage::enableNupControls( bool bEnable )
493cdf0e10cSrcweir {
494cdf0e10cSrcweir     maNupPagesBox.Enable( sal_True );
495cdf0e10cSrcweir     maNupNumPagesTxt.Enable( bEnable );
496cdf0e10cSrcweir     maNupColEdt.Enable( bEnable );
497cdf0e10cSrcweir     maNupTimesTxt.Enable( bEnable );
498cdf0e10cSrcweir     maNupRowsEdt.Enable( bEnable );
499cdf0e10cSrcweir     maPageMarginTxt1.Enable( bEnable );
500cdf0e10cSrcweir     maPageMarginEdt.Enable( bEnable );
501cdf0e10cSrcweir     maPageMarginTxt2.Enable( bEnable );
502cdf0e10cSrcweir     maSheetMarginTxt1.Enable( bEnable );
503cdf0e10cSrcweir     maSheetMarginEdt.Enable( bEnable );
504cdf0e10cSrcweir     maSheetMarginTxt2.Enable( bEnable );
505cdf0e10cSrcweir     maNupOrientationTxt.Enable( bEnable );
506cdf0e10cSrcweir     maNupOrientationBox.Enable( bEnable );
507cdf0e10cSrcweir     maNupOrderTxt.Enable( bEnable );
508cdf0e10cSrcweir     maNupOrderBox.Enable( bEnable );
509cdf0e10cSrcweir     maNupOrderWin.Enable( bEnable );
510cdf0e10cSrcweir     maBorderCB.Enable( bEnable );
511cdf0e10cSrcweir }
512cdf0e10cSrcweir 
513cdf0e10cSrcweir void PrintDialog::NUpTabPage::showAdvancedControls( bool i_bShow )
514cdf0e10cSrcweir {
515cdf0e10cSrcweir     maNupNumPagesTxt.Show( i_bShow );
516cdf0e10cSrcweir     maNupColEdt.Show( i_bShow );
517cdf0e10cSrcweir     maNupTimesTxt.Show( i_bShow );
518cdf0e10cSrcweir     maNupRowsEdt.Show( i_bShow );
519cdf0e10cSrcweir     maPageMarginTxt1.Show( i_bShow );
520cdf0e10cSrcweir     maPageMarginEdt.Show( i_bShow );
521cdf0e10cSrcweir     maPageMarginTxt2.Show( i_bShow );
522cdf0e10cSrcweir     maSheetMarginTxt1.Show( i_bShow );
523cdf0e10cSrcweir     maSheetMarginEdt.Show( i_bShow );
524cdf0e10cSrcweir     maSheetMarginTxt2.Show( i_bShow );
525cdf0e10cSrcweir     maNupOrientationTxt.Show( i_bShow );
526cdf0e10cSrcweir     maNupOrientationBox.Show( i_bShow );
527cdf0e10cSrcweir     getLayout()->resize();
528cdf0e10cSrcweir }
529cdf0e10cSrcweir 
530cdf0e10cSrcweir void PrintDialog::NUpTabPage::setupLayout()
531cdf0e10cSrcweir {
532cdf0e10cSrcweir     boost::shared_ptr<vcl::RowOrColumn> xLayout =
533cdf0e10cSrcweir         boost::dynamic_pointer_cast<vcl::RowOrColumn>( getLayout() );
534cdf0e10cSrcweir     Size aBorder( LogicToPixel( Size( 6, 6 ), MapMode( MAP_APPFONT ) ) );
535cdf0e10cSrcweir     /*  According to OOo style guide, the horizontal indentation of child
536cdf0e10cSrcweir         elements to their parent element should always be 6 map units. */
537cdf0e10cSrcweir     long nIndent = aBorder.Width();
538cdf0e10cSrcweir 
539cdf0e10cSrcweir     xLayout->addWindow( &maNupLine );
540cdf0e10cSrcweir     boost::shared_ptr< vcl::RowOrColumn > xRow( new vcl::RowOrColumn( xLayout.get(), false ) );
541cdf0e10cSrcweir     xLayout->addChild( xRow );
542cdf0e10cSrcweir     boost::shared_ptr< vcl::Indenter > xIndent( new vcl::Indenter( xRow.get() ) );
543cdf0e10cSrcweir     xRow->addChild( xIndent );
544cdf0e10cSrcweir 
545cdf0e10cSrcweir     boost::shared_ptr< vcl::RowOrColumn > xShowNupCol( new vcl::RowOrColumn( xRow.get() ) );
546cdf0e10cSrcweir     xRow->addChild( xShowNupCol, -1 );
547cdf0e10cSrcweir     xShowNupCol->setMinimumSize( xShowNupCol->addWindow( &maNupOrderWin ), Size( 70, 70 ) );
548cdf0e10cSrcweir     boost::shared_ptr< vcl::Spacer > xSpacer( new vcl::Spacer( xShowNupCol.get() ) );
549cdf0e10cSrcweir     xShowNupCol->addChild( xSpacer );
550cdf0e10cSrcweir 
551cdf0e10cSrcweir     boost::shared_ptr< vcl::LabelColumn > xMainCol( new vcl::LabelColumn( xIndent.get() ) );
552cdf0e10cSrcweir     xIndent->setChild( xMainCol );
553cdf0e10cSrcweir 
554cdf0e10cSrcweir     size_t nPagesIndex = xMainCol->addRow( &maPagesBtn, &maNupPagesBox );
555cdf0e10cSrcweir     mxPagesBtnLabel = boost::dynamic_pointer_cast<vcl::LabeledElement>( xMainCol->getChild( nPagesIndex ) );
556cdf0e10cSrcweir 
557cdf0e10cSrcweir     xRow.reset( new vcl::RowOrColumn( xMainCol.get(), false ) );
558cdf0e10cSrcweir     xMainCol->addRow( &maNupNumPagesTxt, xRow, nIndent );
559cdf0e10cSrcweir     xRow->addWindow( &maNupColEdt );
560cdf0e10cSrcweir     xRow->addWindow( &maNupTimesTxt );
561cdf0e10cSrcweir     xRow->addWindow( &maNupRowsEdt );
562cdf0e10cSrcweir 
563cdf0e10cSrcweir     boost::shared_ptr< vcl::LabeledElement > xLab( new vcl::LabeledElement( xMainCol.get(), 2 ) );
564cdf0e10cSrcweir     xLab->setLabel( &maPageMarginEdt );
565cdf0e10cSrcweir     xLab->setElement( &maPageMarginTxt2 );
566cdf0e10cSrcweir     xMainCol->addRow( &maPageMarginTxt1, xLab, nIndent );
567cdf0e10cSrcweir 
568cdf0e10cSrcweir     xLab.reset( new vcl::LabeledElement( xMainCol.get(), 2 ) );
569cdf0e10cSrcweir     xLab->setLabel( &maSheetMarginEdt );
570cdf0e10cSrcweir     xLab->setElement( &maSheetMarginTxt2 );
571cdf0e10cSrcweir     xMainCol->addRow( &maSheetMarginTxt1, xLab, nIndent );
572cdf0e10cSrcweir 
573cdf0e10cSrcweir     xMainCol->addRow( &maNupOrientationTxt, &maNupOrientationBox, nIndent );
574cdf0e10cSrcweir     xMainCol->addRow( &maNupOrderTxt, &maNupOrderBox, nIndent );
575cdf0e10cSrcweir     xMainCol->setBorders( xMainCol->addWindow( &maBorderCB ), nIndent, 0, 0, 0 );
576cdf0e10cSrcweir 
577cdf0e10cSrcweir     xSpacer.reset( new vcl::Spacer( xMainCol.get(), 0, Size( 10, WindowArranger::getDefaultBorder() ) ) );
578cdf0e10cSrcweir     xMainCol->addChild( xSpacer );
579cdf0e10cSrcweir 
580cdf0e10cSrcweir     xRow.reset( new vcl::RowOrColumn( xMainCol.get(), false ) );
581cdf0e10cSrcweir     xMainCol->addRow( &maBrochureBtn, xRow );
582cdf0e10cSrcweir     // remember brochure row for dependencies
583cdf0e10cSrcweir     mxBrochureDep = xRow;
584cdf0e10cSrcweir 
585cdf0e10cSrcweir     // initially advanced controls are not shown, rows=columns=1
586cdf0e10cSrcweir     showAdvancedControls( false );
587cdf0e10cSrcweir }
588cdf0e10cSrcweir 
589cdf0e10cSrcweir void PrintDialog::NUpTabPage::initFromMultiPageSetup( const vcl::PrinterController::MultiPageSetup& i_rMPS )
590cdf0e10cSrcweir {
591cdf0e10cSrcweir     maSheetMarginEdt.SetValue( maSheetMarginEdt.Normalize( i_rMPS.nLeftMargin ), FUNIT_100TH_MM );
592cdf0e10cSrcweir     maPageMarginEdt.SetValue( maPageMarginEdt.Normalize( i_rMPS.nHorizontalSpacing ), FUNIT_100TH_MM );
593cdf0e10cSrcweir     maBorderCB.Check( i_rMPS.bDrawBorder );
594cdf0e10cSrcweir     maNupRowsEdt.SetValue( i_rMPS.nRows );
595cdf0e10cSrcweir     maNupColEdt.SetValue( i_rMPS.nColumns );
596*0dccdc5dSMichael Stahl     maBorderCB.Check( i_rMPS.bDrawBorder );
597*0dccdc5dSMichael Stahl     for( sal_uInt16 i = 0; i < maNupOrderBox.GetEntryCount(); i++ )
598*0dccdc5dSMichael Stahl     {
599*0dccdc5dSMichael Stahl         if( int(sal_IntPtr(maNupOrderBox.GetEntryData( i ))) == i_rMPS.nOrder )
600*0dccdc5dSMichael Stahl             maNupOrderBox.SelectEntryPos( i );
601*0dccdc5dSMichael Stahl     }
602*0dccdc5dSMichael Stahl     if( i_rMPS.nRows != 1 || i_rMPS.nColumns != 1 )
603*0dccdc5dSMichael Stahl     {
604*0dccdc5dSMichael Stahl         maNupPagesBox.SelectEntryPos( maNupPagesBox.GetEntryCount()-1 );
605*0dccdc5dSMichael Stahl         showAdvancedControls( true );
606*0dccdc5dSMichael Stahl         maNupOrderWin.setValues( i_rMPS.nOrder, i_rMPS.nColumns, i_rMPS.nRows );
607*0dccdc5dSMichael Stahl     }
608cdf0e10cSrcweir }
609cdf0e10cSrcweir 
610cdf0e10cSrcweir void PrintDialog::NUpTabPage::readFromSettings()
611cdf0e10cSrcweir {
612cdf0e10cSrcweir }
613cdf0e10cSrcweir 
614cdf0e10cSrcweir void PrintDialog::NUpTabPage::storeToSettings()
615cdf0e10cSrcweir {
616cdf0e10cSrcweir }
617cdf0e10cSrcweir 
618cdf0e10cSrcweir PrintDialog::JobTabPage::JobTabPage( Window* i_pParent, const ResId& rResId )
619cdf0e10cSrcweir     : TabPage( i_pParent, rResId )
620cdf0e10cSrcweir     , maPrinterFL( this, VclResId( SV_PRINT_PRINTERS_FL ) )
621cdf0e10cSrcweir     , maPrinters( this, VclResId( SV_PRINT_PRINTERS ) )
622cdf0e10cSrcweir     , maDetailsBtn( this, VclResId( SV_PRINT_DETAILS_BTN ) )
623cdf0e10cSrcweir     , maStatusLabel( this, VclResId( SV_PRINT_STATUS_TXT ) )
624cdf0e10cSrcweir     , maStatusTxt( this, 0 )
625cdf0e10cSrcweir     , maLocationLabel( this, VclResId( SV_PRINT_LOCATION_TXT ) )
626cdf0e10cSrcweir     , maLocationTxt( this, 0 )
627cdf0e10cSrcweir     , maCommentLabel( this, VclResId( SV_PRINT_COMMENT_TXT ) )
628cdf0e10cSrcweir     , maCommentTxt( this, 0 )
629cdf0e10cSrcweir     , maSetupButton( this, VclResId( SV_PRINT_PRT_SETUP ) )
630cdf0e10cSrcweir     , maCopies( this, VclResId( SV_PRINT_COPIES ) )
631cdf0e10cSrcweir     , maCopySpacer( this, WB_VERT )
632cdf0e10cSrcweir     , maCopyCount( this, VclResId( SV_PRINT_COPYCOUNT ) )
633cdf0e10cSrcweir     , maCopyCountField( this, VclResId( SV_PRINT_COPYCOUNT_FIELD ) )
634cdf0e10cSrcweir     , maCollateBox( this, VclResId( SV_PRINT_COLLATE ) )
635cdf0e10cSrcweir     , maCollateImage( this, VclResId( SV_PRINT_COLLATE_IMAGE ) )
636cdf0e10cSrcweir     , maReverseOrderBox( this, VclResId( SV_PRINT_OPT_REVERSE ) )
637cdf0e10cSrcweir     , maCollateImg( VclResId( SV_PRINT_COLLATE_IMG ) )
638cdf0e10cSrcweir     , maCollateHCImg( VclResId( SV_PRINT_COLLATE_HC_IMG ) )
639cdf0e10cSrcweir     , maNoCollateImg( VclResId( SV_PRINT_NOCOLLATE_IMG ) )
640cdf0e10cSrcweir     , maNoCollateHCImg( VclResId( SV_PRINT_NOCOLLATE_HC_IMG ) )
641cdf0e10cSrcweir     , mnCollateUIMode( 0 )
642cdf0e10cSrcweir {
643cdf0e10cSrcweir     FreeResource();
644cdf0e10cSrcweir 
645cdf0e10cSrcweir     maCopySpacer.Show();
646cdf0e10cSrcweir     maStatusTxt.Show();
647cdf0e10cSrcweir     maCommentTxt.Show();
648cdf0e10cSrcweir     maLocationTxt.Show();
649cdf0e10cSrcweir 
650cdf0e10cSrcweir     setupLayout();
651cdf0e10cSrcweir }
652cdf0e10cSrcweir 
653cdf0e10cSrcweir PrintDialog::JobTabPage::~JobTabPage()
654cdf0e10cSrcweir {
655cdf0e10cSrcweir }
656cdf0e10cSrcweir 
657cdf0e10cSrcweir void PrintDialog::JobTabPage::setupLayout()
658cdf0e10cSrcweir {
659cdf0e10cSrcweir     // HACK: this is not a dropdown box, but the dropdown line count
660cdf0e10cSrcweir     // sets the results of GetOptimalSize in a normal ListBox
661cdf0e10cSrcweir     maPrinters.SetDropDownLineCount( 4 );
662cdf0e10cSrcweir 
663cdf0e10cSrcweir     boost::shared_ptr<vcl::RowOrColumn> xLayout =
664cdf0e10cSrcweir         boost::dynamic_pointer_cast<vcl::RowOrColumn>( getLayout() );
665cdf0e10cSrcweir 
666cdf0e10cSrcweir     // add printer fixed line
667cdf0e10cSrcweir     xLayout->addWindow( &maPrinterFL );
668cdf0e10cSrcweir     // add print LB
669cdf0e10cSrcweir     xLayout->addWindow( &maPrinters, 3 );
670cdf0e10cSrcweir 
671cdf0e10cSrcweir     // create a row for details button/text and properties button
672cdf0e10cSrcweir     boost::shared_ptr< vcl::RowOrColumn > xDetRow( new vcl::RowOrColumn( xLayout.get(), false ) );
673cdf0e10cSrcweir     xLayout->addChild( xDetRow );
674cdf0e10cSrcweir     xDetRow->addWindow( &maDetailsBtn );
675cdf0e10cSrcweir     xDetRow->addChild( new vcl::Spacer( xDetRow.get(), 2 ) );
676cdf0e10cSrcweir     xDetRow->addWindow( &maSetupButton );
677cdf0e10cSrcweir 
678cdf0e10cSrcweir     // create an indent for details
679cdf0e10cSrcweir     boost::shared_ptr< vcl::Indenter > xIndent( new vcl::Indenter( xLayout.get() ) );
680cdf0e10cSrcweir     xLayout->addChild( xIndent );
681cdf0e10cSrcweir     // remember details controls
682cdf0e10cSrcweir     mxDetails = xIndent;
683cdf0e10cSrcweir     // create a column for the details
684cdf0e10cSrcweir     boost::shared_ptr< vcl::LabelColumn > xLabelCol( new vcl::LabelColumn( xIndent.get() ) );
685cdf0e10cSrcweir     xIndent->setChild( xLabelCol );
686cdf0e10cSrcweir     xLabelCol->addRow( &maStatusLabel, &maStatusTxt );
687cdf0e10cSrcweir     xLabelCol->addRow( &maLocationLabel, &maLocationTxt );
688cdf0e10cSrcweir     xLabelCol->addRow( &maCommentLabel, &maCommentTxt );
689cdf0e10cSrcweir 
690cdf0e10cSrcweir     // add print range and copies columns
691cdf0e10cSrcweir     xLayout->addWindow( &maCopies );
692cdf0e10cSrcweir     boost::shared_ptr< vcl::RowOrColumn > xRangeRow( new vcl::RowOrColumn( xLayout.get(), false ) );
693cdf0e10cSrcweir     xLayout->addChild( xRangeRow );
694cdf0e10cSrcweir 
695cdf0e10cSrcweir     // create print range and add to range row
696cdf0e10cSrcweir     mxPrintRange.reset( new vcl::RowOrColumn( xRangeRow.get() ) );
697cdf0e10cSrcweir     xRangeRow->addChild( mxPrintRange );
698cdf0e10cSrcweir     xRangeRow->addWindow( &maCopySpacer );
699cdf0e10cSrcweir 
700cdf0e10cSrcweir     boost::shared_ptr< vcl::RowOrColumn > xCopyCollateCol( new vcl::RowOrColumn( xRangeRow.get() ) );
701cdf0e10cSrcweir     xRangeRow->addChild( xCopyCollateCol );
702cdf0e10cSrcweir 
703cdf0e10cSrcweir     // add copies row to copy/collate column
704cdf0e10cSrcweir     boost::shared_ptr< vcl::LabeledElement > xCopiesRow( new vcl::LabeledElement( xCopyCollateCol.get(), 2 ) );
705cdf0e10cSrcweir     xCopyCollateCol->addChild( xCopiesRow );
706cdf0e10cSrcweir     xCopiesRow->setLabel( &maCopyCount );
707cdf0e10cSrcweir     xCopiesRow->setElement( &maCopyCountField );
708cdf0e10cSrcweir     boost::shared_ptr< vcl::LabeledElement > xCollateRow( new vcl::LabeledElement( xCopyCollateCol.get(), 2 ) );
709cdf0e10cSrcweir     xCopyCollateCol->addChild( xCollateRow );
710cdf0e10cSrcweir     xCollateRow->setLabel( &maCollateBox );
711cdf0e10cSrcweir     xCollateRow->setElement( &maCollateImage );
712cdf0e10cSrcweir 
713cdf0e10cSrcweir     // maDetailsBtn.SetStyle( maDetailsBtn.GetStyle() | (WB_SMALLSTYLE | WB_BEVELBUTTON) );
714cdf0e10cSrcweir     mxDetails->show( false, false );
715cdf0e10cSrcweir }
716cdf0e10cSrcweir 
717cdf0e10cSrcweir void PrintDialog::JobTabPage::readFromSettings()
718cdf0e10cSrcweir {
719cdf0e10cSrcweir     SettingsConfigItem* pItem = SettingsConfigItem::get();
720cdf0e10cSrcweir     rtl::OUString aValue;
721cdf0e10cSrcweir 
722cdf0e10cSrcweir     #if 0
723cdf0e10cSrcweir     // do not actually make copy count persistent
724cdf0e10cSrcweir     // the assumption is that this would lead to a lot of unwanted copies
725cdf0e10cSrcweir     aValue = pItem->getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
726cdf0e10cSrcweir                               rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CopyCount" ) ) );
727cdf0e10cSrcweir     sal_Int32 nVal = aValue.toInt32();
728cdf0e10cSrcweir     maCopyCountField.SetValue( sal_Int64(nVal > 1 ? nVal : 1) );
729cdf0e10cSrcweir     #endif
730cdf0e10cSrcweir 
731cdf0e10cSrcweir     aValue = pItem->getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
732cdf0e10cSrcweir                               rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CollateBox" ) ) );
733cdf0e10cSrcweir     if( aValue.equalsIgnoreAsciiCaseAscii( "alwaysoff" ) )
734cdf0e10cSrcweir     {
735cdf0e10cSrcweir         mnCollateUIMode = 1;
736cdf0e10cSrcweir         maCollateBox.Check( sal_False );
737cdf0e10cSrcweir         maCollateBox.Enable( sal_False );
738cdf0e10cSrcweir     }
739cdf0e10cSrcweir     else
740cdf0e10cSrcweir     {
741cdf0e10cSrcweir         mnCollateUIMode = 0;
742cdf0e10cSrcweir         aValue = pItem->getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
743cdf0e10cSrcweir                                   rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Collate" ) ) );
744cdf0e10cSrcweir         maCollateBox.Check( aValue.equalsIgnoreAsciiCaseAscii( "true" ) );
745cdf0e10cSrcweir     }
746cdf0e10cSrcweir     Resize();
747cdf0e10cSrcweir }
748cdf0e10cSrcweir 
749cdf0e10cSrcweir void PrintDialog::JobTabPage::storeToSettings()
750cdf0e10cSrcweir {
751cdf0e10cSrcweir     SettingsConfigItem* pItem = SettingsConfigItem::get();
752cdf0e10cSrcweir     pItem->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
753cdf0e10cSrcweir                      rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CopyCount" ) ),
754cdf0e10cSrcweir                      maCopyCountField.GetText() );
755cdf0e10cSrcweir     pItem->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
756cdf0e10cSrcweir                      rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Collate" ) ),
757cdf0e10cSrcweir                      rtl::OUString::createFromAscii( maCollateBox.IsChecked() ? "true" : "false" ) );
758cdf0e10cSrcweir }
759cdf0e10cSrcweir 
760cdf0e10cSrcweir PrintDialog::OutputOptPage::OutputOptPage( Window* i_pParent, const ResId& i_rResId )
761cdf0e10cSrcweir     : TabPage( i_pParent, i_rResId )
762cdf0e10cSrcweir     , maOptionsLine( this, VclResId( SV_PRINT_OPT_PRINT_FL ) )
763cdf0e10cSrcweir     , maToFileBox( this, VclResId( SV_PRINT_OPT_TOFILE ) )
764cdf0e10cSrcweir     , maCollateSingleJobsBox( this, VclResId( SV_PRINT_OPT_SINGLEJOBS ) )
765cdf0e10cSrcweir {
766cdf0e10cSrcweir     FreeResource();
767cdf0e10cSrcweir 
768cdf0e10cSrcweir     setupLayout();
769cdf0e10cSrcweir }
770cdf0e10cSrcweir 
771cdf0e10cSrcweir PrintDialog::OutputOptPage::~OutputOptPage()
772cdf0e10cSrcweir {
773cdf0e10cSrcweir }
774cdf0e10cSrcweir 
775cdf0e10cSrcweir void PrintDialog::OutputOptPage::setupLayout()
776cdf0e10cSrcweir {
777cdf0e10cSrcweir     boost::shared_ptr<vcl::RowOrColumn> xLayout =
778cdf0e10cSrcweir         boost::dynamic_pointer_cast<vcl::RowOrColumn>( getLayout() );
779cdf0e10cSrcweir 
780cdf0e10cSrcweir     xLayout->addWindow( &maOptionsLine );
781cdf0e10cSrcweir     boost::shared_ptr<vcl::Indenter> xIndent( new vcl::Indenter( xLayout.get(), -1 ) );
782cdf0e10cSrcweir     xLayout->addChild( xIndent );
783cdf0e10cSrcweir     boost::shared_ptr<vcl::RowOrColumn> xCol( new vcl::RowOrColumn( xIndent.get() ) );
784cdf0e10cSrcweir     xIndent->setChild( xCol );
785cdf0e10cSrcweir     mxOptGroup = xCol;
786cdf0e10cSrcweir     xCol->addWindow( &maToFileBox );
787cdf0e10cSrcweir     xCol->addWindow( &maCollateSingleJobsBox );
788cdf0e10cSrcweir }
789cdf0e10cSrcweir 
790cdf0e10cSrcweir void PrintDialog::OutputOptPage::readFromSettings()
791cdf0e10cSrcweir {
792cdf0e10cSrcweir     #if 0
793cdf0e10cSrcweir     SettingsConfigItem* pItem = SettingsConfigItem::get();
794cdf0e10cSrcweir     rtl::OUString aValue;
795cdf0e10cSrcweir 
796cdf0e10cSrcweir     aValue = pItem->getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
797cdf0e10cSrcweir                               rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ToFile" ) ) );
798cdf0e10cSrcweir     maToFileBox.Check( aValue.equalsIgnoreAsciiCaseAscii( "true" ) );
799cdf0e10cSrcweir     #endif
800cdf0e10cSrcweir }
801cdf0e10cSrcweir 
802cdf0e10cSrcweir void PrintDialog::OutputOptPage::storeToSettings()
803cdf0e10cSrcweir {
804cdf0e10cSrcweir     SettingsConfigItem* pItem = SettingsConfigItem::get();
805cdf0e10cSrcweir     pItem->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
806cdf0e10cSrcweir                      rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ToFile" ) ),
807cdf0e10cSrcweir                      rtl::OUString::createFromAscii( maToFileBox.IsChecked() ? "true" : "false" ) );
808cdf0e10cSrcweir }
809cdf0e10cSrcweir 
810cdf0e10cSrcweir PrintDialog::PrintDialog( Window* i_pParent, const boost::shared_ptr<PrinterController>& i_rController )
811cdf0e10cSrcweir     : ModalDialog( i_pParent, VclResId( SV_DLG_PRINT ) )
812cdf0e10cSrcweir     , maOKButton( this, VclResId( SV_PRINT_OK ) )
813cdf0e10cSrcweir     , maCancelButton( this, VclResId( SV_PRINT_CANCEL ) )
814cdf0e10cSrcweir     , maHelpButton( this, VclResId( SV_PRINT_HELP ) )
815cdf0e10cSrcweir     , maPreviewWindow( this, VclResId( SV_PRINT_PAGE_PREVIEW ) )
816cdf0e10cSrcweir     , maPageEdit( this, VclResId( SV_PRINT_PAGE_EDIT ) )
817cdf0e10cSrcweir     , maNumPagesText( this, VclResId( SV_PRINT_PAGE_TXT ) )
818cdf0e10cSrcweir     , maBackwardBtn( this, VclResId( SV_PRINT_PAGE_BACKWARD ) )
819cdf0e10cSrcweir     , maForwardBtn( this, VclResId( SV_PRINT_PAGE_FORWARD ) )
820cdf0e10cSrcweir     , maTabCtrl( this, VclResId( SV_PRINT_TABCTRL ) )
821cdf0e10cSrcweir     , maNUpPage( &maTabCtrl, VclResId( SV_PRINT_TAB_NUP ) )
822cdf0e10cSrcweir     , maJobPage( &maTabCtrl, VclResId( SV_PRINT_TAB_JOB ) )
823cdf0e10cSrcweir     , maOptionsPage( &maTabCtrl, VclResId( SV_PRINT_TAB_OPT ) )
824cdf0e10cSrcweir     , maButtonLine( this, VclResId( SV_PRINT_BUTTONLINE ) )
825cdf0e10cSrcweir     , maPController( i_rController )
826cdf0e10cSrcweir     , maNoPageStr( String( VclResId( SV_PRINT_NOPAGES ) ) )
827cdf0e10cSrcweir     , mnCurPage( 0 )
828cdf0e10cSrcweir     , mnCachedPages( 0 )
829cdf0e10cSrcweir     , maPrintToFileText( String( VclResId( SV_PRINT_TOFILE_TXT ) ) )
830cdf0e10cSrcweir     , maDefPrtText( String( VclResId( SV_PRINT_DEFPRT_TXT ) ) )
831cdf0e10cSrcweir     , mbShowLayoutPage( sal_True )
832cdf0e10cSrcweir {
833cdf0e10cSrcweir     FreeResource();
834cdf0e10cSrcweir 
835cdf0e10cSrcweir     // save printbutton text, gets exchanged occasionally with print to file
836cdf0e10cSrcweir     maPrintText = maOKButton.GetText();
837cdf0e10cSrcweir 
838cdf0e10cSrcweir     // setup preview controls
839cdf0e10cSrcweir     maForwardBtn.SetStyle( maForwardBtn.GetStyle() | WB_BEVELBUTTON );
840cdf0e10cSrcweir     maBackwardBtn.SetStyle( maBackwardBtn.GetStyle() | WB_BEVELBUTTON );
841cdf0e10cSrcweir 
842cdf0e10cSrcweir     // insert the job (general) tab page first
843cdf0e10cSrcweir     maTabCtrl.InsertPage( SV_PRINT_TAB_JOB, maJobPage.GetText() );
844cdf0e10cSrcweir     maTabCtrl.SetTabPage( SV_PRINT_TAB_JOB, &maJobPage );
845cdf0e10cSrcweir 
846cdf0e10cSrcweir     // set symbols on forward and backward button
847cdf0e10cSrcweir     maBackwardBtn.SetSymbol( SYMBOL_PREV );
848cdf0e10cSrcweir     maForwardBtn.SetSymbol( SYMBOL_NEXT );
849cdf0e10cSrcweir     maBackwardBtn.ImplSetSmallSymbol( sal_True );
850cdf0e10cSrcweir     maForwardBtn.ImplSetSmallSymbol( sal_True );
851cdf0e10cSrcweir 
852cdf0e10cSrcweir     maPageStr = maNumPagesText.GetText();
853cdf0e10cSrcweir 
854cdf0e10cSrcweir     // init reverse print
855cdf0e10cSrcweir     maJobPage.maReverseOrderBox.Check( maPController->getReversePrint() );
856cdf0e10cSrcweir 
857cdf0e10cSrcweir     // fill printer listbox
858cdf0e10cSrcweir     const std::vector< rtl::OUString >& rQueues( Printer::GetPrinterQueues() );
859cdf0e10cSrcweir     for( std::vector< rtl::OUString >::const_iterator it = rQueues.begin();
860cdf0e10cSrcweir          it != rQueues.end(); ++it )
861cdf0e10cSrcweir     {
862cdf0e10cSrcweir         maJobPage.maPrinters.InsertEntry( *it );
863cdf0e10cSrcweir     }
864cdf0e10cSrcweir     // select current printer
865cdf0e10cSrcweir     if( maJobPage.maPrinters.GetEntryPos( maPController->getPrinter()->GetName() ) != LISTBOX_ENTRY_NOTFOUND )
866cdf0e10cSrcweir     {
867cdf0e10cSrcweir         maJobPage.maPrinters.SelectEntry( maPController->getPrinter()->GetName() );
868cdf0e10cSrcweir     }
869cdf0e10cSrcweir     else
870cdf0e10cSrcweir     {
871cdf0e10cSrcweir         // fall back to last printer
872cdf0e10cSrcweir         SettingsConfigItem* pItem = SettingsConfigItem::get();
873cdf0e10cSrcweir         String aValue( pItem->getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
874cdf0e10cSrcweir                                         rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LastPrinter" ) ) ) );
875cdf0e10cSrcweir         if( maJobPage.maPrinters.GetEntryPos( aValue ) != LISTBOX_ENTRY_NOTFOUND )
876cdf0e10cSrcweir         {
877cdf0e10cSrcweir             maJobPage.maPrinters.SelectEntry( aValue );
878cdf0e10cSrcweir             maPController->setPrinter( boost::shared_ptr<Printer>( new Printer( aValue ) ) );
879cdf0e10cSrcweir         }
880cdf0e10cSrcweir         else
881cdf0e10cSrcweir         {
882cdf0e10cSrcweir             // fall back to default printer
883cdf0e10cSrcweir             maJobPage.maPrinters.SelectEntry( Printer::GetDefaultPrinterName() );
884cdf0e10cSrcweir             maPController->setPrinter( boost::shared_ptr<Printer>( new Printer( Printer::GetDefaultPrinterName() ) ) );
885cdf0e10cSrcweir         }
886cdf0e10cSrcweir     }
887cdf0e10cSrcweir     // not printing to file
888cdf0e10cSrcweir     maPController->resetPrinterOptions( false );
889cdf0e10cSrcweir 
890cdf0e10cSrcweir     // get the first page
891cdf0e10cSrcweir     preparePreview( true, true );
892cdf0e10cSrcweir 
893cdf0e10cSrcweir     // update the text fields for the printer
894cdf0e10cSrcweir     updatePrinterText();
895cdf0e10cSrcweir 
896cdf0e10cSrcweir     // set a select handler
897cdf0e10cSrcweir     maJobPage.maPrinters.SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) );
898cdf0e10cSrcweir 
899cdf0e10cSrcweir     // setup sizes for N-Up
900cdf0e10cSrcweir     Size aNupSize( maPController->getPrinter()->PixelToLogic(
901cdf0e10cSrcweir                          maPController->getPrinter()->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) ) );
902cdf0e10cSrcweir     if( maPController->getPrinter()->GetOrientation() == ORIENTATION_LANDSCAPE )
903cdf0e10cSrcweir     {
904cdf0e10cSrcweir         maNupLandscapeSize = aNupSize;
905cdf0e10cSrcweir         maNupPortraitSize = Size( aNupSize.Height(), aNupSize.Width() );
906cdf0e10cSrcweir     }
907cdf0e10cSrcweir     else
908cdf0e10cSrcweir     {
909cdf0e10cSrcweir         maNupPortraitSize = aNupSize;
910cdf0e10cSrcweir         maNupLandscapeSize = Size( aNupSize.Height(), aNupSize.Width() );
911cdf0e10cSrcweir     }
912cdf0e10cSrcweir     maNUpPage.initFromMultiPageSetup( maPController->getMultipage() );
913cdf0e10cSrcweir 
914cdf0e10cSrcweir 
915cdf0e10cSrcweir     // setup click handler on the various buttons
916cdf0e10cSrcweir     maOKButton.SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
917cdf0e10cSrcweir     #if OSL_DEBUG_LEVEL > 1
918cdf0e10cSrcweir     maCancelButton.SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
919cdf0e10cSrcweir     #endif
920cdf0e10cSrcweir     maHelpButton.SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
921cdf0e10cSrcweir     maForwardBtn.SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
922cdf0e10cSrcweir     maBackwardBtn.SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
923cdf0e10cSrcweir     maJobPage.maCollateBox.SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
924cdf0e10cSrcweir     maJobPage.maSetupButton.SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
925cdf0e10cSrcweir     maJobPage.maDetailsBtn.SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
926cdf0e10cSrcweir     maNUpPage.maBorderCB.SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
927cdf0e10cSrcweir     maOptionsPage.maToFileBox.SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
928cdf0e10cSrcweir     maJobPage.maReverseOrderBox.SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
929cdf0e10cSrcweir     maOptionsPage.maCollateSingleJobsBox.SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
930cdf0e10cSrcweir     maNUpPage.maPagesBtn.SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
931cdf0e10cSrcweir 
932cdf0e10cSrcweir     // setup modify hdl
933cdf0e10cSrcweir     maPageEdit.SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
934cdf0e10cSrcweir     maJobPage.maCopyCountField.SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
935cdf0e10cSrcweir     maNUpPage.maNupRowsEdt.SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
936cdf0e10cSrcweir     maNUpPage.maNupColEdt.SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
937cdf0e10cSrcweir     maNUpPage.maPageMarginEdt.SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
938cdf0e10cSrcweir     maNUpPage.maSheetMarginEdt.SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
939cdf0e10cSrcweir 
940cdf0e10cSrcweir     // setup select hdl
941cdf0e10cSrcweir     maNUpPage.maNupPagesBox.SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) );
942cdf0e10cSrcweir     maNUpPage.maNupOrientationBox.SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) );
943cdf0e10cSrcweir     maNUpPage.maNupOrderBox.SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) );
944cdf0e10cSrcweir 
945cdf0e10cSrcweir     // setup the layout
946cdf0e10cSrcweir     setupLayout();
947cdf0e10cSrcweir 
948cdf0e10cSrcweir     // setup optional UI options set by application
949cdf0e10cSrcweir     setupOptionalUI();
950cdf0e10cSrcweir 
951cdf0e10cSrcweir     // set change handler for UI options
952cdf0e10cSrcweir     maPController->setOptionChangeHdl( LINK( this, PrintDialog, UIOptionsChanged ) );
953cdf0e10cSrcweir 
954cdf0e10cSrcweir     // set min size pixel to current size
955cdf0e10cSrcweir     Size aOutSize( GetOutputSizePixel() );
956cdf0e10cSrcweir     SetMinOutputSizePixel( aOutSize );
957cdf0e10cSrcweir 
958cdf0e10cSrcweir     // if there is space enough, enlarge the preview so it gets roughly as
959cdf0e10cSrcweir     // high as the tab control
960cdf0e10cSrcweir     if( aOutSize.Width() < 768 )
961cdf0e10cSrcweir     {
962cdf0e10cSrcweir         Size aJobPageSize( getJobPageSize() );
963cdf0e10cSrcweir         Size aTabSize( maTabCtrl.GetSizePixel() );
964cdf0e10cSrcweir         if( aJobPageSize.Width() < 1 )
965cdf0e10cSrcweir             aJobPageSize.Width() = aTabSize.Width();
966cdf0e10cSrcweir         if( aJobPageSize.Height() < 1 )
967cdf0e10cSrcweir             aJobPageSize.Height() = aTabSize.Height();
968cdf0e10cSrcweir         long nOptPreviewWidth = aTabSize.Height() * aJobPageSize.Width() / aJobPageSize.Height();
969cdf0e10cSrcweir         // add space for borders
970cdf0e10cSrcweir         nOptPreviewWidth += 15;
971cdf0e10cSrcweir         if( aOutSize.Width() - aTabSize.Width() < nOptPreviewWidth )
972cdf0e10cSrcweir         {
973cdf0e10cSrcweir             aOutSize.Width() = aTabSize.Width() + nOptPreviewWidth;
974cdf0e10cSrcweir             if( aOutSize.Width() > 768 ) // don't enlarge the dialog too much
975cdf0e10cSrcweir                 aOutSize.Width() = 768;
976cdf0e10cSrcweir             SetOutputSizePixel( aOutSize );
977cdf0e10cSrcweir         }
978cdf0e10cSrcweir     }
979cdf0e10cSrcweir 
980cdf0e10cSrcweir     // append further tab pages
981cdf0e10cSrcweir     if( mbShowLayoutPage )
982cdf0e10cSrcweir     {
983cdf0e10cSrcweir         maTabCtrl.InsertPage( SV_PRINT_TAB_NUP, maNUpPage.GetText() );
984cdf0e10cSrcweir         maTabCtrl.SetTabPage( SV_PRINT_TAB_NUP, &maNUpPage );
985cdf0e10cSrcweir     }
986cdf0e10cSrcweir     maTabCtrl.InsertPage( SV_PRINT_TAB_OPT, maOptionsPage.GetText() );
987cdf0e10cSrcweir     maTabCtrl.SetTabPage( SV_PRINT_TAB_OPT, &maOptionsPage );
988cdf0e10cSrcweir 
989cdf0e10cSrcweir     // restore settings from last run
990cdf0e10cSrcweir     readFromSettings();
991cdf0e10cSrcweir 
992cdf0e10cSrcweir     // setup dependencies
993cdf0e10cSrcweir     checkControlDependencies();
994cdf0e10cSrcweir 
995cdf0e10cSrcweir }
996cdf0e10cSrcweir 
997cdf0e10cSrcweir PrintDialog::~PrintDialog()
998cdf0e10cSrcweir {
999cdf0e10cSrcweir     while( ! maControls.empty() )
1000cdf0e10cSrcweir     {
1001cdf0e10cSrcweir         delete maControls.front();
1002cdf0e10cSrcweir         maControls.pop_front();
1003cdf0e10cSrcweir     }
1004cdf0e10cSrcweir }
1005cdf0e10cSrcweir 
1006cdf0e10cSrcweir void PrintDialog::setupLayout()
1007cdf0e10cSrcweir {
1008cdf0e10cSrcweir     boost::shared_ptr<vcl::RowOrColumn> xLayout =
1009cdf0e10cSrcweir         boost::dynamic_pointer_cast<vcl::RowOrColumn>( getLayout() );
1010cdf0e10cSrcweir     xLayout->setOuterBorder( 0 );
1011cdf0e10cSrcweir 
1012cdf0e10cSrcweir 
1013cdf0e10cSrcweir     boost::shared_ptr< vcl::RowOrColumn > xPreviewAndTab( new vcl::RowOrColumn( xLayout.get(), false ) );
1014cdf0e10cSrcweir     size_t nIndex = xLayout->addChild( xPreviewAndTab, 5 );
1015cdf0e10cSrcweir     xLayout->setBorders( nIndex, -1, -1, -1, 0 );
1016cdf0e10cSrcweir 
1017cdf0e10cSrcweir     // setup column for preview and sub controls
1018cdf0e10cSrcweir     boost::shared_ptr< vcl::RowOrColumn > xPreview( new vcl::RowOrColumn( xPreviewAndTab.get() ) );
1019cdf0e10cSrcweir     xPreviewAndTab->addChild( xPreview, 5 );
1020cdf0e10cSrcweir     xPreview->addWindow( &maPreviewWindow, 5 );
1021cdf0e10cSrcweir     // get a row for the preview controls
1022cdf0e10cSrcweir     mxPreviewCtrls.reset( new vcl::RowOrColumn( xPreview.get(), false ) );
1023cdf0e10cSrcweir     nIndex = xPreview->addChild( mxPreviewCtrls );
1024cdf0e10cSrcweir     boost::shared_ptr< vcl::Spacer > xSpacer( new vcl::Spacer( mxPreviewCtrls.get(), 2 ) );
1025cdf0e10cSrcweir     mxPreviewCtrls->addChild( xSpacer );
1026cdf0e10cSrcweir     mxPreviewCtrls->addWindow( &maPageEdit );
1027cdf0e10cSrcweir     mxPreviewCtrls->addWindow( &maNumPagesText );
1028cdf0e10cSrcweir     xSpacer.reset( new vcl::Spacer( mxPreviewCtrls.get(), 2 ) );
1029cdf0e10cSrcweir     mxPreviewCtrls->addChild( xSpacer );
1030cdf0e10cSrcweir     mxPreviewCtrls->addWindow( &maBackwardBtn );
1031cdf0e10cSrcweir     mxPreviewCtrls->addWindow( &maForwardBtn );
1032cdf0e10cSrcweir     xSpacer.reset( new vcl::Spacer( mxPreviewCtrls.get(), 2 ) );
1033cdf0e10cSrcweir     mxPreviewCtrls->addChild( xSpacer );
1034cdf0e10cSrcweir 
1035cdf0e10cSrcweir     // continue with the tab ctrl
1036cdf0e10cSrcweir     xPreviewAndTab->addWindow( &maTabCtrl );
1037cdf0e10cSrcweir 
1038cdf0e10cSrcweir     // add the button line
1039cdf0e10cSrcweir     xLayout->addWindow( &maButtonLine );
1040cdf0e10cSrcweir 
1041cdf0e10cSrcweir     // add the row for the buttons
1042cdf0e10cSrcweir     boost::shared_ptr< vcl::RowOrColumn > xButtons( new vcl::RowOrColumn( xLayout.get(), false ) );
1043cdf0e10cSrcweir     nIndex = xLayout->addChild( xButtons );
1044cdf0e10cSrcweir     xLayout->setBorders( nIndex, -1, 0, -1, -1 );
1045cdf0e10cSrcweir 
1046cdf0e10cSrcweir     Size aMinSize( maCancelButton.GetSizePixel() );
1047cdf0e10cSrcweir     // insert help button
1048cdf0e10cSrcweir     xButtons->setMinimumSize( xButtons->addWindow( &maHelpButton ), aMinSize );
1049cdf0e10cSrcweir     // insert a spacer, cancel and OK buttons are right aligned
1050cdf0e10cSrcweir     xSpacer.reset( new vcl::Spacer( xButtons.get(), 2 ) );
1051cdf0e10cSrcweir     xButtons->addChild( xSpacer );
1052cdf0e10cSrcweir     xButtons->setMinimumSize( xButtons->addWindow( &maOKButton ), aMinSize );
1053cdf0e10cSrcweir     xButtons->setMinimumSize( xButtons->addWindow( &maCancelButton ), aMinSize );
1054cdf0e10cSrcweir }
1055cdf0e10cSrcweir 
1056cdf0e10cSrcweir void PrintDialog::readFromSettings()
1057cdf0e10cSrcweir {
1058cdf0e10cSrcweir     maJobPage.readFromSettings();
1059cdf0e10cSrcweir     maNUpPage.readFromSettings();
1060cdf0e10cSrcweir     maOptionsPage.readFromSettings();
1061cdf0e10cSrcweir 
1062cdf0e10cSrcweir     // read last selected tab page; if it exists, actiavte it
1063cdf0e10cSrcweir     SettingsConfigItem* pItem = SettingsConfigItem::get();
1064cdf0e10cSrcweir     rtl::OUString aValue = pItem->getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
1065cdf0e10cSrcweir                                             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LastPage" ) ) );
1066cdf0e10cSrcweir     sal_uInt16 nCount = maTabCtrl.GetPageCount();
1067cdf0e10cSrcweir     for( sal_uInt16 i = 0; i < nCount; i++ )
1068cdf0e10cSrcweir     {
1069cdf0e10cSrcweir         sal_uInt16 nPageId = maTabCtrl.GetPageId( i );
1070cdf0e10cSrcweir         if( aValue.equals( maTabCtrl.GetPageText( nPageId ) ) )
1071cdf0e10cSrcweir         {
1072cdf0e10cSrcweir             maTabCtrl.SelectTabPage( nPageId );
1073cdf0e10cSrcweir             break;
1074cdf0e10cSrcweir         }
1075cdf0e10cSrcweir     }
1076cdf0e10cSrcweir     maOKButton.SetText( maOptionsPage.maToFileBox.IsChecked() ? maPrintToFileText : maPrintText );
1077cdf0e10cSrcweir 
1078cdf0e10cSrcweir     // persistent window state
1079cdf0e10cSrcweir     rtl::OUString aWinState( pItem->getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
1080cdf0e10cSrcweir                                               rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "WindowState" ) ) ) );
1081cdf0e10cSrcweir     if( aWinState.getLength() )
1082cdf0e10cSrcweir         SetWindowState( rtl::OUStringToOString( aWinState, RTL_TEXTENCODING_UTF8 ) );
1083cdf0e10cSrcweir 
1084cdf0e10cSrcweir     if( maOptionsPage.maToFileBox.IsChecked() )
1085cdf0e10cSrcweir     {
1086cdf0e10cSrcweir         maPController->resetPrinterOptions( true );
1087cdf0e10cSrcweir         preparePreview( true, true );
1088cdf0e10cSrcweir     }
1089cdf0e10cSrcweir }
1090cdf0e10cSrcweir 
1091cdf0e10cSrcweir void PrintDialog::storeToSettings()
1092cdf0e10cSrcweir {
1093cdf0e10cSrcweir     maJobPage.storeToSettings();
1094cdf0e10cSrcweir     maNUpPage.storeToSettings();
1095cdf0e10cSrcweir     maOptionsPage.storeToSettings();
1096cdf0e10cSrcweir 
1097cdf0e10cSrcweir     // store last selected printer
1098cdf0e10cSrcweir     SettingsConfigItem* pItem = SettingsConfigItem::get();
1099cdf0e10cSrcweir     pItem->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
1100cdf0e10cSrcweir                      rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LastPrinter" ) ),
1101cdf0e10cSrcweir                      maJobPage.maPrinters.GetSelectEntry() );
1102cdf0e10cSrcweir 
1103cdf0e10cSrcweir     pItem->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
1104cdf0e10cSrcweir                      rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LastPage" ) ),
1105cdf0e10cSrcweir                      maTabCtrl.GetPageText( maTabCtrl.GetCurPageId() ) );
1106cdf0e10cSrcweir     pItem->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
1107cdf0e10cSrcweir                      rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "WindowState" ) ),
1108cdf0e10cSrcweir                      rtl::OStringToOUString( GetWindowState(), RTL_TEXTENCODING_UTF8 )
1109cdf0e10cSrcweir                      );
1110cdf0e10cSrcweir     pItem->Commit();
1111cdf0e10cSrcweir }
1112cdf0e10cSrcweir 
1113cdf0e10cSrcweir bool PrintDialog::isPrintToFile()
1114cdf0e10cSrcweir {
1115cdf0e10cSrcweir     return maOptionsPage.maToFileBox.IsChecked();
1116cdf0e10cSrcweir }
1117cdf0e10cSrcweir 
1118cdf0e10cSrcweir int PrintDialog::getCopyCount()
1119cdf0e10cSrcweir {
1120cdf0e10cSrcweir     return static_cast<int>(maJobPage.maCopyCountField.GetValue());
1121cdf0e10cSrcweir }
1122cdf0e10cSrcweir 
1123cdf0e10cSrcweir bool PrintDialog::isCollate()
1124cdf0e10cSrcweir {
1125cdf0e10cSrcweir     return maJobPage.maCopyCountField.GetValue() > 1 ? maJobPage.maCollateBox.IsChecked() : sal_False;
1126cdf0e10cSrcweir }
1127cdf0e10cSrcweir 
1128cdf0e10cSrcweir bool PrintDialog::isSingleJobs()
1129cdf0e10cSrcweir {
1130cdf0e10cSrcweir     return maOptionsPage.maCollateSingleJobsBox.IsChecked();
1131cdf0e10cSrcweir }
1132cdf0e10cSrcweir 
1133cdf0e10cSrcweir void setHelpId( Window* i_pWindow, const Sequence< rtl::OUString >& i_rHelpIds, sal_Int32 i_nIndex )
1134cdf0e10cSrcweir {
1135cdf0e10cSrcweir     if( i_nIndex >= 0 && i_nIndex < i_rHelpIds.getLength() )
1136cdf0e10cSrcweir         i_pWindow->SetHelpId( rtl::OUStringToOString( i_rHelpIds.getConstArray()[i_nIndex], RTL_TEXTENCODING_UTF8 ) );
1137cdf0e10cSrcweir }
1138cdf0e10cSrcweir 
1139cdf0e10cSrcweir static void setHelpText( Window* i_pWindow, const Sequence< rtl::OUString >& i_rHelpTexts, sal_Int32 i_nIndex )
1140cdf0e10cSrcweir {
1141cdf0e10cSrcweir     // without a help text set and the correct smartID,
1142cdf0e10cSrcweir     // help texts will be retrieved from the online help system
1143cdf0e10cSrcweir     if( i_nIndex >= 0 && i_nIndex < i_rHelpTexts.getLength() )
1144cdf0e10cSrcweir         i_pWindow->SetHelpText( i_rHelpTexts.getConstArray()[i_nIndex] );
1145cdf0e10cSrcweir }
1146cdf0e10cSrcweir 
1147cdf0e10cSrcweir void updateMaxSize( const Size& i_rCheckSize, Size& o_rMaxSize )
1148cdf0e10cSrcweir {
1149cdf0e10cSrcweir     if( i_rCheckSize.Width() > o_rMaxSize.Width() )
1150cdf0e10cSrcweir         o_rMaxSize.Width() = i_rCheckSize.Width();
1151cdf0e10cSrcweir     if( i_rCheckSize.Height() > o_rMaxSize.Height() )
1152cdf0e10cSrcweir         o_rMaxSize.Height() = i_rCheckSize.Height();
1153cdf0e10cSrcweir }
1154cdf0e10cSrcweir 
1155cdf0e10cSrcweir void PrintDialog::setupOptionalUI()
1156cdf0e10cSrcweir {
1157cdf0e10cSrcweir     std::vector< boost::shared_ptr<vcl::RowOrColumn> > aDynamicColumns;
1158cdf0e10cSrcweir     boost::shared_ptr< vcl::RowOrColumn > pCurColumn;
1159cdf0e10cSrcweir 
1160cdf0e10cSrcweir     Window* pCurParent = 0, *pDynamicPageParent = 0;
1161cdf0e10cSrcweir     sal_uInt16 nOptPageId = 9, nCurSubGroup = 0;
1162cdf0e10cSrcweir     bool bOnStaticPage = false;
1163cdf0e10cSrcweir     bool bSubgroupOnStaticPage = false;
1164cdf0e10cSrcweir 
1165cdf0e10cSrcweir     std::multimap< rtl::OUString, boost::shared_ptr<vcl::RowOrColumn> > aPropertyToDependencyRowMap;
1166cdf0e10cSrcweir 
1167cdf0e10cSrcweir     const Sequence< PropertyValue >& rOptions( maPController->getUIOptions() );
1168cdf0e10cSrcweir     for( int i = 0; i < rOptions.getLength(); i++ )
1169cdf0e10cSrcweir     {
1170cdf0e10cSrcweir         Sequence< beans::PropertyValue > aOptProp;
1171cdf0e10cSrcweir         rOptions[i].Value >>= aOptProp;
1172cdf0e10cSrcweir 
1173cdf0e10cSrcweir         // extract ui element
1174cdf0e10cSrcweir         bool bEnabled = true;
1175cdf0e10cSrcweir         rtl::OUString aCtrlType;
1176cdf0e10cSrcweir         rtl::OUString aText;
1177cdf0e10cSrcweir         rtl::OUString aPropertyName;
1178cdf0e10cSrcweir         Sequence< rtl::OUString > aChoices;
1179cdf0e10cSrcweir         Sequence< sal_Bool > aChoicesDisabled;
1180cdf0e10cSrcweir         Sequence< rtl::OUString > aHelpTexts;
1181cdf0e10cSrcweir         Sequence< rtl::OUString > aHelpIds;
1182cdf0e10cSrcweir         sal_Int64 nMinValue = 0, nMaxValue = 0;
1183cdf0e10cSrcweir         sal_Int32 nCurHelpText = 0;
1184cdf0e10cSrcweir         rtl::OUString aGroupingHint;
1185cdf0e10cSrcweir         rtl::OUString aDependsOnName;
1186cdf0e10cSrcweir         sal_Int32 nDependsOnValue = 0;
1187cdf0e10cSrcweir         sal_Bool bUseDependencyRow = sal_False;
1188cdf0e10cSrcweir 
1189cdf0e10cSrcweir         for( int n = 0; n < aOptProp.getLength(); n++ )
1190cdf0e10cSrcweir         {
1191cdf0e10cSrcweir             const beans::PropertyValue& rEntry( aOptProp[ n ] );
1192cdf0e10cSrcweir             if( rEntry.Name.equalsAscii( "Text" ) )
1193cdf0e10cSrcweir             {
1194cdf0e10cSrcweir                 rEntry.Value >>= aText;
1195cdf0e10cSrcweir             }
1196cdf0e10cSrcweir             else if( rEntry.Name.equalsAscii( "ControlType" ) )
1197cdf0e10cSrcweir             {
1198cdf0e10cSrcweir                 rEntry.Value >>= aCtrlType;
1199cdf0e10cSrcweir             }
1200cdf0e10cSrcweir             else if( rEntry.Name.equalsAscii( "Choices" ) )
1201cdf0e10cSrcweir             {
1202cdf0e10cSrcweir                 rEntry.Value >>= aChoices;
1203cdf0e10cSrcweir             }
1204cdf0e10cSrcweir             else if( rEntry.Name.equalsAscii( "ChoicesDisabled" ) )
1205cdf0e10cSrcweir             {
1206cdf0e10cSrcweir                 rEntry.Value >>= aChoicesDisabled;
1207cdf0e10cSrcweir             }
1208cdf0e10cSrcweir             else if( rEntry.Name.equalsAscii( "Property" ) )
1209cdf0e10cSrcweir             {
1210cdf0e10cSrcweir                 PropertyValue aVal;
1211cdf0e10cSrcweir                 rEntry.Value >>= aVal;
1212cdf0e10cSrcweir                 aPropertyName = aVal.Name;
1213cdf0e10cSrcweir             }
1214cdf0e10cSrcweir             else if( rEntry.Name.equalsAscii( "Enabled" ) )
1215cdf0e10cSrcweir             {
1216cdf0e10cSrcweir                 sal_Bool bValue = sal_True;
1217cdf0e10cSrcweir                 rEntry.Value >>= bValue;
1218cdf0e10cSrcweir                 bEnabled = bValue;
1219cdf0e10cSrcweir             }
1220cdf0e10cSrcweir             else if( rEntry.Name.equalsAscii( "GroupingHint" ) )
1221cdf0e10cSrcweir             {
1222cdf0e10cSrcweir                 rEntry.Value >>= aGroupingHint;
1223cdf0e10cSrcweir             }
1224cdf0e10cSrcweir             else if( rEntry.Name.equalsAscii( "DependsOnName" ) )
1225cdf0e10cSrcweir             {
1226cdf0e10cSrcweir                 rEntry.Value >>= aDependsOnName;
1227cdf0e10cSrcweir             }
1228cdf0e10cSrcweir             else if( rEntry.Name.equalsAscii( "DependsOnEntry" ) )
1229cdf0e10cSrcweir             {
1230cdf0e10cSrcweir                 rEntry.Value >>= nDependsOnValue;
1231cdf0e10cSrcweir             }
1232cdf0e10cSrcweir             else if( rEntry.Name.equalsAscii( "AttachToDependency" ) )
1233cdf0e10cSrcweir             {
1234cdf0e10cSrcweir                 rEntry.Value >>= bUseDependencyRow;
1235cdf0e10cSrcweir             }
1236cdf0e10cSrcweir             else if( rEntry.Name.equalsAscii( "MinValue" ) )
1237cdf0e10cSrcweir             {
1238cdf0e10cSrcweir                 rEntry.Value >>= nMinValue;
1239cdf0e10cSrcweir             }
1240cdf0e10cSrcweir             else if( rEntry.Name.equalsAscii( "MaxValue" ) )
1241cdf0e10cSrcweir             {
1242cdf0e10cSrcweir                 rEntry.Value >>= nMaxValue;
1243cdf0e10cSrcweir             }
1244cdf0e10cSrcweir             else if( rEntry.Name.equalsAscii( "HelpText" ) )
1245cdf0e10cSrcweir             {
1246cdf0e10cSrcweir                 if( ! (rEntry.Value >>= aHelpTexts) )
1247cdf0e10cSrcweir                 {
1248cdf0e10cSrcweir                     rtl::OUString aHelpText;
1249cdf0e10cSrcweir                     if( (rEntry.Value >>= aHelpText) )
1250cdf0e10cSrcweir                     {
1251cdf0e10cSrcweir                         aHelpTexts.realloc( 1 );
1252cdf0e10cSrcweir                         *aHelpTexts.getArray() = aHelpText;
1253cdf0e10cSrcweir                     }
1254cdf0e10cSrcweir                 }
1255cdf0e10cSrcweir             }
1256cdf0e10cSrcweir             else if( rEntry.Name.equalsAscii( "HelpId" ) )
1257cdf0e10cSrcweir             {
1258cdf0e10cSrcweir                 if( ! (rEntry.Value >>= aHelpIds ) )
1259cdf0e10cSrcweir                 {
1260cdf0e10cSrcweir                     rtl::OUString aHelpId;
1261cdf0e10cSrcweir                     if( (rEntry.Value >>= aHelpId) )
1262cdf0e10cSrcweir                     {
1263cdf0e10cSrcweir                         aHelpIds.realloc( 1 );
1264cdf0e10cSrcweir                         *aHelpIds.getArray() = aHelpId;
1265cdf0e10cSrcweir                     }
1266cdf0e10cSrcweir                 }
1267cdf0e10cSrcweir             }
1268cdf0e10cSrcweir             else if( rEntry.Name.equalsAscii( "HintNoLayoutPage" ) )
1269cdf0e10cSrcweir             {
1270cdf0e10cSrcweir                 sal_Bool bNoLayoutPage = sal_False;
1271cdf0e10cSrcweir                 rEntry.Value >>= bNoLayoutPage;
1272cdf0e10cSrcweir                 mbShowLayoutPage = ! bNoLayoutPage;
1273cdf0e10cSrcweir             }
1274cdf0e10cSrcweir         }
1275cdf0e10cSrcweir 
1276cdf0e10cSrcweir         // bUseDependencyRow should only be true if a dependency exists
1277cdf0e10cSrcweir         bUseDependencyRow = bUseDependencyRow && (aDependsOnName.getLength() != 0);
1278cdf0e10cSrcweir 
1279cdf0e10cSrcweir         // is it necessary to switch between static and dynamic pages ?
1280cdf0e10cSrcweir         bool bSwitchPage = false;
1281cdf0e10cSrcweir         if( aGroupingHint.getLength() )
1282cdf0e10cSrcweir             bSwitchPage = true;
1283cdf0e10cSrcweir         else if( aCtrlType.equalsAscii( "Subgroup" ) || (bOnStaticPage && ! bSubgroupOnStaticPage )  )
1284cdf0e10cSrcweir             bSwitchPage = true;
1285cdf0e10cSrcweir         if( bSwitchPage )
1286cdf0e10cSrcweir         {
1287cdf0e10cSrcweir             // restore to dynamic
1288cdf0e10cSrcweir             pCurParent = pDynamicPageParent;
1289cdf0e10cSrcweir             if( ! aDynamicColumns.empty() )
1290cdf0e10cSrcweir                 pCurColumn = aDynamicColumns.back();
1291cdf0e10cSrcweir             else
1292cdf0e10cSrcweir                 pCurColumn.reset();
1293cdf0e10cSrcweir             bOnStaticPage = false;
1294cdf0e10cSrcweir             bSubgroupOnStaticPage = false;
1295cdf0e10cSrcweir 
1296cdf0e10cSrcweir             if( aGroupingHint.equalsAscii( "PrintRange" ) )
1297cdf0e10cSrcweir             {
1298cdf0e10cSrcweir                 pCurColumn = maJobPage.mxPrintRange;
1299cdf0e10cSrcweir                 pCurParent = &maJobPage;            // set job page as current parent
1300cdf0e10cSrcweir                 bOnStaticPage = true;
1301cdf0e10cSrcweir             }
1302cdf0e10cSrcweir             else if( aGroupingHint.equalsAscii( "OptionsPage" ) )
1303cdf0e10cSrcweir             {
1304cdf0e10cSrcweir                 pCurColumn = boost::dynamic_pointer_cast<vcl::RowOrColumn>(maOptionsPage.getLayout());
1305cdf0e10cSrcweir                 pCurParent = &maOptionsPage;        // set options page as current parent
1306cdf0e10cSrcweir                 bOnStaticPage = true;
1307cdf0e10cSrcweir             }
1308cdf0e10cSrcweir             else if( aGroupingHint.equalsAscii( "OptionsPageOptGroup" ) )
1309cdf0e10cSrcweir             {
1310cdf0e10cSrcweir                 pCurColumn = maOptionsPage.mxOptGroup;
1311cdf0e10cSrcweir                 pCurParent = &maOptionsPage;        // set options page as current parent
1312cdf0e10cSrcweir                 bOnStaticPage = true;
1313cdf0e10cSrcweir             }
1314cdf0e10cSrcweir             else if( aGroupingHint.equalsAscii( "LayoutPage" ) )
1315cdf0e10cSrcweir             {
1316cdf0e10cSrcweir                 pCurColumn = boost::dynamic_pointer_cast<vcl::RowOrColumn>(maNUpPage.getLayout());
1317cdf0e10cSrcweir                 pCurParent = &maNUpPage;            // set layout page as current parent
1318cdf0e10cSrcweir                 bOnStaticPage = true;
1319cdf0e10cSrcweir             }
1320cdf0e10cSrcweir             else if( aGroupingHint.getLength() )
1321cdf0e10cSrcweir             {
1322cdf0e10cSrcweir                 pCurColumn = boost::dynamic_pointer_cast<vcl::RowOrColumn>(maJobPage.getLayout());
1323cdf0e10cSrcweir                 pCurParent = &maJobPage;            // set job page as current parent
1324cdf0e10cSrcweir                 bOnStaticPage = true;
1325cdf0e10cSrcweir             }
1326cdf0e10cSrcweir         }
1327cdf0e10cSrcweir 
1328cdf0e10cSrcweir         if( aCtrlType.equalsAscii( "Group" ) ||
1329cdf0e10cSrcweir             ( ! pCurParent && ! (bOnStaticPage || aGroupingHint.getLength() ) ) )
1330cdf0e10cSrcweir         {
1331cdf0e10cSrcweir             // add new tab page
1332cdf0e10cSrcweir             TabPage* pNewGroup = new TabPage( &maTabCtrl );
1333cdf0e10cSrcweir             maControls.push_front( pNewGroup );
1334cdf0e10cSrcweir             pDynamicPageParent = pCurParent = pNewGroup;
1335cdf0e10cSrcweir             pNewGroup->SetText( aText );
1336cdf0e10cSrcweir             maTabCtrl.InsertPage( ++nOptPageId, aText );
1337cdf0e10cSrcweir             maTabCtrl.SetTabPage( nOptPageId, pNewGroup );
1338cdf0e10cSrcweir 
1339cdf0e10cSrcweir             // set help id
1340cdf0e10cSrcweir             setHelpId( pNewGroup, aHelpIds, 0 );
1341cdf0e10cSrcweir             // set help text
1342cdf0e10cSrcweir             setHelpText( pNewGroup, aHelpTexts, 0 );
1343cdf0e10cSrcweir 
1344cdf0e10cSrcweir             // reset subgroup counter
1345cdf0e10cSrcweir             nCurSubGroup = 0;
1346cdf0e10cSrcweir 
1347cdf0e10cSrcweir             aDynamicColumns.push_back( boost::dynamic_pointer_cast<vcl::RowOrColumn>(pNewGroup->getLayout()) );
1348cdf0e10cSrcweir             pCurColumn = aDynamicColumns.back();
1349cdf0e10cSrcweir             pCurColumn->setParentWindow( pNewGroup );
1350cdf0e10cSrcweir             bSubgroupOnStaticPage = false;
1351cdf0e10cSrcweir             bOnStaticPage = false;
1352cdf0e10cSrcweir         }
1353cdf0e10cSrcweir         else if( aCtrlType.equalsAscii( "Subgroup" ) && (pCurParent || aGroupingHint.getLength() ) )
1354cdf0e10cSrcweir         {
1355cdf0e10cSrcweir             bSubgroupOnStaticPage = (aGroupingHint.getLength() != 0);
1356cdf0e10cSrcweir             // create group FixedLine
1357cdf0e10cSrcweir             if( ! aGroupingHint.equalsAscii( "PrintRange" ) ||
1358cdf0e10cSrcweir                 ! pCurColumn->countElements() == 0
1359cdf0e10cSrcweir                )
1360cdf0e10cSrcweir             {
1361cdf0e10cSrcweir                 Window* pNewSub = NULL;
1362cdf0e10cSrcweir                 if( aGroupingHint.equalsAscii( "PrintRange" ) )
1363cdf0e10cSrcweir                     pNewSub = new FixedText( pCurParent, WB_VCENTER );
1364cdf0e10cSrcweir                 else
1365cdf0e10cSrcweir                     pNewSub = new FixedLine( pCurParent );
1366cdf0e10cSrcweir                 maControls.push_front( pNewSub );
1367cdf0e10cSrcweir                 pNewSub->SetText( aText );
1368cdf0e10cSrcweir                 pNewSub->Show();
1369cdf0e10cSrcweir 
1370cdf0e10cSrcweir                 // set help id
1371cdf0e10cSrcweir                 setHelpId( pNewSub, aHelpIds, 0 );
1372cdf0e10cSrcweir                 // set help text
1373cdf0e10cSrcweir                 setHelpText( pNewSub, aHelpTexts, 0 );
1374cdf0e10cSrcweir                 // add group to current column
1375cdf0e10cSrcweir                 pCurColumn->addWindow( pNewSub );
1376cdf0e10cSrcweir             }
1377cdf0e10cSrcweir 
1378cdf0e10cSrcweir             // add an indent to the current column
1379cdf0e10cSrcweir             vcl::Indenter* pIndent = new vcl::Indenter( pCurColumn.get(), -1 );
1380cdf0e10cSrcweir             pCurColumn->addChild( pIndent );
1381cdf0e10cSrcweir             // and create a column inside the indent
1382cdf0e10cSrcweir             pCurColumn.reset( new vcl::RowOrColumn( pIndent ) );
1383cdf0e10cSrcweir             pIndent->setChild( pCurColumn );
1384cdf0e10cSrcweir         }
1385cdf0e10cSrcweir         // EVIL
1386cdf0e10cSrcweir         else if( aCtrlType.equalsAscii( "Bool" ) &&
1387cdf0e10cSrcweir                  aGroupingHint.equalsAscii( "LayoutPage" ) &&
1388cdf0e10cSrcweir                  aPropertyName.equalsAscii( "PrintProspect" )
1389cdf0e10cSrcweir                  )
1390cdf0e10cSrcweir         {
1391cdf0e10cSrcweir             maNUpPage.maBrochureBtn.SetText( aText );
1392cdf0e10cSrcweir             maNUpPage.maBrochureBtn.Show();
1393cdf0e10cSrcweir             setHelpText( &maNUpPage.maBrochureBtn, aHelpTexts, 0 );
1394cdf0e10cSrcweir 
1395cdf0e10cSrcweir             sal_Bool bVal = sal_False;
1396cdf0e10cSrcweir             PropertyValue* pVal = maPController->getValue( aPropertyName );
1397cdf0e10cSrcweir             if( pVal )
1398cdf0e10cSrcweir                 pVal->Value >>= bVal;
1399cdf0e10cSrcweir             maNUpPage.maBrochureBtn.Check( bVal );
1400cdf0e10cSrcweir             maNUpPage.maBrochureBtn.Enable( maPController->isUIOptionEnabled( aPropertyName ) && pVal != NULL );
1401cdf0e10cSrcweir             maNUpPage.maBrochureBtn.SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
1402cdf0e10cSrcweir 
1403cdf0e10cSrcweir             maPropertyToWindowMap[ aPropertyName ].push_back( &maNUpPage.maBrochureBtn );
1404cdf0e10cSrcweir             maControlToPropertyMap[&maNUpPage.maBrochureBtn] = aPropertyName;
1405cdf0e10cSrcweir 
1406cdf0e10cSrcweir             aPropertyToDependencyRowMap.insert( std::pair< rtl::OUString, boost::shared_ptr<vcl::RowOrColumn> >( aPropertyName, maNUpPage.mxBrochureDep ) );
1407cdf0e10cSrcweir         }
1408cdf0e10cSrcweir         else
1409cdf0e10cSrcweir         {
1410cdf0e10cSrcweir             boost::shared_ptr<vcl::RowOrColumn> pSaveCurColumn( pCurColumn );
1411cdf0e10cSrcweir 
1412cdf0e10cSrcweir             if( bUseDependencyRow )
1413cdf0e10cSrcweir             {
1414cdf0e10cSrcweir                 // find the correct dependency row (if any)
1415cdf0e10cSrcweir                 std::pair< std::multimap< rtl::OUString, boost::shared_ptr<vcl::RowOrColumn> >::iterator,
1416cdf0e10cSrcweir                            std::multimap< rtl::OUString, boost::shared_ptr<vcl::RowOrColumn> >::iterator > aDepRange;
1417cdf0e10cSrcweir                 aDepRange = aPropertyToDependencyRowMap.equal_range( aDependsOnName );
1418cdf0e10cSrcweir                 if( aDepRange.first != aDepRange.second )
1419cdf0e10cSrcweir                 {
1420cdf0e10cSrcweir                     while( nDependsOnValue && aDepRange.first != aDepRange.second )
1421cdf0e10cSrcweir                     {
1422cdf0e10cSrcweir                         nDependsOnValue--;
1423cdf0e10cSrcweir                         ++aDepRange.first;
1424cdf0e10cSrcweir                     }
1425cdf0e10cSrcweir                     if( aDepRange.first != aPropertyToDependencyRowMap.end() )
1426cdf0e10cSrcweir                     {
1427cdf0e10cSrcweir                         pCurColumn = aDepRange.first->second;
1428cdf0e10cSrcweir                         maReverseDependencySet.insert( aPropertyName );
1429cdf0e10cSrcweir                     }
1430cdf0e10cSrcweir                 }
1431cdf0e10cSrcweir             }
1432cdf0e10cSrcweir             if( aCtrlType.equalsAscii( "Bool" ) && pCurParent )
1433cdf0e10cSrcweir             {
1434cdf0e10cSrcweir                 // add a check box
1435cdf0e10cSrcweir                 CheckBox* pNewBox = new CheckBox( pCurParent );
1436cdf0e10cSrcweir                 maControls.push_front( pNewBox );
1437cdf0e10cSrcweir                 pNewBox->SetText( aText );
1438cdf0e10cSrcweir                 pNewBox->Show();
1439cdf0e10cSrcweir 
1440cdf0e10cSrcweir                 sal_Bool bVal = sal_False;
1441cdf0e10cSrcweir                 PropertyValue* pVal = maPController->getValue( aPropertyName );
1442cdf0e10cSrcweir                 if( pVal )
1443cdf0e10cSrcweir                     pVal->Value >>= bVal;
1444cdf0e10cSrcweir                 pNewBox->Check( bVal );
1445cdf0e10cSrcweir                 pNewBox->SetToggleHdl( LINK( this, PrintDialog, UIOption_CheckHdl ) );
1446cdf0e10cSrcweir 
1447cdf0e10cSrcweir                 maPropertyToWindowMap[ aPropertyName ].push_back( pNewBox );
1448cdf0e10cSrcweir                 maControlToPropertyMap[pNewBox] = aPropertyName;
1449cdf0e10cSrcweir 
1450cdf0e10cSrcweir                 // set help id
1451cdf0e10cSrcweir                 setHelpId( pNewBox, aHelpIds, 0 );
1452cdf0e10cSrcweir                 // set help text
1453cdf0e10cSrcweir                 setHelpText( pNewBox, aHelpTexts, 0 );
1454cdf0e10cSrcweir 
1455cdf0e10cSrcweir                 boost::shared_ptr<vcl::RowOrColumn> pDependencyRow( new vcl::RowOrColumn( pCurColumn.get(), false ) );
1456cdf0e10cSrcweir                 pCurColumn->addChild( pDependencyRow );
1457cdf0e10cSrcweir                 aPropertyToDependencyRowMap.insert( std::pair< rtl::OUString, boost::shared_ptr<vcl::RowOrColumn> >( aPropertyName, pDependencyRow ) );
1458cdf0e10cSrcweir 
1459cdf0e10cSrcweir                 // add checkbox to current column
1460cdf0e10cSrcweir                 pDependencyRow->addWindow( pNewBox );
1461cdf0e10cSrcweir             }
1462cdf0e10cSrcweir             else if( aCtrlType.equalsAscii( "Radio" ) && pCurParent )
1463cdf0e10cSrcweir             {
1464cdf0e10cSrcweir                 boost::shared_ptr<vcl::RowOrColumn> pRadioColumn( pCurColumn );
1465cdf0e10cSrcweir                 if( aText.getLength() )
1466cdf0e10cSrcweir                 {
1467cdf0e10cSrcweir                     // add a FixedText:
1468cdf0e10cSrcweir                     FixedText* pHeading = new FixedText( pCurParent );
1469cdf0e10cSrcweir                     maControls.push_front( pHeading );
1470cdf0e10cSrcweir                     pHeading->SetText( aText );
1471cdf0e10cSrcweir                     pHeading->Show();
1472cdf0e10cSrcweir 
1473cdf0e10cSrcweir                     // set help id
1474cdf0e10cSrcweir                     setHelpId( pHeading, aHelpIds, nCurHelpText );
1475cdf0e10cSrcweir                     // set help text
1476cdf0e10cSrcweir                     setHelpText( pHeading, aHelpTexts, nCurHelpText );
1477cdf0e10cSrcweir                     nCurHelpText++;
1478cdf0e10cSrcweir                     // add fixed text to current column
1479cdf0e10cSrcweir                     pCurColumn->addWindow( pHeading );
1480cdf0e10cSrcweir                     // add an indent to the current column
1481cdf0e10cSrcweir                     vcl::Indenter* pIndent = new vcl::Indenter( pCurColumn.get(), 15 );
1482cdf0e10cSrcweir                     pCurColumn->addChild( pIndent );
1483cdf0e10cSrcweir                     // and create a column inside the indent
1484cdf0e10cSrcweir                     pRadioColumn.reset( new vcl::RowOrColumn( pIndent ) );
1485cdf0e10cSrcweir                     pIndent->setChild( pRadioColumn );
1486cdf0e10cSrcweir                 }
1487cdf0e10cSrcweir                 // iterate options
1488cdf0e10cSrcweir                 sal_Int32 nSelectVal = 0;
1489cdf0e10cSrcweir                 PropertyValue* pVal = maPController->getValue( aPropertyName );
1490cdf0e10cSrcweir                 if( pVal && pVal->Value.hasValue() )
1491cdf0e10cSrcweir                     pVal->Value >>= nSelectVal;
1492cdf0e10cSrcweir                 for( sal_Int32 m = 0; m < aChoices.getLength(); m++ )
1493cdf0e10cSrcweir                 {
1494cdf0e10cSrcweir                     boost::shared_ptr<vcl::LabeledElement> pLabel( new vcl::LabeledElement( pRadioColumn.get(), 1 ) );
1495cdf0e10cSrcweir                     pRadioColumn->addChild( pLabel );
1496cdf0e10cSrcweir                     boost::shared_ptr<vcl::RowOrColumn> pDependencyRow( new vcl::RowOrColumn( pLabel.get(), false ) );
1497cdf0e10cSrcweir                     pLabel->setElement( pDependencyRow );
1498cdf0e10cSrcweir                     aPropertyToDependencyRowMap.insert( std::pair< rtl::OUString, boost::shared_ptr<vcl::RowOrColumn> >( aPropertyName, pDependencyRow ) );
1499cdf0e10cSrcweir 
1500cdf0e10cSrcweir                     RadioButton* pBtn = new RadioButton( pCurParent, m == 0 ? WB_GROUP : 0 );
1501cdf0e10cSrcweir                     maControls.push_front( pBtn );
1502cdf0e10cSrcweir                     pBtn->SetText( aChoices[m] );
1503cdf0e10cSrcweir                     pBtn->Check( m == nSelectVal );
1504cdf0e10cSrcweir                     pBtn->SetToggleHdl( LINK( this, PrintDialog, UIOption_RadioHdl ) );
1505cdf0e10cSrcweir                     if( aChoicesDisabled.getLength() > m && aChoicesDisabled[m] == sal_True )
1506cdf0e10cSrcweir                         pBtn->Enable( sal_False );
1507cdf0e10cSrcweir                     pBtn->Show();
1508cdf0e10cSrcweir                     maPropertyToWindowMap[ aPropertyName ].push_back( pBtn );
1509cdf0e10cSrcweir                     maControlToPropertyMap[pBtn] = aPropertyName;
1510cdf0e10cSrcweir                     maControlToNumValMap[pBtn] = m;
1511cdf0e10cSrcweir 
1512cdf0e10cSrcweir                     // set help id
1513cdf0e10cSrcweir                     setHelpId( pBtn, aHelpIds, nCurHelpText );
1514cdf0e10cSrcweir                     // set help text
1515cdf0e10cSrcweir                     setHelpText( pBtn, aHelpTexts, nCurHelpText );
1516cdf0e10cSrcweir                     nCurHelpText++;
1517cdf0e10cSrcweir                     // add the radio button to the column
1518cdf0e10cSrcweir                     pLabel->setLabel( pBtn );
1519cdf0e10cSrcweir                 }
1520cdf0e10cSrcweir             }
1521cdf0e10cSrcweir             else if( ( aCtrlType.equalsAscii( "List" )   ||
1522cdf0e10cSrcweir                        aCtrlType.equalsAscii( "Range" )  ||
1523cdf0e10cSrcweir                        aCtrlType.equalsAscii( "Edit" )
1524cdf0e10cSrcweir                      ) && pCurParent )
1525cdf0e10cSrcweir             {
1526cdf0e10cSrcweir                 // create a row in the current column
1527cdf0e10cSrcweir                 boost::shared_ptr<vcl::RowOrColumn> pFieldColumn( new vcl::RowOrColumn( pCurColumn.get(), false ) );
1528cdf0e10cSrcweir                 pCurColumn->addChild( pFieldColumn );
1529cdf0e10cSrcweir                 aPropertyToDependencyRowMap.insert( std::pair< rtl::OUString, boost::shared_ptr<vcl::RowOrColumn> >( aPropertyName, pFieldColumn ) );
1530cdf0e10cSrcweir 
1531cdf0e10cSrcweir                 vcl::LabeledElement* pLabel = NULL;
1532cdf0e10cSrcweir                 if( aText.getLength() )
1533cdf0e10cSrcweir                 {
1534cdf0e10cSrcweir                     // add a FixedText:
1535cdf0e10cSrcweir                     FixedText* pHeading = new FixedText( pCurParent, WB_VCENTER );
1536cdf0e10cSrcweir                     maControls.push_front( pHeading );
1537cdf0e10cSrcweir                     pHeading->SetText( aText );
1538cdf0e10cSrcweir                     pHeading->Show();
1539cdf0e10cSrcweir 
1540cdf0e10cSrcweir                     // add to row
1541cdf0e10cSrcweir                     pLabel = new vcl::LabeledElement( pFieldColumn.get(), 2 );
1542cdf0e10cSrcweir                     pFieldColumn->addChild( pLabel );
1543cdf0e10cSrcweir                     pLabel->setLabel( pHeading );
1544cdf0e10cSrcweir                 }
1545cdf0e10cSrcweir 
1546cdf0e10cSrcweir                 if( aCtrlType.equalsAscii( "List" ) )
1547cdf0e10cSrcweir                 {
1548cdf0e10cSrcweir                     ListBox* pList = new ListBox( pCurParent, WB_DROPDOWN | WB_BORDER );
1549cdf0e10cSrcweir                     maControls.push_front( pList );
1550cdf0e10cSrcweir 
1551cdf0e10cSrcweir                     // iterate options
1552cdf0e10cSrcweir                     for( sal_Int32 m = 0; m < aChoices.getLength(); m++ )
1553cdf0e10cSrcweir                     {
1554cdf0e10cSrcweir                         pList->InsertEntry( aChoices[m] );
1555cdf0e10cSrcweir                     }
1556cdf0e10cSrcweir                     sal_Int32 nSelectVal = 0;
1557cdf0e10cSrcweir                     PropertyValue* pVal = maPController->getValue( aPropertyName );
1558cdf0e10cSrcweir                     if( pVal && pVal->Value.hasValue() )
1559cdf0e10cSrcweir                         pVal->Value >>= nSelectVal;
1560cdf0e10cSrcweir                     pList->SelectEntryPos( static_cast<sal_uInt16>(nSelectVal) );
1561cdf0e10cSrcweir                     pList->SetSelectHdl( LINK( this, PrintDialog, UIOption_SelectHdl ) );
1562cdf0e10cSrcweir                     pList->SetDropDownLineCount( static_cast<sal_uInt16>(aChoices.getLength()) );
1563cdf0e10cSrcweir                     pList->Show();
1564cdf0e10cSrcweir 
1565cdf0e10cSrcweir                     // set help id
1566cdf0e10cSrcweir                     setHelpId( pList, aHelpIds, 0 );
1567cdf0e10cSrcweir                     // set help text
1568cdf0e10cSrcweir                     setHelpText( pList, aHelpTexts, 0 );
1569cdf0e10cSrcweir 
1570cdf0e10cSrcweir                     maPropertyToWindowMap[ aPropertyName ].push_back( pList );
1571cdf0e10cSrcweir                     maControlToPropertyMap[pList] = aPropertyName;
1572cdf0e10cSrcweir 
1573cdf0e10cSrcweir                     // finish the pair
1574cdf0e10cSrcweir                     if( pLabel )
1575cdf0e10cSrcweir                         pLabel->setElement( pList );
1576cdf0e10cSrcweir                     else
1577cdf0e10cSrcweir                         pFieldColumn->addWindow( pList );
1578cdf0e10cSrcweir                 }
1579cdf0e10cSrcweir                 else if( aCtrlType.equalsAscii( "Range" ) )
1580cdf0e10cSrcweir                 {
1581cdf0e10cSrcweir                     NumericField* pField = new NumericField( pCurParent, WB_BORDER | WB_SPIN );
1582cdf0e10cSrcweir                     maControls.push_front( pField );
1583cdf0e10cSrcweir 
1584cdf0e10cSrcweir                     // set min/max and current value
1585cdf0e10cSrcweir                     if( nMinValue != nMaxValue )
1586cdf0e10cSrcweir                     {
1587cdf0e10cSrcweir                         pField->SetMin( nMinValue );
1588cdf0e10cSrcweir                         pField->SetMax( nMaxValue );
1589cdf0e10cSrcweir                     }
1590cdf0e10cSrcweir                     sal_Int64 nCurVal = 0;
1591cdf0e10cSrcweir                     PropertyValue* pVal = maPController->getValue( aPropertyName );
1592cdf0e10cSrcweir                     if( pVal && pVal->Value.hasValue() )
1593cdf0e10cSrcweir                         pVal->Value >>= nCurVal;
1594cdf0e10cSrcweir                     pField->SetValue( nCurVal );
1595cdf0e10cSrcweir                     pField->SetModifyHdl( LINK( this, PrintDialog, UIOption_ModifyHdl ) );
1596cdf0e10cSrcweir                     pField->Show();
1597cdf0e10cSrcweir 
1598cdf0e10cSrcweir                     // set help id
1599cdf0e10cSrcweir                     setHelpId( pField, aHelpIds, 0 );
1600cdf0e10cSrcweir                     // set help text
1601cdf0e10cSrcweir                     setHelpText( pField, aHelpTexts, 0 );
1602cdf0e10cSrcweir 
1603cdf0e10cSrcweir                     maPropertyToWindowMap[ aPropertyName ].push_back( pField );
1604cdf0e10cSrcweir                     maControlToPropertyMap[pField] = aPropertyName;
1605cdf0e10cSrcweir 
1606cdf0e10cSrcweir                     // add to row
1607cdf0e10cSrcweir                     if( pLabel )
1608cdf0e10cSrcweir                         pLabel->setElement( pField );
1609cdf0e10cSrcweir                     else
1610cdf0e10cSrcweir                         pFieldColumn->addWindow( pField );
1611cdf0e10cSrcweir                 }
1612cdf0e10cSrcweir                 else if( aCtrlType.equalsAscii( "Edit" ) )
1613cdf0e10cSrcweir                 {
1614cdf0e10cSrcweir                     Edit* pField = new Edit( pCurParent, WB_BORDER );
1615cdf0e10cSrcweir                     maControls.push_front( pField );
1616cdf0e10cSrcweir 
1617cdf0e10cSrcweir                     rtl::OUString aCurVal;
1618cdf0e10cSrcweir                     PropertyValue* pVal = maPController->getValue( aPropertyName );
1619cdf0e10cSrcweir                     if( pVal && pVal->Value.hasValue() )
1620cdf0e10cSrcweir                         pVal->Value >>= aCurVal;
1621cdf0e10cSrcweir                     pField->SetText( aCurVal );
1622cdf0e10cSrcweir                     pField->SetModifyHdl( LINK( this, PrintDialog, UIOption_ModifyHdl ) );
1623cdf0e10cSrcweir                     pField->Show();
1624cdf0e10cSrcweir 
1625cdf0e10cSrcweir                     // set help id
1626cdf0e10cSrcweir                     setHelpId( pField, aHelpIds, 0 );
1627cdf0e10cSrcweir                     // set help text
1628cdf0e10cSrcweir                     setHelpText( pField, aHelpTexts, 0 );
1629cdf0e10cSrcweir 
1630cdf0e10cSrcweir                     maPropertyToWindowMap[ aPropertyName ].push_back( pField );
1631cdf0e10cSrcweir                     maControlToPropertyMap[pField] = aPropertyName;
1632cdf0e10cSrcweir 
1633cdf0e10cSrcweir                     // add to row
1634cdf0e10cSrcweir                     if( pLabel )
1635cdf0e10cSrcweir                         pLabel->setElement( pField );
1636cdf0e10cSrcweir                     else
1637cdf0e10cSrcweir                         pFieldColumn->addWindow( pField, 2 );
1638cdf0e10cSrcweir                 }
1639cdf0e10cSrcweir             }
1640cdf0e10cSrcweir             else
1641cdf0e10cSrcweir             {
1642cdf0e10cSrcweir                 DBG_ERROR( "Unsupported UI option" );
1643cdf0e10cSrcweir             }
1644cdf0e10cSrcweir 
1645cdf0e10cSrcweir             pCurColumn = pSaveCurColumn;
1646cdf0e10cSrcweir         }
1647cdf0e10cSrcweir     }
1648cdf0e10cSrcweir 
1649cdf0e10cSrcweir     // #i106506# if no brochure button, then the singular Pages radio button
1650cdf0e10cSrcweir     // makes no sense, so replace it by a FixedText label
1651cdf0e10cSrcweir     if( ! maNUpPage.maBrochureBtn.IsVisible() )
1652cdf0e10cSrcweir     {
1653cdf0e10cSrcweir         if( maNUpPage.mxPagesBtnLabel.get() )
1654cdf0e10cSrcweir         {
1655cdf0e10cSrcweir             maNUpPage.maPagesBoxTitleTxt.SetText( maNUpPage.maPagesBtn.GetText() );
1656cdf0e10cSrcweir             maNUpPage.maPagesBoxTitleTxt.Show( sal_True );
1657cdf0e10cSrcweir             maNUpPage.mxPagesBtnLabel->setLabel( &maNUpPage.maPagesBoxTitleTxt );
1658cdf0e10cSrcweir             maNUpPage.maPagesBtn.Show( sal_False );
1659cdf0e10cSrcweir         }
1660cdf0e10cSrcweir     }
1661cdf0e10cSrcweir 
1662cdf0e10cSrcweir     // update enable states
1663cdf0e10cSrcweir     checkOptionalControlDependencies();
1664cdf0e10cSrcweir 
1665cdf0e10cSrcweir     // print range empty (currently math only) -> hide print range and spacer line
1666cdf0e10cSrcweir     if( maJobPage.mxPrintRange->countElements() == 0 )
1667cdf0e10cSrcweir     {
1668cdf0e10cSrcweir         maJobPage.mxPrintRange->show( false, false );
1669cdf0e10cSrcweir         maJobPage.maCopySpacer.Show( sal_False );
1670cdf0e10cSrcweir         maJobPage.maReverseOrderBox.Show( sal_False );
1671cdf0e10cSrcweir     }
1672cdf0e10cSrcweir     else
1673cdf0e10cSrcweir     {
1674cdf0e10cSrcweir         // add an indent to the current column
1675cdf0e10cSrcweir         vcl::Indenter* pIndent = new vcl::Indenter( maJobPage.mxPrintRange.get(), -1 );
1676cdf0e10cSrcweir         maJobPage.mxPrintRange->addChild( pIndent );
1677cdf0e10cSrcweir         // and create a column inside the indent
1678cdf0e10cSrcweir         pIndent->setWindow( &maJobPage.maReverseOrderBox );
1679cdf0e10cSrcweir         maJobPage.maReverseOrderBox.Show( sal_True );
1680cdf0e10cSrcweir     }
1681cdf0e10cSrcweir 
1682cdf0e10cSrcweir #ifdef WNT
1683cdf0e10cSrcweir     // FIXME: the GetNativeControlRegion call on Windows has some issues
1684cdf0e10cSrcweir     // (which skew the results of GetOptimalSize())
1685cdf0e10cSrcweir     // however fixing this thoroughly needs to take interaction with paint into
1686cdf0e10cSrcweir     // account, making the right fix less simple. Fix this the right way
1687cdf0e10cSrcweir     // at some point. For now simply add some space at the lowest element
1688cdf0e10cSrcweir     size_t nIndex = maJobPage.getLayout()->countElements();
1689cdf0e10cSrcweir     if( nIndex > 0 ) // sanity check
1690cdf0e10cSrcweir         maJobPage.getLayout()->setBorders( nIndex-1, 0, 0, 0, -1 );
1691cdf0e10cSrcweir #endif
1692cdf0e10cSrcweir 
1693cdf0e10cSrcweir     // create auto mnemomnics now so they can be calculated in layout
1694cdf0e10cSrcweir     ImplWindowAutoMnemonic( &maJobPage );
1695cdf0e10cSrcweir     ImplWindowAutoMnemonic( &maNUpPage );
1696cdf0e10cSrcweir     ImplWindowAutoMnemonic( &maOptionsPage );
1697cdf0e10cSrcweir     ImplWindowAutoMnemonic( this );
1698cdf0e10cSrcweir 
1699cdf0e10cSrcweir     // calculate job page
1700cdf0e10cSrcweir     Size aMaxSize = maJobPage.getLayout()->getOptimalSize( WINDOWSIZE_PREFERRED );
1701cdf0e10cSrcweir     // and layout page
1702cdf0e10cSrcweir     updateMaxSize( maNUpPage.getLayout()->getOptimalSize( WINDOWSIZE_PREFERRED ), aMaxSize );
1703cdf0e10cSrcweir     // and options page
1704cdf0e10cSrcweir     updateMaxSize( maOptionsPage.getLayout()->getOptimalSize( WINDOWSIZE_PREFERRED ), aMaxSize );
1705cdf0e10cSrcweir 
1706cdf0e10cSrcweir     for( std::vector< boost::shared_ptr<vcl::RowOrColumn> >::iterator it = aDynamicColumns.begin();
1707cdf0e10cSrcweir          it != aDynamicColumns.end(); ++it )
1708cdf0e10cSrcweir     {
1709cdf0e10cSrcweir         Size aPageSize( (*it)->getOptimalSize( WINDOWSIZE_PREFERRED ) );
1710cdf0e10cSrcweir         updateMaxSize( aPageSize, aMaxSize );
1711cdf0e10cSrcweir     }
1712cdf0e10cSrcweir 
1713cdf0e10cSrcweir     // resize dialog if necessary
1714cdf0e10cSrcweir     Size aTabSize = maTabCtrl.GetTabPageSizePixel();
1715cdf0e10cSrcweir     maTabCtrl.SetMinimumSizePixel( maTabCtrl.GetSizePixel() );
1716cdf0e10cSrcweir     if( aMaxSize.Height() > aTabSize.Height() || aMaxSize.Width() > aTabSize.Width() )
1717cdf0e10cSrcweir     {
1718cdf0e10cSrcweir         Size aCurSize( GetOutputSizePixel() );
1719cdf0e10cSrcweir         if( aMaxSize.Height() > aTabSize.Height() )
1720cdf0e10cSrcweir 		{
1721cdf0e10cSrcweir             aCurSize.Height() += aMaxSize.Height() - aTabSize.Height();
1722cdf0e10cSrcweir 			aTabSize.Height() = aMaxSize.Height();
1723cdf0e10cSrcweir 		}
1724cdf0e10cSrcweir         if( aMaxSize.Width() > aTabSize.Width() )
1725cdf0e10cSrcweir         {
1726cdf0e10cSrcweir             aCurSize.Width() += aMaxSize.Width() - aTabSize.Width();
1727cdf0e10cSrcweir             // and the tab ctrl needs more space, too
1728cdf0e10cSrcweir             aTabSize.Width() = aMaxSize.Width();
1729cdf0e10cSrcweir         }
1730cdf0e10cSrcweir         maTabCtrl.SetTabPageSizePixel( aTabSize );
1731cdf0e10cSrcweir         maTabCtrl.SetMinimumSizePixel( maTabCtrl.GetSizePixel() );
1732cdf0e10cSrcweir     }
1733cdf0e10cSrcweir 
1734cdf0e10cSrcweir     Size aSz = getLayout()->getOptimalSize( WINDOWSIZE_PREFERRED );
1735cdf0e10cSrcweir     SetOutputSizePixel( aSz );
1736cdf0e10cSrcweir }
1737cdf0e10cSrcweir 
1738cdf0e10cSrcweir void PrintDialog::DataChanged( const DataChangedEvent& i_rDCEvt )
1739cdf0e10cSrcweir {
1740cdf0e10cSrcweir     // react on settings changed
1741cdf0e10cSrcweir     if( i_rDCEvt.GetType() == DATACHANGED_SETTINGS )
1742cdf0e10cSrcweir         checkControlDependencies();
1743cdf0e10cSrcweir     ModalDialog::DataChanged( i_rDCEvt );
1744cdf0e10cSrcweir }
1745cdf0e10cSrcweir 
1746cdf0e10cSrcweir void PrintDialog::checkControlDependencies()
1747cdf0e10cSrcweir {
1748cdf0e10cSrcweir     if( maJobPage.maCopyCountField.GetValue() > 1 )
1749cdf0e10cSrcweir         maJobPage.maCollateBox.Enable( maJobPage.mnCollateUIMode == 0 );
1750cdf0e10cSrcweir     else
1751cdf0e10cSrcweir         maJobPage.maCollateBox.Enable( sal_False );
1752cdf0e10cSrcweir 
1753cdf0e10cSrcweir     Image aImg( maJobPage.maCollateBox.IsChecked() ? maJobPage.maCollateImg : maJobPage.maNoCollateImg );
1754cdf0e10cSrcweir     Image aHCImg( maJobPage.maCollateBox.IsChecked() ? maJobPage.maCollateHCImg : maJobPage.maNoCollateHCImg );
1755cdf0e10cSrcweir     bool bHC = GetSettings().GetStyleSettings().GetHighContrastMode();
1756cdf0e10cSrcweir 
1757cdf0e10cSrcweir     Size aImgSize( aImg.GetSizePixel() );
1758cdf0e10cSrcweir     Size aHCImgSize( aHCImg.GetSizePixel() );
1759cdf0e10cSrcweir 
1760cdf0e10cSrcweir     if( aHCImgSize.Width() > aImgSize.Width() )
1761cdf0e10cSrcweir         aImgSize.Width() = aHCImgSize.Width();
1762cdf0e10cSrcweir     if( aHCImgSize.Height() > aImgSize.Height() )
1763cdf0e10cSrcweir         aImgSize.Height() = aHCImgSize.Height();
1764cdf0e10cSrcweir 
1765cdf0e10cSrcweir     // adjust size of image
1766cdf0e10cSrcweir     maJobPage.maCollateImage.SetSizePixel( aImgSize );
1767cdf0e10cSrcweir     maJobPage.maCollateImage.SetImage( bHC ? aHCImg : aImg );
1768cdf0e10cSrcweir     maJobPage.maCollateImage.SetModeImage( aHCImg, BMP_COLOR_HIGHCONTRAST );
1769cdf0e10cSrcweir     maJobPage.getLayout()->resize();
1770cdf0e10cSrcweir 
1771cdf0e10cSrcweir     // enable setup button only for printers that can be setup
1772cdf0e10cSrcweir     bool bHaveSetup = maPController->getPrinter()->HasSupport( SUPPORT_SETUPDIALOG );
1773cdf0e10cSrcweir     maJobPage.maSetupButton.Enable( bHaveSetup );
1774cdf0e10cSrcweir     if( bHaveSetup )
1775cdf0e10cSrcweir     {
1776cdf0e10cSrcweir         if( ! maJobPage.maSetupButton.IsVisible() )
1777cdf0e10cSrcweir         {
1778cdf0e10cSrcweir             Point aPrinterPos( maJobPage.maPrinters.GetPosPixel() );
1779cdf0e10cSrcweir             Point aSetupPos( maJobPage.maSetupButton.GetPosPixel() );
1780cdf0e10cSrcweir             Size aPrinterSize( maJobPage.maPrinters.GetSizePixel() );
1781cdf0e10cSrcweir             aPrinterSize.Width() = aSetupPos.X() - aPrinterPos.X() - LogicToPixel( Size( 5, 5 ), MapMode( MAP_APPFONT ) ).Width();
1782cdf0e10cSrcweir             maJobPage.maPrinters.SetSizePixel( aPrinterSize );
1783cdf0e10cSrcweir             maJobPage.maSetupButton.Show();
1784cdf0e10cSrcweir             getLayout()->resize();
1785cdf0e10cSrcweir         }
1786cdf0e10cSrcweir     }
1787cdf0e10cSrcweir     else
1788cdf0e10cSrcweir     {
1789cdf0e10cSrcweir         if( maJobPage.maSetupButton.IsVisible() )
1790cdf0e10cSrcweir         {
1791cdf0e10cSrcweir             Point aPrinterPos( maJobPage.maPrinters.GetPosPixel() );
1792cdf0e10cSrcweir             Point aSetupPos( maJobPage.maSetupButton.GetPosPixel() );
1793cdf0e10cSrcweir             Size aPrinterSize( maJobPage.maPrinters.GetSizePixel() );
1794cdf0e10cSrcweir             Size aSetupSize( maJobPage.maSetupButton.GetSizePixel() );
1795cdf0e10cSrcweir             aPrinterSize.Width() = aSetupPos.X() + aSetupSize.Width() - aPrinterPos.X();
1796cdf0e10cSrcweir             maJobPage.maPrinters.SetSizePixel( aPrinterSize );
1797cdf0e10cSrcweir             maJobPage.maSetupButton.Hide();
1798cdf0e10cSrcweir             getLayout()->resize();
1799cdf0e10cSrcweir         }
1800cdf0e10cSrcweir     }
1801cdf0e10cSrcweir }
1802cdf0e10cSrcweir 
1803cdf0e10cSrcweir void PrintDialog::checkOptionalControlDependencies()
1804cdf0e10cSrcweir {
1805cdf0e10cSrcweir     for( std::map< Window*, rtl::OUString >::iterator it = maControlToPropertyMap.begin();
1806cdf0e10cSrcweir          it != maControlToPropertyMap.end(); ++it )
1807cdf0e10cSrcweir     {
1808cdf0e10cSrcweir         bool bShouldbeEnabled = maPController->isUIOptionEnabled( it->second );
1809cdf0e10cSrcweir         if( ! bShouldbeEnabled )
1810cdf0e10cSrcweir         {
1811cdf0e10cSrcweir             // enable controls that are directly attached to a dependency anyway
1812cdf0e10cSrcweir             // if the normally disabled controls get modified, change the dependency
1813cdf0e10cSrcweir             // so the control would be enabled
1814cdf0e10cSrcweir             // example: in print range "Print All" is selected, "Page Range" is then of course
1815cdf0e10cSrcweir             // not selected and the Edit for the Page Range would be disabled
1816cdf0e10cSrcweir             // as a convenience we should enable the Edit anyway and automatically select
1817cdf0e10cSrcweir             // "Page Range" instead of "Print All" if the Edit gets modified
1818cdf0e10cSrcweir             if( maReverseDependencySet.find( it->second ) != maReverseDependencySet.end() )
1819cdf0e10cSrcweir             {
1820cdf0e10cSrcweir                 rtl::OUString aDep( maPController->getDependency( it->second ) );
1821cdf0e10cSrcweir                 // if the dependency is at least enabled, then enable this control anyway
1822cdf0e10cSrcweir                 if( aDep.getLength() && maPController->isUIOptionEnabled( aDep ) )
1823cdf0e10cSrcweir                     bShouldbeEnabled = true;
1824cdf0e10cSrcweir             }
1825cdf0e10cSrcweir         }
1826cdf0e10cSrcweir 
1827cdf0e10cSrcweir         if( bShouldbeEnabled && dynamic_cast<RadioButton*>(it->first) )
1828cdf0e10cSrcweir         {
1829cdf0e10cSrcweir             std::map< Window*, sal_Int32 >::const_iterator r_it = maControlToNumValMap.find( it->first );
1830cdf0e10cSrcweir             if( r_it != maControlToNumValMap.end() )
1831cdf0e10cSrcweir             {
1832cdf0e10cSrcweir                 bShouldbeEnabled = maPController->isUIChoiceEnabled( it->second, r_it->second );
1833cdf0e10cSrcweir             }
1834cdf0e10cSrcweir         }
1835cdf0e10cSrcweir 
1836cdf0e10cSrcweir 
1837cdf0e10cSrcweir         bool bIsEnabled = it->first->IsEnabled();
1838cdf0e10cSrcweir         // Enable does not do a change check first, so can be less cheap than expected
1839cdf0e10cSrcweir         if( bShouldbeEnabled != bIsEnabled )
1840cdf0e10cSrcweir             it->first->Enable( bShouldbeEnabled );
1841cdf0e10cSrcweir     }
1842cdf0e10cSrcweir }
1843cdf0e10cSrcweir 
1844cdf0e10cSrcweir static rtl::OUString searchAndReplace( const rtl::OUString& i_rOrig, const char* i_pRepl, sal_Int32 i_nReplLen, const rtl::OUString& i_rRepl )
1845cdf0e10cSrcweir {
1846cdf0e10cSrcweir     sal_Int32 nPos = i_rOrig.indexOfAsciiL( i_pRepl, i_nReplLen );
1847cdf0e10cSrcweir     if( nPos != -1 )
1848cdf0e10cSrcweir     {
1849cdf0e10cSrcweir         rtl::OUStringBuffer aBuf( i_rOrig.getLength() );
1850cdf0e10cSrcweir         aBuf.append( i_rOrig.getStr(), nPos );
1851cdf0e10cSrcweir         aBuf.append( i_rRepl );
1852cdf0e10cSrcweir         if( nPos + i_nReplLen < i_rOrig.getLength() )
1853cdf0e10cSrcweir             aBuf.append( i_rOrig.getStr() + nPos + i_nReplLen );
1854cdf0e10cSrcweir         return aBuf.makeStringAndClear();
1855cdf0e10cSrcweir     }
1856cdf0e10cSrcweir     return i_rOrig;
1857cdf0e10cSrcweir }
1858cdf0e10cSrcweir 
1859cdf0e10cSrcweir void PrintDialog::updatePrinterText()
1860cdf0e10cSrcweir {
1861cdf0e10cSrcweir     String aDefPrt( Printer::GetDefaultPrinterName() );
1862cdf0e10cSrcweir     const QueueInfo* pInfo = Printer::GetQueueInfo( maJobPage.maPrinters.GetSelectEntry(), true );
1863cdf0e10cSrcweir     if( pInfo )
1864cdf0e10cSrcweir     {
1865cdf0e10cSrcweir         maJobPage.maLocationTxt.SetText( pInfo->GetLocation() );
1866cdf0e10cSrcweir         maJobPage.maCommentTxt.SetText( pInfo->GetComment() );
1867cdf0e10cSrcweir         // FIXME: status text
1868cdf0e10cSrcweir         rtl::OUString aStatus;
1869cdf0e10cSrcweir         if( aDefPrt == pInfo->GetPrinterName() )
1870cdf0e10cSrcweir             aStatus = maDefPrtText;
1871cdf0e10cSrcweir         maJobPage.maStatusTxt.SetText( aStatus );
1872cdf0e10cSrcweir     }
1873cdf0e10cSrcweir     else
1874cdf0e10cSrcweir     {
1875cdf0e10cSrcweir         maJobPage.maLocationTxt.SetText( String() );
1876cdf0e10cSrcweir         maJobPage.maCommentTxt.SetText( String() );
1877cdf0e10cSrcweir         maJobPage.maStatusTxt.SetText( String() );
1878cdf0e10cSrcweir     }
1879cdf0e10cSrcweir }
1880cdf0e10cSrcweir 
1881cdf0e10cSrcweir void PrintDialog::setPreviewText( sal_Int32 )
1882cdf0e10cSrcweir {
1883cdf0e10cSrcweir     rtl::OUString aNewText( searchAndReplace( maPageStr, "%n", 2, rtl::OUString::valueOf( mnCachedPages )  ) );
1884cdf0e10cSrcweir     maNumPagesText.SetText( aNewText );
1885cdf0e10cSrcweir 
1886cdf0e10cSrcweir     // if layout is already established the refresh layout of
1887cdf0e10cSrcweir     // preview controls since text length may have changes
1888cdf0e10cSrcweir     if( mxPreviewCtrls.get() )
1889cdf0e10cSrcweir         mxPreviewCtrls->setManagedArea( mxPreviewCtrls->getManagedArea() );
1890cdf0e10cSrcweir }
1891cdf0e10cSrcweir 
1892cdf0e10cSrcweir void PrintDialog::preparePreview( bool i_bNewPage, bool i_bMayUseCache )
1893cdf0e10cSrcweir {
1894cdf0e10cSrcweir     // page range may have changed depending on options
1895cdf0e10cSrcweir     sal_Int32 nPages = maPController->getFilteredPageCount();
1896cdf0e10cSrcweir     mnCachedPages = nPages;
1897cdf0e10cSrcweir 
1898cdf0e10cSrcweir     if( mnCurPage >= nPages )
1899cdf0e10cSrcweir         mnCurPage = nPages-1;
1900cdf0e10cSrcweir     if( mnCurPage < 0 )
1901cdf0e10cSrcweir         mnCurPage = 0;
1902cdf0e10cSrcweir 
1903cdf0e10cSrcweir     setPreviewText( mnCurPage );
1904cdf0e10cSrcweir 
1905cdf0e10cSrcweir     maPageEdit.SetMin( 1 );
1906cdf0e10cSrcweir     maPageEdit.SetMax( nPages );
1907cdf0e10cSrcweir 
1908cdf0e10cSrcweir     if( i_bNewPage )
1909cdf0e10cSrcweir     {
1910cdf0e10cSrcweir         const MapMode aMapMode( MAP_100TH_MM );
1911cdf0e10cSrcweir         GDIMetaFile aMtf;
1912cdf0e10cSrcweir         boost::shared_ptr<Printer> aPrt( maPController->getPrinter() );
1913cdf0e10cSrcweir         if( nPages > 0 )
1914cdf0e10cSrcweir         {
1915cdf0e10cSrcweir             PrinterController::PageSize aPageSize =
1916cdf0e10cSrcweir                 maPController->getFilteredPageFile( mnCurPage, aMtf, i_bMayUseCache );
1917cdf0e10cSrcweir             if( ! aPageSize.bFullPaper )
1918cdf0e10cSrcweir             {
1919cdf0e10cSrcweir                 Point aOff( aPrt->PixelToLogic( aPrt->GetPageOffsetPixel(), aMapMode ) );
1920cdf0e10cSrcweir                 aMtf.Move( aOff.X(), aOff.Y() );
1921cdf0e10cSrcweir             }
1922cdf0e10cSrcweir         }
1923cdf0e10cSrcweir 
1924cdf0e10cSrcweir         Size aCurPageSize = aPrt->PixelToLogic( aPrt->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) );
1925cdf0e10cSrcweir         maPreviewWindow.setPreview( aMtf, aCurPageSize,
1926cdf0e10cSrcweir                                     aPrt->GetPaperName( false ),
1927cdf0e10cSrcweir                                     nPages > 0 ? rtl::OUString() : maNoPageStr,
1928cdf0e10cSrcweir                                     aPrt->ImplGetDPIX(), aPrt->ImplGetDPIY(),
1929cdf0e10cSrcweir                                     aPrt->GetPrinterOptions().IsConvertToGreyscales()
1930cdf0e10cSrcweir                                    );
1931cdf0e10cSrcweir 
1932cdf0e10cSrcweir         maForwardBtn.Enable( mnCurPage < nPages-1 );
1933cdf0e10cSrcweir         maBackwardBtn.Enable( mnCurPage != 0 );
1934cdf0e10cSrcweir         maPageEdit.Enable( nPages > 1 );
1935cdf0e10cSrcweir     }
1936cdf0e10cSrcweir }
1937cdf0e10cSrcweir 
1938cdf0e10cSrcweir Size PrintDialog::getJobPageSize()
1939cdf0e10cSrcweir {
1940cdf0e10cSrcweir     if( maFirstPageSize.Width() == 0 && maFirstPageSize.Height() == 0)
1941cdf0e10cSrcweir     {
1942cdf0e10cSrcweir         maFirstPageSize = maNupPortraitSize;
1943cdf0e10cSrcweir         GDIMetaFile aMtf;
1944cdf0e10cSrcweir         if( maPController->getPageCountProtected() > 0 )
1945cdf0e10cSrcweir         {
1946cdf0e10cSrcweir             PrinterController::PageSize aPageSize = maPController->getPageFile( 0, aMtf, true );
1947cdf0e10cSrcweir             maFirstPageSize = aPageSize.aSize;
1948cdf0e10cSrcweir         }
1949cdf0e10cSrcweir     }
1950cdf0e10cSrcweir     return maFirstPageSize;
1951cdf0e10cSrcweir }
1952cdf0e10cSrcweir 
1953cdf0e10cSrcweir void PrintDialog::updateNupFromPages()
1954cdf0e10cSrcweir {
1955cdf0e10cSrcweir     long nPages = long(maNUpPage.maNupPagesBox.GetEntryData(maNUpPage.maNupPagesBox.GetSelectEntryPos()));
1956cdf0e10cSrcweir     int nRows   = int(maNUpPage.maNupRowsEdt.GetValue());
1957cdf0e10cSrcweir     int nCols   = int(maNUpPage.maNupColEdt.GetValue());
1958cdf0e10cSrcweir     long nPageMargin  = long(maNUpPage.maPageMarginEdt.Denormalize(maNUpPage.maPageMarginEdt.GetValue( FUNIT_100TH_MM )));
1959cdf0e10cSrcweir     long nSheetMargin = long(maNUpPage.maSheetMarginEdt.Denormalize(maNUpPage.maSheetMarginEdt.GetValue( FUNIT_100TH_MM )));
1960cdf0e10cSrcweir     bool bCustom = false;
1961cdf0e10cSrcweir 
1962cdf0e10cSrcweir     if( nPages == 1 )
1963cdf0e10cSrcweir     {
1964cdf0e10cSrcweir         nRows = nCols = 1;
1965cdf0e10cSrcweir         nSheetMargin = 0;
1966cdf0e10cSrcweir         nPageMargin = 0;
1967cdf0e10cSrcweir     }
1968cdf0e10cSrcweir     else if( nPages == 2 || nPages == 4 || nPages == 6 || nPages == 9 || nPages == 16 )
1969cdf0e10cSrcweir     {
1970cdf0e10cSrcweir         Size aJobPageSize( getJobPageSize() );
1971cdf0e10cSrcweir         bool bPortrait = aJobPageSize.Width() < aJobPageSize.Height();
1972cdf0e10cSrcweir         if( nPages == 2 )
1973cdf0e10cSrcweir         {
1974cdf0e10cSrcweir             if( bPortrait )
1975cdf0e10cSrcweir                 nRows = 1, nCols = 2;
1976cdf0e10cSrcweir             else
1977cdf0e10cSrcweir                 nRows = 2, nCols = 1;
1978cdf0e10cSrcweir         }
1979cdf0e10cSrcweir         else if( nPages == 4 )
1980cdf0e10cSrcweir             nRows = nCols = 2;
1981cdf0e10cSrcweir         else if( nPages == 6 )
1982cdf0e10cSrcweir         {
1983cdf0e10cSrcweir             if( bPortrait )
1984cdf0e10cSrcweir                 nRows = 2, nCols = 3;
1985cdf0e10cSrcweir             else
1986cdf0e10cSrcweir                 nRows = 3, nCols = 2;
1987cdf0e10cSrcweir         }
1988cdf0e10cSrcweir         else if( nPages == 9 )
1989cdf0e10cSrcweir             nRows = nCols = 3;
1990cdf0e10cSrcweir         else if( nPages == 16 )
1991cdf0e10cSrcweir             nRows = nCols = 4;
1992cdf0e10cSrcweir         nPageMargin = 0;
1993cdf0e10cSrcweir         nSheetMargin = 0;
1994cdf0e10cSrcweir     }
1995cdf0e10cSrcweir     else
1996cdf0e10cSrcweir         bCustom = true;
1997cdf0e10cSrcweir 
1998cdf0e10cSrcweir     if( nPages > 1 )
1999cdf0e10cSrcweir     {
2000cdf0e10cSrcweir         // set upper limits for margins based on job page size and rows/columns
2001cdf0e10cSrcweir         Size aSize( getJobPageSize() );
2002cdf0e10cSrcweir 
2003cdf0e10cSrcweir         // maximum sheet distance: 1/2 sheet
2004cdf0e10cSrcweir         long nHorzMax = aSize.Width()/2;
2005cdf0e10cSrcweir         long nVertMax = aSize.Height()/2;
2006cdf0e10cSrcweir         if( nSheetMargin > nHorzMax )
2007cdf0e10cSrcweir             nSheetMargin = nHorzMax;
2008cdf0e10cSrcweir         if( nSheetMargin > nVertMax )
2009cdf0e10cSrcweir             nSheetMargin = nVertMax;
2010cdf0e10cSrcweir 
2011cdf0e10cSrcweir         maNUpPage.maSheetMarginEdt.SetMax(
2012cdf0e10cSrcweir                   maNUpPage.maSheetMarginEdt.Normalize(
2013cdf0e10cSrcweir                            nHorzMax > nVertMax ? nVertMax : nHorzMax ), FUNIT_100TH_MM );
2014cdf0e10cSrcweir 
2015cdf0e10cSrcweir         // maximum page distance
2016cdf0e10cSrcweir         nHorzMax = (aSize.Width() - 2*nSheetMargin);
2017cdf0e10cSrcweir         if( nCols > 1 )
2018cdf0e10cSrcweir             nHorzMax /= (nCols-1);
2019cdf0e10cSrcweir         nVertMax = (aSize.Height() - 2*nSheetMargin);
2020cdf0e10cSrcweir         if( nRows > 1 )
2021cdf0e10cSrcweir             nHorzMax /= (nRows-1);
2022cdf0e10cSrcweir 
2023cdf0e10cSrcweir         if( nPageMargin > nHorzMax )
2024cdf0e10cSrcweir             nPageMargin = nHorzMax;
2025cdf0e10cSrcweir         if( nPageMargin > nVertMax )
2026cdf0e10cSrcweir             nPageMargin = nVertMax;
2027cdf0e10cSrcweir 
2028cdf0e10cSrcweir         maNUpPage.maPageMarginEdt.SetMax(
2029cdf0e10cSrcweir                  maNUpPage.maSheetMarginEdt.Normalize(
2030cdf0e10cSrcweir                            nHorzMax > nVertMax ? nVertMax : nHorzMax ), FUNIT_100TH_MM );
2031cdf0e10cSrcweir     }
2032cdf0e10cSrcweir 
2033cdf0e10cSrcweir     maNUpPage.maNupRowsEdt.SetValue( nRows );
2034cdf0e10cSrcweir     maNUpPage.maNupColEdt.SetValue( nCols );
2035cdf0e10cSrcweir     maNUpPage.maPageMarginEdt.SetValue( maNUpPage.maPageMarginEdt.Normalize( nPageMargin ), FUNIT_100TH_MM );
2036cdf0e10cSrcweir     maNUpPage.maSheetMarginEdt.SetValue( maNUpPage.maSheetMarginEdt.Normalize( nSheetMargin ), FUNIT_100TH_MM );
2037cdf0e10cSrcweir 
2038cdf0e10cSrcweir     maNUpPage.showAdvancedControls( bCustom );
2039cdf0e10cSrcweir     if( bCustom )
2040cdf0e10cSrcweir     {
2041cdf0e10cSrcweir         // see if we have to enlarge the dialog to make the tab page fit
2042cdf0e10cSrcweir         Size aCurSize( maNUpPage.getLayout()->getOptimalSize( WINDOWSIZE_PREFERRED ) );
2043cdf0e10cSrcweir         Size aTabSize( maTabCtrl.GetTabPageSizePixel() );
2044cdf0e10cSrcweir         if( aTabSize.Height() < aCurSize.Height() )
2045cdf0e10cSrcweir         {
2046cdf0e10cSrcweir             Size aDlgSize( GetSizePixel() );
2047cdf0e10cSrcweir             aDlgSize.Height() += aCurSize.Height() - aTabSize.Height();
2048cdf0e10cSrcweir             SetSizePixel( aDlgSize );
2049cdf0e10cSrcweir         }
2050cdf0e10cSrcweir     }
2051cdf0e10cSrcweir 
2052cdf0e10cSrcweir     updateNup();
2053cdf0e10cSrcweir }
2054cdf0e10cSrcweir 
2055cdf0e10cSrcweir void PrintDialog::updateNup()
2056cdf0e10cSrcweir {
2057cdf0e10cSrcweir     int nRows         = int(maNUpPage.maNupRowsEdt.GetValue());
2058cdf0e10cSrcweir     int nCols         = int(maNUpPage.maNupColEdt.GetValue());
2059cdf0e10cSrcweir     long nPageMargin  = long(maNUpPage.maPageMarginEdt.Denormalize(maNUpPage.maPageMarginEdt.GetValue( FUNIT_100TH_MM )));
2060cdf0e10cSrcweir     long nSheetMargin = long(maNUpPage.maSheetMarginEdt.Denormalize(maNUpPage.maSheetMarginEdt.GetValue( FUNIT_100TH_MM )));
2061cdf0e10cSrcweir 
2062cdf0e10cSrcweir     PrinterController::MultiPageSetup aMPS;
2063cdf0e10cSrcweir     aMPS.nRows         = nRows;
2064cdf0e10cSrcweir     aMPS.nColumns      = nCols;
2065cdf0e10cSrcweir     aMPS.nRepeat       = 1;
2066cdf0e10cSrcweir     aMPS.nLeftMargin   =
2067cdf0e10cSrcweir     aMPS.nTopMargin    =
2068cdf0e10cSrcweir     aMPS.nRightMargin  =
2069cdf0e10cSrcweir     aMPS.nBottomMargin = nSheetMargin;
2070cdf0e10cSrcweir 
2071cdf0e10cSrcweir     aMPS.nHorizontalSpacing =
2072cdf0e10cSrcweir     aMPS.nVerticalSpacing   = nPageMargin;
2073cdf0e10cSrcweir 
2074cdf0e10cSrcweir     aMPS.bDrawBorder        = maNUpPage.maBorderCB.IsChecked();
2075cdf0e10cSrcweir 
2076cdf0e10cSrcweir     int nOrderMode = int(sal_IntPtr(maNUpPage.maNupOrderBox.GetEntryData(
2077cdf0e10cSrcweir                            maNUpPage.maNupOrderBox.GetSelectEntryPos() )));
2078cdf0e10cSrcweir     if( nOrderMode == SV_PRINT_PRT_NUP_ORDER_LRTB )
2079cdf0e10cSrcweir         aMPS.nOrder = PrinterController::LRTB;
2080cdf0e10cSrcweir     else if( nOrderMode == SV_PRINT_PRT_NUP_ORDER_TBLR )
2081cdf0e10cSrcweir         aMPS.nOrder = PrinterController::TBLR;
2082cdf0e10cSrcweir     else if( nOrderMode == SV_PRINT_PRT_NUP_ORDER_RLTB )
2083cdf0e10cSrcweir         aMPS.nOrder = PrinterController::RLTB;
2084cdf0e10cSrcweir     else if( nOrderMode == SV_PRINT_PRT_NUP_ORDER_TBRL )
2085cdf0e10cSrcweir         aMPS.nOrder = PrinterController::TBRL;
2086cdf0e10cSrcweir 
2087cdf0e10cSrcweir     int nOrientationMode = int(sal_IntPtr(maNUpPage.maNupOrientationBox.GetEntryData(
2088cdf0e10cSrcweir                                  maNUpPage.maNupOrientationBox.GetSelectEntryPos() )));
2089cdf0e10cSrcweir     if( nOrientationMode == SV_PRINT_PRT_NUP_ORIENTATION_LANDSCAPE )
2090cdf0e10cSrcweir         aMPS.aPaperSize = maNupLandscapeSize;
2091cdf0e10cSrcweir     else if( nOrientationMode == SV_PRINT_PRT_NUP_ORIENTATION_PORTRAIT )
2092cdf0e10cSrcweir         aMPS.aPaperSize = maNupPortraitSize;
2093cdf0e10cSrcweir     else // automatic mode
2094cdf0e10cSrcweir     {
2095cdf0e10cSrcweir         // get size of first real page to see if it is portrait or landscape
2096cdf0e10cSrcweir         // we assume same page sizes for all the pages for this
2097cdf0e10cSrcweir         Size aPageSize = getJobPageSize();
2098cdf0e10cSrcweir 
2099cdf0e10cSrcweir         Size aMultiSize( aPageSize.Width() * nCols, aPageSize.Height() * nRows );
2100cdf0e10cSrcweir         if( aMultiSize.Width() > aMultiSize.Height() ) // fits better on landscape
2101cdf0e10cSrcweir             aMPS.aPaperSize = maNupLandscapeSize;
2102cdf0e10cSrcweir         else
2103cdf0e10cSrcweir             aMPS.aPaperSize = maNupPortraitSize;
2104cdf0e10cSrcweir     }
2105cdf0e10cSrcweir 
2106cdf0e10cSrcweir     maPController->setMultipage( aMPS );
2107cdf0e10cSrcweir 
2108cdf0e10cSrcweir     maNUpPage.maNupOrderWin.setValues( nOrderMode, nCols, nRows );
2109cdf0e10cSrcweir 
2110cdf0e10cSrcweir     preparePreview( true, true );
2111cdf0e10cSrcweir }
2112cdf0e10cSrcweir 
2113cdf0e10cSrcweir IMPL_LINK( PrintDialog, SelectHdl, ListBox*, pBox )
2114cdf0e10cSrcweir {
2115cdf0e10cSrcweir     if(  pBox == &maJobPage.maPrinters )
2116cdf0e10cSrcweir     {
2117cdf0e10cSrcweir         String aNewPrinter( pBox->GetSelectEntry() );
2118cdf0e10cSrcweir         // set new printer
2119cdf0e10cSrcweir         maPController->setPrinter( boost::shared_ptr<Printer>( new Printer( aNewPrinter ) ) );
2120cdf0e10cSrcweir         maPController->resetPrinterOptions( maOptionsPage.maToFileBox.IsChecked() );
2121cdf0e10cSrcweir         // update text fields
2122cdf0e10cSrcweir         updatePrinterText();
2123cdf0e10cSrcweir         preparePreview( true, false );
2124cdf0e10cSrcweir     }
2125cdf0e10cSrcweir     else if( pBox == &maNUpPage.maNupOrientationBox || pBox == &maNUpPage.maNupOrderBox )
2126cdf0e10cSrcweir     {
2127cdf0e10cSrcweir         updateNup();
2128cdf0e10cSrcweir     }
2129cdf0e10cSrcweir     else if( pBox == &maNUpPage.maNupPagesBox )
2130cdf0e10cSrcweir     {
2131cdf0e10cSrcweir         if( !maNUpPage.maPagesBtn.IsChecked() )
2132cdf0e10cSrcweir             maNUpPage.maPagesBtn.Check();
2133cdf0e10cSrcweir         updateNupFromPages();
2134cdf0e10cSrcweir     }
2135cdf0e10cSrcweir 
2136cdf0e10cSrcweir     return 0;
2137cdf0e10cSrcweir }
2138cdf0e10cSrcweir 
2139cdf0e10cSrcweir IMPL_LINK( PrintDialog, ClickHdl, Button*, pButton )
2140cdf0e10cSrcweir {
2141cdf0e10cSrcweir     if( pButton == &maOKButton || pButton == &maCancelButton )
2142cdf0e10cSrcweir     {
2143cdf0e10cSrcweir         storeToSettings();
2144cdf0e10cSrcweir         EndDialog( pButton == &maOKButton );
2145cdf0e10cSrcweir     }
2146cdf0e10cSrcweir     else if( pButton == &maHelpButton )
2147cdf0e10cSrcweir     {
2148cdf0e10cSrcweir         // start help system
2149cdf0e10cSrcweir         Help* pHelp = Application::GetHelp();
2150cdf0e10cSrcweir         if( pHelp )
2151cdf0e10cSrcweir         {
2152cdf0e10cSrcweir             pHelp->Start( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".HelpID:vcl:PrintDialog:OK" ) ), &maOKButton );
2153cdf0e10cSrcweir         }
2154cdf0e10cSrcweir     }
2155cdf0e10cSrcweir     else if( pButton == &maForwardBtn )
2156cdf0e10cSrcweir     {
2157cdf0e10cSrcweir         previewForward();
2158cdf0e10cSrcweir     }
2159cdf0e10cSrcweir     else if( pButton == &maBackwardBtn )
2160cdf0e10cSrcweir     {
2161cdf0e10cSrcweir         previewBackward();
2162cdf0e10cSrcweir     }
2163cdf0e10cSrcweir     else if( pButton == &maOptionsPage.maToFileBox )
2164cdf0e10cSrcweir     {
2165cdf0e10cSrcweir         maOKButton.SetText( maOptionsPage.maToFileBox.IsChecked() ? maPrintToFileText : maPrintText );
2166cdf0e10cSrcweir         maPController->resetPrinterOptions( maOptionsPage.maToFileBox.IsChecked() );
2167cdf0e10cSrcweir         getLayout()->resize();
2168cdf0e10cSrcweir         preparePreview( true, true );
2169cdf0e10cSrcweir     }
2170cdf0e10cSrcweir     else if( pButton == &maNUpPage.maBrochureBtn )
2171cdf0e10cSrcweir     {
2172cdf0e10cSrcweir         PropertyValue* pVal = getValueForWindow( pButton );
2173cdf0e10cSrcweir         if( pVal )
2174cdf0e10cSrcweir         {
2175cdf0e10cSrcweir             sal_Bool bVal = maNUpPage.maBrochureBtn.IsChecked();
2176cdf0e10cSrcweir             pVal->Value <<= bVal;
2177cdf0e10cSrcweir 
2178cdf0e10cSrcweir             checkOptionalControlDependencies();
2179cdf0e10cSrcweir 
2180cdf0e10cSrcweir             // update preview and page settings
2181cdf0e10cSrcweir             preparePreview();
2182cdf0e10cSrcweir         }
2183cdf0e10cSrcweir         if( maNUpPage.maBrochureBtn.IsChecked() )
2184cdf0e10cSrcweir         {
2185cdf0e10cSrcweir             maNUpPage.maNupPagesBox.SelectEntryPos( 0 );
2186cdf0e10cSrcweir             updateNupFromPages();
2187cdf0e10cSrcweir             maNUpPage.showAdvancedControls( false );
2188cdf0e10cSrcweir             maNUpPage.enableNupControls( false );
2189cdf0e10cSrcweir         }
2190cdf0e10cSrcweir     }
2191cdf0e10cSrcweir     else if( pButton == &maNUpPage.maPagesBtn )
2192cdf0e10cSrcweir     {
2193cdf0e10cSrcweir         maNUpPage.enableNupControls( true );
2194cdf0e10cSrcweir         updateNupFromPages();
2195cdf0e10cSrcweir     }
2196cdf0e10cSrcweir     else if( pButton == &maJobPage.maDetailsBtn )
2197cdf0e10cSrcweir     {
2198cdf0e10cSrcweir         bool bShow = maJobPage.maDetailsBtn.IsChecked();
2199cdf0e10cSrcweir         maJobPage.mxDetails->show( bShow );
2200cdf0e10cSrcweir         if( bShow )
2201cdf0e10cSrcweir         {
2202cdf0e10cSrcweir             maDetailsCollapsedSize = GetOutputSizePixel();
2203cdf0e10cSrcweir             // enlarge dialog if necessary
2204cdf0e10cSrcweir             Size aMinSize( maJobPage.getLayout()->getOptimalSize( WINDOWSIZE_MINIMUM ) );
2205cdf0e10cSrcweir             Size aCurSize( maJobPage.GetSizePixel() );
2206cdf0e10cSrcweir             if( aCurSize.Height() < aMinSize.Height() )
2207cdf0e10cSrcweir             {
2208cdf0e10cSrcweir                 Size aDlgSize( GetOutputSizePixel() );
2209cdf0e10cSrcweir                 aDlgSize.Height() += aMinSize.Height() - aCurSize.Height();
2210cdf0e10cSrcweir                 SetOutputSizePixel( aDlgSize );
2211cdf0e10cSrcweir             }
2212cdf0e10cSrcweir             maDetailsExpandedSize = GetOutputSizePixel();
2213cdf0e10cSrcweir         }
2214cdf0e10cSrcweir         else if( maDetailsCollapsedSize.Width() > 0   &&
2215cdf0e10cSrcweir                  maDetailsCollapsedSize.Height() > 0 )
2216cdf0e10cSrcweir         {
2217cdf0e10cSrcweir             // if the user did not resize the dialog
2218cdf0e10cSrcweir             // make it smaller again on collapsing the details
2219cdf0e10cSrcweir             Size aDlgSize( GetOutputSizePixel() );
2220cdf0e10cSrcweir             if( aDlgSize == maDetailsExpandedSize &&
2221cdf0e10cSrcweir                 aDlgSize.Height() > maDetailsCollapsedSize.Height() )
2222cdf0e10cSrcweir             {
2223cdf0e10cSrcweir                 SetOutputSizePixel( maDetailsCollapsedSize );
2224cdf0e10cSrcweir             }
2225cdf0e10cSrcweir         }
2226cdf0e10cSrcweir     }
2227cdf0e10cSrcweir     else if( pButton == &maJobPage.maCollateBox )
2228cdf0e10cSrcweir     {
2229cdf0e10cSrcweir         maPController->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Collate" ) ),
2230cdf0e10cSrcweir                                  makeAny( sal_Bool(isCollate()) ) );
2231cdf0e10cSrcweir         checkControlDependencies();
2232cdf0e10cSrcweir     }
2233cdf0e10cSrcweir     else if( pButton == &maJobPage.maReverseOrderBox )
2234cdf0e10cSrcweir     {
2235cdf0e10cSrcweir         sal_Bool bChecked = maJobPage.maReverseOrderBox.IsChecked();
2236cdf0e10cSrcweir         maPController->setReversePrint( bChecked );
2237cdf0e10cSrcweir         maPController->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintReverse" ) ),
2238cdf0e10cSrcweir                                  makeAny( bChecked ) );
2239cdf0e10cSrcweir         preparePreview( true, true );
2240cdf0e10cSrcweir     }
2241cdf0e10cSrcweir     else if( pButton == &maNUpPage.maBorderCB )
2242cdf0e10cSrcweir     {
2243cdf0e10cSrcweir         updateNup();
2244cdf0e10cSrcweir     }
2245cdf0e10cSrcweir     else
2246cdf0e10cSrcweir     {
2247cdf0e10cSrcweir         if( pButton == &maJobPage.maSetupButton )
2248cdf0e10cSrcweir         {
2249cdf0e10cSrcweir             maPController->setupPrinter( this );
2250cdf0e10cSrcweir             preparePreview( true, true );
2251cdf0e10cSrcweir         }
2252cdf0e10cSrcweir         checkControlDependencies();
2253cdf0e10cSrcweir     }
2254cdf0e10cSrcweir     return 0;
2255cdf0e10cSrcweir }
2256cdf0e10cSrcweir 
2257cdf0e10cSrcweir IMPL_LINK( PrintDialog, ModifyHdl, Edit*, pEdit )
2258cdf0e10cSrcweir {
2259cdf0e10cSrcweir     checkControlDependencies();
2260cdf0e10cSrcweir     if( pEdit == &maNUpPage.maNupRowsEdt || pEdit == &maNUpPage.maNupColEdt ||
2261cdf0e10cSrcweir         pEdit == &maNUpPage.maSheetMarginEdt || pEdit == &maNUpPage.maPageMarginEdt
2262cdf0e10cSrcweir        )
2263cdf0e10cSrcweir     {
2264cdf0e10cSrcweir         updateNupFromPages();
2265cdf0e10cSrcweir     }
2266cdf0e10cSrcweir     else if( pEdit == &maPageEdit )
2267cdf0e10cSrcweir     {
2268cdf0e10cSrcweir         mnCurPage = sal_Int32( maPageEdit.GetValue() - 1 );
2269cdf0e10cSrcweir         preparePreview( true, true );
2270cdf0e10cSrcweir     }
2271cdf0e10cSrcweir     else if( pEdit == &maJobPage.maCopyCountField )
2272cdf0e10cSrcweir     {
2273cdf0e10cSrcweir         maPController->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CopyCount" ) ),
2274cdf0e10cSrcweir                                makeAny( sal_Int32(maJobPage.maCopyCountField.GetValue()) ) );
2275cdf0e10cSrcweir         maPController->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Collate" ) ),
2276cdf0e10cSrcweir                                makeAny( sal_Bool(isCollate()) ) );
2277cdf0e10cSrcweir     }
2278cdf0e10cSrcweir     return 0;
2279cdf0e10cSrcweir }
2280cdf0e10cSrcweir 
2281cdf0e10cSrcweir IMPL_LINK( PrintDialog, UIOptionsChanged, void*, EMPTYARG )
2282cdf0e10cSrcweir {
2283cdf0e10cSrcweir     checkOptionalControlDependencies();
2284cdf0e10cSrcweir     return 0;
2285cdf0e10cSrcweir }
2286cdf0e10cSrcweir 
2287cdf0e10cSrcweir PropertyValue* PrintDialog::getValueForWindow( Window* i_pWindow ) const
2288cdf0e10cSrcweir {
2289cdf0e10cSrcweir     PropertyValue* pVal = NULL;
2290cdf0e10cSrcweir     std::map< Window*, rtl::OUString >::const_iterator it = maControlToPropertyMap.find( i_pWindow );
2291cdf0e10cSrcweir     if( it != maControlToPropertyMap.end() )
2292cdf0e10cSrcweir     {
2293cdf0e10cSrcweir         pVal = maPController->getValue( it->second );
2294cdf0e10cSrcweir         DBG_ASSERT( pVal, "property value not found" );
2295cdf0e10cSrcweir     }
2296cdf0e10cSrcweir     else
2297cdf0e10cSrcweir     {
2298cdf0e10cSrcweir         DBG_ERROR( "changed control not in property map" );
2299cdf0e10cSrcweir     }
2300cdf0e10cSrcweir     return pVal;
2301cdf0e10cSrcweir }
2302cdf0e10cSrcweir 
2303cdf0e10cSrcweir void PrintDialog::updateWindowFromProperty( const rtl::OUString& i_rProperty )
2304cdf0e10cSrcweir {
2305cdf0e10cSrcweir     beans::PropertyValue* pValue = maPController->getValue( i_rProperty );
2306cdf0e10cSrcweir     std::map< rtl::OUString, std::vector< Window* > >::const_iterator it = maPropertyToWindowMap.find( i_rProperty );
2307cdf0e10cSrcweir     if( pValue && it != maPropertyToWindowMap.end() )
2308cdf0e10cSrcweir     {
2309cdf0e10cSrcweir         const std::vector< Window* >& rWindows( it->second );
2310cdf0e10cSrcweir         if( ! rWindows.empty() )
2311cdf0e10cSrcweir         {
2312cdf0e10cSrcweir             sal_Bool bVal = sal_False;
2313cdf0e10cSrcweir             sal_Int32 nVal = -1;
2314cdf0e10cSrcweir             if( pValue->Value >>= bVal )
2315cdf0e10cSrcweir             {
2316cdf0e10cSrcweir                 // we should have a CheckBox for this one
2317cdf0e10cSrcweir                 CheckBox* pBox = dynamic_cast< CheckBox* >( rWindows.front() );
2318cdf0e10cSrcweir                 if( pBox )
2319cdf0e10cSrcweir                 {
2320cdf0e10cSrcweir                     pBox->Check( bVal );
2321cdf0e10cSrcweir                 }
2322cdf0e10cSrcweir                 else if( i_rProperty.equalsAscii( "PrintProspect" ) )
2323cdf0e10cSrcweir                 {
2324cdf0e10cSrcweir                     // EVIL special case
2325cdf0e10cSrcweir                     if( bVal )
2326cdf0e10cSrcweir                         maNUpPage.maBrochureBtn.Check();
2327cdf0e10cSrcweir                     else
2328cdf0e10cSrcweir                         maNUpPage.maPagesBtn.Check();
2329cdf0e10cSrcweir                 }
2330cdf0e10cSrcweir                 else
2331cdf0e10cSrcweir                 {
2332cdf0e10cSrcweir                     DBG_ASSERT( 0, "missing a checkbox" );
2333cdf0e10cSrcweir                 }
2334cdf0e10cSrcweir             }
2335cdf0e10cSrcweir             else if( pValue->Value >>= nVal )
2336cdf0e10cSrcweir             {
2337cdf0e10cSrcweir                 // this could be a ListBox or a RadioButtonGroup
2338cdf0e10cSrcweir                 ListBox* pList = dynamic_cast< ListBox* >( rWindows.front() );
2339cdf0e10cSrcweir                 if( pList )
2340cdf0e10cSrcweir                 {
2341cdf0e10cSrcweir                     pList->SelectEntryPos( static_cast< sal_uInt16 >(nVal) );
2342cdf0e10cSrcweir                 }
2343cdf0e10cSrcweir                 else if( nVal >= 0 && nVal < sal_Int32(rWindows.size() ) )
2344cdf0e10cSrcweir                 {
2345cdf0e10cSrcweir                     RadioButton* pBtn = dynamic_cast< RadioButton* >( rWindows[nVal] );
2346cdf0e10cSrcweir                     DBG_ASSERT( pBtn, "unexpected control for property" );
2347cdf0e10cSrcweir                     if( pBtn )
2348cdf0e10cSrcweir                         pBtn->Check();
2349cdf0e10cSrcweir                 }
2350cdf0e10cSrcweir             }
2351cdf0e10cSrcweir         }
2352cdf0e10cSrcweir     }
2353cdf0e10cSrcweir }
2354cdf0e10cSrcweir 
2355cdf0e10cSrcweir void PrintDialog::makeEnabled( Window* i_pWindow )
2356cdf0e10cSrcweir {
2357cdf0e10cSrcweir     std::map< Window*, rtl::OUString >::const_iterator it = maControlToPropertyMap.find( i_pWindow );
2358cdf0e10cSrcweir     if( it != maControlToPropertyMap.end() )
2359cdf0e10cSrcweir     {
2360cdf0e10cSrcweir         rtl::OUString aDependency( maPController->makeEnabled( it->second ) );
2361cdf0e10cSrcweir         if( aDependency.getLength() )
2362cdf0e10cSrcweir             updateWindowFromProperty( aDependency );
2363cdf0e10cSrcweir     }
2364cdf0e10cSrcweir }
2365cdf0e10cSrcweir 
2366cdf0e10cSrcweir IMPL_LINK( PrintDialog, UIOption_CheckHdl, CheckBox*, i_pBox )
2367cdf0e10cSrcweir {
2368cdf0e10cSrcweir     PropertyValue* pVal = getValueForWindow( i_pBox );
2369cdf0e10cSrcweir     if( pVal )
2370cdf0e10cSrcweir     {
2371cdf0e10cSrcweir         makeEnabled( i_pBox );
2372cdf0e10cSrcweir 
2373cdf0e10cSrcweir         sal_Bool bVal = i_pBox->IsChecked();
2374cdf0e10cSrcweir         pVal->Value <<= bVal;
2375cdf0e10cSrcweir 
2376cdf0e10cSrcweir         checkOptionalControlDependencies();
2377cdf0e10cSrcweir 
2378cdf0e10cSrcweir         // update preview and page settings
2379cdf0e10cSrcweir         preparePreview();
2380cdf0e10cSrcweir     }
2381cdf0e10cSrcweir     return 0;
2382cdf0e10cSrcweir }
2383cdf0e10cSrcweir 
2384cdf0e10cSrcweir IMPL_LINK( PrintDialog, UIOption_RadioHdl, RadioButton*, i_pBtn )
2385cdf0e10cSrcweir {
2386cdf0e10cSrcweir     // this handler gets called for all radiobuttons that get unchecked, too
2387cdf0e10cSrcweir     // however we only want one notificaction for the new value (that is for
2388cdf0e10cSrcweir     // the button that gets checked)
2389cdf0e10cSrcweir     if( i_pBtn->IsChecked() )
2390cdf0e10cSrcweir     {
2391cdf0e10cSrcweir         PropertyValue* pVal = getValueForWindow( i_pBtn );
2392cdf0e10cSrcweir         std::map< Window*, sal_Int32 >::const_iterator it = maControlToNumValMap.find( i_pBtn );
2393cdf0e10cSrcweir         if( pVal && it != maControlToNumValMap.end() )
2394cdf0e10cSrcweir         {
2395cdf0e10cSrcweir             makeEnabled( i_pBtn );
2396cdf0e10cSrcweir 
2397cdf0e10cSrcweir             sal_Int32 nVal = it->second;
2398cdf0e10cSrcweir             pVal->Value <<= nVal;
2399cdf0e10cSrcweir 
2400cdf0e10cSrcweir             checkOptionalControlDependencies();
2401cdf0e10cSrcweir 
2402cdf0e10cSrcweir             // update preview and page settings
2403cdf0e10cSrcweir             preparePreview();
2404cdf0e10cSrcweir         }
2405cdf0e10cSrcweir     }
2406cdf0e10cSrcweir     return 0;
2407cdf0e10cSrcweir }
2408cdf0e10cSrcweir 
2409cdf0e10cSrcweir IMPL_LINK( PrintDialog, UIOption_SelectHdl, ListBox*, i_pBox )
2410cdf0e10cSrcweir {
2411cdf0e10cSrcweir     PropertyValue* pVal = getValueForWindow( i_pBox );
2412cdf0e10cSrcweir     if( pVal )
2413cdf0e10cSrcweir     {
2414cdf0e10cSrcweir         makeEnabled( i_pBox );
2415cdf0e10cSrcweir 
2416cdf0e10cSrcweir         sal_Int32 nVal( i_pBox->GetSelectEntryPos() );
2417cdf0e10cSrcweir         pVal->Value <<= nVal;
2418cdf0e10cSrcweir 
2419cdf0e10cSrcweir         checkOptionalControlDependencies();
2420cdf0e10cSrcweir 
2421cdf0e10cSrcweir         // update preview and page settings
2422cdf0e10cSrcweir         preparePreview();
2423cdf0e10cSrcweir     }
2424cdf0e10cSrcweir     return 0;
2425cdf0e10cSrcweir }
2426cdf0e10cSrcweir 
2427cdf0e10cSrcweir IMPL_LINK( PrintDialog, UIOption_ModifyHdl, Edit*, i_pBox )
2428cdf0e10cSrcweir {
2429cdf0e10cSrcweir     PropertyValue* pVal = getValueForWindow( i_pBox );
2430cdf0e10cSrcweir     if( pVal )
2431cdf0e10cSrcweir     {
2432cdf0e10cSrcweir         makeEnabled( i_pBox );
2433cdf0e10cSrcweir 
2434cdf0e10cSrcweir         NumericField* pNum = dynamic_cast<NumericField*>(i_pBox);
2435cdf0e10cSrcweir         MetricField* pMetric = dynamic_cast<MetricField*>(i_pBox);
2436cdf0e10cSrcweir         if( pNum )
2437cdf0e10cSrcweir         {
2438cdf0e10cSrcweir             sal_Int64 nVal = pNum->GetValue();
2439cdf0e10cSrcweir             pVal->Value <<= nVal;
2440cdf0e10cSrcweir         }
2441cdf0e10cSrcweir         else if( pMetric )
2442cdf0e10cSrcweir         {
2443cdf0e10cSrcweir             sal_Int64 nVal = pMetric->GetValue();
2444cdf0e10cSrcweir             pVal->Value <<= nVal;
2445cdf0e10cSrcweir         }
2446cdf0e10cSrcweir         else
2447cdf0e10cSrcweir         {
2448cdf0e10cSrcweir             rtl::OUString aVal( i_pBox->GetText() );
2449cdf0e10cSrcweir             pVal->Value <<= aVal;
2450cdf0e10cSrcweir         }
2451cdf0e10cSrcweir 
2452cdf0e10cSrcweir         checkOptionalControlDependencies();
2453cdf0e10cSrcweir 
2454cdf0e10cSrcweir         // update preview and page settings
2455cdf0e10cSrcweir         preparePreview();
2456cdf0e10cSrcweir     }
2457cdf0e10cSrcweir     return 0;
2458cdf0e10cSrcweir }
2459cdf0e10cSrcweir 
2460cdf0e10cSrcweir void PrintDialog::Command( const CommandEvent& rEvt )
2461cdf0e10cSrcweir {
2462cdf0e10cSrcweir     if( rEvt.GetCommand() == COMMAND_WHEEL )
2463cdf0e10cSrcweir     {
2464cdf0e10cSrcweir         const CommandWheelData* pWheelData = rEvt.GetWheelData();
2465cdf0e10cSrcweir         if( pWheelData->GetDelta() > 0 )
2466cdf0e10cSrcweir             previewForward();
2467cdf0e10cSrcweir         else if( pWheelData->GetDelta() < 0 )
2468cdf0e10cSrcweir             previewBackward();
2469cdf0e10cSrcweir         /*
2470cdf0e10cSrcweir         else
2471cdf0e10cSrcweir             huh ?
2472cdf0e10cSrcweir         */
2473cdf0e10cSrcweir     }
2474cdf0e10cSrcweir }
2475cdf0e10cSrcweir 
2476cdf0e10cSrcweir void PrintDialog::Resize()
2477cdf0e10cSrcweir {
2478cdf0e10cSrcweir     // maLayout.setManagedArea( Rectangle( Point( 0, 0 ), GetSizePixel() ) );
2479cdf0e10cSrcweir     // and do the preview; however the metafile does not need to be gotten anew
2480cdf0e10cSrcweir     preparePreview( false );
2481cdf0e10cSrcweir 
2482cdf0e10cSrcweir     // do an invalidate for the benefit of the grouping elements
2483cdf0e10cSrcweir     Invalidate();
2484cdf0e10cSrcweir }
2485cdf0e10cSrcweir 
2486cdf0e10cSrcweir void PrintDialog::previewForward()
2487cdf0e10cSrcweir {
2488cdf0e10cSrcweir     maPageEdit.Up();
2489cdf0e10cSrcweir }
2490cdf0e10cSrcweir 
2491cdf0e10cSrcweir void PrintDialog::previewBackward()
2492cdf0e10cSrcweir {
2493cdf0e10cSrcweir     maPageEdit.Down();
2494cdf0e10cSrcweir }
2495cdf0e10cSrcweir 
2496cdf0e10cSrcweir // -----------------------------------------------------------------------------
2497cdf0e10cSrcweir //
2498cdf0e10cSrcweir // PrintProgressDialog
2499cdf0e10cSrcweir //
2500cdf0e10cSrcweir // -----------------------------------------------------------------------------
2501cdf0e10cSrcweir 
2502cdf0e10cSrcweir PrintProgressDialog::PrintProgressDialog( Window* i_pParent, int i_nMax ) :
2503cdf0e10cSrcweir     ModelessDialog( i_pParent, VclResId( SV_DLG_PRINT_PROGRESS ) ),
2504cdf0e10cSrcweir     maText( this, VclResId( SV_PRINT_PROGRESS_TEXT ) ),
2505cdf0e10cSrcweir     maButton( this, VclResId( SV_PRINT_PROGRESS_CANCEL ) ),
2506cdf0e10cSrcweir     mbCanceled( false ),
2507cdf0e10cSrcweir     mnCur( 0 ),
2508cdf0e10cSrcweir     mnMax( i_nMax ),
2509cdf0e10cSrcweir     mnProgressHeight( 15 ),
2510cdf0e10cSrcweir     mbNativeProgress( false )
2511cdf0e10cSrcweir {
2512cdf0e10cSrcweir     FreeResource();
2513cdf0e10cSrcweir 
2514cdf0e10cSrcweir     if( mnMax < 1 )
2515cdf0e10cSrcweir         mnMax = 1;
2516cdf0e10cSrcweir 
2517cdf0e10cSrcweir     maStr = maText.GetText();
2518cdf0e10cSrcweir 
2519cdf0e10cSrcweir     maButton.SetClickHdl( LINK( this, PrintProgressDialog, ClickHdl ) );
2520cdf0e10cSrcweir 
2521cdf0e10cSrcweir }
2522cdf0e10cSrcweir 
2523cdf0e10cSrcweir PrintProgressDialog::~PrintProgressDialog()
2524cdf0e10cSrcweir {
2525cdf0e10cSrcweir }
2526cdf0e10cSrcweir 
2527cdf0e10cSrcweir IMPL_LINK( PrintProgressDialog, ClickHdl, Button*, pButton )
2528cdf0e10cSrcweir {
2529cdf0e10cSrcweir     if( pButton == &maButton )
2530cdf0e10cSrcweir         mbCanceled = true;
2531cdf0e10cSrcweir 
2532cdf0e10cSrcweir     return 0;
2533cdf0e10cSrcweir }
2534cdf0e10cSrcweir 
2535cdf0e10cSrcweir void PrintProgressDialog::implCalcProgressRect()
2536cdf0e10cSrcweir {
2537cdf0e10cSrcweir     if( IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) )
2538cdf0e10cSrcweir     {
2539cdf0e10cSrcweir         ImplControlValue aValue;
2540cdf0e10cSrcweir         Rectangle aControlRegion( Point(), Size( 100, mnProgressHeight ) );
2541cdf0e10cSrcweir         Rectangle aNativeControlRegion, aNativeContentRegion;
2542cdf0e10cSrcweir         if( GetNativeControlRegion( CTRL_PROGRESS, PART_ENTIRE_CONTROL, aControlRegion,
2543cdf0e10cSrcweir                                     CTRL_STATE_ENABLED, aValue, rtl::OUString(),
2544cdf0e10cSrcweir                                     aNativeControlRegion, aNativeContentRegion ) )
2545cdf0e10cSrcweir         {
2546cdf0e10cSrcweir             mnProgressHeight = aNativeControlRegion.GetHeight();
2547cdf0e10cSrcweir         }
2548cdf0e10cSrcweir         mbNativeProgress = true;
2549cdf0e10cSrcweir     }
2550cdf0e10cSrcweir     maProgressRect = Rectangle( Point( 10, maText.GetPosPixel().Y() + maText.GetSizePixel().Height() + 8 ),
2551cdf0e10cSrcweir                                 Size( GetSizePixel().Width() - 20, mnProgressHeight ) );
2552cdf0e10cSrcweir }
2553cdf0e10cSrcweir 
2554cdf0e10cSrcweir void PrintProgressDialog::setProgress( int i_nCurrent, int i_nMax )
2555cdf0e10cSrcweir {
2556cdf0e10cSrcweir     if( maProgressRect.IsEmpty() )
2557cdf0e10cSrcweir         implCalcProgressRect();
2558cdf0e10cSrcweir 
2559cdf0e10cSrcweir     mnCur = i_nCurrent;
2560cdf0e10cSrcweir     if( i_nMax != -1 )
2561cdf0e10cSrcweir         mnMax = i_nMax;
2562cdf0e10cSrcweir 
2563cdf0e10cSrcweir     if( mnMax < 1 )
2564cdf0e10cSrcweir         mnMax = 1;
2565cdf0e10cSrcweir 
2566cdf0e10cSrcweir     rtl::OUString aNewText( searchAndReplace( maStr, "%p", 2, rtl::OUString::valueOf( mnCur ) ) );
2567cdf0e10cSrcweir     aNewText = searchAndReplace( aNewText, "%n", 2, rtl::OUString::valueOf( mnMax ) );
2568cdf0e10cSrcweir     maText.SetText( aNewText );
2569cdf0e10cSrcweir 
2570cdf0e10cSrcweir     // update progress
2571cdf0e10cSrcweir     Invalidate( maProgressRect, INVALIDATE_UPDATE );
2572cdf0e10cSrcweir }
2573cdf0e10cSrcweir 
2574cdf0e10cSrcweir void PrintProgressDialog::tick()
2575cdf0e10cSrcweir {
2576cdf0e10cSrcweir     if( mnCur < mnMax )
2577cdf0e10cSrcweir         setProgress( ++mnCur );
2578cdf0e10cSrcweir }
2579cdf0e10cSrcweir 
2580cdf0e10cSrcweir void PrintProgressDialog::reset()
2581cdf0e10cSrcweir {
2582cdf0e10cSrcweir     mbCanceled = false;
2583cdf0e10cSrcweir     setProgress( 0 );
2584cdf0e10cSrcweir }
2585cdf0e10cSrcweir 
2586cdf0e10cSrcweir void PrintProgressDialog::Paint( const Rectangle& )
2587cdf0e10cSrcweir {
2588cdf0e10cSrcweir     if( maProgressRect.IsEmpty() )
2589cdf0e10cSrcweir         implCalcProgressRect();
2590cdf0e10cSrcweir 
2591cdf0e10cSrcweir     Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
2592cdf0e10cSrcweir 	const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
2593cdf0e10cSrcweir 	Color aPrgsColor = rStyleSettings.GetHighlightColor();
2594cdf0e10cSrcweir 	if ( aPrgsColor == rStyleSettings.GetFaceColor() )
2595cdf0e10cSrcweir 		aPrgsColor = rStyleSettings.GetDarkShadowColor();
2596cdf0e10cSrcweir 	SetLineColor();
2597cdf0e10cSrcweir 	SetFillColor( aPrgsColor );
2598cdf0e10cSrcweir 
2599cdf0e10cSrcweir     const long nOffset = 3;
2600cdf0e10cSrcweir     const long nWidth = 3*mnProgressHeight/2;
2601cdf0e10cSrcweir     const long nFullWidth = nWidth + nOffset;
2602cdf0e10cSrcweir     const long nMaxCount = maProgressRect.GetWidth() / nFullWidth;
2603cdf0e10cSrcweir     DrawProgress( this, maProgressRect.TopLeft(),
2604cdf0e10cSrcweir                         nOffset,
2605cdf0e10cSrcweir                         nWidth,
2606cdf0e10cSrcweir                         mnProgressHeight,
2607cdf0e10cSrcweir                         static_cast<sal_uInt16>(0),
2608cdf0e10cSrcweir                         static_cast<sal_uInt16>(10000*mnCur/mnMax),
2609cdf0e10cSrcweir                         static_cast<sal_uInt16>(10000/nMaxCount),
2610cdf0e10cSrcweir                         maProgressRect
2611cdf0e10cSrcweir                         );
2612cdf0e10cSrcweir     Pop();
2613cdf0e10cSrcweir 
2614cdf0e10cSrcweir     if( ! mbNativeProgress )
2615cdf0e10cSrcweir     {
2616cdf0e10cSrcweir         DecorationView aDecoView( this );
2617cdf0e10cSrcweir         Rectangle aFrameRect( maProgressRect );
2618cdf0e10cSrcweir         aFrameRect.Left() -= nOffset;
2619cdf0e10cSrcweir         aFrameRect.Right() += nOffset;
2620cdf0e10cSrcweir         aFrameRect.Top() -= nOffset;
2621cdf0e10cSrcweir         aFrameRect.Bottom() += nOffset;
2622cdf0e10cSrcweir         aDecoView.DrawFrame( aFrameRect );
2623cdf0e10cSrcweir     }
2624cdf0e10cSrcweir }
2625cdf0e10cSrcweir 
2626