fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
  SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation)  

Fl_Text_Buffer Class Reference

This class manages unicode displayed in one or more Fl_Text_Display widgets. More...

#include <Fl_Text_Buffer.H>

Collaboration diagram for Fl_Text_Buffer:

List of all members.

Public Member Functions

 Fl_Text_Buffer (int requestedSize=0, int preferredGapSize=1024)
 ~Fl_Text_Buffer ()
int length () const
 Returns the number of bytes in the buffer.
char * text () const
 Get a copy of the entire contents of the text buffer. Memory is allocated to contain the returned string, which the caller must free.
void text (const char *text)
char * text_range (int start, int end) const
 Get a copy of a part of the text buffer. Return a copy of the text between start and end character positions from text buffer buf. Positions start at 0, and the range does not include the character pointed to by end. When you are done with the text, free it using the free() function.
unsigned int char_at (int pos) const
char byte_at (int pos) const
const char * address (int pos) const
char * address (int pos)
void insert (int pos, const char *text)
void append (const char *t)
void remove (int start, int end)
void replace (int start, int end, const char *text)
void copy (Fl_Text_Buffer *fromBuf, int fromStart, int fromEnd, int toPos)
int undo (int *cp=0)
void canUndo (char flag=1)
int insertfile (const char *file, int pos, int buflen=128 *1024)
int appendfile (const char *file, int buflen=128 *1024)
int loadfile (const char *file, int buflen=128 *1024)
int outputfile (const char *file, int start, int end, int buflen=128 *1024)
int savefile (const char *file, int buflen=128 *1024)
int tab_distance () const
void tab_distance (int tabDist)
void select (int start, int end)
int selected () const
void unselect ()
int selection_position (int *start, int *end)
char * selection_text ()
void remove_selection ()
void replace_selection (const char *text)
void secondary_select (int start, int end)
int secondary_selected ()
void secondary_unselect ()
int secondary_selection_position (int *start, int *end)
char * secondary_selection_text ()
void remove_secondary_selection ()
void replace_secondary_selection (const char *text)
void highlight (int start, int end)
int highlight ()
void unhighlight ()
int highlight_position (int *start, int *end)
char * highlight_text ()
void add_modify_callback (Fl_Text_Modify_Cb bufModifiedCB, void *cbArg)
void remove_modify_callback (Fl_Text_Modify_Cb bufModifiedCB, void *cbArg)
void call_modify_callbacks ()
void add_predelete_callback (Fl_Text_Predelete_Cb bufPredelCB, void *cbArg)
void remove_predelete_callback (Fl_Text_Predelete_Cb predelCB, void *cbArg)
void call_predelete_callbacks ()
char * line_text (int pos) const
int line_start (int pos) const
int line_end (int pos) const
int word_start (int pos) const
int word_end (int pos) const
int count_displayed_characters (int lineStartPos, int targetPos) const
int skip_displayed_characters (int lineStartPos, int nChars)
int count_lines (int startPos, int endPos) const
int skip_lines (int startPos, int nLines)
int rewind_lines (int startPos, int nLines)
int findchar_forward (int startPos, unsigned searchChar, int *foundPos) const
int findchar_backward (int startPos, unsigned int searchChar, int *foundPos) const
int search_forward (int startPos, const char *searchString, int *foundPos, int matchCase=0) const
int search_backward (int startPos, const char *searchString, int *foundPos, int matchCase=0) const
const Fl_Text_Selectionprimary_selection () const
Fl_Text_Selectionprimary_selection ()
const Fl_Text_Selectionsecondary_selection () const
const Fl_Text_Selectionhighlight_selection () const
int prev_char (int ix) const
int prev_char_clipped (int ix) const
int next_char (int ix) const
int next_char_clipped (int ix) const
int utf8_align (int) const

Public Attributes

int input_file_was_transcoded
 true iff the loaded file has been transcoded to UTF-8
void(* transcoding_warning_action )(Fl_Text_Buffer *)
 Pointer to a function called after reading a non UTF-8 encoded file.

Static Public Attributes

static const char * file_encoding_warning_message = "Some changes may have occurred."

Protected Member Functions

void call_modify_callbacks (int pos, int nDeleted, int nInserted, int nRestyled, const char *deletedText) const
void call_predelete_callbacks (int pos, int nDeleted) const
int insert_ (int pos, const char *text)
void remove_ (int start, int end)
void redisplay_selection (Fl_Text_Selection *oldSelection, Fl_Text_Selection *newSelection) const
void move_gap (int pos)
void reallocate_with_gap (int newGapStart, int newGapLen)
char * selection_text_ (Fl_Text_Selection *sel) const
void remove_selection_ (Fl_Text_Selection *sel)
void replace_selection_ (Fl_Text_Selection *sel, const char *text)
void update_selections (int pos, int nDeleted, int nInserted)

Protected Attributes

Fl_Text_Selection mPrimary
Fl_Text_Selection mSecondary
Fl_Text_Selection mHighlight
int mLength
char * mBuf
int mGapStart
int mGapEnd
int mTabDist
int mNModifyProcs
Fl_Text_Modify_CbmModifyProcs
void ** mCbArgs
int mNPredeleteProcs
Fl_Text_Predelete_CbmPredeleteProcs
void ** mPredeleteCbArgs
int mCursorPosHint
char mCanUndo
int mPreferredGapSize

