You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

782 lines
27KB

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