2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Sound Volume Control
4 * FILE: base/applications/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
;
115 /* move offset to the end of class string */
116 Offset
+= wcslen(ClassName
);
118 /* get window name */
119 WindowName
= (LPWSTR
)(Offset
+ 1);
122 /* move offset past class type/string */
125 if (DialogItem
->id
== MAXWORD
)
127 /* id is not important */
128 wID
= DialogItem
->id
;
133 wID
= DialogItem
->id
* (DialogIdMultiplier
+ 1);
136 /* now create the window */
137 hwnd
= CreateWindowExW(DialogItem
->dwExtendedStyle
,
156 /* check if this the track bar */
157 if (!wcsicmp(ClassName
, L
"msctls_trackbar32"))
160 SendMessage(hwnd
, TBM_SETRANGE
, (WPARAM
) TRUE
, (LPARAM
) MAKELONG(0, 5));
162 /* set up page size */
163 SendMessage(hwnd
, TBM_SETPAGESIZE
, 0, (LPARAM
) 1);
165 /* set available range */
166 //SendMessage(hwnd, TBM_SETSEL, (WPARAM) FALSE, (LPARAM) MAKELONG(0, 5));
169 SendMessage(hwnd
, TBM_SETPOS
, (WPARAM
) TRUE
, (LPARAM
) 0);
172 else if (!wcsicmp(ClassName
, L
"static") || !wcsicmp(ClassName
, L
"button"))
175 SendMessageW(hwnd
, WM_SETFONT
, (WPARAM
)hFont
, TRUE
);
178 //ShowWindow(hwnd, SW_SHOWNORMAL);
180 if (WindowName
!= NULL
)
182 /* move offset past window name */
183 Offset
+= wcslen(WindowName
) + 1;
186 /* check if there is additional data */
189 /* no additional data */
194 /* FIXME: Determine whether this should be "Offset += 1 + *Offset" to explicitly skip the data count too. */
195 /* skip past additional data */
199 /* make sure next template is word-aligned */
200 Offset
= (LPWORD
)(((ULONG_PTR
)Offset
+ 3) & ~3);
208 IN PMIXER_WINDOW MixerWindow
,
211 DWORD DialogIdMultiplier
)
213 LPDLGTEMPLATE DialogHeader
;
214 PDLGITEMTEMPLATE DialogItem
;
221 /* get dialog header */
222 DialogHeader
= (LPDLGTEMPLATE
)DlgResource
;
225 assert(DialogHeader
->cdit
);
227 if (MixerWindow
->Window
)
228 MixerWindow
->Window
= (HWND
*)HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, MixerWindow
->Window
, (MixerWindow
->WindowCount
+ DialogHeader
->cdit
) * sizeof(HWND
));
230 MixerWindow
->Window
= (HWND
*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, DialogHeader
->cdit
* sizeof(HWND
));
231 if (!MixerWindow
->Window
)
237 /* now walk past the dialog header */
238 Offset
= (LPWORD
)(DialogHeader
+ 1);
240 /* FIXME: support menu */
241 assert(*Offset
== 0);
244 /* FIXME: support classes */
245 assert(*Offset
== 0);
248 /* FIXME: support titles */
249 assert(*Offset
== 0);
256 /* calculate font length */
257 Length
= wcslen((LPWSTR
)Offset
) + 1;
258 assert(Length
< (sizeof(FontName
) / sizeof(WCHAR
)));
261 wcscpy(FontName
, (LPWSTR
)Offset
);
263 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
);
266 /* move offset after font name */
269 /* offset is now at first dialog item control */
270 DialogItem
= (PDLGITEMTEMPLATE
)Offset
;
272 /* enumerate now all controls */
273 for(Index
= 0; Index
< DialogHeader
->cdit
; Index
++)
276 Offset
= AddDialogControl(MixerWindow
->hWnd
, &MixerWindow
->Window
[MixerWindow
->WindowCount
], DialogOffset
, DialogItem
, DialogIdMultiplier
, Font
);
281 /* move dialog item to new offset */
282 DialogItem
=(PDLGITEMTEMPLATE
)Offset
;
284 /* increment window count */
285 MixerWindow
->WindowCount
++;
292 IN PMIXER_WINDOW MixerWindow
,
293 IN LPCWSTR DialogResId
,
299 /* first load the dialog resource */
300 DlgResource
= LoadDialogResource(hModule
, DialogResId
, NULL
);
304 /* failed to load resource */
308 /* get window size */
309 GetClientRect(MixerWindow
->hWnd
, &rect
);
311 /* adjust client position */
312 rect
.left
+= (Index
* DIALOG_VOLUME_SIZE
);
315 /* now add the controls */
316 LoadDialogControls(MixerWindow
, &rect
, DlgResource
, Index
);
322 EnumConnectionsCallback(
328 WCHAR LineName
[MIXER_LONG_NAME_CHARS
];
332 UINT ControlCount
= 0, Index
;
333 LPMIXERCONTROL Control
= NULL
;
335 PPREFERENCES_CONTEXT PrefContext
= (PPREFERENCES_CONTEXT
)Context
;
337 if (Line
->cControls
!= 0)
340 if (SndMixerGetLineName(PrefContext
->MixerWindow
->Mixer
, PrefContext
->SelectedLine
, LineName
, MIXER_LONG_NAME_CHARS
, TRUE
) == -1)
342 /* failed to get line name */
346 /* check if line is found in registry settings */
347 if (ReadLineConfig(PrefContext
->DeviceName
,
355 /* load dialog resource */
356 LoadDialog(hAppInstance
, PrefContext
->MixerWindow
, MAKEINTRESOURCE(IDD_VOLUME_CTRL
), PrefContext
->Count
);
359 wID
= (PrefContext
->Count
+ 1) * IDC_LINE_NAME
;
362 SetDlgItemTextW(PrefContext
->MixerWindow
->hWnd
, wID
, Line
->szName
);
365 if (SndMixerQueryControls(Mixer
, &ControlCount
, Line
, &Control
) != FALSE
)
367 /* now go through all controls and update their states */
368 for(Index
= 0; Index
< ControlCount
; Index
++)
370 if ((Control
[Index
].dwControlType
& MIXERCONTROL_CT_CLASS_MASK
) == MIXERCONTROL_CT_CLASS_SWITCH
)
372 MIXERCONTROLDETAILS_BOOLEAN Details
;
374 /* get volume control details */
375 if (SndMixerGetVolumeControlDetails(Mixer
, Control
[Index
].dwControlID
, sizeof(MIXERCONTROLDETAILS_BOOLEAN
), (LPVOID
)&Details
) != -1)
377 /* update dialog control */
378 wID
= (PrefContext
->Count
+ 1) * IDC_LINE_SWITCH
;
380 /* get dialog control */
381 hDlgCtrl
= GetDlgItem(PrefContext
->MixerWindow
->hWnd
, wID
);
383 if (hDlgCtrl
!= NULL
)
386 if (SendMessageW(hDlgCtrl
, BM_GETCHECK
, 0, 0) != Details
.fValue
)
388 /* update control state */
389 SendMessageW(hDlgCtrl
, BM_SETCHECK
, (WPARAM
)Details
.fValue
, 0);
394 else if ((Control
[Index
].dwControlType
& MIXERCONTROL_CT_CLASS_MASK
) == MIXERCONTROL_CT_CLASS_FADER
)
396 MIXERCONTROLDETAILS_UNSIGNED Details
;
398 /* get volume control details */
399 if (SndMixerGetVolumeControlDetails(Mixer
, Control
[Index
].dwControlID
, sizeof(MIXERCONTROLDETAILS_UNSIGNED
), (LPVOID
)&Details
) != -1)
401 /* update dialog control */
403 DWORD Step
= 0x10000 / 5;
405 /* FIXME: give me granularity */
406 Position
= 5 - (Details
.dwValue
/ Step
);
408 /* FIXME support left - right slider */
409 wID
= (PrefContext
->Count
+ 1) * IDC_LINE_SLIDER_VERT
;
411 /* get dialog control */
412 hDlgCtrl
= GetDlgItem(PrefContext
->MixerWindow
->hWnd
, wID
);
414 if (hDlgCtrl
!= NULL
)
417 LRESULT OldPosition
= SendMessageW(hDlgCtrl
, TBM_GETPOS
, 0, 0);
418 if (OldPosition
!= Position
)
420 /* update control state */
421 SendMessageW(hDlgCtrl
, TBM_SETPOS
, (WPARAM
)TRUE
, Position
+ Index
);
429 HeapFree(GetProcessHeap(), 0, Control
);
432 /* increment dialog count */
433 PrefContext
->Count
++;
435 /* get application rectangle */
436 GetWindowRect(PrefContext
->MixerWindow
->hWnd
, &rect
);
438 /* now move the window */
439 MoveWindow(PrefContext
->MixerWindow
->hWnd
, rect
.left
, rect
.top
, (PrefContext
->Count
* DIALOG_VOLUME_SIZE
), rect
.bottom
- rect
.top
, TRUE
);
448 PPREFERENCES_CONTEXT PrefContext
)
452 /* set dialog count to zero */
453 PrefContext
->Count
= 0;
455 /* enumerate controls */
456 SndMixerEnumConnections(PrefContext
->MixerWindow
->Mixer
, PrefContext
->SelectedLine
, EnumConnectionsCallback
, (PVOID
)PrefContext
);
458 /* get last line separator */
459 hDlgCtrl
= GetDlgItem(PrefContext
->MixerWindow
->hWnd
, IDC_LINE_SEP
* PrefContext
->Count
);
461 if (hDlgCtrl
!= NULL
)
463 /* hide last separator */
464 ShowWindow(hDlgCtrl
, SW_HIDE
);
470 UpdateDialogLineSwitchControl(
471 PPREFERENCES_CONTEXT PrefContext
,
478 WCHAR LineName
[MIXER_LONG_NAME_CHARS
];
480 /* find the index of this line */
481 for(Index
= 0; Index
< PrefContext
->Count
; Index
++)
484 wID
= (Index
+ 1) * IDC_LINE_NAME
;
486 if (GetDlgItemText(PrefContext
->MixerWindow
->hWnd
, wID
, LineName
, MIXER_LONG_NAME_CHARS
) == 0)
488 /* failed to retrieve id */
492 /* check if the line name matches */
493 if (!wcsicmp(LineName
, Line
->szName
))
495 /* found matching line name */
496 wID
= (Index
+ 1) * IDC_LINE_SWITCH
;
498 /* get dialog control */
499 hDlgCtrl
= GetDlgItem(PrefContext
->MixerWindow
->hWnd
, wID
);
501 if (hDlgCtrl
!= NULL
)
504 if (SendMessageW(hDlgCtrl
, BM_GETCHECK
, 0, 0) != fValue
)
506 /* update control state */
507 SendMessageW(hDlgCtrl
, BM_SETCHECK
, (WPARAM
)fValue
, 0);
516 UpdateDialogLineSliderControl(
517 PPREFERENCES_CONTEXT PrefContext
,
526 WCHAR LineName
[MIXER_LONG_NAME_CHARS
];
528 /* find the index of this line */
529 for(Index
= 0; Index
< PrefContext
->Count
; Index
++)
532 wID
= (Index
+ 1) * IDC_LINE_NAME
;
534 if (GetDlgItemText(PrefContext
->MixerWindow
->hWnd
, wID
, LineName
, MIXER_LONG_NAME_CHARS
) == 0)
536 /* failed to retrieve id */
540 /* check if the line name matches */
541 if (!wcsicmp(LineName
, Line
->szName
))
543 /* found matching line name */
544 wID
= (Index
+ 1) * dwDialogID
;
546 /* get dialog control */
547 hDlgCtrl
= GetDlgItem(PrefContext
->MixerWindow
->hWnd
, wID
);
549 if (hDlgCtrl
!= NULL
)
552 LRESULT OldPosition
= SendMessageW(hDlgCtrl
, TBM_GETPOS
, 0, 0);
553 if (OldPosition
!= Position
)
555 /* update control state */
556 SendMessageW(hDlgCtrl
, TBM_SETPOS
, (WPARAM
)TRUE
, Position
+ Index
);