Skip to content

Commit

Permalink
Merge pull request #25 from adamstyl/line-layer-api
Browse files Browse the repository at this point in the history
Added support for setting the caret and the selection layer. Thanks @adamstyl !
  • Loading branch information
Petteri Kautonen authored Oct 31, 2022
2 parents af15e80 + e7f3341 commit cf59dbc
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Scintilla.NET/Scintilla.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@
<Compile Include="..\Shared\IndicatorReleaseEventArgs.cs" Link="IndicatorReleaseEventArgs.cs" />
<Compile Include="..\Shared\IndicatorStyle.cs" Link="IndicatorStyle.cs" />
<Compile Include="..\Shared\InsertCheckEventArgs.cs" Link="InsertCheckEventArgs.cs" />
<Compile Include="..\Shared\Layer.cs">
<Link>Layer.cs</Link>
</Compile>
<Compile Include="..\Shared\Lexer.cs" Link="Lexer.cs" />
<Compile Include="..\Shared\Line.cs" Link="Line.cs" />
<Compile Include="..\Shared\LineCollection.cs" Link="LineCollection.cs" />
Expand Down
23 changes: 23 additions & 0 deletions Shared/Layer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace ScintillaNET;

/// <summary>
/// The layer on which a <see cref="Scintilla"/> control will draw elements like for example the text selection.
/// </summary>
public enum Layer
{
/// <summary>
/// Draw the selection background opaquely on the base layer.
/// </summary>
Base = NativeMethods.SC_LAYER_BASE,

/// <summary>
/// Draw the selection background translucently under the text. This will not work in single phase drawing mode.
/// (<see cref="Phases.One"/>) as there is no under-text phase.
/// </summary>
UnderText = NativeMethods.SC_LAYER_UNDER_TEXT,

/// <summary>
/// Draw the selection background translucently over the text.
/// </summary>
OverText = NativeMethods.SC_LAYER_OVER_TEXT
}
11 changes: 10 additions & 1 deletion Shared/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ internal static class NativeMethods
// Line end type
public const int SC_LINE_END_TYPE_DEFAULT = 0;
public const int SC_LINE_END_TYPE_UNICODE = 1;

//Line layers
public const int SC_LAYER_BASE = 0;
public const int SC_LAYER_UNDER_TEXT = 1;
public const int SC_LAYER_OVER_TEXT = 2;

// Margins
public const int SC_MAX_MARGIN = 4;
Expand Down Expand Up @@ -953,6 +958,10 @@ internal static class NativeMethods
public const int SCI_FOLDDISPLAYTEXTSETSTYLE = 2701;
public const int SCI_GETCARETLINEFRAME = 2704;
public const int SCI_SETCARETLINEFRAME = 2705;
public const int SCI_GETSELECTIONLAYER = 2762;
public const int SCI_SETSELECTIONLAYER = 2763;
public const int SCI_GETCARETLINELAYER = 2764;
public const int SCI_SETCARETLINELAYER = 2765;
public const int SCI_STARTRECORD = 3001;
public const int SCI_STOPRECORD = 3002;
public const int SCI_SETLEXER = 4001;
Expand Down Expand Up @@ -2222,4 +2231,4 @@ public struct SCNotification
}

#endregion Structures
}
}
40 changes: 39 additions & 1 deletion Shared/Scintilla.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2677,6 +2677,25 @@ public void SetSelectionForeColor(bool use, Color color)
DirectMessage(NativeMethods.SCI_SETSELFORE, useSelectionForeColour, new IntPtr(colour));
}

/// <summary>
/// Gets or sets the layer where the text selection will be painted. Default value is <see cref="Layer.Base"/>
/// </summary>
[DefaultValue(Layer.Base)]
[Category("Selection")]
[Description("The layer where the text selection will be painted.")]
public Layer SelectionLayer
{
get
{
return (Layer)DirectMessage(NativeMethods.SCI_GETSELECTIONLAYER).ToInt32();
}
set
{
int layer = (int)value;
DirectMessage(NativeMethods.SCI_SETSELECTIONLAYER, new IntPtr(layer), IntPtr.Zero);
}
}

/// <summary>
/// Styles the specified length of characters.
/// </summary>
Expand Down Expand Up @@ -4024,6 +4043,25 @@ public bool CaretLineVisibleAlways
}
}

/// <summary>
/// Gets or sets the layer where the line caret will be painted. Default value is <see cref="Layer.Base"/>
/// </summary>
[DefaultValue(Layer.Base)]
[Category("Caret")]
[Description("The layer where the line caret will be painted.")]
public Layer CaretLineLayer
{
get
{
return (Layer)DirectMessage(NativeMethods.SCI_GETCARETLINELAYER).ToInt32();
}
set
{
int layer = (int)value;
DirectMessage(NativeMethods.SCI_SETCARETLINELAYER, new IntPtr(layer));
}
}

/// <summary>
/// Gets or sets the caret blink rate in milliseconds.
/// </summary>
Expand Down Expand Up @@ -6866,4 +6904,4 @@ public Scintilla()
[Obsolete("Not used by the Scintilla.NET control.")]
public new RightToLeft RightToLeft { get; set; }
}
}
}

0 comments on commit cf59dbc

Please sign in to comment.