ToolBarButton.cs 6.3 KB

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