#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 System.ComponentModel;
using System.Windows;
using ClearCanvas.Common;
using ClearCanvas.Desktop;
using ClearCanvas.Desktop.Actions;
using Nullstack.ClearCanvasEx.DesktopEx.View.WpfAdapter.Utilities;
namespace Nullstack.ClearCanvasEx.DesktopEx.View.WpfAdapter
{
///
/// WPF implementation of .
///
///
///
/// This class may subclassed if customization is desired. In this case, the
/// class must also be subclassed in order to instantiate the subclass from
/// its method.
///
///
public class DesktopWindowView : DesktopObjectView, IDesktopWindowView
{
private static OrderedSet _desktopWindowActivationOrder = new OrderedSet();
private OrderedSet _workspaceActivationOrder = new OrderedSet();
private IDesktopWindow _desktopWindow;
private DesktopWindowForm _desktopWindowForm;
protected internal DesktopWindowView(IDesktopWindow desktopWindow)
: this(desktopWindow, new DesktopWindowForm()) {}
protected DesktopWindowView(IDesktopWindow desktopWindow, DesktopWindowForm desktopWindowForm)
{
_desktopWindow = desktopWindow;
_desktopWindowForm = desktopWindowForm;
//_desktopWindowForm.VisibleChanged += new EventHandler(FormVisibleChangedEventHandler);
_desktopWindowForm.Activated += OnDesktopWindowFormActivated;
_desktopWindowForm.Deactivated += OnDesktopWindowFormDeactivated;
_desktopWindowForm.Closing += OnDesktopWindowFormClosing;
_desktopWindowForm.ActiveWorkspaceViewChanged += OnDesktopWindowFormActiveWorkspaceViewChanged;
//_desktopWindowForm.TabbedGroups.PageCloseRequest += new TabbedGroups.PageCloseRequestHandler(TabbedGroupPageClosePressedEventHandler);
//_desktopWindowForm.TabbedGroups.PageChanged += new TabbedGroups.PageChangeHandler(TabbedGroupPageChangedEventHandler);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (_desktopWindowForm != null)
{
_desktopWindowForm.Activated -= OnDesktopWindowFormActivated;
_desktopWindowForm.Deactivated -= OnDesktopWindowFormDeactivated;
_desktopWindowForm.Closing -= OnDesktopWindowFormClosing;
_desktopWindowForm.ActiveWorkspaceViewChanged -= OnDesktopWindowFormActiveWorkspaceViewChanged;
_desktopWindowForm = null;
}
if (_desktopWindow != null)
{
_desktopWindow = null;
}
}
base.Dispose(disposing);
}
protected internal Window DesktopWindowForm
{
get { return _desktopWindowForm; }
}
public ActionModelNode GlobalMenus
{
get { return _desktopWindowForm.GlobalMenus; }
set { _desktopWindowForm.GlobalMenus = value; }
}
public ActionModelNode GlobalToolbars
{
get { return _desktopWindowForm.GlobalToolbars; }
set { _desktopWindowForm.GlobalToolbars = value; }
}
public override void Open()
{
_desktopWindowForm.Show();
}
public override void Show()
{
_desktopWindowForm.Show();
}
public override void Hide()
{
_desktopWindowForm.Hide();
}
public override void Activate()
{
_desktopWindowForm.Activate();
}
protected override void OnTitleChanged(EventArgs e)
{
base.OnTitleChanged(e);
var title = Title;
if (string.IsNullOrEmpty(title))
title = " ";
_desktopWindowForm.Title = title;
}
#region IDesktopWindowView Members
public IDialogBoxView CreateDialogBoxView(DialogBox dialog)
{
return null;
throw new NotImplementedException();
}
public IShelfView CreateShelfView(Shelf shelf)
{
return null;
throw new NotImplementedException();
}
public IWorkspaceView CreateWorkspaceView(Workspace workspace)
{
return new WorkspaceView(workspace, this);
}
void IDesktopWindowView.SetMenuModel(ActionModelNode model)
{
GlobalMenus = model;
}
void IDesktopWindowView.SetToolbarModel(ActionModelNode model)
{
GlobalToolbars = model;
}
public DialogBoxAction ShowMessageBox(string message, string title, MessageBoxActions buttons)
{
return MessageBox.Show(message, title, buttons, _desktopWindowForm);
}
public FileDialogResult ShowOpenFileDialogBox(FileDialogCreationArgs args)
{
return null;
throw new NotImplementedException();
}
public FileDialogResult ShowSaveFileDialogBox(FileDialogCreationArgs args)
{
return null;
throw new NotImplementedException();
}
public FileDialogResult ShowSelectFolderDialogBox(SelectFolderDialogCreationArgs args)
{
return null;
throw new NotImplementedException();
}
#endregion
#region Window Events
private void OnDesktopWindowFormActivated(object sender, EventArgs e)
{
// deactivate the previous window before activating the new one
var lastActiveDesktopWindow = _desktopWindowActivationOrder.LastElement;
if (lastActiveDesktopWindow != this)
{
if (lastActiveDesktopWindow != null)
{
lastActiveDesktopWindow.Active = false;
}
Active = true;
_desktopWindowActivationOrder.Add(this);
}
}
private void OnDesktopWindowFormDeactivated(object sender, EventArgs e)
{
// this event may be fired when showing a dialog, so it's not really useful
}
private void OnDesktopWindowFormClosing(object sender, CancelEventArgs e)
{
e.Cancel = true;
RequestClose();
}
private void OnDesktopWindowFormActiveWorkspaceViewChanged(object sender, EventArgs e)
{
// deactivate the previous workspace before activating the new one
var lastActiveWorkspace = _workspaceActivationOrder.LastElement;
if (lastActiveWorkspace != null)
{
lastActiveWorkspace.Active = false;
}
// account for the case where the last workspace closes
var activeWorkspace = _desktopWindowForm.ActiveWorkspaceView;
if (activeWorkspace != null)
{
activeWorkspace.Active = false; // force a change event, if it's initializing the workspace
activeWorkspace.Active = true;
_workspaceActivationOrder.Add(activeWorkspace);
}
}
#endregion
internal void AddWorkspaceView(WorkspaceView workspaceView)
{
_desktopWindowForm.AddWorkspaceView(workspaceView);
}
internal void RemoveWorkspaceView(WorkspaceView workspaceView)
{
_desktopWindowForm.RemoveWorkspaceView(workspaceView);
}
}
}