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