Skip to content

Commit

Permalink
feat: style/mouse_hover_ms to configure if to use hover feature, set …
Browse files Browse the repository at this point in the history
…0 to disable it.

code: remove USE_MOUSE_EVENT/USE_MOUSE_HOVER macro
  • Loading branch information
fxliang committed Jul 20, 2023
1 parent 7ee5ba0 commit b00ee09
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 22 deletions.
1 change: 1 addition & 0 deletions RimeWithWeasel/RimeWithWeasel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, UIStyle::PreeditType> _preeditMap = {
Expand Down
11 changes: 3 additions & 8 deletions WeaselUI/WeaselPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 0 additions & 12 deletions WeaselUI/WeaselPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<WeaselPanel>)
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();
Expand All @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions include/WeaselCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions output/data/weasel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b00ee09

Please sign in to comment.