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