#endregion Instance Variables
#region Events
+ static object ButtonClickEvent = new object ();
+ static object ButtonDropDownEvent = new object ();
+
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public new event EventHandler BackColorChanged {
remove { base.BackgroundImageChanged -= value; }
}
- public event ToolBarButtonClickEventHandler ButtonClick;
- public event ToolBarButtonClickEventHandler ButtonDropDown;
+ public event ToolBarButtonClickEventHandler ButtonClick {
+ add { Events.AddHandler (ButtonClickEvent, value); }
+ remove {Events.RemoveHandler (ButtonClickEvent, value); }
+ }
+
+ public event ToolBarButtonClickEventHandler ButtonDropDown {
+ add { Events.AddHandler (ButtonDropDownEvent, value); }
+ remove {Events.RemoveHandler (ButtonDropDownEvent, value); }
+ }
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
MouseLeave += new EventHandler (ToolBar_MouseLeave);
MouseMove += new MouseEventHandler (ToolBar_MouseMove);
MouseUp += new MouseEventHandler (ToolBar_MouseUp);
+ BackgroundImageChanged += new EventHandler (ToolBar_BackgroundImageChanged);
+ TabStop = false;
+
SetStyle (ControlStyles.UserPaint, false);
SetStyle (ControlStyles.FixedHeight, true);
}
[DefaultValue (true)]
[Localizable (true)]
- public bool AutoSize {
+ public new bool AutoSize {
get { return autosize; }
set {
if (value == autosize)
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public override Image BackgroundImage {
- get { return background_image; }
- set {
- if (value == background_image)
- return;
-
- background_image = value;
- OnBackgroundImageChanged (EventArgs.Empty);
- Redraw (false);
- }
+ get { return base.BackgroundImage; }
+ set { base.BackgroundImage = value; }
}
[DefaultValue (BorderStyle.None)]
}
}
- ImeMode ime_mode;
+ // XXX this should probably go away and it should call
+ // into Control.ImeMode instead.
+ new ImeMode ime_mode = ImeMode.Disable;
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
}
}
- bool show_tooltips = false;
+ // Default value is "false" but after make a test in .NET we get "true" result as default.
+ bool show_tooltips = true;
[DefaultValue (false)]
[Localizable (true)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
[EditorBrowsable (EditorBrowsableState.Never)]
public override string Text {
- get { return text; }
+ get { return base.Text; }
set {
- if (value == text)
+ if (value == base.Text)
return;
- text = value;
+ base.Text = value;
Redraw (true);
- OnTextChanged (EventArgs.Empty);
}
}
int count = this.Buttons.Count;
if (count == 0)
- return string.Format ("System.Windows.Forms.ToolBar, Button.Count: 0");
+ return string.Format ("System.Windows.Forms.ToolBar, Buttons.Count: 0");
else
- return string.Format ("System.Windows.Forms.ToolBar, Button.Count: {0}, Buttons[0]: {1}",
+ return string.Format ("System.Windows.Forms.ToolBar, Buttons.Count: {0}, Buttons[0]: {1}",
count, this.Buttons [0].ToString ());
}
#endregion Public Methods
}
e.Button.pressed = false;
- e.Button.InvalidateBorder ();
+ e.Button.Invalidate ();
- if (ButtonClick != null)
- ButtonClick (this, e);
+ ToolBarButtonClickEventHandler eh = (ToolBarButtonClickEventHandler)(Events [ButtonClickEvent]);
+ if (eh != null)
+ eh (this, e);
}
protected virtual void OnButtonDropDown (ToolBarButtonClickEventArgs e)
{
- if (ButtonDropDown != null)
- ButtonDropDown (this, e);
+ ToolBarButtonClickEventHandler eh = (ToolBarButtonClickEventHandler)(Events [ButtonDropDownEvent]);
+ if (eh != null)
+ eh (this, e);
if (e.Button.DropDownMenu == null)
return;
if (Width <= 0 || Height <= 0 || !Visible)
return;
- Redraw (true, background_image != null);
+ Redraw (true, BackgroundImage != null);
}
- bool height_specified = false;
int requested_height = -1;
protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified)
{
- if ((specified & BoundsSpecified.Height) != 0) {
+ // New height requested
+ if (!AutoSize && (requested_height != height) && ((specified & BoundsSpecified.Height) != BoundsSpecified.None))
requested_height = height;
- height_specified = true;
- }
+
base.SetBoundsCore (x, y, width, height, specified);
}
(enabled [next] as ToolBarButton).Hilight = true;
}
+ private void ToolBar_BackgroundImageChanged (object sender, EventArgs args)
+ {
+ Redraw (false);
+ }
+
private void ToolBar_MouseDown (object sender, MouseEventArgs me)
{
if ((!Enabled) || ((me.Button & MouseButtons.Left) == 0))
// We don't redraw the dropdown rect.
if (button.Style == ToolBarButtonStyle.DropDownButton) {
Rectangle rect = button.Rectangle;
- rect.Width = ThemeEngine.Current.ToolBarDropDownWidth;
- rect.X = button.Rectangle.Right - rect.Width;
+ if (DropDownArrows) {
+ rect.Width = ThemeEngine.Current.ToolBarDropDownWidth;
+ rect.X = button.Rectangle.Right - rect.Width;
+ }
+
if (rect.Contains (loc)) {
if (button.DropDownMenu != null) {
button.dd_pressed = true;
}
break;
}
- } else if ((me.Button & MouseButtons.Left) == MouseButtons.Left) {
- button.pressed = true;
- button.inside = true;
- button.InvalidateBorder ();
- break;
}
+ button.pressed = true;
+ button.inside = true;
+ button.Invalidate ();
+ break;
}
}
}
OnButtonClick (new ToolBarButtonClickEventArgs (button));
} else if (button.pressed) {
button.pressed = false;
- button.InvalidateBorder ();
+ button.Invalidate ();
}
}
}
{
bool invalidate = true;
if (recalculate) {
- invalidate = Layout ();
+ invalidate = LayoutToolBar ();
}
if (force || invalidate)
}
}
- bool Layout ()
+ bool LayoutToolBar ()
{
bool changed = false;
Theme theme = ThemeEngine.Current;
int x = theme.ToolBarGripWidth;
int y = theme.ToolBarGripWidth;
- Size button_size = AdjustedButtonSize;
+ Size adjusted_size = AdjustedButtonSize;
+ int ht = adjusted_size.Height + theme.ToolBarGripWidth;
- int ht = button_size.Height + theme.ToolBarGripWidth;
+ int separator_index = -1;
- if (Wrappable && Parent != null) {
- int separator_index = -1;
+ for (int i = 0; i < buttons.Count; i++) {
+ ToolBarButton button = buttons [i];
- for (int i = 0; i < buttons.Count; i++) {
- ToolBarButton button = buttons [i];
+ if (!button.Visible)
+ continue;
- if (!button.Visible)
- continue;
-
- if (size_specified && (button.Style != ToolBarButtonStyle.Separator)) {
- if (button.Layout (button_size))
- changed = true;
- }
- else {
- if (button.Layout ())
- changed = true;
- }
+ if (size_specified && (button.Style != ToolBarButtonStyle.Separator))
+ changed = button.Layout (adjusted_size);
+ else
+ changed = button.Layout ();
+
+ bool is_separator = button.Style == ToolBarButtonStyle.Separator;
- bool is_separator = button.Style == ToolBarButtonStyle.Separator;
-
- if (x + button.Rectangle.Width < Width || is_separator) {
- if (button.Location.X != x || button.Location.Y != y)
- changed = true;
- button.Location = new Point (x, y);
- x += button.Rectangle.Width;
- if (is_separator)
- separator_index = i;
- } else if (separator_index > 0) {
- i = separator_index;
- separator_index = -1;
- x = theme.ToolBarGripWidth;
- y += ht;
- } else {
- x = theme.ToolBarGripWidth;
- y += ht;
- if (button.Location.X != x || button.Location.Y != y)
- changed = true;
- button.Location = new Point (x, y);
- x += button.Rectangle.Width;
- }
- }
- if (AutoSize)
- Height = y + ht;
- } else {
- if (AutoSize)
- Height = ht;
- else if (!height_specified)
- Height = DefaultSize.Height;
- foreach (ToolBarButton button in buttons) {
- if (size_specified) {
- if (button.Layout (button_size))
- changed = true;
- }
- else {
- if (button.Layout ())
- changed = true;
- }
+ if (x + button.Rectangle.Width < Width || is_separator || !Wrappable) {
+ if (button.Location.X != x || button.Location.Y != y)
+ changed = true;
+ button.Location = new Point (x, y);
+ x += button.Rectangle.Width;
+ if (is_separator)
+ separator_index = i;
+ } else if (separator_index > 0) {
+ i = separator_index;
+ separator_index = -1;
+ x = theme.ToolBarGripWidth;
+ y += ht;
+ } else {
+ x = theme.ToolBarGripWidth;
+ y += ht;
if (button.Location.X != x || button.Location.Y != y)
changed = true;
button.Location = new Point (x, y);
x += button.Rectangle.Width;
}
}
-
+
+ if (Parent == null)
+ return changed;
+
+ if (AutoSize)
+ Height = ht + (Wrappable ? y : 0);
+ else
+ Height = requested_height;
+
return changed;
}
#endregion Private Methods