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