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
12 #define DIALOG_VOLUME_SIZE (150)
17 IN LPCWSTR ResourceName
,
18 OUT LPDWORD ResourceLength
)
25 hSrc
= FindResourceW(hModule
, ResourceName
, (LPCWSTR
)RT_DIALOG
);
29 /* failed to find resource */
33 /* now load the resource */
34 hRes
= LoadResource(hAppInstance
, hSrc
);
37 /* failed to load resource */
41 /* now lock the resource */
42 Result
= LockResource(hRes
);
46 /* failed to lock resource */
52 /* store output length */
53 *ResourceLength
= SizeofResource(hAppInstance
, hSrc
);
64 IN LPRECT DialogOffset
,
65 IN PDLGITEMTEMPLATE DialogItem
,
66 IN DWORD DialogIdMultiplier
,
71 LPWSTR ClassName
, WindowName
= NULL
;
75 /* initialize client rectangle */
76 rect
.left
= DialogItem
->x
+ DialogOffset
->left
;
77 rect
.top
= DialogItem
->y
+ DialogOffset
->top
;
78 rect
.right
= DialogItem
->cx
;
79 rect
.bottom
= DialogItem
->cy
;
81 //MapDialogRect(hwndDialog, &rect);
83 /* move offset after dialog item */
84 Offset
= (LPWORD
)(DialogItem
+ 1);
86 if (*Offset
== 0xFFFF)
88 /* class is encoded as type */
91 /* get control type */
95 ClassName
= L
"button";
96 WindowName
= (LPWSTR
)(Offset
+ 1);
99 ClassName
= L
"static";
100 WindowName
= (LPWSTR
)(Offset
+ 1);
110 /* class name is encoded as string */
111 ClassName
= (LPWSTR
)Offset
;
114 Offset
+= wcslen(ClassName
) + 1;
117 WindowName
= (LPWSTR
)(Offset
+ 1);
120 if (DialogItem
->id
== MAXWORD
)
122 /* id is not important */
123 wID
= DialogItem
->id
;
128 wID
= DialogItem
->id
* (DialogIdMultiplier
+ 1);
131 /* now create the window */
132 hwnd
= CreateWindowExW(DialogItem
->dwExtendedStyle
,
151 /* check if this the track bar */
152 if (!wcsicmp(ClassName
, L
"msctls_trackbar32"))
155 SendMessage(hwnd
, TBM_SETRANGE
, (WPARAM
) TRUE
, (LPARAM
) MAKELONG(0, 5));
157 /* set up page size */
158 SendMessage(hwnd
, TBM_SETPAGESIZE
, 0, (LPARAM
) 1);
160 /* set available range */
161 //SendMessage(hwnd, TBM_SETSEL, (WPARAM) FALSE, (LPARAM) MAKELONG(0, 5));
164 SendMessage(hwnd
, TBM_SETPOS
, (WPARAM
) TRUE
, (LPARAM
) 0);
167 else if (!wcsicmp(ClassName
, L
"static") || !wcsicmp(ClassName
, L
"button"))
170 SendMessageW(hwnd
, WM_SETFONT
, (WPARAM
)hFont
, TRUE
);
173 //ShowWindow(hwnd, SW_SHOWNORMAL);
175 if (WindowName
!= NULL
)
177 /* position offset to start of name */
180 /* move offset past name */
181 Offset
+= wcslen((LPWSTR
)Offset
) + 1;
185 /* no name so just adjust offset */
189 /* check if there is additional data */
192 /* no additional data */
197 /* add data offset */
201 /* make sure next template is word-aligned */
202 Offset
= (LPWORD
)(((ULONG_PTR
)Offset
+ 3) & ~3);
210 IN PMIXER_WINDOW MixerWindow
,
213 DWORD DialogIdMultiplier
)
215 LPDLGTEMPLATE DialogHeader
;
216 PDLGITEMTEMPLATE DialogItem
;
223 /* get dialog header */
224 DialogHeader
= (LPDLGTEMPLATE
)DlgResource
;
227 assert(DialogHeader
->cdit
);
229 if (MixerWindow
->Window
)
230 MixerWindow
->Window
= (HWND
*)HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, MixerWindow
->Window
, (MixerWindow
->WindowCount
+ DialogHeader
->cdit
) * sizeof(HWND
));
232 MixerWindow
->Window
= (HWND
*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, DialogHeader
->cdit
* sizeof(HWND
));
233 if (!MixerWindow
->Window
)
239 /* now walk past the dialog header */
240 Offset
= (LPWORD
)(DialogHeader
+ 1);
242 /* FIXME: support menu */
243 assert(*Offset
== 0);
246 /* FIXME: support classes */
247 assert(*Offset
== 0);
250 /* FIXME: support titles */
251 assert(*Offset
== 0);
258 /* calculate font length */
259 Length
= wcslen((LPWSTR
)Offset
) + 1;
260 assert(Length
< (sizeof(FontName
) / sizeof(WCHAR
)));
263 wcscpy(FontName
, (LPWSTR
)Offset
);
265 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
);
268 /* move offset after font name */
271 /* offset is now at first dialog item control */
272 DialogItem
= (PDLGITEMTEMPLATE
)Offset
;
274 /* enumerate now all controls */
275 for(Index
= 0; Index
< DialogHeader
->cdit
; Index
++)
278 Offset
= AddDialogControl(MixerWindow
->hWnd
, &MixerWindow
->Window
[MixerWindow
->WindowCount
], DialogOffset
, DialogItem
, DialogIdMultiplier
, Font
);
283 /* move dialog item to new offset */
284 DialogItem
=(PDLGITEMTEMPLATE
)Offset
;
286 /* increment window count */
287 MixerWindow
->WindowCount
++;
294 IN PMIXER_WINDOW MixerWindow
,
295 IN LPCWSTR DialogResId
,
301 /* first load the dialog resource */
302 DlgResource
= LoadDialogResource(hModule
, DialogResId
, NULL
);
306 /* failed to load resource */
310 /* get window size */
311 GetClientRect(MixerWindow
->hWnd
, &rect
);
313 /* adjust client position */
314 rect
.left
+= (Index
* DIALOG_VOLUME_SIZE
);
317 /* now add the controls */
318 LoadDialogControls(MixerWindow
, &rect
, DlgResource
, Index
);
324 EnumConnectionsCallback(
330 WCHAR LineName
[MIXER_LONG_NAME_CHARS
];
334 UINT ControlCount
= 0, Index
;
335 LPMIXERCONTROL Control
= NULL
;
337 PPREFERENCES_CONTEXT PrefContext
= (PPREFERENCES_CONTEXT
)Context
;
339 if (Line
->cControls
!= 0)
342 if (SndMixerGetLineName(PrefContext
->MixerWindow
->Mixer
, PrefContext
->SelectedLine
, LineName
, MIXER_LONG_NAME_CHARS
, TRUE
) == -1)
344 /* failed to get line name */
348 /* check if line is found in registry settings */
349 if (ReadLineConfig(PrefContext
->DeviceName
,
357 /* load dialog resource */
358 LoadDialog(hAppInstance
, PrefContext
->MixerWindow
, MAKEINTRESOURCE(IDD_VOLUME_CTRL
), PrefContext
->Count
);
361 wID
= (PrefContext
->Count
+ 1) * IDC_LINE_NAME
;
364 SetDlgItemTextW(PrefContext
->MixerWindow
->hWnd
, wID
, Line
->szName
);
367 if (SndMixerQueryControls(Mixer
, &ControlCount
, Line
, &Control
) == TRUE
)
369 /* now go through all controls and update their states */
370 for(Index
= 0; Index
< ControlCount
; Index
++)
372 if ((Control
[Index
].dwControlType
& MIXERCONTROL_CT_CLASS_MASK
) == MIXERCONTROL_CT_CLASS_SWITCH
)
374 MIXERCONTROLDETAILS_BOOLEAN Details
;
376 /* get volume control details */
377 if (SndMixerGetVolumeControlDetails(Mixer
, Control
[Index
].dwControlID
, sizeof(MIXERCONTROLDETAILS_BOOLEAN
), (LPVOID
)&Details
) != -1)
379 /* update dialog control */
380 wID
= (PrefContext
->Count
+ 1) * IDC_LINE_SWITCH
;
382 /* get dialog control */
383 hDlgCtrl
= GetDlgItem(PrefContext
->MixerWindow
->hWnd
, wID
);
385 if (hDlgCtrl
!= NULL
)
388 if (SendMessageW(hDlgCtrl
, BM_GETCHECK
, 0, 0) != Details
.fValue
)
390 /* update control state */
391 SendMessageW(hDlgCtrl
, BM_SETCHECK
, (WPARAM
)Details
.fValue
, 0);
396 else if ((Control
[Index
].dwControlType
& MIXERCONTROL_CT_CLASS_MASK
) == MIXERCONTROL_CT_CLASS_FADER
)
398 MIXERCONTROLDETAILS_UNSIGNED Details
;
400 /* get volume control details */
401 if (SndMixerGetVolumeControlDetails(Mixer
, Control
[Index
].dwControlID
, sizeof(MIXERCONTROLDETAILS_UNSIGNED
), (LPVOID
)&Details
) != -1)
403 /* update dialog control */
405 DWORD Step
= 0x10000 / 5;
407 /* FIXME: give me granularity */
408 Position
= 5 - (Details
.dwValue
/ Step
);
410 /* FIXME support left - right slider */
411 wID
= (PrefContext
->Count
+ 1) * IDC_LINE_SLIDER_VERT
;
413 /* get dialog control */
414 hDlgCtrl
= GetDlgItem(PrefContext
->MixerWindow
->hWnd
, wID
);
416 if (hDlgCtrl
!= NULL
)
419 LRESULT OldPosition
= SendMessageW(hDlgCtrl
, TBM_GETPOS
, 0, 0);
420 if (OldPosition
!= Position
)
422 /* update control state */
423 SendMessageW(hDlgCtrl
, TBM_SETPOS
, (WPARAM
)TRUE
, Position
+ Index
);
431 HeapFree(GetProcessHeap(), 0, Control
);
434 /* increment dialog count */
435 PrefContext
->Count
++;
437 /* get application rectangle */
438 GetWindowRect(PrefContext
->MixerWindow
->hWnd
, &rect
);
440 /* now move the window */
441 MoveWindow(PrefContext
->MixerWindow
->hWnd
, rect
.left
, rect
.top
, (PrefContext
->Count
* DIALOG_VOLUME_SIZE
), rect
.bottom
- rect
.top
, TRUE
);
450 PPREFERENCES_CONTEXT PrefContext
)
454 /* set dialog count to zero */
455 PrefContext
->Count
= 0;
457 /* enumerate controls */
458 SndMixerEnumConnections(PrefContext
->MixerWindow
->Mixer
, PrefContext
->SelectedLine
, EnumConnectionsCallback
, (PVOID
)PrefContext
);
460 /* get last line seperator */
461 hDlgCtrl
= GetDlgItem(PrefContext
->MixerWindow
->hWnd
, IDC_LINE_SEP
* PrefContext
->Count
);
463 if (hDlgCtrl
!= NULL
)
465 /* hide last seperator */
466 ShowWindow(hDlgCtrl
, SW_HIDE
);
472 UpdateDialogLineSwitchControl(
473 PPREFERENCES_CONTEXT PrefContext
,
480 WCHAR LineName
[MIXER_LONG_NAME_CHARS
];
482 /* find the index of this line */
483 for(Index
= 0; Index
< PrefContext
->Count
; Index
++)
486 wID
= (Index
+ 1) * IDC_LINE_NAME
;
488 if (GetDlgItemText(PrefContext
->MixerWindow
->hWnd
, wID
, LineName
, MIXER_LONG_NAME_CHARS
) == 0)
490 /* failed to retrieve id */
494 /* check if the line name matches */
495 if (!wcsicmp(LineName
, Line
->szName
))
497 /* found matching line name */
498 wID
= (Index
+ 1) * IDC_LINE_SWITCH
;
500 /* get dialog control */
501 hDlgCtrl
= GetDlgItem(PrefContext
->MixerWindow
->hWnd
, wID
);
503 if (hDlgCtrl
!= NULL
)
506 if (SendMessageW(hDlgCtrl
, BM_GETCHECK
, 0, 0) != fValue
)
508 /* update control state */
509 SendMessageW(hDlgCtrl
, BM_SETCHECK
, (WPARAM
)fValue
, 0);
518 UpdateDialogLineSliderControl(
519 PPREFERENCES_CONTEXT PrefContext
,
528 WCHAR LineName
[MIXER_LONG_NAME_CHARS
];
530 /* find the index of this line */
531 for(Index
= 0; Index
< PrefContext
->Count
; Index
++)
534 wID
= (Index
+ 1) * IDC_LINE_NAME
;
536 if (GetDlgItemText(PrefContext
->MixerWindow
->hWnd
, wID
, LineName
, MIXER_LONG_NAME_CHARS
) == 0)
538 /* failed to retrieve id */
542 /* check if the line name matches */
543 if (!wcsicmp(LineName
, Line
->szName
))
545 /* found matching line name */
546 wID
= (Index
+ 1) * dwDialogID
;
548 /* get dialog control */
549 hDlgCtrl
= GetDlgItem(PrefContext
->MixerWindow
->hWnd
, wID
);
551 if (hDlgCtrl
!= NULL
)
554 LRESULT OldPosition
= SendMessageW(hDlgCtrl
, TBM_GETPOS
, 0, 0);
555 if (OldPosition
!= Position
)
557 /* update control state */
558 SendMessageW(hDlgCtrl
, TBM_SETPOS
, (WPARAM
)TRUE
, Position
+ Index
);