Changed the behavior of DynamicVariables. The fixed value definition of the following settings is handled as the starting value. If the value definition of these settings contains variables or measures, related !bangs are ignored.

[Measure]
Disabled

[Meter]
Hidden
X
Y

In case of "Hidden":
- Hidden not added or Hidden=0/1 (=fixed value specified) and DynamicVariables=1
The specified value is handled as the starting value. After that the value is not re-read on every update. !RainmeterShowMeter etc. are enabled.

- Hidden=#VAR# or Hidden=[Measure] and DynamicVariables=1
The value is re-read on every update. !RainmeterShowMeter etc. are disabled by re-reading value.
This commit is contained in:
spx 2010-06-01 14:55:52 +00:00
parent 5ff8f59ebf
commit f2682eaee0
7 changed files with 217 additions and 113 deletions

View File

@ -400,8 +400,10 @@ void CConfigParser::SetAutoSelectedMonitorVariables(CMeterWindow* meterWindow)
**
** \param result The string where the variables are returned. The string is modified.
*/
void CConfigParser::ReplaceVariables(std::wstring& result)
bool CConfigParser::ReplaceVariables(std::wstring& result)
{
bool replaced = false;
CRainmeter::ExpandEnvironmentVariables(result);
if (c_MonitorVariables.empty())
@ -432,6 +434,7 @@ void CConfigParser::ReplaceVariables(std::wstring& result)
// Variable found, replace it with the value
result.replace(result.begin() + pos, result.begin() + end + 1, (*iter).second);
start = pos + (*iter).second.length();
replaced = true;
}
else
{
@ -441,6 +444,7 @@ void CConfigParser::ReplaceVariables(std::wstring& result)
// SCREENAREA/WORKAREA variable found, replace it with the value
result.replace(result.begin() + pos, result.begin() + end + 1, (*iter2).second);
start = pos + (*iter2).second.length();
replaced = true;
}
else
{
@ -458,6 +462,73 @@ void CConfigParser::ReplaceVariables(std::wstring& result)
loop = false;
}
} while(loop);
return replaced;
}
/**
** Replaces measures in the given string.
**
** \param result The string where the measure values are returned. The string is modified.
*/
bool CConfigParser::ReplaceMeasures(std::wstring& result)
{
bool replaced = false;
// Check for measures ([Measure])
if (!m_Measures.empty())
{
size_t start = 0;
size_t end = std::wstring::npos;
size_t pos = std::wstring::npos;
size_t pos2 = std::wstring::npos;
bool loop = true;
do
{
pos = result.find(L'[', start);
if (pos != std::wstring::npos)
{
end = result.find(L']', pos + 1);
if (end != std::wstring::npos)
{
pos2 = result.find(L'[', pos + 1);
if (pos2 == std::wstring::npos || end < pos2)
{
std::wstring var(result.begin() + pos + 1, result.begin() + end);
std::map<std::wstring, CMeasure*>::const_iterator iter = m_Measures.find(var);
if (iter != m_Measures.end())
{
std::wstring value = (*iter).second->GetStringValue(false, 1, 5, false);
// Measure found, replace it with the value
result.replace(result.begin() + pos, result.begin() + end + 1, value);
start = pos + value.length();
replaced = true;
}
else
{
start = end;
}
}
else
{
start = pos2;
}
}
else
{
loop = false;
}
}
else
{
loop = false;
}
} while(loop);
}
return replaced;
}
/*
@ -465,7 +536,7 @@ void CConfigParser::ReplaceVariables(std::wstring& result)
**
**
*/
const std::wstring& CConfigParser::ReadString(LPCTSTR section, LPCTSTR key, LPCTSTR defValue, bool bReplaceMeasures)
const std::wstring& CConfigParser::ReadString(LPCTSTR section, LPCTSTR key, LPCTSTR defValue, bool bReplaceMeasures, bool* bReplaced)
{
static std::wstring result;
@ -509,58 +580,16 @@ const std::wstring& CConfigParser::ReadString(LPCTSTR section, LPCTSTR key, LPCT
}
}
ReplaceVariables(result);
bool replaced = ReplaceVariables(result);
// Check for measures ([Measure])
if (!m_Measures.empty() && bReplaceMeasures)
if (bReplaceMeasures)
{
size_t start = 0;
size_t end = std::wstring::npos;
size_t pos = std::wstring::npos;
size_t pos2 = std::wstring::npos;
bool loop = true;
do
{
pos = result.find(L'[', start);
if (pos != std::wstring::npos)
{
end = result.find(L']', pos + 1);
if (end != std::wstring::npos)
{
pos2 = result.find(L'[', pos + 1);
if (pos2 == std::wstring::npos || end < pos2)
{
std::wstring var(result.begin() + pos + 1, result.begin() + end);
std::map<std::wstring, CMeasure*>::const_iterator iter = m_Measures.find(var);
if (iter != m_Measures.end())
{
std::wstring value = (*iter).second->GetStringValue(false, 1, 5, false);
// Measure found, replace it with the value
result.replace(result.begin() + pos, result.begin() + end + 1, value);
start = pos + value.length();
}
else
{
start = end;
}
}
else
{
start = pos2;
}
}
else
{
loop = false;
}
}
else
{
loop = false;
}
} while(loop);
replaced |= ReplaceMeasures(result);
}
if (bReplaced)
{
*bReplaced = replaced;
}
return result;

