diff --git a/Library/ConfigParser.cpp b/Library/ConfigParser.cpp index 717f9be0..a530416e 100644 --- a/Library/ConfigParser.cpp +++ b/Library/ConfigParser.cpp @@ -664,7 +664,7 @@ bool CConfigParser::ReplaceMeasures(std::wstring& result) CMeasure* measure = GetMeasure(var); if (measure) { - const WCHAR* value = measure->GetStringValue(AUTOSCALE_OFF, 1, -1, false); + const WCHAR* value = measure->GetStringOrFormattedValue(AUTOSCALE_OFF, 1, -1, false); size_t valueLen = wcslen(value); // Measure found, replace it with the value diff --git a/Library/DialogAbout.cpp b/Library/DialogAbout.cpp index 770b7372..20b6bf34 100644 --- a/Library/DialogAbout.cpp +++ b/Library/DialogAbout.cpp @@ -807,7 +807,8 @@ void CDialogAbout::CTabSkins::UpdateMeasureList(CMeterWindow* meterWindow) range += buffer; ListView_SetItemText(item, lvi.iItem, 1, (WCHAR*)range.c_str()); - ListView_SetItemText(item, lvi.iItem, 2, (WCHAR*)(*j)->GetStringValue(AUTOSCALE_OFF, 1, -1, false)); + ListView_SetItemText(item, lvi.iItem, 2, (WCHAR*)(*j)->GetStringOrFormattedValue( + AUTOSCALE_OFF, 1, -1, false)); ++lvi.iItem; } diff --git a/Library/Measure.cpp b/Library/Measure.cpp index 0b3b71b0..6a5e7fa5 100644 --- a/Library/Measure.cpp +++ b/Library/Measure.cpp @@ -617,6 +617,26 @@ double CMeasure::GetValueRange() return m_MaxValue - m_MinValue; } +/* +** Base implementation. Derivied classes can provide an alternative implementation if they have a +** string value that is not based on m_Value. +** +*/ +const WCHAR* CMeasure::GetStringValue() +{ + return NULL; +} + +/* +** Returns the unformatted string value if the measure has one or a formatted value otherwise. +** +*/ +const WCHAR* CMeasure::GetStringOrFormattedValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual) +{ + const WCHAR* stringValue = GetStringValue(); + return stringValue ? stringValue : GetFormattedValue(autoScale, scale, decimals, percentual); +} + /* ** This method returns the value as text string. The actual value is ** get with GetValue() so we don't have to worry about m_Invert. @@ -626,7 +646,7 @@ double CMeasure::GetValueRange() ** decimals Number of decimals used in the value. If -1, get rid of ".00000" for dynamic variables. ** percentual Return the value as % from the maximum value. */ -const WCHAR* CMeasure::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual) +const WCHAR* CMeasure::GetFormattedValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual) { static WCHAR buffer[128]; WCHAR format[32]; @@ -737,7 +757,7 @@ void CMeasure::DoChangeAction(bool execute) if (!m_OnChangeAction.empty() && m_ValueAssigned) { double newValue = GetValue(); - const WCHAR* newStringValue = GetStringValue(AUTOSCALE_OFF, 1, -1, false); + const WCHAR* newStringValue = GetStringValue(); if (!m_OldValue) { diff --git a/Library/Measure.h b/Library/Measure.h index 5eb99235..183424d3 100644 --- a/Library/Measure.h +++ b/Library/Measure.h @@ -40,9 +40,34 @@ enum AUTOSCALE class CMeasureValueSet { public: - CMeasureValueSet(double val, const WCHAR* str) : m_Value(val), m_StringValue(str) {} - void Set(double val, const WCHAR* str) { m_Value = val; m_StringValue = str; } - bool IsChanged(double val, const WCHAR* str) { if (m_Value != val || wcscmp(m_StringValue.c_str(), str) != 0) { Set(val, str); return true; } return false; } + CMeasureValueSet(double val, const WCHAR* str) : m_Value(val), m_StringValue(str ? str : L"") {} + + void Set(double val, const WCHAR* str) + { + m_Value = val; + if (str) + { + m_StringValue = str; + } + else + { + m_StringValue.clear(); + } + } + + bool IsChanged(double val, const WCHAR* str) + { + if (m_Value != val || + (!str && !m_StringValue.empty()) || + (str && wcscmp(m_StringValue.c_str(), str) != 0)) + { + Set(val, str); + return true; + } + + return false; + } + private: double m_Value; std::wstring m_StringValue; @@ -74,7 +99,10 @@ public: double GetMinValue() { return m_MinValue; } double GetMaxValue() { return m_MaxValue; } - virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual); + virtual const WCHAR* GetStringValue(); + const WCHAR* GetStringOrFormattedValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual); + const WCHAR* GetFormattedValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual); + static void GetScaledValue(AUTOSCALE autoScale, int decimals, double theValue, WCHAR* buffer, size_t sizeInWords); static void RemoveTrailingZero(WCHAR* str, int strLen); diff --git a/Library/MeasureDiskSpace.cpp b/Library/MeasureDiskSpace.cpp index 14cf54eb..7105aea1 100644 --- a/Library/MeasureDiskSpace.cpp +++ b/Library/MeasureDiskSpace.cpp @@ -164,14 +164,9 @@ void CMeasureDiskSpace::UpdateValue() ** Returns the time as string. ** */ -const WCHAR* CMeasureDiskSpace::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual) +const WCHAR* CMeasureDiskSpace::GetStringValue() { - if (m_Type || m_Label) - { - return CheckSubstitute(m_StringValue.c_str()); - } - - return CMeasure::GetStringValue(autoScale, scale, decimals, percentual); + return (m_Type || m_Label) ? CheckSubstitute(m_StringValue.c_str()) : NULL; } /* diff --git a/Library/MeasureDiskSpace.h b/Library/MeasureDiskSpace.h index 9d3b9034..b33b435b 100644 --- a/Library/MeasureDiskSpace.h +++ b/Library/MeasureDiskSpace.h @@ -29,7 +29,7 @@ public: virtual UINT GetTypeID() { return TypeID(); } - virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual); + virtual const WCHAR* GetStringValue(); protected: virtual void ReadOptions(CConfigParser& parser, const WCHAR* section); diff --git a/Library/MeasurePlugin.cpp b/Library/MeasurePlugin.cpp index 88887f4d..48729378 100644 --- a/Library/MeasurePlugin.cpp +++ b/Library/MeasurePlugin.cpp @@ -213,7 +213,7 @@ void CMeasurePlugin::ReadOptions(CConfigParser& parser, const WCHAR* section) ** Gets the string value from the plugin. ** */ -const WCHAR* CMeasurePlugin::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual) +const WCHAR* CMeasurePlugin::GetStringValue() { if (m_GetStringFunc) { @@ -230,7 +230,7 @@ const WCHAR* CMeasurePlugin::GetStringValue(AUTOSCALE autoScale, double scale, i if (ret) return CheckSubstitute(ret); } - return CMeasure::GetStringValue(autoScale, scale, decimals, percentual); + return NULL; } /* diff --git a/Library/MeasurePlugin.h b/Library/MeasurePlugin.h index 3dedb406..49b26ab0 100644 --- a/Library/MeasurePlugin.h +++ b/Library/MeasurePlugin.h @@ -44,7 +44,7 @@ public: virtual UINT GetTypeID() { return TypeID(); } - virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual); + virtual const WCHAR* GetStringValue(); virtual void Command(const std::wstring& command); protected: diff --git a/Library/MeasureRegistry.cpp b/Library/MeasureRegistry.cpp index ac8b18bf..5390cb19 100644 --- a/Library/MeasureRegistry.cpp +++ b/Library/MeasureRegistry.cpp @@ -157,13 +157,8 @@ void CMeasureRegistry::ReadOptions(CConfigParser& parser, const WCHAR* section) ** value to string as normal. ** */ -const WCHAR* CMeasureRegistry::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual) +const WCHAR* CMeasureRegistry::GetStringValue() { - if (m_StringValue.empty()) - { - return CMeasure::GetStringValue(autoScale, scale, decimals, percentual); - } - - return CheckSubstitute(m_StringValue.c_str()); + return !m_StringValue.empty() ? CheckSubstitute(m_StringValue.c_str()) : NULL; } diff --git a/Library/MeasureRegistry.h b/Library/MeasureRegistry.h index dda358cb..3961a8ec 100644 --- a/Library/MeasureRegistry.h +++ b/Library/MeasureRegistry.h @@ -29,7 +29,7 @@ public: virtual UINT GetTypeID() { return TypeID(); } - virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual); + virtual const WCHAR* GetStringValue(); protected: virtual void ReadOptions(CConfigParser& parser, const WCHAR* section); diff --git a/Library/MeasureScript.cpp b/Library/MeasureScript.cpp index 7608dbc4..bb90afb6 100644 --- a/Library/MeasureScript.cpp +++ b/Library/MeasureScript.cpp @@ -76,14 +76,9 @@ void CMeasureScript::UpdateValue() ** Returns the value as a string. ** */ -const WCHAR* CMeasureScript::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual) +const WCHAR* CMeasureScript::GetStringValue() { - if (m_ValueType == LUA_TSTRING) - { - return CheckSubstitute(m_StringValue.c_str()); - } - - return CMeasure::GetStringValue(autoScale, scale, decimals, percentual); + return (m_ValueType == LUA_TSTRING) ? CheckSubstitute(m_StringValue.c_str()) : NULL; } /* diff --git a/Library/MeasureScript.h b/Library/MeasureScript.h index 069d943f..e567e672 100644 --- a/Library/MeasureScript.h +++ b/Library/MeasureScript.h @@ -29,7 +29,7 @@ public: virtual UINT GetTypeID() { return TypeID(); } - virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual); + virtual const WCHAR* GetStringValue(); virtual void Command(const std::wstring& command); void UninitializeLuaScript(); diff --git a/Library/MeasureTime.cpp b/Library/MeasureTime.cpp index 8f2d0c68..ba2a917f 100644 --- a/Library/MeasureTime.cpp +++ b/Library/MeasureTime.cpp @@ -163,7 +163,7 @@ void CMeasureTime::UpdateValue() ** Returns the time as string. ** */ -const WCHAR* CMeasureTime::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual) +const WCHAR* CMeasureTime::GetStringValue() { static WCHAR tmpSz[MAX_LINE_LENGTH]; struct tm today; diff --git a/Library/MeasureTime.h b/Library/MeasureTime.h index d97fa164..b1c6d359 100644 --- a/Library/MeasureTime.h +++ b/Library/MeasureTime.h @@ -29,7 +29,7 @@ public: virtual UINT GetTypeID() { return TypeID(); } - virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual); + virtual const WCHAR* GetStringValue(); protected: virtual void ReadOptions(CConfigParser& parser, const WCHAR* section); diff --git a/Library/MeasureUptime.cpp b/Library/MeasureUptime.cpp index ac615337..0848abef 100644 --- a/Library/MeasureUptime.cpp +++ b/Library/MeasureUptime.cpp @@ -72,7 +72,7 @@ void CMeasureUptime::UpdateValue() ** Returns the uptime as string. ** */ -const WCHAR* CMeasureUptime::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual) +const WCHAR* CMeasureUptime::GetStringValue() { static WCHAR buffer[MAX_LINE_LENGTH]; diff --git a/Library/MeasureUptime.h b/Library/MeasureUptime.h index f3961d82..82a4403a 100644 --- a/Library/MeasureUptime.h +++ b/Library/MeasureUptime.h @@ -29,7 +29,7 @@ public: virtual UINT GetTypeID() { return TypeID(); } - virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual); + virtual const WCHAR* GetStringValue(); protected: virtual void ReadOptions(CConfigParser& parser, const WCHAR* section); diff --git a/Library/Meter.cpp b/Library/Meter.cpp index 145cf11a..4dd8a0cb 100644 --- a/Library/Meter.cpp +++ b/Library/Meter.cpp @@ -501,7 +501,8 @@ bool CMeter::ReplaceMeasures(std::wstring& str, AUTOSCALE autoScale, double scal size_t len = _snwprintf_s(buffer, _TRUNCATE, L"%%%i", (int)i); size_t start = 0, pos; - const WCHAR* measureValue = m_Measures[i - 1]->GetStringValue(autoScale, scale, decimals, percentual); + const WCHAR* measureValue = m_Measures[i - 1]->GetStringOrFormattedValue( + autoScale, scale, decimals, percentual); int measureValueLen = wcslen(measureValue); do diff --git a/Library/MeterImage.cpp b/Library/MeterImage.cpp index e4d7d7b1..5dea0294 100644 --- a/Library/MeterImage.cpp +++ b/Library/MeterImage.cpp @@ -174,7 +174,8 @@ bool CMeterImage::Update() { if (m_ImageName.empty()) { - m_ImageNameResult = m_Measures[0]->GetStringValue(AUTOSCALE_OFF, 1, 0, false); + m_ImageNameResult = m_Measures[0]->GetStringOrFormattedValue( + AUTOSCALE_OFF, 1, 0, false); } else { @@ -182,7 +183,8 @@ bool CMeterImage::Update() if (!ReplaceMeasures(m_ImageNameResult, AUTOSCALE_OFF)) { // ImageName doesn't contain any measures, so use the result of MeasureName. - m_ImageNameResult = m_Measures[0]->GetStringValue(AUTOSCALE_OFF, 1, 0, false); + m_ImageNameResult = m_Measures[0]->GetStringOrFormattedValue( + AUTOSCALE_OFF, 1, 0, false); } } } diff --git a/Library/MeterString.cpp b/Library/MeterString.cpp index 3ff62099..3ab70853 100644 --- a/Library/MeterString.cpp +++ b/Library/MeterString.cpp @@ -360,7 +360,8 @@ bool CMeterString::Update() { if (m_Text.empty()) { - m_String += m_Measures[0]->GetStringValue(m_AutoScale, m_Scale, decimals, m_Percentual); + m_String += m_Measures[0]->GetStringOrFormattedValue( + m_AutoScale, m_Scale, decimals, m_Percentual); } else { diff --git a/Library/lua/glue/LuaMeasure.cpp b/Library/lua/glue/LuaMeasure.cpp index e483f236..ceab8824 100644 --- a/Library/lua/glue/LuaMeasure.cpp +++ b/Library/lua/glue/LuaMeasure.cpp @@ -126,7 +126,7 @@ static int GetStringValue(lua_State* L) int decimals = (int)lua_tonumber(L, 4); bool percentual = lua_toboolean(L, 5); - const WCHAR* val = self->GetStringValue(autoScale, scale, decimals, percentual); + const WCHAR* val = self->GetStringOrFormattedValue(autoScale, scale, decimals, percentual); LuaManager::PushWide(L, val); return 1;