1 /* $Id: misc.c 43790 2009-10-27 10:34:16Z dgorbachev $
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS Sound Volume Control
5 * FILE: subsys/system/sndvol32/dialog.c
6 * PROGRAMMERS: Johannes Anderwald
13 #define DIALOG_VOLUME_SIZE (150)
18 IN LPCWSTR ResourceName
,
19 OUT LPDWORD ResourceLength
)
26 hSrc
= FindResourceW(hModule
, ResourceName
, (LPCWSTR
)RT_DIALOG
);
30 /* failed to find resource */
34 /* now load the resource */
35 hRes
= LoadResource(hAppInstance
, hSrc
);
38 /* failed to load resource */
42 /* now lock the resource */
43 Result
= LockResource(hRes
);
47 /* failed to lock resource */
53 /* store output length */
54 *ResourceLength
= SizeofResource(hAppInstance
, hSrc
);
65 IN LPRECT DialogOffset
,
66 IN PDLGITEMTEMPLATE DialogItem
,
67 IN DWORD DialogIdMultiplier
,
72 LPWSTR ClassName
, WindowName
= NULL
;
76 /* initialize client rectangle */
77 rect
.left
= DialogItem
->x
+ DialogOffset
->left
;
78 rect
.top
= DialogItem
->y
+ DialogOffset
->top
;
79 rect
.right
= DialogItem
->cx
;
80 rect
.bottom
= DialogItem
->cy
;
82 //MapDialogRect(hwndDialog, &rect);
84 /* move offset after dialog item */
85 Offset
= (LPWORD
)(DialogItem
+ 1);
87 if (*Offset
== 0xFFFF)
89 /* class is encoded as type */
92 /* get control type */
96 ClassName
= L
"button";
97 WindowName
= (LPWSTR
)(Offset
+ 1);
100 ClassName
= L
"static";
101 WindowName
= (LPWSTR
)(Offset
+ 1);
111 /* class name is encoded as string */
112 ClassName
= (LPWSTR
)Offset
;
115 Offset
+= wcslen(ClassName
) + 1;
118 WindowName
= (LPWSTR
)(Offset
+ 1);
121 if (DialogItem
->id
== MAXWORD
)
123 /* id is not important */
124 wID
= DialogItem
->id
;
129 wID
= DialogItem
->id
* (DialogIdMultiplier
+ 1);
132 /* now create the window */
133 hwnd
= CreateWindowExW(DialogItem
->dwExtendedStyle
,
152 /* check if this the track bar */
153 if (!wcsicmp(ClassName
, L
"msctls_trackbar32"))
156 SendMessage(hwnd
, TBM_SETRANGE
, (WPARAM
) TRUE
, (LPARAM
) MAKELONG(0, 5));
158 /* set up page size */
159 SendMessage(hwnd
, TBM_SETPAGESIZE
, 0, (LPARAM
) 1);
161 /* set available range */
162 //SendMessage(hwnd, TBM_SETSEL, (WPARAM) FALSE, (LPARAM) MAKELONG(0, 5));
165 SendMessage(hwnd
, TBM_SETPOS
, (WPARAM
) TRUE
, (LPARAM
) 0);
168 else if (!wcsicmp(ClassName
, L
"static") || !wcsicmp(ClassName
, L
"button"))
171 SendMessageW(hwnd
, WM_SETFONT
, (WPARAM
)hFont
, TRUE
);
174 //ShowWindow(hwnd, SW_SHOWNORMAL);
176 if (WindowName
!= NULL
)
178 /* position offset to start of name */
181 /* move offset past name */
182 Offset
+= wcslen((LPWSTR
)Offset
) + 1;
186 /* no name so just adjust offset */
190 /* check if there is additional data */
193 /* no additional data */
198 /* add data offset */
202 /* make sure next template is word-aligned */
203 Offset
= (LPWORD
)(((ULONG_PTR
)Offset
+ 3) & ~3);
211 IN PMIXER_WINDOW MixerWindow
,
214 DWORD DialogIdMultiplier
)
216 LPDLGTEMPLATE DialogHeader
;
217 PDLGITEMTEMPLATE DialogItem
;
224 /* get dialog header */
225 DialogHeader
= (LPDLGTEMPLATE
)DlgResource
;
228 assert(DialogHeader
->cdit
);
230 if (MixerWindow
->Window
)
231 MixerWindow
->Window
= (HWND
*)HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, MixerWindow
->Window
, (MixerWindow
->WindowCount
+ DialogHeader
->cdit
) * sizeof(HWND
));
233 MixerWindow
->Window
= (HWND
*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, DialogHeader
->cdit
* sizeof(HWND
));
234 if (!MixerWindow
->Window
)
240 /* now walk past the dialog header */
241 Offset
= (LPWORD
)(DialogHeader
+ 1);
243 /* FIXME: support menu */
244 assert(*Offset
== 0);
247 /* FIXME: support classes */
248 assert(*Offset
== 0);
251 /* FIXME: support titles */
252 assert(*Offset
== 0);
259 /* calculate font length */
260 Length
= wcslen((LPWSTR
)Offset
) + 1;
261 assert(Length
< (sizeof(FontName
) / sizeof(WCHAR
)));
264 wcscpy(FontName
, (LPWSTR
)Offset
);
266 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
);
269 /* move offset after font name */
272 /* offset is now at first dialog item control */
273 DialogItem
= (PDLGITEMTEMPLATE
)Offset
;
275 /* enumerate now all controls */
276 for(Index
= 0; Index
< DialogHeader
->cdit
; Index
++)
279 Offset
= AddDialogControl(MixerWindow
->hWnd
, &MixerWindow
->Window
[MixerWindow
->WindowCount
], DialogOffset
, DialogItem
, DialogIdMultiplier
, Font
);
284 /* move dialog item to new offset */
285 DialogItem
=(PDLGITEMTEMPLATE
)Offset
;
287 /* increment window count */
288 MixerWindow
->WindowCount
++;
295 IN PMIXER_WINDOW MixerWindow
,
296 IN LPCWSTR DialogResId
,
302 /* first load the dialog resource */
303 DlgResource
= LoadDialogResource(hModule
, DialogResId
, NULL
);
307 /* failed to load resource */
311 /* get window size */
312 GetClientRect(MixerWindow
->hWnd
, &rect
);
314 /* adjust client position */
315 rect
.left
+= (Index
* DIALOG_VOLUME_SIZE
);
318 /* now add the controls */
319 LoadDialogControls(MixerWindow
, &rect
, DlgResource
, Index
);
325 EnumConnectionsCallback(
331 WCHAR LineName
[MIXER_LONG_NAME_CHARS
];
335 UINT ControlCount
= 0, Index
;
336 LPMIXERCONTROL Control
= NULL
;
338 PPREFERENCES_CONTEXT PrefContext
= (PPREFERENCES_CONTEXT
)Context
;
340 if (Line
->cControls
!= 0)
343 if (SndMixerGetLineName(PrefContext
->MixerWindow
->Mixer
, PrefContext
->SelectedLine
, LineName
, MIXER_LONG_NAME_CHARS
, TRUE
) == -1)
345 /* failed to get line name */
349 /* check if line is found in registry settings */
350 if (ReadLineConfig(PrefContext
->DeviceName
,
358 /* load dialog resource */
359 LoadDialog(hAppInstance
, PrefContext
->MixerWindow
, MAKEINTRESOURCE(IDD_VOLUME_CTRL
), PrefContext
->Count
);
362 wID
= (PrefContext
->Count
+ 1) * IDC_LINE_NAME
;
365 SetDlgItemTextW(PrefContext
->MixerWindow
->hWnd
, wID
, Line
->szName
);
368 if (SndMixerQueryControls(Mixer
, &ControlCount
, Line
, &Control
) == TRUE
)
370 /* now go through all controls and update their states */
371 for(Index
= 0; Index
< ControlCount
; Index
++)
373 if ((Control
[Index
].dwControlType
& MIXERCONTROL_CT_CLASS_MASK
) == MIXERCONTROL_CT_CLASS_SWITCH
)
375 MIXERCONTROLDETAILS_BOOLEAN Details
;
377 /* get volume control details */
378 if (SndMixerGetVolumeControlDetails(Mixer
, Control
[Index
].dwControlID
, sizeof(MIXERCONTROLDETAILS_BOOLEAN
), (LPVOID
)&Details
) != -1)
380 /* update dialog control */
381 wID
= (PrefContext
->Count
+ 1) * IDC_LINE_SWITCH
;
383 /* get dialog control */
384 hDlgCtrl
= GetDlgItem(PrefContext
->MixerWindow
->hWnd
, wID
);
386 if (hDlgCtrl
!= NULL
)
389 if (SendMessageW(hDlgCtrl
, BM_GETCHECK
, 0, 0) != Details
.fValue
)
391 /* update control state */
392 SendMessageW(hDlgCtrl
, BM_SETCHECK
, (WPARAM
)Details
.fValue
, 0);
397 else if ((Control
[Index
].dwControlType
& MIXERCONTROL_CT_CLASS_MASK
) == MIXERCONTROL_CT_CLASS_FADER
)
399 MIXERCONTROLDETAILS_UNSIGNED Details
;
401 /* get volume control details */
402 if (SndMixerGetVolumeControlDetails(Mixer
, Control
[Index
].dwControlID
, sizeof(MIXERCONTROLDETAILS_UNSIGNED
), (LPVOID
)&Details
) != -1)
404 /* update dialog control */
406 DWORD Step
= 0x10000 / 5;
408 /* FIXME: give me granularity */
409 Position
= 5 - (Details
.dwValue
/ Step
);
411 /* FIXME support left - right slider */
412 wID
= (PrefContext
->Count
+ 1) * IDC_LINE_SLIDER_VERT
;
414 /* get dialog control */
415 hDlgCtrl
= GetDlgItem(PrefContext
->MixerWindow
->hWnd
, wID
);
417 if (hDlgCtrl
!= NULL
)
420 LRESULT OldPosition
= SendMessageW(hDlgCtrl
, TBM_GETPOS
, 0, 0);
421 if (OldPosition
!= Position
)
423 /* update control state */
424 SendMessageW(hDlgCtrl
, TBM_SETPOS
, (WPARAM
)TRUE
, Position
+ Index
);
432 HeapFree(GetProcessHeap(), 0, Control
);
435 /* increment dialog count */
436 PrefContext
->Count
++;
438 /* get application rectangle */
439 GetWindowRect(PrefContext
->MixerWindow
->hWnd
, &rect
);
441 /* now move the window */
442 MoveWindow(PrefContext
->MixerWindow
->hWnd
, rect
.left
, rect
.top
, (PrefContext
->Count
* DIALOG_VOLUME_SIZE
), rect
.bottom
- rect
.top
, TRUE
);
451 PPREFERENCES_CONTEXT PrefContext
)
455 /* set dialog count to zero */
456 PrefContext
->Count
= 0;
458 /* enumerate controls */
459 SndMixerEnumConnections(PrefContext
->MixerWindow
->Mixer
, PrefContext
->SelectedLine
, EnumConnectionsCallback
, (PVOID
)PrefContext
);
461 /* get last line seperator */
462 hDlgCtrl
= GetDlgItem(PrefContext
->MixerWindow
->hWnd
, IDC_LINE_SEP
* PrefContext
->Count
);
464 if (hDlgCtrl
!= NULL
)
466 /* hide last seperator */
467 ShowWindow(hDlgCtrl
, SW_HIDE
);
473 UpdateDialogLineSwitchControl(
474 PPREFERENCES_CONTEXT PrefContext
,
481 WCHAR LineName
[MIXER_LONG_NAME_CHARS
];
483 /* find the index of this line */
484 for(Index
= 0; Index
< PrefContext
->Count
; Index
++)
487 wID
= (Index
+ 1) * IDC_LINE_NAME
;
489 if (GetDlgItemText(PrefContext
->MixerWindow
->hWnd
, wID
, LineName
, MIXER_LONG_NAME_CHARS
) == 0)
491 /* failed to retrieve id */
495 /* check if the line name matches */
496 if (!wcsicmp(LineName
, Line
->szName
))
498 /* found matching line name */
499 wID
= (Index
+ 1) * IDC_LINE_SWITCH
;
501 /* get dialog control */
502 hDlgCtrl
= GetDlgItem(PrefContext
->MixerWindow
->hWnd
, wID
);
504 if (hDlgCtrl
!= NULL
)
507 if (SendMessageW(hDlgCtrl
, BM_GETCHECK
, 0, 0) != fValue
)
509 /* update control state */
510 SendMessageW(hDlgCtrl
, BM_SETCHECK
, (WPARAM
)fValue
, 0);
519 UpdateDialogLineSliderControl(
520 PPREFERENCES_CONTEXT PrefContext
,
529 WCHAR LineName
[MIXER_LONG_NAME_CHARS
];
531 /* find the index of this line */
532 for(Index
= 0; Index
< PrefContext
->Count
; Index
++)
535 wID
= (Index
+ 1) * IDC_LINE_NAME
;
537 if (GetDlgItemText(PrefContext
->MixerWindow
->hWnd
, wID
, LineName
, MIXER_LONG_NAME_CHARS
) == 0)
539 /* failed to retrieve id */
543 /* check if the line name matches */
544 if (!wcsicmp(LineName
, Line
->szName
))
546 /* found matching line name */
547 wID
= (Index
+ 1) * dwDialogID
;
549 /* get dialog control */
550 hDlgCtrl
= GetDlgItem(PrefContext
->MixerWindow
->hWnd
, wID
);
552 if (hDlgCtrl
!= NULL
)
555 LRESULT OldPosition
= SendMessageW(hDlgCtrl
, TBM_GETPOS
, 0, 0);
556 if (OldPosition
!= Position
)
558 /* update control state */
559 SendMessageW(hDlgCtrl
, TBM_SETPOS
, (WPARAM
)TRUE
, Position
+ Index
);