forked from HACKERALERT/imgui-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextEditorWrapper.cpp
245 lines (203 loc) · 7.24 KB
/
TextEditorWrapper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#include "TextEditorWrapper.h"
#include "TextEditor.h"
#include "WrapperConverter.h"
IggTextEditorLanguageDefinition IggNewLanguageDef()
{
TextEditor::LanguageDefinition *ld = new TextEditor::LanguageDefinition();
return static_cast<IggTextEditorLanguageDefinition>(ld);
}
void IggTextEditorLDSetName(IggTextEditorLanguageDefinition handle, const char *name)
{
TextEditor::LanguageDefinition *ld = reinterpret_cast<TextEditor::LanguageDefinition*>(handle);
ld->mName = name;
}
void IggTextEditorLDSetKeywords(IggTextEditorLanguageDefinition handle, const char **keywords, int length)
{
TextEditor::LanguageDefinition *ld = reinterpret_cast<TextEditor::LanguageDefinition*>(handle);
int i = 0;
for (i = 0; i < length; i++)
ld->mKeywords.insert(keywords[i]);
}
IggTextEditor IggNewTextEditor()
{
TextEditor *editor = new TextEditor();
return static_cast<IggTextEditor>(editor);
}
void IggTextEditorRender(IggTextEditor handle, const char* aTitle, IggVec2 const *size, int aBorder)
{
Vec2Wrapper sizeArg(size);
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
editor->Render(aTitle, *sizeArg, aBorder != 0);
}
void IggTextEditorSetShowWhitespaces(IggTextEditor handle, int aValue)
{
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
editor->SetShowWhitespaces(aValue != 0);
}
void IggTextEditorSetTabSize(IggTextEditor handle, int size)
{
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
editor->SetTabSize(size);
}
void IggTextEditorSetText(IggTextEditor handle, const char* text)
{
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
editor->SetText(text);
}
void IggTextEditorInsertText(IggTextEditor handle, const char *text)
{
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
editor->InsertText(text);
}
IggBool IggTextEditorHasSelection(IggTextEditor handle)
{
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
return editor->HasSelection() ? 1 : 0;
}
char const *IggTextEditorGetText(IggTextEditor handle)
{
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
std::string str = editor->GetText();
char* c = strcpy(new char[str.length() + 1], str.c_str());
return c;
}
char const *IggTextEditorGetWordUnderCursor(IggTextEditor handle)
{
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
std::string str = editor->GetWordUnderCursor();
char* c = strcpy(new char[str.length() + 1], str.c_str());
return c;
}
char const *IggTextEditorGetSelectedText(IggTextEditor handle)
{
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
std::string str = editor->GetSelectedText();
char* c = strcpy(new char[str.length() + 1], str.c_str());
return c;
}
char const *IggTextEditorGetCurrentLineText(IggTextEditor handle)
{
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
std::string str = editor->GetCurrentLineText();
char* c = strcpy(new char[str.length() + 1], str.c_str());
return c;
}
IggBool IggTextEditorIsTextChanged(IggTextEditor handle)
{
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
return editor->IsTextChanged() ? 1 : 0;
}
void IggTextEditorGetScreenCursorPos(IggTextEditor handle, int *x, int* y)
{
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
TextEditor::Coordinates col = editor->GetScreenCursorPosition();
*x = (float)col.mColumn;
*y = (float)col.mLine;
}
void IggTextEditorGetCursorPos(IggTextEditor handle, int* column, int* line)
{
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
TextEditor::Coordinates col = editor->GetCursorPosition();
*column = (float)col.mColumn;
*line = (float)col.mLine;
}
void IggTextEditorSetCursorPos(IggTextEditor handle, int column, int line)
{
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
TextEditor::Coordinates col(line, column);
editor->SetCursorPosition(col);
}
void IggTextEditorGetSelectionStart(IggTextEditor handle, int* column, int* line)
{
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
TextEditor::Coordinates col = editor->GetSelectionStart();
*column = (float)col.mColumn;
*line = (float)col.mLine;
}
void IggTextEditorSetLanguageDefinition(IggTextEditor handle, IggTextEditorLanguageDefinition defHandle)
{
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
TextEditor::LanguageDefinition *def = static_cast<TextEditor::LanguageDefinition*>(defHandle);
editor->SetLanguageDefinition(*def);
}
void IggTextEditorSetLanguageDefinitionSQL(IggTextEditor handle)
{
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
editor->SetLanguageDefinition(TextEditor::LanguageDefinition::SQL());
}
void IggTextEditorSetLanguageDefinitionCPP(IggTextEditor handle)
{
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
editor->SetLanguageDefinition(TextEditor::LanguageDefinition::CPlusPlus());
}
void IggTextEditorSetLanguageDefinitionC(IggTextEditor handle)
{
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
editor->SetLanguageDefinition(TextEditor::LanguageDefinition::C());
}
void IggTextEditorSetLanguageDefinitionLua(IggTextEditor handle)
{
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
editor->SetLanguageDefinition(TextEditor::LanguageDefinition::Lua());
}
IggTextEditorErrorMarkers IggTextEditorNewErrorMarkers()
{
TextEditor::ErrorMarkers *markers = new TextEditor::ErrorMarkers();
return static_cast<IggTextEditorErrorMarkers>(markers);
}
void IggTextEditorErrorMarkersInsert(IggTextEditorErrorMarkers handle, int pos, const char* errMsg)
{
TextEditor::ErrorMarkers *markers = reinterpret_cast<TextEditor::ErrorMarkers*>(handle);
markers->insert(std::pair<int, std::string>(pos, errMsg));
}
void IggTextEditorErrorMarkersClear(IggTextEditorErrorMarkers marker)
{
TextEditor::ErrorMarkers *markers = reinterpret_cast<TextEditor::ErrorMarkers*>(marker);
markers->clear();
}
unsigned int IggTextEditorErrorMarkersSize(IggTextEditorErrorMarkers handle)
{
TextEditor::ErrorMarkers *markers = reinterpret_cast<TextEditor::ErrorMarkers*>(handle);
return markers->size();
}
void IggTextEditorSetErrorMarkers(IggTextEditor handle, IggTextEditorErrorMarkers marker)
{
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
TextEditor::ErrorMarkers *markers = reinterpret_cast<TextEditor::ErrorMarkers*>(marker);
editor->SetErrorMarkers(*markers);
}
void IggTextEditorCopy(IggTextEditor handle)
{
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
editor->Copy();
}
void IggTextEditorCut(IggTextEditor handle)
{
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
editor->Cut();
}
void IggTextEditorPaste(IggTextEditor handle)
{
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
editor->Paste();
}
void IggTextEditorDelete(IggTextEditor handle)
{
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
editor->Delete();
}
void IggTextEditorSelectWordUnderCursor(IggTextEditor handle)
{
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
editor->SelectWordUnderCursor();
}
void IggTextEditorSelectAll(IggTextEditor handle)
{
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
editor->SelectAll();
}
void IggTextEditorSetHandleKeyboardInputs(IggTextEditor handle, int aValue)
{
TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
editor->SetHandleKeyboardInputs(aValue);
}