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

Add methods for Substyles #443

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions src/ScintillaNET/Scintilla.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ public unsafe void AddText(string text)
DirectMessage(NativeMethods.SCI_ADDTEXT, new IntPtr(bytes.Length), new IntPtr(bp));
}

/// <summary>
/// Allocates some number of substyles for a particular base style. Substyles are allocated contiguously.
/// </summary>
/// <param name="styleBase">The lexer style integer</param>
/// <param name="numberStyles">The amount of substyles to allocate</param>
/// <returns>Returns the first substyle number allocated.</returns>
public int AllocateSubstyles(int styleBase, int numberStyles)
{
return this.DirectMessage(NativeMethods.SCI_ALLOCATESUBSTYLES, new IntPtr(styleBase), new IntPtr(numberStyles)).ToInt32();
}

/// <summary>
/// Removes the annotation text for every <see cref="Line" /> in the document.
/// </summary>
Expand Down Expand Up @@ -891,6 +902,14 @@ public void FoldDisplayTextSetStyle(FoldDisplayText style)
DirectMessage(NativeMethods.SCI_FOLDDISPLAYTEXTSETSTYLE, new IntPtr((int)style));
}

/// <summary>
/// Frees all allocated substyles.
/// </summary>
public void FreeSubstyles()
{
DirectMessage(NativeMethods.SCI_FREESUBSTYLES);
}

/// <summary>
/// Returns the character as the specified document position.
/// </summary>
Expand Down Expand Up @@ -1014,6 +1033,16 @@ private static string GetModulePath()
return modulePath;
}

/// <summary>
/// Gets the Primary style associated with the given Secondary style.
/// </summary>
/// <param name="style">The secondary style</param>
/// <returns>For a secondary style, return the primary style, else return the argument.</returns>
public int GetPrimaryStyleFromStyle(int style)
{
return DirectMessage(NativeMethods.SCI_GETPRIMARYSTYLEFROMSTYLE, new IntPtr(style)).ToInt32();
}

/// <summary>
/// Lookup a property value for the current <see cref="Lexer" />.
/// </summary>
Expand Down Expand Up @@ -1107,6 +1136,36 @@ public int GetStyleAt(int position)
return DirectMessage(NativeMethods.SCI_GETSTYLEAT, new IntPtr(position)).ToInt32();
}

/// <summary>
/// Gets the lexer base style of a substyle.
/// </summary>
/// <param name="subStyle">The integer index of the substyle</param>
/// <returns>Returns the base style, else returns the argument.</returns>
public int GetStyleFromSubstyle(int subStyle)
{
return DirectMessage(NativeMethods.SCI_GETSTYLEFROMSUBSTYLE, new IntPtr(subStyle)).ToInt32();
}

/// <summary>
/// Gets the length of the number of substyles allocated for a given lexer base style.
/// </summary>
/// <param name="styleBase">The lexer style integer</param>
/// <returns>Returns the length of the substyles allocated for a base style.</returns>
public int GetSubstylesLength(int styleBase)
{
return DirectMessage(NativeMethods.SCI_GETSUBSTYLESLENGTH, new IntPtr(styleBase)).ToInt32();
}

/// <summary>
/// Gets the start index of the substyles for a given lexer base style.
/// </summary>
/// <param name="styleBase">The lexer style integer</param>
/// <returns>Returns the start of the substyles allocated for a base style.</returns>
public int GetSubstylesStart(int styleBase)
{
return DirectMessage(NativeMethods.SCI_GETSUBSTYLESSTART, new IntPtr(styleBase)).ToInt32();
}

/// <summary>
/// Returns the capture group text of the most recent regular expression search.
/// </summary>
Expand Down Expand Up @@ -2291,6 +2350,25 @@ public void SetFoldMarginHighlightColor(bool use, Color color)
DirectMessage(NativeMethods.SCI_SETFOLDMARGINHICOLOUR, useFoldMarginHighlightColour, new IntPtr(colour));
}

/// <summary>
/// Similar to <see cref="SetKeywords" /> but for substyles.
/// </summary>
/// <param name="style">The substyle integer index</param>
/// <param name="identifiers">A list of words separated by whitespace (space, tab, '\n', '\r') characters.</param>
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));
}

/// <summary>
/// Updates a keyword set used by the current <see cref="Lexer" />.
/// </summary>
Expand Down Expand Up @@ -3866,6 +3944,20 @@ protected override Size DefaultSize
}
}

/// <summary>
/// Gets a value indicating the start index of the secondary styles.
/// </summary>
/// <returns>Returns the distance between a primary style and its corresponding secondary style.</returns>
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public int DistanceToSecondaryStyles
{
get
{
return DirectMessage(NativeMethods.SCI_DISTANCETOSECONDARYSTYLES).ToInt32();
}
}

/// <summary>
/// Gets or sets the current document used by the control.
/// </summary>
Expand Down