xref: /reactos/dll/cpl/joy/joy.c (revision 7115d7ba)
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  *    05-18-2020  Updated (init of dialog and combobox)
28  */
29 
30 #include "joy.h"
31 
32 #define NUM_APPLETS    (1)
33 
34 LONG CALLBACK SystemApplet(HWND hwnd, UINT uMsg, LPARAM lParam1, LPARAM lParam2);
35 HINSTANCE hApplet = 0;
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         {
85             WCHAR szBuf[256];
86             HWND hComboHwnd = GetDlgItem(hwndDlg,IDC_PREFERRED_DEV_COMBO);
87 
88             LoadStringW(hApplet, IDS_NONE, szBuf, _countof(szBuf));
89             SendMessageW(hComboHwnd, CB_ADDSTRING, 0, (LPARAM)szBuf);
90             SendMessageW(hComboHwnd, CB_SETCURSEL, 0, (LPARAM)NULL);
91             break;
92         }
93 
94         case WM_COMMAND:
95             switch (LOWORD(wParam))
96             {
97                 case IDOK:
98                     EndDialog(hwndDlg,LOWORD(wParam));
99                     break;
100 
101                 case IDCANCEL:
102                     EndDialog(hwndDlg,LOWORD(wParam));
103                     break;
104             }
105             break;
106 
107         case WM_NOTIFY:
108             break;
109 
110         case WM_SYSCOMMAND:
111             switch (LOWORD(wParam))
112             {
113                 case SC_CONTEXTHELP:
114                     // Not implemented yet
115                     break;
116             }
117             break;
118     }
119     return 0;
120 }
121 
122 INT_PTR CALLBACK
123 CustomPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
124 {
125     UNREFERENCED_PARAMETER(lParam);
126 
127     switch (uMsg)
128     {
129         case WM_INITDIALOG:
130         {
131             WCHAR szBuf[2];
132             HWND hComboHwnd;
133             szBuf[1] = UNICODE_NULL;
134 
135             CheckDlgButton(hwndDlg, IDC_JOYSTICK_RADIO, BST_CHECKED);
136 
137             hComboHwnd = GetDlgItem(hwndDlg, IDC_AXES_COMBO);
138             szBuf[0] = L'2';
139             SendMessageW(hComboHwnd, CB_ADDSTRING, 0, (LPARAM)szBuf);
140             szBuf[0] = L'3';
141             SendMessageW(hComboHwnd, CB_ADDSTRING, 0, (LPARAM)szBuf);
142             szBuf[0] = L'4';
143             SendMessageW(hComboHwnd, CB_ADDSTRING, 0, (LPARAM)szBuf);
144             SendMessageW(hComboHwnd, CB_SETCURSEL, 0, 0);
145 
146             hComboHwnd = GetDlgItem(hwndDlg, IDC_BUTTONS_COMBO);
147             szBuf[0] = L'0';
148             SendMessageW(hComboHwnd, CB_ADDSTRING, 0, (LPARAM)szBuf);
149             szBuf[0] = L'1';
150             SendMessageW(hComboHwnd, CB_ADDSTRING, 0, (LPARAM)szBuf);
151             szBuf[0] = L'2';
152             SendMessageW(hComboHwnd, CB_ADDSTRING, 0, (LPARAM)szBuf);
153             szBuf[0] = L'3';
154             SendMessageW(hComboHwnd, CB_ADDSTRING, 0, (LPARAM)szBuf);
155             szBuf[0] = L'4';
156             SendMessageW(hComboHwnd, CB_ADDSTRING, 0, (LPARAM)szBuf);
157             SendMessageW(hComboHwnd, CB_SETCURSEL, 4, 0);
158 
159             break;
160         }
161 
162         case WM_COMMAND:
163             switch (LOWORD(wParam))
164             {
165                 case IDOK:
166                     EndDialog(hwndDlg,LOWORD(wParam));
167                     break;
168 
169                 case IDCANCEL:
170                     EndDialog(hwndDlg,LOWORD(wParam));
171                     break;
172             }
173             break;
174 
175         case WM_NOTIFY:
176             break;
177 
178         case WM_SYSCOMMAND:
179             switch (LOWORD(wParam))
180             {
181                 case SC_CONTEXTHELP:
182                     // Not implemented yet
183                     break;
184             }
185             break;
186     }
187     return 0;
188 }
189 
190 INT_PTR CALLBACK
191 AddPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
192 {
193     UNREFERENCED_PARAMETER(lParam);
194 
195     switch (uMsg)
196     {
197         case WM_INITDIALOG:
198             break;
199 
200         case WM_COMMAND:
201             switch (LOWORD(wParam))
202             {
203                 case IDC_CUSTOM_BUTTON:
204                     DialogBox(hApplet,
205                               MAKEINTRESOURCE(IDD_CUSTOM),
206                               hwndDlg,
207                               CustomPageProc);
208                     break;
209 
210                 case IDOK:
211                     EndDialog(hwndDlg,LOWORD(wParam));
212                     break;
213 
214                 case IDCANCEL:
215                     EndDialog(hwndDlg,LOWORD(wParam));
216                     break;
217             }
218             break;
219 
220         case WM_NOTIFY:
221             break;
222 
223         case WM_SYSCOMMAND:
224             switch (LOWORD(wParam))
225             {
226                 case SC_CONTEXTHELP:
227                     // Not implemented yet
228                     break;
229             }
230             break;
231     }
232     return 0;
233 }
234 
235 /* Property page dialog callback */
236 INT_PTR CALLBACK
237 MainPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
238 {
239     static HICON s_hIcon = NULL, s_hIconSm = NULL;
240     UNREFERENCED_PARAMETER(lParam);
241 
242     switch (uMsg)
243     {
244         case WM_INITDIALOG:
245             AddColumns(GetDlgItem(hwndDlg, IDC_CONTROLLER_LIST));
246             s_hIcon = LoadIconW(hApplet, MAKEINTRESOURCEW(IDI_CPLSYSTEM));
247             s_hIconSm = (HICON)LoadImageW(hApplet, MAKEINTRESOURCEW(IDI_CPLSYSTEM),
248                                           IMAGE_ICON,
249                                           GetSystemMetrics(SM_CXSMICON),
250                                           GetSystemMetrics(SM_CYSMICON), 0);
251             SendMessageW(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)s_hIcon);
252             SendMessageW(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)s_hIconSm);
253             break;
254 
255         case WM_COMMAND:
256             switch (LOWORD(wParam))
257             {
258                 case IDC_ADD_BUTTON:
259                     DialogBox(hApplet,
260                               MAKEINTRESOURCE(IDD_ADD),
261                               hwndDlg,
262                               AddPageProc);
263                     break;
264 
265                 case IDC_ADVANCED_BUTTON:
266                     DialogBox(hApplet,
267                               MAKEINTRESOURCE(IDD_ADVANCED),
268                               hwndDlg,
269                               AdvancedPageProc);
270                     break;
271 
272                 case IDOK:
273                     DestroyIcon(s_hIcon);
274                     DestroyIcon(s_hIconSm);
275                     EndDialog(hwndDlg,LOWORD(wParam));
276                     break;
277             }
278             break;
279 
280         case WM_NOTIFY:
281             break;
282 
283         case WM_SYSCOMMAND:
284             switch (LOWORD(wParam))
285             {
286                 case SC_CLOSE:
287                     DestroyIcon(s_hIcon);
288                     DestroyIcon(s_hIconSm);
289                     EndDialog(hwndDlg,LOWORD(wParam));
290                     break;
291 
292                 case SC_CONTEXTHELP:
293                     // Not implemented yet
294                     break;
295             }
296             break;
297     }
298     return 0;
299 }
300 
301 /* First Applet */
302 LONG CALLBACK
303 SystemApplet(HWND hwnd, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
304 {
305     UNREFERENCED_PARAMETER(uMsg);
306     UNREFERENCED_PARAMETER(lParam1);
307     UNREFERENCED_PARAMETER(lParam2);
308 
309     DialogBox(hApplet,
310               MAKEINTRESOURCE(IDD_PROPPAGEMAIN),
311               hwnd,
312               MainPageProc);
313 
314     return (LONG)TRUE;
315 }
316 
317 /* Control Panel Callback */
318 LONG CALLBACK
319 CPlApplet(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
320 {
321     CPLINFO *CPlInfo;
322     DWORD i;
323 
324     UNREFERENCED_PARAMETER(hwndCPl);
325 
326     i = (DWORD)lParam1;
327     switch (uMsg)
328     {
329         case CPL_INIT:
330             return TRUE;
331 
332         case CPL_GETCOUNT:
333             return NUM_APPLETS;
334 
335         case CPL_INQUIRE:
336             CPlInfo = (CPLINFO*)lParam2;
337             CPlInfo->lData = 0;
338             CPlInfo->idIcon = Applets[i].idIcon;
339             CPlInfo->idName = Applets[i].idName;
340             CPlInfo->idInfo = Applets[i].idDescription;
341             break;
342 
343         case CPL_DBLCLK:
344             Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
345             break;
346     }
347 
348     return FALSE;
349 }
350 
351 BOOL WINAPI
352 DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
353 {
354     UNREFERENCED_PARAMETER(lpvReserved);
355 
356     switch (dwReason)
357     {
358         case DLL_PROCESS_ATTACH:
359         case DLL_THREAD_ATTACH:
360             CoInitialize(NULL);
361             hApplet = hinstDLL;
362             break;
363     }
364 
365     return TRUE;
366 }
367