MenuItemStyle.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //
  2. // System.Web.UI.WebControls.MenuItemStyle.cs
  3. //
  4. // Authors:
  5. // Lluis Sanchez Gual ([email protected])
  6. //
  7. // (C) 2004 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  29. //
  30. #if NET_2_0
  31. using System;
  32. using System.Web.UI;
  33. using System.ComponentModel;
  34. namespace System.Web.UI.WebControls
  35. {
  36. public class MenuItemStyle: Style
  37. {
  38. private static int HORZ_PADD = (0x01 << 16);
  39. private static int SPACING = (0x01 << 17);
  40. private static int VERT_PADD = (0x01 << 18);
  41. [DefaultValue (0)]
  42. [NotifyParentProperty (true)]
  43. public int HorizontalPadding {
  44. get {
  45. if(IsSet(HORZ_PADD))
  46. return (int)(ViewState["HorizontalPadding"]);
  47. return 0;
  48. }
  49. set {
  50. ViewState["HorizontalPadding"] = value;
  51. Set(HORZ_PADD);
  52. }
  53. }
  54. [DefaultValue (0)]
  55. [NotifyParentProperty (true)]
  56. public int VerticalPadding {
  57. get {
  58. if(IsSet(VERT_PADD))
  59. return (int)(ViewState["VerticalPadding"]);
  60. return 0;
  61. }
  62. set {
  63. ViewState["VerticalPadding"] = value;
  64. Set(VERT_PADD);
  65. }
  66. }
  67. [DefaultValue (0)]
  68. [NotifyParentProperty (true)]
  69. public int ItemSpacing {
  70. get {
  71. if(IsSet(SPACING))
  72. return (int)(ViewState["ItemSpacing"]);
  73. return 0;
  74. }
  75. set {
  76. ViewState["ItemSpacing"] = value;
  77. Set(SPACING);
  78. }
  79. }
  80. protected internal override bool IsEmpty {
  81. get { return base.IsEmpty; }
  82. }
  83. public override void CopyFrom (Style s)
  84. {
  85. if (s == null || s.IsEmpty)
  86. return;
  87. base.CopyFrom (s);
  88. MenuItemStyle from = s as MenuItemStyle;
  89. if (from == null)
  90. return;
  91. if (from.IsSet (HORZ_PADD))
  92. HorizontalPadding = from.HorizontalPadding;
  93. if (from.IsSet (SPACING))
  94. ItemSpacing = from.ItemSpacing;
  95. if (from.IsSet (VERT_PADD))
  96. VerticalPadding = from.VerticalPadding;
  97. }
  98. public override void MergeWith(Style s)
  99. {
  100. if(s != null && !s.IsEmpty)
  101. {
  102. if (IsEmpty) {
  103. CopyFrom (s);
  104. return;
  105. }
  106. base.MergeWith(s);
  107. MenuItemStyle with = s as MenuItemStyle;
  108. if (with == null) return;
  109. if (with.IsSet(HORZ_PADD) && !IsSet(HORZ_PADD)) {
  110. HorizontalPadding = with.HorizontalPadding;
  111. }
  112. if (with.IsSet(SPACING) && !IsSet(SPACING)) {
  113. ItemSpacing = with.ItemSpacing;
  114. }
  115. if (with.IsSet(VERT_PADD) && !IsSet(VERT_PADD)) {
  116. VerticalPadding = with.VerticalPadding;
  117. }
  118. }
  119. }
  120. public override void Reset()
  121. {
  122. if(IsSet(HORZ_PADD))
  123. ViewState.Remove("HorizontalPadding");
  124. if(IsSet(SPACING))
  125. ViewState.Remove("ItemSpacing");
  126. if(IsSet(VERT_PADD))
  127. ViewState.Remove("VerticalPadding");
  128. base.Reset();
  129. }
  130. protected override void FillStyleAttributes (CssStyleCollection attributes, IUrlResolutionService urlResolver)
  131. {
  132. base.FillStyleAttributes (attributes, urlResolver);
  133. if (IsSet (HORZ_PADD)) {
  134. attributes.Add (HtmlTextWriterStyle.PaddingLeft, HorizontalPadding.ToString () + "px");
  135. attributes.Add (HtmlTextWriterStyle.PaddingRight, HorizontalPadding.ToString () + "px");
  136. }
  137. if (IsSet (VERT_PADD)) {
  138. attributes.Add (HtmlTextWriterStyle.PaddingTop, VerticalPadding.ToString () + "px");
  139. attributes.Add (HtmlTextWriterStyle.PaddingBottom, VerticalPadding.ToString () + "px");
  140. }
  141. }
  142. }
  143. }
  144. #endif