1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SVTOOLS_TOOLBOXCONTROLLER_HXX
21 #define INCLUDED_SVTOOLS_TOOLBOXCONTROLLER_HXX
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>
42 #include <unordered_map>
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
;
55 class SVT_DLLPUBLIC ToolboxController
:
56 public ToolboxController_Base
,
57 public ::comphelper::OMutexAndBroadcastHelper
,
58 public ::comphelper::OPropertyContainer
,
59 public ::comphelper::OPropertyArrayUsageHelper
< ToolboxController
>
62 bool m_bSupportVisible
;
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
);
68 virtual ~ToolboxController();
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;
74 void updateStatus( const OUString
& aCommandURL
);
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
;
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
;
88 virtual void SAL_CALL
update() throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
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
;
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
;
100 virtual void SAL_CALL
statusChanged( const ::com::sun::star::frame::FeatureStateEvent
& Event
) throw ( ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
= 0;
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
;
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
;
118 const OUString
& getCommandURL() const { return m_aCommandURL
; }
119 const OUString
& getModuleName() const { return m_sModuleName
; }
121 void dispatchCommand( const OUString
& sCommandURL
, const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& rArgs
, const OUString
&rTarget
= OUString() );
123 void enable( bool bEnable
);
126 bool getToolboxId( sal_uInt16
& rItemId
, ToolBox
** ppToolBox
);
127 void setSupportVisibleProperty(bool bValue
);
130 Listener( const ::com::sun::star::util::URL
& rURL
, const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDispatch
>& rDispatch
) :
131 aURL( rURL
), xDispatch( rDispatch
) {}
133 ::com::sun::star::util::URL aURL
;
134 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDispatch
> xDispatch
;
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
;
143 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
)
152 DECL_STATIC_LINK( ToolboxController
, ExecuteHdl_Impl
, DispatchInfo
* );
154 typedef std::unordered_map
< OUString
,
155 css::uno::Reference
< css::frame::XDispatch
>,
157 std::equal_to
< OUString
> > URLToDispatchMap
;
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
);
163 void unbindListener();
164 bool isBound() const;
166 ::com::sun::star::uno::Reference
< ::com::sun::star::util::XURLTransformer
> getURLTransformer() const { return m_xUrlTransformer
;}
168 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
> getParent() const { return m_xParentWindow
;}
170 bool m_bInitialized
: 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
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
;
186 #endif // INCLUDED_SVTOOLS_TOOLBOXCONTROLLER_HXX
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */