Readd emscripten paste by event
This commit is contained in:
parent
d57d2f4752
commit
716f9222dc
2 changed files with 35 additions and 7 deletions
|
|
@ -20,7 +20,8 @@ namespace emscripten_browser_clipboard {
|
|||
using paste_handler = void(*)(std::string&&, void*);
|
||||
using copy_handler = char const*(*)(void*);
|
||||
|
||||
inline void paste(paste_handler callback, void *callback_data = nullptr);
|
||||
inline void paste_event(paste_handler callback, void *callback_data = nullptr);
|
||||
inline void paste_async(paste_handler callback, void *callback_data = nullptr);
|
||||
inline void copy(copy_handler callback, void *callback_data = nullptr);
|
||||
inline void copy(std::string const &content);
|
||||
|
||||
|
|
@ -28,7 +29,13 @@ inline void copy(std::string const &content);
|
|||
|
||||
namespace detail {
|
||||
|
||||
EM_JS_INLINE(void, paste_js, (paste_handler callback, void *callback_data), {
|
||||
EM_JS_INLINE(void, paste_event_js, (paste_handler callback, void *callback_data), {
|
||||
document.addEventListener('paste', (event) => {
|
||||
Module["ccall"]('emscripten_browser_clipboard_detail_paste_return', 'number', ['string', 'number', 'number'], [event.clipboardData.getData('text/plain'), callback, callback_data]);
|
||||
});
|
||||
});
|
||||
|
||||
EM_JS_INLINE(void, paste_async_js, (paste_handler callback, void *callback_data), {
|
||||
/// Register the given callback to handle paste events. Callback data pointer is passed through to the callback.
|
||||
/// Paste handler callback signature is:
|
||||
/// void my_handler(std::string const &paste_data, void *callback_data = nullptr);
|
||||
|
|
@ -59,9 +66,14 @@ EM_JS_INLINE(void, copy_async_js, (char const *content_ptr), {
|
|||
|
||||
} // namespace detail
|
||||
|
||||
inline void paste(paste_handler callback, void *callback_data) {
|
||||
inline void paste_event(paste_handler callback, void *callback_data) {
|
||||
/// C++ wrapper for javascript paste call
|
||||
detail::paste_js(callback, callback_data);
|
||||
detail::paste_event_js(callback, callback_data);
|
||||
}
|
||||
|
||||
inline void paste_async(paste_handler callback, void *callback_data) {
|
||||
/// C++ wrapper for javascript paste call
|
||||
detail::paste_async_js(callback, callback_data);
|
||||
}
|
||||
|
||||
inline void copy(copy_handler callback, void *callback_data) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue