ToolBarButton.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. //
  2. // System.Windows.Forms.ToolBarButton.cs
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining
  5. // a copy of this software and associated documentation files (the
  6. // "Software"), to deal in the Software without restriction, including
  7. // without limitation the rights to use, copy, modify, merge, publish,
  8. // distribute, sublicense, and/or sell copies of the Software, and to
  9. // permit persons to whom the Software is furnished to do so, subject to
  10. // the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be
  13. // included in all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. //
  23. // Copyright (C) 2004 Novell, Inc.
  24. //
  25. // Authors:
  26. // Ravindra ([email protected])
  27. //
  28. // TODO:
  29. // - DropDownMenu
  30. // - Adding a button to two toolbars
  31. //
  32. // $Revision: 1.1 $
  33. // $Modtime: $
  34. // $Log: ToolBarButton.cs,v $
  35. // Revision 1.1 2004/08/15 23:13:15 ravindra
  36. // First Implementation of ToolBar control.
  37. //
  38. //
  39. //
  40. // NOT COMPLETE
  41. using System.ComponentModel;
  42. using System.Drawing;
  43. using System.Drawing.Imaging;
  44. namespace System.Windows.Forms
  45. {
  46. public class ToolBarButton : Component
  47. {
  48. #region instance variable
  49. //private ContextMenu menu; //NotImplemented
  50. private bool enabled = true;
  51. private int imageIndex = -1;
  52. private ToolBar parent;
  53. private bool partialPush = false;
  54. private bool pushed = false;
  55. private ToolBarButtonStyle style = ToolBarButtonStyle.PushButton;
  56. private object tag;
  57. private string text = "";
  58. private string toolTip = "";
  59. private bool visible = true;
  60. private Point location = new Point (0, 0);
  61. private bool wrapper = false;
  62. private bool hilight = false;
  63. #endregion
  64. #region constructors
  65. public ToolBarButton () { }
  66. public ToolBarButton (string text)
  67. {
  68. this.text = text;
  69. }
  70. #endregion
  71. #region internal properties
  72. internal Point Location {
  73. get { return location; }
  74. set { location = value; }
  75. }
  76. internal bool Wrapper {
  77. get { return wrapper; }
  78. set { wrapper = value; }
  79. }
  80. internal bool Hilight {
  81. get { return hilight; }
  82. set {
  83. if (! pushed)
  84. hilight = value;
  85. else
  86. hilight = false;
  87. }
  88. }
  89. #endregion internal properties
  90. #region properties
  91. /*
  92. public Menu DropDownMenu {
  93. get { return menu; }
  94. set {
  95. if (value is ContextMenu)
  96. menu = value;
  97. else
  98. throw new ArgumentException ("DropDownMenu must be of type ContextMenu.");
  99. }
  100. }
  101. */
  102. public bool Enabled {
  103. get { return enabled; }
  104. set {
  105. if (value == enabled)
  106. return;
  107. enabled = value;
  108. }
  109. }
  110. public int ImageIndex {
  111. get { return imageIndex; }
  112. set {
  113. if (value == imageIndex)
  114. return;
  115. imageIndex = value;
  116. }
  117. }
  118. public ToolBar Parent {
  119. get { return parent; }
  120. }
  121. public bool PartialPush {
  122. get { return partialPush; }
  123. set {
  124. if (value == partialPush)
  125. return;
  126. partialPush = value;
  127. }
  128. }
  129. public bool Pushed {
  130. get { return pushed; }
  131. set {
  132. if (value == pushed)
  133. return;
  134. pushed = value;
  135. if (pushed) hilight = false;
  136. }
  137. }
  138. public Rectangle Rectangle {
  139. get {
  140. if (parent == null)
  141. return Rectangle.Empty;
  142. else if (visible && parent.Visible)
  143. return parent.GetChildBounds (this);
  144. else
  145. return Rectangle.Empty;
  146. }
  147. }
  148. public ToolBarButtonStyle Style {
  149. get { return style; }
  150. set {
  151. if (value == style)
  152. return;
  153. style = value;
  154. }
  155. }
  156. public object Tag {
  157. get { return tag; }
  158. set { tag = value; }
  159. }
  160. public string Text {
  161. get { return text; }
  162. set {
  163. if (value == text)
  164. return;
  165. text = value;
  166. }
  167. }
  168. public string ToolTipText {
  169. get { return toolTip; }
  170. set { toolTip = value; }
  171. }
  172. public bool Visible {
  173. get { return visible; }
  174. set {
  175. if (value == visible)
  176. return;
  177. visible = value;
  178. }
  179. }
  180. #endregion
  181. #region internal methods
  182. internal void SetParent (ToolBar parent)
  183. {
  184. this.parent = parent;
  185. }
  186. internal void Dump ()
  187. {
  188. Console.WriteLine ("TBButton: style: " + this.Style);
  189. Console.WriteLine ("TBButton: wrapper: " + this.Wrapper);
  190. Console.WriteLine ("TBButton: loc: " + this.Location);
  191. Console.WriteLine ("TBButton: rect: " + this.Rectangle);
  192. Console.WriteLine ("TBButton: txt: " + this.Text);
  193. Console.WriteLine ("TBButton: visible " + this.Visible);
  194. Console.WriteLine ("TBButton: enabled: " + this.Enabled);
  195. Console.WriteLine ("TBButton: image index: " + this.ImageIndex);
  196. Console.WriteLine ("TBButton: pushed: " + this.Pushed);
  197. Console.WriteLine ("TBButton: partial push: " + this.PartialPush);
  198. }
  199. #endregion
  200. #region methods
  201. protected override void Dispose (bool disposing)
  202. {
  203. base.Dispose (disposing);
  204. }
  205. public override string ToString ()
  206. {
  207. return string.Format ("ToolBarButton: {0}, Style: {1}", text, style);
  208. }
  209. #endregion
  210. }
  211. }