aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-04-20 01:17:28 +0800
committercrupest <crupest@outlook.com>2020-04-20 01:17:28 +0800
commit857adcb7ee2d45b2e29d4250fa4246bb8861a8f9 (patch)
tree2ebe62c58768ded27c5c6b15d1ab04400c9ecf9b /src
parent494d2db1c1203acc9d9f2b127b75c6df6160057a (diff)
downloadcru-857adcb7ee2d45b2e29d4250fa4246bb8861a8f9.tar.gz
cru-857adcb7ee2d45b2e29d4250fa4246bb8861a8f9.tar.bz2
cru-857adcb7ee2d45b2e29d4250fa4246bb8861a8f9.zip
...
Diffstat (limited to 'src')
-rw-r--r--src/win/graph/direct/font.cpp4
-rw-r--r--src/win/native/input_method.cpp32
-rw-r--r--src/win/native/ui_application.cpp6
-rw-r--r--src/win/native/window.cpp22
-rw-r--r--src/win/string.cpp22
5 files changed, 68 insertions, 18 deletions
diff --git a/src/win/graph/direct/font.cpp b/src/win/graph/direct/font.cpp
index 9b5eb477..6d50fafe 100644
--- a/src/win/graph/direct/font.cpp
+++ b/src/win/graph/direct/font.cpp
@@ -24,9 +24,9 @@ DWriteFont::DWriteFont(DirectGraphFactory* factory,
wff.data(), nullptr, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL, font_size, buffer.data(), &text_format_));
- ThrowIfFailed(text_format_->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER));
+ ThrowIfFailed(text_format_->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING));
ThrowIfFailed(
- text_format_->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER));
+ text_format_->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_NEAR));
}
float DWriteFont::GetFontSize() { return text_format_->GetFontSize(); }
diff --git a/src/win/native/input_method.cpp b/src/win/native/input_method.cpp
index 73831bd5..091abedd 100644
--- a/src/win/native/input_method.cpp
+++ b/src/win/native/input_method.cpp
@@ -84,8 +84,8 @@ CompositionClauses GetCompositionClauses(HIMC imm_context, int target_start,
int clause_size =
::ImmGetCompositionString(imm_context, GCS_COMPCLAUSE, NULL, 0);
int clause_length = clause_size / sizeof(std::uint32_t);
- result.reserve(clause_length - 1);
if (clause_length) {
+ result.reserve(clause_length - 1);
std::vector<std::uint32_t> clause_data(clause_length);
::ImmGetCompositionString(imm_context, GCS_COMPCLAUSE, clause_data.data(),
clause_size);
@@ -107,12 +107,21 @@ CompositionClauses GetCompositionClauses(HIMC imm_context, int target_start,
std::wstring GetString(HIMC imm_context) {
LONG string_size =
::ImmGetCompositionString(imm_context, GCS_COMPSTR, NULL, 0);
- std::wstring result((string_size / sizeof(wchar_t)) + 1, 0);
+ std::wstring result((string_size / sizeof(wchar_t)), 0);
::ImmGetCompositionString(imm_context, GCS_COMPSTR, result.data(),
string_size);
return result;
}
+std::wstring GetResultString(HIMC imm_context) {
+ LONG string_size =
+ ::ImmGetCompositionString(imm_context, GCS_RESULTSTR, NULL, 0);
+ std::wstring result((string_size / sizeof(wchar_t)), 0);
+ ::ImmGetCompositionString(imm_context, GCS_RESULTSTR, result.data(),
+ string_size);
+ return result;
+}
+
CompositionText GetCompositionInfo(HIMC imm_context) {
// We only care about GCS_COMPATTR, GCS_COMPCLAUSE and GCS_CURSORPOS, and
// convert them into underlines and selection range respectively.
@@ -244,6 +253,16 @@ void WinInputMethodContext::OnWindowNativeMessage(
switch (message.msg) {
case WM_IME_COMPOSITION: {
composition_event_.Raise(nullptr);
+ auto composition_text = GetCompositionText();
+ log::Debug(
+ "WinInputMethodContext: WM_IME_COMPOSITION composition text:\n{}",
+ composition_text);
+ if (message.l_param & GCS_RESULTSTR) {
+ auto result_string = GetResultString();
+ log::Debug(
+ "WinInputMethodContext: WM_IME_COMPOSITION result string: {}",
+ result_string);
+ }
break;
}
case WM_IME_STARTCOMPOSITION: {
@@ -257,6 +276,15 @@ void WinInputMethodContext::OnWindowNativeMessage(
}
}
+std::string WinInputMethodContext::GetResultString() {
+ auto optional_himc = TryGetHIMC();
+ if (!optional_himc.has_value()) return "";
+ auto himc = *std::move(optional_himc);
+
+ auto w_result = win::GetResultString(himc.Get());
+ return platform::win::ToUtf8String(w_result);
+}
+
std::optional<AutoHIMC> WinInputMethodContext::TryGetHIMC() {
const auto native_window = Resolve(native_window_resolver_.get());
if (native_window == nullptr) return std::nullopt;
diff --git a/src/win/native/ui_application.cpp b/src/win/native/ui_application.cpp
index 7fba6805..9aa3ebcd 100644
--- a/src/win/native/ui_application.cpp
+++ b/src/win/native/ui_application.cpp
@@ -13,6 +13,12 @@
#include "timer.hpp"
#include "window_manager.hpp"
+namespace cru::platform::native {
+std::unique_ptr<IUiApplication> CreateUiApplication() {
+ return std::make_unique<win::WinUiApplication>();
+}
+} // namespace cru::platform::native
+
namespace cru::platform::native::win {
WinUiApplication* WinUiApplication::instance = nullptr;
diff --git a/src/win/native/window.cpp b/src/win/native/window.cpp
index 7ad63769..30c77659 100644
--- a/src/win/native/window.cpp
+++ b/src/win/native/window.cpp
@@ -290,6 +290,20 @@ bool WinNativeWindow::HandleNativeWindowMessage(HWND hwnd, UINT msg,
OnKeyUpInternal(static_cast<int>(w_param));
*result = 0;
return true;
+ case WM_SYSKEYDOWN:
+ if (l_param & (1 << 29)) {
+ OnKeyDownInternal(static_cast<int>(w_param));
+ *result = 0;
+ return true;
+ }
+ return false;
+ case WM_SYSKEYUP:
+ if (l_param & (1 << 29)) {
+ OnKeyUpInternal(static_cast<int>(w_param));
+ *result = 0;
+ return true;
+ }
+ return false;
case WM_CHAR:
OnCharInternal(static_cast<wchar_t>(w_param));
*result = 0;
@@ -419,13 +433,13 @@ void WinNativeWindow::OnCharInternal(wchar_t c) {
last_wm_char_event_wparam_ = c;
return;
} else if (platform::win::IsSurrogatePairTrailing(c)) {
- wchar_t s[3] = {last_wm_char_event_wparam_, c, 0};
- auto str = platform::win::ToUtf8String(s);
+ wchar_t s[2] = {last_wm_char_event_wparam_, c};
+ auto str = platform::win::ToUtf8String({s, 2});
char_event_.Raise(str);
log::Debug("WinNativeWindow: char event, charactor is {}", str);
} else {
- wchar_t s[2] = {c, 0};
- auto str = platform::win::ToUtf8String(s);
+ wchar_t s[1] = {c};
+ auto str = platform::win::ToUtf8String({s, 1});
char_event_.Raise(str);
log::Debug("WinNativeWindow: char event, charactor is {}", str);
}
diff --git a/src/win/string.cpp b/src/win/string.cpp
index fb9811eb..5518e6af 100644
--- a/src/win/string.cpp
+++ b/src/win/string.cpp
@@ -8,9 +8,9 @@ namespace cru::platform::win {
std::string ToUtf8String(const std::wstring_view& string) {
if (string.empty()) return std::string{};
- const auto length =
- ::WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, string.data(), -1,
- nullptr, 0, nullptr, nullptr);
+ const auto length = ::WideCharToMultiByte(
+ CP_UTF8, WC_ERR_INVALID_CHARS, string.data(),
+ static_cast<int>(string.size()), nullptr, 0, nullptr, nullptr);
if (length == 0) {
throw Win32Error(::GetLastError(),
"Failed to convert wide string to UTF-8.");
@@ -18,9 +18,10 @@ std::string ToUtf8String(const std::wstring_view& string) {
std::string result;
result.resize(length);
- if (::WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, string.data(), -1,
- result.data(), static_cast<int>(result.size()),
- nullptr, nullptr) == 0)
+ if (::WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, string.data(),
+ static_cast<int>(string.size()), result.data(),
+ static_cast<int>(result.size()), nullptr,
+ nullptr) == 0)
throw Win32Error(::GetLastError(),
"Failed to convert wide string to UTF-8.");
return result;
@@ -29,8 +30,9 @@ std::string ToUtf8String(const std::wstring_view& string) {
std::wstring ToUtf16String(const std::string_view& string) {
if (string.empty()) return std::wstring{};
- const auto length = ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS,
- string.data(), -1, nullptr, 0);
+ const auto length =
+ ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, string.data(),
+ static_cast<int>(string.size()), nullptr, 0);
if (length == 0) {
throw Win32Error(::GetLastError(),
"Failed to convert wide string to UTF-16.");
@@ -38,8 +40,8 @@ std::wstring ToUtf16String(const std::string_view& string) {
std::wstring result;
result.resize(length);
- if (::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, string.data(), -1,
- result.data(),
+ if (::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, string.data(),
+ static_cast<int>(string.size()), result.data(),
static_cast<int>(result.size())) == 0)
throw win::Win32Error(::GetLastError(),
"Failed to convert wide string to UTF-16.");