update widgets, add copy paste buffer
This commit is contained in:
@@ -206,3 +206,51 @@ PlatformInputEvents platform_get_input_events(PlatformWindow *window) {
|
||||
window->input_events = {};
|
||||
return result;
|
||||
}
|
||||
|
||||
void platform_clipboard_set(const char *text) {
|
||||
if (!text) return;
|
||||
int len = (int)strlen(text);
|
||||
if (len == 0) return;
|
||||
|
||||
// Convert UTF-8 to wide string for Windows clipboard
|
||||
int wlen = MultiByteToWideChar(CP_UTF8, 0, text, len, nullptr, 0);
|
||||
if (wlen == 0) return;
|
||||
|
||||
HGLOBAL hmem = GlobalAlloc(GMEM_MOVEABLE, (wlen + 1) * sizeof(wchar_t));
|
||||
if (!hmem) return;
|
||||
|
||||
wchar_t *wbuf = (wchar_t *)GlobalLock(hmem);
|
||||
MultiByteToWideChar(CP_UTF8, 0, text, len, wbuf, wlen);
|
||||
wbuf[wlen] = L'\0';
|
||||
GlobalUnlock(hmem);
|
||||
|
||||
HWND hwnd = g_current_window ? g_current_window->hwnd : nullptr;
|
||||
if (OpenClipboard(hwnd)) {
|
||||
EmptyClipboard();
|
||||
SetClipboardData(CF_UNICODETEXT, hmem);
|
||||
CloseClipboard();
|
||||
} else {
|
||||
GlobalFree(hmem);
|
||||
}
|
||||
}
|
||||
|
||||
const char *platform_clipboard_get() {
|
||||
static char buf[4096];
|
||||
buf[0] = '\0';
|
||||
|
||||
HWND hwnd = g_current_window ? g_current_window->hwnd : nullptr;
|
||||
if (!OpenClipboard(hwnd)) return nullptr;
|
||||
|
||||
HGLOBAL hmem = GetClipboardData(CF_UNICODETEXT);
|
||||
if (hmem) {
|
||||
wchar_t *wbuf = (wchar_t *)GlobalLock(hmem);
|
||||
if (wbuf) {
|
||||
int len = WideCharToMultiByte(CP_UTF8, 0, wbuf, -1, buf, sizeof(buf) - 1, nullptr, nullptr);
|
||||
buf[len > 0 ? len - 1 : 0] = '\0'; // WideCharToMultiByte includes null in count
|
||||
GlobalUnlock(hmem);
|
||||
}
|
||||
}
|
||||
|
||||
CloseClipboard();
|
||||
return buf[0] ? buf : nullptr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user