DotNet 4.8.1 build of DotNetBar

This commit is contained in:
2025-02-07 10:35:23 -05:00
parent 33439b63a0
commit 6b0a5d60f4
2609 changed files with 989814 additions and 7 deletions

View File

@@ -0,0 +1,98 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Xml;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents class that is a bar container for document docking.
/// </summary>
[DesignTimeVisible(false),ToolboxItem(false),TypeConverter(typeof(DocumentBarContainerConverter))]
public class DocumentBarContainer:DocumentBaseContainer
{
#region Private Variables and Constructor
private Bar m_Bar=null;
/// <summary>
/// Creates new instance of the class.
/// </summary>
public DocumentBarContainer(){}
/// <summary>
/// Creates new instance of the class and initializes it with the Bar object.
/// </summary>
/// <param name="bar">Bar to contain on document.</param>
public DocumentBarContainer(Bar bar)
{
m_Bar=bar;
if(m_Bar.SplitDockHeight>0 || m_Bar.SplitDockWidth>0)
this.SetLayoutBounds(new Rectangle(0,0,m_Bar.SplitDockWidth,m_Bar.SplitDockHeight));
}
/// <summary>
/// Creates new instance of the class and initializes it with the bar and propesed width and height.
/// </summary>
/// <param name="bar">Bar to contain on document.</param>
/// <param name="proposedWidth">Proposed width of the document in pixels</param>
/// <param name="proposedHeight">Proposed height of the document in pixels</param>
public DocumentBarContainer(Bar bar, int proposedWidth, int proposedHeight)
{
m_Bar=bar;
this.SetLayoutBounds(new Rectangle(0,0,proposedWidth,proposedHeight));
}
#endregion
#region Internal Implementation
/// <summary>
/// Gets or sets the bar that is contained by this document.
/// </summary>
[Browsable(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Bar Bar
{
get {return m_Bar;}
set {m_Bar=value;}
}
/// <summary>
/// Resizes document object.
/// </summary>
/// <param name="bounds">Available bounds for the document.</param>
public override void Layout(Rectangle bounds)
{
if (m_Bar != null)
{
m_Bar.SplitDockHeight = 0;
m_Bar.SplitDockWidth = 0;
m_Bar.MinHeight = 0;
m_Bar.RecalcSize(bounds.Size);
m_Bar.Location = bounds.Location;
}
SetDisplayBounds(bounds);
}
/// <summary>
/// Gets whether document is visible.
/// </summary>
public override bool Visible
{
get
{
if (m_Bar == null)
return false;
if(m_Bar.GetDesignMode())
return true;
return m_Bar.IsVisible;
}
}
/// <summary>
/// Gets the minimum size of the document.
/// </summary>
protected internal override System.Drawing.Size MinimumSize
{
get {return m_Bar.GetAdjustedFullSize(m_Bar.MinimumDockSize(eOrientation.Horizontal));}
}
#endregion
}
}

View File

@@ -0,0 +1,65 @@
using System;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using System.Reflection;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents DocumentBarContainer converter.
/// </summary>
public class DocumentBarContainerConverter:TypeConverter
{
/// <summary>
/// Creates new instance of the class.
/// </summary>
public DocumentBarContainerConverter(){}
/// <summary>
/// Checks whether conversion can be made to specified type.
/// </summary>
/// <param name="context">Context Information.</param>
/// <param name="destinationType">Destination type.</param>
/// <returns></returns>
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if(destinationType==typeof(InstanceDescriptor))
return true;
return base.CanConvertTo(context, destinationType);
}
/// <summary>
/// Converts object to specified type.
/// </summary>
/// <param name="context">Context information.</param>
/// <param name="culture">Culture information.</param>
/// <param name="value">Object to convert.</param>
/// <param name="destinationType">Destination type.</param>
/// <returns>Object converted to destination type.</returns>
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if(destinationType==null)
throw new ArgumentNullException("destinationType");
if((destinationType==typeof(InstanceDescriptor)) && (value is DocumentBarContainer))
{
DocumentBarContainer doc=(DocumentBarContainer)value;
Type[] constructorParams=null;
MemberInfo constructorMemberInfo = null;
object[] constructorValues = null;
constructorParams = new Type[3] { typeof(Bar),typeof(int),typeof(int) } ;
constructorMemberInfo = typeof(DocumentBarContainer).GetConstructor(constructorParams);
constructorValues=new object[3] {doc.Bar,doc.LayoutBounds.Width,doc.LayoutBounds.Height};
if(constructorMemberInfo!=null)
{
return new InstanceDescriptor(constructorMemberInfo, constructorValues);
}
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
}

View File

@@ -0,0 +1,186 @@
using System;
using System.ComponentModel;
using System.Drawing;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents Document container base class.
/// </summary>
public abstract class DocumentBaseContainer
{
#region Private Variables and Constructor
private Rectangle m_LayoutBounds=Rectangle.Empty;
private Rectangle m_DisplayBounds=Rectangle.Empty;
private DocumentBaseContainer m_Parent=null;
private static long IdCounter = 0;
private long _Id = 0;
/// <summary>
/// Creates new instance of the class.
/// </summary>
public DocumentBaseContainer()
{
IdCounter++;
_Id = IdCounter;
}
#endregion
#region Internal Implementation
/// <summary>
/// Gets the unique ID for the container.
/// </summary>
public long Id
{
get { return _Id; }
}
/// <summary>
/// Returns actual display bounds of the document.
/// </summary>
[Browsable(false)]
public virtual Rectangle DisplayBounds
{
get {return m_DisplayBounds;}
}
/// <summary>
/// Returns layout bounds of the document. Layout bounds are proposed bounds of the layout and might not be the same
/// as DisplayBounds.
/// </summary>
[Browsable(false)]
public virtual Rectangle LayoutBounds
{
get {return m_LayoutBounds;}
}
/// <summary>
/// Gets the parent container.
/// </summary>
public virtual DocumentBaseContainer Parent
{
get {return m_Parent;}
}
/// <summary>
/// Resizes the document within specified bounds.
/// </summary>
/// <param name="bounds">Area available for the document.</param>
public abstract void Layout(Rectangle bounds);
/// <summary>
/// Sets the display bounds.
/// </summary>
/// <param name="r">New display bounds.</param>
internal void SetDisplayBounds(Rectangle r)
{
m_DisplayBounds=r;
}
/// <summary>
/// Sets layout bounds.
/// </summary>
/// <param name="r">New layout bounds.</param>
internal void SetLayoutBounds(Rectangle r)
{
m_LayoutBounds=r;
}
/// <summary>
/// Resets the layout bounds for the document base container to the empty bounds.
/// </summary>
public void ResetLayoutBounds()
{
m_LayoutBounds = Rectangle.Empty;
}
/// <summary>
/// Resets the layout bounds for the document base container to the empty bounds.
/// </summary>
public void ResetDisplayBounds()
{
m_DisplayBounds = Rectangle.Empty;
}
/// <summary>
/// Sets the parent document.
/// </summary>
/// <param name="parent">Parent container.</param>
internal void SetParent(DocumentBaseContainer parent)
{
m_Parent=parent;
}
/// <summary>
/// Sets the width of the document.
/// </summary>
/// <param name="width">Width in pixels</param>
public virtual void SetWidth(int width)
{
if(m_Parent!=null)
{
//if(!m_Parent.OnSetWidth(this,width))
//return;
m_Parent.OnSetWidth(this, width);
}
if (width >= this.MinimumSize.Width || this.MinimumSize.Width == 0)
{
ResetDisplayBounds();
m_LayoutBounds.Width = width;
}
}
/// <summary>
/// Sets the height of the document.
/// </summary>
/// <param name="height">Height in pixels.</param>
public virtual void SetHeight(int height)
{
if(m_Parent!=null)
m_Parent.OnSetHeight(this,height);
if (height >= this.MinimumSize.Height || this.MinimumSize.Height == 0)
{
ResetDisplayBounds();
m_LayoutBounds.Height = height;
}
}
/// <summary>
/// Occurs when width is being set on child document.
/// </summary>
/// <param name="doc">Reference document being changed</param>
/// <param name="width">Width in pixels</param>
/// <returns>True if width was applied by parent otherwise false</returns>
protected internal virtual bool OnSetWidth(DocumentBaseContainer doc, int width){return false;}
/// <summary>
/// Occurs when height is being set on child document.
/// </summary>
/// <param name="doc">Reference document being changed</param>
/// <param name="height">Height in pixels</param>
/// <returns>True if width was applied by parent otherwise false</returns>
protected internal virtual bool OnSetHeight(DocumentBaseContainer doc, int height){return false;}
/// <summary>
/// Gets whether document is visible or not.
/// </summary>
public abstract bool Visible {get;}
/// <summary>
/// Gets minimum size of the document.
/// </summary>
protected internal abstract System.Drawing.Size MinimumSize {get;}
/// <summary>
/// Updates bounds of the item in response to the scrolling of LayoutControl.
/// </summary>
/// <param name="xScroll"></param>
/// <param name="yScroll"></param>
internal virtual void UpdateScrollBounds(int xScroll, int yScroll, bool moveControls)
{
m_DisplayBounds.Offset(xScroll, yScroll);
}
#endregion
}
}

