2004-11-23 Lluis Sanchez Gual <lluis@novell.com>
[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
36 namespace System.Web.UI.WebControls
37 {
38         public sealed class TreeNodeStyle: Style
39         {
40                 private static int CHILD_PADD = (0x01 << 16);
41                 private static int HORZ_PADD = (0x01 << 17);
42                 private static int IMG_URL = (0x01 << 18);
43                 private static int SPACING = (0x01 << 19);
44                 private static int VERT_PADD = (0x01 << 20);
45                 
46                 public string ImageUrl {
47                         get {
48                                 if(IsSet(IMG_URL))
49                                         return (string)(ViewState["ImageUrl"]);
50                                 return String.Empty;
51                         }
52                         set {
53                                 if(value == null)
54                                         throw new ArgumentNullException("value");
55                                 ViewState["ImageUrl"] = value;
56                                 Set(IMG_URL);
57                         }
58                 }
59
60                 public int ChildNodesPadding {
61                         get {
62                                 if(IsSet(CHILD_PADD))
63                                         return (int)(ViewState["ChildNodesPadding"]);
64                                 return 0;
65                         }
66                         set {
67                                 ViewState["ChildNodesPadding"] = value;
68                                 Set(CHILD_PADD);
69                         }
70                 }
71
72                 public int HorizontalPadding {
73                         get {
74                                 if(IsSet(HORZ_PADD))
75                                         return (int)(ViewState["HorizontalPadding"]);
76                                 return 0;
77                         }
78                         set {
79                                 ViewState["HorizontalPadding"] = value;
80                                 Set(HORZ_PADD);
81                         }
82                 }
83
84                 public int VerticalPadding {
85                         get {
86                                 if(IsSet(VERT_PADD))
87                                         return (int)(ViewState["VerticalPadding"]);
88                                 return 0;
89                         }
90                         set {
91                                 ViewState["VerticalPadding"] = value;
92                                 Set(VERT_PADD);
93                         }
94                 }
95
96                 public int NodeSpacing {
97                         get {
98                                 if(IsSet(SPACING))
99                                         return (int)(ViewState["NodeSpacing"]);
100                                 return 0;
101                         }
102                         set {
103                                 ViewState["NodeSpacing"] = value;
104                                 Set(SPACING);
105                         }
106                 }
107
108                 protected internal override bool IsEmpty {
109                         get { return base.IsEmpty; }
110                 }
111                 
112                 public override void CopyFrom (Style s)
113                 {
114                         if (s == null || s.IsEmpty)
115                                 return;
116
117                         base.CopyFrom (s);
118                         TreeNodeStyle from = s as TreeNodeStyle;
119                         if (from == null)
120                                 return;
121
122                         if (from.IsSet (CHILD_PADD))
123                                 ChildNodesPadding = from.ChildNodesPadding;
124
125                         if (from.IsSet (HORZ_PADD))
126                                 HorizontalPadding = from.HorizontalPadding;
127
128                         if (from.IsSet (IMG_URL))
129                                 ImageUrl = from.ImageUrl;
130
131                         if (from.IsSet (SPACING))
132                                 NodeSpacing = from.NodeSpacing;
133
134                         if (from.IsSet (VERT_PADD))
135                                 VerticalPadding = from.VerticalPadding;
136                 }
137                 
138                 public override void MergeWith(Style s)
139                 {
140                         if(s != null && !s.IsEmpty)
141                         {
142                                 if (IsEmpty) {
143                                         CopyFrom (s);
144                                         return;
145                                 }
146                                 base.MergeWith(s);
147
148                                 TreeNodeStyle with = s as TreeNodeStyle;
149                                 if (with == null) return;
150                                 
151                                 if (with.IsSet(CHILD_PADD) && !IsSet(CHILD_PADD)) {
152                                         ChildNodesPadding = with.ChildNodesPadding;
153                                 }
154                                 if (with.IsSet(HORZ_PADD) && !IsSet(HORZ_PADD)) {
155                                         HorizontalPadding = with.HorizontalPadding;
156                                 }
157                                 if (with.IsSet(IMG_URL) && !IsSet(IMG_URL)) {
158                                         ImageUrl = with.ImageUrl;
159                                 }
160                                 if (with.IsSet(SPACING) && !IsSet(SPACING)) {
161                                         NodeSpacing = with.NodeSpacing;
162                                 }
163                                 if (with.IsSet(VERT_PADD) && !IsSet(VERT_PADD)) {
164                                         VerticalPadding = with.VerticalPadding;
165                                 }
166                         }
167                 }
168
169                 public override void Reset()
170                 {
171                         if(IsSet(CHILD_PADD))
172                                 ViewState.Remove("ChildNodesPadding");
173                         if(IsSet(HORZ_PADD))
174                                 ViewState.Remove("HorizontalPadding");
175                         if(IsSet(IMG_URL))
176                                 ViewState.Remove("ImageUrl");
177                         if(IsSet(SPACING))
178                                 ViewState.Remove("NodeSpacing");
179                         if(IsSet(VERT_PADD))
180                                 ViewState.Remove("VerticalPadding");
181                         base.Reset();
182                 }
183         }
184 }
185
186 #endif