merge the formfield patch from ooo-build
[ooovba.git] / svx / source / inc / fmcontrolbordermanager.hxx
blob51c426b4872c21962dde507cdf6ce3a65aea954a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fmcontrolbordermanager.hxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SVX_SOURCE_INC_FMCONTROLBORDERMANAGER_HXX
32 #define SVX_SOURCE_INC_FMCONTROLBORDERMANAGER_HXX
34 /** === begin UNO includes === **/
35 #include <com/sun/star/awt/VisualEffect.hpp>
36 #include <com/sun/star/awt/FontUnderline.hpp>
37 #include <com/sun/star/awt/XControl.hpp>
38 #include <com/sun/star/awt/XVclWindowPeer.hpp>
39 /** === end UNO includes === **/
40 #include <comphelper/stl_types.hxx>
41 #include <comphelper/stl_types.hxx>
43 #include <set>
45 namespace com { namespace sun { namespace star { namespace form { namespace validation {
46 class XValidatableFormComponent;
47 } } } } }
49 //........................................................................
50 namespace svxform
52 //........................................................................
54 typedef sal_Int16 ControlStatus;
56 #define CONTROL_STATUS_NONE 0x00
57 #define CONTROL_STATUS_FOCUSED 0x01
58 #define CONTROL_STATUS_MOUSE_HOVER 0x02
59 #define CONTROL_STATUS_INVALID 0x04
61 //====================================================================
62 //= BorderDescriptor
63 //====================================================================
64 struct BorderDescriptor
66 sal_Int16 nBorderType;
67 sal_Int32 nBorderColor;
69 BorderDescriptor()
70 :nBorderType( ::com::sun::star::awt::VisualEffect::FLAT )
71 ,nBorderColor( 0x00000000 )
74 inline void clear()
76 nBorderType = ::com::sun::star::awt::VisualEffect::FLAT;
77 nBorderColor = 0x00000000;
81 //====================================================================
82 //= UnderlineDescriptor
83 //====================================================================
84 struct UnderlineDescriptor
86 sal_Int16 nUnderlineType;
87 sal_Int32 nUnderlineColor;
89 UnderlineDescriptor()
90 :nUnderlineType( ::com::sun::star::awt::FontUnderline::NONE )
91 ,nUnderlineColor( 0x00000000 )
95 UnderlineDescriptor( sal_Int16 _nUnderlineType, sal_Int32 _nUnderlineColor )
96 :nUnderlineType( _nUnderlineType )
97 ,nUnderlineColor( _nUnderlineColor )
101 inline void clear()
103 nUnderlineType = ::com::sun::star::awt::FontUnderline::NONE;
104 nUnderlineColor = 0x00000000;
108 //====================================================================
109 //= ControlData
110 //====================================================================
111 struct ControlData : public BorderDescriptor, UnderlineDescriptor
113 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > xControl;
114 ::rtl::OUString sOriginalHelpText;
116 ControlData() : BorderDescriptor() { }
117 ControlData( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl )
118 :xControl( _rxControl )
121 void clear()
123 BorderDescriptor::clear();
124 UnderlineDescriptor::clear();
125 xControl.clear();
126 sOriginalHelpText = ::rtl::OUString();
130 //====================================================================
131 //= ControlBorderManager
132 //====================================================================
133 /** manages the dynamic border color for form controls
135 Used by the <type>FmXFormController</type>, this class manages the dynamic changes in the
136 border color of form controls. For this a set of events have to be forwarded to the manager
137 instance, which then will switch the border color depending on the mouse and focus status
138 of the controls.
140 class ControlBorderManager
142 private:
143 struct ControlDataCompare : public ::std::binary_function< ControlData, ControlData, bool >
145 bool operator()( const ControlData& _rLHS, const ControlData& _rRHS ) const
147 return _rLHS.xControl.get() < _rRHS.xControl.get();
151 typedef ::std::set< ControlData, ControlDataCompare > ControlBag;
152 typedef ::com::sun::star::awt::XVclWindowPeer WindowPeer;
153 typedef ::com::sun::star::uno::Reference< ::com::sun::star::awt::XVclWindowPeer > WindowPeerRef;
154 typedef ::std::set< WindowPeerRef, ::comphelper::OInterfaceCompare< WindowPeer > > PeerBag;
156 PeerBag m_aColorableControls;
157 PeerBag m_aNonColorableControls;
159 ControlData m_aFocusControl;
160 ControlData m_aMouseHoverControl;
161 ControlBag m_aInvalidControls;
163 // ----------------
164 // attributes
165 sal_Int32 m_nFocusColor;
166 sal_Int32 m_nMouseHoveColor;
167 sal_Int32 m_nInvalidColor;
168 bool m_bDynamicBorderColors;
170 public:
171 ControlBorderManager();
172 ~ControlBorderManager();
174 public:
175 void focusGained( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxControl ) SAL_THROW(());
176 void focusLost( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxControl ) SAL_THROW(());
177 void mouseEntered( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxControl ) SAL_THROW(());
178 void mouseExited( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxControl ) SAL_THROW(());
180 void validityChanged(
181 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl,
182 const ::com::sun::star::uno::Reference< ::com::sun::star::form::validation::XValidatableFormComponent >& _rxValidatable
183 ) SAL_THROW(());
185 /// enables dynamic border color for the controls
186 void enableDynamicBorderColor( );
187 /// disables dynamic border color for the controls
188 void disableDynamicBorderColor( );
190 /** sets a color to be used for a given status
191 @param _nStatus
192 the status which the color should be applied for. Must not be CONTROL_STATUS_NONE
193 @param _nColor
194 the color to apply for the given status
196 void setStatusColor( ControlStatus _nStatus, sal_Int32 _nColor );
198 /** restores all colors of all controls where we possibly changed them
200 void restoreAll();
202 private:
203 /** called when a control got one of the two possible stati (focused, and hovered with the mouse)
204 @param _rxControl
205 the control which gained the status
206 @param _rControlData
207 the control's status data, as a reference to our respective member
209 void controlStatusGained(
210 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxControl,
211 ControlData& _rControlData
212 ) SAL_THROW(());
214 /** called when a control lost one of the two possible stati (focused, and hovered with the mouse)
215 @param _rxControl
216 the control which lost the status
217 @param _rControlData
218 the control's status data, as a reference to our respective member
220 void controlStatusLost( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxControl, ControlData& _rControlData ) SAL_THROW(());
222 /** determines whether the border of a given peer can be colored
223 @param _rxPeer
224 the peer to examine. Must not be <NULL/>
226 bool canColorBorder( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XVclWindowPeer >& _rxPeer );
228 /** determines the status of the given control
230 ControlStatus getControlStatus( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl ) SAL_THROW(());
232 /** retrieves the color associated with a given ControlStatus
233 @param _eStatus
234 the status of the control. Must not be <member>ControlStatus::none</member>
236 sal_Int32 getControlColorByStatus( ControlStatus _eStatus );
238 /** sets the border color for a given control, depending on its status
239 @param _rxControl
240 the control to set the border color for. Must not be <NULL/>
241 @param _rxPeer
242 the peer of the control, to be passed herein for optimization the caller usually needs it, anyway).
243 Must not be <NULL/>
244 @param _rFallback
245 the color/type to use when the control has the status CONTROL_STATUS_NONE
247 void updateBorderStyle(
248 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl,
249 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XVclWindowPeer >& _rxPeer,
250 const BorderDescriptor& _rFallback
251 ) SAL_THROW(());
253 /** determines the to-be-remembered original border color and type for a control
255 The method also takes into account that the control may currently have an overwritten
256 border style
258 @param _rxControl
259 the control to examine. Must not be <NULL/>, and have a non-<NULL/> peer
261 void determineOriginalBorderStyle(
262 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl,
263 BorderDescriptor& _rData
264 ) const;
267 //........................................................................
268 } // namespace svxform
269 //........................................................................
271 #endif // SVX_SOURCE_INC_FMCONTROLBORDERMANAGER_HXX