merged tag ooo/OOO330_m14
[LibreOffice.git] / framework / source / loadenv / loadenv.cxx
blob75bcc4c4587f205b717e14330a87d12a9a1d8965
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>
36 #endif
37 #include <classes/framelistanalyzer.hxx>
39 #include <dispatch/interaction.hxx>
41 #ifndef __FRAMEWORK_CONSTANT_FRAMELOADER_HXX_
42 #include <constant/frameloader.hxx>
43 #endif
45 #ifndef __FRAMEWORK_CONSTANT_CONTENTHANDLER_HXX_
46 #include <constant/contenthandler.hxx>
47 #endif
49 #ifndef __FRAMEWORK_CONSTANT_CONTAINERQUERY_HXX_
50 #include <constant/containerquery.hxx>
51 #endif
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>
58 #include <services.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>
102 #endif
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 //_______________________________________________
112 // namespace
114 namespace framework{
116 // may there exist already a define .-(
117 #ifndef css
118 namespace css = ::com::sun::star;
119 #endif
121 //_______________________________________________
122 // declarations
124 class LoadEnvListener : private ThreadHelpBase
125 , public ::cppu::WeakImplHelper2< css::frame::XLoadEventListener ,
126 css::frame::XDispatchResultListener >
128 private:
130 void** m_ppCheck ;
131 LoadEnv* m_pLoadEnv;
133 public:
135 //_______________________________________
136 LoadEnvListener(void* pCheck ,
137 LoadEnv* pLoadEnv)
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 /*-----------------------------------------------
163 14.10.2003 13:43
164 -----------------------------------------------*/
165 LoadEnv::LoadEnv(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
166 throw(LoadEnvException, css::uno::RuntimeException)
167 : ThreadHelpBase( )
168 , m_xSMGR (xSMGR)
169 , m_pCheck (this )
170 , m_pQuietInteraction( 0 )
174 /*-----------------------------------------------
175 14.10.2003 13:43
176 -----------------------------------------------*/
177 LoadEnv::~LoadEnv()
179 m_pCheck = 0;
182 /*-----------------------------------------------
183 10.09.2003 14:05
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,
189 sal_Int32 nFlags ,
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;
199 LoadEnv aEnv(xSMGR);
201 aEnv.initializeLoading(sURL,
202 lArgs,
203 css::uno::Reference< css::frame::XFrame >(xLoader, css::uno::UNO_QUERY),
204 sTarget,
205 nFlags,
206 LoadEnv::E_NO_FEATURE);
207 aEnv.startLoading();
208 aEnv.waitWhileLoading(); // wait for ever!
210 xComponent = aEnv.getTargetComponent();
212 catch(const LoadEnvException& ex)
214 switch(ex.m_nID)
216 case LoadEnvException::ID_INVALID_MEDIADESCRIPTOR:
217 throw css::lang::IllegalArgumentException(
218 ::rtl::OUString::createFromAscii("Optional list of arguments seem to be corrupted."),
219 xLoader,
222 case LoadEnvException::ID_UNSUPPORTED_CONTENT:
223 throw css::lang::IllegalArgumentException(
224 ::rtl::OUString::createFromAscii("URL seems to be an unsupported one."),
225 xLoader,
228 default: xComponent.clear();
229 break;
233 return xComponent;
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 > ());
243 if (xModel.is ())
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;
251 return lDescriptor;
254 /*-----------------------------------------------
255 20.08.2003 09:49
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? */
322 // UI mode
323 const bool bUIMode =
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(
329 m_xSMGR,
330 m_lMediaDescriptor,
331 bUIMode,
332 &m_pQuietInteraction
335 aWriteLock.unlock();
336 // <- SAFE ----------------------------------
339 /*-----------------------------------------------
340 22.01.2010
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 ;
350 if ( i_bUIMode )
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& ) { }
361 // hidden mode
362 else
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();
375 if (
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 /*-----------------------------------------------
391 15.08.2003 08:16
392 -----------------------------------------------*/
393 void LoadEnv::startLoading()
394 throw(LoadEnvException, css::uno::RuntimeException)
396 // SAFE ->
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);
408 // <- SAFE
409 aReadLock.unlock();
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;
425 if (
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();
433 if (!bStarted)
434 bStarted = impl_loadContent();
436 // not started => general error
437 // We cant say - what was the reason for.
438 if (!bStarted)
439 throw LoadEnvException(LoadEnvException::ID_GENERAL_ERROR);
442 /*-----------------------------------------------
443 15.08.2003 09:50
444 TODO
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;
457 while(true)
459 // SAFE -> ------------------------------
460 ReadGuard aReadLock1(m_aLock);
461 if (!m_xAsynchronousJob.is())
462 break;
463 aReadLock1.unlock();
464 // <- SAFE ------------------------------
466 Application::Yield();
468 // forever!
469 if (nTimeout==0)
470 continue;
472 // timed out?
473 --nTime;
474 if (nTime<1)
475 break;
478 // SAFE -> ----------------------------------
479 ReadGuard aReadLock2(m_aLock);
480 return !m_xAsynchronousJob.is();
481 // <- SAFE ----------------------------------
484 /*-----------------------------------------------
485 20.08.2003 10:00
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())
501 aReadLock.unlock();
502 // <- BREAK SAFE ------------------------------
503 xAsyncLoader->cancel();
504 // <- RESTART SAFE ----------------------------
505 aReadLock.lock();
506 /* Attention:
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 :-)
518 else
519 throw LoadEnvException(LoadEnvException::ID_STILL_RUNNING);
522 impl_reactForLoadingState();
524 aReadLock.unlock();
525 // <- PARTIAL(!) SAFE ------------------------------
528 /*-----------------------------------------------
529 14.08.2003 13:33
530 -----------------------------------------------*/
531 css::uno::Reference< css::frame::XFrame > LoadEnv::getTarget() const
533 // SAFE ->
534 ReadGuard aReadLock(m_aLock);
535 return m_xTargetFrame;
536 // <- SAFE
539 /*-----------------------------------------------
540 14.08.2003 13:35
541 -----------------------------------------------*/
542 css::uno::Reference< css::lang::XComponent > LoadEnv::getTargetComponent() const
544 // SAFE ->
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();
555 if (!xModel.is())
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);
559 // <- SAFE
562 /*-----------------------------------------------
563 15.08.2003 11:15
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);
573 m_ppCheck = NULL;
575 aWriteLock.unlock();
576 // <- SAFE ----------------------------------
579 /*-----------------------------------------------
580 14.10.2003 12:23
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);
590 m_ppCheck = NULL;
592 aWriteLock.unlock();
593 // <- SAFE ----------------------------------
596 /*-----------------------------------------------
597 14.10.2003 12:23
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)
606 return;
608 switch(aEvent.State)
610 case css::frame::DispatchResultState::FAILURE :
611 m_pLoadEnv->impl_setResult(sal_False);
612 break;
614 case css::frame::DispatchResultState::SUCCESS :
615 m_pLoadEnv->impl_setResult(sal_False);
616 break;
618 case css::frame::DispatchResultState::DONTKNOW :
619 m_pLoadEnv->impl_setResult(sal_False);
620 break;
622 m_ppCheck = NULL;
624 aWriteLock.unlock();
625 // <- SAFE ----------------------------------
628 /*-----------------------------------------------
629 14.10.2003 12:24
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);
639 m_ppCheck = NULL;
641 aWriteLock.unlock();
642 // <- SAFE ----------------------------------
645 /*-----------------------------------------------
646 14.10.2003 12:20
647 -----------------------------------------------*/
648 void LoadEnv::impl_setResult(sal_Bool bResult)
650 // SAFE -> ----------------------------------
651 WriteGuard aWriteLock(m_aLock);
653 m_bLoaded = bResult;
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();
662 aWriteLock.unlock();
663 // <- SAFE ----------------------------------
666 /*-----------------------------------------------
667 06.02.2004 14:03
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
710 in a special way .-)
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;
726 if (xStream.is())
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;
739 if (xModel.is())
740 return E_CAN_BE_SET;
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 /*-----------------------------------------------
825 03.11.2003 09:31
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;
834 // SAFE ->
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;
843 aReadLock.unlock();
844 // <- SAFE
846 ::rtl::OUString sType;
847 css::uno::Reference< css::document::XTypeDetection > xDetect(xSMGR->createInstance(SERVICENAME_TYPEDETECTION), css::uno::UNO_QUERY);
848 if (xDetect.is())
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);
855 // SAFE ->
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?
862 // see below ...
863 ::rtl::OUString sFilter = m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_FILTERNAME(), ::rtl::OUString());
865 aWriteLock.unlock();
866 // <- SAFE
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())
886 // SAFE ->
887 aWriteLock.lock();
888 m_lMediaDescriptor[::comphelper::MediaDescriptor::PROP_FILTERNAME()] <<= sFilter;
889 aWriteLock.unlock();
890 // <- SAFE
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&)
918 if (bIsOwnTemplate)
920 // SAFE ->
921 aWriteLock.lock();
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;
926 aWriteLock.unlock();
927 // <- SAFE
931 /*-----------------------------------------------
932 15.08.2003 09:38
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);
954 aReadLock.unlock();
955 // <- SAFE -----------------------------------
957 // query
958 css::uno::Sequence< ::rtl::OUString > lTypeReg(1);
959 lTypeReg[0] = sType;
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);
975 if (!xHandler.is())
976 continue;
978 catch(const css::uno::RuntimeException&)
979 { throw; }
980 catch(const css::uno::Exception&)
981 { continue; }
983 // SAFE -> -----------------------------------
984 WriteGuard aWriteLock(m_aLock);
985 m_xAsynchronousJob = xHandler;
986 m_pCheck = this;
987 LoadEnvListener* pListener = new LoadEnvListener(m_pCheck, this);
988 aWriteLock.unlock();
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);
994 return sal_True;
997 return sal_False;
1000 //-----------------------------------------------
1001 sal_Bool LoadEnv::impl_furtherDocsAllowed()
1003 // SAFE ->
1004 ReadGuard aReadLock(m_aLock);
1005 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
1006 aReadLock.unlock();
1007 // <- SAFE
1009 sal_Bool bAllowed = sal_True;
1013 css::uno::Any aVal = ::comphelper::ConfigurationHelper::readDirectKey(
1014 xSMGR,
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 !
1021 // => return TRUE
1022 if ( ! aVal.hasValue())
1023 bAllowed = sal_True;
1024 else
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 .-)
1046 if ( ! bAllowed )
1048 // SAFE ->
1049 aReadLock.lock();
1050 css::uno::Reference< css::task::XInteractionHandler > xInteraction = m_lMediaDescriptor.getUnpackedValueOrDefault(
1051 ::comphelper::MediaDescriptor::PROP_INTERACTIONHANDLER(),
1052 css::uno::Reference< css::task::XInteractionHandler >());
1053 aReadLock.unlock();
1054 // <- SAFE
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);
1084 return bAllowed;
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);
1102 return sal_True;
1104 m_xTargetFrame = impl_searchRecycleTarget();
1107 if (! m_xTargetFrame.is())
1109 if (
1110 (TargetHelper::matchSpecialTarget(sTarget, TargetHelper::E_BLANK )) ||
1111 (TargetHelper::matchSpecialTarget(sTarget, TargetHelper::E_DEFAULT))
1114 if (! impl_furtherDocsAllowed())
1115 return sal_False;
1116 m_xTargetFrame = m_xBaseFrame->findFrame(SPECIALTARGET_BLANK, 0);
1117 m_bCloseFrameOnError = m_xTargetFrame.is();
1119 else
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())
1126 return sal_False;
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.
1135 if (
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
1145 // frame window.
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();
1180 if (xProgress.is())
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 -> -----------------------------------
1198 aWriteLock.lock();
1199 m_xAsynchronousJob = xAsyncLoader;
1200 m_pCheck = this;
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);
1208 return sal_True;
1210 else
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 :-)
1219 return sal_True;
1222 aWriteLock.unlock();
1223 // <- SAFE
1225 return sal_False;
1228 /*-----------------------------------------------
1229 06.02.2004 14:40
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&)
1246 { throw; }
1247 catch(const css::uno::Exception&)
1249 throw LoadEnvException(LoadEnvException::ID_INVALID_ENVIRONMENT);
1252 // Otherwhise ...
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);
1263 aReadLock.unlock();
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())
1276 // try everyone ...
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);
1284 if (xLoader.is())
1285 return xLoader;
1287 catch(const css::uno::RuntimeException&)
1288 { throw; }
1289 catch(const css::uno::Exception&)
1290 { continue; }
1293 return css::uno::Reference< css::uno::XInterface >();
1296 /*-----------------------------------------------
1297 24.01.2006 15:11
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())
1303 return;
1305 css::uno::Reference< css::frame::XDispatchProvider > xProvider(xFrame, css::uno::UNO_QUERY);
1306 if (! xProvider.is())
1307 return;
1309 // SAFE ->
1310 ReadGuard aReadLock(m_aLock);
1311 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
1312 aReadLock.unlock();
1313 // <- SAFE
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())
1323 return;
1325 ::comphelper::SequenceAsHashMap lArgs;
1326 lArgs[::rtl::OUString::createFromAscii("Bookmark")] <<= aURL.Mark;
1327 xDispatcher->dispatch(aCmd, lArgs.getAsConstPropertyValueList());
1330 /*-----------------------------------------------
1331 31.07.2003 09:02
1332 -----------------------------------------------*/
1333 css::uno::Reference< css::frame::XFrame > LoadEnv::impl_searchAlreadyLoaded()
1334 throw(LoadEnvException, css::uno::RuntimeException)
1336 // SAFE ->
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 :-)
1341 if (
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 >();
1351 // check URL
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!
1354 if (
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;
1391 if (!xTask.is())
1392 continue;
1394 css::uno::Reference< css::frame::XController > xController = xTask->getController();
1395 if (!xController.is())
1397 xTask.clear ();
1398 continue;
1401 css::uno::Reference< css::frame::XModel > xModel = xController->getModel();
1402 if (!xModel.is())
1404 xTask.clear ();
1405 continue;
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 ))
1413 xTask.clear ();
1414 continue;
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)
1425 xTask.clear ();
1426 continue;
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);
1433 if (
1434 ( bIsHidden ) &&
1435 ( ! xHiddenTask.is())
1438 xHiddenTask = xTask;
1439 xTask.clear ();
1440 continue;
1443 // We found a visible task pointing to the right model ...
1444 // Break search.
1445 break;
1447 catch(const css::uno::RuntimeException& exRun)
1448 { throw exRun; }
1449 catch(const css::uno::Exception&)
1450 { continue; }
1453 css::uno::Reference< css::frame::XFrame > xResult;
1454 if (xTask.is())
1455 xResult = xTask;
1456 else
1457 if (xHiddenTask.is())
1458 xResult = xHiddenTask;
1460 if (xResult.is())
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);
1472 aReadLock.unlock();
1473 // <- SAFE
1475 return xResult;
1478 /*-----------------------------------------------
1479 30.03.2004 09:12
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 !
1488 if (!xLock.is())
1489 return sal_False;
1491 // Otherwhise we have to look for any other existing lock.
1492 return xLock->isActionLocked();
1495 /*-----------------------------------------------
1496 30.03.2004 09:12
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.
1524 if (
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!)
1534 if (
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!
1549 if (!xTask.is())
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();
1559 if (!xModel.is())
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());
1585 aReadLock.unlock();
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();
1605 if (xOldDoc.is())
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);
1626 return xTask;
1629 /*-----------------------------------------------
1630 15.08.2003 12:39
1631 -----------------------------------------------*/
1632 void LoadEnv::impl_reactForLoadingState()
1633 throw(LoadEnvException, css::uno::RuntimeException)
1635 /*TODO reset action locks */
1637 // SAFE -> ----------------------------------
1638 ReadGuard aReadLock(m_aLock);
1640 if (m_bLoaded)
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);
1649 if (bMinimized)
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();
1657 else
1658 if (!bHidden)
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();
1687 if (xOldDoc.is())
1689 sal_Bool bReactivated = xOldDoc->suspend(sal_False);
1690 if (!bReactivated)
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);
1705 else
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;
1736 bThrow = true;
1739 aReadLock.unlock();
1741 if (bThrow)
1743 if ( aRequest.isExtractableTo( ::cppu::UnoType< css::uno::Exception >::get() ) )
1744 throw LoadEnvException( LoadEnvException::ID_GENERAL_ERROR, aRequest );
1747 // <- SAFE ----------------------------------
1750 /*-----------------------------------------------
1751 16.01.2005 13:04
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 );
1759 aReadLock.unlock();
1760 // <- SAFE ----------------------------------
1762 ::vos::OClearableGuard aSolarGuard(Application::GetSolarMutex());
1763 Window* pWindow = VCLUnoHelper::GetWindow(xWindow);
1764 if ( pWindow )
1766 bool bForceFrontAndFocus(false);
1767 css::uno::Any a = ::comphelper::ConfigurationHelper::readDirectKey(
1768 xSMGR,
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) )
1776 pWindow->ToTop();
1777 else
1778 pWindow->Show(sal_True, (bForceFrontAndFocus || bForceToFront) ? SHOW_FOREGROUNDTASK : 0 );
1781 /* #i19976#
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;
1790 if (xWindow2.is())
1791 bIsVisible = xWindow2->isVisible(); // TODO is parent visible too ? .-)
1793 if (!bIsVisible)
1795 xWindow->setVisible(sal_True);
1796 bForceToFront = sal_True;
1799 if (
1800 (bForceToFront ) &&
1801 (xTopWindow.is())
1804 xTopWindow->toFront();
1809 /*-----------------------------------------------
1810 15.03.2005 11:12
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
1817 if (!xWindow.is())
1818 return;
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);
1823 if (
1824 (xVisibleCheck.is() ) &&
1825 (xVisibleCheck->isVisible())
1827 return;
1829 // SOLAR SAFE ->
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)
1837 return;
1839 // dont overwrite this special state!
1840 WorkWindow* pWorkWindow = (WorkWindow*)pWindow;
1841 if (pWorkWindow->IsMinimized())
1842 return;
1844 aSolarLock1.clear();
1845 // <- SOLAR SAFE
1847 // SAFE ->
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(),
1853 ::rtl::OUString());
1854 if (!sFilter.getLength())
1855 return;
1857 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
1859 aReadLock.unlock();
1860 // <- SAFE
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(
1873 xSMGR,
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())
1885 // SOLAR SAFE ->
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);
1894 if (! pWindowCheck)
1895 return;
1897 SystemWindow* pSystemWindow = (SystemWindow*)pWindowCheck;
1898 pSystemWindow->SetWindowState(U2B_ENC(sWindowState,RTL_TEXTENCODING_UTF8));
1900 aSolarLock2.clear();
1901 // <- SOLAR SAFE
1904 catch(const css::uno::RuntimeException& exRun)
1905 { throw exRun; }
1906 catch(const css::uno::Exception&)
1910 } // namespace framework