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 _SVTOOLS_TOOLBOXCONTROLLER_HXX
21 : #define _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/weak.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 : class SVT_DLLPUBLIC ToolboxController : public ::com::sun::star::frame::XStatusListener,
50 : public ::com::sun::star::frame::XToolbarController,
51 : public ::com::sun::star::lang::XInitialization,
52 : public ::com::sun::star::util::XUpdatable,
53 : public ::com::sun::star::lang::XComponent,
54 : public ::comphelper::OMutexAndBroadcastHelper,//shizhoubo
55 : public ::comphelper::OPropertyContainer,//shizhoubo
56 : public ::comphelper::OPropertyArrayUsageHelper< ToolboxController >,//shizhoubo
57 : public ::cppu::OWeakObject
58 : {
59 : private:
60 : sal_Bool m_bSupportVisible; //shizhoubo
61 : public:
62 : ToolboxController( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& rxContext,
63 : const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame,
64 : const OUString& aCommandURL );
65 : ToolboxController();
66 : virtual ~ToolboxController();
67 :
68 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > getFrameInterface() const;
69 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& getContext() const;
70 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > getLayoutManager() const;
71 :
72 : void updateStatus( const OUString aCommandURL );
73 : void updateStatus();
74 :
75 : // XInterface
76 : virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw (::com::sun::star::uno::RuntimeException);
77 : virtual void SAL_CALL acquire() throw ();
78 : virtual void SAL_CALL release() throw ();
79 :
80 : // XInitialization
81 : 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);
82 :
83 : // XUpdatable
84 : virtual void SAL_CALL update() throw (::com::sun::star::uno::RuntimeException);
85 :
86 : // XComponent
87 : virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException);
88 : virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
89 : virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
90 :
91 : // XEventListener
92 : using cppu::OPropertySetHelper::disposing;
93 : virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& Source ) throw ( ::com::sun::star::uno::RuntimeException );
94 :
95 : // XStatusListener
96 : virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException ) = 0;
97 :
98 : // XToolbarController
99 : virtual void SAL_CALL execute( sal_Int16 KeyModifier ) throw (::com::sun::star::uno::RuntimeException);
100 : virtual void SAL_CALL click() throw (::com::sun::star::uno::RuntimeException);
101 : virtual void SAL_CALL doubleClick() throw (::com::sun::star::uno::RuntimeException);
102 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL createPopupWindow() throw (::com::sun::star::uno::RuntimeException);
103 : 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);
104 : // OPropertySetHelper //shizhoubo
105 : virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const com::sun::star::uno::Any& rValue ) throw(com::sun::star::uno::Exception);
106 : 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);
107 : // XPropertySet //shizhoubo
108 : virtual ::com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() throw(::com::sun::star::uno::RuntimeException);
109 : virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
110 : // OPropertyArrayUsageHelper //shizhoubo
111 : virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
112 :
113 :
114 0 : const OUString& getCommandURL() const { return m_aCommandURL; }
115 1381 : const OUString& getModuleName() const { return m_sModuleName; }
116 :
117 : void dispatchCommand( const OUString& sCommandURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rArgs, const OUString &rTarget = OUString() );
118 :
119 : void enable( bool bEnable );
120 :
121 : protected:
122 : bool getToolboxId( sal_uInt16& rItemId, ToolBox** ppToolBox );
123 : void setSupportVisibleProperty(sal_Bool bValue); //shizhoubo
124 144168 : struct Listener
125 : {
126 44086 : Listener( const ::com::sun::star::util::URL& rURL, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >& rDispatch ) :
127 44086 : aURL( rURL ), xDispatch( rDispatch ) {}
128 :
129 : ::com::sun::star::util::URL aURL;
130 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDispatch;
131 : };
132 :
133 0 : struct DispatchInfo
134 : {
135 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > mxDispatch;
136 : const ::com::sun::star::util::URL maURL;
137 : const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > maArgs;
138 :
139 0 : DispatchInfo( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >& xDispatch,
140 : const ::com::sun::star::util::URL& rURL,
141 : const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rArgs )
142 : : mxDispatch( xDispatch )
143 : , maURL( rURL )
144 0 : , maArgs( rArgs )
145 0 : {}
146 : };
147 :
148 : DECL_STATIC_LINK( ToolboxController, ExecuteHdl_Impl, DispatchInfo* );
149 :
150 : typedef ::boost::unordered_map< OUString,
151 : com::sun::star::uno::Reference< com::sun::star::frame::XDispatch >,
152 : OUStringHash,
153 : ::std::equal_to< OUString > > URLToDispatchMap;
154 :
155 : // methods to support status forwarder, known by the old sfx2 toolbox controller implementation
156 : void addStatusListener( const OUString& aCommandURL );
157 : void removeStatusListener( const OUString& aCommandURL );
158 : void bindListener();
159 : void unbindListener();
160 : sal_Bool isBound() const;
161 : sal_Bool hasBigImages() const;
162 : // TODO remove
163 : ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer > getURLTransformer() const;
164 : // TODO remove
165 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > getParent() const;
166 :
167 : sal_Bool m_bInitialized : 1,
168 : m_bDisposed : 1;
169 : sal_uInt16 m_nToolBoxId;
170 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > m_xFrame;
171 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
172 : OUString m_aCommandURL;
173 : URLToDispatchMap m_aListenerMap;
174 : ::cppu::OMultiTypeInterfaceContainerHelper m_aListenerContainer; /// container for ALL Listener
175 :
176 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > m_xParentWindow;
177 : ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer > m_xUrlTransformer;
178 : OUString m_sModuleName;
179 : };
180 :
181 : }
182 :
183 : #endif // _SVTOOLS_TOOLBOXCONTROLLER_HXX
184 :
185 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|