Blender  V3.3
rna_text_api.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include <stdio.h>
8 #include <stdlib.h>
9 
10 #include "BLI_utildefines.h"
11 
12 #include "ED_text.h"
13 
14 #include "RNA_define.h"
15 
16 #include "rna_internal.h" /* own include */
17 
18 #ifdef RNA_RUNTIME
19 
20 # include "WM_api.h"
21 # include "WM_types.h"
22 
23 static void rna_Text_clear(Text *text)
24 {
25  BKE_text_clear(text);
27 }
28 
29 static void rna_Text_write(Text *text, const char *str)
30 {
31  BKE_text_write(text, str, strlen(str));
33 }
34 
35 static void rna_Text_from_string(Text *text, const char *str)
36 {
37  BKE_text_clear(text);
38  BKE_text_write(text, str, strlen(str));
39 }
40 
41 static void rna_Text_as_string(Text *text, int *r_result_len, const char **result)
42 {
43  size_t result_len;
44  *result = txt_to_buf(text, &result_len);
45  *r_result_len = result_len;
46 }
47 
48 static void rna_Text_select_set(Text *text, int startl, int startc, int endl, int endc)
49 {
50  txt_sel_set(text, startl, startc, endl, endc);
52 }
53 
54 static void rna_Text_cursor_set(Text *text, int line, int ch, bool select)
55 {
56  txt_move_to(text, line, ch, select);
58 }
59 
60 #else
61 
63 {
64  FunctionRNA *func;
65  PropertyRNA *parm;
66 
67  func = RNA_def_function(srna, "clear", "rna_Text_clear");
68  RNA_def_function_ui_description(func, "clear the text block");
69 
70  func = RNA_def_function(srna, "write", "rna_Text_write");
72  func, "write text at the cursor location and advance to the end of the text block");
73  parm = RNA_def_string(func, "text", "Text", 0, "", "New text for this data-block");
75 
76  func = RNA_def_function(srna, "from_string", "rna_Text_from_string");
77  RNA_def_function_ui_description(func, "Replace text with this string.");
78  parm = RNA_def_string(func, "text", "Text", 0, "", "");
80 
81  func = RNA_def_function(srna, "as_string", "rna_Text_as_string");
82  RNA_def_function_ui_description(func, "Return the text as a string");
83  parm = RNA_def_string(func, "text", "Text", 0, "", "");
85 
86  func = RNA_def_function(
87  srna, "is_syntax_highlight_supported", "ED_text_is_syntax_highlight_supported");
89  RNA_def_boolean(func, "is_syntax_highlight_supported", false, "", ""));
91  "Returns True if the editor supports syntax highlighting "
92  "for the current text datablock");
93 
94  func = RNA_def_function(srna, "select_set", "rna_Text_select_set");
95  RNA_def_function_ui_description(func, "Set selection range by line and character index");
96  parm = RNA_def_int(func, "line_start", 0, INT_MIN, INT_MAX, "Start Line", "", INT_MIN, INT_MAX);
98  parm = RNA_def_int(
99  func, "char_start", 0, INT_MIN, INT_MAX, "Start Character", "", INT_MIN, INT_MAX);
101  parm = RNA_def_int(func, "line_end", 0, INT_MIN, INT_MAX, "End Line", "", INT_MIN, INT_MAX);
103  parm = RNA_def_int(func, "char_end", 0, INT_MIN, INT_MAX, "End Character", "", INT_MIN, INT_MAX);
105 
106  func = RNA_def_function(srna, "cursor_set", "rna_Text_cursor_set");
107  RNA_def_function_ui_description(func, "Set cursor by line and (optionally) character index");
108  parm = RNA_def_int(func, "line", 0, 0, INT_MAX, "Line", "", 0, INT_MAX);
110  parm = RNA_def_int(func, "character", 0, 0, INT_MAX, "Character", "", 0, INT_MAX);
111  RNA_def_boolean(func, "select", false, "", "Select when moving the cursor");
112 }
113 
114 #endif
void txt_sel_set(struct Text *text, int startl, int startc, int endl, int endc)
Definition: text.c:1274
struct Text struct Text void BKE_text_clear(struct Text *text) ATTR_NONNULL(1)
Definition: text.c:516
char * txt_to_buf(struct Text *text, size_t *r_buf_strlen) ATTR_NONNULL(1
void txt_move_to(struct Text *text, unsigned int line, unsigned int ch, bool sel)
Definition: text.c:1096
void BKE_text_write(struct Text *text, const char *str, int str_len) ATTR_NONNULL(1
@ PARM_REQUIRED
Definition: RNA_types.h:352
@ PARM_OUTPUT
Definition: RNA_types.h:353
@ PROP_DYNAMIC
Definition: RNA_types.h:290
#define NA_EDITED
Definition: WM_types.h:523
#define NC_TEXT
Definition: WM_types.h:336
__forceinline const avxb select(const avxb &m, const avxb &t, const avxb &f)
Definition: avxb.h:154
#define str(s)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3493
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
Definition: rna_define.c:4312
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
Definition: rna_define.c:4273
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
Definition: rna_define.c:4347
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3687
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, int default_value, int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
Definition: rna_define.c:3597
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
Definition: rna_define.c:1518
void RNA_api_text(StructRNA *srna)
Definition: rna_text_api.c:62
void WM_main_add_notifier(unsigned int type, void *reference)