create TableStyle in CreateControlStyle.
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / TreeNodeStyle.cs
1 //
2 // System.Web.UI.WebControls.TreeNodeStyle.cs
3 //
4 // Authors:
5 //      Lluis Sanchez Gual (lluis@novell.com)
6 //
7 // (C) 2004 Novell, Inc (http://www.novell.com)
8 //
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:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
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.
27 //
28 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
29 //
30
31 #if NET_2_0
32
33 using System;
34 using System.Web.UI;
35 using System.ComponentModel;
36
37 namespace System.Web.UI.WebControls
38 {
39         public sealed class TreeNodeStyle: Style
40         {
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";
46                 
47                 bool IsSet (string v)
48                 {
49                         return ViewState [v] != null;
50                 }
51                 
52                 [DefaultValue ("")]
53                 [UrlProperty]
54                 [NotifyParentProperty (true)]
55                 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
56                 public string ImageUrl {
57                         get {
58                                 return ViewState.GetString (IMG_URL, String.Empty);
59                         }
60                         set {
61                                 if(value == null)
62                                         throw new ArgumentNullException("value");
63                                 ViewState [IMG_URL] = value;
64                         }
65                 }
66
67                 [DefaultValue (0)]
68                 [NotifyParentProperty (true)]
69                 public int ChildNodesPadding {
70                         get {
71                                 return ViewState.GetInt (CHILD_PADD, 0);
72                         }
73                         set {
74                                 ViewState [CHILD_PADD] = value;
75                         }
76                 }
77
78                 [DefaultValue (0)]
79                 [NotifyParentProperty (true)]
80                 public int HorizontalPadding {
81                         get {
82                                 return ViewState.GetInt (HORZ_PADD, 0);
83                         }
84                         set {
85                                 ViewState[HORZ_PADD] = value;
86                         }
87                 }
88
89                 [DefaultValue (0)]
90                 [NotifyParentProperty (true)]
91                 public int VerticalPadding {
92                         get {
93                                 return ViewState.GetInt (VERT_PADD, 0);
94                         }
95                         set {
96                                 ViewState [VERT_PADD] = value;
97                         }
98                 }
99
100                 [DefaultValue (0)]
101                 [NotifyParentProperty (true)]
102                 public int NodeSpacing {
103                         get {
104                                 return ViewState.GetInt (SPACING, 0);
105                         }
106                         set {
107                                 ViewState [SPACING] = value;
108                         }
109                 }
110
111                 // FIXME: shouldn't be part of the public API
112                 public override bool IsEmpty {
113                         get {
114                                 return (base.IsEmpty &&
115                                         !IsSet (CHILD_PADD) &&
116                                         !IsSet (HORZ_PADD) &&
117                                         !IsSet (IMG_URL) &&
118                                         !IsSet (SPACING) &&
119                                         !IsSet (VERT_PADD));
120                         }
121                 }
122                 
123                 public override void CopyFrom (Style s)
124                 {
125                         if (s == null || s.IsEmpty)
126                                 return;
127
128                         base.CopyFrom (s);
129                         TreeNodeStyle from = s as TreeNodeStyle;
130                         if (from == null)
131                                 return;
132
133                         if (from.IsSet (CHILD_PADD))
134                                 ChildNodesPadding = from.ChildNodesPadding;
135
136                         if (from.IsSet (HORZ_PADD))
137                                 HorizontalPadding = from.HorizontalPadding;
138
139                         if (from.IsSet (IMG_URL))
140                                 ImageUrl = from.ImageUrl;
141
142                         if (from.IsSet (SPACING))
143                                 NodeSpacing = from.NodeSpacing;
144
145                         if (from.IsSet (VERT_PADD))
146                                 VerticalPadding = from.VerticalPadding;
147                 }
148                 
149                 public override void MergeWith(Style s)
150                 {
151                         if(s != null && !s.IsEmpty)
152                         {
153                                 if (IsEmpty) {
154                                         CopyFrom (s);
155                                         return;
156                                 }
157                                 base.MergeWith(s);
158
159                                 TreeNodeStyle with = s as TreeNodeStyle;
160                                 if (with == null) return;
161                                 
162                                 if (with.IsSet(CHILD_PADD) && !IsSet(CHILD_PADD)) {
163                                         ChildNodesPadding = with.ChildNodesPadding;
164                                 }
165                                 if (with.IsSet(HORZ_PADD) && !IsSet(HORZ_PADD)) {
166                                         HorizontalPadding = with.HorizontalPadding;
167                                 }
168                                 if (with.IsSet(IMG_URL) && !IsSet(IMG_URL)) {
169                                         ImageUrl = with.ImageUrl;
170                                 }
171                                 if (with.IsSet(SPACING) && !IsSet(SPACING)) {
172                                         NodeSpacing = with.NodeSpacing;
173                                 }
174                                 if (with.IsSet(VERT_PADD) && !IsSet(VERT_PADD)) {
175                                         VerticalPadding = with.VerticalPadding;
176                                 }
177                         }
178                 }
179
180                 public override void Reset()
181                 {
182                         if(IsSet(CHILD_PADD))
183                                 ViewState.Remove("ChildNodesPadding");
184                         if(IsSet(HORZ_PADD))
185                                 ViewState.Remove("HorizontalPadding");
186                         if(IsSet(IMG_URL))
187                                 ViewState.Remove("ImageUrl");
188                         if(IsSet(SPACING))
189                                 ViewState.Remove("NodeSpacing");
190                         if(IsSet(VERT_PADD))
191                                 ViewState.Remove("VerticalPadding");
192                         base.Reset();
193                 }
194         }
195 }
196
197 #endif