TableItemStyle.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /**
  2. * Namespace: System.Web.UI.WebControls
  3. * Class: TableItemStyle
  4. *
  5. * Author: Gaurav Vaish
  6. * Maintainer: [email protected]
  7. * Contact: <[email protected]>, <[email protected]>
  8. * Implementation: yes
  9. * Status: 100%
  10. *
  11. * (C) Gaurav Vaish (2002)
  12. */
  13. using System;
  14. using System.ComponentModel;
  15. using System.Web;
  16. using System.Web.UI;
  17. namespace System.Web.UI.WebControls
  18. {
  19. public class TableItemStyle: Style
  20. {
  21. private static int H_ALIGN = (0x01 << 16);
  22. private static int V_ALIGN = (0x01 << 17);
  23. private static int WRAP = (0x01 << 18);
  24. public TableItemStyle(): base()
  25. {
  26. }
  27. public TableItemStyle(StateBag bag): base(bag)
  28. {
  29. }
  30. [Bindable(true)]
  31. [DefaultValue(HorizontalAlign.NotSet)]
  32. [NotifyParentProperty(true)]
  33. [WebCategory("Layout")]
  34. [WebSysDescription("TableItemStyle_HorizontalAlign")]
  35. public virtual HorizontalAlign HorizontalAlign
  36. {
  37. get
  38. {
  39. if(IsSet(H_ALIGN))
  40. return (HorizontalAlign)ViewState["HorizontalAlign"];
  41. return HorizontalAlign.NotSet;
  42. }
  43. set
  44. {
  45. if(!Enum.IsDefined(typeof(HorizontalAlign), value))
  46. {
  47. throw new ArgumentException();
  48. }
  49. ViewState["HorizontalAlign"] = value;
  50. Set(H_ALIGN);
  51. }
  52. }
  53. [Bindable(true)]
  54. [DefaultValue(VerticalAlign.NotSet)]
  55. [NotifyParentProperty(true)]
  56. [WebCategory("Layout")]
  57. [WebSysDescription("TableItemStyle_VerticalAlign")]
  58. public virtual VerticalAlign VerticalAlign
  59. {
  60. get
  61. {
  62. if(IsSet(V_ALIGN))
  63. return (VerticalAlign)ViewState["VerticalAlign"];
  64. return VerticalAlign.NotSet;
  65. }
  66. set
  67. {
  68. if(!Enum.IsDefined(typeof(VerticalAlign), value))
  69. {
  70. throw new ArgumentException();
  71. }
  72. ViewState["VerticalAlign"] = value;
  73. Set(V_ALIGN);
  74. }
  75. }
  76. [Bindable(true)]
  77. [DefaultValue(VerticalAlign.NotSet)]
  78. [NotifyParentProperty(true)]
  79. [WebCategory("Layout")]
  80. [WebSysDescription("TableItemStyle_Wrap")]
  81. public virtual bool Wrap
  82. {
  83. get
  84. {
  85. if(IsSet(WRAP))
  86. return (bool)ViewState["Wrap"];
  87. return true;
  88. }
  89. set
  90. {
  91. ViewState["Wrap"] = value;
  92. }
  93. }
  94. public override void CopyFrom(Style s)
  95. {
  96. if(s!=null && s is TableItemStyle && !s.IsEmpty)
  97. {
  98. base.CopyFrom(s);
  99. TableItemStyle from = (TableItemStyle)s;
  100. if(from.IsSet(H_ALIGN))
  101. {
  102. HorizontalAlign = from.HorizontalAlign;
  103. }
  104. if(from.IsSet(V_ALIGN))
  105. {
  106. VerticalAlign = from.VerticalAlign;
  107. }
  108. if(from.IsSet(WRAP))
  109. {
  110. Wrap = from.Wrap;
  111. }
  112. }
  113. }
  114. public override void MergeWith(Style s)
  115. {
  116. if(s!=null && s is TableItemStyle && !s.IsEmpty)
  117. {
  118. base.MergeWith(s);
  119. TableItemStyle with = (TableItemStyle)s;
  120. if(with.IsSet(H_ALIGN) && !IsSet(H_ALIGN))
  121. {
  122. HorizontalAlign = with.HorizontalAlign;
  123. }
  124. if(with.IsSet(V_ALIGN) && !IsSet(V_ALIGN))
  125. {
  126. VerticalAlign = with.VerticalAlign;
  127. }
  128. if(with.IsSet(WRAP) && !IsSet(WRAP))
  129. {
  130. Wrap = with.Wrap;
  131. }
  132. }
  133. }
  134. public override void Reset()
  135. {
  136. if(IsSet(H_ALIGN))
  137. ViewState.Remove("HorizontalAlign");
  138. if(IsSet(V_ALIGN))
  139. ViewState.Remove("VerticalAlign");
  140. if(IsSet(WRAP))
  141. ViewState.Remove("Wrap");
  142. base.Reset();
  143. }
  144. public override void AddAttributesToRender(HtmlTextWriter writer, WebControl owner)
  145. {
  146. base.AddAttributesToRender(writer, owner);
  147. if(!Wrap)
  148. {
  149. writer.AddAttribute(HtmlTextWriterAttribute.Nowrap, "nowrap");
  150. }
  151. if(HorizontalAlign != HorizontalAlign.NotSet)
  152. {
  153. writer.AddAttribute(HtmlTextWriterAttribute.Align, TypeDescriptor.GetConverter(typeof(HorizontalAlign)).ConvertToString(HorizontalAlign));
  154. }
  155. if(VerticalAlign != VerticalAlign.NotSet)
  156. {
  157. writer.AddAttribute(HtmlTextWriterAttribute.Valign, TypeDescriptor.GetConverter(typeof(VerticalAlign)).ConvertToString(VerticalAlign));
  158. }
  159. }
  160. }
  161. }