#region Disclaimer / License // Copyright (C) 2010, Jackie Ng // http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie@gmail.com // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // #endregion using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; namespace Maestro.Shared.UI { /// /// The base class of all view content. Provides the default implementation of /// [ToolboxItem(false)] public partial class ViewContentBase : UserControl, IViewContent { /// /// Initializes a new instance of the class. /// public ViewContentBase() { InitializeComponent(); } public virtual bool IsModalWindow { get { return false; } } public virtual bool IsExclusiveToDocumentRegion { get { return false; } } private string _title; /// /// The title of the view /// public string Title { get { return _title; } set { if (_title != value) { _title = value; var handler = this.TitleChanged; if (handler != null) handler(this, EventArgs.Empty); } } } private Form _parent; public void SetParentForm(Form form) { if (_parent != null) throw new InvalidOperationException("Parent form already set"); _parent = form; _parent.FormClosing += new FormClosingEventHandler(OnParentFormClosing); _parent.FormClosing += new FormClosingEventHandler(OnParentFormClosed); } void OnParentFormClosed(object sender, FormClosingEventArgs e) { var h = this.ViewContentClosed; if (h != null) h(this, EventArgs.Empty); } void OnParentFormClosing(object sender, FormClosingEventArgs e) { e.Cancel = CheckCancelEvents(); } /// /// Fires when the title has been changed /// public event EventHandler TitleChanged; /// /// Detrmines if this view can be closed by the user, note that this does not affect the method /// in any way. All view content can still be programmatically closed if they inherit from and /// does not override the default implementation of /// public virtual bool AllowUserClose { get { return true; } } internal bool CheckCancelEvents() { CancelEventArgs ce = new CancelEventArgs(false); var ceHandler = this.ViewContentClosing; if (ceHandler != null) ceHandler(this, ce); return ce.Cancel; } /// /// Closes the view. This raises the event /// public virtual void Close() { if (_parent != null) _parent.Close(); } /// /// Fired when the view has been closed internally /// public event CancelEventHandler ViewContentClosing; /// /// Displays an exception message /// /// The exception object public void ShowError(Exception ex) { ErrorDialog.Show(ex); } /// /// Displays an error message /// /// The message public virtual void ShowError(string message) { //MessageService.ShowError(message); ErrorDialog.Show(message, message); } /// /// Displays an alert message /// /// The title of this message /// The message public virtual void ShowMessage(string title, string message) { //MessageService.ShowMessage(message, title); MessageBox.Show(message, title); } /// /// Make a request for confirmation /// /// The title of the confirmation message /// The message /// /// true if confirmed, false otherwise /// public virtual bool Confirm(string title, string message) { //return MessageService.AskQuestion(message, title); return MessageBox.Show(message, title, MessageBoxButtons.YesNo) == DialogResult.Yes; } /// /// Make a request for confirmation /// /// The title of the confirmation message /// The message template /// The template values /// /// true if confirmed, false otherwise /// public virtual bool ConfirmFormatted(string title, string format, params string[] args) { //return MessageService.AskQuestion(string.Format(format, args), title); return MessageBox.Show(string.Format(format, args), title, MessageBoxButtons.YesNo) == DialogResult.Yes; } /// /// The underlying control /// public Control ContentControl { get { return this; } } private string _description; /// /// The view's description, this is the ToolTip content /// public string Description { get { return _description; } set { if (_description != value) { _description = value; var handler = this.DescriptionChanged; if (handler != null) handler(this, EventArgs.Empty); } } } /// /// Raised when the description has changed /// public event EventHandler DescriptionChanged; /// /// Makes this content active /// public void Activate() { var handler = this.ViewContentActivating; if (handler != null) handler(this, EventArgs.Empty); } /// /// Fired when the view is going to hide /// public event EventHandler ViewContentHiding; /// /// Fired when the view is activating /// public event EventHandler ViewContentActivating; /// /// Conceals the control from the user. /// /// /// /// /// /// /// void IViewContent.Hide() { var handler = this.ViewContentHiding; if (handler != null) handler(this, EventArgs.Empty); } /// /// Indicates whether this view is attached to a workbench /// public bool IsAttached { get; internal set; } /// /// Indicates the default region this view content will be put in /// public virtual ViewRegion DefaultRegion { get { return ViewRegion.Document; } } /// /// Gets the icon for this view /// public virtual Icon ViewIcon { get { return null; } } /// /// Fired when the view has been closed internally /// public event EventHandler ViewContentClosed; /// /// Fired when the view, which was hidden is now being shown /// public event EventHandler ViewContentShowing; } }