LibreOffice Module sdext (master)  1
optimizerdialog.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 
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>
43 
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;
54 
55 
57 {
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") };
67 
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 ) ),
75  Any( sal_Int32( OD_DIALOG_WIDTH ) ) };
76 
77  sal_Int32 nCount = SAL_N_ELEMENTS( pNames );
78 
79  Sequence< OUString > aNames( pNames, nCount );
80  Sequence< Any > aValues( pValues, nCount );
81 
82  setPropertyValues(aNames, aValues);
83 }
84 
85 
87 {
88  try
89  {
90  OUString pNames[] = {
91  OUString("Height"),
92  OUString("PositionX"),
93  OUString("PositionY"),
94  OUString("Step"),
95  OUString("TabIndex"),
96  OUString("Width") };
97 
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 ) ) };
105 
106  sal_Int32 nCount = SAL_N_ELEMENTS( pNames );
107 
108  Sequence< OUString > aNames( pNames, nCount );
109  Sequence< Any > aValues( pValues, nCount );
110 
111  mxRoadmapControlModel = insertControlModel( "com.sun.star.awt.UnoControlRoadmapModel",
112  "rdmNavi", aNames, aValues );
113 
114  Reference< XPropertySet > xPropertySet( mxRoadmapControlModel, UNO_QUERY_THROW );
115  xPropertySet->setPropertyValue( "Name", Any( OUString("rdmNavi") ) );
116  mxRoadmapControl = getControl( "rdmNavi" );
122 
123  OUString const sURL("private:graphicrepository/" BMP_PRESENTATION_MINIMIZER);
124 
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 ) ) );
130  }
131  catch( Exception& )
132  {
133  }
134 }
135 
136 
137 void OptimizerDialog::InsertRoadmapItem( const sal_Int32 nIndex, const OUString& rLabel, const sal_Int32 nItemID )
138 {
139  try
140  {
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 ) );
149  }
150  catch( Exception& )
151  {
152 
153  }
154 }
155 
156 
158 {
159  sal_Int16 nInt16 = 0;
160  Any aAny;
161 
162  Sequence< sal_Int16 > aSelectedItems;
163  Sequence< OUString > aStringItemList;
164 
165  // page0
166  aAny = getControlProperty( "ListBox0Pg0", "SelectedItems" );
167  if ( aAny >>= aSelectedItems )
168  {
169  if ( aSelectedItems.hasElements() )
170  {
171  sal_Int16 nSelectedItem = aSelectedItems[ 0 ];
172  aAny = getControlProperty( "ListBox0Pg0", "StringItemList" );
173  if ( aAny >>= aStringItemList )
174  {
175  if ( aStringItemList.getLength() > nSelectedItem )
176  SetConfigProperty( TK_Name, Any( aStringItemList[ nSelectedItem ] ) );
177  }
178  }
179  }
180 
181  aAny = getControlProperty( "CheckBox3Pg3", "State" );
182  if ( !((aAny >>= nInt16) && nInt16) )
183  return;
184 
185  aAny = getControlProperty( "ListBox0Pg3", "SelectedItems" );
186  if ( !(aAny >>= aSelectedItems) )
187  return;
188 
189  if ( aSelectedItems.hasElements() )
190  {
191  sal_Int16 nSelectedItem = aSelectedItems[ 0 ];
192  aAny = getControlProperty( "ListBox0Pg3", "StringItemList" );
193  if ( aAny >>= aStringItemList )
194  {
195  if ( aStringItemList.getLength() > nSelectedItem )
196  SetConfigProperty( TK_CustomShowName, Any( aStringItemList[ nSelectedItem ] ) );
197  }
198  }
199 }
200 
201 
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 )
215 {
216  Reference< XStorable > xStorable( mxController->getModel(), UNO_QUERY_THROW );
217  mbIsReadonly = xStorable->isReadonly();
218 
219  InitDialog();
220  InitRoadmap();
222  InitPage0();
223  InitPage1();
224  InitPage2();
225  InitPage3();
226  InitPage4();
227  ActivatePage( 0 );
228 
229  OptimizationStats aStats;
230  aStats.InitializeStatusValuesFromDocument( mxController->getModel() );
231  Sequence< PropertyValue > aStatusSequence( aStats.GetStatusSequence() );
232  UpdateStatus( aStatusSequence );
233 }
234 
235 
237 {
238  // not saving configuration if the dialog has been finished via cancel or close window
239  if ( endStatus() )
241 }
242 
243 
245 {
246  Reference< XItemEventBroadcaster > xRoadmapBroadcaster( mxRoadmapControl, UNO_QUERY_THROW );
247  xRoadmapBroadcaster->addItemListener( mxItemListener );
249  UpdateConfiguration(); // taking actual control settings for the configuration
250  xRoadmapBroadcaster->removeItemListener( mxItemListener );
251 }
252 
253 
254 void OptimizerDialog::SwitchPage( sal_Int16 nNewStep )
255 {
256  if ( !(( nNewStep != mnCurrentStep ) && ( nNewStep <= MAX_STEP ) && ( nNewStep >= 0 )) )
257  return;
258 
259  sal_Int16 nOldStep = mnCurrentStep;
260  if ( nNewStep == 0 )
261  disableControl( "btnNavBack" );
262  else if ( nOldStep == 0 )
263  enableControl( "btnNavBack" );
264 
265  if ( nNewStep == MAX_STEP )
266  disableControl( "btnNavNext" );
267  else if ( nOldStep == MAX_STEP )
268  enableControl( "btnNavNext" );
269 
270  setControlProperty( "rdmNavi", "CurrentItemID", Any( nNewStep ) );
271 
272  DeactivatePage( nOldStep );
273  UpdateControlStates( nNewStep );
274 
275  ActivatePage( nNewStep );
276  mnCurrentStep = nNewStep;
277 }
278 
280 {
281  switch( nPage )
282  {
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:
289  {
295  }
296  }
297 }
298 
299 
300 OUString OptimizerDialog::GetSelectedString( OUString const & token )
301 {
302  OUString aSelectedItem;
303  Sequence< sal_Int16 > sSelectedItems;
304  Sequence< OUString > sItemList;
305 
306  if ( ( getControlProperty( token, "SelectedItems" ) >>= sSelectedItems ) &&
307  ( getControlProperty( token, "StringItemList" ) >>= sItemList ) )
308  {
309  if ( sSelectedItems.getLength() == 1 )
310  {
311  sal_Int16 nSelectedItem = sSelectedItems[ 0 ];
312  if ( nSelectedItem < sItemList.getLength() )
313  aSelectedItem = sItemList[ nSelectedItem ];
314  }
315  }
316  return aSelectedItem;
317 }
318 
319 
320 void OptimizerDialog::UpdateStatus( const css::uno::Sequence< css::beans::PropertyValue >& rStatus )
321 {
322  maStats.InitializeStatusValues( rStatus );
323  const Any* pVal( maStats.GetStatusValue( TK_Status ) );
324  if ( pVal )
325  {
326  OUString sStatus;
327  if ( *pVal >>= sStatus )
328  {
329  setControlProperty( "FixedText1Pg4", "Enabled", Any( true ) );
330  setControlProperty( "FixedText1Pg4", "Label", Any( getString( TKGet( sStatus ) ) ) );
331  }
332  }
334  if ( pVal )
335  {
336  sal_Int32 nProgress = 0;
337  if ( *pVal >>= nProgress )
338  setControlProperty( "Progress", "ProgressValue", Any( nProgress ) );
339  }
341  if ( pVal )
343 
344  reschedule();
345 }
346 
347 
348 void ItemListener::itemStateChanged( const ItemEvent& Event )
349 {
350  try
351  {
352  sal_Int16 nState;
353  OUString aControlName;
354  Reference< XControl > xControl;
355  Any aSource( Event.Source );
356  if ( aSource >>= xControl )
357  {
358  Reference< XPropertySet > xPropertySet( xControl->getModel(), UNO_QUERY_THROW );
359  xPropertySet->getPropertyValue( "Name" ) >>= aControlName;
360  PPPOptimizerTokenEnum eControl( TKGet( aControlName ) );
361  switch( eControl )
362  {
363  case TK_rdmNavi :
364  {
365  mrOptimizerDialog.SwitchPage( static_cast< sal_Int16 >( Event.ItemId ) );
366  }
367  break;
368  case TK_CheckBox1Pg1 :
369  {
370  if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
372  }
373  break;
374  case TK_CheckBox2Pg1 :
375  {
376  if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
378  }
379  break;
380  case TK_CheckBox0Pg2 :
381  {
382  if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
383  {
385  mrOptimizerDialog.setControlProperty( "RadioButton0Pg2", "Enabled", Any( nState != 0 ) );
386  mrOptimizerDialog.setControlProperty( "RadioButton1Pg2", "Enabled", Any( nState != 0 ) );
387  }
388  }
389  break;
390  case TK_RadioButton0Pg1 :
391  {
392  sal_Int16 nInt16 = 0;
393  if ( xPropertySet->getPropertyValue( "State" ) >>= nInt16 )
394  {
395  nInt16 ^= 1;
397  mrOptimizerDialog.setControlProperty( "FixedText1Pg1", "Enabled", Any( nInt16 != 0 ) );
398  mrOptimizerDialog.setControlProperty( "FormattedField0Pg1", "Enabled", Any( nInt16 != 0 ) );
399  }
400  }
401  break;
402  case TK_RadioButton1Pg1 :
403  {
404  if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
405  {
407  mrOptimizerDialog.setControlProperty( "FixedText1Pg1", "Enabled", Any( nState != 0 ) );
408  mrOptimizerDialog.setControlProperty( "FormattedField0Pg1", "Enabled", Any( nState != 0 ) );
409  }
410  }
411  break;
412  case TK_RadioButton0Pg2 :
413  {
414  sal_Int16 nInt16;
415  if ( xPropertySet->getPropertyValue( "State" ) >>= nInt16 )
416  {
417  nInt16 ^= 1;
419  }
420  }
421  break;
422  case TK_RadioButton1Pg2 :
423  {
424  if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
426  }
427  break;
428  case TK_CheckBox0Pg3 :
429  {
430  if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
432  }
433  break;
434  case TK_CheckBox1Pg3 :
435  {
436  if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
438  }
439  break;
440  case TK_CheckBox2Pg3 :
441  {
442  if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
444  }
445  break;
446  case TK_CheckBox3Pg3 :
447  {
448  if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
449  mrOptimizerDialog.setControlProperty( "ListBox0Pg3", "Enabled", Any( nState != 0 ) );
450  }
451  break;
452  case TK_CheckBox1Pg4 :
453  {
454  if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
455  mrOptimizerDialog.setControlProperty( "ComboBox0Pg4", "Enabled", Any( nState != 0 ) );
456  }
457  break;
458  case TK_RadioButton0Pg4 :
459  case TK_RadioButton1Pg4 :
460  {
461  if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
462  mrOptimizerDialog.SetConfigProperty( TK_SaveAs, Any( eControl == TK_RadioButton1Pg4 ? nState != 0 : nState == 0 ) );
463  }
464  break;
465  default:
466  break;
467  }
468  }
469  }
470  catch ( Exception& )
471  {
472 
473  }
474 }
475 void ItemListener::disposing( const css::lang::EventObject& /* Source */ )
476 {
477 }
478 
479 void ActionListener::actionPerformed( const ActionEvent& rEvent )
480 {
481  switch( TKGet( rEvent.ActionCommand ) )
482  {
485  case TK_btnNavFinish :
486  {
488 
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 ) );
496 
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 )
502  {
503  // Duplicate presentation before applying changes
504  OUString aSaveAsURL;
506 
507  // generating default file name
508  OUString aName;
509  Reference< XStorable > xStorable( mrOptimizerDialog.controller()->getModel(), UNO_QUERY );
510  if ( xStorable.is() && xStorable->hasLocation() )
511  {
512  INetURLObject aURLObj( xStorable->getLocation() );
513  if ( !aURLObj.hasFinalSlash() )
514  {
515  // tdf#105382 uri-decode file name
517  aName = aURLObj.getName(INetURLObject::LAST_SEGMENT, false,
519  }
520  }
521  else
522  {
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();
527  }
528 
529  if (!aName.isEmpty())
530  {
532  aFileOpenDialog.setDefaultName(aName);
533  }
534 
535  if (aFileOpenDialog.execute() == dialogs::ExecutableDialogResults::OK)
536  {
537  aSaveAsURL = aFileOpenDialog.getURL();
539  mrOptimizerDialog.SetConfigProperty( TK_FilterName, Any( aFileOpenDialog.getFilterName() ) );
540  }
541  if ( aSaveAsURL.isEmpty() )
542  {
543  // something goes wrong...
544  bSuccessfullyExecuted = false;
545  }
546 
547  // waiting for 500ms
549  for ( sal_uInt32 i = osl_getGlobalTimer(); ( i + 500 ) > ( osl_getGlobalTimer() ); )
551  }
552  else
553  {
554  // Apply changes to current presentation
555  Reference<XModifiable> xModifiable(mrOptimizerDialog.controller()->getModel(),
556  UNO_QUERY_THROW );
557  if ( xModifiable->isModified() )
558  {
559  SolarMutexGuard aSolarGuard;
560  std::unique_ptr<weld::MessageDialog> popupDlg(Application::CreateMessageDialog(
561  nullptr, VclMessageType::Question, VclButtonsType::YesNo,
563  if (popupDlg->run() != RET_YES)
564  {
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));
572  return;
573  }
574  }
575  }
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() )
583  {
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;
592  }
593  }
594  if ( bSuccessfullyExecuted )
595  {
596  URL aURL;
597  aURL.Protocol = "vnd.com.sun.star.comp.PPPOptimizer:";
598  aURL.Path = "optimize";
599 
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();
607 
608 
609  ErrCode errorCode;
610  try
611  {
612  ImpOptimizer aOptimizer(
614  mrOptimizerDialog.GetFrame()->getController()->getModel());
615  aOptimizer.Optimize(lArguments);
616  }
617  catch (css::io::IOException&)
618  {
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;
622  }
623  catch (css::uno::Exception&)
624  {
625  // Other general exception
626  errorCode = ERRCODE_IO_GENERAL;
627  }
628 
629  if (errorCode != ERRCODE_NONE)
630  {
631  // Restore wizard controls
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));
638 
639  OUString aFileName;
641  SfxErrorContext aEc(ERRCTX_SFX_SAVEASDOC, aFileName);
642  ErrorHandler::HandleError(errorCode);
643  break;
644  }
645 
646  mrOptimizerDialog.endExecute( bSuccessfullyExecuted );
647  }
648  else
649  {
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 ) );
655  }
656  }
657  break;
658  case TK_btnNavCancel : mrOptimizerDialog.endExecute( false ); break;
659  case TK_Button0Pg0 : // delete configuration
660  {
661  OUString aSelectedItem( mrOptimizerDialog.GetSelectedString( "ListBox0Pg0" ) );
662  if ( !aSelectedItem.isEmpty() )
663  {
664  std::vector< OptimizerSettings >::iterator aIter( mrOptimizerDialog.GetOptimizerSettingsByName( aSelectedItem ) );
665  std::vector< OptimizerSettings >& rList( mrOptimizerDialog.GetOptimizerSettings() );
666  if ( aIter != rList.end() )
667  {
668  rList.erase( aIter );
670  }
671  }
672  }
673  break;
674  default: break;
675  }
676 }
677 void ActionListener::disposing( const css::lang::EventObject& /* Source */ )
678 {
679 }
680 
681 
682 void ActionListenerListBox0Pg0::actionPerformed( const ActionEvent& rEvent )
683 {
684  if ( !rEvent.ActionCommand.isEmpty() )
685  {
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;
690  }
692 }
693 void ActionListenerListBox0Pg0::disposing( const css::lang::EventObject& /* Source */ )
694 {
695 }
696 
697 
698 void TextListenerFormattedField0Pg1::textChanged( const TextEvent& /* rEvent */ )
699 {
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) ) );
704 }
705 void TextListenerFormattedField0Pg1::disposing( const css::lang::EventObject& /* Source */ )
706 {
707 }
708 
709 namespace
710 {
711 
712 bool lcl_mapResolution(OUString& rResolution, const OUString& rImageResolution)
713 {
714  if (rImageResolution.getToken(1, ';')!=rResolution)
715  return false;
716  rResolution = rImageResolution.getToken(0, ';');
717  return true;
718 }
719 
720 }
721 
722 void TextListenerComboBox0Pg1::textChanged( const TextEvent& /* rEvent */ )
723 {
724  OUString aString;
725  Any aAny = mrOptimizerDialog.getControlProperty( "ComboBox0Pg1", "Text" );
726  if ( !(aAny >>= aString) )
727  return;
728 
729  for (int nIR{ STR_IMAGE_RESOLUTION_0 }; nIR <= STR_IMAGE_RESOLUTION_3; ++nIR)
730  {
731  if (lcl_mapResolution(aString, mrOptimizerDialog.getString(static_cast<PPPOptimizerTokenEnum>(nIR))))
732  break;
733  }
734 
736 }
737 void TextListenerComboBox0Pg1::disposing( const css::lang::EventObject& /* Source */ )
738 {
739 }
740 
741 
742 void SpinListenerFormattedField0Pg1::up( const SpinEvent& /* rEvent */ )
743 {
744  double fDouble;
745  Any aAny = mrOptimizerDialog.getControlProperty( "FormattedField0Pg1", "EffectiveValue" );
746  if ( aAny >>= fDouble )
747  {
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) ) );
753  }
754 }
755 void SpinListenerFormattedField0Pg1::down( const SpinEvent& /* rEvent */ )
756 {
757  double fDouble;
758  Any aAny = mrOptimizerDialog.getControlProperty( "FormattedField0Pg1", "EffectiveValue" );
759  if ( aAny >>= fDouble )
760  {
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) ) );
766  }
767 }
768 void SpinListenerFormattedField0Pg1::first( const SpinEvent& /* rEvent */ )
769 {
770  mrOptimizerDialog.setControlProperty( "FormattedField0Pg1", "EffectiveValue", Any( static_cast< double >( 0 ) ) );
772 }
773 void SpinListenerFormattedField0Pg1::last( const SpinEvent& /* rEvent */ )
774 {
775  mrOptimizerDialog.setControlProperty( "FormattedField0Pg1", "EffectiveValue", Any( static_cast< double >( 100 ) ) );
777 }
778 void SpinListenerFormattedField0Pg1::disposing( const css::lang::EventObject& /* Source */ )
779 {
780 }
781 
782 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL actionPerformed(const css::awt::ActionEvent &Event) override
void EnablePage(sal_Int16 nStep)
void disableControl(const OUString &rControlName)
Definition: unodialog.cxx:304
const css::uno::Any * GetStatusValue(const PPPOptimizerTokenEnum eStat) const
URL aURL
css::uno::Any getControlProperty(const OUString &rControlName, const OUString &rPropertyName)
Definition: unodialog.cxx:279
void InitializeStatusValues(const css::uno::Sequence< css::beans::PropertyValue > &rOptimizationStats)
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
#define ITEM_ID_SLIDES
virtual void SAL_CALL up(const css::awt::SpinEvent &Event) override
OptimizerDialog & mrOptimizerDialog
#define ITEM_ID_SUMMARY
bool removeExtension(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true)
void SetStatusValue(const PPPOptimizerTokenEnum eStat, const css::uno::Any &rStatValue)
css::uno::Sequence< css::beans::PropertyValue > GetConfigurationSequence()
OptimizerDialog(const css::uno::Reference< css::uno::XComponentContext > &rxContext, css::uno::Reference< css::frame::XFrame > const &rxFrame, css::uno::Reference< css::frame::XDispatch > const &rxStatusDispatcher)
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
#define DIALOG_HEIGHT
std::vector< OptimizerSettings >::iterator GetOptimizerSettingsByName(const OUString &rName)
void ActivatePage(sal_Int16 nStep)
css::uno::Reference< css::frame::XFrame > & GetFrame()
#define MAX_STEP
virtual void SAL_CALL itemStateChanged(const css::awt::ItemEvent &Event) override
css::uno::Reference< css::frame::XDispatch > & GetStatusDispatcher()
void setPropertyValues(const css::uno::Sequence< OUString > &rNameSeq, const css::uno::Sequence< css::uno::Any > &rValueSeq)
Definition: unodialog.hxx:94
#define ITEM_ID_OLE_OPTIMIZATION
void execute()
Definition: unodialog.cxx:73
void reschedule() const
Definition: unodialog.hxx:90
void InsertRoadmapItem(const sal_Int32 nIndex, const OUString &rLabel, const sal_Int32 nItemID)
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
void setControlProperty(const OUString &rControlName, const OUString &rPropertyName, const css::uno::Any &rPropertyValue)
Definition: unodialog.cxx:263
RET_YES
void InitializeStatusValuesFromDocument(const css::uno::Reference< css::frame::XModel > &rxModel)
int nCount
PPPOptimizerTokenEnum
OptimizerDialog & mrOptimizerDialog
#define ERRCODE_IO_CANTWRITE
css::uno::Reference< css::uno::XInterface > mxRoadmapControl
OptimizerDialog & mrOptimizerDialog
css::uno::Reference< css::awt::XItemListener > mxItemListener
#define SAL_N_ELEMENTS(arr)
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
void SwitchPage(sal_Int16 nNewStep)
OUString getString(const PPPOptimizerTokenEnum) const
#define ERRCODE_IO_GENERAL
int i
void SetConfigProperty(const PPPOptimizerTokenEnum, const css::uno::Any &aValue)
void DeactivatePage(sal_Int16 nStep)
bool endStatus() const
Definition: unodialog.hxx:91
static DialogMask HandleError(ErrCode nId, weld::Window *pParent=nullptr, DialogMask nMask=DialogMask::MAX)
#define ITEM_ID_GRAPHIC_OPTIMIZATION
#define ITEM_ID_INTRODUCTION
void UpdateStatus(const css::uno::Sequence< css::beans::PropertyValue > &rStatus)
void endExecute(bool bStatus)
Definition: unodialog.cxx:80
OptimizerDialog & mrOptimizerDialog
virtual void SAL_CALL actionPerformed(const css::awt::ActionEvent &Event) override
const css::uno::Reference< css::frame::XController > & controller() const
Definition: unodialog.hxx:93
void enableControl(const OUString &rControlName)
Definition: unodialog.cxx:297
virtual void SAL_CALL first(const css::awt::SpinEvent &Event) override
void DisablePage(sal_Int16 nStep)
#define OD_DIALOG_WIDTH
const PropertyValue * pValues
css::uno::Reference< css::frame::XController > mxController
Definition: unodialog.hxx:99
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
virtual void SAL_CALL last(const css::awt::SpinEvent &Event) override
css::uno::Reference< css::uno::XInterface > insertControlModel(const OUString &rServiceName, const OUString &rName, const css::uno::Sequence< OUString > &rPropertyNames, const css::uno::Sequence< css::uno::Any > &rPropertyValues)
Definition: unodialog.cxx:86
#define ERRCODE_NONE
virtual void SAL_CALL textChanged(const css::awt::TextEvent &Event) override
#define ERRCTX_SFX_SAVEASDOC
void UpdateControlStates(sal_Int16 nStep=-1)
OUString aName
std::vector< OptimizerSettings > & GetOptimizerSettings()
css::uno::Reference< css::awt::XControl > getControl(const OUString &rControlName) const
Definition: unodialog.hxx:92
OUString GetSelectedString(OUString const &token)
PPPOptimizerTokenEnum TKGet(const OUString &rToken)
css::beans::PropertyValues GetStatusSequence()
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage)
css::uno::Any GetConfigProperty(const PPPOptimizerTokenEnum) const
css::uno::Reference< css::uno::XInterface > mxRoadmapControlModel
OptimizationStats maStats
sal_Int16 mnCurrentStep
virtual void SAL_CALL down(const css::awt::SpinEvent &Event) override
sal_Int32 nState
const css::uno::Reference< css::uno::XComponentContext > & GetComponentContext() const
virtual void SAL_CALL textChanged(const css::awt::TextEvent &Event) override