Detailed Description

This class manages unicode displayed in one or more Fl_Text_Display widgets.

All text in Fl_Text_Buffermust 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 character will return that in an unsiged int in UCS-4 encoding.

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/.

Definition at line 168 of file Fl_Text_Buffer.H.


Constructor & Destructor Documentation

Fl_Text_Buffer::Fl_Text_Buffer ( int  requestedSize = 0,
int  preferredGapSize = 1024 
)

Create an empty text buffer of a pre-determined size.

Parameters:
requestedSizeuse this to avoid unnecessary re-allocation if you know exactly how much the buffer will need to hold
preferredGapSizeInitial size for the buffer gap (empty space in the buffer where text might be inserted if the user is typing sequential chars)

Definition at line 114 of file Fl_Text_Buffer.cxx.

References input_file_was_transcoded, mBuf, mCanUndo, mCbArgs, mCursorPosHint, Fl_Text_Selection::mEnd, mGapEnd, mGapStart, mHighlight, mLength, mModifyProcs, mNModifyProcs, mNPredeleteProcs, mPredeleteCbArgs, mPredeleteProcs, mPreferredGapSize, mPrimary, mSecondary, Fl_Text_Selection::mSelected, Fl_Text_Selection::mStart, mTabDist, NULL, and transcoding_warning_action.

Fl_Text_Buffer::~Fl_Text_Buffer ( )

Frees a text buffer

Definition at line 144 of file Fl_Text_Buffer.cxx.

References mBuf, mCbArgs, mModifyProcs, mNModifyProcs, mNPredeleteProcs, mPredeleteCbArgs, and mPredeleteProcs.


Member Function Documentation

void Fl_Text_Buffer::add_modify_callback ( Fl_Text_Modify_Cb  bufModifiedCB,
void *  cbArg 
)

Adds a callback function that is called whenever the text buffer is modified. The callback function is declared as follows:

   typedef void (*Fl_Text_Modify_Cb)(int pos, int nInserted, int nDeleted,
      int nRestyled, const char* deletedText,
      void* cbArg);

Definition at line 657 of file Fl_Text_Buffer.cxx.

References i, mCbArgs, mModifyProcs, and mNModifyProcs.

Referenced by Fl_Text_Display::buffer(), and CodeEditor::CodeEditor().

void Fl_Text_Buffer::add_predelete_callback ( Fl_Text_Predelete_Cb  bufPredelCB,
void *  cbArg 
)

Adds a callback routine to be called before text is deleted from the buffer.

Definition at line 733 of file Fl_Text_Buffer.cxx.

References i, mNPredeleteProcs, mPredeleteCbArgs, and mPredeleteProcs.

Referenced by Fl_Text_Display::buffer().

const char* Fl_Text_Buffer::address ( int  pos) const [inline]

Convert a byte offset in buffer into a memory address.

Parameters:
posbyte offset into buffer
Returns:
byte offset converted to a memory address

Definition at line 239 of file Fl_Text_Buffer.H.

Referenced by byte_at(), char_at(), search_backward(), search_forward(), and Fl_Text_Display::wrapped_line_counter().

char* Fl_Text_Buffer::address ( int  pos) [inline]

Convert a byte offset in buffer into a memory address.

Parameters:
posbyte offset into buffer
Returns:
byte offset converted to a memory address

Definition at line 247 of file Fl_Text_Buffer.H.

void Fl_Text_Buffer::append ( const char *  t) [inline]

Appends the text string to the end of the buffer.

Parameters:
tutf-8 encoded and nul terminated text

Definition at line 261 of file Fl_Text_Buffer.H.

References length.

Referenced by do_shell_command(), and shell_pipe_cb().

int Fl_Text_Buffer::appendfile ( const char *  file,
int  buflen = 128*1024 
) [inline]

Appends the named file to the end of the buffer. See also insertfile().

Definition at line 314 of file Fl_Text_Buffer.H.

References length.

char Fl_Text_Buffer::byte_at ( int  pos) const

Returns the raw byte at the specified position pos in the buffer. Positions start at 0

Parameters:
posbyte offset into buffer
Returns:
unencoded raw byte

Definition at line 262 of file Fl_Text_Buffer.cxx.

References address(), and mLength.

Referenced by Fl_Text_Display::measure_proportional_character(), next_char(), Fl_Text_Display::position_style(), prev_char_clipped(), and utf8_align().

void Fl_Text_Buffer::call_modify_callbacks ( int  pos,
int  nDeleted,
int  nInserted,
int  nRestyled,
const char *  deletedText 
) const [protected]

Calls the stored modify callback procedure(s) for this buffer to update the changed area(s) on the screen and any other listeners.

Definition at line 1313 of file Fl_Text_Buffer.cxx.

References i, IS_UTF8_ALIGNED2, mCbArgs, mModifyProcs, and mNModifyProcs.

void Fl_Text_Buffer::call_modify_callbacks ( ) [inline]

Calls all modify callbacks that have been registered using the add_modify_callback() method.

Definition at line 471 of file Fl_Text_Buffer.H.

