TextBuffer Class Reference

List of all members.

Public Member Functions

 TextBuffer (int requestedsize=0)
 ~TextBuffer ()
int length () const
const char * text ()
void text (const char *text)
char character (int pos)
char * text_range (int start, int end)
char * text_in_rectangle (int start, int end, int rectStart, int rectEnd)
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 (TextBuffer *from_buf, int from_start, int from_end, int to_pos)
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)
void insert_column (int column, int startpos, const char *text, int *chars_inserted, int *chars_deleted)
void replace_rectangular (int start, int end, int rectstart, int rectend, const char *text)
void overlay_rectangular (int startpos, int rectStart, int rectEnd, const char *text, int *charsInserted, int *charsDeleted)
void remove_rectangular (int start, int end, int rectStart, int rectEnd)
void clear_rectangular (int start, int end, int rectStart, int rectEnd)
int tab_distance () const
void tab_distance (int tabDist)
void select (int start, int end)
bool selected () const
void unselect ()
void select_rectangular (int start, int end, int rectStart, int rectEnd)
int selection_position (int *start, int *end)
int selection_position (int *start, int *end, int *isRect, int *rectStart, int *rectEnd)
char * selection_text ()
void remove_selection ()
void replace_selection (const char *text)
void secondary_select (int start, int end)
void secondary_unselect ()
void secondary_select_rectangular (int start, int end, int rectStart, int rectEnd)
int secondary_selection_position (int *start, int *end, int *isRect, int *rectStart, int *rectEnd)
char * secondary_selection_text ()
void remove_secondary_selection ()
void replace_secondary_selection (const char *text)
void highlight (int start, int end)
void unhighlight ()
void highlight_rectangular (int start, int end, int rectStart, int rectEnd)
int highlight_position (int *start, int *end, int *isRect, int *rectStart, int *rectEnd)
char * highlight_text ()
void add_modify_callback (Text_Modify_Cb bufModifiedCB, void *cbArg)
void remove_modify_callback (Text_Modify_Cb bufModifiedCB, void *cbArg)
void call_modify_callbacks ()
void add_predelete_callback (Text_Predelete_Cb bufPredelCB, void *cbArg)
void remove_predelete_callback (Text_Predelete_Cb predelCB, void *cbArg)
void call_predelete_callbacks ()
char * line_text (int pos)
int line_start (int pos)
int line_end (int pos)
int word_start (int pos)
int word_end (int pos)
int expand_character (int pos, int indent, char *outStr)
int count_displayed_characters (int lineStartPos, int targetPos)
int count_displayed_characters_utf (int lineStartPos, int targetPos)
int skip_displayed_characters (int lineStartPos, int nChars)
int skip_displayed_characters_utf (int lineStartPos, int nChars)
int count_lines (int startPos, int endPos)
int skip_lines (int startPos, int nLines)
int rewind_lines (int startPos, int nLines)
bool findchar_forward (int startPos, char searchChar, int *foundPos)
bool findchar_backward (int startPos, char searchChar, int *foundPos)
bool findchars_forward (int startpos, const char *searchChars, int *foundPos)
bool findchars_backward (int startpos, const char *searchChars, int *foundPos)
bool search_forward (int startPos, const char *searchString, int *foundPos, bool matchCase=false)
bool search_backward (int startPos, const char *searchString, int *foundPos, bool matchCase=false)
char null_substitution_character ()
TextSelection * primary_selection ()
TextSelection * secondary_selection ()
TextSelection * highlight_selection ()

Static Public Member Functions

int expand_character (char c, int indent, char *outStr, int tabDist, char nullSubsChar)
int character_width (char c, int indent, int tabDist, char nullSubsChar)

Protected Member Functions

void call_modify_callbacks (int pos, int nDeleted, int nInserted, int nRestyled, const char *deletedText)
void call_predelete_callbacks (int pos, int nDeleted)
int insert_ (int pos, const char *text)
void remove_ (int start, int end)
void remove_rectangular_ (int start, int end, int rectStart, int rectEnd, int *replaceLen, int *endPos)
void insert_column_ (int column, int startPos, const char *insText, int *nDeleted, int *nInserted, int *endPos)
void overlay_rectangular_ (int startPos, int rectStart, int rectEnd, const char *insText, int *nDeleted, int *nInserted, int *endPos)
void redisplay_selection (TextSelection *oldSelection, TextSelection *newSelection)
void move_gap (int pos)
void reallocate_with_gap (int newGapStart, int newGapLen)
char * selection_text_ (TextSelection *sel)
void remove_selection_ (TextSelection *sel)
void replace_selection_ (TextSelection *sel, const char *text)
void rectangular_selection_boundaries (int lineStartPos, int rectStart, int rectEnd, int *selStart, int *selEnd)
void update_selections (int pos, int nDeleted, int nInserted)

Protected Attributes

