ce05e33846f5d8568b731aa0da28b05a1c0cce0e
[reactos.git] / dll / cpl / joy / joy.c
1 /*
2 * ReactOS
3 * Copyright (C) 2004 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 /*
20 *
21 * PROJECT: ReactOS Software Control Panel
22 * FILE: dll/cpl/joy/joy.c
23 * PURPOSE: ReactOS Software Control Panel
24 * PROGRAMMER: Dmitry Chapyshev (lentind@yandex.ru)
25 * UPDATE HISTORY:
26 * 10-18-2007 Created
27 */
28
29 #include "joy.h"
30
31 #define NUM_APPLETS (1)
32
33 LONG CALLBACK SystemApplet(VOID);
34 HINSTANCE hApplet = 0;
35 HWND MainDlg;
36
37 /* Applets */
38
39 APPLET Applets[NUM_APPLETS] =
40 {
41 {IDI_CPLSYSTEM, IDS_CPLSYSTEMNAME, IDS_CPLSYSTEMDESCRIPTION, SystemApplet}
42 };
43
44 VOID
45 AddColumns(HWND hList)
46 {
47 LV_COLUMN dummy;
48 RECT rect;
49 int Size;
50 TCHAR szBuf[256];
51
52 GetClientRect(hList, &rect);
53 Size = rect.right - rect.left - 250;
54
55 LoadString(hApplet, IDS_STATUS, szBuf, sizeof(szBuf) / sizeof(TCHAR));
56
57 ZeroMemory(&dummy, sizeof(LV_COLUMN));
58 dummy.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
59 dummy.iSubItem = 0;
60 dummy.pszText = (LPTSTR)szBuf;
61 dummy.cx = Size;
62 (void)ListView_InsertColumn(hList, 0, &dummy);
63
64 GetClientRect(hList, &rect);
65
66 LoadString(hApplet, IDS_CONTROLLER, szBuf, sizeof(szBuf) / sizeof(TCHAR));
67
68 ZeroMemory(&dummy, sizeof(LV_COLUMN));
69 dummy.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
70 dummy.iSubItem = 0;
71 dummy.pszText = (LPTSTR)szBuf;
72 dummy.cx = rect.right - rect.left - Size;
73 (void)ListView_InsertColumn(hList, 0, &dummy);
74 }
75
76 INT_PTR CALLBACK
77 AdvancedPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
78 {
79 UNREFERENCED_PARAMETER(lParam);
80
81 switch (uMsg)
82 {
83 case WM_INITDIALOG:
84 break;
85
86 case WM_COMMAND:
87 switch (LOWORD(wParam))
88 {
89 case IDOK:
90 EndDialog(hwndDlg,LOWORD(wParam));
91 break;
92
93 case IDCANCEL:
94 EndDialog(hwndDlg,LOWORD(wParam));
95 break;
96 }
97 break;
98
99 case WM_NOTIFY:
100 break;
101
102 case WM_SYSCOMMAND:
103 switch (LOWORD(wParam))
104 {
105 case SC_CONTEXTHELP:
106 // Not implemented yet
107 break;
108 }
109 break;
110 }
111 return 0;
112 }
113
114 INT_PTR CALLBACK
115 CustomPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
116 {
117 UNREFERENCED_PARAMETER(lParam);
118
119 switch (uMsg)
120 {
121 case WM_INITDIALOG:
122 break;
123
124 case WM_COMMAND:
125 switch (LOWORD(wParam))
126 {
127 case IDOK:
128 EndDialog(hwndDlg,LOWORD(wParam));
129 break;
130
131 case IDCANCEL:
132 EndDialog(hwndDlg,LOWORD(wParam));
133 break;
134 }
135 break;
136
137 case WM_NOTIFY:
138 break;
139
140 case WM_SYSCOMMAND:
141 switch (LOWORD(wParam))
142 {
143 case SC_CONTEXTHELP:
144 // Not implemented yet
145 break;
146 }
147 break;
148 }
149 return 0;
150 }
151
152 INT_PTR CALLBACK
153 AddPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
154 {
155 UNREFERENCED_PARAMETER(lParam);
156
157 switch (uMsg)
158 {
159 case WM_INITDIALOG:
160 break;
161
162 case WM_COMMAND:
163 switch (LOWORD(wParam))
164 {
165 case IDC_CUSTOM_BUTTON:
166 DialogBox(hApplet,
167 MAKEINTRESOURCE(IDD_CUSTOM),
168 hwndDlg,
169 CustomPageProc);
170 break;
171
172 case IDOK:
173 EndDialog(hwndDlg,LOWORD(wParam));
174 break;
175
176 case IDCANCEL:
177 EndDialog(hwndDlg,LOWORD(wParam));
178 break;
179 }
180 break;
181
182 case WM_NOTIFY:
183 break;
184
185 case WM_SYSCOMMAND:
186 switch (LOWORD(wParam))
187 {
188 case SC_CONTEXTHELP:
189 // Not implemented yet
190 break;
191 }
192 break;
193 }
194 return 0;
195 }
196
197 /* Property page dialog callback */
198 INT_PTR CALLBACK
199 MainPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
200 {
201 UNREFERENCED_PARAMETER(lParam);
202
203 switch (uMsg)
204 {
205 case WM_INITDIALOG:
206 AddColumns(GetDlgItem(hwndDlg,IDC_CONTROLLER_LIST));
207 break;
208
209 case WM_COMMAND:
210 switch (LOWORD(wParam))
211 {
212 case IDC_ADD_BUTTON:
213 DialogBox(hApplet,
214 MAKEINTRESOURCE(IDD_ADD),
215 hwndDlg,
216 AddPageProc);
217 break;
218
219 case IDC_ADVANCED_BUTTON:
220 DialogBox(hApplet,
221 MAKEINTRESOURCE(IDD_ADVANCED),
222 hwndDlg,
223 AdvancedPageProc);
224 break;
225
226 case IDOK:
227 EndDialog(hwndDlg,LOWORD(wParam));
228 break;
229 }
230 break;
231
232 case WM_NOTIFY:
233 break;
234
235 case WM_SYSCOMMAND:
236 switch (LOWORD(wParam))
237 {
238 case SC_CLOSE:
239 EndDialog(hwndDlg,LOWORD(wParam));
240 break;
241
242 case SC_CONTEXTHELP:
243 // Not implemented yet
244 break;
245 }
246 break;
247 }
248 return 0;
249 }
250
251 /* First Applet */
252 LONG CALLBACK
253 SystemApplet(VOID)
254 {
255 DialogBox(hApplet,
256 MAKEINTRESOURCE(IDD_PROPPAGEMAIN),
257 MainDlg,
258 MainPageProc);
259
260 return (LONG)TRUE;
261 }
262
263 /* Control Panel Callback */
264 LONG CALLBACK
265 CPlApplet(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
266 {
267 CPLINFO *CPlInfo;
268 DWORD i;
269
270 UNREFERENCED_PARAMETER(hwndCPl);
271
272 i = (DWORD)lParam1;
273 switch (uMsg)
274 {
275 case CPL_INIT:
276 return TRUE;
277
278 case CPL_GETCOUNT:
279 return NUM_APPLETS;
280
281 case CPL_INQUIRE:
282 CPlInfo = (CPLINFO*)lParam2;
283 CPlInfo->lData = 0;
284 CPlInfo->idIcon = Applets[i].idIcon;
285 CPlInfo->idName = Applets[i].idName;
286 CPlInfo->idInfo = Applets[i].idDescription;
287 break;
288
289 case CPL_DBLCLK:
290 {
291 MainDlg = hwndCPl;
292 Applets[i].AppletProc();
293 }
294 break;
295 }
296
297 return FALSE;
298 }
299
300 BOOL WINAPI
301 DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
302 {
303 UNREFERENCED_PARAMETER(lpvReserved);
304
305 switch (dwReason)
306 {
307 case DLL_PROCESS_ATTACH:
308 case DLL_THREAD_ATTACH:
309 CoInitialize(NULL);
310 hApplet = hinstDLL;
311 break;
312 }
313
314 return TRUE;
315 }