From b65b26c2b772a90e6bccefbd717c4c6546ff62a8 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Wed, 1 Feb 2012 18:00:32 +0000 Subject: [PATCH] Cosmetic changes. --- Library/Export.cpp | 25 ++++++++------------ Library/MeterWindow.cpp | 51 ++++++++++++++++++++++------------------- Library/MeterWindow.h | 1 + 3 files changed, 38 insertions(+), 39 deletions(-) diff --git a/Library/Export.cpp b/Library/Export.cpp index 93f65094..9ae9b071 100644 --- a/Library/Export.cpp +++ b/Library/Export.cpp @@ -132,7 +132,7 @@ LPCWSTR PluginBridge(LPCWSTR command, LPCWSTR data) if (_wcsicmp(command, L"GetConfig") == 0) { - CMeterWindow *meterWindow = Rainmeter->GetMeterWindowByINI(data); + CMeterWindow* meterWindow = Rainmeter->GetMeterWindowByINI(data); if (meterWindow) { g_Buffer = L"\""; @@ -151,7 +151,7 @@ LPCWSTR PluginBridge(LPCWSTR command, LPCWSTR data) { const std::wstring& config = subStrings[0]; - CMeterWindow *meterWindow = Rainmeter->GetMeterWindow(config); + CMeterWindow* meterWindow = Rainmeter->GetMeterWindow(config); if (meterWindow) { WCHAR buf1[64]; @@ -171,7 +171,7 @@ LPCWSTR PluginBridge(LPCWSTR command, LPCWSTR data) { const std::wstring& config = subStrings[0]; - CMeterWindow *meterWindow = Rainmeter->GetMeterWindow(config); + CMeterWindow* meterWindow = Rainmeter->GetMeterWindow(config); if (meterWindow) { const std::wstring& variable = subStrings[1]; @@ -187,20 +187,15 @@ LPCWSTR PluginBridge(LPCWSTR command, LPCWSTR data) } else if (_wcsicmp(command, L"SetVariable") == 0) { - const WCHAR* pos = wcschr(data, L' '); - if (pos) - { - std::wstring config(data + 1, pos - 1); - std::vector subStrings = CRainmeter::ParseString(pos); + std::vector subStrings = CRainmeter::ParseString(data); - if (subStrings.size() == 2) + if (subStrings.size() == 3) + { + CMeterWindow* meterWindow = Rainmeter->GetMeterWindow(subStrings[0]); + if (meterWindow) { - CMeterWindow *meterWindow = Rainmeter->GetMeterWindow(config); - if (meterWindow) - { - meterWindow->RunBang(BANG_SETVARIABLE, subStrings); - return L"success"; - } + meterWindow->SetVariable(subStrings[1], subStrings[2]); + return L"success"; } } diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index 58ae59fa..19e3206d 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -843,9 +843,7 @@ void CMeterWindow::RunBang(BANGCOMMAND bang, const std::vector& ar break; case BANG_MOVE: - { - MoveWindow(_wtoi(args[0].c_str()), _wtoi(args[1].c_str())); - } + MoveWindow(_wtoi(args[0].c_str()), _wtoi(args[1].c_str())); break; case BANG_ZPOS: @@ -950,27 +948,7 @@ void CMeterWindow::RunBang(BANGCOMMAND bang, const std::vector& ar break; case BANG_SETVARIABLE: - { - const std::wstring& variable = args[0]; - const std::wstring& value = args[1]; - - // Formula read fine - double result; - if (m_Parser.ParseFormula(value, &result)) - { - WCHAR buffer[256]; - int len = _snwprintf_s(buffer, _TRUNCATE, L"%.5f", result); - CMeasure::RemoveTrailingZero(buffer, len); - - const std::wstring& resultString = buffer; - - m_Parser.SetVariable(variable, resultString); - } - else - { - m_Parser.SetVariable(variable, value); - } - } + SetVariable(args[0], args[1]); break; case BANG_SETOPTION: @@ -1384,6 +1362,31 @@ void CMeterWindow::UpdateMeasure(const std::wstring& name, bool group) if (!group) LogWithArgs(LOG_ERROR, L"!UpdateMeasure: [%s] not found in \"%s\"", measure, m_SkinName.c_str()); } +/* +** SetVariable +** +** Sets variable to given value. +** +*/ +void CMeterWindow::SetVariable(const std::wstring& variable, const std::wstring& value) +{ + double result; + if (m_Parser.ParseFormula(value, &result)) + { + WCHAR buffer[256]; + int len = _snwprintf_s(buffer, _TRUNCATE, L"%.5f", result); + CMeasure::RemoveTrailingZero(buffer, len); + + const std::wstring& resultString = buffer; + + m_Parser.SetVariable(variable, resultString); + } + else + { + m_Parser.SetVariable(variable, value); + } +} + /* ** SetOption ** diff --git a/Library/MeterWindow.h b/Library/MeterWindow.h index 6243f0bc..13a46250 100644 --- a/Library/MeterWindow.h +++ b/Library/MeterWindow.h @@ -181,6 +181,7 @@ public: void UpdateMeasure(const std::wstring& name, bool group = false); void Refresh(bool init, bool all = false); void Redraw(); + void SetVariable(const std::wstring& variable, const std::wstring& value); void SetOption(const std::wstring& section, const std::wstring& option, const std::wstring& value, bool group); void SetMouseLeaveEvent(bool cancel);