|
| 1 | +// AUTO-GENERATED. DO NOT EDIT. |
| 2 | +// Any manual changes WILL BE LOST when this file is regenerated. |
| 3 | + |
| 4 | +#include "window_drag_session_c.h" |
| 5 | + |
| 6 | +#include <cstdio> |
| 7 | +#include <memory> |
| 8 | +#include <new> |
| 9 | +#include <optional> |
| 10 | +#include <string> |
| 11 | +#include <utility> |
| 12 | +#include <vector> |
| 13 | + |
| 14 | +#include "string_utils_c.h" |
| 15 | +#include "../foundation/handle_table.h" |
| 16 | +#include "../foundation/geometry.h" |
| 17 | +#include "geometry_c.h" |
| 18 | +#include "../window.h" |
| 19 | +#include "window_c.h" |
| 20 | +#include "../window_drag_session.h" |
| 21 | + |
| 22 | +native_window_drag_session_t native_window_drag_session_create(void) { |
| 23 | + try { |
| 24 | + return nativeapi::HandleTable::GetInstance().Insert( |
| 25 | + std::make_shared<nativeapi::WindowDragSession>()); |
| 26 | + } catch (...) { |
| 27 | + fprintf(stderr, "[nativeapi] %s: unexpected exception\n", "native_window_drag_session_create"); |
| 28 | + return 0; |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +bool native_window_drag_session_start(native_window_drag_session_t window_drag_session, native_window_t window, native_point_t anchor) { |
| 33 | + auto self = nativeapi::HandleTable::GetInstance().Resolve<nativeapi::WindowDragSession>(window_drag_session); |
| 34 | + if (!self) { |
| 35 | + return false; |
| 36 | + } |
| 37 | + try { |
| 38 | + auto window_cpp = nativeapi::HandleTable::GetInstance().Resolve<nativeapi::Window>(window); |
| 39 | + auto anchor_cpp = to_cpp_point(anchor); |
| 40 | + return self->Start(window_cpp, anchor_cpp); |
| 41 | + } catch (...) { |
| 42 | + fprintf(stderr, "[nativeapi] %s: unexpected exception\n", "native_window_drag_session_start"); |
| 43 | + return false; |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +void native_window_drag_session_cancel(native_window_drag_session_t window_drag_session) { |
| 48 | + auto self = nativeapi::HandleTable::GetInstance().Resolve<nativeapi::WindowDragSession>(window_drag_session); |
| 49 | + if (!self) { |
| 50 | + return; |
| 51 | + } |
| 52 | + try { |
| 53 | + self->Cancel(); |
| 54 | + return; |
| 55 | + } catch (...) { |
| 56 | + fprintf(stderr, "[nativeapi] %s: unexpected exception\n", "native_window_drag_session_cancel"); |
| 57 | + return; |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +bool native_window_drag_session_is_active(native_window_drag_session_t window_drag_session) { |
| 62 | + auto self = nativeapi::HandleTable::GetInstance().Resolve<nativeapi::WindowDragSession>(window_drag_session); |
| 63 | + if (!self) { |
| 64 | + return false; |
| 65 | + } |
| 66 | + try { |
| 67 | + return self->IsActive(); |
| 68 | + } catch (...) { |
| 69 | + fprintf(stderr, "[nativeapi] %s: unexpected exception\n", "native_window_drag_session_is_active"); |
| 70 | + return false; |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +native_window_id_t native_window_drag_session_get_window_id(native_window_drag_session_t window_drag_session) { |
| 75 | + auto self = nativeapi::HandleTable::GetInstance().Resolve<nativeapi::WindowDragSession>(window_drag_session); |
| 76 | + if (!self) { |
| 77 | + return 0; |
| 78 | + } |
| 79 | + try { |
| 80 | + return self->GetWindowId(); |
| 81 | + } catch (...) { |
| 82 | + fprintf(stderr, "[nativeapi] %s: unexpected exception\n", "native_window_drag_session_get_window_id"); |
| 83 | + return 0; |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +native_point_t native_window_drag_session_get_anchor(native_window_drag_session_t window_drag_session) { |
| 88 | + auto self = nativeapi::HandleTable::GetInstance().Resolve<nativeapi::WindowDragSession>(window_drag_session); |
| 89 | + if (!self) { |
| 90 | + native_point_t result = {}; |
| 91 | + return result; |
| 92 | + } |
| 93 | + try { |
| 94 | + const auto cpp_result = self->GetAnchor(); |
| 95 | + return to_c_point(cpp_result); |
| 96 | + } catch (...) { |
| 97 | + fprintf(stderr, "[nativeapi] %s: unexpected exception\n", "native_window_drag_session_get_anchor"); |
| 98 | + native_point_t result = {}; |
| 99 | + return result; |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | +void native_window_drag_session_free(native_window_drag_session_t window_drag_session) { |
| 104 | + // The table invalidates the handle itself, so releasing an unknown or |
| 105 | + // already-released one is a no-op rather than a double free. |
| 106 | + nativeapi::HandleTable::GetInstance().Release(window_drag_session); |
| 107 | +} |
| 108 | + |
| 109 | +native_listener_id_t native_window_drag_session_add_listener(native_window_drag_session_t window_drag_session, native_window_drag_event_callback_t callback, void* user_data) { |
| 110 | + if (!callback) { |
| 111 | + return 0; |
| 112 | + } |
| 113 | + auto self = nativeapi::HandleTable::GetInstance().Resolve<nativeapi::WindowDragSession>(window_drag_session); |
| 114 | + if (!self) { |
| 115 | + return 0; |
| 116 | + } |
| 117 | + try { |
| 118 | + return static_cast<native_listener_id_t>(self->AddListener<nativeapi::WindowDragEvent>( |
| 119 | + [callback, user_data](const nativeapi::WindowDragEvent& event) { |
| 120 | + native_window_drag_event_t c_event = {}; |
| 121 | + if (!to_c_window_drag_event(event, &c_event)) { |
| 122 | + return; |
| 123 | + } |
| 124 | + callback(&c_event, user_data); |
| 125 | + free_c_window_drag_event(&c_event); |
| 126 | + })); |
| 127 | + } catch (...) { |
| 128 | + return 0; |
| 129 | + } |
| 130 | +} |
| 131 | + |
| 132 | +bool native_window_drag_session_remove_listener(native_window_drag_session_t window_drag_session, native_listener_id_t listener_id) { |
| 133 | + auto self = nativeapi::HandleTable::GetInstance().Resolve<nativeapi::WindowDragSession>(window_drag_session); |
| 134 | + if (!self) { |
| 135 | + return false; |
| 136 | + } |
| 137 | + try { |
| 138 | + return self->RemoveListener(static_cast<size_t>(listener_id)); |
| 139 | + } catch (...) { |
| 140 | + return false; |
| 141 | + } |
| 142 | +} |
| 143 | + |
| 144 | +bool to_c_window_drag_event(const nativeapi::WindowDragEvent& event, native_window_drag_event_t* out) { |
| 145 | + if (!out) { |
| 146 | + return false; |
| 147 | + } |
| 148 | + *out = native_window_drag_event_t{}; |
| 149 | + out->window_id = event.GetWindowId(); |
| 150 | + out->cursor_position = to_c_point(event.GetCursorPosition()); |
| 151 | + if (const auto* typed = dynamic_cast<const nativeapi::WindowDragMovedEvent*>(&event)) { |
| 152 | + out->type = NATIVE_WINDOW_DRAG_EVENT_TYPE_MOVED; |
| 153 | + (void)typed; |
| 154 | + return true; |
| 155 | + } |
| 156 | + if (const auto* typed = dynamic_cast<const nativeapi::WindowDragEndedEvent*>(&event)) { |
| 157 | + out->type = NATIVE_WINDOW_DRAG_EVENT_TYPE_ENDED; |
| 158 | + (void)typed; |
| 159 | + return true; |
| 160 | + } |
| 161 | + if (const auto* typed = dynamic_cast<const nativeapi::WindowDragCancelledEvent*>(&event)) { |
| 162 | + out->type = NATIVE_WINDOW_DRAG_EVENT_TYPE_CANCELLED; |
| 163 | + (void)typed; |
| 164 | + return true; |
| 165 | + } |
| 166 | + return false; |
| 167 | +} |
| 168 | + |
| 169 | +void free_c_window_drag_event(native_window_drag_event_t* value) { |
| 170 | + if (!value) { |
| 171 | + return; |
| 172 | + } |
| 173 | +} |
| 174 | + |
0 commit comments