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 53 class IFocusObserver 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: ~IFocusObserver()60 ~IFocusObserver() {} 61 }; 62 63 64 //= IFocusObserver 65 66 class IContextRequestObserver 67 { 68 public: 69 virtual void contextMenuRequested() = 0; 70 71 protected: ~IContextRequestObserver()72 ~IContextRequestObserver() {} 73 }; 74 75 class FmTextControlShell :public IFocusObserver 76 ,public IContextRequestObserver 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 86 bool m_bActiveControl; 87 // so we need an additional boolean flag telling whether the active control 88 // is really focused 89 #endif 90 bool m_bActiveControlIsReadOnly; 91 bool m_bActiveControlIsRichText; 92 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; 97 98 typedef rtl::Reference<FmMouseListenerAdapter> MouseListenerAdapter; 99 MouseListenerAdapter m_aContextMenuObserver; 100 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; 105 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; 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(); SetControlActivationHandler(const Link<LinkParamNone *,void> & _rHdl)124 void SetControlActivationHandler( const Link<LinkParamNone*,void>& _rHdl ) { m_aControlActivationHandler = _rHdl; } 125 126 /** to be called when a form in our document has been activated 127 */ 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 130 */ 131 void formDeactivated( const css::uno::Reference< css::form::runtime::XFormController >& _rxController ); 132 133 /** notifies the instance that the design mode has changed 134 */ 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 147 enum AttributeSet { eCharAttribs, eParaAttribs }; 148 void executeAttributeDialog( AttributeSet _eSet, SfxRequest& _rReq ); 149 void executeSelectAll( ); 150 void executeClipboardSlot( SfxSlotId _nSlot ); 151 152 private: isControllerListening() const153 bool isControllerListening() const { return !m_aControlObservers.empty(); } 154 155 FmTextControlFeature* 156 implGetFeatureDispatcher( 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 163 void fillFeatureDispatchers( 164 const css::uno::Reference< css::awt::XControl >& _rxControl, 165 SfxSlotId* _pZeroTerminatedSlots, 166 ControlFeatures& _rDispatchers 167 ); 168 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 174 ); 175 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( ); 180 181 void implClearActiveControlRef(); 182 183 /** starts listening at all controls of the given controller for focus events 184 @precond 185 we don't have an active controller currently 186 */ 187 void startControllerListening( const css::uno::Reference< css::form::runtime::XFormController >& _rxController ); 188 /** stops listening at the active controller 189 @precond 190 we have an active controller currently 191 */ 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: */ 204