-
Notifications
You must be signed in to change notification settings - Fork 0
/
EntryBuffer.cs
112 lines (96 loc) · 4.06 KB
/
EntryBuffer.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
101
102
103
104
105
106
107
108
109
110
111
112
using System;
namespace Gtk3
{
/// <summary>
/// The EntryBuffer class contains the actual text displayed in the
/// Entry widget.
/// A single EntryBuffer object can be shared by multiple Entry widgets
/// that will then share the same text content, but not the cursor position,
/// visibility attributes, icon, etc.
/// </summary>
public class EntryBuffer
{
private readonly IntPtr _instance;
/// <summary>
/// Creates a new instance of an EntryBufferObject.
/// </summary>
/// <param name="initialCharacter">The text to show in the initial buffer, or null</param>
/// <param name="numberOfInitialCharacters">The number of characters in initialCharacter, or -1</param>
public EntryBuffer(string initialCharacter, int numberOfInitialCharacters) {
_instance = Native.GtkEntryBuffer.gtk_entry_buffer_new(initialCharacter, numberOfInitialCharacters);
}
/// <summary>
/// Constructs a new EntryBuffer from an existing IntPtr to an entry buffer.
/// </summary>
/// <param name="buffer">The buffer to wrap the EntryBuffer around.</param>
internal EntryBuffer(IntPtr buffer)
{
_instance = buffer;
}
/// <summary>
/// Inserts `numberOfChars` characters of `text` into the contents of the
/// buffer, at position `position`.
///
// If `numberOfChars` is negative, then characters from text will be inserted
// until a null-terminator is found. If `position` or `numberOfChars` are out of
// bounds, or the maximum buffer text length is exceeded, then they are
// coerced to sane values.
/// </summary>
/// <param name="position">the position at which to insert text.</param>
/// <param name="text">the text to insert into the buffer.</param>
/// <param name="numberOfChars">the length of the text in characters, or -1</param>
/// <remarks>Note that the position and length are in characters, not in bytes.</remarks>
/// <returns>The number of characters actually inserted.</returns>
public uint InsertText(uint position, string text, int numberOfChars = -1)
{
return Native.GtkEntryBuffer.gtk_entry_buffer_insert_text(Handle,
position, text, numberOfChars);
}
/// <summary>
/// Deletes a sequence of characters from the buffer. `numberOfChars` characters
/// are deleted starting at `position` . If `numberOfChars` is negative, then
/// all characters until the end of the text are deleted.
/// If `position` or `numberOfChars` are out of bounds, then they are
/// coerced to sane values.
/// </summary>
/// <param name="position">position at which to delete text.</param>
/// <param name="numberOfChars">number of characters to delete</param>
/// <remarks>Note that the positions are specified in characters, not bytes.</remarks>
/// <returns>The number of characters deleted.</returns>
public uint DeleteText(uint position, int numberOfChars)
{
return Native.GtkEntryBuffer.gtk_entry_buffer_delete_text(Handle,
position, numberOfChars);
}
/// <summary>
/// Gets or sets the maximum allowed length of text in the buffer.
/// </summary>
/// <remarks>
/// A returned value of 0 indicates that there is no maximum.
/// When setting the maximum length, if the current contents of the buffer
/// is longer than the new maximum then they are truncated to fit.
/// The maximum length passed in is clamped to the range 0-65536.
/// </remarks>
public int MaxLength {
get => Native.GtkEntryBuffer.gtk_entry_buffer_get_max_length(Handle);
set => Native.GtkEntryBuffer.gtk_entry_buffer_set_max_length(Handle, value);
}
/// <summary>
/// Gets or sets the text in the buffer.
/// </summary>
public string Text {
get => Native.GtkEntryBuffer.gtk_entry_buffer_get_text(Handle);
set {
var numberOfCharacters = -1;
if (value != null)
{
numberOfCharacters = value.Length;
}
Native.GtkEntryBuffer.gtk_entry_buffer_set_text(Handle, value, numberOfCharacters);
}
}
public uint Bytes => Native.GtkEntryBuffer.gtk_entry_buffer_get_bytes(Handle);
public uint Length => Native.GtkEntryBuffer.gtk_entry_buffer_get_length(Handle);
public IntPtr Handle => _instance;
}
}