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_BINDINGS_HXX
20 : #define INCLUDED_SFX2_BINDINGS_HXX
21 :
22 : #include <sal/config.h>
23 : #include <sfx2/dllapi.h>
24 : #include <sal/types.h>
25 : #include <rtl/strbuf.hxx>
26 : #include <tools/link.hxx>
27 : #include <com/sun/star/frame/XFrame.hpp>
28 : #include <com/sun/star/frame/XDispatchProvider.hpp>
29 : #include <com/sun/star/uno/Reference.h>
30 : #include <com/sun/star/frame/XDispatchRecorderSupplier.hpp>
31 : #include <vector>
32 :
33 :
34 : // some other includes
35 :
36 :
37 : #include <sfx2/viewfrm.hxx>
38 :
39 :
40 : // forwards, typedefs, declarations
41 :
42 :
43 : class SystemWindow;
44 : class SfxSlot;
45 : class SfxSlotServer;
46 : class SfxControllerItem;
47 : class SfxStateCache;
48 : class SfxItemSet;
49 : class SfxDispatcher;
50 : class SfxBindings;
51 : class SfxBindings_Impl;
52 : class Timer;
53 : struct SfxFoundCache_Impl;
54 : class SfxFoundCacheArr_Impl;
55 : class SfxWorkWindow;
56 : class SfxUnoControllerItem;
57 :
58 : typedef std::vector<SfxUnoControllerItem*> SfxUnoControllerArr_Impl;
59 :
60 : #define SFX_CALLMODE_SLOT 0x00 // sync/async from Slot
61 : #define SFX_CALLMODE_SYNCHRON 0x01 // synchronously in the same Stackframe
62 : #define SFX_CALLMODE_ASYNCHRON 0x02 // asynchronously via AppEvent
63 : #define SFX_CALLMODE_RECORD 0x04 // take into accont while recording
64 : #define SFX_CALLMODE_API 0x08 // API call (silent)
65 : #define SFX_CALLMODE_MODAL 0x10 // despite ModalMode
66 :
67 : #define SFX_CALLMODE_STANDARD SFX_CALLMODE_RECORD
68 : typedef sal_uInt16 SfxCallMode;
69 :
70 : enum SfxPopupAction
71 : {
72 : SFX_POPUP_DELETE,
73 : SFX_POPUP_HIDE,
74 : SFX_POPUP_SHOW
75 : };
76 :
77 :
78 : class SFX2_DLLPUBLIC SfxBindings: public SfxBroadcaster
79 :
80 : /* [Description]
81 :
82 : In each SFx application one instance of the SfxBindings-Class will
83 : exists from <SfxApplication::Init()> until <SfxApplication::Exit()>.
84 : This instance is automatically created and destroyed by SfxApplication.
85 : However these instances will be handled by the Macro <SFX_BINDINGS>
86 : or the associated <SfxViewFrame>.
87 :
88 : The SfxBindings manages all of its Slot-Ids bound by the registerd
89 : controllers and keeps a cache of the <Slot-Server> respectively.
90 : (it is what we call the combination of SfxShell instance and SfxSlot).
91 : In the SfxBindings it is stored, if and in this case which controllers
92 : that are dirty and which Slot-Server-Caches are dirty respectively.
93 : It summarizes status queries (calls to the status methods specified
94 : in the IDL) that are served by the same state methods, and handles
95 : the simulation of <Pseudo-Slots>.
96 : */
97 :
98 : {
99 : friend class SfxApplication;
100 : friend class SfxShell;
101 : friend class SfxBindings_Impl;
102 :
103 : SfxBindings_Impl*pImp; // Data of the Bindings instance
104 : SfxDispatcher* pDispatcher; // Dispatcher, to be used
105 : sal_uInt16 nRegLevel; // Lock-Level while Reconfig
106 :
107 : private:
108 : SAL_DLLPRIVATE const SfxPoolItem* Execute_Impl( sal_uInt16 nSlot, const SfxPoolItem **pArgs, sal_uInt16 nModi,
109 : SfxCallMode nCall, const SfxPoolItem **pInternalArgs, bool bGlobalOnly=false);
110 : SAL_DLLPRIVATE void SetSubBindings_Impl( SfxBindings* );
111 : SAL_DLLPRIVATE void UpdateSlotServer_Impl(); // Update SlotServer
112 : SAL_DLLPRIVATE SfxItemSet* CreateSet_Impl( SfxStateCache* &pCache,
113 : const SfxSlot* &pRealSlot,
114 : const SfxSlotServer**,
115 : SfxFoundCacheArr_Impl& );
116 : SAL_DLLPRIVATE sal_uInt16 GetSlotPos( sal_uInt16 nId, sal_uInt16 nStartSearchAt = 0 );
117 : SAL_DLLPRIVATE void Update_Impl( SfxStateCache* pCache );
118 : SAL_DLLPRIVATE void UpdateControllers_Impl(
119 : const SfxInterface* pIF,
120 : const SfxFoundCache_Impl* pFound,
121 : const SfxPoolItem *pItem,
122 : SfxItemState eItemState );
123 : SAL_DLLPRIVATE SfxStateCache* GetStateCache( sal_uInt16 nId, sal_uInt16 *pPos);
124 : DECL_DLLPRIVATE_LINK( NextJob_Impl, Timer * );
125 :
126 : public:
127 : SfxBindings();
128 : virtual ~SfxBindings();
129 :
130 : void HidePopups( bool bHide = true );
131 : SAL_DLLPRIVATE void HidePopupCtrls_Impl( bool bHide = true );
132 :
133 : void SetDispatcher(SfxDispatcher *pDisp);
134 :
135 : void Update( sal_uInt16 nId ); // For example, from Menu::Activate
136 : void Update();
137 : SAL_DLLPRIVATE void StartUpdate_Impl(bool bComplete=false);
138 : void Invalidate( sal_uInt16 nId );
139 : void Invalidate( const sal_uInt16* pIds );
140 : void InvalidateShell( const SfxShell &rSh, bool bDeep = false );
141 : void InvalidateAll( bool bWithMsg );
142 : void SetState( const SfxItemSet &rSet );
143 : void SetState( const SfxPoolItem &rItem );
144 : void Invalidate( sal_uInt16 nId, bool bWithItem, bool bWithMsg=false);
145 : void Invalidate( sal_uInt16 nId, bool bWithMsg);
146 : bool IsInUpdate() const;
147 : void SetVisibleState( sal_uInt16 nId, bool bShow );
148 :
149 : bool IsBound( sal_uInt16 nMsgId, sal_uInt16 nStartSearchAt = 0 );
150 :
151 : SfxStateCache* GetStateCache( sal_uInt16 nId);
152 : SAL_DLLPRIVATE SfxStateCache* GetAnyStateCache_Impl( sal_uInt16 nId );
153 : /**
154 : * @param rpState the caller has to delete the pointer
155 : */
156 : SfxItemState QueryState( sal_uInt16 nSID, SfxPoolItem* &rpState );
157 :
158 : const SfxPoolItem* ExecuteSynchron( sal_uInt16 nSlot,
159 : const SfxPoolItem **pArgs = 0,
160 : sal_uInt16 nModi = 0,
161 : const SfxPoolItem **pInternalArgs = 0);
162 : bool Execute( sal_uInt16 nSlot,
163 : const SfxPoolItem **pArgs = 0,
164 : sal_uInt16 nModi = 0,
165 : SfxCallMode nCall = SFX_CALLMODE_SLOT,
166 : const SfxPoolItem **pInternalArgs = 0);
167 :
168 : SAL_DLLPRIVATE void SetDispatchProvider_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > & rFrame );
169 : void SetActiveFrame( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > & rFrame );
170 : const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > GetActiveFrame() const;
171 : // Reconfig
172 : bool IsInRegistrations() const;
173 : sal_uInt16 EnterRegistrations(const char *pFile = 0, int nLine = 0);
174 : void LeaveRegistrations( sal_uInt16 nLevel = USHRT_MAX, const char *pFile = 0, int nLine = 0 );
175 : void Register( SfxControllerItem& rBinding );
176 : void Release( SfxControllerItem& rBinding );
177 0 : SfxDispatcher* GetDispatcher() const
178 0 : { return pDispatcher; }
179 : com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > GetRecorder() const;
180 : com::sun::star::uno::Reference < com::sun::star::frame::XDispatch >
181 : GetDispatch( const SfxSlot*, const com::sun::star::util::URL& aURL, bool bMasterCommand );
182 : SAL_DLLPRIVATE void ContextChanged_Impl();
183 : SAL_DLLPRIVATE void Execute_Impl( SfxRequest& rReq, const SfxSlot* pSlot, SfxShell* pShell );
184 : SAL_DLLPRIVATE void DeleteControllers_Impl();
185 0 : SAL_DLLPRIVATE SfxDispatcher* GetDispatcher_Impl() { return pDispatcher; }
186 : SAL_DLLPRIVATE void ClearCache_Impl( sal_uInt16 nSlotId );
187 : SAL_DLLPRIVATE bool IsInUpdate_Impl() const{ return IsInUpdate(); }
188 : SAL_DLLPRIVATE void RegisterInternal_Impl( SfxControllerItem& rBinding );
189 : SAL_DLLPRIVATE void Register_Impl( SfxControllerItem& rBinding, bool );
190 : SAL_DLLPRIVATE SfxWorkWindow* GetWorkWindow_Impl() const;
191 : SAL_DLLPRIVATE void SetWorkWindow_Impl( SfxWorkWindow* );
192 : SAL_DLLPRIVATE SfxBindings* GetSubBindings_Impl( bool bTop = false ) const;
193 : SAL_DLLPRIVATE void InvalidateUnoControllers_Impl();
194 : SAL_DLLPRIVATE void RegisterUnoController_Impl( SfxUnoControllerItem* );
195 : SAL_DLLPRIVATE void ReleaseUnoController_Impl( SfxUnoControllerItem* );
196 : SAL_DLLPRIVATE bool ExecuteCommand_Impl( const OUString& rCommand );
197 : SAL_DLLPRIVATE void SetRecorder_Impl( com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder >& );
198 : SAL_DLLPRIVATE void InvalidateSlotsInMap_Impl();
199 : SAL_DLLPRIVATE void AddSlotToInvalidateSlotsMap_Impl( sal_uInt16 nId );
200 : };
201 :
202 : #ifdef DBG_UTIL
203 : #define ENTERREGISTRATIONS() EnterRegistrations(__FILE__, __LINE__)
204 : #define LEAVEREGISTRATIONS() LeaveRegistrations(USHRT_MAX, __FILE__, __LINE__)
205 : #define DENTERREGISTRATIONS() \
206 : EnterRegistrations( OStringBuffer(__FILE__).append('(').append(reinterpret_cast<sal_Int64>(this)).append(')').getStr(), __LINE__ )
207 : #define DLEAVEREGISTRATIONS( ) \
208 : LeaveRegistrations( USHRT_MAX, OStringBuffer(__FILE__).append('(').append(reinterpret_cast<sal_Int64>(this)).append(')').getStr(), __LINE__ )
209 : #else
210 : #define ENTERREGISTRATIONS() EnterRegistrations()
211 : #define LEAVEREGISTRATIONS() LeaveRegistrations()
212 : #define DENTERREGISTRATIONS() EnterRegistrations()
213 : #define DLEAVEREGISTRATIONS() LeaveRegistrations()
214 : #endif
215 :
216 :
217 :
218 : inline bool SfxBindings::IsInRegistrations() const
219 :
220 : /* [Description]
221 :
222 : Determines whether the <SfxContollerItems> SfxBindings instance is
223 : registerd or unregisted, i.e. <SfxBindings::EnterRegistrations()>
224 : calls that have not been closed by <SfxBindings::LeaveRegistrations()>.
225 :
226 : [Return value]
227 :
228 : int sal_True
229 : The SfxBindings instance is currently in
230 : Registration-Mode. No status updates .
231 :
232 : int sal_False
233 : The SfxBindings instance is the normal mode.
234 : Status updates can be done.
235 : */
236 :
237 : {
238 : return 0 != nRegLevel;
239 : }
240 :
241 :
242 :
243 : #endif
244 :
245 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|