ToolBarButton.cs 7.8 KB

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