Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_SVTOOLS_TOOLBOXCONTROLLER_HXX
21 : #define INCLUDED_SVTOOLS_TOOLBOXCONTROLLER_HXX
22 :
23 : #include <svtools/svtdllapi.h>
24 : #include <com/sun/star/frame/XFrame.hpp>
25 : #include <com/sun/star/frame/XDispatch.hpp>
26 : #include <com/sun/star/frame/XStatusListener.hpp>
27 : #include <com/sun/star/frame/XToolbarController.hpp>
28 : #include <com/sun/star/frame/XLayoutManager.hpp>
29 : #include <com/sun/star/lang/XInitialization.hpp>
30 : #include <com/sun/star/uno/XComponentContext.hpp>
31 : #include <com/sun/star/util/XUpdatable.hpp>
32 : #include <com/sun/star/util/XURLTransformer.hpp>
33 : #include <cppuhelper/implbase5.hxx>
34 : #include <cppuhelper/interfacecontainer.hxx>
35 : #include <comphelper/broadcasthelper.hxx>
36 : #include <comphelper/proparrhlp.hxx>
37 : #include <comphelper/property.hxx>
38 : #include <comphelper/propertycontainer.hxx>
39 : #include <cppuhelper/propshlp.hxx>
40 : #include <tools/link.hxx>
41 :
42 : #include <boost/unordered_map.hpp>
43 :
44 : class ToolBox;
45 :
46 : namespace svt
47 : {
48 :
49 : typedef cppu::WeakImplHelper5<
50 : css::frame::XStatusListener, css::frame::XToolbarController,
51 : css::lang::XInitialization, css::util::XUpdatable,
52 : css::lang::XComponent >
53 : ToolboxController_Base;
54 :
55 : class SVT_DLLPUBLIC ToolboxController :
56 : public ToolboxController_Base,
57 : public ::comphelper::OMutexAndBroadcastHelper,
58 : public ::comphelper::OPropertyContainer,
59 : public ::comphelper::OPropertyArrayUsageHelper< ToolboxController >
60 : {
61 : private:
62 : bool m_bSupportVisible;
63 : public:
64 : ToolboxController( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& rxContext,
65 : const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame,
66 : const OUString& aCommandURL );
67 : ToolboxController();
68 : virtual ~ToolboxController();
69 :
70 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > getFrameInterface() const;
71 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& getContext() const;
72 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > getLayoutManager() const;
73 :
74 : void updateStatus( const OUString& aCommandURL );
75 : void updateStatus();
76 :
77 : // XInterface
78 : virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
79 : virtual void SAL_CALL acquire() throw () SAL_OVERRIDE;
80 : virtual void SAL_CALL release() throw () SAL_OVERRIDE;
81 : virtual css::uno::Sequence<css::uno::Type> SAL_CALL getTypes()
82 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
83 :
84 : // XInitialization
85 : 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, std::exception) SAL_OVERRIDE;
86 :
87 : // XUpdatable
88 : virtual void SAL_CALL update() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
89 :
90 : // XComponent
91 : virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
92 : virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
93 : virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
94 :
95 : // XEventListener
96 : using cppu::OPropertySetHelper::disposing;
97 : virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& Source ) throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
98 :
99 : // XStatusListener
100 : virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE = 0;
101 :
102 : // XToolbarController
103 : virtual void SAL_CALL execute( sal_Int16 KeyModifier ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
104 : virtual void SAL_CALL click() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
105 : virtual void SAL_CALL doubleClick() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
106 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL createPopupWindow() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
107 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL createItemWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& Parent ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
108 : // OPropertySetHelper
109 : virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const com::sun::star::uno::Any& rValue ) throw(com::sun::star::uno::Exception, std::exception) SAL_OVERRIDE;
110 : virtual sal_Bool SAL_CALL convertFastPropertyValue( com::sun::star::uno::Any& rConvertedValue, com::sun::star::uno::Any& rOldValue, sal_Int32 nHandle, const com::sun::star::uno::Any& rValue) throw(com::sun::star::lang::IllegalArgumentException) SAL_OVERRIDE;
111 : // XPropertySet
112 : virtual ::com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
113 : virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() SAL_OVERRIDE;
114 : // OPropertyArrayUsageHelper
115 : virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const SAL_OVERRIDE;
116 :
117 :
118 0 : const OUString& getCommandURL() const { return m_aCommandURL; }
119 0 : const OUString& getModuleName() const { return m_sModuleName; }
120 :
121 : void dispatchCommand( const OUString& sCommandURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rArgs, const OUString &rTarget = OUString() );
122 :
123 : void enable( bool bEnable );
124 :
125 : protected:
126 : bool getToolboxId( sal_uInt16& rItemId, ToolBox** ppToolBox );
127 : void setSupportVisibleProperty(bool bValue);
128 0 : struct Listener
129 : {
130 0 : Listener( const ::com::sun::star::util::URL& rURL, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >& rDispatch ) :
131 0 : aURL( rURL ), xDispatch( rDispatch ) {}
132 :
133 : ::com::sun::star::util::URL aURL;
134 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDispatch;
135 : };
136 :
137 0 : struct DispatchInfo
138 : {
139 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > mxDispatch;
140 : const ::com::sun::star::util::URL maURL;
141 : const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > maArgs;
142 :
143 0 : DispatchInfo( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >& xDispatch,
144 : const ::com::sun::star::util::URL& rURL,
145 : const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rArgs )
146 : : mxDispatch( xDispatch )
147 : , maURL( rURL )
148 0 : , maArgs( rArgs )
149 0 : {}
150 : };
151 :
152 : DECL_STATIC_LINK( ToolboxController, ExecuteHdl_Impl, DispatchInfo* );
153 :
154 : typedef ::boost::unordered_map< OUString,
155 : com::sun::star::uno::Reference< com::sun::star::frame::XDispatch >,
156 : OUStringHash,
157 : ::std::equal_to< OUString > > URLToDispatchMap;
158 :
159 : // methods to support status forwarder, known by the old sfx2 toolbox controller implementation
160 : void addStatusListener( const OUString& aCommandURL );
161 : void removeStatusListener( const OUString& aCommandURL );
162 : void bindListener();
163 : void unbindListener();
164 : bool isBound() const;
165 : // TODO remove
166 : ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer > getURLTransformer() const;
167 : // TODO remove
168 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > getParent() const;
169 :
170 : bool m_bInitialized : 1,
171 : m_bDisposed : 1;
172 : sal_uInt16 m_nToolBoxId;
173 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > m_xFrame;
174 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
175 : OUString m_aCommandURL;
176 : URLToDispatchMap m_aListenerMap;
177 : ::cppu::OMultiTypeInterfaceContainerHelper m_aListenerContainer; /// container for ALL Listener
178 :
179 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > m_xParentWindow;
180 : ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer > m_xUrlTransformer;
181 : OUString m_sModuleName;
182 : };
183 :
184 : }
185 :
186 : #endif // INCLUDED_SVTOOLS_TOOLBOXCONTROLLER_HXX
187 :
188 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|