xref: /aoo41x/main/sfx2/source/doc/sfxbasemodel.cxx (revision e4c033a6)
1d119d52dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3d119d52dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4d119d52dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5d119d52dSAndrew Rist  * distributed with this work for additional information
6d119d52dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7d119d52dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8d119d52dSAndrew Rist  * "License"); you may not use this file except in compliance
9d119d52dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10d119d52dSAndrew Rist  *
11d119d52dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12d119d52dSAndrew Rist  *
13d119d52dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14d119d52dSAndrew Rist  * software distributed under the License is distributed on an
15d119d52dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16d119d52dSAndrew Rist  * KIND, either express or implied.  See the License for the
17d119d52dSAndrew Rist  * specific language governing permissions and limitations
18d119d52dSAndrew Rist  * under the License.
19d119d52dSAndrew Rist  *
20d119d52dSAndrew Rist  *************************************************************/
21d119d52dSAndrew Rist 
22d119d52dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir //________________________________________________________________________________________________________
28cdf0e10cSrcweir //	my own includes
29cdf0e10cSrcweir //________________________________________________________________________________________________________
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <sfx2/sfxbasemodel.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir //________________________________________________________________________________________________________
34cdf0e10cSrcweir //	include of other projects
35cdf0e10cSrcweir //________________________________________________________________________________________________________
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp>
38cdf0e10cSrcweir #include <com/sun/star/task/ErrorCodeRequest.hpp>
39cdf0e10cSrcweir #include <com/sun/star/view/XSelectionSupplier.hpp>
40cdf0e10cSrcweir #include <com/sun/star/view/XPrintJobListener.hpp>
41cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
42cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp>
43cdf0e10cSrcweir #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
44cdf0e10cSrcweir #include <com/sun/star/frame/IllegalArgumentIOException.hpp>
45cdf0e10cSrcweir #include <com/sun/star/frame/XUntitledNumbers.hpp>
46cdf0e10cSrcweir #include <com/sun/star/frame/UntitledNumbersConst.hpp>
47cdf0e10cSrcweir #include <com/sun/star/embed/XTransactionBroadcaster.hpp>
48cdf0e10cSrcweir #include <com/sun/star/embed/XStorage.hpp>
49cdf0e10cSrcweir #include <com/sun/star/embed/EmbedMapUnits.hpp>
50cdf0e10cSrcweir #include <com/sun/star/document/XStorageChangeListener.hpp>
51cdf0e10cSrcweir #include <com/sun/star/document/XActionLockable.hpp>
52cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
53cdf0e10cSrcweir #include <com/sun/star/container/XIndexContainer.hpp>
54cdf0e10cSrcweir #include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
55cdf0e10cSrcweir #include <com/sun/star/script/provider/XScriptProvider.hpp>
56cdf0e10cSrcweir #include <com/sun/star/ui/XUIConfigurationStorage.hpp>
57cdf0e10cSrcweir #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
58cdf0e10cSrcweir #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
59cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp>
60cdf0e10cSrcweir #include <com/sun/star/embed/Aspects.hpp>
61cdf0e10cSrcweir #include <com/sun/star/document/XDocumentProperties.hpp>
62cdf0e10cSrcweir #include <com/sun/star/frame/XTransientDocumentsDocumentContentFactory.hpp>
63cdf0e10cSrcweir #include <comphelper/enumhelper.hxx>  // can be removed when this is a "real" service
64cdf0e10cSrcweir 
65cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx>
66cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
67cdf0e10cSrcweir #include <comphelper/processfactory.hxx>  // can be removed when this is a "real" service
68cdf0e10cSrcweir #include <comphelper/componentcontext.hxx>
69cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx>
70cdf0e10cSrcweir #include <svl/itemset.hxx>
71cdf0e10cSrcweir #include <svl/stritem.hxx>
72cdf0e10cSrcweir #include <svl/eitem.hxx>
73cdf0e10cSrcweir #include <svl/intitem.hxx>
74cdf0e10cSrcweir #include <basic/sbx.hxx>
75cdf0e10cSrcweir #include <basic/sbuno.hxx>
76cdf0e10cSrcweir #include <tools/urlobj.hxx>
77cdf0e10cSrcweir #include <tools/diagnose_ex.h>
78cdf0e10cSrcweir #include <unotools/tempfile.hxx>
79cdf0e10cSrcweir #include <vos/mutex.hxx>
80cdf0e10cSrcweir #include <vcl/salctype.hxx>
81cdf0e10cSrcweir #include <sot/clsids.hxx>
82cdf0e10cSrcweir #include <sot/storinfo.hxx>
83cdf0e10cSrcweir #include <comphelper/storagehelper.hxx>
84cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
85cdf0e10cSrcweir #include <svtools/transfer.hxx>
86cdf0e10cSrcweir #include <svtools/ehdl.hxx>
87cdf0e10cSrcweir #include <svtools/sfxecode.hxx>
88cdf0e10cSrcweir #include <rtl/logfile.hxx>
89cdf0e10cSrcweir #include <framework/configimporter.hxx>
90cdf0e10cSrcweir #include <framework/interaction.hxx>
91cdf0e10cSrcweir #include <framework/titlehelper.hxx>
92cdf0e10cSrcweir #include <comphelper/numberedcollection.hxx>
93cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
94cdf0e10cSrcweir #include <unotools/ucbhelper.hxx>
95cdf0e10cSrcweir 
96cdf0e10cSrcweir //________________________________________________________________________________________________________
97cdf0e10cSrcweir //	includes of my own project
98cdf0e10cSrcweir //________________________________________________________________________________________________________
99cdf0e10cSrcweir 
100cdf0e10cSrcweir #include <sfx2/sfxbasecontroller.hxx>
101cdf0e10cSrcweir #include "sfx2/viewfac.hxx"
102cdf0e10cSrcweir #include "workwin.hxx"
103cdf0e10cSrcweir #include <sfx2/signaturestate.hxx>
104cdf0e10cSrcweir #include <sfx2/sfxuno.hxx>
105cdf0e10cSrcweir #include <objshimp.hxx>
106cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
107cdf0e10cSrcweir #include <sfx2/viewsh.hxx>
108cdf0e10cSrcweir #include <sfx2/docfile.hxx>
109cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
110cdf0e10cSrcweir #include <sfx2/request.hxx>
111cdf0e10cSrcweir #include <sfx2/objuno.hxx>
112cdf0e10cSrcweir #include <sfx2/printer.hxx>
113cdf0e10cSrcweir #include <sfx2/basmgr.hxx>
114cdf0e10cSrcweir #include <sfx2/event.hxx>
115cdf0e10cSrcweir #include <eventsupplier.hxx>
116cdf0e10cSrcweir #include <sfx2/evntconf.hxx>
117cdf0e10cSrcweir #include <sfx2/sfx.hrc>
118cdf0e10cSrcweir #include <sfx2/app.hxx>
119cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
120cdf0e10cSrcweir #include "appdata.hxx"
121cdf0e10cSrcweir #include <sfx2/docfac.hxx>
122cdf0e10cSrcweir #include <sfx2/fcontnr.hxx>
123cdf0e10cSrcweir #include "sfx2/docstoragemodifylistener.hxx"
124cdf0e10cSrcweir #include "sfx2/brokenpackageint.hxx"
125cdf0e10cSrcweir #include "graphhelp.hxx"
126cdf0e10cSrcweir #include "docundomanager.hxx"
127cdf0e10cSrcweir #include <sfx2/msgpool.hxx>
128cdf0e10cSrcweir #include <sfx2/DocumentMetadataAccess.hxx>
129cdf0e10cSrcweir 
130cdf0e10cSrcweir #include <sfx2/sfxresid.hxx>
131cdf0e10cSrcweir 
132cdf0e10cSrcweir //________________________________________________________________________________________________________
133cdf0e10cSrcweir // const
134cdf0e10cSrcweir static const ::rtl::OUString SERVICENAME_DESKTOP = ::rtl::OUString::createFromAscii ("com.sun.star.frame.Desktop");
135cdf0e10cSrcweir 
136cdf0e10cSrcweir //________________________________________________________________________________________________________
137cdf0e10cSrcweir //	namespaces
138cdf0e10cSrcweir //________________________________________________________________________________________________________
139cdf0e10cSrcweir 
140cdf0e10cSrcweir namespace css = ::com::sun::star;
141cdf0e10cSrcweir using namespace ::com::sun::star;
142cdf0e10cSrcweir using namespace ::com::sun::star::uno;
143cdf0e10cSrcweir using ::com::sun::star::beans::PropertyValue;
144cdf0e10cSrcweir using ::com::sun::star::frame::XFrame;
145cdf0e10cSrcweir using ::com::sun::star::frame::XController;
146cdf0e10cSrcweir using ::com::sun::star::frame::XController2;
147cdf0e10cSrcweir using ::com::sun::star::lang::IllegalArgumentException;
148cdf0e10cSrcweir using ::com::sun::star::io::IOException;
149cdf0e10cSrcweir using ::com::sun::star::lang::WrappedTargetException;
150cdf0e10cSrcweir using ::com::sun::star::uno::Type;
151cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
152cdf0e10cSrcweir using ::com::sun::star::document::XDocumentRecovery;
153cdf0e10cSrcweir using ::com::sun::star::document::XUndoManager;
154cdf0e10cSrcweir using ::com::sun::star::document::XUndoAction;
155cdf0e10cSrcweir using ::com::sun::star::document::UndoFailedException;
156cdf0e10cSrcweir using ::com::sun::star::frame::XModel;
157cdf0e10cSrcweir 
158cdf0e10cSrcweir /** This Listener is used to get notified when the XDocumentProperties of the
159cdf0e10cSrcweir     XModel change.
160cdf0e10cSrcweir  */
161cdf0e10cSrcweir class SfxDocInfoListener_Impl : public ::cppu::WeakImplHelper1<
162cdf0e10cSrcweir     ::com::sun::star::util::XModifyListener >
163cdf0e10cSrcweir {
164cdf0e10cSrcweir 
165cdf0e10cSrcweir public:
166cdf0e10cSrcweir     SfxObjectShell& m_rShell;
167cdf0e10cSrcweir 
SfxDocInfoListener_Impl(SfxObjectShell & i_rDoc)168cdf0e10cSrcweir     SfxDocInfoListener_Impl( SfxObjectShell& i_rDoc )
169cdf0e10cSrcweir         : m_rShell(i_rDoc)
170cdf0e10cSrcweir     { };
171cdf0e10cSrcweir 
172cdf0e10cSrcweir     ~SfxDocInfoListener_Impl();
173cdf0e10cSrcweir 
174cdf0e10cSrcweir     virtual void SAL_CALL disposing( const lang::EventObject& )
175cdf0e10cSrcweir         throw ( uno::RuntimeException );
176cdf0e10cSrcweir     virtual void SAL_CALL modified( const lang::EventObject& )
177cdf0e10cSrcweir         throw ( uno::RuntimeException );
178cdf0e10cSrcweir };
~SfxDocInfoListener_Impl()179cdf0e10cSrcweir SfxDocInfoListener_Impl::~SfxDocInfoListener_Impl()
180cdf0e10cSrcweir {
181cdf0e10cSrcweir }
modified(const lang::EventObject &)182cdf0e10cSrcweir void SAL_CALL SfxDocInfoListener_Impl::modified( const lang::EventObject& )
183cdf0e10cSrcweir         throw ( uno::RuntimeException )
184cdf0e10cSrcweir {
185cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
186cdf0e10cSrcweir 
187cdf0e10cSrcweir     // notify changes to the SfxObjectShell
188cdf0e10cSrcweir     m_rShell.FlushDocInfo();
189cdf0e10cSrcweir }
190cdf0e10cSrcweir 
disposing(const lang::EventObject &)191cdf0e10cSrcweir void SAL_CALL SfxDocInfoListener_Impl::disposing( const lang::EventObject& )
192cdf0e10cSrcweir     throw ( uno::RuntimeException )
193cdf0e10cSrcweir {
194cdf0e10cSrcweir }
195cdf0e10cSrcweir 
196cdf0e10cSrcweir //________________________________________________________________________________________________________
197cdf0e10cSrcweir //	impl. declarations
198cdf0e10cSrcweir //________________________________________________________________________________________________________
199cdf0e10cSrcweir 
200cdf0e10cSrcweir 
201cdf0e10cSrcweir struct IMPL_SfxBaseModel_DataContainer : public ::sfx2::IModifiableDocument
202cdf0e10cSrcweir {
203cdf0e10cSrcweir     // counter for SfxBaseModel instances created.
204cdf0e10cSrcweir     static sal_Int64                                        g_nInstanceCounter      ;
205cdf0e10cSrcweir     SfxObjectShellRef                                       m_pObjectShell          ;
206cdf0e10cSrcweir     ::rtl::OUString                                         m_sURL                  ;
207cdf0e10cSrcweir     ::rtl::OUString                                         m_sRuntimeUID           ;
208cdf0e10cSrcweir     ::rtl::OUString                                         m_aPreusedFilterName;
209cdf0e10cSrcweir     ::cppu::OMultiTypeInterfaceContainerHelper              m_aInterfaceContainer   ;
210cdf0e10cSrcweir     uno::Reference< uno::XInterface >                       m_xParent               ;
211cdf0e10cSrcweir     uno::Reference< frame::XController >                    m_xCurrent              ;
212cdf0e10cSrcweir     uno::Reference< document::XDocumentInfo >               m_xDocumentInfo         ;
213cdf0e10cSrcweir     uno::Reference< document::XDocumentProperties >         m_xDocumentProperties;
214cdf0e10cSrcweir     uno::Reference< script::XStarBasicAccess >              m_xStarBasicAccess      ;
215cdf0e10cSrcweir     uno::Reference< container::XNameReplace >               m_xEvents               ;
216cdf0e10cSrcweir     uno::Sequence< beans::PropertyValue>                    m_seqArguments          ;
217cdf0e10cSrcweir     uno::Sequence< uno::Reference< frame::XController > >   m_seqControllers        ;
218cdf0e10cSrcweir     uno::Reference< container::XIndexAccess >               m_contViewData          ;
219cdf0e10cSrcweir     sal_uInt16                                              m_nControllerLockCount  ;
220cdf0e10cSrcweir     sal_Bool                                                m_bClosed               ;
221cdf0e10cSrcweir     sal_Bool                                                m_bClosing              ;
222cdf0e10cSrcweir     sal_Bool                                                m_bSaving               ;
223cdf0e10cSrcweir     sal_Bool                                                m_bSuicide              ;
224cdf0e10cSrcweir     sal_Bool                                                m_bInitialized          ;
225cdf0e10cSrcweir     sal_Bool                                                m_bExternalTitle        ;
226cdf0e10cSrcweir     sal_Bool                                                m_bModifiedSinceLastSave;
227cdf0e10cSrcweir     uno::Reference< com::sun::star::view::XPrintable>       m_xPrintable            ;
228cdf0e10cSrcweir     uno::Reference< script::provider::XScriptProvider >     m_xScriptProvider;
229cdf0e10cSrcweir     uno::Reference< ui::XUIConfigurationManager >           m_xUIConfigurationManager;
230cdf0e10cSrcweir     ::rtl::Reference< ::sfx2::DocumentStorageModifyListener >   m_pStorageModifyListen;
231cdf0e10cSrcweir     ::rtl::OUString                                         m_sModuleIdentifier;
232cdf0e10cSrcweir     css::uno::Reference< css::frame::XTitle >               m_xTitleHelper;
233cdf0e10cSrcweir     css::uno::Reference< css::frame::XUntitledNumbers >     m_xNumberedControllers;
234cdf0e10cSrcweir     uno::Reference< rdf::XDocumentMetadataAccess>           m_xDocumentMetadata;
235cdf0e10cSrcweir     ::rtl::Reference< ::sfx2::DocumentUndoManager >         m_pDocumentUndoManager;
236cdf0e10cSrcweir 
237cdf0e10cSrcweir 
IMPL_SfxBaseModel_DataContainerIMPL_SfxBaseModel_DataContainer238cdf0e10cSrcweir     IMPL_SfxBaseModel_DataContainer( ::osl::Mutex& rMutex, SfxObjectShell* pObjectShell )
239cdf0e10cSrcweir             :   m_pObjectShell			( pObjectShell	)
240cdf0e10cSrcweir 			,	m_aInterfaceContainer   ( rMutex        )
241cdf0e10cSrcweir 			,	m_nControllerLockCount	( 0				)
242cdf0e10cSrcweir 			,	m_bClosed			    ( sal_False		)
243cdf0e10cSrcweir 			,	m_bClosing			    ( sal_False		)
244cdf0e10cSrcweir             ,   m_bSaving               ( sal_False     )
245cdf0e10cSrcweir             ,   m_bSuicide              ( sal_False     )
246cdf0e10cSrcweir             ,   m_bInitialized          ( sal_False     )
247cdf0e10cSrcweir             ,   m_bExternalTitle        ( sal_False     )
248cdf0e10cSrcweir             ,   m_bModifiedSinceLastSave( sal_False     )
249cdf0e10cSrcweir 			,	m_pStorageModifyListen	( NULL			)
250cdf0e10cSrcweir             ,   m_xTitleHelper          ()
251cdf0e10cSrcweir             ,   m_xNumberedControllers  ()
252cdf0e10cSrcweir             ,   m_xDocumentMetadata     () // lazy
253cdf0e10cSrcweir             ,   m_pDocumentUndoManager  ()
254cdf0e10cSrcweir 	{
255cdf0e10cSrcweir         // increase global instance counter.
256cdf0e10cSrcweir         ++g_nInstanceCounter;
257cdf0e10cSrcweir         // set own Runtime UID
258cdf0e10cSrcweir         m_sRuntimeUID = rtl::OUString::valueOf( g_nInstanceCounter );
259cdf0e10cSrcweir 	}
260cdf0e10cSrcweir 
~IMPL_SfxBaseModel_DataContainerIMPL_SfxBaseModel_DataContainer261cdf0e10cSrcweir     virtual ~IMPL_SfxBaseModel_DataContainer()
262cdf0e10cSrcweir     {
263cdf0e10cSrcweir     }
264cdf0e10cSrcweir 
265cdf0e10cSrcweir     // ::sfx2::IModifiableDocument
storageIsModifiedIMPL_SfxBaseModel_DataContainer266cdf0e10cSrcweir     virtual void storageIsModified()
267cdf0e10cSrcweir     {
268cdf0e10cSrcweir 	    if ( m_pObjectShell.Is() && !m_pObjectShell->IsModified() )
269cdf0e10cSrcweir 		    m_pObjectShell->SetModified( sal_True );
270cdf0e10cSrcweir     }
271cdf0e10cSrcweir 
GetDMAIMPL_SfxBaseModel_DataContainer272cdf0e10cSrcweir     uno::Reference<rdf::XDocumentMetadataAccess> GetDMA()
273cdf0e10cSrcweir     {
274cdf0e10cSrcweir         if (!m_xDocumentMetadata.is())
275cdf0e10cSrcweir         {
276cdf0e10cSrcweir             OSL_ENSURE(m_pObjectShell, "GetDMA: no object shell?");
277cdf0e10cSrcweir             if (!m_pObjectShell)
278cdf0e10cSrcweir             {
279cdf0e10cSrcweir                 return 0;
280cdf0e10cSrcweir             }
281cdf0e10cSrcweir 
282cdf0e10cSrcweir             const uno::Reference<uno::XComponentContext> xContext(
283cdf0e10cSrcweir                 ::comphelper::getProcessComponentContext());
284cdf0e10cSrcweir             ::rtl::OUString uri;
285cdf0e10cSrcweir             const uno::Reference<frame::XModel> xModel(
286cdf0e10cSrcweir                 m_pObjectShell->GetModel());
287cdf0e10cSrcweir             const uno::Reference<lang::XMultiComponentFactory> xMsf(
288cdf0e10cSrcweir                 xContext->getServiceManager());
289cdf0e10cSrcweir             const uno::Reference<frame::
290cdf0e10cSrcweir                 XTransientDocumentsDocumentContentFactory> xTDDCF(
291cdf0e10cSrcweir                     xMsf->createInstanceWithContext(
292cdf0e10cSrcweir                         ::rtl::OUString::createFromAscii( "com.sun.star.frame."
293cdf0e10cSrcweir                             "TransientDocumentsDocumentContentFactory"),
294cdf0e10cSrcweir                     xContext),
295cdf0e10cSrcweir                 uno::UNO_QUERY_THROW);
296cdf0e10cSrcweir             const uno::Reference<ucb::XContent> xContent(
297cdf0e10cSrcweir                 xTDDCF->createDocumentContent(xModel) );
298cdf0e10cSrcweir             OSL_ENSURE(xContent.is(), "GetDMA: cannot create DocumentContent");
299cdf0e10cSrcweir             if (!xContent.is())
300cdf0e10cSrcweir             {
301cdf0e10cSrcweir                 return 0;
302cdf0e10cSrcweir             }
303cdf0e10cSrcweir             uri = xContent->getIdentifier()->getContentIdentifier();
304cdf0e10cSrcweir             OSL_ENSURE(uri.getLength(), "GetDMA: empty uri?");
305cdf0e10cSrcweir             if (uri.getLength() && !uri.endsWithAsciiL("/", 1))
306cdf0e10cSrcweir             {
307cdf0e10cSrcweir                 uri = uri + ::rtl::OUString::createFromAscii("/");
308cdf0e10cSrcweir             }
309cdf0e10cSrcweir 
310cdf0e10cSrcweir             m_xDocumentMetadata = new ::sfx2::DocumentMetadataAccess(
311cdf0e10cSrcweir                 xContext, *m_pObjectShell, uri);
312cdf0e10cSrcweir         }
313cdf0e10cSrcweir         return m_xDocumentMetadata;
314cdf0e10cSrcweir     }
315cdf0e10cSrcweir 
CreateDMAUninitializedIMPL_SfxBaseModel_DataContainer316cdf0e10cSrcweir     uno::Reference<rdf::XDocumentMetadataAccess> CreateDMAUninitialized()
317cdf0e10cSrcweir     {
318cdf0e10cSrcweir         return (m_pObjectShell)
319cdf0e10cSrcweir             ? new ::sfx2::DocumentMetadataAccess(
320cdf0e10cSrcweir                 ::comphelper::getProcessComponentContext(), *m_pObjectShell)
321cdf0e10cSrcweir             : 0;
322cdf0e10cSrcweir     }
323cdf0e10cSrcweir };
324cdf0e10cSrcweir 
325cdf0e10cSrcweir // static member initialization.
326cdf0e10cSrcweir sal_Int64 IMPL_SfxBaseModel_DataContainer::g_nInstanceCounter = 0;
327cdf0e10cSrcweir 
328cdf0e10cSrcweir // =======================================================================================================
329cdf0e10cSrcweir 
330cdf0e10cSrcweir // Listener that forwards notifications from the PrintHelper to the "real" listeners
331cdf0e10cSrcweir class SfxPrintHelperListener_Impl : public ::cppu::WeakImplHelper1< ::com::sun::star::view::XPrintJobListener >
332cdf0e10cSrcweir {
333cdf0e10cSrcweir public:
334cdf0e10cSrcweir     IMPL_SfxBaseModel_DataContainer* m_pData;
SfxPrintHelperListener_Impl(IMPL_SfxBaseModel_DataContainer * pData)335cdf0e10cSrcweir     SfxPrintHelperListener_Impl( IMPL_SfxBaseModel_DataContainer* pData )
336cdf0e10cSrcweir         : m_pData( pData )
337cdf0e10cSrcweir     {}
338cdf0e10cSrcweir 
339cdf0e10cSrcweir     virtual void SAL_CALL disposing( const lang::EventObject& aEvent ) throw ( uno::RuntimeException ) ;
340cdf0e10cSrcweir     virtual void SAL_CALL printJobEvent( const view::PrintJobEvent& rEvent ) throw ( uno::RuntimeException);
341cdf0e10cSrcweir };
342cdf0e10cSrcweir 
disposing(const lang::EventObject &)343cdf0e10cSrcweir void SAL_CALL SfxPrintHelperListener_Impl::disposing( const lang::EventObject& ) throw ( uno::RuntimeException )
344cdf0e10cSrcweir {
345cdf0e10cSrcweir     m_pData->m_xPrintable = 0;
346cdf0e10cSrcweir }
347cdf0e10cSrcweir 
printJobEvent(const view::PrintJobEvent & rEvent)348cdf0e10cSrcweir void SAL_CALL SfxPrintHelperListener_Impl::printJobEvent( const view::PrintJobEvent& rEvent ) throw (uno::RuntimeException)
349cdf0e10cSrcweir {
350cdf0e10cSrcweir     ::cppu::OInterfaceContainerHelper* pContainer = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( ( const uno::Reference< view::XPrintJobListener >*) NULL ) );
351cdf0e10cSrcweir     if ( pContainer!=NULL )
352cdf0e10cSrcweir     {
353cdf0e10cSrcweir         ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
354cdf0e10cSrcweir         while (pIterator.hasMoreElements())
355cdf0e10cSrcweir             ((view::XPrintJobListener*)pIterator.next())->printJobEvent( rEvent );
356cdf0e10cSrcweir     }
357cdf0e10cSrcweir }
358cdf0e10cSrcweir 
359cdf0e10cSrcweir // SfxOwnFramesLocker ====================================================================================
360cdf0e10cSrcweir // allows to lock all the frames related to the provided SfxObjectShell
361cdf0e10cSrcweir class SfxOwnFramesLocker
362cdf0e10cSrcweir {
363cdf0e10cSrcweir 	uno::Sequence< uno::Reference< frame::XFrame > > m_aLockedFrames;
364cdf0e10cSrcweir 
365cdf0e10cSrcweir 	Window* GetVCLWindow( const uno::Reference< frame::XFrame >& xFrame );
366cdf0e10cSrcweir public:
367cdf0e10cSrcweir 	SfxOwnFramesLocker( SfxObjectShell* ObjechShell );
368cdf0e10cSrcweir 	~SfxOwnFramesLocker();
369cdf0e10cSrcweir 	void UnlockFrames();
370cdf0e10cSrcweir };
371cdf0e10cSrcweir 
SfxOwnFramesLocker(SfxObjectShell * pObjectShell)372cdf0e10cSrcweir SfxOwnFramesLocker::SfxOwnFramesLocker( SfxObjectShell* pObjectShell )
373cdf0e10cSrcweir {
374cdf0e10cSrcweir 	if ( !pObjectShell )
375cdf0e10cSrcweir 		return;
376cdf0e10cSrcweir 
377cdf0e10cSrcweir 	for (   SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pObjectShell );
378cdf0e10cSrcweir             pFrame;
379cdf0e10cSrcweir 			pFrame = SfxViewFrame::GetNext( *pFrame, pObjectShell )
380cdf0e10cSrcweir         )
381cdf0e10cSrcweir 	{
382cdf0e10cSrcweir 		SfxFrame& rSfxFrame = pFrame->GetFrame();
383cdf0e10cSrcweir 		try
384cdf0e10cSrcweir 		{
385cdf0e10cSrcweir 			// get vcl window related to the frame and lock it if it is still not locked
386cdf0e10cSrcweir 			uno::Reference< frame::XFrame > xFrame = rSfxFrame.GetFrameInterface();
387cdf0e10cSrcweir 			Window* pWindow = GetVCLWindow( xFrame );
388cdf0e10cSrcweir 			if ( !pWindow )
389cdf0e10cSrcweir 				throw uno::RuntimeException();
390cdf0e10cSrcweir 
391cdf0e10cSrcweir 			if ( pWindow->IsEnabled() )
392cdf0e10cSrcweir 			{
393cdf0e10cSrcweir 				pWindow->Disable();
394cdf0e10cSrcweir 
395cdf0e10cSrcweir 				try
396cdf0e10cSrcweir 				{
397cdf0e10cSrcweir 					sal_Int32 nLen = m_aLockedFrames.getLength();
398cdf0e10cSrcweir 					m_aLockedFrames.realloc( nLen + 1 );
399cdf0e10cSrcweir 					m_aLockedFrames[nLen] = xFrame;
400cdf0e10cSrcweir 				}
401cdf0e10cSrcweir 				catch( uno::Exception& )
402cdf0e10cSrcweir 				{
403cdf0e10cSrcweir 					pWindow->Enable();
404cdf0e10cSrcweir 					throw;
405cdf0e10cSrcweir 				}
406cdf0e10cSrcweir 			}
407cdf0e10cSrcweir 		}
408cdf0e10cSrcweir 		catch( uno::Exception& )
409cdf0e10cSrcweir 		{
410cdf0e10cSrcweir 			OSL_ENSURE( sal_False, "Not possible to lock the frame window!\n" );
411cdf0e10cSrcweir 		}
412cdf0e10cSrcweir 	}
413cdf0e10cSrcweir }
414cdf0e10cSrcweir 
~SfxOwnFramesLocker()415cdf0e10cSrcweir SfxOwnFramesLocker::~SfxOwnFramesLocker()
416cdf0e10cSrcweir {
417cdf0e10cSrcweir 	UnlockFrames();
418cdf0e10cSrcweir }
419cdf0e10cSrcweir 
GetVCLWindow(const uno::Reference<frame::XFrame> & xFrame)420cdf0e10cSrcweir Window* SfxOwnFramesLocker::GetVCLWindow( const uno::Reference< frame::XFrame >& xFrame )
421cdf0e10cSrcweir {
422cdf0e10cSrcweir 	Window* pWindow = NULL;
423cdf0e10cSrcweir 
424cdf0e10cSrcweir 	if ( xFrame.is() )
425cdf0e10cSrcweir 	{
426cdf0e10cSrcweir 		uno::Reference< awt::XWindow > xWindow = xFrame->getContainerWindow();
427cdf0e10cSrcweir 		if ( xWindow.is() )
428cdf0e10cSrcweir    			pWindow = VCLUnoHelper::GetWindow( xWindow );
429cdf0e10cSrcweir 	}
430cdf0e10cSrcweir 
431cdf0e10cSrcweir 	return pWindow;
432cdf0e10cSrcweir }
433cdf0e10cSrcweir 
UnlockFrames()434cdf0e10cSrcweir void SfxOwnFramesLocker::UnlockFrames()
435cdf0e10cSrcweir {
436cdf0e10cSrcweir 	for ( sal_Int32 nInd = 0; nInd < m_aLockedFrames.getLength(); nInd++ )
437cdf0e10cSrcweir 	{
438cdf0e10cSrcweir 		try
439cdf0e10cSrcweir 		{
440cdf0e10cSrcweir 			if ( m_aLockedFrames[nInd].is() )
441cdf0e10cSrcweir 			{
442cdf0e10cSrcweir 				// get vcl window related to the frame and unlock it
443cdf0e10cSrcweir 				Window* pWindow = GetVCLWindow( m_aLockedFrames[nInd] );
444cdf0e10cSrcweir 				if ( !pWindow )
445cdf0e10cSrcweir 					throw uno::RuntimeException();
446cdf0e10cSrcweir 
447cdf0e10cSrcweir 				pWindow->Enable();
448cdf0e10cSrcweir 
449cdf0e10cSrcweir 				m_aLockedFrames[nInd] = uno::Reference< frame::XFrame >();
450cdf0e10cSrcweir 			}
451cdf0e10cSrcweir 		}
452cdf0e10cSrcweir 		catch( uno::Exception& )
453cdf0e10cSrcweir 		{
454cdf0e10cSrcweir 			OSL_ENSURE( sal_False, "Can't unlock the frame window!\n" );
455cdf0e10cSrcweir 		}
456cdf0e10cSrcweir 	}
457cdf0e10cSrcweir }
458cdf0e10cSrcweir 
459cdf0e10cSrcweir // SfxSaveGuard ====================================================================================
460cdf0e10cSrcweir class SfxSaveGuard
461cdf0e10cSrcweir {
462cdf0e10cSrcweir     private:
463cdf0e10cSrcweir         uno::Reference< frame::XModel > m_xModel;
464cdf0e10cSrcweir         IMPL_SfxBaseModel_DataContainer* m_pData;
465cdf0e10cSrcweir         SfxOwnFramesLocker* m_pFramesLock;
466cdf0e10cSrcweir 
467cdf0e10cSrcweir     public:
468cdf0e10cSrcweir         SfxSaveGuard(const uno::Reference< frame::XModel >&             xModel                      ,
469cdf0e10cSrcweir                            IMPL_SfxBaseModel_DataContainer* pData                       ,
470cdf0e10cSrcweir                            sal_Bool                         bRejectConcurrentSaveRequest);
471cdf0e10cSrcweir         ~SfxSaveGuard();
472cdf0e10cSrcweir };
473cdf0e10cSrcweir 
SfxSaveGuard(const uno::Reference<frame::XModel> & xModel,IMPL_SfxBaseModel_DataContainer * pData,sal_Bool bRejectConcurrentSaveRequest)474cdf0e10cSrcweir SfxSaveGuard::SfxSaveGuard(const uno::Reference< frame::XModel >&             xModel                      ,
475cdf0e10cSrcweir                                  IMPL_SfxBaseModel_DataContainer* pData                       ,
476cdf0e10cSrcweir                                  sal_Bool                         bRejectConcurrentSaveRequest)
477cdf0e10cSrcweir     : m_xModel     (xModel)
478cdf0e10cSrcweir     , m_pData      (pData )
479cdf0e10cSrcweir     , m_pFramesLock(0     )
480cdf0e10cSrcweir {
481cdf0e10cSrcweir     static ::rtl::OUString MSG_1 = ::rtl::OUString::createFromAscii("Object already disposed."                                       );
482cdf0e10cSrcweir     static ::rtl::OUString MSG_2 = ::rtl::OUString::createFromAscii("Concurrent save requests on the same document are not possible.");
483cdf0e10cSrcweir 
484cdf0e10cSrcweir     if ( m_pData->m_bClosed )
485cdf0e10cSrcweir         throw ::com::sun::star::lang::DisposedException(
486cdf0e10cSrcweir                 MSG_1,
487cdf0e10cSrcweir                 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >());
488cdf0e10cSrcweir 
489cdf0e10cSrcweir     if (
490cdf0e10cSrcweir         bRejectConcurrentSaveRequest &&
491cdf0e10cSrcweir         m_pData->m_bSaving
492cdf0e10cSrcweir        )
493cdf0e10cSrcweir         throw ::com::sun::star::io::IOException(
494cdf0e10cSrcweir                 MSG_2,
495cdf0e10cSrcweir                 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >());
496cdf0e10cSrcweir 
497cdf0e10cSrcweir     m_pData->m_bSaving = sal_True;
498cdf0e10cSrcweir     m_pFramesLock = new SfxOwnFramesLocker(m_pData->m_pObjectShell);
499cdf0e10cSrcweir }
500cdf0e10cSrcweir 
~SfxSaveGuard()501cdf0e10cSrcweir SfxSaveGuard::~SfxSaveGuard()
502cdf0e10cSrcweir {
503cdf0e10cSrcweir     SfxOwnFramesLocker* pFramesLock = m_pFramesLock;
504cdf0e10cSrcweir     m_pFramesLock = 0;
505cdf0e10cSrcweir     delete pFramesLock;
506cdf0e10cSrcweir 
507cdf0e10cSrcweir     m_pData->m_bSaving = sal_False;
508cdf0e10cSrcweir 
509cdf0e10cSrcweir     // m_bSuicide was set e.g. in case somewhere tried to close a document, while it was used for
510cdf0e10cSrcweir     // storing at the same time. Further m_bSuicide was set to sal_True only if close(sal_True) was called.
511cdf0e10cSrcweir     // So the owner ship was delegated to the place where a veto exception was thrown.
512cdf0e10cSrcweir     // Now we have to call close() again and delegate the owner ship to the next one, which
513cdf0e10cSrcweir     // cant accept that. Close(sal_False) cant work in this case. Because then the document will may be never closed ...
514cdf0e10cSrcweir 
515cdf0e10cSrcweir     if ( m_pData->m_bSuicide )
516cdf0e10cSrcweir     {
517cdf0e10cSrcweir         // Reset this state. In case the new close() request is not accepted by somehwere else ...
518cdf0e10cSrcweir         // it's not a good idea to have two "owners" for close .-)
519cdf0e10cSrcweir         m_pData->m_bSuicide = sal_False;
520cdf0e10cSrcweir         try
521cdf0e10cSrcweir         {
522cdf0e10cSrcweir             uno::Reference< util::XCloseable > xClose(m_xModel, uno::UNO_QUERY);
523cdf0e10cSrcweir             if (xClose.is())
524cdf0e10cSrcweir                 xClose->close(sal_True);
525cdf0e10cSrcweir         }
526cdf0e10cSrcweir         catch(const util::CloseVetoException&)
527cdf0e10cSrcweir         {}
528cdf0e10cSrcweir     }
529cdf0e10cSrcweir }
530cdf0e10cSrcweir 
531cdf0e10cSrcweir // =======================================================================================================
532cdf0e10cSrcweir 
533cdf0e10cSrcweir //________________________________________________________________________________________________________
534cdf0e10cSrcweir //	constructor
535cdf0e10cSrcweir //________________________________________________________________________________________________________
DBG_NAME(sfx2_SfxBaseModel)536cdf0e10cSrcweir DBG_NAME(sfx2_SfxBaseModel)
537cdf0e10cSrcweir SfxBaseModel::SfxBaseModel( SfxObjectShell *pObjectShell )
538cdf0e10cSrcweir : BaseMutex()
539cdf0e10cSrcweir , m_pData( new IMPL_SfxBaseModel_DataContainer( m_aMutex, pObjectShell ) )
540cdf0e10cSrcweir , m_bSupportEmbeddedScripts( pObjectShell && pObjectShell->Get_Impl() ? !pObjectShell->Get_Impl()->m_bNoBasicCapabilities : false )
541cdf0e10cSrcweir , m_bSupportDocRecovery( pObjectShell && pObjectShell->Get_Impl() ? pObjectShell->Get_Impl()->m_bDocRecoverySupport : false )
542cdf0e10cSrcweir {
543cdf0e10cSrcweir     DBG_CTOR(sfx2_SfxBaseModel,NULL);
544cdf0e10cSrcweir 	if ( pObjectShell != NULL )
545cdf0e10cSrcweir 	{
546cdf0e10cSrcweir 		StartListening( *pObjectShell ) ;
547cdf0e10cSrcweir 	}
548cdf0e10cSrcweir }
549cdf0e10cSrcweir 
550cdf0e10cSrcweir //________________________________________________________________________________________________________
551cdf0e10cSrcweir //	destructor
552cdf0e10cSrcweir //________________________________________________________________________________________________________
553cdf0e10cSrcweir 
~SfxBaseModel()554cdf0e10cSrcweir SfxBaseModel::~SfxBaseModel()
555cdf0e10cSrcweir {
556cdf0e10cSrcweir     DBG_DTOR(sfx2_SfxBaseModel,NULL);
557cdf0e10cSrcweir }
558cdf0e10cSrcweir 
559cdf0e10cSrcweir //________________________________________________________________________________________________________
560cdf0e10cSrcweir //	XInterface
561cdf0e10cSrcweir //________________________________________________________________________________________________________
562cdf0e10cSrcweir 
queryInterface(const UNOTYPE & rType)563cdf0e10cSrcweir uno::Any SAL_CALL SfxBaseModel::queryInterface( const UNOTYPE& rType ) throw( uno::RuntimeException )
564cdf0e10cSrcweir {
565cdf0e10cSrcweir     if  (   ( !m_bSupportEmbeddedScripts && rType.equals( XEMBEDDEDSCRIPTS::static_type() ) )
566cdf0e10cSrcweir         ||  ( !m_bSupportDocRecovery && rType.equals( XDocumentRecovery::static_type() ) )
567cdf0e10cSrcweir         )
568cdf0e10cSrcweir         return Any();
569cdf0e10cSrcweir 
570cdf0e10cSrcweir     return SfxBaseModel_Base::queryInterface( rType );
571cdf0e10cSrcweir }
572cdf0e10cSrcweir 
573cdf0e10cSrcweir //________________________________________________________________________________________________________
574cdf0e10cSrcweir //	XInterface
575cdf0e10cSrcweir //________________________________________________________________________________________________________
576cdf0e10cSrcweir 
acquire()577cdf0e10cSrcweir void SAL_CALL SfxBaseModel::acquire() throw( )
578cdf0e10cSrcweir {
579cdf0e10cSrcweir 	// Attention:
580cdf0e10cSrcweir 	//	Don't use mutex or guard in this method!!! Is a method of XInterface.
581cdf0e10cSrcweir 
582cdf0e10cSrcweir 	// Forward to baseclass
583cdf0e10cSrcweir 	OWeakObject::acquire() ;
584cdf0e10cSrcweir }
585cdf0e10cSrcweir 
586cdf0e10cSrcweir //________________________________________________________________________________________________________
587cdf0e10cSrcweir //	XInterface
588cdf0e10cSrcweir //________________________________________________________________________________________________________
589cdf0e10cSrcweir 
release()590cdf0e10cSrcweir void SAL_CALL SfxBaseModel::release() throw( )
591cdf0e10cSrcweir {
592cdf0e10cSrcweir 	// Attention:
593cdf0e10cSrcweir 	//	Don't use mutex or guard in this method!!! Is a method of XInterface.
594cdf0e10cSrcweir 
595cdf0e10cSrcweir 	// Forward to baseclass
596cdf0e10cSrcweir 	OWeakObject::release() ;
597cdf0e10cSrcweir }
598cdf0e10cSrcweir 
599cdf0e10cSrcweir //________________________________________________________________________________________________________
600cdf0e10cSrcweir //	XTypeProvider
601cdf0e10cSrcweir //________________________________________________________________________________________________________
602cdf0e10cSrcweir 
603cdf0e10cSrcweir namespace
604cdf0e10cSrcweir {
lcl_stripType(Sequence<Type> & io_rTypes,const Type & i_rTypeToStrip)605cdf0e10cSrcweir     void lcl_stripType( Sequence< Type >& io_rTypes, const Type& i_rTypeToStrip )
606cdf0e10cSrcweir     {
607cdf0e10cSrcweir         Sequence< UNOTYPE > aStrippedTypes( io_rTypes.getLength() - 1 );
608cdf0e10cSrcweir         ::std::remove_copy_if(
609cdf0e10cSrcweir             io_rTypes.getConstArray(),
610cdf0e10cSrcweir             io_rTypes.getConstArray() + io_rTypes.getLength(),
611cdf0e10cSrcweir             aStrippedTypes.getArray(),
612cdf0e10cSrcweir             ::std::bind2nd( ::std::equal_to< Type >(), i_rTypeToStrip )
613cdf0e10cSrcweir         );
614cdf0e10cSrcweir         io_rTypes = aStrippedTypes;
615cdf0e10cSrcweir     }
616cdf0e10cSrcweir }
617cdf0e10cSrcweir 
getTypes()618cdf0e10cSrcweir uno::Sequence< UNOTYPE > SAL_CALL SfxBaseModel::getTypes() throw( uno::RuntimeException )
619cdf0e10cSrcweir {
620cdf0e10cSrcweir     uno::Sequence< UNOTYPE > aTypes( SfxBaseModel_Base::getTypes() );
621cdf0e10cSrcweir 
622cdf0e10cSrcweir     if ( !m_bSupportEmbeddedScripts )
623cdf0e10cSrcweir         lcl_stripType( aTypes, XEMBEDDEDSCRIPTS::static_type() );
624cdf0e10cSrcweir 
625cdf0e10cSrcweir     if ( !m_bSupportDocRecovery )
626cdf0e10cSrcweir         lcl_stripType( aTypes, XDocumentRecovery::static_type() );
627cdf0e10cSrcweir 
628cdf0e10cSrcweir 	return aTypes;
629cdf0e10cSrcweir }
630cdf0e10cSrcweir 
631cdf0e10cSrcweir //________________________________________________________________________________________________________
632cdf0e10cSrcweir //	XTypeProvider
633cdf0e10cSrcweir //________________________________________________________________________________________________________
634cdf0e10cSrcweir 
getImplementationId()635cdf0e10cSrcweir uno::Sequence< sal_Int8 > SAL_CALL SfxBaseModel::getImplementationId() throw( uno::RuntimeException )
636cdf0e10cSrcweir {
637cdf0e10cSrcweir 	// Create one Id for all instances of this class.
638cdf0e10cSrcweir 	// Use ethernet address to do this! (sal_True)
639cdf0e10cSrcweir 
640cdf0e10cSrcweir 	// Optimize this method
641cdf0e10cSrcweir 	// We initialize a static variable only one time. And we don't must use a mutex at every call!
642cdf0e10cSrcweir 	// For the first call; pID is NULL - for the second call pID is different from NULL!
643cdf0e10cSrcweir     static ::cppu::OImplementationId* pID = NULL ;
644cdf0e10cSrcweir 
645cdf0e10cSrcweir 	if ( pID == NULL )
646cdf0e10cSrcweir 	{
647cdf0e10cSrcweir 		// Ready for multithreading; get global mutex for first call of this method only! see before
648cdf0e10cSrcweir         ::osl::MutexGuard aGuard( MUTEX::getGlobalMutex() ) ;
649cdf0e10cSrcweir 
650cdf0e10cSrcweir 		// Control these pointer again ... it can be, that another instance will be faster then these!
651cdf0e10cSrcweir 		if ( pID == NULL )
652cdf0e10cSrcweir 		{
653cdf0e10cSrcweir 			// Create a new static ID ...
654cdf0e10cSrcweir             static ::cppu::OImplementationId aID( sal_False ) ;
655cdf0e10cSrcweir 			// ... and set his address to static pointer!
656cdf0e10cSrcweir 			pID = &aID ;
657cdf0e10cSrcweir 		}
658cdf0e10cSrcweir 	}
659cdf0e10cSrcweir 
660cdf0e10cSrcweir 	return pID->getImplementationId() ;
661cdf0e10cSrcweir }
662cdf0e10cSrcweir 
663cdf0e10cSrcweir //________________________________________________________________________________________________________
664cdf0e10cSrcweir //	XStarBasicAccess
665cdf0e10cSrcweir //________________________________________________________________________________________________________
666cdf0e10cSrcweir 
implGetStarBasicAccess(SfxObjectShell * pObjectShell)667cdf0e10cSrcweir uno::Reference< script::XStarBasicAccess > implGetStarBasicAccess( SfxObjectShell* pObjectShell )
668cdf0e10cSrcweir {
669cdf0e10cSrcweir     uno::Reference< script::XStarBasicAccess > xRet;
670cdf0e10cSrcweir 	if( pObjectShell )
671cdf0e10cSrcweir 	{
672cdf0e10cSrcweir 		BasicManager* pMgr = pObjectShell->GetBasicManager();
673cdf0e10cSrcweir 		xRet = getStarBasicAccess( pMgr );
674cdf0e10cSrcweir 	}
675cdf0e10cSrcweir 	return xRet;
676cdf0e10cSrcweir }
677cdf0e10cSrcweir 
getLibraryContainer()678cdf0e10cSrcweir uno::Reference< XNAMECONTAINER > SAL_CALL SfxBaseModel::getLibraryContainer() throw( uno::RuntimeException )
679cdf0e10cSrcweir {
680cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
681cdf0e10cSrcweir 
682cdf0e10cSrcweir     uno::Reference< script::XStarBasicAccess >& rxAccess = m_pData->m_xStarBasicAccess;
683cdf0e10cSrcweir 	if( !rxAccess.is() && m_pData->m_pObjectShell.Is() )
684cdf0e10cSrcweir 		rxAccess = implGetStarBasicAccess( m_pData->m_pObjectShell );
685cdf0e10cSrcweir 
686cdf0e10cSrcweir     uno::Reference< XNAMECONTAINER > xRet;
687cdf0e10cSrcweir 	if( rxAccess.is() )
688cdf0e10cSrcweir 		xRet = rxAccess->getLibraryContainer();
689cdf0e10cSrcweir 	return xRet;
690cdf0e10cSrcweir }
691cdf0e10cSrcweir 
692cdf0e10cSrcweir /**___________________________________________________________________________________________________
693cdf0e10cSrcweir 	@seealso	XStarBasicAccess
694cdf0e10cSrcweir */
createLibrary(const::rtl::OUString & LibName,const::rtl::OUString & Password,const::rtl::OUString & ExternalSourceURL,const::rtl::OUString & LinkTargetURL)695cdf0e10cSrcweir void SAL_CALL SfxBaseModel::createLibrary( const ::rtl::OUString& LibName, const ::rtl::OUString& Password,
696cdf0e10cSrcweir     const ::rtl::OUString& ExternalSourceURL, const ::rtl::OUString& LinkTargetURL )
697cdf0e10cSrcweir         throw(ELEMENTEXISTEXCEPTION, uno::RuntimeException)
698cdf0e10cSrcweir {
699cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
700cdf0e10cSrcweir 
701cdf0e10cSrcweir     uno::Reference< script::XStarBasicAccess >& rxAccess = m_pData->m_xStarBasicAccess;
702cdf0e10cSrcweir 	if( !rxAccess.is() && m_pData->m_pObjectShell.Is() )
703cdf0e10cSrcweir 		rxAccess = implGetStarBasicAccess( m_pData->m_pObjectShell );
704cdf0e10cSrcweir 
705cdf0e10cSrcweir 	if( rxAccess.is() )
706cdf0e10cSrcweir 		rxAccess->createLibrary( LibName, Password, ExternalSourceURL, LinkTargetURL );
707cdf0e10cSrcweir }
708cdf0e10cSrcweir 
709cdf0e10cSrcweir /**___________________________________________________________________________________________________
710cdf0e10cSrcweir 	@seealso	XStarBasicAccess
711cdf0e10cSrcweir */
addModule(const::rtl::OUString & LibraryName,const::rtl::OUString & ModuleName,const::rtl::OUString & Language,const::rtl::OUString & Source)712cdf0e10cSrcweir void SAL_CALL SfxBaseModel::addModule( const ::rtl::OUString& LibraryName, const ::rtl::OUString& ModuleName,
713cdf0e10cSrcweir     const ::rtl::OUString& Language, const ::rtl::OUString& Source )
714cdf0e10cSrcweir         throw( NOSUCHELEMENTEXCEPTION, uno::RuntimeException)
715cdf0e10cSrcweir {
716cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
717cdf0e10cSrcweir 
718cdf0e10cSrcweir     uno::Reference< script::XStarBasicAccess >& rxAccess = m_pData->m_xStarBasicAccess;
719cdf0e10cSrcweir 	if( !rxAccess.is() && m_pData->m_pObjectShell.Is() )
720cdf0e10cSrcweir 		rxAccess = implGetStarBasicAccess( m_pData->m_pObjectShell );
721cdf0e10cSrcweir 
722cdf0e10cSrcweir 	if( rxAccess.is() )
723cdf0e10cSrcweir 		rxAccess->addModule( LibraryName, ModuleName, Language, Source );
724cdf0e10cSrcweir }
725cdf0e10cSrcweir 
726cdf0e10cSrcweir /**___________________________________________________________________________________________________
727cdf0e10cSrcweir 	@seealso	XStarBasicAccess
728cdf0e10cSrcweir */
addDialog(const::rtl::OUString & LibraryName,const::rtl::OUString & DialogName,const::com::sun::star::uno::Sequence<sal_Int8> & Data)729cdf0e10cSrcweir void SAL_CALL SfxBaseModel::addDialog( const ::rtl::OUString& LibraryName, const ::rtl::OUString& DialogName,
730cdf0e10cSrcweir 	const ::com::sun::star::uno::Sequence< sal_Int8 >& Data )
731cdf0e10cSrcweir         throw(NOSUCHELEMENTEXCEPTION, uno::RuntimeException)
732cdf0e10cSrcweir {
733cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
734cdf0e10cSrcweir 
735cdf0e10cSrcweir     uno::Reference< script::XStarBasicAccess >& rxAccess = m_pData->m_xStarBasicAccess;
736cdf0e10cSrcweir 	if( !rxAccess.is() && m_pData->m_pObjectShell.Is() )
737cdf0e10cSrcweir 		rxAccess = implGetStarBasicAccess( m_pData->m_pObjectShell );
738cdf0e10cSrcweir 
739cdf0e10cSrcweir 	if( rxAccess.is() )
740cdf0e10cSrcweir 		rxAccess->addDialog( LibraryName, DialogName, Data );
741cdf0e10cSrcweir }
742cdf0e10cSrcweir 
743cdf0e10cSrcweir 
744cdf0e10cSrcweir //________________________________________________________________________________________________________
745cdf0e10cSrcweir //	XChild
746cdf0e10cSrcweir //________________________________________________________________________________________________________
747cdf0e10cSrcweir 
getParent()748cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL SfxBaseModel::getParent() throw( uno::RuntimeException )
749cdf0e10cSrcweir {
750cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
751cdf0e10cSrcweir 
752cdf0e10cSrcweir 	return m_pData->m_xParent;
753cdf0e10cSrcweir }
754cdf0e10cSrcweir 
755cdf0e10cSrcweir //________________________________________________________________________________________________________
756cdf0e10cSrcweir //	XChild
757cdf0e10cSrcweir //________________________________________________________________________________________________________
758cdf0e10cSrcweir 
setParent(const uno::Reference<uno::XInterface> & Parent)759cdf0e10cSrcweir void SAL_CALL SfxBaseModel::setParent(const uno::Reference< uno::XInterface >& Parent) throw(NOSUPPORTEXCEPTION, uno::RuntimeException)
760cdf0e10cSrcweir {
761cdf0e10cSrcweir     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
762cdf0e10cSrcweir 	m_pData->m_xParent = Parent;
763cdf0e10cSrcweir }
764cdf0e10cSrcweir 
765cdf0e10cSrcweir //________________________________________________________________________________________________________
766cdf0e10cSrcweir //	XChild
767cdf0e10cSrcweir //________________________________________________________________________________________________________
768cdf0e10cSrcweir 
dispose()769cdf0e10cSrcweir void SAL_CALL SfxBaseModel::dispose() throw(::com::sun::star::uno::RuntimeException)
770cdf0e10cSrcweir {
771cdf0e10cSrcweir     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
772cdf0e10cSrcweir 
773cdf0e10cSrcweir 	if  ( !m_pData->m_bClosed )
774cdf0e10cSrcweir 	{
775cdf0e10cSrcweir 		// gracefully accept wrong dispose calls instead of close call
776cdf0e10cSrcweir 		// and try to make it work (may be really disposed later!)
777cdf0e10cSrcweir 		try
778cdf0e10cSrcweir 		{
779cdf0e10cSrcweir 			close( sal_True );
780cdf0e10cSrcweir 		}
781cdf0e10cSrcweir 		catch ( com::sun::star::util::CloseVetoException& )
782cdf0e10cSrcweir 		{
783cdf0e10cSrcweir 		}
784cdf0e10cSrcweir 
785cdf0e10cSrcweir 		return;
786cdf0e10cSrcweir 	}
787cdf0e10cSrcweir 
788cdf0e10cSrcweir 	if ( m_pData->m_pStorageModifyListen.is() )
789cdf0e10cSrcweir 	{
790cdf0e10cSrcweir 		m_pData->m_pStorageModifyListen->dispose();
791cdf0e10cSrcweir 		m_pData->m_pStorageModifyListen = NULL;
792cdf0e10cSrcweir 	}
793cdf0e10cSrcweir 
794cdf0e10cSrcweir     if ( m_pData->m_pDocumentUndoManager.is() )
795cdf0e10cSrcweir 	{
796cdf0e10cSrcweir 		m_pData->m_pDocumentUndoManager->disposing();
797cdf0e10cSrcweir 		m_pData->m_pDocumentUndoManager = NULL;
798cdf0e10cSrcweir 	}
799cdf0e10cSrcweir 
800cdf0e10cSrcweir     lang::EventObject aEvent( (frame::XModel *)this );
801cdf0e10cSrcweir 	m_pData->m_aInterfaceContainer.disposeAndClear( aEvent );
802cdf0e10cSrcweir 
803cdf0e10cSrcweir     if ( m_pData->m_xDocumentInfo.is() )
804cdf0e10cSrcweir     {
805cdf0e10cSrcweir         // as long as an SfxObjectShell is assigned to an SfxBaseModel it is still existing here
806cdf0e10cSrcweir         // so we can't dispose the shared DocumentInfoObject here
807cdf0e10cSrcweir         // uno::Reference < lang::XComponent > xComp( m_pData->m_xDocumentInfo, uno::UNO_QUERY );
808cdf0e10cSrcweir         // xComp->dispose();
809cdf0e10cSrcweir         m_pData->m_xDocumentInfo = 0;
810cdf0e10cSrcweir     }
811cdf0e10cSrcweir 
812cdf0e10cSrcweir     m_pData->m_xDocumentProperties.clear();
813cdf0e10cSrcweir 
814cdf0e10cSrcweir     m_pData->m_xDocumentMetadata.clear();
815cdf0e10cSrcweir 
816cdf0e10cSrcweir     EndListening( *m_pData->m_pObjectShell );
817cdf0e10cSrcweir 
818cdf0e10cSrcweir     m_pData->m_xCurrent = uno::Reference< frame::XController > ();
819cdf0e10cSrcweir     m_pData->m_seqControllers = uno::Sequence< uno::Reference< frame::XController > > () ;
820cdf0e10cSrcweir 
821cdf0e10cSrcweir     // m_pData member must be set to zero before 0delete is called to
822cdf0e10cSrcweir     // force disposed exception whenever someone tries to access our
823cdf0e10cSrcweir     // instance while in the dtor.
824cdf0e10cSrcweir     IMPL_SfxBaseModel_DataContainer* pData = m_pData;
825cdf0e10cSrcweir     m_pData = 0;
826cdf0e10cSrcweir     delete pData;
827cdf0e10cSrcweir }
828cdf0e10cSrcweir 
829cdf0e10cSrcweir //________________________________________________________________________________________________________
830cdf0e10cSrcweir //	XChild
831cdf0e10cSrcweir //________________________________________________________________________________________________________
832cdf0e10cSrcweir 
addEventListener(const uno::Reference<XEVENTLISTENER> & aListener)833cdf0e10cSrcweir void SAL_CALL SfxBaseModel::addEventListener( const uno::Reference< XEVENTLISTENER >& aListener )
834cdf0e10cSrcweir     throw(::com::sun::star::uno::RuntimeException)
835cdf0e10cSrcweir {
836cdf0e10cSrcweir     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
837cdf0e10cSrcweir     m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< XEVENTLISTENER >*)0), aListener );
838cdf0e10cSrcweir }
839cdf0e10cSrcweir 
840cdf0e10cSrcweir //________________________________________________________________________________________________________
841cdf0e10cSrcweir //	XChild
842cdf0e10cSrcweir //________________________________________________________________________________________________________
843cdf0e10cSrcweir 
removeEventListener(const uno::Reference<XEVENTLISTENER> & aListener)844cdf0e10cSrcweir void SAL_CALL SfxBaseModel::removeEventListener( const uno::Reference< XEVENTLISTENER >& aListener )
845cdf0e10cSrcweir     throw(::com::sun::star::uno::RuntimeException)
846cdf0e10cSrcweir {
847cdf0e10cSrcweir     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
848cdf0e10cSrcweir     m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XEVENTLISTENER >*)0), aListener );
849cdf0e10cSrcweir }
850cdf0e10cSrcweir 
851cdf0e10cSrcweir //________________________________________________________________________________________________________
852cdf0e10cSrcweir //  document::XDocumentInfoSupplier
853cdf0e10cSrcweir //________________________________________________________________________________________________________
854cdf0e10cSrcweir 
getDocumentInfo()855cdf0e10cSrcweir uno::Reference< document::XDocumentInfo > SAL_CALL SfxBaseModel::getDocumentInfo() throw(::com::sun::star::uno::RuntimeException)
856cdf0e10cSrcweir {
857cdf0e10cSrcweir     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
858cdf0e10cSrcweir     if ( !m_pData->m_xDocumentInfo.is() )
859cdf0e10cSrcweir     {
860cdf0e10cSrcweir         // WARNING: this will only work if (when loading a document) the
861cdf0e10cSrcweir         // document meta-data has already been read and completely written
862cdf0e10cSrcweir         // into the XDocumentProperties at this point
863cdf0e10cSrcweir         // ==> DO NOT call getDocumentInfo before document info has been read!
864cdf0e10cSrcweir         uno::Reference< document::XDocumentInfo > xDocInfo =
865cdf0e10cSrcweir             new SfxDocumentInfoObject;
866cdf0e10cSrcweir         uno::Reference< document::XDocumentProperties > xDocProps =
867cdf0e10cSrcweir             getDocumentProperties();
868cdf0e10cSrcweir         uno::Sequence< uno::Any > args(1);
869cdf0e10cSrcweir         args[0] <<= xDocProps;
870cdf0e10cSrcweir         uno::Reference< lang::XInitialization > xInit(
871cdf0e10cSrcweir             xDocInfo, uno::UNO_QUERY_THROW);
872cdf0e10cSrcweir         try {
873cdf0e10cSrcweir             xInit->initialize(args);
874cdf0e10cSrcweir             ((SfxBaseModel*)this)->m_pData->m_xDocumentInfo = xDocInfo;
875cdf0e10cSrcweir         } catch (uno::RuntimeException &) {
876cdf0e10cSrcweir             throw;
877cdf0e10cSrcweir         } catch (uno::Exception & e) {
878cdf0e10cSrcweir             throw lang::WrappedTargetRuntimeException(::rtl::OUString::createFromAscii(
879cdf0e10cSrcweir                 "SfxBaseModel::getDocumentInfo: cannot initialize"), *this,
880cdf0e10cSrcweir                 uno::makeAny(e));
881cdf0e10cSrcweir         }
882cdf0e10cSrcweir         try {
883cdf0e10cSrcweir             rtl::OUString aName = rtl::OUString::createFromAscii("MediaType");
884cdf0e10cSrcweir             uno::Reference < beans::XPropertySet > xSet(
885cdf0e10cSrcweir                 getDocumentStorage(), uno::UNO_QUERY );
886cdf0e10cSrcweir             uno::Any aMediaType = xSet->getPropertyValue( aName );
887cdf0e10cSrcweir             uno::Reference < beans::XPropertySet > xDocSet(
888cdf0e10cSrcweir                 m_pData->m_xDocumentInfo, uno::UNO_QUERY );
889cdf0e10cSrcweir             xDocSet->setPropertyValue( aName, aMediaType );
890cdf0e10cSrcweir         } catch (uno::Exception &) {
891cdf0e10cSrcweir             //ignore
892cdf0e10cSrcweir         }
893cdf0e10cSrcweir     }
894cdf0e10cSrcweir 
895cdf0e10cSrcweir 	return m_pData->m_xDocumentInfo;
896cdf0e10cSrcweir }
897cdf0e10cSrcweir 
898cdf0e10cSrcweir // document::XDocumentPropertiesSupplier:
899cdf0e10cSrcweir uno::Reference< document::XDocumentProperties > SAL_CALL
getDocumentProperties()900cdf0e10cSrcweir SfxBaseModel::getDocumentProperties()
901cdf0e10cSrcweir     throw(::com::sun::star::uno::RuntimeException)
902cdf0e10cSrcweir {
903cdf0e10cSrcweir     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
904cdf0e10cSrcweir     if ( !m_pData->m_xDocumentProperties.is() )
905cdf0e10cSrcweir     {
906cdf0e10cSrcweir         uno::Reference< lang::XInitialization > xDocProps(
907cdf0e10cSrcweir             ::comphelper::getProcessServiceFactory()->createInstance(
908cdf0e10cSrcweir                 DEFINE_CONST_UNICODE("com.sun.star.document.DocumentProperties") ),
909cdf0e10cSrcweir             uno::UNO_QUERY_THROW);
910cdf0e10cSrcweir //        xDocProps->initialize(uno::Sequence<uno::Any>());
911cdf0e10cSrcweir         m_pData->m_xDocumentProperties.set(xDocProps, uno::UNO_QUERY_THROW);
912cdf0e10cSrcweir         uno::Reference<util::XModifyBroadcaster> xMB(m_pData->m_xDocumentProperties, uno::UNO_QUERY_THROW);
913cdf0e10cSrcweir         xMB->addModifyListener(new SfxDocInfoListener_Impl(*m_pData->m_pObjectShell));
914cdf0e10cSrcweir     }
915cdf0e10cSrcweir 
916cdf0e10cSrcweir 	return m_pData->m_xDocumentProperties;
917cdf0e10cSrcweir }
918cdf0e10cSrcweir 
919cdf0e10cSrcweir 
920cdf0e10cSrcweir //________________________________________________________________________________________________________
921cdf0e10cSrcweir //	XEVENTLISTENER
922cdf0e10cSrcweir //________________________________________________________________________________________________________
923cdf0e10cSrcweir 
disposing(const lang::EventObject & aObject)924cdf0e10cSrcweir void SAL_CALL SfxBaseModel::disposing( const lang::EventObject& aObject )
925cdf0e10cSrcweir     throw(::com::sun::star::uno::RuntimeException)
926cdf0e10cSrcweir {
927cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
928cdf0e10cSrcweir 	if ( impl_isDisposed() )
929cdf0e10cSrcweir 		return;
930cdf0e10cSrcweir 
931cdf0e10cSrcweir     uno::Reference< XMODIFYLISTENER >  xMod( aObject.Source, uno::UNO_QUERY );
932cdf0e10cSrcweir     uno::Reference< XEVENTLISTENER >  xListener( aObject.Source, uno::UNO_QUERY );
933cdf0e10cSrcweir     uno::Reference< XDOCEVENTLISTENER >  xDocListener( aObject.Source, uno::UNO_QUERY );
934cdf0e10cSrcweir 
935cdf0e10cSrcweir     if ( xMod.is() )
936cdf0e10cSrcweir         m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XMODIFYLISTENER >*)0), xMod );
937cdf0e10cSrcweir     else if ( xListener.is() )
938cdf0e10cSrcweir         m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XEVENTLISTENER >*)0), xListener );
939cdf0e10cSrcweir     else if ( xDocListener.is() )
940*e4c033a6SBidouille         m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0), xDocListener );
941cdf0e10cSrcweir }
942cdf0e10cSrcweir 
943cdf0e10cSrcweir //________________________________________________________________________________________________________
944cdf0e10cSrcweir //  frame::XModel
945cdf0e10cSrcweir //________________________________________________________________________________________________________
946cdf0e10cSrcweir 
attachResource(const::rtl::OUString & rURL,const uno::Sequence<beans::PropertyValue> & rArgs)947cdf0e10cSrcweir sal_Bool SAL_CALL SfxBaseModel::attachResource( const   ::rtl::OUString&                   rURL    ,
948cdf0e10cSrcweir                                                 const   uno::Sequence< beans::PropertyValue >&  rArgs   )
949cdf0e10cSrcweir     throw(::com::sun::star::uno::RuntimeException)
950cdf0e10cSrcweir {
951cdf0e10cSrcweir     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
952cdf0e10cSrcweir 	if ( rURL.getLength() == 0 && rArgs.getLength() == 1 && rArgs[0].Name.equalsAscii( "SetEmbedded" ) )
953cdf0e10cSrcweir 	{
954cdf0e10cSrcweir 		// allows to set a windowless document to EMBEDDED state
955cdf0e10cSrcweir 		// but _only_ before load() or initNew() methods
956cdf0e10cSrcweir 		if ( m_pData->m_pObjectShell.Is() && !m_pData->m_pObjectShell->GetMedium() )
957cdf0e10cSrcweir 		{
958cdf0e10cSrcweir 			sal_Bool bEmb = sal_Bool();
959cdf0e10cSrcweir 			if ( ( rArgs[0].Value >>= bEmb ) && bEmb )
960cdf0e10cSrcweir 				m_pData->m_pObjectShell->SetCreateMode_Impl( SFX_CREATE_MODE_EMBEDDED );
961cdf0e10cSrcweir 		}
962cdf0e10cSrcweir 
963cdf0e10cSrcweir 		return sal_True;
964cdf0e10cSrcweir 	}
965cdf0e10cSrcweir 
966cdf0e10cSrcweir 	if ( m_pData->m_pObjectShell.Is() )
967cdf0e10cSrcweir 	{
968cdf0e10cSrcweir 		m_pData->m_sURL = rURL;
969cdf0e10cSrcweir 
970cdf0e10cSrcweir         SfxObjectShell* pObjectShell = m_pData->m_pObjectShell;
971cdf0e10cSrcweir 
972cdf0e10cSrcweir         ::comphelper::NamedValueCollection aArgs( rArgs );
973cdf0e10cSrcweir 
974cdf0e10cSrcweir         Sequence< sal_Int32 > aWinExtent;
975cdf0e10cSrcweir         if ( ( aArgs.get( "WinExtent" ) >>= aWinExtent )&& ( aWinExtent.getLength() == 4 ) )
976cdf0e10cSrcweir         {
977cdf0e10cSrcweir             Rectangle aVisArea( aWinExtent[0], aWinExtent[1], aWinExtent[2], aWinExtent[3] );
978cdf0e10cSrcweir             aVisArea = OutputDevice::LogicToLogic( aVisArea, MAP_100TH_MM, pObjectShell->GetMapUnit() );
979cdf0e10cSrcweir             pObjectShell->SetVisArea( aVisArea );
980cdf0e10cSrcweir         }
981cdf0e10cSrcweir 
982cdf0e10cSrcweir 		sal_Bool bBreakMacroSign = sal_False;
983cdf0e10cSrcweir         if ( aArgs.get( "BreakMacroSignature" ) >>= bBreakMacroSign )
984cdf0e10cSrcweir 		{
985cdf0e10cSrcweir 			pObjectShell->BreakMacroSign_Impl( bBreakMacroSign );
986cdf0e10cSrcweir 		}
987cdf0e10cSrcweir 
988cdf0e10cSrcweir         aArgs.remove( "WinExtent" );
989cdf0e10cSrcweir         aArgs.remove( "BreakMacroSignature" );
990cdf0e10cSrcweir         aArgs.remove( "Stream" );
991cdf0e10cSrcweir         aArgs.remove( "InputStream" );
992cdf0e10cSrcweir         aArgs.remove( "URL" );
993cdf0e10cSrcweir         aArgs.remove( "Frame" );
994cdf0e10cSrcweir         aArgs.remove( "Password" );
995cdf0e10cSrcweir         aArgs.remove( "EncryptionData" );
996cdf0e10cSrcweir 
997cdf0e10cSrcweir 		// TODO/LATER: all the parameters that are accepted by ItemSet of the DocShell must be removed here
998cdf0e10cSrcweir 
999cdf0e10cSrcweir 		m_pData->m_seqArguments = aArgs.getPropertyValues();
1000cdf0e10cSrcweir 
1001cdf0e10cSrcweir         SfxMedium* pMedium = pObjectShell->GetMedium();
1002cdf0e10cSrcweir 		if ( pMedium )
1003cdf0e10cSrcweir 		{
1004cdf0e10cSrcweir 			SfxAllItemSet aSet( pObjectShell->GetPool() );
1005cdf0e10cSrcweir 			TransformParameters( SID_OPENDOC, rArgs, aSet );
1006cdf0e10cSrcweir 
1007cdf0e10cSrcweir             // the arguments are not allowed to reach the medium
1008cdf0e10cSrcweir             aSet.ClearItem( SID_FILE_NAME );
1009cdf0e10cSrcweir             aSet.ClearItem( SID_FILLFRAME );
1010cdf0e10cSrcweir 
1011cdf0e10cSrcweir 			pMedium->GetItemSet()->Put( aSet );
1012cdf0e10cSrcweir 			SFX_ITEMSET_ARG( &aSet, pItem, SfxStringItem, SID_FILTER_NAME, sal_False );
1013cdf0e10cSrcweir 			if ( pItem )
1014cdf0e10cSrcweir 				pMedium->SetFilter(
1015cdf0e10cSrcweir 					pObjectShell->GetFactory().GetFilterContainer()->GetFilter4FilterName( pItem->GetValue() ) );
1016cdf0e10cSrcweir 
1017cdf0e10cSrcweir 			SFX_ITEMSET_ARG( &aSet, pTitleItem, SfxStringItem, SID_DOCINFO_TITLE, sal_False );
1018cdf0e10cSrcweir 			if ( pTitleItem )
1019cdf0e10cSrcweir 			{
1020cdf0e10cSrcweir 				SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pObjectShell );
1021cdf0e10cSrcweir 				if ( pFrame )
1022cdf0e10cSrcweir 					pFrame->UpdateTitle();
1023cdf0e10cSrcweir 			}
1024cdf0e10cSrcweir 		}
1025cdf0e10cSrcweir 	}
1026cdf0e10cSrcweir 
1027cdf0e10cSrcweir 	return sal_True ;
1028cdf0e10cSrcweir }
1029cdf0e10cSrcweir 
1030cdf0e10cSrcweir //________________________________________________________________________________________________________
1031cdf0e10cSrcweir //  frame::XModel
1032cdf0e10cSrcweir //________________________________________________________________________________________________________
1033cdf0e10cSrcweir 
getURL()1034cdf0e10cSrcweir ::rtl::OUString SAL_CALL SfxBaseModel::getURL() throw(::com::sun::star::uno::RuntimeException)
1035cdf0e10cSrcweir {
1036cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1037cdf0e10cSrcweir 	return m_pData->m_sURL ;
1038cdf0e10cSrcweir }
1039cdf0e10cSrcweir 
1040cdf0e10cSrcweir //________________________________________________________________________________________________________
1041cdf0e10cSrcweir //  frame::XModel
1042cdf0e10cSrcweir //________________________________________________________________________________________________________
1043cdf0e10cSrcweir 
getArgs()1044cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > SAL_CALL SfxBaseModel::getArgs() throw(::com::sun::star::uno::RuntimeException)
1045cdf0e10cSrcweir {
1046cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1047cdf0e10cSrcweir 	if ( m_pData->m_pObjectShell.Is() )
1048cdf0e10cSrcweir 	{
1049cdf0e10cSrcweir         uno::Sequence< beans::PropertyValue > seqArgsNew;
1050cdf0e10cSrcweir         uno::Sequence< beans::PropertyValue > seqArgsOld;
1051cdf0e10cSrcweir 		SfxAllItemSet aSet( m_pData->m_pObjectShell->GetPool() );
1052cdf0e10cSrcweir 
1053cdf0e10cSrcweir 		// we need to know which properties are supported by the transformer
1054cdf0e10cSrcweir 		// hopefully it is a temporary solution, I guess nonconvertable properties
1055cdf0e10cSrcweir 		// should not be supported so then there will be only ItemSet from medium
1056cdf0e10cSrcweir 
1057cdf0e10cSrcweir 		TransformItems( SID_OPENDOC, *(m_pData->m_pObjectShell->GetMedium()->GetItemSet()), seqArgsNew );
1058cdf0e10cSrcweir 		TransformParameters( SID_OPENDOC, m_pData->m_seqArguments, aSet );
1059cdf0e10cSrcweir 		TransformItems( SID_OPENDOC, aSet, seqArgsOld );
1060cdf0e10cSrcweir 
1061cdf0e10cSrcweir 		sal_Int32 nOrgLength = m_pData->m_seqArguments.getLength();
1062cdf0e10cSrcweir 		sal_Int32 nOldLength = seqArgsOld.getLength();
1063cdf0e10cSrcweir 		sal_Int32 nNewLength = seqArgsNew.getLength();
1064cdf0e10cSrcweir 
1065cdf0e10cSrcweir 		// "WinExtent" property should be updated always.
1066cdf0e10cSrcweir 		// We can store it now to overwrite an old value
1067cdf0e10cSrcweir 		// since it is not from ItemSet
1068cdf0e10cSrcweir         Rectangle aTmpRect = m_pData->m_pObjectShell->GetVisArea( ASPECT_CONTENT );
1069cdf0e10cSrcweir         aTmpRect = OutputDevice::LogicToLogic( aTmpRect, m_pData->m_pObjectShell->GetMapUnit(), MAP_100TH_MM );
1070cdf0e10cSrcweir 
1071cdf0e10cSrcweir         Sequence< sal_Int32 > aRectSeq(4);
1072cdf0e10cSrcweir         aRectSeq[0] = aTmpRect.Left();
1073cdf0e10cSrcweir         aRectSeq[1] = aTmpRect.Top();
1074cdf0e10cSrcweir         aRectSeq[2] = aTmpRect.Right();
1075cdf0e10cSrcweir         aRectSeq[3] = aTmpRect.Bottom();
1076cdf0e10cSrcweir 
1077cdf0e10cSrcweir         seqArgsNew.realloc( ++nNewLength );
1078cdf0e10cSrcweir         seqArgsNew[ nNewLength - 1 ].Name = ::rtl::OUString::createFromAscii( "WinExtent" );
1079cdf0e10cSrcweir         seqArgsNew[ nNewLength - 1 ].Value <<= aRectSeq;
1080cdf0e10cSrcweir 
1081cdf0e10cSrcweir 		if ( m_pData->m_aPreusedFilterName.getLength() )
1082cdf0e10cSrcweir 		{
1083cdf0e10cSrcweir 			seqArgsNew.realloc( ++nNewLength );
1084cdf0e10cSrcweir 			seqArgsNew[ nNewLength - 1 ].Name = ::rtl::OUString::createFromAscii( "PreusedFilterName" );
1085cdf0e10cSrcweir 			seqArgsNew[ nNewLength - 1 ].Value <<= m_pData->m_aPreusedFilterName;
1086cdf0e10cSrcweir 		}
1087cdf0e10cSrcweir 
1088cdf0e10cSrcweir         SfxViewFrame* pFrame = SfxViewFrame::GetFirst( m_pData->m_pObjectShell );
1089cdf0e10cSrcweir         if ( pFrame )
1090cdf0e10cSrcweir         {
1091cdf0e10cSrcweir             SvBorder aBorder = pFrame->GetBorderPixelImpl( pFrame->GetViewShell() );
1092cdf0e10cSrcweir 
1093cdf0e10cSrcweir 			Sequence< sal_Int32 > aBorderSeq(4);
1094cdf0e10cSrcweir             aBorderSeq[0] = aBorder.Left();
1095cdf0e10cSrcweir             aBorderSeq[1] = aBorder.Top();
1096cdf0e10cSrcweir             aBorderSeq[2] = aBorder.Right();
1097cdf0e10cSrcweir             aBorderSeq[3] = aBorder.Bottom();
1098cdf0e10cSrcweir 
1099cdf0e10cSrcweir 			seqArgsNew.realloc( ++nNewLength );
1100cdf0e10cSrcweir             seqArgsNew[ nNewLength - 1 ].Name = ::rtl::OUString::createFromAscii( "DocumentBorder" );
1101cdf0e10cSrcweir 			seqArgsNew[ nNewLength - 1 ].Value <<= aBorderSeq;
1102cdf0e10cSrcweir 		}
1103cdf0e10cSrcweir 
1104cdf0e10cSrcweir 		// only the values that are not supported by the ItemSet must be cached here
1105cdf0e10cSrcweir 		uno::Sequence< beans::PropertyValue > aFinalCache;
1106cdf0e10cSrcweir 		sal_Int32 nFinalLength = 0;
1107cdf0e10cSrcweir 
1108cdf0e10cSrcweir 		for ( sal_Int32 nOrg = 0; nOrg < nOrgLength; nOrg++ )
1109cdf0e10cSrcweir 		{
1110cdf0e10cSrcweir  			sal_Int32 nOldInd = 0;
1111cdf0e10cSrcweir 			while ( nOldInd < nOldLength )
1112cdf0e10cSrcweir 			{
1113cdf0e10cSrcweir 				if ( m_pData->m_seqArguments[nOrg].Name.equals( seqArgsOld[nOldInd].Name ) )
1114cdf0e10cSrcweir 					break;
1115cdf0e10cSrcweir 				nOldInd++;
1116cdf0e10cSrcweir 			}
1117cdf0e10cSrcweir 
1118cdf0e10cSrcweir 			if ( nOldInd == nOldLength )
1119cdf0e10cSrcweir 			{
1120cdf0e10cSrcweir 				// the entity with this name should be new for seqArgsNew
1121cdf0e10cSrcweir 				// since it is not supported by transformer
1122cdf0e10cSrcweir 
1123cdf0e10cSrcweir 				seqArgsNew.realloc( ++nNewLength );
1124cdf0e10cSrcweir 				seqArgsNew[ nNewLength - 1 ] = m_pData->m_seqArguments[nOrg];
1125cdf0e10cSrcweir 
1126cdf0e10cSrcweir 				aFinalCache.realloc( ++nFinalLength );
1127cdf0e10cSrcweir 				aFinalCache[ nFinalLength - 1 ] = m_pData->m_seqArguments[nOrg];
1128cdf0e10cSrcweir 			}
1129cdf0e10cSrcweir 		}
1130cdf0e10cSrcweir 
1131cdf0e10cSrcweir 		m_pData->m_seqArguments = aFinalCache;
1132cdf0e10cSrcweir 
1133cdf0e10cSrcweir 		return seqArgsNew;
1134cdf0e10cSrcweir 	}
1135cdf0e10cSrcweir 
1136cdf0e10cSrcweir 	return m_pData->m_seqArguments;
1137cdf0e10cSrcweir }
1138cdf0e10cSrcweir 
1139cdf0e10cSrcweir //________________________________________________________________________________________________________
1140cdf0e10cSrcweir //  frame::XModel
1141cdf0e10cSrcweir //________________________________________________________________________________________________________
1142cdf0e10cSrcweir 
connectController(const uno::Reference<frame::XController> & xController)1143cdf0e10cSrcweir void SAL_CALL SfxBaseModel::connectController( const uno::Reference< frame::XController >& xController )
1144cdf0e10cSrcweir     throw(::com::sun::star::uno::RuntimeException)
1145cdf0e10cSrcweir {
1146cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1147cdf0e10cSrcweir     OSL_PRECOND( xController.is(), "SfxBaseModel::connectController: invalid controller!" );
1148cdf0e10cSrcweir     if ( !xController.is() )
1149cdf0e10cSrcweir         return;
1150cdf0e10cSrcweir 
1151cdf0e10cSrcweir 	sal_uInt32 nOldCount = m_pData->m_seqControllers.getLength();
1152cdf0e10cSrcweir     uno::Sequence< uno::Reference< frame::XController > > aNewSeq( nOldCount + 1 );
1153cdf0e10cSrcweir 	for ( sal_uInt32 n = 0; n < nOldCount; n++ )
1154cdf0e10cSrcweir 		aNewSeq.getArray()[n] = m_pData->m_seqControllers.getConstArray()[n];
1155cdf0e10cSrcweir 	aNewSeq.getArray()[nOldCount] = xController;
1156cdf0e10cSrcweir 	m_pData->m_seqControllers = aNewSeq;
1157cdf0e10cSrcweir 
1158cdf0e10cSrcweir     if ( m_pData->m_seqControllers.getLength() == 1 )
1159cdf0e10cSrcweir     {
1160cdf0e10cSrcweir         SfxViewFrame* pViewFrame = SfxViewFrame::Get( xController, GetObjectShell() );
1161cdf0e10cSrcweir         ENSURE_OR_THROW( pViewFrame, "SFX document without SFX view!?" );
1162cdf0e10cSrcweir         pViewFrame->UpdateDocument_Impl();
1163cdf0e10cSrcweir 	    const String sDocumentURL = GetObjectShell()->GetMedium()->GetName();
1164cdf0e10cSrcweir         if ( sDocumentURL.Len() )
1165cdf0e10cSrcweir 	        SFX_APP()->Broadcast( SfxStringHint( SID_OPENURL, sDocumentURL ) );
1166cdf0e10cSrcweir     }
1167cdf0e10cSrcweir }
1168cdf0e10cSrcweir 
1169cdf0e10cSrcweir //________________________________________________________________________________________________________
1170cdf0e10cSrcweir //  frame::XModel
1171cdf0e10cSrcweir //________________________________________________________________________________________________________
1172cdf0e10cSrcweir 
disconnectController(const uno::Reference<frame::XController> & xController)1173cdf0e10cSrcweir void SAL_CALL SfxBaseModel::disconnectController( const uno::Reference< frame::XController >& xController ) throw(::com::sun::star::uno::RuntimeException)
1174cdf0e10cSrcweir {
1175cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1176cdf0e10cSrcweir 
1177cdf0e10cSrcweir     sal_uInt32 nOldCount = m_pData->m_seqControllers.getLength();
1178cdf0e10cSrcweir     if ( !nOldCount )
1179cdf0e10cSrcweir         return;
1180cdf0e10cSrcweir 
1181cdf0e10cSrcweir     uno::Sequence< uno::Reference< frame::XController > > aNewSeq( nOldCount - 1 );
1182cdf0e10cSrcweir 	for ( sal_uInt32 nOld = 0, nNew = 0; nOld < nOldCount; ++nOld )
1183cdf0e10cSrcweir     {
1184cdf0e10cSrcweir 		if ( xController != m_pData->m_seqControllers.getConstArray()[nOld] )
1185cdf0e10cSrcweir 		{
1186cdf0e10cSrcweir 			aNewSeq.getArray()[nNew] = m_pData->m_seqControllers.getConstArray()[nOld];
1187cdf0e10cSrcweir 			++nNew;
1188cdf0e10cSrcweir 		}
1189cdf0e10cSrcweir     }
1190cdf0e10cSrcweir 
1191cdf0e10cSrcweir 	m_pData->m_seqControllers = aNewSeq;
1192cdf0e10cSrcweir 
1193cdf0e10cSrcweir 	if ( xController == m_pData->m_xCurrent )
1194cdf0e10cSrcweir         m_pData->m_xCurrent = uno::Reference< frame::XController > ();
1195cdf0e10cSrcweir }
1196cdf0e10cSrcweir 
1197cdf0e10cSrcweir namespace
1198cdf0e10cSrcweir {
1199cdf0e10cSrcweir     typedef ::cppu::WeakImplHelper1< XUndoAction > ControllerLockUndoAction_Base;
1200cdf0e10cSrcweir     class ControllerLockUndoAction : public ControllerLockUndoAction_Base
1201cdf0e10cSrcweir     {
1202cdf0e10cSrcweir     public:
ControllerLockUndoAction(const Reference<XModel> & i_model,const bool i_undoIsUnlock)1203cdf0e10cSrcweir         ControllerLockUndoAction( const Reference< XModel >& i_model, const bool i_undoIsUnlock )
1204cdf0e10cSrcweir             :m_xModel( i_model )
1205cdf0e10cSrcweir             ,m_bUndoIsUnlock( i_undoIsUnlock )
1206cdf0e10cSrcweir         {
1207cdf0e10cSrcweir         }
1208cdf0e10cSrcweir 
1209cdf0e10cSrcweir         // XUndoAction
1210cdf0e10cSrcweir         virtual ::rtl::OUString SAL_CALL getTitle() throw (RuntimeException);
1211cdf0e10cSrcweir         virtual void SAL_CALL undo(  ) throw (UndoFailedException, RuntimeException);
1212cdf0e10cSrcweir         virtual void SAL_CALL redo(  ) throw (UndoFailedException, RuntimeException);
1213cdf0e10cSrcweir 
1214cdf0e10cSrcweir     private:
1215cdf0e10cSrcweir         const Reference< XModel >   m_xModel;
1216cdf0e10cSrcweir         const bool                  m_bUndoIsUnlock;
1217cdf0e10cSrcweir     };
1218cdf0e10cSrcweir 
getTitle()1219cdf0e10cSrcweir     ::rtl::OUString SAL_CALL ControllerLockUndoAction::getTitle() throw (RuntimeException)
1220cdf0e10cSrcweir     {
1221cdf0e10cSrcweir         // this action is intended to be used within an UndoContext only, so nobody will ever see this title ...
1222cdf0e10cSrcweir         return ::rtl::OUString();
1223cdf0e10cSrcweir     }
1224cdf0e10cSrcweir 
undo()1225cdf0e10cSrcweir     void SAL_CALL ControllerLockUndoAction::undo(  ) throw (UndoFailedException, RuntimeException)
1226cdf0e10cSrcweir     {
1227cdf0e10cSrcweir         if ( m_bUndoIsUnlock )
1228cdf0e10cSrcweir             m_xModel->unlockControllers();
1229cdf0e10cSrcweir         else
1230cdf0e10cSrcweir             m_xModel->lockControllers();
1231cdf0e10cSrcweir     }
1232cdf0e10cSrcweir 
redo()1233cdf0e10cSrcweir     void SAL_CALL ControllerLockUndoAction::redo(  ) throw (UndoFailedException, RuntimeException)
1234cdf0e10cSrcweir     {
1235cdf0e10cSrcweir         if ( m_bUndoIsUnlock )
1236cdf0e10cSrcweir             m_xModel->lockControllers();
1237cdf0e10cSrcweir         else
1238cdf0e10cSrcweir             m_xModel->unlockControllers();
1239cdf0e10cSrcweir     }
1240cdf0e10cSrcweir }
1241cdf0e10cSrcweir 
1242cdf0e10cSrcweir //________________________________________________________________________________________________________
1243cdf0e10cSrcweir //  frame::XModel
1244cdf0e10cSrcweir //________________________________________________________________________________________________________
1245cdf0e10cSrcweir 
lockControllers()1246cdf0e10cSrcweir void SAL_CALL SfxBaseModel::lockControllers() throw(::com::sun::star::uno::RuntimeException)
1247cdf0e10cSrcweir {
1248cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1249cdf0e10cSrcweir 
1250cdf0e10cSrcweir     ++m_pData->m_nControllerLockCount ;
1251cdf0e10cSrcweir 
1252cdf0e10cSrcweir     if  (   m_pData->m_pDocumentUndoManager.is()
1253cdf0e10cSrcweir         &&  m_pData->m_pDocumentUndoManager->isInContext()
1254cdf0e10cSrcweir         &&  !m_pData->m_pDocumentUndoManager->isLocked()
1255cdf0e10cSrcweir         )
1256cdf0e10cSrcweir     {
1257cdf0e10cSrcweir         m_pData->m_pDocumentUndoManager->addUndoAction( new ControllerLockUndoAction( this, true ) );
1258cdf0e10cSrcweir     }
1259cdf0e10cSrcweir }
1260cdf0e10cSrcweir 
1261cdf0e10cSrcweir //________________________________________________________________________________________________________
1262cdf0e10cSrcweir //  frame::XModel
1263cdf0e10cSrcweir //________________________________________________________________________________________________________
1264cdf0e10cSrcweir 
unlockControllers()1265cdf0e10cSrcweir void SAL_CALL SfxBaseModel::unlockControllers() throw(::com::sun::star::uno::RuntimeException)
1266cdf0e10cSrcweir {
1267cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1268cdf0e10cSrcweir 
1269cdf0e10cSrcweir     --m_pData->m_nControllerLockCount ;
1270cdf0e10cSrcweir 
1271cdf0e10cSrcweir     if  (   m_pData->m_pDocumentUndoManager.is()
1272cdf0e10cSrcweir         &&  m_pData->m_pDocumentUndoManager->isInContext()
1273cdf0e10cSrcweir         &&  !m_pData->m_pDocumentUndoManager->isLocked()
1274cdf0e10cSrcweir         )
1275cdf0e10cSrcweir     {
1276cdf0e10cSrcweir         m_pData->m_pDocumentUndoManager->addUndoAction( new ControllerLockUndoAction( this, false ) );
1277cdf0e10cSrcweir     }
1278cdf0e10cSrcweir }
1279cdf0e10cSrcweir 
1280cdf0e10cSrcweir //________________________________________________________________________________________________________
1281cdf0e10cSrcweir //  frame::XModel
1282cdf0e10cSrcweir //________________________________________________________________________________________________________
1283cdf0e10cSrcweir 
hasControllersLocked()1284cdf0e10cSrcweir sal_Bool SAL_CALL SfxBaseModel::hasControllersLocked() throw(::com::sun::star::uno::RuntimeException)
1285cdf0e10cSrcweir {
1286cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1287cdf0e10cSrcweir 	return ( m_pData->m_nControllerLockCount != 0 ) ;
1288cdf0e10cSrcweir }
1289cdf0e10cSrcweir 
1290cdf0e10cSrcweir //________________________________________________________________________________________________________
1291cdf0e10cSrcweir //  frame::XModel
1292cdf0e10cSrcweir //________________________________________________________________________________________________________
1293cdf0e10cSrcweir 
getCurrentController()1294cdf0e10cSrcweir uno::Reference< frame::XController > SAL_CALL SfxBaseModel::getCurrentController() throw(::com::sun::star::uno::RuntimeException)
1295cdf0e10cSrcweir {
1296cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1297cdf0e10cSrcweir 
1298cdf0e10cSrcweir     // get the last active controller of this model
1299cdf0e10cSrcweir 	if ( m_pData->m_xCurrent.is() )
1300cdf0e10cSrcweir 		return m_pData->m_xCurrent;
1301cdf0e10cSrcweir 
1302cdf0e10cSrcweir 	// get the first controller of this model
1303cdf0e10cSrcweir 	return m_pData->m_seqControllers.getLength() ? m_pData->m_seqControllers.getConstArray()[0] : m_pData->m_xCurrent;
1304cdf0e10cSrcweir }
1305cdf0e10cSrcweir 
1306cdf0e10cSrcweir //________________________________________________________________________________________________________
1307cdf0e10cSrcweir //  frame::XModel
1308cdf0e10cSrcweir //________________________________________________________________________________________________________
1309cdf0e10cSrcweir 
setCurrentController(const uno::Reference<frame::XController> & xCurrentController)1310cdf0e10cSrcweir void SAL_CALL SfxBaseModel::setCurrentController( const uno::Reference< frame::XController >& xCurrentController )
1311cdf0e10cSrcweir         throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException)
1312cdf0e10cSrcweir {
1313cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1314cdf0e10cSrcweir 
1315cdf0e10cSrcweir 	m_pData->m_xCurrent = xCurrentController;
1316cdf0e10cSrcweir }
1317cdf0e10cSrcweir 
1318cdf0e10cSrcweir //________________________________________________________________________________________________________
1319cdf0e10cSrcweir //  frame::XModel
1320cdf0e10cSrcweir //________________________________________________________________________________________________________
1321cdf0e10cSrcweir 
getCurrentSelection()1322cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL SfxBaseModel::getCurrentSelection() throw(::com::sun::star::uno::RuntimeException)
1323cdf0e10cSrcweir {
1324cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1325cdf0e10cSrcweir 
1326cdf0e10cSrcweir     uno::Reference< uno::XInterface >     xReturn;
1327cdf0e10cSrcweir     uno::Reference< frame::XController >    xController =   getCurrentController()      ;
1328cdf0e10cSrcweir 
1329cdf0e10cSrcweir 	if ( xController.is() )
1330cdf0e10cSrcweir 	{
1331cdf0e10cSrcweir         uno::Reference< view::XSelectionSupplier >  xDocView( xController, uno::UNO_QUERY );
1332cdf0e10cSrcweir 		if ( xDocView.is() )
1333cdf0e10cSrcweir 		{
1334cdf0e10cSrcweir             uno::Any xSel = xDocView->getSelection();
1335cdf0e10cSrcweir 			xSel >>= xReturn ;
1336cdf0e10cSrcweir 		}
1337cdf0e10cSrcweir 	}
1338cdf0e10cSrcweir 
1339cdf0e10cSrcweir 	return xReturn ;
1340cdf0e10cSrcweir }
1341cdf0e10cSrcweir 
1342cdf0e10cSrcweir //________________________________________________________________________________________________________
1343cdf0e10cSrcweir //	XModifiable2
1344cdf0e10cSrcweir //________________________________________________________________________________________________________
1345cdf0e10cSrcweir 
disableSetModified()1346cdf0e10cSrcweir sal_Bool SAL_CALL SfxBaseModel::disableSetModified() throw (::com::sun::star::uno::RuntimeException)
1347cdf0e10cSrcweir {
1348cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1349cdf0e10cSrcweir 
1350cdf0e10cSrcweir 	if ( !m_pData->m_pObjectShell.Is() )
1351cdf0e10cSrcweir 		throw uno::RuntimeException();
1352cdf0e10cSrcweir 
1353cdf0e10cSrcweir 	sal_Bool bResult = m_pData->m_pObjectShell->IsEnableSetModified();
1354cdf0e10cSrcweir 	m_pData->m_pObjectShell->EnableSetModified( sal_False );
1355cdf0e10cSrcweir 
1356cdf0e10cSrcweir 	return bResult;
1357cdf0e10cSrcweir }
1358cdf0e10cSrcweir 
enableSetModified()1359cdf0e10cSrcweir sal_Bool SAL_CALL SfxBaseModel::enableSetModified() throw (::com::sun::star::uno::RuntimeException)
1360cdf0e10cSrcweir {
1361cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1362cdf0e10cSrcweir 
1363cdf0e10cSrcweir 	if ( !m_pData->m_pObjectShell.Is() )
1364cdf0e10cSrcweir 		throw uno::RuntimeException();
1365cdf0e10cSrcweir 
1366cdf0e10cSrcweir 	sal_Bool bResult = m_pData->m_pObjectShell->IsEnableSetModified();
1367cdf0e10cSrcweir 	m_pData->m_pObjectShell->EnableSetModified( sal_True );
1368cdf0e10cSrcweir 
1369cdf0e10cSrcweir 	return bResult;
1370cdf0e10cSrcweir }
1371cdf0e10cSrcweir 
isSetModifiedEnabled()1372cdf0e10cSrcweir sal_Bool SAL_CALL SfxBaseModel::isSetModifiedEnabled() throw (::com::sun::star::uno::RuntimeException)
1373cdf0e10cSrcweir {
1374cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1375cdf0e10cSrcweir 
1376cdf0e10cSrcweir 	if ( !m_pData->m_pObjectShell.Is() )
1377cdf0e10cSrcweir 		throw uno::RuntimeException();
1378cdf0e10cSrcweir 
1379cdf0e10cSrcweir 	return m_pData->m_pObjectShell->IsEnableSetModified();
1380cdf0e10cSrcweir }
1381cdf0e10cSrcweir 
1382cdf0e10cSrcweir //________________________________________________________________________________________________________
1383cdf0e10cSrcweir //	XModifiable
1384cdf0e10cSrcweir //________________________________________________________________________________________________________
1385cdf0e10cSrcweir 
isModified()1386cdf0e10cSrcweir sal_Bool SAL_CALL SfxBaseModel::isModified() throw(::com::sun::star::uno::RuntimeException)
1387cdf0e10cSrcweir {
1388cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1389cdf0e10cSrcweir 
1390cdf0e10cSrcweir 	return m_pData->m_pObjectShell.Is() ? m_pData->m_pObjectShell->IsModified() : sal_False;
1391cdf0e10cSrcweir }
1392cdf0e10cSrcweir 
1393cdf0e10cSrcweir //________________________________________________________________________________________________________
1394cdf0e10cSrcweir //	XModifiable
1395cdf0e10cSrcweir //________________________________________________________________________________________________________
1396cdf0e10cSrcweir 
setModified(sal_Bool bModified)1397cdf0e10cSrcweir void SAL_CALL SfxBaseModel::setModified( sal_Bool bModified )
1398cdf0e10cSrcweir         throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException)
1399cdf0e10cSrcweir {
1400cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1401cdf0e10cSrcweir 
1402cdf0e10cSrcweir 	if ( m_pData->m_pObjectShell.Is() )
1403cdf0e10cSrcweir 		m_pData->m_pObjectShell->SetModified(bModified);
1404cdf0e10cSrcweir }
1405cdf0e10cSrcweir 
1406cdf0e10cSrcweir //________________________________________________________________________________________________________
1407cdf0e10cSrcweir //	XModifiable
1408cdf0e10cSrcweir //________________________________________________________________________________________________________
1409cdf0e10cSrcweir 
addModifyListener(const uno::Reference<XMODIFYLISTENER> & xListener)1410cdf0e10cSrcweir void SAL_CALL SfxBaseModel::addModifyListener(const uno::Reference< XMODIFYLISTENER >& xListener) throw( uno::RuntimeException )
1411cdf0e10cSrcweir {
1412cdf0e10cSrcweir     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
1413cdf0e10cSrcweir 
1414cdf0e10cSrcweir     m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< XMODIFYLISTENER >*)0),xListener );
1415cdf0e10cSrcweir }
1416cdf0e10cSrcweir 
1417cdf0e10cSrcweir //________________________________________________________________________________________________________
1418cdf0e10cSrcweir //	XModifiable
1419cdf0e10cSrcweir //________________________________________________________________________________________________________
1420cdf0e10cSrcweir 
removeModifyListener(const uno::Reference<XMODIFYLISTENER> & xListener)1421cdf0e10cSrcweir void SAL_CALL SfxBaseModel::removeModifyListener(const uno::Reference< XMODIFYLISTENER >& xListener) throw( uno::RuntimeException )
1422cdf0e10cSrcweir {
1423cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1424cdf0e10cSrcweir 
1425cdf0e10cSrcweir     m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XMODIFYLISTENER >*)0), xListener );
1426cdf0e10cSrcweir }
1427cdf0e10cSrcweir 
1428cdf0e10cSrcweir //____________________________________________________________________________________________________
1429cdf0e10cSrcweir //  XCloseable
1430cdf0e10cSrcweir //____________________________________________________________________________________________________
1431cdf0e10cSrcweir 
close(sal_Bool bDeliverOwnership)1432cdf0e10cSrcweir void SAL_CALL SfxBaseModel::close( sal_Bool bDeliverOwnership ) throw (util::CloseVetoException, uno::RuntimeException)
1433cdf0e10cSrcweir {
1434cdf0e10cSrcweir     static ::rtl::OUString MSG_1 = ::rtl::OUString::createFromAscii("Cant close while saving.");
1435cdf0e10cSrcweir 
1436cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
1437cdf0e10cSrcweir 	if ( impl_isDisposed() || m_pData->m_bClosed || m_pData->m_bClosing )
1438cdf0e10cSrcweir 		return;
1439cdf0e10cSrcweir 
1440cdf0e10cSrcweir     uno::Reference< uno::XInterface > xSelfHold( static_cast< ::cppu::OWeakObject* >(this) );
1441cdf0e10cSrcweir     lang::EventObject             aSource    (static_cast< ::cppu::OWeakObject*>(this));
1442cdf0e10cSrcweir     ::cppu::OInterfaceContainerHelper* pContainer = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( ( const uno::Reference< util::XCloseListener >*) NULL ) );
1443cdf0e10cSrcweir     if (pContainer!=NULL)
1444cdf0e10cSrcweir 	{
1445cdf0e10cSrcweir         ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
1446cdf0e10cSrcweir         while (pIterator.hasMoreElements())
1447cdf0e10cSrcweir         {
1448cdf0e10cSrcweir             try
1449cdf0e10cSrcweir             {
1450cdf0e10cSrcweir                 ((util::XCloseListener*)pIterator.next())->queryClosing( aSource, bDeliverOwnership );
1451cdf0e10cSrcweir             }
1452cdf0e10cSrcweir             catch( uno::RuntimeException& )
1453cdf0e10cSrcweir             {
1454cdf0e10cSrcweir                 pIterator.remove();
1455cdf0e10cSrcweir             }
1456cdf0e10cSrcweir         }
1457cdf0e10cSrcweir 	}
1458cdf0e10cSrcweir 
1459cdf0e10cSrcweir     if ( m_pData->m_bSaving )
1460cdf0e10cSrcweir     {
1461cdf0e10cSrcweir         if (bDeliverOwnership)
1462cdf0e10cSrcweir             m_pData->m_bSuicide = sal_True;
1463cdf0e10cSrcweir         throw util::CloseVetoException(
1464cdf0e10cSrcweir                 MSG_1,
1465cdf0e10cSrcweir                 static_cast< ::com::sun::star::util::XCloseable* >(this));
1466cdf0e10cSrcweir     }
1467cdf0e10cSrcweir 
1468cdf0e10cSrcweir 	// no own objections against closing!
1469cdf0e10cSrcweir 	m_pData->m_bClosing = sal_True;
1470cdf0e10cSrcweir     pContainer = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( ( const uno::Reference< util::XCloseListener >*) NULL ) );
1471cdf0e10cSrcweir     if (pContainer!=NULL)
1472cdf0e10cSrcweir 	{
1473cdf0e10cSrcweir         ::cppu::OInterfaceIteratorHelper pCloseIterator(*pContainer);
1474cdf0e10cSrcweir         while (pCloseIterator.hasMoreElements())
1475cdf0e10cSrcweir         {
1476cdf0e10cSrcweir             try
1477cdf0e10cSrcweir             {
1478cdf0e10cSrcweir                 ((util::XCloseListener*)pCloseIterator.next())->notifyClosing( aSource );
1479cdf0e10cSrcweir             }
1480cdf0e10cSrcweir             catch( uno::RuntimeException& )
1481cdf0e10cSrcweir             {
1482cdf0e10cSrcweir                 pCloseIterator.remove();
1483cdf0e10cSrcweir             }
1484cdf0e10cSrcweir         }
1485cdf0e10cSrcweir 	}
1486cdf0e10cSrcweir 
1487cdf0e10cSrcweir 	m_pData->m_bClosed = sal_True;
1488cdf0e10cSrcweir 	m_pData->m_bClosing = sal_False;
1489cdf0e10cSrcweir 
1490cdf0e10cSrcweir     dispose();
1491cdf0e10cSrcweir }
1492cdf0e10cSrcweir 
1493cdf0e10cSrcweir //____________________________________________________________________________________________________
1494cdf0e10cSrcweir //  XCloseBroadcaster
1495cdf0e10cSrcweir //____________________________________________________________________________________________________
1496cdf0e10cSrcweir 
addCloseListener(const uno::Reference<XCLOSELISTENER> & xListener)1497cdf0e10cSrcweir void SAL_CALL SfxBaseModel::addCloseListener( const uno::Reference< XCLOSELISTENER >& xListener ) throw (uno::RuntimeException)
1498cdf0e10cSrcweir {
1499cdf0e10cSrcweir     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
1500cdf0e10cSrcweir 
1501cdf0e10cSrcweir     m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< XCLOSELISTENER >*)0), xListener );
1502cdf0e10cSrcweir }
1503cdf0e10cSrcweir 
1504cdf0e10cSrcweir //____________________________________________________________________________________________________
1505cdf0e10cSrcweir //  XCloseBroadcaster
1506cdf0e10cSrcweir //____________________________________________________________________________________________________
1507cdf0e10cSrcweir 
removeCloseListener(const uno::Reference<XCLOSELISTENER> & xListener)1508cdf0e10cSrcweir void SAL_CALL SfxBaseModel::removeCloseListener( const uno::Reference< XCLOSELISTENER >& xListener ) throw (uno::RuntimeException)
1509cdf0e10cSrcweir {
1510cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1511cdf0e10cSrcweir 
1512cdf0e10cSrcweir     m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XCLOSELISTENER >*)0), xListener );
1513cdf0e10cSrcweir }
1514cdf0e10cSrcweir 
1515cdf0e10cSrcweir //________________________________________________________________________________________________________
1516cdf0e10cSrcweir //	XPrintable
1517cdf0e10cSrcweir //________________________________________________________________________________________________________
1518cdf0e10cSrcweir 
getPrinter()1519cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > SAL_CALL SfxBaseModel::getPrinter() throw(::com::sun::star::uno::RuntimeException)
1520cdf0e10cSrcweir {
1521cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1522cdf0e10cSrcweir 
1523cdf0e10cSrcweir     if ( impl_getPrintHelper() )
1524cdf0e10cSrcweir         return m_pData->m_xPrintable->getPrinter();
1525cdf0e10cSrcweir     else
1526cdf0e10cSrcweir         return uno::Sequence< beans::PropertyValue >();
1527cdf0e10cSrcweir }
1528cdf0e10cSrcweir 
setPrinter(const uno::Sequence<beans::PropertyValue> & rPrinter)1529cdf0e10cSrcweir void SAL_CALL SfxBaseModel::setPrinter(const uno::Sequence< beans::PropertyValue >& rPrinter)
1530cdf0e10cSrcweir         throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
1531cdf0e10cSrcweir {
1532cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1533cdf0e10cSrcweir 
1534cdf0e10cSrcweir     if ( impl_getPrintHelper() )
1535cdf0e10cSrcweir         m_pData->m_xPrintable->setPrinter( rPrinter );
1536cdf0e10cSrcweir }
1537cdf0e10cSrcweir 
print(const uno::Sequence<beans::PropertyValue> & rOptions)1538cdf0e10cSrcweir void SAL_CALL SfxBaseModel::print(const uno::Sequence< beans::PropertyValue >& rOptions)
1539cdf0e10cSrcweir         throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
1540cdf0e10cSrcweir {
1541cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1542cdf0e10cSrcweir 
1543cdf0e10cSrcweir     if ( impl_getPrintHelper() )
1544cdf0e10cSrcweir         m_pData->m_xPrintable->print( rOptions );
1545cdf0e10cSrcweir }
1546cdf0e10cSrcweir 
1547cdf0e10cSrcweir //________________________________________________________________________________________________________
1548cdf0e10cSrcweir //	XStorable
1549cdf0e10cSrcweir //________________________________________________________________________________________________________
1550cdf0e10cSrcweir 
hasLocation()1551cdf0e10cSrcweir sal_Bool SAL_CALL SfxBaseModel::hasLocation() throw(::com::sun::star::uno::RuntimeException)
1552cdf0e10cSrcweir {
1553cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1554cdf0e10cSrcweir 
1555cdf0e10cSrcweir 	return m_pData->m_pObjectShell.Is() ? m_pData->m_pObjectShell->HasName() : sal_False;
1556cdf0e10cSrcweir }
1557cdf0e10cSrcweir 
1558cdf0e10cSrcweir //________________________________________________________________________________________________________
1559cdf0e10cSrcweir //	XStorable
1560cdf0e10cSrcweir //________________________________________________________________________________________________________
1561cdf0e10cSrcweir 
getLocation()1562cdf0e10cSrcweir ::rtl::OUString SAL_CALL SfxBaseModel::getLocation() throw(::com::sun::star::uno::RuntimeException)
1563cdf0e10cSrcweir {
1564cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1565cdf0e10cSrcweir 
1566cdf0e10cSrcweir     if ( m_pData->m_pObjectShell.Is() )
1567cdf0e10cSrcweir     {
1568cdf0e10cSrcweir         // TODO/LATER: is it correct that the shared document returns shared file location?
1569cdf0e10cSrcweir         if ( m_pData->m_pObjectShell->IsDocShared() )
1570cdf0e10cSrcweir             return m_pData->m_pObjectShell->GetSharedFileURL();
1571cdf0e10cSrcweir         else
1572cdf0e10cSrcweir             return ::rtl::OUString(m_pData->m_pObjectShell->GetMedium()->GetName());
1573cdf0e10cSrcweir     }
1574cdf0e10cSrcweir 
1575cdf0e10cSrcweir     return m_pData->m_sURL;
1576cdf0e10cSrcweir }
1577cdf0e10cSrcweir 
1578cdf0e10cSrcweir //________________________________________________________________________________________________________
1579cdf0e10cSrcweir //	XStorable
1580cdf0e10cSrcweir //________________________________________________________________________________________________________
1581cdf0e10cSrcweir 
isReadonly()1582cdf0e10cSrcweir sal_Bool SAL_CALL SfxBaseModel::isReadonly() throw(::com::sun::star::uno::RuntimeException)
1583cdf0e10cSrcweir {
1584cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1585cdf0e10cSrcweir 
1586cdf0e10cSrcweir 	return m_pData->m_pObjectShell.Is() ? m_pData->m_pObjectShell->IsReadOnly() : sal_True;
1587cdf0e10cSrcweir }
1588cdf0e10cSrcweir 
1589cdf0e10cSrcweir //________________________________________________________________________________________________________
1590cdf0e10cSrcweir //	XStorable2
1591cdf0e10cSrcweir //________________________________________________________________________________________________________
1592cdf0e10cSrcweir 
storeSelf(const uno::Sequence<beans::PropertyValue> & aSeqArgs)1593cdf0e10cSrcweir void SAL_CALL SfxBaseModel::storeSelf( const    uno::Sequence< beans::PropertyValue >&  aSeqArgs )
1594cdf0e10cSrcweir 		throw ( ::com::sun::star::lang::IllegalArgumentException,
1595cdf0e10cSrcweir 				::com::sun::star::io::IOException,
1596cdf0e10cSrcweir 				::com::sun::star::uno::RuntimeException )
1597cdf0e10cSrcweir {
1598cdf0e10cSrcweir 	RTL_LOGFILE_PRODUCT_CONTEXT( aPerfLog, "PERFORMANCE - SfxBaseModel::storeSelf" );
1599cdf0e10cSrcweir 
1600cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1601cdf0e10cSrcweir 
1602cdf0e10cSrcweir 	if ( m_pData->m_pObjectShell.Is() )
1603cdf0e10cSrcweir     {
1604cdf0e10cSrcweir         m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "storeSelf" ) ) );
1605cdf0e10cSrcweir 		SfxSaveGuard aSaveGuard(this, m_pData, sal_False);
1606cdf0e10cSrcweir 
1607cdf0e10cSrcweir 		for ( sal_Int32 nInd = 0; nInd < aSeqArgs.getLength(); nInd++ )
1608cdf0e10cSrcweir 		{
1609cdf0e10cSrcweir 			// check that only acceptable parameters are provided here
1610cdf0e10cSrcweir 			if ( !aSeqArgs[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VersionComment" ) ) )
1611cdf0e10cSrcweir 			  && !aSeqArgs[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Author" ) ) )
1612cdf0e10cSrcweir 			  && !aSeqArgs[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "InteractionHandler" ) ) )
1613cba4944aSOliver-Rainer Wittmann 			  && !aSeqArgs[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StatusIndicator" ) ) )
1614cba4944aSOliver-Rainer Wittmann 			  && !aSeqArgs[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FailOnWarning" ) ) ) )
1615cdf0e10cSrcweir 			{
1616cdf0e10cSrcweir                 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "unexpected parameter for storeSelf, might be no problem if SaveAs is executed." ) ) );
1617cdf0e10cSrcweir                 m_pData->m_pObjectShell->StoreLog();
1618cdf0e10cSrcweir 
1619cdf0e10cSrcweir 				::rtl::OUString aMessage( RTL_CONSTASCII_USTRINGPARAM( "Unexpected MediaDescriptor parameter: " ) );
1620cdf0e10cSrcweir 				aMessage += aSeqArgs[nInd].Name;
1621cdf0e10cSrcweir 				throw lang::IllegalArgumentException( aMessage, uno::Reference< uno::XInterface >(), 1 );
1622cdf0e10cSrcweir 			}
1623cdf0e10cSrcweir 		}
1624cdf0e10cSrcweir 
1625cdf0e10cSrcweir     	SfxAllItemSet *pParams = new SfxAllItemSet( SFX_APP()->GetPool() );
1626cdf0e10cSrcweir     	TransformParameters( SID_SAVEDOC, aSeqArgs, *pParams );
1627cdf0e10cSrcweir 
1628cdf0e10cSrcweir 		SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEDOC, GlobalEventConfig::GetEventName(STR_EVENT_SAVEDOC), m_pData->m_pObjectShell ) );
1629cdf0e10cSrcweir 
1630cdf0e10cSrcweir 		sal_Bool bRet = sal_False;
1631cdf0e10cSrcweir 
1632cdf0e10cSrcweir 		// TODO/LATER: let the embedded case of saving be handled more careful
1633cdf0e10cSrcweir 		if ( m_pData->m_pObjectShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
1634cdf0e10cSrcweir 		{
1635cdf0e10cSrcweir 			// If this is an embedded object that has no URL based location it should be stored to own storage.
1636cdf0e10cSrcweir 			// An embedded object can have a location based on URL in case it is a link, then it should be
1637cdf0e10cSrcweir 			// stored in normal way.
1638cdf0e10cSrcweir 			if ( !hasLocation() || getLocation().compareToAscii( "private:", 8 ) == 0 )
1639cdf0e10cSrcweir 			{
1640cdf0e10cSrcweir 				// actually in this very rare case only UI parameters have sence
1641cdf0e10cSrcweir 				// TODO/LATER: should be done later, after integration of sb19
1642cdf0e10cSrcweir                 bRet = m_pData->m_pObjectShell->DoSave()
1643cdf0e10cSrcweir                     && m_pData->m_pObjectShell->DoSaveCompleted();
1644cdf0e10cSrcweir 			}
1645cdf0e10cSrcweir 			else
1646cdf0e10cSrcweir 			{
1647cdf0e10cSrcweir 				bRet = m_pData->m_pObjectShell->Save_Impl( pParams );
1648cdf0e10cSrcweir 			}
1649cdf0e10cSrcweir 		}
1650cdf0e10cSrcweir 		else
1651cdf0e10cSrcweir 			bRet = m_pData->m_pObjectShell->Save_Impl( pParams );
1652cdf0e10cSrcweir 
1653cdf0e10cSrcweir 		DELETEZ( pParams );
1654cdf0e10cSrcweir 
1655cdf0e10cSrcweir 		sal_uInt32 nErrCode = m_pData->m_pObjectShell->GetError() ? m_pData->m_pObjectShell->GetError()
1656cdf0e10cSrcweir 																	: ERRCODE_IO_CANTWRITE;
1657cdf0e10cSrcweir 		m_pData->m_pObjectShell->ResetError();
1658cdf0e10cSrcweir 
1659cdf0e10cSrcweir 		if ( bRet )
1660cdf0e10cSrcweir 		{
1661cdf0e10cSrcweir             m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "successful saving." ) ) );
1662cdf0e10cSrcweir 			m_pData->m_aPreusedFilterName = GetMediumFilterName_Impl();
1663cdf0e10cSrcweir 
1664cdf0e10cSrcweir 			SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEDOCDONE, GlobalEventConfig::GetEventName(STR_EVENT_SAVEDOCDONE), m_pData->m_pObjectShell ) );
1665cdf0e10cSrcweir 		}
1666cdf0e10cSrcweir 		else
1667cdf0e10cSrcweir 		{
1668cdf0e10cSrcweir             m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing failed!" ) ) );
1669cdf0e10cSrcweir             m_pData->m_pObjectShell->StoreLog();
1670cdf0e10cSrcweir 
1671cdf0e10cSrcweir             // write the contents of the logger to the file
1672cdf0e10cSrcweir 			SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEDOCFAILED, GlobalEventConfig::GetEventName(STR_EVENT_SAVEDOCFAILED), m_pData->m_pObjectShell ) );
1673cdf0e10cSrcweir 
1674cdf0e10cSrcweir 			throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), nErrCode );
1675cdf0e10cSrcweir 		}
1676cdf0e10cSrcweir     }
1677cdf0e10cSrcweir 
1678cdf0e10cSrcweir }
1679cdf0e10cSrcweir 
1680cdf0e10cSrcweir //________________________________________________________________________________________________________
1681cdf0e10cSrcweir //	XStorable
1682cdf0e10cSrcweir //________________________________________________________________________________________________________
1683cdf0e10cSrcweir 
store()1684cdf0e10cSrcweir void SAL_CALL SfxBaseModel::store() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
1685cdf0e10cSrcweir {
1686cdf0e10cSrcweir 	storeSelf( uno::Sequence< beans::PropertyValue >() );
1687cdf0e10cSrcweir }
1688cdf0e10cSrcweir 
1689cdf0e10cSrcweir //________________________________________________________________________________________________________
1690cdf0e10cSrcweir //	XStorable
1691cdf0e10cSrcweir //________________________________________________________________________________________________________
1692cdf0e10cSrcweir 
storeAsURL(const::rtl::OUString & rURL,const uno::Sequence<beans::PropertyValue> & rArgs)1693cdf0e10cSrcweir void SAL_CALL SfxBaseModel::storeAsURL( const   ::rtl::OUString&                   rURL    ,
1694cdf0e10cSrcweir                                         const   uno::Sequence< beans::PropertyValue >&  rArgs   )
1695cdf0e10cSrcweir         throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
1696cdf0e10cSrcweir {
1697cdf0e10cSrcweir 	RTL_LOGFILE_PRODUCT_CONTEXT( aPerfLog, "PERFORMANCE - SfxBaseModel::storeAsURL" );
1698cdf0e10cSrcweir 
1699cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1700cdf0e10cSrcweir 
1701cdf0e10cSrcweir 	if ( m_pData->m_pObjectShell.Is() )
1702cdf0e10cSrcweir 	{
1703cdf0e10cSrcweir         m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "storeAsURL" ) ) );
1704cdf0e10cSrcweir 		SfxSaveGuard aSaveGuard(this, m_pData, sal_False);
1705cdf0e10cSrcweir 
1706cdf0e10cSrcweir 		impl_store( rURL, rArgs, sal_False );
1707cdf0e10cSrcweir 
1708cdf0e10cSrcweir         uno::Sequence< beans::PropertyValue > aSequence ;
1709cdf0e10cSrcweir 		TransformItems( SID_OPENDOC, *m_pData->m_pObjectShell->GetMedium()->GetItemSet(), aSequence );
1710cdf0e10cSrcweir 		attachResource( rURL, aSequence );
1711cdf0e10cSrcweir 
1712cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
1713cdf0e10cSrcweir 		SFX_ITEMSET_ARG( m_pData->m_pObjectShell->GetMedium()->GetItemSet(), pPasswdItem, SfxStringItem, SID_PASSWORD, sal_False);
1714cdf0e10cSrcweir         OSL_ENSURE( !pPasswdItem, "There should be no Password property in the document MediaDescriptor!" );
1715cdf0e10cSrcweir #endif
1716cdf0e10cSrcweir 	}
1717cdf0e10cSrcweir }
1718cdf0e10cSrcweir 
1719cdf0e10cSrcweir //________________________________________________________________________________________________________
1720cdf0e10cSrcweir //	XUndoManagerSupplier
1721cdf0e10cSrcweir //________________________________________________________________________________________________________
getUndoManager()1722cdf0e10cSrcweir Reference< XUndoManager > SAL_CALL SfxBaseModel::getUndoManager(  ) throw (RuntimeException)
1723cdf0e10cSrcweir {
1724cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1725cdf0e10cSrcweir     if ( !m_pData->m_pDocumentUndoManager.is() )
1726cdf0e10cSrcweir         m_pData->m_pDocumentUndoManager.set( new ::sfx2::DocumentUndoManager( *this ) );
1727cdf0e10cSrcweir     return m_pData->m_pDocumentUndoManager.get();
1728cdf0e10cSrcweir }
1729cdf0e10cSrcweir 
1730cdf0e10cSrcweir //________________________________________________________________________________________________________
1731cdf0e10cSrcweir //	XStorable
1732cdf0e10cSrcweir //________________________________________________________________________________________________________
1733cdf0e10cSrcweir 
storeToURL(const::rtl::OUString & rURL,const uno::Sequence<beans::PropertyValue> & rArgs)1734cdf0e10cSrcweir void SAL_CALL SfxBaseModel::storeToURL( const   ::rtl::OUString&                   rURL    ,
1735cdf0e10cSrcweir                                         const   uno::Sequence< beans::PropertyValue >&  rArgs   )
1736cdf0e10cSrcweir         throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
1737cdf0e10cSrcweir {
1738cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1739cdf0e10cSrcweir 
1740cdf0e10cSrcweir 	if ( m_pData->m_pObjectShell.Is() )
1741cdf0e10cSrcweir     {
1742cdf0e10cSrcweir         m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "storeToURL" ) ) );
1743cdf0e10cSrcweir 		SfxSaveGuard aSaveGuard(this, m_pData, sal_False);
1744cdf0e10cSrcweir 		impl_store( rURL, rArgs, sal_True );
1745cdf0e10cSrcweir     }
1746cdf0e10cSrcweir }
1747cdf0e10cSrcweir 
wasModifiedSinceLastSave()1748cdf0e10cSrcweir ::sal_Bool SAL_CALL SfxBaseModel::wasModifiedSinceLastSave() throw ( RuntimeException )
1749cdf0e10cSrcweir {
1750cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1751cdf0e10cSrcweir     return m_pData->m_bModifiedSinceLastSave;
1752cdf0e10cSrcweir }
1753cdf0e10cSrcweir 
storeToRecoveryFile(const::rtl::OUString & i_TargetLocation,const Sequence<PropertyValue> & i_MediaDescriptor)1754cdf0e10cSrcweir void SAL_CALL SfxBaseModel::storeToRecoveryFile( const ::rtl::OUString& i_TargetLocation, const Sequence< PropertyValue >& i_MediaDescriptor ) throw ( RuntimeException, IOException, WrappedTargetException )
1755cdf0e10cSrcweir {
1756cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1757cdf0e10cSrcweir 
1758cdf0e10cSrcweir     // delegate
1759cdf0e10cSrcweir 	SfxSaveGuard aSaveGuard( this, m_pData, sal_False );
1760cdf0e10cSrcweir 	impl_store( i_TargetLocation, i_MediaDescriptor, sal_True );
1761cdf0e10cSrcweir 
1762cdf0e10cSrcweir     // no need for subsequent calls to storeToRecoveryFile, unless we're modified, again
1763cdf0e10cSrcweir     m_pData->m_bModifiedSinceLastSave = sal_False;
1764cdf0e10cSrcweir }
1765cdf0e10cSrcweir 
recoverFromFile(const::rtl::OUString & i_SourceLocation,const::rtl::OUString & i_SalvagedFile,const Sequence<PropertyValue> & i_MediaDescriptor)1766cdf0e10cSrcweir void SAL_CALL SfxBaseModel::recoverFromFile( const ::rtl::OUString& i_SourceLocation, const ::rtl::OUString& i_SalvagedFile, const Sequence< PropertyValue >& i_MediaDescriptor ) throw ( RuntimeException, IOException, WrappedTargetException )
1767cdf0e10cSrcweir {
1768cdf0e10cSrcweir     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
1769cdf0e10cSrcweir 
1770cdf0e10cSrcweir     // delegate to our "load" method
1771cdf0e10cSrcweir     ::comphelper::NamedValueCollection aMediaDescriptor( i_MediaDescriptor );
1772cdf0e10cSrcweir 
1773cdf0e10cSrcweir     // our load implementation expects the SalvagedFile to be in the media descriptor
1774cdf0e10cSrcweir     OSL_ENSURE( !aMediaDescriptor.has( "SalvagedFile" ) || ( aMediaDescriptor.getOrDefault( "SalvagedFile", ::rtl::OUString() ) == i_SalvagedFile ),
1775cdf0e10cSrcweir         "SfxBaseModel::recoverFromFile: inconsistent information!" );
1776cdf0e10cSrcweir     aMediaDescriptor.put( "SalvagedFile", i_SalvagedFile );
1777cdf0e10cSrcweir 
1778cdf0e10cSrcweir     // similar for the to-be-loaded file
1779cdf0e10cSrcweir     OSL_ENSURE( !aMediaDescriptor.has( "URL" ) || ( aMediaDescriptor.getOrDefault( "URL", ::rtl::OUString() ) == i_SourceLocation ),
1780cdf0e10cSrcweir         "SfxBaseModel::recoverFromFile: inconsistent information!" );
1781cdf0e10cSrcweir     aMediaDescriptor.put( "URL", i_SourceLocation );
1782cdf0e10cSrcweir 
1783cdf0e10cSrcweir     load( aMediaDescriptor.getPropertyValues() );
1784cdf0e10cSrcweir 
1785cdf0e10cSrcweir     // Note: The XDocumentRecovery interface specification requires us to do an attachResource after loading.
1786cdf0e10cSrcweir     // However, we will not do this here, as we know that our load implementation (respectively some method
1787cdf0e10cSrcweir     // called from there) already did so.
1788cdf0e10cSrcweir     // In particular, the load process might already have modified some elements of the media
1789cdf0e10cSrcweir     // descriptor, for instance the MacroExecMode (in case the user was involved to decide about it), and we do
1790cdf0e10cSrcweir     // not want to overwrite it with the "old" elements passed to this method here.
1791cdf0e10cSrcweir }
1792cdf0e10cSrcweir 
1793cdf0e10cSrcweir //________________________________________________________________________________________________________
1794cdf0e10cSrcweir // XLoadable
1795cdf0e10cSrcweir //________________________________________________________________________________________________________
1796cdf0e10cSrcweir 
initNew()1797cdf0e10cSrcweir void SAL_CALL SfxBaseModel::initNew()
1798cdf0e10cSrcweir 		throw (::com::sun::star::frame::DoubleInitializationException,
1799cdf0e10cSrcweir 			   ::com::sun::star::io::IOException,
1800cdf0e10cSrcweir 			   ::com::sun::star::uno::RuntimeException,
1801cdf0e10cSrcweir 			   ::com::sun::star::uno::Exception)
1802cdf0e10cSrcweir {
1803cdf0e10cSrcweir     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
1804cdf0e10cSrcweir     if ( IsInitialized() )
1805cdf0e10cSrcweir         throw ::com::sun::star::frame::DoubleInitializationException( ::rtl::OUString(), *this );
1806cdf0e10cSrcweir 
1807cdf0e10cSrcweir 	// the object shell should exist always
1808cdf0e10cSrcweir 	DBG_ASSERT( m_pData->m_pObjectShell.Is(), "Model is useless without an ObjectShell" );
1809cdf0e10cSrcweir 	if ( m_pData->m_pObjectShell.Is() )
1810cdf0e10cSrcweir 	{
1811cdf0e10cSrcweir 		if( m_pData->m_pObjectShell->GetMedium() )
1812cdf0e10cSrcweir 			throw DOUBLEINITIALIZATIONEXCEPTION();
1813cdf0e10cSrcweir 
1814cdf0e10cSrcweir 		sal_Bool bRes = m_pData->m_pObjectShell->DoInitNew( NULL );
1815cdf0e10cSrcweir 		sal_uInt32 nErrCode = m_pData->m_pObjectShell->GetError() ?
1816cdf0e10cSrcweir 									m_pData->m_pObjectShell->GetError() : ERRCODE_IO_CANTCREATE;
1817cdf0e10cSrcweir 		m_pData->m_pObjectShell->ResetError();
1818cdf0e10cSrcweir 
1819cdf0e10cSrcweir 		if ( !bRes )
1820cdf0e10cSrcweir 			throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), nErrCode );
1821cdf0e10cSrcweir 	}
1822cdf0e10cSrcweir }
1823cdf0e10cSrcweir 
1824cdf0e10cSrcweir //________________________________________________________________________________________________________
1825cdf0e10cSrcweir // XLoadable
1826cdf0e10cSrcweir //________________________________________________________________________________________________________
1827cdf0e10cSrcweir 
load(const uno::Sequence<beans::PropertyValue> & seqArguments)1828cdf0e10cSrcweir void SAL_CALL SfxBaseModel::load(   const uno::Sequence< beans::PropertyValue >& seqArguments )
1829cdf0e10cSrcweir 		throw (::com::sun::star::frame::DoubleInitializationException,
1830cdf0e10cSrcweir                ::com::sun::star::io::IOException,
1831cdf0e10cSrcweir 			   ::com::sun::star::uno::RuntimeException,
1832cdf0e10cSrcweir 			   ::com::sun::star::uno::Exception)
1833cdf0e10cSrcweir {
1834cdf0e10cSrcweir     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
1835cdf0e10cSrcweir     if ( IsInitialized() )
1836cdf0e10cSrcweir         throw ::com::sun::star::frame::DoubleInitializationException( ::rtl::OUString(), *this );
1837cdf0e10cSrcweir 
1838cdf0e10cSrcweir 	// the object shell should exist always
1839cdf0e10cSrcweir 	DBG_ASSERT( m_pData->m_pObjectShell.Is(), "Model is useless without an ObjectShell" );
1840cdf0e10cSrcweir 
1841cdf0e10cSrcweir 	if ( m_pData->m_pObjectShell.Is() )
1842cdf0e10cSrcweir 	{
1843cdf0e10cSrcweir 		if( m_pData->m_pObjectShell->GetMedium() )
1844cdf0e10cSrcweir 			// if a Medium is present, the document is already initialized
1845cdf0e10cSrcweir 			throw DOUBLEINITIALIZATIONEXCEPTION();
1846cdf0e10cSrcweir 
1847cdf0e10cSrcweir         SfxMedium* pMedium = new SfxMedium( seqArguments );
1848cdf0e10cSrcweir         String aFilterName;
1849cdf0e10cSrcweir         SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFilterNameItem, SfxStringItem, SID_FILTER_NAME, sal_False );
1850cdf0e10cSrcweir 		if( pFilterNameItem )
1851cdf0e10cSrcweir 			aFilterName = pFilterNameItem->GetValue();
1852cdf0e10cSrcweir 		if( !m_pData->m_pObjectShell->GetFactory().GetFilterContainer()->GetFilter4FilterName( aFilterName ) )
1853cdf0e10cSrcweir 		{
1854cdf0e10cSrcweir 			// filtername is not valid
1855cdf0e10cSrcweir             delete pMedium;
1856cdf0e10cSrcweir             throw frame::IllegalArgumentIOException();
1857cdf0e10cSrcweir 		}
1858cdf0e10cSrcweir 
1859cdf0e10cSrcweir 		// !TODO: currently not working
1860cdf0e10cSrcweir 		//SFX_ITEMSET_ARG( pParams, pFrameItem, SfxFrameItem, SID_DOCFRAME, sal_False );
1861cdf0e10cSrcweir 		//if( pFrameItem && pFrameItem->GetFrame() )
1862cdf0e10cSrcweir 		//{
1863cdf0e10cSrcweir 		//	SfxFrame* pFrame = pFrameItem->GetFrame();
1864cdf0e10cSrcweir 		//	pMedium->SetLoadTargetFrame( pFrame );
1865cdf0e10cSrcweir 		//}
1866cdf0e10cSrcweir 
1867cdf0e10cSrcweir         SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False );
1868cdf0e10cSrcweir         sal_Bool bSalvage = pSalvageItem ? sal_True : sal_False;
1869cdf0e10cSrcweir 
1870cdf0e10cSrcweir         // SFX_ITEMSET_ARG( pMedium->GetItemSet(), pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False);
1871cdf0e10cSrcweir         // sal_Bool bTemplate = pTemplateItem && pTemplateItem->GetValue();
1872cdf0e10cSrcweir         //
1873cdf0e10cSrcweir         // does already happen in DoLoad call
1874cdf0e10cSrcweir         //m_pData->m_pObjectShell->SetActivateEvent_Impl( bTemplate ? SFX_EVENT_CREATEDOC : SFX_EVENT_OPENDOC );
1875cdf0e10cSrcweir 
1876cdf0e10cSrcweir 		// load document
1877cdf0e10cSrcweir 		sal_uInt32 nError = ERRCODE_NONE;
1878cdf0e10cSrcweir 		if ( !m_pData->m_pObjectShell->DoLoad(pMedium) )
1879cdf0e10cSrcweir 			nError=ERRCODE_IO_GENERAL;
1880cdf0e10cSrcweir 
1881cdf0e10cSrcweir         // QUESTION: if the following happens outside of DoLoad, something important is missing there!
1882cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > xHandler = pMedium->GetInteractionHandler();
1883cdf0e10cSrcweir 		if( m_pData->m_pObjectShell->GetErrorCode() )
1884cdf0e10cSrcweir 		{
1885cdf0e10cSrcweir 			nError = m_pData->m_pObjectShell->GetErrorCode();
1886cdf0e10cSrcweir 			if ( nError == ERRCODE_IO_BROKENPACKAGE && xHandler.is() )
1887cdf0e10cSrcweir 			{
1888cdf0e10cSrcweir         		::rtl::OUString aDocName = pMedium->GetURLObject().getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
1889cdf0e10cSrcweir                 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pRepairItem, SfxBoolItem, SID_REPAIRPACKAGE, sal_False );
1890cdf0e10cSrcweir     			if ( !pRepairItem || !pRepairItem->GetValue() )
1891cdf0e10cSrcweir 				{
1892cdf0e10cSrcweir                     RequestPackageReparation aRequest( aDocName );
1893cdf0e10cSrcweir                     xHandler->handle( aRequest.GetRequest() );
1894cdf0e10cSrcweir                     if( aRequest.isApproved() )
1895cdf0e10cSrcweir 					{
1896cdf0e10cSrcweir 						// broken package: try second loading and allow repair
1897cdf0e10cSrcweir     					pMedium->GetItemSet()->Put( SfxBoolItem( SID_REPAIRPACKAGE, sal_True ) );
1898cdf0e10cSrcweir                 		pMedium->GetItemSet()->Put( SfxBoolItem( SID_TEMPLATE, sal_True ) );
1899cdf0e10cSrcweir 						pMedium->GetItemSet()->Put( SfxStringItem( SID_DOCINFO_TITLE, aDocName ) );
1900cdf0e10cSrcweir 
1901cdf0e10cSrcweir 						// the error must be reset and the storage must be reopened in new mode
1902cdf0e10cSrcweir 						pMedium->ResetError();
1903cdf0e10cSrcweir 						pMedium->CloseStorage();
1904cdf0e10cSrcweir 						m_pData->m_pObjectShell->PrepareSecondTryLoad_Impl();
1905cdf0e10cSrcweir 						if ( !m_pData->m_pObjectShell->DoLoad(pMedium) )
1906cdf0e10cSrcweir 							nError=ERRCODE_IO_GENERAL;
1907cdf0e10cSrcweir 						nError = m_pData->m_pObjectShell->GetErrorCode();
1908cdf0e10cSrcweir 					}
1909cdf0e10cSrcweir 				}
1910cdf0e10cSrcweir 
1911cdf0e10cSrcweir 				if ( nError == ERRCODE_IO_BROKENPACKAGE )
1912cdf0e10cSrcweir 				{
1913cdf0e10cSrcweir 					// repair either not allowed or not successful
1914cdf0e10cSrcweir                     NotifyBrokenPackage aRequest( aDocName );
1915cdf0e10cSrcweir                     xHandler->handle( aRequest.GetRequest() );
1916cdf0e10cSrcweir 				}
1917cdf0e10cSrcweir 			}
1918cdf0e10cSrcweir 		}
1919cdf0e10cSrcweir 
1920cdf0e10cSrcweir 		if( m_pData->m_pObjectShell->IsAbortingImport() )
1921cdf0e10cSrcweir 			nError = ERRCODE_ABORT;
1922cdf0e10cSrcweir 
1923cdf0e10cSrcweir         if( bSalvage )
1924cdf0e10cSrcweir         {
1925cdf0e10cSrcweir             // file recovery: restore original filter
1926cdf0e10cSrcweir             SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFilterItem, SfxStringItem, SID_FILTER_NAME, sal_False );
1927cdf0e10cSrcweir             SfxFilterMatcher& rMatcher = SFX_APP()->GetFilterMatcher();
1928cdf0e10cSrcweir             const SfxFilter* pSetFilter = rMatcher.GetFilter4FilterName( pFilterItem->GetValue() );
1929cdf0e10cSrcweir             pMedium->SetFilter( pSetFilter );
1930cdf0e10cSrcweir             m_pData->m_pObjectShell->SetModified(sal_True);
1931cdf0e10cSrcweir         }
1932cdf0e10cSrcweir 
1933cdf0e10cSrcweir         // TODO/LATER: may be the mode should be retrieved from outside and the preused filter should not be set
1934cdf0e10cSrcweir         if ( m_pData->m_pObjectShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
1935cdf0e10cSrcweir         {
1936cdf0e10cSrcweir             SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFilterItem, SfxStringItem, SID_FILTER_NAME, sal_False );
1937cdf0e10cSrcweir             if ( pFilterItem )
1938cdf0e10cSrcweir                 m_pData->m_aPreusedFilterName = pFilterItem->GetValue();
1939cdf0e10cSrcweir         }
1940cdf0e10cSrcweir 
1941cdf0e10cSrcweir         if ( !nError )
1942cdf0e10cSrcweir             nError = pMedium->GetError();
1943cdf0e10cSrcweir 
1944cdf0e10cSrcweir         m_pData->m_pObjectShell->ResetError();
1945cdf0e10cSrcweir 
1946cdf0e10cSrcweir     	if ( nError )
1947cdf0e10cSrcweir 		{
1948cdf0e10cSrcweir 			sal_Bool bSilent = sal_False;
1949cdf0e10cSrcweir 			SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSilentItem, SfxBoolItem, SID_SILENT, sal_False);
1950cdf0e10cSrcweir 			if( pSilentItem )
1951cdf0e10cSrcweir 				bSilent = pSilentItem->GetValue();
1952cdf0e10cSrcweir 
1953cdf0e10cSrcweir           	sal_Bool bWarning = ((nError & ERRCODE_WARNING_MASK) == ERRCODE_WARNING_MASK);
1954cdf0e10cSrcweir         	if ( nError != ERRCODE_IO_BROKENPACKAGE && !bSilent )
1955cdf0e10cSrcweir         	{
1956cdf0e10cSrcweir 				// broken package was handled already
1957cdf0e10cSrcweir             	if ( SfxObjectShell::UseInteractionToHandleError( xHandler, nError ) && !bWarning )
1958cdf0e10cSrcweir 				{
1959cdf0e10cSrcweir 					// abort loading (except for warnings)
1960cdf0e10cSrcweir                    	nError = ERRCODE_IO_ABORT;
1961cdf0e10cSrcweir             	}
1962cdf0e10cSrcweir         	}
1963cdf0e10cSrcweir 
1964cdf0e10cSrcweir 			if ( m_pData->m_pObjectShell->GetMedium() != pMedium )
1965cdf0e10cSrcweir 			{
1966cdf0e10cSrcweir 				// for whatever reason document now has another medium
1967cdf0e10cSrcweir 				DBG_ERROR("Document has rejected the medium?!");
1968cdf0e10cSrcweir 				delete pMedium;
1969cdf0e10cSrcweir 			}
1970cdf0e10cSrcweir 
1971cdf0e10cSrcweir             if ( !bWarning )    // #i30711# don't abort loading if it's only a warning
1972cdf0e10cSrcweir             {
1973cdf0e10cSrcweir                 throw task::ErrorCodeIOException( ::rtl::OUString(),
1974cdf0e10cSrcweir                                                     uno::Reference< uno::XInterface >(),
1975cdf0e10cSrcweir                                                     nError ? nError : ERRCODE_IO_CANTREAD );
1976cdf0e10cSrcweir             }
1977cdf0e10cSrcweir 		}
1978cdf0e10cSrcweir 
1979cdf0e10cSrcweir 		sal_Bool bHidden = sal_False;
1980cdf0e10cSrcweir 		SFX_ITEMSET_ARG( pMedium->GetItemSet(), pHidItem, SfxBoolItem, SID_HIDDEN, sal_False);
1981cdf0e10cSrcweir 		if ( pHidItem )
1982cdf0e10cSrcweir 			bHidden = pHidItem->GetValue();
1983cdf0e10cSrcweir 
1984cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
1985cdf0e10cSrcweir 		SFX_ITEMSET_ARG( pMedium->GetItemSet(), pPasswdItem, SfxStringItem, SID_PASSWORD, sal_False);
1986cdf0e10cSrcweir         OSL_ENSURE( !pPasswdItem, "There should be no Password property in the document MediaDescriptor!" );
1987cdf0e10cSrcweir #endif
1988cdf0e10cSrcweir 		// !TODO: will be done by Framework!
1989cdf0e10cSrcweir     	pMedium->SetUpdatePickList( !bHidden );
1990cdf0e10cSrcweir 	}
1991cdf0e10cSrcweir }
1992cdf0e10cSrcweir 
1993cdf0e10cSrcweir //________________________________________________________________________________________________________
1994cdf0e10cSrcweir // XTransferable
1995cdf0e10cSrcweir //________________________________________________________________________________________________________
1996cdf0e10cSrcweir 
getTransferData(const DATAFLAVOR & aFlavor)1997cdf0e10cSrcweir uno::Any SAL_CALL SfxBaseModel::getTransferData( const DATAFLAVOR& aFlavor )
1998cdf0e10cSrcweir 		throw (::com::sun::star::datatransfer::UnsupportedFlavorException,
1999cdf0e10cSrcweir 			   ::com::sun::star::io::IOException,
2000cdf0e10cSrcweir 			   ::com::sun::star::uno::RuntimeException)
2001cdf0e10cSrcweir {
2002cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
2003cdf0e10cSrcweir 
2004cdf0e10cSrcweir     uno::Any aAny;
2005cdf0e10cSrcweir 
2006cdf0e10cSrcweir 	if ( m_pData->m_pObjectShell.Is() )
2007cdf0e10cSrcweir 	{
2008cdf0e10cSrcweir         if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"" ) )
2009cdf0e10cSrcweir 		{
2010cdf0e10cSrcweir 			if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2011cdf0e10cSrcweir 			{
2012cdf0e10cSrcweir                 TransferableObjectDescriptor aDesc;
2013cdf0e10cSrcweir 
2014cdf0e10cSrcweir                 aDesc.maClassName = m_pData->m_pObjectShell->GetClassName();
2015cdf0e10cSrcweir                 aDesc.maTypeName = aFlavor.HumanPresentableName;
2016cdf0e10cSrcweir 
2017cdf0e10cSrcweir                 // TODO/LATER: ViewAspect needs to be sal_Int64
2018cdf0e10cSrcweir                 aDesc.mnViewAspect = sal::static_int_cast< sal_uInt16 >( embed::Aspects::MSOLE_CONTENT );
2019cdf0e10cSrcweir 
2020cdf0e10cSrcweir                 //TODO/LATER: status needs to become sal_Int64
2021cdf0e10cSrcweir                 aDesc.mnOle2Misc = m_pData->m_pObjectShell->GetMiscStatus();
2022cdf0e10cSrcweir                 Size aSize = m_pData->m_pObjectShell->GetVisArea().GetSize();
2023cdf0e10cSrcweir 
2024cdf0e10cSrcweir                 MapUnit aMapUnit = m_pData->m_pObjectShell->GetMapUnit();
2025cdf0e10cSrcweir                 aDesc.maSize = OutputDevice::LogicToLogic( aSize, aMapUnit, MAP_100TH_MM );
2026cdf0e10cSrcweir                 aDesc.maDragStartPos = Point();
2027cdf0e10cSrcweir                 aDesc.maDisplayName = String();
2028cdf0e10cSrcweir                 aDesc.mbCanLink = sal_False;
2029cdf0e10cSrcweir 
2030cdf0e10cSrcweir                 SvMemoryStream aMemStm( 1024, 1024 );
2031cdf0e10cSrcweir                 aMemStm << aDesc;
2032cdf0e10cSrcweir                 aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Tell() );
2033cdf0e10cSrcweir 			}
2034cdf0e10cSrcweir 			else
2035cdf0e10cSrcweir                 throw datatransfer::UnsupportedFlavorException();
2036cdf0e10cSrcweir 		}
2037cdf0e10cSrcweir         else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-embed-source;windows_formatname=\"Star EMBS\"" ) )
2038cdf0e10cSrcweir 		{
2039cdf0e10cSrcweir 			if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2040cdf0e10cSrcweir 			{
2041cdf0e10cSrcweir                 try
2042cdf0e10cSrcweir                 {
2043cdf0e10cSrcweir                     utl::TempFile aTmp;
2044cdf0e10cSrcweir                     aTmp.EnableKillingFile( sal_True );
2045cdf0e10cSrcweir                     storeToURL( aTmp.GetURL(), uno::Sequence < beans::PropertyValue >() );
2046cdf0e10cSrcweir                     SvStream* pStream = aTmp.GetStream( STREAM_READ );
2047cdf0e10cSrcweir                     const sal_uInt32 nLen = pStream->Seek( STREAM_SEEK_TO_END );
2048cdf0e10cSrcweir                     ::com::sun::star::uno::Sequence< sal_Int8 > aSeq( nLen );
2049cdf0e10cSrcweir                     pStream->Seek( STREAM_SEEK_TO_BEGIN );
2050cdf0e10cSrcweir                     pStream->Read( aSeq.getArray(),  nLen );
2051cdf0e10cSrcweir                     delete pStream;
2052cdf0e10cSrcweir                     if( aSeq.getLength() )
2053cdf0e10cSrcweir                         aAny <<= aSeq;
2054cdf0e10cSrcweir                 }
2055cdf0e10cSrcweir                 catch ( uno::Exception& )
2056cdf0e10cSrcweir                 {
2057cdf0e10cSrcweir                 }
2058cdf0e10cSrcweir 			}
2059cdf0e10cSrcweir 			else
2060cdf0e10cSrcweir                 throw datatransfer::UnsupportedFlavorException();
2061cdf0e10cSrcweir 		}
2062cdf0e10cSrcweir         else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) )
2063cdf0e10cSrcweir 		{
2064cdf0e10cSrcweir 			if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2065cdf0e10cSrcweir 			{
2066cdf0e10cSrcweir 
2067cdf0e10cSrcweir                 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2068cdf0e10cSrcweir                     m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2069cdf0e10cSrcweir 
2070cdf0e10cSrcweir 				if ( pMetaFile )
2071cdf0e10cSrcweir 				{
2072cdf0e10cSrcweir 					SvMemoryStream aMemStm( 65535, 65535 );
2073cdf0e10cSrcweir                     aMemStm.SetVersion( SOFFICE_FILEFORMAT_CURRENT );
2074cdf0e10cSrcweir 
2075cdf0e10cSrcweir 					pMetaFile->Write( aMemStm );
2076cdf0e10cSrcweir 					aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ),
2077cdf0e10cSrcweir 													aMemStm.Seek( STREAM_SEEK_TO_END ) );
2078cdf0e10cSrcweir 				}
2079cdf0e10cSrcweir 			}
2080cdf0e10cSrcweir 			else
2081cdf0e10cSrcweir                 throw datatransfer::UnsupportedFlavorException();
2082cdf0e10cSrcweir 		}
2083cdf0e10cSrcweir         else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) )
2084cdf0e10cSrcweir 		{
2085cdf0e10cSrcweir 			if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2086cdf0e10cSrcweir 			{
2087cdf0e10cSrcweir                 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2088cdf0e10cSrcweir                     m_pData->m_pObjectShell->CreatePreviewMetaFile_Impl( sal_True, sal_True );
2089cdf0e10cSrcweir 
2090cdf0e10cSrcweir 				if ( pMetaFile )
2091cdf0e10cSrcweir 				{
2092cdf0e10cSrcweir 					SvMemoryStream aMemStm( 65535, 65535 );
2093cdf0e10cSrcweir                     aMemStm.SetVersion( SOFFICE_FILEFORMAT_CURRENT );
2094cdf0e10cSrcweir 
2095cdf0e10cSrcweir 					pMetaFile->Write( aMemStm );
2096cdf0e10cSrcweir 					aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ),
2097cdf0e10cSrcweir 													aMemStm.Seek( STREAM_SEEK_TO_END ) );
2098cdf0e10cSrcweir 				}
2099cdf0e10cSrcweir 			}
2100cdf0e10cSrcweir 			else
2101cdf0e10cSrcweir                 throw datatransfer::UnsupportedFlavorException();
2102cdf0e10cSrcweir 		}
2103cdf0e10cSrcweir         else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) )
2104cdf0e10cSrcweir 		{
2105cdf0e10cSrcweir 			if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2106cdf0e10cSrcweir 			{
2107cdf0e10cSrcweir                 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2108cdf0e10cSrcweir                     m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2109cdf0e10cSrcweir 
2110cdf0e10cSrcweir 				if ( pMetaFile )
2111cdf0e10cSrcweir 				{
2112cdf0e10cSrcweir                     ::boost::shared_ptr<SvMemoryStream> pStream(
2113cdf0e10cSrcweir                         GraphicHelper::getFormatStrFromGDI_Impl(
2114cdf0e10cSrcweir                             pMetaFile.get(), CVT_EMF ) );
2115cdf0e10cSrcweir 					if ( pStream )
2116cdf0e10cSrcweir 					{
2117cdf0e10cSrcweir                     	pStream->SetVersion( SOFFICE_FILEFORMAT_CURRENT );
2118cdf0e10cSrcweir 						aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( pStream->GetData() ),
2119cdf0e10cSrcweir 														pStream->Seek( STREAM_SEEK_TO_END ) );
2120cdf0e10cSrcweir 					}
2121cdf0e10cSrcweir 				}
2122cdf0e10cSrcweir 			}
2123cdf0e10cSrcweir 			else if ( GraphicHelper::supportsMetaFileHandle_Impl()
2124cdf0e10cSrcweir 			  && aFlavor.DataType == getCppuType( (const sal_uInt64*) 0 ) )
2125cdf0e10cSrcweir 			{
2126cdf0e10cSrcweir                 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2127cdf0e10cSrcweir                     m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2128cdf0e10cSrcweir 
2129cdf0e10cSrcweir 				if ( pMetaFile )
2130cdf0e10cSrcweir 				{
2131cdf0e10cSrcweir 					aAny <<= reinterpret_cast< const sal_uInt64 >(
2132cdf0e10cSrcweir                         GraphicHelper::getEnhMetaFileFromGDI_Impl( pMetaFile.get() ) );
2133cdf0e10cSrcweir 				}
2134cdf0e10cSrcweir 			}
2135cdf0e10cSrcweir 			else
2136cdf0e10cSrcweir                 throw datatransfer::UnsupportedFlavorException();
2137cdf0e10cSrcweir 		}
2138cdf0e10cSrcweir         else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) )
2139cdf0e10cSrcweir 		{
2140cdf0e10cSrcweir 			if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2141cdf0e10cSrcweir 			{
2142cdf0e10cSrcweir                 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2143cdf0e10cSrcweir                     m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2144cdf0e10cSrcweir 
2145cdf0e10cSrcweir 				if ( pMetaFile )
2146cdf0e10cSrcweir 				{
2147cdf0e10cSrcweir                     ::boost::shared_ptr<SvMemoryStream> pStream(
2148cdf0e10cSrcweir                         GraphicHelper::getFormatStrFromGDI_Impl(
2149cdf0e10cSrcweir                             pMetaFile.get(), CVT_WMF ) );
2150cdf0e10cSrcweir 
2151cdf0e10cSrcweir 					if ( pStream )
2152cdf0e10cSrcweir 					{
2153cdf0e10cSrcweir                     	pStream->SetVersion( SOFFICE_FILEFORMAT_CURRENT );
2154cdf0e10cSrcweir 						aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( pStream->GetData() ),
2155cdf0e10cSrcweir 														pStream->Seek( STREAM_SEEK_TO_END ) );
2156cdf0e10cSrcweir 					}
2157cdf0e10cSrcweir 				}
2158cdf0e10cSrcweir 			}
2159cdf0e10cSrcweir 			else if ( GraphicHelper::supportsMetaFileHandle_Impl()
2160cdf0e10cSrcweir 			  && aFlavor.DataType == getCppuType( (const sal_uInt64*) 0 ) )
2161cdf0e10cSrcweir 			{
2162cdf0e10cSrcweir 				// means HGLOBAL handler to memory storage containing METAFILEPICT structure
2163cdf0e10cSrcweir 
2164cdf0e10cSrcweir                 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2165cdf0e10cSrcweir                     m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2166cdf0e10cSrcweir 
2167cdf0e10cSrcweir 				if ( pMetaFile )
2168cdf0e10cSrcweir 				{
2169cdf0e10cSrcweir 					Size aMetaSize = pMetaFile->GetPrefSize();
2170cdf0e10cSrcweir 					aAny <<= reinterpret_cast< const sal_uInt64 >(
2171cdf0e10cSrcweir                         GraphicHelper::getWinMetaFileFromGDI_Impl(
2172cdf0e10cSrcweir                             pMetaFile.get(), aMetaSize ) );
2173cdf0e10cSrcweir 				}
2174cdf0e10cSrcweir 			}
2175cdf0e10cSrcweir 			else
2176cdf0e10cSrcweir                 throw datatransfer::UnsupportedFlavorException();
2177cdf0e10cSrcweir 		}
2178cdf0e10cSrcweir         else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ) )
2179cdf0e10cSrcweir 		{
2180cdf0e10cSrcweir 			if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2181cdf0e10cSrcweir 			{
2182cdf0e10cSrcweir                 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2183cdf0e10cSrcweir                     m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2184cdf0e10cSrcweir 
2185cdf0e10cSrcweir 				if ( pMetaFile )
2186cdf0e10cSrcweir 				{
2187cdf0e10cSrcweir                     ::boost::shared_ptr<SvMemoryStream> pStream(
2188cdf0e10cSrcweir                         GraphicHelper::getFormatStrFromGDI_Impl(
2189cdf0e10cSrcweir                             pMetaFile.get(), CVT_BMP ) );
2190cdf0e10cSrcweir 
2191cdf0e10cSrcweir 					if ( pStream )
2192cdf0e10cSrcweir 					{
2193cdf0e10cSrcweir                     	pStream->SetVersion( SOFFICE_FILEFORMAT_CURRENT );
2194cdf0e10cSrcweir 						aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( pStream->GetData() ),
2195cdf0e10cSrcweir 														pStream->Seek( STREAM_SEEK_TO_END ) );
2196cdf0e10cSrcweir 					}
2197cdf0e10cSrcweir 				}
2198cdf0e10cSrcweir 			}
2199cdf0e10cSrcweir 			else
2200cdf0e10cSrcweir                 throw datatransfer::UnsupportedFlavorException();
2201cdf0e10cSrcweir 		}
2202cdf0e10cSrcweir 		else if ( aFlavor.MimeType.equalsAscii( "image/png" ) )
2203cdf0e10cSrcweir 		{
2204cdf0e10cSrcweir 			if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2205cdf0e10cSrcweir 			{
2206cdf0e10cSrcweir                 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2207cdf0e10cSrcweir                     m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2208cdf0e10cSrcweir 
2209cdf0e10cSrcweir 				if ( pMetaFile )
2210cdf0e10cSrcweir 				{
2211cdf0e10cSrcweir                     ::boost::shared_ptr<SvMemoryStream> pStream(
2212cdf0e10cSrcweir                         GraphicHelper::getFormatStrFromGDI_Impl(
2213cdf0e10cSrcweir                             pMetaFile.get(), CVT_PNG ) );
2214cdf0e10cSrcweir 
2215cdf0e10cSrcweir 					if ( pStream )
2216cdf0e10cSrcweir 					{
2217cdf0e10cSrcweir                     	pStream->SetVersion( SOFFICE_FILEFORMAT_CURRENT );
2218cdf0e10cSrcweir 						aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( pStream->GetData() ),
2219cdf0e10cSrcweir 														pStream->Seek( STREAM_SEEK_TO_END ) );
2220cdf0e10cSrcweir 					}
2221cdf0e10cSrcweir 				}
2222cdf0e10cSrcweir 			}
2223cdf0e10cSrcweir 			else
2224cdf0e10cSrcweir                 throw datatransfer::UnsupportedFlavorException();
2225cdf0e10cSrcweir 		}
2226cdf0e10cSrcweir         else
2227cdf0e10cSrcweir             throw datatransfer::UnsupportedFlavorException();
2228cdf0e10cSrcweir 	}
2229cdf0e10cSrcweir 
2230cdf0e10cSrcweir 	return aAny;
2231cdf0e10cSrcweir }
2232cdf0e10cSrcweir 
2233cdf0e10cSrcweir //________________________________________________________________________________________________________
2234cdf0e10cSrcweir // XTransferable
2235cdf0e10cSrcweir //________________________________________________________________________________________________________
2236cdf0e10cSrcweir 
2237cdf0e10cSrcweir 
getTransferDataFlavors()2238cdf0e10cSrcweir uno::Sequence< DATAFLAVOR > SAL_CALL SfxBaseModel::getTransferDataFlavors()
2239cdf0e10cSrcweir 		throw (::com::sun::star::uno::RuntimeException)
2240cdf0e10cSrcweir {
2241cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
2242cdf0e10cSrcweir 
2243cdf0e10cSrcweir     sal_Int32 nSuppFlavors = GraphicHelper::supportsMetaFileHandle_Impl() ? 10 : 8;
2244cdf0e10cSrcweir     uno::Sequence< DATAFLAVOR > aFlavorSeq( nSuppFlavors );
2245cdf0e10cSrcweir 
2246cdf0e10cSrcweir 	aFlavorSeq[0].MimeType =
2247cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) );
2248cdf0e10cSrcweir 	aFlavorSeq[0].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "GDIMetaFile" ) );
2249cdf0e10cSrcweir 	aFlavorSeq[0].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2250cdf0e10cSrcweir 
2251cdf0e10cSrcweir 	aFlavorSeq[1].MimeType =
2252cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) );
2253cdf0e10cSrcweir 	aFlavorSeq[1].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "GDIMetaFile" ) );
2254cdf0e10cSrcweir 	aFlavorSeq[1].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2255cdf0e10cSrcweir 
2256cdf0e10cSrcweir 	aFlavorSeq[2].MimeType =
2257cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) );
2258cdf0e10cSrcweir 	aFlavorSeq[2].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enhanced Windows MetaFile" ) );
2259cdf0e10cSrcweir 	aFlavorSeq[2].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2260cdf0e10cSrcweir 
2261cdf0e10cSrcweir 	aFlavorSeq[3].MimeType =
2262cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) );
2263cdf0e10cSrcweir 	aFlavorSeq[3].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Windows MetaFile" ) );
2264cdf0e10cSrcweir 	aFlavorSeq[3].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2265cdf0e10cSrcweir 
2266cdf0e10cSrcweir     aFlavorSeq[4].MimeType =
2267cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"" ) );
2268cdf0e10cSrcweir     aFlavorSeq[4].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Star Object Descriptor (XML)" ) );
2269cdf0e10cSrcweir     aFlavorSeq[4].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2270cdf0e10cSrcweir 
2271cdf0e10cSrcweir     aFlavorSeq[5].MimeType =
2272cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-embed-source-xml;windows_formatname=\"Star Embed Source (XML)\"" ) );
2273cdf0e10cSrcweir     aFlavorSeq[5].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Star Embed Source (XML)" ) );
2274cdf0e10cSrcweir     aFlavorSeq[5].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2275cdf0e10cSrcweir 
2276cdf0e10cSrcweir     aFlavorSeq[6].MimeType =
2277cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ) );
2278cdf0e10cSrcweir     aFlavorSeq[6].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Bitmap" ) );
2279cdf0e10cSrcweir     aFlavorSeq[6].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2280cdf0e10cSrcweir 
2281cdf0e10cSrcweir     aFlavorSeq[7].MimeType =
2282cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "image/png" ) );
2283cdf0e10cSrcweir     aFlavorSeq[7].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PNG" ) );
2284cdf0e10cSrcweir     aFlavorSeq[7].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2285cdf0e10cSrcweir 
2286cdf0e10cSrcweir     if ( nSuppFlavors == 10 )
2287cdf0e10cSrcweir 	{
2288cdf0e10cSrcweir         aFlavorSeq[8].MimeType =
2289cdf0e10cSrcweir             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) );
2290cdf0e10cSrcweir         aFlavorSeq[8].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enhanced Windows MetaFile" ) );
2291cdf0e10cSrcweir         aFlavorSeq[8].DataType = getCppuType( (const sal_uInt64*) 0 );
2292cdf0e10cSrcweir 
2293cdf0e10cSrcweir         aFlavorSeq[9].MimeType =
2294cdf0e10cSrcweir             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) );
2295cdf0e10cSrcweir         aFlavorSeq[9].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Windows MetaFile" ) );
2296cdf0e10cSrcweir         aFlavorSeq[9].DataType = getCppuType( (const sal_uInt64*) 0 );
2297cdf0e10cSrcweir 	}
2298cdf0e10cSrcweir 
2299cdf0e10cSrcweir 	return aFlavorSeq;
2300cdf0e10cSrcweir }
2301cdf0e10cSrcweir 
2302cdf0e10cSrcweir //________________________________________________________________________________________________________
2303cdf0e10cSrcweir // XTransferable
2304cdf0e10cSrcweir //________________________________________________________________________________________________________
2305cdf0e10cSrcweir 
2306cdf0e10cSrcweir 
isDataFlavorSupported(const DATAFLAVOR & aFlavor)2307cdf0e10cSrcweir sal_Bool SAL_CALL SfxBaseModel::isDataFlavorSupported( const DATAFLAVOR& aFlavor )
2308cdf0e10cSrcweir 		throw (::com::sun::star::uno::RuntimeException)
2309cdf0e10cSrcweir {
2310cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
2311cdf0e10cSrcweir 
2312cdf0e10cSrcweir     if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) )
2313cdf0e10cSrcweir 	{
2314cdf0e10cSrcweir 		if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2315cdf0e10cSrcweir 			return sal_True;
2316cdf0e10cSrcweir 	}
2317cdf0e10cSrcweir     else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) )
2318cdf0e10cSrcweir 	{
2319cdf0e10cSrcweir 		if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2320cdf0e10cSrcweir 			return sal_True;
2321cdf0e10cSrcweir 	}
2322cdf0e10cSrcweir     else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) )
2323cdf0e10cSrcweir 	{
2324cdf0e10cSrcweir 		if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2325cdf0e10cSrcweir 			return sal_True;
2326cdf0e10cSrcweir 		else if ( GraphicHelper::supportsMetaFileHandle_Impl()
2327cdf0e10cSrcweir 		  && aFlavor.DataType == getCppuType( (const sal_uInt64*) 0 ) )
2328cdf0e10cSrcweir 			return sal_True;
2329cdf0e10cSrcweir 	}
2330cdf0e10cSrcweir     else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) )
2331cdf0e10cSrcweir 	{
2332cdf0e10cSrcweir 		if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2333cdf0e10cSrcweir 			return sal_True;
2334cdf0e10cSrcweir 		else if ( GraphicHelper::supportsMetaFileHandle_Impl()
2335cdf0e10cSrcweir 		  && aFlavor.DataType == getCppuType( (const sal_uInt64*) 0 ) )
2336cdf0e10cSrcweir 			return sal_True;
2337cdf0e10cSrcweir 	}
2338cdf0e10cSrcweir     else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"" ) )
2339cdf0e10cSrcweir     {
2340cdf0e10cSrcweir         if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2341cdf0e10cSrcweir 			return sal_True;
2342cdf0e10cSrcweir     }
2343cdf0e10cSrcweir     else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-embed-source;windows_formatname=\"Star EMBS\"" ) )
2344cdf0e10cSrcweir     {
2345cdf0e10cSrcweir         if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2346cdf0e10cSrcweir 			return sal_True;
2347cdf0e10cSrcweir     }
2348cdf0e10cSrcweir     else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ) )
2349cdf0e10cSrcweir 	{
2350cdf0e10cSrcweir 		if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2351cdf0e10cSrcweir 			return sal_True;
2352cdf0e10cSrcweir 	}
2353cdf0e10cSrcweir 	else if ( aFlavor.MimeType.equalsAscii( "image/png" ) )
2354cdf0e10cSrcweir 	{
2355cdf0e10cSrcweir 		if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2356cdf0e10cSrcweir 			return sal_True;
2357cdf0e10cSrcweir 	}
2358cdf0e10cSrcweir 
2359cdf0e10cSrcweir 	return sal_False;
2360cdf0e10cSrcweir }
2361cdf0e10cSrcweir 
2362cdf0e10cSrcweir 
2363cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
2364cdf0e10cSrcweir //	XEventsSupplier
2365cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
2366cdf0e10cSrcweir 
getEvents()2367cdf0e10cSrcweir uno::Reference< container::XNameReplace > SAL_CALL SfxBaseModel::getEvents() throw( uno::RuntimeException )
2368cdf0e10cSrcweir {
2369cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
2370cdf0e10cSrcweir 
2371cdf0e10cSrcweir 	if ( ! m_pData->m_xEvents.is() )
2372cdf0e10cSrcweir 	{
2373cdf0e10cSrcweir 		m_pData->m_xEvents = new SfxEvents_Impl( m_pData->m_pObjectShell, this );
2374cdf0e10cSrcweir 	}
2375cdf0e10cSrcweir 
2376cdf0e10cSrcweir 	return m_pData->m_xEvents;
2377cdf0e10cSrcweir }
2378cdf0e10cSrcweir 
2379cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
2380cdf0e10cSrcweir //	XEmbeddedScripts
2381cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
2382cdf0e10cSrcweir 
getBasicLibraries()2383cdf0e10cSrcweir uno::Reference< script::XStorageBasedLibraryContainer > SAL_CALL SfxBaseModel::getBasicLibraries() throw (RuntimeException)
2384cdf0e10cSrcweir {
2385cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
2386cdf0e10cSrcweir 
2387cdf0e10cSrcweir     uno::Reference< script::XStorageBasedLibraryContainer > xBasicLibraries;
2388cdf0e10cSrcweir     if ( m_pData->m_pObjectShell )
2389cdf0e10cSrcweir         xBasicLibraries.set( m_pData->m_pObjectShell->GetBasicContainer(), UNO_QUERY_THROW );
2390cdf0e10cSrcweir     return xBasicLibraries;
2391cdf0e10cSrcweir }
2392cdf0e10cSrcweir 
getDialogLibraries()2393cdf0e10cSrcweir uno::Reference< script::XStorageBasedLibraryContainer > SAL_CALL SfxBaseModel::getDialogLibraries() throw (RuntimeException)
2394cdf0e10cSrcweir {
2395cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
2396cdf0e10cSrcweir 
2397cdf0e10cSrcweir     uno::Reference< script::XStorageBasedLibraryContainer > xDialogLibraries;
2398cdf0e10cSrcweir     if ( m_pData->m_pObjectShell )
2399cdf0e10cSrcweir         xDialogLibraries.set( m_pData->m_pObjectShell->GetDialogContainer(), UNO_QUERY_THROW );
2400cdf0e10cSrcweir     return xDialogLibraries;
2401cdf0e10cSrcweir }
2402cdf0e10cSrcweir 
getAllowMacroExecution()2403cdf0e10cSrcweir ::sal_Bool SAL_CALL SfxBaseModel::getAllowMacroExecution() throw (RuntimeException)
2404cdf0e10cSrcweir {
2405cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
2406cdf0e10cSrcweir 
2407cdf0e10cSrcweir     if ( m_pData->m_pObjectShell )
2408cdf0e10cSrcweir         return m_pData->m_pObjectShell->AdjustMacroMode( String(), false );
2409cdf0e10cSrcweir     return sal_False;
2410cdf0e10cSrcweir }
2411cdf0e10cSrcweir 
2412cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
2413cdf0e10cSrcweir //	XScriptInvocationContext
2414cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
2415cdf0e10cSrcweir 
getScriptContainer()2416cdf0e10cSrcweir Reference< document::XEmbeddedScripts > SAL_CALL SfxBaseModel::getScriptContainer() throw (RuntimeException)
2417cdf0e10cSrcweir {
2418cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
2419cdf0e10cSrcweir 
2420cdf0e10cSrcweir     Reference< document::XEmbeddedScripts > xDocumentScripts;
2421cdf0e10cSrcweir 
2422cdf0e10cSrcweir     try
2423cdf0e10cSrcweir     {
2424cdf0e10cSrcweir         Reference< frame::XModel > xDocument( this );
2425cdf0e10cSrcweir         xDocumentScripts.set( xDocument, uno::UNO_QUERY );
2426cdf0e10cSrcweir         while ( !xDocumentScripts.is() && xDocument.is() )
2427cdf0e10cSrcweir         {
2428cdf0e10cSrcweir             Reference< container::XChild > xDocAsChild( xDocument, uno::UNO_QUERY );
2429cdf0e10cSrcweir             if ( !xDocAsChild.is() )
2430cdf0e10cSrcweir             {
2431cdf0e10cSrcweir                 xDocument = NULL;
2432cdf0e10cSrcweir                 break;
2433cdf0e10cSrcweir             }
2434cdf0e10cSrcweir 
2435cdf0e10cSrcweir             xDocument.set( xDocAsChild->getParent(), uno::UNO_QUERY );
2436cdf0e10cSrcweir             xDocumentScripts.set( xDocument, uno::UNO_QUERY );
2437cdf0e10cSrcweir         }
2438cdf0e10cSrcweir     }
2439cdf0e10cSrcweir     catch( const Exception& )
2440cdf0e10cSrcweir     {
2441cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
2442cdf0e10cSrcweir         xDocumentScripts = NULL;
2443cdf0e10cSrcweir     }
2444cdf0e10cSrcweir 
2445cdf0e10cSrcweir     return xDocumentScripts;
2446cdf0e10cSrcweir }
2447cdf0e10cSrcweir 
2448cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
2449cdf0e10cSrcweir //	XEventBroadcaster
2450cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
2451cdf0e10cSrcweir 
addEventListener(const uno::Reference<XDOCEVENTLISTENER> & aListener)2452cdf0e10cSrcweir void SAL_CALL SfxBaseModel::addEventListener( const uno::Reference< XDOCEVENTLISTENER >& aListener ) throw( uno::RuntimeException )
2453cdf0e10cSrcweir {
2454cdf0e10cSrcweir     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
2455cdf0e10cSrcweir 
2456cdf0e10cSrcweir     m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0), aListener );
2457cdf0e10cSrcweir }
2458cdf0e10cSrcweir 
2459cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
2460cdf0e10cSrcweir //	XEventBroadcaster
2461cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
2462cdf0e10cSrcweir 
removeEventListener(const uno::Reference<XDOCEVENTLISTENER> & aListener)2463cdf0e10cSrcweir void SAL_CALL SfxBaseModel::removeEventListener( const uno::Reference< XDOCEVENTLISTENER >& aListener ) throw( uno::RuntimeException )
2464cdf0e10cSrcweir {
2465cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
2466cdf0e10cSrcweir 
2467cdf0e10cSrcweir     m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0), aListener );
2468cdf0e10cSrcweir }
2469cdf0e10cSrcweir 
2470cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
2471cdf0e10cSrcweir //	XDocumentEventBroadcaster
2472cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
2473cdf0e10cSrcweir // ---------------------------------
addDocumentEventListener(const uno::Reference<document::XDocumentEventListener> & aListener)2474cdf0e10cSrcweir void SAL_CALL SfxBaseModel::addDocumentEventListener( const uno::Reference< document::XDocumentEventListener >& aListener )
2475cdf0e10cSrcweir     throw ( uno::RuntimeException )
2476cdf0e10cSrcweir {
2477cdf0e10cSrcweir     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
2478cdf0e10cSrcweir     m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< document::XDocumentEventListener >*)0), aListener );
2479cdf0e10cSrcweir }
2480cdf0e10cSrcweir 
2481cdf0e10cSrcweir // ---------------------------------
removeDocumentEventListener(const uno::Reference<document::XDocumentEventListener> & aListener)2482cdf0e10cSrcweir void SAL_CALL SfxBaseModel::removeDocumentEventListener( const uno::Reference< document::XDocumentEventListener >& aListener )
2483cdf0e10cSrcweir     throw ( uno::RuntimeException )
2484cdf0e10cSrcweir {
2485cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
2486cdf0e10cSrcweir     m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< document::XDocumentEventListener >*)0), aListener );
2487cdf0e10cSrcweir }
2488cdf0e10cSrcweir 
2489cdf0e10cSrcweir // ---------------------------------
notifyDocumentEvent(const::rtl::OUString &,const uno::Reference<frame::XController2> &,const uno::Any &)2490cdf0e10cSrcweir void SAL_CALL SfxBaseModel::notifyDocumentEvent( const ::rtl::OUString&, const uno::Reference< frame::XController2 >&, const uno::Any& )
2491cdf0e10cSrcweir     throw ( lang::IllegalArgumentException, lang::NoSupportException, uno::RuntimeException )
2492cdf0e10cSrcweir {
2493cdf0e10cSrcweir     throw lang::NoSupportException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SfxBaseModel controlls all the sent notifications itself!" ) ), uno::Reference< uno::XInterface >() );
2494cdf0e10cSrcweir }
2495cdf0e10cSrcweir 
2496cdf0e10cSrcweir //________________________________________________________________________________________________________
2497cdf0e10cSrcweir //	SfxListener
2498cdf0e10cSrcweir //________________________________________________________________________________________________________
2499cdf0e10cSrcweir 
addTitle_Impl(Sequence<::com::sun::star::beans::PropertyValue> & rSeq,const::rtl::OUString & rTitle)2500cdf0e10cSrcweir void addTitle_Impl( Sequence < ::com::sun::star::beans::PropertyValue >& rSeq, const ::rtl::OUString& rTitle )
2501cdf0e10cSrcweir {
2502cdf0e10cSrcweir     sal_Int32 nCount = rSeq.getLength();
2503cdf0e10cSrcweir     sal_Int32 nArg;
2504cdf0e10cSrcweir 
2505cdf0e10cSrcweir     for ( nArg = 0; nArg < nCount; nArg++ )
2506cdf0e10cSrcweir     {
2507cdf0e10cSrcweir         ::com::sun::star::beans::PropertyValue& rProp = rSeq[nArg];
2508cdf0e10cSrcweir         if ( rProp.Name.equalsAscii("Title") )
2509cdf0e10cSrcweir         {
2510cdf0e10cSrcweir             rProp.Value <<= rTitle;
2511cdf0e10cSrcweir             break;
2512cdf0e10cSrcweir         }
2513cdf0e10cSrcweir     }
2514cdf0e10cSrcweir 
2515cdf0e10cSrcweir     if ( nArg == nCount )
2516cdf0e10cSrcweir     {
2517cdf0e10cSrcweir         rSeq.realloc( nCount+1 );
2518cdf0e10cSrcweir         rSeq[nCount].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Title") );
2519cdf0e10cSrcweir         rSeq[nCount].Value <<= rTitle;
2520cdf0e10cSrcweir     }
2521cdf0e10cSrcweir }
2522cdf0e10cSrcweir 
NotifyStorageListeners_Impl()2523cdf0e10cSrcweir void SfxBaseModel::NotifyStorageListeners_Impl()
2524cdf0e10cSrcweir {
2525cdf0e10cSrcweir 	uno::Reference< uno::XInterface > xSelfHold( static_cast< ::cppu::OWeakObject* >(this) );
2526cdf0e10cSrcweir 
2527cdf0e10cSrcweir 	if ( m_pData->m_pObjectShell )
2528cdf0e10cSrcweir 	{
2529cdf0e10cSrcweir     	::cppu::OInterfaceContainerHelper* pContainer =
2530cdf0e10cSrcweir 			m_pData->m_aInterfaceContainer.getContainer(
2531cdf0e10cSrcweir 				::getCppuType( ( const uno::Reference< document::XStorageChangeListener >*) NULL ) );
2532cdf0e10cSrcweir     	if ( pContainer != NULL )
2533cdf0e10cSrcweir 		{
2534cdf0e10cSrcweir 			uno::Reference< embed::XStorage > xNewStorage = m_pData->m_pObjectShell->GetStorage();
2535cdf0e10cSrcweir         	::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
2536cdf0e10cSrcweir         	while ( pIterator.hasMoreElements() )
2537cdf0e10cSrcweir         	{
2538cdf0e10cSrcweir             	try
2539cdf0e10cSrcweir             	{
2540cdf0e10cSrcweir                 	((document::XStorageChangeListener*)pIterator.next())->notifyStorageChange(
2541cdf0e10cSrcweir 																			xSelfHold,
2542cdf0e10cSrcweir 																			xNewStorage );
2543cdf0e10cSrcweir             	}
2544cdf0e10cSrcweir             	catch( uno::RuntimeException& )
2545cdf0e10cSrcweir             	{
2546cdf0e10cSrcweir                 	pIterator.remove();
2547cdf0e10cSrcweir             	}
2548cdf0e10cSrcweir         	}
2549cdf0e10cSrcweir 		}
2550cdf0e10cSrcweir 	}
2551cdf0e10cSrcweir }
2552cdf0e10cSrcweir 
Notify(SfxBroadcaster & rBC,const SfxHint & rHint)2553cdf0e10cSrcweir void SfxBaseModel::Notify(			SfxBroadcaster&	rBC		,
2554cdf0e10cSrcweir 	 						const	SfxHint&		rHint	)
2555cdf0e10cSrcweir {
2556cdf0e10cSrcweir 	if ( !m_pData )
2557cdf0e10cSrcweir 		return;
2558cdf0e10cSrcweir 
2559cdf0e10cSrcweir     if ( &rBC == m_pData->m_pObjectShell )
2560cdf0e10cSrcweir 	{
2561cdf0e10cSrcweir 		SfxSimpleHint* pSimpleHint = PTR_CAST( SfxSimpleHint, &rHint );
2562cdf0e10cSrcweir 		if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DOCCHANGED )
2563cdf0e10cSrcweir 			changing();
2564cdf0e10cSrcweir 
2565cdf0e10cSrcweir 		SfxEventHint* pNamedHint = PTR_CAST( SfxEventHint, &rHint );
2566cdf0e10cSrcweir 		if ( pNamedHint )
2567cdf0e10cSrcweir 		{
2568cdf0e10cSrcweir 
2569cdf0e10cSrcweir             switch ( pNamedHint->GetEventId() )
2570cdf0e10cSrcweir             {
2571cdf0e10cSrcweir             case SFX_EVENT_STORAGECHANGED:
2572cdf0e10cSrcweir 			{
2573cdf0e10cSrcweir 				// for now this event is sent only on creation of a new storage for new document
2574cdf0e10cSrcweir 				// and in case of reload of medium without document reload
2575cdf0e10cSrcweir 				// other events are used to detect storage change
2576cdf0e10cSrcweir 				// NotifyStorageListeners_Impl();
2577cdf0e10cSrcweir 
2578cdf0e10cSrcweir                 if ( m_pData->m_xUIConfigurationManager.is()
2579cdf0e10cSrcweir 				  && m_pData->m_pObjectShell->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED )
2580cdf0e10cSrcweir                 {
2581cdf0e10cSrcweir                     uno::Reference< XSTORAGE > xConfigStorage;
2582cdf0e10cSrcweir                     rtl::OUString aUIConfigFolderName( RTL_CONSTASCII_USTRINGPARAM( "Configurations2" ));
2583cdf0e10cSrcweir 
2584cdf0e10cSrcweir                     xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, com::sun::star::embed::ElementModes::READWRITE );
2585cdf0e10cSrcweir                     if ( !xConfigStorage.is() )
2586cdf0e10cSrcweir                         xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, com::sun::star::embed::ElementModes::READ );
2587cdf0e10cSrcweir 
2588cdf0e10cSrcweir 					if ( xConfigStorage.is() || !m_pData->m_pObjectShell->GetStorage()->hasByName( aUIConfigFolderName ) )
2589cdf0e10cSrcweir 					{
2590cdf0e10cSrcweir 						// the storage is different, since otherwise it could not be opened, so it must be exchanged
2591cdf0e10cSrcweir                         Reference< ui::XUIConfigurationStorage > xUIConfigStorage( m_pData->m_xUIConfigurationManager, uno::UNO_QUERY );
2592cdf0e10cSrcweir                     	xUIConfigStorage->setStorage( xConfigStorage );
2593cdf0e10cSrcweir 					}
2594cdf0e10cSrcweir 					else
2595cdf0e10cSrcweir 					{
2596cdf0e10cSrcweir 						OSL_ENSURE( sal_False, "Unexpected scenario!\n" );
2597cdf0e10cSrcweir 					}
2598cdf0e10cSrcweir                 }
2599cdf0e10cSrcweir 
2600cdf0e10cSrcweir 				ListenForStorage_Impl( m_pData->m_pObjectShell->GetStorage() );
2601cdf0e10cSrcweir 			}
2602cdf0e10cSrcweir             break;
2603cdf0e10cSrcweir 
2604cdf0e10cSrcweir             case SFX_EVENT_LOADFINISHED:
2605cdf0e10cSrcweir 			{
2606cdf0e10cSrcweir                 impl_getPrintHelper();
2607cdf0e10cSrcweir 				ListenForStorage_Impl( m_pData->m_pObjectShell->GetStorage() );
2608cdf0e10cSrcweir                 m_pData->m_bModifiedSinceLastSave = sal_False;
2609cdf0e10cSrcweir 			}
2610cdf0e10cSrcweir             break;
2611cdf0e10cSrcweir 
2612cdf0e10cSrcweir             case SFX_EVENT_SAVEASDOCDONE:
2613cdf0e10cSrcweir             {
2614cdf0e10cSrcweir 				m_pData->m_sURL = m_pData->m_pObjectShell->GetMedium()->GetName();
2615cdf0e10cSrcweir 
2616cdf0e10cSrcweir                 SfxItemSet *pSet = m_pData->m_pObjectShell->GetMedium()->GetItemSet();
2617cdf0e10cSrcweir                 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs;
2618cdf0e10cSrcweir                 ::rtl::OUString aTitle = m_pData->m_pObjectShell->GetTitle();
2619cdf0e10cSrcweir                 TransformItems( SID_SAVEASDOC, *pSet, aArgs );
2620cdf0e10cSrcweir                 addTitle_Impl( aArgs, aTitle );
2621cdf0e10cSrcweir                 attachResource( m_pData->m_pObjectShell->GetMedium()->GetName(), aArgs );
2622cdf0e10cSrcweir             }
2623cdf0e10cSrcweir             break;
2624cdf0e10cSrcweir 
2625cdf0e10cSrcweir             case SFX_EVENT_DOCCREATED:
2626cdf0e10cSrcweir             {
2627cdf0e10cSrcweir                 impl_getPrintHelper();
2628cdf0e10cSrcweir                 m_pData->m_bModifiedSinceLastSave = sal_False;
2629cdf0e10cSrcweir             }
2630cdf0e10cSrcweir             break;
2631cdf0e10cSrcweir 
2632cdf0e10cSrcweir             case SFX_EVENT_MODIFYCHANGED:
2633cdf0e10cSrcweir             {
2634cdf0e10cSrcweir                 m_pData->m_bModifiedSinceLastSave = isModified();
2635cdf0e10cSrcweir             }
2636cdf0e10cSrcweir             break;
2637cdf0e10cSrcweir             }
2638cdf0e10cSrcweir 
2639cdf0e10cSrcweir 
2640cdf0e10cSrcweir             SfxViewEventHint* pViewHint = PTR_CAST( SfxViewEventHint, &rHint );
2641cdf0e10cSrcweir 			postEvent_Impl( pNamedHint->GetEventName(), pViewHint ? pViewHint->GetController() : uno::Reference< frame::XController2 >() );
2642cdf0e10cSrcweir 		}
2643cdf0e10cSrcweir 
2644cdf0e10cSrcweir         if ( pSimpleHint )
2645cdf0e10cSrcweir 		{
2646cdf0e10cSrcweir 			if ( pSimpleHint->GetId() == SFX_HINT_TITLECHANGED )
2647cdf0e10cSrcweir         	{
2648cdf0e10cSrcweir             	::rtl::OUString aTitle = m_pData->m_pObjectShell->GetTitle();
2649cdf0e10cSrcweir             	addTitle_Impl( m_pData->m_seqArguments, aTitle );
2650cdf0e10cSrcweir 				postEvent_Impl( GlobalEventConfig::GetEventName( STR_EVENT_TITLECHANGED ) );
2651cdf0e10cSrcweir         	}
2652cdf0e10cSrcweir 			if ( pSimpleHint->GetId() == SFX_HINT_MODECHANGED )
2653cdf0e10cSrcweir         	{
2654cdf0e10cSrcweir 				postEvent_Impl( GlobalEventConfig::GetEventName( STR_EVENT_MODECHANGED ) );
2655cdf0e10cSrcweir         	}
2656cdf0e10cSrcweir /*
2657cdf0e10cSrcweir 			else if ( pSimpleHint->GetId() == SFX_HINT_DYING
2658cdf0e10cSrcweir 				|| pSimpleHint->GetId() == SFX_HINT_DEINITIALIZING )
2659cdf0e10cSrcweir 			{
2660cdf0e10cSrcweir         		SfxObjectShellLock pShellLock = m_pData->m_pObjectShellLock;
2661cdf0e10cSrcweir         		m_pData->m_pObjectShellLock = SfxObjectShellLock();
2662cdf0e10cSrcweir 			}
2663cdf0e10cSrcweir */
2664cdf0e10cSrcweir 		}
2665cdf0e10cSrcweir 	}
2666cdf0e10cSrcweir }
2667cdf0e10cSrcweir 
2668cdf0e10cSrcweir //________________________________________________________________________________________________________
2669cdf0e10cSrcweir //	public impl.
2670cdf0e10cSrcweir //________________________________________________________________________________________________________
2671cdf0e10cSrcweir 
NotifyModifyListeners_Impl() const2672cdf0e10cSrcweir void SfxBaseModel::NotifyModifyListeners_Impl() const
2673cdf0e10cSrcweir {
2674cdf0e10cSrcweir     ::cppu::OInterfaceContainerHelper* pIC = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType((const uno::Reference< XMODIFYLISTENER >*)0) );
2675cdf0e10cSrcweir 	if ( pIC )
2676cdf0e10cSrcweir 	{
2677cdf0e10cSrcweir         lang::EventObject aEvent( (frame::XModel *)this );
2678cdf0e10cSrcweir         pIC->notifyEach( &util::XModifyListener::modified, aEvent );
2679cdf0e10cSrcweir 	}
2680cdf0e10cSrcweir 
2681cdf0e10cSrcweir     // this notification here is done too generously, we cannot simply assume that we're really modified
2682cdf0e10cSrcweir     // now, but we need to check it ...
2683cdf0e10cSrcweir     m_pData->m_bModifiedSinceLastSave = const_cast< SfxBaseModel* >( this )->isModified();
2684cdf0e10cSrcweir }
2685cdf0e10cSrcweir 
changing()2686cdf0e10cSrcweir void SfxBaseModel::changing()
2687cdf0e10cSrcweir {
2688cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
2689cdf0e10cSrcweir 
2690cdf0e10cSrcweir     // the notification should not be sent if the document can not be modified
2691cdf0e10cSrcweir     if ( !m_pData->m_pObjectShell.Is() || !m_pData->m_pObjectShell->IsEnableSetModified() )
2692cdf0e10cSrcweir         return;
2693cdf0e10cSrcweir 
2694cdf0e10cSrcweir     NotifyModifyListeners_Impl();
2695cdf0e10cSrcweir }
2696cdf0e10cSrcweir 
impl_change()2697cdf0e10cSrcweir void SfxBaseModel::impl_change()
2698cdf0e10cSrcweir {
2699cdf0e10cSrcweir 	// object already disposed?
2700cdf0e10cSrcweir 	if ( impl_isDisposed() )
2701cdf0e10cSrcweir 		return;
2702cdf0e10cSrcweir 
2703cdf0e10cSrcweir     NotifyModifyListeners_Impl();
2704cdf0e10cSrcweir }
2705cdf0e10cSrcweir 
2706cdf0e10cSrcweir //________________________________________________________________________________________________________
2707cdf0e10cSrcweir //	public impl.
2708cdf0e10cSrcweir //________________________________________________________________________________________________________
2709cdf0e10cSrcweir 
GetObjectShell() const2710cdf0e10cSrcweir SfxObjectShell* SfxBaseModel::GetObjectShell() const
2711cdf0e10cSrcweir {
2712cdf0e10cSrcweir 	return m_pData ? (SfxObjectShell*) m_pData->m_pObjectShell : 0;
2713cdf0e10cSrcweir }
2714cdf0e10cSrcweir 
impl_getObjectShell() const2715cdf0e10cSrcweir SfxObjectShell* SfxBaseModel::impl_getObjectShell() const
2716cdf0e10cSrcweir {
2717cdf0e10cSrcweir 	return m_pData ? (SfxObjectShell*) m_pData->m_pObjectShell : 0;
2718cdf0e10cSrcweir }
2719cdf0e10cSrcweir 
2720cdf0e10cSrcweir //________________________________________________________________________________________________________
2721cdf0e10cSrcweir //	public impl.
2722cdf0e10cSrcweir //________________________________________________________________________________________________________
2723cdf0e10cSrcweir 
IsInitialized() const2724cdf0e10cSrcweir sal_Bool SfxBaseModel::IsInitialized() const
2725cdf0e10cSrcweir {
2726cdf0e10cSrcweir 	if ( !m_pData || !m_pData->m_pObjectShell )
2727cdf0e10cSrcweir     {
2728cdf0e10cSrcweir         OSL_ENSURE( false, "SfxBaseModel::IsInitialized: this should have been caught earlier!" );
2729cdf0e10cSrcweir         return sal_False;
2730cdf0e10cSrcweir     }
2731cdf0e10cSrcweir 
2732cdf0e10cSrcweir     return m_pData->m_pObjectShell->GetMedium() != NULL;
2733cdf0e10cSrcweir }
2734cdf0e10cSrcweir 
MethodEntryCheck(const bool i_mustBeInitialized) const2735cdf0e10cSrcweir void SfxBaseModel::MethodEntryCheck( const bool i_mustBeInitialized ) const
2736cdf0e10cSrcweir {
2737cdf0e10cSrcweir     if ( impl_isDisposed() )
2738cdf0e10cSrcweir         throw ::com::sun::star::lang::DisposedException( ::rtl::OUString(), *const_cast< SfxBaseModel* >( this ) );
2739cdf0e10cSrcweir     if ( i_mustBeInitialized && !IsInitialized() )
2740cdf0e10cSrcweir         throw ::com::sun::star::lang::NotInitializedException( ::rtl::OUString(), *const_cast< SfxBaseModel* >( this ) );
2741cdf0e10cSrcweir }
2742cdf0e10cSrcweir 
impl_isDisposed() const2743cdf0e10cSrcweir sal_Bool SfxBaseModel::impl_isDisposed() const
2744cdf0e10cSrcweir {
2745cdf0e10cSrcweir 	return ( m_pData == NULL ) ;
2746cdf0e10cSrcweir }
2747cdf0e10cSrcweir 
2748cdf0e10cSrcweir //________________________________________________________________________________________________________
2749cdf0e10cSrcweir //	private impl.
2750cdf0e10cSrcweir //________________________________________________________________________________________________________
2751cdf0e10cSrcweir 
GetMediumFilterName_Impl()2752cdf0e10cSrcweir ::rtl::OUString SfxBaseModel::GetMediumFilterName_Impl()
2753cdf0e10cSrcweir {
2754cdf0e10cSrcweir 	const SfxFilter* pFilter = NULL;
2755cdf0e10cSrcweir 	SfxMedium* pMedium = m_pData->m_pObjectShell->GetMedium();
2756cdf0e10cSrcweir 	if ( pMedium )
2757cdf0e10cSrcweir 		pFilter = pMedium->GetFilter();
2758cdf0e10cSrcweir 
2759cdf0e10cSrcweir 	if ( pFilter )
2760cdf0e10cSrcweir 		return pFilter->GetName();
2761cdf0e10cSrcweir 
2762cdf0e10cSrcweir 	return ::rtl::OUString();
2763cdf0e10cSrcweir }
2764cdf0e10cSrcweir 
impl_store(const::rtl::OUString & sURL,const uno::Sequence<beans::PropertyValue> & seqArguments,sal_Bool bSaveTo)2765cdf0e10cSrcweir void SfxBaseModel::impl_store(  const   ::rtl::OUString&                   sURL            ,
2766cdf0e10cSrcweir                                 const   uno::Sequence< beans::PropertyValue >&  seqArguments    ,
2767cdf0e10cSrcweir 										sal_Bool					bSaveTo			)
2768cdf0e10cSrcweir {
2769cdf0e10cSrcweir 	if( !sURL.getLength() )
2770cdf0e10cSrcweir         throw frame::IllegalArgumentIOException();
2771cdf0e10cSrcweir 
2772cdf0e10cSrcweir 	//sal_Bool aSaveAsTemplate = sal_False;
2773cdf0e10cSrcweir 
2774cdf0e10cSrcweir     sal_Bool bSaved = sal_False;
2775cdf0e10cSrcweir     if ( !bSaveTo && m_pData->m_pObjectShell && sURL.getLength()
2776cdf0e10cSrcweir       && sURL.compareToAscii( "private:stream", 14 ) != COMPARE_EQUAL
2777cdf0e10cSrcweir 	  && ::utl::UCBContentHelper::EqualURLs( getLocation(), sURL ) )
2778cdf0e10cSrcweir     {
2779cdf0e10cSrcweir         // this is the same file URL as the current document location, try to use storeOwn if possible
2780cdf0e10cSrcweir 
2781cdf0e10cSrcweir         ::comphelper::SequenceAsHashMap aArgHash( seqArguments );
2782cdf0e10cSrcweir         ::rtl::OUString aFilterString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ) );
2783cdf0e10cSrcweir         ::rtl::OUString aFilterName = aArgHash.getUnpackedValueOrDefault( aFilterString, ::rtl::OUString() );
2784cdf0e10cSrcweir         if ( aFilterName.getLength() )
2785cdf0e10cSrcweir         {
2786cdf0e10cSrcweir             SfxMedium* pMedium = m_pData->m_pObjectShell->GetMedium();
2787cdf0e10cSrcweir             if ( pMedium )
2788cdf0e10cSrcweir             {
2789cdf0e10cSrcweir                 const SfxFilter* pFilter = pMedium->GetFilter();
2790cdf0e10cSrcweir                 if ( pFilter && aFilterName.equals( pFilter->GetFilterName() ) )
2791cdf0e10cSrcweir                 {
2792f6b63cabSOliver-Rainer Wittmann                     // 119366 - If the former file saving with password, do not trying in StoreSelf anyway...
2793f6b63cabSOliver-Rainer Wittmann                     bool bFormerPassword = false;
2794cdf0e10cSrcweir                     {
2795f6b63cabSOliver-Rainer Wittmann                         uno::Sequence< beans::NamedValue > aOldEncryptionData;
2796f6b63cabSOliver-Rainer Wittmann                         if (GetEncryptionData_Impl( pMedium->GetItemSet(), aOldEncryptionData ))
2797f6b63cabSOliver-Rainer Wittmann                         {
2798f6b63cabSOliver-Rainer Wittmann                             bFormerPassword = true;
2799f6b63cabSOliver-Rainer Wittmann                         }
2800cdf0e10cSrcweir                     }
2801f6b63cabSOliver-Rainer Wittmann                     if ( !bFormerPassword )
2802cdf0e10cSrcweir                     {
2803f6b63cabSOliver-Rainer Wittmann                         aArgHash.erase( aFilterString );
2804f6b63cabSOliver-Rainer Wittmann                         aArgHash.erase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ) );
2805cdf0e10cSrcweir 
2806f6b63cabSOliver-Rainer Wittmann                         try
2807f6b63cabSOliver-Rainer Wittmann                         {
2808f6b63cabSOliver-Rainer Wittmann                             storeSelf( aArgHash.getAsConstPropertyValueList() );
2809f6b63cabSOliver-Rainer Wittmann                             bSaved = sal_True;
2810f6b63cabSOliver-Rainer Wittmann                         }
2811f6b63cabSOliver-Rainer Wittmann                         catch( const lang::IllegalArgumentException& )
2812f6b63cabSOliver-Rainer Wittmann                         {
2813f6b63cabSOliver-Rainer Wittmann                             // some additional arguments do not allow to use saving, SaveAs should be done
2814f6b63cabSOliver-Rainer Wittmann                             // but only for normal documents, the shared documents would be overwritten in this case
2815f6b63cabSOliver-Rainer Wittmann                             // that would mean an information loss
2816f6b63cabSOliver-Rainer Wittmann                             // TODO/LATER: need a new interaction for this case
2817f6b63cabSOliver-Rainer Wittmann                             if ( m_pData->m_pObjectShell->IsDocShared() )
2818cdf0e10cSrcweir                             {
2819f6b63cabSOliver-Rainer Wittmann                                 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't store shared document!" ) ) );
2820f6b63cabSOliver-Rainer Wittmann                                 m_pData->m_pObjectShell->StoreLog();
2821f6b63cabSOliver-Rainer Wittmann 
2822f6b63cabSOliver-Rainer Wittmann                                 uno::Sequence< beans::NamedValue > aNewEncryptionData = aArgHash.getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionData" ) ), uno::Sequence< beans::NamedValue >() );
2823f6b63cabSOliver-Rainer Wittmann                                 if ( !aNewEncryptionData.getLength() )
2824f6b63cabSOliver-Rainer Wittmann                                 {
2825f6b63cabSOliver-Rainer Wittmann                                     ::rtl::OUString aNewPassword = aArgHash.getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Password" ) ), ::rtl::OUString() );
2826f6b63cabSOliver-Rainer Wittmann                                     aNewEncryptionData = ::comphelper::OStorageHelper::CreatePackageEncryptionData( aNewPassword );
2827f6b63cabSOliver-Rainer Wittmann                                 }
2828f6b63cabSOliver-Rainer Wittmann 
2829f6b63cabSOliver-Rainer Wittmann                                 uno::Sequence< beans::NamedValue > aOldEncryptionData;
2830f6b63cabSOliver-Rainer Wittmann                                 GetEncryptionData_Impl( pMedium->GetItemSet(), aOldEncryptionData );
2831f6b63cabSOliver-Rainer Wittmann 
2832f6b63cabSOliver-Rainer Wittmann                                 if ( !aOldEncryptionData.getLength() && !aNewEncryptionData.getLength() )
2833f6b63cabSOliver-Rainer Wittmann                                     throw;
2834f6b63cabSOliver-Rainer Wittmann                                 else
2835f6b63cabSOliver-Rainer Wittmann                                 {
2836f6b63cabSOliver-Rainer Wittmann                                     // if the password is changed a special error should be used in case of shared document
2837f6b63cabSOliver-Rainer Wittmann                                     throw task::ErrorCodeIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cant change password for shared document." ) ), uno::Reference< uno::XInterface >(), ERRCODE_SFX_SHARED_NOPASSWORDCHANGE );
2838f6b63cabSOliver-Rainer Wittmann                                 }
2839cdf0e10cSrcweir                             }
2840cdf0e10cSrcweir                         }
2841cdf0e10cSrcweir                     }
2842cdf0e10cSrcweir                 }
2843cdf0e10cSrcweir             }
2844cdf0e10cSrcweir         }
2845cdf0e10cSrcweir     }
2846cdf0e10cSrcweir 
2847cdf0e10cSrcweir 	if ( !bSaved && m_pData->m_pObjectShell )
2848cdf0e10cSrcweir 	{
2849cdf0e10cSrcweir 		SFX_APP()->NotifyEvent( SfxEventHint( bSaveTo ? SFX_EVENT_SAVETODOC : SFX_EVENT_SAVEASDOC, GlobalEventConfig::GetEventName( bSaveTo ? STR_EVENT_SAVETODOC : STR_EVENT_SAVEASDOC ),
2850cdf0e10cSrcweir 												m_pData->m_pObjectShell ) );
2851cdf0e10cSrcweir 
2852cdf0e10cSrcweir     	SfxAllItemSet *aParams = new SfxAllItemSet( SFX_APP()->GetPool() );
2853cdf0e10cSrcweir 		aParams->Put( SfxStringItem( SID_FILE_NAME, String(sURL) ) );
2854cdf0e10cSrcweir 		if ( bSaveTo )
2855cdf0e10cSrcweir 			aParams->Put( SfxBoolItem( SID_SAVETO, sal_True ) );
2856cdf0e10cSrcweir 
2857cdf0e10cSrcweir     	TransformParameters( SID_SAVEASDOC, seqArguments, *aParams );
2858cdf0e10cSrcweir 
2859cdf0e10cSrcweir     	SFX_ITEMSET_ARG( aParams, pCopyStreamItem, SfxBoolItem, SID_COPY_STREAM_IF_POSSIBLE, sal_False );
2860cdf0e10cSrcweir 
2861cdf0e10cSrcweir 		if ( pCopyStreamItem && pCopyStreamItem->GetValue() && !bSaveTo )
2862cdf0e10cSrcweir         {
2863cdf0e10cSrcweir             m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Misuse of CopyStreamIfPossible!" ) ) );
2864cdf0e10cSrcweir             m_pData->m_pObjectShell->StoreLog();
2865cdf0e10cSrcweir 
2866cdf0e10cSrcweir             throw frame::IllegalArgumentIOException(
2867cdf0e10cSrcweir 					::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CopyStreamIfPossible parameter is not acceptable for storeAsURL() call!") ),
2868cdf0e10cSrcweir 					uno::Reference< uno::XInterface >() );
2869cdf0e10cSrcweir         }
2870cdf0e10cSrcweir 
2871cdf0e10cSrcweir         sal_uInt32 nModifyPasswordHash = 0;
2872cdf0e10cSrcweir         uno::Sequence< beans::PropertyValue > aModifyPasswordInfo;
2873cdf0e10cSrcweir     	SFX_ITEMSET_ARG( aParams, pModifyPasswordInfoItem, SfxUnoAnyItem, SID_MODIFYPASSWORDINFO, sal_False );
2874cdf0e10cSrcweir         if ( pModifyPasswordInfoItem )
2875cdf0e10cSrcweir         {
2876cdf0e10cSrcweir             // it contains either a simple hash or a set of PropertyValues
2877cdf0e10cSrcweir             // TODO/LATER: the sequence of PropertyValue should replace the hash completely in future
2878cdf0e10cSrcweir             sal_Int32 nMPHTmp = 0;
2879cdf0e10cSrcweir             pModifyPasswordInfoItem->GetValue() >>= nMPHTmp;
2880cdf0e10cSrcweir             nModifyPasswordHash = (sal_uInt32)nMPHTmp;
2881cdf0e10cSrcweir             pModifyPasswordInfoItem->GetValue() >>= aModifyPasswordInfo;
2882cdf0e10cSrcweir         }
2883cdf0e10cSrcweir         aParams->ClearItem( SID_MODIFYPASSWORDINFO );
2884cdf0e10cSrcweir         sal_uInt32 nOldModifyPasswordHash = m_pData->m_pObjectShell->GetModifyPasswordHash();
2885cdf0e10cSrcweir         m_pData->m_pObjectShell->SetModifyPasswordHash( nModifyPasswordHash );
2886cdf0e10cSrcweir         uno::Sequence< beans::PropertyValue > aOldModifyPasswordInfo = m_pData->m_pObjectShell->GetModifyPasswordInfo();
2887cdf0e10cSrcweir         m_pData->m_pObjectShell->SetModifyPasswordInfo( aModifyPasswordInfo );
2888cdf0e10cSrcweir 
2889cdf0e10cSrcweir         // since saving a document modifies its DocumentInfo, the current
2890cdf0e10cSrcweir         // DocumentInfo must be saved on "SaveTo", so it can be restored
2891cdf0e10cSrcweir         // after saving
2892cdf0e10cSrcweir         sal_Bool bCopyTo =  bSaveTo ||
2893cdf0e10cSrcweir             m_pData->m_pObjectShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED;
2894cdf0e10cSrcweir         uno::Reference<document::XDocumentProperties> xOldDocProps;
2895cdf0e10cSrcweir         uno::Reference<document::XDocumentInfo> xOldDocInfo;
2896cdf0e10cSrcweir         if ( bCopyTo )
2897cdf0e10cSrcweir         {
2898cdf0e10cSrcweir             xOldDocProps = getDocumentProperties();
2899cdf0e10cSrcweir             if (m_pData->m_xDocumentInfo.is())
2900cdf0e10cSrcweir             {
2901cdf0e10cSrcweir                 xOldDocInfo = getDocumentInfo();
2902cdf0e10cSrcweir                 const Reference<util::XCloneable> xCloneable(xOldDocInfo,
2903cdf0e10cSrcweir                     UNO_QUERY_THROW);
2904cdf0e10cSrcweir                 const Reference<document::XDocumentInfo> xNewDocInfo(
2905cdf0e10cSrcweir                     xCloneable->createClone(), UNO_QUERY_THROW);
2906cdf0e10cSrcweir                 const Reference<document::XDocumentPropertiesSupplier> xDPS(
2907cdf0e10cSrcweir                     xNewDocInfo, UNO_QUERY_THROW);
2908cdf0e10cSrcweir                 const Reference<document::XDocumentProperties> xNewDocProps(
2909cdf0e10cSrcweir                     xDPS->getDocumentProperties());
2910cdf0e10cSrcweir                 m_pData->m_xDocumentProperties = xNewDocProps;
2911cdf0e10cSrcweir                 m_pData->m_xDocumentInfo = xNewDocInfo;
2912cdf0e10cSrcweir             }
2913cdf0e10cSrcweir             else // try not to create DocumentInfo if it does not exist...
2914cdf0e10cSrcweir             {
2915cdf0e10cSrcweir                 const Reference<util::XCloneable> xCloneable(xOldDocProps,
2916cdf0e10cSrcweir                     UNO_QUERY_THROW);
2917cdf0e10cSrcweir                 const Reference<document::XDocumentProperties> xNewDocProps(
2918cdf0e10cSrcweir                     xCloneable->createClone(), UNO_QUERY_THROW);
2919cdf0e10cSrcweir                 m_pData->m_xDocumentProperties = xNewDocProps;
2920cdf0e10cSrcweir             }
2921cdf0e10cSrcweir         }
2922cdf0e10cSrcweir 
2923cdf0e10cSrcweir 		sal_Bool bRet = m_pData->m_pObjectShell->APISaveAs_Impl( sURL, aParams );
2924cdf0e10cSrcweir 
2925cdf0e10cSrcweir         if ( bCopyTo )
2926cdf0e10cSrcweir         {
2927cdf0e10cSrcweir             // restore DocumentInfo if a copy was created
2928cdf0e10cSrcweir             m_pData->m_xDocumentProperties = xOldDocProps;
2929cdf0e10cSrcweir             m_pData->m_xDocumentInfo = xOldDocInfo;
2930cdf0e10cSrcweir         }
2931cdf0e10cSrcweir 
2932cdf0e10cSrcweir 		uno::Reference < task::XInteractionHandler > xHandler;
2933cdf0e10cSrcweir 		SFX_ITEMSET_ARG( aParams, pItem, SfxUnoAnyItem, SID_INTERACTIONHANDLER, sal_False);
2934cdf0e10cSrcweir 		if ( pItem )
2935cdf0e10cSrcweir 			pItem->GetValue() >>= xHandler;
2936cdf0e10cSrcweir 
2937cdf0e10cSrcweir 		DELETEZ( aParams );
2938cdf0e10cSrcweir 
2939cdf0e10cSrcweir 		sal_uInt32 nErrCode = m_pData->m_pObjectShell->GetErrorCode();
2940cdf0e10cSrcweir 		if ( !bRet && !nErrCode )
2941cdf0e10cSrcweir         {
2942cdf0e10cSrcweir             m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing has failed, no error is set!" ) ) );
2943cdf0e10cSrcweir 			nErrCode = ERRCODE_IO_CANTWRITE;
2944cdf0e10cSrcweir         }
2945cdf0e10cSrcweir 		m_pData->m_pObjectShell->ResetError();
2946cdf0e10cSrcweir 
2947cdf0e10cSrcweir 		if ( bRet )
2948cdf0e10cSrcweir 		{
2949cdf0e10cSrcweir 			if ( nErrCode )
2950cdf0e10cSrcweir 			{
2951cdf0e10cSrcweir 				// must be a warning - use Interactionhandler if possible or abandone
2952cdf0e10cSrcweir                 if ( xHandler.is() )
2953cdf0e10cSrcweir                 {
2954cdf0e10cSrcweir 					// TODO/LATER: a general way to set the error context should be available
2955cdf0e10cSrcweir 					SfxErrorContext aEc( ERRCTX_SFX_SAVEASDOC, m_pData->m_pObjectShell->GetTitle() );
2956cdf0e10cSrcweir 
2957cdf0e10cSrcweir 					::com::sun::star::task::ErrorCodeRequest aErrorCode;
2958cdf0e10cSrcweir 		            aErrorCode.ErrCode = nErrCode;
2959cdf0e10cSrcweir                     SfxMedium::CallApproveHandler( xHandler, uno::makeAny( aErrorCode ), sal_False );
2960cdf0e10cSrcweir 				}
2961cdf0e10cSrcweir 			}
2962cdf0e10cSrcweir 
2963cdf0e10cSrcweir             m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing succeeded!" ) ) );
2964cdf0e10cSrcweir 			if ( !bSaveTo )
2965cdf0e10cSrcweir             {
2966cdf0e10cSrcweir                 m_pData->m_aPreusedFilterName = GetMediumFilterName_Impl();
2967cdf0e10cSrcweir                 m_pData->m_pObjectShell->SetModifyPasswordEntered();
2968cdf0e10cSrcweir 
2969cdf0e10cSrcweir 				SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEASDOCDONE, GlobalEventConfig::GetEventName(STR_EVENT_SAVEASDOCDONE), m_pData->m_pObjectShell ) );
2970cdf0e10cSrcweir             }
2971cdf0e10cSrcweir             else
2972cdf0e10cSrcweir             {
2973cdf0e10cSrcweir                 m_pData->m_pObjectShell->SetModifyPasswordHash( nOldModifyPasswordHash );
2974cdf0e10cSrcweir                 m_pData->m_pObjectShell->SetModifyPasswordInfo( aOldModifyPasswordInfo );
2975cdf0e10cSrcweir 
2976cdf0e10cSrcweir 				SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVETODOCDONE, GlobalEventConfig::GetEventName(STR_EVENT_SAVETODOCDONE), m_pData->m_pObjectShell ) );
2977cdf0e10cSrcweir             }
2978cdf0e10cSrcweir 		}
2979cdf0e10cSrcweir 		else
2980cdf0e10cSrcweir 		{
2981cdf0e10cSrcweir             // let the logring be stored to the related file
2982cdf0e10cSrcweir             m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing failed!" ) ) );
2983cdf0e10cSrcweir             m_pData->m_pObjectShell->StoreLog();
2984cdf0e10cSrcweir 
2985cdf0e10cSrcweir             m_pData->m_pObjectShell->SetModifyPasswordHash( nOldModifyPasswordHash );
2986cdf0e10cSrcweir             m_pData->m_pObjectShell->SetModifyPasswordInfo( aOldModifyPasswordInfo );
2987cdf0e10cSrcweir 
2988cdf0e10cSrcweir 
2989cdf0e10cSrcweir 			SFX_APP()->NotifyEvent( SfxEventHint( bSaveTo ? SFX_EVENT_SAVETODOCFAILED : SFX_EVENT_SAVEASDOCFAILED, GlobalEventConfig::GetEventName( bSaveTo ? STR_EVENT_SAVETODOCFAILED : STR_EVENT_SAVEASDOCFAILED),
2990cdf0e10cSrcweir 													m_pData->m_pObjectShell ) );
2991cdf0e10cSrcweir 
2992cdf0e10cSrcweir 			throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), nErrCode );
2993cdf0e10cSrcweir 		}
2994cdf0e10cSrcweir 	}
2995cdf0e10cSrcweir }
2996cdf0e10cSrcweir 
2997cdf0e10cSrcweir //********************************************************************************************************
2998cdf0e10cSrcweir namespace {
2999cdf0e10cSrcweir template< typename ListenerT, typename EventT >
3000cdf0e10cSrcweir class NotifySingleListenerIgnoreRE
3001cdf0e10cSrcweir {
3002cdf0e10cSrcweir private:
3003cdf0e10cSrcweir     typedef void ( SAL_CALL ListenerT::*NotificationMethod )( const EventT& );
3004cdf0e10cSrcweir     NotificationMethod  m_pMethod;
3005cdf0e10cSrcweir     const EventT&       m_rEvent;
3006cdf0e10cSrcweir public:
NotifySingleListenerIgnoreRE(NotificationMethod method,const EventT & event)3007cdf0e10cSrcweir     NotifySingleListenerIgnoreRE( NotificationMethod method, const EventT& event ) : m_pMethod( method ), m_rEvent( event ) { }
3008cdf0e10cSrcweir 
operator ()(const uno::Reference<ListenerT> & listener) const3009cdf0e10cSrcweir     void operator()( const uno::Reference<ListenerT>& listener ) const
3010cdf0e10cSrcweir     {
3011cdf0e10cSrcweir         try
3012cdf0e10cSrcweir         {
3013cdf0e10cSrcweir             (listener.get()->*m_pMethod)( m_rEvent );
3014cdf0e10cSrcweir         }
3015cdf0e10cSrcweir         catch( uno::RuntimeException& )
3016cdf0e10cSrcweir         {
3017cdf0e10cSrcweir             // this exception is ignored to avoid problems with invalid listeners, the listener should be probably thrown away in future
3018cdf0e10cSrcweir         }
3019cdf0e10cSrcweir     }
3020cdf0e10cSrcweir };
3021cdf0e10cSrcweir } // anonymous namespace
3022cdf0e10cSrcweir 
postEvent_Impl(const::rtl::OUString & aName,const uno::Reference<frame::XController2> & xController)3023cdf0e10cSrcweir void SfxBaseModel::postEvent_Impl( const ::rtl::OUString& aName, const uno::Reference< frame::XController2 >& xController )
3024cdf0e10cSrcweir {
3025cdf0e10cSrcweir 	// object already disposed?
3026cdf0e10cSrcweir 	if ( impl_isDisposed() )
3027cdf0e10cSrcweir 		return;
3028cdf0e10cSrcweir 
3029cdf0e10cSrcweir 	DBG_ASSERT( aName.getLength(), "Empty event name!" );
3030cdf0e10cSrcweir 	if (!aName.getLength())
3031cdf0e10cSrcweir 		return;
3032cdf0e10cSrcweir 
3033cdf0e10cSrcweir     ::cppu::OInterfaceContainerHelper* pIC =
3034cdf0e10cSrcweir         m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( (const uno::Reference< document::XDocumentEventListener >*)0 ) );
3035cdf0e10cSrcweir     if ( pIC )
3036cdf0e10cSrcweir     {
3037cdf0e10cSrcweir #ifdef DBG_UTIL
3038cdf0e10cSrcweir         ByteString aTmp( "SfxDocumentEvent: " );
3039cdf0e10cSrcweir         aTmp += ByteString( String(aName), RTL_TEXTENCODING_UTF8 );
3040cdf0e10cSrcweir         DBG_TRACE( aTmp.GetBuffer() );
3041cdf0e10cSrcweir #endif
3042cdf0e10cSrcweir 
3043cdf0e10cSrcweir         document::DocumentEvent aDocumentEvent( (frame::XModel*)this, aName, xController, uno::Any() );
3044cdf0e10cSrcweir 
3045cdf0e10cSrcweir         pIC->forEach< document::XDocumentEventListener, NotifySingleListenerIgnoreRE< document::XDocumentEventListener, document::DocumentEvent > >(
3046cdf0e10cSrcweir             NotifySingleListenerIgnoreRE< document::XDocumentEventListener, document::DocumentEvent >(
3047cdf0e10cSrcweir                 &document::XDocumentEventListener::documentEventOccured,
3048cdf0e10cSrcweir                 aDocumentEvent ) );
3049cdf0e10cSrcweir     }
3050cdf0e10cSrcweir 
3051cdf0e10cSrcweir     pIC = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( (const uno::Reference< document::XEventListener >*)0 ) );
3052cdf0e10cSrcweir     if ( pIC )
3053cdf0e10cSrcweir     {
3054cdf0e10cSrcweir #ifdef DBG_UTIL
3055cdf0e10cSrcweir         ByteString aTmp( "SfxEvent: " );
3056cdf0e10cSrcweir         aTmp += ByteString( String(aName), RTL_TEXTENCODING_UTF8 );
3057cdf0e10cSrcweir         DBG_TRACE( aTmp.GetBuffer() );
3058cdf0e10cSrcweir #endif
3059cdf0e10cSrcweir 
3060cdf0e10cSrcweir         document::EventObject aEvent( (frame::XModel*)this, aName );
3061cdf0e10cSrcweir 
3062cdf0e10cSrcweir         pIC->forEach< document::XEventListener, NotifySingleListenerIgnoreRE< document::XEventListener, document::EventObject > >(
3063cdf0e10cSrcweir             NotifySingleListenerIgnoreRE< document::XEventListener, document::EventObject >(
3064cdf0e10cSrcweir                 &document::XEventListener::notifyEvent,
3065cdf0e10cSrcweir                 aEvent ) );
3066cdf0e10cSrcweir     }
3067cdf0e10cSrcweir 
3068cdf0e10cSrcweir }
3069cdf0e10cSrcweir 
getViewData()3070cdf0e10cSrcweir uno::Reference < container::XIndexAccess > SAL_CALL SfxBaseModel::getViewData() throw(::com::sun::star::uno::RuntimeException)
3071cdf0e10cSrcweir {
3072cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3073cdf0e10cSrcweir 
3074cdf0e10cSrcweir 	if ( m_pData->m_pObjectShell.Is() && !m_pData->m_contViewData.is() )
3075cdf0e10cSrcweir 	{
3076cdf0e10cSrcweir     	SfxViewFrame *pActFrame = SfxViewFrame::Current();
3077cdf0e10cSrcweir     	if ( !pActFrame || pActFrame->GetObjectShell() != m_pData->m_pObjectShell )
3078cdf0e10cSrcweir         	pActFrame = SfxViewFrame::GetFirst( m_pData->m_pObjectShell );
3079cdf0e10cSrcweir 
3080cdf0e10cSrcweir         if ( !pActFrame || !pActFrame->GetViewShell() )
3081cdf0e10cSrcweir             // currently no frame for this document at all or View is under construction
3082cdf0e10cSrcweir             return uno::Reference < container::XIndexAccess >();
3083cdf0e10cSrcweir 
3084cdf0e10cSrcweir         m_pData->m_contViewData = Reference < container::XIndexAccess >(
3085cdf0e10cSrcweir 				::comphelper::getProcessServiceFactory()->createInstance(
3086cdf0e10cSrcweir 				DEFINE_CONST_UNICODE("com.sun.star.document.IndexedPropertyValues") ),
3087cdf0e10cSrcweir                 uno::UNO_QUERY );
3088cdf0e10cSrcweir 
3089cdf0e10cSrcweir 		if ( !m_pData->m_contViewData.is() )
3090cdf0e10cSrcweir 		{
3091cdf0e10cSrcweir 			// error: no container class available!
3092cdf0e10cSrcweir             return uno::Reference < container::XIndexAccess >();
3093cdf0e10cSrcweir 		}
3094cdf0e10cSrcweir 
3095cdf0e10cSrcweir         uno::Reference < container::XIndexContainer > xCont( m_pData->m_contViewData, uno::UNO_QUERY );
3096cdf0e10cSrcweir 		sal_Int32 nCount = 0;
3097cdf0e10cSrcweir         uno::Sequence < beans::PropertyValue > aSeq;
3098cdf0e10cSrcweir 		::com::sun::star::uno::Any aAny;
3099cdf0e10cSrcweir     	for ( SfxViewFrame *pFrame = SfxViewFrame::GetFirst( m_pData->m_pObjectShell ); pFrame;
3100cdf0e10cSrcweir             	pFrame = SfxViewFrame::GetNext( *pFrame, m_pData->m_pObjectShell ) )
3101cdf0e10cSrcweir     	{
3102cdf0e10cSrcweir 			sal_Bool bIsActive = ( pFrame == pActFrame );
3103cdf0e10cSrcweir 			pFrame->GetViewShell()->WriteUserDataSequence( aSeq );
3104cdf0e10cSrcweir 			aAny <<= aSeq;
3105cdf0e10cSrcweir 			xCont->insertByIndex( bIsActive ? 0 : nCount, aAny );
3106cdf0e10cSrcweir 			nCount++;
3107cdf0e10cSrcweir 		}
3108cdf0e10cSrcweir 	}
3109cdf0e10cSrcweir 
3110cdf0e10cSrcweir 	return m_pData->m_contViewData;
3111cdf0e10cSrcweir }
3112cdf0e10cSrcweir 
setViewData(const uno::Reference<container::XIndexAccess> & aData)3113cdf0e10cSrcweir void SAL_CALL SfxBaseModel::setViewData( const uno::Reference < container::XIndexAccess >& aData ) throw(::com::sun::star::uno::RuntimeException)
3114cdf0e10cSrcweir {
3115cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3116cdf0e10cSrcweir 
3117cdf0e10cSrcweir 	m_pData->m_contViewData = aData;
3118cdf0e10cSrcweir }
3119cdf0e10cSrcweir 
3120cdf0e10cSrcweir /** calls all XEventListeners */
notifyEvent(const::com::sun::star::document::EventObject & aEvent) const3121cdf0e10cSrcweir void SfxBaseModel::notifyEvent( const ::com::sun::star::document::EventObject& aEvent ) const
3122cdf0e10cSrcweir {
3123cdf0e10cSrcweir     // object already disposed?
3124cdf0e10cSrcweir     if ( impl_isDisposed() )
3125cdf0e10cSrcweir         return;
3126cdf0e10cSrcweir 
3127cdf0e10cSrcweir     ::cppu::OInterfaceContainerHelper* pIC = m_pData->m_aInterfaceContainer.getContainer(
3128cdf0e10cSrcweir                                         ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0) );
3129cdf0e10cSrcweir 	if( pIC )
3130cdf0e10cSrcweir 
3131cdf0e10cSrcweir 	{
3132cdf0e10cSrcweir         ::cppu::OInterfaceIteratorHelper aIt( *pIC );
3133cdf0e10cSrcweir 		while( aIt.hasMoreElements() )
3134cdf0e10cSrcweir         {
3135cdf0e10cSrcweir             try
3136cdf0e10cSrcweir             {
3137cdf0e10cSrcweir                 ((XDOCEVENTLISTENER *)aIt.next())->notifyEvent( aEvent );
3138cdf0e10cSrcweir             }
3139cdf0e10cSrcweir             catch( uno::RuntimeException& )
3140cdf0e10cSrcweir             {
3141cdf0e10cSrcweir                 aIt.remove();
3142cdf0e10cSrcweir             }
3143cdf0e10cSrcweir         }
3144cdf0e10cSrcweir 	}
3145cdf0e10cSrcweir }
3146cdf0e10cSrcweir 
3147cdf0e10cSrcweir /** returns true if someone added a XEventListener to this XEventBroadcaster */
hasEventListeners() const3148cdf0e10cSrcweir sal_Bool SfxBaseModel::hasEventListeners() const
3149cdf0e10cSrcweir {
3150cdf0e10cSrcweir     return !impl_isDisposed() && (NULL != m_pData->m_aInterfaceContainer.getContainer( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0) ) );
3151cdf0e10cSrcweir }
3152cdf0e10cSrcweir 
addPrintJobListener(const uno::Reference<view::XPrintJobListener> & xListener)3153cdf0e10cSrcweir void SAL_CALL SfxBaseModel::addPrintJobListener( const uno::Reference< view::XPrintJobListener >& xListener ) throw (uno::RuntimeException)
3154cdf0e10cSrcweir {
3155cdf0e10cSrcweir     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
3156cdf0e10cSrcweir 
3157cdf0e10cSrcweir     if ( impl_getPrintHelper() )
3158cdf0e10cSrcweir 	{
3159cdf0e10cSrcweir 		uno::Reference < view::XPrintJobBroadcaster > xPJB( m_pData->m_xPrintable, uno::UNO_QUERY );
3160cdf0e10cSrcweir 		if ( xPJB.is() )
3161cdf0e10cSrcweir 			xPJB->addPrintJobListener( xListener );
3162cdf0e10cSrcweir 	}
3163cdf0e10cSrcweir //	else
3164cdf0e10cSrcweir //		m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< view::XPrintJobListener >*)0), xListener );
3165cdf0e10cSrcweir }
3166cdf0e10cSrcweir 
removePrintJobListener(const uno::Reference<view::XPrintJobListener> & xListener)3167cdf0e10cSrcweir void SAL_CALL SfxBaseModel::removePrintJobListener( const uno::Reference< view::XPrintJobListener >& xListener ) throw (uno::RuntimeException)
3168cdf0e10cSrcweir {
3169cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3170cdf0e10cSrcweir 
3171cdf0e10cSrcweir     if ( impl_getPrintHelper() )
3172cdf0e10cSrcweir 	{
3173cdf0e10cSrcweir 		uno::Reference < view::XPrintJobBroadcaster > xPJB( m_pData->m_xPrintable, uno::UNO_QUERY );
3174cdf0e10cSrcweir 		if ( xPJB.is() )
3175cdf0e10cSrcweir             xPJB->removePrintJobListener( xListener );
3176cdf0e10cSrcweir 	}
3177cdf0e10cSrcweir //	else
3178cdf0e10cSrcweir //		m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< view::XPrintJobListener >*)0), xListener );
3179cdf0e10cSrcweir }
3180cdf0e10cSrcweir 
3181cdf0e10cSrcweir // simple declaration of class SvObject is enough
3182cdf0e10cSrcweir // the corresponding <so3/iface.hxx> cannon be included because it provides
3183cdf0e10cSrcweir // declaration of class SvBorder that conflicts with ../../inc/viewfrm.hxx
3184cdf0e10cSrcweir class SvObject;
getSomething(const::com::sun::star::uno::Sequence<sal_Int8> & aIdentifier)3185cdf0e10cSrcweir sal_Int64 SAL_CALL SfxBaseModel::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException)
3186cdf0e10cSrcweir {
3187cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
3188cdf0e10cSrcweir 	if ( GetObjectShell() )
3189cdf0e10cSrcweir 	{
3190cdf0e10cSrcweir         SvGlobalName aName( aIdentifier );
3191cdf0e10cSrcweir 		if ( aName == SvGlobalName( SO3_GLOBAL_CLASSID ) )
3192cdf0e10cSrcweir 	 		return (sal_Int64)(sal_IntPtr)(SvObject*)GetObjectShell();
3193cdf0e10cSrcweir 		else if ( aName == SvGlobalName( SFX_GLOBAL_CLASSID ) )
3194cdf0e10cSrcweir 	 		return (sal_Int64)(sal_IntPtr)(SfxObjectShell*)GetObjectShell();
3195cdf0e10cSrcweir 	}
3196cdf0e10cSrcweir 
3197cdf0e10cSrcweir 	return 0;
3198cdf0e10cSrcweir }
3199cdf0e10cSrcweir 
3200cdf0e10cSrcweir //____________________________________________________________________________________________________
3201cdf0e10cSrcweir //	XDocumentSubStorageSupplier
3202cdf0e10cSrcweir //____________________________________________________________________________________________________
3203cdf0e10cSrcweir 
ListenForStorage_Impl(const uno::Reference<embed::XStorage> & xStorage)3204cdf0e10cSrcweir void SfxBaseModel::ListenForStorage_Impl( const uno::Reference< embed::XStorage >& xStorage )
3205cdf0e10cSrcweir {
3206cdf0e10cSrcweir 	uno::Reference< util::XModifiable > xModifiable( xStorage, uno::UNO_QUERY );
3207cdf0e10cSrcweir 	if ( xModifiable.is() )
3208cdf0e10cSrcweir 	{
3209cdf0e10cSrcweir 		if ( !m_pData->m_pStorageModifyListen.is() )
3210cdf0e10cSrcweir 		{
3211cdf0e10cSrcweir             m_pData->m_pStorageModifyListen = new ::sfx2::DocumentStorageModifyListener( *m_pData, Application::GetSolarMutex() );
3212cdf0e10cSrcweir 		}
3213cdf0e10cSrcweir 
3214cdf0e10cSrcweir 		// no need to deregister the listening for old storage since it should be disposed automatically
3215cdf0e10cSrcweir 		xModifiable->addModifyListener( m_pData->m_pStorageModifyListen.get() );
3216cdf0e10cSrcweir 	}
3217cdf0e10cSrcweir }
3218cdf0e10cSrcweir 
getDocumentSubStorage(const::rtl::OUString & aStorageName,sal_Int32 nMode)3219cdf0e10cSrcweir uno::Reference< XSTORAGE > SAL_CALL SfxBaseModel::getDocumentSubStorage( const ::rtl::OUString& aStorageName, sal_Int32 nMode )
3220cdf0e10cSrcweir     throw ( uno::RuntimeException)
3221cdf0e10cSrcweir {
3222cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3223cdf0e10cSrcweir 
3224cdf0e10cSrcweir     uno::Reference< XSTORAGE > xResult;
3225cdf0e10cSrcweir     if ( m_pData->m_pObjectShell.Is() )
3226cdf0e10cSrcweir     {
3227cdf0e10cSrcweir 		uno::Reference< embed::XStorage > xStorage = m_pData->m_pObjectShell->GetStorage();
3228cdf0e10cSrcweir 		if ( xStorage.is() )
3229cdf0e10cSrcweir 		{
3230cdf0e10cSrcweir             try
3231cdf0e10cSrcweir             {
3232cdf0e10cSrcweir                 xResult = xStorage->openStorageElement( aStorageName, nMode );
3233cdf0e10cSrcweir             }
3234cdf0e10cSrcweir             catch ( uno::Exception& )
3235cdf0e10cSrcweir             {
3236cdf0e10cSrcweir             }
3237cdf0e10cSrcweir 		}
3238cdf0e10cSrcweir 	}
3239cdf0e10cSrcweir 
3240cdf0e10cSrcweir 	return xResult;
3241cdf0e10cSrcweir }
3242cdf0e10cSrcweir 
getDocumentSubStoragesNames()3243cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL SfxBaseModel::getDocumentSubStoragesNames()
3244cdf0e10cSrcweir 	throw ( io::IOException,
3245cdf0e10cSrcweir 			RuntimeException )
3246cdf0e10cSrcweir {
3247cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3248cdf0e10cSrcweir 
3249cdf0e10cSrcweir 	Sequence< ::rtl::OUString > aResult;
3250cdf0e10cSrcweir 	sal_Int32 nResultSize = 0;
3251cdf0e10cSrcweir 	sal_Bool bSuccess = sal_False;
3252cdf0e10cSrcweir     if ( m_pData->m_pObjectShell.Is() )
3253cdf0e10cSrcweir     {
3254cdf0e10cSrcweir         uno::Reference < embed::XStorage > xStorage = m_pData->m_pObjectShell->GetStorage();
3255cdf0e10cSrcweir         uno::Reference < container::XNameAccess > xAccess( xStorage, uno::UNO_QUERY );
3256cdf0e10cSrcweir         if ( xAccess.is() )
3257cdf0e10cSrcweir 		{
3258cdf0e10cSrcweir             Sequence< ::rtl::OUString > aTemp = xAccess->getElementNames();
3259cdf0e10cSrcweir             for ( sal_Int32 n = 0; n < aTemp.getLength(); n++ )
3260cdf0e10cSrcweir 			{
3261cdf0e10cSrcweir                 if ( xStorage->isStorageElement( aTemp[n] ) )
3262cdf0e10cSrcweir 				{
3263cdf0e10cSrcweir 					aResult.realloc( ++nResultSize );
3264cdf0e10cSrcweir                     aResult[ nResultSize - 1 ] = aTemp[n];
3265cdf0e10cSrcweir 				}
3266cdf0e10cSrcweir 			}
3267cdf0e10cSrcweir 
3268cdf0e10cSrcweir 			bSuccess = sal_True;
3269cdf0e10cSrcweir 		}
3270cdf0e10cSrcweir 	}
3271cdf0e10cSrcweir 
3272cdf0e10cSrcweir 	if ( !bSuccess )
3273cdf0e10cSrcweir 		throw io::IOException();
3274cdf0e10cSrcweir 
3275cdf0e10cSrcweir        return aResult;
3276cdf0e10cSrcweir }
3277cdf0e10cSrcweir 
3278cdf0e10cSrcweir //____________________________________________________________________________________________________
3279cdf0e10cSrcweir //	XScriptProviderSupplier
3280cdf0e10cSrcweir //____________________________________________________________________________________________________
3281cdf0e10cSrcweir 
3282cdf0e10cSrcweir 
getScriptProvider()3283cdf0e10cSrcweir uno::Reference< script::provider::XScriptProvider > SAL_CALL SfxBaseModel::getScriptProvider()
3284cdf0e10cSrcweir     throw ( uno::RuntimeException )
3285cdf0e10cSrcweir {
3286cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3287cdf0e10cSrcweir 
3288cdf0e10cSrcweir     uno::Reference< script::provider::XScriptProvider > xScriptProvider;
3289cdf0e10cSrcweir 
3290cdf0e10cSrcweir     ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
3291cdf0e10cSrcweir     Reference< script::provider::XScriptProviderFactory > xScriptProviderFactory(
3292cdf0e10cSrcweir         aContext.getSingleton( "com.sun.star.script.provider.theMasterScriptProviderFactory" ), uno::UNO_QUERY_THROW );
3293cdf0e10cSrcweir 
3294cdf0e10cSrcweir     try
3295cdf0e10cSrcweir     {
3296cdf0e10cSrcweir         Reference< XScriptInvocationContext > xScriptContext( this );
3297cdf0e10cSrcweir         xScriptProvider.set( xScriptProviderFactory->createScriptProvider( makeAny( xScriptContext ) ), uno::UNO_SET_THROW );
3298cdf0e10cSrcweir     }
3299cdf0e10cSrcweir     catch( const uno::RuntimeException& )
3300cdf0e10cSrcweir     {
3301cdf0e10cSrcweir         throw;
3302cdf0e10cSrcweir     }
3303cdf0e10cSrcweir     catch( const lang::IllegalArgumentException& )
3304cdf0e10cSrcweir     {
3305cdf0e10cSrcweir         throw lang::WrappedTargetRuntimeException(
3306cdf0e10cSrcweir             ::rtl::OUString(),
3307cdf0e10cSrcweir             *this,
3308cdf0e10cSrcweir             ::cppu::getCaughtException()
3309cdf0e10cSrcweir         );
3310cdf0e10cSrcweir     }
3311cdf0e10cSrcweir 
3312cdf0e10cSrcweir     return xScriptProvider;
3313cdf0e10cSrcweir }
3314cdf0e10cSrcweir 
3315cdf0e10cSrcweir //____________________________________________________________________________________________________
3316cdf0e10cSrcweir //	XUIConfigurationManagerSupplier
3317cdf0e10cSrcweir //____________________________________________________________________________________________________
3318cdf0e10cSrcweir 
getRuntimeUID() const3319cdf0e10cSrcweir rtl::OUString SfxBaseModel::getRuntimeUID() const
3320cdf0e10cSrcweir {
3321cdf0e10cSrcweir     OSL_ENSURE( m_pData->m_sRuntimeUID.getLength() > 0,
3322cdf0e10cSrcweir                 "SfxBaseModel::getRuntimeUID - ID is empty!" );
3323cdf0e10cSrcweir     return m_pData->m_sRuntimeUID;
3324cdf0e10cSrcweir }
3325cdf0e10cSrcweir 
hasValidSignatures() const3326cdf0e10cSrcweir sal_Bool SfxBaseModel::hasValidSignatures() const
3327cdf0e10cSrcweir {
3328cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
3329cdf0e10cSrcweir     if ( m_pData->m_pObjectShell.Is() )
3330cdf0e10cSrcweir         return ( m_pData->m_pObjectShell->ImplGetSignatureState( sal_False ) == SIGNATURESTATE_SIGNATURES_OK );
3331cdf0e10cSrcweir     return sal_False;
3332cdf0e10cSrcweir }
3333cdf0e10cSrcweir 
GetCommandFromSequence(rtl::OUString & rCommand,sal_Int32 & nIndex,const uno::Sequence<beans::PropertyValue> & rSeqPropValue)3334cdf0e10cSrcweir static void GetCommandFromSequence( rtl::OUString& rCommand, sal_Int32& nIndex, const uno::Sequence< beans::PropertyValue >& rSeqPropValue )
3335cdf0e10cSrcweir {
3336cdf0e10cSrcweir     rtl::OUString aCommand;
3337cdf0e10cSrcweir     nIndex = -1;
3338cdf0e10cSrcweir 
3339cdf0e10cSrcweir     for ( sal_Int32 i = 0; i < rSeqPropValue.getLength(); i++ )
3340cdf0e10cSrcweir     {
3341cdf0e10cSrcweir         if ( rSeqPropValue[i].Name.equalsAsciiL( "Command", 7 ))
3342cdf0e10cSrcweir         {
3343cdf0e10cSrcweir             rSeqPropValue[i].Value >>= rCommand;
3344cdf0e10cSrcweir             nIndex = i;
3345cdf0e10cSrcweir             return;
3346cdf0e10cSrcweir         }
3347cdf0e10cSrcweir     }
3348cdf0e10cSrcweir }
3349cdf0e10cSrcweir 
ConvertSlotsToCommands(SfxObjectShell * pDoc,uno::Reference<container::XIndexContainer> & rToolbarDefinition)3350cdf0e10cSrcweir static void ConvertSlotsToCommands( SfxObjectShell* pDoc, uno::Reference< container::XIndexContainer >& rToolbarDefinition )
3351cdf0e10cSrcweir {
3352cdf0e10cSrcweir     if ( pDoc )
3353cdf0e10cSrcweir     {
3354cdf0e10cSrcweir         Any           aAny;
3355cdf0e10cSrcweir         SfxModule*    pModule( pDoc->GetFactory().GetModule() );
3356cdf0e10cSrcweir         rtl::OUString aSlotCmd( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
3357cdf0e10cSrcweir         rtl::OUString aUnoCmd( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ));
3358cdf0e10cSrcweir         uno::Sequence< beans::PropertyValue > aSeqPropValue;
3359cdf0e10cSrcweir 
3360cdf0e10cSrcweir         for ( sal_Int32 i = 0; i < rToolbarDefinition->getCount(); i++ )
3361cdf0e10cSrcweir         {
3362cdf0e10cSrcweir             sal_Int32 nIndex( -1 );
3363cdf0e10cSrcweir             rtl::OUString aCommand;
3364cdf0e10cSrcweir 
3365cdf0e10cSrcweir             if ( rToolbarDefinition->getByIndex( i ) >>= aSeqPropValue )
3366cdf0e10cSrcweir             {
3367cdf0e10cSrcweir                 GetCommandFromSequence( aCommand, nIndex, aSeqPropValue );
3368cdf0e10cSrcweir                 if ( nIndex >= 0 && ( aCommand.indexOf( aSlotCmd ) == 0 ))
3369cdf0e10cSrcweir                 {
3370cdf0e10cSrcweir                     rtl::OUString aSlot( aCommand.copy( 5 ));
3371cdf0e10cSrcweir 
3372cdf0e10cSrcweir                     // We have to replace the old "slot-Command" with our new ".uno:-Command"
3373cdf0e10cSrcweir                     const SfxSlot* pSlot = pModule->GetSlotPool()->GetSlot( sal_uInt16( aSlot.toInt32() ));
3374cdf0e10cSrcweir                     if ( pSlot )
3375cdf0e10cSrcweir                     {
3376cdf0e10cSrcweir                         rtl::OUStringBuffer aStrBuf( aUnoCmd );
3377cdf0e10cSrcweir                         aStrBuf.appendAscii( pSlot->GetUnoName() );
3378cdf0e10cSrcweir 
3379cdf0e10cSrcweir                         aCommand = aStrBuf.makeStringAndClear();
3380cdf0e10cSrcweir                         aSeqPropValue[nIndex].Value <<= aCommand;
3381cdf0e10cSrcweir                         rToolbarDefinition->replaceByIndex( i, Any( aSeqPropValue ));
3382cdf0e10cSrcweir                     }
3383cdf0e10cSrcweir                 }
3384cdf0e10cSrcweir             }
3385cdf0e10cSrcweir         }
3386cdf0e10cSrcweir     }
3387cdf0e10cSrcweir }
3388cdf0e10cSrcweir 
getUIConfigurationManager()3389cdf0e10cSrcweir uno::Reference< ui::XUIConfigurationManager > SAL_CALL SfxBaseModel::getUIConfigurationManager()
3390cdf0e10cSrcweir         throw ( uno::RuntimeException )
3391cdf0e10cSrcweir {
3392cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3393cdf0e10cSrcweir 
3394cdf0e10cSrcweir     if ( !m_pData->m_xUIConfigurationManager.is() )
3395cdf0e10cSrcweir     {
3396cdf0e10cSrcweir         uno::Reference< ui::XUIConfigurationManager > xNewUIConfMan(
3397cdf0e10cSrcweir             ::comphelper::getProcessServiceFactory()->createInstance(
3398cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii( "com.sun.star.ui.UIConfigurationManager" )),
3399cdf0e10cSrcweir                 uno::UNO_QUERY );
3400cdf0e10cSrcweir 
3401cdf0e10cSrcweir         Reference< ui::XUIConfigurationStorage > xUIConfigStorage( xNewUIConfMan, uno::UNO_QUERY );
3402cdf0e10cSrcweir 		if ( xUIConfigStorage.is() )
3403cdf0e10cSrcweir 		{
3404cdf0e10cSrcweir             uno::Reference< XSTORAGE > xConfigStorage;
3405cdf0e10cSrcweir 
3406cdf0e10cSrcweir 			rtl::OUString aUIConfigFolderName( RTL_CONSTASCII_USTRINGPARAM( "Configurations2" ));
3407cdf0e10cSrcweir 			// First try to open with READWRITE and then READ
3408cdf0e10cSrcweir 			xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, embed::ElementModes::READWRITE );
3409cdf0e10cSrcweir 			if ( xConfigStorage.is() )
3410cdf0e10cSrcweir 			{
3411cdf0e10cSrcweir 				rtl::OUString aMediaTypeProp( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ));
3412cdf0e10cSrcweir 				rtl::OUString aUIConfigMediaType(
3413cdf0e10cSrcweir 						RTL_CONSTASCII_USTRINGPARAM( "application/vnd.sun.xml.ui.configuration" ) );
3414cdf0e10cSrcweir 				rtl::OUString aMediaType;
3415cdf0e10cSrcweir                 uno::Reference< beans::XPropertySet > xPropSet( xConfigStorage, uno::UNO_QUERY );
3416cdf0e10cSrcweir 				Any a = xPropSet->getPropertyValue( aMediaTypeProp );
3417cdf0e10cSrcweir 				if ( !( a >>= aMediaType ) || ( aMediaType.getLength() == 0 ))
3418cdf0e10cSrcweir 				{
3419cdf0e10cSrcweir 					a <<= aUIConfigMediaType;
3420cdf0e10cSrcweir 					xPropSet->setPropertyValue( aMediaTypeProp, a );
3421cdf0e10cSrcweir 				}
3422cdf0e10cSrcweir 			}
3423cdf0e10cSrcweir 			else
3424cdf0e10cSrcweir 				xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, embed::ElementModes::READ );
3425cdf0e10cSrcweir 
3426cdf0e10cSrcweir 			// initialize ui configuration manager with document substorage
3427cdf0e10cSrcweir 			xUIConfigStorage->setStorage( xConfigStorage );
3428cdf0e10cSrcweir 
3429cdf0e10cSrcweir             // embedded objects did not support local configuration data until OOo 3.0, so there's nothing to
3430cdf0e10cSrcweir             // migrate
3431cdf0e10cSrcweir             if ( m_pData->m_pObjectShell->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED )
3432cdf0e10cSrcweir             {
3433cdf0e10cSrcweir                 // Import old UI configuration from OOo 1.x
3434cdf0e10cSrcweir                 uno::Reference< XSTORAGE > xOOo1ConfigStorage;
3435cdf0e10cSrcweir                 rtl::OUString         aOOo1UIConfigFolderName( RTL_CONSTASCII_USTRINGPARAM( "Configurations" ));
3436cdf0e10cSrcweir 
3437cdf0e10cSrcweir                 // Try to open with READ
3438cdf0e10cSrcweir 				xOOo1ConfigStorage = getDocumentSubStorage( aOOo1UIConfigFolderName, embed::ElementModes::READ );
3439cdf0e10cSrcweir                 if ( xOOo1ConfigStorage.is() )
3440cdf0e10cSrcweir                 {
3441cdf0e10cSrcweir                     uno::Reference< lang::XMultiServiceFactory > xServiceMgr( ::comphelper::getProcessServiceFactory() );
3442cdf0e10cSrcweir                     uno::Sequence< uno::Reference< container::XIndexContainer > > rToolbars;
3443cdf0e10cSrcweir 
3444cdf0e10cSrcweir                     sal_Bool bImported = framework::UIConfigurationImporterOOo1x::ImportCustomToolbars(
3445cdf0e10cSrcweir                                             xNewUIConfMan, rToolbars, xServiceMgr, xOOo1ConfigStorage );
3446cdf0e10cSrcweir                     if ( bImported )
3447cdf0e10cSrcweir                     {
3448cdf0e10cSrcweir                         SfxObjectShell* pObjShell = SfxBaseModel::GetObjectShell();
3449cdf0e10cSrcweir 
3450cdf0e10cSrcweir                         char aNum[]   = "private:resource/toolbar/custom_OOo1x_0";
3451cdf0e10cSrcweir                         char aTitle[] = "Toolbar 0";
3452cdf0e10cSrcweir                         sal_Int32 nNumIndex = strlen( aNum )-1;
3453cdf0e10cSrcweir                         sal_Int32 nTitleIndex = strlen( aTitle )-1;
3454cdf0e10cSrcweir                         for ( sal_Int32 i = 0; i < rToolbars.getLength(); i++ )
3455cdf0e10cSrcweir                         {
3456cdf0e10cSrcweir                             aNum[nNumIndex]++;
3457cdf0e10cSrcweir                             aTitle[nTitleIndex]++;
3458cdf0e10cSrcweir 
3459cdf0e10cSrcweir                             rtl::OUString aCustomTbxName( RTL_CONSTASCII_USTRINGPARAM( aNum ));
3460cdf0e10cSrcweir                             rtl::OUString aCustomTbxTitle( RTL_CONSTASCII_USTRINGPARAM( aTitle ));
3461cdf0e10cSrcweir 
3462cdf0e10cSrcweir                             uno::Reference< container::XIndexContainer > xToolbar = rToolbars[i];
3463cdf0e10cSrcweir                             ConvertSlotsToCommands( pObjShell, xToolbar );
3464cdf0e10cSrcweir                             if ( !xNewUIConfMan->hasSettings( aCustomTbxName ))
3465cdf0e10cSrcweir                             {
3466cdf0e10cSrcweir                                 // Set UIName for the toolbar with container property
3467cdf0e10cSrcweir                                 uno::Reference< beans::XPropertySet > xPropSet( xToolbar, UNO_QUERY );
3468cdf0e10cSrcweir                                 if ( xPropSet.is() )
3469cdf0e10cSrcweir                                 {
3470cdf0e10cSrcweir                                     try
3471cdf0e10cSrcweir                                     {
3472cdf0e10cSrcweir                                         rtl::OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( "UIName" ));
3473cdf0e10cSrcweir                                         Any           aAny( aCustomTbxTitle );
3474cdf0e10cSrcweir                                         xPropSet->setPropertyValue( aPropName, aAny );
3475cdf0e10cSrcweir                                     }
3476cdf0e10cSrcweir                                     catch ( beans::UnknownPropertyException& )
3477cdf0e10cSrcweir                                     {
3478cdf0e10cSrcweir                                     }
3479cdf0e10cSrcweir                                 }
3480cdf0e10cSrcweir 
3481cdf0e10cSrcweir                                 uno::Reference< container::XIndexAccess > xToolbarData( xToolbar, uno::UNO_QUERY );
3482cdf0e10cSrcweir                                 xNewUIConfMan->insertSettings( aCustomTbxName, xToolbarData );
3483cdf0e10cSrcweir                                 uno::Reference< ui::XUIConfigurationPersistence > xPersist( xNewUIConfMan, uno::UNO_QUERY );
3484cdf0e10cSrcweir                                 xPersist->store();
3485cdf0e10cSrcweir                             }
3486cdf0e10cSrcweir                         }
3487cdf0e10cSrcweir                     }
3488cdf0e10cSrcweir                 }
3489cdf0e10cSrcweir             }
3490cdf0e10cSrcweir         }
3491cdf0e10cSrcweir 
3492cdf0e10cSrcweir 		m_pData->m_xUIConfigurationManager = xNewUIConfMan;
3493cdf0e10cSrcweir 	}
3494cdf0e10cSrcweir 
3495cdf0e10cSrcweir     return m_pData->m_xUIConfigurationManager;
3496cdf0e10cSrcweir }
3497cdf0e10cSrcweir 
3498cdf0e10cSrcweir //____________________________________________________________________________________________________
3499cdf0e10cSrcweir //	XVisualObject
3500cdf0e10cSrcweir //____________________________________________________________________________________________________
3501cdf0e10cSrcweir 
setVisualAreaSize(sal_Int64 nAspect,const awt::Size & aSize)3502cdf0e10cSrcweir void SAL_CALL SfxBaseModel::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize )
3503cdf0e10cSrcweir 		throw ( lang::IllegalArgumentException,
3504cdf0e10cSrcweir 				embed::WrongStateException,
3505cdf0e10cSrcweir 				uno::Exception,
3506cdf0e10cSrcweir 				uno::RuntimeException )
3507cdf0e10cSrcweir {
3508cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3509cdf0e10cSrcweir 
3510cdf0e10cSrcweir 	if ( !m_pData->m_pObjectShell.Is() )
3511cdf0e10cSrcweir 		throw uno::Exception(); // TODO: error handling
3512cdf0e10cSrcweir 
3513cdf0e10cSrcweir     SfxViewFrame* pViewFrm = SfxViewFrame::GetFirst( m_pData->m_pObjectShell, sal_False );
3514cdf0e10cSrcweir     if ( pViewFrm && m_pData->m_pObjectShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED && !pViewFrm->GetFrame().IsInPlace() )
3515cdf0e10cSrcweir 	{
3516cdf0e10cSrcweir         Window* pWindow = VCLUnoHelper::GetWindow( pViewFrm->GetFrame().GetFrameInterface()->getContainerWindow() );
3517cdf0e10cSrcweir         Size aWinSize = pWindow->GetSizePixel();
3518cdf0e10cSrcweir         awt::Size aCurrent = getVisualAreaSize( nAspect );
3519cdf0e10cSrcweir         Size aDiff( aSize.Width-aCurrent.Width, aSize.Height-aCurrent.Height );
3520cdf0e10cSrcweir         Size aWrongDiff = OutputDevice::LogicToLogic( aDiff , m_pData->m_pObjectShell->GetMapUnit(), pWindow->GetMapMode() );
3521cdf0e10cSrcweir         aDiff = pViewFrm->GetViewShell()->GetWindow()->LogicToPixel( aDiff );
3522cdf0e10cSrcweir         aWinSize.Width() += aDiff.Width();
3523cdf0e10cSrcweir         aWinSize.Height() += aDiff.Height();
3524cdf0e10cSrcweir         pWindow->SetSizePixel( aWinSize );
3525cdf0e10cSrcweir 	}
3526cdf0e10cSrcweir 	else
3527cdf0e10cSrcweir     {
3528cdf0e10cSrcweir         Rectangle aTmpRect = m_pData->m_pObjectShell->GetVisArea( ASPECT_CONTENT );
3529cdf0e10cSrcweir 		aTmpRect.SetSize( Size( aSize.Width, aSize.Height ) );
3530cdf0e10cSrcweir         m_pData->m_pObjectShell->SetVisArea( aTmpRect );
3531cdf0e10cSrcweir     }
3532cdf0e10cSrcweir }
3533cdf0e10cSrcweir 
getVisualAreaSize(sal_Int64)3534cdf0e10cSrcweir awt::Size SAL_CALL SfxBaseModel::getVisualAreaSize( sal_Int64 /*nAspect*/ )
3535cdf0e10cSrcweir 		throw ( lang::IllegalArgumentException,
3536cdf0e10cSrcweir 				embed::WrongStateException,
3537cdf0e10cSrcweir 				uno::Exception,
3538cdf0e10cSrcweir 				uno::RuntimeException)
3539cdf0e10cSrcweir {
3540cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3541cdf0e10cSrcweir 
3542cdf0e10cSrcweir 	if ( !m_pData->m_pObjectShell.Is() )
3543cdf0e10cSrcweir 		throw uno::Exception(); // TODO: error handling
3544cdf0e10cSrcweir 
3545cdf0e10cSrcweir 	Rectangle aTmpRect = m_pData->m_pObjectShell->GetVisArea( ASPECT_CONTENT );
3546cdf0e10cSrcweir 
3547cdf0e10cSrcweir #if 0
3548cdf0e10cSrcweir 	Window* pWindow = NULL;
3549cdf0e10cSrcweir 	SfxViewFrame* pViewFrm = m_pData->m_pObjectShell.Is() ?
3550cdf0e10cSrcweir 								SfxViewFrame::GetFirst( m_pData->m_pObjectShell, 0, sal_False ) : 0;
3551cdf0e10cSrcweir 
3552cdf0e10cSrcweir 	if ( pWindow )
3553cdf0e10cSrcweir 	{
3554cdf0e10cSrcweir 		MapMode aInternalMapMode( pViewFrm->GetWindow().GetMapMode() );
3555cdf0e10cSrcweir 		MapMode aExternalMapMode( m_pData->m_pObjectShell->GetMapUnit() );
3556cdf0e10cSrcweir 
3557cdf0e10cSrcweir     	aTmpRect = OutputDevice::LogicToLogic( aTmpRect, aInternalMapMode, aExternalMapMode );
3558cdf0e10cSrcweir 	}
3559cdf0e10cSrcweir #endif
3560cdf0e10cSrcweir 
3561cdf0e10cSrcweir 	return awt::Size( aTmpRect.GetWidth(), aTmpRect.GetHeight() );
3562cdf0e10cSrcweir }
3563cdf0e10cSrcweir 
3564cdf0e10cSrcweir 
getMapUnit(sal_Int64)3565cdf0e10cSrcweir sal_Int32 SAL_CALL SfxBaseModel::getMapUnit( sal_Int64 /*nAspect*/ )
3566cdf0e10cSrcweir 		throw ( uno::Exception,
3567cdf0e10cSrcweir 				uno::RuntimeException)
3568cdf0e10cSrcweir {
3569cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3570cdf0e10cSrcweir 
3571cdf0e10cSrcweir 	if ( !m_pData->m_pObjectShell.Is() )
3572cdf0e10cSrcweir 		throw uno::Exception(); // TODO: error handling
3573cdf0e10cSrcweir 
3574cdf0e10cSrcweir     return VCLUnoHelper::VCL2UnoEmbedMapUnit( m_pData->m_pObjectShell->GetMapUnit() );
3575cdf0e10cSrcweir }
3576cdf0e10cSrcweir 
getPreferredVisualRepresentation(::sal_Int64)3577cdf0e10cSrcweir embed::VisualRepresentation SAL_CALL SfxBaseModel::getPreferredVisualRepresentation( ::sal_Int64 /*nAspect*/ )
3578cdf0e10cSrcweir 		throw ( lang::IllegalArgumentException,
3579cdf0e10cSrcweir 				embed::WrongStateException,
3580cdf0e10cSrcweir 				uno::Exception,
3581cdf0e10cSrcweir 				uno::RuntimeException )
3582cdf0e10cSrcweir {
3583cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3584cdf0e10cSrcweir 
3585cdf0e10cSrcweir 	datatransfer::DataFlavor aDataFlavor(
3586cdf0e10cSrcweir             ::rtl::OUString::createFromAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ),
3587cdf0e10cSrcweir 			::rtl::OUString::createFromAscii( "GDIMetaFile" ),
3588cdf0e10cSrcweir 			::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) );
3589cdf0e10cSrcweir 
3590cdf0e10cSrcweir 	embed::VisualRepresentation aVisualRepresentation;
3591cdf0e10cSrcweir 	aVisualRepresentation.Data = getTransferData( aDataFlavor );
3592cdf0e10cSrcweir 	aVisualRepresentation.Flavor = aDataFlavor;
3593cdf0e10cSrcweir 
3594cdf0e10cSrcweir 	return aVisualRepresentation;
3595cdf0e10cSrcweir }
3596cdf0e10cSrcweir 
3597cdf0e10cSrcweir //____________________________________________________________________________________________________
3598cdf0e10cSrcweir //	XStorageBasedDocument
3599cdf0e10cSrcweir //____________________________________________________________________________________________________
3600cdf0e10cSrcweir 
loadFromStorage(const uno::Reference<XSTORAGE> & xStorage,const uno::Sequence<beans::PropertyValue> & aMediaDescriptor)3601cdf0e10cSrcweir void SAL_CALL SfxBaseModel::loadFromStorage( const uno::Reference< XSTORAGE >& xStorage,
3602cdf0e10cSrcweir                                              const uno::Sequence< beans::PropertyValue >& aMediaDescriptor )
3603cdf0e10cSrcweir     throw ( lang::IllegalArgumentException,
3604cdf0e10cSrcweir 			DOUBLEINITIALIZATIONEXCEPTION,
3605cdf0e10cSrcweir 			IOEXCEPTION,
3606cdf0e10cSrcweir 			EXCEPTION,
3607cdf0e10cSrcweir             uno::RuntimeException )
3608cdf0e10cSrcweir {
3609cdf0e10cSrcweir     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
3610cdf0e10cSrcweir     if ( IsInitialized() )
3611cdf0e10cSrcweir         throw ::com::sun::star::frame::DoubleInitializationException( ::rtl::OUString(), *this );
3612cdf0e10cSrcweir 
3613cdf0e10cSrcweir 	// after i36090 is fixed the pool from object shell can be used
3614cdf0e10cSrcweir 	// SfxAllItemSet aSet( m_pData->m_pObjectShell->GetPool() );
3615cdf0e10cSrcweir     SfxAllItemSet aSet( SFX_APP()->GetPool() );
3616cdf0e10cSrcweir 
3617cdf0e10cSrcweir     // the BaseURL is part of the ItemSet
3618cdf0e10cSrcweir     SfxMedium* pMedium = new SfxMedium( xStorage, String() );
3619cdf0e10cSrcweir 	TransformParameters( SID_OPENDOC, aMediaDescriptor, aSet );
3620cdf0e10cSrcweir 	pMedium->GetItemSet()->Put( aSet );
3621cdf0e10cSrcweir 
3622cdf0e10cSrcweir 	// allow to use an interactionhandler (if there is one)
3623cdf0e10cSrcweir 	pMedium->UseInteractionHandler( sal_True );
3624cdf0e10cSrcweir 
3625cdf0e10cSrcweir 	SFX_ITEMSET_ARG( &aSet, pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False);
3626cdf0e10cSrcweir 	sal_Bool bTemplate = pTemplateItem && pTemplateItem->GetValue();
3627cdf0e10cSrcweir     m_pData->m_pObjectShell->SetActivateEvent_Impl( bTemplate ? SFX_EVENT_CREATEDOC : SFX_EVENT_OPENDOC );
3628cdf0e10cSrcweir     m_pData->m_pObjectShell->Get_Impl()->bOwnsStorage = sal_False;
3629cdf0e10cSrcweir 
3630cdf0e10cSrcweir 	// load document
3631cdf0e10cSrcweir 	if ( !m_pData->m_pObjectShell->DoLoad(pMedium) )
3632cdf0e10cSrcweir 	{
3633cdf0e10cSrcweir 		sal_uInt32 nError = m_pData->m_pObjectShell->GetErrorCode();
3634cdf0e10cSrcweir 		throw task::ErrorCodeIOException( ::rtl::OUString(),
3635cdf0e10cSrcweir 											uno::Reference< uno::XInterface >(),
3636cdf0e10cSrcweir 											nError ? nError : ERRCODE_IO_CANTREAD );
3637cdf0e10cSrcweir 	}
3638cdf0e10cSrcweir }
3639cdf0e10cSrcweir 
storeToStorage(const uno::Reference<XSTORAGE> & xStorage,const uno::Sequence<beans::PropertyValue> & aMediaDescriptor)3640cdf0e10cSrcweir void SAL_CALL SfxBaseModel::storeToStorage( const uno::Reference< XSTORAGE >& xStorage,
3641cdf0e10cSrcweir                                 const uno::Sequence< beans::PropertyValue >& aMediaDescriptor )
3642cdf0e10cSrcweir     throw ( lang::IllegalArgumentException,
3643cdf0e10cSrcweir 			IOEXCEPTION,
3644cdf0e10cSrcweir 			EXCEPTION,
3645cdf0e10cSrcweir             uno::RuntimeException )
3646cdf0e10cSrcweir {
3647cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3648cdf0e10cSrcweir 
3649cdf0e10cSrcweir     uno::Reference< XSTORAGE > xResult;
3650cdf0e10cSrcweir     if ( !m_pData->m_pObjectShell.Is() )
3651cdf0e10cSrcweir 		throw IOEXCEPTION(); // TODO:
3652cdf0e10cSrcweir 
3653cdf0e10cSrcweir 	SfxAllItemSet aSet( m_pData->m_pObjectShell->GetPool() );
3654cdf0e10cSrcweir 	TransformParameters( SID_SAVEASDOC, aMediaDescriptor, aSet );
3655cdf0e10cSrcweir 
3656cdf0e10cSrcweir 	// TODO/LATER: may be a special URL "private:storage" should be used
3657cdf0e10cSrcweir     SFX_ITEMSET_ARG( &aSet, pItem, SfxStringItem, SID_FILTER_NAME, sal_False );
3658cdf0e10cSrcweir     sal_Int32 nVersion = SOFFICE_FILEFORMAT_CURRENT;
3659cdf0e10cSrcweir     if( pItem )
3660cdf0e10cSrcweir     {
3661cdf0e10cSrcweir         String aFilterName = pItem->GetValue();
3662cdf0e10cSrcweir         const SfxFilter* pFilter = SFX_APP()->GetFilterMatcher().GetFilter4FilterName( aFilterName );
3663cdf0e10cSrcweir         if ( pFilter && pFilter->UsesStorage() )
3664cdf0e10cSrcweir             nVersion = pFilter->GetVersion();
3665cdf0e10cSrcweir     }
3666cdf0e10cSrcweir 
3667cdf0e10cSrcweir 	sal_Bool bSuccess = sal_False;
3668cdf0e10cSrcweir 	if ( xStorage == m_pData->m_pObjectShell->GetStorage() )
3669cdf0e10cSrcweir 	{
3670cdf0e10cSrcweir 		// storing to the own storage
3671cdf0e10cSrcweir 		bSuccess = m_pData->m_pObjectShell->DoSave();
3672cdf0e10cSrcweir 	}
3673cdf0e10cSrcweir 	else
3674cdf0e10cSrcweir 	{
3675cdf0e10cSrcweir 		// TODO/LATER: if the provided storage has some data inside the storing might fail, probably the storage must be truncated
3676cdf0e10cSrcweir 		// TODO/LATER: is it possible to have a template here?
3677cdf0e10cSrcweir     	m_pData->m_pObjectShell->SetupStorage( xStorage, nVersion, sal_False );
3678cdf0e10cSrcweir 
3679cdf0e10cSrcweir     	// BaseURL is part of the ItemSet
3680cdf0e10cSrcweir     	SfxMedium aMedium( xStorage, String(), &aSet );
3681cdf0e10cSrcweir     	aMedium.CanDisposeStorage_Impl( sal_False );
3682cdf0e10cSrcweir         if ( aMedium.GetFilter() )
3683cdf0e10cSrcweir         {
3684cdf0e10cSrcweir             // storing without a valid filter will often crash
3685cdf0e10cSrcweir             bSuccess = m_pData->m_pObjectShell->DoSaveObjectAs( aMedium, sal_True );
3686cdf0e10cSrcweir             m_pData->m_pObjectShell->DoSaveCompleted( NULL );
3687cdf0e10cSrcweir         }
3688cdf0e10cSrcweir 	}
3689cdf0e10cSrcweir 
3690cdf0e10cSrcweir     sal_uInt32 nError = m_pData->m_pObjectShell->GetErrorCode();
3691cdf0e10cSrcweir     m_pData->m_pObjectShell->ResetError();
3692cdf0e10cSrcweir 
3693cdf0e10cSrcweir     // the warnings are currently not transported
3694cdf0e10cSrcweir 	if ( !bSuccess )
3695cdf0e10cSrcweir 	{
3696cdf0e10cSrcweir 		throw task::ErrorCodeIOException( ::rtl::OUString(),
3697cdf0e10cSrcweir 											uno::Reference< uno::XInterface >(),
3698cdf0e10cSrcweir 											nError ? nError : ERRCODE_IO_GENERAL );
3699cdf0e10cSrcweir 	}
3700cdf0e10cSrcweir }
3701cdf0e10cSrcweir 
switchToStorage(const uno::Reference<XSTORAGE> & xStorage)3702cdf0e10cSrcweir void SAL_CALL SfxBaseModel::switchToStorage( const uno::Reference< XSTORAGE >& xStorage )
3703cdf0e10cSrcweir         throw ( lang::IllegalArgumentException,
3704cdf0e10cSrcweir 				IOEXCEPTION,
3705cdf0e10cSrcweir 				EXCEPTION,
3706cdf0e10cSrcweir                 uno::RuntimeException )
3707cdf0e10cSrcweir {
3708cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3709cdf0e10cSrcweir 
3710cdf0e10cSrcweir     uno::Reference< XSTORAGE > xResult;
3711cdf0e10cSrcweir     if ( !m_pData->m_pObjectShell.Is() )
3712cdf0e10cSrcweir 		throw IOEXCEPTION(); // TODO:
3713cdf0e10cSrcweir 
3714cdf0e10cSrcweir 	// the persistence should be switched only if the storage is different
3715cdf0e10cSrcweir 	if ( xStorage != m_pData->m_pObjectShell->GetStorage()
3716cdf0e10cSrcweir 	  && !m_pData->m_pObjectShell->SwitchPersistance( xStorage ) )
3717cdf0e10cSrcweir 	{
3718cdf0e10cSrcweir 		sal_uInt32 nError = m_pData->m_pObjectShell->GetErrorCode();
3719cdf0e10cSrcweir 		throw task::ErrorCodeIOException( ::rtl::OUString(),
3720cdf0e10cSrcweir 											uno::Reference< uno::XInterface >(),
3721cdf0e10cSrcweir 											nError ? nError : ERRCODE_IO_GENERAL );
3722cdf0e10cSrcweir 	}
3723cdf0e10cSrcweir 
3724cdf0e10cSrcweir     m_pData->m_pObjectShell->Get_Impl()->bOwnsStorage = sal_False;
3725cdf0e10cSrcweir }
3726cdf0e10cSrcweir 
getDocumentStorage()3727cdf0e10cSrcweir uno::Reference< XSTORAGE > SAL_CALL SfxBaseModel::getDocumentStorage()
3728cdf0e10cSrcweir 		throw ( IOEXCEPTION,
3729cdf0e10cSrcweir 				EXCEPTION,
3730cdf0e10cSrcweir                 uno::RuntimeException )
3731cdf0e10cSrcweir {
3732cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3733cdf0e10cSrcweir 
3734cdf0e10cSrcweir     uno::Reference< XSTORAGE > xResult;
3735cdf0e10cSrcweir     if ( !m_pData->m_pObjectShell.Is() )
3736cdf0e10cSrcweir 		throw IOEXCEPTION(); // TODO
3737cdf0e10cSrcweir 
3738cdf0e10cSrcweir 	return m_pData->m_pObjectShell->GetStorage();
3739cdf0e10cSrcweir }
3740cdf0e10cSrcweir 
addStorageChangeListener(const uno::Reference<document::XStorageChangeListener> & xListener)3741cdf0e10cSrcweir void SAL_CALL SfxBaseModel::addStorageChangeListener(
3742cdf0e10cSrcweir             const uno::Reference< document::XStorageChangeListener >& xListener )
3743cdf0e10cSrcweir         throw ( uno::RuntimeException )
3744cdf0e10cSrcweir {
3745cdf0e10cSrcweir     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
3746cdf0e10cSrcweir 
3747cdf0e10cSrcweir 	m_pData->m_aInterfaceContainer.addInterface(
3748cdf0e10cSrcweir                                     ::getCppuType((const uno::Reference< document::XStorageChangeListener >*)0), xListener );
3749cdf0e10cSrcweir }
3750cdf0e10cSrcweir 
removeStorageChangeListener(const uno::Reference<document::XStorageChangeListener> & xListener)3751cdf0e10cSrcweir void SAL_CALL SfxBaseModel::removeStorageChangeListener(
3752cdf0e10cSrcweir             const uno::Reference< document::XStorageChangeListener >& xListener )
3753cdf0e10cSrcweir         throw ( uno::RuntimeException )
3754cdf0e10cSrcweir {
3755cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3756cdf0e10cSrcweir 
3757cdf0e10cSrcweir 	m_pData->m_aInterfaceContainer.removeInterface(
3758cdf0e10cSrcweir                                     ::getCppuType((const uno::Reference< document::XStorageChangeListener >*)0), xListener );
3759cdf0e10cSrcweir }
3760cdf0e10cSrcweir 
3761cdf0e10cSrcweir #include "printhelper.hxx"
impl_getPrintHelper()3762cdf0e10cSrcweir bool SfxBaseModel::impl_getPrintHelper()
3763cdf0e10cSrcweir {
3764cdf0e10cSrcweir     if ( m_pData->m_xPrintable.is() )
3765cdf0e10cSrcweir         return true;
3766cdf0e10cSrcweir     m_pData->m_xPrintable = new SfxPrintHelper();
3767cdf0e10cSrcweir     uno::Reference < lang::XInitialization > xInit( m_pData->m_xPrintable, uno::UNO_QUERY );
3768cdf0e10cSrcweir     uno::Sequence < uno::Any > aValues(1);
3769cdf0e10cSrcweir     aValues[0] <<= uno::Reference < frame::XModel > (static_cast< frame::XModel* >(this), uno::UNO_QUERY );
3770cdf0e10cSrcweir     xInit->initialize( aValues );
3771cdf0e10cSrcweir     uno::Reference < view::XPrintJobBroadcaster > xBrd( m_pData->m_xPrintable, uno::UNO_QUERY );
3772cdf0e10cSrcweir     xBrd->addPrintJobListener( new SfxPrintHelperListener_Impl( m_pData ) );
3773cdf0e10cSrcweir     return true;
3774cdf0e10cSrcweir }
3775cdf0e10cSrcweir 
3776cdf0e10cSrcweir //=============================================================================
3777cdf0e10cSrcweir // css.frame.XModule
setIdentifier(const::rtl::OUString & Identifier)3778cdf0e10cSrcweir  void SAL_CALL SfxBaseModel::setIdentifier(const ::rtl::OUString& Identifier)
3779cdf0e10cSrcweir     throw (css::uno::RuntimeException)
3780cdf0e10cSrcweir {
3781cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3782cdf0e10cSrcweir     m_pData->m_sModuleIdentifier = Identifier;
3783cdf0e10cSrcweir }
3784cdf0e10cSrcweir 
3785cdf0e10cSrcweir //=============================================================================
3786cdf0e10cSrcweir // css.frame.XModule
getIdentifier()3787cdf0e10cSrcweir  ::rtl::OUString SAL_CALL SfxBaseModel::getIdentifier()
3788cdf0e10cSrcweir     throw (css::uno::RuntimeException)
3789cdf0e10cSrcweir {
3790cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3791cdf0e10cSrcweir     if (m_pData->m_sModuleIdentifier.getLength() > 0)
3792cdf0e10cSrcweir         return m_pData->m_sModuleIdentifier;
3793cdf0e10cSrcweir     if (m_pData->m_pObjectShell)
3794cdf0e10cSrcweir         return m_pData->m_pObjectShell->GetFactory().GetDocumentServiceName();
3795cdf0e10cSrcweir     return ::rtl::OUString();
3796cdf0e10cSrcweir }
3797cdf0e10cSrcweir 
3798cdf0e10cSrcweir //=============================================================================
impl_getTitleHelper()3799cdf0e10cSrcweir css::uno::Reference< css::frame::XTitle > SfxBaseModel::impl_getTitleHelper ()
3800cdf0e10cSrcweir {
3801cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3802cdf0e10cSrcweir 
3803cdf0e10cSrcweir     if ( ! m_pData->m_xTitleHelper.is ())
3804cdf0e10cSrcweir     {
3805cdf0e10cSrcweir         css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR   = ::comphelper::getProcessServiceFactory ();
3806cdf0e10cSrcweir         css::uno::Reference< css::frame::XUntitledNumbers >    xDesktop(xSMGR->createInstance(SERVICENAME_DESKTOP), css::uno::UNO_QUERY_THROW);
3807cdf0e10cSrcweir         css::uno::Reference< css::frame::XModel >              xThis   (static_cast< css::frame::XModel* >(this), css::uno::UNO_QUERY_THROW);
3808cdf0e10cSrcweir 
3809cdf0e10cSrcweir         ::framework::TitleHelper* pHelper = new ::framework::TitleHelper(xSMGR);
3810cdf0e10cSrcweir         m_pData->m_xTitleHelper = css::uno::Reference< css::frame::XTitle >(static_cast< ::cppu::OWeakObject* >(pHelper), css::uno::UNO_QUERY_THROW);
3811cdf0e10cSrcweir         pHelper->setOwner                   (xThis   );
3812cdf0e10cSrcweir         pHelper->connectWithUntitledNumbers (xDesktop);
3813cdf0e10cSrcweir     }
3814cdf0e10cSrcweir 
3815cdf0e10cSrcweir     return m_pData->m_xTitleHelper;
3816cdf0e10cSrcweir }
3817cdf0e10cSrcweir 
3818cdf0e10cSrcweir //=============================================================================
impl_getUntitledHelper()3819cdf0e10cSrcweir css::uno::Reference< css::frame::XUntitledNumbers > SfxBaseModel::impl_getUntitledHelper ()
3820cdf0e10cSrcweir {
3821cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3822cdf0e10cSrcweir 
3823cdf0e10cSrcweir     if ( ! m_pData->m_xNumberedControllers.is ())
3824cdf0e10cSrcweir     {
3825cdf0e10cSrcweir         css::uno::Reference< css::frame::XModel > xThis   (static_cast< css::frame::XModel* >(this), css::uno::UNO_QUERY_THROW);
3826cdf0e10cSrcweir         ::comphelper::NumberedCollection*         pHelper = new ::comphelper::NumberedCollection();
3827cdf0e10cSrcweir 
3828cdf0e10cSrcweir         m_pData->m_xNumberedControllers = css::uno::Reference< css::frame::XUntitledNumbers >(static_cast< ::cppu::OWeakObject* >(pHelper), css::uno::UNO_QUERY_THROW);
3829cdf0e10cSrcweir 
3830cdf0e10cSrcweir         pHelper->setOwner          (xThis);
3831cdf0e10cSrcweir         pHelper->setUntitledPrefix (::rtl::OUString::createFromAscii(" : "));
3832cdf0e10cSrcweir     }
3833cdf0e10cSrcweir 
3834cdf0e10cSrcweir     return m_pData->m_xNumberedControllers;
3835cdf0e10cSrcweir }
3836cdf0e10cSrcweir 
3837cdf0e10cSrcweir //=============================================================================
3838cdf0e10cSrcweir // css.frame.XTitle
getTitle()3839cdf0e10cSrcweir ::rtl::OUString SAL_CALL SfxBaseModel::getTitle()
3840cdf0e10cSrcweir     throw (css::uno::RuntimeException)
3841cdf0e10cSrcweir {
3842cdf0e10cSrcweir     // SYNCHRONIZED ->
3843cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3844cdf0e10cSrcweir 
3845cdf0e10cSrcweir     ::rtl::OUString aResult = impl_getTitleHelper()->getTitle ();
3846cdf0e10cSrcweir     if ( !m_pData->m_bExternalTitle && m_pData->m_pObjectShell )
3847cdf0e10cSrcweir     {
3848cdf0e10cSrcweir         SfxMedium* pMedium = m_pData->m_pObjectShell->GetMedium();
3849cdf0e10cSrcweir         if ( pMedium )
3850cdf0e10cSrcweir         {
3851cdf0e10cSrcweir             SFX_ITEMSET_ARG( pMedium->GetItemSet(), pRepairedDocItem, SfxBoolItem, SID_REPAIRPACKAGE, sal_False );
3852cdf0e10cSrcweir             if ( pRepairedDocItem && pRepairedDocItem->GetValue() )
3853cdf0e10cSrcweir                 aResult += String( SfxResId(STR_REPAIREDDOCUMENT) );
3854cdf0e10cSrcweir         }
3855cdf0e10cSrcweir 
3856cdf0e10cSrcweir         if ( m_pData->m_pObjectShell->IsReadOnlyUI() || (pMedium && pMedium->IsReadOnly()) )
3857cdf0e10cSrcweir             aResult += ::rtl::OUString( String( SfxResId(STR_READONLY) ) );
3858cdf0e10cSrcweir         else if ( m_pData->m_pObjectShell->IsDocShared() )
3859cdf0e10cSrcweir             aResult += ::rtl::OUString( String( SfxResId(STR_SHARED) ) );
3860cdf0e10cSrcweir 
3861cdf0e10cSrcweir         if ( m_pData->m_pObjectShell->GetDocumentSignatureState() == SIGNATURESTATE_SIGNATURES_OK )
3862cdf0e10cSrcweir             aResult += String( SfxResId( RID_XMLSEC_DOCUMENTSIGNED ) );
3863cdf0e10cSrcweir     }
3864cdf0e10cSrcweir 
3865cdf0e10cSrcweir     return aResult;
3866cdf0e10cSrcweir }
3867cdf0e10cSrcweir 
3868cdf0e10cSrcweir //=============================================================================
3869cdf0e10cSrcweir // css.frame.XTitle
setTitle(const::rtl::OUString & sTitle)3870cdf0e10cSrcweir void SAL_CALL SfxBaseModel::setTitle( const ::rtl::OUString& sTitle )
3871cdf0e10cSrcweir     throw (css::uno::RuntimeException)
3872cdf0e10cSrcweir {
3873cdf0e10cSrcweir     // SYNCHRONIZED ->
3874cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3875cdf0e10cSrcweir 
3876cdf0e10cSrcweir     impl_getTitleHelper()->setTitle (sTitle);
3877cdf0e10cSrcweir     m_pData->m_bExternalTitle = sal_True;
3878cdf0e10cSrcweir }
3879cdf0e10cSrcweir 
3880cdf0e10cSrcweir //=============================================================================
3881cdf0e10cSrcweir // css.frame.XTitleChangeBroadcaster
addTitleChangeListener(const css::uno::Reference<css::frame::XTitleChangeListener> & xListener)3882cdf0e10cSrcweir void SAL_CALL SfxBaseModel::addTitleChangeListener( const css::uno::Reference< css::frame::XTitleChangeListener >& xListener )
3883cdf0e10cSrcweir     throw (css::uno::RuntimeException)
3884cdf0e10cSrcweir {
3885cdf0e10cSrcweir     // SYNCHRONIZED ->
3886cdf0e10cSrcweir     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
3887cdf0e10cSrcweir 
3888cdf0e10cSrcweir     css::uno::Reference< css::frame::XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper(), css::uno::UNO_QUERY);
3889cdf0e10cSrcweir     if (xBroadcaster.is ())
3890cdf0e10cSrcweir         xBroadcaster->addTitleChangeListener (xListener);
3891cdf0e10cSrcweir }
3892cdf0e10cSrcweir 
3893cdf0e10cSrcweir //=============================================================================
3894cdf0e10cSrcweir // css.frame.XTitleChangeBroadcaster
removeTitleChangeListener(const css::uno::Reference<css::frame::XTitleChangeListener> & xListener)3895cdf0e10cSrcweir void SAL_CALL SfxBaseModel::removeTitleChangeListener( const css::uno::Reference< css::frame::XTitleChangeListener >& xListener )
3896cdf0e10cSrcweir     throw (css::uno::RuntimeException)
3897cdf0e10cSrcweir {
3898cdf0e10cSrcweir     // SYNCHRONIZED ->
3899cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3900cdf0e10cSrcweir 
3901cdf0e10cSrcweir     css::uno::Reference< css::frame::XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper(), css::uno::UNO_QUERY);
3902cdf0e10cSrcweir     if (xBroadcaster.is ())
3903cdf0e10cSrcweir         xBroadcaster->removeTitleChangeListener (xListener);
3904cdf0e10cSrcweir }
3905cdf0e10cSrcweir 
3906cdf0e10cSrcweir //=============================================================================
3907cdf0e10cSrcweir // css.frame.XUntitledNumbers
leaseNumber(const css::uno::Reference<css::uno::XInterface> & xComponent)3908cdf0e10cSrcweir ::sal_Int32 SAL_CALL SfxBaseModel::leaseNumber( const css::uno::Reference< css::uno::XInterface >& xComponent )
3909cdf0e10cSrcweir     throw (css::lang::IllegalArgumentException,
3910cdf0e10cSrcweir            css::uno::RuntimeException         )
3911cdf0e10cSrcweir {
3912cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3913cdf0e10cSrcweir 
3914cdf0e10cSrcweir     return impl_getUntitledHelper ()->leaseNumber (xComponent);
3915cdf0e10cSrcweir }
3916cdf0e10cSrcweir 
3917cdf0e10cSrcweir //=============================================================================
3918cdf0e10cSrcweir // css.frame.XUntitledNumbers
releaseNumber(::sal_Int32 nNumber)3919cdf0e10cSrcweir void SAL_CALL SfxBaseModel::releaseNumber( ::sal_Int32 nNumber )
3920cdf0e10cSrcweir     throw (css::lang::IllegalArgumentException,
3921cdf0e10cSrcweir            css::uno::RuntimeException         )
3922cdf0e10cSrcweir {
3923cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3924cdf0e10cSrcweir     impl_getUntitledHelper ()->releaseNumber (nNumber);
3925cdf0e10cSrcweir }
3926cdf0e10cSrcweir 
3927cdf0e10cSrcweir //=============================================================================
3928cdf0e10cSrcweir // css.frame.XUntitledNumbers
releaseNumberForComponent(const css::uno::Reference<css::uno::XInterface> & xComponent)3929cdf0e10cSrcweir void SAL_CALL SfxBaseModel::releaseNumberForComponent( const css::uno::Reference< css::uno::XInterface >& xComponent )
3930cdf0e10cSrcweir     throw (css::lang::IllegalArgumentException,
3931cdf0e10cSrcweir            css::uno::RuntimeException         )
3932cdf0e10cSrcweir {
3933cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3934cdf0e10cSrcweir     impl_getUntitledHelper ()->releaseNumberForComponent (xComponent);
3935cdf0e10cSrcweir }
3936cdf0e10cSrcweir 
3937cdf0e10cSrcweir //=============================================================================
3938cdf0e10cSrcweir // css.frame.XUntitledNumbers
getUntitledPrefix()3939cdf0e10cSrcweir ::rtl::OUString SAL_CALL SfxBaseModel::getUntitledPrefix()
3940cdf0e10cSrcweir     throw (css::uno::RuntimeException)
3941cdf0e10cSrcweir {
3942cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3943cdf0e10cSrcweir     return impl_getUntitledHelper ()->getUntitledPrefix ();
3944cdf0e10cSrcweir }
3945cdf0e10cSrcweir 
3946cdf0e10cSrcweir //=============================================================================
3947cdf0e10cSrcweir // css::frame::XModel2
getControllers()3948cdf0e10cSrcweir css::uno::Reference< css::container::XEnumeration > SAL_CALL SfxBaseModel::getControllers()
3949cdf0e10cSrcweir     throw (css::uno::RuntimeException)
3950cdf0e10cSrcweir {
3951cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3952cdf0e10cSrcweir 
3953cdf0e10cSrcweir     sal_Int32 c = m_pData->m_seqControllers.getLength();
3954cdf0e10cSrcweir     sal_Int32 i = 0;
3955cdf0e10cSrcweir     css::uno::Sequence< css::uno::Any > lEnum(c);
3956cdf0e10cSrcweir     for (i=0; i<c; ++i)
3957cdf0e10cSrcweir         lEnum[i] <<= m_pData->m_seqControllers[i];
3958cdf0e10cSrcweir 
3959cdf0e10cSrcweir     ::comphelper::OAnyEnumeration*                      pEnum = new ::comphelper::OAnyEnumeration(lEnum);
3960cdf0e10cSrcweir     css::uno::Reference< css::container::XEnumeration > xEnum(static_cast< css::container::XEnumeration* >(pEnum), css::uno::UNO_QUERY_THROW);
3961cdf0e10cSrcweir     return xEnum;
3962cdf0e10cSrcweir }
3963cdf0e10cSrcweir 
3964cdf0e10cSrcweir //=============================================================================
3965cdf0e10cSrcweir // css::frame::XModel2
getAvailableViewControllerNames()3966cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > SAL_CALL SfxBaseModel::getAvailableViewControllerNames()
3967cdf0e10cSrcweir     throw (css::uno::RuntimeException)
3968cdf0e10cSrcweir {
3969cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3970cdf0e10cSrcweir 
3971cdf0e10cSrcweir     const SfxObjectFactory& rDocumentFactory = GetObjectShell()->GetFactory();
3972cdf0e10cSrcweir     const sal_Int32 nViewFactoryCount = rDocumentFactory.GetViewFactoryCount();
3973cdf0e10cSrcweir 
3974cdf0e10cSrcweir     Sequence< ::rtl::OUString > aViewNames( nViewFactoryCount );
3975cdf0e10cSrcweir     for ( sal_Int32 nViewNo = 0; nViewNo < nViewFactoryCount; ++nViewNo )
3976cdf0e10cSrcweir         aViewNames[nViewNo] = rDocumentFactory.GetViewFactory( nViewNo ).GetAPIViewName();
3977cdf0e10cSrcweir     return aViewNames;
3978cdf0e10cSrcweir }
3979cdf0e10cSrcweir 
3980cdf0e10cSrcweir //=============================================================================
3981cdf0e10cSrcweir // css::frame::XModel2
createDefaultViewController(const css::uno::Reference<css::frame::XFrame> & i_rFrame)3982cdf0e10cSrcweir css::uno::Reference< css::frame::XController2 > SAL_CALL SfxBaseModel::createDefaultViewController( const css::uno::Reference< css::frame::XFrame >& i_rFrame )
3983cdf0e10cSrcweir     throw (css::uno::RuntimeException         ,
3984cdf0e10cSrcweir            css::lang::IllegalArgumentException,
3985cdf0e10cSrcweir            css::uno::Exception                )
3986cdf0e10cSrcweir {
3987cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3988cdf0e10cSrcweir 
3989cdf0e10cSrcweir     const SfxObjectFactory& rDocumentFactory = GetObjectShell()->GetFactory();
3990cdf0e10cSrcweir     const ::rtl::OUString sDefaultViewName = rDocumentFactory.GetViewFactory( 0 ).GetAPIViewName();
3991cdf0e10cSrcweir 
3992cdf0e10cSrcweir     aGuard.clear();
3993cdf0e10cSrcweir 
3994cdf0e10cSrcweir     return createViewController( sDefaultViewName, Sequence< PropertyValue >(), i_rFrame );
3995cdf0e10cSrcweir }
3996cdf0e10cSrcweir 
3997cdf0e10cSrcweir //=============================================================================
3998cdf0e10cSrcweir namespace sfx { namespace intern {
3999cdf0e10cSrcweir 
4000cdf0e10cSrcweir     /** a class which, in its dtor, cleans up variuos objects (well, at the moment only the frame) collected during
4001cdf0e10cSrcweir         the creation of a document view, unless the creation was successful.
4002cdf0e10cSrcweir     */
4003cdf0e10cSrcweir     class SAL_DLLPRIVATE ViewCreationGuard
4004cdf0e10cSrcweir     {
4005cdf0e10cSrcweir     public:
ViewCreationGuard()4006cdf0e10cSrcweir         ViewCreationGuard()
4007cdf0e10cSrcweir             :m_bSuccess( false )
4008cdf0e10cSrcweir         {
4009cdf0e10cSrcweir         }
4010cdf0e10cSrcweir 
~ViewCreationGuard()4011cdf0e10cSrcweir         ~ViewCreationGuard()
4012cdf0e10cSrcweir         {
4013cdf0e10cSrcweir             if ( !m_bSuccess )
4014cdf0e10cSrcweir                 impl_closeAll();
4015cdf0e10cSrcweir         }
4016cdf0e10cSrcweir 
takeFrameOwnership(SfxFrame * i_pFrame)4017cdf0e10cSrcweir         void takeFrameOwnership( SfxFrame* i_pFrame )
4018cdf0e10cSrcweir         {
4019cdf0e10cSrcweir             OSL_PRECOND( !m_aWeakFrame, "ViewCreationGuard::takeFrameOwnership: already have a frame!" );
4020cdf0e10cSrcweir             OSL_PRECOND( i_pFrame != NULL, "ViewCreationGuard::takeFrameOwnership: invalid frame!" );
4021cdf0e10cSrcweir             m_aWeakFrame = i_pFrame;
4022cdf0e10cSrcweir         }
4023cdf0e10cSrcweir 
releaseAll()4024cdf0e10cSrcweir         void    releaseAll()
4025cdf0e10cSrcweir         {
4026cdf0e10cSrcweir             m_bSuccess = true;
4027cdf0e10cSrcweir         }
4028cdf0e10cSrcweir 
4029cdf0e10cSrcweir     private:
impl_closeAll()4030cdf0e10cSrcweir         void impl_closeAll()
4031cdf0e10cSrcweir         {
4032cdf0e10cSrcweir             if ( m_aWeakFrame && !m_aWeakFrame->GetCurrentDocument() )
4033cdf0e10cSrcweir             {
4034cdf0e10cSrcweir                 m_aWeakFrame->SetFrameInterface_Impl( NULL );
4035cdf0e10cSrcweir                 m_aWeakFrame->DoClose();
4036cdf0e10cSrcweir             }
4037cdf0e10cSrcweir         }
4038cdf0e10cSrcweir 
4039cdf0e10cSrcweir     private:
4040cdf0e10cSrcweir         bool            m_bSuccess;
4041cdf0e10cSrcweir         SfxFrameWeak    m_aWeakFrame;
4042cdf0e10cSrcweir     };
4043cdf0e10cSrcweir } }
4044cdf0e10cSrcweir 
4045cdf0e10cSrcweir //=============================================================================
FindOrCreateViewFrame_Impl(const Reference<XFrame> & i_rFrame,::sfx::intern::ViewCreationGuard & i_rGuard) const4046cdf0e10cSrcweir SfxViewFrame* SfxBaseModel::FindOrCreateViewFrame_Impl( const Reference< XFrame >& i_rFrame, ::sfx::intern::ViewCreationGuard& i_rGuard ) const
4047cdf0e10cSrcweir {
4048cdf0e10cSrcweir     SfxViewFrame* pViewFrame = NULL;
4049cdf0e10cSrcweir     for (   pViewFrame = SfxViewFrame::GetFirst( GetObjectShell(), sal_False );
4050cdf0e10cSrcweir             pViewFrame;
4051cdf0e10cSrcweir             pViewFrame= SfxViewFrame::GetNext( *pViewFrame, GetObjectShell(), sal_False )
4052cdf0e10cSrcweir         )
4053cdf0e10cSrcweir     {
4054cdf0e10cSrcweir         if ( pViewFrame->GetFrame().GetFrameInterface() == i_rFrame )
4055cdf0e10cSrcweir             break;
4056cdf0e10cSrcweir     }
4057cdf0e10cSrcweir     if ( !pViewFrame )
4058cdf0e10cSrcweir     {
4059cdf0e10cSrcweir     #if OSL_DEBUG_LEVEL > 0
4060cdf0e10cSrcweir         for (   SfxFrame* pCheckFrame = SfxFrame::GetFirst();
4061cdf0e10cSrcweir                 pCheckFrame;
4062cdf0e10cSrcweir                 pCheckFrame = SfxFrame::GetNext( *pCheckFrame )
4063cdf0e10cSrcweir              )
4064cdf0e10cSrcweir         {
4065cdf0e10cSrcweir             if ( pCheckFrame->GetFrameInterface() == i_rFrame )
4066cdf0e10cSrcweir             {
4067cdf0e10cSrcweir                 if  (   ( pCheckFrame->GetCurrentViewFrame() != NULL )
4068cdf0e10cSrcweir                     ||  ( pCheckFrame->GetCurrentDocument() != NULL )
4069cdf0e10cSrcweir                     )
4070cdf0e10cSrcweir                     // Note that it is perfectly letgitimate that during loading into an XFrame which already contains
4071cdf0e10cSrcweir                     // a document, there exist two SfxFrame instances bound to this XFrame - the old one, which will be
4072cdf0e10cSrcweir                     // destroyed later, and the new one, which we're going to create
4073cdf0e10cSrcweir                     continue;
4074cdf0e10cSrcweir 
4075cdf0e10cSrcweir                 OSL_ENSURE( false, "SfxBaseModel::FindOrCreateViewFrame_Impl: there already is an SfxFrame for the given XFrame, but no view in it!" );
4076cdf0e10cSrcweir                     // nowadays, we're the only instance allowed to create an SfxFrame for an XFrame, so this case here should not happen
4077cdf0e10cSrcweir                 break;
4078cdf0e10cSrcweir             }
4079cdf0e10cSrcweir         }
4080cdf0e10cSrcweir     #endif
4081cdf0e10cSrcweir 
4082cdf0e10cSrcweir         SfxFrame* pTargetFrame = SfxFrame::Create( i_rFrame );
4083cdf0e10cSrcweir         ENSURE_OR_THROW( pTargetFrame, "could not create an SfxFrame" );
4084cdf0e10cSrcweir         i_rGuard.takeFrameOwnership( pTargetFrame );
4085cdf0e10cSrcweir 
4086cdf0e10cSrcweir         // prepare it
4087cdf0e10cSrcweir         pTargetFrame->PrepareForDoc_Impl( *GetObjectShell() );
4088cdf0e10cSrcweir 
4089cdf0e10cSrcweir         // create view frame
4090cdf0e10cSrcweir         pViewFrame = new SfxViewFrame( *pTargetFrame, GetObjectShell() );
4091cdf0e10cSrcweir     }
4092cdf0e10cSrcweir     return pViewFrame;
4093cdf0e10cSrcweir }
4094cdf0e10cSrcweir 
4095cdf0e10cSrcweir //=============================================================================
4096cdf0e10cSrcweir // css::frame::XModel2
createViewController(const::rtl::OUString & i_rViewName,const Sequence<PropertyValue> & i_rArguments,const Reference<XFrame> & i_rFrame)4097cdf0e10cSrcweir css::uno::Reference< css::frame::XController2 > SAL_CALL SfxBaseModel::createViewController(
4098cdf0e10cSrcweir         const ::rtl::OUString& i_rViewName, const Sequence< PropertyValue >& i_rArguments, const Reference< XFrame >& i_rFrame )
4099cdf0e10cSrcweir     throw (css::uno::RuntimeException         ,
4100cdf0e10cSrcweir            css::lang::IllegalArgumentException,
4101cdf0e10cSrcweir            css::uno::Exception                )
4102cdf0e10cSrcweir {
4103cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4104cdf0e10cSrcweir 
4105cdf0e10cSrcweir     if ( !i_rFrame.is() )
4106cdf0e10cSrcweir         throw css::lang::IllegalArgumentException( ::rtl::OUString(), *this, 3 );
4107cdf0e10cSrcweir 
4108cdf0e10cSrcweir     // find the proper SFX view factory
4109cdf0e10cSrcweir     SfxViewFactory* pViewFactory = GetObjectShell()->GetFactory().GetViewFactoryByViewName( i_rViewName );
4110cdf0e10cSrcweir     if ( !pViewFactory )
4111cdf0e10cSrcweir         throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
4112cdf0e10cSrcweir 
4113cdf0e10cSrcweir     // determine previous shell (used in some special cases)
4114cdf0e10cSrcweir     Reference< XController > xPreviousController( i_rFrame->getController() );
4115cdf0e10cSrcweir     const Reference< XModel > xMe( this );
4116cdf0e10cSrcweir     if  (   ( xPreviousController.is() )
4117cdf0e10cSrcweir         &&  ( xMe != xPreviousController->getModel() )
4118cdf0e10cSrcweir         )
4119cdf0e10cSrcweir     {
4120cdf0e10cSrcweir         xPreviousController.clear();
4121cdf0e10cSrcweir     }
4122cdf0e10cSrcweir     SfxViewShell* pOldViewShell = SfxViewShell::Get( xPreviousController );
4123cdf0e10cSrcweir     OSL_ENSURE( !xPreviousController.is() || ( pOldViewShell != NULL ),
4124cdf0e10cSrcweir         "SfxBaseModel::createViewController: invalid old controller!" );
4125cdf0e10cSrcweir 
4126cdf0e10cSrcweir     // a guard which will clean up in case of failure
4127cdf0e10cSrcweir     ::sfx::intern::ViewCreationGuard aViewCreationGuard;
4128cdf0e10cSrcweir 
4129cdf0e10cSrcweir     // determine the ViewFrame belonging to the given XFrame
4130cdf0e10cSrcweir     SfxViewFrame* pViewFrame = FindOrCreateViewFrame_Impl( i_rFrame, aViewCreationGuard );
4131cdf0e10cSrcweir     OSL_POSTCOND( pViewFrame, "SfxBaseModel::createViewController: no frame?" );
4132cdf0e10cSrcweir 
4133cdf0e10cSrcweir     // delegate to SFX' view factory
4134cdf0e10cSrcweir     pViewFrame->GetBindings().ENTERREGISTRATIONS();
4135cdf0e10cSrcweir     SfxViewShell* pViewShell = pViewFactory->CreateInstance( pViewFrame, pOldViewShell );
4136cdf0e10cSrcweir     pViewFrame->GetBindings().LEAVEREGISTRATIONS();
4137cdf0e10cSrcweir     ENSURE_OR_THROW( pViewShell, "invalid view shell provided by factory" );
4138cdf0e10cSrcweir 
4139cdf0e10cSrcweir     // by setting the ViewShell it is prevented that disposing the Controller will destroy this ViewFrame also
4140cdf0e10cSrcweir     pViewFrame->GetDispatcher()->SetDisableFlags( 0 );
4141cdf0e10cSrcweir     pViewFrame->SetViewShell_Impl( pViewShell );
4142cdf0e10cSrcweir 
4143cdf0e10cSrcweir     // remember ViewID
4144cdf0e10cSrcweir     pViewFrame->SetCurViewId_Impl( pViewFactory->GetOrdinal() );
4145cdf0e10cSrcweir 
4146cdf0e10cSrcweir     // ensure a default controller, if the view shell did not provide an own implementation
4147cdf0e10cSrcweir     if ( !pViewShell->GetController().is() )
4148cdf0e10cSrcweir         pViewShell->SetController( new SfxBaseController( pViewShell ) );
4149cdf0e10cSrcweir 
4150cdf0e10cSrcweir     // pass the creation arguments to the controller
4151cdf0e10cSrcweir     SfxBaseController* pBaseController = pViewShell->GetBaseController_Impl();
4152cdf0e10cSrcweir     ENSURE_OR_THROW( pBaseController, "invalid controller implementation!" );
4153cdf0e10cSrcweir     pBaseController->SetCreationArguments_Impl( i_rArguments );
4154cdf0e10cSrcweir 
4155cdf0e10cSrcweir     // some initial view settings, coming from our most recent attachResource call
4156cdf0e10cSrcweir     ::comphelper::NamedValueCollection aDocumentLoadArgs( getArgs() );
4157cdf0e10cSrcweir     if ( aDocumentLoadArgs.getOrDefault( "ViewOnly", false ) )
4158cdf0e10cSrcweir 	    pViewFrame->GetFrame().SetMenuBarOn_Impl( sal_False );
4159cdf0e10cSrcweir 
4160cdf0e10cSrcweir     const sal_Int16 nPluginMode = aDocumentLoadArgs.getOrDefault( "PluginMode", sal_Int16( 0 ) );
4161cdf0e10cSrcweir     if ( nPluginMode == 1 )
4162cdf0e10cSrcweir     {
4163cdf0e10cSrcweir         pViewFrame->ForceOuterResize_Impl( sal_False );
4164cdf0e10cSrcweir         pViewFrame->GetBindings().HidePopups( sal_True );
4165cdf0e10cSrcweir 
4166cdf0e10cSrcweir         SfxFrame& rFrame = pViewFrame->GetFrame();
4167cdf0e10cSrcweir         // MBA: layoutmanager of inplace frame starts locked and invisible
4168cdf0e10cSrcweir         rFrame.GetWorkWindow_Impl()->MakeVisible_Impl( sal_False );
4169cdf0e10cSrcweir         rFrame.GetWorkWindow_Impl()->Lock_Impl( sal_True );
4170cdf0e10cSrcweir 
4171cdf0e10cSrcweir         rFrame.GetWindow().SetBorderStyle( WINDOW_BORDER_NOBORDER );
4172cdf0e10cSrcweir         pViewFrame->GetWindow().SetBorderStyle( WINDOW_BORDER_NOBORDER );
4173cdf0e10cSrcweir     }
4174cdf0e10cSrcweir 
4175cdf0e10cSrcweir     // tell the guard we were successful
4176cdf0e10cSrcweir     aViewCreationGuard.releaseAll();
4177cdf0e10cSrcweir 
4178cdf0e10cSrcweir     // outta gere
4179cdf0e10cSrcweir     return pBaseController;
4180cdf0e10cSrcweir }
4181cdf0e10cSrcweir 
4182cdf0e10cSrcweir //=============================================================================
4183cdf0e10cSrcweir // RDF DocumentMetadataAccess
4184cdf0e10cSrcweir 
4185cdf0e10cSrcweir // ::com::sun::star::rdf::XRepositorySupplier:
4186cdf0e10cSrcweir uno::Reference< rdf::XRepository > SAL_CALL
getRDFRepository()4187cdf0e10cSrcweir SfxBaseModel::getRDFRepository() throw (uno::RuntimeException)
4188cdf0e10cSrcweir {
4189cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4190cdf0e10cSrcweir 
4191cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4192cdf0e10cSrcweir     if (!xDMA.is()) {
4193cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4194cdf0e10cSrcweir             "model has no document metadata"), *this );
4195cdf0e10cSrcweir     }
4196cdf0e10cSrcweir 
4197cdf0e10cSrcweir     return xDMA->getRDFRepository();
4198cdf0e10cSrcweir }
4199cdf0e10cSrcweir 
4200cdf0e10cSrcweir // ::com::sun::star::rdf::XNode:
4201cdf0e10cSrcweir ::rtl::OUString SAL_CALL
getStringValue()4202cdf0e10cSrcweir SfxBaseModel::getStringValue() throw (uno::RuntimeException)
4203cdf0e10cSrcweir {
4204cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4205cdf0e10cSrcweir 
4206cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4207cdf0e10cSrcweir     if (!xDMA.is()) {
4208cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4209cdf0e10cSrcweir             "model has no document metadata"), *this );
4210cdf0e10cSrcweir     }
4211cdf0e10cSrcweir 
4212cdf0e10cSrcweir     return xDMA->getStringValue();
4213cdf0e10cSrcweir }
4214cdf0e10cSrcweir 
4215cdf0e10cSrcweir // ::com::sun::star::rdf::XURI:
4216cdf0e10cSrcweir ::rtl::OUString SAL_CALL
getNamespace()4217cdf0e10cSrcweir SfxBaseModel::getNamespace() throw (uno::RuntimeException)
4218cdf0e10cSrcweir {
4219cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4220cdf0e10cSrcweir 
4221cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4222cdf0e10cSrcweir     if (!xDMA.is()) {
4223cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4224cdf0e10cSrcweir             "model has no document metadata"), *this );
4225cdf0e10cSrcweir     }
4226cdf0e10cSrcweir 
4227cdf0e10cSrcweir     return xDMA->getNamespace();
4228cdf0e10cSrcweir }
4229cdf0e10cSrcweir 
4230cdf0e10cSrcweir ::rtl::OUString SAL_CALL
getLocalName()4231cdf0e10cSrcweir SfxBaseModel::getLocalName() throw (uno::RuntimeException)
4232cdf0e10cSrcweir {
4233cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4234cdf0e10cSrcweir 
4235cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4236cdf0e10cSrcweir     if (!xDMA.is()) {
4237cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4238cdf0e10cSrcweir             "model has no document metadata"), *this );
4239cdf0e10cSrcweir     }
4240cdf0e10cSrcweir 
4241cdf0e10cSrcweir     return xDMA->getLocalName();
4242cdf0e10cSrcweir }
4243cdf0e10cSrcweir 
4244cdf0e10cSrcweir // ::com::sun::star::rdf::XDocumentMetadataAccess:
4245cdf0e10cSrcweir uno::Reference< rdf::XMetadatable > SAL_CALL
getElementByMetadataReference(const::com::sun::star::beans::StringPair & i_rReference)4246cdf0e10cSrcweir SfxBaseModel::getElementByMetadataReference(
4247cdf0e10cSrcweir     const ::com::sun::star::beans::StringPair & i_rReference)
4248cdf0e10cSrcweir throw (uno::RuntimeException)
4249cdf0e10cSrcweir {
4250cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4251cdf0e10cSrcweir 
4252cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4253cdf0e10cSrcweir     if (!xDMA.is()) {
4254cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4255cdf0e10cSrcweir             "model has no document metadata"), *this );
4256cdf0e10cSrcweir     }
4257cdf0e10cSrcweir 
4258cdf0e10cSrcweir     return xDMA->getElementByMetadataReference(i_rReference);
4259cdf0e10cSrcweir }
4260cdf0e10cSrcweir 
4261cdf0e10cSrcweir uno::Reference< rdf::XMetadatable > SAL_CALL
getElementByURI(const uno::Reference<rdf::XURI> & i_xURI)4262cdf0e10cSrcweir SfxBaseModel::getElementByURI(const uno::Reference< rdf::XURI > & i_xURI)
4263cdf0e10cSrcweir throw (uno::RuntimeException, lang::IllegalArgumentException)
4264cdf0e10cSrcweir {
4265cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4266cdf0e10cSrcweir 
4267cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4268cdf0e10cSrcweir     if (!xDMA.is()) {
4269cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4270cdf0e10cSrcweir             "model has no document metadata"), *this );
4271cdf0e10cSrcweir     }
4272cdf0e10cSrcweir 
4273cdf0e10cSrcweir     return xDMA->getElementByURI(i_xURI);
4274cdf0e10cSrcweir }
4275cdf0e10cSrcweir 
4276cdf0e10cSrcweir uno::Sequence< uno::Reference< rdf::XURI > > SAL_CALL
getMetadataGraphsWithType(const uno::Reference<rdf::XURI> & i_xType)4277cdf0e10cSrcweir SfxBaseModel::getMetadataGraphsWithType(
4278cdf0e10cSrcweir     const uno::Reference<rdf::XURI> & i_xType)
4279cdf0e10cSrcweir throw (uno::RuntimeException, lang::IllegalArgumentException)
4280cdf0e10cSrcweir {
4281cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4282cdf0e10cSrcweir 
4283cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4284cdf0e10cSrcweir     if (!xDMA.is()) {
4285cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4286cdf0e10cSrcweir             "model has no document metadata"), *this );
4287cdf0e10cSrcweir     }
4288cdf0e10cSrcweir 
4289cdf0e10cSrcweir     return xDMA->getMetadataGraphsWithType(i_xType);
4290cdf0e10cSrcweir }
4291cdf0e10cSrcweir 
4292cdf0e10cSrcweir uno::Reference<rdf::XURI> SAL_CALL
addMetadataFile(const::rtl::OUString & i_rFileName,const uno::Sequence<uno::Reference<rdf::XURI>> & i_rTypes)4293cdf0e10cSrcweir SfxBaseModel::addMetadataFile(const ::rtl::OUString & i_rFileName,
4294cdf0e10cSrcweir     const uno::Sequence < uno::Reference< rdf::XURI > > & i_rTypes)
4295cdf0e10cSrcweir throw (uno::RuntimeException, lang::IllegalArgumentException,
4296cdf0e10cSrcweir     container::ElementExistException)
4297cdf0e10cSrcweir {
4298cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4299cdf0e10cSrcweir 
4300cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4301cdf0e10cSrcweir     if (!xDMA.is()) {
4302cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4303cdf0e10cSrcweir             "model has no document metadata"), *this );
4304cdf0e10cSrcweir     }
4305cdf0e10cSrcweir 
4306cdf0e10cSrcweir     return xDMA->addMetadataFile(i_rFileName, i_rTypes);
4307cdf0e10cSrcweir }
4308cdf0e10cSrcweir 
4309cdf0e10cSrcweir uno::Reference<rdf::XURI> SAL_CALL
importMetadataFile(::sal_Int16 i_Format,const uno::Reference<io::XInputStream> & i_xInStream,const::rtl::OUString & i_rFileName,const uno::Reference<rdf::XURI> & i_xBaseURI,const uno::Sequence<uno::Reference<rdf::XURI>> & i_rTypes)4310cdf0e10cSrcweir SfxBaseModel::importMetadataFile(::sal_Int16 i_Format,
4311cdf0e10cSrcweir     const uno::Reference< io::XInputStream > & i_xInStream,
4312cdf0e10cSrcweir     const ::rtl::OUString & i_rFileName,
4313cdf0e10cSrcweir     const uno::Reference< rdf::XURI > & i_xBaseURI,
4314cdf0e10cSrcweir     const uno::Sequence < uno::Reference< rdf::XURI > > & i_rTypes)
4315cdf0e10cSrcweir throw (uno::RuntimeException, lang::IllegalArgumentException,
4316cdf0e10cSrcweir     datatransfer::UnsupportedFlavorException,
4317cdf0e10cSrcweir     container::ElementExistException, rdf::ParseException, io::IOException)
4318cdf0e10cSrcweir {
4319cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4320cdf0e10cSrcweir 
4321cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4322cdf0e10cSrcweir     if (!xDMA.is()) {
4323cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4324cdf0e10cSrcweir             "model has no document metadata"), *this );
4325cdf0e10cSrcweir     }
4326cdf0e10cSrcweir 
4327cdf0e10cSrcweir     return xDMA->importMetadataFile(i_Format,
4328cdf0e10cSrcweir         i_xInStream, i_rFileName, i_xBaseURI, i_rTypes);
4329cdf0e10cSrcweir }
4330cdf0e10cSrcweir 
4331cdf0e10cSrcweir void SAL_CALL
removeMetadataFile(const uno::Reference<rdf::XURI> & i_xGraphName)4332cdf0e10cSrcweir SfxBaseModel::removeMetadataFile(
4333cdf0e10cSrcweir     const uno::Reference< rdf::XURI > & i_xGraphName)
4334cdf0e10cSrcweir throw (uno::RuntimeException, lang::IllegalArgumentException,
4335cdf0e10cSrcweir     container::NoSuchElementException)
4336cdf0e10cSrcweir {
4337cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4338cdf0e10cSrcweir 
4339cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4340cdf0e10cSrcweir     if (!xDMA.is()) {
4341cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4342cdf0e10cSrcweir             "model has no document metadata"), *this );
4343cdf0e10cSrcweir     }
4344cdf0e10cSrcweir 
4345cdf0e10cSrcweir     return xDMA->removeMetadataFile(i_xGraphName);
4346cdf0e10cSrcweir }
4347cdf0e10cSrcweir 
4348cdf0e10cSrcweir void SAL_CALL
addContentOrStylesFile(const::rtl::OUString & i_rFileName)4349cdf0e10cSrcweir SfxBaseModel::addContentOrStylesFile(const ::rtl::OUString & i_rFileName)
4350cdf0e10cSrcweir throw (uno::RuntimeException, lang::IllegalArgumentException,
4351cdf0e10cSrcweir     container::ElementExistException)
4352cdf0e10cSrcweir {
4353cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4354cdf0e10cSrcweir 
4355cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4356cdf0e10cSrcweir     if (!xDMA.is()) {
4357cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4358cdf0e10cSrcweir             "model has no document metadata"), *this );
4359cdf0e10cSrcweir     }
4360cdf0e10cSrcweir 
4361cdf0e10cSrcweir     return xDMA->addContentOrStylesFile(i_rFileName);
4362cdf0e10cSrcweir }
4363cdf0e10cSrcweir 
4364cdf0e10cSrcweir void SAL_CALL
removeContentOrStylesFile(const::rtl::OUString & i_rFileName)4365cdf0e10cSrcweir SfxBaseModel::removeContentOrStylesFile(const ::rtl::OUString & i_rFileName)
4366cdf0e10cSrcweir throw (uno::RuntimeException, lang::IllegalArgumentException,
4367cdf0e10cSrcweir     container::NoSuchElementException)
4368cdf0e10cSrcweir {
4369cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4370cdf0e10cSrcweir 
4371cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4372cdf0e10cSrcweir     if (!xDMA.is()) {
4373cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4374cdf0e10cSrcweir             "model has no document metadata"), *this );
4375cdf0e10cSrcweir     }
4376cdf0e10cSrcweir 
4377cdf0e10cSrcweir     return xDMA->removeContentOrStylesFile(i_rFileName);
4378cdf0e10cSrcweir }
4379cdf0e10cSrcweir 
4380cdf0e10cSrcweir void SAL_CALL
loadMetadataFromStorage(uno::Reference<embed::XStorage> const & i_xStorage,uno::Reference<rdf::XURI> const & i_xBaseURI,uno::Reference<task::XInteractionHandler> const & i_xHandler)4381cdf0e10cSrcweir SfxBaseModel::loadMetadataFromStorage(
4382cdf0e10cSrcweir     uno::Reference< embed::XStorage > const & i_xStorage,
4383cdf0e10cSrcweir     uno::Reference<rdf::XURI> const & i_xBaseURI,
4384cdf0e10cSrcweir     uno::Reference<task::XInteractionHandler> const & i_xHandler)
4385cdf0e10cSrcweir throw (uno::RuntimeException, lang::IllegalArgumentException,
4386cdf0e10cSrcweir     lang::WrappedTargetException)
4387cdf0e10cSrcweir {
4388cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4389cdf0e10cSrcweir 
4390cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(
4391cdf0e10cSrcweir         m_pData->CreateDMAUninitialized());
4392cdf0e10cSrcweir     if (!xDMA.is()) {
4393cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4394cdf0e10cSrcweir             "model has no document metadata"), *this );
4395cdf0e10cSrcweir     }
4396cdf0e10cSrcweir 
4397cdf0e10cSrcweir     try {
4398cdf0e10cSrcweir         xDMA->loadMetadataFromStorage(i_xStorage, i_xBaseURI, i_xHandler);
4399cdf0e10cSrcweir     } catch (lang::IllegalArgumentException &) {
4400cdf0e10cSrcweir         throw; // not initialized
4401cdf0e10cSrcweir     } catch (uno::Exception &) {
4402cdf0e10cSrcweir         // UGLY: if it's a RuntimeException, we can't be sure DMA is initialzed
4403cdf0e10cSrcweir         m_pData->m_xDocumentMetadata = xDMA;
4404cdf0e10cSrcweir         throw;
4405cdf0e10cSrcweir     }
4406cdf0e10cSrcweir     m_pData->m_xDocumentMetadata = xDMA;
4407cdf0e10cSrcweir 
4408cdf0e10cSrcweir }
4409cdf0e10cSrcweir 
4410cdf0e10cSrcweir void SAL_CALL
storeMetadataToStorage(uno::Reference<embed::XStorage> const & i_xStorage)4411cdf0e10cSrcweir SfxBaseModel::storeMetadataToStorage(
4412cdf0e10cSrcweir     uno::Reference< embed::XStorage > const & i_xStorage)
4413cdf0e10cSrcweir throw (uno::RuntimeException, lang::IllegalArgumentException,
4414cdf0e10cSrcweir     lang::WrappedTargetException)
4415cdf0e10cSrcweir {
4416cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4417cdf0e10cSrcweir 
4418cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4419cdf0e10cSrcweir     if (!xDMA.is()) {
4420cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4421cdf0e10cSrcweir             "model has no document metadata"), *this );
4422cdf0e10cSrcweir     }
4423cdf0e10cSrcweir 
4424cdf0e10cSrcweir     return xDMA->storeMetadataToStorage(i_xStorage);
4425cdf0e10cSrcweir }
4426cdf0e10cSrcweir 
4427cdf0e10cSrcweir void SAL_CALL
loadMetadataFromMedium(const uno::Sequence<beans::PropertyValue> & i_rMedium)4428cdf0e10cSrcweir SfxBaseModel::loadMetadataFromMedium(
4429cdf0e10cSrcweir     const uno::Sequence< beans::PropertyValue > & i_rMedium)
4430cdf0e10cSrcweir throw (uno::RuntimeException, lang::IllegalArgumentException,
4431cdf0e10cSrcweir     lang::WrappedTargetException)
4432cdf0e10cSrcweir {
4433cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4434cdf0e10cSrcweir 
4435cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(
4436cdf0e10cSrcweir         m_pData->CreateDMAUninitialized());
4437cdf0e10cSrcweir     if (!xDMA.is()) {
4438cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4439cdf0e10cSrcweir             "model has no document metadata"), *this );
4440cdf0e10cSrcweir     }
4441cdf0e10cSrcweir 
4442cdf0e10cSrcweir     try {
4443cdf0e10cSrcweir         xDMA->loadMetadataFromMedium(i_rMedium);
4444cdf0e10cSrcweir     } catch (lang::IllegalArgumentException &) {
4445cdf0e10cSrcweir         throw; // not initialized
4446cdf0e10cSrcweir     } catch (uno::Exception &) {
4447cdf0e10cSrcweir         // UGLY: if it's a RuntimeException, we can't be sure DMA is initialzed
4448cdf0e10cSrcweir         m_pData->m_xDocumentMetadata = xDMA;
4449cdf0e10cSrcweir         throw;
4450cdf0e10cSrcweir     }
4451cdf0e10cSrcweir     m_pData->m_xDocumentMetadata = xDMA;
4452cdf0e10cSrcweir }
4453cdf0e10cSrcweir 
4454cdf0e10cSrcweir void SAL_CALL
storeMetadataToMedium(const uno::Sequence<beans::PropertyValue> & i_rMedium)4455cdf0e10cSrcweir SfxBaseModel::storeMetadataToMedium(
4456cdf0e10cSrcweir     const uno::Sequence< beans::PropertyValue > & i_rMedium)
4457cdf0e10cSrcweir throw (uno::RuntimeException, lang::IllegalArgumentException,
4458cdf0e10cSrcweir     lang::WrappedTargetException)
4459cdf0e10cSrcweir {
4460cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4461cdf0e10cSrcweir 
4462cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4463cdf0e10cSrcweir     if (!xDMA.is()) {
4464cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4465cdf0e10cSrcweir             "model has no document metadata"), *this );
4466cdf0e10cSrcweir     }
4467cdf0e10cSrcweir 
4468cdf0e10cSrcweir     return xDMA->storeMetadataToMedium(i_rMedium);
4469cdf0e10cSrcweir }
4470cdf0e10cSrcweir 
4471cdf0e10cSrcweir // =====================================================================================================================
4472cdf0e10cSrcweir // = SfxModelSubComponent
4473cdf0e10cSrcweir // =====================================================================================================================
4474cdf0e10cSrcweir 
~SfxModelSubComponent()4475cdf0e10cSrcweir SfxModelSubComponent::~SfxModelSubComponent()
4476cdf0e10cSrcweir {
4477cdf0e10cSrcweir }
4478cdf0e10cSrcweir 
disposing()4479cdf0e10cSrcweir void SfxModelSubComponent::disposing()
4480cdf0e10cSrcweir {
4481cdf0e10cSrcweir     // nothing to do here
4482cdf0e10cSrcweir }
4483cdf0e10cSrcweir 
4484