ToolBarButton.cs 7.0 KB

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