- Make local functions static.
[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 * Dmitry Chapyshev (lentind@yandex.ru)
11 */
12
13 #include <windows.h>
14 #include <commctrl.h>
15 #include <shlobj.h>
16 #include <regstr.h>
17 #include <cpl.h>
18
19 #include "resource.h"
20 #include "powercfg.h"
21
22 #define NUM_APPLETS (1)
23
24 static LONG APIENTRY Applet1(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam);
25
26
27 HINSTANCE hApplet = 0;
28 GLOBAL_POWER_POLICY gGPP;
29 TCHAR langSel[255];
30
31 /* Applets */
32 APPLET Applets[NUM_APPLETS] =
33 {
34 {IDC_CPLICON_1, IDS_CPLNAME_1, IDS_CPLDESCRIPTION_1, Applet1}
35 };
36
37 static BOOL CALLBACK
38 PropSheetAddPage(HPROPSHEETPAGE hpage, LPARAM lParam)
39 {
40 PROPSHEETHEADER *ppsh = (PROPSHEETHEADER *)lParam;
41 if (ppsh != NULL && ppsh->nPages < MAX_POWER_PAGES)
42 {
43 ppsh->phpage[ppsh->nPages++] = hpage;
44 return TRUE;
45 }
46
47 return FALSE;
48 }
49
50 static BOOL
51 InitPropSheetPage(PROPSHEETHEADER *ppsh, WORD idDlg, DLGPROC DlgProc)
52 {
53 HPROPSHEETPAGE hPage;
54 PROPSHEETPAGE psp;
55
56 if (ppsh->nPages < MAX_POWER_PAGES)
57 {
58 ZeroMemory(&psp, sizeof(psp));
59 psp.dwSize = sizeof(psp);
60 psp.dwFlags = PSP_DEFAULT;
61 psp.hInstance = hApplet;
62 psp.pszTemplate = MAKEINTRESOURCE(idDlg);
63 psp.pfnDlgProc = DlgProc;
64
65 hPage = CreatePropertySheetPage(&psp);
66 if (hPage != NULL)
67 {
68 return PropSheetAddPage(hPage, (LPARAM)ppsh);
69 }
70 }
71
72 return FALSE;
73 }
74
75
76 /* First Applet */
77 static LONG APIENTRY
78 Applet1(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
79 {
80 HPROPSHEETPAGE hpsp[MAX_POWER_PAGES];
81 PROPSHEETHEADER psh;
82 HPSXA hpsxa = NULL;
83 TCHAR Caption[1024];
84 SYSTEM_POWER_CAPABILITIES spc;
85 LONG ret;
86
87 UNREFERENCED_PARAMETER(hwnd);
88 UNREFERENCED_PARAMETER(uMsg);
89 UNREFERENCED_PARAMETER(wParam);
90 UNREFERENCED_PARAMETER(lParam);
91
92 memset(Caption, 0x0, sizeof(Caption));
93 LoadString(hApplet, IDS_CPLNAME_1, Caption, sizeof(Caption) / sizeof(TCHAR));
94
95 ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
96 psh.dwSize = sizeof(PROPSHEETHEADER);
97 psh.dwFlags = PSH_PROPTITLE;
98 psh.hwndParent = NULL;
99 psh.hInstance = hApplet;
100 psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDC_CPLICON_1));
101 psh.pszCaption = Caption;
102 psh.nPages = 0;
103 psh.nStartPage = 0;
104 psh.phpage = hpsp;
105
106 InitPropSheetPage(&psh, IDD_PROPPAGEPOWERSHEMES, (DLGPROC)PowerSchemesDlgProc);
107 if (GetPwrCapabilities(&spc))
108 {
109 if (spc.SystemBatteriesPresent)
110 {
111 InitPropSheetPage(&psh, IDD_PROPPAGEALARMS, (DLGPROC)AlarmsDlgProc);
112 }
113 }
114 InitPropSheetPage(&psh, IDD_PROPPAGEADVANCED, (DLGPROC)AdvancedDlgProc);
115 InitPropSheetPage(&psh, IDD_PROPPAGEHIBERNATE, (DLGPROC)HibernateDlgProc);
116
117 /* Load additional pages provided by shell extensions */
118 hpsxa = SHCreatePropSheetExtArray(HKEY_LOCAL_MACHINE, REGSTR_PATH_CONTROLSFOLDER TEXT("\\Power"), MAX_POWER_PAGES - psh.nPages);
119 if (hpsxa != NULL)
120 SHAddFromPropSheetExtArray(hpsxa, PropSheetAddPage, (LPARAM)&psh);
121
122 ret = (LONG)(PropertySheet(&psh) != -1);
123
124 if (hpsxa != NULL)
125 SHDestroyPropSheetExtArray(hpsxa);
126
127 return ret;
128 }
129
130 /* Control Panel Callback */
131 LONG CALLBACK
132 CPlApplet(HWND hwndCPl,
133 UINT uMsg,
134 LPARAM lParam1,
135 LPARAM lParam2)
136 {
137 int i = (int)lParam1;
138
139 switch(uMsg)
140 {
141 case CPL_INIT:
142 {
143 return TRUE;
144 }
145 case CPL_GETCOUNT:
146 {
147 return NUM_APPLETS;
148 }
149 case CPL_INQUIRE:
150 {
151 CPLINFO *CPlInfo = (CPLINFO*)lParam2;
152 CPlInfo->lData = 0;
153 CPlInfo->idIcon = Applets[i].idIcon;
154 CPlInfo->idName = Applets[i].idName;
155 CPlInfo->idInfo = Applets[i].idDescription;
156 break;
157 }
158 case CPL_DBLCLK:
159 {
160 Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
161 break;
162 }
163 }
164 return FALSE;
165 }
166
167
168 BOOLEAN WINAPI
169 DllMain(HINSTANCE hinstDLL,
170 DWORD dwReason,
171 LPVOID lpvReserved)
172 {
173 UNREFERENCED_PARAMETER(lpvReserved);
174 switch(dwReason)
175 {
176 case DLL_PROCESS_ATTACH:
177 case DLL_THREAD_ATTACH:
178 hApplet = hinstDLL;
179 break;
180 }
181 return TRUE;
182 }
183
184