From 75453e4a50e7f7b4a7495aa2df512fee810dc397 Mon Sep 17 00:00:00 2001 From: toehead2001 Date: Fri, 5 Apr 2019 19:53:54 -0600 Subject: [PATCH] Add methods for Substyles --- src/ScintillaNET/Scintilla.cs | 92 +++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/src/ScintillaNET/Scintilla.cs b/src/ScintillaNET/Scintilla.cs index d71b722..3cf9f47 100644 --- a/src/ScintillaNET/Scintilla.cs +++ b/src/ScintillaNET/Scintilla.cs @@ -142,6 +142,17 @@ public unsafe void AddText(string text) DirectMessage(NativeMethods.SCI_ADDTEXT, new IntPtr(bytes.Length), new IntPtr(bp)); } + /// + /// Allocates some number of substyles for a particular base style. Substyles are allocated contiguously. + /// + /// The lexer style integer + /// The amount of substyles to allocate + /// Returns the first substyle number allocated. + public int AllocateSubstyles(int styleBase, int numberStyles) + { + return this.DirectMessage(NativeMethods.SCI_ALLOCATESUBSTYLES, new IntPtr(styleBase), new IntPtr(numberStyles)).ToInt32(); + } + /// /// Removes the annotation text for every in the document. /// @@ -891,6 +902,14 @@ public void FoldDisplayTextSetStyle(FoldDisplayText style) DirectMessage(NativeMethods.SCI_FOLDDISPLAYTEXTSETSTYLE, new IntPtr((int)style)); } + /// + /// Frees all allocated substyles. + /// + public void FreeSubstyles() + { + DirectMessage(NativeMethods.SCI_FREESUBSTYLES); + } + /// /// Returns the character as the specified document position. /// @@ -1014,6 +1033,16 @@ private static string GetModulePath() return modulePath; } + /// + /// Gets the Primary style associated with the given Secondary style. + /// + /// The secondary style + /// For a secondary style, return the primary style, else return the argument. + public int GetPrimaryStyleFromStyle(int style) + { + return DirectMessage(NativeMethods.SCI_GETPRIMARYSTYLEFROMSTYLE, new IntPtr(style)).ToInt32(); + } + /// /// Lookup a property value for the current . /// @@ -1107,6 +1136,36 @@ public int GetStyleAt(int position) return DirectMessage(NativeMethods.SCI_GETSTYLEAT, new IntPtr(position)).ToInt32(); } + /// + /// Gets the lexer base style of a substyle. + /// + /// The integer index of the substyle + /// Returns the base style, else returns the argument. + public int GetStyleFromSubstyle(int subStyle) + { + return DirectMessage(NativeMethods.SCI_GETSTYLEFROMSUBSTYLE, new IntPtr(subStyle)).ToInt32(); + } + + /// + /// Gets the length of the number of substyles allocated for a given lexer base style. + /// + /// The lexer style integer + /// Returns the length of the substyles allocated for a base style. + public int GetSubstylesLength(int styleBase) + { + return DirectMessage(NativeMethods.SCI_GETSUBSTYLESLENGTH, new IntPtr(styleBase)).ToInt32(); + } + + /// + /// Gets the start index of the substyles for a given lexer base style. + /// + /// The lexer style integer + /// Returns the start of the substyles allocated for a base style. + public int GetSubstylesStart(int styleBase) + { + return DirectMessage(NativeMethods.SCI_GETSUBSTYLESSTART, new IntPtr(styleBase)).ToInt32(); + } + /// /// Returns the capture group text of the most recent regular expression search. /// @@ -2291,6 +2350,25 @@ public void SetFoldMarginHighlightColor(bool use, Color color) DirectMessage(NativeMethods.SCI_SETFOLDMARGINHICOLOUR, useFoldMarginHighlightColour, new IntPtr(colour)); } + /// + /// Similar to but for substyles. + /// + /// The substyle integer index + /// A list of words separated by whitespace (space, tab, '\n', '\r') characters. + public unsafe void SetIdentifiers(int style, string identifiers) + { + var baseStyle = GetStyleFromSubstyle(style); + var min = GetSubstylesStart(baseStyle); + var length = GetSubstylesLength(baseStyle); + var max = (length > 0) ? min + length - 1 : min; + + style = Helpers.Clamp(style, min, max); + var bytes = Helpers.GetBytes(identifiers ?? string.Empty, Encoding.ASCII, zeroTerminated: true); + + fixed (byte* bp = bytes) + DirectMessage(NativeMethods.SCI_SETIDENTIFIERS, new IntPtr(style), new IntPtr(bp)); + } + /// /// Updates a keyword set used by the current . /// @@ -3866,6 +3944,20 @@ protected override Size DefaultSize } } + /// + /// Gets a value indicating the start index of the secondary styles. + /// + /// Returns the distance between a primary style and its corresponding secondary style. + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public int DistanceToSecondaryStyles + { + get + { + return DirectMessage(NativeMethods.SCI_DISTANCETOSECONDARYSTYLES).ToInt32(); + } + } + /// /// Gets or sets the current document used by the control. ///