Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Commit

Permalink
Hotspot click events. Issue #105.
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobslusser committed Aug 9, 2015
1 parent 4be580c commit 9664588
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/ScintillaNET/HotspotClickEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ScintillaNET
{
/// <summary>
/// Provides data for the <see cref="Scintilla.HotspotClick" />, <see cref="Scintilla.HotspotDoubleClick" />,
/// and <see cref="Scintilla.HotspotReleaseClick" /> events.
/// </summary>
public class HotspotClickEventArgs : EventArgs
{
private readonly Scintilla scintilla;
private readonly int bytePosition;
private int? position;

/// <summary>
/// Gets the modifier keys (SHIFT, CTRL, ALT) held down when clicked.
/// </summary>
/// <returns>A bitwise combination of the Keys enumeration indicating the modifier keys.</returns>
/// <remarks>Only the state of the CTRL key is reported in the <see cref="Scintilla.HotspotReleaseClick" /> event.</remarks>
public Keys Modifiers { get; private set; }

/// <summary>
/// Gets the zero-based document position of the text clicked.
/// </summary>
/// <returns>
/// The zero-based character position within the document of the clicked text;
/// otherwise, -1 if not a document position.
/// </returns>
public int Position
{
get
{
if (position == null)
position = scintilla.Lines.ByteToCharPosition(bytePosition);

return (int)position;
}
}

/// <summary>
/// Initializes a new instance of the <see cref="HotspotClickEventArgs" /> class.
/// </summary>
/// <param name="scintilla">The <see cref="Scintilla" /> control that generated this event.</param>
/// <param name="modifiers">The modifier keys that where held down at the time of the click.</param>
/// <param name="bytePosition">The zero-based byte position of the clicked text.</param>
public HotspotClickEventArgs(Scintilla scintilla, Keys modifiers, int bytePosition)
{
this.scintilla = scintilla;
this.bytePosition = bytePosition;
Modifiers = modifiers;

if (bytePosition == -1)
position = -1;
}
}
}
113 changes: 113 additions & 0 deletions src/ScintillaNET/Scintilla.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1513,6 +1516,39 @@ protected override void OnHandleCreated(EventArgs e)
base.OnHandleCreated(e);
}

/// <summary>
/// Raises the <see cref="HotspotClick" /> event.
/// </summary>
/// <param name="e">A <see cref="HotspotClickEventArgs" /> that contains the event data.</param>
protected virtual void OnHotspotClick(HotspotClickEventArgs e)
{
var handler = Events[hotspotClickEventKey] as EventHandler<HotspotClickEventArgs>;
if (handler != null)
handler(this, e);
}

/// <summary>
/// Raises the <see cref="HotspotDoubleClick" /> event.
/// </summary>
/// <param name="e">A <see cref="HotspotClickEventArgs" /> that contains the event data.</param>
protected virtual void OnHotspotDoubleClick(HotspotClickEventArgs e)
{
var handler = Events[hotspotDoubleClickEventKey] as EventHandler<HotspotClickEventArgs>;
if (handler != null)
handler(this, e);
}

/// <summary>
/// Raises the <see cref="HotspotReleaseClick" /> event.
/// </summary>
/// <param name="e">A <see cref="HotspotClickEventArgs" /> that contains the event data.</param>
protected virtual void OnHotspotReleaseClick(HotspotClickEventArgs e)
{
var handler = Events[hotspotReleaseClickEventKey] as EventHandler<HotspotClickEventArgs>;
if (handler != null)
handler(this, e);
}

/// <summary>
/// Raises the <see cref="Insert" /> event.
/// </summary>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -5367,6 +5429,57 @@ public event EventHandler<DwellEventArgs> DwellStart
}
}

/// <summary>
/// Occurs when the user clicks on text that is in a style with the <see cref="Style.Hotspot" /> property set.
/// </summary>
[Category("Notifications")]
[Description("Occurs when the user clicks text styled with the hotspot flag.")]
public event EventHandler<HotspotClickEventArgs> HotspotClick
{
add
{
Events.AddHandler(hotspotClickEventKey, value);
}
remove
{
Events.RemoveHandler(hotspotClickEventKey, value);
}
}

/// <summary>
/// Occurs when the user double clicks on text that is in a style with the <see cref="Style.Hotspot" /> property set.
/// </summary>
[Category("Notifications")]
[Description("Occurs when the user double clicks text styled with the hotspot flag.")]
public event EventHandler<HotspotClickEventArgs> HotspotDoubleClick
{
add
{
Events.AddHandler(hotspotDoubleClickEventKey, value);
}
remove
{
Events.RemoveHandler(hotspotDoubleClickEventKey, value);
}
}

/// <summary>
/// Occurs when the user releases a click on text that is in a style with the <see cref="Style.Hotspot" /> property set.
/// </summary>
[Category("Notifications")]
[Description("Occurs when the user releases a click on text styled with the hotspot flag.")]
public event EventHandler<HotspotClickEventArgs> HotspotReleaseClick
{
add
{
Events.AddHandler(hotspotReleaseClickEventKey, value);
}
remove
{
Events.RemoveHandler(hotspotReleaseClickEventKey, value);
}
}

/// <summary>
/// Occurs when text has been inserted into the document.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/ScintillaNET/ScintillaNET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<Compile Include="FontQuality.cs" />
<Compile Include="GapBuffer.cs" />
<Compile Include="Helpers.cs" />
<Compile Include="HotspotClickEventArgs.cs" />
<Compile Include="ILoader.cs" />
<Compile Include="IndentView.cs" />
<Compile Include="Indicator.cs" />
Expand Down

0 comments on commit 9664588

Please sign in to comment.