1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 #ifndef __FRAMEWORK_DISPATCH_STARTMODULEDISPATCHER_HXX_
29 #define __FRAMEWORK_DISPATCH_STARTMODULEDISPATCHER_HXX_
30 
31 //_______________________________________________
32 // my own includes
33 
34 #include <threadhelp/threadhelpbase.hxx>
35 #include <macros/xinterface.hxx>
36 #include <macros/xtypeprovider.hxx>
37 #include <macros/debug.hxx>
38 #include <macros/generic.hxx>
39 #include <stdtypes.h>
40 #include <general.h>
41 
42 //_______________________________________________
43 // interface includes
44 #include <com/sun/star/lang/XTypeProvider.hpp>
45 #include <com/sun/star/frame/XFrame.hpp>
46 #include <com/sun/star/frame/XStatusListener.hpp>
47 #include <com/sun/star/frame/XNotifyingDispatch.hpp>
48 #include <com/sun/star/frame/XDispatchInformationProvider.hpp>
49 #include <com/sun/star/util/URL.hpp>
50 #include <com/sun/star/frame/XDispatchResultListener.hpp>
51 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
52 #include <com/sun/star/frame/DispatchResultState.hpp>
53 
54 //_______________________________________________
55 // other includes
56 #include <cppuhelper/weak.hxx>
57 #include <vcl/evntpost.hxx>
58 
59 //_______________________________________________
60 // namespace
61 
62 namespace framework{
63 
64 //-----------------------------------------------
65 /**
66     @short          helper to handle all URLs related to the StartModule
67  */
68 class StartModuleDispatcher : public css::lang::XTypeProvider
69                             , public css::frame::XNotifyingDispatch             // => XDispatch
70                             , public css::frame::XDispatchInformationProvider
71                             // baseclasses ... order is neccessary for right initialization!
72                             , private ThreadHelpBase
73                             , public  ::cppu::OWeakObject
74 {
75     //-------------------------------------------
76     // member
77 
78     private:
79 
80         //---------------------------------------
81         /** @short reference to an uno service manager,
82                    which can be used to create own needed
83                    uno resources. */
84         css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR;
85 
86         //---------------------------------------
87         /** @short  our "context" frame. */
88         css::uno::WeakReference< css::frame::XFrame > m_xOwner;
89 
90         //---------------------------------------
91         /** @short  the original queryDispatch() target. */
92         ::rtl::OUString m_sDispatchTarget;
93 
94         //---------------------------------------
95         /** @short  list of registered status listener */
96         ListenerHash m_lStatusListener;
97 
98     //-------------------------------------------
99     // native interface
100 
101 	public:
102 
103         //---------------------------------------
104         /** @short  connect a new StartModuleDispatcher instance to its "owner frame".
105 
106             @descr  Such "owner frame" is used as context for all related operations.
107 
108             @param  xSMGR
109                     an uno service manager, which is needed to create uno resource
110                     internaly.
111 
112             @param  xFrame
113                     the frame where the corresponding dispatch was started.
114 
115             @param  sTarget
116                     the original target information used for the related queryDispatch() call.
117          */
118         StartModuleDispatcher(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR  ,
119                               const css::uno::Reference< css::frame::XFrame >&              xFrame ,
120                               const ::rtl::OUString&                                        sTarget);
121 
122         //---------------------------------------
123         /** @short  does nothing real. */
124         virtual ~StartModuleDispatcher();
125 
126     //-------------------------------------------
127     // uno interface
128 
129     public:
130 
131         //---------------------------------------
132         FWK_DECLARE_XINTERFACE
133         FWK_DECLARE_XTYPEPROVIDER
134 
135         //---------------------------------------
136         // XNotifyingDispatch
137         virtual void SAL_CALL dispatchWithNotification( const css::util::URL&                                             aURL      ,
138                                                         const css::uno::Sequence< css::beans::PropertyValue >&            lArguments,
139                                                         const css::uno::Reference< css::frame::XDispatchResultListener >& xListener ) throw(css::uno::RuntimeException);
140 
141         //---------------------------------------
142         // XDispatch
143         virtual void SAL_CALL dispatch            ( const css::util::URL&                                     aURL      ,
144                                                     const css::uno::Sequence< css::beans::PropertyValue >&    lArguments) throw(css::uno::RuntimeException);
145         virtual void SAL_CALL addStatusListener   ( const css::uno::Reference< css::frame::XStatusListener >& xListener ,
146                                                     const css::util::URL&                                     aURL      ) throw(css::uno::RuntimeException);
147         virtual void SAL_CALL removeStatusListener( const css::uno::Reference< css::frame::XStatusListener >& xListener ,
148                                                     const css::util::URL&                                     aURL      ) throw(css::uno::RuntimeException);
149 
150         //---------------------------------------
151         // XDispatchInformationProvider
152         virtual css::uno::Sequence< sal_Int16 >                       SAL_CALL getSupportedCommandGroups         (                         ) throw (css::uno::RuntimeException);
153         virtual css::uno::Sequence< css::frame::DispatchInformation > SAL_CALL getConfigurableDispatchInformation( sal_Int16 nCommandGroup ) throw (css::uno::RuntimeException);
154 
155     //-------------------------------------------
156     // internal helper
157 
158     private:
159 
160         //---------------------------------------
161         /** @short  check if StartModule can be shown.
162          */
163         ::sal_Bool implts_isBackingModePossible();
164 
165         //---------------------------------------
166         /** @short  open the special BackingComponent (now StartModule)
167 
168             @return [bool]
169                     sal_True if operation was successfully.
170          */
171         ::sal_Bool implts_establishBackingMode();
172 
173         //---------------------------------------
174         /** @short  notify a DispatchResultListener.
175 
176             @descr  We check the listener reference before we use it.
177                     So this method can be called everytimes!
178 
179             @parama xListener
180                     the listener, which should be notified.
181                     Can be null!
182 
183             @param  nState
184                     directly used as css::frame::DispatchResultState value.
185 
186             @param  aResult
187                     not used yet realy ...
188          */
189         void implts_notifyResultListener(const css::uno::Reference< css::frame::XDispatchResultListener >& xListener,
190                                                sal_Int16                                                   nState   ,
191                                          const css::uno::Any&                                              aResult  );
192 
193 }; // class StartModuleDispatcher
194 
195 } // namespace framework
196 
197 #endif // #ifndef __FRAMEWORK_DISPATCH_STARTMODULEDISPATCHER_HXX_
198