File: SubMenuStyle.cs

package info (click to toggle)
mono 6.8.0.105%2Bdfsg-3.3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,284,512 kB
  • sloc: cs: 11,172,132; xml: 2,850,069; ansic: 671,653; cpp: 122,091; perl: 59,366; javascript: 30,841; asm: 22,168; makefile: 20,093; sh: 15,020; python: 4,827; pascal: 925; sql: 859; sed: 16; php: 1
file content (302 lines) | stat: -rw-r--r-- 10,913 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
//------------------------------------------------------------------------------
// <copyright file="SubMenuStyle.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//------------------------------------------------------------------------------

namespace System.Web.UI.WebControls {
    using System.ComponentModel;
    using System.Drawing;
    using System.Globalization;
    using System.Text;
    using System.Web.UI;

    /// <devdoc>
    ///    Specifies the style of a SubMenu.
    /// </devdoc>
    public class SubMenuStyle : Style, ICustomTypeDescriptor {
        private const int PROP_VPADDING = 0x00010000;
        private const int PROP_HPADDING = 0x00020000;

        public SubMenuStyle() : base() {
        }

        public SubMenuStyle(StateBag bag) : base(bag) {
        }

        /// <devdoc>
        /// Gets and sets the horizontal padding around the node text
        /// </devdoc>
        [
        DefaultValue(typeof(Unit), ""),
        WebCategory("Layout"),
        NotifyParentProperty(true),
        WebSysDescription(SR.SubMenuStyle_HorizontalPadding),
        ]
        public Unit HorizontalPadding {
            get {
                if (IsSet(PROP_HPADDING)) {
                    return (Unit)(ViewState["HorizontalPadding"]);
                }
                return Unit.Empty;
            }
            set {
                if ((value.Type == UnitType.Percentage) || (value.Value < 0)) {
                    throw new ArgumentOutOfRangeException("value");
                }
                ViewState["HorizontalPadding"] = value;
                SetBit(PROP_HPADDING);
            }
        }


        /// <devdoc>
        /// Gets and sets the vertical padding around the node text
        /// </devdoc>
        [
        DefaultValue(typeof(Unit), ""),
        WebCategory("Layout"),
        NotifyParentProperty(true),
        WebSysDescription(SR.SubMenuStyle_VerticalPadding),
        ]
        public Unit VerticalPadding {
            get {
                if (IsSet(PROP_VPADDING)) {
                    return (Unit)(ViewState["VerticalPadding"]);
                }
                return Unit.Empty;
            }
            set {
                if ((value.Type == UnitType.Percentage) || (value.Value < 0)) {
                    throw new ArgumentOutOfRangeException("value");
                }
                ViewState["VerticalPadding"] = value;
                SetBit(PROP_VPADDING);
            }
        }


        /// <devdoc>
        ///    Copies non-blank elements from the specified style, overwriting existing
        ///    style elements if necessary.
        /// </devdoc>
        public override void CopyFrom(Style s) {
            if (s != null) {
                base.CopyFrom(s);

                SubMenuStyle sms = s as SubMenuStyle;
                if (sms != null && !sms.IsEmpty) {
                    // Only copy the paddings if they aren't in the source Style's registered CSS class
                    if (s.RegisteredCssClass.Length != 0) {
                        if (sms.IsSet(PROP_VPADDING)) {
                            ViewState.Remove("VerticalPadding");
                            ClearBit(PROP_VPADDING);
                        }

                        if (sms.IsSet(PROP_HPADDING)) {
                            ViewState.Remove("HorizontalPadding");
                            ClearBit(PROP_HPADDING);
                        }
                    }
                    else {
                        if (sms.IsSet(PROP_VPADDING)) {
                            this.VerticalPadding = sms.VerticalPadding;
                        }

                        if (sms.IsSet(PROP_HPADDING)) {
                            this.HorizontalPadding = sms.HorizontalPadding;
                        }
                    }
                }
            }
        }


        protected override void FillStyleAttributes(CssStyleCollection attributes, IUrlResolutionService urlResolver) {
            // The style will be rendered on container elements that does not contain text directly.
            // It does not render font and forecolor.
            // Users should set font and forecolor on MenuItems styles.
            // Copying the code from the base class, except for the part that deals with Font and ForeColor.
            StateBag viewState = ViewState;
            Color c;

            // BackColor
            if (base.IsSet(PROP_BACKCOLOR)) {
                c = (Color)viewState["BackColor"];
                if (!c.IsEmpty) {
                    attributes.Add(HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(c));
                }
            }

            // BorderColor
            if (base.IsSet(PROP_BORDERCOLOR)) {
                c = (Color)viewState["BorderColor"];
                if (!c.IsEmpty) {
                    attributes.Add(HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(c));
                }
            }

            BorderStyle bs = this.BorderStyle;
            Unit bu = this.BorderWidth;
            if (!bu.IsEmpty) {
                attributes.Add(HtmlTextWriterStyle.BorderWidth, bu.ToString(CultureInfo.InvariantCulture));
                if (bs == BorderStyle.NotSet) {
                    if (bu.Value != 0.0) {
                        attributes.Add(HtmlTextWriterStyle.BorderStyle, "solid");
                    }
                }
                else {
                    attributes.Add(HtmlTextWriterStyle.BorderStyle, borderStyles[(int)bs]);
                }
            }
            else {
                if (bs != BorderStyle.NotSet) {
                    attributes.Add(HtmlTextWriterStyle.BorderStyle, borderStyles[(int)bs]);
                }
            }

            Unit u;

            // Height
            if (base.IsSet(PROP_HEIGHT)) {
                u = (Unit)viewState["Height"];
                if (!u.IsEmpty) {
                    attributes.Add(HtmlTextWriterStyle.Height, u.ToString(CultureInfo.InvariantCulture));
                }
            }

            // Width
            if (base.IsSet(PROP_WIDTH)) {
                u = (Unit)viewState["Width"];
                if (!u.IsEmpty) {
                    attributes.Add(HtmlTextWriterStyle.Width, u.ToString(CultureInfo.InvariantCulture));
                }
            }

            if (!HorizontalPadding.IsEmpty || !VerticalPadding.IsEmpty) {
                attributes.Add(HtmlTextWriterStyle.Padding, string.Format(CultureInfo.InvariantCulture,
                    "{0} {1} {0} {1}",
                    VerticalPadding.IsEmpty ? Unit.Pixel(0) : VerticalPadding,
                    HorizontalPadding.IsEmpty ? Unit.Pixel(0) : HorizontalPadding));
            }
        }


