From cc13d329519054f8f26c1b9043719f17d826303a Mon Sep 17 00:00:00 2001 From: Benau Date: Tue, 2 Jun 2020 10:46:20 +0800 Subject: [PATCH] Use SDL2 clipboard for edit box --- lib/irrlicht/source/Irrlicht/COSOperator.cpp | 59 ++------------------ src/guiengine/widgets/CGUIEditBox.cpp | 19 ++----- 2 files changed, 10 insertions(+), 68 deletions(-) diff --git a/lib/irrlicht/source/Irrlicht/COSOperator.cpp b/lib/irrlicht/source/Irrlicht/COSOperator.cpp index 127474005..25f356dc9 100644 --- a/lib/irrlicht/source/Irrlicht/COSOperator.cpp +++ b/lib/irrlicht/source/Irrlicht/COSOperator.cpp @@ -25,11 +25,8 @@ #include #include "IrrlichtDevice.h" -#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) -#include "CIrrDeviceLinux.h" -#endif -#if defined(_IRR_COMPILE_WITH_WAYLAND_DEVICE_) -#include "CIrrDeviceWayland.h" +#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) +#include "SDL_clipboard.h" #endif #ifdef _IRR_COMPILE_WITH_OSX_DEVICE_ #include "MacOSX/OSXClipboard.h" @@ -124,30 +121,8 @@ void COSOperator::copyToClipboard(const c8* text) const OSXCopyToClipboard(text); -#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_COMPILE_WITH_WAYLAND_DEVICE_) - if (IrrDevice != NULL) - { -#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) - if (IrrDevice->getType() == EIDT_X11) - { - CIrrDeviceLinux* device = dynamic_cast(IrrDevice); - assert(device); - - device->copyToClipboard(text); - } -#endif -#if defined(_IRR_COMPILE_WITH_WAYLAND_DEVICE_) - if (IrrDevice->getType() == EIDT_WAYLAND) - { - CIrrDeviceWayland* device = dynamic_cast(IrrDevice); - assert(device); - - device->copyToClipboard(text); - } -#endif - } -#else - +#elif defined(_IRR_COMPILE_WITH_SDL_DEVICE_) + SDL_SetClipboardText(text); #endif } #endif @@ -199,30 +174,8 @@ const c8* COSOperator::getTextFromClipboard() const -#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_COMPILE_WITH_WAYLAND_DEVICE_) - if (IrrDevice != NULL) - { -#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) - if (IrrDevice->getType() == EIDT_X11) - { - CIrrDeviceLinux* device = dynamic_cast(IrrDevice); - assert(device); - - return device->getTextFromClipboard(); - } -#endif -#if defined(_IRR_COMPILE_WITH_WAYLAND_DEVICE_) - if (IrrDevice->getType() == EIDT_WAYLAND) - { - CIrrDeviceWayland* device = dynamic_cast(IrrDevice); - assert(device); - - return device->getTextFromClipboard(); - } -#endif - } - return 0; - +#elif defined(_IRR_COMPILE_WITH_SDL_DEVICE_) + return SDL_GetClipboardText(); #else return 0; diff --git a/src/guiengine/widgets/CGUIEditBox.cpp b/src/guiengine/widgets/CGUIEditBox.cpp index b35f004c7..8d43a9d52 100644 --- a/src/guiengine/widgets/CGUIEditBox.cpp +++ b/src/guiengine/widgets/CGUIEditBox.cpp @@ -468,11 +468,7 @@ bool CGUIEditBox::processKey(const SEvent& event) const s32 realmend = m_mark_begin < m_mark_end ? m_mark_end : m_mark_begin; std::u32string s = m_edit_text.substr(realmbgn, realmend - realmbgn); -#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_ - Operator->copyToClipboard(StringUtils::utf32ToWide(s).c_str()); -#else Operator->copyToClipboard(StringUtils::utf32ToUtf8(s).c_str()); -#endif } break; case IRR_KEY_X: @@ -484,11 +480,7 @@ bool CGUIEditBox::processKey(const SEvent& event) // copy std::u32string s = m_edit_text.substr(realmbgn, realmend - realmbgn); -#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_ - Operator->copyToClipboard(StringUtils::utf32ToWide(s).c_str()); -#else Operator->copyToClipboard(StringUtils::utf32ToUtf8(s).c_str()); -#endif if (isEnabled()) { @@ -516,13 +508,10 @@ bool CGUIEditBox::processKey(const SEvent& event) const s32 realmend = m_mark_begin < m_mark_end ? m_mark_end : m_mark_begin; // add new character -#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_ - const std::u32string clipboard = - StringUtils::wideToUtf32(Operator->getTextFromClipboard()); -#else - const std::u32string clipboard = - StringUtils::utf8ToUtf32(Operator->getTextFromClipboard()); -#endif + char* clipboard_u8 = (char*)Operator->getTextFromClipboard(); + std::u32string clipboard; + if (clipboard_u8) + clipboard = StringUtils::utf8ToUtf32(clipboard_u8); if (!clipboard.empty()) { if (m_mark_begin == m_mark_end)