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