fltk::TextBuffer Class Reference

List of all members.

Public Member Functions

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

Static Public Member Functions

static int character_width (char c, int indent, int tabDist, char nullSubsChar)
static int expand_character (char c, int indent, char *outStr, 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 insert_column_ (int column, int startPos, const char *insText, int *nDeleted, int *nInserted, int *endPos)
void move_gap (int pos)
void overlay_rectangular_ (int startPos, int rectStart, int rectEnd, const char *insText, int *nDeleted, int *nInserted, int *endPos)
void reallocate_with_gap (int newGapStart, int newGapLen)
void rectangular_selection_boundaries (int lineStartPos, int rectStart, int rectEnd, int *selStart, int *selEnd)
void redisplay_selection (TextSelection *oldSelection, TextSelection *newSelection)
void remove_ (int start, int end)
void remove_rectangular_ (int start, int end, int rectStart, int rectEnd, int *replaceLen, int *endPos)
void remove_selection_ (TextSelection *sel)
void replace_selection_ (TextSelection *sel, const char *text)
char * selection_text_ (TextSelection *sel)
void update_selections (int pos, int nDeleted, int nInserted)

Protected Attributes

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


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.

References buf_, cursorposhint_, gapend_, gapstart_, length_, mCanUndo, modifycbargs_, nmodifyprocs_, npredeleteprocs_, nullsubschar_, prepeletecbargs_, tabdist_, and usetabs_.

TextBuffer::~TextBuffer (  ) 

Free a text buffer

References buf_, modifycbargs_, nmodifyprocs_, npredeleteprocs_, and prepeletecbargs_.


Member Function Documentation

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!

References buf_, gapend_, gapstart_, and length_.

Referenced by tab_distance(), text(), and text_range().

void TextBuffer::text ( const char *  t  ) 

Replace the entire contents of the text buffer

References buf_, gapend_, gapstart_, length_, text(), and update_selections().

char TextBuffer::character ( int  pos  ) 

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"

References buf_, gapend_, gapstart_, length_, and text().

Referenced by insert_column(), insert_column_(), line_text(), overlay_rectangular(), overlay_rectangular_(), fltk::TextDisplay::position_to_xy(), remove_rectangular(), remove_rectangular_(), replace(), replace_rectangular(), and fltk::TextDisplay::xy_to_position().

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

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

References cursorposhint_, insert_(), and length_.

Referenced by fltk::TextDisplay::insert(), and undo().

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"

References cursorposhint_, insert_(), length_, remove_(), and text_range().

Referenced by fltk::TextDisplay::overstrike(), and undo().

int TextBuffer::undo ( int *  cursorPos = 0  ) 

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

References cursorposhint_, insert(), mCanUndo, newstring(), and replace().

void TextBuffer::canUndo ( char  flag = 1  ) 

Let the undo system know if we can undo changes.

References mCanUndo.

Referenced by fltk::TextDisplay::highlight_data().

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.

References count_lines(), cursorposhint_, insert_column_(), line_end(), line_start(), skip_lines(), text_range(), and fltk::warning.

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.

References count_lines(), cursorposhint_, insert_(), insert_column_(), line_end(), line_start(), remove_rectangular_(), text_range(), and fltk::warning.

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.

References count_lines(), cursorposhint_, line_end(), line_start(), nullsubschar_, overlay_rectangular_(), skip_lines(), tabdist_, text_range(), and fltk::warning.

Referenced by clear_rectangular().

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.

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

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.

References count_lines(), and overlay_rectangular().

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.

References length_, tabdist_, and text().

void TextBuffer::add_modify_callback ( Text_Modify_Cb  bufModifiedCB,
void *  cbArg 
)

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

References modifycbargs_, and nmodifyprocs_.

Referenced by fltk::TextDisplay::buffer().

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.

References npredeleteprocs_, and prepeletecbargs_.

Referenced by fltk::TextDisplay::buffer().

char * TextBuffer::line_text ( int  pos  ) 

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

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

int TextBuffer::line_start ( int  pos  ) 

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)

References findchar_forward(), and length_.

Referenced by insert_column(), insert_column_(), fltk::TextDisplay::line_end(), line_text(), overlay_rectangular(), overlay_rectangular_(), remove_rectangular(), remove_rectangular_(), and replace_rectangular().

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