References call_modify_callbacks().

Referenced by call_modify_callbacks(), insert(), redisplay_selection(), remove(), replace(), tab_distance(), and text().

void Fl_Text_Buffer::call_predelete_callbacks ( int  pos,
int  nDeleted 
) const [protected]

Calls the stored pre-delete callback procedure(s) for this buffer to update the changed area(s) on the screen and any other listeners.

Definition at line 1327 of file Fl_Text_Buffer.cxx.

References i, mNPredeleteProcs, mPredeleteCbArgs, and mPredeleteProcs.

void Fl_Text_Buffer::call_predelete_callbacks ( ) [inline]

Calls the stored pre-delete callback procedure(s) for this buffer to update the changed area(s) on the screen and any other listeners.

Definition at line 488 of file Fl_Text_Buffer.H.

References call_predelete_callbacks().

Referenced by call_predelete_callbacks(), insert(), remove(), replace(), tab_distance(), and text().

void Fl_Text_Buffer::canUndo ( char  flag = 1)

Lets the undo system know if we can undo changes

Definition at line 453 of file Fl_Text_Buffer.cxx.

References flag, and mCanUndo.

Referenced by Fl_Text_Display::highlight_data().

unsigned int Fl_Text_Buffer::char_at ( int  pos) const

Returns the character at the specified position pos in the buffer. Positions start at 0

Parameters:
posbyte offset into buffer, pos must be at acharacter boundary
Returns:
Unicode UCS-4 encoded character

Definition at line 247 of file Fl_Text_Buffer.cxx.

References address(), fl_utf8decode(), IS_UTF8_ALIGNED2, and mLength.

Referenced by Fl_Text_Display::find_wrap_range(), findchar_backward(), findchar_forward(), Fl_Text_Display::measure_deleted_lines(), Fl_Text_Display::overstrike(), search_backward(), search_forward(), skip_displayed_characters(), word_end(), word_start(), Fl_Text_Display::wrap_uses_character(), and Fl_Text_Display::wrapped_line_counter().

void Fl_Text_Buffer::copy ( Fl_Text_Buffer fromBuf,
int  fromStart,
int  fromEnd,
int  toPos 
)

Copies text from one buffer to this one.

Parameters:
fromBufsource text buffer may be the same as this
fromStartbyte offset into buffer
fromEndbyte offset into buffer
toPosdestination byte offset into buffer

Definition at line 369 of file Fl_Text_Buffer.cxx.

References IS_UTF8_ALIGNED2, mBuf, mGapEnd, mGapStart, mLength, move_gap(), mPreferredGapSize, reallocate_with_gap(), and update_selections().

Referenced by Fl_Text_Display::find_wrap_range().

int Fl_Text_Buffer::count_displayed_characters ( int  lineStartPos,
int  targetPos 
) const

Count the number of displayed characters between buffer position lineStartPos and targetPos. (displayed characters are the characters shown on the screen to represent characters in the buffer, where tabs and control characters are expanded)

Definition at line 869 of file Fl_Text_Buffer.cxx.

References IS_UTF8_ALIGNED2, and next_char().

Referenced by Fl_Text_Display::overstrike(), Fl_Text_Display::position_to_linecol(), and Fl_Text_Display::wrapped_column().

int Fl_Text_Buffer::count_lines ( int  startPos,
int  endPos 
) const

Counts the number of newlines between startPos and endPos in buffer. The character at position endPos is not counted.

Definition at line 911 of file Fl_Text_Buffer.cxx.

References IS_UTF8_ALIGNED2, mBuf, mGapEnd, mGapStart, and mLength.

Referenced by Fl_Text_Display::absolute_top_line_number(), Fl_Text_Display::buffer_modified_cb(), Fl_Text_Display::count_lines(), Fl_Text_Display::position_to_linecol(), and Fl_Text_Display::wrapped_row().

int Fl_Text_Buffer::findchar_backward ( int  startPos,
unsigned int  searchChar,
int *  foundPos 
) const

Search backwards in buffer buf for character searchChar, starting with the character BEFORE startPos, returning the result in 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)

Parameters:
startPosbyte offset to start position
searchCharUCS-4 character that we want to find
foundPosbyte offset where the character was found
Returns:
1 if found, 0 if not

Definition at line 1502 of file Fl_Text_Buffer.cxx.

References char_at(), mLength, and prev_char().

Referenced by line_start().

int Fl_Text_Buffer::findchar_forward ( int  startPos,
unsigned  searchChar,
int *  foundPos 
) const

Finds the next occurrence of the specified character. Search forwards in buffer for character searchChar, starting with the character startPos, and returning the result in 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)

Parameters:
startPosbyte offset to start position
searchCharUCS-4 character that we want to find
foundPosbyte offset where the character was found
Returns:
1 if found, 0 if not

Definition at line 1475 of file Fl_Text_Buffer.cxx.

References char_at(), mLength, and next_char().

Referenced by line_end().

void Fl_Text_Buffer::highlight ( int  start,
int  end 
)

Highlights the specified text within the buffer.

Definition at line 615 of file Fl_Text_Buffer.cxx.

References mHighlight, redisplay_selection(), and Fl_Text_Selection::set().

