protected virtual void OnClick(EventHandler finishDelegate)
{
bool fireDelegate = true;
if (!Ribbon.InDesignMode)
{
if (Enabled)
{
if (AutoCheck)
{
// Find current state
CheckState checkState = CheckState.Unchecked;
if (KryptonCommand != null)
checkState = KryptonCommand.CheckState;
else
checkState = CheckState;
// Find new state based on the current state
switch (checkState)
{
case CheckState.Unchecked:
checkState = CheckState.Checked;
break;
case CheckState.Checked:
checkState = (ThreeState ? CheckState.Indeterminate : CheckState.Unchecked);
break;
case CheckState.Indeterminate:
checkState = CheckState.Unchecked;
break;
}
// Push back the change to the attached command
if (KryptonCommand != null)
KryptonCommand.CheckState = checkState;
else
CheckState = checkState;
}
// In showing a popup we fire the delegate before the click so that the
// minimized popup is removed out of the way before the event is handled
// because if the event shows a dialog then it would appear behind the popup
if (VisualPopupManager.Singleton.CurrentPopup != null)
{
// Do we need to fire a delegate stating the click processing has finished?
if (fireDelegate && (finishDelegate != null))
finishDelegate(this, EventArgs.Empty);
fireDelegate = false;
}
// Generate actual click event
if (Click != null)
Click(this, EventArgs.Empty);
// Clicking the button should execute the associated command
if (KryptonCommand != null)
KryptonCommand.PerformExecute();
}
}
// Do we need to fire a delegate stating the click processing has finished?
if (fireDelegate && (finishDelegate != null))
finishDelegate(this, EventArgs.Empty);
}