TableItemStyle.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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.Web;
  15. using System.Web.UI;
  16. namespace System.Web.UI.WebControls
  17. {
  18. public class TableItemStyle: Style
  19. {
  20. private static int H_ALIGN = (0x01 << 16);
  21. private static int V_ALIGN = (0x01 << 17);
  22. private static int WRAP = (0x01 << 18);
  23. public TableItemStyle(): base()
  24. {
  25. }
  26. public TableItemStyle(StateBag bag): base(bag)
  27. {
  28. }
  29. public virtual HorizontalAlign HorizontalAlign
  30. {
  31. get
  32. {
  33. if(IsSet(H_ALIGN))
  34. return (HorizontalAlign)ViewState["HorizontalAlign"];
  35. return HorizontalAlign.NotSet;
  36. }
  37. set
  38. {
  39. if(!Enum.IsDefined(typeof(HorizontalAlign), value))
  40. {
  41. throw new ArgumentException();
  42. }
  43. ViewState["HorizontalAlign"] = value;
  44. Set(H_ALIGN);
  45. }
  46. }
  47. public virtual VerticalAlign VerticalAlign
  48. {
  49. get
  50. {
  51. if(IsSet(V_ALIGN))
  52. return (VerticalAlign)iewState["VerticalAlign"];
  53. return VerticalAlign.NotSet;
  54. }
  55. set
  56. {
  57. if(!Enum.IsDefined(typeof(VerticalAlign), value))
  58. {
  59. throw new ArgumentException();
  60. }
  61. ViewState["VerticalAlign"] = value;
  62. Set(V_ALIGN);
  63. }
  64. }
  65. public virtual bool Wrap
  66. {
  67. get
  68. {
  69. if(IsSet(WRAP))
  70. return (bool)ViewState["Wrap"];
  71. return true;
  72. }
  73. set
  74. {
  75. ViewState["Wrap"] = value;
  76. }
  77. }
  78. public override void CopyFrom(Style s)
  79. {
  80. if(s!=null && s is TableItemStyle && !s.IsEmpty)
  81. {
  82. base.CopyFrom(s);
  83. TableItemStyle from = (TableItemStyle)s;
  84. if(from.IsSet(H_ALIGN))
  85. {
  86. HorizontalAlign = from.HorizontalAlign;
  87. }
  88. if(from.IsSet(V_ALIGN))
  89. {
  90. VerticalAlign = from.VerticalAlign;
  91. }
  92. if(from.IsSet(WRAP))
  93. {
  94. Wrap = from.Wrap;
  95. }
  96. }
  97. }
  98. public override void MergeWith(Style s)
  99. {
  100. if(s!=null && s is TableItemStyle && !s.IsEmpty)
  101. {
  102. base.MergeWith(s);
  103. TableItemStyle with = (TableItemStyle)s;
  104. if(from.IsSet(H_ALIGN) && !IsSet(H_ALIGN))
  105. {
  106. HorizontalAlign = with.HorizontalAlign;
  107. }
  108. if(from.IsSet(V_ALIGN) && !IsSet(V_ALIGN))
  109. {
  110. VerticalAlign = with.VerticalAlign;
  111. }
  112. if(from.IsSet(WRAP) && !IsSet(WRAP))
  113. {
  114. Wrap = with.Wrap;
  115. }
  116. }
  117. }
  118. public override void Reset()
  119. {
  120. if(IsSet(H_ALIGN))
  121. ViewState.Remove("HorizontalAlign");
  122. if(IsSet(V_ALIGN))
  123. ViewState.Remove("VerticalAlign");
  124. if(IsSet(WRAP))
  125. ViewState.Remove("Wrap");
  126. base.Reset();
  127. }
  128. protected override void AddAttributesToRender(HtmlTextWriter writer, WebControl owner)
  129. {
  130. base.AddAttributesToRender(writer, owner);
  131. if(!Wrap)
  132. {
  133. writer.AddAttribute(HtmlTextWriterAttribute.NoWrap, "nowrap");
  134. }
  135. if(HorizontalAlign != HorizontalAlign.NotSet)
  136. {
  137. writer.AddAttribute(HtmlTextWriterAttribute.Align, TypeDescriptor.GetConverter(typeof(HorizontalAlign)).ConvertToString(HorizontalAlign));
  138. }
  139. if(VerticalAlign != VerticalAlign.NotSet)
  140. {
  141. writer.AddAttribute(HtmlTextWriterAttribute.Valign, TypeDescriptor.GetConverter(typeof(VerticalAlign)).ConvertToString(VerticalAlign));
  142. }
  143. }
  144. }
  145. }