1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_framework.hxx"
30 //_______________________________________________
31 // includes of own project
32 #include <loadenv/loadenv.hxx>
34 #ifndef __FRAMEWORK_LOADENV_TARGETHELPER_HXX_
35 #include <loadenv/targethelper.hxx>
37 #include <classes/framelistanalyzer.hxx>
39 #include <dispatch/interaction.hxx>
41 #ifndef __FRAMEWORK_CONSTANT_FRAMELOADER_HXX_
42 #include <constant/frameloader.hxx>
45 #ifndef __FRAMEWORK_CONSTANT_CONTENTHANDLER_HXX_
46 #include <constant/contenthandler.hxx>
49 #ifndef __FRAMEWORK_CONSTANT_CONTAINERQUERY_HXX_
50 #include <constant/containerquery.hxx>
52 #include <interaction/quietinteraction.hxx>
53 #include <threadhelp/writeguard.hxx>
54 #include <threadhelp/readguard.hxx>
55 #include <threadhelp/resetableguard.hxx>
56 #include <properties.h>
57 #include <protocols.h>
59 #include <dispatch/interaction.hxx>
61 //_______________________________________________
62 // includes of uno interface
63 #include <com/sun/star/task/ErrorCodeRequest.hpp>
64 #include <com/sun/star/uno/RuntimeException.hpp>
65 #include <com/sun/star/frame/DispatchResultState.hpp>
66 #include <com/sun/star/frame/FrameSearchFlag.hpp>
67 #include <com/sun/star/util/XURLTransformer.hpp>
68 #include <com/sun/star/ucb/XContentProviderManager.hpp>
69 #include <com/sun/star/util/XCloseable.hpp>
70 #include <com/sun/star/lang/XComponent.hpp>
71 #include <com/sun/star/lang/XServiceInfo.hpp>
72 #include <com/sun/star/lang/DisposedException.hpp>
73 #include <com/sun/star/awt/XWindow.hpp>
74 #include <com/sun/star/awt/XWindow2.hpp>
75 #include <com/sun/star/awt/XTopWindow.hpp>
76 #include <com/sun/star/frame/XModel.hpp>
77 #include <com/sun/star/frame/XFrameLoader.hpp>
78 #include <com/sun/star/frame/XSynchronousFrameLoader.hpp>
79 #include <com/sun/star/frame/XNotifyingDispatch.hpp>
80 #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
81 #include <com/sun/star/task/XStatusIndicator.hpp>
82 #include <com/sun/star/util/XModifiable.hpp>
83 #include <com/sun/star/frame/XDispatchProvider.hpp>
84 #include <com/sun/star/document/XTypeDetection.hpp>
85 #include <com/sun/star/document/XActionLockable.hpp>
86 #include <com/sun/star/io/XInputStream.hpp>
87 #include <com/sun/star/task/XInteractionHandler.hpp>
88 #include <com/sun/star/container/XNameAccess.hpp>
89 #include <com/sun/star/container/XContainerQuery.hpp>
90 #include <com/sun/star/container/XEnumeration.hpp>
91 #include <com/sun/star/document/MacroExecMode.hpp>
92 #include <com/sun/star/document/UpdateDocMode.hpp>
94 //_______________________________________________
95 // includes of an other project
96 #include <vcl/window.hxx>
97 #include <vcl/wrkwin.hxx>
98 #include <vcl/syswin.hxx>
100 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
101 #include <toolkit/unohlp.hxx>
103 #include <unotools/moduleoptions.hxx>
104 #include <svtools/sfxecode.hxx>
105 #include <unotools/processfactory.hxx>
106 #include <unotools/ucbhelper.hxx>
107 #include <comphelper/configurationhelper.hxx>
108 #include <rtl/ustrbuf.hxx>
109 #include <vcl/svapp.hxx>
111 //_______________________________________________
116 // may there exist already a define .-(
118 namespace css
= ::com::sun::star
;
121 //_______________________________________________
124 class LoadEnvListener
: private ThreadHelpBase
125 , public ::cppu::WeakImplHelper2
< css::frame::XLoadEventListener
,
126 css::frame::XDispatchResultListener
>
135 //_______________________________________
136 LoadEnvListener(void* pCheck
,
139 m_ppCheck
= &pCheck
;
140 m_pLoadEnv
= pLoadEnv
;
143 //_______________________________________
144 // frame.XLoadEventListener
145 virtual void SAL_CALL
loadFinished(const css::uno::Reference
< css::frame::XFrameLoader
>& xLoader
)
146 throw(css::uno::RuntimeException
);
148 virtual void SAL_CALL
loadCancelled(const css::uno::Reference
< css::frame::XFrameLoader
>& xLoader
)
149 throw(css::uno::RuntimeException
);
151 //_______________________________________
152 // frame.XDispatchResultListener
153 virtual void SAL_CALL
dispatchFinished(const css::frame::DispatchResultEvent
& aEvent
)
154 throw(css::uno::RuntimeException
);
156 //_______________________________________
157 // lang.XEventListener
158 virtual void SAL_CALL
disposing(const css::lang::EventObject
& aEvent
)
159 throw(css::uno::RuntimeException
);
162 /*-----------------------------------------------
164 -----------------------------------------------*/
165 LoadEnv::LoadEnv(const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xSMGR
)
166 throw(LoadEnvException
, css::uno::RuntimeException
)
170 , m_pQuietInteraction( 0 )
174 /*-----------------------------------------------
176 -----------------------------------------------*/
182 /*-----------------------------------------------
184 -----------------------------------------------*/
185 css::uno::Reference
< css::lang::XComponent
> LoadEnv::loadComponentFromURL(const css::uno::Reference
< css::frame::XComponentLoader
>& xLoader
,
186 const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xSMGR
,
187 const ::rtl::OUString
& sURL
,
188 const ::rtl::OUString
& sTarget
,
190 const css::uno::Sequence
< css::beans::PropertyValue
>& lArgs
)
191 throw(css::lang::IllegalArgumentException
,
192 css::io::IOException
,
193 css::uno::RuntimeException
)
195 css::uno::Reference
< css::lang::XComponent
> xComponent
;
201 aEnv
.initializeLoading(sURL
,
203 css::uno::Reference
< css::frame::XFrame
>(xLoader
, css::uno::UNO_QUERY
),
206 LoadEnv::E_NO_FEATURE
);
208 aEnv
.waitWhileLoading(); // wait for ever!
210 xComponent
= aEnv
.getTargetComponent();
212 catch(const LoadEnvException
& ex
)
216 case LoadEnvException::ID_INVALID_MEDIADESCRIPTOR
:
217 throw css::lang::IllegalArgumentException(
218 ::rtl::OUString::createFromAscii("Optional list of arguments seem to be corrupted."),
222 case LoadEnvException::ID_UNSUPPORTED_CONTENT
:
223 throw css::lang::IllegalArgumentException(
224 ::rtl::OUString::createFromAscii("URL seems to be an unsupported one."),
228 default: xComponent
.clear();
236 //-----------------------------------------------
237 ::comphelper::MediaDescriptor
impl_mergeMediaDescriptorWithMightExistingModelArgs(const css::uno::Sequence
< css::beans::PropertyValue
>& lOutsideDescriptor
)
239 ::comphelper::MediaDescriptor
lDescriptor(lOutsideDescriptor
);
240 css::uno::Reference
< css::frame::XModel
> xModel
= lDescriptor
.getUnpackedValueOrDefault(
241 ::comphelper::MediaDescriptor::PROP_MODEL (),
242 css::uno::Reference
< css::frame::XModel
> ());
245 ::comphelper::MediaDescriptor
lModelDescriptor(xModel
->getArgs());
246 ::comphelper::MediaDescriptor::iterator pIt
= lModelDescriptor
.find( ::comphelper::MediaDescriptor::PROP_MACROEXECUTIONMODE() );
247 if ( pIt
!= lModelDescriptor
.end() )
248 lDescriptor
[::comphelper::MediaDescriptor::PROP_MACROEXECUTIONMODE()] = pIt
->second
;
254 /*-----------------------------------------------
256 -----------------------------------------------*/
257 void LoadEnv::initializeLoading(const ::rtl::OUString
& sURL
,
258 const css::uno::Sequence
< css::beans::PropertyValue
>& lMediaDescriptor
,
259 const css::uno::Reference
< css::frame::XFrame
>& xBaseFrame
,
260 const ::rtl::OUString
& sTarget
,
261 sal_Int32 nSearchFlags
,
262 EFeature eFeature
, // => use default ...
263 EContentType eContentType
) // => use default ...
264 throw(LoadEnvException
, css::uno::RuntimeException
)
266 // SAFE -> ----------------------------------
267 WriteGuard
aWriteLock(m_aLock
);
269 // Handle still running processes!
270 if (m_xAsynchronousJob
.is())
271 throw LoadEnvException(LoadEnvException::ID_STILL_RUNNING
);
273 // take over all new parameters.
274 m_xTargetFrame
.clear();
275 m_xBaseFrame
= xBaseFrame
;
276 m_lMediaDescriptor
= impl_mergeMediaDescriptorWithMightExistingModelArgs(lMediaDescriptor
);
277 m_sTarget
= sTarget
;
278 m_nSearchFlags
= nSearchFlags
;
279 m_eFeature
= eFeature
;
280 m_eContentType
= eContentType
;
281 m_bCloseFrameOnError
= sal_False
;
282 m_bReactivateControllerOnError
= sal_False
;
283 m_bLoaded
= sal_False
;
285 // try to find out, if its realy a content, which can be loaded or must be "handled"
286 // We use a default value for this in-parameter. Then we have to start a complex check method
287 // internaly. But if this check was already done outside it can be supressed to perform
288 // the load request. We take over the result then!
289 if (m_eContentType
== E_UNSUPPORTED_CONTENT
)
291 m_eContentType
= LoadEnv::classifyContent(sURL
, lMediaDescriptor
);
292 if (m_eContentType
== E_UNSUPPORTED_CONTENT
)
293 throw LoadEnvException(LoadEnvException::ID_UNSUPPORTED_CONTENT
);
296 // make URL part of the MediaDescriptor
297 // It doesnt mater, if its already an item of it.
298 // It must be the same value ... so we can overwrite it :-)
299 m_lMediaDescriptor
[::comphelper::MediaDescriptor::PROP_URL()] <<= sURL
;
301 // parse it - because some following code require that
302 m_aURL
.Complete
= sURL
;
303 css::uno::Reference
< css::util::XURLTransformer
> xParser(m_xSMGR
->createInstance(SERVICENAME_URLTRANSFORMER
), css::uno::UNO_QUERY
);
304 xParser
->parseStrict(m_aURL
);
306 // BTW: Split URL and JumpMark ...
307 // Because such mark is an explicit value of the media descriptor!
308 if (m_aURL
.Mark
.getLength())
309 m_lMediaDescriptor
[::comphelper::MediaDescriptor::PROP_JUMPMARK()] <<= m_aURL
.Mark
;
311 // By the way: remove the old and deprecated value "FileName" from the descriptor!
312 ::comphelper::MediaDescriptor::iterator pIt
= m_lMediaDescriptor
.find(::comphelper::MediaDescriptor::PROP_FILENAME());
313 if (pIt
!= m_lMediaDescriptor
.end())
314 m_lMediaDescriptor
.erase(pIt
);
316 // patch the MediaDescriptor, so it fullfill the outside requirements
317 // Means especialy items like e.g. UI InteractionHandler, Status Indicator,
318 // MacroExecutionMode etcpp.
320 /*TODO progress is bound to a frame ... How can we set it here? */
324 ( ( m_eFeature
& E_WORK_WITH_UI
) == E_WORK_WITH_UI
) &&
325 ( m_lMediaDescriptor
.getUnpackedValueOrDefault( ::comphelper::MediaDescriptor::PROP_HIDDEN() , sal_False
) == sal_False
) &&
326 ( m_lMediaDescriptor
.getUnpackedValueOrDefault( ::comphelper::MediaDescriptor::PROP_PREVIEW(), sal_False
) == sal_False
);
328 initializeUIDefaults(
336 // <- SAFE ----------------------------------
339 /*-----------------------------------------------
341 -----------------------------------------------*/
342 void LoadEnv::initializeUIDefaults( const css::uno::Reference
< css::lang::XMultiServiceFactory
>& i_rSMGR
,
343 ::comphelper::MediaDescriptor
& io_lMediaDescriptor
, const bool i_bUIMode
,
344 QuietInteraction
** o_ppQuietInteraction
)
346 css::uno::Reference
< css::task::XInteractionHandler
> xInteractionHandler
;
347 sal_Int16 nMacroMode
;
348 sal_Int16 nUpdateMode
;
352 nMacroMode
= css::document::MacroExecMode::USE_CONFIG
;
353 nUpdateMode
= css::document::UpdateDocMode::ACCORDING_TO_CONFIG
;
356 xInteractionHandler
= css::uno::Reference
< css::task::XInteractionHandler
>(i_rSMGR
->createInstance(IMPLEMENTATIONNAME_UIINTERACTIONHANDLER
), css::uno::UNO_QUERY
);
358 catch(const css::uno::RuntimeException
&) {throw;}
359 catch(const css::uno::Exception
& ) { }
364 nMacroMode
= css::document::MacroExecMode::NEVER_EXECUTE
;
365 nUpdateMode
= css::document::UpdateDocMode::NO_UPDATE
;
366 QuietInteraction
* pQuietInteraction
= new QuietInteraction();
367 xInteractionHandler
= css::uno::Reference
< css::task::XInteractionHandler
>(static_cast< css::task::XInteractionHandler
* >(pQuietInteraction
), css::uno::UNO_QUERY
);
368 if ( o_ppQuietInteraction
!= NULL
)
370 *o_ppQuietInteraction
= pQuietInteraction
;
371 (*o_ppQuietInteraction
)->acquire();
376 (xInteractionHandler
.is() ) &&
377 (io_lMediaDescriptor
.find(::comphelper::MediaDescriptor::PROP_INTERACTIONHANDLER()) == io_lMediaDescriptor
.end())
380 io_lMediaDescriptor
[::comphelper::MediaDescriptor::PROP_INTERACTIONHANDLER()] <<= xInteractionHandler
;
383 if (io_lMediaDescriptor
.find(::comphelper::MediaDescriptor::PROP_MACROEXECUTIONMODE()) == io_lMediaDescriptor
.end())
384 io_lMediaDescriptor
[::comphelper::MediaDescriptor::PROP_MACROEXECUTIONMODE()] <<= nMacroMode
;
386 if (io_lMediaDescriptor
.find(::comphelper::MediaDescriptor::PROP_UPDATEDOCMODE()) == io_lMediaDescriptor
.end())
387 io_lMediaDescriptor
[::comphelper::MediaDescriptor::PROP_UPDATEDOCMODE()] <<= nUpdateMode
;
390 /*-----------------------------------------------
392 -----------------------------------------------*/
393 void LoadEnv::startLoading()
394 throw(LoadEnvException
, css::uno::RuntimeException
)
397 ReadGuard
aReadLock(m_aLock
);
399 // Handle still running processes!
400 if (m_xAsynchronousJob
.is())
401 throw LoadEnvException(LoadEnvException::ID_STILL_RUNNING
);
403 // content can not be loaded or handled
404 // check "classifyContent()" failed before ...
405 if (m_eContentType
== E_UNSUPPORTED_CONTENT
)
406 throw LoadEnvException(LoadEnvException::ID_UNSUPPORTED_CONTENT
);
411 // detect its type/filter etcpp.
412 // These information will be available by the
413 // used descriptor member afterwards and is needed
414 // for all following operations!
415 // Note: An exception will be thrown, in case operation was not successfully ...
416 if (m_eContentType
!= E_CAN_BE_SET
)/* Attention: special feature to set existing component on a frame must ignore type detection! */
417 impl_detectTypeAndFilter();
419 // start loading the content ...
420 // Attention: Dont check m_eContentType deeper then UNSUPPORTED/SUPPORTED!
421 // Because it was made in th easiest way ... may a flat detection was made only.
422 // And such simple detection can fail some times .-)
423 // Use another strategy here. Try it and let it run into the case "loading not possible".
424 sal_Bool bStarted
= sal_False
;
426 ((m_eFeature
& E_ALLOW_CONTENTHANDLER
) == E_ALLOW_CONTENTHANDLER
) &&
427 (m_eContentType
!= E_CAN_BE_SET
) /* Attention: special feature to set existing component on a frame must ignore type detection! */
430 bStarted
= impl_handleContent();
434 bStarted
= impl_loadContent();
436 // not started => general error
437 // We cant say - what was the reason for.
439 throw LoadEnvException(LoadEnvException::ID_GENERAL_ERROR
);
442 /*-----------------------------------------------
445 First draft does not implement timeout using [ms].
446 Current implementation counts yield calls only ...
447 -----------------------------------------------*/
448 sal_Bool
LoadEnv::waitWhileLoading(sal_uInt32 nTimeout
)
449 throw(LoadEnvException
, css::uno::RuntimeException
)
451 // Because its not a good idea to block the main thread
452 // (and we cant be shure that we are currently not used inside the
453 // main thread!), we cant use conditions here realy. We must yield
454 // in an intellegent manner :-)
456 sal_Int32 nTime
= nTimeout
;
459 // SAFE -> ------------------------------
460 ReadGuard
aReadLock1(m_aLock
);
461 if (!m_xAsynchronousJob
.is())
464 // <- SAFE ------------------------------
466 Application::Yield();
478 // SAFE -> ----------------------------------
479 ReadGuard
aReadLock2(m_aLock
);
480 return !m_xAsynchronousJob
.is();
481 // <- SAFE ----------------------------------
484 /*-----------------------------------------------
486 -----------------------------------------------*/
487 void LoadEnv::cancelLoading()
488 throw(LoadEnvException
, css::uno::RuntimeException
)
490 // PARTIAL(!) SAFE -> ------------------------------
491 ReadGuard
aReadLock(m_aLock
);
493 // Still running? Might waitWhileLoading()
494 // runned into the timeout!
495 if (m_xAsynchronousJob
.is())
497 // try to cancel it ... if its an asynchronous frame loader
498 css::uno::Reference
< css::frame::XFrameLoader
> xAsyncLoader(m_xAsynchronousJob
, css::uno::UNO_QUERY
);
499 if (xAsyncLoader
.is())
502 // <- BREAK SAFE ------------------------------
503 xAsyncLoader
->cancel();
504 // <- RESTART SAFE ----------------------------
507 After returning from any cancel/dispose call, neither the frame nor weself
508 may be called back. Because only we can cancel this job, we already know
509 the result! => Thats why its not usefull nor neccessary to wait for any
510 asynchronous listener notification.
512 m_bLoaded
= sal_False
;
513 m_xAsynchronousJob
.clear();
515 // or may be its a content handler? Such handler cant be cancelled in its running
516 // operation :-( And we cant deregister us there again :-(
517 // => The only chance is an exception :-)
519 throw LoadEnvException(LoadEnvException::ID_STILL_RUNNING
);
522 impl_reactForLoadingState();
525 // <- PARTIAL(!) SAFE ------------------------------
528 /*-----------------------------------------------
530 -----------------------------------------------*/
531 css::uno::Reference
< css::frame::XFrame
> LoadEnv::getTarget() const
534 ReadGuard
aReadLock(m_aLock
);
535 return m_xTargetFrame
;
539 /*-----------------------------------------------
541 -----------------------------------------------*/
542 css::uno::Reference
< css::lang::XComponent
> LoadEnv::getTargetComponent() const
545 ReadGuard
aReadLock(m_aLock
);
547 if (!m_xTargetFrame
.is())
548 return css::uno::Reference
< css::lang::XComponent
>();
550 css::uno::Reference
< css::frame::XController
> xController
= m_xTargetFrame
->getController();
551 if (!xController
.is())
552 return css::uno::Reference
< css::lang::XComponent
>(m_xTargetFrame
->getComponentWindow(), css::uno::UNO_QUERY
);
554 css::uno::Reference
< css::frame::XModel
> xModel
= xController
->getModel();
556 return css::uno::Reference
< css::lang::XComponent
>(xController
, css::uno::UNO_QUERY
);
558 return css::uno::Reference
< css::lang::XComponent
>(xModel
, css::uno::UNO_QUERY
);
562 /*-----------------------------------------------
564 -----------------------------------------------*/
565 void SAL_CALL
LoadEnvListener::loadFinished(const css::uno::Reference
< css::frame::XFrameLoader
>&)
566 throw(css::uno::RuntimeException
)
568 // SAFE -> ----------------------------------
569 WriteGuard
aWriteLock(m_aLock
);
571 if (m_ppCheck
&& *m_ppCheck
)
572 m_pLoadEnv
->impl_setResult(sal_True
);
576 // <- SAFE ----------------------------------
579 /*-----------------------------------------------
581 -----------------------------------------------*/
582 void SAL_CALL
LoadEnvListener::loadCancelled(const css::uno::Reference
< css::frame::XFrameLoader
>&)
583 throw(css::uno::RuntimeException
)
585 // SAFE -> ----------------------------------
586 WriteGuard
aWriteLock(m_aLock
);
588 if (m_ppCheck
&& *m_ppCheck
)
589 m_pLoadEnv
->impl_setResult(sal_False
);
593 // <- SAFE ----------------------------------
596 /*-----------------------------------------------
598 -----------------------------------------------*/
599 void SAL_CALL
LoadEnvListener::dispatchFinished(const css::frame::DispatchResultEvent
& aEvent
)
600 throw(css::uno::RuntimeException
)
602 // SAFE -> ----------------------------------
603 WriteGuard
aWriteLock(m_aLock
);
605 if (!m_ppCheck
|| !*m_ppCheck
)
610 case css::frame::DispatchResultState::FAILURE
:
611 m_pLoadEnv
->impl_setResult(sal_False
);
614 case css::frame::DispatchResultState::SUCCESS
:
615 m_pLoadEnv
->impl_setResult(sal_False
);
618 case css::frame::DispatchResultState::DONTKNOW
:
619 m_pLoadEnv
->impl_setResult(sal_False
);
625 // <- SAFE ----------------------------------
628 /*-----------------------------------------------
630 -----------------------------------------------*/
631 void SAL_CALL
LoadEnvListener::disposing(const css::lang::EventObject
&)
632 throw(css::uno::RuntimeException
)
634 // SAFE -> ----------------------------------
635 WriteGuard
aWriteLock(m_aLock
);
637 if (m_ppCheck
&& *m_ppCheck
)
638 m_pLoadEnv
->impl_setResult(sal_False
);
642 // <- SAFE ----------------------------------
645 /*-----------------------------------------------
647 -----------------------------------------------*/
648 void LoadEnv::impl_setResult(sal_Bool bResult
)
650 // SAFE -> ----------------------------------
651 WriteGuard
aWriteLock(m_aLock
);
655 impl_reactForLoadingState();
657 // clearing of this reference will unblock waitWhileLoading()!
658 // So we must be shure, that loading process was realy finished.
659 // => do it as last operation of this method ...
660 m_xAsynchronousJob
.clear();
663 // <- SAFE ----------------------------------
666 /*-----------------------------------------------
668 TODO: Is it a good idea to change Sequence<>
669 parameter to stl-adapter?
670 -----------------------------------------------*/
671 LoadEnv::EContentType
LoadEnv::classifyContent(const ::rtl::OUString
& sURL
,
672 const css::uno::Sequence
< css::beans::PropertyValue
>& lMediaDescriptor
)
674 //-------------------------------------------
675 // (i) Filter some special well known URL protocols,
676 // which can not be handled or loaded in general.
677 // Of course an empty URL must be ignored here too.
678 // Note: These URL schemata are fix and well known ...
679 // But there can be some additional ones, which was not
680 // defined at implementation time of this class :-(
681 // So we have to make shure, that the following code
682 // can detect such protocol schemata too :-)
685 (!sURL
.getLength() ) ||
686 (ProtocolCheck::isProtocol(sURL
,ProtocolCheck::E_UNO
)) ||
687 (ProtocolCheck::isProtocol(sURL
,ProtocolCheck::E_SLOT
)) ||
688 (ProtocolCheck::isProtocol(sURL
,ProtocolCheck::E_MACRO
)) ||
689 (ProtocolCheck::isProtocol(sURL
,ProtocolCheck::E_SERVICE
)) ||
690 (ProtocolCheck::isProtocol(sURL
,ProtocolCheck::E_MAILTO
)) ||
691 (ProtocolCheck::isProtocol(sURL
,ProtocolCheck::E_NEWS
))
694 return E_UNSUPPORTED_CONTENT
;
697 //-------------------------------------------
698 // (ii) Some special URLs indicates a given input stream,
699 // a full featured document model directly or
700 // specify a request for opening an empty document.
701 // Such contents are loadable in general.
702 // But we have to check, if the media descriptor contains
703 // all needed resources. If they are missing - the following
704 // load request will fail.
706 /* Attention: The following code cant work on such special URLs!
707 It should not break the office .. but it make no sense
708 to start expensive object creations and complex search
709 algorithm if its clear, that such URLs must be handled
713 // creation of new documents
714 if (ProtocolCheck::isProtocol(sURL
,ProtocolCheck::E_PRIVATE_FACTORY
))
715 return E_CAN_BE_LOADED
;
717 // using of an existing input stream
718 ::comphelper::MediaDescriptor
stlMediaDescriptor(lMediaDescriptor
);
719 ::comphelper::MediaDescriptor::const_iterator pIt
;
720 if (ProtocolCheck::isProtocol(sURL
,ProtocolCheck::E_PRIVATE_STREAM
))
722 pIt
= stlMediaDescriptor
.find(::comphelper::MediaDescriptor::PROP_INPUTSTREAM());
723 css::uno::Reference
< css::io::XInputStream
> xStream
;
724 if (pIt
!= stlMediaDescriptor
.end())
725 pIt
->second
>>= xStream
;
727 return E_CAN_BE_LOADED
;
728 LOG_WARNING("LoadEnv::classifyContent()", "loading from stream with right URL but invalid stream detected")
729 return E_UNSUPPORTED_CONTENT
;
732 // using of a full featured document
733 if (ProtocolCheck::isProtocol(sURL
,ProtocolCheck::E_PRIVATE_OBJECT
))
735 pIt
= stlMediaDescriptor
.find(::comphelper::MediaDescriptor::PROP_MODEL());
736 css::uno::Reference
< css::frame::XModel
> xModel
;
737 if (pIt
!= stlMediaDescriptor
.end())
738 pIt
->second
>>= xModel
;
741 LOG_WARNING("LoadEnv::classifyContent()", "loading with object with right URL but invalid object detected")
742 return E_UNSUPPORTED_CONTENT
;
745 // following operatons can work on an internal type name only :-(
746 css::uno::Reference
< css::lang::XMultiServiceFactory
> xSMGR
= ::utl::getProcessServiceFactory();
747 css::uno::Reference
< css::document::XTypeDetection
> xDetect(xSMGR
->createInstance(SERVICENAME_TYPEDETECTION
), css::uno::UNO_QUERY
);
749 ::rtl::OUString sType
= xDetect
->queryTypeByURL(sURL
);
751 css::uno::Sequence
< css::beans::NamedValue
> lQuery(1) ;
752 css::uno::Reference
< css::container::XContainerQuery
> xContainer
;
753 css::uno::Reference
< css::container::XEnumeration
> xSet
;
754 css::uno::Sequence
< ::rtl::OUString
> lTypesReg(1);
757 //-------------------------------------------
758 lQuery[0].Name = ::framework::constant::Filter::PROP_TYPE;
759 lQuery[0].Value <<= sType;
761 xContainer = css::uno::Reference< css::container::XContainerQuery >(xSMGR->createInstance(SERVICENAME_FILTERFACTORY), css::uno::UNO_QUERY);
762 xSet = xContainer->createSubSetEnumerationByProperties(lQuery);
763 // at least one registered frame loader is enough!
764 if (xSet->hasMoreElements())
765 return E_CAN_BE_LOADED;
768 //-------------------------------------------
769 // (iii) If a FrameLoader service (or at least
770 // a Filter) can be found, which supports
771 // this URL - it must be a loadable content.
772 // Because both items are registered for types
773 // its enough to check for frame loaders only.
774 // Mos of our filters are handled by our global
775 // default loader. But there exist some specialized
776 // loader, which does not work on top of filters!
777 // So its not enough to search on the filter configuration.
778 // Further its not enough to search for types!
779 // Because there exist some types, which are referenced by
780 // other objects ... but not by filters nor frame loaders!
782 lTypesReg
[0] = sType
;
783 lQuery
[0].Name
= ::framework::constant::FrameLoader::PROP_TYPES
;
784 lQuery
[0].Value
<<= lTypesReg
;
786 xContainer
= css::uno::Reference
< css::container::XContainerQuery
>(xSMGR
->createInstance(SERVICENAME_FRAMELOADERFACTORY
), css::uno::UNO_QUERY
);
787 xSet
= xContainer
->createSubSetEnumerationByProperties(lQuery
);
788 // at least one registered frame loader is enough!
789 if (xSet
->hasMoreElements())
790 return E_CAN_BE_LOADED
;
792 //-------------------------------------------
793 // (iv) Some URL protocols are supported by special services.
794 // E.g. ContentHandler.
795 // Such contents can be handled ... but not loaded.
797 lTypesReg
[0] = sType
;
798 lQuery
[0].Name
= ::framework::constant::ContentHandler::PROP_TYPES
;
799 lQuery
[0].Value
<<= lTypesReg
;
801 xContainer
= css::uno::Reference
< css::container::XContainerQuery
>(xSMGR
->createInstance(SERVICENAME_CONTENTHANDLERFACTORY
), css::uno::UNO_QUERY
);
802 xSet
= xContainer
->createSubSetEnumerationByProperties(lQuery
);
803 // at least one registered content handler is enough!
804 if (xSet
->hasMoreElements())
805 return E_CAN_BE_HANDLED
;
807 //-------------------------------------------
808 // (v) Last but not least the UCB is used inside office to
809 // load contents. He has a special configuration to know
810 // which URL schemata can be used inside office.
811 css::uno::Reference
< css::ucb::XContentProviderManager
> xUCB(xSMGR
->createInstance(SERVICENAME_UCBCONTENTBROKER
), css::uno::UNO_QUERY
);
812 if (xUCB
->queryContentProvider(sURL
).is())
813 return E_CAN_BE_LOADED
;
815 //-------------------------------------------
816 // (TODO) At this point, we have no idea .-)
817 // But it seems to be better, to break all
818 // further requests for this URL. Otherwhise
819 // we can run into some trouble.
820 LOG_WARNING("LoadEnv::classifyContent()", "realy an unsupported content?")
821 return E_UNSUPPORTED_CONTENT
;
824 /*-----------------------------------------------
826 -----------------------------------------------*/
827 void LoadEnv::impl_detectTypeAndFilter()
828 throw(LoadEnvException
, css::uno::RuntimeException
)
830 static ::rtl::OUString TYPEPROP_PREFERREDFILTER
= ::rtl::OUString::createFromAscii("PreferredFilter");
831 static ::rtl::OUString FILTERPROP_FLAGS
= ::rtl::OUString::createFromAscii("Flags" );
832 static sal_Int32 FILTERFLAG_TEMPLATEPATH
= 16;
835 ReadGuard
aReadLock(m_aLock
);
837 // Attention: Because our stl media descriptor is a copy of an uno sequence
838 // we cant use as an in/out parameter here. Copy it before and dont forget to
839 // update structure afterwards again!
840 css::uno::Sequence
< css::beans::PropertyValue
> lDescriptor
= m_lMediaDescriptor
.getAsConstPropertyValueList();
841 css::uno::Reference
< css::lang::XMultiServiceFactory
> xSMGR
= m_xSMGR
;
846 ::rtl::OUString sType
;
847 css::uno::Reference
< css::document::XTypeDetection
> xDetect(xSMGR
->createInstance(SERVICENAME_TYPEDETECTION
), css::uno::UNO_QUERY
);
849 sType
= xDetect
->queryTypeByDescriptor(lDescriptor
, sal_True
); /*TODO should deep detection be able for enable/disable it from outside? */
851 // no valid content -> loading not possible
852 if (!sType
.getLength())
853 throw LoadEnvException(LoadEnvException::ID_UNSUPPORTED_CONTENT
);
856 WriteGuard
aWriteLock(m_aLock
);
858 // detection was successfully => update the descriptor member of this class
859 m_lMediaDescriptor
<< lDescriptor
;
860 m_lMediaDescriptor
[::comphelper::MediaDescriptor::PROP_TYPENAME()] <<= sType
;
861 // Is there an already detected (may be preselected) filter?
863 ::rtl::OUString sFilter
= m_lMediaDescriptor
.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_FILTERNAME(), ::rtl::OUString());
868 // But the type isnt enough. For loading sometimes we need more informations.
869 // E.g. for our "_default" feature, where we recylce any frame which contains
870 // and "Untitled" document, we must know if the new document is based on a template!
871 // But this information is available as a filter property only.
872 // => We must try(!) to detect the right filter for this load request.
873 // On the other side ... if no filter is available .. ignore it.
874 // Then the type information must be enough.
875 if (!sFilter
.getLength())
877 // no -> try to find a preferred filter for the detected type.
878 // Dont forget to updatet he media descriptor.
879 css::uno::Reference
< css::container::XNameAccess
> xTypeCont(xDetect
, css::uno::UNO_QUERY_THROW
);
882 ::comphelper::SequenceAsHashMap
lTypeProps(xTypeCont
->getByName(sType
));
883 sFilter
= lTypeProps
.getUnpackedValueOrDefault(TYPEPROP_PREFERREDFILTER
, ::rtl::OUString());
884 if (sFilter
.getLength())
888 m_lMediaDescriptor
[::comphelper::MediaDescriptor::PROP_FILTERNAME()] <<= sFilter
;
893 catch(const css::container::NoSuchElementException
&)
897 // check if the filter (if one exists) points to a template format filter.
898 // Then we have to add the property "AsTemplate".
899 // We need this information to decide afterwards if we can use a "recycle frame"
900 // for target "_default" or has to create a new one everytimes.
901 // On the other side we have to supress that, if this property already exists
902 // and should trigger a special handling. Then the outside calli of this method here,
903 // has to know, what he is doing .-)
905 sal_Bool bIsOwnTemplate
= sal_False
;
906 if (sFilter
.getLength())
908 css::uno::Reference
< css::container::XNameAccess
> xFilterCont(xSMGR
->createInstance(SERVICENAME_FILTERFACTORY
), css::uno::UNO_QUERY_THROW
);
911 ::comphelper::SequenceAsHashMap
lFilterProps(xFilterCont
->getByName(sFilter
));
912 sal_Int32 nFlags
= lFilterProps
.getUnpackedValueOrDefault(FILTERPROP_FLAGS
, (sal_Int32
)0);
913 bIsOwnTemplate
= ((nFlags
& FILTERFLAG_TEMPLATEPATH
) == FILTERFLAG_TEMPLATEPATH
);
915 catch(const css::container::NoSuchElementException
&)
922 // Dont overwrite external decisions! See comments before ...
923 ::comphelper::MediaDescriptor::const_iterator pAsTemplateItem
= m_lMediaDescriptor
.find(::comphelper::MediaDescriptor::PROP_ASTEMPLATE());
924 if (pAsTemplateItem
== m_lMediaDescriptor
.end())
925 m_lMediaDescriptor
[::comphelper::MediaDescriptor::PROP_ASTEMPLATE()] <<= sal_True
;
931 /*-----------------------------------------------
933 -----------------------------------------------*/
934 sal_Bool
LoadEnv::impl_handleContent()
935 throw(LoadEnvException
, css::uno::RuntimeException
)
937 // SAFE -> -----------------------------------
938 ReadGuard
aReadLock(m_aLock
);
940 // the type must exist inside the descriptor ... otherwhise this class is implemented wrong :-)
941 ::rtl::OUString sType
= m_lMediaDescriptor
.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_TYPENAME(), ::rtl::OUString());
942 if (!sType
.getLength())
943 throw LoadEnvException(LoadEnvException::ID_INVALID_MEDIADESCRIPTOR
);
945 // convert media descriptor and URL to right format for later interface call!
946 css::uno::Sequence
< css::beans::PropertyValue
> lDescriptor
;
947 m_lMediaDescriptor
>> lDescriptor
;
948 css::util::URL aURL
= m_aURL
;
950 // get neccessary container to query for a handler object
951 css::uno::Reference
< css::lang::XMultiServiceFactory
> xFactory(m_xSMGR
->createInstance(SERVICENAME_CONTENTHANDLERFACTORY
), css::uno::UNO_QUERY
);
952 css::uno::Reference
< css::container::XContainerQuery
> xQuery (xFactory
, css::uno::UNO_QUERY
);
955 // <- SAFE -----------------------------------
958 css::uno::Sequence
< ::rtl::OUString
> lTypeReg(1);
961 css::uno::Sequence
< css::beans::NamedValue
> lQuery(1);
962 lQuery
[0].Name
= ::framework::constant::ContentHandler::PROP_TYPES
;
963 lQuery
[0].Value
<<= lTypeReg
;
965 css::uno::Reference
< css::container::XEnumeration
> xSet
= xQuery
->createSubSetEnumerationByProperties(lQuery
);
966 while(xSet
->hasMoreElements())
968 ::comphelper::SequenceAsHashMap
lProps (xSet
->nextElement());
969 ::rtl::OUString sHandler
= lProps
.getUnpackedValueOrDefault(::framework::constant::ContentHandler::PROP_NAME
, ::rtl::OUString());
971 css::uno::Reference
< css::frame::XNotifyingDispatch
> xHandler
;
974 xHandler
= css::uno::Reference
< css::frame::XNotifyingDispatch
>(xFactory
->createInstance(sHandler
), css::uno::UNO_QUERY
);
978 catch(const css::uno::RuntimeException
&)
980 catch(const css::uno::Exception
&)
983 // SAFE -> -----------------------------------
984 WriteGuard
aWriteLock(m_aLock
);
985 m_xAsynchronousJob
= xHandler
;
987 LoadEnvListener
* pListener
= new LoadEnvListener(m_pCheck
, this);
989 // <- SAFE -----------------------------------
991 css::uno::Reference
< css::frame::XDispatchResultListener
> xListener(static_cast< css::frame::XDispatchResultListener
* >(pListener
), css::uno::UNO_QUERY
);
992 xHandler
->dispatchWithNotification(aURL
, lDescriptor
, xListener
);
1000 //-----------------------------------------------
1001 sal_Bool
LoadEnv::impl_furtherDocsAllowed()
1004 ReadGuard
aReadLock(m_aLock
);
1005 css::uno::Reference
< css::lang::XMultiServiceFactory
> xSMGR
= m_xSMGR
;
1009 sal_Bool bAllowed
= sal_True
;
1013 css::uno::Any aVal
= ::comphelper::ConfigurationHelper::readDirectKey(
1015 ::rtl::OUString::createFromAscii("org.openoffice.Office.Common/"),
1016 ::rtl::OUString::createFromAscii("Misc"),
1017 ::rtl::OUString::createFromAscii("MaxOpenDocuments"),
1018 ::comphelper::ConfigurationHelper::E_READONLY
);
1020 // NIL means: count of allowed documents = infinite !
1022 if ( ! aVal
.hasValue())
1023 bAllowed
= sal_True
;
1026 sal_Int32 nMaxOpenDocuments
= 0;
1027 aVal
>>= nMaxOpenDocuments
;
1029 css::uno::Reference
< css::frame::XFramesSupplier
> xDesktop(
1030 xSMGR
->createInstance(SERVICENAME_DESKTOP
),
1031 css::uno::UNO_QUERY_THROW
);
1033 FrameListAnalyzer
aAnalyzer(xDesktop
,
1034 css::uno::Reference
< css::frame::XFrame
>(),
1035 FrameListAnalyzer::E_HELP
|
1036 FrameListAnalyzer::E_BACKINGCOMPONENT
|
1037 FrameListAnalyzer::E_HIDDEN
);
1039 sal_Int32 nOpenDocuments
= aAnalyzer
.m_lOtherVisibleFrames
.getLength();
1040 bAllowed
= (nOpenDocuments
< nMaxOpenDocuments
);
1043 catch(const css::uno::Exception
&)
1044 { bAllowed
= sal_True
; } // !! internal errors are no reason to disturb the office from opening documents .-)
1050 css::uno::Reference
< css::task::XInteractionHandler
> xInteraction
= m_lMediaDescriptor
.getUnpackedValueOrDefault(
1051 ::comphelper::MediaDescriptor::PROP_INTERACTIONHANDLER(),
1052 css::uno::Reference
< css::task::XInteractionHandler
>());
1056 if (xInteraction
.is())
1058 css::uno::Any aInteraction
;
1059 css::uno::Sequence
< css::uno::Reference
< css::task::XInteractionContinuation
> > lContinuations(2);
1061 ContinuationAbort
* pAbort
= new ContinuationAbort();
1062 ContinuationApprove
* pApprove
= new ContinuationApprove();
1064 lContinuations
[0] = css::uno::Reference
< css::task::XInteractionContinuation
>(
1065 static_cast< css::task::XInteractionContinuation
* >(pAbort
),
1066 css::uno::UNO_QUERY_THROW
);
1067 lContinuations
[1] = css::uno::Reference
< css::task::XInteractionContinuation
>(
1068 static_cast< css::task::XInteractionContinuation
* >(pApprove
),
1069 css::uno::UNO_QUERY_THROW
);
1071 css::task::ErrorCodeRequest aErrorCode
;
1072 aErrorCode
.ErrCode
= ERRCODE_SFX_NOMOREDOCUMENTSALLOWED
;
1073 aInteraction
<<= aErrorCode
;
1075 InteractionRequest
* pRequest
= new InteractionRequest(aInteraction
, lContinuations
);
1076 css::uno::Reference
< css::task::XInteractionRequest
> xRequest(
1077 static_cast< css::task::XInteractionRequest
* >(pRequest
),
1078 css::uno::UNO_QUERY_THROW
);
1080 xInteraction
->handle(xRequest
);
1087 //-----------------------------------------------
1088 sal_Bool
LoadEnv::impl_loadContent()
1089 throw(LoadEnvException
, css::uno::RuntimeException
)
1091 // SAFE -> -----------------------------------
1092 WriteGuard
aWriteLock(m_aLock
);
1094 // search or create right target frame
1095 ::rtl::OUString sTarget
= m_sTarget
;
1096 if (TargetHelper::matchSpecialTarget(sTarget
, TargetHelper::E_DEFAULT
))
1098 m_xTargetFrame
= impl_searchAlreadyLoaded();
1099 if (m_xTargetFrame
.is())
1101 impl_setResult(sal_True
);
1104 m_xTargetFrame
= impl_searchRecycleTarget();
1107 if (! m_xTargetFrame
.is())
1110 (TargetHelper::matchSpecialTarget(sTarget
, TargetHelper::E_BLANK
)) ||
1111 (TargetHelper::matchSpecialTarget(sTarget
, TargetHelper::E_DEFAULT
))
1114 if (! impl_furtherDocsAllowed())
1116 m_xTargetFrame
= m_xBaseFrame
->findFrame(SPECIALTARGET_BLANK
, 0);
1117 m_bCloseFrameOnError
= m_xTargetFrame
.is();
1121 sal_Int32 nFlags
= m_nSearchFlags
& ~css::frame::FrameSearchFlag::CREATE
;
1122 m_xTargetFrame
= m_xBaseFrame
->findFrame(sTarget
, nFlags
);
1123 if (! m_xTargetFrame
.is())
1125 if (! impl_furtherDocsAllowed())
1127 m_xTargetFrame
= m_xBaseFrame
->findFrame(SPECIALTARGET_BLANK
, 0);
1128 m_bCloseFrameOnError
= m_xTargetFrame
.is();
1133 // If we couldn't find a valid frame or the frame has no container window
1134 // we have to throw an exception.
1136 ( ! m_xTargetFrame
.is() ) ||
1137 ( ! m_xTargetFrame
->getContainerWindow().is() )
1139 throw LoadEnvException(LoadEnvException::ID_NO_TARGET_FOUND
);
1141 css::uno::Reference
< css::frame::XFrame
> xTargetFrame
= m_xTargetFrame
;
1143 // Now we have a valid frame ... and type detection was already done.
1144 // We should apply the module dependend window position and size to the
1146 impl_applyPersistentWindowState(xTargetFrame
->getContainerWindow());
1148 // Don't forget to lock task for following load process. Otherwise it could die
1149 // during this operation runs by terminating the office or closing this task via api.
1150 // If we set this lock "close()" will return false and closing will be broken.
1151 // Attention: Don't forget to reset this lock again after finishing operation.
1152 // Otherwise task AND office couldn't die!!!
1153 // This includes gracefully handling of Exceptions (Runtime!) too ...
1154 // Thats why we use a specialized guard, which will reset the lock
1155 // if it will be run out of scope.
1157 // Note further: ignore if this internal guard already contains a resource.
1158 // Might impl_searchRecylcTarget() set it before. But incase this impl-method wasnt used
1159 // and the target frame was new created ... this lock here must be set!
1160 css::uno::Reference
< css::document::XActionLockable
> xTargetLock(xTargetFrame
, css::uno::UNO_QUERY
);
1161 m_aTargetLock
.setResource(xTargetLock
);
1163 // Add status indicator to descriptor. Loader can show an progresses then.
1164 // But don't do it, if loading should be hidden or preview is used ...!
1165 // So we prevent our code against wrong using. Why?
1166 // It could be, that using of this progress could make trouble. e.g. He make window visible ...
1167 // but shouldn't do that. But if no indicator is available ... nobody has a chance to do that!
1168 sal_Bool bHidden
= m_lMediaDescriptor
.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_HIDDEN() , sal_False
);
1169 sal_Bool bMinimized
= m_lMediaDescriptor
.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_MINIMIZED() , sal_False
);
1170 sal_Bool bPreview
= m_lMediaDescriptor
.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_PREVIEW() , sal_False
);
1171 css::uno::Reference
< css::task::XStatusIndicator
> xProgress
= m_lMediaDescriptor
.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_STATUSINDICATOR(), css::uno::Reference
< css::task::XStatusIndicator
>());
1173 if (!bHidden
&& !bMinimized
&& !bPreview
&& !xProgress
.is())
1175 // Note: its an optional interface!
1176 css::uno::Reference
< css::task::XStatusIndicatorFactory
> xProgressFactory(xTargetFrame
, css::uno::UNO_QUERY
);
1177 if (xProgressFactory
.is())
1179 xProgress
= xProgressFactory
->createStatusIndicator();
1181 m_lMediaDescriptor
[::comphelper::MediaDescriptor::PROP_STATUSINDICATOR()] <<= xProgress
;
1185 // convert media descriptor and URL to right format for later interface call!
1186 css::uno::Sequence
< css::beans::PropertyValue
> lDescriptor
;
1187 m_lMediaDescriptor
>> lDescriptor
;
1188 ::rtl::OUString sURL
= m_aURL
.Complete
;
1190 // try to locate any interested frame loader
1191 css::uno::Reference
< css::uno::XInterface
> xLoader
= impl_searchLoader();
1192 css::uno::Reference
< css::frame::XFrameLoader
> xAsyncLoader(xLoader
, css::uno::UNO_QUERY
);
1193 css::uno::Reference
< css::frame::XSynchronousFrameLoader
> xSyncLoader (xLoader
, css::uno::UNO_QUERY
);
1195 if (xAsyncLoader
.is())
1197 // SAFE -> -----------------------------------
1199 m_xAsynchronousJob
= xAsyncLoader
;
1201 LoadEnvListener
* pListener
= new LoadEnvListener(m_pCheck
, this);
1202 aWriteLock
.unlock();
1203 // <- SAFE -----------------------------------
1205 css::uno::Reference
< css::frame::XLoadEventListener
> xListener(static_cast< css::frame::XLoadEventListener
* >(pListener
), css::uno::UNO_QUERY
);
1206 xAsyncLoader
->load(xTargetFrame
, sURL
, lDescriptor
, xListener
);
1211 if (xSyncLoader
.is())
1213 sal_Bool bResult
= xSyncLoader
->load(lDescriptor
, xTargetFrame
);
1214 // react for the result here, so the outside waiting
1215 // code can ask for it later.
1216 impl_setResult(bResult
);
1217 // But the return value indicates a valid started(!) operation.
1218 // And thats true everxtimes, we reach this line :-)
1222 aWriteLock
.unlock();
1228 /*-----------------------------------------------
1230 -----------------------------------------------*/
1231 css::uno::Reference
< css::uno::XInterface
> LoadEnv::impl_searchLoader()
1233 // SAFE -> -----------------------------------
1234 ReadGuard
aReadLock(m_aLock
);
1236 // special mode to set an existing component on this frame
1237 // In such case the laoder is fix. It must be the SFX based implementation,
1238 // which can create a view on top of such xModel components :-)
1239 if (m_eContentType
== E_CAN_BE_SET
)
1243 return m_xSMGR
->createInstance(IMPLEMENTATIONNAME_GENERICFRAMELOADER
);
1245 catch(const css::uno::RuntimeException
&)
1247 catch(const css::uno::Exception
&)
1249 throw LoadEnvException(LoadEnvException::ID_INVALID_ENVIRONMENT
);
1253 // We need this type information to locate an registered frame loader
1254 // Without such information we cant work!
1255 ::rtl::OUString sType
= m_lMediaDescriptor
.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_TYPENAME(), ::rtl::OUString());
1256 if (!sType
.getLength())
1257 throw LoadEnvException(LoadEnvException::ID_INVALID_MEDIADESCRIPTOR
);
1259 // try to locate any interested frame loader
1260 css::uno::Reference
< css::lang::XMultiServiceFactory
> xLoaderFactory(m_xSMGR
->createInstance(SERVICENAME_FRAMELOADERFACTORY
), css::uno::UNO_QUERY
);
1261 css::uno::Reference
< css::container::XContainerQuery
> xQuery (xLoaderFactory
, css::uno::UNO_QUERY
);
1264 // <- SAFE -----------------------------------
1266 css::uno::Sequence
< ::rtl::OUString
> lTypesReg(1);
1267 lTypesReg
[0] = sType
;
1269 css::uno::Sequence
< css::beans::NamedValue
> lQuery(1);
1270 lQuery
[0].Name
= ::framework::constant::FrameLoader::PROP_TYPES
;
1271 lQuery
[0].Value
<<= lTypesReg
;
1273 css::uno::Reference
< css::container::XEnumeration
> xSet
= xQuery
->createSubSetEnumerationByProperties(lQuery
);
1274 while(xSet
->hasMoreElements())
1277 // Ignore any loader, which makes trouble :-)
1278 ::comphelper::SequenceAsHashMap
lLoaderProps(xSet
->nextElement());
1279 ::rtl::OUString sLoader
= lLoaderProps
.getUnpackedValueOrDefault(::framework::constant::FrameLoader::PROP_NAME
, ::rtl::OUString());
1280 css::uno::Reference
< css::uno::XInterface
> xLoader
;
1283 xLoader
= xLoaderFactory
->createInstance(sLoader
);
1287 catch(const css::uno::RuntimeException
&)
1289 catch(const css::uno::Exception
&)
1293 return css::uno::Reference
< css::uno::XInterface
>();
1296 /*-----------------------------------------------
1298 -----------------------------------------------*/
1299 void LoadEnv::impl_jumpToMark(const css::uno::Reference
< css::frame::XFrame
>& xFrame
,
1300 const css::util::URL
& aURL
)
1302 if (! aURL
.Mark
.getLength())
1305 css::uno::Reference
< css::frame::XDispatchProvider
> xProvider(xFrame
, css::uno::UNO_QUERY
);
1306 if (! xProvider
.is())
1310 ReadGuard
aReadLock(m_aLock
);
1311 css::uno::Reference
< css::lang::XMultiServiceFactory
> xSMGR
= m_xSMGR
;
1315 css::util::URL aCmd
;
1316 aCmd
.Complete
= ::rtl::OUString::createFromAscii(".uno:JumpToMark");
1318 css::uno::Reference
< css::util::XURLTransformer
> xParser(xSMGR
->createInstance(SERVICENAME_URLTRANSFORMER
), css::uno::UNO_QUERY_THROW
);
1319 xParser
->parseStrict(aCmd
);
1321 css::uno::Reference
< css::frame::XDispatch
> xDispatcher
= xProvider
->queryDispatch(aCmd
, SPECIALTARGET_SELF
, 0);
1322 if (! xDispatcher
.is())
1325 ::comphelper::SequenceAsHashMap lArgs
;
1326 lArgs
[::rtl::OUString::createFromAscii("Bookmark")] <<= aURL
.Mark
;
1327 xDispatcher
->dispatch(aCmd
, lArgs
.getAsConstPropertyValueList());
1330 /*-----------------------------------------------
1332 -----------------------------------------------*/
1333 css::uno::Reference
< css::frame::XFrame
> LoadEnv::impl_searchAlreadyLoaded()
1334 throw(LoadEnvException
, css::uno::RuntimeException
)
1337 ReadGuard
aReadLock(m_aLock
);
1339 // such search is allowed for special requests only ...
1340 // or better its not allowed for some requests in general :-)
1342 ( ! TargetHelper::matchSpecialTarget(m_sTarget
, TargetHelper::E_DEFAULT
) ) ||
1343 (m_lMediaDescriptor
.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_ASTEMPLATE() , sal_False
) == sal_True
) ||
1344 // (m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_HIDDEN() , sal_False) == sal_True) ||
1345 (m_lMediaDescriptor
.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_OPENNEWVIEW(), sal_False
) == sal_True
)
1348 return css::uno::Reference
< css::frame::XFrame
>();
1352 // May its not usefull to start expensive document search, if it
1353 // can fail only .. because we load from a stream or model directly!
1355 (ProtocolCheck::isProtocol(m_aURL
.Complete
, ProtocolCheck::E_PRIVATE_STREAM
)) ||
1356 (ProtocolCheck::isProtocol(m_aURL
.Complete
, ProtocolCheck::E_PRIVATE_OBJECT
))
1357 /*TODO should be private:factory here tested too? */
1360 return css::uno::Reference
< css::frame::XFrame
>();
1363 // otherwhise - iterate through the tasks of the desktop container
1364 // to find out, which of them might contains the requested document
1365 css::uno::Reference
< css::frame::XFramesSupplier
> xSupplier(m_xSMGR
->createInstance(SERVICENAME_DESKTOP
), css::uno::UNO_QUERY
);
1366 css::uno::Reference
< css::container::XIndexAccess
> xTaskList(xSupplier
->getFrames() , css::uno::UNO_QUERY
);
1368 if (!xTaskList
.is())
1369 return css::uno::Reference
< css::frame::XFrame
>(); // task list can be empty!
1371 // Note: To detect if a document was alrady loaded before
1372 // we check URLs here only. But might the existing and the requred
1373 // document has different versions! Then its URLs are the same ...
1374 sal_Int16 nNewVersion
= m_lMediaDescriptor
.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_VERSION(), (sal_Int16
)(-1));
1376 // will be used to save the first hidden frame referring the searched model
1377 // Normaly we are interested on visible frames ... but if there is no such visible
1378 // frame we referr to any hidden frame also (but as fallback only).
1379 css::uno::Reference
< css::frame::XFrame
> xHiddenTask
;
1380 css::uno::Reference
< css::frame::XFrame
> xTask
;
1382 sal_Int32 count
= xTaskList
->getCount();
1383 for (sal_Int32 i
=0; i
<count
; ++i
)
1387 // locate model of task
1388 // Note: Without a model there is no chance to decide if
1389 // this task contains the searched document or not!
1390 xTaskList
->getByIndex(i
) >>= xTask
;
1394 css::uno::Reference
< css::frame::XController
> xController
= xTask
->getController();
1395 if (!xController
.is())
1401 css::uno::Reference
< css::frame::XModel
> xModel
= xController
->getModel();
1408 // don't check the complete URL here.
1409 // use its main part - ignore optional jumpmarks!
1410 const ::rtl::OUString sURL
= xModel
->getURL();
1411 if (!::utl::UCBContentHelper::EqualURLs( m_aURL
.Main
, sURL
))
1417 // get the original load arguments from the current document
1418 // and decide if its realy the same then the one will be.
1419 // It must be visible and must use the same file revision ...
1420 // or must not have any file revision set (-1 == -1!)
1421 ::comphelper::MediaDescriptor
lOldDocDescriptor(xModel
->getArgs());
1423 if (lOldDocDescriptor
.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_VERSION(), (sal_Int32
)(-1)) != nNewVersion
)
1429 // Hidden frames are special.
1430 // They will be used as "last chance" if there is no visible frame pointing to the same model.
1431 // Safe the result but continue with current loop might be looking for other visible frames.
1432 ::sal_Bool bIsHidden
= lOldDocDescriptor
.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_HIDDEN(), sal_False
);
1435 ( ! xHiddenTask
.is())
1438 xHiddenTask
= xTask
;
1443 // We found a visible task pointing to the right model ...
1447 catch(const css::uno::RuntimeException
& exRun
)
1449 catch(const css::uno::Exception
&)
1453 css::uno::Reference
< css::frame::XFrame
> xResult
;
1457 if (xHiddenTask
.is())
1458 xResult
= xHiddenTask
;
1462 // Now we are shure, that this task includes the searched document.
1463 // It's time to activate it. As special feature we try to jump internaly
1464 // if an optional jumpmark is given too.
1465 if (m_aURL
.Mark
.getLength())
1466 impl_jumpToMark(xResult
, m_aURL
);
1468 // bring it to front and make sure it's visible...
1469 impl_makeFrameWindowVisible(xResult
->getContainerWindow(), sal_True
);
1478 /*-----------------------------------------------
1480 -----------------------------------------------*/
1481 sal_Bool
LoadEnv::impl_isFrameAlreadyUsedForLoading(const css::uno::Reference
< css::frame::XFrame
>& xFrame
) const
1483 css::uno::Reference
< css::document::XActionLockable
> xLock(xFrame
, css::uno::UNO_QUERY
);
1485 // ? no lock interface ?
1486 // Might its an external written frame implementation :-(
1487 // Allowing using of it ... but it can fail if its not synchronized with our processes !
1491 // Otherwhise we have to look for any other existing lock.
1492 return xLock
->isActionLocked();
1495 /*-----------------------------------------------
1497 -----------------------------------------------*/
1498 css::uno::Reference
< css::frame::XFrame
> LoadEnv::impl_searchRecycleTarget()
1499 throw(LoadEnvException
, css::uno::RuntimeException
)
1501 // SAFE -> ..................................
1502 ReadGuard
aReadLock(m_aLock
);
1504 // The special backing mode frame will be recycled by definition!
1505 // It does'nt matter if somehwere whish to create a new view
1506 // or open a new untitled document ...
1507 // The only exception form that - hidden frames!
1508 if (m_lMediaDescriptor
.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_HIDDEN(), sal_False
) == sal_True
)
1509 return css::uno::Reference
< css::frame::XFrame
>();
1511 css::uno::Reference
< css::frame::XFramesSupplier
> xSupplier(m_xSMGR
->createInstance(SERVICENAME_DESKTOP
), css::uno::UNO_QUERY
);
1512 FrameListAnalyzer
aTasksAnalyzer(xSupplier
, css::uno::Reference
< css::frame::XFrame
>(), FrameListAnalyzer::E_BACKINGCOMPONENT
);
1513 if (aTasksAnalyzer
.m_xBackingComponent
.is())
1515 if (!impl_isFrameAlreadyUsedForLoading(aTasksAnalyzer
.m_xBackingComponent
))
1517 // bring it to front ...
1518 impl_makeFrameWindowVisible(aTasksAnalyzer
.m_xBackingComponent
->getContainerWindow(), sal_True
);
1519 return aTasksAnalyzer
.m_xBackingComponent
;
1523 // These states indicates the wishing for creation of a new view in general.
1525 (m_lMediaDescriptor
.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_ASTEMPLATE() , sal_False
) == sal_True
) ||
1526 (m_lMediaDescriptor
.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_OPENNEWVIEW(), sal_False
) == sal_True
)
1529 return css::uno::Reference
< css::frame::XFrame
>();
1532 // On the other side some special URLs will open a new frame everytimes (expecting
1533 // they can use the backing-mode frame!)
1535 (ProtocolCheck::isProtocol(m_aURL
.Complete
, ProtocolCheck::E_PRIVATE_FACTORY
)) ||
1536 (ProtocolCheck::isProtocol(m_aURL
.Complete
, ProtocolCheck::E_PRIVATE_STREAM
)) ||
1537 (ProtocolCheck::isProtocol(m_aURL
.Complete
, ProtocolCheck::E_PRIVATE_OBJECT
))
1540 return css::uno::Reference
< css::frame::XFrame
>();
1543 // No backing frame! No special URL => recycle active task - if possible.
1544 // Means - if it does not already contains a modified document, or
1545 // use another office module.
1546 css::uno::Reference
< css::frame::XFrame
> xTask
= xSupplier
->getActiveFrame();
1548 // not a real error - but might a focus problem!
1550 return css::uno::Reference
< css::frame::XFrame
>();
1552 // not a real error - may its a view only
1553 css::uno::Reference
< css::frame::XController
> xController
= xTask
->getController();
1554 if (!xController
.is())
1555 return css::uno::Reference
< css::frame::XFrame
>();
1557 // not a real error - may its a db component instead of a full feartured office document
1558 css::uno::Reference
< css::frame::XModel
> xModel
= xController
->getModel();
1560 return css::uno::Reference
< css::frame::XFrame
>();
1562 // get some more informations ...
1564 // A valid set URL means: there is already a location for this document.
1565 // => it was saved there or opened from there. Such Documents can not be used here.
1566 // We search for empty document ... created by a private:factory/ URL!
1567 if (xModel
->getURL().getLength()>0)
1568 return css::uno::Reference
< css::frame::XFrame
>();
1570 // The old document must be unmodified ...
1571 css::uno::Reference
< css::util::XModifiable
> xModified(xModel
, css::uno::UNO_QUERY
);
1572 if (xModified
->isModified())
1573 return css::uno::Reference
< css::frame::XFrame
>();
1575 Window
* pWindow
= VCLUnoHelper::GetWindow(xTask
->getContainerWindow());
1576 if (pWindow
&& pWindow
->IsInModalMode())
1577 return css::uno::Reference
< css::frame::XFrame
>();
1579 // find out the application type of this document
1580 // We can recycle only documents, which uses the same application
1581 // then the new one.
1582 SvtModuleOptions::EFactory eOldApp
= SvtModuleOptions::ClassifyFactoryByModel(xModel
);
1583 SvtModuleOptions::EFactory eNewApp
= SvtModuleOptions::ClassifyFactoryByURL (m_aURL
.Complete
, m_lMediaDescriptor
.getAsConstPropertyValueList());
1586 // <- SAFE ..................................
1588 if (eOldApp
!= eNewApp
)
1589 return css::uno::Reference
< css::frame::XFrame
>();
1591 // OK this task seams to be useable for recycling
1592 // But we should mark it as such - means set an action lock.
1593 // Otherwhise it would be used more then ones or will be destroyed
1594 // by a close() or terminate() request.
1595 // But if such lock already exist ... it means this task is used for
1596 // any other operation already. Don't use it then.
1597 if (impl_isFrameAlreadyUsedForLoading(xTask
))
1598 return css::uno::Reference
< css::frame::XFrame
>();
1600 // OK - there is a valid target frame.
1601 // But may be it contains already a document.
1602 // Then we have to ask it, if it allows recylcing of this frame .-)
1603 sal_Bool bReactivateOldControllerOnError
= sal_False
;
1604 css::uno::Reference
< css::frame::XController
> xOldDoc
= xTask
->getController();
1607 bReactivateOldControllerOnError
= xOldDoc
->suspend(sal_True
);
1608 if (! bReactivateOldControllerOnError
)
1609 return css::uno::Reference
< css::frame::XFrame
>();
1612 // SAFE -> ..................................
1613 WriteGuard
aWriteLock(m_aLock
);
1615 css::uno::Reference
< css::document::XActionLockable
> xLock(xTask
, css::uno::UNO_QUERY
);
1616 if (!m_aTargetLock
.setResource(xLock
))
1617 return css::uno::Reference
< css::frame::XFrame
>();
1619 m_bReactivateControllerOnError
= bReactivateOldControllerOnError
;
1620 aWriteLock
.unlock();
1621 // <- SAFE ..................................
1623 // bring it to front ...
1624 impl_makeFrameWindowVisible(xTask
->getContainerWindow(), sal_True
);
1629 /*-----------------------------------------------
1631 -----------------------------------------------*/
1632 void LoadEnv::impl_reactForLoadingState()
1633 throw(LoadEnvException
, css::uno::RuntimeException
)
1635 /*TODO reset action locks */
1637 // SAFE -> ----------------------------------
1638 ReadGuard
aReadLock(m_aLock
);
1642 // Bring the new loaded document to front (if allowed!).
1643 // Note: We show new created frames here only.
1644 // We dont hide already visible frames here ...
1645 css::uno::Reference
< css::awt::XWindow
> xWindow
= m_xTargetFrame
->getContainerWindow();
1646 sal_Bool bHidden
= m_lMediaDescriptor
.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_HIDDEN(), sal_False
);
1647 sal_Bool bMinimized
= m_lMediaDescriptor
.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_MINIMIZED(), sal_False
);
1651 ::vos::OClearableGuard
aSolarGuard(Application::GetSolarMutex());
1652 Window
* pWindow
= VCLUnoHelper::GetWindow(xWindow
);
1653 // check for system window is neccessary to guarantee correct pointer cast!
1654 if (pWindow
&& pWindow
->IsSystemWindow())
1655 ((WorkWindow
*)pWindow
)->Minimize();
1660 // show frame ... if it's not still visible ...
1661 // But do nothing if it's already visible!
1662 impl_makeFrameWindowVisible(xWindow
, sal_False
);
1665 // Note: Only if an existing property "FrameName" is given by this media descriptor,
1666 // it should be used. Otherwhise we should do nothing. May be the outside code has already
1667 // set a frame name on the target!
1668 ::comphelper::MediaDescriptor::const_iterator pFrameName
= m_lMediaDescriptor
.find(::comphelper::MediaDescriptor::PROP_FRAMENAME());
1669 if (pFrameName
!= m_lMediaDescriptor
.end())
1671 ::rtl::OUString sFrameName
;
1672 pFrameName
->second
>>= sFrameName
;
1673 // Check the name again. e.g. "_default" isnt allowed.
1674 // On the other side "_beamer" is a valid name :-)
1675 if (TargetHelper::isValidNameForFrame(sFrameName
))
1676 m_xTargetFrame
->setName(sFrameName
);
1679 else if (m_bReactivateControllerOnError
)
1681 // Try to reactivate the old document (if any exists!)
1682 css::uno::Reference
< css::frame::XController
> xOldDoc
= m_xTargetFrame
->getController();
1683 // clear does not depend from reactivation state of a might existing old document!
1684 // We must make shure, that a might following getTargetComponent() call does not return
1685 // the old document!
1686 m_xTargetFrame
.clear();
1689 sal_Bool bReactivated
= xOldDoc
->suspend(sal_False
);
1691 throw LoadEnvException(LoadEnvException::ID_COULD_NOT_REACTIVATE_CONTROLLER
);
1692 m_bReactivateControllerOnError
= sal_False
;
1695 else if (m_bCloseFrameOnError
)
1697 // close empty frames
1698 css::uno::Reference
< css::util::XCloseable
> xCloseable (m_xTargetFrame
, css::uno::UNO_QUERY
);
1699 css::uno::Reference
< css::lang::XComponent
> xDisposable(m_xTargetFrame
, css::uno::UNO_QUERY
);
1703 if (xCloseable
.is())
1704 xCloseable
->close(sal_True
);
1706 if (xDisposable
.is())
1707 xDisposable
->dispose();
1709 catch(const css::util::CloseVetoException
&)
1711 catch(const css::lang::DisposedException
&)
1713 m_xTargetFrame
.clear();
1716 // This max force an implicit closing of our target frame ...
1717 // e.g. in case close(TRUE) was called before and the frame
1718 // kill itself if our external use-lock is released here!
1719 // Thats why we releas this lock AFTER ALL OPERATIONS on this frame
1720 // are finished. The frame itslef must handle then
1721 // this situation gracefully.
1722 m_aTargetLock
.freeResource();
1724 // Last but not least :-)
1725 // We have to clear the current media descriptor.
1726 // Otherwhise it hold a might existing stream open!
1727 m_lMediaDescriptor
.clear();
1729 css::uno::Any aRequest
;
1730 bool bThrow
= false;
1731 if ( !m_bLoaded
&& m_pQuietInteraction
&& m_pQuietInteraction
->wasUsed() )
1733 aRequest
= m_pQuietInteraction
->getRequest();
1734 m_pQuietInteraction
->release();
1735 m_pQuietInteraction
= 0;
1743 if ( aRequest
.isExtractableTo( ::cppu::UnoType
< css::uno::Exception
>::get() ) )
1744 throw LoadEnvException( LoadEnvException::ID_GENERAL_ERROR
, aRequest
);
1747 // <- SAFE ----------------------------------
1750 /*-----------------------------------------------
1752 -----------------------------------------------*/
1753 void LoadEnv::impl_makeFrameWindowVisible(const css::uno::Reference
< css::awt::XWindow
>& xWindow
,
1754 sal_Bool bForceToFront
)
1756 // SAFE -> ----------------------------------
1757 ReadGuard
aReadLock(m_aLock
);
1758 css::uno::Reference
< css::lang::XMultiServiceFactory
> xSMGR( m_xSMGR
.get(), css::uno::UNO_QUERY
);
1760 // <- SAFE ----------------------------------
1762 ::vos::OClearableGuard
aSolarGuard(Application::GetSolarMutex());
1763 Window
* pWindow
= VCLUnoHelper::GetWindow(xWindow
);
1766 bool bForceFrontAndFocus(false);
1767 css::uno::Any a
= ::comphelper::ConfigurationHelper::readDirectKey(
1769 ::rtl::OUString::createFromAscii("org.openoffice.Office.Common/View"),
1770 ::rtl::OUString::createFromAscii("NewDocumentHandling"),
1771 ::rtl::OUString::createFromAscii("ForceFocusAndToFront"),
1772 ::comphelper::ConfigurationHelper::E_READONLY
);
1773 a
>>= bForceFrontAndFocus
;
1775 if( pWindow
->IsVisible() && (bForceFrontAndFocus
|| bForceToFront
) )
1778 pWindow
->Show(sal_True
, (bForceFrontAndFocus
|| bForceToFront
) ? SHOW_FOREGROUNDTASK
: 0 );
1782 We tried to prevent a toFront() call in case the user putted the
1783 loading document into the background ..
1784 But we had several errors trying that. So we decided to
1785 rollback these changes and bring the new loaded document to front hardly !
1787 css::uno::Reference< css::awt::XWindow2 > xWindow2(xWindow, css::uno::UNO_QUERY);
1789 sal_Bool bIsVisible = sal_False;
1791 bIsVisible = xWindow2->isVisible(); // TODO is parent visible too ? .-)
1795 xWindow->setVisible(sal_True);
1796 bForceToFront = sal_True;
1804 xTopWindow->toFront();
1809 /*-----------------------------------------------
1811 -----------------------------------------------*/
1812 void LoadEnv::impl_applyPersistentWindowState(const css::uno::Reference
< css::awt::XWindow
>& xWindow
)
1814 static ::rtl::OUString PACKAGE_SETUP_MODULES
= ::rtl::OUString::createFromAscii("/org.openoffice.Setup/Office/Factories");
1816 // no window -> action not possible
1820 // window already visible -> do nothing! If we use a "recycle frame" for loading ...
1821 // the current position and size must be used.
1822 css::uno::Reference
< css::awt::XWindow2
> xVisibleCheck(xWindow
, css::uno::UNO_QUERY
);
1824 (xVisibleCheck
.is() ) &&
1825 (xVisibleCheck
->isVisible())
1830 ::vos::OClearableGuard
aSolarLock1(Application::GetSolarMutex());
1832 Window
* pWindow
= VCLUnoHelper::GetWindow(xWindow
);
1833 sal_Bool bSystemWindow
= pWindow
->IsSystemWindow();
1834 sal_Bool bWorkWindow
= (pWindow
->GetType() == WINDOW_WORKWINDOW
);
1836 if (!bSystemWindow
&& !bWorkWindow
)
1839 // dont overwrite this special state!
1840 WorkWindow
* pWorkWindow
= (WorkWindow
*)pWindow
;
1841 if (pWorkWindow
->IsMinimized())
1844 aSolarLock1
.clear();
1848 ReadGuard
aReadLock(m_aLock
);
1850 // no filter -> no module -> no persistent window state
1851 ::rtl::OUString sFilter
= m_lMediaDescriptor
.getUnpackedValueOrDefault(
1852 ::comphelper::MediaDescriptor::PROP_FILTERNAME(),
1854 if (!sFilter
.getLength())
1857 css::uno::Reference
< css::lang::XMultiServiceFactory
> xSMGR
= m_xSMGR
;
1864 // retrieve the module name from the filter configuration
1865 css::uno::Reference
< css::container::XNameAccess
> xFilterCfg(
1866 xSMGR
->createInstance(SERVICENAME_FILTERFACTORY
),
1867 css::uno::UNO_QUERY_THROW
);
1868 ::comphelper::SequenceAsHashMap
lProps (xFilterCfg
->getByName(sFilter
));
1869 ::rtl::OUString sModule
= lProps
.getUnpackedValueOrDefault(FILTER_PROPNAME_DOCUMENTSERVICE
, ::rtl::OUString());
1871 // get access to the configuration of this office module
1872 css::uno::Reference
< css::container::XNameAccess
> xModuleCfg(::comphelper::ConfigurationHelper::openConfig(
1874 PACKAGE_SETUP_MODULES
,
1875 ::comphelper::ConfigurationHelper::E_READONLY
),
1876 css::uno::UNO_QUERY_THROW
);
1878 // read window state from the configuration
1879 // and apply it on the window.
1880 // Do nothing, if no configuration entry exists!
1881 ::rtl::OUString sWindowState
;
1882 ::comphelper::ConfigurationHelper::readRelativeKey(xModuleCfg
, sModule
, OFFICEFACTORY_PROPNAME_WINDOWATTRIBUTES
) >>= sWindowState
;
1883 if (sWindowState
.getLength())
1886 ::vos::OClearableGuard
aSolarLock2(Application::GetSolarMutex());
1888 // We have to retrieve the window pointer again. Because nobody can guarantee
1889 // that the XWindow was not disposed inbetween .-)
1890 // But if we get a valid pointer we can be sure, that it's the system window pointer
1891 // we already checked and used before. Because nobody recylce the same uno reference for
1892 // a new internal c++ implementation ... hopefully .-))
1893 Window
* pWindowCheck
= VCLUnoHelper::GetWindow(xWindow
);
1897 SystemWindow
* pSystemWindow
= (SystemWindow
*)pWindowCheck
;
1898 pSystemWindow
->SetWindowState(U2B_ENC(sWindowState
,RTL_TEXTENCODING_UTF8
));
1900 aSolarLock2
.clear();
1904 catch(const css::uno::RuntimeException
& exRun
)
1906 catch(const css::uno::Exception
&)
1910 } // namespace framework