xref: /aoo41x/main/sfx2/source/view/ipclient.cxx (revision d119d52d)
1*d119d52dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*d119d52dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*d119d52dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*d119d52dSAndrew Rist  * distributed with this work for additional information
6*d119d52dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*d119d52dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*d119d52dSAndrew Rist  * "License"); you may not use this file except in compliance
9*d119d52dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*d119d52dSAndrew Rist  *
11*d119d52dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*d119d52dSAndrew Rist  *
13*d119d52dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*d119d52dSAndrew Rist  * software distributed under the License is distributed on an
15*d119d52dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d119d52dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*d119d52dSAndrew Rist  * specific language governing permissions and limitations
18*d119d52dSAndrew Rist  * under the License.
19*d119d52dSAndrew Rist  *
20*d119d52dSAndrew Rist  *************************************************************/
21*d119d52dSAndrew Rist 
22*d119d52dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
26cdf0e10cSrcweir #include <com/sun/star/embed/EmbedStates.hpp>
27cdf0e10cSrcweir #include <com/sun/star/embed/XVisualObject.hpp>
28cdf0e10cSrcweir #include <com/sun/star/embed/XEmbeddedClient.hpp>
29cdf0e10cSrcweir #include <com/sun/star/embed/XInplaceClient.hpp>
30cdf0e10cSrcweir #include <com/sun/star/embed/XInplaceObject.hpp>
31cdf0e10cSrcweir #include <com/sun/star/embed/XComponentSupplier.hpp>
32cdf0e10cSrcweir #include <com/sun/star/embed/XWindowSupplier.hpp>
33cdf0e10cSrcweir #include <com/sun/star/embed/XEmbedPersist.hpp>
34cdf0e10cSrcweir #include <com/sun/star/embed/EmbedVerbs.hpp>
35cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp>
36cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
37cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
38cdf0e10cSrcweir #include <com/sun/star/embed/XStateChangeListener.hpp>
39cdf0e10cSrcweir #include <com/sun/star/embed/StateChangeInProgressException.hpp>
40cdf0e10cSrcweir #include <com/sun/star/embed/XLinkageSupport.hpp>
41cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
42cdf0e10cSrcweir #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
43cdf0e10cSrcweir #include <com/sun/star/task/XStatusIndicator.hpp>
44cdf0e10cSrcweir 
45cdf0e10cSrcweir #include <com/sun/star/embed/EmbedMisc.hpp>
46cdf0e10cSrcweir #include <svtools/embedhlp.hxx>
47cdf0e10cSrcweir #include <vcl/svapp.hxx>
48cdf0e10cSrcweir 
49cdf0e10cSrcweir #include <sfx2/ipclient.hxx>
50cdf0e10cSrcweir #include <sfx2/viewsh.hxx>
51cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
52cdf0e10cSrcweir #include <sfx2/objsh.hxx>
53cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
54cdf0e10cSrcweir #include "workwin.hxx"
55cdf0e10cSrcweir #include "guisaveas.hxx"
56cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
57cdf0e10cSrcweir #include <cppuhelper/implbase5.hxx>
58cdf0e10cSrcweir #include <vcl/salbtype.hxx>
59cdf0e10cSrcweir #include <svtools/ehdl.hxx>
60cdf0e10cSrcweir 
61cdf0e10cSrcweir #include <vcl/timer.hxx>
62cdf0e10cSrcweir #include <vcl/window.hxx>
63cdf0e10cSrcweir #include <toolkit/awt/vclxwindow.hxx>
64cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
65cdf0e10cSrcweir #include <toolkit/helper/convert.hxx>
66cdf0e10cSrcweir #include <tools/fract.hxx>
67cdf0e10cSrcweir #include <tools/gen.hxx>
68cdf0e10cSrcweir #include <svl/rectitem.hxx>
69cdf0e10cSrcweir #include <svtools/soerr.hxx>
70cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
71cdf0e10cSrcweir 
72cdf0e10cSrcweir #define SFX_CLIENTACTIVATE_TIMEOUT 100
73cdf0e10cSrcweir 
74cdf0e10cSrcweir using namespace com::sun::star;
75cdf0e10cSrcweir 
76cdf0e10cSrcweir //====================================================================
77cdf0e10cSrcweir // SfxEmbedResizeGuard
78cdf0e10cSrcweir class SfxBooleanFlagGuard
79cdf0e10cSrcweir {
80cdf0e10cSrcweir 	sal_Bool& m_rFlag;
81cdf0e10cSrcweir 	sal_Bool m_bLifeValue;
82cdf0e10cSrcweir public:
SfxBooleanFlagGuard(sal_Bool & bFlag,sal_Bool bLifeValue)83cdf0e10cSrcweir 	SfxBooleanFlagGuard( sal_Bool& bFlag, sal_Bool bLifeValue )
84cdf0e10cSrcweir 	: m_rFlag( bFlag )
85cdf0e10cSrcweir 	, m_bLifeValue( bLifeValue )
86cdf0e10cSrcweir 	{
87cdf0e10cSrcweir 		m_rFlag = m_bLifeValue;
88cdf0e10cSrcweir 	}
89cdf0e10cSrcweir 
~SfxBooleanFlagGuard()90cdf0e10cSrcweir 	~SfxBooleanFlagGuard()
91cdf0e10cSrcweir 	{
92cdf0e10cSrcweir 		m_rFlag = !m_bLifeValue;
93cdf0e10cSrcweir 	}
94cdf0e10cSrcweir };
95cdf0e10cSrcweir 
96cdf0e10cSrcweir //====================================================================
97cdf0e10cSrcweir // SfxInPlaceClient_Impl
98cdf0e10cSrcweir 
99cdf0e10cSrcweir //--------------------------------------------------------------------
100cdf0e10cSrcweir class SfxInPlaceClient_Impl : public ::cppu::WeakImplHelper5< embed::XEmbeddedClient,
101cdf0e10cSrcweir 															  embed::XInplaceClient,
102cdf0e10cSrcweir                                                               document::XEventListener,
103cdf0e10cSrcweir                                                               embed::XStateChangeListener,
104cdf0e10cSrcweir 															  embed::XWindowSupplier >
105cdf0e10cSrcweir {
106cdf0e10cSrcweir public:
107cdf0e10cSrcweir     Timer                           m_aTimer;               // activation timeout, starts after object connection
108cdf0e10cSrcweir     Rectangle                       m_aObjArea;             // area of object in coordinate system of the container (without scaling)
109cdf0e10cSrcweir     Fraction                        m_aScaleWidth;          // scaling that was applied to the object when it was not active
110cdf0e10cSrcweir     Fraction                        m_aScaleHeight;
111cdf0e10cSrcweir     SfxInPlaceClient*               m_pClient;
112cdf0e10cSrcweir     sal_Int64                       m_nAspect;              // ViewAspect that is assigned from the container
113cdf0e10cSrcweir     Rectangle                       m_aLastObjAreaPixel;    // area of object in coordinate system of the container (without scaling)
114cdf0e10cSrcweir     sal_Bool                        m_bStoreObject;
115cdf0e10cSrcweir     sal_Bool                        m_bUIActive;            // set and cleared when notification for UI (de)activation is sent
116cdf0e10cSrcweir 	sal_Bool						m_bResizeNoScale;
117cdf0e10cSrcweir 
118cdf0e10cSrcweir     uno::Reference < embed::XEmbeddedObject > m_xObject;
119cdf0e10cSrcweir     uno::Reference < embed::XEmbeddedClient > m_xClient;
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 
SfxInPlaceClient_Impl()122cdf0e10cSrcweir 	SfxInPlaceClient_Impl()
123cdf0e10cSrcweir 	: m_pClient( NULL )
124cdf0e10cSrcweir 	, m_nAspect( 0 )
125cdf0e10cSrcweir 	, m_bStoreObject( sal_True )
126cdf0e10cSrcweir 	, m_bUIActive( sal_False )
127cdf0e10cSrcweir 	, m_bResizeNoScale( sal_False )
128cdf0e10cSrcweir 	{}
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 	~SfxInPlaceClient_Impl();
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 	void SizeHasChanged();
133cdf0e10cSrcweir     DECL_LINK           (TimerHdl, Timer*);
134cdf0e10cSrcweir     uno::Reference < frame::XFrame > GetFrame() const;
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 	// XEmbeddedClient
137cdf0e10cSrcweir     virtual void SAL_CALL saveObject() throw ( embed::ObjectSaveVetoException, uno::Exception, uno::RuntimeException );
138cdf0e10cSrcweir     virtual void SAL_CALL visibilityChanged( sal_Bool bVisible ) throw ( embed::WrongStateException, uno::RuntimeException );
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 	// XInplaceClient
141cdf0e10cSrcweir     virtual sal_Bool SAL_CALL canInplaceActivate() throw ( uno::RuntimeException );
142cdf0e10cSrcweir     virtual void SAL_CALL activatingInplace() throw ( embed::WrongStateException, uno::RuntimeException );
143cdf0e10cSrcweir     virtual void SAL_CALL activatingUI() throw ( embed::WrongStateException, uno::RuntimeException );
144cdf0e10cSrcweir     virtual void SAL_CALL deactivatedInplace() throw ( embed::WrongStateException, uno::RuntimeException );
145cdf0e10cSrcweir     virtual void SAL_CALL deactivatedUI() throw ( embed::WrongStateException, uno::RuntimeException );
146cdf0e10cSrcweir     virtual uno::Reference< ::com::sun::star::frame::XLayoutManager > SAL_CALL getLayoutManager() throw ( embed::WrongStateException, uno::RuntimeException );
147cdf0e10cSrcweir     virtual uno::Reference< frame::XDispatchProvider > SAL_CALL getInplaceDispatchProvider() throw ( embed::WrongStateException, uno::RuntimeException );
148cdf0e10cSrcweir     virtual awt::Rectangle SAL_CALL getPlacement() throw ( embed::WrongStateException, uno::RuntimeException );
149cdf0e10cSrcweir     virtual awt::Rectangle SAL_CALL getClipRectangle() throw ( embed::WrongStateException, uno::RuntimeException );
150cdf0e10cSrcweir     virtual void SAL_CALL translateAccelerators( const uno::Sequence< awt::KeyEvent >& aKeys ) throw ( embed::WrongStateException, uno::RuntimeException );
151cdf0e10cSrcweir     virtual void SAL_CALL scrollObject( const awt::Size& aOffset ) throw ( embed::WrongStateException, uno::RuntimeException );
152cdf0e10cSrcweir     virtual void SAL_CALL changedPlacement( const awt::Rectangle& aPosRect ) throw ( embed::WrongStateException, uno::Exception, uno::RuntimeException );
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 	// XComponentSupplier
155cdf0e10cSrcweir     virtual uno::Reference< util::XCloseable > SAL_CALL getComponent() throw ( uno::RuntimeException );
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 	// XWindowSupplier
158cdf0e10cSrcweir     virtual uno::Reference< awt::XWindow > SAL_CALL getWindow() throw ( uno::RuntimeException );
159cdf0e10cSrcweir 
160cdf0e10cSrcweir     // document::XEventListener
161cdf0e10cSrcweir     virtual void SAL_CALL       notifyEvent( const document::EventObject& aEvent ) throw( uno::RuntimeException );
162cdf0e10cSrcweir 
163cdf0e10cSrcweir     // XStateChangeListener
164cdf0e10cSrcweir     virtual void SAL_CALL changingState( const ::com::sun::star::lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (::com::sun::star::embed::WrongStateException, ::com::sun::star::uno::RuntimeException);
165cdf0e10cSrcweir     virtual void SAL_CALL stateChanged( const ::com::sun::star::lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (::com::sun::star::uno::RuntimeException);
166cdf0e10cSrcweir     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
167cdf0e10cSrcweir };
168cdf0e10cSrcweir 
~SfxInPlaceClient_Impl()169cdf0e10cSrcweir SfxInPlaceClient_Impl::~SfxInPlaceClient_Impl()
170cdf0e10cSrcweir {
171cdf0e10cSrcweir }
172cdf0e10cSrcweir 
changingState(const::com::sun::star::lang::EventObject &,::sal_Int32,::sal_Int32)173cdf0e10cSrcweir void SAL_CALL SfxInPlaceClient_Impl::changingState(
174cdf0e10cSrcweir     const ::com::sun::star::lang::EventObject& /*aEvent*/,
175cdf0e10cSrcweir     ::sal_Int32 /*nOldState*/,
176cdf0e10cSrcweir     ::sal_Int32 /*nNewState*/ )
177cdf0e10cSrcweir throw (::com::sun::star::embed::WrongStateException, ::com::sun::star::uno::RuntimeException)
178cdf0e10cSrcweir {
179cdf0e10cSrcweir }
180cdf0e10cSrcweir 
stateChanged(const::com::sun::star::lang::EventObject &,::sal_Int32 nOldState,::sal_Int32 nNewState)181cdf0e10cSrcweir void SAL_CALL SfxInPlaceClient_Impl::stateChanged(
182cdf0e10cSrcweir     const ::com::sun::star::lang::EventObject& /*aEvent*/,
183cdf0e10cSrcweir     ::sal_Int32 nOldState,
184cdf0e10cSrcweir     ::sal_Int32 nNewState )
185cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
186cdf0e10cSrcweir {
187cdf0e10cSrcweir     if ( m_pClient && nOldState != embed::EmbedStates::LOADED && nNewState == embed::EmbedStates::RUNNING )
188cdf0e10cSrcweir     {
189cdf0e10cSrcweir         // deactivation of object
190cdf0e10cSrcweir         uno::Reference< frame::XModel > xDocument;
191cdf0e10cSrcweir         if ( m_pClient->GetViewShell()->GetObjectShell() )
192cdf0e10cSrcweir             xDocument = m_pClient->GetViewShell()->GetObjectShell()->GetModel();
193cdf0e10cSrcweir         SfxObjectShell::SetCurrentComponent( xDocument );
194cdf0e10cSrcweir     }
195cdf0e10cSrcweir     else if ( m_pClient && nNewState == embed::EmbedStates::UI_ACTIVE )
196cdf0e10cSrcweir     {
197cdf0e10cSrcweir /*
198cdf0e10cSrcweir         uno::Reference < lang::XUnoTunnel > xObj( m_xObject->getComponent(), uno::UNO_QUERY );
199cdf0e10cSrcweir         uno::Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
200cdf0e10cSrcweir         sal_Int64 nHandle = xObj.is() ? xObj->getSomething( aSeq ) : 0;
201cdf0e10cSrcweir         if ( nHandle )
202cdf0e10cSrcweir         {
203cdf0e10cSrcweir             // currently needs SFX code
204cdf0e10cSrcweir             SfxObjectShell* pDoc = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
205cdf0e10cSrcweir             SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDoc );
206cdf0e10cSrcweir             SfxWorkWindow *pWorkWin = pFrame->GetFrame().GetWorkWindow_Impl();
207cdf0e10cSrcweir             pWorkWin->UpdateObjectBars_Impl();
208cdf0e10cSrcweir         }
209cdf0e10cSrcweir */
210cdf0e10cSrcweir     }
211cdf0e10cSrcweir }
212cdf0e10cSrcweir 
notifyEvent(const document::EventObject & aEvent)213cdf0e10cSrcweir void SAL_CALL SfxInPlaceClient_Impl::notifyEvent( const document::EventObject& aEvent ) throw( uno::RuntimeException )
214cdf0e10cSrcweir {
215cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
216cdf0e10cSrcweir 
217cdf0e10cSrcweir     if ( m_pClient && aEvent.EventName.equalsAscii("OnVisAreaChanged") && m_nAspect != embed::Aspects::MSOLE_ICON )
218cdf0e10cSrcweir     {
219cdf0e10cSrcweir         m_pClient->FormatChanged(); // for Writer when format of the object is changed with the area
220cdf0e10cSrcweir         m_pClient->ViewChanged();
221cdf0e10cSrcweir         m_pClient->Invalidate();
222cdf0e10cSrcweir     }
223cdf0e10cSrcweir }
224cdf0e10cSrcweir 
disposing(const::com::sun::star::lang::EventObject &)225cdf0e10cSrcweir void SAL_CALL SfxInPlaceClient_Impl::disposing( const ::com::sun::star::lang::EventObject& /*aEvent*/ )
226cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
227cdf0e10cSrcweir {
228cdf0e10cSrcweir     DELETEZ( m_pClient );
229cdf0e10cSrcweir }
230cdf0e10cSrcweir 
231cdf0e10cSrcweir // XEmbeddedClient
232cdf0e10cSrcweir //--------------------------------------------------------------------
GetFrame() const233cdf0e10cSrcweir uno::Reference < frame::XFrame > SfxInPlaceClient_Impl::GetFrame() const
234cdf0e10cSrcweir {
235cdf0e10cSrcweir 	if ( !m_pClient )
236cdf0e10cSrcweir 		throw uno::RuntimeException();
237cdf0e10cSrcweir     return m_pClient->GetViewShell()->GetViewFrame()->GetFrame().GetFrameInterface();
238cdf0e10cSrcweir }
239cdf0e10cSrcweir 
saveObject()240cdf0e10cSrcweir void SAL_CALL SfxInPlaceClient_Impl::saveObject()
241cdf0e10cSrcweir 	throw ( embed::ObjectSaveVetoException,
242cdf0e10cSrcweir 			uno::Exception,
243cdf0e10cSrcweir 			uno::RuntimeException )
244cdf0e10cSrcweir {
245cdf0e10cSrcweir     if ( !m_bStoreObject )
246cdf0e10cSrcweir         // client wants to discard the object (usually it means the container document is closed while an object is active
247cdf0e10cSrcweir         // and the user didn't request saving the changes
248cdf0e10cSrcweir         return;
249cdf0e10cSrcweir 
250cdf0e10cSrcweir 	// the common persistance is supported by objects and links
251cdf0e10cSrcweir 	uno::Reference< embed::XCommonEmbedPersist > xPersist( m_xObject, uno::UNO_QUERY );
252cdf0e10cSrcweir 	if ( !xPersist.is() )
253cdf0e10cSrcweir 		throw uno::RuntimeException();
254cdf0e10cSrcweir 
255cdf0e10cSrcweir     uno::Reference< frame::XFrame >              xFrame;
256cdf0e10cSrcweir     uno::Reference< task::XStatusIndicator >     xStatusIndicator;
257cdf0e10cSrcweir     uno::Reference< frame::XModel >              xModel( m_xObject->getComponent(), uno::UNO_QUERY );
258cdf0e10cSrcweir     uno::Reference< lang::XMultiServiceFactory > xSrvMgr( ::comphelper::getProcessServiceFactory() );
259cdf0e10cSrcweir 
260cdf0e10cSrcweir     if ( xModel.is() )
261cdf0e10cSrcweir     {
262cdf0e10cSrcweir         uno::Reference< frame::XController > xController = xModel->getCurrentController();
263cdf0e10cSrcweir         if ( xController.is() )
264cdf0e10cSrcweir             xFrame = xController->getFrame();
265cdf0e10cSrcweir     }
266cdf0e10cSrcweir 
267cdf0e10cSrcweir     if ( xSrvMgr.is() && xFrame.is() )
268cdf0e10cSrcweir     {
269cdf0e10cSrcweir         // set non-reschedule progress to prevent problems when asynchronous calls are made
270cdf0e10cSrcweir         // during storing of the embedded object
271cdf0e10cSrcweir         uno::Reference< lang::XInitialization > xInit(
272cdf0e10cSrcweir             xSrvMgr->createInstance(
273cdf0e10cSrcweir                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.framework.StatusIndicatorFactory" ))),
274cdf0e10cSrcweir             uno::UNO_QUERY_THROW );
275cdf0e10cSrcweir         beans::PropertyValue aProperty;
276cdf0e10cSrcweir         uno::Sequence< uno::Any > aArgs( 2 );
277cdf0e10cSrcweir         aProperty.Name  = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DisableReschedule" ));
278cdf0e10cSrcweir         aProperty.Value = uno::makeAny( sal_True );
279cdf0e10cSrcweir         aArgs[0] = uno::makeAny( aProperty );
280cdf0e10cSrcweir         aProperty.Name  = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
281cdf0e10cSrcweir         aProperty.Value = uno::makeAny( xFrame );
282cdf0e10cSrcweir         aArgs[1] = uno::makeAny( aProperty );
283cdf0e10cSrcweir 
284cdf0e10cSrcweir         xInit->initialize( aArgs );
285cdf0e10cSrcweir 
286cdf0e10cSrcweir         uno::Reference< beans::XPropertySet > xPropSet( xFrame, uno::UNO_QUERY );
287cdf0e10cSrcweir         if ( xPropSet.is() )
288cdf0e10cSrcweir         {
289cdf0e10cSrcweir             try
290cdf0e10cSrcweir             {
291cdf0e10cSrcweir                 uno::Reference< task::XStatusIndicatorFactory > xStatusIndicatorFactory( xInit, uno::UNO_QUERY_THROW );
292cdf0e10cSrcweir                 xStatusIndicator = xStatusIndicatorFactory->createStatusIndicator();
293cdf0e10cSrcweir                 xPropSet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IndicatorInterception" )), uno::makeAny( xStatusIndicator ));
294cdf0e10cSrcweir             }
295cdf0e10cSrcweir             catch ( uno::RuntimeException& e )
296cdf0e10cSrcweir             {
297cdf0e10cSrcweir                 throw e;
298cdf0e10cSrcweir             }
299cdf0e10cSrcweir             catch ( uno::Exception& )
300cdf0e10cSrcweir             {
301cdf0e10cSrcweir             }
302cdf0e10cSrcweir         }
303cdf0e10cSrcweir     }
304cdf0e10cSrcweir 
305cdf0e10cSrcweir     try
306cdf0e10cSrcweir     {
307cdf0e10cSrcweir         xPersist->storeOwn();
308cdf0e10cSrcweir         m_xObject->update();
309cdf0e10cSrcweir     }
310cdf0e10cSrcweir     catch ( uno::Exception& )
311cdf0e10cSrcweir     {
312cdf0e10cSrcweir         //TODO/LATER: what should happen if object can't be saved?!
313cdf0e10cSrcweir     }
314cdf0e10cSrcweir 
315cdf0e10cSrcweir     // reset status indicator interception after storing
316cdf0e10cSrcweir     try
317cdf0e10cSrcweir     {
318cdf0e10cSrcweir         uno::Reference< beans::XPropertySet > xPropSet( xFrame, uno::UNO_QUERY );
319cdf0e10cSrcweir         if ( xPropSet.is() )
320cdf0e10cSrcweir         {
321cdf0e10cSrcweir             xStatusIndicator.clear();
322cdf0e10cSrcweir             xPropSet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IndicatorInterception" )), uno::makeAny( xStatusIndicator ));
323cdf0e10cSrcweir         }
324cdf0e10cSrcweir     }
325cdf0e10cSrcweir     catch ( uno::RuntimeException& e )
326cdf0e10cSrcweir     {
327cdf0e10cSrcweir         throw e;
328cdf0e10cSrcweir     }
329cdf0e10cSrcweir     catch ( uno::Exception& )
330cdf0e10cSrcweir     {
331cdf0e10cSrcweir     }
332cdf0e10cSrcweir 
333cdf0e10cSrcweir     // the client can exist only in case there is a view shell
334cdf0e10cSrcweir 	if ( !m_pClient || !m_pClient->GetViewShell() )
335cdf0e10cSrcweir 		throw uno::RuntimeException();
336cdf0e10cSrcweir 
337cdf0e10cSrcweir 	SfxObjectShell* pDocShell = m_pClient->GetViewShell()->GetObjectShell();
338cdf0e10cSrcweir 	if ( !pDocShell )
339cdf0e10cSrcweir 		throw uno::RuntimeException();
340cdf0e10cSrcweir 
341cdf0e10cSrcweir 	pDocShell->SetModified( sal_True );
342cdf0e10cSrcweir 
343cdf0e10cSrcweir     //TODO/LATER: invalidation might be necessary when object was modified, but is not
344cdf0e10cSrcweir     //saved through this method
345cdf0e10cSrcweir     // m_pClient->Invalidate();
346cdf0e10cSrcweir }
347cdf0e10cSrcweir 
348cdf0e10cSrcweir //--------------------------------------------------------------------
visibilityChanged(sal_Bool bVisible)349cdf0e10cSrcweir void SAL_CALL SfxInPlaceClient_Impl::visibilityChanged( sal_Bool bVisible )
350cdf0e10cSrcweir 	throw ( embed::WrongStateException,
351cdf0e10cSrcweir 			uno::RuntimeException )
352cdf0e10cSrcweir {
353cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
354cdf0e10cSrcweir 
355cdf0e10cSrcweir 	if ( !m_pClient || !m_pClient->GetViewShell() )
356cdf0e10cSrcweir 		throw uno::RuntimeException();
357cdf0e10cSrcweir 
358cdf0e10cSrcweir 	m_pClient->GetViewShell()->OutplaceActivated( bVisible, m_pClient );
359cdf0e10cSrcweir 	m_pClient->Invalidate();
360cdf0e10cSrcweir }
361cdf0e10cSrcweir 
362cdf0e10cSrcweir 
363cdf0e10cSrcweir // XInplaceClient
364cdf0e10cSrcweir //--------------------------------------------------------------------
canInplaceActivate()365cdf0e10cSrcweir sal_Bool SAL_CALL SfxInPlaceClient_Impl::canInplaceActivate()
366cdf0e10cSrcweir 	throw ( uno::RuntimeException )
367cdf0e10cSrcweir {
368cdf0e10cSrcweir 	if ( !m_xObject.is() )
369cdf0e10cSrcweir 		throw uno::RuntimeException();
370cdf0e10cSrcweir 
371cdf0e10cSrcweir     // we don't want to switch directly from outplace to inplace mode
372cdf0e10cSrcweir     if ( m_xObject->getCurrentState() == embed::EmbedStates::ACTIVE || m_nAspect == embed::Aspects::MSOLE_ICON )
373cdf0e10cSrcweir         return sal_False;
374cdf0e10cSrcweir 
375cdf0e10cSrcweir 	return sal_True;
376cdf0e10cSrcweir }
377cdf0e10cSrcweir 
378cdf0e10cSrcweir //--------------------------------------------------------------------
activatingInplace()379cdf0e10cSrcweir void SAL_CALL SfxInPlaceClient_Impl::activatingInplace()
380cdf0e10cSrcweir 	throw ( embed::WrongStateException,
381cdf0e10cSrcweir 			uno::RuntimeException )
382cdf0e10cSrcweir {
383cdf0e10cSrcweir 	if ( !m_pClient || !m_pClient->GetViewShell() )
384cdf0e10cSrcweir 		throw uno::RuntimeException();
385cdf0e10cSrcweir 
386cdf0e10cSrcweir 	m_pClient->GetViewShell()->InplaceActivating( m_pClient );
387cdf0e10cSrcweir }
388cdf0e10cSrcweir 
389cdf0e10cSrcweir //--------------------------------------------------------------------
activatingUI()390cdf0e10cSrcweir void SAL_CALL SfxInPlaceClient_Impl::activatingUI()
391cdf0e10cSrcweir 	throw ( embed::WrongStateException,
392cdf0e10cSrcweir 			uno::RuntimeException )
393cdf0e10cSrcweir {
394cdf0e10cSrcweir 	if ( !m_pClient || !m_pClient->GetViewShell() )
395cdf0e10cSrcweir 		throw uno::RuntimeException();
396cdf0e10cSrcweir 
397cdf0e10cSrcweir     m_pClient->GetViewShell()->ResetAllClients_Impl(m_pClient);
398cdf0e10cSrcweir     m_bUIActive = sal_True;
399cdf0e10cSrcweir     m_pClient->GetViewShell()->UIActivating( m_pClient );
400cdf0e10cSrcweir }
401cdf0e10cSrcweir 
402cdf0e10cSrcweir //--------------------------------------------------------------------
deactivatedInplace()403cdf0e10cSrcweir void SAL_CALL SfxInPlaceClient_Impl::deactivatedInplace()
404cdf0e10cSrcweir 	throw ( embed::WrongStateException,
405cdf0e10cSrcweir 			uno::RuntimeException )
406cdf0e10cSrcweir {
407cdf0e10cSrcweir 	if ( !m_pClient || !m_pClient->GetViewShell() )
408cdf0e10cSrcweir 		throw uno::RuntimeException();
409cdf0e10cSrcweir 
410cdf0e10cSrcweir 	m_pClient->GetViewShell()->InplaceDeactivated( m_pClient );
411cdf0e10cSrcweir }
412cdf0e10cSrcweir 
413cdf0e10cSrcweir //--------------------------------------------------------------------
deactivatedUI()414cdf0e10cSrcweir void SAL_CALL SfxInPlaceClient_Impl::deactivatedUI()
415cdf0e10cSrcweir 	throw ( embed::WrongStateException,
416cdf0e10cSrcweir 			uno::RuntimeException )
417cdf0e10cSrcweir {
418cdf0e10cSrcweir 	if ( !m_pClient || !m_pClient->GetViewShell() )
419cdf0e10cSrcweir 		throw uno::RuntimeException();
420cdf0e10cSrcweir 
421cdf0e10cSrcweir     m_pClient->GetViewShell()->UIDeactivated( m_pClient );
422cdf0e10cSrcweir     m_bUIActive = sal_False;
423cdf0e10cSrcweir }
424cdf0e10cSrcweir 
425cdf0e10cSrcweir //--------------------------------------------------------------------
getLayoutManager()426cdf0e10cSrcweir uno::Reference< ::com::sun::star::frame::XLayoutManager > SAL_CALL SfxInPlaceClient_Impl::getLayoutManager()
427cdf0e10cSrcweir 	throw ( embed::WrongStateException,
428cdf0e10cSrcweir 			uno::RuntimeException )
429cdf0e10cSrcweir {
430cdf0e10cSrcweir     uno::Reference < beans::XPropertySet > xFrame( GetFrame(), uno::UNO_QUERY );
431cdf0e10cSrcweir     if ( !xFrame.is() )
432cdf0e10cSrcweir 		throw uno::RuntimeException();
433cdf0e10cSrcweir 
434cdf0e10cSrcweir     uno::Reference< ::com::sun::star::frame::XLayoutManager > xMan;
435cdf0e10cSrcweir     try
436cdf0e10cSrcweir     {
437cdf0e10cSrcweir         uno::Any aAny = xFrame->getPropertyValue( ::rtl::OUString::createFromAscii("LayoutManager") );
438cdf0e10cSrcweir         aAny >>= xMan;
439cdf0e10cSrcweir     }
440cdf0e10cSrcweir     catch ( uno::Exception& )
441cdf0e10cSrcweir     {
442cdf0e10cSrcweir 		throw uno::RuntimeException();
443cdf0e10cSrcweir     }
444cdf0e10cSrcweir 
445cdf0e10cSrcweir     return xMan;
446cdf0e10cSrcweir }
447cdf0e10cSrcweir 
448cdf0e10cSrcweir //--------------------------------------------------------------------
getInplaceDispatchProvider()449cdf0e10cSrcweir uno::Reference< frame::XDispatchProvider > SAL_CALL SfxInPlaceClient_Impl::getInplaceDispatchProvider()
450cdf0e10cSrcweir 	throw ( embed::WrongStateException,
451cdf0e10cSrcweir 			uno::RuntimeException )
452cdf0e10cSrcweir {
453cdf0e10cSrcweir 	return uno::Reference < frame::XDispatchProvider >( GetFrame(), uno::UNO_QUERY_THROW );
454cdf0e10cSrcweir }
455cdf0e10cSrcweir 
456cdf0e10cSrcweir //--------------------------------------------------------------------
getPlacement()457cdf0e10cSrcweir awt::Rectangle SAL_CALL SfxInPlaceClient_Impl::getPlacement()
458cdf0e10cSrcweir 	throw ( embed::WrongStateException,
459cdf0e10cSrcweir 			uno::RuntimeException )
460cdf0e10cSrcweir {
461cdf0e10cSrcweir 	if ( !m_pClient || !m_pClient->GetViewShell() )
462cdf0e10cSrcweir 		throw uno::RuntimeException();
463cdf0e10cSrcweir 
464cdf0e10cSrcweir     // apply scaling to object area and convert to pixels
465cdf0e10cSrcweir     Rectangle aRealObjArea( m_aObjArea );
466cdf0e10cSrcweir     aRealObjArea.SetSize( Size( Fraction( aRealObjArea.GetWidth() ) * m_aScaleWidth,
467cdf0e10cSrcweir                     			Fraction( aRealObjArea.GetHeight() ) * m_aScaleHeight ) );
468cdf0e10cSrcweir 
469cdf0e10cSrcweir     aRealObjArea = m_pClient->GetEditWin()->LogicToPixel( aRealObjArea );
470cdf0e10cSrcweir 	return AWTRectangle( aRealObjArea );
471cdf0e10cSrcweir }
472cdf0e10cSrcweir 
473cdf0e10cSrcweir //--------------------------------------------------------------------
getClipRectangle()474cdf0e10cSrcweir awt::Rectangle SAL_CALL SfxInPlaceClient_Impl::getClipRectangle()
475cdf0e10cSrcweir 	throw ( embed::WrongStateException,
476cdf0e10cSrcweir 			uno::RuntimeException )
477cdf0e10cSrcweir {
478cdf0e10cSrcweir 	if ( !m_pClient || !m_pClient->GetViewShell() )
479cdf0e10cSrcweir 		throw uno::RuntimeException();
480cdf0e10cSrcweir 
481cdf0e10cSrcweir     // currently(?) same as placement
482cdf0e10cSrcweir 	Rectangle aRealObjArea( m_aObjArea );
483cdf0e10cSrcweir     aRealObjArea.SetSize( Size( Fraction( aRealObjArea.GetWidth() ) * m_aScaleWidth,
484cdf0e10cSrcweir                     			Fraction( aRealObjArea.GetHeight() ) * m_aScaleHeight ) );
485cdf0e10cSrcweir 
486cdf0e10cSrcweir     aRealObjArea = m_pClient->GetEditWin()->LogicToPixel( aRealObjArea );
487cdf0e10cSrcweir 	return AWTRectangle( aRealObjArea );
488cdf0e10cSrcweir }
489cdf0e10cSrcweir 
490cdf0e10cSrcweir //--------------------------------------------------------------------
translateAccelerators(const uno::Sequence<awt::KeyEvent> &)491cdf0e10cSrcweir void SAL_CALL SfxInPlaceClient_Impl::translateAccelerators( const uno::Sequence< awt::KeyEvent >& /*aKeys*/ )
492cdf0e10cSrcweir 	throw ( embed::WrongStateException,
493cdf0e10cSrcweir 			uno::RuntimeException )
494cdf0e10cSrcweir {
495cdf0e10cSrcweir 	if ( !m_pClient || !m_pClient->GetViewShell() )
496cdf0e10cSrcweir 		throw uno::RuntimeException();
497cdf0e10cSrcweir 
498cdf0e10cSrcweir     // TODO/MBA: keyboard accelerators
499cdf0e10cSrcweir }
500cdf0e10cSrcweir 
501cdf0e10cSrcweir //--------------------------------------------------------------------
scrollObject(const awt::Size &)502cdf0e10cSrcweir void SAL_CALL SfxInPlaceClient_Impl::scrollObject( const awt::Size& /*aOffset*/ )
503cdf0e10cSrcweir 	throw ( embed::WrongStateException,
504cdf0e10cSrcweir 			uno::RuntimeException )
505cdf0e10cSrcweir {
506cdf0e10cSrcweir 	if ( !m_pClient || !m_pClient->GetViewShell() )
507cdf0e10cSrcweir 		throw uno::RuntimeException();
508cdf0e10cSrcweir }
509cdf0e10cSrcweir 
510cdf0e10cSrcweir //--------------------------------------------------------------------
changedPlacement(const awt::Rectangle & aPosRect)511cdf0e10cSrcweir void SAL_CALL SfxInPlaceClient_Impl::changedPlacement( const awt::Rectangle& aPosRect )
512cdf0e10cSrcweir 	throw ( embed::WrongStateException,
513cdf0e10cSrcweir 			uno::Exception,
514cdf0e10cSrcweir 			uno::RuntimeException )
515cdf0e10cSrcweir {
516cdf0e10cSrcweir 	uno::Reference< embed::XInplaceObject > xInplace( m_xObject, uno::UNO_QUERY );
517cdf0e10cSrcweir     if ( !xInplace.is() || !m_pClient || !m_pClient->GetEditWin() || !m_pClient->GetViewShell() )
518cdf0e10cSrcweir 		throw uno::RuntimeException();
519cdf0e10cSrcweir 
520cdf0e10cSrcweir     // check if the change is at least one pixel in size
521cdf0e10cSrcweir     awt::Rectangle aOldRect = getPlacement();
522cdf0e10cSrcweir     Rectangle aNewPixelRect = VCLRectangle( aPosRect );
523cdf0e10cSrcweir     Rectangle aOldPixelRect = VCLRectangle( aOldRect );
524cdf0e10cSrcweir     if ( aOldPixelRect == aNewPixelRect )
525cdf0e10cSrcweir         // nothing has changed
526cdf0e10cSrcweir         return;
527cdf0e10cSrcweir 
528cdf0e10cSrcweir     // new scaled object area
529cdf0e10cSrcweir     Rectangle aNewLogicRect = m_pClient->GetEditWin()->PixelToLogic( aNewPixelRect );
530cdf0e10cSrcweir 
531cdf0e10cSrcweir 	// all the size changes in this method should happen without scaling
532cdf0e10cSrcweir 	// SfxBooleanFlagGuard aGuard( m_bResizeNoScale, sal_True );
533cdf0e10cSrcweir 
534cdf0e10cSrcweir     // allow container to apply restrictions on the requested new area;
535cdf0e10cSrcweir 	// the container might change the object view during size calculation;
536cdf0e10cSrcweir 	// currently only writer does it
537cdf0e10cSrcweir     m_pClient->RequestNewObjectArea( aNewLogicRect);
538cdf0e10cSrcweir 
539cdf0e10cSrcweir     if ( aNewLogicRect != m_pClient->GetScaledObjArea() )
540cdf0e10cSrcweir 	{
541cdf0e10cSrcweir 		// the calculation of the object area has not changed the object size
542cdf0e10cSrcweir 		// it should be done here then
543cdf0e10cSrcweir 		SfxBooleanFlagGuard aGuard( m_bResizeNoScale, sal_True );
544cdf0e10cSrcweir 
545cdf0e10cSrcweir     	// new size of the object area without scaling
546cdf0e10cSrcweir     	Size aNewObjSize( Fraction( aNewLogicRect.GetWidth() ) / m_aScaleWidth,
547cdf0e10cSrcweir                           Fraction( aNewLogicRect.GetHeight() ) / m_aScaleHeight );
548cdf0e10cSrcweir 
549cdf0e10cSrcweir     	// now remove scaling from new placement and keep this a the new object area
550cdf0e10cSrcweir     	aNewLogicRect.SetSize( aNewObjSize );
551cdf0e10cSrcweir     	m_aObjArea = aNewLogicRect;
552cdf0e10cSrcweir 
553cdf0e10cSrcweir 		// let the window size be recalculated
554cdf0e10cSrcweir 		SizeHasChanged();
555cdf0e10cSrcweir 	}
556cdf0e10cSrcweir 
557cdf0e10cSrcweir     // notify container view about changes
558cdf0e10cSrcweir     m_pClient->ObjectAreaChanged();
559cdf0e10cSrcweir }
560cdf0e10cSrcweir 
561cdf0e10cSrcweir // XComponentSupplier
562cdf0e10cSrcweir //--------------------------------------------------------------------
getComponent()563cdf0e10cSrcweir uno::Reference< util::XCloseable > SAL_CALL SfxInPlaceClient_Impl::getComponent()
564cdf0e10cSrcweir 	throw ( uno::RuntimeException )
565cdf0e10cSrcweir {
566cdf0e10cSrcweir 	if ( !m_pClient || !m_pClient->GetViewShell() )
567cdf0e10cSrcweir 		throw uno::RuntimeException();
568cdf0e10cSrcweir 
569cdf0e10cSrcweir 	SfxObjectShell* pDocShell = m_pClient->GetViewShell()->GetObjectShell();
570cdf0e10cSrcweir 	if ( !pDocShell )
571cdf0e10cSrcweir 		throw uno::RuntimeException();
572cdf0e10cSrcweir 
573cdf0e10cSrcweir 	// all the components must implement XCloseable
574cdf0e10cSrcweir 	uno::Reference< util::XCloseable > xComp( pDocShell->GetModel(), uno::UNO_QUERY );
575cdf0e10cSrcweir 	if ( !xComp.is() )
576cdf0e10cSrcweir 		throw uno::RuntimeException();
577cdf0e10cSrcweir 
578cdf0e10cSrcweir 	return xComp;
579cdf0e10cSrcweir }
580cdf0e10cSrcweir 
581cdf0e10cSrcweir 
582cdf0e10cSrcweir // XWindowSupplier
583cdf0e10cSrcweir //--------------------------------------------------------------------
getWindow()584cdf0e10cSrcweir uno::Reference< awt::XWindow > SAL_CALL SfxInPlaceClient_Impl::getWindow()
585cdf0e10cSrcweir 	throw ( uno::RuntimeException )
586cdf0e10cSrcweir {
587cdf0e10cSrcweir 	if ( !m_pClient || !m_pClient->GetEditWin() )
588cdf0e10cSrcweir 		throw uno::RuntimeException();
589cdf0e10cSrcweir 
590cdf0e10cSrcweir     uno::Reference< awt::XWindow > xWin( m_pClient->GetEditWin()->GetComponentInterface(), uno::UNO_QUERY );
591cdf0e10cSrcweir     return xWin;
592cdf0e10cSrcweir }
593cdf0e10cSrcweir 
594cdf0e10cSrcweir //--------------------------------------------------------------------
595cdf0e10cSrcweir // notification to the client implementation that either the object area or the scaling has been changed
596cdf0e10cSrcweir // as a result the logical size of the window has changed also
SizeHasChanged()597cdf0e10cSrcweir void SfxInPlaceClient_Impl::SizeHasChanged()
598cdf0e10cSrcweir {
599cdf0e10cSrcweir 	if ( !m_pClient || !m_pClient->GetViewShell() )
600cdf0e10cSrcweir 		throw uno::RuntimeException();
601cdf0e10cSrcweir 
602cdf0e10cSrcweir 	try {
603cdf0e10cSrcweir     	if ( m_xObject.is()
604cdf0e10cSrcweir 		  && ( m_xObject->getCurrentState() == embed::EmbedStates::INPLACE_ACTIVE
605cdf0e10cSrcweir     	 	   || m_xObject->getCurrentState() == embed::EmbedStates::UI_ACTIVE ) )
606cdf0e10cSrcweir 		{
607cdf0e10cSrcweir             // only possible in active states
608cdf0e10cSrcweir 			uno::Reference< embed::XInplaceObject > xInplace( m_xObject, uno::UNO_QUERY );
609cdf0e10cSrcweir 			if ( !xInplace.is() )
610cdf0e10cSrcweir 				throw uno::RuntimeException();
611cdf0e10cSrcweir 
612cdf0e10cSrcweir 			if ( m_bResizeNoScale )
613cdf0e10cSrcweir 			{
614cdf0e10cSrcweir 				// the resizing should be done without scaling
615cdf0e10cSrcweir 				// set the correct size to the object to avoid the scaling
616cdf0e10cSrcweir         		MapMode aObjectMap( VCLUnoHelper::UnoEmbed2VCLMapUnit( m_xObject->getMapUnit( m_nAspect ) ) );
617cdf0e10cSrcweir 				MapMode aClientMap( m_pClient->GetEditWin()->GetMapMode().GetMapUnit() );
618cdf0e10cSrcweir 
619cdf0e10cSrcweir         		// convert to logical coordinates of the embedded object
620cdf0e10cSrcweir         		Size aNewSize = m_pClient->GetEditWin()->LogicToLogic( m_aObjArea.GetSize(), &aClientMap, &aObjectMap );
621cdf0e10cSrcweir         		m_xObject->setVisualAreaSize( m_nAspect, awt::Size( aNewSize.Width(), aNewSize.Height() ) );
622cdf0e10cSrcweir 			}
623cdf0e10cSrcweir 
624cdf0e10cSrcweir 			xInplace->setObjectRectangles( getPlacement(), getClipRectangle() );
625cdf0e10cSrcweir 		}
626cdf0e10cSrcweir 	}
627cdf0e10cSrcweir 	catch( uno::Exception& )
628cdf0e10cSrcweir 	{
629cdf0e10cSrcweir 		// TODO/LATER: handle error
630cdf0e10cSrcweir 	}
631cdf0e10cSrcweir }
632cdf0e10cSrcweir 
633cdf0e10cSrcweir //--------------------------------------------------------------------
IMPL_LINK(SfxInPlaceClient_Impl,TimerHdl,Timer *,EMPTYARG)634cdf0e10cSrcweir IMPL_LINK( SfxInPlaceClient_Impl, TimerHdl, Timer*, EMPTYARG )
635cdf0e10cSrcweir {
636cdf0e10cSrcweir     if ( m_pClient && m_xObject.is() )
637cdf0e10cSrcweir         m_pClient->GetViewShell()->CheckIPClient_Impl( m_pClient, m_pClient->GetViewShell()->GetObjectShell()->GetVisArea() );
638cdf0e10cSrcweir 	return 0;
639cdf0e10cSrcweir }
640cdf0e10cSrcweir 
641cdf0e10cSrcweir 
642cdf0e10cSrcweir //====================================================================
643cdf0e10cSrcweir // SfxInPlaceClient
644cdf0e10cSrcweir 
645cdf0e10cSrcweir //--------------------------------------------------------------------
SfxInPlaceClient(SfxViewShell * pViewShell,Window * pDraw,sal_Int64 nAspect)646cdf0e10cSrcweir SfxInPlaceClient::SfxInPlaceClient( SfxViewShell* pViewShell, Window *pDraw, sal_Int64 nAspect ) :
647cdf0e10cSrcweir 	m_pImp( new SfxInPlaceClient_Impl ),
648cdf0e10cSrcweir     m_pViewSh( pViewShell ),
649cdf0e10cSrcweir     m_pEditWin( pDraw )
650cdf0e10cSrcweir {
651cdf0e10cSrcweir 	m_pImp->acquire();
652cdf0e10cSrcweir     m_pImp->m_pClient = this;
653cdf0e10cSrcweir     m_pImp->m_nAspect = nAspect;
654cdf0e10cSrcweir     m_pImp->m_aScaleWidth = m_pImp->m_aScaleHeight = Fraction(1,1);
655cdf0e10cSrcweir     m_pImp->m_xClient = static_cast< embed::XEmbeddedClient* >( m_pImp );
656cdf0e10cSrcweir     pViewShell->NewIPClient_Impl(this);
657cdf0e10cSrcweir     m_pImp->m_aTimer.SetTimeout( SFX_CLIENTACTIVATE_TIMEOUT );
658cdf0e10cSrcweir     m_pImp->m_aTimer.SetTimeoutHdl( LINK( m_pImp, SfxInPlaceClient_Impl, TimerHdl ) );
659cdf0e10cSrcweir }
660cdf0e10cSrcweir 
661cdf0e10cSrcweir //--------------------------------------------------------------------
662cdf0e10cSrcweir 
~SfxInPlaceClient()663cdf0e10cSrcweir SfxInPlaceClient::~SfxInPlaceClient()
664cdf0e10cSrcweir {
665cdf0e10cSrcweir     m_pViewSh->IPClientGone_Impl(this);
666cdf0e10cSrcweir 
667cdf0e10cSrcweir     // deleting the client before storing the object means discarding all changes
668cdf0e10cSrcweir     m_pImp->m_bStoreObject = sal_False;
669cdf0e10cSrcweir     SetObject(0);
670cdf0e10cSrcweir 
671cdf0e10cSrcweir     m_pImp->m_pClient = NULL;
672cdf0e10cSrcweir 
673cdf0e10cSrcweir     // the next call will destroy m_pImp if no other reference to it exists
674cdf0e10cSrcweir     m_pImp->m_xClient = uno::Reference < embed::XEmbeddedClient >();
675cdf0e10cSrcweir 	m_pImp->release();
676cdf0e10cSrcweir 
677cdf0e10cSrcweir 	// TODO/LATER:
678cdf0e10cSrcweir 	// the class is not intended to be used in multithreaded environment;
679cdf0e10cSrcweir 	// if it will this disconnection and all the parts that use the m_pClient
680cdf0e10cSrcweir     // must be guarded with mutex
681cdf0e10cSrcweir }
682cdf0e10cSrcweir 
683cdf0e10cSrcweir //--------------------------------------------------------------------
SetObjectState(sal_Int32 nState)684cdf0e10cSrcweir void SfxInPlaceClient::SetObjectState( sal_Int32 nState )
685cdf0e10cSrcweir {
686cdf0e10cSrcweir     if ( GetObject().is() )
687cdf0e10cSrcweir     {
688cdf0e10cSrcweir     	if ( m_pImp->m_nAspect == embed::Aspects::MSOLE_ICON
689cdf0e10cSrcweir 		  && ( nState == embed::EmbedStates::UI_ACTIVE || nState == embed::EmbedStates::INPLACE_ACTIVE ) )
690cdf0e10cSrcweir 		{
691cdf0e10cSrcweir 			OSL_ENSURE( sal_False, "Iconified object should not be activated inplace!\n" );
692cdf0e10cSrcweir 			return;
693cdf0e10cSrcweir 		}
694cdf0e10cSrcweir 
695cdf0e10cSrcweir         try
696cdf0e10cSrcweir         {
697cdf0e10cSrcweir             GetObject()->changeState( nState );
698cdf0e10cSrcweir         }
699cdf0e10cSrcweir         catch ( uno::Exception& )
700cdf0e10cSrcweir         {}
701cdf0e10cSrcweir     }
702cdf0e10cSrcweir }
703cdf0e10cSrcweir 
704cdf0e10cSrcweir //--------------------------------------------------------------------
GetObjectMiscStatus() const705cdf0e10cSrcweir sal_Int64 SfxInPlaceClient::GetObjectMiscStatus() const
706cdf0e10cSrcweir {
707cdf0e10cSrcweir     if ( GetObject().is() )
708cdf0e10cSrcweir         return GetObject()->getStatus( m_pImp->m_nAspect );
709cdf0e10cSrcweir     return 0;
710cdf0e10cSrcweir }
711cdf0e10cSrcweir 
712cdf0e10cSrcweir //--------------------------------------------------------------------
GetObject() const713cdf0e10cSrcweir uno::Reference < embed::XEmbeddedObject > SfxInPlaceClient::GetObject() const
714cdf0e10cSrcweir {
715cdf0e10cSrcweir     return m_pImp->m_xObject;
716cdf0e10cSrcweir }
717cdf0e10cSrcweir 
718cdf0e10cSrcweir //--------------------------------------------------------------------
SetObject(const uno::Reference<embed::XEmbeddedObject> & rObject)719cdf0e10cSrcweir void SfxInPlaceClient::SetObject( const uno::Reference < embed::XEmbeddedObject >& rObject )
720cdf0e10cSrcweir {
721cdf0e10cSrcweir     if ( m_pImp->m_xObject.is() && rObject != m_pImp->m_xObject )
722cdf0e10cSrcweir     {
723cdf0e10cSrcweir         DBG_ASSERT( GetObject()->getClientSite() == m_pImp->m_xClient, "Wrong ClientSite!" );
724cdf0e10cSrcweir         if ( GetObject()->getClientSite() == m_pImp->m_xClient )
725cdf0e10cSrcweir         {
726cdf0e10cSrcweir             if ( GetObject()->getCurrentState() != embed::EmbedStates::LOADED )
727cdf0e10cSrcweir                 SetObjectState( embed::EmbedStates::RUNNING );
728cdf0e10cSrcweir             m_pImp->m_xObject->removeEventListener( uno::Reference < document::XEventListener >( m_pImp->m_xClient, uno::UNO_QUERY ) );
729cdf0e10cSrcweir             m_pImp->m_xObject->removeStateChangeListener( uno::Reference < embed::XStateChangeListener >( m_pImp->m_xClient, uno::UNO_QUERY ) );
730cdf0e10cSrcweir 			try
731cdf0e10cSrcweir 			{
732cdf0e10cSrcweir             	m_pImp->m_xObject->setClientSite( 0 );
733cdf0e10cSrcweir 			}
734cdf0e10cSrcweir 			catch( uno::Exception& )
735cdf0e10cSrcweir 			{
736cdf0e10cSrcweir 				OSL_ENSURE( sal_False, "Can not clean the client site!\n" );
737cdf0e10cSrcweir 			}
738cdf0e10cSrcweir         }
739cdf0e10cSrcweir     }
740cdf0e10cSrcweir 
741cdf0e10cSrcweir     if ( !m_pViewSh || m_pViewSh->GetViewFrame()->GetFrame().IsClosing_Impl() )
742cdf0e10cSrcweir         // sometimes applications reconnect clients on shutting down because it happens in their Paint methods
743cdf0e10cSrcweir         return;
744cdf0e10cSrcweir 
745cdf0e10cSrcweir     m_pImp->m_xObject = rObject;
746cdf0e10cSrcweir 
747cdf0e10cSrcweir     if ( rObject.is() )
748cdf0e10cSrcweir     {
749cdf0e10cSrcweir         // as soon as an object was connected to a client it has to be checked wether the object wants
750cdf0e10cSrcweir         // to be activated
751cdf0e10cSrcweir         rObject->addStateChangeListener( uno::Reference < embed::XStateChangeListener >( m_pImp->m_xClient, uno::UNO_QUERY ) );
752cdf0e10cSrcweir         rObject->addEventListener( uno::Reference < document::XEventListener >( m_pImp->m_xClient, uno::UNO_QUERY ) );
753cdf0e10cSrcweir 
754cdf0e10cSrcweir 		try
755cdf0e10cSrcweir 		{
756cdf0e10cSrcweir         	rObject->setClientSite( m_pImp->m_xClient );
757cdf0e10cSrcweir 		}
758cdf0e10cSrcweir 		catch( uno::Exception& )
759cdf0e10cSrcweir 		{
760cdf0e10cSrcweir 			OSL_ENSURE( sal_False, "Can not set the client site!\n" );
761cdf0e10cSrcweir 		}
762cdf0e10cSrcweir 
763cdf0e10cSrcweir         m_pImp->m_aTimer.Start();
764cdf0e10cSrcweir     }
765cdf0e10cSrcweir     else
766cdf0e10cSrcweir         m_pImp->m_aTimer.Stop();
767cdf0e10cSrcweir }
768cdf0e10cSrcweir 
769cdf0e10cSrcweir //--------------------------------------------------------------------
SetObjArea(const Rectangle & rArea)770cdf0e10cSrcweir sal_Bool SfxInPlaceClient::SetObjArea( const Rectangle& rArea )
771cdf0e10cSrcweir {
772cdf0e10cSrcweir     if( rArea != m_pImp->m_aObjArea )
773cdf0e10cSrcweir     {
774cdf0e10cSrcweir         m_pImp->m_aObjArea = rArea;
775cdf0e10cSrcweir 		m_pImp->SizeHasChanged();
776cdf0e10cSrcweir 
777cdf0e10cSrcweir         Invalidate();
778cdf0e10cSrcweir         return sal_True;
779cdf0e10cSrcweir     }
780cdf0e10cSrcweir 
781cdf0e10cSrcweir     return sal_False;
782cdf0e10cSrcweir }
783cdf0e10cSrcweir 
784cdf0e10cSrcweir //--------------------------------------------------------------------
GetObjArea() const785cdf0e10cSrcweir Rectangle SfxInPlaceClient::GetObjArea() const
786cdf0e10cSrcweir {
787cdf0e10cSrcweir     return m_pImp->m_aObjArea;
788cdf0e10cSrcweir }
789cdf0e10cSrcweir 
GetScaledObjArea() const790cdf0e10cSrcweir Rectangle SfxInPlaceClient::GetScaledObjArea() const
791cdf0e10cSrcweir {
792cdf0e10cSrcweir     Rectangle aRealObjArea( m_pImp->m_aObjArea );
793cdf0e10cSrcweir     aRealObjArea.SetSize( Size( Fraction( aRealObjArea.GetWidth() ) * m_pImp->m_aScaleWidth,
794cdf0e10cSrcweir                                 Fraction( aRealObjArea.GetHeight() ) * m_pImp->m_aScaleHeight ) );
795cdf0e10cSrcweir     return aRealObjArea;
796cdf0e10cSrcweir }
797cdf0e10cSrcweir 
798cdf0e10cSrcweir //--------------------------------------------------------------------
SetSizeScale(const Fraction & rScaleWidth,const Fraction & rScaleHeight)799cdf0e10cSrcweir void SfxInPlaceClient::SetSizeScale( const Fraction & rScaleWidth, const Fraction & rScaleHeight )
800cdf0e10cSrcweir {
801cdf0e10cSrcweir 	if ( m_pImp->m_aScaleWidth != rScaleWidth || m_pImp->m_aScaleHeight != rScaleHeight )
802cdf0e10cSrcweir 	{
803cdf0e10cSrcweir     	m_pImp->m_aScaleWidth = rScaleWidth;
804cdf0e10cSrcweir     	m_pImp->m_aScaleHeight = rScaleHeight;
805cdf0e10cSrcweir 
806cdf0e10cSrcweir 		m_pImp->SizeHasChanged();
807cdf0e10cSrcweir 
808cdf0e10cSrcweir         // TODO/LATER: Invalidate seems to trigger (wrong) recalculations of the ObjArea, so it's better
809cdf0e10cSrcweir         // not to call it here, but maybe it sounds reasonable to do so.
810cdf0e10cSrcweir         //Invalidate();
811cdf0e10cSrcweir 	}
812cdf0e10cSrcweir }
813cdf0e10cSrcweir 
814cdf0e10cSrcweir //--------------------------------------------------------------------
SetObjAreaAndScale(const Rectangle & rArea,const Fraction & rScaleWidth,const Fraction & rScaleHeight)815cdf0e10cSrcweir sal_Bool SfxInPlaceClient::SetObjAreaAndScale( const Rectangle& rArea, const Fraction& rScaleWidth, const Fraction& rScaleHeight )
816cdf0e10cSrcweir {
817cdf0e10cSrcweir     if( rArea != m_pImp->m_aObjArea || m_pImp->m_aScaleWidth != rScaleWidth || m_pImp->m_aScaleHeight != rScaleHeight )
818cdf0e10cSrcweir     {
819cdf0e10cSrcweir         m_pImp->m_aObjArea = rArea;
820cdf0e10cSrcweir     	m_pImp->m_aScaleWidth = rScaleWidth;
821cdf0e10cSrcweir     	m_pImp->m_aScaleHeight = rScaleHeight;
822cdf0e10cSrcweir 
823cdf0e10cSrcweir 		m_pImp->SizeHasChanged();
824cdf0e10cSrcweir 
825cdf0e10cSrcweir         Invalidate();
826cdf0e10cSrcweir         return sal_True;
827cdf0e10cSrcweir     }
828cdf0e10cSrcweir 
829cdf0e10cSrcweir     return sal_False;
830cdf0e10cSrcweir }
831cdf0e10cSrcweir 
832cdf0e10cSrcweir //--------------------------------------------------------------------
GetScaleWidth() const833cdf0e10cSrcweir const Fraction& SfxInPlaceClient::GetScaleWidth() const
834cdf0e10cSrcweir {
835cdf0e10cSrcweir     return m_pImp->m_aScaleWidth;
836cdf0e10cSrcweir }
837cdf0e10cSrcweir 
838cdf0e10cSrcweir //--------------------------------------------------------------------
GetScaleHeight() const839cdf0e10cSrcweir const Fraction& SfxInPlaceClient::GetScaleHeight() const
840cdf0e10cSrcweir {
841cdf0e10cSrcweir     return m_pImp->m_aScaleHeight;
842cdf0e10cSrcweir }
843cdf0e10cSrcweir 
844cdf0e10cSrcweir //--------------------------------------------------------------------
Invalidate()845cdf0e10cSrcweir void SfxInPlaceClient::Invalidate()
846cdf0e10cSrcweir {
847cdf0e10cSrcweir     // TODO/LATER: do we need both?
848cdf0e10cSrcweir 
849cdf0e10cSrcweir 	// the object area is provided in logical coordinates of the window but without scaling applied
850cdf0e10cSrcweir     Rectangle aRealObjArea( m_pImp->m_aObjArea );
851cdf0e10cSrcweir     aRealObjArea.SetSize( Size( Fraction( aRealObjArea.GetWidth() ) * m_pImp->m_aScaleWidth,
852cdf0e10cSrcweir                     			Fraction( aRealObjArea.GetHeight() ) * m_pImp->m_aScaleHeight ) );
853cdf0e10cSrcweir     m_pEditWin->Invalidate( aRealObjArea );
854cdf0e10cSrcweir 
855cdf0e10cSrcweir     ViewChanged();
856cdf0e10cSrcweir }
857cdf0e10cSrcweir 
858cdf0e10cSrcweir //--------------------------------------------------------------------
IsObjectUIActive() const859cdf0e10cSrcweir sal_Bool SfxInPlaceClient::IsObjectUIActive() const
860cdf0e10cSrcweir {
861cdf0e10cSrcweir 	try {
862cdf0e10cSrcweir     	return ( m_pImp->m_xObject.is() && ( m_pImp->m_xObject->getCurrentState() == embed::EmbedStates::UI_ACTIVE ) );
863cdf0e10cSrcweir 	}
864cdf0e10cSrcweir 	catch( uno::Exception& )
865cdf0e10cSrcweir 	{}
866cdf0e10cSrcweir 
867cdf0e10cSrcweir 	return sal_False;
868cdf0e10cSrcweir }
869cdf0e10cSrcweir 
870cdf0e10cSrcweir //--------------------------------------------------------------------
IsObjectInPlaceActive() const871cdf0e10cSrcweir sal_Bool SfxInPlaceClient::IsObjectInPlaceActive() const
872cdf0e10cSrcweir {
873cdf0e10cSrcweir 	try {
874cdf0e10cSrcweir         return(
875cdf0e10cSrcweir                (
876cdf0e10cSrcweir                 m_pImp->m_xObject.is() &&
877cdf0e10cSrcweir                 (m_pImp->m_xObject->getCurrentState() == embed::EmbedStates::INPLACE_ACTIVE)
878cdf0e10cSrcweir                ) ||
879cdf0e10cSrcweir                (
880cdf0e10cSrcweir                 m_pImp->m_xObject.is() &&
881cdf0e10cSrcweir                 (m_pImp->m_xObject->getCurrentState() == embed::EmbedStates::UI_ACTIVE)
882cdf0e10cSrcweir                )
883cdf0e10cSrcweir               );
884cdf0e10cSrcweir 	}
885cdf0e10cSrcweir 	catch( uno::Exception& )
886cdf0e10cSrcweir 	{}
887cdf0e10cSrcweir 
888cdf0e10cSrcweir 	return sal_False;
889cdf0e10cSrcweir }
890cdf0e10cSrcweir 
891cdf0e10cSrcweir //--------------------------------------------------------------------
IsObjectActive() const892cdf0e10cSrcweir sal_Bool SfxInPlaceClient::IsObjectActive() const
893cdf0e10cSrcweir {
894cdf0e10cSrcweir 	try {
895cdf0e10cSrcweir     	return ( m_pImp->m_xObject.is() && ( m_pImp->m_xObject->getCurrentState() == embed::EmbedStates::ACTIVE ) );
896cdf0e10cSrcweir 	}
897cdf0e10cSrcweir 	catch( uno::Exception& )
898cdf0e10cSrcweir 	{}
899cdf0e10cSrcweir 
900cdf0e10cSrcweir 	return sal_False;
901cdf0e10cSrcweir }
902cdf0e10cSrcweir 
903cdf0e10cSrcweir //--------------------------------------------------------------------
GetActiveWindow(SfxObjectShell * pDoc,const com::sun::star::uno::Reference<com::sun::star::embed::XEmbeddedObject> & xObject)904cdf0e10cSrcweir Window* SfxInPlaceClient::GetActiveWindow( SfxObjectShell* pDoc, const com::sun::star::uno::Reference < com::sun::star::embed::XEmbeddedObject >& xObject )
905cdf0e10cSrcweir {
906cdf0e10cSrcweir     SfxInPlaceClient* pClient = GetClient( pDoc, xObject );
907cdf0e10cSrcweir     if ( pClient )
908cdf0e10cSrcweir         return pClient->GetEditWin();
909cdf0e10cSrcweir     return NULL;
910cdf0e10cSrcweir }
911cdf0e10cSrcweir 
912cdf0e10cSrcweir //--------------------------------------------------------------------
GetClient(SfxObjectShell * pDoc,const com::sun::star::uno::Reference<com::sun::star::embed::XEmbeddedObject> & xObject)913cdf0e10cSrcweir SfxInPlaceClient* SfxInPlaceClient::GetClient( SfxObjectShell* pDoc, const com::sun::star::uno::Reference < com::sun::star::embed::XEmbeddedObject >& xObject )
914cdf0e10cSrcweir {
915cdf0e10cSrcweir     for ( SfxViewFrame* pFrame = SfxViewFrame::GetFirst(pDoc); pFrame; pFrame=SfxViewFrame::GetNext(*pFrame,pDoc) )
916cdf0e10cSrcweir     {
917cdf0e10cSrcweir 		if( pFrame->GetViewShell() )
918cdf0e10cSrcweir 		{
919cdf0e10cSrcweir 	        SfxInPlaceClient* pClient = pFrame->GetViewShell()->FindIPClient( xObject, NULL );
920cdf0e10cSrcweir 		    if ( pClient )
921cdf0e10cSrcweir 			    return pClient;
922cdf0e10cSrcweir 		}
923cdf0e10cSrcweir     }
924cdf0e10cSrcweir 
925cdf0e10cSrcweir     return NULL;
926cdf0e10cSrcweir }
927cdf0e10cSrcweir 
GetAspect() const928cdf0e10cSrcweir sal_Int64 SfxInPlaceClient::GetAspect() const
929cdf0e10cSrcweir {
930cdf0e10cSrcweir 	return m_pImp->m_nAspect;
931cdf0e10cSrcweir }
932cdf0e10cSrcweir 
DoVerb(long nVerb)933cdf0e10cSrcweir ErrCode SfxInPlaceClient::DoVerb( long nVerb )
934cdf0e10cSrcweir {
935cdf0e10cSrcweir     SfxErrorContext aEc( ERRCTX_SO_DOVERB, m_pViewSh->GetWindow(), RID_SO_ERRCTX );
936cdf0e10cSrcweir     ErrCode nError = ERRCODE_NONE;
937cdf0e10cSrcweir 
938cdf0e10cSrcweir     if ( m_pImp->m_xObject.is() )
939cdf0e10cSrcweir     {
940cdf0e10cSrcweir 		sal_Bool bSaveCopyAs = sal_False;
941cdf0e10cSrcweir 		if ( nVerb == -8 ) // "Save Copy as..."
942cdf0e10cSrcweir 		{
943cdf0e10cSrcweir             svt::EmbeddedObjectRef::TryRunningState( m_pImp->m_xObject );
944cdf0e10cSrcweir 			// TODO/LATER: this special verb should disappear when outplace activation is completely available
945cdf0e10cSrcweir 			uno::Reference< frame::XModel > xEmbModel( m_pImp->m_xObject->getComponent(), uno::UNO_QUERY );
946cdf0e10cSrcweir 			if ( xEmbModel.is() )
947cdf0e10cSrcweir 			{
948cdf0e10cSrcweir 				bSaveCopyAs = sal_True;
949cdf0e10cSrcweir 
950cdf0e10cSrcweir 				try
951cdf0e10cSrcweir 				{
952cdf0e10cSrcweir 					uno::Reference< lang::XMultiServiceFactory > xEmptyFactory;
953cdf0e10cSrcweir 					SfxStoringHelper aHelper( xEmptyFactory );
954cdf0e10cSrcweir 					uno::Sequence< beans::PropertyValue > aDispatchArgs( 1 );
955cdf0e10cSrcweir 					aDispatchArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SaveTo" ) );
956cdf0e10cSrcweir 					aDispatchArgs[0].Value <<= (sal_Bool)sal_True;
957cdf0e10cSrcweir 
958cdf0e10cSrcweir 					aHelper.GUIStoreModel( xEmbModel,
959cdf0e10cSrcweir 											::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SaveAs" ) ),
960cdf0e10cSrcweir 											aDispatchArgs,
961cdf0e10cSrcweir                                             sal_False,
962cdf0e10cSrcweir                                             ::rtl::OUString() );
963cdf0e10cSrcweir 				}
964cdf0e10cSrcweir 				catch( task::ErrorCodeIOException& aErrorEx )
965cdf0e10cSrcweir 				{
966cdf0e10cSrcweir 					nError = (sal_uInt32)aErrorEx.ErrCode;
967cdf0e10cSrcweir 				}
968cdf0e10cSrcweir 				catch( uno::Exception& )
969cdf0e10cSrcweir 				{
970cdf0e10cSrcweir 					nError = ERRCODE_IO_GENERAL;
971cdf0e10cSrcweir 					// TODO/LATER: better error handling
972cdf0e10cSrcweir 				}
973cdf0e10cSrcweir 			}
974cdf0e10cSrcweir 		}
975cdf0e10cSrcweir 
976cdf0e10cSrcweir 		if ( !bSaveCopyAs )
977cdf0e10cSrcweir 		{
978cdf0e10cSrcweir     		if ( m_pImp->m_nAspect == embed::Aspects::MSOLE_ICON )
979cdf0e10cSrcweir 			{
980cdf0e10cSrcweir 				if ( nVerb == embed::EmbedVerbs::MS_OLEVERB_PRIMARY || nVerb == embed::EmbedVerbs::MS_OLEVERB_SHOW )
981cdf0e10cSrcweir 					nVerb = embed::EmbedVerbs::MS_OLEVERB_OPEN; // outplace activation
982cdf0e10cSrcweir 				else if ( nVerb == embed::EmbedVerbs::MS_OLEVERB_UIACTIVATE
983cdf0e10cSrcweir 					   || nVerb == embed::EmbedVerbs::MS_OLEVERB_IPACTIVATE )
984cdf0e10cSrcweir 					nError = ERRCODE_SO_GENERALERROR;
985cdf0e10cSrcweir 			}
986cdf0e10cSrcweir 
987cdf0e10cSrcweir 			if ( !nError )
988cdf0e10cSrcweir 			{
989cdf0e10cSrcweir 
990cdf0e10cSrcweir                 if ( m_pViewSh )
991cdf0e10cSrcweir                     m_pViewSh->GetViewFrame()->GetTopFrame().LockResize_Impl(sal_True);
992cdf0e10cSrcweir         		try
993cdf0e10cSrcweir         		{
994cdf0e10cSrcweir         			m_pImp->m_xObject->setClientSite( m_pImp->m_xClient );
995cdf0e10cSrcweir 
996cdf0e10cSrcweir             		m_pImp->m_xObject->doVerb( nVerb );
997cdf0e10cSrcweir         		}
998cdf0e10cSrcweir 				catch ( embed::UnreachableStateException& )
999cdf0e10cSrcweir 				{
1000cdf0e10cSrcweir 					if ( nVerb == 0 || nVerb == embed::EmbedVerbs::MS_OLEVERB_OPEN )
1001cdf0e10cSrcweir 					{
1002cdf0e10cSrcweir 						// a workaround for the default verb, usually makes sence for alien objects
1003cdf0e10cSrcweir 						try
1004cdf0e10cSrcweir 						{
1005cdf0e10cSrcweir 							m_pImp->m_xObject->doVerb( -9 ); // open own view, a workaround verb that is not visible
1006cdf0e10cSrcweir 
1007cdf0e10cSrcweir                             if ( m_pImp->m_xObject->getCurrentState() == embed::EmbedStates::UI_ACTIVE )
1008cdf0e10cSrcweir                             {
1009cdf0e10cSrcweir                                 // the object was converted to OOo object
1010cdf0e10cSrcweir                                 awt::Size aSize = m_pImp->m_xObject->getVisualAreaSize( m_pImp->m_nAspect );
1011cdf0e10cSrcweir                                 MapMode aObjectMap( VCLUnoHelper::UnoEmbed2VCLMapUnit( m_pImp->m_xObject->getMapUnit( m_pImp->m_nAspect ) ) );
1012cdf0e10cSrcweir                                 MapMode aClientMap( GetEditWin()->GetMapMode().GetMapUnit() );
1013cdf0e10cSrcweir                                 Size aNewSize = GetEditWin()->LogicToLogic( Size( aSize.Width, aSize.Height ), &aObjectMap, &aClientMap );
1014cdf0e10cSrcweir 
1015cdf0e10cSrcweir                                 Rectangle aScaledArea = GetScaledObjArea();
1016cdf0e10cSrcweir                                 m_pImp->m_aObjArea.SetSize( aNewSize );
1017cdf0e10cSrcweir                                 m_pImp->m_aScaleWidth = Fraction( aScaledArea.GetWidth(), aNewSize.Width() );
1018cdf0e10cSrcweir                                 m_pImp->m_aScaleHeight = Fraction( aScaledArea.GetHeight(), aNewSize.Height() );
1019cdf0e10cSrcweir                             }
1020cdf0e10cSrcweir 						}
1021cdf0e10cSrcweir 						catch ( uno::Exception& )
1022cdf0e10cSrcweir 						{
1023cdf0e10cSrcweir 							nError = ERRCODE_SO_GENERALERROR;
1024cdf0e10cSrcweir 						}
1025cdf0e10cSrcweir 					}
1026cdf0e10cSrcweir 				}
1027cdf0e10cSrcweir 				catch ( embed::StateChangeInProgressException& )
1028cdf0e10cSrcweir 				{
1029cdf0e10cSrcweir 					// TODO/LATER: it would be nice to be able to provide the current target state outside
1030cdf0e10cSrcweir 					nError = ERRCODE_SO_CANNOT_DOVERB_NOW;
1031cdf0e10cSrcweir 				}
1032cdf0e10cSrcweir         		catch ( uno::Exception& )
1033cdf0e10cSrcweir         		{
1034cdf0e10cSrcweir 					nError = ERRCODE_SO_GENERALERROR;
1035cdf0e10cSrcweir             		//TODO/LATER: better error handling
1036cdf0e10cSrcweir         		}
1037cdf0e10cSrcweir 
1038cdf0e10cSrcweir                 if ( m_pViewSh )
1039cdf0e10cSrcweir                 {
1040cdf0e10cSrcweir                     SfxViewFrame* pFrame = m_pViewSh->GetViewFrame();
1041cdf0e10cSrcweir                     pFrame->GetTopFrame().LockResize_Impl(sal_False);
1042cdf0e10cSrcweir                     pFrame->GetTopFrame().Resize();
1043cdf0e10cSrcweir                 }
1044cdf0e10cSrcweir             }
1045cdf0e10cSrcweir 		}
1046cdf0e10cSrcweir     }
1047cdf0e10cSrcweir 
1048cdf0e10cSrcweir     if( nError )
1049cdf0e10cSrcweir         ErrorHandler::HandleError( nError );
1050cdf0e10cSrcweir 
1051cdf0e10cSrcweir     return nError;
1052cdf0e10cSrcweir }
1053cdf0e10cSrcweir 
VisAreaChanged()1054cdf0e10cSrcweir void SfxInPlaceClient::VisAreaChanged()
1055cdf0e10cSrcweir {
1056cdf0e10cSrcweir     uno::Reference < embed::XInplaceObject > xObj( m_pImp->m_xObject, uno::UNO_QUERY );
1057cdf0e10cSrcweir     uno::Reference < embed::XInplaceClient > xClient( m_pImp->m_xClient, uno::UNO_QUERY );
1058cdf0e10cSrcweir     if ( xObj.is() && xClient.is() )
1059cdf0e10cSrcweir 		m_pImp->SizeHasChanged();
1060cdf0e10cSrcweir }
1061cdf0e10cSrcweir 
ObjectAreaChanged()1062cdf0e10cSrcweir void SfxInPlaceClient::ObjectAreaChanged()
1063cdf0e10cSrcweir {
1064cdf0e10cSrcweir 	// dummy implementation
1065cdf0e10cSrcweir }
1066cdf0e10cSrcweir 
RequestNewObjectArea(Rectangle &)1067cdf0e10cSrcweir void SfxInPlaceClient::RequestNewObjectArea( Rectangle& )
1068cdf0e10cSrcweir {
1069cdf0e10cSrcweir 	// dummy implementation
1070cdf0e10cSrcweir }
1071cdf0e10cSrcweir 
ViewChanged()1072cdf0e10cSrcweir void SfxInPlaceClient::ViewChanged()
1073cdf0e10cSrcweir {
1074cdf0e10cSrcweir 	// dummy implementation
1075cdf0e10cSrcweir }
1076cdf0e10cSrcweir 
MakeVisible()1077cdf0e10cSrcweir void SfxInPlaceClient::MakeVisible()
1078cdf0e10cSrcweir {
1079cdf0e10cSrcweir 	// dummy implementation
1080cdf0e10cSrcweir }
1081cdf0e10cSrcweir 
FormatChanged()1082cdf0e10cSrcweir void SfxInPlaceClient::FormatChanged()
1083cdf0e10cSrcweir {
1084cdf0e10cSrcweir     // dummy implementation
1085cdf0e10cSrcweir }
1086cdf0e10cSrcweir 
DeactivateObject()1087cdf0e10cSrcweir void SfxInPlaceClient::DeactivateObject()
1088cdf0e10cSrcweir {
1089cdf0e10cSrcweir     if ( GetObject().is() )
1090cdf0e10cSrcweir     {
1091cdf0e10cSrcweir         try
1092cdf0e10cSrcweir         {
1093cdf0e10cSrcweir             m_pImp->m_bUIActive = sal_False;
1094cdf0e10cSrcweir             sal_Bool bHasFocus = sal_False;
1095cdf0e10cSrcweir             uno::Reference< frame::XModel > xModel( m_pImp->m_xObject->getComponent(), uno::UNO_QUERY );
1096cdf0e10cSrcweir             if ( xModel.is() )
1097cdf0e10cSrcweir             {
1098cdf0e10cSrcweir                 uno::Reference< frame::XController > xController = xModel->getCurrentController();
1099cdf0e10cSrcweir                 if ( xController.is() )
1100cdf0e10cSrcweir                 {
1101cdf0e10cSrcweir                     Window* pWindow = VCLUnoHelper::GetWindow( xController->getFrame()->getContainerWindow() );
1102cdf0e10cSrcweir                     bHasFocus = pWindow->HasChildPathFocus( sal_True );
1103cdf0e10cSrcweir                 }
1104cdf0e10cSrcweir             }
1105cdf0e10cSrcweir 
1106cdf0e10cSrcweir             if ( m_pViewSh )
1107cdf0e10cSrcweir                 m_pViewSh->GetViewFrame()->GetTopFrame().LockResize_Impl(sal_True);
1108cdf0e10cSrcweir 
1109cdf0e10cSrcweir             if ( m_pImp->m_xObject->getStatus( m_pImp->m_nAspect ) & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE )
1110cdf0e10cSrcweir             {
1111cdf0e10cSrcweir                 m_pImp->m_xObject->changeState( embed::EmbedStates::INPLACE_ACTIVE );
1112cdf0e10cSrcweir                 if ( bHasFocus && m_pViewSh )
1113cdf0e10cSrcweir                     m_pViewSh->GetWindow()->GrabFocus();
1114cdf0e10cSrcweir             }
1115cdf0e10cSrcweir             else
1116cdf0e10cSrcweir             {
1117cdf0e10cSrcweir                 // the links should not stay in running state for long time because of locking
1118cdf0e10cSrcweir                 uno::Reference< embed::XLinkageSupport > xLink( m_pImp->m_xObject, uno::UNO_QUERY );
1119cdf0e10cSrcweir                 if ( xLink.is() && xLink->isLink() )
1120cdf0e10cSrcweir                     m_pImp->m_xObject->changeState( embed::EmbedStates::LOADED );
1121cdf0e10cSrcweir                 else
1122cdf0e10cSrcweir                     m_pImp->m_xObject->changeState( embed::EmbedStates::RUNNING );
1123cdf0e10cSrcweir             }
1124cdf0e10cSrcweir 
1125cdf0e10cSrcweir             if ( m_pViewSh )
1126cdf0e10cSrcweir             {
1127cdf0e10cSrcweir                 SfxViewFrame* pFrame = m_pViewSh->GetViewFrame();
1128cdf0e10cSrcweir                 SfxViewFrame::SetViewFrame( pFrame );
1129cdf0e10cSrcweir                 pFrame->GetTopFrame().LockResize_Impl(sal_False);
1130cdf0e10cSrcweir                 pFrame->GetTopFrame().Resize();
1131cdf0e10cSrcweir             }
1132cdf0e10cSrcweir         }
1133cdf0e10cSrcweir         catch (com::sun::star::uno::Exception& )
1134cdf0e10cSrcweir         {}
1135cdf0e10cSrcweir     }
1136cdf0e10cSrcweir }
1137cdf0e10cSrcweir 
ResetObject()1138cdf0e10cSrcweir void SfxInPlaceClient::ResetObject()
1139cdf0e10cSrcweir {
1140cdf0e10cSrcweir     if ( GetObject().is() )
1141cdf0e10cSrcweir     {
1142cdf0e10cSrcweir         try
1143cdf0e10cSrcweir         {
1144cdf0e10cSrcweir             m_pImp->m_bUIActive = sal_False;
1145cdf0e10cSrcweir             if ( m_pImp->m_xObject->getStatus( m_pImp->m_nAspect ) & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE )
1146cdf0e10cSrcweir                 m_pImp->m_xObject->changeState( embed::EmbedStates::INPLACE_ACTIVE );
1147cdf0e10cSrcweir             else
1148cdf0e10cSrcweir             {
1149cdf0e10cSrcweir                 // the links should not stay in running state for long time because of locking
1150cdf0e10cSrcweir                 uno::Reference< embed::XLinkageSupport > xLink( m_pImp->m_xObject, uno::UNO_QUERY );
1151cdf0e10cSrcweir                 if ( xLink.is() && xLink->isLink() )
1152cdf0e10cSrcweir                     m_pImp->m_xObject->changeState( embed::EmbedStates::LOADED );
1153cdf0e10cSrcweir                 else
1154cdf0e10cSrcweir                     m_pImp->m_xObject->changeState( embed::EmbedStates::RUNNING );
1155cdf0e10cSrcweir             }
1156cdf0e10cSrcweir         }
1157cdf0e10cSrcweir         catch (com::sun::star::uno::Exception& )
1158cdf0e10cSrcweir         {}
1159cdf0e10cSrcweir     }
1160cdf0e10cSrcweir }
1161cdf0e10cSrcweir 
IsUIActive()1162cdf0e10cSrcweir sal_Bool SfxInPlaceClient::IsUIActive()
1163cdf0e10cSrcweir {
1164cdf0e10cSrcweir     return m_pImp->m_bUIActive;
1165cdf0e10cSrcweir }
1166