Ignore:
Timestamp:
Oct 31, 1999, 2:14:44 AM (26 years ago)
Author:
sandervl
Message:

Window size + paint fix + dialog fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/win32dlg.cpp

    r1525 r1526  
    1 /* $Id: win32dlg.cpp,v 1.25 1999-10-30 18:40:47 cbratschi Exp $ */
     1/* $Id: win32dlg.cpp,v 1.26 1999-10-31 01:14:42 sandervl Exp $ */
    22/*
    33 * Win32 Dialog Code for OS/2
     
    4646
    4747    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;
    5059
    5160    /* Parse dialog template */
     
    227236    dprintf(("********* DIALOG CREATION FAILED! ************"));
    228237    return FALSE;
     238}
     239//******************************************************************************
     240//******************************************************************************
     241BOOL 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;
    229248}
    230249/***********************************************************************
     
    312331}
    313332/***********************************************************************
     333 *           DIALOG_Init
     334 *
     335 * Initialisation of the dialog manager.
     336 */
     337BOOL 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 */
     358BOOL 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 */
     414BOOL 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/***********************************************************************
    314422 *           DIALOG_ParseTemplate32
    315423 *
     
    513621                                        (LPCWSTR)info.className,
    514622                                        (LPCWSTR)info.windowName,
    515                                         info.style | WS_CHILD | WS_CLIPSIBLINGS,
     623                                        info.style | WS_CHILD,
    516624                                        info.x * xUnit / 4,
    517625                                        info.y * yUnit / 8,
     
    537645                                        classNameA,
    538646                                        windowNameA,
    539                                         info.style | WS_CHILD | WS_CLIPSIBLINGS,
     647                                        info.style | WS_CHILD,
    540648                                        info.x * xUnit / 4,
    541649                                        info.y * yUnit / 8,
     
    9781086//******************************************************************************
    9791087//******************************************************************************
    980 
     1088BOOL Win32Dialog::fInitialized = FALSE;
     1089int  Win32Dialog::xBaseUnit    = 10;
     1090int  Win32Dialog::yBaseUnit    = 20;
Note: See TracChangeset for help on using the changeset viewer.