Ignore:
Timestamp:
Aug 2, 2001, 10:36:35 PM (24 years ago)
Author:
umoeller
Message:

Misc changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/helpers/dialog.c

    r89 r91  
    110110    const char  *pcszControlsFont;  // from dlghCreateDlg
    111111
     112    // V0.9.14 (2001-08-01) [umoeller]
    112113    HPS         hps;
    113     /* const char  *pcszFontLast;
    114     LONG        lcidLast; */
     114    const char  *pcszFontLast;
     115    LONG        lcidLast;
     116    FONTMETRICS fmLast;
     117
    115118} DLGPRIVATE, *PDLGPRIVATE;
    116119
     
    148151    BOOL        fIsNestedTable;     // if TRUE, pvDefinition points to a nested TABLEDEF;
    149152                                    // if FALSE, pvDefinition points to a CONTROLDEF as
    150                                     // specified by the user
     153                                    // specified by the caller
    151154
    152155    PVOID       pvDefinition;       // either a PTABLEDEF or a PCONTROLDEF
     
    225228 *@@changed V0.9.12 (2001-05-31) [umoeller]: fixed various things with statics
    226229 *@@changed V0.9.12 (2001-05-31) [umoeller]: fixed broken fonts
     230 *@@changed V0.9.14 (2001-08-01) [umoeller]: now caching fonts, which is significantly faster
    227231 */
    228232
     
    232236                      PDLGPRIVATE pDlgData)
    233237{
    234     BOOL        fFind = FALSE;
    235     RECTL       rclText;
    236     LONG        lcid = 0;
    237 
    238238    const char *pcszFontThis = pControlDef->pcszFont;
    239239                    // can be NULL,
     
    248248    if (pcszFontThis)
    249249    {
    250         FONTMETRICS fm;
    251250        LONG lPointSize = 0;
    252251
    253         // create new font
    254         lcid = gpihFindPresFont(NULLHANDLE,        // no window yet
    255                                 FALSE,
    256                                 pDlgData->hps,
    257                                 pcszFontThis,
    258                                 &fm,
    259                                 &lPointSize);
    260         GpiSetCharSet(pDlgData->hps, lcid);
    261         if (fm.fsDefn & FM_DEFN_OUTLINE)
    262             gpihSetPointSize(pDlgData->hps, lPointSize);
    263 
    264         pszlAuto->cy = fm.lMaxBaselineExt + fm.lExternalLeading;
     252        // check if we can reuse font data from last time
     253        // V0.9.14 (2001-08-01) [umoeller]
     254        if (strhcmp(pcszFontThis,
     255                    pDlgData->pcszFontLast))
     256        {
     257            // different font than last time:
     258
     259            // delete old font?
     260            if (pDlgData->lcidLast)
     261            {
     262                GpiSetCharSet(pDlgData->hps, LCID_DEFAULT);
     263                GpiDeleteSetId(pDlgData->hps, pDlgData->lcidLast);
     264            }
     265
     266            // create new font
     267            pDlgData->lcidLast = gpihFindPresFont(NULLHANDLE,        // no window yet
     268                                                  FALSE,
     269                                                  pDlgData->hps,
     270                                                  pcszFontThis,
     271                                                  &pDlgData->fmLast,
     272                                                  &lPointSize);
     273
     274            GpiSetCharSet(pDlgData->hps, pDlgData->lcidLast);
     275            if (pDlgData->fmLast.fsDefn & FM_DEFN_OUTLINE)
     276                gpihSetPointSize(pDlgData->hps, lPointSize);
     277
     278            pDlgData->pcszFontLast = pcszFontThis;
     279        }
     280
     281        pszlAuto->cy =   pDlgData->fmLast.lMaxBaselineExt
     282                       + pDlgData->fmLast.lExternalLeading;
    265283    }
    266284
     
    300318        }
    301319    }
    302 
    303     /* if (lcid)
    304     {
    305         GpiSetCharSet(pDlgData->hps, LCID_DEFAULT);
    306         GpiDeleteSetId(pDlgData->hps, lcid);
    307     } */
    308 
    309320}
    310321
     
    336347                                        | BS_CHECKBOX
    337348                                        | BS_RADIOBUTTON))
     349            {
     350                // give a little extra width for the box bitmap
    338351                pszlAuto->cx += 20;     // @@todo
     352                // and height
     353                pszlAuto->cy += 2;
     354            }
    339355            else if (pControlDef->flStyle & BS_BITMAP)
    340356                ;
     
    722738                PDLGPRIVATE pDlgData)
    723739{
    724     ULONG   ul;
     740    // ULONG   ul;
    725741    LONG    lX;
    726742    PLISTNODE pNode;
     
    791807                  PDLGPRIVATE pDlgData)
    792808{
    793     ULONG   ul;
     809    // ULONG   ul;
    794810    LONG    lY;
    795811    PLISTNODE pNode;
     
    864880                PROCESSMODE ProcessMode)
    865881{
    866     ULONG ul;
     882    // ULONG ul;
    867883    PLISTNODE pNode;
    868884    CONTROLPOS cpTable;
     
    943959
    944960    return (arc);
     961}
     962
     963/*
     964 *@@ FreeTable:
     965 *      frees the specified table and recurses
     966 *      into nested tables, if necessary.
     967 *
     968 *      This was added with V0.9.14 to fix the
     969 *      bad memory leaks with nested tables.
     970 *
     971 *@@added V0.9.14 (2001-08-01) [umoeller]
     972 */
     973
     974VOID FreeTable(PTABLEDEF pTable)
     975{
     976    // for each table, clean up the rows
     977    PLISTNODE pRowNode;
     978    FOR_ALL_NODES(&pTable->llRows, pRowNode)
     979    {
     980        PROWDEF pRow = (PROWDEF)pRowNode->pItemData;
     981
     982        // for each row, clean up the columns
     983        PLISTNODE pColumnNode;
     984        FOR_ALL_NODES(&pRow->llColumns, pColumnNode)
     985        {
     986            PCOLUMNDEF pColumn = (PCOLUMNDEF)pColumnNode->pItemData;
     987
     988            if (pColumn->fIsNestedTable)
     989            {
     990                // nested table: recurse!
     991                PTABLEDEF pNestedTable = (PTABLEDEF)pColumn->pvDefinition;
     992                FreeTable(pNestedTable);
     993            }
     994
     995            free(pColumn);
     996        }
     997        lstClear(&pRow->llColumns);
     998
     999        free(pRow);
     1000    }
     1001    lstClear(&pTable->llRows);
     1002
     1003    free(pTable);
    9451004}
    9461005
     
    11811240 *
    11821241 *@@changed V0.9.14 (2001-07-07) [umoeller]: fixed disabled mouse with hwndOwner == HWND_DESKTOP
     1242 *@@changed V0.9.14 (2001-08-01) [umoeller]: fixed major memory leaks with nested tables
    11831243 */
    11841244
     
    12701330                        // create "table" column for this
    12711331                        PCOLUMNDEF pColumnDef;
    1272                         arc = CreateColumn(pCurrentRow,
    1273                                            TRUE,        // nested table
    1274                                            pCurrentTable,
    1275                                            &pColumnDef);
    1276                         if (!arc)
    1277                             lstAppendItem(&pCurrentRow->llColumns, pColumnDef);
     1332                        if (!(arc = CreateColumn(pCurrentRow,
     1333                                                 TRUE,        // nested table
     1334                                                 pCurrentTable,
     1335                                                 &pColumnDef)))
     1336                            lstAppendItem(&pCurrentRow->llColumns,
     1337                                          pColumnDef);
    12781338                    }
    12791339                }
     
    13191379            {
    13201380                PCOLUMNDEF pColumnDef;
    1321                 arc = CreateColumn(pCurrentRow,
    1322                                    FALSE,        // no nested table
    1323                                    (PVOID)pItemThis->ulData,
    1324                                    &pColumnDef);
    1325                 if (!arc)
    1326                     lstAppendItem(&pCurrentRow->llColumns, pColumnDef);
     1381                if (!(arc = CreateColumn(pCurrentRow,
     1382                                         FALSE,        // no nested table
     1383                                         (PVOID)pItemThis->ulData,
     1384                                         &pColumnDef)))
     1385                    lstAppendItem(&pCurrentRow->llColumns,
     1386                                  pColumnDef);
    13271387            break; }
    13281388
     
    14161476                       PROCESS_CALC_SIZES);
    14171477
     1478            if (pDlgData->lcidLast)
     1479            {
     1480                GpiSetCharSet(pDlgData->hps, LCID_DEFAULT);
     1481                GpiDeleteSetId(pDlgData->hps, pDlgData->lcidLast);
     1482            }
    14181483            if (pDlgData->hps)
    14191484                WinReleasePS(pDlgData->hps);
     
    15061571            PTABLEDEF pTable = (PTABLEDEF)pTableNode->pItemData;
    15071572
    1508             // for each table, clean up the rows
    1509             PLISTNODE pRowNode;
    1510             FOR_ALL_NODES(&pTable->llRows, pRowNode)
    1511             {
    1512                 PROWDEF pRow = (PROWDEF)pRowNode->pItemData;
    1513 
    1514                 // for each row, clean up the columns
    1515                 PLISTNODE pColumnNode;
    1516                 FOR_ALL_NODES(&pRow->llColumns, pColumnNode)
    1517                 {
    1518                     PCOLUMNDEF pColumn = (PCOLUMNDEF)pColumnNode->pItemData;
    1519                     free(pColumn);
    1520                 }
    1521                 lstClear(&pRow->llColumns);
    1522 
    1523                 free(pRow);
    1524             }
    1525             lstClear(&pTable->llRows);
    1526 
    1527             free(pTable);
     1573            FreeTable(pTable);
     1574                    // this may recurse for nested tables
    15281575        }
    15291576
     
    15321579
    15331580        free(pDlgData);
     1581    }
     1582
     1583    if (arc)
     1584    {
     1585        CHAR szErr[300];
     1586        sprintf(szErr, "Error %d occured in dlghCreateDlg.", arc);
     1587        winhDebugBox(hwndOwner,
     1588                     "Error in Dialog Manager",
     1589                     szErr);
    15341590    }
    15351591
Note: See TracChangeset for help on using the changeset viewer.