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