View File

@@ -0,0 +1,153 @@
using System;
using System.Collections;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Collection of DocumentBaseContainer objects.
/// </summary>
public class DocumentBaseContainerCollection:CollectionBase
{
#region Private Variables and Events
public event EventHandler DocumentRemoved;
public event EventHandler DocumentAdded;
private DocumentBaseContainer m_Owner=null;
#endregion
#region Internal Implementation
public DocumentBaseContainerCollection()
{
//m_Owner=owner;
}
/// <summary>
/// Adds new object to the collection.
/// </summary>
/// <param name="tab">Object to add.</param>
/// <returns>Index of newly added object.</returns>
public int Add(DocumentBaseContainer tab)
{
return List.Add(tab);
}
/// <summary>
/// Adds new objects to the collection.
/// </summary>
/// <param name="documents">Array of documents to add.</param>
public void AddRange(DocumentBaseContainer[] documents)
{
foreach(DocumentBaseContainer doc in documents)
List.Add(doc);
}
/// <summary>
/// Returns reference to the object in collection based on it's index.
/// </summary>
public DocumentBaseContainer this[int index]
{
get {return (DocumentBaseContainer)(List[index]);}
set {List[index] = value;}
}
/// <summary>
/// Inserts new object into the collection.
/// </summary>
/// <param name="index">Position of the object.</param>
/// <param name="value">Object to insert.</param>
public void Insert(int index, DocumentBaseContainer value)
{
List.Insert(index, value);
}
/// <summary>
/// Returns index of the object inside of the collection.
/// </summary>
/// <param name="value">Reference to the object.</param>
/// <returns>Index of the object.</returns>
public int IndexOf(DocumentBaseContainer value)
{
return List.IndexOf(value);
}
/// <summary>
/// Returns whether collection contains specified object.
/// </summary>
/// <param name="value">Object to look for.</param>
/// <returns>true if object is part of the collection, otherwise false.</returns>
public bool Contains(DocumentBaseContainer value)
{
return List.Contains(value);
}
/// <summary>
/// Removes specified object from the collection.
/// </summary>
/// <param name="value"></param>
public void Remove(DocumentBaseContainer value)
{
List.Remove(value);
}
protected override void OnRemoveComplete(int index,object value)
{
base.OnRemoveComplete(index,value);
DocumentBaseContainer item=value as DocumentBaseContainer;
item.SetParent(null);
if(DocumentRemoved!=null)
DocumentRemoved(item,new EventArgs());
}
protected override void OnInsertComplete(int index,object value)
{
base.OnInsertComplete(index,value);
DocumentBaseContainer item=value as DocumentBaseContainer;
if(m_Owner!=null)
item.SetParent(m_Owner);
if(DocumentAdded!=null)
DocumentAdded(item,new EventArgs());
}
/// <summary>
/// Copies collection into the specified array.
/// </summary>
/// <param name="array">Array to copy collection to.</param>
/// <param name="index">Starting index.</param>
public void CopyTo(DocumentBaseContainer[] array, int index)
{
List.CopyTo(array, index);
}
/// <summary>
/// Copies contained items to the DocumentBaseContainer array.
/// </summary>
/// <param name="array">Array to copy to.</param>
internal void CopyTo(DocumentBaseContainer[] array)
{
List.CopyTo(array,0);
}
internal DocumentBaseContainer Owner
{
get {return m_Owner;}
set {m_Owner=value;}
}
protected override void OnClear()
{
//m_Owner.OnTabsCleared();
base.OnClear();
}
public int VisibleCount
{
get
{
int count = 0;
foreach (DocumentBaseContainer item in this.List)
{
if (item.Visible) count++;
}
return count;
}
}
#endregion
}
}

