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>
32 namespace com::sun::star::form::validation
{ class XValidatableFormComponent
; }
34 enum class ControlStatus
{
41 template<> struct typed_flags
<ControlStatus
> : is_typed_flags
<ControlStatus
, 0x07> {};
49 struct BorderDescriptor
51 sal_Int16 nBorderType
;
55 :nBorderType( css::awt::VisualEffect::FLAT
)
60 struct UnderlineDescriptor
62 sal_Int16 nUnderlineType
;
63 Color nUnderlineColor
;
66 :nUnderlineType( css::awt::FontUnderline::NONE
)
70 UnderlineDescriptor( sal_Int16 _nUnderlineType
, Color _nUnderlineColor
)
71 :nUnderlineType( _nUnderlineType
)
72 ,nUnderlineColor( _nUnderlineColor
)
77 struct ControlData
: public BorderDescriptor
, UnderlineDescriptor
79 css::uno::Reference
< css::awt::XControl
> xControl
;
80 OUString sOriginalHelpText
;
82 ControlData() : BorderDescriptor() { }
83 ControlData( const css::uno::Reference
< css::awt::XControl
>& _rxControl
)
84 :xControl( _rxControl
)
90 //= ControlBorderManager
92 /** manages the dynamic border color for form controls
94 Used by the <type>FormController</type>, this class manages the dynamic changes in the
95 border color of form controls. For this a set of events have to be forwarded to the manager
96 instance, which then will switch the border color depending on the mouse and focus status
99 class ControlBorderManager
102 struct ControlDataCompare
104 bool operator()( const ControlData
& _rLHS
, const ControlData
& _rRHS
) const
106 return _rLHS
.xControl
.get() < _rRHS
.xControl
.get();
110 typedef ::std::set
< ControlData
, ControlDataCompare
> ControlBag
;
111 typedef ::std::set
< css::uno::Reference
< css::awt::XVclWindowPeer
> > PeerBag
;
113 PeerBag m_aColorableControls
;
114 PeerBag m_aNonColorableControls
;
116 ControlData m_aFocusControl
;
117 ControlData m_aMouseHoverControl
;
118 ControlBag m_aInvalidControls
;
123 Color m_nMouseHoveColor
;
124 Color m_nInvalidColor
;
125 bool m_bDynamicBorderColors
;
128 ControlBorderManager();
129 ~ControlBorderManager();
132 void focusGained( const css::uno::Reference
< css::uno::XInterface
>& _rxControl
);
133 void focusLost( const css::uno::Reference
< css::uno::XInterface
>& _rxControl
);
134 void mouseEntered( const css::uno::Reference
< css::uno::XInterface
>& _rxControl
);
135 void mouseExited( const css::uno::Reference
< css::uno::XInterface
>& _rxControl
);
137 void validityChanged(
138 const css::uno::Reference
< css::awt::XControl
>& _rxControl
,
139 const css::uno::Reference
< css::form::validation::XValidatableFormComponent
>& _rxValidatable
142 /// enables dynamic border color for the controls
143 void enableDynamicBorderColor( );
144 /// disables dynamic border color for the controls
145 void disableDynamicBorderColor( );
147 /** sets a color to be used for a given status
149 the status which the color should be applied for. Must not be ControlStatus::NONE
151 the color to apply for the given status
153 void setStatusColor( ControlStatus _nStatus
, Color _nColor
);
155 /** restores all colors of all controls where we possibly changed them
160 /** called when a control got one of the two possible statuses (focused, and hovered with the mouse)
162 the control which gained the status
164 the control's status data, as a reference to our respective member
166 void controlStatusGained(
167 const css::uno::Reference
< css::uno::XInterface
>& _rxControl
,
168 ControlData
& _rControlData
171 /** called when a control lost one of the two possible statuses (focused, and hovered with the mouse)
173 the control which lost the status
175 the control's status data, as a reference to our respective member
177 void controlStatusLost( const css::uno::Reference
< css::uno::XInterface
>& _rxControl
, ControlData
& _rControlData
);
179 /** determines whether the border of a given peer can be colored
181 the peer to examine. Must not be <NULL/>
183 bool canColorBorder( const css::uno::Reference
< css::awt::XVclWindowPeer
>& _rxPeer
);
185 /** determines the status of the given control
187 ControlStatus
getControlStatus( const css::uno::Reference
< css::awt::XControl
>& _rxControl
);
189 /** retrieves the color associated with a given ControlStatus
191 the status of the control. Must not be <member>ControlStatus::none</member>
193 Color
getControlColorByStatus( ControlStatus _eStatus
);
195 /** sets the border color for a given control, depending on its status
197 the control to set the border color for. Must not be <NULL/>
199 the peer of the control, to be passed herein for optimization the caller usually needs it, anyway).
202 the color/type to use when the control has the status ControlStatus::NONE
204 void updateBorderStyle(
205 const css::uno::Reference
< css::awt::XControl
>& _rxControl
,
206 const css::uno::Reference
< css::awt::XVclWindowPeer
>& _rxPeer
,
207 const BorderDescriptor
& _rFallback
210 /** determines the to-be-remembered original border color and type for a control
212 The method also takes into account that the control may currently have an overwritten
216 the control to examine. Must not be <NULL/>, and have a non-<NULL/> peer
218 void determineOriginalBorderStyle(
219 const css::uno::Reference
< css::awt::XControl
>& _rxControl
,
220 BorderDescriptor
& _rData
228 #endif // INCLUDED_SVX_SOURCE_INC_FMCONTROLBORDERMANAGER_HXX
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */