bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / inc / fmcontrolbordermanager.hxx
bloba7caef5bbf8cb4c24d8fd2e4acd564c0112da57c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef SVX_SOURCE_INC_FMCONTROLBORDERMANAGER_HXX
21 #define SVX_SOURCE_INC_FMCONTROLBORDERMANAGER_HXX
23 #include <com/sun/star/awt/VisualEffect.hpp>
24 #include <com/sun/star/awt/FontUnderline.hpp>
25 #include <com/sun/star/awt/XControl.hpp>
26 #include <com/sun/star/awt/XVclWindowPeer.hpp>
27 #include <comphelper/stl_types.hxx>
29 #include <set>
31 namespace com { namespace sun { namespace star { namespace form { namespace validation {
32 class XValidatableFormComponent;
33 } } } } }
35 //........................................................................
36 namespace svxform
38 //........................................................................
40 typedef sal_Int16 ControlStatus;
42 #define CONTROL_STATUS_NONE 0x00
43 #define CONTROL_STATUS_FOCUSED 0x01
44 #define CONTROL_STATUS_MOUSE_HOVER 0x02
45 #define CONTROL_STATUS_INVALID 0x04
47 //====================================================================
48 //= BorderDescriptor
49 //====================================================================
50 struct BorderDescriptor
52 sal_Int16 nBorderType;
53 sal_Int32 nBorderColor;
55 BorderDescriptor()
56 :nBorderType( ::com::sun::star::awt::VisualEffect::FLAT )
57 ,nBorderColor( 0x00000000 )
60 inline void clear()
62 nBorderType = ::com::sun::star::awt::VisualEffect::FLAT;
63 nBorderColor = 0x00000000;
67 //====================================================================
68 //= UnderlineDescriptor
69 //====================================================================
70 struct UnderlineDescriptor
72 sal_Int16 nUnderlineType;
73 sal_Int32 nUnderlineColor;
75 UnderlineDescriptor()
76 :nUnderlineType( ::com::sun::star::awt::FontUnderline::NONE )
77 ,nUnderlineColor( 0x00000000 )
81 UnderlineDescriptor( sal_Int16 _nUnderlineType, sal_Int32 _nUnderlineColor )
82 :nUnderlineType( _nUnderlineType )
83 ,nUnderlineColor( _nUnderlineColor )
87 inline void clear()
89 nUnderlineType = ::com::sun::star::awt::FontUnderline::NONE;
90 nUnderlineColor = 0x00000000;
94 //====================================================================
95 //= ControlData
96 //====================================================================
97 struct ControlData : public BorderDescriptor, UnderlineDescriptor
99 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > xControl;
100 OUString sOriginalHelpText;
102 ControlData() : BorderDescriptor() { }
103 ControlData( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl )
104 :xControl( _rxControl )
107 void clear()
109 BorderDescriptor::clear();
110 UnderlineDescriptor::clear();
111 xControl.clear();
112 sOriginalHelpText = OUString();
116 //====================================================================
117 //= ControlBorderManager
118 //====================================================================
119 /** manages the dynamic border color for form controls
121 Used by the <type>FormController</type>, this class manages the dynamic changes in the
122 border color of form controls. For this a set of events have to be forwarded to the manager
123 instance, which then will switch the border color depending on the mouse and focus status
124 of the controls.
126 class ControlBorderManager
128 private:
129 struct ControlDataCompare : public ::std::binary_function< ControlData, ControlData, bool >
131 bool operator()( const ControlData& _rLHS, const ControlData& _rRHS ) const
133 return _rLHS.xControl.get() < _rRHS.xControl.get();
137 typedef ::std::set< ControlData, ControlDataCompare > ControlBag;
138 typedef ::com::sun::star::awt::XVclWindowPeer WindowPeer;
139 typedef ::com::sun::star::uno::Reference< ::com::sun::star::awt::XVclWindowPeer > WindowPeerRef;
140 typedef ::std::set< WindowPeerRef, ::comphelper::OInterfaceCompare< WindowPeer > > PeerBag;
142 PeerBag m_aColorableControls;
143 PeerBag m_aNonColorableControls;
145 ControlData m_aFocusControl;
146 ControlData m_aMouseHoverControl;
147 ControlBag m_aInvalidControls;
149 // ----------------
150 // attributes
151 sal_Int32 m_nFocusColor;
152 sal_Int32 m_nMouseHoveColor;
153 sal_Int32 m_nInvalidColor;
154 bool m_bDynamicBorderColors;
156 public:
157 ControlBorderManager();
158 ~ControlBorderManager();
160 public:
161 void focusGained( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxControl ) SAL_THROW(());
162 void focusLost( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxControl ) SAL_THROW(());
163 void mouseEntered( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxControl ) SAL_THROW(());
164 void mouseExited( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxControl ) SAL_THROW(());
166 void validityChanged(
167 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl,
168 const ::com::sun::star::uno::Reference< ::com::sun::star::form::validation::XValidatableFormComponent >& _rxValidatable
169 ) SAL_THROW(());
171 /// enables dynamic border color for the controls
172 void enableDynamicBorderColor( );
173 /// disables dynamic border color for the controls
174 void disableDynamicBorderColor( );
176 /** sets a color to be used for a given status
177 @param _nStatus
178 the status which the color should be applied for. Must not be CONTROL_STATUS_NONE
179 @param _nColor
180 the color to apply for the given status
182 void setStatusColor( ControlStatus _nStatus, sal_Int32 _nColor );
184 /** restores all colors of all controls where we possibly changed them
186 void restoreAll();
188 private:
189 /** called when a control got one of the two possible stati (focused, and hovered with the mouse)
190 @param _rxControl
191 the control which gained the status
192 @param _rControlData
193 the control's status data, as a reference to our respective member
195 void controlStatusGained(
196 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxControl,
197 ControlData& _rControlData
198 ) SAL_THROW(());
200 /** called when a control lost one of the two possible stati (focused, and hovered with the mouse)
201 @param _rxControl
202 the control which lost the status
203 @param _rControlData
204 the control's status data, as a reference to our respective member
206 void controlStatusLost( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxControl, ControlData& _rControlData ) SAL_THROW(());
208 /** determines whether the border of a given peer can be colored
209 @param _rxPeer
210 the peer to examine. Must not be <NULL/>
212 bool canColorBorder( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XVclWindowPeer >& _rxPeer );
214 /** determines the status of the given control
216 ControlStatus getControlStatus( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl ) SAL_THROW(());
218 /** retrieves the color associated with a given ControlStatus
219 @param _eStatus
220 the status of the control. Must not be <member>ControlStatus::none</member>
222 sal_Int32 getControlColorByStatus( ControlStatus _eStatus );
224 /** sets the border color for a given control, depending on its status
225 @param _rxControl
226 the control to set the border color for. Must not be <NULL/>
227 @param _rxPeer
228 the peer of the control, to be passed herein for optimization the caller usually needs it, anyway).
229 Must not be <NULL/>
230 @param _rFallback
231 the color/type to use when the control has the status CONTROL_STATUS_NONE
233 void updateBorderStyle(
234 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl,
235 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XVclWindowPeer >& _rxPeer,
236 const BorderDescriptor& _rFallback
237 ) SAL_THROW(());
239 /** determines the to-be-remembered original border color and type for a control
241 The method also takes into account that the control may currently have an overwritten
242 border style
244 @param _rxControl
245 the control to examine. Must not be <NULL/>, and have a non-<NULL/> peer
247 void determineOriginalBorderStyle(
248 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl,
249 BorderDescriptor& _rData
250 ) const;
253 //........................................................................
254 } // namespace svxform
255 //........................................................................
257 #endif // SVX_SOURCE_INC_FMCONTROLBORDERMANAGER_HXX
259 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */