Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / inc / fmcontrolbordermanager.hxx
blobe0d96c5577a8296b71c48bf55a5c4f9ff118fcc6
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>
31 #include <utility>
33 namespace com::sun::star::form::validation { class XValidatableFormComponent; }
35 enum class ControlStatus {
36 NONE = 0x00,
37 Focused = 0x01,
38 MouseHover = 0x02,
39 Invalid = 0x04
41 namespace o3tl {
42 template<> struct typed_flags<ControlStatus> : is_typed_flags<ControlStatus, 0x07> {};
46 namespace svxform
50 struct BorderDescriptor
52 sal_Int16 nBorderType;
53 Color nBorderColor;
55 BorderDescriptor()
56 :nBorderType( css::awt::VisualEffect::FLAT )
61 struct UnderlineDescriptor
63 sal_Int16 nUnderlineType;
64 Color nUnderlineColor;
66 UnderlineDescriptor()
67 :nUnderlineType( css::awt::FontUnderline::NONE )
71 UnderlineDescriptor( sal_Int16 _nUnderlineType, Color _nUnderlineColor )
72 :nUnderlineType( _nUnderlineType )
73 ,nUnderlineColor( _nUnderlineColor )
78 struct ControlData : public BorderDescriptor, UnderlineDescriptor
80 css::uno::Reference< css::awt::XControl > xControl;
81 OUString sOriginalHelpText;
83 ControlData() : BorderDescriptor() { }
84 ControlData( css::uno::Reference< css::awt::XControl > _xControl )
85 :xControl(std::move( _xControl ))
91 //= ControlBorderManager
93 /** manages the dynamic border color for form controls
95 Used by the <type>FormController</type>, this class manages the dynamic changes in the
96 border color of form controls. For this a set of events have to be forwarded to the manager
97 instance, which then will switch the border color depending on the mouse and focus status
98 of the controls.
100 class ControlBorderManager
102 private:
103 struct ControlDataCompare
105 bool operator()( const ControlData& _rLHS, const ControlData& _rRHS ) const
107 return _rLHS.xControl.get() < _rRHS.xControl.get();
111 typedef ::std::set< ControlData, ControlDataCompare > ControlBag;
112 typedef ::std::set< css::uno::Reference< css::awt::XVclWindowPeer > > PeerBag;
114 PeerBag m_aColorableControls;
115 PeerBag m_aNonColorableControls;
117 ControlData m_aFocusControl;
118 ControlData m_aMouseHoverControl;
119 ControlBag m_aInvalidControls;
122 // attributes
123 Color m_nFocusColor;
124 Color m_nMouseHoveColor;
125 Color m_nInvalidColor;
126 bool m_bDynamicBorderColors;
128 public:
129 ControlBorderManager();
130 ~ControlBorderManager();
132 public:
133 void focusGained( const css::uno::Reference< css::uno::XInterface >& _rxControl );
134 void focusLost( const css::uno::Reference< css::uno::XInterface >& _rxControl );
135 void mouseEntered( const css::uno::Reference< css::uno::XInterface >& _rxControl );
136 void mouseExited( const css::uno::Reference< css::uno::XInterface >& _rxControl );
138 void validityChanged(
139 const css::uno::Reference< css::awt::XControl >& _rxControl,
140 const css::uno::Reference< css::form::validation::XValidatableFormComponent >& _rxValidatable
143 /// enables dynamic border color for the controls
144 void enableDynamicBorderColor( );
145 /// disables dynamic border color for the controls
146 void disableDynamicBorderColor( );
148 /** sets a color to be used for a given status
149 @param _nStatus
150 the status which the color should be applied for. Must not be ControlStatus::NONE
151 @param _nColor
152 the color to apply for the given status
154 void setStatusColor( ControlStatus _nStatus, Color _nColor );
156 /** restores all colors of all controls where we possibly changed them
158 void restoreAll();
160 private:
161 /** called when a control got one of the two possible statuses (focused, and hovered with the mouse)
162 @param _rxControl
163 the control which gained the status
164 @param _rControlData
165 the control's status data, as a reference to our respective member
167 void controlStatusGained(
168 const css::uno::Reference< css::uno::XInterface >& _rxControl,
169 ControlData& _rControlData
172 /** called when a control lost one of the two possible statuses (focused, and hovered with the mouse)
173 @param _rxControl
174 the control which lost the status
175 @param _rControlData
176 the control's status data, as a reference to our respective member
178 void controlStatusLost( const css::uno::Reference< css::uno::XInterface >& _rxControl, ControlData& _rControlData );
180 /** determines whether the border of a given peer can be colored
181 @param _rxPeer
182 the peer to examine. Must not be <NULL/>
184 bool canColorBorder( const css::uno::Reference< css::awt::XVclWindowPeer >& _rxPeer );
186 /** determines the status of the given control
188 ControlStatus getControlStatus( const css::uno::Reference< css::awt::XControl >& _rxControl );
190 /** retrieves the color associated with a given ControlStatus
191 @param _eStatus
192 the status of the control. Must not be <member>ControlStatus::none</member>
194 Color getControlColorByStatus( ControlStatus _eStatus ) const;
196 /** sets the border color for a given control, depending on its status
197 @param _rxControl
198 the control to set the border color for. Must not be <NULL/>
199 @param _rxPeer
200 the peer of the control, to be passed herein for optimization the caller usually needs it, anyway).
201 Must not be <NULL/>
202 @param _rFallback
203 the color/type to use when the control has the status ControlStatus::NONE
205 void updateBorderStyle(
206 const css::uno::Reference< css::awt::XControl >& _rxControl,
207 const css::uno::Reference< css::awt::XVclWindowPeer >& _rxPeer,
208 const BorderDescriptor& _rFallback
211 /** determines the to-be-remembered original border color and type for a control
213 The method also takes into account that the control may currently have an overwritten
214 border style
216 @param _rxControl
217 the control to examine. Must not be <NULL/>, and have a non-<NULL/> peer
219 void determineOriginalBorderStyle(
220 const css::uno::Reference< css::awt::XControl >& _rxControl,
221 BorderDescriptor& _rData
222 ) const;
229 #endif // INCLUDED_SVX_SOURCE_INC_FMCONTROLBORDERMANAGER_HXX
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */