LibreOffice Module embeddedobj (master) 1
dummyobject.cxx
Go to the documentation of this file.
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/UnreachableStateException.hpp>
22#include <com/sun/star/embed/WrongStateException.hpp>
23#include <com/sun/star/embed/XEmbeddedClient.hpp>
24#include <com/sun/star/embed/Aspects.hpp>
25#include <com/sun/star/embed/EmbedMapUnits.hpp>
26#include <com/sun/star/embed/EntryInitModes.hpp>
27#include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
28#include <com/sun/star/io/IOException.hpp>
29#include <com/sun/star/lang/DisposedException.hpp>
30#include <com/sun/star/lang/IllegalArgumentException.hpp>
31#include <com/sun/star/lang/NoSupportException.hpp>
32
35#include <osl/diagnose.h>
36#include <dummyobject.hxx>
37
38
39using namespace ::com::sun::star;
40
41
43{
44 if ( m_bDisposed )
45 throw lang::DisposedException();
46
47 if ( m_nObjectState == -1 )
48 throw embed::WrongStateException( "The object has no persistence!",
49 static_cast< ::cppu::OWeakObject* >(this) );
50}
51
53{
54 if ( m_bDisposed )
55 throw lang::DisposedException();
56
57 if ( m_nObjectState == -1 )
58 throw uno::RuntimeException( "The object has no persistence!",
59 static_cast< ::cppu::OWeakObject* >(this) );
60}
61void ODummyEmbeddedObject::PostEvent_Impl( const OUString& aEventName )
62{
64 return;
65
68 if( !pIC )
69 return;
70
71 document::EventObject aEvent;
72 aEvent.EventName = aEventName;
73 aEvent.Source.set( static_cast< ::cppu::OWeakObject* >( this ) );
74 // For now all the events are sent as object events
75 // aEvent.Source = ( xSource.is() ? xSource
76 // : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ) );
78 while( aIt.hasMoreElements() )
79 {
80 try
81 {
82 static_cast<document::XEventListener *>(aIt.next())->notifyEvent( aEvent );
83 }
84 catch( const uno::RuntimeException& )
85 {
86 aIt.remove();
87 }
88
89 // the listener could dispose the object.
90 if ( m_bDisposed )
91 return;
92 }
93}
94
95
97{
98}
99
100
101void SAL_CALL ODummyEmbeddedObject::changeState( sal_Int32 nNewState )
102{
103 ::osl::MutexGuard aGuard( m_aMutex );
105
106 if ( nNewState == embed::EmbedStates::LOADED )
107 return;
108
109 throw embed::UnreachableStateException();
110}
111
112
113uno::Sequence< sal_Int32 > SAL_CALL ODummyEmbeddedObject::getReachableStates()
114{
115 ::osl::MutexGuard aGuard( m_aMutex );
117
118 return { embed::EmbedStates::LOADED };
119}
120
121
123{
124 ::osl::MutexGuard aGuard( m_aMutex );
126
127 return m_nObjectState;
128}
129
130
131void SAL_CALL ODummyEmbeddedObject::doVerb( sal_Int32 )
132{
133 ::osl::MutexGuard aGuard( m_aMutex );
135
136 // no supported verbs
137}
138
139
140uno::Sequence< embed::VerbDescriptor > SAL_CALL ODummyEmbeddedObject::getSupportedVerbs()
141{
142 ::osl::MutexGuard aGuard( m_aMutex );
144
145 return uno::Sequence< embed::VerbDescriptor >();
146}
147
148
150 const uno::Reference< embed::XEmbeddedClient >& xClient )
151{
152 ::osl::MutexGuard aGuard( m_aMutex );
154
155 m_xClientSite = xClient;
156}
157
158
159uno::Reference< embed::XEmbeddedClient > SAL_CALL ODummyEmbeddedObject::getClientSite()
160{
161 ::osl::MutexGuard aGuard( m_aMutex );
163
164 return m_xClientSite;
165}
166
167
169{
170 ::osl::MutexGuard aGuard( m_aMutex );
172}
173
174
175void SAL_CALL ODummyEmbeddedObject::setUpdateMode( sal_Int32 )
176{
177 ::osl::MutexGuard aGuard( m_aMutex );
179}
180
181
182sal_Int64 SAL_CALL ODummyEmbeddedObject::getStatus( sal_Int64 )
183{
184 ::osl::MutexGuard aGuard( m_aMutex );
186
187 return 0;
188}
189
190
191void SAL_CALL ODummyEmbeddedObject::setContainerName( const OUString& )
192{
193 ::osl::MutexGuard aGuard( m_aMutex );
195}
196
197
198void SAL_CALL ODummyEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize )
199{
200 ::osl::MutexGuard aGuard( m_aMutex );
202
203 OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!" );
204 if ( nAspect == embed::Aspects::MSOLE_ICON )
205 // no representation can be retrieved
206 throw embed::WrongStateException( "Illegal call!",
207 static_cast< ::cppu::OWeakObject* >(this) );
208
209 m_nCachedAspect = nAspect;
210 m_aCachedSize = aSize;
211 m_bHasCachedSize = true;
212}
213
214
215awt::Size SAL_CALL ODummyEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect )
216{
217 ::osl::MutexGuard aGuard( m_aMutex );
219
220 OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!" );
221 if ( nAspect == embed::Aspects::MSOLE_ICON )
222 // no representation can be retrieved
223 throw embed::WrongStateException( "Illegal call!",
224 static_cast< ::cppu::OWeakObject* >(this) );
225
226 if ( !m_bHasCachedSize || m_nCachedAspect != nAspect )
227 throw embed::NoVisualAreaSizeException(
228 "No size available!",
229 static_cast< ::cppu::OWeakObject* >(this) );
230
231 return m_aCachedSize;
232}
233
234
235sal_Int32 SAL_CALL ODummyEmbeddedObject::getMapUnit( sal_Int64 nAspect )
236{
237 ::osl::MutexGuard aGuard( m_aMutex );
239
240 OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!" );
241 if ( nAspect == embed::Aspects::MSOLE_ICON )
242 // no representation can be retrieved
243 throw embed::WrongStateException( "Illegal call!",
244 static_cast< ::cppu::OWeakObject* >(this) );
245
246 return embed::EmbedMapUnits::ONE_100TH_MM;
247}
248
249
250embed::VisualRepresentation SAL_CALL ODummyEmbeddedObject::getPreferredVisualRepresentation( sal_Int64 )
251{
252 ::osl::MutexGuard aGuard( m_aMutex );
254
255 // no representation can be retrieved
256 throw embed::WrongStateException( "Illegal call!",
257 static_cast< ::cppu::OWeakObject* >(this) );
258}
259
260
262 const uno::Reference< embed::XStorage >& xStorage,
263 const OUString& sEntName,
264 sal_Int32 nEntryConnectionMode,
265 const uno::Sequence< beans::PropertyValue >& /* lArguments */,
266 const uno::Sequence< beans::PropertyValue >& /* lObjArgs */ )
267{
268 ::osl::MutexGuard aGuard( m_aMutex );
269 if ( m_bDisposed )
270 throw lang::DisposedException(); // TODO
271
272 if ( !xStorage.is() )
273 throw lang::IllegalArgumentException( "No parent storage is provided!",
274 static_cast< ::cppu::OWeakObject* >(this),
275 1 );
276
277 if ( sEntName.isEmpty() )
278 throw lang::IllegalArgumentException( "Empty element name is provided!",
279 static_cast< ::cppu::OWeakObject* >(this),
280 2 );
281
282 if ( ( m_nObjectState != -1 || nEntryConnectionMode == embed::EntryInitModes::NO_INIT )
283 && ( m_nObjectState == -1 || nEntryConnectionMode != embed::EntryInitModes::NO_INIT ) )
284 {
285 throw embed::WrongStateException(
286 "Can't change persistent representation of activated object!",
287 static_cast< ::cppu::OWeakObject* >(this) );
288 }
289
291 {
292 if ( nEntryConnectionMode != embed::EntryInitModes::NO_INIT )
293 throw embed::WrongStateException(
294 "The object waits for saveCompleted() call!",
295 static_cast< ::cppu::OWeakObject* >(this) );
296
297 saveCompleted( m_xParentStorage != xStorage || m_aEntryName != sEntName );
298
299 }
300
301 if ( nEntryConnectionMode != embed::EntryInitModes::DEFAULT_INIT
302 && nEntryConnectionMode != embed::EntryInitModes::NO_INIT )
303 throw lang::IllegalArgumentException( "Wrong connection mode is provided!",
304 static_cast< ::cppu::OWeakObject* >(this),
305 3 );
306
307 if ( !xStorage->hasByName( sEntName ) )
308 throw lang::IllegalArgumentException( "Wrong entry is provided!",
309 static_cast< ::cppu::OWeakObject* >(this),
310 2 );
311
312 m_xParentStorage = xStorage;
313 m_aEntryName = sEntName;
314 m_nObjectState = embed::EmbedStates::LOADED;
315}
316
317
318void SAL_CALL ODummyEmbeddedObject::storeToEntry( const uno::Reference< embed::XStorage >& xStorage,
319 const OUString& sEntName,
320 const uno::Sequence< beans::PropertyValue >& /* lArguments */,
321 const uno::Sequence< beans::PropertyValue >& /* lObjArgs */ )
322{
323 ::osl::MutexGuard aGuard( m_aMutex );
325
327 throw embed::WrongStateException(
328 "The object waits for saveCompleted() call!",
329 static_cast< ::cppu::OWeakObject* >(this) );
330
331 m_xParentStorage->copyElementTo( m_aEntryName, xStorage, sEntName );
332}
333
334
335void SAL_CALL ODummyEmbeddedObject::storeAsEntry( const uno::Reference< embed::XStorage >& xStorage,
336 const OUString& sEntName,
337 const uno::Sequence< beans::PropertyValue >& /* lArguments */,
338 const uno::Sequence< beans::PropertyValue >& /* lObjArgs */ )
339{
340 ::osl::MutexGuard aGuard( m_aMutex );
342
344 throw embed::WrongStateException(
345 "The object waits for saveCompleted() call!",
346 static_cast< ::cppu::OWeakObject* >(this) );
347
348 PostEvent_Impl( "OnSaveAs" );
349
350 m_xParentStorage->copyElementTo( m_aEntryName, xStorage, sEntName );
351
353 m_xNewParentStorage = xStorage;
354 m_aNewEntryName = sEntName;
355}
356
357
359{
360 ::osl::MutexGuard aGuard( m_aMutex );
362
363 // it is allowed to call saveCompleted( false ) for nonstored objects
364 if ( !m_bWaitSaveCompleted && !bUseNew )
365 return;
366
367 OSL_ENSURE( m_bWaitSaveCompleted, "Unexpected saveCompleted() call!" );
369 throw io::IOException(); // TODO: illegal call
370
371 OSL_ENSURE( m_xNewParentStorage.is() , "Internal object information is broken!" );
372 if ( !m_xNewParentStorage.is() )
373 throw uno::RuntimeException(); // TODO: broken internal information
374
375 if ( bUseNew )
376 {
379
380 PostEvent_Impl( "OnSaveAsDone" );
381 }
382
383 m_xNewParentStorage.clear();
384 m_aNewEntryName.clear();
385 m_bWaitSaveCompleted = false;
386}
387
388
390{
391 ::osl::MutexGuard aGuard( m_aMutex );
393
395 throw embed::WrongStateException(
396 "The object waits for saveCompleted() call!",
397 static_cast< ::cppu::OWeakObject* >(this) );
398
399 if ( !m_aEntryName.isEmpty() )
400 return true;
401
402 return false;
403}
404
405
407{
408 ::osl::MutexGuard aGuard( m_aMutex );
410
412 throw embed::WrongStateException(
413 "The object waits for saveCompleted() call!",
414 static_cast< ::cppu::OWeakObject* >(this) );
415
416 return m_aEntryName;
417}
418
419
421{
422 ::osl::MutexGuard aGuard( m_aMutex );
424
426 throw embed::WrongStateException(
427 "The object waits for saveCompleted() call!",
428 static_cast< ::cppu::OWeakObject* >(this) );
429
430 // the object can not be activated or changed
431}
432
433
435{
436 ::osl::MutexGuard aGuard( m_aMutex );
438
440 throw embed::WrongStateException(
441 "The object waits for saveCompleted() call!",
442 static_cast< ::cppu::OWeakObject* >(this) );
443
444 // this object can not be changed
445 return true;
446}
447
448
450 const uno::Sequence< beans::PropertyValue >& /* lArguments */,
451 const uno::Sequence< beans::PropertyValue >& /* lObjArgs */ )
452{
453 ::osl::MutexGuard aGuard( m_aMutex );
455
457 throw embed::WrongStateException(
458 "The object waits for saveCompleted() call!",
459 static_cast< ::cppu::OWeakObject* >(this) );
460
461 // nothing to reload
462}
463
464
465uno::Sequence< sal_Int8 > SAL_CALL ODummyEmbeddedObject::getClassID()
466{
467 ::osl::MutexGuard aGuard( m_aMutex );
469
470 // currently the class ID is empty
471 // TODO/LATER: should a special class ID be used in this case?
472 return uno::Sequence< sal_Int8 >();
473}
474
475
477{
478 ::osl::MutexGuard aGuard( m_aMutex );
479 if ( m_bDisposed )
480 throw lang::DisposedException(); // TODO
481
482 return OUString();
483}
484
485
487 const uno::Sequence< sal_Int8 >& /*aClassID*/, const OUString& /*aClassName*/ )
488{
489 throw lang::NoSupportException();
490}
491
492
493uno::Reference< util::XCloseable > SAL_CALL ODummyEmbeddedObject::getComponent()
494{
495 ::osl::MutexGuard aGuard( m_aMutex );
497
498 return uno::Reference< util::XCloseable >();
499}
500
501
502void SAL_CALL ODummyEmbeddedObject::addStateChangeListener( const uno::Reference< embed::XStateChangeListener >& xListener )
503{
504 ::osl::MutexGuard aGuard( m_aMutex );
505 if ( m_bDisposed )
506 return;
507
510
512 xListener );
513}
514
515
517 const uno::Reference< embed::XStateChangeListener >& xListener )
518{
519 ::osl::MutexGuard aGuard( m_aMutex );
522 xListener );
523}
524
525
526void SAL_CALL ODummyEmbeddedObject::close( sal_Bool bDeliverOwnership )
527{
528 ::osl::MutexGuard aGuard( m_aMutex );
529 if ( m_bDisposed )
530 throw lang::DisposedException(); // TODO
531
532 uno::Reference< uno::XInterface > xSelfHold( static_cast< ::cppu::OWeakObject* >( this ) );
533 lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >( this ) );
534
536 {
539 if ( pContainer != nullptr )
540 {
541 comphelper::OInterfaceIteratorHelper2 pIterator(*pContainer);
542 while (pIterator.hasMoreElements())
543 {
544 try
545 {
546 static_cast<util::XCloseListener*>(pIterator.next())->queryClosing( aSource, bDeliverOwnership );
547 }
548 catch( const uno::RuntimeException& )
549 {
550 pIterator.remove();
551 }
552 }
553 }
554
555 pContainer = m_pInterfaceContainer->getContainer(
557 if ( pContainer != nullptr )
558 {
559 comphelper::OInterfaceIteratorHelper2 pCloseIterator(*pContainer);
560 while (pCloseIterator.hasMoreElements())
561 {
562 try
563 {
564 static_cast<util::XCloseListener*>(pCloseIterator.next())->notifyClosing( aSource );
565 }
566 catch( const uno::RuntimeException& )
567 {
568 pCloseIterator.remove();
569 }
570 }
571 }
572
573 m_pInterfaceContainer->disposeAndClear( aSource );
574 }
575
576 m_bDisposed = true; // the object is disposed now for outside
577}
578
579
580void SAL_CALL ODummyEmbeddedObject::addCloseListener( const uno::Reference< util::XCloseListener >& xListener )
581{
582 ::osl::MutexGuard aGuard( m_aMutex );
583 if ( m_bDisposed )
584 return;
585
588
590}
591
592
593void SAL_CALL ODummyEmbeddedObject::removeCloseListener( const uno::Reference< util::XCloseListener >& xListener )
594{
595 ::osl::MutexGuard aGuard( m_aMutex );
598 xListener );
599}
600
601
602void SAL_CALL ODummyEmbeddedObject::addEventListener( const uno::Reference< document::XEventListener >& xListener )
603{
604 ::osl::MutexGuard aGuard( m_aMutex );
605 if ( m_bDisposed )
606 return;
607
610
612}
613
614
615void SAL_CALL ODummyEmbeddedObject::removeEventListener( const uno::Reference< document::XEventListener >& xListener )
616{
617 ::osl::MutexGuard aGuard( m_aMutex );
620 xListener );
621}
622
624{
625 return "com.sun.star.comp.embed.ODummyEmbeddedObject";
626}
627
628sal_Bool SAL_CALL ODummyEmbeddedObject::supportsService(const OUString& ServiceName)
629{
631}
632
633uno::Sequence<OUString> SAL_CALL ODummyEmbeddedObject::getSupportedServiceNames()
634{
635 return { "com.sun.star.comp.embed.ODummyEmbeddedObject" };
636}
637
638/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
std::unique_ptr< comphelper::OMultiTypeInterfaceContainerHelper2 > m_pInterfaceContainer
Definition: dummyobject.hxx:58
virtual css::uno::Reference< css::util::XCloseable > SAL_CALL getComponent() override
void PostEvent_Impl(const OUString &aEventName)
Definition: dummyobject.cxx:61
css::uno::Reference< css::embed::XEmbeddedClient > m_xClientSite
Definition: dummyobject.hxx:65
virtual void SAL_CALL addStateChangeListener(const css::uno::Reference< css::embed::XStateChangeListener > &xListener) override
virtual void SAL_CALL close(sal_Bool DeliverOwnership) override
virtual void SAL_CALL changeState(sal_Int32 nNewState) override
virtual css::uno::Sequence< sal_Int32 > SAL_CALL getReachableStates() override
css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL storeAsEntry(const css::uno::Reference< css::embed::XStorage > &xStorage, const OUString &sEntName, const css::uno::Sequence< css::beans::PropertyValue > &lArguments, const css::uno::Sequence< css::beans::PropertyValue > &lObjArgs) override
virtual void SAL_CALL setClassInfo(const css::uno::Sequence< sal_Int8 > &aClassID, const OUString &aClassName) override
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getClassID() override
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::document::XEventListener > &Listener) override
virtual sal_Int64 SAL_CALL getStatus(sal_Int64 nAspect) override
sal_Int32 m_nObjectState
Definition: dummyobject.hxx:63
css::uno::Reference< css::embed::XStorage > m_xParentStorage
Definition: dummyobject.hxx:62
virtual void SAL_CALL addCloseListener(const css::uno::Reference< css::util::XCloseListener > &Listener) override
virtual void SAL_CALL doVerb(sal_Int32 nVerbID) override
sal_Int64 m_nCachedAspect
Definition: dummyobject.hxx:67
virtual void SAL_CALL storeToEntry(const css::uno::Reference< css::embed::XStorage > &xStorage, const OUString &sEntName, const css::uno::Sequence< css::beans::PropertyValue > &lArguments, const css::uno::Sequence< css::beans::PropertyValue > &lObjArgs) override
::osl::Mutex m_aMutex
Definition: dummyobject.hxx:56
virtual void SAL_CALL setVisualAreaSize(sal_Int64 nAspect, const css::awt::Size &aSize) override
virtual void SAL_CALL saveCompleted(sal_Bool bUseNew) override
virtual void SAL_CALL setContainerName(const OUString &sName) override
virtual sal_Int32 SAL_CALL getMapUnit(sal_Int64 nAspect) override
virtual void SAL_CALL storeOwn() override
css::uno::Reference< css::embed::XStorage > m_xNewParentStorage
Definition: dummyobject.hxx:74
virtual css::uno::Reference< css::embed::XEmbeddedClient > SAL_CALL getClientSite() override
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::document::XEventListener > &Listener) override
virtual void SAL_CALL setClientSite(const css::uno::Reference< css::embed::XEmbeddedClient > &xClient) override
virtual void SAL_CALL removeStateChangeListener(const css::uno::Reference< css::embed::XStateChangeListener > &xListener) override
virtual sal_Bool SAL_CALL isReadonly() override
virtual css::embed::VisualRepresentation SAL_CALL getPreferredVisualRepresentation(::sal_Int64 nAspect) override
virtual void SAL_CALL update() override
virtual void SAL_CALL setUpdateMode(sal_Int32 nMode) override
virtual OUString SAL_CALL getEntryName() override
virtual css::awt::Size SAL_CALL getVisualAreaSize(sal_Int64 nAspect) override
virtual sal_Int32 SAL_CALL getCurrentState() override
virtual void SAL_CALL removeCloseListener(const css::uno::Reference< css::util::XCloseListener > &Listener) override
OUString SAL_CALL getImplementationName() override
virtual css::uno::Sequence< css::embed::VerbDescriptor > SAL_CALL getSupportedVerbs() override
virtual OUString SAL_CALL getClassName() override
virtual void SAL_CALL setPersistentEntry(const css::uno::Reference< css::embed::XStorage > &xStorage, const OUString &sEntName, sal_Int32 nEntryConnectionMode, const css::uno::Sequence< css::beans::PropertyValue > &lArguments, const css::uno::Sequence< css::beans::PropertyValue > &lObjArgs) override
virtual sal_Bool SAL_CALL hasEntry() override
css::awt::Size m_aCachedSize
Definition: dummyobject.hxx:68
virtual void SAL_CALL reload(const css::uno::Sequence< css::beans::PropertyValue > &lArguments, const css::uno::Sequence< css::beans::PropertyValue > &lObjArgs) override
sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual ~ODummyEmbeddedObject() override
Definition: dummyobject.cxx:96
css::uno::XInterface * next()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
unsigned char sal_Bool