1*bfd08df8SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*bfd08df8SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*bfd08df8SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*bfd08df8SAndrew Rist * distributed with this work for additional information 6*bfd08df8SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*bfd08df8SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*bfd08df8SAndrew Rist * "License"); you may not use this file except in compliance 9*bfd08df8SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*bfd08df8SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*bfd08df8SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*bfd08df8SAndrew Rist * software distributed under the License is distributed on an 15*bfd08df8SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*bfd08df8SAndrew Rist * KIND, either express or implied. See the License for the 17*bfd08df8SAndrew Rist * specific language governing permissions and limitations 18*bfd08df8SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*bfd08df8SAndrew Rist *************************************************************/ 21*bfd08df8SAndrew Rist 22*bfd08df8SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_embeddedobj.hxx" 26cdf0e10cSrcweir #include <com/sun/star/embed/Aspects.hpp> 27cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp> 28cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp> 29cdf0e10cSrcweir #include <com/sun/star/frame/XSynchronousFrameLoader.hpp> 30cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 31cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp> 32cdf0e10cSrcweir #include <com/sun/star/lang/XSingleComponentFactory.hpp> 33cdf0e10cSrcweir #include <com/sun/star/util/XCloseBroadcaster.hpp> 34cdf0e10cSrcweir #include <com/sun/star/util/XCloseable.hpp> 35cdf0e10cSrcweir #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACESS_HPP_ 36cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 37cdf0e10cSrcweir #endif 38cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 39cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 40cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 41cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp> 42cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp> 43cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp> 44cdf0e10cSrcweir #include <com/sun/star/frame/XFramesSupplier.hpp> 45cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchHelper.hpp> 46cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp> 47cdf0e10cSrcweir #include <com/sun/star/frame/XControllerBorder.hpp> 48cdf0e10cSrcweir #include <com/sun/star/util/XModifyBroadcaster.hpp> 49cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProviderInterception.hpp> 50cdf0e10cSrcweir #include <com/sun/star/awt/XTopWindow.hpp> 51cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp> 52cdf0e10cSrcweir #include <com/sun/star/awt/XView.hpp> 53cdf0e10cSrcweir #include <com/sun/star/awt/WindowAttribute.hpp> 54cdf0e10cSrcweir #include <com/sun/star/awt/VclWindowPeerAttribute.hpp> 55cdf0e10cSrcweir #include <com/sun/star/bridge/XBridgeSupplier2.hpp> 56cdf0e10cSrcweir #include <com/sun/star/bridge/ModelDependent.hpp> 57cdf0e10cSrcweir #include <com/sun/star/embed/XHatchWindow.hpp> 58cdf0e10cSrcweir #include <com/sun/star/embed/XHatchWindowFactory.hpp> 59cdf0e10cSrcweir #include <com/sun/star/embed/XInplaceClient.hpp> 60cdf0e10cSrcweir #include <com/sun/star/frame/XLayoutManager.hpp> 61cdf0e10cSrcweir #include <com/sun/star/frame/XMenuBarMergingAcceptor.hpp> 62cdf0e10cSrcweir #include <com/sun/star/frame/XModuleManager.hpp> 63cdf0e10cSrcweir #include <com/sun/star/ui/XDockingAreaAcceptor.hpp> 64cdf0e10cSrcweir #include <com/sun/star/ui/XUIElementSettings.hpp> 65cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UI_XCONFIGURATIONMANAGER_HPP_ 66cdf0e10cSrcweir #include <com/sun/star/ui/XUIConfigurationManager.hpp> 67cdf0e10cSrcweir #endif 68cdf0e10cSrcweir #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp> 69cdf0e10cSrcweir #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp> 70cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 71cdf0e10cSrcweir #include <com/sun/star/embed/StateChangeInProgressException.hpp> 72cdf0e10cSrcweir 73cdf0e10cSrcweir #include <com/sun/star/embed/EmbedMisc.hpp> 74cdf0e10cSrcweir #include <com/sun/star/embed/EmbedStates.hpp> 75cdf0e10cSrcweir #include <osl/diagnose.h> 76cdf0e10cSrcweir #include <rtl/process.h> 77cdf0e10cSrcweir 78cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 79cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx> 80cdf0e10cSrcweir 81cdf0e10cSrcweir #include "docholder.hxx" 82cdf0e10cSrcweir #include "commonembobj.hxx" 83cdf0e10cSrcweir #include "intercept.hxx" 84cdf0e10cSrcweir 85cdf0e10cSrcweir 86cdf0e10cSrcweir // #include <toolkit/helper/vclunohelper.hxx> 87cdf0e10cSrcweir // #include <vcl/window.hxx> 88cdf0e10cSrcweir 89cdf0e10cSrcweir #define HATCH_BORDER_WIDTH (((m_pEmbedObj->getStatus(embed::Aspects::MSOLE_CONTENT)&embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE) && \ 90cdf0e10cSrcweir m_pEmbedObj->getCurrentState()!=embed::EmbedStates::UI_ACTIVE) ? 0 : 4 ) 91cdf0e10cSrcweir 92cdf0e10cSrcweir using namespace ::com::sun::star; 93cdf0e10cSrcweir 94cdf0e10cSrcweir //=========================================================================== 95cdf0e10cSrcweir 96cdf0e10cSrcweir class IntCounterGuard { 97cdf0e10cSrcweir sal_Int32& m_nFlag; 98cdf0e10cSrcweir public: 99cdf0e10cSrcweir IntCounterGuard( sal_Int32& nFlag ) 100cdf0e10cSrcweir : m_nFlag( nFlag ) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir m_nFlag++; 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir ~IntCounterGuard() 106cdf0e10cSrcweir { 107cdf0e10cSrcweir if ( m_nFlag ) 108cdf0e10cSrcweir m_nFlag--; 109cdf0e10cSrcweir } 110cdf0e10cSrcweir }; 111cdf0e10cSrcweir 112cdf0e10cSrcweir //=========================================================================== 113cdf0e10cSrcweir 114cdf0e10cSrcweir static void InsertMenu_Impl( const uno::Reference< container::XIndexContainer >& xTargetMenu, 115cdf0e10cSrcweir sal_Int32 nTargetIndex, 116cdf0e10cSrcweir const uno::Reference< container::XIndexAccess >& xSourceMenu, 117cdf0e10cSrcweir sal_Int32 nSourceIndex, 118cdf0e10cSrcweir const ::rtl::OUString aContModuleName, 119cdf0e10cSrcweir const uno::Reference< frame::XDispatchProvider >& xSourceDisp ) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir sal_Int32 nInd = 0; 122cdf0e10cSrcweir ::rtl::OUString aModuleIdentPropName( RTL_CONSTASCII_USTRINGPARAM( "ModuleIdentifier" ) ); 123cdf0e10cSrcweir ::rtl::OUString aDispProvPropName( RTL_CONSTASCII_USTRINGPARAM( "DispatchProvider" ) ); 124cdf0e10cSrcweir sal_Bool bModuleNameSet = sal_False; 125cdf0e10cSrcweir sal_Bool bDispProvSet = sal_False; 126cdf0e10cSrcweir 127cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aSourceProps; 128cdf0e10cSrcweir xSourceMenu->getByIndex( nSourceIndex ) >>= aSourceProps; 129cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aTargetProps( aSourceProps.getLength() ); 130cdf0e10cSrcweir for ( nInd = 0; nInd < aSourceProps.getLength(); nInd++ ) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir aTargetProps[nInd].Name = aSourceProps[nInd].Name; 133cdf0e10cSrcweir if ( aContModuleName.getLength() && aTargetProps[nInd].Name.equals( aModuleIdentPropName ) ) 134cdf0e10cSrcweir { 135cdf0e10cSrcweir aTargetProps[nInd].Value <<= aContModuleName; 136cdf0e10cSrcweir bModuleNameSet = sal_True; 137cdf0e10cSrcweir } 138cdf0e10cSrcweir else if ( aTargetProps[nInd].Name.equals( aDispProvPropName ) ) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir aTargetProps[nInd].Value <<= xSourceDisp; 141cdf0e10cSrcweir bDispProvSet = sal_True; 142cdf0e10cSrcweir } 143cdf0e10cSrcweir else 144cdf0e10cSrcweir aTargetProps[nInd].Value = aSourceProps[nInd].Value; 145cdf0e10cSrcweir } 146cdf0e10cSrcweir 147cdf0e10cSrcweir if ( !bModuleNameSet && aContModuleName.getLength() ) 148cdf0e10cSrcweir { 149cdf0e10cSrcweir aTargetProps.realloc( ++nInd ); 150cdf0e10cSrcweir aTargetProps[nInd-1].Name = aModuleIdentPropName; 151cdf0e10cSrcweir aTargetProps[nInd-1].Value <<= aContModuleName; 152cdf0e10cSrcweir } 153cdf0e10cSrcweir 154cdf0e10cSrcweir if ( !bDispProvSet && xSourceDisp.is() ) 155cdf0e10cSrcweir { 156cdf0e10cSrcweir aTargetProps.realloc( ++nInd ); 157cdf0e10cSrcweir aTargetProps[nInd-1].Name = aDispProvPropName; 158cdf0e10cSrcweir aTargetProps[nInd-1].Value <<= xSourceDisp; 159cdf0e10cSrcweir } 160cdf0e10cSrcweir 161cdf0e10cSrcweir xTargetMenu->insertByIndex( nTargetIndex, uno::makeAny( aTargetProps ) ); 162cdf0e10cSrcweir } 163cdf0e10cSrcweir 164cdf0e10cSrcweir //=========================================================================== 165cdf0e10cSrcweir DocumentHolder::DocumentHolder( const uno::Reference< lang::XMultiServiceFactory >& xFactory, 166cdf0e10cSrcweir OCommonEmbeddedObject* pEmbObj ) 167cdf0e10cSrcweir : m_pEmbedObj( pEmbObj ), 168cdf0e10cSrcweir m_pInterceptor( NULL ), 169cdf0e10cSrcweir m_xFactory( xFactory ), 170cdf0e10cSrcweir m_bReadOnly( sal_False ), 171cdf0e10cSrcweir m_bWaitForClose( sal_False ), 172cdf0e10cSrcweir m_bAllowClosing( sal_False ), 173cdf0e10cSrcweir m_bDesktopTerminated( sal_False ), 174cdf0e10cSrcweir m_nNoBorderResizeReact( 0 ), 175cdf0e10cSrcweir m_nNoResizeReact( 0 ) 176cdf0e10cSrcweir { 177cdf0e10cSrcweir m_aOutplaceFrameProps.realloc( 3 ); 178cdf0e10cSrcweir beans::NamedValue aArg; 179cdf0e10cSrcweir 180cdf0e10cSrcweir aArg.Name = ::rtl::OUString::createFromAscii("TopWindow"); 181cdf0e10cSrcweir aArg.Value <<= sal_True; 182cdf0e10cSrcweir m_aOutplaceFrameProps[0] <<= aArg; 183cdf0e10cSrcweir 184cdf0e10cSrcweir aArg.Name = ::rtl::OUString::createFromAscii("MakeVisible"); 185cdf0e10cSrcweir aArg.Value <<= sal_False; 186cdf0e10cSrcweir m_aOutplaceFrameProps[1] <<= aArg; 187cdf0e10cSrcweir 188cdf0e10cSrcweir const ::rtl::OUString aServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.frame.Desktop" ) ); 189cdf0e10cSrcweir uno::Reference< frame::XDesktop > xDesktop( m_xFactory->createInstance( aServiceName ), uno::UNO_QUERY ); 190cdf0e10cSrcweir if ( xDesktop.is() ) 191cdf0e10cSrcweir { 192cdf0e10cSrcweir m_refCount++; 193cdf0e10cSrcweir try 194cdf0e10cSrcweir { 195cdf0e10cSrcweir xDesktop->addTerminateListener( this ); 196cdf0e10cSrcweir } 197cdf0e10cSrcweir catch ( uno::Exception& ) 198cdf0e10cSrcweir { 199cdf0e10cSrcweir } 200cdf0e10cSrcweir m_refCount--; 201cdf0e10cSrcweir 202cdf0e10cSrcweir aArg.Name = ::rtl::OUString::createFromAscii("ParentFrame"); 203cdf0e10cSrcweir aArg.Value <<= xDesktop; //TODO/LATER: should use parent document frame 204cdf0e10cSrcweir m_aOutplaceFrameProps[2] <<= aArg; 205cdf0e10cSrcweir } 206cdf0e10cSrcweir else 207cdf0e10cSrcweir m_aOutplaceFrameProps.realloc( 2 ); 208cdf0e10cSrcweir } 209cdf0e10cSrcweir 210cdf0e10cSrcweir //--------------------------------------------------------------------------- 211cdf0e10cSrcweir DocumentHolder::~DocumentHolder() 212cdf0e10cSrcweir { 213cdf0e10cSrcweir m_refCount++; // to allow deregistration as a listener 214cdf0e10cSrcweir 215cdf0e10cSrcweir if( m_xFrame.is() ) 216cdf0e10cSrcweir CloseFrame(); 217cdf0e10cSrcweir 218cdf0e10cSrcweir if ( m_xComponent.is() ) 219cdf0e10cSrcweir { 220cdf0e10cSrcweir try { 221cdf0e10cSrcweir CloseDocument( sal_True, sal_False ); 222cdf0e10cSrcweir } catch( uno::Exception& ) {} 223cdf0e10cSrcweir } 224cdf0e10cSrcweir 225cdf0e10cSrcweir if ( m_pInterceptor ) 226cdf0e10cSrcweir { 227cdf0e10cSrcweir m_pInterceptor->DisconnectDocHolder(); 228cdf0e10cSrcweir m_pInterceptor->release(); 229cdf0e10cSrcweir } 230cdf0e10cSrcweir 231cdf0e10cSrcweir if ( !m_bDesktopTerminated ) 232cdf0e10cSrcweir FreeOffice(); 233cdf0e10cSrcweir } 234cdf0e10cSrcweir 235cdf0e10cSrcweir //--------------------------------------------------------------------------- 236cdf0e10cSrcweir void DocumentHolder::CloseFrame() 237cdf0e10cSrcweir { 238cdf0e10cSrcweir uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( m_xFrame, uno::UNO_QUERY ); 239cdf0e10cSrcweir if ( xCloseBroadcaster.is() ) 240cdf0e10cSrcweir xCloseBroadcaster->removeCloseListener( ( util::XCloseListener* )this ); 241cdf0e10cSrcweir 242cdf0e10cSrcweir uno::Reference<util::XCloseable> xCloseable( 243cdf0e10cSrcweir m_xFrame,uno::UNO_QUERY ); 244cdf0e10cSrcweir if( xCloseable.is() ) 245cdf0e10cSrcweir try { 246cdf0e10cSrcweir xCloseable->close( sal_True ); 247cdf0e10cSrcweir } 248cdf0e10cSrcweir catch( const uno::Exception& ) { 249cdf0e10cSrcweir } 250cdf0e10cSrcweir else { 251cdf0e10cSrcweir uno::Reference<lang::XComponent> xComp( m_xFrame,uno::UNO_QUERY ); 252cdf0e10cSrcweir if( xComp.is() ) 253cdf0e10cSrcweir xComp->dispose(); 254cdf0e10cSrcweir } 255cdf0e10cSrcweir 256cdf0e10cSrcweir uno::Reference< lang::XComponent > xComp( m_xHatchWindow, uno::UNO_QUERY ); 257cdf0e10cSrcweir if ( xComp.is() ) 258cdf0e10cSrcweir xComp->dispose(); 259cdf0e10cSrcweir 260cdf0e10cSrcweir m_xHatchWindow = uno::Reference< awt::XWindow >(); 261cdf0e10cSrcweir m_xOwnWindow = uno::Reference< awt::XWindow >(); 262cdf0e10cSrcweir m_xFrame = uno::Reference< frame::XFrame >(); 263cdf0e10cSrcweir } 264cdf0e10cSrcweir 265cdf0e10cSrcweir //--------------------------------------------------------------------------- 266cdf0e10cSrcweir void DocumentHolder::FreeOffice() 267cdf0e10cSrcweir { 268cdf0e10cSrcweir const ::rtl::OUString aServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.frame.Desktop" ) ); 269cdf0e10cSrcweir uno::Reference< frame::XDesktop > xDesktop( m_xFactory->createInstance( aServiceName ), uno::UNO_QUERY ); 270cdf0e10cSrcweir if ( xDesktop.is() ) 271cdf0e10cSrcweir { 272cdf0e10cSrcweir xDesktop->removeTerminateListener( this ); 273cdf0e10cSrcweir 274cdf0e10cSrcweir // the following code is commented out since for now there is still no completely correct way to detect 275cdf0e10cSrcweir // whether the office can be terminated, so it is better to have unnecessary process running than 276cdf0e10cSrcweir // to loose any data 277cdf0e10cSrcweir 278cdf0e10cSrcweir // uno::Reference< frame::XFramesSupplier > xFramesSupplier( xDesktop, uno::UNO_QUERY ); 279cdf0e10cSrcweir // if ( xFramesSupplier.is() ) 280cdf0e10cSrcweir // { 281cdf0e10cSrcweir // uno::Reference< frame::XFrames > xFrames = xFramesSupplier->getFrames(); 282cdf0e10cSrcweir // if ( xFrames.is() && !xFrames->hasElements() ) 283cdf0e10cSrcweir // { 284cdf0e10cSrcweir // try 285cdf0e10cSrcweir // { 286cdf0e10cSrcweir // xDesktop->terminate(); 287cdf0e10cSrcweir // } 288cdf0e10cSrcweir // catch( uno::Exception & ) 289cdf0e10cSrcweir // {} 290cdf0e10cSrcweir // } 291cdf0e10cSrcweir // } 292cdf0e10cSrcweir } 293cdf0e10cSrcweir } 294cdf0e10cSrcweir 295cdf0e10cSrcweir //--------------------------------------------------------------------------- 296cdf0e10cSrcweir void DocumentHolder::CloseDocument( sal_Bool bDeliverOwnership, sal_Bool bWaitForClose ) 297cdf0e10cSrcweir { 298cdf0e10cSrcweir uno::Reference< util::XCloseBroadcaster > xBroadcaster( m_xComponent, uno::UNO_QUERY ); 299cdf0e10cSrcweir if ( xBroadcaster.is() ) 300cdf0e10cSrcweir { 301cdf0e10cSrcweir uno::Reference< document::XEventBroadcaster > xEventBroadcaster( m_xComponent, uno::UNO_QUERY ); 302cdf0e10cSrcweir if ( xEventBroadcaster.is() ) 303cdf0e10cSrcweir xEventBroadcaster->removeEventListener( ( document::XEventListener* )this ); 304cdf0e10cSrcweir else 305cdf0e10cSrcweir { 306cdf0e10cSrcweir // the object does not support document::XEventBroadcaster interface 307cdf0e10cSrcweir // use the workaround, register for modified events 308cdf0e10cSrcweir uno::Reference< util::XModifyBroadcaster > xModifyBroadcaster( m_xComponent, uno::UNO_QUERY ); 309cdf0e10cSrcweir if ( xModifyBroadcaster.is() ) 310cdf0e10cSrcweir xModifyBroadcaster->removeModifyListener( ( util::XModifyListener* )this ); 311cdf0e10cSrcweir } 312cdf0e10cSrcweir 313cdf0e10cSrcweir uno::Reference< util::XCloseable > xCloseable( xBroadcaster, uno::UNO_QUERY ); 314cdf0e10cSrcweir if ( xCloseable.is() ) 315cdf0e10cSrcweir { 316cdf0e10cSrcweir m_bAllowClosing = sal_True; 317cdf0e10cSrcweir m_bWaitForClose = bWaitForClose; 318cdf0e10cSrcweir xCloseable->close( bDeliverOwnership ); 319cdf0e10cSrcweir } 320cdf0e10cSrcweir } 321cdf0e10cSrcweir 322cdf0e10cSrcweir m_xComponent = 0; 323cdf0e10cSrcweir } 324cdf0e10cSrcweir 325cdf0e10cSrcweir //--------------------------------------------------------------------------- 326cdf0e10cSrcweir void DocumentHolder::PlaceFrame( const awt::Rectangle& aNewRect ) 327cdf0e10cSrcweir { 328cdf0e10cSrcweir OSL_ENSURE( m_xFrame.is() && m_xOwnWindow.is(), 329cdf0e10cSrcweir "The object does not have windows required for inplace mode!" ); 330cdf0e10cSrcweir 331cdf0e10cSrcweir //TODO: may need mutex locking??? 332cdf0e10cSrcweir if ( m_xFrame.is() && m_xOwnWindow.is() ) 333cdf0e10cSrcweir { 334cdf0e10cSrcweir // the frame can be replaced only in inplace mode 335cdf0e10cSrcweir frame::BorderWidths aOldWidths; 336cdf0e10cSrcweir IntCounterGuard aGuard( m_nNoBorderResizeReact ); 337cdf0e10cSrcweir 338cdf0e10cSrcweir do 339cdf0e10cSrcweir { 340cdf0e10cSrcweir aOldWidths = m_aBorderWidths; 341cdf0e10cSrcweir 342cdf0e10cSrcweir awt::Rectangle aHatchRect = AddBorderToArea( aNewRect ); 343cdf0e10cSrcweir 344cdf0e10cSrcweir ResizeWindows_Impl( aHatchRect ); 345cdf0e10cSrcweir 346cdf0e10cSrcweir } while ( aOldWidths.Left != m_aBorderWidths.Left 347cdf0e10cSrcweir || aOldWidths.Top != m_aBorderWidths.Top 348cdf0e10cSrcweir || aOldWidths.Right != m_aBorderWidths.Right 349cdf0e10cSrcweir || aOldWidths.Bottom != m_aBorderWidths.Bottom ); 350cdf0e10cSrcweir 351cdf0e10cSrcweir m_aObjRect = aNewRect; 352cdf0e10cSrcweir } 353cdf0e10cSrcweir } 354cdf0e10cSrcweir 355cdf0e10cSrcweir //--------------------------------------------------------------------------- 356cdf0e10cSrcweir void DocumentHolder::ResizeWindows_Impl( const awt::Rectangle& aHatchRect ) 357cdf0e10cSrcweir { 358cdf0e10cSrcweir OSL_ENSURE( m_xFrame.is() && m_xOwnWindow.is() /*&& m_xHatchWindow.is()*/, 359cdf0e10cSrcweir "The object does not have windows required for inplace mode!" ); 360cdf0e10cSrcweir if ( m_xHatchWindow.is() ) 361cdf0e10cSrcweir { 362cdf0e10cSrcweir m_xOwnWindow->setPosSize( HATCH_BORDER_WIDTH, 363cdf0e10cSrcweir HATCH_BORDER_WIDTH, 364cdf0e10cSrcweir aHatchRect.Width - 2*HATCH_BORDER_WIDTH, 365cdf0e10cSrcweir aHatchRect.Height - 2*HATCH_BORDER_WIDTH, 366cdf0e10cSrcweir awt::PosSize::POSSIZE ); 367cdf0e10cSrcweir 368cdf0e10cSrcweir // Window* pWindow = VCLUnoHelper::GetWindow( m_xOwnWindow ); 369cdf0e10cSrcweir 370cdf0e10cSrcweir m_xHatchWindow->setPosSize( aHatchRect.X, 371cdf0e10cSrcweir aHatchRect.Y, 372cdf0e10cSrcweir aHatchRect.Width, 373cdf0e10cSrcweir aHatchRect.Height, 374cdf0e10cSrcweir awt::PosSize::POSSIZE ); 375cdf0e10cSrcweir } 376cdf0e10cSrcweir else 377cdf0e10cSrcweir m_xOwnWindow->setPosSize( aHatchRect.X + HATCH_BORDER_WIDTH, 378cdf0e10cSrcweir aHatchRect.Y + HATCH_BORDER_WIDTH, 379cdf0e10cSrcweir aHatchRect.Width - 2*HATCH_BORDER_WIDTH, 380cdf0e10cSrcweir aHatchRect.Height - 2*HATCH_BORDER_WIDTH, 381cdf0e10cSrcweir awt::PosSize::POSSIZE ); 382cdf0e10cSrcweir } 383cdf0e10cSrcweir 384cdf0e10cSrcweir //--------------------------------------------------------------------------- 385cdf0e10cSrcweir sal_Bool DocumentHolder::SetFrameLMVisibility( const uno::Reference< frame::XFrame >& xFrame, sal_Bool bVisible ) 386cdf0e10cSrcweir { 387cdf0e10cSrcweir sal_Bool bResult = sal_False; 388cdf0e10cSrcweir 389cdf0e10cSrcweir try 390cdf0e10cSrcweir { 391cdf0e10cSrcweir uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager; 392cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPropSet( xFrame, uno::UNO_QUERY_THROW ); 393cdf0e10cSrcweir xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))) >>= xLayoutManager; 394cdf0e10cSrcweir if ( xLayoutManager.is() ) 395cdf0e10cSrcweir { 396cdf0e10cSrcweir xLayoutManager->setVisible( bVisible ); 397cdf0e10cSrcweir 398cdf0e10cSrcweir // MBA: locking is done only on the container LM, because it is not about hiding windows, it's about 399cdf0e10cSrcweir // giving up control over the component window (and stopping to listen for resize events of the container window) 400cdf0e10cSrcweir if ( bVisible ) 401cdf0e10cSrcweir xLayoutManager->unlock(); 402cdf0e10cSrcweir else 403cdf0e10cSrcweir xLayoutManager->lock(); 404cdf0e10cSrcweir 405cdf0e10cSrcweir bResult = sal_True; 406cdf0e10cSrcweir } 407cdf0e10cSrcweir } 408cdf0e10cSrcweir catch( uno::Exception& ) 409cdf0e10cSrcweir {} 410cdf0e10cSrcweir 411cdf0e10cSrcweir return bResult; 412cdf0e10cSrcweir } 413cdf0e10cSrcweir 414cdf0e10cSrcweir //--------------------------------------------------------------------------- 415cdf0e10cSrcweir sal_Bool DocumentHolder::ShowInplace( const uno::Reference< awt::XWindowPeer >& xParent, 416cdf0e10cSrcweir const awt::Rectangle& aRectangleToShow, 417cdf0e10cSrcweir const uno::Reference< frame::XDispatchProvider >& xContDisp ) 418cdf0e10cSrcweir { 419cdf0e10cSrcweir OSL_ENSURE( !m_xFrame.is(), "A frame exists already!" ); 420cdf0e10cSrcweir 421cdf0e10cSrcweir if ( !m_xFrame.is() ) 422cdf0e10cSrcweir { 423cdf0e10cSrcweir uno::Reference < frame::XModel > xModel( GetComponent(), uno::UNO_QUERY ); 424cdf0e10cSrcweir awt::Rectangle aHatchRectangle = AddBorderToArea( aRectangleToShow ); 425cdf0e10cSrcweir 426cdf0e10cSrcweir awt::Rectangle aOwnRectangle( HATCH_BORDER_WIDTH, 427cdf0e10cSrcweir HATCH_BORDER_WIDTH, 428cdf0e10cSrcweir aHatchRectangle.Width - 2*HATCH_BORDER_WIDTH, 429cdf0e10cSrcweir aHatchRectangle.Height - 2*HATCH_BORDER_WIDTH ); 430cdf0e10cSrcweir uno::Reference< awt::XWindow > xHWindow; 431cdf0e10cSrcweir uno::Reference< awt::XWindowPeer > xMyParent( xParent ); 432cdf0e10cSrcweir 433cdf0e10cSrcweir if ( xModel.is() ) 434cdf0e10cSrcweir { 435cdf0e10cSrcweir 436cdf0e10cSrcweir uno::Reference< embed::XHatchWindowFactory > xHatchFactory( 437cdf0e10cSrcweir m_xFactory->createInstance( 438cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "com.sun.star.embed.HatchWindowFactory" ) ), 439cdf0e10cSrcweir uno::UNO_QUERY ); 440cdf0e10cSrcweir 441cdf0e10cSrcweir if ( !xHatchFactory.is() ) 442cdf0e10cSrcweir throw uno::RuntimeException(); 443cdf0e10cSrcweir 444cdf0e10cSrcweir uno::Reference< embed::XHatchWindow > xHatchWindow = 445cdf0e10cSrcweir xHatchFactory->createHatchWindowInstance( xParent, 446cdf0e10cSrcweir aHatchRectangle, 447cdf0e10cSrcweir awt::Size( HATCH_BORDER_WIDTH, HATCH_BORDER_WIDTH ) ); 448cdf0e10cSrcweir 449cdf0e10cSrcweir uno::Reference< awt::XWindowPeer > xHatchWinPeer( xHatchWindow, uno::UNO_QUERY ); 450cdf0e10cSrcweir xHWindow = uno::Reference< awt::XWindow >( xHatchWinPeer, uno::UNO_QUERY ); 451cdf0e10cSrcweir if ( !xHWindow.is() ) 452cdf0e10cSrcweir throw uno::RuntimeException(); // TODO: can not create own window 453cdf0e10cSrcweir 454cdf0e10cSrcweir xHatchWindow->setController( uno::Reference< embed::XHatchWindowController >( 455cdf0e10cSrcweir static_cast< embed::XHatchWindowController* >( this ) ) ); 456cdf0e10cSrcweir 457cdf0e10cSrcweir xMyParent = xHatchWinPeer; 458cdf0e10cSrcweir } 459cdf0e10cSrcweir else 460cdf0e10cSrcweir { 461cdf0e10cSrcweir aOwnRectangle.X += aHatchRectangle.X; 462cdf0e10cSrcweir aOwnRectangle.Y += aHatchRectangle.Y; 463cdf0e10cSrcweir } 464cdf0e10cSrcweir 465cdf0e10cSrcweir awt::WindowDescriptor aOwnWinDescriptor( awt::WindowClass_TOP, 466cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("dockingwindow") ), 467cdf0e10cSrcweir xMyParent, 468cdf0e10cSrcweir 0, 469cdf0e10cSrcweir awt::Rectangle(),//aOwnRectangle, 470cdf0e10cSrcweir awt::WindowAttribute::SHOW | awt::VclWindowPeerAttribute::CLIPCHILDREN ); 471cdf0e10cSrcweir 472cdf0e10cSrcweir uno::Reference< awt::XToolkit > xToolkit( 473cdf0e10cSrcweir m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.awt.Toolkit" ) ), 474cdf0e10cSrcweir uno::UNO_QUERY ); 475cdf0e10cSrcweir if ( !xToolkit.is() ) 476cdf0e10cSrcweir throw uno::RuntimeException(); 477cdf0e10cSrcweir 478cdf0e10cSrcweir uno::Reference< awt::XWindowPeer > xNewWinPeer = xToolkit->createWindow( aOwnWinDescriptor ); 479cdf0e10cSrcweir uno::Reference< awt::XWindow > xOwnWindow( xNewWinPeer, uno::UNO_QUERY ); 480cdf0e10cSrcweir if ( !xOwnWindow.is() ) 481cdf0e10cSrcweir throw uno::RuntimeException(); // TODO: can not create own window 482cdf0e10cSrcweir 483cdf0e10cSrcweir // create a frame based on the specified window 484cdf0e10cSrcweir uno::Reference< lang::XSingleServiceFactory > xFrameFact( 485cdf0e10cSrcweir m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.TaskCreator" ) ), 486cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 487cdf0e10cSrcweir 488cdf0e10cSrcweir uno::Sequence< uno::Any > aArgs( 2 ); 489cdf0e10cSrcweir beans::NamedValue aArg; 490cdf0e10cSrcweir 491cdf0e10cSrcweir aArg.Name = ::rtl::OUString::createFromAscii("ContainerWindow"); 492cdf0e10cSrcweir aArg.Value <<= xOwnWindow; 493cdf0e10cSrcweir aArgs[0] <<= aArg; 494cdf0e10cSrcweir 495cdf0e10cSrcweir uno::Reference< frame::XFrame > xContFrame( xContDisp, uno::UNO_QUERY ); 496cdf0e10cSrcweir if ( xContFrame.is() ) 497cdf0e10cSrcweir { 498cdf0e10cSrcweir aArg.Name = ::rtl::OUString::createFromAscii("ParentFrame"); 499cdf0e10cSrcweir aArg.Value <<= xContFrame; 500cdf0e10cSrcweir aArgs[1] <<= aArg; 501cdf0e10cSrcweir } 502cdf0e10cSrcweir else 503cdf0e10cSrcweir aArgs.realloc( 1 ); 504cdf0e10cSrcweir 505cdf0e10cSrcweir // the call will create, initialize the frame, and register it in the parent 506cdf0e10cSrcweir m_xFrame.set( xFrameFact->createInstanceWithArguments( aArgs ), uno::UNO_QUERY_THROW ); 507cdf0e10cSrcweir 508cdf0e10cSrcweir m_xHatchWindow = xHWindow; 509cdf0e10cSrcweir m_xOwnWindow = xOwnWindow; 510cdf0e10cSrcweir 511cdf0e10cSrcweir if ( !SetFrameLMVisibility( m_xFrame, sal_False ) ) 512cdf0e10cSrcweir { 513cdf0e10cSrcweir OSL_ENSURE( sal_False, "Can't deactivate LayoutManager!\n" ); 514cdf0e10cSrcweir // TODO/LATER: error handling? 515cdf0e10cSrcweir } 516cdf0e10cSrcweir 517cdf0e10cSrcweir // m_bIsInplace = sal_True; TODO: ? 518cdf0e10cSrcweir 519cdf0e10cSrcweir uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( m_xFrame, uno::UNO_QUERY ); 520cdf0e10cSrcweir if ( xCloseBroadcaster.is() ) 521cdf0e10cSrcweir xCloseBroadcaster->addCloseListener( ( util::XCloseListener* )this ); 522cdf0e10cSrcweir 523cdf0e10cSrcweir // TODO: some listeners to the frame and the window ( resize for example ) 524cdf0e10cSrcweir } 525cdf0e10cSrcweir 526cdf0e10cSrcweir if ( m_xComponent.is() ) 527cdf0e10cSrcweir { 528cdf0e10cSrcweir if ( !LoadDocToFrame( sal_True ) ) 529cdf0e10cSrcweir { 530cdf0e10cSrcweir CloseFrame(); 531cdf0e10cSrcweir return sal_False; 532cdf0e10cSrcweir } 533cdf0e10cSrcweir 534cdf0e10cSrcweir uno::Reference< frame::XControllerBorder > xControllerBorder( m_xFrame->getController(), uno::UNO_QUERY ); 535cdf0e10cSrcweir if ( xControllerBorder.is() ) 536cdf0e10cSrcweir { 537cdf0e10cSrcweir m_aBorderWidths = xControllerBorder->getBorder(); 538cdf0e10cSrcweir xControllerBorder->addBorderResizeListener( (frame::XBorderResizeListener*)this ); 539cdf0e10cSrcweir } 540cdf0e10cSrcweir 541cdf0e10cSrcweir PlaceFrame( aRectangleToShow ); 542cdf0e10cSrcweir 543cdf0e10cSrcweir if ( m_xHatchWindow.is() ) 544cdf0e10cSrcweir m_xHatchWindow->setVisible( sal_True ); 545cdf0e10cSrcweir 546cdf0e10cSrcweir return sal_True; 547cdf0e10cSrcweir } 548cdf0e10cSrcweir 549cdf0e10cSrcweir return sal_False; 550cdf0e10cSrcweir } 551cdf0e10cSrcweir 552cdf0e10cSrcweir //--------------------------------------------------------------------------- 553cdf0e10cSrcweir uno::Reference< container::XIndexAccess > DocumentHolder::RetrieveOwnMenu_Impl() 554cdf0e10cSrcweir { 555cdf0e10cSrcweir uno::Reference< container::XIndexAccess > xResult; 556cdf0e10cSrcweir 557cdf0e10cSrcweir uno::Reference< ::com::sun::star::ui::XUIConfigurationManagerSupplier > xUIConfSupplier( 558cdf0e10cSrcweir m_xComponent, 559cdf0e10cSrcweir uno::UNO_QUERY ); 560cdf0e10cSrcweir uno::Reference< ::com::sun::star::ui::XUIConfigurationManager > xUIConfigManager; 561cdf0e10cSrcweir if( xUIConfSupplier.is()) 562cdf0e10cSrcweir { 563cdf0e10cSrcweir xUIConfigManager.set( 564cdf0e10cSrcweir xUIConfSupplier->getUIConfigurationManager(), 565cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 566cdf0e10cSrcweir } 567cdf0e10cSrcweir 568cdf0e10cSrcweir try 569cdf0e10cSrcweir { 570cdf0e10cSrcweir if( xUIConfigManager.is()) 571cdf0e10cSrcweir { 572cdf0e10cSrcweir xResult = xUIConfigManager->getSettings( 573cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/menubar/menubar" ) ), 574cdf0e10cSrcweir sal_False ); 575cdf0e10cSrcweir } 576cdf0e10cSrcweir } 577cdf0e10cSrcweir catch( uno::Exception ) 578cdf0e10cSrcweir {} 579cdf0e10cSrcweir 580cdf0e10cSrcweir if ( !xResult.is() ) 581cdf0e10cSrcweir { 582cdf0e10cSrcweir // no internal document configuration, use the one from the module 583cdf0e10cSrcweir uno::Reference< ::com::sun::star::frame::XModuleManager > xModuleMan( 584cdf0e10cSrcweir m_xFactory->createInstance( 585cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ModuleManager" ) ) ), 586cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 587cdf0e10cSrcweir ::rtl::OUString aModuleIdent = 588cdf0e10cSrcweir xModuleMan->identify( uno::Reference< uno::XInterface >( m_xComponent, uno::UNO_QUERY ) ); 589cdf0e10cSrcweir 590cdf0e10cSrcweir if ( aModuleIdent.getLength() ) 591cdf0e10cSrcweir { 592cdf0e10cSrcweir uno::Reference< ::com::sun::star::ui::XModuleUIConfigurationManagerSupplier > xModConfSupplier( 593cdf0e10cSrcweir m_xFactory->createInstance( ::rtl::OUString( 594cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.ModuleUIConfigurationManagerSupplier" ) ) ), 595cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 596cdf0e10cSrcweir uno::Reference< ::com::sun::star::ui::XUIConfigurationManager > xModUIConfMan( 597cdf0e10cSrcweir xModConfSupplier->getUIConfigurationManager( aModuleIdent ), 598cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 599cdf0e10cSrcweir xResult = xModUIConfMan->getSettings( 600cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/menubar/menubar" ) ), 601cdf0e10cSrcweir sal_False ); 602cdf0e10cSrcweir } 603cdf0e10cSrcweir } 604cdf0e10cSrcweir 605cdf0e10cSrcweir if ( !xResult.is() ) 606cdf0e10cSrcweir throw uno::RuntimeException(); 607cdf0e10cSrcweir 608cdf0e10cSrcweir return xResult; 609cdf0e10cSrcweir } 610cdf0e10cSrcweir 611cdf0e10cSrcweir //--------------------------------------------------------------------------- 612cdf0e10cSrcweir void DocumentHolder::FindConnectPoints( 613cdf0e10cSrcweir const uno::Reference< container::XIndexAccess >& xMenu, 614cdf0e10cSrcweir sal_Int32 nConnectPoints[2] ) 615cdf0e10cSrcweir throw ( uno::Exception ) 616cdf0e10cSrcweir { 617cdf0e10cSrcweir nConnectPoints[0] = -1; 618cdf0e10cSrcweir nConnectPoints[1] = -1; 619cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < xMenu->getCount(); nInd++ ) 620cdf0e10cSrcweir { 621cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aProps; 622cdf0e10cSrcweir xMenu->getByIndex( nInd ) >>= aProps; 623cdf0e10cSrcweir rtl::OUString aCommand; 624cdf0e10cSrcweir for ( sal_Int32 nSeqInd = 0; nSeqInd < aProps.getLength(); nSeqInd++ ) 625cdf0e10cSrcweir if ( aProps[nSeqInd].Name.equalsAscii( "CommandURL" ) ) 626cdf0e10cSrcweir { 627cdf0e10cSrcweir aProps[nSeqInd].Value >>= aCommand; 628cdf0e10cSrcweir break; 629cdf0e10cSrcweir } 630cdf0e10cSrcweir 631cdf0e10cSrcweir if ( !aCommand.getLength() ) 632cdf0e10cSrcweir throw uno::RuntimeException(); 633cdf0e10cSrcweir 634cdf0e10cSrcweir if ( aCommand.equalsAscii( ".uno:PickList" ) ) 635cdf0e10cSrcweir nConnectPoints[0] = nInd; 636cdf0e10cSrcweir else if ( aCommand.equalsAscii( ".uno:WindowList" ) ) 637cdf0e10cSrcweir nConnectPoints[1] = nInd; 638cdf0e10cSrcweir } 639cdf0e10cSrcweir } 640cdf0e10cSrcweir 641cdf0e10cSrcweir //--------------------------------------------------------------------------- 642cdf0e10cSrcweir uno::Reference< container::XIndexAccess > DocumentHolder::MergeMenuesForInplace( 643cdf0e10cSrcweir const uno::Reference< container::XIndexAccess >& xContMenu, 644cdf0e10cSrcweir const uno::Reference< frame::XDispatchProvider >& xContDisp, 645cdf0e10cSrcweir const ::rtl::OUString& aContModuleName, 646cdf0e10cSrcweir const uno::Reference< container::XIndexAccess >& xOwnMenu, 647cdf0e10cSrcweir const uno::Reference< frame::XDispatchProvider >& xOwnDisp ) 648cdf0e10cSrcweir throw ( uno::Exception ) 649cdf0e10cSrcweir { 650cdf0e10cSrcweir // TODO/LATER: use dispatch providers on merge 651cdf0e10cSrcweir 652cdf0e10cSrcweir sal_Int32 nContPoints[2]; 653cdf0e10cSrcweir sal_Int32 nOwnPoints[2]; 654cdf0e10cSrcweir 655cdf0e10cSrcweir uno::Reference< lang::XSingleComponentFactory > xIndAccessFact( xContMenu, uno::UNO_QUERY_THROW ); 656cdf0e10cSrcweir 657cdf0e10cSrcweir uno::Reference< uno::XComponentContext > xComponentContext; 658cdf0e10cSrcweir 659cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY ); 660cdf0e10cSrcweir if ( xProps.is() ) 661cdf0e10cSrcweir xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))) >>= 662cdf0e10cSrcweir xComponentContext; 663cdf0e10cSrcweir 664cdf0e10cSrcweir uno::Reference< container::XIndexContainer > xMergedMenu( 665cdf0e10cSrcweir xIndAccessFact->createInstanceWithContext( xComponentContext ), 666cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 667cdf0e10cSrcweir 668cdf0e10cSrcweir FindConnectPoints( xContMenu, nContPoints ); 669cdf0e10cSrcweir FindConnectPoints( xOwnMenu, nOwnPoints ); 670cdf0e10cSrcweir 671cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < xOwnMenu->getCount(); nInd++ ) 672cdf0e10cSrcweir { 673cdf0e10cSrcweir if ( nOwnPoints[0] == nInd ) 674cdf0e10cSrcweir { 675cdf0e10cSrcweir if ( nContPoints[0] >= 0 && nContPoints[0] < xContMenu->getCount() ) 676cdf0e10cSrcweir { 677cdf0e10cSrcweir InsertMenu_Impl( xMergedMenu, nInd, xContMenu, nContPoints[0], aContModuleName, xContDisp ); 678cdf0e10cSrcweir } 679cdf0e10cSrcweir } 680cdf0e10cSrcweir else if ( nOwnPoints[1] == nInd ) 681cdf0e10cSrcweir { 682cdf0e10cSrcweir if ( nContPoints[1] >= 0 && nContPoints[1] < xContMenu->getCount() ) 683cdf0e10cSrcweir { 684cdf0e10cSrcweir InsertMenu_Impl( xMergedMenu, nInd, xContMenu, nContPoints[1], aContModuleName, xContDisp ); 685cdf0e10cSrcweir } 686cdf0e10cSrcweir } 687cdf0e10cSrcweir else 688cdf0e10cSrcweir InsertMenu_Impl( xMergedMenu, nInd, xOwnMenu, nInd, ::rtl::OUString(), xOwnDisp ); 689cdf0e10cSrcweir } 690cdf0e10cSrcweir 691cdf0e10cSrcweir return uno::Reference< container::XIndexAccess >( xMergedMenu, uno::UNO_QUERY_THROW ); 692cdf0e10cSrcweir } 693cdf0e10cSrcweir 694cdf0e10cSrcweir //--------------------------------------------------------------------------- 695cdf0e10cSrcweir sal_Bool DocumentHolder::MergeMenues_Impl( const uno::Reference< ::com::sun::star::frame::XLayoutManager >& xOwnLM, 696cdf0e10cSrcweir const uno::Reference< ::com::sun::star::frame::XLayoutManager >& xContLM, 697cdf0e10cSrcweir const uno::Reference< frame::XDispatchProvider >& xContDisp, 698cdf0e10cSrcweir const ::rtl::OUString& aContModuleName ) 699cdf0e10cSrcweir { 700cdf0e10cSrcweir sal_Bool bMenuMerged = sal_False; 701cdf0e10cSrcweir try 702cdf0e10cSrcweir { 703cdf0e10cSrcweir uno::Reference< ::com::sun::star::ui::XUIElementSettings > xUISettings( 704cdf0e10cSrcweir xContLM->getElement( 705cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/menubar/menubar" ) ) ), 706cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 707cdf0e10cSrcweir uno::Reference< container::XIndexAccess > xContMenu = xUISettings->getSettings( sal_True ); 708cdf0e10cSrcweir if ( !xContMenu.is() ) 709cdf0e10cSrcweir throw uno::RuntimeException(); 710cdf0e10cSrcweir 711cdf0e10cSrcweir uno::Reference< container::XIndexAccess > xOwnMenu = RetrieveOwnMenu_Impl(); 712cdf0e10cSrcweir uno::Reference< frame::XDispatchProvider > xOwnDisp( m_xFrame, uno::UNO_QUERY_THROW ); 713cdf0e10cSrcweir 714cdf0e10cSrcweir uno::Reference< container::XIndexAccess > xMergedMenu = MergeMenuesForInplace( xContMenu, xContDisp, aContModuleName, xOwnMenu, xOwnDisp ); 715cdf0e10cSrcweir uno::Reference< ::com::sun::star::frame::XMenuBarMergingAcceptor > xMerge( xOwnLM, 716cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 717cdf0e10cSrcweir bMenuMerged = xMerge->setMergedMenuBar( xMergedMenu ); 718cdf0e10cSrcweir } 719cdf0e10cSrcweir catch( uno::Exception& ) 720cdf0e10cSrcweir {} 721cdf0e10cSrcweir 722cdf0e10cSrcweir return bMenuMerged; 723cdf0e10cSrcweir } 724cdf0e10cSrcweir 725cdf0e10cSrcweir sal_Bool DocumentHolder::ShowUI( const uno::Reference< ::com::sun::star::frame::XLayoutManager >& xContainerLM, 726cdf0e10cSrcweir const uno::Reference< frame::XDispatchProvider >& xContainerDP, 727cdf0e10cSrcweir const ::rtl::OUString& aContModuleName ) 728cdf0e10cSrcweir { 729cdf0e10cSrcweir sal_Bool bResult = sal_False; 730cdf0e10cSrcweir if ( xContainerLM.is() ) 731cdf0e10cSrcweir { 732cdf0e10cSrcweir // the LM of the embedded frame and its current DockingAreaAcceptor 733cdf0e10cSrcweir uno::Reference< ::com::sun::star::frame::XLayoutManager > xOwnLM; 734cdf0e10cSrcweir uno::Reference< ::com::sun::star::ui::XDockingAreaAcceptor > xDocAreaAcc; 735cdf0e10cSrcweir 736cdf0e10cSrcweir try 737cdf0e10cSrcweir { 738cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPropSet( m_xFrame, uno::UNO_QUERY_THROW ); 739cdf0e10cSrcweir xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))) >>= xOwnLM; 740cdf0e10cSrcweir xDocAreaAcc = xContainerLM->getDockingAreaAcceptor(); 741cdf0e10cSrcweir } 742cdf0e10cSrcweir catch( uno::Exception& ){} 743cdf0e10cSrcweir 744cdf0e10cSrcweir // make sure that lock state of LM is correct even if an exception is thrown in between 745cdf0e10cSrcweir sal_Bool bUnlock = sal_False; 746cdf0e10cSrcweir sal_Bool bLock = sal_False; 747cdf0e10cSrcweir if ( xOwnLM.is() && xDocAreaAcc.is() ) 748cdf0e10cSrcweir { 749cdf0e10cSrcweir try 750cdf0e10cSrcweir { 751cdf0e10cSrcweir // take over the control over the containers window 752cdf0e10cSrcweir // as long as the LM is invisible and locked an empty tool space will be used on resizing 753cdf0e10cSrcweir xOwnLM->setDockingAreaAcceptor( xDocAreaAcc ); 754cdf0e10cSrcweir 755cdf0e10cSrcweir // try to merge menues; don't do anything else if it fails 756cdf0e10cSrcweir if ( MergeMenues_Impl( xOwnLM, xContainerLM, xContainerDP, aContModuleName ) ) 757cdf0e10cSrcweir { 758cdf0e10cSrcweir // make sure that the container LM does not control the size of the containers window anymore 759cdf0e10cSrcweir // this must be done after merging menues as we won't get the container menu otherwise 760cdf0e10cSrcweir xContainerLM->setDockingAreaAcceptor( uno::Reference < ui::XDockingAreaAcceptor >() ); 761cdf0e10cSrcweir 762cdf0e10cSrcweir // prevent further changes at this LM 763cdf0e10cSrcweir xContainerLM->setVisible( sal_False ); 764cdf0e10cSrcweir xContainerLM->lock(); 765cdf0e10cSrcweir bUnlock = sal_True; 766cdf0e10cSrcweir 767cdf0e10cSrcweir // by unlocking the LM each layout change will now resize the containers window; pending layouts will be processed now 768cdf0e10cSrcweir xOwnLM->setVisible( sal_True ); 769cdf0e10cSrcweir 770cdf0e10cSrcweir uno::Reference< frame::XFramesSupplier > xSupp( m_xFrame->getCreator(), uno::UNO_QUERY ); 771cdf0e10cSrcweir if ( xSupp.is() ) 772cdf0e10cSrcweir xSupp->setActiveFrame( m_xFrame ); 773cdf0e10cSrcweir 774cdf0e10cSrcweir xOwnLM->unlock(); 775cdf0e10cSrcweir bLock = sal_True; 776cdf0e10cSrcweir bResult = sal_True; 777cdf0e10cSrcweir 778cdf0e10cSrcweir // TODO/LATER: The following action should be done only if the window is not hidden 779cdf0e10cSrcweir // otherwise the activation must fail, unfortunatelly currently it is not possible 780cdf0e10cSrcweir // to detect whether the window is hidden using UNO API 781cdf0e10cSrcweir m_xOwnWindow->setFocus(); 782cdf0e10cSrcweir } 783cdf0e10cSrcweir } 784cdf0e10cSrcweir catch( uno::Exception& ) 785cdf0e10cSrcweir { 786cdf0e10cSrcweir // activation failed; reestablish old state 787cdf0e10cSrcweir try 788cdf0e10cSrcweir { 789cdf0e10cSrcweir uno::Reference< frame::XFramesSupplier > xSupp( m_xFrame->getCreator(), uno::UNO_QUERY ); 790cdf0e10cSrcweir if ( xSupp.is() ) 791cdf0e10cSrcweir xSupp->setActiveFrame( 0 ); 792cdf0e10cSrcweir 793cdf0e10cSrcweir // remove control about containers window from own LM 794cdf0e10cSrcweir if ( bLock ) 795cdf0e10cSrcweir xOwnLM->lock(); 796cdf0e10cSrcweir xOwnLM->setVisible( sal_False ); 797cdf0e10cSrcweir xOwnLM->setDockingAreaAcceptor( uno::Reference< ::com::sun::star::ui::XDockingAreaAcceptor >() ); 798cdf0e10cSrcweir 799cdf0e10cSrcweir // unmerge menu 800cdf0e10cSrcweir uno::Reference< ::com::sun::star::frame::XMenuBarMergingAcceptor > xMerge( xOwnLM, uno::UNO_QUERY_THROW ); 801cdf0e10cSrcweir xMerge->removeMergedMenuBar(); 802cdf0e10cSrcweir } 803cdf0e10cSrcweir catch( uno::Exception& ) {} 804cdf0e10cSrcweir 805cdf0e10cSrcweir try 806cdf0e10cSrcweir { 807cdf0e10cSrcweir // reestablish control of containers window 808cdf0e10cSrcweir xContainerLM->setDockingAreaAcceptor( xDocAreaAcc ); 809cdf0e10cSrcweir xContainerLM->setVisible( sal_True ); 810cdf0e10cSrcweir if ( bUnlock ) 811cdf0e10cSrcweir xContainerLM->unlock(); 812cdf0e10cSrcweir } 813cdf0e10cSrcweir catch( uno::Exception& ) {} 814cdf0e10cSrcweir } 815cdf0e10cSrcweir } 816cdf0e10cSrcweir } 817cdf0e10cSrcweir 818cdf0e10cSrcweir return bResult; 819cdf0e10cSrcweir } 820cdf0e10cSrcweir 821cdf0e10cSrcweir //--------------------------------------------------------------------------- 822cdf0e10cSrcweir sal_Bool DocumentHolder::HideUI( const uno::Reference< ::com::sun::star::frame::XLayoutManager >& xContainerLM ) 823cdf0e10cSrcweir { 824cdf0e10cSrcweir sal_Bool bResult = sal_False; 825cdf0e10cSrcweir 826cdf0e10cSrcweir if ( xContainerLM.is() ) 827cdf0e10cSrcweir { 828cdf0e10cSrcweir uno::Reference< ::com::sun::star::frame::XLayoutManager > xOwnLM; 829cdf0e10cSrcweir 830cdf0e10cSrcweir try { 831cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPropSet( m_xFrame, uno::UNO_QUERY_THROW ); 832cdf0e10cSrcweir xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))) >>= xOwnLM; 833cdf0e10cSrcweir } catch( uno::Exception& ) 834cdf0e10cSrcweir {} 835cdf0e10cSrcweir 836cdf0e10cSrcweir if ( xOwnLM.is() ) 837cdf0e10cSrcweir { 838cdf0e10cSrcweir try { 839cdf0e10cSrcweir uno::Reference< frame::XFramesSupplier > xSupp( m_xFrame->getCreator(), uno::UNO_QUERY ); 840cdf0e10cSrcweir if ( xSupp.is() ) 841cdf0e10cSrcweir xSupp->setActiveFrame( 0 ); 842cdf0e10cSrcweir 843cdf0e10cSrcweir uno::Reference< ::com::sun::star::ui::XDockingAreaAcceptor > xDocAreaAcc = xOwnLM->getDockingAreaAcceptor(); 844cdf0e10cSrcweir 845cdf0e10cSrcweir xOwnLM->setDockingAreaAcceptor( uno::Reference < ui::XDockingAreaAcceptor >() ); 846cdf0e10cSrcweir xOwnLM->lock(); 847cdf0e10cSrcweir xOwnLM->setVisible( sal_False ); 848cdf0e10cSrcweir 849cdf0e10cSrcweir uno::Reference< ::com::sun::star::frame::XMenuBarMergingAcceptor > xMerge( xOwnLM, uno::UNO_QUERY_THROW ); 850cdf0e10cSrcweir xMerge->removeMergedMenuBar(); 851cdf0e10cSrcweir 852cdf0e10cSrcweir xContainerLM->setDockingAreaAcceptor( xDocAreaAcc ); 853cdf0e10cSrcweir xContainerLM->setVisible( sal_True ); 854cdf0e10cSrcweir xContainerLM->unlock(); 855cdf0e10cSrcweir 856cdf0e10cSrcweir xContainerLM->doLayout(); 857cdf0e10cSrcweir bResult = sal_True; 858cdf0e10cSrcweir } 859cdf0e10cSrcweir catch( uno::Exception& ) 860cdf0e10cSrcweir { 861cdf0e10cSrcweir SetFrameLMVisibility( m_xFrame, sal_True ); 862cdf0e10cSrcweir } 863cdf0e10cSrcweir } 864cdf0e10cSrcweir } 865cdf0e10cSrcweir 866cdf0e10cSrcweir return bResult; 867cdf0e10cSrcweir } 868cdf0e10cSrcweir 869cdf0e10cSrcweir //--------------------------------------------------------------------------- 870cdf0e10cSrcweir uno::Reference< frame::XFrame > DocumentHolder::GetDocFrame() 871cdf0e10cSrcweir { 872cdf0e10cSrcweir // the frame for outplace activation 873cdf0e10cSrcweir if ( !m_xFrame.is() ) 874cdf0e10cSrcweir { 875cdf0e10cSrcweir uno::Reference< lang::XSingleServiceFactory > xFrameFact( 876cdf0e10cSrcweir m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.TaskCreator" ) ), 877cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 878cdf0e10cSrcweir 879cdf0e10cSrcweir m_xFrame.set(xFrameFact->createInstanceWithArguments( m_aOutplaceFrameProps ), uno::UNO_QUERY_THROW); 880cdf0e10cSrcweir 881cdf0e10cSrcweir uno::Reference< frame::XDispatchProviderInterception > xInterception( m_xFrame, uno::UNO_QUERY ); 882cdf0e10cSrcweir if ( xInterception.is() ) 883cdf0e10cSrcweir { 884cdf0e10cSrcweir if ( m_pInterceptor ) 885cdf0e10cSrcweir { 886cdf0e10cSrcweir m_pInterceptor->DisconnectDocHolder(); 887cdf0e10cSrcweir m_pInterceptor->release(); 888cdf0e10cSrcweir m_pInterceptor = NULL; 889cdf0e10cSrcweir } 890cdf0e10cSrcweir 891cdf0e10cSrcweir m_pInterceptor = new Interceptor( this ); 892cdf0e10cSrcweir m_pInterceptor->acquire(); 893cdf0e10cSrcweir 894cdf0e10cSrcweir // register interceptor from outside 895cdf0e10cSrcweir if ( m_xOutplaceInterceptor.is() ) 896cdf0e10cSrcweir xInterception->registerDispatchProviderInterceptor( m_xOutplaceInterceptor ); 897cdf0e10cSrcweir 898cdf0e10cSrcweir xInterception->registerDispatchProviderInterceptor( m_pInterceptor ); 899cdf0e10cSrcweir } 900cdf0e10cSrcweir 901cdf0e10cSrcweir uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( m_xFrame, uno::UNO_QUERY ); 902cdf0e10cSrcweir if ( xCloseBroadcaster.is() ) 903cdf0e10cSrcweir xCloseBroadcaster->addCloseListener( ( util::XCloseListener* )this ); 904cdf0e10cSrcweir } 905cdf0e10cSrcweir 906cdf0e10cSrcweir if ( m_xComponent.is() ) 907cdf0e10cSrcweir { 908cdf0e10cSrcweir uno::Reference< ::com::sun::star::frame::XLayoutManager > xOwnLM; 909cdf0e10cSrcweir try { 910cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPropSet( m_xFrame, uno::UNO_QUERY_THROW ); 911cdf0e10cSrcweir xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))) >>= xOwnLM; 912cdf0e10cSrcweir } catch( uno::Exception& ) 913cdf0e10cSrcweir {} 914cdf0e10cSrcweir 915cdf0e10cSrcweir if ( xOwnLM.is() ) 916cdf0e10cSrcweir xOwnLM->lock(); 917cdf0e10cSrcweir 918cdf0e10cSrcweir // TODO/LATER: get it for the real aspect 919cdf0e10cSrcweir awt::Size aSize; 920cdf0e10cSrcweir GetExtent( embed::Aspects::MSOLE_CONTENT, &aSize ); 921cdf0e10cSrcweir LoadDocToFrame(sal_False); 922cdf0e10cSrcweir 923cdf0e10cSrcweir if ( xOwnLM.is() ) 924cdf0e10cSrcweir { 925cdf0e10cSrcweir xOwnLM->unlock(); 926cdf0e10cSrcweir xOwnLM->lock(); 927cdf0e10cSrcweir } 928cdf0e10cSrcweir 929cdf0e10cSrcweir SetExtent( embed::Aspects::MSOLE_CONTENT, aSize ); 930cdf0e10cSrcweir 931cdf0e10cSrcweir if ( xOwnLM.is() ) 932cdf0e10cSrcweir xOwnLM->unlock(); 933cdf0e10cSrcweir } 934cdf0e10cSrcweir 935cdf0e10cSrcweir try 936cdf0e10cSrcweir { 937cdf0e10cSrcweir uno::Reference< awt::XWindow > xHWindow = m_xFrame->getContainerWindow(); 938cdf0e10cSrcweir 939cdf0e10cSrcweir if( xHWindow.is() ) 940cdf0e10cSrcweir { 941cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xMonProps( m_xFactory->createInstance(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.DisplayAccess" ) ) ), uno::UNO_QUERY_THROW ); 942cdf0e10cSrcweir const rtl::OUString sPropName( RTL_CONSTASCII_USTRINGPARAM( "DefaultDisplay" ) ); 943cdf0e10cSrcweir sal_Int32 nDisplay = 0; 944cdf0e10cSrcweir xMonProps->getPropertyValue( sPropName ) >>= nDisplay; 945cdf0e10cSrcweir 946cdf0e10cSrcweir uno::Reference< container::XIndexAccess > xMultiMon( xMonProps, uno::UNO_QUERY_THROW ); 947cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xMonitor( xMultiMon->getByIndex( nDisplay ), uno::UNO_QUERY_THROW ); 948cdf0e10cSrcweir awt::Rectangle aWorkRect; 949cdf0e10cSrcweir xMonitor->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "WorkArea" ) ) ) >>= aWorkRect; 950cdf0e10cSrcweir awt::Rectangle aWindowRect = xHWindow->getPosSize(); 951cdf0e10cSrcweir 952cdf0e10cSrcweir if (( aWindowRect.Width < aWorkRect.Width) && ( aWindowRect.Height < aWorkRect.Height )) 953cdf0e10cSrcweir { 954cdf0e10cSrcweir int OffsetX = ( aWorkRect.Width - aWindowRect.Width ) / 2 + aWorkRect.X; 955cdf0e10cSrcweir int OffsetY = ( aWorkRect.Height - aWindowRect.Height ) /2 + aWorkRect.Y; 956cdf0e10cSrcweir xHWindow->setPosSize( OffsetX, OffsetY, aWindowRect.Width, aWindowRect.Height, awt::PosSize::POS ); 957cdf0e10cSrcweir } 958cdf0e10cSrcweir else 959cdf0e10cSrcweir { 960cdf0e10cSrcweir xHWindow->setPosSize( aWorkRect.X, aWorkRect.Y, aWorkRect.Width, aWorkRect.Height, awt::PosSize::POSSIZE ); 961cdf0e10cSrcweir } 962cdf0e10cSrcweir 963cdf0e10cSrcweir xHWindow->setVisible( sal_True ); 964cdf0e10cSrcweir } 965cdf0e10cSrcweir } 966cdf0e10cSrcweir catch ( uno::Exception& ) 967cdf0e10cSrcweir { 968cdf0e10cSrcweir } 969cdf0e10cSrcweir 970cdf0e10cSrcweir return m_xFrame; 971cdf0e10cSrcweir } 972cdf0e10cSrcweir 973cdf0e10cSrcweir //--------------------------------------------------------------------------- 974cdf0e10cSrcweir void DocumentHolder::SetComponent( const uno::Reference< util::XCloseable >& xDoc, sal_Bool bReadOnly ) 975cdf0e10cSrcweir { 976cdf0e10cSrcweir if ( m_xComponent.is() ) 977cdf0e10cSrcweir { 978cdf0e10cSrcweir // May be should be improved 979cdf0e10cSrcweir try { 980cdf0e10cSrcweir CloseDocument( sal_True, sal_False ); 981cdf0e10cSrcweir } catch( uno::Exception& ) 982cdf0e10cSrcweir {} 983cdf0e10cSrcweir } 984cdf0e10cSrcweir 985cdf0e10cSrcweir m_xComponent = xDoc; 986cdf0e10cSrcweir // done outside currently uno::Reference < container::XChild > xChild( m_xComponent, uno::UNO_QUERY ); 987cdf0e10cSrcweir // done outside currently if ( xChild.is() && m_pEmbedObj ) 988cdf0e10cSrcweir // done outside currently xChild->setParent( m_pEmbedObj->getParent() ); 989cdf0e10cSrcweir 990cdf0e10cSrcweir m_bReadOnly = bReadOnly; 991cdf0e10cSrcweir m_bAllowClosing = sal_False; 992cdf0e10cSrcweir 993cdf0e10cSrcweir uno::Reference< util::XCloseBroadcaster > xBroadcaster( m_xComponent, uno::UNO_QUERY ); 994cdf0e10cSrcweir if ( xBroadcaster.is() ) 995cdf0e10cSrcweir xBroadcaster->addCloseListener( ( util::XCloseListener* )this ); 996cdf0e10cSrcweir 997cdf0e10cSrcweir uno::Reference< document::XEventBroadcaster > xEventBroadcaster( m_xComponent, uno::UNO_QUERY ); 998cdf0e10cSrcweir if ( xEventBroadcaster.is() ) 999cdf0e10cSrcweir xEventBroadcaster->addEventListener( ( document::XEventListener* )this ); 1000cdf0e10cSrcweir else 1001cdf0e10cSrcweir { 1002cdf0e10cSrcweir // the object does not support document::XEventBroadcaster interface 1003cdf0e10cSrcweir // use the workaround, register for modified events 1004cdf0e10cSrcweir uno::Reference< util::XModifyBroadcaster > xModifyBroadcaster( m_xComponent, uno::UNO_QUERY ); 1005cdf0e10cSrcweir if ( xModifyBroadcaster.is() ) 1006cdf0e10cSrcweir xModifyBroadcaster->addModifyListener( ( util::XModifyListener* )this ); 1007cdf0e10cSrcweir } 1008cdf0e10cSrcweir 1009cdf0e10cSrcweir if ( m_xFrame.is() ) 1010cdf0e10cSrcweir LoadDocToFrame(sal_False); 1011cdf0e10cSrcweir } 1012cdf0e10cSrcweir 1013cdf0e10cSrcweir //--------------------------------------------------------------------------- 1014cdf0e10cSrcweir sal_Bool DocumentHolder::LoadDocToFrame( sal_Bool bInPlace ) 1015cdf0e10cSrcweir { 1016cdf0e10cSrcweir if ( m_xFrame.is() && m_xComponent.is() ) 1017cdf0e10cSrcweir { 1018cdf0e10cSrcweir uno::Reference < frame::XModel > xDoc( m_xComponent, uno::UNO_QUERY ); 1019cdf0e10cSrcweir if ( xDoc.is() ) 1020cdf0e10cSrcweir { 1021cdf0e10cSrcweir // load new document in to the frame 1022cdf0e10cSrcweir uno::Reference< frame::XComponentLoader > xComponentLoader( m_xFrame, uno::UNO_QUERY_THROW ); 1023cdf0e10cSrcweir 1024cdf0e10cSrcweir ::comphelper::NamedValueCollection aArgs; 1025cdf0e10cSrcweir aArgs.put( "Model", m_xComponent ); 1026cdf0e10cSrcweir aArgs.put( "ReadOnly", m_bReadOnly ); 1027cdf0e10cSrcweir //aArgs.put( "Hidden", sal_True ); 1028cdf0e10cSrcweir if ( bInPlace ) 1029cdf0e10cSrcweir aArgs.put( "PluginMode", sal_Int16(1) ); 1030cdf0e10cSrcweir ::rtl::OUString sUrl; 1031cdf0e10cSrcweir uno::Reference< lang::XServiceInfo> xServiceInfo(xDoc,uno::UNO_QUERY); 1032cdf0e10cSrcweir if ( xServiceInfo.is() 1033cdf0e10cSrcweir && xServiceInfo->supportsService(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.ReportDefinition"))) ) 1034cdf0e10cSrcweir { 1035cdf0e10cSrcweir sUrl = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".component:DB/ReportDesign")); 1036cdf0e10cSrcweir } 1037cdf0e10cSrcweir else if( xServiceInfo.is() 1038cdf0e10cSrcweir && xServiceInfo->supportsService( ::rtl::OUString::createFromAscii("com.sun.star.chart2.ChartDocument")) ) 1039cdf0e10cSrcweir sUrl = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/schart")); 1040cdf0e10cSrcweir else 1041cdf0e10cSrcweir sUrl = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:object")); 1042cdf0e10cSrcweir 1043cdf0e10cSrcweir xComponentLoader->loadComponentFromURL( sUrl, 1044cdf0e10cSrcweir rtl::OUString::createFromAscii( "_self" ), 1045cdf0e10cSrcweir 0, 1046cdf0e10cSrcweir aArgs.getPropertyValues() ); 1047cdf0e10cSrcweir 1048cdf0e10cSrcweir return sal_True; 1049cdf0e10cSrcweir } 1050cdf0e10cSrcweir else 1051cdf0e10cSrcweir { 1052cdf0e10cSrcweir uno::Reference < frame::XSynchronousFrameLoader > xLoader( m_xComponent, uno::UNO_QUERY ); 1053cdf0e10cSrcweir if ( xLoader.is() ) 1054cdf0e10cSrcweir return xLoader->load( uno::Sequence < beans::PropertyValue >(), m_xFrame ); 1055cdf0e10cSrcweir else 1056cdf0e10cSrcweir return sal_False; 1057cdf0e10cSrcweir } 1058cdf0e10cSrcweir } 1059cdf0e10cSrcweir 1060cdf0e10cSrcweir return sal_True; 1061cdf0e10cSrcweir } 1062cdf0e10cSrcweir 1063cdf0e10cSrcweir //--------------------------------------------------------------------------- 1064cdf0e10cSrcweir void DocumentHolder::Show() 1065cdf0e10cSrcweir { 1066cdf0e10cSrcweir if( m_xFrame.is() ) 1067cdf0e10cSrcweir { 1068cdf0e10cSrcweir m_xFrame->activate(); 1069cdf0e10cSrcweir uno::Reference<awt::XTopWindow> xTopWindow( m_xFrame->getContainerWindow(), uno::UNO_QUERY ); 1070cdf0e10cSrcweir if( xTopWindow.is() ) 1071cdf0e10cSrcweir xTopWindow->toFront(); 1072cdf0e10cSrcweir } 1073cdf0e10cSrcweir else 1074cdf0e10cSrcweir GetDocFrame(); 1075cdf0e10cSrcweir } 1076cdf0e10cSrcweir 1077cdf0e10cSrcweir //--------------------------------------------------------------------------- 1078cdf0e10cSrcweir sal_Bool DocumentHolder::SetExtent( sal_Int64 nAspect, const awt::Size& aSize ) 1079cdf0e10cSrcweir { 1080cdf0e10cSrcweir uno::Reference< embed::XVisualObject > xDocVis( m_xComponent, uno::UNO_QUERY ); 1081cdf0e10cSrcweir if ( xDocVis.is() ) 1082cdf0e10cSrcweir { 1083cdf0e10cSrcweir try 1084cdf0e10cSrcweir { 1085cdf0e10cSrcweir xDocVis->setVisualAreaSize( nAspect, aSize ); 1086cdf0e10cSrcweir return sal_True; 1087cdf0e10cSrcweir } 1088cdf0e10cSrcweir catch( uno::Exception& ) 1089cdf0e10cSrcweir { 1090cdf0e10cSrcweir // TODO: Error handling 1091cdf0e10cSrcweir } 1092cdf0e10cSrcweir } 1093cdf0e10cSrcweir 1094cdf0e10cSrcweir return sal_False; 1095cdf0e10cSrcweir } 1096cdf0e10cSrcweir 1097cdf0e10cSrcweir //--------------------------------------------------------------------------- 1098cdf0e10cSrcweir sal_Bool DocumentHolder::GetExtent( sal_Int64 nAspect, awt::Size *pSize ) 1099cdf0e10cSrcweir { 1100cdf0e10cSrcweir uno::Reference< embed::XVisualObject > xDocVis( m_xComponent, uno::UNO_QUERY ); 1101cdf0e10cSrcweir if ( pSize && xDocVis.is() ) 1102cdf0e10cSrcweir { 1103cdf0e10cSrcweir try 1104cdf0e10cSrcweir { 1105cdf0e10cSrcweir *pSize = xDocVis->getVisualAreaSize( nAspect ); 1106cdf0e10cSrcweir return sal_True; 1107cdf0e10cSrcweir } 1108cdf0e10cSrcweir catch( uno::Exception& ) 1109cdf0e10cSrcweir { 1110cdf0e10cSrcweir // TODO: Error handling 1111cdf0e10cSrcweir } 1112cdf0e10cSrcweir } 1113cdf0e10cSrcweir 1114cdf0e10cSrcweir return sal_False; 1115cdf0e10cSrcweir } 1116cdf0e10cSrcweir 1117cdf0e10cSrcweir //--------------------------------------------------------------------------- 1118cdf0e10cSrcweir sal_Int32 DocumentHolder::GetMapUnit( sal_Int64 nAspect ) 1119cdf0e10cSrcweir { 1120cdf0e10cSrcweir uno::Reference< embed::XVisualObject > xDocVis( m_xComponent, uno::UNO_QUERY ); 1121cdf0e10cSrcweir if ( xDocVis.is() ) 1122cdf0e10cSrcweir { 1123cdf0e10cSrcweir try 1124cdf0e10cSrcweir { 1125cdf0e10cSrcweir return xDocVis->getMapUnit( nAspect ); 1126cdf0e10cSrcweir } 1127cdf0e10cSrcweir catch( uno::Exception& ) 1128cdf0e10cSrcweir { 1129cdf0e10cSrcweir // TODO: Error handling 1130cdf0e10cSrcweir } 1131cdf0e10cSrcweir } 1132cdf0e10cSrcweir 1133cdf0e10cSrcweir return 0; 1134cdf0e10cSrcweir } 1135cdf0e10cSrcweir 1136cdf0e10cSrcweir //--------------------------------------------------------------------------- 1137cdf0e10cSrcweir awt::Rectangle DocumentHolder::CalculateBorderedArea( const awt::Rectangle& aRect ) 1138cdf0e10cSrcweir { 1139cdf0e10cSrcweir return awt::Rectangle( aRect.X + m_aBorderWidths.Left + HATCH_BORDER_WIDTH, 1140cdf0e10cSrcweir aRect.Y + m_aBorderWidths.Top + HATCH_BORDER_WIDTH, 1141cdf0e10cSrcweir aRect.Width - m_aBorderWidths.Left - m_aBorderWidths.Right - 2*HATCH_BORDER_WIDTH, 1142cdf0e10cSrcweir aRect.Height - m_aBorderWidths.Top - m_aBorderWidths.Bottom - 2*HATCH_BORDER_WIDTH ); 1143cdf0e10cSrcweir } 1144cdf0e10cSrcweir 1145cdf0e10cSrcweir //--------------------------------------------------------------------------- 1146cdf0e10cSrcweir awt::Rectangle DocumentHolder::AddBorderToArea( const awt::Rectangle& aRect ) 1147cdf0e10cSrcweir { 1148cdf0e10cSrcweir return awt::Rectangle( aRect.X - m_aBorderWidths.Left - HATCH_BORDER_WIDTH, 1149cdf0e10cSrcweir aRect.Y - m_aBorderWidths.Top - HATCH_BORDER_WIDTH, 1150cdf0e10cSrcweir aRect.Width + m_aBorderWidths.Left + m_aBorderWidths.Right + 2*HATCH_BORDER_WIDTH, 1151cdf0e10cSrcweir aRect.Height + m_aBorderWidths.Top + m_aBorderWidths.Bottom + 2*HATCH_BORDER_WIDTH ); 1152cdf0e10cSrcweir } 1153cdf0e10cSrcweir 1154cdf0e10cSrcweir //--------------------------------------------------------------------------- 1155cdf0e10cSrcweir void SAL_CALL DocumentHolder::disposing( const com::sun::star::lang::EventObject& aSource ) 1156cdf0e10cSrcweir throw (uno::RuntimeException) 1157cdf0e10cSrcweir { 1158cdf0e10cSrcweir if ( m_xComponent.is() && m_xComponent == aSource.Source ) 1159cdf0e10cSrcweir { 1160cdf0e10cSrcweir m_xComponent = 0; 1161cdf0e10cSrcweir if ( m_bWaitForClose ) 1162cdf0e10cSrcweir { 1163cdf0e10cSrcweir m_bWaitForClose = sal_False; 1164cdf0e10cSrcweir FreeOffice(); 1165cdf0e10cSrcweir } 1166cdf0e10cSrcweir } 1167cdf0e10cSrcweir 1168cdf0e10cSrcweir if( m_xFrame.is() && m_xFrame == aSource.Source ) 1169cdf0e10cSrcweir { 1170cdf0e10cSrcweir m_xHatchWindow = uno::Reference< awt::XWindow >(); 1171cdf0e10cSrcweir m_xOwnWindow = uno::Reference< awt::XWindow >(); 1172cdf0e10cSrcweir m_xFrame = uno::Reference< frame::XFrame >(); 1173cdf0e10cSrcweir } 1174cdf0e10cSrcweir } 1175cdf0e10cSrcweir 1176cdf0e10cSrcweir 1177cdf0e10cSrcweir //--------------------------------------------------------------------------- 1178cdf0e10cSrcweir void SAL_CALL DocumentHolder::queryClosing( const lang::EventObject& aSource, sal_Bool /*bGetsOwnership*/ ) 1179cdf0e10cSrcweir throw (util::CloseVetoException, uno::RuntimeException) 1180cdf0e10cSrcweir { 1181cdf0e10cSrcweir if ( m_xComponent.is() && m_xComponent == aSource.Source && !m_bAllowClosing ) 1182cdf0e10cSrcweir throw util::CloseVetoException(); 1183cdf0e10cSrcweir } 1184cdf0e10cSrcweir 1185cdf0e10cSrcweir //--------------------------------------------------------------------------- 1186cdf0e10cSrcweir void SAL_CALL DocumentHolder::notifyClosing( const lang::EventObject& aSource ) 1187cdf0e10cSrcweir throw (uno::RuntimeException) 1188cdf0e10cSrcweir { 1189cdf0e10cSrcweir if ( m_xComponent.is() && m_xComponent == aSource.Source ) 1190cdf0e10cSrcweir { 1191cdf0e10cSrcweir m_xComponent = 0; 1192cdf0e10cSrcweir if ( m_bWaitForClose ) 1193cdf0e10cSrcweir { 1194cdf0e10cSrcweir m_bWaitForClose = sal_False; 1195cdf0e10cSrcweir FreeOffice(); 1196cdf0e10cSrcweir } 1197cdf0e10cSrcweir } 1198cdf0e10cSrcweir 1199cdf0e10cSrcweir if( m_xFrame.is() && m_xFrame == aSource.Source ) 1200cdf0e10cSrcweir { 1201cdf0e10cSrcweir m_xHatchWindow = uno::Reference< awt::XWindow >(); 1202cdf0e10cSrcweir m_xOwnWindow = uno::Reference< awt::XWindow >(); 1203cdf0e10cSrcweir m_xFrame = uno::Reference< frame::XFrame >(); 1204cdf0e10cSrcweir } 1205cdf0e10cSrcweir } 1206cdf0e10cSrcweir 1207cdf0e10cSrcweir //--------------------------------------------------------------------------- 1208cdf0e10cSrcweir void SAL_CALL DocumentHolder::queryTermination( const lang::EventObject& ) 1209cdf0e10cSrcweir throw (frame::TerminationVetoException, uno::RuntimeException) 1210cdf0e10cSrcweir { 1211cdf0e10cSrcweir if ( m_bWaitForClose ) 1212cdf0e10cSrcweir throw frame::TerminationVetoException(); 1213cdf0e10cSrcweir } 1214cdf0e10cSrcweir 1215cdf0e10cSrcweir //--------------------------------------------------------------------------- 1216cdf0e10cSrcweir void SAL_CALL DocumentHolder::notifyTermination( const lang::EventObject& aSource ) 1217cdf0e10cSrcweir throw (uno::RuntimeException) 1218cdf0e10cSrcweir { 1219cdf0e10cSrcweir OSL_ENSURE( !m_xComponent.is(), "Just a disaster..." ); 1220cdf0e10cSrcweir 1221cdf0e10cSrcweir uno::Reference< frame::XDesktop > xDesktop( aSource.Source, uno::UNO_QUERY ); 1222cdf0e10cSrcweir m_bDesktopTerminated = sal_True; 1223cdf0e10cSrcweir if ( xDesktop.is() ) 1224cdf0e10cSrcweir xDesktop->removeTerminateListener( ( frame::XTerminateListener* )this ); 1225cdf0e10cSrcweir } 1226cdf0e10cSrcweir 1227cdf0e10cSrcweir //--------------------------------------------------------------------------- 1228cdf0e10cSrcweir void SAL_CALL DocumentHolder::modified( const lang::EventObject& aEvent ) 1229cdf0e10cSrcweir throw ( uno::RuntimeException ) 1230cdf0e10cSrcweir { 1231cdf0e10cSrcweir // if the component does not support document::XEventBroadcaster 1232cdf0e10cSrcweir // the modify notifications are used as workaround, but only for running state 1233cdf0e10cSrcweir if( aEvent.Source == m_xComponent && m_pEmbedObj && m_pEmbedObj->getCurrentState() == embed::EmbedStates::RUNNING ) 1234cdf0e10cSrcweir m_pEmbedObj->PostEvent_Impl( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnVisAreaChanged" ) ), aEvent.Source ); 1235cdf0e10cSrcweir } 1236cdf0e10cSrcweir 1237cdf0e10cSrcweir //--------------------------------------------------------------------------- 1238cdf0e10cSrcweir void SAL_CALL DocumentHolder::notifyEvent( const document::EventObject& Event ) 1239cdf0e10cSrcweir throw ( uno::RuntimeException ) 1240cdf0e10cSrcweir { 1241cdf0e10cSrcweir if( m_pEmbedObj && Event.Source == m_xComponent ) 1242cdf0e10cSrcweir { 1243cdf0e10cSrcweir // for now the ignored events are not forwarded, but sent by the object itself 1244cdf0e10cSrcweir if ( !Event.EventName.equalsAscii( "OnSave" ) 1245cdf0e10cSrcweir && !Event.EventName.equalsAscii( "OnSaveDone" ) 1246cdf0e10cSrcweir && !Event.EventName.equalsAscii( "OnSaveAs" ) 1247cdf0e10cSrcweir && !Event.EventName.equalsAscii( "OnSaveAsDone" ) 1248cdf0e10cSrcweir && !( Event.EventName.equalsAscii( "OnVisAreaChanged" ) && m_nNoResizeReact ) ) 1249cdf0e10cSrcweir m_pEmbedObj->PostEvent_Impl( Event.EventName, Event.Source ); 1250cdf0e10cSrcweir } 1251cdf0e10cSrcweir } 1252cdf0e10cSrcweir 1253cdf0e10cSrcweir //--------------------------------------------------------------------------- 1254cdf0e10cSrcweir void SAL_CALL DocumentHolder::borderWidthsChanged( const uno::Reference< uno::XInterface >& aObject, 1255cdf0e10cSrcweir const frame::BorderWidths& aNewSize ) 1256cdf0e10cSrcweir throw ( uno::RuntimeException ) 1257cdf0e10cSrcweir { 1258cdf0e10cSrcweir // TODO: may require mutex introduction ??? 1259cdf0e10cSrcweir if ( m_pEmbedObj && m_xFrame.is() && aObject == m_xFrame->getController() ) 1260cdf0e10cSrcweir { 1261cdf0e10cSrcweir if ( m_aBorderWidths.Left != aNewSize.Left 1262cdf0e10cSrcweir || m_aBorderWidths.Right != aNewSize.Right 1263cdf0e10cSrcweir || m_aBorderWidths.Top != aNewSize.Top 1264cdf0e10cSrcweir || m_aBorderWidths.Bottom != aNewSize.Bottom ) 1265cdf0e10cSrcweir { 1266cdf0e10cSrcweir m_aBorderWidths = aNewSize; 1267cdf0e10cSrcweir if ( !m_nNoBorderResizeReact ) 1268cdf0e10cSrcweir PlaceFrame( m_aObjRect ); 1269cdf0e10cSrcweir } 1270cdf0e10cSrcweir } 1271cdf0e10cSrcweir } 1272cdf0e10cSrcweir 1273cdf0e10cSrcweir //--------------------------------------------------------------------------- 1274cdf0e10cSrcweir void SAL_CALL DocumentHolder::requestPositioning( const awt::Rectangle& aRect ) 1275cdf0e10cSrcweir throw (uno::RuntimeException) 1276cdf0e10cSrcweir { 1277cdf0e10cSrcweir // TODO: may require mutex introduction ??? 1278cdf0e10cSrcweir if ( m_pEmbedObj ) 1279cdf0e10cSrcweir { 1280cdf0e10cSrcweir // borders should not be counted 1281cdf0e10cSrcweir awt::Rectangle aObjRect = CalculateBorderedArea( aRect ); 1282cdf0e10cSrcweir IntCounterGuard aGuard( m_nNoResizeReact ); 1283cdf0e10cSrcweir m_pEmbedObj->requestPositioning( aObjRect ); 1284cdf0e10cSrcweir } 1285cdf0e10cSrcweir } 1286cdf0e10cSrcweir 1287cdf0e10cSrcweir //--------------------------------------------------------------------------- 1288cdf0e10cSrcweir awt::Rectangle SAL_CALL DocumentHolder::calcAdjustedRectangle( const awt::Rectangle& aRect ) 1289cdf0e10cSrcweir throw (uno::RuntimeException) 1290cdf0e10cSrcweir { 1291cdf0e10cSrcweir // Solar mutex should be locked already since this is a call from HatchWindow with focus 1292cdf0e10cSrcweir awt::Rectangle aResult( aRect ); 1293cdf0e10cSrcweir 1294cdf0e10cSrcweir if ( m_xFrame.is() ) 1295cdf0e10cSrcweir { 1296cdf0e10cSrcweir // borders should not be counted 1297cdf0e10cSrcweir uno::Reference< frame::XControllerBorder > xControllerBorder( m_xFrame->getController(), uno::UNO_QUERY ); 1298cdf0e10cSrcweir if ( xControllerBorder.is() ) 1299cdf0e10cSrcweir { 1300cdf0e10cSrcweir awt::Rectangle aObjRect = CalculateBorderedArea( aRect ); 1301cdf0e10cSrcweir aObjRect = xControllerBorder->queryBorderedArea( aObjRect ); 1302cdf0e10cSrcweir aResult = AddBorderToArea( aObjRect ); 1303cdf0e10cSrcweir } 1304cdf0e10cSrcweir } 1305cdf0e10cSrcweir 1306cdf0e10cSrcweir awt::Rectangle aMinRectangle = AddBorderToArea( awt::Rectangle() ); 1307cdf0e10cSrcweir if ( aResult.Width < aMinRectangle.Width + 2 ) 1308cdf0e10cSrcweir aResult.Width = aMinRectangle.Width + 2; 1309cdf0e10cSrcweir if ( aResult.Height < aMinRectangle.Height + 2 ) 1310cdf0e10cSrcweir aResult.Height = aMinRectangle.Height + 2; 1311cdf0e10cSrcweir 1312cdf0e10cSrcweir return aResult; 1313cdf0e10cSrcweir } 1314cdf0e10cSrcweir 1315cdf0e10cSrcweir void SAL_CALL DocumentHolder::activated( ) throw (::com::sun::star::uno::RuntimeException) 1316cdf0e10cSrcweir { 1317cdf0e10cSrcweir if ( (m_pEmbedObj->getStatus(embed::Aspects::MSOLE_CONTENT)&embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE) ) 1318cdf0e10cSrcweir { 1319cdf0e10cSrcweir if ( m_pEmbedObj->getCurrentState() != embed::EmbedStates::UI_ACTIVE && 1320cdf0e10cSrcweir !(m_pEmbedObj->getStatus(embed::Aspects::MSOLE_CONTENT)&embed::EmbedMisc::MS_EMBED_NOUIACTIVATE) ) 1321cdf0e10cSrcweir { 1322cdf0e10cSrcweir try 1323cdf0e10cSrcweir { 1324cdf0e10cSrcweir m_pEmbedObj->changeState( embed::EmbedStates::UI_ACTIVE ); 1325cdf0e10cSrcweir } 1326cdf0e10cSrcweir catch ( com::sun::star::embed::StateChangeInProgressException& ) 1327cdf0e10cSrcweir { 1328cdf0e10cSrcweir // must catch this exception because focus is grabbed while UI activation in doVerb() 1329cdf0e10cSrcweir } 1330cdf0e10cSrcweir catch ( com::sun::star::uno::Exception& ) 1331cdf0e10cSrcweir { 1332cdf0e10cSrcweir // no outgoing exceptions specified here 1333cdf0e10cSrcweir } 1334cdf0e10cSrcweir } 1335cdf0e10cSrcweir else 1336cdf0e10cSrcweir { 1337cdf0e10cSrcweir uno::Reference< frame::XFramesSupplier > xSupp( m_xFrame->getCreator(), uno::UNO_QUERY ); 1338cdf0e10cSrcweir if ( xSupp.is() ) 1339cdf0e10cSrcweir xSupp->setActiveFrame( m_xFrame ); 1340cdf0e10cSrcweir } 1341cdf0e10cSrcweir } 1342cdf0e10cSrcweir } 1343cdf0e10cSrcweir 1344cdf0e10cSrcweir void DocumentHolder::ResizeHatchWindow() 1345cdf0e10cSrcweir { 1346cdf0e10cSrcweir awt::Rectangle aHatchRect = AddBorderToArea( m_aObjRect ); 1347cdf0e10cSrcweir ResizeWindows_Impl( aHatchRect ); 1348cdf0e10cSrcweir uno::Reference< embed::XHatchWindow > xHatchWindow( m_xHatchWindow, uno::UNO_QUERY ); 1349cdf0e10cSrcweir xHatchWindow->setHatchBorderSize( awt::Size( HATCH_BORDER_WIDTH, HATCH_BORDER_WIDTH ) ); 1350cdf0e10cSrcweir } 1351cdf0e10cSrcweir 1352cdf0e10cSrcweir void SAL_CALL DocumentHolder::deactivated( ) throw (::com::sun::star::uno::RuntimeException) 1353cdf0e10cSrcweir { 1354cdf0e10cSrcweir // deactivation is too unspecific to be useful; usually we only trigger code from activation 1355cdf0e10cSrcweir // so UIDeactivation is actively triggered by the container 1356cdf0e10cSrcweir } 1357