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