2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Sound Volume Control
4 * FILE: subsys/system/sndvol32/dialog.c
5 * PROGRAMMERS: Johannes Anderwald
14 #define DIALOG_VOLUME_SIZE (150)
19 IN LPCWSTR ResourceName
,
20 OUT LPDWORD ResourceLength
)
27 hSrc
= FindResourceW(hModule
, ResourceName
, (LPCWSTR
)RT_DIALOG
);
31 /* failed to find resource */
35 /* now load the resource */
36 hRes
= LoadResource(hAppInstance
, hSrc
);
39 /* failed to load resource */
43 /* now lock the resource */
44 Result
= LockResource(hRes
);
48 /* failed to lock resource */
54 /* store output length */
55 *ResourceLength
= SizeofResource(hAppInstance
, hSrc
);
66 IN LPRECT DialogOffset
,
67 IN PDLGITEMTEMPLATE DialogItem
,
68 IN DWORD DialogIdMultiplier
,
73 LPWSTR ClassName
, WindowName
= NULL
;
77 /* initialize client rectangle */
78 rect
.left
= DialogItem
->x
+ DialogOffset
->left
;
79 rect
.top
= DialogItem
->y
+ DialogOffset
->top
;
80 rect
.right
= DialogItem
->cx
;
81 rect
.bottom
= DialogItem
->cy
;
83 //MapDialogRect(hwndDialog, &rect);
85 /* move offset after dialog item */
86 Offset
= (LPWORD
)(DialogItem
+ 1);
88 if (*Offset
== 0xFFFF)
90 /* class is encoded as type */
93 /* get control type */
97 ClassName
= L
"button";
98 WindowName
= (LPWSTR
)(Offset
+ 1);
101 ClassName
= L
"static";
102 WindowName
= (LPWSTR
)(Offset
+ 1);
112 /* class name is encoded as string */
113 ClassName
= (LPWSTR
)Offset
;
116 Offset
+= wcslen(ClassName
) + 1;
119 WindowName
= (LPWSTR
)(Offset
+ 1);
122 if (DialogItem
->id
== MAXWORD
)
124 /* id is not important */
125 wID
= DialogItem
->id
;
130 wID
= DialogItem
->id
* (DialogIdMultiplier
+ 1);
133 /* now create the window */
134 hwnd
= CreateWindowExW(DialogItem
->dwExtendedStyle
,
153 /* check if this the track bar */
154 if (!wcsicmp(ClassName
, L
"msctls_trackbar32"))
157 SendMessage(hwnd
, TBM_SETRANGE
, (WPARAM
) TRUE
, (LPARAM
) MAKELONG(0, 5));
159 /* set up page size */
160 SendMessage(hwnd
, TBM_SETPAGESIZE
, 0, (LPARAM
) 1);
162 /* set available range */
163 //SendMessage(hwnd, TBM_SETSEL, (WPARAM) FALSE, (LPARAM) MAKELONG(0, 5));
166 SendMessage(hwnd
, TBM_SETPOS
, (WPARAM
) TRUE
, (LPARAM
) 0);
169 else if (!wcsicmp(ClassName
, L
"static") || !wcsicmp(ClassName
, L
"button"))
172 SendMessageW(hwnd
, WM_SETFONT
, (WPARAM
)hFont
, TRUE
);
175 //ShowWindow(hwnd, SW_SHOWNORMAL);
177 if (WindowName
!= NULL
)
179 /* position offset to start of name */
182 /* move offset past name */
183 Offset
+= wcslen((LPWSTR
)Offset
) + 1;
187 /* no name so just adjust offset */
191 /* check if there is additional data */
194 /* no additional data */
199 /* add data offset */
203 /* make sure next template is word-aligned */
204 Offset
= (LPWORD
)(((ULONG_PTR
)Offset
+ 3) & ~3);
212 IN PMIXER_WINDOW MixerWindow
,
215 DWORD DialogIdMultiplier
)
217 LPDLGTEMPLATE DialogHeader
;
218 PDLGITEMTEMPLATE DialogItem
;
225 /* get dialog header */
226 DialogHeader
= (LPDLGTEMPLATE
)DlgResource
;
229 assert(DialogHeader
->cdit
);
231 if (MixerWindow
->Window
)
232 MixerWindow
->Window
= (HWND
*)HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, MixerWindow
->Window
, (MixerWindow
->WindowCount
+ DialogHeader
->cdit
) * sizeof(HWND
));
234 MixerWindow
->Window
= (HWND
*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, DialogHeader
->cdit
* sizeof(HWND
));
235 if (!MixerWindow
->Window
)
241 /* now walk past the dialog header */
242 Offset
= (LPWORD
)(DialogHeader
+ 1);
244 /* FIXME: support menu */
245 assert(*Offset
== 0);
248 /* FIXME: support classes */
249 assert(*Offset
== 0);
252 /* FIXME: support titles */
253 assert(*Offset
== 0);
260 /* calculate font length */
261 Length
= wcslen((LPWSTR
)Offset
) + 1;
262 assert(Length
< (sizeof(FontName
) / sizeof(WCHAR
)));
265 wcscpy(FontName
, (LPWSTR
)Offset
);
267 Font
= CreateFontW(FontSize
+8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, DEFAULT_CHARSET
, OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
, DEFAULT_QUALITY
, FF_DONTCARE
, FontName
);
270 /* move offset after font name */
273 /* offset is now at first dialog item control */
274 DialogItem
= (PDLGITEMTEMPLATE
)Offset
;
276 /* enumerate now all controls */
277 for(Index
= 0; Index
< DialogHeader
->cdit
; Index
++)
280 Offset
= AddDialogControl(MixerWindow
->hWnd
, &MixerWindow
->Window
[MixerWindow
->WindowCount
], DialogOffset
, DialogItem
, DialogIdMultiplier
, Font
);
285 /* move dialog item to new offset */
286 DialogItem
=(PDLGITEMTEMPLATE
)Offset
;
288 /* increment window count */
289 MixerWindow
->WindowCount
++;
296 IN PMIXER_WINDOW MixerWindow
,
297 IN LPCWSTR DialogResId
,
303 /* first load the dialog resource */
304 DlgResource
= LoadDialogResource(hModule
, DialogResId
, NULL
);
308 /* failed to load resource */
312 /* get window size */
313 GetClientRect(MixerWindow
->hWnd
, &rect
);
315 /* adjust client position */
316 rect
.left
+= (Index
* DIALOG_VOLUME_SIZE
);
319 /* now add the controls */
320 LoadDialogControls(MixerWindow
, &rect
, DlgResource
, Index
);
326 EnumConnectionsCallback(
332 WCHAR LineName
[MIXER_LONG_NAME_CHARS
];
336 UINT ControlCount
= 0, Index
;
337 LPMIXERCONTROL Control
= NULL
;
339 PPREFERENCES_CONTEXT PrefContext
= (PPREFERENCES_CONTEXT
)Context
;
341 if (Line
->cControls
!= 0)
344 if (SndMixerGetLineName(PrefContext
->MixerWindow
->Mixer
, PrefContext
->SelectedLine
, LineName
, MIXER_LONG_NAME_CHARS
, TRUE
) == -1)
346 /* failed to get line name */
350 /* check if line is found in registry settings */
351 if (ReadLineConfig(PrefContext
->DeviceName
,
359 /* load dialog resource */
360 LoadDialog(hAppInstance
, PrefContext
->MixerWindow
, MAKEINTRESOURCE(IDD_VOLUME_CTRL
), PrefContext
->Count
);
363 wID
= (PrefContext
->Count
+ 1) * IDC_LINE_NAME
;
366 SetDlgItemTextW(PrefContext
->MixerWindow
->hWnd
, wID
, Line
->szName
);
369 if (SndMixerQueryControls(Mixer
, &ControlCount
, Line
, &Control
) == TRUE
)
371 /* now go through all controls and update their states */
372 for(Index
= 0; Index
< ControlCount
; Index
++)
374 if ((Control
[Index
].dwControlType
& MIXERCONTROL_CT_CLASS_MASK
) == MIXERCONTROL_CT_CLASS_SWITCH
)
376 MIXERCONTROLDETAILS_BOOLEAN Details
;
378 /* get volume control details */
379 if (SndMixerGetVolumeControlDetails(Mixer
, Control
[Index
].dwControlID
, sizeof(MIXERCONTROLDETAILS_BOOLEAN
), (LPVOID
)&Details
) != -1)
381 /* update dialog control */
382 wID
= (PrefContext
->Count
+ 1) * IDC_LINE_SWITCH
;
384 /* get dialog control */
385 hDlgCtrl
= GetDlgItem(PrefContext
->MixerWindow
->hWnd
, wID
);
387 if (hDlgCtrl
!= NULL
)
390 if (SendMessageW(hDlgCtrl
, BM_GETCHECK
, 0, 0) != Details
.fValue
)
392 /* update control state */
393 SendMessageW(hDlgCtrl
, BM_SETCHECK
, (WPARAM
)Details
.fValue
, 0);
398 else if ((Control
[Index
].dwControlType
& MIXERCONTROL_CT_CLASS_MASK
) == MIXERCONTROL_CT_CLASS_FADER
)
400 MIXERCONTROLDETAILS_UNSIGNED Details
;
402 /* get volume control details */
403 if (SndMixerGetVolumeControlDetails(Mixer
, Control
[Index
].dwControlID
, sizeof(MIXERCONTROLDETAILS_UNSIGNED
), (LPVOID
)&Details
) != -1)
405 /* update dialog control */
407 DWORD Step
= 0x10000 / 5;
409 /* FIXME: give me granularity */
410 Position
= 5 - (Details
.dwValue
/ Step
);
412 /* FIXME support left - right slider */
413 wID
= (PrefContext
->Count
+ 1) * IDC_LINE_SLIDER_VERT
;
415 /* get dialog control */
416 hDlgCtrl
= GetDlgItem(PrefContext
->MixerWindow
->hWnd
, wID
);
418 if (hDlgCtrl
!= NULL
)
421 LRESULT OldPosition
= SendMessageW(hDlgCtrl
, TBM_GETPOS
, 0, 0);
422 if (OldPosition
!= Position
)
424 /* update control state */
425 SendMessageW(hDlgCtrl
, TBM_SETPOS
, (WPARAM
)TRUE
, Position
+ Index
);
433 HeapFree(GetProcessHeap(), 0, Control
);
436 /* increment dialog count */
437 PrefContext
->Count
++;
439 /* get application rectangle */
440 GetWindowRect(PrefContext
->MixerWindow
->hWnd
, &rect
);
442 /* now move the window */
443 MoveWindow(PrefContext
->MixerWindow
->hWnd
, rect
.left
, rect
.top
, (PrefContext
->Count
* DIALOG_VOLUME_SIZE
), rect
.bottom
- rect
.top
, TRUE
);
452 PPREFERENCES_CONTEXT PrefContext
)
456 /* set dialog count to zero */
457 PrefContext
->Count
= 0;
459 /* enumerate controls */
460 SndMixerEnumConnections(PrefContext
->MixerWindow
->Mixer
, PrefContext
->SelectedLine
, EnumConnectionsCallback
, (PVOID
)PrefContext
);
462 /* get last line seperator */
463 hDlgCtrl
= GetDlgItem(PrefContext
->MixerWindow
->hWnd
, IDC_LINE_SEP
* PrefContext
->Count
);
465 if (hDlgCtrl
!= NULL
)
467 /* hide last seperator */
468 ShowWindow(hDlgCtrl
, SW_HIDE
);
474 UpdateDialogLineSwitchControl(
475 PPREFERENCES_CONTEXT PrefContext
,
482 WCHAR LineName
[MIXER_LONG_NAME_CHARS
];
484 /* find the index of this line */
485 for(Index
= 0; Index
< PrefContext
->Count
; Index
++)
488 wID
= (Index
+ 1) * IDC_LINE_NAME
;
490 if (GetDlgItemText(PrefContext
->MixerWindow
->hWnd
, wID
, LineName
, MIXER_LONG_NAME_CHARS
) == 0)
492 /* failed to retrieve id */
496 /* check if the line name matches */
497 if (!wcsicmp(LineName
, Line
->szName
))
499 /* found matching line name */
500 wID
= (Index
+ 1) * IDC_LINE_SWITCH
;
502 /* get dialog control */
503 hDlgCtrl
= GetDlgItem(PrefContext
->MixerWindow
->hWnd
, wID
);
505 if (hDlgCtrl
!= NULL
)
508 if (SendMessageW(hDlgCtrl
, BM_GETCHECK
, 0, 0) != fValue
)
510 /* update control state */
511 SendMessageW(hDlgCtrl
, BM_SETCHECK
, (WPARAM
)fValue
, 0);
520 UpdateDialogLineSliderControl(
521 PPREFERENCES_CONTEXT PrefContext
,
530 WCHAR LineName
[MIXER_LONG_NAME_CHARS
];
532 /* find the index of this line */
533 for(Index
= 0; Index
< PrefContext
->Count
; Index
++)
536 wID
= (Index
+ 1) * IDC_LINE_NAME
;
538 if (GetDlgItemText(PrefContext
->MixerWindow
->hWnd
, wID
, LineName
, MIXER_LONG_NAME_CHARS
) == 0)
540 /* failed to retrieve id */
544 /* check if the line name matches */
545 if (!wcsicmp(LineName
, Line
->szName
))
547 /* found matching line name */
548 wID
= (Index
+ 1) * dwDialogID
;
550 /* get dialog control */
551 hDlgCtrl
= GetDlgItem(PrefContext
->MixerWindow
->hWnd
, wID
);
553 if (hDlgCtrl
!= NULL
)
556 LRESULT OldPosition
= SendMessageW(hDlgCtrl
, TBM_GETPOS
, 0, 0);
557 if (OldPosition
!= Position
)
559 /* update control state */
560 SendMessageW(hDlgCtrl
, TBM_SETPOS
, (WPARAM
)TRUE
, Position
+ Index
);