1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
|
/*************************************************************************
*
* $RCSfile: olepersist.cxx,v $
*
* $Revision: 1.8 $
*
* last change: $Author: mav $ $Date: 2003-11-26 16:44:04 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#include <oleembobj.hxx>
#ifndef _COM_SUN_STAR_EMBED_EMBEDSTATES_HPP_
#include <com/sun/star/embed/EmbedStates.hpp>
#endif
#ifndef _COM_SUN_STAR_EMBED_EMBEDVERBS_HPP_
#include <com/sun/star/embed/EmbedVerbs.hpp>
#endif
#ifndef _COM_SUN_STAR_EMBED_ENTRYINITMODES_HPP_
#include <com/sun/star/embed/EntryInitModes.hpp>
#endif
#ifndef _COM_SUN_STAR_EMBED_XSTORAGE_HPP_
#include <com/sun/star/embed/XStorage.hpp>
#endif
#ifndef _COM_SUN_STAR_EMBED_ELEMENTMODES_HPP_
#include <com/sun/star/embed/ElementModes.hpp>
#endif
#ifndef _COM_SUN_STAR_EMBED_EMBEDUPDATEMODES_HPP_
#include <com/sun/star/embed/EmbedUpdateModes.hpp>
#endif
#ifndef _COM_SUN_STAR_EMBED_ASPECTS_HPP_
#include <com/sun/star/embed/Aspects.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_
#include <com/sun/star/lang/XComponent.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_
#include <com/sun/star/lang/DisposedException.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
#include <com/sun/star/container/XNameAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_IO_XTRUNCATE_HPP_
#include <com/sun/star/io/XTruncate.hpp>
#endif
#include <olecomponent.hxx>
#include <closepreventer.hxx>
using namespace ::com::sun::star;
//------------------------------------------------------
void OleEmbeddedObject::SwitchOwnPersistence( const uno::Reference< embed::XStorage >& xNewParentStorage,
const uno::Reference< io::XStream >& xNewObjectStream,
const ::rtl::OUString& aNewName )
{
try {
uno::Reference< lang::XComponent > xComponent( m_xObjectStream, uno::UNO_QUERY );
OSL_ENSURE( !m_xObjectStream.is() || xComponent.is(), "Wrong stream implementation!" );
if ( xComponent.is() )
xComponent->dispose();
}
catch ( uno::Exception& )
{
}
m_xObjectStream = xNewObjectStream;
m_xParentStorage = xNewParentStorage;
m_aEntryName = aNewName;
}
//------------------------------------------------------
void OleEmbeddedObject::SwitchOwnPersistence( const uno::Reference< embed::XStorage >& xNewParentStorage,
const ::rtl::OUString& aNewName )
{
sal_Int32 nStreamMode = m_bReadOnly ? embed::ElementModes::ELEMENT_READ : embed::ElementModes::ELEMENT_READWRITE;
uno::Reference< io::XStream > xNewOwnStream = xNewParentStorage->openStreamElement( aNewName, nStreamMode );
OSL_ENSURE( xNewOwnStream.is(), "The method can not return empty reference!" );
SwitchOwnPersistence( xNewParentStorage, xNewOwnStream, aNewName );
}
//----------------------------------------------
sal_Bool OleEmbeddedObject::SaveObject_Impl()
{
sal_Bool bResult = sal_False;
if ( m_xClientSite.is() )
{
try
{
m_xClientSite->saveObject();
bResult = sal_True;
}
catch( uno::Exception& )
{
}
}
return bResult;
}
//----------------------------------------------
sal_Bool OleEmbeddedObject::OnShowWindow_Impl( sal_Bool bShow )
{
sal_Bool bResult = sal_False;
OSL_ENSURE( m_nObjectState != -1, "The object has no persistence!\n" );
OSL_ENSURE( m_nObjectState != embed::EmbedStates::EMBED_LOADED, "The object get OnShowWindow in loaded state!\n" );
if ( m_nObjectState == -1 || m_nObjectState == embed::EmbedStates::EMBED_LOADED )
return sal_False;
// the object is either activated or deactivated
if ( bShow && m_nObjectState == embed::EmbedStates::EMBED_RUNNING )
m_nObjectState = embed::EmbedStates::EMBED_ACTIVE;
else if ( !bShow && m_nObjectState == embed::EmbedStates::EMBED_ACTIVE )
m_nObjectState = embed::EmbedStates::EMBED_RUNNING;
if ( m_xClientSite.is() )
{
try
{
m_xClientSite->onShowWindow( bShow );
bResult = sal_True;
}
catch( uno::Exception& )
{
}
}
return bResult;
}
//------------------------------------------------------
void OleEmbeddedObject::CreateOleComponent_Impl( OleComponent* pOleComponent )
{
if ( !m_pOleComponent )
{
m_pOleComponent = pOleComponent ? pOleComponent : new OleComponent( m_xFactory, this );
m_pOleComponent->acquire(); // TODO: needs holder?
if ( !m_xClosePreventer.is() )
m_xClosePreventer = uno::Reference< util::XCloseListener >(
static_cast< ::cppu::OWeakObject* >( new OClosePreventer ),
uno::UNO_QUERY );
m_pOleComponent->addCloseListener( m_xClosePreventer );
}
else
OSL_ENSURE( sal_False, "Trying to recreate OLE component!\n" );
}
//------------------------------------------------------
uno::Reference< io::XOutputStream > OleEmbeddedObject::GetStreamForSaving()
{
if ( !m_xObjectStream.is() )
throw uno::RuntimeException(); //TODO:
uno::Reference< io::XOutputStream > xOutStream = m_xObjectStream->getOutputStream();
if ( !xOutStream.is() )
throw io::IOException(); //TODO: access denied
uno::Reference< io::XTruncate > xTruncate( xOutStream, uno::UNO_QUERY );
if ( !xTruncate.is() )
throw uno::RuntimeException(); //TODO:
xTruncate->truncate();
return xOutStream;
}
//------------------------------------------------------
void SAL_CALL OleEmbeddedObject::setPersistentEntry(
const uno::Reference< embed::XStorage >& xStorage,
const ::rtl::OUString& sEntName,
sal_Int32 nEntryConnectionMode,
const uno::Sequence< beans::PropertyValue >& lArguments )
throw ( lang::IllegalArgumentException,
embed::WrongStateException,
io::IOException,
uno::Exception,
uno::RuntimeException )
{
// the type of the object must be already set
// a kind of typedetection should be done in the factory;
// the only exception is object initialized from a stream,
// the class ID will be detected from the stream
::osl::MutexGuard aGuard( m_aMutex );
if ( m_bDisposed )
throw lang::DisposedException(); // TODO
if ( !xStorage.is() )
throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ),
1 );
if ( !sEntName.getLength() )
throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ),
2 );
// May be EMBED_LOADED should be forbidden here ???
if ( ( m_nObjectState != -1 || nEntryConnectionMode == embed::EntryInitModes::ENTRY_NO_INIT )
&& ( m_nObjectState == -1 || nEntryConnectionMode != embed::EntryInitModes::ENTRY_NO_INIT ) )
{
// if the object is not loaded
// it can not get persistant representation without initialization
// if the object is loaded
// it can switch persistant representation only without initialization
throw embed::WrongStateException(
::rtl::OUString::createFromAscii( "Can't change persistant representation of activated object!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
}
if ( m_bWaitSaveCompleted )
throw embed::WrongStateException(
::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY );
if ( !xNameAccess.is() )
throw uno::RuntimeException(); //TODO
// detect entry existence
sal_Bool bElExists = xNameAccess->hasByName( sEntName );
m_bReadOnly = sal_False;
for ( sal_Int32 nInd = 0; nInd < lArguments.getLength(); nInd++ )
if ( lArguments[nInd].Name.equalsAscii( "ReadOnly" ) )
lArguments[nInd].Value >>= m_bReadOnly;
sal_Int32 nStorageMode = m_bReadOnly ? embed::ElementModes::ELEMENT_READ : embed::ElementModes::ELEMENT_READWRITE;
SwitchOwnPersistence( xStorage, sEntName );
if ( nEntryConnectionMode == embed::EntryInitModes::ENTRY_DEFAULT_INIT )
{
CreateOleComponent_Impl();
if ( bElExists )
{
// load object from the stream
uno::Reference< io::XInputStream > xInStream = m_xObjectStream->getInputStream();
if ( !xInStream.is() )
throw io::IOException(); // TODO: access denied
// after the loading the object can appear as a link
// will be detected later by olecomponent
m_pOleComponent->LoadEmbeddedObject( xInStream, embed::Aspects::MSASPECT_CONTENT );
m_aClassID = m_pOleComponent->GetCLSID(); // was not set during consruction
m_nObjectState = embed::EmbedStates::EMBED_LOADED;
}
else
{
// create a new object
m_pOleComponent->CreateNewEmbeddedObject( m_aClassID, embed::Aspects::MSASPECT_CONTENT, NULL );
m_pOleComponent->RunObject();
m_nObjectState = embed::EmbedStates::EMBED_RUNNING;
}
}
else
{
if ( ( nStorageMode & embed::ElementModes::ELEMENT_READWRITE ) != embed::ElementModes::ELEMENT_READWRITE )
throw io::IOException();
if ( nEntryConnectionMode == embed::EntryInitModes::ENTRY_NO_INIT )
{
// the document just already changed its stream to store to
// the links to OLE documents switch their persistence in the same way
// as normal embedded objects
}
else if ( nEntryConnectionMode == embed::EntryInitModes::ENTRY_TRUNCATE_INIT )
{
// create a new object, that will be stored in specified stream
CreateOleComponent_Impl();
m_pOleComponent->CreateNewEmbeddedObject( m_aClassID, embed::Aspects::MSASPECT_CONTENT, NULL );
m_pOleComponent->RunObject();
m_nObjectState = embed::EmbedStates::EMBED_RUNNING;
}
else if ( nEntryConnectionMode == embed::EntryInitModes::ENTRY_MEDIA_DESCRIPTOR_INIT )
{
// use URL ( may be content or stream later ) from MediaDescriptor to initialize object
::rtl::OUString aURL;
for ( sal_Int32 nInd = 0; nInd < lArguments.getLength(); nInd++ )
if ( lArguments[nInd].Name.equalsAscii( "URL" ) )
lArguments[nInd].Value >>= aURL;
if ( !aURL.getLength() )
throw lang::IllegalArgumentException(
::rtl::OUString::createFromAscii( "Empty URL is provided in the media descriptor!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ),
4 );
CreateOleComponent_Impl();
// TODO: the m_bIsLink value must be set already
if ( !m_bIsLink )
m_pOleComponent->CreateObjectFromFile( aURL, embed::Aspects::MSASPECT_CONTENT, NULL );
else
m_pOleComponent->CreateLinkFromFile( aURL, embed::Aspects::MSASPECT_CONTENT, NULL );
m_pOleComponent->RunObject();
m_aClassID = m_pOleComponent->GetCLSID(); // was not set during consruction
m_nObjectState = embed::EmbedStates::EMBED_RUNNING;
}
//else if ( nEntryConnectionMode == embed::EntryInitModes::ENTRY_TRANSFERABLE_INIT )
//{
//TODO:
//}
else
throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Wrong connection mode is provided!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ),
3 );
}
}
//------------------------------------------------------
void SAL_CALL OleEmbeddedObject::storeOwn()
throw ( embed::WrongStateException,
io::IOException,
uno::Exception,
uno::RuntimeException )
{
// during switching from Activated to Running and from Running to Loaded states the object will
// ask container to store the object, the container has to make decision
// to do so or not
::osl::MutexGuard aGuard( m_aMutex );
if ( m_bDisposed )
throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 )
{
// the object is still not loaded
throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Can't store object without persistence!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
}
if ( m_bWaitSaveCompleted )
throw embed::WrongStateException(
::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
if ( m_bReadOnly )
throw io::IOException(); // TODO: access denied
if ( m_nObjectState == embed::EmbedStates::EMBED_LOADED )
return; // nothing to do, the object is in loaded state
if ( !m_pOleComponent )
throw uno::RuntimeException();
OSL_ENSURE( m_xParentStorage.is() && m_xObjectStream.is(), "The object has no valid persistence!\n" );
if ( !m_xObjectStream.is() )
throw io::IOException(); //TODO: access denied
uno::Reference< io::XOutputStream > xOutStream = m_xObjectStream->getOutputStream();
if ( !xOutStream.is() )
throw io::IOException(); //TODO: access denied
if ( m_bIsLink )
{
// just let the link store itself
// in case visual repersentation must be stored also
// the procedure should be the same as for embedded objects
uno::Reference< io::XOutputStream > xOutStream = GetStreamForSaving();
// should the component detect that it is a link???
m_pOleComponent->StoreObjectToStream( xOutStream, m_bStoreVisRepl );
}
else
{
uno::Reference< io::XOutputStream > xOutStream = GetStreamForSaving();
m_pOleComponent->StoreObjectToStream( xOutStream, m_bStoreVisRepl );
}
// TODO:
// notify listeners
if ( m_nUpdateMode == embed::EmbedUpdateModes::EMBED_ALWAYS_UPDATE )
{
// TODO: update visual representation
}
}
//------------------------------------------------------
void SAL_CALL OleEmbeddedObject::storeToEntry( const uno::Reference< embed::XStorage >& xStorage,
const ::rtl::OUString& sEntName,
const uno::Sequence< beans::PropertyValue >& lArguments )
throw ( lang::IllegalArgumentException,
embed::WrongStateException,
io::IOException,
uno::Exception,
uno::RuntimeException )
{
::osl::MutexGuard aGuard( m_aMutex );
if ( m_bDisposed )
throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 )
{
// the object is still not loaded
throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Can't store object without persistence!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
}
if ( m_bWaitSaveCompleted )
throw embed::WrongStateException(
::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
OSL_ENSURE( m_bIsLink || m_xParentStorage.is() && m_xObjectStream.is(), "The object has no valid persistence!\n" );
// ???
uno::Reference< io::XStream > xTargetStream =
xStorage->openStreamElement( sEntName, embed::ElementModes::ELEMENT_READWRITE );
if ( !xTargetStream.is() )
throw io::IOException(); //TODO: access denied
uno::Reference< io::XOutputStream > xOutStream = xTargetStream->getOutputStream();
if ( !xOutStream.is() )
throw io::IOException(); //TODO: access denied
m_pOleComponent->StoreObjectToStream( xOutStream, m_bStoreVisRepl );
uno::Reference< lang::XComponent > xComp( xTargetStream, uno::UNO_QUERY );
if ( xComp.is() )
{
try {
xComp->dispose();
} catch( uno::Exception& )
{
}
}
// TODO: should the listener notification be done?
}
//------------------------------------------------------
void SAL_CALL OleEmbeddedObject::storeAsEntry( const uno::Reference< embed::XStorage >& xStorage,
const ::rtl::OUString& sEntName,
const uno::Sequence< beans::PropertyValue >& lArguments )
throw ( lang::IllegalArgumentException,
embed::WrongStateException,
io::IOException,
uno::Exception,
uno::RuntimeException )
{
::osl::MutexGuard aGuard( m_aMutex );
if ( m_bDisposed )
throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 )
{
// the object is still not loaded
throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Can't store object without persistence!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
}
if ( m_bWaitSaveCompleted )
throw embed::WrongStateException(
::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
OSL_ENSURE( m_xParentStorage.is() && m_xObjectStream.is(), "The object has no valid persistence!\n" );
uno::Reference< io::XStream > xTargetStream =
xStorage->openStreamElement( sEntName, embed::ElementModes::ELEMENT_READWRITE );
if ( !xTargetStream.is() )
throw io::IOException(); //TODO: access denied
uno::Reference< io::XOutputStream > xOutStream = xTargetStream->getOutputStream();
if ( !xOutStream.is() )
throw io::IOException(); //TODO: access denied
m_pOleComponent->StoreObjectToStream( xOutStream, m_bStoreVisRepl );
m_bWaitSaveCompleted = sal_True;
m_xNewObjectStream = xTargetStream;
m_xNewParentStorage = xStorage;
m_aEntryName = sEntName;
// TODO: register listeners for storages above, in case thay are disposed
// an exception will be thrown on saveCompleted( true )
// TODO: should the listener notification be done here or in saveCompleted?
}
//------------------------------------------------------
void SAL_CALL OleEmbeddedObject::saveCompleted( sal_Bool bUseNew )
throw ( embed::WrongStateException,
uno::Exception,
uno::RuntimeException )
{
::osl::MutexGuard aGuard( m_aMutex );
if ( m_bDisposed )
throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 )
{
// the object is still not loaded
throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Can't store object without persistence!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
}
OSL_ENSURE( m_bWaitSaveCompleted, "Unexpected saveCompleted() call!\n" );
if ( !m_bWaitSaveCompleted )
throw io::IOException(); // TODO: illegal call
OSL_ENSURE( m_xNewObjectStream.is() && m_xNewParentStorage.is() , "Internal object information is broken!\n" );
if ( !m_xNewObjectStream.is() || !m_xNewParentStorage.is() )
throw uno::RuntimeException(); // TODO: broken internal information
if ( bUseNew )
{
SwitchOwnPersistence( m_xNewParentStorage, m_xNewObjectStream, m_aNewEntryName );
}
else
{
// close remembered stream
try {
uno::Reference< lang::XComponent > xComponent( m_xNewObjectStream, uno::UNO_QUERY );
OSL_ENSURE( xComponent.is(), "Wrong storage implementation!" );
if ( xComponent.is() )
xComponent->dispose();
}
catch ( uno::Exception& )
{
}
}
m_xNewObjectStream = uno::Reference< io::XStream >();
m_xNewParentStorage = uno::Reference< embed::XStorage >();
m_aNewEntryName = ::rtl::OUString();
m_bWaitSaveCompleted = sal_False;
if ( bUseNew )
{
// TODO: notify listeners
if ( m_nUpdateMode == embed::EmbedUpdateModes::EMBED_ALWAYS_UPDATE )
{
// TODO: update visual representation
}
}
}
//------------------------------------------------------
sal_Bool SAL_CALL OleEmbeddedObject::hasEntry()
throw ( embed::WrongStateException,
uno::RuntimeException )
{
::osl::MutexGuard aGuard( m_aMutex );
if ( m_bDisposed )
throw lang::DisposedException(); // TODO
if ( m_bWaitSaveCompleted )
throw embed::WrongStateException(
::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
if ( m_xObjectStream.is() )
return sal_True;
return sal_False;
}
//------------------------------------------------------
::rtl::OUString SAL_CALL OleEmbeddedObject::getEntryName()
throw ( embed::WrongStateException,
uno::RuntimeException )
{
::osl::MutexGuard aGuard( m_aMutex );
if ( m_bDisposed )
throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 )
{
// the object is still not loaded
throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object persistence is not initialized!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
}
if ( m_bWaitSaveCompleted )
throw embed::WrongStateException(
::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
return m_aEntryName;
}
//------------------------------------------------------
sal_Bool SAL_CALL OleEmbeddedObject::isReadonly()
throw ( embed::WrongStateException,
uno::RuntimeException )
{
::osl::MutexGuard aGuard( m_aMutex );
if ( m_bDisposed )
throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 )
{
// the object is still not loaded
throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object persistence is not initialized!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
}
if ( m_bWaitSaveCompleted )
throw embed::WrongStateException(
::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
return m_bReadOnly;
}
//------------------------------------------------------
void SAL_CALL OleEmbeddedObject::reload(
const uno::Sequence< beans::PropertyValue >& lArguments )
throw ( lang::IllegalArgumentException,
embed::WrongStateException,
io::IOException,
uno::Exception,
uno::RuntimeException )
{
::osl::MutexGuard aGuard( m_aMutex );
if ( m_bDisposed )
throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 )
{
// the object is still not loaded
throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object persistence is not initialized!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
}
if ( m_bWaitSaveCompleted )
throw embed::WrongStateException(
::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
// TODO:
// throw away current document
// load new document from current storage
// use meaningfull part of lArguments
}
//------------------------------------------------------
void SAL_CALL OleEmbeddedObject::breakLink( const uno::Reference< embed::XStorage >& xStorage,
const ::rtl::OUString& sEntName )
throw ( lang::IllegalArgumentException,
embed::WrongStateException,
io::IOException,
uno::Exception,
uno::RuntimeException )
{
::osl::MutexGuard aGuard( m_aMutex );
if ( m_bDisposed )
throw lang::DisposedException(); // TODO
if ( !xStorage.is() )
throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ),
1 );
if ( !sEntName.getLength() )
throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ),
2 );
// TODO: The object must be at least in Running state;
if ( !m_bIsLink || m_nObjectState == -1 || !m_pOleComponent )
{
// it must be a linked initialized object
throw embed::WrongStateException(
::rtl::OUString::createFromAscii( "The object is not a valid linked object!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
}
if ( m_bReadOnly )
throw io::IOException(); // TODO: Access denied
if ( m_bWaitSaveCompleted )
throw embed::WrongStateException(
::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
// TODO: if the parent storage and entry are the same as object uses the breaking of link must be done
// just by through OLE functionality
// TODO: create an object based on the link
OleComponent* pNewOleComponent = new OleComponent( m_xFactory, this );
try {
pNewOleComponent->InitEmbeddedCopyOfLink( m_pOleComponent );
}
catch ( uno::Exception& )
{
delete pNewOleComponent;
throw;
}
GetRidOfComponent();
CreateOleComponent_Impl( pNewOleComponent );
if ( m_xParentStorage != xStorage || !m_aEntryName.equals( sEntName ) )
SwitchOwnPersistence( xStorage, sEntName );
if ( m_nObjectState != embed::EmbedStates::EMBED_LOADED )
{
// TODO: should we activate the new object if the link was activated?
sal_Int32 nTargetState = m_nObjectState;
m_nObjectState = embed::EmbedStates::EMBED_LOADED;
if ( m_nObjectState == embed::EmbedStates::EMBED_RUNNING )
m_pOleComponent->RunObject();
else // m_nObjectState == embed::EmbedStates::EMBED_ACTIVE
{
m_pOleComponent->RunObject();
m_pOleComponent->ExecuteVerb( embed::EmbedVerbs::MS_OLEVERB_OPEN );
}
m_nObjectState = nTargetState;
}
m_bIsLink = sal_False;
m_aLinkURL = ::rtl::OUString();
}
//------------------------------------------------------
sal_Bool SAL_CALL OleEmbeddedObject::isLink()
throw ( embed::WrongStateException,
uno::RuntimeException )
{
::osl::MutexGuard aGuard( m_aMutex );
if ( m_bDisposed )
throw lang::DisposedException(); // TODO
return m_bIsLink;
}
//------------------------------------------------------
::rtl::OUString SAL_CALL OleEmbeddedObject::getLinkURL()
throw ( embed::WrongStateException,
uno::Exception,
uno::RuntimeException )
{
::osl::MutexGuard aGuard( m_aMutex );
if ( m_bDisposed )
throw lang::DisposedException(); // TODO
if ( m_bWaitSaveCompleted )
throw embed::WrongStateException(
::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
if ( !m_bIsLink )
throw embed::WrongStateException(
::rtl::OUString::createFromAscii( "The object is not a link object!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
// TODO: probably the link URL can be retrieved from OLE
return m_aLinkURL;
}
|