push 3ea7f427b854582f33bb4f72399138cb53b12d0c
[wine/hacks.git] / programs / winecfg / audio.c
blobc082cdb14161433ced8ac323833c0858a62e2aa4
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_PULSE, "pulse"},
92 {IDS_DRIVER_ALSA, "alsa"},
93 {IDS_DRIVER_OSS, "oss"},
94 {IDS_DRIVER_COREAUDIO, "coreaudio"},
95 {IDS_DRIVER_JACK, "jack"},
96 #if 0
97 {IDS_DRIVER_NAS, "nas"},
98 #endif
99 {IDS_DRIVER_ESOUND, "esd"},
100 {IDS_DRIVER_AUDIOIO, "audioio"},
101 {0, ""}
104 /* list of available drivers */
105 static AUDIO_DRIVER * loadedAudioDrv;
107 /* local copy of registry setting */
108 static char curAudioDriver[1024];
110 /* driver index to configure */
111 static int toConfigure;
113 /* display a driver specific configuration dialog */
114 static void configureAudioDriver(HWND hDlg)
116 const AUDIO_DRIVER *pAudioDrv = &loadedAudioDrv[toConfigure];
118 if (strlen(pAudioDrv->szDriver) != 0)
120 HDRVR hdrvr;
121 char wine_driver[MAX_NAME_LENGTH + 9];
122 sprintf(wine_driver, "wine%s.drv", pAudioDrv->szDriver);
123 hdrvr = OpenDriverA(wine_driver, 0, 0);
124 if (hdrvr != 0)
126 if (SendDriverMessage(hdrvr, DRV_QUERYCONFIGURE, 0, 0) != 0)
128 DRVCONFIGINFO dci;
129 LONG lRes;
130 dci.dwDCISize = sizeof (dci);
131 dci.lpszDCISectionName = NULL;
132 dci.lpszDCIAliasName = NULL;
133 lRes = SendDriverMessage(hdrvr, DRV_CONFIGURE, 0, (LONG_PTR)&dci);
135 CloseDriver(hdrvr, 0, 0);
137 else
139 WCHAR wine_driverW[MAX_NAME_LENGTH+9];
140 WCHAR messageStr[256];
141 WCHAR str[1024];
143 MultiByteToWideChar (CP_ACP, 0, wine_driver, -1, wine_driverW,
144 sizeof (wine_driverW)/sizeof(wine_driverW[0]));
146 LoadStringW (GetModuleHandle (NULL), IDS_OPEN_DRIVER_ERROR, messageStr,
147 sizeof(messageStr)/sizeof(messageStr[0]));
148 wsprintfW (str, messageStr, wine_driverW);
149 MessageBoxW (hDlg, str, NULL, MB_OK | MB_ICONERROR);
154 /* is driver in local copy of driver registry string */
155 static BOOL isDriverSet(const char * driver)
157 WINE_TRACE("driver = %s, curAudioDriver = %s\n", driver, curAudioDriver);
159 if (strstr(curAudioDriver, driver))
160 return TRUE;
162 return FALSE;
165 /* add driver to local copy of driver registry string */
166 static void addDriver(const char * driver)
168 if (!isDriverSet(driver))
170 if (strlen(curAudioDriver))
171 strcat(curAudioDriver, ",");
172 strcat(curAudioDriver, driver);
176 /* remove driver from local copy of driver registry string */
177 static void removeDriver(const char * driver)
179 char pattern[32], *p;
180 int drvlen, listlen;
182 strcpy(pattern, ",");
183 strcat(pattern, driver);
184 strcat(pattern, ",");
185 drvlen = strlen(driver);
186 listlen = strlen(curAudioDriver);
188 p = strstr(curAudioDriver, pattern);
189 if (p) /* somewhere in the middle */
190 memmove(p, p+drvlen+1, strlen(p+drvlen+1)+1);
191 else if (!strncmp(curAudioDriver, pattern+1, drvlen+1)) /* the head */
192 memmove(curAudioDriver, curAudioDriver+drvlen+1, listlen-drvlen);
193 else if (!strncmp(curAudioDriver+listlen-drvlen-1, pattern, drvlen+1)) /* the tail */
194 curAudioDriver[listlen-drvlen-1] = 0;
195 else if (!strcmp(curAudioDriver, driver)) /* only one entry (head&tail) */
196 curAudioDriver[0] = 0;
197 else
198 WINE_FIXME("driver '%s' is not in the list, please report!\n", driver);
201 static void initAudioDeviceTree(HWND hDlg)
203 const AUDIO_DRIVER *pAudioDrv = NULL;
204 int i, j;
205 TVINSERTSTRUCTW insert;
206 HTREEITEM root, driver[10];
207 HWND tree = NULL;
208 HIMAGELIST hImageList;
209 HBITMAP hBitMap;
210 HCURSOR old_cursor;
211 WCHAR driver_type[64], dev_type[64];
213 tree = GetDlgItem(hDlg, IDC_AUDIO_TREE);
215 if (!tree)
216 return;
218 /* set tree view style */
219 SetWindowLong(tree, GWL_STYLE, GetWindowLong(tree, GWL_STYLE) | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT);
221 /* state checkbox */
222 hImageList = ImageList_Create(16, 16, FALSE, 3, 0);
223 hBitMap = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_CHECKBOX));
224 ImageList_Add(hImageList, hBitMap, NULL);
225 DeleteObject(hBitMap);
226 SendMessageW( tree, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)hImageList );
228 /* root item */
229 LoadStringW (GetModuleHandle (NULL), IDS_SOUNDDRIVERS, driver_type,
230 sizeof(driver_type)/sizeof(driver_type[0]));
231 insert.hParent = TVI_ROOT;
232 insert.hInsertAfter = TVI_LAST;
233 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
234 insert.u.item.pszText = driver_type;
235 insert.u.item.cChildren = 1;
236 root = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
238 /* change to the wait cursor because this can take a while if there is a
239 * misbehaving driver that takes a long time to open
241 old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
243 /* iterate over list of loaded drivers */
244 for (pAudioDrv = loadedAudioDrv, i = 0; pAudioDrv->nameID; i++, pAudioDrv++) {
245 HDRVR hdrv;
246 char name[MAX_PATH];
247 WCHAR text[MAX_PATH];
249 sprintf(name, "wine%s.drv", pAudioDrv->szDriver);
250 LoadStringW (GetModuleHandle (NULL), pAudioDrv->nameID, text,
251 sizeof(text)/sizeof(text[0]));
253 if ((hdrv = OpenDriverA(name, 0, 0)))
255 HMODULE lib;
256 if ((lib = GetDriverModuleHandle(hdrv)))
258 int num_wod = 0, num_wid = 0, num_mod = 0, num_mid = 0, num_aux = 0, num_mxd = 0;
259 MessagePtr wodMessagePtr = (MessagePtr)GetProcAddress(lib, "wodMessage");
260 MessagePtr widMessagePtr = (MessagePtr)GetProcAddress(lib, "widMessage");
261 MessagePtr modMessagePtr = (MessagePtr)GetProcAddress(lib, "modMessage");
262 MessagePtr midMessagePtr = (MessagePtr)GetProcAddress(lib, "midMessage");
263 MessagePtr auxMessagePtr = (MessagePtr)GetProcAddress(lib, "auxMessage");
264 MessagePtr mxdMessagePtr = (MessagePtr)GetProcAddress(lib, "mxdMessage");
266 if (wodMessagePtr)
267 num_wod = wodMessagePtr(0, WODM_GETNUMDEVS, 0, 0, 0);
269 if (widMessagePtr)
270 num_wid = widMessagePtr(0, WIDM_GETNUMDEVS, 0, 0, 0);
272 if (modMessagePtr)
273 num_mod = modMessagePtr(0, MODM_GETNUMDEVS, 0, 0, 0);
275 if (midMessagePtr)
276 num_mid = midMessagePtr(0, MIDM_GETNUMDEVS, 0, 0, 0);
278 if (auxMessagePtr)
279 num_aux = auxMessagePtr(0, AUXDM_GETNUMDEVS, 0, 0, 0);
281 if (mxdMessagePtr)
282 num_mxd = mxdMessagePtr(0, MXDM_GETNUMDEVS, 0, 0, 0);
284 if (num_wod == 0 && num_wid == 0 && num_mod == 0 && num_mid == 0 && num_aux == 0 && num_mxd == 0)
286 insert.hParent = root;
287 insert.u.item.mask = TVIF_TEXT | TVIF_STATE | TVIF_PARAM;
288 insert.u.item.pszText = text;
289 insert.u.item.stateMask = TVIS_STATEIMAGEMASK;
290 insert.u.item.lParam = i + DRIVER_MASK;
291 if (isDriverSet(pAudioDrv->szDriver))
292 insert.u.item.state = INDEXTOSTATEIMAGEMASK(2);
293 else
294 insert.u.item.state = INDEXTOSTATEIMAGEMASK(1);
296 driver[i] = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
298 else
300 HTREEITEM type;
302 insert.hParent = root;
303 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN | TVIF_STATE | TVIF_PARAM;
304 insert.u.item.pszText = text;
305 insert.u.item.cChildren = 1;
306 insert.u.item.stateMask = TVIS_STATEIMAGEMASK;
307 insert.u.item.lParam = i + DRIVER_MASK;
309 if (isDriverSet(pAudioDrv->szDriver))
310 insert.u.item.state = INDEXTOSTATEIMAGEMASK(2);
311 else
312 insert.u.item.state = INDEXTOSTATEIMAGEMASK(1);
314 driver[i] = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
316 if (num_wod)
318 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_WAVEOUT, dev_type,
319 sizeof(dev_type)/sizeof(dev_type[0]));
321 insert.hParent = driver[i];
322 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
323 insert.u.item.pszText = dev_type;
324 insert.u.item.cChildren = 1;
326 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
328 for (j = 0; j < num_wod; j++)
330 WAVEOUTCAPSW caps;
332 wodMessagePtr(j, WODM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
334 insert.hParent = type;
335 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
336 insert.u.item.pszText = caps.szPname;
337 insert.u.item.lParam = j + DEVICE_MASK;
339 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
343 if (num_wid)
345 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_WAVEIN, dev_type,
346 sizeof(dev_type)/sizeof(dev_type[0]));
348 insert.hParent = driver[i];
349 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
350 insert.u.item.pszText = dev_type;
351 insert.u.item.cChildren = 1;
353 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
355 for (j = 0; j < num_wid; j++)
357 WAVEINCAPSW caps;
359 widMessagePtr(j, WIDM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
361 insert.hParent = type;
362 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
363 insert.u.item.pszText = caps.szPname;
364 insert.u.item.lParam = j + DEVICE_MASK;
366 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
370 if (num_mod)
372 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_MIDIOUT, dev_type,
373 sizeof(dev_type)/sizeof(dev_type[0]));
375 insert.hParent = driver[i];
376 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
377 insert.u.item.pszText = dev_type;
378 insert.u.item.cChildren = 1;
380 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
382 for (j = 0; j < num_mod; j++)
384 MIDIOUTCAPSW caps;
386 modMessagePtr(j, MODM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
388 insert.hParent = type;
389 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
390 insert.u.item.pszText = caps.szPname;
391 insert.u.item.lParam = j + DEVICE_MASK;
393 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
397 if (num_mid)
399 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_MIDIIN, dev_type,
400 sizeof(dev_type)/sizeof(dev_type[0]));
402 insert.hParent = driver[i];
403 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
404 insert.u.item.pszText = dev_type;
405 insert.u.item.cChildren = 1;
407 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
409 for (j = 0; j < num_mid; j++)
411 MIDIINCAPSW caps;
413 midMessagePtr(j, MIDM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
415 insert.hParent = type;
416 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
417 insert.u.item.pszText = caps.szPname;
418 insert.u.item.lParam = j + DEVICE_MASK;
420 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
424 if (num_aux)
426 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_AUX, dev_type,
427 sizeof(dev_type)/sizeof(dev_type[0]));
429 insert.hParent = driver[i];
430 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
431 insert.u.item.pszText = dev_type;
432 insert.u.item.cChildren = 1;
434 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
436 for (j = 0; j < num_aux; j++)
438 AUXCAPSW caps;
440 auxMessagePtr(j, AUXDM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
442 insert.hParent = type;
443 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
444 insert.u.item.pszText = caps.szPname;
445 insert.u.item.lParam = j + DEVICE_MASK;
447 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
451 if (num_mxd)
453 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_MIXER, dev_type,
454 sizeof(dev_type)/sizeof(dev_type[0]));
456 insert.hParent = driver[i];
457 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
458 insert.u.item.pszText = dev_type;
459 insert.u.item.cChildren = 1;
461 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
463 for (j = 0; j < num_mxd; j++)
465 MIXERCAPSW caps;
467 mxdMessagePtr(j, MXDM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
469 insert.hParent = type;
470 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
471 insert.u.item.pszText = caps.szPname;
472 insert.u.item.lParam = j + DEVICE_MASK;
474 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
479 CloseDriver(hdrv, 0, 0);
483 /* restore the original cursor */
484 SetCursor(old_cursor);
486 SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_SELECTITEM, 0, 0);
487 SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_EXPAND, TVE_EXPAND, (LPARAM)root);
488 for (j = 0; j < i; j++)
489 SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_EXPAND, TVE_EXPAND, (LPARAM)driver[j]);
492 /* find all drivers that can be loaded */
493 static void findAudioDrivers(void)
495 int numFound = 0;
496 const AUDIO_DRIVER *pAudioDrv = NULL;
497 HCURSOR old_cursor;
499 /* delete an existing list */
500 HeapFree(GetProcessHeap(), 0, loadedAudioDrv);
501 loadedAudioDrv = 0;
503 /* change to the wait cursor because this can take a while if there is a
504 * misbehaving driver that takes a long time to open
506 old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
508 for (pAudioDrv = sAudioDrivers; pAudioDrv->nameID; pAudioDrv++)
510 if (strlen(pAudioDrv->szDriver))
512 HDRVR hdrv;
513 char driver[MAX_PATH];
515 sprintf(driver, "wine%s.drv", pAudioDrv->szDriver);
517 if ((hdrv = OpenDriverA(driver, 0, 0)))
519 CloseDriver(hdrv, 0, 0);
521 if (loadedAudioDrv)
522 loadedAudioDrv = HeapReAlloc(GetProcessHeap(), 0, loadedAudioDrv, (numFound + 1) * sizeof(AUDIO_DRIVER));
523 else
524 loadedAudioDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(AUDIO_DRIVER));
526 CopyMemory(&loadedAudioDrv[numFound], pAudioDrv, sizeof(AUDIO_DRIVER));
527 numFound++;
532 /* restore the original cursor */
533 SetCursor(old_cursor);
535 /* terminate list with empty driver */
536 if (numFound) {
537 loadedAudioDrv = HeapReAlloc(GetProcessHeap(), 0, loadedAudioDrv, (numFound + 1) * sizeof(AUDIO_DRIVER));
538 CopyMemory(&loadedAudioDrv[numFound], pAudioDrv, sizeof(AUDIO_DRIVER));
539 } else {
540 loadedAudioDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(AUDIO_DRIVER));
541 CopyMemory(&loadedAudioDrv[0], pAudioDrv, sizeof(AUDIO_DRIVER));
545 /* check local copy of registry string for unloadable drivers */
546 static void checkRegistrySetting(HWND hDlg)
548 const AUDIO_DRIVER *pAudioDrv;
549 char * token, * tokens;
551 tokens = HeapAlloc(GetProcessHeap(), 0, strlen(curAudioDriver)+1);
552 strcpy(tokens, curAudioDriver);
554 start_over:
555 token = strtok(tokens, ",");
556 while (token != NULL)
558 BOOL found = FALSE;
559 for (pAudioDrv = loadedAudioDrv; pAudioDrv->nameID; pAudioDrv++)
561 if (strcmp(token, pAudioDrv->szDriver) == 0)
563 found = TRUE;
564 break;
567 if (found == FALSE)
569 WCHAR tokenW[MAX_NAME_LENGTH+1];
570 WCHAR messageStr[256];
571 WCHAR str[1024];
572 WCHAR caption[64];
574 MultiByteToWideChar (CP_ACP, 0, token, -1, tokenW, sizeof(tokenW)/sizeof(tokenW[0]));
576 LoadStringW (GetModuleHandle (NULL), IDS_UNAVAILABLE_DRIVER, messageStr,
577 sizeof(messageStr)/sizeof(messageStr[0]));
578 wsprintfW (str, messageStr, tokenW);
579 LoadStringW (GetModuleHandle (NULL), IDS_WARNING, caption,
580 sizeof(caption)/sizeof(caption[0]));
581 if (MessageBoxW (hDlg, str, caption, MB_ICONWARNING | MB_YESNOCANCEL) == IDYES)
583 removeDriver(token);
584 strcpy(tokens, curAudioDriver);
585 goto start_over;
588 token = strtok(NULL, ",");
590 HeapFree(GetProcessHeap(), 0, tokens);
593 static void selectDriver(HWND hDlg, const char * driver)
595 WCHAR text[1024];
596 WCHAR caption[64];
598 strcpy(curAudioDriver, driver);
599 set_reg_key(config_key, "Drivers", "Audio", curAudioDriver);
601 if (LoadStringW(GetModuleHandle(NULL), IDS_AUDIO_MISSING, text, sizeof(text)/sizeof(text[0])))
603 if (LoadStringW(GetModuleHandle(NULL), IDS_WINECFG_TITLE, caption, sizeof(caption)/sizeof(caption[0])))
604 MessageBoxW(hDlg, text, caption, MB_OK | MB_ICONINFORMATION);
607 SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM) hDlg, 0); /* enable apply button */
610 static void initAudioDlg (HWND hDlg)
612 int i;
613 char* buf = NULL;
615 WINE_TRACE("\n");
617 /* make a list of all drivers that can be loaded */
618 findAudioDrivers();
620 /* get current registry setting if available */
621 buf = get_reg_key(config_key, "Drivers", "Audio", NULL);
623 /* check for first time install and set a default driver
624 * select first available driver, and if that fails: none
626 if (buf == NULL)
628 /* select first available driver */
629 if (*loadedAudioDrv->szDriver)
630 selectDriver(hDlg, loadedAudioDrv->szDriver);
632 else /* make a local copy of the current registry setting */
633 strcpy(curAudioDriver, buf);
635 WINE_TRACE("curAudioDriver = %s\n", curAudioDriver);
637 /* check for drivers that can't be loaded */
638 checkRegistrySetting(hDlg);
640 initAudioDeviceTree(hDlg);
642 SendDlgItemMessage(hDlg, IDC_DSOUND_HW_ACCEL, CB_RESETCONTENT, 0, 0);
643 for (i = 0; 0 != DSound_HW_Accels[i].displayID; ++i) {
644 WCHAR accelStr[64];
645 LoadStringW (GetModuleHandle (NULL), DSound_HW_Accels[i].displayID, accelStr,
646 sizeof(accelStr)/sizeof(accelStr[0]));
647 SendDlgItemMessageW (hDlg, IDC_DSOUND_HW_ACCEL, CB_ADDSTRING, 0, (LPARAM)accelStr);
649 buf = get_reg_key(config_key, keypath("DirectSound"), "HardwareAcceleration", "Full");
650 for (i = 0; NULL != DSound_HW_Accels[i].settingStr; ++i) {
651 if (strcmp(buf, DSound_HW_Accels[i].settingStr) == 0) {
652 SendDlgItemMessage(hDlg, IDC_DSOUND_HW_ACCEL, CB_SETCURSEL, i, 0);
653 break ;
656 if (NULL == DSound_HW_Accels[i].settingStr) {
657 WINE_ERR("Invalid Direct Sound HW Accel read from registry (%s)\n", buf);
659 HeapFree(GetProcessHeap(), 0, buf);
661 SendDlgItemMessage(hDlg, IDC_DSOUND_RATES, CB_RESETCONTENT, 0, 0);
662 for (i = 0; NULL != DSound_Rates[i]; ++i) {
663 SendDlgItemMessage(hDlg, IDC_DSOUND_RATES, CB_ADDSTRING, 0, (LPARAM) DSound_Rates[i]);
665 buf = get_reg_key(config_key, keypath("DirectSound"), "DefaultSampleRate", "44100");
666 for (i = 0; NULL != DSound_Rates[i]; ++i) {
667 if (strcmp(buf, DSound_Rates[i]) == 0) {
668 SendDlgItemMessage(hDlg, IDC_DSOUND_RATES, CB_SETCURSEL, i, 0);
669 break ;
673 SendDlgItemMessage(hDlg, IDC_DSOUND_BITS, CB_RESETCONTENT, 0, 0);
674 for (i = 0; NULL != DSound_Bits[i]; ++i) {
675 SendDlgItemMessage(hDlg, IDC_DSOUND_BITS, CB_ADDSTRING, 0, (LPARAM) DSound_Bits[i]);
677 buf = get_reg_key(config_key, keypath("DirectSound"), "DefaultBitsPerSample", "16");
678 for (i = 0; NULL != DSound_Bits[i]; ++i) {
679 if (strcmp(buf, DSound_Bits[i]) == 0) {
680 SendDlgItemMessage(hDlg, IDC_DSOUND_BITS, CB_SETCURSEL, i, 0);
681 break ;
685 buf = get_reg_key(config_key, keypath("DirectSound"), "EmulDriver", "N");
686 if (IS_OPTION_TRUE(*buf))
687 CheckDlgButton(hDlg, IDC_DSOUND_DRV_EMUL, BST_CHECKED);
688 else
689 CheckDlgButton(hDlg, IDC_DSOUND_DRV_EMUL, BST_UNCHECKED);
690 HeapFree(GetProcessHeap(), 0, buf);
693 INT_PTR CALLBACK
694 AudioDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
696 switch (uMsg) {
697 case WM_COMMAND:
698 switch (LOWORD(wParam)) {
699 case IDC_AUDIO_CONFIGURE:
700 configureAudioDriver(hDlg);
701 break;
702 case IDC_AUDIO_TEST:
703 if(!PlaySound(MAKEINTRESOURCE(IDW_TESTSOUND), NULL, SND_RESOURCE | SND_SYNC))
704 MessageBox(NULL, "Audio test failed!", "Error", MB_OK | MB_ICONERROR);
705 break;
706 case IDC_AUDIO_CONTROL_PANEL:
707 MessageBox(NULL, "Launching audio control panel not implemented yet!", "Fixme", MB_OK | MB_ICONERROR);
708 break;
709 case IDC_DSOUND_HW_ACCEL:
710 if (HIWORD(wParam) == CBN_SELCHANGE) {
711 int selected_dsound_accel;
712 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
713 selected_dsound_accel = SendDlgItemMessage(hDlg, IDC_DSOUND_HW_ACCEL, CB_GETCURSEL, 0, 0);
714 set_reg_key(config_key, keypath("DirectSound"), "HardwareAcceleration",
715 DSound_HW_Accels[selected_dsound_accel].settingStr);
717 break;
718 case IDC_DSOUND_RATES:
719 if (HIWORD(wParam) == CBN_SELCHANGE) {
720 int selected_dsound_rate;
721 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
722 selected_dsound_rate = SendDlgItemMessage(hDlg, IDC_DSOUND_RATES, CB_GETCURSEL, 0, 0);
723 set_reg_key(config_key, keypath("DirectSound"), "DefaultSampleRate", DSound_Rates[selected_dsound_rate]);
725 break;
726 case IDC_DSOUND_BITS:
727 if (HIWORD(wParam) == CBN_SELCHANGE) {
728 int selected_dsound_bits;
729 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
730 selected_dsound_bits = SendDlgItemMessage(hDlg, IDC_DSOUND_BITS, CB_GETCURSEL, 0, 0);
731 set_reg_key(config_key, keypath("DirectSound"), "DefaultBitsPerSample", DSound_Bits[selected_dsound_bits]);
733 break;
734 case IDC_DSOUND_DRV_EMUL:
735 if (HIWORD(wParam) == BN_CLICKED) {
736 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
737 if (IsDlgButtonChecked(hDlg, IDC_DSOUND_DRV_EMUL) == BST_CHECKED)
738 set_reg_key(config_key, keypath("DirectSound"), "EmulDriver", "Y");
739 else
740 set_reg_key(config_key, keypath("DirectSound"), "EmulDriver", "N");
742 break;
744 break;
746 case WM_SHOWWINDOW:
747 set_window_title(hDlg);
748 break;
750 case WM_NOTIFY:
751 switch(((LPNMHDR)lParam)->code) {
752 case PSN_KILLACTIVE:
753 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
754 break;
755 case PSN_APPLY:
756 set_reg_key(config_key, "Drivers", "Audio", curAudioDriver);
757 apply();
758 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
759 break;
760 case PSN_SETACTIVE:
761 break;
762 case NM_CLICK:
763 if (((LPNMHDR)lParam)->idFrom == IDC_AUDIO_TREE)
765 TVHITTESTINFO ht;
766 DWORD dwPos = GetMessagePos();
767 HWND tree = ((LPNMHDR)lParam)->hwndFrom;
768 ZeroMemory(&ht, sizeof(ht));
769 ht.pt.x = (short)LOWORD(dwPos);
770 ht.pt.y = (short)HIWORD(dwPos);
771 MapWindowPoints(HWND_DESKTOP, tree, &ht.pt, 1);
772 SendMessageW( tree, TVM_HITTEST, 0, (LPARAM)&ht );
773 if (TVHT_ONITEMSTATEICON & ht.flags)
775 TVITEM tvItem;
776 int index;
777 ZeroMemory(&tvItem, sizeof(tvItem));
778 tvItem.hItem = ht.hItem;
779 SendMessageW( tree, TVM_GETITEMW, 0, (LPARAM) &tvItem );
781 index = TreeView_GetItemState(tree, ht.hItem, TVIS_STATEIMAGEMASK);
782 if (index == INDEXTOSTATEIMAGEMASK(1))
784 TreeView_SetItemState(tree, ht.hItem, INDEXTOSTATEIMAGEMASK(2), TVIS_STATEIMAGEMASK);
785 addDriver(loadedAudioDrv[tvItem.lParam & 0xff].szDriver);
786 SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM) hDlg, 0); /* enable apply button */
788 else if (index == INDEXTOSTATEIMAGEMASK(2))
790 TreeView_SetItemState(tree, ht.hItem, INDEXTOSTATEIMAGEMASK(1), TVIS_STATEIMAGEMASK);
791 removeDriver(loadedAudioDrv[tvItem.lParam & 0xff].szDriver);
792 SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM) hDlg, 0); /* enable apply button */
796 break;
797 case NM_RCLICK:
798 if (((LPNMHDR)lParam)->idFrom == IDC_AUDIO_TREE)
800 TVHITTESTINFO ht;
801 DWORD dwPos = GetMessagePos();
802 HWND tree = ((LPNMHDR)lParam)->hwndFrom;
803 POINT pt;
804 ZeroMemory(&ht, sizeof(ht));
805 pt.x = (short)LOWORD(dwPos);
806 pt.y = (short)HIWORD(dwPos);
807 ht.pt = pt;
808 MapWindowPoints(HWND_DESKTOP, tree, &ht.pt, 1);
809 SendMessageW( tree, TVM_HITTEST, 0, (LPARAM)&ht );
810 if (TVHT_ONITEMLABEL & ht.flags)
812 TVITEM tvItem;
813 ZeroMemory(&tvItem, sizeof(tvItem));
814 tvItem.hItem = ht.hItem;
815 tvItem.mask = TVIF_PARAM;
816 tvItem.lParam = -1;
817 if (TreeView_GetItem(tree, &tvItem))
819 if (tvItem.lParam & DRIVER_MASK)
821 if (hPopupMenus)
823 TrackPopupMenu(GetSubMenu(hPopupMenus, 0), TPM_RIGHTBUTTON, pt.x, pt.y, 0, tree, NULL);
824 toConfigure = tvItem.lParam & ~DRIVER_MASK;
827 else if (tvItem.lParam & DEVICE_MASK)
829 /* FIXME TBD */
836 break;
838 case WM_INITDIALOG:
839 initAudioDlg(hDlg);
840 break;
843 return FALSE;