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