1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_embeddedobj.hxx"
30*cdf0e10cSrcweir #include <com/sun/star/embed/EmbedStates.hpp>
31*cdf0e10cSrcweir #include <com/sun/star/embed/EmbedVerbs.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/embed/EmbedUpdateModes.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/embed/XEmbeddedClient.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/embed/XInplaceClient.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/embed/XWindowSupplier.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/embed/StateChangeInProgressException.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/embed/Aspects.hpp>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include <com/sun/star/awt/XWindowPeer.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/util/XCloseBroadcaster.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/util/XCloseable.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/frame/XModuleManager.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir #include <com/sun/star/embed/EmbedMisc.hpp>
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir #include <rtl/logfile.hxx>
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir #include <targetstatecontrol.hxx>
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir #include "commonembobj.hxx"
56*cdf0e10cSrcweir #include "intercept.hxx"
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir using namespace ::com::sun::star;
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir awt::Rectangle GetRectangleInterception( const awt::Rectangle& aRect1, const awt::Rectangle& aRect2 )
62*cdf0e10cSrcweir {
63*cdf0e10cSrcweir     awt::Rectangle aResult;
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir     OSL_ENSURE( aRect1.Width >= 0 && aRect2.Width >= 0 && aRect1.Height >= 0 && aRect2.Height >= 0,
66*cdf0e10cSrcweir                 "Offset must not be less then zero!" );
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir     aResult.X = aRect1.X > aRect2.X ? aRect1.X : aRect2.X;
69*cdf0e10cSrcweir     aResult.Y = aRect1.Y > aRect2.Y ? aRect1.Y : aRect2.Y;
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir     sal_Int32 nRight1 = aRect1.X + aRect1.Width;
72*cdf0e10cSrcweir     sal_Int32 nBottom1 = aRect1.Y + aRect1.Height;
73*cdf0e10cSrcweir     sal_Int32 nRight2 = aRect2.X + aRect2.Width;
74*cdf0e10cSrcweir     sal_Int32 nBottom2 = aRect2.Y + aRect2.Height;
75*cdf0e10cSrcweir     aResult.Width = ( nRight1 < nRight2 ? nRight1 : nRight2 ) - aResult.X;
76*cdf0e10cSrcweir     aResult.Height = ( nBottom1 < nBottom2 ? nBottom1 : nBottom2 ) - aResult.Y;
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir     return aResult;
79*cdf0e10cSrcweir }
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir //----------------------------------------------
82*cdf0e10cSrcweir sal_Int32 OCommonEmbeddedObject::ConvertVerbToState_Impl( sal_Int32 nVerb )
83*cdf0e10cSrcweir {
84*cdf0e10cSrcweir     for ( sal_Int32 nInd = 0; nInd < m_aVerbTable.getLength(); nInd++ )
85*cdf0e10cSrcweir         if ( m_aVerbTable[nInd][0] == nVerb )
86*cdf0e10cSrcweir             return m_aVerbTable[nInd][1];
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir     throw lang::IllegalArgumentException(); // TODO: unexpected verb provided
89*cdf0e10cSrcweir }
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir //----------------------------------------------
92*cdf0e10cSrcweir void OCommonEmbeddedObject::Deactivate()
93*cdf0e10cSrcweir {
94*cdf0e10cSrcweir     uno::Reference< util::XModifiable > xModif( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
95*cdf0e10cSrcweir     //MBA if ( !xModif.is() )
96*cdf0e10cSrcweir     //MBA    throw uno::RuntimeException();
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir     // no need to lock for the initialization
99*cdf0e10cSrcweir     uno::Reference< embed::XEmbeddedClient > xClientSite = m_xClientSite;
100*cdf0e10cSrcweir     if ( !xClientSite.is() )
101*cdf0e10cSrcweir         throw embed::WrongStateException(); //TODO: client site is not set!
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir     // store document if it is modified
104*cdf0e10cSrcweir     if ( xModif.is() && xModif->isModified() )
105*cdf0e10cSrcweir     {
106*cdf0e10cSrcweir         try {
107*cdf0e10cSrcweir             xClientSite->saveObject();
108*cdf0e10cSrcweir         }
109*cdf0e10cSrcweir         catch( embed::ObjectSaveVetoException& )
110*cdf0e10cSrcweir         {
111*cdf0e10cSrcweir         }
112*cdf0e10cSrcweir         catch( uno::Exception& e )
113*cdf0e10cSrcweir         {
114*cdf0e10cSrcweir             throw embed::StorageWrappedTargetException(
115*cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii( "The client could not store the object!" ),
116*cdf0e10cSrcweir                 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ),
117*cdf0e10cSrcweir                 uno::makeAny( e ) );
118*cdf0e10cSrcweir         }
119*cdf0e10cSrcweir     }
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir     m_pDocHolder->CloseFrame();
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir     xClientSite->visibilityChanged( sal_False );
124*cdf0e10cSrcweir }
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir //----------------------------------------------
127*cdf0e10cSrcweir void OCommonEmbeddedObject::StateChangeNotification_Impl( sal_Bool bBeforeChange, sal_Int32 nOldState, sal_Int32 nNewState ,::osl::ResettableMutexGuard& rGuard )
128*cdf0e10cSrcweir {
129*cdf0e10cSrcweir     if ( m_pInterfaceContainer )
130*cdf0e10cSrcweir     {
131*cdf0e10cSrcweir         ::cppu::OInterfaceContainerHelper* pContainer = m_pInterfaceContainer->getContainer(
132*cdf0e10cSrcweir                             ::getCppuType( ( const uno::Reference< embed::XStateChangeListener >*) NULL ) );
133*cdf0e10cSrcweir         if ( pContainer != NULL )
134*cdf0e10cSrcweir         {
135*cdf0e10cSrcweir             lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >( this ) );
136*cdf0e10cSrcweir             ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir             // should be locked after the method is finished successfully
139*cdf0e10cSrcweir             rGuard.clear();
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir             while (pIterator.hasMoreElements())
142*cdf0e10cSrcweir             {
143*cdf0e10cSrcweir                 try
144*cdf0e10cSrcweir                 {
145*cdf0e10cSrcweir                     if ( bBeforeChange )
146*cdf0e10cSrcweir                         ((embed::XStateChangeListener*)pIterator.next())->changingState( aSource, nOldState, nNewState );
147*cdf0e10cSrcweir                     else
148*cdf0e10cSrcweir                         ((embed::XStateChangeListener*)pIterator.next())->stateChanged( aSource, nOldState, nNewState );
149*cdf0e10cSrcweir                 }
150*cdf0e10cSrcweir                 catch( uno::Exception& )
151*cdf0e10cSrcweir                 {
152*cdf0e10cSrcweir                     // even if the listener complains ignore it for now
153*cdf0e10cSrcweir                    }
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir                 if ( m_bDisposed )
156*cdf0e10cSrcweir                     return;
157*cdf0e10cSrcweir             }
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir             rGuard.reset();
160*cdf0e10cSrcweir         }
161*cdf0e10cSrcweir     }
162*cdf0e10cSrcweir }
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir //----------------------------------------------
165*cdf0e10cSrcweir void OCommonEmbeddedObject::SwitchStateTo_Impl( sal_Int32 nNextState )
166*cdf0e10cSrcweir {
167*cdf0e10cSrcweir     // TODO: may be needs interaction handler to detect wherether the object state
168*cdf0e10cSrcweir     //         can be changed even after errors
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir     if ( m_nObjectState == embed::EmbedStates::LOADED )
171*cdf0e10cSrcweir     {
172*cdf0e10cSrcweir         if ( nNextState == embed::EmbedStates::RUNNING )
173*cdf0e10cSrcweir         {
174*cdf0e10cSrcweir             // after the object reaches the running state the cloned size is not necessary any more
175*cdf0e10cSrcweir             m_bHasClonedSize = sal_False;
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir             if ( m_bIsLink )
178*cdf0e10cSrcweir             {
179*cdf0e10cSrcweir                 m_pDocHolder->SetComponent( LoadLink_Impl(), m_bReadOnly );
180*cdf0e10cSrcweir             }
181*cdf0e10cSrcweir             else
182*cdf0e10cSrcweir             {
183*cdf0e10cSrcweir                 uno::Reference < embed::XEmbedPersist > xPersist( static_cast < embed::XClassifiedObject* > (this), uno::UNO_QUERY );
184*cdf0e10cSrcweir                 if ( xPersist.is() )
185*cdf0e10cSrcweir                 {
186*cdf0e10cSrcweir                     // in case embedded object is in loaded state the contents must
187*cdf0e10cSrcweir                     // be stored in the related storage and the storage
188*cdf0e10cSrcweir                     // must be created already
189*cdf0e10cSrcweir                     if ( !m_xObjectStorage.is() )
190*cdf0e10cSrcweir                         throw io::IOException(); //TODO: access denied
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir                     m_pDocHolder->SetComponent( LoadDocumentFromStorage_Impl(), m_bReadOnly );
193*cdf0e10cSrcweir                 }
194*cdf0e10cSrcweir                 else
195*cdf0e10cSrcweir                 {
196*cdf0e10cSrcweir                     // objects without persistence will be initialized internally
197*cdf0e10cSrcweir                     uno::Sequence < uno::Any > aArgs(1);
198*cdf0e10cSrcweir                     aArgs[0] <<= uno::Reference < embed::XEmbeddedObject >( this );
199*cdf0e10cSrcweir                     uno::Reference< util::XCloseable > xDocument(
200*cdf0e10cSrcweir                             m_xFactory->createInstanceWithArguments( GetDocumentServiceName(), aArgs ), uno::UNO_QUERY );
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir                     uno::Reference < container::XChild > xChild( xDocument, uno::UNO_QUERY );
203*cdf0e10cSrcweir                     if ( xChild.is() )
204*cdf0e10cSrcweir                         xChild->setParent( m_xParent );
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir                     m_pDocHolder->SetComponent( xDocument, m_bReadOnly );
207*cdf0e10cSrcweir                 }
208*cdf0e10cSrcweir             }
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir             if ( !m_pDocHolder->GetComponent().is() )
211*cdf0e10cSrcweir                 throw embed::UnreachableStateException(); //TODO: can't open document
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir             m_nObjectState = nNextState;
214*cdf0e10cSrcweir         }
215*cdf0e10cSrcweir         else
216*cdf0e10cSrcweir         {
217*cdf0e10cSrcweir             OSL_ENSURE( sal_False, "Unacceptable state switch!\n" );
218*cdf0e10cSrcweir             throw uno::RuntimeException(); // TODO
219*cdf0e10cSrcweir         }
220*cdf0e10cSrcweir     }
221*cdf0e10cSrcweir     else if ( m_nObjectState == embed::EmbedStates::RUNNING )
222*cdf0e10cSrcweir     {
223*cdf0e10cSrcweir         if ( nNextState == embed::EmbedStates::LOADED )
224*cdf0e10cSrcweir         {
225*cdf0e10cSrcweir             m_nClonedMapUnit = m_pDocHolder->GetMapUnit( embed::Aspects::MSOLE_CONTENT );
226*cdf0e10cSrcweir             m_bHasClonedSize = m_pDocHolder->GetExtent( embed::Aspects::MSOLE_CONTENT, &m_aClonedSize );
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir             // actually frame should not exist at this point
229*cdf0e10cSrcweir             m_pDocHolder->CloseDocument( sal_False, sal_False );
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir             m_nObjectState = nNextState;
232*cdf0e10cSrcweir         }
233*cdf0e10cSrcweir         else
234*cdf0e10cSrcweir         {
235*cdf0e10cSrcweir             if ( nNextState == embed::EmbedStates::INPLACE_ACTIVE )
236*cdf0e10cSrcweir             {
237*cdf0e10cSrcweir                 if ( !m_xClientSite.is() )
238*cdf0e10cSrcweir                     throw embed::WrongStateException(
239*cdf0e10cSrcweir                         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "client site not set, yet" ) ),
240*cdf0e10cSrcweir                         *this
241*cdf0e10cSrcweir                 );
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir                 uno::Reference< embed::XInplaceClient > xInplaceClient( m_xClientSite, uno::UNO_QUERY );
244*cdf0e10cSrcweir                 if ( xInplaceClient.is() && xInplaceClient->canInplaceActivate() )
245*cdf0e10cSrcweir                 {
246*cdf0e10cSrcweir                     xInplaceClient->activatingInplace();
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir                     uno::Reference< embed::XWindowSupplier > xClientWindowSupplier( xInplaceClient, uno::UNO_QUERY );
249*cdf0e10cSrcweir                     if ( !xClientWindowSupplier.is() )
250*cdf0e10cSrcweir                         throw uno::RuntimeException(); // TODO: the inplace client implementation must support XWinSupp
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir                     m_xClientWindow = xClientWindowSupplier->getWindow();
253*cdf0e10cSrcweir                     m_aOwnRectangle = xInplaceClient->getPlacement();
254*cdf0e10cSrcweir                     m_aClipRectangle = xInplaceClient->getClipRectangle();
255*cdf0e10cSrcweir                     awt::Rectangle aRectangleToShow = GetRectangleInterception( m_aOwnRectangle, m_aClipRectangle );
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir                     // create own window based on the client window
258*cdf0e10cSrcweir                     // place and resize the window according to the rectangles
259*cdf0e10cSrcweir                     uno::Reference< awt::XWindowPeer > xClientWindowPeer( m_xClientWindow, uno::UNO_QUERY );
260*cdf0e10cSrcweir                     if ( !xClientWindowPeer.is() )
261*cdf0e10cSrcweir                         throw uno::RuntimeException(); // TODO: the container window must support the interface
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir                     // dispatch provider may not be provided
264*cdf0e10cSrcweir                     uno::Reference< frame::XDispatchProvider > xContainerDP = xInplaceClient->getInplaceDispatchProvider();
265*cdf0e10cSrcweir                     sal_Bool bOk = m_pDocHolder->ShowInplace( xClientWindowPeer, aRectangleToShow, xContainerDP );
266*cdf0e10cSrcweir                     m_nObjectState = nNextState;
267*cdf0e10cSrcweir                     if ( !bOk )
268*cdf0e10cSrcweir                     {
269*cdf0e10cSrcweir                         SwitchStateTo_Impl( embed::EmbedStates::RUNNING );
270*cdf0e10cSrcweir                         throw embed::WrongStateException(); //TODO: can't activate inplace
271*cdf0e10cSrcweir                     }
272*cdf0e10cSrcweir                 }
273*cdf0e10cSrcweir                 else
274*cdf0e10cSrcweir                     throw embed::WrongStateException(); //TODO: can't activate inplace
275*cdf0e10cSrcweir             }
276*cdf0e10cSrcweir             else if ( nNextState == embed::EmbedStates::ACTIVE )
277*cdf0e10cSrcweir             {
278*cdf0e10cSrcweir                 if ( !m_xClientSite.is() )
279*cdf0e10cSrcweir                     throw embed::WrongStateException(); //TODO: client site is not set!
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir                 // create frame and load document in the frame
282*cdf0e10cSrcweir                 m_pDocHolder->Show();
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir                 m_xClientSite->visibilityChanged( sal_True );
285*cdf0e10cSrcweir                 m_nObjectState = nNextState;
286*cdf0e10cSrcweir             }
287*cdf0e10cSrcweir             else
288*cdf0e10cSrcweir             {
289*cdf0e10cSrcweir                 OSL_ENSURE( sal_False, "Unacceptable state switch!\n" );
290*cdf0e10cSrcweir                 throw uno::RuntimeException(); // TODO
291*cdf0e10cSrcweir             }
292*cdf0e10cSrcweir         }
293*cdf0e10cSrcweir     }
294*cdf0e10cSrcweir     else if ( m_nObjectState == embed::EmbedStates::INPLACE_ACTIVE )
295*cdf0e10cSrcweir     {
296*cdf0e10cSrcweir         if ( nNextState == embed::EmbedStates::RUNNING )
297*cdf0e10cSrcweir         {
298*cdf0e10cSrcweir             uno::Reference< embed::XInplaceClient > xInplaceClient( m_xClientSite, uno::UNO_QUERY );
299*cdf0e10cSrcweir             if ( !xInplaceClient.is() )
300*cdf0e10cSrcweir                 throw uno::RuntimeException();
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir             m_xClientSite->visibilityChanged( sal_True );
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir             xInplaceClient->deactivatedInplace();
305*cdf0e10cSrcweir             Deactivate();
306*cdf0e10cSrcweir             m_nObjectState = nNextState;
307*cdf0e10cSrcweir         }
308*cdf0e10cSrcweir         else if ( nNextState == embed::EmbedStates::UI_ACTIVE )
309*cdf0e10cSrcweir         {
310*cdf0e10cSrcweir             if ( !(m_nMiscStatus & embed::EmbedMisc::MS_EMBED_NOUIACTIVATE) )
311*cdf0e10cSrcweir             {
312*cdf0e10cSrcweir                 uno::Reference< embed::XInplaceClient > xInplaceClient( m_xClientSite, uno::UNO_QUERY_THROW );
313*cdf0e10cSrcweir                 // TODO:
314*cdf0e10cSrcweir                 uno::Reference< ::com::sun::star::frame::XLayoutManager > xContainerLM =
315*cdf0e10cSrcweir                             xInplaceClient->getLayoutManager();
316*cdf0e10cSrcweir                 if ( xContainerLM.is() )
317*cdf0e10cSrcweir                 {
318*cdf0e10cSrcweir                     // dispatch provider may not be provided
319*cdf0e10cSrcweir                     uno::Reference< frame::XDispatchProvider > xContainerDP = xInplaceClient->getInplaceDispatchProvider();
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir                     // get the container module name
322*cdf0e10cSrcweir                     ::rtl::OUString aModuleName;
323*cdf0e10cSrcweir                     try
324*cdf0e10cSrcweir                     {
325*cdf0e10cSrcweir                         uno::Reference< embed::XComponentSupplier > xCompSupl( m_xClientSite, uno::UNO_QUERY_THROW );
326*cdf0e10cSrcweir                         uno::Reference< uno::XInterface > xContDoc( xCompSupl->getComponent(), uno::UNO_QUERY_THROW );
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir                         uno::Reference< frame::XModuleManager > xManager(
329*cdf0e10cSrcweir                             m_xFactory->createInstance(
330*cdf0e10cSrcweir                                     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ModuleManager" ) ) ),
331*cdf0e10cSrcweir                             uno::UNO_QUERY_THROW );
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir                         aModuleName = xManager->identify( xContDoc );
334*cdf0e10cSrcweir                     }
335*cdf0e10cSrcweir                     catch( uno::Exception& )
336*cdf0e10cSrcweir                     {}
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir                     // if currently another object is UIactive it will be deactivated; usually this will activate the LM of
339*cdf0e10cSrcweir                     // the container. Locking the LM will prevent flicker.
340*cdf0e10cSrcweir                     xContainerLM->lock();
341*cdf0e10cSrcweir                     xInplaceClient->activatingUI();
342*cdf0e10cSrcweir                     sal_Bool bOk = m_pDocHolder->ShowUI( xContainerLM, xContainerDP, aModuleName );
343*cdf0e10cSrcweir                     xContainerLM->unlock();
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir                     if ( bOk )
346*cdf0e10cSrcweir                     {
347*cdf0e10cSrcweir                         m_nObjectState = nNextState;
348*cdf0e10cSrcweir                         m_pDocHolder->ResizeHatchWindow();
349*cdf0e10cSrcweir                     }
350*cdf0e10cSrcweir                     else
351*cdf0e10cSrcweir                     {
352*cdf0e10cSrcweir                         xInplaceClient->deactivatedUI();
353*cdf0e10cSrcweir                         throw embed::WrongStateException(); //TODO: can't activate UI
354*cdf0e10cSrcweir                     }
355*cdf0e10cSrcweir                 }
356*cdf0e10cSrcweir                 else
357*cdf0e10cSrcweir                     throw embed::WrongStateException(); //TODO: can't activate UI
358*cdf0e10cSrcweir             }
359*cdf0e10cSrcweir         }
360*cdf0e10cSrcweir         else
361*cdf0e10cSrcweir         {
362*cdf0e10cSrcweir             OSL_ENSURE( sal_False, "Unacceptable state switch!\n" );
363*cdf0e10cSrcweir             throw uno::RuntimeException(); // TODO
364*cdf0e10cSrcweir         }
365*cdf0e10cSrcweir     }
366*cdf0e10cSrcweir     else if ( m_nObjectState == embed::EmbedStates::ACTIVE )
367*cdf0e10cSrcweir     {
368*cdf0e10cSrcweir         if ( nNextState == embed::EmbedStates::RUNNING )
369*cdf0e10cSrcweir         {
370*cdf0e10cSrcweir             Deactivate();
371*cdf0e10cSrcweir             m_nObjectState = nNextState;
372*cdf0e10cSrcweir         }
373*cdf0e10cSrcweir         else
374*cdf0e10cSrcweir         {
375*cdf0e10cSrcweir             OSL_ENSURE( sal_False, "Unacceptable state switch!\n" );
376*cdf0e10cSrcweir             throw uno::RuntimeException(); // TODO
377*cdf0e10cSrcweir         }
378*cdf0e10cSrcweir     }
379*cdf0e10cSrcweir     else if ( m_nObjectState == embed::EmbedStates::UI_ACTIVE )
380*cdf0e10cSrcweir     {
381*cdf0e10cSrcweir         if ( nNextState == embed::EmbedStates::INPLACE_ACTIVE )
382*cdf0e10cSrcweir         {
383*cdf0e10cSrcweir             uno::Reference< embed::XInplaceClient > xInplaceClient( m_xClientSite, uno::UNO_QUERY_THROW );
384*cdf0e10cSrcweir             uno::Reference< ::com::sun::star::frame::XLayoutManager > xContainerLM =
385*cdf0e10cSrcweir                         xInplaceClient->getLayoutManager();
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir             sal_Bool bOk = sal_False;
388*cdf0e10cSrcweir             if ( xContainerLM.is() )
389*cdf0e10cSrcweir                    bOk = m_pDocHolder->HideUI( xContainerLM );
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir             if ( bOk )
392*cdf0e10cSrcweir             {
393*cdf0e10cSrcweir                 m_nObjectState = nNextState;
394*cdf0e10cSrcweir                 m_pDocHolder->ResizeHatchWindow();
395*cdf0e10cSrcweir                    xInplaceClient->deactivatedUI();
396*cdf0e10cSrcweir             }
397*cdf0e10cSrcweir             else
398*cdf0e10cSrcweir                 throw embed::WrongStateException(); //TODO: can't activate UI
399*cdf0e10cSrcweir         }
400*cdf0e10cSrcweir     }
401*cdf0e10cSrcweir     else
402*cdf0e10cSrcweir         throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object is in unacceptable state!\n" ),
403*cdf0e10cSrcweir                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
404*cdf0e10cSrcweir }
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir //----------------------------------------------
407*cdf0e10cSrcweir uno::Sequence< sal_Int32 > OCommonEmbeddedObject::GetIntermediateStatesSequence_Impl( sal_Int32 nNewState )
408*cdf0e10cSrcweir {
409*cdf0e10cSrcweir     sal_Int32 nCurInd = 0;
410*cdf0e10cSrcweir     for ( nCurInd = 0; nCurInd < m_aAcceptedStates.getLength(); nCurInd++ )
411*cdf0e10cSrcweir         if ( m_aAcceptedStates[nCurInd] == m_nObjectState )
412*cdf0e10cSrcweir             break;
413*cdf0e10cSrcweir 
414*cdf0e10cSrcweir     if ( nCurInd == m_aAcceptedStates.getLength() )
415*cdf0e10cSrcweir         throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object is in unacceptable state!\n" ),
416*cdf0e10cSrcweir                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir     sal_Int32 nDestInd = 0;
419*cdf0e10cSrcweir     for ( nDestInd = 0; nDestInd < m_aAcceptedStates.getLength(); nDestInd++ )
420*cdf0e10cSrcweir         if ( m_aAcceptedStates[nDestInd] == nNewState )
421*cdf0e10cSrcweir             break;
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir     if ( nDestInd == m_aAcceptedStates.getLength() )
424*cdf0e10cSrcweir         throw embed::UnreachableStateException(
425*cdf0e10cSrcweir             ::rtl::OUString::createFromAscii( "The state either not reachable, or the object allows the state only as an intermediate one!\n" ),
426*cdf0e10cSrcweir             uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
427*cdf0e10cSrcweir             m_nObjectState,
428*cdf0e10cSrcweir             nNewState );
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir     return m_pIntermediateStatesSeqs[nCurInd][nDestInd];
431*cdf0e10cSrcweir }
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir //----------------------------------------------
434*cdf0e10cSrcweir void SAL_CALL OCommonEmbeddedObject::changeState( sal_Int32 nNewState )
435*cdf0e10cSrcweir         throw ( embed::UnreachableStateException,
436*cdf0e10cSrcweir                 embed::WrongStateException,
437*cdf0e10cSrcweir                 uno::Exception,
438*cdf0e10cSrcweir                 uno::RuntimeException )
439*cdf0e10cSrcweir {
440*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::changeState" );
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ), uno::UNO_QUERY);
443*cdf0e10cSrcweir     {
444*cdf0e10cSrcweir         ::osl::ResettableMutexGuard aGuard( m_aMutex );
445*cdf0e10cSrcweir         if ( m_bDisposed )
446*cdf0e10cSrcweir             throw lang::DisposedException(); // TODO
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir         if ( m_nObjectState == -1 )
449*cdf0e10cSrcweir             throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ),
450*cdf0e10cSrcweir                                             uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
451*cdf0e10cSrcweir 
452*cdf0e10cSrcweir         sal_Int32 nOldState = m_nObjectState;
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir         if ( m_nTargetState != -1 )
455*cdf0e10cSrcweir         {
456*cdf0e10cSrcweir             // means that the object is currently trying to reach the target state
457*cdf0e10cSrcweir             throw embed::StateChangeInProgressException( ::rtl::OUString(),
458*cdf0e10cSrcweir                                                         uno::Reference< uno::XInterface >(),
459*cdf0e10cSrcweir                                                         m_nTargetState );
460*cdf0e10cSrcweir         }
461*cdf0e10cSrcweir         else
462*cdf0e10cSrcweir         {
463*cdf0e10cSrcweir             TargetStateControl_Impl aControl( m_nTargetState, nNewState );
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir             // in case the object is already in requested state
466*cdf0e10cSrcweir             if ( m_nObjectState == nNewState )
467*cdf0e10cSrcweir             {
468*cdf0e10cSrcweir                 // if active object is activated again, bring it's window to top
469*cdf0e10cSrcweir                 if ( m_nObjectState == embed::EmbedStates::ACTIVE )
470*cdf0e10cSrcweir                     m_pDocHolder->Show();
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir                 return;
473*cdf0e10cSrcweir             }
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir             // retrieve sequence of states that should be passed to reach desired state
476*cdf0e10cSrcweir             uno::Sequence< sal_Int32 > aIntermediateStates = GetIntermediateStatesSequence_Impl( nNewState );
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir             // notify listeners that the object is going to change the state
479*cdf0e10cSrcweir             StateChangeNotification_Impl( sal_True, nOldState, nNewState,aGuard );
480*cdf0e10cSrcweir 
481*cdf0e10cSrcweir             try {
482*cdf0e10cSrcweir                 for ( sal_Int32 nInd = 0; nInd < aIntermediateStates.getLength(); nInd++ )
483*cdf0e10cSrcweir                     SwitchStateTo_Impl( aIntermediateStates[nInd] );
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir                 SwitchStateTo_Impl( nNewState );
486*cdf0e10cSrcweir             }
487*cdf0e10cSrcweir             catch( uno::Exception& )
488*cdf0e10cSrcweir             {
489*cdf0e10cSrcweir                 if ( nOldState != m_nObjectState )
490*cdf0e10cSrcweir                     // notify listeners that the object has changed the state
491*cdf0e10cSrcweir                     StateChangeNotification_Impl( sal_False, nOldState, m_nObjectState, aGuard );
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir                 throw;
494*cdf0e10cSrcweir             }
495*cdf0e10cSrcweir         }
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir         // notify listeners that the object has changed the state
498*cdf0e10cSrcweir         StateChangeNotification_Impl( sal_False, nOldState, nNewState, aGuard );
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir         // let the object window be shown
501*cdf0e10cSrcweir         if ( nNewState == embed::EmbedStates::UI_ACTIVE || nNewState == embed::EmbedStates::INPLACE_ACTIVE )
502*cdf0e10cSrcweir             PostEvent_Impl( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnVisAreaChanged" ) ),
503*cdf0e10cSrcweir                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
504*cdf0e10cSrcweir     }
505*cdf0e10cSrcweir }
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir //----------------------------------------------
508*cdf0e10cSrcweir uno::Sequence< sal_Int32 > SAL_CALL OCommonEmbeddedObject::getReachableStates()
509*cdf0e10cSrcweir         throw ( embed::WrongStateException,
510*cdf0e10cSrcweir                 uno::RuntimeException )
511*cdf0e10cSrcweir {
512*cdf0e10cSrcweir     if ( m_bDisposed )
513*cdf0e10cSrcweir         throw lang::DisposedException(); // TODO
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir     if ( m_nObjectState == -1 )
516*cdf0e10cSrcweir         throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ),
517*cdf0e10cSrcweir                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir     return m_aAcceptedStates;
520*cdf0e10cSrcweir }
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir //----------------------------------------------
523*cdf0e10cSrcweir sal_Int32 SAL_CALL OCommonEmbeddedObject::getCurrentState()
524*cdf0e10cSrcweir         throw ( embed::WrongStateException,
525*cdf0e10cSrcweir                 uno::RuntimeException )
526*cdf0e10cSrcweir {
527*cdf0e10cSrcweir     if ( m_bDisposed )
528*cdf0e10cSrcweir         throw lang::DisposedException(); // TODO
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir     if ( m_nObjectState == -1 )
531*cdf0e10cSrcweir         throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ),
532*cdf0e10cSrcweir                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir     return m_nObjectState;
535*cdf0e10cSrcweir }
536*cdf0e10cSrcweir 
537*cdf0e10cSrcweir //----------------------------------------------
538*cdf0e10cSrcweir void SAL_CALL OCommonEmbeddedObject::doVerb( sal_Int32 nVerbID )
539*cdf0e10cSrcweir         throw ( lang::IllegalArgumentException,
540*cdf0e10cSrcweir                 embed::WrongStateException,
541*cdf0e10cSrcweir                 embed::UnreachableStateException,
542*cdf0e10cSrcweir                 uno::Exception,
543*cdf0e10cSrcweir                 uno::RuntimeException )
544*cdf0e10cSrcweir {
545*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::doVerb" );
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir     ::osl::ResettableMutexGuard aGuard( m_aMutex );
548*cdf0e10cSrcweir     if ( m_bDisposed )
549*cdf0e10cSrcweir         throw lang::DisposedException(); // TODO
550*cdf0e10cSrcweir 
551*cdf0e10cSrcweir     if ( m_nObjectState == -1 )
552*cdf0e10cSrcweir         throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ),
553*cdf0e10cSrcweir                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir     // for internal documents this call is just a duplicate of changeState
556*cdf0e10cSrcweir     sal_Int32 nNewState = -1;
557*cdf0e10cSrcweir     try
558*cdf0e10cSrcweir     {
559*cdf0e10cSrcweir         nNewState = ConvertVerbToState_Impl( nVerbID );
560*cdf0e10cSrcweir     }
561*cdf0e10cSrcweir     catch( uno::Exception& )
562*cdf0e10cSrcweir     {}
563*cdf0e10cSrcweir 
564*cdf0e10cSrcweir     if ( nNewState == -1 )
565*cdf0e10cSrcweir     {
566*cdf0e10cSrcweir         // TODO/LATER: Save Copy as... verb ( -8 ) is implemented by container
567*cdf0e10cSrcweir         // TODO/LATER: check if the verb is a supported one and if it is produce related operation
568*cdf0e10cSrcweir     }
569*cdf0e10cSrcweir     else
570*cdf0e10cSrcweir     {
571*cdf0e10cSrcweir         aGuard.clear();
572*cdf0e10cSrcweir         changeState( nNewState );
573*cdf0e10cSrcweir     }
574*cdf0e10cSrcweir }
575*cdf0e10cSrcweir 
576*cdf0e10cSrcweir //----------------------------------------------
577*cdf0e10cSrcweir uno::Sequence< embed::VerbDescriptor > SAL_CALL OCommonEmbeddedObject::getSupportedVerbs()
578*cdf0e10cSrcweir         throw ( embed::WrongStateException,
579*cdf0e10cSrcweir                 uno::RuntimeException )
580*cdf0e10cSrcweir {
581*cdf0e10cSrcweir     if ( m_bDisposed )
582*cdf0e10cSrcweir         throw lang::DisposedException(); // TODO
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir     if ( m_nObjectState == -1 )
585*cdf0e10cSrcweir         throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ),
586*cdf0e10cSrcweir                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
587*cdf0e10cSrcweir 
588*cdf0e10cSrcweir     return m_aObjectVerbs;
589*cdf0e10cSrcweir }
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir //----------------------------------------------
592*cdf0e10cSrcweir void SAL_CALL OCommonEmbeddedObject::setClientSite(
593*cdf0e10cSrcweir                 const uno::Reference< embed::XEmbeddedClient >& xClient )
594*cdf0e10cSrcweir         throw ( embed::WrongStateException,
595*cdf0e10cSrcweir                 uno::RuntimeException )
596*cdf0e10cSrcweir {
597*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( m_aMutex );
598*cdf0e10cSrcweir     if ( m_bDisposed )
599*cdf0e10cSrcweir         throw lang::DisposedException(); // TODO
600*cdf0e10cSrcweir 
601*cdf0e10cSrcweir     if ( m_xClientSite != xClient)
602*cdf0e10cSrcweir     {
603*cdf0e10cSrcweir         if ( m_nObjectState != embed::EmbedStates::LOADED && m_nObjectState != embed::EmbedStates::RUNNING )
604*cdf0e10cSrcweir             throw embed::WrongStateException(
605*cdf0e10cSrcweir                                     ::rtl::OUString::createFromAscii( "The client site can not be set currently!\n" ),
606*cdf0e10cSrcweir                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
607*cdf0e10cSrcweir 
608*cdf0e10cSrcweir         m_xClientSite = xClient;
609*cdf0e10cSrcweir     }
610*cdf0e10cSrcweir }
611*cdf0e10cSrcweir 
612*cdf0e10cSrcweir //----------------------------------------------
613*cdf0e10cSrcweir uno::Reference< embed::XEmbeddedClient > SAL_CALL OCommonEmbeddedObject::getClientSite()
614*cdf0e10cSrcweir         throw ( embed::WrongStateException,
615*cdf0e10cSrcweir                 uno::RuntimeException )
616*cdf0e10cSrcweir {
617*cdf0e10cSrcweir     if ( m_bDisposed )
618*cdf0e10cSrcweir         throw lang::DisposedException(); // TODO
619*cdf0e10cSrcweir 
620*cdf0e10cSrcweir     if ( m_nObjectState == -1 )
621*cdf0e10cSrcweir         throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ),
622*cdf0e10cSrcweir                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
623*cdf0e10cSrcweir 
624*cdf0e10cSrcweir     return m_xClientSite;
625*cdf0e10cSrcweir }
626*cdf0e10cSrcweir 
627*cdf0e10cSrcweir //----------------------------------------------
628*cdf0e10cSrcweir void SAL_CALL OCommonEmbeddedObject::update()
629*cdf0e10cSrcweir         throw ( embed::WrongStateException,
630*cdf0e10cSrcweir                 uno::Exception,
631*cdf0e10cSrcweir                 uno::RuntimeException )
632*cdf0e10cSrcweir {
633*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( m_aMutex );
634*cdf0e10cSrcweir     if ( m_bDisposed )
635*cdf0e10cSrcweir         throw lang::DisposedException(); // TODO
636*cdf0e10cSrcweir 
637*cdf0e10cSrcweir     if ( m_nObjectState == -1 )
638*cdf0e10cSrcweir         throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ),
639*cdf0e10cSrcweir                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
640*cdf0e10cSrcweir 
641*cdf0e10cSrcweir     PostEvent_Impl( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnVisAreaChanged" ) ),
642*cdf0e10cSrcweir                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
643*cdf0e10cSrcweir }
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir //----------------------------------------------
646*cdf0e10cSrcweir void SAL_CALL OCommonEmbeddedObject::setUpdateMode( sal_Int32 nMode )
647*cdf0e10cSrcweir         throw ( embed::WrongStateException,
648*cdf0e10cSrcweir                 uno::RuntimeException )
649*cdf0e10cSrcweir {
650*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( m_aMutex );
651*cdf0e10cSrcweir     if ( m_bDisposed )
652*cdf0e10cSrcweir         throw lang::DisposedException(); // TODO
653*cdf0e10cSrcweir 
654*cdf0e10cSrcweir     if ( m_nObjectState == -1 )
655*cdf0e10cSrcweir         throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ),
656*cdf0e10cSrcweir                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
657*cdf0e10cSrcweir 
658*cdf0e10cSrcweir     OSL_ENSURE( nMode == embed::EmbedUpdateModes::ALWAYS_UPDATE
659*cdf0e10cSrcweir                     || nMode == embed::EmbedUpdateModes::EXPLICIT_UPDATE,
660*cdf0e10cSrcweir                 "Unknown update mode!\n" );
661*cdf0e10cSrcweir     m_nUpdateMode = nMode;
662*cdf0e10cSrcweir }
663*cdf0e10cSrcweir 
664*cdf0e10cSrcweir //----------------------------------------------
665*cdf0e10cSrcweir sal_Int64 SAL_CALL OCommonEmbeddedObject::getStatus( sal_Int64 )
666*cdf0e10cSrcweir         throw ( embed::WrongStateException,
667*cdf0e10cSrcweir                 uno::RuntimeException )
668*cdf0e10cSrcweir {
669*cdf0e10cSrcweir     if ( m_bDisposed )
670*cdf0e10cSrcweir         throw lang::DisposedException(); // TODO
671*cdf0e10cSrcweir 
672*cdf0e10cSrcweir     return m_nMiscStatus;
673*cdf0e10cSrcweir }
674*cdf0e10cSrcweir 
675*cdf0e10cSrcweir //----------------------------------------------
676*cdf0e10cSrcweir void SAL_CALL OCommonEmbeddedObject::setContainerName( const ::rtl::OUString& sName )
677*cdf0e10cSrcweir         throw ( uno::RuntimeException )
678*cdf0e10cSrcweir {
679*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( m_aMutex );
680*cdf0e10cSrcweir     if ( m_bDisposed )
681*cdf0e10cSrcweir         throw lang::DisposedException(); // TODO
682*cdf0e10cSrcweir 
683*cdf0e10cSrcweir     m_aContainerName = sName;
684*cdf0e10cSrcweir }
685*cdf0e10cSrcweir 
686*cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::uno::XInterface > SAL_CALL OCommonEmbeddedObject::getParent() throw (::com::sun::star::uno::RuntimeException)
687*cdf0e10cSrcweir {
688*cdf0e10cSrcweir     return m_xParent;
689*cdf0e10cSrcweir }
690*cdf0e10cSrcweir 
691*cdf0e10cSrcweir void SAL_CALL OCommonEmbeddedObject::setParent( const com::sun::star::uno::Reference< com::sun::star::uno::XInterface >& xParent ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException)
692*cdf0e10cSrcweir {
693*cdf0e10cSrcweir     m_xParent = xParent;
694*cdf0e10cSrcweir     if ( m_nObjectState != -1 && m_nObjectState != embed::EmbedStates::LOADED )
695*cdf0e10cSrcweir     {
696*cdf0e10cSrcweir         uno::Reference < container::XChild > xChild( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
697*cdf0e10cSrcweir         if ( xChild.is() )
698*cdf0e10cSrcweir             xChild->setParent( xParent );
699*cdf0e10cSrcweir     }
700*cdf0e10cSrcweir }
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir // XDefaultSizeTransmitter
703*cdf0e10cSrcweir void SAL_CALL OCommonEmbeddedObject::setDefaultSize( const ::com::sun::star::awt::Size& rSize_100TH_MM ) throw (::com::sun::star::uno::RuntimeException)
704*cdf0e10cSrcweir {
705*cdf0e10cSrcweir     //#i103460# charts do not necessaryly have an own size within ODF files, in this case they need to use the size settings from the surrounding frame, which is made available with this method
706*cdf0e10cSrcweir     m_aDefaultSizeForChart_In_100TH_MM = rSize_100TH_MM;
707*cdf0e10cSrcweir }
708