1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef SVX_SOURCE_INC_FMTEXTCONTROLSHELL_HXX
20 #define SVX_SOURCE_INC_FMTEXTCONTROLSHELL_HXX
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 <comphelper/implementationreference.hxx>
31 #include <tools/link.hxx>
32 #include <vcl/timer.hxx>
33 #include "fmslotinvalidator.hxx"
45 //........................................................................
48 //........................................................................
50 class FmFocusListenerAdapter
;
51 class FmTextControlFeature
;
52 class FmMouseListenerAdapter
;
54 //====================================================================
56 //====================================================================
60 virtual void focusGained( const ::com::sun::star::awt::FocusEvent
& _rEvent
) = 0;
61 virtual void focusLost( const ::com::sun::star::awt::FocusEvent
& _rEvent
) = 0;
67 //====================================================================
69 //====================================================================
70 class IContextRequestObserver
73 virtual void contextMenuRequested( const ::com::sun::star::awt::MouseEvent
& _rEvent
) = 0;
76 ~IContextRequestObserver() {}
79 //====================================================================
80 //= FmTextControlShell
81 //====================================================================
82 class FmTextControlShell
:public IFocusObserver
83 ,public ISlotInvalidator
84 ,public IContextRequestObserver
87 ::com::sun::star::uno::Reference
< ::com::sun::star::util::XURLTransformer
> m_xURLTransformer
;
88 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControl
> m_xActiveControl
;
89 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XTextComponent
> m_xActiveTextComponent
;
90 ::com::sun::star::uno::Reference
< ::com::sun::star::form::runtime::XFormController
> m_xActiveController
;
91 #ifndef DONT_REMEMBER_LAST_CONTROL
92 // without this define, m_xActiveControl remembers the *last* active control, even
93 // if it, in the meantime, already lost the focus
94 bool m_bActiveControl
;
95 // so we need an additional boolean flag telling whether the active cotrol
98 bool m_bActiveControlIsReadOnly
;
99 bool m_bActiveControlIsRichText
;
101 // listening at all controls of the active controller for focus changes
102 typedef ::comphelper::ImplementationReference
< FmFocusListenerAdapter
, ::com::sun::star::awt::XFocusListener
>
103 FocusListenerAdapter
;
104 typedef ::std::vector
< FocusListenerAdapter
> FocusListenerAdapters
;
105 FocusListenerAdapters m_aControlObservers
;
107 typedef ::comphelper::ImplementationReference
< FmMouseListenerAdapter
, ::com::sun::star::awt::XMouseListener
>
108 MouseListenerAdapter
;
109 MouseListenerAdapter m_aContextMenuObserver
;
111 // translating between "slots" of the framework and "features" of the active control
112 typedef ::comphelper::ImplementationReference
< FmTextControlFeature
, ::com::sun::star::frame::XStatusListener
>
114 typedef ::std::map
< SfxSlotId
, ControlFeature
, ::std::less
< SfxSlotId
> > ControlFeatures
;
115 ControlFeatures m_aControlFeatures
;
117 SfxViewFrame
* m_pViewFrame
;
118 // invalidating slots
119 SfxBindings
& m_rBindings
;
120 Link m_aControlActivationHandler
;
121 AutoTimer m_aClipboardInvalidation
;
122 bool m_bNeedClipboardInvalidation
;
125 FmTextControlShell( SfxViewFrame
* _pFrame
);
126 virtual ~FmTextControlShell();
128 // clean up any resources associated with this instance
131 void ExecuteTextAttribute( SfxRequest
& _rReq
);
132 void GetTextAttributeState( SfxItemSet
& _rSet
);
133 bool IsActiveControl( bool _bCountRichTextOnly
= false ) const;
134 void ForgetActiveControl();
135 void SetControlActivationHandler( const Link
& _rHdl
) { m_aControlActivationHandler
= _rHdl
; }
137 /** to be called when a form in our document has been activated
139 void formActivated( const ::com::sun::star::uno::Reference
< ::com::sun::star::form::runtime::XFormController
>& _rxController
);
140 /** to be called when a form in our document has been deactivated
142 void formDeactivated( const ::com::sun::star::uno::Reference
< ::com::sun::star::form::runtime::XFormController
>& _rxController
);
144 /** notifies the instance that the design mode has changed
146 void designModeChanged( bool _bNewDesignMode
);
150 virtual void focusGained( const ::com::sun::star::awt::FocusEvent
& _rEvent
);
151 virtual void focusLost( const ::com::sun::star::awt::FocusEvent
& _rEvent
);
153 // IContextRequestObserver
154 virtual void contextMenuRequested( const ::com::sun::star::awt::MouseEvent
& _rEvent
);
157 virtual void Invalidate( SfxSlotId _nSlot
);
160 enum AttributeSet
{ eCharAttribs
, eParaAttribs
};
161 void executeAttributeDialog( AttributeSet _eSet
, SfxRequest
& _rReq
);
162 bool executeSelectAll( );
163 bool executeClipboardSlot( SfxSlotId _nSlot
);
166 inline bool isControllerListening() const { return !m_aControlObservers
.empty(); }
168 FmTextControlFeature
*
169 implGetFeatureDispatcher(
170 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDispatchProvider
>& _rxProvider
,
171 SfxApplication
* _pApplication
,
175 // fills the given structure with dispatchers for the given slots, for the given control
176 void fillFeatureDispatchers(
177 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControl
> _rxControl
,
178 SfxSlotId
* _pZeroTerminatedSlots
,
179 ControlFeatures
& _rDispatchers
182 /// creates SfxPoolItes for all features in the given set, and puts them into the given SfxAllItemSet
183 void transferFeatureStatesToItemSet(
184 ControlFeatures
& _rDispatchers
,
185 SfxAllItemSet
& _rSet
,
186 bool _bTranslateLatin
= false
189 /// to be called when a control has been activated
190 void controlActivated( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControl
>& _rxControl
);
191 /// to be called when the currently active control has been deactivated
192 void controlDeactivated( );
194 void implClearActiveControlRef();
196 /** starts listening at all controls of the given controller for focus events
198 we don't have an active controller currently
200 void startControllerListening( const ::com::sun::star::uno::Reference
< ::com::sun::star::form::runtime::XFormController
>& _rxController
);
201 /** stops listening at the active controller
203 we have an active controller currently
205 void stopControllerListening( );
207 /** parses the given URL's Complete member, by calling XURLTransformer::parseString
209 void impl_parseURL_nothrow( ::com::sun::star::util::URL
& _rURL
);
211 DECL_LINK( OnInvalidateClipboard
, void* );
214 //........................................................................
216 //........................................................................
218 #endif // SVX_SOURCE_INC_FMTEXTCONTROLSHELL_HXX
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */