diff --git a/include/SFML/Graphics/RenderWindow.hpp b/include/SFML/Graphics/RenderWindow.hpp index 399b40f0..35f565f6 100644 --- a/include/SFML/Graphics/RenderWindow.hpp +++ b/include/SFML/Graphics/RenderWindow.hpp @@ -73,7 +73,7 @@ public : /// \param settings Additional settings for the underlying OpenGL context /// //////////////////////////////////////////////////////////// - RenderWindow(VideoMode mode, const std::string& title, Uint32 style = Style::Default, const ContextSettings& settings = ContextSettings()); + RenderWindow(VideoMode mode, const String& title, Uint32 style = Style::Default, const ContextSettings& settings = ContextSettings()); //////////////////////////////////////////////////////////// /// \brief Construct the window from an existing control diff --git a/include/SFML/Window/Window.hpp b/include/SFML/Window/Window.hpp index d4b91e3f..5e5e613a 100644 --- a/include/SFML/Window/Window.hpp +++ b/include/SFML/Window/Window.hpp @@ -37,7 +37,7 @@ #include #include #include -#include +#include namespace sf @@ -86,7 +86,7 @@ public : /// \param settings Additional settings for the underlying OpenGL context /// //////////////////////////////////////////////////////////// - Window(VideoMode mode, const std::string& title, Uint32 style = Style::Default, const ContextSettings& settings = ContextSettings()); + Window(VideoMode mode, const String& title, Uint32 style = Style::Default, const ContextSettings& settings = ContextSettings()); //////////////////////////////////////////////////////////// /// \brief Construct the window from an existing control @@ -125,7 +125,7 @@ public : /// \param settings Additional settings for the underlying OpenGL context /// //////////////////////////////////////////////////////////// - void create(VideoMode mode, const std::string& title, Uint32 style = Style::Default, const ContextSettings& settings = ContextSettings()); + void create(VideoMode mode, const String& title, Uint32 style = Style::Default, const ContextSettings& settings = ContextSettings()); //////////////////////////////////////////////////////////// /// \brief Create (or recreate) the window from an existing control @@ -284,7 +284,7 @@ public : /// \see setIcon /// //////////////////////////////////////////////////////////// - void setTitle(const std::string& title); + void setTitle(const String& title); //////////////////////////////////////////////////////////// /// \brief Change the window's icon diff --git a/src/SFML/Graphics/RenderWindow.cpp b/src/SFML/Graphics/RenderWindow.cpp index d1843f10..23404405 100644 --- a/src/SFML/Graphics/RenderWindow.cpp +++ b/src/SFML/Graphics/RenderWindow.cpp @@ -39,7 +39,7 @@ RenderWindow::RenderWindow() //////////////////////////////////////////////////////////// -RenderWindow::RenderWindow(VideoMode mode, const std::string& title, Uint32 style, const ContextSettings& settings) +RenderWindow::RenderWindow(VideoMode mode, const String& title, Uint32 style, const ContextSettings& settings) { // Don't call the base class constructor because it contains virtual function calls create(mode, title, style, settings); diff --git a/src/SFML/Window/Linux/WindowImplX11.cpp b/src/SFML/Window/Linux/WindowImplX11.cpp index d3b8642f..f2f8ec40 100644 --- a/src/SFML/Window/Linux/WindowImplX11.cpp +++ b/src/SFML/Window/Linux/WindowImplX11.cpp @@ -35,6 +35,8 @@ #include #include #include +#include +#include //////////////////////////////////////////////////////////// @@ -91,7 +93,7 @@ m_keyRepeat (true) //////////////////////////////////////////////////////////// -WindowImplX11::WindowImplX11(VideoMode mode, const std::string& title, unsigned long style) : +WindowImplX11::WindowImplX11(VideoMode mode, const String& title, unsigned long style) : m_window (0), m_inputMethod (NULL), m_inputContext(NULL), @@ -313,9 +315,23 @@ void WindowImplX11::setSize(const Vector2u& size) //////////////////////////////////////////////////////////// -void WindowImplX11::setTitle(const std::string& title) +void WindowImplX11::setTitle(const String& title) { - XStoreName(m_display, m_window, title.c_str()); + // Bare X11 has no Unicode window title support. + // There is however an option to tell the window manager your unicode title via hints. + + // Convert to UTF-8 encoding. + std::basic_string utf8Title; + sf::Utf32::toUtf8(title.begin(), title.end(), std::back_inserter(utf8Title)); + + // Set the _NET_WM_NAME atom, which specifies a UTF-8 encoded window title. + Atom wmName = XInternAtom(m_display, "_NET_WM_NAME", False); + Atom useUtf8 = XInternAtom(m_display, "UTF8_STRING", False); + XChangeProperty(m_display, m_window, wmName, useUtf8, 8, + PropModeReplace, utf8Title.c_str(), utf8Title.size()); + + // Set the non-Unicode title as a fallback for window managers who don't support _NET_WM_NAME. + XStoreName(m_display, m_window, title.toAnsiString().c_str()); } diff --git a/src/SFML/Window/Linux/WindowImplX11.hpp b/src/SFML/Window/Linux/WindowImplX11.hpp index 11c7e6ef..74392ba7 100644 --- a/src/SFML/Window/Linux/WindowImplX11.hpp +++ b/src/SFML/Window/Linux/WindowImplX11.hpp @@ -30,9 +30,9 @@ //////////////////////////////////////////////////////////// #include #include +#include #include #include -#include namespace sf @@ -63,7 +63,7 @@ public : /// \param style Window style (resizable, fixed, or fullscren) /// //////////////////////////////////////////////////////////// - WindowImplX11(VideoMode mode, const std::string& title, unsigned long style); + WindowImplX11(VideoMode mode, const String& title, unsigned long style); //////////////////////////////////////////////////////////// /// \brief Destructor @@ -117,7 +117,7 @@ public : /// \param title New title /// //////////////////////////////////////////////////////////// - virtual void setTitle(const std::string& title); + virtual void setTitle(const String& title); //////////////////////////////////////////////////////////// /// \brief Change the window's icon diff --git a/src/SFML/Window/OSX/WindowImplCocoa.hpp b/src/SFML/Window/OSX/WindowImplCocoa.hpp index 40b18dc0..e1866556 100644 --- a/src/SFML/Window/OSX/WindowImplCocoa.hpp +++ b/src/SFML/Window/OSX/WindowImplCocoa.hpp @@ -31,6 +31,7 @@ //////////////////////////////////////////////////////////// #include #include +#include //////////////////////////////////////////////////////////// /// Predefine OBJC classes @@ -79,7 +80,7 @@ public : /// \param style Window style (resizable, fixed, or fullscren) /// //////////////////////////////////////////////////////////// - WindowImplCocoa(VideoMode mode, const std::string& title, unsigned long style); + WindowImplCocoa(VideoMode mode, const String& title, unsigned long style); //////////////////////////////////////////////////////////// /// \brief Destructor @@ -280,7 +281,7 @@ public : /// \param title New title /// //////////////////////////////////////////////////////////// - virtual void setTitle(const std::string& title); + virtual void setTitle(const String& title); //////////////////////////////////////////////////////////// /// \brief Change the window's icon diff --git a/src/SFML/Window/OSX/WindowImplCocoa.mm b/src/SFML/Window/OSX/WindowImplCocoa.mm index 687f5b78..210daf52 100644 --- a/src/SFML/Window/OSX/WindowImplCocoa.mm +++ b/src/SFML/Window/OSX/WindowImplCocoa.mm @@ -28,6 +28,7 @@ //////////////////////////////////////////////////////////// #include #include +#include #import #import @@ -80,7 +81,7 @@ WindowImplCocoa::WindowImplCocoa(WindowHandle handle) //////////////////////////////////////////////////////////// WindowImplCocoa::WindowImplCocoa(VideoMode mode, - const std::string& title, + const String& title, unsigned long style) : m_showCursor(true) { @@ -91,7 +92,7 @@ WindowImplCocoa::WindowImplCocoa(VideoMode mode, retainPool(); m_delegate = [[SFWindowController alloc] initWithMode:mode andStyle:style]; - [m_delegate changeTitle:stringToNSString(title)]; + [m_delegate changeTitle:sfStringToNSString(title)]; [m_delegate setRequesterTo:this]; } @@ -362,9 +363,9 @@ void WindowImplCocoa::setSize(const Vector2u& size) //////////////////////////////////////////////////////////// -void WindowImplCocoa::setTitle(const std::string& title) +void WindowImplCocoa::setTitle(const String& title) { - [m_delegate changeTitle:stringToNSString(title)]; + [m_delegate changeTitle:sfStringToNSString(title)]; } diff --git a/src/SFML/Window/OSX/cpp_objc_conversion.h b/src/SFML/Window/OSX/cpp_objc_conversion.h index 73b42aca..75095b35 100644 --- a/src/SFML/Window/OSX/cpp_objc_conversion.h +++ b/src/SFML/Window/OSX/cpp_objc_conversion.h @@ -27,6 +27,7 @@ // Headers //////////////////////////////////////////////////////////// #include +#include #import @@ -35,4 +36,4 @@ /// //////////////////////////////////////////////////////////// NSString* stringToNSString(std::string const& string); - +NSString* sfStringToNSString(sf::String const& string); diff --git a/src/SFML/Window/OSX/cpp_objc_conversion.mm b/src/SFML/Window/OSX/cpp_objc_conversion.mm index 91d33aec..4b619a58 100644 --- a/src/SFML/Window/OSX/cpp_objc_conversion.mm +++ b/src/SFML/Window/OSX/cpp_objc_conversion.mm @@ -28,6 +28,7 @@ //////////////////////////////////////////////////////////// #include +#import #import //////////////////////////////////////////////////////////// @@ -40,3 +41,18 @@ NSString* stringToNSString(std::string const& string) return str; } +//////////////////////////////////////////////////////////// +NSString* sfStringToNSString(sf::String const& string) +{ + sf::Uint32 length = string.getSize() * sizeof(sf::Uint32); + const void* data = reinterpret_cast(string.getData()); + + NSStringEncoding encoding; + if (NSHostByteOrder() == NS_LittleEndian) + encoding = NSUTF32LittleEndianStringEncoding; + else + encoding = NSUTF32BigEndianStringEncoding; + + NSString* str = [[NSString alloc] initWithBytes:data length:length encoding:encoding]; + return str; +} diff --git a/src/SFML/Window/Win32/WindowImplWin32.cpp b/src/SFML/Window/Win32/WindowImplWin32.cpp index 44b5087c..bf80e8f4 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.cpp +++ b/src/SFML/Window/Win32/WindowImplWin32.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include // MinGW lacks the definition of some Win32 constants @@ -84,7 +85,7 @@ m_resizing (false) //////////////////////////////////////////////////////////// -WindowImplWin32::WindowImplWin32(VideoMode mode, const std::string& title, Uint32 style) : +WindowImplWin32::WindowImplWin32(VideoMode mode, const String& title, Uint32 style) : m_handle (NULL), m_callback (0), m_cursor (NULL), @@ -132,14 +133,11 @@ m_resizing (false) // Create the window if (hasUnicodeSupport()) { - wchar_t wTitle[256]; - int count = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, title.c_str(), static_cast(title.size()), wTitle, sizeof(wTitle) / sizeof(*wTitle)); - wTitle[count] = L'\0'; - m_handle = CreateWindowW(classNameW, wTitle, win32Style, left, top, width, height, NULL, NULL, GetModuleHandle(NULL), this); + m_handle = CreateWindowW(classNameW, title.toWideString().c_str(), win32Style, left, top, width, height, NULL, NULL, GetModuleHandle(NULL), this); } else { - m_handle = CreateWindowA(classNameA, title.c_str(), win32Style, left, top, width, height, NULL, NULL, GetModuleHandle(NULL), this); + m_handle = CreateWindowA(classNameA, title.toAnsiString().c_str(), win32Style, left, top, width, height, NULL, NULL, GetModuleHandle(NULL), this); } // Switch to fullscreen if requested @@ -253,9 +251,16 @@ void WindowImplWin32::setSize(const Vector2u& size) //////////////////////////////////////////////////////////// -void WindowImplWin32::setTitle(const std::string& title) +void WindowImplWin32::setTitle(const String& title) { - SetWindowTextA(m_handle, title.c_str()); + if (hasUnicodeSupport()) + { + SetWindowTextW(m_handle, title.toWideString().c_str()); + } + else + { + SetWindowTextA(m_handle, title.toAnsiString().c_str()); + } } @@ -877,3 +882,4 @@ LRESULT CALLBACK WindowImplWin32::globalOnEvent(HWND handle, UINT message, WPARA } // namespace priv } // namespace sf + diff --git a/src/SFML/Window/Win32/WindowImplWin32.hpp b/src/SFML/Window/Win32/WindowImplWin32.hpp index 88d1a3ed..ac091e87 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.hpp +++ b/src/SFML/Window/Win32/WindowImplWin32.hpp @@ -30,8 +30,8 @@ //////////////////////////////////////////////////////////// #include #include +#include #include -#include namespace sf @@ -62,7 +62,7 @@ public : /// \param style Window style /// //////////////////////////////////////////////////////////// - WindowImplWin32(VideoMode mode, const std::string& title, Uint32 style); + WindowImplWin32(VideoMode mode, const String& title, Uint32 style); //////////////////////////////////////////////////////////// /// \brief Destructor @@ -116,7 +116,7 @@ public : /// \param title New title /// //////////////////////////////////////////////////////////// - virtual void setTitle(const std::string& title); + virtual void setTitle(const String& title); //////////////////////////////////////////////////////////// /// \brief Change the window's icon diff --git a/src/SFML/Window/Window.cpp b/src/SFML/Window/Window.cpp index c58f3693..63ffd60d 100644 --- a/src/SFML/Window/Window.cpp +++ b/src/SFML/Window/Window.cpp @@ -51,7 +51,7 @@ m_frameTimeLimit(Time::Zero) //////////////////////////////////////////////////////////// -Window::Window(VideoMode mode, const std::string& title, Uint32 style, const ContextSettings& settings) : +Window::Window(VideoMode mode, const String& title, Uint32 style, const ContextSettings& settings) : m_impl (NULL), m_context (NULL), m_frameTimeLimit(Time::Zero) @@ -78,7 +78,7 @@ Window::~Window() //////////////////////////////////////////////////////////// -void Window::create(VideoMode mode, const std::string& title, Uint32 style, const ContextSettings& settings) +void Window::create(VideoMode mode, const String& title, Uint32 style, const ContextSettings& settings) { // Destroy the previous window implementation close(); @@ -236,7 +236,7 @@ void Window::setSize(const Vector2u size) //////////////////////////////////////////////////////////// -void Window::setTitle(const std::string& title) +void Window::setTitle(const String& title) { if (m_impl) m_impl->setTitle(title); diff --git a/src/SFML/Window/WindowImpl.cpp b/src/SFML/Window/WindowImpl.cpp index 2e3d5ac3..8fd0d92d 100644 --- a/src/SFML/Window/WindowImpl.cpp +++ b/src/SFML/Window/WindowImpl.cpp @@ -55,7 +55,7 @@ namespace sf namespace priv { //////////////////////////////////////////////////////////// -WindowImpl* WindowImpl::create(VideoMode mode, const std::string& title, Uint32 style) +WindowImpl* WindowImpl::create(VideoMode mode, const String& title, Uint32 style) { return new WindowImplType(mode, title, style); } diff --git a/src/SFML/Window/WindowImpl.hpp b/src/SFML/Window/WindowImpl.hpp index d60960f3..ff57cfd1 100644 --- a/src/SFML/Window/WindowImpl.hpp +++ b/src/SFML/Window/WindowImpl.hpp @@ -30,6 +30,7 @@ //////////////////////////////////////////////////////////// #include #include +#include #include #include #include @@ -37,8 +38,6 @@ #include #include #include -#include - namespace sf { @@ -64,7 +63,7 @@ public : /// \return Pointer to the created window (don't forget to delete it) /// //////////////////////////////////////////////////////////// - static WindowImpl* create(VideoMode mode, const std::string& title, Uint32 style); + static WindowImpl* create(VideoMode mode, const String& title, Uint32 style); //////////////////////////////////////////////////////////// /// \brief Create a new window depending on to the current OS @@ -155,7 +154,7 @@ public : /// \param title New title /// //////////////////////////////////////////////////////////// - virtual void setTitle(const std::string& title) = 0; + virtual void setTitle(const String& title) = 0; //////////////////////////////////////////////////////////// /// \brief Change the window's icon