using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
using static Vanara.PInvoke.Shell32;
namespace Vanara.Windows.Shell
{
/// Specifies taskbar button thumbnail tab properties.
public enum TaskbarItemTabThumbnailOption
{
/// The tab window provides a thumbnail and peek image, either live or static as appropriate.
TabWindow = 0,
///
/// Always use the thumbnail or peek image provided by the main application frame window rather than a thumbnail or peek image
/// provided by the individual tab window.
///
MainWindow = 1,
///
/// When the application tab is active and a live representation of its window is available, use the main application's frame window
/// as the thumbnail or peek feature. At other times, use the tab window thumbnail or peek feature.
///
MainWindowWhenActive = 2,
}
//[TypeConverter(typeof(TaskbarItemTabConverter))]
//[Serializable]
///
///
public class TaskbarButtonThumbnail : INotifyPropertyChanged //, ISerializable
{
internal STPFLAG flag = 0;
private Control tabWin;
/// Initializes a new instance of the class.
public TaskbarButtonThumbnail()
{
}
/// Initializes a new instance of the class.
/// The tab window.
public TaskbarButtonThumbnail(Control tabWindow) => ChildWindow = tabWindow;
/*private TaskbarItemTab(SerializationInfo info, StreamingContext context)
{
flag = (STPFLAG)info.GetValue(nameof(flag), flag.GetType());
TabWindow = (Control)info.GetValue(nameof(ChildWindow), typeof(Control));
}
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue(nameof(ChildWindow), tabWin, typeof(Control));
info.AddValue(nameof(flag), flag, flag.GetType());
}*/
/// Occurs when a property has changed.
public event PropertyChangedEventHandler PropertyChanged;
/// Gets or sets the child window whose image will be displayed in this thumbnail.
/// The child window.
[DefaultValue(null), Category("Appearance")]
public Control ChildWindow
{
get => tabWin;
set
{
if (ReferenceEquals(tabWin, value ?? throw new ArgumentNullException(nameof(ChildWindow), "Child window must be specified for tab.")))
return;
tabWin = value;
//if (Parent != null)
//{
// var idx = Parent.Thumbnails.IndexOf(this);
// var nextTab = (idx < (Parent.Thumbnails.Count - 1)) ? Parent.Thumbnails[idx + 1] : null;
// Register(nextTab);
//}
OnPropertyChanged();
}
}
/// Gets or sets the peek image provider.
/// The peek image provider.
[DefaultValue(typeof(TaskbarItemTabThumbnailOption), "TabWindow"), Category("Appearance")]
public TaskbarItemTabThumbnailOption PeekImageProvider
{
get => (TaskbarItemTabThumbnailOption)(((int)flag & 0xC) >> 2);
set { flag = (STPFLAG)(((int)flag & 0x3) | ((int)value << 2)); OnPropertyChanged(); }
}
/// Gets or sets the thumbnail provider.
/// The thumbnail provider.
[DefaultValue(typeof(TaskbarItemTabThumbnailOption), "TabWindow"), Category("Appearance")]
public TaskbarItemTabThumbnailOption ThumbnailProvider
{
get => (TaskbarItemTabThumbnailOption)((int)flag & 0x3);
set { flag = (STPFLAG)(((int)flag & 0xC) | (int)value); OnPropertyChanged(); }
}
/// Called when [property changed].
/// Name of the property.
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = "") => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
/*internal class TaskbarItemTabConverter : TypeConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
return destinationType == typeof(InstanceDescriptor) || base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == null)
throw new ArgumentNullException(nameof(destinationType));
if (destinationType == typeof(InstanceDescriptor))
{
TaskbarItemTab tab = (TaskbarItemTab)value;
var ci = typeof(TaskbarItemTab).GetConstructor((tab.ChildWindow == null) ? Type.EmptyTypes : new Type[] { typeof(Control) });
if (ci != null)
return new InstanceDescriptor(ci, (tab.ChildWindow == null) ? null : new object[] { tab.ChildWindow }, false);
}
return base.ConvertTo(context, culture, value, destinationType);
}
}*/
}