1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team |
---|
2 | // |
---|
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this |
---|
4 | // software and associated documentation files (the "Software"), to deal in the Software |
---|
5 | // without restriction, including without limitation the rights to use, copy, modify, merge, |
---|
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons |
---|
7 | // to whom the Software is furnished to do so, subject to the following conditions: |
---|
8 | // |
---|
9 | // The above copyright notice and this permission notice shall be included in all copies or |
---|
10 | // substantial portions of the Software. |
---|
11 | // |
---|
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
---|
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
---|
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE |
---|
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
---|
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
17 | // DEALINGS IN THE SOFTWARE. |
---|
18 | |
---|
19 | using System; |
---|
20 | using System.Runtime.Serialization; |
---|
21 | using System.Security.Permissions; |
---|
22 | using System.Windows; |
---|
23 | |
---|
24 | namespace ICSharpCode.AvalonEdit.Highlighting.Xshd |
---|
25 | { |
---|
26 | /// <summary> |
---|
27 | /// A color in an Xshd file. |
---|
28 | /// </summary> |
---|
29 | [Serializable] |
---|
30 | public class XshdColor : XshdElement, ISerializable |
---|
31 | { |
---|
32 | /// <summary> |
---|
33 | /// Gets/sets the name. |
---|
34 | /// </summary> |
---|
35 | public string Name { get; set; } |
---|
36 | |
---|
37 | /// <summary> |
---|
38 | /// Gets/sets the foreground brush. |
---|
39 | /// </summary> |
---|
40 | public HighlightingBrush Foreground { get; set; } |
---|
41 | |
---|
42 | /// <summary> |
---|
43 | /// Gets/sets the background brush. |
---|
44 | /// </summary> |
---|
45 | public HighlightingBrush Background { get; set; } |
---|
46 | |
---|
47 | /// <summary> |
---|
48 | /// Gets/sets the font weight. |
---|
49 | /// </summary> |
---|
50 | public FontWeight? FontWeight { get; set; } |
---|
51 | |
---|
52 | /// <summary> |
---|
53 | /// Gets/sets the font style. |
---|
54 | /// </summary> |
---|
55 | public FontStyle? FontStyle { get; set; } |
---|
56 | |
---|
57 | /// <summary> |
---|
58 | /// Gets/Sets the example text that demonstrates where the color is used. |
---|
59 | /// </summary> |
---|
60 | public string ExampleText { get; set; } |
---|
61 | |
---|
62 | /// <summary> |
---|
63 | /// Creates a new XshdColor instance. |
---|
64 | /// </summary> |
---|
65 | public XshdColor() |
---|
66 | { |
---|
67 | } |
---|
68 | |
---|
69 | /// <summary> |
---|
70 | /// Deserializes an XshdColor. |
---|
71 | /// </summary> |
---|
72 | protected XshdColor(SerializationInfo info, StreamingContext context) |
---|
73 | { |
---|
74 | if (info == null) |
---|
75 | throw new ArgumentNullException("info"); |
---|
76 | this.Name = info.GetString("Name"); |
---|
77 | this.Foreground = (HighlightingBrush)info.GetValue("Foreground", typeof(HighlightingBrush)); |
---|
78 | this.Background = (HighlightingBrush)info.GetValue("Background", typeof(HighlightingBrush)); |
---|
79 | if (info.GetBoolean("HasWeight")) |
---|
80 | this.FontWeight = System.Windows.FontWeight.FromOpenTypeWeight(info.GetInt32("Weight")); |
---|
81 | if (info.GetBoolean("HasStyle")) |
---|
82 | this.FontStyle = (FontStyle?)new FontStyleConverter().ConvertFromInvariantString(info.GetString("Style")); |
---|
83 | this.ExampleText = info.GetString("ExampleText"); |
---|
84 | } |
---|
85 | |
---|
86 | /// <summary> |
---|
87 | /// Serializes this XshdColor instance. |
---|
88 | /// </summary> |
---|
89 | #if DOTNET4 |
---|
90 | [System.Security.SecurityCritical] |
---|
91 | #else |
---|
92 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)] |
---|
93 | #endif |
---|
94 | public virtual void GetObjectData(SerializationInfo info, StreamingContext context) |
---|
95 | { |
---|
96 | if (info == null) |
---|
97 | throw new ArgumentNullException("info"); |
---|
98 | info.AddValue("Name", this.Name); |
---|
99 | info.AddValue("Foreground", this.Foreground); |
---|
100 | info.AddValue("Background", this.Background); |
---|
101 | info.AddValue("HasWeight", this.FontWeight.HasValue); |
---|
102 | if (this.FontWeight.HasValue) |
---|
103 | info.AddValue("Weight", this.FontWeight.Value.ToOpenTypeWeight()); |
---|
104 | info.AddValue("HasStyle", this.FontStyle.HasValue); |
---|
105 | if (this.FontStyle.HasValue) |
---|
106 | info.AddValue("Style", this.FontStyle.Value.ToString()); |
---|
107 | info.AddValue("ExampleText", this.ExampleText); |
---|
108 | } |
---|
109 | |
---|
110 | /// <inheritdoc/> |
---|
111 | public override object AcceptVisitor(IXshdVisitor visitor) |
---|
112 | { |
---|
113 | return visitor.VisitColor(this); |
---|
114 | } |
---|
115 | } |
---|
116 | } |
---|