xref: /AOO41X/main/sdext/source/minimizer/optimizerdialog.cxx (revision ff0525f24f03981d56b7579b645949f111420994)
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 "fileopendialog.hxx"
29 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
30 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
31 #include <com/sun/star/io/XInputStream.hpp>
32 #ifndef _COM_SUN_STAR_UTIL_XCloseBroadcaster_HPP_
33 #include <com/sun/star/util/XCloseBroadcaster.hpp>
34 #endif
35 #include <com/sun/star/frame/XComponentLoader.hpp>
36 #include <com/sun/star/frame/XLayoutManager.hpp>
37 #include <osl/time.h>
38 
39 // -------------------
40 // - OPTIMIZERDIALOG -
41 // -------------------
42 
43 using namespace ::rtl;
44 using namespace ::com::sun::star::io;
45 using namespace ::com::sun::star::ui;
46 using namespace ::com::sun::star::awt;
47 using namespace ::com::sun::star::ucb;
48 using namespace ::com::sun::star::uno;
49 using namespace ::com::sun::star::util;
50 using namespace ::com::sun::star::lang;
51 using namespace ::com::sun::star::frame;
52 using namespace ::com::sun::star::beans;
53 using namespace ::com::sun::star::script;
54 using namespace ::com::sun::star::container;
55 
56 
57 // -----------------------------------------------------------------------------
58 
59 void OptimizerDialog::InitDialog()
60 {
61    // setting the dialog properties
62     OUString pNames[] = {
63         TKGet( TK_Closeable ),
64         TKGet( TK_Height ),
65         TKGet( TK_Moveable ),
66         TKGet( TK_PositionX ),
67         TKGet( TK_PositionY ),
68         TKGet( TK_Title ),
69         TKGet( TK_Width ) };
70 
71     Any pValues[] = {
72         Any( sal_True ),
73         Any( sal_Int32( DIALOG_HEIGHT ) ),
74         Any( sal_True ),
75         Any( sal_Int32( 200 ) ),
76         Any( sal_Int32( 52 ) ),
77         Any( getString( STR_SUN_OPTIMIZATION_WIZARD2 ) ),
78         Any( sal_Int32( OD_DIALOG_WIDTH ) ) };
79 
80     sal_Int32 nCount = sizeof( pNames ) / sizeof( OUString );
81 
82     Sequence< rtl::OUString >   aNames( pNames, nCount );
83     Sequence< Any >             aValues( pValues, nCount );
84 
85     mxDialogModelMultiPropertySet->setPropertyValues( aNames, aValues );
86 }
87 
88 // -----------------------------------------------------------------------------
89 
90 void OptimizerDialog::InitRoadmap()
91 {
92     try
93     {
94         OUString pNames[] = {
95             TKGet( TK_Height ),
96             TKGet( TK_PositionX ),
97             TKGet( TK_PositionY ),
98             TKGet( TK_Step ),
99             TKGet( TK_TabIndex ),
100             TKGet( TK_Width ) };
101 
102         Any pValues[] = {
103             Any( sal_Int32( DIALOG_HEIGHT - 26 ) ),
104             Any( sal_Int32( 0 ) ),
105             Any( sal_Int32( 0 ) ),
106             Any( sal_Int32( 0 ) ),
107             Any( mnTabIndex++ ),
108             Any( sal_Int32( 85 ) ) };
109 
110         sal_Int32 nCount = sizeof( pNames ) / sizeof( OUString );
111 
112         Sequence< rtl::OUString >   aNames( pNames, nCount );
113         Sequence< Any >             aValues( pValues, nCount );
114 
115         mxRoadmapControlModel = insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlRoadmapModel" ) ),
116                                                               TKGet( TK_rdmNavi ), aNames, aValues  );
117 
118         Reference< XPropertySet > xPropertySet( mxRoadmapControlModel, UNO_QUERY_THROW );
119         xPropertySet->setPropertyValue( TKGet( TK_Name ), Any( TKGet( TK_rdmNavi ) ) );
120         mxRoadmapControl = mxDialogControlContainer->getControl( TKGet( TK_rdmNavi ) );
121         InsertRoadmapItem( 0, sal_True, getString( STR_INTRODUCTION ), ITEM_ID_INTRODUCTION );
122         InsertRoadmapItem( 1, sal_True, getString( STR_SLIDES ), ITEM_ID_SLIDES );
123         InsertRoadmapItem( 2, sal_True, getString( STR_IMAGE_OPTIMIZATION ), ITEM_ID_GRAPHIC_OPTIMIZATION );
124         InsertRoadmapItem( 3, sal_True, getString( STR_OLE_OBJECTS ), ITEM_ID_OLE_OPTIMIZATION );
125         InsertRoadmapItem( 4, sal_True, getString( STR_SUMMARY ), ITEM_ID_SUMMARY );
126 
127         rtl::OUString sBitmapPath( getPath( TK_BitmapPath ) );
128         rtl::OUString sBitmap( isHighContrast() ? rtl::OUString::createFromAscii( "/minimizepresi_80_h.png" )
129                                                 : rtl::OUString::createFromAscii( "/minimizepresi_80.png" ) );
130         rtl::OUString sURL( sBitmapPath += sBitmap );
131 
132         xPropertySet->setPropertyValue( TKGet( TK_ImageURL ), Any( sURL ) );
133         xPropertySet->setPropertyValue( TKGet( TK_Activated ), Any( (sal_Bool)sal_True ) );
134         xPropertySet->setPropertyValue( TKGet( TK_Complete ), Any( (sal_Bool)sal_True ) );
135         xPropertySet->setPropertyValue( TKGet( TK_CurrentItemID ), Any( (sal_Int16)ITEM_ID_INTRODUCTION ) );
136         xPropertySet->setPropertyValue( TKGet( TK_Text ), Any( getString( STR_STEPS ) ) );
137     }
138     catch( Exception& )
139     {
140     }
141 }
142 
143 // -----------------------------------------------------------------------------
144 
145 void OptimizerDialog::InsertRoadmapItem( const sal_Int32 nIndex, const sal_Bool bEnabled, const rtl::OUString& rLabel, const sal_Int32 nItemID )
146 {
147     try
148     {
149         Reference< XSingleServiceFactory > xSFRoadmap( mxRoadmapControlModel, UNO_QUERY_THROW );
150         Reference< XIndexContainer > aIndexContainerRoadmap( mxRoadmapControlModel, UNO_QUERY_THROW );
151         Reference< XInterface > xRoadmapItem( xSFRoadmap->createInstance(), UNO_QUERY_THROW );
152         Reference< XPropertySet > xPropertySet( xRoadmapItem, UNO_QUERY_THROW );
153         xPropertySet->setPropertyValue( TKGet( TK_Label ), Any( rLabel ) );
154         xPropertySet->setPropertyValue( TKGet( TK_Enabled ), Any( bEnabled ) );
155         xPropertySet->setPropertyValue( TKGet( TK_ID ), Any( nItemID ) );
156         aIndexContainerRoadmap->insertByIndex( nIndex, Any( xRoadmapItem ) );
157     }
158     catch( Exception& )
159     {
160 
161     }
162 }
163 
164 // -----------------------------------------------------------------------------
165 
166 void OptimizerDialog::UpdateConfiguration()
167 {
168     sal_Int16   nInt16 = 0;
169     OUString    aString;
170     Any         aAny;
171 
172     Sequence< sal_Int16 > aSelectedItems;
173     Sequence< OUString > aStringItemList;
174 
175     // page0
176     aAny = getControlProperty( TKGet( TK_ListBox0Pg0 ), TKGet( TK_SelectedItems ) );
177     if ( aAny >>= aSelectedItems )
178     {
179         if ( aSelectedItems.getLength() )
180         {
181             sal_Int16 nSelectedItem = aSelectedItems[ 0 ];
182             aAny = getControlProperty( TKGet( TK_ListBox0Pg0 ), TKGet( TK_StringItemList ) );
183             if ( aAny >>= aStringItemList )
184             {
185                 if ( aStringItemList.getLength() > nSelectedItem )
186                     SetConfigProperty( TK_Name, Any( aStringItemList[ nSelectedItem ] ) );
187             }
188         }
189     }
190 
191     aAny = getControlProperty( TKGet( TK_CheckBox3Pg3 ), TKGet( TK_State ) );
192     if ( aAny >>= nInt16 )
193     {
194         if ( nInt16 )
195         {
196             aAny = getControlProperty( TKGet( TK_ListBox0Pg3 ), TKGet( TK_SelectedItems ) );
197             if ( aAny >>= aSelectedItems )
198             {
199                 if ( aSelectedItems.getLength() )
200                 {
201                     sal_Int16 nSelectedItem = aSelectedItems[ 0 ];
202                     aAny = getControlProperty( TKGet( TK_ListBox0Pg3 ), TKGet( TK_StringItemList ) );
203                     if ( aAny >>= aStringItemList )
204                     {
205                         if ( aStringItemList.getLength() > nSelectedItem )
206                             SetConfigProperty( TK_CustomShowName, Any( aStringItemList[ nSelectedItem ] ) );
207                     }
208                 }
209             }
210         }
211     }
212 }
213 
214 // -----------------------------------------------------------------------------
215 
216 OptimizerDialog::OptimizerDialog( const Reference< XComponentContext > &rxMSF, Reference< XFrame >& rxFrame, Reference< XDispatch > rxStatusDispatcher ) :
217     UnoDialog( rxMSF, rxFrame ),
218     ConfigurationAccess( rxMSF, NULL ),
219     mnCurrentStep( 0 ),
220     mnTabIndex( 0 ),
221     mxMSF( rxMSF ),
222     mxFrame( rxFrame ),
223     mxItemListener( new ItemListener( *this ) ),
224     mxActionListener( new ActionListener( *this ) ),
225     mxActionListenerListBox0Pg0( new ActionListenerListBox0Pg0( *this ) ),
226     mxTextListenerFormattedField0Pg1( new TextListenerFormattedField0Pg1( *this ) ),
227     mxTextListenerComboBox0Pg1( new TextListenerComboBox0Pg1( *this ) ),
228     mxSpinListenerFormattedField0Pg1( new SpinListenerFormattedField0Pg1( *this ) ),
229     mxStatusDispatcher( rxStatusDispatcher )
230 {
231     Reference< XStorable > xStorable( mxController->getModel(), UNO_QUERY_THROW );
232     mbIsReadonly = xStorable->isReadonly();
233 
234     InitDialog();
235     InitRoadmap();
236     InitNavigationBar();
237     InitPage0();
238     InitPage1();
239     InitPage2();
240     InitPage3();
241     InitPage4();
242     ActivatePage( 0 );
243 
244     OptimizationStats aStats;
245     aStats.InitializeStatusValuesFromDocument( mxController->getModel() );
246     Sequence< PropertyValue > aStatusSequence( aStats.GetStatusSequence() );
247     UpdateStatus( aStatusSequence );
248 }
249 
250 // -----------------------------------------------------------------------------
251 
252 OptimizerDialog::~OptimizerDialog()
253 {
254     // not saving configuration if the dialog has been finished via cancel or close window
255     if ( mbStatus )
256         SaveConfiguration();
257 }
258 
259 // -----------------------------------------------------------------------------
260 
261 sal_Bool OptimizerDialog::execute()
262 {
263     Reference< XItemEventBroadcaster > maRoadmapBroadcaster( mxRoadmapControl, UNO_QUERY_THROW );
264     maRoadmapBroadcaster->addItemListener( mxItemListener );
265     UnoDialog::execute();
266     UpdateConfiguration();          // taking actual control settings for the configuration
267     maRoadmapBroadcaster->removeItemListener( mxItemListener );
268     return mbStatus;
269 }
270 
271 // -----------------------------------------------------------------------------
272 
273 void OptimizerDialog::SwitchPage( sal_Int16 nNewStep )
274 {
275     if ( ( nNewStep != mnCurrentStep ) && ( ( nNewStep <= MAX_STEP ) || ( nNewStep >= 0 ) ) )
276     {
277         sal_Int16 nOldStep = mnCurrentStep;
278         if ( nNewStep == 0 )
279             disableControl( TKGet( TK_btnNavBack ) );
280         else if ( nOldStep == 0 )
281             enableControl( TKGet( TK_btnNavBack ) );
282 
283         if ( nNewStep == MAX_STEP )
284             disableControl( TKGet( TK_btnNavNext ) );
285         else if ( nOldStep == MAX_STEP )
286             enableControl( TKGet( TK_btnNavNext ) );
287 
288         setControlProperty( TKGet( TK_rdmNavi ), TKGet( TK_CurrentItemID ), Any( nNewStep ) );
289 
290         DeactivatePage( nOldStep );
291         UpdateControlStates( nNewStep );
292 
293         ActivatePage( nNewStep );
294         mnCurrentStep = nNewStep;
295     }
296 }
297 
298 void OptimizerDialog::UpdateControlStates( sal_Int16 nPage )
299 {
300     switch( nPage )
301     {
302         case 0 : UpdateControlStatesPage0(); break;
303         case 1 : UpdateControlStatesPage1(); break;
304         case 2 : UpdateControlStatesPage2(); break;
305         case 3 : UpdateControlStatesPage3(); break;
306         case 4 : UpdateControlStatesPage4(); break;
307         default:
308         {
309             UpdateControlStatesPage0();
310             UpdateControlStatesPage1();
311             UpdateControlStatesPage2();
312             UpdateControlStatesPage3();
313             UpdateControlStatesPage4();
314         }
315     }
316 }
317 
318 // -----------------------------------------------------------------------------
319 
320 rtl::OUString OptimizerDialog::GetSelectedString( const PPPOptimizerTokenEnum eToken )
321 {
322     OUString aSelectedItem;
323     Sequence< sal_Int16 > sSelectedItems;
324     Sequence< OUString >  sItemList;
325 
326     if ( ( getControlProperty( TKGet( eToken ), TKGet( TK_SelectedItems ) ) >>= sSelectedItems ) &&
327             ( getControlProperty( TKGet( eToken ), TKGet( TK_StringItemList ) ) >>= sItemList ) )
328     {
329         if ( sSelectedItems.getLength() == 1 )
330         {
331             sal_Int16 nSelectedItem = sSelectedItems[ 0 ];
332             if ( nSelectedItem < sItemList.getLength() )
333                 aSelectedItem = sItemList[ nSelectedItem ];
334         }
335     }
336     return aSelectedItem;
337 }
338 
339 // -----------------------------------------------------------------------------
340 
341 void OptimizerDialog::UpdateStatus( const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& rStatus )
342 {
343     if ( mxReschedule.is() )
344     {
345         maStats.InitializeStatusValues( rStatus );
346         const Any* pVal( maStats.GetStatusValue( TK_Status ) );
347         if ( pVal )
348         {
349             rtl::OUString sStatus;
350             if ( *pVal >>= sStatus )
351             {
352                 setControlProperty( TKGet( TK_FixedText1Pg4 ), TKGet( TK_Enabled ), Any( sal_True ) );
353                 setControlProperty( TKGet( TK_FixedText1Pg4 ), TKGet( TK_Label ), Any( getString( TKGet( sStatus ) ) ) );
354             }
355         }
356         pVal = maStats.GetStatusValue( TK_Progress );
357         if ( pVal )
358         {
359             sal_Int32 nProgress = 0;
360             if ( *pVal >>= nProgress )
361                 setControlProperty( TKGet( TK_Progress ), TKGet( TK_ProgressValue ), Any( nProgress ) );
362         }
363         pVal = maStats.GetStatusValue( TK_OpenNewDocument );
364         if ( pVal )
365             SetConfigProperty( TK_OpenNewDocument, *pVal );
366 
367         mxReschedule->reschedule();
368     }
369 }
370 
371 // -----------------------------------------------------------------------------
372 
373 void ItemListener::itemStateChanged( const ItemEvent& Event )
374     throw ( RuntimeException )
375 {
376     try
377     {
378         sal_Int16 nState;
379         OUString aControlName;
380         Reference< XControl > xControl;
381         Any aSource( Event.Source );
382         if ( aSource >>= xControl )
383         {
384             Reference< XPropertySet > xPropertySet( xControl->getModel(), UNO_QUERY_THROW );
385             xPropertySet->getPropertyValue( TKGet( TK_Name ) ) >>= aControlName;
386             PPPOptimizerTokenEnum eControl( TKGet( aControlName ) );
387             switch( eControl )
388             {
389                 case TK_rdmNavi :
390                 {
391                     mrOptimizerDialog.SwitchPage( static_cast< sal_Int16 >( Event.ItemId ) );
392                 }
393                 break;
394                 case TK_CheckBox1Pg1 :
395                 {
396                     if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState )
397                         mrOptimizerDialog.SetConfigProperty( TK_RemoveCropArea, Any( nState != 0 ) );
398                 }
399                 break;
400                 case TK_CheckBox2Pg1 :
401                 {
402                     if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState )
403                         mrOptimizerDialog.SetConfigProperty( TK_EmbedLinkedGraphics, Any( nState != 0 ) );
404                 }
405                 break;
406                 case TK_CheckBox0Pg2 :
407                 {
408                     if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState )
409                     {
410                         mrOptimizerDialog.SetConfigProperty( TK_OLEOptimization, Any( nState != 0 ) );
411                         mrOptimizerDialog.setControlProperty( TKGet( TK_RadioButton0Pg2 ), TKGet( TK_Enabled ), Any( nState != 0 ) );
412                         mrOptimizerDialog.setControlProperty( TKGet( TK_RadioButton1Pg2 ), TKGet( TK_Enabled ), Any( nState != 0 ) );
413                     }
414                 }
415                 break;
416                 case TK_RadioButton0Pg1 :
417                 {
418                     sal_Int16 nInt16 = 0;
419                     if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nInt16 )
420                     {
421                         nInt16 ^= 1;
422                         mrOptimizerDialog.SetConfigProperty( TK_JPEGCompression, Any( nInt16 != 0 ) );
423                         mrOptimizerDialog.setControlProperty( TKGet( TK_FixedText1Pg1 ), TKGet( TK_Enabled ), Any( nInt16 != 0 ) );
424                         mrOptimizerDialog.setControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_Enabled ), Any( nInt16 != 0 ) );
425                     }
426                 }
427                 break;
428                 case TK_RadioButton1Pg1 :
429                 {
430                     if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState )
431                     {
432                         mrOptimizerDialog.SetConfigProperty( TK_JPEGCompression, Any( nState != 0 ) );
433                         mrOptimizerDialog.setControlProperty( TKGet( TK_FixedText1Pg1 ), TKGet( TK_Enabled ), Any( nState != 0 ) );
434                         mrOptimizerDialog.setControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_Enabled ), Any( nState != 0 ) );
435                     }
436                 }
437                 break;
438                 case TK_RadioButton0Pg2 :
439                 {
440                     sal_Int16 nInt16;
441                     if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nInt16 )
442                     {
443                         nInt16 ^= 1;
444                         mrOptimizerDialog.SetConfigProperty( TK_OLEOptimizationType, Any( nInt16 ) );
445                     }
446                 }
447                 break;
448                 case TK_RadioButton1Pg2 :
449                 {
450                     if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState )
451                         mrOptimizerDialog.SetConfigProperty( TK_OLEOptimizationType, Any( nState ) );
452                 }
453                 break;
454                 case TK_CheckBox0Pg3 :
455                 {
456                     if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState )
457                         mrOptimizerDialog.SetConfigProperty( TK_DeleteUnusedMasterPages, Any( nState != 0 ) );
458                 }
459                 break;
460                 case TK_CheckBox1Pg3 :
461                 {
462                     if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState )
463                         mrOptimizerDialog.SetConfigProperty( TK_DeleteNotesPages, Any( nState != 0 ) );
464                 }
465                 break;
466                 case TK_CheckBox2Pg3 :
467                 {
468                     if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState )
469                         mrOptimizerDialog.SetConfigProperty( TK_DeleteHiddenSlides, Any( nState != 0 ) );
470                 }
471                 break;
472                 case TK_CheckBox3Pg3 :
473                 {
474                     if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState )
475                         mrOptimizerDialog.setControlProperty( TKGet( TK_ListBox0Pg3 ), TKGet( TK_Enabled ), Any( nState != 0 ) );
476                 }
477                 break;
478                 case TK_CheckBox1Pg4 :
479                 {
480                     if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState )
481                         mrOptimizerDialog.setControlProperty( TKGet( TK_ComboBox0Pg4 ), TKGet( TK_Enabled ), Any( nState != 0 ) );
482                 }
483                 break;
484                 case TK_RadioButton0Pg4 :
485                 case TK_RadioButton1Pg4 :
486                 {
487                     if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState )
488                         mrOptimizerDialog.SetConfigProperty( TK_SaveAs, Any( eControl == TK_RadioButton1Pg4 ? nState != 0 : nState == 0 ) );
489                 }
490                 break;
491                 default:
492                 break;
493             }
494         }
495     }
496     catch ( Exception& )
497     {
498 
499     }
500 }
501 void ItemListener::disposing( const ::com::sun::star::lang::EventObject& /* Source */ )
502     throw ( com::sun::star::uno::RuntimeException )
503 {
504 }
505 
506 // -----------------------------------------------------------------------------
507 
508 void ActionListener::actionPerformed( const ActionEvent& rEvent )
509     throw ( com::sun::star::uno::RuntimeException )
510 {
511     switch( TKGet( rEvent.ActionCommand ) )
512     {
513         case TK_btnNavHelp :
514         {
515             try
516             {
517                 static Reference< XFrame > xHelpFrame;
518                 if ( !xHelpFrame.is() )
519                 {
520                     rtl::OUString sHelpFile( mrOptimizerDialog.getPath( TK_HelpFile ) );
521                     Reference< XDesktop > desktop( mrOptimizerDialog.GetComponentContext()->getServiceManager()->createInstanceWithContext(
522                             OUString::createFromAscii( "com.sun.star.frame.Desktop" ), mrOptimizerDialog.GetComponentContext() ), UNO_QUERY_THROW );
523                     Reference< XSimpleFileAccess > xSimpleFileAccess( mrOptimizerDialog.GetComponentContext()->getServiceManager()->createInstanceWithContext(
524                             OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ), mrOptimizerDialog.GetComponentContext() ), UNO_QUERY_THROW );
525                     Reference< XInputStream > xInputStream( xSimpleFileAccess->openFileRead( sHelpFile ) );
526                     Reference< XDesktop > xDesktop( mrOptimizerDialog.GetComponentContext()->getServiceManager()->createInstanceWithContext(
527                             OUString::createFromAscii( "com.sun.star.frame.Desktop" ), mrOptimizerDialog.GetComponentContext() ), UNO_QUERY_THROW );
528                     Reference< XFrame > xDesktopFrame( xDesktop, UNO_QUERY_THROW );
529                     xHelpFrame = Reference< XFrame >( xDesktopFrame->findFrame( TKGet( TK__blank ), 0 ) );
530                     Reference< XCloseBroadcaster > xCloseBroadcaster( xHelpFrame, UNO_QUERY_THROW );
531                     xCloseBroadcaster->addCloseListener( new HelpCloseListener( xHelpFrame ) );
532                     Reference< XComponentLoader > xLoader( xHelpFrame, UNO_QUERY_THROW );
533 
534                     Sequence< PropertyValue > aLoadProps( 2 );
535                     aLoadProps[ 0 ].Name = TKGet( TK_ReadOnly );
536                     aLoadProps[ 0 ].Value <<= (sal_Bool)( sal_True );
537                     aLoadProps[ 1 ].Name = TKGet( TK_InputStream );
538                     aLoadProps[ 1 ].Value <<= xInputStream;
539 
540                     Reference< XComponent >( xLoader->loadComponentFromURL( OUString::createFromAscii( "private:stream" ),
541                         TKGet( TK__self ), 0, aLoadProps ) );
542 
543                     Reference< XPropertySet > xPropSet( xHelpFrame, UNO_QUERY_THROW );
544                     Reference< XLayoutManager > xLayoutManager;
545                     if ( xPropSet->getPropertyValue( OUString::createFromAscii( "LayoutManager" ) ) >>= xLayoutManager )
546                     {
547                         xLayoutManager->setVisible( sal_False );
548                         xLayoutManager->hideElement( OUString::createFromAscii( "private:resource/menubar/menubar" ) );
549                         xLayoutManager->destroyElement( OUString::createFromAscii( "private:resource/statusbar/statusbar" ) );
550                     }
551                 }
552             }
553             catch( Exception& )
554             {
555 
556             }
557         }
558         break;
559         case TK_btnNavBack :    mrOptimizerDialog.SwitchPage( mrOptimizerDialog.mnCurrentStep - 1 ); break;
560         case TK_btnNavNext :    mrOptimizerDialog.SwitchPage( mrOptimizerDialog.mnCurrentStep + 1 ); break;
561         case TK_btnNavFinish :
562         {
563             mrOptimizerDialog.UpdateConfiguration();
564 
565             mrOptimizerDialog.SwitchPage( ITEM_ID_SUMMARY );
566             mrOptimizerDialog.DisablePage( ITEM_ID_SUMMARY );
567             mrOptimizerDialog.setControlProperty( TKGet( TK_btnNavHelp ), TKGet( TK_Enabled ), Any( sal_False ) );
568             mrOptimizerDialog.setControlProperty( TKGet( TK_btnNavBack ), TKGet( TK_Enabled ), Any( sal_False ) );
569             mrOptimizerDialog.setControlProperty( TKGet( TK_btnNavNext ), TKGet( TK_Enabled ), Any( sal_False ) );
570             mrOptimizerDialog.setControlProperty( TKGet( TK_btnNavFinish ), TKGet( TK_Enabled ), Any( sal_False ) );
571             mrOptimizerDialog.setControlProperty( TKGet( TK_btnNavCancel ), TKGet( TK_Enabled ), Any( sal_False ) );
572             mrOptimizerDialog.setControlProperty( TKGet( TK_FixedText0Pg4 ), TKGet( TK_Enabled ), Any( sal_True ) );
573 
574             // check if we have to open the FileDialog
575             sal_Bool    bSuccessfullyExecuted = sal_True;
576             sal_Int16   nInt16 = 0;
577             mrOptimizerDialog.getControlProperty( TKGet( TK_RadioButton1Pg4 ), TKGet( TK_State ) ) >>= nInt16;
578             if ( nInt16 )
579             {
580                 rtl::OUString aSaveAsURL;
581                 FileOpenDialog aFileOpenDialog( ((UnoDialog&)mrOptimizerDialog).mxMSF );
582 
583                 // generating default file name
584                 Reference< XStorable > xStorable( mrOptimizerDialog.mxController->getModel(), UNO_QUERY );
585                 if ( xStorable.is() && xStorable->hasLocation() )
586                 {
587                     rtl::OUString aLocation( xStorable->getLocation() );
588                     if ( aLocation.getLength() )
589                     {
590                         sal_Int32 nIndex = aLocation.lastIndexOf( '/', aLocation.getLength() - 1 );
591                         if ( nIndex >= 0 )
592                         {
593                             if ( nIndex < aLocation.getLength() - 1 )
594                                 aLocation = aLocation.copy( nIndex + 1 );
595 
596                             // remove extension
597                             nIndex = aLocation.lastIndexOf( '.', aLocation.getLength() - 1 );
598                             if ( nIndex >= 0 )
599                                 aLocation = aLocation.copy( 0, nIndex );
600 
601                             // adding .mini
602                             aLocation = aLocation.concat( OUString::createFromAscii( ".mini" ) );
603                             aFileOpenDialog.setDefaultName( aLocation );
604                         }
605                     }
606                 }
607                 sal_Bool bDialogExecuted = aFileOpenDialog.execute() == dialogs::ExecutableDialogResults::OK;
608                 if ( bDialogExecuted )
609                 {
610                     aSaveAsURL = aFileOpenDialog.getURL();
611                     mrOptimizerDialog.SetConfigProperty( TK_SaveAsURL, Any( aSaveAsURL ) );
612                     mrOptimizerDialog.SetConfigProperty( TK_FilterName, Any( aFileOpenDialog.getFilterName() ) );
613                 }
614                 if ( !aSaveAsURL.getLength() )
615                 {
616                     // something goes wrong...
617                     bSuccessfullyExecuted = sal_False;
618                 }
619 
620                 // waiting for 500ms
621                 if ( mrOptimizerDialog.mxReschedule.is() )
622                 {
623                     mrOptimizerDialog.mxReschedule->reschedule();
624                     for ( sal_uInt32 i = osl_getGlobalTimer(); ( i + 500 ) > ( osl_getGlobalTimer() ); )
625                     mrOptimizerDialog.mxReschedule->reschedule();
626                 }
627             }
628             if ( bSuccessfullyExecuted )
629             {   // now check if we have to store a session template
630                 nInt16 = 0;
631                 OUString aSettingsName;
632                 mrOptimizerDialog.getControlProperty( TKGet( TK_CheckBox1Pg4 ), TKGet( TK_State ) ) >>= nInt16;
633                 mrOptimizerDialog.getControlProperty( TKGet( TK_ComboBox0Pg4 ), TKGet( TK_Text ) ) >>= aSettingsName;
634                 if ( nInt16 && aSettingsName.getLength() )
635                 {
636                     std::vector< OptimizerSettings >::iterator aIter( mrOptimizerDialog.GetOptimizerSettingsByName( aSettingsName ) );
637                     std::vector< OptimizerSettings >& rSettings( mrOptimizerDialog.GetOptimizerSettings() );
638                     OptimizerSettings aNewSettings( rSettings[ 0 ] );
639                     aNewSettings.maName = aSettingsName;
640                     if ( aIter == rSettings.end() )
641                         rSettings.push_back( aNewSettings );
642                     else
643                         *aIter = aNewSettings;
644                 }
645             }
646             if ( bSuccessfullyExecuted )
647             {
648                 Sequence< Any > aArgs( 1 );
649                 aArgs[ 0 ] <<= mrOptimizerDialog.GetFrame();
650 
651                 Reference < XDispatch > xDispatch( mrOptimizerDialog.GetComponentContext()->getServiceManager()->createInstanceWithArgumentsAndContext(
652                     OUString::createFromAscii( "com.sun.star.comp.PPPOptimizer" ), aArgs, mrOptimizerDialog.GetComponentContext() ), UNO_QUERY );
653 
654                 URL aURL;
655                 aURL.Protocol = OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.com.sun.star.comp.PPPOptimizer:" ) );
656                 aURL.Path = OUString( RTL_CONSTASCII_USTRINGPARAM( "optimize" ) );
657 
658                 Sequence< PropertyValue > lArguments( 3 );
659                 lArguments[ 0 ].Name = TKGet( TK_Settings );
660                 lArguments[ 0 ].Value <<= mrOptimizerDialog.GetConfigurationSequence();
661                 lArguments[ 1 ].Name = TKGet( TK_StatusDispatcher );
662                 lArguments[ 1 ].Value <<= mrOptimizerDialog.GetStatusDispatcher();
663                 lArguments[ 2 ].Name = TKGet( TK_InformationDialog );
664                 lArguments[ 2 ].Value <<= mrOptimizerDialog.GetFrame();
665 
666                 if( xDispatch.is() )
667                     xDispatch->dispatch( aURL, lArguments );
668 
669                 mrOptimizerDialog.endExecute( bSuccessfullyExecuted );
670             }
671             else
672             {
673                 mrOptimizerDialog.setControlProperty( TKGet( TK_btnNavHelp ), TKGet( TK_Enabled ), Any( sal_True ) );
674                 mrOptimizerDialog.setControlProperty( TKGet( TK_btnNavBack ), TKGet( TK_Enabled ), Any( sal_True ) );
675                 mrOptimizerDialog.setControlProperty( TKGet( TK_btnNavNext ), TKGet( TK_Enabled ), Any( sal_False ) );
676                 mrOptimizerDialog.setControlProperty( TKGet( TK_btnNavFinish ), TKGet( TK_Enabled ), Any( sal_True ) );
677                 mrOptimizerDialog.setControlProperty( TKGet( TK_btnNavCancel ), TKGet( TK_Enabled ), Any( sal_True ) );
678                 mrOptimizerDialog.EnablePage( ITEM_ID_SUMMARY );
679             }
680         }
681         break;
682         case TK_btnNavCancel :  mrOptimizerDialog.endExecute( sal_False ); break;
683         case TK_Button0Pg0 :    // delete configuration
684         {
685             OUString aSelectedItem( mrOptimizerDialog.GetSelectedString( TK_ListBox0Pg0 ) );
686             if ( aSelectedItem.getLength() )
687             {
688                 std::vector< OptimizerSettings >::iterator aIter( mrOptimizerDialog.GetOptimizerSettingsByName( aSelectedItem ) );
689                 std::vector< OptimizerSettings >& rList( mrOptimizerDialog.GetOptimizerSettings() );
690                 if ( aIter != rList.end() )
691                 {
692                     rList.erase( aIter );
693                     mrOptimizerDialog.UpdateControlStates();
694                 }
695             }
696         }
697         break;
698         default: break;
699     }
700 }
701 void ActionListener::disposing( const ::com::sun::star::lang::EventObject& /* Source */ )
702     throw ( com::sun::star::uno::RuntimeException )
703 {
704 }
705 
706 // -----------------------------------------------------------------------------
707 
708 void ActionListenerListBox0Pg0::actionPerformed( const ActionEvent& rEvent )
709     throw ( com::sun::star::uno::RuntimeException )
710 {
711     if ( rEvent.ActionCommand.getLength() )
712     {
713         std::vector< OptimizerSettings >::iterator aIter( mrOptimizerDialog.GetOptimizerSettingsByName( rEvent.ActionCommand ) );
714         std::vector< OptimizerSettings >& rList( mrOptimizerDialog.GetOptimizerSettings() );
715         if ( aIter != rList.end() )
716             rList[ 0 ] = *aIter;
717     }
718     mrOptimizerDialog.UpdateControlStates();
719 }
720 void ActionListenerListBox0Pg0::disposing( const ::com::sun::star::lang::EventObject& /* Source */ )
721     throw ( com::sun::star::uno::RuntimeException )
722 {
723 }
724 
725 // -----------------------------------------------------------------------------
726 
727 void TextListenerFormattedField0Pg1::textChanged( const TextEvent& /* rEvent */ )
728     throw ( com::sun::star::uno::RuntimeException )
729 {
730     double fDouble = 0;
731     Any aAny = mrOptimizerDialog.getControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_EffectiveValue ) );
732     if ( aAny >>= fDouble )
733         mrOptimizerDialog.SetConfigProperty( TK_JPEGQuality, Any( (sal_Int32)fDouble ) );
734 }
735 void TextListenerFormattedField0Pg1::disposing( const ::com::sun::star::lang::EventObject& /* Source */ )
736     throw ( com::sun::star::uno::RuntimeException )
737 {
738 }
739 
740 // -----------------------------------------------------------------------------
741 
742 void TextListenerComboBox0Pg1::textChanged( const TextEvent& /* rEvent */ )
743     throw ( com::sun::star::uno::RuntimeException )
744 {
745     rtl::OUString aString;
746     Any aAny = mrOptimizerDialog.getControlProperty( TKGet( TK_ComboBox0Pg1 ), TKGet( TK_Text ) );
747     if ( aAny >>= aString )
748     {
749         sal_Int32 nI0, nI1, nI2, nI3, nI4;
750         nI0 = nI1 = nI2 = nI3 = nI4 = 0;
751 
752         if ( mrOptimizerDialog.getString( STR_IMAGE_RESOLUTION_0 ).getToken( 1, ';', nI0 ) == aString )
753             aString = mrOptimizerDialog.getString( STR_IMAGE_RESOLUTION_0 ).getToken( 0, ';', nI4 );
754         else if ( mrOptimizerDialog.getString( STR_IMAGE_RESOLUTION_1 ).getToken( 1, ';', nI1 ) == aString )
755             aString = mrOptimizerDialog.getString( STR_IMAGE_RESOLUTION_1 ).getToken( 0, ';', nI4 );
756         else if ( mrOptimizerDialog.getString( STR_IMAGE_RESOLUTION_2 ).getToken( 1, ';', nI2 ) == aString )
757             aString = mrOptimizerDialog.getString( STR_IMAGE_RESOLUTION_2 ).getToken( 0, ';', nI4 );
758         else if ( mrOptimizerDialog.getString( STR_IMAGE_RESOLUTION_3 ).getToken( 1, ';', nI3 ) == aString )
759             aString = mrOptimizerDialog.getString( STR_IMAGE_RESOLUTION_3 ).getToken( 0, ';', nI4 );
760 
761         mrOptimizerDialog.SetConfigProperty( TK_ImageResolution, Any( aString.toInt32() ) );
762     }
763 }
764 void TextListenerComboBox0Pg1::disposing( const ::com::sun::star::lang::EventObject& /* Source */ )
765     throw ( com::sun::star::uno::RuntimeException )
766 {
767 }
768 
769 // -----------------------------------------------------------------------------
770 
771 void SpinListenerFormattedField0Pg1::up( const SpinEvent& /* rEvent */ )
772     throw ( com::sun::star::uno::RuntimeException )
773 {
774     double fDouble;
775     Any aAny = mrOptimizerDialog.getControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_EffectiveValue ) );
776     if ( aAny >>= fDouble )
777     {
778         fDouble += 9;
779         if ( fDouble > 100 )
780             fDouble = 100;
781         mrOptimizerDialog.setControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_EffectiveValue ), Any( fDouble ) );
782         mrOptimizerDialog.SetConfigProperty( TK_JPEGQuality, Any( (sal_Int32)fDouble ) );
783     }
784 }
785 void SpinListenerFormattedField0Pg1::down( const SpinEvent& /* rEvent */ )
786     throw ( com::sun::star::uno::RuntimeException )
787 {
788     double fDouble;
789     Any aAny = mrOptimizerDialog.getControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_EffectiveValue ) );
790     if ( aAny >>= fDouble )
791     {
792         fDouble -= 9;
793         if ( fDouble < 0 )
794             fDouble = 0;
795         mrOptimizerDialog.setControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_EffectiveValue ), Any( fDouble ) );
796         mrOptimizerDialog.SetConfigProperty( TK_JPEGQuality, Any( (sal_Int32)fDouble ) );
797     }
798 }
799 void SpinListenerFormattedField0Pg1::first( const SpinEvent& /* rEvent */ )
800     throw ( com::sun::star::uno::RuntimeException )
801 {
802     mrOptimizerDialog.setControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_EffectiveValue ), Any( static_cast< double >( 0 ) ) );
803     mrOptimizerDialog.SetConfigProperty( TK_JPEGQuality, Any( (sal_Int32)0 ) );
804 }
805 void SpinListenerFormattedField0Pg1::last( const SpinEvent& /* rEvent */ )
806     throw ( com::sun::star::uno::RuntimeException )
807 {
808     mrOptimizerDialog.setControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_EffectiveValue ), Any( static_cast< double >( 100 ) ) );
809     mrOptimizerDialog.SetConfigProperty( TK_JPEGQuality, Any( (sal_Int32)100 ) );
810 }
811 void SpinListenerFormattedField0Pg1::disposing( const ::com::sun::star::lang::EventObject& /* Source */ )
812     throw ( com::sun::star::uno::RuntimeException )
813 {
814 }
815 
816 // -----------------------------------------------------------------------------
817 
818 void HelpCloseListener::addCloseListener( const Reference < XCloseListener >& ) throw( RuntimeException )
819 {
820 }
821 void HelpCloseListener::removeCloseListener( const Reference < XCloseListener >& ) throw( RuntimeException )
822 {
823 }
824 void HelpCloseListener::queryClosing( const EventObject&, sal_Bool /* bDeliverOwnership */ )
825         throw ( RuntimeException, CloseVetoException )
826 {
827 }
828 void HelpCloseListener::notifyClosing( const EventObject& )
829         throw ( RuntimeException )
830 {
831 }
832 void HelpCloseListener::disposing( const EventObject& ) throw ( RuntimeException )
833 {
834     mrXFrame = NULL;
835 }
836