#region --- License --- /* Copyright (c) 2006, 2007 Stefanos Apostolopoulos * See license.txt for license info */ #endregion using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; namespace OpenTK.Platform.Windows { /// /// Describes a Windows.Form.Control, Windows.Forms.NativeWindow or OpenTK.GameWindow on the Windows platform. /// This class supports OpenTK, and is not intended for use by OpenTK programs. /// internal sealed class WindowInfo : IMutableWindowInfo { private IntPtr handle; private WindowInfo parent; public WindowInfo() { } public WindowInfo(IntPtr handle, IWindowInfo parent) { this.Handle = handle; this.Parent = parent; } public WindowInfo(IWindowInfo info) { if (info == null) throw new ArgumentException("WindowInfo cannot be null."); this.Handle = info.Handle; this.Parent = info.Parent; } public WindowInfo(Control control) { if (control == null) throw new ArgumentException("Control cannot be null."); this.Handle = control.Handle; this.Parent = control.Parent != null ? new WindowInfo(control.Parent) : this.Parent; } public WindowInfo(NativeWindow window) { if (window == null) throw new ArgumentException("NativeWindow cannot be null."); this.Handle = window.Handle; this.Parent = null; } public WindowInfo(GameWindow window) { if (window == null) throw new ArgumentException("GameWindow cannot be null."); this.Handle = window.WindowInfo.Handle; this.Parent = window.WindowInfo.Parent; } #region --- IWindowInfo Members --- public IntPtr Handle { get { return handle; } internal set { handle = value; } } public IWindowInfo Parent { get { return parent; } internal set { parent = value as WindowInfo; } } public IWindowInfo GetInfoFrom(Control control) { if (control == null) throw new ArgumentException("Control cannot be null."); if (control.Parent == null) { return new WindowInfo(control.Handle, null); } return new WindowInfo(control.Handle, GetInfoFrom(control.Parent)); } public IWindowInfo GetInfoFrom(NativeWindow window) { if (window == null) throw new ArgumentException("NativeWindow cannot be null."); return new WindowInfo(window.Handle, null); } public IWindowInfo GetInfoFrom(GameWindow window) { if (window == null) throw new ArgumentException("GameWindow cannot be null."); return GetInfoFrom(window.WindowInfo as Windows.WindowInfo); } public IWindowInfo GetInfoFrom(IWindowInfo info) { if (info == null) throw new ArgumentException("IWindowInfo cannot be null."); return info; } public void CopyInfoFrom(IWindowInfo info) { this.Handle = info.Handle; this.Parent = info.Parent; } #endregion public override string ToString() { return String.Format("Windows.WindowInfo: Handle {0}, Parent ({1})", this.Handle, this.Parent != null ? this.Parent.ToString() : "null"); } } }