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