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 24cdf0e10cSrcweir #ifndef SVX_SOURCE_INC_FMCONTROLBORDERMANAGER_HXX 25cdf0e10cSrcweir #define SVX_SOURCE_INC_FMCONTROLBORDERMANAGER_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir /** === begin UNO includes === **/ 28cdf0e10cSrcweir #include <com/sun/star/awt/VisualEffect.hpp> 29cdf0e10cSrcweir #include <com/sun/star/awt/FontUnderline.hpp> 30cdf0e10cSrcweir #include <com/sun/star/awt/XControl.hpp> 31cdf0e10cSrcweir #include <com/sun/star/awt/XVclWindowPeer.hpp> 32cdf0e10cSrcweir /** === end UNO includes === **/ 33cdf0e10cSrcweir #include <comphelper/stl_types.hxx> 34cdf0e10cSrcweir #include <comphelper/stl_types.hxx> 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include <set> 37cdf0e10cSrcweir 38cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace form { namespace validation { 39cdf0e10cSrcweir class XValidatableFormComponent; 40cdf0e10cSrcweir } } } } } 41cdf0e10cSrcweir 42cdf0e10cSrcweir //........................................................................ 43cdf0e10cSrcweir namespace svxform 44cdf0e10cSrcweir { 45cdf0e10cSrcweir //........................................................................ 46cdf0e10cSrcweir 47cdf0e10cSrcweir typedef sal_Int16 ControlStatus; 48cdf0e10cSrcweir 49cdf0e10cSrcweir #define CONTROL_STATUS_NONE 0x00 50cdf0e10cSrcweir #define CONTROL_STATUS_FOCUSED 0x01 51cdf0e10cSrcweir #define CONTROL_STATUS_MOUSE_HOVER 0x02 52cdf0e10cSrcweir #define CONTROL_STATUS_INVALID 0x04 53cdf0e10cSrcweir 54cdf0e10cSrcweir //==================================================================== 55cdf0e10cSrcweir //= BorderDescriptor 56cdf0e10cSrcweir //==================================================================== 57cdf0e10cSrcweir struct BorderDescriptor 58cdf0e10cSrcweir { 59cdf0e10cSrcweir sal_Int16 nBorderType; 60cdf0e10cSrcweir sal_Int32 nBorderColor; 61cdf0e10cSrcweir BorderDescriptorsvxform::BorderDescriptor62cdf0e10cSrcweir BorderDescriptor() 63cdf0e10cSrcweir :nBorderType( ::com::sun::star::awt::VisualEffect::FLAT ) 64cdf0e10cSrcweir ,nBorderColor( 0x00000000 ) 65cdf0e10cSrcweir { 66cdf0e10cSrcweir } clearsvxform::BorderDescriptor67cdf0e10cSrcweir inline void clear() 68cdf0e10cSrcweir { 69cdf0e10cSrcweir nBorderType = ::com::sun::star::awt::VisualEffect::FLAT; 70cdf0e10cSrcweir nBorderColor = 0x00000000; 71cdf0e10cSrcweir } 72cdf0e10cSrcweir }; 73cdf0e10cSrcweir 74cdf0e10cSrcweir //==================================================================== 75cdf0e10cSrcweir //= UnderlineDescriptor 76cdf0e10cSrcweir //==================================================================== 77cdf0e10cSrcweir struct UnderlineDescriptor 78cdf0e10cSrcweir { 79cdf0e10cSrcweir sal_Int16 nUnderlineType; 80cdf0e10cSrcweir sal_Int32 nUnderlineColor; 81cdf0e10cSrcweir UnderlineDescriptorsvxform::UnderlineDescriptor82cdf0e10cSrcweir UnderlineDescriptor() 83cdf0e10cSrcweir :nUnderlineType( ::com::sun::star::awt::FontUnderline::NONE ) 84cdf0e10cSrcweir ,nUnderlineColor( 0x00000000 ) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir } 87cdf0e10cSrcweir UnderlineDescriptorsvxform::UnderlineDescriptor88cdf0e10cSrcweir UnderlineDescriptor( sal_Int16 _nUnderlineType, sal_Int32 _nUnderlineColor ) 89cdf0e10cSrcweir :nUnderlineType( _nUnderlineType ) 90cdf0e10cSrcweir ,nUnderlineColor( _nUnderlineColor ) 91cdf0e10cSrcweir { 92cdf0e10cSrcweir } 93cdf0e10cSrcweir clearsvxform::UnderlineDescriptor94cdf0e10cSrcweir inline void clear() 95cdf0e10cSrcweir { 96cdf0e10cSrcweir nUnderlineType = ::com::sun::star::awt::FontUnderline::NONE; 97cdf0e10cSrcweir nUnderlineColor = 0x00000000; 98cdf0e10cSrcweir } 99cdf0e10cSrcweir }; 100cdf0e10cSrcweir 101cdf0e10cSrcweir //==================================================================== 102cdf0e10cSrcweir //= ControlData 103cdf0e10cSrcweir //==================================================================== 104cdf0e10cSrcweir struct ControlData : public BorderDescriptor, UnderlineDescriptor 105cdf0e10cSrcweir { 106cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > xControl; 107cdf0e10cSrcweir ::rtl::OUString sOriginalHelpText; 108cdf0e10cSrcweir ControlDatasvxform::ControlData109cdf0e10cSrcweir ControlData() : BorderDescriptor() { } ControlDatasvxform::ControlData110cdf0e10cSrcweir ControlData( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl ) 111cdf0e10cSrcweir :xControl( _rxControl ) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir } clearsvxform::ControlData114cdf0e10cSrcweir void clear() 115cdf0e10cSrcweir { 116cdf0e10cSrcweir BorderDescriptor::clear(); 117cdf0e10cSrcweir UnderlineDescriptor::clear(); 118cdf0e10cSrcweir xControl.clear(); 119cdf0e10cSrcweir sOriginalHelpText = ::rtl::OUString(); 120cdf0e10cSrcweir } 121cdf0e10cSrcweir }; 122cdf0e10cSrcweir 123cdf0e10cSrcweir //==================================================================== 124cdf0e10cSrcweir //= ControlBorderManager 125cdf0e10cSrcweir //==================================================================== 126cdf0e10cSrcweir /** manages the dynamic border color for form controls 127cdf0e10cSrcweir 128cdf0e10cSrcweir Used by the <type>FormController</type>, this class manages the dynamic changes in the 129cdf0e10cSrcweir border color of form controls. For this a set of events have to be forwarded to the manager 130cdf0e10cSrcweir instance, which then will switch the border color depending on the mouse and focus status 131cdf0e10cSrcweir of the controls. 132cdf0e10cSrcweir */ 133cdf0e10cSrcweir class ControlBorderManager 134cdf0e10cSrcweir { 135cdf0e10cSrcweir private: 136cdf0e10cSrcweir struct ControlDataCompare : public ::std::binary_function< ControlData, ControlData, bool > 137cdf0e10cSrcweir { operator ()svxform::ControlBorderManager::ControlDataCompare138cdf0e10cSrcweir bool operator()( const ControlData& _rLHS, const ControlData& _rRHS ) const 139cdf0e10cSrcweir { 140cdf0e10cSrcweir return _rLHS.xControl.get() < _rRHS.xControl.get(); 141cdf0e10cSrcweir } 142cdf0e10cSrcweir }; 143cdf0e10cSrcweir 144cdf0e10cSrcweir typedef ::std::set< ControlData, ControlDataCompare > ControlBag; 145cdf0e10cSrcweir typedef ::com::sun::star::awt::XVclWindowPeer WindowPeer; 146cdf0e10cSrcweir typedef ::com::sun::star::uno::Reference< ::com::sun::star::awt::XVclWindowPeer > WindowPeerRef; 147cdf0e10cSrcweir typedef ::std::set< WindowPeerRef, ::comphelper::OInterfaceCompare< WindowPeer > > PeerBag; 148cdf0e10cSrcweir 149cdf0e10cSrcweir PeerBag m_aColorableControls; 150cdf0e10cSrcweir PeerBag m_aNonColorableControls; 151cdf0e10cSrcweir 152cdf0e10cSrcweir ControlData m_aFocusControl; 153cdf0e10cSrcweir ControlData m_aMouseHoverControl; 154cdf0e10cSrcweir ControlBag m_aInvalidControls; 155cdf0e10cSrcweir 156cdf0e10cSrcweir // ---------------- 157cdf0e10cSrcweir // attributes 158cdf0e10cSrcweir sal_Int32 m_nFocusColor; 159cdf0e10cSrcweir sal_Int32 m_nMouseHoveColor; 160cdf0e10cSrcweir sal_Int32 m_nInvalidColor; 161cdf0e10cSrcweir bool m_bDynamicBorderColors; 162cdf0e10cSrcweir 163cdf0e10cSrcweir public: 164cdf0e10cSrcweir ControlBorderManager(); 165cdf0e10cSrcweir ~ControlBorderManager(); 166cdf0e10cSrcweir 167cdf0e10cSrcweir public: 168cdf0e10cSrcweir void focusGained( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxControl ) SAL_THROW(()); 169cdf0e10cSrcweir void focusLost( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxControl ) SAL_THROW(()); 170cdf0e10cSrcweir void mouseEntered( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxControl ) SAL_THROW(()); 171cdf0e10cSrcweir void mouseExited( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxControl ) SAL_THROW(()); 172cdf0e10cSrcweir 173cdf0e10cSrcweir void validityChanged( 174cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl, 175cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::form::validation::XValidatableFormComponent >& _rxValidatable 176cdf0e10cSrcweir ) SAL_THROW(()); 177cdf0e10cSrcweir 178cdf0e10cSrcweir /// enables dynamic border color for the controls 179cdf0e10cSrcweir void enableDynamicBorderColor( ); 180cdf0e10cSrcweir /// disables dynamic border color for the controls 181cdf0e10cSrcweir void disableDynamicBorderColor( ); 182cdf0e10cSrcweir 183cdf0e10cSrcweir /** sets a color to be used for a given status 184cdf0e10cSrcweir @param _nStatus 185cdf0e10cSrcweir the status which the color should be applied for. Must not be CONTROL_STATUS_NONE 186cdf0e10cSrcweir @param _nColor 187cdf0e10cSrcweir the color to apply for the given status 188cdf0e10cSrcweir */ 189cdf0e10cSrcweir void setStatusColor( ControlStatus _nStatus, sal_Int32 _nColor ); 190cdf0e10cSrcweir 191cdf0e10cSrcweir /** restores all colors of all controls where we possibly changed them 192cdf0e10cSrcweir */ 193cdf0e10cSrcweir void restoreAll(); 194cdf0e10cSrcweir 195cdf0e10cSrcweir private: 196cdf0e10cSrcweir /** called when a control got one of the two possible stati (focused, and hovered with the mouse) 197cdf0e10cSrcweir @param _rxControl 198cdf0e10cSrcweir the control which gained the status 199cdf0e10cSrcweir @param _rControlData 200cdf0e10cSrcweir the control's status data, as a reference to our respective member 201cdf0e10cSrcweir */ 202cdf0e10cSrcweir void controlStatusGained( 203cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxControl, 204cdf0e10cSrcweir ControlData& _rControlData 205cdf0e10cSrcweir ) SAL_THROW(()); 206cdf0e10cSrcweir 207cdf0e10cSrcweir /** called when a control lost one of the two possible stati (focused, and hovered with the mouse) 208cdf0e10cSrcweir @param _rxControl 209cdf0e10cSrcweir the control which lost the status 210cdf0e10cSrcweir @param _rControlData 211cdf0e10cSrcweir the control's status data, as a reference to our respective member 212cdf0e10cSrcweir */ 213cdf0e10cSrcweir void controlStatusLost( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxControl, ControlData& _rControlData ) SAL_THROW(()); 214cdf0e10cSrcweir 215cdf0e10cSrcweir /** determines whether the border of a given peer can be colored 216cdf0e10cSrcweir @param _rxPeer 217cdf0e10cSrcweir the peer to examine. Must not be <NULL/> 218cdf0e10cSrcweir */ 219cdf0e10cSrcweir bool canColorBorder( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XVclWindowPeer >& _rxPeer ); 220cdf0e10cSrcweir 221cdf0e10cSrcweir /** determines the status of the given control 222cdf0e10cSrcweir */ 223cdf0e10cSrcweir ControlStatus getControlStatus( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl ) SAL_THROW(()); 224cdf0e10cSrcweir 225cdf0e10cSrcweir /** retrieves the color associated with a given ControlStatus 226cdf0e10cSrcweir @param _eStatus 227cdf0e10cSrcweir the status of the control. Must not be <member>ControlStatus::none</member> 228cdf0e10cSrcweir */ 229cdf0e10cSrcweir sal_Int32 getControlColorByStatus( ControlStatus _eStatus ); 230cdf0e10cSrcweir 231cdf0e10cSrcweir /** sets the border color for a given control, depending on its status 232cdf0e10cSrcweir @param _rxControl 233cdf0e10cSrcweir the control to set the border color for. Must not be <NULL/> 234cdf0e10cSrcweir @param _rxPeer 235cdf0e10cSrcweir the peer of the control, to be passed herein for optimization the caller usually needs it, anyway). 236cdf0e10cSrcweir Must not be <NULL/> 237cdf0e10cSrcweir @param _rFallback 238cdf0e10cSrcweir the color/type to use when the control has the status CONTROL_STATUS_NONE 239cdf0e10cSrcweir */ 240cdf0e10cSrcweir void updateBorderStyle( 241cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl, 242cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XVclWindowPeer >& _rxPeer, 243cdf0e10cSrcweir const BorderDescriptor& _rFallback 244cdf0e10cSrcweir ) SAL_THROW(()); 245cdf0e10cSrcweir 246cdf0e10cSrcweir /** determines the to-be-remembered original border color and type for a control 247cdf0e10cSrcweir 248cdf0e10cSrcweir The method also takes into account that the control may currently have an overwritten 249cdf0e10cSrcweir border style 250cdf0e10cSrcweir 251cdf0e10cSrcweir @param _rxControl 252cdf0e10cSrcweir the control to examine. Must not be <NULL/>, and have a non-<NULL/> peer 253cdf0e10cSrcweir */ 254cdf0e10cSrcweir void determineOriginalBorderStyle( 255cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl, 256cdf0e10cSrcweir BorderDescriptor& _rData 257cdf0e10cSrcweir ) const; 258cdf0e10cSrcweir }; 259cdf0e10cSrcweir 260cdf0e10cSrcweir //........................................................................ 261cdf0e10cSrcweir } // namespace svxform 262cdf0e10cSrcweir //........................................................................ 263cdf0e10cSrcweir 264cdf0e10cSrcweir #endif // SVX_SOURCE_INC_FMCONTROLBORDERMANAGER_HXX 265