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