NanoXLSX.Core 3.0.0-rc.3
Loading...
Searching...
No Matches
SystemColor.cs
1/*
2 * NanoXLSX is a small .NET library to generate and read XLSX (Microsoft Excel 2007 or newer) files in an easy and native way
3 * Copyright Raphael Stoeckli © 2025
4 * This library is licensed under the MIT License.
5 * You find a copy of the license in project folder or on: http://opensource.org/licenses/MIT
6 */
7
8using System.Collections.Generic;
11using NanoXLSX.Utils;
12using static NanoXLSX.Themes.SystemColor;
13
14namespace NanoXLSX.Themes
15{
19 public class SystemColor : ITypedColor<Value>
20 {
87
88
89 private string lastColor = "000000";
90
94 public Value ColorValue { get; set; } = Value.WindowText;
95
99 public string StringValue { get { return MapValueToString(this.ColorValue); } }
100
104 public string LastColor
105 {
106 get => lastColor;
107 set
108 {
109 Validators.ValidateColor(value, false);
110 lastColor = value;
111 }
112 }
113
117 public SystemColor()
118 {
119 }
120
125 public SystemColor(Value value) : this()
126 {
127 this.ColorValue = value;
128 }
129
135 public SystemColor(Value value, string lastColor) : this(value)
136 {
137 this.LastColor = lastColor;
138 }
139
145 private static string MapValueToString(Value value)
146 {
147 switch (value)
148 {
149 case Value.ThreeDimensionalDarkShadow: return "3dDkShadow";
150 case Value.ThreeDimensionalLight: return "3dLight";
151 case Value.ActiveBorder: return "activeBorder";
152 case Value.ActiveCaption: return "activeCaption";
153 case Value.AppWorkspace: return "appWorkspace";
154 case Value.Background: return "background";
155 case Value.ButtonFace: return "btnFace";
156 case Value.ButtonHighlight: return "btnHighlight";
157 case Value.ButtonShadow: return "btnShadow";
158 case Value.ButtonText: return "btnText";
159 case Value.CaptionText: return "captionText";
160 case Value.GradientActiveCaption: return "gradientActiveCaption";
161 case Value.GradientInactiveCaption: return "gradientInactiveCaption";
162 case Value.GrayText: return "grayText";
163 case Value.Highlight: return "highlight";
164 case Value.HighlightText: return "highlightText";
165 case Value.HotLight: return "hotLight";
166 case Value.InactiveBorder: return "inactiveBorder";
167 case Value.InactiveCaption: return "inactiveCaption";
168 case Value.InactiveCaptionText: return "inactiveCaptionText";
169 case Value.InfoBackground: return "infoBk";
170 case Value.InfoText: return "infoText";
171 case Value.Menu: return "menu";
172 case Value.MenuBar: return "menuBar";
173 case Value.MenuHighlight: return "menuHighlight";
174 case Value.MenuText: return "menuText";
175 case Value.ScrollBar: return "scrollBar";
176 case Value.Window: return "window";
177 case Value.WindowFrame: return "windowFrame";
178 case Value.WindowText: return "windowText";
179 default:
180 throw new StyleException(value + " is not a valid system color value");
181 }
182 }
183
189 internal static Value MapStringToValue(string value)
190 {
191 switch (value)
192 {
193 case "3dDkShadow": return Value.ThreeDimensionalDarkShadow;
194 case "3dLight": return Value.ThreeDimensionalLight;
195 case "activeBorder": return Value.ActiveBorder;
196 case "activeCaption": return Value.ActiveCaption;
197 case "appWorkspace": return Value.AppWorkspace;
198 case "background": return Value.Background;
199 case "btnFace": return Value.ButtonFace;
200 case "btnHighlight": return Value.ButtonHighlight;
201 case "btnShadow": return Value.ButtonShadow;
202 case "btnText": return Value.ButtonText;
203 case "captionText": return Value.CaptionText;
204 case "gradientActiveCaption": return Value.GradientActiveCaption;
205 case "gradientInactiveCaption": return Value.GradientInactiveCaption;
206 case "grayText": return Value.GrayText;
207 case "highlight": return Value.Highlight;
208 case "highlightText": return Value.HighlightText;
209 case "hotLight": return Value.HotLight;
210 case "inactiveBorder": return Value.InactiveBorder;
211 case "inactiveCaption": return Value.InactiveCaption;
212 case "inactiveCaptionText": return Value.InactiveCaptionText;
213 case "infoBk": return Value.InfoBackground;
214 case "infoText": return Value.InfoText;
215 case "menu": return Value.Menu;
216 case "menuBar": return Value.MenuBar;
217 case "menuHighlight": return Value.MenuHighlight;
218 case "menuText": return Value.MenuText;
219 case "scrollBar": return Value.ScrollBar;
220 case "window": return Value.Window;
221 case "windowFrame": return Value.WindowFrame;
222 case "windowText": return Value.WindowText;
223 default:
224 throw new StyleException(value + " is not a valid system color value");
225 }
226 }
227
233 public override bool Equals(object obj)
234 {
235 return obj is SystemColor color &&
236 ColorValue == color.ColorValue &&
237 LastColor == color.LastColor;
238 }
239
244 public override int GetHashCode()
245 {
246 unchecked
247 {
248 int hashCode = 1425985453;
249 hashCode = hashCode * -1521134295 + ColorValue.GetHashCode();
250 hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(LastColor);
251 return hashCode;
252 }
253 }
254 }
255}
Class for exceptions regarding Style incidents.
Class representing a predefined system color for certain purposes or target areas in the UI.
string StringValue
Gets the internal OOXML string value of the enum, defined in ColorValue.
Value
Enum defining the available system colors.
@ HotLight
summary>Inactive Border System Color: Specifies the color of the Inactive window border
@ Highlight
summary>Highlight Text System Color: Specifies the text color of item(s) selected in a control
@ InfoBackground
summary>Info Text System Color: Specifies the text color for tool tip controls
@ AppWorkspace
summary>Background System Color: Specifies the desktop background color
@ ActiveCaption
summary>Application Workspace System Color: Specifies the Background color of multiple document inter...
@ GradientInactiveCaption
summary>Gray Text System Color: Specifies a grayed (disabled) text. This color is set to 0 if the cur...
@ ButtonText
summary>Caption Text System Color: Specifies the color of text in the caption, size box,...
@ ButtonShadow
summary>Button Text System Color: Specifies the color of text on push buttons
@ CaptionText
summary>Gradient Active Caption System Color: Specifies the right side color in the color gradient of...
@ InactiveCaptionText
summary>Info Back System Color: Specifies the background color for tool tip controls
@ GrayText
summary>Highlight System Color: Specifies the color of Item(s) selected in a control
@ GradientActiveCaption
summary>Gradient Inactive Caption System Color: Specifies the right side color in the color gradient ...
@ HighlightText
summary>Hot Light System Color: Specifies the color for a hyperlink or hot-tracked item
@ ScrollBar
summary>Window System Color: Specifies window background color
@ InactiveCaption
summary>Inactive Caption Text System Color: Specifies the color of text in an inactive caption
@ ThreeDimensionalDarkShadow
summary>3D Dark System Color: Specifies a Dark shadow color for three-dimensional display elements
@ ThreeDimensionalLight
summary>Active Border System Color: Specifies an Active Window Border Color
@ Background
summary>Button Face System Color: Specifies the face color for three-dimensional display elements and...
@ MenuBar
summary>Menu Highlight System Color: Specifies the color used to highlight menu items when the menu a...
@ ButtonHighlight
summary>Button Shadow System Color: Specifies the shadow color for three-dimensional display elements...
@ Menu
summary>Menu Bar System Color: Specifies the background color for the menu bar when menus appear as f...
@ MenuText
summary>Scroll Bar System Color: Specifies the scroll bar gray area color
@ ButtonFace
summary>Button Highlight System Color: Specifies the highlight color for three-dimensional display el...
@ Window
summary>Window Frame System Color: Specifies the window frame color
@ WindowFrame
summary>Window Text System Color: Specifies the color of text in windows
@ InactiveBorder
summary>Inactive Caption System Color: Specifies the color of the Inactive window caption....
@ ActiveBorder
summary>Active Caption System Color: Specifies the active window title bar color. In particular the l...
@ InfoText
summary>Menu System Color: Specifies the menu background color
@ MenuHighlight
summary>Menu Text System Color: Specifies the color of Text in menus
override bool Equals(object obj)
Determines whether the specified object is equal to the current system color instance.
SystemColor()
Default constructor.
SystemColor(Value value, string lastColor)
Constructor with all parameters.
override int GetHashCode()
Gets the hash code of the system color instance.
SystemColor(Value value)
Constructor with value as parameter.
Value ColorValue
Gets or sets the enum value of the system color.
string LastColor
Color value that was last computed by the generating application.
Class providing general validator methods.
Definition Validators.cs:11
static void ValidateColor(string hexCode, bool useAlpha, bool allowEmpty=false)
Validates the passed string, whether it is a valid RGB or ARGB value that can be used for Fills or Fo...
Definition Validators.cs:25