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