merge the formfield patch from ooo-build
[ooovba.git] / framework / source / inc / loadenv / loadenv.hxx
blobed73c0a859b6a934d8a8e0195d6aad08dbfa9b43
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: loadenv.hxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef __FRAMEWORK_LOADENV_LOADENV_HXX_
31 #define __FRAMEWORK_LOADENV_LOADENV_HXX_
33 //_______________________________________________
34 // includes of own project
36 #include <loadenv/loadenvexception.hxx>
37 #include <loadenv/actionlockguard.hxx>
38 #include <threadhelp/threadhelpbase.hxx>
40 //_______________________________________________
41 // includes of uno interface
42 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
43 #include <com/sun/star/frame/XComponentLoader.hpp>
44 #include <com/sun/star/frame/XFrameLoader.hpp>
45 #include <com/sun/star/frame/XLoadEventListener.hpp>
46 #include <com/sun/star/frame/XDispatchResultListener.hpp>
47 #include <com/sun/star/frame/XFrame.hpp>
48 #include <com/sun/star/util/URL.hpp>
50 #ifndef _COM_SUN_STAR_LANG_IllegalArgumentException_HPP_
51 #include <com/sun/star/lang/IllegalArgumentException.hpp>
52 #endif
54 #ifndef _COM_SUN_STAR_IO_IOException_HPP_
55 #include <com/sun/star/io/IOException.hpp>
56 #endif
58 //_______________________________________________
59 // includes of an other project
60 #include <comphelper/mediadescriptor.hxx>
61 #include <comphelper/sequenceashashmap.hxx>
62 #include <cppuhelper/implbase2.hxx>
64 //_______________________________________________
65 // namespace
67 namespace framework{
69 namespace css = ::com::sun::star;
70 class QuietInteraction;
71 //_______________________________________________
72 // definitions
74 /** @short implements general mechainsm for loading documents.
76 @descr An instance of this class can be used inside the API calls
77 XComponentLoader::loadComponentFromURL() and XDispatch::dispatch()
78 (of course in its derived interfaces too :-)).
80 @author as96863
82 class LoadEnv : private ThreadHelpBase
84 //___________________________________________
85 // structs, types, etc.
87 public:
89 /** @short enable/disable special features
90 of a load request.
92 @desrc Such features must outcome without
93 any special parameters.
94 To make enableing/disabling of
95 features very easy (e.g. at the ctor of
96 this class) these values must be combinable
97 as flags. That means: its values must be in
98 range of [2^n]!
100 enum EFeature
102 /// we should be informed, if no feature is enabled :-)
103 E_NO_FEATURE = 0,
104 /// enable using of UI elements during loading (means progress, interaction handler etcpp.)
105 E_WORK_WITH_UI = 1,
106 /// enable loading of resources, which are not related to a target frame! (see concept of ContentHandler)
107 E_ALLOW_CONTENTHANDLER = 2
110 //_______________________________________
112 /** @short classify a content.
114 @descr The load environment must know, if a content
115 is related to a target frame or not. Only "visible"
116 components, which full fill the requirements of the
117 model-controller-view paradigm can be loaded into a frame.
118 Such contents are classified as E_CAN_BE_LOADED.
120 But e.g. for the dispatch framework exists special ContentHandler
121 objects, which can load a content in "non visible" mode ...
122 and do not need a target frame for its operation. Such
123 ContentHandler e.g. plays sounds.
124 Such contents are classified as E_CAN_BE_HANDLED.
126 And last but not least a content can be "not valid" in general.
128 enum EContentType
130 /// identifies a content, which seems to be invalid in general
131 E_UNSUPPORTED_CONTENT,
132 /// identifies a content, which can be used with a ContentHandler and is not related to a target frame
133 E_CAN_BE_HANDLED,
134 /// identifies a content, which can be loaded into a target frame
135 E_CAN_BE_LOADED,
136 /// special mode for non real loading, In such case the model is given directly!
137 E_CAN_BE_SET
140 //___________________________________________
141 // member
143 private:
145 /** @short reference to an uno service manager, which must be used
146 to created on needed services on demand.
148 css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR;
150 /** @short points to the frame, which uses this LoadEnv object
151 and must be used to start target search there.
153 css::uno::Reference< css::frame::XFrame > m_xBaseFrame;
155 /** @short points to the frame, into which the new component was loaded.
157 @descr Note: This reference will be empty if loading failed
158 or a non visible content was loaded!
159 It can be the same frame as m_xBaseFrame it describe, in case
160 the target "_self", "" or the search flag "SELF" was used.
161 Otherwhise its the new created or recycled frame, which was
162 used for loading and contains further the new component.
164 Please use method getTarget() or getTargetComponent()
165 to return the frame/controller or model to any interested
166 user of the results of this load request.
168 css::uno::Reference< css::frame::XFrame > m_xTargetFrame;
170 /** @short contains the name of the target, in which the specified resource
171 of this instance must be loaded.
173 ::rtl::OUString m_sTarget;
175 /** @short if m_sTarget is not a special one, this flags regulate searching
176 of a suitable one.
178 sal_Int32 m_nSearchFlags;
180 /** @short contains all needed informations about the resource,
181 which should be loaded.
183 @descr Inside this struct e.g. the URL, its type and filter name,
184 the stream or a model directly are saved.
186 ::comphelper::MediaDescriptor m_lMediaDescriptor;
188 /** @short because the mediadescriptor contains the complete URL ... but
189 some functionality need the structured version, we hold it twice :-(.
191 css::util::URL m_aURL;
193 /** @short enable/disable special features of a load request. */
194 EFeature m_eFeature;
196 /** @short classify the content, which should be loaded by this instance. */
197 EContentType m_eContentType;
199 /** @short it indicates, that the member m_xTargetFrame was new created for this
200 load request and must be closed in case loading (not handling!)
201 operation failed. The default value is FALSE!
203 sal_Bool m_bCloseFrameOnError;
205 /** @short it indicates, that the old document (which was located inside m_xBaseFrame
206 in combination with the m_sTarget value "_self") was suspended.
207 Normaly it will be replaced by the new loaded document. But in case
208 loading (not handling!) failed, it must be reactivated.
209 The default value is FALSE!
211 sal_Bool m_bReactivateControllerOnError;
213 /** @short it holds one (!) asynchronous used contenthandler or frameloader
214 alive, till the asynchronous operation will be finished.
216 css::uno::Reference< css::uno::XInterface > m_xAsynchronousJob;
218 /** @short holds the information about the finished load process.
220 @descr The content of m_xTargetFrame cant be used as valid indicator,
221 (in case the micht existing old document was reactivated)
222 we must hold the result of the load process explicitly.
224 sal_Bool m_bLoaded;
226 /** @short holds an XActionLock on the internal used task member.
228 @seealso m_xTargetFrame
230 ActionLockGuard m_aTargetLock;
232 /** TODO document me ... */
233 void* m_pCheck;
235 QuietInteraction* m_pQuietInteraction;
237 //___________________________________________
238 // native interface
240 public:
242 /** @short initialize a new instance of this load environment.
244 @param xSMGR
245 reference to an uno service manager, which can be used internaly
246 to create on needed services on demand.
248 @throw Currently there is no reason to throw such exception!
250 @throw A RuntimeException in case any internal process indicates, that
251 the whole runtime cant be used any longer.
253 LoadEnv(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
254 throw(LoadEnvException, css::uno::RuntimeException);
256 //_______________________________________
258 /** @short deinitialize an instance of this class in the right way.
260 virtual ~LoadEnv();
262 //_______________________________________
264 /** @short DRAFT TODO
266 static css::uno::Reference< css::lang::XComponent > loadComponentFromURL(const css::uno::Reference< css::frame::XComponentLoader >& xLoader,
267 const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR ,
268 const ::rtl::OUString& sURL ,
269 const ::rtl::OUString& sTarget,
270 sal_Int32 nFlags ,
271 const css::uno::Sequence< css::beans::PropertyValue >& lArgs )
272 throw(css::lang::IllegalArgumentException,
273 css::io::IOException ,
274 css::uno::RuntimeException );
276 //_______________________________________
278 /** @short set some changeable parameters for a new load request.
280 @descr The parameter for targeting, the content description, and
281 some environment specifier (UI, dispatch functionality)
282 can be set here ... BEFORE the real load process is started
283 by calling startLoading(). Of course a still running load request
284 will be detected here and a suitable exception will be thrown.
285 Such constellation can be detected outside by using provided
286 synchronisation methods or callbacks.
288 @param sURL
289 points to the resource, which should be loaded.
291 @param lMediaDescriptor
292 contains additional informations for the following load request.
294 @param xBaseFrame
295 points to the frame which must be used as start point for target search.
297 @param sTarget
298 regulate searching/creating of frames, which should contain the
299 new loaded component afterwards.
301 @param nSearchFlags
302 regulate searching of targets, if sTarget is not a special one.
304 @param eFeature
305 flag field, which enable/disable special features of this
306 new instance for following load call.
308 @param eContentType
309 classify the given content.
310 This value is set to a default value "UNKNWON_CONTENT", which force
311 an internal check, if this content is loadable or not.
312 But may this check was already made by the caller of this method and
313 passing this information to this LoadEnv instance can supress this
314 might expensive check.
315 That can be usefull in case this information is needed outside too,
316 to decide if its neccessary to create some resources for this load
317 request ... or to reject the request imidiatly if it seems to be not
318 loadable in general.
320 @throw A LoadEnvException e.g. if another load operation is till in progress
321 or initialization of a new one fail by other reasons.
322 The real reason, a suitable message and ID will be given here immidiatly.
324 @throw A RuntimeException in case any internal process indicates, that
325 the whole runtime cant be used any longer.
327 virtual void initializeLoading(const ::rtl::OUString& sURL ,
328 const css::uno::Sequence< css::beans::PropertyValue >& lMediaDescriptor,
329 const css::uno::Reference< css::frame::XFrame >& xBaseFrame ,
330 const ::rtl::OUString& sTarget ,
331 sal_Int32 nSearchFlags ,
332 EFeature eFeature = E_NO_FEATURE ,
333 EContentType eContentType = E_UNSUPPORTED_CONTENT)
334 throw(LoadEnvException, css::uno::RuntimeException);
336 //_______________________________________
338 /** @short start loading of the resource represented by this loadenv instance.
340 @descr There is no direct return value possible here. Because it depends
341 from the usage of this instance! E.g. for loading a "visible component"
342 a frame with a controller/model inside can be possible. For loading
343 of a "non visible component" only an information about a successfully start
344 can be provided.
345 Further it cant be guranteed, that the internal process runs synchronous.
346 Thats why we preferr using of specialized methods afterwards e.g. to:
347 - wait till the internal job will be finished
348 and get the results
349 - or to let it run without any further control from outside.
351 @throw A LoadEnvException if start of the load process failed (because
352 another is still in progress!).
353 The reason, a suitable message and ID will be given here immidiatly.
355 @throw A RuntimeException in case any internal process indicates, that
356 the whole runtime cant be used any longer.
358 virtual void startLoading()
359 throw(LoadEnvException, css::uno::RuntimeException);
361 //_______________________________________
363 /** @short wait for an alreay running load request (started by calling
364 startLoading() before).
366 @descr The timeout parameter can be used to wait some times only
367 or forever. The return value indicates if the load request
368 was finished during the specified timeout period.
369 But it indicates not, if the load request was successfully or not!
371 @param nTimeout
372 specify a timeout in [ms].
373 A value 0 let it wait forever!
375 @return TRUE if the started load process could be finished in time;
376 FALSE if the specified time was over.
378 @throw ... currently not used :-)
380 @throw A RuntimeException in case any internal process indicates, that
381 the whole runtime cant be used any longer.
383 virtual sal_Bool waitWhileLoading(sal_uInt32 nTimeout = 0)
384 throw(LoadEnvException, css::uno::RuntimeException);
386 //_______________________________________
387 /** TODO document me ... */
388 virtual void cancelLoading()
389 throw(LoadEnvException, css::uno::RuntimeException);
391 //_______________________________________
392 /** TODO document me ... */
393 virtual css::uno::Reference< css::frame::XFrame > getTarget() const;
395 //_______________________________________
396 /** TODO document me ... */
397 virtual css::uno::Reference< css::lang::XComponent > getTargetComponent() const;
399 //___________________________________________
400 // helper uno interface!
401 // You have to use the native interface only!
403 public:
405 //_______________________________________
406 // frame.XLoadEventListener
407 virtual void SAL_CALL loadFinished(const css::uno::Reference< css::frame::XFrameLoader >& xLoader)
408 throw(css::uno::RuntimeException);
410 virtual void SAL_CALL loadCancelled(const css::uno::Reference< css::frame::XFrameLoader >& xLoader)
411 throw(css::uno::RuntimeException);
413 //_______________________________________
414 // frame.XDispatchResultListener
415 virtual void SAL_CALL dispatchFinished(const css::frame::DispatchResultEvent& aEvent)
416 throw(css::uno::RuntimeException);
418 //_______________________________________
419 // lang.XEventListener
420 virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent)
421 throw(css::uno::RuntimeException);
423 //___________________________________________
424 // static interface
426 public:
428 /** @short checks if the specified content can be handled by a
429 ContentHandler only and is not related to a target frame,
430 or if it can be loaded by a FrameLoader into a target frame
431 as "visible" component.
433 @descr using:
434 switch(classifyContent(...))
436 case E_CAN_BE_HANDLED :
437 handleIt(...);
438 break;
440 case E_CAN_BE_LOADED :
441 xFrame = locateTargetFrame();
442 loadIt(xFrame);
443 break;
445 case E_NOT_A_CONTENT :
446 default : throw ...;
449 @param sURL
450 describe the content.
452 @param lMediaDescriptor
453 describe the content more detailed!
455 @return A suitable enum value, which classify the specified content.
457 static EContentType classifyContent(const ::rtl::OUString& sURL ,
458 const css::uno::Sequence< css::beans::PropertyValue >& lMediaDescriptor);
460 /** TODO document me ... */
461 void impl_setResult(sal_Bool bResult);
463 /** TODO document me ... */
464 css::uno::Reference< css::uno::XInterface > impl_searchLoader();
466 //_______________________________________
468 /** @short it means; show the frame, bring it to front,
469 might set the right icon etcpp. in case loading was
470 successfully or reactivate a might existing old document or
471 close the frame if it was created before in case loading failed.
473 @throw A LoadEnvException only in cases, where an internal error indicates,
474 that the complete load environment seems to be not useable in general.
475 In such cases a RuntimeException would be to hard for the outside code :-)
477 @throw A RuntimeException in case any internal process indicates, that
478 the whole runtime cant be used any longer.
480 void impl_reactForLoadingState()
481 throw(LoadEnvException, css::uno::RuntimeException);
483 //___________________________________________
484 // private helper
486 private:
488 /** @short tries to detect the type and the filter of the specified content.
490 @descr This method actualize the available media descriptor of this instance,
491 so it contains the right type, a corresponding filter, may a
492 valid frame loader etc. In case detection failed, this descriptor
493 is corrected first, before a suitable exception will be thrown.
494 (Excepting a RuntimeException occure!)
496 @attention Not all types we know, are supported by filters. So it does not
497 indicates an error, if no suitable filter(loader etcpp will be found
498 for a type. But a type must be detected for the specified content.
499 Otherwhise its an error and loading cant be finished successfully.
501 @throw A LoadEnvException if detection failed.
503 @throw A RuntimeException in case any internal process indicates, that
504 the whole runtime cant be used any longer.
506 void impl_detectTypeAndFilter()
507 throw(LoadEnvException, css::uno::RuntimeException);
509 //_______________________________________
511 /** @short tries to ask user for it's filter decision in case
512 normal detection failed.
514 @descr We use a may existing interaction handler to do so.
516 @return [string]
517 the type selected by the user.
519 @attention Internaly we update the member m_lMediaDescriptor!
521 ::rtl::OUString impl_askUserForTypeAndFilterIfAllowed()
522 throw(LoadEnvException, css::uno::RuntimeException);
524 //_______________________________________
526 /** @short tries to use ContentHandler objects for loading.
528 @descr It searches for a suitable content handler object, registered
529 for the detected content type (must be done before by calling
530 impl_detectTypeAndFilter()). Because such handler does not depend
531 from a real target frame, location of such frame will be
532 supressed here.
533 In case handle failed all new created resources will be
534 removed before a suitable exception is thrown.
535 (Excepting a RuntimeException occure!)
537 @return TODO
539 @throw A LoadEnvException if handling failed.
541 @throw A RuntimeException in case any internal process indicates, that
542 the whole runtime cant be used any longer.
544 sal_Bool impl_handleContent()
545 throw(LoadEnvException, css::uno::RuntimeException);
547 //_______________________________________
549 /** @short tries to use FrameLoader objects for loading.
551 @descr First the target frame will be located. If it could be found
552 or new created a filter/frame loader will be instanciated and
553 used to load the content into this frame.
554 In case loading failed all new created resources will be
555 removed before a suitable exception is thrown.
556 (Excepting a RuntimeException occure!)
558 @return TODO
560 @throw A LoadEnvException if loading failed.
562 @throw A RuntimeException in case any internal process indicates, that
563 the whole runtime cant be used any longer.
565 sal_Bool impl_loadContent()
566 throw(LoadEnvException, css::uno::RuntimeException);
568 //_______________________________________
570 /** @short checks if the specified content is already loaded.
572 @descr It depends from the set target information, if such
573 search is allowed or not! So this method checks first,
574 if the target is the special one "_default".
575 If not it returns with an empty result immidatly!
576 In case search is allowed, an existing document with the
577 same URL is searched. If it could be found, the corresponding
578 view will get the focus and this method return the corresponding frame.
579 Optional jumpmarks will be accepted here too. So the
580 view of the document will be updated to show the position
581 inside the document, which is related to the jumpmark.
583 @return A valid reference to the target frame, which contains the already loaded content
584 and could be activated successfully. An empty reference oterwhise.
586 @throw A LoadEnvException only in cases, where an internal error indicates,
587 that the complete load environment seems to be not useable in general.
588 In such cases a RuntimeException would be to hard for the outside code :-)
590 @throw A RuntimeException in case any internal process indicates, that
591 the whole runtime cant be used any longer.
593 css::uno::Reference< css::frame::XFrame > impl_searchAlreadyLoaded()
594 throw(LoadEnvException, css::uno::RuntimeException);
596 //_______________________________________
598 /** @short search for any target frame, which seems to be useable
599 for this load request.
601 @descr Because this special feature is bound to the target specifier "_default"
602 its checked inside first. If its not set => this method return an empty
603 reference. Otherwhise any currently existing frame will be analyzed, if
604 it can be used here. The following rules exists:
606 <ul>
607 <li>The frame must be empty ...</li>
608 <li>or contains an empty document of the same application module
609 which the new document will have (Note: the filter of the new content
610 must be well known here!)</li>
611 <li>and(!) this target must not be already used by any other load request.</li>
612 </ul>
614 If a suitable target is located it will be locked. Thats why the last rule
615 exists! If this method returns a valid frame reference, it was locked to be useable
616 for this load request only. (Dont forget to reset this state later!)
617 Concurrent LoadEnv instances can synchronize her work be using such locks :-) HOPEFULLY
619 @throw A LoadEnvException only in cases, where an internal error indicates,
620 that the complete load environment seems to be not useable in general.
621 In such cases a RuntimeException would be to hard for the outside code :-)
623 @throw A RuntimeException in case any internal process indicates, that
624 the whole runtime cant be used any longer.
626 css::uno::Reference< css::frame::XFrame > impl_searchRecycleTarget()
627 throw(LoadEnvException, css::uno::RuntimeException);
629 //_______________________________________
631 /** @short because showing of a frame is needed more then once ...
632 it's implemented as an seperate method .-)
634 @descr Note: Showing of a frame is bound to a special feature ...
635 a) If we recycle any existing frame, we must bring it to front.
636 Showing of such frame isnt needed realy .. because we recycle
637 visible frames only!
638 b) If the document was already shown (e.g. by our progress implementation)
639 we do nothing here. The reason behind: The document was already shown ..
640 and it was already make a top window ...
641 If the user activated another frame inbetween (because loading needed some time)
642 it's not allowed to disturb the user again. Then the frame must resists in the background.
643 c) If the frame was not shown before ... but loading of a visible document into this frame
644 was finished ... we need both actions: setVisible() and toFront().
646 @param xWindow
647 points to the container window of a frame.
649 @param bForceToFront
650 if it's set to FALSE ... showing of the window is done more intelligent.
651 setVisible() is called only if the window was not shown before.
652 This mode is needed by b) and c)
653 If it's set to TRUE ... both actions has to be done: setVisible(), toFront()!
654 This mode is needed by a)
656 void impl_makeFrameWindowVisible(const css::uno::Reference< css::awt::XWindow >& xWindow ,
657 sal_Bool bForceToFront);
659 //_______________________________________
661 /** @short checks weather a frame is already used for another load request or not.
663 @descr Such frames cant be used for our "recycle feature"!
665 @param xFrame
666 the frame, which should be checked.
668 @return [sal_Bool]
669 TRUE if this frame is already used for loading,
670 FALSE otherwise.
672 sal_Bool impl_isFrameAlreadyUsedForLoading(const css::uno::Reference< css::frame::XFrame >& xFrame) const;
674 //_______________________________________
676 /** @short try to determine the used application module
677 of this load request and applay right position and size
678 for this document window ... hopefully before we show it .-)
680 void impl_applyPersistentWindowState(const css::uno::Reference< css::awt::XWindow >& xWindow);
682 //_______________________________________
684 /** @short determine if it's allowed to open new document frames.
686 sal_Bool impl_furtherDocsAllowed();
688 //_______________________________________
690 /** @short jumps to the requested bookmark inside a given document.
692 void impl_jumpToMark(const css::uno::Reference< css::frame::XFrame >& xFrame,
693 const css::util::URL& aURL );
696 } // namespace framework
698 #endif // __FRAMEWORK_LOADENV_LOADENV_HXX_