1c2c66affSColin Finck /*
2c2c66affSColin Finck * PROJECT: ReactOS Power Configuration Applet
3c2c66affSColin Finck * LICENSE: GPL - See COPYING in the top level directory
4c2c66affSColin Finck * FILE: dll/cpl/powercfg/advanced.c
5c2c66affSColin Finck * PURPOSE: advanced tab of applet
6c2c66affSColin Finck * PROGRAMMERS: Alexander Wurzinger (Lohnegrim at gmx dot net)
7c2c66affSColin Finck * Johannes Anderwald (johannes.anderwald@reactos.org)
8c2c66affSColin Finck * Martin Rottensteiner
9c2c66affSColin Finck * Dmitry Chapyshev (lentind@yandex.ru)
10c2c66affSColin Finck */
11c2c66affSColin Finck
12c2c66affSColin Finck #include "powercfg.h"
13c2c66affSColin Finck
14c2c66affSColin Finck static POWER_ACTION g_SystemBatteries[3];
15c2c66affSColin Finck static POWER_ACTION g_PowerButton[5];
16c2c66affSColin Finck static POWER_ACTION g_SleepButton[5];
17c2c66affSColin Finck
18c2c66affSColin Finck
19c2c66affSColin Finck static
20c2c66affSColin Finck VOID
SetSystrayPowerIconState(BOOL bEnabled)21c2c66affSColin Finck SetSystrayPowerIconState(BOOL bEnabled)
22c2c66affSColin Finck {
23c2c66affSColin Finck HWND hwndTaskBar;
24c2c66affSColin Finck
25c2c66affSColin Finck hwndTaskBar = FindWindowW(L"SystemTray_Main", NULL);
26c2c66affSColin Finck if (hwndTaskBar == NULL)
27c2c66affSColin Finck return;
28c2c66affSColin Finck
29c2c66affSColin Finck SendMessageW(hwndTaskBar, WM_USER + 220, 1, bEnabled);
30c2c66affSColin Finck }
31c2c66affSColin Finck
32c2c66affSColin Finck static
33c2c66affSColin Finck BOOL
GetSystrayPowerIconState(VOID)34c2c66affSColin Finck GetSystrayPowerIconState(VOID)
35c2c66affSColin Finck {
36c2c66affSColin Finck HWND hwndTaskBar;
37c2c66affSColin Finck
38c2c66affSColin Finck hwndTaskBar = FindWindowW(L"SystemTray_Main", NULL);
39c2c66affSColin Finck if (hwndTaskBar == NULL)
40c2c66affSColin Finck return FALSE;
41c2c66affSColin Finck
42c2c66affSColin Finck return (BOOL)SendMessageW(hwndTaskBar, WM_USER + 221, 1, 0);
43c2c66affSColin Finck }
44c2c66affSColin Finck
45c2c66affSColin Finck static VOID
AddItem(HWND hDlgCtrl,INT ResourceId,LPARAM lParam,POWER_ACTION * lpAction)46c2c66affSColin Finck AddItem(HWND hDlgCtrl, INT ResourceId, LPARAM lParam, POWER_ACTION * lpAction)
47c2c66affSColin Finck {
48c2c66affSColin Finck TCHAR szBuffer[MAX_PATH];
49c2c66affSColin Finck LRESULT Index;
5022411ef2SEric Kohl
51c2c66affSColin Finck if (LoadString(hApplet, ResourceId, szBuffer, MAX_PATH) < MAX_PATH)
52c2c66affSColin Finck {
53cc13842aSEric Kohl Index = SendMessage(hDlgCtrl, CB_INSERTSTRING, -1, (LPARAM)szBuffer);
54c2c66affSColin Finck if (Index != CB_ERR)
55c2c66affSColin Finck {
56c2c66affSColin Finck SendMessage(hDlgCtrl, CB_SETITEMDATA, (WPARAM)Index, lParam);
57c2c66affSColin Finck lpAction[Index] = (POWER_ACTION)lParam;
58c2c66affSColin Finck }
59c2c66affSColin Finck }
60c2c66affSColin Finck }
61c2c66affSColin Finck
62c2c66affSColin Finck static INT
FindActionIndex(POWER_ACTION * lpAction,DWORD dwActionSize,POWER_ACTION poAction)63c2c66affSColin Finck FindActionIndex(POWER_ACTION * lpAction, DWORD dwActionSize, POWER_ACTION poAction)
64c2c66affSColin Finck {
65c2c66affSColin Finck INT Index;
66c2c66affSColin Finck
67c2c66affSColin Finck for (Index = 0; Index < (INT)dwActionSize; Index++)
68c2c66affSColin Finck {
69c2c66affSColin Finck if (lpAction[Index] == poAction)
70c2c66affSColin Finck return Index;
71c2c66affSColin Finck }
72c2c66affSColin Finck
73c2c66affSColin Finck return -1;
74c2c66affSColin Finck }
75c2c66affSColin Finck
76c2c66affSColin Finck static BOOLEAN
IsBatteryUsed(VOID)77c2c66affSColin Finck IsBatteryUsed(VOID)
78c2c66affSColin Finck {
79c2c66affSColin Finck SYSTEM_BATTERY_STATE sbs;
80c2c66affSColin Finck
81c2c66affSColin Finck if (CallNtPowerInformation(SystemBatteryState,NULL, (ULONG)0, &sbs, sizeof(SYSTEM_BATTERY_STATE)) == STATUS_SUCCESS)
82c2c66affSColin Finck {
83c2c66affSColin Finck if (sbs.BatteryPresent)
84c2c66affSColin Finck {
85c2c66affSColin Finck if (sbs.AcOnLine)
86c2c66affSColin Finck {
87c2c66affSColin Finck return FALSE;
88c2c66affSColin Finck }
89c2c66affSColin Finck return TRUE;
90c2c66affSColin Finck }
91c2c66affSColin Finck }
92c2c66affSColin Finck
93c2c66affSColin Finck return FALSE;
94c2c66affSColin Finck }
95c2c66affSColin Finck
96c2c66affSColin Finck POWER_ACTION
GetPowerActionFromPolicy(POWER_ACTION_POLICY * Policy,PSYSTEM_POWER_CAPABILITIES spc,BOOL bIsLid)97*3a207cdfSEric Kohl GetPowerActionFromPolicy(
98*3a207cdfSEric Kohl POWER_ACTION_POLICY *Policy,
99*3a207cdfSEric Kohl PSYSTEM_POWER_CAPABILITIES spc,
100*3a207cdfSEric Kohl BOOL bIsLid)
101c2c66affSColin Finck {
102c2c66affSColin Finck POWER_ACTION poAction = PowerActionNone;
103c2c66affSColin Finck /*
104c2c66affSColin Finck
105c2c66affSColin Finck TCHAR szBuffer[MAX_PATH];
106c2c66affSColin Finck
107c2c66affSColin Finck // Note: Windows XP SP2+ does not return the PowerAction code
108c2c66affSColin Finck // for PowerActionWarmEject + PowerActionShutdown but sets it
109c2c66affSColin Finck // to PowerActionNone and sets the Flags & EventCode
110c2c66affSColin Finck
111c2c66affSColin Finck
112c2c66affSColin Finck _stprintf(szBuffer, L"Action: %x EventCode %x Flags %x",Policy->Action, Policy->EventCode, Policy->Flags);
113c2c66affSColin Finck MessageBoxW(NULL, szBuffer, NULL, MB_OK);
114c2c66affSColin Finck
115c2c66affSColin Finck */
116c2c66affSColin Finck
117c2c66affSColin Finck if (Policy->Action == PowerActionNone)
118c2c66affSColin Finck {
119c2c66affSColin Finck if (Policy->Flags == (POWER_ACTION_UI_ALLOWED | POWER_ACTION_QUERY_ALLOWED))
120c2c66affSColin Finck {
121c2c66affSColin Finck if (Policy->EventCode == POWER_FORCE_TRIGGER_RESET)
122c2c66affSColin Finck {
123c2c66affSColin Finck poAction = PowerActionNone;
124c2c66affSColin Finck }
125c2c66affSColin Finck else if (Policy->EventCode == POWER_USER_NOTIFY_BUTTON)
126c2c66affSColin Finck {
127c2c66affSColin Finck poAction = PowerActionWarmEject;
128c2c66affSColin Finck }
129c2c66affSColin Finck else if (Policy->EventCode == POWER_USER_NOTIFY_SHUTDOWN)
130c2c66affSColin Finck {
131c2c66affSColin Finck poAction = PowerActionShutdown;
132c2c66affSColin Finck }
133c2c66affSColin Finck }
134c2c66affSColin Finck }
135c2c66affSColin Finck else
136c2c66affSColin Finck {
137c2c66affSColin Finck poAction = Policy->Action;
138*3a207cdfSEric Kohl if ((poAction == PowerActionHibernate) && !(spc->SystemS4 && spc->HiberFilePresent))
139*3a207cdfSEric Kohl poAction = PowerActionSleep;
140*3a207cdfSEric Kohl if ((poAction == PowerActionSleep) && !(spc->SystemS1 || spc->SystemS2 || spc->SystemS3))
141*3a207cdfSEric Kohl {
142*3a207cdfSEric Kohl if (bIsLid)
143*3a207cdfSEric Kohl poAction = PowerActionNone;
144*3a207cdfSEric Kohl else
145*3a207cdfSEric Kohl poAction = PowerActionShutdown;
146*3a207cdfSEric Kohl }
147c2c66affSColin Finck }
148c2c66affSColin Finck
149c2c66affSColin Finck return poAction;
150c2c66affSColin Finck }
151c2c66affSColin Finck
152c2c66affSColin Finck VOID
ShowCurrentPowerActionPolicy(HWND hDlgCtrl,POWER_ACTION * lpAction,DWORD dwActionSize,POWER_ACTION_POLICY * Policy,PSYSTEM_POWER_CAPABILITIES spc,BOOL bIsLid)153c2c66affSColin Finck ShowCurrentPowerActionPolicy(HWND hDlgCtrl,
154c2c66affSColin Finck POWER_ACTION *lpAction,
155c2c66affSColin Finck DWORD dwActionSize,
156*3a207cdfSEric Kohl POWER_ACTION_POLICY *Policy,
157*3a207cdfSEric Kohl PSYSTEM_POWER_CAPABILITIES spc,
158*3a207cdfSEric Kohl BOOL bIsLid)
159c2c66affSColin Finck {
160c2c66affSColin Finck int poActionIndex;
161c2c66affSColin Finck POWER_ACTION poAction;
162c2c66affSColin Finck
163*3a207cdfSEric Kohl poAction = GetPowerActionFromPolicy(Policy, spc, bIsLid);
164c2c66affSColin Finck poActionIndex = FindActionIndex(lpAction, dwActionSize, poAction);
165c2c66affSColin Finck
166c2c66affSColin Finck if (poActionIndex < 0)
167c2c66affSColin Finck {
168c2c66affSColin Finck return;
169c2c66affSColin Finck }
170c2c66affSColin Finck
171c2c66affSColin Finck SendMessage(hDlgCtrl, CB_SETCURSEL, (WPARAM)poActionIndex, (LPARAM)0);
172c2c66affSColin Finck }
173c2c66affSColin Finck
174c2c66affSColin Finck BOOLEAN
SaveCurrentPowerActionPolicy(IN HWND hDlgCtrl,OUT POWER_ACTION_POLICY * Policy)175c2c66affSColin Finck SaveCurrentPowerActionPolicy(IN HWND hDlgCtrl,
176c2c66affSColin Finck OUT POWER_ACTION_POLICY *Policy)
177c2c66affSColin Finck {
178c2c66affSColin Finck LRESULT Index;
179c2c66affSColin Finck LRESULT ItemData;
180c2c66affSColin Finck
181c2c66affSColin Finck Index = SendMessage(hDlgCtrl, CB_GETCURSEL, 0, 0);
182c2c66affSColin Finck if (Index == CB_ERR)
183c2c66affSColin Finck return FALSE;
184c2c66affSColin Finck
185c2c66affSColin Finck ItemData = SendMessage(hDlgCtrl, CB_GETITEMDATA, (WPARAM)Index, 0);
186c2c66affSColin Finck if (ItemData == CB_ERR)
187c2c66affSColin Finck return FALSE;
188c2c66affSColin Finck
189c2c66affSColin Finck switch(ItemData)
190c2c66affSColin Finck {
191c2c66affSColin Finck case PowerActionNone:
192c2c66affSColin Finck Policy->Action = PowerActionNone;
193c2c66affSColin Finck Policy->EventCode = POWER_FORCE_TRIGGER_RESET;
194c2c66affSColin Finck break;
19522411ef2SEric Kohl
196c2c66affSColin Finck case PowerActionWarmEject:
197c2c66affSColin Finck Policy->Action = PowerActionNone;
198c2c66affSColin Finck Policy->EventCode = POWER_USER_NOTIFY_BUTTON;
199c2c66affSColin Finck break;
20022411ef2SEric Kohl
201c2c66affSColin Finck case PowerActionShutdown:
202c2c66affSColin Finck Policy->Action = PowerActionNone;
203c2c66affSColin Finck Policy->EventCode = POWER_USER_NOTIFY_SHUTDOWN;
204c2c66affSColin Finck break;
20522411ef2SEric Kohl
206c2c66affSColin Finck case PowerActionSleep:
207c2c66affSColin Finck case PowerActionHibernate:
208c2c66affSColin Finck Policy->Action = (POWER_ACTION)ItemData;
209c2c66affSColin Finck Policy->EventCode = 0;
210c2c66affSColin Finck break;
21122411ef2SEric Kohl
212c2c66affSColin Finck default:
213c2c66affSColin Finck return FALSE;
214c2c66affSColin Finck }
21522411ef2SEric Kohl
216c2c66affSColin Finck Policy->Flags = (POWER_ACTION_UI_ALLOWED | POWER_ACTION_QUERY_ALLOWED);
217c2c66affSColin Finck
218c2c66affSColin Finck return TRUE;
219c2c66affSColin Finck }
220c2c66affSColin Finck
221c2c66affSColin Finck
222c2c66affSColin Finck //-------------------------------------------------------------------
223c2c66affSColin Finck
224c2c66affSColin Finck VOID
ShowCurrentPowerActionPolicies(HWND hwndDlg,PSYSTEM_POWER_CAPABILITIES spc)225*3a207cdfSEric Kohl ShowCurrentPowerActionPolicies(
226*3a207cdfSEric Kohl HWND hwndDlg,
227*3a207cdfSEric Kohl PSYSTEM_POWER_CAPABILITIES spc)
228c2c66affSColin Finck {
229c2c66affSColin Finck if (!IsBatteryUsed())
230c2c66affSColin Finck {
231*3a207cdfSEric Kohl ShowCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_LIDCLOSE),
232c2c66affSColin Finck g_SystemBatteries,
233c2c66affSColin Finck sizeof(g_SystemBatteries) / sizeof(POWER_ACTION),
234*3a207cdfSEric Kohl &gGPP.user.LidCloseAc,
235*3a207cdfSEric Kohl spc,
236*3a207cdfSEric Kohl TRUE);
237*3a207cdfSEric Kohl
238c2c66affSColin Finck ShowCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_POWERBUTTON),
239c2c66affSColin Finck g_PowerButton,
240c2c66affSColin Finck sizeof(g_PowerButton) / sizeof(POWER_ACTION),
241*3a207cdfSEric Kohl &gGPP.user.PowerButtonAc,
242*3a207cdfSEric Kohl spc,
243*3a207cdfSEric Kohl FALSE);
244c2c66affSColin Finck
245c2c66affSColin Finck ShowCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_SLEEPBUTTON),
246c2c66affSColin Finck g_SleepButton,
247c2c66affSColin Finck sizeof(g_SleepButton) / sizeof(POWER_ACTION),
248*3a207cdfSEric Kohl &gGPP.user.SleepButtonAc,
249*3a207cdfSEric Kohl spc,
250*3a207cdfSEric Kohl FALSE);
251c2c66affSColin Finck }
252c2c66affSColin Finck else
253c2c66affSColin Finck {
254c2c66affSColin Finck ShowCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_LIDCLOSE),
255*3a207cdfSEric Kohl g_SystemBatteries,
256*3a207cdfSEric Kohl sizeof(g_SystemBatteries) / sizeof(POWER_ACTION),
257*3a207cdfSEric Kohl &gGPP.user.LidCloseDc,
258*3a207cdfSEric Kohl spc,
259*3a207cdfSEric Kohl TRUE);
260c2c66affSColin Finck
261c2c66affSColin Finck ShowCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_POWERBUTTON),
262*3a207cdfSEric Kohl g_PowerButton,
263*3a207cdfSEric Kohl sizeof(g_PowerButton) / sizeof(POWER_ACTION),
264*3a207cdfSEric Kohl &gGPP.user.PowerButtonDc,
265*3a207cdfSEric Kohl spc,
266*3a207cdfSEric Kohl FALSE);
267c2c66affSColin Finck
268c2c66affSColin Finck ShowCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_SLEEPBUTTON),
269c2c66affSColin Finck g_SleepButton,
270c2c66affSColin Finck sizeof(g_SleepButton) / sizeof(POWER_ACTION),
271*3a207cdfSEric Kohl &gGPP.user.SleepButtonDc,
272*3a207cdfSEric Kohl spc,
273*3a207cdfSEric Kohl FALSE);
274c2c66affSColin Finck }
275c2c66affSColin Finck }
276c2c66affSColin Finck
277c2c66affSColin Finck VOID
Adv_InitDialog(HWND hwndDlg)278cc13842aSEric Kohl Adv_InitDialog(
279cc13842aSEric Kohl HWND hwndDlg)
280c2c66affSColin Finck {
281c2c66affSColin Finck HWND hList1;
282c2c66affSColin Finck HWND hList2;
283c2c66affSColin Finck HWND hList3;
284c2c66affSColin Finck
285c2c66affSColin Finck BOOLEAN bSuspend = FALSE;
286c2c66affSColin Finck BOOLEAN bHibernate;
287c2c66affSColin Finck BOOLEAN bShutdown;
2888fb2a2ddSEric Kohl BOOL bEnabled;
289c2c66affSColin Finck
290c2c66affSColin Finck SYSTEM_POWER_CAPABILITIES spc;
291c2c66affSColin Finck
2928fb2a2ddSEric Kohl bEnabled = GetSystrayPowerIconState();
2938fb2a2ddSEric Kohl
2948fb2a2ddSEric Kohl if (bEnabled)
295c2c66affSColin Finck gGPP.user.GlobalFlags |= EnableSysTrayBatteryMeter;
296c2c66affSColin Finck else
297c2c66affSColin Finck gGPP.user.GlobalFlags &= ~EnableSysTrayBatteryMeter;
298c2c66affSColin Finck
299cc13842aSEric Kohl CheckDlgButton(hwndDlg,
300c2c66affSColin Finck IDC_SYSTRAYBATTERYMETER,
3018fb2a2ddSEric Kohl bEnabled ? BST_CHECKED : BST_UNCHECKED);
302cc13842aSEric Kohl CheckDlgButton(hwndDlg,
303c2c66affSColin Finck IDC_PASSWORDLOGON,
304c2c66affSColin Finck gGPP.user.GlobalFlags & EnablePasswordLogon ? BST_CHECKED : BST_UNCHECKED);
305cc13842aSEric Kohl CheckDlgButton(hwndDlg,
306c2c66affSColin Finck IDC_VIDEODIMDISPLAY,
307c2c66affSColin Finck gGPP.user.GlobalFlags & EnableVideoDimDisplay ? BST_CHECKED : BST_UNCHECKED);
308c2c66affSColin Finck
309c2c66affSColin Finck GetPwrCapabilities(&spc);
310c2c66affSColin Finck
311c2c66affSColin Finck if (spc.SystemS1 || spc.SystemS2 || spc.SystemS3)
312c2c66affSColin Finck bSuspend=TRUE;
313c2c66affSColin Finck
314c2c66affSColin Finck bHibernate = spc.HiberFilePresent;
315c2c66affSColin Finck bShutdown = spc.SystemS5;
316c2c66affSColin Finck
317cc13842aSEric Kohl hList1 = GetDlgItem(hwndDlg, IDC_LIDCLOSE);
318c2c66affSColin Finck SendMessage(hList1, CB_RESETCONTENT, 0, 0);
319c2c66affSColin Finck
320c2c66affSColin Finck memset(g_SystemBatteries, 0x0, sizeof(g_SystemBatteries));
321c2c66affSColin Finck if (spc.SystemBatteriesPresent)
322c2c66affSColin Finck {
323c2c66affSColin Finck AddItem(hList1, IDS_PowerActionNone1, (LPARAM)PowerActionNone, g_SystemBatteries);
324c2c66affSColin Finck
325c2c66affSColin Finck if (bSuspend)
326c2c66affSColin Finck {
327c2c66affSColin Finck AddItem(hList1, IDS_PowerActionSleep, (LPARAM)PowerActionSleep, g_SystemBatteries);
328c2c66affSColin Finck }
329c2c66affSColin Finck
330c2c66affSColin Finck if (bHibernate)
331c2c66affSColin Finck {
332c2c66affSColin Finck AddItem(hList1, IDS_PowerActionHibernate, (LPARAM)PowerActionHibernate, g_SystemBatteries);
333c2c66affSColin Finck }
334c2c66affSColin Finck }
335c2c66affSColin Finck else
336c2c66affSColin Finck {
337cc13842aSEric Kohl ShowWindow(GetDlgItem(hwndDlg, IDC_VIDEODIMDISPLAY), FALSE);
338cc13842aSEric Kohl ShowWindow(GetDlgItem(hwndDlg, IDC_SLIDCLOSE), FALSE);
339c2c66affSColin Finck ShowWindow(hList1, FALSE);
340c2c66affSColin Finck }
341c2c66affSColin Finck
342cc13842aSEric Kohl hList2 = GetDlgItem(hwndDlg, IDC_POWERBUTTON);
343c2c66affSColin Finck SendMessage(hList2, CB_RESETCONTENT, 0, 0);
344c2c66affSColin Finck
345c2c66affSColin Finck memset(g_PowerButton, 0x0, sizeof(g_PowerButton));
346c2c66affSColin Finck if (spc.PowerButtonPresent)
347c2c66affSColin Finck {
348c2c66affSColin Finck AddItem(hList2, IDS_PowerActionNone1, (LPARAM)PowerActionNone, g_PowerButton);
349c2c66affSColin Finck AddItem(hList2, IDS_PowerActionWarmEject, (LPARAM)PowerActionWarmEject, g_PowerButton);
350c2c66affSColin Finck
351c2c66affSColin Finck if (bSuspend)
352c2c66affSColin Finck {
353c2c66affSColin Finck AddItem(hList2, IDS_PowerActionSleep, (LPARAM)PowerActionSleep, g_PowerButton);
354c2c66affSColin Finck }
355c2c66affSColin Finck
356c2c66affSColin Finck if (bHibernate)
357c2c66affSColin Finck {
358c2c66affSColin Finck AddItem(hList2, IDS_PowerActionHibernate, (LPARAM)PowerActionHibernate, g_PowerButton);
359c2c66affSColin Finck }
36022411ef2SEric Kohl
361c2c66affSColin Finck if (bShutdown)
362c2c66affSColin Finck {
363c2c66affSColin Finck AddItem(hList2, IDS_PowerActionShutdown, (LPARAM)PowerActionShutdown, g_PowerButton);
364c2c66affSColin Finck }
365c2c66affSColin Finck }
366c2c66affSColin Finck else
367c2c66affSColin Finck {
368cc13842aSEric Kohl ShowWindow(GetDlgItem(hwndDlg, IDC_SPOWERBUTTON), FALSE);
369c2c66affSColin Finck ShowWindow(hList2, FALSE);
370c2c66affSColin Finck }
371c2c66affSColin Finck
372cc13842aSEric Kohl hList3 = GetDlgItem(hwndDlg, IDC_SLEEPBUTTON);
373c2c66affSColin Finck SendMessage(hList3, CB_RESETCONTENT, 0, 0);
374c2c66affSColin Finck memset(g_SleepButton, 0x0, sizeof(g_SleepButton));
375c2c66affSColin Finck
376c2c66affSColin Finck if (spc.SleepButtonPresent)
377c2c66affSColin Finck {
378c2c66affSColin Finck AddItem(hList3, IDS_PowerActionNone1, (LPARAM)PowerActionNone, g_SleepButton);
379c2c66affSColin Finck AddItem(hList3, IDS_PowerActionWarmEject, (LPARAM)PowerActionWarmEject, g_SleepButton);
380c2c66affSColin Finck
381c2c66affSColin Finck if (bSuspend)
382c2c66affSColin Finck {
383c2c66affSColin Finck AddItem(hList3, IDS_PowerActionSleep, (LPARAM)PowerActionSleep, g_SleepButton);
384c2c66affSColin Finck }
385c2c66affSColin Finck
386c2c66affSColin Finck if (bHibernate)
387c2c66affSColin Finck {
388c2c66affSColin Finck AddItem(hList3, IDS_PowerActionHibernate, (LPARAM)PowerActionHibernate, g_SleepButton);
389c2c66affSColin Finck }
390c2c66affSColin Finck
391c2c66affSColin Finck if (bShutdown)
392c2c66affSColin Finck {
393c2c66affSColin Finck AddItem(hList3, IDS_PowerActionShutdown, (LPARAM)PowerActionShutdown, g_SleepButton);
394c2c66affSColin Finck }
395c2c66affSColin Finck }
396c2c66affSColin Finck else
397c2c66affSColin Finck {
398cc13842aSEric Kohl ShowWindow(GetDlgItem(hwndDlg, IDC_SSLEEPBUTTON), FALSE);
399c2c66affSColin Finck ShowWindow(hList3, FALSE);
400c2c66affSColin Finck }
401c2c66affSColin Finck
402c2c66affSColin Finck if (ReadGlobalPwrPolicy(&gGPP))
403c2c66affSColin Finck {
404*3a207cdfSEric Kohl ShowCurrentPowerActionPolicies(hwndDlg, &spc);
405c2c66affSColin Finck }
406c2c66affSColin Finck }
407c2c66affSColin Finck
408c2c66affSColin Finck static VOID
Adv_SaveData(HWND hwndDlg)409c2c66affSColin Finck Adv_SaveData(HWND hwndDlg)
410c2c66affSColin Finck {
411c2c66affSColin Finck BOOL bSystrayBatteryMeter;
412c2c66affSColin Finck BOOL bPasswordLogon;
413c2c66affSColin Finck BOOL bVideoDimDisplay;
414c2c66affSColin Finck
415c2c66affSColin Finck bSystrayBatteryMeter =
416c2c66affSColin Finck (IsDlgButtonChecked(hwndDlg, IDC_SYSTRAYBATTERYMETER) == BST_CHECKED);
417c2c66affSColin Finck
418c2c66affSColin Finck bPasswordLogon =
419c2c66affSColin Finck (IsDlgButtonChecked(hwndDlg, IDC_PASSWORDLOGON) == BST_CHECKED);
420c2c66affSColin Finck
421c2c66affSColin Finck bVideoDimDisplay =
422c2c66affSColin Finck (IsDlgButtonChecked(hwndDlg, IDC_VIDEODIMDISPLAY) == BST_CHECKED);
423c2c66affSColin Finck
424c2c66affSColin Finck if (bSystrayBatteryMeter)
425c2c66affSColin Finck {
426c2c66affSColin Finck if (!(gGPP.user.GlobalFlags & EnableSysTrayBatteryMeter))
427c2c66affSColin Finck {
428c2c66affSColin Finck gGPP.user.GlobalFlags = gGPP.user.GlobalFlags + EnableSysTrayBatteryMeter;
429c2c66affSColin Finck }
430c2c66affSColin Finck }
431c2c66affSColin Finck else
432c2c66affSColin Finck {
433c2c66affSColin Finck if ((gGPP.user.GlobalFlags & EnableSysTrayBatteryMeter))
434c2c66affSColin Finck {
435c2c66affSColin Finck gGPP.user.GlobalFlags = gGPP.user.GlobalFlags - EnableSysTrayBatteryMeter;
436c2c66affSColin Finck }
437c2c66affSColin Finck }
438c2c66affSColin Finck
439c2c66affSColin Finck if (bPasswordLogon)
440c2c66affSColin Finck {
441c2c66affSColin Finck if (!(gGPP.user.GlobalFlags & EnablePasswordLogon))
442c2c66affSColin Finck {
443c2c66affSColin Finck gGPP.user.GlobalFlags = gGPP.user.GlobalFlags + EnablePasswordLogon;
444c2c66affSColin Finck }
445c2c66affSColin Finck }
446c2c66affSColin Finck else
447c2c66affSColin Finck {
448c2c66affSColin Finck if ((gGPP.user.GlobalFlags & EnablePasswordLogon))
449c2c66affSColin Finck {
450c2c66affSColin Finck gGPP.user.GlobalFlags = gGPP.user.GlobalFlags - EnablePasswordLogon;
451c2c66affSColin Finck }
452c2c66affSColin Finck }
453c2c66affSColin Finck
454c2c66affSColin Finck if (bVideoDimDisplay)
455c2c66affSColin Finck {
456c2c66affSColin Finck if (!(gGPP.user.GlobalFlags & EnableVideoDimDisplay))
457c2c66affSColin Finck {
458c2c66affSColin Finck gGPP.user.GlobalFlags = gGPP.user.GlobalFlags + EnableVideoDimDisplay;
459c2c66affSColin Finck }
460c2c66affSColin Finck }
461c2c66affSColin Finck else
462c2c66affSColin Finck {
463c2c66affSColin Finck if ((gGPP.user.GlobalFlags & EnableVideoDimDisplay))
464c2c66affSColin Finck {
465c2c66affSColin Finck gGPP.user.GlobalFlags = gGPP.user.GlobalFlags - EnableVideoDimDisplay;
466c2c66affSColin Finck }
467c2c66affSColin Finck }
468c2c66affSColin Finck
469c2c66affSColin Finck if (!IsBatteryUsed())
470c2c66affSColin Finck {
471c2c66affSColin Finck #if 0
472c2c66affSColin Finck SaveCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_LIDCLOSE), &gGPP.user.LidCloseAc);
473c2c66affSColin Finck #endif
474cc13842aSEric Kohl SaveCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_POWERBUTTON), &gGPP.user.PowerButtonAc);
475cc13842aSEric Kohl SaveCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_SLEEPBUTTON), &gGPP.user.SleepButtonAc);
476c2c66affSColin Finck }
477c2c66affSColin Finck else
478c2c66affSColin Finck {
479c2c66affSColin Finck #if 0
480c2c66affSColin Finck SaveCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_LIDCLOSE), &gGPP.user.LidCloseDc);
481cc13842aSEric Kohl SaveCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_POWERBUTTON), &gGPP.user.PowerButtonDc);
482c2c66affSColin Finck SaveCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_SLEEPBUTTON), &gGPP.user.SleepButtonDc);
483c2c66affSColin Finck #endif
484c2c66affSColin Finck }
485c2c66affSColin Finck
486c2c66affSColin Finck if (!WriteGlobalPwrPolicy(&gGPP))
487c2c66affSColin Finck {
488c2c66affSColin Finck MessageBox(hwndDlg, L"WriteGlobalPwrPolicy failed", NULL, MB_OK);
489c2c66affSColin Finck }
490c2c66affSColin Finck
4918fb2a2ddSEric Kohl SetSystrayPowerIconState(bSystrayBatteryMeter);
492c2c66affSColin Finck
493cc13842aSEric Kohl // Adv_InitDialog(hwndDlg);
494c2c66affSColin Finck }
495c2c66affSColin Finck
496c2c66affSColin Finck /* Property page dialog callback */
497c2c66affSColin Finck INT_PTR CALLBACK
AdvancedDlgProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)498c2c66affSColin Finck AdvancedDlgProc(HWND hwndDlg,
499c2c66affSColin Finck UINT uMsg,
500c2c66affSColin Finck WPARAM wParam,
501c2c66affSColin Finck LPARAM lParam)
502c2c66affSColin Finck {
503c2c66affSColin Finck switch (uMsg)
504c2c66affSColin Finck {
505c2c66affSColin Finck case WM_INITDIALOG:
506cc13842aSEric Kohl Adv_InitDialog(hwndDlg);
507c2c66affSColin Finck return TRUE;
50822411ef2SEric Kohl
509c2c66affSColin Finck case WM_COMMAND:
510c2c66affSColin Finck switch (LOWORD(wParam))
511c2c66affSColin Finck {
512c2c66affSColin Finck case IDC_SYSTRAYBATTERYMETER:
513c2c66affSColin Finck case IDC_PASSWORDLOGON:
514c2c66affSColin Finck case IDC_VIDEODIMDISPLAY:
515c2c66affSColin Finck if (HIWORD(wParam) == BN_CLICKED)
516c2c66affSColin Finck {
517c2c66affSColin Finck PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
518c2c66affSColin Finck }
519c2c66affSColin Finck break;
52022411ef2SEric Kohl
521c2c66affSColin Finck case IDC_LIDCLOSE:
522c2c66affSColin Finck case IDC_POWERBUTTON:
523c2c66affSColin Finck case IDC_SLEEPBUTTON:
524c2c66affSColin Finck if (HIWORD(wParam) == CBN_SELCHANGE)
525c2c66affSColin Finck {
526c2c66affSColin Finck PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
527c2c66affSColin Finck }
528c2c66affSColin Finck break;
529c2c66affSColin Finck }
530c2c66affSColin Finck break;
53122411ef2SEric Kohl
532c2c66affSColin Finck case WM_NOTIFY:
533cc13842aSEric Kohl switch (((LPNMHDR)lParam)->code)
534c2c66affSColin Finck {
535cc13842aSEric Kohl case PSN_APPLY:
536c2c66affSColin Finck Adv_SaveData(hwndDlg);
537cc13842aSEric Kohl return TRUE;
538cc13842aSEric Kohl
539cc13842aSEric Kohl case PSN_SETACTIVE:
540cc13842aSEric Kohl Adv_InitDialog(hwndDlg);
541c2c66affSColin Finck return TRUE;
542c2c66affSColin Finck }
543cc13842aSEric Kohl break;
544c2c66affSColin Finck }
54522411ef2SEric Kohl
546c2c66affSColin Finck return FALSE;
547c2c66affSColin Finck }
548