diff --git a/server/src/ipc/event_listener.cpp b/server/src/ipc/event_listener.cpp index b1720f67..159759cd 100644 --- a/server/src/ipc/event_listener.cpp +++ b/server/src/ipc/event_listener.cpp @@ -59,27 +59,24 @@ void WorkerThread() // Global::CandidateWordList.clear(); Global::SelectedCandidateString = L""; - int cnt = 0; - for (const auto &[pinyin, word, weight] : Global::CandidateList) + Global::PageIndex = 0; + Global::ItemTotalCount = Global::CandidateList.size(); + int loop = Global::ItemTotalCount > Global::CountOfOnePage // + ? Global::CountOfOnePage // + : Global::ItemTotalCount; + for (int i = 0; i < loop; i++) { - if (cnt == 0) + auto &[pinyin, word, weight] = Global::CandidateList[i]; + if (i == 0) { Global::SelectedCandidateString = string_to_wstring(word); } - if (cnt < 8) - { - candidate_string += std::to_string(cnt + 1) + ". " + word; - Global::CandidateWordList.push_back(string_to_wstring(word)); - cnt++; - } - if (cnt < 7) + candidate_string += std::to_string(i + 1) + ". " + word; + Global::CandidateWordList.push_back(string_to_wstring(word)); + if (i < Global::CountOfOnePage - 1) { candidate_string += ","; } - else - { - break; - } } ::WriteDataToSharedMemory(string_to_wstring(candidate_string), true); PostMessage(::global_hwnd, WM_SHOW_MAIN_WINDOW, 0, 0); @@ -110,6 +107,61 @@ void WorkerThread() ::SendImeInputs(Global::CandidateWordList[Global::Keycode - '1']); } } + else if (Global::Keycode == VK_OEM_MINUS) // Page previous + { + if (Global::PageIndex > 0) + { + std::string candidate_string; + Global::PageIndex--; + int loop = Global::CountOfOnePage; + for (int i = 0; i < loop; i++) + { + auto &[pinyin, word, weight] = + Global::CandidateList[i + Global::PageIndex * Global::CountOfOnePage]; + if (i == 0) + { + Global::SelectedCandidateString = string_to_wstring(word); + } + candidate_string += std::to_string(i + 1) + ". " + word; + Global::CandidateWordList.push_back(string_to_wstring(word)); + if (i < loop - 1) + { + candidate_string += ","; + } + } + ::WriteDataToSharedMemory(string_to_wstring(candidate_string), true); + PostMessage(::global_hwnd, WM_SHOW_MAIN_WINDOW, 0, 0); + } + } + else if (Global::Keycode == VK_OEM_PLUS) // Page next + { + if (Global::PageIndex < (Global::ItemTotalCount - 1) / Global::CountOfOnePage) + { + std::string candidate_string; + Global::PageIndex++; + int loop = + Global::ItemTotalCount - Global::PageIndex * Global::CountOfOnePage > Global::CountOfOnePage + ? Global::CountOfOnePage + : Global::ItemTotalCount - Global::PageIndex * Global::CountOfOnePage; + for (int i = 0; i < loop; i++) + { + auto &[pinyin, word, weight] = + Global::CandidateList[i + Global::PageIndex * Global::CountOfOnePage]; + if (i == 0) + { + Global::SelectedCandidateString = string_to_wstring(word); + } + candidate_string += std::to_string(i + 1) + ". " + word; + Global::CandidateWordList.push_back(string_to_wstring(word)); + if (i < loop - 1) + { + candidate_string += ","; + } + } + ::WriteDataToSharedMemory(string_to_wstring(candidate_string), true); + PostMessage(::global_hwnd, WM_SHOW_MAIN_WINDOW, 0, 0); + } + } } } } diff --git a/server/src/ipc/ipc.h b/server/src/ipc/ipc.h index 2b57da86..774c52ae 100644 --- a/server/src/ipc/ipc.h +++ b/server/src/ipc/ipc.h @@ -57,4 +57,8 @@ inline std::wstring CandidateString = L""; inline std::vector CandidateList; inline std::vector CandidateWordList; inline std::wstring SelectedCandidateString = L""; + +inline int CountOfOnePage = 8; +inline int PageIndex = 0; +inline int ItemTotalCount = 0; } // namespace Global \ No newline at end of file diff --git a/server/src/window/candidate_window.cpp b/server/src/window/candidate_window.cpp index 5af45352..1c12121f 100644 --- a/server/src/window/candidate_window.cpp +++ b/server/src/window/candidate_window.cpp @@ -143,10 +143,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } ShowWindow(hWnd, SW_SHOWNOACTIVATE); ::ReadDataFromSharedMemory(0b100000); - Global::PinyinString = string_to_wstring( // + std::wstring embeded_pinyin = string_to_wstring( // PinyinUtil::pinyin_segmentation(wstring_to_string(Global::PinyinString)) // ); - std::wstring str = Global::PinyinString + L"," + Global::CandidateString; + std::wstring str = embeded_pinyin + L"," + Global::CandidateString; InflateCandidateWindow(str); return 0; }