xbintsc 0.6.10 → 0.6.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/ast/expressions.d.ts +6 -0
- package/dist/src/checker/globals.js +2 -1
- package/dist/src/checker/globals.js.map +1 -1
- package/dist/src/checker/type-infer.js +1 -1
- package/dist/src/checker/type-infer.js.map +1 -1
- package/dist/src/cli/help.d.ts +1 -1
- package/dist/src/codegen/generator/calls/literals.js +4 -1
- package/dist/src/codegen/generator/calls/literals.js.map +1 -1
- package/dist/src/codegen/generator/expressions/assignment.js +3 -1
- package/dist/src/codegen/generator/expressions/assignment.js.map +1 -1
- package/dist/src/codegen/generator/expressions/operators.js +2 -6
- package/dist/src/codegen/generator/expressions/operators.js.map +1 -1
- package/dist/src/codegen/generator/expressions/primary.d.ts +9 -0
- package/dist/src/codegen/generator/expressions/primary.js +44 -7
- package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
- package/dist/src/codegen/generator/state.js +3 -0
- package/dist/src/codegen/generator/state.js.map +1 -1
- package/dist/src/codegen/generator/tables.js +3 -0
- package/dist/src/codegen/generator/tables.js.map +1 -1
- package/dist/src/driver/bundler/commonjs.js +1 -1
- package/dist/src/driver/bundler/commonjs.js.map +1 -1
- package/dist/src/driver/bundler/symbols.js +6 -0
- package/dist/src/driver/bundler/symbols.js.map +1 -1
- package/dist/src/driver/compiler.js +1 -1
- package/dist/src/driver/compiler.js.map +1 -1
- package/dist/src/driver/runtime-objects.d.ts +1 -1
- package/dist/src/driver/runtime-objects.js +2 -0
- package/dist/src/driver/runtime-objects.js.map +1 -1
- package/dist/src/driver/version.d.ts +1 -1
- package/dist/src/driver/version.js +1 -1
- package/dist/src/extensions/node/crypto/index.js +12 -1
- package/dist/src/extensions/node/crypto/index.js.map +1 -1
- package/dist/src/extensions/node/index.js +2 -0
- package/dist/src/extensions/node/index.js.map +1 -1
- package/dist/src/extensions/node/readline/index.d.ts +12 -0
- package/dist/src/extensions/node/readline/index.js +27 -0
- package/dist/src/extensions/node/readline/index.js.map +1 -0
- package/dist/src/parser/declarations/functions.js +6 -0
- package/dist/src/parser/declarations/functions.js.map +1 -1
- package/dist/src/parser/literals.js +1 -1
- package/dist/src/parser/literals.js.map +1 -1
- package/dist/tests/e2e/compile-builtins.test.js +26 -0
- package/dist/tests/e2e/compile-builtins.test.js.map +1 -1
- package/dist/tests/e2e/compile-modules.test.js +22 -0
- package/dist/tests/e2e/compile-modules.test.js.map +1 -1
- package/dist/tests/e2e/compile-node.test.js +37 -1
- package/dist/tests/e2e/compile-node.test.js.map +1 -1
- package/dist/tests/e2e/crypto-random.test.d.ts +9 -0
- package/dist/tests/e2e/crypto-random.test.js +63 -0
- package/dist/tests/e2e/crypto-random.test.js.map +1 -0
- package/dist/tests/e2e/date-parse.test.js +44 -1
- package/dist/tests/e2e/date-parse.test.js.map +1 -1
- package/dist/tests/e2e/gui-browser.test.js +61 -0
- package/dist/tests/e2e/gui-browser.test.js.map +1 -1
- package/dist/tests/e2e/gui-css-coverage.test.js +40 -1
- package/dist/tests/e2e/gui-css-coverage.test.js.map +1 -1
- package/dist/tests/e2e/gui-css-features.test.js +100 -0
- package/dist/tests/e2e/gui-css-features.test.js.map +1 -1
- package/dist/tests/e2e/gui-dom.test.js +63 -0
- package/dist/tests/e2e/gui-dom.test.js.map +1 -1
- package/dist/tests/e2e/gui-errors.test.d.ts +11 -0
- package/dist/tests/e2e/gui-errors.test.js +68 -0
- package/dist/tests/e2e/gui-errors.test.js.map +1 -0
- package/dist/tests/e2e/gui-form.test.d.ts +9 -0
- package/dist/tests/e2e/gui-form.test.js +359 -0
- package/dist/tests/e2e/gui-form.test.js.map +1 -0
- package/dist/tests/e2e/gui-script-import-order.test.js +6 -1
- package/dist/tests/e2e/gui-script-import-order.test.js.map +1 -1
- package/dist/tests/e2e/gui-style.test.js +82 -0
- package/dist/tests/e2e/gui-style.test.js.map +1 -1
- package/dist/tests/e2e/gui-unsupported.test.js +4 -3
- package/dist/tests/e2e/gui-unsupported.test.js.map +1 -1
- package/dist/tests/e2e/gui-webgl2-shadow-sampler.test.js +7 -1
- package/dist/tests/e2e/gui-webgl2-shadow-sampler.test.js.map +1 -1
- package/dist/tests/e2e/harness.d.ts +4 -0
- package/dist/tests/e2e/harness.js +2 -0
- package/dist/tests/e2e/harness.js.map +1 -1
- package/dist/tests/e2e/json-parse-errors.test.d.ts +9 -0
- package/dist/tests/e2e/json-parse-errors.test.js +48 -0
- package/dist/tests/e2e/json-parse-errors.test.js.map +1 -0
- package/dist/tests/e2e/readline.test.d.ts +7 -0
- package/dist/tests/e2e/readline.test.js +73 -0
- package/dist/tests/e2e/readline.test.js.map +1 -0
- package/doc/ai/language-support.md +2 -1
- package/doc/ai/zh-CN/language-support.md +2 -1
- package/doc/gui/api.md +24 -3
- package/doc/gui/dom.md +28 -14
- package/doc/gui/input.md +74 -3
- package/doc/gui/known-issues.md +2 -1
- package/doc/gui/layout.md +5 -1
- package/doc/implemented/node/crypto.md +8 -0
- package/doc/implemented/node/fs.md +1 -1
- package/doc/implemented/node/readline.md +34 -0
- package/doc/implemented/node.md +1 -0
- package/doc/implemented/stdlib.md +10 -2
- package/doc/unimplemented/node/modules.md +2 -3
- package/doc/unimplemented/node.md +2 -2
- package/doc/zh-CN/gui/api.md +20 -3
- package/doc/zh-CN/gui/dom.md +23 -13
- package/doc/zh-CN/gui/input.md +65 -4
- package/doc/zh-CN/gui/known-issues.md +2 -1
- package/doc/zh-CN/gui/layout.md +4 -1
- package/doc/zh-CN/implemented/node/crypto.md +6 -0
- package/doc/zh-CN/implemented/node/fs.md +1 -1
- package/doc/zh-CN/implemented/node/readline.md +33 -0
- package/doc/zh-CN/implemented/node.md +1 -0
- package/doc/zh-CN/implemented/stdlib.md +10 -2
- package/doc/zh-CN/unimplemented/node/modules.md +1 -2
- package/doc/zh-CN/unimplemented/node.md +2 -2
- package/package.json +7 -7
- package/runtime/ext_gui/browser_abort.cpp +2 -2
- package/runtime/ext_gui/browser_loop.cpp +1 -0
- package/runtime/ext_gui/browser_media.cpp +1 -1
- package/runtime/ext_gui/css_match.cpp +21 -1
- package/runtime/ext_gui/css_selector.cpp +2 -2
- package/runtime/ext_gui/document.cpp +12 -0
- package/runtime/ext_gui/dom.h +41 -2
- package/runtime/ext_gui/dom_api_canvas_image.cpp +2 -1
- package/runtime/ext_gui/dom_api_document.cpp +28 -0
- package/runtime/ext_gui/dom_api_events.cpp +18 -15
- package/runtime/ext_gui/dom_api_form.cpp +567 -0
- package/runtime/ext_gui/dom_api_internal.h +48 -214
- package/runtime/ext_gui/dom_api_mutation.cpp +1 -1
- package/runtime/ext_gui/dom_api_node.cpp +28 -15
- package/runtime/ext_gui/dom_api_node_read.cpp +28 -1
- package/runtime/ext_gui/dom_api_proto.cpp +47 -0
- package/runtime/ext_gui/dom_api_webgl_methods.h +217 -0
- package/runtime/ext_gui/dom_parse.cpp +114 -1
- package/runtime/ext_gui/error_report.cpp +166 -0
- package/runtime/ext_gui/form_focus.cpp +293 -0
- package/runtime/ext_gui/form_input.cpp +448 -0
- package/runtime/ext_gui/form_internal.h +30 -0
- package/runtime/ext_gui/form_shared.cpp +126 -0
- package/runtime/ext_gui/form_state.cpp +536 -0
- package/runtime/ext_gui/form_state.h +97 -0
- package/runtime/ext_gui/gui.cpp +16 -0
- package/runtime/ext_gui/gui_engine.h +53 -4
- package/runtime/ext_gui/gui_events.cpp +67 -49
- package/runtime/ext_gui/layout.cpp +6 -0
- package/runtime/ext_gui/layout.h +4 -0
- package/runtime/ext_gui/layout_flow.cpp +23 -1
- package/runtime/ext_gui/layout_inline.cpp +46 -14
- package/runtime/ext_gui/paint.cpp +26 -1
- package/runtime/ext_gui/paint_form.cpp +389 -0
- package/runtime/ext_gui/paint_internal.h +6 -0
- package/runtime/ext_gui/script.cpp +1 -1
- package/runtime/ext_gui/style.cpp +1 -0
- package/runtime/ext_gui/style.h +13 -0
- package/runtime/ext_gui/style_print.cpp +129 -0
- package/runtime/ext_gui/style_text.cpp +79 -0
- package/runtime/ext_gui/style_ua.cpp +42 -0
- package/runtime/ext_gui/warnings.cpp +5 -7
- package/runtime/ext_gui/webgl_texture.cpp +0 -8
- package/runtime/ext_gui/window.cpp +52 -62
- package/runtime/ext_gui/window_diagnostics.cpp +58 -0
- package/runtime/ext_gui/window_emit.cpp +51 -0
- package/runtime/ext_node/crypto/crypto.c +3 -2
- package/runtime/ext_node/crypto/crypto_hash.h +13 -0
- package/runtime/ext_node/crypto/crypto_random.c +339 -0
- package/runtime/ext_node/fs/async_worker.c +1 -1
- package/runtime/ext_node/fs/fs_ops.c +1 -1
- package/runtime/ext_node/fs/parts/platform.inc +67 -0
- package/runtime/ext_node/readline/readline.c +572 -0
- package/runtime/rt.h +42 -0
- package/runtime/rt_internal.h +3 -2
- package/runtime/xt_crypto.c +132 -0
- package/runtime/xt_io/exception.inc +29 -6
- package/runtime/xt_loop.c +36 -1
- package/runtime/xt_promise.c +26 -2
- package/runtime/xt_random.c +143 -0
- package/runtime/xt_regex/matcher.inc +9 -28
- package/runtime/xt_regex/parser.inc +65 -2
- package/runtime/xt_regex/types.inc +11 -1
- package/runtime/xt_regex.h +6 -2
- package/runtime/xt_stdlib/dispatch.inc +2 -0
- package/runtime/xt_stdlib/math.inc +1 -1
- package/runtime/xt_stdlib2/date.inc +206 -6
- package/runtime/xt_stdlib2/json.inc +4 -546
- package/runtime/xt_stdlib2/json_parse.inc +347 -0
- package/runtime/xt_stdlib2/json_stringify.inc +368 -0
- package/runtime/xt_stdlib2/regexp-match.inc +6 -11
- package/runtime/xt_stdlib2.c +0 -4
- package/runtime/xt_typed_array/elements.inc +2 -6
- package/runtime/xt_url.c +0 -6
- package/runtime/xt_url_object.c +1 -1
- package/src/ast/expressions.ts +6 -0
- package/src/checker/globals.ts +2 -0
- package/src/checker/type-infer.ts +1 -1
- package/src/codegen/generator/calls/literals.ts +4 -1
- package/src/codegen/generator/expressions/assignment.ts +3 -1
- package/src/codegen/generator/expressions/operators.ts +2 -6
- package/src/codegen/generator/expressions/primary.ts +58 -6
- package/src/codegen/generator/state.ts +3 -0
- package/src/codegen/generator/tables.ts +3 -0
- package/src/driver/bundler/commonjs.ts +1 -1
- package/src/driver/bundler/symbols.ts +6 -0
- package/src/driver/compiler.ts +1 -1
- package/src/driver/runtime-objects.ts +2 -0
- package/src/driver/version.ts +1 -1
- package/src/extensions/node/crypto/index.ts +12 -1
- package/src/extensions/node/index.ts +2 -0
- package/src/extensions/node/readline/index.ts +31 -0
- package/src/parser/declarations/functions.ts +6 -0
- package/src/parser/literals.ts +1 -1
|
@@ -0,0 +1,567 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc GUI engine — form-control DOM bindings.
|
|
3
|
+
*
|
|
4
|
+
* Exposes the live value state (`value`, `checked`, selection range, `type`,
|
|
5
|
+
* `disabled`, `placeholder`, ...) of `<input>`/`<textarea>`/`<select>` and the
|
|
6
|
+
* small set of methods a form script uses (`setSelectionRange`, `select`).
|
|
7
|
+
* Text editing itself lives in `form_input.cpp`; painting in `paint_form.cpp`.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#include "dom_api_internal.h"
|
|
11
|
+
|
|
12
|
+
#include "form_state.h"
|
|
13
|
+
|
|
14
|
+
#include <cstdio>
|
|
15
|
+
#include <cstdlib>
|
|
16
|
+
#include <string>
|
|
17
|
+
#include <vector>
|
|
18
|
+
|
|
19
|
+
namespace domapi {
|
|
20
|
+
|
|
21
|
+
static void form_dirty(XtGuiWindow *win) {
|
|
22
|
+
if (win == nullptr) return;
|
|
23
|
+
win->geometry.dirty = 1;
|
|
24
|
+
win->present_dirty = 1;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static bool is_form_element(const xtgui::Node *node) {
|
|
28
|
+
if (node == nullptr || !node->isElement()) return false;
|
|
29
|
+
return xtgui::xt_form_is_control(node) || node->tag == "button" || node->tag == "option" ||
|
|
30
|
+
node->tag == "optgroup" || node->tag == "fieldset" || node->tag == "label" ||
|
|
31
|
+
node->tag == "form";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static bool text_control(const xtgui::Node *node) {
|
|
35
|
+
return node != nullptr && xtgui::xt_form_is_text_like(node);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static int clamp_selection(const xtgui::Node *node, int value) {
|
|
39
|
+
const xtgui::FormState *state = xtgui::xt_form_state(node);
|
|
40
|
+
std::string text = state != nullptr ? state->value : "";
|
|
41
|
+
int length = (int)xtgui::xt_form_utf16_length(text);
|
|
42
|
+
if (value < 0) return 0;
|
|
43
|
+
if (value > length) return length;
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static void set_selection(xtgui::Node *node, int start, int end, int direction) {
|
|
48
|
+
if (!text_control(node)) return;
|
|
49
|
+
int length = (int)xtgui::xt_form_utf16_length(xtgui::xt_form_value(node));
|
|
50
|
+
if (start < 0) start = 0;
|
|
51
|
+
if (end < 0) end = 0;
|
|
52
|
+
if (start > length) start = length;
|
|
53
|
+
if (end > length) end = length;
|
|
54
|
+
if (start > end) {
|
|
55
|
+
int swap = start;
|
|
56
|
+
start = end;
|
|
57
|
+
end = swap;
|
|
58
|
+
if (direction == 1) direction = -1;
|
|
59
|
+
}
|
|
60
|
+
if (direction == 0) direction = start < end ? 1 : 0;
|
|
61
|
+
xtgui::FormState *state = xtgui::xt_form_state(node);
|
|
62
|
+
if (state == nullptr) return;
|
|
63
|
+
state->selection_start = start;
|
|
64
|
+
state->selection_end = end;
|
|
65
|
+
state->selection_direction = direction;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
#define METHOD(name) xt_value name(xt_value self, xt_value env, int32_t argc, xt_value *argv)
|
|
69
|
+
|
|
70
|
+
METHOD(node_value_get) {
|
|
71
|
+
(void)env;
|
|
72
|
+
(void)argc;
|
|
73
|
+
(void)argv;
|
|
74
|
+
xtgui::Node *node = resolve_node(self, nullptr);
|
|
75
|
+
if (node == nullptr) return XT_UNDEFINED;
|
|
76
|
+
if (xtgui::xt_form_is_control(node)) {
|
|
77
|
+
return xt_string_from_cstr(xtgui::xt_form_value(node).c_str());
|
|
78
|
+
}
|
|
79
|
+
if (node->isElement() && node->tag == "option") {
|
|
80
|
+
return xt_string_from_cstr(xtgui::xt_form_option_value(node).c_str());
|
|
81
|
+
}
|
|
82
|
+
if (node->isElement() && node->tag == "button") {
|
|
83
|
+
const std::string *value = node->attr("value");
|
|
84
|
+
return xt_string_from_cstr(value != nullptr ? value->c_str() : "");
|
|
85
|
+
}
|
|
86
|
+
return XT_UNDEFINED;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
METHOD(node_value_set) {
|
|
90
|
+
(void)env;
|
|
91
|
+
XtGuiWindow *win = nullptr;
|
|
92
|
+
xtgui::Node *node = resolve_node(self, &win);
|
|
93
|
+
if (node == nullptr) return XT_UNDEFINED;
|
|
94
|
+
std::string value = argc >= 1 ? to_string_value(xt_arg(argc, argv, 0)) : "";
|
|
95
|
+
if (xtgui::xt_form_is_control(node)) {
|
|
96
|
+
xtgui::xt_form_set_value(node, value);
|
|
97
|
+
form_dirty(win);
|
|
98
|
+
} else if (node->isElement() && node->tag == "option") {
|
|
99
|
+
set_attribute(win, node, "value", value);
|
|
100
|
+
} else if (node->isElement() && node->tag == "button") {
|
|
101
|
+
set_attribute(win, node, "value", value);
|
|
102
|
+
}
|
|
103
|
+
return XT_UNDEFINED;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
METHOD(node_default_value_get) {
|
|
107
|
+
(void)env;
|
|
108
|
+
(void)argc;
|
|
109
|
+
(void)argv;
|
|
110
|
+
xtgui::Node *node = resolve_node(self, nullptr);
|
|
111
|
+
if (node == nullptr) return XT_UNDEFINED;
|
|
112
|
+
if (xtgui::xt_form_is_textarea(node)) {
|
|
113
|
+
std::string text;
|
|
114
|
+
for (const std::unique_ptr<xtgui::Node> &child : node->children) {
|
|
115
|
+
if (child->isText()) text += child->text;
|
|
116
|
+
}
|
|
117
|
+
return xt_string_from_cstr(text.c_str());
|
|
118
|
+
}
|
|
119
|
+
if (xtgui::xt_form_is_control(node) || node->tag == "option") {
|
|
120
|
+
const std::string *value = node->attr("value");
|
|
121
|
+
return xt_string_from_cstr(value != nullptr ? value->c_str() : "");
|
|
122
|
+
}
|
|
123
|
+
return XT_UNDEFINED;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
METHOD(node_checked_get) {
|
|
127
|
+
(void)env;
|
|
128
|
+
(void)argc;
|
|
129
|
+
(void)argv;
|
|
130
|
+
xtgui::Node *node = resolve_node(self, nullptr);
|
|
131
|
+
if (node == nullptr) return XT_FALSE;
|
|
132
|
+
return xtgui::xt_form_checked(node) ? XT_TRUE : XT_FALSE;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
METHOD(node_checked_set) {
|
|
136
|
+
(void)env;
|
|
137
|
+
XtGuiWindow *win = nullptr;
|
|
138
|
+
xtgui::Node *node = resolve_node(self, &win);
|
|
139
|
+
if (node == nullptr || !xtgui::xt_form_is_checkable(node)) return XT_UNDEFINED;
|
|
140
|
+
xtgui::xt_form_set_checked(node, argc >= 1 ? value_truthy(xt_arg(argc, argv, 0)) : false);
|
|
141
|
+
mark_dirty(win);
|
|
142
|
+
form_dirty(win);
|
|
143
|
+
return XT_UNDEFINED;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
METHOD(node_type_get) {
|
|
147
|
+
(void)env;
|
|
148
|
+
(void)argc;
|
|
149
|
+
(void)argv;
|
|
150
|
+
xtgui::Node *node = resolve_node(self, nullptr);
|
|
151
|
+
if (node == nullptr || !node->isElement()) return XT_UNDEFINED;
|
|
152
|
+
std::string type = xtgui::xt_form_type(node);
|
|
153
|
+
return xt_string_from_cstr(type.c_str());
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
METHOD(node_type_set) {
|
|
157
|
+
(void)env;
|
|
158
|
+
XtGuiWindow *win = nullptr;
|
|
159
|
+
xtgui::Node *node = resolve_node(self, &win);
|
|
160
|
+
if (node == nullptr || !node->isElement()) return XT_UNDEFINED;
|
|
161
|
+
if (!xtgui::xt_form_is_input(node) && node->tag != "button" && node->tag != "select" &&
|
|
162
|
+
node->tag != "textarea") {
|
|
163
|
+
return XT_UNDEFINED;
|
|
164
|
+
}
|
|
165
|
+
set_attribute(win, node, "type", argc >= 1 ? to_string_value(xt_arg(argc, argv, 0)) : "text");
|
|
166
|
+
if (node->form) node->form->initialized = false;
|
|
167
|
+
if (xtgui::xt_form_is_control(node)) {
|
|
168
|
+
xtgui::xt_form_init(node);
|
|
169
|
+
form_dirty(win);
|
|
170
|
+
}
|
|
171
|
+
return XT_UNDEFINED;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
METHOD(node_name_get) {
|
|
175
|
+
(void)env;
|
|
176
|
+
(void)argc;
|
|
177
|
+
(void)argv;
|
|
178
|
+
xtgui::Node *node = resolve_node(self, nullptr);
|
|
179
|
+
if (node == nullptr || !node->isElement()) return XT_UNDEFINED;
|
|
180
|
+
const std::string *value = node->attr("name");
|
|
181
|
+
return xt_string_from_cstr(value != nullptr ? value->c_str() : "");
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
METHOD(node_name_set) {
|
|
185
|
+
(void)env;
|
|
186
|
+
XtGuiWindow *win = nullptr;
|
|
187
|
+
xtgui::Node *node = resolve_node(self, &win);
|
|
188
|
+
if (node == nullptr || !node->isElement()) return XT_UNDEFINED;
|
|
189
|
+
set_attribute(win, node, "name", argc >= 1 ? to_string_value(xt_arg(argc, argv, 0)) : "");
|
|
190
|
+
return XT_UNDEFINED;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
METHOD(node_disabled_get) {
|
|
194
|
+
(void)env;
|
|
195
|
+
(void)argc;
|
|
196
|
+
(void)argv;
|
|
197
|
+
xtgui::Node *node = resolve_node(self, nullptr);
|
|
198
|
+
if (node == nullptr || !is_form_element(node)) return XT_UNDEFINED;
|
|
199
|
+
return xtgui::xt_form_is_disabled(node) ? XT_TRUE : XT_FALSE;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
METHOD(node_disabled_set) {
|
|
203
|
+
(void)env;
|
|
204
|
+
XtGuiWindow *win = nullptr;
|
|
205
|
+
xtgui::Node *node = resolve_node(self, &win);
|
|
206
|
+
if (node == nullptr || !is_form_element(node)) return XT_UNDEFINED;
|
|
207
|
+
if (argc >= 1 && value_truthy(xt_arg(argc, argv, 0))) {
|
|
208
|
+
set_attribute(win, node, "disabled", "");
|
|
209
|
+
} else {
|
|
210
|
+
remove_attribute_raw(node, "disabled");
|
|
211
|
+
mark_dirty(win);
|
|
212
|
+
}
|
|
213
|
+
form_dirty(win);
|
|
214
|
+
return XT_UNDEFINED;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
METHOD(node_read_only_get) {
|
|
218
|
+
(void)env;
|
|
219
|
+
(void)argc;
|
|
220
|
+
(void)argv;
|
|
221
|
+
xtgui::Node *node = resolve_node(self, nullptr);
|
|
222
|
+
if (node == nullptr || !xtgui::xt_form_is_control(node)) return XT_UNDEFINED;
|
|
223
|
+
return xtgui::xt_form_is_readonly(node) ? XT_TRUE : XT_FALSE;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
METHOD(node_read_only_set) {
|
|
227
|
+
(void)env;
|
|
228
|
+
XtGuiWindow *win = nullptr;
|
|
229
|
+
xtgui::Node *node = resolve_node(self, &win);
|
|
230
|
+
if (node == nullptr || !xtgui::xt_form_is_control(node)) return XT_UNDEFINED;
|
|
231
|
+
if (argc >= 1 && value_truthy(xt_arg(argc, argv, 0))) {
|
|
232
|
+
set_attribute(win, node, "readonly", "");
|
|
233
|
+
} else {
|
|
234
|
+
remove_attribute_raw(node, "readonly");
|
|
235
|
+
mark_dirty(win);
|
|
236
|
+
}
|
|
237
|
+
return XT_UNDEFINED;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
METHOD(node_required_get) {
|
|
241
|
+
(void)env;
|
|
242
|
+
(void)argc;
|
|
243
|
+
(void)argv;
|
|
244
|
+
xtgui::Node *node = resolve_node(self, nullptr);
|
|
245
|
+
if (node == nullptr || !xtgui::xt_form_is_control(node)) return XT_FALSE;
|
|
246
|
+
return node->attr("required") != nullptr ? XT_TRUE : XT_FALSE;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
METHOD(node_required_set) {
|
|
250
|
+
(void)env;
|
|
251
|
+
XtGuiWindow *win = nullptr;
|
|
252
|
+
xtgui::Node *node = resolve_node(self, &win);
|
|
253
|
+
if (node == nullptr || !xtgui::xt_form_is_control(node)) return XT_UNDEFINED;
|
|
254
|
+
if (argc >= 1 && value_truthy(xt_arg(argc, argv, 0))) {
|
|
255
|
+
set_attribute(win, node, "required", "");
|
|
256
|
+
} else {
|
|
257
|
+
remove_attribute_raw(node, "required");
|
|
258
|
+
mark_dirty(win);
|
|
259
|
+
}
|
|
260
|
+
return XT_UNDEFINED;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
METHOD(node_placeholder_get) {
|
|
264
|
+
(void)env;
|
|
265
|
+
(void)argc;
|
|
266
|
+
(void)argv;
|
|
267
|
+
xtgui::Node *node = resolve_node(self, nullptr);
|
|
268
|
+
if (node == nullptr || !xtgui::xt_form_is_control(node)) return XT_UNDEFINED;
|
|
269
|
+
const std::string *value = node->attr("placeholder");
|
|
270
|
+
return xt_string_from_cstr(value != nullptr ? value->c_str() : "");
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
METHOD(node_placeholder_set) {
|
|
274
|
+
(void)env;
|
|
275
|
+
XtGuiWindow *win = nullptr;
|
|
276
|
+
xtgui::Node *node = resolve_node(self, &win);
|
|
277
|
+
if (node == nullptr || !xtgui::xt_form_is_control(node)) return XT_UNDEFINED;
|
|
278
|
+
std::string value = argc >= 1 ? to_string_value(xt_arg(argc, argv, 0)) : "";
|
|
279
|
+
if (value.empty()) {
|
|
280
|
+
remove_attribute_raw(node, "placeholder");
|
|
281
|
+
mark_dirty(win);
|
|
282
|
+
} else {
|
|
283
|
+
set_attribute(win, node, "placeholder", value);
|
|
284
|
+
}
|
|
285
|
+
form_dirty(win);
|
|
286
|
+
return XT_UNDEFINED;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
METHOD(node_selection_start_get) {
|
|
290
|
+
(void)env;
|
|
291
|
+
(void)argc;
|
|
292
|
+
(void)argv;
|
|
293
|
+
xtgui::Node *node = resolve_node(self, nullptr);
|
|
294
|
+
if (!text_control(node)) return XT_UNDEFINED;
|
|
295
|
+
const xtgui::FormState *state = xtgui::xt_form_state(node);
|
|
296
|
+
return xt_number(state != nullptr ? state->selection_start : 0);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
METHOD(node_selection_start_set) {
|
|
300
|
+
(void)env;
|
|
301
|
+
XtGuiWindow *win = nullptr;
|
|
302
|
+
xtgui::Node *node = resolve_node(self, &win);
|
|
303
|
+
if (!text_control(node)) return XT_UNDEFINED;
|
|
304
|
+
const xtgui::FormState *state = xtgui::xt_form_state(node);
|
|
305
|
+
int end = state != nullptr ? state->selection_end : 0;
|
|
306
|
+
int start = clamp_selection(node, argc >= 1 ? (int)xt_to_number(xt_arg(argc, argv, 0)) : 0);
|
|
307
|
+
set_selection(node, start, end > start ? end : start, 1);
|
|
308
|
+
form_dirty(win);
|
|
309
|
+
return XT_UNDEFINED;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
METHOD(node_selection_end_get) {
|
|
313
|
+
(void)env;
|
|
314
|
+
(void)argc;
|
|
315
|
+
(void)argv;
|
|
316
|
+
xtgui::Node *node = resolve_node(self, nullptr);
|
|
317
|
+
if (!text_control(node)) return XT_UNDEFINED;
|
|
318
|
+
const xtgui::FormState *state = xtgui::xt_form_state(node);
|
|
319
|
+
return xt_number(state != nullptr ? state->selection_end : 0);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
METHOD(node_selection_end_set) {
|
|
323
|
+
(void)env;
|
|
324
|
+
XtGuiWindow *win = nullptr;
|
|
325
|
+
xtgui::Node *node = resolve_node(self, &win);
|
|
326
|
+
if (!text_control(node)) return XT_UNDEFINED;
|
|
327
|
+
const xtgui::FormState *state = xtgui::xt_form_state(node);
|
|
328
|
+
int start = state != nullptr ? state->selection_start : 0;
|
|
329
|
+
int end = clamp_selection(node, argc >= 1 ? (int)xt_to_number(xt_arg(argc, argv, 0)) : 0);
|
|
330
|
+
set_selection(node, start < end ? start : end, end, 1);
|
|
331
|
+
form_dirty(win);
|
|
332
|
+
return XT_UNDEFINED;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
METHOD(node_selection_direction_get) {
|
|
336
|
+
(void)env;
|
|
337
|
+
(void)argc;
|
|
338
|
+
(void)argv;
|
|
339
|
+
xtgui::Node *node = resolve_node(self, nullptr);
|
|
340
|
+
if (!text_control(node)) return XT_UNDEFINED;
|
|
341
|
+
const xtgui::FormState *state = xtgui::xt_form_state(node);
|
|
342
|
+
int direction = state != nullptr ? state->selection_direction : 0;
|
|
343
|
+
return xt_string_from_cstr(direction > 0 ? "forward" : direction < 0 ? "backward" : "none");
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
METHOD(node_set_selection_range) {
|
|
347
|
+
(void)env;
|
|
348
|
+
XtGuiWindow *win = nullptr;
|
|
349
|
+
xtgui::Node *node = resolve_node(self, &win);
|
|
350
|
+
if (!text_control(node)) return XT_UNDEFINED;
|
|
351
|
+
int start = argc >= 1 ? (int)xt_to_number(xt_arg(argc, argv, 0)) : 0;
|
|
352
|
+
int end = argc >= 2 ? (int)xt_to_number(xt_arg(argc, argv, 1)) : start;
|
|
353
|
+
std::string direction = argc >= 3 ? to_string_value(xt_arg(argc, argv, 2)) : "none";
|
|
354
|
+
int sign = direction == "forward" ? 1 : direction == "backward" ? -1 : 0;
|
|
355
|
+
set_selection(node, start, end, sign);
|
|
356
|
+
form_dirty(win);
|
|
357
|
+
return XT_UNDEFINED;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
METHOD(node_select) {
|
|
361
|
+
(void)env;
|
|
362
|
+
(void)argc;
|
|
363
|
+
(void)argv;
|
|
364
|
+
XtGuiWindow *win = nullptr;
|
|
365
|
+
xtgui::Node *node = resolve_node(self, &win);
|
|
366
|
+
if (!text_control(node)) return XT_UNDEFINED;
|
|
367
|
+
int length = (int)xtgui::xt_form_utf16_length(xtgui::xt_form_value(node));
|
|
368
|
+
set_selection(node, 0, length, 1);
|
|
369
|
+
xt_gui_set_focus(win, node);
|
|
370
|
+
form_dirty(win);
|
|
371
|
+
return XT_UNDEFINED;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
METHOD(node_form_get) {
|
|
375
|
+
(void)env;
|
|
376
|
+
(void)argc;
|
|
377
|
+
(void)argv;
|
|
378
|
+
XtGuiWindow *win = nullptr;
|
|
379
|
+
xtgui::Node *node = resolve_node(self, &win);
|
|
380
|
+
if (node == nullptr) return XT_UNDEFINED;
|
|
381
|
+
for (xtgui::Node *parent = node->parent; parent != nullptr; parent = parent->parent) {
|
|
382
|
+
if (parent->isElement() && parent->tag == "form") return xt_gui_node_handle(win, parent);
|
|
383
|
+
}
|
|
384
|
+
return XT_UNDEFINED;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
METHOD(node_options_get) {
|
|
388
|
+
(void)env;
|
|
389
|
+
(void)argc;
|
|
390
|
+
(void)argv;
|
|
391
|
+
XtGuiWindow *win = nullptr;
|
|
392
|
+
xtgui::Node *node = resolve_node(self, &win);
|
|
393
|
+
xt_value array = xt_array_new(0, NULL);
|
|
394
|
+
if (!xtgui::xt_form_is_select(node)) return array;
|
|
395
|
+
std::vector<const xtgui::Node *> options;
|
|
396
|
+
struct Collect {
|
|
397
|
+
std::vector<const xtgui::Node *> *out;
|
|
398
|
+
void visit(const xtgui::Node *current) const {
|
|
399
|
+
if (current->isElement() && current->isTag("option")) out->push_back(current);
|
|
400
|
+
for (const std::unique_ptr<xtgui::Node> &child : current->children) visit(child.get());
|
|
401
|
+
}
|
|
402
|
+
} collect = {&options};
|
|
403
|
+
collect.visit(node);
|
|
404
|
+
for (const xtgui::Node *option : options) xt_array_push(array, xt_gui_node_handle(win, option));
|
|
405
|
+
return array;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
METHOD(node_selected_index_get) {
|
|
409
|
+
(void)env;
|
|
410
|
+
(void)argc;
|
|
411
|
+
(void)argv;
|
|
412
|
+
xtgui::Node *node = resolve_node(self, nullptr);
|
|
413
|
+
if (!xtgui::xt_form_is_select(node)) return xt_number(-1);
|
|
414
|
+
const xtgui::FormState *state = xtgui::xt_form_state(node);
|
|
415
|
+
return xt_number(state != nullptr ? state->selected_index : -1);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
METHOD(node_selected_index_set) {
|
|
419
|
+
(void)env;
|
|
420
|
+
XtGuiWindow *win = nullptr;
|
|
421
|
+
xtgui::Node *node = resolve_node(self, &win);
|
|
422
|
+
if (!xtgui::xt_form_is_select(node)) return XT_UNDEFINED;
|
|
423
|
+
xtgui::FormState *state = xtgui::xt_form_state(node);
|
|
424
|
+
if (state == nullptr) return XT_UNDEFINED;
|
|
425
|
+
int index = argc >= 1 ? (int)xt_to_number(xt_arg(argc, argv, 0)) : -1;
|
|
426
|
+
std::vector<const xtgui::Node *> options;
|
|
427
|
+
struct Collect {
|
|
428
|
+
std::vector<const xtgui::Node *> *out;
|
|
429
|
+
void visit(const xtgui::Node *current) const {
|
|
430
|
+
if (current->isElement() && current->isTag("option")) out->push_back(current);
|
|
431
|
+
for (const std::unique_ptr<xtgui::Node> &child : current->children) visit(child.get());
|
|
432
|
+
}
|
|
433
|
+
} collect = {&options};
|
|
434
|
+
collect.visit(node);
|
|
435
|
+
if (index < 0 || (size_t)index >= options.size()) index = options.empty() ? -1 : 0;
|
|
436
|
+
state->selected_index = index;
|
|
437
|
+
if (index >= 0) state->value = xtgui::xt_form_option_value(options[(size_t)index]);
|
|
438
|
+
mark_dirty(win);
|
|
439
|
+
form_dirty(win);
|
|
440
|
+
return XT_UNDEFINED;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
static xt_value attrum_get(xt_value self, int32_t argc, xt_value *argv, const char *name,
|
|
444
|
+
xt_value fallback) {
|
|
445
|
+
(void)argc;
|
|
446
|
+
(void)argv;
|
|
447
|
+
xtgui::Node *node = resolve_node(self, nullptr);
|
|
448
|
+
if (node == nullptr || !node->isElement()) return fallback;
|
|
449
|
+
const std::string *value = node->attr(name);
|
|
450
|
+
return xt_string_from_cstr(value != nullptr ? value->c_str() : "");
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
static xt_value attrum_set(xt_value self, int32_t argc, xt_value *argv, const char *name,
|
|
454
|
+
bool numeric) {
|
|
455
|
+
XtGuiWindow *win = nullptr;
|
|
456
|
+
xtgui::Node *node = resolve_node(self, &win);
|
|
457
|
+
if (node == nullptr || !node->isElement()) return XT_UNDEFINED;
|
|
458
|
+
if (numeric && argc >= 1 && xt_to_number(xt_arg(argc, argv, 0)) < 0) {
|
|
459
|
+
remove_attribute_raw(node, name);
|
|
460
|
+
mark_dirty(win);
|
|
461
|
+
return XT_UNDEFINED;
|
|
462
|
+
}
|
|
463
|
+
set_attribute(win, node, name, argc >= 1 ? to_string_value(xt_arg(argc, argv, 0)) : "");
|
|
464
|
+
return XT_UNDEFINED;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
METHOD(node_max_length_get) {
|
|
468
|
+
(void)env;
|
|
469
|
+
xtgui::Node *node = resolve_node(self, nullptr);
|
|
470
|
+
if (node == nullptr || !node->isElement()) return xt_number(-1);
|
|
471
|
+
const std::string *value = node->attr("maxlength");
|
|
472
|
+
return xt_number(value != nullptr ? std::strtod(value->c_str(), nullptr) : -1);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
METHOD(node_max_length_set) {
|
|
476
|
+
(void)env;
|
|
477
|
+
return attrum_set(self, argc, argv, "maxlength", true);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
METHOD(node_min_get) {
|
|
481
|
+
(void)env;
|
|
482
|
+
return attrum_get(self, argc, argv, "min", xt_string_from_cstr(""));
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
METHOD(node_min_set) {
|
|
486
|
+
(void)env;
|
|
487
|
+
return attrum_set(self, argc, argv, "min", false);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
METHOD(node_max_get) {
|
|
491
|
+
(void)env;
|
|
492
|
+
return attrum_get(self, argc, argv, "max", xt_string_from_cstr(""));
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
METHOD(node_max_set) {
|
|
496
|
+
(void)env;
|
|
497
|
+
return attrum_set(self, argc, argv, "max", false);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
METHOD(node_step_get) {
|
|
501
|
+
(void)env;
|
|
502
|
+
return attrum_get(self, argc, argv, "step", xt_string_from_cstr(""));
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
METHOD(node_step_set) {
|
|
506
|
+
(void)env;
|
|
507
|
+
return attrum_set(self, argc, argv, "step", false);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
METHOD(node_tab_index_get) {
|
|
511
|
+
(void)env;
|
|
512
|
+
(void)argc;
|
|
513
|
+
(void)argv;
|
|
514
|
+
xtgui::Node *node = resolve_node(self, nullptr);
|
|
515
|
+
if (node == nullptr || !node->isElement()) return xt_number(-1);
|
|
516
|
+
const std::string *value = node->attr("tabindex");
|
|
517
|
+
if (value != nullptr) return xt_number(std::strtod(value->c_str(), nullptr));
|
|
518
|
+
return xtgui::xt_form_is_focusable(node) ? xt_number(0) : xt_number(-1);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
METHOD(node_tab_index_set) {
|
|
522
|
+
(void)env;
|
|
523
|
+
XtGuiWindow *win = nullptr;
|
|
524
|
+
xtgui::Node *node = resolve_node(self, &win);
|
|
525
|
+
if (node == nullptr || !node->isElement()) return XT_UNDEFINED;
|
|
526
|
+
int value = argc >= 1 ? (int)xt_to_number(xt_arg(argc, argv, 0)) : -1;
|
|
527
|
+
char text[16];
|
|
528
|
+
std::snprintf(text, sizeof(text), "%d", value);
|
|
529
|
+
set_attribute(win, node, "tabindex", text);
|
|
530
|
+
return XT_UNDEFINED;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
METHOD(node_form_submit) {
|
|
534
|
+
(void)env;
|
|
535
|
+
(void)argc;
|
|
536
|
+
(void)argv;
|
|
537
|
+
XtGuiWindow *win = nullptr;
|
|
538
|
+
xtgui::Node *node = resolve_node(self, &win);
|
|
539
|
+
if (node == nullptr || !node->isElement() || node->tag != "form") return XT_UNDEFINED;
|
|
540
|
+
xt_gui_form_submit_request(win, node, nullptr);
|
|
541
|
+
return XT_UNDEFINED;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
METHOD(node_form_request_submit) {
|
|
545
|
+
(void)env;
|
|
546
|
+
XtGuiWindow *win = nullptr;
|
|
547
|
+
xtgui::Node *node = resolve_node(self, &win);
|
|
548
|
+
if (node == nullptr || !node->isElement() || node->tag != "form") return XT_UNDEFINED;
|
|
549
|
+
xtgui::Node *submitter = argc >= 1 ? resolve_node(xt_arg(argc, argv, 0), nullptr) : nullptr;
|
|
550
|
+
xt_gui_form_submit_request(win, node, submitter);
|
|
551
|
+
return XT_UNDEFINED;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
METHOD(node_form_reset) {
|
|
555
|
+
(void)env;
|
|
556
|
+
(void)argc;
|
|
557
|
+
(void)argv;
|
|
558
|
+
XtGuiWindow *win = nullptr;
|
|
559
|
+
xtgui::Node *node = resolve_node(self, &win);
|
|
560
|
+
if (node == nullptr || !node->isElement() || node->tag != "form") return XT_UNDEFINED;
|
|
561
|
+
xt_gui_form_reset(win, node);
|
|
562
|
+
return XT_UNDEFINED;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
#undef METHOD
|
|
566
|
+
|
|
567
|
+
} // namespace domapi
|