[AboutDialog]

- Fixed the issue that the statistics are updated many times if many active skins are working. "Log" is now updated once every 1 second. Config is now updated once on its Update=.
- Fixed the issue that the statistics show by incorrect order in some conditions.
- Fixed the issue that the entries aren't updated if the skin is activated/deactivated.
This commit is contained in:
spx 2010-08-30 22:51:58 +00:00
parent c753f0cbac
commit c14cd5491b
4 changed files with 244 additions and 127 deletions

View File

@ -24,12 +24,18 @@
#include "AboutDialog.h" #include "AboutDialog.h"
#include "../revision-number.h" #include "../revision-number.h"
#include <commctrl.h> #include <commctrl.h>
#include <string>
#include <map>
#define LOGTIMER 1
extern CRainmeter* Rainmeter; extern CRainmeter* Rainmeter;
INT_PTR CALLBACK AboutProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK AboutProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam);
void UpdateWidgets();
BOOL OnInitAboutDialog(HWND window);
HWND g_DialogWin = NULL; HWND g_DialogWin = NULL;
VOID UpdateWidgets(HWND window);
struct PLUGIN_INFO struct PLUGIN_INFO
{ {
@ -57,7 +63,71 @@ HWND OpenAboutDialog(HWND hwndOwner, HINSTANCE instance)
return g_DialogWin; return g_DialogWin;
} }
void UpdateAboutStatistics() void UpdateAboutDialog()
{
if (g_DialogWin != NULL && IsWindowVisible(g_DialogWin))
{
WCHAR* selectedItemName = NULL;
HWND widget;
widget = GetDlgItem(g_DialogWin, IDC_ABOUT_ENTRIES);
int selected = (int)SendMessage(widget, LB_GETCURSEL, 0, 0);
// Get current selected entry
if (selected != 0 && selected != 1 && selected != LB_ERR)
{
int selectedItemLen = (int)SendMessage(widget, LB_GETTEXTLEN, selected, 0);
if (selectedItemLen != LB_ERR)
{
selectedItemName = new WCHAR[selectedItemLen + 1];
if (LB_ERR != SendMessage(widget, LB_GETTEXT, selected, (LPARAM)selectedItemName))
{
selectedItemName[selectedItemLen] = L'\0';
}
else
{
delete [] selectedItemName;
selectedItemName = NULL;
}
}
}
// Delete all entries
SendMessage(widget, LB_RESETCONTENT, 0, 0);
// Update all dialog widgets
OnInitAboutDialog(g_DialogWin);
// Re-select entry
if (selected == 0 || selected == 1)
{
SendMessage(widget, LB_SETCURSEL, selected, 0);
UpdateWidgets();
}
else if (selectedItemName != NULL)
{
int sel = 3;
std::map<std::wstring, CMeterWindow*>& windows = Rainmeter->GetAllMeterWindows();
std::map<std::wstring, CMeterWindow*>::const_iterator iter = windows.begin();
for( ; iter != windows.end(); ++iter)
{
if (wcsicmp(selectedItemName, (*iter).first.c_str()) == 0)
{
SendMessage(widget, LB_SETCURSEL, sel, 0);
break;
}
++sel;
}
delete [] selectedItemName;
}
}
}
void UpdateAboutStatistics(LPCTSTR entryName)
{ {
if (g_DialogWin != NULL && IsWindowVisible(g_DialogWin)) if (g_DialogWin != NULL && IsWindowVisible(g_DialogWin))
{ {
@ -65,12 +135,15 @@ void UpdateAboutStatistics()
widget = GetDlgItem(g_DialogWin, IDC_ABOUT_ENTRIES); widget = GetDlgItem(g_DialogWin, IDC_ABOUT_ENTRIES);
int selected = (int)SendMessage(widget, LB_GETCURSEL, NULL, NULL); int selected = (int)SendMessage(widget, LB_GETCURSEL, NULL, NULL);
int count = (int)SendMessage(widget, LB_GETCOUNT, NULL, NULL); int count = (int)SendMessage(widget, LB_GETCOUNT, NULL, NULL);
int current = 0;
if (selected != LB_ERR)
{
widget = GetDlgItem(g_DialogWin, IDC_STATISTICS); widget = GetDlgItem(g_DialogWin, IDC_STATISTICS);
SendMessage(widget, WM_SETREDRAW, 0, 0); SendMessage(widget, WM_SETREDRAW, 0, 0);
if (selected == 0) if (selected == 0)
{
if (entryName == NULL)
{ {
int count = ListView_GetItemCount(widget); int count = ListView_GetItemCount(widget);
@ -98,20 +171,25 @@ void UpdateAboutStatistics()
++i; ++i;
} }
} }
}
else if (selected == 2) else if (selected == 2)
{ {
widget = GetDlgItem(g_DialogWin, IDC_ABOUT_ENTRIES); HWND widgetEnt;
SendMessage(widget, LB_SETCURSEL, 1, NULL); widgetEnt = GetDlgItem(g_DialogWin, IDC_ABOUT_ENTRIES);
UpdateWidgets(g_DialogWin); SendMessage(widgetEnt, LB_SETCURSEL, 1, NULL);
UpdateWidgets();
} }
else if (selected > 2) else
{ {
std::map<std::wstring, CMeterWindow*>& windows = Rainmeter->GetAllMeterWindows(); int current = 3;
std::map<std::wstring, CMeterWindow*>& windows = Rainmeter->GetAllMeterWindows();
std::map<std::wstring, CMeterWindow*>::const_iterator iter = windows.begin(); std::map<std::wstring, CMeterWindow*>::const_iterator iter = windows.begin();
for( ; iter != windows.end(); ++iter) for( ; iter != windows.end(); ++iter)
{ {
if (current == selected - 3) if (current == selected)
{
if (entryName == NULL || wcsicmp(entryName, (*iter).first.c_str()) == 0)
{ {
int count = ListView_GetItemCount(widget); int count = ListView_GetItemCount(widget);
@ -145,7 +223,7 @@ void UpdateAboutStatistics()
{ {
LVITEM vitem; LVITEM vitem;
vitem.mask = LVIF_TEXT; vitem.mask = LVIF_TEXT;
vitem.iItem = 0; vitem.iItem = index;
vitem.iSubItem = 0; vitem.iSubItem = 0;
vitem.pszText = (WCHAR*)name; vitem.pszText = (WCHAR*)name;
ListView_InsertItem(widget, &vitem); ListView_InsertItem(widget, &vitem);
@ -160,21 +238,32 @@ void UpdateAboutStatistics()
} }
} }
if (count > index)
{
// Delete unnecessary items
for (int j = index; j < count; ++j)
{
ListView_DeleteItem(widget, index);
}
}
}
break; break;
} }
++current; ++current;
} }
} }
SendMessage(widget, WM_SETREDRAW, 1, 0); SendMessage(widget, WM_SETREDRAW, 1, 0);
} }
}
} }
void UpdateWidgets(HWND window) void UpdateWidgets()
{ {
HWND widget; HWND widget;
widget = GetDlgItem(g_DialogWin, IDC_ABOUT_ENTRIES); widget = GetDlgItem(g_DialogWin, IDC_ABOUT_ENTRIES);
int selected = (int)SendMessage(widget, LB_GETCURSEL, NULL, NULL); int selected = (int)SendMessage(widget, LB_GETCURSEL, NULL, NULL);
int count = (int)SendMessage(widget, LB_GETCOUNT, NULL, NULL);
widget = GetDlgItem(g_DialogWin, IDC_STATISTICS); widget = GetDlgItem(g_DialogWin, IDC_STATISTICS);
ListView_DeleteAllItems(widget); ListView_DeleteAllItems(widget);
@ -354,20 +443,21 @@ BOOL OnInitAboutDialog(HWND window)
swprintf(tmpSz, L"Built on %s", ConvertToWide(__DATE__).c_str()); swprintf(tmpSz, L"Built on %s", ConvertToWide(__DATE__).c_str());
SetWindowText(widget, tmpSz); SetWindowText(widget, tmpSz);
CheckDlgButton(window, IDC_DISABLE_VERSION_CHECK, Rainmeter->GetDisableVersionCheck() ? BST_CHECKED : BST_UNCHECKED);
// Add entries for each config // Add entries for each config
widget = GetDlgItem(window, IDC_ABOUT_ENTRIES); widget = GetDlgItem(window, IDC_ABOUT_ENTRIES);
std::map<std::wstring, CMeterWindow*>& windows = Rainmeter->GetAllMeterWindows(); std::map<std::wstring, CMeterWindow*>& windows = Rainmeter->GetAllMeterWindows();
std::map<std::wstring, CMeterWindow*>::const_iterator iter = windows.begin(); std::map<std::wstring, CMeterWindow*>::const_iterator iter = windows.begin();
int i = 0;
for( ; iter != windows.end(); ++iter) for( ; iter != windows.end(); ++iter)
{ {
CMeterWindow* meterWindow = (*iter).second; CMeterWindow* meterWindow = (*iter).second;
wchar_t* skinName = (WCHAR*)meterWindow->GetSkinName().c_str(); const std::wstring& skinName = meterWindow->GetSkinName();
SendMessage(widget, LB_ADDSTRING, NULL, (LPARAM) skinName); SendMessage(widget, LB_ADDSTRING, NULL, (LPARAM)skinName.c_str());
size_t namelength = wcslen(skinName); size_t namelength = skinName.length();
int currwidth = (INT)SendMessage(widget, LB_GETHORIZONTALEXTENT, NULL, NULL); int currwidth = (int)SendMessage(widget, LB_GETHORIZONTALEXTENT, NULL, NULL);
if(6 * namelength > currwidth) if(6 * (int)namelength > currwidth)
{ {
SendMessage(widget, LB_SETHORIZONTALEXTENT, 6 * namelength, NULL); SendMessage(widget, LB_SETHORIZONTALEXTENT, 6 * namelength, NULL);
} }
@ -376,6 +466,8 @@ BOOL OnInitAboutDialog(HWND window)
SendMessage(widget, LB_INSERTSTRING, 1, (LPARAM) L"Plugins"); SendMessage(widget, LB_INSERTSTRING, 1, (LPARAM) L"Plugins");
SendMessage(widget, LB_INSERTSTRING, 2, (LPARAM) L"--------------------"); SendMessage(widget, LB_INSERTSTRING, 2, (LPARAM) L"--------------------");
if (g_DialogWin == NULL)
{
// Add columns to the list view // Add columns to the list view
widget = GetDlgItem(window, IDC_STATISTICS); widget = GetDlgItem(window, IDC_STATISTICS);
@ -393,18 +485,16 @@ BOOL OnInitAboutDialog(HWND window)
lvc.cx = 100; lvc.cx = 100;
lvc.pszText = L"Value"; lvc.pszText = L"Value";
ListView_InsertColumn(widget, 1, &lvc); ListView_InsertColumn(widget, 1, &lvc);
lvc.iSubItem = 1; lvc.iSubItem = 2;
lvc.cx = 150; lvc.cx = 150;
lvc.pszText = L"Range"; lvc.pszText = L"Range";
ListView_InsertColumn(widget, 2, &lvc); ListView_InsertColumn(widget, 2, &lvc);
CheckDlgButton(window, IDC_DISABLE_VERSION_CHECK, Rainmeter->GetDisableVersionCheck() ? BST_CHECKED : BST_UNCHECKED);
ScanPlugins(); ScanPlugins();
UpdateWidgets(window); }
RepositionControls(window);
g_DialogWin = window; UpdateWidgets();
RepositionControls(window);
return TRUE; return TRUE;
} }
@ -430,6 +520,7 @@ INT_PTR CALLBACK AboutProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lPa
break; break;
case WM_CLOSE: case WM_CLOSE:
KillTimer(hwndDlg, LOGTIMER);
Rainmeter->SaveSettings(); Rainmeter->SaveSettings();
DestroyWindow(hwndDlg); DestroyWindow(hwndDlg);
g_DialogWin = NULL; g_DialogWin = NULL;
@ -450,20 +541,37 @@ INT_PTR CALLBACK AboutProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lPa
break; break;
case IDOK: case IDOK:
Rainmeter->SaveSettings(); SendMessage(hwndDlg, WM_CLOSE, 0, 0);
DestroyWindow(hwndDlg);
g_DialogWin = NULL;
return TRUE; return TRUE;
case IDC_ABOUT_ENTRIES: case IDC_ABOUT_ENTRIES:
if (HIWORD(wParam) == LBN_SELCHANGE) if (HIWORD(wParam) == LBN_SELCHANGE)
{ {
UpdateWidgets(hwndDlg); KillTimer(hwndDlg, LOGTIMER);
HWND widget = GetDlgItem(hwndDlg, IDC_ABOUT_ENTRIES);
if (widget != NULL)
{
if (0 == (int)SendMessage(widget, LB_GETCURSEL, 0, 0))
{
SetTimer(g_DialogWin, LOGTIMER, 1000, NULL);
}
}
UpdateWidgets();
UpdateAboutStatistics(); UpdateAboutStatistics();
} }
break; break;
} }
break; break;
case WM_TIMER:
if (wParam == LOGTIMER)
{
UpdateAboutStatistics();
return TRUE;
}
break;
} }
return FALSE; return FALSE;
} }

View File

@ -22,7 +22,8 @@
#include "MeterWindow.h" #include "MeterWindow.h"
HWND OpenAboutDialog(HWND hwndOwner, HINSTANCE instance); HWND OpenAboutDialog(HWND hwndOwner, HINSTANCE instance);
void UpdateAboutStatistics(); void UpdateAboutDialog();
void UpdateAboutStatistics(LPCTSTR entryName = NULL);
#endif #endif

View File

@ -2628,7 +2628,7 @@ LRESULT CMeterWindow::OnTimer(WPARAM wParam, LPARAM lParam)
if(wParam == METERTIMER) if(wParam == METERTIMER)
{ {
Update(false); Update(false);
UpdateAboutStatistics(); UpdateAboutStatistics(m_SkinName.c_str());
//if (m_KeepOnScreen) //if (m_KeepOnScreen)
//{ //{

View File

@ -1910,6 +1910,8 @@ void CRainmeter::CreateMeterWindow(std::wstring path, std::wstring config, std::
{ {
m_Meters[config] = mw; m_Meters[config] = mw;
mw->Initialize(*this); mw->Initialize(*this);
UpdateAboutDialog();
} }
} }
@ -1929,6 +1931,8 @@ void CRainmeter::ClearDeleteLaterList()
if ((*iter).second == meterWindow) if ((*iter).second == meterWindow)
{ {
m_Meters.erase(iter); m_Meters.erase(iter);
UpdateAboutDialog();
break; break;
} }
} }
@ -1961,6 +1965,8 @@ bool CRainmeter::DeleteMeterWindow(CMeterWindow* meterWindow, bool bLater)
{ {
m_Meters.erase(iter); m_Meters.erase(iter);
delete meterWindow; delete meterWindow;
UpdateAboutDialog();
return true; return true;
} }
} }
@ -1969,6 +1975,8 @@ bool CRainmeter::DeleteMeterWindow(CMeterWindow* meterWindow, bool bLater)
{ {
m_Meters.clear(); m_Meters.clear();
} }
UpdateAboutDialog();
} }
return false; return false;