Tidying up default clipboard handler for non Windows-OS

This commit is contained in:
ocornut 2016-07-30 10:02:46 +02:00
parent f34d7ea199
commit 20a0fde012
2 changed files with 7 additions and 15 deletions

View File

@ -2833,11 +2833,7 @@ void ImGui::Shutdown()
g.RenderDrawLists[i].clear(); g.RenderDrawLists[i].clear();
g.OverlayDrawList.ClearFreeMemory(); g.OverlayDrawList.ClearFreeMemory();
g.ColorEditModeStorage.Clear(); g.ColorEditModeStorage.Clear();
if (g.PrivateClipboard) g.PrivateClipboard.clear();
{
ImGui::MemFree(g.PrivateClipboard);
g.PrivateClipboard = NULL;
}
g.InputTextState.Text.clear(); g.InputTextState.Text.clear();
g.InputTextState.InitialText.clear(); g.InputTextState.InitialText.clear();
g.InputTextState.TempTextBuffer.clear(); g.InputTextState.TempTextBuffer.clear();
@ -10336,21 +10332,18 @@ static void SetClipboardTextFn_DefaultImpl(const char* text)
// Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers // Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers
static const char* GetClipboardTextFn_DefaultImpl() static const char* GetClipboardTextFn_DefaultImpl()
{ {
return GImGui->PrivateClipboard; ImGuiContext& g = *GImGui;
return g.PrivateClipboard.empty() ? NULL : g.PrivateClipboard.begin();
} }
// Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers // Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers
static void SetClipboardTextFn_DefaultImpl(const char* text) static void SetClipboardTextFn_DefaultImpl(const char* text)
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
if (g.PrivateClipboard) g.PrivateClipboard.clear();
{
ImGui::MemFree(g.PrivateClipboard);
g.PrivateClipboard = NULL;
}
const char* text_end = text + strlen(text); const char* text_end = text + strlen(text);
g.PrivateClipboard = (char*)ImGui::MemAlloc((size_t)(text_end - text) + 1); g.PrivateClipboard.resize((size_t)(text_end - text) + 1);
memcpy(g.PrivateClipboard, text, (size_t)(text_end - text)); memcpy(&g.PrivateClipboard[0], text, (size_t)(text_end - text));
g.PrivateClipboard[(int)(text_end - text)] = 0; g.PrivateClipboard[(int)(text_end - text)] = 0;
} }

View File

@ -467,7 +467,7 @@ struct ImGuiContext
float DragSpeedScaleFast; float DragSpeedScaleFast;
ImVec2 ScrollbarClickDeltaToGrabCenter; // Distance between mouse and center of grab box, normalized in parent space. Use storage? ImVec2 ScrollbarClickDeltaToGrabCenter; // Distance between mouse and center of grab box, normalized in parent space. Use storage?
char Tooltip[1024]; char Tooltip[1024];
char* PrivateClipboard; // If no custom clipboard handler is defined ImVector<char> PrivateClipboard; // If no custom clipboard handler is defined
ImVec2 OsImePosRequest, OsImePosSet; // Cursor position request & last passed to the OS Input Method Editor ImVec2 OsImePosRequest, OsImePosSet; // Cursor position request & last passed to the OS Input Method Editor
// Logging // Logging
@ -554,7 +554,6 @@ struct ImGuiContext
DragSpeedScaleFast = 10.0f; DragSpeedScaleFast = 10.0f;
ScrollbarClickDeltaToGrabCenter = ImVec2(0.0f, 0.0f); ScrollbarClickDeltaToGrabCenter = ImVec2(0.0f, 0.0f);
memset(Tooltip, 0, sizeof(Tooltip)); memset(Tooltip, 0, sizeof(Tooltip));
PrivateClipboard = NULL;
OsImePosRequest = OsImePosSet = ImVec2(-1.0f, -1.0f); OsImePosRequest = OsImePosSet = ImVec2(-1.0f, -1.0f);
ModalWindowDarkeningRatio = 0.0f; ModalWindowDarkeningRatio = 0.0f;