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