22#include <com/sun/star/awt/XVclWindowPeer.hpp>
23#include <com/sun/star/embed/Aspects.hpp>
24#include <com/sun/star/embed/EmbedStates.hpp>
25#include <com/sun/star/embed/UnreachableStateException.hpp>
26#include <com/sun/star/embed/XEmbeddedClient.hpp>
27#include <com/sun/star/embed/XInplaceClient.hpp>
28#include <com/sun/star/embed/XInplaceObject.hpp>
29#include <com/sun/star/embed/XWindowSupplier.hpp>
30#include <com/sun/star/embed/EmbedVerbs.hpp>
31#include <com/sun/star/embed/XEmbeddedOleObject.hpp>
32#include <com/sun/star/embed/XEmbeddedObject.hpp>
33#include <com/sun/star/beans/XPropertySet.hpp>
34#include <com/sun/star/beans/PropertyValue.hpp>
35#include <com/sun/star/embed/XStateChangeListener.hpp>
36#include <com/sun/star/embed/StateChangeInProgressException.hpp>
37#include <com/sun/star/embed/XLinkageSupport.hpp>
38#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
39#include <com/sun/star/task/ErrorCodeIOException.hpp>
40#include <com/sun/star/task/StatusIndicatorFactory.hpp>
41#include <com/sun/star/task/XStatusIndicator.hpp>
43#include <com/sun/star/embed/EmbedMisc.hpp>
69#include <LibreOfficeKit/LibreOfficeKitEnums.h>
71#define SFX_CLIENTACTIVATE_TIMEOUT 100
78class SfxBooleanFlagGuard
82 explicit SfxBooleanFlagGuard(
bool& bFlag)
88 ~SfxBooleanFlagGuard()
109 embed::XInplaceClient,
110 document::XEventListener,
111 embed::XStateChangeListener,
112 embed::XWindowSupplier >
140 uno::Reference < frame::XFrame >
const &
GetFrame()
const;
152 virtual uno::Reference< css::frame::XLayoutManager > SAL_CALL
getLayoutManager()
override;
154 virtual awt::Rectangle SAL_CALL
getPlacement()
override;
157 virtual void SAL_CALL
scrollObject(
const awt::Size& aOffset )
override;
158 virtual void SAL_CALL
changedPlacement(
const awt::Rectangle& aPosRect )
override;
161 virtual uno::Reference< util::XCloseable > SAL_CALL
getComponent()
override;
164 virtual uno::Reference< awt::XWindow > SAL_CALL
getWindow()
override;
167 virtual void SAL_CALL
notifyEvent(
const document::EventObject& aEvent )
override;
170 virtual void SAL_CALL
changingState(
const css::lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState )
override;
171 virtual void SAL_CALL
stateChanged(
const css::lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState )
override;
172 virtual void SAL_CALL
disposing(
const css::lang::EventObject& aEvent )
override;
176 const css::lang::EventObject& ,
183 const css::lang::EventObject& ,
184 ::sal_Int32 nOldState,
185 ::sal_Int32 nNewState )
187 if (
m_pClient && nOldState != embed::EmbedStates::LOADED && nNewState == embed::EmbedStates::RUNNING )
190 uno::Reference< frame::XModel > xDocument;
220 throw uno::RuntimeException();
232 uno::Reference< embed::XCommonEmbedPersist > xPersist(
m_xObject, uno::UNO_QUERY_THROW );
234 uno::Reference< frame::XFrame >
xFrame;
235 uno::Reference< task::XStatusIndicator > xStatusIndicator;
236 uno::Reference< frame::XModel >
xModel(
m_xObject->getComponent(), uno::UNO_QUERY );
237 uno::Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
241 uno::Reference< frame::XController >
xController =
xModel->getCurrentController();
250 uno::Reference< task::XStatusIndicatorFactory > xStatusIndicatorFactory =
251 task::StatusIndicatorFactory::createWithFrame( xContext,
xFrame,
true,
false );
253 uno::Reference< beans::XPropertySet > xPropSet(
xFrame, uno::UNO_QUERY );
258 xStatusIndicator = xStatusIndicatorFactory->createStatusIndicator();
259 xPropSet->setPropertyValue(
"IndicatorInterception" ,
uno::Any( xStatusIndicator ));
261 catch (
const uno::RuntimeException& )
265 catch ( uno::Exception& )
273 xPersist->storeOwn();
276 catch ( uno::Exception& )
284 uno::Reference< beans::XPropertySet > xPropSet(
xFrame, uno::UNO_QUERY );
287 xStatusIndicator.clear();
288 xPropSet->setPropertyValue(
"IndicatorInterception" ,
uno::Any( xStatusIndicator ));
291 catch (
const uno::RuntimeException& )
295 catch ( uno::Exception& )
301 throw uno::RuntimeException();
305 throw uno::RuntimeException();
320 throw uno::RuntimeException();
333 throw uno::RuntimeException();
336 if (
m_xObject->getCurrentState() == embed::EmbedStates::ACTIVE ||
m_nAspect == embed::Aspects::MSOLE_ICON )
346 throw uno::RuntimeException();
362 pViewShell->libreOfficeKitViewCallback( LOK_CALLBACK_GRAPHIC_SELECTION, str );
371 throw uno::RuntimeException();
382 throw uno::RuntimeException();
387 pViewShell->libreOfficeKitViewCallback( LOK_CALLBACK_GRAPHIC_SELECTION,
"INPLACE EXIT" );
396 throw uno::RuntimeException();
405 uno::Reference < beans::XPropertySet >
xFrame(
GetFrame(), uno::UNO_QUERY_THROW );
407 uno::Reference< css::frame::XLayoutManager > xMan;
413 catch ( uno::Exception&
ex )
416 throw css::lang::WrappedTargetRuntimeException(
ex.Message,
426 return uno::Reference < frame::XDispatchProvider >(
GetFrame(), uno::UNO_QUERY_THROW );
433 throw uno::RuntimeException();
450 if (!bMapModeEnabled)
468 throw uno::RuntimeException();
480 if (!bMapModeEnabled)
498 throw uno::RuntimeException();
507 throw uno::RuntimeException();
513 uno::Reference< embed::XInplaceObject > xInplace(
m_xObject, uno::UNO_QUERY_THROW );
515 throw uno::RuntimeException();
521 if ( aOldPixelRect == aNewPixelRect )
547 aNewLogicRect.
SetSize( aNewObjSize );
563 throw uno::RuntimeException();
567 throw uno::RuntimeException();
570 uno::Reference< util::XCloseable > xComp( pDocShell->
GetModel(), uno::UNO_QUERY_THROW );
580 throw uno::RuntimeException();
592 throw uno::RuntimeException();
596 && (
m_xObject->getCurrentState() == embed::EmbedStates::INPLACE_ACTIVE
597 ||
m_xObject->getCurrentState() == embed::EmbedStates::UI_ACTIVE ) )
600 uno::Reference< embed::XInplaceObject > xInplace(
m_xObject, uno::UNO_QUERY_THROW );
617 catch( uno::Exception& )
626 if ( m_pClient && m_xObject.is() )
628 m_pClient->GetViewShell()->CheckIPClient_Impl(m_pClient,
629 m_pClient->GetViewShell()->GetObjectShell()->GetVisArea());
639 m_pViewSh( pViewShell ),
643 m_xImp->m_nAspect = nAspect;
656 m_xImp->m_bStoreObject =
false;
659 m_xImp->m_pClient =
nullptr;
676 if (
m_xImp->m_nAspect == embed::Aspects::MSOLE_ICON
677 && (
nState == embed::EmbedStates::UI_ACTIVE ||
nState == embed::EmbedStates::INPLACE_ACTIVE ) )
679 OSL_FAIL(
"Iconified object should not be activated inplace!" );
687 catch ( uno::Exception& )
708 if (
m_xImp->m_xObject.is() && rObject !=
m_xImp->m_xObject )
713 if (
GetObject()->getCurrentState() != embed::EmbedStates::LOADED )
719 m_xImp->m_xObject->setClientSite(
nullptr );
721 catch( uno::Exception& )
723 OSL_FAIL(
"Can not clean the client site!" );
732 m_xImp->m_xObject = rObject;
738 rObject->addStateChangeListener(
m_xImp );
739 rObject->addEventListener(
m_xImp );
743 rObject->setClientSite(
m_xImp );
745 catch( uno::Exception& )
747 OSL_FAIL(
"Can not set the client site!" );
759 if( rArea !=
m_xImp->m_aObjArea )
761 m_xImp->m_aObjArea = rArea;
774 return m_xImp->m_aObjArea;
788 if (
m_xImp->m_aScaleWidth != rScaleWidth ||
m_xImp->m_aScaleHeight != rScaleHeight )
790 m_xImp->m_aScaleWidth = rScaleWidth;
791 m_xImp->m_aScaleHeight = rScaleHeight;
804 if( rArea !=
m_xImp->m_aObjArea ||
m_xImp->m_aScaleWidth != rScaleWidth ||
m_xImp->m_aScaleHeight != rScaleHeight )
806 m_xImp->m_aObjArea = rArea;
807 m_xImp->m_aScaleWidth = rScaleWidth;
808 m_xImp->m_aScaleHeight = rScaleHeight;
819 return m_xImp->m_aScaleWidth;
825 return m_xImp->m_aScaleHeight;
847 return (
m_xImp->m_xObject.is() && (
m_xImp->m_xObject->getCurrentState() == embed::EmbedStates::UI_ACTIVE ) );
849 catch( uno::Exception& )
862 (
m_xImp->m_xObject->getCurrentState() == embed::EmbedStates::INPLACE_ACTIVE)
866 (
m_xImp->m_xObject->getCurrentState() == embed::EmbedStates::UI_ACTIVE)
870 catch( uno::Exception& )
881 if( pFrame->GetViewShell() )
902 if (
m_xImp->m_xObject.is() )
904 bool bSaveCopyAs =
false;
909 uno::Reference< frame::XModel > xEmbModel(
m_xImp->m_xObject->getComponent(), uno::UNO_QUERY );
910 if ( xEmbModel.is() )
917 uno::Sequence< beans::PropertyValue > aDispatchArgs{
921 aHelper.GUIStoreModel( xEmbModel,
928 catch(
const task::ErrorCodeIOException& aErrorEx )
930 nError =
ErrCode(aErrorEx.ErrCode);
932 catch( uno::Exception& )
942 if (
m_xImp->m_nAspect == embed::Aspects::MSOLE_ICON )
946 uno::Reference< embed::XEmbeddedOleObject > xEmbeddedOleObject(
m_xImp->m_xObject, uno::UNO_QUERY );
948 if ( xEmbeddedOleObject.is() && (nVerb == embed::EmbedVerbs::MS_OLEVERB_PRIMARY || nVerb == embed::EmbedVerbs::MS_OLEVERB_OPEN || nVerb == embed::EmbedVerbs::MS_OLEVERB_SHOW ))
949 nVerb = embed::EmbedVerbs::MS_OLEVERB_SHOW;
950 else if ( nVerb == embed::EmbedVerbs::MS_OLEVERB_PRIMARY || nVerb == embed::EmbedVerbs::MS_OLEVERB_SHOW )
951 nVerb = embed::EmbedVerbs::MS_OLEVERB_OPEN;
952 else if ( nVerb == embed::EmbedVerbs::MS_OLEVERB_UIACTIVATE
953 || nVerb == embed::EmbedVerbs::MS_OLEVERB_IPACTIVATE )
971 m_xImp->m_xObject->doVerb( nVerb );
973 catch ( embed::UnreachableStateException& )
975 if (nVerb == embed::EmbedVerbs::MS_OLEVERB_PRIMARY || nVerb == embed::EmbedVerbs::MS_OLEVERB_OPEN || nVerb == embed::EmbedVerbs::MS_OLEVERB_SHOW)
980 m_xImp->m_xObject->doVerb( -9 );
982 if (
m_xImp->m_xObject->getCurrentState() == embed::EmbedStates::UI_ACTIVE )
985 awt::Size aSize =
m_xImp->m_xObject->getVisualAreaSize(
m_xImp->m_nAspect );
991 m_xImp->m_aObjArea.SetSize( aNewSize );
996 catch (uno::Exception
const&)
1003 catch ( embed::StateChangeInProgressException& )
1008 catch (uno::Exception
const&)
1035 uno::Reference < embed::XInplaceObject > xObj(
m_xImp->m_xObject, uno::UNO_QUERY );
1037 m_xImp->SizeHasChanged();
1069 m_xImp->m_bUIActive =
false;
1070 bool bHasFocus =
false;
1071 uno::Reference< frame::XModel >
xModel(
m_xImp->m_xObject->getComponent(), uno::UNO_QUERY );
1074 uno::Reference< frame::XController >
xController =
xModel->getCurrentController();
1078 bHasFocus = pWindow->HasChildPathFocus(
true );
1084 if (
m_xImp->m_xObject->getStatus(
m_xImp->m_nAspect ) & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE )
1086 m_xImp->m_xObject->changeState( embed::EmbedStates::INPLACE_ACTIVE );
1093 uno::Reference< embed::XLinkageSupport > xLink(
m_xImp->m_xObject, uno::UNO_QUERY );
1094 if ( xLink.is() && xLink->isLink() )
1095 m_xImp->m_xObject->changeState( embed::EmbedStates::LOADED );
1097 m_xImp->m_xObject->changeState( embed::EmbedStates::RUNNING );
1105 catch (css::uno::Exception& )
1116 m_xImp->m_bUIActive =
false;
1117 if (
m_xImp->m_xObject->getStatus(
m_xImp->m_nAspect ) & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE )
1118 m_xImp->m_xObject->changeState( embed::EmbedStates::INPLACE_ACTIVE );
1122 uno::Reference< embed::XLinkageSupport > xLink(
m_xImp->m_xObject, uno::UNO_QUERY );
1123 if ( xLink.is() && xLink->isLink() )
1124 m_xImp->m_xObject->changeState( embed::EmbedStates::LOADED );
1126 m_xImp->m_xObject->changeState( embed::EmbedStates::RUNNING );
1129 catch (css::uno::Exception& )
1135 return m_xImp->m_bUIActive;
1140 m_xImp->m_bNegativeX = bSet;
1145 return m_xImp->m_bNegativeX;
static DialogMask HandleError(ErrCode nId, weld::Window *pParent=nullptr, DialogMask nMask=DialogMask::MAX)
MapUnit GetMapUnit() const
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
bool IsClosing_Impl() const
SAL_DLLPRIVATE void LockResize_Impl(bool bLock)
virtual void SAL_CALL disposing(const css::lang::EventObject &aEvent) override
uno::Reference< embed::XEmbeddedObject > m_xObject
virtual awt::Rectangle SAL_CALL getClipRectangle() override
virtual void SAL_CALL activatingInplace() override
virtual void SAL_CALL stateChanged(const css::lang::EventObject &aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState) override
SfxInPlaceClient * m_pClient
virtual void SAL_CALL visibilityChanged(sal_Bool bVisible) override
virtual awt::Rectangle SAL_CALL getPlacement() override
virtual void SAL_CALL notifyEvent(const document::EventObject &aEvent) override
virtual void SAL_CALL changedPlacement(const awt::Rectangle &aPosRect) override
virtual uno::Reference< frame::XDispatchProvider > SAL_CALL getInplaceDispatchProvider() override
virtual void SAL_CALL deactivatedInplace() override
virtual uno::Reference< util::XCloseable > SAL_CALL getComponent() override
virtual void SAL_CALL activatingUI() override
virtual void SAL_CALL scrollObject(const awt::Size &aOffset) override
virtual uno::Reference< awt::XWindow > SAL_CALL getWindow() override
virtual void SAL_CALL saveObject() override
virtual void SAL_CALL deactivatedUI() override
virtual void SAL_CALL translateAccelerators(const uno::Sequence< awt::KeyEvent > &aKeys) override
virtual void SAL_CALL changingState(const css::lang::EventObject &aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState) override
tools::Rectangle m_aObjArea
uno::Reference< frame::XFrame > const & GetFrame() const
virtual sal_Bool SAL_CALL canInplaceActivate() override
DECL_LINK(TimerHdl, Timer *, void)
virtual uno::Reference< css::frame::XLayoutManager > SAL_CALL getLayoutManager() override
void SetNegativeX(bool bSet)
To indicate that negated document X coordinates are used.
sal_Int64 GetObjectMiscStatus() const
bool SetObjArea(const tools::Rectangle &)
VclPtr< vcl::Window > m_pEditWin
void SetObjectState(sal_Int32)
void SetObjAreaAndScale(const tools::Rectangle &, const Fraction &, const Fraction &)
const css::uno::Reference< css::embed::XEmbeddedObject > & GetObject() const
virtual void FormatChanged()
virtual SAL_DLLPRIVATE void ObjectAreaChanged()
const Fraction & GetScaleHeight() const
virtual SAL_DLLPRIVATE void ViewChanged()
void SetObject(const css::uno::Reference< css::embed::XEmbeddedObject > &rObject)
virtual SAL_DLLPRIVATE void RequestNewObjectArea(tools::Rectangle &)
vcl::Window * GetEditWin() const
const tools::Rectangle & GetObjArea() const
tools::Rectangle GetScaledObjArea() const
bool IsObjectUIActive() const
void SetSizeScale(const Fraction &rScaleWidth, const Fraction &rScaleHeight)
rtl::Reference< SfxInPlaceClient_Impl > m_xImp
virtual ~SfxInPlaceClient()
bool IsObjectInPlaceActive() const
ErrCode DoVerb(sal_Int32 nVerb)
SfxInPlaceClient(SfxViewShell *pViewShell, vcl::Window *pDraw, sal_Int64 nAspect)
const Fraction & GetScaleWidth() const
static SfxInPlaceClient * GetClient(SfxObjectShell const *pDoc, const css::uno::Reference< css::embed::XEmbeddedObject > &xObject)
SfxViewShell * GetViewShell() const
virtual bool IsProtected() const
sal_Int64 GetAspect() const
static void SetCurrentComponent(const css::uno::Reference< css::uno::XInterface > &_rxComponent)
css::uno::Reference< css::frame::XModel3 > GetModel() const
virtual void SetModified(bool bModified=true)
static SAL_WARN_UNUSED_RESULT SfxViewFrame * GetNext(const SfxViewFrame &rPrev, const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
static SAL_WARN_UNUSED_RESULT SfxViewFrame * GetFirst(const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
SfxFrame & GetFrame() const
static void SetViewFrame(SfxViewFrame *)
One SfxViewShell more or less represents one edit window for a document, there can be multiple ones f...
weld::Window * GetFrameWeld() const
virtual void UIActivating(SfxInPlaceClient *pClient)
SfxViewFrame & GetViewFrame() const
SfxInPlaceClient * FindIPClient(const css::uno::Reference< css::embed::XEmbeddedObject > &xObj, vcl::Window *pObjParentWin) const
SAL_DLLPRIVATE void IPClientGone_Impl(SfxInPlaceClient const *pIPClient)
void OutplaceActivated(bool bActive)
virtual SfxObjectShell * GetObjectShell() override
SAL_DLLPRIVATE void NewIPClient_Impl(SfxInPlaceClient *pIPClient)
SAL_DLLPRIVATE void ResetAllClients_Impl(SfxInPlaceClient const *pIP)
vcl::Window * GetWindow() const
virtual void UIDeactivated(SfxInPlaceClient *pClient)
constexpr tools::Long Height() const
constexpr tools::Long Width() const
static MapUnit UnoEmbed2VCLMapUnit(sal_Int32 nUnoEmbedMapUnit)
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
static bool TryRunningState(const css::uno::Reference< css::embed::XEmbeddedObject > &)
Point LogicToPixel(const Point &rLogicPt) const
Size LogicToLogic(const Size &rSzSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
bool IsMapModeEnabled() const
const MapMode & GetMapMode() const
virtual css::uno::Reference< css::awt::XVclWindowPeer > GetComponentInterface(bool bCreate=true)
Point PixelToLogic(const Point &rDevicePt) const
void EnableMapMode(bool bEnable=true)
css::awt::Rectangle AWTRectangle(const ::tools::Rectangle &rVCLRect)
inline ::tools::Rectangle VCLRectangle(const css::awt::Rectangle &rAWTRect)
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define ERRCODE_IO_GENERAL
IMPL_LINK_NOARG(SfxInPlaceClient_Impl, TimerHdl, Timer *, void)
#define SFX_CLIENTACTIVATE_TIMEOUT
#define LINK(Instance, Class, Member)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
Any SAL_CALL getCaughtException()
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
OUString toString(OptionInfo const *info)
#define ERRCODE_SO_CANNOT_DOVERB_NOW
#define ERRCODE_SO_GENERALERROR
SVT_DLLPUBLIC const ErrMsgCode RID_SO_ERRCTX[]
Reference< XController > xController
Reference< XFrame > xFrame
Reference< XModel > xModel