View File

@@ -0,0 +1,562 @@
using System;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
using System.Xml;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents Dock container with either horizontal or vertical layout.
/// </summary>
[DesignTimeVisible(false), ToolboxItem(false), TypeConverter(typeof(DocumentDockContainerConverter))]
public class DocumentDockContainer : DocumentBaseContainer
{
#region Private Variables
private bool _OversizeEnabled;
private eOrientation m_Orientation = eOrientation.Horizontal;
private DocumentBaseContainerCollection m_Documents = new DocumentBaseContainerCollection();
private int m_SplitterSize = 3;
private Size m_MinimumSize = Size.Empty;
private bool m_RecordDocumentSize = false;
#endregion
#region Internal Implementation
/// <summary>
/// Creates new instance of the object and initializes it with specified values.
/// </summary>
/// <param name="documents">Array of documents to host in this container.</param>
/// <param name="orientation">Container orientation</param>
public DocumentDockContainer(DocumentBaseContainer[] documents, eOrientation orientation)
{
m_Orientation = orientation;
m_Documents.Owner = this;
m_Documents.DocumentAdded += new EventHandler(DocumentAdded);
m_Documents.DocumentRemoved += new EventHandler(DocumentRemoved);
if (documents != null)
{
foreach (DocumentBaseContainer doc in documents)
m_Documents.Add(doc);
}
}
/// <summary>
/// Creates new instance of the object.
/// </summary>
public DocumentDockContainer() : this(null, eOrientation.Horizontal) { }
/// <summary>
/// Resizes the object inside of the given bounds.
/// </summary>
/// <param name="bounds">Available area.</param>
public override void Layout(Rectangle bounds)
{
if (LayoutInternal(bounds))
{
if (!_OversizeEnabled)
this.SetDisplayBounds(bounds);
}
else
this.SetDisplayBounds(Rectangle.Empty);
}
private struct DocumentMeasureInfo
{
public int TotalSize;
public int VisibleCount;
}
private DocumentMeasureInfo MeasureDocuments(Rectangle bounds)
{
DocumentMeasureInfo info = new DocumentMeasureInfo();
if (m_Documents.Count == 0)
return info;
int boundsSize = (m_Orientation == eOrientation.Horizontal ? bounds.Width : bounds.Height);
int defaultSize = 0; // (boundsSize - ((m_Documents.Count - 1) * m_SplitterSize)) / m_Documents.Count;
// Check whether default size is below minimum size and make appropriate adjustments...
int[] dockSizes = new int[m_Documents.Count];
bool adjustDefaultSize = false;
int defaultSizeCount = m_Documents.Count;
int splitterSize = Dpi.Width(m_SplitterSize);
do
{
defaultSize = (boundsSize - ((defaultSizeCount - 1) * splitterSize)) / defaultSizeCount;
adjustDefaultSize = false;
for (int i = 0; i < m_Documents.Count; i++)
{
if (dockSizes[i] != 0) continue;
DocumentBaseContainer doc = m_Documents[i];
if (m_Orientation == eOrientation.Horizontal && doc.LayoutBounds.Width == 0 && doc.MinimumSize.Width > defaultSize)
{
dockSizes[i] = doc.MinimumSize.Width;
adjustDefaultSize = true;
boundsSize -= dockSizes[i];
defaultSizeCount--;
break;
}
else if (m_Orientation == eOrientation.Vertical && doc.LayoutBounds.Height == 0 && doc.MinimumSize.Height > defaultSize)
{
dockSizes[i] = doc.MinimumSize.Height;
adjustDefaultSize = true;
boundsSize -= dockSizes[i];
defaultSizeCount--;
break;
}
}
} while (adjustDefaultSize && defaultSizeCount > 0);
int totalSize = 0;
int visibleCount = 0;
for (int i = 0; i < m_Documents.Count; i++)
{
DocumentBaseContainer doc = m_Documents[i];
if (m_Orientation == eOrientation.Horizontal && doc.LayoutBounds.Width == 0)
doc.SetLayoutBounds(new Rectangle(0, 0, (dockSizes[i] > 0 ? dockSizes[i] : defaultSize), bounds.Height));
else if (m_Orientation == eOrientation.Vertical && doc.LayoutBounds.Height == 0)
doc.SetLayoutBounds(new Rectangle(0, 0, bounds.Width, (dockSizes[i] > 0 ? dockSizes[i] : defaultSize)));
if (doc.Visible)
{
totalSize += ((m_Orientation == eOrientation.Horizontal ? doc.LayoutBounds.Width : doc.LayoutBounds.Height) + splitterSize);
visibleCount++;
}
}
if (visibleCount > 0)
totalSize -= splitterSize;
info.TotalSize = totalSize;
info.VisibleCount = visibleCount;
return info;
}
private bool AdjustLayoutBoundsForMinimumSize(float m, Rectangle layoutBounds)
{
bool layoutAdjusted = false;
foreach (DocumentBaseContainer doc in m_Documents)
{
if (!doc.Visible) continue;
Rectangle docBounds;
if (m_Orientation == eOrientation.Horizontal)
{
docBounds = new Rectangle(layoutBounds.X, layoutBounds.Y, (int)(doc.LayoutBounds.Width * m), layoutBounds.Height);
if (docBounds.Width < doc.MinimumSize.Width)
{
layoutAdjusted = true;
break;
}
}
else
{
docBounds = new Rectangle(layoutBounds.X, layoutBounds.Y, layoutBounds.Width, (int)(doc.LayoutBounds.Height * m));
if (docBounds.Height < doc.MinimumSize.Height)
{
layoutAdjusted = true;
break;
}
}
}
if (layoutAdjusted)
{
foreach (DocumentBaseContainer doc in m_Documents)
doc.SetLayoutBounds(Rectangle.Empty);
}
return layoutAdjusted;
}
private bool LayoutInternal(Rectangle bounds)
{
if (m_Documents.Count == 0)
return false;
int boundsSize = (m_Orientation == eOrientation.Horizontal ? bounds.Width : bounds.Height);
DocumentMeasureInfo info = MeasureDocuments(bounds);
if (info.VisibleCount == 0)
return false;
int totalSize = info.TotalSize;
int visibleCount = info.VisibleCount;
float m = (float)boundsSize / (float)totalSize;
if (AdjustLayoutBoundsForMinimumSize(m, bounds))
info = MeasureDocuments(bounds);
Rectangle layoutBounds = bounds;
int processed = 0;
bool setSize = true;
if (!m_RecordDocumentSize && Math.Abs(totalSize - boundsSize) / m_Documents.Count != (int)(Math.Abs(totalSize - boundsSize) / m_Documents.Count) * m_Documents.Count)
setSize = false;
bool resize = (totalSize != boundsSize);
Rectangle contentBounds = Rectangle.Empty;
for (int i = 0; i < m_Documents.Count; i++)
{
DocumentBaseContainer doc = m_Documents[i];
if (doc.Visible)
{
processed++;
Rectangle docBounds;
if (resize)
{
if (m_Orientation == eOrientation.Horizontal)
{
if (_OversizeEnabled)
docBounds = new Rectangle(layoutBounds.X, layoutBounds.Y, (int)Math.Max(doc.MinimumSize.Width, (doc.LayoutBounds.Width * m)), Math.Max(layoutBounds.Height, doc.MinimumSize.Height));
else
docBounds = new Rectangle(layoutBounds.X, layoutBounds.Y, (int)(doc.LayoutBounds.Width * m), layoutBounds.Height);
}
else
{
if (_OversizeEnabled)
docBounds = new Rectangle(layoutBounds.X, layoutBounds.Y, Math.Max(layoutBounds.Width, doc.MinimumSize.Width), (int)Math.Max(doc.MinimumSize.Height, (doc.LayoutBounds.Height * m)));
else
docBounds = new Rectangle(layoutBounds.X, layoutBounds.Y, layoutBounds.Width, (int)(doc.LayoutBounds.Height * m));
}
}
else
{
if (m_Orientation == eOrientation.Horizontal)
{
if (_OversizeEnabled)
docBounds = new Rectangle(layoutBounds.X, layoutBounds.Y, doc.LayoutBounds.Width, Math.Max(layoutBounds.Height, doc.MinimumSize.Height));
else
docBounds = new Rectangle(layoutBounds.X, layoutBounds.Y, doc.LayoutBounds.Width, layoutBounds.Height);
}
else
{
if (_OversizeEnabled)
docBounds = new Rectangle(layoutBounds.X, layoutBounds.Y, Math.Max(layoutBounds.Width, doc.MinimumSize.Width), doc.LayoutBounds.Height);
else
docBounds = new Rectangle(layoutBounds.X, layoutBounds.Y, layoutBounds.Width, doc.LayoutBounds.Height);
}
}
if (processed == visibleCount && (!_OversizeEnabled || docBounds.Width < layoutBounds.Width && m_Orientation == eOrientation.Horizontal || docBounds.Height < layoutBounds.Height && m_Orientation == eOrientation.Vertical))
docBounds = layoutBounds;
Rectangle actualDocBounds = docBounds;
actualDocBounds.Offset(_ScrollPosition);
doc.Layout(actualDocBounds);
if (setSize) doc.SetLayoutBounds(actualDocBounds);
if (contentBounds.IsEmpty)
contentBounds = actualDocBounds;
else
contentBounds = Rectangle.Union(contentBounds, actualDocBounds);
int splitterSize = Dpi.Width(m_SplitterSize);
if (m_Orientation == eOrientation.Horizontal)
{
layoutBounds.Width -= (docBounds.Width + splitterSize);
layoutBounds.X += (docBounds.Width + splitterSize);
}
else
{
layoutBounds.Height -= (docBounds.Height + splitterSize);
layoutBounds.Y += (docBounds.Height + splitterSize);
}
}
}
if (_OversizeEnabled)
{
this.SetDisplayBounds(contentBounds);
}
return true;
}
private Point _ScrollPosition = Point.Empty;
internal Point ScrollPosition
{
get { return _ScrollPosition; }
set { _ScrollPosition = value; }
}
/// <summary>
/// Gets whether document is visible or not.
/// </summary>
public override bool Visible
{
get
{
foreach (DocumentBaseContainer doc in m_Documents)
{
if (doc.Visible)
return true;
}
return false;
}
}
/// <summary>
/// Gets the orientation of the container. Default value is Horizontal.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public eOrientation Orientation
{
get { return m_Orientation; }
set
{
if (m_Orientation != value)
{
m_Orientation = value;
OnOrientationChanged();
}
}
}
/// <summary>
/// Returns collection of the documents hosted by this container.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public DocumentBaseContainerCollection Documents
{
get { return m_Documents; }
}
/// <summary>
/// Occurs when width is being set on child document.
/// </summary>
/// <param name="doc">Reference document being changed</param>
/// <param name="width">Width in pixels</param>
/// <returns>True if width was applied by parent otherwise false</returns>
protected internal override bool OnSetWidth(DocumentBaseContainer doc, int width)
{
bool ret = false;
if (m_Orientation != eOrientation.Horizontal || width < doc.MinimumSize.Width && doc.MinimumSize.Width > 0)
return ret;
DocumentBaseContainer pairDoc = null;
DocumentBaseContainer previousDoc = null;
int refIndex = m_Documents.IndexOf(doc);
// Lock in the display size if it is set
for (int i = 0; i < m_Documents.Count; i++)
{
DocumentBaseContainer dc = m_Documents[i];
if (!dc.Visible) continue;
if (dc.DisplayBounds.Width > 0)
dc.SetLayoutBounds(dc.DisplayBounds);
if (i > refIndex && dc.Visible && pairDoc == null)
pairDoc = dc;
else if (i < refIndex && dc.Visible)
previousDoc = dc;
}
int diff = doc.LayoutBounds.Width - width;
if (pairDoc != null && pairDoc.LayoutBounds.Width > 0 && pairDoc.LayoutBounds.Width + diff > 0 &&
(pairDoc.LayoutBounds.Width + diff >= pairDoc.MinimumSize.Width || pairDoc.MinimumSize.Width == 0))
{
pairDoc.SetLayoutBounds(new Rectangle(pairDoc.LayoutBounds.X, pairDoc.LayoutBounds.Y, pairDoc.LayoutBounds.Width + diff, pairDoc.LayoutBounds.Height));
ret = true;
}
else if (pairDoc == null && previousDoc != null && previousDoc.LayoutBounds.Width > 0 && previousDoc.LayoutBounds.Width + diff > 0 &&
(previousDoc.LayoutBounds.Width + diff >= previousDoc.MinimumSize.Width || previousDoc.MinimumSize.Width == 0))
{
doc.SetLayoutBounds(new Rectangle(doc.LayoutBounds.X, doc.LayoutBounds.Y, width, doc.LayoutBounds.Height));
// Resetting previous document width caused problem with ever growing bar when Width of single bar is set
// Reason is that resetting width here will cause the new space in container to be proportionally allocated thus setting single bar width which is intent of this function never works
//previousDoc.SetLayoutBounds(new Rectangle(previousDoc.LayoutBounds.X, previousDoc.LayoutBounds.Y, 0, previousDoc.LayoutBounds.Height));
ret = true;
}
return ret;
}
/// <summary>
/// Occurs when height is being set on child document.
/// </summary>
/// <param name="doc">Reference document being changed</param>
/// <param name="height">Height in pixels</param>
/// <returns>True if width was applied by parent otherwise false</returns>
protected internal override bool OnSetHeight(DocumentBaseContainer doc, int height)
{
bool ret = false;
if (m_Orientation != eOrientation.Vertical || height < doc.MinimumSize.Height && doc.MinimumSize.Height > 0)
return ret;
DocumentBaseContainer pairDoc = null;
DocumentBaseContainer previousDoc = null;
int refIndex = m_Documents.IndexOf(doc);
// Lock in the display size if it is set
for (int i = 0; i < m_Documents.Count; i++)
{
DocumentBaseContainer dc = m_Documents[i];
if (!dc.Visible) continue;
if (dc.DisplayBounds.Height > 0)
dc.SetLayoutBounds(dc.DisplayBounds);
if (i > refIndex && dc.Visible && pairDoc == null)
pairDoc = dc;
else if (i < refIndex && dc.Visible)
previousDoc = dc;
}
if (pairDoc == null) pairDoc = previousDoc;
int diff = doc.LayoutBounds.Height - height;
if (pairDoc != null && pairDoc.LayoutBounds.Height > 0 && pairDoc.LayoutBounds.Height + diff > 0 &&
(pairDoc.LayoutBounds.Height + diff >= pairDoc.MinimumSize.Height || pairDoc.MinimumSize.Height == 0))
{
pairDoc.SetLayoutBounds(new Rectangle(pairDoc.LayoutBounds.X, pairDoc.LayoutBounds.Y, pairDoc.LayoutBounds.Width, pairDoc.LayoutBounds.Height + diff));
ret = true;
}
else if (pairDoc == null && previousDoc != null && previousDoc.LayoutBounds.Height > 0 && previousDoc.LayoutBounds.Height + diff > 0 &&
(previousDoc.LayoutBounds.Height + diff >= previousDoc.MinimumSize.Height || previousDoc.MinimumSize.Height == 0))
{
doc.SetLayoutBounds(new Rectangle(doc.LayoutBounds.X, doc.LayoutBounds.Y, doc.LayoutBounds.Width, height));
previousDoc.SetLayoutBounds(new Rectangle(previousDoc.LayoutBounds.X, previousDoc.LayoutBounds.Y, previousDoc.LayoutBounds.Width, 0));
ret = true;
}
return ret;
}
/// <summary>
/// Returns the DocumentBarContainer object for a given bar.
/// </summary>
/// <param name="bar">Bar to search for.</param>
/// <returns>Reference to container or null if bar could not be found</returns>
public DocumentBarContainer GetBarDocumentContainer(Bar bar)
{
foreach (DocumentBaseContainer doc in m_Documents)
{
if (doc is DocumentBarContainer && ((DocumentBarContainer)doc).Bar == bar)
return (DocumentBarContainer)doc;
else if (doc is DocumentDockContainer)
{
DocumentBarContainer db = ((DocumentDockContainer)doc).GetBarDocumentContainer(bar);
if (db != null) return db;
}
}
return null;
}
/// <summary>
/// Returns minimum size of the object.
/// </summary>
protected internal override System.Drawing.Size MinimumSize
{
get
{
return m_MinimumSize;
}
}
private void DocumentAdded(object sender, EventArgs e)
{
DocumentBaseContainer doc = sender as DocumentBaseContainer;
Size s = doc.MinimumSize;
int splitterSize = Dpi.Width(m_SplitterSize);
if (m_Orientation == eOrientation.Horizontal)
{
m_MinimumSize.Width += (s.Width + splitterSize);
if (s.Height > m_MinimumSize.Height)
m_MinimumSize.Height = s.Height;
}
else
{
m_MinimumSize.Height += (s.Height + splitterSize);
if (s.Width > m_MinimumSize.Width)
m_MinimumSize.Width = s.Width;
}
}
internal void DocumentRemoved(object sender, EventArgs e)
{
RefreshMinimumSize();
}
internal void RefreshMinimumSize()
{
m_MinimumSize = Size.Empty;
foreach (DocumentBaseContainer doc in m_Documents)
{
Size s = doc.MinimumSize;
int splitterSize = Dpi.Width(m_SplitterSize);
if (m_Orientation == eOrientation.Horizontal)
{
m_MinimumSize.Width += (s.Width + splitterSize);
if (s.Height > m_MinimumSize.Height)
m_MinimumSize.Height = s.Height;
}
else
{
m_MinimumSize.Height += (s.Height + splitterSize);
if (s.Width > m_MinimumSize.Width)
m_MinimumSize.Width = s.Width;
}
}
}
private void OnOrientationChanged()
{
ResetDocumentsLayout();
}
private void ResetDocumentsLayout()
{
foreach (DocumentBaseContainer doc in m_Documents)
doc.SetLayoutBounds(Rectangle.Empty);
}
/// <summary>
/// Gets or sets splitter size in pixels between the documents docking inside the container. Default value is 3.
/// </summary>
[Browsable(true), DefaultValue(3), Description("Indicates the splitter size between the documents docking inside the container."), Category("Layout")]
public virtual int SplitterSize
{
get { return m_SplitterSize; }
set
{
m_SplitterSize = value;
foreach (DocumentBaseContainer doc in m_Documents)
{
DocumentDockContainer cont = doc as DocumentDockContainer;
if (cont != null)
cont.SplitterSize = value;
}
}
}
/// <summary>
/// Gets or sets whether the size of the documents is recorded once the layout is calculated.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool RecordDocumentSize
{
get { return m_RecordDocumentSize; }
set { m_RecordDocumentSize = value; }
}
/// <summary>
/// Indicates whether the container is allowed to exceed the parent control client size due to inner child windows minimum size constraints.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool OversizeEnabled
{
get { return _OversizeEnabled; }
set { _OversizeEnabled = value; }
}
internal override void UpdateScrollBounds(int xScroll, int yScroll, bool moveControls)
{
base.UpdateScrollBounds(xScroll, yScroll, moveControls);
foreach (DocumentBaseContainer doc in m_Documents)
{
doc.UpdateScrollBounds(xScroll, yScroll, moveControls);
}
}
#endregion
}
}

