Skip to content

Commit

Permalink
Merge pull request #3 from bobhodge/master
Browse files Browse the repository at this point in the history
Implemented horizontal scrolling sync; plus mousewheel scrolling
  • Loading branch information
Petteri Kautonen authored Apr 25, 2020
2 parents 1646b9d + f1da113 commit 20ea732
Showing 1 changed file with 53 additions and 10 deletions.
63 changes: 53 additions & 10 deletions ScintillaDiff/ScrollSyncScintilla.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#endregion

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using ScintillaNET;

Expand All @@ -40,7 +37,7 @@ namespace ScintillaDiff
/// Implements the <see cref="ScintillaNET.Scintilla" />
/// </summary>
/// <seealso cref="ScintillaNET.Scintilla" />
public class ScrollSyncScintilla: Scintilla
public class ScrollSyncScintilla : Scintilla
{
// ReSharper disable once CommentTypo
/// <summary>
Expand All @@ -50,25 +47,71 @@ public class ScrollSyncScintilla: Scintilla
/// https://docs.microsoft.com/en-us/windows/desktop/controls/wm-vscroll
/// </remarks>
/// </summary>
const int WM_VSCROLL = 0x115;
// ReSharper disable once InconsistentNaming
private const int WM_VSCROLL = 0x115;
// ReSharper disable once CommentTypo
/// <summary>
/// The WM_HSCROLL message is sent to a window when a scroll event occurs in the window's standard horizontal scroll bar.
/// This message is also sent to the owner of a horizontal scroll bar control when a scroll event occurs in the control.
/// <remarks>
/// https://docs.microsoft.com/en-us/windows/desktop/controls/wm-hscroll
/// </remarks>
/// </summary>
// ReSharper disable once InconsistentNaming
private const int WM_HSCROLL = 0x114;
/// <summary>
/// The WM_MOUSEWHEEL message is Sent to the focus window when the mouse wheel is rotated.
/// <remarks>
/// https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-mousewheel
/// </remarks>
/// </summary>
// ReSharper disable once InconsistentNaming
private const int WM_MOUSEWHEEL = 0x20a;

/// <summary>
/// The SendMessage Win32 function is used to send a specified message to a window or windows.
/// <remarks>
/// https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessage
/// </remarks>
/// </summary>
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);

/// <summary>
/// Processes Windows messages.
/// </summary>
/// <param name="m">The Windows Message to process.</param>
protected override void WndProc(ref Message m)
{
// ReSharper disable once CommentTypo
// capture the WM_VSCROLL message..
if (m.Msg == WM_MOUSEWHEEL)
{
// two casts to make this work with 32 bit and 64 bit params
var wp = new IntPtr((int)(long)m.WParam < 0 ? 1 : 0);
SendMessage(this.Handle, WM_VSCROLL, wp, new IntPtr(0));
return;
}

base.WndProc(ref m);

// vertical scrolling
if (m.Msg == WM_VSCROLL && ScrollSync != null)
{
// get the first visible line of this control..
int scrollTop = FirstVisibleLine;

// set the value to the another Scintilla control..
// set the value to the other Scintilla control..
ScrollSync.FirstVisibleLine = scrollTop;
}
base.WndProc(ref m);

// horizontal scrolling
if (m.Msg == WM_HSCROLL && ScrollSync != null)
{
// get the leftmost pixel
int scrollLeft = XOffset;

// set the value to the other Scintilla control..
ScrollSync.XOffset = scrollLeft;
}
}

/// <summary>
Expand Down

0 comments on commit 20ea732

Please sign in to comment.