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