Applied kvark's latest NativeWindow/GameWindow patch, which improves event handling, the shutdown sequence and documentation, while removing stale code.

This commit is contained in:
the_fiddler 2009-09-04 21:27:05 +00:00
parent 6b03992812
commit c730a706a6
2 changed files with 218 additions and 281 deletions

View file

@ -79,11 +79,8 @@ namespace OpenTK
IGraphicsContext glContext; IGraphicsContext glContext;
bool hasMainLoop;
bool isExiting = false; bool isExiting = false;
int main_loop_thread_id;
double update_period, render_period; double update_period, render_period;
double target_update_period, target_render_period; double target_update_period, target_render_period;
// TODO: Implement these: // TODO: Implement these:
@ -213,7 +210,6 @@ namespace OpenTK
VSync = VSyncMode.On; VSync = VSyncMode.On;
//glWindow.WindowInfoChanged += delegate(object sender, EventArgs e) { OnWindowInfoChangedInternal(e); }; //glWindow.WindowInfoChanged += delegate(object sender, EventArgs e) { OnWindowInfoChangedInternal(e); };
EnableEvents();
} }
catch (Exception e) catch (Exception e)
{ {
@ -236,7 +232,7 @@ namespace OpenTK
/// <summary> /// <summary>
/// Disposes of the GameWindow, releasing all resources consumed by it. /// Disposes of the GameWindow, releasing all resources consumed by it.
/// </summary> /// </summary>
public new void Dispose() public override void Dispose()
{ {
try try
{ {
@ -244,14 +240,16 @@ namespace OpenTK
} }
finally finally
{ {
if (!IsDisposed()) try
{ {
if (glContext != null) if (glContext != null)
{ {
glContext.Dispose(); glContext.Dispose();
glContext = null; glContext = null;
} }
}
finally
{
base.Dispose(); base.Dispose();
} }
} }
@ -271,6 +269,7 @@ namespace OpenTK
/// </remarks> /// </remarks>
public virtual void Exit() public virtual void Exit()
{ {
isExiting = true;
Close(); Close();
} }
@ -292,13 +291,12 @@ namespace OpenTK
#region OnLoad #region OnLoad
/// <summary> /// <summary>
/// Occurs after establishing an OpenGL context, but before entering the main loop. /// Called after an OpenGL context has been established, but before entering the main loop.
/// Override to load resources that should be maintained for the lifetime of the application.
/// </summary> /// </summary>
/// <param name="e">Not used.</param> /// <param name="e">Not used.</param>
public virtual void OnLoad(EventArgs e) public virtual void OnLoad(EventArgs e)
{ {
EnsureUndisposed(); //if (disposed) throw new ObjectDisposedException("GameWindow"); // What is the exact purpose? if (Load != null) Load(this, e);
} }
#endregion #endregion
@ -306,13 +304,12 @@ namespace OpenTK
#region OnUnload #region OnUnload
/// <summary> /// <summary>
/// Occurs after after calling GameWindow.Exit, but before destroying the OpenGL context. /// Called after GameWindow.Exit was called, but before destroying the OpenGL context.
/// Override to unload application resources.
/// </summary> /// </summary>
/// <param name="e">Not used.</param> /// <param name="e">Not used.</param>
public virtual void OnUnload(EventArgs e) public virtual void OnUnload(EventArgs e)
{ {
EnsureUndisposed(); //if (disposed) throw new ObjectDisposedException("GameWindow"); // What is the exact purpose? if (Unload != null) Unload(this, e);
} }
#endregion #endregion
@ -363,10 +360,6 @@ namespace OpenTK
try try
{ {
// Necessary to be here, otherwise Exit() wouldn't work correctly when called inside OnLoad().
hasMainLoop = true;
main_loop_thread_id = Thread.CurrentThread.ManagedThreadId;
if (updates_per_second < 0.0 || updates_per_second > 200.0) if (updates_per_second < 0.0 || updates_per_second > 200.0)
throw new ArgumentOutOfRangeException("updates_per_second", updates_per_second, throw new ArgumentOutOfRangeException("updates_per_second", updates_per_second,
"Parameter should be inside the range [0.0, 200.0]"); "Parameter should be inside the range [0.0, 200.0]");
@ -389,7 +382,7 @@ namespace OpenTK
OnLoadInternal(EventArgs.Empty); OnLoadInternal(EventArgs.Empty);
Debug.Print("Entering main loop."); Debug.Print("Entering main loop.");
while (!IsExiting && Exists && HasMainLoop) while (!IsExiting && Exists)
{ {
ProcessEvents(); ProcessEvents();
@ -897,26 +890,32 @@ namespace OpenTK
#region OnRenderFrame #region OnRenderFrame
/// <summary> /// <summary>
/// Override in derived classes to render a frame. /// Called when the frame is rendered.
/// </summary> /// </summary>
/// <param name="e">Contains information necessary for frame rendering.</param> /// <param name="e">Contains information necessary for frame rendering.</param>
/// <remarks> /// <remarks>
/// The base implementation (base.OnRenderFrame) is empty, there is no need to call it. /// Subscribe to the <see cref="RenderFrame"/> event instead of overriding this method.
/// </remarks> /// </remarks>
protected virtual void OnRenderFrame(FrameEventArgs e) { } protected virtual void OnRenderFrame(FrameEventArgs e)
{
if (RenderFrame != null) RenderFrame(this, e);
}
#endregion #endregion
#region OnUpdateFrame #region OnUpdateFrame
/// <summary> /// <summary>
/// Override in derived classes to update a frame. /// Called when the frame is updated.
/// </summary> /// </summary>
/// <param name="e">Contains information necessary for frame updating.</param> /// <param name="e">Contains information necessary for frame updating.</param>
/// <remarks> /// <remarks>
/// The base implementation (base.OnUpdateFrame) is empty, there is no need to call it. /// Subscribe to the <see cref="UpdateFrame"/> event instead of overriding this method.
/// </remarks> /// </remarks>
protected virtual void OnUpdateFrame(FrameEventArgs e) { } protected virtual void OnUpdateFrame(FrameEventArgs e)
{
if (UpdateFrame != null) UpdateFrame(this, e);
}
#endregion #endregion
@ -932,57 +931,13 @@ namespace OpenTK
#endregion #endregion
#region --- Assembly Members ---
#region Methods
#region ExitAsync
// Gracefully exits the GameWindow. May be called from any thread.
void ExitAsync()
{
HasMainLoop = false;
isExiting = true;
//UpdateFrame += delegate
//{
// ExitInternal();
//};
}
#endregion
#endregion
#region Properties
#region HasMainLoop
bool HasMainLoop
{
get { return hasMainLoop; }
set { hasMainLoop = value; }
}
#endregion
#endregion
#endregion
#region --- Private Members --- #region --- Private Members ---
#region OnLoadInternal #region OnLoadInternal
/// <summary>
/// Raises the Load event, and calls the user's OnLoad override.
/// </summary>
/// <param name="e">The event data.</param>
private void OnLoadInternal(EventArgs e) private void OnLoadInternal(EventArgs e)
{ {
OnResize(EventArgs.Empty); OnResize(EventArgs.Empty);
if (Load != null) Load(this, e);
OnLoad(e); OnLoad(e);
} }
@ -990,46 +945,19 @@ namespace OpenTK
#region OnRenderFrameInternal #region OnRenderFrameInternal
private void OnRenderFrameInternal(FrameEventArgs e) private void OnRenderFrameInternal(FrameEventArgs e) { if (Exists && !isExiting) OnRenderFrame(e); }
{
EnsureUndisposed();
if (!this.Exists || this.IsExiting) return; // TODO: Redundant because of EnsureUndisposed.
if (RenderFrame != null) RenderFrame(this, e);
OnRenderFrame(e);
}
#endregion #endregion
#region OnUnloadInternal #region OnUnloadInternal
/// <summary> private void OnUnloadInternal(EventArgs e) { OnUnload(e); }
/// Raises the Unload event, and calls the user's OnUnload override.
/// </summary>
/// <param name="e">The event data.</param>
private void OnUnloadInternal(EventArgs e)
{
if (Unload != null) Unload(this, e);
OnUnload(e);
}
#endregion #endregion
#region OnUpdateFrameInternal #region OnUpdateFrameInternal
private void OnUpdateFrameInternal(FrameEventArgs e) private void OnUpdateFrameInternal(FrameEventArgs e) { if (Exists && !isExiting) OnUpdateFrame(e); }
{
EnsureUndisposed();
if (!this.Exists || this.IsExiting) return; // TODO: Redundant because of EnsureUndisposed.
if (UpdateFrame != null) UpdateFrame(this, e);
OnUpdateFrame(e);
}
#endregion #endregion
@ -1045,14 +973,6 @@ namespace OpenTK
#endregion #endregion
#endregion #endregion
///// <summary>Finalizes unmanaged resources consumed by the GameWindow.</summary>
//~GameWindow()
//{
// Dispose(false);
// DisposeInternal(false);
//}
} }
#region public enum VSyncMode #region public enum VSyncMode

View file

@ -15,10 +15,14 @@ namespace OpenTK
{ {
#region --- Fields --- #region --- Fields ---
private bool disposed; private readonly GameWindowFlags options;
private readonly DisplayDevice device;
private readonly INativeWindow implementation; private readonly INativeWindow implementation;
private bool disposed, events;
#endregion #endregion
#region --- Contructors --- #region --- Contructors ---
@ -27,16 +31,7 @@ namespace OpenTK
/// <summary>Constructs a new NativeWindow with default attributes without enabling events.</summary> /// <summary>Constructs a new NativeWindow with default attributes without enabling events.</summary>
public NativeWindow() public NativeWindow()
: this(640, 480, "OpenTK Native Window", GameWindowFlags.Default, GraphicsMode.Default, DisplayDevice.Default, false) { } : this(640, 480, "OpenTK Native Window", GameWindowFlags.Default, GraphicsMode.Default, DisplayDevice.Default) { }
#endregion
#region
/// <summary>Constructs a new NativeWindow with default attributes.</summary>
/// <param name="enableEvents">Indicates to enable event processing as part of the NativeWindow construction.</param>
public NativeWindow(bool enableEvents)
: this(640, 480, "OpenTK Native Window", GameWindowFlags.Default, GraphicsMode.Default, DisplayDevice.Default, enableEvents) { }
#endregion #endregion
@ -44,7 +39,7 @@ namespace OpenTK
#region NativeWindow(int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device) #region NativeWindow(int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device)
/// <summary>Constructs a new centered NativeWindow with the specified attributes without enabling events.</summary> /// <summary>Constructs a new centered NativeWindow with the specified attributes.</summary>
/// <param name="width">The width of the NativeWindow in pixels.</param> /// <param name="width">The width of the NativeWindow in pixels.</param>
/// <param name="height">The height of the NativeWindow in pixels.</param> /// <param name="height">The height of the NativeWindow in pixels.</param>
/// <param name="title">The title of the NativeWindow.</param> /// <param name="title">The title of the NativeWindow.</param>
@ -54,32 +49,15 @@ namespace OpenTK
/// <exception cref="System.ArgumentOutOfRangeException">If width or height is less than 1.</exception> /// <exception cref="System.ArgumentOutOfRangeException">If width or height is less than 1.</exception>
/// <exception cref="System.ArgumentNullException">If mode or device is null.</exception> /// <exception cref="System.ArgumentNullException">If mode or device is null.</exception>
public NativeWindow(int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device) public NativeWindow(int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device)
: this(width, height, title, options, mode, device, false) { }
#endregion
#region NativeWindow(int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device, bool enableEvents)
/// <summary>Constructs a new centered NativeWindow with the specified attributes.</summary>
/// <param name="width">The width of the NativeWindow in pixels.</param>
/// <param name="height">The height of the NativeWindow in pixels.</param>
/// <param name="title">The title of the NativeWindow.</param>
/// <param name="options">GameWindow options specifying window appearance and behavior.</param>
/// <param name="mode">The OpenTK.Graphics.GraphicsMode of the NativeWindow.</param>
/// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the NativeWindow in.</param>
/// <param name="enableEvents">Indicates to enable event processing as part of the NativeWindow construction.</param>
/// <exception cref="System.ArgumentOutOfRangeException">If width or height is less than 1.</exception>
/// <exception cref="System.ArgumentNullException">If mode or device is null.</exception>
public NativeWindow(int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device, bool enableEvents)
: this(device.Bounds.Left + (device.Bounds.Width - width) / 2, : this(device.Bounds.Left + (device.Bounds.Width - width) / 2,
device.Bounds.Top + (device.Bounds.Height - height) / 2, device.Bounds.Top + (device.Bounds.Height - height) / 2,
width, height, title, options, mode, device, enableEvents) { } width, height, title, options, mode, device) { }
#endregion #endregion
#region NativeWindow0(int x, int y, int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device) #region NativeWindow(int x, int y, int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device)
/// <summary>Constructs a new NativeWindow with the specified attributes without enabling events.</summary> /// <summary>Constructs a new NativeWindow with the specified attributes.</summary>
/// <param name="x">Horizontal screen space coordinate of the NativeWindow's origin.</param> /// <param name="x">Horizontal screen space coordinate of the NativeWindow's origin.</param>
/// <param name="y">Vertical screen space coordinate of the NativeWindow's origin.</param> /// <param name="y">Vertical screen space coordinate of the NativeWindow's origin.</param>
/// <param name="width">The width of the NativeWindow in pixels.</param> /// <param name="width">The width of the NativeWindow in pixels.</param>
@ -91,25 +69,6 @@ namespace OpenTK
/// <exception cref="System.ArgumentOutOfRangeException">If width or height is less than 1.</exception> /// <exception cref="System.ArgumentOutOfRangeException">If width or height is less than 1.</exception>
/// <exception cref="System.ArgumentNullException">If mode or device is null.</exception> /// <exception cref="System.ArgumentNullException">If mode or device is null.</exception>
public NativeWindow(int x, int y, int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device) public NativeWindow(int x, int y, int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device)
: this(x, y, width, height, title, options, mode, device, false) { }
#endregion
#region NativeWindow0(int x, int y, int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device, bool enableEvents)
/// <summary>Constructs a new NativeWindow with the specified attributes.</summary>
/// <param name="x">Horizontal screen space coordinate of the NativeWindow's origin.</param>
/// <param name="y">Vertical screen space coordinate of the NativeWindow's origin.</param>
/// <param name="width">The width of the NativeWindow in pixels.</param>
/// <param name="height">The height of the NativeWindow in pixels.</param>
/// <param name="title">The title of the NativeWindow.</param>
/// <param name="options">GameWindow options specifying window appearance and behavior.</param>
/// <param name="mode">The OpenTK.Graphics.GraphicsMode of the NativeWindow.</param>
/// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the NativeWindow in.</param>
/// <param name="enableEvents">Indicates to enable event processing as part of the NativeWindow construction.</param>
/// <exception cref="System.ArgumentOutOfRangeException">If width or height is less than 1.</exception>
/// <exception cref="System.ArgumentNullException">If mode or device is null.</exception>
public NativeWindow(int x, int y, int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device, bool enableEvents)
{ {
// TODO: Should a constraint be added for the position? // TODO: Should a constraint be added for the position?
if (width < 1) if (width < 1)
@ -121,15 +80,16 @@ namespace OpenTK
if (device == null) if (device == null)
throw new ArgumentNullException("device"); throw new ArgumentNullException("device");
implementation = Factory.Default.CreateNativeWindow(x, y, width, height, title, mode, options, device); this.options = options;
this.device = device;
implementation = Factory.Default.CreateNativeWindow(x, y, width, height, title, mode, options, this.device);
if ((options & GameWindowFlags.Fullscreen) != 0) if ((options & GameWindowFlags.Fullscreen) != 0)
{ {
device.ChangeResolution(width, height, mode.ColorFormat.BitsPerPixel, 0); this.device.ChangeResolution(width, height, mode.ColorFormat.BitsPerPixel, 0);
WindowState = WindowState.Fullscreen; WindowState = WindowState.Fullscreen;
} }
if (enableEvents) EnableEvents();
} }
#endregion #endregion
@ -201,8 +161,7 @@ namespace OpenTK
/// </summary> /// </summary>
public void ProcessEvents() public void ProcessEvents()
{ {
EnsureUndisposed(); ProcessEvents(false);
implementation.ProcessEvents();
} }
#endregion #endregion
@ -616,10 +575,15 @@ namespace OpenTK
/// <summary> /// <summary>
/// Releases all non-managed resources belonging to this NativeWindow. /// Releases all non-managed resources belonging to this NativeWindow.
/// </summary> /// </summary>
public void Dispose() public virtual void Dispose()
{ {
if (!disposed) if (!disposed)
{ {
if ((options & GameWindowFlags.Fullscreen) != 0)
{
//if (WindowState == WindowState.Fullscreen) WindowState = WindowState.Normal; // TODO: Revise.
device.RestoreResolution();
}
implementation.Dispose(); implementation.Dispose();
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
@ -635,52 +599,6 @@ namespace OpenTK
#region Methods #region Methods
#region DisableEvents
/// <summary>
/// Disables the propagation of OS events.
/// </summary>
protected void DisableEvents()
{
EnsureUndisposed();
implementation.Closed -= OnClosedInternal;
implementation.Closing -= OnClosingInternal;
implementation.Disposed -= OnDisposedInternal;
implementation.FocusedChanged -= OnFocusedChangedInternal;
implementation.KeyPress -= OnKeyPressInternal;
implementation.Move -= OnMoveInternal;
implementation.Resize -= OnResizeInternal;
implementation.TitleChanged -= OnTitleChangedInternal;
implementation.VisibleChanged -= OnVisibleChangedInternal;
implementation.WindowBorderChanged -= OnWindowBorderChangedInternal;
implementation.WindowStateChanged -= OnWindowStateChangedInternal;
}
#endregion
#region EnableEvents
/// <summary>
/// Enables the propagation of OS events.
/// </summary>
protected void EnableEvents()
{
EnsureUndisposed();
implementation.Closed += OnClosedInternal;
implementation.Closing += OnClosingInternal;
implementation.Disposed += OnDisposedInternal;
implementation.FocusedChanged += OnFocusedChangedInternal;
implementation.KeyPress += OnKeyPressInternal;
implementation.Move += OnMoveInternal;
implementation.Resize += OnResizeInternal;
implementation.TitleChanged += OnTitleChangedInternal;
implementation.VisibleChanged += OnVisibleChangedInternal;
implementation.WindowBorderChanged += OnWindowBorderChangedInternal;
implementation.WindowStateChanged += OnWindowStateChangedInternal;
}
#endregion
#region EnsureUndisposed #region EnsureUndisposed
/// <summary> /// <summary>
@ -711,7 +629,10 @@ namespace OpenTK
/// Called when the NativeWindow has closed. /// Called when the NativeWindow has closed.
/// </summary> /// </summary>
/// <param name="e">Not used.</param> /// <param name="e">Not used.</param>
protected virtual void OnClosed(EventArgs e) { } protected virtual void OnClosed(EventArgs e)
{
if (Closed != null) Closed(this, e);
}
#endregion #endregion
@ -723,7 +644,49 @@ namespace OpenTK
/// <param name="e"> /// <param name="e">
/// The <see cref="System.ComponentModel.CancelEventArgs" /> for this event. /// The <see cref="System.ComponentModel.CancelEventArgs" /> for this event.
/// Set e.Cancel to true in order to stop the NativeWindow from closing.</param> /// Set e.Cancel to true in order to stop the NativeWindow from closing.</param>
protected virtual void OnClosing(CancelEventArgs e) { } protected virtual void OnClosing(CancelEventArgs e)
{
if (Closing != null) Closing(this, e);
}
#endregion
#region OnDisposed
/// <summary>
/// Called when the NativeWindow is disposed.
/// </summary>
/// <param name="e">Not used.</param>
protected virtual void OnDisposed(EventArgs e)
{
if (Disposed != null) Disposed(this, e);
}
#endregion
#region OnFocusedChanged
/// <summary>
/// Called when the <see cref="OpenTK.INativeWindow.Focused"/> property of the NativeWindow has changed.
/// </summary>
/// <param name="e">Not used.</param>
protected virtual void OnFocusedChanged(EventArgs e)
{
if (FocusedChanged != null) FocusedChanged(this, e);
}
#endregion
#region OnKeyPress
/// <summary>
/// Called when a character is typed.
/// </summary>
/// <param name="e">The <see cref="OpenTK.KeyPressEventArgs"/> for this event.</param>
protected virtual void OnKeyPress(KeyPressEventArgs e)
{
if (KeyPress != null) KeyPress(this, e);
}
#endregion #endregion
@ -733,7 +696,10 @@ namespace OpenTK
/// Called when the NativeWindow is moved. /// Called when the NativeWindow is moved.
/// </summary> /// </summary>
/// <param name="e">Not used.</param> /// <param name="e">Not used.</param>
protected virtual void OnMove(EventArgs e) { } protected virtual void OnMove(EventArgs e)
{
if (Move != null) Move(this, e);
}
#endregion #endregion
@ -743,7 +709,36 @@ namespace OpenTK
/// Called when the NativeWindow is resized. /// Called when the NativeWindow is resized.
/// </summary> /// </summary>
/// <param name="e">Not used.</param> /// <param name="e">Not used.</param>
protected virtual void OnResize(EventArgs e) { } protected virtual void OnResize(EventArgs e)
{
if (Resize != null) Resize(this, e);
}
#endregion
#region OnTitleChanged
/// <summary>
/// Called when the <see cref="OpenTK.INativeWindow.Title"/> property of the NativeWindow has changed.
/// </summary>
/// <param name="e">Not used.</param>
protected virtual void OnTitleChanged(EventArgs e)
{
if (TitleChanged != null) TitleChanged(this, e);
}
#endregion
#region OnVisibleChanged
/// <summary>
/// Called when the <see cref="OpenTK.INativeWindow.Visible"/> property of the NativeWindow has changed.
/// </summary>
/// <param name="e">Not used.</param>
protected virtual void OnVisibleChanged(EventArgs e)
{
if (VisibleChanged != null) VisibleChanged(this, e);
}
#endregion #endregion
@ -753,7 +748,10 @@ namespace OpenTK
/// Called when the WindowBorder of this NativeWindow has changed. /// Called when the WindowBorder of this NativeWindow has changed.
/// </summary> /// </summary>
/// <param name="e">Not used.</param> /// <param name="e">Not used.</param>
protected virtual void OnWindowBorderChanged(EventArgs e) { } protected virtual void OnWindowBorderChanged(EventArgs e)
{
if (WindowBorderChanged != null) WindowBorderChanged(this, e);
}
#endregion #endregion
@ -763,7 +761,25 @@ namespace OpenTK
/// Called when the WindowState of this NativeWindow has changed. /// Called when the WindowState of this NativeWindow has changed.
/// </summary> /// </summary>
/// <param name="e">Not used.</param> /// <param name="e">Not used.</param>
protected virtual void OnWindowStateChanged(EventArgs e) { } protected virtual void OnWindowStateChanged(EventArgs e)
{
if (WindowStateChanged != null) WindowStateChanged(this, e);
}
#endregion
#region ProcessEvents
/// <summary>
/// Processes operating system events until the NativeWindow becomes idle.
/// </summary>
/// <param name="retainEvents">If true, the state of underlying system event propagation will be preserved, otherwise event propagation will be enabled if it has not been already.</param>
protected void ProcessEvents(bool retainEvents)
{
EnsureUndisposed();
if (!events) Events = true;
implementation.ProcessEvents();
}
#endregion #endregion
@ -773,129 +789,130 @@ namespace OpenTK
#region --- Private Members --- #region --- Private Members ---
#region Methods
#region OnClosedInternal #region OnClosedInternal
private void OnClosedInternal(object sender, EventArgs e) private void OnClosedInternal(object sender, EventArgs e)
{ {
OnClosed(e); OnClosed(e);
Events = false;
if (Closed != null) Closed(this, e);
} }
#endregion #endregion
#region OnClosingInternal #region OnClosingInternal
private void OnClosingInternal(object sender, CancelEventArgs e) private void OnClosingInternal(object sender, CancelEventArgs e) { OnClosing(e); }
{
OnClosing(e);
if (Closing != null) Closing(this, e);
//if (!e.Cancel) Close();
}
#endregion #endregion
#region OnDisposedInternal #region OnDisposedInternal
private void OnDisposedInternal(object sender, EventArgs e) private void OnDisposedInternal(object sender, EventArgs e) { OnDisposed(e); }
{
// TODO: OnDisposed?
if (Disposed != null) Disposed(this, e);
}
#endregion #endregion
#region OnFocusedChangedInternal #region OnFocusedChangedInternal
private void OnFocusedChangedInternal(object sender, EventArgs e) private void OnFocusedChangedInternal(object sender, EventArgs e) { OnFocusedChanged(e); }
{
// TODO: OnFocusedChanged?
if (FocusedChanged != null) FocusedChanged(this, e);
}
#endregion #endregion
#region OnKeyPressInternal #region OnKeyPressInternal
private void OnKeyPressInternal(object sender, KeyPressEventArgs e) private void OnKeyPressInternal(object sender, KeyPressEventArgs e) { OnKeyPress(e); }
{
// TODO: OnKeyPress?
if (KeyPress != null) KeyPress(this, e);
}
#endregion #endregion
#region OnMoveInternal #region OnMoveInternal
private void OnMoveInternal(object sender, EventArgs e) private void OnMoveInternal(object sender, EventArgs e) { OnMove(e); }
{
EnsureUndisposed();
//if (!this.Exists || this.IsExiting) return; // TODO: See EnableEvents and DisableEvents.
OnMove(e);
if (Move != null) Move(this, e);
}
#endregion #endregion
#region OnResizeInternal #region OnResizeInternal
private void OnResizeInternal(object sender, EventArgs e) private void OnResizeInternal(object sender, EventArgs e) { OnResize(e); }
{
EnsureUndisposed();
//if (!this.Exists || this.IsExiting) return; // TODO: See EnableEvents and DisableEvents.
OnResize(e);
if (Resize != null) Resize(this, e);
}
#endregion #endregion
#region OnTitleChangedInternal #region OnTitleChangedInternal
private void OnTitleChangedInternal(object sender, EventArgs e) private void OnTitleChangedInternal(object sender, EventArgs e) { OnTitleChanged(e); }
{
// TODO: OnTitleChanged?
if (TitleChanged != null) TitleChanged(this, e);
}
#endregion #endregion
#region OnVisibleChangedInternal #region OnVisibleChangedInternal
private void OnVisibleChangedInternal(object sender, EventArgs e) private void OnVisibleChangedInternal(object sender, EventArgs e) { OnVisibleChanged(e); }
{
// TODO: OnVisibleChanged?
if (VisibleChanged != null) VisibleChanged(this, e);
}
#endregion #endregion
#region OnWindowBorderChangedInternal #region OnWindowBorderChangedInternal
private void OnWindowBorderChangedInternal(object sender, EventArgs e) private void OnWindowBorderChangedInternal(object sender, EventArgs e) { OnWindowBorderChanged(e); }
{
OnWindowBorderChanged(e);
if (WindowBorderChanged != null) WindowBorderChanged(this, e); // TODO: This was closed with EventArgs.Empty. Special reason?
}
#endregion #endregion
#region OnWindowStateChangedInternal #region OnWindowStateChangedInternal
private void OnWindowStateChangedInternal(object sender, EventArgs e) private void OnWindowStateChangedInternal(object sender, EventArgs e) { OnWindowStateChanged(e); }
#endregion
#endregion
#region Properties
#region Events
private bool Events
{ {
OnWindowStateChanged(e); set
{
if (WindowStateChanged != null) WindowStateChanged(this, e); if (value)
{
if (events)
{
throw new InvalidOperationException("Event propagation is already enabled.");
} }
implementation.Closed += OnClosedInternal;
implementation.Closing += OnClosingInternal;
implementation.Disposed += OnDisposedInternal;
implementation.FocusedChanged += OnFocusedChangedInternal;
implementation.KeyPress += OnKeyPressInternal;
implementation.Move += OnMoveInternal;
implementation.Resize += OnResizeInternal;
implementation.TitleChanged += OnTitleChangedInternal;
implementation.VisibleChanged += OnVisibleChangedInternal;
implementation.WindowBorderChanged += OnWindowBorderChangedInternal;
implementation.WindowStateChanged += OnWindowStateChangedInternal;
events = true;
}
else if (events)
{
implementation.Closed -= OnClosedInternal;
implementation.Closing -= OnClosingInternal;
implementation.Disposed -= OnDisposedInternal;
implementation.FocusedChanged -= OnFocusedChangedInternal;
implementation.KeyPress -= OnKeyPressInternal;
implementation.Move -= OnMoveInternal;
implementation.Resize -= OnResizeInternal;
implementation.TitleChanged -= OnTitleChangedInternal;
implementation.VisibleChanged -= OnVisibleChangedInternal;
implementation.WindowBorderChanged -= OnWindowBorderChangedInternal;
implementation.WindowStateChanged -= OnWindowStateChangedInternal;
events = false;
}
else
{
throw new InvalidOperationException("Event propagation is already disabled.");
}
}
}
#endregion
#endregion #endregion