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
33 // $Log: ToolBarButton.cs,v $
34 // Revision 1.9 2004/10/14 11:10:47 ravindra
35 // - Added an internal member 'inside' to handle mouse move
36 // with mouse pressed ie mouse drag event.
37 // - Changed 'Pressed' property to return true only when
38 // 'inside' and 'pressed' are both true.
39 // - Some coding style love.
41 // Revision 1.8 2004/10/05 08:42:20 ravindra
42 // Added an internal member dd_pressed to handle clicks on DropDown arrow.
44 // Revision 1.7 2004/09/09 11:23:05 ravindra
45 // Changes in ToolBarButton need to make it's parent redraw.
47 // Revision 1.6 2004/08/27 22:12:56 ravindra
48 // Added TypeConverter attribute.
50 // Revision 1.5 2004/08/25 20:04:40 ravindra
51 // Added the missing divider code and grip for ToolBar Control.
53 // Revision 1.4 2004/08/22 00:03:20 ravindra
54 // Fixed toolbar control signatures.
56 // Revision 1.3 2004/08/21 01:52:08 ravindra
57 // Improvments in mouse event handling in the ToolBar control.
59 // Revision 1.2 2004/08/17 02:00:54 ravindra
62 // Revision 1.1 2004/08/15 23:13:15 ravindra
63 // First Implementation of ToolBar control.
69 using System.ComponentModel;
70 using System.ComponentModel.Design;
72 using System.Drawing.Imaging;
74 namespace System.Windows.Forms
76 [DefaultProperty ("Text")]
77 [Designer ("System.Windows.Forms.Design.ToolBarButtonDesigner, " + Consts.AssemblySystem_Design, typeof (IDesigner))]
78 [DesignTimeVisible (false)]
80 public class ToolBarButton : Component
82 #region instance variable
83 private bool enabled = true;
84 private int image_index = -1;
85 private ContextMenu menu;
86 private ToolBar parent;
87 private bool partial_push = false;
88 private bool pushed = false;
89 private ToolBarButtonStyle style = ToolBarButtonStyle.PushButton;
91 private string text = "";
92 private string tooltip = "";
93 private bool visible = true;
94 private Point location = new Point (ThemeEngine.Current.ToolBarGripWidth,
95 ThemeEngine.Current.ToolBarGripWidth);
96 internal bool dd_pressed = false; // to check for a mouse down on dropdown rect
97 internal bool hilight = false; // to hilight buttons in flat style
98 internal bool inside = false; // to handle the mouse move event with mouse pressed
99 internal bool wrapper = false; // to mark a wrapping button
100 internal bool pressed = false; // this is to check for mouse down on a button
104 public ToolBarButton () { }
106 public ToolBarButton (string text)
112 #region internal properties
113 internal bool Hilight {
114 get { return hilight; }
123 internal Point Location {
124 get { return location; }
125 set { location = value; }
128 internal bool Pressed {
130 if (pressed && inside)
135 set { pressed = value; }
138 internal bool Wrapper {
139 get { return wrapper; }
140 set { wrapper = value; }
142 #endregion internal properties
145 [DefaultValue (null)]
146 [TypeConverter (typeof (ReferenceConverter))]
147 public Menu DropDownMenu {
151 if (value is ContextMenu)
152 menu = (ContextMenu) value;
154 throw new ArgumentException ("DropDownMenu must be of type ContextMenu.");
158 [DefaultValue (true)]
160 public bool Enabled {
161 get { return enabled; }
163 if (value == enabled)
168 parent.Redraw (false);
173 [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
175 [TypeConverter (typeof (ImageIndexConverter))]
176 public int ImageIndex {
177 get { return image_index; }
180 throw new ArgumentException ("ImageIndex value must be above or equal to -1.");
182 if (value == image_index)
187 parent.Redraw (true);
192 public ToolBar Parent {
193 get { return parent; }
196 [DefaultValue (false)]
197 public bool PartialPush {
198 get { return partial_push; }
200 if (value == partial_push)
203 partial_push = value;
205 parent.Redraw (false);
209 [DefaultValue (false)]
211 get { return pushed; }
220 parent.Redraw (false);
224 public Rectangle Rectangle {
227 return Rectangle.Empty;
228 else if (visible && parent.Visible)
229 return parent.GetChildBounds (this);
231 return Rectangle.Empty;
235 [DefaultValue (ToolBarButtonStyle.PushButton)]
236 [RefreshProperties (RefreshProperties.Repaint)]
237 public ToolBarButtonStyle Style {
238 get { return style; }
245 parent.Redraw (true);
250 [DefaultValue (null)]
251 [Localizable (false)]
252 [TypeConverter (typeof (StringConverter))]
258 [DefaultValue (null)]
268 parent.Redraw (true);
272 [DefaultValue (null)]
274 public string ToolTipText {
275 get { return tooltip; }
276 set { tooltip = value; }
279 [DefaultValue (true)]
281 public bool Visible {
282 get { return visible; }
284 if (value == visible)
289 parent.Redraw (true);
294 #region internal methods
295 internal void SetParent (ToolBar parent)
297 this.parent = parent;
300 internal void Dump ()
302 Console.WriteLine ("TBButton: style: " + this.Style);
303 Console.WriteLine ("TBButton: wrapper: " + this.Wrapper);
304 Console.WriteLine ("TBButton: hilight: " + this.Hilight);
305 Console.WriteLine ("TBButton: loc: " + this.Location);
306 Console.WriteLine ("TBButton: rect: " + this.Rectangle);
307 Console.WriteLine ("TBButton: txt: " + this.Text);
308 Console.WriteLine ("TBButton: visible " + this.Visible);
309 Console.WriteLine ("TBButton: enabled: " + this.Enabled);
310 Console.WriteLine ("TBButton: image index: " + this.ImageIndex);
311 Console.WriteLine ("TBButton: pushed: " + this.Pushed);
312 Console.WriteLine ("TBButton: partial push: " + this.PartialPush);
317 protected override void Dispose (bool disposing)
319 base.Dispose (disposing);
322 public override string ToString ()
324 return string.Format ("ToolBarButton: {0}, Style: {1}", text, style);