64a90bb540b0f817f77d5764a808929eb79af31b
[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), FALSE);
237 ShowWindow(GetDlgItem(hwndDlg, IDC_IAC), FALSE);
238 ShowWindow(GetDlgItem(hwndDlg, IDC_SAC), FALSE);
239 ShowWindow(GetDlgItem(hwndDlg, IDC_IDC), FALSE);
240 ShowWindow(GetDlgItem(hwndDlg, IDC_SDC), FALSE);
241 ShowWindow(GetDlgItem(hwndDlg, IDC_MONITORDCLIST), FALSE);
242 ShowWindow(GetDlgItem(hwndDlg, IDC_DISKDCLIST), FALSE);
243 ShowWindow(GetDlgItem(hwndDlg, IDC_STANDBYDCLIST), FALSE);
244 ShowWindow(GetDlgItem(hwndDlg, IDC_HYBERNATEDCLIST), FALSE);
245 ShowWindow(GetDlgItem(hwndDlg, IDC_HYBERNATEACLIST), spc.HiberFilePresent);
246
247 }
248 else
249 {
250 ShowWindow(GetDlgItem(hwndDlg, IDC_HYBERNATEDCLIST), spc.HiberFilePresent);
251 ShowWindow(GetDlgItem(hwndDlg, IDC_HYBERNATEACLIST), FALSE);
252 }
253
254
255 if (!(spc.SystemS1 ||spc.SystemS2 || spc.SystemS3))
256 {
257 ShowWindow(GetDlgItem(hwndDlg, IDC_STANDBYACLIST), TRUE);
258 ShowWindow(GetDlgItem(hwndDlg, IDC_STANDBYDCLIST), TRUE);
259 ShowWindow(GetDlgItem(hwndDlg, IDC_STANDBY), TRUE);
260 }
261
262 ShowWindow(GetDlgItem(hwndDlg, IDC_HYBERNATE), spc.HiberFilePresent);
263
264 return TRUE;
265 }
266
267
268 static
269 VOID
270 LoadConfig(
271 HWND hwndDlg)
272 {
273 PPOWER_SCHEME pScheme;
274 INT i = 0, iCurSel = 0;
275 TCHAR szTemp[MAX_PATH];
276 TCHAR szConfig[MAX_PATH];
277 PPOWER_POLICY pp;
278
279 iCurSel = (INT)SendDlgItemMessage(hwndDlg,
280 IDC_ENERGYLIST,
281 CB_GETCURSEL,
282 0,
283 0);
284 if (iCurSel == CB_ERR)
285 return;
286
287 pScheme = (PPOWER_SCHEME)SendDlgItemMessage(hwndDlg,
288 IDC_ENERGYLIST,
289 CB_GETITEMDATA,
290 (WPARAM)iCurSel,
291 0);
292 if (pScheme == (PPOWER_SCHEME)CB_ERR)
293 return;
294
295 if (LoadString(hApplet, IDS_CONFIG1, szTemp, MAX_PATH))
296 {
297 _stprintf(szConfig, szTemp, pScheme->pszName);
298 SetWindowText(GetDlgItem(hwndDlg, IDC_GRPDETAIL), szConfig);
299 }
300
301 pp = &pScheme->PowerPolicy;
302
303 for (i = 0; i < 16; i++)
304 {
305 if (Sec[i] == pp->user.VideoTimeoutAc)
306 {
307 SendDlgItemMessage(hwndDlg, IDC_MONITORACLIST,
308 CB_SETCURSEL,
309 i,
310 (LPARAM)0);
311 }
312
313 if (Sec[i] == pp->user.VideoTimeoutDc)
314 {
315 SendDlgItemMessage(hwndDlg, IDC_MONITORDCLIST,
316 CB_SETCURSEL,
317 i,
318 (LPARAM)0);
319 }
320
321 if (Sec[i] == pp->user.SpindownTimeoutAc)
322 {
323 SendDlgItemMessage(hwndDlg, IDC_DISKACLIST,
324 CB_SETCURSEL,
325 i - 2,
326 (LPARAM)0);
327 }
328
329 if (Sec[i] == pp->user.SpindownTimeoutDc)
330 {
331 SendDlgItemMessage(hwndDlg, IDC_DISKDCLIST,
332 CB_SETCURSEL,
333 i - 2,
334 (LPARAM)0);
335 }
336
337 if (Sec[i] == pp->user.IdleTimeoutAc)
338 {
339 SendDlgItemMessage(hwndDlg, IDC_STANDBYACLIST,
340 CB_SETCURSEL,
341 i,
342 (LPARAM)0);
343 }
344
345 if (Sec[i] == pp->user.IdleTimeoutDc)
346 {
347 SendDlgItemMessage(hwndDlg, IDC_STANDBYDCLIST,
348 CB_SETCURSEL,
349 i,
350 (LPARAM)0);
351 }
352
353 if (Sec[i] == pp->mach.DozeS4TimeoutAc)
354 {
355 SendDlgItemMessage(hwndDlg, IDC_HYBERNATEACLIST,
356 CB_SETCURSEL,
357 i,
358 (LPARAM)0);
359 }
360
361 if (Sec[i] == pp->mach.DozeS4TimeoutDc)
362 {
363 SendDlgItemMessage(hwndDlg, IDC_HYBERNATEDCLIST,
364 CB_SETCURSEL,
365 i,
366 (LPARAM)0);
367 }
368 }
369 }
370
371
372 static VOID
373 Pos_InitPage(HWND hwndDlg)
374 {
375 int ifrom = 0, i = 0, imin = 0;
376 HWND hwnd = NULL;
377 TCHAR szName[MAX_PATH];
378 LRESULT index;
379
380 for (i = 1; i < 9; i++)
381 {
382 switch (i)
383 {
384 case 1:
385 hwnd = GetDlgItem(hwndDlg, IDC_MONITORACLIST);
386 imin = IDS_TIMEOUT1;
387 break;
388
389 case 2:
390 hwnd = GetDlgItem(hwndDlg, IDC_STANDBYACLIST);
391 imin = IDS_TIMEOUT1;
392 break;
393
394 case 3:
395 hwnd = GetDlgItem(hwndDlg, IDC_DISKACLIST);
396 imin = IDS_TIMEOUT3;
397 break;
398
399 case 4:
400 hwnd = GetDlgItem(hwndDlg, IDC_HYBERNATEACLIST);
401 imin = IDS_TIMEOUT3;
402 break;
403
404 case 5:
405 hwnd = GetDlgItem(hwndDlg, IDC_MONITORDCLIST);
406 imin = IDS_TIMEOUT1;
407 break;
408
409 case 6:
410 hwnd = GetDlgItem(hwndDlg, IDC_STANDBYDCLIST);
411 imin = IDS_TIMEOUT1;
412 break;
413
414 case 7:
415 hwnd = GetDlgItem(hwndDlg, IDC_DISKDCLIST);
416 imin = IDS_TIMEOUT3;
417 break;
418
419 case 8:
420 hwnd = GetDlgItem(hwndDlg, IDC_HYBERNATEDCLIST);
421 imin = IDS_TIMEOUT3;
422 break;
423
424 default:
425 return;
426 }
427
428 for (ifrom = imin; ifrom < (IDS_TIMEOUT15 + 1); ifrom++)
429 {
430 if (LoadString(hApplet, ifrom, szName, MAX_PATH))
431 {
432 index = SendMessage(hwnd,
433 CB_ADDSTRING,
434 0,
435 (LPARAM)szName);
436 if (index == CB_ERR)
437 return;
438
439 SendMessage(hwnd,
440 CB_SETITEMDATA,
441 index,
442 (LPARAM)Sec[ifrom - IDS_TIMEOUT16]);
443 }
444 }
445
446 if (LoadString(hApplet, IDS_TIMEOUT16, szName, MAX_PATH))
447 {
448 index = SendMessage(hwnd,
449 CB_ADDSTRING,
450 0,
451 (LPARAM)szName);
452 if (index == CB_ERR)
453 return;
454
455 SendMessage(hwnd,
456 CB_SETITEMDATA,
457 index,
458 (LPARAM)Sec[0]);
459 }
460 }
461 }
462
463
464 static VOID
465 Pos_SaveData(HWND hwndDlg)
466 {
467 PPOWER_SCHEME pScheme;
468 INT iCurSel, tmp;
469
470 iCurSel = (INT)SendDlgItemMessage(hwndDlg,
471 IDC_ENERGYLIST,
472 CB_GETCURSEL,
473 0,
474 0);
475 if (iCurSel == CB_ERR)
476 return;
477
478 pScheme = (PPOWER_SCHEME)SendDlgItemMessage(hwndDlg,
479 IDC_ENERGYLIST,
480 CB_GETITEMDATA,
481 (WPARAM)iCurSel,
482 0);
483 if (pScheme == (PPOWER_SCHEME)CB_ERR)
484 return;
485
486 tmp = (INT)SendDlgItemMessage(hwndDlg, IDC_MONITORACLIST,
487 CB_GETCURSEL,
488 0,
489 (LPARAM)0);
490 if (tmp > 0 && tmp < 16)
491 {
492 pScheme->PowerPolicy.user.VideoTimeoutAc = Sec[tmp];
493 }
494
495 tmp = (INT)SendDlgItemMessage(hwndDlg, IDC_MONITORDCLIST,
496 CB_GETCURSEL,
497 0,
498 (LPARAM)0);
499 if (tmp > 0 && tmp < 16)
500 {
501 pScheme->PowerPolicy.user.VideoTimeoutDc = Sec[tmp];
502 }
503
504 tmp = (INT)SendDlgItemMessage(hwndDlg, IDC_DISKACLIST,
505 CB_GETCURSEL,
506 0,
507 (LPARAM)0);
508 if (tmp > 0 && tmp < 16)
509 {
510 pScheme->PowerPolicy.user.SpindownTimeoutAc = Sec[tmp + 2];
511 }
512
513 tmp = (INT)SendDlgItemMessage(hwndDlg, IDC_DISKDCLIST,
514 CB_GETCURSEL,
515 0,
516 (LPARAM)0);
517 if (tmp > 0 && tmp < 16)
518 {
519 pScheme->PowerPolicy.user.SpindownTimeoutDc = Sec[tmp + 2];
520 }
521
522 tmp = (INT)SendDlgItemMessage(hwndDlg, IDC_STANDBYACLIST,
523 CB_GETCURSEL,
524 0,
525 (LPARAM)0);
526 if (tmp > 0 && tmp < 16)
527 {
528 pScheme->PowerPolicy.user.IdleTimeoutAc = Sec[tmp];
529 }
530
531 tmp = (INT)SendDlgItemMessage(hwndDlg, IDC_STANDBYDCLIST,
532 CB_GETCURSEL,
533 0,
534 (LPARAM)0);
535 if (tmp > 0 && tmp < 16)
536 {
537 pScheme->PowerPolicy.user.IdleTimeoutDc = Sec[tmp];
538 }
539
540 tmp = (INT)SendDlgItemMessage(hwndDlg, IDC_HYBERNATEACLIST,
541 CB_GETCURSEL,
542 0,
543 (LPARAM)0);
544 if (tmp > 0 && tmp < 16)
545 {
546 pScheme->PowerPolicy.mach.DozeS4TimeoutAc = Sec[tmp];
547 }
548
549 tmp = (INT)SendDlgItemMessage(hwndDlg, IDC_HYBERNATEDCLIST,
550 CB_GETCURSEL,
551 0,
552 (LPARAM)0);
553 if (tmp > 0 && tmp < 16)
554 {
555 pScheme->PowerPolicy.mach.DozeS4TimeoutDc = Sec[tmp];
556 }
557
558 SetActivePwrScheme(iCurSel, NULL, &pScheme->PowerPolicy);
559 LoadConfig(hwndDlg);
560 }
561
562
563 static BOOL
564 DelScheme(HWND hwnd)
565 {
566 INT iCurSel;
567 HWND hList;
568 TCHAR szBuf[1024], szBufT[1024];
569 PPOWER_SCHEME pScheme;
570
571 hList = GetDlgItem(hwnd, IDC_ENERGYLIST);
572
573 iCurSel = SendMessage(hList, CB_GETCURSEL, 0, 0);
574 if (iCurSel == CB_ERR)
575 return FALSE;
576
577 SendMessage(hList, CB_SETCURSEL, iCurSel, 0);
578
579 pScheme = (PPOWER_SCHEME)SendMessage(hList, CB_GETITEMDATA, (WPARAM)iCurSel, 0);
580 if (pScheme == (PPOWER_SCHEME)CB_ERR)
581 return FALSE;
582
583 LoadString(hApplet, IDS_DEL_SCHEME_TITLE, szBufT, sizeof(szBufT) / sizeof(TCHAR));
584 LoadString(hApplet, IDS_DEL_SCHEME, szBuf, sizeof(szBuf) / sizeof(TCHAR));
585
586 if (MessageBox(hwnd, szBuf, szBufT, MB_YESNO | MB_ICONQUESTION) == IDYES)
587 {
588 UINT Current;
589
590 if (GetActivePwrScheme(&Current))
591 {
592 SendMessage(hList, CB_SETCURSEL, (WPARAM)0, 0);
593 SendMessage(hList, CB_DELETESTRING, (WPARAM)iCurSel, 0);
594 if (Current == pScheme->uId)
595 Pos_SaveData(hwnd);
596 }
597
598 if (DeletePwrScheme(pScheme->uId) != 0)
599 return TRUE;
600 }
601
602 return FALSE;
603 }
604
605
606 static BOOL
607 CreateEnergyList(
608 HWND hwndDlg,
609 PPOWER_SCHEMES_PAGE_DATA pPageData)
610 {
611 PLIST_ENTRY ListEntry;
612 PPOWER_SCHEME pScheme;
613 INT index;
614 POWER_POLICY pp;
615 SYSTEM_POWER_CAPABILITIES spc;
616 HWND hwndList;
617 unsigned aps = 0;
618
619 hwndList = GetDlgItem(hwndDlg, IDC_ENERGYLIST);
620
621 if (!GetActivePwrScheme(&aps))
622 return FALSE;
623
624 if (!ReadGlobalPwrPolicy(&gGPP))
625 return FALSE;
626
627 if (!ReadPwrScheme(aps, &pp))
628 return FALSE;
629
630 if (!ValidatePowerPolicies(&gGPP, 0))
631 return FALSE;
632
633 /*
634 if (!SetActivePwrScheme(aps, &gGPP, &pp))
635 return FALSE;
636 */
637
638 if (!GetPwrCapabilities(&spc))
639 return FALSE;
640
641 if (CanUserWritePwrScheme())
642 {
643 // TODO:
644 // Enable write / delete powerscheme button
645 }
646
647 Pos_InitPage(hwndDlg);
648
649 if (!GetActivePwrScheme(&aps))
650 return FALSE;
651
652 ListEntry = pPageData->PowerSchemesList.Flink;
653 while (ListEntry != &pPageData->PowerSchemesList)
654 {
655 pScheme = CONTAINING_RECORD(ListEntry, POWER_SCHEME, ListEntry);
656
657 index = (int)SendMessage(hwndList,
658 CB_ADDSTRING,
659 0,
660 (LPARAM)pScheme->pszName);
661 if (index == CB_ERR)
662 break;
663
664 SendMessage(hwndList,
665 CB_SETITEMDATA,
666 index,
667 (LPARAM)pScheme);
668
669 if (aps == pScheme->uId)
670 {
671 SendMessage(hwndList,
672 CB_SELECTSTRING,
673 TRUE,
674 (LPARAM)pScheme->pszName);
675
676 LoadConfig(hwndDlg);
677 }
678
679 ListEntry = ListEntry->Flink;
680 }
681
682 if (SendMessage(hwndList, CB_GETCOUNT, 0, 0) > 0)
683 {
684 EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_BTN), TRUE);
685 EnableWindow(GetDlgItem(hwndDlg, IDC_SAVEAS_BTN), TRUE);
686 }
687
688 return TRUE;
689 }
690
691
692 /* Property page dialog callback */
693 INT_PTR CALLBACK
694 PowerSchemesDlgProc(
695 HWND hwndDlg,
696 UINT uMsg,
697 WPARAM wParam,
698 LPARAM lParam)
699 {
700 PPOWER_SCHEMES_PAGE_DATA pPageData;
701
702 pPageData = (PPOWER_SCHEMES_PAGE_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
703
704 switch (uMsg)
705 {
706 case WM_INITDIALOG:
707 pPageData = (PPOWER_SCHEMES_PAGE_DATA)HeapAlloc(GetProcessHeap(),
708 0,
709 sizeof(PPOWER_SCHEMES_PAGE_DATA));
710 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pPageData);
711
712 BuildSchemesList(pPageData);
713
714 if (!Pos_InitData(hwndDlg))
715 {
716 // TODO:
717 // Initialization failed
718 // Handle error
719 MessageBox(hwndDlg,_T("Pos_InitData failed\n"), NULL, MB_OK);
720 }
721
722 if (!CreateEnergyList(hwndDlg, pPageData))
723 {
724 // TODO:
725 // Initialization failed
726 // Handle error
727 MessageBox(hwndDlg,_T("CreateEnergyList failed\n"), NULL, MB_OK);
728 }
729 return TRUE;
730
731 case WM_DESTROY:
732 if (pPageData)
733 {
734 DestroySchemesList(pPageData);
735 HeapFree(GetProcessHeap(), 0, pPageData);
736 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)NULL);
737 }
738 break;
739
740 case WM_COMMAND:
741 switch(LOWORD(wParam))
742 {
743 case IDC_ENERGYLIST:
744 if (HIWORD(wParam) == CBN_SELCHANGE)
745 {
746 LoadConfig(hwndDlg);
747 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
748 }
749 break;
750
751 case IDC_DELETE_BTN:
752 DelScheme(hwndDlg);
753 break;
754
755 case IDC_SAVEAS_BTN:
756 break;
757
758 case IDC_MONITORACLIST:
759 case IDC_MONITORDCLIST:
760 case IDC_DISKACLIST:
761 case IDC_DISKDCLIST:
762 case IDC_STANDBYACLIST:
763 case IDC_STANDBYDCLIST:
764 case IDC_HYBERNATEACLIST:
765 case IDC_HYBERNATEDCLIST:
766 if (HIWORD(wParam) == CBN_SELCHANGE)
767 {
768 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
769 }
770 break;
771 }
772 break;
773
774 case WM_NOTIFY:
775 {
776 LPNMHDR lpnm = (LPNMHDR)lParam;
777 if (lpnm->code == (UINT)PSN_APPLY)
778 {
779 Pos_SaveData(hwndDlg);
780 }
781 return TRUE;
782 }
783 break;
784 }
785
786 return FALSE;
787 }