private void OnFormChromeCheck(object sender, EventArgs e)
{
bool needLayout = false;
bool integrated = false;
// Are we inside a KryptonForm instance that is using custom chrome?
if ((_kryptonForm != null) && _kryptonForm.ApplyCustomChrome)
{
// Ribbon must be placed at the top left of the forms client area
if (_ribbon.Location == Point.Empty)
{
// Find the height of the top caption area for the form
int height = _kryptonForm.RealWindowBorders.Top;
// Must be at least the minimum for the application button and spacing gap above it
if (height >= MIN_INTEGRATED_HEIGHT)
integrated = true;
// Update width of the separator used in place of the app button when app button not visible
_spaceInsteadOfAppButton.SeparatorSize = new Size(_kryptonForm.RealWindowBorders.Left, 0);
}
}
if (_kryptonForm != null)
{
bool overrideIntegrated = integrated;
// If told to prevent the integration, then prevent it now
if (PreventIntegration && overrideIntegrated)
overrideIntegrated = false;
// Is there a change in integrated requirements?
if (overrideIntegrated != _integrated)
{
// Do we need to inject our application button into the caption?
if (!_integrated)
{
_captionAppButton.OwnerForm = _kryptonForm;
_captionQAT.OwnerForm = _kryptonForm;
_kryptonForm.InjectViewElement(_captionQAT, ViewDockStyle.Left);
_kryptonForm.InjectViewElement(_spaceInsteadOfAppButton, ViewDockStyle.Left);
_kryptonForm.InjectViewElement(_captionAppButton, ViewDockStyle.Left);
// Only inject if not already present
if (!_compoRightInjected)
{
_kryptonForm.InjectViewElement(_compRightBorder, ViewDockStyle.Right);
_compoRightInjected = true;
}
_kryptonForm.InjectViewElement(_contextTiles, ViewDockStyle.Fill);
}
else
{
_captionAppButton.OwnerForm = null;
_captionQAT.OwnerForm = null;
_kryptonForm.RevokeViewElement(_contextTiles, ViewDockStyle.Fill);
// At runtime under vista we do not remove the compo right border
if (_ribbon.InDesignMode ||
(Environment.OSVersion.Version.Major < 6) ||
!DWM.IsCompositionEnabled)
{
_kryptonForm.RevokeViewElement(_compRightBorder, ViewDockStyle.Right);
_compoRightInjected = true;
}
_kryptonForm.RevokeViewElement(_captionAppButton, ViewDockStyle.Left);
_kryptonForm.RevokeViewElement(_spaceInsteadOfAppButton, ViewDockStyle.Left);
_kryptonForm.RevokeViewElement(_captionQAT, ViewDockStyle.Left);
}
_integrated = overrideIntegrated;
UpdateVisible();
needLayout = true;
}
_kryptonForm.AllowComposition = _ribbon.AllowFormIntegrate && !_ribbon.InDesignMode;
bool newAllowIconDisplay = (!_integrated || !_ribbon.RibbonAppButton.AppButtonVisible);
if (_kryptonForm.AllowIconDisplay != newAllowIconDisplay)
{
_kryptonForm.AllowIconDisplay = newAllowIconDisplay;
needLayout = true;
}
}
// If not integrated
if (!_integrated)
{
// Get the font we used to draw the context tab text
Font ribbonFont = _ribbon.StateCommon.RibbonGeneral.GetRibbonTextFont(PaletteState.Normal);
// Can we use the cached font height?
if (ribbonFont != _cacheRibbonFont)
{
_cacheRibbonFont = ribbonFont;
_cacheRibbonFontHeight = ribbonFont.Height;
}
// Calculate the desired height of our own area
int calculatedHeight = Math.Max(_cacheRibbonFontHeight + CAPTION_TEXT_GAPS, MIN_SELF_HEIGHT);
// If a change in desired height then request layout to effect change
if (_calculatedHeight != calculatedHeight)
{
_calculatedHeight = calculatedHeight;
needLayout = true;
}
}
if (needLayout)
{
PerformNeedPaint(true);
if (_kryptonForm != null)
{
_kryptonForm.RecreateMinMaxCloseButtons();
_kryptonForm.PerformNeedPaint(true);
}
}
}