Fl_Text_Buffer.H 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. //
  2. // "$Id: Fl_Text_Buffer.H 9956 2013-08-12 15:46:57Z greg.ercolano $"
  3. //
  4. // Header file for Fl_Text_Buffer class.
  5. //
  6. // Copyright 2001-2010 by Bill Spitzak and others.
  7. // Original code Copyright Mark Edel. Permission to distribute under
  8. // the LGPL for the FLTK library granted by Mark Edel.
  9. //
  10. // Please report all bugs and problems on the following page:
  11. //
  12. // http://www.fltk.org/str.php
  13. //
  14. // Please report all bugs and problems on the following page:
  15. //
  16. // http://www.fltk.org/str.php
  17. //
  18. /* \file
  19. Fl_Text_Buffer, Fl_Text_Selection widget . */
  20. #ifndef FL_TEXT_BUFFER_H
  21. #define FL_TEXT_BUFFER_H
  22. #undef ASSERT_UTF8
  23. #ifdef ASSERT_UTF8
  24. # include <assert.h>
  25. # define IS_UTF8_ALIGNED(a) if (a && *a) assert(fl_utf8len(*(a))>0);
  26. # define IS_UTF8_ALIGNED2(a, b) if (b>=0 && b<a->length()) assert(fl_utf8len(a->byte_at(b))>0);
  27. #else
  28. # define IS_UTF8_ALIGNED(a)
  29. # define IS_UTF8_ALIGNED2(a, b)
  30. #endif
  31. /*
  32. "character size" is the size of a UTF-8 character in bytes
  33. "character width" is the width of a Unicode character in pixels
  34. "column" was orginally defined as a character offset from the left margin.
  35. It was identical to the byte offset. In UTF-8, we have neither a byte offset
  36. nor truly fixed width fonts (*). Column could be a pixel value multiplied with
  37. an average character width (which is a bearable approximation).
  38. * in Unicode, there are no fixed width fonts! Even if the ASCII characters may
  39. happen to be all the same width in pixels, chinese charcaters surely are not.
  40. There are plenty of exceptions, like ligatures, that make special handling of
  41. "fixed" character widths a nightmare. I decided to remove all references to
  42. fixed fonts and see "columns" as a multiple of the average width of a
  43. character in the main font.
  44. - Matthias
  45. */
  46. /* Maximum length in characters of a tab or control character expansion
  47. of a single buffer character */
  48. #define FL_TEXT_MAX_EXP_CHAR_LEN 20
  49. #include "Fl_Export.H"
  50. /**
  51. \class Fl_Text_Selection
  52. \brief This is an internal class for Fl_Text_Buffer to manage text selections.
  53. This class works correctly with utf-8 strings assuming that the parameters
  54. for all calls are on character boundaries.
  55. */
  56. class FL_EXPORT Fl_Text_Selection {
  57. friend class Fl_Text_Buffer;
  58. public:
  59. /**
  60. \brief Set the selection range.
  61. \param start byte offset to first selected character
  62. \param end byte offset pointing after last selected character
  63. */
  64. void set(int start, int end);
  65. /**
  66. \brief Updates a selection afer text was modified.
  67. Updates an individual selection for changes in the corresponding text
  68. \param pos byte offset into text buffer at which the change occured
  69. \param nDeleted number of bytes deleted from the buffer
  70. \param nInserted number of bytes inserted into the buffer
  71. */
  72. void update(int pos, int nDeleted, int nInserted);
  73. /**
  74. \brief Return the byte offset to the first selected character.
  75. \return byte offset
  76. */
  77. int start() const { return mStart; }
  78. /**
  79. \brief Return the byte ofsset to the character after the last selected character.
  80. \return byte offset
  81. */
  82. int end() const { return mEnd; }
  83. /**
  84. \brief Returns true if any text is selected.
  85. \return a non-zero number if any text has been selected, or 0
  86. if no text is selected.
  87. */
  88. bool selected() const { return mSelected; }
  89. /**
  90. \brief Modify the 'selected' flag.
  91. \param b new flag
  92. */
  93. void selected(bool b) { mSelected = b; }
  94. /**
  95. Return true if position \p pos with indentation \p dispIndex is in
  96. the Fl_Text_Selection.
  97. */
  98. int includes(int pos) const;
  99. /**
  100. \brief Return the positions of this selection.
  101. \param start retrun byte offset to first selected character
  102. \param end retrun byte offset pointing after last selected character
  103. \return true if selected
  104. */
  105. int position(int* start, int* end) const;
  106. protected:
  107. int mStart; ///< byte offset to the first selected character
  108. int mEnd; ///< byte offset to the character after the last selected character
  109. bool mSelected; ///< this flag is set if any text is selected
  110. };
  111. typedef void (*Fl_Text_Modify_Cb)(int pos, int nInserted, int nDeleted,
  112. int nRestyled, const char* deletedText,
  113. void* cbArg);
  114. typedef void (*Fl_Text_Predelete_Cb)(int pos, int nDeleted, void* cbArg);
  115. /**
  116. \brief This class manages unicode displayed in one or more Fl_Text_Display widgets.
  117. All text in Fl_Text_Buffermust be encoded in UTF-8. All indices used in the
  118. function calls must be aligned to the start of a UTF-8 sequence. All indices
  119. and pointers returned will be aligned. All functions that return a single
  120. character will return that in an unsiged int in UCS-4 encoding.
  121. The Fl_Text_Buffer class is used by the Fl_Text_Display
  122. and Fl_Text_Editor to manage complex text data and is based upon the
  123. excellent NEdit text editor engine - see http://www.nedit.org/.
  124. */
  125. class FL_EXPORT Fl_Text_Buffer {
  126. public:
  127. /**
  128. Create an empty text buffer of a pre-determined size.
  129. \param requestedSize use this to avoid unnecessary re-allocation
  130. if you know exactly how much the buffer will need to hold
  131. \param preferredGapSize Initial size for the buffer gap (empty space
  132. in the buffer where text might be inserted
  133. if the user is typing sequential chars)
  134. */
  135. Fl_Text_Buffer(int requestedSize = 0, int preferredGapSize = 1024);
  136. /**
  137. Frees a text buffer
  138. */
  139. ~Fl_Text_Buffer();
  140. /**
  141. \brief Returns the number of bytes in the buffer.
  142. \return size of text in bytes
  143. */
  144. int length() const { return mLength; }
  145. /**
  146. \brief Get a copy of the entire contents of the text buffer.
  147. Memory is allocated to contain the returned string, which the caller
  148. must free.
  149. \return newly allocated text buffer - must be free'd, text is utf8
  150. */
  151. char* text() const;
  152. /**
  153. Replaces the entire contents of the text buffer.
  154. \param text Text must be valid utf8. if null an empty string is substituted.
  155. */
  156. void text(const char* text);
  157. /**
  158. \brief Get a copy of a part of the text buffer.
  159. Return a copy of the text between \p start and \p end character positions
  160. from text buffer \p buf. Positions start at 0, and the range does not
  161. include the character pointed to by \p end.
  162. When you are done with the text, free it using the free() function.
  163. \param start byte offset to first character
  164. \param end byte offset after last character in range
  165. \return newly allocated text buffer - must be free'd, text is utf8
  166. */
  167. char* text_range(int start, int end) const;
  168. /**
  169. Returns the character at the specified position pos in the buffer.
  170. Positions start at 0
  171. \param pos byte offset into buffer, pos must be at a character boundary
  172. \return Unicode UCS-4 encoded character
  173. */
  174. unsigned int char_at(int pos) const;
  175. /**
  176. Returns the raw byte at the specified position pos in the buffer.
  177. Positions start at 0
  178. \param pos byte offset into buffer
  179. \return unencoded raw byte
  180. */
  181. char byte_at(int pos) const;
  182. /**
  183. Convert a byte offset in buffer into a memory address.
  184. \param pos byte offset into buffer
  185. \return byte offset converted to a memory address
  186. */
  187. const char *address(int pos) const
  188. { return (pos < mGapStart) ? mBuf+pos : mBuf+pos+mGapEnd-mGapStart; }
  189. /**
  190. Convert a byte offset in buffer into a memory address.
  191. \param pos byte offset into buffer
  192. \return byte offset converted to a memory address
  193. */
  194. char *address(int pos)
  195. { return (pos < mGapStart) ? mBuf+pos : mBuf+pos+mGapEnd-mGapStart; }
  196. /**
  197. Inserts null-terminated string \p text at position \p pos.
  198. \param pos insertion position as byte offset (must be utf-8 character aligned)
  199. \param text utf-8 encoded and nul terminated text
  200. */
  201. void insert(int pos, const char* text);
  202. /**
  203. Appends the text string to the end of the buffer.
  204. \param t utf-8 encoded and nul terminated text
  205. */
  206. void append(const char* t) { insert(length(), t); }
  207. /**
  208. Deletes a range of characters in the buffer.
  209. \param start byte offset to first character to be removed
  210. \param end byte offset to charcatre after last character to be removed
  211. */
  212. void remove(int start, int end);
  213. /**
  214. Deletes the characters between \p start and \p end, and inserts the null-terminated string \p text in their place in the buffer.
  215. \param start byte offset to first character to be removed and new insert position
  216. \param end byte offset to charcatre after last character to be removed
  217. \param text utf-8 encoded and nul terminated text
  218. */
  219. void replace(int start, int end, const char *text);
  220. /**
  221. Copies text from one buffer to this one.
  222. \param fromBuf source text buffer may be the same as this
  223. \param fromStart byte offset into buffer
  224. \param fromEnd byte offset into buffer
  225. \param toPos destination byte offset into buffer
  226. */
  227. void copy(Fl_Text_Buffer* fromBuf, int fromStart, int fromEnd, int toPos);
  228. /**
  229. Undo text modification according to the undo variables or insert text
  230. from the undo buffer
  231. */
  232. int undo(int *cp=0);
  233. /**
  234. Lets the undo system know if we can undo changes
  235. */
  236. void canUndo(char flag=1);
  237. /**
  238. Inserts a file at the specified position. Returns 0 on success,
  239. non-zero on error (strerror() contains reason). 1 indicates open
  240. for read failed (no data loaded). 2 indicates error occurred
  241. while reading data (data was partially loaded).
  242. File can be UTF-8 or CP1252-encoded.
  243. If the input file is not UTF-8-encoded, the Fl_Text_Buffer widget will contain
  244. UTF-8-transcoded data. By default, the message Fl_Text_Buffer::file_encoding_warning_message
  245. will warn the user about this.
  246. \see input_file_was_transcoded and transcoding_warning_action.
  247. */
  248. int insertfile(const char *file, int pos, int buflen = 128*1024);
  249. /**
  250. Appends the named file to the end of the buffer. See also insertfile().
  251. */
  252. int appendfile(const char *file, int buflen = 128*1024)
  253. { return insertfile(file, length(), buflen); }
  254. /**
  255. Loads a text file into the buffer. See also insertfile().
  256. */
  257. int loadfile(const char *file, int buflen = 128*1024)
  258. { select(0, length()); remove_selection(); return appendfile(file, buflen); }
  259. /**
  260. Writes the specified portions of the file to a file. Returns 0 on success, non-zero
  261. on error (strerror() contains reason). 1 indicates open for write failed
  262. (no data saved). 2 indicates error occurred while writing data
  263. (data was partially saved).
  264. */
  265. int outputfile(const char *file, int start, int end, int buflen = 128*1024);
  266. /**
  267. Saves a text file from the current buffer
  268. */
  269. int savefile(const char *file, int buflen = 128*1024)
  270. { return outputfile(file, 0, length(), buflen); }
  271. /**
  272. Gets the tab width.
  273. */
  274. int tab_distance() const { return mTabDist; }
  275. /**
  276. Set the hardware tab distance (width) used by all displays for this buffer,
  277. and used in computing offsets for rectangular selection operations.
  278. */
  279. void tab_distance(int tabDist);
  280. /**
  281. Selects a range of characters in the buffer.
  282. */
  283. void select(int start, int end);
  284. /**
  285. Returns a non 0 value if text has been selected, 0 otherwise
  286. */
  287. int selected() const { return mPrimary.selected(); }
  288. /**
  289. Cancels any previous selection on the primary text selection object
  290. */
  291. void unselect();
  292. /**
  293. Gets the selection position
  294. */
  295. int selection_position(int* start, int* end);
  296. /**
  297. Returns the currently selected text. When you are done with
  298. the text, free it using the free() function.
  299. */
  300. char* selection_text();
  301. /**
  302. Removes the text in the primary selection.
  303. */
  304. void remove_selection();
  305. /**
  306. Replaces the text in the primary selection.
  307. */
  308. void replace_selection(const char* text);
  309. /**
  310. Selects a range of characters in the secondary selection.
  311. */
  312. void secondary_select(int start, int end);
  313. /**
  314. Returns a non 0 value if text has been selected in the secondary
  315. text selection, 0 otherwise
  316. */
  317. int secondary_selected() { return mSecondary.selected(); }
  318. /**
  319. Clears any selection in the secondary text selection object.
  320. */
  321. void secondary_unselect();
  322. /**
  323. Returns the current selection in the secondary text selection object.
  324. */
  325. int secondary_selection_position(int* start, int* end);
  326. /**
  327. Returns the text in the secondary selection. When you are
  328. done with the text, free it using the free() function.
  329. */
  330. char* secondary_selection_text();
  331. /**
  332. Removes the text from the buffer corresponding to the secondary text selection object.
  333. */
  334. void remove_secondary_selection();
  335. /**
  336. Replaces the text from the buffer corresponding to the secondary
  337. text selection object with the new string \p text.
  338. */
  339. void replace_secondary_selection(const char* text);
  340. /**
  341. Highlights the specified text within the buffer.
  342. */
  343. void highlight(int start, int end);
  344. /**
  345. Returns the highlighted text. When you are done with the
  346. text, free it using the free() function.
  347. */
  348. int highlight() { return mHighlight.selected(); }
  349. /**
  350. Unhighlights text in the buffer.
  351. */
  352. void unhighlight();
  353. /**
  354. Highlights the specified text between \p start and \p end within the buffer.
  355. */
  356. int highlight_position(int* start, int* end);
  357. /**
  358. Returns the highlighted text. When you are done with the
  359. text, free it using the free() function.
  360. */
  361. char* highlight_text();
  362. /**
  363. Adds a callback function that is called whenever the text buffer is
  364. modified. The callback function is declared as follows:
  365. \code
  366. typedef void (*Fl_Text_Modify_Cb)(int pos, int nInserted, int nDeleted,
  367. int nRestyled, const char* deletedText,
  368. void* cbArg);
  369. \endcode
  370. */
  371. void add_modify_callback(Fl_Text_Modify_Cb bufModifiedCB, void* cbArg);
  372. /**
  373. Removes a modify callback.
  374. */
  375. void remove_modify_callback(Fl_Text_Modify_Cb bufModifiedCB, void* cbArg);
  376. /**
  377. Calls all modify callbacks that have been registered using
  378. the add_modify_callback()
  379. method.
  380. */
  381. void call_modify_callbacks() { call_modify_callbacks(0, 0, 0, 0, 0); }
  382. /**
  383. Adds a callback routine to be called before text is deleted from the buffer.
  384. */
  385. void add_predelete_callback(Fl_Text_Predelete_Cb bufPredelCB, void* cbArg);
  386. /**
  387. Removes a callback routine \p bufPreDeleteCB associated with argument \p cbArg
  388. to be called before text is deleted from the buffer.
  389. */
  390. void remove_predelete_callback(Fl_Text_Predelete_Cb predelCB, void* cbArg);
  391. /**
  392. Calls the stored pre-delete callback procedure(s) for this buffer to update
  393. the changed area(s) on the screen and any other listeners.
  394. */
  395. void call_predelete_callbacks() { call_predelete_callbacks(0, 0); }
  396. /**
  397. Returns the text from the entire line containing the specified
  398. character position. When you are done with the text, free it
  399. using the free() function.
  400. \param pos byte index into buffer
  401. \return copy of utf8 text, must be free'd
  402. */
  403. char* line_text(int pos) const;
  404. /**
  405. Returns the position of the start of the line containing position \p pos.
  406. \param pos byte index into buffer
  407. \return byte offset to line start
  408. */
  409. int line_start(int pos) const;
  410. /**
  411. Finds and returns the position of the end of the line containing position \p pos
  412. (which is either a pointer to the newline character ending the line,
  413. or a pointer to one character beyond the end of the buffer)
  414. \param pos byte index into buffer
  415. \return byte offset to line end
  416. */
  417. int line_end(int pos) const;
  418. /**
  419. Returns the position corresponding to the start of the word
  420. \param pos byte index into buffer
  421. \return byte offset to word start
  422. */
  423. int word_start(int pos) const;
  424. /**
  425. Returns the position corresponding to the end of the word.
  426. \param pos byte index into buffer
  427. \return byte offset to word end
  428. */
  429. int word_end(int pos) const;
  430. /**
  431. Count the number of displayed characters between buffer position
  432. \p lineStartPos and \p targetPos. (displayed characters are the characters
  433. shown on the screen to represent characters in the buffer, where tabs and
  434. control characters are expanded)
  435. */
  436. int count_displayed_characters(int lineStartPos, int targetPos) const;
  437. /**
  438. Count forward from buffer position \p startPos in displayed characters
  439. (displayed characters are the characters shown on the screen to represent
  440. characters in the buffer, where tabs and control characters are expanded)
  441. \param lineStartPos byte offset into buffer
  442. \param nChars number of bytes that are sent to the display
  443. \return byte offset in input after all output bytes are sent
  444. */
  445. int skip_displayed_characters(int lineStartPos, int nChars);
  446. /**
  447. Counts the number of newlines between \p startPos and \p endPos in buffer.
  448. The character at position \p endPos is not counted.
  449. */
  450. int count_lines(int startPos, int endPos) const;
  451. /**
  452. Finds the first character of the line \p nLines forward from \p startPos
  453. in the buffer and returns its position
  454. */
  455. int skip_lines(int startPos, int nLines);
  456. /**
  457. Finds and returns the position of the first character of the line \p nLines backwards
  458. from \p startPos (not counting the character pointed to by \p startpos if
  459. that is a newline) in the buffer. \p nLines == 0 means find the beginning of the line
  460. */
  461. int rewind_lines(int startPos, int nLines);
  462. /**
  463. Finds the next occurrence of the specified character.
  464. Search forwards in buffer for character \p searchChar, starting
  465. with the character \p startPos, and returning the result in \p foundPos
  466. returns 1 if found, 0 if not. (The difference between this and
  467. BufSearchForward is that it's optimized for single characters. The
  468. overall performance of the text widget is dependent on its ability to
  469. count lines quickly, hence searching for a single character: newline)
  470. \param startPos byte offset to start position
  471. \param searchChar UCS-4 character that we want to find
  472. \param foundPos byte offset where the character was found
  473. \return 1 if found, 0 if not
  474. */
  475. int findchar_forward(int startPos, unsigned searchChar, int* foundPos) const;
  476. /**
  477. Search backwards in buffer \p buf for character \p searchChar, starting
  478. with the character BEFORE \p startPos, returning the result in \p foundPos
  479. returns 1 if found, 0 if not. (The difference between this and
  480. BufSearchBackward is that it's optimized for single characters. The
  481. overall performance of the text widget is dependent on its ability to
  482. count lines quickly, hence searching for a single character: newline)
  483. \param startPos byte offset to start position
  484. \param searchChar UCS-4 character that we want to find
  485. \param foundPos byte offset where the character was found
  486. \return 1 if found, 0 if not
  487. */
  488. int findchar_backward(int startPos, unsigned int searchChar, int* foundPos) const;
  489. /**
  490. Search forwards in buffer for string \p searchString, starting with the
  491. character \p startPos, and returning the result in \p foundPos
  492. returns 1 if found, 0 if not.
  493. \param startPos byte offset to start position
  494. \param searchString utf8 string that we want to find
  495. \param foundPos byte offset where the string was found
  496. \param matchCase if set, match character case
  497. \return 1 if found, 0 if not
  498. */
  499. int search_forward(int startPos, const char* searchString, int* foundPos,
  500. int matchCase = 0) const;
  501. /**
  502. Search backwards in buffer for string <i>searchCharssearchString</i>, starting with the
  503. character BEFORE \p startPos, returning the result in \p foundPos
  504. returns 1 if found, 0 if not.
  505. \param startPos byte offset to start position
  506. \param searchString utf8 string that we want to find
  507. \param foundPos byte offset where the string was found
  508. \param matchCase if set, match character case
  509. \return 1 if found, 0 if not
  510. */
  511. int search_backward(int startPos, const char* searchString, int* foundPos,
  512. int matchCase = 0) const;
  513. /**
  514. Returns the primary selection.
  515. */
  516. const Fl_Text_Selection* primary_selection() const { return &mPrimary; }
  517. /**
  518. Returns the primary selection.
  519. */
  520. Fl_Text_Selection* primary_selection() { return &mPrimary; }
  521. /**
  522. Returns the secondary selection.
  523. */
  524. const Fl_Text_Selection* secondary_selection() const { return &mSecondary; }
  525. /**
  526. Returns the current highlight selection.
  527. */
  528. const Fl_Text_Selection* highlight_selection() const { return &mHighlight; }
  529. /**
  530. Returns the index of the previous character.
  531. \param ix index to the current char
  532. */
  533. int prev_char(int ix) const;
  534. int prev_char_clipped(int ix) const;
  535. /**
  536. Returns the index of the next character.
  537. \param ix index to the current char
  538. */
  539. int next_char(int ix) const;
  540. int next_char_clipped(int ix) const;
  541. /**
  542. Align an index into the buffer to the current or previous utf8 boundary.
  543. */
  544. int utf8_align(int) const;
  545. /**
  546. \brief true iff the loaded file has been transcoded to UTF-8
  547. */
  548. int input_file_was_transcoded;
  549. /** This message may be displayed using the fl_alert() function when a file
  550. which was not UTF-8 encoded is input.
  551. */
  552. static const char* file_encoding_warning_message;
  553. /**
  554. \brief Pointer to a function called after reading a non UTF-8 encoded file.
  555. This function is called after reading a file if the file content
  556. was transcoded to UTF-8. Its default implementation calls fl_alert()
  557. with the text of \ref file_encoding_warning_message. No warning message is
  558. displayed if this pointer is set to NULL. Use \ref input_file_was_transcoded
  559. to be informed if file input required transcoding to UTF-8.
  560. */
  561. void (*transcoding_warning_action)(Fl_Text_Buffer*);
  562. protected:
  563. /**
  564. Calls the stored modify callback procedure(s) for this buffer to update the
  565. changed area(s) on the screen and any other listeners.
  566. */
  567. void call_modify_callbacks(int pos, int nDeleted, int nInserted,
  568. int nRestyled, const char* deletedText) const;
  569. /**
  570. Calls the stored pre-delete callback procedure(s) for this buffer to update
  571. the changed area(s) on the screen and any other listeners.
  572. */
  573. void call_predelete_callbacks(int pos, int nDeleted) const;
  574. /**
  575. Internal (non-redisplaying) version of BufInsert. Returns the length of
  576. text inserted (this is just strlen(\p text), however this calculation can be
  577. expensive and the length will be required by any caller who will continue
  578. on to call redisplay). \p pos must be contiguous with the existing text in
  579. the buffer (i.e. not past the end).
  580. \return the number of bytes inserted
  581. */
  582. int insert_(int pos, const char* text);
  583. /**
  584. Internal (non-redisplaying) version of BufRemove. Removes the contents
  585. of the buffer between start and end (and moves the gap to the site of
  586. the delete).
  587. */
  588. void remove_(int start, int end);
  589. /**
  590. Calls the stored redisplay procedure(s) for this buffer to update the
  591. screen for a change in a selection.
  592. */
  593. void redisplay_selection(Fl_Text_Selection* oldSelection,
  594. Fl_Text_Selection* newSelection) const;
  595. /**
  596. Move the gap to start at a new position.
  597. */
  598. void move_gap(int pos);
  599. /**
  600. Reallocates the text storage in the buffer to have a gap starting at \p newGapStart
  601. and a gap size of \p newGapLen, preserving the buffer's current contents.
  602. */
  603. void reallocate_with_gap(int newGapStart, int newGapLen);
  604. char* selection_text_(Fl_Text_Selection* sel) const;
  605. /**
  606. Removes the text from the buffer corresponding to \p sel.
  607. */
  608. void remove_selection_(Fl_Text_Selection* sel);
  609. /**
  610. Replaces the \p text in selection \p sel.
  611. */
  612. void replace_selection_(Fl_Text_Selection* sel, const char* text);
  613. /**
  614. Updates all of the selections in the buffer for changes in the buffer's text
  615. */
  616. void update_selections(int pos, int nDeleted, int nInserted);
  617. Fl_Text_Selection mPrimary; /**< highlighted areas */
  618. Fl_Text_Selection mSecondary; /**< highlighted areas */
  619. Fl_Text_Selection mHighlight; /**< highlighted areas */
  620. int mLength; /**< length of the text in the buffer (the length
  621. of the buffer itself must be calculated:
  622. gapEnd - gapStart + length) */
  623. char* mBuf; /**< allocated memory where the text is stored */
  624. int mGapStart; /**< points to the first character of the gap */
  625. int mGapEnd; /**< points to the first char after the gap */
  626. // The hardware tab distance used by all displays for this buffer,
  627. // and used in computing offsets for rectangular selection operations.
  628. int mTabDist; /**< equiv. number of characters in a tab */
  629. int mNModifyProcs; /**< number of modify-redisplay procs attached */
  630. Fl_Text_Modify_Cb *mModifyProcs;/**< procedures to call when buffer is
  631. modified to redisplay contents */
  632. void** mCbArgs; /**< caller arguments for modifyProcs above */
  633. int mNPredeleteProcs; /**< number of pre-delete procs attached */
  634. Fl_Text_Predelete_Cb *mPredeleteProcs; /**< procedure to call before text is deleted
  635. from the buffer; at most one is supported. */
  636. void **mPredeleteCbArgs; /**< caller argument for pre-delete proc above */
  637. int mCursorPosHint; /**< hint for reasonable cursor position after
  638. a buffer modification operation */
  639. char mCanUndo; /**< if this buffer is used for attributes, it must
  640. not do any undo calls */
  641. int mPreferredGapSize; /**< the default allocation for the text gap is 1024
  642. bytes and should only be increased if frequent
  643. and large changes in buffer size are expected */
  644. };
  645. #endif
  646. //
  647. // End of "$Id: Fl_Text_Buffer.H 9956 2013-08-12 15:46:57Z greg.ercolano $".
  648. //