using System; using System.Drawing.Drawing2D; using System.Collections.Generic; using System.Text; using System.Drawing; using System.IO; using System.Diagnostics; using System.Windows.Forms; namespace Netron.Diagramming.Core { /// /// Clickable icon-and-label shape material, i.e. an hyperlink with an icon. This material combines /// the and the /// public partial class ClickableIconLabelMaterial : IconLabelMaterial, IMouseListener, IHoverListener { #region Fields /// /// the url of this link /// private string mUrl = string.Empty; // ------------------------------------------------------------------ /// /// Implementation of IVersion - the current version of /// ClickableIconLabelMaterial. /// // ------------------------------------------------------------------ protected double clickableIconLabelMaterialVersion = 1.0; #endregion #region Properties // ------------------------------------------------------------------ /// /// Gets or sets the URL of this clickable material. Note that the /// material can handle more than just Url's by overriding the mouse /// event handlers. Settings this property is just a convenient way /// to accelerate the development or customization of shapes. /// /// The URL. // ------------------------------------------------------------------ public string Url { get { return mUrl; } set { mUrl = value; } } // ------------------------------------------------------------------ /// /// Gets the current version. /// // ------------------------------------------------------------------ public virtual double Version { get { return clickableIconLabelMaterialVersion; } } #endregion #region Constructor /// /// Initializes a new instance of the class. /// public ClickableIconLabelMaterial() : base() { //Resizable = false; } /// /// Initializes a new instance of the class. /// /// The text. public ClickableIconLabelMaterial(string text) : base(text) { } /// /// Initializes a new instance of the class. /// /// The text. /// The resource location. public ClickableIconLabelMaterial(string text, string resourceLocation) : base(text, resourceLocation) { } /// /// Initializes a new instance of the class. /// /// The text. /// The resource location. /// The URL. public ClickableIconLabelMaterial(string text, string resourceLocation, string url) : base(text, resourceLocation) { this.mUrl = url; } #endregion #region Methods #region IMouseListener Members /// /// Gets the service object of the specified type. /// /// An object that specifies the type of service object to get. /// /// A service object of type serviceType.-or- null if there is no service object of type serviceType. /// public override object GetService(Type serviceType) { if (serviceType.Equals(typeof(IMouseListener))) return this; else if (serviceType.Equals(typeof(IHoverListener))) return this; else return null; } /// /// Handles the mouse-down event /// /// The instance containing the event data. public virtual bool MouseDown(MouseEventArgs e) { if (this.Rectangle.Contains(e.Location)) { if (mUrl.Length > 0) { try { Process.Start(mUrl); } catch (ObjectDisposedException oex) { Trace.WriteLine(oex.Message); } catch (System.ComponentModel.Win32Exception wex) { Trace.WriteLine(wex.Message); } catch (ArgumentException aex) { Trace.WriteLine(aex.Message); } catch (InvalidOperationException iex) { Trace.WriteLine(iex.Message); } } return true;//let the rest of the loop go, the event was handled } return false; } /// /// Handles the mouse-move event /// /// The instance containing the event data. public void MouseMove(MouseEventArgs e) { System.Diagnostics.Trace.WriteLine(e.Location.ToString()); } /// /// Handles the mouse-up event /// /// The instance containing the event data. public virtual void MouseUp(MouseEventArgs e) { } #endregion #region IHoverListener Members /// /// Handles the event. /// /// The instance containing the event data. public void MouseHover(MouseEventArgs e) { } private Cursor previousCursor; /// /// Handles the OnMouseEnter event. /// /// The instance containing the event data. public void MouseEnter(MouseEventArgs e) { previousCursor = Cursor.Current; this.Shape.Model.RaiseOnCursorChange(Cursors.Hand); } /// /// Handles the OnMouseLeave event. /// /// The instance containing the event data. public void MouseLeave(MouseEventArgs e) { this.Shape.Model.RaiseOnCursorChange(previousCursor); } //public override void Paint(Graphics g) //{ // g.DrawRectangle(Pens.Violet, Rectangle); // base.Paint(g); //} #endregion #endregion } }