[POWERCFG] Fix the initialization of the power schemes page
[reactos.git] / dll / cpl / powercfg / powershemes.c
1 /*
2 * PROJECT: ReactOS Power Configuration Applet
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/cpl/powercfg/powershemes.c
5 * PURPOSE: powerschemes tab of applet
6 * PROGRAMMERS: Alexander Wurzinger (Lohnegrim at gmx dot net)
7 * Johannes Anderwald (johannes.anderwald@reactos.org)
8 * Martin Rottensteiner
9 * Dmitry Chapyshev (lentind@yandex.ru)
10 */
11
12 #include "powercfg.h"
13
14
15 typedef struct _POWER_SCHEME
16 {
17 LIST_ENTRY ListEntry;
18 UINT uId;
19 LPTSTR pszName;
20 LPTSTR pszDescription;
21 POWER_POLICY PowerPolicy;
22 } POWER_SCHEME, *PPOWER_SCHEME;
23
24
25 typedef struct _POWER_SCHEMES_PAGE_DATA
26 {
27 LIST_ENTRY PowerSchemesList;
28 PPOWER_SCHEME pActivePowerScheme;
29 } POWER_SCHEMES_PAGE_DATA, *PPOWER_SCHEMES_PAGE_DATA;
30
31
32 UINT Sec[]=
33 {
34 60,
35 120,
36 180,
37 300,
38 600,
39 900,
40 1200,
41 1500,
42 1800,
43 2700,
44 3600,
45 7200,
46 10800,
47 14400,
48 18000,
49 0
50 };
51
52
53 static
54 PPOWER_SCHEME
55 AddPowerScheme(
56 PPOWER_SCHEMES_PAGE_DATA pPageData,
57 UINT uId,
58 DWORD dwName,
59 LPTSTR pszName,
60 DWORD dwDescription,
61 LPWSTR pszDescription,
62 PPOWER_POLICY pp)
63 {
64 PPOWER_SCHEME pScheme;
65
66 pScheme = HeapAlloc(GetProcessHeap(),
67 HEAP_ZERO_MEMORY,
68 sizeof(POWER_SCHEME));
69 if (pScheme == NULL)
70 return NULL;
71
72 pScheme->pszName = HeapAlloc(GetProcessHeap(),
73 HEAP_ZERO_MEMORY,
74 dwName + sizeof(TCHAR));
75
76 pScheme->pszDescription = HeapAlloc(GetProcessHeap(),
77 HEAP_ZERO_MEMORY,
78 dwDescription + sizeof(TCHAR));
79 if (pScheme->pszName == NULL || pScheme->pszDescription == NULL)
80 {
81 HeapFree(GetProcessHeap(), 0, pScheme->pszName);
82 HeapFree(GetProcessHeap(), 0, pScheme->pszDescription);
83 HeapFree(GetProcessHeap(), 0, pScheme);
84 return NULL;
85 }
86
87 pScheme->uId = uId;
88 _tcscpy(pScheme->pszName, pszName);
89 _tcscpy(pScheme->pszDescription, pszDescription);
90
91 CopyMemory(&pScheme->PowerPolicy, pp, sizeof(POWER_POLICY));
92
93 InsertTailList(&pPageData->PowerSchemesList, &pScheme->ListEntry);
94
95 return pScheme;
96 }
97
98
99 static
100 VOID
101 DeletePowerScheme(
102 PPOWER_SCHEME pScheme)
103 {
104 RemoveEntryList(&pScheme->ListEntry);
105
106 HeapFree(GetProcessHeap(), 0, pScheme->pszName);
107 HeapFree(GetProcessHeap(), 0, pScheme->pszDescription);
108 HeapFree(GetProcessHeap(), 0, pScheme);
109 }
110
111
112 static
113 BOOLEAN
114 CALLBACK
115 EnumPowerSchemeCallback(
116 UINT uiIndex,
117 DWORD dwName,
118 LPTSTR pszName,
119 DWORD dwDesc,
120 LPWSTR pszDesc,
121 PPOWER_POLICY pp,
122 LPARAM lParam)
123 {
124 if (ValidatePowerPolicies(0, pp))
125 {
126 AddPowerScheme((PPOWER_SCHEMES_PAGE_DATA)lParam,
127 uiIndex,
128 dwName,
129 pszName,
130 dwDesc,
131 pszDesc,
132 pp);
133 }
134
135 return TRUE;
136 }
137
138 static
139 VOID
140 BuildSchemesList(
141 PPOWER_SCHEMES_PAGE_DATA pPageData)
142 {
143 InitializeListHead(&pPageData->PowerSchemesList);
144
145 EnumPwrSchemes(EnumPowerSchemeCallback, (LPARAM)pPageData);
146 }
147
148
149 static
150 VOID
151 DestroySchemesList(
152 PPOWER_SCHEMES_PAGE_DATA pPageData)
153 {
154 PLIST_ENTRY ListEntry;
155 PPOWER_SCHEME pScheme;
156
157 while (!IsListEmpty(&pPageData->PowerSchemesList))
158 {
159 ListEntry = pPageData->PowerSchemesList.Flink;
160 pScheme = CONTAINING_RECORD(ListEntry, POWER_SCHEME, ListEntry);
161 DeletePowerScheme(pScheme);
162 }
163
164 pPageData->pActivePowerScheme = NULL;
165 }
166
167
168 BOOLEAN
169 Pos_InitData(
170 HWND hwndDlg)
171 {
172 SYSTEM_POWER_CAPABILITIES spc;
173 /*
174 RECT rectCtl, rectDlg, rectCtl2;
175 LONG movetop = 0;
176 LONG moveright = 0;
177
178 if (GetWindowRect(hwndDlg,&rectDlg))
179 {
180 if (GetWindowRect(GetDlgItem(hwndDlg, IDC_SAT),&rectCtl2))
181 {
182 if (GetWindowRect(GetDlgItem(hwndDlg, IDC_MONITOR),&rectCtl))
183 {
184 movetop=rectCtl.top - rectCtl2.top;
185 MoveWindow(GetDlgItem(hwndDlg, IDC_MONITOR),rectCtl.left-rectDlg.left,rectCtl.top-rectDlg.top-movetop,rectCtl.right-rectCtl.left,rectCtl.bottom-rectCtl.top,FALSE);
186 if (GetWindowRect(GetDlgItem(hwndDlg, IDC_DISK),&rectCtl))
187 {
188 MoveWindow(GetDlgItem(hwndDlg, IDC_DISK),rectCtl.left-rectDlg.left,rectCtl.top-rectDlg.top-movetop,rectCtl.right-rectCtl.left,rectCtl.bottom-rectCtl.top,FALSE);
189 }
190 if (GetWindowRect(GetDlgItem(hwndDlg, IDC_STANDBY),&rectCtl))
191 {
192 MoveWindow(GetDlgItem(hwndDlg, IDC_STANDBY),rectCtl.left-rectDlg.left,rectCtl.top-rectDlg.top-movetop,rectCtl.right-rectCtl.left,rectCtl.bottom-rectCtl.top,FALSE);
193 }
194 if (GetWindowRect(GetDlgItem(hwndDlg, IDC_HYBERNATE),&rectCtl))
195 {
196 MoveWindow(GetDlgItem(hwndDlg, IDC_HYBERNATE),rectCtl.left-rectDlg.left,rectCtl.top-rectDlg.top-movetop,rectCtl.right-rectCtl.left,rectCtl.bottom-rectCtl.top,FALSE);
197 }
198 if (GetWindowRect(GetDlgItem(hwndDlg, IDC_MONITORDCLIST),&rectCtl2))
199 {
200 movetop=movetop-8;
201 if (GetWindowRect(GetDlgItem(hwndDlg, IDC_MONITORACLIST),&rectCtl))
202 {
203 moveright=rectCtl.right - rectCtl2.right;
204 MoveWindow(GetDlgItem(hwndDlg, IDC_MONITORACLIST),rectCtl.left-rectDlg.left,rectCtl.top-rectDlg.top-movetop,rectCtl.right-rectCtl.left-moveright,rectCtl.bottom-rectCtl.top,FALSE);
205 if (GetWindowRect(GetDlgItem(hwndDlg, IDC_DISKACLIST),&rectCtl))
206 {
207 MoveWindow(GetDlgItem(hwndDlg, IDC_DISKACLIST),rectCtl.left-rectDlg.left,rectCtl.top-rectDlg.top-movetop,rectCtl.right-rectCtl.left-moveright,rectCtl.bottom-rectCtl.top,FALSE);
208 }
209 if (GetWindowRect(GetDlgItem(hwndDlg, IDC_STANDBYACLIST),&rectCtl))
210 {
211 MoveWindow(GetDlgItem(hwndDlg, IDC_STANDBYACLIST),rectCtl.left-rectDlg.left,rectCtl.top-rectDlg.top-movetop,rectCtl.right-rectCtl.left-moveright,rectCtl.bottom-rectCtl.top,FALSE);
212 }
213 if (GetWindowRect(GetDlgItem(hwndDlg, IDC_HYBERNATEACLIST),&rectCtl))
214 {
215 MoveWindow(GetDlgItem(hwndDlg, IDC_HYBERNATEACLIST),rectCtl.left-rectDlg.left,rectCtl.top-rectDlg.top-movetop,rectCtl.right-rectCtl.left-moveright,rectCtl.bottom-rectCtl.top,FALSE);
216 }
217 }
218 if (GetWindowRect(GetDlgItem(hwndDlg, IDC_GRPDETAIL),&rectCtl))
219 {
220 MoveWindow(GetDlgItem(hwndDlg, IDC_GRPDETAIL),rectCtl.left-rectDlg.left,rectCtl.top-rectDlg.top,rectCtl.right-rectCtl.left,rectCtl.bottom-rectCtl.top,FALSE);
221 }
222 }
223 }
224 }
225 }
226 }
227 */
228
229 if (!GetPwrCapabilities(&spc))
230 {
231 return FALSE;
232 }
233
234 if (!spc.SystemBatteriesPresent)
235 {
236 ShowWindow(GetDlgItem(hwndDlg, IDC_SAT), SW_HIDE);
237 ShowWindow(GetDlgItem(hwndDlg, IDC_IAC), SW_HIDE);
238 ShowWindow(GetDlgItem(hwndDlg, IDC_SAC), SW_HIDE);
239 ShowWindow(GetDlgItem(hwndDlg, IDC_IDC), SW_HIDE);
240 ShowWindow(GetDlgItem(hwndDlg, IDC_SDC), SW_HIDE);
241 ShowWindow(GetDlgItem(hwndDlg, IDC_MONITORDCLIST), SW_HIDE);
242 ShowWindow(GetDlgItem(hwndDlg, IDC_DISKDCLIST), SW_HIDE);
243 ShowWindow(GetDlgItem(hwndDlg, IDC_STANDBYDCLIST), SW_HIDE);
244 ShowWindow(GetDlgItem(hwndDlg, IDC_HYBERNATEDCLIST), SW_HIDE);
245 }
246
247 if (!(spc.SystemS1 || spc.SystemS2 || spc.SystemS3))
248 {
249 ShowWindow(GetDlgItem(hwndDlg, IDC_STANDBY), SW_HIDE);
250 ShowWindow(GetDlgItem(hwndDlg, IDC_STANDBYACLIST), SW_HIDE);
251 ShowWindow(GetDlgItem(hwndDlg, IDC_STANDBYDCLIST), SW_HIDE);
252 }
253
254 if (!spc.HiberFilePresent)
255 {
256 ShowWindow(GetDlgItem(hwndDlg, IDC_HYBERNATE), SW_HIDE);
257 ShowWindow(GetDlgItem(hwndDlg, IDC_HYBERNATEACLIST), SW_HIDE);
258 ShowWindow(GetDlgItem(hwndDlg, IDC_HYBERNATEDCLIST), SW_HIDE);
259 }
260
261 return TRUE;
262 }
263
264
265 static
266 VOID
267 LoadConfig(
268 HWND hwndDlg)
269 {
270 PPOWER_SCHEME pScheme;
271 INT i = 0, iCurSel = 0;
272 TCHAR szTemp[MAX_PATH];
273 TCHAR szConfig[MAX_PATH];
274 PPOWER_POLICY pp;
275
276 iCurSel = (INT)SendDlgItemMessage(hwndDlg,
277 IDC_ENERGYLIST,
278 CB_GETCURSEL,
279 0,
280 0);
281 if (iCurSel == CB_ERR)
282 return;
283
284 pScheme = (PPOWER_SCHEME)SendDlgItemMessage(hwndDlg,
285 IDC_ENERGYLIST,
286 CB_GETITEMDATA,
287 (WPARAM)iCurSel,
288 0);
289 if (pScheme == (PPOWER_SCHEME)CB_ERR)
290 return;
291
292 if (LoadString(hApplet, IDS_CONFIG1, szTemp, MAX_PATH))
293 {
294 _stprintf(szConfig, szTemp, pScheme->pszName);
295 SetWindowText(GetDlgItem(hwndDlg, IDC_GRPDETAIL), szConfig);
296 }
297
298 pp = &pScheme->PowerPolicy;
299
300 for (i = 0; i < 16; i++)
301 {
302 if (Sec[i] == pp->user.VideoTimeoutAc)
303 {
304 SendDlgItemMessage(hwndDlg, IDC_MONITORACLIST,
305 CB_SETCURSEL,
306 i,
307 (LPARAM)0);
308 }
309
310 if (Sec[i] == pp->user.VideoTimeoutDc)
311 {
312 SendDlgItemMessage(hwndDlg, IDC_MONITORDCLIST,
313 CB_SETCURSEL,
314 i,
315 (LPARAM)0);
316 }
317
318 if (Sec[i] == pp->user.SpindownTimeoutAc)
319 {
320 SendDlgItemMessage(hwndDlg, IDC_DISKACLIST,
321 CB_SETCURSEL,
322 i - 2,
323 (LPARAM)0);
324 }
325
326 if (Sec[i] == pp->user.SpindownTimeoutDc)
327 {
328 SendDlgItemMessage(hwndDlg, IDC_DISKDCLIST,
329 CB_SETCURSEL,
330 i - 2,
331 (LPARAM)0);
332 }
333
334 if (Sec[i] == pp->user.IdleTimeoutAc)
335 {
336 SendDlgItemMessage(hwndDlg, IDC_STANDBYACLIST,
337 CB_SETCURSEL,
338 i,
339 (LPARAM)0);
340 }
341
342 if (Sec[i] == pp->user.IdleTimeoutDc)
343 {
344 SendDlgItemMessage(hwndDlg, IDC_STANDBYDCLIST,
345 CB_SETCURSEL,
346 i,
347 (LPARAM)0);
348 }
349
350 if (Sec[i] == pp->mach.DozeS4TimeoutAc)
351 {
352 SendDlgItemMessage(hwndDlg, IDC_HYBERNATEACLIST,
353 CB_SETCURSEL,
354 i,
355 (LPARAM)0);
356 }
357
358 if (Sec[i] == pp->mach.DozeS4TimeoutDc)
359 {
360 SendDlgItemMessage(hwndDlg, IDC_HYBERNATEDCLIST,
361 CB_SETCURSEL,
362 i,
363 (LPARAM)0);
364 }
365 }
366 }
367
368
369 static VOID
370 Pos_InitPage(HWND hwndDlg)
371 {
372 int ifrom = 0, i = 0, imin = 0;
373 HWND hwnd = NULL;
374 TCHAR szName[MAX_PATH];
375 LRESULT index;
376
377 for (i = 1; i < 9; i++)
378 {
379 switch (i)
380 {
381 case 1:
382 hwnd = GetDlgItem(hwndDlg, IDC_MONITORACLIST);
383 imin = IDS_TIMEOUT1;
384 break;
385
386 case 2:
387 hwnd = GetDlgItem(hwndDlg, IDC_STANDBYACLIST);
388 imin = IDS_TIMEOUT1;
389 break;
390
391 case 3:
392 hwnd = GetDlgItem(hwndDlg, IDC_DISKACLIST);
393 imin = IDS_TIMEOUT3;
394 break;
395
396 case 4:
397 hwnd = GetDlgItem(hwndDlg, IDC_HYBERNATEACLIST);
398 imin = IDS_TIMEOUT3;
399 break;
400
401 case 5:
402 hwnd = GetDlgItem(hwndDlg, IDC_MONITORDCLIST);
403 imin = IDS_TIMEOUT1;
404 break;
405
406 case 6:
407 hwnd = GetDlgItem(hwndDlg, IDC_STANDBYDCLIST);
408 imin = IDS_TIMEOUT1;
409 break;
410
411 case 7:
412 hwnd = GetDlgItem(hwndDlg, IDC_DISKDCLIST);
413 imin = IDS_TIMEOUT3;
414 break;
415
416 case 8:
417 hwnd = GetDlgItem(hwndDlg, IDC_HYBERNATEDCLIST);
418 imin = IDS_TIMEOUT3;
419 break;
420
421 default:
422 return;
423 }
424
425 for (ifrom = imin; ifrom < (IDS_TIMEOUT15 + 1); ifrom++)
426 {
427 if (LoadString(hApplet, ifrom, szName, MAX_PATH))
428 {
429 index = SendMessage(hwnd,
430 CB_ADDSTRING,
431 0,
432 (LPARAM)szName);
433 if (index == CB_ERR)
434 return;
435
436 SendMessage(hwnd,
437 CB_SETITEMDATA,
438 index,
439 (LPARAM)Sec[ifrom - IDS_TIMEOUT16]);
440 }
441 }
442
443 if (LoadString(hApplet, IDS_TIMEOUT16, szName, MAX_PATH))
444 {
445 index = SendMessage(hwnd,
446 CB_ADDSTRING,
447 0,
448 (LPARAM)szName);
449 if (index == CB_ERR)
450 return;
451
452 SendMessage(hwnd,
453 CB_SETITEMDATA,
454 index,
455 (LPARAM)Sec[0]);
456 }
457 }
458 }
459
460
461 static VOID
462 Pos_SaveData(HWND hwndDlg)
463 {
464 PPOWER_SCHEME pScheme;
465 INT iCurSel, tmp;
466
467 iCurSel = (INT)SendDlgItemMessage(hwndDlg,
468 IDC_ENERGYLIST,
469 CB_GETCURSEL,
470 0,
471 0);
472 if (iCurSel == CB_ERR)
473 return;
474
475 pScheme = (PPOWER_SCHEME)SendDlgItemMessage(hwndDlg,
476 IDC_ENERGYLIST,
477 CB_GETITEMDATA,
478 (WPARAM)iCurSel,
479 0);
480 if (pScheme == (PPOWER_SCHEME)CB_ERR)
481 return;
482
483 tmp = (INT)SendDlgItemMessage(hwndDlg, IDC_MONITORACLIST,
484 CB_GETCURSEL,
485 0,
486 (LPARAM)0);
487 if (tmp > 0 && tmp < 16)
488 {
489 pScheme->PowerPolicy.user.VideoTimeoutAc = Sec[tmp];
490 }
491
492 tmp = (INT)SendDlgItemMessage(hwndDlg, IDC_MONITORDCLIST,
493 CB_GETCURSEL,
494 0,
495 (LPARAM)0);
496 if (tmp > 0 && tmp < 16)
497 {
498 pScheme->PowerPolicy.user.VideoTimeoutDc = Sec[tmp];
499 }
500
501 tmp = (INT)SendDlgItemMessage(hwndDlg, IDC_DISKACLIST,
502 CB_GETCURSEL,
503 0,
504 (LPARAM)0);
505 if (tmp > 0 && tmp < 16)
506 {
507 pScheme->PowerPolicy.user.SpindownTimeoutAc = Sec[tmp + 2];
508 }
509
510 tmp = (INT)SendDlgItemMessage(hwndDlg, IDC_DISKDCLIST,
511 CB_GETCURSEL,
512 0,
513 (LPARAM)0);
514 if (tmp > 0 && tmp < 16)
515 {
516 pScheme->PowerPolicy.user.SpindownTimeoutDc = Sec[tmp + 2];
517 }
518
519 tmp = (INT)SendDlgItemMessage(hwndDlg, IDC_STANDBYACLIST,
520 CB_GETCURSEL,
521 0,
522 (LPARAM)0);
523 if (tmp > 0 && tmp < 16)
524 {
525 pScheme->PowerPolicy.user.IdleTimeoutAc = Sec[tmp];
526 }
527
528 tmp = (INT)SendDlgItemMessage(hwndDlg, IDC_STANDBYDCLIST,
529 CB_GETCURSEL,
530 0,
531 (LPARAM)0);
532 if (tmp > 0 && tmp < 16)
533 {
534 pScheme->PowerPolicy.user.IdleTimeoutDc = Sec[tmp];
535 }
536
537 tmp = (INT)SendDlgItemMessage(hwndDlg, IDC_HYBERNATEACLIST,
538 CB_GETCURSEL,
539 0,
540 (LPARAM)0);
541 if (tmp > 0 && tmp < 16)
542 {
543 pScheme->PowerPolicy.mach.DozeS4TimeoutAc = Sec[tmp];
544 }
545
546 tmp = (INT)SendDlgItemMessage(hwndDlg, IDC_HYBERNATEDCLIST,
547 CB_GETCURSEL,
548 0,
549 (LPARAM)0);
550 if (tmp > 0 && tmp < 16)
551 {
552 pScheme->PowerPolicy.mach.DozeS4TimeoutDc = Sec[tmp];
553 }
554
555 SetActivePwrScheme(iCurSel, NULL, &pScheme->PowerPolicy);
556 LoadConfig(hwndDlg);
557 }
558
559
560 static BOOL
561 DelScheme(HWND hwnd)
562 {
563 INT iCurSel;
564 HWND hList;
565 TCHAR szBuf[1024], szBufT[1024];
566 PPOWER_SCHEME pScheme;
567
568 hList = GetDlgItem(hwnd, IDC_ENERGYLIST);
569
570 iCurSel = SendMessage(hList, CB_GETCURSEL, 0, 0);
571 if (iCurSel == CB_ERR)
572 return FALSE;
573
574 SendMessage(hList, CB_SETCURSEL, iCurSel, 0);
575
576 pScheme = (PPOWER_SCHEME)SendMessage(hList, CB_GETITEMDATA, (WPARAM)iCurSel, 0);
577 if (pScheme == (PPOWER_SCHEME)CB_ERR)
578 return FALSE;
579
580 LoadString(hApplet, IDS_DEL_SCHEME_TITLE, szBufT, sizeof(szBufT) / sizeof(TCHAR));
581 LoadString(hApplet, IDS_DEL_SCHEME, szBuf, sizeof(szBuf) / sizeof(TCHAR));
582
583 if (MessageBox(hwnd, szBuf, szBufT, MB_YESNO | MB_ICONQUESTION) == IDYES)
584 {
585 UINT Current;
586
587 if (GetActivePwrScheme(&Current))
588 {
589 SendMessage(hList, CB_SETCURSEL, (WPARAM)0, 0);
590 SendMessage(hList, CB_DELETESTRING, (WPARAM)iCurSel, 0);
591 if (Current == pScheme->uId)
592 Pos_SaveData(hwnd);
593 }
594
595 if (DeletePwrScheme(pScheme->uId) != 0)
596 return TRUE;
597 }
598
599 return FALSE;
600 }
601
602
603 static BOOL
604 CreateEnergyList(
605 HWND hwndDlg,
606 PPOWER_SCHEMES_PAGE_DATA pPageData)
607 {
608 PLIST_ENTRY ListEntry;
609 PPOWER_SCHEME pScheme;
610 INT index;
611 POWER_POLICY pp;
612 SYSTEM_POWER_CAPABILITIES spc;
613 HWND hwndList;
614 unsigned aps = 0;
615
616 hwndList = GetDlgItem(hwndDlg, IDC_ENERGYLIST);
617
618 if (!GetActivePwrScheme(&aps))
619 return FALSE;
620
621 if (!ReadGlobalPwrPolicy(&gGPP))
622 return FALSE;
623
624 if (!ReadPwrScheme(aps, &pp))
625 return FALSE;
626
627 if (!ValidatePowerPolicies(&gGPP, 0))
628 return FALSE;
629
630 /*
631 if (!SetActivePwrScheme(aps, &gGPP, &pp))
632 return FALSE;
633 */
634
635 if (!GetPwrCapabilities(&spc))
636 return FALSE;
637
638 if (CanUserWritePwrScheme())
639 {
640 // TODO:
641 // Enable write / delete powerscheme button
642 }
643
644 Pos_InitPage(hwndDlg);
645
646 if (!GetActivePwrScheme(&aps))
647 return FALSE;
648
649 ListEntry = pPageData->PowerSchemesList.Flink;
650 while (ListEntry != &pPageData->PowerSchemesList)
651 {
652 pScheme = CONTAINING_RECORD(ListEntry, POWER_SCHEME, ListEntry);
653
654 index = (int)SendMessage(hwndList,
655 CB_ADDSTRING,
656 0,
657 (LPARAM)pScheme->pszName);
658 if (index == CB_ERR)
659 break;
660
661 SendMessage(hwndList,
662 CB_SETITEMDATA,
663 index,
664 (LPARAM)pScheme);
665
666 if (aps == pScheme->uId)
667 {
668 SendMessage(hwndList,
669 CB_SELECTSTRING,
670 TRUE,
671 (LPARAM)pScheme->pszName);
672
673 LoadConfig(hwndDlg);
674 }
675
676 ListEntry = ListEntry->Flink;
677 }
678
679 if (SendMessage(hwndList, CB_GETCOUNT, 0, 0) > 0)
680 {
681 EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_BTN), TRUE);
682 EnableWindow(GetDlgItem(hwndDlg, IDC_SAVEAS_BTN), TRUE);
683 }
684
685 return TRUE;
686 }
687
688
689 /* Property page dialog callback */
690 INT_PTR CALLBACK
691 PowerSchemesDlgProc(
692 HWND hwndDlg,
693 UINT uMsg,
694 WPARAM wParam,
695 LPARAM lParam)
696 {
697 PPOWER_SCHEMES_PAGE_DATA pPageData;
698
699 pPageData = (PPOWER_SCHEMES_PAGE_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
700
701 switch (uMsg)
702 {
703 case WM_INITDIALOG:
704 pPageData = (PPOWER_SCHEMES_PAGE_DATA)HeapAlloc(GetProcessHeap(),
705 0,
706 sizeof(PPOWER_SCHEMES_PAGE_DATA));
707 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pPageData);
708
709 BuildSchemesList(pPageData);
710
711 if (!Pos_InitData(hwndDlg))
712 {
713 // TODO:
714 // Initialization failed
715 // Handle error
716 MessageBox(hwndDlg,_T("Pos_InitData failed\n"), NULL, MB_OK);
717 }
718
719 if (!CreateEnergyList(hwndDlg, pPageData))
720 {
721 // TODO:
722 // Initialization failed
723 // Handle error
724 MessageBox(hwndDlg,_T("CreateEnergyList failed\n"), NULL, MB_OK);
725 }
726 return TRUE;
727
728 case WM_DESTROY:
729 if (pPageData)
730 {
731 DestroySchemesList(pPageData);
732 HeapFree(GetProcessHeap(), 0, pPageData);
733 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)NULL);
734 }
735 break;
736
737 case WM_COMMAND:
738 switch(LOWORD(wParam))
739 {
740 case IDC_ENERGYLIST:
741 if (HIWORD(wParam) == CBN_SELCHANGE)
742 {
743 LoadConfig(hwndDlg);
744 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
745 }
746 break;
747
748 case IDC_DELETE_BTN:
749 DelScheme(hwndDlg);
750 break;
751
752 case IDC_SAVEAS_BTN:
753 break;
754
755 case IDC_MONITORACLIST:
756 case IDC_MONITORDCLIST:
757 case IDC_DISKACLIST:
758 case IDC_DISKDCLIST:
759 case IDC_STANDBYACLIST:
760 case IDC_STANDBYDCLIST:
761 case IDC_HYBERNATEACLIST:
762 case IDC_HYBERNATEDCLIST:
763 if (HIWORD(wParam) == CBN_SELCHANGE)
764 {
765 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
766 }
767 break;
768 }
769 break;
770
771 case WM_NOTIFY:
772 {
773 LPNMHDR lpnm = (LPNMHDR)lParam;
774 if (lpnm->code == (UINT)PSN_APPLY)
775 {
776 Pos_SaveData(hwndDlg);
777 }
778 return TRUE;
779 }
780 break;
781 }
782
783 return FALSE;
784 }