public void EndResizeOperation(ResizeBar bar, int delta) { // Find position of this ResizeBar in the Controls collection int barIndex = _control.Controls.IndexOf(bar); // Convert from control to children indexing int beforeIndex = (barIndex - 1) / 2; // The Window relating to this bar must be the one before it in the collection TabGroupBase before = _children[beforeIndex]; // Is the Window being expanded DeltaGroupSpace(before, delta); }
public TabGroupLeaf(TabbedGroups tabbedGroups, TabGroupBase parent) : base(tabbedGroups, parent) { // Create our managed tab control instance _tabControl = new Controls.TabControl(); // We need page drag to begin when mouse dragged a small distance _tabControl.DragFromControl = false; // We need to monitor attempts to drag into the tab control _dragEntered = false; _tabControl.AllowDrop = true; _tabControl.DragDrop += new DragEventHandler(OnControlDragDrop); _tabControl.DragEnter += new DragEventHandler(OnControlDragEnter); _tabControl.DragLeave += new EventHandler(OnControlDragLeave); // Need notification when page drag begins _tabControl.PageDragStart += new MouseEventHandler(OnPageDragStart); _tabControl.PageDragMove += new MouseEventHandler(OnPageDragMove); _tabControl.PageDragEnd += new MouseEventHandler(OnPageDragEnd); _tabControl.PageDragQuit += new MouseEventHandler(OnPageDragQuit); // Hook into tab page collection events _tabControl.TabPages.Cleared += new CollectionClear(OnTabPagesCleared); _tabControl.TabPages.Inserted += new CollectionChange(OnTabPagesInserted); _tabControl.TabPages.Removed += new CollectionChange(OnTabPagesRemoved); // Hook into page level events _tabControl.GotFocus += new EventHandler(OnGainedFocus); _tabControl.PageGotFocus += new EventHandler(OnGainedFocus); _tabControl.ClosePressed += new EventHandler(OnClose); // Manager only created at start of drag operation _targetManager = null; DefinePopupMenuForControl(_tabControl); // Setup the correct 'HideTabsMode' for the control Notify(TabGroupBase.NotifyCode.DisplayTabMode); // Define the default setup of TabControl and allow developer to customize _tabbedGroups.OnTabControlCreated(_tabControl); }
protected TabGroupBase Add(TabGroupBase group) { // Remember reference _children.Add(group); // First group added to sequence? if (_children.Count == 1) { // Add new child control _control.Controls.Add(group.GroupControl); } else { // Create a resizing bar ResizeBar bar = new ResizeBar(_direction, this); // Append resize bar between existing entries and new entry _control.Controls.Add(bar); // Append new group control _control.Controls.Add(group.GroupControl); } if (!_tabbedGroups.Initializing) { // Allocate space for the new child AllocateSpace(group); // Update child layout to reflect new proportional spacing values RepositionChildren(); } // Mark layout as dirty if (_tabbedGroups.AutoCalculateDirty) { _tabbedGroups.Dirty = true; } return(group); }
public bool StartResizeOperation(ResizeBar bar, ref Rectangle screenBoundary) { // Find position of this ResizeBar in the Controls collection int barIndex = _control.Controls.IndexOf(bar); // Convert from control to children indexing int beforeIndex = (barIndex - 1) / 2; // Get groups before and after the resize bar TabGroupBase before = _children[beforeIndex]; TabGroupBase after = _children[beforeIndex + 1]; // Resizing boundary is defaulted to whole control area screenBoundary = _control.RectangleToScreen(_control.ClientRectangle); // Find screen rectangle for the groups either side of the bar Rectangle rectBefore = before.GroupControl.RectangleToScreen(before.GroupControl.ClientRectangle); Rectangle rectAfter = after.GroupControl.RectangleToScreen(after.GroupControl.ClientRectangle); // Reduce the boundary in the appropriate direction if (_direction == Common.Direction.Vertical) { screenBoundary.Y = rectBefore.Y + before.MinimumSize.Height; screenBoundary.Height -= screenBoundary.Bottom - rectAfter.Bottom; screenBoundary.Height -= after.MinimumSize.Height; } else { screenBoundary.X = rectBefore.X + before.MinimumSize.Width; screenBoundary.Width -= screenBoundary.Right - rectAfter.Right; screenBoundary.Width -= after.MinimumSize.Width; } // Allow resize operation to occur return(true); }
internal void Replace(TabGroupBase orig, TabGroupBase replace) { // Find array position of old item int origPos = _children.IndexOf(orig); // Transfer across the space occupied replace.RealSpace = orig.RealSpace; // Is this the only Window entry? if (_children.Count == 1) { // Remove Window from appearance // Use helper method to circumvent form Close bug ControlHelper.RemoveAt(_control.Controls, 0); } else { int pos = 0; // Calculate position of Window to remove if (origPos != 0) { pos = origPos * 2 - 1; } // Remove Window and bar // Use helper method to circumvent form Close bug ControlHelper.RemoveAt(_control.Controls, pos); ControlHelper.RemoveAt(_control.Controls, pos); } // Inserting at start of collection? if (origPos == 0) { if (_children.Count > 1) { // Create a resizing bar ResizeBar bar = new ResizeBar(_direction, this); // Append resize bar between existing entries and new entry _control.Controls.Add(bar); // Reposition the bar and group to start of collection _control.Controls.SetChildIndex(bar, 0); } // Append new group control _control.Controls.Add(replace.GroupControl); // Reposition the bar and group to start of collection _control.Controls.SetChildIndex(replace.GroupControl, 0); } else { // Create a resizing bar ResizeBar bar = new ResizeBar(_direction, this); // Append resize bar between existing entries and new entry _control.Controls.Add(bar); // Append new group control _control.Controls.Add(replace.GroupControl); // Find correct index taking into account number of resize bars int pos = origPos * 2 - 1; // Reposition the bar and Window to correct relative ordering _control.Controls.SetChildIndex(bar, pos++); _control.Controls.SetChildIndex(replace.GroupControl, pos); } // Update parentage replace.SetParent(this); // Replace the entry _children[origPos] = replace; // Update child layout to reflect new proportional spacing values RepositionChildren(); // Mark layout as dirty if (_tabbedGroups.AutoCalculateDirty) { _tabbedGroups.Dirty = true; } }
protected void CompactReduceSameDirection(TabbedGroups.CompactFlags flags) { bool changed = false; // Should we check for same direction sub-sequences? if ((flags & 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) { // Create a resizing bar ResizeBar bar = new ResizeBar(_direction, this); _control.Controls.Add(bar); _control.Controls.SetChildIndex(bar, childPos++); } // Add new child control in its place _control.Controls.Add(tgb.GroupControl); _control.Controls.SetChildIndex(tgb.GroupControl, childPos++); // Insert at current position _children.Insert(index, tgb); // Adjust variables to reflect increased size index++; count++; firstInsert = false; } // Assign any remainder to last group _children[index - 1].RealSpace += temp - totalAllocated; // 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 CompactReduceSingleEntries(TabbedGroups.CompactFlags flags) { bool changed = false; // Should we check for single instance nodes? if ((flags & 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(); } }
public TabGroupSequence(TabbedGroups tabbedGroups, TabGroupBase parent, River.Orqa.Controls.Common.Direction direction) : base(tabbedGroups, parent) { InternalConstruct(null, direction); }
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); Common.Direction direction = (rawDirection == "Horizontal" ? Common.Direction.Horizontal : Common.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 TabGroupSequence(TabbedGroups tabbedGroups, TabGroupBase parent) : base(tabbedGroups, parent) { InternalConstruct(null, Common.Direction.Horizontal); }
public int IndexOf(TabGroupBase group) { return(_children.IndexOf(group)); }
public void Remove(TabGroupBase group) { // Convert from reference to index to use existing RemoveAt implementation RemoveAt(_children.IndexOf(group)); }
protected void DeltaGroupSpace(TabGroupBase group, int vector) { Rectangle clientRect = _control.ClientRectangle; // Space available for allocation int space; // New pixel length of the modified group int newLength = vector; if (_direction == Common.Direction.Vertical) { space = clientRect.Height; // New pixel size is requested change plus original // height minus the minimal size that is always added newLength += group.GroupControl.Height; newLength -= group.MinimumSize.Height; } else { space = clientRect.Width; // New pixel size is requested change plus original // width minus the minimal size that is always added newLength += group.GroupControl.Width; newLength -= group.MinimumSize.Width; } int barSpace = 0; // Create temporary array of working values int[] positions = new int[_control.Controls.Count]; // Pass 1, allocate all the space needed for each ResizeBar and the // minimal amount of space that each Window requests. AllocateMandatorySizes(ref positions, ref barSpace, ref space); // What is the new percentage it needs? Decimal newPercent = 0m; // Is there any room to allow a percentage calculation if ((newLength > 0) && (space > 0)) { newPercent = (Decimal)newLength / (Decimal)space * 100m; } // What is the change in area Decimal reallocate = newPercent - group.Space; // Find the group after this one TabGroupBase nextGroup = _children[_children.IndexOf(group) + 1]; if ((nextGroup.Space - reallocate) < 0m) { reallocate = nextGroup.Space; } // Modify the Window in question group.Space += reallocate; // Reverse modify the Window afterwards nextGroup.Space -= reallocate; // Update the visual appearance RepositionChildren(); }
public TabGroupBase(TabbedGroups tabbedGroups, TabGroupBase parent) { InternalConstruct(tabbedGroups, parent); }
internal void SetParent(TabGroupBase tgb) { _parent = tgb; }