Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #ifndef SVX_SOURCE_INC_FMTEXTCONTROLSHELL_HXX
29 : : #define SVX_SOURCE_INC_FMTEXTCONTROLSHELL_HXX
30 : :
31 : : #include <com/sun/star/frame/XDispatchProvider.hpp>
32 : : #include <com/sun/star/awt/XTextComponent.hpp>
33 : : #include <com/sun/star/frame/XStatusListener.hpp>
34 : : #include <com/sun/star/awt/XFocusListener.hpp>
35 : : #include <com/sun/star/awt/XMouseListener.hpp>
36 : : #include <com/sun/star/form/runtime/XFormController.hpp>
37 : : #include <com/sun/star/awt/XControl.hpp>
38 : : #include <com/sun/star/util/XURLTransformer.hpp>
39 : : #include <comphelper/implementationreference.hxx>
40 : : #include <tools/link.hxx>
41 : : #include <vcl/timer.hxx>
42 : : #include "fmslotinvalidator.hxx"
43 : :
44 : : #include <vector>
45 : : #include <map>
46 : :
47 : : class SfxRequest;
48 : : class SfxItemSet;
49 : : class SfxAllItemSet;
50 : : class SfxBindings;
51 : : class SfxViewFrame;
52 : : class SfxApplication;
53 : :
54 : : //........................................................................
55 : : namespace svx
56 : : {
57 : : //........................................................................
58 : :
59 : : class FmFocusListenerAdapter;
60 : : class FmTextControlFeature;
61 : : class FmMouseListenerAdapter;
62 : :
63 : : //====================================================================
64 : : //= IFocusObserver
65 : : //====================================================================
66 : 1669 : class IFocusObserver
67 : : {
68 : : public:
69 : : virtual void focusGained( const ::com::sun::star::awt::FocusEvent& _rEvent ) = 0;
70 : : virtual void focusLost( const ::com::sun::star::awt::FocusEvent& _rEvent ) = 0;
71 : :
72 : : protected:
73 : 1578 : ~IFocusObserver() {}
74 : : };
75 : :
76 : : //====================================================================
77 : : //= IFocusObserver
78 : : //====================================================================
79 : 1669 : class IContextRequestObserver
80 : : {
81 : : public:
82 : : virtual void contextMenuRequested( const ::com::sun::star::awt::MouseEvent& _rEvent ) = 0;
83 : :
84 : : protected:
85 : 1578 : ~IContextRequestObserver() {}
86 : : };
87 : :
88 : : //====================================================================
89 : : //= FmTextControlShell
90 : : //====================================================================
91 : : class FmTextControlShell :public IFocusObserver
92 : : ,public ISlotInvalidator
93 : : ,public IContextRequestObserver
94 : : {
95 : : private:
96 : : ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer > m_xURLTransformer;
97 : : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > m_xActiveControl;
98 : : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextComponent > m_xActiveTextComponent;
99 : : ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > m_xActiveController;
100 : : #ifndef DONT_REMEMBER_LAST_CONTROL
101 : : // without this define, m_xActiveControl remembers the *last* active control, even
102 : : // if it, in the meantime, already lost the focus
103 : : bool m_bActiveControl;
104 : : // so we need an additional boolean flag telling whether the active cotrol
105 : : // is really focused
106 : : #endif
107 : : bool m_bActiveControlIsReadOnly;
108 : : bool m_bActiveControlIsRichText;
109 : :
110 : : // listening at all controls of the active controller for focus changes
111 : : typedef ::comphelper::ImplementationReference< FmFocusListenerAdapter, ::com::sun::star::awt::XFocusListener >
112 : : FocusListenerAdapter;
113 : : typedef ::std::vector< FocusListenerAdapter > FocusListenerAdapters;
114 : : FocusListenerAdapters m_aControlObservers;
115 : :
116 : : typedef ::comphelper::ImplementationReference< FmMouseListenerAdapter, ::com::sun::star::awt::XMouseListener >
117 : : MouseListenerAdapter;
118 : : MouseListenerAdapter m_aContextMenuObserver;
119 : :
120 : : // translating between "slots" of the framework and "features" of the active control
121 : : typedef ::comphelper::ImplementationReference< FmTextControlFeature, ::com::sun::star::frame::XStatusListener >
122 : : ControlFeature;
123 : : typedef ::std::map< SfxSlotId, ControlFeature, ::std::less< SfxSlotId > > ControlFeatures;
124 : : ControlFeatures m_aControlFeatures;
125 : :
126 : : SfxViewFrame* m_pViewFrame;
127 : : // invalidating slots
128 : : SfxBindings& m_rBindings;
129 : : Link m_aControlActivationHandler;
130 : : AutoTimer m_aClipboardInvalidation;
131 : : bool m_bNeedClipboardInvalidation;
132 : :
133 : : public:
134 : : FmTextControlShell( SfxViewFrame* _pFrame );
135 : : virtual ~FmTextControlShell();
136 : :
137 : : // clean up any resources associated with this instance
138 : : void dispose();
139 : :
140 : : void ExecuteTextAttribute( SfxRequest& _rReq );
141 : : void GetTextAttributeState( SfxItemSet& _rSet );
142 : : bool IsActiveControl( bool _bCountRichTextOnly = false ) const;
143 : : void ForgetActiveControl();
144 : 1795 : void SetControlActivationHandler( const Link& _rHdl ) { m_aControlActivationHandler = _rHdl; }
145 : :
146 : : /** to be called when a form in our document has been activated
147 : : */
148 : : void formActivated( const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController );
149 : : /** to be called when a form in our document has been deactivated
150 : : */
151 : : void formDeactivated( const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController );
152 : :
153 : : /** notifies the instance that the design mode has changed
154 : : */
155 : : void designModeChanged( bool _bNewDesignMode );
156 : :
157 : : protected:
158 : : // IFocusObserver
159 : : virtual void focusGained( const ::com::sun::star::awt::FocusEvent& _rEvent );
160 : : virtual void focusLost( const ::com::sun::star::awt::FocusEvent& _rEvent );
161 : :
162 : : // IContextRequestObserver
163 : : virtual void contextMenuRequested( const ::com::sun::star::awt::MouseEvent& _rEvent );
164 : :
165 : : // ISlotInvalidator
166 : : virtual void Invalidate( SfxSlotId _nSlot );
167 : :
168 : : protected:
169 : : enum AttributeSet { eCharAttribs, eParaAttribs };
170 : : void executeAttributeDialog( AttributeSet _eSet, SfxRequest& _rReq );
171 : : bool executeSelectAll( );
172 : : bool executeClipboardSlot( SfxSlotId _nSlot );
173 : :
174 : : private:
175 : 3168 : inline bool isControllerListening() const { return !m_aControlObservers.empty(); }
176 : :
177 : : FmTextControlFeature*
178 : : implGetFeatureDispatcher(
179 : : const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& _rxProvider,
180 : : SfxApplication* _pApplication,
181 : : SfxSlotId _nSlot
182 : : );
183 : :
184 : : // fills the given structure with dispatchers for the given slots, for the given control
185 : : void fillFeatureDispatchers(
186 : : const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > _rxControl,
187 : : SfxSlotId* _pZeroTerminatedSlots,
188 : : ControlFeatures& _rDispatchers
189 : : );
190 : :
191 : : /// creates SfxPoolItes for all features in the given set, and puts them into the given SfxAllItemSet
192 : : void transferFeatureStatesToItemSet(
193 : : ControlFeatures& _rDispatchers,
194 : : SfxAllItemSet& _rSet,
195 : : bool _bTranslateLatin = false
196 : : );
197 : :
198 : : /// to be called when a control has been activated
199 : : void controlActivated( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl );
200 : : /// to be called when the currently active control has been deactivated
201 : : void controlDeactivated( );
202 : :
203 : : void implClearActiveControlRef();
204 : :
205 : : /** starts listening at all controls of the given controller for focus events
206 : : @precond
207 : : we don't have an active controller currently
208 : : */
209 : : void startControllerListening( const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController );
210 : : /** stops listening at the active controller
211 : : @precond
212 : : we have an active controller currently
213 : : */
214 : : void stopControllerListening( );
215 : :
216 : : /** parses the given URL's Complete member, by calling XURLTransformer::parseString
217 : : */
218 : : void impl_parseURL_nothrow( ::com::sun::star::util::URL& _rURL );
219 : :
220 : : DECL_LINK( OnInvalidateClipboard, void* );
221 : : };
222 : :
223 : : //........................................................................
224 : : } // namespace svx
225 : : //........................................................................
226 : :
227 : : #endif // SVX_SOURCE_INC_FMTEXTCONTROLSHELL_HXX
228 : :
229 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|