b4a2edec6a
* Final update copyright headers to reference license files at the repo root Signed-off-by: spham <spham@amazon.com> * Fix copyright validator unit tests to support the stale O3DE header scenario Signed-off-by: spham <spham@amazon.com>
56 lines
1.8 KiB
C++
56 lines
1.8 KiB
C++
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
// UiClipboard is responsible setting and getting clipboard data for the UI elements in a platform-independent way.
|
|
|
|
#include "LyShine_precompiled.h"
|
|
#include "UiClipboard.h"
|
|
#include <AzCore/PlatformIncl.h>
|
|
#include <StringUtils.h>
|
|
|
|
bool UiClipboard::SetText(const AZStd::string& text)
|
|
{
|
|
bool success = false;
|
|
if (OpenClipboard(nullptr))
|
|
{
|
|
if (EmptyClipboard())
|
|
{
|
|
if (text.length() > 0)
|
|
{
|
|
auto wstr = CryStringUtils::UTF8ToWStr(text.c_str());
|
|
const SIZE_T buffSize = (wstr.size() + 1) * sizeof(WCHAR);
|
|
if (HGLOBAL hBuffer = GlobalAlloc(GMEM_MOVEABLE, buffSize))
|
|
{
|
|
auto buffer = static_cast<WCHAR*>(GlobalLock(hBuffer));
|
|
memcpy_s(buffer, buffSize, wstr.data(), wstr.size() * sizeof(wchar_t));
|
|
buffer[wstr.size()] = WCHAR(0);
|
|
GlobalUnlock(hBuffer);
|
|
SetClipboardData(CF_UNICODETEXT, hBuffer); // Clipboard now owns the hBuffer
|
|
success = true;
|
|
}
|
|
}
|
|
}
|
|
CloseClipboard();
|
|
}
|
|
return success;
|
|
}
|
|
|
|
AZStd::string UiClipboard::GetText()
|
|
{
|
|
AZStd::string outText;
|
|
if (OpenClipboard(nullptr))
|
|
{
|
|
if (HANDLE hText = GetClipboardData(CF_UNICODETEXT))
|
|
{
|
|
const WCHAR* text = static_cast<const WCHAR*>(GlobalLock(hText));
|
|
outText = CryStringUtils::WStrToUTF8(text);
|
|
GlobalUnlock(hText);
|
|
}
|
|
CloseClipboard();
|
|
}
|
|
return outText;
|
|
}
|