2004-12-03 Lluis Sanchez Gual <lluis@novell.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / MenuItemStyle.cs
1 //
2 // System.Web.UI.WebControls.MenuItemStyle.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 class MenuItemStyle: Style
40         {
41                 private static int HORZ_PADD = (0x01 << 16);
42                 private static int SPACING = (0x01 << 17);
43                 private static int VERT_PADD = (0x01 << 18);
44                 
45                 [DefaultValue (0)]
46                 [NotifyParentProperty (true)]
47                 public int HorizontalPadding {
48                         get {
49                                 if(IsSet(HORZ_PADD))
50                                         return (int)(ViewState["HorizontalPadding"]);
51                                 return 0;
52                         }
53                         set {
54                                 ViewState["HorizontalPadding"] = value;
55                                 Set(HORZ_PADD);
56                         }
57                 }
58
59                 [DefaultValue (0)]
60                 [NotifyParentProperty (true)]
61                 public int VerticalPadding {
62                         get {
63                                 if(IsSet(VERT_PADD))
64                                         return (int)(ViewState["VerticalPadding"]);
65                                 return 0;
66                         }
67                         set {
68                                 ViewState["VerticalPadding"] = value;
69                                 Set(VERT_PADD);
70                         }
71                 }
72
73                 [DefaultValue (0)]
74                 [NotifyParentProperty (true)]
75                 public int ItemSpacing {
76                         get {
77                                 if(IsSet(SPACING))
78                                         return (int)(ViewState["ItemSpacing"]);
79                                 return 0;
80                         }
81                         set {
82                                 ViewState["ItemSpacing"] = value;
83                                 Set(SPACING);
84                         }
85                 }
86
87                 protected internal override bool IsEmpty {
88                         get { return base.IsEmpty; }
89                 }
90                 
91                 public override void CopyFrom (Style s)
92                 {
93                         if (s == null || s.IsEmpty)
94                                 return;
95
96                         base.CopyFrom (s);
97                         MenuItemStyle from = s as MenuItemStyle;
98                         if (from == null)
99                                 return;
100
101                         if (from.IsSet (HORZ_PADD))
102                                 HorizontalPadding = from.HorizontalPadding;
103
104                         if (from.IsSet (SPACING))
105                                 ItemSpacing = from.ItemSpacing;
106
107                         if (from.IsSet (VERT_PADD))
108                                 VerticalPadding = from.VerticalPadding;
109                 }
110                 
111                 public override void MergeWith(Style s)
112                 {
113                         if(s != null && !s.IsEmpty)
114                         {
115                                 if (IsEmpty) {
116                                         CopyFrom (s);
117                                         return;
118                                 }
119                                 base.MergeWith(s);
120
121                                 MenuItemStyle with = s as MenuItemStyle;
122                                 if (with == null) return;
123                                 
124                                 if (with.IsSet(HORZ_PADD) && !IsSet(HORZ_PADD)) {
125                                         HorizontalPadding = with.HorizontalPadding;
126                                 }
127                                 if (with.IsSet(SPACING) && !IsSet(SPACING)) {
128                                         ItemSpacing = with.ItemSpacing;
129                                 }
130                                 if (with.IsSet(VERT_PADD) && !IsSet(VERT_PADD)) {
131                                         VerticalPadding = with.VerticalPadding;
132                                 }
133                         }
134                 }
135
136                 public override void Reset()
137                 {
138                         if(IsSet(HORZ_PADD))
139                                 ViewState.Remove("HorizontalPadding");
140                         if(IsSet(SPACING))
141                                 ViewState.Remove("ItemSpacing");
142                         if(IsSet(VERT_PADD))
143                                 ViewState.Remove("VerticalPadding");
144                         base.Reset();
145                 }
146         }
147 }
148
149 #endif