2007-08-10 09:27:13 +00:00
|
|
|
|
#region --- License ---
|
|
|
|
|
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
|
|
|
* See license.txt for license info
|
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
using System;
|
2007-08-05 13:42:31 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
2007-09-09 11:52:09 +00:00
|
|
|
|
using System.Windows.Forms;
|
2007-08-05 13:42:31 +00:00
|
|
|
|
|
|
|
|
|
namespace OpenTK.Platform.Windows
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2007-09-09 11:52:09 +00:00
|
|
|
|
/// Describes a Windows.Form.Control, Windows.Forms.NativeWindow or OpenTK.GameWindow on the Windows platform.
|
2007-08-05 13:42:31 +00:00
|
|
|
|
/// This class supports OpenTK, and is not intended for use by OpenTK programs.
|
|
|
|
|
/// </summary>
|
2007-09-21 20:07:30 +00:00
|
|
|
|
public sealed class WindowInfo : IMutableWindowInfo
|
2007-08-05 13:42:31 +00:00
|
|
|
|
{
|
|
|
|
|
private IntPtr handle;
|
|
|
|
|
private WindowInfo parent;
|
|
|
|
|
|
2008-01-23 12:42:27 +00:00
|
|
|
|
#region --- Constructors ---
|
|
|
|
|
|
2007-09-09 11:52:09 +00:00
|
|
|
|
public WindowInfo()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public WindowInfo(IWindowInfo info)
|
|
|
|
|
{
|
2007-09-21 20:07:30 +00:00
|
|
|
|
/*
|
2007-09-09 11:52:09 +00:00
|
|
|
|
if (info == null)
|
|
|
|
|
throw new ArgumentException("WindowInfo cannot be null.");
|
|
|
|
|
|
|
|
|
|
this.Handle = info.Handle;
|
|
|
|
|
this.Parent = info.Parent;
|
2007-09-21 20:07:30 +00:00
|
|
|
|
*/
|
|
|
|
|
this.CopyInfoFrom(info);
|
2007-09-09 11:52:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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.");
|
2007-09-21 20:07:30 +00:00
|
|
|
|
/*
|
2007-09-09 11:52:09 +00:00
|
|
|
|
this.Handle = window.WindowInfo.Handle;
|
|
|
|
|
this.Parent = window.WindowInfo.Parent;
|
2007-09-21 20:07:30 +00:00
|
|
|
|
*/
|
|
|
|
|
this.CopyInfoFrom(window.WindowInfo);
|
2007-09-09 11:52:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-23 12:42:27 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2007-08-05 13:42:31 +00:00
|
|
|
|
#region --- IWindowInfo Members ---
|
|
|
|
|
|
|
|
|
|
public IntPtr Handle
|
|
|
|
|
{
|
|
|
|
|
get { return handle; }
|
|
|
|
|
internal set { handle = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IWindowInfo Parent
|
|
|
|
|
{
|
|
|
|
|
get { return parent; }
|
2007-09-09 11:52:09 +00:00
|
|
|
|
internal set
|
|
|
|
|
{
|
|
|
|
|
parent = value as WindowInfo;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-09 15:10:21 +00:00
|
|
|
|
public IWindowInfo GetInfoFrom(Control control)
|
2007-09-09 11:52:09 +00:00
|
|
|
|
{
|
|
|
|
|
if (control == null)
|
|
|
|
|
throw new ArgumentException("Control cannot be null.");
|
|
|
|
|
|
2007-09-21 20:07:30 +00:00
|
|
|
|
return new WindowInfo(control);
|
2007-09-09 11:52:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-09 15:10:21 +00:00
|
|
|
|
public IWindowInfo GetInfoFrom(NativeWindow window)
|
2007-09-09 11:52:09 +00:00
|
|
|
|
{
|
|
|
|
|
if (window == null)
|
|
|
|
|
throw new ArgumentException("NativeWindow cannot be null.");
|
|
|
|
|
|
2007-09-21 20:07:30 +00:00
|
|
|
|
return new WindowInfo(window);
|
2007-09-09 11:52:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-09 15:10:21 +00:00
|
|
|
|
public IWindowInfo GetInfoFrom(GameWindow window)
|
2007-09-09 11:52:09 +00:00
|
|
|
|
{
|
|
|
|
|
if (window == null)
|
|
|
|
|
throw new ArgumentException("GameWindow cannot be null.");
|
|
|
|
|
|
2007-09-09 15:10:21 +00:00
|
|
|
|
return GetInfoFrom(window.WindowInfo as Windows.WindowInfo);
|
2007-09-09 11:52:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-09 15:10:21 +00:00
|
|
|
|
public IWindowInfo GetInfoFrom(IWindowInfo info)
|
2007-09-09 11:52:09 +00:00
|
|
|
|
{
|
|
|
|
|
if (info == null)
|
|
|
|
|
throw new ArgumentException("IWindowInfo cannot be null.");
|
2007-09-09 15:10:21 +00:00
|
|
|
|
|
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-21 20:07:30 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region --- IMutableWindowInfo Members ---
|
|
|
|
|
|
2007-09-09 15:10:21 +00:00
|
|
|
|
public void CopyInfoFrom(IWindowInfo info)
|
|
|
|
|
{
|
2007-09-09 11:52:09 +00:00
|
|
|
|
this.Handle = info.Handle;
|
2007-09-21 20:07:30 +00:00
|
|
|
|
this.Parent = info.Parent;
|
2007-08-05 13:42:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2007-08-05 16:44:31 +00:00
|
|
|
|
|
2008-01-23 12:42:27 +00:00
|
|
|
|
#region public override string ToString()
|
|
|
|
|
|
2007-08-05 16:44:31 +00:00
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
2007-08-06 11:22:18 +00:00
|
|
|
|
return String.Format("Windows.WindowInfo: Handle {0}, Parent ({1})",
|
2007-08-05 16:54:14 +00:00
|
|
|
|
this.Handle, this.Parent != null ? this.Parent.ToString() : "null");
|
2007-08-05 16:44:31 +00:00
|
|
|
|
}
|
2008-01-23 12:42:27 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
2007-08-05 13:42:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|