ToolBarButton.cs 6.8 KB

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