From eee8d9bb1c11cbfd1da99ccbf622acce5b467b32 Mon Sep 17 00:00:00 2001 From: jsmorley Date: Fri, 10 Sep 2010 17:29:30 +0000 Subject: [PATCH] Changed ToolTip function to allow using %1, %2 etc. as appropriate for various meter types: Line, String: %1, %2, %3, ... Histogram: %1, %2 Others: %1 --- Application/Application.rc | 8 ++-- Library/Meter.cpp | 89 +++++++++++++++++++++++++++++++++++--- Library/Meter.h | 6 +++ Library/MeterHistogram.cpp | 1 + Library/MeterLine.cpp | 1 + Library/MeterString.cpp | 1 + Library/MeterWindow.cpp | 12 ++--- revision-number.h | 2 +- 8 files changed, 103 insertions(+), 17 deletions(-) diff --git a/Application/Application.rc b/Application/Application.rc index df88d856..5c3065b0 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,520 - PRODUCTVERSION 1,3,0,520 + FILEVERSION 1,3,0,530 + PRODUCTVERSION 1,3,0,530 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, 520" + VALUE "FileVersion", "1, 3, 0, 530" VALUE "InternalName", "Rainmeter" VALUE "LegalCopyright", "Copyright (C) 2010 - Rainy" VALUE "OriginalFilename", "Rainmeter.exe" VALUE "ProductName", "Rainmeter" - VALUE "ProductVersion", "1, 3, 0, 520" + VALUE "ProductVersion", "1, 3, 0, 530" END END BLOCK "VarFileInfo" diff --git a/Library/Meter.cpp b/Library/Meter.cpp index 8b1faf1e..ba9197fb 100644 --- a/Library/Meter.cpp +++ b/Library/Meter.cpp @@ -490,6 +490,80 @@ bool CMeter::Update() return true; } +/* +** SetAllMeasures +** +** Creates a vector containing all the defined measures (Histogram) +*/ +void CMeter::SetAllMeasures(CMeasure* measure) +{ + m_AllMeasures.clear(); + m_AllMeasures.push_back(m_Measure); + m_AllMeasures.push_back(measure); +} + +void CMeter::SetAllMeasures(std::vector measures) +{ + m_AllMeasures.clear(); + m_AllMeasures.push_back(m_Measure); + + std::vector::const_iterator i = measures.begin(); + for( ; i != measures.end(); ++i) + { + m_AllMeasures.push_back(*i); + } +} + +/* +** ReplaceMeasures +** +** Replaces %1, %2 etc with the corresponding measure value +*/ +std::wstring CMeter::ReplaceMeasures(std::wstring source) +{ + std::vector stringValues; + + if (!m_AllMeasures.empty()) + { + stringValues.push_back(m_AllMeasures.front()->GetStringValue(true, 1, 0, false)); + // Get the values for the other measures + for (size_t i = 1; i < m_AllMeasures.size(); ++i) + { + stringValues.push_back(m_AllMeasures[i]->GetStringValue(true, 1, 0, false)); + } + } + else if (m_Measure != NULL) + { + stringValues.push_back(m_Measure->GetStringValue(true, 1, 0, false)); + } + else + { + return source; + } + + WCHAR buffer[256]; + // Create the actual text (i.e. replace %1, %2, .. with the measure texts) + + for (size_t i = 0; i < stringValues.size(); ++i) + { + wsprintf(buffer, L"%%%i", i + 1); + + size_t start = 0; + size_t pos = std::wstring::npos; + + do + { + pos = source.find(buffer, start); + if (pos != std::wstring::npos) + { + source.replace(source.begin() + pos, source.begin() + pos + wcslen(buffer), stringValues[i]); + start = pos + stringValues[i].length(); + } + } while(pos != std::wstring::npos); + } + return source; +} + /* ** CreateToolTip ** @@ -535,7 +609,9 @@ void CMeter::CreateToolTip(CMeterWindow* meterWindow) ti.uFlags = TTF_SUBCLASS; ti.hwnd = m_MeterWindow->GetWindow(); ti.hinst = m_MeterWindow->GetMainObject()->GetInstance(); - ti.lpszText = (PTSTR) m_ToolTipText.c_str(); + + std::wstring text = ReplaceMeasures(m_ToolTipText); + ti.lpszText = (PTSTR) text.c_str(); ti.rect = GetMeterRect(); SendMessage(hwndTT, TTM_ADDTOOL, NULL, (LPARAM) (LPTOOLINFO) &ti); @@ -571,8 +647,8 @@ void CMeter::CreateToolTip(CMeterWindow* meterWindow) 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()); + text = ReplaceMeasures(m_ToolTipTitle); + SendMessage(hwndTT, TTM_SETTITLE, (WPARAM) hIcon, (LPARAM) text.c_str()); DestroyIcon(hIcon); } if (IsHidden()) @@ -597,7 +673,8 @@ void CMeter::UpdateToolTip() SendMessage(hwndTT, TTM_GETTOOLINFO, NULL, (LPARAM) (LPTOOLINFO) &ti); - ti.lpszText = (PTSTR) m_ToolTipText.c_str(); + std::wstring text = ReplaceMeasures(m_ToolTipText); + ti.lpszText = (PTSTR) text.c_str(); ti.rect = GetMeterRect(); SendMessage(hwndTT, TTM_SETTOOLINFO, NULL, (LPARAM) (LPTOOLINFO) &ti); @@ -632,8 +709,8 @@ void CMeter::UpdateToolTip() 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()); + text = ReplaceMeasures(m_ToolTipTitle); + SendMessage(hwndTT, TTM_SETTITLE, (WPARAM) hIcon, (LPARAM) text.c_str()); DestroyIcon(hIcon); } } diff --git a/Library/Meter.h b/Library/Meter.h index e0f50ff9..325360f6 100644 --- a/Library/Meter.h +++ b/Library/Meter.h @@ -64,6 +64,11 @@ public: std::wstring& GetMouseOverAction() { return m_MouseOverAction; }; std::wstring& GetMouseLeaveAction() { return m_MouseLeaveAction; }; + void SetAllMeasures(CMeasure* measure); + void SetAllMeasures(std::vector measures); + + std::wstring CMeter::ReplaceMeasures(std::wstring source); + std::wstring& GetToolTipText() { return m_ToolTipText; }; HWND GetToolTipHandle() { return m_ToolTipHandle; }; void SetToolTipHandle(HWND handle) { m_ToolTipHandle = handle; }; @@ -113,6 +118,7 @@ protected: std::wstring m_Name; // Name of the meter std::wstring m_MeasureName; // Name of the measure this is bound to CMeasure* m_Measure; // Pointer to the measure this meter is bound to + std::vector m_AllMeasures; int m_X; // X-position of the meter int m_Y; // Y-position of the meter int m_W; // Width of the meter diff --git a/Library/MeterHistogram.cpp b/Library/MeterHistogram.cpp index 3fb596bd..629c1204 100644 --- a/Library/MeterHistogram.cpp +++ b/Library/MeterHistogram.cpp @@ -569,6 +569,7 @@ void CMeterHistogram::BindMeasure(std::list& measures) if(_wcsicmp((*i)->GetName(), m_SecondaryMeasureName.c_str()) == 0) { m_SecondaryMeasure = (*i); + CMeter::SetAllMeasures(m_SecondaryMeasure); return; } } diff --git a/Library/MeterLine.cpp b/Library/MeterLine.cpp index 8e153b8f..875a6983 100644 --- a/Library/MeterLine.cpp +++ b/Library/MeterLine.cpp @@ -374,4 +374,5 @@ void CMeterLine::BindMeasure(std::list& measures) throw CError(std::wstring(L"The meter [") + m_Name + L"] cannot be bound with [" + (*j) + L"]!", __LINE__, __FILE__); } } + CMeter::SetAllMeasures(m_Measures); } diff --git a/Library/MeterString.cpp b/Library/MeterString.cpp index dd7d1630..0db1ff34 100644 --- a/Library/MeterString.cpp +++ b/Library/MeterString.cpp @@ -617,6 +617,7 @@ void CMeterString::BindMeasure(std::list& measures) throw CError(std::wstring(L"The meter [") + m_Name + L"] cannot be bound with [" + (*j) + L"]!", __LINE__, __FILE__); } } + CMeter::SetAllMeasures(m_Measures); } /* diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index 7239b5a4..995c83d5 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -1985,11 +1985,6 @@ bool CMeterWindow::ReadSkin() } meter->ReadConfig(strSection.c_str()); - - if (!meter->GetToolTipText().empty()) - { - meter->CreateToolTip(this); - } } } catch (CError& error) @@ -2021,13 +2016,18 @@ bool CMeterWindow::ReadSkin() } else { - // Bind the meters to the measures + // Bind the meters to the measures and create tooltips std::list::const_iterator j = m_Meters.begin(); for( ; j != m_Meters.end(); ++j) { try { (*j)->BindMeasure(m_Measures); + + if (!(*j)->GetToolTipText().empty()) + { + (*j)->CreateToolTip(this); + } } catch (CError& error) { diff --git a/revision-number.h b/revision-number.h index e4770d61..611d1392 100644 --- a/revision-number.h +++ b/revision-number.h @@ -1,3 +1,3 @@ #pragma once -const int revision_number = 520; +const int revision_number = 530; const bool revision_beta = true; \ No newline at end of file