ToolBarButton.cs 7.5 KB

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