        /// <devdoc>
        ///    Copies non-blank elements from the specified style, but will not overwrite
        ///    any existing style elements.
        /// </devdoc>
        public override void MergeWith(Style s) {
            if (s != null) {
                if (IsEmpty) {
                    // Merging with an empty style is equivalent to copying,
                    // which is more efficient.
                    CopyFrom(s);
                    return;
                }

                base.MergeWith(s);

                SubMenuStyle sms = s as SubMenuStyle;
                // Since we're already copying the registered CSS class in base.MergeWith, we don't
                // need to any attributes that would be included in that class.
                if (sms != null && !sms.IsEmpty && s.RegisteredCssClass.Length == 0) {
                    if (sms.IsSet(PROP_VPADDING) && !this.IsSet(PROP_VPADDING)) {
                        this.VerticalPadding = sms.VerticalPadding;
                    }

                    if (sms.IsSet(PROP_HPADDING) && !this.IsSet(PROP_HPADDING)) {
                        this.HorizontalPadding = sms.HorizontalPadding;
                    }
                }
            }
        }


        /// <devdoc>
        ///    Clears out any defined style elements from the state bag.
        /// </devdoc>
        public override void Reset() {
            if (IsSet(PROP_VPADDING))
                ViewState.Remove("VerticalPadding");
            if (IsSet(PROP_HPADDING))
                ViewState.Remove("HorizontalPadding");

            base.Reset();
        }


		#region ICustomTypeDesciptor implementation
		System.ComponentModel.AttributeCollection ICustomTypeDescriptor.GetAttributes() {
			return TypeDescriptor.GetAttributes(this, true);
		}

		string ICustomTypeDescriptor.GetClassName() {
			return TypeDescriptor.GetClassName(this, true);
		}

		string ICustomTypeDescriptor.GetComponentName() {
			return TypeDescriptor.GetComponentName(this, true);
		}

		TypeConverter ICustomTypeDescriptor.GetConverter() {
			return TypeDescriptor.GetConverter(this, true);
		}

		EventDescriptor ICustomTypeDescriptor.GetDefaultEvent() {
			return TypeDescriptor.GetDefaultEvent(this, true);
		}

		PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty() {
			return TypeDescriptor.GetDefaultProperty(this, true);
		}

		object ICustomTypeDescriptor.GetEditor(Type editorBaseType) {
			return TypeDescriptor.GetEditor(this, editorBaseType, true);
		}

		EventDescriptorCollection ICustomTypeDescriptor.GetEvents() {
			return TypeDescriptor.GetEvents(this, true);
		}

		EventDescriptorCollection ICustomTypeDescriptor.GetEvents(Attribute[] attributes) {
			return TypeDescriptor.GetEvents(this, attributes, true);
		}

		PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties() {
			return ((ICustomTypeDescriptor)this).GetProperties(null);
		}

		PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes) {
			PropertyDescriptorCollection oldProperties = TypeDescriptor.GetProperties(GetType(), attributes);
			PropertyDescriptor[] newProperties = new PropertyDescriptor[oldProperties.Count];

			PropertyDescriptor fontProperty = oldProperties["Font"];
			PropertyDescriptor forecolorProperty = oldProperties["ForeColor"];

			Attribute[] newAttributes = new Attribute[] {
                new BrowsableAttribute(false),
                new EditorBrowsableAttribute(EditorBrowsableState.Never),
                new ThemeableAttribute(false),
            };

			for (int i = 0; i < oldProperties.Count; i++) {
				PropertyDescriptor property = oldProperties[i];
				if ((property == fontProperty) || (property == forecolorProperty)) {
					newProperties[i] = TypeDescriptor.CreateProperty(GetType(), property, newAttributes);
				}
				else {
					newProperties[i] = property;
				}
			}

			return new PropertyDescriptorCollection(newProperties, true);
		}

		object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd) {
			return this;
		}
        #endregion //ICustomTypeDescriptor implementation

    }
}