mirror of
https://github.com/reactos/reactos.git
synced 2025-05-15 07:17:23 +00:00
[POWERCFG] Use a list of power schemes (power policy, id, name and description) rather than a bare array of power policies. This will simplify adding and deleting schemes quite a lot.
This commit is contained in:
parent
8896706566
commit
f62a4b2015
2 changed files with 298 additions and 158 deletions
|
@ -16,6 +16,7 @@
|
|||
#include <shlobj.h>
|
||||
#include <shlwapi.h>
|
||||
#include <powrprof.h>
|
||||
#include <ndk/rtlfuncs.h>
|
||||
|
||||
#include "resource.h"
|
||||
|
||||
|
@ -30,7 +31,6 @@ typedef struct
|
|||
extern HINSTANCE hApplet;
|
||||
extern GLOBAL_POWER_POLICY gGPP;
|
||||
extern POWER_POLICY gPP[];
|
||||
extern UINT guiIndex;
|
||||
|
||||
#define MAX_POWER_PAGES 32
|
||||
|
||||
|
|
|
@ -11,6 +11,24 @@
|
|||
|
||||
#include "powercfg.h"
|
||||
|
||||
|
||||
typedef struct _POWER_SCHEME
|
||||
{
|
||||
LIST_ENTRY ListEntry;
|
||||
UINT uId;
|
||||
LPTSTR pszName;
|
||||
LPTSTR pszDescription;
|
||||
POWER_POLICY PowerPolicy;
|
||||
} POWER_SCHEME, *PPOWER_SCHEME;
|
||||
|
||||
|
||||
typedef struct _POWER_SCHEMES_PAGE_DATA
|
||||
{
|
||||
LIST_ENTRY PowerSchemesList;
|
||||
PPOWER_SCHEME pActivePowerScheme;
|
||||
} POWER_SCHEMES_PAGE_DATA, *PPOWER_SCHEMES_PAGE_DATA;
|
||||
|
||||
|
||||
UINT Sec[]=
|
||||
{
|
||||
60,
|
||||
|
@ -31,20 +49,125 @@ UINT Sec[]=
|
|||
0
|
||||
};
|
||||
|
||||
HWND hList = 0;
|
||||
HWND hPos = 0;
|
||||
|
||||
unsigned aps = 0;
|
||||
static
|
||||
PPOWER_SCHEME
|
||||
AddPowerScheme(
|
||||
PPOWER_SCHEMES_PAGE_DATA pPageData,
|
||||
UINT uId,
|
||||
DWORD dwName,
|
||||
LPTSTR pszName,
|
||||
DWORD dwDescription,
|
||||
LPWSTR pszDescription,
|
||||
PPOWER_POLICY pp)
|
||||
{
|
||||
PPOWER_SCHEME pScheme;
|
||||
|
||||
#define MAX_POWER_POLICY 20
|
||||
pScheme = HeapAlloc(GetProcessHeap(),
|
||||
HEAP_ZERO_MEMORY,
|
||||
sizeof(POWER_SCHEME));
|
||||
if (pScheme == NULL)
|
||||
return NULL;
|
||||
|
||||
POWER_POLICY gPP[MAX_POWER_POLICY];
|
||||
UINT guiIndex = 0;
|
||||
HWND hwndDialog;
|
||||
pScheme->pszName = HeapAlloc(GetProcessHeap(),
|
||||
HEAP_ZERO_MEMORY,
|
||||
dwName + sizeof(TCHAR));
|
||||
|
||||
pScheme->pszDescription = HeapAlloc(GetProcessHeap(),
|
||||
HEAP_ZERO_MEMORY,
|
||||
dwDescription + sizeof(TCHAR));
|
||||
if (pScheme->pszName == NULL || pScheme->pszDescription == NULL)
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, pScheme->pszName);
|
||||
HeapFree(GetProcessHeap(), 0, pScheme->pszDescription);
|
||||
HeapFree(GetProcessHeap(), 0, pScheme);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pScheme->uId = uId;
|
||||
_tcscpy(pScheme->pszName, pszName);
|
||||
_tcscpy(pScheme->pszDescription, pszDescription);
|
||||
|
||||
CopyMemory(&pScheme->PowerPolicy, pp, sizeof(POWER_POLICY));
|
||||
|
||||
InsertTailList(&pPageData->PowerSchemesList, &pScheme->ListEntry);
|
||||
|
||||
return pScheme;
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
VOID
|
||||
DeletePowerScheme(
|
||||
PPOWER_SCHEME pScheme)
|
||||
{
|
||||
RemoveEntryList(&pScheme->ListEntry);
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, pScheme->pszName);
|
||||
HeapFree(GetProcessHeap(), 0, pScheme->pszDescription);
|
||||
HeapFree(GetProcessHeap(), 0, pScheme);
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
BOOLEAN
|
||||
CALLBACK
|
||||
EnumPowerSchemeCallback(
|
||||
UINT uiIndex,
|
||||
DWORD dwName,
|
||||
LPTSTR pszName,
|
||||
DWORD dwDesc,
|
||||
LPWSTR pszDesc,
|
||||
PPOWER_POLICY pp,
|
||||
LPARAM lParam)
|
||||
{
|
||||
if (ValidatePowerPolicies(0, pp))
|
||||
{
|
||||
AddPowerScheme((PPOWER_SCHEMES_PAGE_DATA)lParam,
|
||||
uiIndex,
|
||||
dwName,
|
||||
pszName,
|
||||
dwDesc,
|
||||
pszDesc,
|
||||
pp);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static
|
||||
VOID
|
||||
BuildSchemesList(
|
||||
PPOWER_SCHEMES_PAGE_DATA pPageData)
|
||||
{
|
||||
InitializeListHead(&pPageData->PowerSchemesList);
|
||||
|
||||
EnumPwrSchemes(EnumPowerSchemeCallback, (LPARAM)pPageData);
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
VOID
|
||||
DestroySchemesList(
|
||||
PPOWER_SCHEMES_PAGE_DATA pPageData)
|
||||
{
|
||||
PLIST_ENTRY ListEntry;
|
||||
PPOWER_SCHEME pScheme;
|
||||
|
||||
while (!IsListEmpty(&pPageData->PowerSchemesList))
|
||||
{
|
||||
ListEntry = pPageData->PowerSchemesList.Flink;
|
||||
pScheme = CONTAINING_RECORD(ListEntry, POWER_SCHEME, ListEntry);
|
||||
DeletePowerScheme(pScheme);
|
||||
}
|
||||
|
||||
pPageData->pActivePowerScheme = NULL;
|
||||
}
|
||||
|
||||
|
||||
BOOLEAN
|
||||
Pos_InitData(VOID)
|
||||
Pos_InitData(
|
||||
HWND hwndDlg)
|
||||
{
|
||||
SYSTEM_POWER_CAPABILITIES spc;
|
||||
/*
|
||||
|
@ -52,49 +175,49 @@ Pos_InitData(VOID)
|
|||
LONG movetop = 0;
|
||||
LONG moveright = 0;
|
||||
|
||||
if (GetWindowRect(hPos,&rectDlg))
|
||||
if (GetWindowRect(hwndDlg,&rectDlg))
|
||||
{
|
||||
if (GetWindowRect(GetDlgItem(hPos, IDC_SAT),&rectCtl2))
|
||||
if (GetWindowRect(GetDlgItem(hwndDlg, IDC_SAT),&rectCtl2))
|
||||
{
|
||||
if (GetWindowRect(GetDlgItem(hPos, IDC_MONITOR),&rectCtl))
|
||||
if (GetWindowRect(GetDlgItem(hwndDlg, IDC_MONITOR),&rectCtl))
|
||||
{
|
||||
movetop=rectCtl.top - rectCtl2.top;
|
||||
MoveWindow(GetDlgItem(hPos, IDC_MONITOR),rectCtl.left-rectDlg.left,rectCtl.top-rectDlg.top-movetop,rectCtl.right-rectCtl.left,rectCtl.bottom-rectCtl.top,FALSE);
|
||||
if (GetWindowRect(GetDlgItem(hPos, IDC_DISK),&rectCtl))
|
||||
MoveWindow(GetDlgItem(hwndDlg, IDC_MONITOR),rectCtl.left-rectDlg.left,rectCtl.top-rectDlg.top-movetop,rectCtl.right-rectCtl.left,rectCtl.bottom-rectCtl.top,FALSE);
|
||||
if (GetWindowRect(GetDlgItem(hwndDlg, IDC_DISK),&rectCtl))
|
||||
{
|
||||
MoveWindow(GetDlgItem(hPos, IDC_DISK),rectCtl.left-rectDlg.left,rectCtl.top-rectDlg.top-movetop,rectCtl.right-rectCtl.left,rectCtl.bottom-rectCtl.top,FALSE);
|
||||
MoveWindow(GetDlgItem(hwndDlg, IDC_DISK),rectCtl.left-rectDlg.left,rectCtl.top-rectDlg.top-movetop,rectCtl.right-rectCtl.left,rectCtl.bottom-rectCtl.top,FALSE);
|
||||
}
|
||||
if (GetWindowRect(GetDlgItem(hPos, IDC_STANDBY),&rectCtl))
|
||||
if (GetWindowRect(GetDlgItem(hwndDlg, IDC_STANDBY),&rectCtl))
|
||||
{
|
||||
MoveWindow(GetDlgItem(hPos, IDC_STANDBY),rectCtl.left-rectDlg.left,rectCtl.top-rectDlg.top-movetop,rectCtl.right-rectCtl.left,rectCtl.bottom-rectCtl.top,FALSE);
|
||||
MoveWindow(GetDlgItem(hwndDlg, IDC_STANDBY),rectCtl.left-rectDlg.left,rectCtl.top-rectDlg.top-movetop,rectCtl.right-rectCtl.left,rectCtl.bottom-rectCtl.top,FALSE);
|
||||
}
|
||||
if (GetWindowRect(GetDlgItem(hPos, IDC_HYBERNATE),&rectCtl))
|
||||
if (GetWindowRect(GetDlgItem(hwndDlg, IDC_HYBERNATE),&rectCtl))
|
||||
{
|
||||
MoveWindow(GetDlgItem(hPos, IDC_HYBERNATE),rectCtl.left-rectDlg.left,rectCtl.top-rectDlg.top-movetop,rectCtl.right-rectCtl.left,rectCtl.bottom-rectCtl.top,FALSE);
|
||||
MoveWindow(GetDlgItem(hwndDlg, IDC_HYBERNATE),rectCtl.left-rectDlg.left,rectCtl.top-rectDlg.top-movetop,rectCtl.right-rectCtl.left,rectCtl.bottom-rectCtl.top,FALSE);
|
||||
}
|
||||
if (GetWindowRect(GetDlgItem(hPos, IDC_MONITORDCLIST),&rectCtl2))
|
||||
if (GetWindowRect(GetDlgItem(hwndDlg, IDC_MONITORDCLIST),&rectCtl2))
|
||||
{
|
||||
movetop=movetop-8;
|
||||
if (GetWindowRect(GetDlgItem(hPos, IDC_MONITORACLIST),&rectCtl))
|
||||
if (GetWindowRect(GetDlgItem(hwndDlg, IDC_MONITORACLIST),&rectCtl))
|
||||
{
|
||||
moveright=rectCtl.right - rectCtl2.right;
|
||||
MoveWindow(GetDlgItem(hPos, IDC_MONITORACLIST),rectCtl.left-rectDlg.left,rectCtl.top-rectDlg.top-movetop,rectCtl.right-rectCtl.left-moveright,rectCtl.bottom-rectCtl.top,FALSE);
|
||||
if (GetWindowRect(GetDlgItem(hPos, IDC_DISKACLIST),&rectCtl))
|
||||
MoveWindow(GetDlgItem(hwndDlg, IDC_MONITORACLIST),rectCtl.left-rectDlg.left,rectCtl.top-rectDlg.top-movetop,rectCtl.right-rectCtl.left-moveright,rectCtl.bottom-rectCtl.top,FALSE);
|
||||
if (GetWindowRect(GetDlgItem(hwndDlg, IDC_DISKACLIST),&rectCtl))
|
||||
{
|
||||
MoveWindow(GetDlgItem(hPos, IDC_DISKACLIST),rectCtl.left-rectDlg.left,rectCtl.top-rectDlg.top-movetop,rectCtl.right-rectCtl.left-moveright,rectCtl.bottom-rectCtl.top,FALSE);
|
||||
MoveWindow(GetDlgItem(hwndDlg, IDC_DISKACLIST),rectCtl.left-rectDlg.left,rectCtl.top-rectDlg.top-movetop,rectCtl.right-rectCtl.left-moveright,rectCtl.bottom-rectCtl.top,FALSE);
|
||||
}
|
||||
if (GetWindowRect(GetDlgItem(hPos, IDC_STANDBYACLIST),&rectCtl))
|
||||
if (GetWindowRect(GetDlgItem(hwndDlg, IDC_STANDBYACLIST),&rectCtl))
|
||||
{
|
||||
MoveWindow(GetDlgItem(hPos, IDC_STANDBYACLIST),rectCtl.left-rectDlg.left,rectCtl.top-rectDlg.top-movetop,rectCtl.right-rectCtl.left-moveright,rectCtl.bottom-rectCtl.top,FALSE);
|
||||
MoveWindow(GetDlgItem(hwndDlg, IDC_STANDBYACLIST),rectCtl.left-rectDlg.left,rectCtl.top-rectDlg.top-movetop,rectCtl.right-rectCtl.left-moveright,rectCtl.bottom-rectCtl.top,FALSE);
|
||||
}
|
||||
if (GetWindowRect(GetDlgItem(hPos, IDC_HYBERNATEACLIST),&rectCtl))
|
||||
if (GetWindowRect(GetDlgItem(hwndDlg, IDC_HYBERNATEACLIST),&rectCtl))
|
||||
{
|
||||
MoveWindow(GetDlgItem(hPos, IDC_HYBERNATEACLIST),rectCtl.left-rectDlg.left,rectCtl.top-rectDlg.top-movetop,rectCtl.right-rectCtl.left-moveright,rectCtl.bottom-rectCtl.top,FALSE);
|
||||
MoveWindow(GetDlgItem(hwndDlg, IDC_HYBERNATEACLIST),rectCtl.left-rectDlg.left,rectCtl.top-rectDlg.top-movetop,rectCtl.right-rectCtl.left-moveright,rectCtl.bottom-rectCtl.top,FALSE);
|
||||
}
|
||||
}
|
||||
if (GetWindowRect(GetDlgItem(hPos, IDC_GRPDETAIL),&rectCtl))
|
||||
if (GetWindowRect(GetDlgItem(hwndDlg, IDC_GRPDETAIL),&rectCtl))
|
||||
{
|
||||
MoveWindow(GetDlgItem(hPos, IDC_GRPDETAIL),rectCtl.left-rectDlg.left,rectCtl.top-rectDlg.top,rectCtl.right-rectCtl.left,rectCtl.bottom-rectCtl.top,FALSE);
|
||||
MoveWindow(GetDlgItem(hwndDlg, IDC_GRPDETAIL),rectCtl.left-rectDlg.left,rectCtl.top-rectDlg.top,rectCtl.right-rectCtl.left,rectCtl.bottom-rectCtl.top,FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -110,71 +233,76 @@ Pos_InitData(VOID)
|
|||
|
||||
if (!spc.SystemBatteriesPresent)
|
||||
{
|
||||
ShowWindow(GetDlgItem(hPos, IDC_SAT), FALSE);
|
||||
ShowWindow(GetDlgItem(hPos, IDC_IAC), FALSE);
|
||||
ShowWindow(GetDlgItem(hPos, IDC_SAC), FALSE);
|
||||
ShowWindow(GetDlgItem(hPos, IDC_IDC), FALSE);
|
||||
ShowWindow(GetDlgItem(hPos, IDC_SDC), FALSE);
|
||||
ShowWindow(GetDlgItem(hPos, IDC_MONITORDCLIST), FALSE);
|
||||
ShowWindow(GetDlgItem(hPos, IDC_DISKDCLIST), FALSE);
|
||||
ShowWindow(GetDlgItem(hPos, IDC_STANDBYDCLIST), FALSE);
|
||||
ShowWindow(GetDlgItem(hPos, IDC_HYBERNATEDCLIST), FALSE);
|
||||
ShowWindow(GetDlgItem(hPos, IDC_HYBERNATEACLIST), spc.HiberFilePresent);
|
||||
ShowWindow(GetDlgItem(hwndDlg, IDC_SAT), FALSE);
|
||||
ShowWindow(GetDlgItem(hwndDlg, IDC_IAC), FALSE);
|
||||
ShowWindow(GetDlgItem(hwndDlg, IDC_SAC), FALSE);
|
||||
ShowWindow(GetDlgItem(hwndDlg, IDC_IDC), FALSE);
|
||||
ShowWindow(GetDlgItem(hwndDlg, IDC_SDC), FALSE);
|
||||
ShowWindow(GetDlgItem(hwndDlg, IDC_MONITORDCLIST), FALSE);
|
||||
ShowWindow(GetDlgItem(hwndDlg, IDC_DISKDCLIST), FALSE);
|
||||
ShowWindow(GetDlgItem(hwndDlg, IDC_STANDBYDCLIST), FALSE);
|
||||
ShowWindow(GetDlgItem(hwndDlg, IDC_HYBERNATEDCLIST), FALSE);
|
||||
ShowWindow(GetDlgItem(hwndDlg, IDC_HYBERNATEACLIST), spc.HiberFilePresent);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowWindow(GetDlgItem(hPos, IDC_HYBERNATEDCLIST), spc.HiberFilePresent);
|
||||
ShowWindow(GetDlgItem(hPos, IDC_HYBERNATEACLIST), FALSE);
|
||||
ShowWindow(GetDlgItem(hwndDlg, IDC_HYBERNATEDCLIST), spc.HiberFilePresent);
|
||||
ShowWindow(GetDlgItem(hwndDlg, IDC_HYBERNATEACLIST), FALSE);
|
||||
}
|
||||
|
||||
|
||||
if (!(spc.SystemS1 ||spc.SystemS2 || spc.SystemS3))
|
||||
{
|
||||
ShowWindow(GetDlgItem(hPos, IDC_STANDBYACLIST), TRUE);
|
||||
ShowWindow(GetDlgItem(hPos, IDC_STANDBYDCLIST), TRUE);
|
||||
ShowWindow(GetDlgItem(hPos, IDC_STANDBY), TRUE);
|
||||
ShowWindow(GetDlgItem(hwndDlg, IDC_STANDBYACLIST), TRUE);
|
||||
ShowWindow(GetDlgItem(hwndDlg, IDC_STANDBYDCLIST), TRUE);
|
||||
ShowWindow(GetDlgItem(hwndDlg, IDC_STANDBY), TRUE);
|
||||
}
|
||||
|
||||
ShowWindow(GetDlgItem(hPos, IDC_HYBERNATE), spc.HiberFilePresent);
|
||||
ShowWindow(GetDlgItem(hwndDlg, IDC_HYBERNATE), spc.HiberFilePresent);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
static VOID
|
||||
LoadConfig(HWND hwndDlg)
|
||||
static
|
||||
VOID
|
||||
LoadConfig(
|
||||
HWND hwndDlg)
|
||||
{
|
||||
PPOWER_SCHEME pScheme;
|
||||
INT i = 0, iCurSel = 0;
|
||||
UINT uiIndex;
|
||||
TCHAR szProfile[MAX_PATH];
|
||||
TCHAR szTemp[MAX_PATH];
|
||||
TCHAR szConfig[MAX_PATH];
|
||||
POWER_POLICY pp;
|
||||
PPOWER_POLICY pp;
|
||||
|
||||
iCurSel = (INT)SendDlgItemMessage(hwndDlg, IDC_ENERGYLIST,
|
||||
CB_GETCURSEL,
|
||||
0,
|
||||
0);
|
||||
iCurSel = (INT)SendDlgItemMessage(hwndDlg,
|
||||
IDC_ENERGYLIST,
|
||||
CB_GETCURSEL,
|
||||
0,
|
||||
0);
|
||||
if (iCurSel == CB_ERR)
|
||||
return;
|
||||
|
||||
memcpy(&pp, &gPP[iCurSel], sizeof(POWER_POLICY));
|
||||
pScheme = (PPOWER_SCHEME)SendDlgItemMessage(hwndDlg,
|
||||
IDC_ENERGYLIST,
|
||||
CB_GETITEMDATA,
|
||||
(WPARAM)iCurSel,
|
||||
0);
|
||||
if (pScheme == (PPOWER_SCHEME)CB_ERR)
|
||||
return;
|
||||
|
||||
uiIndex = (UINT)SendDlgItemMessage(hwndDlg, IDC_ENERGYLIST, CB_GETCURSEL, 0, 0);
|
||||
if (uiIndex != (UINT)CB_ERR)
|
||||
if (LoadString(hApplet, IDS_CONFIG1, szTemp, MAX_PATH))
|
||||
{
|
||||
SendDlgItemMessage(hwndDlg, IDC_ENERGYLIST, CB_GETLBTEXT, uiIndex, (LPARAM)szProfile);
|
||||
if (LoadString(hApplet, IDS_CONFIG1, szTemp, MAX_PATH))
|
||||
{
|
||||
_stprintf(szConfig,szTemp,szProfile);
|
||||
SetWindowText(GetDlgItem(hwndDlg, IDC_GRPDETAIL), szConfig);
|
||||
}
|
||||
_stprintf(szConfig, szTemp, pScheme->pszName);
|
||||
SetWindowText(GetDlgItem(hwndDlg, IDC_GRPDETAIL), szConfig);
|
||||
}
|
||||
|
||||
pp = &pScheme->PowerPolicy;
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
if (Sec[i] == pp.user.VideoTimeoutAc)
|
||||
if (Sec[i] == pp->user.VideoTimeoutAc)
|
||||
{
|
||||
SendDlgItemMessage(hwndDlg, IDC_MONITORACLIST,
|
||||
CB_SETCURSEL,
|
||||
|
@ -182,7 +310,7 @@ LoadConfig(HWND hwndDlg)
|
|||
(LPARAM)0);
|
||||
}
|
||||
|
||||
if (Sec[i] == pp.user.VideoTimeoutDc)
|
||||
if (Sec[i] == pp->user.VideoTimeoutDc)
|
||||
{
|
||||
SendDlgItemMessage(hwndDlg, IDC_MONITORDCLIST,
|
||||
CB_SETCURSEL,
|
||||
|
@ -190,7 +318,7 @@ LoadConfig(HWND hwndDlg)
|
|||
(LPARAM)0);
|
||||
}
|
||||
|
||||
if (Sec[i] == pp.user.SpindownTimeoutAc)
|
||||
if (Sec[i] == pp->user.SpindownTimeoutAc)
|
||||
{
|
||||
SendDlgItemMessage(hwndDlg, IDC_DISKACLIST,
|
||||
CB_SETCURSEL,
|
||||
|
@ -198,7 +326,7 @@ LoadConfig(HWND hwndDlg)
|
|||
(LPARAM)0);
|
||||
}
|
||||
|
||||
if (Sec[i] == pp.user.SpindownTimeoutDc) // IdleTimeoutDc)
|
||||
if (Sec[i] == pp->user.SpindownTimeoutDc)
|
||||
{
|
||||
SendDlgItemMessage(hwndDlg, IDC_DISKDCLIST,
|
||||
CB_SETCURSEL,
|
||||
|
@ -206,7 +334,7 @@ LoadConfig(HWND hwndDlg)
|
|||
(LPARAM)0);
|
||||
}
|
||||
|
||||
if (Sec[i] == pp.user.IdleTimeoutAc)
|
||||
if (Sec[i] == pp->user.IdleTimeoutAc)
|
||||
{
|
||||
SendDlgItemMessage(hwndDlg, IDC_STANDBYACLIST,
|
||||
CB_SETCURSEL,
|
||||
|
@ -214,7 +342,7 @@ LoadConfig(HWND hwndDlg)
|
|||
(LPARAM)0);
|
||||
}
|
||||
|
||||
if (Sec[i] == pp.user.IdleTimeoutDc)
|
||||
if (Sec[i] == pp->user.IdleTimeoutDc)
|
||||
{
|
||||
SendDlgItemMessage(hwndDlg, IDC_STANDBYDCLIST,
|
||||
CB_SETCURSEL,
|
||||
|
@ -222,7 +350,7 @@ LoadConfig(HWND hwndDlg)
|
|||
(LPARAM)0);
|
||||
}
|
||||
|
||||
if (Sec[i] == pp.mach.DozeS4TimeoutAc)
|
||||
if (Sec[i] == pp->mach.DozeS4TimeoutAc)
|
||||
{
|
||||
SendDlgItemMessage(hwndDlg, IDC_HYBERNATEACLIST,
|
||||
CB_SETCURSEL,
|
||||
|
@ -230,7 +358,7 @@ LoadConfig(HWND hwndDlg)
|
|||
(LPARAM)0);
|
||||
}
|
||||
|
||||
if (Sec[i] == pp.mach.DozeS4TimeoutDc)
|
||||
if (Sec[i] == pp->mach.DozeS4TimeoutDc)
|
||||
{
|
||||
SendDlgItemMessage(hwndDlg, IDC_HYBERNATEDCLIST,
|
||||
CB_SETCURSEL,
|
||||
|
@ -241,56 +369,6 @@ LoadConfig(HWND hwndDlg)
|
|||
}
|
||||
|
||||
|
||||
BOOLEAN CALLBACK
|
||||
callback_EnumPwrScheme(UINT uiIndex, DWORD dwName, LPTSTR sName, DWORD dwDesc,
|
||||
LPWSTR sDesc, PPOWER_POLICY pp, LPARAM lParam)
|
||||
{
|
||||
int index;
|
||||
|
||||
UNREFERENCED_PARAMETER(lParam);
|
||||
UNREFERENCED_PARAMETER(sDesc);
|
||||
UNREFERENCED_PARAMETER(dwDesc);
|
||||
UNREFERENCED_PARAMETER(dwName);
|
||||
|
||||
if (ValidatePowerPolicies(0, pp))
|
||||
{
|
||||
if (guiIndex >= MAX_POWER_POLICY)
|
||||
{
|
||||
// FIXME:
|
||||
// Implement store power policy dynamically
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
memcpy(&gPP[guiIndex], pp, sizeof(POWER_POLICY));
|
||||
guiIndex++;
|
||||
|
||||
index = (int)SendMessage(hList,
|
||||
CB_ADDSTRING,
|
||||
0,
|
||||
(LPARAM)sName);
|
||||
if (index == CB_ERR)
|
||||
return FALSE;
|
||||
|
||||
SendMessage(hList,
|
||||
CB_SETITEMDATA,
|
||||
index,
|
||||
(LPARAM)uiIndex);
|
||||
|
||||
if (aps == uiIndex)
|
||||
{
|
||||
SendMessage(hList,
|
||||
CB_SELECTSTRING,
|
||||
TRUE,
|
||||
(LPARAM)sName);
|
||||
LoadConfig(GetParent(hList));
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
static VOID
|
||||
Pos_InitPage(HWND hwndDlg)
|
||||
{
|
||||
|
@ -386,22 +464,32 @@ Pos_InitPage(HWND hwndDlg)
|
|||
static VOID
|
||||
Pos_SaveData(HWND hwndDlg)
|
||||
{
|
||||
INT iCurSel = 0, tmp = 0;
|
||||
PPOWER_SCHEME pScheme;
|
||||
INT iCurSel, tmp;
|
||||
|
||||
iCurSel = (INT)SendDlgItemMessage(hwndDlg, IDC_ENERGYLIST,
|
||||
CB_GETCURSEL,
|
||||
0,
|
||||
0);
|
||||
iCurSel = (INT)SendDlgItemMessage(hwndDlg,
|
||||
IDC_ENERGYLIST,
|
||||
CB_GETCURSEL,
|
||||
0,
|
||||
0);
|
||||
if (iCurSel == CB_ERR)
|
||||
return;
|
||||
|
||||
pScheme = (PPOWER_SCHEME)SendDlgItemMessage(hwndDlg,
|
||||
IDC_ENERGYLIST,
|
||||
CB_GETITEMDATA,
|
||||
(WPARAM)iCurSel,
|
||||
0);
|
||||
if (pScheme == (PPOWER_SCHEME)CB_ERR)
|
||||
return;
|
||||
|
||||
tmp = (INT)SendDlgItemMessage(hwndDlg, IDC_MONITORACLIST,
|
||||
CB_GETCURSEL,
|
||||
0,
|
||||
(LPARAM)0);
|
||||
if (tmp > 0 && tmp < 16)
|
||||
{
|
||||
gPP[iCurSel].user.VideoTimeoutAc = Sec[tmp];
|
||||
pScheme->PowerPolicy.user.VideoTimeoutAc = Sec[tmp];
|
||||
}
|
||||
|
||||
tmp = (INT)SendDlgItemMessage(hwndDlg, IDC_MONITORDCLIST,
|
||||
|
@ -410,7 +498,7 @@ Pos_SaveData(HWND hwndDlg)
|
|||
(LPARAM)0);
|
||||
if (tmp > 0 && tmp < 16)
|
||||
{
|
||||
gPP[iCurSel].user.VideoTimeoutDc = Sec[tmp];
|
||||
pScheme->PowerPolicy.user.VideoTimeoutDc = Sec[tmp];
|
||||
}
|
||||
|
||||
tmp = (INT)SendDlgItemMessage(hwndDlg, IDC_DISKACLIST,
|
||||
|
@ -419,7 +507,7 @@ Pos_SaveData(HWND hwndDlg)
|
|||
(LPARAM)0);
|
||||
if (tmp > 0 && tmp < 16)
|
||||
{
|
||||
gPP[iCurSel].user.SpindownTimeoutAc = Sec[tmp + 2];
|
||||
pScheme->PowerPolicy.user.SpindownTimeoutAc = Sec[tmp + 2];
|
||||
}
|
||||
|
||||
tmp = (INT)SendDlgItemMessage(hwndDlg, IDC_DISKDCLIST,
|
||||
|
@ -428,7 +516,7 @@ Pos_SaveData(HWND hwndDlg)
|
|||
(LPARAM)0);
|
||||
if (tmp > 0 && tmp < 16)
|
||||
{
|
||||
gPP[iCurSel].user.SpindownTimeoutDc = Sec[tmp + 2];
|
||||
pScheme->PowerPolicy.user.SpindownTimeoutDc = Sec[tmp + 2];
|
||||
}
|
||||
|
||||
tmp = (INT)SendDlgItemMessage(hwndDlg, IDC_STANDBYACLIST,
|
||||
|
@ -437,7 +525,7 @@ Pos_SaveData(HWND hwndDlg)
|
|||
(LPARAM)0);
|
||||
if (tmp > 0 && tmp < 16)
|
||||
{
|
||||
gPP[iCurSel].user.IdleTimeoutAc = Sec[tmp];
|
||||
pScheme->PowerPolicy.user.IdleTimeoutAc = Sec[tmp];
|
||||
}
|
||||
|
||||
tmp = (INT)SendDlgItemMessage(hwndDlg, IDC_STANDBYDCLIST,
|
||||
|
@ -446,7 +534,7 @@ Pos_SaveData(HWND hwndDlg)
|
|||
(LPARAM)0);
|
||||
if (tmp > 0 && tmp < 16)
|
||||
{
|
||||
gPP[iCurSel].user.IdleTimeoutDc = Sec[tmp];
|
||||
pScheme->PowerPolicy.user.IdleTimeoutDc = Sec[tmp];
|
||||
}
|
||||
|
||||
tmp = (INT)SendDlgItemMessage(hwndDlg, IDC_HYBERNATEACLIST,
|
||||
|
@ -455,7 +543,7 @@ Pos_SaveData(HWND hwndDlg)
|
|||
(LPARAM)0);
|
||||
if (tmp > 0 && tmp < 16)
|
||||
{
|
||||
gPP[iCurSel].mach.DozeS4TimeoutAc = Sec[tmp];
|
||||
pScheme->PowerPolicy.mach.DozeS4TimeoutAc = Sec[tmp];
|
||||
}
|
||||
|
||||
tmp = (INT)SendDlgItemMessage(hwndDlg, IDC_HYBERNATEDCLIST,
|
||||
|
@ -464,21 +552,21 @@ Pos_SaveData(HWND hwndDlg)
|
|||
(LPARAM)0);
|
||||
if (tmp > 0 && tmp < 16)
|
||||
{
|
||||
gPP[iCurSel].mach.DozeS4TimeoutDc = Sec[tmp];
|
||||
pScheme->PowerPolicy.mach.DozeS4TimeoutDc = Sec[tmp];
|
||||
}
|
||||
|
||||
SetActivePwrScheme(iCurSel, NULL, &gPP[iCurSel]);
|
||||
SetActivePwrScheme(iCurSel, NULL, &pScheme->PowerPolicy);
|
||||
LoadConfig(hwndDlg);
|
||||
}
|
||||
|
||||
|
||||
static BOOLEAN
|
||||
static BOOL
|
||||
DelScheme(HWND hwnd)
|
||||
{
|
||||
INT iCurSel;
|
||||
HWND hList;
|
||||
TCHAR szBuf[1024], szBufT[1024];
|
||||
UINT DelScheme;
|
||||
PPOWER_SCHEME pScheme;
|
||||
|
||||
hList = GetDlgItem(hwnd, IDC_ENERGYLIST);
|
||||
|
||||
|
@ -488,8 +576,8 @@ DelScheme(HWND hwnd)
|
|||
|
||||
SendMessage(hList, CB_SETCURSEL, iCurSel, 0);
|
||||
|
||||
DelScheme = SendMessage(hList, CB_GETITEMDATA, (WPARAM)iCurSel, 0);
|
||||
if (DelScheme == (UINT)CB_ERR)
|
||||
pScheme = (PPOWER_SCHEME)SendMessage(hList, CB_GETITEMDATA, (WPARAM)iCurSel, 0);
|
||||
if (pScheme == (PPOWER_SCHEME)CB_ERR)
|
||||
return FALSE;
|
||||
|
||||
LoadString(hApplet, IDS_DEL_SCHEME_TITLE, szBufT, sizeof(szBufT) / sizeof(TCHAR));
|
||||
|
@ -503,11 +591,11 @@ DelScheme(HWND hwnd)
|
|||
{
|
||||
SendMessage(hList, CB_SETCURSEL, (WPARAM)0, 0);
|
||||
SendMessage(hList, CB_DELETESTRING, (WPARAM)iCurSel, 0);
|
||||
if (Current == DelScheme)
|
||||
if (Current == pScheme->uId)
|
||||
Pos_SaveData(hwnd);
|
||||
}
|
||||
|
||||
if (DeletePwrScheme(DelScheme) != 0)
|
||||
if (DeletePwrScheme(pScheme->uId) != 0)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -515,14 +603,20 @@ DelScheme(HWND hwnd)
|
|||
}
|
||||
|
||||
|
||||
static BOOLEAN
|
||||
CreateEnergyList(HWND hwnd)
|
||||
static BOOL
|
||||
CreateEnergyList(
|
||||
HWND hwndDlg,
|
||||
PPOWER_SCHEMES_PAGE_DATA pPageData)
|
||||
{
|
||||
BOOLEAN retval;
|
||||
PLIST_ENTRY ListEntry;
|
||||
PPOWER_SCHEME pScheme;
|
||||
INT index;
|
||||
POWER_POLICY pp;
|
||||
SYSTEM_POWER_CAPABILITIES spc;
|
||||
HWND hwndList;
|
||||
unsigned aps = 0;
|
||||
|
||||
hList = hwnd;
|
||||
hwndList = GetDlgItem(hwndDlg, IDC_ENERGYLIST);
|
||||
|
||||
if (!GetActivePwrScheme(&aps))
|
||||
return FALSE;
|
||||
|
@ -550,20 +644,48 @@ CreateEnergyList(HWND hwnd)
|
|||
// Enable write / delete powerscheme button
|
||||
}
|
||||
|
||||
Pos_InitPage(GetParent(hwnd));
|
||||
Pos_InitPage(hwndDlg);
|
||||
|
||||
if (!GetActivePwrScheme(&aps))
|
||||
return FALSE;
|
||||
|
||||
retval = EnumPwrSchemes(callback_EnumPwrScheme, aps);
|
||||
|
||||
if (SendMessage(hwnd, CB_GETCOUNT, 0, 0) > 0)
|
||||
ListEntry = pPageData->PowerSchemesList.Flink;
|
||||
while (ListEntry != &pPageData->PowerSchemesList)
|
||||
{
|
||||
EnableWindow(GetDlgItem(hwndDialog, IDC_DELETE_BTN), TRUE);
|
||||
EnableWindow(GetDlgItem(hwndDialog, IDC_SAVEAS_BTN), TRUE);
|
||||
pScheme = CONTAINING_RECORD(ListEntry, POWER_SCHEME, ListEntry);
|
||||
|
||||
index = (int)SendMessage(hwndList,
|
||||
CB_ADDSTRING,
|
||||
0,
|
||||
(LPARAM)pScheme->pszName);
|
||||
if (index == CB_ERR)
|
||||
break;
|
||||
|
||||
SendMessage(hwndList,
|
||||
CB_SETITEMDATA,
|
||||
index,
|
||||
(LPARAM)pScheme);
|
||||
|
||||
if (aps == pScheme->uId)
|
||||
{
|
||||
SendMessage(hwndList,
|
||||
CB_SELECTSTRING,
|
||||
TRUE,
|
||||
(LPARAM)pScheme->pszName);
|
||||
|
||||
LoadConfig(hwndDlg);
|
||||
}
|
||||
|
||||
ListEntry = ListEntry->Flink;
|
||||
}
|
||||
|
||||
return retval;
|
||||
if (SendMessage(hwndList, CB_GETCOUNT, 0, 0) > 0)
|
||||
{
|
||||
EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_BTN), TRUE);
|
||||
EnableWindow(GetDlgItem(hwndDlg, IDC_SAVEAS_BTN), TRUE);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -575,12 +697,21 @@ PowerSchemesDlgProc(
|
|||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
switch(uMsg)
|
||||
PPOWER_SCHEMES_PAGE_DATA pPageData;
|
||||
|
||||
pPageData = (PPOWER_SCHEMES_PAGE_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
|
||||
|
||||
switch (uMsg)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
hPos = hwndDlg;
|
||||
hwndDialog = hwndDlg;
|
||||
if (!Pos_InitData())
|
||||
pPageData = (PPOWER_SCHEMES_PAGE_DATA)HeapAlloc(GetProcessHeap(),
|
||||
0,
|
||||
sizeof(PPOWER_SCHEMES_PAGE_DATA));
|
||||
SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pPageData);
|
||||
|
||||
BuildSchemesList(pPageData);
|
||||
|
||||
if (!Pos_InitData(hwndDlg))
|
||||
{
|
||||
// TODO:
|
||||
// Initialization failed
|
||||
|
@ -588,7 +719,7 @@ PowerSchemesDlgProc(
|
|||
MessageBox(hwndDlg,_T("Pos_InitData failed\n"), NULL, MB_OK);
|
||||
}
|
||||
|
||||
if (!CreateEnergyList(GetDlgItem(hwndDlg, IDC_ENERGYLIST)))
|
||||
if (!CreateEnergyList(hwndDlg, pPageData))
|
||||
{
|
||||
// TODO:
|
||||
// Initialization failed
|
||||
|
@ -597,6 +728,15 @@ PowerSchemesDlgProc(
|
|||
}
|
||||
return TRUE;
|
||||
|
||||
case WM_DESTROY:
|
||||
if (pPageData)
|
||||
{
|
||||
DestroySchemesList(pPageData);
|
||||
HeapFree(GetProcessHeap(), 0, pPageData);
|
||||
SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)NULL);
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_COMMAND:
|
||||
switch(LOWORD(wParam))
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue