aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-04-19 19:54:44 +0800
committercrupest <crupest@outlook.com>2020-04-19 19:54:44 +0800
commit494d2db1c1203acc9d9f2b127b75c6df6160057a (patch)
treea0e4eaf7540ac4af3b50baf085113122ef2ca651 /src
parent76f62be24b7e612b1f6880f9d7b0ddc07a8d38eb (diff)
downloadcru-494d2db1c1203acc9d9f2b127b75c6df6160057a.tar.gz
cru-494d2db1c1203acc9d9f2b127b75c6df6160057a.tar.bz2
cru-494d2db1c1203acc9d9f2b127b75c6df6160057a.zip
...
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt6
-rw-r--r--src/main.cpp58
-rw-r--r--src/win/native/input_method.cpp44
3 files changed, 38 insertions, 70 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e2eb921c..e10aafbd 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -8,9 +8,3 @@ endif()
add_subdirectory(ui)
-add_executable(demo main.cpp)
-target_link_libraries(demo PRIVATE cru_ui)
-
-if(WIN32)
- target_link_libraries(demo PRIVATE cru_win_native)
-endif()
diff --git a/src/main.cpp b/src/main.cpp
deleted file mode 100644
index 0172838e..00000000
--- a/src/main.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-#include "cru/platform/heap_debug.hpp"
-#include "cru/platform/native/window.hpp"
-#include "cru/ui/controls/button.hpp"
-#include "cru/ui/controls/flex_layout.hpp"
-#include "cru/ui/controls/stack_layout.hpp"
-#include "cru/ui/controls/text_block.hpp"
-#include "cru/ui/ui_host.hpp"
-#include "cru/ui/window.hpp"
-#include "cru/win/native/ui_application.hpp"
-
-using cru::platform::native::win::WinUiApplication;
-using cru::ui::Rect;
-using cru::ui::Thickness;
-using cru::ui::Window;
-using cru::ui::controls::Button;
-using cru::ui::controls::FlexLayout;
-using cru::ui::controls::StackLayout;
-using cru::ui::controls::TextBlock;
-
-int main() {
-#ifdef CRU_DEBUG
- cru::platform::SetupHeapDebug();
-#endif
-
- std::unique_ptr<WinUiApplication> application =
- std::make_unique<WinUiApplication>();
-
- const auto window = Window::CreateOverlapped();
-
- const auto flex_layout = FlexLayout::Create();
-
- window->SetChild(flex_layout);
-
- const auto button = Button::Create();
- const auto text_block1 = TextBlock::Create();
- text_block1->SetText("Hello World!");
- button->SetChild(text_block1);
- flex_layout->AddChild(button, 0);
-
- const auto text_block2 = TextBlock::Create();
- text_block2->SetText("Hello World!");
-
- const auto text_block3 = TextBlock::Create();
- text_block3->SetText("Overlapped text");
-
- const auto stack_layout = StackLayout::Create();
- stack_layout->AddChild(text_block2, 0);
- stack_layout->AddChild(text_block3, 1);
- flex_layout->AddChild(stack_layout, 1);
-
- const auto text_block4 = TextBlock::Create();
- text_block4->SetText("Hello World!!!");
- flex_layout->AddChild(text_block4, 2);
-
- window->GetUiHost()->GetNativeWindowResolver()->Resolve()->SetVisible(true);
-
- return application->Run();
-}
diff --git a/src/win/native/input_method.cpp b/src/win/native/input_method.cpp
index dace5827..73831bd5 100644
--- a/src/win/native/input_method.cpp
+++ b/src/win/native/input_method.cpp
@@ -128,9 +128,17 @@ CompositionText GetCompositionInfo(HIMC imm_context) {
auto clauses =
GetCompositionClauses(imm_context, w_target_start, w_target_end);
- int cursor = ::ImmGetCompositionString(imm_context, GCS_CURSORPOS, NULL, 0);
+ int w_cursor = ::ImmGetCompositionString(imm_context, GCS_CURSORPOS, NULL, 0);
- // TODO: Finish this.
+ auto text = platform::win::ToUtf8String(w_text);
+ for (auto& clause : clauses) {
+ clause.start = platform::win::IndexUtf16ToUtf8(w_text, clause.start, text);
+ clause.end = platform::win::IndexUtf16ToUtf8(w_text, clause.end, text);
+ }
+ int cursor = platform::win::IndexUtf16ToUtf8(w_text, w_cursor, text);
+
+ return CompositionText{std::move(text), std::move(clauses),
+ TextRange{cursor}};
}
} // namespace
@@ -161,21 +169,45 @@ void WinInputMethodContext::DisableIME() {
if (native_window == nullptr) return;
const auto hwnd = native_window->GetWindowHandle();
+ AutoHIMC himc{hwnd};
+
+ if (!::ImmNotifyIME(himc.Get(), NI_COMPOSITIONSTR, CPS_COMPLETE, 0)) {
+ log::Warn(
+ "WinInputMethodContext: Failed to complete composition before disable "
+ "ime.");
+ }
+
if (::ImmAssociateContextEx(hwnd, nullptr, 0) == FALSE) {
log::Warn("WinInputMethodContext: Failed to disable ime.");
}
}
void WinInputMethodContext::CompleteComposition() {
- // TODO: Not implemented.
+ auto optional_himc = TryGetHIMC();
+ if (!optional_himc.has_value()) return;
+ auto himc = *std::move(optional_himc);
+
+ if (!::ImmNotifyIME(himc.Get(), NI_COMPOSITIONSTR, CPS_COMPLETE, 0)) {
+ log::Warn("WinInputMethodContext: Failed to complete composition.");
+ }
}
void WinInputMethodContext::CancelComposition() {
- // TODO: Not implemented.
+ auto optional_himc = TryGetHIMC();
+ if (!optional_himc.has_value()) return;
+ auto himc = *std::move(optional_himc);
+
+ if (!::ImmNotifyIME(himc.Get(), NI_COMPOSITIONSTR, CPS_CANCEL, 0)) {
+ log::Warn("WinInputMethodContext: Failed to complete composition.");
+ }
}
-const CompositionText& WinInputMethodContext::GetCompositionText() {
- // TODO: Not implemented.
+CompositionText WinInputMethodContext::GetCompositionText() {
+ auto optional_himc = TryGetHIMC();
+ if (!optional_himc.has_value()) return CompositionText{};
+ auto himc = *std::move(optional_himc);
+
+ return GetCompositionInfo(himc.Get());
}
void WinInputMethodContext::SetCandidateWindowPosition(const Point& point) {