Changeset 197


Ignore:
Timestamp:
Aug 9, 2002, 8:44:53 PM (23 years ago)
Author:
umoeller
Message:

Misc fixes.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/helpers/dialog.h

    r195 r197  
    5555    #define DLGERR_INVALID_CONTROL_TITLE        (ERROR_DLG_FIRST + 9)
    5656    #define DLGERR_INVALID_STATIC_BITMAP        (ERROR_DLG_FIRST + 10)
    57 
    58     #define ERROR_DLG_LAST                      (ERROR_DLG_FIRST + 10)
     57    #define DLGERR_INTEGRITY_BAD_COLUMN_INDEX   (ERROR_DLG_FIRST + 11)
     58
     59    #define ERROR_DLG_LAST                      (ERROR_DLG_FIRST + 11)
    5960
    6061    /* ******************************************************************
     
    6768
    6869    #define CTL_COMMON_FONT             ((PCSZ)-1)
    69 
    70     #define ROW_VALIGN_MASK             0x0003
    71     #define ROW_VALIGN_BOTTOM           0x0000
    72     #define ROW_VALIGN_CENTER           0x0001
    73     #define ROW_VALIGN_TOP              0x0002
    7470
    7571    /*
     
    162158    } DLGHITEMTYPE;
    163159
    164     // a few handy macros for defining templates
    165 
    166     #define START_TABLE         { TYPE_START_NEW_TABLE, 0 }
    167 
    168     // this macro is slightly insane, but performs type checking
    169     // in case the user gives a pointer which is not of CONTROLDEF
    170     #define START_GROUP_TABLE(pDef)   { TYPE_START_NEW_TABLE, \
    171                 (   (ULONG)(&(pDef)->pcszClass)   ) }
    172 
    173     #define END_TABLE           { TYPE_END_TABLE, 0 }
    174 
    175     #define START_ROW(fl)       { TYPE_START_NEW_ROW, fl }
    176 
    177     #define CONTROL_DEF(pDef)   { TYPE_CONTROL_DEF, \
    178                 (   (ULONG)(&(pDef)->pcszClass)   ) }
    179 
    180160    /*
    181161     *@@ DLGHITEM:
     
    197177                // TYPE_END_TABLE               // end of table
    198178
    199         ULONG           ulData;
     179        const CONTROLDEF *pCtlDef;
    200180                // -- with TYPE_START_NEW_TABLE: if NULL, this starts
    201181                //          an invisible table (for formatting only).
     
    205185                //          with SS_GROUPBOX to create a group around
    206186                //          the table.
     187
     188        ULONG           fl;
     189                // -- with TYPE_START_NEW_TABLE. TABLE_* formatting flags.
     190                        #define TABLE_ALIGN_COLUMNS         0x0100
     191
    207192                // -- with TYPE_START_NEW_ROW: ROW_* formatting flags.
    208                 // -- with TYPE_CONTROL_DEF: _CONTROLDEF pointer to a control definition
     193                        #define ROW_VALIGN_MASK             0x0003
     194                        #define ROW_VALIGN_BOTTOM           0x0000
     195                        #define ROW_VALIGN_CENTER           0x0001
     196                        #define ROW_VALIGN_TOP              0x0002
     197
    209198    } DLGHITEM, *PDLGHITEM;
    210199
    211200    typedef const struct _DLGHITEM *PCDLGHITEM;
     201
     202    // a few handy macros for defining templates
     203
     204    #define START_TABLE                     { TYPE_START_NEW_TABLE, NULL, 0 }
     205
     206    #define START_TABLE_ALIGN               { TYPE_START_NEW_TABLE, NULL, TABLE_ALIGN_COLUMNS }
     207                // added V0.9.20 (2002-08-08) [umoeller]
     208
     209    #define START_GROUP_TABLE(pDef)         { TYPE_START_NEW_TABLE, pDef, 0 }
     210
     211    #define START_GROUP_TABLE_ALIGN(pDef)   { TYPE_START_NEW_TABLE, pDef, TABLE_ALIGN_COLUMNS }
     212                // added V0.9.20 (2002-08-08) [umoeller]
     213
     214    #define END_TABLE                       { TYPE_END_TABLE, NULL, 0 }
     215
     216    #define START_ROW(fl)                   { TYPE_START_NEW_ROW, NULL, fl }
     217
     218    #define CONTROL_DEF(pDef)               { TYPE_CONTROL_DEF, pDef, 0 }
    212219
    213220    /* ******************************************************************
  • trunk/src/helpers/dialog.c

    r196 r197  
    237237    LINKLIST    llRows;             // contains ROWDEF structs, no auto-free
    238238
    239     PCONTROLDEF pCtlDef;            // if != NULL, we create a PM control around the table
     239    const CONTROLDEF *pCtlDef;      // if != NULL, we create a PM control around the table
    240240
    241241    CONTROLPOS  cpTable;
     242
     243    ULONG       flTable;            // copied from DLGHITEM
    242244
    243245} TABLEDEF;
     
    274276 */
    275277
    276 static VOID SetDlgFont(PCONTROLDEF pControlDef,
     278static VOID SetDlgFont(const CONTROLDEF *pControlDef,
    277279                       PDLGPRIVATE pDlgData)
    278280{
     
    340342 */
    341343
    342 static APIRET CalcAutoSizeText(PCONTROLDEF pControlDef,
     344static APIRET CalcAutoSizeText(const CONTROLDEF *pControlDef,
    343345                               BOOL fMultiLine,          // in: if TRUE, multiple lines
    344346                               ULONG ulWidth,            // in: proposed width of control
     
    407409 */
    408410
    409 static APIRET CalcAutoSize(PCONTROLDEF pControlDef,
     411static APIRET CalcAutoSize(const CONTROLDEF *pControlDef,
    410412                           ULONG ulWidth,            // in: proposed width of control
    411413                           PSIZEL pszlAuto,          // out: computed size
     
    519521{
    520522    APIRET      arc = NO_ERROR;
    521     PCONTROLDEF pControlDef = NULL;
     523    const CONTROLDEF *pControlDef = NULL;
    522524    ULONG       xExtraColumn = 0,
    523525                yExtraColumn = 0;
     
    574576        SIZEL       szlAuto;
    575577
    576         pControlDef = (PCONTROLDEF)pColumnDef->pvDefinition;
     578        pControlDef = (const CONTROLDEF *)pColumnDef->pvDefinition;
    577579
    578580        // do auto-size calculations only on the first loop
     
    742744    {
    743745        // no nested table, but control:
    744         PCONTROLDEF pControlDef = (PCONTROLDEF)pColumnDef->pvDefinition;
     746        const CONTROLDEF *pControlDef = (const CONTROLDEF *)pColumnDef->pvDefinition;
    745747        xSpacingControl = pControlDef->duSpacing * FACTOR_X;
    746748        ySpacingControl = pControlDef->duSpacing * FACTOR_Y;
     
    788790    APIRET      arc = NO_ERROR;
    789791
    790     PCONTROLDEF pControlDef = NULL;
     792    const CONTROLDEF *pControlDef = NULL;
    791793
    792794    PCSZ        pcszClass = NULL;
     
    877879    {
    878880        // no nested table, but control:
    879         pControlDef = (PCONTROLDEF)pColumnDef->pvDefinition;
     881        pControlDef = (const CONTROLDEF *)pColumnDef->pvDefinition;
    880882        // pcp = &pColumnDef->cpControl;
    881883        pcszClass = pControlDef->pcszClass;
     
    11131115 *@@changed V0.9.12 (2001-05-31) [umoeller]: added control data
    11141116 *@@changed V0.9.12 (2001-05-31) [umoeller]: fixed font problems
     1117 *@@changed V0.9.20 (2002-08-08) [umoeller]: added support for aligning columns horizontally
    11151118 */
    11161119
     
    11561159            {
    11571160                // no nested table, but control:
    1158                 PCONTROLDEF pControlDef = (PCONTROLDEF)pColumnDef->pvDefinition;
     1161                const CONTROLDEF *pControlDef = (const CONTROLDEF *)pColumnDef->pvDefinition;
    11591162
    11601163                if (    (pControlDef->szlDlgUnits.cx < -1)
     
    12251228
    12261229        case PROCESS_3_CALC_FINAL_TABLE_SIZES:
     1230        {
     1231            PTABLEDEF pOwningTable;
    12271232            // re-run calc sizes since we now know all
    12281233            // the auto-size items
     
    12301235                                  ProcessMode,
    12311236                                  pDlgData);
     1237
     1238
     1239            // now check if the table has TABLE_ALIGN_COLUMNS enabled
     1240            // (START_TABLE_ALIGN or START_GROUP_TABLE_ALIGN macros)
     1241            // and, if so, align the colums horizontally by making all
     1242            // columns as wide as the widest column in the table
     1243            // V0.9.20 (2002-08-08) [umoeller]
     1244            if (    (pOwningRow)
     1245                 && (pOwningTable = pOwningRow->pOwningTable)
     1246                 && (pOwningTable->flTable & TABLE_ALIGN_COLUMNS)
     1247               )
     1248            {
     1249                // determine the index of this column in the current row
     1250                ULONG ulMyIndex = lstIndexFromItem(&pOwningRow->llColumns,
     1251                                                   pColumnDef);
     1252                if (ulMyIndex == -1)
     1253                    arc = DLGERR_INTEGRITY_BAD_COLUMN_INDEX;
     1254                else
     1255                {
     1256                    // find the widest column with this index in the table
     1257                    PLISTNODE pRowNode;
     1258                    FOR_ALL_NODES(&pOwningTable->llRows, pRowNode)
     1259                    {
     1260                        PROWDEF     pRowThis = (PROWDEF)pRowNode->pItemData;
     1261                        PCOLUMNDEF  pCorrespondingColumn;
     1262                        if (    (pCorrespondingColumn = lstItemFromIndex(&pRowThis->llColumns, ulMyIndex))
     1263                             && (pCorrespondingColumn->cpColumn.cx > pColumnDef->cpColumn.cx)
     1264                           )
     1265                            pColumnDef->cpColumn.cx = pCorrespondingColumn->cpColumn.cx;
     1266                    }
     1267                }
     1268            }
     1269        }
    12321270        break;
    12331271
     
    12791317    pRowDef->pOwningTable = pOwningTable;
    12801318
    1281     if (    (ProcessMode == PROCESS_1_CALC_SIZES)
    1282          || (ProcessMode == PROCESS_3_CALC_FINAL_TABLE_SIZES)
    1283        )
    1284     {
    1285         pRowDef->cpRow.cx = 0;
    1286         pRowDef->cpRow.cy = 0;
    1287     }
    1288     else if (ProcessMode == PROCESS_4_CALC_POSITIONS)
    1289     {
    1290         // set up x and y so that the columns can
    1291         // base on that
    1292         pRowDef->cpRow.x = pOwningTable->cpTable.x;
    1293         // decrease y by row height
    1294         *plY -= pRowDef->cpRow.cy;
    1295         // and use that for our bottom position
    1296         pRowDef->cpRow.y = *plY;
    1297 
    1298         // set lX to left of row; used by column calls below
    1299         lX = pRowDef->cpRow.x;
     1319    switch (ProcessMode)
     1320    {
     1321        case PROCESS_1_CALC_SIZES:
     1322        case PROCESS_3_CALC_FINAL_TABLE_SIZES:
     1323            pRowDef->cpRow.cx = 0;
     1324            pRowDef->cpRow.cy = 0;
     1325        break;
     1326
     1327        case PROCESS_4_CALC_POSITIONS:
     1328            // set up x and y so that the columns can
     1329            // base on that
     1330            pRowDef->cpRow.x = pOwningTable->cpTable.x;
     1331            // decrease y by row height
     1332            *plY -= pRowDef->cpRow.cy;
     1333            // and use that for our bottom position
     1334            pRowDef->cpRow.y = *plY;
     1335
     1336            // set lX to left of row; used by column calls below
     1337            lX = pRowDef->cpRow.x;
     1338        break;
    13001339    }
    13011340
     
    13561395    {
    13571396        case PROCESS_1_CALC_SIZES:
     1397            pTableDef->cpTable.cx = 0;
     1398            pTableDef->cpTable.cy = 0;
     1399        break;
     1400
    13581401        case PROCESS_3_CALC_FINAL_TABLE_SIZES:
    13591402            pTableDef->cpTable.cx = 0;
     
    14041447 *
    14051448 *      The first trick to formatting is that ProcessAll will
    1406  *      get three times, thus going down the entire tree three
     1449 *      get FIVE times, thus going down the entire tree FIVE
    14071450 *      times, with ProcessMode being set to one of the
    14081451 *      following for each call (in this order):
     
    15101553        {
    15111554            // create column and store ctl def
    1512             PCOLUMNDEF pColumnDef = NEW(COLUMNDEF);
    1513             if (!pColumnDef)
     1555            PCOLUMNDEF pColumnDef;
     1556            if (!(pColumnDef = NEW(COLUMNDEF)))
    15141557                arc = ERROR_NOT_ENOUGH_MEMORY;
    15151558            else
     
    17061749                    lstInit(&pCurrentTable->llRows, FALSE);
    17071750
    1708                     if (pItemThis->ulData)
    1709                         // control specified: store it (this will become a PM group)
    1710                         pCurrentTable->pCtlDef = (PCONTROLDEF)pItemThis->ulData;
     1751                    // if control specified: store it (this will become a PM group)
     1752                    pCurrentTable->pCtlDef = pItemThis->pCtlDef;        // can be NULL for plain table
     1753
     1754                    pCurrentTable->flTable = pItemThis->fl;         // V0.9.20 (2002-08-08) [umoeller]
    17111755
    17121756                    if (fIsRoot)
     
    17561800                        lstInit(&pCurrentRow->llColumns, FALSE);
    17571801
    1758                         pCurrentRow->flRowFormat = pItemThis->ulData;
     1802                        pCurrentRow->flRowFormat = pItemThis->fl;
    17591803
    17601804                        lstAppendItem(&pCurrentTable->llRows, pCurrentRow);
     
    17741818                if (!(arc = CreateColumn(pCurrentRow,
    17751819                                         FALSE,        // no nested table
    1776                                          (PVOID)pItemThis->ulData,
     1820                                         (PVOID)pItemThis->pCtlDef,
    17771821                                         &pColumnDef)))
    17781822                    lstAppendItem(&pCurrentRow->llColumns,
     
    19612005 *      automatically here. Even better, for many controls,
    19622006 *      auto-sizing is supported according to the control's
    1963  *      text (e.g. for statics and checkboxes). In a way,
    1964  *      this is a bit similar to HTML tables.
     2007 *      text (e.g. for statics and checkboxes). This is
     2008 *      quite similar to HTML tables.
    19652009 *
    19662010 *      A regular standard dialog would use something like
     
    20052049 *      --  START_TABLE starts a new table. The tables may nest,
    20062050 *          but must each be properly terminated with END_TABLE.
     2051 *
     2052 *          Note that as opposed to HTML tables, the columns
     2053 *          in the rows of the table are NOT aligned under each
     2054 *          other. If that is what you want, use START_TABLE_ALIGN
     2055 *          instead.
    20072056 *
    20082057 *      --  START_GROUP_TABLE(pDef) starts a group. This
     
    20172066 *          terminated with END_TABLE.
    20182067 *
     2068 *          As with START_TABLE, columns in the rows of the table
     2069 *          are NOT aligned under each other. If that is what you
     2070 *          want, use START_GROUP_TABLE_ALIGN instead.
     2071 *
    20192072 *      --  START_ROW(fl) starts a new row in a table (regular
    20202073 *          or group). This must also be the first item after
     
    20442097 *          control items will be considered to be in the same
    20452098 *          row (== positioned next to each other).
     2099 *
     2100 *          Columns will only be aligned horizontally if the
     2101 *          container table was specified with START_TABLE_ALIGN
     2102 *          or START_GROUP_TABLE_ALIGN.
    20462103 *
    20472104 *      There are a few rules, whose violation will produce
     
    21632220 *          specify a row first.
    21642221 *
    2165  *      --  DLGERR_NULL_CTL_DEF: TYPE_END_TABLE was specified,
    2166  *          but the CONTROLDEF ptr was NULL.
     2222 *      --  DLGERR_NULL_CTL_DEF: A required CONTROLDEF ptr
     2223 *          was NULL.
    21672224 *
    21682225 *      --  DLGERR_CANNOT_CREATE_FRAME: unable to create the
    2169  *          WC_FRAME window. Maybe an invalid owner was specified.
     2226 *          WC_FRAME window. Typically an invalid owner was
     2227 *          specified.
    21702228 *
    21712229 *      --  DLGERR_INVALID_CODE: invalid "Type" field in
Note: See TracChangeset for help on using the changeset viewer.