namespace System.Windows.Forms
{
-#if NET_2_0
[ComVisible (true)]
[ClassInterface (ClassInterfaceType.AutoDispatch)]
-#endif
[DefaultEvent ("ButtonClick")]
[DefaultProperty ("Buttons")]
[Designer ("System.Windows.Forms.Design.ToolBarDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
static object ButtonClickEvent = new object ();
static object ButtonDropDownEvent = new object ();
-#if NET_2_0
[Browsable (true)]
[EditorBrowsable (EditorBrowsableState.Always)]
public new event EventHandler AutoSizeChanged {
add { base.AutoSizeChanged += value; }
remove { base.AutoSizeChanged -= value; }
}
-#endif
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
remove { base.BackgroundImageChanged -= value; }
}
-#if NET_2_0
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public new event EventHandler BackgroundImageLayoutChanged {
add { base.BackgroundImageLayoutChanged += value; }
remove { base.BackgroundImageLayoutChanged -= value; }
}
-#endif
public event ToolBarButtonClickEventHandler ButtonClick {
add { Events.AddHandler (ButtonClickEvent, value); }
get { return ThemeEngine.Current.ToolBarDefaultSize; }
}
-#if NET_2_0
[EditorBrowsable (EditorBrowsableState.Never)]
protected override bool DoubleBuffered {
get { return base.DoubleBuffered; }
set { base.DoubleBuffered = value; }
}
-#endif
#endregion
ToolBarAppearance appearance = ToolBarAppearance.Normal;
bool autosize = true;
-#if NET_2_0
[Browsable (true)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Visible)]
[EditorBrowsable (EditorBrowsableState.Always)]
-#endif
[DefaultValue (true)]
[Localizable (true)]
- public
-#if NET_2_0
- override
-#else
- new
-#endif
- bool AutoSize {
+ public override bool AutoSize {
get { return autosize; }
set {
if (value == autosize)
set { base.BackgroundImage = value; }
}
-#if NET_2_0
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public override ImageLayout BackgroundImageLayout {
get { return base.BackgroundImageLayout; }
set { base.BackgroundImageLayout = value; }
}
-#endif
[DefaultValue (BorderStyle.None)]
[DispIdAttribute (-504)]
// XXX this should probably go away and it should call
// into Control.ImeMode instead.
- new ImeMode ime_mode = ImeMode.Disable;
+ ImeMode ime_mode = ImeMode.Disable;
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
base.Dispose (disposing);
}
- protected virtual void OnButtonClick (ToolBarButtonClickEventArgs e)
+ private ToolBarButton button_for_focus = null;
+
+ internal void UIAPerformClick (ToolBarButton button)
{
+ ToolBarItem previous_item = current_item;
+ current_item = null;
+
+ foreach (ToolBarItem item in items)
+ if (item.Button == button) {
+ current_item = item;
+ break;
+ }
+
+ try {
+ if (current_item == null)
+ throw new ArgumentException ("button", "The button specified is not part of this toolbar");
+ PerformButtonClick (new ToolBarButtonClickEventArgs (button));
+ } finally {
+ current_item = previous_item;
+ }
+ }
+
+ void PerformButtonClick (ToolBarButtonClickEventArgs e)
+ {
+ // Only change pushed for ToogleButton
if (e.Button.Style == ToolBarButtonStyle.ToggleButton) {
if (! e.Button.Pushed)
e.Button.Pushed = true;
current_item.Pressed = false;
current_item.Invalidate ();
+ button_for_focus = current_item.Button;
+ button_for_focus.UIAHasFocus = true;
+
+ OnButtonClick (e);
+ }
+
+ protected virtual void OnButtonClick (ToolBarButtonClickEventArgs e)
+ {
ToolBarButtonClickEventHandler eh = (ToolBarButtonClickEventHandler)(Events [ButtonClickEvent]);
if (eh != null)
eh (this, e);
if (e.Button.DropDownMenu == null)
return;
- ToolBarItem item = current_item;
+ ShowDropDownMenu (current_item);
+ }
+ internal void ShowDropDownMenu (ToolBarItem item)
+ {
Point loc = new Point (item.Rectangle.X + 1, item.Rectangle.Bottom + 1);
- ((ContextMenu) e.Button.DropDownMenu).Show (this, loc);
+ ((ContextMenu) item.Button.DropDownMenu).Show (this, loc);
item.DDPressed = false;
item.Hilight = false;
LayoutToolBar ();
}
-#if NET_2_0
protected override void ScaleControl (SizeF factor, BoundsSpecified specified)
{
specified &= ~BoundsSpecified.Height;
base.ScaleCore (dx, dy);
}
-#endif
private int requested_size = -1;
{
if (msg.Msg == (int)Msg.WM_KEYDOWN) {
Keys key_data = (Keys)msg.WParam.ToInt32();
- if (HandleKeyDown (key_data))
+ if (HandleKeyDown (ref msg, key_data))
return true;
}
return base.InternalPreProcessMessage (ref msg);
#endregion Protected Methods
#region Private Methods
+ internal int CurrentItem {
+ get {
+ return Array.IndexOf (items, current_item);
+ }
+ set {
+ if (current_item != null)
+ current_item.Hilight = false;
+
+ current_item = value == -1 ? null : items [value];
+
+ if (current_item != null)
+ current_item.Hilight = true;
+ }
+
+ }
+
private void FocusChanged (object sender, EventArgs args)
{
+ if (!Focused && button_for_focus != null)
+ button_for_focus.UIAHasFocus = false;
+ button_for_focus = null;
+
if (Appearance != ToolBarAppearance.Flat || Buttons.Count == 0)
return;
}
}
- private bool HandleKeyDown (Keys key_data)
+ private bool HandleKeyDown (ref Message msg, Keys key_data)
{
if (Appearance != ToolBarAppearance.Flat || Buttons.Count == 0)
return false;
+ // Handle the key as needed if the current item is a dropdownbutton.
+ if (HandleKeyOnDropDown (ref msg, key_data))
+ return true;
+
switch (key_data) {
case Keys.Left:
case Keys.Up:
case Keys.Down:
HighlightButton (1);
return true;
- default:
- return false;
+ case Keys.Enter:
+ case Keys.Space:
+ if (current_item != null) {
+ OnButtonClick (new ToolBarButtonClickEventArgs (current_item.Button));
+ return true;
+ }
+ break;
}
+
+ return false;
+ }
+
+ bool HandleKeyOnDropDown (ref Message msg, Keys key_data)
+ {
+ if (current_item == null || current_item.Button.Style != ToolBarButtonStyle.DropDownButton ||
+ current_item.Button.DropDownMenu == null)
+ return false;
+
+ Menu dropdown_menu = current_item.Button.DropDownMenu;
+
+ if (dropdown_menu.Tracker.active) {
+ dropdown_menu.ProcessCmdKey (ref msg, key_data);
+ return true; // always true if the menu is active
+ }
+
+ if (key_data == Keys.Up || key_data == Keys.Down) {
+ current_item.DDPressed = true;
+ current_item.Invalidate ();
+ OnButtonDropDown (new ToolBarButtonClickEventArgs (current_item.Button));
+ return true;
+ }
+
+ return false;
}
void HighlightButton (int offset)
if (curr_item != null)
curr_item.Hilight = false;
- (enabled [next] as ToolBarItem).Hilight = true;
+
+ current_item = enabled [next] as ToolBarItem;
+ current_item.Hilight = true;
}
private void ToolBar_BackgroundImageChanged (object sender, EventArgs args)
// Fire a ButtonClick
current_item = item;
if ((item.Pressed) && ((me.Button & MouseButtons.Left) == MouseButtons.Left))
- OnButtonClick (new ToolBarButtonClickEventArgs (item.Button));
+ PerformButtonClick (new ToolBarButtonClickEventArgs (item.Button));
} else if (item.Pressed) {
item.Pressed = false;
item.Invalidate ();
private bool redraw; // Flag if needs to redraw after add/remove operations
#endregion
+ #region UIA Framework Events
+ static object UIACollectionChangedEvent = new object ();
+
+ internal event CollectionChangeEventHandler UIACollectionChanged {
+ add { owner.Events.AddHandler (UIACollectionChangedEvent, value); }
+ remove { owner.Events.RemoveHandler (UIACollectionChangedEvent, value); }
+ }
+
+ internal void OnUIACollectionChanged (CollectionChangeEventArgs e)
+ {
+ CollectionChangeEventHandler eh
+ = (CollectionChangeEventHandler) owner.Events [UIACollectionChangedEvent];
+ if (eh != null)
+ eh (owner, e);
+ }
+ #endregion
+
#region constructors
public ToolBarButtonCollection (ToolBar owner)
{
public virtual ToolBarButton this [int index] {
get { return (ToolBarButton) list [index]; }
set {
+ // UIA Framework Event: Button Removed
+ OnUIACollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Remove, index));
+
value.SetParent (owner);
list [index] = value;
owner.Redraw (true);
+
+ // UIA Framework Event: Button Added
+ OnUIACollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, index));
}
}
-#if NET_2_0
public virtual ToolBarButton this[string key] {
get {
if (string.IsNullOrEmpty (key))
return null;
}
}
-#endif
bool ICollection.IsSynchronized {
get { return list.IsSynchronized; }
result = list.Add (button);
if (redraw)
owner.Redraw (true);
+
+ // UIA Framework Event: Button Added
+ OnUIACollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, result));
+
return result;
}
{
list.Clear ();
owner.Redraw (false);
+
+ // UIA Framework Event: Button Cleared
+ OnUIACollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Refresh, -1));
}
public bool Contains (ToolBarButton button)
return list.Contains (button);
}
-#if NET_2_0
public virtual bool ContainsKey (string key)
{
return !(this[key] == null);
}
-#endif
public IEnumerator GetEnumerator ()
{
return list.IndexOf (button);
}
-#if NET_2_0
public virtual int IndexOfKey (string key)
{
return IndexOf (this[key]);
}
-#endif
public void Insert (int index, ToolBarButton button)
{
list.Insert (index, button);
owner.Redraw (true);
+
+ // UIA Framework Event: Button Added
+ OnUIACollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, index));
}
public void Remove (ToolBarButton button)
{
list.RemoveAt (index);
owner.Redraw (true);
+
+ // UIA Framework Event: Button Removed
+ OnUIACollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Remove, index));
}
-#if NET_2_0
public virtual void RemoveByKey (string key)
{
Remove (this[key]);
}
-#endif
#endregion methods
}