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