Top | ![]() |
![]() |
![]() |
![]() |
InfTextBufferInfTextBuffer — Interface for the text storage of an InfTextSession |
const gchar * | inf_text_buffer_get_encoding () |
guint | inf_text_buffer_get_length () |
InfTextChunk * | inf_text_buffer_get_slice () |
void | inf_text_buffer_insert_text () |
void | inf_text_buffer_insert_chunk () |
void | inf_text_buffer_erase_text () |
InfTextBufferIter * | inf_text_buffer_create_begin_iter () |
InfTextBufferIter * | inf_text_buffer_create_end_iter () |
void | inf_text_buffer_destroy_iter () |
gboolean | inf_text_buffer_iter_next () |
gboolean | inf_text_buffer_iter_prev () |
gpointer | inf_text_buffer_iter_get_text () |
guint | inf_text_buffer_iter_get_offset () |
guint | inf_text_buffer_iter_get_length () |
gsize | inf_text_buffer_iter_get_bytes () |
guint | inf_text_buffer_iter_get_author () |
void | inf_text_buffer_text_inserted () |
void | inf_text_buffer_text_erased () |
InfTextBuffer is implemented by InfTextDefaultBuffer and InfTextFixlineBuffer.
InfTextBuffer is an interface on top of InfBuffer which represents a text buffer in a similar way as GtkTextBuffer. InfTextBuffer can be used as the buffer of an InfTextSession, allowing the session to insert text written by remote users and access text written by local users and send it to everyone else.
See InfTextDefaultBuffer for a simple implementation based on InfTextChunk. However, in GUI collaborative editing clients this interface should be implemented in a more sophisticated way, such that the text of a document is not stored twice in memory. InfTextGtkBuffer does this for GTK+ based user interfaces.
const gchar *
inf_text_buffer_get_encoding (InfTextBuffer *buffer
);
Returns the character encoding that the buffer uses. This means that all InfTextChunk return values are encoded in this encoding and all InfTextChunk parameters are expected to be encoded in that encoding.
guint
inf_text_buffer_get_length (InfTextBuffer *buffer
);
Returns the number of characters in buffer
.
InfTextChunk * inf_text_buffer_get_slice (InfTextBuffer *buffer
,guint pos
,guint len
);
Reads len
characters, starting at pos
, from the buffer, and returns them
as a InfTextChunk.
void inf_text_buffer_insert_text (InfTextBuffer *buffer
,guint pos
,gconstpointer text
,gsize bytes
,guint len
,InfUser *user
);
Inserts text
into buffer
as written by author
. text
must be encoded in
the character encoding of the buffer, see inf_text_buffer_get_encoding()
.
buffer |
||
pos |
A character offset into |
|
text (type=guint8*) (array length=bytes) (transfer none) |
A pointer to the text to insert. |
|
len |
The length (in characters) of |
|
bytes |
The length (in bytes) of |
|
user |
A InfUser that has inserted the new text, or |
[allow-none] |
void inf_text_buffer_insert_chunk (InfTextBuffer *buffer
,guint pos
,InfTextChunk *chunk
,InfUser *user
);
Inserts a InfTextChunk into buffer
. user
must not necessarily be the
author of chunk
(chunk
may even consist of multiple segments). This
happens when undoing a delete operation that erased another user's text.
buffer |
||
pos |
A character offset into |
|
chunk |
A InfTextChunk. |
[transfer none] |
user |
A InfUser inserting |
[allow-none] |
void inf_text_buffer_erase_text (InfTextBuffer *buffer
,guint pos
,guint len
,InfUser *user
);
Erases characters from the text buffer.
buffer |
||
pos |
The position to begin deleting characters from. |
|
len |
The amount of characters to delete. |
|
user |
A InfUser that erases the text, or |
[allow-none] |
InfTextBufferIter *
inf_text_buffer_create_begin_iter (InfTextBuffer *buffer
);
Creates a InfTextBufferIter pointing to the first segment of buffer
.
A InfTextBufferIter is used to traverse the buffer contents in steps of
so-called segments each of which is written by the same user. The function
returns NULL
if there are no segments (i.e. the buffer is empty).
The iterator stays valid as long as the buffer remains unmodified and
must be freed with inf_text_buffer_destroy_iter()
before.
A InfTextBufferIter to be freed by
inf_text_buffer_destroy_iter()
when done using it, or NULL
.
[transfer full][allow-none]
InfTextBufferIter *
inf_text_buffer_create_end_iter (InfTextBuffer *buffer
);
Creates a InfTextBufferIter pointing to the last segment of buffer
.
A InfTextBufferIter is used to traverse the buffer contents in steps of
so-called segments each of which is written by the same user. The function
returns NULL
if there are no segments (i.e. the buffer is empty).
The iterator stays valid as long as the buffer remains unmodified and
must be freed with inf_text_buffer_destroy_iter()
before.
A InfTextBufferIter to be freed by
inf_text_buffer_destroy_iter()
when done using it, or NULL
.
[transfer full][allow-none]
void inf_text_buffer_destroy_iter (InfTextBuffer *buffer
,InfTextBufferIter *iter
);
Destroys a InfTextBufferIter created by
inf_text_buffer_create_begin_iter()
or inf_text_buffer_create_end_iter()
.
gboolean inf_text_buffer_iter_next (InfTextBuffer *buffer
,InfTextBufferIter *iter
);
Moves iter
to point to the next segment in the buffer. If iter
already
points to the last segment, iter
is left unmodified and the function
returns FALSE
.
gboolean inf_text_buffer_iter_prev (InfTextBuffer *buffer
,InfTextBufferIter *iter
);
Moves iter
to point to the previous segment in the buffer. If iter
already points to the first segment, iter
is left unmodified and the
function returns FALSE
.
gpointer inf_text_buffer_iter_get_text (InfTextBuffer *buffer
,InfTextBufferIter *iter
);
Returns the text of the segment iter
points to. It is encoded in
buffer
's encoding (see inf_text_buffer_get_encoding()
).
guint inf_text_buffer_iter_get_offset (InfTextBuffer *buffer
,InfTextBufferIter *iter
);
Returns the offset of the first character in the segment iter
points
to, in characters.
guint inf_text_buffer_iter_get_length (InfTextBuffer *buffer
,InfTextBufferIter *iter
);
Returns the length of the segment iter
points to, in characters.
gsize inf_text_buffer_iter_get_bytes (InfTextBuffer *buffer
,InfTextBufferIter *iter
);
Returns the length of the segment iter
points to, in bytes.
guint inf_text_buffer_iter_get_author (InfTextBuffer *buffer
,InfTextBufferIter *iter
);
Returns the user ID of the user that has written the segment iter
points
to.
void inf_text_buffer_text_inserted (InfTextBuffer *buffer
,guint pos
,InfTextChunk *chunk
,InfUser *user
);
Emits the “text-inserted” signal. This is meant to be used
by interface implementations in their insert_text
function, or when text
was inserted by other means.
buffer |
||
pos |
A character offset into |
|
chunk |
A InfTextChunk. |
|
user |
A InfUser inserting |
[allow-none] |
void inf_text_buffer_text_erased (InfTextBuffer *buffer
,guint pos
,InfTextChunk *chunk
,InfUser *user
);
Emits the “text-erased” signal. This is meant to be used
by interface implementations in their erase_text
function, or when text
was erased by other means.
buffer |
||
pos |
The position to begin deleting characters from. |
|
chunk |
A InfTextChunk containing the erased text. |
|
user |
A InfUser that erases the text, or |
[allow-none] |
typedef struct _InfTextBuffer InfTextBuffer;
InfTextBuffer is an opaque data type. You should only access it via the public API functions.
struct InfTextBufferInterface { /* Virtual table */ const gchar* (*get_encoding)(InfTextBuffer* buffer); guint(*get_length)(InfTextBuffer* buffer); InfTextChunk*(*get_slice)(InfTextBuffer* buffer, guint pos, guint len); void(*insert_text)(InfTextBuffer* buffer, guint pos, InfTextChunk* chunk, InfUser* user); void(*erase_text)(InfTextBuffer* buffer, guint pos, guint len, InfUser* user); InfTextBufferIter*(*create_begin_iter)(InfTextBuffer* buffer); InfTextBufferIter*(*create_end_iter)(InfTextBuffer* buffer); void(*destroy_iter)(InfTextBuffer* buffer, InfTextBufferIter* iter); gboolean(*iter_next)(InfTextBuffer* buffer, InfTextBufferIter* iter); gboolean(*iter_prev)(InfTextBuffer* buffer, InfTextBufferIter* iter); gpointer(*iter_get_text)(InfTextBuffer* buffer, InfTextBufferIter* iter); guint(*iter_get_offset)(InfTextBuffer* buffer, InfTextBufferIter* iter); guint(*iter_get_length)(InfTextBuffer* buffer, InfTextBufferIter* iter); gsize(*iter_get_bytes)(InfTextBuffer* buffer, InfTextBufferIter* iter); guint(*iter_get_author)(InfTextBuffer* buffer, InfTextBufferIter* iter); /* Signals */ void(*text_inserted)(InfTextBuffer* buffer, guint pos, InfTextChunk* chunk, InfUser* user); void(*text_erased)(InfTextBuffer* buffer, guint pos, InfTextChunk* chunk, InfUser* user); };
This structure contains virtual functions and signal handlers of the InfTextBuffer interface.
Virtual function which returns the character coding of the buffer. |
||
Virtual function to return the total length of the text in the buffer, in characters. |
||
Virtual function to extract a slice of text from the buffer. |
||
Virtual function to insert text into the buffer. |
||
Virtual function to remove text from the buffer. |
||
Virtual function to create a InfTextBufferIter at the beginning of the buffer, used for traversing through buffer segments. |
||
Virtual function to create a InfTextBufferIter at the end of the buffer, used for traversing through buffer segments. |
||
Virtual function to destroy an iterator created with
the |
||
Virtual function to advance a InfTextBufferIter to the next segment. |
||
Virtual function to retreat a InfTextBufferIter to the previous segment. |
||
Virtual function to obtain the text of a segment a InfTextBufferIter points to. |
||
Virtual function to obtain the offset of the first character in the segment a InfTextBufferIter points to. |
||
Virtual function to obtain the length of a segment a InfTextBufferIter points to. |
||
Virtual function to obtain the number of bytes in a segment a InfTextBufferIter points to. |
||
Virtual function to obtain the author of the segment a InfTextBufferIter points to. |
||
Default signal handler of the “text-inserted” signal. |
||
Default signal handler of the “text-erased” signal. |
typedef struct _InfTextBufferIter InfTextBufferIter;
InfTextBufferIter is an opaque data type. You should only access it via the public API functions.
“text-erased”
signalvoid user_function (InfTextBuffer *inftextbuffer, guint arg1, InfTextChunk *arg2, InfUser *arg3, gpointer user_data)
Flags: Run First
“text-inserted”
signalvoid user_function (InfTextBuffer *inftextbuffer, guint arg1, InfTextChunk *arg2, InfUser *arg3, gpointer user_data)
Flags: Run First