-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathctextselect.cpp
More file actions
65 lines (54 loc) · 1.86 KB
/
ctextselect.cpp
File metadata and controls
65 lines (54 loc) · 1.86 KB
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
#include "textselect.hpp"
#include "ctextselect.h"
#include <string>
// 内部用ラッパー
struct TextSelectWrapper {
TextSelect impl;
void* userdata;
TextSelectWrapper(GetLineAtIdxFn getLineAtIdx, GetNumLinesFn getNumLines, void* userdata, bool enableWordWrap)
: impl(
[getLineAtIdx, userdata](size_t idx) -> std::string_view {
size_t len = 0;
const char* str = getLineAtIdx(idx, userdata, &len);
return std::string_view(str, len);
},
[getNumLines, userdata]() -> size_t {
return getNumLines(userdata);
},
enableWordWrap),
userdata(userdata)
{}
};
extern "C" {
TextSelect* textselect_create(GetLineAtIdxFn getLineAtIdx,
GetNumLinesFn getNumLines,
void* userdata,
int enableWordWrap) {
return reinterpret_cast<TextSelect*>(
new TextSelectWrapper(getLineAtIdx, getNumLines, userdata, enableWordWrap)
);
}
void textselect_destroy(TextSelect* ts) {
delete reinterpret_cast<TextSelectWrapper*>(ts);
}
int textselect_has_selection(const TextSelect* ts) {
auto* self = reinterpret_cast<const TextSelectWrapper*>(ts);
return self->impl.hasSelection() ? 1 : 0;
}
void textselect_copy(const TextSelect* ts) {
auto* self = reinterpret_cast<const TextSelectWrapper*>(ts);
self->impl.copy();
}
void textselect_select_all(TextSelect* ts) {
auto* self = reinterpret_cast<TextSelectWrapper*>(ts);
self->impl.selectAll();
}
void textselect_update(TextSelect* ts) {
auto* self = reinterpret_cast<TextSelectWrapper*>(ts);
self->impl.update();
}
void textselect_clear_selection(TextSelect* ts) {
auto* self = reinterpret_cast<TextSelectWrapper*>(ts);
self->impl.clearSelection();
}
} // extern "C"