/src/libreoffice/svx/source/inc/fmtextcontrolshell.hxx
Line | Count | Source |
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_SVX_SOURCE_INC_FMTEXTCONTROLSHELL_HXX |
20 | | #define INCLUDED_SVX_SOURCE_INC_FMTEXTCONTROLSHELL_HXX |
21 | | |
22 | | #include <com/sun/star/frame/XDispatchProvider.hpp> |
23 | | #include <com/sun/star/awt/FocusEvent.hpp> |
24 | | #include <com/sun/star/awt/XTextComponent.hpp> |
25 | | #include <com/sun/star/form/runtime/XFormController.hpp> |
26 | | #include <com/sun/star/awt/XControl.hpp> |
27 | | #include <com/sun/star/util/XURLTransformer.hpp> |
28 | | #include <rtl/ref.hxx> |
29 | | #include <tools/link.hxx> |
30 | | #include <vcl/timer.hxx> |
31 | | #include "fmslotinvalidator.hxx" |
32 | | |
33 | | #include <vector> |
34 | | #include <map> |
35 | | |
36 | | class SfxRequest; |
37 | | class SfxItemSet; |
38 | | class SfxAllItemSet; |
39 | | class SfxBindings; |
40 | | class SfxViewFrame; |
41 | | class SfxApplication; |
42 | | |
43 | | |
44 | | namespace svx |
45 | | { |
46 | | |
47 | | |
48 | | class FmFocusListenerAdapter; |
49 | | class FmTextControlFeature; |
50 | | class FmMouseListenerAdapter; |
51 | | |
52 | | class IFocusObserver |
53 | | { |
54 | | public: |
55 | | virtual void focusGained( const css::awt::FocusEvent& _rEvent ) = 0; |
56 | | virtual void focusLost( const css::awt::FocusEvent& _rEvent ) = 0; |
57 | | |
58 | | protected: |
59 | 8.47k | ~IFocusObserver() {} |
60 | | }; |
61 | | |
62 | | |
63 | | //= IFocusObserver |
64 | | |
65 | | class IContextRequestObserver |
66 | | { |
67 | | public: |
68 | | virtual void contextMenuRequested() = 0; |
69 | | |
70 | | protected: |
71 | 8.47k | ~IContextRequestObserver() {} |
72 | | }; |
73 | | |
74 | | class FmTextControlShell final : public IFocusObserver |
75 | | ,public IContextRequestObserver |
76 | | { |
77 | | private: |
78 | | css::uno::Reference< css::util::XURLTransformer > m_xURLTransformer; |
79 | | css::uno::Reference< css::awt::XControl > m_xActiveControl; |
80 | | css::uno::Reference< css::awt::XTextComponent > m_xActiveTextComponent; |
81 | | css::uno::Reference< css::form::runtime::XFormController > m_xActiveController; |
82 | | #ifndef DONT_REMEMBER_LAST_CONTROL |
83 | | // without this define, m_xActiveControl remembers the *last* active control, even |
84 | | // if it, in the meantime, already lost the focus |
85 | | bool m_bActiveControl; |
86 | | // so we need an additional boolean flag telling whether the active control |
87 | | // is really focused |
88 | | #endif |
89 | | bool m_bActiveControlIsReadOnly; |
90 | | bool m_bActiveControlIsRichText; |
91 | | |
92 | | // listening at all controls of the active controller for focus changes |
93 | | typedef rtl::Reference<FmFocusListenerAdapter> FocusListenerAdapter; |
94 | | typedef ::std::vector< FocusListenerAdapter > FocusListenerAdapters; |
95 | | FocusListenerAdapters m_aControlObservers; |
96 | | |
97 | | typedef rtl::Reference<FmMouseListenerAdapter> MouseListenerAdapter; |
98 | | MouseListenerAdapter m_aContextMenuObserver; |
99 | | |
100 | | // translating between "slots" of the framework and "features" of the active control |
101 | | typedef rtl::Reference<FmTextControlFeature> ControlFeature; |
102 | | typedef ::std::map< SfxSlotId, ControlFeature > ControlFeatures; |
103 | | ControlFeatures m_aControlFeatures; |
104 | | |
105 | | SfxViewFrame* m_pViewFrame; |
106 | | // invalidating slots |
107 | | SfxBindings& m_rBindings; |
108 | | Link<LinkParamNone*,void> m_aControlActivationHandler; |
109 | | AutoTimer m_aClipboardInvalidation; |
110 | | bool m_bNeedClipboardInvalidation; |
111 | | |
112 | | public: |
113 | | FmTextControlShell( SfxViewFrame* _pFrame ); |
114 | | ~FmTextControlShell(); |
115 | | |
116 | | // clean up any resources associated with this instance |
117 | | void dispose(); |
118 | | |
119 | | void ExecuteTextAttribute( SfxRequest& _rReq ); |
120 | | void GetTextAttributeState( SfxItemSet& _rSet ); |
121 | | bool IsActiveControl( bool _bCountRichTextOnly = false ) const; |
122 | | void ForgetActiveControl(); |
123 | 8.47k | void SetControlActivationHandler( const Link<LinkParamNone*,void>& _rHdl ) { m_aControlActivationHandler = _rHdl; } |
124 | | |
125 | | /** to be called when a form in our document has been activated |
126 | | */ |
127 | | void formActivated( const css::uno::Reference< css::form::runtime::XFormController >& _rxController ); |
128 | | /** to be called when a form in our document has been deactivated |
129 | | */ |
130 | | void formDeactivated( const css::uno::Reference< css::form::runtime::XFormController >& _rxController ); |
131 | | |
132 | | /** notifies the instance that the design mode has changed |
133 | | */ |
134 | | void designModeChanged(); |
135 | | |
136 | | void Invalidate( SfxSlotId _nSlot ); |
137 | | |
138 | | private: |
139 | | // IFocusObserver |
140 | | virtual void focusGained( const css::awt::FocusEvent& _rEvent ) override; |
141 | | virtual void focusLost( const css::awt::FocusEvent& _rEvent ) override; |
142 | | |
143 | | // IContextRequestObserver |
144 | | virtual void contextMenuRequested() override; |
145 | | |
146 | | enum AttributeSet { eCharAttribs, eParaAttribs }; |
147 | | void executeAttributeDialog( AttributeSet _eSet, SfxRequest& _rReq ); |
148 | | void executeSelectAll( ); |
149 | | void executeClipboardSlot( SfxSlotId _nSlot ); |
150 | | |
151 | 16.9k | bool isControllerListening() const { return !m_aControlObservers.empty(); } |
152 | | |
153 | | rtl::Reference<FmTextControlFeature> |
154 | | implGetFeatureDispatcher( |
155 | | const css::uno::Reference< css::frame::XDispatchProvider >& _rxProvider, |
156 | | SfxApplication const * _pApplication, |
157 | | SfxSlotId _nSlot |
158 | | ); |
159 | | |
160 | | // fills the given structure with dispatchers for the given slots, for the given control |
161 | | void fillFeatureDispatchers( |
162 | | const css::uno::Reference< css::awt::XControl >& _rxControl, |
163 | | SfxSlotId* _pZeroTerminatedSlots, |
164 | | ControlFeatures& _rDispatchers |
165 | | ); |
166 | | |
167 | | /// creates SfxPoolItes for all features in the given set, and puts them into the given SfxAllItemSet |
168 | | static void transferFeatureStatesToItemSet( |
169 | | ControlFeatures& _rDispatchers, |
170 | | SfxAllItemSet& _rSet, |
171 | | bool _bTranslateLatin |
172 | | ); |
173 | | |
174 | | /// to be called when a control has been activated |
175 | | void controlActivated( const css::uno::Reference< css::awt::XControl >& _rxControl ); |
176 | | /// to be called when the currently active control has been deactivated |
177 | | void controlDeactivated( ); |
178 | | |
179 | | void implClearActiveControlRef(); |
180 | | |
181 | | /** starts listening at all controls of the given controller for focus events |
182 | | @precond |
183 | | we don't have an active controller currently |
184 | | */ |
185 | | void startControllerListening( const css::uno::Reference< css::form::runtime::XFormController >& _rxController ); |
186 | | /** stops listening at the active controller |
187 | | @precond |
188 | | we have an active controller currently |
189 | | */ |
190 | | void stopControllerListening( ); |
191 | | |
192 | | DECL_LINK( OnInvalidateClipboard, Timer*, void ); |
193 | | }; |
194 | | |
195 | | |
196 | | } |
197 | | |
198 | | |
199 | | #endif // INCLUDED_SVX_SOURCE_INC_FMTEXTCONTROLSHELL_HXX |
200 | | |
201 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |