[Bf-blender-cvs] [d6facd44b53] blender-v2.93-release: Fix T88909: Win32 getTitle() UTF8 Support

Harley Acheson noreply at git.blender.org
Mon Sep 6 09:40:34 CEST 2021


Commit: d6facd44b53108575381ca0637cd0fff73d45391
Author: Harley Acheson
Date:   Thu Jul 1 18:08:29 2021 -0700
Branches: blender-v2.93-release
https://developer.blender.org/rBd6facd44b53108575381ca0637cd0fff73d45391

Fix T88909: Win32 getTitle() UTF8 Support

In the Win32 platform our setTitle() can properly assign a Unicode
utf-8 window title. Unfortunately our getTitle() will only read regular
8-bit character strings. This means that we can never compare what we
set to what we get. This patch updates getTitle() to use Unicode-aware
GetWindowTextLengthW and GetWindowTextW.

see T88909 for an example of this affecting user experience.

Differential Revision: https://developer.blender.org/D11782

Reviewed by Ray Molenkamp

===================================================================

M	intern/ghost/intern/GHOST_WindowWin32.cpp

===================================================================

diff --git a/intern/ghost/intern/GHOST_WindowWin32.cpp b/intern/ghost/intern/GHOST_WindowWin32.cpp
index ef155d96f99..88ca458d240 100644
--- a/intern/ghost/intern/GHOST_WindowWin32.cpp
+++ b/intern/ghost/intern/GHOST_WindowWin32.cpp
@@ -376,9 +376,13 @@ void GHOST_WindowWin32::setTitle(const char *title)
 
 std::string GHOST_WindowWin32::getTitle() const
 {
-  char buf[s_maxTitleLength]; /*CHANGE + never used yet*/
-  ::GetWindowText(m_hWnd, buf, s_maxTitleLength);
-  return std::string(buf);
+  std::wstring wtitle(::GetWindowTextLengthW(m_hWnd) + 1, L'\0');
+  ::GetWindowTextW(m_hWnd, &wtitle[0], wtitle.capacity());
+
+  std::string title(count_utf_8_from_16(wtitle.c_str()) + 1, '\0');
+  conv_utf_16_to_8(wtitle.c_str(), &title[0], title.capacity());
+
+  return title;
 }
 
 void GHOST_WindowWin32::getWindowBounds(GHOST_Rect &bounds) const



More information about the Bf-blender-cvs mailing list