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