1 | using System;
|
---|
2 | using System.Drawing.Drawing2D;
|
---|
3 | using System.Collections.Generic;
|
---|
4 | using System.Text;
|
---|
5 | using System.Drawing;
|
---|
6 | using System.IO;
|
---|
7 | using System.Diagnostics;
|
---|
8 | using System.Windows.Forms;
|
---|
9 | namespace Netron.Diagramming.Core
|
---|
10 | {
|
---|
11 | /// <summary>
|
---|
12 | /// Clickable icon-and-label shape material, i.e. an hyperlink with an icon. This material combines
|
---|
13 | /// the <see cref="IconMaterial"/> and the <see cref="ClcikableLabelMaterial"/>
|
---|
14 | /// </summary>
|
---|
15 | public partial class ClickableIconLabelMaterial :
|
---|
16 | IconLabelMaterial,
|
---|
17 | IMouseListener,
|
---|
18 | IHoverListener
|
---|
19 | {
|
---|
20 | #region Fields
|
---|
21 | /// <summary>
|
---|
22 | /// the url of this link
|
---|
23 | /// </summary>
|
---|
24 | private string mUrl = string.Empty;
|
---|
25 |
|
---|
26 | // ------------------------------------------------------------------
|
---|
27 | /// <summary>
|
---|
28 | /// Implementation of IVersion - the current version of
|
---|
29 | /// ClickableIconLabelMaterial.
|
---|
30 | /// </summary>
|
---|
31 | // ------------------------------------------------------------------
|
---|
32 | protected double clickableIconLabelMaterialVersion = 1.0;
|
---|
33 |
|
---|
34 | #endregion
|
---|
35 |
|
---|
36 | #region Properties
|
---|
37 |
|
---|
38 | // ------------------------------------------------------------------
|
---|
39 | /// <summary>
|
---|
40 | /// Gets or sets the URL of this clickable material. Note that the
|
---|
41 | /// material can handle more than just Url's by overriding the mouse
|
---|
42 | /// event handlers. Settings this property is just a convenient way
|
---|
43 | /// to accelerate the development or customization of shapes.
|
---|
44 | /// </summary>
|
---|
45 | /// <value>The URL.</value>
|
---|
46 | // ------------------------------------------------------------------
|
---|
47 | public string Url
|
---|
48 | {
|
---|
49 | get { return mUrl; }
|
---|
50 | set { mUrl = value; }
|
---|
51 | }
|
---|
52 |
|
---|
53 | // ------------------------------------------------------------------
|
---|
54 | /// <summary>
|
---|
55 | /// Gets the current version.
|
---|
56 | /// </summary>
|
---|
57 | // ------------------------------------------------------------------
|
---|
58 | public virtual double Version
|
---|
59 | {
|
---|
60 | get
|
---|
61 | {
|
---|
62 | return clickableIconLabelMaterialVersion;
|
---|
63 | }
|
---|
64 | }
|
---|
65 | #endregion
|
---|
66 |
|
---|
67 | #region Constructor
|
---|
68 | /// <summary>
|
---|
69 | /// Initializes a new instance of the <see cref="T:ClickableIconLabelMaterial"/> class.
|
---|
70 | /// </summary>
|
---|
71 | public ClickableIconLabelMaterial() : base()
|
---|
72 | {
|
---|
73 | //Resizable = false;
|
---|
74 | }
|
---|
75 |
|
---|
76 | /// <summary>
|
---|
77 | /// Initializes a new instance of the <see cref="T:ClickableIconLabelMaterial"/> class.
|
---|
78 | /// </summary>
|
---|
79 | /// <param name="text">The text.</param>
|
---|
80 | public ClickableIconLabelMaterial(string text) : base(text) { }
|
---|
81 |
|
---|
82 | /// <summary>
|
---|
83 | /// Initializes a new instance of the <see cref="T:ClickableIconLabelMaterial"/> class.
|
---|
84 | /// </summary>
|
---|
85 | /// <param name="text">The text.</param>
|
---|
86 | /// <param name="resourceLocation">The resource location.</param>
|
---|
87 | public ClickableIconLabelMaterial(string text, string resourceLocation)
|
---|
88 | : base(text, resourceLocation)
|
---|
89 | {
|
---|
90 |
|
---|
91 | }
|
---|
92 |
|
---|
93 | /// <summary>
|
---|
94 | /// Initializes a new instance of the <see cref="T:ClickableIconLabelMaterial"/> class.
|
---|
95 | /// </summary>
|
---|
96 | /// <param name="text">The text.</param>
|
---|
97 | /// <param name="resourceLocation">The resource location.</param>
|
---|
98 | /// <param name="url">The URL.</param>
|
---|
99 | public ClickableIconLabelMaterial(string text, string resourceLocation, string url)
|
---|
100 | : base(text, resourceLocation)
|
---|
101 | {
|
---|
102 | this.mUrl = url;
|
---|
103 | }
|
---|
104 | #endregion
|
---|
105 |
|
---|
106 | #region Methods
|
---|
107 |
|
---|
108 | #region IMouseListener Members
|
---|
109 | /// <summary>
|
---|
110 | /// Gets the service object of the specified type.
|
---|
111 | /// </summary>
|
---|
112 | /// <param name="serviceType">An object that specifies the type of service object to get.</param>
|
---|
113 | /// <returns>
|
---|
114 | /// A service object of type serviceType.-or- null if there is no service object of type serviceType.
|
---|
115 | /// </returns>
|
---|
116 | public override object GetService(Type serviceType)
|
---|
117 | {
|
---|
118 | if (serviceType.Equals(typeof(IMouseListener)))
|
---|
119 | return this;
|
---|
120 | else if (serviceType.Equals(typeof(IHoverListener)))
|
---|
121 | return this;
|
---|
122 | else
|
---|
123 | return null;
|
---|
124 | }
|
---|
125 |
|
---|
126 | /// <summary>
|
---|
127 | /// Handles the mouse-down event
|
---|
128 | /// </summary>
|
---|
129 | /// <param name="e">The <see cref="T:MouseEventArgs"/> instance containing the event data.</param>
|
---|
130 | public virtual bool MouseDown(MouseEventArgs e)
|
---|
131 | {
|
---|
132 | if (this.Rectangle.Contains(e.Location))
|
---|
133 | {
|
---|
134 | if (mUrl.Length > 0)
|
---|
135 | {
|
---|
136 | try
|
---|
137 | {
|
---|
138 | Process.Start(mUrl);
|
---|
139 | }
|
---|
140 |
|
---|
141 | catch (ObjectDisposedException oex)
|
---|
142 | {
|
---|
143 | Trace.WriteLine(oex.Message);
|
---|
144 | }
|
---|
145 | catch (System.ComponentModel.Win32Exception wex)
|
---|
146 | {
|
---|
147 | Trace.WriteLine(wex.Message);
|
---|
148 | }
|
---|
149 | catch (ArgumentException aex)
|
---|
150 | {
|
---|
151 | Trace.WriteLine(aex.Message);
|
---|
152 | }
|
---|
153 | catch (InvalidOperationException iex)
|
---|
154 | {
|
---|
155 | Trace.WriteLine(iex.Message);
|
---|
156 | }
|
---|
157 | }
|
---|
158 | return true;//let the rest of the loop go, the event was handled
|
---|
159 | }
|
---|
160 | return false;
|
---|
161 | }
|
---|
162 |
|
---|
163 | /// <summary>
|
---|
164 | /// Handles the mouse-move event
|
---|
165 | /// </summary>
|
---|
166 | /// <param name="e">The <see cref="T:MouseEventArgs"/> instance containing the event data.</param>
|
---|
167 | public void MouseMove(MouseEventArgs e)
|
---|
168 | {
|
---|
169 | System.Diagnostics.Trace.WriteLine(e.Location.ToString());
|
---|
170 | }
|
---|
171 |
|
---|
172 | /// <summary>
|
---|
173 | /// Handles the mouse-up event
|
---|
174 | /// </summary>
|
---|
175 | /// <param name="e">The <see cref="T:MouseEventArgs"/> instance containing the event data.</param>
|
---|
176 | public virtual void MouseUp(MouseEventArgs e)
|
---|
177 | {
|
---|
178 |
|
---|
179 | }
|
---|
180 |
|
---|
181 | #endregion
|
---|
182 |
|
---|
183 | #region IHoverListener Members
|
---|
184 | /// <summary>
|
---|
185 | /// Handles the <see cref="OnMouseHover"/> event.
|
---|
186 | /// </summary>
|
---|
187 | /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
|
---|
188 | public void MouseHover(MouseEventArgs e)
|
---|
189 | {
|
---|
190 |
|
---|
191 | }
|
---|
192 | private Cursor previousCursor;
|
---|
193 |
|
---|
194 | /// <summary>
|
---|
195 | /// Handles the OnMouseEnter event.
|
---|
196 | /// </summary>
|
---|
197 | /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
|
---|
198 | public void MouseEnter(MouseEventArgs e)
|
---|
199 | {
|
---|
200 | previousCursor = Cursor.Current;
|
---|
201 | this.Shape.Model.RaiseOnCursorChange(Cursors.Hand);
|
---|
202 | }
|
---|
203 |
|
---|
204 | /// <summary>
|
---|
205 | /// Handles the OnMouseLeave event.
|
---|
206 | /// </summary>
|
---|
207 | /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
|
---|
208 | public void MouseLeave(MouseEventArgs e)
|
---|
209 | {
|
---|
210 | this.Shape.Model.RaiseOnCursorChange(previousCursor);
|
---|
211 | }
|
---|
212 |
|
---|
213 | //public override void Paint(Graphics g)
|
---|
214 | //{
|
---|
215 | // g.DrawRectangle(Pens.Violet, Rectangle);
|
---|
216 | // base.Paint(g);
|
---|
217 | //}
|
---|
218 | #endregion
|
---|
219 |
|
---|
220 | #endregion
|
---|
221 |
|
---|
222 | }
|
---|
223 | }
|
---|