/src/libreoffice/svx/source/inc/fmcontrolbordermanager.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #ifndef INCLUDED_SVX_SOURCE_INC_FMCONTROLBORDERMANAGER_HXX |
21 | | #define INCLUDED_SVX_SOURCE_INC_FMCONTROLBORDERMANAGER_HXX |
22 | | |
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> |
29 | | |
30 | | #include <set> |
31 | | #include <utility> |
32 | | |
33 | | namespace com::sun::star::form::validation { class XValidatableFormComponent; } |
34 | | |
35 | | enum class ControlStatus { |
36 | | NONE = 0x00, |
37 | | Focused = 0x01, |
38 | | MouseHover = 0x02, |
39 | | Invalid = 0x04 |
40 | | }; |
41 | | namespace o3tl { |
42 | | template<> struct typed_flags<ControlStatus> : is_typed_flags<ControlStatus, 0x07> {}; |
43 | | } |
44 | | |
45 | | |
46 | | namespace svxform |
47 | | { |
48 | | |
49 | | |
50 | | struct BorderDescriptor |
51 | | { |
52 | | sal_Int16 nBorderType; |
53 | | Color nBorderColor; |
54 | | |
55 | | BorderDescriptor() |
56 | 0 | :nBorderType( css::awt::VisualEffect::FLAT ) |
57 | 0 | { |
58 | 0 | } |
59 | | }; |
60 | | |
61 | | struct UnderlineDescriptor |
62 | | { |
63 | | sal_Int16 nUnderlineType; |
64 | | Color nUnderlineColor; |
65 | | |
66 | | UnderlineDescriptor() |
67 | 0 | :nUnderlineType( css::awt::FontUnderline::NONE ) |
68 | 0 | { |
69 | 0 | } |
70 | | |
71 | | UnderlineDescriptor( sal_Int16 _nUnderlineType, Color _nUnderlineColor ) |
72 | 0 | :nUnderlineType( _nUnderlineType ) |
73 | 0 | ,nUnderlineColor( _nUnderlineColor ) |
74 | 0 | { |
75 | 0 | } |
76 | | }; |
77 | | |
78 | | struct ControlData : public BorderDescriptor, UnderlineDescriptor |
79 | | { |
80 | | css::uno::Reference< css::awt::XControl > xControl; |
81 | | OUString sOriginalHelpText; |
82 | | |
83 | 0 | ControlData() : BorderDescriptor() { } |
84 | | ControlData( css::uno::Reference< css::awt::XControl > _xControl ) |
85 | 0 | :xControl(std::move( _xControl )) |
86 | 0 | { |
87 | 0 | } |
88 | | }; |
89 | | |
90 | | |
91 | | //= ControlBorderManager |
92 | | |
93 | | /** manages the dynamic border color for form controls |
94 | | |
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. |
99 | | */ |
100 | | class ControlBorderManager |
101 | | { |
102 | | private: |
103 | | struct ControlDataCompare |
104 | | { |
105 | | bool operator()( const ControlData& _rLHS, const ControlData& _rRHS ) const |
106 | 0 | { |
107 | 0 | return _rLHS.xControl.get() < _rRHS.xControl.get(); |
108 | 0 | } |
109 | | }; |
110 | | |
111 | | typedef ::std::set< ControlData, ControlDataCompare > ControlBag; |
112 | | typedef ::std::set< css::uno::Reference< css::awt::XVclWindowPeer > > PeerBag; |
113 | | |
114 | | PeerBag m_aColorableControls; |
115 | | PeerBag m_aNonColorableControls; |
116 | | |
117 | | ControlData m_aFocusControl; |
118 | | ControlData m_aMouseHoverControl; |
119 | | ControlBag m_aInvalidControls; |
120 | | |
121 | | |
122 | | // attributes |
123 | | Color m_nFocusColor; |
124 | | Color m_nMouseHoveColor; |
125 | | Color m_nInvalidColor; |
126 | | bool m_bDynamicBorderColors; |
127 | | |
128 | | public: |
129 | | ControlBorderManager(); |
130 | | ~ControlBorderManager(); |
131 | | |
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 ); |
137 | | |
138 | | void validityChanged( |
139 | | const css::uno::Reference< css::awt::XControl >& _rxControl, |
140 | | const css::uno::Reference< css::form::validation::XValidatableFormComponent >& _rxValidatable |
141 | | ); |
142 | | |
143 | | /// enables dynamic border color for the controls |
144 | | void enableDynamicBorderColor( ); |
145 | | /// disables dynamic border color for the controls |
146 | | void disableDynamicBorderColor( ); |
147 | | |
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 |
153 | | */ |
154 | | void setStatusColor( ControlStatus _nStatus, Color _nColor ); |
155 | | |
156 | | /** restores all colors of all controls where we possibly changed them |
157 | | */ |
158 | | void restoreAll(); |
159 | | |
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 |
166 | | */ |
167 | | void controlStatusGained( |
168 | | const css::uno::Reference< css::uno::XInterface >& _rxControl, |
169 | | ControlData& _rControlData |
170 | | ); |
171 | | |
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 |
177 | | */ |
178 | | void controlStatusLost( const css::uno::Reference< css::uno::XInterface >& _rxControl, ControlData& _rControlData ); |
179 | | |
180 | | /** determines whether the border of a given peer can be colored |
181 | | @param _rxPeer |
182 | | the peer to examine. Must not be <NULL/> |
183 | | */ |
184 | | bool canColorBorder( const css::uno::Reference< css::awt::XVclWindowPeer >& _rxPeer ); |
185 | | |
186 | | /** determines the status of the given control |
187 | | */ |
188 | | ControlStatus getControlStatus( const css::uno::Reference< css::awt::XControl >& _rxControl ); |
189 | | |
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> |
193 | | */ |
194 | | Color getControlColorByStatus( ControlStatus _eStatus ) const; |
195 | | |
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 |
204 | | */ |
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 |
209 | | ); |
210 | | |
211 | | /** determines the to-be-remembered original border color and type for a control |
212 | | |
213 | | The method also takes into account that the control may currently have an overwritten |
214 | | border style |
215 | | |
216 | | @param _rxControl |
217 | | the control to examine. Must not be <NULL/>, and have a non-<NULL/> peer |
218 | | */ |
219 | | void determineOriginalBorderStyle( |
220 | | const css::uno::Reference< css::awt::XControl >& _rxControl, |
221 | | BorderDescriptor& _rData |
222 | | ) const; |
223 | | }; |
224 | | |
225 | | |
226 | | } |
227 | | |
228 | | |
229 | | #endif // INCLUDED_SVX_SOURCE_INC_FMCONTROLBORDERMANAGER_HXX |
230 | | |
231 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |