ソースを参照

Fix copy paste

luboslenco 1 ヶ月 前
コミット
20696247fd

+ 1 - 3
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) {

+ 1 - 11
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);
 					}
 				}
 

+ 3 - 12
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);

+ 0 - 1
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;