mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-11-04 07:01:04 +01:00 
			
		
		
		
	Added a void* user_data parameter to Clipboard function handlers. (#875)
This commit is contained in:
		
							
								
								
									
										25
									
								
								imgui.cpp
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								imgui.cpp
									
									
									
									
									
								
							@@ -150,6 +150,7 @@
 | 
			
		||||
 Here is a change-log of API breaking changes, if you are using one of the functions listed, expect to have to fix some code.
 | 
			
		||||
 Also read releases logs https://github.com/ocornut/imgui/releases for more details.
 | 
			
		||||
 | 
			
		||||
 - 2016/10/15 (1.50) - avoid 'void* user_data' parameter to io.SetClipboardTextFn/io.GetClipboardTextFn pointers. We pass io.ClipboardUserData to it.
 | 
			
		||||
 - 2016/09/25 (1.50) - style.WindowTitleAlign is now a ImVec2 (ImGuiAlign enum was removed). set to (0.5f,0.5f) for horizontal+vertical centering, (0.0f,0.0f) for upper-left, etc.
 | 
			
		||||
 - 2016/07/30 (1.50) - SameLine(x) with x>0.0f is now relative to left of column/group if any, and not always to left of window. This was sort of always the intent and hopefully breakage should be minimal.
 | 
			
		||||
 - 2016/05/12 (1.49) - title bar (using ImGuiCol_TitleBg/ImGuiCol_TitleBgActive colors) isn't rendered over a window background (ImGuiCol_WindowBg color) anymore. 
 | 
			
		||||
@@ -703,8 +704,8 @@ static bool             DataTypeApplyOpFromText(const char* buf, const char* ini
 | 
			
		||||
// Platform dependent default implementations
 | 
			
		||||
//-----------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
static const char*      GetClipboardTextFn_DefaultImpl();
 | 
			
		||||
static void             SetClipboardTextFn_DefaultImpl(const char* text);
 | 
			
		||||
static const char*      GetClipboardTextFn_DefaultImpl(void* user_data);
 | 
			
		||||
static void             SetClipboardTextFn_DefaultImpl(void* user_data, const char* text);
 | 
			
		||||
static void             ImeSetInputScreenPosFn_DefaultImpl(int x, int y);
 | 
			
		||||
 | 
			
		||||
//-----------------------------------------------------------------------------
 | 
			
		||||
@@ -829,6 +830,7 @@ ImGuiIO::ImGuiIO()
 | 
			
		||||
    MemFreeFn = free;
 | 
			
		||||
    GetClipboardTextFn = GetClipboardTextFn_DefaultImpl;   // Platform dependent default implementations
 | 
			
		||||
    SetClipboardTextFn = SetClipboardTextFn_DefaultImpl;
 | 
			
		||||
    ClipboardUserData = NULL;
 | 
			
		||||
    ImeSetInputScreenPosFn = ImeSetInputScreenPosFn_DefaultImpl;
 | 
			
		||||
 | 
			
		||||
    // Set OS X style defaults based on __APPLE__ compile time flag
 | 
			
		||||
@@ -2010,13 +2012,13 @@ void ImGui::MemFree(void* ptr)
 | 
			
		||||
 | 
			
		||||
const char* ImGui::GetClipboardText()
 | 
			
		||||
{
 | 
			
		||||
    return GImGui->IO.GetClipboardTextFn ? GImGui->IO.GetClipboardTextFn() : "";
 | 
			
		||||
    return GImGui->IO.GetClipboardTextFn ? GImGui->IO.GetClipboardTextFn(GImGui->IO.ClipboardUserData) : "";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ImGui::SetClipboardText(const char* text)
 | 
			
		||||
{
 | 
			
		||||
    if (GImGui->IO.SetClipboardTextFn)
 | 
			
		||||
        GImGui->IO.SetClipboardTextFn(text);
 | 
			
		||||
        GImGui->IO.SetClipboardTextFn(GImGui->IO.ClipboardUserData, text);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const char* ImGui::GetVersion()
 | 
			
		||||
@@ -5796,8 +5798,7 @@ void ImGui::LogFinish()
 | 
			
		||||
    }
 | 
			
		||||
    if (g.LogClipboard->size() > 1)
 | 
			
		||||
    {
 | 
			
		||||
        if (g.IO.SetClipboardTextFn)
 | 
			
		||||
            g.IO.SetClipboardTextFn(g.LogClipboard->begin());
 | 
			
		||||
        SetClipboardText(g.LogClipboard->begin());
 | 
			
		||||
        g.LogClipboard->clear();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -7859,7 +7860,7 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
 | 
			
		||||
                const int ie = edit_state.HasSelection() ? ImMax(edit_state.StbState.select_start, edit_state.StbState.select_end) : edit_state.CurLenW;
 | 
			
		||||
                edit_state.TempTextBuffer.resize((ie-ib) * 4 + 1);
 | 
			
		||||
                ImTextStrToUtf8(edit_state.TempTextBuffer.Data, edit_state.TempTextBuffer.Size, edit_state.Text.Data+ib, edit_state.Text.Data+ie);
 | 
			
		||||
                io.SetClipboardTextFn(edit_state.TempTextBuffer.Data);
 | 
			
		||||
                SetClipboardText(edit_state.TempTextBuffer.Data);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (cut)
 | 
			
		||||
@@ -7871,7 +7872,7 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
 | 
			
		||||
        else if (is_shortcut_key_only && IsKeyPressedMap(ImGuiKey_V) && is_editable)
 | 
			
		||||
        {
 | 
			
		||||
            // Paste
 | 
			
		||||
            if (const char* clipboard = io.GetClipboardTextFn ? io.GetClipboardTextFn() : NULL)
 | 
			
		||||
            if (const char* clipboard = GetClipboardText())
 | 
			
		||||
            {
 | 
			
		||||
                // Filter pasted buffer
 | 
			
		||||
                const int clipboard_len = (int)strlen(clipboard);
 | 
			
		||||
@@ -9565,7 +9566,7 @@ void ImGui::ValueColor(const char* prefix, ImU32 v)
 | 
			
		||||
#pragma comment(lib, "user32")
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
static const char* GetClipboardTextFn_DefaultImpl()
 | 
			
		||||
static const char* GetClipboardTextFn_DefaultImpl(void*)
 | 
			
		||||
{
 | 
			
		||||
    static ImVector<char> buf_local;
 | 
			
		||||
    buf_local.clear();
 | 
			
		||||
@@ -9585,7 +9586,7 @@ static const char* GetClipboardTextFn_DefaultImpl()
 | 
			
		||||
    return buf_local.Data;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void SetClipboardTextFn_DefaultImpl(const char* text)
 | 
			
		||||
static void SetClipboardTextFn_DefaultImpl(void*, const char* text)
 | 
			
		||||
{
 | 
			
		||||
    if (!OpenClipboard(NULL))
 | 
			
		||||
        return;
 | 
			
		||||
@@ -9604,13 +9605,13 @@ static void SetClipboardTextFn_DefaultImpl(const char* text)
 | 
			
		||||
#else
 | 
			
		||||
 | 
			
		||||
// Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers
 | 
			
		||||
static const char* GetClipboardTextFn_DefaultImpl()
 | 
			
		||||
static const char* GetClipboardTextFn_DefaultImpl(void*)
 | 
			
		||||
{
 | 
			
		||||
    return GImGui->PrivateClipboard;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers
 | 
			
		||||
static void SetClipboardTextFn_DefaultImpl(const char* text)
 | 
			
		||||
static void SetClipboardTextFn_DefaultImpl(void*, const char* text)
 | 
			
		||||
{
 | 
			
		||||
    ImGuiContext& g = *GImGui;
 | 
			
		||||
    if (g.PrivateClipboard)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user