Skip to content

Commit

Permalink
fixed: respond incorrect when click on paging button, caused by style…
Browse files Browse the repository at this point in the history
…/paging_on_scroll feat commit f6bac0a
  • Loading branch information
fxliang committed Sep 18, 2023
1 parent 1b08cd4 commit 8f62c9c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 26 deletions.
35 changes: 20 additions & 15 deletions WeaselTSF/CandidateList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ void CCandidateList::StartUI()
}

if(!_ui->uiCallback())
_ui->SetUICallBack([this](size_t* const sel, size_t* const hov, bool* const next) { _tsf->HandleUICallback(sel, hov, next); });
_ui->SetUICallBack([this](size_t* const sel, size_t* const hov, bool* const next, bool* const scroll_next) { _tsf->HandleUICallback(sel, hov, next, scroll_next); });
pUIElementMgr->BeginUIElement(this, &_pbShow, &uiid);
//pUIElementMgr->UpdateUIElement(uiid);
if (_pbShow)
Expand Down Expand Up @@ -426,22 +426,27 @@ void WeaselTSF::_SelectCandidateOnCurrentPage(size_t index)
DoEditSession(0);
}

void WeaselTSF::_HandleMousePageEvent(const bool nextPage)
void WeaselTSF::_HandleMousePageEvent( bool* const nextPage, bool* const scrollNextPage)
{
// ToDo: if feature new api comes, replace the processes bellow
weasel::KeyEvent ke{ 0, 0 };
if(_cand->style().paging_on_scroll)
ke.keycode = nextPage ? ibus::Page_Down : ibus::Page_Up;
else
{
ke.keycode = nextPage ? ibus::Down : ibus::Up;
if(_cand->GetIsReposition())
// from scrolling event
if ( scrollNextPage ) {
if(_cand->style().paging_on_scroll)
ke.keycode = *scrollNextPage ? ibus::Page_Down : ibus::Page_Up;
else
{
if(ke.keycode == ibus::Up)
ke.keycode = ibus::Down;
else if(ke.keycode == ibus::Down)
ke.keycode = ibus::Up;
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;
}
}
} else { // from click event
ke.keycode = *nextPage ? ibus::Page_Down : ibus::Page_Up;
}
m_client.ProcessKeyEvent(ke);
DoEditSession(0);
Expand All @@ -468,12 +473,12 @@ void WeaselTSF::_HandleMouseHoverEvent(const size_t index)
}
}

void WeaselTSF::HandleUICallback(size_t* const sel, size_t* const hov, bool* const next)
void WeaselTSF::HandleUICallback(size_t* const sel, size_t* const hov, bool* const next, bool* const scroll_next)
{
if (sel)
_SelectCandidateOnCurrentPage(*sel);
else if (hov)
_HandleMouseHoverEvent(*hov);
else if (next)
_HandleMousePageEvent(*next);
else if (next || scroll_next)
_HandleMousePageEvent(next, scroll_next);
}
4 changes: 2 additions & 2 deletions WeaselTSF/WeaselTSF.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ class WeaselTSF:


com_ptr<ITfThreadMgr> _GetThreadMgr() { return _pThreadMgr; }
void HandleUICallback(size_t* const sel, size_t* const hov, bool* const next);
void HandleUICallback(size_t* const sel, size_t* const hov, bool* const next, bool* const scroll_next);

private:
/* ui callback functions private */
void _SelectCandidateOnCurrentPage(const size_t index);
void _HandleMouseHoverEvent(const size_t index);
void _HandleMousePageEvent(const bool nextPage);
void _HandleMousePageEvent( bool* const nextPage, bool* const scrollNextPage);
/* TSF Related */
BOOL _InitThreadMgrEventSink();
void _UninitThreadMgrEventSink();
Expand Down
10 changes: 5 additions & 5 deletions WeaselUI/WeaselPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ LRESULT WeaselPanel::OnMouseWheel(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
if(_UICallback && delta != 0)
{
bool nextpage = delta < 0;
_UICallback(NULL, NULL, &nextpage);
_UICallback(NULL, NULL, NULL, &nextpage);
}
bHandled = true;
return 0;
Expand Down Expand Up @@ -267,7 +267,7 @@ LRESULT WeaselPanel::OnLeftClicked(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL
if(prc.PtInRect(point)) {
bool nextPage = false;
if(_UICallback)
_UICallback(NULL, NULL, &nextPage);
_UICallback(NULL, NULL, &nextPage, NULL);
bHandled = true;
return 0;
}
Expand All @@ -279,7 +279,7 @@ LRESULT WeaselPanel::OnLeftClicked(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL
if(prc.PtInRect(point)) {
bool nextPage = true;
if(_UICallback)
_UICallback(NULL, NULL, &nextPage);
_UICallback(NULL, NULL, &nextPage, NULL);
bHandled = true;
return 0;
}
Expand All @@ -293,7 +293,7 @@ LRESULT WeaselPanel::OnLeftClicked(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL
if (rect.PtInRect(point))
{
if(_UICallback)
_UICallback(&i, NULL, NULL);
_UICallback(&i, NULL, NULL, NULL);
break;
}
}
Expand All @@ -316,7 +316,7 @@ LRESULT WeaselPanel::OnMouseHover(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
if (rect.PtInRect(point) && i != m_ctx.cinfo.highlighted)
{
if (_UICallback)
_UICallback(NULL, &i, NULL);
_UICallback(NULL, &i, NULL, NULL);
}
}
bHandled = true;
Expand Down
2 changes: 1 addition & 1 deletion WeaselUI/WeaselPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,5 @@ class WeaselPanel :
bool hide_candidates;
// for multi font_face & font_point
PDWR pDWR;
std::function<void(size_t *const, size_t *const, bool *const)>& _UICallback;
std::function<void(size_t *const, size_t *const, bool *const, bool* const)>& _UICallback;
};
6 changes: 3 additions & 3 deletions include/WeaselUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ namespace weasel
PDWR pdwr() { return pDWR; }
bool GetIsReposition();

std::function<void(size_t* const, size_t* const, bool* const)>& uiCallback() { return _UICallback; }
void SetUICallBack(std::function<void(size_t* const, size_t* const, bool* const)> const & func) { _UICallback = func; }
std::function<void(size_t* const, size_t* const, bool* const, bool* const)>& uiCallback() { return _UICallback; }
void SetUICallBack(std::function<void(size_t* const, size_t* const, bool* const, bool* const)> const & func) { _UICallback = func; }

private:
UIImpl* pimpl_;
Expand All @@ -94,7 +94,7 @@ namespace weasel
Status status_;
UIStyle style_;
UIStyle ostyle_;
std::function<void(size_t* const, size_t* const, bool* const)> _UICallback;
std::function<void(size_t* const, size_t* const, bool* const, bool* const)> _UICallback;
};

class DirectWriteResources
Expand Down

0 comments on commit 8f62c9c

Please sign in to comment.