xref: /trunk/main/sfx2/source/doc/sfxbasemodel.cxx (revision f6b63cab6a777f6a85aebdbffb72add87b8265ed)
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
10cdf0e10cSrcweir  *
11d119d52dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
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.
19cdf0e10cSrcweir  *
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 
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 };
179cdf0e10cSrcweir SfxDocInfoListener_Impl::~SfxDocInfoListener_Impl()
180cdf0e10cSrcweir {
181cdf0e10cSrcweir }
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 
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 
238cdf0e10cSrcweir     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 
261cdf0e10cSrcweir     virtual ~IMPL_SfxBaseModel_DataContainer()
262cdf0e10cSrcweir     {
263cdf0e10cSrcweir     }
264cdf0e10cSrcweir 
265cdf0e10cSrcweir     // ::sfx2::IModifiableDocument
266cdf0e10cSrcweir     virtual void storageIsModified()
267cdf0e10cSrcweir     {
268cdf0e10cSrcweir         if ( m_pObjectShell.Is() && !m_pObjectShell->IsModified() )
269cdf0e10cSrcweir             m_pObjectShell->SetModified( sal_True );
270cdf0e10cSrcweir     }
271cdf0e10cSrcweir 
272cdf0e10cSrcweir     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 
316cdf0e10cSrcweir     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;
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 
343cdf0e10cSrcweir void SAL_CALL SfxPrintHelperListener_Impl::disposing( const lang::EventObject& ) throw ( uno::RuntimeException )
344cdf0e10cSrcweir {
345cdf0e10cSrcweir     m_pData->m_xPrintable = 0;
346cdf0e10cSrcweir }
347cdf0e10cSrcweir 
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 
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 
415cdf0e10cSrcweir SfxOwnFramesLocker::~SfxOwnFramesLocker()
416cdf0e10cSrcweir {
417cdf0e10cSrcweir     UnlockFrames();
418cdf0e10cSrcweir }
419cdf0e10cSrcweir 
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 
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 
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 
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 //________________________________________________________________________________________________________
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 
554cdf0e10cSrcweir SfxBaseModel::~SfxBaseModel()
555cdf0e10cSrcweir {
556cdf0e10cSrcweir     DBG_DTOR(sfx2_SfxBaseModel,NULL);
557cdf0e10cSrcweir }
558cdf0e10cSrcweir 
559cdf0e10cSrcweir //________________________________________________________________________________________________________
560cdf0e10cSrcweir //  XInterface
561cdf0e10cSrcweir //________________________________________________________________________________________________________
562cdf0e10cSrcweir 
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 
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 
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 {
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 
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 
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 
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 
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 */
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 */
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 */
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 
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 
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 
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 
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 
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 
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
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 
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() )
940cdf0e10cSrcweir         m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0), xListener );
941cdf0e10cSrcweir }
942cdf0e10cSrcweir 
943cdf0e10cSrcweir //________________________________________________________________________________________________________
944cdf0e10cSrcweir //  frame::XModel
945cdf0e10cSrcweir //________________________________________________________________________________________________________
946cdf0e10cSrcweir 
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 
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 
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 
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 
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:
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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" ) ) )
1613cdf0e10cSrcweir               && !aSeqArgs[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StatusIndicator" ) ) ) )
1614cdf0e10cSrcweir             {
1615cdf0e10cSrcweir                 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." ) ) );
1616cdf0e10cSrcweir                 m_pData->m_pObjectShell->StoreLog();
1617cdf0e10cSrcweir 
1618cdf0e10cSrcweir                 ::rtl::OUString aMessage( RTL_CONSTASCII_USTRINGPARAM( "Unexpected MediaDescriptor parameter: " ) );
1619cdf0e10cSrcweir                 aMessage += aSeqArgs[nInd].Name;
1620cdf0e10cSrcweir                 throw lang::IllegalArgumentException( aMessage, uno::Reference< uno::XInterface >(), 1 );
1621cdf0e10cSrcweir             }
1622cdf0e10cSrcweir         }
1623cdf0e10cSrcweir 
1624cdf0e10cSrcweir         SfxAllItemSet *pParams = new SfxAllItemSet( SFX_APP()->GetPool() );
1625cdf0e10cSrcweir         TransformParameters( SID_SAVEDOC, aSeqArgs, *pParams );
1626cdf0e10cSrcweir 
1627cdf0e10cSrcweir         SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEDOC, GlobalEventConfig::GetEventName(STR_EVENT_SAVEDOC), m_pData->m_pObjectShell ) );
1628cdf0e10cSrcweir 
1629cdf0e10cSrcweir         sal_Bool bRet = sal_False;
1630cdf0e10cSrcweir 
1631cdf0e10cSrcweir         // TODO/LATER: let the embedded case of saving be handled more careful
1632cdf0e10cSrcweir         if ( m_pData->m_pObjectShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
1633cdf0e10cSrcweir         {
1634cdf0e10cSrcweir             // If this is an embedded object that has no URL based location it should be stored to own storage.
1635cdf0e10cSrcweir             // An embedded object can have a location based on URL in case it is a link, then it should be
1636cdf0e10cSrcweir             // stored in normal way.
1637cdf0e10cSrcweir             if ( !hasLocation() || getLocation().compareToAscii( "private:", 8 ) == 0 )
1638cdf0e10cSrcweir             {
1639cdf0e10cSrcweir                 // actually in this very rare case only UI parameters have sence
1640cdf0e10cSrcweir                 // TODO/LATER: should be done later, after integration of sb19
1641cdf0e10cSrcweir                 bRet = m_pData->m_pObjectShell->DoSave()
1642cdf0e10cSrcweir                     && m_pData->m_pObjectShell->DoSaveCompleted();
1643cdf0e10cSrcweir             }
1644cdf0e10cSrcweir             else
1645cdf0e10cSrcweir             {
1646cdf0e10cSrcweir                 bRet = m_pData->m_pObjectShell->Save_Impl( pParams );
1647cdf0e10cSrcweir             }
1648cdf0e10cSrcweir         }
1649cdf0e10cSrcweir         else
1650cdf0e10cSrcweir             bRet = m_pData->m_pObjectShell->Save_Impl( pParams );
1651cdf0e10cSrcweir 
1652cdf0e10cSrcweir         DELETEZ( pParams );
1653cdf0e10cSrcweir 
1654cdf0e10cSrcweir         sal_uInt32 nErrCode = m_pData->m_pObjectShell->GetError() ? m_pData->m_pObjectShell->GetError()
1655cdf0e10cSrcweir                                                                     : ERRCODE_IO_CANTWRITE;
1656cdf0e10cSrcweir         m_pData->m_pObjectShell->ResetError();
1657cdf0e10cSrcweir 
1658cdf0e10cSrcweir         if ( bRet )
1659cdf0e10cSrcweir         {
1660cdf0e10cSrcweir             m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "successful saving." ) ) );
1661cdf0e10cSrcweir             m_pData->m_aPreusedFilterName = GetMediumFilterName_Impl();
1662cdf0e10cSrcweir 
1663cdf0e10cSrcweir             SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEDOCDONE, GlobalEventConfig::GetEventName(STR_EVENT_SAVEDOCDONE), m_pData->m_pObjectShell ) );
1664cdf0e10cSrcweir         }
1665cdf0e10cSrcweir         else
1666cdf0e10cSrcweir         {
1667cdf0e10cSrcweir             m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing failed!" ) ) );
1668cdf0e10cSrcweir             m_pData->m_pObjectShell->StoreLog();
1669cdf0e10cSrcweir 
1670cdf0e10cSrcweir             // write the contents of the logger to the file
1671cdf0e10cSrcweir             SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEDOCFAILED, GlobalEventConfig::GetEventName(STR_EVENT_SAVEDOCFAILED), m_pData->m_pObjectShell ) );
1672cdf0e10cSrcweir 
1673cdf0e10cSrcweir             throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), nErrCode );
1674cdf0e10cSrcweir         }
1675cdf0e10cSrcweir     }
1676cdf0e10cSrcweir 
1677cdf0e10cSrcweir }
1678cdf0e10cSrcweir 
1679cdf0e10cSrcweir //________________________________________________________________________________________________________
1680cdf0e10cSrcweir //  XStorable
1681cdf0e10cSrcweir //________________________________________________________________________________________________________
1682cdf0e10cSrcweir 
1683cdf0e10cSrcweir void SAL_CALL SfxBaseModel::store() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
1684cdf0e10cSrcweir {
1685cdf0e10cSrcweir     storeSelf( uno::Sequence< beans::PropertyValue >() );
1686cdf0e10cSrcweir }
1687cdf0e10cSrcweir 
1688cdf0e10cSrcweir //________________________________________________________________________________________________________
1689cdf0e10cSrcweir //  XStorable
1690cdf0e10cSrcweir //________________________________________________________________________________________________________
1691cdf0e10cSrcweir 
1692cdf0e10cSrcweir void SAL_CALL SfxBaseModel::storeAsURL( const   ::rtl::OUString&                   rURL    ,
1693cdf0e10cSrcweir                                         const   uno::Sequence< beans::PropertyValue >&  rArgs   )
1694cdf0e10cSrcweir         throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
1695cdf0e10cSrcweir {
1696cdf0e10cSrcweir     RTL_LOGFILE_PRODUCT_CONTEXT( aPerfLog, "PERFORMANCE - SfxBaseModel::storeAsURL" );
1697cdf0e10cSrcweir 
1698cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1699cdf0e10cSrcweir 
1700cdf0e10cSrcweir     if ( m_pData->m_pObjectShell.Is() )
1701cdf0e10cSrcweir     {
1702cdf0e10cSrcweir         m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "storeAsURL" ) ) );
1703cdf0e10cSrcweir         SfxSaveGuard aSaveGuard(this, m_pData, sal_False);
1704cdf0e10cSrcweir 
1705cdf0e10cSrcweir         impl_store( rURL, rArgs, sal_False );
1706cdf0e10cSrcweir 
1707cdf0e10cSrcweir         uno::Sequence< beans::PropertyValue > aSequence ;
1708cdf0e10cSrcweir         TransformItems( SID_OPENDOC, *m_pData->m_pObjectShell->GetMedium()->GetItemSet(), aSequence );
1709cdf0e10cSrcweir         attachResource( rURL, aSequence );
1710cdf0e10cSrcweir 
1711cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
1712cdf0e10cSrcweir         SFX_ITEMSET_ARG( m_pData->m_pObjectShell->GetMedium()->GetItemSet(), pPasswdItem, SfxStringItem, SID_PASSWORD, sal_False);
1713cdf0e10cSrcweir         OSL_ENSURE( !pPasswdItem, "There should be no Password property in the document MediaDescriptor!" );
1714cdf0e10cSrcweir #endif
1715cdf0e10cSrcweir     }
1716cdf0e10cSrcweir }
1717cdf0e10cSrcweir 
1718cdf0e10cSrcweir //________________________________________________________________________________________________________
1719cdf0e10cSrcweir //  XUndoManagerSupplier
1720cdf0e10cSrcweir //________________________________________________________________________________________________________
1721cdf0e10cSrcweir Reference< XUndoManager > SAL_CALL SfxBaseModel::getUndoManager(  ) throw (RuntimeException)
1722cdf0e10cSrcweir {
1723cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1724cdf0e10cSrcweir     if ( !m_pData->m_pDocumentUndoManager.is() )
1725cdf0e10cSrcweir         m_pData->m_pDocumentUndoManager.set( new ::sfx2::DocumentUndoManager( *this ) );
1726cdf0e10cSrcweir     return m_pData->m_pDocumentUndoManager.get();
1727cdf0e10cSrcweir }
1728cdf0e10cSrcweir 
1729cdf0e10cSrcweir //________________________________________________________________________________________________________
1730cdf0e10cSrcweir //  XStorable
1731cdf0e10cSrcweir //________________________________________________________________________________________________________
1732cdf0e10cSrcweir 
1733cdf0e10cSrcweir void SAL_CALL SfxBaseModel::storeToURL( const   ::rtl::OUString&                   rURL    ,
1734cdf0e10cSrcweir                                         const   uno::Sequence< beans::PropertyValue >&  rArgs   )
1735cdf0e10cSrcweir         throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
1736cdf0e10cSrcweir {
1737cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1738cdf0e10cSrcweir 
1739cdf0e10cSrcweir     if ( m_pData->m_pObjectShell.Is() )
1740cdf0e10cSrcweir     {
1741cdf0e10cSrcweir         m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "storeToURL" ) ) );
1742cdf0e10cSrcweir         SfxSaveGuard aSaveGuard(this, m_pData, sal_False);
1743cdf0e10cSrcweir         impl_store( rURL, rArgs, sal_True );
1744cdf0e10cSrcweir     }
1745cdf0e10cSrcweir }
1746cdf0e10cSrcweir 
1747cdf0e10cSrcweir ::sal_Bool SAL_CALL SfxBaseModel::wasModifiedSinceLastSave() throw ( RuntimeException )
1748cdf0e10cSrcweir {
1749cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1750cdf0e10cSrcweir     return m_pData->m_bModifiedSinceLastSave;
1751cdf0e10cSrcweir }
1752cdf0e10cSrcweir 
1753cdf0e10cSrcweir void SAL_CALL SfxBaseModel::storeToRecoveryFile( const ::rtl::OUString& i_TargetLocation, const Sequence< PropertyValue >& i_MediaDescriptor ) throw ( RuntimeException, IOException, WrappedTargetException )
1754cdf0e10cSrcweir {
1755cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
1756cdf0e10cSrcweir 
1757cdf0e10cSrcweir     // delegate
1758cdf0e10cSrcweir     SfxSaveGuard aSaveGuard( this, m_pData, sal_False );
1759cdf0e10cSrcweir     impl_store( i_TargetLocation, i_MediaDescriptor, sal_True );
1760cdf0e10cSrcweir 
1761cdf0e10cSrcweir     // no need for subsequent calls to storeToRecoveryFile, unless we're modified, again
1762cdf0e10cSrcweir     m_pData->m_bModifiedSinceLastSave = sal_False;
1763cdf0e10cSrcweir }
1764cdf0e10cSrcweir 
1765cdf0e10cSrcweir void SAL_CALL SfxBaseModel::recoverFromFile( const ::rtl::OUString& i_SourceLocation, const ::rtl::OUString& i_SalvagedFile, const Sequence< PropertyValue >& i_MediaDescriptor ) throw ( RuntimeException, IOException, WrappedTargetException )
1766cdf0e10cSrcweir {
1767cdf0e10cSrcweir     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
1768cdf0e10cSrcweir 
1769cdf0e10cSrcweir     // delegate to our "load" method
1770cdf0e10cSrcweir     ::comphelper::NamedValueCollection aMediaDescriptor( i_MediaDescriptor );
1771cdf0e10cSrcweir 
1772cdf0e10cSrcweir     // our load implementation expects the SalvagedFile to be in the media descriptor
1773cdf0e10cSrcweir     OSL_ENSURE( !aMediaDescriptor.has( "SalvagedFile" ) || ( aMediaDescriptor.getOrDefault( "SalvagedFile", ::rtl::OUString() ) == i_SalvagedFile ),
1774cdf0e10cSrcweir         "SfxBaseModel::recoverFromFile: inconsistent information!" );
1775cdf0e10cSrcweir     aMediaDescriptor.put( "SalvagedFile", i_SalvagedFile );
1776cdf0e10cSrcweir 
1777cdf0e10cSrcweir     // similar for the to-be-loaded file
1778cdf0e10cSrcweir     OSL_ENSURE( !aMediaDescriptor.has( "URL" ) || ( aMediaDescriptor.getOrDefault( "URL", ::rtl::OUString() ) == i_SourceLocation ),
1779cdf0e10cSrcweir         "SfxBaseModel::recoverFromFile: inconsistent information!" );
1780cdf0e10cSrcweir     aMediaDescriptor.put( "URL", i_SourceLocation );
1781cdf0e10cSrcweir 
1782cdf0e10cSrcweir     load( aMediaDescriptor.getPropertyValues() );
1783cdf0e10cSrcweir 
1784cdf0e10cSrcweir     // Note: The XDocumentRecovery interface specification requires us to do an attachResource after loading.
1785cdf0e10cSrcweir     // However, we will not do this here, as we know that our load implementation (respectively some method
1786cdf0e10cSrcweir     // called from there) already did so.
1787cdf0e10cSrcweir     // In particular, the load process might already have modified some elements of the media
1788cdf0e10cSrcweir     // descriptor, for instance the MacroExecMode (in case the user was involved to decide about it), and we do
1789cdf0e10cSrcweir     // not want to overwrite it with the "old" elements passed to this method here.
1790cdf0e10cSrcweir }
1791cdf0e10cSrcweir 
1792cdf0e10cSrcweir //________________________________________________________________________________________________________
1793cdf0e10cSrcweir // XLoadable
1794cdf0e10cSrcweir //________________________________________________________________________________________________________
1795cdf0e10cSrcweir 
1796cdf0e10cSrcweir void SAL_CALL SfxBaseModel::initNew()
1797cdf0e10cSrcweir         throw (::com::sun::star::frame::DoubleInitializationException,
1798cdf0e10cSrcweir                ::com::sun::star::io::IOException,
1799cdf0e10cSrcweir                ::com::sun::star::uno::RuntimeException,
1800cdf0e10cSrcweir                ::com::sun::star::uno::Exception)
1801cdf0e10cSrcweir {
1802cdf0e10cSrcweir     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
1803cdf0e10cSrcweir     if ( IsInitialized() )
1804cdf0e10cSrcweir         throw ::com::sun::star::frame::DoubleInitializationException( ::rtl::OUString(), *this );
1805cdf0e10cSrcweir 
1806cdf0e10cSrcweir     // the object shell should exist always
1807cdf0e10cSrcweir     DBG_ASSERT( m_pData->m_pObjectShell.Is(), "Model is useless without an ObjectShell" );
1808cdf0e10cSrcweir     if ( m_pData->m_pObjectShell.Is() )
1809cdf0e10cSrcweir     {
1810cdf0e10cSrcweir         if( m_pData->m_pObjectShell->GetMedium() )
1811cdf0e10cSrcweir             throw DOUBLEINITIALIZATIONEXCEPTION();
1812cdf0e10cSrcweir 
1813cdf0e10cSrcweir         sal_Bool bRes = m_pData->m_pObjectShell->DoInitNew( NULL );
1814cdf0e10cSrcweir         sal_uInt32 nErrCode = m_pData->m_pObjectShell->GetError() ?
1815cdf0e10cSrcweir                                     m_pData->m_pObjectShell->GetError() : ERRCODE_IO_CANTCREATE;
1816cdf0e10cSrcweir         m_pData->m_pObjectShell->ResetError();
1817cdf0e10cSrcweir 
1818cdf0e10cSrcweir         if ( !bRes )
1819cdf0e10cSrcweir             throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), nErrCode );
1820cdf0e10cSrcweir     }
1821cdf0e10cSrcweir }
1822cdf0e10cSrcweir 
1823cdf0e10cSrcweir //________________________________________________________________________________________________________
1824cdf0e10cSrcweir // XLoadable
1825cdf0e10cSrcweir //________________________________________________________________________________________________________
1826cdf0e10cSrcweir 
1827cdf0e10cSrcweir void SAL_CALL SfxBaseModel::load(   const uno::Sequence< beans::PropertyValue >& seqArguments )
1828cdf0e10cSrcweir         throw (::com::sun::star::frame::DoubleInitializationException,
1829cdf0e10cSrcweir                ::com::sun::star::io::IOException,
1830cdf0e10cSrcweir                ::com::sun::star::uno::RuntimeException,
1831cdf0e10cSrcweir                ::com::sun::star::uno::Exception)
1832cdf0e10cSrcweir {
1833cdf0e10cSrcweir     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
1834cdf0e10cSrcweir     if ( IsInitialized() )
1835cdf0e10cSrcweir         throw ::com::sun::star::frame::DoubleInitializationException( ::rtl::OUString(), *this );
1836cdf0e10cSrcweir 
1837cdf0e10cSrcweir     // the object shell should exist always
1838cdf0e10cSrcweir     DBG_ASSERT( m_pData->m_pObjectShell.Is(), "Model is useless without an ObjectShell" );
1839cdf0e10cSrcweir 
1840cdf0e10cSrcweir     if ( m_pData->m_pObjectShell.Is() )
1841cdf0e10cSrcweir     {
1842cdf0e10cSrcweir         if( m_pData->m_pObjectShell->GetMedium() )
1843cdf0e10cSrcweir             // if a Medium is present, the document is already initialized
1844cdf0e10cSrcweir             throw DOUBLEINITIALIZATIONEXCEPTION();
1845cdf0e10cSrcweir 
1846cdf0e10cSrcweir         SfxMedium* pMedium = new SfxMedium( seqArguments );
1847cdf0e10cSrcweir         String aFilterName;
1848cdf0e10cSrcweir         SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFilterNameItem, SfxStringItem, SID_FILTER_NAME, sal_False );
1849cdf0e10cSrcweir         if( pFilterNameItem )
1850cdf0e10cSrcweir             aFilterName = pFilterNameItem->GetValue();
1851cdf0e10cSrcweir         if( !m_pData->m_pObjectShell->GetFactory().GetFilterContainer()->GetFilter4FilterName( aFilterName ) )
1852cdf0e10cSrcweir         {
1853cdf0e10cSrcweir             // filtername is not valid
1854cdf0e10cSrcweir             delete pMedium;
1855cdf0e10cSrcweir             throw frame::IllegalArgumentIOException();
1856cdf0e10cSrcweir         }
1857cdf0e10cSrcweir 
1858cdf0e10cSrcweir         // !TODO: currently not working
1859cdf0e10cSrcweir         //SFX_ITEMSET_ARG( pParams, pFrameItem, SfxFrameItem, SID_DOCFRAME, sal_False );
1860cdf0e10cSrcweir         //if( pFrameItem && pFrameItem->GetFrame() )
1861cdf0e10cSrcweir         //{
1862cdf0e10cSrcweir         //  SfxFrame* pFrame = pFrameItem->GetFrame();
1863cdf0e10cSrcweir         //  pMedium->SetLoadTargetFrame( pFrame );
1864cdf0e10cSrcweir         //}
1865cdf0e10cSrcweir 
1866cdf0e10cSrcweir         SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False );
1867cdf0e10cSrcweir         sal_Bool bSalvage = pSalvageItem ? sal_True : sal_False;
1868cdf0e10cSrcweir 
1869cdf0e10cSrcweir         // SFX_ITEMSET_ARG( pMedium->GetItemSet(), pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False);
1870cdf0e10cSrcweir         // sal_Bool bTemplate = pTemplateItem && pTemplateItem->GetValue();
1871cdf0e10cSrcweir         //
1872cdf0e10cSrcweir         // does already happen in DoLoad call
1873cdf0e10cSrcweir         //m_pData->m_pObjectShell->SetActivateEvent_Impl( bTemplate ? SFX_EVENT_CREATEDOC : SFX_EVENT_OPENDOC );
1874cdf0e10cSrcweir 
1875cdf0e10cSrcweir         // load document
1876cdf0e10cSrcweir         sal_uInt32 nError = ERRCODE_NONE;
1877cdf0e10cSrcweir         if ( !m_pData->m_pObjectShell->DoLoad(pMedium) )
1878cdf0e10cSrcweir             nError=ERRCODE_IO_GENERAL;
1879cdf0e10cSrcweir 
1880cdf0e10cSrcweir         // QUESTION: if the following happens outside of DoLoad, something important is missing there!
1881cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > xHandler = pMedium->GetInteractionHandler();
1882cdf0e10cSrcweir         if( m_pData->m_pObjectShell->GetErrorCode() )
1883cdf0e10cSrcweir         {
1884cdf0e10cSrcweir             nError = m_pData->m_pObjectShell->GetErrorCode();
1885cdf0e10cSrcweir             if ( nError == ERRCODE_IO_BROKENPACKAGE && xHandler.is() )
1886cdf0e10cSrcweir             {
1887cdf0e10cSrcweir                 ::rtl::OUString aDocName = pMedium->GetURLObject().getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
1888cdf0e10cSrcweir                 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pRepairItem, SfxBoolItem, SID_REPAIRPACKAGE, sal_False );
1889cdf0e10cSrcweir                 if ( !pRepairItem || !pRepairItem->GetValue() )
1890cdf0e10cSrcweir                 {
1891cdf0e10cSrcweir                     RequestPackageReparation aRequest( aDocName );
1892cdf0e10cSrcweir                     xHandler->handle( aRequest.GetRequest() );
1893cdf0e10cSrcweir                     if( aRequest.isApproved() )
1894cdf0e10cSrcweir                     {
1895cdf0e10cSrcweir                         // broken package: try second loading and allow repair
1896cdf0e10cSrcweir                         pMedium->GetItemSet()->Put( SfxBoolItem( SID_REPAIRPACKAGE, sal_True ) );
1897cdf0e10cSrcweir                         pMedium->GetItemSet()->Put( SfxBoolItem( SID_TEMPLATE, sal_True ) );
1898cdf0e10cSrcweir                         pMedium->GetItemSet()->Put( SfxStringItem( SID_DOCINFO_TITLE, aDocName ) );
1899cdf0e10cSrcweir 
1900cdf0e10cSrcweir                         // the error must be reset and the storage must be reopened in new mode
1901cdf0e10cSrcweir                         pMedium->ResetError();
1902cdf0e10cSrcweir                         pMedium->CloseStorage();
1903cdf0e10cSrcweir                         m_pData->m_pObjectShell->PrepareSecondTryLoad_Impl();
1904cdf0e10cSrcweir                         if ( !m_pData->m_pObjectShell->DoLoad(pMedium) )
1905cdf0e10cSrcweir                             nError=ERRCODE_IO_GENERAL;
1906cdf0e10cSrcweir                         nError = m_pData->m_pObjectShell->GetErrorCode();
1907cdf0e10cSrcweir                     }
1908cdf0e10cSrcweir                 }
1909cdf0e10cSrcweir 
1910cdf0e10cSrcweir                 if ( nError == ERRCODE_IO_BROKENPACKAGE )
1911cdf0e10cSrcweir                 {
1912cdf0e10cSrcweir                     // repair either not allowed or not successful
1913cdf0e10cSrcweir                     NotifyBrokenPackage aRequest( aDocName );
1914cdf0e10cSrcweir                     xHandler->handle( aRequest.GetRequest() );
1915cdf0e10cSrcweir                 }
1916cdf0e10cSrcweir             }
1917cdf0e10cSrcweir         }
1918cdf0e10cSrcweir 
1919cdf0e10cSrcweir         if( m_pData->m_pObjectShell->IsAbortingImport() )
1920cdf0e10cSrcweir             nError = ERRCODE_ABORT;
1921cdf0e10cSrcweir 
1922cdf0e10cSrcweir         if( bSalvage )
1923cdf0e10cSrcweir         {
1924cdf0e10cSrcweir             // file recovery: restore original filter
1925cdf0e10cSrcweir             SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFilterItem, SfxStringItem, SID_FILTER_NAME, sal_False );
1926cdf0e10cSrcweir             SfxFilterMatcher& rMatcher = SFX_APP()->GetFilterMatcher();
1927cdf0e10cSrcweir             const SfxFilter* pSetFilter = rMatcher.GetFilter4FilterName( pFilterItem->GetValue() );
1928cdf0e10cSrcweir             pMedium->SetFilter( pSetFilter );
1929cdf0e10cSrcweir             m_pData->m_pObjectShell->SetModified(sal_True);
1930cdf0e10cSrcweir         }
1931cdf0e10cSrcweir 
1932cdf0e10cSrcweir         // TODO/LATER: may be the mode should be retrieved from outside and the preused filter should not be set
1933cdf0e10cSrcweir         if ( m_pData->m_pObjectShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
1934cdf0e10cSrcweir         {
1935cdf0e10cSrcweir             SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFilterItem, SfxStringItem, SID_FILTER_NAME, sal_False );
1936cdf0e10cSrcweir             if ( pFilterItem )
1937cdf0e10cSrcweir                 m_pData->m_aPreusedFilterName = pFilterItem->GetValue();
1938cdf0e10cSrcweir         }
1939cdf0e10cSrcweir 
1940cdf0e10cSrcweir         if ( !nError )
1941cdf0e10cSrcweir             nError = pMedium->GetError();
1942cdf0e10cSrcweir 
1943cdf0e10cSrcweir         m_pData->m_pObjectShell->ResetError();
1944cdf0e10cSrcweir 
1945cdf0e10cSrcweir         if ( nError )
1946cdf0e10cSrcweir         {
1947cdf0e10cSrcweir             sal_Bool bSilent = sal_False;
1948cdf0e10cSrcweir             SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSilentItem, SfxBoolItem, SID_SILENT, sal_False);
1949cdf0e10cSrcweir             if( pSilentItem )
1950cdf0e10cSrcweir                 bSilent = pSilentItem->GetValue();
1951cdf0e10cSrcweir 
1952cdf0e10cSrcweir             sal_Bool bWarning = ((nError & ERRCODE_WARNING_MASK) == ERRCODE_WARNING_MASK);
1953cdf0e10cSrcweir             if ( nError != ERRCODE_IO_BROKENPACKAGE && !bSilent )
1954cdf0e10cSrcweir             {
1955cdf0e10cSrcweir                 // broken package was handled already
1956cdf0e10cSrcweir                 if ( SfxObjectShell::UseInteractionToHandleError( xHandler, nError ) && !bWarning )
1957cdf0e10cSrcweir                 {
1958cdf0e10cSrcweir                     // abort loading (except for warnings)
1959cdf0e10cSrcweir                     nError = ERRCODE_IO_ABORT;
1960cdf0e10cSrcweir                 }
1961cdf0e10cSrcweir             }
1962cdf0e10cSrcweir 
1963cdf0e10cSrcweir             if ( m_pData->m_pObjectShell->GetMedium() != pMedium )
1964cdf0e10cSrcweir             {
1965cdf0e10cSrcweir                 // for whatever reason document now has another medium
1966cdf0e10cSrcweir                 DBG_ERROR("Document has rejected the medium?!");
1967cdf0e10cSrcweir                 delete pMedium;
1968cdf0e10cSrcweir             }
1969cdf0e10cSrcweir 
1970cdf0e10cSrcweir             if ( !bWarning )    // #i30711# don't abort loading if it's only a warning
1971cdf0e10cSrcweir             {
1972cdf0e10cSrcweir                 throw task::ErrorCodeIOException( ::rtl::OUString(),
1973cdf0e10cSrcweir                                                     uno::Reference< uno::XInterface >(),
1974cdf0e10cSrcweir                                                     nError ? nError : ERRCODE_IO_CANTREAD );
1975cdf0e10cSrcweir             }
1976cdf0e10cSrcweir         }
1977cdf0e10cSrcweir 
1978cdf0e10cSrcweir         sal_Bool bHidden = sal_False;
1979cdf0e10cSrcweir         SFX_ITEMSET_ARG( pMedium->GetItemSet(), pHidItem, SfxBoolItem, SID_HIDDEN, sal_False);
1980cdf0e10cSrcweir         if ( pHidItem )
1981cdf0e10cSrcweir             bHidden = pHidItem->GetValue();
1982cdf0e10cSrcweir 
1983cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
1984cdf0e10cSrcweir         SFX_ITEMSET_ARG( pMedium->GetItemSet(), pPasswdItem, SfxStringItem, SID_PASSWORD, sal_False);
1985cdf0e10cSrcweir         OSL_ENSURE( !pPasswdItem, "There should be no Password property in the document MediaDescriptor!" );
1986cdf0e10cSrcweir #endif
1987cdf0e10cSrcweir         // !TODO: will be done by Framework!
1988cdf0e10cSrcweir         pMedium->SetUpdatePickList( !bHidden );
1989cdf0e10cSrcweir     }
1990cdf0e10cSrcweir }
1991cdf0e10cSrcweir 
1992cdf0e10cSrcweir //________________________________________________________________________________________________________
1993cdf0e10cSrcweir // XTransferable
1994cdf0e10cSrcweir //________________________________________________________________________________________________________
1995cdf0e10cSrcweir 
1996cdf0e10cSrcweir uno::Any SAL_CALL SfxBaseModel::getTransferData( const DATAFLAVOR& aFlavor )
1997cdf0e10cSrcweir         throw (::com::sun::star::datatransfer::UnsupportedFlavorException,
1998cdf0e10cSrcweir                ::com::sun::star::io::IOException,
1999cdf0e10cSrcweir                ::com::sun::star::uno::RuntimeException)
2000cdf0e10cSrcweir {
2001cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
2002cdf0e10cSrcweir 
2003cdf0e10cSrcweir     uno::Any aAny;
2004cdf0e10cSrcweir 
2005cdf0e10cSrcweir     if ( m_pData->m_pObjectShell.Is() )
2006cdf0e10cSrcweir     {
2007cdf0e10cSrcweir         if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"" ) )
2008cdf0e10cSrcweir         {
2009cdf0e10cSrcweir             if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2010cdf0e10cSrcweir             {
2011cdf0e10cSrcweir                 TransferableObjectDescriptor aDesc;
2012cdf0e10cSrcweir 
2013cdf0e10cSrcweir                 aDesc.maClassName = m_pData->m_pObjectShell->GetClassName();
2014cdf0e10cSrcweir                 aDesc.maTypeName = aFlavor.HumanPresentableName;
2015cdf0e10cSrcweir 
2016cdf0e10cSrcweir                 // TODO/LATER: ViewAspect needs to be sal_Int64
2017cdf0e10cSrcweir                 aDesc.mnViewAspect = sal::static_int_cast< sal_uInt16 >( embed::Aspects::MSOLE_CONTENT );
2018cdf0e10cSrcweir 
2019cdf0e10cSrcweir                 //TODO/LATER: status needs to become sal_Int64
2020cdf0e10cSrcweir                 aDesc.mnOle2Misc = m_pData->m_pObjectShell->GetMiscStatus();
2021cdf0e10cSrcweir                 Size aSize = m_pData->m_pObjectShell->GetVisArea().GetSize();
2022cdf0e10cSrcweir 
2023cdf0e10cSrcweir                 MapUnit aMapUnit = m_pData->m_pObjectShell->GetMapUnit();
2024cdf0e10cSrcweir                 aDesc.maSize = OutputDevice::LogicToLogic( aSize, aMapUnit, MAP_100TH_MM );
2025cdf0e10cSrcweir                 aDesc.maDragStartPos = Point();
2026cdf0e10cSrcweir                 aDesc.maDisplayName = String();
2027cdf0e10cSrcweir                 aDesc.mbCanLink = sal_False;
2028cdf0e10cSrcweir 
2029cdf0e10cSrcweir                 SvMemoryStream aMemStm( 1024, 1024 );
2030cdf0e10cSrcweir                 aMemStm << aDesc;
2031cdf0e10cSrcweir                 aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Tell() );
2032cdf0e10cSrcweir             }
2033cdf0e10cSrcweir             else
2034cdf0e10cSrcweir                 throw datatransfer::UnsupportedFlavorException();
2035cdf0e10cSrcweir         }
2036cdf0e10cSrcweir         else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-embed-source;windows_formatname=\"Star EMBS\"" ) )
2037cdf0e10cSrcweir         {
2038cdf0e10cSrcweir             if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2039cdf0e10cSrcweir             {
2040cdf0e10cSrcweir                 try
2041cdf0e10cSrcweir                 {
2042cdf0e10cSrcweir                     utl::TempFile aTmp;
2043cdf0e10cSrcweir                     aTmp.EnableKillingFile( sal_True );
2044cdf0e10cSrcweir                     storeToURL( aTmp.GetURL(), uno::Sequence < beans::PropertyValue >() );
2045cdf0e10cSrcweir                     SvStream* pStream = aTmp.GetStream( STREAM_READ );
2046cdf0e10cSrcweir                     const sal_uInt32 nLen = pStream->Seek( STREAM_SEEK_TO_END );
2047cdf0e10cSrcweir                     ::com::sun::star::uno::Sequence< sal_Int8 > aSeq( nLen );
2048cdf0e10cSrcweir                     pStream->Seek( STREAM_SEEK_TO_BEGIN );
2049cdf0e10cSrcweir                     pStream->Read( aSeq.getArray(),  nLen );
2050cdf0e10cSrcweir                     delete pStream;
2051cdf0e10cSrcweir                     if( aSeq.getLength() )
2052cdf0e10cSrcweir                         aAny <<= aSeq;
2053cdf0e10cSrcweir                 }
2054cdf0e10cSrcweir                 catch ( uno::Exception& )
2055cdf0e10cSrcweir                 {
2056cdf0e10cSrcweir                 }
2057cdf0e10cSrcweir             }
2058cdf0e10cSrcweir             else
2059cdf0e10cSrcweir                 throw datatransfer::UnsupportedFlavorException();
2060cdf0e10cSrcweir         }
2061cdf0e10cSrcweir         else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) )
2062cdf0e10cSrcweir         {
2063cdf0e10cSrcweir             if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2064cdf0e10cSrcweir             {
2065cdf0e10cSrcweir 
2066cdf0e10cSrcweir                 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2067cdf0e10cSrcweir                     m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2068cdf0e10cSrcweir 
2069cdf0e10cSrcweir                 if ( pMetaFile )
2070cdf0e10cSrcweir                 {
2071cdf0e10cSrcweir                     SvMemoryStream aMemStm( 65535, 65535 );
2072cdf0e10cSrcweir                     aMemStm.SetVersion( SOFFICE_FILEFORMAT_CURRENT );
2073cdf0e10cSrcweir 
2074cdf0e10cSrcweir                     pMetaFile->Write( aMemStm );
2075cdf0e10cSrcweir                     aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ),
2076cdf0e10cSrcweir                                                     aMemStm.Seek( STREAM_SEEK_TO_END ) );
2077cdf0e10cSrcweir                 }
2078cdf0e10cSrcweir             }
2079cdf0e10cSrcweir             else
2080cdf0e10cSrcweir                 throw datatransfer::UnsupportedFlavorException();
2081cdf0e10cSrcweir         }
2082cdf0e10cSrcweir         else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) )
2083cdf0e10cSrcweir         {
2084cdf0e10cSrcweir             if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2085cdf0e10cSrcweir             {
2086cdf0e10cSrcweir                 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2087cdf0e10cSrcweir                     m_pData->m_pObjectShell->CreatePreviewMetaFile_Impl( sal_True, sal_True );
2088cdf0e10cSrcweir 
2089cdf0e10cSrcweir                 if ( pMetaFile )
2090cdf0e10cSrcweir                 {
2091cdf0e10cSrcweir                     SvMemoryStream aMemStm( 65535, 65535 );
2092cdf0e10cSrcweir                     aMemStm.SetVersion( SOFFICE_FILEFORMAT_CURRENT );
2093cdf0e10cSrcweir 
2094cdf0e10cSrcweir                     pMetaFile->Write( aMemStm );
2095cdf0e10cSrcweir                     aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ),
2096cdf0e10cSrcweir                                                     aMemStm.Seek( STREAM_SEEK_TO_END ) );
2097cdf0e10cSrcweir                 }
2098cdf0e10cSrcweir             }
2099cdf0e10cSrcweir             else
2100cdf0e10cSrcweir                 throw datatransfer::UnsupportedFlavorException();
2101cdf0e10cSrcweir         }
2102cdf0e10cSrcweir         else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) )
2103cdf0e10cSrcweir         {
2104cdf0e10cSrcweir             if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2105cdf0e10cSrcweir             {
2106cdf0e10cSrcweir                 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2107cdf0e10cSrcweir                     m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2108cdf0e10cSrcweir 
2109cdf0e10cSrcweir                 if ( pMetaFile )
2110cdf0e10cSrcweir                 {
2111cdf0e10cSrcweir                     ::boost::shared_ptr<SvMemoryStream> pStream(
2112cdf0e10cSrcweir                         GraphicHelper::getFormatStrFromGDI_Impl(
2113cdf0e10cSrcweir                             pMetaFile.get(), CVT_EMF ) );
2114cdf0e10cSrcweir                     if ( pStream )
2115cdf0e10cSrcweir                     {
2116cdf0e10cSrcweir                         pStream->SetVersion( SOFFICE_FILEFORMAT_CURRENT );
2117cdf0e10cSrcweir                         aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( pStream->GetData() ),
2118cdf0e10cSrcweir                                                         pStream->Seek( STREAM_SEEK_TO_END ) );
2119cdf0e10cSrcweir                     }
2120cdf0e10cSrcweir                 }
2121cdf0e10cSrcweir             }
2122cdf0e10cSrcweir             else if ( GraphicHelper::supportsMetaFileHandle_Impl()
2123cdf0e10cSrcweir               && aFlavor.DataType == getCppuType( (const sal_uInt64*) 0 ) )
2124cdf0e10cSrcweir             {
2125cdf0e10cSrcweir                 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2126cdf0e10cSrcweir                     m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2127cdf0e10cSrcweir 
2128cdf0e10cSrcweir                 if ( pMetaFile )
2129cdf0e10cSrcweir                 {
2130cdf0e10cSrcweir                     aAny <<= reinterpret_cast< const sal_uInt64 >(
2131cdf0e10cSrcweir                         GraphicHelper::getEnhMetaFileFromGDI_Impl( pMetaFile.get() ) );
2132cdf0e10cSrcweir                 }
2133cdf0e10cSrcweir             }
2134cdf0e10cSrcweir             else
2135cdf0e10cSrcweir                 throw datatransfer::UnsupportedFlavorException();
2136cdf0e10cSrcweir         }
2137cdf0e10cSrcweir         else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) )
2138cdf0e10cSrcweir         {
2139cdf0e10cSrcweir             if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2140cdf0e10cSrcweir             {
2141cdf0e10cSrcweir                 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2142cdf0e10cSrcweir                     m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2143cdf0e10cSrcweir 
2144cdf0e10cSrcweir                 if ( pMetaFile )
2145cdf0e10cSrcweir                 {
2146cdf0e10cSrcweir                     ::boost::shared_ptr<SvMemoryStream> pStream(
2147cdf0e10cSrcweir                         GraphicHelper::getFormatStrFromGDI_Impl(
2148cdf0e10cSrcweir                             pMetaFile.get(), CVT_WMF ) );
2149cdf0e10cSrcweir 
2150cdf0e10cSrcweir                     if ( pStream )
2151cdf0e10cSrcweir                     {
2152cdf0e10cSrcweir                         pStream->SetVersion( SOFFICE_FILEFORMAT_CURRENT );
2153cdf0e10cSrcweir                         aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( pStream->GetData() ),
2154cdf0e10cSrcweir                                                         pStream->Seek( STREAM_SEEK_TO_END ) );
2155cdf0e10cSrcweir                     }
2156cdf0e10cSrcweir                 }
2157cdf0e10cSrcweir             }
2158cdf0e10cSrcweir             else if ( GraphicHelper::supportsMetaFileHandle_Impl()
2159cdf0e10cSrcweir               && aFlavor.DataType == getCppuType( (const sal_uInt64*) 0 ) )
2160cdf0e10cSrcweir             {
2161cdf0e10cSrcweir                 // means HGLOBAL handler to memory storage containing METAFILEPICT structure
2162cdf0e10cSrcweir 
2163cdf0e10cSrcweir                 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2164cdf0e10cSrcweir                     m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2165cdf0e10cSrcweir 
2166cdf0e10cSrcweir                 if ( pMetaFile )
2167cdf0e10cSrcweir                 {
2168cdf0e10cSrcweir                     Size aMetaSize = pMetaFile->GetPrefSize();
2169cdf0e10cSrcweir                     aAny <<= reinterpret_cast< const sal_uInt64 >(
2170cdf0e10cSrcweir                         GraphicHelper::getWinMetaFileFromGDI_Impl(
2171cdf0e10cSrcweir                             pMetaFile.get(), aMetaSize ) );
2172cdf0e10cSrcweir                 }
2173cdf0e10cSrcweir             }
2174cdf0e10cSrcweir             else
2175cdf0e10cSrcweir                 throw datatransfer::UnsupportedFlavorException();
2176cdf0e10cSrcweir         }
2177cdf0e10cSrcweir         else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ) )
2178cdf0e10cSrcweir         {
2179cdf0e10cSrcweir             if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2180cdf0e10cSrcweir             {
2181cdf0e10cSrcweir                 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2182cdf0e10cSrcweir                     m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2183cdf0e10cSrcweir 
2184cdf0e10cSrcweir                 if ( pMetaFile )
2185cdf0e10cSrcweir                 {
2186cdf0e10cSrcweir                     ::boost::shared_ptr<SvMemoryStream> pStream(
2187cdf0e10cSrcweir                         GraphicHelper::getFormatStrFromGDI_Impl(
2188cdf0e10cSrcweir                             pMetaFile.get(), CVT_BMP ) );
2189cdf0e10cSrcweir 
2190cdf0e10cSrcweir                     if ( pStream )
2191cdf0e10cSrcweir                     {
2192cdf0e10cSrcweir                         pStream->SetVersion( SOFFICE_FILEFORMAT_CURRENT );
2193cdf0e10cSrcweir                         aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( pStream->GetData() ),
2194cdf0e10cSrcweir                                                         pStream->Seek( STREAM_SEEK_TO_END ) );
2195cdf0e10cSrcweir                     }
2196cdf0e10cSrcweir                 }
2197cdf0e10cSrcweir             }
2198cdf0e10cSrcweir             else
2199cdf0e10cSrcweir                 throw datatransfer::UnsupportedFlavorException();
2200cdf0e10cSrcweir         }
2201cdf0e10cSrcweir         else if ( aFlavor.MimeType.equalsAscii( "image/png" ) )
2202cdf0e10cSrcweir         {
2203cdf0e10cSrcweir             if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2204cdf0e10cSrcweir             {
2205cdf0e10cSrcweir                 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2206cdf0e10cSrcweir                     m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2207cdf0e10cSrcweir 
2208cdf0e10cSrcweir                 if ( pMetaFile )
2209cdf0e10cSrcweir                 {
2210cdf0e10cSrcweir                     ::boost::shared_ptr<SvMemoryStream> pStream(
2211cdf0e10cSrcweir                         GraphicHelper::getFormatStrFromGDI_Impl(
2212cdf0e10cSrcweir                             pMetaFile.get(), CVT_PNG ) );
2213cdf0e10cSrcweir 
2214cdf0e10cSrcweir                     if ( pStream )
2215cdf0e10cSrcweir                     {
2216cdf0e10cSrcweir                         pStream->SetVersion( SOFFICE_FILEFORMAT_CURRENT );
2217cdf0e10cSrcweir                         aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( pStream->GetData() ),
2218cdf0e10cSrcweir                                                         pStream->Seek( STREAM_SEEK_TO_END ) );
2219cdf0e10cSrcweir                     }
2220cdf0e10cSrcweir                 }
2221cdf0e10cSrcweir             }
2222cdf0e10cSrcweir             else
2223cdf0e10cSrcweir                 throw datatransfer::UnsupportedFlavorException();
2224cdf0e10cSrcweir         }
2225cdf0e10cSrcweir         else
2226cdf0e10cSrcweir             throw datatransfer::UnsupportedFlavorException();
2227cdf0e10cSrcweir     }
2228cdf0e10cSrcweir 
2229cdf0e10cSrcweir     return aAny;
2230cdf0e10cSrcweir }
2231cdf0e10cSrcweir 
2232cdf0e10cSrcweir //________________________________________________________________________________________________________
2233cdf0e10cSrcweir // XTransferable
2234cdf0e10cSrcweir //________________________________________________________________________________________________________
2235cdf0e10cSrcweir 
2236cdf0e10cSrcweir 
2237cdf0e10cSrcweir uno::Sequence< DATAFLAVOR > SAL_CALL SfxBaseModel::getTransferDataFlavors()
2238cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException)
2239cdf0e10cSrcweir {
2240cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
2241cdf0e10cSrcweir 
2242cdf0e10cSrcweir     sal_Int32 nSuppFlavors = GraphicHelper::supportsMetaFileHandle_Impl() ? 10 : 8;
2243cdf0e10cSrcweir     uno::Sequence< DATAFLAVOR > aFlavorSeq( nSuppFlavors );
2244cdf0e10cSrcweir 
2245cdf0e10cSrcweir     aFlavorSeq[0].MimeType =
2246cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) );
2247cdf0e10cSrcweir     aFlavorSeq[0].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "GDIMetaFile" ) );
2248cdf0e10cSrcweir     aFlavorSeq[0].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2249cdf0e10cSrcweir 
2250cdf0e10cSrcweir     aFlavorSeq[1].MimeType =
2251cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) );
2252cdf0e10cSrcweir     aFlavorSeq[1].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "GDIMetaFile" ) );
2253cdf0e10cSrcweir     aFlavorSeq[1].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2254cdf0e10cSrcweir 
2255cdf0e10cSrcweir     aFlavorSeq[2].MimeType =
2256cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) );
2257cdf0e10cSrcweir     aFlavorSeq[2].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enhanced Windows MetaFile" ) );
2258cdf0e10cSrcweir     aFlavorSeq[2].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2259cdf0e10cSrcweir 
2260cdf0e10cSrcweir     aFlavorSeq[3].MimeType =
2261cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) );
2262cdf0e10cSrcweir     aFlavorSeq[3].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Windows MetaFile" ) );
2263cdf0e10cSrcweir     aFlavorSeq[3].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2264cdf0e10cSrcweir 
2265cdf0e10cSrcweir     aFlavorSeq[4].MimeType =
2266cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"" ) );
2267cdf0e10cSrcweir     aFlavorSeq[4].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Star Object Descriptor (XML)" ) );
2268cdf0e10cSrcweir     aFlavorSeq[4].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2269cdf0e10cSrcweir 
2270cdf0e10cSrcweir     aFlavorSeq[5].MimeType =
2271cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-embed-source-xml;windows_formatname=\"Star Embed Source (XML)\"" ) );
2272cdf0e10cSrcweir     aFlavorSeq[5].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Star Embed Source (XML)" ) );
2273cdf0e10cSrcweir     aFlavorSeq[5].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2274cdf0e10cSrcweir 
2275cdf0e10cSrcweir     aFlavorSeq[6].MimeType =
2276cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ) );
2277cdf0e10cSrcweir     aFlavorSeq[6].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Bitmap" ) );
2278cdf0e10cSrcweir     aFlavorSeq[6].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2279cdf0e10cSrcweir 
2280cdf0e10cSrcweir     aFlavorSeq[7].MimeType =
2281cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "image/png" ) );
2282cdf0e10cSrcweir     aFlavorSeq[7].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PNG" ) );
2283cdf0e10cSrcweir     aFlavorSeq[7].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2284cdf0e10cSrcweir 
2285cdf0e10cSrcweir     if ( nSuppFlavors == 10 )
2286cdf0e10cSrcweir     {
2287cdf0e10cSrcweir         aFlavorSeq[8].MimeType =
2288cdf0e10cSrcweir             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) );
2289cdf0e10cSrcweir         aFlavorSeq[8].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enhanced Windows MetaFile" ) );
2290cdf0e10cSrcweir         aFlavorSeq[8].DataType = getCppuType( (const sal_uInt64*) 0 );
2291cdf0e10cSrcweir 
2292cdf0e10cSrcweir         aFlavorSeq[9].MimeType =
2293cdf0e10cSrcweir             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) );
2294cdf0e10cSrcweir         aFlavorSeq[9].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Windows MetaFile" ) );
2295cdf0e10cSrcweir         aFlavorSeq[9].DataType = getCppuType( (const sal_uInt64*) 0 );
2296cdf0e10cSrcweir     }
2297cdf0e10cSrcweir 
2298cdf0e10cSrcweir     return aFlavorSeq;
2299cdf0e10cSrcweir }
2300cdf0e10cSrcweir 
2301cdf0e10cSrcweir //________________________________________________________________________________________________________
2302cdf0e10cSrcweir // XTransferable
2303cdf0e10cSrcweir //________________________________________________________________________________________________________
2304cdf0e10cSrcweir 
2305cdf0e10cSrcweir 
2306cdf0e10cSrcweir sal_Bool SAL_CALL SfxBaseModel::isDataFlavorSupported( const DATAFLAVOR& aFlavor )
2307cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException)
2308cdf0e10cSrcweir {
2309cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
2310cdf0e10cSrcweir 
2311cdf0e10cSrcweir     if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) )
2312cdf0e10cSrcweir     {
2313cdf0e10cSrcweir         if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2314cdf0e10cSrcweir             return sal_True;
2315cdf0e10cSrcweir     }
2316cdf0e10cSrcweir     else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) )
2317cdf0e10cSrcweir     {
2318cdf0e10cSrcweir         if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2319cdf0e10cSrcweir             return sal_True;
2320cdf0e10cSrcweir     }
2321cdf0e10cSrcweir     else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) )
2322cdf0e10cSrcweir     {
2323cdf0e10cSrcweir         if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2324cdf0e10cSrcweir             return sal_True;
2325cdf0e10cSrcweir         else if ( GraphicHelper::supportsMetaFileHandle_Impl()
2326cdf0e10cSrcweir           && aFlavor.DataType == getCppuType( (const sal_uInt64*) 0 ) )
2327cdf0e10cSrcweir             return sal_True;
2328cdf0e10cSrcweir     }
2329cdf0e10cSrcweir     else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) )
2330cdf0e10cSrcweir     {
2331cdf0e10cSrcweir         if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2332cdf0e10cSrcweir             return sal_True;
2333cdf0e10cSrcweir         else if ( GraphicHelper::supportsMetaFileHandle_Impl()
2334cdf0e10cSrcweir           && aFlavor.DataType == getCppuType( (const sal_uInt64*) 0 ) )
2335cdf0e10cSrcweir             return sal_True;
2336cdf0e10cSrcweir     }
2337cdf0e10cSrcweir     else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"" ) )
2338cdf0e10cSrcweir     {
2339cdf0e10cSrcweir         if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2340cdf0e10cSrcweir             return sal_True;
2341cdf0e10cSrcweir     }
2342cdf0e10cSrcweir     else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-embed-source;windows_formatname=\"Star EMBS\"" ) )
2343cdf0e10cSrcweir     {
2344cdf0e10cSrcweir         if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2345cdf0e10cSrcweir             return sal_True;
2346cdf0e10cSrcweir     }
2347cdf0e10cSrcweir     else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ) )
2348cdf0e10cSrcweir     {
2349cdf0e10cSrcweir         if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2350cdf0e10cSrcweir             return sal_True;
2351cdf0e10cSrcweir     }
2352cdf0e10cSrcweir     else if ( aFlavor.MimeType.equalsAscii( "image/png" ) )
2353cdf0e10cSrcweir     {
2354cdf0e10cSrcweir         if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2355cdf0e10cSrcweir             return sal_True;
2356cdf0e10cSrcweir     }
2357cdf0e10cSrcweir 
2358cdf0e10cSrcweir     return sal_False;
2359cdf0e10cSrcweir }
2360cdf0e10cSrcweir 
2361cdf0e10cSrcweir 
2362cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
2363cdf0e10cSrcweir //  XEventsSupplier
2364cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
2365cdf0e10cSrcweir 
2366cdf0e10cSrcweir uno::Reference< container::XNameReplace > SAL_CALL SfxBaseModel::getEvents() throw( uno::RuntimeException )
2367cdf0e10cSrcweir {
2368cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
2369cdf0e10cSrcweir 
2370cdf0e10cSrcweir     if ( ! m_pData->m_xEvents.is() )
2371cdf0e10cSrcweir     {
2372cdf0e10cSrcweir         m_pData->m_xEvents = new SfxEvents_Impl( m_pData->m_pObjectShell, this );
2373cdf0e10cSrcweir     }
2374cdf0e10cSrcweir 
2375cdf0e10cSrcweir     return m_pData->m_xEvents;
2376cdf0e10cSrcweir }
2377cdf0e10cSrcweir 
2378cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
2379cdf0e10cSrcweir //  XEmbeddedScripts
2380cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
2381cdf0e10cSrcweir 
2382cdf0e10cSrcweir uno::Reference< script::XStorageBasedLibraryContainer > SAL_CALL SfxBaseModel::getBasicLibraries() throw (RuntimeException)
2383cdf0e10cSrcweir {
2384cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
2385cdf0e10cSrcweir 
2386cdf0e10cSrcweir     uno::Reference< script::XStorageBasedLibraryContainer > xBasicLibraries;
2387cdf0e10cSrcweir     if ( m_pData->m_pObjectShell )
2388cdf0e10cSrcweir         xBasicLibraries.set( m_pData->m_pObjectShell->GetBasicContainer(), UNO_QUERY_THROW );
2389cdf0e10cSrcweir     return xBasicLibraries;
2390cdf0e10cSrcweir }
2391cdf0e10cSrcweir 
2392cdf0e10cSrcweir uno::Reference< script::XStorageBasedLibraryContainer > SAL_CALL SfxBaseModel::getDialogLibraries() throw (RuntimeException)
2393cdf0e10cSrcweir {
2394cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
2395cdf0e10cSrcweir 
2396cdf0e10cSrcweir     uno::Reference< script::XStorageBasedLibraryContainer > xDialogLibraries;
2397cdf0e10cSrcweir     if ( m_pData->m_pObjectShell )
2398cdf0e10cSrcweir         xDialogLibraries.set( m_pData->m_pObjectShell->GetDialogContainer(), UNO_QUERY_THROW );
2399cdf0e10cSrcweir     return xDialogLibraries;
2400cdf0e10cSrcweir }
2401cdf0e10cSrcweir 
2402cdf0e10cSrcweir ::sal_Bool SAL_CALL SfxBaseModel::getAllowMacroExecution() throw (RuntimeException)
2403cdf0e10cSrcweir {
2404cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
2405cdf0e10cSrcweir 
2406cdf0e10cSrcweir     if ( m_pData->m_pObjectShell )
2407cdf0e10cSrcweir         return m_pData->m_pObjectShell->AdjustMacroMode( String(), false );
2408cdf0e10cSrcweir     return sal_False;
2409cdf0e10cSrcweir }
2410cdf0e10cSrcweir 
2411cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
2412cdf0e10cSrcweir //  XScriptInvocationContext
2413cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
2414cdf0e10cSrcweir 
2415cdf0e10cSrcweir Reference< document::XEmbeddedScripts > SAL_CALL SfxBaseModel::getScriptContainer() throw (RuntimeException)
2416cdf0e10cSrcweir {
2417cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
2418cdf0e10cSrcweir 
2419cdf0e10cSrcweir     Reference< document::XEmbeddedScripts > xDocumentScripts;
2420cdf0e10cSrcweir 
2421cdf0e10cSrcweir     try
2422cdf0e10cSrcweir     {
2423cdf0e10cSrcweir         Reference< frame::XModel > xDocument( this );
2424cdf0e10cSrcweir         xDocumentScripts.set( xDocument, uno::UNO_QUERY );
2425cdf0e10cSrcweir         while ( !xDocumentScripts.is() && xDocument.is() )
2426cdf0e10cSrcweir         {
2427cdf0e10cSrcweir             Reference< container::XChild > xDocAsChild( xDocument, uno::UNO_QUERY );
2428cdf0e10cSrcweir             if ( !xDocAsChild.is() )
2429cdf0e10cSrcweir             {
2430cdf0e10cSrcweir                 xDocument = NULL;
2431cdf0e10cSrcweir                 break;
2432cdf0e10cSrcweir             }
2433cdf0e10cSrcweir 
2434cdf0e10cSrcweir             xDocument.set( xDocAsChild->getParent(), uno::UNO_QUERY );
2435cdf0e10cSrcweir             xDocumentScripts.set( xDocument, uno::UNO_QUERY );
2436cdf0e10cSrcweir         }
2437cdf0e10cSrcweir     }
2438cdf0e10cSrcweir     catch( const Exception& )
2439cdf0e10cSrcweir     {
2440cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
2441cdf0e10cSrcweir         xDocumentScripts = NULL;
2442cdf0e10cSrcweir     }
2443cdf0e10cSrcweir 
2444cdf0e10cSrcweir     return xDocumentScripts;
2445cdf0e10cSrcweir }
2446cdf0e10cSrcweir 
2447cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
2448cdf0e10cSrcweir //  XEventBroadcaster
2449cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
2450cdf0e10cSrcweir 
2451cdf0e10cSrcweir void SAL_CALL SfxBaseModel::addEventListener( const uno::Reference< XDOCEVENTLISTENER >& aListener ) throw( uno::RuntimeException )
2452cdf0e10cSrcweir {
2453cdf0e10cSrcweir     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
2454cdf0e10cSrcweir 
2455cdf0e10cSrcweir     m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0), aListener );
2456cdf0e10cSrcweir }
2457cdf0e10cSrcweir 
2458cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
2459cdf0e10cSrcweir //  XEventBroadcaster
2460cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
2461cdf0e10cSrcweir 
2462cdf0e10cSrcweir void SAL_CALL SfxBaseModel::removeEventListener( const uno::Reference< XDOCEVENTLISTENER >& aListener ) throw( uno::RuntimeException )
2463cdf0e10cSrcweir {
2464cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
2465cdf0e10cSrcweir 
2466cdf0e10cSrcweir     m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0), aListener );
2467cdf0e10cSrcweir }
2468cdf0e10cSrcweir 
2469cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
2470cdf0e10cSrcweir //  XDocumentEventBroadcaster
2471cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
2472cdf0e10cSrcweir // ---------------------------------
2473cdf0e10cSrcweir void SAL_CALL SfxBaseModel::addDocumentEventListener( const uno::Reference< document::XDocumentEventListener >& aListener )
2474cdf0e10cSrcweir     throw ( uno::RuntimeException )
2475cdf0e10cSrcweir {
2476cdf0e10cSrcweir     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
2477cdf0e10cSrcweir     m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< document::XDocumentEventListener >*)0), aListener );
2478cdf0e10cSrcweir }
2479cdf0e10cSrcweir 
2480cdf0e10cSrcweir // ---------------------------------
2481cdf0e10cSrcweir void SAL_CALL SfxBaseModel::removeDocumentEventListener( const uno::Reference< document::XDocumentEventListener >& aListener )
2482cdf0e10cSrcweir     throw ( uno::RuntimeException )
2483cdf0e10cSrcweir {
2484cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
2485cdf0e10cSrcweir     m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< document::XDocumentEventListener >*)0), aListener );
2486cdf0e10cSrcweir }
2487cdf0e10cSrcweir 
2488cdf0e10cSrcweir // ---------------------------------
2489cdf0e10cSrcweir void SAL_CALL SfxBaseModel::notifyDocumentEvent( const ::rtl::OUString&, const uno::Reference< frame::XController2 >&, const uno::Any& )
2490cdf0e10cSrcweir     throw ( lang::IllegalArgumentException, lang::NoSupportException, uno::RuntimeException )
2491cdf0e10cSrcweir {
2492cdf0e10cSrcweir     throw lang::NoSupportException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SfxBaseModel controlls all the sent notifications itself!" ) ), uno::Reference< uno::XInterface >() );
2493cdf0e10cSrcweir }
2494cdf0e10cSrcweir 
2495cdf0e10cSrcweir //________________________________________________________________________________________________________
2496cdf0e10cSrcweir //  SfxListener
2497cdf0e10cSrcweir //________________________________________________________________________________________________________
2498cdf0e10cSrcweir 
2499cdf0e10cSrcweir void addTitle_Impl( Sequence < ::com::sun::star::beans::PropertyValue >& rSeq, const ::rtl::OUString& rTitle )
2500cdf0e10cSrcweir {
2501cdf0e10cSrcweir     sal_Int32 nCount = rSeq.getLength();
2502cdf0e10cSrcweir     sal_Int32 nArg;
2503cdf0e10cSrcweir 
2504cdf0e10cSrcweir     for ( nArg = 0; nArg < nCount; nArg++ )
2505cdf0e10cSrcweir     {
2506cdf0e10cSrcweir         ::com::sun::star::beans::PropertyValue& rProp = rSeq[nArg];
2507cdf0e10cSrcweir         if ( rProp.Name.equalsAscii("Title") )
2508cdf0e10cSrcweir         {
2509cdf0e10cSrcweir             rProp.Value <<= rTitle;
2510cdf0e10cSrcweir             break;
2511cdf0e10cSrcweir         }
2512cdf0e10cSrcweir     }
2513cdf0e10cSrcweir 
2514cdf0e10cSrcweir     if ( nArg == nCount )
2515cdf0e10cSrcweir     {
2516cdf0e10cSrcweir         rSeq.realloc( nCount+1 );
2517cdf0e10cSrcweir         rSeq[nCount].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Title") );
2518cdf0e10cSrcweir         rSeq[nCount].Value <<= rTitle;
2519cdf0e10cSrcweir     }
2520cdf0e10cSrcweir }
2521cdf0e10cSrcweir 
2522cdf0e10cSrcweir void SfxBaseModel::NotifyStorageListeners_Impl()
2523cdf0e10cSrcweir {
2524cdf0e10cSrcweir     uno::Reference< uno::XInterface > xSelfHold( static_cast< ::cppu::OWeakObject* >(this) );
2525cdf0e10cSrcweir 
2526cdf0e10cSrcweir     if ( m_pData->m_pObjectShell )
2527cdf0e10cSrcweir     {
2528cdf0e10cSrcweir         ::cppu::OInterfaceContainerHelper* pContainer =
2529cdf0e10cSrcweir             m_pData->m_aInterfaceContainer.getContainer(
2530cdf0e10cSrcweir                 ::getCppuType( ( const uno::Reference< document::XStorageChangeListener >*) NULL ) );
2531cdf0e10cSrcweir         if ( pContainer != NULL )
2532cdf0e10cSrcweir         {
2533cdf0e10cSrcweir             uno::Reference< embed::XStorage > xNewStorage = m_pData->m_pObjectShell->GetStorage();
2534cdf0e10cSrcweir             ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
2535cdf0e10cSrcweir             while ( pIterator.hasMoreElements() )
2536cdf0e10cSrcweir             {
2537cdf0e10cSrcweir                 try
2538cdf0e10cSrcweir                 {
2539cdf0e10cSrcweir                     ((document::XStorageChangeListener*)pIterator.next())->notifyStorageChange(
2540cdf0e10cSrcweir                                                                             xSelfHold,
2541cdf0e10cSrcweir                                                                             xNewStorage );
2542cdf0e10cSrcweir                 }
2543cdf0e10cSrcweir                 catch( uno::RuntimeException& )
2544cdf0e10cSrcweir                 {
2545cdf0e10cSrcweir                     pIterator.remove();
2546cdf0e10cSrcweir                 }
2547cdf0e10cSrcweir             }
2548cdf0e10cSrcweir         }
2549cdf0e10cSrcweir     }
2550cdf0e10cSrcweir }
2551cdf0e10cSrcweir 
2552cdf0e10cSrcweir void SfxBaseModel::Notify(          SfxBroadcaster& rBC     ,
2553cdf0e10cSrcweir                             const   SfxHint&        rHint   )
2554cdf0e10cSrcweir {
2555cdf0e10cSrcweir     if ( !m_pData )
2556cdf0e10cSrcweir         return;
2557cdf0e10cSrcweir 
2558cdf0e10cSrcweir     if ( &rBC == m_pData->m_pObjectShell )
2559cdf0e10cSrcweir     {
2560cdf0e10cSrcweir         SfxSimpleHint* pSimpleHint = PTR_CAST( SfxSimpleHint, &rHint );
2561cdf0e10cSrcweir         if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DOCCHANGED )
2562cdf0e10cSrcweir             changing();
2563cdf0e10cSrcweir 
2564cdf0e10cSrcweir         SfxEventHint* pNamedHint = PTR_CAST( SfxEventHint, &rHint );
2565cdf0e10cSrcweir         if ( pNamedHint )
2566cdf0e10cSrcweir         {
2567cdf0e10cSrcweir 
2568cdf0e10cSrcweir             switch ( pNamedHint->GetEventId() )
2569cdf0e10cSrcweir             {
2570cdf0e10cSrcweir             case SFX_EVENT_STORAGECHANGED:
2571cdf0e10cSrcweir             {
2572cdf0e10cSrcweir                 // for now this event is sent only on creation of a new storage for new document
2573cdf0e10cSrcweir                 // and in case of reload of medium without document reload
2574cdf0e10cSrcweir                 // other events are used to detect storage change
2575cdf0e10cSrcweir                 // NotifyStorageListeners_Impl();
2576cdf0e10cSrcweir 
2577cdf0e10cSrcweir                 if ( m_pData->m_xUIConfigurationManager.is()
2578cdf0e10cSrcweir                   && m_pData->m_pObjectShell->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED )
2579cdf0e10cSrcweir                 {
2580cdf0e10cSrcweir                     uno::Reference< XSTORAGE > xConfigStorage;
2581cdf0e10cSrcweir                     rtl::OUString aUIConfigFolderName( RTL_CONSTASCII_USTRINGPARAM( "Configurations2" ));
2582cdf0e10cSrcweir 
2583cdf0e10cSrcweir                     xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, com::sun::star::embed::ElementModes::READWRITE );
2584cdf0e10cSrcweir                     if ( !xConfigStorage.is() )
2585cdf0e10cSrcweir                         xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, com::sun::star::embed::ElementModes::READ );
2586cdf0e10cSrcweir 
2587cdf0e10cSrcweir                     if ( xConfigStorage.is() || !m_pData->m_pObjectShell->GetStorage()->hasByName( aUIConfigFolderName ) )
2588cdf0e10cSrcweir                     {
2589cdf0e10cSrcweir                         // the storage is different, since otherwise it could not be opened, so it must be exchanged
2590cdf0e10cSrcweir                         Reference< ui::XUIConfigurationStorage > xUIConfigStorage( m_pData->m_xUIConfigurationManager, uno::UNO_QUERY );
2591cdf0e10cSrcweir                         xUIConfigStorage->setStorage( xConfigStorage );
2592cdf0e10cSrcweir                     }
2593cdf0e10cSrcweir                     else
2594cdf0e10cSrcweir                     {
2595cdf0e10cSrcweir                         OSL_ENSURE( sal_False, "Unexpected scenario!\n" );
2596cdf0e10cSrcweir                     }
2597cdf0e10cSrcweir                 }
2598cdf0e10cSrcweir 
2599cdf0e10cSrcweir                 ListenForStorage_Impl( m_pData->m_pObjectShell->GetStorage() );
2600cdf0e10cSrcweir             }
2601cdf0e10cSrcweir             break;
2602cdf0e10cSrcweir 
2603cdf0e10cSrcweir             case SFX_EVENT_LOADFINISHED:
2604cdf0e10cSrcweir             {
2605cdf0e10cSrcweir                 impl_getPrintHelper();
2606cdf0e10cSrcweir                 ListenForStorage_Impl( m_pData->m_pObjectShell->GetStorage() );
2607cdf0e10cSrcweir                 m_pData->m_bModifiedSinceLastSave = sal_False;
2608cdf0e10cSrcweir             }
2609cdf0e10cSrcweir             break;
2610cdf0e10cSrcweir 
2611cdf0e10cSrcweir             case SFX_EVENT_SAVEASDOCDONE:
2612cdf0e10cSrcweir             {
2613cdf0e10cSrcweir                 m_pData->m_sURL = m_pData->m_pObjectShell->GetMedium()->GetName();
2614cdf0e10cSrcweir 
2615cdf0e10cSrcweir                 SfxItemSet *pSet = m_pData->m_pObjectShell->GetMedium()->GetItemSet();
2616cdf0e10cSrcweir                 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs;
2617cdf0e10cSrcweir                 ::rtl::OUString aTitle = m_pData->m_pObjectShell->GetTitle();
2618cdf0e10cSrcweir                 TransformItems( SID_SAVEASDOC, *pSet, aArgs );
2619cdf0e10cSrcweir                 addTitle_Impl( aArgs, aTitle );
2620cdf0e10cSrcweir                 attachResource( m_pData->m_pObjectShell->GetMedium()->GetName(), aArgs );
2621cdf0e10cSrcweir             }
2622cdf0e10cSrcweir             break;
2623cdf0e10cSrcweir 
2624cdf0e10cSrcweir             case SFX_EVENT_DOCCREATED:
2625cdf0e10cSrcweir             {
2626cdf0e10cSrcweir                 impl_getPrintHelper();
2627cdf0e10cSrcweir                 m_pData->m_bModifiedSinceLastSave = sal_False;
2628cdf0e10cSrcweir             }
2629cdf0e10cSrcweir             break;
2630cdf0e10cSrcweir 
2631cdf0e10cSrcweir             case SFX_EVENT_MODIFYCHANGED:
2632cdf0e10cSrcweir             {
2633cdf0e10cSrcweir                 m_pData->m_bModifiedSinceLastSave = isModified();
2634cdf0e10cSrcweir             }
2635cdf0e10cSrcweir             break;
2636cdf0e10cSrcweir             }
2637cdf0e10cSrcweir 
2638cdf0e10cSrcweir 
2639cdf0e10cSrcweir             SfxViewEventHint* pViewHint = PTR_CAST( SfxViewEventHint, &rHint );
2640cdf0e10cSrcweir             postEvent_Impl( pNamedHint->GetEventName(), pViewHint ? pViewHint->GetController() : uno::Reference< frame::XController2 >() );
2641cdf0e10cSrcweir         }
2642cdf0e10cSrcweir 
2643cdf0e10cSrcweir         if ( pSimpleHint )
2644cdf0e10cSrcweir         {
2645cdf0e10cSrcweir             if ( pSimpleHint->GetId() == SFX_HINT_TITLECHANGED )
2646cdf0e10cSrcweir             {
2647cdf0e10cSrcweir                 ::rtl::OUString aTitle = m_pData->m_pObjectShell->GetTitle();
2648cdf0e10cSrcweir                 addTitle_Impl( m_pData->m_seqArguments, aTitle );
2649cdf0e10cSrcweir                 postEvent_Impl( GlobalEventConfig::GetEventName( STR_EVENT_TITLECHANGED ) );
2650cdf0e10cSrcweir             }
2651cdf0e10cSrcweir             if ( pSimpleHint->GetId() == SFX_HINT_MODECHANGED )
2652cdf0e10cSrcweir             {
2653cdf0e10cSrcweir                 postEvent_Impl( GlobalEventConfig::GetEventName( STR_EVENT_MODECHANGED ) );
2654cdf0e10cSrcweir             }
2655cdf0e10cSrcweir /*
2656cdf0e10cSrcweir             else if ( pSimpleHint->GetId() == SFX_HINT_DYING
2657cdf0e10cSrcweir                 || pSimpleHint->GetId() == SFX_HINT_DEINITIALIZING )
2658cdf0e10cSrcweir             {
2659cdf0e10cSrcweir                 SfxObjectShellLock pShellLock = m_pData->m_pObjectShellLock;
2660cdf0e10cSrcweir                 m_pData->m_pObjectShellLock = SfxObjectShellLock();
2661cdf0e10cSrcweir             }
2662cdf0e10cSrcweir */
2663cdf0e10cSrcweir         }
2664cdf0e10cSrcweir     }
2665cdf0e10cSrcweir }
2666cdf0e10cSrcweir 
2667cdf0e10cSrcweir //________________________________________________________________________________________________________
2668cdf0e10cSrcweir //  public impl.
2669cdf0e10cSrcweir //________________________________________________________________________________________________________
2670cdf0e10cSrcweir 
2671cdf0e10cSrcweir void SfxBaseModel::NotifyModifyListeners_Impl() const
2672cdf0e10cSrcweir {
2673cdf0e10cSrcweir     ::cppu::OInterfaceContainerHelper* pIC = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType((const uno::Reference< XMODIFYLISTENER >*)0) );
2674cdf0e10cSrcweir     if ( pIC )
2675cdf0e10cSrcweir     {
2676cdf0e10cSrcweir         lang::EventObject aEvent( (frame::XModel *)this );
2677cdf0e10cSrcweir         pIC->notifyEach( &util::XModifyListener::modified, aEvent );
2678cdf0e10cSrcweir     }
2679cdf0e10cSrcweir 
2680cdf0e10cSrcweir     // this notification here is done too generously, we cannot simply assume that we're really modified
2681cdf0e10cSrcweir     // now, but we need to check it ...
2682cdf0e10cSrcweir     m_pData->m_bModifiedSinceLastSave = const_cast< SfxBaseModel* >( this )->isModified();
2683cdf0e10cSrcweir }
2684cdf0e10cSrcweir 
2685cdf0e10cSrcweir void SfxBaseModel::changing()
2686cdf0e10cSrcweir {
2687cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
2688cdf0e10cSrcweir 
2689cdf0e10cSrcweir     // the notification should not be sent if the document can not be modified
2690cdf0e10cSrcweir     if ( !m_pData->m_pObjectShell.Is() || !m_pData->m_pObjectShell->IsEnableSetModified() )
2691cdf0e10cSrcweir         return;
2692cdf0e10cSrcweir 
2693cdf0e10cSrcweir     NotifyModifyListeners_Impl();
2694cdf0e10cSrcweir }
2695cdf0e10cSrcweir 
2696cdf0e10cSrcweir void SfxBaseModel::impl_change()
2697cdf0e10cSrcweir {
2698cdf0e10cSrcweir     // object already disposed?
2699cdf0e10cSrcweir     if ( impl_isDisposed() )
2700cdf0e10cSrcweir         return;
2701cdf0e10cSrcweir 
2702cdf0e10cSrcweir     NotifyModifyListeners_Impl();
2703cdf0e10cSrcweir }
2704cdf0e10cSrcweir 
2705cdf0e10cSrcweir //________________________________________________________________________________________________________
2706cdf0e10cSrcweir //  public impl.
2707cdf0e10cSrcweir //________________________________________________________________________________________________________
2708cdf0e10cSrcweir 
2709cdf0e10cSrcweir SfxObjectShell* SfxBaseModel::GetObjectShell() const
2710cdf0e10cSrcweir {
2711cdf0e10cSrcweir     return m_pData ? (SfxObjectShell*) m_pData->m_pObjectShell : 0;
2712cdf0e10cSrcweir }
2713cdf0e10cSrcweir 
2714cdf0e10cSrcweir SfxObjectShell* SfxBaseModel::impl_getObjectShell() const
2715cdf0e10cSrcweir {
2716cdf0e10cSrcweir     return m_pData ? (SfxObjectShell*) m_pData->m_pObjectShell : 0;
2717cdf0e10cSrcweir }
2718cdf0e10cSrcweir 
2719cdf0e10cSrcweir //________________________________________________________________________________________________________
2720cdf0e10cSrcweir //  public impl.
2721cdf0e10cSrcweir //________________________________________________________________________________________________________
2722cdf0e10cSrcweir 
2723cdf0e10cSrcweir sal_Bool SfxBaseModel::IsInitialized() const
2724cdf0e10cSrcweir {
2725cdf0e10cSrcweir     if ( !m_pData || !m_pData->m_pObjectShell )
2726cdf0e10cSrcweir     {
2727cdf0e10cSrcweir         OSL_ENSURE( false, "SfxBaseModel::IsInitialized: this should have been caught earlier!" );
2728cdf0e10cSrcweir         return sal_False;
2729cdf0e10cSrcweir     }
2730cdf0e10cSrcweir 
2731cdf0e10cSrcweir     return m_pData->m_pObjectShell->GetMedium() != NULL;
2732cdf0e10cSrcweir }
2733cdf0e10cSrcweir 
2734cdf0e10cSrcweir void SfxBaseModel::MethodEntryCheck( const bool i_mustBeInitialized ) const
2735cdf0e10cSrcweir {
2736cdf0e10cSrcweir     if ( impl_isDisposed() )
2737cdf0e10cSrcweir         throw ::com::sun::star::lang::DisposedException( ::rtl::OUString(), *const_cast< SfxBaseModel* >( this ) );
2738cdf0e10cSrcweir     if ( i_mustBeInitialized && !IsInitialized() )
2739cdf0e10cSrcweir         throw ::com::sun::star::lang::NotInitializedException( ::rtl::OUString(), *const_cast< SfxBaseModel* >( this ) );
2740cdf0e10cSrcweir }
2741cdf0e10cSrcweir 
2742cdf0e10cSrcweir sal_Bool SfxBaseModel::impl_isDisposed() const
2743cdf0e10cSrcweir {
2744cdf0e10cSrcweir     return ( m_pData == NULL ) ;
2745cdf0e10cSrcweir }
2746cdf0e10cSrcweir 
2747cdf0e10cSrcweir //________________________________________________________________________________________________________
2748cdf0e10cSrcweir //  private impl.
2749cdf0e10cSrcweir //________________________________________________________________________________________________________
2750cdf0e10cSrcweir 
2751cdf0e10cSrcweir ::rtl::OUString SfxBaseModel::GetMediumFilterName_Impl()
2752cdf0e10cSrcweir {
2753cdf0e10cSrcweir     const SfxFilter* pFilter = NULL;
2754cdf0e10cSrcweir     SfxMedium* pMedium = m_pData->m_pObjectShell->GetMedium();
2755cdf0e10cSrcweir     if ( pMedium )
2756cdf0e10cSrcweir         pFilter = pMedium->GetFilter();
2757cdf0e10cSrcweir 
2758cdf0e10cSrcweir     if ( pFilter )
2759cdf0e10cSrcweir         return pFilter->GetName();
2760cdf0e10cSrcweir 
2761cdf0e10cSrcweir     return ::rtl::OUString();
2762cdf0e10cSrcweir }
2763cdf0e10cSrcweir 
2764cdf0e10cSrcweir void SfxBaseModel::impl_store(  const   ::rtl::OUString&                   sURL            ,
2765cdf0e10cSrcweir                                 const   uno::Sequence< beans::PropertyValue >&  seqArguments    ,
2766cdf0e10cSrcweir                                         sal_Bool                    bSaveTo         )
2767cdf0e10cSrcweir {
2768cdf0e10cSrcweir     if( !sURL.getLength() )
2769cdf0e10cSrcweir         throw frame::IllegalArgumentIOException();
2770cdf0e10cSrcweir 
2771cdf0e10cSrcweir     //sal_Bool aSaveAsTemplate = sal_False;
2772cdf0e10cSrcweir 
2773cdf0e10cSrcweir     sal_Bool bSaved = sal_False;
2774cdf0e10cSrcweir     if ( !bSaveTo && m_pData->m_pObjectShell && sURL.getLength()
2775cdf0e10cSrcweir       && sURL.compareToAscii( "private:stream", 14 ) != COMPARE_EQUAL
2776cdf0e10cSrcweir       && ::utl::UCBContentHelper::EqualURLs( getLocation(), sURL ) )
2777cdf0e10cSrcweir     {
2778cdf0e10cSrcweir         // this is the same file URL as the current document location, try to use storeOwn if possible
2779cdf0e10cSrcweir 
2780cdf0e10cSrcweir         ::comphelper::SequenceAsHashMap aArgHash( seqArguments );
2781cdf0e10cSrcweir         ::rtl::OUString aFilterString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ) );
2782cdf0e10cSrcweir         ::rtl::OUString aFilterName = aArgHash.getUnpackedValueOrDefault( aFilterString, ::rtl::OUString() );
2783cdf0e10cSrcweir         if ( aFilterName.getLength() )
2784cdf0e10cSrcweir         {
2785cdf0e10cSrcweir             SfxMedium* pMedium = m_pData->m_pObjectShell->GetMedium();
2786cdf0e10cSrcweir             if ( pMedium )
2787cdf0e10cSrcweir             {
2788cdf0e10cSrcweir                 const SfxFilter* pFilter = pMedium->GetFilter();
2789cdf0e10cSrcweir                 if ( pFilter && aFilterName.equals( pFilter->GetFilterName() ) )
2790cdf0e10cSrcweir                 {
2791*f6b63cabSOliver-Rainer Wittmann                     // 119366 - If the former file saving with password, do not trying in StoreSelf anyway...
2792*f6b63cabSOliver-Rainer Wittmann                     bool bFormerPassword = false;
2793*f6b63cabSOliver-Rainer Wittmann                     {
2794*f6b63cabSOliver-Rainer Wittmann                         uno::Sequence< beans::NamedValue > aOldEncryptionData;
2795*f6b63cabSOliver-Rainer Wittmann                         if (GetEncryptionData_Impl( pMedium->GetItemSet(), aOldEncryptionData ))
2796*f6b63cabSOliver-Rainer Wittmann                         {
2797*f6b63cabSOliver-Rainer Wittmann                             bFormerPassword = true;
2798*f6b63cabSOliver-Rainer Wittmann                         }
2799*f6b63cabSOliver-Rainer Wittmann                     }
2800*f6b63cabSOliver-Rainer Wittmann                     if ( !bFormerPassword )
2801*f6b63cabSOliver-Rainer Wittmann                     {
2802cdf0e10cSrcweir                         aArgHash.erase( aFilterString );
2803cdf0e10cSrcweir                         aArgHash.erase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ) );
2804cdf0e10cSrcweir 
2805cdf0e10cSrcweir                         try
2806cdf0e10cSrcweir                         {
2807cdf0e10cSrcweir                             storeSelf( aArgHash.getAsConstPropertyValueList() );
2808cdf0e10cSrcweir                             bSaved = sal_True;
2809cdf0e10cSrcweir                         }
2810cdf0e10cSrcweir                         catch( const lang::IllegalArgumentException& )
2811cdf0e10cSrcweir                         {
2812cdf0e10cSrcweir                             // some additional arguments do not allow to use saving, SaveAs should be done
2813cdf0e10cSrcweir                             // but only for normal documents, the shared documents would be overwritten in this case
2814cdf0e10cSrcweir                             // that would mean an information loss
2815cdf0e10cSrcweir                             // TODO/LATER: need a new interaction for this case
2816cdf0e10cSrcweir                             if ( m_pData->m_pObjectShell->IsDocShared() )
2817cdf0e10cSrcweir                             {
2818cdf0e10cSrcweir                                 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't store shared document!" ) ) );
2819cdf0e10cSrcweir                                 m_pData->m_pObjectShell->StoreLog();
2820cdf0e10cSrcweir 
2821cdf0e10cSrcweir                                 uno::Sequence< beans::NamedValue > aNewEncryptionData = aArgHash.getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionData" ) ), uno::Sequence< beans::NamedValue >() );
2822cdf0e10cSrcweir                                 if ( !aNewEncryptionData.getLength() )
2823cdf0e10cSrcweir                                 {
2824cdf0e10cSrcweir                                     ::rtl::OUString aNewPassword = aArgHash.getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Password" ) ), ::rtl::OUString() );
2825cdf0e10cSrcweir                                     aNewEncryptionData = ::comphelper::OStorageHelper::CreatePackageEncryptionData( aNewPassword );
2826cdf0e10cSrcweir                                 }
2827cdf0e10cSrcweir 
2828cdf0e10cSrcweir                                 uno::Sequence< beans::NamedValue > aOldEncryptionData;
2829cdf0e10cSrcweir                                 GetEncryptionData_Impl( pMedium->GetItemSet(), aOldEncryptionData );
2830cdf0e10cSrcweir 
2831cdf0e10cSrcweir                                 if ( !aOldEncryptionData.getLength() && !aNewEncryptionData.getLength() )
2832cdf0e10cSrcweir                                     throw;
2833cdf0e10cSrcweir                                 else
2834cdf0e10cSrcweir                                 {
2835cdf0e10cSrcweir                                     // if the password is changed a special error should be used in case of shared document
2836cdf0e10cSrcweir                                     throw task::ErrorCodeIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cant change password for shared document." ) ), uno::Reference< uno::XInterface >(), ERRCODE_SFX_SHARED_NOPASSWORDCHANGE );
2837cdf0e10cSrcweir                                 }
2838cdf0e10cSrcweir                             }
2839cdf0e10cSrcweir                         }
2840cdf0e10cSrcweir                     }
2841cdf0e10cSrcweir                 }
2842cdf0e10cSrcweir             }
2843cdf0e10cSrcweir         }
2844*f6b63cabSOliver-Rainer Wittmann     }
2845cdf0e10cSrcweir 
2846cdf0e10cSrcweir     if ( !bSaved && m_pData->m_pObjectShell )
2847cdf0e10cSrcweir     {
2848cdf0e10cSrcweir         SFX_APP()->NotifyEvent( SfxEventHint( bSaveTo ? SFX_EVENT_SAVETODOC : SFX_EVENT_SAVEASDOC, GlobalEventConfig::GetEventName( bSaveTo ? STR_EVENT_SAVETODOC : STR_EVENT_SAVEASDOC ),
2849cdf0e10cSrcweir                                                 m_pData->m_pObjectShell ) );
2850cdf0e10cSrcweir 
2851cdf0e10cSrcweir         SfxAllItemSet *aParams = new SfxAllItemSet( SFX_APP()->GetPool() );
2852cdf0e10cSrcweir         aParams->Put( SfxStringItem( SID_FILE_NAME, String(sURL) ) );
2853cdf0e10cSrcweir         if ( bSaveTo )
2854cdf0e10cSrcweir             aParams->Put( SfxBoolItem( SID_SAVETO, sal_True ) );
2855cdf0e10cSrcweir 
2856cdf0e10cSrcweir         TransformParameters( SID_SAVEASDOC, seqArguments, *aParams );
2857cdf0e10cSrcweir 
2858cdf0e10cSrcweir         SFX_ITEMSET_ARG( aParams, pCopyStreamItem, SfxBoolItem, SID_COPY_STREAM_IF_POSSIBLE, sal_False );
2859cdf0e10cSrcweir 
2860cdf0e10cSrcweir         if ( pCopyStreamItem && pCopyStreamItem->GetValue() && !bSaveTo )
2861cdf0e10cSrcweir         {
2862cdf0e10cSrcweir             m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Misuse of CopyStreamIfPossible!" ) ) );
2863cdf0e10cSrcweir             m_pData->m_pObjectShell->StoreLog();
2864cdf0e10cSrcweir 
2865cdf0e10cSrcweir             throw frame::IllegalArgumentIOException(
2866cdf0e10cSrcweir                     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CopyStreamIfPossible parameter is not acceptable for storeAsURL() call!") ),
2867cdf0e10cSrcweir                     uno::Reference< uno::XInterface >() );
2868cdf0e10cSrcweir         }
2869cdf0e10cSrcweir 
2870cdf0e10cSrcweir         sal_uInt32 nModifyPasswordHash = 0;
2871cdf0e10cSrcweir         uno::Sequence< beans::PropertyValue > aModifyPasswordInfo;
2872cdf0e10cSrcweir         SFX_ITEMSET_ARG( aParams, pModifyPasswordInfoItem, SfxUnoAnyItem, SID_MODIFYPASSWORDINFO, sal_False );
2873cdf0e10cSrcweir         if ( pModifyPasswordInfoItem )
2874cdf0e10cSrcweir         {
2875cdf0e10cSrcweir             // it contains either a simple hash or a set of PropertyValues
2876cdf0e10cSrcweir             // TODO/LATER: the sequence of PropertyValue should replace the hash completely in future
2877cdf0e10cSrcweir             sal_Int32 nMPHTmp = 0;
2878cdf0e10cSrcweir             pModifyPasswordInfoItem->GetValue() >>= nMPHTmp;
2879cdf0e10cSrcweir             nModifyPasswordHash = (sal_uInt32)nMPHTmp;
2880cdf0e10cSrcweir             pModifyPasswordInfoItem->GetValue() >>= aModifyPasswordInfo;
2881cdf0e10cSrcweir         }
2882cdf0e10cSrcweir         aParams->ClearItem( SID_MODIFYPASSWORDINFO );
2883cdf0e10cSrcweir         sal_uInt32 nOldModifyPasswordHash = m_pData->m_pObjectShell->GetModifyPasswordHash();
2884cdf0e10cSrcweir         m_pData->m_pObjectShell->SetModifyPasswordHash( nModifyPasswordHash );
2885cdf0e10cSrcweir         uno::Sequence< beans::PropertyValue > aOldModifyPasswordInfo = m_pData->m_pObjectShell->GetModifyPasswordInfo();
2886cdf0e10cSrcweir         m_pData->m_pObjectShell->SetModifyPasswordInfo( aModifyPasswordInfo );
2887cdf0e10cSrcweir 
2888cdf0e10cSrcweir         // since saving a document modifies its DocumentInfo, the current
2889cdf0e10cSrcweir         // DocumentInfo must be saved on "SaveTo", so it can be restored
2890cdf0e10cSrcweir         // after saving
2891cdf0e10cSrcweir         sal_Bool bCopyTo =  bSaveTo ||
2892cdf0e10cSrcweir             m_pData->m_pObjectShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED;
2893cdf0e10cSrcweir         uno::Reference<document::XDocumentProperties> xOldDocProps;
2894cdf0e10cSrcweir         uno::Reference<document::XDocumentInfo> xOldDocInfo;
2895cdf0e10cSrcweir         if ( bCopyTo )
2896cdf0e10cSrcweir         {
2897cdf0e10cSrcweir             xOldDocProps = getDocumentProperties();
2898cdf0e10cSrcweir             if (m_pData->m_xDocumentInfo.is())
2899cdf0e10cSrcweir             {
2900cdf0e10cSrcweir                 xOldDocInfo = getDocumentInfo();
2901cdf0e10cSrcweir                 const Reference<util::XCloneable> xCloneable(xOldDocInfo,
2902cdf0e10cSrcweir                     UNO_QUERY_THROW);
2903cdf0e10cSrcweir                 const Reference<document::XDocumentInfo> xNewDocInfo(
2904cdf0e10cSrcweir                     xCloneable->createClone(), UNO_QUERY_THROW);
2905cdf0e10cSrcweir                 const Reference<document::XDocumentPropertiesSupplier> xDPS(
2906cdf0e10cSrcweir                     xNewDocInfo, UNO_QUERY_THROW);
2907cdf0e10cSrcweir                 const Reference<document::XDocumentProperties> xNewDocProps(
2908cdf0e10cSrcweir                     xDPS->getDocumentProperties());
2909cdf0e10cSrcweir                 m_pData->m_xDocumentProperties = xNewDocProps;
2910cdf0e10cSrcweir                 m_pData->m_xDocumentInfo = xNewDocInfo;
2911cdf0e10cSrcweir             }
2912cdf0e10cSrcweir             else // try not to create DocumentInfo if it does not exist...
2913cdf0e10cSrcweir             {
2914cdf0e10cSrcweir                 const Reference<util::XCloneable> xCloneable(xOldDocProps,
2915cdf0e10cSrcweir                     UNO_QUERY_THROW);
2916cdf0e10cSrcweir                 const Reference<document::XDocumentProperties> xNewDocProps(
2917cdf0e10cSrcweir                     xCloneable->createClone(), UNO_QUERY_THROW);
2918cdf0e10cSrcweir                 m_pData->m_xDocumentProperties = xNewDocProps;
2919cdf0e10cSrcweir             }
2920cdf0e10cSrcweir         }
2921cdf0e10cSrcweir 
2922cdf0e10cSrcweir         sal_Bool bRet = m_pData->m_pObjectShell->APISaveAs_Impl( sURL, aParams );
2923cdf0e10cSrcweir 
2924cdf0e10cSrcweir         if ( bCopyTo )
2925cdf0e10cSrcweir         {
2926cdf0e10cSrcweir             // restore DocumentInfo if a copy was created
2927cdf0e10cSrcweir             m_pData->m_xDocumentProperties = xOldDocProps;
2928cdf0e10cSrcweir             m_pData->m_xDocumentInfo = xOldDocInfo;
2929cdf0e10cSrcweir         }
2930cdf0e10cSrcweir 
2931cdf0e10cSrcweir         uno::Reference < task::XInteractionHandler > xHandler;
2932cdf0e10cSrcweir         SFX_ITEMSET_ARG( aParams, pItem, SfxUnoAnyItem, SID_INTERACTIONHANDLER, sal_False);
2933cdf0e10cSrcweir         if ( pItem )
2934cdf0e10cSrcweir             pItem->GetValue() >>= xHandler;
2935cdf0e10cSrcweir 
2936cdf0e10cSrcweir         DELETEZ( aParams );
2937cdf0e10cSrcweir 
2938cdf0e10cSrcweir         sal_uInt32 nErrCode = m_pData->m_pObjectShell->GetErrorCode();
2939cdf0e10cSrcweir         if ( !bRet && !nErrCode )
2940cdf0e10cSrcweir         {
2941cdf0e10cSrcweir             m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing has failed, no error is set!" ) ) );
2942cdf0e10cSrcweir             nErrCode = ERRCODE_IO_CANTWRITE;
2943cdf0e10cSrcweir         }
2944cdf0e10cSrcweir         m_pData->m_pObjectShell->ResetError();
2945cdf0e10cSrcweir 
2946cdf0e10cSrcweir         if ( bRet )
2947cdf0e10cSrcweir         {
2948cdf0e10cSrcweir             if ( nErrCode )
2949cdf0e10cSrcweir             {
2950cdf0e10cSrcweir                 // must be a warning - use Interactionhandler if possible or abandone
2951cdf0e10cSrcweir                 if ( xHandler.is() )
2952cdf0e10cSrcweir                 {
2953cdf0e10cSrcweir                     // TODO/LATER: a general way to set the error context should be available
2954cdf0e10cSrcweir                     SfxErrorContext aEc( ERRCTX_SFX_SAVEASDOC, m_pData->m_pObjectShell->GetTitle() );
2955cdf0e10cSrcweir 
2956cdf0e10cSrcweir                     ::com::sun::star::task::ErrorCodeRequest aErrorCode;
2957cdf0e10cSrcweir                     aErrorCode.ErrCode = nErrCode;
2958cdf0e10cSrcweir                     SfxMedium::CallApproveHandler( xHandler, uno::makeAny( aErrorCode ), sal_False );
2959cdf0e10cSrcweir                 }
2960cdf0e10cSrcweir             }
2961cdf0e10cSrcweir 
2962cdf0e10cSrcweir             m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing succeeded!" ) ) );
2963cdf0e10cSrcweir             if ( !bSaveTo )
2964cdf0e10cSrcweir             {
2965cdf0e10cSrcweir                 m_pData->m_aPreusedFilterName = GetMediumFilterName_Impl();
2966cdf0e10cSrcweir                 m_pData->m_pObjectShell->SetModifyPasswordEntered();
2967cdf0e10cSrcweir 
2968cdf0e10cSrcweir                 SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEASDOCDONE, GlobalEventConfig::GetEventName(STR_EVENT_SAVEASDOCDONE), m_pData->m_pObjectShell ) );
2969cdf0e10cSrcweir             }
2970cdf0e10cSrcweir             else
2971cdf0e10cSrcweir             {
2972cdf0e10cSrcweir                 m_pData->m_pObjectShell->SetModifyPasswordHash( nOldModifyPasswordHash );
2973cdf0e10cSrcweir                 m_pData->m_pObjectShell->SetModifyPasswordInfo( aOldModifyPasswordInfo );
2974cdf0e10cSrcweir 
2975cdf0e10cSrcweir                 SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVETODOCDONE, GlobalEventConfig::GetEventName(STR_EVENT_SAVETODOCDONE), m_pData->m_pObjectShell ) );
2976cdf0e10cSrcweir             }
2977cdf0e10cSrcweir         }
2978cdf0e10cSrcweir         else
2979cdf0e10cSrcweir         {
2980cdf0e10cSrcweir             // let the logring be stored to the related file
2981cdf0e10cSrcweir             m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing failed!" ) ) );
2982cdf0e10cSrcweir             m_pData->m_pObjectShell->StoreLog();
2983cdf0e10cSrcweir 
2984cdf0e10cSrcweir             m_pData->m_pObjectShell->SetModifyPasswordHash( nOldModifyPasswordHash );
2985cdf0e10cSrcweir             m_pData->m_pObjectShell->SetModifyPasswordInfo( aOldModifyPasswordInfo );
2986cdf0e10cSrcweir 
2987cdf0e10cSrcweir 
2988cdf0e10cSrcweir             SFX_APP()->NotifyEvent( SfxEventHint( bSaveTo ? SFX_EVENT_SAVETODOCFAILED : SFX_EVENT_SAVEASDOCFAILED, GlobalEventConfig::GetEventName( bSaveTo ? STR_EVENT_SAVETODOCFAILED : STR_EVENT_SAVEASDOCFAILED),
2989cdf0e10cSrcweir                                                     m_pData->m_pObjectShell ) );
2990cdf0e10cSrcweir 
2991cdf0e10cSrcweir             throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), nErrCode );
2992cdf0e10cSrcweir         }
2993cdf0e10cSrcweir     }
2994cdf0e10cSrcweir }
2995cdf0e10cSrcweir 
2996cdf0e10cSrcweir //********************************************************************************************************
2997cdf0e10cSrcweir namespace {
2998cdf0e10cSrcweir template< typename ListenerT, typename EventT >
2999cdf0e10cSrcweir class NotifySingleListenerIgnoreRE
3000cdf0e10cSrcweir {
3001cdf0e10cSrcweir private:
3002cdf0e10cSrcweir     typedef void ( SAL_CALL ListenerT::*NotificationMethod )( const EventT& );
3003cdf0e10cSrcweir     NotificationMethod  m_pMethod;
3004cdf0e10cSrcweir     const EventT&       m_rEvent;
3005cdf0e10cSrcweir public:
3006cdf0e10cSrcweir     NotifySingleListenerIgnoreRE( NotificationMethod method, const EventT& event ) : m_pMethod( method ), m_rEvent( event ) { }
3007cdf0e10cSrcweir 
3008cdf0e10cSrcweir     void operator()( const uno::Reference<ListenerT>& listener ) const
3009cdf0e10cSrcweir     {
3010cdf0e10cSrcweir         try
3011cdf0e10cSrcweir         {
3012cdf0e10cSrcweir             (listener.get()->*m_pMethod)( m_rEvent );
3013cdf0e10cSrcweir         }
3014cdf0e10cSrcweir         catch( uno::RuntimeException& )
3015cdf0e10cSrcweir         {
3016cdf0e10cSrcweir             // this exception is ignored to avoid problems with invalid listeners, the listener should be probably thrown away in future
3017cdf0e10cSrcweir         }
3018cdf0e10cSrcweir     }
3019cdf0e10cSrcweir };
3020cdf0e10cSrcweir } // anonymous namespace
3021cdf0e10cSrcweir 
3022cdf0e10cSrcweir void SfxBaseModel::postEvent_Impl( const ::rtl::OUString& aName, const uno::Reference< frame::XController2 >& xController )
3023cdf0e10cSrcweir {
3024cdf0e10cSrcweir     // object already disposed?
3025cdf0e10cSrcweir     if ( impl_isDisposed() )
3026cdf0e10cSrcweir         return;
3027cdf0e10cSrcweir 
3028cdf0e10cSrcweir     DBG_ASSERT( aName.getLength(), "Empty event name!" );
3029cdf0e10cSrcweir     if (!aName.getLength())
3030cdf0e10cSrcweir         return;
3031cdf0e10cSrcweir 
3032cdf0e10cSrcweir     ::cppu::OInterfaceContainerHelper* pIC =
3033cdf0e10cSrcweir         m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( (const uno::Reference< document::XDocumentEventListener >*)0 ) );
3034cdf0e10cSrcweir     if ( pIC )
3035cdf0e10cSrcweir     {
3036cdf0e10cSrcweir #ifdef DBG_UTIL
3037cdf0e10cSrcweir         ByteString aTmp( "SfxDocumentEvent: " );
3038cdf0e10cSrcweir         aTmp += ByteString( String(aName), RTL_TEXTENCODING_UTF8 );
3039cdf0e10cSrcweir         DBG_TRACE( aTmp.GetBuffer() );
3040cdf0e10cSrcweir #endif
3041cdf0e10cSrcweir 
3042cdf0e10cSrcweir         document::DocumentEvent aDocumentEvent( (frame::XModel*)this, aName, xController, uno::Any() );
3043cdf0e10cSrcweir 
3044cdf0e10cSrcweir         pIC->forEach< document::XDocumentEventListener, NotifySingleListenerIgnoreRE< document::XDocumentEventListener, document::DocumentEvent > >(
3045cdf0e10cSrcweir             NotifySingleListenerIgnoreRE< document::XDocumentEventListener, document::DocumentEvent >(
3046cdf0e10cSrcweir                 &document::XDocumentEventListener::documentEventOccured,
3047cdf0e10cSrcweir                 aDocumentEvent ) );
3048cdf0e10cSrcweir     }
3049cdf0e10cSrcweir 
3050cdf0e10cSrcweir     pIC = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( (const uno::Reference< document::XEventListener >*)0 ) );
3051cdf0e10cSrcweir     if ( pIC )
3052cdf0e10cSrcweir     {
3053cdf0e10cSrcweir #ifdef DBG_UTIL
3054cdf0e10cSrcweir         ByteString aTmp( "SfxEvent: " );
3055cdf0e10cSrcweir         aTmp += ByteString( String(aName), RTL_TEXTENCODING_UTF8 );
3056cdf0e10cSrcweir         DBG_TRACE( aTmp.GetBuffer() );
3057cdf0e10cSrcweir #endif
3058cdf0e10cSrcweir 
3059cdf0e10cSrcweir         document::EventObject aEvent( (frame::XModel*)this, aName );
3060cdf0e10cSrcweir 
3061cdf0e10cSrcweir         pIC->forEach< document::XEventListener, NotifySingleListenerIgnoreRE< document::XEventListener, document::EventObject > >(
3062cdf0e10cSrcweir             NotifySingleListenerIgnoreRE< document::XEventListener, document::EventObject >(
3063cdf0e10cSrcweir                 &document::XEventListener::notifyEvent,
3064cdf0e10cSrcweir                 aEvent ) );
3065cdf0e10cSrcweir     }
3066cdf0e10cSrcweir 
3067cdf0e10cSrcweir }
3068cdf0e10cSrcweir 
3069cdf0e10cSrcweir uno::Reference < container::XIndexAccess > SAL_CALL SfxBaseModel::getViewData() throw(::com::sun::star::uno::RuntimeException)
3070cdf0e10cSrcweir {
3071cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3072cdf0e10cSrcweir 
3073cdf0e10cSrcweir     if ( m_pData->m_pObjectShell.Is() && !m_pData->m_contViewData.is() )
3074cdf0e10cSrcweir     {
3075cdf0e10cSrcweir         SfxViewFrame *pActFrame = SfxViewFrame::Current();
3076cdf0e10cSrcweir         if ( !pActFrame || pActFrame->GetObjectShell() != m_pData->m_pObjectShell )
3077cdf0e10cSrcweir             pActFrame = SfxViewFrame::GetFirst( m_pData->m_pObjectShell );
3078cdf0e10cSrcweir 
3079cdf0e10cSrcweir         if ( !pActFrame || !pActFrame->GetViewShell() )
3080cdf0e10cSrcweir             // currently no frame for this document at all or View is under construction
3081cdf0e10cSrcweir             return uno::Reference < container::XIndexAccess >();
3082cdf0e10cSrcweir 
3083cdf0e10cSrcweir         m_pData->m_contViewData = Reference < container::XIndexAccess >(
3084cdf0e10cSrcweir                 ::comphelper::getProcessServiceFactory()->createInstance(
3085cdf0e10cSrcweir                 DEFINE_CONST_UNICODE("com.sun.star.document.IndexedPropertyValues") ),
3086cdf0e10cSrcweir                 uno::UNO_QUERY );
3087cdf0e10cSrcweir 
3088cdf0e10cSrcweir         if ( !m_pData->m_contViewData.is() )
3089cdf0e10cSrcweir         {
3090cdf0e10cSrcweir             // error: no container class available!
3091cdf0e10cSrcweir             return uno::Reference < container::XIndexAccess >();
3092cdf0e10cSrcweir         }
3093cdf0e10cSrcweir 
3094cdf0e10cSrcweir         uno::Reference < container::XIndexContainer > xCont( m_pData->m_contViewData, uno::UNO_QUERY );
3095cdf0e10cSrcweir         sal_Int32 nCount = 0;
3096cdf0e10cSrcweir         uno::Sequence < beans::PropertyValue > aSeq;
3097cdf0e10cSrcweir         ::com::sun::star::uno::Any aAny;
3098cdf0e10cSrcweir         for ( SfxViewFrame *pFrame = SfxViewFrame::GetFirst( m_pData->m_pObjectShell ); pFrame;
3099cdf0e10cSrcweir                 pFrame = SfxViewFrame::GetNext( *pFrame, m_pData->m_pObjectShell ) )
3100cdf0e10cSrcweir         {
3101cdf0e10cSrcweir             sal_Bool bIsActive = ( pFrame == pActFrame );
3102cdf0e10cSrcweir             pFrame->GetViewShell()->WriteUserDataSequence( aSeq );
3103cdf0e10cSrcweir             aAny <<= aSeq;
3104cdf0e10cSrcweir             xCont->insertByIndex( bIsActive ? 0 : nCount, aAny );
3105cdf0e10cSrcweir             nCount++;
3106cdf0e10cSrcweir         }
3107cdf0e10cSrcweir     }
3108cdf0e10cSrcweir 
3109cdf0e10cSrcweir     return m_pData->m_contViewData;
3110cdf0e10cSrcweir }
3111cdf0e10cSrcweir 
3112cdf0e10cSrcweir void SAL_CALL SfxBaseModel::setViewData( const uno::Reference < container::XIndexAccess >& aData ) throw(::com::sun::star::uno::RuntimeException)
3113cdf0e10cSrcweir {
3114cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3115cdf0e10cSrcweir 
3116cdf0e10cSrcweir     m_pData->m_contViewData = aData;
3117cdf0e10cSrcweir }
3118cdf0e10cSrcweir 
3119cdf0e10cSrcweir /** calls all XEventListeners */
3120cdf0e10cSrcweir void SfxBaseModel::notifyEvent( const ::com::sun::star::document::EventObject& aEvent ) const
3121cdf0e10cSrcweir {
3122cdf0e10cSrcweir     // object already disposed?
3123cdf0e10cSrcweir     if ( impl_isDisposed() )
3124cdf0e10cSrcweir         return;
3125cdf0e10cSrcweir 
3126cdf0e10cSrcweir     ::cppu::OInterfaceContainerHelper* pIC = m_pData->m_aInterfaceContainer.getContainer(
3127cdf0e10cSrcweir                                         ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0) );
3128cdf0e10cSrcweir     if( pIC )
3129cdf0e10cSrcweir 
3130cdf0e10cSrcweir     {
3131cdf0e10cSrcweir         ::cppu::OInterfaceIteratorHelper aIt( *pIC );
3132cdf0e10cSrcweir         while( aIt.hasMoreElements() )
3133cdf0e10cSrcweir         {
3134cdf0e10cSrcweir             try
3135cdf0e10cSrcweir             {
3136cdf0e10cSrcweir                 ((XDOCEVENTLISTENER *)aIt.next())->notifyEvent( aEvent );
3137cdf0e10cSrcweir             }
3138cdf0e10cSrcweir             catch( uno::RuntimeException& )
3139cdf0e10cSrcweir             {
3140cdf0e10cSrcweir                 aIt.remove();
3141cdf0e10cSrcweir             }
3142cdf0e10cSrcweir         }
3143cdf0e10cSrcweir     }
3144cdf0e10cSrcweir }
3145cdf0e10cSrcweir 
3146cdf0e10cSrcweir /** returns true if someone added a XEventListener to this XEventBroadcaster */
3147cdf0e10cSrcweir sal_Bool SfxBaseModel::hasEventListeners() const
3148cdf0e10cSrcweir {
3149cdf0e10cSrcweir     return !impl_isDisposed() && (NULL != m_pData->m_aInterfaceContainer.getContainer( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0) ) );
3150cdf0e10cSrcweir }
3151cdf0e10cSrcweir 
3152cdf0e10cSrcweir void SAL_CALL SfxBaseModel::addPrintJobListener( const uno::Reference< view::XPrintJobListener >& xListener ) throw (uno::RuntimeException)
3153cdf0e10cSrcweir {
3154cdf0e10cSrcweir     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
3155cdf0e10cSrcweir 
3156cdf0e10cSrcweir     if ( impl_getPrintHelper() )
3157cdf0e10cSrcweir     {
3158cdf0e10cSrcweir         uno::Reference < view::XPrintJobBroadcaster > xPJB( m_pData->m_xPrintable, uno::UNO_QUERY );
3159cdf0e10cSrcweir         if ( xPJB.is() )
3160cdf0e10cSrcweir             xPJB->addPrintJobListener( xListener );
3161cdf0e10cSrcweir     }
3162cdf0e10cSrcweir //  else
3163cdf0e10cSrcweir //      m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< view::XPrintJobListener >*)0), xListener );
3164cdf0e10cSrcweir }
3165cdf0e10cSrcweir 
3166cdf0e10cSrcweir void SAL_CALL SfxBaseModel::removePrintJobListener( const uno::Reference< view::XPrintJobListener >& xListener ) throw (uno::RuntimeException)
3167cdf0e10cSrcweir {
3168cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3169cdf0e10cSrcweir 
3170cdf0e10cSrcweir     if ( impl_getPrintHelper() )
3171cdf0e10cSrcweir     {
3172cdf0e10cSrcweir         uno::Reference < view::XPrintJobBroadcaster > xPJB( m_pData->m_xPrintable, uno::UNO_QUERY );
3173cdf0e10cSrcweir         if ( xPJB.is() )
3174cdf0e10cSrcweir             xPJB->removePrintJobListener( xListener );
3175cdf0e10cSrcweir     }
3176cdf0e10cSrcweir //  else
3177cdf0e10cSrcweir //      m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< view::XPrintJobListener >*)0), xListener );
3178cdf0e10cSrcweir }
3179cdf0e10cSrcweir 
3180cdf0e10cSrcweir // simple declaration of class SvObject is enough
3181cdf0e10cSrcweir // the corresponding <so3/iface.hxx> cannon be included because it provides
3182cdf0e10cSrcweir // declaration of class SvBorder that conflicts with ../../inc/viewfrm.hxx
3183cdf0e10cSrcweir class SvObject;
3184cdf0e10cSrcweir sal_Int64 SAL_CALL SfxBaseModel::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException)
3185cdf0e10cSrcweir {
3186cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
3187cdf0e10cSrcweir     if ( GetObjectShell() )
3188cdf0e10cSrcweir     {
3189cdf0e10cSrcweir         SvGlobalName aName( aIdentifier );
3190cdf0e10cSrcweir         if ( aName == SvGlobalName( SO3_GLOBAL_CLASSID ) )
3191cdf0e10cSrcweir             return (sal_Int64)(sal_IntPtr)(SvObject*)GetObjectShell();
3192cdf0e10cSrcweir         else if ( aName == SvGlobalName( SFX_GLOBAL_CLASSID ) )
3193cdf0e10cSrcweir             return (sal_Int64)(sal_IntPtr)(SfxObjectShell*)GetObjectShell();
3194cdf0e10cSrcweir     }
3195cdf0e10cSrcweir 
3196cdf0e10cSrcweir     return 0;
3197cdf0e10cSrcweir }
3198cdf0e10cSrcweir 
3199cdf0e10cSrcweir //____________________________________________________________________________________________________
3200cdf0e10cSrcweir //  XDocumentSubStorageSupplier
3201cdf0e10cSrcweir //____________________________________________________________________________________________________
3202cdf0e10cSrcweir 
3203cdf0e10cSrcweir void SfxBaseModel::ListenForStorage_Impl( const uno::Reference< embed::XStorage >& xStorage )
3204cdf0e10cSrcweir {
3205cdf0e10cSrcweir     uno::Reference< util::XModifiable > xModifiable( xStorage, uno::UNO_QUERY );
3206cdf0e10cSrcweir     if ( xModifiable.is() )
3207cdf0e10cSrcweir     {
3208cdf0e10cSrcweir         if ( !m_pData->m_pStorageModifyListen.is() )
3209cdf0e10cSrcweir         {
3210cdf0e10cSrcweir             m_pData->m_pStorageModifyListen = new ::sfx2::DocumentStorageModifyListener( *m_pData, Application::GetSolarMutex() );
3211cdf0e10cSrcweir         }
3212cdf0e10cSrcweir 
3213cdf0e10cSrcweir         // no need to deregister the listening for old storage since it should be disposed automatically
3214cdf0e10cSrcweir         xModifiable->addModifyListener( m_pData->m_pStorageModifyListen.get() );
3215cdf0e10cSrcweir     }
3216cdf0e10cSrcweir }
3217cdf0e10cSrcweir 
3218cdf0e10cSrcweir uno::Reference< XSTORAGE > SAL_CALL SfxBaseModel::getDocumentSubStorage( const ::rtl::OUString& aStorageName, sal_Int32 nMode )
3219cdf0e10cSrcweir     throw ( uno::RuntimeException)
3220cdf0e10cSrcweir {
3221cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3222cdf0e10cSrcweir 
3223cdf0e10cSrcweir     uno::Reference< XSTORAGE > xResult;
3224cdf0e10cSrcweir     if ( m_pData->m_pObjectShell.Is() )
3225cdf0e10cSrcweir     {
3226cdf0e10cSrcweir         uno::Reference< embed::XStorage > xStorage = m_pData->m_pObjectShell->GetStorage();
3227cdf0e10cSrcweir         if ( xStorage.is() )
3228cdf0e10cSrcweir         {
3229cdf0e10cSrcweir             try
3230cdf0e10cSrcweir             {
3231cdf0e10cSrcweir                 xResult = xStorage->openStorageElement( aStorageName, nMode );
3232cdf0e10cSrcweir             }
3233cdf0e10cSrcweir             catch ( uno::Exception& )
3234cdf0e10cSrcweir             {
3235cdf0e10cSrcweir             }
3236cdf0e10cSrcweir         }
3237cdf0e10cSrcweir     }
3238cdf0e10cSrcweir 
3239cdf0e10cSrcweir     return xResult;
3240cdf0e10cSrcweir }
3241cdf0e10cSrcweir 
3242cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL SfxBaseModel::getDocumentSubStoragesNames()
3243cdf0e10cSrcweir     throw ( io::IOException,
3244cdf0e10cSrcweir             RuntimeException )
3245cdf0e10cSrcweir {
3246cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3247cdf0e10cSrcweir 
3248cdf0e10cSrcweir     Sequence< ::rtl::OUString > aResult;
3249cdf0e10cSrcweir     sal_Int32 nResultSize = 0;
3250cdf0e10cSrcweir     sal_Bool bSuccess = sal_False;
3251cdf0e10cSrcweir     if ( m_pData->m_pObjectShell.Is() )
3252cdf0e10cSrcweir     {
3253cdf0e10cSrcweir         uno::Reference < embed::XStorage > xStorage = m_pData->m_pObjectShell->GetStorage();
3254cdf0e10cSrcweir         uno::Reference < container::XNameAccess > xAccess( xStorage, uno::UNO_QUERY );
3255cdf0e10cSrcweir         if ( xAccess.is() )
3256cdf0e10cSrcweir         {
3257cdf0e10cSrcweir             Sequence< ::rtl::OUString > aTemp = xAccess->getElementNames();
3258cdf0e10cSrcweir             for ( sal_Int32 n = 0; n < aTemp.getLength(); n++ )
3259cdf0e10cSrcweir             {
3260cdf0e10cSrcweir                 if ( xStorage->isStorageElement( aTemp[n] ) )
3261cdf0e10cSrcweir                 {
3262cdf0e10cSrcweir                     aResult.realloc( ++nResultSize );
3263cdf0e10cSrcweir                     aResult[ nResultSize - 1 ] = aTemp[n];
3264cdf0e10cSrcweir                 }
3265cdf0e10cSrcweir             }
3266cdf0e10cSrcweir 
3267cdf0e10cSrcweir             bSuccess = sal_True;
3268cdf0e10cSrcweir         }
3269cdf0e10cSrcweir     }
3270cdf0e10cSrcweir 
3271cdf0e10cSrcweir     if ( !bSuccess )
3272cdf0e10cSrcweir         throw io::IOException();
3273cdf0e10cSrcweir 
3274cdf0e10cSrcweir        return aResult;
3275cdf0e10cSrcweir }
3276cdf0e10cSrcweir 
3277cdf0e10cSrcweir //____________________________________________________________________________________________________
3278cdf0e10cSrcweir //  XScriptProviderSupplier
3279cdf0e10cSrcweir //____________________________________________________________________________________________________
3280cdf0e10cSrcweir 
3281cdf0e10cSrcweir 
3282cdf0e10cSrcweir uno::Reference< script::provider::XScriptProvider > SAL_CALL SfxBaseModel::getScriptProvider()
3283cdf0e10cSrcweir     throw ( uno::RuntimeException )
3284cdf0e10cSrcweir {
3285cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3286cdf0e10cSrcweir 
3287cdf0e10cSrcweir     uno::Reference< script::provider::XScriptProvider > xScriptProvider;
3288cdf0e10cSrcweir 
3289cdf0e10cSrcweir     ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
3290cdf0e10cSrcweir     Reference< script::provider::XScriptProviderFactory > xScriptProviderFactory(
3291cdf0e10cSrcweir         aContext.getSingleton( "com.sun.star.script.provider.theMasterScriptProviderFactory" ), uno::UNO_QUERY_THROW );
3292cdf0e10cSrcweir 
3293cdf0e10cSrcweir     try
3294cdf0e10cSrcweir     {
3295cdf0e10cSrcweir         Reference< XScriptInvocationContext > xScriptContext( this );
3296cdf0e10cSrcweir         xScriptProvider.set( xScriptProviderFactory->createScriptProvider( makeAny( xScriptContext ) ), uno::UNO_SET_THROW );
3297cdf0e10cSrcweir     }
3298cdf0e10cSrcweir     catch( const uno::RuntimeException& )
3299cdf0e10cSrcweir     {
3300cdf0e10cSrcweir         throw;
3301cdf0e10cSrcweir     }
3302cdf0e10cSrcweir     catch( const lang::IllegalArgumentException& )
3303cdf0e10cSrcweir     {
3304cdf0e10cSrcweir         throw lang::WrappedTargetRuntimeException(
3305cdf0e10cSrcweir             ::rtl::OUString(),
3306cdf0e10cSrcweir             *this,
3307cdf0e10cSrcweir             ::cppu::getCaughtException()
3308cdf0e10cSrcweir         );
3309cdf0e10cSrcweir     }
3310cdf0e10cSrcweir 
3311cdf0e10cSrcweir     return xScriptProvider;
3312cdf0e10cSrcweir }
3313cdf0e10cSrcweir 
3314cdf0e10cSrcweir //____________________________________________________________________________________________________
3315cdf0e10cSrcweir //  XUIConfigurationManagerSupplier
3316cdf0e10cSrcweir //____________________________________________________________________________________________________
3317cdf0e10cSrcweir 
3318cdf0e10cSrcweir rtl::OUString SfxBaseModel::getRuntimeUID() const
3319cdf0e10cSrcweir {
3320cdf0e10cSrcweir     OSL_ENSURE( m_pData->m_sRuntimeUID.getLength() > 0,
3321cdf0e10cSrcweir                 "SfxBaseModel::getRuntimeUID - ID is empty!" );
3322cdf0e10cSrcweir     return m_pData->m_sRuntimeUID;
3323cdf0e10cSrcweir }
3324cdf0e10cSrcweir 
3325cdf0e10cSrcweir sal_Bool SfxBaseModel::hasValidSignatures() const
3326cdf0e10cSrcweir {
3327cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
3328cdf0e10cSrcweir     if ( m_pData->m_pObjectShell.Is() )
3329cdf0e10cSrcweir         return ( m_pData->m_pObjectShell->ImplGetSignatureState( sal_False ) == SIGNATURESTATE_SIGNATURES_OK );
3330cdf0e10cSrcweir     return sal_False;
3331cdf0e10cSrcweir }
3332cdf0e10cSrcweir 
3333cdf0e10cSrcweir static void GetCommandFromSequence( rtl::OUString& rCommand, sal_Int32& nIndex, const uno::Sequence< beans::PropertyValue >& rSeqPropValue )
3334cdf0e10cSrcweir {
3335cdf0e10cSrcweir     rtl::OUString aCommand;
3336cdf0e10cSrcweir     nIndex = -1;
3337cdf0e10cSrcweir 
3338cdf0e10cSrcweir     for ( sal_Int32 i = 0; i < rSeqPropValue.getLength(); i++ )
3339cdf0e10cSrcweir     {
3340cdf0e10cSrcweir         if ( rSeqPropValue[i].Name.equalsAsciiL( "Command", 7 ))
3341cdf0e10cSrcweir         {
3342cdf0e10cSrcweir             rSeqPropValue[i].Value >>= rCommand;
3343cdf0e10cSrcweir             nIndex = i;
3344cdf0e10cSrcweir             return;
3345cdf0e10cSrcweir         }
3346cdf0e10cSrcweir     }
3347cdf0e10cSrcweir }
3348cdf0e10cSrcweir 
3349cdf0e10cSrcweir static void ConvertSlotsToCommands( SfxObjectShell* pDoc, uno::Reference< container::XIndexContainer >& rToolbarDefinition )
3350cdf0e10cSrcweir {
3351cdf0e10cSrcweir     if ( pDoc )
3352cdf0e10cSrcweir     {
3353cdf0e10cSrcweir         Any           aAny;
3354cdf0e10cSrcweir         SfxModule*    pModule( pDoc->GetFactory().GetModule() );
3355cdf0e10cSrcweir         rtl::OUString aSlotCmd( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
3356cdf0e10cSrcweir         rtl::OUString aUnoCmd( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ));
3357cdf0e10cSrcweir         uno::Sequence< beans::PropertyValue > aSeqPropValue;
3358cdf0e10cSrcweir 
3359cdf0e10cSrcweir         for ( sal_Int32 i = 0; i < rToolbarDefinition->getCount(); i++ )
3360cdf0e10cSrcweir         {
3361cdf0e10cSrcweir             sal_Int32 nIndex( -1 );
3362cdf0e10cSrcweir             rtl::OUString aCommand;
3363cdf0e10cSrcweir 
3364cdf0e10cSrcweir             if ( rToolbarDefinition->getByIndex( i ) >>= aSeqPropValue )
3365cdf0e10cSrcweir             {
3366cdf0e10cSrcweir                 GetCommandFromSequence( aCommand, nIndex, aSeqPropValue );
3367cdf0e10cSrcweir                 if ( nIndex >= 0 && ( aCommand.indexOf( aSlotCmd ) == 0 ))
3368cdf0e10cSrcweir                 {
3369cdf0e10cSrcweir                     rtl::OUString aSlot( aCommand.copy( 5 ));
3370cdf0e10cSrcweir 
3371cdf0e10cSrcweir                     // We have to replace the old "slot-Command" with our new ".uno:-Command"
3372cdf0e10cSrcweir                     const SfxSlot* pSlot = pModule->GetSlotPool()->GetSlot( sal_uInt16( aSlot.toInt32() ));
3373cdf0e10cSrcweir                     if ( pSlot )
3374cdf0e10cSrcweir                     {
3375cdf0e10cSrcweir                         rtl::OUStringBuffer aStrBuf( aUnoCmd );
3376cdf0e10cSrcweir                         aStrBuf.appendAscii( pSlot->GetUnoName() );
3377cdf0e10cSrcweir 
3378cdf0e10cSrcweir                         aCommand = aStrBuf.makeStringAndClear();
3379cdf0e10cSrcweir                         aSeqPropValue[nIndex].Value <<= aCommand;
3380cdf0e10cSrcweir                         rToolbarDefinition->replaceByIndex( i, Any( aSeqPropValue ));
3381cdf0e10cSrcweir                     }
3382cdf0e10cSrcweir                 }
3383cdf0e10cSrcweir             }
3384cdf0e10cSrcweir         }
3385cdf0e10cSrcweir     }
3386cdf0e10cSrcweir }
3387cdf0e10cSrcweir 
3388cdf0e10cSrcweir uno::Reference< ui::XUIConfigurationManager > SAL_CALL SfxBaseModel::getUIConfigurationManager()
3389cdf0e10cSrcweir         throw ( uno::RuntimeException )
3390cdf0e10cSrcweir {
3391cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3392cdf0e10cSrcweir 
3393cdf0e10cSrcweir     if ( !m_pData->m_xUIConfigurationManager.is() )
3394cdf0e10cSrcweir     {
3395cdf0e10cSrcweir         uno::Reference< ui::XUIConfigurationManager > xNewUIConfMan(
3396cdf0e10cSrcweir             ::comphelper::getProcessServiceFactory()->createInstance(
3397cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii( "com.sun.star.ui.UIConfigurationManager" )),
3398cdf0e10cSrcweir                 uno::UNO_QUERY );
3399cdf0e10cSrcweir 
3400cdf0e10cSrcweir         Reference< ui::XUIConfigurationStorage > xUIConfigStorage( xNewUIConfMan, uno::UNO_QUERY );
3401cdf0e10cSrcweir         if ( xUIConfigStorage.is() )
3402cdf0e10cSrcweir         {
3403cdf0e10cSrcweir             uno::Reference< XSTORAGE > xConfigStorage;
3404cdf0e10cSrcweir 
3405cdf0e10cSrcweir             rtl::OUString aUIConfigFolderName( RTL_CONSTASCII_USTRINGPARAM( "Configurations2" ));
3406cdf0e10cSrcweir             // First try to open with READWRITE and then READ
3407cdf0e10cSrcweir             xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, embed::ElementModes::READWRITE );
3408cdf0e10cSrcweir             if ( xConfigStorage.is() )
3409cdf0e10cSrcweir             {
3410cdf0e10cSrcweir                 rtl::OUString aMediaTypeProp( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ));
3411cdf0e10cSrcweir                 rtl::OUString aUIConfigMediaType(
3412cdf0e10cSrcweir                         RTL_CONSTASCII_USTRINGPARAM( "application/vnd.sun.xml.ui.configuration" ) );
3413cdf0e10cSrcweir                 rtl::OUString aMediaType;
3414cdf0e10cSrcweir                 uno::Reference< beans::XPropertySet > xPropSet( xConfigStorage, uno::UNO_QUERY );
3415cdf0e10cSrcweir                 Any a = xPropSet->getPropertyValue( aMediaTypeProp );
3416cdf0e10cSrcweir                 if ( !( a >>= aMediaType ) || ( aMediaType.getLength() == 0 ))
3417cdf0e10cSrcweir                 {
3418cdf0e10cSrcweir                     a <<= aUIConfigMediaType;
3419cdf0e10cSrcweir                     xPropSet->setPropertyValue( aMediaTypeProp, a );
3420cdf0e10cSrcweir                 }
3421cdf0e10cSrcweir             }
3422cdf0e10cSrcweir             else
3423cdf0e10cSrcweir                 xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, embed::ElementModes::READ );
3424cdf0e10cSrcweir 
3425cdf0e10cSrcweir             // initialize ui configuration manager with document substorage
3426cdf0e10cSrcweir             xUIConfigStorage->setStorage( xConfigStorage );
3427cdf0e10cSrcweir 
3428cdf0e10cSrcweir             // embedded objects did not support local configuration data until OOo 3.0, so there's nothing to
3429cdf0e10cSrcweir             // migrate
3430cdf0e10cSrcweir             if ( m_pData->m_pObjectShell->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED )
3431cdf0e10cSrcweir             {
3432cdf0e10cSrcweir                 // Import old UI configuration from OOo 1.x
3433cdf0e10cSrcweir                 uno::Reference< XSTORAGE > xOOo1ConfigStorage;
3434cdf0e10cSrcweir                 rtl::OUString         aOOo1UIConfigFolderName( RTL_CONSTASCII_USTRINGPARAM( "Configurations" ));
3435cdf0e10cSrcweir 
3436cdf0e10cSrcweir                 // Try to open with READ
3437cdf0e10cSrcweir                 xOOo1ConfigStorage = getDocumentSubStorage( aOOo1UIConfigFolderName, embed::ElementModes::READ );
3438cdf0e10cSrcweir                 if ( xOOo1ConfigStorage.is() )
3439cdf0e10cSrcweir                 {
3440cdf0e10cSrcweir                     uno::Reference< lang::XMultiServiceFactory > xServiceMgr( ::comphelper::getProcessServiceFactory() );
3441cdf0e10cSrcweir                     uno::Sequence< uno::Reference< container::XIndexContainer > > rToolbars;
3442cdf0e10cSrcweir 
3443cdf0e10cSrcweir                     sal_Bool bImported = framework::UIConfigurationImporterOOo1x::ImportCustomToolbars(
3444cdf0e10cSrcweir                                             xNewUIConfMan, rToolbars, xServiceMgr, xOOo1ConfigStorage );
3445cdf0e10cSrcweir                     if ( bImported )
3446cdf0e10cSrcweir                     {
3447cdf0e10cSrcweir                         SfxObjectShell* pObjShell = SfxBaseModel::GetObjectShell();
3448cdf0e10cSrcweir 
3449cdf0e10cSrcweir                         char aNum[]   = "private:resource/toolbar/custom_OOo1x_0";
3450cdf0e10cSrcweir                         char aTitle[] = "Toolbar 0";
3451cdf0e10cSrcweir                         sal_Int32 nNumIndex = strlen( aNum )-1;
3452cdf0e10cSrcweir                         sal_Int32 nTitleIndex = strlen( aTitle )-1;
3453cdf0e10cSrcweir                         for ( sal_Int32 i = 0; i < rToolbars.getLength(); i++ )
3454cdf0e10cSrcweir                         {
3455cdf0e10cSrcweir                             aNum[nNumIndex]++;
3456cdf0e10cSrcweir                             aTitle[nTitleIndex]++;
3457cdf0e10cSrcweir 
3458cdf0e10cSrcweir                             rtl::OUString aCustomTbxName( RTL_CONSTASCII_USTRINGPARAM( aNum ));
3459cdf0e10cSrcweir                             rtl::OUString aCustomTbxTitle( RTL_CONSTASCII_USTRINGPARAM( aTitle ));
3460cdf0e10cSrcweir 
3461cdf0e10cSrcweir                             uno::Reference< container::XIndexContainer > xToolbar = rToolbars[i];
3462cdf0e10cSrcweir                             ConvertSlotsToCommands( pObjShell, xToolbar );
3463cdf0e10cSrcweir                             if ( !xNewUIConfMan->hasSettings( aCustomTbxName ))
3464cdf0e10cSrcweir                             {
3465cdf0e10cSrcweir                                 // Set UIName for the toolbar with container property
3466cdf0e10cSrcweir                                 uno::Reference< beans::XPropertySet > xPropSet( xToolbar, UNO_QUERY );
3467cdf0e10cSrcweir                                 if ( xPropSet.is() )
3468cdf0e10cSrcweir                                 {
3469cdf0e10cSrcweir                                     try
3470cdf0e10cSrcweir                                     {
3471cdf0e10cSrcweir                                         rtl::OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( "UIName" ));
3472cdf0e10cSrcweir                                         Any           aAny( aCustomTbxTitle );
3473cdf0e10cSrcweir                                         xPropSet->setPropertyValue( aPropName, aAny );
3474cdf0e10cSrcweir                                     }
3475cdf0e10cSrcweir                                     catch ( beans::UnknownPropertyException& )
3476cdf0e10cSrcweir                                     {
3477cdf0e10cSrcweir                                     }
3478cdf0e10cSrcweir                                 }
3479cdf0e10cSrcweir 
3480cdf0e10cSrcweir                                 uno::Reference< container::XIndexAccess > xToolbarData( xToolbar, uno::UNO_QUERY );
3481cdf0e10cSrcweir                                 xNewUIConfMan->insertSettings( aCustomTbxName, xToolbarData );
3482cdf0e10cSrcweir                                 uno::Reference< ui::XUIConfigurationPersistence > xPersist( xNewUIConfMan, uno::UNO_QUERY );
3483cdf0e10cSrcweir                                 xPersist->store();
3484cdf0e10cSrcweir                             }
3485cdf0e10cSrcweir                         }
3486cdf0e10cSrcweir                     }
3487cdf0e10cSrcweir                 }
3488cdf0e10cSrcweir             }
3489cdf0e10cSrcweir         }
3490cdf0e10cSrcweir 
3491cdf0e10cSrcweir         m_pData->m_xUIConfigurationManager = xNewUIConfMan;
3492cdf0e10cSrcweir     }
3493cdf0e10cSrcweir 
3494cdf0e10cSrcweir     return m_pData->m_xUIConfigurationManager;
3495cdf0e10cSrcweir }
3496cdf0e10cSrcweir 
3497cdf0e10cSrcweir //____________________________________________________________________________________________________
3498cdf0e10cSrcweir //  XVisualObject
3499cdf0e10cSrcweir //____________________________________________________________________________________________________
3500cdf0e10cSrcweir 
3501cdf0e10cSrcweir void SAL_CALL SfxBaseModel::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize )
3502cdf0e10cSrcweir         throw ( lang::IllegalArgumentException,
3503cdf0e10cSrcweir                 embed::WrongStateException,
3504cdf0e10cSrcweir                 uno::Exception,
3505cdf0e10cSrcweir                 uno::RuntimeException )
3506cdf0e10cSrcweir {
3507cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3508cdf0e10cSrcweir 
3509cdf0e10cSrcweir     if ( !m_pData->m_pObjectShell.Is() )
3510cdf0e10cSrcweir         throw uno::Exception(); // TODO: error handling
3511cdf0e10cSrcweir 
3512cdf0e10cSrcweir     SfxViewFrame* pViewFrm = SfxViewFrame::GetFirst( m_pData->m_pObjectShell, sal_False );
3513cdf0e10cSrcweir     if ( pViewFrm && m_pData->m_pObjectShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED && !pViewFrm->GetFrame().IsInPlace() )
3514cdf0e10cSrcweir     {
3515cdf0e10cSrcweir         Window* pWindow = VCLUnoHelper::GetWindow( pViewFrm->GetFrame().GetFrameInterface()->getContainerWindow() );
3516cdf0e10cSrcweir         Size aWinSize = pWindow->GetSizePixel();
3517cdf0e10cSrcweir         awt::Size aCurrent = getVisualAreaSize( nAspect );
3518cdf0e10cSrcweir         Size aDiff( aSize.Width-aCurrent.Width, aSize.Height-aCurrent.Height );
3519cdf0e10cSrcweir         Size aWrongDiff = OutputDevice::LogicToLogic( aDiff , m_pData->m_pObjectShell->GetMapUnit(), pWindow->GetMapMode() );
3520cdf0e10cSrcweir         aDiff = pViewFrm->GetViewShell()->GetWindow()->LogicToPixel( aDiff );
3521cdf0e10cSrcweir         aWinSize.Width() += aDiff.Width();
3522cdf0e10cSrcweir         aWinSize.Height() += aDiff.Height();
3523cdf0e10cSrcweir         pWindow->SetSizePixel( aWinSize );
3524cdf0e10cSrcweir     }
3525cdf0e10cSrcweir     else
3526cdf0e10cSrcweir     {
3527cdf0e10cSrcweir         Rectangle aTmpRect = m_pData->m_pObjectShell->GetVisArea( ASPECT_CONTENT );
3528cdf0e10cSrcweir         aTmpRect.SetSize( Size( aSize.Width, aSize.Height ) );
3529cdf0e10cSrcweir         m_pData->m_pObjectShell->SetVisArea( aTmpRect );
3530cdf0e10cSrcweir     }
3531cdf0e10cSrcweir }
3532cdf0e10cSrcweir 
3533cdf0e10cSrcweir awt::Size SAL_CALL SfxBaseModel::getVisualAreaSize( sal_Int64 /*nAspect*/ )
3534cdf0e10cSrcweir         throw ( lang::IllegalArgumentException,
3535cdf0e10cSrcweir                 embed::WrongStateException,
3536cdf0e10cSrcweir                 uno::Exception,
3537cdf0e10cSrcweir                 uno::RuntimeException)
3538cdf0e10cSrcweir {
3539cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3540cdf0e10cSrcweir 
3541cdf0e10cSrcweir     if ( !m_pData->m_pObjectShell.Is() )
3542cdf0e10cSrcweir         throw uno::Exception(); // TODO: error handling
3543cdf0e10cSrcweir 
3544cdf0e10cSrcweir     Rectangle aTmpRect = m_pData->m_pObjectShell->GetVisArea( ASPECT_CONTENT );
3545cdf0e10cSrcweir 
3546cdf0e10cSrcweir #if 0
3547cdf0e10cSrcweir     Window* pWindow = NULL;
3548cdf0e10cSrcweir     SfxViewFrame* pViewFrm = m_pData->m_pObjectShell.Is() ?
3549cdf0e10cSrcweir                                 SfxViewFrame::GetFirst( m_pData->m_pObjectShell, 0, sal_False ) : 0;
3550cdf0e10cSrcweir 
3551cdf0e10cSrcweir     if ( pWindow )
3552cdf0e10cSrcweir     {
3553cdf0e10cSrcweir         MapMode aInternalMapMode( pViewFrm->GetWindow().GetMapMode() );
3554cdf0e10cSrcweir         MapMode aExternalMapMode( m_pData->m_pObjectShell->GetMapUnit() );
3555cdf0e10cSrcweir 
3556cdf0e10cSrcweir         aTmpRect = OutputDevice::LogicToLogic( aTmpRect, aInternalMapMode, aExternalMapMode );
3557cdf0e10cSrcweir     }
3558cdf0e10cSrcweir #endif
3559cdf0e10cSrcweir 
3560cdf0e10cSrcweir     return awt::Size( aTmpRect.GetWidth(), aTmpRect.GetHeight() );
3561cdf0e10cSrcweir }
3562cdf0e10cSrcweir 
3563cdf0e10cSrcweir 
3564cdf0e10cSrcweir sal_Int32 SAL_CALL SfxBaseModel::getMapUnit( sal_Int64 /*nAspect*/ )
3565cdf0e10cSrcweir         throw ( uno::Exception,
3566cdf0e10cSrcweir                 uno::RuntimeException)
3567cdf0e10cSrcweir {
3568cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3569cdf0e10cSrcweir 
3570cdf0e10cSrcweir     if ( !m_pData->m_pObjectShell.Is() )
3571cdf0e10cSrcweir         throw uno::Exception(); // TODO: error handling
3572cdf0e10cSrcweir 
3573cdf0e10cSrcweir     return VCLUnoHelper::VCL2UnoEmbedMapUnit( m_pData->m_pObjectShell->GetMapUnit() );
3574cdf0e10cSrcweir }
3575cdf0e10cSrcweir 
3576cdf0e10cSrcweir embed::VisualRepresentation SAL_CALL SfxBaseModel::getPreferredVisualRepresentation( ::sal_Int64 /*nAspect*/ )
3577cdf0e10cSrcweir         throw ( lang::IllegalArgumentException,
3578cdf0e10cSrcweir                 embed::WrongStateException,
3579cdf0e10cSrcweir                 uno::Exception,
3580cdf0e10cSrcweir                 uno::RuntimeException )
3581cdf0e10cSrcweir {
3582cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3583cdf0e10cSrcweir 
3584cdf0e10cSrcweir     datatransfer::DataFlavor aDataFlavor(
3585cdf0e10cSrcweir             ::rtl::OUString::createFromAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ),
3586cdf0e10cSrcweir             ::rtl::OUString::createFromAscii( "GDIMetaFile" ),
3587cdf0e10cSrcweir             ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) );
3588cdf0e10cSrcweir 
3589cdf0e10cSrcweir     embed::VisualRepresentation aVisualRepresentation;
3590cdf0e10cSrcweir     aVisualRepresentation.Data = getTransferData( aDataFlavor );
3591cdf0e10cSrcweir     aVisualRepresentation.Flavor = aDataFlavor;
3592cdf0e10cSrcweir 
3593cdf0e10cSrcweir     return aVisualRepresentation;
3594cdf0e10cSrcweir }
3595cdf0e10cSrcweir 
3596cdf0e10cSrcweir //____________________________________________________________________________________________________
3597cdf0e10cSrcweir //  XStorageBasedDocument
3598cdf0e10cSrcweir //____________________________________________________________________________________________________
3599cdf0e10cSrcweir 
3600cdf0e10cSrcweir void SAL_CALL SfxBaseModel::loadFromStorage( const uno::Reference< XSTORAGE >& xStorage,
3601cdf0e10cSrcweir                                              const uno::Sequence< beans::PropertyValue >& aMediaDescriptor )
3602cdf0e10cSrcweir     throw ( lang::IllegalArgumentException,
3603cdf0e10cSrcweir             DOUBLEINITIALIZATIONEXCEPTION,
3604cdf0e10cSrcweir             IOEXCEPTION,
3605cdf0e10cSrcweir             EXCEPTION,
3606cdf0e10cSrcweir             uno::RuntimeException )
3607cdf0e10cSrcweir {
3608cdf0e10cSrcweir     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
3609cdf0e10cSrcweir     if ( IsInitialized() )
3610cdf0e10cSrcweir         throw ::com::sun::star::frame::DoubleInitializationException( ::rtl::OUString(), *this );
3611cdf0e10cSrcweir 
3612cdf0e10cSrcweir     // after i36090 is fixed the pool from object shell can be used
3613cdf0e10cSrcweir     // SfxAllItemSet aSet( m_pData->m_pObjectShell->GetPool() );
3614cdf0e10cSrcweir     SfxAllItemSet aSet( SFX_APP()->GetPool() );
3615cdf0e10cSrcweir 
3616cdf0e10cSrcweir     // the BaseURL is part of the ItemSet
3617cdf0e10cSrcweir     SfxMedium* pMedium = new SfxMedium( xStorage, String() );
3618cdf0e10cSrcweir     TransformParameters( SID_OPENDOC, aMediaDescriptor, aSet );
3619cdf0e10cSrcweir     pMedium->GetItemSet()->Put( aSet );
3620cdf0e10cSrcweir 
3621cdf0e10cSrcweir     // allow to use an interactionhandler (if there is one)
3622cdf0e10cSrcweir     pMedium->UseInteractionHandler( sal_True );
3623cdf0e10cSrcweir 
3624cdf0e10cSrcweir     SFX_ITEMSET_ARG( &aSet, pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False);
3625cdf0e10cSrcweir     sal_Bool bTemplate = pTemplateItem && pTemplateItem->GetValue();
3626cdf0e10cSrcweir     m_pData->m_pObjectShell->SetActivateEvent_Impl( bTemplate ? SFX_EVENT_CREATEDOC : SFX_EVENT_OPENDOC );
3627cdf0e10cSrcweir     m_pData->m_pObjectShell->Get_Impl()->bOwnsStorage = sal_False;
3628cdf0e10cSrcweir 
3629cdf0e10cSrcweir     // load document
3630cdf0e10cSrcweir     if ( !m_pData->m_pObjectShell->DoLoad(pMedium) )
3631cdf0e10cSrcweir     {
3632cdf0e10cSrcweir         sal_uInt32 nError = m_pData->m_pObjectShell->GetErrorCode();
3633cdf0e10cSrcweir         throw task::ErrorCodeIOException( ::rtl::OUString(),
3634cdf0e10cSrcweir                                             uno::Reference< uno::XInterface >(),
3635cdf0e10cSrcweir                                             nError ? nError : ERRCODE_IO_CANTREAD );
3636cdf0e10cSrcweir     }
3637cdf0e10cSrcweir }
3638cdf0e10cSrcweir 
3639cdf0e10cSrcweir void SAL_CALL SfxBaseModel::storeToStorage( const uno::Reference< XSTORAGE >& xStorage,
3640cdf0e10cSrcweir                                 const uno::Sequence< beans::PropertyValue >& aMediaDescriptor )
3641cdf0e10cSrcweir     throw ( lang::IllegalArgumentException,
3642cdf0e10cSrcweir             IOEXCEPTION,
3643cdf0e10cSrcweir             EXCEPTION,
3644cdf0e10cSrcweir             uno::RuntimeException )
3645cdf0e10cSrcweir {
3646cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3647cdf0e10cSrcweir 
3648cdf0e10cSrcweir     uno::Reference< XSTORAGE > xResult;
3649cdf0e10cSrcweir     if ( !m_pData->m_pObjectShell.Is() )
3650cdf0e10cSrcweir         throw IOEXCEPTION(); // TODO:
3651cdf0e10cSrcweir 
3652cdf0e10cSrcweir     SfxAllItemSet aSet( m_pData->m_pObjectShell->GetPool() );
3653cdf0e10cSrcweir     TransformParameters( SID_SAVEASDOC, aMediaDescriptor, aSet );
3654cdf0e10cSrcweir 
3655cdf0e10cSrcweir     // TODO/LATER: may be a special URL "private:storage" should be used
3656cdf0e10cSrcweir     SFX_ITEMSET_ARG( &aSet, pItem, SfxStringItem, SID_FILTER_NAME, sal_False );
3657cdf0e10cSrcweir     sal_Int32 nVersion = SOFFICE_FILEFORMAT_CURRENT;
3658cdf0e10cSrcweir     if( pItem )
3659cdf0e10cSrcweir     {
3660cdf0e10cSrcweir         String aFilterName = pItem->GetValue();
3661cdf0e10cSrcweir         const SfxFilter* pFilter = SFX_APP()->GetFilterMatcher().GetFilter4FilterName( aFilterName );
3662cdf0e10cSrcweir         if ( pFilter && pFilter->UsesStorage() )
3663cdf0e10cSrcweir             nVersion = pFilter->GetVersion();
3664cdf0e10cSrcweir     }
3665cdf0e10cSrcweir 
3666cdf0e10cSrcweir     sal_Bool bSuccess = sal_False;
3667cdf0e10cSrcweir     if ( xStorage == m_pData->m_pObjectShell->GetStorage() )
3668cdf0e10cSrcweir     {
3669cdf0e10cSrcweir         // storing to the own storage
3670cdf0e10cSrcweir         bSuccess = m_pData->m_pObjectShell->DoSave();
3671cdf0e10cSrcweir     }
3672cdf0e10cSrcweir     else
3673cdf0e10cSrcweir     {
3674cdf0e10cSrcweir         // TODO/LATER: if the provided storage has some data inside the storing might fail, probably the storage must be truncated
3675cdf0e10cSrcweir         // TODO/LATER: is it possible to have a template here?
3676cdf0e10cSrcweir         m_pData->m_pObjectShell->SetupStorage( xStorage, nVersion, sal_False );
3677cdf0e10cSrcweir 
3678cdf0e10cSrcweir         // BaseURL is part of the ItemSet
3679cdf0e10cSrcweir         SfxMedium aMedium( xStorage, String(), &aSet );
3680cdf0e10cSrcweir         aMedium.CanDisposeStorage_Impl( sal_False );
3681cdf0e10cSrcweir         if ( aMedium.GetFilter() )
3682cdf0e10cSrcweir         {
3683cdf0e10cSrcweir             // storing without a valid filter will often crash
3684cdf0e10cSrcweir             bSuccess = m_pData->m_pObjectShell->DoSaveObjectAs( aMedium, sal_True );
3685cdf0e10cSrcweir             m_pData->m_pObjectShell->DoSaveCompleted( NULL );
3686cdf0e10cSrcweir         }
3687cdf0e10cSrcweir     }
3688cdf0e10cSrcweir 
3689cdf0e10cSrcweir     sal_uInt32 nError = m_pData->m_pObjectShell->GetErrorCode();
3690cdf0e10cSrcweir     m_pData->m_pObjectShell->ResetError();
3691cdf0e10cSrcweir 
3692cdf0e10cSrcweir     // the warnings are currently not transported
3693cdf0e10cSrcweir     if ( !bSuccess )
3694cdf0e10cSrcweir     {
3695cdf0e10cSrcweir         throw task::ErrorCodeIOException( ::rtl::OUString(),
3696cdf0e10cSrcweir                                             uno::Reference< uno::XInterface >(),
3697cdf0e10cSrcweir                                             nError ? nError : ERRCODE_IO_GENERAL );
3698cdf0e10cSrcweir     }
3699cdf0e10cSrcweir }
3700cdf0e10cSrcweir 
3701cdf0e10cSrcweir void SAL_CALL SfxBaseModel::switchToStorage( const uno::Reference< XSTORAGE >& xStorage )
3702cdf0e10cSrcweir         throw ( lang::IllegalArgumentException,
3703cdf0e10cSrcweir                 IOEXCEPTION,
3704cdf0e10cSrcweir                 EXCEPTION,
3705cdf0e10cSrcweir                 uno::RuntimeException )
3706cdf0e10cSrcweir {
3707cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3708cdf0e10cSrcweir 
3709cdf0e10cSrcweir     uno::Reference< XSTORAGE > xResult;
3710cdf0e10cSrcweir     if ( !m_pData->m_pObjectShell.Is() )
3711cdf0e10cSrcweir         throw IOEXCEPTION(); // TODO:
3712cdf0e10cSrcweir 
3713cdf0e10cSrcweir     // the persistence should be switched only if the storage is different
3714cdf0e10cSrcweir     if ( xStorage != m_pData->m_pObjectShell->GetStorage()
3715cdf0e10cSrcweir       && !m_pData->m_pObjectShell->SwitchPersistance( xStorage ) )
3716cdf0e10cSrcweir     {
3717cdf0e10cSrcweir         sal_uInt32 nError = m_pData->m_pObjectShell->GetErrorCode();
3718cdf0e10cSrcweir         throw task::ErrorCodeIOException( ::rtl::OUString(),
3719cdf0e10cSrcweir                                             uno::Reference< uno::XInterface >(),
3720cdf0e10cSrcweir                                             nError ? nError : ERRCODE_IO_GENERAL );
3721cdf0e10cSrcweir     }
3722cdf0e10cSrcweir 
3723cdf0e10cSrcweir     m_pData->m_pObjectShell->Get_Impl()->bOwnsStorage = sal_False;
3724cdf0e10cSrcweir }
3725cdf0e10cSrcweir 
3726cdf0e10cSrcweir uno::Reference< XSTORAGE > SAL_CALL SfxBaseModel::getDocumentStorage()
3727cdf0e10cSrcweir         throw ( IOEXCEPTION,
3728cdf0e10cSrcweir                 EXCEPTION,
3729cdf0e10cSrcweir                 uno::RuntimeException )
3730cdf0e10cSrcweir {
3731cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3732cdf0e10cSrcweir 
3733cdf0e10cSrcweir     uno::Reference< XSTORAGE > xResult;
3734cdf0e10cSrcweir     if ( !m_pData->m_pObjectShell.Is() )
3735cdf0e10cSrcweir         throw IOEXCEPTION(); // TODO
3736cdf0e10cSrcweir 
3737cdf0e10cSrcweir     return m_pData->m_pObjectShell->GetStorage();
3738cdf0e10cSrcweir }
3739cdf0e10cSrcweir 
3740cdf0e10cSrcweir void SAL_CALL SfxBaseModel::addStorageChangeListener(
3741cdf0e10cSrcweir             const uno::Reference< document::XStorageChangeListener >& xListener )
3742cdf0e10cSrcweir         throw ( uno::RuntimeException )
3743cdf0e10cSrcweir {
3744cdf0e10cSrcweir     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
3745cdf0e10cSrcweir 
3746cdf0e10cSrcweir     m_pData->m_aInterfaceContainer.addInterface(
3747cdf0e10cSrcweir                                     ::getCppuType((const uno::Reference< document::XStorageChangeListener >*)0), xListener );
3748cdf0e10cSrcweir }
3749cdf0e10cSrcweir 
3750cdf0e10cSrcweir void SAL_CALL SfxBaseModel::removeStorageChangeListener(
3751cdf0e10cSrcweir             const uno::Reference< document::XStorageChangeListener >& xListener )
3752cdf0e10cSrcweir         throw ( uno::RuntimeException )
3753cdf0e10cSrcweir {
3754cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3755cdf0e10cSrcweir 
3756cdf0e10cSrcweir     m_pData->m_aInterfaceContainer.removeInterface(
3757cdf0e10cSrcweir                                     ::getCppuType((const uno::Reference< document::XStorageChangeListener >*)0), xListener );
3758cdf0e10cSrcweir }
3759cdf0e10cSrcweir 
3760cdf0e10cSrcweir #include "printhelper.hxx"
3761cdf0e10cSrcweir bool SfxBaseModel::impl_getPrintHelper()
3762cdf0e10cSrcweir {
3763cdf0e10cSrcweir     if ( m_pData->m_xPrintable.is() )
3764cdf0e10cSrcweir         return true;
3765cdf0e10cSrcweir     m_pData->m_xPrintable = new SfxPrintHelper();
3766cdf0e10cSrcweir     uno::Reference < lang::XInitialization > xInit( m_pData->m_xPrintable, uno::UNO_QUERY );
3767cdf0e10cSrcweir     uno::Sequence < uno::Any > aValues(1);
3768cdf0e10cSrcweir     aValues[0] <<= uno::Reference < frame::XModel > (static_cast< frame::XModel* >(this), uno::UNO_QUERY );
3769cdf0e10cSrcweir     xInit->initialize( aValues );
3770cdf0e10cSrcweir     uno::Reference < view::XPrintJobBroadcaster > xBrd( m_pData->m_xPrintable, uno::UNO_QUERY );
3771cdf0e10cSrcweir     xBrd->addPrintJobListener( new SfxPrintHelperListener_Impl( m_pData ) );
3772cdf0e10cSrcweir     return true;
3773cdf0e10cSrcweir }
3774cdf0e10cSrcweir 
3775cdf0e10cSrcweir //=============================================================================
3776cdf0e10cSrcweir // css.frame.XModule
3777cdf0e10cSrcweir  void SAL_CALL SfxBaseModel::setIdentifier(const ::rtl::OUString& Identifier)
3778cdf0e10cSrcweir     throw (css::uno::RuntimeException)
3779cdf0e10cSrcweir {
3780cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3781cdf0e10cSrcweir     m_pData->m_sModuleIdentifier = Identifier;
3782cdf0e10cSrcweir }
3783cdf0e10cSrcweir 
3784cdf0e10cSrcweir //=============================================================================
3785cdf0e10cSrcweir // css.frame.XModule
3786cdf0e10cSrcweir  ::rtl::OUString SAL_CALL SfxBaseModel::getIdentifier()
3787cdf0e10cSrcweir     throw (css::uno::RuntimeException)
3788cdf0e10cSrcweir {
3789cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3790cdf0e10cSrcweir     if (m_pData->m_sModuleIdentifier.getLength() > 0)
3791cdf0e10cSrcweir         return m_pData->m_sModuleIdentifier;
3792cdf0e10cSrcweir     if (m_pData->m_pObjectShell)
3793cdf0e10cSrcweir         return m_pData->m_pObjectShell->GetFactory().GetDocumentServiceName();
3794cdf0e10cSrcweir     return ::rtl::OUString();
3795cdf0e10cSrcweir }
3796cdf0e10cSrcweir 
3797cdf0e10cSrcweir //=============================================================================
3798cdf0e10cSrcweir css::uno::Reference< css::frame::XTitle > SfxBaseModel::impl_getTitleHelper ()
3799cdf0e10cSrcweir {
3800cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3801cdf0e10cSrcweir 
3802cdf0e10cSrcweir     if ( ! m_pData->m_xTitleHelper.is ())
3803cdf0e10cSrcweir     {
3804cdf0e10cSrcweir         css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR   = ::comphelper::getProcessServiceFactory ();
3805cdf0e10cSrcweir         css::uno::Reference< css::frame::XUntitledNumbers >    xDesktop(xSMGR->createInstance(SERVICENAME_DESKTOP), css::uno::UNO_QUERY_THROW);
3806cdf0e10cSrcweir         css::uno::Reference< css::frame::XModel >              xThis   (static_cast< css::frame::XModel* >(this), css::uno::UNO_QUERY_THROW);
3807cdf0e10cSrcweir 
3808cdf0e10cSrcweir         ::framework::TitleHelper* pHelper = new ::framework::TitleHelper(xSMGR);
3809cdf0e10cSrcweir         m_pData->m_xTitleHelper = css::uno::Reference< css::frame::XTitle >(static_cast< ::cppu::OWeakObject* >(pHelper), css::uno::UNO_QUERY_THROW);
3810cdf0e10cSrcweir         pHelper->setOwner                   (xThis   );
3811cdf0e10cSrcweir         pHelper->connectWithUntitledNumbers (xDesktop);
3812cdf0e10cSrcweir     }
3813cdf0e10cSrcweir 
3814cdf0e10cSrcweir     return m_pData->m_xTitleHelper;
3815cdf0e10cSrcweir }
3816cdf0e10cSrcweir 
3817cdf0e10cSrcweir //=============================================================================
3818cdf0e10cSrcweir css::uno::Reference< css::frame::XUntitledNumbers > SfxBaseModel::impl_getUntitledHelper ()
3819cdf0e10cSrcweir {
3820cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3821cdf0e10cSrcweir 
3822cdf0e10cSrcweir     if ( ! m_pData->m_xNumberedControllers.is ())
3823cdf0e10cSrcweir     {
3824cdf0e10cSrcweir         css::uno::Reference< css::frame::XModel > xThis   (static_cast< css::frame::XModel* >(this), css::uno::UNO_QUERY_THROW);
3825cdf0e10cSrcweir         ::comphelper::NumberedCollection*         pHelper = new ::comphelper::NumberedCollection();
3826cdf0e10cSrcweir 
3827cdf0e10cSrcweir         m_pData->m_xNumberedControllers = css::uno::Reference< css::frame::XUntitledNumbers >(static_cast< ::cppu::OWeakObject* >(pHelper), css::uno::UNO_QUERY_THROW);
3828cdf0e10cSrcweir 
3829cdf0e10cSrcweir         pHelper->setOwner          (xThis);
3830cdf0e10cSrcweir         pHelper->setUntitledPrefix (::rtl::OUString::createFromAscii(" : "));
3831cdf0e10cSrcweir     }
3832cdf0e10cSrcweir 
3833cdf0e10cSrcweir     return m_pData->m_xNumberedControllers;
3834cdf0e10cSrcweir }
3835cdf0e10cSrcweir 
3836cdf0e10cSrcweir //=============================================================================
3837cdf0e10cSrcweir // css.frame.XTitle
3838cdf0e10cSrcweir ::rtl::OUString SAL_CALL SfxBaseModel::getTitle()
3839cdf0e10cSrcweir     throw (css::uno::RuntimeException)
3840cdf0e10cSrcweir {
3841cdf0e10cSrcweir     // SYNCHRONIZED ->
3842cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3843cdf0e10cSrcweir 
3844cdf0e10cSrcweir     ::rtl::OUString aResult = impl_getTitleHelper()->getTitle ();
3845cdf0e10cSrcweir     if ( !m_pData->m_bExternalTitle && m_pData->m_pObjectShell )
3846cdf0e10cSrcweir     {
3847cdf0e10cSrcweir         SfxMedium* pMedium = m_pData->m_pObjectShell->GetMedium();
3848cdf0e10cSrcweir         if ( pMedium )
3849cdf0e10cSrcweir         {
3850cdf0e10cSrcweir             SFX_ITEMSET_ARG( pMedium->GetItemSet(), pRepairedDocItem, SfxBoolItem, SID_REPAIRPACKAGE, sal_False );
3851cdf0e10cSrcweir             if ( pRepairedDocItem && pRepairedDocItem->GetValue() )
3852cdf0e10cSrcweir                 aResult += String( SfxResId(STR_REPAIREDDOCUMENT) );
3853cdf0e10cSrcweir         }
3854cdf0e10cSrcweir 
3855cdf0e10cSrcweir         if ( m_pData->m_pObjectShell->IsReadOnlyUI() || (pMedium && pMedium->IsReadOnly()) )
3856cdf0e10cSrcweir             aResult += ::rtl::OUString( String( SfxResId(STR_READONLY) ) );
3857cdf0e10cSrcweir         else if ( m_pData->m_pObjectShell->IsDocShared() )
3858cdf0e10cSrcweir             aResult += ::rtl::OUString( String( SfxResId(STR_SHARED) ) );
3859cdf0e10cSrcweir 
3860cdf0e10cSrcweir         if ( m_pData->m_pObjectShell->GetDocumentSignatureState() == SIGNATURESTATE_SIGNATURES_OK )
3861cdf0e10cSrcweir             aResult += String( SfxResId( RID_XMLSEC_DOCUMENTSIGNED ) );
3862cdf0e10cSrcweir     }
3863cdf0e10cSrcweir 
3864cdf0e10cSrcweir     return aResult;
3865cdf0e10cSrcweir }
3866cdf0e10cSrcweir 
3867cdf0e10cSrcweir //=============================================================================
3868cdf0e10cSrcweir // css.frame.XTitle
3869cdf0e10cSrcweir void SAL_CALL SfxBaseModel::setTitle( const ::rtl::OUString& sTitle )
3870cdf0e10cSrcweir     throw (css::uno::RuntimeException)
3871cdf0e10cSrcweir {
3872cdf0e10cSrcweir     // SYNCHRONIZED ->
3873cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3874cdf0e10cSrcweir 
3875cdf0e10cSrcweir     impl_getTitleHelper()->setTitle (sTitle);
3876cdf0e10cSrcweir     m_pData->m_bExternalTitle = sal_True;
3877cdf0e10cSrcweir }
3878cdf0e10cSrcweir 
3879cdf0e10cSrcweir //=============================================================================
3880cdf0e10cSrcweir // css.frame.XTitleChangeBroadcaster
3881cdf0e10cSrcweir void SAL_CALL SfxBaseModel::addTitleChangeListener( const css::uno::Reference< css::frame::XTitleChangeListener >& xListener )
3882cdf0e10cSrcweir     throw (css::uno::RuntimeException)
3883cdf0e10cSrcweir {
3884cdf0e10cSrcweir     // SYNCHRONIZED ->
3885cdf0e10cSrcweir     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
3886cdf0e10cSrcweir 
3887cdf0e10cSrcweir     css::uno::Reference< css::frame::XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper(), css::uno::UNO_QUERY);
3888cdf0e10cSrcweir     if (xBroadcaster.is ())
3889cdf0e10cSrcweir         xBroadcaster->addTitleChangeListener (xListener);
3890cdf0e10cSrcweir }
3891cdf0e10cSrcweir 
3892cdf0e10cSrcweir //=============================================================================
3893cdf0e10cSrcweir // css.frame.XTitleChangeBroadcaster
3894cdf0e10cSrcweir void SAL_CALL SfxBaseModel::removeTitleChangeListener( const css::uno::Reference< css::frame::XTitleChangeListener >& xListener )
3895cdf0e10cSrcweir     throw (css::uno::RuntimeException)
3896cdf0e10cSrcweir {
3897cdf0e10cSrcweir     // SYNCHRONIZED ->
3898cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3899cdf0e10cSrcweir 
3900cdf0e10cSrcweir     css::uno::Reference< css::frame::XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper(), css::uno::UNO_QUERY);
3901cdf0e10cSrcweir     if (xBroadcaster.is ())
3902cdf0e10cSrcweir         xBroadcaster->removeTitleChangeListener (xListener);
3903cdf0e10cSrcweir }
3904cdf0e10cSrcweir 
3905cdf0e10cSrcweir //=============================================================================
3906cdf0e10cSrcweir // css.frame.XUntitledNumbers
3907cdf0e10cSrcweir ::sal_Int32 SAL_CALL SfxBaseModel::leaseNumber( const css::uno::Reference< css::uno::XInterface >& xComponent )
3908cdf0e10cSrcweir     throw (css::lang::IllegalArgumentException,
3909cdf0e10cSrcweir            css::uno::RuntimeException         )
3910cdf0e10cSrcweir {
3911cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3912cdf0e10cSrcweir 
3913cdf0e10cSrcweir     return impl_getUntitledHelper ()->leaseNumber (xComponent);
3914cdf0e10cSrcweir }
3915cdf0e10cSrcweir 
3916cdf0e10cSrcweir //=============================================================================
3917cdf0e10cSrcweir // css.frame.XUntitledNumbers
3918cdf0e10cSrcweir void SAL_CALL SfxBaseModel::releaseNumber( ::sal_Int32 nNumber )
3919cdf0e10cSrcweir     throw (css::lang::IllegalArgumentException,
3920cdf0e10cSrcweir            css::uno::RuntimeException         )
3921cdf0e10cSrcweir {
3922cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3923cdf0e10cSrcweir     impl_getUntitledHelper ()->releaseNumber (nNumber);
3924cdf0e10cSrcweir }
3925cdf0e10cSrcweir 
3926cdf0e10cSrcweir //=============================================================================
3927cdf0e10cSrcweir // css.frame.XUntitledNumbers
3928cdf0e10cSrcweir void SAL_CALL SfxBaseModel::releaseNumberForComponent( const css::uno::Reference< css::uno::XInterface >& xComponent )
3929cdf0e10cSrcweir     throw (css::lang::IllegalArgumentException,
3930cdf0e10cSrcweir            css::uno::RuntimeException         )
3931cdf0e10cSrcweir {
3932cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3933cdf0e10cSrcweir     impl_getUntitledHelper ()->releaseNumberForComponent (xComponent);
3934cdf0e10cSrcweir }
3935cdf0e10cSrcweir 
3936cdf0e10cSrcweir //=============================================================================
3937cdf0e10cSrcweir // css.frame.XUntitledNumbers
3938cdf0e10cSrcweir ::rtl::OUString SAL_CALL SfxBaseModel::getUntitledPrefix()
3939cdf0e10cSrcweir     throw (css::uno::RuntimeException)
3940cdf0e10cSrcweir {
3941cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3942cdf0e10cSrcweir     return impl_getUntitledHelper ()->getUntitledPrefix ();
3943cdf0e10cSrcweir }
3944cdf0e10cSrcweir 
3945cdf0e10cSrcweir //=============================================================================
3946cdf0e10cSrcweir // css::frame::XModel2
3947cdf0e10cSrcweir css::uno::Reference< css::container::XEnumeration > SAL_CALL SfxBaseModel::getControllers()
3948cdf0e10cSrcweir     throw (css::uno::RuntimeException)
3949cdf0e10cSrcweir {
3950cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3951cdf0e10cSrcweir 
3952cdf0e10cSrcweir     sal_Int32 c = m_pData->m_seqControllers.getLength();
3953cdf0e10cSrcweir     sal_Int32 i = 0;
3954cdf0e10cSrcweir     css::uno::Sequence< css::uno::Any > lEnum(c);
3955cdf0e10cSrcweir     for (i=0; i<c; ++i)
3956cdf0e10cSrcweir         lEnum[i] <<= m_pData->m_seqControllers[i];
3957cdf0e10cSrcweir 
3958cdf0e10cSrcweir     ::comphelper::OAnyEnumeration*                      pEnum = new ::comphelper::OAnyEnumeration(lEnum);
3959cdf0e10cSrcweir     css::uno::Reference< css::container::XEnumeration > xEnum(static_cast< css::container::XEnumeration* >(pEnum), css::uno::UNO_QUERY_THROW);
3960cdf0e10cSrcweir     return xEnum;
3961cdf0e10cSrcweir }
3962cdf0e10cSrcweir 
3963cdf0e10cSrcweir //=============================================================================
3964cdf0e10cSrcweir // css::frame::XModel2
3965cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > SAL_CALL SfxBaseModel::getAvailableViewControllerNames()
3966cdf0e10cSrcweir     throw (css::uno::RuntimeException)
3967cdf0e10cSrcweir {
3968cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3969cdf0e10cSrcweir 
3970cdf0e10cSrcweir     const SfxObjectFactory& rDocumentFactory = GetObjectShell()->GetFactory();
3971cdf0e10cSrcweir     const sal_Int32 nViewFactoryCount = rDocumentFactory.GetViewFactoryCount();
3972cdf0e10cSrcweir 
3973cdf0e10cSrcweir     Sequence< ::rtl::OUString > aViewNames( nViewFactoryCount );
3974cdf0e10cSrcweir     for ( sal_Int32 nViewNo = 0; nViewNo < nViewFactoryCount; ++nViewNo )
3975cdf0e10cSrcweir         aViewNames[nViewNo] = rDocumentFactory.GetViewFactory( nViewNo ).GetAPIViewName();
3976cdf0e10cSrcweir     return aViewNames;
3977cdf0e10cSrcweir }
3978cdf0e10cSrcweir 
3979cdf0e10cSrcweir //=============================================================================
3980cdf0e10cSrcweir // css::frame::XModel2
3981cdf0e10cSrcweir css::uno::Reference< css::frame::XController2 > SAL_CALL SfxBaseModel::createDefaultViewController( const css::uno::Reference< css::frame::XFrame >& i_rFrame )
3982cdf0e10cSrcweir     throw (css::uno::RuntimeException         ,
3983cdf0e10cSrcweir            css::lang::IllegalArgumentException,
3984cdf0e10cSrcweir            css::uno::Exception                )
3985cdf0e10cSrcweir {
3986cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
3987cdf0e10cSrcweir 
3988cdf0e10cSrcweir     const SfxObjectFactory& rDocumentFactory = GetObjectShell()->GetFactory();
3989cdf0e10cSrcweir     const ::rtl::OUString sDefaultViewName = rDocumentFactory.GetViewFactory( 0 ).GetAPIViewName();
3990cdf0e10cSrcweir 
3991cdf0e10cSrcweir     aGuard.clear();
3992cdf0e10cSrcweir 
3993cdf0e10cSrcweir     return createViewController( sDefaultViewName, Sequence< PropertyValue >(), i_rFrame );
3994cdf0e10cSrcweir }
3995cdf0e10cSrcweir 
3996cdf0e10cSrcweir //=============================================================================
3997cdf0e10cSrcweir namespace sfx { namespace intern {
3998cdf0e10cSrcweir 
3999cdf0e10cSrcweir     /** a class which, in its dtor, cleans up variuos objects (well, at the moment only the frame) collected during
4000cdf0e10cSrcweir         the creation of a document view, unless the creation was successful.
4001cdf0e10cSrcweir     */
4002cdf0e10cSrcweir     class SAL_DLLPRIVATE ViewCreationGuard
4003cdf0e10cSrcweir     {
4004cdf0e10cSrcweir     public:
4005cdf0e10cSrcweir         ViewCreationGuard()
4006cdf0e10cSrcweir             :m_bSuccess( false )
4007cdf0e10cSrcweir         {
4008cdf0e10cSrcweir         }
4009cdf0e10cSrcweir 
4010cdf0e10cSrcweir         ~ViewCreationGuard()
4011cdf0e10cSrcweir         {
4012cdf0e10cSrcweir             if ( !m_bSuccess )
4013cdf0e10cSrcweir                 impl_closeAll();
4014cdf0e10cSrcweir         }
4015cdf0e10cSrcweir 
4016cdf0e10cSrcweir         void takeFrameOwnership( SfxFrame* i_pFrame )
4017cdf0e10cSrcweir         {
4018cdf0e10cSrcweir             OSL_PRECOND( !m_aWeakFrame, "ViewCreationGuard::takeFrameOwnership: already have a frame!" );
4019cdf0e10cSrcweir             OSL_PRECOND( i_pFrame != NULL, "ViewCreationGuard::takeFrameOwnership: invalid frame!" );
4020cdf0e10cSrcweir             m_aWeakFrame = i_pFrame;
4021cdf0e10cSrcweir         }
4022cdf0e10cSrcweir 
4023cdf0e10cSrcweir         void    releaseAll()
4024cdf0e10cSrcweir         {
4025cdf0e10cSrcweir             m_bSuccess = true;
4026cdf0e10cSrcweir         }
4027cdf0e10cSrcweir 
4028cdf0e10cSrcweir     private:
4029cdf0e10cSrcweir         void impl_closeAll()
4030cdf0e10cSrcweir         {
4031cdf0e10cSrcweir             if ( m_aWeakFrame && !m_aWeakFrame->GetCurrentDocument() )
4032cdf0e10cSrcweir             {
4033cdf0e10cSrcweir                 m_aWeakFrame->SetFrameInterface_Impl( NULL );
4034cdf0e10cSrcweir                 m_aWeakFrame->DoClose();
4035cdf0e10cSrcweir             }
4036cdf0e10cSrcweir         }
4037cdf0e10cSrcweir 
4038cdf0e10cSrcweir     private:
4039cdf0e10cSrcweir         bool            m_bSuccess;
4040cdf0e10cSrcweir         SfxFrameWeak    m_aWeakFrame;
4041cdf0e10cSrcweir     };
4042cdf0e10cSrcweir } }
4043cdf0e10cSrcweir 
4044cdf0e10cSrcweir //=============================================================================
4045cdf0e10cSrcweir SfxViewFrame* SfxBaseModel::FindOrCreateViewFrame_Impl( const Reference< XFrame >& i_rFrame, ::sfx::intern::ViewCreationGuard& i_rGuard ) const
4046cdf0e10cSrcweir {
4047cdf0e10cSrcweir     SfxViewFrame* pViewFrame = NULL;
4048cdf0e10cSrcweir     for (   pViewFrame = SfxViewFrame::GetFirst( GetObjectShell(), sal_False );
4049cdf0e10cSrcweir             pViewFrame;
4050cdf0e10cSrcweir             pViewFrame= SfxViewFrame::GetNext( *pViewFrame, GetObjectShell(), sal_False )
4051cdf0e10cSrcweir         )
4052cdf0e10cSrcweir     {
4053cdf0e10cSrcweir         if ( pViewFrame->GetFrame().GetFrameInterface() == i_rFrame )
4054cdf0e10cSrcweir             break;
4055cdf0e10cSrcweir     }
4056cdf0e10cSrcweir     if ( !pViewFrame )
4057cdf0e10cSrcweir     {
4058cdf0e10cSrcweir     #if OSL_DEBUG_LEVEL > 0
4059cdf0e10cSrcweir         for (   SfxFrame* pCheckFrame = SfxFrame::GetFirst();
4060cdf0e10cSrcweir                 pCheckFrame;
4061cdf0e10cSrcweir                 pCheckFrame = SfxFrame::GetNext( *pCheckFrame )
4062cdf0e10cSrcweir              )
4063cdf0e10cSrcweir         {
4064cdf0e10cSrcweir             if ( pCheckFrame->GetFrameInterface() == i_rFrame )
4065cdf0e10cSrcweir             {
4066cdf0e10cSrcweir                 if  (   ( pCheckFrame->GetCurrentViewFrame() != NULL )
4067cdf0e10cSrcweir                     ||  ( pCheckFrame->GetCurrentDocument() != NULL )
4068cdf0e10cSrcweir                     )
4069cdf0e10cSrcweir                     // Note that it is perfectly letgitimate that during loading into an XFrame which already contains
4070cdf0e10cSrcweir                     // a document, there exist two SfxFrame instances bound to this XFrame - the old one, which will be
4071cdf0e10cSrcweir                     // destroyed later, and the new one, which we're going to create
4072cdf0e10cSrcweir                     continue;
4073cdf0e10cSrcweir 
4074cdf0e10cSrcweir                 OSL_ENSURE( false, "SfxBaseModel::FindOrCreateViewFrame_Impl: there already is an SfxFrame for the given XFrame, but no view in it!" );
4075cdf0e10cSrcweir                     // nowadays, we're the only instance allowed to create an SfxFrame for an XFrame, so this case here should not happen
4076cdf0e10cSrcweir                 break;
4077cdf0e10cSrcweir             }
4078cdf0e10cSrcweir         }
4079cdf0e10cSrcweir     #endif
4080cdf0e10cSrcweir 
4081cdf0e10cSrcweir         SfxFrame* pTargetFrame = SfxFrame::Create( i_rFrame );
4082cdf0e10cSrcweir         ENSURE_OR_THROW( pTargetFrame, "could not create an SfxFrame" );
4083cdf0e10cSrcweir         i_rGuard.takeFrameOwnership( pTargetFrame );
4084cdf0e10cSrcweir 
4085cdf0e10cSrcweir         // prepare it
4086cdf0e10cSrcweir         pTargetFrame->PrepareForDoc_Impl( *GetObjectShell() );
4087cdf0e10cSrcweir 
4088cdf0e10cSrcweir         // create view frame
4089cdf0e10cSrcweir         pViewFrame = new SfxViewFrame( *pTargetFrame, GetObjectShell() );
4090cdf0e10cSrcweir     }
4091cdf0e10cSrcweir     return pViewFrame;
4092cdf0e10cSrcweir }
4093cdf0e10cSrcweir 
4094cdf0e10cSrcweir //=============================================================================
4095cdf0e10cSrcweir // css::frame::XModel2
4096cdf0e10cSrcweir css::uno::Reference< css::frame::XController2 > SAL_CALL SfxBaseModel::createViewController(
4097cdf0e10cSrcweir         const ::rtl::OUString& i_rViewName, const Sequence< PropertyValue >& i_rArguments, const Reference< XFrame >& i_rFrame )
4098cdf0e10cSrcweir     throw (css::uno::RuntimeException         ,
4099cdf0e10cSrcweir            css::lang::IllegalArgumentException,
4100cdf0e10cSrcweir            css::uno::Exception                )
4101cdf0e10cSrcweir {
4102cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4103cdf0e10cSrcweir 
4104cdf0e10cSrcweir     if ( !i_rFrame.is() )
4105cdf0e10cSrcweir         throw css::lang::IllegalArgumentException( ::rtl::OUString(), *this, 3 );
4106cdf0e10cSrcweir 
4107cdf0e10cSrcweir     // find the proper SFX view factory
4108cdf0e10cSrcweir     SfxViewFactory* pViewFactory = GetObjectShell()->GetFactory().GetViewFactoryByViewName( i_rViewName );
4109cdf0e10cSrcweir     if ( !pViewFactory )
4110cdf0e10cSrcweir         throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
4111cdf0e10cSrcweir 
4112cdf0e10cSrcweir     // determine previous shell (used in some special cases)
4113cdf0e10cSrcweir     Reference< XController > xPreviousController( i_rFrame->getController() );
4114cdf0e10cSrcweir     const Reference< XModel > xMe( this );
4115cdf0e10cSrcweir     if  (   ( xPreviousController.is() )
4116cdf0e10cSrcweir         &&  ( xMe != xPreviousController->getModel() )
4117cdf0e10cSrcweir         )
4118cdf0e10cSrcweir     {
4119cdf0e10cSrcweir         xPreviousController.clear();
4120cdf0e10cSrcweir     }
4121cdf0e10cSrcweir     SfxViewShell* pOldViewShell = SfxViewShell::Get( xPreviousController );
4122cdf0e10cSrcweir     OSL_ENSURE( !xPreviousController.is() || ( pOldViewShell != NULL ),
4123cdf0e10cSrcweir         "SfxBaseModel::createViewController: invalid old controller!" );
4124cdf0e10cSrcweir 
4125cdf0e10cSrcweir     // a guard which will clean up in case of failure
4126cdf0e10cSrcweir     ::sfx::intern::ViewCreationGuard aViewCreationGuard;
4127cdf0e10cSrcweir 
4128cdf0e10cSrcweir     // determine the ViewFrame belonging to the given XFrame
4129cdf0e10cSrcweir     SfxViewFrame* pViewFrame = FindOrCreateViewFrame_Impl( i_rFrame, aViewCreationGuard );
4130cdf0e10cSrcweir     OSL_POSTCOND( pViewFrame, "SfxBaseModel::createViewController: no frame?" );
4131cdf0e10cSrcweir 
4132cdf0e10cSrcweir     // delegate to SFX' view factory
4133cdf0e10cSrcweir     pViewFrame->GetBindings().ENTERREGISTRATIONS();
4134cdf0e10cSrcweir     SfxViewShell* pViewShell = pViewFactory->CreateInstance( pViewFrame, pOldViewShell );
4135cdf0e10cSrcweir     pViewFrame->GetBindings().LEAVEREGISTRATIONS();
4136cdf0e10cSrcweir     ENSURE_OR_THROW( pViewShell, "invalid view shell provided by factory" );
4137cdf0e10cSrcweir 
4138cdf0e10cSrcweir     // by setting the ViewShell it is prevented that disposing the Controller will destroy this ViewFrame also
4139cdf0e10cSrcweir     pViewFrame->GetDispatcher()->SetDisableFlags( 0 );
4140cdf0e10cSrcweir     pViewFrame->SetViewShell_Impl( pViewShell );
4141cdf0e10cSrcweir 
4142cdf0e10cSrcweir     // remember ViewID
4143cdf0e10cSrcweir     pViewFrame->SetCurViewId_Impl( pViewFactory->GetOrdinal() );
4144cdf0e10cSrcweir 
4145cdf0e10cSrcweir     // ensure a default controller, if the view shell did not provide an own implementation
4146cdf0e10cSrcweir     if ( !pViewShell->GetController().is() )
4147cdf0e10cSrcweir         pViewShell->SetController( new SfxBaseController( pViewShell ) );
4148cdf0e10cSrcweir 
4149cdf0e10cSrcweir     // pass the creation arguments to the controller
4150cdf0e10cSrcweir     SfxBaseController* pBaseController = pViewShell->GetBaseController_Impl();
4151cdf0e10cSrcweir     ENSURE_OR_THROW( pBaseController, "invalid controller implementation!" );
4152cdf0e10cSrcweir     pBaseController->SetCreationArguments_Impl( i_rArguments );
4153cdf0e10cSrcweir 
4154cdf0e10cSrcweir     // some initial view settings, coming from our most recent attachResource call
4155cdf0e10cSrcweir     ::comphelper::NamedValueCollection aDocumentLoadArgs( getArgs() );
4156cdf0e10cSrcweir     if ( aDocumentLoadArgs.getOrDefault( "ViewOnly", false ) )
4157cdf0e10cSrcweir         pViewFrame->GetFrame().SetMenuBarOn_Impl( sal_False );
4158cdf0e10cSrcweir 
4159cdf0e10cSrcweir     const sal_Int16 nPluginMode = aDocumentLoadArgs.getOrDefault( "PluginMode", sal_Int16( 0 ) );
4160cdf0e10cSrcweir     if ( nPluginMode == 1 )
4161cdf0e10cSrcweir     {
4162cdf0e10cSrcweir         pViewFrame->ForceOuterResize_Impl( sal_False );
4163cdf0e10cSrcweir         pViewFrame->GetBindings().HidePopups( sal_True );
4164cdf0e10cSrcweir 
4165cdf0e10cSrcweir         SfxFrame& rFrame = pViewFrame->GetFrame();
4166cdf0e10cSrcweir         // MBA: layoutmanager of inplace frame starts locked and invisible
4167cdf0e10cSrcweir         rFrame.GetWorkWindow_Impl()->MakeVisible_Impl( sal_False );
4168cdf0e10cSrcweir         rFrame.GetWorkWindow_Impl()->Lock_Impl( sal_True );
4169cdf0e10cSrcweir 
4170cdf0e10cSrcweir         rFrame.GetWindow().SetBorderStyle( WINDOW_BORDER_NOBORDER );
4171cdf0e10cSrcweir         pViewFrame->GetWindow().SetBorderStyle( WINDOW_BORDER_NOBORDER );
4172cdf0e10cSrcweir     }
4173cdf0e10cSrcweir 
4174cdf0e10cSrcweir     // tell the guard we were successful
4175cdf0e10cSrcweir     aViewCreationGuard.releaseAll();
4176cdf0e10cSrcweir 
4177cdf0e10cSrcweir     // outta gere
4178cdf0e10cSrcweir     return pBaseController;
4179cdf0e10cSrcweir }
4180cdf0e10cSrcweir 
4181cdf0e10cSrcweir //=============================================================================
4182cdf0e10cSrcweir // RDF DocumentMetadataAccess
4183cdf0e10cSrcweir 
4184cdf0e10cSrcweir // ::com::sun::star::rdf::XRepositorySupplier:
4185cdf0e10cSrcweir uno::Reference< rdf::XRepository > SAL_CALL
4186cdf0e10cSrcweir SfxBaseModel::getRDFRepository() throw (uno::RuntimeException)
4187cdf0e10cSrcweir {
4188cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4189cdf0e10cSrcweir 
4190cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4191cdf0e10cSrcweir     if (!xDMA.is()) {
4192cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4193cdf0e10cSrcweir             "model has no document metadata"), *this );
4194cdf0e10cSrcweir     }
4195cdf0e10cSrcweir 
4196cdf0e10cSrcweir     return xDMA->getRDFRepository();
4197cdf0e10cSrcweir }
4198cdf0e10cSrcweir 
4199cdf0e10cSrcweir // ::com::sun::star::rdf::XNode:
4200cdf0e10cSrcweir ::rtl::OUString SAL_CALL
4201cdf0e10cSrcweir SfxBaseModel::getStringValue() throw (uno::RuntimeException)
4202cdf0e10cSrcweir {
4203cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4204cdf0e10cSrcweir 
4205cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4206cdf0e10cSrcweir     if (!xDMA.is()) {
4207cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4208cdf0e10cSrcweir             "model has no document metadata"), *this );
4209cdf0e10cSrcweir     }
4210cdf0e10cSrcweir 
4211cdf0e10cSrcweir     return xDMA->getStringValue();
4212cdf0e10cSrcweir }
4213cdf0e10cSrcweir 
4214cdf0e10cSrcweir // ::com::sun::star::rdf::XURI:
4215cdf0e10cSrcweir ::rtl::OUString SAL_CALL
4216cdf0e10cSrcweir SfxBaseModel::getNamespace() throw (uno::RuntimeException)
4217cdf0e10cSrcweir {
4218cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4219cdf0e10cSrcweir 
4220cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4221cdf0e10cSrcweir     if (!xDMA.is()) {
4222cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4223cdf0e10cSrcweir             "model has no document metadata"), *this );
4224cdf0e10cSrcweir     }
4225cdf0e10cSrcweir 
4226cdf0e10cSrcweir     return xDMA->getNamespace();
4227cdf0e10cSrcweir }
4228cdf0e10cSrcweir 
4229cdf0e10cSrcweir ::rtl::OUString SAL_CALL
4230cdf0e10cSrcweir SfxBaseModel::getLocalName() throw (uno::RuntimeException)
4231cdf0e10cSrcweir {
4232cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4233cdf0e10cSrcweir 
4234cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4235cdf0e10cSrcweir     if (!xDMA.is()) {
4236cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4237cdf0e10cSrcweir             "model has no document metadata"), *this );
4238cdf0e10cSrcweir     }
4239cdf0e10cSrcweir 
4240cdf0e10cSrcweir     return xDMA->getLocalName();
4241cdf0e10cSrcweir }
4242cdf0e10cSrcweir 
4243cdf0e10cSrcweir // ::com::sun::star::rdf::XDocumentMetadataAccess:
4244cdf0e10cSrcweir uno::Reference< rdf::XMetadatable > SAL_CALL
4245cdf0e10cSrcweir SfxBaseModel::getElementByMetadataReference(
4246cdf0e10cSrcweir     const ::com::sun::star::beans::StringPair & i_rReference)
4247cdf0e10cSrcweir throw (uno::RuntimeException)
4248cdf0e10cSrcweir {
4249cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4250cdf0e10cSrcweir 
4251cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4252cdf0e10cSrcweir     if (!xDMA.is()) {
4253cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4254cdf0e10cSrcweir             "model has no document metadata"), *this );
4255cdf0e10cSrcweir     }
4256cdf0e10cSrcweir 
4257cdf0e10cSrcweir     return xDMA->getElementByMetadataReference(i_rReference);
4258cdf0e10cSrcweir }
4259cdf0e10cSrcweir 
4260cdf0e10cSrcweir uno::Reference< rdf::XMetadatable > SAL_CALL
4261cdf0e10cSrcweir SfxBaseModel::getElementByURI(const uno::Reference< rdf::XURI > & i_xURI)
4262cdf0e10cSrcweir throw (uno::RuntimeException, lang::IllegalArgumentException)
4263cdf0e10cSrcweir {
4264cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4265cdf0e10cSrcweir 
4266cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4267cdf0e10cSrcweir     if (!xDMA.is()) {
4268cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4269cdf0e10cSrcweir             "model has no document metadata"), *this );
4270cdf0e10cSrcweir     }
4271cdf0e10cSrcweir 
4272cdf0e10cSrcweir     return xDMA->getElementByURI(i_xURI);
4273cdf0e10cSrcweir }
4274cdf0e10cSrcweir 
4275cdf0e10cSrcweir uno::Sequence< uno::Reference< rdf::XURI > > SAL_CALL
4276cdf0e10cSrcweir SfxBaseModel::getMetadataGraphsWithType(
4277cdf0e10cSrcweir     const uno::Reference<rdf::XURI> & i_xType)
4278cdf0e10cSrcweir throw (uno::RuntimeException, lang::IllegalArgumentException)
4279cdf0e10cSrcweir {
4280cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4281cdf0e10cSrcweir 
4282cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4283cdf0e10cSrcweir     if (!xDMA.is()) {
4284cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4285cdf0e10cSrcweir             "model has no document metadata"), *this );
4286cdf0e10cSrcweir     }
4287cdf0e10cSrcweir 
4288cdf0e10cSrcweir     return xDMA->getMetadataGraphsWithType(i_xType);
4289cdf0e10cSrcweir }
4290cdf0e10cSrcweir 
4291cdf0e10cSrcweir uno::Reference<rdf::XURI> SAL_CALL
4292cdf0e10cSrcweir SfxBaseModel::addMetadataFile(const ::rtl::OUString & i_rFileName,
4293cdf0e10cSrcweir     const uno::Sequence < uno::Reference< rdf::XURI > > & i_rTypes)
4294cdf0e10cSrcweir throw (uno::RuntimeException, lang::IllegalArgumentException,
4295cdf0e10cSrcweir     container::ElementExistException)
4296cdf0e10cSrcweir {
4297cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4298cdf0e10cSrcweir 
4299cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4300cdf0e10cSrcweir     if (!xDMA.is()) {
4301cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4302cdf0e10cSrcweir             "model has no document metadata"), *this );
4303cdf0e10cSrcweir     }
4304cdf0e10cSrcweir 
4305cdf0e10cSrcweir     return xDMA->addMetadataFile(i_rFileName, i_rTypes);
4306cdf0e10cSrcweir }
4307cdf0e10cSrcweir 
4308cdf0e10cSrcweir uno::Reference<rdf::XURI> SAL_CALL
4309cdf0e10cSrcweir SfxBaseModel::importMetadataFile(::sal_Int16 i_Format,
4310cdf0e10cSrcweir     const uno::Reference< io::XInputStream > & i_xInStream,
4311cdf0e10cSrcweir     const ::rtl::OUString & i_rFileName,
4312cdf0e10cSrcweir     const uno::Reference< rdf::XURI > & i_xBaseURI,
4313cdf0e10cSrcweir     const uno::Sequence < uno::Reference< rdf::XURI > > & i_rTypes)
4314cdf0e10cSrcweir throw (uno::RuntimeException, lang::IllegalArgumentException,
4315cdf0e10cSrcweir     datatransfer::UnsupportedFlavorException,
4316cdf0e10cSrcweir     container::ElementExistException, rdf::ParseException, io::IOException)
4317cdf0e10cSrcweir {
4318cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4319cdf0e10cSrcweir 
4320cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4321cdf0e10cSrcweir     if (!xDMA.is()) {
4322cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4323cdf0e10cSrcweir             "model has no document metadata"), *this );
4324cdf0e10cSrcweir     }
4325cdf0e10cSrcweir 
4326cdf0e10cSrcweir     return xDMA->importMetadataFile(i_Format,
4327cdf0e10cSrcweir         i_xInStream, i_rFileName, i_xBaseURI, i_rTypes);
4328cdf0e10cSrcweir }
4329cdf0e10cSrcweir 
4330cdf0e10cSrcweir void SAL_CALL
4331cdf0e10cSrcweir SfxBaseModel::removeMetadataFile(
4332cdf0e10cSrcweir     const uno::Reference< rdf::XURI > & i_xGraphName)
4333cdf0e10cSrcweir throw (uno::RuntimeException, lang::IllegalArgumentException,
4334cdf0e10cSrcweir     container::NoSuchElementException)
4335cdf0e10cSrcweir {
4336cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4337cdf0e10cSrcweir 
4338cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4339cdf0e10cSrcweir     if (!xDMA.is()) {
4340cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4341cdf0e10cSrcweir             "model has no document metadata"), *this );
4342cdf0e10cSrcweir     }
4343cdf0e10cSrcweir 
4344cdf0e10cSrcweir     return xDMA->removeMetadataFile(i_xGraphName);
4345cdf0e10cSrcweir }
4346cdf0e10cSrcweir 
4347cdf0e10cSrcweir void SAL_CALL
4348cdf0e10cSrcweir SfxBaseModel::addContentOrStylesFile(const ::rtl::OUString & i_rFileName)
4349cdf0e10cSrcweir throw (uno::RuntimeException, lang::IllegalArgumentException,
4350cdf0e10cSrcweir     container::ElementExistException)
4351cdf0e10cSrcweir {
4352cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4353cdf0e10cSrcweir 
4354cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4355cdf0e10cSrcweir     if (!xDMA.is()) {
4356cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4357cdf0e10cSrcweir             "model has no document metadata"), *this );
4358cdf0e10cSrcweir     }
4359cdf0e10cSrcweir 
4360cdf0e10cSrcweir     return xDMA->addContentOrStylesFile(i_rFileName);
4361cdf0e10cSrcweir }
4362cdf0e10cSrcweir 
4363cdf0e10cSrcweir void SAL_CALL
4364cdf0e10cSrcweir SfxBaseModel::removeContentOrStylesFile(const ::rtl::OUString & i_rFileName)
4365cdf0e10cSrcweir throw (uno::RuntimeException, lang::IllegalArgumentException,
4366cdf0e10cSrcweir     container::NoSuchElementException)
4367cdf0e10cSrcweir {
4368cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4369cdf0e10cSrcweir 
4370cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4371cdf0e10cSrcweir     if (!xDMA.is()) {
4372cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4373cdf0e10cSrcweir             "model has no document metadata"), *this );
4374cdf0e10cSrcweir     }
4375cdf0e10cSrcweir 
4376cdf0e10cSrcweir     return xDMA->removeContentOrStylesFile(i_rFileName);
4377cdf0e10cSrcweir }
4378cdf0e10cSrcweir 
4379cdf0e10cSrcweir void SAL_CALL
4380cdf0e10cSrcweir SfxBaseModel::loadMetadataFromStorage(
4381cdf0e10cSrcweir     uno::Reference< embed::XStorage > const & i_xStorage,
4382cdf0e10cSrcweir     uno::Reference<rdf::XURI> const & i_xBaseURI,
4383cdf0e10cSrcweir     uno::Reference<task::XInteractionHandler> const & i_xHandler)
4384cdf0e10cSrcweir throw (uno::RuntimeException, lang::IllegalArgumentException,
4385cdf0e10cSrcweir     lang::WrappedTargetException)
4386cdf0e10cSrcweir {
4387cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4388cdf0e10cSrcweir 
4389cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(
4390cdf0e10cSrcweir         m_pData->CreateDMAUninitialized());
4391cdf0e10cSrcweir     if (!xDMA.is()) {
4392cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4393cdf0e10cSrcweir             "model has no document metadata"), *this );
4394cdf0e10cSrcweir     }
4395cdf0e10cSrcweir 
4396cdf0e10cSrcweir     try {
4397cdf0e10cSrcweir         xDMA->loadMetadataFromStorage(i_xStorage, i_xBaseURI, i_xHandler);
4398cdf0e10cSrcweir     } catch (lang::IllegalArgumentException &) {
4399cdf0e10cSrcweir         throw; // not initialized
4400cdf0e10cSrcweir     } catch (uno::Exception &) {
4401cdf0e10cSrcweir         // UGLY: if it's a RuntimeException, we can't be sure DMA is initialzed
4402cdf0e10cSrcweir         m_pData->m_xDocumentMetadata = xDMA;
4403cdf0e10cSrcweir         throw;
4404cdf0e10cSrcweir     }
4405cdf0e10cSrcweir     m_pData->m_xDocumentMetadata = xDMA;
4406cdf0e10cSrcweir 
4407cdf0e10cSrcweir }
4408cdf0e10cSrcweir 
4409cdf0e10cSrcweir void SAL_CALL
4410cdf0e10cSrcweir SfxBaseModel::storeMetadataToStorage(
4411cdf0e10cSrcweir     uno::Reference< embed::XStorage > const & i_xStorage)
4412cdf0e10cSrcweir throw (uno::RuntimeException, lang::IllegalArgumentException,
4413cdf0e10cSrcweir     lang::WrappedTargetException)
4414cdf0e10cSrcweir {
4415cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4416cdf0e10cSrcweir 
4417cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4418cdf0e10cSrcweir     if (!xDMA.is()) {
4419cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4420cdf0e10cSrcweir             "model has no document metadata"), *this );
4421cdf0e10cSrcweir     }
4422cdf0e10cSrcweir 
4423cdf0e10cSrcweir     return xDMA->storeMetadataToStorage(i_xStorage);
4424cdf0e10cSrcweir }
4425cdf0e10cSrcweir 
4426cdf0e10cSrcweir void SAL_CALL
4427cdf0e10cSrcweir SfxBaseModel::loadMetadataFromMedium(
4428cdf0e10cSrcweir     const uno::Sequence< beans::PropertyValue > & i_rMedium)
4429cdf0e10cSrcweir throw (uno::RuntimeException, lang::IllegalArgumentException,
4430cdf0e10cSrcweir     lang::WrappedTargetException)
4431cdf0e10cSrcweir {
4432cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4433cdf0e10cSrcweir 
4434cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(
4435cdf0e10cSrcweir         m_pData->CreateDMAUninitialized());
4436cdf0e10cSrcweir     if (!xDMA.is()) {
4437cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4438cdf0e10cSrcweir             "model has no document metadata"), *this );
4439cdf0e10cSrcweir     }
4440cdf0e10cSrcweir 
4441cdf0e10cSrcweir     try {
4442cdf0e10cSrcweir         xDMA->loadMetadataFromMedium(i_rMedium);
4443cdf0e10cSrcweir     } catch (lang::IllegalArgumentException &) {
4444cdf0e10cSrcweir         throw; // not initialized
4445cdf0e10cSrcweir     } catch (uno::Exception &) {
4446cdf0e10cSrcweir         // UGLY: if it's a RuntimeException, we can't be sure DMA is initialzed
4447cdf0e10cSrcweir         m_pData->m_xDocumentMetadata = xDMA;
4448cdf0e10cSrcweir         throw;
4449cdf0e10cSrcweir     }
4450cdf0e10cSrcweir     m_pData->m_xDocumentMetadata = xDMA;
4451cdf0e10cSrcweir }
4452cdf0e10cSrcweir 
4453cdf0e10cSrcweir void SAL_CALL
4454cdf0e10cSrcweir SfxBaseModel::storeMetadataToMedium(
4455cdf0e10cSrcweir     const uno::Sequence< beans::PropertyValue > & i_rMedium)
4456cdf0e10cSrcweir throw (uno::RuntimeException, lang::IllegalArgumentException,
4457cdf0e10cSrcweir     lang::WrappedTargetException)
4458cdf0e10cSrcweir {
4459cdf0e10cSrcweir     SfxModelGuard aGuard( *this );
4460cdf0e10cSrcweir 
4461cdf0e10cSrcweir     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4462cdf0e10cSrcweir     if (!xDMA.is()) {
4463cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4464cdf0e10cSrcweir             "model has no document metadata"), *this );
4465cdf0e10cSrcweir     }
4466cdf0e10cSrcweir 
4467cdf0e10cSrcweir     return xDMA->storeMetadataToMedium(i_rMedium);
4468cdf0e10cSrcweir }
4469cdf0e10cSrcweir 
4470cdf0e10cSrcweir // =====================================================================================================================
4471cdf0e10cSrcweir // = SfxModelSubComponent
4472cdf0e10cSrcweir // =====================================================================================================================
4473cdf0e10cSrcweir 
4474cdf0e10cSrcweir SfxModelSubComponent::~SfxModelSubComponent()
4475cdf0e10cSrcweir {
4476cdf0e10cSrcweir }
4477cdf0e10cSrcweir 
4478cdf0e10cSrcweir void SfxModelSubComponent::disposing()
4479cdf0e10cSrcweir {
4480cdf0e10cSrcweir     // nothing to do here
4481cdf0e10cSrcweir }
4482cdf0e10cSrcweir 
4483