ci: fix clipboard_test.v on windows

pull/7853/head
Delyan Angelov 2021-01-03 22:30:35 +02:00
parent 760de7c811
commit 9b43b6833b
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 6 additions and 5 deletions

View File

@ -2,6 +2,7 @@ module clipboard
import time import time
#include <windows.h>
#flag -lUser32 #flag -lUser32
struct WndClassEx { struct WndClassEx {
cb_size u32 cb_size u32
@ -103,11 +104,11 @@ fn new_clipboard() &Clipboard {
} }
fn (cb &Clipboard) check_availability() bool { fn (cb &Clipboard) check_availability() bool {
return cb.hwnd != C.HWND(C.NULL) return voidptr(cb.hwnd) != voidptr(0)
} }
fn (cb &Clipboard) has_ownership() bool { fn (cb &Clipboard) has_ownership() bool {
return C.GetClipboardOwner() == cb.hwnd return voidptr(C.GetClipboardOwner()) == voidptr(cb.hwnd)
} }
fn (mut cb Clipboard) clear() { fn (mut cb Clipboard) clear() {
@ -129,7 +130,7 @@ fn to_wide(text string) C.HGLOBAL {
len_required := C.MultiByteToWideChar(C.CP_UTF8, C.MB_ERR_INVALID_CHARS, text.str, len_required := C.MultiByteToWideChar(C.CP_UTF8, C.MB_ERR_INVALID_CHARS, text.str,
text.len + 1, C.NULL, 0) text.len + 1, C.NULL, 0)
buf := C.GlobalAlloc(C.GMEM_MOVEABLE, i64(sizeof(u16)) * len_required) buf := C.GlobalAlloc(C.GMEM_MOVEABLE, i64(sizeof(u16)) * len_required)
if buf != C.HGLOBAL(C.NULL) { if voidptr(buf) != voidptr(0) {
mut locked := &u16(C.GlobalLock(buf)) mut locked := &u16(C.GlobalLock(buf))
C.MultiByteToWideChar(C.CP_UTF8, C.MB_ERR_INVALID_CHARS, text.str, text.len + 1, C.MultiByteToWideChar(C.CP_UTF8, C.MB_ERR_INVALID_CHARS, text.str, text.len + 1,
locked, len_required) locked, len_required)
@ -150,7 +151,7 @@ fn (mut cb Clipboard) set_text(text string) bool {
} else { } else {
// EmptyClipboard must be called to properly update clipboard ownership // EmptyClipboard must be called to properly update clipboard ownership
C.EmptyClipboard() C.EmptyClipboard()
if C.SetClipboardData(C.CF_UNICODETEXT, buf) == C.HANDLE(C.NULL) { if voidptr(C.SetClipboardData(C.CF_UNICODETEXT, buf)) == voidptr(0) {
println('SetClipboardData: Failed.') println('SetClipboardData: Failed.')
C.CloseClipboard() C.CloseClipboard()
C.GlobalFree(buf) C.GlobalFree(buf)
@ -168,7 +169,7 @@ fn (mut cb Clipboard) get_text() string {
return '' return ''
} }
h_data := C.GetClipboardData(C.CF_UNICODETEXT) h_data := C.GetClipboardData(C.CF_UNICODETEXT)
if h_data == C.HANDLE(C.NULL) { if voidptr(h_data) == voidptr(0) {
C.CloseClipboard() C.CloseClipboard()
return '' return ''
} }