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 INCLUDED_SVX_SOURCE_INC_FMTEXTCONTROLSHELL_HXX
20 #define INCLUDED_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/awt/XFocusListener.hpp>
25 #include <com/sun/star/awt/XMouseListener.hpp>
26 #include <com/sun/star/form/runtime/XFormController.hpp>
27 #include <com/sun/star/awt/XControl.hpp>
28 #include <com/sun/star/util/XURLTransformer.hpp>
29 #include <rtl/ref.hxx>
30 #include <tools/link.hxx>
31 #include <vcl/timer.hxx>
32 #include "fmslotinvalidator.hxx"
49 class FmFocusListenerAdapter
;
50 class FmTextControlFeature
;
51 class FmMouseListenerAdapter
;
56 virtual void focusGained( const css::awt::FocusEvent
& _rEvent
) = 0;
57 virtual void focusLost( const css::awt::FocusEvent
& _rEvent
) = 0;
66 class IContextRequestObserver
69 virtual void contextMenuRequested() = 0;
72 ~IContextRequestObserver() {}
75 class FmTextControlShell
:public IFocusObserver
76 ,public IContextRequestObserver
79 css::uno::Reference
< css::util::XURLTransformer
> m_xURLTransformer
;
80 css::uno::Reference
< css::awt::XControl
> m_xActiveControl
;
81 css::uno::Reference
< css::awt::XTextComponent
> m_xActiveTextComponent
;
82 css::uno::Reference
< css::form::runtime::XFormController
> m_xActiveController
;
83 #ifndef DONT_REMEMBER_LAST_CONTROL
84 // without this define, m_xActiveControl remembers the *last* active control, even
85 // if it, in the meantime, already lost the focus
86 bool m_bActiveControl
;
87 // so we need an additional boolean flag telling whether the active control
90 bool m_bActiveControlIsReadOnly
;
91 bool m_bActiveControlIsRichText
;
93 // listening at all controls of the active controller for focus changes
94 typedef rtl::Reference
<FmFocusListenerAdapter
> FocusListenerAdapter
;
95 typedef ::std::vector
< FocusListenerAdapter
> FocusListenerAdapters
;
96 FocusListenerAdapters m_aControlObservers
;
98 typedef rtl::Reference
<FmMouseListenerAdapter
> MouseListenerAdapter
;
99 MouseListenerAdapter m_aContextMenuObserver
;
101 // translating between "slots" of the framework and "features" of the active control
102 typedef rtl::Reference
<FmTextControlFeature
> ControlFeature
;
103 typedef ::std::map
< SfxSlotId
, ControlFeature
> ControlFeatures
;
104 ControlFeatures m_aControlFeatures
;
106 SfxViewFrame
* m_pViewFrame
;
107 // invalidating slots
108 SfxBindings
& m_rBindings
;
109 Link
<LinkParamNone
*,void> m_aControlActivationHandler
;
110 AutoTimer m_aClipboardInvalidation
;
111 bool m_bNeedClipboardInvalidation
;
114 FmTextControlShell( SfxViewFrame
* _pFrame
);
115 virtual ~FmTextControlShell();
117 // clean up any resources associated with this instance
120 void ExecuteTextAttribute( SfxRequest
& _rReq
);
121 void GetTextAttributeState( SfxItemSet
& _rSet
);
122 bool IsActiveControl( bool _bCountRichTextOnly
= false ) const;
123 void ForgetActiveControl();
124 void SetControlActivationHandler( const Link
<LinkParamNone
*,void>& _rHdl
) { m_aControlActivationHandler
= _rHdl
; }
126 /** to be called when a form in our document has been activated
128 void formActivated( const css::uno::Reference
< css::form::runtime::XFormController
>& _rxController
);
129 /** to be called when a form in our document has been deactivated
131 void formDeactivated( const css::uno::Reference
< css::form::runtime::XFormController
>& _rxController
);
133 /** notifies the instance that the design mode has changed
135 void designModeChanged();
137 void Invalidate( SfxSlotId _nSlot
);
141 virtual void focusGained( const css::awt::FocusEvent
& _rEvent
) override
;
142 virtual void focusLost( const css::awt::FocusEvent
& _rEvent
) override
;
144 // IContextRequestObserver
145 virtual void contextMenuRequested() override
;
147 enum AttributeSet
{ eCharAttribs
, eParaAttribs
};
148 void executeAttributeDialog( AttributeSet _eSet
, SfxRequest
& _rReq
);
149 void executeSelectAll( );
150 void executeClipboardSlot( SfxSlotId _nSlot
);
153 bool isControllerListening() const { return !m_aControlObservers
.empty(); }
155 FmTextControlFeature
*
156 implGetFeatureDispatcher(
157 const css::uno::Reference
< css::frame::XDispatchProvider
>& _rxProvider
,
158 SfxApplication
const * _pApplication
,
162 // fills the given structure with dispatchers for the given slots, for the given control
163 void fillFeatureDispatchers(
164 const css::uno::Reference
< css::awt::XControl
>& _rxControl
,
165 SfxSlotId
* _pZeroTerminatedSlots
,
166 ControlFeatures
& _rDispatchers
169 /// creates SfxPoolItes for all features in the given set, and puts them into the given SfxAllItemSet
170 static void transferFeatureStatesToItemSet(
171 ControlFeatures
& _rDispatchers
,
172 SfxAllItemSet
& _rSet
,
173 bool _bTranslateLatin
176 /// to be called when a control has been activated
177 void controlActivated( const css::uno::Reference
< css::awt::XControl
>& _rxControl
);
178 /// to be called when the currently active control has been deactivated
179 void controlDeactivated( );
181 void implClearActiveControlRef();
183 /** starts listening at all controls of the given controller for focus events
185 we don't have an active controller currently
187 void startControllerListening( const css::uno::Reference
< css::form::runtime::XFormController
>& _rxController
);
188 /** stops listening at the active controller
190 we have an active controller currently
192 void stopControllerListening( );
194 DECL_LINK( OnInvalidateClipboard
, Timer
*, void );
201 #endif // INCLUDED_SVX_SOURCE_INC_FMTEXTCONTROLSHELL_HXX
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */