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 const string CHILD_PADD = "ChildNodesPadding";
42 const string HORZ_PADD = "HorizontalPadding";
43 const string IMG_URL = "ImageUrl";
44 const string SPACING = "NodeSpacing";
45 const string VERT_PADD = "VerticalPadding";
50 ChildNodesPadding = 0x00010000,
51 HorizontalPadding = 0x00020000,
52 ImageUrl = 0x00040000,
53 NodeSpacing = 0x00080000,
54 VerticalPadding = 0x00100000,
57 public TreeNodeStyle ()
62 public TreeNodeStyle (StateBag bag)
69 [NotifyParentProperty (true)]
70 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
71 public string ImageUrl {
73 if (!CheckBit ((int) TreeNodeStyles.ImageUrl))
75 return ViewState.GetString (IMG_URL, String.Empty);
79 throw new ArgumentNullException("value");
80 ViewState [IMG_URL] = value;
81 SetBit ((int) TreeNodeStyles.ImageUrl);
86 [NotifyParentProperty (true)]
87 public Unit ChildNodesPadding {
89 if (!CheckBit ((int) TreeNodeStyles.ChildNodesPadding))
91 return ViewState [CHILD_PADD] == null ? 0 : (Unit) ViewState [CHILD_PADD];
94 ViewState [CHILD_PADD] = value;
95 SetBit ((int) TreeNodeStyles.ChildNodesPadding);
100 [NotifyParentProperty (true)]
101 public Unit HorizontalPadding {
103 if (!CheckBit ((int) TreeNodeStyles.HorizontalPadding))
105 return ViewState [HORZ_PADD] == null ? 0 : (Unit) ViewState [HORZ_PADD];
108 ViewState[HORZ_PADD] = value;
109 SetBit ((int) TreeNodeStyles.HorizontalPadding);
114 [NotifyParentProperty (true)]
115 public Unit VerticalPadding {
117 if (!CheckBit ((int) TreeNodeStyles.VerticalPadding))
119 return ViewState [VERT_PADD] == null ? 0 : (Unit) ViewState [VERT_PADD];
122 ViewState [VERT_PADD] = value;
123 SetBit ((int) TreeNodeStyles.VerticalPadding);
128 [NotifyParentProperty (true)]
129 public Unit NodeSpacing {
131 if (!CheckBit ((int) TreeNodeStyles.NodeSpacing))
133 return ViewState [SPACING] == null ? 0 : (Unit) ViewState [SPACING];
136 ViewState [SPACING] = value;
137 SetBit ((int) TreeNodeStyles.NodeSpacing);
141 public override void CopyFrom (Style s)
143 if (s == null || s.IsEmpty)
147 TreeNodeStyle from = s as TreeNodeStyle;
151 if (from.CheckBit ((int) TreeNodeStyles.ChildNodesPadding))
152 ChildNodesPadding = from.ChildNodesPadding;
154 if (from.CheckBit ((int) TreeNodeStyles.HorizontalPadding))
155 HorizontalPadding = from.HorizontalPadding;
157 if (from.CheckBit ((int) TreeNodeStyles.ImageUrl))
158 ImageUrl = from.ImageUrl;
160 if (from.CheckBit ((int) TreeNodeStyles.NodeSpacing))
161 NodeSpacing = from.NodeSpacing;
163 if (from.CheckBit ((int) TreeNodeStyles.VerticalPadding))
164 VerticalPadding = from.VerticalPadding;
167 public override void MergeWith(Style s)
169 if(s != null && !s.IsEmpty)
177 TreeNodeStyle with = s as TreeNodeStyle;
178 if (with == null) return;
180 if (with.CheckBit ((int) TreeNodeStyles.ChildNodesPadding) && !CheckBit ((int) TreeNodeStyles.ChildNodesPadding)) {
181 ChildNodesPadding = with.ChildNodesPadding;
183 if (with.CheckBit ((int) TreeNodeStyles.HorizontalPadding) && !CheckBit ((int) TreeNodeStyles.HorizontalPadding)) {
184 HorizontalPadding = with.HorizontalPadding;
186 if (with.CheckBit ((int) TreeNodeStyles.ImageUrl) && !CheckBit ((int) TreeNodeStyles.ImageUrl)) {
187 ImageUrl = with.ImageUrl;
189 if (with.CheckBit ((int) TreeNodeStyles.NodeSpacing) && !CheckBit ((int) TreeNodeStyles.NodeSpacing)) {
190 NodeSpacing = with.NodeSpacing;
192 if (with.CheckBit ((int) TreeNodeStyles.VerticalPadding) && !CheckBit ((int) TreeNodeStyles.VerticalPadding)) {
193 VerticalPadding = with.VerticalPadding;
198 public override void Reset()
200 if (CheckBit ((int) TreeNodeStyles.ChildNodesPadding))
201 ViewState.Remove(CHILD_PADD);
202 if (CheckBit ((int) TreeNodeStyles.HorizontalPadding))
203 ViewState.Remove(HORZ_PADD);
204 if (CheckBit ((int) TreeNodeStyles.ImageUrl))
205 ViewState.Remove(IMG_URL);
206 if (CheckBit ((int) TreeNodeStyles.NodeSpacing))
207 ViewState.Remove(SPACING);
208 if (CheckBit ((int) TreeNodeStyles.VerticalPadding))
209 ViewState.Remove(VERT_PADD);
213 protected override void FillStyleAttributes (CssStyleCollection attributes, IUrlResolutionService urlResolver) {
214 base.FillStyleAttributes (attributes, urlResolver);
215 if (CheckBit ((int) TreeNodeStyles.HorizontalPadding)) {
216 attributes.Add (HtmlTextWriterStyle.PaddingLeft, HorizontalPadding.ToString ());
217 attributes.Add (HtmlTextWriterStyle.PaddingRight, HorizontalPadding.ToString ());
219 if (CheckBit ((int) TreeNodeStyles.VerticalPadding)) {
220 attributes.Add (HtmlTextWriterStyle.PaddingTop, VerticalPadding.ToString ());
221 attributes.Add (HtmlTextWriterStyle.PaddingBottom, VerticalPadding.ToString ());