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