ieframe: Moved dialog resources to ieframe.
[wine/testsucceed.git] / programs / winecfg / audio.c
blobeacfa6f0f00af7feee93958c592f0d475e82f20c
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_PTR, DWORD_PTR, DWORD_PTR);
56 static struct DSOUNDACCEL
58 UINT displayID;
59 UINT visible;
60 const char* settingStr;
61 } DSound_HW_Accels[] = {
62 {IDS_ACCEL_FULL, 1, "Full"},
63 {IDS_ACCEL_STANDARD, 0, "Standard"},
64 {IDS_ACCEL_BASIC, 0, "Basic"},
65 {IDS_ACCEL_EMULATION, 1, "Emulation"},
66 {0, 0, 0}
69 static const char* DSound_Rates[] = {
70 "48000",
71 "44100",
72 "22050",
73 "16000",
74 "11025",
75 "8000",
76 NULL
79 static const char* DSound_Bits[] = {
80 "8",
81 "16",
82 NULL
85 typedef struct
87 UINT nameID;
88 const char *szDriver;
89 HDRVR hDriver;
90 } AUDIO_DRIVER;
92 static AUDIO_DRIVER sAudioDrivers[] = {
93 {IDS_DRIVER_ALSA, "alsa"},
94 {IDS_DRIVER_OSS, "oss"},
95 {IDS_DRIVER_COREAUDIO, "coreaudio"},
96 {0, ""}
99 /* list of available drivers */
100 static AUDIO_DRIVER * loadedAudioDrv;
102 /* local copy of registry setting */
103 static char curAudioDriver[1024];
105 /* driver index to configure */
106 static int toConfigure;
108 /* display a driver specific configuration dialog */
109 static void configureAudioDriver(HWND hDlg)
111 const AUDIO_DRIVER *pAudioDrv = &loadedAudioDrv[toConfigure];
113 if (strlen(pAudioDrv->szDriver) != 0)
115 HDRVR hdrvr;
116 char wine_driver[MAX_NAME_LENGTH + 9];
117 sprintf(wine_driver, "wine%s.drv", pAudioDrv->szDriver);
118 hdrvr = pAudioDrv->hDriver;
119 if (hdrvr != 0)
121 if (SendDriverMessage(hdrvr, DRV_QUERYCONFIGURE, 0, 0) != 0)
123 DRVCONFIGINFO dci;
124 dci.dwDCISize = sizeof (dci);
125 dci.lpszDCISectionName = NULL;
126 dci.lpszDCIAliasName = NULL;
127 SendDriverMessage(hdrvr, DRV_CONFIGURE, 0, (LONG_PTR)&dci);
130 else
132 WCHAR wine_driverW[MAX_NAME_LENGTH+9];
133 WCHAR messageStr[256];
134 WCHAR str[1024];
136 MultiByteToWideChar (CP_ACP, 0, wine_driver, -1, wine_driverW,
137 sizeof (wine_driverW)/sizeof(wine_driverW[0]));
139 LoadStringW (GetModuleHandle (NULL), IDS_OPEN_DRIVER_ERROR, messageStr,
140 sizeof(messageStr)/sizeof(messageStr[0]));
141 wsprintfW (str, messageStr, wine_driverW);
142 MessageBoxW (hDlg, str, NULL, MB_OK | MB_ICONERROR);
147 /* is driver in local copy of driver registry string */
148 static BOOL isDriverSet(const char * driver)
150 WINE_TRACE("driver = %s, curAudioDriver = %s\n", driver, curAudioDriver);
152 if (strstr(curAudioDriver, driver))
153 return TRUE;
155 return FALSE;
158 /* add driver to local copy of driver registry string */
159 static void addDriver(const char * driver)
161 if (!isDriverSet(driver))
163 if (strlen(curAudioDriver))
164 strcat(curAudioDriver, ",");
165 strcat(curAudioDriver, driver);
169 /* remove driver from local copy of driver registry string */
170 static void removeDriver(const char * driver)
172 char pattern[32], *p;
173 int drvlen, listlen;
175 strcpy(pattern, ",");
176 strcat(pattern, driver);
177 strcat(pattern, ",");
178 drvlen = strlen(driver);
179 listlen = strlen(curAudioDriver);
181 p = strstr(curAudioDriver, pattern);
182 if (p) /* somewhere in the middle */
183 memmove(p, p+drvlen+1, strlen(p+drvlen+1)+1);
184 else if (!strncmp(curAudioDriver, pattern+1, drvlen+1)) /* the head */
185 memmove(curAudioDriver, curAudioDriver+drvlen+1, listlen-drvlen);
186 else if (!strncmp(curAudioDriver+listlen-drvlen-1, pattern, drvlen+1)) /* the tail */
187 curAudioDriver[listlen-drvlen-1] = 0;
188 else if (!strcmp(curAudioDriver, driver)) /* only one entry (head&tail) */
189 curAudioDriver[0] = 0;
190 else
191 WINE_FIXME("driver '%s' is not in the list, please report!\n", driver);
194 static void initAudioDeviceTree(HWND hDlg)
196 AUDIO_DRIVER *pAudioDrv = NULL;
197 int i, j;
198 TVINSERTSTRUCTW insert;
199 HTREEITEM root, driver[10];
200 HWND tree = NULL;
201 HIMAGELIST hImageList;
202 HBITMAP hBitMap;
203 HCURSOR old_cursor;
204 WCHAR driver_type[64], dev_type[64];
206 tree = GetDlgItem(hDlg, IDC_AUDIO_TREE);
208 if (!tree)
209 return;
211 /* set tree view style */
212 SetWindowLong(tree, GWL_STYLE, GetWindowLong(tree, GWL_STYLE) | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT);
214 /* state checkbox */
215 hImageList = ImageList_Create(16, 16, FALSE, 3, 0);
216 hBitMap = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_CHECKBOX));
217 ImageList_Add(hImageList, hBitMap, NULL);
218 DeleteObject(hBitMap);
219 SendMessageW( tree, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)hImageList );
221 /* root item */
222 LoadStringW (GetModuleHandle (NULL), IDS_SOUNDDRIVERS, driver_type,
223 sizeof(driver_type)/sizeof(driver_type[0]));
224 insert.hParent = TVI_ROOT;
225 insert.hInsertAfter = TVI_LAST;
226 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
227 insert.u.item.pszText = driver_type;
228 insert.u.item.cChildren = 1;
229 root = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
231 /* change to the wait cursor because this can take a while if there is a
232 * misbehaving driver that takes a long time to open
234 old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
236 /* iterate over list of loaded drivers */
237 for (pAudioDrv = loadedAudioDrv, i = 0; pAudioDrv->nameID; i++, pAudioDrv++) {
238 HDRVR hdrv;
239 char name[MAX_PATH];
240 WCHAR text[MAX_PATH];
242 sprintf(name, "wine%s.drv", pAudioDrv->szDriver);
243 LoadStringW (GetModuleHandle (NULL), pAudioDrv->nameID, text,
244 sizeof(text)/sizeof(text[0]));
246 if ((hdrv = pAudioDrv->hDriver))
248 HMODULE lib;
249 if ((lib = GetDriverModuleHandle(hdrv)))
251 int num_wod = 0, num_wid = 0, num_mod = 0, num_mid = 0, num_aux = 0, num_mxd = 0;
252 MessagePtr wodMessagePtr = (MessagePtr)GetProcAddress(lib, "wodMessage");
253 MessagePtr widMessagePtr = (MessagePtr)GetProcAddress(lib, "widMessage");
254 MessagePtr modMessagePtr = (MessagePtr)GetProcAddress(lib, "modMessage");
255 MessagePtr midMessagePtr = (MessagePtr)GetProcAddress(lib, "midMessage");
256 MessagePtr auxMessagePtr = (MessagePtr)GetProcAddress(lib, "auxMessage");
257 MessagePtr mxdMessagePtr = (MessagePtr)GetProcAddress(lib, "mxdMessage");
259 if (wodMessagePtr)
260 num_wod = wodMessagePtr(0, WODM_GETNUMDEVS, 0, 0, 0);
262 if (widMessagePtr)
263 num_wid = widMessagePtr(0, WIDM_GETNUMDEVS, 0, 0, 0);
265 if (modMessagePtr)
266 num_mod = modMessagePtr(0, MODM_GETNUMDEVS, 0, 0, 0);
268 if (midMessagePtr)
269 num_mid = midMessagePtr(0, MIDM_GETNUMDEVS, 0, 0, 0);
271 if (auxMessagePtr)
272 num_aux = auxMessagePtr(0, AUXDM_GETNUMDEVS, 0, 0, 0);
274 if (mxdMessagePtr)
275 num_mxd = mxdMessagePtr(0, MXDM_GETNUMDEVS, 0, 0, 0);
277 if (num_wod == 0 && num_wid == 0 && num_mod == 0 && num_mid == 0 && num_aux == 0 && num_mxd == 0)
279 insert.hParent = root;
280 insert.u.item.mask = TVIF_TEXT | TVIF_STATE | TVIF_PARAM;
281 insert.u.item.pszText = text;
282 insert.u.item.stateMask = TVIS_STATEIMAGEMASK;
283 insert.u.item.lParam = i + DRIVER_MASK;
284 if (isDriverSet(pAudioDrv->szDriver))
285 insert.u.item.state = INDEXTOSTATEIMAGEMASK(2);
286 else
287 insert.u.item.state = INDEXTOSTATEIMAGEMASK(1);
289 driver[i] = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
291 else
293 HTREEITEM type;
295 insert.hParent = root;
296 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN | TVIF_STATE | TVIF_PARAM;
297 insert.u.item.pszText = text;
298 insert.u.item.cChildren = 1;
299 insert.u.item.stateMask = TVIS_STATEIMAGEMASK;
300 insert.u.item.lParam = i + DRIVER_MASK;
302 if (isDriverSet(pAudioDrv->szDriver))
303 insert.u.item.state = INDEXTOSTATEIMAGEMASK(2);
304 else
305 insert.u.item.state = INDEXTOSTATEIMAGEMASK(1);
307 driver[i] = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
309 if (num_wod)
311 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_WAVEOUT, dev_type,
312 sizeof(dev_type)/sizeof(dev_type[0]));
314 insert.hParent = driver[i];
315 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
316 insert.u.item.pszText = dev_type;
317 insert.u.item.cChildren = 1;
319 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
321 for (j = 0; j < num_wod; j++)
323 WAVEOUTCAPSW caps;
325 wodMessagePtr(j, WODM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
327 insert.hParent = type;
328 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
329 insert.u.item.pszText = caps.szPname;
330 insert.u.item.lParam = j + DEVICE_MASK;
332 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
336 if (num_wid)
338 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_WAVEIN, dev_type,
339 sizeof(dev_type)/sizeof(dev_type[0]));
341 insert.hParent = driver[i];
342 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
343 insert.u.item.pszText = dev_type;
344 insert.u.item.cChildren = 1;
346 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
348 for (j = 0; j < num_wid; j++)
350 WAVEINCAPSW caps;
352 widMessagePtr(j, WIDM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
354 insert.hParent = type;
355 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
356 insert.u.item.pszText = caps.szPname;
357 insert.u.item.lParam = j + DEVICE_MASK;
359 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
363 if (num_mod)
365 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_MIDIOUT, dev_type,
366 sizeof(dev_type)/sizeof(dev_type[0]));
368 insert.hParent = driver[i];
369 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
370 insert.u.item.pszText = dev_type;
371 insert.u.item.cChildren = 1;
373 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
375 for (j = 0; j < num_mod; j++)
377 MIDIOUTCAPSW caps;
379 modMessagePtr(j, MODM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
381 insert.hParent = type;
382 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
383 insert.u.item.pszText = caps.szPname;
384 insert.u.item.lParam = j + DEVICE_MASK;
386 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
390 if (num_mid)
392 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_MIDIIN, dev_type,
393 sizeof(dev_type)/sizeof(dev_type[0]));
395 insert.hParent = driver[i];
396 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
397 insert.u.item.pszText = dev_type;
398 insert.u.item.cChildren = 1;
400 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
402 for (j = 0; j < num_mid; j++)
404 MIDIINCAPSW caps;
406 midMessagePtr(j, MIDM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
408 insert.hParent = type;
409 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
410 insert.u.item.pszText = caps.szPname;
411 insert.u.item.lParam = j + DEVICE_MASK;
413 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
417 if (num_aux)
419 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_AUX, dev_type,
420 sizeof(dev_type)/sizeof(dev_type[0]));
422 insert.hParent = driver[i];
423 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
424 insert.u.item.pszText = dev_type;
425 insert.u.item.cChildren = 1;
427 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
429 for (j = 0; j < num_aux; j++)
431 AUXCAPSW caps;
433 auxMessagePtr(j, AUXDM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
435 insert.hParent = type;
436 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
437 insert.u.item.pszText = caps.szPname;
438 insert.u.item.lParam = j + DEVICE_MASK;
440 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
444 if (num_mxd)
446 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_MIXER, dev_type,
447 sizeof(dev_type)/sizeof(dev_type[0]));
449 insert.hParent = driver[i];
450 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
451 insert.u.item.pszText = dev_type;
452 insert.u.item.cChildren = 1;
454 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
456 for (j = 0; j < num_mxd; j++)
458 MIXERCAPSW caps;
460 mxdMessagePtr(j, MXDM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
462 insert.hParent = type;
463 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
464 insert.u.item.pszText = caps.szPname;
465 insert.u.item.lParam = j + DEVICE_MASK;
467 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
475 /* restore the original cursor */
476 SetCursor(old_cursor);
478 SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_SELECTITEM, 0, 0);
479 SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_EXPAND, TVE_EXPAND, (LPARAM)root);
480 for (j = 0; j < i; j++)
481 SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_EXPAND, TVE_EXPAND, (LPARAM)driver[j]);
484 /* find all drivers that can be loaded */
485 static void findAudioDrivers(void)
487 int numFound = 0;
488 AUDIO_DRIVER *pAudioDrv = NULL;
489 HCURSOR old_cursor;
491 /* delete an existing list */
492 HeapFree(GetProcessHeap(), 0, loadedAudioDrv);
493 loadedAudioDrv = 0;
495 /* change to the wait cursor because this can take a while if there is a
496 * misbehaving driver that takes a long time to open
498 old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
500 for (pAudioDrv = sAudioDrivers; pAudioDrv->nameID; pAudioDrv++)
502 if (strlen(pAudioDrv->szDriver))
504 HDRVR hdrv;
505 char driver[MAX_PATH];
507 sprintf(driver, "wine%s.drv", pAudioDrv->szDriver);
509 hdrv = pAudioDrv->hDriver;
510 if (!pAudioDrv->hDriver && (hdrv = OpenDriverA(driver, 0, 0))) {
511 HMODULE lib = GetDriverModuleHandle(hdrv);
512 MessagePtr wodMessagePtr = (MessagePtr)GetProcAddress(lib, "wodMessage");
513 MessagePtr widMessagePtr = (MessagePtr)GetProcAddress(lib, "widMessage");
514 MessagePtr modMessagePtr = (MessagePtr)GetProcAddress(lib, "modMessage");
515 MessagePtr midMessagePtr = (MessagePtr)GetProcAddress(lib, "midMessage");
516 MessagePtr auxMessagePtr = (MessagePtr)GetProcAddress(lib, "auxMessage");
517 MessagePtr mxdMessagePtr = (MessagePtr)GetProcAddress(lib, "mxdMessage");
519 pAudioDrv->hDriver = hdrv;
521 if (wodMessagePtr)
522 wodMessagePtr(0, DRVM_INIT, 0, 0, 0);
524 if (widMessagePtr)
525 widMessagePtr(0, DRVM_INIT, 0, 0, 0);
527 if (modMessagePtr)
528 modMessagePtr(0, DRVM_INIT, 0, 0, 0);
530 if (midMessagePtr)
531 midMessagePtr(0, DRVM_INIT, 0, 0, 0);
533 if (auxMessagePtr)
534 auxMessagePtr(0, DRVM_INIT, 0, 0, 0);
536 if (mxdMessagePtr)
537 mxdMessagePtr(0, DRVM_INIT, 0, 0, 0);
539 if (hdrv)
541 if (loadedAudioDrv)
542 loadedAudioDrv = HeapReAlloc(GetProcessHeap(), 0, loadedAudioDrv, (numFound + 1) * sizeof(AUDIO_DRIVER));
543 else
544 loadedAudioDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(AUDIO_DRIVER));
546 CopyMemory(&loadedAudioDrv[numFound], pAudioDrv, sizeof(AUDIO_DRIVER));
547 numFound++;
552 /* restore the original cursor */
553 SetCursor(old_cursor);
555 /* terminate list with empty driver */
556 if (numFound) {
557 loadedAudioDrv = HeapReAlloc(GetProcessHeap(), 0, loadedAudioDrv, (numFound + 1) * sizeof(AUDIO_DRIVER));
558 CopyMemory(&loadedAudioDrv[numFound], pAudioDrv, sizeof(AUDIO_DRIVER));
559 } else {
560 loadedAudioDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(AUDIO_DRIVER));
561 CopyMemory(&loadedAudioDrv[0], pAudioDrv, sizeof(AUDIO_DRIVER));
565 /* check local copy of registry string for unloadable drivers */
566 static void checkRegistrySetting(HWND hDlg)
568 const AUDIO_DRIVER *pAudioDrv;
569 char * token, * tokens;
571 tokens = HeapAlloc(GetProcessHeap(), 0, strlen(curAudioDriver)+1);
572 strcpy(tokens, curAudioDriver);
574 start_over:
575 token = strtok(tokens, ",");
576 while (token != NULL)
578 BOOL found = FALSE;
579 for (pAudioDrv = loadedAudioDrv; pAudioDrv->nameID; pAudioDrv++)
581 if (strcmp(token, pAudioDrv->szDriver) == 0)
583 found = TRUE;
584 break;
587 if (found == FALSE)
589 WCHAR tokenW[MAX_NAME_LENGTH+1];
590 WCHAR messageStr[256];
591 WCHAR str[1024];
592 WCHAR caption[64];
594 MultiByteToWideChar (CP_ACP, 0, token, -1, tokenW, sizeof(tokenW)/sizeof(tokenW[0]));
596 LoadStringW (GetModuleHandle (NULL), IDS_UNAVAILABLE_DRIVER, messageStr,
597 sizeof(messageStr)/sizeof(messageStr[0]));
598 wsprintfW (str, messageStr, tokenW);
599 LoadStringW (GetModuleHandle (NULL), IDS_WARNING, caption,
600 sizeof(caption)/sizeof(caption[0]));
601 if (MessageBoxW (hDlg, str, caption, MB_ICONWARNING | MB_YESNOCANCEL) == IDYES)
603 removeDriver(token);
604 strcpy(tokens, curAudioDriver);
605 goto start_over;
608 token = strtok(NULL, ",");
610 HeapFree(GetProcessHeap(), 0, tokens);
613 static void selectDriver(HWND hDlg, const char * driver)
615 WCHAR text[1024];
616 WCHAR caption[64];
618 strcpy(curAudioDriver, driver);
619 set_reg_key(config_key, "Drivers", "Audio", curAudioDriver);
621 if (LoadStringW(GetModuleHandle(NULL), IDS_AUDIO_MISSING, text, sizeof(text)/sizeof(text[0])))
623 if (LoadStringW(GetModuleHandle(NULL), IDS_WINECFG_TITLE, caption, sizeof(caption)/sizeof(caption[0])))
624 MessageBoxW(hDlg, text, caption, MB_OK | MB_ICONINFORMATION);
627 SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM) hDlg, 0); /* enable apply button */
630 static void initAudioDlg (HWND hDlg)
632 int i, j, found;
633 char* buf = NULL;
635 WINE_TRACE("\n");
637 /* make a list of all drivers that can be loaded */
638 findAudioDrivers();
640 /* get current registry setting if available */
641 buf = get_reg_key(config_key, "Drivers", "Audio", NULL);
643 /* check for first time install and set a default driver
644 * select first available driver, and if that fails: none
646 if (buf == NULL)
648 /* select first available driver */
649 if (*loadedAudioDrv->szDriver)
650 selectDriver(hDlg, loadedAudioDrv->szDriver);
652 else /* make a local copy of the current registry setting */
653 strcpy(curAudioDriver, buf);
655 WINE_TRACE("curAudioDriver = %s\n", curAudioDriver);
657 /* check for drivers that can't be loaded */
658 checkRegistrySetting(hDlg);
660 initAudioDeviceTree(hDlg);
662 SendDlgItemMessage(hDlg, IDC_DSOUND_HW_ACCEL, CB_RESETCONTENT, 0, 0);
663 buf = get_reg_key(config_key, keypath("DirectSound"), "HardwareAcceleration", "Full");
665 j = found = 0;
666 for (i = 0; 0 != DSound_HW_Accels[i].displayID; ++i) {
667 WCHAR accelStr[64];
668 int match;
670 match = (strcmp(buf, DSound_HW_Accels[i].settingStr) == 0);
671 if (match)
673 DSound_HW_Accels[i].visible = 1;
674 found = 1;
677 if (DSound_HW_Accels[i].visible)
679 LoadStringW (GetModuleHandle (NULL), DSound_HW_Accels[i].displayID,
680 accelStr, sizeof(accelStr)/sizeof(accelStr[0]));
681 SendDlgItemMessageW (hDlg, IDC_DSOUND_HW_ACCEL, CB_ADDSTRING, 0, (LPARAM)accelStr);
682 if (match)
683 SendDlgItemMessage(hDlg, IDC_DSOUND_HW_ACCEL, CB_SETCURSEL, j, 0);
684 j++;
687 if (!found) {
688 WINE_ERR("Invalid Direct Sound HW Accel read from registry (%s)\n", buf);
690 HeapFree(GetProcessHeap(), 0, buf);
692 SendDlgItemMessage(hDlg, IDC_DSOUND_RATES, CB_RESETCONTENT, 0, 0);
693 for (i = 0; NULL != DSound_Rates[i]; ++i) {
694 SendDlgItemMessage(hDlg, IDC_DSOUND_RATES, CB_ADDSTRING, 0, (LPARAM) DSound_Rates[i]);
696 buf = get_reg_key(config_key, keypath("DirectSound"), "DefaultSampleRate", "44100");
697 for (i = 0; NULL != DSound_Rates[i]; ++i) {
698 if (strcmp(buf, DSound_Rates[i]) == 0) {
699 SendDlgItemMessage(hDlg, IDC_DSOUND_RATES, CB_SETCURSEL, i, 0);
700 break ;
704 SendDlgItemMessage(hDlg, IDC_DSOUND_BITS, CB_RESETCONTENT, 0, 0);
705 for (i = 0; NULL != DSound_Bits[i]; ++i) {
706 SendDlgItemMessage(hDlg, IDC_DSOUND_BITS, CB_ADDSTRING, 0, (LPARAM) DSound_Bits[i]);
708 buf = get_reg_key(config_key, keypath("DirectSound"), "DefaultBitsPerSample", "16");
709 for (i = 0; NULL != DSound_Bits[i]; ++i) {
710 if (strcmp(buf, DSound_Bits[i]) == 0) {
711 SendDlgItemMessage(hDlg, IDC_DSOUND_BITS, CB_SETCURSEL, i, 0);
712 break ;
715 HeapFree(GetProcessHeap(), 0, buf);
718 INT_PTR CALLBACK
719 AudioDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
721 switch (uMsg) {
722 case WM_COMMAND:
723 switch (LOWORD(wParam)) {
724 case IDC_AUDIO_CONFIGURE:
725 configureAudioDriver(hDlg);
726 break;
727 case IDC_AUDIO_TEST:
728 if(!PlaySound(MAKEINTRESOURCE(IDW_TESTSOUND), NULL, SND_RESOURCE | SND_SYNC))
729 MessageBox(NULL, "Audio test failed!", "Error", MB_OK | MB_ICONERROR);
730 break;
731 case IDC_AUDIO_CONTROL_PANEL:
732 MessageBox(NULL, "Launching audio control panel not implemented yet!", "Fixme", MB_OK | MB_ICONERROR);
733 break;
734 case IDC_DSOUND_HW_ACCEL:
735 if (HIWORD(wParam) == CBN_SELCHANGE) {
736 int selected_dsound_accel;
737 int i, j = 0;
739 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
740 selected_dsound_accel = SendDlgItemMessage(hDlg, IDC_DSOUND_HW_ACCEL, CB_GETCURSEL, 0, 0);
741 for (i = 0; DSound_HW_Accels[i].settingStr; ++i)
743 if (DSound_HW_Accels[i].visible)
745 if (j == selected_dsound_accel)
747 set_reg_key(config_key, keypath("DirectSound"), "HardwareAcceleration",
748 DSound_HW_Accels[i].settingStr);
749 break;
751 j++;
755 break;
756 case IDC_DSOUND_RATES:
757 if (HIWORD(wParam) == CBN_SELCHANGE) {
758 int selected_dsound_rate;
759 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
760 selected_dsound_rate = SendDlgItemMessage(hDlg, IDC_DSOUND_RATES, CB_GETCURSEL, 0, 0);
761 set_reg_key(config_key, keypath("DirectSound"), "DefaultSampleRate", DSound_Rates[selected_dsound_rate]);
763 break;
764 case IDC_DSOUND_BITS:
765 if (HIWORD(wParam) == CBN_SELCHANGE) {
766 int selected_dsound_bits;
767 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
768 selected_dsound_bits = SendDlgItemMessage(hDlg, IDC_DSOUND_BITS, CB_GETCURSEL, 0, 0);
769 set_reg_key(config_key, keypath("DirectSound"), "DefaultBitsPerSample", DSound_Bits[selected_dsound_bits]);
771 break;
773 break;
775 case WM_SHOWWINDOW:
776 set_window_title(hDlg);
777 break;
779 case WM_NOTIFY:
780 switch(((LPNMHDR)lParam)->code) {
781 case PSN_KILLACTIVE:
782 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
783 break;
784 case PSN_APPLY:
785 set_reg_key(config_key, "Drivers", "Audio", curAudioDriver);
786 apply();
787 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
788 break;
789 case PSN_SETACTIVE:
790 break;
791 case NM_CLICK:
792 if (((LPNMHDR)lParam)->idFrom == IDC_AUDIO_TREE)
794 TVHITTESTINFO ht;
795 DWORD dwPos = GetMessagePos();
796 HWND tree = ((LPNMHDR)lParam)->hwndFrom;
797 ZeroMemory(&ht, sizeof(ht));
798 ht.pt.x = (short)LOWORD(dwPos);
799 ht.pt.y = (short)HIWORD(dwPos);
800 MapWindowPoints(HWND_DESKTOP, tree, &ht.pt, 1);
801 SendMessageW( tree, TVM_HITTEST, 0, (LPARAM)&ht );
802 if (TVHT_ONITEMSTATEICON & ht.flags)
804 TVITEM tvItem;
805 int index;
806 ZeroMemory(&tvItem, sizeof(tvItem));
807 tvItem.hItem = ht.hItem;
808 SendMessageW( tree, TVM_GETITEMW, 0, (LPARAM) &tvItem );
810 index = TreeView_GetItemState(tree, ht.hItem, TVIS_STATEIMAGEMASK);
811 if (index == INDEXTOSTATEIMAGEMASK(1))
813 TreeView_SetItemState(tree, ht.hItem, INDEXTOSTATEIMAGEMASK(2), TVIS_STATEIMAGEMASK);
814 addDriver(loadedAudioDrv[tvItem.lParam & 0xff].szDriver);
815 SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM) hDlg, 0); /* enable apply button */
817 else if (index == INDEXTOSTATEIMAGEMASK(2))
819 TreeView_SetItemState(tree, ht.hItem, INDEXTOSTATEIMAGEMASK(1), TVIS_STATEIMAGEMASK);
820 removeDriver(loadedAudioDrv[tvItem.lParam & 0xff].szDriver);
821 SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM) hDlg, 0); /* enable apply button */
825 break;
826 case NM_RCLICK:
827 if (((LPNMHDR)lParam)->idFrom == IDC_AUDIO_TREE)
829 TVHITTESTINFO ht;
830 DWORD dwPos = GetMessagePos();
831 HWND tree = ((LPNMHDR)lParam)->hwndFrom;
832 POINT pt;
833 ZeroMemory(&ht, sizeof(ht));
834 pt.x = (short)LOWORD(dwPos);
835 pt.y = (short)HIWORD(dwPos);
836 ht.pt = pt;
837 MapWindowPoints(HWND_DESKTOP, tree, &ht.pt, 1);
838 SendMessageW( tree, TVM_HITTEST, 0, (LPARAM)&ht );
839 if (TVHT_ONITEMLABEL & ht.flags)
841 TVITEM tvItem;
842 ZeroMemory(&tvItem, sizeof(tvItem));
843 tvItem.hItem = ht.hItem;
844 tvItem.mask = TVIF_PARAM;
845 tvItem.lParam = -1;
846 if (TreeView_GetItem(tree, &tvItem))
848 if (tvItem.lParam & DRIVER_MASK)
850 if (hPopupMenus)
852 TrackPopupMenu(GetSubMenu(hPopupMenus, 0), TPM_RIGHTBUTTON, pt.x, pt.y, 0, tree, NULL);
853 toConfigure = tvItem.lParam & ~DRIVER_MASK;
856 else if (tvItem.lParam & DEVICE_MASK)
858 /* FIXME TBD */
865 break;
867 case WM_INITDIALOG:
868 initAudioDlg(hDlg);
869 break;
872 return FALSE;