private void UpdateParent(Control parentControl)
{
// Is there a change in the custom control or a change in
// the parent control that is hosting the control...
if ((parentControl != LastParentControl) ||
(LastCustomControl != _ribbonCustomControl.CustomControl))
{
// We only modify the parent and visible state if processing for correct container
if ((_ribbonCustomControl.RibbonContainer.RibbonGroup.ShowingAsPopup && (parentControl is VisualPopupGroup)) ||
(!_ribbonCustomControl.RibbonContainer.RibbonGroup.ShowingAsPopup && !(parentControl is VisualPopupGroup)))
{
// If we have added the custrom control to a parent before
if ((LastCustomControl != null) && (LastParentControl != null))
{
// If that control is still a child of the old parent
if (LastParentControl.Controls.Contains(LastCustomControl))
{
// Check for a collection that is based on the read only class
LastParentControl.Controls.Remove(LastCustomControl);
}
}
// Remember the current control and new parent
LastCustomControl = _ribbonCustomControl.CustomControl;
LastParentControl = parentControl;
// If we have a new custom control and parent
if ((LastCustomControl != null) && (LastParentControl != null))
{
// Ensure the control is not in the display area when first added
LastCustomControl.Location = new Point(-LastCustomControl.Width, -LastCustomControl.Height);
// Check for the correct visible/enabled state of the custom control
UpdateVisible(LastCustomControl);
UpdateEnabled(LastCustomControl);
// Check for a collection that is based on the read only class
LastParentControl.Controls.Add(LastCustomControl);
}
}
}
}