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