// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Windows.Forms;
namespace UnrealControls
{
///
/// Custom renderer for drawing ToolStripItems in Unreal .NET tools.
/// Prevents highlighting of ToolStripItems when the application is not focused.
///
public class UnrealToolStripItemRenderer : ToolStripProfessionalRenderer
{
///
/// Determines if any of the running forms has focus.
///
/// true if one form has focus; false, otherwise
protected bool AppHasFocus()
{
bool bHasFocus = false;
Form ActiveForm = System.Windows.Forms.Form.ActiveForm;
// If the active form is null, then this app doesn't have focus.
if (ActiveForm != null)
{
bHasFocus = ActiveForm.ContainsFocus;
}
return bHasFocus;
}
///
/// Disables menu item highlighting while mousing over
/// a menu item when the app doesn't have focus.
///
/// The event holding the menu item to render.
protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs Args)
{
if ( AppHasFocus() )
{
base.OnRenderMenuItemBackground(Args);
}
}
///
/// Disables tool strip item highlighting while mousing over
/// a tool strip item when the app doesn't have focus.
///
/// The event holding the tool strip item to render.
protected override void OnRenderItemBackground(ToolStripItemRenderEventArgs Args)
{
if ( AppHasFocus() )
{
base.OnRenderItemBackground(Args);
}
}
///
/// Disables button highlighting while mousing over
/// a button when the app doesn't have focus.
///
/// The event holding the button to render.
protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs Args)
{
if ( AppHasFocus() )
{
base.OnRenderButtonBackground(Args);
}
}
///
/// Disables drop down button highlighting while mousing over
/// a drop down button when the app doesn't have focus.
///
/// The event holding the drop down button to render.
protected override void OnRenderDropDownButtonBackground(ToolStripItemRenderEventArgs Args)
{
if ( AppHasFocus() )
{
base.OnRenderDropDownButtonBackground(Args);
}
}
///
/// Disables overflow button highlighting while mousing over
/// a overflow button when the app doesn't have focus.
///
/// The event holding the overflow button to render.
protected override void OnRenderOverflowButtonBackground(ToolStripItemRenderEventArgs Args)
{
if ( AppHasFocus() )
{
base.OnRenderOverflowButtonBackground(Args);
}
}
///
/// Disables split button highlighting while mousing over
/// a split button when the app doesn't have focus.
///
/// The event holding the split button to render.
protected override void OnRenderSplitButtonBackground(ToolStripItemRenderEventArgs Args)
{
if ( AppHasFocus() )
{
base.OnRenderSplitButtonBackground(Args);
}
else
{
ToolStripSplitButton SplitButton = Args.Item as ToolStripSplitButton;
ToolStripArrowRenderEventArgs DrawArrowEvent = new ToolStripArrowRenderEventArgs( Args.Graphics,
SplitButton,
SplitButton.DropDownButtonBounds,
SplitButton.BackColor,
ArrowDirection.Down);
// If we don't do draw the down arrow while the form doesn't have focus, the arrow will
// disappear as the user hovers over the split button while the app is not focused.
base.DrawArrow(DrawArrowEvent);
}
}
}
}