int Fl_Text_Buffer::highlight ( ) [inline]

Returns the highlighted text. When you are done with the text, free it using the free() function.

Definition at line 431 of file Fl_Text_Buffer.H.

int Fl_Text_Buffer::highlight_position ( int *  start,
int *  end 
)

Highlights the specified text between start and end within the buffer.

Definition at line 639 of file Fl_Text_Buffer.cxx.

References mHighlight, and Fl_Text_Selection::position().

const Fl_Text_Selection* Fl_Text_Buffer::highlight_selection ( ) const [inline]

Returns the current highlight selection.

Definition at line 639 of file Fl_Text_Buffer.H.

Referenced by Fl_Text_Display::position_style().

char * Fl_Text_Buffer::highlight_text ( )

Returns the highlighted text. When you are done with the text, free it using the free() function.

Definition at line 648 of file Fl_Text_Buffer.cxx.

References mHighlight, and selection_text_().

void Fl_Text_Buffer::insert ( int  pos,
const char *  text 
)

Inserts null-terminated string text at position pos.

Parameters:
posinsertion position as byte offset (must be utf-8 character aligned)
textutf-8 encoded and nul terminated text

Definition at line 274 of file Fl_Text_Buffer.cxx.

References call_modify_callbacks(), call_predelete_callbacks(), insert_(), IS_UTF8_ALIGNED, IS_UTF8_ALIGNED2, mCursorPosHint, mLength, and NULL.

Referenced by Fl_Text_Display::find_wrap_range(), Fl_Text_Display::insert(), insertfile(), and undo().

int Fl_Text_Buffer::insert_ ( int  pos,
const char *  text 
) [protected]

Internal (non-redisplaying) version of BufInsert. Returns the length of text inserted (this is just strlen(text), however this calculation can be expensive and the length will be required by any caller who will continue on to call redisplay). pos must be contiguous with the existing text in the buffer (i.e. not past the end).

Returns:
the number of bytes inserted

Definition at line 1124 of file Fl_Text_Buffer.cxx.

References mBuf, mCanUndo, mGapEnd, mGapStart, mLength, move_gap(), mPreferredGapSize, reallocate_with_gap(), and update_selections().

Referenced by insert(), and replace().

int Fl_Text_Buffer::insertfile ( const char *  file,
int  pos,
int  buflen = 128*1024 
)

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 UTF-8-transcoded data. By default, the message Fl_Text_Buffer::file_encoding_warning_message will warn the user about this.

See also:
input_file_was_transcoded and transcoding_warning_action.

Definition at line 1658 of file Fl_Text_Buffer.cxx.

References endline, fl_fopen(), fp, input_file_was_transcoded, insert(), and transcoding_warning_action.

int Fl_Text_Buffer::line_end ( int  pos) const

Finds and returns the position of the end of the line containing position 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)

Parameters:
posbyte index into buffer
Returns:
byte offset to line end

Definition at line 829 of file Fl_Text_Buffer.cxx.

References findchar_forward(), and mLength.

Referenced by Fl_Text_Display::buffer_modified_cb(), Fl_Text_Display::extend_range_for_styles(), Fl_Text_Display::find_line_end(), Fl_Text_Display::line_end(), and line_text().

int Fl_Text_Buffer::line_start ( int  pos) const

Returns the position of the start of the line containing position pos.

Parameters:
posbyte index into buffer
Returns:
byte offset to line start

Definition at line 818 of file Fl_Text_Buffer.cxx.

References findchar_backward().

Referenced by Fl_Text_Display::find_wrap_range(), Fl_Text_Display::line_start(), line_text(), Fl_Text_Display::measure_deleted_lines(), Fl_Text_Display::overstrike(), Fl_Text_Display::rewind_lines(), and Fl_Text_Display::wrapped_column().

char * Fl_Text_Buffer::line_text ( int  pos) const

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.

Parameters:
posbyte index into buffer
Returns:
copy of utf8 text, must be free'd

Definition at line 810 of file Fl_Text_Buffer.cxx.

References line_end(), line_start(), and text_range().

int Fl_Text_Buffer::loadfile ( const char *  file,
int  buflen = 128*1024 
) [inline]

Loads a text file into the buffer. See also insertfile().

Definition at line 320 of file Fl_Text_Buffer.H.

References length, and select().

void Fl_Text_Buffer::move_gap ( int  pos) [protected]

Move the gap to start at a new position.

Definition at line 1393 of file Fl_Text_Buffer.cxx.

References mBuf, mGapEnd, and mGapStart.

Referenced by copy(), insert_(), and remove_().

int Fl_Text_Buffer::next_char_clipped ( int  ix) const

Definition at line 1774 of file Fl_Text_Buffer.cxx.

References next_char().

int Fl_Text_Buffer::outputfile ( const char *  file,
int  start,
int  end,
int  buflen = 128*1024 
)

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).

Definition at line 1699 of file Fl_Text_Buffer.cxx.

References fl_fopen(), fp, min, and text_range().

int Fl_Text_Buffer::prev_char ( int  ix) const

Returns the index of the previous character.

Parameters:
ixindex to the current char

Definition at line 1747 of file Fl_Text_Buffer.cxx.

References prev_char_clipped().

