Make use of the system clipboard on all OSes when using SFML >= 2.5

With older SFML versions, the system clipboard will only be accessed on Windows
0.8
Bruno Van de Velde 2017-06-29 18:40:43 +02:00
parent c9f2e74f08
commit 29f6df6bbd
4 changed files with 44 additions and 10 deletions

View File

@ -57,7 +57,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static void set(const sf::String& contents);
#if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 5
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Sets the window handle which is needed to access the system clipboard on windows
///
@ -73,7 +73,7 @@ namespace tgui
static sf::String m_contents;
static sf::WindowHandle m_windowHandle;
static bool m_isWindowHandleSet;
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
};

View File

@ -408,8 +408,10 @@ namespace tgui
// The sfml window or other target to draw on
sf::RenderTarget* m_window;
#if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 5
// Does m_Window contains a sf::RenderWindow?
bool m_accessToWindow;
#endif
// Internal container to store all widgets
GuiContainer::Ptr m_container = std::make_shared<GuiContainer>();

View File

@ -26,9 +26,13 @@
#include <TGUI/Clipboard.hpp>
#if SFML_VERSION_MAJOR > 2 || (SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR >= 5)
#include <SFML/Window/Clipboard.hpp>
#else
#ifdef SFML_SYSTEM_WINDOWS
#include <windows.h>
#endif
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -36,14 +40,19 @@ namespace tgui
{
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 5
sf::String Clipboard::m_contents;
sf::WindowHandle Clipboard::m_windowHandle = sf::WindowHandle();
bool Clipboard::m_isWindowHandleSet = false;
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
sf::String Clipboard::get()
{
#if SFML_VERSION_MAJOR > 2 || (SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR >= 5)
return sf::Clipboard::getString();
#else
#ifdef SFML_SYSTEM_WINDOWS
if (m_isWindowHandleSet)
{
@ -67,12 +76,16 @@ namespace tgui
#endif
return m_contents;
#endif
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Clipboard::set(const sf::String& contents)
{
#if SFML_VERSION_MAJOR > 2 || (SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR >= 5)
sf::Clipboard::setString(contents);
#else
m_contents = contents;
#ifdef SFML_SYSTEM_WINDOWS
@ -101,16 +114,17 @@ namespace tgui
}
}
#endif
#endif
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 5
void Clipboard::setWindowHandle(const sf::WindowHandle& windowHandle)
{
m_windowHandle = windowHandle;
m_isWindowHandleSet = true;
}
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

View File

@ -39,8 +39,12 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Gui::Gui() :
#if SFML_VERSION_MAJOR > 2 || (SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR >= 5)
m_window(nullptr)
#else
m_window (nullptr),
m_accessToWindow(false)
#endif
{
m_container->m_focused = true;
@ -52,13 +56,19 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Gui::Gui(sf::RenderWindow& window) :
#if SFML_VERSION_MAJOR > 2 || (SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR >= 5)
m_window(&window)
#else
m_window (&window),
m_accessToWindow(true)
#endif
{
m_container->m_window = &window;
m_container->m_focused = true;
#if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 5
Clipboard::setWindowHandle(window.getSystemHandle());
#endif
setView(window.getDefaultView());
@ -70,8 +80,12 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Gui::Gui(sf::RenderTarget& window) :
#if SFML_VERSION_MAJOR > 2 || (SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR >= 5)
m_window(&window)
#else
m_window (&window),
m_accessToWindow(false)
#endif
{
m_container->m_window = &window;
m_container->m_focused = true;
@ -87,12 +101,13 @@ namespace tgui
void Gui::setWindow(sf::RenderWindow& window)
{
m_accessToWindow = true;
m_window = &window;
m_container->m_window = &window;
#if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 5
m_accessToWindow = true;
Clipboard::setWindowHandle(window.getSystemHandle());
#endif
setView(window.getDefaultView());
}
@ -101,7 +116,9 @@ namespace tgui
void Gui::setWindow(sf::RenderTarget& window)
{
#if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 5
m_accessToWindow = false;
#endif
m_window = &window;
m_container->m_window = &window;
@ -222,9 +239,10 @@ namespace tgui
else if (event.type == sf::Event::GainedFocus)
{
m_container->m_focused = true;
#if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 5
if (m_accessToWindow)
Clipboard::setWindowHandle(static_cast<sf::RenderWindow*>(m_window)->getSystemHandle());
#endif
}
// Let the event manager handle the event