1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #ifndef SVX_SOURCE_INC_FMCONTROLBORDERMANAGER_HXX
30 #define SVX_SOURCE_INC_FMCONTROLBORDERMANAGER_HXX
32 /** === begin UNO includes === **/
33 #include <com/sun/star/awt/VisualEffect.hpp>
34 #include <com/sun/star/awt/FontUnderline.hpp>
35 #include <com/sun/star/awt/XControl.hpp>
36 #include <com/sun/star/awt/XVclWindowPeer.hpp>
37 /** === end UNO includes === **/
38 #include <comphelper/stl_types.hxx>
42 namespace com
{ namespace sun
{ namespace star
{ namespace form
{ namespace validation
{
43 class XValidatableFormComponent
;
46 //........................................................................
49 //........................................................................
51 typedef sal_Int16 ControlStatus
;
53 #define CONTROL_STATUS_NONE 0x00
54 #define CONTROL_STATUS_FOCUSED 0x01
55 #define CONTROL_STATUS_MOUSE_HOVER 0x02
56 #define CONTROL_STATUS_INVALID 0x04
58 //====================================================================
60 //====================================================================
61 struct BorderDescriptor
63 sal_Int16 nBorderType
;
64 sal_Int32 nBorderColor
;
67 :nBorderType( ::com::sun::star::awt::VisualEffect::FLAT
)
68 ,nBorderColor( 0x00000000 )
73 nBorderType
= ::com::sun::star::awt::VisualEffect::FLAT
;
74 nBorderColor
= 0x00000000;
78 //====================================================================
79 //= UnderlineDescriptor
80 //====================================================================
81 struct UnderlineDescriptor
83 sal_Int16 nUnderlineType
;
84 sal_Int32 nUnderlineColor
;
87 :nUnderlineType( ::com::sun::star::awt::FontUnderline::NONE
)
88 ,nUnderlineColor( 0x00000000 )
92 UnderlineDescriptor( sal_Int16 _nUnderlineType
, sal_Int32 _nUnderlineColor
)
93 :nUnderlineType( _nUnderlineType
)
94 ,nUnderlineColor( _nUnderlineColor
)
100 nUnderlineType
= ::com::sun::star::awt::FontUnderline::NONE
;
101 nUnderlineColor
= 0x00000000;
105 //====================================================================
107 //====================================================================
108 struct ControlData
: public BorderDescriptor
, UnderlineDescriptor
110 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControl
> xControl
;
111 ::rtl::OUString sOriginalHelpText
;
113 ControlData() : BorderDescriptor() { }
114 ControlData( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControl
>& _rxControl
)
115 :xControl( _rxControl
)
120 BorderDescriptor::clear();
121 UnderlineDescriptor::clear();
123 sOriginalHelpText
= ::rtl::OUString();
127 //====================================================================
128 //= ControlBorderManager
129 //====================================================================
130 /** manages the dynamic border color for form controls
132 Used by the <type>FormController</type>, this class manages the dynamic changes in the
133 border color of form controls. For this a set of events have to be forwarded to the manager
134 instance, which then will switch the border color depending on the mouse and focus status
137 class ControlBorderManager
140 struct ControlDataCompare
: public ::std::binary_function
< ControlData
, ControlData
, bool >
142 bool operator()( const ControlData
& _rLHS
, const ControlData
& _rRHS
) const
144 return _rLHS
.xControl
.get() < _rRHS
.xControl
.get();
148 typedef ::std::set
< ControlData
, ControlDataCompare
> ControlBag
;
149 typedef ::com::sun::star::awt::XVclWindowPeer WindowPeer
;
150 typedef ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XVclWindowPeer
> WindowPeerRef
;
151 typedef ::std::set
< WindowPeerRef
, ::comphelper::OInterfaceCompare
< WindowPeer
> > PeerBag
;
153 PeerBag m_aColorableControls
;
154 PeerBag m_aNonColorableControls
;
156 ControlData m_aFocusControl
;
157 ControlData m_aMouseHoverControl
;
158 ControlBag m_aInvalidControls
;
162 sal_Int32 m_nFocusColor
;
163 sal_Int32 m_nMouseHoveColor
;
164 sal_Int32 m_nInvalidColor
;
165 bool m_bDynamicBorderColors
;
168 ControlBorderManager();
169 ~ControlBorderManager();
172 void focusGained( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _rxControl
) SAL_THROW(());
173 void focusLost( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _rxControl
) SAL_THROW(());
174 void mouseEntered( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _rxControl
) SAL_THROW(());
175 void mouseExited( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _rxControl
) SAL_THROW(());
177 void validityChanged(
178 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControl
>& _rxControl
,
179 const ::com::sun::star::uno::Reference
< ::com::sun::star::form::validation::XValidatableFormComponent
>& _rxValidatable
182 /// enables dynamic border color for the controls
183 void enableDynamicBorderColor( );
184 /// disables dynamic border color for the controls
185 void disableDynamicBorderColor( );
187 /** sets a color to be used for a given status
189 the status which the color should be applied for. Must not be CONTROL_STATUS_NONE
191 the color to apply for the given status
193 void setStatusColor( ControlStatus _nStatus
, sal_Int32 _nColor
);
195 /** restores all colors of all controls where we possibly changed them
200 /** called when a control got one of the two possible stati (focused, and hovered with the mouse)
202 the control which gained the status
204 the control's status data, as a reference to our respective member
206 void controlStatusGained(
207 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _rxControl
,
208 ControlData
& _rControlData
211 /** called when a control lost one of the two possible stati (focused, and hovered with the mouse)
213 the control which lost the status
215 the control's status data, as a reference to our respective member
217 void controlStatusLost( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _rxControl
, ControlData
& _rControlData
) SAL_THROW(());
219 /** determines whether the border of a given peer can be colored
221 the peer to examine. Must not be <NULL/>
223 bool canColorBorder( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XVclWindowPeer
>& _rxPeer
);
225 /** determines the status of the given control
227 ControlStatus
getControlStatus( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControl
>& _rxControl
) SAL_THROW(());
229 /** retrieves the color associated with a given ControlStatus
231 the status of the control. Must not be <member>ControlStatus::none</member>
233 sal_Int32
getControlColorByStatus( ControlStatus _eStatus
);
235 /** sets the border color for a given control, depending on its status
237 the control to set the border color for. Must not be <NULL/>
239 the peer of the control, to be passed herein for optimization the caller usually needs it, anyway).
242 the color/type to use when the control has the status CONTROL_STATUS_NONE
244 void updateBorderStyle(
245 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControl
>& _rxControl
,
246 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XVclWindowPeer
>& _rxPeer
,
247 const BorderDescriptor
& _rFallback
250 /** determines the to-be-remembered original border color and type for a control
252 The method also takes into account that the control may currently have an overwritten
256 the control to examine. Must not be <NULL/>, and have a non-<NULL/> peer
258 void determineOriginalBorderStyle(
259 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControl
>& _rxControl
,
260 BorderDescriptor
& _rData
264 //........................................................................
265 } // namespace svxform
266 //........................................................................
268 #endif // SVX_SOURCE_INC_FMCONTROLBORDERMANAGER_HXX
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */