1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
33 namespace com::sun::star::form::validation
{ class XValidatableFormComponent
; }
35 enum class ControlStatus
{
42 template<> struct typed_flags
<ControlStatus
> : is_typed_flags
<ControlStatus
, 0x07> {};
50 struct BorderDescriptor
52 sal_Int16 nBorderType
;
56 :nBorderType( css::awt::VisualEffect::FLAT
)
61 struct UnderlineDescriptor
63 sal_Int16 nUnderlineType
;
64 Color nUnderlineColor
;
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
100 class ControlBorderManager
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
;
124 Color m_nMouseHoveColor
;
125 Color m_nInvalidColor
;
126 bool m_bDynamicBorderColors
;
129 ControlBorderManager();
130 ~ControlBorderManager();
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
150 the status which the color should be applied for. Must not be ControlStatus::NONE
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
161 /** called when a control got one of the two possible statuses (focused, and hovered with the mouse)
163 the control which gained the status
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)
174 the control which lost the status
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
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
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
198 the control to set the border color for. Must not be <NULL/>
200 the peer of the control, to be passed herein for optimization the caller usually needs it, anyway).
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
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
229 #endif // INCLUDED_SVX_SOURCE_INC_FMCONTROLBORDERMANAGER_HXX
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */