rainmeter-studio/Library/AboutDialog.cpp

612 lines
17 KiB
C++
Raw Normal View History

2009-02-10 18:37:48 +00:00
/*
Copyright (C) 2000 Kimmo Pekkola
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "StdAfx.h"
2009-02-10 18:37:48 +00:00
#include "Rainmeter.h"
#include "System.h"
2009-02-10 18:37:48 +00:00
#include "MeterWindow.h"
#include "Measure.h"
#include "resource.h"
#include "AboutDialog.h"
#include "../Version.h"
#define LOGTIMER 1
2009-02-10 18:37:48 +00:00
#define WM_DELAYED_CLOSE WM_APP + 0
2009-02-10 18:37:48 +00:00
extern CRainmeter* Rainmeter;
INT_PTR CALLBACK AboutProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam);
void UpdateWidgets();
BOOL OnInitAboutDialog(HWND window);
2009-02-10 18:37:48 +00:00
HWND g_DialogWin = NULL;
WINDOWPLACEMENT g_DialogPlacement = {0};
2009-02-10 18:37:48 +00:00
struct PLUGIN_INFO
{
std::wstring name;
UINT version;
std::wstring author;
};
std::vector<PLUGIN_INFO> g_Plugins;
HWND OpenAboutDialog(HWND hwndOwner, HINSTANCE instance)
{
if (g_DialogWin == NULL)
{
g_DialogWin = CreateDialog(instance, MAKEINTRESOURCE(IDD_ABOUT_DIALOG), hwndOwner, AboutProc);
if (g_DialogWin)
{
HICON hIcon = LoadIcon(instance, MAKEINTRESOURCE(IDI_TRAY));
SendMessage(g_DialogWin, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
if (g_DialogPlacement.length == 0)
{
g_DialogPlacement.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(g_DialogWin, &g_DialogPlacement);
}
SetWindowPlacement(g_DialogWin, &g_DialogPlacement);
}
}
else
{
if (!IsZoomed(g_DialogWin))
{
ShowWindow(g_DialogWin, SW_SHOWNORMAL);
}
2009-02-10 18:37:48 +00:00
}
UpdateAboutStatistics();
return g_DialogWin;
}
void UpdateAboutDialog()
2009-02-10 18:37:48 +00:00
{
if (g_DialogWin != NULL && IsWindowVisible(g_DialogWin))
{
WCHAR* selectedItemName = NULL;
2009-02-10 18:37:48 +00:00
HWND widget;
widget = GetDlgItem(g_DialogWin, IDC_ABOUT_ENTRIES);
int selected = (int)SendMessage(widget, LB_GETCURSEL, 0, 0);
2009-02-10 18:37:48 +00:00
// Get current selected entry
if (selected != 0 && selected != 1 && selected != LB_ERR)
2009-02-10 18:37:48 +00:00
{
int selectedItemLen = (int)SendMessage(widget, LB_GETTEXTLEN, selected, 0);
if (selectedItemLen != LB_ERR)
2009-02-10 18:37:48 +00:00
{
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;
2009-02-10 18:37:48 +00:00
2011-01-24 10:15:05 +00:00
const std::map<std::wstring, CMeterWindow*>& windows = Rainmeter->GetAllMeterWindows();
std::map<std::wstring, CMeterWindow*>::const_iterator iter = windows.begin();
for( ; iter != windows.end(); ++iter)
{
2010-09-17 08:47:22 +00:00
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))
{
HWND widget;
widget = GetDlgItem(g_DialogWin, IDC_ABOUT_ENTRIES);
int selected = (int)SendMessage(widget, LB_GETCURSEL, NULL, NULL);
int count = (int)SendMessage(widget, LB_GETCOUNT, NULL, NULL);
if (selected != LB_ERR)
{
widget = GetDlgItem(g_DialogWin, IDC_STATISTICS);
SendMessage(widget, WM_SETREDRAW, 0, 0);
if (selected == 0)
{
if (entryName == NULL)
2009-02-10 18:37:48 +00:00
{
int count = ListView_GetItemCount(widget);
2009-02-10 18:37:48 +00:00
std::list<CRainmeter::LOG_INFO>::const_iterator iter = Rainmeter->GetAboutLogData().begin();
LVITEM vitem;
vitem.mask = LVIF_TEXT;
int i = 0;
for ( ; iter != Rainmeter->GetAboutLogData().end(); ++iter)
{
if (i < count)
2009-02-10 18:37:48 +00:00
{
ListView_SetItemText(widget, i, 0, (WCHAR*)(*iter).timestamp.c_str());
}
else
{
vitem.iItem = i;
vitem.iSubItem = 0;
vitem.pszText = (WCHAR*)(*iter).timestamp.c_str();
ListView_InsertItem(widget, &vitem);
}
ListView_SetItemText(widget, i, 1, (WCHAR*)(*iter).type.c_str());
ListView_SetItemText(widget, i, 2, (WCHAR*)(*iter).message.c_str());
++i;
}
}
}
else if (selected == 2)
{
HWND widgetEnt;
widgetEnt = GetDlgItem(g_DialogWin, IDC_ABOUT_ENTRIES);
SendMessage(widgetEnt, LB_SETCURSEL, 1, NULL);
UpdateWidgets();
}
else
{
int current = 3;
2011-01-24 10:15:05 +00:00
const std::map<std::wstring, CMeterWindow*>& windows = Rainmeter->GetAllMeterWindows();
std::map<std::wstring, CMeterWindow*>::const_iterator iter = windows.begin();
for( ; iter != windows.end(); ++iter)
{
if (current == selected)
{
2010-09-17 08:47:22 +00:00
if (entryName == NULL || _wcsicmp(entryName, (*iter).first.c_str()) == 0)
{
int count = ListView_GetItemCount(widget);
CMeterWindow* meterWindow = (*iter).second;
2011-01-24 10:15:05 +00:00
const std::list<CMeasure*>& measures = meterWindow->GetMeasures();
int index = 0;
std::list<CMeasure*>::const_iterator i = measures.begin();
for( ; i != measures.end(); ++i)
{
const WCHAR* name = (*i)->GetName();
const WCHAR* val = (*i)->GetStats();
WCHAR buffer[256];
double minVal = (*i)->GetMinValue();
double maxVal = (*i)->GetMaxValue();
CMeasure::GetScaledValue(AUTOSCALE_ON, 1, minVal, buffer, _countof(buffer));
std::wstring range = buffer;
range += L" - ";
CMeasure::GetScaledValue(AUTOSCALE_ON, 1, maxVal, buffer, _countof(buffer));
range += buffer;
2010-11-25 15:34:49 +00:00
if (name && *name)
{
if (index < count)
{
ListView_SetItemText(widget, index, 0, (WCHAR*)name);
}
else
{
LVITEM vitem;
vitem.mask = LVIF_TEXT;
vitem.iItem = index;
vitem.iSubItem = 0;
vitem.pszText = (WCHAR*)name;
ListView_InsertItem(widget, &vitem);
}
ListView_SetItemText(widget, index, 1, (WCHAR*)range.c_str());
if (val)
{
ListView_SetItemText(widget, index, 2, (WCHAR*)val);
}
++index;
}
}
if (count > index)
{
// Delete unnecessary items
for (int j = index; j < count; ++j)
{
ListView_DeleteItem(widget, index);
}
}
2009-02-10 18:37:48 +00:00
}
break;
}
++current;
}
2009-02-10 18:37:48 +00:00
}
SendMessage(widget, WM_SETREDRAW, 1, 0);
2009-02-10 18:37:48 +00:00
}
}
}
void UpdateWidgets()
2009-02-10 18:37:48 +00:00
{
HWND widget;
widget = GetDlgItem(g_DialogWin, IDC_ABOUT_ENTRIES);
int selected = (int)SendMessage(widget, LB_GETCURSEL, NULL, NULL);
2009-02-10 18:37:48 +00:00
widget = GetDlgItem(g_DialogWin, IDC_STATISTICS);
ListView_DeleteAllItems(widget);
if (selected == 0)
{
LVCOLUMN lvc;
lvc.mask = LVCF_TEXT;
lvc.pszText = L"Time";
ListView_SetColumn(widget, 0, &lvc);
lvc.pszText = L"Type";
ListView_SetColumn(widget, 1, &lvc);
lvc.pszText = L"Message";
ListView_SetColumn(widget, 2, &lvc);
}
else if (selected == 1)
2009-02-10 18:37:48 +00:00
{
LVCOLUMN lvc;
lvc.mask = LVCF_TEXT;
lvc.pszText = L"Plugin";
ListView_SetColumn(widget, 0, &lvc);
lvc.pszText = L"Version";
ListView_SetColumn(widget, 1, &lvc);
lvc.pszText = L"Author";
ListView_SetColumn(widget, 2, &lvc);
// Update the list of plugins
if (g_Plugins.empty())
{
ScanPlugins();
}
2010-03-30 22:37:05 +00:00
std::vector<PLUGIN_INFO>::const_iterator iter = g_Plugins.begin();
2009-02-10 18:37:48 +00:00
LVITEM vitem;
vitem.mask = LVIF_TEXT;
int i = 0;
2010-03-30 22:37:05 +00:00
for ( ; iter != g_Plugins.end(); ++iter)
2009-02-10 18:37:48 +00:00
{
if (!(*iter).name.empty())
{
vitem.iItem = i;
vitem.iSubItem = 0;
vitem.pszText = (WCHAR*)(*iter).name.c_str();
ListView_InsertItem(widget, &vitem);
}
if ((*iter).version != 0)
{
2010-09-13 20:06:52 +00:00
WCHAR buffer[64];
_snwprintf_s(buffer, _TRUNCATE, L"%u.%u", (*iter).version / 1000, (*iter).version % 1000);
2009-02-10 18:37:48 +00:00
ListView_SetItemText(widget, i, 1, buffer);
}
ListView_SetItemText(widget, i, 2, (WCHAR*)(*iter).author.c_str());
2010-03-30 22:37:05 +00:00
++i;
2009-02-10 18:37:48 +00:00
}
if (!g_Plugins.empty())
2009-02-10 18:37:48 +00:00
{
ListView_SetItemState(widget, 0, LVIS_SELECTED, LVIS_SELECTED);
}
}
else
2009-02-10 18:37:48 +00:00
{
LVCOLUMN lvc;
lvc.mask = LVCF_TEXT;
lvc.pszText = L"Measure";
ListView_SetColumn(widget, 0, &lvc);
lvc.pszText = L"Range";
ListView_SetColumn(widget, 1, &lvc);
lvc.pszText = L"Value";
2009-02-10 18:37:48 +00:00
ListView_SetColumn(widget, 2, &lvc);
}
}
typedef LPCTSTR (*GETPLUGINAUTHOR)();
typedef UINT (*GETPLUGINVERSION)();
void ScanPlugins()
{
WIN32_FIND_DATA fileData; // Data structure describes the file found
HANDLE hSearch; // Search handle returned by FindFirstFile
2009-02-10 18:37:48 +00:00
std::wstring files = Rainmeter->GetPluginPath() + L"*.dll";
2009-02-10 18:37:48 +00:00
// Start searching for .ini files in the given directory.
hSearch = FindFirstFile(files.c_str(), &fileData);
2009-02-10 18:37:48 +00:00
do
{
if (hSearch == INVALID_HANDLE_VALUE) break; // No more files found
2009-02-10 18:37:48 +00:00
PLUGIN_INFO info;
info.name = fileData.cFileName;
info.version = 0;
// Try to get the version and author
std::wstring tmpSz = Rainmeter->GetPluginPath() + fileData.cFileName;
DWORD err = 0;
HMODULE dll = CSystem::RmLoadLibrary(tmpSz.c_str(), &err, true);
2009-02-10 18:37:48 +00:00
if (dll)
{
GETPLUGINAUTHOR GetAuthorFunc = (GETPLUGINAUTHOR)GetProcAddress(dll, "GetPluginAuthor");
if (GetAuthorFunc)
{
LPCTSTR author = GetAuthorFunc();
2010-11-25 15:34:49 +00:00
if (author && *author)
2009-02-10 18:37:48 +00:00
{
info.author = author;
}
}
GETPLUGINVERSION GetVersionFunc = (GETPLUGINVERSION)GetProcAddress(dll, "GetPluginVersion");
if (GetVersionFunc)
{
info.version = GetVersionFunc();
}
FreeLibrary(dll);
}
else
{
LogWithArgs(LOG_WARNING, L"Unable to load plugin: \"%s\", ErrorCode=%u", tmpSz.c_str(), err);
}
2009-02-10 18:37:48 +00:00
g_Plugins.push_back(info);
}
while (FindNextFile(hSearch, &fileData));
2009-02-10 18:37:48 +00:00
FindClose(hSearch);
2009-02-10 18:37:48 +00:00
}
void RepositionControls(HWND hwndDlg)
{
RECT r, br, ar, sr, wr;
HWND widget;
GetClientRect(hwndDlg, &r);
GetClientRect(GetDlgItem(hwndDlg, IDOK), &br);
GetClientRect(GetDlgItem(hwndDlg, IDC_STATIC_ABOUT), &ar);
GetClientRect(GetDlgItem(hwndDlg, IDC_VERSION_STRING), &sr);
// Reposition the statistics widgets
widget = GetDlgItem(hwndDlg, IDC_STATIC_ABOUT);
SetWindowPos(widget, NULL, 0, 0, r.right - 22, ar.bottom, SWP_NOMOVE | SWP_NOZORDER);
widget = GetDlgItem(hwndDlg, IDC_VERSION_STRING);
SetWindowPos(widget, NULL, 0, 0, r.right - 44, sr.bottom, SWP_NOMOVE | SWP_NOZORDER);
widget = GetDlgItem(hwndDlg, IDC_BUILD_STRING);
SetWindowPos(widget, NULL, 0, 0, r.right - 44, sr.bottom, SWP_NOMOVE | SWP_NOZORDER);
widget = GetDlgItem(hwndDlg, IDC_URL_STRING);
SetWindowPos(widget, NULL, 0, 0, r.right - 44, sr.bottom, SWP_NOMOVE | SWP_NOZORDER);
widget = GetDlgItem(hwndDlg, IDC_DISABLE_VERSION_CHECK);
2009-02-10 18:37:48 +00:00
GetClientRect(widget, &wr);
MapWindowPoints(widget, hwndDlg, (LPPOINT)&wr, 2);
2010-08-05 16:38:28 +00:00
SetWindowPos(widget, NULL, ((r.right - (wr.right - wr.left)) / 2) + 9, wr.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
2009-02-10 18:37:48 +00:00
widget = GetDlgItem(hwndDlg, IDC_ABOUT_ENTRIES);
2011-02-01 18:16:34 +00:00
SetWindowPos(widget, NULL, 0, 0, (r.right < 800) ? ((r.right - 28) / 3) : 257, r.bottom - 170, SWP_NOMOVE | SWP_NOZORDER);
2009-02-10 18:37:48 +00:00
widget = GetDlgItem(hwndDlg, IDOK);
SetWindowPos(widget, NULL, (r.right - br.right) / 2, r.bottom - br.bottom - 9, br.right, br.bottom, SWP_NOZORDER);
// Set listbox width and adjust third column
widget = GetDlgItem(hwndDlg, IDC_STATISTICS);
2011-02-01 18:16:34 +00:00
SetWindowPos(widget, NULL, (r.right < 800) ? (18 + ((r.right - 28) / 3)) : 275, 130, (r.right < 800) ? (2 * ((r.right - 28) / 3)) : (r.right - 287), r.bottom - 170, SWP_NOZORDER);
LVCOLUMN lvc;
lvc.mask = LVCF_WIDTH;
2011-02-01 18:16:34 +00:00
lvc.cx = ((r.right < 800) ? (2 * ((r.right - 28) / 3)) : (r.right - 287)) - 200;
ListView_SetColumn(widget, 2, &lvc);
2009-02-10 18:37:48 +00:00
}
BOOL OnInitAboutDialog(HWND window)
{
WCHAR tmpSz[256];
HWND widget;
widget = GetDlgItem(window, IDC_VERSION_STRING);
_snwprintf_s(tmpSz, _TRUNCATE, L"%s %s%s rev %i %s", APPNAME, APPVERSION, revision_beta ? L" beta" : L"", revision_number, APPBITS);
2009-02-10 18:37:48 +00:00
SetWindowText(widget, tmpSz);
widget = GetDlgItem(window, IDC_BUILD_STRING);
_snwprintf_s(tmpSz, _TRUNCATE, L"Built on %s", ConvertToWide(__DATE__).c_str());
2009-02-10 18:37:48 +00:00
SetWindowText(widget, tmpSz);
CheckDlgButton(window, IDC_DISABLE_VERSION_CHECK, Rainmeter->GetDisableVersionCheck() ? BST_CHECKED : BST_UNCHECKED);
// Add entries for each config
widget = GetDlgItem(window, IDC_ABOUT_ENTRIES);
2011-01-24 10:15:05 +00:00
const std::map<std::wstring, CMeterWindow*>& windows = Rainmeter->GetAllMeterWindows();
2010-03-30 22:37:05 +00:00
std::map<std::wstring, CMeterWindow*>::const_iterator iter = windows.begin();
for ( ; iter != windows.end(); ++iter)
2009-02-10 18:37:48 +00:00
{
CMeterWindow* meterWindow = (*iter).second;
const std::wstring& skinName = meterWindow->GetSkinName();
SendMessage(widget, LB_ADDSTRING, NULL, (LPARAM)skinName.c_str());
size_t namelength = skinName.length();
2009-02-10 18:37:48 +00:00
int currwidth = (int)SendMessage(widget, LB_GETHORIZONTALEXTENT, NULL, NULL);
if(6 * (int)namelength > currwidth)
{
SendMessage(widget, LB_SETHORIZONTALEXTENT, 6 * namelength, NULL);
}
2009-02-10 18:37:48 +00:00
}
SendMessage(widget, LB_INSERTSTRING, 0, (LPARAM) L"Log");
SendMessage(widget, LB_INSERTSTRING, 1, (LPARAM) L"Plugins");
SendMessage(widget, LB_INSERTSTRING, 2, (LPARAM) L"--------------------");
2009-02-10 18:37:48 +00:00
// Select Log entry
SendMessage(widget, LB_SETCURSEL, 0, 0);
SetTimer(window, LOGTIMER, 1000, NULL);
if (g_DialogWin == NULL)
{
// Add columns to the list view
widget = GetDlgItem(window, IDC_STATISTICS);
2009-02-10 18:37:48 +00:00
//ListView_SetExtendedListViewStyleEx(widget, LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
ListView_SetExtendedListViewStyleEx(widget, LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER, LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER);
2009-02-10 18:37:48 +00:00
LVCOLUMN lvc;
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvc.iSubItem = 0;
lvc.pszText = L"Time";
lvc.cx = 110;
lvc.fmt = LVCFMT_LEFT; // left-aligned column
ListView_InsertColumn(widget, 0, &lvc);
lvc.iSubItem = 1;
2011-02-01 18:16:34 +00:00
lvc.cx = 85;
lvc.pszText = L"Type";
ListView_InsertColumn(widget, 1, &lvc);
lvc.iSubItem = 2;
2011-02-01 18:16:34 +00:00
lvc.cx = 170;
lvc.pszText = L"Message";
ListView_InsertColumn(widget, 2, &lvc);
}
2009-02-10 18:37:48 +00:00
UpdateWidgets();
RepositionControls(window);
2009-02-10 18:37:48 +00:00
return TRUE;
}
INT_PTR CALLBACK AboutProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return OnInitAboutDialog(hwndDlg);
2009-02-10 18:37:48 +00:00
case WM_WINDOWPOSCHANGING:
{
WINDOWPOS* pos = (WINDOWPOS*)lParam;
2009-02-10 18:37:48 +00:00
pos->cx = max(420, pos->cx);
pos->cy = max(340, pos->cy);
}
return TRUE;
case WM_SIZE:
RepositionControls(hwndDlg);
return TRUE;
case WM_CLOSE:
PostMessage(hwndDlg, WM_DELAYED_CLOSE, 0, 0);
return TRUE;
2009-02-10 18:37:48 +00:00
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_DISABLE_VERSION_CHECK:
if (IsDlgButtonChecked(hwndDlg, IDC_DISABLE_VERSION_CHECK))
{
Rainmeter->SetDisableVersionCheck(TRUE);
}
else
{
Rainmeter->SetDisableVersionCheck(FALSE);
}
return TRUE;
2009-02-10 18:37:48 +00:00
case IDOK:
PostMessage(hwndDlg, WM_DELAYED_CLOSE, 0, 0);
2009-02-10 18:37:48 +00:00
return TRUE;
case IDC_ABOUT_ENTRIES:
if (HIWORD(wParam) == LBN_SELCHANGE)
2009-02-10 18:37:48 +00:00
{
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();
return TRUE;
}
break;
}
break;
case WM_DELAYED_CLOSE:
KillTimer(hwndDlg, LOGTIMER);
Rainmeter->SaveSettings();
GetWindowPlacement(hwndDlg, &g_DialogPlacement);
if (g_DialogPlacement.showCmd == SW_SHOWMINIMIZED)
{
g_DialogPlacement.showCmd = SW_SHOWNORMAL;
}
DestroyWindow(hwndDlg);
g_DialogWin = NULL;
g_Plugins.clear();
return TRUE;
case WM_TIMER:
if (wParam == LOGTIMER)
{
UpdateAboutStatistics();
return TRUE;
}
break;
2009-02-10 18:37:48 +00:00
}
return FALSE;
2009-02-10 18:37:48 +00:00
}