using System;
using System.Drawing;
using TaskbarLib.Interop;
namespace TaskbarLib.DesktopIntegration
{
///
/// Represents a taskbar thumbnail button in the thumbnail toolbar.
///
public sealed class ThumbButton
{
private ThumbButtonManager _manager;
internal ThumbButton(ThumbButtonManager manager, uint id, Icon icon, string tooltip)
{
_manager = manager;
Id = id;
Icon = icon;
Tooltip = tooltip;
}
///
/// The event that occurs when the taskbar thumbnail button
/// is clicked.
///
public event EventHandler Clicked;
///
/// Gets or sets thumbnail button's id.
///
public uint Id { get; set; }
///
/// Gets or sets the thumbnail button's icon.
///
public Icon Icon { get; set; }
///
/// Gets or sets the thumbnail button's tooltip.
///
public string Tooltip { get; set; }
internal ThumbnailButtonFlags Flags { get; set; }
internal THUMBBUTTON Win32ThumbButton
{
get
{
THUMBBUTTON win32ThumbButton = new THUMBBUTTON();
win32ThumbButton.iId = Id;
win32ThumbButton.szTip = Tooltip;
win32ThumbButton.hIcon = Icon.Handle;
win32ThumbButton.dwFlags = Flags;
win32ThumbButton.dwMask = ThumbnailButtonMask.Flags;
if (Tooltip != null)
win32ThumbButton.dwMask |= ThumbnailButtonMask.Tooltip;
if (Icon != null)
win32ThumbButton.dwMask |= ThumbnailButtonMask.Icon;
return win32ThumbButton;
}
}
///
/// Gets or sets the thumbnail button's visibility.
///
public bool Visible
{
get
{
return (this.Flags & ThumbnailButtonFlags.HIDDEN) == 0;
}
set
{
if (value)
{
this.Flags &= ~(ThumbnailButtonFlags.HIDDEN);
}
else
{
this.Flags |= ThumbnailButtonFlags.HIDDEN;
}
_manager.RefreshThumbButtons();
}
}
///
/// Gets or sets the thumbnail button's enabled state.
///
public bool Enabled
{
get
{
return (this.Flags & ThumbnailButtonFlags.DISABLED) == 0;
}
set
{
if (value)
{
this.Flags &= ~(ThumbnailButtonFlags.DISABLED);
}
else
{
this.Flags |= ThumbnailButtonFlags.DISABLED;
}
_manager.RefreshThumbButtons();
}
}
internal void FireClick()
{
if (Clicked != null)
Clicked(this, EventArgs.Empty);
}
}
}