From 651e6594b5fb7eafd5ea2b945f195d925c258ca0 Mon Sep 17 00:00:00 2001 From: Brian Ferguson Date: Tue, 13 Nov 2012 22:39:32 -0700 Subject: [PATCH] Added new Mouse actions. Added OnFocusAction/OnUnfocusAction. --- Library/MeterWindow.cpp | 191 ++++++++++++++++++++++++++++++++++++++++ Library/MeterWindow.h | 8 ++ Library/Mouse.cpp | 50 +++++++++++ Library/Mouse.h | 32 ++++++- 4 files changed, 280 insertions(+), 1 deletion(-) diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index 86e137d2..c51b2a83 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -1990,6 +1990,8 @@ bool CMeterWindow::ReadSkin() m_OnRefreshAction = m_Parser.ReadString(L"Rainmeter", L"OnRefreshAction", L"", false); m_OnCloseAction = m_Parser.ReadString(L"Rainmeter", L"OnCloseAction", L"", false); + m_OnFocusAction = m_Parser.ReadString(L"Rainmeter", L"OnFocusAction", L"", false); + m_OnUnfocusAction = m_Parser.ReadString(L"Rainmeter", L"OnUnfocusAction", L"", false); m_WindowUpdate = m_Parser.ReadInt(L"Rainmeter", L"Update", INTERVAL_METER); m_TransitionUpdate = m_Parser.ReadInt(L"Rainmeter", L"TransitionUpdate", INTERVAL_TRANSITION); @@ -3187,6 +3189,64 @@ LRESULT CMeterWindow::OnMouseLeave(UINT uMsg, WPARAM wParam, LPARAM lParam) return 0; } +/* +** When we get WM_MOUSEWHEEL messages. +** +*/ +LRESULT CMeterWindow::OnMouseScrollMove(UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + int delta = GET_WHEEL_DELTA_WPARAM(wParam); + + POINT pos; + pos.x = GET_X_LPARAM(lParam); + pos.y = GET_Y_LPARAM(lParam); + + MapWindowPoints(NULL, m_Window, &pos, 1); + + // Handle buttons + HandleButtons(pos, BUTTONPROC_MOVE); + + if (delta < 0) + { + DoAction(pos.x, pos.y, MOUSE_MW_DOWN, false); + } + else + { + DoAction(pos.x, pos.y, MOUSE_MW_UP, false); + } + + return 0; +} + +/* +** When we get WM_MOUSEHWHEEL messages. +** +*/ +LRESULT CMeterWindow::OnMouseHScrollMove(UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + int delta = GET_WHEEL_DELTA_WPARAM(wParam); + + POINT pos; + pos.x = GET_X_LPARAM(lParam); + pos.y = GET_Y_LPARAM(lParam); + + MapWindowPoints(NULL, m_Window, &pos, 1); + + // Handle buttons + HandleButtons(pos, BUTTONPROC_MOVE); + + if (delta < 0) + { + DoAction(pos.x, pos.y, MOUSE_MW_LEFT, false); + } + else + { + DoAction(pos.x, pos.y, MOUSE_MW_RIGHT, false); + } + + return 0; +} + /* ** Handle the menu commands. ** @@ -4014,6 +4074,127 @@ LRESULT CMeterWindow::OnMiddleButtonDoubleClick(UINT uMsg, WPARAM wParam, LPARAM return 0; } +/* +** Runs the action when a X mouse button is down +** +*/ +LRESULT CMeterWindow::OnXButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + POINT pos; + pos.x = GET_X_LPARAM(lParam); + pos.y = GET_Y_LPARAM(lParam); + + if (uMsg == WM_NCXBUTTONDOWN) + { + // Transform the point to client rect + MapWindowPoints(NULL, m_Window, &pos, 1); + } + + // Handle buttons + HandleButtons(pos, BUTTONPROC_MOVE); + + if (GET_XBUTTON_WPARAM (wParam) == XBUTTON1) + { + DoAction(pos.x, pos.y, MOUSE_X1MB_DOWN, false); + } + else if (GET_XBUTTON_WPARAM (wParam) == XBUTTON2) + { + DoAction(pos.x, pos.y, MOUSE_X2MB_DOWN, false); + } + + return 0; +} + +/* +** Runs the action when a X mouse button is up +** +*/ +LRESULT CMeterWindow::OnXButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + POINT pos; + pos.x = GET_X_LPARAM(lParam); + pos.y = GET_Y_LPARAM(lParam); + + if (uMsg == WM_NCXBUTTONUP) + { + // Transform the point to client rect + MapWindowPoints(NULL, m_Window, &pos, 1); + } + + // Handle buttons + HandleButtons(pos, BUTTONPROC_MOVE); + + if (GET_XBUTTON_WPARAM (wParam) == XBUTTON1) + { + DoAction(pos.x, pos.y, MOUSE_X1MB_UP, false); + } + else if (GET_XBUTTON_WPARAM (wParam) == XBUTTON2) + { + DoAction(pos.x, pos.y, MOUSE_X2MB_UP, false); + } + + return 0; +} + +/* +** Runs the action when a X mouse button is double-clicked +** +*/ +LRESULT CMeterWindow::OnXButtonDoubleClick(UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + POINT pos; + pos.x = GET_X_LPARAM(lParam); + pos.y = GET_Y_LPARAM(lParam); + + if (uMsg == WM_NCXBUTTONDBLCLK) + { + // Transform the point to client rect + MapWindowPoints(NULL, m_Window, &pos, 1); + } + + // Handle buttons + HandleButtons(pos, BUTTONPROC_MOVE); + + if (GET_XBUTTON_WPARAM (wParam) == XBUTTON1 && + !DoAction(pos.x, pos.y, MOUSE_X1MB_DBLCLK, false)) + { + DoAction(pos.x, pos.y, MOUSE_X1MB_DOWN, false); + } + else if (GET_XBUTTON_WPARAM (wParam) == XBUTTON2 && + !DoAction(pos.x, pos.y, MOUSE_X2MB_DBLCLK, false)) + { + DoAction(pos.x, pos.y, MOUSE_X2MB_DOWN, false); + } + + return 0; +} + +/* +** Runs the action when the MeterWindow gets or loses focus +** +*/ +LRESULT CMeterWindow::OnSetWindowFocus(UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch (uMsg) + { + case WM_SETFOCUS: + if (!m_OnFocusAction.empty()) + { + Rainmeter->ExecuteCommand(m_OnFocusAction.c_str(), this); + } + break; + + case WM_KILLFOCUS: + if (!m_OnUnfocusAction.empty()) + { + Rainmeter->ExecuteCommand(m_OnUnfocusAction.c_str(), this); + } + break; + } + + return 0; +} + /* ** Handles the context menu. The menu is recreated every time it is shown. ** @@ -4279,6 +4460,8 @@ LRESULT CALLBACK CMeterWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR MESSAGE(OnMouseMove, WM_NCMOUSEMOVE) MESSAGE(OnMouseLeave, WM_MOUSELEAVE) MESSAGE(OnMouseLeave, WM_NCMOUSELEAVE) + MESSAGE(OnMouseScrollMove, WM_MOUSEWHEEL) + MESSAGE(OnMouseHScrollMove, WM_MOUSEHWHEEL) MESSAGE(OnContextMenu, WM_CONTEXTMENU) MESSAGE(OnRightButtonDown, WM_NCRBUTTONDOWN) MESSAGE(OnRightButtonDown, WM_RBUTTONDOWN) @@ -4298,6 +4481,12 @@ LRESULT CALLBACK CMeterWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR MESSAGE(OnMiddleButtonUp, WM_NCMBUTTONUP) MESSAGE(OnMiddleButtonDoubleClick, WM_MBUTTONDBLCLK) MESSAGE(OnMiddleButtonDoubleClick, WM_NCMBUTTONDBLCLK) + MESSAGE(OnXButtonDown, WM_XBUTTONDOWN); + MESSAGE(OnXButtonDown, WM_NCXBUTTONDOWN); + MESSAGE(OnXButtonUp, WM_XBUTTONUP); + MESSAGE(OnXButtonUp, WM_NCXBUTTONUP); + MESSAGE(OnXButtonDoubleClick, WM_XBUTTONDBLCLK); + MESSAGE(OnXButtonDoubleClick, WM_NCXBUTTONDBLCLK); MESSAGE(OnWindowPosChanging, WM_WINDOWPOSCHANGING) MESSAGE(OnCopyData, WM_COPYDATA) MESSAGE(OnDelayedRefresh, WM_METERWINDOW_DELAYED_REFRESH) @@ -4306,6 +4495,8 @@ LRESULT CALLBACK CMeterWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR MESSAGE(OnDwmCompositionChange, WM_DWMCOMPOSITIONCHANGED) MESSAGE(OnSettingChange, WM_SETTINGCHANGE) MESSAGE(OnDisplayChange, WM_DISPLAYCHANGE) + MESSAGE(OnSetWindowFocus, WM_SETFOCUS) + MESSAGE(OnSetWindowFocus, WM_KILLFOCUS) END_MESSAGEPROC } diff --git a/Library/MeterWindow.h b/Library/MeterWindow.h index b673ca4d..90e783b2 100644 --- a/Library/MeterWindow.h +++ b/Library/MeterWindow.h @@ -261,6 +261,8 @@ protected: LRESULT OnEnterMenuLoop(UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT OnMouseLeave(UINT uMsg, WPARAM wParam, LPARAM lParam); + LRESULT OnMouseScrollMove(UINT uMsg, WPARAM wParam, LPARAM lParam); + LRESULT OnMouseHScrollMove(UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT OnLeftButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT OnRightButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam); @@ -271,6 +273,9 @@ protected: LRESULT OnLeftButtonDoubleClick(UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT OnRightButtonDoubleClick(UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT OnMiddleButtonDoubleClick(UINT uMsg, WPARAM wParam, LPARAM lParam); + LRESULT OnXButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam); + LRESULT OnXButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam); + LRESULT OnXButtonDoubleClick(UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT OnDelayedRefresh(UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT OnDelayedMove(UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT OnCopyData(UINT uMsg, WPARAM wParam, LPARAM lParam); @@ -278,6 +283,7 @@ protected: LRESULT OnDwmCompositionChange(UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT OnSettingChange(UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT OnDisplayChange(UINT uMsg, WPARAM wParam, LPARAM lParam); + LRESULT OnSetWindowFocus(UINT uMsg, WPARAM wParam, LPARAM lParam); private: enum OPTION @@ -354,6 +360,8 @@ private: std::wstring m_OnRefreshAction; std::wstring m_OnCloseAction; + std::wstring m_OnFocusAction; + std::wstring m_OnUnfocusAction; std::wstring m_BackgroundName; RECT m_BackgroundMargins; diff --git a/Library/Mouse.cpp b/Library/Mouse.cpp index fb52bf1d..824cb25f 100644 --- a/Library/Mouse.cpp +++ b/Library/Mouse.cpp @@ -49,6 +49,16 @@ void CMouse::ReadOptions(CConfigParser& parser, const WCHAR* section, CMeterWind m_MiddleDoubleClickAction = parser.ReadString(section, L"MiddleMouseDoubleClickAction", L"", false); m_OverAction = parser.ReadString(section, L"MouseOverAction", L"", false); m_LeaveAction = parser.ReadString(section, L"MouseLeaveAction", L"", false); + m_MouseScrollDownAction = parser.ReadString(section, L"MouseScrollDownAction", L"", false); + m_MouseScrollUpAction = parser.ReadString(section, L"MouseScrollUpAction", L"", false); + m_MouseScrollLeftAction = parser.ReadString(section, L"MouseScrollLeftAction", L"", false); + m_MouseScrollRightAction = parser.ReadString(section, L"MouseScrollRightAction", L"", false); + m_X1DownAction = parser.ReadString(section, L"X1MouseDownAction", L"", false); + m_X1UpAction = parser.ReadString(section, L"X1MouseUpAction", L"", false); + m_X1DoubleClickAction = parser.ReadString(section, L"X1MouseDoubleClickAction", L"", false); + m_X2DownAction = parser.ReadString(section, L"X2MouseDownAction", L"", false); + m_X2UpAction = parser.ReadString(section, L"X2MouseUpAction", L"", false); + m_X2DoubleClickAction = parser.ReadString(section, L"X2MouseDoubleClickAction", L"", false); m_CursorState = 0!=parser.ReadInt(section, L"MouseActionCursor", meterWindow->GetMouse().GetCursorState()); @@ -189,6 +199,46 @@ const WCHAR* CMouse::GetActionCommand(MOUSEACTION action) const case MOUSE_MMB_DBLCLK: command = m_MiddleDoubleClickAction.c_str(); break; + + case MOUSE_MW_DOWN: + command = m_MouseScrollDownAction.c_str(); + break; + + case MOUSE_MW_UP: + command = m_MouseScrollUpAction.c_str(); + break; + + case MOUSE_MW_LEFT: + command = m_MouseScrollLeftAction.c_str(); + break; + + case MOUSE_MW_RIGHT: + command = m_MouseScrollRightAction.c_str(); + break; + + case MOUSE_X1MB_DOWN: + command = m_X1DownAction.c_str(); + break; + + case MOUSE_X1MB_UP: + command = m_X1UpAction.c_str(); + break; + + case MOUSE_X1MB_DBLCLK: + command = m_X1DoubleClickAction.c_str(); + break; + + case MOUSE_X2MB_DOWN: + command = m_X2DownAction.c_str(); + break; + + case MOUSE_X2MB_UP: + command = m_X2UpAction.c_str(); + break; + + case MOUSE_X2MB_DBLCLK: + command = m_X2DoubleClickAction.c_str(); + break; } return *command ? command : NULL; diff --git a/Library/Mouse.h b/Library/Mouse.h index f4f6ea41..fc1ee5d0 100644 --- a/Library/Mouse.h +++ b/Library/Mouse.h @@ -31,7 +31,17 @@ enum MOUSEACTION MOUSE_MMB_UP, MOUSE_MMB_DBLCLK, MOUSE_OVER, - MOUSE_LEAVE + MOUSE_LEAVE, + MOUSE_MW_DOWN, + MOUSE_MW_UP, + MOUSE_MW_LEFT, + MOUSE_MW_RIGHT, + MOUSE_X1MB_DOWN, + MOUSE_X1MB_UP, + MOUSE_X1MB_DBLCLK, + MOUSE_X2MB_DOWN, + MOUSE_X2MB_UP, + MOUSE_X2MB_DBLCLK }; enum MOUSECURSOR @@ -73,6 +83,16 @@ public: const std::wstring& GetMiddleDoubleClickAction() const { return m_MiddleDoubleClickAction; } const std::wstring& GetOverAction() const { return m_OverAction; } const std::wstring& GetLeaveAction() const { return m_LeaveAction; } + const std::wstring& GetMouseScrollUpAction() const { return m_MouseScrollUpAction; } + const std::wstring& GetMouseScrollDownAction() const { return m_MouseScrollDownAction; } + const std::wstring& GetMouseScrollLeftAction() const { return m_MouseScrollLeftAction; } + const std::wstring& GetMouseScrollRightAction() const { return m_MouseScrollRightAction; } + const std::wstring& GetX1DownAction() const { return m_X1DownAction; } + const std::wstring& GetX1UpAction() const { return m_X1UpAction; } + const std::wstring& GetX1DoubleClickAction() const { return m_X1DoubleClickAction; } + const std::wstring& GetX2DownAction() const { return m_X2DownAction; } + const std::wstring& GetX2UpAction() const { return m_X2UpAction; } + const std::wstring& GetX2DoubleClickAction() const { return m_X2DoubleClickAction; } private: std::wstring m_LeftDownAction; @@ -86,6 +106,16 @@ private: std::wstring m_MiddleDoubleClickAction; std::wstring m_OverAction; std::wstring m_LeaveAction; + std::wstring m_MouseScrollDownAction; + std::wstring m_MouseScrollUpAction; + std::wstring m_MouseScrollLeftAction; + std::wstring m_MouseScrollRightAction; + std::wstring m_X1DownAction; + std::wstring m_X1UpAction; + std::wstring m_X1DoubleClickAction; + std::wstring m_X2DownAction; + std::wstring m_X2UpAction; + std::wstring m_X2DoubleClickAction; MOUSECURSOR m_CursorType; HCURSOR m_CustomCursor;