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