View File

@ -45,7 +45,7 @@ public:
void ResetVariables(CRainmeter* pRainmeter, CMeterWindow* meterWindow = NULL);
const std::wstring& ReadString(LPCTSTR section, LPCTSTR key, LPCTSTR defValue, bool bReplaceMeasures = true);
const std::wstring& ReadString(LPCTSTR section, LPCTSTR key, LPCTSTR defValue, bool bReplaceMeasures = true, bool* bReplaced = NULL);
double ReadFloat(LPCTSTR section, LPCTSTR key, double defValue);
double ReadFormula(LPCTSTR section, LPCTSTR key, double defValue);
int ReadInt(LPCTSTR section, LPCTSTR key, int defValue);
@ -68,7 +68,8 @@ public:
private:
void SetDefaultVariables(CRainmeter* pRainmeter, CMeterWindow* meterWindow);
void ReadVariables();
void ReplaceVariables(std::wstring& result);
bool ReplaceVariables(std::wstring& result);
bool ReplaceMeasures(std::wstring& result);
void ReadIniFile(const std::wstring& strFileName, int depth = 0);
void SetValue(const std::wstring& strSection, const std::wstring& strKey, const std::wstring& strValue);

View File

@ -68,6 +68,7 @@ CMeasure::CMeasure(CMeterWindow* meterWindow)
m_AveragePos = 0;
m_AverageSize = 0;
m_DynamicVariables = false;
m_Initialized = false;
m_MeterWindow = meterWindow;
}
@ -82,6 +83,17 @@ CMeasure::~CMeasure()
{
}
/*
** Initialize
**
** Initializes the measure.
**
*/
void CMeasure::Initialize()
{
m_Initialized = true;
}
/*
** ReadConfig
**
@ -91,6 +103,8 @@ CMeasure::~CMeasure()
*/
void CMeasure::ReadConfig(CConfigParser& parser, const WCHAR* section)
{
bool replaced;
// Clear substitutes to prevent from being added more than once.
if (!m_Substitute.empty())
{
@ -98,7 +112,20 @@ void CMeasure::ReadConfig(CConfigParser& parser, const WCHAR* section)
}
m_Invert = 0!=parser.ReadInt(section, L"InvertMeasure", 0);
m_Disabled = 0!=parser.ReadInt(section, L"Disabled", m_Disabled);
if (!m_Initialized)
{
m_Disabled = 0!=parser.ReadInt(section, L"Disabled", 0);
}
else
{
replaced = false;
const std::wstring& result = parser.ReadString(section, L"Disabled", L"0", true, &replaced);
if (replaced)
{
m_Disabled = 0!=(int)parser.ParseDouble(result, 0.0, true);
}
}
UINT updateDivider = parser.ReadInt(section, L"UpdateDivider", 1);
if (updateDivider != m_UpdateDivider)

View File

@ -31,6 +31,7 @@ public:
virtual ~CMeasure();
virtual void ReadConfig(CConfigParser& parser, const WCHAR* section);
virtual void Initialize();
virtual bool Update() = 0;
virtual const WCHAR* GetStats();
@ -97,6 +98,7 @@ protected:
bool m_Disabled; // Status of the measure
UINT m_UpdateDivider; // Divider for the update
UINT m_UpdateCounter; // Current update counter
bool m_Initialized;
CMeterWindow* m_MeterWindow;
};

View File

