Delete all Trailing spaces in code.
[reactos.git] / reactos / dll / cpl / powercfg / powercfg.c
1 /* $Id$
2 *
3 * PROJECT: ReactOS Power Configuration Applet
4 * LICENSE: GPL - See COPYING in the top level directory
5 * FILE: dll/cpl/powercfg/powershemes.c
6 * PURPOSE: initialization of applet
7 * PROGRAMMERS: Alexander Wurzinger (Lohnegrim at gmx dot net)
8 * Johannes Anderwald (johannes.anderwald@student.tugraz.at)
9 * Martin Rottensteiner
10 */
11
12 #include <windows.h>
13 #include <commctrl.h>
14 #include <shlobj.h>
15 #include <regstr.h>
16 #include <cpl.h>
17
18 #include "resource.h"
19 #include "powercfg.h"
20
21 #define NUM_APPLETS (1)
22
23 static LONG APIENTRY Applet1(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam);
24 INT_PTR CALLBACK powershemesProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
25 INT_PTR CALLBACK alarmsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
26 INT_PTR CALLBACK advancedProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
27 INT_PTR CALLBACK hibernateProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
28
29 HINSTANCE hApplet = 0;
30 GLOBAL_POWER_POLICY gGPP;
31 TCHAR langSel[255];
32
33 /* Applets */
34 APPLET Applets[NUM_APPLETS] =
35 {
36 {IDC_CPLICON_1, IDS_CPLNAME_1, IDS_CPLDESCRIPTION_1, Applet1}
37 };
38
39 static BOOL CALLBACK
40 PropSheetAddPage(HPROPSHEETPAGE hpage, LPARAM lParam)
41 {
42 PROPSHEETHEADER *ppsh = (PROPSHEETHEADER *)lParam;
43 if (ppsh != NULL && ppsh->nPages < MAX_POWER_PAGES)
44 {
45 ppsh->phpage[ppsh->nPages++] = hpage;
46 return TRUE;
47 }
48
49 return FALSE;
50 }
51
52 static BOOL
53 InitPropSheetPage(PROPSHEETHEADER *ppsh, WORD idDlg, DLGPROC DlgProc)
54 {
55 HPROPSHEETPAGE hPage;
56 PROPSHEETPAGE psp;
57
58 if (ppsh->nPages < MAX_POWER_PAGES)
59 {
60 ZeroMemory(&psp, sizeof(psp));
61 psp.dwSize = sizeof(psp);
62 psp.dwFlags = PSP_DEFAULT;
63 psp.hInstance = hApplet;
64 psp.pszTemplate = MAKEINTRESOURCE(idDlg);
65 psp.pfnDlgProc = DlgProc;
66
67 hPage = CreatePropertySheetPage(&psp);
68 if (hPage != NULL)
69 {
70 return PropSheetAddPage(hPage, (LPARAM)ppsh);
71 }
72 }
73
74 return FALSE;
75 }
76
77
78 /* Property Sheet Callback */
79 int CALLBACK
80 PropSheetProc(
81 HWND hwndDlg,
82 UINT uMsg,
83 LPARAM lParam
84 )
85 {
86 UNREFERENCED_PARAMETER(hwndDlg);
87 switch(uMsg)
88 {
89 case PSCB_BUTTONPRESSED:
90 switch(lParam)
91 {
92 case PSBTN_OK: /* OK */
93 break;
94 case PSBTN_CANCEL: /* Cancel */
95 break;
96 case PSBTN_APPLYNOW: /* Apply now */
97 break;
98 case PSBTN_FINISH: /* Close */
99 break;
100 default:
101 return FALSE;
102 }
103 break;
104
105 case PSCB_INITIALIZED:
106 break;
107 }
108 return TRUE;
109 }
110
111 /* First Applet */
112 static LONG APIENTRY
113 Applet1(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
114 {
115 HPROPSHEETPAGE hpsp[MAX_POWER_PAGES];
116 PROPSHEETHEADER psh;
117 HPSXA hpsxa = NULL;
118 TCHAR Caption[1024];
119 SYSTEM_POWER_CAPABILITIES spc;
120 LONG ret;
121
122 UNREFERENCED_PARAMETER(hwnd);
123 UNREFERENCED_PARAMETER(uMsg);
124 UNREFERENCED_PARAMETER(wParam);
125 UNREFERENCED_PARAMETER(lParam);
126
127 memset(Caption, 0x0, sizeof(Caption));
128 LoadString(hApplet, IDS_CPLNAME_1, Caption, sizeof(Caption) / sizeof(TCHAR));
129
130 ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
131 psh.dwSize = sizeof(PROPSHEETHEADER);
132 psh.dwFlags = PSH_USECALLBACK | PSH_PROPTITLE;
133 psh.hwndParent = NULL;
134 psh.hInstance = hApplet;
135 psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDC_CPLICON_1));
136 psh.pszCaption = Caption;
137 psh.nPages = 0;
138 psh.nStartPage = 0;
139 psh.phpage = hpsp;
140 psh.pfnCallback = PropSheetProc;
141
142 InitPropSheetPage(&psh, IDD_PROPPAGEPOWERSHEMES, (DLGPROC) powershemesProc);
143 if (GetPwrCapabilities(&spc))
144 {
145 if (spc.SystemBatteriesPresent)
146 {
147 InitPropSheetPage(&psh, IDD_PROPPAGEALARMS, (DLGPROC) alarmsProc);
148 }
149 }
150 InitPropSheetPage(&psh, IDD_PROPPAGEADVANCED, (DLGPROC) advancedProc);
151 InitPropSheetPage(&psh, IDD_PROPPAGEHIBERNATE, (DLGPROC) hibernateProc);
152
153 /* Load additional pages provided by shell extensions */
154 hpsxa = SHCreatePropSheetExtArray(HKEY_LOCAL_MACHINE, REGSTR_PATH_CONTROLSFOLDER TEXT("\\Power"), MAX_POWER_PAGES - psh.nPages);
155 if (hpsxa != NULL)
156 SHAddFromPropSheetExtArray(hpsxa, PropSheetAddPage, (LPARAM)&psh);
157
158 ret = (LONG)(PropertySheet(&psh) != -1);
159
160 if (hpsxa != NULL)
161 SHDestroyPropSheetExtArray(hpsxa);
162
163 return ret;
164 }
165
166 /* Control Panel Callback */
167 LONG CALLBACK
168 CPlApplet(
169 HWND hwndCPl,
170 UINT uMsg,
171 LPARAM lParam1,
172 LPARAM lParam2)
173 {
174 int i = (int)lParam1;
175
176 switch(uMsg)
177 {
178 case CPL_INIT:
179 {
180 return TRUE;
181 }
182 case CPL_GETCOUNT:
183 {
184 return NUM_APPLETS;
185 }
186 case CPL_INQUIRE:
187 {
188 CPLINFO *CPlInfo = (CPLINFO*)lParam2;
189 CPlInfo->lData = 0;
190 CPlInfo->idIcon = Applets[i].idIcon;
191 CPlInfo->idName = Applets[i].idName;
192 CPlInfo->idInfo = Applets[i].idDescription;
193 break;
194 }
195 case CPL_DBLCLK:
196 {
197 Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
198 break;
199 }
200 }
201 return FALSE;
202 }
203
204
205 BOOLEAN
206 WINAPI
207 DllMain(
208 HINSTANCE hinstDLL,
209 DWORD dwReason,
210 LPVOID lpvReserved)
211 {
212 UNREFERENCED_PARAMETER(lpvReserved);
213 switch(dwReason)
214 {
215 case DLL_PROCESS_ATTACH:
216 case DLL_THREAD_ATTACH:
217 hApplet = hinstDLL;
218 break;
219 }
220 return TRUE;
221 }
222