mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
Default clipboard handlers for Windows handle UTF-8 (the glfw ones already did that)
This commit is contained in:
parent
6e12d31417
commit
0eeb6228b9
31
imgui.cpp
31
imgui.cpp
@ -8251,12 +8251,16 @@ static const char* GetClipboardTextFn_DefaultImpl()
|
|||||||
}
|
}
|
||||||
if (!OpenClipboard(NULL))
|
if (!OpenClipboard(NULL))
|
||||||
return NULL;
|
return NULL;
|
||||||
HANDLE buf_handle = GetClipboardData(CF_TEXT);
|
HANDLE wbuf_handle = GetClipboardData(CF_UNICODETEXT);
|
||||||
if (buf_handle == NULL)
|
if (wbuf_handle == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (char* buf_global = (char*)GlobalLock(buf_handle))
|
if (ImWchar* wbuf_global = (ImWchar*)GlobalLock(wbuf_handle))
|
||||||
buf_local = ImStrdup(buf_global);
|
{
|
||||||
GlobalUnlock(buf_handle);
|
int buf_len = ImTextCountUtf8BytesFromWchar(wbuf_global, NULL) + 1;
|
||||||
|
buf_local = (char*)ImGui::MemAlloc(buf_len * sizeof(char));
|
||||||
|
ImTextStrToUtf8(buf_local, buf_len, wbuf_global, NULL);
|
||||||
|
}
|
||||||
|
GlobalUnlock(wbuf_handle);
|
||||||
CloseClipboard();
|
CloseClipboard();
|
||||||
return buf_local;
|
return buf_local;
|
||||||
}
|
}
|
||||||
@ -8266,17 +8270,16 @@ static void SetClipboardTextFn_DefaultImpl(const char* text)
|
|||||||
{
|
{
|
||||||
if (!OpenClipboard(NULL))
|
if (!OpenClipboard(NULL))
|
||||||
return;
|
return;
|
||||||
const char* text_end = text + strlen(text);
|
|
||||||
const int buf_length = (int)(text_end - text) + 1;
|
const int wbuf_length = ImTextCountCharsFromUtf8(text, NULL) + 1;
|
||||||
HGLOBAL buf_handle = GlobalAlloc(GMEM_MOVEABLE, (SIZE_T)buf_length * sizeof(char));
|
HGLOBAL wbuf_handle = GlobalAlloc(GMEM_MOVEABLE, (SIZE_T)wbuf_length * sizeof(ImWchar));
|
||||||
if (buf_handle == NULL)
|
if (wbuf_handle == NULL)
|
||||||
return;
|
return;
|
||||||
char* buf_global = (char *)GlobalLock(buf_handle);
|
ImWchar* wbuf_global = (ImWchar*)GlobalLock(wbuf_handle);
|
||||||
memcpy(buf_global, text, (size_t)(text_end - text));
|
ImTextStrFromUtf8(wbuf_global, wbuf_length, text, NULL);
|
||||||
buf_global[text_end - text] = 0;
|
GlobalUnlock(wbuf_handle);
|
||||||
GlobalUnlock(buf_handle);
|
|
||||||
EmptyClipboard();
|
EmptyClipboard();
|
||||||
SetClipboardData(CF_TEXT, buf_handle);
|
SetClipboardData(CF_UNICODETEXT, wbuf_handle);
|
||||||
CloseClipboard();
|
CloseClipboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user