using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sys = System.Threading;
using System.Reflection;
using Yaulw.WPF;
using System.Threading;
using System.Windows.Threading;
using Yaulw.Other;
namespace Yaulw.Thread
{
///
///
///
public enum DispatcherThreatType
{
WPF,
// Winforms // ~Not implmented
// Silverlight? // ~Not implemented
}
///
///
///
public class WindowType
{
public Type T;
public Enum Key;
public bool IsSingleton;
public bool IsPerformanceLoaded;
public WindowType(Type t, Enum Key, bool IsSingleton, bool IsPerformanceLoaded)
{
this.T = t;
this.Key = Key;
this.IsSingleton = IsSingleton;
this.IsPerformanceLoaded = IsPerformanceLoaded;
}
}
///
///
///
public class WindowAttributes
{
public IntPtr hWndOwner;
public uint Height;
public uint Width;
public int Top;
public int Left;
public string Title;
public WindowAttributes(IntPtr hWndOwner, uint Height, uint Width, int Top, int Left, string Title)
{
this.hWndOwner = hWndOwner;
this.Height = Height;
this.Width = Width;
this.Top = Top;
this.Left = Left;
this.Title = Title;
}
public WindowAttributes(IntPtr hWndOwner, int Top, int Left)
{
this.hWndOwner = hWndOwner;
this.Height = 0;
this.Width = 0;
this.Top = Top;
this.Left = Left;
this.Title = String.Empty;
}
public WindowAttributes(IntPtr hWndOwner)
{
this.hWndOwner = hWndOwner;
this.Height = 0;
this.Width = 0;
this.Top = int.MinValue;
this.Left = int.MinValue;
this.Title = String.Empty;
}
}
#region Window Manager Definition
///
/// Abstract Base Class all Window Managers must inherit from.
///
///
public abstract class WindowManager : IDisposable
{
#region Private Members
private Dictionary> s_WindowsToManage = new Dictionary>();
#endregion
#region Construction
///
/// Construct a Window Manager Object
///
/// Thread Dispatcher Object
/// Window Types this WindowManager is managing
/// true, to load performance enabled windows upon construction
public WindowManager(Dispatcher dispatcher, WindowType[] windowTypes, bool PerformanceLoad)
{
Dispatcher = dispatcher;
WindowTypes = windowTypes;
if (Dispatcher == null)
throw new ArgumentException("dispatcher can't be null");
if (windowTypes == null || windowTypes.Length < 1)
throw new ArgumentException("windowTypes can't be null or empty");
// Add All Window Types
foreach (WindowType type in windowTypes)
{
// Add the Type to be managed
AddWindowTypeToManage(type);
// perform performance optimization
if (PerformanceLoad && type.IsPerformanceLoaded)
{
object o = CreateInstance(type);
AddObject(type, o);
}
}
}
#endregion
#region Public Properties
///
/// Returns the Dispatcher Thread responsible for this Window Manager
///
public Dispatcher Dispatcher { get; private set; }
///
/// Returns all the Window Types that have been set to be managed by this Window Manager
///
public WindowType[] WindowTypes { get; private set; }
#endregion
#region Protected Common Window Object Operations
///
/// Create a new Object Instance of type
///
/// type of object to create
/// a new object for type, or null
protected object CreateInstance(WindowType window)
{
object o = null;
if (window != null)
o = Activator.CreateInstance(window.T);
return o;
}
///
/// Create a new Object Instance of type
///
/// type of object to create
/// a new object for type, or null
protected object CreateInstance(Enum windowKey)
{
return CreateInstance(GetType(windowKey));
}
///
///
///
///
///
protected List