BKE_text.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * ***** BEGIN GPL LICENSE BLOCK *****
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software Foundation,
  16. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. *
  18. * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
  19. * All rights reserved.
  20. *
  21. * The Original Code is: all of this file.
  22. *
  23. * Contributor(s): none yet.
  24. *
  25. * ***** END GPL LICENSE BLOCK *****
  26. */
  27. #ifndef __BKE_TEXT_H__
  28. #define __BKE_TEXT_H__
  29. /** \file BKE_text.h
  30. * \ingroup bke
  31. * \since March 2001
  32. * \author nzc
  33. */
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. struct Main;
  38. struct Text;
  39. struct TextLine;
  40. void BKE_text_free_lines (struct Text *text);
  41. void BKE_text_free (struct Text *text);
  42. void txt_set_undostate (int u);
  43. int txt_get_undostate (void);
  44. void BKE_text_init(struct Text *ta);
  45. struct Text *BKE_text_add (struct Main *bmain, const char *name);
  46. int txt_extended_ascii_as_utf8(char **str);
  47. bool BKE_text_reload(struct Text *text);
  48. struct Text *BKE_text_load_ex(struct Main *bmain, const char *file, const char *relpath,
  49. const bool is_internal);
  50. struct Text *BKE_text_load (struct Main *bmain, const char *file, const char *relpath);
  51. struct Text *BKE_text_copy (struct Main *bmain, const struct Text *ta);
  52. void BKE_text_make_local (struct Main *bmain, struct Text *text, const bool lib_local);
  53. void BKE_text_clear (struct Text *text);
  54. void BKE_text_write (struct Text *text, const char *str);
  55. int BKE_text_file_modified_check(struct Text *text);
  56. void BKE_text_file_modified_ignore(struct Text *text);
  57. char *txt_to_buf (struct Text *text);
  58. void txt_clean_text (struct Text *text);
  59. void txt_order_cursors (struct Text *text, const bool reverse);
  60. int txt_find_string (struct Text *text, const char *findstr, int wrap, int match_case);
  61. bool txt_has_sel (struct Text *text);
  62. int txt_get_span (struct TextLine *from, struct TextLine *to);
  63. int txt_utf8_offset_to_index(const char *str, int offset);
  64. int txt_utf8_index_to_offset(const char *str, int index);
  65. int txt_utf8_offset_to_column(const char *str, int offset);
  66. int txt_utf8_column_to_offset(const char *str, int column);
  67. void txt_move_up (struct Text *text, const bool sel);
  68. void txt_move_down (struct Text *text, const bool sel);
  69. void txt_move_left (struct Text *text, const bool sel);
  70. void txt_move_right (struct Text *text, const bool sel);
  71. void txt_jump_left (struct Text *text, const bool sel, const bool use_init_step);
  72. void txt_jump_right (struct Text *text, const bool sel, const bool use_init_step);
  73. void txt_move_bof (struct Text *text, const bool sel);
  74. void txt_move_eof (struct Text *text, const bool sel);
  75. void txt_move_bol (struct Text *text, const bool sel);
  76. void txt_move_eol (struct Text *text, const bool sel);
  77. void txt_move_toline (struct Text *text, unsigned int line, const bool sel);
  78. void txt_move_to (struct Text *text, unsigned int line, unsigned int ch, const bool sel);
  79. void txt_pop_sel (struct Text *text);
  80. void txt_delete_char (struct Text *text);
  81. void txt_delete_word (struct Text *text);
  82. void txt_delete_selected (struct Text *text);
  83. void txt_sel_all (struct Text *text);
  84. void txt_sel_clear (struct Text *text);
  85. void txt_sel_line (struct Text *text);
  86. char *txt_sel_to_buf (struct Text *text);
  87. void txt_insert_buf (struct Text *text, const char *in_buffer);
  88. void txt_undo_add_op (struct Text *text, int op);
  89. void txt_do_undo (struct Text *text);
  90. void txt_do_redo (struct Text *text);
  91. void txt_split_curline (struct Text *text);
  92. void txt_backspace_char (struct Text *text);
  93. void txt_backspace_word (struct Text *text);
  94. bool txt_add_char (struct Text *text, unsigned int add);
  95. bool txt_add_raw_char (struct Text *text, unsigned int add);
  96. bool txt_replace_char (struct Text *text, unsigned int add);
  97. void txt_unindent (struct Text *text);
  98. void txt_comment (struct Text *text);
  99. void txt_indent (struct Text *text);
  100. void txt_uncomment (struct Text *text);
  101. void txt_move_lines (struct Text *text, const int direction);
  102. void txt_duplicate_line (struct Text *text);
  103. int txt_setcurr_tab_spaces(struct Text *text, int space);
  104. bool txt_cursor_is_line_start(struct Text *text);
  105. bool txt_cursor_is_line_end(struct Text *text);
  106. int txt_calc_tab_left(struct TextLine *line, int ch);
  107. int txt_calc_tab_right(struct TextLine *line, int ch);
  108. #if 0
  109. void txt_print_undo (struct Text *text);
  110. #endif
  111. /* utility functions, could be moved somewhere more generic but are python/text related */
  112. int text_check_bracket(const char ch);
  113. bool text_check_delim(const char ch);
  114. bool text_check_digit(const char ch);
  115. bool text_check_identifier(const char ch);
  116. bool text_check_identifier_nodigit(const char ch);
  117. bool text_check_whitespace(const char ch);
  118. int text_find_identifier_start(const char *str, int i);
  119. /* defined in bpy_interface.c */
  120. extern int text_check_identifier_unicode(const unsigned int ch);
  121. extern int text_check_identifier_nodigit_unicode(const unsigned int ch);
  122. enum {
  123. TXT_MOVE_LINE_UP = -1,
  124. TXT_MOVE_LINE_DOWN = 1
  125. };
  126. /* Undo opcodes */
  127. /* Complex editing */
  128. /* 1 - opcode is followed by 1 byte for ascii character and opcode (repeat)) */
  129. /* 2 - opcode is followed by 2 bytes for utf-8 character and opcode (repeat)) */
  130. /* 3 - opcode is followed by 3 bytes for utf-8 character and opcode (repeat)) */
  131. /* 4 - opcode is followed by 4 bytes for unicode character and opcode (repeat)) */
  132. #define UNDO_INSERT_1 013
  133. #define UNDO_INSERT_2 014
  134. #define UNDO_INSERT_3 015
  135. #define UNDO_INSERT_4 016
  136. #define UNDO_BS_1 017
  137. #define UNDO_BS_2 020
  138. #define UNDO_BS_3 021
  139. #define UNDO_BS_4 022
  140. #define UNDO_DEL_1 023
  141. #define UNDO_DEL_2 024
  142. #define UNDO_DEL_3 025
  143. #define UNDO_DEL_4 026
  144. /* Text block (opcode is followed
  145. * by 4 character length ID + the text
  146. * block itself + the 4 character length
  147. * ID (repeat) and opcode (repeat)) */
  148. #define UNDO_DBLOCK 027 /* Delete block */
  149. #define UNDO_IBLOCK 030 /* Insert block */
  150. /* Misc */
  151. #define UNDO_INDENT 032
  152. #define UNDO_UNINDENT 033
  153. #define UNDO_COMMENT 034
  154. #define UNDO_UNCOMMENT 035
  155. #define UNDO_MOVE_LINES_UP 036
  156. #define UNDO_MOVE_LINES_DOWN 037
  157. #define UNDO_DUPLICATE 040
  158. #ifdef __cplusplus
  159. }
  160. #endif
  161. #endif