nomen-lang 0.7.0 → 0.8.0
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/core/System/Buffer.nm +32 -0
- package/core/System/ClassBuffer.nm +24 -0
- package/core/System/Controls/Alert.nm +326 -0
- package/core/System/Controls/App.nm +147 -0
- package/core/System/Controls/Button.nm +119 -1
- package/core/System/Controls/CheckBox.nm +24 -0
- package/core/System/Controls/ColorPicker.nm +307 -0
- package/core/System/Controls/ComboBox.nm +430 -0
- package/core/System/Controls/Container.nm +837 -9
- package/core/System/Controls/Control.nm +443 -0
- package/core/System/Controls/DatePicker.nm +288 -0
- package/core/System/Controls/Form.nm +70 -0
- package/core/System/Controls/GroupBox.nm +267 -0
- package/core/System/Controls/ImageView.nm +311 -0
- package/core/System/Controls/LevelIndicator.nm +305 -0
- package/core/System/Controls/ListView.nm +633 -0
- package/core/System/Controls/Menu.nm +428 -0
- package/core/System/Controls/NumberInput.nm +56 -0
- package/core/System/Controls/OtpInput.nm +50 -0
- package/core/System/Controls/OutlineView.nm +598 -0
- package/core/System/Controls/Pagination.nm +142 -0
- package/core/System/Controls/Popover.nm +296 -0
- package/core/System/Controls/Progress.nm +348 -0
- package/core/System/Controls/Radio.nm +292 -0
- package/core/System/Controls/Scrollable.nm +584 -0
- package/core/System/Controls/SearchField.nm +326 -0
- package/core/System/Controls/SecureField.nm +344 -0
- package/core/System/Controls/Segmented.nm +380 -0
- package/core/System/Controls/Select.nm +340 -0
- package/core/System/Controls/Separator.nm +198 -0
- package/core/System/Controls/Sheet.nm +329 -0
- package/core/System/Controls/Slider.nm +315 -0
- package/core/System/Controls/Spinner.nm +287 -0
- package/core/System/Controls/SplitView.nm +509 -0
- package/core/System/Controls/Stepper.nm +349 -0
- package/core/System/Controls/Switch.nm +259 -0
- package/core/System/Controls/Table.nm +833 -0
- package/core/System/Controls/Tabs.nm +500 -0
- package/core/System/Controls/Text.nm +108 -11
- package/core/System/Controls/TextBox.nm +112 -1
- package/core/System/Controls/TextView.nm +329 -0
- package/core/System/Controls/Toggle.nm +346 -0
- package/core/System/Controls/Toolbar.nm +501 -0
- package/core/System/Controls/Tooltip.nm +76 -0
- package/core/System/Controls/Window.nm +1549 -91
- package/core/System/List.nm +34 -0
- package/core/System/Map.nm +21 -4
- package/core/System/Set.nm +14 -0
- package/dist/index.mjs +3425 -710
- package/package.json +1 -1
|
@@ -0,0 +1,598 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A tree of expandable rows (NSOutlineView, cell-based)
|
|
3
|
+
*
|
|
4
|
+
* An OWNING STRUCT (STRUCT_PLAN_3 Phase R, tranche 4 — the shape menu): the
|
|
5
|
+
* single field is a platform handle, so the value is movable and its
|
|
6
|
+
* `#destroy` releases what they name. The constructor's `self` is the
|
|
7
|
+
* inline instance (the `.` accessor); methods keep the pointer form.
|
|
8
|
+
*
|
|
9
|
+
* The data-source bridge generalizes ListView's (see that file) from rows
|
|
10
|
+
* to a TREE: nodes live in a fixed-capacity C-global pool (text + parent
|
|
11
|
+
* index; children are found by scanning), and NSOutlineView's item protocol
|
|
12
|
+
* passes node handles as opaque `(id)(index + 1)` pointers (0 = the root).
|
|
13
|
+
* `add_item(text, parent)` appends and reloads; `set_expanded` opens a
|
|
14
|
+
* branch. One OutlineView per process (shared pool — the same trade ListView
|
|
15
|
+
* makes). Selection is POLLED (`selected_row`), like every value in the
|
|
16
|
+
* manual loop. The view is cell-based (plain-text rows, no view reuse).
|
|
17
|
+
* Named `OutlineView` with no stdlib collision (the ListView `List<T>`
|
|
18
|
+
* lesson). macOS-only (no iOS counterpart; see GUI_PLAN Tier 2 — the iOS
|
|
19
|
+
* blocks are TODO stubs).
|
|
20
|
+
**/
|
|
21
|
+
pub mv struct OutlineView : Control {
|
|
22
|
+
var uint64 handle = 0
|
|
23
|
+
var uint64 tree = 0
|
|
24
|
+
|
|
25
|
+
// File-scope helper: the node pool (shared — one OutlineView per process)
|
|
26
|
+
// and the data-source IMPs answering the item protocol.
|
|
27
|
+
pub func #init = (self, Window window) {
|
|
28
|
+
```
|
|
29
|
+
#arch: c
|
|
30
|
+
#platform: macos
|
|
31
|
+
#scope: file
|
|
32
|
+
#define NOMEN_TREE_MAX 256
|
|
33
|
+
static char *g_tree_text[NOMEN_TREE_MAX];
|
|
34
|
+
static long g_tree_parent[NOMEN_TREE_MAX]; // -1 = top level
|
|
35
|
+
static long g_tree_count = 0;
|
|
36
|
+
static id g_tree_delegate = 0;
|
|
37
|
+
|
|
38
|
+
// Append a NUL-terminated copy of `text` under `parent` (-1 = top
|
|
39
|
+
// level); returns the new node's index or -1 when the pool is full.
|
|
40
|
+
static long nomen_tree_append(const char *text, long parent) {
|
|
41
|
+
if (g_tree_count >= NOMEN_TREE_MAX) return -1;
|
|
42
|
+
if (parent < -1 || parent >= g_tree_count) return -1;
|
|
43
|
+
g_tree_text[g_tree_count] = strdup(text);
|
|
44
|
+
g_tree_parent[g_tree_count] = parent;
|
|
45
|
+
g_tree_count += 1;
|
|
46
|
+
return g_tree_count - 1;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// The index of the `n`-th child of `parent` (-1 = top level), or -1.
|
|
50
|
+
static long nomen_tree_child(long parent, long n) {
|
|
51
|
+
long seen = 0;
|
|
52
|
+
for (long i = 0; i < g_tree_count; i++) {
|
|
53
|
+
if (g_tree_parent[i] == parent) {
|
|
54
|
+
if (seen == n) return i;
|
|
55
|
+
seen += 1;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return -1;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static long nomen_tree_children_of(long parent) {
|
|
62
|
+
long n = 0;
|
|
63
|
+
for (long i = 0; i < g_tree_count; i++) {
|
|
64
|
+
if (g_tree_parent[i] == parent) n += 1;
|
|
65
|
+
}
|
|
66
|
+
return n;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// NSOutlineView items are opaque objects AppKit may retain, hash, or
|
|
70
|
+
// message — so the node handle is a REAL NSNumber (autoreleased, like
|
|
71
|
+
// every NSString this library hands AppKit); a bare integer pointer
|
|
72
|
+
// would crash on retain.
|
|
73
|
+
static id nomen_tree_item(long index) {
|
|
74
|
+
return ((id(*)(id, SEL, long))objc_msgSend)(
|
|
75
|
+
(id)objc_getClass("NSNumber"), sel_registerName("numberWithLong:"), index);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
static long nomen_tree_index(id item) {
|
|
79
|
+
return ((long(*)(id, SEL))objc_msgSend)(item, sel_registerName("longValue"));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static long nomen_tree_number_of_children(id self, SEL cmd, id tv, id item) {
|
|
83
|
+
(void)self; (void)cmd; (void)tv;
|
|
84
|
+
long parent = item ? nomen_tree_index(item) : -1;
|
|
85
|
+
if (parent >= g_tree_count) return 0;
|
|
86
|
+
return nomen_tree_children_of(parent);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
static BOOL nomen_tree_is_expandable(id self, SEL cmd, id tv, id item) {
|
|
90
|
+
(void)self; (void)cmd; (void)tv;
|
|
91
|
+
long parent = item ? nomen_tree_index(item) : -1;
|
|
92
|
+
if (parent >= g_tree_count) return 0;
|
|
93
|
+
return nomen_tree_children_of(parent) > 0 ? 1 : 0;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
static id nomen_tree_child_of_item(id self, SEL cmd, id tv, long index, id item) {
|
|
97
|
+
(void)self; (void)cmd; (void)tv;
|
|
98
|
+
long parent = item ? nomen_tree_index(item) : -1;
|
|
99
|
+
if (parent >= g_tree_count) return (id)0;
|
|
100
|
+
long child = nomen_tree_child(parent, index);
|
|
101
|
+
return child < 0 ? (id)0 : nomen_tree_item(child);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
static id nomen_tree_object_value(id self, SEL cmd, id tv, id col, id item) {
|
|
105
|
+
(void)self; (void)cmd; (void)tv; (void)col;
|
|
106
|
+
long idx = item ? nomen_tree_index(item) : -1;
|
|
107
|
+
const char *text = (idx < 0 || idx >= g_tree_count) ? "" : g_tree_text[idx];
|
|
108
|
+
return ((id(*)(id, SEL, const char*))objc_msgSend)(
|
|
109
|
+
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), text);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// The delegate's selection hook: every selection change — user click
|
|
113
|
+
// AND programmatic select_row — pushes the outline view's handle
|
|
114
|
+
// into the shared selection record (the on_select feed; the ring
|
|
115
|
+
// lives in Control.nm next to the click ring).
|
|
116
|
+
static void nomen_tree_selection_did_change(id self, SEL cmd, id note) {
|
|
117
|
+
(void)self; (void)cmd;
|
|
118
|
+
id ov = ((id(*)(id, SEL))objc_msgSend)(note, sel_registerName("object"));
|
|
119
|
+
extern void nomen_select_push(unsigned long long);
|
|
120
|
+
nomen_select_push((unsigned long long)(void *)ov);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
static id nomen_tree_delegate_class(void) {
|
|
124
|
+
Class Od = objc_getClass("NomenOutlineDelegate");
|
|
125
|
+
if (!Od) {
|
|
126
|
+
Od = objc_allocateClassPair(objc_getClass("NSObject"), "NomenOutlineDelegate", 0);
|
|
127
|
+
if (Od) {
|
|
128
|
+
class_addMethod(Od, sel_registerName("outlineView:numberOfChildrenOfItem:"),
|
|
129
|
+
(IMP)nomen_tree_number_of_children, "l@:@@");
|
|
130
|
+
class_addMethod(Od, sel_registerName("outlineView:isItemExpandable:"),
|
|
131
|
+
(IMP)nomen_tree_is_expandable, "c@:@@");
|
|
132
|
+
class_addMethod(Od, sel_registerName("outlineView:child:ofItem:"),
|
|
133
|
+
(IMP)nomen_tree_child_of_item, "@@:@l@");
|
|
134
|
+
class_addMethod(Od, sel_registerName("outlineView:objectValueForTableColumn:byItem:"),
|
|
135
|
+
(IMP)nomen_tree_object_value, "@@:@@@");
|
|
136
|
+
class_addMethod(Od, sel_registerName("tableViewSelectionDidChange:"),
|
|
137
|
+
(IMP)nomen_tree_selection_did_change, "v@:@");
|
|
138
|
+
objc_registerClassPair(Od);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (!g_tree_delegate) {
|
|
142
|
+
g_tree_delegate = ((id(*)(id, SEL))objc_msgSend)(Od, sel_registerName("new"));
|
|
143
|
+
}
|
|
144
|
+
return g_tree_delegate;
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
```
|
|
148
|
+
#arch: aarch64_use_c
|
|
149
|
+
#platform: macos
|
|
150
|
+
#scope: file
|
|
151
|
+
#define NOMEN_TREE_MAX 256
|
|
152
|
+
static char *g_tree_text[NOMEN_TREE_MAX];
|
|
153
|
+
static long g_tree_parent[NOMEN_TREE_MAX]; // -1 = top level
|
|
154
|
+
static long g_tree_count = 0;
|
|
155
|
+
static id g_tree_delegate = 0;
|
|
156
|
+
|
|
157
|
+
// Append a NUL-terminated copy of `text` under `parent` (-1 = top
|
|
158
|
+
// level); returns the new node's index or -1 when the pool is full.
|
|
159
|
+
static long nomen_tree_append(const char *text, long parent) {
|
|
160
|
+
if (g_tree_count >= NOMEN_TREE_MAX) return -1;
|
|
161
|
+
if (parent < -1 || parent >= g_tree_count) return -1;
|
|
162
|
+
g_tree_text[g_tree_count] = strdup(text);
|
|
163
|
+
g_tree_parent[g_tree_count] = parent;
|
|
164
|
+
g_tree_count += 1;
|
|
165
|
+
return g_tree_count - 1;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// The index of the `n`-th child of `parent` (-1 = top level), or -1.
|
|
169
|
+
static long nomen_tree_child(long parent, long n) {
|
|
170
|
+
long seen = 0;
|
|
171
|
+
for (long i = 0; i < g_tree_count; i++) {
|
|
172
|
+
if (g_tree_parent[i] == parent) {
|
|
173
|
+
if (seen == n) return i;
|
|
174
|
+
seen += 1;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return -1;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
static long nomen_tree_children_of(long parent) {
|
|
181
|
+
long n = 0;
|
|
182
|
+
for (long i = 0; i < g_tree_count; i++) {
|
|
183
|
+
if (g_tree_parent[i] == parent) n += 1;
|
|
184
|
+
}
|
|
185
|
+
return n;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// NSOutlineView items are opaque objects AppKit may retain, hash, or
|
|
189
|
+
// message — so the node handle is a REAL NSNumber (autoreleased, like
|
|
190
|
+
// every NSString this library hands AppKit); a bare integer pointer
|
|
191
|
+
// would crash on retain.
|
|
192
|
+
static id nomen_tree_item(long index) {
|
|
193
|
+
return ((id(*)(id, SEL, long))objc_msgSend)(
|
|
194
|
+
(id)objc_getClass("NSNumber"), sel_registerName("numberWithLong:"), index);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
static long nomen_tree_index(id item) {
|
|
198
|
+
return ((long(*)(id, SEL))objc_msgSend)(item, sel_registerName("longValue"));
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
static long nomen_tree_number_of_children(id self, SEL cmd, id tv, id item) {
|
|
202
|
+
(void)self; (void)cmd; (void)tv;
|
|
203
|
+
long parent = item ? nomen_tree_index(item) : -1;
|
|
204
|
+
if (parent >= g_tree_count) return 0;
|
|
205
|
+
return nomen_tree_children_of(parent);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
static BOOL nomen_tree_is_expandable(id self, SEL cmd, id tv, id item) {
|
|
209
|
+
(void)self; (void)cmd; (void)tv;
|
|
210
|
+
long parent = item ? nomen_tree_index(item) : -1;
|
|
211
|
+
if (parent >= g_tree_count) return 0;
|
|
212
|
+
return nomen_tree_children_of(parent) > 0 ? 1 : 0;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
static id nomen_tree_child_of_item(id self, SEL cmd, id tv, long index, id item) {
|
|
216
|
+
(void)self; (void)cmd; (void)tv;
|
|
217
|
+
long parent = item ? nomen_tree_index(item) : -1;
|
|
218
|
+
if (parent >= g_tree_count) return (id)0;
|
|
219
|
+
long child = nomen_tree_child(parent, index);
|
|
220
|
+
return child < 0 ? (id)0 : nomen_tree_item(child);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
static id nomen_tree_object_value(id self, SEL cmd, id tv, id col, id item) {
|
|
224
|
+
(void)self; (void)cmd; (void)tv; (void)col;
|
|
225
|
+
long idx = item ? nomen_tree_index(item) : -1;
|
|
226
|
+
const char *text = (idx < 0 || idx >= g_tree_count) ? "" : g_tree_text[idx];
|
|
227
|
+
return ((id(*)(id, SEL, const char*))objc_msgSend)(
|
|
228
|
+
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), text);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// The delegate's selection hook (see the c twin above).
|
|
232
|
+
static void nomen_tree_selection_did_change(id self, SEL cmd, id note) {
|
|
233
|
+
(void)self; (void)cmd;
|
|
234
|
+
id ov = ((id(*)(id, SEL))objc_msgSend)(note, sel_registerName("object"));
|
|
235
|
+
extern void nomen_select_push(unsigned long long);
|
|
236
|
+
nomen_select_push((unsigned long long)(void *)ov);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
static id nomen_tree_delegate_class(void) {
|
|
240
|
+
Class Od = objc_getClass("NomenOutlineDelegate");
|
|
241
|
+
if (!Od) {
|
|
242
|
+
Od = objc_allocateClassPair(objc_getClass("NSObject"), "NomenOutlineDelegate", 0);
|
|
243
|
+
if (Od) {
|
|
244
|
+
class_addMethod(Od, sel_registerName("outlineView:numberOfChildrenOfItem:"),
|
|
245
|
+
(IMP)nomen_tree_number_of_children, "l@:@@");
|
|
246
|
+
class_addMethod(Od, sel_registerName("outlineView:isItemExpandable:"),
|
|
247
|
+
(IMP)nomen_tree_is_expandable, "c@:@@");
|
|
248
|
+
class_addMethod(Od, sel_registerName("outlineView:child:ofItem:"),
|
|
249
|
+
(IMP)nomen_tree_child_of_item, "@@:@l@");
|
|
250
|
+
class_addMethod(Od, sel_registerName("outlineView:objectValueForTableColumn:byItem:"),
|
|
251
|
+
(IMP)nomen_tree_object_value, "@@:@@@");
|
|
252
|
+
class_addMethod(Od, sel_registerName("tableViewSelectionDidChange:"),
|
|
253
|
+
(IMP)nomen_tree_selection_did_change, "v@:@");
|
|
254
|
+
objc_registerClassPair(Od);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (!g_tree_delegate) {
|
|
258
|
+
g_tree_delegate = ((id(*)(id, SEL))objc_msgSend)(Od, sel_registerName("new"));
|
|
259
|
+
}
|
|
260
|
+
return g_tree_delegate;
|
|
261
|
+
}
|
|
262
|
+
```
|
|
263
|
+
```
|
|
264
|
+
#arch: c
|
|
265
|
+
#platform: macos
|
|
266
|
+
id sv = ((id(*)(id, SEL, CGRect))objc_msgSend)(
|
|
267
|
+
((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("NSScrollView"), sel_registerName("alloc")),
|
|
268
|
+
sel_registerName("initWithFrame:"),
|
|
269
|
+
((CGRect(*)(double, double, double, double))CGRectMake)(0, 0, 200, 160));
|
|
270
|
+
((void(*)(id, SEL, BOOL))objc_msgSend)(sv, sel_registerName("setDrawsBackground:"), 0);
|
|
271
|
+
id ov = ((id(*)(id, SEL, CGRect))objc_msgSend)(
|
|
272
|
+
((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("NSOutlineView"), sel_registerName("alloc")),
|
|
273
|
+
sel_registerName("initWithFrame:"),
|
|
274
|
+
((CGRect(*)(double, double, double, double))CGRectMake)(0, 0, 200, 160));
|
|
275
|
+
((void(*)(id, SEL, double))objc_msgSend)(ov, sel_registerName("setRowHeight:"), 22.0);
|
|
276
|
+
((void(*)(id, SEL, id))objc_msgSend)(ov, sel_registerName("setHeaderView:"), (id)0);
|
|
277
|
+
((void(*)(id, SEL, BOOL))objc_msgSend)(ov, sel_registerName("setAllowsColumnSelection:"), 0);
|
|
278
|
+
id col = ((id(*)(id, SEL, id))objc_msgSend)(
|
|
279
|
+
((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("NSTableColumn"), sel_registerName("alloc")),
|
|
280
|
+
sel_registerName("initWithIdentifier:"),
|
|
281
|
+
((id(*)(id, SEL, const char*))objc_msgSend)(
|
|
282
|
+
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), "main"));
|
|
283
|
+
((void(*)(id, SEL, unsigned long))objc_msgSend)(col, sel_registerName("setResizingMask:"), 2UL);
|
|
284
|
+
((void(*)(id, SEL, id))objc_msgSend)(ov, sel_registerName("addTableColumn:"), col);
|
|
285
|
+
((void(*)(id, SEL))objc_msgSend)(col, sel_registerName("release"));
|
|
286
|
+
((void(*)(id, SEL, id))objc_msgSend)(ov, sel_registerName("setDelegate:"), nomen_tree_delegate_class());
|
|
287
|
+
((void(*)(id, SEL, id))objc_msgSend)(ov, sel_registerName("setDataSource:"), nomen_tree_delegate_class());
|
|
288
|
+
((void(*)(id, SEL, id))objc_msgSend)(sv, sel_registerName("setDocumentView:"), ov);
|
|
289
|
+
((void(*)(id, SEL))objc_msgSend)(ov, sel_registerName("release"));
|
|
290
|
+
id contentView = ((id(*)(id, SEL))objc_msgSend)(
|
|
291
|
+
(id)window->handle, sel_registerName("contentView"));
|
|
292
|
+
((void(*)(id, SEL, id))objc_msgSend)(
|
|
293
|
+
contentView, sel_registerName("addSubview:"), sv);
|
|
294
|
+
self.handle = (uint64_t)sv;
|
|
295
|
+
self.tree = (uint64_t)((id(*)(id, SEL))objc_msgSend)(sv, sel_registerName("documentView"));
|
|
296
|
+
```
|
|
297
|
+
```
|
|
298
|
+
#arch: aarch64_use_c
|
|
299
|
+
#platform: macos
|
|
300
|
+
id sv = ((id(*)(id, SEL, CGRect))objc_msgSend)(
|
|
301
|
+
((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("NSScrollView"), sel_registerName("alloc")),
|
|
302
|
+
sel_registerName("initWithFrame:"),
|
|
303
|
+
((CGRect(*)(double, double, double, double))CGRectMake)(0, 0, 200, 160));
|
|
304
|
+
((void(*)(id, SEL, BOOL))objc_msgSend)(sv, sel_registerName("setDrawsBackground:"), 0);
|
|
305
|
+
id ov = ((id(*)(id, SEL, CGRect))objc_msgSend)(
|
|
306
|
+
((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("NSOutlineView"), sel_registerName("alloc")),
|
|
307
|
+
sel_registerName("initWithFrame:"),
|
|
308
|
+
((CGRect(*)(double, double, double, double))CGRectMake)(0, 0, 200, 160));
|
|
309
|
+
((void(*)(id, SEL, double))objc_msgSend)(ov, sel_registerName("setRowHeight:"), 22.0);
|
|
310
|
+
((void(*)(id, SEL, id))objc_msgSend)(ov, sel_registerName("setHeaderView:"), (id)0);
|
|
311
|
+
((void(*)(id, SEL, BOOL))objc_msgSend)(ov, sel_registerName("setAllowsColumnSelection:"), 0);
|
|
312
|
+
id col = ((id(*)(id, SEL, id))objc_msgSend)(
|
|
313
|
+
((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("NSTableColumn"), sel_registerName("alloc")),
|
|
314
|
+
sel_registerName("initWithIdentifier:"),
|
|
315
|
+
((id(*)(id, SEL, const char*))objc_msgSend)(
|
|
316
|
+
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), "main"));
|
|
317
|
+
((void(*)(id, SEL, unsigned long))objc_msgSend)(col, sel_registerName("setResizingMask:"), 2UL);
|
|
318
|
+
((void(*)(id, SEL, id))objc_msgSend)(ov, sel_registerName("addTableColumn:"), col);
|
|
319
|
+
((void(*)(id, SEL))objc_msgSend)(col, sel_registerName("release"));
|
|
320
|
+
((void(*)(id, SEL, id))objc_msgSend)(ov, sel_registerName("setDelegate:"), nomen_tree_delegate_class());
|
|
321
|
+
((void(*)(id, SEL, id))objc_msgSend)(ov, sel_registerName("setDataSource:"), nomen_tree_delegate_class());
|
|
322
|
+
((void(*)(id, SEL, id))objc_msgSend)(sv, sel_registerName("setDocumentView:"), ov);
|
|
323
|
+
((void(*)(id, SEL))objc_msgSend)(ov, sel_registerName("release"));
|
|
324
|
+
id contentView = ((id(*)(id, SEL))objc_msgSend)(
|
|
325
|
+
(id)window->handle, sel_registerName("contentView"));
|
|
326
|
+
((void(*)(id, SEL, id))objc_msgSend)(
|
|
327
|
+
contentView, sel_registerName("addSubview:"), sv);
|
|
328
|
+
self->handle = (uint64_t)sv;
|
|
329
|
+
self->tree = (uint64_t)((id(*)(id, SEL))objc_msgSend)(sv, sel_registerName("documentView"));
|
|
330
|
+
```
|
|
331
|
+
```
|
|
332
|
+
#arch: c
|
|
333
|
+
#platform: ios
|
|
334
|
+
/* TODO: iOS — no NSOutlineView counterpart (compose from a
|
|
335
|
+
* UITableView data source with depth indentation; see GUI_PLAN
|
|
336
|
+
* Tier 2; defer). */
|
|
337
|
+
```
|
|
338
|
+
```
|
|
339
|
+
#arch: aarch64_use_c
|
|
340
|
+
#platform: ios
|
|
341
|
+
/* TODO: iOS (see #init) */
|
|
342
|
+
```
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// Append a node under `parent` (its `add_item`-order index, or -1 for a
|
|
346
|
+
// top-level item) and reload.
|
|
347
|
+
pub func add_item = (self, string text, int parent) {
|
|
348
|
+
```
|
|
349
|
+
#arch: c
|
|
350
|
+
#platform: macos
|
|
351
|
+
nomen_tree_append(text.ptr, (long)parent);
|
|
352
|
+
((void(*)(id, SEL))objc_msgSend)((id)self->tree, sel_registerName("reloadData"));
|
|
353
|
+
```
|
|
354
|
+
```
|
|
355
|
+
#arch: aarch64_use_c
|
|
356
|
+
#platform: macos
|
|
357
|
+
nomen_tree_append(text.ptr, (long)parent);
|
|
358
|
+
((void(*)(id, SEL))objc_msgSend)((id)self->tree, sel_registerName("reloadData"));
|
|
359
|
+
```
|
|
360
|
+
```
|
|
361
|
+
#arch: c
|
|
362
|
+
#platform: ios
|
|
363
|
+
/* TODO: iOS (see #init) */
|
|
364
|
+
```
|
|
365
|
+
```
|
|
366
|
+
#arch: aarch64_use_c
|
|
367
|
+
#platform: ios
|
|
368
|
+
/* TODO: iOS (see #init) */
|
|
369
|
+
```
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// Expand or collapse the branch at node `index`.
|
|
373
|
+
pub func set_expanded = (self, int index, bool expanded) {
|
|
374
|
+
```
|
|
375
|
+
#arch: c
|
|
376
|
+
#platform: macos
|
|
377
|
+
if (index < 0 || (long)index >= g_tree_count) return;
|
|
378
|
+
((void(*)(id, SEL, id, BOOL))objc_msgSend)(
|
|
379
|
+
(id)self->tree, sel_registerName("expandItem:expandChildren:"),
|
|
380
|
+
nomen_tree_item((long)index), expanded ? 1 : 0);
|
|
381
|
+
```
|
|
382
|
+
```
|
|
383
|
+
#arch: aarch64_use_c
|
|
384
|
+
#platform: macos
|
|
385
|
+
if (index < 0 || (long)index >= g_tree_count) return;
|
|
386
|
+
((void(*)(id, SEL, id, BOOL))objc_msgSend)(
|
|
387
|
+
(id)self->tree, sel_registerName("expandItem:expandChildren:"),
|
|
388
|
+
nomen_tree_item((long)index), expanded ? 1 : 0);
|
|
389
|
+
```
|
|
390
|
+
```
|
|
391
|
+
#arch: c
|
|
392
|
+
#platform: ios
|
|
393
|
+
/* TODO: iOS (see #init) */
|
|
394
|
+
```
|
|
395
|
+
```
|
|
396
|
+
#arch: aarch64_use_c
|
|
397
|
+
#platform: ios
|
|
398
|
+
/* TODO: iOS (see #init) */
|
|
399
|
+
```
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// The total number of nodes in the pool.
|
|
403
|
+
pub func count = (self, out int) {
|
|
404
|
+
```
|
|
405
|
+
#arch: c
|
|
406
|
+
#platform: macos
|
|
407
|
+
return (int)g_tree_count;
|
|
408
|
+
```
|
|
409
|
+
```
|
|
410
|
+
#arch: aarch64_use_c
|
|
411
|
+
#platform: macos
|
|
412
|
+
return (int)g_tree_count;
|
|
413
|
+
```
|
|
414
|
+
```
|
|
415
|
+
#arch: c
|
|
416
|
+
#platform: ios
|
|
417
|
+
/* TODO: iOS (see #init) */
|
|
418
|
+
return 0;
|
|
419
|
+
```
|
|
420
|
+
```
|
|
421
|
+
#arch: aarch64_use_c
|
|
422
|
+
#platform: ios
|
|
423
|
+
/* TODO: iOS (see #init) */
|
|
424
|
+
return 0;
|
|
425
|
+
```
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// The selected ROW (a visible row number, not a node index), polled;
|
|
429
|
+
// -1 = no selection.
|
|
430
|
+
pub func selected_row = (self, out int) {
|
|
431
|
+
```
|
|
432
|
+
#arch: c
|
|
433
|
+
#platform: macos
|
|
434
|
+
return (int)((long(*)(id, SEL))objc_msgSend)((id)self->tree, sel_registerName("selectedRow"));
|
|
435
|
+
```
|
|
436
|
+
```
|
|
437
|
+
#arch: aarch64_use_c
|
|
438
|
+
#platform: macos
|
|
439
|
+
return (int)((long(*)(id, SEL))objc_msgSend)((id)self->tree, sel_registerName("selectedRow"));
|
|
440
|
+
```
|
|
441
|
+
```
|
|
442
|
+
#arch: c
|
|
443
|
+
#platform: ios
|
|
444
|
+
/* TODO: iOS (see #init) */
|
|
445
|
+
return -1;
|
|
446
|
+
```
|
|
447
|
+
```
|
|
448
|
+
#arch: aarch64_use_c
|
|
449
|
+
#platform: ios
|
|
450
|
+
/* TODO: iOS (see #init) */
|
|
451
|
+
return -1;
|
|
452
|
+
```
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// The on_select desugar's drain (docs/HANDLERS.md): true when the
|
|
456
|
+
// selected row changed since the last drain — user clicks AND
|
|
457
|
+
// programmatic select_row (the delegate observes both; a pre-selection
|
|
458
|
+
// in #init therefore fires on the first frame). The handler body reads
|
|
459
|
+
// the row through selected_row(). The record is keyed on the outline
|
|
460
|
+
// view (what the delegate sees), not the scroll wrapper.
|
|
461
|
+
pub func take_select = (self, out bool) {
|
|
462
|
+
```
|
|
463
|
+
#arch: c
|
|
464
|
+
#platform: macos
|
|
465
|
+
extern long nomen_select_take(unsigned long long);
|
|
466
|
+
return (long)nomen_select_take((unsigned long long)self->tree);
|
|
467
|
+
```
|
|
468
|
+
```
|
|
469
|
+
#arch: aarch64_use_c
|
|
470
|
+
#platform: macos
|
|
471
|
+
extern long nomen_select_take(unsigned long long);
|
|
472
|
+
return (long)nomen_select_take((unsigned long long)self->tree);
|
|
473
|
+
```
|
|
474
|
+
```
|
|
475
|
+
#arch: c
|
|
476
|
+
#platform: ios
|
|
477
|
+
/* TODO: iOS (see #init) */
|
|
478
|
+
return false;
|
|
479
|
+
```
|
|
480
|
+
```
|
|
481
|
+
#arch: aarch64_use_c
|
|
482
|
+
#platform: ios
|
|
483
|
+
/* TODO: iOS (see #init) */
|
|
484
|
+
return false;
|
|
485
|
+
```
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
pub func set_hidden = (self, bool hidden) {
|
|
489
|
+
```
|
|
490
|
+
#arch: c
|
|
491
|
+
#platform: macos
|
|
492
|
+
((void(*)(id, SEL, BOOL))objc_msgSend)(
|
|
493
|
+
(id)self->handle, sel_registerName("setHidden:"), hidden ? 1 : 0);
|
|
494
|
+
```
|
|
495
|
+
```
|
|
496
|
+
#arch: aarch64_use_c
|
|
497
|
+
#platform: macos
|
|
498
|
+
((void(*)(id, SEL, BOOL))objc_msgSend)(
|
|
499
|
+
(id)self->handle, sel_registerName("setHidden:"), hidden ? 1 : 0);
|
|
500
|
+
```
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// ── Control trait conformance ──
|
|
504
|
+
pub func set_frame = (ref self, int x, int y, int width, int height) {
|
|
505
|
+
```
|
|
506
|
+
#arch: c
|
|
507
|
+
#platform: macos
|
|
508
|
+
((void(*)(id, SEL, CGRect))objc_msgSend)(
|
|
509
|
+
(id)self->handle, sel_registerName("setFrame:"),
|
|
510
|
+
((CGRect(*)(double, double, double, double))CGRectMake)((double)x, (double)y, (double)width, (double)height));
|
|
511
|
+
```
|
|
512
|
+
```
|
|
513
|
+
#arch: aarch64_use_c
|
|
514
|
+
#platform: macos
|
|
515
|
+
((void(*)(id, SEL, CGRect))objc_msgSend)(
|
|
516
|
+
(id)self->handle, sel_registerName("setFrame:"),
|
|
517
|
+
((CGRect(*)(double, double, double, double))CGRectMake)((double)x, (double)y, (double)width, (double)height));
|
|
518
|
+
```
|
|
519
|
+
```
|
|
520
|
+
#arch: c
|
|
521
|
+
#platform: ios
|
|
522
|
+
/* TODO: iOS (see #init) */
|
|
523
|
+
```
|
|
524
|
+
```
|
|
525
|
+
#arch: aarch64_use_c
|
|
526
|
+
#platform: ios
|
|
527
|
+
/* TODO: iOS (see #init) */
|
|
528
|
+
```
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
pub func intrinsic_size = (self, out Size) {
|
|
532
|
+
var [w, h] = native_intrinsic(self.handle)
|
|
533
|
+
var s = Size()
|
|
534
|
+
s.width = w
|
|
535
|
+
s.height = h
|
|
536
|
+
return s
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
pub func measure = (self, BoxConstraints constraints, out Size) {
|
|
540
|
+
var Size s = self.intrinsic_size()
|
|
541
|
+
if s.width > constraints.max_width {
|
|
542
|
+
s.width = constraints.max_width
|
|
543
|
+
}
|
|
544
|
+
if s.width < constraints.min_width {
|
|
545
|
+
s.width = constraints.min_width
|
|
546
|
+
}
|
|
547
|
+
if s.height > constraints.max_height {
|
|
548
|
+
s.height = constraints.max_height
|
|
549
|
+
}
|
|
550
|
+
if s.height < constraints.min_height {
|
|
551
|
+
s.height = constraints.min_height
|
|
552
|
+
}
|
|
553
|
+
return s
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
func #destroy = () {
|
|
557
|
+
```
|
|
558
|
+
#arch: c
|
|
559
|
+
#platform: macos
|
|
560
|
+
for (long i = 0; i < g_tree_count; i++) {
|
|
561
|
+
free(g_tree_text[i]);
|
|
562
|
+
g_tree_text[i] = 0;
|
|
563
|
+
}
|
|
564
|
+
g_tree_count = 0;
|
|
565
|
+
if (self->handle) {
|
|
566
|
+
((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("removeFromSuperview"));
|
|
567
|
+
((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("release"));
|
|
568
|
+
self->handle = 0;
|
|
569
|
+
}
|
|
570
|
+
self->tree = 0;
|
|
571
|
+
```
|
|
572
|
+
```
|
|
573
|
+
#arch: aarch64_use_c
|
|
574
|
+
#platform: macos
|
|
575
|
+
for (long i = 0; i < g_tree_count; i++) {
|
|
576
|
+
free(g_tree_text[i]);
|
|
577
|
+
g_tree_text[i] = 0;
|
|
578
|
+
}
|
|
579
|
+
g_tree_count = 0;
|
|
580
|
+
if (self->handle) {
|
|
581
|
+
((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("removeFromSuperview"));
|
|
582
|
+
((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("release"));
|
|
583
|
+
self->handle = 0;
|
|
584
|
+
}
|
|
585
|
+
self->tree = 0;
|
|
586
|
+
```
|
|
587
|
+
```
|
|
588
|
+
#arch: c
|
|
589
|
+
#platform: ios
|
|
590
|
+
/* TODO: iOS (see #init) */
|
|
591
|
+
```
|
|
592
|
+
```
|
|
593
|
+
#arch: aarch64_use_c
|
|
594
|
+
#platform: ios
|
|
595
|
+
/* TODO: iOS (see #init) */
|
|
596
|
+
```
|
|
597
|
+
}
|
|
598
|
+
}
|