/*
* Process Hacker -
* ProcessHacker Taskbar Extensions
*
* Copyright (C) 2009 dmex
*
* This file is part of Process Hacker.
*
* Process Hacker is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Process Hacker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Process Hacker. If not, see .
*
*/
using System;
using System.Drawing;
using TaskbarLib.Interop;
namespace TaskbarLib
{
///
/// Represents a taskbar thumbnail button in the thumbnail toolbar.
///
public sealed class ThumbButton
{
private ThumbButtonManager _manager;
internal ThumbButton(ThumbButtonManager manager, int 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 Click;
///
/// Gets or sets thumbnail button's id.
///
public int 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 | ThumbnailButtonFlags.DISMISSONCLICK;
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();
}
}
public bool NoIconBackground
{
get
{
return (this.Flags & ThumbnailButtonFlags.NOBACKGROUND) == 0;
}
set
{
if (value)
{
this.Flags &= ~(ThumbnailButtonFlags.NOBACKGROUND);
}
else
{
this.Flags |= ThumbnailButtonFlags.NOBACKGROUND;
}
_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 OnClick()
{
if (Click != null)
Click(this, EventArgs.Empty);
}
}
}