// Jonathan Pobst (monkey@jpobst.com)
//
-#if NET_2_0
using System;
using System.Drawing;
this.auto_size = true;
this.auto_tool_tip = this.DefaultAutoToolTip;
this.available = true;
- this.back_color = Control.DefaultBackColor;
+ this.back_color = Color.Empty;
this.background_image_layout = ImageLayout.Tile;
this.can_select = true;
this.display_style = this.DefaultDisplayStyle;
this.dock = DockStyle.None;
this.enabled = true;
- this.font = new Font ("Tahoma", 8.25f);
- this.fore_color = Control.DefaultForeColor;
+ this.fore_color = Color.Empty;
this.image = image;
this.image_align = ContentAlignment.MiddleCenter;
this.image_index = -1;
if (!Enum.IsDefined (typeof (ToolStripItemAlignment), value))
throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripItemAlignment", value));
- this.alignment = value;
+ if (this.alignment != value) {
+ this.alignment = value;
+ this.CalculateAutoSize ();
+ }
}
}
- [MonoTODO]
+ [MonoTODO ("Stub, does nothing")]
[Browsable (false)]
[DefaultValue (false)]
[EditorBrowsable (EditorBrowsableState.Advanced)]
}
public virtual Color BackColor {
- get { return this.back_color; }
+ get {
+ if (back_color != Color.Empty)
+ return back_color;
+
+ if (Parent != null)
+ return parent.BackColor;
+
+ return Control.DefaultBackColor;
+ }
set {
if (this.back_color != value) {
back_color = value;
this.display_style = value;
this.CalculateAutoSize ();
OnDisplayStyleChanged (EventArgs.Empty);
- if (this.Parent != null)
- this.Parent.PerformLayout ();
}
}
}
}
[Localizable (true)]
- public virtual Font Font
- {
- get { return this.font; }
+ public virtual Font Font {
+ get {
+ if (font != null)
+ return font;
+
+ if (Parent != null)
+ return Parent.Font;
+
+ return DefaultFont;
+ }
set {
if (this.font != value) {
this.font = value;
}
public virtual Color ForeColor {
- get { return this.fore_color; }
+ get {
+ if (fore_color != Color.Empty)
+ return fore_color;
+
+ if (Parent != null)
+ return parent.ForeColor;
+
+ return Control.DefaultForeColor;
+ }
set {
if (this.fore_color != value) {
this.fore_color = value;
return this.image;
if (this.image_index >= 0)
- if (this.owner != null && this.owner.ImageList != null)
+ if (this.owner != null && this.owner.ImageList != null && this.owner.ImageList.Images.Count > this.image_index)
return this.owner.ImageList.Images[this.image_index];
if (!string.IsNullOrEmpty (this.image_key))
- if (this.owner != null && this.owner.ImageList != null)
+ if (this.owner != null && this.owner.ImageList != null && this.owner.ImageList.Images.Count > this.image_index)
return this.owner.ImageList.Images[this.image_key];
return null;
if (!Enum.IsDefined (typeof (ContentAlignment), value))
throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ContentAlignment", value));
- this.image_align = value;
- this.Invalidate ();
+ if (image_align != value) {
+ this.image_align = value;
+ this.CalculateAutoSize ();
+ }
}
}
public ToolStripItemImageScaling ImageScaling {
get { return this.image_scaling; }
set {
- this.image_scaling = value;
- this.CalculateAutoSize ();
- this.Invalidate ();
+ if (image_scaling != value) {
+ this.image_scaling = value;
+ this.CalculateAutoSize ();
+ }
}
}
get { return this.owner; }
set {
if (this.owner != value) {
- this.owner = value;
- this.CalculateAutoSize ();
- OnOwnerChanged (EventArgs.Empty);
+ if (this.owner != null)
+ this.owner.Items.Remove (this);
+
+ if (value != null)
+ value.Items.Add (this);
+ else
+ this.owner = null;
}
}
}
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public virtual bool Pressed { get { return this.is_pressed; } }
- [MonoTODO ("Stub, not implemented")]
+ [MonoTODO ("RTL not implemented")]
[Localizable (true)]
public virtual RightToLeft RightToLeft {
get { return this.right_to_left; }
set {
if (!Enum.IsDefined (typeof (ContentAlignment), value))
throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ContentAlignment", value));
- this.text_align = value;
- this.Invalidate ();
+
+ if (this.text_align != value) {
+ this.text_align = value;
+ this.CalculateAutoSize ();
+ }
}
}
#endregion
#region Public Methods
- [MonoTODO ("Stub")]
+ [MonoTODO ("Stub, does nothing")]
[EditorBrowsable (EditorBrowsableState.Advanced)]
public DragDropEffects DoDragDrop (Object data, DragDropEffects allowedEffects)
{
}
[EditorBrowsable (EditorBrowsableState.Never)]
- public virtual void ResetBackColor () { this.BackColor = Control.DefaultBackColor; }
+ public virtual void ResetBackColor () { this.BackColor = Color.Empty; }
[EditorBrowsable (EditorBrowsableState.Never)]
public virtual void ResetDisplayStyle () { this.display_style = this.DefaultDisplayStyle; }
[EditorBrowsable (EditorBrowsableState.Never)]
- public virtual void ResetFont () { this.font = new Font ("Tahoma", 8.25f); }
+ public virtual void ResetFont () { this.font = null; }
[EditorBrowsable (EditorBrowsableState.Never)]
- public virtual void ResetForeColor () { this.ForeColor = Control.DefaultForeColor; }
+ public virtual void ResetForeColor () { this.ForeColor = Color.Empty; }
[EditorBrowsable (EditorBrowsableState.Never)]
public virtual void ResetImage () { this.image = null; }
if (!this.is_selected && this.CanSelect) {
this.is_selected = true;
- if (this.Visible && this.Parent.Focused && this is ToolStripControlHost)
- (this as ToolStripControlHost).Focus ();
-
- this.Invalidate ();
- this.Parent.NotifySelectedChanged (this);
+ if (this.Parent != null) {
+ if (this.Visible && this.Parent.Focused && this is ToolStripControlHost)
+ (this as ToolStripControlHost).Focus ();
+
+ this.Invalidate ();
+ this.Parent.NotifySelectedChanged (this);
+ }
+ OnUIASelectionChanged ();
}
}
StopAnimation ();
image = null;
}
+
+ if (owner != null)
+ owner.Items.Remove (this);
base.Dispose (disposing);
}
EventHandler eh = (EventHandler)(Events [DoubleClickEvent]);
if (eh != null)
eh (this, e);
-
- if (!double_click_enabled)
- OnClick (e);
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
this.is_selected = false;
this.is_pressed = false;
this.Invalidate ();
+ OnUIASelectionChanged ();
}
EventHandler eh = (EventHandler)(Events [MouseLeaveEvent]);
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected internal virtual void OnOwnerFontChanged (EventArgs e)
{
+ this.CalculateAutoSize ();
+ OnFontChanged (EventArgs.Empty);
}
-
- protected virtual void OnPaint (PaintEventArgs e)
+
+ void OnPaintInternal (PaintEventArgs e)
{
+ // Have the background rendered independently from OnPaint
if (this.parent != null)
this.parent.Renderer.DrawItemBackground (new ToolStripItemRenderEventArgs (e.Graphics, this));
-
+
+ OnPaint (e);
+ }
+
+ protected virtual void OnPaint (PaintEventArgs e)
+ {
PaintEventHandler eh = (PaintEventHandler)(Events [PaintEvent]);
if (eh != null)
eh (this, e);
protected virtual void OnParentChanged (ToolStrip oldParent, ToolStrip newParent)
{
+ this.text_size = TextRenderer.MeasureText (this.Text == null ? string.Empty : this.text, this.Font, Size.Empty, TextFormatFlags.HidePrefix);
+
if (oldParent != null)
oldParent.PerformLayout ();
remove {Events.RemoveHandler (DoubleClickEvent, value); }
}
- [MonoTODO ("Not raised")]
+ [MonoTODO ("Event never raised")]
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Advanced)]
public event DragEventHandler DragDrop {
remove { Events.RemoveHandler (DragDropEvent, value); }
}
- [MonoTODO ("Not raised")]
+ [MonoTODO ("Event never raised")]
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Advanced)]
public event DragEventHandler DragEnter {
remove { Events.RemoveHandler (DragEnterEvent, value); }
}
- [MonoTODO ("Not raised")]
+ [MonoTODO ("Event never raised")]
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Advanced)]
public event EventHandler DragLeave {
remove { Events.RemoveHandler (DragLeaveEvent, value); }
}
- [MonoTODO ("Not raised")]
+ [MonoTODO ("Event never raised")]
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Advanced)]
public event DragEventHandler DragOver {
remove {Events.RemoveHandler (ForeColorChangedEvent, value); }
}
- [MonoTODO ("Not raised")]
+ [MonoTODO ("Event never raised")]
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Advanced)]
public event GiveFeedbackEventHandler GiveFeedback {
remove {Events.RemoveHandler (PaintEvent, value); }
}
- [MonoTODO ("Not raised")]
+ [MonoTODO ("Event never raised")]
public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp {
add { Events.AddHandler (QueryAccessibilityHelpEvent, value); }
remove { Events.RemoveHandler (QueryAccessibilityHelpEvent, value); }
}
- [MonoTODO ("Not raised")]
+ [MonoTODO ("Event never raised")]
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Advanced)]
public event QueryContinueDragEventHandler QueryContinueDrag {
preferred_size = new Size (width, height);
break;
case ToolStripItemDisplayStyle.Image:
- if (this.Image == null)
+ if (this.GetImageSize () == Size.Empty)
preferred_size = this.DefaultSize;
else {
switch (this.image_scaling) {
case ToolStripItemImageScaling.None:
- preferred_size = this.Image.Size;
+ preferred_size = this.GetImageSize ();
break;
case ToolStripItemImageScaling.SizeToFit:
if (this.parent == null)
- preferred_size = this.Image.Size;
+ preferred_size = this.GetImageSize ();
else
preferred_size = this.parent.ImageScalingSize;
break;
int width2 = text_size.Width + this.padding.Horizontal;
int height2 = text_size.Height + this.padding.Vertical;
- if (this.Image != null) {
- Size image_size = this.Image.Size;
+ if (this.GetImageSize () != Size.Empty) {
+ Size image_size = this.GetImageSize ();
if (this.image_scaling == ToolStripItemImageScaling.SizeToFit && this.parent != null)
image_size = this.parent.ImageScalingSize;
preferred_size.Height += 4;
preferred_size.Width += 4;
}
-
- // Account for ToolStripDropDownButton's drop down arrow
- if (this is ToolStripDropDownButton && (this as ToolStripDropDownButton).ShowDropDownArrow)
- preferred_size.Width += 9;
return preferred_size;
}
}
}
+ private static Font DefaultFont { get { return new Font ("Tahoma", 8.25f); } }
+
internal virtual ToolStripTextDirection DefaultTextDirection { get { return ToolStripTextDirection.Inherit; } }
internal virtual void Dismiss (ToolStripDropDownCloseReason reason)
if (is_selected) {
this.is_selected = false;
this.Invalidate ();
+ OnUIASelectionChanged ();
}
}
internal Size GetImageSize ()
{
- if (this.Image == null)
- return Size.Empty;
+ // Get the actual size of our internal image -or-
+ // Get the ImageList.ImageSize if we are using ImageLists
+ if (this.image_scaling == ToolStripItemImageScaling.None) {
+ if (this.image != null)
+ return image.Size;
+
+ if (this.image_index >= 0 || !string.IsNullOrEmpty (this.image_key))
+ if (this.owner != null && this.owner.ImageList != null)
+ return this.owner.ImageList.ImageSize;
+ } else {
+ // If we have an image and a parent, return ImageScalingSize
+ if (this.Parent == null)
+ return Size.Empty;
+
+ if (this.image != null)
+ return this.Parent.ImageScalingSize;
+
+ if (this.image_index >= 0 || !string.IsNullOrEmpty (this.image_key))
+ if (this.owner != null && this.owner.ImageList != null)
+ return this.Parent.ImageScalingSize;
+ }
- if (this.image_scaling == ToolStripItemImageScaling.None)
- return this.Image.Size;
-
- if (this.Parent == null)
- return Size.Empty;
-
- return this.Parent.ImageScalingSize;
+ return Size.Empty;
}
internal string GetToolTip ()
switch (met) {
case ToolStripItemEventType.MouseUp:
+ this.HandleClick (((MouseEventArgs)e).Clicks, e);
this.OnMouseUp ((MouseEventArgs)e);
- this.HandleClick (e);
break;
case ToolStripItemEventType.MouseDown:
this.OnMouseDown ((MouseEventArgs)e);
this.OnMouseMove ((MouseEventArgs)e);
break;
case ToolStripItemEventType.Paint:
- this.OnPaint ((PaintEventArgs)e);
+ this.OnPaintInternal ((PaintEventArgs)e);
break;
case ToolStripItemEventType.Click:
- this.HandleClick (e);
+ this.HandleClick (1, e);
break;
}
}
- internal virtual void HandleClick (EventArgs e)
+ internal virtual void HandleClick (int mouse_clicks, EventArgs e)
{
+ if (Parent == null)
+ return;
this.Parent.HandleItemClick (this);
- this.OnClick (e);
+ if (mouse_clicks == 2 && double_click_enabled)
+ this.OnDoubleClick (e);
+ else
+ this.OnClick (e);
}
internal virtual void SetPlacement (ToolStripItemPlacement placement)
return true;
if (!(this.Owner is ToolStripDropDownMenu))
- return true;
+ return false;
ToolStripDropDownMenu tsddm = (ToolStripDropDownMenu)this.Owner;
return true;
if (!(this.Owner is ToolStripDropDownMenu))
- return true;
+ return false;
ToolStripDropDownMenu tsddm = (ToolStripDropDownMenu)this.Owner;
get { return this.visible; }
set { this.visible = value; Invalidate (); }
}
-
+
+ internal ToolStrip InternalOwner {
+ set {
+ if (this.owner != value) {
+ this.owner = value;
+ if (this.owner != null)
+ this.CalculateAutoSize ();
+ OnOwnerChanged (EventArgs.Empty);
+ }
+ }
+ }
+
internal Point Location {
get { return this.bounds.Location; }
set {
}
#endregion
+ #region UIA Framework: Methods, Properties and Events
+
+ static object UIASelectionChangedEvent = new object ();
+
+ internal event EventHandler UIASelectionChanged {
+ add { Events.AddHandler (UIASelectionChangedEvent, value); }
+ remove { Events.RemoveHandler (UIASelectionChangedEvent, value); }
+ }
+
+ internal void OnUIASelectionChanged ()
+ {
+ EventHandler eh = (EventHandler)(Events [UIASelectionChangedEvent]);
+ if (eh != null)
+ eh (this, EventArgs.Empty);
+ }
+
+ #endregion
+
[ComVisible (true)]
public class ToolStripItemAccessibleObject : AccessibleObject
{
{
}
}
-
-#endif