diff --git a/RimeWithWeasel/RimeWithWeasel.cpp b/RimeWithWeasel/RimeWithWeasel.cpp index 7525e5a17..e60411160 100644 --- a/RimeWithWeasel/RimeWithWeasel.cpp +++ b/RimeWithWeasel/RimeWithWeasel.cpp @@ -806,6 +806,7 @@ static void _UpdateUIStyle(RimeConfig* config, UI* ui, bool initialize) style.font_point = 12; _RimeGetIntWithFallback(config, "style/label_font_point", &style.label_font_point, "style/font_point", _abs); _RimeGetIntWithFallback(config, "style/comment_font_point", &style.comment_font_point, "style/font_point", _abs); + _RimeGetIntWithFallback(config, "style/mouse_hover_ms", &style.mouse_hover_ms, NULL, _abs); _RimeGetBool(config, "style/inline_preedit", initialize, style.inline_preedit, true, false); _RimeGetBool(config, "style/vertical_auto_reverse", initialize, style.vertical_auto_reverse, true, false); const std::map _preeditMap = { diff --git a/WeaselUI/WeaselPanel.cpp b/WeaselUI/WeaselPanel.cpp index ae3861de2..a74079f18 100644 --- a/WeaselUI/WeaselPanel.cpp +++ b/WeaselUI/WeaselPanel.cpp @@ -161,7 +161,6 @@ void WeaselPanel::_InitFontRes(void) dpi = dpiX; } -#ifdef USE_MOUSE_EVENTS static HBITMAP CopyDCToBitmap(HDC hDC, LPRECT lpRect) { if (!hDC || !lpRect || IsRectEmpty(lpRect)) return NULL; @@ -289,9 +288,9 @@ LRESULT WeaselPanel::OnLeftClicked(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL return 0; } -#ifdef USE_MOUSE_HOVER LRESULT WeaselPanel::OnMouseHover(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { + if(!m_style.mouse_hover_ms) return 0; CPoint point; point.x = GET_X_LPARAM(lParam); point.y = GET_Y_LPARAM(lParam); @@ -312,12 +311,12 @@ LRESULT WeaselPanel::OnMouseHover(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& LRESULT WeaselPanel::OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { - if (m_mouse_entry == false) + if (m_mouse_entry == false && m_style.mouse_hover_ms) { TRACKMOUSEEVENT tme; tme.cbSize = sizeof(TRACKMOUSEEVENT); tme.dwFlags = TME_HOVER | TME_LEAVE; - tme.dwHoverTime = 400; // 400 ms + tme.dwHoverTime = m_style.mouse_hover_ms; // unit: ms tme.hwndTrack = m_hWnd; TrackMouseEvent(&tme); } @@ -329,8 +328,6 @@ LRESULT WeaselPanel::OnMouseLeave(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& m_mouse_entry = false; return 0; } -#endif /* USE_MOUSE_HOVER */ -#endif /* USE_MOUSE_EVENTS */ void WeaselPanel::_HighlightText(CDCHandle &dc, CRect rc, COLORREF color, COLORREF shadowColor, int radius, BackType type = BackType::TEXT, IsToRoundStruct rd = IsToRoundStruct(), COLORREF bordercolor=TRANS_COLOR) { @@ -797,10 +794,8 @@ void WeaselPanel::DoPaint(CDCHandle dc) } _LayerUpdate(rcw, memDC); -#ifdef USE_MOUSE_EVENTS // turn off WS_EX_TRANSPARENT after drawings, for better resp performance ::SetWindowLong(m_hWnd, GWL_EXSTYLE, ::GetWindowLong(m_hWnd, GWL_EXSTYLE) & (~WS_EX_TRANSPARENT)); -#endif // clean objs ::DeleteDC(memDC); ::DeleteObject(memBitmap); diff --git a/WeaselUI/WeaselPanel.h b/WeaselUI/WeaselPanel.h index 37435c0e0..4eac7e12f 100644 --- a/WeaselUI/WeaselPanel.h +++ b/WeaselUI/WeaselPanel.h @@ -28,32 +28,24 @@ class WeaselPanel : MESSAGE_HANDLER(WM_CREATE, OnCreate) MESSAGE_HANDLER(WM_DESTROY, OnDestroy) MESSAGE_HANDLER(WM_DPICHANGED, OnDpiChanged) -#ifdef USE_MOUSE_EVENTS MESSAGE_HANDLER(WM_MOUSEACTIVATE, OnMouseActivate) MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLeftClicked) MESSAGE_HANDLER(WM_MOUSEWHEEL, OnMouseWheel) -#ifdef USE_MOUSE_HOVER MESSAGE_HANDLER(WM_MOUSEHOVER, OnMouseHover) MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove) MESSAGE_HANDLER(WM_MOUSELEAVE, OnMouseLeave) -#endif /* USE_MOUSE_HOVER */ -#endif /* USE_MOUSE_EVENTS */ CHAIN_MSG_MAP(CDoubleBufferImpl) END_MSG_MAP() LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnDpiChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); -#ifdef USE_MOUSE_EVENTS LRESULT OnMouseActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnLeftClicked(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnMouseWheel(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); -#ifdef USE_MOUSE_HOVER LRESULT OnMouseHover(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnMouseLeave(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); -#endif /* USE_MOUSE_HOVER */ -#endif /* USE_MOUSE_EVENTS */ WeaselPanel(weasel::UI &ui); ~WeaselPanel(); @@ -65,12 +57,8 @@ class WeaselPanel : private: void _InitFontRes(void); -#ifdef USE_MOUSE_EVENTS void _CaptureRect(CRect& rect); -#ifdef USE_MOUSE_HOVER bool m_mouse_entry = false; -#endif /* USE_MOUSE_HOVER */ -#endif /* USE_MOUSE_EVENTS */ void _CreateLayout(); void _ResizeWindow(); void _RepositionWindow(bool adj = false); diff --git a/include/WeaselCommon.h b/include/WeaselCommon.h index 7f2971c74..f71758828 100644 --- a/include/WeaselCommon.h +++ b/include/WeaselCommon.h @@ -9,8 +9,6 @@ #define WEASEL_REG_KEY L"Software\\Rime\\Weasel" #define RIME_REG_KEY L"Software\\Rime" -#define USE_MOUSE_EVENTS -#define USE_MOUSE_HOVER //#define USE_SHARP_COLOR_CODE //#define _DEBUG_ @@ -285,6 +283,7 @@ namespace weasel std::wstring font_face; std::wstring label_font_face; std::wstring comment_font_face; + int mouse_hover_ms; int font_point; int label_font_point; int comment_font_point; @@ -347,6 +346,7 @@ namespace weasel UIStyle() : font_face(), label_font_face(), comment_font_face(), + mouse_hover_ms(0), font_point(0), label_font_point(0), comment_font_point(0), @@ -421,6 +421,7 @@ namespace weasel || font_face != st.font_face || label_font_face != st.label_font_face || comment_font_face != st.comment_font_face + || mouse_hover_ms != st.mouse_hover_ms || font_point != st.font_point || label_font_point != st.label_font_point || comment_font_point != st.comment_font_point @@ -486,6 +487,7 @@ namespace boost { ar & s.font_face; ar & s.label_font_face; ar & s.comment_font_face; + ar & s.mouse_hover_ms; ar & s.font_point; ar & s.label_font_point; ar & s.comment_font_point; diff --git a/output/data/weasel.yaml b/output/data/weasel.yaml index 26937704a..4830e8d8c 100644 --- a/output/data/weasel.yaml +++ b/output/data/weasel.yaml @@ -26,6 +26,7 @@ style: display_tray_icon: false label_format: "%s." mark_text: "" + mouse_hover_ms: 0 vertical_auto_reverse: false vertical_text: false vertical_text_left_to_right: false