Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / Documents / Table.cs / 1305600 / Table.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
//
// Description: Table implementation
//
// See spec at http://avalon/layout/Tables/WPP%20TableOM.doc
//
// History:
// 05/19/2003 : olego - created
//
//---------------------------------------------------------------------------
using MS.Internal;
using MS.Internal.PtsHost;
using MS.Internal.PtsTable;
using MS.Utility;
using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows.Threading;
using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Media;
using System.Windows.Markup;
using MS.Internal.PtsHost.UnsafeNativeMethods;
using MS.Internal.Documents;
#pragma warning disable 1634, 1691 // suppressing PreSharp warnings
namespace System.Windows.Documents
{
///
/// Table implements
///
[ContentProperty("RowGroups")]
public class Table : Block, IAddChild, IAcceptInsertion
{
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
///
/// Static ctor. Initializes property metadata.
///
static Table()
{
MarginProperty.OverrideMetadata(typeof(Table), new FrameworkPropertyMetadata(new Thickness(Double.NaN)));
}
///
/// Table constructor.
///
public Table()
{
PrivateInitialize();
}
#endregion Constructors
//------------------------------------------------------
//
// Public Methods
//
//-----------------------------------------------------
#region Public Methods
///
///
///
void IAddChild.AddChild(object value)
{
if (value == null)
{
throw new ArgumentNullException("value");
}
TableRowGroup rowGroup = value as TableRowGroup;
if (rowGroup != null)
{
RowGroups.Add(rowGroup);
return;
}
throw (new ArgumentException(SR.Get(SRID.UnexpectedParameterType, value.GetType(), typeof(TableRowGroup)), "value"));
}
///
///
///
void IAddChild.AddText(string text)
{
XamlSerializerUtil.ThrowIfNonWhiteSpaceInAddText(text, this);
}
///
/// Initialization of this element is about to begin
///
public override void BeginInit()
{
base.BeginInit();
_initializing = true;
}
///
/// Initialization of this element has completed
///
public override void EndInit()
{
_initializing = false;
OnStructureChanged();
base.EndInit();
}
///
///
///
///
/// children enumerated in the following order:
/// * columns
/// * rowgroups
///
protected internal override IEnumerator LogicalChildren
{
get { return (new TableChildrenCollectionEnumeratorSimple(this)); }
}
#endregion Public Methods
//------------------------------------------------------
//
// Public Properties
//
//------------------------------------------------------
#region Public Properties
///
/// Returns table column collection.
///
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public TableColumnCollection Columns { get { return (_columns); } }
///
/// This method is used by TypeDescriptor to determine if this property should
/// be serialized.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeColumns()
{
return (Columns.Count > 0);
}
///
/// Returns table row group.
///
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public TableRowGroupCollection RowGroups
{
get { return (_rowGroups); }
}
///
/// Cell spacing property.
///
[TypeConverter(typeof(LengthConverter))]
public double CellSpacing
{
get { return (double) GetValue(CellSpacingProperty); }
set { SetValue(CellSpacingProperty, value); }
}
#endregion Public Properties
//-----------------------------------------------------
//
// Protected Methods
//
//------------------------------------------------------
#region Protected Methods
///
/// Creates AutomationPeer ( )
///
protected override AutomationPeer OnCreateAutomationPeer()
{
return new TableAutomationPeer(this);
}
#endregion Protected Methods
//-----------------------------------------------------
//
// Internal Properties
//
//-----------------------------------------------------
#region Internal Properties
///
/// Internal cell spacing getter
///
internal double InternalCellSpacing
{
get { return Math.Max(CellSpacing, 0); }
}
int IAcceptInsertion.InsertionIndex
{
get { return this.InsertionIndex; }
set { this.InsertionIndex = value; }
}
///
/// Stores temporary data for where to insert a new row group
///
internal int InsertionIndex
{
get { return _rowGroupInsertionIndex; }
set { _rowGroupInsertionIndex = value; }
}
///
/// Count of columns in the table
///
internal int ColumnCount
{
get
{
return (_columnCount);
}
}
#endregion Internal Properties
//-----------------------------------------------------
//
// Internal Methods
//
//------------------------------------------------------
#region Internal Methods
///
/// Updates table actual column count
///
/// Count of column to account for
internal void EnsureColumnCount(int columnCount)
{
if (_columnCount < columnCount)
_columnCount = columnCount;
}
///
/// OnStructureChanged - Called to rebuild structure.
///
internal void OnStructureChanged()
{
if (!_initializing)
{
if (TableStructureChanged != null)
{
TableStructureChanged(this, EventArgs.Empty);
}
ValidateStructure();
// Table structure changes affect number of rows and colums. Need to notify peer about it.
TableAutomationPeer peer = ContentElementAutomationPeer.FromElement(this) as TableAutomationPeer;
if (peer != null)
{
peer.OnStructureInvalidated();
}
}
}
///
/// ValidateStructure
///
internal void ValidateStructure()
{
if (!_initializing)
{
//
// validate row groups structural cache
//
_columnCount = 0;
for (int i = 0; i < _rowGroups.Count; ++i)
{
_rowGroups[i].ValidateStructure();
}
_version++;
}
}
///
/// Notifies the text container that some property change has occurred, requiring a revalidation of table.
///
internal void InvalidateColumns()
{
NotifyTypographicPropertyChanged(true /* affectsMeasureOrArrange */, true /* localValueChanged */, null);
}
///
/// Returns true if the given rowGroupIndex is the first non-empty one
///
internal bool IsFirstNonEmptyRowGroup(int rowGroupIndex)
{
rowGroupIndex--;
while(rowGroupIndex >= 0)
{
if(RowGroups[rowGroupIndex].Rows.Count > 0)
{
return false;
}
rowGroupIndex--;
}
return true;
}
///
/// Returns true if the given rowGroupIndex is the last non-empty one
///
internal bool IsLastNonEmptyRowGroup(int rowGroupIndex)
{
rowGroupIndex++;
while(rowGroupIndex < RowGroups.Count)
{
if(RowGroups[rowGroupIndex].Rows.Count > 0)
{
return false;
}
rowGroupIndex++;
}
return true;
}
#endregion Internal Methods
//-----------------------------------------------------
//
// Internal Events
//
//------------------------------------------------------
#region Internal Events
///
/// Fired when the table changes structurally
///
internal event EventHandler TableStructureChanged;
#endregion
//------------------------------------------------------
//
// Private Methods
//
//-----------------------------------------------------
#region Private Methods
///
/// Private ctor time initialization.
///
private void PrivateInitialize()
{
// Acquire new PTS Context.
_columns = new TableColumnCollection(this);
_rowGroups = new TableRowGroupCollection(this);
_rowGroupInsertionIndex = -1;
}
private static bool IsValidCellSpacing(object o)
{
double spacing = (double)o;
double maxSpacing = Math.Min(1000000, PTS.MaxPageSize);
if (Double.IsNaN(spacing))
{
return false;
}
if (spacing < 0 || spacing > maxSpacing)
{
return false;
}
return true;
}
#endregion Private Methods
//------------------------------------------------------
//
// Private Fields
//
//-----------------------------------------------------
#region Private Fields
private TableColumnCollection _columns; // collection of columns
private TableRowGroupCollection _rowGroups; // collection of row groups
private int _rowGroupInsertionIndex; // insertion index used by row group collection
private const double c_defaultCellSpacing = 2; // default value of cell spacing
private int _columnCount;
private int _version = 0;
private bool _initializing; // True if the table is being initialized
#endregion Private Fields
//-----------------------------------------------------
//
// Private Structures / Classes
//
//-----------------------------------------------------
#region Private Structures Classes
///
/// Implementation of a simple enumerator of table's children
///
private class TableChildrenCollectionEnumeratorSimple : IEnumerator, ICloneable
{
internal TableChildrenCollectionEnumeratorSimple(Table table)
{
Debug.Assert(table != null);
_table = table;
_version = _table._version;
_columns = ((IEnumerable)_table._columns).GetEnumerator();
_rowGroups = ((IEnumerable)_table._rowGroups).GetEnumerator();
}
public Object Clone()
{
return (MemberwiseClone());
}
public bool MoveNext()
{
if (_version != _table._version)
{
throw new InvalidOperationException(SR.Get(SRID.EnumeratorVersionChanged));
}
// Strange design, but iterator must spin on contained column iterator
if ((_currentChildType != ChildrenTypes.Columns) && (_currentChildType != ChildrenTypes.RowGroups))
_currentChildType++;
Object currentChild = null;
while (_currentChildType < ChildrenTypes.AfterLast)
{
switch (_currentChildType)
{
case (ChildrenTypes.Columns):
if (_columns.MoveNext())
{
currentChild = _columns.Current;
}
break;
case (ChildrenTypes.RowGroups):
if (_rowGroups.MoveNext())
{
currentChild = _rowGroups.Current;
}
break;
}
if (currentChild != null)
{
_currentChild = currentChild;
break;
}
_currentChildType++;
}
Debug.Assert(_currentChildType != ChildrenTypes.BeforeFirst);
return (_currentChildType != ChildrenTypes.AfterLast);
}
public Object Current
{
get
{
if (_currentChildType == ChildrenTypes.BeforeFirst)
{
#pragma warning suppress 6503 // IEnumerator.Current is documented to throw this exception
throw new InvalidOperationException(SR.Get(SRID.EnumeratorNotStarted));
}
if (_currentChildType == ChildrenTypes.AfterLast)
{
#pragma warning suppress 6503 // IEnumerator.Current is documented to throw this exception
throw new InvalidOperationException(SR.Get(SRID.EnumeratorReachedEnd));
}
return (_currentChild);
}
}
public void Reset()
{
if (_version != _table._version)
{
throw new InvalidOperationException(SR.Get(SRID.EnumeratorVersionChanged));
}
_columns.Reset();
_rowGroups.Reset();
_currentChildType = ChildrenTypes.BeforeFirst;
_currentChild = null;
}
private Table _table;
private int _version;
private IEnumerator _columns;
private IEnumerator _rowGroups;
private ChildrenTypes _currentChildType;
private Object _currentChild;
private enum ChildrenTypes : int
{
BeforeFirst = 0,
Columns = 1,
RowGroups = 2,
AfterLast = 3,
}
}
#endregion Private Structures Classes
//------------------------------------------------------
//
// Properties
//
//-----------------------------------------------------
#region Properties
///
/// Cell spacing property.
///
public static readonly DependencyProperty CellSpacingProperty =
DependencyProperty.Register(
"CellSpacing",
typeof(double),
typeof(Table),
new FrameworkPropertyMetadata(
c_defaultCellSpacing,
FrameworkPropertyMetadataOptions.AffectsMeasure),
new ValidateValueCallback(IsValidCellSpacing));
#endregion Properties
//------------------------------------------------------
//
// Debug / Performance
//
//------------------------------------------------------
#if TABLEPARANOIA
internal int ParanoiaVersion = 0;
#endif // TABLEPARANOIA
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- AnonymousIdentificationSection.cs
- CodeCatchClauseCollection.cs
- HttpDebugHandler.cs
- DataGridViewCellMouseEventArgs.cs
- EntityKey.cs
- ThemeConfigurationDialog.cs
- Span.cs
- OrderPreservingSpoolingTask.cs
- CodeDomDesignerLoader.cs
- XmlDataSourceNodeDescriptor.cs
- ScriptDescriptor.cs
- SqlMethodTransformer.cs
- Point.cs
- ActivityDesignerLayoutSerializers.cs
- ThicknessAnimationBase.cs
- ThreadPool.cs
- KeyedPriorityQueue.cs
- DBDataPermission.cs
- DynamicMethod.cs
- Queue.cs
- Convert.cs
- ClientScriptManager.cs
- WebPartDisplayMode.cs
- IndexedString.cs
- SmiEventSink_Default.cs
- ServiceOperationParameter.cs
- CodeCatchClauseCollection.cs
- BasicViewGenerator.cs
- VarInfo.cs
- RecordsAffectedEventArgs.cs
- SapiRecognizer.cs
- PrivilegedConfigurationManager.cs
- ProcessModelSection.cs
- FixUp.cs
- DesignerRegionMouseEventArgs.cs
- ZipIOCentralDirectoryDigitalSignature.cs
- UiaCoreApi.cs
- MediaContextNotificationWindow.cs
- UpdateException.cs
- __TransparentProxy.cs
- ToggleButtonAutomationPeer.cs
- Operators.cs
- safemediahandle.cs
- CheckBoxField.cs
- SystemDiagnosticsSection.cs
- SetterBase.cs
- DependencyPropertyKind.cs
- HasCopySemanticsAttribute.cs
- StringAttributeCollection.cs
- BasicExpandProvider.cs
- PeerFlooder.cs
- SiteMapHierarchicalDataSourceView.cs
- DiscreteKeyFrames.cs
- ControlBuilderAttribute.cs
- XmlEntity.cs
- WebPartCollection.cs
- MenuCommandsChangedEventArgs.cs
- MailWebEventProvider.cs
- CacheHelper.cs
- dbenumerator.cs
- JsonSerializer.cs
- XmlDictionaryReaderQuotasElement.cs
- MimeTypeMapper.cs
- SafeCryptoHandles.cs
- Crc32.cs
- GuidelineCollection.cs
- invalidudtexception.cs
- ApplicationDirectoryMembershipCondition.cs
- LinqMaximalSubtreeNominator.cs
- FactorySettingsElement.cs
- HebrewCalendar.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- AndCondition.cs
- ADMembershipUser.cs
- Hash.cs
- NameTable.cs
- ProfilePropertySettings.cs
- TextElement.cs
- AttributeUsageAttribute.cs
- C14NUtil.cs
- SqlTypeSystemProvider.cs
- sqlcontext.cs
- BamlVersionHeader.cs
- ProcessModuleDesigner.cs
- CommandID.cs
- PlatformCulture.cs
- SqlHelper.cs
- XmlLanguageConverter.cs
- ClientScriptManager.cs
- EnumerableCollectionView.cs
- WindowsIPAddress.cs
- SerializationAttributes.cs
- MouseActionValueSerializer.cs
- MobileControlsSectionHandler.cs
- DbConnectionPoolGroupProviderInfo.cs
- OpenTypeLayoutCache.cs
- DefaultEventAttribute.cs
- ConditionalAttribute.cs
- PlaceHolder.cs
- ImmutableCollection.cs