Skip to content

Commit 5f0a917

Browse files
feat: Allow usage of char slices in addition to null-terminated strings (#60)
Co-authored-by: zipsegv <[email protected]>
1 parent 3b8ab84 commit 5f0a917

File tree

4 files changed

+242
-24
lines changed

4 files changed

+242
-24
lines changed

include/accesskit.h

Lines changed: 159 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,8 +869,8 @@ typedef struct accesskit_opt_text_selection {
869869
} accesskit_opt_text_selection;
870870

871871
/**
872-
* Use `accesskit_custom_action_new` to create this struct. Do not reallocate
873-
* `description`.
872+
* Use `accesskit_custom_action_new` to create this struct. Do not
873+
* reallocate `description`.
874874
*
875875
* When you get this struct, you are responsible for freeing `description`.
876876
*/
@@ -1368,6 +1368,12 @@ char *accesskit_node_label(const struct accesskit_node *node);
13681368
*/
13691369
void accesskit_node_set_label(struct accesskit_node *node, const char *value);
13701370

1371+
/**
1372+
* Caller is responsible for freeing the memory pointed by `value`.
1373+
*/
1374+
void accesskit_node_set_label_with_length(struct accesskit_node *node,
1375+
const char *value, size_t length);
1376+
13711377
void accesskit_node_clear_label(struct accesskit_node *node);
13721378

13731379
/**
@@ -1381,6 +1387,13 @@ char *accesskit_node_description(const struct accesskit_node *node);
13811387
void accesskit_node_set_description(struct accesskit_node *node,
13821388
const char *value);
13831389

1390+
/**
1391+
* Caller is responsible for freeing the memory pointed by `value`.
1392+
*/
1393+
void accesskit_node_set_description_with_length(struct accesskit_node *node,
1394+
const char *value,
1395+
size_t length);
1396+
13841397
void accesskit_node_clear_description(struct accesskit_node *node);
13851398

13861399
/**
@@ -1393,6 +1406,12 @@ char *accesskit_node_value(const struct accesskit_node *node);
13931406
*/
13941407
void accesskit_node_set_value(struct accesskit_node *node, const char *value);
13951408

1409+
/**
1410+
* Caller is responsible for freeing the memory pointed by `value`.
1411+
*/
1412+
void accesskit_node_set_value_with_length(struct accesskit_node *node,
1413+
const char *value, size_t length);
1414+
13961415
void accesskit_node_clear_value(struct accesskit_node *node);
13971416

13981417
/**
@@ -1406,6 +1425,13 @@ char *accesskit_node_access_key(const struct accesskit_node *node);
14061425
void accesskit_node_set_access_key(struct accesskit_node *node,
14071426
const char *value);
14081427

1428+
/**
1429+
* Caller is responsible for freeing the memory pointed by `value`.
1430+
*/
1431+
void accesskit_node_set_access_key_with_length(struct accesskit_node *node,
1432+
const char *value,
1433+
size_t length);
1434+
14091435
void accesskit_node_clear_access_key(struct accesskit_node *node);
14101436

14111437
/**
@@ -1419,6 +1445,12 @@ char *accesskit_node_author_id(const struct accesskit_node *node);
14191445
void accesskit_node_set_author_id(struct accesskit_node *node,
14201446
const char *value);
14211447

1448+
/**
1449+
* Caller is responsible for freeing the memory pointed by `value`.
1450+
*/
1451+
void accesskit_node_set_author_id_with_length(struct accesskit_node *node,
1452+
const char *value, size_t length);
1453+
14221454
void accesskit_node_clear_author_id(struct accesskit_node *node);
14231455

14241456
/**
@@ -1432,6 +1464,13 @@ char *accesskit_node_class_name(const struct accesskit_node *node);
14321464
void accesskit_node_set_class_name(struct accesskit_node *node,
14331465
const char *value);
14341466

1467+
/**
1468+
* Caller is responsible for freeing the memory pointed by `value`.
1469+
*/
1470+
void accesskit_node_set_class_name_with_length(struct accesskit_node *node,
1471+
const char *value,
1472+
size_t length);
1473+
14351474
void accesskit_node_clear_class_name(struct accesskit_node *node);
14361475

14371476
/**
@@ -1445,6 +1484,13 @@ char *accesskit_node_font_family(const struct accesskit_node *node);
14451484
void accesskit_node_set_font_family(struct accesskit_node *node,
14461485
const char *value);
14471486

1487+
/**
1488+
* Caller is responsible for freeing the memory pointed by `value`.
1489+
*/
1490+
void accesskit_node_set_font_family_with_length(struct accesskit_node *node,
1491+
const char *value,
1492+
size_t length);
1493+
14481494
void accesskit_node_clear_font_family(struct accesskit_node *node);
14491495

14501496
/**
@@ -1458,6 +1504,12 @@ char *accesskit_node_html_tag(const struct accesskit_node *node);
14581504
void accesskit_node_set_html_tag(struct accesskit_node *node,
14591505
const char *value);
14601506

1507+
/**
1508+
* Caller is responsible for freeing the memory pointed by `value`.
1509+
*/
1510+
void accesskit_node_set_html_tag_with_length(struct accesskit_node *node,
1511+
const char *value, size_t length);
1512+
14611513
void accesskit_node_clear_html_tag(struct accesskit_node *node);
14621514

14631515
/**
@@ -1471,6 +1523,13 @@ char *accesskit_node_inner_html(const struct accesskit_node *node);
14711523
void accesskit_node_set_inner_html(struct accesskit_node *node,
14721524
const char *value);
14731525

1526+
/**
1527+
* Caller is responsible for freeing the memory pointed by `value`.
1528+
*/
1529+
void accesskit_node_set_inner_html_with_length(struct accesskit_node *node,
1530+
const char *value,
1531+
size_t length);
1532+
14741533
void accesskit_node_clear_inner_html(struct accesskit_node *node);
14751534

14761535
/**
@@ -1484,6 +1543,12 @@ char *accesskit_node_keyboard_shortcut(const struct accesskit_node *node);
14841543
void accesskit_node_set_keyboard_shortcut(struct accesskit_node *node,
14851544
const char *value);
14861545

1546+
/**
1547+
* Caller is responsible for freeing the memory pointed by `value`.
1548+
*/
1549+
void accesskit_node_set_keyboard_shortcut_with_length(
1550+
struct accesskit_node *node, const char *value, size_t length);
1551+
14871552
void accesskit_node_clear_keyboard_shortcut(struct accesskit_node *node);
14881553

14891554
/**
@@ -1497,6 +1562,12 @@ char *accesskit_node_language(const struct accesskit_node *node);
14971562
void accesskit_node_set_language(struct accesskit_node *node,
14981563
const char *value);
14991564

1565+
/**
1566+
* Caller is responsible for freeing the memory pointed by `value`.
1567+
*/
1568+
void accesskit_node_set_language_with_length(struct accesskit_node *node,
1569+
const char *value, size_t length);
1570+
15001571
void accesskit_node_clear_language(struct accesskit_node *node);
15011572

15021573
/**
@@ -1510,6 +1581,13 @@ char *accesskit_node_placeholder(const struct accesskit_node *node);
15101581
void accesskit_node_set_placeholder(struct accesskit_node *node,
15111582
const char *value);
15121583

1584+
/**
1585+
* Caller is responsible for freeing the memory pointed by `value`.
1586+
*/
1587+
void accesskit_node_set_placeholder_with_length(struct accesskit_node *node,
1588+
const char *value,
1589+
size_t length);
1590+
15131591
void accesskit_node_clear_placeholder(struct accesskit_node *node);
15141592

15151593
/**
@@ -1523,6 +1601,12 @@ char *accesskit_node_role_description(const struct accesskit_node *node);
15231601
void accesskit_node_set_role_description(struct accesskit_node *node,
15241602
const char *value);
15251603

1604+
/**
1605+
* Caller is responsible for freeing the memory pointed by `value`.
1606+
*/
1607+
void accesskit_node_set_role_description_with_length(
1608+
struct accesskit_node *node, const char *value, size_t length);
1609+
15261610
void accesskit_node_clear_role_description(struct accesskit_node *node);
15271611

15281612
/**
@@ -1536,6 +1620,12 @@ char *accesskit_node_state_description(const struct accesskit_node *node);
15361620
void accesskit_node_set_state_description(struct accesskit_node *node,
15371621
const char *value);
15381622

1623+
/**
1624+
* Caller is responsible for freeing the memory pointed by `value`.
1625+
*/
1626+
void accesskit_node_set_state_description_with_length(
1627+
struct accesskit_node *node, const char *value, size_t length);
1628+
15391629
void accesskit_node_clear_state_description(struct accesskit_node *node);
15401630

15411631
/**
@@ -1548,6 +1638,12 @@ char *accesskit_node_tooltip(const struct accesskit_node *node);
15481638
*/
15491639
void accesskit_node_set_tooltip(struct accesskit_node *node, const char *value);
15501640

1641+
/**
1642+
* Caller is responsible for freeing the memory pointed by `value`.
1643+
*/
1644+
void accesskit_node_set_tooltip_with_length(struct accesskit_node *node,
1645+
const char *value, size_t length);
1646+
15511647
void accesskit_node_clear_tooltip(struct accesskit_node *node);
15521648

15531649
/**
@@ -1560,6 +1656,12 @@ char *accesskit_node_url(const struct accesskit_node *node);
15601656
*/
15611657
void accesskit_node_set_url(struct accesskit_node *node, const char *value);
15621658

1659+
/**
1660+
* Caller is responsible for freeing the memory pointed by `value`.
1661+
*/
1662+
void accesskit_node_set_url_with_length(struct accesskit_node *node,
1663+
const char *value, size_t length);
1664+
15631665
void accesskit_node_clear_url(struct accesskit_node *node);
15641666

15651667
/**
@@ -1573,6 +1675,13 @@ char *accesskit_node_row_index_text(const struct accesskit_node *node);
15731675
void accesskit_node_set_row_index_text(struct accesskit_node *node,
15741676
const char *value);
15751677

1678+
/**
1679+
* Caller is responsible for freeing the memory pointed by `value`.
1680+
*/
1681+
void accesskit_node_set_row_index_text_with_length(struct accesskit_node *node,
1682+
const char *value,
1683+
size_t length);
1684+
15761685
void accesskit_node_clear_row_index_text(struct accesskit_node *node);
15771686

15781687
/**
@@ -1586,6 +1695,12 @@ char *accesskit_node_column_index_text(const struct accesskit_node *node);
15861695
void accesskit_node_set_column_index_text(struct accesskit_node *node,
15871696
const char *value);
15881697

1698+
/**
1699+
* Caller is responsible for freeing the memory pointed by `value`.
1700+
*/
1701+
void accesskit_node_set_column_index_text_with_length(
1702+
struct accesskit_node *node, const char *value, size_t length);
1703+
15891704
void accesskit_node_clear_column_index_text(struct accesskit_node *node);
15901705

15911706
struct accesskit_opt_double accesskit_node_scroll_x(
@@ -2014,19 +2129,39 @@ void accesskit_tree_free(struct accesskit_tree *tree);
20142129
*/
20152130
char *accesskit_tree_get_toolkit_name(const struct accesskit_tree *tree);
20162131

2132+
/**
2133+
* Caller is responsible for freeing the memory pointed by `toolkit_name`
2134+
*/
20172135
void accesskit_tree_set_toolkit_name(struct accesskit_tree *tree,
20182136
const char *toolkit_name);
20192137

2138+
/**
2139+
* Caller is responsible for freeing the memory pointed by `toolkit_name`
2140+
*/
2141+
void accesskit_tree_set_toolkit_name_with_length(struct accesskit_tree *tree,
2142+
const char *toolkit_name,
2143+
size_t length);
2144+
20202145
void accesskit_tree_clear_toolkit_name(struct accesskit_tree *tree);
20212146

20222147
/**
20232148
* Caller must call `accesskit_string_free` with the return value.
20242149
*/
20252150
char *accesskit_tree_get_toolkit_version(const struct accesskit_tree *tree);
20262151

2152+
/**
2153+
* Caller is responsible for freeing the memory pointed by `toolkit_version`
2154+
*/
20272155
void accesskit_tree_set_toolkit_version(struct accesskit_tree *tree,
20282156
const char *toolkit_version);
20292157

2158+
/**
2159+
* Caller is responsible for freeing the memory pointed by `toolkit_version`
2160+
*/
2161+
void accesskit_tree_set_toolkit_version_with_length(struct accesskit_tree *tree,
2162+
const char *toolkit_version,
2163+
size_t length);
2164+
20302165
void accesskit_tree_clear_toolkit_version(struct accesskit_tree *tree);
20312166

20322167
/**
@@ -2319,6 +2454,28 @@ void accesskit_macos_add_focus_forwarder_to_window_class(
23192454
const char *class_name);
23202455
#endif
23212456

2457+
#if defined(__APPLE__)
2458+
/**
2459+
* Modifies the specified class, which must be a subclass of `NSWindow`,
2460+
* to include an `accessibilityFocusedUIElement` method that calls
2461+
* the corresponding method on the window's content view. This is needed
2462+
* for windowing libraries such as SDL that place the keyboard focus
2463+
* directly on the window rather than the content view.
2464+
* Caller is responsible for freeing `class_name`.
2465+
*
2466+
* # Safety
2467+
*
2468+
* This function is declared unsafe because the caller must ensure that the
2469+
* code for this library is never unloaded from the application process,
2470+
* since it's not possible to reverse this operation. It's safest
2471+
* if this library is statically linked into the application's main executable.
2472+
* Also, this function assumes that the specified class is a subclass
2473+
* of `NSWindow`.
2474+
*/
2475+
void accesskit_macos_add_focus_forwarder_to_window_class_with_length(
2476+
const char *class_name, size_t length);
2477+
#endif
2478+
23222479
#if (defined(__linux__) || defined(__DragonFly__) || defined(__FreeBSD__) || \
23232480
defined(__NetBSD__) || defined(__OpenBSD__))
23242481
/**

0 commit comments

Comments
 (0)