2 // System.Web.UI.WebControls.TreeNodeStyle.cs
5 // Lluis Sanchez Gual (lluis@novell.com)
7 // (C) 2004 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
35 using System.ComponentModel;
37 namespace System.Web.UI.WebControls
39 public sealed class TreeNodeStyle: Style
41 private const string CHILD_PADD = "ChildNodesPadding";
42 private const string HORZ_PADD = "HorizontalPadding";
43 private const string IMG_URL = "ImageUrl";
44 private const string SPACING = "NodeSpacing";
45 private const string VERT_PADD = "VerticalPadding";
49 return ViewState [v] != null;
54 [NotifyParentProperty (true)]
55 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
56 public string ImageUrl {
58 return ViewState.GetString (IMG_URL, String.Empty);
62 throw new ArgumentNullException("value");
63 ViewState [IMG_URL] = value;
68 [NotifyParentProperty (true)]
69 public int ChildNodesPadding {
71 return ViewState.GetInt (CHILD_PADD, 0);
74 ViewState [CHILD_PADD] = value;
79 [NotifyParentProperty (true)]
80 public int HorizontalPadding {
82 return ViewState.GetInt (HORZ_PADD, 0);
85 ViewState[HORZ_PADD] = value;
90 [NotifyParentProperty (true)]
91 public int VerticalPadding {
93 return ViewState.GetInt (VERT_PADD, 0);
96 ViewState [VERT_PADD] = value;
101 [NotifyParentProperty (true)]
102 public int NodeSpacing {
104 return ViewState.GetInt (SPACING, 0);
107 ViewState [SPACING] = value;
111 // FIXME: shouldn't be part of the public API
112 public override bool IsEmpty {
114 return (base.IsEmpty &&
115 !IsSet (CHILD_PADD) &&
116 !IsSet (HORZ_PADD) &&
123 public override void CopyFrom (Style s)
125 if (s == null || s.IsEmpty)
129 TreeNodeStyle from = s as TreeNodeStyle;
133 if (from.IsSet (CHILD_PADD))
134 ChildNodesPadding = from.ChildNodesPadding;
136 if (from.IsSet (HORZ_PADD))
137 HorizontalPadding = from.HorizontalPadding;
139 if (from.IsSet (IMG_URL))
140 ImageUrl = from.ImageUrl;
142 if (from.IsSet (SPACING))
143 NodeSpacing = from.NodeSpacing;
145 if (from.IsSet (VERT_PADD))
146 VerticalPadding = from.VerticalPadding;
149 public override void MergeWith(Style s)
151 if(s != null && !s.IsEmpty)
159 TreeNodeStyle with = s as TreeNodeStyle;
160 if (with == null) return;
162 if (with.IsSet(CHILD_PADD) && !IsSet(CHILD_PADD)) {
163 ChildNodesPadding = with.ChildNodesPadding;
165 if (with.IsSet(HORZ_PADD) && !IsSet(HORZ_PADD)) {
166 HorizontalPadding = with.HorizontalPadding;
168 if (with.IsSet(IMG_URL) && !IsSet(IMG_URL)) {
169 ImageUrl = with.ImageUrl;
171 if (with.IsSet(SPACING) && !IsSet(SPACING)) {
172 NodeSpacing = with.NodeSpacing;
174 if (with.IsSet(VERT_PADD) && !IsSet(VERT_PADD)) {
175 VerticalPadding = with.VerticalPadding;
180 public override void Reset()
182 if(IsSet(CHILD_PADD))
183 ViewState.Remove("ChildNodesPadding");
185 ViewState.Remove("HorizontalPadding");
187 ViewState.Remove("ImageUrl");
189 ViewState.Remove("NodeSpacing");
191 ViewState.Remove("VerticalPadding");