From ff153f3f867ba1164f0727a46e32f288722f2a3c Mon Sep 17 00:00:00 2001 From: jsmorley Date: Sat, 17 Jul 2010 00:06:24 +0000 Subject: [PATCH] Adding JamesAC's new ToolTips functionality. Minor fix to the Rainmeter installer Minor changes to RainBrowser and RainThemes --- Application/Application.rc | 8 +- Library/Meter.cpp | 166 +++++++++++++++++++++++++++++++++++++ Library/Meter.h | 15 ++++ Library/MeterWindow.cpp | 19 +++++ Library/MeterWindow.h | 2 + revision-number.h | 2 +- 6 files changed, 207 insertions(+), 5 deletions(-) diff --git a/Application/Application.rc b/Application/Application.rc index 5d349ccb..b87f7bd4 100644 --- a/Application/Application.rc +++ b/Application/Application.rc @@ -28,8 +28,8 @@ LANGUAGE LANG_FINNISH, SUBLANG_DEFAULT // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,3,0,466 - PRODUCTVERSION 1,3,0,466 + FILEVERSION 1,3,0,467 + PRODUCTVERSION 1,3,0,467 FILEFLAGSMASK 0x17L #ifdef _DEBUG FILEFLAGS 0x1L @@ -45,12 +45,12 @@ BEGIN BLOCK "040b04b0" BEGIN VALUE "FileDescription", "Rainmeter - A Customizable Resource Meter" - VALUE "FileVersion", "1, 3, 0, 466" + VALUE "FileVersion", "1, 3, 0, 467" VALUE "InternalName", "Rainmeter" VALUE "LegalCopyright", "Copyright (C) 2010 - Rainy" VALUE "OriginalFilename", "Rainmeter.exe" VALUE "ProductName", "Rainmeter" - VALUE "ProductVersion", "1, 3, 0, 466" + VALUE "ProductVersion", "1, 3, 0, 467" END END BLOCK "VarFileInfo" diff --git a/Library/Meter.cpp b/Library/Meter.cpp index 5d94da33..5cc427cf 100644 --- a/Library/Meter.cpp +++ b/Library/Meter.cpp @@ -184,6 +184,24 @@ int CMeter::GetY(bool abs) return m_Y; } +/* +** GetMeterRect +** +** Returns a RECT containing the dimensions of the meter within the MeterWindow +** +*/ +RECT CMeter::GetMeterRect() +{ + RECT meterRect; + + meterRect.left = GetX(); + meterRect.top = GetY(); + meterRect.right = GetX() + m_W; + meterRect.bottom = GetY() + m_H; + + return meterRect; +} + /* ** HitTest ** @@ -340,6 +358,11 @@ void CMeter::ReadConfig(const WCHAR* section) || !m_MiddleMouseUpAction.empty() || !m_MiddleMouseDownAction.empty() || !m_MiddleMouseDoubleClickAction.empty() || !m_RightMouseUpAction.empty() || !m_RightMouseDownAction.empty() || !m_RightMouseDoubleClickAction.empty() ); + m_ToolTipText = parser.ReadString(section, L"ToolTipText", L"", true); + m_ToolTipTitle = parser.ReadString(section, L"ToolTipTitle", L"", true); + m_ToolTipIcon = parser.ReadString(section, L"ToolTipIcon", L"", true); + m_ToolTipType = 0!=parser.ReadInt(section, L"ToolTipType", 0); + m_MeasureName = parser.ReadString(section, L"MeasureName", L""); m_UpdateDivider = parser.ReadInt(section, L"UpdateDivider", 1); @@ -466,6 +489,149 @@ bool CMeter::Update() return true; } +/* +** CreateToolTip +** +** Does the initial construction of the ToolTip for the meter +*/ +void CMeter::CreateToolTip(CMeterWindow* meterWindow) +{ + HWND hwndTT; + if(!m_ToolTipType) + { + hwndTT = CreateWindowEx(WS_EX_TOPMOST, + TOOLTIPS_CLASS, + NULL, + WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, + CW_USEDEFAULT, + CW_USEDEFAULT, + CW_USEDEFAULT, + CW_USEDEFAULT, + m_MeterWindow->GetWindow(), + NULL, + m_MeterWindow->GetMainObject()->GetInstance(), + NULL); + } + else + { + hwndTT = CreateWindowEx(WS_EX_TOPMOST, + TOOLTIPS_CLASS, + NULL, + WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP | TTS_BALLOON, + CW_USEDEFAULT, + CW_USEDEFAULT, + CW_USEDEFAULT, + CW_USEDEFAULT, + m_MeterWindow->GetWindow(), + NULL, + m_MeterWindow->GetMainObject()->GetInstance(), + NULL); + } + SetWindowPos(hwndTT, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); + + TOOLINFO ti = { 0 }; + ti.cbSize = sizeof(TOOLINFO); + ti.uFlags = TTF_SUBCLASS; + ti.hwnd = m_MeterWindow->GetWindow(); + ti.hinst = m_MeterWindow->GetMainObject()->GetInstance(); + ti.lpszText = (PTSTR) m_ToolTipText.c_str(); + ti.rect = GetMeterRect(); + + SendMessage(hwndTT, TTM_ADDTOOL, NULL, (LPARAM) (LPTOOLINFO) &ti); + + if (!m_ToolTipTitle.empty()) + { + HICON hIcon = NULL; + if (!m_ToolTipIcon.empty()) + { + if (!_wcsicmp(m_ToolTipIcon.c_str(), L"INFO")) + { + hIcon = (HICON) TTI_INFO; + } + else if (!_wcsicmp(m_ToolTipIcon.c_str(), L"WARNING")) + { + hIcon = (HICON) TTI_WARNING; + } + else if (!_wcsicmp(m_ToolTipIcon.c_str(), L"ERROR")) + { + hIcon = (HICON) TTI_ERROR; + } + else if (!_wcsicmp(m_ToolTipIcon.c_str(), L"QUESTION")) + { + hIcon = LoadIcon(NULL, IDI_QUESTION); + } + else if (!_wcsicmp(m_ToolTipIcon.c_str(), L"SHIELD")) + { + hIcon = LoadIcon(NULL, IDI_SHIELD); + } + else + { + hIcon = (HICON) LoadImage(NULL, m_ToolTipIcon.c_str(), IMAGE_ICON, 0, 0, LR_LOADFROMFILE); + } + } + + SendMessage(hwndTT, TTM_SETTITLE, (WPARAM) hIcon, (LPARAM) m_ToolTipTitle.c_str()); + DestroyIcon(hIcon); + } + m_ToolTipHandle = hwndTT; +} + +/* +** UpdateToolTip +** +** Updates the ToolTip to match new values +*/ +void CMeter::UpdateToolTip() +{ + HWND hwndTT = m_ToolTipHandle; + + TOOLINFO ti = { 0 }; + ti.cbSize = sizeof(TOOLINFO); + ti.hwnd = m_MeterWindow->GetWindow(); + + SendMessage(hwndTT, TTM_GETTOOLINFO, NULL, (LPARAM) (LPTOOLINFO) &ti); + + ti.lpszText = (PTSTR) m_ToolTipText.c_str(); + ti.rect = GetMeterRect(); + + SendMessage(hwndTT, TTM_SETTOOLINFO, NULL, (LPARAM) (LPTOOLINFO) &ti); + + if (!m_ToolTipTitle.empty()) + { + HICON hIcon = NULL; + if (!m_ToolTipIcon.empty()) + { + if (!_wcsicmp(m_ToolTipIcon.c_str(), L"INFO")) + { + hIcon = (HICON) TTI_INFO; + } + else if (!_wcsicmp(m_ToolTipIcon.c_str(), L"WARNING")) + { + hIcon = (HICON) TTI_WARNING; + } + else if (!_wcsicmp(m_ToolTipIcon.c_str(), L"ERROR")) + { + hIcon = (HICON) TTI_ERROR; + } + else if (!_wcsicmp(m_ToolTipIcon.c_str(), L"QUESTION")) + { + hIcon = LoadIcon(NULL, IDI_QUESTION); + } + else if (!_wcsicmp(m_ToolTipIcon.c_str(), L"SHIELD")) + { + hIcon = LoadIcon(NULL, IDI_SHIELD); + } + else + { + hIcon = (HICON) LoadImage(NULL, m_ToolTipIcon.c_str(), IMAGE_ICON, 0, 0, LR_LOADFROMFILE); + } + } + + SendMessage(hwndTT, TTM_SETTITLE, (WPARAM) hIcon, (LPARAM) m_ToolTipTitle.c_str()); + DestroyIcon(hIcon); + } +} + /* ** Draw ** diff --git a/Library/Meter.h b/Library/Meter.h index bf84f04e..d563c70d 100644 --- a/Library/Meter.h +++ b/Library/Meter.h @@ -47,6 +47,7 @@ public: virtual int GetW() { return m_Hidden ? 0 : m_W; }; virtual int GetX(bool abs = false); virtual int GetY(bool abs = false); + RECT GetMeterRect(); void SetX(int x) { m_X = x; m_RelativeX = POSITION_ABSOLUTE; }; void SetY(int y) { m_Y = y; m_RelativeY = POSITION_ABSOLUTE; }; @@ -63,6 +64,13 @@ public: std::wstring& GetMouseOverAction() { return m_MouseOverAction; }; std::wstring& GetMouseLeaveAction() { return m_MouseLeaveAction; }; + std::wstring& GetToolTipText() { return m_ToolTipText; }; + HWND GetToolTipHandle() { return m_ToolTipHandle; }; + void SetToolTipHandle(HWND handle) { m_ToolTipHandle = handle; }; + + void CreateToolTip(CMeterWindow* meterWindow); + void UpdateToolTip(); + bool HasMouseAction() { return m_HasMouseAction; }; bool HasMouseActionCursor() { return m_MouseActionCursor; }; void SetMouseActionCursor(bool b) { m_MouseActionCursor = b; }; @@ -113,6 +121,13 @@ protected: CMeter* m_RelativeMeter; bool m_DynamicVariables; // If true, the measure contains dynamic variables + std::wstring m_ToolTipText; + std::wstring m_ToolTipTitle; + std::wstring m_ToolTipIcon; + bool m_ToolTipType; + + HWND m_ToolTipHandle; + std::wstring m_RightMouseDownAction; // Actions for left and right and middle mouse buttons std::wstring m_RightMouseUpAction; std::wstring m_RightMouseDoubleClickAction; diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index 66f64cf5..697eaee6 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -333,6 +333,11 @@ void CMeterWindow::Refresh(bool init, bool all) std::list::iterator j = m_Meters.begin(); for( ; j != m_Meters.end(); ++j) { + if ((*j)->GetToolTipHandle() != NULL) + { + DestroyWindow((*j)->GetToolTipHandle()); + (*j)->SetToolTipHandle(NULL); + } delete (*j); } m_Meters.clear(); @@ -1840,6 +1845,11 @@ void CMeterWindow::ReadSkin() } meter->ReadConfig(strSection.c_str()); + + if (!meter->GetToolTipText().empty()) + { + meter->CreateToolTip(this); + } } } catch (CError& error) @@ -2320,6 +2330,15 @@ void CMeterWindow::Update(bool nodraw) Redraw(); } + j = m_Meters.begin(); + for ( ; j != m_Meters.end(); ++j) + { + if ((*j)->GetToolTipHandle() != NULL) + { + (*j)->UpdateToolTip(); + } + } + // Check for transitions and start the timer if necessary bool bActiveTransition = false; j = m_Meters.begin(); diff --git a/Library/MeterWindow.h b/Library/MeterWindow.h index df44ccb1..2228181e 100644 --- a/Library/MeterWindow.h +++ b/Library/MeterWindow.h @@ -129,6 +129,8 @@ public: int Initialize(CRainmeter& Rainmeter); + CRainmeter* GetMainObject() { return m_Rainmeter; }; + void RunBang(BANGCOMMAND bang, const WCHAR* arg); void MoveMeter(int x, int y, const WCHAR* name); diff --git a/revision-number.h b/revision-number.h index 95c0c195..5e91ba6b 100644 --- a/revision-number.h +++ b/revision-number.h @@ -1,2 +1,2 @@ #pragma once -const int revision_number = 466; \ No newline at end of file +const int revision_number = 467; \ No newline at end of file