ToolBarButton.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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.3 $
  33. // $Modtime: $
  34. // $Log: ToolBarButton.cs,v $
  35. // Revision 1.3 2004/08/21 01:52:08 ravindra
  36. // Improvments in mouse event handling in the ToolBar control.
  37. //
  38. // Revision 1.2 2004/08/17 02:00:54 ravindra
  39. // Added attributes.
  40. //
  41. // Revision 1.1 2004/08/15 23:13:15 ravindra
  42. // First Implementation of ToolBar control.
  43. //
  44. //
  45. // NOT COMPLETE
  46. using System.ComponentModel;
  47. using System.ComponentModel.Design;
  48. using System.Drawing;
  49. using System.Drawing.Imaging;
  50. namespace System.Windows.Forms
  51. {
  52. [DefaultProperty ("Text")]
  53. [Designer ("System.Windows.Forms.Design.ToolBarButtonDesigner, " + Consts.AssemblySystem_Design, typeof (IDesigner))]
  54. [DesignTimeVisible (false)]
  55. [ToolboxItem (false)]
  56. public class ToolBarButton : Component
  57. {
  58. #region instance variable
  59. //private ContextMenu menu; //NotImplemented
  60. private bool enabled = true;
  61. private int imageIndex = -1;
  62. private ToolBar parent;
  63. private bool partialPush = false;
  64. private bool pushed = false;
  65. private ToolBarButtonStyle style = ToolBarButtonStyle.PushButton;
  66. private object tag;
  67. private string text = "";
  68. private string toolTip = "";
  69. private bool visible = true;
  70. private Point location = new Point (0, 0);
  71. private bool wrapper = false;
  72. private bool hilight = false;
  73. private bool pressed = false; // this is to check for mouse down on a button
  74. #endregion
  75. #region constructors
  76. public ToolBarButton () { }
  77. public ToolBarButton (string text)
  78. {
  79. this.text = text;
  80. }
  81. #endregion
  82. #region internal properties
  83. internal bool Hilight {
  84. get { return hilight; }
  85. set {
  86. if (! pushed)
  87. hilight = value;
  88. else
  89. hilight = false;
  90. }
  91. }
  92. internal Point Location {
  93. get { return location; }
  94. set { location = value; }
  95. }
  96. internal bool Pressed {
  97. get { return pressed; }
  98. set { pressed = value; }
  99. }
  100. internal bool Wrapper {
  101. get { return wrapper; }
  102. set { wrapper = value; }
  103. }
  104. #endregion internal properties
  105. #region properties
  106. /*
  107. [DefaultValue (null)]
  108. [TypeConverter (typeof (ReferenceConverter))]
  109. public Menu DropDownMenu {
  110. get { return menu; }
  111. set {
  112. if (value is ContextMenu)
  113. menu = value;
  114. else
  115. throw new ArgumentException ("DropDownMenu must be of type ContextMenu.");
  116. }
  117. }
  118. */
  119. [DefaultValue (true)]
  120. [Localizable (true)]
  121. public bool Enabled {
  122. get { return enabled; }
  123. set {
  124. if (value == enabled)
  125. return;
  126. enabled = value;
  127. }
  128. }
  129. [DefaultValue (-1)]
  130. [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
  131. [Localizable (true)]
  132. //[TypeConverter (typeof (ImageIndexConverter)]
  133. public int ImageIndex {
  134. get { return imageIndex; }
  135. set {
  136. if (value == imageIndex)
  137. return;
  138. imageIndex = value;
  139. }
  140. }
  141. [Browsable (false)]
  142. public ToolBar Parent {
  143. get { return parent; }
  144. }
  145. [DefaultValue (false)]
  146. public bool PartialPush {
  147. get { return partialPush; }
  148. set {
  149. if (value == partialPush)
  150. return;
  151. partialPush = value;
  152. }
  153. }
  154. [DefaultValue (false)]
  155. public bool Pushed {
  156. get { return pushed; }
  157. set {
  158. if (value == pushed)
  159. return;
  160. pushed = value;
  161. if (pushed) hilight = false;
  162. }
  163. }
  164. public Rectangle Rectangle {
  165. get {
  166. if (parent == null)
  167. return Rectangle.Empty;
  168. else if (visible && parent.Visible)
  169. return parent.GetChildBounds (this);
  170. else
  171. return Rectangle.Empty;
  172. }
  173. }
  174. [DefaultValue (ToolBarButtonStyle.PushButton)]
  175. [RefreshProperties (RefreshProperties.Repaint)]
  176. public ToolBarButtonStyle Style {
  177. get { return style; }
  178. set {
  179. if (value == style)
  180. return;
  181. style = value;
  182. }
  183. }
  184. [Bindable (true)]
  185. [DefaultValue (null)]
  186. [Localizable (false)]
  187. [TypeConverter (typeof (StringConverter))]
  188. public object Tag {
  189. get { return tag; }
  190. set { tag = value; }
  191. }
  192. [DefaultValue (null)]
  193. [Localizable (true)]
  194. public string Text {
  195. get { return text; }
  196. set {
  197. if (value == text)
  198. return;
  199. text = value;
  200. }
  201. }
  202. [DefaultValue (null)]
  203. [Localizable (true)]
  204. public string ToolTipText {
  205. get { return toolTip; }
  206. set { toolTip = value; }
  207. }
  208. [DefaultValue (true)]
  209. [Localizable (true)]
  210. public bool Visible {
  211. get { return visible; }
  212. set {
  213. if (value == visible)
  214. return;
  215. visible = value;
  216. }
  217. }
  218. #endregion
  219. #region internal methods
  220. internal void SetParent (ToolBar parent)
  221. {
  222. this.parent = parent;
  223. }
  224. internal void Dump ()
  225. {
  226. Console.WriteLine ("TBButton: style: " + this.Style);
  227. Console.WriteLine ("TBButton: wrapper: " + this.Wrapper);
  228. Console.WriteLine ("TBButton: loc: " + this.Location);
  229. Console.WriteLine ("TBButton: rect: " + this.Rectangle);
  230. Console.WriteLine ("TBButton: txt: " + this.Text);
  231. Console.WriteLine ("TBButton: visible " + this.Visible);
  232. Console.WriteLine ("TBButton: enabled: " + this.Enabled);
  233. Console.WriteLine ("TBButton: image index: " + this.ImageIndex);
  234. Console.WriteLine ("TBButton: pushed: " + this.Pushed);
  235. Console.WriteLine ("TBButton: partial push: " + this.PartialPush);
  236. }
  237. #endregion
  238. #region methods
  239. protected override void Dispose (bool disposing)
  240. {
  241. base.Dispose (disposing);
  242. }
  243. public override string ToString ()
  244. {
  245. return string.Format ("ToolBarButton: {0}, Style: {1}", text, style);
  246. }
  247. #endregion
  248. }
  249. }