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/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"
32 
33 #include <vector>
34 #include <map>
35 
36 class SfxRequest;
37 class SfxItemSet;
38 class SfxAllItemSet;
39 class SfxBindings;
40 class SfxViewFrame;
41 class SfxApplication;
42 
43 
44 namespace svx
45 {
46 
47 
48  class FmFocusListenerAdapter;
49  class FmTextControlFeature;
50  class FmMouseListenerAdapter;
51 
53  {
54  public:
55  virtual void focusGained( const css::awt::FocusEvent& _rEvent ) = 0;
56  virtual void focusLost( const css::awt::FocusEvent& _rEvent ) = 0;
57 
58  protected:
60  };
61 
62 
63  //= IFocusObserver
64 
66  {
67  public:
68  virtual void contextMenuRequested() = 0;
69 
70  protected:
72  };
73 
76  {
77  private:
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
86  // so we need an additional boolean flag telling whether the active control
87  // is really focused
88 #endif
91 
92  // listening at all controls of the active controller for focus changes
94  typedef ::std::vector< FocusListenerAdapter > FocusListenerAdapters;
95  FocusListenerAdapters m_aControlObservers;
96 
98  MouseListenerAdapter m_aContextMenuObserver;
99 
100  // translating between "slots" of the framework and "features" of the active control
102  typedef ::std::map< SfxSlotId, ControlFeature > ControlFeatures;
103  ControlFeatures m_aControlFeatures;
104 
106  // invalidating slots
111 
112  public:
113  FmTextControlShell( SfxViewFrame* _pFrame );
114  virtual ~FmTextControlShell();
115 
116  // clean up any resources associated with this instance
117  void dispose();
118 
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; }
124 
127  void formActivated( const css::uno::Reference< css::form::runtime::XFormController >& _rxController );
130  void formDeactivated( const css::uno::Reference< css::form::runtime::XFormController >& _rxController );
131 
134  void designModeChanged();
135 
136  void Invalidate( SfxSlotId _nSlot );
137 
138  protected:
139  // IFocusObserver
140  virtual void focusGained( const css::awt::FocusEvent& _rEvent ) override;
141  virtual void focusLost( const css::awt::FocusEvent& _rEvent ) override;
142 
143  // IContextRequestObserver
144  virtual void contextMenuRequested() override;
145 
147  void executeAttributeDialog( AttributeSet _eSet, SfxRequest& _rReq );
148  void executeSelectAll( );
149  void executeClipboardSlot( SfxSlotId _nSlot );
150 
151  private:
152  bool isControllerListening() const { return !m_aControlObservers.empty(); }
153 
156  const css::uno::Reference< css::frame::XDispatchProvider >& _rxProvider,
157  SfxApplication const * _pApplication,
158  SfxSlotId _nSlot
159  );
160 
161  // fills the given structure with dispatchers for the given slots, for the given control
163  const css::uno::Reference< css::awt::XControl >& _rxControl,
164  SfxSlotId* _pZeroTerminatedSlots,
165  ControlFeatures& _rDispatchers
166  );
167 
169  static void transferFeatureStatesToItemSet(
170  ControlFeatures& _rDispatchers,
171  SfxAllItemSet& _rSet,
172  bool _bTranslateLatin
173  );
174 
176  void controlActivated( const css::uno::Reference< css::awt::XControl >& _rxControl );
178  void controlDeactivated( );
179 
181 
186  void startControllerListening( const css::uno::Reference< css::form::runtime::XFormController >& _rxController );
191  void stopControllerListening( );
192 
193  DECL_LINK( OnInvalidateClipboard, Timer*, void );
194  };
195 
196 
197 }
198 
199 
200 #endif // INCLUDED_SVX_SOURCE_INC_FMTEXTCONTROLSHELL_HXX
201 
202 /* 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