1*3334a7e6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*3334a7e6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*3334a7e6SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*3334a7e6SAndrew Rist * distributed with this work for additional information 6*3334a7e6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*3334a7e6SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*3334a7e6SAndrew Rist * "License"); you may not use this file except in compliance 9*3334a7e6SAndrew Rist * with the License. You may obtain a copy of the License at 10*3334a7e6SAndrew Rist * 11*3334a7e6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*3334a7e6SAndrew Rist * 13*3334a7e6SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*3334a7e6SAndrew Rist * software distributed under the License is distributed on an 15*3334a7e6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*3334a7e6SAndrew Rist * KIND, either express or implied. See the License for the 17*3334a7e6SAndrew Rist * specific language governing permissions and limitations 18*3334a7e6SAndrew Rist * under the License. 19*3334a7e6SAndrew Rist * 20*3334a7e6SAndrew Rist *************************************************************/ 21*3334a7e6SAndrew Rist 22*3334a7e6SAndrew Rist 23cdf0e10cSrcweir #ifndef SVX_SOURCE_INC_FMTEXTCONTROLSHELL_HXX 24cdf0e10cSrcweir #define SVX_SOURCE_INC_FMTEXTCONTROLSHELL_HXX 25cdf0e10cSrcweir 26cdf0e10cSrcweir /** === begin UNO includes === **/ 27cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp> 28cdf0e10cSrcweir #include <com/sun/star/awt/XTextComponent.hpp> 29cdf0e10cSrcweir #include <com/sun/star/frame/XStatusListener.hpp> 30cdf0e10cSrcweir #include <com/sun/star/awt/XFocusListener.hpp> 31cdf0e10cSrcweir #include <com/sun/star/awt/XMouseListener.hpp> 32cdf0e10cSrcweir #include <com/sun/star/form/runtime/XFormController.hpp> 33cdf0e10cSrcweir #include <com/sun/star/awt/XControl.hpp> 34cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp> 35cdf0e10cSrcweir /** === end UNO includes === **/ 36cdf0e10cSrcweir #include <comphelper/implementationreference.hxx> 37cdf0e10cSrcweir #include <tools/link.hxx> 38cdf0e10cSrcweir #include <vcl/timer.hxx> 39cdf0e10cSrcweir #include "fmslotinvalidator.hxx" 40cdf0e10cSrcweir 41cdf0e10cSrcweir #include <vector> 42cdf0e10cSrcweir #include <map> 43cdf0e10cSrcweir 44cdf0e10cSrcweir class SfxRequest; 45cdf0e10cSrcweir class SfxItemSet; 46cdf0e10cSrcweir class SfxAllItemSet; 47cdf0e10cSrcweir class SfxBindings; 48cdf0e10cSrcweir class SfxViewFrame; 49cdf0e10cSrcweir class Window; 50cdf0e10cSrcweir class SfxApplication; 51cdf0e10cSrcweir 52cdf0e10cSrcweir //........................................................................ 53cdf0e10cSrcweir namespace svx 54cdf0e10cSrcweir { 55cdf0e10cSrcweir //........................................................................ 56cdf0e10cSrcweir 57cdf0e10cSrcweir class FmFocusListenerAdapter; 58cdf0e10cSrcweir class FmTextControlFeature; 59cdf0e10cSrcweir class FmMouseListenerAdapter; 60cdf0e10cSrcweir 61cdf0e10cSrcweir //==================================================================== 62cdf0e10cSrcweir //= IFocusObserver 63cdf0e10cSrcweir //==================================================================== 64cdf0e10cSrcweir class IFocusObserver 65cdf0e10cSrcweir { 66cdf0e10cSrcweir public: 67cdf0e10cSrcweir virtual void focusGained( const ::com::sun::star::awt::FocusEvent& _rEvent ) = 0; 68cdf0e10cSrcweir virtual void focusLost( const ::com::sun::star::awt::FocusEvent& _rEvent ) = 0; 69cdf0e10cSrcweir }; 70cdf0e10cSrcweir 71cdf0e10cSrcweir //==================================================================== 72cdf0e10cSrcweir //= IFocusObserver 73cdf0e10cSrcweir //==================================================================== 74cdf0e10cSrcweir class IContextRequestObserver 75cdf0e10cSrcweir { 76cdf0e10cSrcweir public: 77cdf0e10cSrcweir virtual void contextMenuRequested( const ::com::sun::star::awt::MouseEvent& _rEvent ) = 0; 78cdf0e10cSrcweir }; 79cdf0e10cSrcweir 80cdf0e10cSrcweir //==================================================================== 81cdf0e10cSrcweir //= FmTextControlShell 82cdf0e10cSrcweir //==================================================================== 83cdf0e10cSrcweir class FmTextControlShell :public IFocusObserver 84cdf0e10cSrcweir ,public ISlotInvalidator 85cdf0e10cSrcweir ,public IContextRequestObserver 86cdf0e10cSrcweir { 87cdf0e10cSrcweir private: 88cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer > m_xURLTransformer; 89cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > m_xActiveControl; 90cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextComponent > m_xActiveTextComponent; 91cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > m_xActiveController; 92cdf0e10cSrcweir #ifndef DONT_REMEMBER_LAST_CONTROL 93cdf0e10cSrcweir // without this define, m_xActiveControl remembers the *last* active control, even 94cdf0e10cSrcweir // if it, in the meantime, already lost the focus 95cdf0e10cSrcweir bool m_bActiveControl; 96cdf0e10cSrcweir // so we need an additional boolean flag telling whether the active cotrol 97cdf0e10cSrcweir // is really focused 98cdf0e10cSrcweir #endif 99cdf0e10cSrcweir bool m_bActiveControlIsReadOnly; 100cdf0e10cSrcweir bool m_bActiveControlIsRichText; 101cdf0e10cSrcweir 102cdf0e10cSrcweir // listening at all controls of the active controller for focus changes 103cdf0e10cSrcweir typedef ::comphelper::ImplementationReference< FmFocusListenerAdapter, ::com::sun::star::awt::XFocusListener > 104cdf0e10cSrcweir FocusListenerAdapter; 105cdf0e10cSrcweir typedef ::std::vector< FocusListenerAdapter > FocusListenerAdapters; 106cdf0e10cSrcweir FocusListenerAdapters m_aControlObservers; 107cdf0e10cSrcweir 108cdf0e10cSrcweir typedef ::comphelper::ImplementationReference< FmMouseListenerAdapter, ::com::sun::star::awt::XMouseListener > 109cdf0e10cSrcweir MouseListenerAdapter; 110cdf0e10cSrcweir MouseListenerAdapter m_aContextMenuObserver; 111cdf0e10cSrcweir 112cdf0e10cSrcweir // translating between "slots" of the framework and "features" of the active control 113cdf0e10cSrcweir typedef ::comphelper::ImplementationReference< FmTextControlFeature, ::com::sun::star::frame::XStatusListener > 114cdf0e10cSrcweir ControlFeature; 115cdf0e10cSrcweir typedef ::std::map< SfxSlotId, ControlFeature, ::std::less< SfxSlotId > > ControlFeatures; 116cdf0e10cSrcweir ControlFeatures m_aControlFeatures; 117cdf0e10cSrcweir 118cdf0e10cSrcweir SfxViewFrame* m_pViewFrame; 119cdf0e10cSrcweir // invalidating slots 120cdf0e10cSrcweir SfxBindings& m_rBindings; 121cdf0e10cSrcweir Link m_aControlActivationHandler; 122cdf0e10cSrcweir AutoTimer m_aClipboardInvalidation; 123cdf0e10cSrcweir bool m_bNeedClipboardInvalidation; 124cdf0e10cSrcweir 125cdf0e10cSrcweir public: 126cdf0e10cSrcweir FmTextControlShell( SfxViewFrame* _pFrame ); 127cdf0e10cSrcweir virtual ~FmTextControlShell(); 128cdf0e10cSrcweir 129cdf0e10cSrcweir // clean up any resources associated with this instance 130cdf0e10cSrcweir void dispose(); 131cdf0e10cSrcweir 132cdf0e10cSrcweir void ExecuteTextAttribute( SfxRequest& _rReq ); 133cdf0e10cSrcweir void GetTextAttributeState( SfxItemSet& _rSet ); 134cdf0e10cSrcweir bool IsActiveControl( bool _bCountRichTextOnly = false ) const; 135cdf0e10cSrcweir void ForgetActiveControl(); SetControlActivationHandler(const Link & _rHdl)136cdf0e10cSrcweir void SetControlActivationHandler( const Link& _rHdl ) { m_aControlActivationHandler = _rHdl; } 137cdf0e10cSrcweir 138cdf0e10cSrcweir /** to be called when a form in our document has been activated 139cdf0e10cSrcweir */ 140cdf0e10cSrcweir void formActivated( const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController ); 141cdf0e10cSrcweir /** to be called when a form in our document has been deactivated 142cdf0e10cSrcweir */ 143cdf0e10cSrcweir void formDeactivated( const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController ); 144cdf0e10cSrcweir 145cdf0e10cSrcweir /** notifies the instance that the design mode has changed 146cdf0e10cSrcweir */ 147cdf0e10cSrcweir void designModeChanged( bool _bNewDesignMode ); 148cdf0e10cSrcweir 149cdf0e10cSrcweir protected: 150cdf0e10cSrcweir // IFocusObserver 151cdf0e10cSrcweir virtual void focusGained( const ::com::sun::star::awt::FocusEvent& _rEvent ); 152cdf0e10cSrcweir virtual void focusLost( const ::com::sun::star::awt::FocusEvent& _rEvent ); 153cdf0e10cSrcweir 154cdf0e10cSrcweir // IContextRequestObserver 155cdf0e10cSrcweir virtual void contextMenuRequested( const ::com::sun::star::awt::MouseEvent& _rEvent ); 156cdf0e10cSrcweir 157cdf0e10cSrcweir // ISlotInvalidator 158cdf0e10cSrcweir virtual void Invalidate( SfxSlotId _nSlot ); 159cdf0e10cSrcweir 160cdf0e10cSrcweir protected: 161cdf0e10cSrcweir enum AttributeSet { eCharAttribs, eParaAttribs }; 162cdf0e10cSrcweir void executeAttributeDialog( AttributeSet _eSet, SfxRequest& _rReq ); 163cdf0e10cSrcweir bool executeSelectAll( ); 164cdf0e10cSrcweir bool executeClipboardSlot( SfxSlotId _nSlot ); 165cdf0e10cSrcweir 166cdf0e10cSrcweir private: isControllerListening() const167cdf0e10cSrcweir inline bool isControllerListening() const { return !m_aControlObservers.empty(); } 168cdf0e10cSrcweir 169cdf0e10cSrcweir FmTextControlFeature* 170cdf0e10cSrcweir implGetFeatureDispatcher( 171cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& _rxProvider, 172cdf0e10cSrcweir SfxApplication* _pApplication, 173cdf0e10cSrcweir SfxSlotId _nSlot 174cdf0e10cSrcweir ); 175cdf0e10cSrcweir 176cdf0e10cSrcweir // fills the given structure with dispatchers for the given slots, for the given control 177cdf0e10cSrcweir void fillFeatureDispatchers( 178cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > _rxControl, 179cdf0e10cSrcweir SfxSlotId* _pZeroTerminatedSlots, 180cdf0e10cSrcweir ControlFeatures& _rDispatchers 181cdf0e10cSrcweir ); 182cdf0e10cSrcweir 183cdf0e10cSrcweir /// creates SfxPoolItes for all features in the given set, and puts them into the given SfxAllItemSet 184cdf0e10cSrcweir void transferFeatureStatesToItemSet( 185cdf0e10cSrcweir ControlFeatures& _rDispatchers, 186cdf0e10cSrcweir SfxAllItemSet& _rSet, 187cdf0e10cSrcweir bool _bTranslateLatin = false 188cdf0e10cSrcweir ); 189cdf0e10cSrcweir 190cdf0e10cSrcweir /// to be called when a control has been activated 191cdf0e10cSrcweir void controlActivated( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl ); 192cdf0e10cSrcweir /// to be called when the currently active control has been deactivated 193cdf0e10cSrcweir void controlDeactivated( ); 194cdf0e10cSrcweir 195cdf0e10cSrcweir void implClearActiveControlRef(); 196cdf0e10cSrcweir 197cdf0e10cSrcweir /** starts listening at all controls of the given controller for focus events 198cdf0e10cSrcweir @precond 199cdf0e10cSrcweir we don't have an active controller currently 200cdf0e10cSrcweir */ 201cdf0e10cSrcweir void startControllerListening( const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController ); 202cdf0e10cSrcweir /** stops listening at the active controller 203cdf0e10cSrcweir @precond 204cdf0e10cSrcweir we have an active controller currently 205cdf0e10cSrcweir */ 206cdf0e10cSrcweir void stopControllerListening( ); 207cdf0e10cSrcweir 208cdf0e10cSrcweir /** parses the given URL's Complete member, by calling XURLTransformer::parseString 209cdf0e10cSrcweir */ 210cdf0e10cSrcweir void impl_parseURL_nothrow( ::com::sun::star::util::URL& _rURL ); 211cdf0e10cSrcweir 212cdf0e10cSrcweir DECL_LINK( OnInvalidateClipboard, void* ); 213cdf0e10cSrcweir }; 214cdf0e10cSrcweir 215cdf0e10cSrcweir //........................................................................ 216cdf0e10cSrcweir } // namespace svx 217cdf0e10cSrcweir //........................................................................ 218cdf0e10cSrcweir 219cdf0e10cSrcweir #endif // SVX_SOURCE_INC_FMTEXTCONTROLSHELL_HXX 220cdf0e10cSrcweir 221