Ignore:
Timestamp:
Feb 4, 2002, 6:32:38 PM (24 years ago)
Author:
umoeller
Message:

Buncha fixes, and fixes for fixes.

File:
1 edited

Legend:

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

    r136 r137  
    7373#include "helpers\xstring.h"
    7474
     75#pragma hdrstop
     76
     77// #define DEBUG_DIALOG_WINDOWS 1
     78
    7579/*
    7680 *@@category: Helpers\PM helpers\Dialog templates
     
    109113                                 // created
    110114
    111     const char  *pcszControlsFont;  // from dlghCreateDlg
    112 
    113     // V0.9.14 (2001-08-01) [umoeller]
     115    PCSZ        pcszControlsFont;  // from dlghCreateDlg
     116
     117    // size of the client to be created
     118    SIZEL       szlClient;
     119
     120    // various cached data V0.9.14 (2001-08-01) [umoeller]
    114121    HPS         hps;
    115     const char  *pcszFontLast;
     122    PCSZ        pcszFontLast;
    116123    LONG        lcidLast;
    117124    FONTMETRICS fmLast;
     
    190197typedef struct _TABLEDEF
    191198{
     199    PCOLUMNDEF  pOwningColumn;      // != NULL if this is a nested table
     200
    192201    LINKLIST    llRows;             // contains ROWDEF structs, no auto-free
    193202
     
    205214typedef enum _PROCESSMODE
    206215{
    207     PROCESS_CALC_SIZES,             // step 1
    208     PROCESS_CALC_POSITIONS,         // step 3
    209     PROCESS_CREATE_CONTROLS         // step 4
     216    PROCESS_1_CALC_SIZES,             // step 1
     217    PROCESS_2_CALC_SIZES_FROM_TABLES, // step 2
     218    PROCESS_3_CALC_FINAL_TABLE_SIZES, // step 3
     219    PROCESS_4_CALC_POSITIONS,         // step 4
     220    PROCESS_5_CREATE_CONTROLS         // step 5
    210221} PROCESSMODE;
    211222
     
    217228
    218229#define PM_GROUP_SPACING_X          16
    219 #define PM_GROUP_SPACING_TOP        20
     230#define PM_GROUP_SPACING_TOP        16
    220231
    221232APIRET ProcessTable(PTABLEDEF pTableDef,
     
    293304 *@@changed V0.9.14 (2001-08-01) [umoeller]: now caching fonts, which is significantly faster
    294305 *@@changed V0.9.16 (2001-10-15) [umoeller]: added APIRET
     306 *@@changed V0.9.16 (2002-02-02) [umoeller]: added ulWidth
    295307 */
    296308
    297309APIRET CalcAutoSizeText(PCONTROLDEF pControlDef,
    298310                        BOOL fMultiLine,          // in: if TRUE, multiple lines
     311                        ULONG ulWidth,            // in: proposed width of control
    299312                        PSIZEL pszlAuto,          // out: computed size
    300313                        PDLGPRIVATE pDlgData)
     
    317330        {
    318331            RECTL rcl = {0, 0, 0, 0};
     332            /*
    319333            if (pControlDef->szlControlProposed.cx > 0)
    320334                rcl.xRight = pControlDef->szlControlProposed.cx;   // V0.9.12 (2001-05-31) [umoeller]
    321335            else
    322336                rcl.xRight = winhQueryScreenCX() * 2 / 3;
     337            */
     338            rcl.xRight = ulWidth;
    323339            if (pControlDef->szlControlProposed.cy > 0)
    324340                rcl.yTop = pControlDef->szlControlProposed.cy;   // V0.9.12 (2001-05-31) [umoeller]
     
    358374
    359375APIRET CalcAutoSize(PCONTROLDEF pControlDef,
     376                    ULONG ulWidth,            // in: proposed width of control
    360377                    PSIZEL pszlAuto,          // out: computed size
    361378                    PDLGPRIVATE pDlgData)
     
    372389            if (!(arc = CalcAutoSizeText(pControlDef,
    373390                                         FALSE,         // no multiline
     391                                         ulWidth,
    374392                                         pszlAuto,
    375393                                         pDlgData)))
     
    404422                arc = CalcAutoSizeText(pControlDef,
    405423                                       ((pControlDef->flStyle & DT_WORDBREAK) != 0),
     424                                       ulWidth,
    406425                                       pszlAuto,
    407426                                       pDlgData);
     
    437456            pszlAuto->cy =   pDlgData->fmLast.lMaxBaselineExt
    438457                           + pDlgData->fmLast.lExternalLeading
    439                            + 5;         // some space
     458                           + 7;         // some space
    440459    }
    441460
     
    445464/*
    446465 *@@ ColumnCalcSizes:
    447  *      implementation for PROCESS_CALC_SIZES in
     466 *      implementation for PROCESS_1_CALC_SIZES in
    448467 *      ProcessColumn.
     468 *
     469 *      This gets called a second time for
     470 *      PROCESS_3_CALC_FINAL_TABLE_SIZES (V0.9.16).
    449471 *
    450472 *@@added V0.9.15 (2001-08-26) [umoeller]
     
    455477
    456478APIRET ColumnCalcSizes(PCOLUMNDEF pColumnDef,
     479                       PROCESSMODE ProcessMode,     // in: PROCESS_1_CALC_SIZES or PROCESS_3_CALC_FINAL_TABLE_SIZES
    457480                       PDLGPRIVATE pDlgData)
    458481{
    459482    APIRET arc = NO_ERROR;
    460483
    461     ULONG       ulXSpacing = 0,
    462                 ulYSpacing = 0;
     484    ULONG       ulExtraCX = 0,
     485                ulExtraCY = 0;
    463486    if (pColumnDef->fIsNestedTable)
    464487    {
     
    467490        if (!(arc = ProcessTable(pTableDef,
    468491                                 NULL,
    469                                  PROCESS_CALC_SIZES,
     492                                 ProcessMode,
    470493                                 pDlgData)))
    471494        {
     
    491514
    492515                // in any case, make this wider
    493                 ulXSpacing =    2 * PM_GROUP_SPACING_X;
    494                 ulYSpacing =    // 3 * PM_GROUP_SPACING_X;
    495                             (PM_GROUP_SPACING_X + PM_GROUP_SPACING_TOP);
     516                ulExtraCX =    2 * PM_GROUP_SPACING_X;
     517                ulExtraCY =    (PM_GROUP_SPACING_X + PM_GROUP_SPACING_TOP);
    496518            }
    497519        }
     
    501523        // no nested table, but control:
    502524        PCONTROLDEF pControlDef = (PCONTROLDEF)pColumnDef->pvDefinition;
    503         PSIZEL      pszl = &pControlDef->szlControlProposed;
    504525        SIZEL       szlAuto;
    505526
    506         if (    (pszl->cx < -1)
    507              && (pszl->cx >= -100)
    508            )
    509         {
    510             // other negative CX value:
    511             // this is then a percentage of the row width... ignore for now
    512             // V0.9.16 (2002-02-02) [umoeller]
    513             szlAuto.cx = 0;
    514             szlAuto.cy = 0;
    515         }
    516         else if (    (pszl->cx == -1)
    517                   || (pszl->cy == -1)
    518                 )
    519         {
    520             arc = CalcAutoSize(pControlDef,
    521                                &szlAuto,
    522                                pDlgData);
    523         }
    524 
    525         if (!arc)
    526         {
    527             if (pszl->cx < 0)
    528                 pColumnDef->cpControl.cx = szlAuto.cx;
    529             else
    530                 pColumnDef->cpControl.cx = pszl->cx;
    531 
    532             if (pszl->cy < 0)
    533                 pColumnDef->cpControl.cy = szlAuto.cy;
    534             else
    535                 pColumnDef->cpControl.cy = pszl->cy;
    536 
    537             // @@todo hack sizes
    538 
    539             ulXSpacing
    540             = ulYSpacing
    541             = (2 * pControlDef->ulSpacing);
    542         }
     527        // do auto-size calculations only on the first loop
     528        // V0.9.16 (2002-02-02) [umoeller]
     529        if (ProcessMode == PROCESS_1_CALC_SIZES)
     530        {
     531            if (    (pControlDef->szlControlProposed.cx == -1)
     532                 || (pControlDef->szlControlProposed.cy == -1)
     533               )
     534            {
     535                ULONG ulWidth;
     536                if (pControlDef->szlControlProposed.cx == -1)
     537                    ulWidth = 1000;
     538                else
     539                    ulWidth = pControlDef->szlControlProposed.cx;
     540                arc = CalcAutoSize(pControlDef,
     541                                   ulWidth,
     542                                   &szlAuto,
     543                                   pDlgData);
     544            }
     545
     546            if (    (pControlDef->szlControlProposed.cx < -1)
     547                 && (pControlDef->szlControlProposed.cx >= -100)
     548               )
     549            {
     550                // other negative CX value:
     551                // this is then a percentage of the table width... ignore for now
     552                // V0.9.16 (2002-02-02) [umoeller]
     553                szlAuto.cx = 0;
     554            }
     555
     556            if (    (pControlDef->szlControlProposed.cy < -1)
     557                 && (pControlDef->szlControlProposed.cy >= -100)
     558               )
     559            {
     560                // other negative CY value:
     561                // this is then a percentage of the row height... ignore for now
     562                // V0.9.16 (2002-02-02) [umoeller]
     563                szlAuto.cy = 0;
     564            }
     565
     566            if (!arc)
     567            {
     568                if (pControlDef->szlControlProposed.cx < 0)
     569                    pColumnDef->cpControl.cx = szlAuto.cx;
     570                else
     571                    pColumnDef->cpControl.cx = pControlDef->szlControlProposed.cx;
     572
     573                if (pControlDef->szlControlProposed.cy < 0)
     574                    pColumnDef->cpControl.cy = szlAuto.cy;
     575                else
     576                    pColumnDef->cpControl.cy = pControlDef->szlControlProposed.cy;
     577            }
     578
     579        } // end if (ProcessMode == PROCESS_1_CALC_SIZES)
     580
     581
     582        ulExtraCX
     583        = ulExtraCY
     584        = (2 * pControlDef->ulSpacing);
    543585    }
    544586
    545587    pColumnDef->cpColumn.cx =   pColumnDef->cpControl.cx
    546                                + ulXSpacing;
     588                               + ulExtraCX;
    547589    pColumnDef->cpColumn.cy =   pColumnDef->cpControl.cy
    548                                + ulYSpacing;
     590                               + ulExtraCY;
    549591
    550592    return (arc);
     
    553595/*
    554596 *@@ ColumnCalcPositions:
    555  *      implementation for PROCESS_CALC_POSITIONS in
     597 *      implementation for PROCESS_4_CALC_POSITIONS in
    556598 *      ProcessColumn.
    557599 *
     
    562604APIRET ColumnCalcPositions(PCOLUMNDEF pColumnDef,
    563605                           PROWDEF pOwningRow,          // in: current row from ProcessRow
    564                            PLONG plX,                   // in/out: PROCESS_CALC_POSITIONS only
     606                           PLONG plX,                   // in/out: PROCESS_4_CALC_POSITIONS only
    565607                           PDLGPRIVATE pDlgData)
    566608{
     
    568610
    569611    // calculate column position: this includes spacing
    570     ULONG ulSpacing = 0;
     612    LONG   lSpacingX = 0,
     613           lSpacingY = 0;
    571614
    572615    // column position = *plX on ProcessRow stack
     
    599642        // should we create a PM control around the table?
    600643        if (pTableDef->pCtlDef)
     644        {
    601645            // yes:
    602             ulSpacing = PM_GROUP_SPACING_X / 2;     // V0.9.16 (2001-10-15) [umoeller]
     646            lSpacingX = PM_GROUP_SPACING_X;     // V0.9.16 (2001-10-15) [umoeller]
     647            lSpacingY = PM_GROUP_SPACING_X;     // V0.9.16 (2001-10-15) [umoeller]
     648        }
    603649    }
    604650    else
     
    606652        // no nested table, but control:
    607653        PCONTROLDEF pControlDef = (PCONTROLDEF)pColumnDef->pvDefinition;
    608         ulSpacing = pControlDef->ulSpacing;
     654        lSpacingX = lSpacingY = pControlDef->ulSpacing;
    609655    }
    610656
     
    613659
    614660    // calculate CONTROL pos from COLUMN pos by applying spacing
    615     pColumnDef->cpControl.x =   pColumnDef->cpColumn.x
    616                               + ulSpacing;
    617     pColumnDef->cpControl.y =   pColumnDef->cpColumn.y
    618                               + ulSpacing;
     661    pColumnDef->cpControl.x =   (LONG)pColumnDef->cpColumn.x
     662                              + lSpacingX;
     663    pColumnDef->cpControl.y =   (LONG)pColumnDef->cpColumn.y
     664                              + lSpacingY;
    619665
    620666    if (pColumnDef->fIsNestedTable)
     
    626672        arc = ProcessTable(pTableDef,
    627673                           &pColumnDef->cpControl,   // start pos for new table
    628                            PROCESS_CALC_POSITIONS,
     674                           PROCESS_4_CALC_POSITIONS,
    629675                           pDlgData);
    630676    }
     
    635681/*
    636682 *@@ ColumnCreateControls:
    637  *      implementation for PROCESS_CREATE_CONTROLS in
     683 *      implementation for PROCESS_5_CREATE_CONTROLS in
    638684 *      ProcessColumn.
    639685 *
     
    648694    APIRET      arc = NO_ERROR;
    649695
    650     PCONTROLPOS pcp = NULL;
    651696    PCONTROLDEF pControlDef = NULL;
    652     const char  *pcszTitle = NULL;
     697
     698    PCSZ        pcszClass = NULL;
     699    PCSZ        pcszTitle = NULL;
    653700    ULONG       flStyle = 0;
    654701    LHANDLE     lHandleSet = NULLHANDLE;
     
    665712        if (!(arc = ProcessTable(pTableDef,
    666713                                 NULL,
    667                                  PROCESS_CREATE_CONTROLS,
     714                                 PROCESS_5_CREATE_CONTROLS,
    668715                                 pDlgData)))
    669716        {
     
    674721            {
    675722                // yes:
    676                 pcp  = &pColumnDef->cpColumn;  // !! not control
     723                // pcp  = &pColumnDef->cpColumn;  // !! not control
    677724                pControlDef = pTableDef->pCtlDef;
     725                pcszClass = pControlDef->pcszClass;
    678726                pcszTitle = pControlDef->pcszText;
    679727                flStyle = pControlDef->flStyle;
    680728
    681                 x = pcp->x + pDlgData->ptlTotalOfs.x;
    682                 cx = pcp->cx - PM_GROUP_SPACING_X;
     729                x  =   pColumnDef->cpColumn.x
     730                     + pDlgData->ptlTotalOfs.x
     731                     + PM_GROUP_SPACING_X / 2;
     732                cx =   pColumnDef->cpColumn.cx
     733                     - PM_GROUP_SPACING_X;
    683734                    // note, just one spacing: for the _column_ size,
    684735                    // we have specified 2 X spacings
    685                 y = pcp->y + pDlgData->ptlTotalOfs.y;
     736                y  =   pColumnDef->cpColumn.y
     737                     + pDlgData->ptlTotalOfs.y
     738                     + PM_GROUP_SPACING_X / 2;
    686739                // cy = pcp->cy - PM_GROUP_SPACING_X;
    687                 cy = pcp->cy - /* PM_GROUP_SPACING_X - */ PM_GROUP_SPACING_TOP / 2;
     740                // cy = pcp->cy - /* PM_GROUP_SPACING_X - */ PM_GROUP_SPACING_TOP;
     741                cy =   pColumnDef->cpColumn.cy
     742                     - PM_GROUP_SPACING_X / 2; //  - PM_GROUP_SPACING_TOP / 2;
    688743            }
     744
     745#ifdef DEBUG_DIALOG_WINDOWS
     746            {
     747                HWND hwndDebug;
     748                // debug: create a frame with the exact size
     749                // of the _column_ (not the control), so this
     750                // includes spacing
     751                hwndDebug =
     752                   WinCreateWindow(pDlgData->hwndDlg,   // parent
     753                                WC_STATIC,
     754                                "",
     755                                WS_VISIBLE | SS_FGNDFRAME,
     756                                pTableDef->cpTable.x + pDlgData->ptlTotalOfs.x,
     757                                pTableDef->cpTable.y + pDlgData->ptlTotalOfs.y,
     758                                pTableDef->cpTable.cx,
     759                                pTableDef->cpTable.cy,
     760                                pDlgData->hwndDlg,   // owner
     761                                HWND_BOTTOM,
     762                                -1,
     763                                NULL,
     764                                NULL);
     765                winhSetPresColor(hwndDebug, PP_FOREGROUNDCOLOR, RGBCOL_BLUE);
     766            }
     767#endif
    689768        }
    690769    }
     
    693772        // no nested table, but control:
    694773        pControlDef = (PCONTROLDEF)pColumnDef->pvDefinition;
    695         pcp = &pColumnDef->cpControl;
     774        // pcp = &pColumnDef->cpControl;
     775        pcszClass = pControlDef->pcszClass;
    696776        pcszTitle = pControlDef->pcszText;
    697777        flStyle = pControlDef->flStyle;
    698778
    699         x = pcp->x + pDlgData->ptlTotalOfs.x;
    700         cx = pcp->cx;
    701         y = pcp->y + pDlgData->ptlTotalOfs.y;
    702         cy = pcp->cy;
     779        x  =   pColumnDef->cpControl.x
     780             + pDlgData->ptlTotalOfs.x;
     781        cx =   pColumnDef->cpControl.cx;
     782        y  =   pColumnDef->cpControl.y
     783             + pDlgData->ptlTotalOfs.y;
     784        cy =   pColumnDef->cpControl.cy;
    703785
    704786        // now implement hacks for certain controls
     
    734816
    735817            case 0xffff0006L:   // entry field
     818            case 0xffff000AL:   // MLE:
    736819                // the stupid entry field resizes itself if it has
    737820                // the ES_MARGIN style, so correlate that too... dammit
     
    743826
    744827                    x += cxMargin;
    745                     y += cxMargin;
     828                    y += cyMargin;
     829                    cx -= 2 * cxMargin;
     830                    cy -= 2 * cyMargin;
     831                    // cy -= cxMargin;
    746832                }
    747833            break;
     
    749835    }
    750836
    751     if (pcp && pControlDef)
     837    if (pControlDef)
    752838    {
    753839        // create something:
    754         // PPRESPARAMS ppp = NULL;
    755 
    756         const char  *pcszFont = pControlDef->pcszFont;
     840        PCSZ pcszFont = pControlDef->pcszFont;
    757841                        // can be NULL, or CTL_COMMON_FONT
    758842        if (pcszFont == CTL_COMMON_FONT)
    759843            pcszFont = pDlgData->pcszControlsFont;
    760844
    761         /* if (pcszFont)
    762             winhStorePresParam(&ppp,
    763                                PP_FONTNAMESIZE,
    764                                strlen(pcszFont),
    765                                (PVOID)pcszFont); */
    766 
    767845        if (pColumnDef->hwndControl
    768846            = WinCreateWindow(pDlgData->hwndDlg,   // parent
    769                               (PSZ)pControlDef->pcszClass,
     847                              (PSZ)pcszClass,   // hacked
    770848                              (pcszTitle)   // hacked
    771849                                    ? (PSZ)pcszTitle
     
    782860                              NULL))
    783861        {
     862#ifdef DEBUG_DIALOG_WINDOWS
     863            {
     864                HWND hwndDebug;
     865                // debug: create a frame with the exact size
     866                // of the _column_ (not the control), so this
     867                // includes spacing
     868                hwndDebug =
     869                   WinCreateWindow(pDlgData->hwndDlg,   // parent
     870                                WC_STATIC,
     871                                "",
     872                                WS_VISIBLE | SS_FGNDFRAME,
     873                                pColumnDef->cpColumn.x + pDlgData->ptlTotalOfs.x,
     874                                pColumnDef->cpColumn.y + pDlgData->ptlTotalOfs.y,
     875                                pColumnDef->cpColumn.cx,
     876                                pColumnDef->cpColumn.cy,
     877                                pDlgData->hwndDlg,   // owner
     878                                HWND_BOTTOM,
     879                                -1,
     880                                NULL,
     881                                NULL);
     882                winhSetPresColor(hwndDebug, PP_FOREGROUNDCOLOR, RGBCOL_RED);
     883            }
     884#endif
     885
    784886            if (lHandleSet)
    785887            {
     
    850952 *      This does the following:
    851953 *
    852  *      -- PROCESS_CALC_SIZES: size is taken from control def,
     954 *      -- PROCESS_1_CALC_SIZES: size is taken from control def,
    853955 *         or for tables, this produces a recursive ProcessTable
    854956 *         call.
    855957 *         Preconditions: none.
    856958 *
    857  *      -- PROCESS_CALC_POSITIONS: position of each column
     959 *      -- PROCESS_4_CALC_POSITIONS: position of each column
    858960 *         is taken from *plX, which is increased by the
    859961 *         column width by this call.
     
    865967 *         size here.
    866968 *
    867  *      -- PROCESS_CREATE_CONTROLS: well, creates the controls.
     969 *      -- PROCESS_5_CREATE_CONTROLS: well, creates the controls.
    868970 *
    869971 *         For tables, this recurses again. If the table has
     
    878980                     PROWDEF pOwningRow,          // in: current row from ProcessRow
    879981                     PROCESSMODE ProcessMode,     // in: processing mode (see ProcessAll)
    880                      PLONG plX,                   // in/out: PROCESS_CALC_POSITIONS only
     982                     PLONG plX,                   // in/out: PROCESS_4_CALC_POSITIONS only
    881983                     PDLGPRIVATE pDlgData)
    882984{
     
    888990    {
    889991        /*
    890          * PROCESS_CALC_SIZES:
     992         * PROCESS_1_CALC_SIZES:
    891993         *      step 1.
    892994         */
    893995
    894         case PROCESS_CALC_SIZES:
     996        case PROCESS_1_CALC_SIZES:
    895997            arc = ColumnCalcSizes(pColumnDef,
     998                                  ProcessMode,
    896999                                  pDlgData);
    8971000        break;
    8981001
    8991002        /*
    900          * PROCESS_CALC_POSITIONS:
    901          *      step 2.
     1003         * PROCESS_2_CALC_SIZES_FROM_TABLES:
     1004         *
    9021005         */
    9031006
    904         case PROCESS_CALC_POSITIONS:
     1007        case PROCESS_2_CALC_SIZES_FROM_TABLES:
     1008            if (pColumnDef->fIsNestedTable)
     1009            {
     1010                PTABLEDEF pTableDef = (PTABLEDEF)pColumnDef->pvDefinition;
     1011                if (!(arc = ProcessTable(pTableDef,
     1012                                         NULL,
     1013                                         PROCESS_2_CALC_SIZES_FROM_TABLES,
     1014                                         pDlgData)))
     1015                    ;
     1016            }
     1017            else
     1018            {
     1019                // no nested table, but control:
     1020                PCONTROLDEF pControlDef = (PCONTROLDEF)pColumnDef->pvDefinition;
     1021
     1022                if (    (pControlDef->szlControlProposed.cx < -1)
     1023                     && (pControlDef->szlControlProposed.cx >= -100)
     1024                   )
     1025                {
     1026                    // other negative CX value:
     1027                    // this we ignored during PROCESS_1_CALC_SIZES
     1028                    // (see ColumnCalcSizes); now set it to the
     1029                    // table width!
     1030                    ULONG cxThis = pOwningRow->pOwningTable->cpTable.cx
     1031                                    * -pControlDef->szlControlProposed.cx / 100;
     1032
     1033                    // but the table already has spacing applied,
     1034                    // so reduce that
     1035                    pColumnDef->cpControl.cx = cxThis
     1036                                            - (2 * pControlDef->ulSpacing);
     1037
     1038                    pColumnDef->cpColumn.cx = cxThis;
     1039
     1040                    // now we might have to re-compute auto-size
     1041                    if (pControlDef->szlControlProposed.cy == -1)
     1042                    {
     1043                        SIZEL   szlAuto;
     1044                        if (!(arc = CalcAutoSize(pControlDef,
     1045                                                 // now that we now the width,
     1046                                                 // use that!
     1047                                                 pColumnDef->cpControl.cx,
     1048                                                 &szlAuto,
     1049                                                 pDlgData)))
     1050                        {
     1051                            LONG cyColumnOld = pColumnDef->cpColumn.cy;
     1052                            LONG lDelta;
     1053                            PROWDEF pRowThis;
     1054
     1055                            pColumnDef->cpControl.cy = szlAuto.cy;
     1056                            pColumnDef->cpColumn.cy = szlAuto.cy
     1057                                        + (2 * pControlDef->ulSpacing);
     1058                        }
     1059                    }
     1060                }
     1061
     1062                if (    (pControlDef->szlControlProposed.cy < -1)
     1063                     && (pControlDef->szlControlProposed.cy >= -100)
     1064                   )
     1065                {
     1066                    // same thing for CY, but this time we
     1067                    // take the row height
     1068                    ULONG cyThis = pOwningRow->cpRow.cy
     1069                                    * -pControlDef->szlControlProposed.cy / 100;
     1070
     1071                    // but the table already has spacing applied,
     1072                    // so reduce that
     1073                    pColumnDef->cpControl.cy = cyThis
     1074                                            - (2 * pControlDef->ulSpacing);
     1075
     1076                    pColumnDef->cpColumn.cy = cyThis;
     1077                }
     1078            }
     1079        break;
     1080
     1081        /*
     1082         * PROCESS_3_CALC_FINAL_TABLE_SIZES:
     1083         *
     1084         */
     1085
     1086        case PROCESS_3_CALC_FINAL_TABLE_SIZES:
     1087            // re-run calc sizes since we now know all
     1088            // the auto-size items
     1089            arc = ColumnCalcSizes(pColumnDef,
     1090                                  ProcessMode,
     1091                                  pDlgData);
     1092        break;
     1093
     1094        /*
     1095         * PROCESS_4_CALC_POSITIONS:
     1096         *      step 4.
     1097         */
     1098
     1099        case PROCESS_4_CALC_POSITIONS:
    9051100            arc = ColumnCalcPositions(pColumnDef,
    9061101                                      pOwningRow,
     
    9101105
    9111106        /*
    912          * PROCESS_CREATE_CONTROLS:
    913          *      step 3.
     1107         * PROCESS_5_CREATE_CONTROLS:
     1108         *      step 5.
    9141109         */
    9151110
    916         case PROCESS_CREATE_CONTROLS:
     1111        case PROCESS_5_CREATE_CONTROLS:
    9171112            arc = ColumnCreateControls(pColumnDef,
    9181113                                       pDlgData);
     
    9441139    pRowDef->pOwningTable = pOwningTable;
    9451140
    946     if (ProcessMode == PROCESS_CALC_SIZES)
     1141    if (    (ProcessMode == PROCESS_1_CALC_SIZES)
     1142         || (ProcessMode == PROCESS_3_CALC_FINAL_TABLE_SIZES)
     1143       )
    9471144    {
    9481145        pRowDef->cpRow.cx = 0;
    9491146        pRowDef->cpRow.cy = 0;
    9501147    }
    951     else if (ProcessMode == PROCESS_CALC_POSITIONS)
     1148    else if (ProcessMode == PROCESS_4_CALC_POSITIONS)
    9521149    {
    9531150        // set up x and y so that the columns can
     
    9691166        if (!(arc = ProcessColumn(pColumnDefThis, pRowDef, ProcessMode, &lX, pDlgData)))
    9701167        {
    971             if (ProcessMode == PROCESS_CALC_SIZES)
     1168            if (    (ProcessMode == PROCESS_1_CALC_SIZES)
     1169                 || (ProcessMode == PROCESS_3_CALC_FINAL_TABLE_SIZES)
     1170               )
    9721171            {
    9731172                // row width = sum of all columns
     
    9971196 *      nested table is found in a COLUMNDEF.
    9981197 *
    999  *      With PROCESS_CALC_POSITIONS, pptl must specify
     1198 *      With PROCESS_4_CALC_POSITIONS, pptl must specify
    10001199 *      the lower left corner of the table. For the
    10011200 *      root call, this will be {0, 0}; for nested calls,
     
    10061205
    10071206APIRET ProcessTable(PTABLEDEF pTableDef,
    1008                     const CONTROLPOS *pcpTable,       // in: table position with PROCESS_CALC_POSITIONS
     1207                    const CONTROLPOS *pcpTable,       // in: table position with PROCESS_4_CALC_POSITIONS
    10091208                    PROCESSMODE ProcessMode,          // in: processing mode (see ProcessAll)
    10101209                    PDLGPRIVATE pDlgData)
     
    10141213    PLISTNODE pNode;
    10151214
    1016     if (ProcessMode == PROCESS_CALC_SIZES)
    1017     {
    1018         pTableDef->cpTable.cx = 0;
    1019         pTableDef->cpTable.cy = 0;
    1020     }
    1021     else if (ProcessMode == PROCESS_CALC_POSITIONS)
    1022     {
    1023         pTableDef->cpTable.x = pcpTable->x;
    1024         pTableDef->cpTable.y = pcpTable->y;
    1025 
    1026         // start the rows on top
    1027         lY = pcpTable->y + pTableDef->cpTable.cy;
     1215    switch (ProcessMode)
     1216    {
     1217        case PROCESS_1_CALC_SIZES:
     1218        case PROCESS_3_CALC_FINAL_TABLE_SIZES:
     1219            pTableDef->cpTable.cx = 0;
     1220            pTableDef->cpTable.cy = 0;
     1221        break;
     1222
     1223        case PROCESS_4_CALC_POSITIONS:
     1224            pTableDef->cpTable.x = pcpTable->x;
     1225            pTableDef->cpTable.y = pcpTable->y;
     1226
     1227            // start the rows on top
     1228            lY = pcpTable->y + pTableDef->cpTable.cy;
     1229        break;
    10281230    }
    10291231
     
    10341236        if (!(arc = ProcessRow(pRowDefThis, pTableDef, ProcessMode, &lY, pDlgData)))
    10351237        {
    1036             if (ProcessMode == PROCESS_CALC_SIZES)
     1238            if (    (ProcessMode == PROCESS_1_CALC_SIZES)
     1239                 || (ProcessMode == PROCESS_3_CALC_FINAL_TABLE_SIZES)
     1240               )
    10371241            {
    10381242                // table width = maximum width of a row
     
    10641268 *      following for each call (in this order):
    10651269 *
    1066  *      -- PROCESS_CALC_SIZES: calculates the sizes
    1067  *         of all tables, rows, columns, and controls.
    1068  *
    1069  *         After this first call, we know all the sizes
    1070  *         only and can then calculate the positions.
    1071  *
    1072  *      -- PROCESS_CALC_POSITIONS: calculates the positions
    1073  *         based on the sizes calculated before.
    1074  *
    1075  *      -- PROCESS_CREATE_CONTROLS: creates the controls with the
    1076  *         positions and sizes calculated before.
     1270 *      --  PROCESS_1_CALC_SIZES: calculates the preliminary
     1271 *          sizes of all tables, rows, columns, and controls
     1272 *          except those controls that have specified that
     1273 *          their size should depend on others.
     1274 *
     1275 *      --  PROCESS_2_CALC_SIZES_FROM_TABLES: calculates the
     1276 *          sizes of those controls that want to depend on
     1277 *          others.
     1278 *
     1279 *      --  PROCESS_3_CALC_FINAL_TABLE_SIZES: since the table
     1280 *          and row sizes might have changed during
     1281 *          PROCESS_2_CALC_SIZES_FROM_TABLES, we need to re-run
     1282 *          to re-calculate the size of all rows and tables.
     1283 *          After this first call, we know _all_ the sizes
     1284 *          and can then calculate the positions.
     1285 *
     1286 *      --  PROCESS_4_CALC_POSITIONS: calculates the positions
     1287 *          based on the sizes calculated before.
     1288 *
     1289 *      --  PROCESS_5_CREATE_CONTROLS: creates the controls with the
     1290 *          positions and sizes calculated before.
    10771291 *
    10781292 *      The second trick is the precondition that tables may
     
    10841298
    10851299APIRET ProcessAll(PDLGPRIVATE pDlgData,
    1086                   PSIZEL pszlClient,
    10871300                  PROCESSMODE ProcessMode)
    10881301{
     
    10941307    switch (ProcessMode)
    10951308    {
    1096         case PROCESS_CALC_SIZES:
    1097             pszlClient->cx = 0;
    1098             pszlClient->cy = 0;
     1309        case PROCESS_1_CALC_SIZES:
     1310        case PROCESS_3_CALC_FINAL_TABLE_SIZES:
     1311            pDlgData->szlClient.cx = 0;
     1312            pDlgData->szlClient.cy = 0;
    10991313        break;
    11001314
    1101         case PROCESS_CALC_POSITIONS:
     1315        case PROCESS_4_CALC_POSITIONS:
    11021316            // start with the table on top
    1103             cpTable.y = pszlClient->cy;
     1317            cpTable.y = pDlgData->szlClient.cy;
    11041318        break;
    11051319    }
     
    11091323        PTABLEDEF pTableDefThis = (PTABLEDEF)pNode->pItemData;
    11101324
    1111         if (ProcessMode == PROCESS_CALC_POSITIONS)
     1325        if (ProcessMode == PROCESS_4_CALC_POSITIONS)
    11121326        {
    11131327            cpTable.x = 0;
     
    11201334                                 pDlgData)))
    11211335        {
    1122             if (ProcessMode == PROCESS_CALC_SIZES)
     1336            if (    (ProcessMode == PROCESS_2_CALC_SIZES_FROM_TABLES)
     1337                 || (ProcessMode == PROCESS_3_CALC_FINAL_TABLE_SIZES)
     1338               )
    11231339            {
    11241340                // all sizes have now been computed:
    1125                 pszlClient->cx += pTableDefThis->cpTable.cx;
    1126                 pszlClient->cy += pTableDefThis->cpTable.cy;
     1341                pDlgData->szlClient.cx += pTableDefThis->cpTable.cx;
     1342                pDlgData->szlClient.cy += pTableDefThis->cpTable.cy;
    11271343            }
    11281344        }
     
    13351551                                                 pCurrentTable,
    13361552                                                 &pColumnDef)))
     1553                        {
     1554                            pCurrentTable->pOwningColumn = pColumnDef;
    13371555                            lstAppendItem(&pCurrentRow->llColumns,
    13381556                                          pColumnDef);
     1557                        }
    13391558                    }
    13401559                }
     
    14271646 *@@ Dlg2_CalcSizes:
    14281647 *
     1648 *      After this, DLGPRIVATE.szlClient is valid.
     1649 *
    14291650 *@@added V0.9.15 (2001-08-26) [umoeller]
    14301651 */
    14311652
    1432 APIRET Dlg2_CalcSizes(PDLGPRIVATE pDlgData,
    1433                       PSIZEL pszlClient)          // out: dialog's client size
    1434 {
    1435     APIRET arc = ProcessAll(pDlgData,
    1436                             pszlClient,
    1437                             PROCESS_CALC_SIZES);
     1653APIRET Dlg2_CalcSizes(PDLGPRIVATE pDlgData)
     1654{
     1655    APIRET arc;
     1656
     1657    if (!(arc = ProcessAll(pDlgData,
     1658                           PROCESS_1_CALC_SIZES)))
    14381659                     // this goes into major recursions...
     1660        // run again to compute sizes that depend on tables
     1661        if (!(arc = ProcessAll(pDlgData,
     1662                               PROCESS_2_CALC_SIZES_FROM_TABLES)))
     1663            arc = ProcessAll(pDlgData,
     1664                             PROCESS_3_CALC_FINAL_TABLE_SIZES);
    14391665
    14401666    // free the cached font resources that
     
    14611687
    14621688APIRET Dlg3_PositionAndCreate(PDLGPRIVATE pDlgData,
    1463                               PSIZEL pszlClient,          // in: dialog's client size
    14641689                              HWND *phwndFocusItem)       // out: item to give focus to
    14651690{
     
    14721697
    14731698    ProcessAll(pDlgData,
    1474                pszlClient,
    1475                PROCESS_CALC_POSITIONS);
     1699               PROCESS_4_CALC_POSITIONS);
    14761700
    14771701    /*
     
    14851709
    14861710    ProcessAll(pDlgData,
    1487                pszlClient,
    1488                PROCESS_CREATE_CONTROLS);
     1711               PROCESS_5_CREATE_CONTROLS);
    14891712
    14901713    if (pDlgData->hwndDefPushbutton)
     
    15641787 *      automatically here. Even better, for many controls,
    15651788 *      auto-sizing is supported according to the control's
    1566  *      text (e.g. for statics and checkboxes).
     1789 *      text (e.g. for statics and checkboxes). In a way,
     1790 *      this is a bit similar to HTML tables.
    15671791 *
    15681792 *      A regular standard dialog would use something like
     
    16001824 *      in some table. Tables may also nest (see below).
    16011825 *
    1602  *      The macros are:
     1826 *      The DLGHITEM macros are:
    16031827 *
    16041828 *      --  START_TABLE starts a new table. The tables may nest,
     
    16531877 *          always be a START_ROW first.
    16541878 *
     1879 *      While it is possible to set up the CONTROLDEFs manually
     1880 *      as static structures, I recommend using the bunch of
     1881 *      other macros that were defined in dialog.h for this.
     1882 *      For example, you can use CONTROLDEF_PUSHBUTTON to create
     1883 *      a push button, and many more.
     1884 *
    16551885 *      To create a dialog, set up arrays like the following:
    16561886 *
    16571887 +          // control definitions referenced by DlgTemplate:
    16581888 +          CONTROLDEF
    1659  +      (1)             GroupDef = {
    1660  +                                  WC_STATIC, "", ....,
    1661  +                                  { 0, 0 },       // size, ignored for groups
    1662  +                                  5               // spacing
    1663  +                               },
    1664  +      (2)             CnrDef = {
    1665  +                                  WC_CONTAINER, "", ....,
    1666  +                                  { 50, 50 },     // size
    1667  +                                  5               // spacing
    1668  +                               },
    1669  +      (3)             Static = {
    1670  +                                  WC_STATIC, "Static below cnr", ...,
    1671  +                                  { SZL_AUTOSIZE, SZL_AUTOSIZE },     // size
    1672  +                                  5               // spacing
    1673  +                               },
    1674  +      (4)             OKButton = {
    1675  +                                  WC_STATIC, "~OK", ...,
    1676  +                                  { 100, 30 },    // size
    1677  +                                  5               // spacing
    1678  +                               },
    1679  +      (5)             CancelButton = {
    1680  +                                  WC_STATIC, "~Cancel", ...,
    1681  +                                  { 100, 30 },    // size
    1682  +                                  5               // spacing
    1683  +                               };
     1889 +      (1)             GroupDef = CONTROLDEF_GROUP("Group",
     1890 +                                                  -1,     // ID
     1891 +                                                  SZL_AUTOSIZE,
     1892 +                                                  SZL_AUTOSIZE),
     1893 +      (2)             CnrDef = CONTROLDEF_CONTAINER(-1,   // ID,
     1894 +                                                  50,
     1895 +                                                  50),
     1896 +      (3)             Static = CONTROLDEF_TEXT("Static below cnr",
     1897 +                                                  -1,     // ID
     1898 +                                                  SZL_AUTOSIZE,
     1899 +                                                  SZL_AUTOSIZE),
     1900 +      (4)             OKButton = CONTROLDEF_DEFPUSHBUTTON("~OK",
     1901 +                                                  DID_OK,
     1902 +                                                  SZL_AUTOSIZE,
     1903 +                                                  SZL_AUTOSIZE),
     1904 +      (5)             CancelButton = CONTROLDEF_PUSHBUTTON("~Cancel",
     1905 +                                                  DID_CANCEL,
     1906 +                                                  SZL_AUTOSIZE,
     1907 +                                                  SZL_AUTOSIZE);
    16841908 +
    16851909 +          DLGHITEM DlgTemplate[] =
     
    17231947 +          ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍŒ
    17241948 *
    1725  *      <B>Errors:</B>
    1726  *
    1727  *      This does not return a HWND, but an APIRET. This will be
    1728  *      one of the following:
    1729  *
    1730  *      --  NO_ERROR: only in that case, the phwndDlg ptr
    1731  *          receives the HWND of the new dialog, which can
    1732  *          then be given to WinProcessDlg. Don't forget
    1733  *          WinDestroyWindow.
    1734  *
    1735  *      --  ERROR_NOT_ENOUGH_MEMORY
    1736  *
    1737  *      --  DLGERR_ROW_BEFORE_TABLE: a row definition appeared
    1738  *          outside a table definition.
    1739  *
    1740  *      --  DLGERR_CONTROL_BEFORE_ROW: a control definition
    1741  *          appeared right after a table definition. You must
    1742  *          specify a row first.
    1743  *
    1744  *      --  DLGERR_NULL_CTL_DEF: TYPE_END_TABLE was specified,
    1745  *          but the CONTROLDEF ptr was NULL.
    1746  *
    1747  *      --  DLGERR_CANNOT_CREATE_FRAME: unable to create the
    1748  *          WC_FRAME window. Maybe an invalid owner was specified.
    1749  *
    1750  *      --  DLGERR_INVALID_CODE: invalid "Type" field in
    1751  *          DLGHITEM.
    1752  *
    1753  *      --  DLGERR_TABLE_NOT_CLOSED, DLGERR_TOO_MANY_TABLES_CLOSED:
    1754  *          improper nesting of TYPE_START_NEW_TABLE and
    1755  *          TYPE_END_TABLE fields.
    1756  *
    17571949 *      <B>Example:</B>
    17581950 *
     
    17621954 +          if (NO_ERROR == dlghCreateDlg(&hwndDlg,
    17631955 +                                        hwndOwner,
    1764  +                                        FCF_DLGBORDER | FCF_NOBYTEALIGN,
     1956 +                                        FCF_TITLEBAR | FCF_SYSMENU
     1957 +                                           | FCF_DLGBORDER | FCF_NOBYTEALIGN,
    17651958 +                                        fnwpMyDlgProc,
    17661959 +                                        "My Dlg Title",
     
    17731966 +              WinDestroyWindow(hwndDlg);
    17741967 +          }
     1968 *
     1969 *      <B>Errors:</B>
     1970 *
     1971 *      This does not return a HWND, but an APIRET. This will be
     1972 *      one of the following:
     1973 *
     1974 *      --  NO_ERROR: only in that case, the phwndDlg ptr
     1975 *          receives the HWND of the new dialog, which can
     1976 *          then be given to WinProcessDlg. Don't forget
     1977 *          WinDestroyWindow.
     1978 *
     1979 *      --  ERROR_NOT_ENOUGH_MEMORY
     1980 *
     1981 *      --  DLGERR_ROW_BEFORE_TABLE: a row definition appeared
     1982 *          outside a table definition.
     1983 *
     1984 *      --  DLGERR_CONTROL_BEFORE_ROW: a control definition
     1985 *          appeared right after a table definition. You must
     1986 *          specify a row first.
     1987 *
     1988 *      --  DLGERR_NULL_CTL_DEF: TYPE_END_TABLE was specified,
     1989 *          but the CONTROLDEF ptr was NULL.
     1990 *
     1991 *      --  DLGERR_CANNOT_CREATE_FRAME: unable to create the
     1992 *          WC_FRAME window. Maybe an invalid owner was specified.
     1993 *
     1994 *      --  DLGERR_INVALID_CODE: invalid "Type" field in
     1995 *          DLGHITEM.
     1996 *
     1997 *      --  DLGERR_TABLE_NOT_CLOSED, DLGERR_TOO_MANY_TABLES_CLOSED:
     1998 *          improper nesting of TYPE_START_NEW_TABLE and
     1999 *          TYPE_END_TABLE fields.
     2000 *
     2001 *      --  DLGERR_CANNOT_CREATE_CONTROL: creation of some
     2002 *          sub-control failed. Maybe an invalid window class
     2003 *          was specified.
     2004 *
     2005 *      --  DLGERR_INVALID_CONTROL_TITLE: bad window title in
     2006 *          control.
     2007 *
     2008 *      --  DLGERR_INVALID_STATIC_BITMAP: static bitmap contains
     2009 *          an invalid bitmap handle.
    17752010 *
    17762011 *@@changed V0.9.14 (2001-07-07) [umoeller]: fixed disabled mouse with hwndOwner == HWND_DESKTOP
     
    18602095                HWND    hwndDlg = pDlgData->hwndDlg;
    18612096                HWND    hwndFocusItem = NULLHANDLE;
    1862                 SIZEL   szlClient = {0};
    18632097                RECTL   rclClient;
    18642098
     
    18682102                 */
    18692103
    1870                 if (!(arc = Dlg2_CalcSizes(pDlgData,
    1871                                            &szlClient)))
     2104                if (!(arc = Dlg2_CalcSizes(pDlgData)))
    18722105                {
    18732106                    WinSubclassWindow(hwndDlg, pfnwpDialogProc);
     
    18812114                    rclClient.xLeft = 10;
    18822115                    rclClient.yBottom = 10;
    1883                     rclClient.xRight = szlClient.cx + 2 * SPACING;
    1884                     rclClient.yTop = szlClient.cy + 2 * SPACING;
     2116                    rclClient.xRight = pDlgData->szlClient.cx + 2 * SPACING;
     2117                    rclClient.yTop = pDlgData->szlClient.cy + 2 * SPACING;
    18852118                    WinCalcFrameRect(hwndDlg,
    18862119                                     &rclClient,
     
    18962129
    18972130                    arc = Dlg3_PositionAndCreate(pDlgData,
    1898                                                  &szlClient,
    18992131                                                 &hwndFocusItem);
    19002132
     
    20212253             */
    20222254
    2023             Dlg2_CalcSizes(pDlgData,
    2024                            &szlClient);
     2255            Dlg2_CalcSizes(pDlgData);
    20252256
    20262257            // WinSubclassWindow(hwndDlg, pfnwpDialogProc);
     
    20542285            {
    20552286                if (!(arc = Dlg3_PositionAndCreate(pDlgData,
    2056                                                    &szlClient,
    20572287                                                   &hwndFocusItem)))
    20582288                    WinSetFocus(HWND_DESKTOP, hwndFocusItem);
     
    23592589    ULONG flButtons = flFlags & 0xF;        // low nibble contains MB_YESNO etc.
    23602590
    2361     const char  *p0 = "Error",
    2362                 *p1 = NULL,
    2363                 *p2 = NULL;
     2591    PCSZ        p0 = "Error",
     2592                p1 = NULL,
     2593                p2 = NULL;
    23642594
    23652595    Icon.pcszText = (PCSZ)hptrIcon;
     
    26722902                            CTL_COMMON_FONT,
    26732903                            0,
    2674                             { 300, 20 },     // size
     2904                            { 300, SZL_AUTOSIZE },     // size
    26752905                            5               // spacing
    26762906                         },
Note: See TracChangeset for help on using the changeset viewer.