xref: /trunk/main/sdext/source/minimizer/optimizerdialogcontrols.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1  /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sdext.hxx"
30 
31 #include "optimizerdialog.hxx"
32 
33 // -------------------
34 // - OptimizerDialog -
35 // -------------------
36 #include "pppoptimizer.hxx"
37 #include "graphiccollector.hxx"
38 #include "pagecollector.hxx"
39 #include <com/sun/star/presentation/XCustomPresentationSupplier.hpp>
40 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
41 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
42 #include <com/sun/star/awt/FontDescriptor.hpp>
43 #ifndef _COM_SUN_STAR_AWT_XFONTWEIGHT_HPP_
44 #include <com/sun/star/awt/FontWeight.hpp>
45 #endif
46 #include <rtl/ustrbuf.hxx>
47 
48 using namespace ::rtl;
49 using namespace ::com::sun::star::awt;
50 using namespace ::com::sun::star::uno;
51 using namespace ::com::sun::star::util;
52 using namespace ::com::sun::star::lang;
53 using namespace ::com::sun::star::frame;
54 using namespace ::com::sun::star::beans;
55 using namespace ::com::sun::star::script;
56 using namespace ::com::sun::star::drawing;
57 using namespace ::com::sun::star::container;
58 using namespace ::com::sun::star::presentation;
59 
60 // -----------------------------------------------------------------------------
61 
62 void SetBold( OptimizerDialog& rOptimizerDialog, const rtl::OUString& rControl )
63 {
64     FontDescriptor aFontDescriptor;
65     if ( rOptimizerDialog.getControlProperty( rControl, TKGet( TK_FontDescriptor ) ) >>= aFontDescriptor )
66     {
67         aFontDescriptor.Weight = FontWeight::BOLD;
68         rOptimizerDialog.setControlProperty( rControl, TKGet( TK_FontDescriptor ), Any( aFontDescriptor ) );
69     }
70 }
71 
72 // -----------------------------------------------------------------------------
73 
74 rtl::OUString InsertSeparator( OptimizerDialog& rOptimizerDialog, const OUString& rControlName, sal_Int32 nOrientation,
75                         sal_Int32 nPosX, sal_Int32 nPosY, sal_Int32 nWidth, sal_Int32 nHeight )
76 {
77     OUString pNames[] = {
78         TKGet( TK_Height ),
79         TKGet( TK_Orientation ),
80         TKGet( TK_PositionX ),
81         TKGet( TK_PositionY ),
82         TKGet( TK_Step ),
83         TKGet( TK_Width ) };
84 
85     Any pValues[] = {
86         Any( nHeight ),
87         Any( nOrientation ),
88         Any( nPosX ),
89         Any( nPosY ),
90         Any( sal_Int16( 0 ) ),
91         Any( nWidth ) };
92 
93     sal_Int32 nCount = sizeof( pNames ) / sizeof( OUString );
94 
95     Sequence< rtl::OUString >   aNames( pNames, nCount );
96     Sequence< Any >             aValues( pValues, nCount );
97 
98     rOptimizerDialog.insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlFixedLineModel" ) ),
99         rControlName, aNames, aValues );
100     return rControlName;
101 }
102 
103 // -----------------------------------------------------------------------------
104 
105 rtl::OUString InsertButton( OptimizerDialog& rOptimizerDialog, const OUString& rControlName, Reference< XActionListener >& xActionListener,
106     sal_Int32 nXPos, sal_Int32 nYPos, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int16 nTabIndex, sal_Bool bEnabled, PPPOptimizerTokenEnum nResID, sal_Int16 nPushButtonType )
107 {
108     OUString pNames[] = {
109         TKGet( TK_Enabled ),
110         TKGet( TK_Height ),
111         TKGet( TK_Label ),
112         TKGet( TK_PositionX ),
113         TKGet( TK_PositionY ),
114         TKGet( TK_PushButtonType ),
115         TKGet( TK_Step ),
116         TKGet( TK_TabIndex ),
117         TKGet( TK_Width ) };
118 
119     Any pValues[] = {
120         Any( bEnabled  ),
121         Any( nHeight ),
122         Any( rOptimizerDialog.getString( nResID ) ),
123         Any( nXPos ),
124         Any( nYPos ),
125         Any( nPushButtonType ),
126         Any( (sal_Int16)0 ),
127         Any( nTabIndex ),
128         Any( nWidth ) };
129 
130 
131     sal_Int32 nCount = sizeof( pNames ) / sizeof( OUString );
132 
133     Sequence< rtl::OUString >   aNames( pNames, nCount );
134     Sequence< Any >             aValues( pValues, nCount );
135 
136     rOptimizerDialog.insertButton( rControlName, xActionListener, aNames, aValues );
137     return rControlName;
138 }
139 
140 // -----------------------------------------------------------------------------
141 
142 rtl::OUString InsertFixedText( OptimizerDialog& rOptimizerDialog, const rtl::OUString& rControlName, const OUString& rLabel,
143                                 sal_Int32 nXPos, sal_Int32 nYPos, sal_Int32 nWidth, sal_Int32 nHeight, sal_Bool bMultiLine, sal_Bool bBold, sal_Int16 nTabIndex )
144 {
145     OUString pNames[] = {
146         TKGet( TK_Height ),
147         TKGet( TK_Label ),
148         TKGet( TK_MultiLine ),
149         TKGet( TK_PositionX ),
150         TKGet( TK_PositionY ),
151         TKGet( TK_Step ),
152         TKGet( TK_TabIndex ),
153         TKGet( TK_Width ) };
154 
155     Any pValues[] = {
156         Any( nHeight ),
157         Any( rLabel ),
158         Any( bMultiLine ),
159         Any( nXPos ),
160         Any( nYPos ),
161         Any( (sal_Int16)0 ),
162         Any( nTabIndex ),
163         Any( nWidth ) };
164 
165     sal_Int32 nCount = sizeof( pNames ) / sizeof( OUString );
166 
167     Sequence< rtl::OUString >   aNames( pNames, nCount );
168     Sequence< Any >             aValues( pValues, nCount );
169 
170     rOptimizerDialog.insertFixedText( rControlName, aNames, aValues );
171     if ( bBold )
172         SetBold( rOptimizerDialog, rControlName );
173     return rControlName;
174 }
175 
176 // -----------------------------------------------------------------------------
177 
178 rtl::OUString InsertCheckBox( OptimizerDialog& rOptimizerDialog, const OUString& rControlName,
179     const Reference< XItemListener > xItemListener, const OUString& rLabel,
180         sal_Int32 nXPos, sal_Int32 nYPos, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int16 nTabIndex )
181 {
182     OUString pNames[] = {
183         TKGet( TK_Enabled ),
184         TKGet( TK_Height ),
185         TKGet( TK_Label ),
186         TKGet( TK_PositionX ),
187         TKGet( TK_PositionY ),
188         TKGet( TK_Step ),
189         TKGet( TK_TabIndex ),
190         TKGet( TK_Width ) };
191 
192     Any pValues[] = {
193         Any( sal_True ),
194         Any( nHeight ),
195         Any( rLabel ),
196         Any( nXPos ),
197         Any( nYPos ),
198         Any( (sal_Int16)0 ),
199         Any( nTabIndex ),
200         Any( nWidth ) };
201 
202     sal_Int32 nCount = sizeof( pNames ) / sizeof( OUString );
203 
204     Sequence< rtl::OUString >   aNames( pNames, nCount );
205     Sequence< Any >             aValues( pValues, nCount );
206 
207     Reference< XCheckBox > xCheckBox( rOptimizerDialog.insertCheckBox( rControlName, aNames, aValues ) );
208     if ( xItemListener.is() )
209         xCheckBox->addItemListener( xItemListener );
210     return rControlName;
211 }
212 
213 // -----------------------------------------------------------------------------
214 
215 rtl::OUString InsertFormattedField( OptimizerDialog& rOptimizerDialog, const OUString& rControlName,
216         const Reference< XTextListener > xTextListener, const Reference< XSpinListener > xSpinListener, sal_Int32 nXPos, sal_Int32 nYPos, sal_Int32 nWidth,
217             double fEffectiveMin, double fEffectiveMax, sal_Int16 nTabIndex )
218 {
219     OUString pNames[] = {
220         TKGet( TK_EffectiveMax ),
221         TKGet( TK_EffectiveMin ),
222         TKGet( TK_Enabled ),
223         TKGet( TK_Height ),
224         TKGet( TK_PositionX ),
225         TKGet( TK_PositionY ),
226         TKGet( TK_Repeat ),
227         TKGet( TK_Spin ),
228         TKGet( TK_Step ),
229         TKGet( TK_TabIndex ),
230         TKGet( TK_Width ) };
231 
232     Any pValues[] = {
233         Any( fEffectiveMax ),
234         Any( fEffectiveMin ),
235         Any( sal_True ),
236         Any( (sal_Int32)12 ),
237         Any( nXPos ),
238         Any( nYPos ),
239         Any( (sal_Bool)sal_True ),
240         Any( (sal_Bool)sal_True ),
241         Any( (sal_Int16)0 ),
242         Any( nTabIndex ),
243         Any( nWidth ) };
244 
245     sal_Int32 nCount = sizeof( pNames ) / sizeof( OUString );
246 
247     Sequence< rtl::OUString >   aNames( pNames, nCount );
248     Sequence< Any >             aValues( pValues, nCount );
249 
250     Reference< XTextComponent > xTextComponent( rOptimizerDialog.insertFormattedField( rControlName, aNames, aValues ), UNO_QUERY_THROW );
251     if ( xTextListener.is() )
252         xTextComponent->addTextListener( xTextListener );
253     if ( xSpinListener.is() )
254     {
255         Reference< XSpinField > xSpinField( xTextComponent, UNO_QUERY_THROW );
256         xSpinField->addSpinListener( xSpinListener );
257     }
258     return rControlName;
259 }
260 
261 // -----------------------------------------------------------------------------
262 
263 rtl::OUString InsertComboBox( OptimizerDialog& rOptimizerDialog, const OUString& rControlName,
264     const Reference< XTextListener > xTextListener, const sal_Bool bEnabled, const Sequence< OUString >& rItemList,
265         sal_Int32 nXPos, sal_Int32 nYPos, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int16 nTabIndex )
266 {
267     OUString pNames[] = {
268         TKGet( TK_Dropdown ),
269         TKGet( TK_Enabled ),
270         TKGet( TK_Height ),
271         TKGet( TK_LineCount ),
272         TKGet( TK_PositionX ),
273         TKGet( TK_PositionY ),
274         TKGet( TK_Step ),
275         TKGet( TK_StringItemList ),
276         TKGet( TK_TabIndex ),
277         TKGet( TK_Width ) };
278 
279     Any pValues[] = {
280         Any( sal_True ),
281         Any( bEnabled ),
282         Any( nHeight ),
283         Any( (sal_Int16)8),
284         Any( nXPos ),
285         Any( nYPos ),
286         Any( (sal_Int16)0 ),
287         Any( rItemList ),
288         Any( nTabIndex ),
289         Any( nWidth ) };
290 
291     sal_Int32 nCount = sizeof( pNames ) / sizeof( OUString );
292 
293     Sequence< rtl::OUString >   aNames( pNames, nCount );
294     Sequence< Any >             aValues( pValues, nCount );
295 
296     Reference< XTextComponent > xTextComponent( rOptimizerDialog.insertComboBox( rControlName, aNames, aValues ), UNO_QUERY_THROW );
297     if ( xTextListener.is() )
298         xTextComponent->addTextListener( xTextListener );
299     return rControlName;
300 }
301 
302 // -----------------------------------------------------------------------------
303 
304 rtl::OUString InsertRadioButton( OptimizerDialog& rOptimizerDialog, const rtl::OUString& rControlName, const Reference< XItemListener > xItemListener,
305     const OUString& rLabel, sal_Int32 nXPos, sal_Int32 nYPos, sal_Int32 nWidth, sal_Int32 nHeight, sal_Bool bMultiLine, sal_Int16 nTabIndex )
306 {
307     OUString pNames[] = {
308         TKGet( TK_Height ),
309         TKGet( TK_Label ),
310         TKGet( TK_MultiLine ),
311         TKGet( TK_PositionX ),
312         TKGet( TK_PositionY ),
313         TKGet( TK_Step ),
314         TKGet( TK_TabIndex ),
315         TKGet( TK_Width ) };
316 
317     Any pValues[] = {
318         Any( nHeight ),
319         Any( rLabel ),
320         Any( bMultiLine ),
321         Any( nXPos ),
322         Any( nYPos ),
323         Any( (sal_Int16)0 ),
324         Any( nTabIndex ),
325         Any( nWidth ) };
326 
327     sal_Int32 nCount = sizeof( pNames ) / sizeof( OUString );
328 
329     Sequence< rtl::OUString >   aNames( pNames, nCount );
330     Sequence< Any >             aValues( pValues, nCount );
331 
332     Reference< XRadioButton > xRadioButton( rOptimizerDialog.insertRadioButton( rControlName, aNames, aValues ) );
333     if ( xItemListener.is() )
334         xRadioButton->addItemListener( xItemListener );
335     return rControlName;
336 }
337 
338 // -----------------------------------------------------------------------------
339 
340 rtl::OUString InsertListBox( OptimizerDialog& rOptimizerDialog, const OUString& rControlName,
341     const Reference< XActionListener > xActionListener, const sal_Bool bEnabled, const Sequence< OUString >& rItemList,
342         sal_Int32 nXPos, sal_Int32 nYPos, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int16 nTabIndex )
343 {
344     OUString pNames[] = {
345         TKGet( TK_Dropdown ),
346         TKGet( TK_Enabled ),
347         TKGet( TK_Height ),
348         TKGet( TK_LineCount ),
349         TKGet( TK_MultiSelection ),
350         TKGet( TK_PositionX ),
351         TKGet( TK_PositionY ),
352         TKGet( TK_Step ),
353         TKGet( TK_StringItemList ),
354         TKGet( TK_TabIndex ),
355         TKGet( TK_Width ) };
356 
357     Any pValues[] = {
358         Any( sal_True ),
359         Any( bEnabled ),
360         Any( nHeight ),
361         Any( (sal_Int16)8),
362         Any( sal_False ),
363         Any( nXPos ),
364         Any( nYPos ),
365         Any( (sal_Int16)0 ),
366         Any( rItemList ),
367         Any( nTabIndex ),
368         Any( nWidth ) };
369 
370     sal_Int32 nCount = sizeof( pNames ) / sizeof( OUString );
371 
372     Sequence< rtl::OUString >   aNames( pNames, nCount );
373     Sequence< Any >             aValues( pValues, nCount );
374 
375     Reference< XListBox > xListBox( rOptimizerDialog.insertListBox( rControlName, aNames, aValues ) );
376     if ( xListBox.is() )
377         xListBox->addActionListener( xActionListener );
378     return rControlName;
379 }
380 
381 // -----------------------------------------------------------------------------
382 
383 void OptimizerDialog::InitNavigationBar()
384 {
385     sal_Int32   nCancelPosX = OD_DIALOG_WIDTH - BUTTON_WIDTH - 6;
386     sal_Int32   nFinishPosX = nCancelPosX - 6 - BUTTON_WIDTH;
387     sal_Int32   nNextPosX = nFinishPosX - 6 - BUTTON_WIDTH;
388     sal_Int32   nBackPosX = nNextPosX - 3 - BUTTON_WIDTH;
389 
390     InsertSeparator( *this, TKGet( TK_lnNavSep1 ), 0, 0, DIALOG_HEIGHT - 26, OD_DIALOG_WIDTH, 1 );
391     InsertSeparator( *this, TKGet( TK_lnNavSep2 ), 1, 85, 0, 1, BUTTON_POS_Y - 6 );
392 
393     InsertButton( *this, TKGet( TK_btnNavHelp ), mxActionListener, 8, BUTTON_POS_Y, BUTTON_WIDTH, BUTTON_HEIGHT, mnTabIndex++, sal_True, STR_HELP, PushButtonType_STANDARD );
394     InsertButton( *this, TKGet( TK_btnNavBack ), mxActionListener, nBackPosX, BUTTON_POS_Y, BUTTON_WIDTH, BUTTON_HEIGHT, mnTabIndex++, sal_False, STR_BACK, PushButtonType_STANDARD );
395     InsertButton( *this, TKGet( TK_btnNavNext ), mxActionListener, nNextPosX, BUTTON_POS_Y, BUTTON_WIDTH, BUTTON_HEIGHT, mnTabIndex++, sal_True, STR_NEXT, PushButtonType_STANDARD );
396     InsertButton( *this, TKGet( TK_btnNavFinish ), mxActionListener, nFinishPosX, BUTTON_POS_Y, BUTTON_WIDTH, BUTTON_HEIGHT, mnTabIndex++, sal_True, STR_FINISH, PushButtonType_STANDARD );
397     InsertButton( *this, TKGet( TK_btnNavCancel ), mxActionListener, nCancelPosX, BUTTON_POS_Y, BUTTON_WIDTH, BUTTON_HEIGHT, mnTabIndex++, sal_True, STR_CANCEL, PushButtonType_STANDARD );
398 
399     setControlProperty( TKGet( TK_btnNavNext ), TKGet( TK_DefaultButton ), Any( sal_True ) );
400 }
401 
402 // -----------------------------------------------------------------------------
403 
404 void OptimizerDialog::UpdateControlStatesPage0()
405 {
406     sal_uInt32 i;
407     short nSelectedItem = -1;
408     Sequence< OUString > aItemList;
409     const std::vector< OptimizerSettings >& rList( GetOptimizerSettings() );
410     if ( rList.size() > 1 ) // the first session in the list is the actual one -> skipping first one
411     {
412         aItemList.realloc( rList.size() - 1 );
413         for ( i = 1; i < rList.size(); i++ )
414         {
415             aItemList[ i - 1 ] = rList[ i ].maName;
416             if ( nSelectedItem < 0 )
417             {
418                 if ( rList[ i ] == rList[ 0 ] )
419                     nSelectedItem = static_cast< short >( i - 1 );
420             }
421         }
422     }
423     sal_Bool bRemoveButtonEnabled = sal_False;
424     Sequence< short > aSelectedItems;
425     if ( nSelectedItem >= 0 )
426     {
427         aSelectedItems.realloc( 1 );
428         aSelectedItems[ 0 ] = nSelectedItem;
429         if ( nSelectedItem > 2 )    // only allowing to delete custom themes, the first can|t be deleted
430             bRemoveButtonEnabled = sal_True;
431     }
432     setControlProperty( TKGet( TK_ListBox0Pg0 ), TKGet( TK_StringItemList ), Any( aItemList ) );
433     setControlProperty( TKGet( TK_ListBox0Pg0 ), TKGet( TK_SelectedItems ), Any( aSelectedItems ) );
434     setControlProperty( TKGet( TK_Button0Pg0 ), TKGet( TK_Enabled ), Any( bRemoveButtonEnabled ) );
435 }
436 void OptimizerDialog::InitPage0()
437 {
438     Sequence< OUString > aItemList;
439     std::vector< rtl::OUString > aControlList;
440     aControlList.push_back( InsertFixedText( *this, TKGet( TK_FixedText0Pg0 ), getString( STR_INTRODUCTION ), PAGE_POS_X, PAGE_POS_Y, PAGE_WIDTH, 8, sal_False, sal_True, mnTabIndex++ ) );
441     aControlList.push_back( InsertFixedText( *this, TKGet( TK_FixedText1Pg0 ), getString( STR_INTRODUCTION_T ), PAGE_POS_X + 6, PAGE_POS_Y + 14, PAGE_WIDTH - 12, 100, sal_True, sal_False, mnTabIndex++ ) );
442     aControlList.push_back( InsertSeparator( *this, TKGet( TK_Separator1Pg0 ), 0, PAGE_POS_X + 6, DIALOG_HEIGHT - 66, PAGE_WIDTH - 12, 1 ) );
443     aControlList.push_back( InsertFixedText( *this, TKGet( TK_FixedText2Pg0 ), getString( STR_CHOSE_SETTINGS ), PAGE_POS_X + 6, DIALOG_HEIGHT - 60, PAGE_WIDTH - 12, 8, sal_True, sal_False, mnTabIndex++ ) );
444     aControlList.push_back( InsertListBox(  *this, TKGet( TK_ListBox0Pg0 ), mxActionListenerListBox0Pg0, sal_True, aItemList, PAGE_POS_X + 6, DIALOG_HEIGHT - 48, ( OD_DIALOG_WIDTH - 50 ) - ( PAGE_POS_X + 6 ), 12, mnTabIndex++ ) );
445     aControlList.push_back( InsertButton( *this, TKGet( TK_Button0Pg0 ), mxActionListener, OD_DIALOG_WIDTH - 46, DIALOG_HEIGHT - 49, 40, 14, mnTabIndex++, sal_True, STR_REMOVE, PushButtonType_STANDARD ) );
446     maControlPages.push_back( aControlList );
447     DeactivatePage( 0 );
448     UpdateControlStatesPage0();
449 }
450 
451 // -----------------------------------------------------------------------------
452 
453 void OptimizerDialog::UpdateControlStatesPage1()
454 {
455     sal_Bool bDeleteUnusedMasterPages( GetConfigProperty( TK_DeleteUnusedMasterPages, sal_False ) );
456     sal_Bool bDeleteHiddenSlides( GetConfigProperty( TK_DeleteHiddenSlides, sal_False ) );
457     sal_Bool bDeleteNotesPages( GetConfigProperty( TK_DeleteNotesPages, sal_False ) );
458 
459     setControlProperty( TKGet( TK_CheckBox0Pg3 ), TKGet( TK_State ), Any( (sal_Int16)bDeleteUnusedMasterPages ) );
460     setControlProperty( TKGet( TK_CheckBox1Pg3 ), TKGet( TK_State ), Any( (sal_Int16)bDeleteNotesPages ) );
461     setControlProperty( TKGet( TK_CheckBox2Pg3 ), TKGet( TK_State ), Any( (sal_Int16)bDeleteHiddenSlides ) );
462 }
463 void OptimizerDialog::InitPage1()
464 {
465     Sequence< OUString > aCustomShowList;
466     Reference< XModel > xModel( mxController->getModel() );
467     if ( xModel.is() )
468     {
469         Reference< XCustomPresentationSupplier > aXCPSup( xModel, UNO_QUERY_THROW );
470         Reference< XNameContainer > aXCont( aXCPSup->getCustomPresentations() );
471         if ( aXCont.is() )
472             aCustomShowList = aXCont->getElementNames();
473     }
474     std::vector< rtl::OUString > aControlList;
475     aControlList.push_back( InsertFixedText( *this, TKGet( TK_FixedText0Pg3 ), getString( STR_CHOOSE_SLIDES ), PAGE_POS_X, PAGE_POS_Y, PAGE_WIDTH, 8, sal_False, sal_True, mnTabIndex++ ) );
476     aControlList.push_back( InsertCheckBox(  *this, TKGet( TK_CheckBox0Pg3 ), mxItemListener, getString( STR_DELETE_MASTER_PAGES ), PAGE_POS_X + 6, PAGE_POS_Y + 14, PAGE_WIDTH - 12, 8, mnTabIndex++ ) );
477     aControlList.push_back( InsertCheckBox(  *this, TKGet( TK_CheckBox2Pg3 ), mxItemListener, getString( STR_DELETE_HIDDEN_SLIDES ), PAGE_POS_X + 6, PAGE_POS_Y + 28, PAGE_WIDTH - 12, 8, mnTabIndex++ ) );
478     aControlList.push_back( InsertCheckBox(  *this, TKGet( TK_CheckBox3Pg3 ), mxItemListener, getString( STR_CUSTOM_SHOW ), PAGE_POS_X + 6, PAGE_POS_Y + 42, PAGE_WIDTH - 12, 8, mnTabIndex++ ) );
479     aControlList.push_back( InsertListBox(  *this, TKGet( TK_ListBox0Pg3 ), mxActionListener, sal_True, aCustomShowList, PAGE_POS_X + 14, PAGE_POS_Y + 54, 150, 12, mnTabIndex++ ) );
480     aControlList.push_back( InsertCheckBox(  *this, TKGet( TK_CheckBox1Pg3 ), mxItemListener, getString( STR_DELETE_NOTES_PAGES ), PAGE_POS_X + 6, PAGE_POS_Y + 70, PAGE_WIDTH - 12, 8, mnTabIndex++ ) );
481     maControlPages.push_back( aControlList );
482     DeactivatePage( 1 );
483 
484     setControlProperty( TKGet( TK_CheckBox3Pg3 ), TKGet( TK_State ), Any( sal_False ) );
485     setControlProperty( TKGet( TK_CheckBox3Pg3 ), TKGet( TK_Enabled ), Any( aCustomShowList.getLength() != 0 ) );
486     setControlProperty( TKGet( TK_ListBox0Pg3 ), TKGet( TK_Enabled ), Any( sal_False ) );
487 
488     UpdateControlStatesPage1();
489 }
490 
491 // -----------------------------------------------------------------------------
492 
493 void OptimizerDialog::UpdateControlStatesPage2()
494 {
495     sal_Bool bJPEGCompression( GetConfigProperty( TK_JPEGCompression, sal_False ) );
496     sal_Bool bRemoveCropArea( GetConfigProperty( TK_RemoveCropArea, sal_False ) );
497     sal_Bool bEmbedLinkedGraphics( GetConfigProperty( TK_EmbedLinkedGraphics, sal_True ) );
498     sal_Int32 nJPEGQuality( GetConfigProperty( TK_JPEGQuality, (sal_Int32)90 ) );
499 
500     sal_Int32 nImageResolution( GetConfigProperty( TK_ImageResolution, (sal_Int32)0 ) );
501 
502     sal_Int32 nI0, nI1, nI2, nI3;
503     nI0 = nI1 = nI2 = nI3 = 0;
504     OUString aResolutionText;
505     Sequence< OUString > aResolutionItemList( 4 );
506     aResolutionItemList[ 0 ] = getString( STR_IMAGE_RESOLUTION_0 ).getToken( 1, ';', nI0 );
507     aResolutionItemList[ 1 ] = getString( STR_IMAGE_RESOLUTION_1 ).getToken( 1, ';', nI1 );
508     aResolutionItemList[ 2 ] = getString( STR_IMAGE_RESOLUTION_2 ).getToken( 1, ';', nI2 );
509     aResolutionItemList[ 3 ] = getString( STR_IMAGE_RESOLUTION_3 ).getToken( 1, ';', nI3 );
510     nI0 = nI1 = nI2 = nI3 = 0;
511     if ( getString( STR_IMAGE_RESOLUTION_0 ).getToken( 0, ';', nI0 ).toInt32() == nImageResolution )
512         aResolutionText = aResolutionItemList[ 0 ];
513     else if ( getString( STR_IMAGE_RESOLUTION_1 ).getToken( 0, ';', nI1 ).toInt32() == nImageResolution )
514         aResolutionText = aResolutionItemList[ 1 ];
515     else if ( getString( STR_IMAGE_RESOLUTION_2 ).getToken( 0, ';', nI2 ).toInt32() == nImageResolution )
516         aResolutionText = aResolutionItemList[ 2 ];
517     else if ( getString( STR_IMAGE_RESOLUTION_3 ).getToken( 0, ';', nI3 ).toInt32() == nImageResolution )
518         aResolutionText = aResolutionItemList[ 3 ];
519     if ( !aResolutionText.getLength() )
520         aResolutionText = OUString::valueOf( nImageResolution );
521 
522     setControlProperty( TKGet( TK_RadioButton0Pg1 ), TKGet( TK_State ), Any( (sal_Int16)( bJPEGCompression != sal_True ) ) );
523     setControlProperty( TKGet( TK_RadioButton1Pg1 ), TKGet( TK_State ), Any( (sal_Int16)( bJPEGCompression != sal_False ) ) );
524     setControlProperty( TKGet( TK_FixedText1Pg1  ), TKGet( TK_Enabled ), Any( bJPEGCompression ) );
525     setControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_Enabled ), Any( bJPEGCompression ) );
526     setControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_EffectiveValue ), Any( (double)nJPEGQuality ) );
527     setControlProperty( TKGet( TK_CheckBox1Pg1 ), TKGet( TK_State ), Any( (sal_Int16)bRemoveCropArea ) );
528     setControlProperty( TKGet( TK_ComboBox0Pg1 ), TKGet( TK_Text ), Any( aResolutionText ) );
529     setControlProperty( TKGet( TK_CheckBox2Pg1 ), TKGet( TK_State ), Any( (sal_Int16)bEmbedLinkedGraphics ) );
530 }
531 void OptimizerDialog::InitPage2()
532 {
533     sal_Int32 nI0, nI1, nI2, nI3;
534     nI0 = nI1 = nI2 = nI3 = 0;
535     Sequence< OUString > aResolutionItemList( 4 );
536     aResolutionItemList[ 0 ] = getString( STR_IMAGE_RESOLUTION_0 ).getToken( 1, ';', nI0 );
537     aResolutionItemList[ 1 ] = getString( STR_IMAGE_RESOLUTION_1 ).getToken( 1, ';', nI1 );
538     aResolutionItemList[ 2 ] = getString( STR_IMAGE_RESOLUTION_2 ).getToken( 1, ';', nI2 );
539     aResolutionItemList[ 3 ] = getString( STR_IMAGE_RESOLUTION_3 ).getToken( 1, ';', nI3 );
540 
541     std::vector< rtl::OUString > aControlList;
542     aControlList.push_back( InsertFixedText( *this, TKGet( TK_FixedText0Pg1 ), getString( STR_GRAPHIC_OPTIMIZATION ), PAGE_POS_X, PAGE_POS_Y, PAGE_WIDTH, 8, sal_False, sal_True, mnTabIndex++ ) );
543     aControlList.push_back( InsertRadioButton( *this, TKGet( TK_RadioButton0Pg1 ), mxItemListener, getString( STR_LOSSLESS_COMPRESSION ), PAGE_POS_X + 6, PAGE_POS_Y + 14, PAGE_WIDTH - 12, 8, sal_False, mnTabIndex++ ) );
544     aControlList.push_back( InsertRadioButton( *this, TKGet( TK_RadioButton1Pg1 ), mxItemListener, getString( STR_JPEG_COMPRESSION ), PAGE_POS_X + 6, PAGE_POS_Y + 28, PAGE_WIDTH - 12, 8, sal_False, mnTabIndex++ ) );
545     aControlList.push_back( InsertFixedText( *this, TKGet( TK_FixedText1Pg1 ), getString( STR_QUALITY ), PAGE_POS_X + 20, PAGE_POS_Y + 40, 72, 8, sal_False, sal_False, mnTabIndex++ ) );
546     aControlList.push_back( InsertFormattedField( *this, TKGet( TK_FormattedField0Pg1 ), mxTextListenerFormattedField0Pg1, mxSpinListenerFormattedField0Pg1, PAGE_POS_X + 106, PAGE_POS_Y + 38, 50, 0, 100, mnTabIndex++ ) );
547     aControlList.push_back( InsertFixedText( *this, TKGet( TK_FixedText2Pg1 ), getString( STR_IMAGE_RESOLUTION ), PAGE_POS_X + 6, PAGE_POS_Y + 54, 94, 8, sal_False, sal_False, mnTabIndex++ ) );
548     aControlList.push_back( InsertComboBox(  *this, TKGet( TK_ComboBox0Pg1 ), mxTextListenerComboBox0Pg1, sal_True, aResolutionItemList, PAGE_POS_X + 106, PAGE_POS_Y + 52, 100, 12, mnTabIndex++ ) );
549     aControlList.push_back( InsertCheckBox(  *this, TKGet( TK_CheckBox1Pg1 ), mxItemListener, getString( STR_REMOVE_CROP_AREA ), PAGE_POS_X + 6, PAGE_POS_Y + 68, PAGE_WIDTH - 12, 8, mnTabIndex++ ) );
550     aControlList.push_back( InsertCheckBox(  *this, TKGet( TK_CheckBox2Pg1 ), mxItemListener, getString( STR_EMBED_LINKED_GRAPHICS ), PAGE_POS_X + 6, PAGE_POS_Y + 82, PAGE_WIDTH - 12, 8, mnTabIndex++ ) );
551     maControlPages.push_back( aControlList );
552     DeactivatePage( 2 );
553     UpdateControlStatesPage2();
554 }
555 
556 // -----------------------------------------------------------------------------
557 
558 void OptimizerDialog::UpdateControlStatesPage3()
559 {
560     sal_Bool bConvertOLEObjects( GetConfigProperty( TK_OLEOptimization, sal_False ) );
561     sal_Int16 nOLEOptimizationType( GetConfigProperty( TK_OLEOptimizationType, (sal_Int16)0 ) );
562 
563     setControlProperty( TKGet( TK_CheckBox0Pg2 ), TKGet( TK_State ), Any( (sal_Int16)bConvertOLEObjects ) );
564     setControlProperty( TKGet( TK_RadioButton0Pg2 ), TKGet( TK_Enabled ), Any( bConvertOLEObjects ) );
565     setControlProperty( TKGet( TK_RadioButton0Pg2 ), TKGet( TK_State ), Any( (sal_Int16)( nOLEOptimizationType == 0 ) ) );
566     setControlProperty( TKGet( TK_RadioButton1Pg2 ), TKGet( TK_Enabled ), Any( bConvertOLEObjects ) );
567     setControlProperty( TKGet( TK_RadioButton1Pg2 ), TKGet( TK_State ), Any( (sal_Int16)( nOLEOptimizationType == 1 ) ) );
568 }
569 void OptimizerDialog::InitPage3()
570 {
571     int nOLECount = 0;
572     Reference< XModel > xModel( mxController->getModel() );
573     Reference< XDrawPagesSupplier > xDrawPagesSupplier( xModel, UNO_QUERY_THROW );
574     Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY_THROW );
575     for ( sal_Int32 i = 0; i < xDrawPages->getCount(); i++ )
576     {
577         Reference< XShapes > xShapes( xDrawPages->getByIndex( i ), UNO_QUERY_THROW );
578         for ( sal_Int32 j = 0; j < xShapes->getCount(); j++ )
579         {
580             const OUString sOLE2Shape( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.OLE2Shape" ) );
581             Reference< XShape > xShape( xShapes->getByIndex( j ), UNO_QUERY_THROW );
582             if ( xShape->getShapeType() == sOLE2Shape )
583                 nOLECount++;
584         }
585     }
586 
587     std::vector< rtl::OUString > aControlList;
588     aControlList.push_back( InsertFixedText( *this, TKGet( TK_FixedText0Pg2 ), getString( STR_OLE_OPTIMIZATION ), PAGE_POS_X, PAGE_POS_Y, PAGE_WIDTH, 8, sal_False, sal_True, mnTabIndex++ ) );
589     aControlList.push_back( InsertCheckBox(  *this, TKGet( TK_CheckBox0Pg2 ), mxItemListener, getString( STR_OLE_REPLACE ), PAGE_POS_X + 6, PAGE_POS_Y + 14, PAGE_WIDTH - 12, 8, mnTabIndex++ ) );
590     aControlList.push_back( InsertRadioButton( *this, TKGet( TK_RadioButton0Pg2 ), mxItemListener, getString( STR_ALL_OLE_OBJECTS ), PAGE_POS_X + 14, PAGE_POS_Y + 28, PAGE_WIDTH - 22, 8, sal_False, mnTabIndex++ ) );
591     aControlList.push_back( InsertRadioButton( *this, TKGet( TK_RadioButton1Pg2 ), mxItemListener, getString( STR_ALIEN_OLE_OBJECTS_ONLY ), PAGE_POS_X + 14, PAGE_POS_Y + 40, PAGE_WIDTH - 22, 8, sal_False, mnTabIndex++ ) );
592     aControlList.push_back( InsertFixedText( *this, TKGet( TK_FixedText1Pg2 ), nOLECount ? getString( STR_OLE_OBJECTS_DESC ) : getString( STR_NO_OLE_OBJECTS_DESC ), PAGE_POS_X + 6, PAGE_POS_Y + 64, PAGE_WIDTH - 22, 50, sal_True, sal_False, mnTabIndex++ ) );
593     maControlPages.push_back( aControlList );
594     DeactivatePage( 3 );
595     UpdateControlStatesPage3();
596 }
597 
598 // -----------------------------------------------------------------------------
599 
600 static OUString ImpValueOfInMB( const sal_Int64& rVal, sal_Unicode nSeparator = '.' )
601 {
602     double fVal( static_cast<double>( rVal ) );
603     fVal /= ( 1 << 20 );
604     fVal += 0.05;
605     rtl::OUStringBuffer aVal( OUString::valueOf( fVal ) );
606     sal_Int32 nX( OUString( aVal.getStr() ).indexOf( '.', 0 ) );
607     if ( nX >= 0 )
608     {
609         aVal.setLength( nX + 2 );
610         aVal.setCharAt( nX, nSeparator );
611     }
612     aVal.append( OUString::createFromAscii( " MB" ) );
613     return aVal.makeStringAndClear();
614 }
615 
616 void OptimizerDialog::UpdateControlStatesPage4()
617 {
618     sal_Bool bSaveAs( GetConfigProperty( TK_SaveAs, sal_True ) );
619     if ( mbIsReadonly )
620     {
621         setControlProperty( TKGet( TK_RadioButton0Pg4 ), TKGet( TK_State ), Any( (sal_Int16)( sal_False ) ) );
622         setControlProperty( TKGet( TK_RadioButton1Pg4 ), TKGet( TK_State ), Any( (sal_Int16)( sal_True ) ) );
623     }
624     else
625     {
626         setControlProperty( TKGet( TK_RadioButton0Pg4 ), TKGet( TK_State ), Any( (sal_Int16)( bSaveAs == sal_False ) ) );
627         setControlProperty( TKGet( TK_RadioButton1Pg4 ), TKGet( TK_State ), Any( (sal_Int16)( bSaveAs == sal_True ) ) );
628     }
629     setControlProperty( TKGet( TK_ComboBox0Pg4 ), TKGet( TK_Enabled ), Any( sal_False ) );
630 
631     sal_uInt32 w;
632     Sequence< OUString > aItemList;
633     const std::vector< OptimizerSettings >& rList( GetOptimizerSettings() );
634     if ( rList.size() > 1 ) // the first session in the list is the actual one -> skipping first one
635     {
636         aItemList.realloc( rList.size() - 1 );
637         for ( w = 1; w < rList.size(); w++ )
638             aItemList[ w - 1 ] = rList[ w ].maName;
639     }
640     setControlProperty( TKGet( TK_ComboBox0Pg4 ), TKGet( TK_StringItemList ), Any( aItemList ) );
641 
642     // now check if it is sensible to enable the combo box
643     sal_Bool bSaveSettingsEnabled = sal_True;
644     if ( rList.size() > 1 ) // the first session in the list is the actual one -> skipping first one
645     {
646         for ( w = 1; w < rList.size(); w++ )
647         {
648             if ( rList[ w ] == rList[ 0 ] )
649             {
650                 bSaveSettingsEnabled = sal_False;
651                 break;
652             }
653         }
654     }
655     sal_Int16 nInt16 = 0;
656     getControlProperty( TKGet( TK_CheckBox1Pg4 ), TKGet( TK_State ) ) >>= nInt16;
657     setControlProperty( TKGet( TK_CheckBox1Pg4 ), TKGet( TK_Enabled ), Any( bSaveSettingsEnabled ) );
658     setControlProperty( TKGet( TK_ComboBox0Pg4 ), TKGet( TK_Enabled ), Any( bSaveSettingsEnabled && nInt16 ) );
659 
660     std::vector< OUString > aSummaryStrings;
661 
662     // taking care of deleted slides
663     sal_Int32 nDeletedSlides = 0;
664     rtl::OUString aCustomShowName;
665     if ( getControlProperty( TKGet( TK_CheckBox3Pg3 ), TKGet( TK_State ) ) >>= nInt16 )
666     {
667         if ( nInt16 )
668         {
669             Sequence< short > aSelectedItems;
670             Sequence< OUString > aStringItemList;
671             Any aAny = getControlProperty( TKGet( TK_ListBox0Pg3 ), TKGet( TK_SelectedItems ) );
672             if ( aAny >>= aSelectedItems )
673             {
674                 if ( aSelectedItems.getLength() )
675                 {
676                     sal_Int16 nSelectedItem = aSelectedItems[ 0 ];
677                     aAny = getControlProperty( TKGet( TK_ListBox0Pg3 ), TKGet( TK_StringItemList ) );
678                     if ( aAny >>= aStringItemList )
679                     {
680                         if ( aStringItemList.getLength() > nSelectedItem )
681                             SetConfigProperty( TK_CustomShowName, Any( aStringItemList[ nSelectedItem ] ) );
682                     }
683                 }
684             }
685         }
686     }
687     if ( aCustomShowName.getLength() )
688     {
689         std::vector< Reference< XDrawPage > > vNonUsedPageList;
690         PageCollector::CollectNonCustomShowPages( mxController->getModel(), aCustomShowName, vNonUsedPageList );
691         nDeletedSlides += vNonUsedPageList.size();
692     }
693     if ( GetConfigProperty( TK_DeleteHiddenSlides, sal_False ) )
694     {
695         if ( aCustomShowName.getLength() )
696         {
697             std::vector< Reference< XDrawPage > > vUsedPageList;
698             PageCollector::CollectCustomShowPages( mxController->getModel(), aCustomShowName, vUsedPageList );
699             std::vector< Reference< XDrawPage > >::iterator aIter( vUsedPageList.begin() );
700             while( aIter != vUsedPageList.end() )
701             {
702                 Reference< XPropertySet > xPropSet( *aIter, UNO_QUERY_THROW );
703                 sal_Bool bVisible = sal_True;
704                 const OUString sVisible( RTL_CONSTASCII_USTRINGPARAM( "Visible" ) );
705                 if ( xPropSet->getPropertyValue( sVisible ) >>= bVisible )
706                 {
707                     if (!bVisible )
708                         nDeletedSlides++;
709                 }
710                 aIter++;
711             }
712         }
713         else
714         {
715             Reference< XDrawPagesSupplier > xDrawPagesSupplier( mxController->getModel(), UNO_QUERY_THROW );
716             Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY_THROW );
717             for( sal_Int32 i = 0; i < xDrawPages->getCount(); i++ )
718             {
719                 Reference< XDrawPage > xDrawPage( xDrawPages->getByIndex( i ), UNO_QUERY_THROW );
720                 Reference< XPropertySet > xPropSet( xDrawPage, UNO_QUERY_THROW );
721 
722                 sal_Bool bVisible = sal_True;
723                 const OUString sVisible( RTL_CONSTASCII_USTRINGPARAM( "Visible" ) );
724                 if ( xPropSet->getPropertyValue( sVisible ) >>= bVisible )
725                 {
726                     if (!bVisible )
727                         nDeletedSlides++;
728                 }
729             }
730         }
731     }
732     if ( GetConfigProperty( TK_DeleteUnusedMasterPages, sal_False ) )
733     {
734         std::vector< PageCollector::MasterPageEntity > aMasterPageList;
735         PageCollector::CollectMasterPages( mxController->getModel(), aMasterPageList );
736         Reference< XMasterPagesSupplier > xMasterPagesSupplier( mxController->getModel(), UNO_QUERY_THROW );
737         Reference< XDrawPages > xMasterPages( xMasterPagesSupplier->getMasterPages(), UNO_QUERY_THROW );
738         std::vector< PageCollector::MasterPageEntity >::iterator aIter( aMasterPageList.begin() );
739         while( aIter != aMasterPageList.end() )
740         {
741             if ( !aIter->bUsed )
742                 nDeletedSlides++;
743             aIter++;
744         }
745     }
746     if ( nDeletedSlides > 1 )
747     {
748         OUString aStr( getString( STR_DELETE_SLIDES ) );
749         OUString aPlaceholder( RTL_CONSTASCII_USTRINGPARAM( "%SLIDES" ) );
750         sal_Int32 i = aStr.indexOf( aPlaceholder, 0 );
751         if ( i >= 0 )
752             aStr = aStr.replaceAt( i, aPlaceholder.getLength(), OUString::valueOf( nDeletedSlides ) );
753         aSummaryStrings.push_back( aStr );
754     }
755 
756 // generating graphic compression info
757     sal_Int32 nGraphics = 0;
758     sal_Bool bJPEGCompression( GetConfigProperty( TK_JPEGCompression, sal_False ) );
759     sal_Int32 nJPEGQuality( GetConfigProperty( TK_JPEGQuality, (sal_Int32)90 ) );
760     sal_Int32 nImageResolution( GetConfigProperty( TK_ImageResolution, (sal_Int32)0 ) );
761     GraphicSettings aGraphicSettings( bJPEGCompression, nJPEGQuality, GetConfigProperty( TK_RemoveCropArea, sal_False ),
762                                         nImageResolution, GetConfigProperty( TK_EmbedLinkedGraphics, sal_True ) );
763     GraphicCollector::CountGraphics( mxMSF, mxController->getModel(), aGraphicSettings, nGraphics );
764     if ( nGraphics > 1 )
765     {
766         OUString aStr( getString( STR_OPTIMIZE_IMAGES ) );
767         OUString aImagePlaceholder( RTL_CONSTASCII_USTRINGPARAM( "%IMAGES" ) );
768         OUString aQualityPlaceholder( RTL_CONSTASCII_USTRINGPARAM( "%QUALITY" ) );
769         OUString aResolutionPlaceholder( RTL_CONSTASCII_USTRINGPARAM( "%RESOLUTION" ) );
770         sal_Int32 i = aStr.indexOf( aImagePlaceholder, 0 );
771         if ( i >= 0 )
772             aStr = aStr.replaceAt( i, aImagePlaceholder.getLength(), OUString::valueOf( nGraphics ) );
773 
774         sal_Int32 j = aStr.indexOf( aQualityPlaceholder, 0 );
775         if ( j >= 0 )
776             aStr = aStr.replaceAt( j, aQualityPlaceholder.getLength(), OUString::valueOf( nJPEGQuality ) );
777 
778         sal_Int32 k = aStr.indexOf( aResolutionPlaceholder, 0 );
779         if ( k >= 0 )
780             aStr = aStr.replaceAt( k, aResolutionPlaceholder.getLength(), OUString::valueOf( nImageResolution ) );
781 
782         aSummaryStrings.push_back( aStr );
783     }
784 
785     if ( GetConfigProperty( TK_OLEOptimization, sal_False ) )
786     {
787         sal_Int32 nOLEReplacements = 0;
788         Reference< XDrawPagesSupplier > xDrawPagesSupplier( mxController->getModel(), UNO_QUERY_THROW );
789         Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY_THROW );
790         for ( sal_Int32 i = 0; i < xDrawPages->getCount(); i++ )
791         {
792             Reference< XShapes > xShapes( xDrawPages->getByIndex( i ), UNO_QUERY_THROW );
793             for ( sal_Int32 j = 0; j < xShapes->getCount(); j++ )
794             {
795                 const OUString sOLE2Shape( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.OLE2Shape" ) );
796                 Reference< XShape > xShape( xShapes->getByIndex( j ), UNO_QUERY_THROW );
797                 if ( xShape->getShapeType() == sOLE2Shape )
798                     nOLEReplacements++;
799             }
800         }
801         if ( nOLEReplacements > 1 )
802         {
803             OUString aStr( getString( STR_CREATE_REPLACEMENT ) );
804             OUString aPlaceholder( RTL_CONSTASCII_USTRINGPARAM( "%OLE" ) );
805             sal_Int32 i = aStr.indexOf( aPlaceholder, 0 );
806             if ( i >= 0 )
807                 aStr = aStr.replaceAt( i, aPlaceholder.getLength(), OUString::valueOf( nOLEReplacements ) );
808             aSummaryStrings.push_back( aStr );
809         }
810     }
811     while( aSummaryStrings.size() < 3 )
812         aSummaryStrings.push_back( OUString() );
813     setControlProperty( TKGet( TK_FixedText4Pg4 ), TKGet( TK_Label ), Any( aSummaryStrings[ 0 ] ) );
814     setControlProperty( TKGet( TK_FixedText5Pg4 ), TKGet( TK_Label ), Any( aSummaryStrings[ 1 ] ) );
815     setControlProperty( TKGet( TK_FixedText6Pg4 ), TKGet( TK_Label ), Any( aSummaryStrings[ 2 ] ) );
816 
817     sal_Int64 nCurrentFileSize = 0;
818     sal_Int64 nEstimatedFileSize = 0;
819     Reference< XStorable > xStorable( mxController->getModel(), UNO_QUERY );
820     if ( xStorable.is() && xStorable->hasLocation() )
821         nCurrentFileSize = PPPOptimizer::GetFileSize( xStorable->getLocation() );
822 
823     if ( nCurrentFileSize )
824     {
825         double fE = static_cast< double >( nCurrentFileSize );
826         if ( nImageResolution )
827         {
828             double v = ( static_cast< double >( nImageResolution ) + 75.0 ) / 300.0;
829             if ( v < 1.0 )
830                 fE *= v;
831         }
832         if ( bJPEGCompression )
833         {
834             double v = 0.75 - ( ( 100.0 - static_cast< double >( nJPEGQuality ) ) / 400.0 ) ;
835             fE *= v;
836         }
837         nEstimatedFileSize = static_cast< sal_Int64 >( fE );
838     }
839     sal_Unicode nSeparator = '.';
840     OUString aStr( getString( STR_FILESIZESEPARATOR ) );
841     if ( aStr.getLength() )
842         nSeparator = aStr[ 0 ];
843     setControlProperty( TKGet( TK_FixedText7Pg4 ), TKGet( TK_Label ), Any( ImpValueOfInMB( nCurrentFileSize, nSeparator ) ) );
844     setControlProperty( TKGet( TK_FixedText8Pg4 ), TKGet( TK_Label ), Any( ImpValueOfInMB( nEstimatedFileSize, nSeparator ) ) );
845     SetConfigProperty( TK_EstimatedFileSize, Any( nEstimatedFileSize ) );
846 }
847 
848 void OptimizerDialog::InitPage4()
849 {
850     {   // creating progress bar:
851         OUString pNames[] = {
852             TKGet( TK_Height ),
853             TKGet( TK_Name ),
854             TKGet( TK_PositionX ),
855             TKGet( TK_PositionY ),
856             TKGet( TK_ProgressValue ),
857             TKGet( TK_ProgressValueMax ),
858             TKGet( TK_ProgressValueMin ),
859             TKGet( TK_Width ) };
860 
861         Any pValues[] = {
862             Any( (sal_Int32)12 ),
863             Any( TKGet( STR_SAVE_AS ) ),
864             Any( (sal_Int32)( PAGE_POS_X + 6 ) ),
865             Any( (sal_Int32)( DIALOG_HEIGHT - 75 ) ),
866             Any( (sal_Int32)( 0 ) ),
867             Any( (sal_Int32)( 100 ) ),
868             Any( (sal_Int32)( 0 ) ),
869             Any( (sal_Int32)( PAGE_WIDTH - 12 ) ) };
870 
871         sal_Int32 nCount = sizeof( pNames ) / sizeof( OUString );
872 
873         Sequence< rtl::OUString >   aNames( pNames, nCount );
874         Sequence< Any >             aValues( pValues, nCount );
875 
876         Reference< XMultiPropertySet > xMultiPropertySet( insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlProgressBarModel" ) ),
877             TKGet( TK_Progress ), aNames, aValues ), UNO_QUERY );
878     }
879     Reference< XTextListener > xTextListener;
880     Sequence< OUString > aItemList;
881     std::vector< rtl::OUString > aControlList;
882     aControlList.push_back( InsertFixedText( *this, TKGet( TK_FixedText0Pg4 ), getString( STR_SUMMARY_TITLE ), PAGE_POS_X, PAGE_POS_Y, PAGE_WIDTH, 8, sal_False, sal_True, mnTabIndex++ ) );
883 //  aControlList.push_back( InsertSeparator( *this, TKGet( TK_Separator0Pg4 ), 0, PAGE_POS_X + 6, PAGE_POS_Y + 90, PAGE_WIDTH - 12, 1 ) );
884 
885     aControlList.push_back( InsertFixedText( *this, TKGet( TK_FixedText4Pg4 ), OUString(), PAGE_POS_X + 6, PAGE_POS_Y + 14, PAGE_WIDTH - 12, 8, sal_False, sal_False, mnTabIndex++ ) );
886     aControlList.push_back( InsertFixedText( *this, TKGet( TK_FixedText5Pg4 ), OUString(), PAGE_POS_X + 6, PAGE_POS_Y + 22, PAGE_WIDTH - 12, 8, sal_False, sal_False, mnTabIndex++ ) );
887     aControlList.push_back( InsertFixedText( *this, TKGet( TK_FixedText6Pg4 ), OUString(), PAGE_POS_X + 6, PAGE_POS_Y + 30, PAGE_WIDTH - 12, 8, sal_False, sal_False, mnTabIndex++ ) );
888 
889     aControlList.push_back( InsertFixedText( *this, TKGet( TK_FixedText2Pg4 ), getString( STR_CURRENT_FILESIZE ), PAGE_POS_X + 6, PAGE_POS_Y + 50, 88, 8, sal_False, sal_False, mnTabIndex++ ) );
890     aControlList.push_back( InsertFixedText( *this, TKGet( TK_FixedText7Pg4 ), OUString(), PAGE_POS_X + 100, PAGE_POS_Y + 50, 30, 8, sal_False, sal_False, mnTabIndex++ ) );
891     setControlProperty( TKGet( TK_FixedText7Pg4 ), TKGet( TK_Align ), Any( static_cast< short >( 2 ) ) );
892     aControlList.push_back( InsertFixedText( *this, TKGet( TK_FixedText3Pg4 ), getString( STR_ESTIMATED_FILESIZE ), PAGE_POS_X + 6, PAGE_POS_Y + 58, 88, 8, sal_False, sal_False, mnTabIndex++ ) );
893     aControlList.push_back( InsertFixedText( *this, TKGet( TK_FixedText8Pg4 ), OUString(), PAGE_POS_X + 100, PAGE_POS_Y + 58, 30, 8, sal_False, sal_False, mnTabIndex++ ) );
894     setControlProperty( TKGet( TK_FixedText8Pg4 ), TKGet( TK_Align ), Any( static_cast< short >( 2 ) ) );
895 
896     aControlList.push_back( InsertRadioButton( *this, TKGet( TK_RadioButton0Pg4 ), mxItemListener, getString(  STR_APPLY_TO_CURRENT ), PAGE_POS_X + 6, PAGE_POS_Y + 78, PAGE_WIDTH - 12, 8, sal_False, mnTabIndex++ ) );
897     aControlList.push_back( InsertRadioButton( *this, TKGet( TK_RadioButton1Pg4 ), mxItemListener, getString( STR_SAVE_AS ), PAGE_POS_X + 6, PAGE_POS_Y + 90, PAGE_WIDTH - 12, 8, sal_False, mnTabIndex++ ) );
898     aControlList.push_back( InsertFixedText( *this, TKGet( TK_FixedText1Pg4 ), OUString(), PAGE_POS_X + 6, DIALOG_HEIGHT - 87, PAGE_WIDTH - 12, 8, sal_True, sal_False, mnTabIndex++ ) );
899     aControlList.push_back( TKGet( TK_Progress ) );
900     aControlList.push_back( InsertSeparator( *this, TKGet( TK_Separator1Pg4 ), 0, PAGE_POS_X + 6, DIALOG_HEIGHT - 58, PAGE_WIDTH - 12, 1 ) );
901     aControlList.push_back( InsertCheckBox(  *this, TKGet( TK_CheckBox1Pg4 ), mxItemListener, getString( STR_SAVE_SETTINGS ), PAGE_POS_X + 6, DIALOG_HEIGHT - 47, 100, 8, mnTabIndex++ ) );
902     aControlList.push_back( InsertComboBox(  *this, TKGet( TK_ComboBox0Pg4 ), xTextListener, sal_True, aItemList, PAGE_POS_X + 106, DIALOG_HEIGHT - 48, 100, 12, mnTabIndex++ ) );
903     maControlPages.push_back( aControlList );
904     DeactivatePage( 4 );
905 
906     // creating a default session name that hasn't been used yet
907     OUString aSettingsName;
908     OUString aDefault( getString( STR_MY_SETTINGS ) );
909     sal_Int32 nSession = 1;
910     sal_uInt32 i;
911     const std::vector< OptimizerSettings >& rList( GetOptimizerSettings() );
912     do
913     {
914         OUString aTemp( aDefault.concat( OUString::valueOf( nSession++ ) ) );
915         for ( i = 1; i < rList.size(); i++ )
916         {
917             if ( rList[ i ].maName == aTemp )
918                 break;
919         }
920         if ( i == rList.size() )
921             aSettingsName = aTemp;
922     }
923     while( !aSettingsName.getLength() );
924 
925     setControlProperty( TKGet( TK_ComboBox0Pg4 ), TKGet( TK_Text ), Any( aSettingsName ) );
926     setControlProperty( TKGet( TK_RadioButton0Pg4 ), TKGet( TK_Enabled ), Any( !mbIsReadonly ) );
927     setControlProperty( TKGet( TK_RadioButton1Pg4 ), TKGet( TK_Enabled ), Any( !mbIsReadonly ) );
928 
929     UpdateControlStatesPage4();
930 }
931 
932 // -----------------------------------------------------------------------------
933 void OptimizerDialog::EnablePage( sal_Int16 nStep )
934 {
935     std::vector< rtl::OUString >::iterator aBeg( maControlPages[ nStep ].begin() );
936     std::vector< rtl::OUString >::iterator aEnd( maControlPages[ nStep ].end() );
937     while( aBeg != aEnd )
938         setControlProperty( *aBeg++, TKGet( TK_Enabled ), Any( sal_True ) );
939 }
940 void OptimizerDialog::DisablePage( sal_Int16 nStep )
941 {
942     std::vector< rtl::OUString >::iterator aBeg( maControlPages[ nStep ].begin() );
943     std::vector< rtl::OUString >::iterator aEnd( maControlPages[ nStep ].end() );
944     while( aBeg != aEnd )
945         setControlProperty( *aBeg++, TKGet( TK_Enabled ), Any( sal_False ) );
946 }
947 void OptimizerDialog::ActivatePage( sal_Int16 nStep )
948 {
949     std::vector< rtl::OUString >::iterator aBeg( maControlPages[ nStep ].begin() );
950     std::vector< rtl::OUString >::iterator aEnd( maControlPages[ nStep ].end() );
951     while( aBeg != aEnd )
952         setVisible( *aBeg++, sal_True );
953 }
954 void OptimizerDialog::DeactivatePage( sal_Int16 nStep )
955 {
956     std::vector< rtl::OUString >::iterator aBeg( maControlPages[ nStep ].begin() );
957     std::vector< rtl::OUString >::iterator aEnd( maControlPages[ nStep ].end() );
958     while( aBeg != aEnd )
959         setVisible( *aBeg++, sal_False );
960 }
961