20#include <com/sun/star/embed/Aspects.hpp>
21#include <com/sun/star/frame/TaskCreator.hpp>
22#include <com/sun/star/frame/XTitle.hpp>
23#include <com/sun/star/frame/TerminationVetoException.hpp>
24#include <com/sun/star/frame/XComponentLoader.hpp>
25#include <com/sun/star/frame/XSynchronousFrameLoader.hpp>
26#include <com/sun/star/lang/XSingleServiceFactory.hpp>
27#include <com/sun/star/lang/XSingleComponentFactory.hpp>
28#include <com/sun/star/util/CloseVetoException.hpp>
29#include <com/sun/star/util/XCloseBroadcaster.hpp>
30#include <com/sun/star/util/XCloseable.hpp>
31#include <com/sun/star/lang/XServiceInfo.hpp>
32#include <com/sun/star/beans/XPropertySet.hpp>
33#include <com/sun/star/beans/NamedValue.hpp>
34#include <com/sun/star/frame/XModel.hpp>
35#include <com/sun/star/frame/Desktop.hpp>
36#include <com/sun/star/frame/XFramesSupplier.hpp>
37#include <com/sun/star/frame/XControllerBorder.hpp>
38#include <com/sun/star/util/XModifyBroadcaster.hpp>
39#include <com/sun/star/frame/XDispatchProviderInterception.hpp>
40#include <com/sun/star/awt/Toolkit.hpp>
41#include <com/sun/star/awt/XTopWindow.hpp>
42#include <com/sun/star/awt/PosSize.hpp>
43#include <com/sun/star/awt/WindowAttribute.hpp>
44#include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
45#include <com/sun/star/embed/XHatchWindow.hpp>
46#include <com/sun/star/embed/HatchWindowFactory.hpp>
47#include <com/sun/star/frame/XLayoutManager.hpp>
48#include <com/sun/star/frame/XMenuBarMergingAcceptor.hpp>
49#include <com/sun/star/frame/ModuleManager.hpp>
50#include <com/sun/star/ui/XDockingAreaAcceptor.hpp>
51#include <com/sun/star/ui/XUIElementSettings.hpp>
52#include <com/sun/star/ui/XUIConfigurationManager.hpp>
53#include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
54#include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
55#include <com/sun/star/embed/StateChangeInProgressException.hpp>
57#include <com/sun/star/embed/EmbedMisc.hpp>
58#include <com/sun/star/embed/EmbedStates.hpp>
59#include <osl/diagnose.h>
63#include <sfx2/strings.hrc>
68#include <docholder.hxx>
70#include <intercept.hxx>
72#define HATCH_BORDER_WIDTH (((m_pEmbedObj->getStatus(embed::Aspects::MSOLE_CONTENT)&embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE) && \
73 m_pEmbedObj->getCurrentState()!=embed::EmbedStates::UI_ACTIVE) ? 0 : 4 )
83 explicit IntCounterGuard(sal_Int32& rFlag)
98static void InsertMenu_Impl(
const uno::Reference< container::XIndexContainer >& xTargetMenu,
99 sal_Int32 nTargetIndex,
100 const uno::Reference< container::XIndexAccess >& xSourceMenu,
101 sal_Int32 nSourceIndex,
102 const OUString& aContModuleName,
103 const uno::Reference< frame::XDispatchProvider >& xSourceDisp )
106 OUString aModuleIdentPropName(
"ModuleIdentifier" );
107 OUString aDispProvPropName(
"DispatchProvider" );
108 bool bModuleNameSet =
false;
109 bool bDispProvSet =
false;
111 uno::Sequence< beans::PropertyValue > aSourceProps;
112 xSourceMenu->getByIndex( nSourceIndex ) >>= aSourceProps;
113 uno::Sequence< beans::PropertyValue > aTargetProps( aSourceProps.getLength() );
114 auto aTargetPropsRange = asNonConstRange(aTargetProps);
115 for ( nInd = 0; nInd < aSourceProps.getLength(); nInd++ )
117 aTargetPropsRange[nInd].Name = aSourceProps[nInd].Name;
118 if ( !aContModuleName.isEmpty() && aTargetProps[nInd].Name == aModuleIdentPropName )
120 aTargetPropsRange[nInd].Value <<= aContModuleName;
121 bModuleNameSet =
true;
123 else if ( aTargetProps[nInd].
Name == aDispProvPropName )
125 aTargetPropsRange[nInd].Value <<= xSourceDisp;
129 aTargetPropsRange[nInd].Value = aSourceProps[nInd].Value;
132 if ( !bModuleNameSet && !aContModuleName.isEmpty() )
134 aTargetProps.realloc( ++nInd );
135 auto pTargetProps = aTargetProps.getArray();
136 pTargetProps[nInd-1].Name = aModuleIdentPropName;
137 pTargetProps[nInd-1].Value <<= aContModuleName;
140 if ( !bDispProvSet && xSourceDisp.is() )
142 aTargetProps.realloc( ++nInd );
143 auto pTargetProps = aTargetProps.getArray();
144 pTargetProps[nInd-1].Name = aDispProvPropName;
145 pTargetProps[nInd-1].Value <<= xSourceDisp;
148 xTargetMenu->insertByIndex( nTargetIndex,
uno::Any( aTargetProps ) );
154: m_pEmbedObj( pEmbObj ),
157 m_bWaitForClose( false ),
158 m_bAllowClosing( false ),
159 m_bDesktopTerminated( false ),
160 m_nNoBorderResizeReact( 0 ),
161 m_nNoResizeReact( 0 )
163 uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create( m_xContext );
164 osl_atomic_increment(&m_refCount);
167 xDesktop->addTerminateListener(
this );
169 catch (
const uno::Exception& )
172 osl_atomic_decrement(&m_refCount);
174 m_aOutplaceFrameProps = {
uno::Any(beans::NamedValue{
"TopWindow",
uno::Any(
true) }),
183 osl_atomic_increment(&m_refCount);
188 if ( m_xComponent.is() )
192 }
catch(
const uno::Exception& ) {}
195 if ( m_xInterceptor.is() )
197 m_xInterceptor->DisconnectDocHolder();
198 m_xInterceptor.clear();
201 if ( !m_bDesktopTerminated )
208 uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster(
m_xFrame, uno::UNO_QUERY );
209 if ( xCloseBroadcaster.is() )
210 xCloseBroadcaster->removeCloseListener(
static_cast<util::XCloseListener*
>(
this) );
212 uno::Reference<util::XCloseable> xCloseable(
214 if( xCloseable.is() )
216 xCloseable->close(
true );
218 catch(
const uno::Exception& ) {
225 if ( m_xHatchWindow.is() )
226 m_xHatchWindow->dispose();
228 m_xHatchWindow.clear();
229 m_xOwnWindow.clear();
237 uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create( m_xContext );
238 xDesktop->removeTerminateListener(
this );
239 }
catch (
const css::uno::DeploymentException&) {
266 if ( m_xComponent.is() )
268 uno::Reference< document::XEventBroadcaster > xEventBroadcaster( m_xComponent, uno::UNO_QUERY );
269 if ( xEventBroadcaster.is() )
270 xEventBroadcaster->removeEventListener(
static_cast<document::XEventListener*
>(
this) );
275 uno::Reference< util::XModifyBroadcaster > xModifyBroadcaster( m_xComponent, uno::UNO_QUERY );
276 if ( xModifyBroadcaster.is() )
277 xModifyBroadcaster->removeModifyListener(
static_cast<util::XModifyListener*
>(
this) );
280 m_bAllowClosing =
true;
281 m_bWaitForClose = bWaitForClose;
282 m_xComponent->close( bDeliverOwnership );
285 m_xComponent =
nullptr;
289void DocumentHolder::PlaceFrame(
const awt::Rectangle& aNewRect )
291 OSL_ENSURE(
m_xFrame.is() && m_xOwnWindow.is(),
292 "The object does not have windows required for inplace mode!" );
295 if ( !(
m_xFrame.is() && m_xOwnWindow.is()) )
299 frame::BorderWidths aOldWidths;
300 IntCounterGuard aGuard( m_nNoBorderResizeReact );
304 aOldWidths = m_aBorderWidths;
306 awt::Rectangle aHatchRect = AddBorderToArea( aNewRect );
308 ResizeWindows_Impl( aHatchRect );
310 }
while ( aOldWidths.Left != m_aBorderWidths.Left
311 || aOldWidths.Top != m_aBorderWidths.Top
312 || aOldWidths.Right != m_aBorderWidths.Right
313 || aOldWidths.Bottom != m_aBorderWidths.Bottom );
315 m_aObjRect = aNewRect;
319void DocumentHolder::ResizeWindows_Impl(
const awt::Rectangle& aHatchRect )
321 OSL_ENSURE(
m_xFrame.is() && m_xOwnWindow.is() ,
322 "The object does not have windows required for inplace mode!" );
323 if ( m_xHatchWindow.is() )
329 awt::PosSize::POSSIZE );
332 m_xHatchWindow->setPosSize( aHatchRect.X,
336 awt::PosSize::POSSIZE );
343 awt::PosSize::POSSIZE );
347bool DocumentHolder::SetFrameLMVisibility(
const uno::Reference< frame::XFrame >& xFrame,
bool bVisible )
349 bool bResult =
false;
353 uno::Reference< css::frame::XLayoutManager > xLayoutManager;
354 uno::Reference< beans::XPropertySet > xPropSet( xFrame, uno::UNO_QUERY_THROW );
355 xPropSet->getPropertyValue(
"LayoutManager") >>= xLayoutManager;
356 if ( xLayoutManager.is() )
358 xLayoutManager->setVisible( bVisible );
363 xLayoutManager->unlock();
365 xLayoutManager->lock();
370 catch(
const uno::Exception& )
377bool DocumentHolder::ShowInplace(
const uno::Reference< awt::XWindowPeer >& xParent,
378 const awt::Rectangle& aRectangleToShow,
379 const uno::Reference< frame::XDispatchProvider >& xContDisp )
381 OSL_ENSURE( !
m_xFrame.is(),
"A frame exists already!" );
385 uno::Reference < frame::XModel >
xModel( GetComponent(), uno::UNO_QUERY );
386 awt::Rectangle aHatchRectangle = AddBorderToArea( aRectangleToShow );
392 uno::Reference< awt::XWindow > xHWindow;
393 uno::Reference< awt::XWindowPeer > xMyParent( xParent );
398 uno::Reference< embed::XHatchWindowFactory > xHatchFactory =
399 embed::HatchWindowFactory::create(m_xContext);
401 uno::Reference< embed::XHatchWindow > xHatchWindow =
402 xHatchFactory->createHatchWindowInstance( xParent,
406 uno::Reference< awt::XWindowPeer > xHatchWinPeer( xHatchWindow, uno::UNO_QUERY );
407 xHWindow.set( xHatchWinPeer, uno::UNO_QUERY_THROW );
409 xHatchWindow->setController( uno::Reference< embed::XHatchWindowController >(
410 static_cast< embed::XHatchWindowController*
>(
this ) ) );
412 xMyParent = xHatchWinPeer;
416 aOwnRectangle.X += aHatchRectangle.X;
417 aOwnRectangle.Y += aHatchRectangle.Y;
420 awt::WindowDescriptor aOwnWinDescriptor( awt::WindowClass_TOP,
425 awt::WindowAttribute::SHOW | awt::VclWindowPeerAttribute::CLIPCHILDREN );
427 uno::Reference< awt::XToolkit2 > xToolkit = awt::Toolkit::create(m_xContext);
429 uno::Reference< awt::XWindowPeer > xNewWinPeer = xToolkit->createWindow( aOwnWinDescriptor );
430 uno::Reference< awt::XWindow > xOwnWindow( xNewWinPeer, uno::UNO_QUERY_THROW );
431 uno::Reference< frame::XFrame > xContFrame( xContDisp, uno::UNO_QUERY );
434 uno::Reference< lang::XSingleServiceFactory > xFrameFact = frame::TaskCreator::create(m_xContext);
436 uno::Sequence< uno::Any > aArgs( xContFrame.is() ? 2 : 1 );
437 auto pArgs = aArgs.getArray();
438 beans::NamedValue aArg;
440 aArg.Name =
"ContainerWindow";
441 aArg.Value <<= xOwnWindow;
444 if ( xContFrame.is() )
446 aArg.Name =
"ParentFrame";
447 aArg.Value <<= xContFrame;
452 m_xFrame.set( xFrameFact->createInstanceWithArguments( aArgs ), uno::UNO_QUERY_THROW );
454 m_xHatchWindow = xHWindow;
455 m_xOwnWindow = xOwnWindow;
457 if ( !SetFrameLMVisibility(
m_xFrame,
false ) )
459 OSL_FAIL(
"Can't deactivate LayoutManager!" );
465 uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster(
m_xFrame, uno::UNO_QUERY );
466 if ( xCloseBroadcaster.is() )
467 xCloseBroadcaster->addCloseListener(
static_cast<util::XCloseListener*
>(
this) );
475 if ( !LoadDocToFrame(
true ) )
481 uno::Reference< frame::XControllerBorder > xControllerBorder(
m_xFrame->getController(), uno::UNO_QUERY );
482 if ( xControllerBorder.is() )
484 m_aBorderWidths = xControllerBorder->getBorder();
485 xControllerBorder->addBorderResizeListener(
static_cast<frame::XBorderResizeListener*
>(
this) );
488 PlaceFrame( aRectangleToShow );
490 if ( m_xHatchWindow.is() )
491 m_xHatchWindow->setVisible(
true );
497uno::Reference< container::XIndexAccess > DocumentHolder::RetrieveOwnMenu_Impl()
499 uno::Reference< container::XIndexAccess > xResult;
501 uno::Reference< css::ui::XUIConfigurationManagerSupplier > xUIConfSupplier(
504 uno::Reference< css::ui::XUIConfigurationManager > xUIConfigManager;
505 if( xUIConfSupplier.is())
507 xUIConfigManager.set(
508 xUIConfSupplier->getUIConfigurationManager(),
509 uno::UNO_SET_THROW );
514 if( xUIConfigManager.is())
516 xResult = xUIConfigManager->getSettings(
517 "private:resource/menubar/menubar",
521 catch(
const uno::Exception& )
527 uno::Reference< frame::XModuleManager2 > xModuleMan = frame::ModuleManager::create(m_xContext);
528 OUString aModuleIdent =
529 xModuleMan->identify( uno::Reference< uno::XInterface >( m_xComponent, uno::UNO_QUERY ) );
531 if ( !aModuleIdent.isEmpty() )
533 uno::Reference< ui::XModuleUIConfigurationManagerSupplier > xModConfSupplier =
534 ui::theModuleUIConfigurationManagerSupplier::get(m_xContext);
535 uno::Reference< css::ui::XUIConfigurationManager > xModUIConfMan(
536 xModConfSupplier->getUIConfigurationManager( aModuleIdent ),
537 uno::UNO_SET_THROW );
538 xResult = xModUIConfMan->getSettings(
539 "private:resource/menubar/menubar",
545 throw uno::RuntimeException();
551void DocumentHolder::FindConnectPoints(
552 const uno::Reference< container::XIndexAccess >& xMenu,
553 sal_Int32 nConnectPoints[2] )
555 nConnectPoints[0] = -1;
556 nConnectPoints[1] = -1;
557 for ( sal_Int32 nInd = 0; nInd < xMenu->getCount(); nInd++ )
559 uno::Sequence< beans::PropertyValue > aProps;
560 xMenu->getByIndex( nInd ) >>= aProps;
562 for ( beans::PropertyValue
const & prop : std::as_const(aProps) )
563 if ( prop.Name ==
"CommandURL" )
570 throw uno::RuntimeException();
572 if ( aCommand ==
".uno:PickList" )
573 nConnectPoints[0] = nInd;
574 else if ( aCommand ==
".uno:WindowList" )
575 nConnectPoints[1] = nInd;
580uno::Reference< container::XIndexAccess > DocumentHolder::MergeMenusForInplace(
581 const uno::Reference< container::XIndexAccess >& xContMenu,
582 const uno::Reference< frame::XDispatchProvider >& xContDisp,
583 const OUString& aContModuleName,
584 const uno::Reference< container::XIndexAccess >& xOwnMenu,
585 const uno::Reference< frame::XDispatchProvider >& xOwnDisp )
589 sal_Int32 nContPoints[2];
590 sal_Int32 nOwnPoints[2];
592 uno::Reference< lang::XSingleComponentFactory > xIndAccessFact( xContMenu, uno::UNO_QUERY_THROW );
594 uno::Reference< container::XIndexContainer > xMergedMenu(
595 xIndAccessFact->createInstanceWithContext(
597 uno::UNO_QUERY_THROW );
599 FindConnectPoints( xContMenu, nContPoints );
600 FindConnectPoints( xOwnMenu, nOwnPoints );
602 for ( sal_Int32 nInd = 0; nInd < xOwnMenu->getCount(); nInd++ )
604 if ( nOwnPoints[0] == nInd )
606 if ( nContPoints[0] >= 0 && nContPoints[0] < xContMenu->getCount() )
608 InsertMenu_Impl( xMergedMenu, nInd, xContMenu, nContPoints[0], aContModuleName, xContDisp );
611 else if ( nOwnPoints[1] == nInd )
613 if ( nContPoints[1] >= 0 && nContPoints[1] < xContMenu->getCount() )
615 InsertMenu_Impl( xMergedMenu, nInd, xContMenu, nContPoints[1], aContModuleName, xContDisp );
619 InsertMenu_Impl( xMergedMenu, nInd, xOwnMenu, nInd, OUString(), xOwnDisp );
622 return uno::Reference< container::XIndexAccess >( xMergedMenu, uno::UNO_QUERY_THROW );
626bool DocumentHolder::MergeMenus_Impl(
const uno::Reference< css::frame::XLayoutManager >& xOwnLM,
627 const uno::Reference< css::frame::XLayoutManager >& xContLM,
628 const uno::Reference< frame::XDispatchProvider >& xContDisp,
629 const OUString& aContModuleName )
631 bool bMenuMerged =
false;
634 uno::Reference< css::ui::XUIElementSettings > xUISettings(
635 xContLM->getElement(
"private:resource/menubar/menubar" ),
636 uno::UNO_QUERY_THROW );
637 uno::Reference< container::XIndexAccess > xContMenu = xUISettings->getSettings(
true );
638 if ( !xContMenu.is() )
639 throw uno::RuntimeException();
641 uno::Reference< container::XIndexAccess > xOwnMenu = RetrieveOwnMenu_Impl();
642 uno::Reference< frame::XDispatchProvider > xOwnDisp(
m_xFrame, uno::UNO_QUERY_THROW );
644 uno::Reference< container::XIndexAccess > xMergedMenu = MergeMenusForInplace( xContMenu, xContDisp, aContModuleName, xOwnMenu, xOwnDisp );
645 uno::Reference< css::frame::XMenuBarMergingAcceptor > xMerge( xOwnLM,
646 uno::UNO_QUERY_THROW );
647 bMenuMerged = xMerge->setMergedMenuBar( xMergedMenu );
649 catch(
const uno::Exception& )
655bool DocumentHolder::ShowUI(
const uno::Reference< css::frame::XLayoutManager >& xContainerLM,
656 const uno::Reference< frame::XDispatchProvider >& xContainerDP,
657 const OUString& aContModuleName )
659 bool bResult =
false;
660 if ( xContainerLM.is() )
663 uno::Reference< css::frame::XLayoutManager > xOwnLM;
664 uno::Reference< css::ui::XDockingAreaAcceptor > xDocAreaAcc;
668 uno::Reference< beans::XPropertySet > xPropSet(
m_xFrame, uno::UNO_QUERY_THROW );
669 xPropSet->getPropertyValue(
"LayoutManager") >>= xOwnLM;
670 xDocAreaAcc = xContainerLM->getDockingAreaAcceptor();
672 catch(
const uno::Exception& ){}
674 if ( xOwnLM.is() && xDocAreaAcc.is() )
677 bool bUnlockContainerLM =
false;
678 bool bLockOwnLM =
false;
683 xOwnLM->setDockingAreaAcceptor( xDocAreaAcc );
686 if ( MergeMenus_Impl( xOwnLM, xContainerLM, xContainerDP, aContModuleName ) )
690 xContainerLM->setDockingAreaAcceptor( uno::Reference < ui::XDockingAreaAcceptor >() );
692 uno::Reference< lang::XServiceInfo> xServiceInfo(m_xComponent, uno::UNO_QUERY);
693 if (!xServiceInfo.is() || !xServiceInfo->supportsService(
"com.sun.star.chart2.ChartDocument"))
696 xContainerLM->setVisible(
false);
697 xContainerLM->lock();
698 bUnlockContainerLM =
true;
702 xOwnLM->setVisible(
true );
704 uno::Reference< frame::XFramesSupplier > xSupp =
m_xFrame->getCreator();
715 m_xOwnWindow->setFocus();
718 catch(
const uno::Exception& )
723 uno::Reference< frame::XFramesSupplier > xSupp =
m_xFrame->getCreator();
725 xSupp->setActiveFrame(
nullptr );
730 xOwnLM->setVisible(
false );
731 xOwnLM->setDockingAreaAcceptor( uno::Reference< css::ui::XDockingAreaAcceptor >() );
734 uno::Reference< css::frame::XMenuBarMergingAcceptor > xMerge( xOwnLM, uno::UNO_QUERY_THROW );
735 xMerge->removeMergedMenuBar();
737 catch(
const uno::Exception& ) {}
742 xContainerLM->setDockingAreaAcceptor( xDocAreaAcc );
743 xContainerLM->setVisible(
true );
744 if (bUnlockContainerLM)
745 xContainerLM->unlock();
747 catch(
const uno::Exception& ) {}
756bool DocumentHolder::HideUI(
const uno::Reference< css::frame::XLayoutManager >& xContainerLM )
758 bool bResult =
false;
760 if ( xContainerLM.is() )
762 uno::Reference< css::frame::XLayoutManager > xOwnLM;
765 uno::Reference< beans::XPropertySet > xPropSet(
m_xFrame, uno::UNO_QUERY_THROW );
766 xPropSet->getPropertyValue(
"LayoutManager") >>= xOwnLM;
767 }
catch(
const uno::Exception& )
773 uno::Reference< frame::XFramesSupplier > xSupp =
m_xFrame->getCreator();
775 xSupp->setActiveFrame(
nullptr );
777 uno::Reference< css::ui::XDockingAreaAcceptor > xDocAreaAcc = xOwnLM->getDockingAreaAcceptor();
779 xOwnLM->setDockingAreaAcceptor( uno::Reference < ui::XDockingAreaAcceptor >() );
781 xOwnLM->setVisible(
false );
783 uno::Reference< css::frame::XMenuBarMergingAcceptor > xMerge( xOwnLM, uno::UNO_QUERY_THROW );
784 xMerge->removeMergedMenuBar();
786 xContainerLM->setDockingAreaAcceptor( xDocAreaAcc );
787 uno::Reference< lang::XServiceInfo> xServiceInfo(m_xComponent, uno::UNO_QUERY);
788 if (!xServiceInfo.is() || !xServiceInfo->supportsService(
"com.sun.star.chart2.ChartDocument"))
790 xContainerLM->setVisible(
true);
791 xContainerLM->unlock();
794 xContainerLM->doLayout();
797 catch(
const uno::Exception& )
799 SetFrameLMVisibility(
m_xFrame,
true );
808uno::Reference< frame::XFrame >
const & DocumentHolder::GetDocFrame()
813 uno::Reference< lang::XSingleServiceFactory > xFrameFact = frame::TaskCreator::create(m_xContext);
815 m_xFrame.set(xFrameFact->createInstanceWithArguments( m_aOutplaceFrameProps ), uno::UNO_QUERY_THROW);
817 uno::Reference< frame::XDispatchProviderInterception > xInterception(
m_xFrame, uno::UNO_QUERY );
818 if ( xInterception.is() )
820 if ( m_xInterceptor.is() )
822 m_xInterceptor->DisconnectDocHolder();
823 m_xInterceptor.clear();
828 xInterception->registerDispatchProviderInterceptor( m_xInterceptor );
831 if ( m_xOutplaceInterceptor.is() )
832 xInterception->registerDispatchProviderInterceptor( m_xOutplaceInterceptor );
835 uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster(
m_xFrame, uno::UNO_QUERY );
836 if ( xCloseBroadcaster.is() )
837 xCloseBroadcaster->addCloseListener(
static_cast<util::XCloseListener*
>(
this) );
840 if ( m_xComponent.is() )
842 uno::Reference< css::frame::XLayoutManager > xOwnLM;
844 uno::Reference< beans::XPropertySet > xPropSet(
m_xFrame, uno::UNO_QUERY_THROW );
845 xPropSet->getPropertyValue(
"LayoutManager") >>= xOwnLM;
846 }
catch(
const uno::Exception& )
854 LoadDocToFrame(
false);
862 GetExtent(embed::Aspects::MSOLE_CONTENT, &aSize);
863 SetExtent(embed::Aspects::MSOLE_CONTENT, aSize);
871 uno::Reference< awt::XWindow > xHWindow =
m_xFrame->getContainerWindow();
878 awt::Rectangle aWindowRect = xHWindow->getPosSize();
880 if (( aWindowRect.Width < aWorkRect.
GetWidth()) && ( aWindowRect.Height < aWorkRect.
GetHeight() ))
882 int OffsetX = ( aWorkRect.
GetWidth() - aWindowRect.Width ) / 2 + aWorkRect.
Left();
883 int OffsetY = ( aWorkRect.
GetHeight() - aWindowRect.Height ) /2 + aWorkRect.
Top();
884 xHWindow->setPosSize( OffsetX, OffsetY, aWindowRect.Width, aWindowRect.Height, awt::PosSize::POS );
888 xHWindow->setPosSize( aWorkRect.
Left(), aWorkRect.
Top(), aWorkRect.
GetWidth(), aWorkRect.
GetHeight(), awt::PosSize::POSSIZE );
891 xHWindow->setVisible(
true );
894 catch (
const uno::Exception& )
902void DocumentHolder::SetComponent(
const uno::Reference< util::XCloseable >& xDoc,
bool bReadOnly )
904 if ( m_xComponent.is() )
909 }
catch(
const uno::Exception& )
916 m_bAllowClosing =
false;
918 if ( m_xComponent.is() )
919 m_xComponent->addCloseListener(
static_cast<util::XCloseListener*
>(
this) );
921 uno::Reference< document::XEventBroadcaster > xEventBroadcaster( m_xComponent, uno::UNO_QUERY );
922 if ( xEventBroadcaster.is() )
923 xEventBroadcaster->addEventListener(
static_cast<document::XEventListener*
>(
this) );
928 uno::Reference< util::XModifyBroadcaster > xModifyBroadcaster( m_xComponent, uno::UNO_QUERY );
929 if ( xModifyBroadcaster.is() )
930 xModifyBroadcaster->addModifyListener(
static_cast<util::XModifyListener*
>(
this) );
934 LoadDocToFrame(
false);
938bool DocumentHolder::LoadDocToFrame(
bool bInPlace )
943 uno::Reference < frame::XModel > xDoc( m_xComponent, uno::UNO_QUERY );
947 uno::Reference< frame::XComponentLoader > xComponentLoader(
m_xFrame, uno::UNO_QUERY_THROW );
950 aArgs.
put(
"Model", m_xComponent );
951 aArgs.
put(
"ReadOnly", m_bReadOnly );
954 css::uno::Reference< css::frame::XTitle > xModelTitle( xDoc, css::uno::UNO_QUERY );
955 if( xModelTitle.is() && m_pEmbedObj && !m_pEmbedObj->
getContainerName().isEmpty() )
966 aArgs.
put(
"PluginMode", sal_Int16(1) );
968 uno::Reference< lang::XServiceInfo> xServiceInfo(xDoc,uno::UNO_QUERY);
969 if ( xServiceInfo.is()
970 && xServiceInfo->supportsService(
"com.sun.star.report.ReportDefinition") )
972 sUrl =
".component:DB/ReportDesign";
974 else if( xServiceInfo.is()
975 && xServiceInfo->supportsService(
"com.sun.star.chart2.ChartDocument"))
976 sUrl =
"private:factory/schart";
978 sUrl =
"private:object";
980 xComponentLoader->loadComponentFromURL( sUrl,
989 uno::Reference < frame::XSynchronousFrameLoader > xLoader( m_xComponent, uno::UNO_QUERY );
991 return xLoader->load( uno::Sequence < beans::PropertyValue >(),
m_xFrame );
1000void DocumentHolder::Show()
1005 uno::Reference<awt::XTopWindow> xTopWindow(
m_xFrame->getContainerWindow(), uno::UNO_QUERY );
1006 if( xTopWindow.is() )
1007 xTopWindow->toFront();
1016 uno::Reference< embed::XVisualObject > xDocVis( m_xComponent, uno::UNO_QUERY );
1021 xDocVis->setVisualAreaSize( nAspect, aSize );
1024 catch(
const uno::Exception& )
1036 uno::Reference< embed::XVisualObject > xDocVis( m_xComponent, uno::UNO_QUERY );
1037 if ( pSize && xDocVis.is() )
1041 *pSize = xDocVis->getVisualAreaSize( nAspect );
1044 catch(
const uno::Exception& )
1054sal_Int32 DocumentHolder::GetMapUnit( sal_Int64 nAspect )
1056 uno::Reference< embed::XVisualObject > xDocVis( m_xComponent, uno::UNO_QUERY );
1061 return xDocVis->getMapUnit( nAspect );
1063 catch(
const uno::Exception& )
1073awt::Rectangle DocumentHolder::CalculateBorderedArea(
const awt::Rectangle& aRect )
1078 aRect.Height - m_aBorderWidths.Top - m_aBorderWidths.Bottom - 2*
HATCH_BORDER_WIDTH );
1082awt::Rectangle DocumentHolder::AddBorderToArea(
const awt::Rectangle& aRect )
1087 aRect.Height + m_aBorderWidths.Top + m_aBorderWidths.Bottom + 2*
HATCH_BORDER_WIDTH );
1093 if ( m_xComponent.is() && m_xComponent == aSource.Source )
1095 m_xComponent =
nullptr;
1096 if ( m_bWaitForClose )
1098 m_bWaitForClose =
false;
1105 m_xHatchWindow.clear();
1106 m_xOwnWindow.clear();
1114 if ( m_xComponent.is() && m_xComponent == aSource.Source && !m_bAllowClosing )
1115 throw util::CloseVetoException(
"To close an embedded document, close the document holder (document definition), not the document itself.",
static_cast< ::
cppu::OWeakObject*
>(
this));
1121 if ( m_xComponent.is() && m_xComponent == aSource.Source )
1123 m_xComponent =
nullptr;
1124 if ( m_bWaitForClose )
1126 m_bWaitForClose =
false;
1133 m_xHatchWindow.clear();
1134 m_xOwnWindow.clear();
1142 if ( m_bWaitForClose )
1143 throw frame::TerminationVetoException();
1149 OSL_ENSURE( !m_xComponent.is(),
"Just a disaster..." );
1151 uno::Reference< frame::XDesktop > xDesktop( aSource.Source, uno::UNO_QUERY );
1152 m_bDesktopTerminated =
true;
1153 if ( xDesktop.is() )
1154 xDesktop->removeTerminateListener(
static_cast<frame::XTerminateListener*
>(
this) );
1162 if(
aEvent.Source == m_xComponent && m_pEmbedObj && m_pEmbedObj->
getCurrentState() == embed::EmbedStates::RUNNING )
1167void SAL_CALL DocumentHolder::notifyEvent(
const document::EventObject& Event )
1169 if( m_pEmbedObj && Event.Source == m_xComponent )
1172 if ( !Event.EventName.startsWith(
"OnSave" )
1173 && !Event.EventName.startsWith(
"OnSaveDone" )
1174 && !Event.EventName.startsWith(
"OnSaveAs" )
1175 && !Event.EventName.startsWith(
"OnSaveAsDone" )
1176 && !( Event.EventName.startsWith(
"OnVisAreaChanged" ) && m_nNoResizeReact ) )
1182void SAL_CALL DocumentHolder::borderWidthsChanged(
const uno::Reference< uno::XInterface >& aObject,
1183 const frame::BorderWidths& aNewSize )
1186 if ( m_pEmbedObj &&
m_xFrame.is() && aObject ==
m_xFrame->getController() )
1188 if ( m_aBorderWidths.Left != aNewSize.Left
1189 || m_aBorderWidths.Right != aNewSize.Right
1190 || m_aBorderWidths.Top != aNewSize.Top
1191 || m_aBorderWidths.Bottom != aNewSize.Bottom )
1193 m_aBorderWidths = aNewSize;
1194 if ( !m_nNoBorderResizeReact )
1195 PlaceFrame( m_aObjRect );
1201void SAL_CALL DocumentHolder::requestPositioning(
const awt::Rectangle& aRect )
1207 awt::Rectangle aObjRect = CalculateBorderedArea( aRect );
1208 IntCounterGuard aGuard( m_nNoResizeReact );
1214awt::Rectangle SAL_CALL DocumentHolder::calcAdjustedRectangle(
const awt::Rectangle& aRect )
1217 awt::Rectangle aResult( aRect );
1222 uno::Reference< frame::XControllerBorder > xControllerBorder(
m_xFrame->getController(), uno::UNO_QUERY );
1223 if ( xControllerBorder.is() )
1225 awt::Rectangle aObjRect = CalculateBorderedArea( aRect );
1226 aObjRect = xControllerBorder->queryBorderedArea( aObjRect );
1227 aResult = AddBorderToArea( aObjRect );
1231 awt::Rectangle aMinRectangle = AddBorderToArea( awt::Rectangle() );
1232 if ( aResult.Width < aMinRectangle.Width + 2 )
1233 aResult.Width = aMinRectangle.Width + 2;
1234 if ( aResult.Height < aMinRectangle.Height + 2 )
1235 aResult.Height = aMinRectangle.Height + 2;
1240void SAL_CALL DocumentHolder::activated( )
1242 if ( !(m_pEmbedObj->
getStatus(embed::Aspects::MSOLE_CONTENT)&embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE) )
1245 if ( m_pEmbedObj->
getCurrentState() != embed::EmbedStates::UI_ACTIVE &&
1246 !(m_pEmbedObj->
getStatus(embed::Aspects::MSOLE_CONTENT)&embed::EmbedMisc::MS_EMBED_NOUIACTIVATE) )
1250 m_pEmbedObj->
changeState( embed::EmbedStates::UI_ACTIVE );
1252 catch (
const css::embed::StateChangeInProgressException& )
1256 catch (
const css::uno::Exception& )
1263 uno::Reference< frame::XFramesSupplier > xSupp =
m_xFrame->getCreator();
1269void DocumentHolder::ResizeHatchWindow()
1271 awt::Rectangle aHatchRect = AddBorderToArea( m_aObjRect );
1272 ResizeWindows_Impl( aHatchRect );
1273 uno::Reference< embed::XHatchWindow > xHatchWindow( m_xHatchWindow, uno::UNO_QUERY );
1277void SAL_CALL DocumentHolder::deactivated( )
Reference< XComponentContext > m_xContext
static unsigned int GetDisplayBuiltInScreen()
static tools::Rectangle GetScreenPosSizePixel(unsigned int nScreen)
virtual void SAL_CALL disposing(const css::lang::EventObject &aSource) override
virtual void SAL_CALL notifyTermination(const css::lang::EventObject &aSource) override
virtual void SAL_CALL queryTermination(const css::lang::EventObject &aSource) override
~DocumentHolder() override
virtual void SAL_CALL queryClosing(const css::lang::EventObject &aSource, sal_Bool bGetsOwnership) override
HRESULT GetExtent(SIZEL *pSize)
virtual void SAL_CALL modified(const css::lang::EventObject &aEvent) override
OUString m_aContainerName
virtual void SAL_CALL notifyClosing(const css::lang::EventObject &aSource) override
HRESULT SetExtent(const SIZEL *pSize)
OUString m_aDocumentNamePart
css::uno::Reference< css::frame::XFrame2 > m_xFrame
DocumentHolder(const css::uno::Reference< css::lang::XMultiServiceFactory > &xFactory, const ::rtl::Reference< EmbeddedDocumentInstanceAccess_Impl > &xOleAccess)
Represents an OLE object that has native data and we loaded that data into a document model successfu...
void PostEvent_Impl(const OUString &aEventName)
virtual void SAL_CALL changeState(sal_Int32 nNewState) override
OUString const & getContainerName() const
void requestPositioning(const css::awt::Rectangle &aRect)
virtual sal_Int64 SAL_CALL getStatus(sal_Int64 nAspect) override
virtual sal_Int32 SAL_CALL getCurrentState() override
bool put(const OUString &_rValueName, const VALUE_TYPE &_rValue)
css::uno::Sequence< css::beans::PropertyValue > getPropertyValues() const
#define HATCH_BORDER_WIDTH
static void InsertMenu_Impl(const uno::Reference< container::XIndexContainer > &xTargetMenu, sal_Int32 nTargetIndex, const uno::Reference< container::XIndexAccess > &xSourceMenu, sal_Int32 nSourceIndex, const OUString &aContModuleName, const uno::Reference< frame::XDispatchProvider > &xSourceDisp)
std::locale Create(std::string_view aPrefixName, const LanguageTag &rLocale)
OUString get(TranslateId sContextAndId, const std::locale &loc)
Reference< XComponentContext > getProcessComponentContext()
Reference< XModel > xModel