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
This commit is contained in:
jsmorley 2010-09-10 17:29:30 +00:00
parent 1343a3ae9e
commit eee8d9bb1c
8 changed files with 103 additions and 17 deletions

View File

@ -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"

View File

@ -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<CMeasure*> measures)
{
m_AllMeasures.clear();
m_AllMeasures.push_back(m_Measure);
std::vector<CMeasure*>::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<std::wstring> 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);
}
}

View File

@ -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<CMeasure*> 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<CMeasure*> 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

View File

@ -569,6 +569,7 @@ void CMeterHistogram::BindMeasure(std::list<CMeasure*>& measures)
if(_wcsicmp((*i)->GetName(), m_SecondaryMeasureName.c_str()) == 0)
{
m_SecondaryMeasure = (*i);
CMeter::SetAllMeasures(m_SecondaryMeasure);
return;
}
}

View File

@ -374,4 +374,5 @@ void CMeterLine::BindMeasure(std::list<CMeasure*>& measures)
throw CError(std::wstring(L"The meter [") + m_Name + L"] cannot be bound with [" + (*j) + L"]!", __LINE__, __FILE__);
}
}
CMeter::SetAllMeasures(m_Measures);
}

View File

@ -617,6 +617,7 @@ void CMeterString::BindMeasure(std::list<CMeasure*>& measures)
throw CError(std::wstring(L"The meter [") + m_Name + L"] cannot be bound with [" + (*j) + L"]!", __LINE__, __FILE__);
}
}
CMeter::SetAllMeasures(m_Measures);
}
/*

View File

@ -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<CMeter*>::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)
{

View File

@ -1,3 +1,3 @@
#pragma once
const int revision_number = 520;
const int revision_number = 530;
const bool revision_beta = true;