1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sfx2.hxx" 30 #include <svl/stritem.hxx> 31 #include <svl/eitem.hxx> 32 #include <svl/whiter.hxx> 33 #include <vcl/msgbox.hxx> 34 #include <vcl/toolbox.hxx> 35 #include <svl/intitem.hxx> 36 #include <svtools/sfxecode.hxx> 37 #include <svtools/ehdl.hxx> 38 #include <com/sun/star/frame/XLayoutManager.hpp> 39 #include <com/sun/star/frame/XModuleManager.hpp> 40 #include <com/sun/star/beans/XPropertySet.hpp> 41 #include <com/sun/star/embed/EmbedStates.hpp> 42 #include <com/sun/star/embed/EmbedMisc.hpp> 43 #include <com/sun/star/system/XSystemShellExecute.hpp> 44 #include <com/sun/star/system/SystemShellExecuteFlags.hpp> 45 #include <com/sun/star/container/XContainerQuery.hpp> 46 #include <com/sun/star/frame/XStorable.hpp> 47 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp> 48 #include <cppuhelper/implbase1.hxx> 49 50 #include <osl/file.hxx> 51 #include <vos/mutex.hxx> 52 #include <tools/urlobj.hxx> 53 #include <unotools/tempfile.hxx> 54 #include <unotools/pathoptions.hxx> 55 #include <svtools/miscopt.hxx> 56 #include <svtools/soerr.hxx> 57 #include <unotools/internaloptions.hxx> 58 59 #include <unotools/javaoptions.hxx> 60 #include <basic/basmgr.hxx> 61 #include <basic/sbuno.hxx> 62 #include <framework/actiontriggerhelper.hxx> 63 #include <comphelper/processfactory.hxx> 64 #include <comphelper/sequenceashashmap.hxx> 65 #include <toolkit/unohlp.hxx> 66 67 68 #include <sfx2/app.hxx> 69 #include "view.hrc" 70 #include <sfx2/viewsh.hxx> 71 #include "viewimp.hxx" 72 #include "sfx2/sfxresid.hxx" 73 #include <sfx2/request.hxx> 74 #include <sfx2/templdlg.hxx> 75 #include <sfx2/printer.hxx> 76 #include <sfx2/docfile.hxx> 77 #include <sfx2/dispatch.hxx> 78 #include "arrdecl.hxx" 79 #include <sfx2/docfac.hxx> 80 #include "view.hrc" 81 #include "sfxlocal.hrc" 82 #include <sfx2/sfxbasecontroller.hxx> 83 #include "sfx2/mailmodelapi.hxx" 84 #include <sfx2/viewfrm.hxx> 85 #include <sfx2/event.hxx> 86 #include <sfx2/fcontnr.hxx> 87 #include <sfx2/ipclient.hxx> 88 #include "workwin.hxx" 89 #include <sfx2/objface.hxx> 90 #include <sfx2/docfilt.hxx> 91 92 // #110897# 93 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX 94 #include <comphelper/processfactory.hxx> 95 #endif 96 97 using namespace ::com::sun::star; 98 using namespace ::com::sun::star::uno; 99 using namespace ::com::sun::star::frame; 100 using namespace ::com::sun::star::beans; 101 using namespace ::com::sun::star::util; 102 using namespace ::com::sun::star::system; 103 using namespace ::cppu; 104 namespace css = ::com::sun::star; 105 106 //========================================================================= 107 DBG_NAME(SfxViewShell) 108 109 #define SfxViewShell 110 #include "sfxslots.hxx" 111 112 //========================================================================= 113 114 class SfxClipboardChangeListener : public ::cppu::WeakImplHelper1< 115 datatransfer::clipboard::XClipboardListener > 116 { 117 public: 118 SfxClipboardChangeListener( SfxViewShell* pView, const uno::Reference< datatransfer::clipboard::XClipboardNotifier >& xClpbrdNtfr ); 119 virtual ~SfxClipboardChangeListener(); 120 121 // XEventListener 122 virtual void SAL_CALL disposing( const lang::EventObject& rEventObject ) 123 throw ( uno::RuntimeException ); 124 125 // XClipboardListener 126 virtual void SAL_CALL changedContents( const datatransfer::clipboard::ClipboardEvent& rEventObject ) 127 throw ( uno::RuntimeException ); 128 129 void DisconnectViewShell() { m_pViewShell = NULL; } 130 void ChangedContents(); 131 132 enum AsyncExecuteCmd 133 { 134 ASYNCEXECUTE_CMD_DISPOSING, 135 ASYNCEXECUTE_CMD_CHANGEDCONTENTS 136 }; 137 138 struct AsyncExecuteInfo 139 { 140 AsyncExecuteInfo( AsyncExecuteCmd eCmd, uno::Reference< datatransfer::clipboard::XClipboardListener > xThis, SfxClipboardChangeListener* pListener ) : 141 m_eCmd( eCmd ), m_xThis( xThis ), m_pListener( pListener ) {} 142 143 AsyncExecuteCmd m_eCmd; 144 uno::Reference< datatransfer::clipboard::XClipboardListener > m_xThis; 145 SfxClipboardChangeListener* m_pListener; 146 }; 147 148 private: 149 SfxViewShell* m_pViewShell; 150 uno::Reference< datatransfer::clipboard::XClipboardNotifier > m_xClpbrdNtfr; 151 uno::Reference< lang::XComponent > m_xCtrl; 152 153 DECL_STATIC_LINK( SfxClipboardChangeListener, AsyncExecuteHdl_Impl, AsyncExecuteInfo* ); 154 }; 155 156 SfxClipboardChangeListener::SfxClipboardChangeListener( SfxViewShell* pView, const uno::Reference< datatransfer::clipboard::XClipboardNotifier >& xClpbrdNtfr ) 157 : m_pViewShell( 0 ), m_xClpbrdNtfr( xClpbrdNtfr ) 158 { 159 m_xCtrl = uno::Reference < lang::XComponent >( pView->GetController(), uno::UNO_QUERY ); 160 if ( m_xCtrl.is() ) 161 { 162 m_xCtrl->addEventListener( uno::Reference < lang::XEventListener > ( static_cast < lang::XEventListener* >( this ) ) ); 163 m_pViewShell = pView; 164 } 165 if ( m_xClpbrdNtfr.is() ) 166 { 167 m_xClpbrdNtfr->addClipboardListener( uno::Reference< datatransfer::clipboard::XClipboardListener >( 168 static_cast< datatransfer::clipboard::XClipboardListener* >( this ))); 169 } 170 } 171 172 SfxClipboardChangeListener::~SfxClipboardChangeListener() 173 { 174 } 175 176 void SfxClipboardChangeListener::ChangedContents() 177 { 178 const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 179 if( m_pViewShell ) 180 { 181 SfxBindings& rBind = m_pViewShell->GetViewFrame()->GetBindings(); 182 rBind.Invalidate( SID_PASTE ); 183 rBind.Invalidate( SID_PASTE_SPECIAL ); 184 rBind.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS ); 185 } 186 } 187 188 IMPL_STATIC_LINK_NOINSTANCE( SfxClipboardChangeListener, AsyncExecuteHdl_Impl, AsyncExecuteInfo*, pAsyncExecuteInfo ) 189 { 190 if ( pAsyncExecuteInfo ) 191 { 192 uno::Reference< datatransfer::clipboard::XClipboardListener > xThis( pAsyncExecuteInfo->m_xThis ); 193 if ( pAsyncExecuteInfo->m_pListener ) 194 { 195 if ( pAsyncExecuteInfo->m_eCmd == ASYNCEXECUTE_CMD_DISPOSING ) 196 pAsyncExecuteInfo->m_pListener->DisconnectViewShell(); 197 else if ( pAsyncExecuteInfo->m_eCmd == ASYNCEXECUTE_CMD_CHANGEDCONTENTS ) 198 pAsyncExecuteInfo->m_pListener->ChangedContents(); 199 } 200 } 201 delete pAsyncExecuteInfo; 202 203 return 0; 204 } 205 206 void SAL_CALL SfxClipboardChangeListener::disposing( const lang::EventObject& /*rEventObject*/ ) 207 throw ( uno::RuntimeException ) 208 { 209 // Either clipboard or ViewShell is going to be destroyed -> no interest in listening anymore 210 uno::Reference< lang::XComponent > xCtrl( m_xCtrl ); 211 uno::Reference< datatransfer::clipboard::XClipboardNotifier > xNotify( m_xClpbrdNtfr ); 212 213 uno::Reference< datatransfer::clipboard::XClipboardListener > xThis( static_cast< datatransfer::clipboard::XClipboardListener* >( this )); 214 if ( xCtrl.is() ) 215 xCtrl->removeEventListener( uno::Reference < lang::XEventListener > ( static_cast < lang::XEventListener* >( this ))); 216 if ( xNotify.is() ) 217 xNotify->removeClipboardListener( xThis ); 218 219 // Make asynchronous call to avoid locking SolarMutex which is the 220 // root for many deadlocks, especially in conjuction with the "Windows" 221 // based single thread apartment clipboard code! 222 AsyncExecuteInfo* pInfo = new AsyncExecuteInfo( ASYNCEXECUTE_CMD_DISPOSING, xThis, this ); 223 Application::PostUserEvent( STATIC_LINK( 0, SfxClipboardChangeListener, AsyncExecuteHdl_Impl ), pInfo ); 224 } 225 226 void SAL_CALL SfxClipboardChangeListener::changedContents( const datatransfer::clipboard::ClipboardEvent& ) 227 throw ( RuntimeException ) 228 { 229 // Make asynchronous call to avoid locking SolarMutex which is the 230 // root for many deadlocks, especially in conjuction with the "Windows" 231 // based single thread apartment clipboard code! 232 uno::Reference< datatransfer::clipboard::XClipboardListener > xThis( static_cast< datatransfer::clipboard::XClipboardListener* >( this )); 233 AsyncExecuteInfo* pInfo = new AsyncExecuteInfo( ASYNCEXECUTE_CMD_CHANGEDCONTENTS, xThis, this ); 234 Application::PostUserEvent( STATIC_LINK( 0, SfxClipboardChangeListener, AsyncExecuteHdl_Impl ), pInfo ); 235 } 236 237 //========================================================================= 238 239 static ::rtl::OUString RetrieveLabelFromCommand( 240 const ::rtl::OUString& rCommandURL, 241 const css::uno::Reference< css::frame::XFrame >& rFrame ) 242 { 243 static css::uno::WeakReference< frame::XModuleManager > s_xModuleManager; 244 static css::uno::WeakReference< container::XNameAccess > s_xNameAccess; 245 246 ::rtl::OUString aLabel; 247 css::uno::Reference< css::frame::XModuleManager > xModuleManager( s_xModuleManager ); 248 css::uno::Reference< css::container::XNameAccess > xNameAccess( s_xNameAccess ); 249 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR( 250 ::comphelper::getProcessServiceFactory(), css::uno::UNO_QUERY_THROW); 251 252 try 253 { 254 if ( !xModuleManager.is() ) 255 { 256 xModuleManager = css::uno::Reference< css::frame::XModuleManager >( 257 xSMGR->createInstance( 258 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ModuleManager" ))), 259 css::uno::UNO_QUERY_THROW ); 260 s_xModuleManager = xModuleManager; 261 } 262 263 ::rtl::OUString aModuleIdentifier = xModuleManager->identify( rFrame ); 264 265 if ( !xNameAccess.is() ) 266 { 267 xNameAccess = css::uno::Reference< css::container::XNameAccess >( 268 xSMGR->createInstance( 269 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.UICommandDescription" ))), 270 css::uno::UNO_QUERY_THROW ); 271 s_xNameAccess = xNameAccess; 272 } 273 274 css::uno::Any a = xNameAccess->getByName( aModuleIdentifier ); 275 css::uno::Reference< css::container::XNameAccess > xUICommands; 276 a >>= xUICommands; 277 278 rtl::OUString aStr; 279 css::uno::Sequence< css::beans::PropertyValue > aPropSeq; 280 281 a = xUICommands->getByName( rCommandURL ); 282 if ( a >>= aPropSeq ) 283 { 284 for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ ) 285 { 286 if ( aPropSeq[i].Name.equalsAscii( "Label" )) 287 { 288 aPropSeq[i].Value >>= aStr; 289 break; 290 } 291 } 292 aLabel = aStr; 293 } 294 } 295 catch ( css::uno::Exception& ) 296 { 297 } 298 299 return aLabel; 300 } 301 302 //========================================================================= 303 SfxViewShell_Impl::SfxViewShell_Impl(sal_uInt16 const nFlags) 304 : aInterceptorContainer( aMutex ) 305 , m_bControllerSet(false) 306 , m_nPrinterLocks(0) 307 , m_bCanPrint(SFX_VIEW_CAN_PRINT == (nFlags & SFX_VIEW_CAN_PRINT)) 308 , m_bHasPrintOptions( 309 SFX_VIEW_HAS_PRINTOPTIONS == (nFlags & SFX_VIEW_HAS_PRINTOPTIONS)) 310 , m_bPlugInsActive(true) 311 , m_bIsShowView(SFX_VIEW_NO_SHOW != (nFlags & SFX_VIEW_NO_SHOW)) 312 , m_bGotOwnership(false) 313 , m_bGotFrameOwnership(false) 314 , m_eScroll(SCROLLING_DEFAULT) 315 , m_nFamily(0xFFFF) // undefined, default set by TemplateDialog 316 , m_pController(0) 317 , m_pAccExec(0) 318 {} 319 320 //========================================================================= 321 SFX_IMPL_INTERFACE(SfxViewShell,SfxShell,SfxResId(0)) 322 { 323 SFX_CHILDWINDOW_REGISTRATION( SID_MAIL_CHILDWIN ); 324 } 325 326 TYPEINIT2(SfxViewShell,SfxShell,SfxListener); 327 328 //-------------------------------------------------------------------- 329 /** search for a filter name dependent on type and module 330 */ 331 332 static ::rtl::OUString impl_retrieveFilterNameFromTypeAndModule( 333 const css::uno::Reference< css::container::XContainerQuery >& rContainerQuery, 334 const ::rtl::OUString& rType, 335 const ::rtl::OUString& rModuleIdentifier, 336 const sal_Int32 nFlags ) 337 { 338 // Retrieve filter from type 339 css::uno::Sequence< css::beans::NamedValue > aQuery( 2 ); 340 aQuery[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Type" )); 341 aQuery[0].Value = css::uno::makeAny( rType ); 342 aQuery[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentService" )); 343 aQuery[1].Value = css::uno::makeAny( rModuleIdentifier ); 344 345 css::uno::Reference< css::container::XEnumeration > xEnumeration = 346 rContainerQuery->createSubSetEnumerationByProperties( aQuery ); 347 348 ::rtl::OUString aFoundFilterName; 349 while ( xEnumeration->hasMoreElements() ) 350 { 351 ::comphelper::SequenceAsHashMap aFilterPropsHM( xEnumeration->nextElement() ); 352 ::rtl::OUString aFilterName = aFilterPropsHM.getUnpackedValueOrDefault( 353 ::rtl::OUString::createFromAscii( "Name" ), 354 ::rtl::OUString() ); 355 356 sal_Int32 nFilterFlags = aFilterPropsHM.getUnpackedValueOrDefault( 357 ::rtl::OUString::createFromAscii( "Flags" ), 358 sal_Int32( 0 ) ); 359 360 if ( nFilterFlags & nFlags ) 361 { 362 aFoundFilterName = aFilterName; 363 break; 364 } 365 } 366 367 return aFoundFilterName; 368 } 369 370 //-------------------------------------------------------------------- 371 /** search for an internal typename, which map to the current app module 372 and map also to a "family" of file formats as e.g. PDF/MS Doc/OOo Doc. 373 */ 374 enum ETypeFamily 375 { 376 E_MS_DOC, 377 E_OOO_DOC 378 }; 379 380 ::rtl::OUString impl_searchFormatTypeForApp(const css::uno::Reference< css::frame::XFrame >& xFrame , 381 ETypeFamily eTypeFamily) 382 { 383 static ::rtl::OUString SERVICENAME_MODULEMANAGER = ::rtl::OUString::createFromAscii("com.sun.star.frame.ModuleManager"); 384 385 try 386 { 387 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR (::comphelper::getProcessServiceFactory() , css::uno::UNO_QUERY_THROW); 388 css::uno::Reference< css::frame::XModuleManager > xModuleManager(xSMGR->createInstance(SERVICENAME_MODULEMANAGER), css::uno::UNO_QUERY_THROW); 389 390 ::rtl::OUString sModule = xModuleManager->identify(xFrame); 391 ::rtl::OUString sType ; 392 393 switch(eTypeFamily) 394 { 395 case E_MS_DOC: 396 { 397 if (sModule.equalsAscii( "com.sun.star.text.TextDocument" )) 398 sType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "writer_MS_Word_97" )); 399 else 400 if (sModule.equalsAscii( "com.sun.star.sheet.SpreadsheetDocument" )) 401 sType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "calc_MS_Excel_97" )); 402 else 403 if (sModule.equalsAscii( "com.sun.star.drawing.DrawingDocument" )) 404 sType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "impress_MS_PowerPoint_97" )); 405 else 406 if (sModule.equalsAscii( "com.sun.star.presentation.PresentationDocument" )) 407 sType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "impress_MS_PowerPoint_97" )); 408 } 409 break; 410 411 case E_OOO_DOC: 412 { 413 if (sModule.equalsAscii( "com.sun.star.text.TextDocument" )) 414 sType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "writer8" )); 415 else 416 if (sModule.equalsAscii( "com.sun.star.sheet.SpreadsheetDocument" )) 417 sType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "calc8" )); 418 else 419 if (sModule.equalsAscii( "com.sun.star.drawing.DrawingDocument" )) 420 sType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "draw8" )); 421 else 422 if (sModule.equalsAscii( "com.sun.star.presentation.PresentationDocument" )) 423 sType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "impress8" )); 424 } 425 break; 426 } 427 428 return sType; 429 } 430 catch(const css::uno::RuntimeException& exRun) 431 { throw exRun; } 432 catch(const css::uno::Exception&) 433 {} 434 435 return ::rtl::OUString(); 436 } 437 438 //-------------------------------------------------------------------- 439 440 void SfxViewShell::ExecMisc_Impl( SfxRequest &rReq ) 441 { 442 const sal_uInt16 nId = rReq.GetSlot(); 443 switch( nId ) 444 { 445 case SID_STYLE_FAMILY : 446 { 447 SFX_REQUEST_ARG(rReq, pItem, SfxUInt16Item, nId, sal_False); 448 if (pItem) 449 { 450 pImp->m_nFamily = pItem->GetValue(); 451 } 452 break; 453 } 454 455 case SID_STYLE_CATALOG: 456 { 457 SfxTemplateCatalog aCatalog( 458 SFX_APP()->GetTopWindow(), &GetViewFrame()->GetBindings()); 459 aCatalog.Execute(); 460 rReq.Ignore(); 461 break; 462 } 463 case SID_ACTIVATE_STYLE_APPLY: 464 { 465 com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame( 466 GetViewFrame()->GetFrame().GetFrameInterface(), 467 com::sun::star::uno::UNO_QUERY); 468 469 Reference< com::sun::star::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY ); 470 Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager; 471 if ( xPropSet.is() ) 472 { 473 try 474 { 475 Any aValue = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))); 476 aValue >>= xLayoutManager; 477 if ( xLayoutManager.is() ) 478 { 479 rtl::OUString aTextResString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/textobjectbar" )); 480 uno::Reference< ui::XUIElement > xElement = xLayoutManager->getElement( aTextResString ); 481 if(!xElement.is()) 482 { 483 rtl::OUString aFrameResString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/frameobjectbar" )); 484 xElement = xLayoutManager->getElement( aFrameResString ); 485 } 486 if(!xElement.is()) 487 { 488 rtl::OUString aOleResString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/oleobjectbar" )); 489 xElement = xLayoutManager->getElement( aOleResString ); 490 } 491 if(xElement.is()) 492 { 493 uno::Reference< awt::XWindow > xWin( xElement->getRealInterface(), uno::UNO_QUERY_THROW ); 494 Window* pWin = VCLUnoHelper::GetWindow( xWin ); 495 ToolBox* pTextToolbox = dynamic_cast< ToolBox* >( pWin ); 496 if( pTextToolbox ) 497 { 498 sal_uInt16 nItemCount = pTextToolbox->GetItemCount(); 499 for( sal_uInt16 nItem = 0; nItem < nItemCount; ++nItem ) 500 { 501 sal_uInt16 nItemId = pTextToolbox->GetItemId( nItem ); 502 const XubString& rCommand = pTextToolbox->GetItemCommand( nItemId ); 503 if( rCommand.EqualsAscii( ".uno:StyleApply" ) ) 504 { 505 Window* pItemWin = pTextToolbox->GetItemWindow( nItemId ); 506 if( pItemWin ) 507 pItemWin->GrabFocus(); 508 break; 509 } 510 } 511 } 512 } 513 } 514 } 515 catch ( Exception& ) 516 { 517 } 518 } 519 rReq.Done(); 520 } 521 break; 522 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 523 524 case SID_MAIL_SENDDOCASMS: 525 case SID_MAIL_SENDDOCASOOO: 526 case SID_MAIL_SENDDOCASPDF: 527 case SID_MAIL_SENDDOC: 528 case SID_MAIL_SENDDOCASFORMAT: 529 { 530 SfxObjectShell* pDoc = GetObjectShell(); 531 if ( pDoc && pDoc->QueryHiddenInformation( 532 WhenSaving, &GetViewFrame()->GetWindow() ) != RET_YES ) 533 break; 534 535 if ( SvtInternalOptions().MailUIEnabled() ) 536 { 537 GetViewFrame()->SetChildWindow( SID_MAIL_CHILDWIN, sal_True ); 538 } 539 else 540 { 541 SfxMailModel aModel; 542 rtl::OUString aDocType; 543 544 SFX_REQUEST_ARG(rReq, pMailSubject, SfxStringItem, SID_MAIL_SUBJECT, sal_False ); 545 if ( pMailSubject ) 546 aModel.SetSubject( pMailSubject->GetValue() ); 547 548 SFX_REQUEST_ARG(rReq, pMailRecipient, SfxStringItem, SID_MAIL_RECIPIENT, sal_False ); 549 if ( pMailRecipient ) 550 { 551 String aRecipient( pMailRecipient->GetValue() ); 552 String aMailToStr( String::CreateFromAscii( "mailto:" )); 553 554 if ( aRecipient.Search( aMailToStr ) == 0 ) 555 aRecipient = aRecipient.Erase( 0, aMailToStr.Len() ); 556 aModel.AddAddress( aRecipient, SfxMailModel::ROLE_TO ); 557 } 558 SFX_REQUEST_ARG(rReq, pMailDocType, SfxStringItem, SID_TYPE_NAME, sal_False ); 559 if ( pMailDocType ) 560 aDocType = pMailDocType->GetValue(); 561 562 uno::Reference < frame::XFrame > xFrame( pFrame->GetFrame().GetFrameInterface() ); 563 SfxMailModel::SendMailResult eResult = SfxMailModel::SEND_MAIL_ERROR; 564 565 if ( nId == SID_MAIL_SENDDOC ) 566 eResult = aModel.SaveAndSend( xFrame, rtl::OUString() ); 567 else 568 if ( nId == SID_MAIL_SENDDOCASPDF ) 569 eResult = aModel.SaveAndSend( xFrame, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "pdf_Portable_Document_Format" ))); 570 else 571 if ( nId == SID_MAIL_SENDDOCASMS ) 572 { 573 aDocType = impl_searchFormatTypeForApp(xFrame, E_MS_DOC); 574 if (aDocType.getLength() > 0) 575 eResult = aModel.SaveAndSend( xFrame, aDocType ); 576 } 577 else 578 if ( nId == SID_MAIL_SENDDOCASOOO ) 579 { 580 aDocType = impl_searchFormatTypeForApp(xFrame, E_OOO_DOC); 581 if (aDocType.getLength() > 0) 582 eResult = aModel.SaveAndSend( xFrame, aDocType ); 583 } 584 585 if ( eResult == SfxMailModel::SEND_MAIL_ERROR ) 586 { 587 InfoBox aBox( SFX_APP()->GetTopWindow(), SfxResId( MSG_ERROR_SEND_MAIL )); 588 aBox.Execute(); 589 rReq.Ignore(); 590 } 591 else 592 rReq.Done(); 593 } 594 595 break; 596 } 597 598 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 599 case SID_WEBHTML: 600 { 601 static const char HTML_DOCUMENT_TYPE[] = "writer_web_HTML"; 602 static const char HTML_GRAPHIC_TYPE[] = "graphic_HTML"; 603 const sal_Int32 FILTERFLAG_EXPORT = 0x00000002; 604 605 css::uno::Reference< lang::XMultiServiceFactory > xSMGR(::comphelper::getProcessServiceFactory(), css::uno::UNO_QUERY_THROW); 606 css::uno::Reference < css::frame::XFrame > xFrame( pFrame->GetFrame().GetFrameInterface() ); 607 css::uno::Reference< css::frame::XModel > xModel; 608 609 const rtl::OUString aModuleManager( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ModuleManager" )); 610 css::uno::Reference< css::frame::XModuleManager > xModuleManager( xSMGR->createInstance( aModuleManager ), css::uno::UNO_QUERY_THROW ); 611 if ( !xModuleManager.is() ) 612 { 613 rReq.Done(sal_False); 614 return; 615 } 616 617 rtl::OUString aModule; 618 try 619 { 620 aModule = xModuleManager->identify( xFrame ); 621 } 622 catch ( css::uno::RuntimeException& ) 623 { 624 throw; 625 } 626 catch ( css::uno::Exception& ) 627 { 628 } 629 630 if ( xFrame.is() ) 631 { 632 css::uno::Reference< css::frame::XController > xController = xFrame->getController(); 633 if ( xController.is() ) 634 xModel = xController->getModel(); 635 } 636 637 // We need at least a valid module name and model reference 638 css::uno::Reference< css::frame::XStorable > xStorable( xModel, css::uno::UNO_QUERY ); 639 if ( xModel.is() && xStorable.is() ) 640 { 641 rtl::OUString aFilterName; 642 rtl::OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM( HTML_DOCUMENT_TYPE )); 643 rtl::OUString aFileName; 644 rtl::OUString aExtension( RTL_CONSTASCII_USTRINGPARAM( "htm" )); 645 646 rtl::OUString aLocation = xStorable->getLocation(); 647 INetURLObject aFileObj( aLocation ); 648 649 bool bPrivateProtocol = ( aFileObj.GetProtocol() == INET_PROT_PRIV_SOFFICE ); 650 bool bHasLocation = ( aLocation.getLength() > 0 ) && !bPrivateProtocol; 651 652 css::uno::Reference< css::container::XContainerQuery > xContainerQuery( 653 xSMGR->createInstance( rtl::OUString( 654 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.FilterFactory" ))), 655 css::uno::UNO_QUERY_THROW ); 656 657 // Retrieve filter from type 658 sal_Int32 nFilterFlags = FILTERFLAG_EXPORT; 659 aFilterName = impl_retrieveFilterNameFromTypeAndModule( xContainerQuery, aTypeName, aModule, nFilterFlags ); 660 if ( aFilterName.getLength() == 0 ) 661 { 662 // Draw/Impress uses a different type. 2nd chance try to use alternative type name 663 aFilterName = impl_retrieveFilterNameFromTypeAndModule( 664 xContainerQuery, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( HTML_GRAPHIC_TYPE )), aModule, nFilterFlags ); 665 } 666 667 // No filter found => error 668 // No type and no location => error 669 if (( aFilterName.getLength() == 0 ) || ( aTypeName.getLength() == 0 )) 670 { 671 rReq.Done(sal_False); 672 return; 673 } 674 675 // Use provided save file name. If empty determine file name 676 if ( !bHasLocation ) 677 { 678 // Create a default file name with the correct extension 679 const rtl::OUString aPreviewFileName( RTL_CONSTASCII_USTRINGPARAM( "webpreview" )); 680 aFileName = aPreviewFileName; 681 } 682 else 683 { 684 // Determine file name from model 685 INetURLObject aFObj( xStorable->getLocation() ); 686 aFileName = aFObj.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::NO_DECODE ); 687 } 688 689 OSL_ASSERT( aFilterName.getLength() > 0 ); 690 OSL_ASSERT( aFileName.getLength() > 0 ); 691 692 // Creates a temporary directory to store our predefined file into it. 693 ::utl::TempFile aTempDir( NULL, sal_True ); 694 695 INetURLObject aFilePathObj( aTempDir.GetURL() ); 696 aFilePathObj.insertName( aFileName ); 697 aFilePathObj.setExtension( aExtension ); 698 699 rtl::OUString aFileURL = aFilePathObj.GetMainURL( INetURLObject::NO_DECODE ); 700 701 css::uno::Sequence< css::beans::PropertyValue > aArgs( 1 ); 702 aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" )); 703 aArgs[0].Value = css::uno::makeAny( aFilterName ); 704 705 // Store document in the html format 706 try 707 { 708 xStorable->storeToURL( aFileURL, aArgs ); 709 } 710 catch ( com::sun::star::io::IOException& ) 711 { 712 rReq.Done(sal_False); 713 return; 714 } 715 716 ::com::sun::star::uno::Reference< XSystemShellExecute > xSystemShellExecute( xSMGR->createInstance( 717 ::rtl::OUString::createFromAscii( "com.sun.star.system.SystemShellExecute" )), 718 css::uno::UNO_QUERY ); 719 720 sal_Bool bRet( sal_True ); 721 if ( xSystemShellExecute.is() ) 722 { 723 try 724 { 725 xSystemShellExecute->execute( 726 aFileURL, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS ); 727 } 728 catch ( uno::Exception& ) 729 { 730 vos::OGuard aGuard( Application::GetSolarMutex() ); 731 Window *pParent = SFX_APP()->GetTopWindow(); 732 ErrorBox( pParent, SfxResId( MSG_ERROR_NO_WEBBROWSER_FOUND )).Execute(); 733 bRet = sal_False; 734 } 735 } 736 737 rReq.Done(bRet); 738 break; 739 } 740 else 741 { 742 rReq.Done(sal_False); 743 return; 744 } 745 } 746 747 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 748 case SID_PLUGINS_ACTIVE: 749 { 750 SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, nId, sal_False); 751 bool const bActive = (pShowItem) 752 ? pShowItem->GetValue() 753 : !pImp->m_bPlugInsActive; 754 // ggf. recorden 755 if ( !rReq.IsAPI() ) 756 rReq.AppendItem( SfxBoolItem( nId, bActive ) ); 757 758 // Jetzt schon DONE aufrufen, da die Argumente evtl. einen Pool 759 // benutzen, der demn"achst weg ist 760 rReq.Done(sal_True); 761 762 // ausfuehren 763 if (!pShowItem || (bActive != pImp->m_bPlugInsActive)) 764 { 765 SfxFrame* pTopFrame = &GetFrame()->GetTopFrame(); 766 if ( pTopFrame != &GetFrame()->GetFrame() ) 767 { 768 // FramesetDocument 769 SfxViewShell *pShell = pTopFrame->GetCurrentViewFrame()->GetViewShell(); 770 if ( pShell->GetInterface()->GetSlot( nId ) ) 771 pShell->ExecuteSlot( rReq ); 772 break; 773 } 774 775 SfxFrameIterator aIter( *pTopFrame ); 776 while ( pTopFrame ) 777 { 778 if ( pTopFrame->GetCurrentViewFrame() ) 779 { 780 SfxViewShell *pView = pTopFrame->GetCurrentViewFrame()->GetViewShell(); 781 if ( pView ) 782 { 783 pView->pImp->m_bPlugInsActive = bActive; 784 Rectangle aVisArea = GetObjectShell()->GetVisArea(); 785 VisAreaChanged(aVisArea); 786 787 // the plugins might need change in their state 788 SfxInPlaceClientList *pClients = pView->GetIPClientList_Impl(sal_False); 789 if ( pClients ) 790 { 791 for (sal_uInt16 n=0; n < pClients->Count(); n++) 792 { 793 SfxInPlaceClient* pIPClient = pClients->GetObject(n); 794 if ( pIPClient ) 795 pView->CheckIPClient_Impl( pIPClient, aVisArea ); 796 } 797 } 798 } 799 } 800 801 if ( !pTopFrame->GetParentFrame() ) 802 pTopFrame = aIter.FirstFrame(); 803 else 804 pTopFrame = aIter.NextFrame( *pTopFrame ); 805 } 806 } 807 808 break; 809 } 810 } 811 } 812 813 //-------------------------------------------------------------------- 814 815 void SfxViewShell::GetState_Impl( SfxItemSet &rSet ) 816 { 817 DBG_CHKTHIS(SfxViewShell, 0); 818 819 SfxWhichIter aIter( rSet ); 820 for ( sal_uInt16 nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() ) 821 { 822 switch ( nSID ) 823 { 824 case SID_STYLE_CATALOG: 825 { 826 if ( !GetViewFrame()->KnowsChildWindow( SID_STYLE_DESIGNER ) ) 827 rSet.DisableItem( nSID ); 828 break; 829 } 830 831 // Printer-Funktionen 832 case SID_PRINTDOC: 833 case SID_PRINTDOCDIRECT: 834 case SID_SETUPPRINTER: 835 case SID_PRINTER_NAME: 836 { 837 bool bEnabled = pImp->m_bCanPrint && !pImp->m_nPrinterLocks; 838 bEnabled = bEnabled && !Application::GetSettings().GetMiscSettings().GetDisablePrinting(); 839 if ( bEnabled ) 840 { 841 SfxPrinter *pPrinter = GetPrinter(sal_False); 842 843 if ( SID_PRINTDOCDIRECT == nSID ) 844 { 845 rtl::OUString aPrinterName; 846 if ( pPrinter != NULL ) 847 aPrinterName = pPrinter->GetName(); 848 else 849 aPrinterName = Printer::GetDefaultPrinterName(); 850 if ( aPrinterName.getLength() > 0 ) 851 { 852 uno::Reference < frame::XFrame > xFrame( pFrame->GetFrame().GetFrameInterface() ); 853 854 ::rtl::OUStringBuffer aBuffer( 60 ); 855 aBuffer.append( RetrieveLabelFromCommand( 856 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:PrintDefault" )), 857 xFrame )); 858 aBuffer.appendAscii( " (" ); 859 aBuffer.append( aPrinterName ); 860 aBuffer.appendAscii( ")" ); 861 862 rSet.Put( SfxStringItem( SID_PRINTDOCDIRECT, aBuffer.makeStringAndClear() ) ); 863 } 864 } 865 bEnabled = !pPrinter || !pPrinter->IsPrinting(); 866 } 867 if ( !bEnabled ) 868 { 869 // will now be handled by requeing the request 870 /* rSet.DisableItem( SID_PRINTDOC ); 871 rSet.DisableItem( SID_PRINTDOCDIRECT ); 872 rSet.DisableItem( SID_SETUPPRINTER ); */ 873 } 874 break; 875 } 876 877 // Mail-Funktionen 878 case SID_MAIL_SENDDOCASPDF: 879 case SID_MAIL_SENDDOC: 880 case SID_MAIL_SENDDOCASFORMAT: 881 { 882 sal_Bool bEnable = !GetViewFrame()->HasChildWindow( SID_MAIL_CHILDWIN ); 883 if ( !bEnable ) 884 rSet.DisableItem( nSID ); 885 break; 886 } 887 888 // PlugIns running 889 case SID_PLUGINS_ACTIVE: 890 { 891 rSet.Put( SfxBoolItem( SID_PLUGINS_ACTIVE, 892 !pImp->m_bPlugInsActive) ); 893 break; 894 } 895 /* 896 // SelectionText 897 case SID_SELECTION_TEXT: 898 { 899 rSet.Put( SfxStringItem( SID_SELECTION_TEXT, GetSelectionText() ) ); 900 break; 901 } 902 903 // SelectionTextExt 904 case SID_SELECTION_TEXT_EXT: 905 { 906 rSet.Put( SfxStringItem( SID_SELECTION_TEXT_EXT, GetSelectionText(sal_True) ) ); 907 break; 908 } 909 */ 910 case SID_STYLE_FAMILY : 911 { 912 rSet.Put( SfxUInt16Item( SID_STYLE_FAMILY, pImp->m_nFamily ) ); 913 break; 914 } 915 } 916 } 917 } 918 919 //-------------------------------------------------------------------- 920 921 void SfxViewShell::SetZoomFactor( const Fraction &rZoomX, 922 const Fraction &rZoomY ) 923 { 924 DBG_ASSERT( GetWindow(), "no window" ); 925 MapMode aMap( GetWindow()->GetMapMode() ); 926 aMap.SetScaleX( rZoomX ); 927 aMap.SetScaleY( rZoomY ); 928 GetWindow()->SetMapMode( aMap ); 929 } 930 931 //-------------------------------------------------------------------- 932 ErrCode SfxViewShell::DoVerb(long /*nVerb*/) 933 934 /* [Beschreibung] 935 936 Virtuelle Methode, um am selektierten Objekt ein Verb auszuf"uhren. 937 Da dieses Objekt nur den abgeleiteten Klassen bekannt ist, muss DoVerb 938 dort "uberschrieben werden. 939 940 */ 941 942 { 943 return ERRCODE_SO_NOVERBS; 944 } 945 946 //-------------------------------------------------------------------- 947 948 void SfxViewShell::OutplaceActivated( sal_Bool bActive, SfxInPlaceClient* /*pClient*/ ) 949 { 950 if ( !bActive ) 951 GetFrame()->GetFrame().Appear(); 952 } 953 954 //-------------------------------------------------------------------- 955 956 void SfxViewShell::InplaceActivating( SfxInPlaceClient* /*pClient*/ ) 957 { 958 // TODO/LATER: painting of the bitmap can be stopped, it is required if CLIPCHILDREN problem #i25788# is not solved, 959 // but may be the bug will not affect the real office vcl windows, then it is not required 960 } 961 962 //-------------------------------------------------------------------- 963 964 void SfxViewShell::InplaceDeactivated( SfxInPlaceClient* /*pClient*/ ) 965 { 966 // TODO/LATER: paint the replacement image in normal way if the painting was stopped 967 } 968 969 //-------------------------------------------------------------------- 970 971 void SfxViewShell::UIActivating( SfxInPlaceClient* /*pClient*/ ) 972 { 973 uno::Reference < frame::XFrame > xOwnFrame( pFrame->GetFrame().GetFrameInterface() ); 974 uno::Reference < frame::XFramesSupplier > xParentFrame( xOwnFrame->getCreator(), uno::UNO_QUERY ); 975 if ( xParentFrame.is() ) 976 xParentFrame->setActiveFrame( xOwnFrame ); 977 978 pFrame->GetBindings().HidePopups(sal_True); 979 pFrame->GetDispatcher()->Update_Impl( sal_True ); 980 } 981 982 //-------------------------------------------------------------------- 983 984 void SfxViewShell::UIDeactivated( SfxInPlaceClient* /*pClient*/ ) 985 { 986 if ( !pFrame->GetFrame().IsClosing_Impl() || 987 SfxViewFrame::Current() != pFrame ) 988 pFrame->GetDispatcher()->Update_Impl( sal_True ); 989 pFrame->GetBindings().HidePopups(sal_False); 990 991 // uno::Reference < frame::XFrame > xOwnFrame( pFrame->GetFrame().GetFrameInterface() ); 992 // uno::Reference < frame::XFramesSupplier > xParentFrame( xOwnFrame->getCreator(), uno::UNO_QUERY ); 993 // if ( xParentFrame.is() ) 994 // xParentFrame->setActiveFrame( uno::Reference < frame::XFrame >() ); 995 } 996 997 //-------------------------------------------------------------------- 998 999 SfxInPlaceClient* SfxViewShell::FindIPClient 1000 ( 1001 const uno::Reference < embed::XEmbeddedObject >& xObj, 1002 Window* pObjParentWin 1003 ) const 1004 { 1005 SfxInPlaceClientList *pClients = GetIPClientList_Impl(sal_False); 1006 if ( !pClients ) 1007 return 0; 1008 1009 if( !pObjParentWin ) 1010 pObjParentWin = GetWindow(); 1011 for (sal_uInt16 n=0; n < pClients->Count(); n++) 1012 { 1013 SfxInPlaceClient *pIPClient = (SfxInPlaceClient*) pClients->GetObject(n); 1014 if ( pIPClient->GetObject() == xObj && pIPClient->GetEditWin() == pObjParentWin ) 1015 return pIPClient; 1016 } 1017 1018 return 0; 1019 } 1020 1021 //-------------------------------------------------------------------- 1022 1023 SfxInPlaceClient* SfxViewShell::GetIPClient() const 1024 { 1025 return GetUIActiveClient(); 1026 } 1027 1028 //-------------------------------------------------------------------- 1029 1030 SfxInPlaceClient* SfxViewShell::GetUIActiveIPClient_Impl() const 1031 { 1032 // this method is needed as long as SFX still manages the border space for ChildWindows (see SfxFrame::Resize) 1033 SfxInPlaceClientList *pClients = GetIPClientList_Impl(sal_False); 1034 if ( !pClients ) 1035 return 0; 1036 1037 for (sal_uInt16 n=0; n < pClients->Count(); n++) 1038 { 1039 SfxInPlaceClient* pIPClient = pClients->GetObject(n); 1040 if ( pIPClient->IsUIActive() ) 1041 return pIPClient; 1042 } 1043 1044 return NULL; 1045 } 1046 1047 SfxInPlaceClient* SfxViewShell::GetUIActiveClient() const 1048 { 1049 SfxInPlaceClientList *pClients = GetIPClientList_Impl(sal_False); 1050 if ( !pClients ) 1051 return 0; 1052 1053 for (sal_uInt16 n=0; n < pClients->Count(); n++) 1054 { 1055 SfxInPlaceClient* pIPClient = pClients->GetObject(n); 1056 if ( pIPClient->IsObjectUIActive() ) 1057 return pIPClient; 1058 } 1059 1060 return NULL; 1061 } 1062 1063 //-------------------------------------------------------------------- 1064 1065 void SfxViewShell::Activate( sal_Bool bMDI ) 1066 { 1067 DBG_CHKTHIS(SfxViewShell, 0); 1068 if ( bMDI ) 1069 { 1070 SfxObjectShell *pSh = GetViewFrame()->GetObjectShell(); 1071 if ( pSh->GetModel().is() ) 1072 pSh->GetModel()->setCurrentController( GetViewFrame()->GetFrame().GetController() ); 1073 1074 SetCurrentDocument(); 1075 } 1076 } 1077 1078 //-------------------------------------------------------------------- 1079 1080 void SfxViewShell::Deactivate(sal_Bool /*bMDI*/) 1081 { 1082 DBG_CHKTHIS(SfxViewShell, 0); 1083 } 1084 1085 //-------------------------------------------------------------------- 1086 1087 void SfxViewShell::AdjustPosSizePixel 1088 ( 1089 const Point& /*rToolOffset*/,// linke obere Ecke der Tools im Frame-Window 1090 const Size& /*rSize*/ // gesamte zur Verf"ugung stehende Gr"o\se 1091 ) 1092 1093 { 1094 DBG_CHKTHIS(SfxViewShell, 0); 1095 } 1096 1097 //-------------------------------------------------------------------- 1098 1099 void SfxViewShell::Move() 1100 1101 /* [Beschreibung] 1102 1103 Diese virtuelle Methode wird gerufen, wenn das Fenster, in dem die 1104 SfxViewShell dargestellt wird eine StarView-Move() Nachricht erh"alt. 1105 1106 Die Basisimplementierung braucht nicht gerufen zu werden. 1107 1108 1109 [Anmerkung] 1110 1111 Diese Methode kann dazu verwendet werden, eine Selektion abzubrechen, 1112 um durch das Moven des Fensters erzeugte Maus-Bewegungen anzufangen. 1113 1114 Zur Zeit funktioniert die Benachrichtigung nicht In-Place. 1115 */ 1116 1117 { 1118 } 1119 1120 //-------------------------------------------------------------------- 1121 1122 void SfxViewShell::OuterResizePixel 1123 ( 1124 const Point& /*rToolOffset*/,// linke obere Ecke der Tools im Frame-Window 1125 const Size& /*rSize*/ // gesamte zur Verf"ugung stehende Gr"o\se 1126 ) 1127 1128 /* [Beschreibung] 1129 1130 Diese Methode muss ueberladen werden, um auf "Anderungen der Groesse 1131 der View zu reagieren. Dabei definieren wir die View als das Edit-Window 1132 zuz"uglich der um das Edit-Window angeordnenten Tools (z.B. Lineale). 1133 1134 Das Edit-Window darf weder in Gr"o\se noch Position ver"andert werden. 1135 1136 Die Vis-Area der SfxObjectShell, dessen Skalierung und Position 1137 d"urfen hier ver"andert werden. Der Hauptanwendungsfall ist dabei, 1138 das Ver"andern der Gr"o\se der Vis-Area. 1139 1140 "Andert sich durch die neue Berechnung der Border, so mu\s dieser 1141 mit <SfxViewShell::SetBorderPixel(const SvBorder&)> gesetzt werden. 1142 Erst nach Aufruf von 'SetBorderPixel' ist das Positionieren von 1143 Tools erlaubt. 1144 1145 1146 [Beispiel] 1147 1148 void AppViewSh::OuterViewResizePixel( const Point &rOfs, const Size &rSz ) 1149 { 1150 // Tool-Positionen und Gr"o\sen von au\sen berechnen, NICHT setzen! 1151 // (wegen folgender Border-Berechnung) 1152 Point aHLinPos...; Size aHLinSz...; 1153 ... 1154 1155 // Border f"ur Tools passend zu rSize berechnen und setzen 1156 SvBorder aBorder... 1157 SetBorderPixel( aBorder ); // ab jetzt sind Positionierungen erlaubt 1158 1159 // Tools anordnen 1160 pHLin->SetPosSizePixel( aHLinPos, aHLinSz ); 1161 ... 1162 } 1163 1164 1165 [Querverweise] 1166 1167 <SfxViewShell::InnerResizePixel(const Point&,const Size& rSize)> 1168 */ 1169 1170 { 1171 DBG_CHKTHIS(SfxViewShell, 0); 1172 SetBorderPixel( SvBorder() ); 1173 } 1174 1175 //-------------------------------------------------------------------- 1176 1177 void SfxViewShell::InnerResizePixel 1178 ( 1179 const Point& /*rToolOffset*/,// linke obere Ecke der Tools im Frame-Window 1180 const Size& /*rSize*/ // dem Edit-Win zur Verf"ugung stehende Gr"o\se 1181 ) 1182 1183 /* [Beschreibung] 1184 1185 Diese Methode muss ueberladen werden, um auf "Anderungen der Groesse 1186 des Edit-Windows zu reagieren. 1187 1188 Das Edit-Window darf weder in Gr"o\se noch Position ver"andert werden. 1189 Weder die Vis-Area der SfxObjectShell noch dessen Skalierung oder 1190 Position d"urfen ver"andert werden. 1191 1192 "Andert sich durch die neue Berechnung der Border, so mu\s dieser 1193 mit <SfxViewShell::SetBorderPixel(const SvBorder&)> gesetzt werden. 1194 Erst nach Aufruf von 'SetBorderPixel' ist das Positionieren von 1195 Tools erlaubt. 1196 1197 1198 [Beispiel] 1199 1200 void AppViewSh::InnerViewResizePixel( const Point &rOfs, const Size &rSz ) 1201 { 1202 // Tool-Positionen und Gr"o\sen von innen berechnen, NICHT setzen! 1203 // (wegen folgender Border-Berechnung) 1204 Point aHLinPos...; Size aHLinSz...; 1205 ... 1206 1207 // Border f"ur Tools passend zu rSz berechnen und setzen 1208 SvBorder aBorder... 1209 SetBorderPixel( aBorder ); // ab jetzt sind Positionierungen erlaubt 1210 1211 // Tools anordnen 1212 pHLin->SetPosSizePixel( aHLinPos, aHLinSz ); 1213 ... 1214 } 1215 1216 1217 [Querverweise] 1218 1219 <SfxViewShell::OuterResizePixel(const Point&,const Size& rSize)> 1220 */ 1221 1222 { 1223 DBG_CHKTHIS(SfxViewShell, 0); 1224 SetBorderPixel( SvBorder() ); 1225 } 1226 1227 //-------------------------------------------------------------------- 1228 1229 void SfxViewShell::InvalidateBorder() 1230 { 1231 DBG_CHKTHIS(SfxViewShell, 0); 1232 DBG_ASSERT( GetViewFrame(), "SfxViewShell without SfxViewFrame" ); 1233 1234 GetViewFrame()->InvalidateBorderImpl( this ); 1235 if (pImp->m_pController.is()) 1236 { 1237 pImp->m_pController->BorderWidthsChanged_Impl(); 1238 } 1239 } 1240 1241 //-------------------------------------------------------------------- 1242 1243 void SfxViewShell::SetBorderPixel( const SvBorder &rBorder ) 1244 { 1245 DBG_CHKTHIS(SfxViewShell, 0); 1246 DBG_ASSERT( GetViewFrame(), "SfxViewShell without SfxViewFrame" ); 1247 1248 //if ( rBorder != GetBorderPixel()) 1249 { 1250 GetViewFrame()->SetBorderPixelImpl( this, rBorder ); 1251 1252 // notify related controller that border size is changed 1253 if (pImp->m_pController.is()) 1254 { 1255 pImp->m_pController->BorderWidthsChanged_Impl(); 1256 } 1257 } 1258 } 1259 1260 //-------------------------------------------------------------------- 1261 1262 const SvBorder& SfxViewShell::GetBorderPixel() const 1263 { 1264 DBG_CHKTHIS(SfxViewShell, 0); 1265 DBG_ASSERT( GetViewFrame(), "SfxViewShell without SfxViewFrame" ); 1266 1267 return GetViewFrame()->GetBorderPixelImpl( this ); 1268 } 1269 1270 //-------------------------------------------------------------------- 1271 1272 void SfxViewShell::SetWindow 1273 ( 1274 Window* pViewPort // Pointer auf das Datenfenster bzw. 0 im Destruktor 1275 ) 1276 1277 /* [Beschreibung] 1278 1279 Mit dieser Methode wird der SfxViewShell das Datenfenster mitgeteilt. 1280 Dieses wird f"ur den In-Place-Container und f"ur das korrekte 1281 Wiederherstellen des Focus ben"otigt. 1282 1283 Selbst In-Place-aktiv ist das Umsetzen des ViewPort-Windows verboten. 1284 */ 1285 1286 { 1287 if( pWindow == pViewPort ) 1288 return; 1289 1290 // ggf. vorhandene IP-Clients disconnecten 1291 DisconnectAllClients(); 1292 1293 //TODO: should we have a "ReconnectAllClients" method? 1294 DiscardClients_Impl(); 1295 1296 // View-Port austauschen 1297 sal_Bool bHadFocus = pWindow ? pWindow->HasChildPathFocus( sal_True ) : sal_False; 1298 pWindow = pViewPort; 1299 1300 if( pWindow ) 1301 { 1302 // Disable automatic GUI mirroring (right-to-left) for document windows 1303 pWindow->EnableRTL( sal_False ); 1304 } 1305 1306 if ( bHadFocus && pWindow ) 1307 pWindow->GrabFocus(); 1308 //TODO/CLEANUP 1309 //brauchen wir die Methode doch noch?! 1310 //SFX_APP()->GrabFocus( pWindow ); 1311 } 1312 1313 //-------------------------------------------------------------------- 1314 1315 Size SfxViewShell::GetOptimalSizePixel() const 1316 { 1317 DBG_ERROR( "Useless call!" ); 1318 return Size(); 1319 } 1320 1321 //------------------------------------------------------------------------ 1322 1323 SfxViewShell::SfxViewShell 1324 ( 1325 SfxViewFrame* pViewFrame, /* <SfxViewFrame>, in dem diese View dargestellt wird */ 1326 sal_uInt16 nFlags /* siehe <SfxViewShell-Flags> */ 1327 ) 1328 1329 : SfxShell(this) 1330 , pImp( new SfxViewShell_Impl(nFlags) ) 1331 ,pIPClientList( 0 ) 1332 ,pFrame(pViewFrame) 1333 ,pSubShell(0) 1334 ,pWindow(0) 1335 ,bNoNewWindow( 0 != (nFlags & SFX_VIEW_NO_NEWWINDOW) ) 1336 { 1337 DBG_CTOR(SfxViewShell, 0); 1338 1339 //pImp->pPrinterCommandQueue = new SfxAsyncPrintExec_Impl( this ); 1340 1341 if ( pViewFrame->GetParentViewFrame() ) 1342 { 1343 pImp->m_bPlugInsActive = pViewFrame->GetParentViewFrame() 1344 ->GetViewShell()->pImp->m_bPlugInsActive; 1345 } 1346 SetMargin( pViewFrame->GetMargin_Impl() ); 1347 1348 SetPool( &pViewFrame->GetObjectShell()->GetPool() ); 1349 StartListening(*pViewFrame->GetObjectShell()); 1350 1351 // in Liste eintragen 1352 const SfxViewShell *pThis = this; // wegen der kranken Array-Syntax 1353 SfxViewShellArr_Impl &rViewArr = SFX_APP()->GetViewShells_Impl(); 1354 rViewArr.Insert(pThis, rViewArr.Count() ); 1355 } 1356 1357 //-------------------------------------------------------------------- 1358 1359 SfxViewShell::~SfxViewShell() 1360 { 1361 DBG_DTOR(SfxViewShell, 0); 1362 1363 // aus Liste austragen 1364 const SfxViewShell *pThis = this; 1365 SfxViewShellArr_Impl &rViewArr = SFX_APP()->GetViewShells_Impl(); 1366 rViewArr.Remove( rViewArr.GetPos(pThis) ); 1367 1368 if ( pImp->xClipboardListener.is() ) 1369 { 1370 pImp->xClipboardListener->DisconnectViewShell(); 1371 pImp->xClipboardListener = NULL; 1372 } 1373 1374 if (pImp->m_pController.is()) 1375 { 1376 pImp->m_pController->ReleaseShell_Impl(); 1377 pImp->m_pController.clear(); 1378 } 1379 1380 //DELETEZ( pImp->pPrinterCommandQueue ); 1381 DELETEZ( pImp ); 1382 DELETEZ( pIPClientList ); 1383 } 1384 1385 //-------------------------------------------------------------------- 1386 1387 sal_uInt16 SfxViewShell::PrepareClose 1388 ( 1389 sal_Bool bUI, // sal_True: Dialoge etc. erlaubt, sal_False: silent-mode 1390 sal_Bool /*bForBrowsing*/ 1391 ) 1392 { 1393 SfxPrinter *pPrinter = GetPrinter(); 1394 if ( pPrinter && pPrinter->IsPrinting() ) 1395 { 1396 if ( bUI ) 1397 { 1398 InfoBox aInfoBox( &GetViewFrame()->GetWindow(), SfxResId( MSG_CANT_CLOSE ) ); 1399 aInfoBox.Execute(); 1400 } 1401 1402 return sal_False; 1403 } 1404 1405 if( GetViewFrame()->IsInModalMode() ) 1406 return sal_False; 1407 1408 if( bUI && GetViewFrame()->GetDispatcher()->IsLocked() ) 1409 return sal_False; 1410 1411 return sal_True; 1412 } 1413 1414 //-------------------------------------------------------------------- 1415 1416 SfxViewShell* SfxViewShell::Current() 1417 { 1418 SfxViewFrame *pCurrent = SfxViewFrame::Current(); 1419 return pCurrent ? pCurrent->GetViewShell() : NULL; 1420 } 1421 1422 //-------------------------------------------------------------------- 1423 1424 SfxViewShell* SfxViewShell::Get( const Reference< XController>& i_rController ) 1425 { 1426 if ( !i_rController.is() ) 1427 return NULL; 1428 1429 for ( SfxViewShell* pViewShell = SfxViewShell::GetFirst( NULL, sal_False ); 1430 pViewShell; 1431 pViewShell = SfxViewShell::GetNext( *pViewShell, NULL, sal_False ) 1432 ) 1433 { 1434 if ( pViewShell->GetController() == i_rController ) 1435 return pViewShell; 1436 } 1437 return NULL; 1438 } 1439 1440 //-------------------------------------------------------------------- 1441 1442 SdrView* SfxViewShell::GetDrawView() const 1443 1444 /* [Beschreibung] 1445 1446 Diese virtuelle Methode mu\s von den Subklassen "uberladen werden, wenn 1447 der Property-Editor zur Verf"ugung stehen soll. 1448 1449 Die Default-Implementierung liefert immer 0. 1450 */ 1451 1452 { 1453 return 0; 1454 } 1455 1456 //-------------------------------------------------------------------- 1457 1458 String SfxViewShell::GetSelectionText 1459 ( 1460 sal_Bool /*bCompleteWords*/ /* sal_False (default) 1461 Nur der tats"achlich selektierte Text wird 1462 zur"uckgegeben. 1463 1464 TRUE 1465 Der selektierte Text wird soweit erweitert, 1466 da\s nur ganze W"orter zur"uckgegeben werden. 1467 Als Worttrenner gelten White-Spaces und die 1468 Satzzeichen ".,;" sowie einfache und doppelte 1469 Anf"uhrungszeichen. 1470 */ 1471 ) 1472 1473 /* [Beschreibung] 1474 1475 Diese Methode kann von Anwendungsprogrammierer "uberladen werden, 1476 um einen Text zur"uckzuliefern, der in der aktuellen Selektion 1477 steht. Dieser wird z.B. beim Versenden (email) verwendet. 1478 1479 Mit "CompleteWords == TRUE" ger"ufen, reicht z.B. auch der Cursor, 1480 der in einer URL steht, um die gesamte URL zu liefern. 1481 */ 1482 1483 { 1484 return String(); 1485 } 1486 1487 //-------------------------------------------------------------------- 1488 1489 sal_Bool SfxViewShell::HasSelection( sal_Bool ) const 1490 1491 /* [Beschreibung] 1492 1493 Mit dieser virtuellen Methode kann z.B. ein Dialog abfragen, ob in der 1494 aktuellen View etwas selektiert ist. Wenn der Parameter <sal_Bool> sal_True ist, 1495 wird abgefragt, ob Text selektiert ist. 1496 */ 1497 1498 { 1499 return sal_False; 1500 } 1501 1502 //-------------------------------------------------------------------- 1503 1504 void SfxViewShell::SetSubShell( SfxShell *pShell ) 1505 1506 /* [Beschreibung] 1507 1508 Mit dieser Methode kann eine Selektions- oder Cursor-Shell angemeldet 1509 werden, die automatisch unmittelbar nach der SfxViewShell auf den 1510 SfxDispatcher gepusht wird, und automatisch umittelbar vor ihr 1511 gepoppt wird. 1512 1513 Ist die SfxViewShell-Instanz bereits gepusht, dann wird pShell 1514 sofort ebenfalls gepusht. Wird mit SetSubShell eine andere SfxShell 1515 Instanz angemeldet, als vorher angemeldet war, wird die zuvor angemeldete 1516 ggf. automatisch gepoppt. Mit pShell==0 kann daher die aktuelle 1517 Sub-Shell abgemeldet werden. 1518 */ 1519 1520 { 1521 // ist diese ViewShell "uberhaupt aktiv? 1522 SfxDispatcher *pDisp = pFrame->GetDispatcher(); 1523 if ( pDisp->IsActive(*this) ) 1524 { 1525 // Dispatcher updaten 1526 if ( pSubShell ) 1527 pDisp->Pop(*pSubShell); 1528 if ( pShell ) 1529 pDisp->Push(*pShell); 1530 pDisp->Flush(); 1531 } 1532 1533 pSubShell = pShell; 1534 } 1535 1536 void SfxViewShell::AddSubShell( SfxShell& rShell ) 1537 { 1538 pImp->aArr.Insert( &rShell, pImp->aArr.Count() ); 1539 SfxDispatcher *pDisp = pFrame->GetDispatcher(); 1540 if ( pDisp->IsActive(*this) ) 1541 { 1542 pDisp->Push(rShell); 1543 pDisp->Flush(); 1544 } 1545 } 1546 1547 void SfxViewShell::RemoveSubShell( SfxShell* pShell ) 1548 { 1549 SfxDispatcher *pDisp = pFrame->GetDispatcher(); 1550 if ( !pShell ) 1551 { 1552 sal_uInt16 nCount = pImp->aArr.Count(); 1553 if ( pDisp->IsActive(*this) ) 1554 { 1555 for ( sal_uInt16 n=nCount; n>0; n-- ) 1556 pDisp->Pop( *pImp->aArr[n-1] ); 1557 pDisp->Flush(); 1558 } 1559 1560 pImp->aArr.Remove(0, nCount); 1561 } 1562 else 1563 { 1564 sal_uInt16 nPos = pImp->aArr.GetPos( pShell ); 1565 if ( nPos != 0xFFFF ) 1566 { 1567 pImp->aArr.Remove( nPos ); 1568 if ( pDisp->IsActive(*this) ) 1569 { 1570 pDisp->RemoveShell_Impl( *pShell ); 1571 pDisp->Flush(); 1572 } 1573 } 1574 } 1575 } 1576 1577 SfxShell* SfxViewShell::GetSubShell( sal_uInt16 nNo ) 1578 { 1579 sal_uInt16 nCount = pImp->aArr.Count(); 1580 if ( nNo<nCount ) 1581 return pImp->aArr[nCount-nNo-1]; 1582 return NULL; 1583 } 1584 1585 void SfxViewShell::PushSubShells_Impl( sal_Bool bPush ) 1586 { 1587 sal_uInt16 nCount = pImp->aArr.Count(); 1588 SfxDispatcher *pDisp = pFrame->GetDispatcher(); 1589 if ( bPush ) 1590 { 1591 for ( sal_uInt16 n=0; n<nCount; n++ ) 1592 pDisp->Push( *pImp->aArr[n] ); 1593 } 1594 else if ( nCount ) 1595 { 1596 SfxShell& rPopUntil = *pImp->aArr[0]; 1597 if ( pDisp->GetShellLevel( rPopUntil ) != USHRT_MAX ) 1598 pDisp->Pop( rPopUntil, SFX_SHELL_POP_UNTIL ); 1599 } 1600 1601 pDisp->Flush(); 1602 } 1603 1604 //-------------------------------------------------------------------- 1605 1606 void SfxViewShell::WriteUserData( String&, sal_Bool ) 1607 { 1608 } 1609 1610 //-------------------------------------------------------------------- 1611 1612 void SfxViewShell::ReadUserData(const String&, sal_Bool ) 1613 { 1614 } 1615 1616 void SfxViewShell::ReadUserDataSequence ( const ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >&, sal_Bool ) 1617 { 1618 } 1619 1620 void SfxViewShell::WriteUserDataSequence ( ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >&, sal_Bool ) 1621 { 1622 } 1623 1624 1625 //-------------------------------------------------------------------- 1626 // returns the first shell of spec. type viewing the specified doc. 1627 1628 SfxViewShell* SfxViewShell::GetFirst 1629 ( 1630 const TypeId* pType, 1631 sal_Bool bOnlyVisible 1632 ) 1633 { 1634 // search for a SfxViewShell of the specified type 1635 SfxViewShellArr_Impl &rShells = SFX_APP()->GetViewShells_Impl(); 1636 SfxViewFrameArr_Impl &rFrames = SFX_APP()->GetViewFrames_Impl(); 1637 for ( sal_uInt16 nPos = 0; nPos < rShells.Count(); ++nPos ) 1638 { 1639 SfxViewShell *pShell = rShells.GetObject(nPos); 1640 if ( pShell ) 1641 { 1642 // sometimes dangling SfxViewShells exist that point to a dead SfxViewFrame 1643 // these ViewShells shouldn't be accessible anymore 1644 // a destroyed ViewFrame is not in the ViewFrame array anymore, so checking this array helps 1645 for ( sal_uInt16 n=0; n<rFrames.Count(); ++n ) 1646 { 1647 SfxViewFrame *pFrame = rFrames.GetObject(n); 1648 if ( pFrame == pShell->GetViewFrame() ) 1649 { 1650 // only ViewShells with a valid ViewFrame will be returned 1651 if ( ( !bOnlyVisible || pFrame->IsVisible() ) && ( !pType || pShell->IsA(*pType) ) ) 1652 return pShell; 1653 break; 1654 } 1655 } 1656 } 1657 } 1658 1659 return 0; 1660 } 1661 1662 //-------------------------------------------------------------------- 1663 // returns the next shell of spec. type viewing the specified doc. 1664 1665 SfxViewShell* SfxViewShell::GetNext 1666 ( 1667 const SfxViewShell& rPrev, 1668 const TypeId* pType, 1669 sal_Bool bOnlyVisible 1670 ) 1671 { 1672 SfxViewShellArr_Impl &rShells = SFX_APP()->GetViewShells_Impl(); 1673 SfxViewFrameArr_Impl &rFrames = SFX_APP()->GetViewFrames_Impl(); 1674 sal_uInt16 nPos; 1675 for ( nPos = 0; nPos < rShells.Count(); ++nPos ) 1676 if ( rShells.GetObject(nPos) == &rPrev ) 1677 break; 1678 1679 for ( ++nPos; nPos < rShells.Count(); ++nPos ) 1680 { 1681 SfxViewShell *pShell = rShells.GetObject(nPos); 1682 if ( pShell ) 1683 { 1684 // sometimes dangling SfxViewShells exist that point to a dead SfxViewFrame 1685 // these ViewShells shouldn't be accessible anymore 1686 // a destroyed ViewFrame is not in the ViewFrame array anymore, so checking this array helps 1687 for ( sal_uInt16 n=0; n<rFrames.Count(); ++n ) 1688 { 1689 SfxViewFrame *pFrame = rFrames.GetObject(n); 1690 if ( pFrame == pShell->GetViewFrame() ) 1691 { 1692 // only ViewShells with a valid ViewFrame will be returned 1693 if ( ( !bOnlyVisible || pFrame->IsVisible() ) && ( !pType || pShell->IsA(*pType) ) ) 1694 return pShell; 1695 break; 1696 } 1697 } 1698 } 1699 } 1700 1701 return 0; 1702 } 1703 1704 //-------------------------------------------------------------------- 1705 1706 void SfxViewShell::Notify( SfxBroadcaster& rBC, 1707 const SfxHint& rHint ) 1708 { 1709 if ( rHint.IsA(TYPE(SfxEventHint)) ) 1710 { 1711 switch ( ((SfxEventHint&)rHint).GetEventId() ) 1712 { 1713 case SFX_EVENT_LOADFINISHED: 1714 { 1715 if ( GetController().is() ) 1716 { 1717 // avoid access to dangling ViewShells 1718 SfxViewFrameArr_Impl &rFrames = SFX_APP()->GetViewFrames_Impl(); 1719 for ( sal_uInt16 n=0; n<rFrames.Count(); ++n ) 1720 { 1721 SfxViewFrame *frame = rFrames.GetObject(n); 1722 if ( frame == GetViewFrame() && &rBC == GetObjectShell() ) 1723 { 1724 SfxItemSet* pSet = GetObjectShell()->GetMedium()->GetItemSet(); 1725 SFX_ITEMSET_ARG( pSet, pItem, SfxUnoAnyItem, SID_VIEW_DATA, sal_False ); 1726 if ( pItem ) 1727 { 1728 pImp->m_pController->restoreViewData( 1729 pItem->GetValue() ); 1730 pSet->ClearItem( SID_VIEW_DATA ); 1731 } 1732 1733 break; 1734 } 1735 } 1736 } 1737 1738 break; 1739 } 1740 } 1741 } 1742 } 1743 1744 //-------------------------------------------------------------------- 1745 1746 sal_Bool SfxViewShell::ExecKey_Impl(const KeyEvent& aKey) 1747 { 1748 if (!pImp->m_pAccExec.get()) 1749 { 1750 pImp->m_pAccExec.reset( 1751 ::svt::AcceleratorExecute::createAcceleratorHelper() ); 1752 pImp->m_pAccExec->init(::comphelper::getProcessServiceFactory(), 1753 pFrame->GetFrame().GetFrameInterface()); 1754 } 1755 1756 return pImp->m_pAccExec->execute(aKey.GetKeyCode()); 1757 } 1758 1759 //-------------------------------------------------------------------- 1760 1761 FASTBOOL SfxViewShell::KeyInput( const KeyEvent &rKeyEvent ) 1762 1763 /* [Beschreibung] 1764 1765 Diese Methode f"uhrt das KeyEvent 'rKeyEvent' "uber die an dieser 1766 SfxViewShell direkt oder indirekt (z.B. via Applikation) konfigurierten 1767 Tasten (Accelerator) aus. 1768 1769 1770 [R"uckgabewert] 1771 1772 FASTBOOL sal_True 1773 die Taste ist konfiguriert, der betreffende 1774 Handler wurde gerufen 1775 1776 FALSE 1777 die Taste ist nicht konfiguriert, es konnte 1778 also kein Handler gerufen werden 1779 1780 1781 [Querverweise] 1782 <SfxApplication::KeyInput(const KeyEvent&)> 1783 */ 1784 { 1785 return ExecKey_Impl(rKeyEvent); 1786 } 1787 1788 bool SfxViewShell::GlobalKeyInput_Impl( const KeyEvent &rKeyEvent ) 1789 { 1790 return ExecKey_Impl(rKeyEvent); 1791 } 1792 1793 //-------------------------------------------------------------------- 1794 1795 void SfxViewShell::ShowCursor( FASTBOOL /*bOn*/ ) 1796 1797 /* [Beschreibung] 1798 1799 Diese Methode mu\s von Subklassen "uberladen werden, damit vom SFx 1800 aus der Cursor ein- und ausgeschaltet werden kann. Dies geschieht 1801 z.B. bei laufendem <SfxProgress>. 1802 */ 1803 1804 { 1805 } 1806 1807 //-------------------------------------------------------------------- 1808 1809 void SfxViewShell::GotFocus() const 1810 1811 /* [Beschreibung] 1812 1813 Diese Methode mu\s vom Applikationsentwickler gerufen werden, wenn 1814 das Edit-Window den Focus erhalten hat. Der SFx hat so z.B. die 1815 M"oglichkeit, den Accelerator einzuschalten. 1816 1817 1818 [Anmerkung] 1819 1820 <StarView> liefert leider keine M"oglichkeit, solche Events 1821 'von der Seite' einzuh"angen. 1822 */ 1823 1824 { 1825 } 1826 1827 //-------------------------------------------------------------------- 1828 void SfxViewShell::ResetAllClients_Impl( SfxInPlaceClient *pIP ) 1829 { 1830 1831 SfxInPlaceClientList *pClients = GetIPClientList_Impl(sal_False); 1832 if ( !pClients ) 1833 return; 1834 1835 for ( sal_uInt16 n=0; n < pClients->Count(); n++ ) 1836 { 1837 SfxInPlaceClient* pIPClient = pClients->GetObject(n); 1838 if( pIPClient != pIP ) 1839 pIPClient->ResetObject(); 1840 } 1841 } 1842 1843 //-------------------------------------------------------------------- 1844 1845 void SfxViewShell::DisconnectAllClients() 1846 { 1847 SfxInPlaceClientList *pClients = GetIPClientList_Impl(sal_False); 1848 if ( !pClients ) 1849 return; 1850 1851 for ( sal_uInt16 n=0; n<pClients->Count(); ) 1852 // clients will remove themselves from the list 1853 delete pClients->GetObject(n); 1854 } 1855 1856 //-------------------------------------------------------------------- 1857 1858 void SfxViewShell::QueryObjAreaPixel( Rectangle& ) const 1859 { 1860 } 1861 1862 //-------------------------------------------------------------------- 1863 1864 void SfxViewShell::AdjustVisArea(const Rectangle& rRect) 1865 { 1866 DBG_ASSERT (pFrame, "Kein Frame?"); 1867 GetObjectShell()->SetVisArea( rRect ); 1868 } 1869 1870 //-------------------------------------------------------------------- 1871 1872 void SfxViewShell::VisAreaChanged(const Rectangle& /*rVisArea*/) 1873 { 1874 SfxInPlaceClientList *pClients = GetIPClientList_Impl(sal_False); 1875 if ( !pClients ) 1876 return; 1877 1878 for (sal_uInt16 n=0; n < pClients->Count(); n++) 1879 { 1880 SfxInPlaceClient* pIPClient = pClients->GetObject(n); 1881 if ( pIPClient->IsObjectInPlaceActive() ) 1882 // client is active, notify client that the VisArea might have changed 1883 pIPClient->VisAreaChanged(); 1884 } 1885 } 1886 1887 //-------------------------------------------------------------------- 1888 void SfxViewShell::CheckIPClient_Impl( SfxInPlaceClient *pIPClient, const Rectangle& rVisArea ) 1889 { 1890 if ( GetObjectShell()->IsInClose() ) 1891 return; 1892 1893 sal_Bool bAlwaysActive = 1894 ( ( pIPClient->GetObjectMiscStatus() & embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY ) != 0 ); 1895 sal_Bool bActiveWhenVisible = 1896 ( ( pIPClient->GetObjectMiscStatus() & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE ) != 0 ); 1897 1898 // this method is called when either a client is created or the "Edit/Plugins" checkbox is checked 1899 if ( !pIPClient->IsObjectInPlaceActive() && pImp->m_bPlugInsActive ) 1900 { 1901 // object in client is currently not active 1902 // check if the object wants to be activated always or when it becomes at least partially visible 1903 // TODO/LATER: maybe we should use the scaled area instead of the ObjArea?! 1904 if ( bAlwaysActive || (bActiveWhenVisible && rVisArea.IsOver(pIPClient->GetObjArea())) ) 1905 { 1906 try 1907 { 1908 pIPClient->GetObject()->changeState( embed::EmbedStates::INPLACE_ACTIVE ); 1909 } 1910 catch ( uno::Exception& ) 1911 { 1912 } 1913 } 1914 } 1915 else if (!pImp->m_bPlugInsActive) 1916 { 1917 // object in client is currently active and "Edit/Plugins" checkbox is selected 1918 // check if the object wants to be activated always or when it becomes at least partially visible 1919 // in this case selecting of the "Edit/Plugin" checkbox should let such objects deactivate 1920 if ( bAlwaysActive || bActiveWhenVisible ) 1921 pIPClient->GetObject()->changeState( embed::EmbedStates::RUNNING ); 1922 } 1923 } 1924 1925 //-------------------------------------------------------------------- 1926 1927 sal_Bool SfxViewShell::PlugInsActive() const 1928 { 1929 return pImp->m_bPlugInsActive; 1930 } 1931 1932 //-------------------------------------------------------------------- 1933 void SfxViewShell::DiscardClients_Impl() 1934 1935 /* [Beschreibung] 1936 1937 Diese Methode dient dazu, vor dem Schlie\sen eines Dokuments das 1938 Speichern der Objekte zu verhindern, wenn der Benutzer Schlie\en ohne 1939 Speichern gew"ahlt hatte. 1940 */ 1941 1942 { 1943 SfxInPlaceClientList *pClients = GetIPClientList_Impl(sal_False); 1944 if ( !pClients ) 1945 return; 1946 1947 for (sal_uInt16 n=0; n < pClients->Count(); ) 1948 delete pClients->GetObject(n); 1949 } 1950 1951 //-------------------------------------------------------------------- 1952 1953 SfxScrollingMode SfxViewShell::GetScrollingMode() const 1954 { 1955 return pImp->m_eScroll; 1956 } 1957 1958 //-------------------------------------------------------------------- 1959 1960 void SfxViewShell::SetScrollingMode( SfxScrollingMode eMode ) 1961 { 1962 pImp->m_eScroll = eMode; 1963 } 1964 1965 //-------------------------------------------------------------------- 1966 1967 SfxObjectShell* SfxViewShell::GetObjectShell() 1968 { 1969 return pFrame ? pFrame->GetObjectShell() : NULL; 1970 } 1971 1972 //-------------------------------------------------------------------- 1973 1974 Reference< XModel > SfxViewShell::GetCurrentDocument() const 1975 { 1976 Reference< XModel > xDocument; 1977 1978 const SfxObjectShell* pDocShell( const_cast< SfxViewShell* >( this )->GetObjectShell() ); 1979 OSL_ENSURE( pDocShell, "SfxViewFrame::GetCurrentDocument: no DocShell!?" ); 1980 if ( pDocShell ) 1981 xDocument = pDocShell->GetModel(); 1982 return xDocument; 1983 } 1984 1985 //-------------------------------------------------------------------- 1986 1987 void SfxViewShell::SetCurrentDocument() const 1988 { 1989 uno::Reference< frame::XModel > xDocument( GetCurrentDocument() ); 1990 if ( xDocument.is() ) 1991 SfxObjectShell::SetCurrentComponent( xDocument ); 1992 } 1993 1994 //-------------------------------------------------------------------- 1995 1996 const Size& SfxViewShell::GetMargin() const 1997 { 1998 return pImp->aMargin; 1999 } 2000 2001 //-------------------------------------------------------------------- 2002 2003 void SfxViewShell::SetMargin( const Size& rSize ) 2004 { 2005 // Der default-Margin wurde "geeicht" mit www.apple.com !! 2006 Size aMargin = rSize; 2007 if ( aMargin.Width() == -1 ) 2008 aMargin.Width() = DEFAULT_MARGIN_WIDTH; 2009 if ( aMargin.Height() == -1 ) 2010 aMargin.Height() = DEFAULT_MARGIN_HEIGHT; 2011 2012 if ( aMargin != pImp->aMargin ) 2013 { 2014 pImp->aMargin = aMargin; 2015 MarginChanged(); 2016 } 2017 } 2018 2019 //-------------------------------------------------------------------- 2020 2021 void SfxViewShell::MarginChanged() 2022 { 2023 } 2024 2025 //-------------------------------------------------------------------- 2026 2027 sal_Bool SfxViewShell::IsShowView_Impl() const 2028 { 2029 return pImp->m_bIsShowView; 2030 } 2031 2032 //-------------------------------------------------------------------- 2033 2034 SfxFrame* SfxViewShell::GetSmartSelf( SfxFrame* pSelf, SfxMedium& /*rMedium*/ ) 2035 { 2036 return pSelf; 2037 } 2038 2039 //------------------------------------------------------------------------ 2040 2041 void SfxViewShell::JumpToMark( const String& rMark ) 2042 { 2043 SfxStringItem aMarkItem( SID_JUMPTOMARK, rMark ); 2044 GetViewFrame()->GetDispatcher()->Execute( 2045 SID_JUMPTOMARK, 2046 SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD, 2047 &aMarkItem, 0L ); 2048 } 2049 2050 //------------------------------------------------------------------------ 2051 2052 SfxInPlaceClientList* SfxViewShell::GetIPClientList_Impl( sal_Bool bCreate ) const 2053 { 2054 if ( !pIPClientList && bCreate ) 2055 ( (SfxViewShell*) this )->pIPClientList = new SfxInPlaceClientList; 2056 return pIPClientList; 2057 } 2058 2059 void SfxViewShell::SetController( SfxBaseController* pController ) 2060 { 2061 pImp->m_pController = pController; 2062 pImp->m_bControllerSet = true; 2063 2064 // there should be no old listener, but if there is one, it should be disconnected 2065 if ( pImp->xClipboardListener.is() ) 2066 pImp->xClipboardListener->DisconnectViewShell(); 2067 2068 pImp->xClipboardListener = new SfxClipboardChangeListener( this, GetClipboardNotifier() ); 2069 } 2070 2071 Reference < XController > SfxViewShell::GetController() 2072 { 2073 return pImp->m_pController.get(); 2074 } 2075 2076 SfxBaseController* SfxViewShell::GetBaseController_Impl() const 2077 { 2078 return pImp->m_pController.get(); 2079 } 2080 2081 void SfxViewShell::AddContextMenuInterceptor_Impl( const REFERENCE< XCONTEXTMENUINTERCEPTOR >& xInterceptor ) 2082 { 2083 pImp->aInterceptorContainer.addInterface( xInterceptor ); 2084 } 2085 2086 void SfxViewShell::RemoveContextMenuInterceptor_Impl( const REFERENCE< XCONTEXTMENUINTERCEPTOR >& xInterceptor ) 2087 { 2088 pImp->aInterceptorContainer.removeInterface( xInterceptor ); 2089 } 2090 2091 ::cppu::OInterfaceContainerHelper& SfxViewShell::GetContextMenuInterceptors() const 2092 { 2093 return pImp->aInterceptorContainer; 2094 } 2095 2096 void Change( Menu* pMenu, SfxViewShell* pView ) 2097 { 2098 SfxDispatcher *pDisp = pView->GetViewFrame()->GetDispatcher(); 2099 sal_uInt16 nCount = pMenu->GetItemCount(); 2100 for ( sal_uInt16 nPos=0; nPos<nCount; ++nPos ) 2101 { 2102 sal_uInt16 nId = pMenu->GetItemId(nPos); 2103 String aCmd = pMenu->GetItemCommand(nId); 2104 PopupMenu* pPopup = pMenu->GetPopupMenu(nId); 2105 if ( pPopup ) 2106 { 2107 Change( pPopup, pView ); 2108 } 2109 else if ( nId < 5000 ) 2110 { 2111 if ( aCmd.CompareToAscii(".uno:", 5) == 0 ) 2112 { 2113 for (sal_uInt16 nIdx=0;;) 2114 { 2115 SfxShell *pShell=pDisp->GetShell(nIdx++); 2116 if (pShell == NULL) 2117 break; 2118 const SfxInterface *pIFace = pShell->GetInterface(); 2119 const SfxSlot* pSlot = pIFace->GetSlot( aCmd ); 2120 if ( pSlot ) 2121 { 2122 pMenu->InsertItem( pSlot->GetSlotId(), pMenu->GetItemText( nId ), pMenu->GetItemBits( nId ), nPos ); 2123 pMenu->SetItemCommand( pSlot->GetSlotId(), aCmd ); 2124 pMenu->RemoveItem( nPos+1 ); 2125 break; 2126 } 2127 } 2128 } 2129 } 2130 } 2131 } 2132 2133 2134 sal_Bool SfxViewShell::TryContextMenuInterception( Menu& rIn, const ::rtl::OUString& rMenuIdentifier, Menu*& rpOut, ui::ContextMenuExecuteEvent aEvent ) 2135 { 2136 rpOut = NULL; 2137 sal_Bool bModified = sal_False; 2138 2139 // create container from menu 2140 // #110897# 2141 // aEvent.ActionTriggerContainer = ::framework::ActionTriggerHelper::CreateActionTriggerContainerFromMenu( &rIn ); 2142 aEvent.ActionTriggerContainer = ::framework::ActionTriggerHelper::CreateActionTriggerContainerFromMenu( 2143 ::comphelper::getProcessServiceFactory(), &rIn, &rMenuIdentifier ); 2144 2145 // get selection from controller 2146 aEvent.Selection = uno::Reference < view::XSelectionSupplier > ( GetController(), uno::UNO_QUERY ); 2147 2148 // call interceptors 2149 ::cppu::OInterfaceIteratorHelper aIt( pImp->aInterceptorContainer ); 2150 while( aIt.hasMoreElements() ) 2151 { 2152 try 2153 { 2154 ui::ContextMenuInterceptorAction eAction = 2155 ((ui::XContextMenuInterceptor*)aIt.next())->notifyContextMenuExecute( aEvent ); 2156 switch ( eAction ) 2157 { 2158 case ui::ContextMenuInterceptorAction_CANCELLED : 2159 // interceptor does not want execution 2160 return sal_False; 2161 case ui::ContextMenuInterceptorAction_EXECUTE_MODIFIED : 2162 // interceptor wants his modified menu to be executed 2163 bModified = sal_True; 2164 break; 2165 case ui::ContextMenuInterceptorAction_CONTINUE_MODIFIED : 2166 // interceptor has modified menu, but allows for calling other interceptors 2167 bModified = sal_True; 2168 continue; 2169 case ui::ContextMenuInterceptorAction_IGNORED : 2170 // interceptor is indifferent 2171 continue; 2172 default: 2173 DBG_ERROR("Wrong return value of ContextMenuInterceptor!"); 2174 continue; 2175 } 2176 } 2177 catch( uno::RuntimeException& ) 2178 { 2179 aIt.remove(); 2180 } 2181 2182 break; 2183 } 2184 2185 if ( bModified ) 2186 { 2187 // container was modified, create a new window out of it 2188 rpOut = new PopupMenu; 2189 ::framework::ActionTriggerHelper::CreateMenuFromActionTriggerContainer( rpOut, aEvent.ActionTriggerContainer ); 2190 2191 Change( rpOut, this ); 2192 } 2193 2194 return sal_True; 2195 } 2196 2197 void SfxViewShell::TakeOwnerShip_Impl() 2198 { 2199 // currently there is only one reason to take OwnerShip: a hidden frame is printed 2200 // so the ViewShell will check this on EndPrint (->prnmon.cxx) 2201 pImp->m_bGotOwnership = true; 2202 } 2203 2204 void SfxViewShell::TakeFrameOwnerShip_Impl() 2205 { 2206 // currently there is only one reason to take OwnerShip: a hidden frame is printed 2207 // so the ViewShell will check this on EndPrint (->prnmon.cxx) 2208 pImp->m_bGotFrameOwnership = true; 2209 } 2210 2211 void SfxViewShell::CheckOwnerShip_Impl() 2212 { 2213 sal_Bool bSuccess = sal_False; 2214 if (pImp->m_bGotOwnership) 2215 { 2216 uno::Reference < util::XCloseable > xModel( 2217 GetObjectShell()->GetModel(), uno::UNO_QUERY ); 2218 if ( xModel.is() ) 2219 { 2220 try 2221 { 2222 // this call will destroy this object in case of success! 2223 xModel->close( sal_True ); 2224 bSuccess = sal_True; 2225 } 2226 catch ( util::CloseVetoException& ) 2227 { 2228 } 2229 } 2230 } 2231 2232 if (!bSuccess && pImp->m_bGotFrameOwnership) 2233 { 2234 // document couldn't be closed or it shouldn't, now try at least to close the frame 2235 uno::Reference < util::XCloseable > xFrame( 2236 GetViewFrame()->GetFrame().GetFrameInterface(), com::sun::star::uno::UNO_QUERY ); 2237 if ( xFrame.is() ) 2238 { 2239 try 2240 { 2241 xFrame->close( sal_True ); 2242 } 2243 catch ( util::CloseVetoException& ) 2244 { 2245 } 2246 } 2247 } 2248 } 2249 2250 long SfxViewShell::HandleNotifyEvent_Impl( NotifyEvent& rEvent ) 2251 { 2252 if (pImp->m_pController.is()) 2253 return pImp->m_pController->HandleEvent_Impl( rEvent ); 2254 return 0; 2255 } 2256 2257 sal_Bool SfxViewShell::HasKeyListeners_Impl() 2258 { 2259 return (pImp->m_pController.is()) 2260 ? pImp->m_pController->HasKeyListeners_Impl() : sal_False; 2261 } 2262 2263 sal_Bool SfxViewShell::HasMouseClickListeners_Impl() 2264 { 2265 return (pImp->m_pController.is()) 2266 ? pImp->m_pController->HasMouseClickListeners_Impl() : sal_False; 2267 } 2268 2269 void SfxViewShell::SetAdditionalPrintOptions( const com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue >& rOpts ) 2270 { 2271 pImp->aPrintOpts = rOpts; 2272 // GetObjectShell()->Broadcast( SfxPrintingHint( -3, NULL, NULL, rOpts ) ); 2273 } 2274 2275 sal_Bool SfxViewShell::Escape() 2276 { 2277 return GetViewFrame()->GetBindings().Execute( SID_TERMINATE_INPLACEACTIVATION ); 2278 } 2279 2280 Reference< view::XRenderable > SfxViewShell::GetRenderable() 2281 { 2282 Reference< view::XRenderable >xRender; 2283 SfxObjectShell* pObj = GetObjectShell(); 2284 if( pObj ) 2285 { 2286 Reference< frame::XModel > xModel( pObj->GetModel() ); 2287 if( xModel.is() ) 2288 xRender = Reference< view::XRenderable >( xModel, UNO_QUERY ); 2289 } 2290 return xRender; 2291 } 2292 2293 uno::Reference< datatransfer::clipboard::XClipboardNotifier > SfxViewShell::GetClipboardNotifier() 2294 { 2295 uno::Reference< datatransfer::clipboard::XClipboardNotifier > xClipboardNotifier; 2296 if ( GetViewFrame() ) 2297 xClipboardNotifier = uno::Reference< datatransfer::clipboard::XClipboardNotifier >( GetViewFrame()->GetWindow().GetClipboard(), uno::UNO_QUERY ); 2298 2299 return xClipboardNotifier; 2300 } 2301 2302 void SfxViewShell::AddRemoveClipboardListener( const uno::Reference < datatransfer::clipboard::XClipboardListener >& rClp, sal_Bool bAdd ) 2303 { 2304 try 2305 { 2306 if ( GetViewFrame() ) 2307 { 2308 uno::Reference< datatransfer::clipboard::XClipboard > xClipboard( GetViewFrame()->GetWindow().GetClipboard() ); 2309 if( xClipboard.is() ) 2310 { 2311 uno::Reference< datatransfer::clipboard::XClipboardNotifier > xClpbrdNtfr( xClipboard, uno::UNO_QUERY ); 2312 if( xClpbrdNtfr.is() ) 2313 { 2314 if( bAdd ) 2315 xClpbrdNtfr->addClipboardListener( rClp ); 2316 else 2317 xClpbrdNtfr->removeClipboardListener( rClp ); 2318 } 2319 } 2320 } 2321 } 2322 catch( const uno::Exception& ) 2323 { 2324 } 2325 } 2326 2327