References character(), nullsubschar_, and tabdist_.

Referenced by count_displayed_characters(), fltk::TextDisplay::position_to_xy(), and fltk::TextDisplay::xy_to_position().

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

Referenced by fltk::TextDisplay::overstrike(), rectangular_selection_boundaries(), and skip_displayed_characters().

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)

References expand_character().

Referenced by fltk::TextDisplay::overstrike().

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)

References character(), character_width(), length_, nullsubschar_, and tabdist_.

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.

References buf_, gapend_, and length_.

Referenced by clear_rectangular(), insert_column(), insert_column_(), overlay_rectangular(), overlay_rectangular_(), remove_rectangular_(), and replace_rectangular().

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

References buf_, gapend_, and length_.

Referenced by insert_column(), insert_column_(), overlay_rectangular(), and overlay_rectangular_().

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

References buf_, and gapend_.

Referenced by fltk::TextDisplay::move_up().

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)

References buf_, gapend_, and length_.

Referenced by line_end().

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)

References buf_, gapend_, and length_.

Referenced by line_start().

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.

References buf_, gapend_, and length_.

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.

References buf_, and gapend_.

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.

References modifycbargs_.

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.

References prepeletecbargs_.

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

References buf_, gapend_, length_, mCanUndo, reallocate_with_gap(), and update_selections().

Referenced by insert(), insert_column_(), overlay_rectangular_(), remove_rectangular_(), replace(), and replace_rectangular().

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

References buf_, gapend_, length_, mCanUndo, and update_selections().

Referenced by insert_column_(), overlay_rectangular_(), remove_rectangular_(), and replace().

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)

References count_lines(), insert_(), length_, line_end(), line_start(), nullsubschar_, remove_(), tabdist_, text_range(), and usetabs_.

Referenced by remove_rectangular(), and replace_rectangular().

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

References count_lines(), insert_(), length_, line_end(), line_start(), nullsubschar_, remove_(), skip_lines(), tabdist_, text_range(), and usetabs_.

Referenced by insert_column(), and replace_rectangular().

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

References count_lines(), insert_(), length_, line_end(), line_start(), nullsubschar_, remove_(), skip_lines(), tabdist_, text_range(), and usetabs_.

Referenced by overlay_rectangular().

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

References buf_, gapend_, and length_.

Referenced by insert_().

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.

References character(), character_width(), length_, nullsubschar_, and tabdist_.

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

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


Member Data Documentation

int fltk::TextBuffer::length_ [protected]

char* fltk::TextBuffer::buf_ [protected]

int fltk::TextBuffer::gapstart_ [protected]

points to the first character of the gap

Referenced by character(), text(), text_range(), and TextBuffer().

int fltk::TextBuffer::gapend_ [protected]

int fltk::TextBuffer::tabdist_ [protected]

bool fltk::TextBuffer::usetabs_ [protected]

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

Referenced by insert_column_(), overlay_rectangular_(), remove_rectangular_(), and TextBuffer().

number of modify-redisplay procs attached

Referenced by add_modify_callback(), TextBuffer(), and ~TextBuffer().

void** fltk::TextBuffer::modifycbargs_ [protected]

caller arguments for modifyprocs_ above

Referenced by add_modify_callback(), call_modify_callbacks(), TextBuffer(), and ~TextBuffer().

number of pre-delete procs attached

Referenced by add_predelete_callback(), TextBuffer(), and ~TextBuffer().

caller argument for pre-delete proc above

Referenced by add_predelete_callback(), call_predelete_callbacks(), TextBuffer(), and ~TextBuffer().

hint for reasonable cursor position after a buffer modification operation

Referenced by insert(), insert_column(), overlay_rectangular(), remove_rectangular(), replace(), replace_rectangular(), TextBuffer(), and undo().

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

Referenced by expand_character(), insert_column_(), overlay_rectangular(), overlay_rectangular_(), rectangular_selection_boundaries(), remove_rectangular_(), skip_displayed_characters(), and TextBuffer().

char fltk::TextBuffer::mCanUndo [protected]

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

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


Wed Jun 17 08:49:30 2009. FLTK ©2007 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.