LibreOffice Module svx (master)  1
fmtextcontrolshell.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 #ifndef INCLUDED_SVX_SOURCE_INC_FMTEXTCONTROLSHELL_HXX
20 #define INCLUDED_SVX_SOURCE_INC_FMTEXTCONTROLSHELL_HXX
21 
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"
33 
34 #include <vector>
35 #include <map>
36 
37 class SfxRequest;
38 class SfxItemSet;
39 class SfxAllItemSet;
40 class SfxBindings;
41 class SfxViewFrame;
42 class SfxApplication;
43 
44 
45 namespace svx
46 {
47 
48 
49  class FmFocusListenerAdapter;
50  class FmTextControlFeature;
51  class FmMouseListenerAdapter;
52 
54  {
55  public:
56  virtual void focusGained( const css::awt::FocusEvent& _rEvent ) = 0;
57  virtual void focusLost( const css::awt::FocusEvent& _rEvent ) = 0;
58 
59  protected:
61  };
62 
63 
64  //= IFocusObserver
65 
67  {
68  public:
69  virtual void contextMenuRequested() = 0;
70 
71  protected:
73  };
74 
77  {
78  private:
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
87  // so we need an additional boolean flag telling whether the active control
88  // is really focused
89 #endif
92 
93  // listening at all controls of the active controller for focus changes
95  typedef ::std::vector< FocusListenerAdapter > FocusListenerAdapters;
96  FocusListenerAdapters m_aControlObservers;
97 
99  MouseListenerAdapter m_aContextMenuObserver;
100 
101  // translating between "slots" of the framework and "features" of the active control
103  typedef ::std::map< SfxSlotId, ControlFeature > ControlFeatures;
104  ControlFeatures m_aControlFeatures;
105 
107  // invalidating slots
112 
113  public:
114  FmTextControlShell( SfxViewFrame* _pFrame );
115  virtual ~FmTextControlShell();
116 
117  // clean up any resources associated with this instance
118  void dispose();
119 
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; }
125 
128  void formActivated( const css::uno::Reference< css::form::runtime::XFormController >& _rxController );
131  void formDeactivated( const css::uno::Reference< css::form::runtime::XFormController >& _rxController );
132 
135  void designModeChanged();
136 
137  void Invalidate( SfxSlotId _nSlot );
138 
139  protected:
140  // IFocusObserver
141  virtual void focusGained( const css::awt::FocusEvent& _rEvent ) override;
142  virtual void focusLost( const css::awt::FocusEvent& _rEvent ) override;
143 
144  // IContextRequestObserver
145  virtual void contextMenuRequested() override;
146 
148  void executeAttributeDialog( AttributeSet _eSet, SfxRequest& _rReq );
149  void executeSelectAll( );
150  void executeClipboardSlot( SfxSlotId _nSlot );
151 
152  private:
153  bool isControllerListening() const { return !m_aControlObservers.empty(); }
154 
157  const css::uno::Reference< css::frame::XDispatchProvider >& _rxProvider,
158  SfxApplication const * _pApplication,
159  SfxSlotId _nSlot
160  );
161 
162  // fills the given structure with dispatchers for the given slots, for the given control
164  const css::uno::Reference< css::awt::XControl >& _rxControl,
165  SfxSlotId* _pZeroTerminatedSlots,
166  ControlFeatures& _rDispatchers
167  );
168 
170  static void transferFeatureStatesToItemSet(
171  ControlFeatures& _rDispatchers,
172  SfxAllItemSet& _rSet,
173  bool _bTranslateLatin
174  );
175 
177  void controlActivated( const css::uno::Reference< css::awt::XControl >& _rxControl );
179  void controlDeactivated( );
180 
182 
187  void startControllerListening( const css::uno::Reference< css::form::runtime::XFormController >& _rxController );
192  void stopControllerListening( );
193 
194  DECL_LINK( OnInvalidateClipboard, Timer*, void );
195  };
196 
197 
198 }
199 
200 
201 #endif // INCLUDED_SVX_SOURCE_INC_FMTEXTCONTROLSHELL_HXX
202 
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ControlFeatures m_aControlFeatures
void startControllerListening(const css::uno::Reference< css::form::runtime::XFormController > &_rxController)
starts listening at all controls of the given controller for focus events we don't have an active co...
virtual void contextMenuRequested() override
MouseListenerAdapter m_aContextMenuObserver
css::uno::Reference< css::form::runtime::XFormController > m_xActiveController
css::uno::Reference< css::awt::XControl > m_xActiveControl
Link< LinkParamNone *, void > m_aControlActivationHandler
sal_uInt16 SfxSlotId
void controlDeactivated()
to be called when the currently active control has been deactivated
void stopControllerListening()
stops listening at the active controller we have an active controller currently
DECL_LINK(OnInvalidateClipboard, Timer *, void)
void SetControlActivationHandler(const Link< LinkParamNone *, void > &_rHdl)
virtual void focusLost(const css::awt::FocusEvent &_rEvent) override
void formActivated(const css::uno::Reference< css::form::runtime::XFormController > &_rxController)
to be called when a form in our document has been activated
bool IsActiveControl(bool _bCountRichTextOnly=false) const
void ExecuteTextAttribute(SfxRequest &_rReq)
FmTextControlShell(SfxViewFrame *_pFrame)
::std::map< SfxSlotId, ControlFeature > ControlFeatures
rtl::Reference< FmFocusListenerAdapter > FocusListenerAdapter
static void transferFeatureStatesToItemSet(ControlFeatures &_rDispatchers, SfxAllItemSet &_rSet, bool _bTranslateLatin)
creates SfxPoolItes for all features in the given set, and puts them into the given SfxAllItemSet ...
rtl::Reference< FmMouseListenerAdapter > MouseListenerAdapter
FmTextControlFeature * implGetFeatureDispatcher(const css::uno::Reference< css::frame::XDispatchProvider > &_rxProvider, SfxApplication const *_pApplication, SfxSlotId _nSlot)
css::uno::Reference< css::util::XURLTransformer > m_xURLTransformer
FocusListenerAdapters m_aControlObservers
rtl::Reference< FmTextControlFeature > ControlFeature
virtual void focusGained(const css::awt::FocusEvent &_rEvent) override
void formDeactivated(const css::uno::Reference< css::form::runtime::XFormController > &_rxController)
to be called when a form in our document has been deactivated
css::uno::Reference< css::awt::XTextComponent > m_xActiveTextComponent
virtual void focusGained(const css::awt::FocusEvent &_rEvent)=0
void executeClipboardSlot(SfxSlotId _nSlot)
void GetTextAttributeState(SfxItemSet &_rSet)
void fillFeatureDispatchers(const css::uno::Reference< css::awt::XControl > &_rxControl, SfxSlotId *_pZeroTerminatedSlots, ControlFeatures &_rDispatchers)
void executeAttributeDialog(AttributeSet _eSet, SfxRequest &_rReq)
void designModeChanged()
notifies the instance that the design mode has changed
virtual void contextMenuRequested()=0
virtual void focusLost(const css::awt::FocusEvent &_rEvent)=0
void controlActivated(const css::uno::Reference< css::awt::XControl > &_rxControl)
to be called when a control has been activated
void Invalidate(SfxSlotId _nSlot)
::std::vector< FocusListenerAdapter > FocusListenerAdapters