| 1 | // The C surface of crates/mobile; see its lib.rs and library.rs for each call's contract. |
| 2 | #pragma once |
| 3 | |
| 4 | #include <stdbool.h> |
| 5 | #include <stddef.h> |
| 6 | #include <stdint.h> |
| 7 | |
| 8 | typedef struct Library Library; |
| 9 | typedef struct Share Share; |
| 10 | typedef struct Section Section; |
| 11 | typedef struct View View; |
| 12 | |
| 13 | void sb_string_free(char *text); |
| 14 | |
| 15 | bool sb_crash_start(const char *path, const char *build, const char *system); |
| 16 | const char *sb_crash_address(void); |
| 17 | char *sb_crash_report(void); |
| 18 | void sb_crash_forget(void); |
| 19 | |
| 20 | typedef void (*sb_coordinator)(const char *path, bool write, void (*body)(void *), void *context); |
| 21 | void sb_set_coordinator(sb_coordinator coordinator); |
| 22 | void sb_set_sync_wake(void (*wake)(void)); |
| 23 | typedef void (*sb_versions)(const char *path, void (*found)(void *, const char *id, const char *device), void *context); |
| 24 | typedef bool (*sb_retire)(const char *path, const char *id, bool keep); |
| 25 | void sb_set_versions(sb_versions versions, sb_retire retire); |
| 26 | char *sb_tags(void); |
| 27 | char *sb_pens(uint32_t section); |
| 28 | bool sb_tag_icon(uint16_t shape, bool checked, uint32_t pixels, uint8_t *rgba); |
| 29 | |
| 30 | const Library *sb_library_open(const char *path, const char *cache, bool local, char **error); |
| 31 | const Library *sb_library_server(const char *address, const char *share, const char *user, const char *password, |
| 32 | const char *domain, const char *root, const char *cache, char **error); |
| 33 | bool sb_notebook_create(const char *path, const char *cache, const char *author, const char *date, const char *time, |
| 34 | char **error); |
| 35 | bool sb_notebook_moved(const char *cache, const char *from, const char *to, char **error); |
| 36 | char *sb_library_sections(const Library *library); |
| 37 | int32_t sb_library_color(const Library *library); |
| 38 | char *sb_library_new_section(const Library *library, const char *folder, const char *name, const char *author, |
| 39 | const char *date, const char *time); |
| 40 | char *sb_library_move_page(const Library *library, const char *from, const char *id, const char *to, const char *before, |
| 41 | uint32_t level, const char *discard, const char *author, const char *date, const char *time); |
| 42 | char *sb_library_place(const Library *library, const char *path, const char *folder, const char *paths); |
| 43 | char *sb_search(const Library *const *libraries, size_t count, const char *section, const char *query); |
| 44 | char *sb_library_tagged(const Library *library); |
| 45 | bool sb_library_unlock(const Library *library, const char *path, const char *password); |
| 46 | void sb_library_lock_all(const Library *library); |
| 47 | char *sb_library_sync_status(const Library *library); |
| 48 | void sb_library_set_offline(const Library *library, bool offline); |
| 49 | void sb_library_touched(const Library *library, const char *path); |
| 50 | void sb_library_sync_now(const Library *library); |
| 51 | bool sb_library_close(const Library *library, double seconds, char **error); |
| 52 | void sb_library_free(const Library *library); |
| 53 | |
| 54 | Share *sb_share_connect(const char *address, const char *share, const char *user, const char *password, |
| 55 | const char *domain, char **error); |
| 56 | char *sb_share_list(const Share *share, const char *path); |
| 57 | void sb_share_free(Share *share); |
| 58 | |
| 59 | typedef void (*sb_wake)(uintptr_t token); |
| 60 | Section *sb_section_open(const Library *library, const char *path, const char *author, sb_wake wake, |
| 61 | uintptr_t token, char **error); |
| 62 | char *sb_section_pages(const Section *section); |
| 63 | uint32_t sb_section_poll(const Section *section, uint8_t *status); |
| 64 | char *sb_section_new_page(const Section *section, const char *parent, const char *date, const char *time); |
| 65 | bool sb_section_delete_page(const Section *section, const char *id, const char *date, const char *time); |
| 66 | bool sb_section_arrange(const Section *section, const char *order, const char *moved); |
| 67 | char *sb_section_themes(const Section *section, const char *id); |
| 68 | bool sb_section_set_theme(const Section *section, const char *id, uint8_t scope, const char *theme); |
| 69 | bool sb_section_flush(const Section *section, double seconds); |
| 70 | void sb_section_wake(const Section *section); |
| 71 | void sb_section_set_author(const Section *section, const char *author); |
| 72 | void sb_section_free(Section *section); |
| 73 | |
| 74 | View *sb_view_new(void *layer, const Section *section, const char *id, float width, float height, float scale); |
| 75 | void sb_view_free(View *view); |
| 76 | void sb_view_resize(View *view, float width, float height, float scale); |
| 77 | bool sb_view_render(View *view); |
| 78 | bool sb_view_frame_pending(const View *view); |
| 79 | void sb_view_set_dark(View *view, bool dark); |
| 80 | bool sb_view_read_only(const View *view); |
| 81 | char *sb_view_reading(const View *view, float width); |
| 82 | bool sb_view_set_reading(View *view, float width); |
| 83 | bool sb_view_reload(View *view, bool discard); |
| 84 | void sb_view_focus(View *view, bool focused); |
| 85 | void sb_view_content(View *view, float bounds[4]); |
| 86 | bool sb_view_block(const View *view, float x, float y, float rect[4]); |
| 87 | void sb_view_set_transform(View *view, float zoom, float x, float y); |
| 88 | uint8_t sb_view_target(const View *view, float x, float y); |
| 89 | void sb_view_pressure(View *view, float pressure); |
| 90 | void sb_set_snap_to_grid(bool on); |
| 91 | void sb_set_default_font(const char *face, float size); |
| 92 | void sb_set_markdown_shortcuts(bool on); |
| 93 | bool sb_view_press(View *view, float x, float y); |
| 94 | bool sb_view_drag(View *view, float x, float y); |
| 95 | bool sb_view_release(View *view); |
| 96 | bool sb_view_undo(View *view, bool redo); |
| 97 | bool sb_view_can_undo(const View *view, bool redo); |
| 98 | uint64_t sb_view_format(const View *view); |
| 99 | bool sb_view_apply(View *view, uint8_t command); |
| 100 | bool sb_view_style(View *view, uint8_t place); |
| 101 | int32_t sb_view_style_place(const View *view); |
| 102 | char *sb_view_correction(const View *view); |
| 103 | bool sb_view_correct(View *view, uint8_t command, const char *text); |
| 104 | char *sb_view_title(const View *view); |
| 105 | bool sb_view_focus_title(View *view); |
| 106 | bool sb_view_find(View *view, const char *query); |
| 107 | bool sb_view_select_paragraph(View *view, const char *id); |
| 108 | char *sb_view_copy(View *view, bool cut); |
| 109 | void sb_view_insert_space(View *view); |
| 110 | void sb_view_set_tool(View *view, uint8_t tool, uint8_t detail, uint32_t section); |
| 111 | bool sb_view_cancel(View *view); |
| 112 | bool sb_view_ink_selection(const View *view, float rect[4]); |
| 113 | char *sb_view_paper(const View *view); |
| 114 | bool sb_view_set_paper(View *view, int16_t red, uint8_t green, uint8_t blue, int8_t ruled); |
| 115 | bool sb_view_set_art(View *view, const char *name); |
| 116 | char *sb_view_page_text(const View *view); |
| 117 | uint8_t *sb_view_pdf(const View *view, float width, float height, const char *section, size_t *length); |
| 118 | void sb_bytes_free(uint8_t *bytes, size_t length); |
| 119 | int8_t sb_view_date_request(View *view, int64_t *seconds); |
| 120 | bool sb_view_change_date(View *view, int64_t seconds, const char *date, const char *time); |
| 121 | bool sb_view_insert_picture(View *view, const uint8_t *bytes, size_t length, float width, float height); |
| 122 | |
| 123 | typedef struct Movie Movie; |
| 124 | uint32_t sb_recording_rate(void); |
| 125 | bool sb_view_start_recording(View *view, bool video, const char *date, const char *time); |
| 126 | int64_t sb_view_recording(const View *view, bool *paused); |
| 127 | void sb_view_pause_recording(View *view, bool paused); |
| 128 | bool sb_view_finish_recording(View *view, const uint8_t *bytes, size_t length, bool video); |
| 129 | char *sb_view_play_request(View *view, const char *folder); |
| 130 | bool sb_view_played(View *view, int64_t at_ms); |
| 131 | Movie *sb_movie_new(void); |
| 132 | void sb_movie_picture(Movie *movie, uint64_t at_us, const uint8_t *bgra, uint32_t width, uint32_t height, |
| 133 | size_t stride); |
| 134 | void sb_movie_sound(Movie *movie, const uint8_t *pcm, size_t length); |
| 135 | uint8_t *sb_movie_finish(Movie *movie, uint64_t duration_us, size_t *length); |
| 136 | |
| 137 | uint32_t sb_text_length(const View *view); |
| 138 | char *sb_text(const View *view, uint32_t start, uint32_t end); |
| 139 | void sb_selection(const View *view, uint32_t range[2]); |
| 140 | bool sb_select(View *view, uint32_t start, uint32_t end); |
| 141 | bool sb_select_more(View *view); |
| 142 | bool sb_marked(const View *view, uint32_t range[2]); |
| 143 | bool sb_set_marked(View *view, const char *text, uint32_t selected_start, uint32_t selected_end); |
| 144 | void sb_unmark(View *view); |
| 145 | bool sb_insert(View *view, const char *text); |
| 146 | bool sb_replace(View *view, uint32_t start, uint32_t end, const char *text); |
| 147 | bool sb_paste(View *view, const char *text, const char *language); |
| 148 | bool sb_delete_backward(View *view); |
| 149 | bool sb_caret_rect(const View *view, uint32_t offset, float rect[4]); |
| 150 | size_t sb_range_rects(const View *view, uint32_t start, uint32_t end, float (*rects)[4], size_t capacity); |
| 151 | uint32_t sb_closest(const View *view, float x, float y); |