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 { 281 Sequence< PropertyValue > aArguments; 282 if ( ( aState.State >>= aArguments ) && aArguments.getLength() ) 283 UpdateStatus( aArguments ); 284 } 285 286 void SAL_CALL OptimizerDialog::disposing( 287 const ::com::sun::star::lang::EventObject& /*aSource*/ ) 288 {} 289 290 // ----------------------------------------------------------------------------- 291 292 sal_Bool OptimizerDialog::execute() 293 { 294 Reference< XItemEventBroadcaster > maRoadmapBroadcaster( mxRoadmapControl, UNO_QUERY_THROW ); 295 maRoadmapBroadcaster->addItemListener( this ); 296 UnoDialog::execute(); 297 UpdateConfiguration(); // taking actual control settings for the configuration 298 maRoadmapBroadcaster->removeItemListener( this ); 299 return mbStatus; 300 } 301 302 // ----------------------------------------------------------------------------- 303 304 void OptimizerDialog::SwitchPage( sal_Int16 nNewStep ) 305 { 306 if ( ( nNewStep != mnCurrentStep ) && ( ( nNewStep <= MAX_STEP ) || ( nNewStep >= 0 ) ) ) 307 { 308 sal_Int16 nOldStep = mnCurrentStep; 309 if ( nNewStep == 0 ) 310 disableControl( TKGet( TK_btnNavBack ) ); 311 else if ( nOldStep == 0 ) 312 enableControl( TKGet( TK_btnNavBack ) ); 313 314 if ( nNewStep == MAX_STEP ) 315 disableControl( TKGet( TK_btnNavNext ) ); 316 else if ( nOldStep == MAX_STEP ) 317 enableControl( TKGet( TK_btnNavNext ) ); 318 319 setControlProperty( TKGet( TK_rdmNavi ), TKGet( TK_CurrentItemID ), Any( nNewStep ) ); 320 321 DeactivatePage( nOldStep ); 322 UpdateControlStates( nNewStep ); 323 324 ActivatePage( nNewStep ); 325 mnCurrentStep = nNewStep; 326 } 327 } 328 329 void OptimizerDialog::UpdateControlStates( sal_Int16 nPage ) 330 { 331 switch( nPage ) 332 { 333 case 0 : UpdateControlStatesPage0(); break; 334 case 1 : UpdateControlStatesPage1(); break; 335 case 2 : UpdateControlStatesPage2(); break; 336 case 3 : UpdateControlStatesPage3(); break; 337 case 4 : UpdateControlStatesPage4(); break; 338 default: 339 { 340 UpdateControlStatesPage0(); 341 UpdateControlStatesPage1(); 342 UpdateControlStatesPage2(); 343 UpdateControlStatesPage3(); 344 UpdateControlStatesPage4(); 345 } 346 } 347 } 348 349 // ----------------------------------------------------------------------------- 350 351 rtl::OUString OptimizerDialog::GetSelectedString( const PPPOptimizerTokenEnum eToken ) 352 { 353 OUString aSelectedItem; 354 Sequence< sal_Int16 > sSelectedItems; 355 Sequence< OUString > sItemList; 356 357 if ( ( getControlProperty( TKGet( eToken ), TKGet( TK_SelectedItems ) ) >>= sSelectedItems ) && 358 ( getControlProperty( TKGet( eToken ), TKGet( TK_StringItemList ) ) >>= sItemList ) ) 359 { 360 if ( sSelectedItems.getLength() == 1 ) 361 { 362 sal_Int16 nSelectedItem = sSelectedItems[ 0 ]; 363 if ( nSelectedItem < sItemList.getLength() ) 364 aSelectedItem = sItemList[ nSelectedItem ]; 365 } 366 } 367 return aSelectedItem; 368 } 369 370 // ----------------------------------------------------------------------------- 371 372 void OptimizerDialog::UpdateStatus( const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& rStatus ) 373 { 374 if ( mxReschedule.is() ) 375 { 376 maStats.InitializeStatusValues( rStatus ); 377 const Any* pVal( maStats.GetStatusValue( TK_Status ) ); 378 if ( pVal ) 379 { 380 rtl::OUString sStatus; 381 if ( *pVal >>= sStatus ) 382 { 383 setControlProperty( TKGet( TK_FixedText1Pg4 ), TKGet( TK_Enabled ), Any( sal_True ) ); 384 setControlProperty( TKGet( TK_FixedText1Pg4 ), TKGet( TK_Label ), Any( sStatus ) ); 385 } 386 } 387 pVal = maStats.GetStatusValue( TK_Progress ); 388 if ( pVal ) 389 { 390 sal_Int32 nProgress = 0; 391 if ( *pVal >>= nProgress ) 392 setControlProperty( TKGet( TK_Progress ), TKGet( TK_ProgressValue ), Any( nProgress ) ); 393 } 394 pVal = maStats.GetStatusValue( TK_OpenNewDocument ); 395 if ( pVal ) 396 SetConfigProperty( TK_OpenNewDocument, *pVal ); 397 398 mxReschedule->reschedule(); 399 } 400 } 401 402 // ----------------------------------------------------------------------------- 403 404 void OptimizerDialog::itemStateChanged( const ItemEvent& Event ) 405 { 406 try 407 { 408 sal_Int16 nState; 409 OUString aControlName; 410 Reference< XControl > xControl; 411 Any aSource( Event.Source ); 412 if ( aSource >>= xControl ) 413 { 414 Reference< XPropertySet > xPropertySet( xControl->getModel(), UNO_QUERY_THROW ); 415 xPropertySet->getPropertyValue( TKGet( TK_Name ) ) >>= aControlName; 416 PPPOptimizerTokenEnum eControl( TKGet( aControlName ) ); 417 switch( eControl ) 418 { 419 case TK_rdmNavi : 420 { 421 SwitchPage( static_cast< sal_Int16 >( Event.ItemId ) ); 422 } 423 break; 424 case TK_CheckBox1Pg1 : 425 { 426 if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState ) 427 SetConfigProperty( TK_RemoveCropArea, Any( nState != 0 ) ); 428 } 429 break; 430 case TK_CheckBox2Pg1 : 431 { 432 if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState ) 433 SetConfigProperty( TK_EmbedLinkedGraphics, Any( nState != 0 ) ); 434 } 435 break; 436 case TK_CheckBox0Pg2 : 437 { 438 if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState ) 439 { 440 SetConfigProperty( TK_OLEOptimization, Any( nState != 0 ) ); 441 setControlProperty( TKGet( TK_RadioButton0Pg2 ), TKGet( TK_Enabled ), Any( nState != 0 ) ); 442 setControlProperty( TKGet( TK_RadioButton1Pg2 ), TKGet( TK_Enabled ), Any( nState != 0 ) ); 443 } 444 } 445 break; 446 case TK_RadioButton0Pg1 : 447 { 448 sal_Int16 nInt16 = 0; 449 if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nInt16 ) 450 { 451 nInt16 ^= 1; 452 SetConfigProperty( TK_JPEGCompression, Any( nInt16 != 0 ) ); 453 setControlProperty( TKGet( TK_FixedText1Pg1 ), TKGet( TK_Enabled ), Any( nInt16 != 0 ) ); 454 setControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_Enabled ), Any( nInt16 != 0 ) ); 455 } 456 } 457 break; 458 case TK_RadioButton1Pg1 : 459 { 460 if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState ) 461 { 462 SetConfigProperty( TK_JPEGCompression, Any( nState != 0 ) ); 463 setControlProperty( TKGet( TK_FixedText1Pg1 ), TKGet( TK_Enabled ), Any( nState != 0 ) ); 464 setControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_Enabled ), Any( nState != 0 ) ); 465 } 466 } 467 break; 468 case TK_RadioButton0Pg2 : 469 { 470 sal_Int16 nInt16; 471 if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nInt16 ) 472 { 473 nInt16 ^= 1; 474 SetConfigProperty( TK_OLEOptimizationType, Any( nInt16 ) ); 475 } 476 } 477 break; 478 case TK_RadioButton1Pg2 : 479 { 480 if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState ) 481 SetConfigProperty( TK_OLEOptimizationType, Any( nState ) ); 482 } 483 break; 484 case TK_CheckBox0Pg3 : 485 { 486 if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState ) 487 SetConfigProperty( TK_DeleteUnusedMasterPages, Any( nState != 0 ) ); 488 } 489 break; 490 case TK_CheckBox1Pg3 : 491 { 492 if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState ) 493 SetConfigProperty( TK_DeleteNotesPages, Any( nState != 0 ) ); 494 } 495 break; 496 case TK_CheckBox2Pg3 : 497 { 498 if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState ) 499 SetConfigProperty( TK_DeleteHiddenSlides, Any( nState != 0 ) ); 500 } 501 break; 502 case TK_CheckBox3Pg3 : 503 { 504 if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState ) 505 setControlProperty( TKGet( TK_ListBox0Pg3 ), TKGet( TK_Enabled ), Any( nState != 0 ) ); 506 } 507 break; 508 case TK_CheckBox1Pg4 : 509 { 510 if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState ) 511 setControlProperty( TKGet( TK_ComboBox0Pg4 ), TKGet( TK_Enabled ), Any( nState != 0 ) ); 512 } 513 break; 514 case TK_RadioButton0Pg4 : 515 case TK_RadioButton1Pg4 : 516 { 517 if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState ) 518 SetConfigProperty( TK_SaveAs, Any( eControl == TK_RadioButton1Pg4 ? nState != 0 : nState == 0 ) ); 519 } 520 break; 521 default: 522 break; 523 } 524 } 525 } 526 catch ( Exception& ) 527 { 528 } 529 } 530 531 // ----------------------------------------------------------------------------- 532 533 void OptimizerDialog::actionPerformed( const ActionEvent& rEvent ) 534 { 535 switch( TKGet( rEvent.ActionCommand ) ) 536 { 537 case TK_btnNavBack : SwitchPage( mnCurrentStep - 1 ); break; 538 case TK_btnNavNext : SwitchPage( mnCurrentStep + 1 ); break; 539 case TK_btnNavFinish : 540 { 541 UpdateConfiguration(); 542 543 SwitchPage( ITEM_ID_SUMMARY ); 544 DisablePage( ITEM_ID_SUMMARY ); 545 setControlProperty( TKGet( TK_btnNavHelp ), TKGet( TK_Enabled ), Any( sal_False ) ); 546 setControlProperty( TKGet( TK_btnNavBack ), TKGet( TK_Enabled ), Any( sal_False ) ); 547 setControlProperty( TKGet( TK_btnNavNext ), TKGet( TK_Enabled ), Any( sal_False ) ); 548 setControlProperty( TKGet( TK_btnNavFinish ), TKGet( TK_Enabled ), Any( sal_False ) ); 549 setControlProperty( TKGet( TK_btnNavCancel ), TKGet( TK_Enabled ), Any( sal_False ) ); 550 setControlProperty( TKGet( TK_FixedText0Pg4 ), TKGet( TK_Enabled ), Any( sal_True ) ); 551 552 // check if we have to open the FileDialog 553 sal_Bool bSuccessfullyExecuted = sal_True; 554 sal_Int16 nInt16 = 0; 555 getControlProperty( TKGet( TK_RadioButton1Pg4 ), TKGet( TK_State ) ) >>= nInt16; 556 if ( nInt16 ) 557 { 558 rtl::OUString aSaveAsURL; 559 FileOpenDialog aFileOpenDialog( mxContext, Reference< XWindow >( mxParent, UNO_QUERY ) ); 560 561 // generating default file name 562 Reference< XStorable > xStorable( mxModel, UNO_QUERY ); 563 if ( xStorable.is() && xStorable->hasLocation() ) 564 { 565 rtl::OUString aLocation( xStorable->getLocation() ); 566 if ( aLocation.getLength() ) 567 { 568 sal_Int32 nIndex = aLocation.lastIndexOf( '/', aLocation.getLength() - 1 ); 569 if ( nIndex >= 0 ) 570 { 571 if ( nIndex < aLocation.getLength() - 1 ) 572 aLocation = aLocation.copy( nIndex + 1 ); 573 574 // remove extension 575 nIndex = aLocation.lastIndexOf( '.', aLocation.getLength() - 1 ); 576 if ( nIndex >= 0 ) 577 aLocation = aLocation.copy( 0, nIndex ); 578 579 // adding .mini 580 aLocation = aLocation.concat( OUString::createFromAscii( ".mini" ) ); 581 aFileOpenDialog.setDefaultName( aLocation ); 582 } 583 } 584 } 585 sal_Bool bDialogExecuted = aFileOpenDialog.execute() == dialogs::ExecutableDialogResults::OK; 586 if ( bDialogExecuted ) 587 { 588 aSaveAsURL = aFileOpenDialog.getURL(); 589 SetConfigProperty( TK_SaveAsURL, Any( aSaveAsURL ) ); 590 SetConfigProperty( TK_FilterName, Any( aFileOpenDialog.getFilterName() ) ); 591 } 592 if ( !aSaveAsURL.getLength() ) 593 { 594 // something goes wrong... 595 bSuccessfullyExecuted = sal_False; 596 } 597 598 // waiting for 500ms 599 if ( mxReschedule.is() ) 600 { 601 mxReschedule->reschedule(); 602 for ( sal_uInt32 i = osl_getGlobalTimer(); ( i + 500 ) > ( osl_getGlobalTimer() ); ) 603 mxReschedule->reschedule(); 604 } 605 } 606 if ( bSuccessfullyExecuted ) 607 { // now check if we have to store a session template 608 nInt16 = 0; 609 OUString aSettingsName; 610 getControlProperty( TKGet( TK_CheckBox1Pg4 ), TKGet( TK_State ) ) >>= nInt16; 611 getControlProperty( TKGet( TK_ComboBox0Pg4 ), TKGet( TK_Text ) ) >>= aSettingsName; 612 if ( nInt16 && aSettingsName.getLength() ) 613 { 614 std::vector< OptimizerSettings >::iterator aIter( GetOptimizerSettingsByName( aSettingsName ) ); 615 std::vector< OptimizerSettings >& rSettings( GetOptimizerSettings() ); 616 OptimizerSettings aNewSettings( rSettings[ 0 ] ); 617 aNewSettings.maName = aSettingsName; 618 if ( aIter == rSettings.end() ) 619 rSettings.push_back( aNewSettings ); 620 else 621 *aIter = aNewSettings; 622 } 623 } 624 if ( bSuccessfullyExecuted ) 625 { 626 Sequence< Any > aArgs( 1 ); 627 aArgs[ 0 ] <<= mxFrame; 628 629 Reference < XDispatch > xDispatch( 630 mxContext->getServiceManager()->createInstanceWithArgumentsAndContext( 631 OUString( RTL_CONSTASCII_USTRINGPARAM( 632 "com.sun.star.presentation.PresentationOptimizer" ) ), 633 aArgs, mxContext ), 634 UNO_QUERY ); 635 636 URL aURL; 637 aURL.Protocol = OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.com.sun.star.presentation.PresentationOptimizer:" ) ); 638 aURL.Path = OUString( RTL_CONSTASCII_USTRINGPARAM( "optimize" ) ); 639 640 Sequence< PropertyValue > lArguments( 3 ); 641 lArguments[ 0 ].Name = TKGet( TK_Settings ); 642 lArguments[ 0 ].Value <<= GetConfigurationSequence(); 643 lArguments[ 1 ].Name = TKGet( TK_StatusListener ); 644 lArguments[ 1 ].Value <<= Reference< XStatusListener >( this ); 645 lArguments[ 2 ].Name = TKGet( TK_ParentWindow ); 646 lArguments[ 2 ].Value <<= mxDialogWindowPeer; 647 648 if( xDispatch.is() ) 649 xDispatch->dispatch( aURL, lArguments ); 650 651 endExecute( bSuccessfullyExecuted ); 652 } 653 else 654 { 655 setControlProperty( TKGet( TK_btnNavHelp ), TKGet( TK_Enabled ), Any( sal_True ) ); 656 setControlProperty( TKGet( TK_btnNavBack ), TKGet( TK_Enabled ), Any( sal_True ) ); 657 setControlProperty( TKGet( TK_btnNavNext ), TKGet( TK_Enabled ), Any( sal_False ) ); 658 setControlProperty( TKGet( TK_btnNavFinish ), TKGet( TK_Enabled ), Any( sal_True ) ); 659 setControlProperty( TKGet( TK_btnNavCancel ), TKGet( TK_Enabled ), Any( sal_True ) ); 660 EnablePage( ITEM_ID_SUMMARY ); 661 } 662 } 663 break; 664 case TK_btnNavCancel : endExecute( sal_False ); break; 665 case TK_Button0Pg0 : // delete configuration 666 { 667 OUString aSelectedItem( GetSelectedString( TK_ListBox0Pg0 ) ); 668 if ( aSelectedItem.getLength() ) 669 { 670 std::vector< OptimizerSettings >::iterator aIter( GetOptimizerSettingsByName( aSelectedItem ) ); 671 std::vector< OptimizerSettings >& rList( GetOptimizerSettings() ); 672 if ( aIter != rList.end() ) 673 { 674 rList.erase( aIter ); 675 UpdateControlStates(); 676 } 677 } 678 } 679 break; 680 default: 681 { 682 Reference< XControl > xControl( rEvent.Source, UNO_QUERY ); 683 if ( xControl.is() ) 684 { 685 OUString aName; 686 Reference< XPropertySet > xProps( xControl->getModel(), UNO_QUERY ); 687 xProps->getPropertyValue( TKGet( TK_Name ) ) >>= aName; 688 if ( TKGet( aName ) == TK_ListBox0Pg0 ) 689 { 690 if ( rEvent.ActionCommand.getLength() ) 691 { 692 std::vector< OptimizerSettings >::iterator aIter( GetOptimizerSettingsByName( rEvent.ActionCommand ) ); 693 std::vector< OptimizerSettings >& rList( GetOptimizerSettings() ); 694 if ( aIter != rList.end() ) 695 rList[ 0 ] = *aIter; 696 } 697 UpdateControlStates(); 698 } 699 } 700 } 701 break; 702 } 703 } 704 705 // ----------------------------------------------------------------------------- 706 707 void OptimizerDialog::textChanged( const TextEvent& rEvent ) 708 { 709 Reference< XSpinField > xFormattedField( rEvent.Source, UNO_QUERY ); 710 if ( xFormattedField.is() ) 711 { 712 double fDouble = 0; 713 Any aAny = getControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_EffectiveValue ) ); 714 if ( aAny >>= fDouble ) 715 SetConfigProperty( TK_JPEGQuality, Any( (sal_Int32)fDouble ) ); 716 return; 717 } 718 719 Reference< XComboBox > xComboBox( rEvent.Source, UNO_QUERY ); 720 if ( xComboBox.is() ) 721 { 722 rtl::OUString aString; 723 Any aAny = getControlProperty( TKGet( TK_ComboBox0Pg1 ), TKGet( TK_Text ) ); 724 if ( aAny >>= aString ) 725 { 726 sal_Int32 nI0, nI1, nI2, nI3, nI4; 727 nI0 = nI1 = nI2 = nI3 = nI4 = 0; 728 729 if ( getString( STR_IMAGE_RESOLUTION_0 ).getToken( 1, ';', nI0 ) == aString ) 730 aString = getString( STR_IMAGE_RESOLUTION_0 ).getToken( 0, ';', nI4 ); 731 else if ( getString( STR_IMAGE_RESOLUTION_1 ).getToken( 1, ';', nI1 ) == aString ) 732 aString = getString( STR_IMAGE_RESOLUTION_1 ).getToken( 0, ';', nI4 ); 733 else if ( getString( STR_IMAGE_RESOLUTION_2 ).getToken( 1, ';', nI2 ) == aString ) 734 aString = getString( STR_IMAGE_RESOLUTION_2 ).getToken( 0, ';', nI4 ); 735 else if ( getString( STR_IMAGE_RESOLUTION_3 ).getToken( 1, ';', nI3 ) == aString ) 736 aString = getString( STR_IMAGE_RESOLUTION_3 ).getToken( 0, ';', nI4 ); 737 738 SetConfigProperty( TK_ImageResolution, Any( aString.toInt32() ) ); 739 } 740 } 741 } 742 743 // ----------------------------------------------------------------------------- 744 745 void OptimizerDialog::up( const SpinEvent& /* rEvent */ ) 746 { 747 double fDouble; 748 Any aAny = getControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_EffectiveValue ) ); 749 if ( aAny >>= fDouble ) 750 { 751 fDouble += 9; 752 if ( fDouble > 100 ) 753 fDouble = 100; 754 setControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_EffectiveValue ), Any( fDouble ) ); 755 SetConfigProperty( TK_JPEGQuality, Any( (sal_Int32)fDouble ) ); 756 } 757 } 758 759 void OptimizerDialog::down( const SpinEvent& /* rEvent */ ) 760 { 761 double fDouble; 762 Any aAny = getControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_EffectiveValue ) ); 763 if ( aAny >>= fDouble ) 764 { 765 fDouble -= 9; 766 if ( fDouble < 0 ) 767 fDouble = 0; 768 setControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_EffectiveValue ), Any( fDouble ) ); 769 SetConfigProperty( TK_JPEGQuality, Any( (sal_Int32)fDouble ) ); 770 } 771 } 772 773 void OptimizerDialog::first( const SpinEvent& /* rEvent */ ) 774 { 775 setControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_EffectiveValue ), Any( static_cast< double >( 0 ) ) ); 776 SetConfigProperty( TK_JPEGQuality, Any( (sal_Int32)0 ) ); 777 } 778 779 void OptimizerDialog::last( const SpinEvent& /* rEvent */ ) 780 { 781 setControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_EffectiveValue ), Any( static_cast< double >( 100 ) ) ); 782 SetConfigProperty( TK_JPEGQuality, Any( (sal_Int32)100 ) ); 783 } 784 785 /* vim: set noet sw=4 ts=4: */ 786