diff --git a/Source/OpenTK/Platform/IMutableWindowInfo.cs b/Source/OpenTK/Platform/IMutableWindowInfo.cs index 8bf3b14a..a882a860 100644 --- a/Source/OpenTK/Platform/IMutableWindowInfo.cs +++ b/Source/OpenTK/Platform/IMutableWindowInfo.cs @@ -15,10 +15,6 @@ namespace OpenTK.Platform /// public interface IMutableWindowInfo : IWindowInfo { - IWindowInfo GetInfoFrom(System.Windows.Forms.Control control); - IWindowInfo GetInfoFrom(System.Windows.Forms.NativeWindow window); - IWindowInfo GetInfoFrom(OpenTK.GameWindow window); - IWindowInfo GetInfoFrom(IWindowInfo info); void CopyInfoFrom(IWindowInfo info); } } diff --git a/Source/OpenTK/Platform/IWindowInfo.cs b/Source/OpenTK/Platform/IWindowInfo.cs index b868b817..f54f0c99 100644 --- a/Source/OpenTK/Platform/IWindowInfo.cs +++ b/Source/OpenTK/Platform/IWindowInfo.cs @@ -18,5 +18,9 @@ namespace OpenTK.Platform { IntPtr Handle { get; } IWindowInfo Parent { get; } + IWindowInfo GetInfoFrom(System.Windows.Forms.Control control); + IWindowInfo GetInfoFrom(System.Windows.Forms.NativeWindow window); + IWindowInfo GetInfoFrom(OpenTK.GameWindow window); + IWindowInfo GetInfoFrom(IWindowInfo info); } } diff --git a/Source/OpenTK/Platform/WindowInfo.cs b/Source/OpenTK/Platform/WindowInfo.cs index dda6a25e..f6bcab45 100644 --- a/Source/OpenTK/Platform/WindowInfo.cs +++ b/Source/OpenTK/Platform/WindowInfo.cs @@ -60,7 +60,7 @@ namespace OpenTK.Platform /// The System.Windows.Forms.NativeWindow to get info from. public WindowInfo(NativeWindow window) : this() { - implementation.GetInfoFrom(window); + implementation.CopyInfoFrom(implementation.GetInfoFrom(window)); } /// @@ -69,7 +69,7 @@ namespace OpenTK.Platform /// The OpenTK.GameWindow to get info from. public WindowInfo(GameWindow window) : this() { - implementation.GetInfoFrom(window); + implementation.CopyInfoFrom(implementation.GetInfoFrom(window)); } #endregion @@ -92,10 +92,6 @@ namespace OpenTK.Platform get { return implementation.Parent; } } - #endregion - - #region --- IMutableWindowInfo Members --- - /// /// Updates the WindowInfo to describe the specified Control. /// @@ -132,11 +128,25 @@ namespace OpenTK.Platform return implementation.GetInfoFrom(info); } + #endregion + + #region --- IMutableWindowInfo Members --- + public void CopyInfoFrom(IWindowInfo info) { implementation.CopyInfoFrom(info); } + public static implicit operator Windows.WindowInfo (WindowInfo info) + { + return (Windows.WindowInfo)info.implementation; + } + + public static implicit operator X11.WindowInfo (WindowInfo info) + { + return (X11.WindowInfo)info.implementation; + } + #endregion } } diff --git a/Source/OpenTK/Platform/Windows/WindowInfo.cs b/Source/OpenTK/Platform/Windows/WindowInfo.cs index c8e5ba47..0115615a 100644 --- a/Source/OpenTK/Platform/Windows/WindowInfo.cs +++ b/Source/OpenTK/Platform/Windows/WindowInfo.cs @@ -15,7 +15,7 @@ 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 + public sealed class WindowInfo : IMutableWindowInfo { private IntPtr handle; private WindowInfo parent; @@ -24,19 +24,16 @@ namespace OpenTK.Platform.Windows { } - 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; + */ + this.CopyInfoFrom(info); } public WindowInfo(Control control) @@ -61,9 +58,11 @@ namespace OpenTK.Platform.Windows { if (window == null) throw new ArgumentException("GameWindow cannot be null."); - + /* this.Handle = window.WindowInfo.Handle; this.Parent = window.WindowInfo.Parent; + */ + this.CopyInfoFrom(window.WindowInfo); } #region --- IWindowInfo Members --- @@ -88,12 +87,7 @@ namespace OpenTK.Platform.Windows 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)); + return new WindowInfo(control); } public IWindowInfo GetInfoFrom(NativeWindow window) @@ -101,7 +95,7 @@ namespace OpenTK.Platform.Windows if (window == null) throw new ArgumentException("NativeWindow cannot be null."); - return new WindowInfo(window.Handle, null); + return new WindowInfo(window); } public IWindowInfo GetInfoFrom(GameWindow window) @@ -120,10 +114,14 @@ namespace OpenTK.Platform.Windows return info; } + #endregion + + #region --- IMutableWindowInfo Members --- + public void CopyInfoFrom(IWindowInfo info) { this.Handle = info.Handle; - this.Parent = info.Parent; + this.Parent = info.Parent; } #endregion diff --git a/Source/OpenTK/Platform/X11/WindowInfo.cs b/Source/OpenTK/Platform/X11/WindowInfo.cs index 5e77d808..4e564f48 100644 --- a/Source/OpenTK/Platform/X11/WindowInfo.cs +++ b/Source/OpenTK/Platform/X11/WindowInfo.cs @@ -15,36 +15,53 @@ namespace OpenTK.Platform.X11 /// Describes a Windows.Form.Control, Windows.Forms.NativeWindow or OpenTK.GameWindow on the X11 platform. /// This class supports OpenTK, and is not intended for use by OpenTK programs. /// - internal sealed class WindowInfo : IMutableWindowInfo + public sealed class WindowInfo : IMutableWindowInfo { - private IntPtr rootWindow, handle, topLevelWindow, display; + private IntPtr handle, topLevelWindow; + private IntPtr rootWindow, display; private int screen; private WindowInfo parent; private XVisualInfo visinfo; + private static Type xplatui; public WindowInfo() { - visinfo = new XVisualInfo(); + //visinfo = new XVisualInfo(); + } + + public WindowInfo(IWindowInfo info) + { + this.CopyInfoFrom(info); } public WindowInfo(Control control) { - throw new NotImplementedException(); + if (control == null) + throw new ArgumentException("Control cannot be null."); + + this.CopyInfoFromXPlatUI(); + this.Handle = control.Handle; + this.Parent = control.Parent != null ? new WindowInfo(control.Parent) : this.Parent; + this.TopLevelWindow = control.TopLevelControl != null ? control.TopLevelControl.Handle : IntPtr.Zero; } public WindowInfo(NativeWindow window) { - throw new NotImplementedException(); + if (window == null) + throw new ArgumentException("NativeWindow cannot be null."); + + this.CopyInfoFromXPlatUI(); + this.Handle = window.Handle; + this.Parent = null; + this.TopLevelWindow = IntPtr.Zero; } public WindowInfo(GameWindow window) { - throw new NotImplementedException(); - } + if (window == null) + throw new ArgumentException("GameWindow cannot be null."); - public WindowInfo(WindowInfo info) - { - this.GetInfoFrom(info); + this.CopyInfoFrom(window.WindowInfo); } #region --- IWindowInfo Members --- @@ -52,24 +69,20 @@ namespace OpenTK.Platform.X11 public IntPtr Handle { get { return handle; } internal set { handle = value; } } public IWindowInfo Parent { get { return parent; } internal set { parent = value as WindowInfo; } } - #endregion - - #region --- IMutableWindowInfo Members --- - public IWindowInfo GetInfoFrom(Control control) { if (control == null) - throw new ArgumentException("GameWindow cannot be null."); - - throw new NotImplementedException(); + throw new ArgumentException("Control cannot be null."); + + return new WindowInfo(control); } public IWindowInfo GetInfoFrom(NativeWindow window) { if (window == null) - throw new ArgumentException("GameWindow cannot be null."); + throw new ArgumentException("NativeWindow cannot be null."); - throw new NotImplementedException(); + return new WindowInfo(window); } public IWindowInfo GetInfoFrom(GameWindow window) @@ -88,6 +101,10 @@ namespace OpenTK.Platform.X11 return info; } + #endregion + + #region --- IMutableWindowInfo Members --- + public void CopyInfoFrom(IWindowInfo info) { this.Handle = info.Handle; @@ -115,5 +132,19 @@ namespace OpenTK.Platform.X11 return String.Format("X11.WindowInfo: Display {0}, Screen {1}, Handle {2}, Parent: ({3})", this.Display, this.Screen, this.Handle, this.Parent != null ? this.Parent.ToString() : "null"); } + + private void CopyInfoFromXPlatUI() + { + xplatui = Type.GetType("System.Windows.Forms.XplatUIX11, System.Windows.Forms"); + if (xplatui == null) + throw new ApplicationException("Could not get System.Windows.Forms.XplatUIX11 through reflection. Unsupported platform or Mono runtime version, aborting."); + + this.Display = (IntPtr)xplatui.GetField("DisplayHandle", + System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).GetValue(null); + this.RootWindow = (IntPtr)xplatui.GetField("RootWindow", + System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).GetValue(null); + this.Screen = (int)xplatui.GetField("ScreenNo", + System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).GetValue(null); + } } }