1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: optimizerdialog.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sdext.hxx"
35 #include "optimizerdialog.hxx"
36 #include "fileopendialog.hxx"
37 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
38 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
39 #include <com/sun/star/io/XInputStream.hpp>
40 #ifndef _COM_SUN_STAR_UTIL_XCloseBroadcaster_HPP_
41 #include <com/sun/star/util/XCloseBroadcaster.hpp>
43 #include <com/sun/star/frame/XComponentLoader.hpp>
44 #include <com/sun/star/frame/XLayoutManager.hpp>
47 // -------------------
48 // - OPTIMIZERDIALOG -
49 // -------------------
51 using namespace ::rtl
;
52 using namespace ::com::sun::star::io
;
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
;
65 // -----------------------------------------------------------------------------
67 void OptimizerDialog::InitDialog()
69 // setting the dialog properties
71 TKGet( TK_Closeable
),
74 TKGet( TK_PositionX
),
75 TKGet( TK_PositionY
),
81 Any( sal_Int32( DIALOG_HEIGHT
) ),
83 Any( sal_Int32( 200 ) ),
84 Any( sal_Int32( 52 ) ),
85 Any( getString( STR_SUN_OPTIMIZATION_WIZARD2
) ),
86 Any( sal_Int32( OD_DIALOG_WIDTH
) ) };
88 sal_Int32 nCount
= sizeof( pNames
) / sizeof( OUString
);
90 Sequence
< rtl::OUString
> aNames( pNames
, nCount
);
91 Sequence
< Any
> aValues( pValues
, nCount
);
93 mxDialogModelMultiPropertySet
->setPropertyValues( aNames
, aValues
);
96 // -----------------------------------------------------------------------------
98 void OptimizerDialog::InitRoadmap()
102 OUString pNames
[] = {
104 TKGet( TK_PositionX
),
105 TKGet( TK_PositionY
),
107 TKGet( TK_TabIndex
),
111 Any( sal_Int32( DIALOG_HEIGHT
- 26 ) ),
112 Any( sal_Int32( 0 ) ),
113 Any( sal_Int32( 0 ) ),
114 Any( sal_Int32( 0 ) ),
116 Any( sal_Int32( 85 ) ) };
118 sal_Int32 nCount
= sizeof( pNames
) / sizeof( OUString
);
120 Sequence
< rtl::OUString
> aNames( pNames
, nCount
);
121 Sequence
< Any
> aValues( pValues
, nCount
);
123 mxRoadmapControlModel
= insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlRoadmapModel" ) ),
124 TKGet( TK_rdmNavi
), aNames
, aValues
);
126 Reference
< XPropertySet
> xPropertySet( mxRoadmapControlModel
, UNO_QUERY_THROW
);
127 xPropertySet
->setPropertyValue( TKGet( TK_Name
), Any( TKGet( TK_rdmNavi
) ) );
128 mxRoadmapControl
= mxDialogControlContainer
->getControl( TKGet( TK_rdmNavi
) );
129 InsertRoadmapItem( 0, sal_True
, getString( STR_INTRODUCTION
), ITEM_ID_INTRODUCTION
);
130 InsertRoadmapItem( 1, sal_True
, getString( STR_SLIDES
), ITEM_ID_SLIDES
);
131 InsertRoadmapItem( 2, sal_True
, getString( STR_IMAGE_OPTIMIZATION
), ITEM_ID_GRAPHIC_OPTIMIZATION
);
132 InsertRoadmapItem( 3, sal_True
, getString( STR_OLE_OBJECTS
), ITEM_ID_OLE_OPTIMIZATION
);
133 InsertRoadmapItem( 4, sal_True
, getString( STR_SUMMARY
), ITEM_ID_SUMMARY
);
135 rtl::OUString
sBitmapPath( getPath( TK_BitmapPath
) );
136 rtl::OUString
sBitmap( isHighContrast() ? rtl::OUString::createFromAscii( "/minimizepresi_80_h.png" )
137 : rtl::OUString::createFromAscii( "/minimizepresi_80.png" ) );
138 rtl::OUString
sURL( sBitmapPath
+= sBitmap
);
140 xPropertySet
->setPropertyValue( TKGet( TK_ImageURL
), Any( sURL
) );
141 xPropertySet
->setPropertyValue( TKGet( TK_Activated
), Any( (sal_Bool
)sal_True
) );
142 xPropertySet
->setPropertyValue( TKGet( TK_Complete
), Any( (sal_Bool
)sal_True
) );
143 xPropertySet
->setPropertyValue( TKGet( TK_CurrentItemID
), Any( (sal_Int16
)ITEM_ID_INTRODUCTION
) );
144 xPropertySet
->setPropertyValue( TKGet( TK_Text
), Any( getString( STR_STEPS
) ) );
151 // -----------------------------------------------------------------------------
153 void OptimizerDialog::InsertRoadmapItem( const sal_Int32 nIndex
, const sal_Bool bEnabled
, const rtl::OUString
& rLabel
, const sal_Int32 nItemID
)
157 Reference
< XSingleServiceFactory
> xSFRoadmap( mxRoadmapControlModel
, UNO_QUERY_THROW
);
158 Reference
< XIndexContainer
> aIndexContainerRoadmap( mxRoadmapControlModel
, UNO_QUERY_THROW
);
159 Reference
< XInterface
> xRoadmapItem( xSFRoadmap
->createInstance(), UNO_QUERY_THROW
);
160 Reference
< XPropertySet
> xPropertySet( xRoadmapItem
, UNO_QUERY_THROW
);
161 xPropertySet
->setPropertyValue( TKGet( TK_Label
), Any( rLabel
) );
162 xPropertySet
->setPropertyValue( TKGet( TK_Enabled
), Any( bEnabled
) );
163 xPropertySet
->setPropertyValue( TKGet( TK_ID
), Any( nItemID
) );
164 aIndexContainerRoadmap
->insertByIndex( nIndex
, Any( xRoadmapItem
) );
172 // -----------------------------------------------------------------------------
174 void OptimizerDialog::UpdateConfiguration()
176 sal_Int16 nInt16
= 0;
180 Sequence
< sal_Int16
> aSelectedItems
;
181 Sequence
< OUString
> aStringItemList
;
184 aAny
= getControlProperty( TKGet( TK_ListBox0Pg0
), TKGet( TK_SelectedItems
) );
185 if ( aAny
>>= aSelectedItems
)
187 if ( aSelectedItems
.getLength() )
189 sal_Int16 nSelectedItem
= aSelectedItems
[ 0 ];
190 aAny
= getControlProperty( TKGet( TK_ListBox0Pg0
), TKGet( TK_StringItemList
) );
191 if ( aAny
>>= aStringItemList
)
193 if ( aStringItemList
.getLength() > nSelectedItem
)
194 SetConfigProperty( TK_Name
, Any( aStringItemList
[ nSelectedItem
] ) );
199 aAny
= getControlProperty( TKGet( TK_CheckBox3Pg3
), TKGet( TK_State
) );
200 if ( aAny
>>= nInt16
)
204 aAny
= getControlProperty( TKGet( TK_ListBox0Pg3
), TKGet( TK_SelectedItems
) );
205 if ( aAny
>>= aSelectedItems
)
207 if ( aSelectedItems
.getLength() )
209 sal_Int16 nSelectedItem
= aSelectedItems
[ 0 ];
210 aAny
= getControlProperty( TKGet( TK_ListBox0Pg3
), TKGet( TK_StringItemList
) );
211 if ( aAny
>>= aStringItemList
)
213 if ( aStringItemList
.getLength() > nSelectedItem
)
214 SetConfigProperty( TK_CustomShowName
, Any( aStringItemList
[ nSelectedItem
] ) );
222 // -----------------------------------------------------------------------------
224 OptimizerDialog::OptimizerDialog( const Reference
< XComponentContext
> &rxMSF
, Reference
< XFrame
>& rxFrame
, Reference
< XDispatch
> rxStatusDispatcher
) :
225 UnoDialog( rxMSF
, rxFrame
),
226 ConfigurationAccess( rxMSF
, NULL
),
231 mxItemListener( new ItemListener( *this ) ),
232 mxActionListener( new ActionListener( *this ) ),
233 mxActionListenerListBox0Pg0( new ActionListenerListBox0Pg0( *this ) ),
234 mxTextListenerFormattedField0Pg1( new TextListenerFormattedField0Pg1( *this ) ),
235 mxTextListenerComboBox0Pg1( new TextListenerComboBox0Pg1( *this ) ),
236 mxSpinListenerFormattedField0Pg1( new SpinListenerFormattedField0Pg1( *this ) ),
237 mxStatusDispatcher( rxStatusDispatcher
)
239 Reference
< XStorable
> xStorable( mxController
->getModel(), UNO_QUERY_THROW
);
240 mbIsReadonly
= xStorable
->isReadonly();
252 OptimizationStats aStats
;
253 aStats
.InitializeStatusValuesFromDocument( mxController
->getModel() );
254 Sequence
< PropertyValue
> aStatusSequence( aStats
.GetStatusSequence() );
255 UpdateStatus( aStatusSequence
);
258 // -----------------------------------------------------------------------------
260 OptimizerDialog::~OptimizerDialog()
262 // not saving configuration if the dialog has been finished via cancel or close window
267 // -----------------------------------------------------------------------------
269 sal_Bool
OptimizerDialog::execute()
271 Reference
< XItemEventBroadcaster
> maRoadmapBroadcaster( mxRoadmapControl
, UNO_QUERY_THROW
);
272 maRoadmapBroadcaster
->addItemListener( mxItemListener
);
273 UnoDialog::execute();
274 UpdateConfiguration(); // taking actual control settings for the configuration
275 maRoadmapBroadcaster
->removeItemListener( mxItemListener
);
279 // -----------------------------------------------------------------------------
281 void OptimizerDialog::SwitchPage( sal_Int16 nNewStep
)
283 if ( ( nNewStep
!= mnCurrentStep
) && ( ( nNewStep
<= MAX_STEP
) || ( nNewStep
>= 0 ) ) )
285 sal_Int16 nOldStep
= mnCurrentStep
;
287 disableControl( TKGet( TK_btnNavBack
) );
288 else if ( nOldStep
== 0 )
289 enableControl( TKGet( TK_btnNavBack
) );
291 if ( nNewStep
== MAX_STEP
)
292 disableControl( TKGet( TK_btnNavNext
) );
293 else if ( nOldStep
== MAX_STEP
)
294 enableControl( TKGet( TK_btnNavNext
) );
296 setControlProperty( TKGet( TK_rdmNavi
), TKGet( TK_CurrentItemID
), Any( nNewStep
) );
298 DeactivatePage( nOldStep
);
299 UpdateControlStates( nNewStep
);
301 ActivatePage( nNewStep
);
302 mnCurrentStep
= nNewStep
;
306 void OptimizerDialog::UpdateControlStates( sal_Int16 nPage
)
310 case 0 : UpdateControlStatesPage0(); break;
311 case 1 : UpdateControlStatesPage1(); break;
312 case 2 : UpdateControlStatesPage2(); break;
313 case 3 : UpdateControlStatesPage3(); break;
314 case 4 : UpdateControlStatesPage4(); break;
317 UpdateControlStatesPage0();
318 UpdateControlStatesPage1();
319 UpdateControlStatesPage2();
320 UpdateControlStatesPage3();
321 UpdateControlStatesPage4();
326 // -----------------------------------------------------------------------------
328 rtl::OUString
OptimizerDialog::GetSelectedString( const PPPOptimizerTokenEnum eToken
)
330 OUString aSelectedItem
;
331 Sequence
< sal_Int16
> sSelectedItems
;
332 Sequence
< OUString
> sItemList
;
334 if ( ( getControlProperty( TKGet( eToken
), TKGet( TK_SelectedItems
) ) >>= sSelectedItems
) &&
335 ( getControlProperty( TKGet( eToken
), TKGet( TK_StringItemList
) ) >>= sItemList
) )
337 if ( sSelectedItems
.getLength() == 1 )
339 sal_Int16 nSelectedItem
= sSelectedItems
[ 0 ];
340 if ( nSelectedItem
< sItemList
.getLength() )
341 aSelectedItem
= sItemList
[ nSelectedItem
];
344 return aSelectedItem
;
347 // -----------------------------------------------------------------------------
349 void OptimizerDialog::UpdateStatus( const com::sun::star::uno::Sequence
< com::sun::star::beans::PropertyValue
>& rStatus
)
351 if ( mxReschedule
.is() )
353 maStats
.InitializeStatusValues( rStatus
);
354 const Any
* pVal( maStats
.GetStatusValue( TK_Status
) );
357 rtl::OUString sStatus
;
358 if ( *pVal
>>= sStatus
)
360 setControlProperty( TKGet( TK_FixedText1Pg4
), TKGet( TK_Enabled
), Any( sal_True
) );
361 setControlProperty( TKGet( TK_FixedText1Pg4
), TKGet( TK_Label
), Any( getString( TKGet( sStatus
) ) ) );
364 pVal
= maStats
.GetStatusValue( TK_Progress
);
367 sal_Int32 nProgress
= 0;
368 if ( *pVal
>>= nProgress
)
369 setControlProperty( TKGet( TK_Progress
), TKGet( TK_ProgressValue
), Any( nProgress
) );
371 pVal
= maStats
.GetStatusValue( TK_OpenNewDocument
);
373 SetConfigProperty( TK_OpenNewDocument
, *pVal
);
375 mxReschedule
->reschedule();
379 // -----------------------------------------------------------------------------
381 void ItemListener::itemStateChanged( const ItemEvent
& Event
)
382 throw ( RuntimeException
)
387 OUString aControlName
;
388 Reference
< XControl
> xControl
;
389 Any
aSource( Event
.Source
);
390 if ( aSource
>>= xControl
)
392 Reference
< XPropertySet
> xPropertySet( xControl
->getModel(), UNO_QUERY_THROW
);
393 xPropertySet
->getPropertyValue( TKGet( TK_Name
) ) >>= aControlName
;
394 PPPOptimizerTokenEnum
eControl( TKGet( aControlName
) );
399 mrOptimizerDialog
.SwitchPage( static_cast< sal_Int16
>( Event
.ItemId
) );
402 case TK_CheckBox1Pg1
:
404 if ( xPropertySet
->getPropertyValue( TKGet( TK_State
) ) >>= nState
)
405 mrOptimizerDialog
.SetConfigProperty( TK_RemoveCropArea
, Any( nState
!= 0 ) );
408 case TK_CheckBox2Pg1
:
410 if ( xPropertySet
->getPropertyValue( TKGet( TK_State
) ) >>= nState
)
411 mrOptimizerDialog
.SetConfigProperty( TK_EmbedLinkedGraphics
, Any( nState
!= 0 ) );
414 case TK_CheckBox0Pg2
:
416 if ( xPropertySet
->getPropertyValue( TKGet( TK_State
) ) >>= nState
)
418 mrOptimizerDialog
.SetConfigProperty( TK_OLEOptimization
, Any( nState
!= 0 ) );
419 mrOptimizerDialog
.setControlProperty( TKGet( TK_RadioButton0Pg2
), TKGet( TK_Enabled
), Any( nState
!= 0 ) );
420 mrOptimizerDialog
.setControlProperty( TKGet( TK_RadioButton1Pg2
), TKGet( TK_Enabled
), Any( nState
!= 0 ) );
424 case TK_RadioButton0Pg1
:
426 sal_Int16 nInt16
= 0;
427 if ( xPropertySet
->getPropertyValue( TKGet( TK_State
) ) >>= nInt16
)
430 mrOptimizerDialog
.SetConfigProperty( TK_JPEGCompression
, Any( nInt16
!= 0 ) );
431 mrOptimizerDialog
.setControlProperty( TKGet( TK_FixedText1Pg1
), TKGet( TK_Enabled
), Any( nInt16
!= 0 ) );
432 mrOptimizerDialog
.setControlProperty( TKGet( TK_FormattedField0Pg1
), TKGet( TK_Enabled
), Any( nInt16
!= 0 ) );
436 case TK_RadioButton1Pg1
:
438 if ( xPropertySet
->getPropertyValue( TKGet( TK_State
) ) >>= nState
)
440 mrOptimizerDialog
.SetConfigProperty( TK_JPEGCompression
, Any( nState
!= 0 ) );
441 mrOptimizerDialog
.setControlProperty( TKGet( TK_FixedText1Pg1
), TKGet( TK_Enabled
), Any( nState
!= 0 ) );
442 mrOptimizerDialog
.setControlProperty( TKGet( TK_FormattedField0Pg1
), TKGet( TK_Enabled
), Any( nState
!= 0 ) );
446 case TK_RadioButton0Pg2
:
449 if ( xPropertySet
->getPropertyValue( TKGet( TK_State
) ) >>= nInt16
)
452 mrOptimizerDialog
.SetConfigProperty( TK_OLEOptimizationType
, Any( nInt16
) );
456 case TK_RadioButton1Pg2
:
458 if ( xPropertySet
->getPropertyValue( TKGet( TK_State
) ) >>= nState
)
459 mrOptimizerDialog
.SetConfigProperty( TK_OLEOptimizationType
, Any( nState
) );
462 case TK_CheckBox0Pg3
:
464 if ( xPropertySet
->getPropertyValue( TKGet( TK_State
) ) >>= nState
)
465 mrOptimizerDialog
.SetConfigProperty( TK_DeleteUnusedMasterPages
, Any( nState
!= 0 ) );
468 case TK_CheckBox1Pg3
:
470 if ( xPropertySet
->getPropertyValue( TKGet( TK_State
) ) >>= nState
)
471 mrOptimizerDialog
.SetConfigProperty( TK_DeleteNotesPages
, Any( nState
!= 0 ) );
474 case TK_CheckBox2Pg3
:
476 if ( xPropertySet
->getPropertyValue( TKGet( TK_State
) ) >>= nState
)
477 mrOptimizerDialog
.SetConfigProperty( TK_DeleteHiddenSlides
, Any( nState
!= 0 ) );
480 case TK_CheckBox3Pg3
:
482 if ( xPropertySet
->getPropertyValue( TKGet( TK_State
) ) >>= nState
)
483 mrOptimizerDialog
.setControlProperty( TKGet( TK_ListBox0Pg3
), TKGet( TK_Enabled
), Any( nState
!= 0 ) );
486 case TK_CheckBox1Pg4
:
488 if ( xPropertySet
->getPropertyValue( TKGet( TK_State
) ) >>= nState
)
489 mrOptimizerDialog
.setControlProperty( TKGet( TK_ComboBox0Pg4
), TKGet( TK_Enabled
), Any( nState
!= 0 ) );
492 case TK_RadioButton0Pg4
:
493 case TK_RadioButton1Pg4
:
495 if ( xPropertySet
->getPropertyValue( TKGet( TK_State
) ) >>= nState
)
496 mrOptimizerDialog
.SetConfigProperty( TK_SaveAs
, Any( eControl
== TK_RadioButton1Pg4
? nState
!= 0 : nState
== 0 ) );
509 void ItemListener::disposing( const ::com::sun::star::lang::EventObject
& /* Source */ )
510 throw ( com::sun::star::uno::RuntimeException
)
514 // -----------------------------------------------------------------------------
516 void ActionListener::actionPerformed( const ActionEvent
& rEvent
)
517 throw ( com::sun::star::uno::RuntimeException
)
519 switch( TKGet( rEvent
.ActionCommand
) )
525 static Reference
< XFrame
> xHelpFrame
;
526 if ( !xHelpFrame
.is() )
528 rtl::OUString
sHelpFile( mrOptimizerDialog
.getPath( TK_HelpFile
) );
529 Reference
< XDesktop
> desktop( mrOptimizerDialog
.GetComponentContext()->getServiceManager()->createInstanceWithContext(
530 OUString::createFromAscii( "com.sun.star.frame.Desktop" ), mrOptimizerDialog
.GetComponentContext() ), UNO_QUERY_THROW
);
531 Reference
< XSimpleFileAccess
> xSimpleFileAccess( mrOptimizerDialog
.GetComponentContext()->getServiceManager()->createInstanceWithContext(
532 OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ), mrOptimizerDialog
.GetComponentContext() ), UNO_QUERY_THROW
);
533 Reference
< XInputStream
> xInputStream( xSimpleFileAccess
->openFileRead( sHelpFile
) );
534 Reference
< XDesktop
> xDesktop( mrOptimizerDialog
.GetComponentContext()->getServiceManager()->createInstanceWithContext(
535 OUString::createFromAscii( "com.sun.star.frame.Desktop" ), mrOptimizerDialog
.GetComponentContext() ), UNO_QUERY_THROW
);
536 Reference
< XFrame
> xDesktopFrame( xDesktop
, UNO_QUERY_THROW
);
537 xHelpFrame
= Reference
< XFrame
>( xDesktopFrame
->findFrame( TKGet( TK__blank
), 0 ) );
538 Reference
< XCloseBroadcaster
> xCloseBroadcaster( xHelpFrame
, UNO_QUERY_THROW
);
539 xCloseBroadcaster
->addCloseListener( new HelpCloseListener( xHelpFrame
) );
540 Reference
< XComponentLoader
> xLoader( xHelpFrame
, UNO_QUERY_THROW
);
542 Sequence
< PropertyValue
> aLoadProps( 2 );
543 aLoadProps
[ 0 ].Name
= TKGet( TK_ReadOnly
);
544 aLoadProps
[ 0 ].Value
<<= (sal_Bool
)( sal_True
);
545 aLoadProps
[ 1 ].Name
= TKGet( TK_InputStream
);
546 aLoadProps
[ 1 ].Value
<<= xInputStream
;
548 Reference
< XComponent
>( xLoader
->loadComponentFromURL( OUString::createFromAscii( "private:stream" ),
549 TKGet( TK__self
), 0, aLoadProps
) );
551 Reference
< XPropertySet
> xPropSet( xHelpFrame
, UNO_QUERY_THROW
);
552 Reference
< XLayoutManager
> xLayoutManager
;
553 if ( xPropSet
->getPropertyValue( OUString::createFromAscii( "LayoutManager" ) ) >>= xLayoutManager
)
555 xLayoutManager
->setVisible( sal_False
);
556 xLayoutManager
->hideElement( OUString::createFromAscii( "private:resource/menubar/menubar" ) );
557 xLayoutManager
->destroyElement( OUString::createFromAscii( "private:resource/statusbar/statusbar" ) );
567 case TK_btnNavBack
: mrOptimizerDialog
.SwitchPage( mrOptimizerDialog
.mnCurrentStep
- 1 ); break;
568 case TK_btnNavNext
: mrOptimizerDialog
.SwitchPage( mrOptimizerDialog
.mnCurrentStep
+ 1 ); break;
569 case TK_btnNavFinish
:
571 mrOptimizerDialog
.UpdateConfiguration();
573 mrOptimizerDialog
.SwitchPage( ITEM_ID_SUMMARY
);
574 mrOptimizerDialog
.DisablePage( ITEM_ID_SUMMARY
);
575 mrOptimizerDialog
.setControlProperty( TKGet( TK_btnNavHelp
), TKGet( TK_Enabled
), Any( sal_False
) );
576 mrOptimizerDialog
.setControlProperty( TKGet( TK_btnNavBack
), TKGet( TK_Enabled
), Any( sal_False
) );
577 mrOptimizerDialog
.setControlProperty( TKGet( TK_btnNavNext
), TKGet( TK_Enabled
), Any( sal_False
) );
578 mrOptimizerDialog
.setControlProperty( TKGet( TK_btnNavFinish
), TKGet( TK_Enabled
), Any( sal_False
) );
579 mrOptimizerDialog
.setControlProperty( TKGet( TK_btnNavCancel
), TKGet( TK_Enabled
), Any( sal_False
) );
580 mrOptimizerDialog
.setControlProperty( TKGet( TK_FixedText0Pg4
), TKGet( TK_Enabled
), Any( sal_True
) );
582 // check if we have to open the FileDialog
583 sal_Bool bSuccessfullyExecuted
= sal_True
;
584 sal_Int16 nInt16
= 0;
585 mrOptimizerDialog
.getControlProperty( TKGet( TK_RadioButton1Pg4
), TKGet( TK_State
) ) >>= nInt16
;
588 rtl::OUString aSaveAsURL
;
589 FileOpenDialog
aFileOpenDialog( ((UnoDialog
&)mrOptimizerDialog
).mxMSF
);
591 // generating default file name
592 Reference
< XStorable
> xStorable( mrOptimizerDialog
.mxController
->getModel(), UNO_QUERY
);
593 if ( xStorable
.is() && xStorable
->hasLocation() )
595 rtl::OUString
aLocation( xStorable
->getLocation() );
596 if ( aLocation
.getLength() )
598 sal_Int32 nIndex
= aLocation
.lastIndexOf( '/', aLocation
.getLength() - 1 );
601 if ( nIndex
< aLocation
.getLength() - 1 )
602 aLocation
= aLocation
.copy( nIndex
+ 1 );
605 nIndex
= aLocation
.lastIndexOf( '.', aLocation
.getLength() - 1 );
607 aLocation
= aLocation
.copy( 0, nIndex
);
610 aLocation
= aLocation
.concat( OUString::createFromAscii( ".mini" ) );
611 aFileOpenDialog
.setDefaultName( aLocation
);
615 sal_Bool bDialogExecuted
= aFileOpenDialog
.execute() == dialogs::ExecutableDialogResults::OK
;
616 if ( bDialogExecuted
)
618 aSaveAsURL
= aFileOpenDialog
.getURL();
619 mrOptimizerDialog
.SetConfigProperty( TK_SaveAsURL
, Any( aSaveAsURL
) );
620 mrOptimizerDialog
.SetConfigProperty( TK_FilterName
, Any( aFileOpenDialog
.getFilterName() ) );
622 if ( !aSaveAsURL
.getLength() )
624 // something goes wrong...
625 bSuccessfullyExecuted
= sal_False
;
629 if ( mrOptimizerDialog
.mxReschedule
.is() )
631 mrOptimizerDialog
.mxReschedule
->reschedule();
632 for ( sal_uInt32 i
= osl_getGlobalTimer(); ( i
+ 500 ) > ( osl_getGlobalTimer() ); )
633 mrOptimizerDialog
.mxReschedule
->reschedule();
636 if ( bSuccessfullyExecuted
)
637 { // now check if we have to store a session template
639 OUString aSettingsName
;
640 mrOptimizerDialog
.getControlProperty( TKGet( TK_CheckBox1Pg4
), TKGet( TK_State
) ) >>= nInt16
;
641 mrOptimizerDialog
.getControlProperty( TKGet( TK_ComboBox0Pg4
), TKGet( TK_Text
) ) >>= aSettingsName
;
642 if ( nInt16
&& aSettingsName
.getLength() )
644 std::vector
< OptimizerSettings
>::iterator
aIter( mrOptimizerDialog
.GetOptimizerSettingsByName( aSettingsName
) );
645 std::vector
< OptimizerSettings
>& rSettings( mrOptimizerDialog
.GetOptimizerSettings() );
646 OptimizerSettings
aNewSettings( rSettings
[ 0 ] );
647 aNewSettings
.maName
= aSettingsName
;
648 if ( aIter
== rSettings
.end() )
649 rSettings
.push_back( aNewSettings
);
651 *aIter
= aNewSettings
;
654 if ( bSuccessfullyExecuted
)
656 Sequence
< Any
> aArgs( 1 );
657 aArgs
[ 0 ] <<= mrOptimizerDialog
.GetFrame();
659 Reference
< XDispatch
> xDispatch( mrOptimizerDialog
.GetComponentContext()->getServiceManager()->createInstanceWithArgumentsAndContext(
660 OUString::createFromAscii( "com.sun.star.comp.PPPOptimizer" ), aArgs
, mrOptimizerDialog
.GetComponentContext() ), UNO_QUERY
);
663 aURL
.Protocol
= OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.com.sun.star.comp.PPPOptimizer:" ) );
664 aURL
.Path
= OUString( RTL_CONSTASCII_USTRINGPARAM( "optimize" ) );
666 Sequence
< PropertyValue
> lArguments( 3 );
667 lArguments
[ 0 ].Name
= TKGet( TK_Settings
);
668 lArguments
[ 0 ].Value
<<= mrOptimizerDialog
.GetConfigurationSequence();
669 lArguments
[ 1 ].Name
= TKGet( TK_StatusDispatcher
);
670 lArguments
[ 1 ].Value
<<= mrOptimizerDialog
.GetStatusDispatcher();
671 lArguments
[ 2 ].Name
= TKGet( TK_InformationDialog
);
672 lArguments
[ 2 ].Value
<<= mrOptimizerDialog
.GetFrame();
675 xDispatch
->dispatch( aURL
, lArguments
);
677 mrOptimizerDialog
.endExecute( bSuccessfullyExecuted
);
681 mrOptimizerDialog
.setControlProperty( TKGet( TK_btnNavHelp
), TKGet( TK_Enabled
), Any( sal_True
) );
682 mrOptimizerDialog
.setControlProperty( TKGet( TK_btnNavBack
), TKGet( TK_Enabled
), Any( sal_True
) );
683 mrOptimizerDialog
.setControlProperty( TKGet( TK_btnNavNext
), TKGet( TK_Enabled
), Any( sal_False
) );
684 mrOptimizerDialog
.setControlProperty( TKGet( TK_btnNavFinish
), TKGet( TK_Enabled
), Any( sal_True
) );
685 mrOptimizerDialog
.setControlProperty( TKGet( TK_btnNavCancel
), TKGet( TK_Enabled
), Any( sal_True
) );
686 mrOptimizerDialog
.EnablePage( ITEM_ID_SUMMARY
);
690 case TK_btnNavCancel
: mrOptimizerDialog
.endExecute( sal_False
); break;
691 case TK_Button0Pg0
: // delete configuration
693 OUString
aSelectedItem( mrOptimizerDialog
.GetSelectedString( TK_ListBox0Pg0
) );
694 if ( aSelectedItem
.getLength() )
696 std::vector
< OptimizerSettings
>::iterator
aIter( mrOptimizerDialog
.GetOptimizerSettingsByName( aSelectedItem
) );
697 std::vector
< OptimizerSettings
>& rList( mrOptimizerDialog
.GetOptimizerSettings() );
698 if ( aIter
!= rList
.end() )
700 rList
.erase( aIter
);
701 mrOptimizerDialog
.UpdateControlStates();
709 void ActionListener::disposing( const ::com::sun::star::lang::EventObject
& /* Source */ )
710 throw ( com::sun::star::uno::RuntimeException
)
714 // -----------------------------------------------------------------------------
716 void ActionListenerListBox0Pg0::actionPerformed( const ActionEvent
& rEvent
)
717 throw ( com::sun::star::uno::RuntimeException
)
719 if ( rEvent
.ActionCommand
.getLength() )
721 std::vector
< OptimizerSettings
>::iterator
aIter( mrOptimizerDialog
.GetOptimizerSettingsByName( rEvent
.ActionCommand
) );
722 std::vector
< OptimizerSettings
>& rList( mrOptimizerDialog
.GetOptimizerSettings() );
723 if ( aIter
!= rList
.end() )
726 mrOptimizerDialog
.UpdateControlStates();
728 void ActionListenerListBox0Pg0::disposing( const ::com::sun::star::lang::EventObject
& /* Source */ )
729 throw ( com::sun::star::uno::RuntimeException
)
733 // -----------------------------------------------------------------------------
735 void TextListenerFormattedField0Pg1::textChanged( const TextEvent
& /* rEvent */ )
736 throw ( com::sun::star::uno::RuntimeException
)
739 Any aAny
= mrOptimizerDialog
.getControlProperty( TKGet( TK_FormattedField0Pg1
), TKGet( TK_EffectiveValue
) );
740 if ( aAny
>>= fDouble
)
741 mrOptimizerDialog
.SetConfigProperty( TK_JPEGQuality
, Any( (sal_Int32
)fDouble
) );
743 void TextListenerFormattedField0Pg1::disposing( const ::com::sun::star::lang::EventObject
& /* Source */ )
744 throw ( com::sun::star::uno::RuntimeException
)
748 // -----------------------------------------------------------------------------
750 void TextListenerComboBox0Pg1::textChanged( const TextEvent
& /* rEvent */ )
751 throw ( com::sun::star::uno::RuntimeException
)
753 rtl::OUString aString
;
754 Any aAny
= mrOptimizerDialog
.getControlProperty( TKGet( TK_ComboBox0Pg1
), TKGet( TK_Text
) );
755 if ( aAny
>>= aString
)
757 sal_Int32 nI0
, nI1
, nI2
, nI3
, nI4
;
758 nI0
= nI1
= nI2
= nI3
= nI4
= 0;
760 if ( mrOptimizerDialog
.getString( STR_IMAGE_RESOLUTION_0
).getToken( 1, ';', nI0
) == aString
)
761 aString
= mrOptimizerDialog
.getString( STR_IMAGE_RESOLUTION_0
).getToken( 0, ';', nI4
);
762 else if ( mrOptimizerDialog
.getString( STR_IMAGE_RESOLUTION_1
).getToken( 1, ';', nI1
) == aString
)
763 aString
= mrOptimizerDialog
.getString( STR_IMAGE_RESOLUTION_1
).getToken( 0, ';', nI4
);
764 else if ( mrOptimizerDialog
.getString( STR_IMAGE_RESOLUTION_2
).getToken( 1, ';', nI2
) == aString
)
765 aString
= mrOptimizerDialog
.getString( STR_IMAGE_RESOLUTION_2
).getToken( 0, ';', nI4
);
766 else if ( mrOptimizerDialog
.getString( STR_IMAGE_RESOLUTION_3
).getToken( 1, ';', nI3
) == aString
)
767 aString
= mrOptimizerDialog
.getString( STR_IMAGE_RESOLUTION_3
).getToken( 0, ';', nI4
);
769 mrOptimizerDialog
.SetConfigProperty( TK_ImageResolution
, Any( aString
.toInt32() ) );
772 void TextListenerComboBox0Pg1::disposing( const ::com::sun::star::lang::EventObject
& /* Source */ )
773 throw ( com::sun::star::uno::RuntimeException
)
777 // -----------------------------------------------------------------------------
779 void SpinListenerFormattedField0Pg1::up( const SpinEvent
& /* rEvent */ )
780 throw ( com::sun::star::uno::RuntimeException
)
783 Any aAny
= mrOptimizerDialog
.getControlProperty( TKGet( TK_FormattedField0Pg1
), TKGet( TK_EffectiveValue
) );
784 if ( aAny
>>= fDouble
)
789 mrOptimizerDialog
.setControlProperty( TKGet( TK_FormattedField0Pg1
), TKGet( TK_EffectiveValue
), Any( fDouble
) );
790 mrOptimizerDialog
.SetConfigProperty( TK_JPEGQuality
, Any( (sal_Int32
)fDouble
) );
793 void SpinListenerFormattedField0Pg1::down( const SpinEvent
& /* rEvent */ )
794 throw ( com::sun::star::uno::RuntimeException
)
797 Any aAny
= mrOptimizerDialog
.getControlProperty( TKGet( TK_FormattedField0Pg1
), TKGet( TK_EffectiveValue
) );
798 if ( aAny
>>= fDouble
)
803 mrOptimizerDialog
.setControlProperty( TKGet( TK_FormattedField0Pg1
), TKGet( TK_EffectiveValue
), Any( fDouble
) );
804 mrOptimizerDialog
.SetConfigProperty( TK_JPEGQuality
, Any( (sal_Int32
)fDouble
) );
807 void SpinListenerFormattedField0Pg1::first( const SpinEvent
& /* rEvent */ )
808 throw ( com::sun::star::uno::RuntimeException
)
810 mrOptimizerDialog
.setControlProperty( TKGet( TK_FormattedField0Pg1
), TKGet( TK_EffectiveValue
), Any( static_cast< double >( 0 ) ) );
811 mrOptimizerDialog
.SetConfigProperty( TK_JPEGQuality
, Any( (sal_Int32
)0 ) );
813 void SpinListenerFormattedField0Pg1::last( const SpinEvent
& /* rEvent */ )
814 throw ( com::sun::star::uno::RuntimeException
)
816 mrOptimizerDialog
.setControlProperty( TKGet( TK_FormattedField0Pg1
), TKGet( TK_EffectiveValue
), Any( static_cast< double >( 100 ) ) );
817 mrOptimizerDialog
.SetConfigProperty( TK_JPEGQuality
, Any( (sal_Int32
)100 ) );
819 void SpinListenerFormattedField0Pg1::disposing( const ::com::sun::star::lang::EventObject
& /* Source */ )
820 throw ( com::sun::star::uno::RuntimeException
)
824 // -----------------------------------------------------------------------------
826 void HelpCloseListener::addCloseListener( const Reference
< XCloseListener
>& ) throw( RuntimeException
)
829 void HelpCloseListener::removeCloseListener( const Reference
< XCloseListener
>& ) throw( RuntimeException
)
832 void HelpCloseListener::queryClosing( const EventObject
&, sal_Bool
/* bDeliverOwnership */ )
833 throw ( RuntimeException
, CloseVetoException
)
836 void HelpCloseListener::notifyClosing( const EventObject
& )
837 throw ( RuntimeException
)
840 void HelpCloseListener::disposing( const EventObject
& ) throw ( RuntimeException
)