View File

@@ -0,0 +1,60 @@
using System;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using System.Reflection;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents DocumentDockContainer object converter.
/// </summary>
public class DocumentDockContainerConverter:TypeConverter
{
public DocumentDockContainerConverter(){}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if(destinationType==typeof(InstanceDescriptor))
return true;
return base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if(destinationType==null)
throw new ArgumentNullException("destinationType");
if((destinationType==typeof(InstanceDescriptor)) && (value is DocumentDockContainer))
{
DocumentDockContainer doc=(DocumentDockContainer)value;
Type[] constructorParams=null;
MemberInfo constructorMemberInfo = null;
object[] constructorValues = null;
if(doc.Documents.Count==0)
{
constructorParams = new Type[0];
constructorMemberInfo = typeof(DocumentDockContainer).GetConstructor(constructorParams);
constructorValues = new object[0];
}
else
{
constructorParams = new Type[2] { typeof(DocumentBaseContainer[]), typeof(eOrientation) } ;
constructorMemberInfo = typeof(DocumentDockContainer).GetConstructor(constructorParams);
DocumentBaseContainer[] documentsArray = new DocumentBaseContainer[doc.Documents.Count];
doc.Documents.CopyTo(documentsArray);
constructorValues=new object[2] {documentsArray,doc.Orientation};
}
if(constructorMemberInfo!=null)
{
return new InstanceDescriptor(constructorMemberInfo, constructorValues);
}
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,29 @@
using System;
namespace DevComponents.DotNetBar
{
internal class DocumentSerializationXml
{
public static string Documents="documents";
public static string DockContainer="dockcontainer";
public static string BarContainer="barcontainer";
public static string Orientation="orientation";
public static string Width="w";
public static string Height="h";
public static string DockSite = "docksite";
public static string DockingSide = "dockingside";
public static string DockSiteSize = "size";
public static string Version = "version";
public static string OriginalDockSiteSize = "originaldocksitesize";
public static DocumentBaseContainer CreateDocument(string xmlName)
{
if(xmlName==DocumentSerializationXml.DockContainer)
return new DocumentDockContainer();
else if(xmlName==DocumentSerializationXml.BarContainer)
return new DocumentBarContainer();
else
throw new InvalidOperationException("Document type not recognized: "+xmlName);
}
}
}

View File

@@ -0,0 +1,333 @@
using System;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Collections;
using System.Drawing;
using System.ComponentModel.Design;
using System.ComponentModel;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents panel that is hosted by DockContainerItem as docked control.
/// </summary>
[ToolboxItem(false), Designer("DevComponents.DotNetBar.Design.PanelDockContainerDesigner, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf")]
public class PanelDockContainer:PanelEx
{
#region Private Variables
private const string INFO_TEXT="Drop controls here. Drag and Drop tabs to perform docking.";
private DockContainerItem m_DockContainerItem=null;
private bool m_UseCustomStyle=false;
#endregion
#region Internal Implementation
#if FRAMEWORK20
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override bool AutoSize
{
get
{
return base.AutoSize;
}
set
{
base.AutoSize = value;
}
}
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override AutoSizeMode AutoSizeMode
{
get
{
return base.AutoSizeMode;
}
set
{
base.AutoSizeMode = value;
}
}
#endif
/// <summary>
/// Creates new instance of the panel.
/// </summary>
public PanelDockContainer():base()
{
this.BackColor=SystemColors.Control;
}
private Rectangle GetThemedRect(Rectangle r)
{
const int offset=6;
switch(this.TabAlignment)
{
case eTabStripAlignment.Top:
{
r.Y-=offset;
r.Height+=offset;
break;
}
case eTabStripAlignment.Left:
{
r.X-=offset;
r.Width+=offset;
break;
}
case eTabStripAlignment.Right:
{
r.Width+=offset;
break;
}
case eTabStripAlignment.Bottom:
{
r.Height+=offset;
break;
}
}
return r;
}
private eTabStripAlignment TabAlignment
{
get
{
if(m_DockContainerItem!=null)
{
if(m_DockContainerItem.ContainerControl is Bar)
{
return ((Bar)m_DockContainerItem.ContainerControl).DockTabAlignment;
}
}
return eTabStripAlignment.Top;
}
}
protected override void OnPaint(PaintEventArgs e)
{
bool baseCall=true;
if(DrawThemedPane && BarFunctions.ThemedOS && m_DockContainerItem!=null)
{
Rectangle r=GetThemedRect(this.ClientRectangle);
eTabStripAlignment tabAlignment=this.TabAlignment;
Rectangle rTemp=new Rectangle(0,0,r.Width,r.Height);
if(tabAlignment==eTabStripAlignment.Right || tabAlignment==eTabStripAlignment.Left)
rTemp=new Rectangle(0,0,rTemp.Height,rTemp.Width);
if(m_ThemeCachedBitmap==null || m_ThemeCachedBitmap.Size!=rTemp.Size)
{
DisposeThemeCachedBitmap();
Bitmap bmp=new Bitmap(rTemp.Width,rTemp.Height,e.Graphics);
try
{
Graphics gTemp=Graphics.FromImage(bmp);
try
{
using(SolidBrush brush=new SolidBrush(Color.Transparent))
gTemp.FillRectangle(brush,0,0,bmp.Width,bmp.Height);
this.ThemeTab.DrawBackground(gTemp,ThemeTabParts.Pane,ThemeTabStates.Normal,rTemp);
}
finally
{
gTemp.Dispose();
}
}
finally
{
if(tabAlignment==eTabStripAlignment.Left)
bmp.RotateFlip(RotateFlipType.Rotate270FlipNone);
else if(tabAlignment==eTabStripAlignment.Right)
bmp.RotateFlip(RotateFlipType.Rotate90FlipNone);
else if(tabAlignment==eTabStripAlignment.Bottom)
bmp.RotateFlip(RotateFlipType.Rotate180FlipNone);
e.Graphics.DrawImageUnscaled(bmp,r.X,r.Y);
m_ThemeCachedBitmap=bmp;
}
}
else
e.Graphics.DrawImageUnscaled(m_ThemeCachedBitmap,r.X,r.Y);
baseCall=false;
}
if(baseCall)
base.OnPaint(e);
if(this.DesignMode && this.Controls.Count==0 && this.Text=="")
{
Rectangle r=this.ClientRectangle;
r.Inflate(-2,-2);
eTextFormat sf = eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter | eTextFormat.EndEllipsis | eTextFormat.WordBreak;
Font font=new Font(this.Font,FontStyle.Bold);
TextDrawing.DrawString(e.Graphics,INFO_TEXT,font,ControlPaint.Dark(this.Style.BackColor1.Color),r,sf);
font.Dispose();
}
}
/// <summary>
/// Called after either ColorScheme or ColorSchemeStyle has changed. If you override make sure that you call base implementation so default
/// processing can occur.
/// </summary>
protected override void OnColorSchemeChanged()
{
base.OnColorSchemeChanged();
if (!UseCustomStyle)
{
if (StyleManager.IsVisualStudio2012(StyleManager.Style))
{
this.Style.BackColor1.ColorSchemePart = eColorSchemePart.PanelBackground;
}
else
{
this.Style.BackColor1.ColorSchemePart = eColorSchemePart.BarBackground;
}
}
}
/// <summary>
/// Indicates whether style of the panel is managed by tab control automatically.
/// Set this to true if you would like to control style of the panel.
/// </summary>
[Browsable(true),DefaultValue(false),Category("Appearance"),Description("Indicates whether style of the panel is managed by tab control automatically. Set this to true if you would like to control style of the panel.")]
public bool UseCustomStyle
{
get {return m_UseCustomStyle;}
set {m_UseCustomStyle=value;}
}
/// <summary>
/// Gets or sets TabItem that this panel is attached to.
/// </summary>
[Browsable(false),DefaultValue(null),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public DockContainerItem DockContainerItem
{
get {return m_DockContainerItem;}
set {m_DockContainerItem=value;}
}
protected override void OnResize(EventArgs e)
{
DisposeThemeCachedBitmap();
base.OnResize(e);
}
/// <summary>
/// Gets or sets which edge of the parent container a control is docked to.
/// </summary>
[Browsable(false),DefaultValue(DockStyle.None),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override DockStyle Dock
{
get {return base.Dock;}
set {base.Dock=value;}
}
/// <summary>
/// Gets or sets the size of the control.
/// </summary>
[Browsable(false)]
public new System.Drawing.Size Size
{
get {return base.Size;}
set {base.Size=value;}
}
/// <summary>
/// Gets or sets the coordinates of the upper-left corner of the control relative to the upper-left corner of its container.
/// </summary>
[Browsable(false)]
public new Point Location
{
get {return base.Location;}
set {base.Location=value;}
}
/// <summary>
/// Gets or sets a value indicating whether the control is displayed.
/// </summary>
[Browsable(false)]
public new bool Visible
{
get {return base.Visible;}
set {base.Visible=value;}
}
/// <summary>
/// Gets or sets which edges of the control are anchored to the edges of its container.
/// </summary>
[Browsable(false)]
public override AnchorStyles Anchor
{
get {return base.Anchor;}
set {base.Anchor=value;}
}
private TabStrip GetDockTabStrip()
{
TabStrip tabStrip=null;
if(m_DockContainerItem!=null && m_DockContainerItem.ContainerControl is Bar)
{
Bar bar=m_DockContainerItem.ContainerControl as Bar;
if(bar.DockSide==eDockSide.Document)
tabStrip=bar.DockTabControl;
}
return tabStrip;
}
protected override void OnEnter(EventArgs e)
{
// Notify DotNetBarManager on activation
DotNetBarManager manager = GetDotNetBarManager();
if (manager != null) manager.InternalDockContainerActivated(m_DockContainerItem);
TabStrip tabStrip=GetDockTabStrip();
if(tabStrip==null)
return;
try
{
if(tabStrip.SelectedTabFont == null)
tabStrip.SelectedTabFont = new Font(tabStrip.Font, FontStyle.Bold);
}
catch{}
if (this.Controls.Count > 0)
{
Form f = this.FindForm();
if (f != null)
{
if (f.ActiveControl == this || f.ActiveControl == tabStrip && tabStrip != null)
this.SelectNextControl(null, true, true, true, true);
}
}
base.OnEnter(e);
}
private DotNetBarManager GetDotNetBarManager()
{
if (m_DockContainerItem != null && m_DockContainerItem.ContainerControl is Bar)
{
return ((Bar)m_DockContainerItem.ContainerControl).Owner as DotNetBarManager;
}
return null;
}
protected override void OnLeave(EventArgs e)
{
// Notify DotNetBarManager on activation
DotNetBarManager manager = GetDotNetBarManager();
if (manager != null) manager.InternalDockContainerDeactivated(m_DockContainerItem);
TabStrip tabStrip=GetDockTabStrip();
if(tabStrip==null)
return;
if(tabStrip.SelectedTabFont != null)
tabStrip.SelectedTabFont = null;
base.OnLeave(e);
}
#endregion
}
}