From 20696247fd58fc57bbe092dac0d2914ea6954ee6 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Sun, 3 Aug 2025 22:42:44 +0200 Subject: [PATCH] Fix copy paste --- base/sources/backends/macos_system.m | 4 +--- base/sources/backends/windows_system.c | 12 +----------- base/sources/iron.h | 15 +++------------ base/sources/ts/iron/iron.ts | 1 - 4 files changed, 5 insertions(+), 27 deletions(-) diff --git a/base/sources/backends/macos_system.m b/base/sources/backends/macos_system.m index 69fed679..cdd94881 100644 --- a/base/sources/backends/macos_system.m +++ b/base/sources/backends/macos_system.m @@ -179,9 +179,7 @@ static bool cmd = false; if (ch == 'c' && [theEvent modifierFlags] & NSCommandKeyMask) { char *text = iron_internal_copy_callback(); if (text != NULL) { - NSPasteboard *board = [NSPasteboard generalPasteboard]; - [board clearContents]; - [board setString:[NSString stringWithUTF8String:text] forType:NSStringPboardType]; + iron_copy_to_clipboard(text); } } if (ch == 'v' && [theEvent modifierFlags] & NSCommandKeyMask) { diff --git a/base/sources/backends/windows_system.c b/base/sources/backends/windows_system.c index b17353b9..acf2752e 100644 --- a/base/sources/backends/windows_system.c +++ b/base/sources/backends/windows_system.c @@ -692,17 +692,7 @@ LRESULT WINAPI IronWindowsMessageProcedure(HWND hWnd, UINT msg, WPARAM wParam, L if (controlDown && keyTranslated[wParam] == IRON_KEY_C) { char *text = iron_internal_copy_callback(); if (text != NULL) { - wchar_t wtext[4096]; - MultiByteToWideChar(CP_UTF8, 0, text, -1, wtext, 4096); - OpenClipboard(hWnd); - EmptyClipboard(); - size_t size = (wcslen(wtext) + 1) * sizeof(wchar_t); - HANDLE handle = GlobalAlloc(GMEM_MOVEABLE, size); - void *data = GlobalLock(handle); - memcpy(data, wtext, size); - GlobalUnlock(handle); - SetClipboardData(CF_UNICODETEXT, handle); - CloseClipboard(); + iron_copy_to_clipboard(text); } } diff --git a/base/sources/iron.h b/base/sources/iron.h index eaad21e0..087d6a6b 100644 --- a/base/sources/iron.h +++ b/base/sources/iron.h @@ -216,9 +216,6 @@ struct HWND__ *iron_windows_window_handle(); void (*iron_update)(void); void (*iron_drop_files)(char *); -char *(*iron_cut)(void *); -char *(*iron_copy)(void *); -void (*iron_paste)(char *, void *); void (*iron_foreground)(void); void (*iron_resume)(void); void (*iron_pause)(void); @@ -822,6 +819,9 @@ void _iron_init(iron_window_options_t *ops) { ops->color_bits = 32; iron_init(ops->title, ops->width, ops->height, ops); iron_random_init((int)(iron_time() * 1000)); + iron_set_cut_callback(_cut, NULL); + iron_set_copy_callback(_copy, NULL); + iron_set_paste_callback(_paste, NULL); #ifdef IRON_WINDOWS // Maximized window has x < -1, prevent window centering @@ -850,15 +850,6 @@ void _iron_set_drop_files_callback(void (*callback)(char *)) { iron_set_drop_files_callback(_drop_files, NULL); } -void iron_set_cut_copy_paste_callback(char *(*on_cut)(void *), char *(*on_copy)(void *), void (*on_paste)(char *, void *)) { - iron_set_cut_callback(_cut, NULL); - iron_set_copy_callback(_copy, NULL); - iron_set_paste_callback(_paste, NULL); - iron_cut = on_cut; - iron_copy = on_copy; - iron_paste = on_paste; -} - void iron_set_application_state_callback(void (*on_foreground)(void), void (*on_resume)(void), void (*on_pause)(void), void (*on_background)(void), void (*on_shutdown)(void)) { iron_set_foreground_callback(on_foreground != NULL ? _foreground : NULL, NULL); iron_set_resume_callback(on_resume != NULL ? _resume : NULL, NULL); diff --git a/base/sources/ts/iron/iron.ts b/base/sources/ts/iron/iron.ts index 5789b4ba..d3c00901 100644 --- a/base/sources/ts/iron/iron.ts +++ b/base/sources/ts/iron/iron.ts @@ -186,7 +186,6 @@ declare function iron_set_app_name(name: string): void; declare function iron_log(v: any): void; declare function _iron_set_update_callback(callback: ()=>void): void; declare function _iron_set_drop_files_callback(callback: (file: string)=>void): void; -declare function iron_set_cut_copy_paste_callback(on_cut: ()=>string, on_copy: ()=>string, on_paste: (text: string)=>void): void; declare function iron_set_application_state_callback(on_foreground: ()=>void, on_resume: ()=>void, on_pause: ()=>void, on_background: ()=>void, on_shutdown: ()=>void): void; declare function iron_set_keyboard_down_callback(callback: (code: i32)=>void): void; declare function iron_set_keyboard_up_callback(callback: (code: i32)=>void): void;