22#ifndef FL_TEXT_BUFFER_H
23#define FL_TEXT_BUFFER_H
32# define IS_UTF8_ALIGNED(a) if (a && *a) assert(fl_utf8len(*(a))>0);
33# define IS_UTF8_ALIGNED2(a, b) if (b>=0 && b<a->length()) assert(fl_utf8len(a->byte_at(b))>0);
35# define IS_UTF8_ALIGNED(a)
36# define IS_UTF8_ALIGNED2(a, b)
60#define FL_TEXT_MAX_EXP_CHAR_LEN 20
64class Fl_Text_Undo_Action_List;
65class Fl_Text_Undo_Action;
106 void set(
int startpos,
int endpos);
109 void update(
int pos,
int nDeleted,
int nInserted);
122 int start()
const {
return mSelected ? mStart : 0; }
135 int end()
const {
return mSelected ? mEnd : 0; }
163 int length()
const {
return mSelected ? mEnd - mStart : 0; }
166 int includes(
int pos)
const;
169 int selected(
int *startpos,
int *endpos)
const;
170 FL_DEPRECATED(
"in 1.4.0 - use selected(startpos, endpos) instead",
171 int position(
int *startpos,
int *endpos)
const) {
return selected(startpos, endpos); }
181typedef void (*Fl_Text_Modify_Cb)(
int pos,
int nInserted,
int nDeleted,
182 int nRestyled,
const char* deletedText,
186typedef void (*Fl_Text_Predelete_Cb)(
int pos,
int nDeleted,
void* cbArg);
212 Fl_Text_Buffer(
int requestedSize = 0,
int preferredGapSize = 1024);
237 void text(
const char* text);
249 char* text_range(
int start,
int end)
const;
257 unsigned int char_at(
int pos)
const;
265 char byte_at(
int pos)
const;
273 {
return (pos < mGapStart) ? mBuf+pos : mBuf+pos+mGapEnd-mGapStart; }
281 {
return (pos < mGapStart) ? mBuf+pos : mBuf+pos+mGapEnd-mGapStart; }
289 void insert(
int pos,
const char* text,
int insertedLength = -1);
296 void append(
const char* t,
int addedLength = -1) { insert(length(), t, addedLength); }
298 void vprintf(
const char *fmt, va_list ap);
299 void printf(
const char* fmt, ...);
306 void remove(
int start,
int end);
316 void replace(
int start,
int end,
const char *text,
int insertedLength = -1);
325 void copy(
Fl_Text_Buffer* fromBuf,
int fromStart,
int fromEnd,
int toPos);
337 bool can_undo()
const;
348 bool can_redo()
const;
357 void canUndo(
char flag=1);
374 int insertfile(
const char *file,
int pos,
int buflen = 128*1024);
380 {
return insertfile(file, length(), buflen); }
385 int loadfile(
const char *file,
int buflen = 128*1024)
386 { select(0, length()); remove_selection();
return appendfile(file, buflen); }
398 int outputfile(
const char *file,
int start,
int end,
int buflen = 128*1024);
410 int savefile(
const char *file,
int buflen = 128*1024)
411 {
return outputfile(file, 0, length(), buflen); }
425 void tab_distance(
int tabDist);
430 void select(
int start,
int end);
435 int selected()
const {
return mPrimary.selected(); }
445 int selection_position(
int* start,
int* end);
452 char* selection_text();
457 void remove_selection();
462 void replace_selection(
const char* text);
467 void secondary_select(
int start,
int end);
478 void secondary_unselect();
483 int secondary_selection_position(
int* start,
int* end);
490 char* secondary_selection_text();
496 void remove_secondary_selection();
502 void replace_secondary_selection(
const char* text);
507 void highlight(
int start,
int end);
522 int highlight_position(
int* start,
int* end);
529 char* highlight_text();
542 void add_modify_callback(Fl_Text_Modify_Cb bufModifiedCB,
void* cbArg);
547 void remove_modify_callback(Fl_Text_Modify_Cb bufModifiedCB,
void* cbArg);
558 void add_predelete_callback(Fl_Text_Predelete_Cb bufPredelCB,
void* cbArg);
564 void remove_predelete_callback(Fl_Text_Predelete_Cb predelCB,
void* cbArg);
580 char* line_text(
int pos)
const;
587 int line_start(
int pos)
const;
596 int line_end(
int pos)
const;
603 int word_start(
int pos)
const;
610 int word_end(
int pos)
const;
619 int count_displayed_characters(
int lineStartPos,
int targetPos)
const;
630 int skip_displayed_characters(
int lineStartPos,
int nChars);
636 int count_lines(
int startPos,
int endPos)
const;
642 int skip_lines(
int startPos,
int nLines);
650 int rewind_lines(
int startPos,
int nLines);
666 int findchar_forward(
int startPos,
unsigned searchChar,
int* foundPos)
const;
681 int findchar_backward(
int startPos,
unsigned int searchChar,
int* foundPos)
const;
694 int search_forward(
int startPos,
const char* searchString,
int* foundPos,
695 int matchCase = 0)
const;
708 int search_backward(
int startPos,
const char* searchString,
int* foundPos,
709 int matchCase = 0)
const;
735 int prev_char(
int ix)
const;
736 int prev_char_clipped(
int ix)
const;
742 int next_char(
int ix)
const;
743 int next_char_clipped(
int ix)
const;
748 int utf8_align(
int)
const;
770 bool is_word_separator(
int pos)
const;
778 void call_modify_callbacks(
int pos,
int nDeleted,
int nInserted,
779 int nRestyled,
const char* deletedText)
const;
785 void call_predelete_callbacks(
int pos,
int nDeleted)
const;
797 int insert_(
int pos,
const char* text,
int insertedLength = -1);
805 void remove_(
int start,
int end);
817 void move_gap(
int pos);
823 void reallocate_with_gap(
int newGapStart,
int newGapLen);
840 void update_selections(
int pos,
int nDeleted,
int nInserted);
845 int apply_undo(Fl_Text_Undo_Action* action,
int* cursorPos);
This class manages Unicode text displayed in one or more Fl_Text_Display widgets.
Definition Fl_Text_Buffer.H:201
Fl_Text_Selection mSecondary
highlighted areas
Definition Fl_Text_Buffer.H:848
void ** mCbArgs
caller arguments for modifyProcs above
Definition Fl_Text_Buffer.H:862
int savefile(const char *file, int buflen=128 *1024)
Saves a text file from the current buffer.
Definition Fl_Text_Buffer.H:410
char * mBuf
allocated memory where the text is stored
Definition Fl_Text_Buffer.H:853
int length() const
Returns the number of bytes in the buffer.
Definition Fl_Text_Buffer.H:223
const Fl_Text_Selection * primary_selection() const
Returns the primary selection.
Definition Fl_Text_Buffer.H:714
int secondary_selected()
Returns a non-zero value if text has been selected in the secondary text selection,...
Definition Fl_Text_Buffer.H:473
const Fl_Text_Selection * secondary_selection() const
Returns the secondary selection.
Definition Fl_Text_Buffer.H:724
int selected() const
Returns a non-zero value if text has been selected, 0 otherwise.
Definition Fl_Text_Buffer.H:435
void append(const char *t, int addedLength=-1)
Appends the text string to the end of the buffer.
Definition Fl_Text_Buffer.H:296
Fl_Text_Undo_Action_List * mRedoList
List of redo event.
Definition Fl_Text_Buffer.H:876
int input_file_was_transcoded
true if the loaded file has been transcoded to UTF-8.
Definition Fl_Text_Buffer.H:753
const char * address(int pos) const
Convert a byte offset in buffer into a memory address.
Definition Fl_Text_Buffer.H:272
static const char * file_encoding_warning_message
This message may be displayed using the fl_alert() function when a file which was not UTF-8 encoded i...
Definition Fl_Text_Buffer.H:758
int mNModifyProcs
number of modify-redisplay procs attached
Definition Fl_Text_Buffer.H:859
Fl_Text_Undo_Action_List * mUndoList
List of undo event.
Definition Fl_Text_Buffer.H:875
const Fl_Text_Selection * highlight_selection() const
Returns the current highlight selection.
Definition Fl_Text_Buffer.H:729
int mGapStart
points to the first character of the gap
Definition Fl_Text_Buffer.H:854
int mCursorPosHint
hint for reasonable cursor position after a buffer modification operation
Definition Fl_Text_Buffer.H:867
Fl_Text_Undo_Action * mUndo
local undo event
Definition Fl_Text_Buffer.H:874
int appendfile(const char *file, int buflen=128 *1024)
Appends the named file to the end of the buffer.
Definition Fl_Text_Buffer.H:379
void call_predelete_callbacks()
Calls the stored pre-delete callback procedure(s) for this buffer to update the changed area(s) on th...
Definition Fl_Text_Buffer.H:570
void call_modify_callbacks()
Calls all modify callbacks that have been registered using the add_modify_callback() method.
Definition Fl_Text_Buffer.H:553
Fl_Text_Selection mHighlight
highlighted areas
Definition Fl_Text_Buffer.H:849
int highlight()
Returns a non-zero value if text has been highlighted, 0 otherwise.
Definition Fl_Text_Buffer.H:512
int mGapEnd
points to the first character after the gap
Definition Fl_Text_Buffer.H:855
Fl_Text_Predelete_Cb * mPredeleteProcs
procedure to call before text is deleted from the buffer; at most one is supported.
Definition Fl_Text_Buffer.H:864
void ** mPredeleteCbArgs
caller argument for pre-delete proc above
Definition Fl_Text_Buffer.H:866
char * address(int pos)
Convert a byte offset in buffer into a memory address.
Definition Fl_Text_Buffer.H:280
Fl_Text_Selection mPrimary
highlighted areas
Definition Fl_Text_Buffer.H:847
Fl_Text_Selection * primary_selection()
Returns the primary selection.
Definition Fl_Text_Buffer.H:719
int mNPredeleteProcs
number of pre-delete procs attached
Definition Fl_Text_Buffer.H:863
int mPreferredGapSize
the default allocation for the text gap is 1024 bytes and should only be increased if frequent and la...
Definition Fl_Text_Buffer.H:871
Fl_Text_Modify_Cb * mModifyProcs
procedures to call when buffer is modified to redisplay contents
Definition Fl_Text_Buffer.H:860
char mCanUndo
if this buffer is used for attributes, it must not do any undo calls
Definition Fl_Text_Buffer.H:869
int loadfile(const char *file, int buflen=128 *1024)
Loads a text file into the buffer.
Definition Fl_Text_Buffer.H:385
int mTabDist
equiv.
Definition Fl_Text_Buffer.H:858
int tab_distance() const
Gets the tab width.
Definition Fl_Text_Buffer.H:419
int mLength
length of the text in the buffer (the length of the buffer itself must be calculated: gapEnd - gapSta...
Definition Fl_Text_Buffer.H:850
This is an internal class for Fl_Text_Buffer to manage text selections.
Definition Fl_Text_Buffer.H:100
int position(int *startpos, int *endpos) const
Definition Fl_Text_Buffer.H:171
int end() const
Returns the byte offset to the character after the last selected character.
Definition Fl_Text_Buffer.H:135
bool selected() const
Returns true if any text is selected.
Definition Fl_Text_Buffer.H:142
void selected(bool b)
Modifies the 'selected' flag.
Definition Fl_Text_Buffer.H:148
bool mSelected
this flag is set if any text is selected
Definition Fl_Text_Buffer.H:177
int mEnd
byte offset to the character after the last selected character
Definition Fl_Text_Buffer.H:176
int start() const
Returns the byte offset to the first selected character.
Definition Fl_Text_Buffer.H:122
int mStart
byte offset to the first selected character
Definition Fl_Text_Buffer.H:175
int length() const
Returns the size in bytes of the selection.
Definition Fl_Text_Buffer.H:163
This file defines compiler-specific macros.
#define FL_DEPRECATED(msg, func)
Enclosing a function or method in FL_DEPRECATED marks it as no longer recommended.
Definition fl_attr.h:57