ToolBarButton.cs 7.1 KB

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