Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygendialog.c
Go to the documentation of this file.
00001 /* $Id: misc.c 43790 2009-10-27 10:34:16Z dgorbachev $ 00002 * 00003 * COPYRIGHT: See COPYING in the top level directory 00004 * PROJECT: ReactOS Sound Volume Control 00005 * FILE: subsys/system/sndvol32/dialog.c 00006 * PROGRAMMERS: Johannes Anderwald 00007 */ 00008 #include "sndvol32.h" 00009 00010 00011 #define XLEFT (30) 00012 #define XTOP (20) 00013 #define DIALOG_VOLUME_SIZE (150) 00014 00015 LPVOID 00016 LoadDialogResource( 00017 IN HMODULE hModule, 00018 IN LPCWSTR ResourceName, 00019 OUT LPDWORD ResourceLength) 00020 { 00021 HRSRC hSrc; 00022 HGLOBAL hRes; 00023 PVOID Result; 00024 00025 /* find resource */ 00026 hSrc = FindResourceW(hModule, ResourceName, (LPCWSTR)RT_DIALOG); 00027 00028 if (!hSrc) 00029 { 00030 /* failed to find resource */ 00031 return NULL; 00032 } 00033 00034 /* now load the resource */ 00035 hRes = LoadResource(hAppInstance, hSrc); 00036 if (!hRes) 00037 { 00038 /* failed to load resource */ 00039 return NULL; 00040 } 00041 00042 /* now lock the resource */ 00043 Result = LockResource(hRes); 00044 00045 if (!Result) 00046 { 00047 /* failed to lock resource */ 00048 return NULL; 00049 } 00050 00051 if (ResourceLength) 00052 { 00053 /* store output length */ 00054 *ResourceLength = SizeofResource(hAppInstance, hSrc); 00055 } 00056 00057 /* done */ 00058 return Result; 00059 } 00060 00061 LPWORD 00062 AddDialogControl( 00063 IN HWND hwndDialog, 00064 IN HWND * OutWnd, 00065 IN LPRECT DialogOffset, 00066 IN PDLGITEMTEMPLATE DialogItem, 00067 IN DWORD DialogIdMultiplier, 00068 IN HFONT hFont) 00069 { 00070 RECT rect; 00071 LPWORD Offset; 00072 LPWSTR ClassName, WindowName = NULL; 00073 HWND hwnd; 00074 DWORD wID; 00075 00076 /* initialize client rectangle */ 00077 rect.left = DialogItem->x + DialogOffset->left; 00078 rect.top = DialogItem->y + DialogOffset->top; 00079 rect.right = DialogItem->cx; 00080 rect.bottom = DialogItem->cy; 00081 00082 //MapDialogRect(hwndDialog, &rect); 00083 00084 /* move offset after dialog item */ 00085 Offset = (LPWORD)(DialogItem + 1); 00086 00087 if (*Offset == 0xFFFF) 00088 { 00089 /* class is encoded as type */ 00090 Offset++; 00091 00092 /* get control type */ 00093 switch(*Offset) 00094 { 00095 case 0x80: 00096 ClassName = L"button"; 00097 WindowName = (LPWSTR)(Offset + 1); 00098 break ; 00099 case 0x82: 00100 ClassName = L"static"; 00101 WindowName = (LPWSTR)(Offset + 1); 00102 break; 00103 default: 00104 /* FIXME */ 00105 assert(0); 00106 ClassName = 0; 00107 } 00108 } 00109 else 00110 { 00111 /* class name is encoded as string */ 00112 ClassName = (LPWSTR)Offset; 00113 00114 /* adjust offset */ 00115 Offset += wcslen(ClassName) + 1; 00116 00117 /* get offset */ 00118 WindowName = (LPWSTR)(Offset + 1); 00119 } 00120 00121 if (DialogItem->id == MAXWORD) 00122 { 00123 /* id is not important */ 00124 wID = DialogItem->id; 00125 } 00126 else 00127 { 00128 /* calculate id */ 00129 wID = DialogItem->id * (DialogIdMultiplier + 1); 00130 00131 } 00132 /* now create the window */ 00133 hwnd = CreateWindowExW(DialogItem->dwExtendedStyle, 00134 ClassName, 00135 WindowName, 00136 DialogItem->style, 00137 rect.left, 00138 rect.top, 00139 rect.right, 00140 rect.bottom, 00141 hwndDialog, 00142 (HMENU)(wID), 00143 hAppInstance, 00144 NULL); 00145 00146 /* sanity check */ 00147 assert(hwnd); 00148 00149 /* store window */ 00150 *OutWnd = hwnd; 00151 00152 /* check if this the track bar */ 00153 if (!wcsicmp(ClassName, L"msctls_trackbar32")) 00154 { 00155 /* set up range */ 00156 SendMessage(hwnd, TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG(0, 5)); 00157 00158 /* set up page size */ 00159 SendMessage(hwnd, TBM_SETPAGESIZE, 0, (LPARAM) 1); 00160 00161 /* set available range */ 00162 //SendMessage(hwnd, TBM_SETSEL, (WPARAM) FALSE, (LPARAM) MAKELONG(0, 5)); 00163 00164 /* set position */ 00165 SendMessage(hwnd, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) 0); 00166 00167 } 00168 else if (!wcsicmp(ClassName, L"static") || !wcsicmp(ClassName, L"button")) 00169 { 00170 /* set font */ 00171 SendMessageW(hwnd, WM_SETFONT, (WPARAM)hFont, TRUE); 00172 } 00173 00174 //ShowWindow(hwnd, SW_SHOWNORMAL); 00175 00176 if (WindowName != NULL) 00177 { 00178 /* position offset to start of name */ 00179 Offset++; 00180 00181 /* move offset past name */ 00182 Offset += wcslen((LPWSTR)Offset) + 1; 00183 } 00184 else 00185 { 00186 /* no name so just adjust offset */ 00187 Offset++; 00188 } 00189 00190 /* check if there is additional data */ 00191 if (*Offset == 0) 00192 { 00193 /* no additional data */ 00194 Offset++; 00195 } 00196 else 00197 { 00198 /* add data offset */ 00199 Offset += *Offset; 00200 } 00201 00202 /* make sure next template is word-aligned */ 00203 Offset = (LPWORD)(((ULONG_PTR)Offset + 3) & ~3); 00204 00205 /* done */ 00206 return Offset; 00207 } 00208 00209 VOID 00210 LoadDialogControls( 00211 IN PMIXER_WINDOW MixerWindow, 00212 LPRECT DialogOffset, 00213 LPVOID DlgResource, 00214 DWORD DialogIdMultiplier) 00215 { 00216 LPDLGTEMPLATE DialogHeader; 00217 PDLGITEMTEMPLATE DialogItem; 00218 LPWORD Offset; 00219 WORD FontSize; 00220 WCHAR FontName[100]; 00221 WORD Length, Index; 00222 HFONT Font; 00223 00224 /* get dialog header */ 00225 DialogHeader = (LPDLGTEMPLATE)DlgResource; 00226 00227 /* sanity check */ 00228 assert(DialogHeader->cdit); 00229 00230 if (MixerWindow->Window) 00231 MixerWindow->Window = (HWND*)HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, MixerWindow->Window, (MixerWindow->WindowCount + DialogHeader->cdit) * sizeof(HWND)); 00232 else 00233 MixerWindow->Window = (HWND*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, DialogHeader->cdit * sizeof(HWND)); 00234 if (!MixerWindow->Window) 00235 { 00236 /* no memory */ 00237 return; 00238 } 00239 00240 /* now walk past the dialog header */ 00241 Offset = (LPWORD)(DialogHeader + 1); 00242 00243 /* FIXME: support menu */ 00244 assert(*Offset == 0); 00245 Offset++; 00246 00247 /* FIXME: support classes */ 00248 assert(*Offset == 0); 00249 Offset++; 00250 00251 /* FIXME: support titles */ 00252 assert(*Offset == 0); 00253 Offset++; 00254 00255 /* get font size */ 00256 FontSize = *Offset; 00257 Offset++; 00258 00259 /* calculate font length */ 00260 Length = wcslen((LPWSTR)Offset) + 1; 00261 assert(Length < (sizeof(FontName) / sizeof(WCHAR))); 00262 00263 /* copy font */ 00264 wcscpy(FontName, (LPWSTR)Offset); 00265 00266 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); 00267 assert(Font); 00268 00269 /* move offset after font name */ 00270 Offset += Length; 00271 00272 /* offset is now at first dialog item control */ 00273 DialogItem = (PDLGITEMTEMPLATE)Offset; 00274 00275 /* enumerate now all controls */ 00276 for(Index = 0; Index < DialogHeader->cdit; Index++) 00277 { 00278 /* add controls */ 00279 Offset = AddDialogControl(MixerWindow->hWnd, &MixerWindow->Window[MixerWindow->WindowCount], DialogOffset, DialogItem, DialogIdMultiplier, Font); 00280 00281 /* sanity check */ 00282 assert(Offset); 00283 00284 /* move dialog item to new offset */ 00285 DialogItem =(PDLGITEMTEMPLATE)Offset; 00286 00287 /* increment window count */ 00288 MixerWindow->WindowCount++; 00289 } 00290 } 00291 00292 VOID 00293 LoadDialog( 00294 IN HMODULE hModule, 00295 IN PMIXER_WINDOW MixerWindow, 00296 IN LPCWSTR DialogResId, 00297 IN DWORD Index) 00298 { 00299 LPVOID DlgResource; 00300 RECT rect; 00301 00302 /* first load the dialog resource */ 00303 DlgResource = LoadDialogResource(hModule, DialogResId, NULL); 00304 00305 if (!DlgResource) 00306 { 00307 /* failed to load resource */ 00308 return; 00309 } 00310 00311 /* get window size */ 00312 GetClientRect(MixerWindow->hWnd, &rect); 00313 00314 /* adjust client position */ 00315 rect.left += (Index * DIALOG_VOLUME_SIZE); 00316 00317 00318 /* now add the controls */ 00319 LoadDialogControls(MixerWindow, &rect, DlgResource, Index); 00320 00321 } 00322 00323 BOOL 00324 CALLBACK 00325 EnumConnectionsCallback( 00326 PSND_MIXER Mixer, 00327 DWORD LineID, 00328 LPMIXERLINE Line, 00329 PVOID Context) 00330 { 00331 WCHAR LineName[MIXER_LONG_NAME_CHARS]; 00332 DWORD Flags; 00333 DWORD wID; 00334 RECT rect; 00335 UINT ControlCount = 0, Index; 00336 LPMIXERCONTROL Control = NULL; 00337 HWND hDlgCtrl; 00338 PPREFERENCES_CONTEXT PrefContext = (PPREFERENCES_CONTEXT)Context; 00339 00340 if (Line->cControls != 0) 00341 { 00342 /* get line name */ 00343 if (SndMixerGetLineName(PrefContext->MixerWindow->Mixer, PrefContext->SelectedLine, LineName, MIXER_LONG_NAME_CHARS, TRUE) == -1) 00344 { 00345 /* failed to get line name */ 00346 LineName[0] = L'\0'; 00347 } 00348 00349 /* check if line is found in registry settings */ 00350 if (ReadLineConfig(PrefContext->DeviceName, 00351 LineName, 00352 Line->szName, 00353 &Flags)) 00354 { 00355 /* is it selected */ 00356 if (Flags != 0x4) 00357 { 00358 /* load dialog resource */ 00359 LoadDialog(hAppInstance, PrefContext->MixerWindow, MAKEINTRESOURCE(IDD_VOLUME_CTRL), PrefContext->Count); 00360 00361 /* get id */ 00362 wID = (PrefContext->Count + 1) * IDC_LINE_NAME; 00363 00364 /* set line name */ 00365 SetDlgItemTextW(PrefContext->MixerWindow->hWnd, wID, Line->szName); 00366 00367 /* query controls */ 00368 if (SndMixerQueryControls(Mixer, &ControlCount, Line, &Control) == TRUE) 00369 { 00370 /* now go through all controls and update their states */ 00371 for(Index = 0; Index < ControlCount; Index++) 00372 { 00373 if ((Control[Index].dwControlType & MIXERCONTROL_CT_CLASS_MASK) == MIXERCONTROL_CT_CLASS_SWITCH) 00374 { 00375 MIXERCONTROLDETAILS_BOOLEAN Details; 00376 00377 /* get volume control details */ 00378 if (SndMixerGetVolumeControlDetails(Mixer, Control[Index].dwControlID, sizeof(MIXERCONTROLDETAILS_BOOLEAN), (LPVOID)&Details) != -1) 00379 { 00380 /* update dialog control */ 00381 wID = (PrefContext->Count + 1) * IDC_LINE_SWITCH; 00382 00383 /* get dialog control */ 00384 hDlgCtrl = GetDlgItem(PrefContext->MixerWindow->hWnd, wID); 00385 00386 if (hDlgCtrl != NULL) 00387 { 00388 /* check state */ 00389 if (SendMessageW(hDlgCtrl, BM_GETCHECK, 0, 0) != Details.fValue) 00390 { 00391 /* update control state */ 00392 SendMessageW(hDlgCtrl, BM_SETCHECK, (WPARAM)Details.fValue, 0); 00393 } 00394 } 00395 } 00396 } 00397 else if ((Control[Index].dwControlType & MIXERCONTROL_CT_CLASS_MASK) == MIXERCONTROL_CT_CLASS_FADER) 00398 { 00399 MIXERCONTROLDETAILS_UNSIGNED Details; 00400 00401 /* get volume control details */ 00402 if (SndMixerGetVolumeControlDetails(Mixer, Control[Index].dwControlID, sizeof(MIXERCONTROLDETAILS_UNSIGNED), (LPVOID)&Details) != -1) 00403 { 00404 /* update dialog control */ 00405 DWORD Position; 00406 DWORD Step = 0x10000 / 5; 00407 00408 /* FIXME: give me granularity */ 00409 Position = 5 - (Details.dwValue / Step); 00410 00411 /* FIXME support left - right slider */ 00412 wID = (PrefContext->Count + 1) * IDC_LINE_SLIDER_VERT; 00413 00414 /* get dialog control */ 00415 hDlgCtrl = GetDlgItem(PrefContext->MixerWindow->hWnd, wID); 00416 00417 if (hDlgCtrl != NULL) 00418 { 00419 /* check state */ 00420 LRESULT OldPosition = SendMessageW(hDlgCtrl, TBM_GETPOS, 0, 0); 00421 if (OldPosition != Position) 00422 { 00423 /* update control state */ 00424 SendMessageW(hDlgCtrl, TBM_SETPOS, (WPARAM)TRUE, Position + Index); 00425 } 00426 } 00427 } 00428 } 00429 } 00430 00431 /* free controls */ 00432 HeapFree(GetProcessHeap(), 0, Control); 00433 } 00434 00435 /* increment dialog count */ 00436 PrefContext->Count++; 00437 00438 /* get application rectangle */ 00439 GetWindowRect(PrefContext->MixerWindow->hWnd, &rect); 00440 00441 /* now move the window */ 00442 MoveWindow(PrefContext->MixerWindow->hWnd, rect.left, rect.top, (PrefContext->Count * DIALOG_VOLUME_SIZE), rect.bottom - rect.top, TRUE); 00443 } 00444 } 00445 } 00446 return TRUE; 00447 } 00448 00449 VOID 00450 LoadDialogCtrls( 00451 PPREFERENCES_CONTEXT PrefContext) 00452 { 00453 HWND hDlgCtrl; 00454 00455 /* set dialog count to zero */ 00456 PrefContext->Count = 0; 00457 00458 /* enumerate controls */ 00459 SndMixerEnumConnections(PrefContext->MixerWindow->Mixer, PrefContext->SelectedLine, EnumConnectionsCallback, (PVOID)PrefContext); 00460 00461 /* get last line seperator */ 00462 hDlgCtrl = GetDlgItem(PrefContext->MixerWindow->hWnd, IDC_LINE_SEP * PrefContext->Count); 00463 00464 if (hDlgCtrl != NULL) 00465 { 00466 /* hide last seperator */ 00467 ShowWindow(hDlgCtrl, SW_HIDE); 00468 } 00469 00470 } 00471 00472 VOID 00473 UpdateDialogLineSwitchControl( 00474 PPREFERENCES_CONTEXT PrefContext, 00475 LPMIXERLINE Line, 00476 LONG fValue) 00477 { 00478 DWORD Index; 00479 DWORD wID; 00480 HWND hDlgCtrl; 00481 WCHAR LineName[MIXER_LONG_NAME_CHARS]; 00482 00483 /* find the index of this line */ 00484 for(Index = 0; Index < PrefContext->Count; Index++) 00485 { 00486 /* get id */ 00487 wID = (Index + 1) * IDC_LINE_NAME; 00488 00489 if (GetDlgItemText(PrefContext->MixerWindow->hWnd, wID, LineName, MIXER_LONG_NAME_CHARS) == 0) 00490 { 00491 /* failed to retrieve id */ 00492 continue; 00493 } 00494 00495 /* check if the line name matches */ 00496 if (!wcsicmp(LineName, Line->szName)) 00497 { 00498 /* found matching line name */ 00499 wID = (Index + 1) * IDC_LINE_SWITCH; 00500 00501 /* get dialog control */ 00502 hDlgCtrl = GetDlgItem(PrefContext->MixerWindow->hWnd, wID); 00503 00504 if (hDlgCtrl != NULL) 00505 { 00506 /* check state */ 00507 if (SendMessageW(hDlgCtrl, BM_GETCHECK, 0, 0) != fValue) 00508 { 00509 /* update control state */ 00510 SendMessageW(hDlgCtrl, BM_SETCHECK, (WPARAM)fValue, 0); 00511 } 00512 } 00513 break; 00514 } 00515 } 00516 } 00517 00518 VOID 00519 UpdateDialogLineSliderControl( 00520 PPREFERENCES_CONTEXT PrefContext, 00521 LPMIXERLINE Line, 00522 DWORD dwControlID, 00523 DWORD dwDialogID, 00524 DWORD Position) 00525 { 00526 DWORD Index; 00527 DWORD wID; 00528 HWND hDlgCtrl; 00529 WCHAR LineName[MIXER_LONG_NAME_CHARS]; 00530 00531 /* find the index of this line */ 00532 for(Index = 0; Index < PrefContext->Count; Index++) 00533 { 00534 /* get id */ 00535 wID = (Index + 1) * IDC_LINE_NAME; 00536 00537 if (GetDlgItemText(PrefContext->MixerWindow->hWnd, wID, LineName, MIXER_LONG_NAME_CHARS) == 0) 00538 { 00539 /* failed to retrieve id */ 00540 continue; 00541 } 00542 00543 /* check if the line name matches */ 00544 if (!wcsicmp(LineName, Line->szName)) 00545 { 00546 /* found matching line name */ 00547 wID = (Index + 1) * dwDialogID; 00548 00549 /* get dialog control */ 00550 hDlgCtrl = GetDlgItem(PrefContext->MixerWindow->hWnd, wID); 00551 00552 if (hDlgCtrl != NULL) 00553 { 00554 /* check state */ 00555 LRESULT OldPosition = SendMessageW(hDlgCtrl, TBM_GETPOS, 0, 0); 00556 if (OldPosition != Position) 00557 { 00558 /* update control state */ 00559 SendMessageW(hDlgCtrl, TBM_SETPOS, (WPARAM)TRUE, Position + Index); 00560 } 00561 } 00562 break; 00563 } 00564 } 00565 } 00566 Generated on Sun May 27 2012 04:16:36 for ReactOS by
1.7.6.1
|