Changeset 1526 for trunk/src/user32/win32dlg.cpp
- Timestamp:
- Oct 31, 1999, 2:14:44 AM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/user32/win32dlg.cpp
r1525 r1526 1 /* $Id: win32dlg.cpp,v 1.2 5 1999-10-30 18:40:47 cbratschiExp $ */1 /* $Id: win32dlg.cpp,v 1.26 1999-10-31 01:14:42 sandervl Exp $ */ 2 2 /* 3 3 * Win32 Dialog Code for OS/2 … … 46 46 47 47 dprintf(("********* CREATE DIALOG ************")); 48 xUnit = getXBaseUnit(); 49 yUnit = getYBaseUnit(); 48 if(fInitialized == FALSE) { 49 if(DIALOG_Init() == FALSE) { 50 dprintf(("DIALOG_Init FAILED!")); 51 DebugInt3(); 52 SetLastError(ERROR_GEN_FAILURE); 53 return; 54 } 55 fInitialized = TRUE; 56 } 57 xUnit = xBaseUnit; 58 yUnit = yBaseUnit; 50 59 51 60 /* Parse dialog template */ … … 227 236 dprintf(("********* DIALOG CREATION FAILED! ************")); 228 237 return FALSE; 238 } 239 //****************************************************************************** 240 //****************************************************************************** 241 BOOL Win32Dialog::MapDialogRect(LPRECT rect) 242 { 243 rect->left = (rect->left * xUnit) / 4; 244 rect->right = (rect->right * xUnit) / 4; 245 rect->top = (rect->top * yUnit) / 8; 246 rect->bottom = (rect->bottom * yUnit) / 8; 247 return TRUE; 229 248 } 230 249 /*********************************************************************** … … 312 331 } 313 332 /*********************************************************************** 333 * DIALOG_Init 334 * 335 * Initialisation of the dialog manager. 336 */ 337 BOOL Win32Dialog::DIALOG_Init(void) 338 { 339 HDC hdc; 340 SIZE size; 341 342 /* Calculate the dialog base units */ 343 if (!(hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL ))) return FALSE; 344 if (!getCharSizeFromDC( hdc, 0, &size )) return FALSE; 345 DeleteDC( hdc ); 346 xBaseUnit = size.cx; 347 yBaseUnit = size.cy; 348 349 return TRUE; 350 } 351 /*********************************************************************** 352 * DIALOG_GetCharSizeFromDC 353 * 354 * 355 * Calculates the *true* average size of English characters in the 356 * specified font as oppposed to the one returned by GetTextMetrics. 357 */ 358 BOOL Win32Dialog::getCharSizeFromDC( HDC hDC, HFONT hUserFont, SIZE * pSize ) 359 { 360 BOOL Success = FALSE; 361 HFONT hUserFontPrev = 0; 362 pSize->cx = xBaseUnit; 363 pSize->cy = yBaseUnit; 364 365 if ( hDC ) 366 { 367 /* select the font */ 368 TEXTMETRICA tm; 369 memset(&tm,0,sizeof(tm)); 370 if (hUserFont) hUserFontPrev = SelectFont(hDC,hUserFont); 371 if (GetTextMetricsA(hDC,&tm)) 372 { 373 pSize->cx = tm.tmAveCharWidth; 374 pSize->cy = tm.tmHeight; 375 376 /* if variable width font */ 377 if (tm.tmPitchAndFamily & TMPF_FIXED_PITCH) 378 { 379 SIZE total; 380 static const char szAvgChars[53] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 381 382 /* Calculate a true average as opposed to the one returned 383 * by tmAveCharWidth. This works better when dealing with 384 * proportional spaced fonts and (more important) that's 385 * how Microsoft's dialog creation code calculates the size 386 * of the font 387 */ 388 if (GetTextExtentPointA(hDC,szAvgChars,sizeof(szAvgChars),&total)) 389 { 390 /* round up */ 391 pSize->cx = ((2*total.cx/sizeof(szAvgChars)) + 1)/2; 392 Success = TRUE; 393 } 394 } 395 else 396 { 397 Success = TRUE; 398 } 399 } 400 401 /* select the original font */ 402 if (hUserFontPrev) SelectFont(hDC,hUserFontPrev); 403 } 404 return (Success); 405 } 406 /*********************************************************************** 407 * DIALOG_GetCharSize 408 * 409 * 410 * Calculates the *true* average size of English characters in the 411 * specified font as oppposed to the one returned by GetTextMetrics. 412 * A convenient variant of DIALOG_GetCharSizeFromDC. 413 */ 414 BOOL Win32Dialog::getCharSize( HFONT hUserFont, SIZE * pSize ) 415 { 416 HDC hDC = GetDC(0); 417 BOOL Success = getCharSizeFromDC( hDC, hUserFont, pSize ); 418 ReleaseDC(0, hDC); 419 return Success; 420 } 421 /*********************************************************************** 314 422 * DIALOG_ParseTemplate32 315 423 * … … 513 621 (LPCWSTR)info.className, 514 622 (LPCWSTR)info.windowName, 515 info.style | WS_CHILD | WS_CLIPSIBLINGS,623 info.style | WS_CHILD, 516 624 info.x * xUnit / 4, 517 625 info.y * yUnit / 8, … … 537 645 classNameA, 538 646 windowNameA, 539 info.style | WS_CHILD | WS_CLIPSIBLINGS,647 info.style | WS_CHILD, 540 648 info.x * xUnit / 4, 541 649 info.y * yUnit / 8, … … 978 1086 //****************************************************************************** 979 1087 //****************************************************************************** 980 1088 BOOL Win32Dialog::fInitialized = FALSE; 1089 int Win32Dialog::xBaseUnit = 10; 1090 int Win32Dialog::yBaseUnit = 20;
Note:
See TracChangeset
for help on using the changeset viewer.