|
@@ -7,51 +7,49 @@ import "base:runtime"
|
|
import "core:strings"
|
|
import "core:strings"
|
|
import "core:mem"
|
|
import "core:mem"
|
|
|
|
|
|
-read_from_clipboard :: proc(wnd_handle: win32.HWND, allocator: runtime.Allocator) -> (result: string, ok: win32.BOOL)
|
|
|
|
-{
|
|
|
|
- win32.IsClipboardFormatAvailable(win32.CF_TEXT) or_return;
|
|
|
|
|
|
+read_from_clipboard :: proc(wnd_handle: win32.HWND, allocator: runtime.Allocator) -> (result: string, ok: win32.BOOL) {
|
|
|
|
+ win32.IsClipboardFormatAvailable(win32.CF_TEXT) or_return
|
|
|
|
|
|
- win32.OpenClipboard(wnd_handle) or_return;
|
|
|
|
- defer win32.CloseClipboard();
|
|
|
|
|
|
+ win32.OpenClipboard(wnd_handle) or_return
|
|
|
|
+ defer win32.CloseClipboard()
|
|
|
|
|
|
- clipboard_data := win32.GetClipboardData(win32.CF_TEXT);
|
|
|
|
|
|
+ clipboard_data := win32.GetClipboardData(win32.CF_TEXT)
|
|
if clipboard_data != nil {
|
|
if clipboard_data != nil {
|
|
if cstr := cstring(win32.GlobalLock(win32.HGLOBAL(clipboard_data))); cstr != nil {
|
|
if cstr := cstring(win32.GlobalLock(win32.HGLOBAL(clipboard_data))); cstr != nil {
|
|
- result = strings.clone_from_cstring(cstr, allocator);
|
|
|
|
- ok = true;
|
|
|
|
|
|
+ result = strings.clone_from_cstring(cstr, allocator)
|
|
|
|
+ ok = true
|
|
}
|
|
}
|
|
- win32.GlobalUnlock(win32.HGLOBAL(clipboard_data));
|
|
|
|
|
|
+ win32.GlobalUnlock(win32.HGLOBAL(clipboard_data))
|
|
}
|
|
}
|
|
- return;
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
-write_to_clipboard :: proc(wnd_handle: win32.HWND, text: string) -> win32.BOOL
|
|
|
|
-{
|
|
|
|
- win32.OpenClipboard(wnd_handle) or_return;
|
|
|
|
- defer win32.CloseClipboard();
|
|
|
|
- win32.EmptyClipboard();
|
|
|
|
|
|
+write_to_clipboard :: proc(wnd_handle: win32.HWND, text: string) -> win32.BOOL {
|
|
|
|
+ win32.OpenClipboard(wnd_handle) or_return
|
|
|
|
+ defer win32.CloseClipboard()
|
|
|
|
+ win32.EmptyClipboard()
|
|
|
|
|
|
- h_mem := win32.HGLOBAL(win32.GlobalAlloc(win32.GMEM_MOVEABLE, len(text) + 1));
|
|
|
|
- if h_mem == nil {return false};
|
|
|
|
|
|
+ h_mem := win32.HGLOBAL(win32.GlobalAlloc(win32.GMEM_MOVEABLE, len(text) + 1))
|
|
|
|
+ if h_mem == nil {return false}
|
|
|
|
|
|
- cstr_dst := cast([^]u8)win32.GlobalLock(h_mem);
|
|
|
|
- defer win32.GlobalUnlock(h_mem);
|
|
|
|
- if cstr_dst == nil {return false};
|
|
|
|
|
|
+ cstr_dst := cast([^]u8)win32.GlobalLock(h_mem)
|
|
|
|
+ defer win32.GlobalUnlock(h_mem)
|
|
|
|
+ if cstr_dst == nil {return false}
|
|
|
|
|
|
- mem.copy(rawptr(cstr_dst), raw_data(text), len(text));
|
|
|
|
- cstr_dst[len(text)] = 0;
|
|
|
|
|
|
+ mem.copy(rawptr(cstr_dst), raw_data(text), len(text))
|
|
|
|
+ cstr_dst[len(text)] = 0
|
|
|
|
|
|
- win32.SetClipboardData(win32.CF_TEXT, win32.HANDLE(h_mem));
|
|
|
|
- return true;
|
|
|
|
|
|
+ win32.SetClipboardData(win32.CF_TEXT, win32.HANDLE(h_mem))
|
|
|
|
+ return true
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@(test)
|
|
@(test)
|
|
verify_win32_clipboard :: proc(t: ^testing.T) {
|
|
verify_win32_clipboard :: proc(t: ^testing.T) {
|
|
- ok1 := write_to_clipboard(nil, "Hello everynyan! OH MY GAH");
|
|
|
|
- testing.expect_value(t, ok1, true);
|
|
|
|
|
|
+ ok1 := write_to_clipboard(nil, "Hello everynyan! OH MY GAH")
|
|
|
|
+ testing.expect_value(t, ok1, true)
|
|
|
|
|
|
- clipboard_content, ok2 := read_from_clipboard(nil, context.temp_allocator);
|
|
|
|
- testing.expect_value(t, ok2, true);
|
|
|
|
- testing.expect_value(t, clipboard_content, "Hello everynyan! OH MY GAH");
|
|
|
|
|
|
+ clipboard_content, ok2 := read_from_clipboard(nil, context.temp_allocator)
|
|
|
|
+ testing.expect_value(t, ok2, true)
|
|
|
|
+ testing.expect_value(t, clipboard_content, "Hello everynyan! OH MY GAH")
|
|
}
|
|
}
|