Referenced by Fl_Text_Display::find_wrap_range(), findchar_backward(), Fl_Text_Display::previous_word(), search_backward(), Fl_Text_Display::vline_length(), word_start(), and Fl_Text_Display::wrapped_line_counter().

int Fl_Text_Buffer::prev_char_clipped ( int  ix) const
const Fl_Text_Selection* Fl_Text_Buffer::primary_selection ( ) const [inline]
Fl_Text_Selection* Fl_Text_Buffer::primary_selection ( ) [inline]

Returns the primary selection.

Definition at line 629 of file Fl_Text_Buffer.H.

void Fl_Text_Buffer::reallocate_with_gap ( int  newGapStart,
int  newGapLen 
) [protected]

Reallocates the text storage in the buffer to have a gap starting at newGapStart and a gap size of newGapLen, preserving the buffer's current contents.

Definition at line 1410 of file Fl_Text_Buffer.cxx.

References mBuf, mGapEnd, mGapStart, and mLength.

Referenced by copy(), and insert_().

void Fl_Text_Buffer::redisplay_selection ( Fl_Text_Selection oldSelection,
Fl_Text_Selection newSelection 
) const [protected]

Calls the stored redisplay procedure(s) for this buffer to update the screen for a change in a selection.

Definition at line 1337 of file Fl_Text_Buffer.cxx.

References call_modify_callbacks(), Fl_Text_Selection::mEnd, min, Fl_Text_Selection::mSelected, Fl_Text_Selection::mStart, and NULL.

Referenced by highlight(), replace_selection_(), secondary_select(), secondary_unselect(), select(), unhighlight(), and unselect().

void Fl_Text_Buffer::remove ( int  start,
int  end 
)

Deletes a range of characters in the buffer.

Parameters:
startbyte offset to first character to be removed
endbyte offset to charcatre after last character to be removed

Definition at line 332 of file Fl_Text_Buffer.cxx.

References call_modify_callbacks(), call_predelete_callbacks(), IS_UTF8_ALIGNED2, mCursorPosHint, mLength, remove_(), start, and text_range().

void Fl_Text_Buffer::remove_ ( int  start,
int  end 
) [protected]

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).

Definition at line 1167 of file Fl_Text_Buffer.cxx.

References mBuf, mCanUndo, mGapEnd, mGapStart, mLength, move_gap(), start, and update_selections().

Referenced by remove(), and replace().

void Fl_Text_Buffer::remove_modify_callback ( Fl_Text_Modify_Cb  bufModifiedCB,
void *  cbArg 
)

Removes a modify callback.

Definition at line 682 of file Fl_Text_Buffer.cxx.

References Fl::error, i, mCbArgs, mModifyProcs, mNModifyProcs, and NULL.

Referenced by Fl_Text_Display::buffer(), and Fl_Text_Display::~Fl_Text_Display().

void Fl_Text_Buffer::remove_predelete_callback ( Fl_Text_Predelete_Cb  predelCB,
void *  cbArg 
)

Removes a callback routine bufPreDeleteCB associated with argument cbArg to be called before text is deleted from the buffer.

Definition at line 758 of file Fl_Text_Buffer.cxx.

References Fl::error, i, mNPredeleteProcs, mPredeleteCbArgs, mPredeleteProcs, and NULL.

Referenced by Fl_Text_Display::buffer(), and Fl_Text_Display::~Fl_Text_Display().

void Fl_Text_Buffer::remove_secondary_selection ( )

Removes the text from the buffer corresponding to the secondary text selection object.

Definition at line 596 of file Fl_Text_Buffer.cxx.

References mSecondary, and remove_selection_().

void Fl_Text_Buffer::remove_selection ( )

Removes the text in the primary selection.

Definition at line 535 of file Fl_Text_Buffer.cxx.

References mPrimary, and remove_selection_().

Referenced by Fl_Text_Editor::handle().

void Fl_Text_Buffer::remove_selection_ ( Fl_Text_Selection sel) [protected]

Removes the text from the buffer corresponding to sel.

Definition at line 1274 of file Fl_Text_Buffer.cxx.

References Fl_Text_Selection::position(), and start.

Referenced by remove_secondary_selection(), and remove_selection().

void Fl_Text_Buffer::replace ( int  start,
int  end,
const char *  text 
)

Deletes the characters between start and end, and inserts the null-terminated string text in their place in the buffer.

Parameters:
startbyte offset to first character to be removed and new insert position
endbyte offset to charcatre after last character to be removed
textutf-8 encoded and nul terminated text

Definition at line 304 of file Fl_Text_Buffer.cxx.

References call_modify_callbacks(), call_predelete_callbacks(), insert_(), IS_UTF8_ALIGNED, IS_UTF8_ALIGNED2, mCursorPosHint, mLength, remove_(), and text_range().

Referenced by Fl_Text_Display::overstrike(), replace_selection_(), and undo().

void Fl_Text_Buffer::replace_secondary_selection ( const char *  text)

Replaces the text from the buffer corresponding to the secondary text selection object with the new string text.

Definition at line 605 of file Fl_Text_Buffer.cxx.

References mSecondary, and replace_selection_().

void Fl_Text_Buffer::replace_selection ( const char *  text)

