[tests] Separate MONO_PATH directories by PLATFORM_PATH_SEPARATOR
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / HyperLink.cs
1 //
2 // System.Web.UI.WebControls.Label.cs
3 //
4 // Authors:
5 //      Ben Maurer (bmaurer@novell.com)
6 //
7 // (C) 2005-2010 Novell, Inc (http://www.novell.com)
8 //
9 // TODO: Are we missing something in LoadViewState?
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System.ComponentModel;
32 using System.Security.Permissions;
33
34 namespace System.Web.UI.WebControls
35 {
36         // CAS
37         [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
38         [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
39         // attributes
40         [ControlBuilder(typeof(HyperLinkControlBuilder))]
41         [DataBindingHandler("System.Web.UI.Design.HyperLinkDataBindingHandler, " + Consts.AssemblySystem_Design)]
42         [ParseChildren (false)]
43         [ToolboxData("<{0}:HyperLink runat=\"server\">HyperLink</{0}:HyperLink>")]
44         [DefaultProperty("Text")]
45         [Designer("System.Web.UI.Design.WebControls.HyperLinkDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
46         public class HyperLink : WebControl
47         {
48                 public HyperLink () : base (HtmlTextWriterTag.A)
49                 {
50                 }
51                                 
52                 protected override void AddAttributesToRender (HtmlTextWriter w)
53                 {
54                         base.AddAttributesToRender (w);
55                         AddDisplayStyleAttribute (w);
56                         if (!IsEnabled)
57                                 return;
58                         // add attributes - only if they're not empty
59                         string t = Target;
60                         string s = NavigateUrl;
61                         if (s.Length > 0)
62                                 w.AddAttribute (HtmlTextWriterAttribute.Href, ResolveClientUrl (s));
63                         if (t.Length > 0)
64                                 w.AddAttribute (HtmlTextWriterAttribute.Target, t);
65                 }
66                 
67                 protected override void AddParsedSubObject (object obj)
68                 {
69                         if (HasControls ()) {
70                                 base.AddParsedSubObject (obj);
71                                 return;
72                         }
73                         
74                         LiteralControl lc = obj as LiteralControl;
75
76                         if (lc == null) {
77                                 string s = Text;
78                                 if (s.Length != 0) {
79                                         Text = null;
80                                         Controls.Add (new LiteralControl (s));
81                                 }
82                                 base.AddParsedSubObject (obj);
83                         } else
84                                 Text = lc.Text;
85                 }
86
87                 [MonoTODO ("Why override?")]
88                 protected override void LoadViewState (object savedState)
89                 {
90                         base.LoadViewState (savedState);
91                 }
92                 
93                 protected internal override void RenderContents (HtmlTextWriter w)      
94                 {
95                         if (HasControls () || HasRenderMethodDelegate ()) {
96                                 base.RenderContents (w);
97                                 return;
98                         }
99                         string image_url = ImageUrl;
100                         if (!String.IsNullOrEmpty (image_url)) {
101                                 string str = ToolTip;
102                                 if (!String.IsNullOrEmpty (str))
103                                         w.AddAttribute (HtmlTextWriterAttribute.Title, str);
104
105                                 w.AddAttribute (HtmlTextWriterAttribute.Src, ResolveClientUrl (image_url));
106                                 str = Text;
107                                         w.AddAttribute (HtmlTextWriterAttribute.Alt, str);
108                                 w.RenderBeginTag (HtmlTextWriterTag.Img);
109                                 w.RenderEndTag ();
110                         } else
111                                 w.Write (Text);
112                 }
113
114                 [Bindable(true)]
115                 [DefaultValue("")]
116                 [Editor("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, typeof(System.Drawing.Design.UITypeEditor))]
117                 [UrlProperty]
118                 [WebSysDescription ("")]
119                 [WebCategory ("Appearance")]
120                 public virtual string ImageUrl {
121                         get { return ViewState.GetString ("ImageUrl", String.Empty); }
122                         set { ViewState ["ImageUrl"] = value; } 
123                 }
124                 
125                 [Bindable(true)]
126                 [DefaultValue("")]
127                 [Editor("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, typeof(System.Drawing.Design.UITypeEditor))]
128                 [UrlProperty]
129                 [WebSysDescription ("")]
130                 [WebCategory ("Navigation")]
131                 public string NavigateUrl {
132                         get { return ViewState.GetString ("NavigateUrl", String.Empty); }
133                         set { ViewState ["NavigateUrl"] = value; }      
134                 }
135                 
136                 [DefaultValue("")]
137                 [TypeConverter(typeof(System.Web.UI.WebControls.TargetConverter))]
138                 [WebSysDescription ("")]
139                 [WebCategory ("Navigation")]
140                 public string Target {
141                         get { return ViewState.GetString ("Target", String.Empty); }
142                         set { ViewState ["Target"] = value; }
143                 }
144                 
145                 [Bindable(true)]
146                 [DefaultValue("")]
147                 [PersistenceMode(PersistenceMode.InnerDefaultProperty)]
148                 [Localizable (true)]
149                 [WebSysDescription ("")]
150                 [WebCategory ("Appearance")]
151                 public virtual string Text {
152                         get { return ViewState.GetString ("Text", String.Empty); }
153                         set {
154                                 ViewState ["Text"] = value;
155                                 if (HasControls ())
156                                         Controls.Clear ();
157                         }
158                 }
159                 public override bool SupportsDisabledAttribute {
160                         get { return RenderingCompatibilityLessThan40; }
161                 }
162         }
163 }