Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.

Commit b93cf7b

Browse files
author
Savas Ziplies
committed
Added: GetScrollInfo() method to grab scroll information from the current Scintilla instance (@see jacobslusser/ScintillaNET#158)
1 parent 62b7eb7 commit b93cf7b

File tree

3 files changed

+106
-1
lines changed

3 files changed

+106
-1
lines changed

Visual Studio Project Template C#/PluginInfrastructure/IScintillaGateway.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// NPP plugin platform for .Net v0.93.87 by Kasper B. Graversen etc.
2-
using System;
2+
3+
using static Kbg.NppPluginNET.PluginInfrastructure.Win32;
34

45
namespace Kbg.NppPluginNET.PluginInfrastructure
56
{
@@ -23,6 +24,13 @@ public interface IScintillaGateway
2324
/// </summary>
2425
int GetCurrentLineNumber();
2526

27+
/// <summary>
28+
/// Get the scroll information for the current Scintilla window.
29+
/// </summary>
30+
/// <param name="mask">Argumetns for the scroll information such as tracking</param>
31+
/// <param name="scrollBar">Which scroll bar information are you looking for</param>
32+
/// <returns>A ScrollInfo struct with information of the current scroll state</returns>
33+
ScrollInfo GetScrollInfo(ScrollInfoMask mask, ScrollInfoBar scrollBar);
2634

2735
/* ++Autogenerated -- start of section automatically generated from Scintilla.iface */
2836
/// <summary>Add text to the document at current position. (Scintilla feature 2001)</summary>

Visual Studio Project Template C#/PluginInfrastructure/ScintillaGateway.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// NPP plugin platform for .Net v0.93.87 by Kasper B. Graversen etc.
22
using System;
3+
using System.Runtime.InteropServices;
34
using System.Text;
5+
using static Kbg.NppPluginNET.PluginInfrastructure.Win32;
46

57
namespace Kbg.NppPluginNET.PluginInfrastructure
68
{
@@ -66,6 +68,21 @@ public int GetCurrentLineNumber()
6668
return LineFromPosition(GetCurrentPos());
6769
}
6870

71+
/// <summary>
72+
/// Get the scroll information for the current Scintilla window.
73+
/// </summary>
74+
/// <param name="mask">Argumetns for the scroll information such as tracking</param>
75+
/// <param name="scrollBar">Which scroll bar information are you looking for</param>
76+
/// <returns>A ScrollInfo struct with information of the current scroll state</returns>
77+
public ScrollInfo GetScrollInfo(ScrollInfoMask mask, ScrollInfoBar scrollBar)
78+
{
79+
ScrollInfo scrollInfo = new ScrollInfo();
80+
scrollInfo.cbSize = (uint)Marshal.SizeOf(scrollInfo);
81+
scrollInfo.fMask = (uint)mask;
82+
Win32.GetScrollInfo(scintilla, (int)scrollBar, ref scrollInfo);
83+
return scrollInfo;
84+
}
85+
6986
/* ++Autogenerated -- start of section automatically generated from Scintilla.iface */
7087
/// <summary>Add text to the document at current position. (Scintilla feature 2001)</summary>
7188
public unsafe void AddText(int length, string text)

Visual Studio Project Template C#/PluginInfrastructure/Win32.cs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,76 @@ namespace Kbg.NppPluginNET.PluginInfrastructure
88
{
99
public class Win32
1010
{
11+
/// <summary>
12+
/// Get the scroll information of a scroll bar or window with scroll bar
13+
/// @see https://msdn.microsoft.com/en-us/library/windows/desktop/bb787537(v=vs.85).aspx
14+
/// </summary>
15+
[StructLayout(LayoutKind.Sequential)]
16+
public struct ScrollInfo
17+
{
18+
/// <summary>
19+
/// Specifies the size, in bytes, of this structure. The caller must set this to sizeof(SCROLLINFO).
20+
/// </summary>
21+
public uint cbSize;
22+
/// <summary>
23+
/// Specifies the scroll bar parameters to set or retrieve.
24+
/// @see ScrollInfoMask
25+
/// </summary>
26+
public uint fMask;
27+
/// <summary>
28+
/// Specifies the minimum scrolling position.
29+
/// </summary>
30+
public int nMin;
31+
/// <summary>
32+
/// Specifies the maximum scrolling position.
33+
/// </summary>
34+
public int nMax;
35+
/// <summary>
36+
/// Specifies the page size, in device units. A scroll bar uses this value to determine the appropriate size of the proportional scroll box.
37+
/// </summary>
38+
public uint nPage;
39+
/// <summary>
40+
/// Specifies the position of the scroll box.
41+
/// </summary>
42+
public int nPos;
43+
/// <summary>
44+
/// Specifies the immediate position of a scroll box that the user is dragging.
45+
/// An application can retrieve this value while processing the SB_THUMBTRACK request code.
46+
/// An application cannot set the immediate scroll position; the SetScrollInfo function ignores this member.
47+
/// </summary>
48+
public int nTrackPos;
49+
}
50+
51+
/// <summary>
52+
/// Used for the ScrollInfo fMask
53+
/// SIF_ALL => Combination of SIF_PAGE, SIF_POS, SIF_RANGE, and SIF_TRACKPOS.
54+
/// SIF_DISABLENOSCROLL => This value is used only when setting a scroll bar's parameters. If the scroll bar's new parameters make the scroll bar unnecessary, disable the scroll bar instead of removing it.
55+
/// SIF_PAGE => The nPage member contains the page size for a proportional scroll bar.
56+
/// SIF_POS => The nPos member contains the scroll box position, which is not updated while the user drags the scroll box.
57+
/// SIF_RANGE => The nMin and nMax members contain the minimum and maximum values for the scrolling range.
58+
/// SIF_TRACKPOS => The nTrackPos member contains the current position of the scroll box while the user is dragging it.
59+
/// </summary>
60+
public enum ScrollInfoMask
61+
{
62+
SIF_RANGE = 0x1,
63+
SIF_PAGE = 0x2,
64+
SIF_POS = 0x4,
65+
SIF_DISABLENOSCROLL = 0x8,
66+
SIF_TRACKPOS = 0x10,
67+
SIF_ALL = SIF_RANGE + SIF_PAGE + SIF_POS + SIF_TRACKPOS
68+
}
69+
70+
/// <summary>
71+
/// Used for the GetScrollInfo() nBar parameter
72+
/// </summary>
73+
public enum ScrollInfoBar
74+
{
75+
SB_HORZ = 0,
76+
SB_VERT = 1,
77+
SB_CTL = 2,
78+
SB_BOTH = 3
79+
}
80+
1181
/// <summary>
1282
/// You should try to avoid calling this method in your plugin code. Rather use one of the gateways such as
1383
/// <see cref="ScintillaGateway"/> or <see cref="NotepadPPGateway"/>.
@@ -185,5 +255,15 @@ public class Win32
185255

186256
[DllImport("kernel32")]
187257
public static extern void OutputDebugString(string lpOutputString);
258+
259+
/// <summary>
260+
/// @see https://msdn.microsoft.com/en-us/library/windows/desktop/bb787583(v=vs.85).aspx
261+
/// </summary>
262+
/// <param name="hwnd"></param>
263+
/// <param name="nBar"></param>
264+
/// <param name="scrollInfo"></param>
265+
/// <returns></returns>
266+
[DllImport("user32")]
267+
public static extern int GetScrollInfo(IntPtr hwnd, int nBar, ref ScrollInfo scrollInfo);
188268
}
189269
}

0 commit comments

Comments
 (0)