Replaces the text in the primary selection.

Definition at line 544 of file Fl_Text_Buffer.cxx.

References mPrimary, and replace_selection_().

void Fl_Text_Buffer::replace_selection_ ( Fl_Text_Selection sel,
const char *  text 
) [protected]

Replaces the text in selection sel.

Definition at line 1289 of file Fl_Text_Buffer.cxx.

References Fl_Text_Selection::mSelected, Fl_Text_Selection::position(), redisplay_selection(), replace(), and start.

Referenced by replace_secondary_selection(), and replace_selection().

int Fl_Text_Buffer::rewind_lines ( int  startPos,
int  nLines 
)

Finds and returns the position of the first character of the line nLines backwards from startPos (not counting the character pointed to by startpos if that is a newline) in the buffer. nLines == 0 means find the beginning of the line

Definition at line 979 of file Fl_Text_Buffer.cxx.

References IS_UTF8_ALIGNED2, mBuf, mGapEnd, and mGapStart.

Referenced by Fl_Text_Display::rewind_lines().

int Fl_Text_Buffer::savefile ( const char *  file,
int  buflen = 128*1024 
) [inline]

Saves a text file from the current buffer

Definition at line 334 of file Fl_Text_Buffer.H.

References length.

int Fl_Text_Buffer::search_backward ( int  startPos,
const char *  searchString,
int *  foundPos,
int  matchCase = 0 
) const

Search backwards in buffer for string searchCharssearchString, starting with the character BEFORE startPos, returning the result in foundPos returns 1 if found, 0 if not.

Parameters:
startPosbyte offset to start position
searchStringutf8 string that we want to find
foundPosbyte offset where the string was found
matchCaseif set, match character case
Returns:
1 if found, 0 if not

Definition at line 1066 of file Fl_Text_Buffer.cxx.

References address(), b, char_at(), fl_tolower(), fl_utf8decode(), fl_utf8len1(), IS_UTF8_ALIGNED, IS_UTF8_ALIGNED2, next_char(), and prev_char().

int Fl_Text_Buffer::search_forward ( int  startPos,
const char *  searchString,
int *  foundPos,
int  matchCase = 0 
) const

Search forwards in buffer for string searchString, starting with the character startPos, and returning the result in foundPos returns 1 if found, 0 if not.

Parameters:
startPosbyte offset to start position
searchStringutf8 string that we want to find
foundPosbyte offset where the string was found
matchCaseif set, match character case
Returns:
1 if found, 0 if not

Definition at line 1014 of file Fl_Text_Buffer.cxx.

References address(), b, char_at(), fl_tolower(), fl_utf8decode(), fl_utf8len1(), IS_UTF8_ALIGNED, IS_UTF8_ALIGNED2, length(), and next_char().

void Fl_Text_Buffer::secondary_select ( int  start,
int  end 
)

Selects a range of characters in the secondary selection.

Definition at line 554 of file Fl_Text_Buffer.cxx.

References mSecondary, redisplay_selection(), and Fl_Text_Selection::set().

int Fl_Text_Buffer::secondary_selected ( ) [inline]

Returns a non 0 value if text has been selected in the secondary text selection, 0 otherwise

Definition at line 393 of file Fl_Text_Buffer.H.

const Fl_Text_Selection* Fl_Text_Buffer::secondary_selection ( ) const [inline]

Returns the secondary selection.

Definition at line 634 of file Fl_Text_Buffer.H.

Referenced by Fl_Text_Display::position_style().

int Fl_Text_Buffer::secondary_selection_position ( int *  start,
int *  end 
)

Returns the current selection in the secondary text selection object.

Definition at line 578 of file Fl_Text_Buffer.cxx.

References mSecondary, and Fl_Text_Selection::position().

char * Fl_Text_Buffer::secondary_selection_text ( )

Returns the text in the secondary selection. When you are done with the text, free it using the free() function.

Definition at line 587 of file Fl_Text_Buffer.cxx.

References mSecondary, and selection_text_().

void Fl_Text_Buffer::secondary_unselect ( )

Clears any selection in the secondary text selection object.

Definition at line 566 of file Fl_Text_Buffer.cxx.

References mSecondary, Fl_Text_Selection::mSelected, and redisplay_selection().

void Fl_Text_Buffer::select ( int  start,
int  end 
)

Selects a range of characters in the buffer.

Definition at line 490 of file Fl_Text_Buffer.cxx.

References IS_UTF8_ALIGNED2, mPrimary, redisplay_selection(), and Fl_Text_Selection::set().

Referenced by Fl_Text_Display::handle(), and Fl_Text_Editor::handle_key().

int Fl_Text_Buffer::selected ( ) const [inline]

Returns a non 0 value if text has been selected, 0 otherwise

Definition at line 356 of file Fl_Text_Buffer.H.

int Fl_Text_Buffer::selection_position ( int *  start,
int *  end 
)

Gets the selection position

Definition at line 517 of file Fl_Text_Buffer.cxx.

References mPrimary, and Fl_Text_Selection::position().

char * Fl_Text_Buffer::selection_text ( )

Returns the currently selected text. When you are done with the text, free it using the free() function.

Definition at line 526 of file Fl_Text_Buffer.cxx.

