Blender V4.3
rna_text_api.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include <cstdio>
10#include <cstdlib>
11
12#include "BLI_utildefines.h"
13
14#include "ED_text.hh"
15
16#include "RNA_define.hh"
17
18#include "rna_internal.hh" /* own include */
19
20#ifdef RNA_RUNTIME
21
22# include "WM_api.hh"
23# include "WM_types.hh"
24
25static void rna_Text_clear(Text *text)
26{
27 BKE_text_clear(text);
29}
30
31static void rna_Text_write(Text *text, const char *str)
32{
33 BKE_text_write(text, str, strlen(str));
35}
36
37static void rna_Text_from_string(Text *text, const char *str)
38{
39 BKE_text_clear(text);
40 BKE_text_write(text, str, strlen(str));
41}
42
43static void rna_Text_as_string(Text *text, const char **result, int *r_result_len)
44{
45 size_t result_len;
46 *result = txt_to_buf(text, &result_len);
47 *r_result_len = result_len;
48}
49
50static void rna_Text_select_set(Text *text, int startl, int startc, int endl, int endc)
51{
52 txt_sel_set(text, startl, startc, endl, endc);
54}
55
56static void rna_Text_cursor_set(Text *text, int line, int ch, bool select)
57{
58 txt_move_to(text, line, ch, select);
60}
61
62#else
63
65{
66 FunctionRNA *func;
67 PropertyRNA *parm;
68
69 func = RNA_def_function(srna, "clear", "rna_Text_clear");
70 RNA_def_function_ui_description(func, "clear the text block");
71
72 func = RNA_def_function(srna, "write", "rna_Text_write");
74 func, "write text at the cursor location and advance to the end of the text block");
75 parm = RNA_def_string(func, "text", "Text", 0, "", "New text for this data-block");
77
78 func = RNA_def_function(srna, "from_string", "rna_Text_from_string");
79 RNA_def_function_ui_description(func, "Replace text with this string.");
80 parm = RNA_def_string(func, "text", "Text", 0, "", "");
82
83 func = RNA_def_function(srna, "as_string", "rna_Text_as_string");
84 RNA_def_function_ui_description(func, "Return the text as a string");
85 parm = RNA_def_string(func, "text", "Text", 0, "", "");
87
88 func = RNA_def_function(
89 srna, "is_syntax_highlight_supported", "ED_text_is_syntax_highlight_supported");
91 RNA_def_boolean(func, "is_syntax_highlight_supported", false, "", ""));
93 "Returns True if the editor supports syntax highlighting "
94 "for the current text datablock");
95
96 func = RNA_def_function(srna, "select_set", "rna_Text_select_set");
97 RNA_def_function_ui_description(func, "Set selection range by line and character index");
98 parm = RNA_def_int(func, "line_start", 0, INT_MIN, INT_MAX, "Start Line", "", INT_MIN, INT_MAX);
100 parm = RNA_def_int(
101 func, "char_start", 0, INT_MIN, INT_MAX, "Start Character", "", INT_MIN, INT_MAX);
103 parm = RNA_def_int(func, "line_end", 0, INT_MIN, INT_MAX, "End Line", "", INT_MIN, INT_MAX);
105 parm = RNA_def_int(func, "char_end", 0, INT_MIN, INT_MAX, "End Character", "", INT_MIN, INT_MAX);
107
108 func = RNA_def_function(srna, "cursor_set", "rna_Text_cursor_set");
109 RNA_def_function_ui_description(func, "Set cursor by line and (optionally) character index");
110 parm = RNA_def_int(func, "line", 0, 0, INT_MAX, "Line", "", 0, INT_MAX);
112 parm = RNA_def_int(func, "character", 0, 0, INT_MAX, "Character", "", 0, INT_MAX);
113 RNA_def_boolean(func, "select", false, "", "Select when moving the cursor");
114}
115
116#endif
void txt_sel_set(struct Text *text, int startl, int startc, int endl, int endc)
Definition text.cc:1282
char * txt_to_buf(struct Text *text, size_t *r_buf_strlen) ATTR_NONNULL(1
struct Text struct Text void BKE_text_clear(struct Text *text) ATTR_NONNULL(1)
Definition text.cc:510
void txt_move_to(struct Text *text, unsigned int line, unsigned int ch, bool sel)
Definition text.cc:1099
void BKE_text_write(struct Text *text, const char *str, int str_len) ATTR_NONNULL(1
@ PARM_REQUIRED
Definition RNA_types.hh:397
@ PARM_OUTPUT
Definition RNA_types.hh:398
PropertyFlag
Definition RNA_types.hh:201
@ PROP_DYNAMIC
Definition RNA_types.hh:317
#define NA_EDITED
Definition WM_types.hh:550
#define NC_TEXT
Definition WM_types.hh:353
#define str(s)
ccl_device_inline float4 select(const int4 mask, const float4 a, const float4 b)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void RNA_api_text(StructRNA *srna)
void WM_main_add_notifier(uint type, void *reference)