ole32: STGM_PRIORITY implies STGM_SHARE_EXCLUSIVE.
[wine.git] / programs / winecfg / audio.c
blobba82e543d4f9768cb91daccd555f309a91784a94
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
53 typedef DWORD (WINAPI * MessagePtr)(UINT, UINT, DWORD, DWORD, DWORD);
55 static const char* DSound_HW_Accels[] = {
56 "Full",
57 "Standard",
58 "Basic",
59 "Emulation",
60 NULL
63 static const AUDIO_DRIVER sAudioDrivers[] = {
64 {"ALSA", "alsa"},
65 {"aRts", "arts"},
66 {"EsounD", "esd"},
67 {"OSS", "oss"},
68 {"JACK", "jack"},
69 {"NAS", "nas"},
70 {"Audio IO(Solaris)", "audioio"},
71 {"Disable sound", ""},
72 {"", ""}
75 /* list of available drivers */
76 static AUDIO_DRIVER * loadedAudioDrv;
78 /* local copy of registry setting */
79 static char curAudioDriver[1024];
81 /* driver index to configure */
82 static int toConfigure;
84 /* display a driver specific configuration dialog */
85 static void configureAudioDriver(HWND hDlg)
87 const AUDIO_DRIVER *pAudioDrv = &loadedAudioDrv[toConfigure];
89 if (strlen(pAudioDrv->szDriver) != 0)
91 HDRVR hdrvr;
92 char wine_driver[MAX_NAME_LENGTH + 8];
93 sprintf(wine_driver, "wine%s.drv", pAudioDrv->szDriver);
94 hdrvr = OpenDriverA(wine_driver, 0, 0);
95 if (hdrvr != 0)
97 if (SendDriverMessage(hdrvr, DRV_QUERYCONFIGURE, 0, 0) != 0)
99 DRVCONFIGINFO dci;
100 LONG lRes;
101 dci.dwDCISize = sizeof (dci);
102 dci.lpszDCISectionName = NULL;
103 dci.lpszDCIAliasName = NULL;
104 lRes = SendDriverMessage(hdrvr, DRV_CONFIGURE, 0, (LONG)&dci);
106 CloseDriver(hdrvr, 0, 0);
108 else
110 char str[1024];
111 sprintf(str, "Couldn't open %s!", wine_driver);
112 MessageBox(hDlg, str, "Fixme", MB_OK | MB_ICONERROR);
117 /* is driver in local copy of driver registry string */
118 static BOOL isDriverSet(const char * driver)
120 WINE_TRACE("driver = %s, curAudioDriver = %s\n", driver, curAudioDriver);
122 if (strstr(curAudioDriver, driver))
123 return TRUE;
125 return FALSE;
128 /* add driver to local copy of driver registry string */
129 static void addDriver(const char * driver)
131 if (!isDriverSet(driver))
133 if (strlen(curAudioDriver))
134 strcat(curAudioDriver, ",");
135 strcat(curAudioDriver, driver);
139 /* remove driver from local copy of driver registry string */
140 static void removeDriver(const char * driver)
142 char before[32], after[32], * start;
144 strcpy(before, ",");
145 strcat(before, driver);
146 strcpy(after, driver);
147 strcat(after, ",");
149 if ((start = strstr(curAudioDriver, after)))
151 int len = strlen(after);
152 char * end = curAudioDriver + strlen(curAudioDriver);
153 int i, count = end - start + len;
154 for (i = 0; i < count; i++)
156 if (start + len >= end)
157 *start = 0;
158 else
159 *start = start[len];
160 start++;
163 else if ((start = strstr(curAudioDriver, before)))
165 int len = strlen(before);
166 char * end = curAudioDriver + strlen(curAudioDriver);
167 int i, count = end - start + len;
168 for (i = 0; i < count; i++)
170 if (start + len >= end)
171 *start = 0;
172 else
173 *start = start[len];
174 start++;
177 else if (strcmp(curAudioDriver, driver) == 0)
179 strcpy(curAudioDriver, "");
183 static void initAudioDeviceTree(HWND hDlg)
185 const AUDIO_DRIVER *pAudioDrv = NULL;
186 int i, j;
187 TVINSERTSTRUCT insert;
188 HTREEITEM root, driver[10];
189 HWND tree = NULL;
190 HIMAGELIST hImageList;
191 HBITMAP hBitMap;
192 HCURSOR old_cursor;
194 tree = GetDlgItem(hDlg, IDC_AUDIO_TREE);
196 if (!tree)
197 return;
199 /* set tree view style */
200 SetWindowLong(tree, GWL_STYLE, GetWindowLong(tree, GWL_STYLE) | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT);
202 /* state checkbox */
203 hImageList = ImageList_Create(16, 16, FALSE, 3, 0);
204 hBitMap = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_CHECKBOX));
205 ImageList_Add(hImageList, hBitMap, NULL);
206 DeleteObject(hBitMap);
207 SendMessageW( tree, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)hImageList );
209 /* root item */
210 insert.hParent = TVI_ROOT;
211 insert.hInsertAfter = TVI_LAST;
212 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
213 insert.u.item.pszText = "Sound Drivers";
214 insert.u.item.cChildren = 1;
215 root = (HTREEITEM)SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_INSERTITEM, 0, (LPARAM)&insert);
217 /* change to the wait cursor because this can take a while if there is a
218 * misbehaving driver that takes a long time to open
220 old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
222 /* iterate over list of loaded drivers */
223 for (pAudioDrv = loadedAudioDrv, i = 0; *pAudioDrv->szName; i++, pAudioDrv++) {
224 HDRVR hdrv;
225 char name[MAX_PATH];
226 char text[MAX_PATH];
228 sprintf(name, "wine%s.drv", pAudioDrv->szDriver);
229 sprintf(text, "%s Driver", pAudioDrv->szName);
231 if ((hdrv = OpenDriverA(name, 0, 0)))
233 HMODULE lib;
234 if ((lib = GetDriverModuleHandle(hdrv)))
236 int num_wod = 0, num_wid = 0, num_mod = 0, num_mid = 0, num_aux = 0, num_mxd = 0;
237 MessagePtr wodMessagePtr = (MessagePtr)GetProcAddress(lib, "wodMessage");
238 MessagePtr widMessagePtr = (MessagePtr)GetProcAddress(lib, "widMessage");
239 MessagePtr modMessagePtr = (MessagePtr)GetProcAddress(lib, "modMessage");
240 MessagePtr midMessagePtr = (MessagePtr)GetProcAddress(lib, "midMessage");
241 MessagePtr auxMessagePtr = (MessagePtr)GetProcAddress(lib, "auxMessage");
242 MessagePtr mxdMessagePtr = (MessagePtr)GetProcAddress(lib, "mxdMessage");
244 if (wodMessagePtr)
245 num_wod = wodMessagePtr(0, WODM_GETNUMDEVS, 0, 0, 0);
247 if (widMessagePtr)
248 num_wid = widMessagePtr(0, WIDM_GETNUMDEVS, 0, 0, 0);
250 if (modMessagePtr)
251 num_mod = modMessagePtr(0, MODM_GETNUMDEVS, 0, 0, 0);
253 if (midMessagePtr)
254 num_mid = midMessagePtr(0, MIDM_GETNUMDEVS, 0, 0, 0);
256 if (auxMessagePtr)
257 num_aux = auxMessagePtr(0, AUXDM_GETNUMDEVS, 0, 0, 0);
259 if (mxdMessagePtr)
260 num_mxd = mxdMessagePtr(0, MXDM_GETNUMDEVS, 0, 0, 0);
262 if (num_wod == 0 && num_wid == 0 && num_mod == 0 && num_mid == 0 && num_aux == 0 && num_mxd == 0)
264 insert.hParent = root;
265 insert.u.item.mask = TVIF_TEXT | TVIF_STATE | TVIF_PARAM;
266 insert.u.item.pszText = text;
267 insert.u.item.stateMask = TVIS_STATEIMAGEMASK;
268 insert.u.item.lParam = i + DRIVER_MASK;
270 driver[i] = (HTREEITEM)SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_INSERTITEM, 0, (LPARAM)&insert);
272 else
274 HTREEITEM type;
276 insert.hParent = root;
277 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN | TVIF_STATE | TVIF_PARAM;
278 insert.u.item.pszText = text;
279 insert.u.item.cChildren = 1;
280 insert.u.item.stateMask = TVIS_STATEIMAGEMASK;
281 insert.u.item.lParam = i + DRIVER_MASK;
283 if (isDriverSet(pAudioDrv->szDriver))
284 insert.u.item.state = INDEXTOSTATEIMAGEMASK(2);
285 else
286 insert.u.item.state = INDEXTOSTATEIMAGEMASK(1);
288 driver[i] = (HTREEITEM)SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_INSERTITEM, 0, (LPARAM)&insert);
290 if (num_wod)
292 insert.hParent = driver[i];
293 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
294 insert.u.item.pszText = "Wave Out Devices";
295 insert.u.item.cChildren = 1;
297 type = (HTREEITEM)SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_INSERTITEM, 0, (LPARAM)&insert);
299 for (j = 0; j < num_wod; j++)
301 WAVEOUTCAPSW caps;
302 char szPname[MAXPNAMELEN];
304 wodMessagePtr(j, WODM_GETDEVCAPS, 0, (DWORD)&caps, sizeof(caps));
305 WideCharToMultiByte(CP_ACP, 0, caps.szPname, -1, szPname, MAXPNAMELEN, 0, 0);
307 insert.hParent = type;
308 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
309 insert.u.item.pszText = szPname;
310 insert.u.item.lParam = j + DEVICE_MASK;
312 SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_INSERTITEM, 0, (LPARAM)&insert);
316 if (num_wid)
318 insert.hParent = driver[i];
319 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
320 insert.u.item.pszText = "Wave In Devices";
321 insert.u.item.cChildren = 1;
323 type = (HTREEITEM)SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_INSERTITEM, 0, (LPARAM)&insert);
325 for (j = 0; j < num_wid; j++)
327 WAVEINCAPSW caps;
328 char szPname[MAXPNAMELEN];
330 widMessagePtr(j, WIDM_GETDEVCAPS, 0, (DWORD)&caps, sizeof(caps));
331 WideCharToMultiByte(CP_ACP, 0, caps.szPname, -1, szPname, MAXPNAMELEN, 0, 0);
333 insert.hParent = type;
334 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
335 insert.u.item.pszText = szPname;
336 insert.u.item.lParam = j + DEVICE_MASK;
338 SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_INSERTITEM, 0, (LPARAM)&insert);
342 if (num_mod)
344 insert.hParent = driver[i];
345 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
346 insert.u.item.pszText = "MIDI Out Devices";
347 insert.u.item.cChildren = 1;
349 type = (HTREEITEM)SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_INSERTITEM, 0, (LPARAM)&insert);
351 for (j = 0; j < num_mod; j++)
353 MIDIOUTCAPSW caps;
354 char szPname[MAXPNAMELEN];
356 modMessagePtr(j, MODM_GETDEVCAPS, 0, (DWORD)&caps, sizeof(caps));
357 WideCharToMultiByte(CP_ACP, 0, caps.szPname, -1, szPname, MAXPNAMELEN, 0, 0);
359 insert.hParent = type;
360 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
361 insert.u.item.pszText = szPname;
362 insert.u.item.lParam = j + DEVICE_MASK;
364 SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_INSERTITEM, 0, (LPARAM)&insert);
368 if (num_mid)
370 insert.hParent = driver[i];
371 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
372 insert.u.item.pszText = "MIDI In Devices";
373 insert.u.item.cChildren = 1;
375 type = (HTREEITEM)SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_INSERTITEM, 0, (LPARAM)&insert);
377 for (j = 0; j < num_mid; j++)
379 MIDIINCAPSW caps;
380 char szPname[MAXPNAMELEN];
382 midMessagePtr(j, MIDM_GETDEVCAPS, 0, (DWORD)&caps, sizeof(caps));
383 WideCharToMultiByte(CP_ACP, 0, caps.szPname, -1, szPname, MAXPNAMELEN, 0, 0);
385 insert.hParent = type;
386 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
387 insert.u.item.pszText = szPname;
388 insert.u.item.lParam = j + DEVICE_MASK;
390 SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_INSERTITEM, 0, (LPARAM)&insert);
394 if (num_aux)
396 insert.hParent = driver[i];
397 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
398 insert.u.item.pszText = "Aux Devices";
399 insert.u.item.cChildren = 1;
401 type = (HTREEITEM)SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_INSERTITEM, 0, (LPARAM)&insert);
403 for (j = 0; j < num_aux; j++)
405 AUXCAPSW caps;
406 char szPname[MAXPNAMELEN];
408 auxMessagePtr(j, AUXDM_GETDEVCAPS, 0, (DWORD)&caps, sizeof(caps));
409 WideCharToMultiByte(CP_ACP, 0, caps.szPname, -1, szPname, MAXPNAMELEN, 0, 0);
411 insert.hParent = type;
412 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
413 insert.u.item.pszText = szPname;
414 insert.u.item.lParam = j + DEVICE_MASK;
416 SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_INSERTITEM, 0, (LPARAM)&insert);
420 if (num_mxd)
422 insert.hParent = driver[i];
423 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
424 insert.u.item.pszText = "Mixer Devices";
425 insert.u.item.cChildren = 1;
427 type = (HTREEITEM)SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_INSERTITEM, 0, (LPARAM)&insert);
429 for (j = 0; j < num_mxd; j++)
431 MIXERCAPSW caps;
432 char szPname[MAXPNAMELEN];
434 mxdMessagePtr(j, MXDM_GETDEVCAPS, 0, (DWORD)&caps, sizeof(caps));
435 WideCharToMultiByte(CP_ACP, 0, caps.szPname, -1, szPname, MAXPNAMELEN, 0, 0);
437 insert.hParent = type;
438 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
439 insert.u.item.pszText = szPname;
440 insert.u.item.lParam = j + DEVICE_MASK;
442 SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_INSERTITEM, 0, (LPARAM)&insert);
450 /* restore the original cursor */
451 SetCursor(old_cursor);
453 SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_SELECTITEM, 0, 0);
454 SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_EXPAND, TVE_EXPAND, (LPARAM)root);
455 for (j = 0; j < i; j++)
456 SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_EXPAND, TVE_EXPAND, (LPARAM)driver[j]);
459 /* find all drivers that can be loaded */
460 static void findAudioDrivers(void)
462 int numFound = 0;
463 const AUDIO_DRIVER *pAudioDrv = NULL;
464 HCURSOR old_cursor;
466 /* delete an existing list */
467 if (loadedAudioDrv)
469 HeapFree(GetProcessHeap(), 0, loadedAudioDrv);
470 loadedAudioDrv = 0;
473 /* change to the wait cursor because this can take a while if there is a
474 * misbehaving driver that takes a long time to open
476 old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
478 for (pAudioDrv = sAudioDrivers; *pAudioDrv->szName; pAudioDrv++)
480 if (strlen(pAudioDrv->szDriver))
482 HDRVR hdrv;
483 char driver[MAX_PATH];
485 sprintf(driver, "wine%s.drv", pAudioDrv->szDriver);
487 if ((hdrv = OpenDriverA(driver, 0, 0)))
489 CloseDriver(hdrv, 0, 0);
491 if (loadedAudioDrv)
492 loadedAudioDrv = HeapReAlloc(GetProcessHeap(), 0, loadedAudioDrv, (numFound + 1) * sizeof(AUDIO_DRIVER));
493 else
494 loadedAudioDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(AUDIO_DRIVER));
496 CopyMemory(&loadedAudioDrv[numFound], pAudioDrv, sizeof(AUDIO_DRIVER));
497 numFound++;
502 /* restore the original cursor */
503 SetCursor(old_cursor);
505 /* terminate list with empty driver */
506 loadedAudioDrv = HeapReAlloc(GetProcessHeap(), 0, loadedAudioDrv, (numFound + 1) * sizeof(AUDIO_DRIVER));
507 CopyMemory(&loadedAudioDrv[numFound], pAudioDrv, sizeof(AUDIO_DRIVER));
510 /* check local copy of registry string for unloadable drivers */
511 static void checkRegistrySetting(HWND hDlg)
513 const AUDIO_DRIVER *pAudioDrv;
514 char * token, * tokens = strdup(curAudioDriver);
516 start_over:
517 token = strtok(tokens, ",");
518 while (token != NULL)
520 BOOL found = FALSE;
521 for (pAudioDrv = loadedAudioDrv; *pAudioDrv->szName; pAudioDrv++)
523 if (strcmp(token, pAudioDrv->szDriver) == 0)
525 found = TRUE;
526 break;
529 if (found == FALSE)
531 char str[1024];
532 sprintf(str, "Found driver in registry that in not available!\n\nRemove \"%s\" from registry?", token);
533 if (MessageBox(hDlg, str, "WARNING", MB_ICONWARNING | MB_YESNOCANCEL) == IDYES)
535 removeDriver(token);
536 strcpy(tokens, curAudioDriver);
537 goto start_over;
540 token = strtok(NULL, ",");
542 free(tokens);
545 static void selectDriver(HWND hDlg, const char * driver)
547 WCHAR text[1024];
548 WCHAR caption[64];
550 strcpy(curAudioDriver, driver);
551 set_reg_key(config_key, "Drivers", "Audio", curAudioDriver);
553 if (LoadStringW(GetModuleHandle(NULL), IDS_AUDIO_MISSING, text, sizeof(text)/sizeof(text[0])))
555 if (LoadStringW(GetModuleHandle(NULL), IDS_WINECFG_TITLE, caption, sizeof(caption)/sizeof(caption[0])))
556 MessageBoxW(hDlg, text, caption, MB_OK | MB_ICONINFORMATION);
559 SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM) hDlg, 0); /* enable apply button */
562 static void initAudioDlg (HWND hDlg)
564 int i;
565 char* buf = NULL;
567 WINE_TRACE("\n");
569 /* make a list of all drivers that can be loaded */
570 findAudioDrivers();
572 /* get current registry setting if available */
573 buf = get_reg_key(config_key, "Drivers", "Audio", NULL);
575 /* check for first time install and set a default driver
576 * select in this order: oss, alsa, first available driver, none
578 if (buf == NULL)
580 const AUDIO_DRIVER *pAudioDrv = NULL;
582 /* select oss if available */
583 for (pAudioDrv = loadedAudioDrv; *pAudioDrv->szName; pAudioDrv++)
585 if (strcmp(pAudioDrv->szDriver, "oss") == 0)
587 selectDriver(hDlg, "oss");
588 break;
592 if (strlen(curAudioDriver) == 0)
594 /* select alsa if available */
595 for (pAudioDrv = loadedAudioDrv; *pAudioDrv->szName; pAudioDrv++)
597 if (strcmp(pAudioDrv->szDriver, "alsa") == 0)
599 selectDriver(hDlg, "alsa");
600 break;
605 if (strlen(curAudioDriver) == 0)
607 /* select first available driver */
608 if (*loadedAudioDrv->szDriver)
609 selectDriver(hDlg, loadedAudioDrv->szDriver);
612 else /* make a local copy of the current registry setting */
613 strcpy(curAudioDriver, buf);
615 WINE_TRACE("curAudioDriver = %s\n", curAudioDriver);
617 /* check for drivers that can't be loaded */
618 checkRegistrySetting(hDlg);
620 initAudioDeviceTree(hDlg);
622 SendDlgItemMessage(hDlg, IDC_DSOUND_HW_ACCEL, CB_RESETCONTENT, 0, 0);
623 for (i = 0; NULL != DSound_HW_Accels[i]; ++i) {
624 SendDlgItemMessage(hDlg, IDC_DSOUND_HW_ACCEL, CB_ADDSTRING, 0, (LPARAM) DSound_HW_Accels[i]);
626 buf = get_reg_key(config_key, keypath("DirectSound"), "HardwareAcceleration", "Full");
627 for (i = 0; NULL != DSound_HW_Accels[i]; ++i) {
628 if (strcmp(buf, DSound_HW_Accels[i]) == 0) {
629 SendDlgItemMessage(hDlg, IDC_DSOUND_HW_ACCEL, CB_SETCURSEL, i, 0);
630 break ;
633 if (NULL == DSound_HW_Accels[i]) {
634 WINE_ERR("Invalid Direct Sound HW Accel read from registry (%s)\n", buf);
636 HeapFree(GetProcessHeap(), 0, buf);
638 buf = get_reg_key(config_key, keypath("DirectSound"), "EmulDriver", "N");
639 if (IS_OPTION_TRUE(*buf))
640 CheckDlgButton(hDlg, IDC_DSOUND_DRV_EMUL, BST_CHECKED);
641 else
642 CheckDlgButton(hDlg, IDC_DSOUND_DRV_EMUL, BST_UNCHECKED);
643 HeapFree(GetProcessHeap(), 0, buf);
646 INT_PTR CALLBACK
647 AudioDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
649 switch (uMsg) {
650 case WM_COMMAND:
651 switch (LOWORD(wParam)) {
652 case IDC_AUDIO_CONFIGURE:
653 configureAudioDriver(hDlg);
654 break;
655 case IDC_AUDIO_CONTROL_PANEL:
656 MessageBox(NULL, "Launching audio control panel not implemented yet!", "Fixme", MB_OK | MB_ICONERROR);
657 break;
658 case IDC_DSOUND_HW_ACCEL:
659 if (HIWORD(wParam) == CBN_SELCHANGE) {
660 int selected_dsound_accel;
661 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
662 selected_dsound_accel = SendDlgItemMessage(hDlg, IDC_DSOUND_HW_ACCEL, CB_GETCURSEL, 0, 0);
663 set_reg_key(config_key, keypath("DirectSound"), "HardwareAcceleration", DSound_HW_Accels[selected_dsound_accel]);
665 break;
666 case IDC_DSOUND_DRV_EMUL:
667 if (HIWORD(wParam) == BN_CLICKED) {
668 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
669 if (IsDlgButtonChecked(hDlg, IDC_DSOUND_DRV_EMUL) == BST_CHECKED)
670 set_reg_key(config_key, keypath("DirectSound"), "EmulDriver", "Y");
671 else
672 set_reg_key(config_key, keypath("DirectSound"), "EmulDriver", "N");
674 break;
676 break;
678 case WM_SHOWWINDOW:
679 set_window_title(hDlg);
680 break;
682 case WM_NOTIFY:
683 switch(((LPNMHDR)lParam)->code) {
684 case PSN_KILLACTIVE:
685 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
686 break;
687 case PSN_APPLY:
688 set_reg_key(config_key, "Drivers", "Audio", curAudioDriver);
689 apply();
690 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
691 break;
692 case PSN_SETACTIVE:
693 break;
694 case NM_CLICK:
695 if (((LPNMHDR)lParam)->idFrom == IDC_AUDIO_TREE)
697 TVHITTESTINFO ht;
698 DWORD dwPos = GetMessagePos();
699 HWND tree = ((LPNMHDR)lParam)->hwndFrom;
700 ZeroMemory(&ht, sizeof(ht));
701 ht.pt.x = (short)LOWORD(dwPos);
702 ht.pt.y = (short)HIWORD(dwPos);
703 MapWindowPoints(HWND_DESKTOP, tree, &ht.pt, 1);
704 SendMessageW( tree, TVM_HITTEST, 0, (LPARAM)&ht );
705 if (TVHT_ONITEMSTATEICON & ht.flags)
707 TVITEM tvItem;
708 int index;
709 ZeroMemory(&tvItem, sizeof(tvItem));
710 tvItem.hItem = ht.hItem;
711 SendMessageW( tree, TVM_GETITEMW, 0, (LPARAM) &tvItem );
713 index = TreeView_GetItemState(tree, ht.hItem, TVIS_STATEIMAGEMASK);
714 if (index == INDEXTOSTATEIMAGEMASK(1))
716 TreeView_SetItemState(tree, ht.hItem, INDEXTOSTATEIMAGEMASK(2), TVIS_STATEIMAGEMASK);
717 addDriver(loadedAudioDrv[tvItem.lParam & 0xff].szDriver);
718 SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM) hDlg, 0); /* enable apply button */
720 else if (index == INDEXTOSTATEIMAGEMASK(2))
722 TreeView_SetItemState(tree, ht.hItem, INDEXTOSTATEIMAGEMASK(1), TVIS_STATEIMAGEMASK);
723 removeDriver(loadedAudioDrv[tvItem.lParam & 0xff].szDriver);
724 SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM) hDlg, 0); /* enable apply button */
728 break;
729 case NM_RCLICK:
730 if (((LPNMHDR)lParam)->idFrom == IDC_AUDIO_TREE)
732 TVHITTESTINFO ht;
733 DWORD dwPos = GetMessagePos();
734 HWND tree = ((LPNMHDR)lParam)->hwndFrom;
735 POINT pt;
736 ZeroMemory(&ht, sizeof(ht));
737 pt.x = (short)LOWORD(dwPos);
738 pt.y = (short)HIWORD(dwPos);
739 ht.pt = pt;
740 MapWindowPoints(HWND_DESKTOP, tree, &ht.pt, 1);
741 SendMessageW( tree, TVM_HITTEST, 0, (LPARAM)&ht );
742 if (TVHT_ONITEMLABEL & ht.flags)
744 TVITEM tvItem;
745 ZeroMemory(&tvItem, sizeof(tvItem));
746 tvItem.hItem = ht.hItem;
747 tvItem.mask = TVIF_PARAM;
748 tvItem.lParam = -1;
749 if (TreeView_GetItem(tree, &tvItem))
751 if (tvItem.lParam & DRIVER_MASK)
753 if (hPopupMenus)
755 TrackPopupMenu(GetSubMenu(hPopupMenus, 0), TPM_RIGHTBUTTON, pt.x, pt.y, 0, tree, NULL);
756 toConfigure = tvItem.lParam & ~DRIVER_MASK;
759 else if (tvItem.lParam & DEVICE_MASK)
761 /* FIXME TBD */
768 break;
770 case WM_INITDIALOG:
771 initAudioDlg(hDlg);
772 break;
775 return FALSE;