#region License
// Copyright (c) 2010, Jasper Yeh.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of ClearCanvas Inc. nor the names of its contributors
// may be used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
// OF SUCH DAMAGE.
#endregion
using System;
using ClearCanvas.Common;
using ClearCanvas.Common.Utilities;
using ClearCanvas.Desktop;
using WinFormsControl = System.Windows.Forms.Control;
using WinFormsHost=System.Windows.Forms.Integration.WindowsFormsHost;
namespace Nullstack.ClearCanvasEx.DesktopEx.View.WpfAdapter
{
///
/// Abstract base implementation of .
///
public abstract class DesktopObjectView : WpfView, IDesktopObjectView
{
private event EventHandler _activeChanged;
private event EventHandler _visibleChanged;
private event EventHandler _closeRequested;
private event EventHandler _titleChanged;
private bool _active = false;
private bool _visible = false;
private string _title = null;
///
/// Gets a value indicating whether or not the view object is visible.
///
public bool Visible
{
get { return _visible; }
protected internal set
{
if (_visible != value)
{
_visible = value;
OnVisibleChanged(EventArgs.Empty);
}
}
}
///
/// Gets a value indicating whether or not the view object is currently active.
///
public bool Active
{
get { return _active; }
protected internal set
{
if (_active != value)
{
_active = value;
OnActiveChanged(EventArgs.Empty);
}
}
}
public string Title
{
get { return _title; }
set
{
if (_title != value)
{
_title = value;
OnTitleChanged(EventArgs.Empty);
}
}
}
///
/// Occurs when the property changes.
///
public event EventHandler VisibleChanged
{
add { _visibleChanged += value; }
remove { _visibleChanged -= value; }
}
///
/// Occurs when the property changes.
///
public event EventHandler ActiveChanged
{
add { _activeChanged += value; }
remove { _activeChanged -= value; }
}
///
/// Occurs when the user has requested that the view object be closed.
///
public event EventHandler CloseRequested
{
add { _closeRequested += value; }
remove { _closeRequested -= value; }
}
public event EventHandler TitleChanged
{
add { _titleChanged += value; }
remove { _titleChanged -= value; }
}
///
/// Opens the view object.
///
public abstract void Open();
///
/// Shows the view object.
///
public abstract void Show();
///
/// Hides the view object.
///
public abstract void Hide();
///
/// Activates the view object.
///
public abstract void Activate();
///
/// Requests that the view object be closed.
///
protected internal void RequestClose()
{
OnCloseRequested(EventArgs.Empty);
}
///
/// Sets the title of the view object.
///
///
void IDesktopObjectView.SetTitle(string title)
{
Title = title;
}
///
/// Disposes of this object.
///
/// A value indicating whether the object is being disposed or being finalized.
protected virtual void Dispose(bool disposing) {}
///
/// Raises the event.
///
protected virtual void OnCloseRequested(EventArgs e)
{
EventsHelper.Fire(_closeRequested, this, e);
}
///
/// Raises the event.
///
protected virtual void OnActiveChanged(EventArgs e)
{
EventsHelper.Fire(_activeChanged, this, e);
}
///
/// Raises the event.
///
protected virtual void OnVisibleChanged(EventArgs e)
{
EventsHelper.Fire(_visibleChanged, this, e);
}
protected virtual void OnTitleChanged(EventArgs e)
{
EventsHelper.Fire(_titleChanged, this, e);
}
protected static object GetContent(object guiElement)
{
if (guiElement is WinFormsControl)
return new WinFormsHost {Child = (WinFormsControl) guiElement};
return guiElement;
}
#region IDisposable Members
///
/// Disposes of this object.
///
public void Dispose()
{
try
{
Dispose(true);
GC.SuppressFinalize(this);
}
catch (Exception e)
{
// shouldn't throw anything from inside Dispose()
Platform.Log(LogLevel.Error, e);
}
}
#endregion
#region WpfView overrides
///
/// Not used by this class.
///
public override object GuiElement
{
get { throw new NotSupportedException(); }
}
#endregion
}
}