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  xPropertySet->setPropertyValue( "ImageURL", Any( OUString("private:graphicrepository/" BMP_PRESENTATION_MINIMIZER) ) );
124  xPropertySet->setPropertyValue( "Activated", Any( true ) );
125  xPropertySet->setPropertyValue( "Complete", Any( true ) );
126  xPropertySet->setPropertyValue( "CurrentItemID", Any( sal_Int16(ITEM_ID_INTRODUCTION) ) );
127  xPropertySet->setPropertyValue( "Text", Any( getString( STR_STEPS ) ) );
128  }
129  catch( Exception& )
130  {
131  }
132 }
133 
134 
135 void OptimizerDialog::InsertRoadmapItem( const sal_Int32 nIndex, const OUString& rLabel, const sal_Int32 nItemID )
136 {
137  try
138  {
139  Reference< XSingleServiceFactory > xSFRoadmap( mxRoadmapControlModel, UNO_QUERY_THROW );
140  Reference< XIndexContainer > aIndexContainerRoadmap( mxRoadmapControlModel, UNO_QUERY_THROW );
141  Reference< XInterface > xRoadmapItem( xSFRoadmap->createInstance(), UNO_SET_THROW );
142  Reference< XPropertySet > xPropertySet( xRoadmapItem, UNO_QUERY_THROW );
143  xPropertySet->setPropertyValue( "Label", Any( rLabel ) );
144  xPropertySet->setPropertyValue( "Enabled", Any( true ) );
145  xPropertySet->setPropertyValue( "ID", Any( nItemID ) );
146  aIndexContainerRoadmap->insertByIndex( nIndex, Any( xRoadmapItem ) );
147  }
148  catch( Exception& )
149  {
150 
151  }
152 }
153 
154 
156 {
157  sal_Int16 nInt16 = 0;
158  Any aAny;
159 
160  Sequence< sal_Int16 > aSelectedItems;
161  Sequence< OUString > aStringItemList;
162 
163  // page0
164  aAny = getControlProperty( "ListBox0Pg0", "SelectedItems" );
165  if ( aAny >>= aSelectedItems )
166  {
167  if ( aSelectedItems.hasElements() )
168  {
169  sal_Int16 nSelectedItem = aSelectedItems[ 0 ];
170  aAny = getControlProperty( "ListBox0Pg0", "StringItemList" );
171  if ( aAny >>= aStringItemList )
172  {
173  if ( aStringItemList.getLength() > nSelectedItem )
174  SetConfigProperty( TK_Name, Any( aStringItemList[ nSelectedItem ] ) );
175  }
176  }
177  }
178 
179  aAny = getControlProperty( "CheckBox3Pg3", "State" );
180  if ( !((aAny >>= nInt16) && nInt16) )
181  return;
182 
183  aAny = getControlProperty( "ListBox0Pg3", "SelectedItems" );
184  if ( !(aAny >>= aSelectedItems) )
185  return;
186 
187  if ( aSelectedItems.hasElements() )
188  {
189  sal_Int16 nSelectedItem = aSelectedItems[ 0 ];
190  aAny = getControlProperty( "ListBox0Pg3", "StringItemList" );
191  if ( aAny >>= aStringItemList )
192  {
193  if ( aStringItemList.getLength() > nSelectedItem )
194  SetConfigProperty( TK_CustomShowName, Any( aStringItemList[ nSelectedItem ] ) );
195  }
196  }
197 }
198 
199 
200 OptimizerDialog::OptimizerDialog( const Reference< XComponentContext > &rxContext, Reference< XFrame > const & rxFrame, Reference< XDispatch > const & rxStatusDispatcher ) :
201  UnoDialog( rxContext, rxFrame ),
202  ConfigurationAccess( rxContext ),
203  mnCurrentStep( 0 ),
204  mnTabIndex( 0 ),
205  mxFrame( rxFrame ),
206  mxItemListener( new ItemListener( *this ) ),
207  mxActionListener( new ActionListener( *this ) ),
208  mxActionListenerListBox0Pg0( new ActionListenerListBox0Pg0( *this ) ),
209  mxTextListenerFormattedField0Pg1( new TextListenerFormattedField0Pg1( *this ) ),
210  mxTextListenerComboBox0Pg1( new TextListenerComboBox0Pg1( *this ) ),
211  mxSpinListenerFormattedField0Pg1( new SpinListenerFormattedField0Pg1( *this ) ),
212  mxStatusDispatcher( rxStatusDispatcher )
213 {
214  Reference< XStorable > xStorable( mxController->getModel(), UNO_QUERY_THROW );
215  mbIsReadonly = xStorable->isReadonly();
216 
217  InitDialog();
218  InitRoadmap();
220  InitPage0();
221  InitPage1();
222  InitPage2();
223  InitPage3();
224  InitPage4();
225  ActivatePage( 0 );
226 
227  OptimizationStats aStats;
228  aStats.InitializeStatusValuesFromDocument( mxController->getModel() );
229  Sequence< PropertyValue > aStatusSequence( aStats.GetStatusSequence() );
230  UpdateStatus( aStatusSequence );
231 }
232 
233 
235 {
236  // not saving configuration if the dialog has been finished via cancel or close window
237  if ( endStatus() )
239 }
240 
241 
243 {
244  Reference< XItemEventBroadcaster > xRoadmapBroadcaster( mxRoadmapControl, UNO_QUERY_THROW );
245  xRoadmapBroadcaster->addItemListener( mxItemListener );
247  UpdateConfiguration(); // taking actual control settings for the configuration
248  xRoadmapBroadcaster->removeItemListener( mxItemListener );
249 }
250 
251 
252 void OptimizerDialog::SwitchPage( sal_Int16 nNewStep )
253 {
254  if ( !(( nNewStep != mnCurrentStep ) && ( nNewStep <= MAX_STEP ) && ( nNewStep >= 0 )) )
255  return;
256 
257  sal_Int16 nOldStep = mnCurrentStep;
258  if ( nNewStep == 0 )
259  disableControl( "btnNavBack" );
260  else if ( nOldStep == 0 )
261  enableControl( "btnNavBack" );
262 
263  if ( nNewStep == MAX_STEP )
264  disableControl( "btnNavNext" );
265  else if ( nOldStep == MAX_STEP )
266  enableControl( "btnNavNext" );
267 
268  setControlProperty( "rdmNavi", "CurrentItemID", Any( nNewStep ) );
269 
270  DeactivatePage( nOldStep );
271  UpdateControlStates( nNewStep );
272 
273  ActivatePage( nNewStep );
274  mnCurrentStep = nNewStep;
275 }
276 
278 {
279  switch( nPage )
280  {
281  case 0 : UpdateControlStatesPage0(); break;
282  case 1 : UpdateControlStatesPage1(); break;
283  case 2 : UpdateControlStatesPage2(); break;
284  case 3 : UpdateControlStatesPage3(); break;
285  case 4 : UpdateControlStatesPage4(); break;
286  default:
287  {
293  }
294  }
295 }
296 
297 
298 OUString OptimizerDialog::GetSelectedString( OUString const & token )
299 {
300  OUString aSelectedItem;
301  Sequence< sal_Int16 > sSelectedItems;
302  Sequence< OUString > sItemList;
303 
304  if ( ( getControlProperty( token, "SelectedItems" ) >>= sSelectedItems ) &&
305  ( getControlProperty( token, "StringItemList" ) >>= sItemList ) )
306  {
307  if ( sSelectedItems.getLength() == 1 )
308  {
309  sal_Int16 nSelectedItem = sSelectedItems[ 0 ];
310  if ( nSelectedItem < sItemList.getLength() )
311  aSelectedItem = sItemList[ nSelectedItem ];
312  }
313  }
314  return aSelectedItem;
315 }
316 
317 
318 void OptimizerDialog::UpdateStatus( const css::uno::Sequence< css::beans::PropertyValue >& rStatus )
319 {
320  maStats.InitializeStatusValues( rStatus );
321  const Any* pVal( maStats.GetStatusValue( TK_Status ) );
322  if ( pVal )
323  {
324  OUString sStatus;
325  if ( *pVal >>= sStatus )
326  {
327  setControlProperty( "FixedText1Pg4", "Enabled", Any( true ) );
328  setControlProperty( "FixedText1Pg4", "Label", Any( getString( TKGet( sStatus ) ) ) );
329  }
330  }
332  if ( pVal )
333  {
334  sal_Int32 nProgress = 0;
335  if ( *pVal >>= nProgress )
336  setControlProperty( "Progress", "ProgressValue", Any( nProgress ) );
337  }
339  if ( pVal )
341 
342  reschedule();
343 }
344 
345 
346 void ItemListener::itemStateChanged( const ItemEvent& Event )
347 {
348  try
349  {
350  sal_Int16 nState;
351  OUString aControlName;
352  Reference< XControl > xControl;
353  Any aSource( Event.Source );
354  if ( aSource >>= xControl )
355  {
356  Reference< XPropertySet > xPropertySet( xControl->getModel(), UNO_QUERY_THROW );
357  xPropertySet->getPropertyValue( "Name" ) >>= aControlName;
358  PPPOptimizerTokenEnum eControl( TKGet( aControlName ) );
359  switch( eControl )
360  {
361  case TK_rdmNavi :
362  {
363  mrOptimizerDialog.SwitchPage( static_cast< sal_Int16 >( Event.ItemId ) );
364  }
365  break;
366  case TK_CheckBox1Pg1 :
367  {
368  if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
370  }
371  break;
372  case TK_CheckBox2Pg1 :
373  {
374  if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
376  }
377  break;
378  case TK_CheckBox0Pg2 :
379  {
380  if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
381  {
383  mrOptimizerDialog.setControlProperty( "RadioButton0Pg2", "Enabled", Any( nState != 0 ) );
384  mrOptimizerDialog.setControlProperty( "RadioButton1Pg2", "Enabled", Any( nState != 0 ) );
385  }
386  }
387  break;
388  case TK_RadioButton0Pg1 :
389  {
390  sal_Int16 nInt16 = 0;
391  if ( xPropertySet->getPropertyValue( "State" ) >>= nInt16 )
392  {
393  nInt16 ^= 1;
395  mrOptimizerDialog.setControlProperty( "FixedText1Pg1", "Enabled", Any( nInt16 != 0 ) );
396  mrOptimizerDialog.setControlProperty( "FormattedField0Pg1", "Enabled", Any( nInt16 != 0 ) );
397  }
398  }
399  break;
400  case TK_RadioButton1Pg1 :
401  {
402  if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
403  {
405  mrOptimizerDialog.setControlProperty( "FixedText1Pg1", "Enabled", Any( nState != 0 ) );
406  mrOptimizerDialog.setControlProperty( "FormattedField0Pg1", "Enabled", Any( nState != 0 ) );
407  }
408  }
409  break;
410  case TK_RadioButton0Pg2 :
411  {
412  sal_Int16 nInt16;
413  if ( xPropertySet->getPropertyValue( "State" ) >>= nInt16 )
414  {
415  nInt16 ^= 1;
417  }
418  }
419  break;
420  case TK_RadioButton1Pg2 :
421  {
422  if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
424  }
425  break;
426  case TK_CheckBox0Pg3 :
427  {
428  if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
430  }
431  break;
432  case TK_CheckBox1Pg3 :
433  {
434  if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
436  }
437  break;
438  case TK_CheckBox2Pg3 :
439  {
440  if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
442  }
443  break;
444  case TK_CheckBox3Pg3 :
445  {
446  if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
447  mrOptimizerDialog.setControlProperty( "ListBox0Pg3", "Enabled", Any( nState != 0 ) );
448  }
449  break;
450  case TK_CheckBox1Pg4 :
451  {
452  if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
453  mrOptimizerDialog.setControlProperty( "ComboBox0Pg4", "Enabled", Any( nState != 0 ) );
454  }
455  break;
456  case TK_RadioButton0Pg4 :
457  case TK_RadioButton1Pg4 :
458  {
459  if ( xPropertySet->getPropertyValue( "State" ) >>= nState )
460  mrOptimizerDialog.SetConfigProperty( TK_SaveAs, Any( eControl == TK_RadioButton1Pg4 ? nState != 0 : nState == 0 ) );
461  }
462  break;
463  default:
464  break;
465  }
466  }
467  }
468  catch ( Exception& )
469  {
470 
471  }
472 }
473 void ItemListener::disposing( const css::lang::EventObject& /* Source */ )
474 {
475 }
476 
477 void ActionListener::actionPerformed( const ActionEvent& rEvent )
478 {
479  switch( TKGet( rEvent.ActionCommand ) )
480  {
483  case TK_btnNavFinish :
484  {
486 
489  mrOptimizerDialog.setControlProperty( "btnNavBack", "Enabled", Any( false ) );
490  mrOptimizerDialog.setControlProperty( "btnNavNext", "Enabled", Any( false ) );
491  mrOptimizerDialog.setControlProperty( "btnNavFinish", "Enabled", Any( false ) );
492  mrOptimizerDialog.setControlProperty( "btnNavCancel", "Enabled", Any( false ) );
493  mrOptimizerDialog.setControlProperty( "FixedText0Pg4", "Enabled", Any( true ) );
494 
495  // check if we have to open the FileDialog
496  bool bSuccessfullyExecuted = true;
497  sal_Int16 nInt16 = 0;
498  mrOptimizerDialog.getControlProperty( "RadioButton1Pg4", "State" ) >>= nInt16;
499  if ( nInt16 )
500  {
501  // Duplicate presentation before applying changes
502  OUString aSaveAsURL;
504 
505  // generating default file name
506  OUString aName;
507  Reference< XStorable > xStorable( mrOptimizerDialog.controller()->getModel(), UNO_QUERY );
508  if ( xStorable.is() && xStorable->hasLocation() )
509  {
510  INetURLObject aURLObj( xStorable->getLocation() );
511  if ( !aURLObj.hasFinalSlash() )
512  {
513  // tdf#105382 uri-decode file name
515  aName = aURLObj.getName(INetURLObject::LAST_SEGMENT, false,
517  }
518  }
519  else
520  {
521  // If no filename, try to use model title ("Untitled 1" or something like this)
522  Reference<XTitle> xTitle(
523  mrOptimizerDialog.GetFrame()->getController()->getModel(), UNO_QUERY);
524  aName = xTitle->getTitle();
525  }
526 
527  if (!aName.isEmpty())
528  {
530  aFileOpenDialog.setDefaultName(aName);
531  }
532 
533  if (aFileOpenDialog.execute() == dialogs::ExecutableDialogResults::OK)
534  {
535  aSaveAsURL = aFileOpenDialog.getURL();
537  mrOptimizerDialog.SetConfigProperty( TK_FilterName, Any( aFileOpenDialog.getFilterName() ) );
538  }
539  if ( aSaveAsURL.isEmpty() )
540  {
541  // something goes wrong...
542  bSuccessfullyExecuted = false;
543  }
544 
545  // waiting for 500ms
547  for ( sal_uInt32 i = osl_getGlobalTimer(); ( i + 500 ) > ( osl_getGlobalTimer() ); )
549  }
550  else
551  {
552  // Apply changes to current presentation
553  Reference<XModifiable> xModifiable(mrOptimizerDialog.controller()->getModel(),
554  UNO_QUERY_THROW );
555  if ( xModifiable->isModified() )
556  {
557  SolarMutexGuard aSolarGuard;
558  std::unique_ptr<weld::MessageDialog> popupDlg(Application::CreateMessageDialog(
559  nullptr, VclMessageType::Question, VclButtonsType::YesNo,
561  if (popupDlg->run() != RET_YES)
562  {
563  // Selected not "yes" ("no" or dialog was cancelled) so return to previous step
564  mrOptimizerDialog.setControlProperty("btnNavBack", "Enabled",
565  Any(true));
566  mrOptimizerDialog.setControlProperty("btnNavNext", "Enabled", Any(false));
567  mrOptimizerDialog.setControlProperty("btnNavFinish", "Enabled", Any(true));
568  mrOptimizerDialog.setControlProperty("btnNavCancel", "Enabled", Any(true));
570  return;
571  }
572  }
573  }
574  if ( bSuccessfullyExecuted )
575  { // now check if we have to store a session template
576  nInt16 = 0;
577  OUString aSettingsName;
578  mrOptimizerDialog.getControlProperty( "CheckBox1Pg4", "State" ) >>= nInt16;
579  mrOptimizerDialog.getControlProperty( "ComboBox0Pg4", "Text" ) >>= aSettingsName;
580  if ( nInt16 && !aSettingsName.isEmpty() )
581  {
582  std::vector< OptimizerSettings >::iterator aIter( mrOptimizerDialog.GetOptimizerSettingsByName( aSettingsName ) );
583  std::vector< OptimizerSettings >& rSettings( mrOptimizerDialog.GetOptimizerSettings() );
584  OptimizerSettings aNewSettings( rSettings[ 0 ] );
585  aNewSettings.maName = aSettingsName;
586  if ( aIter == rSettings.end() )
587  rSettings.push_back( aNewSettings );
588  else
589  *aIter = aNewSettings;
590  }
591  }
592  if ( bSuccessfullyExecuted )
593  {
594  URL aURL;
595  aURL.Protocol = "vnd.com.sun.star.comp.PPPOptimizer:";
596  aURL.Path = "optimize";
597 
598  Sequence< PropertyValue > lArguments( 3 );
599  lArguments[ 0 ].Name = "Settings";
600  lArguments[ 0 ].Value <<= mrOptimizerDialog.GetConfigurationSequence();
601  lArguments[ 1 ].Name = "StatusDispatcher";
602  lArguments[ 1 ].Value <<= mrOptimizerDialog.GetStatusDispatcher();
603  lArguments[ 2 ].Name = "InformationDialog";
604  lArguments[ 2 ].Value <<= mrOptimizerDialog.GetFrame();
605 
606 
607  ErrCode errorCode;
608  try
609  {
610  ImpOptimizer aOptimizer(
612  mrOptimizerDialog.GetFrame()->getController()->getModel());
613  aOptimizer.Optimize(lArguments);
614  }
615  catch (css::io::IOException&)
616  {
617  // We always receive just ERRCODE_IO_CANTWRITE in case of problems, so no need to bother
618  // about extracting error code from exception text
619  errorCode = ERRCODE_IO_CANTWRITE;
620  }
621  catch (css::uno::Exception&)
622  {
623  // Other general exception
624  errorCode = ERRCODE_IO_GENERAL;
625  }
626 
627  if (errorCode != ERRCODE_NONE)
628  {
629  // Restore wizard controls
631  Any(static_cast<sal_Int32>(0)));
632  mrOptimizerDialog.setControlProperty("btnNavBack", "Enabled", Any(true));
633  mrOptimizerDialog.setControlProperty("btnNavNext", "Enabled", Any(false));
634  mrOptimizerDialog.setControlProperty("btnNavFinish", "Enabled", Any(true));
635  mrOptimizerDialog.setControlProperty("btnNavCancel", "Enabled", Any(true));
636 
637  OUString aFileName;
639  SfxErrorContext aEc(ERRCTX_SFX_SAVEASDOC, aFileName);
640  ErrorHandler::HandleError(errorCode);
641  break;
642  }
643 
644  mrOptimizerDialog.endExecute( bSuccessfullyExecuted );
645  }
646  else
647  {
648  mrOptimizerDialog.setControlProperty( "btnNavBack", "Enabled", Any( true ) );
649  mrOptimizerDialog.setControlProperty( "btnNavNext", "Enabled", Any( false ) );
650  mrOptimizerDialog.setControlProperty( "btnNavFinish", "Enabled", Any( true ) );
651  mrOptimizerDialog.setControlProperty( "btnNavCancel", "Enabled", Any( true ) );
653  }
654  }
655  break;
656  case TK_btnNavCancel : mrOptimizerDialog.endExecute( false ); break;
657  case TK_Button0Pg0 : // delete configuration
658  {
659  OUString aSelectedItem( mrOptimizerDialog.GetSelectedString( "ListBox0Pg0" ) );
660  if ( !aSelectedItem.isEmpty() )
661  {
662  std::vector< OptimizerSettings >::iterator aIter( mrOptimizerDialog.GetOptimizerSettingsByName( aSelectedItem ) );
663  std::vector< OptimizerSettings >& rList( mrOptimizerDialog.GetOptimizerSettings() );
664  if ( aIter != rList.end() )
665  {
666  rList.erase( aIter );
668  }
669  }
670  }
671  break;
672  default: break;
673  }
674 }
675 void ActionListener::disposing( const css::lang::EventObject& /* Source */ )
676 {
677 }
678 
679 
680 void ActionListenerListBox0Pg0::actionPerformed( const ActionEvent& rEvent )
681 {
682  if ( !rEvent.ActionCommand.isEmpty() )
683  {
684  std::vector< OptimizerSettings >::iterator aIter( mrOptimizerDialog.GetOptimizerSettingsByName( rEvent.ActionCommand ) );
685  std::vector< OptimizerSettings >& rList( mrOptimizerDialog.GetOptimizerSettings() );
686  if ( aIter != rList.end() )
687  rList[ 0 ] = *aIter;
688  }
690 }
691 void ActionListenerListBox0Pg0::disposing( const css::lang::EventObject& /* Source */ )
692 {
693 }
694 
695 
696 void TextListenerFormattedField0Pg1::textChanged( const TextEvent& /* rEvent */ )
697 {
698  double fDouble = 0;
699  Any aAny = mrOptimizerDialog.getControlProperty( "FormattedField0Pg1", "EffectiveValue" );
700  if ( aAny >>= fDouble )
701  mrOptimizerDialog.SetConfigProperty( TK_JPEGQuality, Any( static_cast<sal_Int32>(fDouble) ) );
702 }
703 void TextListenerFormattedField0Pg1::disposing( const css::lang::EventObject& /* Source */ )
704 {
705 }
706 
707 namespace
708 {
709 
710 bool lcl_mapResolution(OUString& rResolution, const OUString& rImageResolution)
711 {
712  if (rImageResolution.getToken(1, ';')!=rResolution)
713  return false;
714  rResolution = rImageResolution.getToken(0, ';');
715  return true;
716 }
717 
718 }
719 
720 void TextListenerComboBox0Pg1::textChanged( const TextEvent& /* rEvent */ )
721 {
722  OUString aString;
723  Any aAny = mrOptimizerDialog.getControlProperty( "ComboBox0Pg1", "Text" );
724  if ( !(aAny >>= aString) )
725  return;
726 
727  for (int nIR{ STR_IMAGE_RESOLUTION_0 }; nIR <= STR_IMAGE_RESOLUTION_3; ++nIR)
728  {
729  if (lcl_mapResolution(aString, mrOptimizerDialog.getString(static_cast<PPPOptimizerTokenEnum>(nIR))))
730  break;
731  }
732 
734 }
735 void TextListenerComboBox0Pg1::disposing( const css::lang::EventObject& /* Source */ )
736 {
737 }
738 
739 
740 void SpinListenerFormattedField0Pg1::up( const SpinEvent& /* rEvent */ )
741 {
742  double fDouble;
743  Any aAny = mrOptimizerDialog.getControlProperty( "FormattedField0Pg1", "EffectiveValue" );
744  if ( aAny >>= fDouble )
745  {
746  fDouble += 9;
747  if ( fDouble > 100 )
748  fDouble = 100;
749  mrOptimizerDialog.setControlProperty( "FormattedField0Pg1", "EffectiveValue", Any( fDouble ) );
750  mrOptimizerDialog.SetConfigProperty( TK_JPEGQuality, Any( static_cast<sal_Int32>(fDouble) ) );
751  }
752 }
753 void SpinListenerFormattedField0Pg1::down( const SpinEvent& /* rEvent */ )
754 {
755  double fDouble;
756  Any aAny = mrOptimizerDialog.getControlProperty( "FormattedField0Pg1", "EffectiveValue" );
757  if ( aAny >>= fDouble )
758  {
759  fDouble -= 9;
760  if ( fDouble < 0 )
761  fDouble = 0;
762  mrOptimizerDialog.setControlProperty( "FormattedField0Pg1", "EffectiveValue", Any( fDouble ) );
763  mrOptimizerDialog.SetConfigProperty( TK_JPEGQuality, Any( static_cast<sal_Int32>(fDouble) ) );
764  }
765 }
766 void SpinListenerFormattedField0Pg1::first( const SpinEvent& /* rEvent */ )
767 {
768  mrOptimizerDialog.setControlProperty( "FormattedField0Pg1", "EffectiveValue", Any( static_cast< double >( 0 ) ) );
770 }
771 void SpinListenerFormattedField0Pg1::last( const SpinEvent& /* rEvent */ )
772 {
773  mrOptimizerDialog.setControlProperty( "FormattedField0Pg1", "EffectiveValue", Any( static_cast< double >( 100 ) ) );
775 }
776 void SpinListenerFormattedField0Pg1::disposing( const css::lang::EventObject& /* Source */ )
777 {
778 }
779 
780 /* 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:303
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()
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
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
virtual void SAL_CALL textChanged(const css::awt::TextEvent &Event) override