Ignore:
Timestamp:
Mar 14, 2001, 7:57:34 PM (24 years ago)
Author:
umoeller
Message:

misc changes

File:
1 edited

Legend:

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

    r46 r48  
    947947
    948948/*
     949 *@@ cnrhExpandFromRoot:
     950 *      expands prec and climbs up all parent
     951 *      records and expands them all as well.
     952 *
     953 *      Returns the no. of records expanded.
     954 *
     955 *@@added V0.9.9 (2001-03-13) [umoeller]
     956 */
     957
     958ULONG cnrhExpandFromRoot(HWND hwndCnr,
     959                         PRECORDCORE prec)
     960{
     961    ULONG ul = 0;
     962    PRECORDCORE preccParent = prec;
     963    while (preccParent)
     964    {
     965        WinSendMsg(hwndCnr, CM_EXPANDTREE, (MPARAM)preccParent, MPNULL);
     966        ul++;
     967
     968        preccParent = (PRECORDCORE)WinSendMsg(hwndCnr,
     969                                              CM_QUERYRECORD,
     970                                              (MPARAM)preccParent,
     971                                              MPFROM2SHORT(CMA_PARENT,
     972                                                           CMA_ITEMORDER));
     973
     974        if (preccParent == (PRECORDCORE)-1)
     975            preccParent = NULL;
     976    }
     977
     978    return (ul);
     979}
     980
     981/*
    949982 *@@ cnrhScrollToRecord:
    950983 *      scrolls a given container control to make a given
     
    957990 *      --  3:       record is already visible (scrolling not necessary)
    958991 *      --  4:       cnrinfo query failed (error)
    959  *      --  5:       parent record rectangle query failed (error)
    960992 *
    961993 *      Note: All messages are _sent_ to the container, not posted.
     
    9681000 *
    9691001 *@@changed V0.9.4 (2000-08-07) [umoeller]: now posting scroll messages to avoid sync errors
    970  *@@changed V0.9.9 (2001-03-12) [umoeller]: this never worked for root records in tree view if KeepParent == TRUE, fixed
     1002 *@@changed V0.9.9 (2001-03-12) [umoeller]: this never scrolled for root records in tree view if KeepParent == TRUE, fixed
     1003 *@@changed V0.9.9 (2001-03-13) [umoeller]: largely rewritten; this now scrolls x properly too and is faster
    9711004 */
    9721005
     
    9801013                                 // -- CMA_TEXT: the record text
    9811014                                 // -- CMA_TREEICON: the "+" sign in tree view
    982                          BOOL KeepParent)
     1015                         BOOL fKeepParent)
    9831016                                 // for tree views only: whether to keep
    9841017                                 // the parent record of pRec visible when scrolling.
     
    9891022
    9901023{
    991     QUERYRECORDRECT qRect, qRect2;
    992     RECTL           rclRecord, rclParentRecord, rclCnr, rclCnr2;
    993     POINTL          ptlRecord, ptlParentRecord;
    994     CNRINFO         CnrInfo;
    995     HAB             hab = WinQueryAnchorBlock(hwndCnr);
    996     BOOL            KeepParent2;
    997     LONG            lYOfs;
     1024    QUERYRECORDRECT qRect;
     1025    RECTL           rclRecord,
     1026                    rclCnr;
     1027    LONG            lXOfs = 0,
     1028                    lYOfs = 0;
    9981029
    9991030    qRect.cb = sizeof(qRect);
    10001031    qRect.pRecord = (PRECORDCORE)pRec;
    10011032    qRect.fsExtent = fsExtent;
     1033
     1034    if (fKeepParent)
     1035    {
     1036        CNRINFO         CnrInfo;
     1037        // this is only valid in tree view, so check
     1038        if (!WinSendMsg(hwndCnr,
     1039                        CM_QUERYCNRINFO,
     1040                        (MPARAM)&CnrInfo,
     1041                        (MPARAM)sizeof(CnrInfo)))
     1042            return 4;
     1043        else
     1044            // disable if not tree view
     1045            fKeepParent = ((CnrInfo.flWindowAttr & CV_TREE) != 0);
     1046    }
    10021047
    10031048    // query record location and size of container
     
    10111056                    CM_QUERYVIEWPORTRECT,
    10121057                    &rclCnr,
    1013                     MPFROM2SHORT(CMA_WINDOW, FALSE)) )
     1058                    MPFROM2SHORT(CMA_WINDOW,
     1059                                    // returns the client area rectangle
     1060                                    // in container window coordinates
     1061                                 FALSE)) )
    10141062        return 2;
    10151063
    10161064    // check if left bottom point of pRec is currently visible in container
    1017     ptlRecord.x = (rclRecord.xLeft);
    1018     ptlRecord.y = (rclRecord.yBottom);
    1019     // ptlRecord.x = (rclRecord.xLeft + rclRecord.xRight) / 2;
    1020     // ptlRecord.y = (rclRecord.yBottom + rclRecord.yTop) / 2;
    1021     if (WinPtInRect(hab, &rclCnr, &ptlRecord))
    1022          return 3;
    1023 
    1024     if (KeepParent)
    1025     {
    1026         if (!WinSendMsg(hwndCnr,
    1027                         CM_QUERYCNRINFO,
    1028                         (MPARAM)&CnrInfo,
    1029                         (MPARAM)sizeof(CnrInfo)))
    1030             return 4;
    1031         else
    1032             KeepParent2 = (CnrInfo.flWindowAttr & CV_TREE);
    1033     }
    1034     else
    1035         KeepParent2 = FALSE;
    1036 
    1037     // calculate offset to scroll to make pRec visible
    1038     lYOfs = (rclCnr.yBottom - rclRecord.yBottom)    // this would suffice
    1039           + (rclRecord.yTop - rclRecord.yBottom);  // but we make the next rcl visible too
    1040 
    1041     if (KeepParent2)
    1042     {
    1043         qRect2.cb = sizeof(qRect2);
    1044         qRect2.pRecord = (PRECORDCORE)WinSendMsg(hwndCnr,
    1045                                                  CM_QUERYRECORD,
    1046                                                  (MPARAM)pRec,
    1047                                                  MPFROM2SHORT(CMA_PARENT,
    1048                                                               CMA_ITEMORDER));
    1049         if (qRect2.pRecord)     // V0.9.9 (2001-03-12) [umoeller]
     1065
     1066    #define IS_BETWEEN(a, b, c) (((a) >= (b)) && ((a) <= (c)))
     1067
     1068    // 1) set lXOfs if we need to scroll horizontally
     1069    if (!IS_BETWEEN(rclRecord.xLeft, rclCnr.xLeft, rclCnr.xRight))
     1070        // record xLeft is outside viewport:
     1071        // scroll horizontally so that xLeft is exactly on left of viewport
     1072        lXOfs = (rclRecord.xLeft - rclCnr.xLeft);
     1073    else if (!IS_BETWEEN(rclRecord.xRight, rclCnr.xLeft, rclCnr.xRight))
     1074        // record xRight is outside viewport:
     1075        // scroll horizontally so that xRight is exactly on right of viewport
     1076        lXOfs = (rclRecord.xRight - rclCnr.xRight);
     1077
     1078    // 2) set lYOfs if we need to scroll vertically
     1079    if (!IS_BETWEEN(rclRecord.yBottom, rclCnr.yBottom, rclCnr.yTop))
     1080        // record yBottom is outside viewport:
     1081        // scroll horizontally so that yBottom is exactly on bottom of viewport
     1082        lYOfs =   (rclCnr.yBottom - rclRecord.yBottom)    // this would suffice
     1083                + (rclRecord.yTop - rclRecord.yBottom);
     1084                            // but we make the next rcl visible too
     1085    else if (!IS_BETWEEN(rclRecord.yTop, rclCnr.yBottom, rclCnr.yTop))
     1086        // record yTop is outside viewport:
     1087        // scroll horizontally so that yTop is exactly on top of viewport
     1088        lYOfs = (rclRecord.yTop - rclCnr.yTop);
     1089
     1090    if (fKeepParent && (lXOfs || lYOfs))
     1091    {
     1092        // keep parent enabled, and we're scrolling:
     1093        // find the parent record then
     1094        qRect.cb = sizeof(qRect);
     1095        qRect.pRecord = (PRECORDCORE)WinSendMsg(hwndCnr,
     1096                                                CM_QUERYRECORD,
     1097                                                (MPARAM)pRec,
     1098                                                MPFROM2SHORT(CMA_PARENT,
     1099                                                             CMA_ITEMORDER));
     1100        if (qRect.pRecord)     // V0.9.9 (2001-03-12) [umoeller]
    10501101        {
    1051             qRect2.fsExtent = fsExtent;
    1052 
    1053             // now query PARENT record location and size of container
    1054             if (!WinSendMsg(hwndCnr, CM_QUERYRECORDRECT, &rclParentRecord, &qRect2))
    1055                 return 5;
    1056 
    1057             ptlParentRecord.x = (rclParentRecord.xLeft);
    1058             ptlParentRecord.y = (rclParentRecord.yTop);
    1059             // ptlParentRecord.x = (rclParentRecord.xLeft + rclParentRecord.xRight) / 2;
    1060             // ptlParentRecord.y = (rclParentRecord.yBottom + rclParentRecord.yTop) / 2;
    1061             rclCnr2 = rclCnr;
    1062             WinOffsetRect(hab, &rclCnr2, 0, -lYOfs);
    1063             // if ( (rclParentRecord.yBottom - rclRecord.yBottom) > (rclCnr.yTop - rclCnr.yBottom) )
    1064             if (!(WinPtInRect(hab, &rclCnr2, &ptlParentRecord)))
     1102            // parent exists:
     1103            // get PARENT record rectangle then
     1104            RECTL rclParentRecord;
     1105            qRect.fsExtent = fsExtent;
     1106            if (WinSendMsg(hwndCnr,
     1107                           CM_QUERYRECORDRECT,
     1108                           &rclParentRecord,
     1109                           &qRect))
    10651110            {
    1066                 lYOfs = (rclCnr.yTop - rclParentRecord.yTop) // this would suffice
    1067                       - (rclRecord.yTop - rclRecord.yBottom);  // but we make the previous rcl visible too
     1111                // check if parent record WOULD still be visible
     1112                // if we scrolled what we calculated above
     1113                RECTL rclCnr2;
     1114                memcpy(&rclCnr2, &rclCnr, sizeof(rclCnr2));
     1115                winhOffsetRect(&rclCnr2, lXOfs, -lYOfs);
     1116
     1117                if (    lXOfs
     1118                     && (!IS_BETWEEN(rclParentRecord.xLeft, rclCnr2.xLeft, rclCnr2.xRight))
     1119                   )
     1120                    // record xLeft is outside viewport:
     1121                    // scroll horizontally so that xLeft is exactly on left of viewport
     1122                    lXOfs = (rclParentRecord.xLeft - rclCnr.xLeft);
     1123
     1124                if (    lYOfs
     1125                     && (!IS_BETWEEN(rclParentRecord.yBottom, rclCnr2.yBottom, rclCnr2.yTop))
     1126                   )
     1127                    // record yBottom is outside viewport:
     1128                    // recalculate y ofs so that we scroll so
     1129                    // that parent record is on top of cnr viewport
     1130                    lYOfs =   (rclCnr.yTop - rclParentRecord.yTop) // this would suffice
     1131                            - (rclRecord.yTop - rclRecord.yBottom);  // but we make the previous rcl visible too
    10681132            }
    10691133        }
    10701134    }
    10711135
    1072     if (!KeepParent2)
     1136    if (lXOfs)
    10731137        // scroll horizontally
    10741138        WinPostMsg(hwndCnr,
    10751139                   CM_SCROLLWINDOW,
    10761140                   (MPARAM)CMA_HORIZONTAL,
    1077                    (MPARAM)(rclRecord.xLeft - rclCnr.xLeft));
     1141                   (MPARAM)lXOfs);
    10781142
    10791143    // scroll vertically
    1080     WinPostMsg(hwndCnr,
    1081                CM_SCROLLWINDOW,
    1082                (MPARAM)CMA_VERTICAL,
    1083                (MPARAM)lYOfs);
     1144    if (lYOfs)
     1145        WinPostMsg(hwndCnr,
     1146                   CM_SCROLLWINDOW,
     1147                   (MPARAM)CMA_VERTICAL,
     1148                   (MPARAM)lYOfs);
    10841149
    10851150    return 0;
Note: See TracChangeset for help on using the changeset viewer.