fltk::TextBuffer Class Reference

#include <TextBuffer.h>

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 canUndo (char flag=1)
char character (int pos)
void clear_rectangular (int start, int end, int rectStart, int rectEnd)
int count_displayed_characters (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 insert (int pos, const char *text)
void insert_column (int column, int startpos, const char *text, int *chars_inserted, int *chars_deleted)
int line_end (int pos)
int line_start (int pos)
char * line_text (int pos)
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 replace (int start, int end, const char *text)
void replace_rectangular (int start, int end, int rectstart, int rectend, const char *text)
int rewind_lines (int startPos, int nLines)
int skip_displayed_characters (int lineStartPos, int nChars)
int skip_lines (int startPos, int nLines)
void tab_distance (int tabDist)
void text (const char *text)
const char * text ()
char * text_range (int start, int end)
 TextBuffer (int requestedsize=0)
int undo (int *cp=0)
 ~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 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 update_selections (int pos, int nDeleted, int nInserted)

Protected Attributes

char * buf_
int cursorposhint_
int gapend_
int gapstart_
int length_
char mCanUndo
void ** modifycbargs_
int nmodifyprocs_
int npredeleteprocs_
char nullsubschar_
void ** prepeletecbargs_
int tabdist_
bool usetabs_

Detailed Description


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 ( 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

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

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.

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!

void TextBuffer::text ( const char *  t)

Replace the entire contents of the text buffer

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* fltk::TextBuffer::buf_ [protected]

allocated memory where the text is stored

hint for reasonable cursor position after a buffer modification operation

int fltk::TextBuffer::gapend_ [protected]

points to the first char after the gap

int fltk::TextBuffer::gapstart_ [protected]

points to the first character of the gap

int fltk::TextBuffer::length_ [protected]

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

char fltk::TextBuffer::mCanUndo [protected]

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

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

caller arguments for modifyprocs_ above

number of modify-redisplay procs attached

number of pre-delete procs attached

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

caller argument for pre-delete proc above

int fltk::TextBuffer::tabdist_ [protected]

equiv. number of characters in a tab

bool fltk::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: