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 _SVTOOLS_STATUSBARCONTROLLER_HXX
25 #define _SVTOOLS_STATUSBARCONTROLLER_HXX
26 
27 #include "svtools/svtdllapi.h"
28 #include <com/sun/star/ui/XStatusbarItem.hpp>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 #include <com/sun/star/frame/XFrame.hpp>
31 #include <com/sun/star/frame/XDispatch.hpp>
32 #include <com/sun/star/frame/XStatusbarController.hpp>
33 #include <com/sun/star/util/XURLTransformer.hpp>
34 #include <com/sun/star/frame/XLayoutManager.hpp>
35 #include <cppuhelper/weak.hxx>
36 #include <cppuhelper/interfacecontainer.hxx>
37 #include <comphelper/broadcasthelper.hxx>
38 
39 #ifndef INCLUDED_HASH_MAP
40 #include <hash_map>
41 #define INCLUDED_HASH_MAP
42 #endif
43 
44 #include <tools/gen.hxx>
45 
46 namespace svt
47 {
48 
49 class SVT_DLLPUBLIC StatusbarController :
50                             public ::com::sun::star::frame::XStatusbarController,
51                             public ::comphelper::OBaseMutex,
52                             public ::cppu::OWeakObject
53 {
54     public:
55         StatusbarController( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rServiceManager,
56                              const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame,
57                              const rtl::OUString& aCommandURL,
58                              unsigned short       nID );
59         StatusbarController();
60         virtual ~StatusbarController();
61 
62         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > getFrameInterface() const;
63         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > getServiceManager() const;
64         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > getLayoutManager() const;
65         ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer > getURLTransformer() const;
66 
67         void updateStatus( const rtl::OUString aCommandURL );
68         void updateStatus();
69 
70         ::Rectangle getControlRect() const;
71 
72         // XInterface
73 		virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw (::com::sun::star::uno::RuntimeException);
74 		virtual void SAL_CALL acquire() throw ();
75 		virtual void SAL_CALL release() throw ();
76 
77         // XInitialization
78         virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
79 
80         // XUpdatable
81         virtual void SAL_CALL update() throw (::com::sun::star::uno::RuntimeException);
82 
83         // XComponent
84         virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException);
85         virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
86         virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
87 
88         // XEventListener
89 		virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& Source ) throw ( ::com::sun::star::uno::RuntimeException );
90 
91         // XStatusListener
92 		virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException );
93 
94         // XStatusbarController
95         virtual ::sal_Bool SAL_CALL mouseButtonDown( const ::com::sun::star::awt::MouseEvent& aMouseEvent ) throw (::com::sun::star::uno::RuntimeException);
96         virtual ::sal_Bool SAL_CALL mouseMove( const ::com::sun::star::awt::MouseEvent& aMouseEvent ) throw (::com::sun::star::uno::RuntimeException);
97         virtual ::sal_Bool SAL_CALL mouseButtonUp( const ::com::sun::star::awt::MouseEvent& aMouseEvent ) throw (::com::sun::star::uno::RuntimeException);
98         virtual void SAL_CALL command( const ::com::sun::star::awt::Point& aPos,
99                                        ::sal_Int32 nCommand,
100                                        ::sal_Bool bMouseEvent,
101                                        const ::com::sun::star::uno::Any& aData ) throw (::com::sun::star::uno::RuntimeException);
102         virtual void SAL_CALL paint( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics >& xGraphics,
103                                      const ::com::sun::star::awt::Rectangle& rOutputRectangle,
104                                      ::sal_Int32 nStyle ) throw (::com::sun::star::uno::RuntimeException);
105         virtual void SAL_CALL click( const ::com::sun::star::awt::Point& aPos ) throw (::com::sun::star::uno::RuntimeException);
106         virtual void SAL_CALL doubleClick( const ::com::sun::star::awt::Point& aPos ) throw (::com::sun::star::uno::RuntimeException);
107 
108     protected:
109         struct Listener
110         {
Listenersvt::StatusbarController::Listener111             Listener( const ::com::sun::star::util::URL& rURL, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >& rDispatch ) :
112                 aURL( rURL ), xDispatch( rDispatch ) {}
113 
114             ::com::sun::star::util::URL aURL;
115             ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDispatch;
116         };
117 
118         typedef ::std::hash_map< ::rtl::OUString,
119 				                 com::sun::star::uno::Reference< com::sun::star::frame::XDispatch >,
120                                  ::rtl::OUStringHash,
121 								 ::std::equal_to< ::rtl::OUString > > URLToDispatchMap;
122 
123         // methods to support status forwarder, known by the old sfx2 toolbox controller implementation
124         void addStatusListener( const rtl::OUString& aCommandURL );
125         void removeStatusListener( const rtl::OUString& aCommandURL );
126         void bindListener();
127         void unbindListener();
128         sal_Bool isBound() const;
129 
130         // execute methods
131         // execute bound status bar controller command/execute various commands
132         void execute( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs );
133         void execute( const rtl::OUString& aCommand, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs );
134 
135         sal_Bool                                                                            m_bInitialized : 1,
136                                                                                             m_bDisposed : 1;
137         unsigned short                                                                      m_nID;
138         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >                 m_xFrame;
139         ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >                  m_xParentWindow;
140         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >    m_xServiceManager;
141         rtl::OUString                                                                       m_aCommandURL;
142         URLToDispatchMap                                                                    m_aListenerMap;
143         ::cppu::OMultiTypeInterfaceContainerHelper                                          m_aListenerContainer;   /// container for ALL Listener
144         mutable ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer > m_xURLTransformer;
145         ::com::sun::star::uno::Reference< ::com::sun::star::ui::XStatusbarItem >           m_xStatusbarItem;
146 };
147 
148 }
149 
150 #endif // _SVTOOLS_TOOLBOXCONTROLLER_HXX
151