From af8befd22b601b6ce80be9131251156a3ab714fc Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Sun, 10 Mar 2013 12:14:40 +0200 Subject: [PATCH] Fix that unloaded skin is displayed in context menu until fade is complete --- Library/MeterWindow.cpp | 4 +++- Library/Rainmeter.cpp | 51 +++++++++++++++++++---------------------- Library/Rainmeter.h | 3 ++- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index 4f8b8d61..d7771dc2 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -389,6 +389,8 @@ void CMeterWindow::RemoveWindowExStyle(LONG_PTR flag) */ void CMeterWindow::Deactivate() { + Rainmeter->RemoveMeterWindow(this); + HideFade(); SetTimer(m_Window, TIMER_DEACTIVATE, m_FadeDuration + 50, NULL); } @@ -2879,7 +2881,7 @@ LRESULT CMeterWindow::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam) if (m_FadeStartTime == 0) { KillTimer(m_Window, TIMER_DEACTIVATE); - Rainmeter->DeleteMeterWindow(this, true); // "delete this;" + delete this; } break; } diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index 85db93f9..21b17ce4 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -728,7 +728,7 @@ CRainmeter::~CRainmeter() { KillTimer(m_Window, TIMER_NETSTATS); - DeleteMeterWindow(NULL); + DeleteAllMeterWindows(); delete m_TrayWindow; @@ -1528,36 +1528,34 @@ void CRainmeter::CreateMeterWindow(const std::wstring& folderPath, const std::ws CDialogManage::UpdateSkins(mw); } -void CRainmeter::DeleteMeterWindow(CMeterWindow* meterWindow, bool force) +void CRainmeter::DeleteAllMeterWindows() { - std::map::iterator iter = m_MeterWindows.begin(); - for (; iter != m_MeterWindows.end(); ++iter) + for (auto it = m_MeterWindows.cbegin(); it != m_MeterWindows.end(); ++it) { - if (meterWindow == NULL) + CDialogManage::UpdateSkins((*it).second, true); + delete (*it).second; + } + + m_MeterWindows.clear(); + CDialogAbout::UpdateSkins(); +} + +/* +** Removes the skin from m_MeterWindow. The skin should delete itself. +** +*/ +void CRainmeter::RemoveMeterWindow(CMeterWindow* meterWindow) +{ + for (auto it = m_MeterWindows.cbegin(); it != m_MeterWindows.end(); ++it) + { + if ((*it).second == meterWindow) { - // Delete all meter windows - CDialogManage::UpdateSkins((*iter).second, true); - delete (*iter).second; - } - else if ((*iter).second == meterWindow) - { - m_MeterWindows.erase(iter); - force = true; + m_MeterWindows.erase(it); + CDialogManage::UpdateSkins(meterWindow, true); + CDialogAbout::UpdateSkins(); break; } } - - if (meterWindow == NULL) - { - m_MeterWindows.clear(); - } - else if (force) - { - CDialogManage::UpdateSkins(meterWindow, true); - delete meterWindow; - } - - CDialogAbout::UpdateSkins(); } CMeterWindow* CRainmeter::GetMeterWindow(const std::wstring& folderPath) @@ -2592,8 +2590,7 @@ bool CRainmeter::LoadLayout(const std::wstring& name) return false; } - // Delete all meter windows - DeleteMeterWindow(NULL); + DeleteAllMeterWindows(); std::wstring backup = GetLayoutPath(); backup += L"@Backup"; diff --git a/Library/Rainmeter.h b/Library/Rainmeter.h index 5376d551..86d9e554 100644 --- a/Library/Rainmeter.h +++ b/Library/Rainmeter.h @@ -126,7 +126,8 @@ public: const std::vector& GetFolders() { return m_SkinFolders; } const std::vector& GetAllLayouts() { return m_Layouts; } - void DeleteMeterWindow(CMeterWindow* meterWindow, bool force = false); + void DeleteAllMeterWindows(); + void RemoveMeterWindow(CMeterWindow* meterWindow); void ActivateSkin(int folderIndex, int fileIndex); void DeactivateSkin(CMeterWindow* meterWindow, int folderIndex, bool save = true);