TextSelection primary_
TextSelection secondary_
TextSelection highlight_
int length_
char * buf_
int gapstart_
int gapend_
int tabdist_
bool usetabs_
int nmodifyprocs_
Text_Modify_Cb * modifyprocs_
void ** modifycbargs_
int npredeleteprocs_
Text_Predelete_Cb * predeleteprocs_
void ** prepeletecbargs_
int cursorposhint_
char nullsubschar_
char mCanUndo

Detailed Description

TextBuffer


Constructor & Destructor Documentation

TextBuffer::TextBuffer int  requestedsize = 0  ) 
 

Create an empty text buffer of a pre-determined size (use this to avoid unnecessary re-allocation if you know exactly how much the buffer will need to hold.

TextBuffer::~TextBuffer  ) 
 

Free a text buffer


Member Function Documentation

void TextBuffer::add_modify_callback Text_Modify_Cb  bufModifiedCB,
void *  cbArg
 

Add a callback routine to be called when the buffer is modified

void TextBuffer::add_predelete_callback Text_Predelete_Cb  bufPreDeleteCB,
void *  cbArg
 

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

void TextBuffer::call_modify_callbacks int  pos,
int  ndeleted,
int  ninserted,
int  nRestyled,
const char *  deleted_text
[protected]
 

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

void TextBuffer::call_predelete_callbacks int  pos,
int  ndeleted
[protected]
 

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

void TextBuffer::canUndo char  flag = 1  ) 
 

Let the undo system know if we can undo changes.

char TextBuffer::character int  pos  ) 
 

Return the character at buffer position "pos". Positions start at 0.

int TextBuffer::character_width char  c,
int  indent,
int  tabDist,
char  nullSubsChar
[static]
 

Return the length in displayed characters of character "c" expanded for display (as discussed above in BufGetExpandedChar). If the buffer for which the character width is being measured is doing null substitution, nullSubsChar should be passed as that character (or nul to ignore).

void TextBuffer::clear_rectangular int  start,
int  end,
int  rectstart,
int  rectend
 

Clear a rectangular "hole" out of the buffer between character positions start and end and horizontal displayed-character offsets rectstart and rectend.

int TextBuffer::count_displayed_characters int  linestartpos,
int  targetpos
 

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)

int TextBuffer::count_lines int  startpos,
int  endpos
 

Count the number of newlines between startpos and endpos in buffer "buf". The character at position "endpos" is not counted.

int TextBuffer::expand_character char  c,
int  indent,
char *  out_str,
int  tabDist,
char  nullSubsChar
[static]
 

Expand a single character from the text buffer into it's screen representation (which may be several characters for a tab or a control code). Returns the number of characters added to "out_str". "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 TEXT_MAX_EXP_CHAR_LEN

int TextBuffer::expand_character int  pos,
int  indent,
char *  out_str
 

Get a character from the text buffer expanded into it's screen representation (which may be several characters for a tab or a control code). Returns the number of characters written to "out_str". "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 TEXT_MAX_EXP_CHAR_LEN

bool TextBuffer::findchar_backward int  startpos,
char  searchChar,
int *  foundPos
 

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)

bool TextBuffer::findchar_forward int  startpos,
char  searchChar,
int *  foundPos
 

Search forwards in buffer "buf" 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)

bool TextBuffer::findchars_backward int  startpos,
const char *  searchChars,
int *  foundPos
 

Search backwards in buffer "buf" for characters in "searchChars", starting with the character BEFORE "startpos", returning the result in "foundPos" returns True if found, False if not.

bool TextBuffer::findchars_forward int  startpos,
const char *  searchChars,
int *  foundPos
 

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.

void TextBuffer::insert int  pos,
const char *  s
 

Insert null-terminated string "s" at position "pos" in "buf"

int TextBuffer::insert_ int  pos,
const char *  s
[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).

void TextBuffer::insert_column int  column,
int  startpos,
const char *  s,
int *  chars_inserted,
int *  chars_deleted
 

Insert "text" columnwise into buffer starting at displayed character position "column" on the line beginning at "startpos". Opens a rectangular space the width and height of "text", by moving all text to the right of "column" right. If chars_inserted and chars_deleted are not NULL, the number of characters inserted and deleted in the operation (beginning at startpos) are returned in these arguments.

void TextBuffer::insert_column_ int  column,
int  startpos,
const char *  ins_text,
int *  ndeleted,
int *  ninserted,
int *  endpos
[protected]
 

Insert 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. "ndeleted" and "ninserted" return the number of characters deleted and inserted beginning at the start of the line containing "startpos". "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).

int TextBuffer::line_end int  pos  ) 
 

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

int TextBuffer::line_start int  pos  ) 
 

Find the position of the start of the line containing position "pos"

char * TextBuffer::line_text int  pos  ) 
 

Return the text from the entire line containing position "pos"