References mPrimary, and selection_text_().

Referenced by Fl_Text_Display::handle().

char * Fl_Text_Buffer::selection_text_ ( Fl_Text_Selection sel) const [protected]
int Fl_Text_Buffer::skip_displayed_characters ( int  lineStartPos,
int  nChars 
)

Count forward from buffer position 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)

Parameters:
lineStartPosbyte offset into buffer
nCharsnumber of bytes that are sent to the display
Returns:
byte offset in input after all output bytes are sent

Definition at line 890 of file Fl_Text_Buffer.cxx.

References char_at(), IS_UTF8_ALIGNED2, mLength, and next_char().

int Fl_Text_Buffer::skip_lines ( int  startPos,
int  nLines 
)

Finds the first character of the line nLines forward from startPos in the buffer and returns its position

Definition at line 941 of file Fl_Text_Buffer.cxx.

References IS_UTF8_ALIGNED2, mBuf, mGapEnd, mGapStart, and mLength.

Referenced by Fl_Text_Display::skip_lines().

int Fl_Text_Buffer::tab_distance ( ) const [inline]

Gets the tab width.

Definition at line 340 of file Fl_Text_Buffer.H.

void Fl_Text_Buffer::tab_distance ( int  tabDist)

Set the hardware tab distance (width) used by all displays for this buffer, and used in computing offsets for rectangular selection operations.

Definition at line 469 of file Fl_Text_Buffer.cxx.

References call_modify_callbacks(), call_predelete_callbacks(), mLength, mTabDist, and text().

void Fl_Text_Buffer::text ( const char *  text)

Replaces the entire contents of the text buffer.

Parameters:
textText must be valid utf8.

Definition at line 174 of file Fl_Text_Buffer.cxx.

References call_modify_callbacks(), call_predelete_callbacks(), IS_UTF8_ALIGNED, length(), mBuf, mGapEnd, mGapStart, mLength, mPreferredGapSize, text(), and update_selections().

char * Fl_Text_Buffer::text ( ) const

Get a copy of the entire contents of the text buffer. Memory is allocated to contain the returned string, which the caller must free.

Returns:
newly allocated text buffer - must be free'd, text is utf8

Definition at line 162 of file Fl_Text_Buffer.cxx.

References mBuf, mGapEnd, mGapStart, and mLength.

Referenced by Fl_Text_Display::buffer(), CodeEditor::CodeEditor(), do_shell_command(), tab_distance(), and text().

char * Fl_Text_Buffer::text_range ( int  start,
int  end 
) const

Get a copy of a part of the text buffer. Return a copy of the text between start and end character positions from text buffer buf. Positions start at 0, and the range does not include the character pointed to by end. When you are done with the text, free it using the free() function.

Parameters:
startbyte offset to first character
endbyte offset after last character in range
Returns:
newly allocated text buffer - must be free'd, text is utf8

Definition at line 205 of file Fl_Text_Buffer.cxx.

References IS_UTF8_ALIGNED2, mBuf, mGapEnd, mGapStart, mLength, NULL, and start.

Referenced by Fl_Text_Display::handle_vline(), line_text(), outputfile(), remove(), replace(), and selection_text_().

int Fl_Text_Buffer::undo ( int *  cp = 0)

Undo text modification according to the undo variables or insert text from the undo buffer

Definition at line 412 of file Fl_Text_Buffer.cxx.

References b, insert(), mCanUndo, mCursorPosHint, and replace().

void Fl_Text_Buffer::unhighlight ( )

Unhighlights text in the buffer.

Definition at line 627 of file Fl_Text_Buffer.cxx.

References mHighlight, Fl_Text_Selection::mSelected, and redisplay_selection().

void Fl_Text_Buffer::unselect ( )

Cancels any previous selection on the primary text selection object

Definition at line 505 of file Fl_Text_Buffer.cxx.

References mPrimary, Fl_Text_Selection::mSelected, and redisplay_selection().

Referenced by Fl_Text_Editor::handle(), and Fl_Text_Display::handle().

void Fl_Text_Buffer::update_selections ( int  pos,
int  nDeleted,
int  nInserted 
) [protected]

Updates all of the selections in the buffer for changes in the buffer's text

Definition at line 1439 of file Fl_Text_Buffer.cxx.

References mHighlight, mPrimary, mSecondary, and Fl_Text_Selection::update().

Referenced by copy(), insert_(), remove_(), and text().

int Fl_Text_Buffer::utf8_align ( int  pos) const

Align an index into the buffer to the current or previous utf8 boundary.

Definition at line 1782 of file Fl_Text_Buffer.cxx.

References byte_at().

Referenced by Fl_Text_Display::draw_range(), and Fl_Text_Display::extend_range_for_styles().

int Fl_Text_Buffer::word_end ( int  pos) const

Returns the position corresponding to the end of the word.

Parameters:
posbyte index into buffer
Returns:
byte offset to word end

Definition at line 856 of file Fl_Text_Buffer.cxx.

References char_at(), length(), and next_char().

int Fl_Text_Buffer::word_start ( int  pos) const

Returns the position corresponding to the start of the word

Parameters:
posbyte index into buffer
Returns:
byte offset to word start

