-
Notifications
You must be signed in to change notification settings - Fork 1
/
InsertCheckEventArgs.cs
100 lines (92 loc) · 3.92 KB
/
InsertCheckEventArgs.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// ***********************************************************************
// Assembly : Zeroit.Framework.CodeBox
// Author : ZEROIT
// Created : 03-19-2019
//
// Last Modified By : ZEROIT
// Last Modified On : 01-05-2019
// ***********************************************************************
// <copyright file="InsertCheckEventArgs.cs" company="Zeroit Dev">
// This program is for creating a Code Editor control.
// Copyright © 2017 Zeroit Dev Technologies
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// You can contact me at zeroitdevnet@gmail.com or zeroitdev@outlook.com
// </copyright>
// <summary></summary>
// ***********************************************************************
using System;
namespace Zeroit.Framework.CodeBox
{
/// <summary>
/// Provides data for the <see cref="Scintilla.InsertCheck" /> event.
/// </summary>
public class InsertCheckEventArgs : EventArgs
{
private readonly ZeroitCodeExplorer Scintilla;
private readonly int bytePosition;
private readonly int byteLength;
private readonly IntPtr textPtr;
internal int? CachedPosition { get; set; }
internal string CachedText { get; set; }
/// <summary>
/// Gets the zero-based document position where text will be inserted.
/// </summary>
/// <returns>The zero-based character position within the document where text will be inserted.</returns>
public int Position
{
get
{
if (CachedPosition == null)
CachedPosition = Scintilla.Lines.ByteToCharPosition(bytePosition);
return (int)CachedPosition;
}
}
/// <summary>
/// Gets or sets the text being inserted.
/// </summary>
/// <returns>The text being inserted into the document.</returns>
public unsafe string Text
{
get
{
if (CachedText == null)
CachedText = Helpers.GetString(textPtr, byteLength, Scintilla.Encoding);
return CachedText;
}
set
{
CachedText = value ?? string.Empty;
var bytes = Helpers.GetBytes(CachedText, Scintilla.Encoding, zeroTerminated: false);
fixed (byte* bp = bytes)
Scintilla.DirectMessage(NativeMethods.SCI_CHANGEINSERTION, new IntPtr(bytes.Length), new IntPtr(bp));
}
}
/// <summary>
/// Initializes a new instance of the <see cref="InsertCheckEventArgs" /> class.
/// </summary>
/// <param name="Scintilla">The <see cref="Scintilla" /> control that generated this event.</param>
/// <param name="bytePosition">The zero-based byte position within the document where text is being inserted.</param>
/// <param name="byteLength">The length in bytes of the inserted text.</param>
/// <param name="text">A pointer to the text being inserted.</param>
public InsertCheckEventArgs(ZeroitCodeExplorer Scintilla, int bytePosition, int byteLength, IntPtr text)
{
this.Scintilla = Scintilla;
this.bytePosition = bytePosition;
this.byteLength = byteLength;
this.textPtr = text;
}
}
}