void TextBuffer::overlay_rectangular int  startpos,
int  rectstart,
int  rectend,
const char *  s,
int *  chars_inserted,
int *  chars_deleted
 

Overlay "text" between displayed character positions "rectstart" and "rectend" on the line beginning at "startpos". If chars_inserted and chars_deleted are not NULL, the number of characters inserted and deleted in the operation (beginning at startpos) are returned in these arguments.

void TextBuffer::overlay_rectangular_ int  startpos,
int  rectstart,
int  rectend,
const char *  ins_text,
int *  ndeleted,
int *  ninserted,
int *  endpos
[protected]
 

Overlay a rectangular area of text without calling the modify callbacks. "ndeleted" and "ninserted" return the number of characters deleted and inserted beginning at the start of the line containing "startpos". "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).

void TextBuffer::reallocate_with_gap int  newGapStart,
int  newGapLen
[protected]
 

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

void TextBuffer::rectangular_selection_boundaries int  linestartpos,
int  rectstart,
int  rectend,
int *  selstart,
int *  selend
[protected]
 

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

void TextBuffer::redisplay_selection TextSelection *  old_selection,
TextSelection *  newSelection
[protected]
 

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

void TextBuffer::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).

void TextBuffer::remove_rectangular int  start,
int  end,
int  rectstart,
int  rectend
 

Remove a rectangular swath of characters between character positions start and end and horizontal displayed-character offsets rectstart and rectend.

void TextBuffer::remove_rectangular_ int  start,
int  end,
int  rectstart,
int  rectend,
int *  replaceLen,
int *  endpos
[protected]
 

Delete a rectangle of text without calling the modify callbacks. Returns the number of characters replacing those between start and end. Note that in some pathological cases, deleting can actually increase the size of the buffer because of tab expansions. "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)

void TextBuffer::replace int  start,
int  end,
const char *  s
 

Delete the characters between "start" and "end", and insert the null-terminated string "text" in their place in in "buf"

void TextBuffer::replace_rectangular int  start,
int  end,
int  rectstart,
int  rectend,
const char *  s
 

Replace a rectangular area in buf, given by "start", "end", "rectstart", and "rectend", with "text". If "text" is vertically longer than the rectangle, add extra lines to make room for it.

int TextBuffer::rewind_lines int  startpos,
int  nlines
 

Find 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 "buf". nlines == 0 means find the beginning of the line

int TextBuffer::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)

int TextBuffer::skip_lines int  startpos,
int  nlines
 

Find the first character of the line "nlines" forward from "startpos" in "buf" and return its position

void TextBuffer::tab_distance int  tabDist  ) 
 

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

void TextBuffer::text const char *  t  ) 
 

Replace the entire contents of the text buffer

const char * TextBuffer::text  ) 
 

Return the entire contents of the text buffer. Returned memory is temporary and will only be usable until the next time the text is altered.

Unlike previous versions of fltk, DO NOT FREE THE RETURNED RESULT!

char * TextBuffer::text_range int  start,
int  end
 

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"

int TextBuffer::undo int *  cursorPos = 0  ) 
 

Remove text according to the undo variables or insert text from the undo buffer.

void TextBuffer::update_selections int  pos,
int  ndeleted,
int  ninserted
[protected]
 

Update all of the selections in "buf" for changes in the buffer's text


Member Data Documentation

char* TextBuffer::buf_ [protected]
 

allocated memory where the text is stored

int TextBuffer::cursorposhint_ [protected]
 

hint for reasonable cursor position after a buffer modification operation

int TextBuffer::gapend_ [protected]
 

points to the first char after the gap

int TextBuffer::gapstart_ [protected]
 

points to the first character of the gap

int TextBuffer::length_ [protected]
 

length of the text in the buffer (the length of the buffer itself must be calculated: gapend - gapstart + length)

char TextBuffer::mCanUndo [protected]
 

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

void** TextBuffer::modifycbargs_ [protected]
 

caller arguments for modifyprocs_ above

int TextBuffer::nmodifyprocs_ [protected]
 

number of modify-redisplay procs attached

int TextBuffer::npredeleteprocs_ [protected]
 

number of pre-delete procs attached

char TextBuffer::nullsubschar_ [protected]
 

TextBuffer is based on C null-terminated strings, so ascii-nul characters must be substituted with something else. This is the else, but of course, things get quite messy when you use it

void** TextBuffer::prepeletecbargs_ [protected]
 

caller argument for pre-delete proc above

int TextBuffer::tabdist_ [protected]
 

equiv. number of characters in a tab

bool TextBuffer::usetabs_ [protected]
 

True if buffer routines are allowed to use tabs for padding in rectangular operations


The documentation for this class was generated from the following files:
Sun Jan 7 00:55:18 2007. FLTK ©2006 Bill Spitzak and others.
Permission is granted to reproduce this manual or any portion for any purpose, provided this copyright and permission notice are preserved.