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