//
// ToolStripContentPanel.cs
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2006 Jonathan Pobst
//
// Authors:
// Jonathan Pobst (monkey@jpobst.com)
//
#if NET_2_0
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms.Layout;
using System.ComponentModel;
namespace System.Windows.Forms{
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
[DefaultEvent ("Load")]
[ToolboxItem (false)]
[Docking (DockingBehavior.Never)]
[InitializationEvent ("Load")]
[Designer ("System.Windows.Forms.Design.ToolStripContentPanelDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
public class ToolStripContentPanel : Panel
{
private ToolStripRenderMode render_mode;
private ToolStripRenderer renderer;
#region Public Constructors
public ToolStripContentPanel () : base ()
{
this.RenderMode = ToolStripRenderMode.System;
}
#endregion
#region Public Properties
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public override AnchorStyles Anchor {
get { return base.Anchor; }
set { base.Anchor = value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public override bool AutoScroll {
get { return base.AutoScroll; }
set { base.AutoScroll = value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public new Size AutoScrollMargin {
get { return base.AutoScrollMargin; }
set { base.AutoScrollMargin = value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public new Size AutoScrollMinSize {
get { return base.AutoScrollMinSize; }
set { base.AutoScrollMinSize = value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public override bool AutoSize {
get { return base.AutoSize; }
set { base.AutoSize = value; }
}
[Browsable (false)]
[Localizable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public override AutoSizeMode AutoSizeMode {
get { return base.AutoSizeMode; }
set { base.AutoSizeMode = value; }
}
public override Color BackColor {
get { return base.BackColor; }
set { base.BackColor = value;
if (this.Parent != null)
this.Parent.BackColor = value;
}
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public new bool CausesValidation {
get { return base.CausesValidation; }
set { base.CausesValidation = value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public override DockStyle Dock {
get { return base.Dock; }
set { base.Dock = value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public new Point Location {
get { return base.Location; }
set { base.Location = value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public override Size MaximumSize {
get { return base.MaximumSize; }
set { base.MaximumSize = value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public override Size MinimumSize {
get { return base.MinimumSize; }
set { base.MinimumSize = value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public new string Name {
get { return base.Name; }
set { base.Name = value; }
}
[Browsable (false)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public ToolStripRenderer Renderer {
get {
if (this.render_mode == ToolStripRenderMode.ManagerRenderMode)
return ToolStripManager.Renderer;
return this.renderer;
}
set {
if (this.renderer != value) {
this.renderer = value;
this.render_mode = ToolStripRenderMode.Custom;
this.OnRendererChanged (EventArgs.Empty);
}
}
}
public ToolStripRenderMode RenderMode {
get { return this.render_mode; }
set {
if (!Enum.IsDefined (typeof (ToolStripRenderMode), value))
throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripRenderMode", value));
if (value == ToolStripRenderMode.Custom && this.renderer == null)
throw new NotSupportedException ("Must set Renderer property before setting RenderMode to Custom");
else if (value == ToolStripRenderMode.Professional)
this.renderer = new ToolStripProfessionalRenderer ();
else if (value == ToolStripRenderMode.System)
this.renderer = new ToolStripSystemRenderer ();
this.render_mode = value;
}
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public new int TabIndex {
get { return base.TabIndex; }
set { base.TabIndex = value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public new bool TabStop {
get { return base.TabStop; }
set { base.TabStop = value; }
}
#endregion
#region Protected Methods
protected override void OnHandleCreated (EventArgs e)
{
base.OnHandleCreated (e);
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected virtual void OnLoad (EventArgs e)
{
EventHandler eh = (EventHandler)(Events [LoadEvent]);
if (eh != null)
eh (this, e);
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected override void OnPaintBackground (PaintEventArgs e)
{
base.OnPaintBackground (e);
this.Renderer.DrawToolStripContentPanelBackground (new ToolStripContentPanelRenderEventArgs (e.Graphics, this));
}
protected virtual void OnRendererChanged (EventArgs e)
{
EventHandler eh = (EventHandler)(Events [RendererChangedEvent]);
if (eh != null)
eh (this, e);
}
#endregion
#region Public Events
static object LoadEvent = new object ();
static object RendererChangedEvent = new object ();
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public new event EventHandler AutoSizeChanged {
add { base.AutoSizeChanged += value; }
remove { base.AutoSizeChanged -= value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public new event EventHandler CausesValidationChanged {
add { base.CausesValidationChanged += value; }
remove { base.CausesValidationChanged -= value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public new event EventHandler DockChanged {
add { base.DockChanged += value; }
remove { base.DockChanged -= value; }
}
public event EventHandler Load {
add { Events.AddHandler (LoadEvent, value); }
remove { Events.RemoveHandler (LoadEvent, value); }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public new event EventHandler LocationChanged {
add { base.LocationChanged += value; }
remove { base.LocationChanged -= value; }
}
public event EventHandler RendererChanged {
add { Events.AddHandler (RendererChangedEvent, value); }
remove { Events.RemoveHandler (RendererChangedEvent, value); }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public new event EventHandler TabIndexChanged {
add { base.TabIndexChanged += value; }
remove { base.TabIndexChanged -= value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public new event EventHandler TabStopChanged {
add { base.TabStopChanged += value; }
remove { base.TabStopChanged -= value; }
}
#endregion
}
}
#endif
|