winhttp, wininet: Load i2d_X509 from libcrypto.so.
[wine/multimedia.git] / programs / winecfg / audio.c
blob8e966a5059b2bc1b88686b4f406cc707f516cb30
1 /*
2 * Audio management UI code
4 * Copyright 2004 Chris Morgan
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define WIN32_LEAN_AND_MEAN
23 #define NONAMELESSSTRUCT
24 #define NONAMELESSUNION
26 #include "config.h"
27 #include "wine/port.h"
29 #include <assert.h>
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <string.h>
34 #include <windows.h>
35 #include <wine/debug.h>
36 #include <shellapi.h>
37 #include <objbase.h>
38 #include <shlguid.h>
39 #include <shlwapi.h>
40 #include <shlobj.h>
41 #include <mmsystem.h>
42 #include <mmreg.h>
43 #include <mmddk.h>
45 #include "winecfg.h"
46 #include "resource.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
50 #define DRIVER_MASK 0x80000000
51 #define DEVICE_MASK 0x40000000
52 #define MAX_NAME_LENGTH 64
54 typedef DWORD (WINAPI * MessagePtr)(UINT, UINT, DWORD, DWORD, DWORD);
56 static struct DSOUNDACCEL
58 UINT displayID;
59 const char* settingStr;
60 } const DSound_HW_Accels[] = {
61 {IDS_ACCEL_FULL, "Full"},
62 {IDS_ACCEL_STANDARD, "Standard"},
63 {IDS_ACCEL_BASIC, "Basic"},
64 {IDS_ACCEL_EMULATION, "Emulation"},
65 {0, 0}
68 static const char* DSound_Rates[] = {
69 "48000",
70 "44100",
71 "22050",
72 "16000",
73 "11025",
74 "8000",
75 NULL
78 static const char* DSound_Bits[] = {
79 "8",
80 "16",
81 NULL
84 typedef struct
86 UINT nameID;
87 const char *szDriver;
88 } AUDIO_DRIVER;
90 static const AUDIO_DRIVER sAudioDrivers[] = {
91 {IDS_DRIVER_ALSA, "alsa"},
92 {IDS_DRIVER_OSS, "oss"},
93 {IDS_DRIVER_COREAUDIO, "coreaudio"},
94 {IDS_DRIVER_JACK, "jack"},
95 {IDS_DRIVER_NAS, "nas"},
96 {IDS_DRIVER_ESOUND, "esd"},
97 {IDS_DRIVER_AUDIOIO, "audioio"},
98 {0, ""}
101 /* list of available drivers */
102 static AUDIO_DRIVER * loadedAudioDrv;
104 /* local copy of registry setting */
105 static char curAudioDriver[1024];
107 /* driver index to configure */
108 static int toConfigure;
110 /* display a driver specific configuration dialog */
111 static void configureAudioDriver(HWND hDlg)
113 const AUDIO_DRIVER *pAudioDrv = &loadedAudioDrv[toConfigure];
115 if (strlen(pAudioDrv->szDriver) != 0)
117 HDRVR hdrvr;
118 char wine_driver[MAX_NAME_LENGTH + 9];
119 sprintf(wine_driver, "wine%s.drv", pAudioDrv->szDriver);
120 hdrvr = OpenDriverA(wine_driver, 0, 0);
121 if (hdrvr != 0)
123 if (SendDriverMessage(hdrvr, DRV_QUERYCONFIGURE, 0, 0) != 0)
125 DRVCONFIGINFO dci;
126 LONG lRes;
127 dci.dwDCISize = sizeof (dci);
128 dci.lpszDCISectionName = NULL;
129 dci.lpszDCIAliasName = NULL;
130 lRes = SendDriverMessage(hdrvr, DRV_CONFIGURE, 0, (LONG_PTR)&dci);
132 CloseDriver(hdrvr, 0, 0);
134 else
136 WCHAR wine_driverW[MAX_NAME_LENGTH+9];
137 WCHAR messageStr[256];
138 WCHAR str[1024];
140 MultiByteToWideChar (CP_ACP, 0, wine_driver, -1, wine_driverW,
141 sizeof (wine_driverW)/sizeof(wine_driverW[0]));
143 LoadStringW (GetModuleHandle (NULL), IDS_OPEN_DRIVER_ERROR, messageStr,
144 sizeof(messageStr)/sizeof(messageStr[0]));
145 wsprintfW (str, messageStr, wine_driverW);
146 MessageBoxW (hDlg, str, NULL, MB_OK | MB_ICONERROR);
151 /* is driver in local copy of driver registry string */
152 static BOOL isDriverSet(const char * driver)
154 WINE_TRACE("driver = %s, curAudioDriver = %s\n", driver, curAudioDriver);
156 if (strstr(curAudioDriver, driver))
157 return TRUE;
159 return FALSE;
162 /* add driver to local copy of driver registry string */
163 static void addDriver(const char * driver)
165 if (!isDriverSet(driver))
167 if (strlen(curAudioDriver))
168 strcat(curAudioDriver, ",");
169 strcat(curAudioDriver, driver);
173 /* remove driver from local copy of driver registry string */
174 static void removeDriver(const char * driver)
176 char pattern[32], *p;
177 int drvlen, listlen;
179 strcpy(pattern, ",");
180 strcat(pattern, driver);
181 strcat(pattern, ",");
182 drvlen = strlen(driver);
183 listlen = strlen(curAudioDriver);
185 p = strstr(curAudioDriver, pattern);
186 if (p) /* somewhere in the middle */
187 memmove(p, p+drvlen+1, strlen(p+drvlen+1)+1);
188 else if (!strncmp(curAudioDriver, pattern+1, drvlen+1)) /* the head */
189 memmove(curAudioDriver, curAudioDriver+drvlen+1, listlen-drvlen);
190 else if (!strncmp(curAudioDriver+listlen-drvlen-1, pattern, drvlen+1)) /* the tail */
191 curAudioDriver[listlen-drvlen-1] = 0;
192 else if (!strcmp(curAudioDriver, driver)) /* only one entry (head&tail) */
193 curAudioDriver[0] = 0;
194 else
195 WINE_FIXME("driver '%s' is not in the list, please report!\n", driver);
198 static void initAudioDeviceTree(HWND hDlg)
200 const AUDIO_DRIVER *pAudioDrv = NULL;
201 int i, j;
202 TVINSERTSTRUCTW insert;
203 HTREEITEM root, driver[10];
204 HWND tree = NULL;
205 HIMAGELIST hImageList;
206 HBITMAP hBitMap;
207 HCURSOR old_cursor;
208 WCHAR driver_type[64], dev_type[64];
210 tree = GetDlgItem(hDlg, IDC_AUDIO_TREE);
212 if (!tree)
213 return;
215 /* set tree view style */
216 SetWindowLong(tree, GWL_STYLE, GetWindowLong(tree, GWL_STYLE) | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT);
218 /* state checkbox */
219 hImageList = ImageList_Create(16, 16, FALSE, 3, 0);
220 hBitMap = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_CHECKBOX));
221 ImageList_Add(hImageList, hBitMap, NULL);
222 DeleteObject(hBitMap);
223 SendMessageW( tree, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)hImageList );
225 /* root item */
226 LoadStringW (GetModuleHandle (NULL), IDS_SOUNDDRIVERS, driver_type,
227 sizeof(driver_type)/sizeof(driver_type[0]));
228 insert.hParent = TVI_ROOT;
229 insert.hInsertAfter = TVI_LAST;
230 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
231 insert.u.item.pszText = driver_type;
232 insert.u.item.cChildren = 1;
233 root = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
235 /* change to the wait cursor because this can take a while if there is a
236 * misbehaving driver that takes a long time to open
238 old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
240 /* iterate over list of loaded drivers */
241 for (pAudioDrv = loadedAudioDrv, i = 0; pAudioDrv->nameID; i++, pAudioDrv++) {
242 HDRVR hdrv;
243 char name[MAX_PATH];
244 WCHAR text[MAX_PATH];
246 sprintf(name, "wine%s.drv", pAudioDrv->szDriver);
247 LoadStringW (GetModuleHandle (NULL), pAudioDrv->nameID, text,
248 sizeof(text)/sizeof(text[0]));
250 if ((hdrv = OpenDriverA(name, 0, 0)))
252 HMODULE lib;
253 if ((lib = GetDriverModuleHandle(hdrv)))
255 int num_wod = 0, num_wid = 0, num_mod = 0, num_mid = 0, num_aux = 0, num_mxd = 0;
256 MessagePtr wodMessagePtr = (MessagePtr)GetProcAddress(lib, "wodMessage");
257 MessagePtr widMessagePtr = (MessagePtr)GetProcAddress(lib, "widMessage");
258 MessagePtr modMessagePtr = (MessagePtr)GetProcAddress(lib, "modMessage");
259 MessagePtr midMessagePtr = (MessagePtr)GetProcAddress(lib, "midMessage");
260 MessagePtr auxMessagePtr = (MessagePtr)GetProcAddress(lib, "auxMessage");
261 MessagePtr mxdMessagePtr = (MessagePtr)GetProcAddress(lib, "mxdMessage");
263 if (wodMessagePtr)
264 num_wod = wodMessagePtr(0, WODM_GETNUMDEVS, 0, 0, 0);
266 if (widMessagePtr)
267 num_wid = widMessagePtr(0, WIDM_GETNUMDEVS, 0, 0, 0);
269 if (modMessagePtr)
270 num_mod = modMessagePtr(0, MODM_GETNUMDEVS, 0, 0, 0);
272 if (midMessagePtr)
273 num_mid = midMessagePtr(0, MIDM_GETNUMDEVS, 0, 0, 0);
275 if (auxMessagePtr)
276 num_aux = auxMessagePtr(0, AUXDM_GETNUMDEVS, 0, 0, 0);
278 if (mxdMessagePtr)
279 num_mxd = mxdMessagePtr(0, MXDM_GETNUMDEVS, 0, 0, 0);
281 if (num_wod == 0 && num_wid == 0 && num_mod == 0 && num_mid == 0 && num_aux == 0 && num_mxd == 0)
283 insert.hParent = root;
284 insert.u.item.mask = TVIF_TEXT | TVIF_STATE | TVIF_PARAM;
285 insert.u.item.pszText = text;
286 insert.u.item.stateMask = TVIS_STATEIMAGEMASK;
287 insert.u.item.lParam = i + DRIVER_MASK;
288 if (isDriverSet(pAudioDrv->szDriver))
289 insert.u.item.state = INDEXTOSTATEIMAGEMASK(2);
290 else
291 insert.u.item.state = INDEXTOSTATEIMAGEMASK(1);
293 driver[i] = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
295 else
297 HTREEITEM type;
299 insert.hParent = root;
300 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN | TVIF_STATE | TVIF_PARAM;
301 insert.u.item.pszText = text;
302 insert.u.item.cChildren = 1;
303 insert.u.item.stateMask = TVIS_STATEIMAGEMASK;
304 insert.u.item.lParam = i + DRIVER_MASK;
306 if (isDriverSet(pAudioDrv->szDriver))
307 insert.u.item.state = INDEXTOSTATEIMAGEMASK(2);
308 else
309 insert.u.item.state = INDEXTOSTATEIMAGEMASK(1);
311 driver[i] = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
313 if (num_wod)
315 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_WAVEOUT, dev_type,
316 sizeof(dev_type)/sizeof(dev_type[0]));
318 insert.hParent = driver[i];
319 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
320 insert.u.item.pszText = dev_type;
321 insert.u.item.cChildren = 1;
323 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
325 for (j = 0; j < num_wod; j++)
327 WAVEOUTCAPSW caps;
329 wodMessagePtr(j, WODM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
331 insert.hParent = type;
332 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
333 insert.u.item.pszText = caps.szPname;
334 insert.u.item.lParam = j + DEVICE_MASK;
336 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
340 if (num_wid)
342 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_WAVEIN, dev_type,
343 sizeof(dev_type)/sizeof(dev_type[0]));
345 insert.hParent = driver[i];
346 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
347 insert.u.item.pszText = dev_type;
348 insert.u.item.cChildren = 1;
350 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
352 for (j = 0; j < num_wid; j++)
354 WAVEINCAPSW caps;
356 widMessagePtr(j, WIDM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
358 insert.hParent = type;
359 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
360 insert.u.item.pszText = caps.szPname;
361 insert.u.item.lParam = j + DEVICE_MASK;
363 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
367 if (num_mod)
369 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_MIDIOUT, dev_type,
370 sizeof(dev_type)/sizeof(dev_type[0]));
372 insert.hParent = driver[i];
373 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
374 insert.u.item.pszText = dev_type;
375 insert.u.item.cChildren = 1;
377 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
379 for (j = 0; j < num_mod; j++)
381 MIDIOUTCAPSW caps;
383 modMessagePtr(j, MODM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
385 insert.hParent = type;
386 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
387 insert.u.item.pszText = caps.szPname;
388 insert.u.item.lParam = j + DEVICE_MASK;
390 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
394 if (num_mid)
396 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_MIDIIN, dev_type,
397 sizeof(dev_type)/sizeof(dev_type[0]));
399 insert.hParent = driver[i];
400 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
401 insert.u.item.pszText = dev_type;
402 insert.u.item.cChildren = 1;
404 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
406 for (j = 0; j < num_mid; j++)
408 MIDIINCAPSW caps;
410 midMessagePtr(j, MIDM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
412 insert.hParent = type;
413 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
414 insert.u.item.pszText = caps.szPname;
415 insert.u.item.lParam = j + DEVICE_MASK;
417 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
421 if (num_aux)
423 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_AUX, dev_type,
424 sizeof(dev_type)/sizeof(dev_type[0]));
426 insert.hParent = driver[i];
427 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
428 insert.u.item.pszText = dev_type;
429 insert.u.item.cChildren = 1;
431 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
433 for (j = 0; j < num_aux; j++)
435 AUXCAPSW caps;
437 auxMessagePtr(j, AUXDM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
439 insert.hParent = type;
440 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
441 insert.u.item.pszText = caps.szPname;
442 insert.u.item.lParam = j + DEVICE_MASK;
444 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
448 if (num_mxd)
450 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_MIXER, dev_type,
451 sizeof(dev_type)/sizeof(dev_type[0]));
453 insert.hParent = driver[i];
454 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
455 insert.u.item.pszText = dev_type;
456 insert.u.item.cChildren = 1;
458 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
460 for (j = 0; j < num_mxd; j++)
462 MIXERCAPSW caps;
464 mxdMessagePtr(j, MXDM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
466 insert.hParent = type;
467 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
468 insert.u.item.pszText = caps.szPname;
469 insert.u.item.lParam = j + DEVICE_MASK;
471 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
476 CloseDriver(hdrv, 0, 0);
480 /* restore the original cursor */
481 SetCursor(old_cursor);
483 SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_SELECTITEM, 0, 0);
484 SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_EXPAND, TVE_EXPAND, (LPARAM)root);
485 for (j = 0; j < i; j++)
486 SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_EXPAND, TVE_EXPAND, (LPARAM)driver[j]);
489 /* find all drivers that can be loaded */
490 static void findAudioDrivers(void)
492 int numFound = 0;
493 const AUDIO_DRIVER *pAudioDrv = NULL;
494 HCURSOR old_cursor;
496 /* delete an existing list */
497 HeapFree(GetProcessHeap(), 0, loadedAudioDrv);
498 loadedAudioDrv = 0;
500 /* change to the wait cursor because this can take a while if there is a
501 * misbehaving driver that takes a long time to open
503 old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
505 for (pAudioDrv = sAudioDrivers; pAudioDrv->nameID; pAudioDrv++)
507 if (strlen(pAudioDrv->szDriver))
509 HDRVR hdrv;
510 char driver[MAX_PATH];
512 sprintf(driver, "wine%s.drv", pAudioDrv->szDriver);
514 if ((hdrv = OpenDriverA(driver, 0, 0)))
516 CloseDriver(hdrv, 0, 0);
518 if (loadedAudioDrv)
519 loadedAudioDrv = HeapReAlloc(GetProcessHeap(), 0, loadedAudioDrv, (numFound + 1) * sizeof(AUDIO_DRIVER));
520 else
521 loadedAudioDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(AUDIO_DRIVER));
523 CopyMemory(&loadedAudioDrv[numFound], pAudioDrv, sizeof(AUDIO_DRIVER));
524 numFound++;
529 /* restore the original cursor */
530 SetCursor(old_cursor);
532 /* terminate list with empty driver */
533 if (numFound) {
534 loadedAudioDrv = HeapReAlloc(GetProcessHeap(), 0, loadedAudioDrv, (numFound + 1) * sizeof(AUDIO_DRIVER));
535 CopyMemory(&loadedAudioDrv[numFound], pAudioDrv, sizeof(AUDIO_DRIVER));
536 } else {
537 loadedAudioDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(AUDIO_DRIVER));
538 CopyMemory(&loadedAudioDrv[0], pAudioDrv, sizeof(AUDIO_DRIVER));
542 /* check local copy of registry string for unloadable drivers */
543 static void checkRegistrySetting(HWND hDlg)
545 const AUDIO_DRIVER *pAudioDrv;
546 char * token, * tokens = strdup(curAudioDriver);
548 start_over:
549 token = strtok(tokens, ",");
550 while (token != NULL)
552 BOOL found = FALSE;
553 for (pAudioDrv = loadedAudioDrv; pAudioDrv->nameID; pAudioDrv++)
555 if (strcmp(token, pAudioDrv->szDriver) == 0)
557 found = TRUE;
558 break;
561 if (found == FALSE)
563 WCHAR tokenW[MAX_NAME_LENGTH+1];
564 WCHAR messageStr[256];
565 WCHAR str[1024];
566 WCHAR caption[64];
568 MultiByteToWideChar (CP_ACP, 0, token, -1, tokenW, sizeof(tokenW)/sizeof(tokenW[0]));
570 LoadStringW (GetModuleHandle (NULL), IDS_UNAVAILABLE_DRIVER, messageStr,
571 sizeof(messageStr)/sizeof(messageStr[0]));
572 wsprintfW (str, messageStr, tokenW);
573 LoadStringW (GetModuleHandle (NULL), IDS_WARNING, caption,
574 sizeof(caption)/sizeof(caption[0]));
575 if (MessageBoxW (hDlg, str, caption, MB_ICONWARNING | MB_YESNOCANCEL) == IDYES)
577 removeDriver(token);
578 strcpy(tokens, curAudioDriver);
579 goto start_over;
582 token = strtok(NULL, ",");
584 free(tokens);
587 static void selectDriver(HWND hDlg, const char * driver)
589 WCHAR text[1024];
590 WCHAR caption[64];
592 strcpy(curAudioDriver, driver);
593 set_reg_key(config_key, "Drivers", "Audio", curAudioDriver);
595 if (LoadStringW(GetModuleHandle(NULL), IDS_AUDIO_MISSING, text, sizeof(text)/sizeof(text[0])))
597 if (LoadStringW(GetModuleHandle(NULL), IDS_WINECFG_TITLE, caption, sizeof(caption)/sizeof(caption[0])))
598 MessageBoxW(hDlg, text, caption, MB_OK | MB_ICONINFORMATION);
601 SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM) hDlg, 0); /* enable apply button */
604 static void initAudioDlg (HWND hDlg)
606 int i;
607 char* buf = NULL;
609 WINE_TRACE("\n");
611 /* make a list of all drivers that can be loaded */
612 findAudioDrivers();
614 /* get current registry setting if available */
615 buf = get_reg_key(config_key, "Drivers", "Audio", NULL);
617 /* check for first time install and set a default driver
618 * select first available driver, and if that fails: none
620 if (buf == NULL)
622 /* select first available driver */
623 if (*loadedAudioDrv->szDriver)
624 selectDriver(hDlg, loadedAudioDrv->szDriver);
626 else /* make a local copy of the current registry setting */
627 strcpy(curAudioDriver, buf);
629 WINE_TRACE("curAudioDriver = %s\n", curAudioDriver);
631 /* check for drivers that can't be loaded */
632 checkRegistrySetting(hDlg);
634 initAudioDeviceTree(hDlg);
636 SendDlgItemMessage(hDlg, IDC_DSOUND_HW_ACCEL, CB_RESETCONTENT, 0, 0);
637 for (i = 0; 0 != DSound_HW_Accels[i].displayID; ++i) {
638 WCHAR accelStr[64];
639 LoadStringW (GetModuleHandle (NULL), DSound_HW_Accels[i].displayID, accelStr,
640 sizeof(accelStr)/sizeof(accelStr[0]));
641 SendDlgItemMessageW (hDlg, IDC_DSOUND_HW_ACCEL, CB_ADDSTRING, 0, (LPARAM)accelStr);
643 buf = get_reg_key(config_key, keypath("DirectSound"), "HardwareAcceleration", "Full");
644 for (i = 0; NULL != DSound_HW_Accels[i].settingStr; ++i) {
645 if (strcmp(buf, DSound_HW_Accels[i].settingStr) == 0) {
646 SendDlgItemMessage(hDlg, IDC_DSOUND_HW_ACCEL, CB_SETCURSEL, i, 0);
647 break ;
650 if (NULL == DSound_HW_Accels[i].settingStr) {
651 WINE_ERR("Invalid Direct Sound HW Accel read from registry (%s)\n", buf);
653 HeapFree(GetProcessHeap(), 0, buf);
655 SendDlgItemMessage(hDlg, IDC_DSOUND_RATES, CB_RESETCONTENT, 0, 0);
656 for (i = 0; NULL != DSound_Rates[i]; ++i) {
657 SendDlgItemMessage(hDlg, IDC_DSOUND_RATES, CB_ADDSTRING, 0, (LPARAM) DSound_Rates[i]);
659 buf = get_reg_key(config_key, keypath("DirectSound"), "DefaultSampleRate", "44100");
660 for (i = 0; NULL != DSound_Rates[i]; ++i) {
661 if (strcmp(buf, DSound_Rates[i]) == 0) {
662 SendDlgItemMessage(hDlg, IDC_DSOUND_RATES, CB_SETCURSEL, i, 0);
663 break ;
667 SendDlgItemMessage(hDlg, IDC_DSOUND_BITS, CB_RESETCONTENT, 0, 0);
668 for (i = 0; NULL != DSound_Bits[i]; ++i) {
669 SendDlgItemMessage(hDlg, IDC_DSOUND_BITS, CB_ADDSTRING, 0, (LPARAM) DSound_Bits[i]);
671 buf = get_reg_key(config_key, keypath("DirectSound"), "DefaultBitsPerSample", "16");
672 for (i = 0; NULL != DSound_Bits[i]; ++i) {
673 if (strcmp(buf, DSound_Bits[i]) == 0) {
674 SendDlgItemMessage(hDlg, IDC_DSOUND_BITS, CB_SETCURSEL, i, 0);
675 break ;
679 buf = get_reg_key(config_key, keypath("DirectSound"), "EmulDriver", "N");
680 if (IS_OPTION_TRUE(*buf))
681 CheckDlgButton(hDlg, IDC_DSOUND_DRV_EMUL, BST_CHECKED);
682 else
683 CheckDlgButton(hDlg, IDC_DSOUND_DRV_EMUL, BST_UNCHECKED);
684 HeapFree(GetProcessHeap(), 0, buf);
687 INT_PTR CALLBACK
688 AudioDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
690 switch (uMsg) {
691 case WM_COMMAND:
692 switch (LOWORD(wParam)) {
693 case IDC_AUDIO_CONFIGURE:
694 configureAudioDriver(hDlg);
695 break;
696 case IDC_AUDIO_TEST:
697 if(!PlaySound(MAKEINTRESOURCE(IDW_TESTSOUND), NULL, SND_RESOURCE | SND_SYNC))
698 MessageBox(NULL, "Audio test failed!", "Error", MB_OK | MB_ICONERROR);
699 break;
700 case IDC_AUDIO_CONTROL_PANEL:
701 MessageBox(NULL, "Launching audio control panel not implemented yet!", "Fixme", MB_OK | MB_ICONERROR);
702 break;
703 case IDC_DSOUND_HW_ACCEL:
704 if (HIWORD(wParam) == CBN_SELCHANGE) {
705 int selected_dsound_accel;
706 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
707 selected_dsound_accel = SendDlgItemMessage(hDlg, IDC_DSOUND_HW_ACCEL, CB_GETCURSEL, 0, 0);
708 set_reg_key(config_key, keypath("DirectSound"), "HardwareAcceleration",
709 DSound_HW_Accels[selected_dsound_accel].settingStr);
711 break;
712 case IDC_DSOUND_RATES:
713 if (HIWORD(wParam) == CBN_SELCHANGE) {
714 int selected_dsound_rate;
715 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
716 selected_dsound_rate = SendDlgItemMessage(hDlg, IDC_DSOUND_RATES, CB_GETCURSEL, 0, 0);
717 set_reg_key(config_key, keypath("DirectSound"), "DefaultSampleRate", DSound_Rates[selected_dsound_rate]);
719 break;
720 case IDC_DSOUND_BITS:
721 if (HIWORD(wParam) == CBN_SELCHANGE) {
722 int selected_dsound_bits;
723 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
724 selected_dsound_bits = SendDlgItemMessage(hDlg, IDC_DSOUND_BITS, CB_GETCURSEL, 0, 0);
725 set_reg_key(config_key, keypath("DirectSound"), "DefaultBitsPerSample", DSound_Bits[selected_dsound_bits]);
727 break;
728 case IDC_DSOUND_DRV_EMUL:
729 if (HIWORD(wParam) == BN_CLICKED) {
730 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
731 if (IsDlgButtonChecked(hDlg, IDC_DSOUND_DRV_EMUL) == BST_CHECKED)
732 set_reg_key(config_key, keypath("DirectSound"), "EmulDriver", "Y");
733 else
734 set_reg_key(config_key, keypath("DirectSound"), "EmulDriver", "N");
736 break;
738 break;
740 case WM_SHOWWINDOW:
741 set_window_title(hDlg);
742 break;
744 case WM_NOTIFY:
745 switch(((LPNMHDR)lParam)->code) {
746 case PSN_KILLACTIVE:
747 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
748 break;
749 case PSN_APPLY:
750 set_reg_key(config_key, "Drivers", "Audio", curAudioDriver);
751 apply();
752 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
753 break;
754 case PSN_SETACTIVE:
755 break;
756 case NM_CLICK:
757 if (((LPNMHDR)lParam)->idFrom == IDC_AUDIO_TREE)
759 TVHITTESTINFO ht;
760 DWORD dwPos = GetMessagePos();
761 HWND tree = ((LPNMHDR)lParam)->hwndFrom;
762 ZeroMemory(&ht, sizeof(ht));
763 ht.pt.x = (short)LOWORD(dwPos);
764 ht.pt.y = (short)HIWORD(dwPos);
765 MapWindowPoints(HWND_DESKTOP, tree, &ht.pt, 1);
766 SendMessageW( tree, TVM_HITTEST, 0, (LPARAM)&ht );
767 if (TVHT_ONITEMSTATEICON & ht.flags)
769 TVITEM tvItem;
770 int index;
771 ZeroMemory(&tvItem, sizeof(tvItem));
772 tvItem.hItem = ht.hItem;
773 SendMessageW( tree, TVM_GETITEMW, 0, (LPARAM) &tvItem );
775 index = TreeView_GetItemState(tree, ht.hItem, TVIS_STATEIMAGEMASK);
776 if (index == INDEXTOSTATEIMAGEMASK(1))
778 TreeView_SetItemState(tree, ht.hItem, INDEXTOSTATEIMAGEMASK(2), TVIS_STATEIMAGEMASK);
779 addDriver(loadedAudioDrv[tvItem.lParam & 0xff].szDriver);
780 SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM) hDlg, 0); /* enable apply button */
782 else if (index == INDEXTOSTATEIMAGEMASK(2))
784 TreeView_SetItemState(tree, ht.hItem, INDEXTOSTATEIMAGEMASK(1), TVIS_STATEIMAGEMASK);
785 removeDriver(loadedAudioDrv[tvItem.lParam & 0xff].szDriver);
786 SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM) hDlg, 0); /* enable apply button */
790 break;
791 case NM_RCLICK:
792 if (((LPNMHDR)lParam)->idFrom == IDC_AUDIO_TREE)
794 TVHITTESTINFO ht;
795 DWORD dwPos = GetMessagePos();
796 HWND tree = ((LPNMHDR)lParam)->hwndFrom;
797 POINT pt;
798 ZeroMemory(&ht, sizeof(ht));
799 pt.x = (short)LOWORD(dwPos);
800 pt.y = (short)HIWORD(dwPos);
801 ht.pt = pt;
802 MapWindowPoints(HWND_DESKTOP, tree, &ht.pt, 1);
803 SendMessageW( tree, TVM_HITTEST, 0, (LPARAM)&ht );
804 if (TVHT_ONITEMLABEL & ht.flags)
806 TVITEM tvItem;
807 ZeroMemory(&tvItem, sizeof(tvItem));
808 tvItem.hItem = ht.hItem;
809 tvItem.mask = TVIF_PARAM;
810 tvItem.lParam = -1;
811 if (TreeView_GetItem(tree, &tvItem))
813 if (tvItem.lParam & DRIVER_MASK)
815 if (hPopupMenus)
817 TrackPopupMenu(GetSubMenu(hPopupMenus, 0), TPM_RIGHTBUTTON, pt.x, pt.y, 0, tree, NULL);
818 toConfigure = tvItem.lParam & ~DRIVER_MASK;
821 else if (tvItem.lParam & DEVICE_MASK)
823 /* FIXME TBD */
830 break;
832 case WM_INITDIALOG:
833 initAudioDlg(hDlg);
834 break;
837 return FALSE;