@ -209,7 +209,8 @@ bool CMeter::HitTest(int x, int y)
*/
void CMeter::ReadConfig(const WCHAR* section)
{
WCHAR buffer[256];
bool replaced;
CConfigParser& parser = m_MeterWindow->GetParser();
// The MeterStyle defines a template where the values are read if the meter doesn't have it itself
@ -219,82 +220,101 @@ void CMeter::ReadConfig(const WCHAR* section)
parser.SetStyleTemplate(style);
}
wsprintf(buffer, L"%i%c", m_X, (m_RelativeX == POSITION_RELATIVE_TL) ? L'r' : (m_RelativeX == POSITION_RELATIVE_BR) ? L'R' : L'');
std::wstring coord = parser.ReadString(section, L"X", buffer);
if (!coord.empty())
replaced = false;
std::wstring coord = parser.ReadString(section, L"X", L"0", true, &replaced);
if (!m_Initialized || replaced)
{
size_t len = coord.size();
if (coord[len - 1] == L'r')
if (!coord.empty())
{
m_RelativeX = POSITION_RELATIVE_TL;
coord.erase(--len);
}
else if (coord[len - 1] == L'R')
{
m_RelativeX = POSITION_RELATIVE_BR;
coord.erase(--len);
size_t len = coord.size();
if (coord[len - 1] == L'r')
{
m_RelativeX = POSITION_RELATIVE_TL;
coord.erase(--len);
}
else if (coord[len - 1] == L'R')
{
m_RelativeX = POSITION_RELATIVE_BR;
coord.erase(--len);
}
else
{
m_RelativeX = POSITION_ABSOLUTE;
}
double val;
if (len >= 2 && coord[0] == L'(' && coord[len - 1] == L')' && -1 != parser.ReadFormula(coord, &val))
{
m_X = (int)val;
}
else
{
m_X = (int)parser.ParseDouble(coord, 0.0);
}
}
else
{
m_X = 0;
m_RelativeX = POSITION_ABSOLUTE;
}
}
double val;
if (len >= 2 && coord[0] == L'(' && coord[len - 1] == L')' && -1 != parser.ReadFormula(coord, &val))
replaced = false;
coord = parser.ReadString(section, L"Y", L"0", true, &replaced);
if (!m_Initialized || replaced)
{
if (!coord.empty())
{
m_X = (int)val;
}
else
{
m_X = (int)parser.ParseDouble(coord, 0.0);
}
}
else
{
m_X = 0;
m_RelativeX = POSITION_ABSOLUTE;
}
wsprintf(buffer, L"%i%c", m_Y, (m_RelativeY == POSITION_RELATIVE_TL) ? L'r' : (m_RelativeY == POSITION_RELATIVE_BR) ? L'R' : L'');
coord = parser.ReadString(section, L"Y", buffer);
if (!coord.empty())
{
size_t len = coord.size();
if (coord[len - 1] == L'r')
{
m_RelativeY = POSITION_RELATIVE_TL;
coord.erase(--len);
}
else if (coord[len - 1] == L'R')
{
m_RelativeY = POSITION_RELATIVE_BR;
coord.erase(--len);
size_t len = coord.size();
if (coord[len - 1] == L'r')
{
m_RelativeY = POSITION_RELATIVE_TL;
coord.erase(--len);
}
else if (coord[len - 1] == L'R')
{
m_RelativeY = POSITION_RELATIVE_BR;
coord.erase(--len);
}
else
{
m_RelativeY = POSITION_ABSOLUTE;
}
double val;
if (len >= 2 && coord[0] == L'(' && coord[len - 1] == L')' && -1 != parser.ReadFormula(coord, &val))
{
m_Y = (int)val;
}
else
{
m_Y = (int)parser.ParseDouble(coord, 0.0);
}
}
else
{
m_Y = 0;
m_RelativeY = POSITION_ABSOLUTE;
}
double val;
if (len >= 2 && coord[0] == L'(' && coord[len - 1] == L')' && -1 != parser.ReadFormula(coord, &val))
{
m_Y = (int)val;
}
else
{
m_Y = (int)parser.ParseDouble(coord, 0.0);
}
}
else
{
m_Y = 0;
m_RelativeY = POSITION_ABSOLUTE;
}
m_W = (int)parser.ReadFormula(section, L"W", 1.0);
m_H = (int)parser.ReadFormula(section, L"H", 1.0);
m_Hidden = 0!=parser.ReadInt(section, L"Hidden", m_Hidden);
if (!m_Initialized)
{
m_Hidden = 0!=parser.ReadInt(section, L"Hidden", 0);
}
else
{
replaced = false;
const std::wstring& result = parser.ReadString(section, L"Hidden", L"0", true, &replaced);
if (replaced)
{
m_Hidden = 0!=(int)parser.ParseDouble(result, 0.0, true);
}
}
m_SolidBevel = (BEVELTYPE)parser.ReadInt(section, L"BevelType", BEVELTYPE_NONE);
m_SolidColor = parser.ReadColor(section, L"SolidColor", Color(0, 0, 0, 0));

View File

@ -354,6 +354,7 @@ void CMeterWindow::Refresh(bool init, bool all)
ReadConfig(); // Read the general settings
ReadSkin();
InitializeMeasures();
InitializeMeters();
// Remove transparent flag
@ -1820,6 +1821,29 @@ void CMeterWindow::ReadSkin()
}
}
/*
** InitializeMeasures
**
** Initializes all the measures
**
*/
void CMeterWindow::InitializeMeasures()
{
// Initalize all measures
std::list<CMeasure*>::const_iterator i = m_Measures.begin();
for( ; i != m_Measures.end(); ++i)
{
try
{
(*i)->Initialize();
}
catch (CError& error)
{
MessageBox(m_Window, error.GetString().c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION);
}
}
}
/*
** InitializeMeters
**

View File

@ -227,6 +227,7 @@ private:
void ReadConfig();
void WriteConfig();
void ReadSkin();
void InitializeMeasures();
void InitializeMeters();
void ShowWindowIfAppropriate();
bool DoAction(int x, int y, MOUSE mouse, bool test);