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
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org 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 version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sfx2.hxx"
#include "arrdecl.hxx"
#include <cppuhelper/implbase1.hxx>
#include <com/sun/star/util/XCloseable.hpp>
#include <com/sun/star/frame/XComponentLoader.hpp>
#include <com/sun/star/util/XCloseBroadcaster.hpp>
#include <com/sun/star/util/XCloseListener.hpp>
#include <com/sun/star/util/XModifyBroadcaster.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/frame/XTitle.hpp>
#include <osl/mutex.hxx>
#include <tools/resary.hxx>
#include <vcl/msgbox.hxx>
#include <vcl/wrkwin.hxx>
#include <vcl/svapp.hxx>
#include <svl/eitem.hxx>
#include <tools/rtti.hxx>
#include <svl/lstner.hxx>
#include <sfx2/sfxhelp.hxx>
#include <basic/sbstar.hxx>
#include <svl/stritem.hxx>
#include <basic/sbx.hxx>
#include <unotools/eventcfg.hxx>
#include <sfx2/objsh.hxx>
#include <sfx2/signaturestate.hxx>
#include <sfx2/sfxmodelfactory.hxx>
#include <basic/sbuno.hxx>
#include <svtools/sfxecode.hxx>
#include <svtools/ehdl.hxx>
#include <unotools/printwarningoptions.hxx>
#include <comphelper/processfactory.hxx>
#include <com/sun/star/document/XStorageBasedDocument.hpp>
#include <com/sun/star/script/DocumentDialogLibraryContainer.hpp>
#include <com/sun/star/script/DocumentScriptLibraryContainer.hpp>
#include <com/sun/star/document/XEmbeddedScripts.hpp>
#include <com/sun/star/document/XScriptInvocationContext.hpp>
#include <svl/urihelper.hxx>
#include <unotools/pathoptions.hxx>
#include <svl/sharecontrolfile.hxx>
#include <unotools/localfilehelper.hxx>
#include <unotools/ucbhelper.hxx>
#include <svtools/asynclink.hxx>
#include <tools/diagnose_ex.h>
#include <sot/clsids.hxx>
#include <sfx2/app.hxx>
#include <sfx2/docfac.hxx>
#include <sfx2/docfile.hxx>
#include <sfx2/event.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/viewsh.hxx>
#include <sfx2/viewfrm.hxx>
#include "sfx2/sfxresid.hxx"
#include "objshimp.hxx"
#include "appbas.hxx"
#include "sfxtypes.hxx"
#include <sfx2/evntconf.hxx>
#include <sfx2/request.hxx>
#include "doc.hrc"
#include "sfxlocal.hrc"
#include "appdata.hxx"
#include <sfx2/appuno.hxx>
#include <sfx2/sfxsids.hrc>
#include "sfx2/basmgr.hxx"
#include "sfx2/QuerySaveDocument.hxx"
#include "helpid.hrc"
#include <sfx2/msg.hxx>
#include "appbaslib.hxx"
#include <sfx2/sfxbasemodel.hxx>
#include <basic/basicmanagerrepository.hxx>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::script;
using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::document;
using ::basic::BasicManagerRepository;
#include <uno/mapping.hxx>
//====================================================================
DBG_NAME(SfxObjectShell)
#define DocumentInfo
#include "sfxslots.hxx"
static WeakReference< XInterface > s_xCurrentComponent;
void lcl_UpdateAppBasicDocVars( const Reference< XInterface >& _rxComponent, bool bClear = false )
{
BasicManager* pAppMgr = SFX_APP()->GetBasicManager();
if ( pAppMgr )
{
uno::Reference< beans::XPropertySet > xProps( _rxComponent, uno::UNO_QUERY );
if ( xProps.is() )
{
try
{
// ThisVBADocObj contains a PropertyValue
// Name is ( the name of the VBA global to insert )
// Value is the Object to insert.
// ( note: at the moment the Value is actually the model so
// it strictly is not necessary, however we do intend to store
// not the model in basic but a custom object, so we keep this
// level of indirection for future proofing )
beans::PropertyValue aProp;
xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ThisVBADocObj") ) ) >>= aProp;
rtl::OString sTmp( rtl::OUStringToOString( aProp.Name, RTL_TEXTENCODING_UTF8 ) );
const char* pAscii = sTmp.getStr();
if ( bClear )
pAppMgr->SetGlobalUNOConstant( pAscii, uno::makeAny( uno::Reference< uno::XInterface >() ) );
else
pAppMgr->SetGlobalUNOConstant( pAscii, aProp.Value );
}
catch( const uno::Exception& )
{
}
}
}
}
//=========================================================================
class SfxModelListener_Impl : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XCloseListener >
{
SfxObjectShell* mpDoc;
public:
SfxModelListener_Impl( SfxObjectShell* pDoc ) : mpDoc(pDoc) {};
virtual void SAL_CALL queryClosing( const com::sun::star::lang::EventObject& aEvent, sal_Bool bDeliverOwnership )
throw ( com::sun::star::uno::RuntimeException, com::sun::star::util::CloseVetoException) ;
virtual void SAL_CALL notifyClosing( const com::sun::star::lang::EventObject& aEvent ) throw ( com::sun::star::uno::RuntimeException ) ;
virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& aEvent ) throw ( com::sun::star::uno::RuntimeException ) ;
};
void SAL_CALL SfxModelListener_Impl::queryClosing( const com::sun::star::lang::EventObject& , sal_Bool )
throw ( com::sun::star::uno::RuntimeException, com::sun::star::util::CloseVetoException)
{
}
void SAL_CALL SfxModelListener_Impl::notifyClosing( const com::sun::star::lang::EventObject& ) throw ( com::sun::star::uno::RuntimeException )
{
SolarMutexGuard aSolarGuard;
mpDoc->Broadcast( SfxSimpleHint(SFX_HINT_DEINITIALIZING) );
}
void SAL_CALL SfxModelListener_Impl::disposing( const com::sun::star::lang::EventObject& _rEvent ) throw ( com::sun::star::uno::RuntimeException )
{
// am I ThisComponent in AppBasic?
SolarMutexGuard aSolarGuard;
if ( SfxObjectShell::GetCurrentComponent() == _rEvent.Source )
{
lcl_UpdateAppBasicDocVars( SfxObjectShell::GetCurrentComponent(), true );
// remove ThisComponent reference from AppBasic
SfxObjectShell::SetCurrentComponent( Reference< XInterface >() );
}
if ( mpDoc->Get_Impl()->bHiddenLockedByAPI )
{
mpDoc->Get_Impl()->bHiddenLockedByAPI = sal_False;
mpDoc->OwnerLock(sal_False);
}
else if ( !mpDoc->Get_Impl()->bClosing )
// GCC stuerzt ab, wenn schon im dtor, also vorher Flag abfragen
mpDoc->DoClose();
}
TYPEINIT1(SfxObjectShell, SfxShell);
//--------------------------------------------------------------------
SfxObjectShell_Impl::SfxObjectShell_Impl( SfxObjectShell& _rDocShell )
:mpObjectContainer(0)
,pBasicManager( new SfxBasicManagerHolder )
,rDocShell( _rDocShell )
,aMacroMode( *this )
,pProgress( 0)
,nTime()
,nVisualDocumentNumber( USHRT_MAX)
,nDocumentSignatureState( SIGNATURESTATE_UNKNOWN )
,nScriptingSignatureState( SIGNATURESTATE_UNKNOWN )
,bInList( sal_False)
,bClosing( sal_False)
,bIsSaving( sal_False)
,bPasswd( sal_False)
,bIsTmp( sal_False)
,bIsNamedVisible( sal_False)
,bIsTemplate(sal_False)
,bIsAbortingImport ( sal_False)
,bImportDone ( sal_False)
,bInPrepareClose( sal_False )
,bPreparedForClose( sal_False )
,bWaitingForPicklist( sal_True )
,bForbidReload( sal_False )
,bBasicInitialized( sal_False )
,bIsPrintJobCancelable( sal_True )
,bOwnsStorage( sal_True )
,bNoBaseURL( sal_False )
,bInitialized( sal_False )
,bSignatureErrorIsShown( sal_False )
,bModelInitialized( sal_False )
,bPreserveVersions( sal_True )
,m_bMacroSignBroken( sal_False )
,m_bNoBasicCapabilities( sal_False )
,m_bDocRecoverySupport( sal_True )
,bQueryLoadTemplate( sal_True )
,bLoadReadonly( sal_False )
,bUseUserData( sal_True )
,bSaveVersionOnClose( sal_False )
,m_bSharedXMLFlag( sal_False )
,m_bAllowShareControlFileClean( sal_True )
,m_bConfigOptionsChecked( sal_False )
,lErr(ERRCODE_NONE)
,nEventId ( 0)
,pReloadTimer ( 0)
,pMarkData( 0 )
,nLoadedFlags ( SFX_LOADED_ALL )
,nFlagsInProgress( 0 )
,bModalMode( sal_False )
,bRunningMacro( sal_False )
,bReloadAvailable( sal_False )
,nAutoLoadLocks( 0 )
,pModule( 0 )
,eFlags( SFXOBJECTSHELL_UNDEFINED )
,bReadOnlyUI( sal_False )
,bHiddenLockedByAPI( sal_False )
,nStyleFilter( 0 )
,bDisposing( sal_False )
,m_bEnableSetModified( sal_True )
,m_bIsModified( sal_False )
,m_nMapUnit( MAP_100TH_MM )
,m_bCreateTempStor( sal_False )
,m_bIsInit( sal_False )
,m_bIncomplEncrWarnShown( sal_False )
,m_nModifyPasswordHash( 0 )
,m_bModifyPasswordEntered( sal_False )
{
SfxObjectShell* pDoc = &_rDocShell;
SfxObjectShellArr_Impl &rArr = SFX_APP()->GetObjectShells_Impl();
rArr.C40_INSERT( SfxObjectShell, pDoc, rArr.Count() );
bInList = sal_True;
}
//--------------------------------------------------------------------
SfxObjectShell_Impl::~SfxObjectShell_Impl()
{
delete pBasicManager;
}
//--------------------------------------------------------------------
SfxObjectShell::SfxObjectShell( const sal_uInt64 i_nCreationFlags )
: pImp( new SfxObjectShell_Impl( *this ) )
, pMedium(0)
, pStyleSheetPool(0)
, eCreateMode( ( i_nCreationFlags & SFXMODEL_EMBEDDED_OBJECT ) ? SFX_CREATE_MODE_EMBEDDED : SFX_CREATE_MODE_STANDARD )
, bHasName( sal_False )
{
DBG_CTOR(SfxObjectShell, 0);
const bool bScriptSupport = ( i_nCreationFlags & SFXMODEL_DISABLE_EMBEDDED_SCRIPTS ) == 0;
if ( !bScriptSupport )
SetHasNoBasic();
const bool bDocRecovery = ( i_nCreationFlags & SFXMODEL_DISABLE_DOCUMENT_RECOVERY ) == 0;
if ( !bDocRecovery )
pImp->m_bDocRecoverySupport = sal_False;
}
//--------------------------------------------------------------------
// initializes a document from a file-description
SfxObjectShell::SfxObjectShell
(
SfxObjectCreateMode eMode /* Purpose, io which the SfxObjectShell
is created:
SFX_CREATE_MODE_EMBEDDED (default)
as SO-Server from within another
Document
SFX_CREATE_MODE_STANDARD,
as a normal Document open stand-alone
SFX_CREATE_MODE_PREVIEW
to enable a Preview, if possible are
only little information is needed
SFX_CREATE_MODE_ORGANIZER
to be displayed in the Organizer, here
notning of the contents is used */
)
/* [Description]
Constructor of the class SfxObjectShell.
*/
: pImp( new SfxObjectShell_Impl( *this ) ),
pMedium(0),
pStyleSheetPool(0),
eCreateMode(eMode),
bHasName( sal_False )
{
DBG_CTOR(SfxObjectShell, 0);
}
//--------------------------------------------------------------------
// virtual destructor of typical base-class SfxObjectShell
SfxObjectShell::~SfxObjectShell()
{
DBG_DTOR(SfxObjectShell, 0);
if ( IsEnableSetModified() )
EnableSetModified( sal_False );
// Never call GetInPlaceObject(), the access to the derivative branch
// SfxInternObject is not allowed because of a compiler bug
SfxObjectShell::Close();
pImp->pBaseModel.set( NULL );
DELETEX(pImp->pReloadTimer );
SfxApplication *pSfxApp = SFX_APP();
if ( USHRT_MAX != pImp->nVisualDocumentNumber )
pSfxApp->ReleaseIndex(pImp->nVisualDocumentNumber);
// Destroy Basic-Manager
pImp->pBasicManager->reset( NULL );
if ( pSfxApp->GetDdeService() )
pSfxApp->RemoveDdeTopic( this );
pImp->pBaseModel.set( NULL );
// don't call GetStorage() here, in case of Load Failure it's possible that a storage was never assigned!
if ( pMedium && pMedium->HasStorage_Impl() && pMedium->GetStorage( sal_False ) == pImp->m_xDocStorage )
pMedium->CanDisposeStorage_Impl( sal_False );
if ( pImp->mpObjectContainer )
{
pImp->mpObjectContainer->CloseEmbeddedObjects();
delete pImp->mpObjectContainer;
}
if ( pImp->bOwnsStorage && pImp->m_xDocStorage.is() )
pImp->m_xDocStorage->dispose();
if ( pMedium )
{
pMedium->CloseAndReleaseStreams_Impl();
if ( IsDocShared() )
FreeSharedFile();
DELETEX( pMedium );
}
// The removing of the temporary file must be done as the latest step in the document destruction
if ( pImp->aTempName.Len() )
{
String aTmp;
::utl::LocalFileHelper::ConvertPhysicalNameToURL( pImp->aTempName, aTmp );
::utl::UCBContentHelper::Kill( aTmp );
}
delete pImp;
}
//--------------------------------------------------------------------
void SfxObjectShell::Stamp_SetPrintCancelState(sal_Bool bState)
{
pImp->bIsPrintJobCancelable = bState;
}
//--------------------------------------------------------------------
sal_Bool SfxObjectShell::Stamp_GetPrintCancelState() const
{
return pImp->bIsPrintJobCancelable;
}
//--------------------------------------------------------------------
void SfxObjectShell::ViewAssigned()
/* [Description]
This method is called when a view is assigned.
*/
{
}
//--------------------------------------------------------------------
// closes the Object and all its views
sal_Bool SfxObjectShell::Close()
{
{DBG_CHKTHIS(SfxObjectShell, 0);}
SfxObjectShellRef aRef(this);
if ( !pImp->bClosing )
{
// Do not close if a progress is still running
if ( !pImp->bDisposing && GetProgress() )
return sal_False;
pImp->bClosing = sal_True;
Reference< util::XCloseable > xCloseable( GetBaseModel(), UNO_QUERY );
if ( xCloseable.is() )
{
try
{
xCloseable->close( sal_True );
}
catch( Exception& )
{
pImp->bClosing = sal_False;
}
}
if ( pImp->bClosing )
{
// remove from Document list
SfxApplication *pSfxApp = SFX_APP();
SfxObjectShellArr_Impl &rDocs = pSfxApp->GetObjectShells_Impl();
const SfxObjectShell *pThis = this;
sal_uInt16 nPos = rDocs.GetPos(pThis);
if ( nPos < rDocs.Count() )
rDocs.Remove( nPos );
pImp->bInList = sal_False;
}
}
return sal_True;
}
//--------------------------------------------------------------------
// returns a pointer the first SfxDocument of specified type
SfxObjectShell* SfxObjectShell::GetFirst
(
const TypeId* pType ,
sal_Bool bOnlyVisible
)
{
SfxObjectShellArr_Impl &rDocs = SFX_APP()->GetObjectShells_Impl();
// seach for a SfxDocument of the specified type
for ( sal_uInt16 nPos = 0; nPos < rDocs.Count(); ++nPos )
{
SfxObjectShell* pSh = rDocs.GetObject( nPos );
if ( bOnlyVisible && pSh->IsPreview() && pSh->IsReadOnly() )
continue;
if ( ( !pType || pSh->IsA(*pType) ) &&
( !bOnlyVisible || SfxViewFrame::GetFirst( pSh, sal_True )))
return pSh;
}
return 0;
}
//--------------------------------------------------------------------
// returns a pointer to the next SfxDocument of specified type behind *pDoc
SfxObjectShell* SfxObjectShell::GetNext
(
const SfxObjectShell& rPrev,
const TypeId* pType,
sal_Bool bOnlyVisible
)
{
SfxObjectShellArr_Impl &rDocs = SFX_APP()->GetObjectShells_Impl();
// refind the specified predecessor
sal_uInt16 nPos;
for ( nPos = 0; nPos < rDocs.Count(); ++nPos )
if ( rDocs.GetObject(nPos) == &rPrev )
break;
// search for the next SfxDocument of the specified type
for ( ++nPos; nPos < rDocs.Count(); ++nPos )
{
SfxObjectShell* pSh = rDocs.GetObject( nPos );
if ( bOnlyVisible && pSh->IsPreview() && pSh->IsReadOnly() )
continue;
if ( ( !pType || pSh->IsA(*pType) ) &&
( !bOnlyVisible || SfxViewFrame::GetFirst( pSh, sal_True )))
return pSh;
}
return 0;
}
//--------------------------------------------------------------------
SfxObjectShell* SfxObjectShell::Current()
{
SfxViewFrame *pFrame = SfxViewFrame::Current();
return pFrame ? pFrame->GetObjectShell() : 0;
}
//-------------------------------------------------------------------------
sal_Bool SfxObjectShell::IsInPrepareClose() const
{
return pImp->bInPrepareClose;
}
//------------------------------------------------------------------------
struct BoolEnv_Impl
{
SfxObjectShell_Impl* pImp;
BoolEnv_Impl( SfxObjectShell_Impl* pImpP) : pImp( pImpP )
{ pImpP->bInPrepareClose = sal_True; }
~BoolEnv_Impl() { pImp->bInPrepareClose = sal_False; }
};
sal_uInt16 SfxObjectShell::PrepareClose
(
sal_Bool bUI, // sal_True: Dialog and so on is allowed
// sal_False: silent-mode
sal_Bool bForBrowsing
)
{
if( pImp->bInPrepareClose || pImp->bPreparedForClose )
return sal_True;
BoolEnv_Impl aBoolEnv( pImp );
// DocModalDialog?
if ( IsInModalMode() )
return sal_False;
SfxViewFrame* pFirst = SfxViewFrame::GetFirst( this );
if( pFirst && !pFirst->GetFrame().PrepareClose_Impl( bUI, bForBrowsing ) )
return sal_False;
// prepare views for closing
for ( SfxViewFrame* pFrm = SfxViewFrame::GetFirst( this );
pFrm; pFrm = SfxViewFrame::GetNext( *pFrm, this ) )
{
DBG_ASSERT(pFrm->GetViewShell(),"No Shell");
if ( pFrm->GetViewShell() )
{
sal_uInt16 nRet = pFrm->GetViewShell()->PrepareClose( bUI, bForBrowsing );
if ( nRet != sal_True )
return nRet;
}
}
SfxApplication *pSfxApp = SFX_APP();
pSfxApp->NotifyEvent( SfxEventHint(SFX_EVENT_PREPARECLOSEDOC, GlobalEventConfig::GetEventName(STR_EVENT_PREPARECLOSEDOC), this) );
if( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
{
pImp->bPreparedForClose = sal_True;
return sal_True;
}
// Ask if possible if it should be saved
// only ask for the Document in the visable window
SfxViewFrame *pFrame = SfxObjectShell::Current() == this
? SfxViewFrame::Current() : SfxViewFrame::GetFirst( this );
if ( bUI && IsModified() && pFrame )
{
// restore minimized
SfxFrame& rTop = pFrame->GetTopFrame();
SfxViewFrame::SetViewFrame( rTop.GetCurrentViewFrame() );
pFrame->GetFrame().Appear();
// Ask if to save
short nRet = RET_YES;
{
//initiate help agent to inform about "print modifies the document"
SvtPrintWarningOptions aPrintOptions;
if (aPrintOptions.IsModifyDocumentOnPrintingAllowed() &&
HasName() && getDocProperties()->getPrintDate().Month > 0)
{
SfxHelp::OpenHelpAgent( &pFirst->GetFrame(), HID_CLOSE_WARNING );
}
const Reference< XTitle > xTitle( *pImp->pBaseModel.get(), UNO_QUERY_THROW );
const ::rtl::OUString sTitle = xTitle->getTitle ();
nRet = ExecuteQuerySaveDocument(&pFrame->GetWindow(),sTitle);
}
/*HACK for plugin::destroy()*/
if ( RET_YES == nRet )
{
// Save by each Dispatcher
const SfxPoolItem *pPoolItem;
if ( IsSaveVersionOnClose() )
{
SfxStringItem aItem( SID_DOCINFO_COMMENTS, String( SfxResId( STR_AUTOMATICVERSION ) ) );
SfxBoolItem aWarnItem( SID_FAIL_ON_WARNING, bUI );
const SfxPoolItem* ppArgs[] = { &aItem, &aWarnItem, 0 };
pPoolItem = pFrame->GetBindings().ExecuteSynchron( SID_SAVEDOC, ppArgs );
}
else
{
SfxBoolItem aWarnItem( SID_FAIL_ON_WARNING, bUI );
const SfxPoolItem* ppArgs[] = { &aWarnItem, 0 };
pPoolItem = pFrame->GetBindings().ExecuteSynchron( SID_SAVEDOC, ppArgs );
}
if ( !pPoolItem || pPoolItem->ISA(SfxVoidItem) || ( pPoolItem->ISA(SfxBoolItem) && !( (const SfxBoolItem*) pPoolItem )->GetValue() ) )
return sal_False;
}
else if ( RET_CANCEL == nRet )
// Cancelled
return sal_False;
else if ( RET_NEWTASK == nRet )
{
return RET_NEWTASK;
}
}
pImp->bPreparedForClose = sal_True;
return sal_True;
}
//--------------------------------------------------------------------
namespace
{
static BasicManager* lcl_getBasicManagerForDocument( const SfxObjectShell& _rDocument )
{
if ( !_rDocument.Get_Impl()->m_bNoBasicCapabilities )
{
if ( !_rDocument.Get_Impl()->bBasicInitialized )
const_cast< SfxObjectShell& >( _rDocument ).InitBasicManager_Impl();
return _rDocument.Get_Impl()->pBasicManager->get();
}
// assume we do not have Basic ourself, but we can refer to another
// document which does (by our model's XScriptInvocationContext::getScriptContainer).
// In this case, we return the BasicManager of this other document.
OSL_ENSURE( !Reference< XEmbeddedScripts >( _rDocument.GetModel(), UNO_QUERY ).is(),
"lcl_getBasicManagerForDocument: inconsistency: no Basic, but an XEmbeddedScripts?" );
Reference< XModel > xForeignDocument;
Reference< XScriptInvocationContext > xContext( _rDocument.GetModel(), UNO_QUERY );
if ( xContext.is() )
{
xForeignDocument.set( xContext->getScriptContainer(), UNO_QUERY );
OSL_ENSURE( xForeignDocument.is() && xForeignDocument != _rDocument.GetModel(),
"lcl_getBasicManagerForDocument: no Basic, but providing ourself as script container?" );
}
BasicManager* pBasMgr = NULL;
if ( xForeignDocument.is() )
pBasMgr = ::basic::BasicManagerRepository::getDocumentBasicManager( xForeignDocument );
return pBasMgr;
}
}
//--------------------------------------------------------------------
BasicManager* SfxObjectShell::GetBasicManager() const
{
BasicManager* pBasMgr = lcl_getBasicManagerForDocument( *this );
if ( !pBasMgr )
pBasMgr = SFX_APP()->GetBasicManager();
return pBasMgr;
}
//--------------------------------------------------------------------
void SfxObjectShell::SetHasNoBasic()
{
pImp->m_bNoBasicCapabilities = sal_True;
}
//--------------------------------------------------------------------
sal_Bool SfxObjectShell::HasBasic() const
{
if ( pImp->m_bNoBasicCapabilities )
return sal_False;
if ( !pImp->bBasicInitialized )
const_cast< SfxObjectShell* >( this )->InitBasicManager_Impl();
return pImp->pBasicManager->isValid();
}
//--------------------------------------------------------------------
namespace
{
const Reference< XLibraryContainer >&
lcl_getOrCreateLibraryContainer( bool _bScript, Reference< XLibraryContainer >& _rxContainer,
const Reference< XModel >& _rxDocument )
{
if ( !_rxContainer.is() )
{
try
{
Reference< XStorageBasedDocument > xStorageDoc( _rxDocument, UNO_QUERY );
const Reference< XComponentContext > xContext(
::comphelper::getProcessComponentContext() );
_rxContainer.set ( _bScript
? DocumentScriptLibraryContainer::create(
xContext, xStorageDoc )
: DocumentDialogLibraryContainer::create(
xContext, xStorageDoc )
, UNO_QUERY_THROW );
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
}
return _rxContainer;
}
}
//--------------------------------------------------------------------
Reference< XLibraryContainer > SfxObjectShell::GetDialogContainer()
{
if ( !pImp->m_bNoBasicCapabilities )
return lcl_getOrCreateLibraryContainer( false, pImp->xDialogLibraries, GetModel() );
BasicManager* pBasMgr = lcl_getBasicManagerForDocument( *this );
if ( pBasMgr )
return pBasMgr->GetDialogLibraryContainer().get();
OSL_FAIL( "SfxObjectShell::GetDialogContainer: falling back to the application - is this really expected here?" );
return SFX_APP()->GetDialogContainer();
}
//--------------------------------------------------------------------
Reference< XLibraryContainer > SfxObjectShell::GetBasicContainer()
{
if ( !pImp->m_bNoBasicCapabilities )
return lcl_getOrCreateLibraryContainer( true, pImp->xBasicLibraries, GetModel() );
BasicManager* pBasMgr = lcl_getBasicManagerForDocument( *this );
if ( pBasMgr )
return pBasMgr->GetScriptLibraryContainer().get();
OSL_FAIL( "SfxObjectShell::GetBasicContainer: falling back to the application - is this really expected here?" );
return SFX_APP()->GetBasicContainer();
}
//--------------------------------------------------------------------
StarBASIC* SfxObjectShell::GetBasic() const
{
return GetBasicManager()->GetLib(0);
}
//--------------------------------------------------------------------
void SfxObjectShell::InitBasicManager_Impl()
/* [Description]
Creates a document's BasicManager and loads it, if we are already based on
a storage.
[Note]
This method has to be called through the overloading of
<SvPersist::Load()> (With the PStore from the parameters of load ())
and from the overloading of <SvPersist::InitNew()> (with PStore = 0).
*/
{
/* #163556# (DR) - Handling of recursive calls while creating the Bacic
manager.
It is possible that (while creating the Basic manager) the code that
imports the Basic storage wants to access the Basic manager again.
Especially in VBA compatibility mode, there is code that wants to
access the "VBA Globals" object which is stored as global UNO constant
in the Basic manager.
To achieve correct handling of the recursive calls of this function
from lcl_getBasicManagerForDocument(), the implementation of the
function BasicManagerRepository::getDocumentBasicManager() has been
changed to return the Basic manager currently under construction, when
called repeatedly.
The variable pImp->bBasicInitialized will be set to sal_True after
construction now, to ensure that the recursive call of the function
lcl_getBasicManagerForDocument() will be routed into this function too.
Calling BasicManagerHolder::reset() twice is not a big problem, as it
does not take ownership but stores only the raw pointer. Owner of all
Basic managers is the global BasicManagerRepository instance.
*/
DBG_ASSERT( !pImp->bBasicInitialized && !pImp->pBasicManager->isValid(), "Lokaler BasicManager bereits vorhanden");
pImp->pBasicManager->reset( BasicManagerRepository::getDocumentBasicManager( GetModel() ) );
DBG_ASSERT( pImp->pBasicManager->isValid(), "SfxObjectShell::InitBasicManager_Impl: did not get a BasicManager!" );
pImp->bBasicInitialized = sal_True;
}
//--------------------------------------------------------------------
sal_uInt16 SfxObjectShell::Count()
{
return SFX_APP()->GetObjectShells_Impl().Count();
}
//--------------------------------------------------------------------
sal_Bool SfxObjectShell::DoClose()
{
return Close();
}
//--------------------------------------------------------------------
SfxObjectShell* SfxObjectShell::GetObjectShell()
{
return this;
}
//--------------------------------------------------------------------
uno::Sequence< ::rtl::OUString > SfxObjectShell::GetEventNames()
{
static uno::Sequence< ::rtl::OUString >* pEventNameContainer = NULL;
if ( !pEventNameContainer )
{
SolarMutexGuard aGuard;
if ( !pEventNameContainer )
{
static uno::Sequence< ::rtl::OUString > aEventNameContainer = GlobalEventConfig().getElementNames();
pEventNameContainer = &aEventNameContainer;
}
}
return *pEventNameContainer;
}
//--------------------------------------------------------------------
::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > SfxObjectShell::GetModel() const
{
return GetBaseModel();
}
void SfxObjectShell::SetBaseModel( SfxBaseModel* pModel )
{
OSL_ENSURE( !pImp->pBaseModel.is() || pModel == NULL, "Model already set!" );
pImp->pBaseModel.set( pModel );
if ( pImp->pBaseModel.is() )
{
pImp->pBaseModel->addCloseListener( new SfxModelListener_Impl(this) );
}
}
//--------------------------------------------------------------------
::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > SfxObjectShell::GetBaseModel() const
{
return pImp->pBaseModel.get();
}
void SfxObjectShell::SetAutoStyleFilterIndex(sal_uInt16 nSet)
{
pImp->nStyleFilter = nSet;
}
sal_uInt16 SfxObjectShell::GetAutoStyleFilterIndex()
{
return pImp->nStyleFilter;
}
void SfxObjectShell::SetCurrentComponent( const Reference< XInterface >& _rxComponent )
{
Reference< XInterface > xTest(s_xCurrentComponent);
if ( _rxComponent == xTest )
// nothing to do
return;
// note that "_rxComponent.get() == s_xCurrentComponent.get().get()" is /sufficient/, but not
// /required/ for "_rxComponent == s_xCurrentComponent.get()".
// In other words, it's still possible that we here do something which is not necessary,
// but we should have filtered quite some unnecessary calls already.
BasicManager* pAppMgr = SFX_APP()->GetBasicManager();
s_xCurrentComponent = _rxComponent;
if ( pAppMgr )
{
lcl_UpdateAppBasicDocVars( _rxComponent );
pAppMgr->SetGlobalUNOConstant( "ThisComponent", makeAny( _rxComponent ) );
}
}
Reference< XInterface > SfxObjectShell::GetCurrentComponent()
{
return s_xCurrentComponent;
}
String SfxObjectShell::GetServiceNameFromFactory( const String& rFact )
{
//! Remove everything behind name!
String aFact( rFact );
String aPrefix = String::CreateFromAscii( "private:factory/" );
if ( aPrefix.Len() == aFact.Match( aPrefix ) )
aFact.Erase( 0, aPrefix.Len() );
sal_uInt16 nPos = aFact.Search( '?' );
String aParam;
if ( nPos != STRING_NOTFOUND )
{
aParam = aFact.Copy( nPos, aFact.Len() );
aFact.Erase( nPos, aFact.Len() );
aParam.Erase(0,1);
}
aFact.EraseAllChars('4').ToLowerAscii();
// HACK: sometimes a real document service name is given here instead of
// a factory short name. Set return value directly to this service name as fallback
// in case next lines of code does nothing ...
// use rFact instead of normed aFact value !
::rtl::OUString aServiceName = rFact;
if ( aFact.EqualsAscii("swriter") )
{
aServiceName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextDocument"));
}
else if ( aFact.EqualsAscii("sweb") || aFact.EqualsAscii("swriter/web") )
{
aServiceName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.WebDocument"));
}
else if ( aFact.EqualsAscii("sglobal") || aFact.EqualsAscii("swriter/globaldocument") )
{
aServiceName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.GlobalDocument"));
}
else if ( aFact.EqualsAscii("scalc") )
{
aServiceName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.SpreadsheetDocument"));
}
else if ( aFact.EqualsAscii("sdraw") )
{
aServiceName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.DrawingDocument"));
}
else if ( aFact.EqualsAscii("simpress") )
{
aServiceName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.PresentationDocument"));
}
else if ( aFact.EqualsAscii("schart") )
{
aServiceName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.ChartDocument"));
}
else if ( aFact.EqualsAscii("smath") )
{
aServiceName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.formula.FormulaProperties"));
}
else if ( aFact.EqualsAscii("sbasic") )
{
aServiceName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.script.BasicIDE"));
}
else if ( aFact.EqualsAscii("sdatabase") )
{
aServiceName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.OfficeDatabaseDocument"));
}
return aServiceName;
}
SfxObjectShell* SfxObjectShell::CreateObjectByFactoryName( const String& rFact, SfxObjectCreateMode eMode )
{
return CreateObject( GetServiceNameFromFactory( rFact ), eMode );
}
SfxObjectShell* SfxObjectShell::CreateObject( const String& rServiceName, SfxObjectCreateMode eCreateMode )
{
if ( rServiceName.Len() )
{
::com::sun::star::uno::Reference < ::com::sun::star::frame::XModel > xDoc(
::comphelper::getProcessServiceFactory()->createInstance( rServiceName ), UNO_QUERY );
if ( xDoc.is() )
{
::com::sun::star::uno::Reference < ::com::sun::star::lang::XUnoTunnel > xObj( xDoc, UNO_QUERY );
::com::sun::star::uno::Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
sal_Int64 nHandle = xObj->getSomething( aSeq );
if ( nHandle )
{
SfxObjectShell* pRet = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
pRet->SetCreateMode_Impl( eCreateMode );
return pRet;
}
}
}
return 0;
}
SfxObjectShell* SfxObjectShell::CreateAndLoadObject( const SfxItemSet& rSet, SfxFrame* pFrame )
{
Reference<lang::XComponent> xComp = CreateAndLoadComponent(rSet, pFrame);
return GetShellFromComponent(xComp);
}
Reference<lang::XComponent> SfxObjectShell::CreateAndLoadComponent( const SfxItemSet& rSet, SfxFrame* pFrame )
{
uno::Sequence < beans::PropertyValue > aProps;
TransformItems( SID_OPENDOC, rSet, aProps );
SFX_ITEMSET_ARG(&rSet, pFileNameItem, SfxStringItem, SID_FILE_NAME, sal_False);
SFX_ITEMSET_ARG(&rSet, pTargetItem, SfxStringItem, SID_TARGETNAME, sal_False);
::rtl::OUString aURL;
::rtl::OUString aTarget(RTL_CONSTASCII_USTRINGPARAM("_blank"));
if ( pFileNameItem )
aURL = pFileNameItem->GetValue();
if ( pTargetItem )
aTarget = pTargetItem->GetValue();
uno::Reference < frame::XComponentLoader > xLoader;
if ( pFrame )
{
xLoader = uno::Reference < frame::XComponentLoader >( pFrame->GetFrameInterface(), uno::UNO_QUERY );
}
else
xLoader = uno::Reference < frame::XComponentLoader >( comphelper::getProcessServiceFactory()->createInstance(
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop")) ), uno::UNO_QUERY );
Reference <lang::XComponent> xComp;
try
{
xComp = xLoader->loadComponentFromURL(aURL, aTarget, 0, aProps);
}
catch( uno::Exception& )
{}
return xComp;
}
SfxObjectShell* SfxObjectShell::GetShellFromComponent( const Reference<lang::XComponent>& xComp )
{
try
{
Reference<lang::XUnoTunnel> xTunnel(xComp, UNO_QUERY_THROW);
Sequence <sal_Int8> aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
sal_Int64 nHandle = xTunnel->getSomething( aSeq );
if (!nHandle)
return NULL;
return reinterpret_cast< SfxObjectShell* >(sal::static_int_cast< sal_IntPtr >( nHandle ));
}
catch (const Exception&)
{
}
return NULL;
}
void SfxObjectShell::SetInitialized_Impl( const bool i_fromInitNew )
{
pImp->bInitialized = sal_True;
if ( i_fromInitNew )
{
SetActivateEvent_Impl( SFX_EVENT_CREATEDOC );
SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_DOCCREATED, GlobalEventConfig::GetEventName(STR_EVENT_DOCCREATED), this ) );
}
else
{
SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_LOADFINISHED, GlobalEventConfig::GetEventName(STR_EVENT_LOADFINISHED), this ) );
}
}
bool SfxObjectShell::IsChangeRecording() const
{
// currently this function needs to be overwritten by Writer and Calc only
DBG_ASSERT( 0, "function not implemented" );
return false;
}
bool SfxObjectShell::HasChangeRecordProtection() const
{
// currently this function needs to be overwritten by Writer and Calc only
DBG_ASSERT( 0, "function not implemented" );
return false;
}
void SfxObjectShell::SetChangeRecording( bool /*bActivate*/ )
{
// currently this function needs to be overwritten by Writer and Calc only
DBG_ASSERT( 0, "function not implemented" );
}
bool SfxObjectShell::SetProtectionPassword( const String & /*rPassword*/ )
{
// currently this function needs to be overwritten by Writer and Calc only
DBG_ASSERT( 0, "function not implemented" );
return false;
}
bool SfxObjectShell::GetProtectionHash( /*out*/ ::com::sun::star::uno::Sequence< sal_Int8 > & /*rPasswordHash*/ )
{
// currently this function needs to be overwritten by Writer and Calc only
DBG_ASSERT( 0, "function not implemented" );
return false;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|