vcl: allow for overriding the default PDF rendering resolution
[LibreOffice.git] / sdext / source / minimizer / optimizerdialog.cxx
blob407bf393929908f8e005ccdeae5a8a53e1134ba9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "optimizerdialog.hxx"
22 #include "impoptimizer.hxx"
23 #include "fileopendialog.hxx"
24 #include <com/sun/star/awt/XItemEventBroadcaster.hpp>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/container/XIndexContainer.hpp>
27 #include <com/sun/star/frame/XStorable.hpp>
28 #include <com/sun/star/frame/XTitle.hpp>
29 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
30 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
31 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
32 #include <com/sun/star/io/IOException.hpp>
33 #include <com/sun/star/util/XModifiable.hpp>
34 #include <sal/macros.h>
35 #include <osl/time.h>
36 #include <vcl/errinf.hxx>
37 #include <vcl/svapp.hxx>
38 #include <vcl/weld.hxx>
39 #include <svtools/sfxecode.hxx>
40 #include <svtools/ehdl.hxx>
41 #include <tools/urlobj.hxx>
42 #include <bitmaps.hlst>
44 using namespace ::com::sun::star::io;
45 using namespace ::com::sun::star::ui;
46 using namespace ::com::sun::star::awt;
47 using namespace ::com::sun::star::ucb;
48 using namespace ::com::sun::star::uno;
49 using namespace ::com::sun::star::util;
50 using namespace ::com::sun::star::lang;
51 using namespace ::com::sun::star::frame;
52 using namespace ::com::sun::star::beans;
53 using namespace ::com::sun::star::container;
56 void OptimizerDialog::InitDialog()
58 // setting the dialog properties
59 OUString pNames[] = {
60 OUString("Closeable"),
61 OUString("Height"),
62 OUString("Moveable"),
63 OUString("PositionX"),
64 OUString("PositionY"),
65 OUString("Title"),
66 OUString("Width") };
68 Any pValues[] = {
69 Any( true ),
70 Any( sal_Int32( DIALOG_HEIGHT ) ),
71 Any( true ),
72 Any( sal_Int32( 200 ) ),
73 Any( sal_Int32( 52 ) ),
74 Any( getString( STR_SUN_OPTIMIZATION_WIZARD2 ) ),
75 Any( sal_Int32( OD_DIALOG_WIDTH ) ) };
77 sal_Int32 nCount = SAL_N_ELEMENTS( pNames );
79 Sequence< OUString > aNames( pNames, nCount );
80 Sequence< Any > aValues( pValues, nCount );
82 setPropertyValues(aNames, aValues);
86 void OptimizerDialog::InitRoadmap()
88 try
90 OUString pNames[] = {
91 OUString("Height"),
92 OUString("PositionX"),
93 OUString("PositionY"),
94 OUString("Step"),
95 OUString("TabIndex"),
96 OUString("Width") };
98 Any pValues[] = {
99 Any( sal_Int32( DIALOG_HEIGHT - 26 ) ),
100 Any( sal_Int32( 0 ) ),
101 Any( sal_Int32( 0 ) ),
102 Any( sal_Int32( 0 ) ),
103 Any( mnTabIndex++ ),
104 Any( sal_Int32( 85 ) ) };
106 sal_Int32 nCount = SAL_N_ELEMENTS( pNames );
108 Sequence< OUString > aNames( pNames, nCount );
109 Sequence< Any > aValues( pValues, nCount );
111 mxRoadmapControlModel = insertControlModel( "com.sun.star.awt.UnoControlRoadmapModel",
112 "rdmNavi", aNames, aValues );
114 Reference< XPropertySet > xPropertySet( mxRoadmapControlModel, UNO_QUERY_THROW );
115 xPropertySet->setPropertyValue( "Name", Any( OUString("rdmNavi") ) );
116 mxRoadmapControl = getControl( "rdmNavi" );
117 InsertRoadmapItem( 0, getString( STR_INTRODUCTION ), ITEM_ID_INTRODUCTION );
118 InsertRoadmapItem( 1, getString( STR_SLIDES ), ITEM_ID_SLIDES );
119 InsertRoadmapItem( 2, getString( STR_IMAGE_OPTIMIZATION ), ITEM_ID_GRAPHIC_OPTIMIZATION );
120 InsertRoadmapItem( 3, getString( STR_OLE_OBJECTS ), ITEM_ID_OLE_OPTIMIZATION );
121 InsertRoadmapItem( 4, getString( STR_SUMMARY ), ITEM_ID_SUMMARY );
123 OUString const sURL("private:graphicrepository/" BMP_PRESENTATION_MINIMIZER);
125 xPropertySet->setPropertyValue( "ImageURL", Any( sURL ) );
126 xPropertySet->setPropertyValue( "Activated", Any( true ) );
127 xPropertySet->setPropertyValue( "Complete", Any( true ) );
128 xPropertySet->setPropertyValue( "CurrentItemID", Any( sal_Int16(ITEM_ID_INTRODUCTION) ) );
129 xPropertySet->setPropertyValue( "Text", Any( getString( STR_STEPS ) ) );
131 catch( Exception& )
137 void OptimizerDialog::InsertRoadmapItem( const sal_Int32 nIndex, const OUString& rLabel, const sal_Int32 nItemID )
141 Reference< XSingleServiceFactory > xSFRoadmap( mxRoadmapControlModel, UNO_QUERY_THROW );
142 Reference< XIndexContainer > aIndexContainerRoadmap( mxRoadmapControlModel, UNO_QUERY_THROW );
143 Reference< XInterface > xRoadmapItem( xSFRoadmap->createInstance(), UNO_SET_THROW );
144 Reference< XPropertySet > xPropertySet( xRoadmapItem, UNO_QUERY_THROW );
145 xPropertySet->setPropertyValue( "Label", Any( rLabel ) );
146 xPropertySet->setPropertyValue( "Enabled", Any( true ) );
147 xPropertySet->setPropertyValue( "ID", Any( nItemID ) );
148 aIndexContainerRoadmap->insertByIndex( nIndex, Any( xRoadmapItem ) );
150 catch( Exception& )
157 void OptimizerDialog::UpdateConfiguration()
159 sal_Int16 nInt16 = 0;
160 Any aAny;
162 Sequence< sal_Int16 > aSelectedItems;
163 Sequence< OUString > aStringItemList;
165 // page0
166 aAny = getControlProperty( "ListBox0Pg0", "SelectedItems" );
167 if ( aAny >>= aSelectedItems )
169 if ( aSelectedItems.hasElements() )
171 sal_Int16 nSelectedItem = aSelectedItems[ 0 ];
172 aAny = getControlProperty( "ListBox0Pg0", "StringItemList" );
173 if ( aAny >>= aStringItemList )
175 if ( aStringItemList.getLength() > nSelectedItem )
176 SetConfigProperty( TK_Name, Any( aStringItemList[ nSelectedItem ] ) );
181 aAny = getControlProperty( "CheckBox3Pg3", "State" );
182 if ( !((aAny >>= nInt16) && nInt16) )
183 return;
185 aAny = getControlProperty( "ListBox0Pg3", "SelectedItems" );
186 if ( !(aAny >>= aSelectedItems) )
187 return;
189 if ( aSelectedItems.hasElements() )
191 sal_Int16 nSelectedItem = aSelectedItems[ 0 ];
192 aAny = getControlProperty( "ListBox0Pg3", "StringItemList" );
193 if ( aAny >>= aStringItemList )
195 if ( aStringItemList.getLength() > nSelectedItem )
196 SetConfigProperty( TK_CustomShowName, Any( aStringItemList[ nSelectedItem ] ) );
202 OptimizerDialog::OptimizerDialog( const Reference< XComponentContext > &rxContext, Reference< XFrame > const & rxFrame, Reference< XDispatch > const & rxStatusDispatcher ) :
203 UnoDialog( rxContext, rxFrame ),
204 ConfigurationAccess( rxContext ),
205 mnCurrentStep( 0 ),
206 mnTabIndex( 0 ),
207 mxFrame( rxFrame ),
208 mxItemListener( new ItemListener( *this ) ),
209 mxActionListener( new ActionListener( *this ) ),
210 mxActionListenerListBox0Pg0( new ActionListenerListBox0Pg0( *this ) ),
211 mxTextListenerFormattedField0Pg1( new TextListenerFormattedField0Pg1( *this ) ),
212 mxTextListenerComboBox0Pg1( new TextListenerComboBox0Pg1( *this ) ),
213 mxSpinListenerFormattedField0Pg1( new SpinListenerFormattedField0Pg1( *this ) ),
214 mxStatusDispatcher( rxStatusDispatcher )
216 Reference< XStorable > xStorable( mxController->getModel(), UNO_QUERY_THROW );
217 mbIsReadonly = xStorable->isReadonly();
219 InitDialog();
220 InitRoadmap();
221 InitNavigationBar();
222 InitPage0();
223 InitPage1();
224 InitPage2();
225 InitPage3();
226 InitPage4();
227 ActivatePage( 0 );
229 OptimizationStats aStats;
230 aStats.InitializeStatusValuesFromDocument( mxController->getModel() );
231 Sequence< PropertyValue > aStatusSequence( aStats.GetStatusSequence() );
232 UpdateStatus( aStatusSequence );
236 OptimizerDialog::~OptimizerDialog()
238 // not saving configuration if the dialog has been finished via cancel or close window
239 if ( endStatus() )
240 SaveConfiguration();
244 void OptimizerDialog::execute()
246 Reference< XItemEventBroadcaster > xRoadmapBroadcaster( mxRoadmapControl, UNO_QUERY_THROW );
247 xRoadmapBroadcaster->addItemListener( mxItemListener );
248 UnoDialog::execute();
249 UpdateConfiguration(); // taking actual control settings for the configuration
250 xRoadmapBroadcaster->removeItemListener( mxItemListener );
254 void OptimizerDialog::SwitchPage( sal_Int16 nNewStep )
256 if ( !(( nNewStep != mnCurrentStep ) && ( nNewStep <= MAX_STEP ) && ( nNewStep >= 0 )) )
257 return;
259 sal_Int16 nOldStep = mnCurrentStep;
260 if ( nNewStep == 0 )
261 disableControl( "btnNavBack" );
262 else if ( nOldStep == 0 )
263 enableControl( "btnNavBack" );
265 if ( nNewStep == MAX_STEP )
266 disableControl( "btnNavNext" );
267 else if ( nOldStep == MAX_STEP )
268 enableControl( "btnNavNext" );
270 setControlProperty( "rdmNavi", "CurrentItemID", Any( nNewStep ) );
272 DeactivatePage( nOldStep );
273 UpdateControlStates( nNewStep );
275 ActivatePage( nNewStep );
276 mnCurrentStep = nNewStep;
279 void OptimizerDialog::UpdateControlStates( sal_Int16 nPage )
281 switch( nPage )
283 case 0 : UpdateControlStatesPage0(); break;
284 case 1 : UpdateControlStatesPage1(); break;
285 case 2 : UpdateControlStatesPage2(); break;
286 case 3 : UpdateControlStatesPage3(); break;
287 case 4 : UpdateControlStatesPage4(); break;
288 default:
290 UpdateControlStatesPage0();
291 UpdateControlStatesPage1();
292 UpdateControlStatesPage2();
293 UpdateControlStatesPage3();
294 UpdateControlStatesPage4();
300 OUString OptimizerDialog::GetSelectedString( OUString const & token )
302 OUString aSelectedItem;
303 Sequence< sal_Int16 > sSelectedItems;
304 Sequence< OUString > sItemList;
306 if ( ( getControlProperty( token, "SelectedItems" ) >>= sSelectedItems ) &&
307 ( getControlProperty( token, "StringItemList" ) >>= sItemList ) )
309 if ( sSelectedItems.getLength() == 1 )
311 sal_Int16 nSelectedItem = sSelectedItems[ 0 ];
312 if ( nSelectedItem < sItemList.getLength() )
313 aSelectedItem = sItemList[ nSelectedItem ];
316 return aSelectedItem;
320 void OptimizerDialog::UpdateStatus( const css::uno::Sequence< css::beans::PropertyValue >& rStatus )
322 maStats.InitializeStatusValues( rStatus );
323 const Any* pVal( maStats.GetStatusValue( TK_Status ) );
324 if ( pVal )
326 OUString sStatus;
327 if ( *pVal >>= sStatus )
329 setControlProperty( "FixedText1Pg4", "Enabled", Any( true ) );
330 setControlProperty( "FixedText1Pg4", "Label", Any( getString( TKGet( sStatus ) ) ) );
333 pVal = maStats.GetStatusValue( TK_Progress );
334 if ( pVal )
336 sal_Int32 nProgress = 0;
337 if ( *pVal >>= nProgress )
338 setControlProperty( "Progress", "ProgressValue", Any( nProgress ) );
340 pVal = maStats.GetStatusValue( TK_OpenNewDocument );
341 if ( pVal )
342 SetConfigProperty( TK_OpenNewDocument, *pVal );
344 reschedule();
348 void ItemListener::itemStateChanged( const ItemEvent& Event )
352 sal_Int16 nState;
353 OUString aControlName;
354 Reference< XControl > xControl;
355 Any aSource( Event.Source );
356 if ( aSource >>= xControl )
358 Reference< XPropertySet > xPropertySet( xControl->getModel(), UNO_QUERY_THROW );
359 xPropertySet->getPropertyValue( "Name" ) >>= aControlName;
360 PPPOptimizerTokenEnum eControl( TKGet( aControlName ) );
361 switch( eControl )
363 case TK_rdmNavi :
365 mrOptimizerDialog.SwitchPage( static_cast< sal_Int16 >( Event.ItemId ) );
367 break;
368 case TK_CheckBox1Pg1 :
370 if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
371 mrOptimizerDialog.SetConfigProperty( TK_RemoveCropArea, Any( nState != 0 ) );
373 break;
374 case TK_CheckBox2Pg1 :
376 if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
377 mrOptimizerDialog.SetConfigProperty( TK_EmbedLinkedGraphics, Any( nState != 0 ) );
379 break;
380 case TK_CheckBox0Pg2 :
382 if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
384 mrOptimizerDialog.SetConfigProperty( TK_OLEOptimization, Any( nState != 0 ) );
385 mrOptimizerDialog.setControlProperty( "RadioButton0Pg2", "Enabled", Any( nState != 0 ) );
386 mrOptimizerDialog.setControlProperty( "RadioButton1Pg2", "Enabled", Any( nState != 0 ) );
389 break;
390 case TK_RadioButton0Pg1 :
392 sal_Int16 nInt16 = 0;
393 if ( xPropertySet->getPropertyValue( "State" ) >>= nInt16 )
395 nInt16 ^= 1;
396 mrOptimizerDialog.SetConfigProperty( TK_JPEGCompression, Any( nInt16 != 0 ) );
397 mrOptimizerDialog.setControlProperty( "FixedText1Pg1", "Enabled", Any( nInt16 != 0 ) );
398 mrOptimizerDialog.setControlProperty( "FormattedField0Pg1", "Enabled", Any( nInt16 != 0 ) );
401 break;
402 case TK_RadioButton1Pg1 :
404 if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
406 mrOptimizerDialog.SetConfigProperty( TK_JPEGCompression, Any( nState != 0 ) );
407 mrOptimizerDialog.setControlProperty( "FixedText1Pg1", "Enabled", Any( nState != 0 ) );
408 mrOptimizerDialog.setControlProperty( "FormattedField0Pg1", "Enabled", Any( nState != 0 ) );
411 break;
412 case TK_RadioButton0Pg2 :
414 sal_Int16 nInt16;
415 if ( xPropertySet->getPropertyValue( "State" ) >>= nInt16 )
417 nInt16 ^= 1;
418 mrOptimizerDialog.SetConfigProperty( TK_OLEOptimizationType, Any( nInt16 ) );
421 break;
422 case TK_RadioButton1Pg2 :
424 if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
425 mrOptimizerDialog.SetConfigProperty( TK_OLEOptimizationType, Any( nState ) );
427 break;
428 case TK_CheckBox0Pg3 :
430 if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
431 mrOptimizerDialog.SetConfigProperty( TK_DeleteUnusedMasterPages, Any( nState != 0 ) );
433 break;
434 case TK_CheckBox1Pg3 :
436 if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
437 mrOptimizerDialog.SetConfigProperty( TK_DeleteNotesPages, Any( nState != 0 ) );
439 break;
440 case TK_CheckBox2Pg3 :
442 if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
443 mrOptimizerDialog.SetConfigProperty( TK_DeleteHiddenSlides, Any( nState != 0 ) );
445 break;
446 case TK_CheckBox3Pg3 :
448 if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
449 mrOptimizerDialog.setControlProperty( "ListBox0Pg3", "Enabled", Any( nState != 0 ) );
451 break;
452 case TK_CheckBox1Pg4 :
454 if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
455 mrOptimizerDialog.setControlProperty( "ComboBox0Pg4", "Enabled", Any( nState != 0 ) );
457 break;
458 case TK_RadioButton0Pg4 :
459 case TK_RadioButton1Pg4 :
461 if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
462 mrOptimizerDialog.SetConfigProperty( TK_SaveAs, Any( eControl == TK_RadioButton1Pg4 ? nState != 0 : nState == 0 ) );
464 break;
465 default:
466 break;
470 catch ( Exception& )
475 void ItemListener::disposing( const css::lang::EventObject& /* Source */ )
479 void ActionListener::actionPerformed( const ActionEvent& rEvent )
481 switch( TKGet( rEvent.ActionCommand ) )
483 case TK_btnNavBack : mrOptimizerDialog.SwitchPage( mrOptimizerDialog.mnCurrentStep - 1 ); break;
484 case TK_btnNavNext : mrOptimizerDialog.SwitchPage( mrOptimizerDialog.mnCurrentStep + 1 ); break;
485 case TK_btnNavFinish :
487 mrOptimizerDialog.UpdateConfiguration();
489 mrOptimizerDialog.SwitchPage( ITEM_ID_SUMMARY );
490 mrOptimizerDialog.DisablePage( ITEM_ID_SUMMARY );
491 mrOptimizerDialog.setControlProperty( "btnNavBack", "Enabled", Any( false ) );
492 mrOptimizerDialog.setControlProperty( "btnNavNext", "Enabled", Any( false ) );
493 mrOptimizerDialog.setControlProperty( "btnNavFinish", "Enabled", Any( false ) );
494 mrOptimizerDialog.setControlProperty( "btnNavCancel", "Enabled", Any( false ) );
495 mrOptimizerDialog.setControlProperty( "FixedText0Pg4", "Enabled", Any( true ) );
497 // check if we have to open the FileDialog
498 bool bSuccessfullyExecuted = true;
499 sal_Int16 nInt16 = 0;
500 mrOptimizerDialog.getControlProperty( "RadioButton1Pg4", "State" ) >>= nInt16;
501 if ( nInt16 )
503 // Duplicate presentation before applying changes
504 OUString aSaveAsURL;
505 FileOpenDialog aFileOpenDialog( mrOptimizerDialog.GetComponentContext() );
507 // generating default file name
508 OUString aName;
509 Reference< XStorable > xStorable( mrOptimizerDialog.controller()->getModel(), UNO_QUERY );
510 if ( xStorable.is() && xStorable->hasLocation() )
512 INetURLObject aURLObj( xStorable->getLocation() );
513 if ( !aURLObj.hasFinalSlash() )
515 // tdf#105382 uri-decode file name
516 aURLObj.removeExtension(INetURLObject::LAST_SEGMENT, false);
517 aName = aURLObj.getName(INetURLObject::LAST_SEGMENT, false,
518 INetURLObject::DecodeMechanism::WithCharset);
521 else
523 // If no filename, try to use model title ("Untitled 1" or something like this)
524 Reference<XTitle> xTitle(
525 mrOptimizerDialog.GetFrame()->getController()->getModel(), UNO_QUERY);
526 aName = xTitle->getTitle();
529 if (!aName.isEmpty())
531 aName += " " + mrOptimizerDialog.getString(STR_FILENAME_SUFFIX);
532 aFileOpenDialog.setDefaultName(aName);
535 if (aFileOpenDialog.execute() == dialogs::ExecutableDialogResults::OK)
537 aSaveAsURL = aFileOpenDialog.getURL();
538 mrOptimizerDialog.SetConfigProperty( TK_SaveAsURL, Any( aSaveAsURL ) );
539 mrOptimizerDialog.SetConfigProperty( TK_FilterName, Any( aFileOpenDialog.getFilterName() ) );
541 if ( aSaveAsURL.isEmpty() )
543 // something goes wrong...
544 bSuccessfullyExecuted = false;
547 // waiting for 500ms
548 mrOptimizerDialog.reschedule();
549 for ( sal_uInt32 i = osl_getGlobalTimer(); ( i + 500 ) > ( osl_getGlobalTimer() ); )
550 mrOptimizerDialog.reschedule();
552 else
554 // Apply changes to current presentation
555 Reference<XModifiable> xModifiable(mrOptimizerDialog.controller()->getModel(),
556 UNO_QUERY_THROW );
557 if ( xModifiable->isModified() )
559 SolarMutexGuard aSolarGuard;
560 std::unique_ptr<weld::MessageDialog> popupDlg(Application::CreateMessageDialog(
561 nullptr, VclMessageType::Question, VclButtonsType::YesNo,
562 mrOptimizerDialog.getString(STR_WARN_UNSAVED_PRESENTATION)));
563 if (popupDlg->run() != RET_YES)
565 // Selected not "yes" ("no" or dialog was cancelled) so return to previous step
566 mrOptimizerDialog.setControlProperty("btnNavBack", "Enabled",
567 Any(true));
568 mrOptimizerDialog.setControlProperty("btnNavNext", "Enabled", Any(false));
569 mrOptimizerDialog.setControlProperty("btnNavFinish", "Enabled", Any(true));
570 mrOptimizerDialog.setControlProperty("btnNavCancel", "Enabled", Any(true));
571 mrOptimizerDialog.EnablePage(ITEM_ID_SUMMARY);
572 return;
576 if ( bSuccessfullyExecuted )
577 { // now check if we have to store a session template
578 nInt16 = 0;
579 OUString aSettingsName;
580 mrOptimizerDialog.getControlProperty( "CheckBox1Pg4", "State" ) >>= nInt16;
581 mrOptimizerDialog.getControlProperty( "ComboBox0Pg4", "Text" ) >>= aSettingsName;
582 if ( nInt16 && !aSettingsName.isEmpty() )
584 std::vector< OptimizerSettings >::iterator aIter( mrOptimizerDialog.GetOptimizerSettingsByName( aSettingsName ) );
585 std::vector< OptimizerSettings >& rSettings( mrOptimizerDialog.GetOptimizerSettings() );
586 OptimizerSettings aNewSettings( rSettings[ 0 ] );
587 aNewSettings.maName = aSettingsName;
588 if ( aIter == rSettings.end() )
589 rSettings.push_back( aNewSettings );
590 else
591 *aIter = aNewSettings;
594 if ( bSuccessfullyExecuted )
596 URL aURL;
597 aURL.Protocol = "vnd.com.sun.star.comp.PPPOptimizer:";
598 aURL.Path = "optimize";
600 Sequence< PropertyValue > lArguments( 3 );
601 lArguments[ 0 ].Name = "Settings";
602 lArguments[ 0 ].Value <<= mrOptimizerDialog.GetConfigurationSequence();
603 lArguments[ 1 ].Name = "StatusDispatcher";
604 lArguments[ 1 ].Value <<= mrOptimizerDialog.GetStatusDispatcher();
605 lArguments[ 2 ].Name = "InformationDialog";
606 lArguments[ 2 ].Value <<= mrOptimizerDialog.GetFrame();
609 ErrCode errorCode;
612 ImpOptimizer aOptimizer(
613 mrOptimizerDialog.GetComponentContext(),
614 mrOptimizerDialog.GetFrame()->getController()->getModel());
615 aOptimizer.Optimize(lArguments);
617 catch (css::io::IOException&)
619 // We always receive just ERRCODE_IO_CANTWRITE in case of problems, so no need to bother
620 // about extracting error code from exception text
621 errorCode = ERRCODE_IO_CANTWRITE;
623 catch (css::uno::Exception&)
625 // Other general exception
626 errorCode = ERRCODE_IO_GENERAL;
629 if (errorCode != ERRCODE_NONE)
631 // Restore wizard controls
632 mrOptimizerDialog.maStats.SetStatusValue(TK_Progress,
633 Any(static_cast<sal_Int32>(0)));
634 mrOptimizerDialog.setControlProperty("btnNavBack", "Enabled", Any(true));
635 mrOptimizerDialog.setControlProperty("btnNavNext", "Enabled", Any(false));
636 mrOptimizerDialog.setControlProperty("btnNavFinish", "Enabled", Any(true));
637 mrOptimizerDialog.setControlProperty("btnNavCancel", "Enabled", Any(true));
639 OUString aFileName;
640 mrOptimizerDialog.GetConfigProperty(TK_SaveAsURL) >>= aFileName;
641 SfxErrorContext aEc(ERRCTX_SFX_SAVEASDOC, aFileName);
642 ErrorHandler::HandleError(errorCode);
643 break;
646 mrOptimizerDialog.endExecute( bSuccessfullyExecuted );
648 else
650 mrOptimizerDialog.setControlProperty( "btnNavBack", "Enabled", Any( true ) );
651 mrOptimizerDialog.setControlProperty( "btnNavNext", "Enabled", Any( false ) );
652 mrOptimizerDialog.setControlProperty( "btnNavFinish", "Enabled", Any( true ) );
653 mrOptimizerDialog.setControlProperty( "btnNavCancel", "Enabled", Any( true ) );
654 mrOptimizerDialog.EnablePage( ITEM_ID_SUMMARY );
657 break;
658 case TK_btnNavCancel : mrOptimizerDialog.endExecute( false ); break;
659 case TK_Button0Pg0 : // delete configuration
661 OUString aSelectedItem( mrOptimizerDialog.GetSelectedString( "ListBox0Pg0" ) );
662 if ( !aSelectedItem.isEmpty() )
664 std::vector< OptimizerSettings >::iterator aIter( mrOptimizerDialog.GetOptimizerSettingsByName( aSelectedItem ) );
665 std::vector< OptimizerSettings >& rList( mrOptimizerDialog.GetOptimizerSettings() );
666 if ( aIter != rList.end() )
668 rList.erase( aIter );
669 mrOptimizerDialog.UpdateControlStates();
673 break;
674 default: break;
677 void ActionListener::disposing( const css::lang::EventObject& /* Source */ )
682 void ActionListenerListBox0Pg0::actionPerformed( const ActionEvent& rEvent )
684 if ( !rEvent.ActionCommand.isEmpty() )
686 std::vector< OptimizerSettings >::iterator aIter( mrOptimizerDialog.GetOptimizerSettingsByName( rEvent.ActionCommand ) );
687 std::vector< OptimizerSettings >& rList( mrOptimizerDialog.GetOptimizerSettings() );
688 if ( aIter != rList.end() )
689 rList[ 0 ] = *aIter;
691 mrOptimizerDialog.UpdateControlStates();
693 void ActionListenerListBox0Pg0::disposing( const css::lang::EventObject& /* Source */ )
698 void TextListenerFormattedField0Pg1::textChanged( const TextEvent& /* rEvent */ )
700 double fDouble = 0;
701 Any aAny = mrOptimizerDialog.getControlProperty( "FormattedField0Pg1", "EffectiveValue" );
702 if ( aAny >>= fDouble )
703 mrOptimizerDialog.SetConfigProperty( TK_JPEGQuality, Any( static_cast<sal_Int32>(fDouble) ) );
705 void TextListenerFormattedField0Pg1::disposing( const css::lang::EventObject& /* Source */ )
709 namespace
712 bool lcl_mapResolution(OUString& rResolution, const OUString& rImageResolution)
714 if (rImageResolution.getToken(1, ';')!=rResolution)
715 return false;
716 rResolution = rImageResolution.getToken(0, ';');
717 return true;
722 void TextListenerComboBox0Pg1::textChanged( const TextEvent& /* rEvent */ )
724 OUString aString;
725 Any aAny = mrOptimizerDialog.getControlProperty( "ComboBox0Pg1", "Text" );
726 if ( !(aAny >>= aString) )
727 return;
729 for (int nIR{ STR_IMAGE_RESOLUTION_0 }; nIR <= STR_IMAGE_RESOLUTION_3; ++nIR)
731 if (lcl_mapResolution(aString, mrOptimizerDialog.getString(static_cast<PPPOptimizerTokenEnum>(nIR))))
732 break;
735 mrOptimizerDialog.SetConfigProperty( TK_ImageResolution, Any( aString.toInt32() ) );
737 void TextListenerComboBox0Pg1::disposing( const css::lang::EventObject& /* Source */ )
742 void SpinListenerFormattedField0Pg1::up( const SpinEvent& /* rEvent */ )
744 double fDouble;
745 Any aAny = mrOptimizerDialog.getControlProperty( "FormattedField0Pg1", "EffectiveValue" );
746 if ( aAny >>= fDouble )
748 fDouble += 9;
749 if ( fDouble > 100 )
750 fDouble = 100;
751 mrOptimizerDialog.setControlProperty( "FormattedField0Pg1", "EffectiveValue", Any( fDouble ) );
752 mrOptimizerDialog.SetConfigProperty( TK_JPEGQuality, Any( static_cast<sal_Int32>(fDouble) ) );
755 void SpinListenerFormattedField0Pg1::down( const SpinEvent& /* rEvent */ )
757 double fDouble;
758 Any aAny = mrOptimizerDialog.getControlProperty( "FormattedField0Pg1", "EffectiveValue" );
759 if ( aAny >>= fDouble )
761 fDouble -= 9;
762 if ( fDouble < 0 )
763 fDouble = 0;
764 mrOptimizerDialog.setControlProperty( "FormattedField0Pg1", "EffectiveValue", Any( fDouble ) );
765 mrOptimizerDialog.SetConfigProperty( TK_JPEGQuality, Any( static_cast<sal_Int32>(fDouble) ) );
768 void SpinListenerFormattedField0Pg1::first( const SpinEvent& /* rEvent */ )
770 mrOptimizerDialog.setControlProperty( "FormattedField0Pg1", "EffectiveValue", Any( static_cast< double >( 0 ) ) );
771 mrOptimizerDialog.SetConfigProperty( TK_JPEGQuality, Any( sal_Int32(0) ) );
773 void SpinListenerFormattedField0Pg1::last( const SpinEvent& /* rEvent */ )
775 mrOptimizerDialog.setControlProperty( "FormattedField0Pg1", "EffectiveValue", Any( static_cast< double >( 100 ) ) );
776 mrOptimizerDialog.SetConfigProperty( TK_JPEGQuality, Any( sal_Int32(100) ) );
778 void SpinListenerFormattedField0Pg1::disposing( const css::lang::EventObject& /* Source */ )
782 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */