diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 2cd044cf4..7c0baaffe 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -206,6 +206,15 @@ namespace MWGui mVideoWidget = mVideoBackground->createWidgetReal("ImageBox", 0,0,1,1, MyGUI::Align::Default); mVideoWidget->setNeedMouseFocus(true); mVideoWidget->setNeedKeyFocus(true); + +#if MYGUI_VERSION >= MYGUI_DEFINE_VERSION(3,2,1) + // Removes default MyGUI system clipboard implementation, which supports windows only + MyGUI::ClipboardManager::getInstance().eventClipboardChanged.clear(); + MyGUI::ClipboardManager::getInstance().eventClipboardRequested.clear(); + + MyGUI::ClipboardManager::getInstance().eventClipboardChanged += MyGUI::newDelegate(this, &WindowManager::onClipboardChanged); + MyGUI::ClipboardManager::getInstance().eventClipboardRequested += MyGUI::newDelegate(this, &WindowManager::onClipboardRequested); +#endif } void WindowManager::initUI() @@ -1699,4 +1708,27 @@ namespace MWGui { mScreenFader->setFactor(factor); } + + void WindowManager::onClipboardChanged(const std::string &_type, const std::string &_data) + { + if (_type == "Text") + SDL_SetClipboardText(MyGUI::TextIterator::getOnlyText(MyGUI::UString(_data)).asUTF8().c_str()); + } + + void WindowManager::onClipboardRequested(const std::string &_type, std::string &_data) + { + if (_type != "Text") + return; + char* text=0; + text = SDL_GetClipboardText(); + if (text) + { + // MyGUI's clipboard might still have color information, to retain that information, only set the new text + // if it actually changed (clipboard inserted by an external application) + if (MyGUI::TextIterator::getOnlyText(_data) != text) + _data = text; + } + SDL_free(text); + } + } diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index 598ecd1ee..76bab8fc8 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -448,6 +448,9 @@ namespace MWGui void onVideoKeyPressed(MyGUI::Widget *_sender, MyGUI::KeyCode _key, MyGUI::Char _char); void sizeVideo(int screenWidth, int screenHeight); + + void onClipboardChanged(const std::string& _type, const std::string& _data); + void onClipboardRequested(const std::string& _type, std::string& _data); }; } diff --git a/apps/openmw/mwinput/inputmanagerimp.cpp b/apps/openmw/mwinput/inputmanagerimp.cpp index c07b4760d..7f81d7fcc 100644 --- a/apps/openmw/mwinput/inputmanagerimp.cpp +++ b/apps/openmw/mwinput/inputmanagerimp.cpp @@ -498,6 +498,7 @@ namespace MWInput void InputManager::keyPressed( const SDL_KeyboardEvent &arg ) { +#if MYGUI_VERSION <= MYGUI_DEFINE_VERSION(3,2,0) // Cut, copy & paste MyGUI::Widget* focus = MyGUI::InputManager::getInstance().getKeyFocusWidget(); if (focus) @@ -537,6 +538,7 @@ namespace MWInput } } } +#endif OIS::KeyCode kc = mInputManager->sdl2OISKeyCode(arg.keysym.sym); @@ -550,7 +552,9 @@ namespace MWInput // Clear MyGUI's clipboard, so it doesn't interfere with our own clipboard implementation. // We do not use MyGUI's clipboard manager because it doesn't support system clipboard integration with SDL. +#if MYGUI_VERSION <= MYGUI_DEFINE_VERSION(3,2,0) MyGUI::ClipboardManager::getInstance().clearClipboardData("Text"); +#endif } void InputManager::textInput(const SDL_TextInputEvent &arg)