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