Changeset 48 for trunk/src/helpers/cnrh.c
- Timestamp:
- Mar 14, 2001, 7:57:34 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/cnrh.c
r46 r48 947 947 948 948 /* 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 958 ULONG 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 /* 949 982 *@@ cnrhScrollToRecord: 950 983 * scrolls a given container control to make a given … … 957 990 * -- 3: record is already visible (scrolling not necessary) 958 991 * -- 4: cnrinfo query failed (error) 959 * -- 5: parent record rectangle query failed (error)960 992 * 961 993 * Note: All messages are _sent_ to the container, not posted. … … 968 1000 * 969 1001 *@@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 971 1004 */ 972 1005 … … 980 1013 // -- CMA_TEXT: the record text 981 1014 // -- CMA_TREEICON: the "+" sign in tree view 982 BOOL KeepParent)1015 BOOL fKeepParent) 983 1016 // for tree views only: whether to keep 984 1017 // the parent record of pRec visible when scrolling. … … 989 1022 990 1023 { 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; 998 1029 999 1030 qRect.cb = sizeof(qRect); 1000 1031 qRect.pRecord = (PRECORDCORE)pRec; 1001 1032 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 } 1002 1047 1003 1048 // query record location and size of container … … 1011 1056 CM_QUERYVIEWPORTRECT, 1012 1057 &rclCnr, 1013 MPFROM2SHORT(CMA_WINDOW, FALSE)) ) 1058 MPFROM2SHORT(CMA_WINDOW, 1059 // returns the client area rectangle 1060 // in container window coordinates 1061 FALSE)) ) 1014 1062 return 2; 1015 1063 1016 1064 // 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] 1050 1101 { 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)) 1065 1110 { 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 1068 1132 } 1069 1133 } 1070 1134 } 1071 1135 1072 if ( !KeepParent2)1136 if (lXOfs) 1073 1137 // scroll horizontally 1074 1138 WinPostMsg(hwndCnr, 1075 1139 CM_SCROLLWINDOW, 1076 1140 (MPARAM)CMA_HORIZONTAL, 1077 (MPARAM) (rclRecord.xLeft - rclCnr.xLeft));1141 (MPARAM)lXOfs); 1078 1142 1079 1143 // 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); 1084 1149 1085 1150 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.