Definition at line 840 of file Fl_Text_Buffer.cxx.

References char_at(), next_char(), and prev_char().


Member Data Documentation

const char * Fl_Text_Buffer::file_encoding_warning_message = "Some changes may have occurred." [static]

This message may be displayed using the fl_alert() function when a file which was not UTF-8 encoded is input.

Definition at line 668 of file Fl_Text_Buffer.H.

true iff the loaded file has been transcoded to UTF-8

Definition at line 663 of file Fl_Text_Buffer.H.

Referenced by Fl_Text_Buffer(), and insertfile().

char* Fl_Text_Buffer::mBuf [protected]

allocated memory where the text is stored

Definition at line 754 of file Fl_Text_Buffer.H.

Referenced by copy(), count_lines(), Fl_Text_Buffer(), insert_(), move_gap(), reallocate_with_gap(), remove_(), rewind_lines(), skip_lines(), text(), text_range(), and ~Fl_Text_Buffer().

char Fl_Text_Buffer::mCanUndo [protected]

if this buffer is used for attributes, it must not do any undo calls

Definition at line 770 of file Fl_Text_Buffer.H.

Referenced by canUndo(), Fl_Text_Buffer(), insert_(), remove_(), and undo().

void** Fl_Text_Buffer::mCbArgs [protected]

caller arguments for modifyProcs above

Definition at line 763 of file Fl_Text_Buffer.H.

Referenced by add_modify_callback(), call_modify_callbacks(), Fl_Text_Buffer(), remove_modify_callback(), and ~Fl_Text_Buffer().

hint for reasonable cursor position after a buffer modification operation

Definition at line 768 of file Fl_Text_Buffer.H.

Referenced by Fl_Text_Buffer(), insert(), remove(), replace(), and undo().

int Fl_Text_Buffer::mGapEnd [protected]

points to the first char after the gap

Definition at line 756 of file Fl_Text_Buffer.H.

Referenced by copy(), count_lines(), Fl_Text_Buffer(), insert_(), move_gap(), reallocate_with_gap(), remove_(), rewind_lines(), skip_lines(), text(), and text_range().

int Fl_Text_Buffer::mGapStart [protected]

points to the first character of the gap

Definition at line 755 of file Fl_Text_Buffer.H.

Referenced by copy(), count_lines(), Fl_Text_Buffer(), insert_(), move_gap(), reallocate_with_gap(), remove_(), rewind_lines(), skip_lines(), text(), and text_range().

int Fl_Text_Buffer::mLength [protected]

length of the text in the buffer (the length of the buffer itself must be calculated: gapEnd - gapStart + length)

Definition at line 751 of file Fl_Text_Buffer.H.

Referenced by byte_at(), char_at(), copy(), count_lines(), findchar_backward(), findchar_forward(), Fl_Text_Buffer(), insert(), insert_(), line_end(), next_char(), reallocate_with_gap(), remove(), remove_(), replace(), skip_displayed_characters(), skip_lines(), tab_distance(), text(), and text_range().

procedures to call when buffer is modified to redisplay contents

Definition at line 761 of file Fl_Text_Buffer.H.

Referenced by add_modify_callback(), call_modify_callbacks(), Fl_Text_Buffer(), remove_modify_callback(), and ~Fl_Text_Buffer().

number of modify-redisplay procs attached

Definition at line 760 of file Fl_Text_Buffer.H.

Referenced by add_modify_callback(), call_modify_callbacks(), Fl_Text_Buffer(), remove_modify_callback(), and ~Fl_Text_Buffer().

number of pre-delete procs attached

Definition at line 764 of file Fl_Text_Buffer.H.

Referenced by add_predelete_callback(), call_predelete_callbacks(), Fl_Text_Buffer(), remove_predelete_callback(), and ~Fl_Text_Buffer().

caller argument for pre-delete proc above

Definition at line 767 of file Fl_Text_Buffer.H.

Referenced by add_predelete_callback(), call_predelete_callbacks(), Fl_Text_Buffer(), remove_predelete_callback(), and ~Fl_Text_Buffer().

procedure to call before text is deleted from the buffer; at most one is supported.

Definition at line 765 of file Fl_Text_Buffer.H.

Referenced by add_predelete_callback(), call_predelete_callbacks(), Fl_Text_Buffer(), remove_predelete_callback(), and ~Fl_Text_Buffer().

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

Definition at line 772 of file Fl_Text_Buffer.H.

Referenced by copy(), Fl_Text_Buffer(), insert_(), and text().

int Fl_Text_Buffer::mTabDist [protected]

equiv. number of characters in a tab

Definition at line 759 of file Fl_Text_Buffer.H.

Referenced by Fl_Text_Buffer(), and tab_distance().

Pointer to a function called after reading a non UTF-8 encoded file.

This function is called after reading a file if the file content was transcoded to UTF-8. Its default implementation calls fl_alert() with the text of file_encoding_warning_message. No warning message is displayed if this pointer is set to NULL. Use input_file_was_transcoded to be informed if file input required transcoding to UTF-8.

Definition at line 679 of file Fl_Text_Buffer.H.

Referenced by Fl_Text_Buffer(), and insertfile().


The documentation for this class was generated from the following files: