Panel.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. //
  2. // System.Web.UI.WebControls.Panel.cs
  3. //
  4. // Authors:
  5. // Ben Maurer ([email protected])
  6. //
  7. // (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  9. // TODO: Are we missing something in LoadViewState?
  10. // What to do in AddParsedSubObject
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. using System.ComponentModel;
  32. using System.Security.Permissions;
  33. namespace System.Web.UI.WebControls {
  34. // CAS
  35. [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  36. [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  37. // attributes
  38. [Designer ("System.Web.UI.Design.WebControls.PanelDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
  39. [ParseChildren (false)]
  40. [PersistChildren (true)]
  41. [ToolboxData ("<{0}:Panel runat=server>Panel</{0}:Panel>")]
  42. public class Panel : WebControl {
  43. public Panel () : base (HtmlTextWriterTag.Div)
  44. {
  45. }
  46. protected override void AddAttributesToRender (HtmlTextWriter w)
  47. {
  48. base.AddAttributesToRender (w);
  49. string image = BackImageUrl;
  50. if (image != "") {
  51. image = String.Format ("url({0})", image);
  52. w.AddStyleAttribute (HtmlTextWriterStyle.BackgroundImage, image);
  53. }
  54. #if NET_2_0
  55. if (!String.IsNullOrEmpty (DefaultButton) && Page != null) {
  56. Control button = FindControl (DefaultButton);
  57. if (button == null || !(button is IButtonControl))
  58. throw new InvalidOperationException (String.Format ("The DefaultButton of '{0}' must be the ID of a control of type IButtonControl.", ID));
  59. w.AddAttribute ("onkeypress", String.Format ("javascript:return WebForm_FireDefaultButton(event, '{0}')", button.ClientID));
  60. }
  61. if (Direction != ContentDirection.NotSet) {
  62. w.AddAttribute (HtmlTextWriterAttribute.Dir, Direction == ContentDirection.RightToLeft ? "rtl" : "ltr");
  63. }
  64. switch (ScrollBars) {
  65. case ScrollBars.Auto:
  66. w.AddStyleAttribute (HtmlTextWriterStyle.Overflow, "auto");
  67. break;
  68. case ScrollBars.Both:
  69. w.AddStyleAttribute (HtmlTextWriterStyle.Overflow, "scroll");
  70. break;
  71. case ScrollBars.Horizontal:
  72. w.AddStyleAttribute (HtmlTextWriterStyle.OverflowX, "scroll");
  73. break;
  74. case ScrollBars.Vertical:
  75. w.AddStyleAttribute (HtmlTextWriterStyle.OverflowY, "scroll");
  76. break;
  77. }
  78. #endif
  79. if (!Wrap) {
  80. #if NET_2_0
  81. w.AddStyleAttribute (HtmlTextWriterStyle.WhiteSpace, "nowrap");
  82. #else
  83. w.AddAttribute (HtmlTextWriterAttribute.Nowrap, "nowrap");
  84. #endif
  85. }
  86. string align = "";
  87. switch (HorizontalAlign) {
  88. case HorizontalAlign.Center: align = "center"; break;
  89. case HorizontalAlign.Justify: align = "justify"; break;
  90. case HorizontalAlign.Left: align = "left"; break;
  91. case HorizontalAlign.Right: align = "right"; break;
  92. }
  93. if (align != "")
  94. #if NET_2_0
  95. w.AddStyleAttribute (HtmlTextWriterStyle.TextAlign, align);
  96. #else
  97. w.AddAttribute (HtmlTextWriterAttribute.Align, align);
  98. #endif
  99. }
  100. #if !NET_2_0
  101. [Bindable(true)]
  102. [DefaultValue("")]
  103. [Editor("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, typeof(System.Drawing.Design.UITypeEditor))]
  104. [WebSysDescription ("")]
  105. [WebCategory ("Appearance")]
  106. public virtual string BackImageUrl {
  107. get {
  108. return ViewState.GetString ("BackImageUrl", "");
  109. }
  110. set {
  111. ViewState ["BackImageUrl"] = value;
  112. }
  113. }
  114. [Bindable(true)]
  115. [DefaultValue(HorizontalAlign.NotSet)]
  116. [WebSysDescription ("")]
  117. [WebCategory ("Layout")]
  118. public virtual HorizontalAlign HorizontalAlign {
  119. get {
  120. return (HorizontalAlign) ViewState.GetInt ("HorizontalAlign", (int) HorizontalAlign.NotSet);
  121. }
  122. set {
  123. ViewState ["HorizontalAlign"] = (int) value;
  124. }
  125. }
  126. [Bindable(true)]
  127. [DefaultValue(true)]
  128. [WebSysDescription ("")]
  129. [WebCategory ("Layout")]
  130. public virtual bool Wrap {
  131. get {
  132. return ViewState.GetBool ("Wrap", true);
  133. }
  134. set {
  135. ViewState ["Wrap"] = value;
  136. }
  137. }
  138. #endif
  139. #if NET_2_0
  140. PanelStyle PanelStyle {
  141. get { return (ControlStyle as PanelStyle); }
  142. }
  143. [Bindable (true)]
  144. [DefaultValue ("")]
  145. [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
  146. [WebSysDescription ("")]
  147. [WebCategory ("Appearance")]
  148. public virtual string BackImageUrl {
  149. get {
  150. if (ControlStyleCreated) {
  151. if (PanelStyle != null)
  152. return PanelStyle.BackImageUrl;
  153. else
  154. return ViewState.GetString ("BackImageUrl", String.Empty);
  155. }
  156. return String.Empty;
  157. }
  158. set {
  159. if(PanelStyle!=null)
  160. PanelStyle.BackImageUrl = value;
  161. else
  162. ViewState ["BackImageUrl"] = value;
  163. }
  164. }
  165. [Bindable (true)]
  166. [DefaultValue (HorizontalAlign.NotSet)]
  167. [WebSysDescription ("")]
  168. [WebCategory ("Layout")]
  169. public virtual HorizontalAlign HorizontalAlign {
  170. get {
  171. if (ControlStyleCreated) {
  172. if (PanelStyle != null)
  173. return PanelStyle.HorizontalAlign;
  174. else
  175. return ViewState ["HorizontalAlign"] != null ? (HorizontalAlign) ViewState ["HorizontalAlign"] : HorizontalAlign.NotSet;
  176. }
  177. return HorizontalAlign.NotSet;
  178. }
  179. set {
  180. if (PanelStyle != null)
  181. PanelStyle.HorizontalAlign = value;
  182. else
  183. ViewState ["HorizontalAlign"] = value;
  184. }
  185. }
  186. [Bindable (true)]
  187. [DefaultValue (true)]
  188. [WebSysDescription ("")]
  189. [WebCategory ("Layout")]
  190. public virtual bool Wrap {
  191. get {
  192. if (ControlStyleCreated) {
  193. if (PanelStyle != null)
  194. return PanelStyle.Wrap;
  195. else
  196. return ViewState.GetBool ("Wrap", true);
  197. }
  198. return true;
  199. }
  200. set {
  201. if (PanelStyle != null)
  202. PanelStyle.Wrap = value;
  203. else
  204. ViewState ["Wrap"] = value;
  205. }
  206. }
  207. [ThemeableAttribute (false)]
  208. public virtual string DefaultButton {
  209. get {
  210. return ViewState.GetString ("DefaultButton", String.Empty);
  211. }
  212. set {
  213. ViewState ["DefaultButton"] = value;
  214. }
  215. }
  216. public virtual ContentDirection Direction {
  217. get {
  218. if (ControlStyleCreated) {
  219. if (PanelStyle != null)
  220. return PanelStyle.Direction;
  221. else
  222. return ViewState ["Direction"] != null ? (ContentDirection) ViewState ["Direction"] : ContentDirection.NotSet;
  223. }
  224. return ContentDirection.NotSet;
  225. }
  226. set {
  227. if (PanelStyle != null)
  228. PanelStyle.Direction = value;
  229. else
  230. ViewState ["Direction"] = value;
  231. }
  232. }
  233. [LocalizableAttribute (true)]
  234. public virtual string GroupingText {
  235. get {
  236. return ViewState.GetString ("GroupingText", String.Empty);
  237. }
  238. set {
  239. ViewState ["GroupingText"] = value;
  240. }
  241. }
  242. public virtual ScrollBars ScrollBars {
  243. get {
  244. if (ControlStyleCreated) {
  245. if (PanelStyle != null)
  246. return PanelStyle.ScrollBars;
  247. else
  248. return ViewState ["ScrollBars"] != null ? (ScrollBars) ViewState ["Direction"] : ScrollBars.None;
  249. }
  250. return ScrollBars.None;
  251. }
  252. set {
  253. if (PanelStyle != null)
  254. PanelStyle.ScrollBars = value;
  255. else
  256. ViewState ["ScrollBars"] = value;
  257. }
  258. }
  259. protected override Style CreateControlStyle ()
  260. {
  261. return new PanelStyle (ViewState);
  262. }
  263. public override void RenderBeginTag (HtmlTextWriter writer)
  264. {
  265. base.RenderBeginTag (writer);
  266. if (!String.IsNullOrEmpty (GroupingText)) {
  267. writer.RenderBeginTag (HtmlTextWriterTag.Fieldset);
  268. writer.RenderBeginTag (HtmlTextWriterTag.Legend);
  269. writer.Write (GroupingText);
  270. writer.RenderEndTag ();
  271. }
  272. }
  273. public override void RenderEndTag (HtmlTextWriter writer)
  274. {
  275. if (!String.IsNullOrEmpty (GroupingText)) {
  276. writer.RenderEndTag (); // Fieldset
  277. }
  278. base.RenderEndTag (writer);
  279. }
  280. #endif
  281. }
  282. }