diff --git a/Library/Measure.h b/Library/Measure.h index db9134ce..59a18e7a 100644 --- a/Library/Measure.h +++ b/Library/Measure.h @@ -67,13 +67,11 @@ public: static void GetScaledValue(AUTOSCALE autoScale, int decimals, double theValue, WCHAR* buffer, size_t sizeInWords); static void RemoveTrailingZero(WCHAR* str, int strLen); - std::wstring GetOnUpdateAction() { return m_OnUpdateAction; } - - std::wstring GetOnChangeAction() { return m_OnChangeAction; } + const std::wstring& GetOnChangeAction() { return m_OnChangeAction; } void SetOldValue(double value) { m_OldValue = value; } double GetOldValue() { return m_OldValue; } void SetOldStringValue(std::wstring value) { m_OldStringValue = value; } - std::wstring GetOldStringValue() { return m_OldStringValue; } + const std::wstring& GetOldStringValue() { return m_OldStringValue; } CMeterWindow* GetMeterWindow() { return m_MeterWindow; } @@ -118,8 +116,6 @@ protected: bool m_Disabled; // Status of the measure bool m_Initialized; - std::wstring m_OnUpdateAction; - std::wstring m_OnChangeAction; double m_OldValue; std::wstring m_OldStringValue; diff --git a/Library/Meter.h b/Library/Meter.h index ad788a51..97657ca2 100644 --- a/Library/Meter.h +++ b/Library/Meter.h @@ -76,8 +76,6 @@ public: void SetMouseOver(bool over) { m_MouseOver = over; } bool IsMouseOver() { return m_MouseOver; } - std::wstring GetOnUpdateAction() { return m_OnUpdateAction; } - CMeterWindow* GetMeterWindow() { return m_MeterWindow; } static CMeter* Create(const WCHAR* meter, CMeterWindow* meterWindow, const WCHAR* name); @@ -153,8 +151,6 @@ protected: bool m_AntiAlias; bool m_Initialized; - std::wstring m_OnUpdateAction; - CMeterWindow* m_MeterWindow; }; diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index a362160a..a591f104 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -1226,12 +1226,9 @@ void CMeterWindow::UpdateMeter(const std::wstring& name, bool group) { if (all || (bContinue && CompareName((*j), meter, group))) { - UpdateMeter((*j), bActiveTransition, true); - - std::wstring updateAction = (*j)->GetOnUpdateAction(); - if (!updateAction.empty()) + if (UpdateMeter((*j), bActiveTransition, true)) { - Rainmeter->ExecuteCommand(updateAction.c_str(), this); + DoUpdateAction((*j)); } SetResizeWindowMode(RESIZEMODE_CHECK); // Need to recalculate the window size @@ -1355,12 +1352,10 @@ void CMeterWindow::UpdateMeasure(const std::wstring& name, bool group) bNetStats = false; } - UpdateMeasure((*i), true); - - std::wstring updateAction = (*i)->GetOnUpdateAction(); - if (!updateAction.empty()) + if (UpdateMeasure((*i), true)) { - Rainmeter->ExecuteCommand(updateAction.c_str(), this); + DoUpdateAction((*i)); + //DoChangeAction((*i), false); // TODO: Check that this is the first update or not } if (!group) return; @@ -2698,27 +2693,8 @@ void CMeterWindow::Update(bool refresh) { if (UpdateMeasure((*i), refresh)) { - std::wstring updateAction = (*i)->GetOnUpdateAction(); - if (!updateAction.empty()) - { - Rainmeter->ExecuteCommand(updateAction.c_str(), this); - } - - double newValue = (*i)->GetValue(); - const WCHAR* newStringValue = (*i)->GetStringValue(AUTOSCALE_OFF, 1, -1, false); - std::wstring changeAction = (*i)->GetOnChangeAction(); - - if (refresh) - { - (*i)->SetOldValue(newValue); - (*i)->SetOldStringValue(newStringValue); - } - else if (((*i)->GetOldValue() != newValue || (*i)->GetOldStringValue() != newStringValue) && !changeAction.empty()) - { - (*i)->SetOldValue(newValue); - (*i)->SetOldStringValue(newStringValue); - Rainmeter->ExecuteCommand(changeAction.c_str(), this); - } + DoUpdateAction((*i)); + DoChangeAction((*i), refresh); } } } @@ -2735,11 +2711,7 @@ void CMeterWindow::Update(bool refresh) { bUpdate = true; - std::wstring updateAction = (*j)->GetOnUpdateAction(); - if (!updateAction.empty()) - { - Rainmeter->ExecuteCommand(updateAction.c_str(), this); - } + DoUpdateAction((*j)); } } @@ -2769,6 +2741,40 @@ void CMeterWindow::Update(bool refresh) } } +void CMeterWindow::DoUpdateAction(CSection* section) +{ + const std::wstring& updateAction = section->GetOnUpdateAction(); + if (!updateAction.empty()) + { + Rainmeter->ExecuteCommand(updateAction.c_str(), this); + } +} + +void CMeterWindow::DoChangeAction(CMeasure* measure, bool first) +{ + const std::wstring& changeAction = measure->GetOnChangeAction(); + if (first) + { + double newValue = measure->GetValue(); + const WCHAR* newStringValue = measure->GetStringValue(AUTOSCALE_OFF, 1, -1, false); + + measure->SetOldValue(newValue); + measure->SetOldStringValue(newStringValue); + } + else if (!changeAction.empty()) + { + double newValue = measure->GetValue(); + const WCHAR* newStringValue = measure->GetStringValue(AUTOSCALE_OFF, 1, -1, false); + + if (measure->GetOldValue() != newValue || wcscmp(measure->GetOldStringValue().c_str(), newStringValue) != 0) + { + measure->SetOldValue(newValue); + measure->SetOldStringValue(newStringValue); + Rainmeter->ExecuteCommand(changeAction.c_str(), this); + } + } +} + /* ** Updates the window contents ** diff --git a/Library/MeterWindow.h b/Library/MeterWindow.h index cf242f38..af8699ae 100644 --- a/Library/MeterWindow.h +++ b/Library/MeterWindow.h @@ -25,6 +25,7 @@ #include #include #include "ConfigParser.h" +#include "Section.h" #include "Group.h" #include "Mouse.h" @@ -317,6 +318,8 @@ private: bool UpdateMeasure(CMeasure* measure, bool force); bool UpdateMeter(CMeter* meter, bool& bActiveTransition, bool force); void Update(bool refresh); + void DoUpdateAction(CSection* section); + void DoChangeAction(CMeasure* measure, bool first); void UpdateWindow(int alpha, bool reset); void ReadOptions(); void WriteOptions(INT setting = OPTION_ALL); diff --git a/Library/Section.h b/Library/Section.h index 6033728a..1bcd0929 100644 --- a/Library/Section.h +++ b/Library/Section.h @@ -40,6 +40,8 @@ public: int GetUpdateCounter() const { return m_UpdateCounter; } int GetUpdateDivider() const { return m_UpdateDivider; } + const std::wstring& GetOnUpdateAction() { return m_OnUpdateAction; } + protected: CSection(const WCHAR* name) : m_Name(name), m_DynamicVariables(false), m_UpdateDivider(1), m_UpdateCounter(1) {} @@ -48,6 +50,8 @@ protected: bool m_DynamicVariables; // If true, the section contains dynamic variables int m_UpdateDivider; // Divider for the update int m_UpdateCounter; // Current update counter + + std::wstring m_OnUpdateAction; }; #endif