TableItemStyle.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. //
  2. // Permission is hereby granted, free of charge, to any person obtaining
  3. // a copy of this software and associated documentation files (the
  4. // "Software"), to deal in the Software without restriction, including
  5. // without limitation the rights to use, copy, modify, merge, publish,
  6. // distribute, sublicense, and/or sell copies of the Software, and to
  7. // permit persons to whom the Software is furnished to do so, subject to
  8. // the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be
  11. // included in all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  14. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  17. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  18. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  19. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. //
  21. /**
  22. * Namespace: System.Web.UI.WebControls
  23. * Class: TableItemStyle
  24. *
  25. * Author: Gaurav Vaish
  26. * Maintainer: [email protected]
  27. * Contact: <[email protected]>, <[email protected]>
  28. * Implementation: yes
  29. * Status: 100%
  30. *
  31. * (C) Gaurav Vaish (2002)
  32. */
  33. using System;
  34. using System.ComponentModel;
  35. using System.Web;
  36. using System.Web.UI;
  37. namespace System.Web.UI.WebControls
  38. {
  39. public class TableItemStyle: Style
  40. {
  41. private static int H_ALIGN = (0x01 << 16);
  42. private static int V_ALIGN = (0x01 << 17);
  43. private static int WRAP = (0x01 << 18);
  44. public TableItemStyle(): base()
  45. {
  46. }
  47. public TableItemStyle(StateBag bag): base(bag)
  48. {
  49. }
  50. [Bindable(true)]
  51. [DefaultValue(HorizontalAlign.NotSet)]
  52. [NotifyParentProperty(true)]
  53. [WebCategory("Layout")]
  54. [WebSysDescription("TableItemStyle_HorizontalAlign")]
  55. public virtual HorizontalAlign HorizontalAlign
  56. {
  57. get
  58. {
  59. if(IsSet(H_ALIGN))
  60. return (HorizontalAlign)ViewState["HorizontalAlign"];
  61. return HorizontalAlign.NotSet;
  62. }
  63. set
  64. {
  65. if(!Enum.IsDefined(typeof(HorizontalAlign), value))
  66. {
  67. throw new ArgumentException();
  68. }
  69. ViewState["HorizontalAlign"] = value;
  70. Set(H_ALIGN);
  71. }
  72. }
  73. [Bindable(true)]
  74. [DefaultValue(VerticalAlign.NotSet)]
  75. [NotifyParentProperty(true)]
  76. [WebCategory("Layout")]
  77. [WebSysDescription("TableItemStyle_VerticalAlign")]
  78. public virtual VerticalAlign VerticalAlign
  79. {
  80. get
  81. {
  82. if(IsSet(V_ALIGN))
  83. return (VerticalAlign)ViewState["VerticalAlign"];
  84. return VerticalAlign.NotSet;
  85. }
  86. set
  87. {
  88. if(!Enum.IsDefined(typeof(VerticalAlign), value))
  89. {
  90. throw new ArgumentException();
  91. }
  92. ViewState["VerticalAlign"] = value;
  93. Set(V_ALIGN);
  94. }
  95. }
  96. [Bindable(true)]
  97. [DefaultValue(VerticalAlign.NotSet)]
  98. [NotifyParentProperty(true)]
  99. [WebCategory("Layout")]
  100. [WebSysDescription("TableItemStyle_Wrap")]
  101. public virtual bool Wrap
  102. {
  103. get
  104. {
  105. if(IsSet(WRAP))
  106. return (bool)ViewState["Wrap"];
  107. return true;
  108. }
  109. set
  110. {
  111. ViewState["Wrap"] = value;
  112. Set(WRAP);
  113. }
  114. }
  115. public override void CopyFrom(Style s)
  116. {
  117. if(s!=null && !s.IsEmpty)
  118. {
  119. base.CopyFrom(s);
  120. if (!(s is TableItemStyle))
  121. return;
  122. TableItemStyle from = (TableItemStyle)s;
  123. if(from.IsSet(H_ALIGN))
  124. {
  125. HorizontalAlign = from.HorizontalAlign;
  126. }
  127. if(from.IsSet(V_ALIGN))
  128. {
  129. VerticalAlign = from.VerticalAlign;
  130. }
  131. if(from.IsSet(WRAP))
  132. {
  133. Wrap = from.Wrap;
  134. }
  135. }
  136. }
  137. public override void MergeWith(Style s)
  138. {
  139. if(s!=null && !s.IsEmpty)
  140. {
  141. if (IsEmpty) {
  142. CopyFrom (s);
  143. return;
  144. }
  145. base.MergeWith(s);
  146. if (!(s is TableItemStyle))
  147. return;
  148. TableItemStyle with = (TableItemStyle)s;
  149. if(with.IsSet(H_ALIGN) && !IsSet(H_ALIGN))
  150. {
  151. HorizontalAlign = with.HorizontalAlign;
  152. }
  153. if(with.IsSet(V_ALIGN) && !IsSet(V_ALIGN))
  154. {
  155. VerticalAlign = with.VerticalAlign;
  156. }
  157. if(with.IsSet(WRAP) && !IsSet(WRAP))
  158. {
  159. Wrap = with.Wrap;
  160. }
  161. }
  162. }
  163. public override void Reset()
  164. {
  165. if(IsSet(H_ALIGN))
  166. ViewState.Remove("HorizontalAlign");
  167. if(IsSet(V_ALIGN))
  168. ViewState.Remove("VerticalAlign");
  169. if(IsSet(WRAP))
  170. ViewState.Remove("Wrap");
  171. base.Reset();
  172. }
  173. public override void AddAttributesToRender(HtmlTextWriter writer, WebControl owner)
  174. {
  175. base.AddAttributesToRender(writer, owner);
  176. if(!Wrap)
  177. {
  178. writer.AddAttribute(HtmlTextWriterAttribute.Nowrap, "nowrap");
  179. }
  180. if(HorizontalAlign != HorizontalAlign.NotSet)
  181. {
  182. // Temporarily commented out. I'm having problems in cygwin.
  183. //writer.AddAttribute(HtmlTextWriterAttribute.Align, TypeDescriptor.GetConverter(typeof(HorizontalAlign)).ConvertToString(HorizontalAlign));
  184. writer.AddAttribute(HtmlTextWriterAttribute.Align, HorizontalAlign.ToString ());
  185. }
  186. if(VerticalAlign != VerticalAlign.NotSet)
  187. {
  188. // Temporarily commented out. I'm having problems in cygwin.
  189. //writer.AddAttribute(HtmlTextWriterAttribute.Valign, TypeDescriptor.GetConverter(typeof(VerticalAlign)).ConvertToString(VerticalAlign));
  190. writer.AddAttribute(HtmlTextWriterAttribute.Valign, VerticalAlign.ToString ());
  191. }
  192. }
  193. }
  194. }