2001-08-02 01:24:49 +04:00
|
|
|
//
|
|
|
|
// Header file for Fl_Text_Buffer class.
|
|
|
|
//
|
2023-02-10 19:13:20 +03:00
|
|
|
// Copyright 2001-2023 by Bill Spitzak and others.
|
2002-01-01 18:11:33 +03:00
|
|
|
// Original code Copyright Mark Edel. Permission to distribute under
|
|
|
|
// the LGPL for the FLTK library granted by Mark Edel.
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
// file is missing or damaged, see the license at:
|
2011-07-19 08:49:30 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/COPYING.php
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// Please see the following page on how to report bugs and issues:
|
2005-04-16 04:13:17 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/bugs.php
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
|
|
|
|
2008-10-15 17:46:06 +04:00
|
|
|
/* \file
|
2010-04-05 23:52:52 +04:00
|
|
|
Fl_Text_Buffer, Fl_Text_Selection widget . */
|
2008-09-16 11:26:22 +04:00
|
|
|
|
2001-08-02 01:24:49 +04:00
|
|
|
#ifndef FL_TEXT_BUFFER_H
|
|
|
|
#define FL_TEXT_BUFFER_H
|
|
|
|
|
2021-03-20 23:39:28 +03:00
|
|
|
#include <stdarg.h> /* va_list */
|
2023-02-10 18:14:30 +03:00
|
|
|
#include "fl_attr.h" /* Doxygen can't find <FL/fl_attr.h> */
|
2010-11-06 17:29:12 +03:00
|
|
|
|
2010-12-06 21:22:22 +03:00
|
|
|
#undef ASSERT_UTF8
|
2010-11-06 17:29:12 +03:00
|
|
|
|
|
|
|
#ifdef ASSERT_UTF8
|
|
|
|
# include <assert.h>
|
|
|
|
# define IS_UTF8_ALIGNED(a) if (a && *a) assert(fl_utf8len(*(a))>0);
|
2010-11-07 02:58:57 +03:00
|
|
|
# define IS_UTF8_ALIGNED2(a, b) if (b>=0 && b<a->length()) assert(fl_utf8len(a->byte_at(b))>0);
|
2010-11-06 17:29:12 +03:00
|
|
|
#else
|
|
|
|
# define IS_UTF8_ALIGNED(a)
|
2010-11-07 02:58:57 +03:00
|
|
|
# define IS_UTF8_ALIGNED2(a, b)
|
2010-11-06 17:29:12 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2010-04-05 16:45:03 +04:00
|
|
|
/*
|
|
|
|
"character size" is the size of a UTF-8 character in bytes
|
2016-01-28 20:16:32 +03:00
|
|
|
"character width" is the width of a Unicode character in pixels
|
2023-08-26 16:17:28 +03:00
|
|
|
"column" was originally defined as a character offset from the left margin.
|
2016-01-28 20:16:32 +03:00
|
|
|
It was identical to the byte offset. In UTF-8, we have neither a byte offset
|
2010-12-06 21:22:22 +03:00
|
|
|
nor truly fixed width fonts (*). Column could be a pixel value multiplied with
|
2010-04-05 23:52:52 +04:00
|
|
|
an average character width (which is a bearable approximation).
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
* in Unicode, there are no fixed width fonts! Even if the ASCII characters may
|
|
|
|
happen to be all the same width in pixels, Chinese characters surely are not.
|
2010-11-04 01:01:43 +03:00
|
|
|
There are plenty of exceptions, like ligatures, that make special handling of
|
|
|
|
"fixed" character widths a nightmare. I decided to remove all references to
|
2016-01-28 20:16:32 +03:00
|
|
|
fixed fonts and see "columns" as a multiple of the average width of a
|
2010-11-04 01:01:43 +03:00
|
|
|
character in the main font.
|
|
|
|
- Matthias
|
2010-04-05 16:45:03 +04:00
|
|
|
*/
|
2010-04-05 23:52:52 +04:00
|
|
|
|
2010-04-05 16:45:03 +04:00
|
|
|
|
2001-08-02 01:24:49 +04:00
|
|
|
/* Maximum length in characters of a tab or control character expansion
|
2016-01-28 20:16:32 +03:00
|
|
|
of a single buffer character */
|
2001-08-02 01:24:49 +04:00
|
|
|
#define FL_TEXT_MAX_EXP_CHAR_LEN 20
|
|
|
|
|
2001-08-04 16:21:34 +04:00
|
|
|
#include "Fl_Export.H"
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2023-02-10 19:13:20 +03:00
|
|
|
class Fl_Text_Undo_Action_List;
|
2022-11-26 22:28:12 +03:00
|
|
|
class Fl_Text_Undo_Action;
|
2010-04-05 16:45:03 +04:00
|
|
|
|
2016-01-28 20:16:32 +03:00
|
|
|
/**
|
2017-07-26 15:32:13 +03:00
|
|
|
\class Fl_Text_Selection
|
|
|
|
\brief This is an internal class for Fl_Text_Buffer to manage text selections.
|
|
|
|
|
|
|
|
All methods use byte (not UTF-8 character) offsets and start at 0. This
|
|
|
|
class works correctly with UTF-8 strings assuming that the parameters
|
|
|
|
for all calls are on character boundaries.
|
|
|
|
|
|
|
|
If the selection is inactive (not currently used), then selected()
|
|
|
|
returns \p false and start() and end() return 0 (zero).
|
|
|
|
|
|
|
|
The stored offsets are in ascending order, hence the following conditions
|
|
|
|
are true (pseudo code):
|
|
|
|
\code
|
|
|
|
if ( !selected() ) : (start() == 0) && (end() == 0) && (start() == end())
|
|
|
|
if ( selected() ) : start() < end()
|
|
|
|
always : 0 <= start() <= end()
|
|
|
|
always : length() == end() - start()
|
|
|
|
\endcode
|
|
|
|
|
|
|
|
The selection size in bytes can always (unconditionally) be computed by
|
|
|
|
\code
|
|
|
|
int size = sel->end() - sel->start();
|
|
|
|
\endcode
|
|
|
|
|
|
|
|
\see length()
|
|
|
|
|
|
|
|
\note
|
|
|
|
The \b protected member variables \p mStart and \p mEnd are not
|
|
|
|
necessarily 0 (zero) if mSelected == \p false because they are
|
|
|
|
not cleared when \p selected(false) is called (as of Jul 2017).
|
|
|
|
This may be changed in the future.
|
|
|
|
*/
|
2001-08-04 16:21:34 +04:00
|
|
|
class FL_EXPORT Fl_Text_Selection {
|
2001-08-02 01:24:49 +04:00
|
|
|
friend class Fl_Text_Buffer;
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 16:45:03 +04:00
|
|
|
public:
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2017-07-26 15:32:13 +03:00
|
|
|
// Sets the selection range and selected().
|
|
|
|
void set(int startpos, int endpos);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2017-07-26 15:32:13 +03:00
|
|
|
// Updates a selection after text was modified.
|
2010-04-05 16:45:03 +04:00
|
|
|
void update(int pos, int nDeleted, int nInserted);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 16:45:03 +04:00
|
|
|
/**
|
2017-07-26 15:32:13 +03:00
|
|
|
\brief Returns the byte offset to the first selected character.
|
|
|
|
|
|
|
|
The returned offset is only valid if selected() returns true.
|
|
|
|
If the selection is not valid the returned offset is 0 since FLTK 1.4.0.
|
|
|
|
|
|
|
|
\note In FLTK 1.3.x the returned offset could be non-zero even if
|
|
|
|
selected() would have returned 0.
|
|
|
|
|
|
|
|
\return byte offset or 0 if not selected.
|
|
|
|
*/
|
|
|
|
int start() const { return mSelected ? mStart : 0; }
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 16:45:03 +04:00
|
|
|
/**
|
2017-07-26 15:32:13 +03:00
|
|
|
\brief Returns the byte offset to the character after the last selected character.
|
|
|
|
|
|
|
|
The returned offset is only valid if selected() returns true (non-zero).
|
|
|
|
The offset is 0 if no text is selected (since FLTK 1.4.0).
|
|
|
|
|
|
|
|
\note In FLTK 1.3.x the returned offset could be non-zero even if
|
|
|
|
selected() would have returned 0.
|
|
|
|
|
|
|
|
\return byte offset or 0 if not selected.
|
|
|
|
*/
|
|
|
|
int end() const { return mSelected ? mEnd : 0; }
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 16:45:03 +04:00
|
|
|
/**
|
|
|
|
\brief Returns true if any text is selected.
|
2017-07-26 15:32:13 +03:00
|
|
|
\return \p true if any text has been selected, or \p false
|
2020-07-01 19:03:10 +03:00
|
|
|
if no text is selected.
|
2017-07-26 15:32:13 +03:00
|
|
|
*/
|
2010-11-04 01:01:43 +03:00
|
|
|
bool selected() const { return mSelected; }
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 16:45:03 +04:00
|
|
|
/**
|
2017-07-26 15:32:13 +03:00
|
|
|
\brief Modifies the 'selected' flag.
|
|
|
|
\param b new flag
|
|
|
|
*/
|
2010-11-04 01:01:43 +03:00
|
|
|
void selected(bool b) { mSelected = b; }
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 16:45:03 +04:00
|
|
|
/**
|
2017-07-26 15:32:13 +03:00
|
|
|
\brief Returns the size in bytes of the selection.
|
|
|
|
|
|
|
|
This is a convenience method. It always returns the same as
|
|
|
|
\code
|
|
|
|
end() - start()
|
|
|
|
\endcode
|
|
|
|
and it returns 0 if selected() == false.
|
|
|
|
|
|
|
|
\return size in bytes or 0 if not selected.
|
|
|
|
|
|
|
|
\since FLTK 1.4.0
|
|
|
|
*/
|
|
|
|
int length() const { return mSelected ? mEnd - mStart : 0; }
|
|
|
|
|
|
|
|
// Returns true if position \p pos is in this Fl_Text_Selection.
|
2010-11-04 01:01:43 +03:00
|
|
|
int includes(int pos) const;
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2017-07-26 15:32:13 +03:00
|
|
|
// Returns true if selected() and the positions of this selection.
|
2023-02-02 22:54:19 +03:00
|
|
|
int selected(int *startpos, int *endpos) const;
|
2024-11-01 19:48:13 +03:00
|
|
|
FL_DEPRECATED("since 1.4.0 - use selected(startpos, endpos) instead",
|
2023-02-02 22:54:19 +03:00
|
|
|
int position(int *startpos, int *endpos) const) { return selected(startpos, endpos); }
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 16:45:03 +04:00
|
|
|
protected:
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 16:45:03 +04:00
|
|
|
int mStart; ///< byte offset to the first selected character
|
|
|
|
int mEnd; ///< byte offset to the character after the last selected character
|
2016-01-28 20:16:32 +03:00
|
|
|
bool mSelected; ///< this flag is set if any text is selected
|
2001-08-02 01:24:49 +04:00
|
|
|
};
|
|
|
|
|
2010-11-04 01:01:43 +03:00
|
|
|
|
2001-08-02 01:24:49 +04:00
|
|
|
typedef void (*Fl_Text_Modify_Cb)(int pos, int nInserted, int nDeleted,
|
|
|
|
int nRestyled, const char* deletedText,
|
|
|
|
void* cbArg);
|
2010-04-05 16:45:03 +04:00
|
|
|
|
2010-11-04 01:01:43 +03:00
|
|
|
|
2002-09-20 23:59:45 +04:00
|
|
|
typedef void (*Fl_Text_Predelete_Cb)(int pos, int nDeleted, void* cbArg);
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2010-04-05 16:45:03 +04:00
|
|
|
|
2008-09-15 20:39:05 +04:00
|
|
|
/**
|
2019-05-15 18:16:11 +03:00
|
|
|
This class manages Unicode text displayed in one or more Fl_Text_Display widgets.
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
All text in Fl_Text_Buffer must be encoded in UTF-8. All indices used in the
|
|
|
|
function calls must be aligned to the start of a UTF-8 sequence. All indices
|
|
|
|
and pointers returned will be aligned. All functions that return a single
|
2023-08-26 16:17:28 +03:00
|
|
|
character will return that in an unsigned int in UCS-4 encoding.
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2019-05-15 18:16:11 +03:00
|
|
|
The Fl_Text_Buffer class is used by the Fl_Text_Display and Fl_Text_Editor
|
|
|
|
to manage complex text data and is based upon the excellent NEdit text
|
|
|
|
editor engine - see https://sourceforge.net/projects/nedit/.
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
2001-08-04 16:21:34 +04:00
|
|
|
class FL_EXPORT Fl_Text_Buffer {
|
2010-04-05 23:52:52 +04:00
|
|
|
public:
|
2002-09-20 23:59:45 +04:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
2016-01-28 20:16:32 +03:00
|
|
|
Create an empty text buffer of a pre-determined size.
|
|
|
|
\param requestedSize use this to avoid unnecessary re-allocation
|
2010-04-07 03:00:56 +04:00
|
|
|
if you know exactly how much the buffer will need to hold
|
2010-04-05 23:52:52 +04:00
|
|
|
\param preferredGapSize Initial size for the buffer gap (empty space
|
2010-04-07 03:00:56 +04:00
|
|
|
in the buffer where text might be inserted
|
2016-01-28 20:16:32 +03:00
|
|
|
if the user is typing sequential characters)
|
2008-09-15 20:39:05 +04:00
|
|
|
*/
|
2010-04-05 23:52:52 +04:00
|
|
|
Fl_Text_Buffer(int requestedSize = 0, int preferredGapSize = 1024);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
Frees a text buffer
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
~Fl_Text_Buffer();
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
2010-04-06 02:18:14 +04:00
|
|
|
\brief Returns the number of bytes in the buffer.
|
|
|
|
\return size of text in bytes
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int length() const { return mLength; }
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
2010-04-06 02:18:14 +04:00
|
|
|
\brief Get a copy of the entire contents of the text buffer.
|
2016-01-28 20:16:32 +03:00
|
|
|
Memory is allocated to contain the returned string, which the caller
|
2010-04-06 02:18:14 +04:00
|
|
|
must free.
|
2016-01-28 20:16:32 +03:00
|
|
|
\return newly allocated text buffer - must be free'd, text is UTF-8
|
|
|
|
*/
|
2010-04-05 23:52:52 +04:00
|
|
|
char* text() const;
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
/**
|
2010-11-04 01:01:43 +03:00
|
|
|
Replaces the entire contents of the text buffer.
|
2016-01-28 20:16:32 +03:00
|
|
|
\param text Text must be valid UTF-8. If null, an empty string is substituted.
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void text(const char* text);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
2010-04-06 02:18:14 +04:00
|
|
|
\brief Get a copy of a part of the text buffer.
|
2010-04-05 23:52:52 +04:00
|
|
|
Return a copy of the text between \p start and \p end character positions
|
|
|
|
from text buffer \p buf. Positions start at 0, and the range does not
|
|
|
|
include the character pointed to by \p end.
|
|
|
|
When you are done with the text, free it using the free() function.
|
2010-04-06 02:18:14 +04:00
|
|
|
\param start byte offset to first character
|
|
|
|
\param end byte offset after last character in range
|
2016-01-28 20:16:32 +03:00
|
|
|
\return newly allocated text buffer - must be free'd, text is UTF-8
|
2010-04-07 03:00:56 +04:00
|
|
|
*/
|
2010-04-05 23:52:52 +04:00
|
|
|
char* text_range(int start, int end) const;
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
2016-01-28 20:16:32 +03:00
|
|
|
Returns the character at the specified position \p pos in the buffer.
|
|
|
|
Positions start at 0.
|
|
|
|
\param pos byte offset into buffer, \p pos must be at a UTF-8 character boundary
|
2010-04-07 03:00:56 +04:00
|
|
|
\return Unicode UCS-4 encoded character
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
2010-11-04 01:01:43 +03:00
|
|
|
unsigned int char_at(int pos) const;
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-11-04 01:01:43 +03:00
|
|
|
/**
|
|
|
|
Returns the raw byte at the specified position pos in the buffer.
|
2016-01-28 20:16:32 +03:00
|
|
|
Positions start at 0.
|
2010-11-04 01:01:43 +03:00
|
|
|
\param pos byte offset into buffer
|
|
|
|
\return unencoded raw byte
|
|
|
|
*/
|
|
|
|
char byte_at(int pos) const;
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-18 18:33:33 +04:00
|
|
|
/**
|
|
|
|
Convert a byte offset in buffer into a memory address.
|
2010-11-05 00:53:56 +03:00
|
|
|
\param pos byte offset into buffer
|
|
|
|
\return byte offset converted to a memory address
|
2010-04-18 18:33:33 +04:00
|
|
|
*/
|
|
|
|
const char *address(int pos) const
|
|
|
|
{ return (pos < mGapStart) ? mBuf+pos : mBuf+pos+mGapEnd-mGapStart; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
Convert a byte offset in buffer into a memory address.
|
2010-11-05 00:53:56 +03:00
|
|
|
\param pos byte offset into buffer
|
|
|
|
\return byte offset converted to a memory address
|
2010-04-18 18:33:33 +04:00
|
|
|
*/
|
|
|
|
char *address(int pos)
|
|
|
|
{ return (pos < mGapStart) ? mBuf+pos : mBuf+pos+mGapEnd-mGapStart; }
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
Inserts null-terminated string \p text at position \p pos.
|
|
|
|
\param pos insertion position as byte offset (must be UTF-8 character aligned)
|
2023-05-19 19:57:18 +03:00
|
|
|
\param text UTF-8 encoded text
|
|
|
|
\param insertedLength number of bytes to insert, or -1 to indicate \p text is null-terminated
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
2023-05-19 19:57:18 +03:00
|
|
|
void insert(int pos, const char* text, int insertedLength = -1);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
2016-01-28 20:16:32 +03:00
|
|
|
Appends the text string to the end of the buffer.
|
2023-05-19 19:57:18 +03:00
|
|
|
\param t UTF-8 encoded text
|
|
|
|
\param addedLength number of bytes to append, or -1 to indicate \p t is null-terminated
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
2023-05-19 19:57:18 +03:00
|
|
|
void append(const char* t, int addedLength = -1) { insert(length(), t, addedLength); }
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2017-10-08 23:38:36 +03:00
|
|
|
void vprintf(const char *fmt, va_list ap);
|
|
|
|
void printf(const char* fmt, ...);
|
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
|
|
|
Deletes a range of characters in the buffer.
|
2010-04-07 03:00:56 +04:00
|
|
|
\param start byte offset to first character to be removed
|
2016-04-05 20:52:58 +03:00
|
|
|
\param end byte offset to character after last character to be removed
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void remove(int start, int end);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
2016-01-28 20:16:32 +03:00
|
|
|
Deletes the characters between \p start and \p end, and inserts the
|
|
|
|
null-terminated string \p text in their place in the buffer.
|
2010-04-07 03:00:56 +04:00
|
|
|
\param start byte offset to first character to be removed and new insert position
|
2016-01-28 20:16:32 +03:00
|
|
|
\param end byte offset to character after last character to be removed
|
2023-05-19 19:57:18 +03:00
|
|
|
\param text UTF-8 encoded text
|
|
|
|
\param insertedLength number of bytes to insert, or -1 to indicate \p text is null-terminated
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
2023-05-19 19:57:18 +03:00
|
|
|
void replace(int start, int end, const char *text, int insertedLength = -1);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
2016-01-28 20:16:32 +03:00
|
|
|
Copies text from another Fl_Text_Buffer to this one.
|
|
|
|
\param fromBuf source text buffer, may be the same as this
|
2010-11-04 01:01:43 +03:00
|
|
|
\param fromStart byte offset into buffer
|
|
|
|
\param fromEnd byte offset into buffer
|
|
|
|
\param toPos destination byte offset into buffer
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void copy(Fl_Text_Buffer* fromBuf, int fromStart, int fromEnd, int toPos);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
2016-01-28 20:16:32 +03:00
|
|
|
Undo text modification according to the undo variables or insert text
|
2010-04-05 23:52:52 +04:00
|
|
|
from the undo buffer
|
|
|
|
*/
|
|
|
|
int undo(int *cp=0);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2023-04-14 17:54:11 +03:00
|
|
|
/**
|
2023-08-26 16:17:28 +03:00
|
|
|
Check if undo is enabled and if the last action can be undone.
|
2023-04-14 17:54:11 +03:00
|
|
|
\see canUndo()
|
|
|
|
*/
|
2023-04-17 17:12:03 +03:00
|
|
|
bool can_undo() const;
|
2023-04-14 17:54:11 +03:00
|
|
|
|
2023-02-10 19:13:20 +03:00
|
|
|
/**
|
|
|
|
Redo previous undo action.
|
|
|
|
*/
|
|
|
|
int redo(int *cp=0);
|
|
|
|
|
2016-01-28 20:16:32 +03:00
|
|
|
/**
|
2023-08-26 16:17:28 +03:00
|
|
|
Check if undo is enabled and if the last undo action can be redone.
|
2023-04-14 17:54:11 +03:00
|
|
|
\see canUndo()
|
|
|
|
*/
|
2023-04-17 17:12:03 +03:00
|
|
|
bool can_redo() const;
|
2023-04-14 17:54:11 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
Enable or disable undo actions for this text buffer.
|
|
|
|
Undo actions are enable for text buffer by default. If used as a style buffer
|
|
|
|
in Fl_Text_Display, undo actions are disabled as they are handled by the
|
|
|
|
text buffer.
|
|
|
|
\see can_undo()
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void canUndo(char flag=1);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
Inserts a file at the specified position.
|
|
|
|
Returns
|
|
|
|
- 0 on success
|
|
|
|
- non-zero on error (strerror() contains reason)
|
|
|
|
- 1 indicates open for read failed (no data loaded)
|
|
|
|
- 2 indicates error occurred while reading data (data was partially loaded)
|
|
|
|
|
|
|
|
File can be UTF-8 or CP1252 encoded.
|
|
|
|
If the input file is not UTF-8 encoded, the Fl_Text_Buffer widget will
|
|
|
|
contain data transcoded to UTF-8. By default, the message
|
|
|
|
Fl_Text_Buffer::file_encoding_warning_message
|
2010-12-10 22:24:28 +03:00
|
|
|
will warn the user about this.
|
2010-12-15 20:38:39 +03:00
|
|
|
\see input_file_was_transcoded and transcoding_warning_action.
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int insertfile(const char *file, int pos, int buflen = 128*1024);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
2010-12-10 22:24:28 +03:00
|
|
|
Appends the named file to the end of the buffer. See also insertfile().
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int appendfile(const char *file, int buflen = 128*1024)
|
|
|
|
{ return insertfile(file, length(), buflen); }
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
/**
|
2010-12-10 22:24:28 +03:00
|
|
|
Loads a text file into the buffer. See also insertfile().
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int loadfile(const char *file, int buflen = 128*1024)
|
|
|
|
{ select(0, length()); remove_selection(); return appendfile(file, buflen); }
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
2016-01-28 20:16:32 +03:00
|
|
|
Writes the specified portions of the text buffer to a file.
|
|
|
|
Returns
|
|
|
|
- 0 on success
|
|
|
|
- non-zero on error (strerror() contains reason)
|
|
|
|
- 1 indicates open for write failed (no data saved)
|
|
|
|
- 2 indicates error occurred while writing data (data was partially saved)
|
2016-07-20 02:23:28 +03:00
|
|
|
|
|
|
|
\see savefile(const char *file, int buflen)
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int outputfile(const char *file, int start, int end, int buflen = 128*1024);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
/**
|
2016-07-20 03:50:36 +03:00
|
|
|
Saves a text file from the current buffer.
|
2016-07-20 02:23:28 +03:00
|
|
|
Returns
|
|
|
|
- 0 on success
|
|
|
|
- non-zero on error (strerror() contains reason)
|
|
|
|
- 1 indicates open for write failed (no data saved)
|
|
|
|
- 2 indicates error occurred while writing data (data was partially saved)
|
|
|
|
|
|
|
|
\see outputfile(const char *file, int start, int end, int buflen)
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int savefile(const char *file, int buflen = 128*1024)
|
|
|
|
{ return outputfile(file, 0, length(), buflen); }
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
2016-01-28 20:16:32 +03:00
|
|
|
Gets the tab width.
|
|
|
|
|
|
|
|
The tab width is measured in characters. The pixel position is
|
|
|
|
calculated using an average character width.
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int tab_distance() const { return mTabDist; }
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
|
|
|
Set the hardware tab distance (width) used by all displays for this buffer,
|
|
|
|
and used in computing offsets for rectangular selection operations.
|
|
|
|
*/
|
|
|
|
void tab_distance(int tabDist);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
/**
|
2010-04-05 23:52:52 +04:00
|
|
|
Selects a range of characters in the buffer.
|
|
|
|
*/
|
|
|
|
void select(int start, int end);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a non-zero value if text has been selected, 0 otherwise.
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int selected() const { return mPrimary.selected(); }
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
Cancels any previous selection on the primary text selection object.
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void unselect();
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
Gets the selection position.
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int selection_position(int* start, int* end);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the currently selected text.
|
|
|
|
|
|
|
|
When you are done with the text, free it using the free() function.
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
char* selection_text();
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2016-01-28 20:16:32 +03:00
|
|
|
/**
|
2010-04-05 23:52:52 +04:00
|
|
|
Removes the text in the primary selection.
|
|
|
|
*/
|
|
|
|
void remove_selection();
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
|
|
|
Replaces the text in the primary selection.
|
|
|
|
*/
|
|
|
|
void replace_selection(const char* text);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
|
|
|
Selects a range of characters in the secondary selection.
|
|
|
|
*/
|
|
|
|
void secondary_select(int start, int end);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a non-zero value if text has been selected in the secondary
|
|
|
|
text selection, 0 otherwise.
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int secondary_selected() { return mSecondary.selected(); }
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
Clears any selection in the secondary text selection object.
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void secondary_unselect();
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
/**
|
2010-04-05 23:52:52 +04:00
|
|
|
Returns the current selection in the secondary text selection object.
|
|
|
|
*/
|
|
|
|
int secondary_selection_position(int* start, int* end);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the text in the secondary selection.
|
|
|
|
|
|
|
|
When you are done with the text, free it using the free() function.
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
char* secondary_selection_text();
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
Removes the text from the buffer corresponding to the secondary text
|
|
|
|
selection object.
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void remove_secondary_selection();
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
Replaces the text from the buffer corresponding to the secondary
|
2010-04-05 23:52:52 +04:00
|
|
|
text selection object with the new string \p text.
|
|
|
|
*/
|
|
|
|
void replace_secondary_selection(const char* text);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
/**
|
2010-04-05 23:52:52 +04:00
|
|
|
Highlights the specified text within the buffer.
|
|
|
|
*/
|
|
|
|
void highlight(int start, int end);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
2020-04-14 23:28:39 +03:00
|
|
|
Returns a non-zero value if text has been highlighted, 0 otherwise.
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int highlight() { return mHighlight.selected(); }
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
|
|
|
Unhighlights text in the buffer.
|
|
|
|
*/
|
|
|
|
void unhighlight();
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2016-01-28 20:16:32 +03:00
|
|
|
/**
|
2010-04-05 23:52:52 +04:00
|
|
|
Highlights the specified text between \p start and \p end within the buffer.
|
|
|
|
*/
|
|
|
|
int highlight_position(int* start, int* end);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the highlighted text.
|
|
|
|
|
|
|
|
When you are done with the text, free it using the free() function.
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
char* highlight_text();
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
2016-01-28 20:16:32 +03:00
|
|
|
Adds a callback function that is called whenever the text buffer is modified.
|
|
|
|
|
|
|
|
The callback function is declared as follows:
|
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
\code
|
|
|
|
typedef void (*Fl_Text_Modify_Cb)(int pos, int nInserted, int nDeleted,
|
|
|
|
int nRestyled, const char* deletedText,
|
|
|
|
void* cbArg);
|
|
|
|
\endcode
|
|
|
|
*/
|
|
|
|
void add_modify_callback(Fl_Text_Modify_Cb bufModifiedCB, void* cbArg);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
|
|
|
Removes a modify callback.
|
|
|
|
*/
|
|
|
|
void remove_modify_callback(Fl_Text_Modify_Cb bufModifiedCB, void* cbArg);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
|
|
|
Calls all modify callbacks that have been registered using
|
2016-01-28 20:16:32 +03:00
|
|
|
the add_modify_callback() method.
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void call_modify_callbacks() { call_modify_callbacks(0, 0, 0, 0, 0); }
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
Adds a callback routine to be called before text is deleted from the buffer.
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void add_predelete_callback(Fl_Text_Predelete_Cb bufPredelCB, void* cbArg);
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2016-01-28 20:16:32 +03:00
|
|
|
/**
|
|
|
|
Removes a callback routine \p bufPreDeleteCB associated with argument \p cbArg
|
|
|
|
to be called before text is deleted from the buffer.
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void remove_predelete_callback(Fl_Text_Predelete_Cb predelCB, void* cbArg);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
2016-01-28 20:16:32 +03:00
|
|
|
Calls the stored pre-delete callback procedure(s) for this buffer to update
|
2010-04-05 23:52:52 +04:00
|
|
|
the changed area(s) on the screen and any other listeners.
|
|
|
|
*/
|
|
|
|
void call_predelete_callbacks() { call_predelete_callbacks(0, 0); }
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
|
|
|
Returns the text from the entire line containing the specified
|
2016-01-28 20:16:32 +03:00
|
|
|
character position.
|
|
|
|
|
|
|
|
When you are done with the text, free it using the free() function.
|
2010-11-04 01:01:43 +03:00
|
|
|
\param pos byte index into buffer
|
2016-01-28 20:16:32 +03:00
|
|
|
\return copy of UTF-8 text, must be free'd
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
char* line_text(int pos) const;
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the position of the start of the line containing position \p pos.
|
2010-11-04 01:01:43 +03:00
|
|
|
\param pos byte index into buffer
|
|
|
|
\return byte offset to line start
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int line_start(int pos) const;
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
Finds and returns the position of the end of the line containing position
|
|
|
|
\p pos (which is either a pointer to the newline character ending the line
|
|
|
|
or a pointer to one character beyond the end of the buffer).
|
2010-11-04 01:01:43 +03:00
|
|
|
\param pos byte index into buffer
|
|
|
|
\return byte offset to line end
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int line_end(int pos) const;
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2016-01-28 20:16:32 +03:00
|
|
|
/**
|
|
|
|
Returns the position corresponding to the start of the word.
|
2010-11-04 01:01:43 +03:00
|
|
|
\param pos byte index into buffer
|
|
|
|
\return byte offset to word start
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int word_start(int pos) const;
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2016-01-28 20:16:32 +03:00
|
|
|
/**
|
2010-04-05 23:52:52 +04:00
|
|
|
Returns the position corresponding to the end of the word.
|
2010-11-04 01:01:43 +03:00
|
|
|
\param pos byte index into buffer
|
|
|
|
\return byte offset to word end
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int word_end(int pos) const;
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
|
|
|
Count the number of displayed characters between buffer position
|
2016-01-28 20:16:32 +03:00
|
|
|
\p lineStartPos and \p targetPos.
|
|
|
|
|
|
|
|
Displayed characters are the characters shown on the screen to represent
|
|
|
|
characters in the buffer, where tabs and control characters are expanded.
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int count_displayed_characters(int lineStartPos, int targetPos) const;
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
2016-01-28 20:16:32 +03:00
|
|
|
Count forward from buffer position \p startPos in displayed characters.
|
|
|
|
|
|
|
|
Displayed characters are the characters shown on the screen to represent
|
|
|
|
characters in the buffer, where tabs and control characters are expanded.
|
2010-04-06 02:18:14 +04:00
|
|
|
\param lineStartPos byte offset into buffer
|
|
|
|
\param nChars number of bytes that are sent to the display
|
|
|
|
\return byte offset in input after all output bytes are sent
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int skip_displayed_characters(int lineStartPos, int nChars);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
|
|
|
Counts the number of newlines between \p startPos and \p endPos in buffer.
|
|
|
|
The character at position \p endPos is not counted.
|
|
|
|
*/
|
|
|
|
int count_lines(int startPos, int endPos) const;
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2024-08-04 01:32:05 +03:00
|
|
|
/**
|
|
|
|
Estimate the number of newlines between \p startPos and \p endPos in buffer.
|
|
|
|
This call takes line wrapping into account. It assumes a line break at every
|
|
|
|
`lineLen` characters after the beginning of a line.
|
|
|
|
*/
|
|
|
|
int estimate_lines(int startPos, int endPos, int lineLen) const;
|
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
|
|
|
Finds the first character of the line \p nLines forward from \p startPos
|
2016-01-28 20:16:32 +03:00
|
|
|
in the buffer and returns its position.
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int skip_lines(int startPos, int nLines);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
2016-01-28 20:16:32 +03:00
|
|
|
Finds and returns the position of the first character of the line \p nLines
|
|
|
|
backwards from \p startPos (not counting the character pointed to by
|
|
|
|
\p startpos if that is a newline) in the buffer.
|
|
|
|
\p nLines == 0 means find the beginning of the line.
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int rewind_lines(int startPos, int nLines);
|
|
|
|
|
2016-01-28 20:16:32 +03:00
|
|
|
/**
|
2010-04-05 23:52:52 +04:00
|
|
|
Finds the next occurrence of the specified character.
|
|
|
|
Search forwards in buffer for character \p searchChar, starting
|
2016-01-28 20:16:32 +03:00
|
|
|
with the character \p startPos, and returning the result in \p foundPos.
|
|
|
|
Returns 1 if found, 0 if not.
|
|
|
|
The difference between this and search_forward() is that it's optimized
|
|
|
|
for single characters. The overall performance of the text widget is
|
|
|
|
dependent on its ability to count lines quickly, hence searching for a
|
|
|
|
single character: newline.
|
2010-11-04 01:01:43 +03:00
|
|
|
\param startPos byte offset to start position
|
|
|
|
\param searchChar UCS-4 character that we want to find
|
|
|
|
\param foundPos byte offset where the character was found
|
|
|
|
\return 1 if found, 0 if not
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
2010-11-04 01:01:43 +03:00
|
|
|
int findchar_forward(int startPos, unsigned searchChar, int* foundPos) const;
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
|
|
|
Search backwards in buffer \p buf for character \p searchChar, starting
|
2016-01-28 20:16:32 +03:00
|
|
|
with the character \e before \p startPos, returning the result in \p foundPos.
|
|
|
|
|
|
|
|
Returns 1 if found, 0 if not. The difference between this and
|
|
|
|
search_backward() is that it's optimized for single characters. The
|
2010-04-05 23:52:52 +04:00
|
|
|
overall performance of the text widget is dependent on its ability to
|
2016-01-28 20:16:32 +03:00
|
|
|
count lines quickly, hence searching for a single character: newline.
|
2010-11-04 01:01:43 +03:00
|
|
|
\param startPos byte offset to start position
|
|
|
|
\param searchChar UCS-4 character that we want to find
|
|
|
|
\param foundPos byte offset where the character was found
|
|
|
|
\return 1 if found, 0 if not
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
2010-12-02 03:43:07 +03:00
|
|
|
int findchar_backward(int startPos, unsigned int searchChar, int* foundPos) const;
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
|
|
|
Search forwards in buffer for string \p searchString, starting with the
|
2016-01-28 20:16:32 +03:00
|
|
|
character \p startPos, and returning the result in \p foundPos.
|
|
|
|
|
|
|
|
Returns 1 if found, 0 if not.
|
2010-11-04 01:01:43 +03:00
|
|
|
\param startPos byte offset to start position
|
2016-01-28 20:16:32 +03:00
|
|
|
\param searchString UTF-8 string that we want to find
|
2010-11-04 01:01:43 +03:00
|
|
|
\param foundPos byte offset where the string was found
|
|
|
|
\param matchCase if set, match character case
|
|
|
|
\return 1 if found, 0 if not
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int search_forward(int startPos, const char* searchString, int* foundPos,
|
|
|
|
int matchCase = 0) const;
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
2016-01-28 20:16:32 +03:00
|
|
|
Search backwards in buffer for string \p searchString, starting with
|
2016-07-20 03:50:36 +03:00
|
|
|
the character \e at \p startPos, returning the result in \p foundPos.
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
Returns 1 if found, 0 if not.
|
2010-11-04 01:01:43 +03:00
|
|
|
\param startPos byte offset to start position
|
2016-01-28 20:16:32 +03:00
|
|
|
\param searchString UTF-8 string that we want to find
|
2010-11-04 01:01:43 +03:00
|
|
|
\param foundPos byte offset where the string was found
|
|
|
|
\param matchCase if set, match character case
|
|
|
|
\return 1 if found, 0 if not
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int search_backward(int startPos, const char* searchString, int* foundPos,
|
|
|
|
int matchCase = 0) const;
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the primary selection.
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
const Fl_Text_Selection* primary_selection() const { return &mPrimary; }
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
2016-01-28 20:16:32 +03:00
|
|
|
Returns the primary selection.
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
Fl_Text_Selection* primary_selection() { return &mPrimary; }
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
|
|
|
Returns the secondary selection.
|
|
|
|
*/
|
|
|
|
const Fl_Text_Selection* secondary_selection() const { return &mSecondary; }
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
|
|
|
Returns the current highlight selection.
|
|
|
|
*/
|
|
|
|
const Fl_Text_Selection* highlight_selection() const { return &mHighlight; }
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-11-04 01:01:43 +03:00
|
|
|
/**
|
|
|
|
Returns the index of the previous character.
|
2016-01-28 20:16:32 +03:00
|
|
|
\param ix index to the current character
|
2010-11-04 01:01:43 +03:00
|
|
|
*/
|
|
|
|
int prev_char(int ix) const;
|
2010-11-06 03:29:58 +03:00
|
|
|
int prev_char_clipped(int ix) const;
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-11-04 01:01:43 +03:00
|
|
|
/**
|
|
|
|
Returns the index of the next character.
|
2016-01-28 20:16:32 +03:00
|
|
|
\param ix index to the current character
|
2010-11-04 01:01:43 +03:00
|
|
|
*/
|
|
|
|
int next_char(int ix) const;
|
2010-11-06 03:29:58 +03:00
|
|
|
int next_char_clipped(int ix) const;
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-11-06 17:29:12 +03:00
|
|
|
/**
|
2016-01-28 20:16:32 +03:00
|
|
|
Align an index into the buffer to the current or previous UTF-8 boundary.
|
2010-11-06 17:29:12 +03:00
|
|
|
*/
|
|
|
|
int utf8_align(int) const;
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-12-10 22:24:28 +03:00
|
|
|
/**
|
2016-01-28 20:16:32 +03:00
|
|
|
\brief true if the loaded file has been transcoded to UTF-8.
|
2010-12-10 22:24:28 +03:00
|
|
|
*/
|
2010-12-15 20:38:39 +03:00
|
|
|
int input_file_was_transcoded;
|
2010-12-10 22:24:28 +03:00
|
|
|
|
|
|
|
/** This message may be displayed using the fl_alert() function when a file
|
|
|
|
which was not UTF-8 encoded is input.
|
|
|
|
*/
|
|
|
|
static const char* file_encoding_warning_message;
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
/**
|
2010-12-10 22:24:28 +03:00
|
|
|
\brief Pointer to a function called after reading a non UTF-8 encoded file.
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-12-10 22:24:28 +03:00
|
|
|
This function is called after reading a file if the file content
|
2010-12-15 20:38:39 +03:00
|
|
|
was transcoded to UTF-8. Its default implementation calls fl_alert()
|
2010-12-10 22:24:28 +03:00
|
|
|
with the text of \ref file_encoding_warning_message. No warning message is
|
2010-12-15 20:38:39 +03:00
|
|
|
displayed if this pointer is set to NULL. Use \ref input_file_was_transcoded
|
|
|
|
to be informed if file input required transcoding to UTF-8.
|
2010-12-10 22:24:28 +03:00
|
|
|
*/
|
|
|
|
void (*transcoding_warning_action)(Fl_Text_Buffer*);
|
2016-12-17 10:42:54 +03:00
|
|
|
bool is_word_separator(int pos) const;
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
protected:
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
|
|
|
Calls the stored modify callback procedure(s) for this buffer to update the
|
|
|
|
changed area(s) on the screen and any other listeners.
|
|
|
|
*/
|
|
|
|
void call_modify_callbacks(int pos, int nDeleted, int nInserted,
|
|
|
|
int nRestyled, const char* deletedText) const;
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
2016-01-28 20:16:32 +03:00
|
|
|
Calls the stored pre-delete callback procedure(s) for this buffer to update
|
2010-04-05 23:52:52 +04:00
|
|
|
the changed area(s) on the screen and any other listeners.
|
|
|
|
*/
|
|
|
|
void call_predelete_callbacks(int pos, int nDeleted) const;
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
2016-01-28 20:16:32 +03:00
|
|
|
Internal (non-redisplaying) version of insert().
|
|
|
|
|
2023-05-19 19:57:18 +03:00
|
|
|
Returns the length of text inserted (this is just strlen(\p text) if
|
|
|
|
\p insertedLength == -1, however
|
2016-01-28 20:16:32 +03:00
|
|
|
this calculation can be expensive and the length will be required by any
|
|
|
|
caller who will continue on to call redisplay). \p pos must be contiguous
|
|
|
|
with the existing text in the buffer (i.e. not past the end).
|
2010-11-05 00:53:56 +03:00
|
|
|
\return the number of bytes inserted
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
2023-05-19 19:57:18 +03:00
|
|
|
int insert_(int pos, const char* text, int insertedLength = -1);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
2016-01-28 20:16:32 +03:00
|
|
|
Internal (non-redisplaying) version of remove().
|
|
|
|
|
|
|
|
Removes the contents of the buffer between \p start and \p end (and moves
|
|
|
|
the gap to the site of the delete).
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void remove_(int start, int end);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
|
|
|
Calls the stored redisplay procedure(s) for this buffer to update the
|
|
|
|
screen for a change in a selection.
|
|
|
|
*/
|
|
|
|
void redisplay_selection(Fl_Text_Selection* oldSelection,
|
|
|
|
Fl_Text_Selection* newSelection) const;
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-06 00:01:10 +04:00
|
|
|
/**
|
2010-11-07 23:13:50 +03:00
|
|
|
Move the gap to start at a new position.
|
2010-04-06 00:01:10 +04:00
|
|
|
*/
|
2010-04-05 23:52:52 +04:00
|
|
|
void move_gap(int pos);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
|
|
|
Reallocates the text storage in the buffer to have a gap starting at \p newGapStart
|
|
|
|
and a gap size of \p newGapLen, preserving the buffer's current contents.
|
|
|
|
*/
|
|
|
|
void reallocate_with_gap(int newGapStart, int newGapLen);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
char* selection_text_(Fl_Text_Selection* sel) const;
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
/**
|
2010-04-05 23:52:52 +04:00
|
|
|
Removes the text from the buffer corresponding to \p sel.
|
|
|
|
*/
|
|
|
|
void remove_selection_(Fl_Text_Selection* sel);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
|
|
|
/**
|
2010-04-05 23:52:52 +04:00
|
|
|
Replaces the \p text in selection \p sel.
|
|
|
|
*/
|
|
|
|
void replace_selection_(Fl_Text_Selection* sel, const char* text);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
|
|
|
Updates all of the selections in the buffer for changes in the buffer's text
|
|
|
|
*/
|
|
|
|
void update_selections(int pos, int nDeleted, int nInserted);
|
2016-01-28 20:16:32 +03:00
|
|
|
|
2023-02-10 19:13:20 +03:00
|
|
|
/**
|
|
|
|
Apply the current undo/redo operation, called from undo() or redo().
|
|
|
|
*/
|
|
|
|
int apply_undo(Fl_Text_Undo_Action* action, int* cursorPos);
|
|
|
|
|
2010-04-06 00:01:10 +04:00
|
|
|
Fl_Text_Selection mPrimary; /**< highlighted areas */
|
|
|
|
Fl_Text_Selection mSecondary; /**< highlighted areas */
|
|
|
|
Fl_Text_Selection mHighlight; /**< highlighted areas */
|
|
|
|
int mLength; /**< length of the text in the buffer (the length
|
2016-01-28 20:16:32 +03:00
|
|
|
of the buffer itself must be calculated:
|
|
|
|
gapEnd - gapStart + length) */
|
2010-04-06 00:01:10 +04:00
|
|
|
char* mBuf; /**< allocated memory where the text is stored */
|
|
|
|
int mGapStart; /**< points to the first character of the gap */
|
2016-01-28 20:16:32 +03:00
|
|
|
int mGapEnd; /**< points to the first character after the gap */
|
2010-04-05 23:52:52 +04:00
|
|
|
// The hardware tab distance used by all displays for this buffer,
|
|
|
|
// and used in computing offsets for rectangular selection operations.
|
2010-04-06 00:01:10 +04:00
|
|
|
int mTabDist; /**< equiv. number of characters in a tab */
|
|
|
|
int mNModifyProcs; /**< number of modify-redisplay procs attached */
|
2016-01-28 20:16:32 +03:00
|
|
|
Fl_Text_Modify_Cb *mModifyProcs;/**< procedures to call when buffer is
|
|
|
|
modified to redisplay contents */
|
2010-04-06 00:01:10 +04:00
|
|
|
void** mCbArgs; /**< caller arguments for modifyProcs above */
|
|
|
|
int mNPredeleteProcs; /**< number of pre-delete procs attached */
|
2010-11-04 01:01:43 +03:00
|
|
|
Fl_Text_Predelete_Cb *mPredeleteProcs; /**< procedure to call before text is deleted
|
2016-01-28 20:16:32 +03:00
|
|
|
from the buffer; at most one is supported. */
|
2010-04-06 00:01:10 +04:00
|
|
|
void **mPredeleteCbArgs; /**< caller argument for pre-delete proc above */
|
|
|
|
int mCursorPosHint; /**< hint for reasonable cursor position after
|
2016-01-28 20:16:32 +03:00
|
|
|
a buffer modification operation */
|
2010-04-06 00:01:10 +04:00
|
|
|
char mCanUndo; /**< if this buffer is used for attributes, it must
|
2016-01-28 20:16:32 +03:00
|
|
|
not do any undo calls */
|
2010-04-06 00:01:10 +04:00
|
|
|
int mPreferredGapSize; /**< the default allocation for the text gap is 1024
|
2016-01-28 20:16:32 +03:00
|
|
|
bytes and should only be increased if frequent
|
|
|
|
and large changes in buffer size are expected */
|
2022-11-26 22:28:12 +03:00
|
|
|
Fl_Text_Undo_Action* mUndo; /**< local undo event */
|
2023-02-10 19:13:20 +03:00
|
|
|
Fl_Text_Undo_Action_List* mUndoList; /**< List of undo event */
|
|
|
|
Fl_Text_Undo_Action_List* mRedoList; /**< List of redo event */
|
2001-08-02 01:24:49 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|