2001-08-02 01:24:49 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// "$Id$"
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
|
|
|
// Header file for Fl_Text_Buffer class.
|
|
|
|
//
|
2009-01-01 19:11:32 +03:00
|
|
|
// Copyright 2001-2009 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
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Library General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library 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
|
|
|
|
// Library General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Library General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
// USA.
|
|
|
|
//
|
2005-04-16 04:13:17 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.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
|
|
|
|
|
2010-04-05 16:45:03 +04:00
|
|
|
/*
|
2010-04-05 16:55:14 +04:00
|
|
|
Suggested UTF-8 terminology for this file:
|
2010-04-05 23:52:52 +04:00
|
|
|
|
2010-04-05 16:55:14 +04:00
|
|
|
?? "length" is the number of characters in a string
|
|
|
|
?? "size" is the number of bytes
|
|
|
|
?? "index" is the position in a string in number of characters
|
|
|
|
?? "offset" is the position in a strin in bytes (and must be kept on a charater boundary)
|
|
|
|
(there seems to be no standard in Uncode documents, howevere "length" is commonly
|
|
|
|
referencing the number of bytes. Maybe "bytes" and "glyphs" would be the most
|
|
|
|
obvious way to describe sizes?)
|
2010-04-05 16:45:03 +04:00
|
|
|
|
|
|
|
"character size" is the size of a UTF-8 character in bytes
|
|
|
|
"character width" is the width of a Unicode character in pixels
|
2010-04-05 23:52:52 +04:00
|
|
|
|
2010-04-05 16:45:03 +04:00
|
|
|
"column" was orginally defined as a character offset from the left margin. It was
|
2010-04-05 23:52:52 +04:00
|
|
|
identical to the byte offset. In UTF-8, we have neither a byte offset nor
|
|
|
|
truly fixed width fonts. Column could be a pixel value multiplied with
|
|
|
|
an average character width (which is a bearable approximation).
|
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
|
2010-04-05 23:52:52 +04: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
|
|
|
|
2010-04-05 16:45:03 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
\class Fl_Text_Selection
|
|
|
|
\brief This is an internal class for Fl_Text_Buffer to manage text selections.
|
2010-04-06 01:10:40 +04:00
|
|
|
This class works correctly with utf-8 strings assuming that the parameters
|
|
|
|
for all calls are on character boundaries.
|
2008-09-21 05:46:27 +04:00
|
|
|
*/
|
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;
|
2010-04-05 23:52:52 +04:00
|
|
|
|
2010-04-05 16:45:03 +04:00
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Set the selection range.
|
|
|
|
\param start byte offset to first selected character
|
|
|
|
\param end byte offset pointing after last selected character
|
|
|
|
*/
|
|
|
|
void set(int start, int end);
|
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Set a regtangular selection range.
|
|
|
|
\param start byte offset to first selected character
|
|
|
|
\param end byte offset pointing after last selected character
|
|
|
|
\param rectStart first selected column
|
|
|
|
\param rectEnd last selected column +1
|
|
|
|
*/
|
|
|
|
void set_rectangular(int start, int end, int rectStart, int rectEnd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Updates a selection afer text was modified.
|
2010-04-05 23:52:52 +04:00
|
|
|
Updates an individual selection for changes in the corresponding text
|
2010-04-05 16:45:03 +04:00
|
|
|
\param pos byte offset into text buffer at which the change occured
|
|
|
|
\param nDeleted number of bytes deleted from the buffer
|
|
|
|
\param nInserted number of bytes inserted into the buffer
|
|
|
|
*/
|
|
|
|
void update(int pos, int nDeleted, int nInserted);
|
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Returns true if the selection is rectangular.
|
2010-04-06 01:10:40 +04:00
|
|
|
\return flag
|
2010-04-05 16:45:03 +04:00
|
|
|
*/
|
|
|
|
char rectangular() const { return mRectangular; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Return the byte offset to the first selected character.
|
2010-04-06 01:10:40 +04:00
|
|
|
\return byte offset
|
2010-04-05 16:45:03 +04:00
|
|
|
*/
|
|
|
|
int start() const { return mStart; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Return the byte ofsset to the character after the last selected character.
|
2010-04-06 01:10:40 +04:00
|
|
|
\return byte offset
|
2010-04-05 16:45:03 +04:00
|
|
|
*/
|
|
|
|
int end() const { return mEnd; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Return the first column of the rectangular selection.
|
2010-04-06 01:10:40 +04:00
|
|
|
\return first column of rectangular selection
|
2010-04-05 16:45:03 +04:00
|
|
|
*/
|
|
|
|
int rect_start() const { return mRectStart; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Return the last column of the rectangular selection + 1.
|
2010-04-06 01:10:40 +04:00
|
|
|
\return last column of rectangular selection +1
|
2010-04-05 16:45:03 +04:00
|
|
|
*/
|
|
|
|
int rect_end() const { return mRectEnd; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Returns true if any text is selected.
|
2010-04-06 01:10:40 +04:00
|
|
|
\return a non-zero number if any text has been selected, or 0
|
2010-04-05 16:45:03 +04:00
|
|
|
if no text is selected.
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
2010-04-05 16:45:03 +04:00
|
|
|
char selected() const { return mSelected; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Modify the 'selected' flag.
|
2010-04-06 01:10:40 +04:00
|
|
|
\param b new flag
|
2010-04-05 16:45:03 +04:00
|
|
|
*/
|
|
|
|
void selected(char b) { mSelected = b; }
|
|
|
|
|
|
|
|
/**
|
2010-04-05 23:52:52 +04:00
|
|
|
Return true if position \p pos with indentation \p dispIndex is in
|
|
|
|
the Fl_Text_Selection.
|
2010-04-05 16:45:03 +04:00
|
|
|
*/
|
|
|
|
int includes(int pos, int lineStartPos, int dispIndex) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Return the positions of this selection.
|
|
|
|
\param start retrun byte offset to first selected character
|
|
|
|
\param end retrun byte offset pointing after last selected character
|
2010-04-06 01:10:40 +04:00
|
|
|
\return true if selected
|
2010-04-05 16:45:03 +04:00
|
|
|
*/
|
|
|
|
int position(int* start, int* end) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Return the positions of this rectangular selection.
|
|
|
|
\param start return byte offset to first selected character
|
|
|
|
\param end return byte offset pointing after last selected character
|
|
|
|
\param isRect return if the selection is rectangular
|
|
|
|
\param rectStart return first selected column
|
|
|
|
\param rectEnd return last selected column +1
|
2010-04-06 01:10:40 +04:00
|
|
|
\return true if selected
|
2010-04-05 16:45:03 +04:00
|
|
|
*/
|
|
|
|
int position(int* start, int* end, int* isRect, int* rectStart, int* rectEnd) const;
|
2010-04-05 23:52:52 +04:00
|
|
|
|
2010-04-05 16:45:03 +04:00
|
|
|
protected:
|
|
|
|
|
|
|
|
char mSelected; ///< this flag is set if any text is selected
|
|
|
|
char mRectangular; ///< this flag is set if the selection is rectangular
|
|
|
|
int mStart; ///< byte offset to the first selected character
|
|
|
|
int mEnd; ///< byte offset to the character after the last selected character
|
|
|
|
int mRectStart; ///< first selected column (see "column")
|
|
|
|
int mRectEnd; ///< last selected column +1 (see "column")
|
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
|
|
|
|
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
|
|
|
/**
|
2010-04-05 16:45:03 +04:00
|
|
|
\brief This class manages unicode displayed in one or more Fl_Text_Display widgets.
|
|
|
|
|
2010-04-05 23:52:52 +04: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 http://www.nedit.org/.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
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
|
|
|
/**
|
2010-04-06 00:01:10 +04:00
|
|
|
Create an empty text buffer of a pre-determined size.
|
2010-04-05 23:52:52 +04:00
|
|
|
\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
|
|
|
|
if the user is typing sequential chars)
|
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);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Frees a text buffer
|
|
|
|
*/
|
|
|
|
~Fl_Text_Buffer();
|
|
|
|
|
|
|
|
/**
|
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; }
|
|
|
|
|
|
|
|
/**
|
2010-04-06 02:18:14 +04:00
|
|
|
\brief Get a copy of the entire contents of the text buffer.
|
|
|
|
Memory is allocated to contain the returned string, which the caller
|
|
|
|
must free.
|
|
|
|
\return newly allocated text buffer - must be free'd
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
char* text() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Replaces the entire contents of the text buffer
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void text(const char* text);
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
|
\return newly allocated text buffer - must be free'd
|
2010-04-07 03:00:56 +04:00
|
|
|
*/
|
2010-04-05 23:52:52 +04:00
|
|
|
char* text_range(int start, int end) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the character at the specified position pos in the buffer.
|
|
|
|
Positions start at 0
|
2010-04-07 03:00:56 +04:00
|
|
|
\param pos byte offset into buffer
|
|
|
|
\return Unicode UCS-4 encoded character
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
2010-04-07 03:00:56 +04:00
|
|
|
unsigned int character(int pos) const;
|
2010-04-05 23:52:52 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the text from the given rectangle. When you are done
|
|
|
|
with the text, free it using the free() function.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
char* text_in_rectangle(int start, int end, int rectStart, int rectEnd) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Inserts null-terminated string \p text at position \p pos.
|
2010-04-07 03:00:56 +04:00
|
|
|
\param pos insertion position as byte offset (must be utf-8 character aligned)
|
|
|
|
\param text utf-8 encoded and nul terminated text
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void insert(int pos, const char* text);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Appends the text string to the end of the buffer.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void append(const char* t) { insert(length(), t); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
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
|
|
|
|
\param end byte offset to charcatre after last character to be removed
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void remove(int start, int end);
|
|
|
|
|
|
|
|
/**
|
|
|
|
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
|
|
|
|
\param end byte offset to charcatre after last character to be removed
|
|
|
|
\param text utf-8 encoded and nul terminated text
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void replace(int start, int end, const char *text);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Copies text from one buffer to this one; fromBuf may
|
|
|
|
be the same as this.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void copy(Fl_Text_Buffer* fromBuf, int fromStart, int fromEnd, int toPos);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Undo text modification according to the undo variables or insert text
|
|
|
|
from the undo buffer
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int undo(int *cp=0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Lets the undo system know if we can undo changes
|
|
|
|
*/
|
|
|
|
void canUndo(char flag=1);
|
|
|
|
|
|
|
|
/**
|
|
|
|
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).
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int insertfile(const char *file, int pos, int buflen = 128*1024);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Appends the named file to the end of the buffer. 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).
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int appendfile(const char *file, int buflen = 128*1024)
|
|
|
|
{ return insertfile(file, length(), buflen); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
Loads a text file into the buffer
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
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); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
Writes the specified portions of the file 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).
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int outputfile(const char *file, int start, int end, int buflen = 128*1024);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Saves a text file from the current buffer
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int savefile(const char *file, int buflen = 128*1024)
|
|
|
|
{ return outputfile(file, 0, length(), buflen); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
Insert \p s columnwise into buffer starting at displayed character
|
|
|
|
position \p column on the line beginning at \p startPos. Opens a rectangular
|
|
|
|
space the width and height of \p s, by moving all text to the right of
|
|
|
|
\p column right. If \p charsInserted and \p charsDeleted are not NULL, the
|
|
|
|
number of characters inserted and deleted in the operation (beginning
|
|
|
|
at \p startPos) are returned in these arguments.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void insert_column(int column, int startPos, const char* text,
|
|
|
|
int* charsInserted, int* charsDeleted);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Replaces a rectangular area in the buffer, given by \p start, \p end,
|
|
|
|
\p rectStart, and \p rectEnd, with \p text. If \p text is vertically
|
|
|
|
longer than the rectangle, add extra lines to make room for it.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void replace_rectangular(int start, int end, int rectStart, int rectEnd,
|
|
|
|
const char* text);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Overlay \p text between displayed character positions \p rectStart and
|
|
|
|
\p rectEnd on the line beginning at \p startPos. If \p charsInserted and
|
|
|
|
\p charsDeleted are not NULL, the number of characters inserted and deleted
|
|
|
|
in the operation (beginning at \p startPos) are returned in these arguments.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void overlay_rectangular(int startPos, int rectStart, int rectEnd,
|
|
|
|
const char* text, int* charsInserted,
|
|
|
|
int* charsDeleted);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Removes a rectangular swath of characters between character positions start
|
|
|
|
and end and horizontal displayed-character offsets rectStart and rectEnd.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void remove_rectangular(int start, int end, int rectStart, int rectEnd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Clears text in the specified area.
|
|
|
|
It clears a rectangular "hole" out of the buffer between character positions
|
|
|
|
start and end and horizontal displayed-character offsets rectStart and
|
|
|
|
rectEnd.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void clear_rectangular(int start, int end, int rectStart, int rectEnd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Gets the tab width.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int tab_distance() const { return mTabDist; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
Set the hardware tab distance (width) used by all displays for this buffer,
|
|
|
|
and used in computing offsets for rectangular selection operations.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void tab_distance(int tabDist);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Selects a range of characters in the buffer.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void select(int start, int end);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a non 0 value if text has been selected, 0 otherwise
|
|
|
|
*/
|
|
|
|
int selected() const { return mPrimary.selected(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
Cancels any previous selection on the primary text selection object
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void unselect();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Achieves a rectangular selection on the primary text selection object
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void select_rectangular(int start, int end, int rectStart, int rectEnd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Gets the selection position
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int selection_position(int* start, int* end);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Gets the selection position, and rectangular selection info
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int selection_position(int* start, int* end, int* isRect, int* rectStart,
|
|
|
|
int* rectEnd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the currently selected text. When you are done with
|
|
|
|
the text, free it using the free() function.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
char* selection_text();
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
|
|
|
Removes the text in the primary selection.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void remove_selection();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Replaces the text in the primary selection.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void replace_selection(const char* text);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Selects a range of characters in the secondary selection.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void secondary_select(int start, int end);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a non 0 value if text has been selected in the secondary
|
|
|
|
text selection, 0 otherwise
|
|
|
|
*/
|
|
|
|
int secondary_selected() { return mSecondary.selected(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
Clears any selection in the secondary text selection object.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void secondary_unselect();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Achieves a rectangular selection on the secondary text selection object
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void secondary_select_rectangular(int start, int end, int rectStart,
|
|
|
|
int rectEnd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the current selection in the secondary text selection object.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int secondary_selection_position(int* start, int* end);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the current selection in the secondary text selection object.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int secondary_selection_position(int* start, int* end, int* isRect,
|
|
|
|
int* rectStart, int* rectEnd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the text in the secondary selection. When you are
|
|
|
|
done with the text, free it using the free() function.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
char* secondary_selection_text();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Removes the text from the buffer corresponding to the secondary text selection object.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void remove_secondary_selection();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Replaces the text from the buffer corresponding to the secondary
|
|
|
|
text selection object with the new string \p text.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void replace_secondary_selection(const char* text);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Highlights the specified text within the buffer.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void highlight(int start, int end);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the highlighted text. When you are done with the
|
|
|
|
text, free it using the free() function.
|
|
|
|
*/
|
|
|
|
int highlight() { return mHighlight.selected(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
Unhighlights text in the buffer.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void unhighlight();
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
|
|
|
Highlights a rectangular selection in the buffer
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void highlight_rectangular(int start, int end, int rectStart, int rectEnd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Highlights the specified text between \p start and \p end within the buffer.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int highlight_position(int* start, int* end);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Highlights the specified rectangle of text within the buffer.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int highlight_position(int* start, int* end, int* isRect, int* rectStart,
|
|
|
|
int* rectEnd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the highlighted text. When you are done with the
|
|
|
|
text, free it using the free() function.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
char* highlight_text();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Adds a callback function that is called whenever the text buffer is
|
|
|
|
modified. The callback function is declared as follows:
|
|
|
|
|
|
|
|
\code
|
|
|
|
typedef void (*Fl_Text_Modify_Cb)(int pos, int nInserted, int nDeleted,
|
|
|
|
int nRestyled, const char* deletedText,
|
|
|
|
void* cbArg);
|
|
|
|
\endcode
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void add_modify_callback(Fl_Text_Modify_Cb bufModifiedCB, void* cbArg);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Removes a modify callback.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void remove_modify_callback(Fl_Text_Modify_Cb bufModifiedCB, void* cbArg);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Calls all modify callbacks that have been registered using
|
|
|
|
the add_modify_callback()
|
|
|
|
method.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void call_modify_callbacks() { call_modify_callbacks(0, 0, 0, 0, 0); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
Adds a callback routine to be called before text is deleted from the buffer.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
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
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
|
|
|
Removes a callback routine \p bufPreDeleteCB associated with argument \p cbArg
|
|
|
|
to be called before text is deleted from the buffer.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void remove_predelete_callback(Fl_Text_Predelete_Cb predelCB, void* cbArg);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Calls the stored pre-delete callback procedure(s) for this buffer to update
|
|
|
|
the changed area(s) on the screen and any other listeners.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void call_predelete_callbacks() { call_predelete_callbacks(0, 0); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the text from the entire line containing the specified
|
|
|
|
character position. When you are done with the text, free it
|
|
|
|
using the free() function.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
char* line_text(int pos) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the position of the start of the line containing position \p pos.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int line_start(int pos) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
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-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int line_end(int pos) const;
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
|
|
|
Returns the position corresponding to the start of the word
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int word_start(int pos) const;
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
|
|
|
Returns the position corresponding to the end of the word.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int word_end(int pos) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Expands the given character to a displayable format. Tabs and
|
|
|
|
other control characters are given special treatment.
|
|
|
|
Get a character from the text buffer expanded into its screen
|
|
|
|
representation (which may be several characters for a tab or a
|
|
|
|
control code). Returns the number of characters written to \p outStr.
|
|
|
|
\p indent is the number of characters from the start of the line
|
|
|
|
for figuring tabs. Output string is guranteed to be shorter or
|
|
|
|
equal in length to FL_TEXT_MAX_EXP_CHAR_LEN
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int expand_character(int pos, int indent, char *outStr) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Expand a single character \p c from the text buffer into it's displayable
|
|
|
|
screen representation (which may be several characters for a tab or a
|
|
|
|
control code). Returns the number of characters added to \p outStr.
|
|
|
|
\p indent is the number of characters from the start of the line
|
|
|
|
for figuring tabs of length \p tabDist. Output string is guaranteed
|
2010-04-06 02:18:14 +04:00
|
|
|
to be shorter or equal in length to FL_TEXT_MAX_EXP_CHAR_LEN
|
2010-04-05 23:52:52 +04:00
|
|
|
Tabs and other control characters are given special treatment.
|
2010-04-06 02:18:14 +04:00
|
|
|
\param src address of utf-8 text
|
|
|
|
\param indent
|
|
|
|
\param[out] outStr write substitution here
|
|
|
|
\param tabDist
|
|
|
|
\return number of byte in substitution
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
2010-04-06 02:18:14 +04:00
|
|
|
static int expand_character(const char *src, int indent, char* outStr, int tabDist);
|
2010-04-05 23:52:52 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Return the length in displayed characters of character \p c expanded
|
2010-04-06 02:18:14 +04:00
|
|
|
for display (as discussed above in expand_character() ).
|
|
|
|
\param src address of utf-8 text
|
|
|
|
\param indent
|
|
|
|
\param tabDist
|
|
|
|
\return number of byte in substitution
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
2010-04-06 02:18:14 +04:00
|
|
|
static int character_width(const char *src, int indent, int tabDist);
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
|
|
|
Count the number of displayed characters between buffer position
|
|
|
|
\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-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
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
|
|
|
/**
|
|
|
|
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-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int skip_displayed_characters(int lineStartPos, int nChars);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Counts the number of newlines between \p startPos and \p endPos in buffer.
|
|
|
|
The character at position \p endPos is not counted.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int count_lines(int startPos, int endPos) const;
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2010-04-05 23:52:52 +04:00
|
|
|
/**
|
|
|
|
Finds the first character of the line \p nLines forward from \p startPos
|
|
|
|
in the buffer and returns its position
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int skip_lines(int startPos, int nLines);
|
|
|
|
|
|
|
|
/**
|
|
|
|
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-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int rewind_lines(int startPos, int nLines);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Finds the next occurrence of the specified character.
|
|
|
|
Search forwards in buffer for character \p searchChar, starting
|
|
|
|
with the character \p startPos, and returning the result in \p foundPos
|
|
|
|
returns 1 if found, 0 if not. (The difference between this and
|
|
|
|
BufSearchForward 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-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int findchar_forward(int startPos, char searchChar, int* foundPos) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Search backwards in buffer \p buf for character \p searchChar, starting
|
|
|
|
with the character BEFORE \p startPos, returning the result in \p foundPos
|
|
|
|
returns 1 if found, 0 if not. (The difference between this and
|
|
|
|
BufSearchBackward 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-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int findchar_backward(int startPos, char searchChar, int* foundPos) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Finds the next occurrence of the specified characters.
|
|
|
|
Search forwards in buffer for characters in \p searchChars, starting
|
|
|
|
with the character \p startPos, and returning the result in \p foundPos
|
|
|
|
returns 1 if found, 0 if not.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int findchars_forward(int startPos, const char* searchChars, int* foundPos) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Finds the previous occurrence of the specified characters.
|
|
|
|
Search backwards in buffer for characters in \p searchChars, starting
|
|
|
|
with the character BEFORE \p startPos, returning the result in \p foundPos
|
|
|
|
returns 1 if found, 0 if not.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int findchars_backward(int startPos, const char* searchChars, int* foundPos) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Search forwards in buffer for string \p searchString, starting with the
|
|
|
|
character \p startPos, and returning the result in \p foundPos
|
|
|
|
returns 1 if found, 0 if not.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int search_forward(int startPos, const char* searchString, int* foundPos,
|
|
|
|
int matchCase = 0) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Search backwards in buffer for string <i>searchCharssearchString</i>, starting with the
|
|
|
|
character BEFORE \p startPos, returning the result in \p foundPos
|
|
|
|
returns 1 if found, 0 if not.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int search_backward(int startPos, const char* searchString, int* foundPos,
|
|
|
|
int matchCase = 0) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the primary selection.
|
|
|
|
*/
|
|
|
|
const Fl_Text_Selection* primary_selection() const { return &mPrimary; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the primary selection.
|
|
|
|
*/
|
|
|
|
Fl_Text_Selection* primary_selection() { return &mPrimary; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the secondary selection.
|
|
|
|
*/
|
|
|
|
const Fl_Text_Selection* secondary_selection() const { return &mSecondary; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the current highlight selection.
|
|
|
|
*/
|
|
|
|
const Fl_Text_Selection* highlight_selection() const { return &mHighlight; }
|
|
|
|
|
|
|
|
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.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void call_modify_callbacks(int pos, int nDeleted, int nInserted,
|
|
|
|
int nRestyled, const char* deletedText) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Calls the stored pre-delete callback procedure(s) for this buffer to update
|
|
|
|
the changed area(s) on the screen and any other listeners.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void call_predelete_callbacks(int pos, int nDeleted) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Internal (non-redisplaying) version of BufInsert. Returns the length of
|
|
|
|
text inserted (this is just strlen(\p text), however 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-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
int insert_(int pos, const char* text);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Internal (non-redisplaying) version of BufRemove. Removes the contents
|
|
|
|
of the buffer between start and end (and moves the gap to the site of
|
|
|
|
the delete).
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void remove_(int start, int end);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Deletes a rectangle of text without calling the modify callbacks. Returns
|
|
|
|
the number of characters replacing those between \p start and \p end. Note that
|
|
|
|
in some pathological cases, deleting can actually increase the size of
|
|
|
|
the buffer because of tab expansions. \p endPos returns the buffer position
|
|
|
|
of the point in the last line where the text was removed (as a hint for
|
|
|
|
routines which need to position the cursor after a delete operation)
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void remove_rectangular_(int start, int end, int rectStart, int rectEnd,
|
|
|
|
int* replaceLen, int* endPos);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Inserts a column of text without calling the modify callbacks. Note that
|
|
|
|
in some pathological cases, inserting can actually decrease the size of
|
|
|
|
the buffer because of spaces being coalesced into tabs. \p nDeleted and
|
|
|
|
\p nInserted return the number of characters deleted and inserted beginning
|
|
|
|
at the start of the line containing \p startPos. \p endPos returns buffer
|
|
|
|
position of the lower left edge of the inserted column (as a hint for
|
|
|
|
routines which need to set a cursor position).
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void insert_column_(int column, int startPos, const char* insText,
|
|
|
|
int* nDeleted, int* nInserted, int* endPos);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Overlay a rectangular area of text without calling the modify callbacks.
|
|
|
|
\p nDeleted and \p nInserted return the number of characters deleted and
|
|
|
|
inserted beginning at the start of the line containing \p startPos.
|
|
|
|
\p endPos returns buffer position of the lower left edge of the inserted
|
|
|
|
column (as a hint for routines which need to set a cursor position).
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void overlay_rectangular_(int startPos, int rectStart, int rectEnd,
|
|
|
|
const char* insText, int* nDeleted,
|
|
|
|
int* nInserted, int* endPos);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Calls the stored redisplay procedure(s) for this buffer to update the
|
|
|
|
screen for a change in a selection.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void redisplay_selection(Fl_Text_Selection* oldSelection,
|
|
|
|
Fl_Text_Selection* newSelection) const;
|
|
|
|
|
2010-04-06 00:01:10 +04:00
|
|
|
/**
|
|
|
|
\todo unicode check
|
|
|
|
*/
|
2010-04-05 23:52:52 +04:00
|
|
|
void move_gap(int pos);
|
|
|
|
|
|
|
|
/**
|
|
|
|
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.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void reallocate_with_gap(int newGapStart, int newGapLen);
|
|
|
|
|
|
|
|
char* selection_text_(Fl_Text_Selection* sel) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Removes the text from the buffer corresponding to \p sel.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void remove_selection_(Fl_Text_Selection* sel);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Replaces the \p text in selection \p sel.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void replace_selection_(Fl_Text_Selection* sel, const char* text);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Finds the first and last character position in a line within a rectangular
|
|
|
|
selection (for copying). Includes tabs which cross rectStart, but not
|
|
|
|
control characters which do so. Leaves off tabs which cross rectEnd.
|
|
|
|
|
|
|
|
Technically, the calling routine should convert tab characters which
|
|
|
|
cross the right boundary of the selection to spaces which line up with
|
|
|
|
the edge of the selection. Unfortunately, the additional memory
|
|
|
|
management required in the parent routine to allow for the changes
|
|
|
|
in string size is not worth all the extra work just for a couple of
|
|
|
|
shifted characters, so if a tab protrudes, just lop it off and hope
|
|
|
|
that there are other characters in the selection to establish the right
|
|
|
|
margin for subsequent columnar pastes of this data.
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void rectangular_selection_boundaries(int lineStartPos, int rectStart,
|
|
|
|
int rectEnd, int* selStart,
|
|
|
|
int* selEnd) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Updates all of the selections in the buffer for changes in the buffer's text
|
2010-04-06 00:01:10 +04:00
|
|
|
\todo unicode check
|
2010-04-05 23:52:52 +04:00
|
|
|
*/
|
|
|
|
void update_selections(int pos, int nDeleted, int nInserted);
|
|
|
|
|
2010-04-06 02:18:14 +04:00
|
|
|
/**
|
|
|
|
Convert a byte offset in buffer into a memory address.
|
|
|
|
*/
|
|
|
|
const char *address(int pos) const
|
|
|
|
{ return (pos < mGapStart) ? mBuf+pos : mBuf+pos+mGapEnd-mGapStart; }
|
2010-04-06 02:26:29 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Convert a byte offset in buffer into a memory address.
|
|
|
|
*/
|
2010-04-06 02:18:14 +04:00
|
|
|
char *address(int pos)
|
|
|
|
{ return (pos < mGapStart) ? mBuf+pos : mBuf+pos+mGapEnd-mGapStart; }
|
|
|
|
|
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
|
|
|
|
of the buffer itself must be calculated:
|
|
|
|
gapEnd - gapStart + length) */
|
|
|
|
char* mBuf; /**< allocated memory where the text is stored */
|
|
|
|
int mGapStart; /**< points to the first character of the gap */
|
|
|
|
int mGapEnd; /**< points to the first char 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 mUseTabs; /**< True if buffer routines are allowed to use
|
|
|
|
tabs for padding in rectangular operations */
|
|
|
|
int mNModifyProcs; /**< number of modify-redisplay procs attached */
|
|
|
|
Fl_Text_Modify_Cb* /**< procedures to call when buffer is */
|
|
|
|
mModifyProcs; /**< modified to redisplay contents */
|
|
|
|
void** mCbArgs; /**< caller arguments for modifyProcs above */
|
|
|
|
int mNPredeleteProcs; /**< number of pre-delete procs attached */
|
|
|
|
Fl_Text_Predelete_Cb* /**< procedure to call before text is deleted */
|
|
|
|
mPredeleteProcs; /**< from the buffer; at most one is supported. */
|
|
|
|
void **mPredeleteCbArgs; /**< caller argument for pre-delete proc above */
|
|
|
|
int mCursorPosHint; /**< hint for reasonable cursor position after
|
|
|
|
a buffer modification operation */
|
|
|
|
char mCanUndo; /**< if this buffer is used for attributes, it must
|
|
|
|
not do any undo calls */
|
|
|
|
int mPreferredGapSize; /**< the default allocation for the text gap is 1024
|
|
|
|
bytes and should only be increased if frequent
|
|
|
|
and large changes in buffer size are expected */
|
2001-08-02 01:24:49 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// End of "$Id$".
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|