?? tabgroupsequence.cs
字號:
// Check our own leaf nodes first
foreach(TabGroupBase group in _children)
if (group.IsLeaf)
if (group == prominent)
return true;
// Need to check sub-sequences?
if (recurse)
{
// Check our child sequences
foreach(TabGroupBase group in _children)
if (group.IsSequence)
if (group.ContainsProminent(recurse))
return true;
}
// Not found
return false;
}
public override void SaveToXml(XmlTextWriter xmlOut)
{
// Output standard values appropriate for all Sequence instances
xmlOut.WriteStartElement("Sequence");
xmlOut.WriteAttributeString("Count", _children.Count.ToString());
xmlOut.WriteAttributeString("Unique", _unique.ToString());
xmlOut.WriteAttributeString("Space", _space.ToString());
xmlOut.WriteAttributeString("Direction", _direction.ToString());
// Output each sub element
foreach(TabGroupBase tgb in _children)
tgb.SaveToXml(xmlOut);
xmlOut.WriteEndElement();
}
public override void LoadFromXml(XmlTextReader xmlIn)
{
// Grab the expected attributes
string rawCount = xmlIn.GetAttribute(0);
string rawUnique = xmlIn.GetAttribute(1);
string rawSpace = xmlIn.GetAttribute(2);
string rawDirection = xmlIn.GetAttribute(3);
// Convert to correct types
int count = Convert.ToInt32(rawCount);
int unique = Convert.ToInt32(rawUnique);
Decimal space = Convert.ToDecimal(rawSpace);
Direction direction = (rawDirection == "Horizontal" ? Direction.Horizontal :
Direction.Vertical);
// Update myself with new values
_unique = unique;
_space = space;
_direction = direction;
// Load each of the children
for(int i=0; i<count; i++)
{
// Read the next Element
if (!xmlIn.Read())
throw new ArgumentException("An element was expected but could not be read in");
TabGroupBase newElement = null;
// Is it another sequence?
if (xmlIn.Name == "Sequence")
newElement = new TabGroupSequence(_tabbedGroups, this);
else if (xmlIn.Name == "Leaf")
newElement = new TabGroupLeaf(_tabbedGroups, this);
else
throw new ArgumentException("Unknown element was encountered");
bool expectEndElement = !xmlIn.IsEmptyElement;
// Load its config
newElement.LoadFromXml(xmlIn);
// Add new element to the collection
Add(newElement);
// Do we expect and end element to occur?
if (expectEndElement)
{
// Move past the end element
if (!xmlIn.Read())
throw new ArgumentException("Could not read in next expected node");
// Check it has the expected name
if (xmlIn.NodeType != XmlNodeType.EndElement)
throw new ArgumentException("EndElement expected but not found");
}
}
}
public void Compact()
{
Compact(_tabbedGroups.CompactOptions);
}
public void Compact(TabbedGroups.CompactFlags flags)
{
// Compact each child sequence
foreach(TabGroupBase tgb in _children)
if (tgb.IsSequence)
(tgb as TabGroupSequence).Compact(flags);
// Remove dangling entries
CompactRemoveEmptyTabLeafs(flags);
CompactRemoveEmptyTabSequences(flags);
// Integrate single entries
CompactReduceSingleEntries(flags);
// Integrate sub-sequences which run in same direction
CompactReduceSameDirection(flags);
}
public void Reposition()
{
// Update child layout to reflect new proportional spacing values
RepositionChildren();
}
protected void CompactRemoveEmptyTabLeafs(TabbedGroups.CompactFlags flags)
{
// Should we check for empty leaf nodes?
if ((flags & Controls.TabbedGroups.CompactFlags.RemoveEmptyTabLeaf) != 0)
{
int count = _children.Count;
for(int index=0; index<count; index++)
{
// Only interested in leaf entries
if (_children[index].IsLeaf)
{
TabGroupLeaf tgl = (TabGroupLeaf)_children[index];
// Is this an empty leaf node?
if (tgl.Count == 0)
{
// Update active leaf setting
if (_tabbedGroups.ActiveLeaf == tgl)
{
TabGroupLeaf newLeaf = _tabbedGroups.NextLeaf(tgl);
if (newLeaf == null)
newLeaf = _tabbedGroups.PreviousLeaf(tgl);
_tabbedGroups.ActiveLeaf = newLeaf;
}
// Need to remove the redundant entry
RemoveAt(index);
// Reduce number of entries left to check
count--;
// Move backwards so the next increment stays on same index
index--;
// Mark layout as dirty
if (_tabbedGroups.AutoCalculateDirty)
_tabbedGroups.Dirty = true;
}
}
}
}
}
protected void CompactRemoveEmptyTabSequences(TabbedGroups.CompactFlags flags)
{
// Should we check for empty sequence nodes?
if ((flags & Controls.TabbedGroups.CompactFlags.RemoveEmptyTabSequence) != 0)
{
int count = _children.Count;
for(int index=0; index<count; index++)
{
// Only interested in sequence entries
if (_children[index].IsSequence)
{
TabGroupSequence tgs = (TabGroupSequence)_children[index];
// Is this an empty sequence node?
if (tgs.Count == 0)
{
// Need to remove the redundant entry
RemoveAt(index);
// Reduce number of entries left to check
count--;
// Move backwards so the next increment stays on same index
index--;
// Mark layout as dirty
if (_tabbedGroups.AutoCalculateDirty)
_tabbedGroups.Dirty = true;
}
}
}
}
}
protected void CompactReduceSingleEntries(TabbedGroups.CompactFlags flags)
{
bool changed = false;
// Should we check for single instance nodes?
if ((flags & Controls.TabbedGroups.CompactFlags.ReduceSingleEntries) != 0)
{
int count = _children.Count;
for(int index=0; index<count; index++)
{
// Only interested in sequence entries
if (_children[index].IsSequence)
{
TabGroupSequence tgs = (TabGroupSequence)_children[index];
// Does this entry only have a single child
if (tgs.Count == 1)
{
// Remember how much space the base entry occupies
Decimal temp = tgs.RealSpace;
// Get reference to only child
TabGroupBase child = tgs[0];
// Update parentage
child.SetParent(this);
// Find the child control to be replaced
int childPos = _control.Controls.IndexOf(tgs.GroupControl);
// Remove it
ControlHelper.RemoveAt(_control.Controls, childPos);
// Add new child control in its place
_control.Controls.Add(child.GroupControl);
_control.Controls.SetChildIndex(child.GroupControl, childPos);
// Replace the middle object with the child
_children.RemoveAt(index);
_children.Insert(index, child);
// Restore its correct spacing
child.RealSpace = temp;
// Need controls repositioned
changed = true;
// Mark layout as dirty
if (_tabbedGroups.AutoCalculateDirty)
_tabbedGroups.Dirty = true;
}
}
}
}
// Change in contents requires entries to be repositioned
if (changed)
RepositionChildren();
}
protected void CompactReduceSameDirection(TabbedGroups.CompactFlags flags)
{
bool changed = false;
// Should we check for same direction sub-sequences?
if ((flags & Controls.TabbedGroups.CompactFlags.ReduceSameDirection) != 0)
{
int count = _children.Count;
for(int index=0; index<count; index++)
{
// Only interested in sequence entries
if (_children[index].IsSequence)
{
TabGroupSequence tgs = (TabGroupSequence)_children[index];
// Does it run in same direction as ourself?
if (_direction == tgs.Direction)
{
// Remember how much space the base entry occupies
Decimal temp = tgs.RealSpace;
// Find the child control to be replaced
int childPos = _control.Controls.IndexOf(tgs.GroupControl);
// Need to remove a resize bar before the control?
if (childPos > 0)
ControlHelper.RemoveAt(_control.Controls, childPos);
// Remove the actual control
ControlHelper.RemoveAt(_control.Controls, childPos);
// Remove the intermediate group
_children.RemoveAt(index);
// Reflect change in size
count--;
Decimal totalAllocated = 0m;
// Add in each sub group in turn
int subCount = tgs.Count;
bool firstInsert = true;
for(int subIndex=0; subIndex<subCount; subIndex++)
{
TabGroupBase tgb = tgs[subIndex];
// What percentage of original space did it have?
Decimal orig = tgb.RealSpace;
// Give it the same proportion of new space
Decimal update = Decimal.Round(temp / 100 * orig, SPACE_PRECISION);
// Keep total actually allocated
totalAllocated += update;
// Use new proportion
tgb.RealSpace = update;
// Update parentage
tgb.SetParent(this);
// Does new child control need a resizing bar?
if ((childPos > 0) && !firstInsert)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -