TableItemStyle.cs 3.4 KB

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