xref: /AOO41X/main/sfx2/inc/sfx2/sfxbasecontroller.hxx (revision 353d8f4d17010cd2d0ea815067cad67e477f2bee)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SFX_SFXBASECONTROLLER_HXX_
25 #define _SFX_SFXBASECONTROLLER_HXX_
26 
27 #include "sal/config.h"
28 #include "sfx2/dllapi.h"
29 #include "sal/types.h"
30 #include <com/sun/star/frame/XDispatch.hpp>
31 #include <com/sun/star/frame/XDispatchProvider.hpp>
32 #include <com/sun/star/frame/DispatchDescriptor.hpp>
33 #include <com/sun/star/frame/XDispatchInformationProvider.hpp>
34 #include <com/sun/star/frame/XController2.hpp>
35 #include <com/sun/star/frame/XControllerBorder.hpp>
36 #include <com/sun/star/frame/XModel.hpp>
37 #include <com/sun/star/frame/XFrame.hpp>
38 #include <com/sun/star/frame/XTitle.hpp>
39 #include <com/sun/star/frame/XTitleChangeBroadcaster.hpp>
40 #include <com/sun/star/util/URL.hpp>
41 #include <com/sun/star/lang/XTypeProvider.hpp>
42 #include <cppuhelper/implbase9.hxx>
43 #include <cppuhelper/basemutex.hxx>
44 #include <osl/mutex.hxx>
45 #include <com/sun/star/task/XStatusIndicatorSupplier.hpp>
46 #include <com/sun/star/ui/XContextMenuInterception.hpp>
47 #include <com/sun/star/ui/XContextMenuInterceptor.hpp>
48 #include <com/sun/star/awt/XMouseClickHandler.hpp>
49 #include <com/sun/star/awt/XKeyHandler.hpp>
50 #include <com/sun/star/awt/XUserInputInterception.hpp>
51 
52 //________________________________________________________________________________________________________
53 //  include of my own project
54 //________________________________________________________________________________________________________
55 #include <sfx2/viewsh.hxx>
56 #include <sfx2/sfxuno.hxx>
57 
58 //________________________________________________________________________________________________________
59 //  defines
60 //________________________________________________________________________________________________________
61 
62 // Some defines to write better code :-)
63 #define REFERENCE               ::com::sun::star::uno::Reference
64 #define ANY                     ::com::sun::star::uno::Any
65 #define XDISPATCH               ::com::sun::star::frame::XDispatch
66 #define DISPATCHDESCRIPTOR      ::com::sun::star::frame::DispatchDescriptor
67 #define XMODEL                  ::com::sun::star::frame::XModel
68 #define XFRAME                  ::com::sun::star::frame::XFrame
69 #define XEVENTLISTENER          ::com::sun::star::lang::XEventListener
70 #define MUTEX                   ::osl::Mutex
71 #define RUNTIMEEXCEPTION        ::com::sun::star::uno::RuntimeException
72 #define UNOTYPE                 ::com::sun::star::uno::Type
73 #define UNOURL                  ::com::sun::star::util::URL
74 #define OUSTRING                ::rtl::OUString
75 #define XCONTEXTMENUINTERCEPTOR ::com::sun::star::ui::XContextMenuInterceptor
76 
77 //________________________________________________________________________________________________________
78 //  forwards
79 //________________________________________________________________________________________________________
80 
81 struct  IMPL_SfxBaseController_DataContainer    ;   // impl. struct to hold member of class SfxBaseController
82 
83 class SfxViewFrame;
84 
85 sal_Int16 MapGroupIDToCommandGroup( sal_Int16 nGroupID );
86 sal_Bool SupportsCommandGroup( sal_Int16 nCommandGroup );
87 sal_Int16 MapCommandGroupToGroupID( sal_Int16 nCommandGroup );
88 
89 //________________________________________________________________________________________________________
90 //  class declarations
91 //________________________________________________________________________________________________________
92 
93 typedef ::cppu::WeakImplHelper9 <   ::com::sun::star::frame::XController2
94                                 ,   ::com::sun::star::frame::XControllerBorder
95                                 ,   ::com::sun::star::frame::XDispatchProvider
96                                 ,   ::com::sun::star::task::XStatusIndicatorSupplier
97                                 ,   ::com::sun::star::ui::XContextMenuInterception
98                                 ,   ::com::sun::star::awt::XUserInputInterception
99                                 ,   ::com::sun::star::frame::XDispatchInformationProvider
100                                 ,   ::com::sun::star::frame::XTitle
101                                 ,   ::com::sun::star::frame::XTitleChangeBroadcaster
102                                 >   SfxBaseController_Base;
103 
104 class SFX2_DLLPUBLIC SfxBaseController  :public SfxBaseController_Base
105                                         ,public ::cppu::BaseMutex
106 {
107 //________________________________________________________________________________________________________
108 //  public methods
109 //________________________________________________________________________________________________________
110 
111 public:
112 
113     //____________________________________________________________________________________________________
114     //  constructor/destructor
115     //____________________________________________________________________________________________________
116 
117     /**___________________________________________________________________________________________________
118         @short      -
119         @descr      -
120 
121         @seealso    -
122 
123         @param      -
124 
125         @return     -
126 
127         @onerror    -
128     */
129 
130     SfxBaseController( SfxViewShell* pView ) ;
131 
132     /**___________________________________________________________________________________________________
133         @short      -
134         @descr      -
135 
136         @seealso    -
137 
138         @param      -
139 
140         @return     -
141 
142         @onerror    -
143     */
144 
145     ~SfxBaseController() ;
146 
147     SAL_DLLPRIVATE void ReleaseShell_Impl();
148     SAL_DLLPRIVATE void BorderWidthsChanged_Impl();
149 
150     ::com::sun::star::uno::Reference< ::com::sun::star::task::XStatusIndicator > SAL_CALL getStatusIndicator(  ) throw (::com::sun::star::uno::RuntimeException);
151 
152     //____________________________________________________________________________________________________
153     //  XController2
154     //____________________________________________________________________________________________________
155     virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL getComponentWindow() throw (::com::sun::star::uno::RuntimeException);
156     virtual ::rtl::OUString SAL_CALL getViewControllerName() throw (::com::sun::star::uno::RuntimeException);
157     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getCreationArguments() throw (::com::sun::star::uno::RuntimeException);
158 
159     //____________________________________________________________________________________________________
160     //  XController
161     //____________________________________________________________________________________________________
162 
163     /**___________________________________________________________________________________________________
164         @short      -
165         @descr      -
166 
167         @seealso    -
168 
169         @param      -
170 
171         @return     -
172 
173         @onerror    -
174     */
175 
176     virtual void SAL_CALL attachFrame( const REFERENCE< XFRAME >& xFrame ) throw( RUNTIMEEXCEPTION ) ;
177 
178     /**___________________________________________________________________________________________________
179         @short      -
180         @descr      -
181 
182         @seealso    -
183 
184         @param      -
185 
186         @return     -
187 
188         @onerror    -
189     */
190 
191     virtual sal_Bool SAL_CALL attachModel( const REFERENCE< XMODEL >& xModel ) throw( RUNTIMEEXCEPTION ) ;
192 
193     /**___________________________________________________________________________________________________
194         @short      -
195         @descr      -
196 
197         @seealso    -
198 
199         @param      -
200 
201         @return     -
202 
203         @onerror    -
204     */
205 
206     virtual sal_Bool SAL_CALL suspend( sal_Bool bSuspend ) throw( RUNTIMEEXCEPTION ) ;
207 
208     /**___________________________________________________________________________________________________
209         @short      -
210         @descr      -
211 
212         @seealso    -
213 
214         @param      -
215 
216         @return     -
217 
218         @onerror    -
219     */
220 
221     ANY SAL_CALL getViewData() throw( RUNTIMEEXCEPTION ) ;
222 
223     /**___________________________________________________________________________________________________
224         @short      -
225         @descr      -
226 
227         @seealso    -
228 
229         @param      -
230 
231         @return     -
232 
233         @onerror    -
234     */
235 
236     void SAL_CALL restoreViewData( const ANY& aValue ) throw( RUNTIMEEXCEPTION ) ;
237 
238     /**___________________________________________________________________________________________________
239         @short      -
240         @descr      -
241 
242         @seealso    -
243 
244         @param      -
245 
246         @return     -
247 
248         @onerror    -
249     */
250 
251     REFERENCE< XFRAME > SAL_CALL getFrame() throw( RUNTIMEEXCEPTION ) ;
252 
253     /**___________________________________________________________________________________________________
254         @short      -
255         @descr      -
256 
257         @seealso    -
258 
259         @param      -
260 
261         @return     -
262 
263         @onerror    -
264     */
265 
266     REFERENCE< XMODEL > SAL_CALL getModel() throw( RUNTIMEEXCEPTION ) ;
267 
268     //____________________________________________________________________________________________________
269     //  XDispatchProvider
270     //____________________________________________________________________________________________________
271 
272     /**___________________________________________________________________________________________________
273         @short      -
274         @descr      -
275 
276         @seealso    -
277 
278         @param      -
279 
280         @return     -
281 
282         @onerror    -
283     */
284 
285     virtual REFERENCE< XDISPATCH > SAL_CALL queryDispatch(  const   UNOURL &            aURL            ,
286                                                             const   OUSTRING &          sTargetFrameName,
287                                                                     FrameSearchFlags    eSearchFlags    ) throw( RUNTIMEEXCEPTION ) ;
288 
289     /**___________________________________________________________________________________________________
290         @short      -
291         @descr      -
292 
293         @seealso    -
294 
295         @param      -
296 
297         @return     -
298 
299         @onerror    -
300     */
301 
302     virtual ::com::sun::star::uno::Sequence< REFERENCE< XDISPATCH > > SAL_CALL queryDispatches( const ::com::sun::star::uno::Sequence< DISPATCHDESCRIPTOR >& seqDescriptor ) throw( RUNTIMEEXCEPTION ) ;
303 
304     //____________________________________________________________________________________________________
305     //  XControllerBorder
306     //____________________________________________________________________________________________________
307 
308     virtual ::com::sun::star::frame::BorderWidths SAL_CALL getBorder() throw (::com::sun::star::uno::RuntimeException);
309     virtual void SAL_CALL addBorderResizeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XBorderResizeListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
310     virtual void SAL_CALL removeBorderResizeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XBorderResizeListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
311     virtual ::com::sun::star::awt::Rectangle SAL_CALL queryBorderedArea( const ::com::sun::star::awt::Rectangle& aPreliminaryRectangle ) throw (::com::sun::star::uno::RuntimeException);
312 
313     //____________________________________________________________________________________________________
314     //  XComponent
315     //____________________________________________________________________________________________________
316 
317     /**___________________________________________________________________________________________________
318         @short      -
319         @descr      -
320 
321         @seealso    -
322 
323         @param      -
324 
325         @return     -
326 
327         @onerror    -
328     */
329 
330     virtual void SAL_CALL dispose() throw( RUNTIMEEXCEPTION ) ;
331 
332     /**___________________________________________________________________________________________________
333         @short      -
334         @descr      -
335 
336         @seealso    -
337 
338         @param      -
339 
340         @return     -
341 
342         @onerror    -
343     */
344 
345     virtual void SAL_CALL addEventListener( const REFERENCE< XEVENTLISTENER >& aListener ) throw( RUNTIMEEXCEPTION ) ;
346 
347     /**___________________________________________________________________________________________________
348         @short      -
349         @descr      -
350 
351         @seealso    -
352 
353         @param      -
354 
355         @return     -
356 
357         @onerror    -
358     */
359 
360     virtual void SAL_CALL removeEventListener( const REFERENCE< XEVENTLISTENER >& aListener ) throw( RUNTIMEEXCEPTION ) ;
361     virtual void SAL_CALL registerContextMenuInterceptor( const REFERENCE< XCONTEXTMENUINTERCEPTOR >& xInterceptor ) throw( RUNTIMEEXCEPTION );
362     virtual void SAL_CALL releaseContextMenuInterceptor( const REFERENCE< XCONTEXTMENUINTERCEPTOR >& xInterceptor ) throw( RUNTIMEEXCEPTION );
363 
364     virtual void SAL_CALL addKeyHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XKeyHandler >& xHandler ) throw (::com::sun::star::uno::RuntimeException);
365     virtual void SAL_CALL removeKeyHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XKeyHandler >& xHandler ) throw (::com::sun::star::uno::RuntimeException);
366     virtual void SAL_CALL addMouseClickHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseClickHandler >& xHandler ) throw (::com::sun::star::uno::RuntimeException);
367     virtual void SAL_CALL removeMouseClickHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseClickHandler >& xHandler ) throw (::com::sun::star::uno::RuntimeException);
368 
369     //____________________________________________________________________________________________________
370     //  XDispatchInformationProvider
371     //____________________________________________________________________________________________________
372     virtual ::com::sun::star::uno::Sequence< sal_Int16 > SAL_CALL getSupportedCommandGroups() throw (::com::sun::star::uno::RuntimeException);
373     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::frame::DispatchInformation > SAL_CALL getConfigurableDispatchInformation( sal_Int16 nCommandGroup ) throw (::com::sun::star::uno::RuntimeException);
374 
375     // css::frame::XTitle
376     virtual ::rtl::OUString SAL_CALL getTitle(  ) throw (::com::sun::star::uno::RuntimeException);
377     virtual void SAL_CALL setTitle( const ::rtl::OUString& sTitle ) throw (::com::sun::star::uno::RuntimeException);
378 
379     // css::frame::XTitleChangeBroadcaster
380     virtual void SAL_CALL addTitleChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XTitleChangeListener >& xListener )     throw (::com::sun::star::uno::RuntimeException);
381     virtual void SAL_CALL removeTitleChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XTitleChangeListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
382 
383 //#if 0 // _SOLAR__PRIVATE
384     // FIXME: TL needs this in sw/source/ui/uno/unotxdoc.cxx now;
385     // either the _Impl name should vanish or there should be an "official" API
386     SfxViewShell* GetViewShell_Impl() const;
387     SAL_DLLPRIVATE sal_Bool HandleEvent_Impl( NotifyEvent& rEvent );
388     SAL_DLLPRIVATE sal_Bool HasKeyListeners_Impl();
389     SAL_DLLPRIVATE sal_Bool HasMouseClickListeners_Impl();
390     SAL_DLLPRIVATE void SetCreationArguments_Impl( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_rCreationArgs );
391     SAL_DLLPRIVATE ::com::sun::star::uno::Reference< ::com::sun::star::frame::XTitle > impl_getTitleHelper ();
392 //#endif
393 private:
394     enum ConnectSfxFrame
395     {
396         E_CONNECT,
397         E_DISCONNECT,
398         E_RECONNECT
399     };
400     SAL_DLLPRIVATE void ConnectSfxFrame_Impl( const ConnectSfxFrame i_eConnect );
401     SAL_DLLPRIVATE SfxViewFrame& GetViewFrame_Impl() const;
402 
403 //________________________________________________________________________________________________________
404 //  private variables
405 //________________________________________________________________________________________________________
406 
407 private:
408 
409     IMPL_SfxBaseController_DataContainer*   m_pData ;
410 
411 } ; // class SfxBaseController
412 
413 #endif  // _SFX_SFXBASECONTROLLER_HXX
414