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 : #ifndef INCLUDED_SFX2_UNOCTITM_HXX
20 : #define INCLUDED_SFX2_UNOCTITM_HXX
21 :
22 : #include <com/sun/star/frame/XNotifyingDispatch.hpp>
23 : #include <com/sun/star/frame/XDispatchResultListener.hpp>
24 : #include <com/sun/star/frame/XDispatchProviderInterceptor.hpp>
25 : #include <com/sun/star/frame/XDispatch.hpp>
26 : #include <com/sun/star/frame/XDispatchProvider.hpp>
27 : #include <com/sun/star/frame/XStatusListener.hpp>
28 : #include <com/sun/star/frame/FrameSearchFlag.hpp>
29 : #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
30 : #include <com/sun/star/frame/FeatureStateEvent.hpp>
31 : #include <com/sun/star/frame/DispatchDescriptor.hpp>
32 : #include <com/sun/star/util/XURLTransformer.hpp>
33 : #include <com/sun/star/lang/XUnoTunnel.hpp>
34 : #include <com/sun/star/frame/XFrame.hpp>
35 : #include <cppuhelper/implbase1.hxx>
36 : #include <cppuhelper/interfacecontainer.hxx>
37 :
38 : #include <sfx2/ctrlitem.hxx>
39 : #include <osl/mutex.hxx>
40 :
41 : class SfxBindings;
42 : class SfxFrame;
43 : class SfxDispatcher;
44 :
45 : class SfxUnoControllerItem : public ::cppu::WeakImplHelper1< css::frame::XStatusListener >
46 : {
47 : ::com::sun::star::util::URL aCommand;
48 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDispatch;
49 : SfxControllerItem* pCtrlItem;
50 : SfxBindings* pBindings;
51 :
52 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > TryGetDispatch( SfxFrame* pFrame );
53 :
54 : public:
55 :
56 : SfxUnoControllerItem( SfxControllerItem*, SfxBindings&, const OUString& );
57 : virtual ~SfxUnoControllerItem();
58 :
59 : const ::com::sun::star::util::URL& GetCommand() const
60 : { return aCommand; }
61 :
62 : // XStatusListener
63 : virtual void SAL_CALL statusChanged(const ::com::sun::star::frame::FeatureStateEvent& Event) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
64 :
65 : // Something else
66 : virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
67 : void UnBind();
68 : void GetNewDispatch();
69 : void ReleaseDispatch();
70 : void ReleaseBindings();
71 : };
72 :
73 : typedef cppu::OMultiTypeInterfaceContainerHelperVar<OUString>
74 : SfxStatusDispatcher_Impl_ListenerContainer;
75 :
76 80274 : class SfxStatusDispatcher : public ::cppu::WeakImplHelper1< css::frame::XNotifyingDispatch >
77 : {
78 : ::osl::Mutex aMutex;
79 : SfxStatusDispatcher_Impl_ListenerContainer aListeners;
80 :
81 : public:
82 :
83 : SfxStatusDispatcher();
84 :
85 : // XDispatch
86 : virtual void SAL_CALL dispatchWithNotification( const ::com::sun::star::util::URL& aURL,
87 : const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs,
88 : const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchResultListener >& rListener ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
89 : virtual void SAL_CALL dispatch( const ::com::sun::star::util::URL& aURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
90 : virtual void SAL_CALL addStatusListener(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xControl, const ::com::sun::star::util::URL& aURL) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
91 : virtual void SAL_CALL removeStatusListener(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xControl, const ::com::sun::star::util::URL& aURL) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
92 :
93 : // Something else
94 : void ReleaseAll();
95 142335 : SfxStatusDispatcher_Impl_ListenerContainer& GetListeners()
96 142335 : { return aListeners; }
97 : };
98 :
99 : class SfxSlotServer;
100 : class SfxDispatchController_Impl;
101 : class SfxOfficeDispatch : public ::cppu::ImplInheritanceHelper1< SfxStatusDispatcher, css::lang::XUnoTunnel >
102 : {
103 : friend class SfxDispatchController_Impl;
104 : SfxDispatchController_Impl* pControllerItem;
105 : public:
106 : SfxOfficeDispatch( SfxBindings& rBind,
107 : SfxDispatcher* pDispat,
108 : const SfxSlot* pSlot,
109 : const ::com::sun::star::util::URL& rURL );
110 : SfxOfficeDispatch( SfxDispatcher* pDispat,
111 : const SfxSlot* pSlot,
112 : const ::com::sun::star::util::URL& rURL );
113 : virtual ~SfxOfficeDispatch();
114 :
115 : virtual void SAL_CALL dispatchWithNotification( const ::com::sun::star::util::URL& aURL,
116 : const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs,
117 : const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchResultListener >& rListener )
118 : throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
119 : virtual void SAL_CALL dispatch( const ::com::sun::star::util::URL& aURL,
120 : const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs )
121 : throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
122 : virtual void SAL_CALL addStatusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xControl,
123 : const ::com::sun::star::util::URL& aURL)
124 : throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
125 :
126 : // XUnoTunnel
127 : virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE ;
128 : static const ::com::sun::star::uno::Sequence< sal_Int8 >& impl_getStaticIdentifier();
129 :
130 : static bool IsMasterUnoCommand( const ::com::sun::star::util::URL& aURL );
131 : static OUString GetMasterUnoCommand( const ::com::sun::star::util::URL& aURL );
132 :
133 : void SetFrame(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame);
134 :
135 : void SetMasterUnoCommand( bool bSet );
136 :
137 : SfxDispatcher* GetDispatcher_Impl();
138 : };
139 :
140 : class SfxDispatchController_Impl : public SfxControllerItem
141 : {
142 : ::com::sun::star::util::URL aDispatchURL;
143 : SfxDispatcher* pDispatcher;
144 : SfxBindings* pBindings;
145 : const SfxPoolItem* pLastState;
146 : sal_uInt16 nSlot;
147 : SfxOfficeDispatch* pDispatch;
148 : bool bMasterSlave;
149 : bool bVisible;
150 : const char* pUnoName;
151 : ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XFrame > xFrame;
152 :
153 : static void addParametersToArgs( const com::sun::star::util::URL& aURL,
154 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rArgs );
155 : static SfxMapUnit GetCoreMetric( SfxItemPool& rPool, sal_uInt16 nSlot );
156 :
157 : public:
158 : SfxDispatchController_Impl( SfxOfficeDispatch* pDisp,
159 : SfxBindings* pBind,
160 : SfxDispatcher* pDispat,
161 : const SfxSlot* pSlot,
162 : const ::com::sun::star::util::URL& rURL );
163 : virtual ~SfxDispatchController_Impl();
164 :
165 : static OUString getSlaveCommand( const ::com::sun::star::util::URL& rURL );
166 :
167 : void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState, SfxSlotServer* pServ );
168 : virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState ) SAL_OVERRIDE;
169 : void setMasterSlaveCommand( bool bSet );
170 : void SAL_CALL dispatch( const ::com::sun::star::util::URL& aURL,
171 : const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs,
172 : const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchResultListener >& rListener )
173 : throw (css::uno::RuntimeException, std::exception);
174 : void SAL_CALL addStatusListener(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xControl, const ::com::sun::star::util::URL& aURL) throw( ::com::sun::star::uno::RuntimeException );
175 : void UnBindController();
176 : SfxDispatcher* GetDispatcher();
177 : void SetFrame(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame);
178 :
179 : static void InterceptLOKStateChangeEvent(const SfxObjectShell* objSh, const ::com::sun::star::frame::FeatureStateEvent& aEvent);
180 : };
181 :
182 : #endif
183 :
184 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|