diff --git a/RimeWithWeasel/RimeWithWeasel.cpp b/RimeWithWeasel/RimeWithWeasel.cpp index c33a6fe20..6399ce48d 100644 --- a/RimeWithWeasel/RimeWithWeasel.cpp +++ b/RimeWithWeasel/RimeWithWeasel.cpp @@ -296,6 +296,30 @@ void RimeWithWeaselHandler::SelectCandidateOnCurrentPage(size_t index, UINT sess api->select_candidate_on_current_page(session_id, index); } +bool RimeWithWeaselHandler::HighlightCandidateOnCurrentPage(size_t index, UINT session_id, EatLine eat) +{ + DLOG(INFO) << "highlight candidate on current page, session_id = " << session_id << ", index = " << index; + RimeApi* api = rime_get_api(); + if(!api) + return false; + bool res = api->highlight_candidate_on_current_page(session_id, index); + _Respond(session_id, eat); + _UpdateUI(session_id); + return res; +} + +bool RimeWithWeaselHandler::ChangePage(bool backward, UINT session_id, EatLine eat) +{ + DLOG(INFO) << "change page, session_id = " << session_id << (backward? "backward" : "foreward"); + RimeApi* api = rime_get_api(); + if(!api) + return false; + bool res = api->change_page(session_id, backward); + _Respond(session_id, eat); + _UpdateUI(session_id); + return res; +} + void RimeWithWeaselHandler::FocusIn(DWORD client_caps, UINT session_id) { DLOG(INFO) << "Focus in: session_id = " << session_id << ", client_caps = " << client_caps; diff --git a/WeaselIPC/WeaselClientImpl.cpp b/WeaselIPC/WeaselClientImpl.cpp index 34a5d7392..04a5a3469 100644 --- a/WeaselIPC/WeaselClientImpl.cpp +++ b/WeaselIPC/WeaselClientImpl.cpp @@ -101,6 +101,22 @@ bool ClientImpl::SelectCandidateOnCurrentPage(size_t index) return ret != 0; } +bool ClientImpl::HighlightCandidateOnCurrentPage(size_t index) +{ + if(!_Active()) + return false; + LRESULT ret = _SendMessage(WEASEL_IPC_HIGHLIGHT_CANDIDATE_ON_CURRENT_PAGE, index, session_id); + return ret != 0; +} + +bool ClientImpl::ChangePage(bool backward) +{ + if(!_Active()) + return false; + LRESULT ret = _SendMessage(WEASEL_IPC_CHANGE_PAGE, backward, session_id); + return ret != 0; +} + void ClientImpl::UpdateInputPosition(RECT const& rc) { if (!_Active()) @@ -257,6 +273,16 @@ bool Client::SelectCandidateOnCurrentPage(size_t index) return m_pImpl->SelectCandidateOnCurrentPage(index); } +bool Client::HighlightCandidateOnCurrentPage(size_t index) +{ + return m_pImpl->HighlightCandidateOnCurrentPage(index); +} + +bool Client::ChangePage(bool backward) +{ + return m_pImpl->ChangePage(backward); +} + void Client::UpdateInputPosition(RECT const& rc) { m_pImpl->UpdateInputPosition(rc); diff --git a/WeaselIPC/WeaselClientImpl.h b/WeaselIPC/WeaselClientImpl.h index 27c5399c7..7c16d7c52 100644 --- a/WeaselIPC/WeaselClientImpl.h +++ b/WeaselIPC/WeaselClientImpl.h @@ -23,6 +23,8 @@ namespace weasel bool CommitComposition(); bool ClearComposition(); bool SelectCandidateOnCurrentPage(size_t index); + bool HighlightCandidateOnCurrentPage(size_t index); + bool ChangePage(bool backward); void UpdateInputPosition(RECT const& rc); void FocusIn(); void FocusOut(); diff --git a/WeaselIPCServer/WeaselServerImpl.cpp b/WeaselIPCServer/WeaselServerImpl.cpp index 90c6255df..a7c9cd75b 100644 --- a/WeaselIPCServer/WeaselServerImpl.cpp +++ b/WeaselIPCServer/WeaselServerImpl.cpp @@ -319,6 +319,32 @@ DWORD ServerImpl::OnSelectCandidateOnCurrentPage(WEASEL_IPC_COMMAND uMsg, DWORD return 0; } +DWORD ServerImpl::OnHighlightCandidateOnCurrentPage(WEASEL_IPC_COMMAND uMsg, DWORD wParam, DWORD lParam) +{ + if(m_pRequestHandler) + { + auto eat = [this](std::wstring &msg) -> bool { + *channel << msg; + return true; + }; + m_pRequestHandler->HighlightCandidateOnCurrentPage(wParam, lParam, eat); + } + return 0; +} + +DWORD ServerImpl::OnChangePage(WEASEL_IPC_COMMAND uMsg, DWORD wParam, DWORD lParam) +{ + if(m_pRequestHandler) + { + auto eat = [this](std::wstring &msg) -> bool { + *channel << msg; + return true; + }; + m_pRequestHandler->ChangePage(wParam, lParam, eat); + } + return 0; +} + #define MAP_PIPE_MSG_HANDLE(__msg, __wParam, __lParam) {\ auto lParam = __lParam;\ auto wParam = __wParam;\ @@ -351,6 +377,8 @@ void ServerImpl::HandlePipeMessage(PipeMessage pipe_msg, _Resp resp) PIPE_MSG_HANDLE(WEASEL_IPC_COMMIT_COMPOSITION, OnCommitComposition) PIPE_MSG_HANDLE(WEASEL_IPC_CLEAR_COMPOSITION, OnClearComposition); PIPE_MSG_HANDLE(WEASEL_IPC_SELECT_CANDIDATE_ON_CURRENT_PAGE, OnSelectCandidateOnCurrentPage); + PIPE_MSG_HANDLE(WEASEL_IPC_HIGHLIGHT_CANDIDATE_ON_CURRENT_PAGE, OnHighlightCandidateOnCurrentPage); + PIPE_MSG_HANDLE(WEASEL_IPC_CHANGE_PAGE, OnChangePage); PIPE_MSG_HANDLE(WEASEL_IPC_TRAY_COMMAND, OnCommand); END_MAP_PIPE_MSG_HANDLE(result); diff --git a/WeaselIPCServer/WeaselServerImpl.h b/WeaselIPCServer/WeaselServerImpl.h index b07bccd0f..d3973d622 100644 --- a/WeaselIPCServer/WeaselServerImpl.h +++ b/WeaselIPCServer/WeaselServerImpl.h @@ -53,6 +53,8 @@ namespace weasel DWORD OnCommitComposition(WEASEL_IPC_COMMAND uMsg, DWORD wParam, DWORD lParam); DWORD OnClearComposition(WEASEL_IPC_COMMAND uMsg, DWORD wParam, DWORD lParam); DWORD OnSelectCandidateOnCurrentPage(WEASEL_IPC_COMMAND uMsg, DWORD wParam, DWORD lParam); + DWORD OnHighlightCandidateOnCurrentPage(WEASEL_IPC_COMMAND uMsg, DWORD wParam, DWORD lParam); + DWORD OnChangePage(WEASEL_IPC_COMMAND uMsg, DWORD wParam, DWORD lParam); public: ServerImpl(); diff --git a/WeaselTSF/CandidateList.cpp b/WeaselTSF/CandidateList.cpp index 5df851593..d603a6fbb 100644 --- a/WeaselTSF/CandidateList.cpp +++ b/WeaselTSF/CandidateList.cpp @@ -422,39 +422,41 @@ void WeaselTSF::_SelectCandidateOnCurrentPage(size_t index) { m_client.SelectCandidateOnCurrentPage(index); // simulate a VK_SELECT presskey to get data back and DoEditSession - // the simulated keycode must be the one make TranslateKeycode Non-Zero return - // fix me: are there any better ways? - INPUT inputs[2]; - inputs[0].type = INPUT_KEYBOARD; - inputs[0].ki = {VK_SELECT, 0,0,0,0}; - inputs[1].type = INPUT_KEYBOARD; - inputs[1].ki = {VK_SELECT, 0,KEYEVENTF_KEYUP,0,0}; - ::SendInput(sizeof(inputs) / sizeof(INPUT), inputs, sizeof(INPUT)); + // the simulated keycode must be the one make TranslateKeycode Non-Zero return + // fix me: are there any better ways? + INPUT inputs[2]; + inputs[0].type = INPUT_KEYBOARD; + inputs[0].ki = {VK_SELECT, 0,0,0,0}; + inputs[1].type = INPUT_KEYBOARD; + inputs[1].ki = {VK_SELECT, 0,KEYEVENTF_KEYUP,0,0}; + ::SendInput(sizeof(inputs) / sizeof(INPUT), inputs, sizeof(INPUT)); } void WeaselTSF::_HandleMousePageEvent( bool* const nextPage, bool* const scrollNextPage) { - // ToDo: if feature new api comes, replace the processes bellow - weasel::KeyEvent ke{ 0, 0 }; // from scrolling event if ( scrollNextPage ) { if(_cand->style().paging_on_scroll) - ke.keycode = *scrollNextPage ? ibus::Page_Down : ibus::Page_Up; - else - { - ke.keycode = *scrollNextPage ? ibus::Down : ibus::Up; - if(_cand->GetIsReposition()) - { - if(ke.keycode == ibus::Up) - ke.keycode = ibus::Down; - else if(ke.keycode == ibus::Down) - ke.keycode = ibus::Up; + m_client.ChangePage(!(*scrollNextPage)); + else { + UINT current_select = 0, cand_count = 0; + _cand->GetSelection(¤t_select); + _cand->GetCount(&cand_count); + bool is_reposition = _cand->GetIsReposition(); + int offset = *scrollNextPage ? 1 : -1; + offset = offset * (is_reposition ? -1 : 1); + int index = (int)current_select + offset; + if (index >= 0 && index < cand_count) + m_client.HighlightCandidateOnCurrentPage((size_t)index); + else { + KeyEvent ke{0, 0}; + ke.keycode = (index < 0) ? ibus::Up : ibus::Down; + m_client.ProcessKeyEvent(ke); } } } else { // from click event - ke.keycode = *nextPage ? ibus::Page_Down : ibus::Page_Up; + m_client.ChangePage(!(*nextPage)); } - m_client.ProcessKeyEvent(ke); _UpdateComposition(_pEditSessionContext); } @@ -465,19 +467,7 @@ void WeaselTSF::_HandleMouseHoverEvent(const size_t index) if(index != current_select) { - // simuulate change current_select in librime - // maybe replace with new api in the future - weasel::KeyEvent ke{ 0, 0 }; - ke.keycode = current_select < index ? ibus::Down : ibus::Up; - int inc = index > current_select ? 1 : -1; - if (_cand->GetIsReposition()) inc = -inc; - UINT gap = abs((INT)((INT)index - (INT)current_select)); - for(UINT i=0; i < gap; i++) - { - m_client.ProcessKeyEvent(ke); - } - // simuulate change current_select end - _cand->SetSelection(current_select + inc * gap); + m_client.HighlightCandidateOnCurrentPage(index); _UpdateComposition(_pEditSessionContext); } } diff --git a/include/RimeWithWeasel.h b/include/RimeWithWeasel.h index 5f1d543f9..45ced7081 100644 --- a/include/RimeWithWeasel.h +++ b/include/RimeWithWeasel.h @@ -42,6 +42,8 @@ class RimeWithWeaselHandler : virtual void CommitComposition(UINT session_id); virtual void ClearComposition(UINT session_id); virtual void SelectCandidateOnCurrentPage(size_t index, UINT session_id); + virtual bool HighlightCandidateOnCurrentPage(size_t index, UINT session_id, EatLine eat); + virtual bool ChangePage(bool backward, UINT session_id, EatLine eat); virtual void FocusIn(DWORD param, UINT session_id); virtual void FocusOut(DWORD param, UINT session_id); virtual void UpdateInputPosition(RECT const& rc, UINT session_id); diff --git a/include/WeaselIPC.h b/include/WeaselIPC.h index 91b869009..9c12ef298 100644 --- a/include/WeaselIPC.h +++ b/include/WeaselIPC.h @@ -27,8 +27,10 @@ enum WEASEL_IPC_COMMAND WEASEL_IPC_END_MAINTENANCE, WEASEL_IPC_COMMIT_COMPOSITION, WEASEL_IPC_CLEAR_COMPOSITION, - WEASEL_IPC_SELECT_CANDIDATE_ON_CURRENT_PAGE, WEASEL_IPC_TRAY_COMMAND, + WEASEL_IPC_SELECT_CANDIDATE_ON_CURRENT_PAGE, + WEASEL_IPC_HIGHLIGHT_CANDIDATE_ON_CURRENT_PAGE, + WEASEL_IPC_CHANGE_PAGE, WEASEL_IPC_LAST_COMMAND }; @@ -78,6 +80,8 @@ namespace weasel virtual void CommitComposition(UINT session_id) {} virtual void ClearComposition(UINT session_id) {} virtual void SelectCandidateOnCurrentPage(size_t index, UINT session_id) {} + virtual bool HighlightCandidateOnCurrentPage(size_t index, UINT session_id, EatLine eat) {return false;} + virtual bool ChangePage(bool backward, UINT session_id, EatLine eat) {return false;} virtual void FocusIn(DWORD param, UINT session_id) {} virtual void FocusOut(DWORD param, UINT session_id) {} virtual void UpdateInputPosition(RECT const& rc, UINT session_id) {} @@ -135,6 +139,10 @@ namespace weasel bool ClearComposition(); // 选择当前页面编号为index的候选 bool SelectCandidateOnCurrentPage(size_t index); + // 高亮当前页面编号为index的候选 + bool HighlightCandidateOnCurrentPage(size_t index); + // 高亮当前页面编号为index的候选 + bool ChangePage(bool backward); // 更新输入位置 void UpdateInputPosition(RECT const& rc); // 输入窗口获得焦点