diff --git a/src/ScintillaNET/HotspotClickEventArgs.cs b/src/ScintillaNET/HotspotClickEventArgs.cs new file mode 100644 index 0000000..343ad86 --- /dev/null +++ b/src/ScintillaNET/HotspotClickEventArgs.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace ScintillaNET +{ + /// + /// Provides data for the , , + /// and events. + /// + public class HotspotClickEventArgs : EventArgs + { + private readonly Scintilla scintilla; + private readonly int bytePosition; + private int? position; + + /// + /// Gets the modifier keys (SHIFT, CTRL, ALT) held down when clicked. + /// + /// A bitwise combination of the Keys enumeration indicating the modifier keys. + /// Only the state of the CTRL key is reported in the event. + public Keys Modifiers { get; private set; } + + /// + /// Gets the zero-based document position of the text clicked. + /// + /// + /// The zero-based character position within the document of the clicked text; + /// otherwise, -1 if not a document position. + /// + public int Position + { + get + { + if (position == null) + position = scintilla.Lines.ByteToCharPosition(bytePosition); + + return (int)position; + } + } + + /// + /// Initializes a new instance of the class. + /// + /// The control that generated this event. + /// The modifier keys that where held down at the time of the click. + /// The zero-based byte position of the clicked text. + public HotspotClickEventArgs(Scintilla scintilla, Keys modifiers, int bytePosition) + { + this.scintilla = scintilla; + this.bytePosition = bytePosition; + Modifiers = modifiers; + + if (bytePosition == -1) + position = -1; + } + } +} diff --git a/src/ScintillaNET/Scintilla.cs b/src/ScintillaNET/Scintilla.cs index 1cc4eb0..ae733f3 100644 --- a/src/ScintillaNET/Scintilla.cs +++ b/src/ScintillaNET/Scintilla.cs @@ -54,6 +54,9 @@ public class Scintilla : Control private static readonly object doubleClickEventKey = new object(); private static readonly object paintedEventKey = new object(); private static readonly object needShownEventKey = new object(); + private static readonly object hotspotClickEventKey = new object(); + private static readonly object hotspotDoubleClickEventKey = new object(); + private static readonly object hotspotReleaseClickEventKey = new object(); // The goods private IntPtr sciPtr; @@ -1513,6 +1516,39 @@ protected override void OnHandleCreated(EventArgs e) base.OnHandleCreated(e); } + /// + /// Raises the event. + /// + /// A that contains the event data. + protected virtual void OnHotspotClick(HotspotClickEventArgs e) + { + var handler = Events[hotspotClickEventKey] as EventHandler; + if (handler != null) + handler(this, e); + } + + /// + /// Raises the event. + /// + /// A that contains the event data. + protected virtual void OnHotspotDoubleClick(HotspotClickEventArgs e) + { + var handler = Events[hotspotDoubleClickEventKey] as EventHandler; + if (handler != null) + handler(this, e); + } + + /// + /// Raises the event. + /// + /// A that contains the event data. + protected virtual void OnHotspotReleaseClick(HotspotClickEventArgs e) + { + var handler = Events[hotspotReleaseClickEventKey] as EventHandler; + if (handler != null) + handler(this, e); + } + /// /// Raises the event. /// @@ -1835,6 +1871,26 @@ private void ScnDoubleClick(ref NativeMethods.SCNotification scn) OnDoubleClick(eventArgs); } + private void ScnHotspotClick(ref NativeMethods.SCNotification scn) + { + var keys = Keys.Modifiers & (Keys)(scn.modifiers << 16); + var eventArgs = new HotspotClickEventArgs(this, keys, scn.position); + switch (scn.nmhdr.code) + { + case NativeMethods.SCN_HOTSPOTCLICK: + OnHotspotClick(eventArgs); + break; + + case NativeMethods.SCN_HOTSPOTDOUBLECLICK: + OnHotspotDoubleClick(eventArgs); + break; + + case NativeMethods.SCN_HOTSPOTRELEASECLICK: + OnHotspotReleaseClick(eventArgs); + break; + } + } + private void ScnMarginClick(ref NativeMethods.SCNotification scn) { var keys = Keys.Modifiers & (Keys)(scn.modifiers << 16); @@ -2469,6 +2525,12 @@ private void WmReflectNotify(ref Message m) OnNeedShown(new NeedShownEventArgs(this, scn.position, scn.length)); break; + case NativeMethods.SCN_HOTSPOTCLICK: + case NativeMethods.SCN_HOTSPOTDOUBLECLICK: + case NativeMethods.SCN_HOTSPOTRELEASECLICK: + ScnHotspotClick(ref scn); + break; + default: // Not our notification base.WndProc(ref m); @@ -5367,6 +5429,57 @@ public event EventHandler DwellStart } } + /// + /// Occurs when the user clicks on text that is in a style with the property set. + /// + [Category("Notifications")] + [Description("Occurs when the user clicks text styled with the hotspot flag.")] + public event EventHandler HotspotClick + { + add + { + Events.AddHandler(hotspotClickEventKey, value); + } + remove + { + Events.RemoveHandler(hotspotClickEventKey, value); + } + } + + /// + /// Occurs when the user double clicks on text that is in a style with the property set. + /// + [Category("Notifications")] + [Description("Occurs when the user double clicks text styled with the hotspot flag.")] + public event EventHandler HotspotDoubleClick + { + add + { + Events.AddHandler(hotspotDoubleClickEventKey, value); + } + remove + { + Events.RemoveHandler(hotspotDoubleClickEventKey, value); + } + } + + /// + /// Occurs when the user releases a click on text that is in a style with the property set. + /// + [Category("Notifications")] + [Description("Occurs when the user releases a click on text styled with the hotspot flag.")] + public event EventHandler HotspotReleaseClick + { + add + { + Events.AddHandler(hotspotReleaseClickEventKey, value); + } + remove + { + Events.RemoveHandler(hotspotReleaseClickEventKey, value); + } + } + /// /// Occurs when text has been inserted into the document. /// diff --git a/src/ScintillaNET/ScintillaNET.csproj b/src/ScintillaNET/ScintillaNET.csproj index c6f25c8..245ccc2 100644 --- a/src/ScintillaNET/ScintillaNET.csproj +++ b/src/ScintillaNET/ScintillaNET.csproj @@ -78,6 +78,7 @@ +