2 // System.Windows.Forms.ToolBarButton.cs
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:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
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.
23 // Copyright (C) 2004 Novell, Inc. (http://www.novell.com)
26 // Ravindra (rkumar@novell.com)
29 // - Adding a button to two toolbars
35 using System.ComponentModel;
36 using System.ComponentModel.Design;
38 using System.Drawing.Imaging;
40 namespace System.Windows.Forms
42 [DefaultProperty ("Text")]
43 [Designer ("System.Windows.Forms.Design.ToolBarButtonDesigner, " + Consts.AssemblySystem_Design)]
44 [DesignTimeVisible (false)]
46 public class ToolBarButton : Component
48 #region instance variable
49 private bool enabled = true;
50 private int image_index = -1;
51 private ContextMenu menu;
52 private ToolBar parent;
53 private bool partial_push = false;
54 private bool pushed = false;
55 private ToolBarButtonStyle style = ToolBarButtonStyle.PushButton;
57 private string text = "";
58 private string tooltip = "";
59 private bool visible = true;
60 private Point location = new Point (ThemeEngine.Current.ToolBarGripWidth,
61 ThemeEngine.Current.ToolBarGripWidth);
62 internal bool dd_pressed = false; // to check for a mouse down on dropdown rect
63 internal bool hilight = false; // to hilight buttons in flat style
64 internal bool inside = false; // to handle the mouse move event with mouse pressed
65 internal bool wrapper = false; // to mark a wrapping button
66 internal bool pressed = false; // this is to check for mouse down on a button
70 public ToolBarButton () { }
72 public ToolBarButton (string text)
78 #region internal properties
79 internal bool Hilight {
80 get { return hilight; }
89 internal Point Location {
90 get { return location; }
91 set { location = value; }
94 internal bool Pressed {
96 if (pressed && inside)
101 set { pressed = value; }
104 internal bool Wrapper {
105 get { return wrapper; }
106 set { wrapper = value; }
108 #endregion internal properties
111 [DefaultValue (null)]
112 [TypeConverter (typeof (ReferenceConverter))]
113 public Menu DropDownMenu {
117 if (value is ContextMenu)
118 menu = (ContextMenu) value;
120 throw new ArgumentException ("DropDownMenu must be of type ContextMenu.");
124 [DefaultValue (true)]
126 public bool Enabled {
127 get { return enabled; }
129 if (value == enabled)
134 parent.Redraw (false);
139 [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
141 [TypeConverter (typeof (ImageIndexConverter))]
142 public int ImageIndex {
143 get { return image_index; }
146 throw new ArgumentException ("ImageIndex value must be above or equal to -1.");
148 if (value == image_index)
153 parent.Redraw (true);
158 public ToolBar Parent {
159 get { return parent; }
162 [DefaultValue (false)]
163 public bool PartialPush {
164 get { return partial_push; }
166 if (value == partial_push)
169 partial_push = value;
171 parent.Redraw (false);
175 [DefaultValue (false)]
177 get { return pushed; }
186 parent.Redraw (false);
190 public Rectangle Rectangle {
193 return Rectangle.Empty;
194 else if (visible && parent.Visible)
195 return parent.GetChildBounds (this);
197 return Rectangle.Empty;
201 [DefaultValue (ToolBarButtonStyle.PushButton)]
202 [RefreshProperties (RefreshProperties.Repaint)]
203 public ToolBarButtonStyle Style {
204 get { return style; }
211 parent.Redraw (true);
216 [DefaultValue (null)]
217 [Localizable (false)]
218 [TypeConverter (typeof (StringConverter))]
234 parent.Redraw (true);
240 public string ToolTipText {
241 get { return tooltip; }
242 set { tooltip = value; }
245 [DefaultValue (true)]
247 public bool Visible {
248 get { return visible; }
250 if (value == visible)
255 parent.Redraw (true);
260 #region internal methods
261 internal void SetParent (ToolBar parent)
263 this.parent = parent;
266 internal void Dump ()
268 Console.WriteLine ("TBButton: style: " + this.Style);
269 Console.WriteLine ("TBButton: wrapper: " + this.Wrapper);
270 Console.WriteLine ("TBButton: hilight: " + this.Hilight);
271 Console.WriteLine ("TBButton: loc: " + this.Location);
272 Console.WriteLine ("TBButton: rect: " + this.Rectangle);
273 Console.WriteLine ("TBButton: txt: " + this.Text);
274 Console.WriteLine ("TBButton: visible " + this.Visible);
275 Console.WriteLine ("TBButton: enabled: " + this.Enabled);
276 Console.WriteLine ("TBButton: image index: " + this.ImageIndex);
277 Console.WriteLine ("TBButton: pushed: " + this.Pushed);
278 Console.WriteLine ("TBButton: partial push: " + this.PartialPush);
283 protected override void Dispose (bool disposing)
285 base.Dispose (disposing);
288 public override string ToString ()
290 return string.Format ("ToolBarButton: {0}, Style: {1}", text, style);