Bump version to 6.4-15
[LibreOffice.git] / svx / source / inc / fmcontrolbordermanager.hxx
blob5b12dbc4d50f5dd06c0ffbd0290e8255706d7605
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 INCLUDED_SVX_SOURCE_INC_FMCONTROLBORDERMANAGER_HXX
21 #define INCLUDED_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 <o3tl/typed_flags_set.hxx>
28 #include <tools/color.hxx>
30 #include <set>
32 namespace com { namespace sun { namespace star { namespace form { namespace validation {
33 class XValidatableFormComponent;
34 } } } } }
36 enum class ControlStatus {
37 NONE = 0x00,
38 Focused = 0x01,
39 MouseHover = 0x02,
40 Invalid = 0x04
42 namespace o3tl {
43 template<> struct typed_flags<ControlStatus> : is_typed_flags<ControlStatus, 0x07> {};
47 namespace svxform
51 struct BorderDescriptor
53 sal_Int16 nBorderType;
54 Color nBorderColor;
56 BorderDescriptor()
57 :nBorderType( css::awt::VisualEffect::FLAT )
62 struct UnderlineDescriptor
64 sal_Int16 nUnderlineType;
65 Color nUnderlineColor;
67 UnderlineDescriptor()
68 :nUnderlineType( css::awt::FontUnderline::NONE )
72 UnderlineDescriptor( sal_Int16 _nUnderlineType, Color _nUnderlineColor )
73 :nUnderlineType( _nUnderlineType )
74 ,nUnderlineColor( _nUnderlineColor )
79 struct ControlData : public BorderDescriptor, UnderlineDescriptor
81 css::uno::Reference< css::awt::XControl > xControl;
82 OUString sOriginalHelpText;
84 ControlData() : BorderDescriptor() { }
85 ControlData( const css::uno::Reference< css::awt::XControl >& _rxControl )
86 :xControl( _rxControl )
92 //= ControlBorderManager
94 /** manages the dynamic border color for form controls
96 Used by the <type>FormController</type>, this class manages the dynamic changes in the
97 border color of form controls. For this a set of events have to be forwarded to the manager
98 instance, which then will switch the border color depending on the mouse and focus status
99 of the controls.
101 class ControlBorderManager
103 private:
104 struct ControlDataCompare
106 bool operator()( const ControlData& _rLHS, const ControlData& _rRHS ) const
108 return _rLHS.xControl.get() < _rRHS.xControl.get();
112 typedef ::std::set< ControlData, ControlDataCompare > ControlBag;
113 typedef ::std::set< css::uno::Reference< css::awt::XVclWindowPeer > > PeerBag;
115 PeerBag m_aColorableControls;
116 PeerBag m_aNonColorableControls;
118 ControlData m_aFocusControl;
119 ControlData m_aMouseHoverControl;
120 ControlBag m_aInvalidControls;
123 // attributes
124 Color m_nFocusColor;
125 Color m_nMouseHoveColor;
126 Color m_nInvalidColor;
127 bool m_bDynamicBorderColors;
129 public:
130 ControlBorderManager();
131 ~ControlBorderManager();
133 public:
134 void focusGained( const css::uno::Reference< css::uno::XInterface >& _rxControl );
135 void focusLost( const css::uno::Reference< css::uno::XInterface >& _rxControl );
136 void mouseEntered( const css::uno::Reference< css::uno::XInterface >& _rxControl );
137 void mouseExited( const css::uno::Reference< css::uno::XInterface >& _rxControl );
139 void validityChanged(
140 const css::uno::Reference< css::awt::XControl >& _rxControl,
141 const css::uno::Reference< css::form::validation::XValidatableFormComponent >& _rxValidatable
144 /// enables dynamic border color for the controls
145 void enableDynamicBorderColor( );
146 /// disables dynamic border color for the controls
147 void disableDynamicBorderColor( );
149 /** sets a color to be used for a given status
150 @param _nStatus
151 the status which the color should be applied for. Must not be ControlStatus::NONE
152 @param _nColor
153 the color to apply for the given status
155 void setStatusColor( ControlStatus _nStatus, Color _nColor );
157 /** restores all colors of all controls where we possibly changed them
159 void restoreAll();
161 private:
162 /** called when a control got one of the two possible statuses (focused, and hovered with the mouse)
163 @param _rxControl
164 the control which gained the status
165 @param _rControlData
166 the control's status data, as a reference to our respective member
168 void controlStatusGained(
169 const css::uno::Reference< css::uno::XInterface >& _rxControl,
170 ControlData& _rControlData
173 /** called when a control lost one of the two possible statuses (focused, and hovered with the mouse)
174 @param _rxControl
175 the control which lost the status
176 @param _rControlData
177 the control's status data, as a reference to our respective member
179 void controlStatusLost( const css::uno::Reference< css::uno::XInterface >& _rxControl, ControlData& _rControlData );
181 /** determines whether the border of a given peer can be colored
182 @param _rxPeer
183 the peer to examine. Must not be <NULL/>
185 bool canColorBorder( const css::uno::Reference< css::awt::XVclWindowPeer >& _rxPeer );
187 /** determines the status of the given control
189 ControlStatus getControlStatus( const css::uno::Reference< css::awt::XControl >& _rxControl );
191 /** retrieves the color associated with a given ControlStatus
192 @param _eStatus
193 the status of the control. Must not be <member>ControlStatus::none</member>
195 Color getControlColorByStatus( ControlStatus _eStatus );
197 /** sets the border color for a given control, depending on its status
198 @param _rxControl
199 the control to set the border color for. Must not be <NULL/>
200 @param _rxPeer
201 the peer of the control, to be passed herein for optimization the caller usually needs it, anyway).
202 Must not be <NULL/>
203 @param _rFallback
204 the color/type to use when the control has the status ControlStatus::NONE
206 void updateBorderStyle(
207 const css::uno::Reference< css::awt::XControl >& _rxControl,
208 const css::uno::Reference< css::awt::XVclWindowPeer >& _rxPeer,
209 const BorderDescriptor& _rFallback
212 /** determines the to-be-remembered original border color and type for a control
214 The method also takes into account that the control may currently have an overwritten
215 border style
217 @param _rxControl
218 the control to examine. Must not be <NULL/>, and have a non-<NULL/> peer
220 void determineOriginalBorderStyle(
221 const css::uno::Reference< css::awt::XControl >& _rxControl,
222 BorderDescriptor& _rData
223 ) const;
230 #endif // INCLUDED_SVX_SOURCE_INC_FMCONTROLBORDERMANAGER_HXX
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */