1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_framework.hxx"
30*cdf0e10cSrcweir //_______________________________________________
31*cdf0e10cSrcweir // includes of own project
32*cdf0e10cSrcweir #include <loadenv/loadenv.hxx>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #ifndef __FRAMEWORK_LOADENV_TARGETHELPER_HXX_
35*cdf0e10cSrcweir #include <loadenv/targethelper.hxx>
36*cdf0e10cSrcweir #endif
37*cdf0e10cSrcweir #include <framework/framelistanalyzer.hxx>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #ifndef __FRAMEWORK_CONSTANT_FRAMELOADER_HXX_
40*cdf0e10cSrcweir #include <constant/frameloader.hxx>
41*cdf0e10cSrcweir #endif
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir #ifndef __FRAMEWORK_CONSTANT_CONTENTHANDLER_HXX_
44*cdf0e10cSrcweir #include <constant/contenthandler.hxx>
45*cdf0e10cSrcweir #endif
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir #ifndef __FRAMEWORK_CONSTANT_CONTAINERQUERY_HXX_
48*cdf0e10cSrcweir #include <constant/containerquery.hxx>
49*cdf0e10cSrcweir #endif
50*cdf0e10cSrcweir #include <interaction/quietinteraction.hxx>
51*cdf0e10cSrcweir #include <threadhelp/writeguard.hxx>
52*cdf0e10cSrcweir #include <threadhelp/readguard.hxx>
53*cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx>
54*cdf0e10cSrcweir #include <properties.h>
55*cdf0e10cSrcweir #include <protocols.h>
56*cdf0e10cSrcweir #include <services.h>
57*cdf0e10cSrcweir #include <comphelper/interaction.hxx>
58*cdf0e10cSrcweir #include <framework/interaction.hxx>
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir //_______________________________________________
61*cdf0e10cSrcweir // includes of uno interface
62*cdf0e10cSrcweir #include <com/sun/star/task/ErrorCodeRequest.hpp>
63*cdf0e10cSrcweir #include <com/sun/star/uno/RuntimeException.hpp>
64*cdf0e10cSrcweir #include <com/sun/star/frame/DispatchResultState.hpp>
65*cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp>
66*cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
67*cdf0e10cSrcweir #include <com/sun/star/ucb/XContentProviderManager.hpp>
68*cdf0e10cSrcweir #include <com/sun/star/util/XCloseable.hpp>
69*cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
70*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
71*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
72*cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp>
73*cdf0e10cSrcweir #include <com/sun/star/awt/XWindow2.hpp>
74*cdf0e10cSrcweir #include <com/sun/star/awt/XTopWindow.hpp>
75*cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
76*cdf0e10cSrcweir #include <com/sun/star/frame/XFrameLoader.hpp>
77*cdf0e10cSrcweir #include <com/sun/star/frame/XSynchronousFrameLoader.hpp>
78*cdf0e10cSrcweir #include <com/sun/star/frame/XNotifyingDispatch.hpp>
79*cdf0e10cSrcweir #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
80*cdf0e10cSrcweir #include <com/sun/star/task/XStatusIndicator.hpp>
81*cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp>
82*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp>
83*cdf0e10cSrcweir #include <com/sun/star/document/XTypeDetection.hpp>
84*cdf0e10cSrcweir #include <com/sun/star/document/XActionLockable.hpp>
85*cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
86*cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp>
87*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
88*cdf0e10cSrcweir #include <com/sun/star/container/XContainerQuery.hpp>
89*cdf0e10cSrcweir #include <com/sun/star/container/XEnumeration.hpp>
90*cdf0e10cSrcweir #include <com/sun/star/document/MacroExecMode.hpp>
91*cdf0e10cSrcweir #include <com/sun/star/document/UpdateDocMode.hpp>
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir //_______________________________________________
94*cdf0e10cSrcweir // includes of an other project
95*cdf0e10cSrcweir #include <vcl/window.hxx>
96*cdf0e10cSrcweir #include <vcl/wrkwin.hxx>
97*cdf0e10cSrcweir #include <vcl/syswin.hxx>
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
100*cdf0e10cSrcweir #include <toolkit/unohlp.hxx>
101*cdf0e10cSrcweir #endif
102*cdf0e10cSrcweir #include <unotools/moduleoptions.hxx>
103*cdf0e10cSrcweir #include <svtools/sfxecode.hxx>
104*cdf0e10cSrcweir #include <unotools/processfactory.hxx>
105*cdf0e10cSrcweir #include <unotools/ucbhelper.hxx>
106*cdf0e10cSrcweir #include <comphelper/configurationhelper.hxx>
107*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
108*cdf0e10cSrcweir #include <vcl/svapp.hxx>
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir //_______________________________________________
111*cdf0e10cSrcweir // namespace
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir namespace framework{
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir // may there exist already a define .-(
116*cdf0e10cSrcweir #ifndef css
117*cdf0e10cSrcweir namespace css = ::com::sun::star;
118*cdf0e10cSrcweir #endif
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir //_______________________________________________
121*cdf0e10cSrcweir // declarations
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir class LoadEnvListener : private ThreadHelpBase
124*cdf0e10cSrcweir                       , public ::cppu::WeakImplHelper2< css::frame::XLoadEventListener      ,
125*cdf0e10cSrcweir                                                         css::frame::XDispatchResultListener >
126*cdf0e10cSrcweir {
127*cdf0e10cSrcweir     private:
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir         void**   m_ppCheck ;
130*cdf0e10cSrcweir         LoadEnv* m_pLoadEnv;
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir     public:
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir         //_______________________________________
135*cdf0e10cSrcweir         LoadEnvListener(void*    pCheck  ,
136*cdf0e10cSrcweir                         LoadEnv* pLoadEnv)
137*cdf0e10cSrcweir         {
138*cdf0e10cSrcweir             m_ppCheck  = &pCheck ;
139*cdf0e10cSrcweir             m_pLoadEnv = pLoadEnv;
140*cdf0e10cSrcweir         }
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir         //_______________________________________
143*cdf0e10cSrcweir         // frame.XLoadEventListener
144*cdf0e10cSrcweir         virtual void SAL_CALL loadFinished(const css::uno::Reference< css::frame::XFrameLoader >& xLoader)
145*cdf0e10cSrcweir             throw(css::uno::RuntimeException);
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir         virtual void SAL_CALL loadCancelled(const css::uno::Reference< css::frame::XFrameLoader >& xLoader)
148*cdf0e10cSrcweir             throw(css::uno::RuntimeException);
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir         //_______________________________________
151*cdf0e10cSrcweir         // frame.XDispatchResultListener
152*cdf0e10cSrcweir         virtual void SAL_CALL dispatchFinished(const css::frame::DispatchResultEvent& aEvent)
153*cdf0e10cSrcweir             throw(css::uno::RuntimeException);
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir         //_______________________________________
156*cdf0e10cSrcweir         // lang.XEventListener
157*cdf0e10cSrcweir         virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent)
158*cdf0e10cSrcweir             throw(css::uno::RuntimeException);
159*cdf0e10cSrcweir };
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir /*-----------------------------------------------
162*cdf0e10cSrcweir     14.10.2003 13:43
163*cdf0e10cSrcweir -----------------------------------------------*/
164*cdf0e10cSrcweir LoadEnv::LoadEnv(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
165*cdf0e10cSrcweir     throw(LoadEnvException, css::uno::RuntimeException)
166*cdf0e10cSrcweir     : ThreadHelpBase(     )
167*cdf0e10cSrcweir     , m_xSMGR       (xSMGR)
168*cdf0e10cSrcweir     , m_pCheck      (this )
169*cdf0e10cSrcweir 	, m_pQuietInteraction( 0 )
170*cdf0e10cSrcweir {
171*cdf0e10cSrcweir }
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir /*-----------------------------------------------
174*cdf0e10cSrcweir     14.10.2003 13:43
175*cdf0e10cSrcweir -----------------------------------------------*/
176*cdf0e10cSrcweir LoadEnv::~LoadEnv()
177*cdf0e10cSrcweir {
178*cdf0e10cSrcweir     m_pCheck = 0;
179*cdf0e10cSrcweir }
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir /*-----------------------------------------------
182*cdf0e10cSrcweir     10.09.2003 14:05
183*cdf0e10cSrcweir -----------------------------------------------*/
184*cdf0e10cSrcweir css::uno::Reference< css::lang::XComponent > LoadEnv::loadComponentFromURL(const css::uno::Reference< css::frame::XComponentLoader >&    xLoader,
185*cdf0e10cSrcweir                                                                            const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR  ,
186*cdf0e10cSrcweir                                                                            const ::rtl::OUString&                                        sURL   ,
187*cdf0e10cSrcweir                                                                            const ::rtl::OUString&                                        sTarget,
188*cdf0e10cSrcweir                                                                                  sal_Int32                                               nFlags ,
189*cdf0e10cSrcweir                                                                            const css::uno::Sequence< css::beans::PropertyValue >&        lArgs  )
190*cdf0e10cSrcweir     throw(css::lang::IllegalArgumentException,
191*cdf0e10cSrcweir           css::io::IOException               ,
192*cdf0e10cSrcweir           css::uno::RuntimeException         )
193*cdf0e10cSrcweir {
194*cdf0e10cSrcweir     css::uno::Reference< css::lang::XComponent > xComponent;
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir     try
197*cdf0e10cSrcweir     {
198*cdf0e10cSrcweir         LoadEnv aEnv(xSMGR);
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir         aEnv.initializeLoading(sURL,
201*cdf0e10cSrcweir                                lArgs,
202*cdf0e10cSrcweir                                css::uno::Reference< css::frame::XFrame >(xLoader, css::uno::UNO_QUERY),
203*cdf0e10cSrcweir                                sTarget,
204*cdf0e10cSrcweir                                nFlags,
205*cdf0e10cSrcweir                                LoadEnv::E_NO_FEATURE);
206*cdf0e10cSrcweir         aEnv.startLoading();
207*cdf0e10cSrcweir         aEnv.waitWhileLoading(); // wait for ever!
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir         xComponent = aEnv.getTargetComponent();
210*cdf0e10cSrcweir     }
211*cdf0e10cSrcweir     catch(const LoadEnvException& ex)
212*cdf0e10cSrcweir     {
213*cdf0e10cSrcweir         switch(ex.m_nID)
214*cdf0e10cSrcweir         {
215*cdf0e10cSrcweir             case LoadEnvException::ID_INVALID_MEDIADESCRIPTOR:
216*cdf0e10cSrcweir                     throw css::lang::IllegalArgumentException(
217*cdf0e10cSrcweir                             ::rtl::OUString::createFromAscii("Optional list of arguments seem to be corrupted."),
218*cdf0e10cSrcweir                             xLoader,
219*cdf0e10cSrcweir                             4);
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir             case LoadEnvException::ID_UNSUPPORTED_CONTENT:
222*cdf0e10cSrcweir                     throw css::lang::IllegalArgumentException(
223*cdf0e10cSrcweir                             ::rtl::OUString::createFromAscii("URL seems to be an unsupported one."),
224*cdf0e10cSrcweir                             xLoader,
225*cdf0e10cSrcweir                             1);
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir 			default: xComponent.clear();
228*cdf0e10cSrcweir                     break;
229*cdf0e10cSrcweir         }
230*cdf0e10cSrcweir     }
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir     return xComponent;
233*cdf0e10cSrcweir }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir //-----------------------------------------------
236*cdf0e10cSrcweir ::comphelper::MediaDescriptor impl_mergeMediaDescriptorWithMightExistingModelArgs(const css::uno::Sequence< css::beans::PropertyValue >& lOutsideDescriptor)
237*cdf0e10cSrcweir {
238*cdf0e10cSrcweir     ::comphelper::MediaDescriptor lDescriptor(lOutsideDescriptor);
239*cdf0e10cSrcweir     css::uno::Reference< css::frame::XModel > xModel     = lDescriptor.getUnpackedValueOrDefault(
240*cdf0e10cSrcweir                                                             ::comphelper::MediaDescriptor::PROP_MODEL (),
241*cdf0e10cSrcweir                                                             css::uno::Reference< css::frame::XModel > ());
242*cdf0e10cSrcweir     if (xModel.is ())
243*cdf0e10cSrcweir     {
244*cdf0e10cSrcweir         ::comphelper::MediaDescriptor lModelDescriptor(xModel->getArgs());
245*cdf0e10cSrcweir         ::comphelper::MediaDescriptor::iterator pIt = lModelDescriptor.find( ::comphelper::MediaDescriptor::PROP_MACROEXECUTIONMODE() );
246*cdf0e10cSrcweir 		if ( pIt != lModelDescriptor.end() )
247*cdf0e10cSrcweir 			lDescriptor[::comphelper::MediaDescriptor::PROP_MACROEXECUTIONMODE()] = pIt->second;
248*cdf0e10cSrcweir     }
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir     return lDescriptor;
251*cdf0e10cSrcweir }
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir /*-----------------------------------------------
254*cdf0e10cSrcweir     20.08.2003 09:49
255*cdf0e10cSrcweir -----------------------------------------------*/
256*cdf0e10cSrcweir void LoadEnv::initializeLoading(const ::rtl::OUString&                                           sURL            ,
257*cdf0e10cSrcweir                                 const css::uno::Sequence< css::beans::PropertyValue >&           lMediaDescriptor,
258*cdf0e10cSrcweir                                 const css::uno::Reference< css::frame::XFrame >&                 xBaseFrame      ,
259*cdf0e10cSrcweir                                 const ::rtl::OUString&                                           sTarget         ,
260*cdf0e10cSrcweir                                       sal_Int32                                                  nSearchFlags    ,
261*cdf0e10cSrcweir                                       EFeature                                                   eFeature        , // => use default ...
262*cdf0e10cSrcweir                                       EContentType                                               eContentType    ) // => use default ...
263*cdf0e10cSrcweir     throw(LoadEnvException, css::uno::RuntimeException)
264*cdf0e10cSrcweir {
265*cdf0e10cSrcweir     // SAFE -> ----------------------------------
266*cdf0e10cSrcweir     WriteGuard aWriteLock(m_aLock);
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir     // Handle still running processes!
269*cdf0e10cSrcweir     if (m_xAsynchronousJob.is())
270*cdf0e10cSrcweir         throw LoadEnvException(LoadEnvException::ID_STILL_RUNNING);
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir     // take over all new parameters.
273*cdf0e10cSrcweir     m_xTargetFrame.clear();
274*cdf0e10cSrcweir     m_xBaseFrame                    = xBaseFrame        ;
275*cdf0e10cSrcweir     m_lMediaDescriptor              = impl_mergeMediaDescriptorWithMightExistingModelArgs(lMediaDescriptor);
276*cdf0e10cSrcweir     m_sTarget                       = sTarget           ;
277*cdf0e10cSrcweir     m_nSearchFlags                  = nSearchFlags      ;
278*cdf0e10cSrcweir     m_eFeature                      = eFeature          ;
279*cdf0e10cSrcweir     m_eContentType                  = eContentType      ;
280*cdf0e10cSrcweir     m_bCloseFrameOnError            = sal_False         ;
281*cdf0e10cSrcweir     m_bReactivateControllerOnError  = sal_False         ;
282*cdf0e10cSrcweir     m_bLoaded                       = sal_False         ;
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir     // try to find out, if its realy a content, which can be loaded or must be "handled"
285*cdf0e10cSrcweir     // We use a default value for this in-parameter. Then we have to start a complex check method
286*cdf0e10cSrcweir     // internaly. But if this check was already done outside it can be supressed to perform
287*cdf0e10cSrcweir     // the load request. We take over the result then!
288*cdf0e10cSrcweir     if (m_eContentType == E_UNSUPPORTED_CONTENT)
289*cdf0e10cSrcweir     {
290*cdf0e10cSrcweir         m_eContentType = LoadEnv::classifyContent(sURL, lMediaDescriptor);
291*cdf0e10cSrcweir         if (m_eContentType == E_UNSUPPORTED_CONTENT)
292*cdf0e10cSrcweir             throw LoadEnvException(LoadEnvException::ID_UNSUPPORTED_CONTENT);
293*cdf0e10cSrcweir     }
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir     // make URL part of the MediaDescriptor
296*cdf0e10cSrcweir     // It doesnt mater, if its already an item of it.
297*cdf0e10cSrcweir     // It must be the same value ... so we can overwrite it :-)
298*cdf0e10cSrcweir     m_lMediaDescriptor[::comphelper::MediaDescriptor::PROP_URL()] <<= sURL;
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir     // parse it - because some following code require that
301*cdf0e10cSrcweir     m_aURL.Complete = sURL;
302*cdf0e10cSrcweir     css::uno::Reference< css::util::XURLTransformer > xParser(m_xSMGR->createInstance(SERVICENAME_URLTRANSFORMER), css::uno::UNO_QUERY);
303*cdf0e10cSrcweir     xParser->parseStrict(m_aURL);
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir     // BTW: Split URL and JumpMark ...
306*cdf0e10cSrcweir     // Because such mark is an explicit value of the media descriptor!
307*cdf0e10cSrcweir     if (m_aURL.Mark.getLength())
308*cdf0e10cSrcweir         m_lMediaDescriptor[::comphelper::MediaDescriptor::PROP_JUMPMARK()] <<= m_aURL.Mark;
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir     // By the way: remove the old and deprecated value "FileName" from the descriptor!
311*cdf0e10cSrcweir     ::comphelper::MediaDescriptor::iterator pIt = m_lMediaDescriptor.find(::comphelper::MediaDescriptor::PROP_FILENAME());
312*cdf0e10cSrcweir     if (pIt != m_lMediaDescriptor.end())
313*cdf0e10cSrcweir         m_lMediaDescriptor.erase(pIt);
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir     // patch the MediaDescriptor, so it fullfill the outside requirements
316*cdf0e10cSrcweir     // Means especialy items like e.g. UI InteractionHandler, Status Indicator,
317*cdf0e10cSrcweir     // MacroExecutionMode etcpp.
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir     /*TODO progress is bound to a frame ... How can we set it here? */
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir     // UI mode
322*cdf0e10cSrcweir     const bool bUIMode =
323*cdf0e10cSrcweir         ( ( m_eFeature & E_WORK_WITH_UI )                                                                          == E_WORK_WITH_UI ) &&
324*cdf0e10cSrcweir         ( m_lMediaDescriptor.getUnpackedValueOrDefault( ::comphelper::MediaDescriptor::PROP_HIDDEN() , sal_False ) == sal_False      ) &&
325*cdf0e10cSrcweir         ( m_lMediaDescriptor.getUnpackedValueOrDefault( ::comphelper::MediaDescriptor::PROP_PREVIEW(), sal_False ) == sal_False      );
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir     initializeUIDefaults(
328*cdf0e10cSrcweir         m_xSMGR,
329*cdf0e10cSrcweir         m_lMediaDescriptor,
330*cdf0e10cSrcweir         bUIMode,
331*cdf0e10cSrcweir         &m_pQuietInteraction
332*cdf0e10cSrcweir     );
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir     aWriteLock.unlock();
335*cdf0e10cSrcweir     // <- SAFE ----------------------------------
336*cdf0e10cSrcweir }
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir /*-----------------------------------------------
339*cdf0e10cSrcweir     22.01.2010
340*cdf0e10cSrcweir -----------------------------------------------*/
341*cdf0e10cSrcweir void LoadEnv::initializeUIDefaults( const css::uno::Reference< css::lang::XMultiServiceFactory >& i_rSMGR,
342*cdf0e10cSrcweir                                     ::comphelper::MediaDescriptor& io_lMediaDescriptor, const bool i_bUIMode,
343*cdf0e10cSrcweir                                     QuietInteraction** o_ppQuietInteraction )
344*cdf0e10cSrcweir {
345*cdf0e10cSrcweir     css::uno::Reference< css::task::XInteractionHandler > xInteractionHandler;
346*cdf0e10cSrcweir     sal_Int16                                             nMacroMode         ;
347*cdf0e10cSrcweir     sal_Int16                                             nUpdateMode        ;
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir     if ( i_bUIMode )
350*cdf0e10cSrcweir     {
351*cdf0e10cSrcweir         nMacroMode  = css::document::MacroExecMode::USE_CONFIG;
352*cdf0e10cSrcweir         nUpdateMode = css::document::UpdateDocMode::ACCORDING_TO_CONFIG;
353*cdf0e10cSrcweir         try
354*cdf0e10cSrcweir         {
355*cdf0e10cSrcweir             xInteractionHandler = css::uno::Reference< css::task::XInteractionHandler >(i_rSMGR->createInstance(IMPLEMENTATIONNAME_UIINTERACTIONHANDLER), css::uno::UNO_QUERY);
356*cdf0e10cSrcweir         }
357*cdf0e10cSrcweir         catch(const css::uno::RuntimeException&) {throw;}
358*cdf0e10cSrcweir         catch(const css::uno::Exception&       ) {      }
359*cdf0e10cSrcweir     }
360*cdf0e10cSrcweir     // hidden mode
361*cdf0e10cSrcweir     else
362*cdf0e10cSrcweir     {
363*cdf0e10cSrcweir         nMacroMode  = css::document::MacroExecMode::NEVER_EXECUTE;
364*cdf0e10cSrcweir         nUpdateMode = css::document::UpdateDocMode::NO_UPDATE;
365*cdf0e10cSrcweir         QuietInteraction* pQuietInteraction = new QuietInteraction();
366*cdf0e10cSrcweir         xInteractionHandler = css::uno::Reference< css::task::XInteractionHandler >(static_cast< css::task::XInteractionHandler* >(pQuietInteraction), css::uno::UNO_QUERY);
367*cdf0e10cSrcweir         if ( o_ppQuietInteraction != NULL )
368*cdf0e10cSrcweir         {
369*cdf0e10cSrcweir             *o_ppQuietInteraction = pQuietInteraction;
370*cdf0e10cSrcweir             (*o_ppQuietInteraction)->acquire();
371*cdf0e10cSrcweir         }
372*cdf0e10cSrcweir     }
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir     if (
375*cdf0e10cSrcweir         (xInteractionHandler.is()                                                                                       ) &&
376*cdf0e10cSrcweir         (io_lMediaDescriptor.find(::comphelper::MediaDescriptor::PROP_INTERACTIONHANDLER()) == io_lMediaDescriptor.end())
377*cdf0e10cSrcweir        )
378*cdf0e10cSrcweir     {
379*cdf0e10cSrcweir         io_lMediaDescriptor[::comphelper::MediaDescriptor::PROP_INTERACTIONHANDLER()] <<= xInteractionHandler;
380*cdf0e10cSrcweir     }
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir     if (io_lMediaDescriptor.find(::comphelper::MediaDescriptor::PROP_MACROEXECUTIONMODE()) == io_lMediaDescriptor.end())
383*cdf0e10cSrcweir         io_lMediaDescriptor[::comphelper::MediaDescriptor::PROP_MACROEXECUTIONMODE()] <<= nMacroMode;
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir     if (io_lMediaDescriptor.find(::comphelper::MediaDescriptor::PROP_UPDATEDOCMODE()) == io_lMediaDescriptor.end())
386*cdf0e10cSrcweir         io_lMediaDescriptor[::comphelper::MediaDescriptor::PROP_UPDATEDOCMODE()] <<= nUpdateMode;
387*cdf0e10cSrcweir }
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir /*-----------------------------------------------
390*cdf0e10cSrcweir     15.08.2003 08:16
391*cdf0e10cSrcweir -----------------------------------------------*/
392*cdf0e10cSrcweir void LoadEnv::startLoading()
393*cdf0e10cSrcweir     throw(LoadEnvException, css::uno::RuntimeException)
394*cdf0e10cSrcweir {
395*cdf0e10cSrcweir     // SAFE ->
396*cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir     // Handle still running processes!
399*cdf0e10cSrcweir     if (m_xAsynchronousJob.is())
400*cdf0e10cSrcweir         throw LoadEnvException(LoadEnvException::ID_STILL_RUNNING);
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir     // content can not be loaded or handled
403*cdf0e10cSrcweir     // check "classifyContent()" failed before ...
404*cdf0e10cSrcweir     if (m_eContentType == E_UNSUPPORTED_CONTENT)
405*cdf0e10cSrcweir         throw LoadEnvException(LoadEnvException::ID_UNSUPPORTED_CONTENT);
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir     // <- SAFE
408*cdf0e10cSrcweir     aReadLock.unlock();
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir     // detect its type/filter etcpp.
411*cdf0e10cSrcweir     // These information will be available by the
412*cdf0e10cSrcweir     // used descriptor member afterwards and is needed
413*cdf0e10cSrcweir     // for all following operations!
414*cdf0e10cSrcweir     // Note: An exception will be thrown, in case operation was not successfully ...
415*cdf0e10cSrcweir     if (m_eContentType != E_CAN_BE_SET)/* Attention: special feature to set existing component on a frame must ignore type detection! */
416*cdf0e10cSrcweir         impl_detectTypeAndFilter();
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir     // start loading the content ...
419*cdf0e10cSrcweir     // Attention: Dont check m_eContentType deeper then UNSUPPORTED/SUPPORTED!
420*cdf0e10cSrcweir     // Because it was made in th easiest way ... may a flat detection was made only.
421*cdf0e10cSrcweir     // And such simple detection can fail some times .-)
422*cdf0e10cSrcweir     // Use another strategy here. Try it and let it run into the case "loading not possible".
423*cdf0e10cSrcweir     sal_Bool bStarted = sal_False;
424*cdf0e10cSrcweir     if (
425*cdf0e10cSrcweir         ((m_eFeature & E_ALLOW_CONTENTHANDLER) == E_ALLOW_CONTENTHANDLER) &&
426*cdf0e10cSrcweir         (m_eContentType                        != E_CAN_BE_SET          )   /* Attention: special feature to set existing component on a frame must ignore type detection! */
427*cdf0e10cSrcweir        )
428*cdf0e10cSrcweir     {
429*cdf0e10cSrcweir         bStarted = impl_handleContent();
430*cdf0e10cSrcweir     }
431*cdf0e10cSrcweir 
432*cdf0e10cSrcweir     if (!bStarted)
433*cdf0e10cSrcweir         bStarted = impl_loadContent();
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir     // not started => general error
436*cdf0e10cSrcweir     // We cant say - what was the reason for.
437*cdf0e10cSrcweir     if (!bStarted)
438*cdf0e10cSrcweir         throw LoadEnvException(LoadEnvException::ID_GENERAL_ERROR);
439*cdf0e10cSrcweir }
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir /*-----------------------------------------------
442*cdf0e10cSrcweir     15.08.2003 09:50
443*cdf0e10cSrcweir     TODO
444*cdf0e10cSrcweir         First draft does not implement timeout using [ms].
445*cdf0e10cSrcweir         Current implementation counts yield calls only ...
446*cdf0e10cSrcweir -----------------------------------------------*/
447*cdf0e10cSrcweir sal_Bool LoadEnv::waitWhileLoading(sal_uInt32 nTimeout)
448*cdf0e10cSrcweir     throw(LoadEnvException, css::uno::RuntimeException)
449*cdf0e10cSrcweir {
450*cdf0e10cSrcweir     // Because its not a good idea to block the main thread
451*cdf0e10cSrcweir     // (and we cant be shure that we are currently not used inside the
452*cdf0e10cSrcweir     // main thread!), we cant use conditions here realy. We must yield
453*cdf0e10cSrcweir     // in an intellegent manner :-)
454*cdf0e10cSrcweir 
455*cdf0e10cSrcweir     sal_Int32 nTime = nTimeout;
456*cdf0e10cSrcweir     while(true)
457*cdf0e10cSrcweir     {
458*cdf0e10cSrcweir         // SAFE -> ------------------------------
459*cdf0e10cSrcweir         ReadGuard aReadLock1(m_aLock);
460*cdf0e10cSrcweir         if (!m_xAsynchronousJob.is())
461*cdf0e10cSrcweir             break;
462*cdf0e10cSrcweir         aReadLock1.unlock();
463*cdf0e10cSrcweir         // <- SAFE ------------------------------
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir         Application::Yield();
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir         // forever!
468*cdf0e10cSrcweir         if (nTimeout==0)
469*cdf0e10cSrcweir             continue;
470*cdf0e10cSrcweir 
471*cdf0e10cSrcweir         // timed out?
472*cdf0e10cSrcweir         --nTime;
473*cdf0e10cSrcweir         if (nTime<1)
474*cdf0e10cSrcweir             break;
475*cdf0e10cSrcweir     }
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir     // SAFE -> ----------------------------------
478*cdf0e10cSrcweir     ReadGuard aReadLock2(m_aLock);
479*cdf0e10cSrcweir     return !m_xAsynchronousJob.is();
480*cdf0e10cSrcweir     // <- SAFE ----------------------------------
481*cdf0e10cSrcweir }
482*cdf0e10cSrcweir 
483*cdf0e10cSrcweir /*-----------------------------------------------
484*cdf0e10cSrcweir     20.08.2003 10:00
485*cdf0e10cSrcweir -----------------------------------------------*/
486*cdf0e10cSrcweir void LoadEnv::cancelLoading()
487*cdf0e10cSrcweir     throw(LoadEnvException, css::uno::RuntimeException)
488*cdf0e10cSrcweir {
489*cdf0e10cSrcweir     // PARTIAL(!) SAFE -> ------------------------------
490*cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
491*cdf0e10cSrcweir 
492*cdf0e10cSrcweir     // Still running? Might waitWhileLoading()
493*cdf0e10cSrcweir     // runned into the timeout!
494*cdf0e10cSrcweir     if (m_xAsynchronousJob.is())
495*cdf0e10cSrcweir     {
496*cdf0e10cSrcweir         // try to cancel it ... if its an asynchronous frame loader
497*cdf0e10cSrcweir         css::uno::Reference< css::frame::XFrameLoader > xAsyncLoader(m_xAsynchronousJob, css::uno::UNO_QUERY);
498*cdf0e10cSrcweir         if (xAsyncLoader.is())
499*cdf0e10cSrcweir         {
500*cdf0e10cSrcweir             aReadLock.unlock();
501*cdf0e10cSrcweir             // <- BREAK SAFE ------------------------------
502*cdf0e10cSrcweir             xAsyncLoader->cancel();
503*cdf0e10cSrcweir             // <- RESTART SAFE ----------------------------
504*cdf0e10cSrcweir             aReadLock.lock();
505*cdf0e10cSrcweir             /* Attention:
506*cdf0e10cSrcweir                 After returning from any cancel/dispose call, neither the frame nor weself
507*cdf0e10cSrcweir                 may be called back. Because only we can cancel this job, we already know
508*cdf0e10cSrcweir                 the result! => Thats why its not usefull nor neccessary to wait for any
509*cdf0e10cSrcweir                 asynchronous listener notification.
510*cdf0e10cSrcweir             */
511*cdf0e10cSrcweir             m_bLoaded = sal_False;
512*cdf0e10cSrcweir             m_xAsynchronousJob.clear();
513*cdf0e10cSrcweir         }
514*cdf0e10cSrcweir         // or may be its a content handler? Such handler cant be cancelled in its running
515*cdf0e10cSrcweir         // operation :-( And we cant deregister us there again :-(
516*cdf0e10cSrcweir         // => The only chance is an exception :-)
517*cdf0e10cSrcweir         else
518*cdf0e10cSrcweir             throw LoadEnvException(LoadEnvException::ID_STILL_RUNNING);
519*cdf0e10cSrcweir     }
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir     impl_reactForLoadingState();
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir     aReadLock.unlock();
524*cdf0e10cSrcweir     // <- PARTIAL(!) SAFE ------------------------------
525*cdf0e10cSrcweir }
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir /*-----------------------------------------------
528*cdf0e10cSrcweir     14.08.2003 13:33
529*cdf0e10cSrcweir -----------------------------------------------*/
530*cdf0e10cSrcweir css::uno::Reference< css::frame::XFrame > LoadEnv::getTarget() const
531*cdf0e10cSrcweir {
532*cdf0e10cSrcweir     // SAFE ->
533*cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
534*cdf0e10cSrcweir     return m_xTargetFrame;
535*cdf0e10cSrcweir     // <- SAFE
536*cdf0e10cSrcweir }
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir /*-----------------------------------------------
539*cdf0e10cSrcweir     14.08.2003 13:35
540*cdf0e10cSrcweir -----------------------------------------------*/
541*cdf0e10cSrcweir css::uno::Reference< css::lang::XComponent > LoadEnv::getTargetComponent() const
542*cdf0e10cSrcweir {
543*cdf0e10cSrcweir     // SAFE ->
544*cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir     if (!m_xTargetFrame.is())
547*cdf0e10cSrcweir         return css::uno::Reference< css::lang::XComponent >();
548*cdf0e10cSrcweir 
549*cdf0e10cSrcweir     css::uno::Reference< css::frame::XController > xController = m_xTargetFrame->getController();
550*cdf0e10cSrcweir     if (!xController.is())
551*cdf0e10cSrcweir         return css::uno::Reference< css::lang::XComponent >(m_xTargetFrame->getComponentWindow(), css::uno::UNO_QUERY);
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir     css::uno::Reference< css::frame::XModel > xModel = xController->getModel();
554*cdf0e10cSrcweir     if (!xModel.is())
555*cdf0e10cSrcweir         return css::uno::Reference< css::lang::XComponent >(xController, css::uno::UNO_QUERY);
556*cdf0e10cSrcweir 
557*cdf0e10cSrcweir     return css::uno::Reference< css::lang::XComponent >(xModel, css::uno::UNO_QUERY);
558*cdf0e10cSrcweir     // <- SAFE
559*cdf0e10cSrcweir }
560*cdf0e10cSrcweir 
561*cdf0e10cSrcweir /*-----------------------------------------------
562*cdf0e10cSrcweir     15.08.2003 11:15
563*cdf0e10cSrcweir -----------------------------------------------*/
564*cdf0e10cSrcweir void SAL_CALL LoadEnvListener::loadFinished(const css::uno::Reference< css::frame::XFrameLoader >&)
565*cdf0e10cSrcweir     throw(css::uno::RuntimeException)
566*cdf0e10cSrcweir {
567*cdf0e10cSrcweir     // SAFE -> ----------------------------------
568*cdf0e10cSrcweir     WriteGuard aWriteLock(m_aLock);
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir     if (m_ppCheck && *m_ppCheck)
571*cdf0e10cSrcweir         m_pLoadEnv->impl_setResult(sal_True);
572*cdf0e10cSrcweir     m_ppCheck = NULL;
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir     aWriteLock.unlock();
575*cdf0e10cSrcweir     // <- SAFE ----------------------------------
576*cdf0e10cSrcweir }
577*cdf0e10cSrcweir 
578*cdf0e10cSrcweir /*-----------------------------------------------
579*cdf0e10cSrcweir     14.10.2003 12:23
580*cdf0e10cSrcweir -----------------------------------------------*/
581*cdf0e10cSrcweir void SAL_CALL LoadEnvListener::loadCancelled(const css::uno::Reference< css::frame::XFrameLoader >&)
582*cdf0e10cSrcweir     throw(css::uno::RuntimeException)
583*cdf0e10cSrcweir {
584*cdf0e10cSrcweir     // SAFE -> ----------------------------------
585*cdf0e10cSrcweir     WriteGuard aWriteLock(m_aLock);
586*cdf0e10cSrcweir 
587*cdf0e10cSrcweir     if (m_ppCheck && *m_ppCheck)
588*cdf0e10cSrcweir         m_pLoadEnv->impl_setResult(sal_False);
589*cdf0e10cSrcweir     m_ppCheck = NULL;
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir     aWriteLock.unlock();
592*cdf0e10cSrcweir     // <- SAFE ----------------------------------
593*cdf0e10cSrcweir }
594*cdf0e10cSrcweir 
595*cdf0e10cSrcweir /*-----------------------------------------------
596*cdf0e10cSrcweir     14.10.2003 12:23
597*cdf0e10cSrcweir -----------------------------------------------*/
598*cdf0e10cSrcweir void SAL_CALL LoadEnvListener::dispatchFinished(const css::frame::DispatchResultEvent& aEvent)
599*cdf0e10cSrcweir     throw(css::uno::RuntimeException)
600*cdf0e10cSrcweir {
601*cdf0e10cSrcweir     // SAFE -> ----------------------------------
602*cdf0e10cSrcweir     WriteGuard aWriteLock(m_aLock);
603*cdf0e10cSrcweir 
604*cdf0e10cSrcweir     if (!m_ppCheck || !*m_ppCheck)
605*cdf0e10cSrcweir         return;
606*cdf0e10cSrcweir 
607*cdf0e10cSrcweir     switch(aEvent.State)
608*cdf0e10cSrcweir     {
609*cdf0e10cSrcweir         case css::frame::DispatchResultState::FAILURE :
610*cdf0e10cSrcweir             m_pLoadEnv->impl_setResult(sal_False);
611*cdf0e10cSrcweir             break;
612*cdf0e10cSrcweir 
613*cdf0e10cSrcweir         case css::frame::DispatchResultState::SUCCESS :
614*cdf0e10cSrcweir             m_pLoadEnv->impl_setResult(sal_False);
615*cdf0e10cSrcweir             break;
616*cdf0e10cSrcweir 
617*cdf0e10cSrcweir         case css::frame::DispatchResultState::DONTKNOW :
618*cdf0e10cSrcweir             m_pLoadEnv->impl_setResult(sal_False);
619*cdf0e10cSrcweir             break;
620*cdf0e10cSrcweir     }
621*cdf0e10cSrcweir     m_ppCheck = NULL;
622*cdf0e10cSrcweir 
623*cdf0e10cSrcweir     aWriteLock.unlock();
624*cdf0e10cSrcweir     // <- SAFE ----------------------------------
625*cdf0e10cSrcweir }
626*cdf0e10cSrcweir 
627*cdf0e10cSrcweir /*-----------------------------------------------
628*cdf0e10cSrcweir     14.10.2003 12:24
629*cdf0e10cSrcweir -----------------------------------------------*/
630*cdf0e10cSrcweir void SAL_CALL LoadEnvListener::disposing(const css::lang::EventObject&)
631*cdf0e10cSrcweir     throw(css::uno::RuntimeException)
632*cdf0e10cSrcweir {
633*cdf0e10cSrcweir     // SAFE -> ----------------------------------
634*cdf0e10cSrcweir     WriteGuard aWriteLock(m_aLock);
635*cdf0e10cSrcweir 
636*cdf0e10cSrcweir     if (m_ppCheck && *m_ppCheck)
637*cdf0e10cSrcweir         m_pLoadEnv->impl_setResult(sal_False);
638*cdf0e10cSrcweir     m_ppCheck = NULL;
639*cdf0e10cSrcweir 
640*cdf0e10cSrcweir     aWriteLock.unlock();
641*cdf0e10cSrcweir     // <- SAFE ----------------------------------
642*cdf0e10cSrcweir }
643*cdf0e10cSrcweir 
644*cdf0e10cSrcweir /*-----------------------------------------------
645*cdf0e10cSrcweir     14.10.2003 12:20
646*cdf0e10cSrcweir -----------------------------------------------*/
647*cdf0e10cSrcweir void LoadEnv::impl_setResult(sal_Bool bResult)
648*cdf0e10cSrcweir {
649*cdf0e10cSrcweir     // SAFE -> ----------------------------------
650*cdf0e10cSrcweir     WriteGuard aWriteLock(m_aLock);
651*cdf0e10cSrcweir 
652*cdf0e10cSrcweir     m_bLoaded = bResult;
653*cdf0e10cSrcweir 
654*cdf0e10cSrcweir     impl_reactForLoadingState();
655*cdf0e10cSrcweir 
656*cdf0e10cSrcweir     // clearing of this reference will unblock waitWhileLoading()!
657*cdf0e10cSrcweir     // So we must be shure, that loading process was realy finished.
658*cdf0e10cSrcweir     // => do it as last operation of this method ...
659*cdf0e10cSrcweir     m_xAsynchronousJob.clear();
660*cdf0e10cSrcweir 
661*cdf0e10cSrcweir     aWriteLock.unlock();
662*cdf0e10cSrcweir     // <- SAFE ----------------------------------
663*cdf0e10cSrcweir }
664*cdf0e10cSrcweir 
665*cdf0e10cSrcweir /*-----------------------------------------------
666*cdf0e10cSrcweir     06.02.2004 14:03
667*cdf0e10cSrcweir     TODO: Is it a good idea to change Sequence<>
668*cdf0e10cSrcweir           parameter to stl-adapter?
669*cdf0e10cSrcweir -----------------------------------------------*/
670*cdf0e10cSrcweir LoadEnv::EContentType LoadEnv::classifyContent(const ::rtl::OUString&                                 sURL            ,
671*cdf0e10cSrcweir                                                const css::uno::Sequence< css::beans::PropertyValue >& lMediaDescriptor)
672*cdf0e10cSrcweir {
673*cdf0e10cSrcweir     //-------------------------------------------
674*cdf0e10cSrcweir     // (i) Filter some special well known URL protocols,
675*cdf0e10cSrcweir     //     which can not be handled or loaded in general.
676*cdf0e10cSrcweir     //     Of course an empty URL must be ignored here too.
677*cdf0e10cSrcweir     //     Note: These URL schemata are fix and well known ...
678*cdf0e10cSrcweir     //     But there can be some additional ones, which was not
679*cdf0e10cSrcweir     //     defined at implementation time of this class :-(
680*cdf0e10cSrcweir     //     So we have to make shure, that the following code
681*cdf0e10cSrcweir     //     can detect such protocol schemata too :-)
682*cdf0e10cSrcweir 
683*cdf0e10cSrcweir     if(
684*cdf0e10cSrcweir         (!sURL.getLength()                                       ) ||
685*cdf0e10cSrcweir         (ProtocolCheck::isProtocol(sURL,ProtocolCheck::E_UNO    )) ||
686*cdf0e10cSrcweir         (ProtocolCheck::isProtocol(sURL,ProtocolCheck::E_SLOT   )) ||
687*cdf0e10cSrcweir         (ProtocolCheck::isProtocol(sURL,ProtocolCheck::E_MACRO  )) ||
688*cdf0e10cSrcweir         (ProtocolCheck::isProtocol(sURL,ProtocolCheck::E_SERVICE)) ||
689*cdf0e10cSrcweir         (ProtocolCheck::isProtocol(sURL,ProtocolCheck::E_MAILTO )) ||
690*cdf0e10cSrcweir         (ProtocolCheck::isProtocol(sURL,ProtocolCheck::E_NEWS   ))
691*cdf0e10cSrcweir       )
692*cdf0e10cSrcweir     {
693*cdf0e10cSrcweir         return E_UNSUPPORTED_CONTENT;
694*cdf0e10cSrcweir     }
695*cdf0e10cSrcweir 
696*cdf0e10cSrcweir     //-------------------------------------------
697*cdf0e10cSrcweir     // (ii) Some special URLs indicates a given input stream,
698*cdf0e10cSrcweir     //      a full featured document model directly or
699*cdf0e10cSrcweir     //      specify a request for opening an empty document.
700*cdf0e10cSrcweir     //      Such contents are loadable in general.
701*cdf0e10cSrcweir     //      But we have to check, if the media descriptor contains
702*cdf0e10cSrcweir     //      all needed resources. If they are missing - the following
703*cdf0e10cSrcweir     //      load request will fail.
704*cdf0e10cSrcweir 
705*cdf0e10cSrcweir     /* Attention: The following code cant work on such special URLs!
706*cdf0e10cSrcweir                   It should not break the office .. but it make no sense
707*cdf0e10cSrcweir                   to start expensive object creations and complex search
708*cdf0e10cSrcweir                   algorithm if its clear, that such URLs must be handled
709*cdf0e10cSrcweir                   in a special way .-)
710*cdf0e10cSrcweir     */
711*cdf0e10cSrcweir 
712*cdf0e10cSrcweir     // creation of new documents
713*cdf0e10cSrcweir     if (ProtocolCheck::isProtocol(sURL,ProtocolCheck::E_PRIVATE_FACTORY))
714*cdf0e10cSrcweir         return E_CAN_BE_LOADED;
715*cdf0e10cSrcweir 
716*cdf0e10cSrcweir     // using of an existing input stream
717*cdf0e10cSrcweir     ::comphelper::MediaDescriptor                 stlMediaDescriptor(lMediaDescriptor);
718*cdf0e10cSrcweir     ::comphelper::MediaDescriptor::const_iterator pIt;
719*cdf0e10cSrcweir     if (ProtocolCheck::isProtocol(sURL,ProtocolCheck::E_PRIVATE_STREAM))
720*cdf0e10cSrcweir     {
721*cdf0e10cSrcweir         pIt = stlMediaDescriptor.find(::comphelper::MediaDescriptor::PROP_INPUTSTREAM());
722*cdf0e10cSrcweir         css::uno::Reference< css::io::XInputStream > xStream;
723*cdf0e10cSrcweir         if (pIt != stlMediaDescriptor.end())
724*cdf0e10cSrcweir             pIt->second >>= xStream;
725*cdf0e10cSrcweir         if (xStream.is())
726*cdf0e10cSrcweir             return E_CAN_BE_LOADED;
727*cdf0e10cSrcweir         LOG_WARNING("LoadEnv::classifyContent()", "loading from stream with right URL but invalid stream detected")
728*cdf0e10cSrcweir         return E_UNSUPPORTED_CONTENT;
729*cdf0e10cSrcweir     }
730*cdf0e10cSrcweir 
731*cdf0e10cSrcweir     // using of a full featured document
732*cdf0e10cSrcweir     if (ProtocolCheck::isProtocol(sURL,ProtocolCheck::E_PRIVATE_OBJECT))
733*cdf0e10cSrcweir     {
734*cdf0e10cSrcweir         pIt = stlMediaDescriptor.find(::comphelper::MediaDescriptor::PROP_MODEL());
735*cdf0e10cSrcweir         css::uno::Reference< css::frame::XModel > xModel;
736*cdf0e10cSrcweir         if (pIt != stlMediaDescriptor.end())
737*cdf0e10cSrcweir             pIt->second >>= xModel;
738*cdf0e10cSrcweir         if (xModel.is())
739*cdf0e10cSrcweir             return E_CAN_BE_SET;
740*cdf0e10cSrcweir         LOG_WARNING("LoadEnv::classifyContent()", "loading with object with right URL but invalid object detected")
741*cdf0e10cSrcweir         return E_UNSUPPORTED_CONTENT;
742*cdf0e10cSrcweir     }
743*cdf0e10cSrcweir 
744*cdf0e10cSrcweir     // following operatons can work on an internal type name only :-(
745*cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::utl::getProcessServiceFactory();
746*cdf0e10cSrcweir     css::uno::Reference< css::document::XTypeDetection > xDetect(xSMGR->createInstance(SERVICENAME_TYPEDETECTION), css::uno::UNO_QUERY);
747*cdf0e10cSrcweir 
748*cdf0e10cSrcweir     ::rtl::OUString sType = xDetect->queryTypeByURL(sURL);
749*cdf0e10cSrcweir 
750*cdf0e10cSrcweir     css::uno::Sequence< css::beans::NamedValue >           lQuery(1)   ;
751*cdf0e10cSrcweir     css::uno::Reference< css::container::XContainerQuery > xContainer  ;
752*cdf0e10cSrcweir     css::uno::Reference< css::container::XEnumeration >    xSet        ;
753*cdf0e10cSrcweir     css::uno::Sequence< ::rtl::OUString >                  lTypesReg(1);
754*cdf0e10cSrcweir 
755*cdf0e10cSrcweir     /*
756*cdf0e10cSrcweir     //-------------------------------------------
757*cdf0e10cSrcweir     lQuery[0].Name    = ::framework::constant::Filter::PROP_TYPE;
758*cdf0e10cSrcweir     lQuery[0].Value <<= sType;
759*cdf0e10cSrcweir 
760*cdf0e10cSrcweir     xContainer = css::uno::Reference< css::container::XContainerQuery >(xSMGR->createInstance(SERVICENAME_FILTERFACTORY), css::uno::UNO_QUERY);
761*cdf0e10cSrcweir     xSet       = xContainer->createSubSetEnumerationByProperties(lQuery);
762*cdf0e10cSrcweir     // at least one registered frame loader is enough!
763*cdf0e10cSrcweir     if (xSet->hasMoreElements())
764*cdf0e10cSrcweir         return E_CAN_BE_LOADED;
765*cdf0e10cSrcweir     */
766*cdf0e10cSrcweir 
767*cdf0e10cSrcweir     //-------------------------------------------
768*cdf0e10cSrcweir     // (iii) If a FrameLoader service (or at least
769*cdf0e10cSrcweir     //      a Filter) can be found, which supports
770*cdf0e10cSrcweir     //      this URL - it must be a loadable content.
771*cdf0e10cSrcweir     //      Because both items are registered for types
772*cdf0e10cSrcweir     //      its enough to check for frame loaders only.
773*cdf0e10cSrcweir     //      Mos of our filters are handled by our global
774*cdf0e10cSrcweir     //      default loader. But there exist some specialized
775*cdf0e10cSrcweir     //      loader, which does not work on top of filters!
776*cdf0e10cSrcweir     //      So its not enough to search on the filter configuration.
777*cdf0e10cSrcweir     //      Further its not enough to search for types!
778*cdf0e10cSrcweir     //      Because there exist some types, which are referenced by
779*cdf0e10cSrcweir     //      other objects ... but not by filters nor frame loaders!
780*cdf0e10cSrcweir 
781*cdf0e10cSrcweir     lTypesReg[0]      = sType;
782*cdf0e10cSrcweir     lQuery[0].Name    = ::framework::constant::FrameLoader::PROP_TYPES;
783*cdf0e10cSrcweir     lQuery[0].Value <<= lTypesReg;
784*cdf0e10cSrcweir 
785*cdf0e10cSrcweir     xContainer = css::uno::Reference< css::container::XContainerQuery >(xSMGR->createInstance(SERVICENAME_FRAMELOADERFACTORY), css::uno::UNO_QUERY);
786*cdf0e10cSrcweir     xSet       = xContainer->createSubSetEnumerationByProperties(lQuery);
787*cdf0e10cSrcweir     // at least one registered frame loader is enough!
788*cdf0e10cSrcweir     if (xSet->hasMoreElements())
789*cdf0e10cSrcweir         return E_CAN_BE_LOADED;
790*cdf0e10cSrcweir 
791*cdf0e10cSrcweir     //-------------------------------------------
792*cdf0e10cSrcweir     // (iv) Some URL protocols are supported by special services.
793*cdf0e10cSrcweir     //      E.g. ContentHandler.
794*cdf0e10cSrcweir     //      Such contents can be handled ... but not loaded.
795*cdf0e10cSrcweir 
796*cdf0e10cSrcweir     lTypesReg[0]      = sType;
797*cdf0e10cSrcweir     lQuery[0].Name    = ::framework::constant::ContentHandler::PROP_TYPES;
798*cdf0e10cSrcweir     lQuery[0].Value <<= lTypesReg;
799*cdf0e10cSrcweir 
800*cdf0e10cSrcweir     xContainer = css::uno::Reference< css::container::XContainerQuery >(xSMGR->createInstance(SERVICENAME_CONTENTHANDLERFACTORY), css::uno::UNO_QUERY);
801*cdf0e10cSrcweir     xSet       = xContainer->createSubSetEnumerationByProperties(lQuery);
802*cdf0e10cSrcweir     // at least one registered content handler is enough!
803*cdf0e10cSrcweir     if (xSet->hasMoreElements())
804*cdf0e10cSrcweir         return E_CAN_BE_HANDLED;
805*cdf0e10cSrcweir 
806*cdf0e10cSrcweir     //-------------------------------------------
807*cdf0e10cSrcweir     // (v) Last but not least the UCB is used inside office to
808*cdf0e10cSrcweir     //     load contents. He has a special configuration to know
809*cdf0e10cSrcweir     //     which URL schemata can be used inside office.
810*cdf0e10cSrcweir     css::uno::Reference< css::ucb::XContentProviderManager > xUCB(xSMGR->createInstance(SERVICENAME_UCBCONTENTBROKER), css::uno::UNO_QUERY);
811*cdf0e10cSrcweir     if (xUCB->queryContentProvider(sURL).is())
812*cdf0e10cSrcweir         return E_CAN_BE_LOADED;
813*cdf0e10cSrcweir 
814*cdf0e10cSrcweir     //-------------------------------------------
815*cdf0e10cSrcweir     // (TODO) At this point, we have no idea .-)
816*cdf0e10cSrcweir     //        But it seems to be better, to break all
817*cdf0e10cSrcweir     //        further requests for this URL. Otherwhise
818*cdf0e10cSrcweir     //        we can run into some trouble.
819*cdf0e10cSrcweir     LOG_WARNING("LoadEnv::classifyContent()", "realy an unsupported content?")
820*cdf0e10cSrcweir     return E_UNSUPPORTED_CONTENT;
821*cdf0e10cSrcweir }
822*cdf0e10cSrcweir 
823*cdf0e10cSrcweir /*-----------------------------------------------
824*cdf0e10cSrcweir     03.11.2003 09:31
825*cdf0e10cSrcweir -----------------------------------------------*/
826*cdf0e10cSrcweir void LoadEnv::impl_detectTypeAndFilter()
827*cdf0e10cSrcweir     throw(LoadEnvException, css::uno::RuntimeException)
828*cdf0e10cSrcweir {
829*cdf0e10cSrcweir     static ::rtl::OUString TYPEPROP_PREFERREDFILTER = ::rtl::OUString::createFromAscii("PreferredFilter");
830*cdf0e10cSrcweir     static ::rtl::OUString FILTERPROP_FLAGS         = ::rtl::OUString::createFromAscii("Flags"          );
831*cdf0e10cSrcweir     static sal_Int32       FILTERFLAG_TEMPLATEPATH  = 16;
832*cdf0e10cSrcweir 
833*cdf0e10cSrcweir     // SAFE ->
834*cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
835*cdf0e10cSrcweir 
836*cdf0e10cSrcweir     // Attention: Because our stl media descriptor is a copy of an uno sequence
837*cdf0e10cSrcweir     // we cant use as an in/out parameter here. Copy it before and dont forget to
838*cdf0e10cSrcweir     // update structure afterwards again!
839*cdf0e10cSrcweir     css::uno::Sequence< css::beans::PropertyValue >        lDescriptor = m_lMediaDescriptor.getAsConstPropertyValueList();
840*cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR       = m_xSMGR;
841*cdf0e10cSrcweir 
842*cdf0e10cSrcweir     aReadLock.unlock();
843*cdf0e10cSrcweir     // <- SAFE
844*cdf0e10cSrcweir 
845*cdf0e10cSrcweir     ::rtl::OUString sType;
846*cdf0e10cSrcweir     css::uno::Reference< css::document::XTypeDetection > xDetect(xSMGR->createInstance(SERVICENAME_TYPEDETECTION), css::uno::UNO_QUERY);
847*cdf0e10cSrcweir     if (xDetect.is())
848*cdf0e10cSrcweir         sType = xDetect->queryTypeByDescriptor(lDescriptor, sal_True); /*TODO should deep detection be able for enable/disable it from outside? */
849*cdf0e10cSrcweir 
850*cdf0e10cSrcweir     // no valid content -> loading not possible
851*cdf0e10cSrcweir     if (!sType.getLength())
852*cdf0e10cSrcweir         throw LoadEnvException(LoadEnvException::ID_UNSUPPORTED_CONTENT);
853*cdf0e10cSrcweir 
854*cdf0e10cSrcweir     // SAFE ->
855*cdf0e10cSrcweir     WriteGuard aWriteLock(m_aLock);
856*cdf0e10cSrcweir 
857*cdf0e10cSrcweir     // detection was successfully => update the descriptor member of this class
858*cdf0e10cSrcweir     m_lMediaDescriptor << lDescriptor;
859*cdf0e10cSrcweir     m_lMediaDescriptor[::comphelper::MediaDescriptor::PROP_TYPENAME()] <<= sType;
860*cdf0e10cSrcweir     // Is there an already detected (may be preselected) filter?
861*cdf0e10cSrcweir     // see below ...
862*cdf0e10cSrcweir     ::rtl::OUString sFilter = m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_FILTERNAME(), ::rtl::OUString());
863*cdf0e10cSrcweir 
864*cdf0e10cSrcweir     aWriteLock.unlock();
865*cdf0e10cSrcweir     // <- SAFE
866*cdf0e10cSrcweir 
867*cdf0e10cSrcweir     // But the type isnt enough. For loading sometimes we need more informations.
868*cdf0e10cSrcweir     // E.g. for our "_default" feature, where we recylce any frame which contains
869*cdf0e10cSrcweir     // and "Untitled" document, we must know if the new document is based on a template!
870*cdf0e10cSrcweir     // But this information is available as a filter property only.
871*cdf0e10cSrcweir     // => We must try(!) to detect the right filter for this load request.
872*cdf0e10cSrcweir     // On the other side ... if no filter is available .. ignore it.
873*cdf0e10cSrcweir     // Then the type information must be enough.
874*cdf0e10cSrcweir     if (!sFilter.getLength())
875*cdf0e10cSrcweir     {
876*cdf0e10cSrcweir         // no -> try to find a preferred filter for the detected type.
877*cdf0e10cSrcweir         // Dont forget to updatet he media descriptor.
878*cdf0e10cSrcweir         css::uno::Reference< css::container::XNameAccess > xTypeCont(xDetect, css::uno::UNO_QUERY_THROW);
879*cdf0e10cSrcweir         try
880*cdf0e10cSrcweir         {
881*cdf0e10cSrcweir             ::comphelper::SequenceAsHashMap lTypeProps(xTypeCont->getByName(sType));
882*cdf0e10cSrcweir             sFilter = lTypeProps.getUnpackedValueOrDefault(TYPEPROP_PREFERREDFILTER, ::rtl::OUString());
883*cdf0e10cSrcweir             if (sFilter.getLength())
884*cdf0e10cSrcweir             {
885*cdf0e10cSrcweir                 // SAFE ->
886*cdf0e10cSrcweir                 aWriteLock.lock();
887*cdf0e10cSrcweir                 m_lMediaDescriptor[::comphelper::MediaDescriptor::PROP_FILTERNAME()] <<= sFilter;
888*cdf0e10cSrcweir                 aWriteLock.unlock();
889*cdf0e10cSrcweir                 // <- SAFE
890*cdf0e10cSrcweir             }
891*cdf0e10cSrcweir         }
892*cdf0e10cSrcweir         catch(const css::container::NoSuchElementException&)
893*cdf0e10cSrcweir             {}
894*cdf0e10cSrcweir     }
895*cdf0e10cSrcweir 
896*cdf0e10cSrcweir     // check if the filter (if one exists) points to a template format filter.
897*cdf0e10cSrcweir     // Then we have to add the property "AsTemplate".
898*cdf0e10cSrcweir     // We need this information to decide afterwards if we can use a "recycle frame"
899*cdf0e10cSrcweir     // for target "_default" or has to create a new one everytimes.
900*cdf0e10cSrcweir     // On the other side we have to supress that, if this property already exists
901*cdf0e10cSrcweir     // and should trigger a special handling. Then the outside calli of this method here,
902*cdf0e10cSrcweir     // has to know, what he is doing .-)
903*cdf0e10cSrcweir 
904*cdf0e10cSrcweir     sal_Bool bIsOwnTemplate = sal_False;
905*cdf0e10cSrcweir     if (sFilter.getLength())
906*cdf0e10cSrcweir     {
907*cdf0e10cSrcweir         css::uno::Reference< css::container::XNameAccess > xFilterCont(xSMGR->createInstance(SERVICENAME_FILTERFACTORY), css::uno::UNO_QUERY_THROW);
908*cdf0e10cSrcweir         try
909*cdf0e10cSrcweir         {
910*cdf0e10cSrcweir             ::comphelper::SequenceAsHashMap lFilterProps(xFilterCont->getByName(sFilter));
911*cdf0e10cSrcweir             sal_Int32 nFlags         = lFilterProps.getUnpackedValueOrDefault(FILTERPROP_FLAGS, (sal_Int32)0);
912*cdf0e10cSrcweir                       bIsOwnTemplate = ((nFlags & FILTERFLAG_TEMPLATEPATH) == FILTERFLAG_TEMPLATEPATH);
913*cdf0e10cSrcweir         }
914*cdf0e10cSrcweir         catch(const css::container::NoSuchElementException&)
915*cdf0e10cSrcweir             {}
916*cdf0e10cSrcweir     }
917*cdf0e10cSrcweir     if (bIsOwnTemplate)
918*cdf0e10cSrcweir     {
919*cdf0e10cSrcweir         // SAFE ->
920*cdf0e10cSrcweir         aWriteLock.lock();
921*cdf0e10cSrcweir         // Dont overwrite external decisions! See comments before ...
922*cdf0e10cSrcweir         ::comphelper::MediaDescriptor::const_iterator pAsTemplateItem = m_lMediaDescriptor.find(::comphelper::MediaDescriptor::PROP_ASTEMPLATE());
923*cdf0e10cSrcweir         if (pAsTemplateItem == m_lMediaDescriptor.end())
924*cdf0e10cSrcweir             m_lMediaDescriptor[::comphelper::MediaDescriptor::PROP_ASTEMPLATE()] <<= sal_True;
925*cdf0e10cSrcweir         aWriteLock.unlock();
926*cdf0e10cSrcweir         // <- SAFE
927*cdf0e10cSrcweir     }
928*cdf0e10cSrcweir }
929*cdf0e10cSrcweir 
930*cdf0e10cSrcweir /*-----------------------------------------------
931*cdf0e10cSrcweir     15.08.2003 09:38
932*cdf0e10cSrcweir -----------------------------------------------*/
933*cdf0e10cSrcweir sal_Bool LoadEnv::impl_handleContent()
934*cdf0e10cSrcweir     throw(LoadEnvException, css::uno::RuntimeException)
935*cdf0e10cSrcweir {
936*cdf0e10cSrcweir     // SAFE -> -----------------------------------
937*cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
938*cdf0e10cSrcweir 
939*cdf0e10cSrcweir     // the type must exist inside the descriptor ... otherwhise this class is implemented wrong :-)
940*cdf0e10cSrcweir     ::rtl::OUString sType = m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_TYPENAME(), ::rtl::OUString());
941*cdf0e10cSrcweir     if (!sType.getLength())
942*cdf0e10cSrcweir         throw LoadEnvException(LoadEnvException::ID_INVALID_MEDIADESCRIPTOR);
943*cdf0e10cSrcweir 
944*cdf0e10cSrcweir     // convert media descriptor and URL to right format for later interface call!
945*cdf0e10cSrcweir     css::uno::Sequence< css::beans::PropertyValue > lDescriptor;
946*cdf0e10cSrcweir     m_lMediaDescriptor >> lDescriptor;
947*cdf0e10cSrcweir     css::util::URL aURL = m_aURL;
948*cdf0e10cSrcweir 
949*cdf0e10cSrcweir     // get neccessary container to query for a handler object
950*cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiServiceFactory > xFactory(m_xSMGR->createInstance(SERVICENAME_CONTENTHANDLERFACTORY), css::uno::UNO_QUERY);
951*cdf0e10cSrcweir     css::uno::Reference< css::container::XContainerQuery > xQuery  (xFactory                                                  , css::uno::UNO_QUERY);
952*cdf0e10cSrcweir 
953*cdf0e10cSrcweir     aReadLock.unlock();
954*cdf0e10cSrcweir     // <- SAFE -----------------------------------
955*cdf0e10cSrcweir 
956*cdf0e10cSrcweir     // query
957*cdf0e10cSrcweir     css::uno::Sequence< ::rtl::OUString > lTypeReg(1);
958*cdf0e10cSrcweir     lTypeReg[0] = sType;
959*cdf0e10cSrcweir 
960*cdf0e10cSrcweir     css::uno::Sequence< css::beans::NamedValue > lQuery(1);
961*cdf0e10cSrcweir     lQuery[0].Name    = ::framework::constant::ContentHandler::PROP_TYPES;
962*cdf0e10cSrcweir     lQuery[0].Value <<= lTypeReg;
963*cdf0e10cSrcweir 
964*cdf0e10cSrcweir     css::uno::Reference< css::container::XEnumeration > xSet = xQuery->createSubSetEnumerationByProperties(lQuery);
965*cdf0e10cSrcweir     while(xSet->hasMoreElements())
966*cdf0e10cSrcweir     {
967*cdf0e10cSrcweir         ::comphelper::SequenceAsHashMap lProps   (xSet->nextElement());
968*cdf0e10cSrcweir         ::rtl::OUString                 sHandler = lProps.getUnpackedValueOrDefault(::framework::constant::ContentHandler::PROP_NAME, ::rtl::OUString());
969*cdf0e10cSrcweir 
970*cdf0e10cSrcweir         css::uno::Reference< css::frame::XNotifyingDispatch > xHandler;
971*cdf0e10cSrcweir         try
972*cdf0e10cSrcweir         {
973*cdf0e10cSrcweir             xHandler = css::uno::Reference< css::frame::XNotifyingDispatch >(xFactory->createInstance(sHandler), css::uno::UNO_QUERY);
974*cdf0e10cSrcweir             if (!xHandler.is())
975*cdf0e10cSrcweir                 continue;
976*cdf0e10cSrcweir         }
977*cdf0e10cSrcweir         catch(const css::uno::RuntimeException&)
978*cdf0e10cSrcweir             { throw; }
979*cdf0e10cSrcweir         catch(const css::uno::Exception&)
980*cdf0e10cSrcweir             { continue; }
981*cdf0e10cSrcweir 
982*cdf0e10cSrcweir         // SAFE -> -----------------------------------
983*cdf0e10cSrcweir         WriteGuard aWriteLock(m_aLock);
984*cdf0e10cSrcweir         m_xAsynchronousJob = xHandler;
985*cdf0e10cSrcweir         m_pCheck           = this;
986*cdf0e10cSrcweir         LoadEnvListener* pListener = new LoadEnvListener(m_pCheck, this);
987*cdf0e10cSrcweir         aWriteLock.unlock();
988*cdf0e10cSrcweir         // <- SAFE -----------------------------------
989*cdf0e10cSrcweir 
990*cdf0e10cSrcweir         css::uno::Reference< css::frame::XDispatchResultListener > xListener(static_cast< css::frame::XDispatchResultListener* >(pListener), css::uno::UNO_QUERY);
991*cdf0e10cSrcweir         xHandler->dispatchWithNotification(aURL, lDescriptor, xListener);
992*cdf0e10cSrcweir 
993*cdf0e10cSrcweir         return sal_True;
994*cdf0e10cSrcweir     }
995*cdf0e10cSrcweir 
996*cdf0e10cSrcweir     return sal_False;
997*cdf0e10cSrcweir }
998*cdf0e10cSrcweir 
999*cdf0e10cSrcweir //-----------------------------------------------
1000*cdf0e10cSrcweir sal_Bool LoadEnv::impl_furtherDocsAllowed()
1001*cdf0e10cSrcweir {
1002*cdf0e10cSrcweir     // SAFE ->
1003*cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
1004*cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
1005*cdf0e10cSrcweir     aReadLock.unlock();
1006*cdf0e10cSrcweir     // <- SAFE
1007*cdf0e10cSrcweir 
1008*cdf0e10cSrcweir     sal_Bool bAllowed = sal_True;
1009*cdf0e10cSrcweir 
1010*cdf0e10cSrcweir     try
1011*cdf0e10cSrcweir     {
1012*cdf0e10cSrcweir         css::uno::Any aVal = ::comphelper::ConfigurationHelper::readDirectKey(
1013*cdf0e10cSrcweir                                 xSMGR,
1014*cdf0e10cSrcweir                                 ::rtl::OUString::createFromAscii("org.openoffice.Office.Common/"),
1015*cdf0e10cSrcweir                                 ::rtl::OUString::createFromAscii("Misc"),
1016*cdf0e10cSrcweir                                 ::rtl::OUString::createFromAscii("MaxOpenDocuments"),
1017*cdf0e10cSrcweir                                 ::comphelper::ConfigurationHelper::E_READONLY);
1018*cdf0e10cSrcweir 
1019*cdf0e10cSrcweir         // NIL means: count of allowed documents = infinite !
1020*cdf0e10cSrcweir         //     => return sal_True
1021*cdf0e10cSrcweir         if ( ! aVal.hasValue())
1022*cdf0e10cSrcweir             bAllowed = sal_True;
1023*cdf0e10cSrcweir         else
1024*cdf0e10cSrcweir         {
1025*cdf0e10cSrcweir             sal_Int32 nMaxOpenDocuments = 0;
1026*cdf0e10cSrcweir             aVal >>= nMaxOpenDocuments;
1027*cdf0e10cSrcweir 
1028*cdf0e10cSrcweir             css::uno::Reference< css::frame::XFramesSupplier > xDesktop(
1029*cdf0e10cSrcweir                 xSMGR->createInstance(SERVICENAME_DESKTOP),
1030*cdf0e10cSrcweir                 css::uno::UNO_QUERY_THROW);
1031*cdf0e10cSrcweir 
1032*cdf0e10cSrcweir             FrameListAnalyzer aAnalyzer(xDesktop,
1033*cdf0e10cSrcweir                                         css::uno::Reference< css::frame::XFrame >(),
1034*cdf0e10cSrcweir                                         FrameListAnalyzer::E_HELP |
1035*cdf0e10cSrcweir                                         FrameListAnalyzer::E_BACKINGCOMPONENT |
1036*cdf0e10cSrcweir                                         FrameListAnalyzer::E_HIDDEN);
1037*cdf0e10cSrcweir 
1038*cdf0e10cSrcweir             sal_Int32 nOpenDocuments = aAnalyzer.m_lOtherVisibleFrames.getLength();
1039*cdf0e10cSrcweir                       bAllowed       = (nOpenDocuments < nMaxOpenDocuments);
1040*cdf0e10cSrcweir         }
1041*cdf0e10cSrcweir     }
1042*cdf0e10cSrcweir     catch(const css::uno::Exception&)
1043*cdf0e10cSrcweir         { bAllowed = sal_True; } // !! internal errors are no reason to disturb the office from opening documents .-)
1044*cdf0e10cSrcweir 
1045*cdf0e10cSrcweir     if ( ! bAllowed )
1046*cdf0e10cSrcweir     {
1047*cdf0e10cSrcweir         // SAFE ->
1048*cdf0e10cSrcweir         aReadLock.lock();
1049*cdf0e10cSrcweir         css::uno::Reference< css::task::XInteractionHandler > xInteraction = m_lMediaDescriptor.getUnpackedValueOrDefault(
1050*cdf0e10cSrcweir                                                                                 ::comphelper::MediaDescriptor::PROP_INTERACTIONHANDLER(),
1051*cdf0e10cSrcweir                                                                                 css::uno::Reference< css::task::XInteractionHandler >());
1052*cdf0e10cSrcweir         aReadLock.unlock();
1053*cdf0e10cSrcweir         // <- SAFE
1054*cdf0e10cSrcweir 
1055*cdf0e10cSrcweir         if (xInteraction.is())
1056*cdf0e10cSrcweir         {
1057*cdf0e10cSrcweir             css::uno::Any                                                                    aInteraction;
1058*cdf0e10cSrcweir             css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > lContinuations(2);
1059*cdf0e10cSrcweir 
1060*cdf0e10cSrcweir             comphelper::OInteractionAbort*   pAbort   = new comphelper::OInteractionAbort();
1061*cdf0e10cSrcweir             comphelper::OInteractionApprove* pApprove = new comphelper::OInteractionApprove();
1062*cdf0e10cSrcweir 
1063*cdf0e10cSrcweir             lContinuations[0] = css::uno::Reference< css::task::XInteractionContinuation >(
1064*cdf0e10cSrcweir                                     static_cast< css::task::XInteractionContinuation* >(pAbort),
1065*cdf0e10cSrcweir                                     css::uno::UNO_QUERY_THROW);
1066*cdf0e10cSrcweir             lContinuations[1] = css::uno::Reference< css::task::XInteractionContinuation >(
1067*cdf0e10cSrcweir                                     static_cast< css::task::XInteractionContinuation* >(pApprove),
1068*cdf0e10cSrcweir                                     css::uno::UNO_QUERY_THROW);
1069*cdf0e10cSrcweir 
1070*cdf0e10cSrcweir             css::task::ErrorCodeRequest aErrorCode;
1071*cdf0e10cSrcweir             aErrorCode.ErrCode = ERRCODE_SFX_NOMOREDOCUMENTSALLOWED;
1072*cdf0e10cSrcweir             aInteraction <<= aErrorCode;
1073*cdf0e10cSrcweir             xInteraction->handle( InteractionRequest::CreateRequest(aInteraction, lContinuations) );
1074*cdf0e10cSrcweir         }
1075*cdf0e10cSrcweir     }
1076*cdf0e10cSrcweir 
1077*cdf0e10cSrcweir     return bAllowed;
1078*cdf0e10cSrcweir }
1079*cdf0e10cSrcweir 
1080*cdf0e10cSrcweir //-----------------------------------------------
1081*cdf0e10cSrcweir sal_Bool LoadEnv::impl_loadContent()
1082*cdf0e10cSrcweir     throw(LoadEnvException, css::uno::RuntimeException)
1083*cdf0e10cSrcweir {
1084*cdf0e10cSrcweir     // SAFE -> -----------------------------------
1085*cdf0e10cSrcweir     WriteGuard aWriteLock(m_aLock);
1086*cdf0e10cSrcweir 
1087*cdf0e10cSrcweir     // search or create right target frame
1088*cdf0e10cSrcweir     ::rtl::OUString sTarget = m_sTarget;
1089*cdf0e10cSrcweir     if (TargetHelper::matchSpecialTarget(sTarget, TargetHelper::E_DEFAULT))
1090*cdf0e10cSrcweir     {
1091*cdf0e10cSrcweir         m_xTargetFrame = impl_searchAlreadyLoaded();
1092*cdf0e10cSrcweir         if (m_xTargetFrame.is())
1093*cdf0e10cSrcweir 		{
1094*cdf0e10cSrcweir 			impl_setResult(sal_True);
1095*cdf0e10cSrcweir 			return sal_True;
1096*cdf0e10cSrcweir 		}
1097*cdf0e10cSrcweir         m_xTargetFrame = impl_searchRecycleTarget();
1098*cdf0e10cSrcweir     }
1099*cdf0e10cSrcweir 
1100*cdf0e10cSrcweir     if (! m_xTargetFrame.is())
1101*cdf0e10cSrcweir     {
1102*cdf0e10cSrcweir         if (
1103*cdf0e10cSrcweir             (TargetHelper::matchSpecialTarget(sTarget, TargetHelper::E_BLANK  )) ||
1104*cdf0e10cSrcweir             (TargetHelper::matchSpecialTarget(sTarget, TargetHelper::E_DEFAULT))
1105*cdf0e10cSrcweir            )
1106*cdf0e10cSrcweir         {
1107*cdf0e10cSrcweir             if (! impl_furtherDocsAllowed())
1108*cdf0e10cSrcweir                 return sal_False;
1109*cdf0e10cSrcweir             m_xTargetFrame       = m_xBaseFrame->findFrame(SPECIALTARGET_BLANK, 0);
1110*cdf0e10cSrcweir             m_bCloseFrameOnError = m_xTargetFrame.is();
1111*cdf0e10cSrcweir         }
1112*cdf0e10cSrcweir         else
1113*cdf0e10cSrcweir         {
1114*cdf0e10cSrcweir             sal_Int32 nFlags = m_nSearchFlags & ~css::frame::FrameSearchFlag::CREATE;
1115*cdf0e10cSrcweir             m_xTargetFrame   = m_xBaseFrame->findFrame(sTarget, nFlags);
1116*cdf0e10cSrcweir             if (! m_xTargetFrame.is())
1117*cdf0e10cSrcweir             {
1118*cdf0e10cSrcweir                 if (! impl_furtherDocsAllowed())
1119*cdf0e10cSrcweir                     return sal_False;
1120*cdf0e10cSrcweir                 m_xTargetFrame       = m_xBaseFrame->findFrame(SPECIALTARGET_BLANK, 0);
1121*cdf0e10cSrcweir                 m_bCloseFrameOnError = m_xTargetFrame.is();
1122*cdf0e10cSrcweir             }
1123*cdf0e10cSrcweir         }
1124*cdf0e10cSrcweir     }
1125*cdf0e10cSrcweir 
1126*cdf0e10cSrcweir     // If we couldn't find a valid frame or the frame has no container window
1127*cdf0e10cSrcweir     // we have to throw an exception.
1128*cdf0e10cSrcweir     if (
1129*cdf0e10cSrcweir         ( ! m_xTargetFrame.is()                       ) ||
1130*cdf0e10cSrcweir         ( ! m_xTargetFrame->getContainerWindow().is() )
1131*cdf0e10cSrcweir        )
1132*cdf0e10cSrcweir         throw LoadEnvException(LoadEnvException::ID_NO_TARGET_FOUND);
1133*cdf0e10cSrcweir 
1134*cdf0e10cSrcweir     css::uno::Reference< css::frame::XFrame > xTargetFrame = m_xTargetFrame;
1135*cdf0e10cSrcweir 
1136*cdf0e10cSrcweir     // Now we have a valid frame ... and type detection was already done.
1137*cdf0e10cSrcweir     // We should apply the module dependend window position and size to the
1138*cdf0e10cSrcweir     // frame window.
1139*cdf0e10cSrcweir     impl_applyPersistentWindowState(xTargetFrame->getContainerWindow());
1140*cdf0e10cSrcweir 
1141*cdf0e10cSrcweir     // Don't forget to lock task for following load process. Otherwise it could die
1142*cdf0e10cSrcweir     // during this operation runs by terminating the office or closing this task via api.
1143*cdf0e10cSrcweir     // If we set this lock "close()" will return false and closing will be broken.
1144*cdf0e10cSrcweir     // Attention: Don't forget to reset this lock again after finishing operation.
1145*cdf0e10cSrcweir     // Otherwise task AND office couldn't die!!!
1146*cdf0e10cSrcweir     // This includes gracefully handling of Exceptions (Runtime!) too ...
1147*cdf0e10cSrcweir     // Thats why we use a specialized guard, which will reset the lock
1148*cdf0e10cSrcweir     // if it will be run out of scope.
1149*cdf0e10cSrcweir 
1150*cdf0e10cSrcweir     // Note further: ignore if this internal guard already contains a resource.
1151*cdf0e10cSrcweir     // Might impl_searchRecylcTarget() set it before. But incase this impl-method wasnt used
1152*cdf0e10cSrcweir     // and the target frame was new created ... this lock here must be set!
1153*cdf0e10cSrcweir     css::uno::Reference< css::document::XActionLockable > xTargetLock(xTargetFrame, css::uno::UNO_QUERY);
1154*cdf0e10cSrcweir     m_aTargetLock.setResource(xTargetLock);
1155*cdf0e10cSrcweir 
1156*cdf0e10cSrcweir     // Add status indicator to descriptor. Loader can show an progresses then.
1157*cdf0e10cSrcweir     // But don't do it, if loading should be hidden or preview is used ...!
1158*cdf0e10cSrcweir     // So we prevent our code against wrong using. Why?
1159*cdf0e10cSrcweir     // It could be, that using of this progress could make trouble. e.g. He make window visible ...
1160*cdf0e10cSrcweir     // but shouldn't do that. But if no indicator is available ... nobody has a chance to do that!
1161*cdf0e10cSrcweir     sal_Bool                                           bHidden    = m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_HIDDEN()         , sal_False                                           );
1162*cdf0e10cSrcweir     sal_Bool                                           bMinimized = m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_MINIMIZED()      , sal_False                                           );
1163*cdf0e10cSrcweir     sal_Bool                                           bPreview   = m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_PREVIEW()        , sal_False                                           );
1164*cdf0e10cSrcweir     css::uno::Reference< css::task::XStatusIndicator > xProgress  = m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_STATUSINDICATOR(), css::uno::Reference< css::task::XStatusIndicator >());
1165*cdf0e10cSrcweir 
1166*cdf0e10cSrcweir     if (!bHidden && !bMinimized && !bPreview && !xProgress.is())
1167*cdf0e10cSrcweir     {
1168*cdf0e10cSrcweir         // Note: its an optional interface!
1169*cdf0e10cSrcweir         css::uno::Reference< css::task::XStatusIndicatorFactory > xProgressFactory(xTargetFrame, css::uno::UNO_QUERY);
1170*cdf0e10cSrcweir         if (xProgressFactory.is())
1171*cdf0e10cSrcweir         {
1172*cdf0e10cSrcweir             xProgress = xProgressFactory->createStatusIndicator();
1173*cdf0e10cSrcweir             if (xProgress.is())
1174*cdf0e10cSrcweir                 m_lMediaDescriptor[::comphelper::MediaDescriptor::PROP_STATUSINDICATOR()] <<= xProgress;
1175*cdf0e10cSrcweir         }
1176*cdf0e10cSrcweir     }
1177*cdf0e10cSrcweir 
1178*cdf0e10cSrcweir     // convert media descriptor and URL to right format for later interface call!
1179*cdf0e10cSrcweir     css::uno::Sequence< css::beans::PropertyValue > lDescriptor;
1180*cdf0e10cSrcweir     m_lMediaDescriptor >> lDescriptor;
1181*cdf0e10cSrcweir     ::rtl::OUString sURL = m_aURL.Complete;
1182*cdf0e10cSrcweir 
1183*cdf0e10cSrcweir     // try to locate any interested frame loader
1184*cdf0e10cSrcweir     css::uno::Reference< css::uno::XInterface >                xLoader     = impl_searchLoader();
1185*cdf0e10cSrcweir     css::uno::Reference< css::frame::XFrameLoader >            xAsyncLoader(xLoader, css::uno::UNO_QUERY);
1186*cdf0e10cSrcweir     css::uno::Reference< css::frame::XSynchronousFrameLoader > xSyncLoader (xLoader, css::uno::UNO_QUERY);
1187*cdf0e10cSrcweir 
1188*cdf0e10cSrcweir     if (xAsyncLoader.is())
1189*cdf0e10cSrcweir     {
1190*cdf0e10cSrcweir         // SAFE -> -----------------------------------
1191*cdf0e10cSrcweir         aWriteLock.lock();
1192*cdf0e10cSrcweir         m_xAsynchronousJob = xAsyncLoader;
1193*cdf0e10cSrcweir         m_pCheck           = this;
1194*cdf0e10cSrcweir         LoadEnvListener* pListener = new LoadEnvListener(m_pCheck, this);
1195*cdf0e10cSrcweir         aWriteLock.unlock();
1196*cdf0e10cSrcweir         // <- SAFE -----------------------------------
1197*cdf0e10cSrcweir 
1198*cdf0e10cSrcweir         css::uno::Reference< css::frame::XLoadEventListener > xListener(static_cast< css::frame::XLoadEventListener* >(pListener), css::uno::UNO_QUERY);
1199*cdf0e10cSrcweir         xAsyncLoader->load(xTargetFrame, sURL, lDescriptor, xListener);
1200*cdf0e10cSrcweir 
1201*cdf0e10cSrcweir         return sal_True;
1202*cdf0e10cSrcweir     }
1203*cdf0e10cSrcweir     else
1204*cdf0e10cSrcweir     if (xSyncLoader.is())
1205*cdf0e10cSrcweir     {
1206*cdf0e10cSrcweir         sal_Bool bResult = xSyncLoader->load(lDescriptor, xTargetFrame);
1207*cdf0e10cSrcweir         // react for the result here, so the outside waiting
1208*cdf0e10cSrcweir         // code can ask for it later.
1209*cdf0e10cSrcweir         impl_setResult(bResult);
1210*cdf0e10cSrcweir         // But the return value indicates a valid started(!) operation.
1211*cdf0e10cSrcweir         // And thats true everxtimes, we reach this line :-)
1212*cdf0e10cSrcweir         return sal_True;
1213*cdf0e10cSrcweir     }
1214*cdf0e10cSrcweir 
1215*cdf0e10cSrcweir     aWriteLock.unlock();
1216*cdf0e10cSrcweir     // <- SAFE
1217*cdf0e10cSrcweir 
1218*cdf0e10cSrcweir     return sal_False;
1219*cdf0e10cSrcweir }
1220*cdf0e10cSrcweir 
1221*cdf0e10cSrcweir /*-----------------------------------------------
1222*cdf0e10cSrcweir     06.02.2004 14:40
1223*cdf0e10cSrcweir -----------------------------------------------*/
1224*cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > LoadEnv::impl_searchLoader()
1225*cdf0e10cSrcweir {
1226*cdf0e10cSrcweir     // SAFE -> -----------------------------------
1227*cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
1228*cdf0e10cSrcweir 
1229*cdf0e10cSrcweir     // special mode to set an existing component on this frame
1230*cdf0e10cSrcweir     // In such case the laoder is fix. It must be the SFX based implementation,
1231*cdf0e10cSrcweir     // which can create a view on top of such xModel components :-)
1232*cdf0e10cSrcweir     if (m_eContentType == E_CAN_BE_SET)
1233*cdf0e10cSrcweir     {
1234*cdf0e10cSrcweir         try
1235*cdf0e10cSrcweir         {
1236*cdf0e10cSrcweir             return m_xSMGR->createInstance(IMPLEMENTATIONNAME_GENERICFRAMELOADER);
1237*cdf0e10cSrcweir         }
1238*cdf0e10cSrcweir         catch(const css::uno::RuntimeException&)
1239*cdf0e10cSrcweir             { throw; }
1240*cdf0e10cSrcweir         catch(const css::uno::Exception&)
1241*cdf0e10cSrcweir             {}
1242*cdf0e10cSrcweir         throw LoadEnvException(LoadEnvException::ID_INVALID_ENVIRONMENT);
1243*cdf0e10cSrcweir     }
1244*cdf0e10cSrcweir 
1245*cdf0e10cSrcweir     // Otherwhise ...
1246*cdf0e10cSrcweir     // We need this type information to locate an registered frame loader
1247*cdf0e10cSrcweir     // Without such information we cant work!
1248*cdf0e10cSrcweir     ::rtl::OUString sType = m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_TYPENAME(), ::rtl::OUString());
1249*cdf0e10cSrcweir     if (!sType.getLength())
1250*cdf0e10cSrcweir         throw LoadEnvException(LoadEnvException::ID_INVALID_MEDIADESCRIPTOR);
1251*cdf0e10cSrcweir 
1252*cdf0e10cSrcweir     // try to locate any interested frame loader
1253*cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiServiceFactory > xLoaderFactory(m_xSMGR->createInstance(SERVICENAME_FRAMELOADERFACTORY), css::uno::UNO_QUERY);
1254*cdf0e10cSrcweir     css::uno::Reference< css::container::XContainerQuery > xQuery        (xLoaderFactory                                         , css::uno::UNO_QUERY);
1255*cdf0e10cSrcweir 
1256*cdf0e10cSrcweir     aReadLock.unlock();
1257*cdf0e10cSrcweir     // <- SAFE -----------------------------------
1258*cdf0e10cSrcweir 
1259*cdf0e10cSrcweir     css::uno::Sequence< ::rtl::OUString > lTypesReg(1);
1260*cdf0e10cSrcweir     lTypesReg[0] = sType;
1261*cdf0e10cSrcweir 
1262*cdf0e10cSrcweir     css::uno::Sequence< css::beans::NamedValue > lQuery(1);
1263*cdf0e10cSrcweir     lQuery[0].Name    = ::framework::constant::FrameLoader::PROP_TYPES;
1264*cdf0e10cSrcweir     lQuery[0].Value <<= lTypesReg;
1265*cdf0e10cSrcweir 
1266*cdf0e10cSrcweir     css::uno::Reference< css::container::XEnumeration > xSet = xQuery->createSubSetEnumerationByProperties(lQuery);
1267*cdf0e10cSrcweir     while(xSet->hasMoreElements())
1268*cdf0e10cSrcweir     {
1269*cdf0e10cSrcweir         // try everyone ...
1270*cdf0e10cSrcweir         // Ignore any loader, which makes trouble :-)
1271*cdf0e10cSrcweir         ::comphelper::SequenceAsHashMap             lLoaderProps(xSet->nextElement());
1272*cdf0e10cSrcweir         ::rtl::OUString                             sLoader     = lLoaderProps.getUnpackedValueOrDefault(::framework::constant::FrameLoader::PROP_NAME, ::rtl::OUString());
1273*cdf0e10cSrcweir         css::uno::Reference< css::uno::XInterface > xLoader     ;
1274*cdf0e10cSrcweir         try
1275*cdf0e10cSrcweir         {
1276*cdf0e10cSrcweir             xLoader = xLoaderFactory->createInstance(sLoader);
1277*cdf0e10cSrcweir             if (xLoader.is())
1278*cdf0e10cSrcweir                 return xLoader;
1279*cdf0e10cSrcweir         }
1280*cdf0e10cSrcweir         catch(const css::uno::RuntimeException&)
1281*cdf0e10cSrcweir             { throw; }
1282*cdf0e10cSrcweir         catch(const css::uno::Exception&)
1283*cdf0e10cSrcweir             { continue; }
1284*cdf0e10cSrcweir     }
1285*cdf0e10cSrcweir 
1286*cdf0e10cSrcweir     return css::uno::Reference< css::uno::XInterface >();
1287*cdf0e10cSrcweir }
1288*cdf0e10cSrcweir 
1289*cdf0e10cSrcweir /*-----------------------------------------------
1290*cdf0e10cSrcweir     24.01.2006 15:11
1291*cdf0e10cSrcweir -----------------------------------------------*/
1292*cdf0e10cSrcweir void LoadEnv::impl_jumpToMark(const css::uno::Reference< css::frame::XFrame >& xFrame,
1293*cdf0e10cSrcweir                               const css::util::URL&                            aURL  )
1294*cdf0e10cSrcweir {
1295*cdf0e10cSrcweir     if (! aURL.Mark.getLength())
1296*cdf0e10cSrcweir         return;
1297*cdf0e10cSrcweir 
1298*cdf0e10cSrcweir     css::uno::Reference< css::frame::XDispatchProvider > xProvider(xFrame, css::uno::UNO_QUERY);
1299*cdf0e10cSrcweir     if (! xProvider.is())
1300*cdf0e10cSrcweir         return;
1301*cdf0e10cSrcweir 
1302*cdf0e10cSrcweir     // SAFE ->
1303*cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
1304*cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
1305*cdf0e10cSrcweir     aReadLock.unlock();
1306*cdf0e10cSrcweir     // <- SAFE
1307*cdf0e10cSrcweir 
1308*cdf0e10cSrcweir     css::util::URL aCmd;
1309*cdf0e10cSrcweir     aCmd.Complete = ::rtl::OUString::createFromAscii(".uno:JumpToMark");
1310*cdf0e10cSrcweir 
1311*cdf0e10cSrcweir     css::uno::Reference< css::util::XURLTransformer > xParser(xSMGR->createInstance(SERVICENAME_URLTRANSFORMER), css::uno::UNO_QUERY_THROW);
1312*cdf0e10cSrcweir     xParser->parseStrict(aCmd);
1313*cdf0e10cSrcweir 
1314*cdf0e10cSrcweir     css::uno::Reference< css::frame::XDispatch > xDispatcher = xProvider->queryDispatch(aCmd, SPECIALTARGET_SELF, 0);
1315*cdf0e10cSrcweir     if (! xDispatcher.is())
1316*cdf0e10cSrcweir         return;
1317*cdf0e10cSrcweir 
1318*cdf0e10cSrcweir     ::comphelper::SequenceAsHashMap lArgs;
1319*cdf0e10cSrcweir     lArgs[::rtl::OUString::createFromAscii("Bookmark")] <<= aURL.Mark;
1320*cdf0e10cSrcweir     xDispatcher->dispatch(aCmd, lArgs.getAsConstPropertyValueList());
1321*cdf0e10cSrcweir }
1322*cdf0e10cSrcweir 
1323*cdf0e10cSrcweir /*-----------------------------------------------
1324*cdf0e10cSrcweir     31.07.2003 09:02
1325*cdf0e10cSrcweir -----------------------------------------------*/
1326*cdf0e10cSrcweir css::uno::Reference< css::frame::XFrame > LoadEnv::impl_searchAlreadyLoaded()
1327*cdf0e10cSrcweir     throw(LoadEnvException, css::uno::RuntimeException)
1328*cdf0e10cSrcweir {
1329*cdf0e10cSrcweir     // SAFE ->
1330*cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
1331*cdf0e10cSrcweir 
1332*cdf0e10cSrcweir     // such search is allowed for special requests only ...
1333*cdf0e10cSrcweir     // or better its not allowed for some requests in general :-)
1334*cdf0e10cSrcweir     if (
1335*cdf0e10cSrcweir         ( ! TargetHelper::matchSpecialTarget(m_sTarget, TargetHelper::E_DEFAULT)                                               ) ||
1336*cdf0e10cSrcweir         (m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_ASTEMPLATE() , sal_False) == sal_True) ||
1337*cdf0e10cSrcweir //      (m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_HIDDEN()     , sal_False) == sal_True) ||
1338*cdf0e10cSrcweir         (m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_OPENNEWVIEW(), sal_False) == sal_True)
1339*cdf0e10cSrcweir        )
1340*cdf0e10cSrcweir     {
1341*cdf0e10cSrcweir         return css::uno::Reference< css::frame::XFrame >();
1342*cdf0e10cSrcweir     }
1343*cdf0e10cSrcweir 
1344*cdf0e10cSrcweir     // check URL
1345*cdf0e10cSrcweir     // May its not usefull to start expensive document search, if it
1346*cdf0e10cSrcweir     // can fail only .. because we load from a stream or model directly!
1347*cdf0e10cSrcweir     if (
1348*cdf0e10cSrcweir         (ProtocolCheck::isProtocol(m_aURL.Complete, ProtocolCheck::E_PRIVATE_STREAM )) ||
1349*cdf0e10cSrcweir         (ProtocolCheck::isProtocol(m_aURL.Complete, ProtocolCheck::E_PRIVATE_OBJECT ))
1350*cdf0e10cSrcweir         /*TODO should be private:factory here tested too? */
1351*cdf0e10cSrcweir        )
1352*cdf0e10cSrcweir     {
1353*cdf0e10cSrcweir         return css::uno::Reference< css::frame::XFrame >();
1354*cdf0e10cSrcweir     }
1355*cdf0e10cSrcweir 
1356*cdf0e10cSrcweir     // otherwhise - iterate through the tasks of the desktop container
1357*cdf0e10cSrcweir     // to find out, which of them might contains the requested document
1358*cdf0e10cSrcweir     css::uno::Reference< css::frame::XFramesSupplier >  xSupplier(m_xSMGR->createInstance(SERVICENAME_DESKTOP), css::uno::UNO_QUERY);
1359*cdf0e10cSrcweir     css::uno::Reference< css::container::XIndexAccess > xTaskList(xSupplier->getFrames()                      , css::uno::UNO_QUERY);
1360*cdf0e10cSrcweir 
1361*cdf0e10cSrcweir     if (!xTaskList.is())
1362*cdf0e10cSrcweir         return css::uno::Reference< css::frame::XFrame >(); // task list can be empty!
1363*cdf0e10cSrcweir 
1364*cdf0e10cSrcweir     // Note: To detect if a document was alrady loaded before
1365*cdf0e10cSrcweir     // we check URLs here only. But might the existing and the requred
1366*cdf0e10cSrcweir     // document has different versions! Then its URLs are the same ...
1367*cdf0e10cSrcweir     sal_Int16 nNewVersion = m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_VERSION(), (sal_Int16)(-1));
1368*cdf0e10cSrcweir 
1369*cdf0e10cSrcweir     // will be used to save the first hidden frame referring the searched model
1370*cdf0e10cSrcweir     // Normaly we are interested on visible frames ... but if there is no such visible
1371*cdf0e10cSrcweir     // frame we referr to any hidden frame also (but as fallback only).
1372*cdf0e10cSrcweir     css::uno::Reference< css::frame::XFrame > xHiddenTask;
1373*cdf0e10cSrcweir     css::uno::Reference< css::frame::XFrame > xTask;
1374*cdf0e10cSrcweir 
1375*cdf0e10cSrcweir     sal_Int32 count = xTaskList->getCount();
1376*cdf0e10cSrcweir     for (sal_Int32 i=0; i<count; ++i)
1377*cdf0e10cSrcweir     {
1378*cdf0e10cSrcweir         try
1379*cdf0e10cSrcweir         {
1380*cdf0e10cSrcweir             // locate model of task
1381*cdf0e10cSrcweir             // Note: Without a model there is no chance to decide if
1382*cdf0e10cSrcweir             // this task contains the searched document or not!
1383*cdf0e10cSrcweir             xTaskList->getByIndex(i) >>= xTask;
1384*cdf0e10cSrcweir             if (!xTask.is())
1385*cdf0e10cSrcweir                 continue;
1386*cdf0e10cSrcweir 
1387*cdf0e10cSrcweir             css::uno::Reference< css::frame::XController > xController = xTask->getController();
1388*cdf0e10cSrcweir             if (!xController.is())
1389*cdf0e10cSrcweir 			{
1390*cdf0e10cSrcweir 				xTask.clear ();
1391*cdf0e10cSrcweir                 continue;
1392*cdf0e10cSrcweir 			}
1393*cdf0e10cSrcweir 
1394*cdf0e10cSrcweir             css::uno::Reference< css::frame::XModel > xModel = xController->getModel();
1395*cdf0e10cSrcweir             if (!xModel.is())
1396*cdf0e10cSrcweir 			{
1397*cdf0e10cSrcweir 				xTask.clear ();
1398*cdf0e10cSrcweir                 continue;
1399*cdf0e10cSrcweir 			}
1400*cdf0e10cSrcweir 
1401*cdf0e10cSrcweir             // don't check the complete URL here.
1402*cdf0e10cSrcweir             // use its main part - ignore optional jumpmarks!
1403*cdf0e10cSrcweir 			const ::rtl::OUString sURL = xModel->getURL();
1404*cdf0e10cSrcweir             if (!::utl::UCBContentHelper::EqualURLs( m_aURL.Main, sURL ))
1405*cdf0e10cSrcweir 			{
1406*cdf0e10cSrcweir 				xTask.clear ();
1407*cdf0e10cSrcweir                 continue;
1408*cdf0e10cSrcweir 			}
1409*cdf0e10cSrcweir 
1410*cdf0e10cSrcweir             // get the original load arguments from the current document
1411*cdf0e10cSrcweir             // and decide if its realy the same then the one will be.
1412*cdf0e10cSrcweir             // It must be visible and must use the same file revision ...
1413*cdf0e10cSrcweir             // or must not have any file revision set (-1 == -1!)
1414*cdf0e10cSrcweir             ::comphelper::MediaDescriptor lOldDocDescriptor(xModel->getArgs());
1415*cdf0e10cSrcweir 
1416*cdf0e10cSrcweir             if (lOldDocDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_VERSION(), (sal_Int32)(-1)) != nNewVersion)
1417*cdf0e10cSrcweir 			{
1418*cdf0e10cSrcweir 				xTask.clear ();
1419*cdf0e10cSrcweir                 continue;
1420*cdf0e10cSrcweir 			}
1421*cdf0e10cSrcweir 
1422*cdf0e10cSrcweir             // Hidden frames are special.
1423*cdf0e10cSrcweir             // They will be used as "last chance" if there is no visible frame pointing to the same model.
1424*cdf0e10cSrcweir             // Safe the result but continue with current loop might be looking for other visible frames.
1425*cdf0e10cSrcweir             ::sal_Bool bIsHidden = lOldDocDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_HIDDEN(), sal_False);
1426*cdf0e10cSrcweir             if (
1427*cdf0e10cSrcweir                 (   bIsHidden       ) &&
1428*cdf0e10cSrcweir                 ( ! xHiddenTask.is())
1429*cdf0e10cSrcweir                )
1430*cdf0e10cSrcweir             {
1431*cdf0e10cSrcweir                 xHiddenTask = xTask;
1432*cdf0e10cSrcweir                 xTask.clear ();
1433*cdf0e10cSrcweir                 continue;
1434*cdf0e10cSrcweir             }
1435*cdf0e10cSrcweir 
1436*cdf0e10cSrcweir             // We found a visible task pointing to the right model ...
1437*cdf0e10cSrcweir             // Break search.
1438*cdf0e10cSrcweir             break;
1439*cdf0e10cSrcweir         }
1440*cdf0e10cSrcweir         catch(const css::uno::RuntimeException& exRun)
1441*cdf0e10cSrcweir             { throw exRun; }
1442*cdf0e10cSrcweir         catch(const css::uno::Exception&)
1443*cdf0e10cSrcweir             { continue; }
1444*cdf0e10cSrcweir     }
1445*cdf0e10cSrcweir 
1446*cdf0e10cSrcweir     css::uno::Reference< css::frame::XFrame > xResult;
1447*cdf0e10cSrcweir     if (xTask.is())
1448*cdf0e10cSrcweir         xResult = xTask;
1449*cdf0e10cSrcweir     else
1450*cdf0e10cSrcweir     if (xHiddenTask.is())
1451*cdf0e10cSrcweir         xResult = xHiddenTask;
1452*cdf0e10cSrcweir 
1453*cdf0e10cSrcweir     if (xResult.is())
1454*cdf0e10cSrcweir     {
1455*cdf0e10cSrcweir         // Now we are shure, that this task includes the searched document.
1456*cdf0e10cSrcweir         // It's time to activate it. As special feature we try to jump internaly
1457*cdf0e10cSrcweir         // if an optional jumpmark is given too.
1458*cdf0e10cSrcweir         if (m_aURL.Mark.getLength())
1459*cdf0e10cSrcweir             impl_jumpToMark(xResult, m_aURL);
1460*cdf0e10cSrcweir 
1461*cdf0e10cSrcweir         // bring it to front and make sure it's visible...
1462*cdf0e10cSrcweir         impl_makeFrameWindowVisible(xResult->getContainerWindow(), sal_True);
1463*cdf0e10cSrcweir     }
1464*cdf0e10cSrcweir 
1465*cdf0e10cSrcweir     aReadLock.unlock();
1466*cdf0e10cSrcweir     // <- SAFE
1467*cdf0e10cSrcweir 
1468*cdf0e10cSrcweir     return xResult;
1469*cdf0e10cSrcweir }
1470*cdf0e10cSrcweir 
1471*cdf0e10cSrcweir /*-----------------------------------------------
1472*cdf0e10cSrcweir     30.03.2004 09:12
1473*cdf0e10cSrcweir -----------------------------------------------*/
1474*cdf0e10cSrcweir sal_Bool LoadEnv::impl_isFrameAlreadyUsedForLoading(const css::uno::Reference< css::frame::XFrame >& xFrame) const
1475*cdf0e10cSrcweir {
1476*cdf0e10cSrcweir     css::uno::Reference< css::document::XActionLockable > xLock(xFrame, css::uno::UNO_QUERY);
1477*cdf0e10cSrcweir 
1478*cdf0e10cSrcweir     // ? no lock interface ?
1479*cdf0e10cSrcweir     // Might its an external written frame implementation :-(
1480*cdf0e10cSrcweir     // Allowing using of it ... but it can fail if its not synchronized with our processes !
1481*cdf0e10cSrcweir     if (!xLock.is())
1482*cdf0e10cSrcweir         return sal_False;
1483*cdf0e10cSrcweir 
1484*cdf0e10cSrcweir     // Otherwhise we have to look for any other existing lock.
1485*cdf0e10cSrcweir     return xLock->isActionLocked();
1486*cdf0e10cSrcweir }
1487*cdf0e10cSrcweir 
1488*cdf0e10cSrcweir /*-----------------------------------------------
1489*cdf0e10cSrcweir     30.03.2004 09:12
1490*cdf0e10cSrcweir -----------------------------------------------*/
1491*cdf0e10cSrcweir css::uno::Reference< css::frame::XFrame > LoadEnv::impl_searchRecycleTarget()
1492*cdf0e10cSrcweir     throw(LoadEnvException, css::uno::RuntimeException)
1493*cdf0e10cSrcweir {
1494*cdf0e10cSrcweir     // SAFE -> ..................................
1495*cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
1496*cdf0e10cSrcweir 
1497*cdf0e10cSrcweir     // The special backing mode frame will be recycled by definition!
1498*cdf0e10cSrcweir     // It does'nt matter if somehwere whish to create a new view
1499*cdf0e10cSrcweir     // or open a new untitled document ...
1500*cdf0e10cSrcweir     // The only exception form that - hidden frames!
1501*cdf0e10cSrcweir     if (m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_HIDDEN(), sal_False) == sal_True)
1502*cdf0e10cSrcweir         return css::uno::Reference< css::frame::XFrame >();
1503*cdf0e10cSrcweir 
1504*cdf0e10cSrcweir     css::uno::Reference< css::frame::XFramesSupplier > xSupplier(m_xSMGR->createInstance(SERVICENAME_DESKTOP), css::uno::UNO_QUERY);
1505*cdf0e10cSrcweir     FrameListAnalyzer aTasksAnalyzer(xSupplier, css::uno::Reference< css::frame::XFrame >(), FrameListAnalyzer::E_BACKINGCOMPONENT);
1506*cdf0e10cSrcweir     if (aTasksAnalyzer.m_xBackingComponent.is())
1507*cdf0e10cSrcweir     {
1508*cdf0e10cSrcweir         if (!impl_isFrameAlreadyUsedForLoading(aTasksAnalyzer.m_xBackingComponent))
1509*cdf0e10cSrcweir         {
1510*cdf0e10cSrcweir             // bring it to front ...
1511*cdf0e10cSrcweir             impl_makeFrameWindowVisible(aTasksAnalyzer.m_xBackingComponent->getContainerWindow(), sal_True);
1512*cdf0e10cSrcweir             return aTasksAnalyzer.m_xBackingComponent;
1513*cdf0e10cSrcweir         }
1514*cdf0e10cSrcweir     }
1515*cdf0e10cSrcweir 
1516*cdf0e10cSrcweir     // These states indicates the wishing for creation of a new view in general.
1517*cdf0e10cSrcweir     if (
1518*cdf0e10cSrcweir         (m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_ASTEMPLATE() , sal_False) == sal_True) ||
1519*cdf0e10cSrcweir         (m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_OPENNEWVIEW(), sal_False) == sal_True)
1520*cdf0e10cSrcweir        )
1521*cdf0e10cSrcweir     {
1522*cdf0e10cSrcweir         return css::uno::Reference< css::frame::XFrame >();
1523*cdf0e10cSrcweir     }
1524*cdf0e10cSrcweir 
1525*cdf0e10cSrcweir 	// On the other side some special URLs will open a new frame everytimes (expecting
1526*cdf0e10cSrcweir 	// they can use the backing-mode frame!)
1527*cdf0e10cSrcweir     if (
1528*cdf0e10cSrcweir         (ProtocolCheck::isProtocol(m_aURL.Complete, ProtocolCheck::E_PRIVATE_FACTORY )) ||
1529*cdf0e10cSrcweir         (ProtocolCheck::isProtocol(m_aURL.Complete, ProtocolCheck::E_PRIVATE_STREAM  )) ||
1530*cdf0e10cSrcweir         (ProtocolCheck::isProtocol(m_aURL.Complete, ProtocolCheck::E_PRIVATE_OBJECT  ))
1531*cdf0e10cSrcweir        )
1532*cdf0e10cSrcweir     {
1533*cdf0e10cSrcweir         return css::uno::Reference< css::frame::XFrame >();
1534*cdf0e10cSrcweir     }
1535*cdf0e10cSrcweir 
1536*cdf0e10cSrcweir 	// No backing frame! No special URL => recycle active task - if possible.
1537*cdf0e10cSrcweir 	// Means - if it does not already contains a modified document, or
1538*cdf0e10cSrcweir 	// use another office module.
1539*cdf0e10cSrcweir     css::uno::Reference< css::frame::XFrame > xTask = xSupplier->getActiveFrame();
1540*cdf0e10cSrcweir 
1541*cdf0e10cSrcweir     // not a real error - but might a focus problem!
1542*cdf0e10cSrcweir     if (!xTask.is())
1543*cdf0e10cSrcweir         return css::uno::Reference< css::frame::XFrame >();
1544*cdf0e10cSrcweir 
1545*cdf0e10cSrcweir     // not a real error - may its a view only
1546*cdf0e10cSrcweir     css::uno::Reference< css::frame::XController > xController = xTask->getController();
1547*cdf0e10cSrcweir     if (!xController.is())
1548*cdf0e10cSrcweir         return css::uno::Reference< css::frame::XFrame >();
1549*cdf0e10cSrcweir 
1550*cdf0e10cSrcweir     // not a real error - may its a db component instead of a full feartured office document
1551*cdf0e10cSrcweir     css::uno::Reference< css::frame::XModel > xModel = xController->getModel();
1552*cdf0e10cSrcweir     if (!xModel.is())
1553*cdf0e10cSrcweir         return css::uno::Reference< css::frame::XFrame >();
1554*cdf0e10cSrcweir 
1555*cdf0e10cSrcweir     // get some more informations ...
1556*cdf0e10cSrcweir 
1557*cdf0e10cSrcweir     // A valid set URL means: there is already a location for this document.
1558*cdf0e10cSrcweir     // => it was saved there or opened from there. Such Documents can not be used here.
1559*cdf0e10cSrcweir     // We search for empty document ... created by a private:factory/ URL!
1560*cdf0e10cSrcweir     if (xModel->getURL().getLength()>0)
1561*cdf0e10cSrcweir         return css::uno::Reference< css::frame::XFrame >();
1562*cdf0e10cSrcweir 
1563*cdf0e10cSrcweir     // The old document must be unmodified ...
1564*cdf0e10cSrcweir     css::uno::Reference< css::util::XModifiable > xModified(xModel, css::uno::UNO_QUERY);
1565*cdf0e10cSrcweir     if (xModified->isModified())
1566*cdf0e10cSrcweir         return css::uno::Reference< css::frame::XFrame >();
1567*cdf0e10cSrcweir 
1568*cdf0e10cSrcweir     Window* pWindow = VCLUnoHelper::GetWindow(xTask->getContainerWindow());
1569*cdf0e10cSrcweir     if (pWindow && pWindow->IsInModalMode())
1570*cdf0e10cSrcweir         return css::uno::Reference< css::frame::XFrame >();
1571*cdf0e10cSrcweir 
1572*cdf0e10cSrcweir     // find out the application type of this document
1573*cdf0e10cSrcweir     // We can recycle only documents, which uses the same application
1574*cdf0e10cSrcweir     // then the new one.
1575*cdf0e10cSrcweir     SvtModuleOptions::EFactory eOldApp = SvtModuleOptions::ClassifyFactoryByModel(xModel);
1576*cdf0e10cSrcweir     SvtModuleOptions::EFactory eNewApp = SvtModuleOptions::ClassifyFactoryByURL  (m_aURL.Complete, m_lMediaDescriptor.getAsConstPropertyValueList());
1577*cdf0e10cSrcweir 
1578*cdf0e10cSrcweir     aReadLock.unlock();
1579*cdf0e10cSrcweir     // <- SAFE ..................................
1580*cdf0e10cSrcweir 
1581*cdf0e10cSrcweir     if (eOldApp != eNewApp)
1582*cdf0e10cSrcweir         return css::uno::Reference< css::frame::XFrame >();
1583*cdf0e10cSrcweir 
1584*cdf0e10cSrcweir     // OK this task seams to be useable for recycling
1585*cdf0e10cSrcweir     // But we should mark it as such - means set an action lock.
1586*cdf0e10cSrcweir     // Otherwhise it would be used more then ones or will be destroyed
1587*cdf0e10cSrcweir     // by a close() or terminate() request.
1588*cdf0e10cSrcweir     // But if such lock already exist ... it means this task is used for
1589*cdf0e10cSrcweir     // any other operation already. Don't use it then.
1590*cdf0e10cSrcweir     if (impl_isFrameAlreadyUsedForLoading(xTask))
1591*cdf0e10cSrcweir         return css::uno::Reference< css::frame::XFrame >();
1592*cdf0e10cSrcweir 
1593*cdf0e10cSrcweir     // OK - there is a valid target frame.
1594*cdf0e10cSrcweir     // But may be it contains already a document.
1595*cdf0e10cSrcweir     // Then we have to ask it, if it allows recylcing of this frame .-)
1596*cdf0e10cSrcweir     sal_Bool bReactivateOldControllerOnError = sal_False;
1597*cdf0e10cSrcweir     css::uno::Reference< css::frame::XController > xOldDoc = xTask->getController();
1598*cdf0e10cSrcweir     if (xOldDoc.is())
1599*cdf0e10cSrcweir     {
1600*cdf0e10cSrcweir         bReactivateOldControllerOnError = xOldDoc->suspend(sal_True);
1601*cdf0e10cSrcweir         if (! bReactivateOldControllerOnError)
1602*cdf0e10cSrcweir             return css::uno::Reference< css::frame::XFrame >();
1603*cdf0e10cSrcweir     }
1604*cdf0e10cSrcweir 
1605*cdf0e10cSrcweir     // SAFE -> ..................................
1606*cdf0e10cSrcweir     WriteGuard aWriteLock(m_aLock);
1607*cdf0e10cSrcweir 
1608*cdf0e10cSrcweir     css::uno::Reference< css::document::XActionLockable > xLock(xTask, css::uno::UNO_QUERY);
1609*cdf0e10cSrcweir     if (!m_aTargetLock.setResource(xLock))
1610*cdf0e10cSrcweir         return css::uno::Reference< css::frame::XFrame >();
1611*cdf0e10cSrcweir 
1612*cdf0e10cSrcweir     m_bReactivateControllerOnError = bReactivateOldControllerOnError;
1613*cdf0e10cSrcweir     aWriteLock.unlock();
1614*cdf0e10cSrcweir     // <- SAFE ..................................
1615*cdf0e10cSrcweir 
1616*cdf0e10cSrcweir     // bring it to front ...
1617*cdf0e10cSrcweir     impl_makeFrameWindowVisible(xTask->getContainerWindow(), sal_True);
1618*cdf0e10cSrcweir 
1619*cdf0e10cSrcweir     return xTask;
1620*cdf0e10cSrcweir }
1621*cdf0e10cSrcweir 
1622*cdf0e10cSrcweir /*-----------------------------------------------
1623*cdf0e10cSrcweir     15.08.2003 12:39
1624*cdf0e10cSrcweir -----------------------------------------------*/
1625*cdf0e10cSrcweir void LoadEnv::impl_reactForLoadingState()
1626*cdf0e10cSrcweir     throw(LoadEnvException, css::uno::RuntimeException)
1627*cdf0e10cSrcweir {
1628*cdf0e10cSrcweir     /*TODO reset action locks */
1629*cdf0e10cSrcweir 
1630*cdf0e10cSrcweir     // SAFE -> ----------------------------------
1631*cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
1632*cdf0e10cSrcweir 
1633*cdf0e10cSrcweir     if (m_bLoaded)
1634*cdf0e10cSrcweir     {
1635*cdf0e10cSrcweir         // Bring the new loaded document to front (if allowed!).
1636*cdf0e10cSrcweir         // Note: We show new created frames here only.
1637*cdf0e10cSrcweir         // We dont hide already visible frames here ...
1638*cdf0e10cSrcweir         css::uno::Reference< css::awt::XWindow > xWindow      = m_xTargetFrame->getContainerWindow();
1639*cdf0e10cSrcweir         sal_Bool                                 bHidden      = m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_HIDDEN(), sal_False);
1640*cdf0e10cSrcweir         sal_Bool                                 bMinimized = m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_MINIMIZED(), sal_False);
1641*cdf0e10cSrcweir 
1642*cdf0e10cSrcweir         if (bMinimized)
1643*cdf0e10cSrcweir         {
1644*cdf0e10cSrcweir             ::vos::OClearableGuard aSolarGuard(Application::GetSolarMutex());
1645*cdf0e10cSrcweir             Window* pWindow = VCLUnoHelper::GetWindow(xWindow);
1646*cdf0e10cSrcweir             // check for system window is neccessary to guarantee correct pointer cast!
1647*cdf0e10cSrcweir             if (pWindow && pWindow->IsSystemWindow())
1648*cdf0e10cSrcweir                 ((WorkWindow*)pWindow)->Minimize();
1649*cdf0e10cSrcweir         }
1650*cdf0e10cSrcweir         else
1651*cdf0e10cSrcweir         if (!bHidden)
1652*cdf0e10cSrcweir         {
1653*cdf0e10cSrcweir             // show frame ... if it's not still visible ...
1654*cdf0e10cSrcweir             // But do nothing if it's already visible!
1655*cdf0e10cSrcweir             impl_makeFrameWindowVisible(xWindow, sal_False);
1656*cdf0e10cSrcweir         }
1657*cdf0e10cSrcweir 
1658*cdf0e10cSrcweir         // Note: Only if an existing property "FrameName" is given by this media descriptor,
1659*cdf0e10cSrcweir         // it should be used. Otherwhise we should do nothing. May be the outside code has already
1660*cdf0e10cSrcweir         // set a frame name on the target!
1661*cdf0e10cSrcweir         ::comphelper::MediaDescriptor::const_iterator pFrameName = m_lMediaDescriptor.find(::comphelper::MediaDescriptor::PROP_FRAMENAME());
1662*cdf0e10cSrcweir         if (pFrameName != m_lMediaDescriptor.end())
1663*cdf0e10cSrcweir         {
1664*cdf0e10cSrcweir             ::rtl::OUString sFrameName;
1665*cdf0e10cSrcweir             pFrameName->second >>= sFrameName;
1666*cdf0e10cSrcweir             // Check the name again. e.g. "_default" isnt allowed.
1667*cdf0e10cSrcweir             // On the other side "_beamer" is a valid name :-)
1668*cdf0e10cSrcweir             if (TargetHelper::isValidNameForFrame(sFrameName))
1669*cdf0e10cSrcweir                 m_xTargetFrame->setName(sFrameName);
1670*cdf0e10cSrcweir         }
1671*cdf0e10cSrcweir     }
1672*cdf0e10cSrcweir     else if (m_bReactivateControllerOnError)
1673*cdf0e10cSrcweir 	{
1674*cdf0e10cSrcweir 		// Try to reactivate the old document (if any exists!)
1675*cdf0e10cSrcweir 		css::uno::Reference< css::frame::XController > xOldDoc = m_xTargetFrame->getController();
1676*cdf0e10cSrcweir 		// clear does not depend from reactivation state of a might existing old document!
1677*cdf0e10cSrcweir 		// We must make shure, that a might following getTargetComponent() call does not return
1678*cdf0e10cSrcweir 		// the old document!
1679*cdf0e10cSrcweir 		m_xTargetFrame.clear();
1680*cdf0e10cSrcweir 		if (xOldDoc.is())
1681*cdf0e10cSrcweir 		{
1682*cdf0e10cSrcweir 			sal_Bool bReactivated = xOldDoc->suspend(sal_False);
1683*cdf0e10cSrcweir 			if (!bReactivated)
1684*cdf0e10cSrcweir 				throw LoadEnvException(LoadEnvException::ID_COULD_NOT_REACTIVATE_CONTROLLER);
1685*cdf0e10cSrcweir 			m_bReactivateControllerOnError = sal_False;
1686*cdf0e10cSrcweir 		}
1687*cdf0e10cSrcweir 	}
1688*cdf0e10cSrcweir 	else if (m_bCloseFrameOnError)
1689*cdf0e10cSrcweir 	{
1690*cdf0e10cSrcweir 		// close empty frames
1691*cdf0e10cSrcweir 		css::uno::Reference< css::util::XCloseable > xCloseable (m_xTargetFrame, css::uno::UNO_QUERY);
1692*cdf0e10cSrcweir 		css::uno::Reference< css::lang::XComponent > xDisposable(m_xTargetFrame, css::uno::UNO_QUERY);
1693*cdf0e10cSrcweir 
1694*cdf0e10cSrcweir 		try
1695*cdf0e10cSrcweir 		{
1696*cdf0e10cSrcweir 			if (xCloseable.is())
1697*cdf0e10cSrcweir 				xCloseable->close(sal_True);
1698*cdf0e10cSrcweir 			else
1699*cdf0e10cSrcweir 			if (xDisposable.is())
1700*cdf0e10cSrcweir 				xDisposable->dispose();
1701*cdf0e10cSrcweir 		}
1702*cdf0e10cSrcweir 		catch(const css::util::CloseVetoException&)
1703*cdf0e10cSrcweir 		{}
1704*cdf0e10cSrcweir 		catch(const css::lang::DisposedException&)
1705*cdf0e10cSrcweir 		{}
1706*cdf0e10cSrcweir 		m_xTargetFrame.clear();
1707*cdf0e10cSrcweir 	}
1708*cdf0e10cSrcweir 
1709*cdf0e10cSrcweir     // This max force an implicit closing of our target frame ...
1710*cdf0e10cSrcweir     // e.g. in case close(sal_True) was called before and the frame
1711*cdf0e10cSrcweir     // kill itself if our external use-lock is released here!
1712*cdf0e10cSrcweir     // Thats why we releas this lock AFTER ALL OPERATIONS on this frame
1713*cdf0e10cSrcweir     // are finished. The frame itslef must handle then
1714*cdf0e10cSrcweir     // this situation gracefully.
1715*cdf0e10cSrcweir     m_aTargetLock.freeResource();
1716*cdf0e10cSrcweir 
1717*cdf0e10cSrcweir     // Last but not least :-)
1718*cdf0e10cSrcweir     // We have to clear the current media descriptor.
1719*cdf0e10cSrcweir     // Otherwhise it hold a might existing stream open!
1720*cdf0e10cSrcweir     m_lMediaDescriptor.clear();
1721*cdf0e10cSrcweir 
1722*cdf0e10cSrcweir 	css::uno::Any aRequest;
1723*cdf0e10cSrcweir 	bool bThrow = false;
1724*cdf0e10cSrcweir 	if ( !m_bLoaded && m_pQuietInteraction && m_pQuietInteraction->wasUsed() )
1725*cdf0e10cSrcweir 	{
1726*cdf0e10cSrcweir 		aRequest = m_pQuietInteraction->getRequest();
1727*cdf0e10cSrcweir 		m_pQuietInteraction->release();
1728*cdf0e10cSrcweir 		m_pQuietInteraction = 0;
1729*cdf0e10cSrcweir 		bThrow = true;
1730*cdf0e10cSrcweir 	}
1731*cdf0e10cSrcweir 
1732*cdf0e10cSrcweir     aReadLock.unlock();
1733*cdf0e10cSrcweir 
1734*cdf0e10cSrcweir 	if (bThrow)
1735*cdf0e10cSrcweir 	{
1736*cdf0e10cSrcweir         if  ( aRequest.isExtractableTo( ::cppu::UnoType< css::uno::Exception >::get() ) )
1737*cdf0e10cSrcweir 			throw LoadEnvException( LoadEnvException::ID_GENERAL_ERROR, aRequest );
1738*cdf0e10cSrcweir 	}
1739*cdf0e10cSrcweir 
1740*cdf0e10cSrcweir     // <- SAFE ----------------------------------
1741*cdf0e10cSrcweir }
1742*cdf0e10cSrcweir 
1743*cdf0e10cSrcweir /*-----------------------------------------------
1744*cdf0e10cSrcweir     16.01.2005 13:04
1745*cdf0e10cSrcweir -----------------------------------------------*/
1746*cdf0e10cSrcweir void LoadEnv::impl_makeFrameWindowVisible(const css::uno::Reference< css::awt::XWindow >& xWindow      ,
1747*cdf0e10cSrcweir                                                 sal_Bool bForceToFront)
1748*cdf0e10cSrcweir {
1749*cdf0e10cSrcweir     // SAFE -> ----------------------------------
1750*cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
1751*cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR( m_xSMGR.get(), css::uno::UNO_QUERY );
1752*cdf0e10cSrcweir     aReadLock.unlock();
1753*cdf0e10cSrcweir     // <- SAFE ----------------------------------
1754*cdf0e10cSrcweir 
1755*cdf0e10cSrcweir     ::vos::OClearableGuard aSolarGuard(Application::GetSolarMutex());
1756*cdf0e10cSrcweir     Window* pWindow = VCLUnoHelper::GetWindow(xWindow);
1757*cdf0e10cSrcweir     if ( pWindow )
1758*cdf0e10cSrcweir     {
1759*cdf0e10cSrcweir         bool bForceFrontAndFocus(false);
1760*cdf0e10cSrcweir         css::uno::Any a = ::comphelper::ConfigurationHelper::readDirectKey(
1761*cdf0e10cSrcweir             xSMGR,
1762*cdf0e10cSrcweir             ::rtl::OUString::createFromAscii("org.openoffice.Office.Common/View"),
1763*cdf0e10cSrcweir             ::rtl::OUString::createFromAscii("NewDocumentHandling"),
1764*cdf0e10cSrcweir             ::rtl::OUString::createFromAscii("ForceFocusAndToFront"),
1765*cdf0e10cSrcweir             ::comphelper::ConfigurationHelper::E_READONLY);
1766*cdf0e10cSrcweir         a >>= bForceFrontAndFocus;
1767*cdf0e10cSrcweir 
1768*cdf0e10cSrcweir         if( pWindow->IsVisible() && (bForceFrontAndFocus || bForceToFront) )
1769*cdf0e10cSrcweir             pWindow->ToTop();
1770*cdf0e10cSrcweir         else
1771*cdf0e10cSrcweir             pWindow->Show(sal_True, (bForceFrontAndFocus || bForceToFront) ? SHOW_FOREGROUNDTASK : 0 );
1772*cdf0e10cSrcweir     }
1773*cdf0e10cSrcweir 
1774*cdf0e10cSrcweir /* #i19976#
1775*cdf0e10cSrcweir     We tried to prevent a toFront() call in case the user putted the
1776*cdf0e10cSrcweir     loading document into the background ..
1777*cdf0e10cSrcweir     But we had several errors trying that. So we decided to
1778*cdf0e10cSrcweir     rollback these changes and bring the new loaded document to front hardly !
1779*cdf0e10cSrcweir 
1780*cdf0e10cSrcweir     css::uno::Reference< css::awt::XWindow2 > xWindow2(xWindow, css::uno::UNO_QUERY);
1781*cdf0e10cSrcweir 
1782*cdf0e10cSrcweir     sal_Bool bIsVisible = sal_False;
1783*cdf0e10cSrcweir     if (xWindow2.is())
1784*cdf0e10cSrcweir         bIsVisible = xWindow2->isVisible(); // TODO is parent visible too ? .-)
1785*cdf0e10cSrcweir 
1786*cdf0e10cSrcweir     if (!bIsVisible)
1787*cdf0e10cSrcweir     {
1788*cdf0e10cSrcweir         xWindow->setVisible(sal_True);
1789*cdf0e10cSrcweir         bForceToFront = sal_True;
1790*cdf0e10cSrcweir     }
1791*cdf0e10cSrcweir 
1792*cdf0e10cSrcweir     if (
1793*cdf0e10cSrcweir         (bForceToFront  ) &&
1794*cdf0e10cSrcweir         (xTopWindow.is())
1795*cdf0e10cSrcweir        )
1796*cdf0e10cSrcweir     {
1797*cdf0e10cSrcweir         xTopWindow->toFront();
1798*cdf0e10cSrcweir     }
1799*cdf0e10cSrcweir */
1800*cdf0e10cSrcweir }
1801*cdf0e10cSrcweir 
1802*cdf0e10cSrcweir /*-----------------------------------------------
1803*cdf0e10cSrcweir     15.03.2005 11:12
1804*cdf0e10cSrcweir -----------------------------------------------*/
1805*cdf0e10cSrcweir void LoadEnv::impl_applyPersistentWindowState(const css::uno::Reference< css::awt::XWindow >& xWindow)
1806*cdf0e10cSrcweir {
1807*cdf0e10cSrcweir     static ::rtl::OUString PACKAGE_SETUP_MODULES = ::rtl::OUString::createFromAscii("/org.openoffice.Setup/Office/Factories");
1808*cdf0e10cSrcweir 
1809*cdf0e10cSrcweir     // no window -> action not possible
1810*cdf0e10cSrcweir     if (!xWindow.is())
1811*cdf0e10cSrcweir         return;
1812*cdf0e10cSrcweir 
1813*cdf0e10cSrcweir     // window already visible -> do nothing! If we use a "recycle frame" for loading ...
1814*cdf0e10cSrcweir     // the current position and size must be used.
1815*cdf0e10cSrcweir     css::uno::Reference< css::awt::XWindow2 > xVisibleCheck(xWindow, css::uno::UNO_QUERY);
1816*cdf0e10cSrcweir     if (
1817*cdf0e10cSrcweir         (xVisibleCheck.is()        ) &&
1818*cdf0e10cSrcweir         (xVisibleCheck->isVisible())
1819*cdf0e10cSrcweir        )
1820*cdf0e10cSrcweir        return;
1821*cdf0e10cSrcweir 
1822*cdf0e10cSrcweir     // SOLAR SAFE ->
1823*cdf0e10cSrcweir     ::vos::OClearableGuard aSolarLock1(Application::GetSolarMutex());
1824*cdf0e10cSrcweir 
1825*cdf0e10cSrcweir     Window*  pWindow       = VCLUnoHelper::GetWindow(xWindow);
1826*cdf0e10cSrcweir     sal_Bool bSystemWindow = pWindow->IsSystemWindow();
1827*cdf0e10cSrcweir     sal_Bool bWorkWindow   = (pWindow->GetType() == WINDOW_WORKWINDOW);
1828*cdf0e10cSrcweir 
1829*cdf0e10cSrcweir     if (!bSystemWindow && !bWorkWindow)
1830*cdf0e10cSrcweir         return;
1831*cdf0e10cSrcweir 
1832*cdf0e10cSrcweir     // dont overwrite this special state!
1833*cdf0e10cSrcweir     WorkWindow* pWorkWindow = (WorkWindow*)pWindow;
1834*cdf0e10cSrcweir     if (pWorkWindow->IsMinimized())
1835*cdf0e10cSrcweir         return;
1836*cdf0e10cSrcweir 
1837*cdf0e10cSrcweir     aSolarLock1.clear();
1838*cdf0e10cSrcweir     // <- SOLAR SAFE
1839*cdf0e10cSrcweir 
1840*cdf0e10cSrcweir     // SAFE ->
1841*cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
1842*cdf0e10cSrcweir 
1843*cdf0e10cSrcweir     // no filter -> no module -> no persistent window state
1844*cdf0e10cSrcweir     ::rtl::OUString sFilter = m_lMediaDescriptor.getUnpackedValueOrDefault(
1845*cdf0e10cSrcweir                                     ::comphelper::MediaDescriptor::PROP_FILTERNAME(),
1846*cdf0e10cSrcweir                                     ::rtl::OUString());
1847*cdf0e10cSrcweir     if (!sFilter.getLength())
1848*cdf0e10cSrcweir         return;
1849*cdf0e10cSrcweir 
1850*cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
1851*cdf0e10cSrcweir 
1852*cdf0e10cSrcweir     aReadLock.unlock();
1853*cdf0e10cSrcweir     // <- SAFE
1854*cdf0e10cSrcweir 
1855*cdf0e10cSrcweir     try
1856*cdf0e10cSrcweir     {
1857*cdf0e10cSrcweir         // retrieve the module name from the filter configuration
1858*cdf0e10cSrcweir         css::uno::Reference< css::container::XNameAccess > xFilterCfg(
1859*cdf0e10cSrcweir             xSMGR->createInstance(SERVICENAME_FILTERFACTORY),
1860*cdf0e10cSrcweir             css::uno::UNO_QUERY_THROW);
1861*cdf0e10cSrcweir         ::comphelper::SequenceAsHashMap lProps (xFilterCfg->getByName(sFilter));
1862*cdf0e10cSrcweir         ::rtl::OUString                 sModule = lProps.getUnpackedValueOrDefault(FILTER_PROPNAME_DOCUMENTSERVICE, ::rtl::OUString());
1863*cdf0e10cSrcweir 
1864*cdf0e10cSrcweir         // get access to the configuration of this office module
1865*cdf0e10cSrcweir         css::uno::Reference< css::container::XNameAccess > xModuleCfg(::comphelper::ConfigurationHelper::openConfig(
1866*cdf0e10cSrcweir                                                                         xSMGR,
1867*cdf0e10cSrcweir                                                                         PACKAGE_SETUP_MODULES,
1868*cdf0e10cSrcweir                                                                         ::comphelper::ConfigurationHelper::E_READONLY),
1869*cdf0e10cSrcweir                                                                       css::uno::UNO_QUERY_THROW);
1870*cdf0e10cSrcweir 
1871*cdf0e10cSrcweir         // read window state from the configuration
1872*cdf0e10cSrcweir         // and apply it on the window.
1873*cdf0e10cSrcweir         // Do nothing, if no configuration entry exists!
1874*cdf0e10cSrcweir         ::rtl::OUString sWindowState ;
1875*cdf0e10cSrcweir         ::comphelper::ConfigurationHelper::readRelativeKey(xModuleCfg, sModule, OFFICEFACTORY_PROPNAME_WINDOWATTRIBUTES) >>= sWindowState;
1876*cdf0e10cSrcweir         if (sWindowState.getLength())
1877*cdf0e10cSrcweir         {
1878*cdf0e10cSrcweir             // SOLAR SAFE ->
1879*cdf0e10cSrcweir             ::vos::OClearableGuard aSolarLock2(Application::GetSolarMutex());
1880*cdf0e10cSrcweir 
1881*cdf0e10cSrcweir             // We have to retrieve the window pointer again. Because nobody can guarantee
1882*cdf0e10cSrcweir             // that the XWindow was not disposed inbetween .-)
1883*cdf0e10cSrcweir             // But if we get a valid pointer we can be sure, that it's the system window pointer
1884*cdf0e10cSrcweir             // we already checked and used before. Because nobody recylce the same uno reference for
1885*cdf0e10cSrcweir             // a new internal c++ implementation ... hopefully .-))
1886*cdf0e10cSrcweir             Window* pWindowCheck  = VCLUnoHelper::GetWindow(xWindow);
1887*cdf0e10cSrcweir             if (! pWindowCheck)
1888*cdf0e10cSrcweir                 return;
1889*cdf0e10cSrcweir 
1890*cdf0e10cSrcweir             SystemWindow* pSystemWindow = (SystemWindow*)pWindowCheck;
1891*cdf0e10cSrcweir             pSystemWindow->SetWindowState(U2B_ENC(sWindowState,RTL_TEXTENCODING_UTF8));
1892*cdf0e10cSrcweir 
1893*cdf0e10cSrcweir             aSolarLock2.clear();
1894*cdf0e10cSrcweir             // <- SOLAR SAFE
1895*cdf0e10cSrcweir         }
1896*cdf0e10cSrcweir     }
1897*cdf0e10cSrcweir     catch(const css::uno::RuntimeException& exRun)
1898*cdf0e10cSrcweir         { throw exRun; }
1899*cdf0e10cSrcweir     catch(const css::uno::Exception&)
1900*cdf0e10cSrcweir         {}
1901*cdf0e10cSrcweir }
1902*cdf0e10cSrcweir 
1903*cdf0e10cSrcweir } // namespace framework
1904*cdf0e10cSrcweir 
1905