- Timestamp:
- Mar 22, 2000, 5:56:36 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/comctl32/listview.cpp
r3182 r3194 1 /*$Id: listview.cpp,v 1. 4 2000-03-21 17:30:42cbratschi Exp $*/1 /*$Id: listview.cpp,v 1.5 2000-03-22 16:56:36 cbratschi Exp $*/ 2 2 /* 3 3 * Listview control … … 154 154 static LRESULT LISTVIEW_SetItemState(HWND hwnd,INT nItem,DWORD data,DWORD mask); 155 155 static BOOL LISTVIEW_SetItemPosition(HWND hwnd, INT nItem, INT nPosX, INT nPosY); 156 static LRESULT LISTVIEW_GetStringWidth(HWND hwnd, LPWSTR lpszText,BOOL unicode);156 static LRESULT LISTVIEW_GetStringWidth(HWND hwnd,HDC hdc,LPWSTR lpszText,BOOL unicode); 157 157 static BOOL LISTVIEW_EnsureVisible(HWND hwnd,INT nItem,BOOL bPartial); 158 static VOID LISTVIEW_UpdateHeaderSize(HWND hwnd, INT nNewScrollPos); 158 159 159 160 static VOID LISTVIEW_Refresh(HWND hwnd) … … 163 164 UINT uView; 164 165 165 if (infoPtr->refreshFlags & RF_REFRESH) return;166 if (infoPtr->refreshFlags & (RF_REFRESH | RF_NOREDRAW)) return; 166 167 167 168 dwStyle = GetWindowLongA(hwnd,GWL_STYLE); … … 184 185 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)LISTVIEW_GetInfoPtr(hwnd); 185 186 187 if (infoPtr->refreshFlags & RF_NOREDRAW) return; 188 186 189 if (infoPtr->refreshFlags & RF_REFRESH) 187 190 KillTimer (hwnd,LV_REFRESH_TIMER); … … 219 222 RECT rect; 220 223 221 if (infoPtr->refreshFlags & RF_REFRESH) return;224 if (infoPtr->refreshFlags & (RF_REFRESH | RF_NOREDRAW)) return; 222 225 LISTVIEW_GetItemRect(hwnd,nItem,&rect,LVIR_SELECTBOUNDS); 223 226 InvalidateRect(hwnd,&rect,TRUE); … … 227 230 { 228 231 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)LISTVIEW_GetInfoPtr(hwnd); 229 RECT rect ;230 231 //CB: todo 232 if (infoPtr->refreshFlags & RF_REFRESH) return;232 RECT rect,header; 233 INT xOffset = infoPtr->lefttop.x*LISTVIEW_SCROLL_DIV_SIZE; 234 235 if (infoPtr->refreshFlags & (RF_REFRESH | RF_NOREDRAW)) return; 233 236 LISTVIEW_GetItemRect(hwnd,nItem,&rect,LVIR_SELECTBOUNDS); 237 238 //get header rect 239 Header_GetItemRect(infoPtr->hwndHeader,nSubItem,&header); 240 rect.left = header.left+REPORT_MARGINX; 241 rect.right = max(header.left,header.right-REPORT_MARGINX); 242 243 /* Offset the Scroll Bar Pos */ 244 rect.left -= xOffset; 245 rect.right -= xOffset; 246 234 247 InvalidateRect(hwnd,&rect,TRUE); 235 248 } … … 239 252 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)LISTVIEW_GetInfoPtr(hwnd); 240 253 241 if (infoPtr->refreshFlags & RF_REFRESH) return;254 if (infoPtr->refreshFlags & (RF_REFRESH | RF_NOREDRAW)) return; 242 255 243 256 if (uView == LVS_REPORT) … … 266 279 ScrollWindowEx(hwnd,xScroll,yScroll,&rect,NULL,0,NULL,SW_INVALIDATE); 267 280 } 281 if (xScroll != 0) LISTVIEW_UpdateHeaderSize(hwnd,infoPtr->lefttop.x); 268 282 } else ScrollWindowEx(hwnd,xScroll,yScroll,NULL,NULL,0,NULL,SW_INVALIDATE); 269 283 } … … 339 353 INT nCountPerRow = LISTVIEW_GetCountPerRow(hwnd); 340 354 INT nNumOfItems = GETITEMCOUNT(infoPtr); 341 355 //CB: todo: doesn't work! 342 356 infoPtr->maxScroll.x = nNumOfItems / nCountPerColumn+1; 343 357 if ((nNumOfItems % nCountPerColumn) == 0) … … 1088 1102 { 1089 1103 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)LISTVIEW_GetInfoPtr(hwnd); 1090 1091 if (nItem > 0) 1092 { 1093 LISTVIEW_RemoveSelections(hwnd, 0, nItem - 1); 1094 } 1095 1096 if (nItem < GETITEMCOUNT(infoPtr)) 1097 { 1098 LISTVIEW_RemoveSelections(hwnd, nItem + 1, GETITEMCOUNT(infoPtr)); 1099 } 1100 1101 LISTVIEW_SetItemState(hwnd,infoPtr->nFocusedItem,0,LVIS_FOCUSED); 1104 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE); 1105 DWORD mask = LVIS_FOCUSED; 1106 1107 if (!(dwStyle & LVS_SINGLESEL)) 1108 { 1109 if (nItem > 0) 1110 LISTVIEW_RemoveSelections(hwnd, 0, nItem - 1); 1111 1112 if (nItem < GETITEMCOUNT(infoPtr)) 1113 LISTVIEW_RemoveSelections(hwnd, nItem + 1, GETITEMCOUNT(infoPtr)); 1114 } else mask |= LVIS_SELECTED; 1115 1116 LISTVIEW_SetItemState(hwnd,infoPtr->nFocusedItem,0,mask); 1102 1117 LISTVIEW_SetItemState(hwnd,nItem,LVIS_SELECTED | LVIS_FOCUSED,LVIS_SELECTED | LVIS_FOCUSED); 1103 1118 … … 1165 1180 static LRESULT LISTVIEW_MouseSelection(HWND hwnd, POINT pt) 1166 1181 { 1167 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)LISTVIEW_GetInfoPtr(hwnd); 1182 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)LISTVIEW_GetInfoPtr(hwnd); 1183 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE); 1184 UINT uView = dwStyle & LVS_TYPEMASK; 1168 1185 RECT rcItem; 1169 INT i; 1170 1171 for (i = 0; i < GETITEMCOUNT(infoPtr); i++) 1186 INT i,nFirst = LISTVIEW_GetTopIndex(hwnd),nLast = GETITEMCOUNT(infoPtr); 1187 1188 //CB: todo: first calc rect, then compare with item rect 1189 // remove loop 1190 1191 if (uView == LVS_REPORT) 1192 { 1193 nLast = nFirst+LISTVIEW_GetCountPerColumn(hwnd)+2; 1194 nLast = min(nLast,GETITEMCOUNT(infoPtr)); 1195 } 1196 1197 for (i = nFirst;i < nLast;i++) 1172 1198 { 1173 1199 rcItem.left = LVIR_SELECTBOUNDS; 1174 if (LISTVIEW_GetItemRect(hwnd, i, &rcItem) == TRUE) 1175 { 1176 if (PtInRect(&rcItem, pt) != FALSE) 1177 { 1178 return i; 1179 } 1180 } 1200 if (LISTVIEW_GetItemRect(hwnd,i,&rcItem) && PtInRect(&rcItem,pt)) 1201 return i; 1181 1202 } 1182 1203 … … 1199 1220 { 1200 1221 INT i; 1222 1223 //CB: really slow! 1201 1224 1202 1225 for (i = nFirst; i <= nLast; i++) … … 1858 1881 1859 1882 /* state icons */ 1860 if (infoPtr->himlState != NULL)1883 if (infoPtr->himlState) 1861 1884 { 1862 1885 UINT uStateImage = (lvItem.header.state & LVIS_STATEIMAGEMASK) >> 12; 1863 if (uStateImage != 0) 1864 { 1865 ImageList_Draw(infoPtr->himlState, uStateImage - 1, hdc, rcItem.left, 1866 rcItem.top, ILD_NORMAL); 1867 } 1886 1887 if (uStateImage) 1888 ImageList_Draw(infoPtr->himlState,uStateImage-1,hdc,rcItem.left,rcItem.top,ILD_NORMAL); 1868 1889 1869 1890 rcItem.left += infoPtr->iconSize.cx; … … 1871 1892 1872 1893 /* small icons */ 1873 if (infoPtr->himlSmall != NULL) 1874 { 1875 if (lvItem.header.state & LVIS_SELECTED) 1876 { 1877 ImageList_SetBkColor(infoPtr->himlSmall, CLR_NONE); 1878 ImageList_Draw(infoPtr->himlSmall, lvItem.header.iImage, hdc, rcItem.left, 1879 rcItem.top, ILD_SELECTED); 1880 } 1881 else 1882 { 1883 ImageList_SetBkColor(infoPtr->himlSmall, CLR_NONE); 1884 ImageList_Draw(infoPtr->himlSmall, lvItem.header.iImage, hdc, rcItem.left, 1885 rcItem.top, ILD_NORMAL); 1886 } 1894 if (infoPtr->himlSmall) 1895 { 1896 ImageList_SetBkColor(infoPtr->himlSmall, CLR_NONE); 1897 ImageList_Draw(infoPtr->himlSmall,lvItem.header.iImage,hdc,rcItem.left,rcItem.top,((lvItem.header.state & LVIS_SELECTED) && !infoPtr->bFocus) ? ILD_SELECTED:ILD_NORMAL); 1887 1898 1888 1899 rcItem.left += infoPtr->iconSize.cx; … … 1921 1932 } 1922 1933 1923 nLabelWidth = LISTVIEW_GetStringWidth(hwnd, lvItem.header.pszText,lvItem.unicode);1934 nLabelWidth = LISTVIEW_GetStringWidth(hwnd,hdc,lvItem.header.pszText,lvItem.unicode); 1924 1935 if (rcItem.left + nLabelWidth < rcItem.right) 1925 1936 rcItem.right = rcItem.left + nLabelWidth; … … 1932 1943 1933 1944 if ((lvItem.header.state & LVIS_FOCUSED) && infoPtr->bFocus) 1934 {1935 1945 Rectangle(hdc, rcItem.left, rcItem.top, rcItem.right, rcItem.bottom); 1936 } 1937 1938 if (nMixMode != 0) 1946 1947 if (nMixMode) 1939 1948 { 1940 1949 SetROP2(hdc, R2_COPYPEN); … … 1961 1970 static VOID LISTVIEW_DrawLargeItem(HWND hwnd, HDC hdc, INT nItem, RECT rcItem) 1962 1971 { 1963 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)LISTVIEW_GetInfoPtr(hwnd); 1964 WCHAR szDispText[DISP_TEXT_SIZE]; 1972 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)LISTVIEW_GetInfoPtr(hwnd); 1965 1973 INT nDrawPosX = rcItem.left; 1966 1974 INT nLabelWidth; 1967 1975 TEXTMETRICA tm; 1968 LVITEMW lvItem; 1969 1970 // TRACE("(hwnd=%x, hdc=%x, nItem=%d, left=%d, top=%d, right=%d, \ 1971 //bottom=%d)\n", hwnd, hdc, nItem, rcItem.left, rcItem.top, rcItem.right, 1972 // rcItem.bottom); 1976 LVINTERNALITEMW lvItem; 1973 1977 1974 1978 /* get information needed for drawing the item */ 1975 1979 ZeroMemory(&lvItem, sizeof(LVITEMW)); 1976 lvItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; 1977 lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED; 1978 lvItem.iItem = nItem; 1979 lvItem.iSubItem = 0; 1980 lvItem.cchTextMax = DISP_TEXT_SIZE; 1981 lvItem.pszText = szDispText; 1982 LISTVIEW_GetItem(hwnd,&lvItem,TRUE,FALSE);//CB:todo 1983 1984 if (lvItem.state & LVIS_SELECTED) 1980 lvItem.header.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; 1981 lvItem.header.stateMask = LVIS_SELECTED | LVIS_FOCUSED; 1982 lvItem.header.iItem = nItem; 1983 lvItem.header.iSubItem = 0; 1984 lvItem.header.cchTextMax = DISP_TEXT_SIZE; 1985 lvItem.header.pszText = NULL; 1986 lvItem.mustFree = FALSE; 1987 LISTVIEW_GetItem(hwnd,(LPLVITEMW)&lvItem,TRUE,TRUE); 1988 1989 if (lvItem.header.state & LVIS_SELECTED) 1985 1990 { 1986 1991 /* set item colors */ … … 1989 1994 /* set raster mode */ 1990 1995 SetROP2(hdc, R2_XORPEN); 1991 } 1992 else 1996 } else 1993 1997 { 1994 1998 /* set item colors */ … … 1999 2003 } 2000 2004 2001 if (infoPtr->himlNormal != NULL)2005 if (infoPtr->himlNormal) 2002 2006 { 2003 2007 rcItem.top += ICON_TOP_PADDING; 2004 2008 nDrawPosX += (infoPtr->iconSpacing.cx - infoPtr->iconSize.cx) / 2; 2005 if (lvItem.state & LVIS_SELECTED) 2006 { 2007 ImageList_Draw(infoPtr->himlNormal, lvItem.iImage, hdc, nDrawPosX, 2008 rcItem.top, ILD_SELECTED); 2009 } 2010 else 2011 { 2012 ImageList_Draw(infoPtr->himlNormal, lvItem.iImage, hdc, nDrawPosX, 2013 rcItem.top, ILD_NORMAL); 2014 } 2009 ImageList_Draw(infoPtr->himlNormal,lvItem.header.iImage,hdc,nDrawPosX,rcItem.top,(lvItem.header.state & LVIS_SELECTED) ? ILD_SELECTED:ILD_NORMAL); 2015 2010 } 2016 2011 2017 2012 /* Don't bother painting item being edited */ 2018 if (infoPtr->hwndEdit && lvItem.state & LVIS_FOCUSED) 2019 return; 2013 if (infoPtr->hwndEdit && (lvItem.header.state & LVIS_FOCUSED)) 2014 { 2015 if (lvItem.mustFree) COMCTL32_Free(lvItem.header.pszText); 2016 return; 2017 } 2020 2018 2021 2019 rcItem.top += infoPtr->iconSize.cy + ICON_BOTTOM_PADDING; 2022 nLabelWidth = LISTVIEW_GetStringWidth(hwnd, lvItem.pszText,TRUE);2020 nLabelWidth = LISTVIEW_GetStringWidth(hwnd,hdc,lvItem.header.pszText,lvItem.unicode); 2023 2021 nDrawPosX = infoPtr->iconSpacing.cx - nLabelWidth; 2024 2022 if (nDrawPosX > 1) … … 2026 2024 rcItem.left += nDrawPosX / 2; 2027 2025 rcItem.right = rcItem.left + nLabelWidth; 2028 } 2029 else 2026 } else 2030 2027 { 2031 2028 rcItem.left += 1; … … 2034 2031 2035 2032 /* draw label */ 2036 GetTextMetricsA(hdc, 2033 GetTextMetricsA(hdc,&tm); 2037 2034 rcItem.bottom = rcItem.top + tm.tmHeight + HEIGHT_PADDING; 2038 ExtTextOutW(hdc, rcItem.left, rcItem.top, ETO_OPAQUE | ETO_CLIPPED, 2039 &rcItem, lvItem.pszText, lstrlenW(lvItem.pszText), NULL); 2040 2041 if (lvItem.state & LVIS_FOCUSED) 2042 { 2035 if (lvItem.unicode) 2036 ExtTextOutW(hdc,rcItem.left,rcItem.top,ETO_OPAQUE | ETO_CLIPPED,&rcItem,lvItem.header.pszText,lstrlenW(lvItem.header.pszText),NULL); 2037 else 2038 ExtTextOutA(hdc,rcItem.left,rcItem.top,ETO_OPAQUE | ETO_CLIPPED,&rcItem,(LPSTR)lvItem.header.pszText,lstrlenA((LPSTR)lvItem.header.pszText),NULL); 2039 2040 if (lvItem.header.state & LVIS_FOCUSED) 2043 2041 Rectangle(hdc, rcItem.left, rcItem.top, rcItem.right, rcItem.bottom); 2044 }2042 if (lvItem.mustFree) COMCTL32_Free(lvItem.header.pszText); 2045 2043 } 2046 2044 … … 2061 2059 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE); 2062 2060 INT nDrawPosY = infoPtr->rcList.top; 2063 INT nColumnCount; 2064 RECT rcItem,rcClient; 2065 INT j; 2066 INT nItem; 2067 INT nLast; 2061 INT nColumnCount = Header_GetItemCount(infoPtr->hwndHeader); 2062 RECT rcItem,rcClient,*rcHeader; 2063 INT j,nItem,nLast,xOffset = infoPtr->lefttop.x*LISTVIEW_SCROLL_DIV_SIZE; 2068 2064 2069 2065 nItem = LISTVIEW_GetTopIndex(hwnd); … … 2086 2082 GetClientRect(hwnd,&rcClient); 2087 2083 2084 //get header rects 2085 rcHeader = (LPRECT)COMCTL32_Alloc(nColumnCount*sizeof(RECT)); 2086 for (j = 0;j < nColumnCount;j++) 2087 { 2088 Header_GetItemRect(infoPtr->hwndHeader,j,&rcHeader[j]); 2089 rcHeader[j].left += REPORT_MARGINX; 2090 rcHeader[j].right = max(rcHeader[j].left,rcHeader[j].right-REPORT_MARGINX); 2091 2092 /* Offset the Scroll Bar Pos */ 2093 if (dwStyle & WS_HSCROLL) 2094 { 2095 rcHeader[j].left -= xOffset; 2096 rcHeader[j].right -= xOffset; 2097 } 2098 } 2099 2088 2100 for (; nItem < nLast; nItem++) 2089 2101 { 2090 nColumnCount = Header_GetItemCount(infoPtr->hwndHeader);2091 2102 for (j = 0; j < nColumnCount; j++) 2092 2103 { 2093 Header_GetItemRect(infoPtr->hwndHeader, j, &rcItem); 2094 rcItem.left += REPORT_MARGINX; 2095 rcItem.right = max(rcItem.left, rcItem.right - REPORT_MARGINX); 2104 rcItem = rcHeader[j]; 2096 2105 rcItem.top = nDrawPosY; 2097 2106 rcItem.bottom = rcItem.top + infoPtr->nItemHeight; 2098 2107 2099 if (rcItem.top >= rcClient.bottom) return; 2100 2101 /* Offset the Scroll Bar Pos */ 2102 if (dwStyle & WS_HSCROLL) 2103 { 2104 rcItem.left -= (infoPtr->lefttop.x * LISTVIEW_SCROLL_DIV_SIZE); 2105 rcItem.right -= (infoPtr->lefttop.x * LISTVIEW_SCROLL_DIV_SIZE); 2106 } 2108 if (rcItem.top >= (updateRect ? updateRect->bottom:rcClient.bottom)) goto DR_END; 2107 2109 2108 2110 if (!updateRect || IntersectRect(NULL,&rcItem,updateRect)) … … 2117 2119 nDrawPosY += infoPtr->nItemHeight; 2118 2120 } 2121 DR_END: 2122 COMCTL32_Free(rcHeader); 2119 2123 } 2120 2124 … … 2176 2180 nCountPerColumn = nListHeight / infoPtr->nItemHeight; 2177 2181 if (nCountPerColumn == 0) 2178 {2179 2182 nCountPerColumn = 1; 2180 }2181 2183 } 2182 2184 … … 2238 2240 INT nItemWidth = infoPtr->nItemWidth; 2239 2241 INT nItemHeight = infoPtr->nItemHeight; 2242 RECT rcClient; 2240 2243 2241 2244 /* get number of fully visible columns */ … … 2244 2247 nItem = LISTVIEW_GetTopIndex(hwnd); 2245 2248 2249 GetClientRect(hwnd,&rcClient); 2250 //CB: todo: hscroll! 2246 2251 for (i = 0; i < nColumnCount; i++) 2247 2252 { … … 2255 2260 rcItem.bottom = rcItem.top + nItemHeight; 2256 2261 rcItem.right = rcItem.left + nItemWidth; 2257 LISTVIEW_DrawItem(hwnd, hdc, nItem, rcItem); 2262 2263 if (rcItem.left >= (updateRect ? updateRect->right:rcClient.right)) return; 2264 2265 if (!updateRect || IntersectRect(NULL,&rcItem,updateRect)) 2266 LISTVIEW_DrawItem(hwnd, hdc, nItem, rcItem); 2258 2267 } 2259 2268 } … … 2273 2282 static VOID LISTVIEW_DrawIcon(HWND hwnd,HDC hdc,BOOL bSmall,RECT *updateRect) 2274 2283 { 2275 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO 2284 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)LISTVIEW_GetInfoPtr(hwnd); 2276 2285 POINT ptPosition; 2277 2286 POINT ptOrigin; … … 2285 2294 ptPosition.x += ptOrigin.x; 2286 2295 ptPosition.y += ptOrigin.y; 2287 2296 //CB: wrong nItemWidth/Height! 2288 2297 if (ptPosition.y + infoPtr->nItemHeight > infoPtr->rcList.top) 2289 2298 { … … 2298 2307 rcItem.bottom = rcItem.top + infoPtr->nItemHeight; 2299 2308 rcItem.right = rcItem.left + infoPtr->nItemWidth; 2300 if ( bSmall == FALSE)2309 if (!updateRect || IntersectRect(NULL,&rcItem,updateRect)) 2301 2310 { 2302 LISTVIEW_DrawLargeItem(hwnd, hdc, i, rcItem); 2303 } 2304 else 2305 { 2306 LISTVIEW_DrawItem(hwnd, hdc, i, rcItem); 2307 } 2311 if (!bSmall) 2312 LISTVIEW_DrawLargeItem(hwnd, hdc, i, rcItem); 2313 else 2314 LISTVIEW_DrawItem(hwnd, hdc, i, rcItem); 2315 } else if (updateRect && (rcItem.top >= updateRect->bottom)) return; 2308 2316 } 2309 } 2317 } else return; 2310 2318 } 2311 2319 } … … 2326 2334 static VOID LISTVIEW_Draw(HWND hwnd,HDC hdc,RECT *updateRect) 2327 2335 { 2328 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO 2336 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)LISTVIEW_GetInfoPtr(hwnd); 2329 2337 UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK; 2330 2338 HFONT hOldFont; … … 2341 2349 SelectObject(hdc, GetStockObject(NULL_BRUSH)); 2342 2350 2343 if (uView == LVS_LIST) 2344 { 2345 LISTVIEW_DrawList(hwnd,hdc,updateRect); 2346 } 2347 else if (uView == LVS_REPORT) 2348 { 2349 LISTVIEW_DrawReport(hwnd,hdc,updateRect); 2350 } 2351 else if (uView == LVS_SMALLICON) 2352 { 2353 LISTVIEW_DrawIcon(hwnd,hdc,TRUE,updateRect); 2354 } 2355 else if (uView == LVS_ICON) 2356 { 2357 LISTVIEW_DrawIcon(hwnd,hdc,FALSE,updateRect); 2351 switch (uView) 2352 { 2353 case LVS_LIST: 2354 LISTVIEW_DrawList(hwnd,hdc,updateRect); 2355 break; 2356 2357 case LVS_REPORT: 2358 LISTVIEW_DrawReport(hwnd,hdc,updateRect); 2359 break; 2360 2361 case LVS_SMALLICON: 2362 LISTVIEW_DrawIcon(hwnd,hdc,TRUE,updateRect); 2363 break; 2364 2365 case LVS_ICON: 2366 LISTVIEW_DrawIcon(hwnd,hdc,FALSE,updateRect); 2367 break; 2358 2368 } 2359 2369 … … 4111 4121 INT nCountPerColumn; 4112 4122 INT nRow; 4113 4114 // TRACE("(hwnd=%x,nItem=%d,lpptPosition=%p)\n", hwnd, nItem, 4115 // lpptPosition); 4116 4123 //CB: lefttop position not used!!! 4117 4124 if ((nItem >= 0) && (nItem < GETITEMCOUNT(infoPtr)) && 4118 4125 (lpptPosition != NULL)) … … 4525 4532 lvItem.mustFree = FALSE; 4526 4533 if (LISTVIEW_GetItem(hwnd,(LPLVITEMW)&lvItem,TRUE,TRUE)) 4527 nLabelWidth = LISTVIEW_GetStringWidth(hwnd, lvItem.header.pszText,lvItem.unicode);4534 nLabelWidth = LISTVIEW_GetStringWidth(hwnd,0,lvItem.header.pszText,lvItem.unicode); 4528 4535 if (lvItem.mustFree) COMCTL32_Free(lvItem.header.pszText); 4529 4536 … … 4794 4801 DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE); 4795 4802 UINT uView = dwStyle & LVS_TYPEMASK; 4796 BOOL bResult = FALSE;4797 4803 4798 4804 if ((uView == LVS_SMALLICON) || (uView == LVS_ICON)) 4799 4805 { 4800 ZeroMemory(lpptOrigin, sizeof(POINT));4801 4802 4806 if (dwStyle & WS_HSCROLL) 4803 4807 lpptOrigin->x = -infoPtr->lefttop.x*LISTVIEW_SCROLL_DIV_SIZE; 4808 else 4809 lpptOrigin->x = 0; 4804 4810 4805 4811 if (dwStyle & WS_VSCROLL) 4806 4812 lpptOrigin->y = -infoPtr->lefttop.y*LISTVIEW_SCROLL_DIV_SIZE; 4807 4808 bResult = TRUE; 4809 } 4810 4811 return bResult; 4813 else 4814 lpptOrigin->y = 0; 4815 4816 return TRUE; 4817 } 4818 4819 return FALSE; 4812 4820 } 4813 4821 … … 4867 4875 * FAILURE : zero 4868 4876 */ 4869 static LRESULT LISTVIEW_GetStringWidth(HWND hwnd, LPWSTR lpszText,BOOL unicode)4877 static LRESULT LISTVIEW_GetStringWidth(HWND hwnd,HDC hdc,LPWSTR lpszText,BOOL unicode) 4870 4878 { 4871 4879 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)LISTVIEW_GetInfoPtr(hwnd); 4872 4880 HFONT hFont, hOldFont; 4873 4881 SIZE stringSize; 4874 HDC hdc; 4875 4876 ZeroMemory(&stringSize, sizeof(SIZE)); 4877 if (lpszText != NULL) 4878 { 4879 hFont = infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont; 4880 hdc = GetDC(hwnd); 4881 hOldFont = SelectObject(hdc, hFont); 4882 BOOL ownDC = FALSE; 4883 4884 ZeroMemory(&stringSize,sizeof(SIZE)); 4885 if (lpszText) 4886 { 4887 if (!hdc) 4888 { 4889 hFont = infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont; 4890 hdc = GetDC(hwnd); 4891 hOldFont = SelectObject(hdc, hFont); 4892 ownDC = TRUE; 4893 } 4882 4894 if (unicode) 4883 4895 GetTextExtentPointW(hdc,lpszText,lstrlenW(lpszText),&stringSize); 4884 4896 else 4885 4897 GetTextExtentPointA(hdc,(LPSTR)lpszText,lstrlenA((LPSTR)lpszText),&stringSize); 4886 SelectObject(hdc, hOldFont); 4887 ReleaseDC(hwnd, hdc); 4898 if (ownDC) 4899 { 4900 SelectObject(hdc, hOldFont); 4901 ReleaseDC(hwnd, hdc); 4902 } 4888 4903 } 4889 4904 … … 6393 6408 static LRESULT LISTVIEW_HScroll(HWND hwnd,INT nScrollCode,SHORT nCurrentPos,HWND hScrollWnd) 6394 6409 { 6395 SCROLLINFO scrollInfo; 6396 //CB: todo 6397 ZeroMemory(&scrollInfo, sizeof(SCROLLINFO)); 6398 scrollInfo.cbSize = sizeof(SCROLLINFO); 6399 scrollInfo.fMask = SIF_PAGE | SIF_POS | SIF_RANGE; 6400 6401 if (GetScrollInfo(hwnd, SB_HORZ, &scrollInfo) != FALSE) 6402 { 6403 INT nOldScrollPos = scrollInfo.nPos; 6404 6405 switch (nScrollCode) 6406 { 6410 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)LISTVIEW_GetInfoPtr(hwnd); 6411 INT maxX = infoPtr->maxScroll.x-infoPtr->scrollPage.x,oldX = infoPtr->lefttop.x; 6412 6413 switch (nScrollCode) 6414 { 6407 6415 case SB_LINELEFT: 6408 if (scrollInfo.nPos > scrollInfo.nMin) 6409 { 6410 scrollInfo.nPos--; 6411 } 6416 if (infoPtr->lefttop.x > 0) 6417 infoPtr->lefttop.x--; 6412 6418 break; 6413 6419 6414 6420 case SB_LINERIGHT: 6415 if (scrollInfo.nPos < scrollInfo.nMax) 6416 { 6417 scrollInfo.nPos++; 6418 } 6421 if (infoPtr->lefttop.x < maxX) 6422 infoPtr->lefttop.x++; 6419 6423 break; 6420 6424 6421 6425 case SB_PAGELEFT: 6422 if (scrollInfo.nPos > scrollInfo.nMin) 6423 { 6424 if (scrollInfo.nPos >= scrollInfo.nPage) 6425 { 6426 scrollInfo.nPos -= scrollInfo.nPage; 6427 } 6426 if (infoPtr->lefttop.x > 0) 6427 { 6428 if (infoPtr->lefttop.x >= infoPtr->scrollPage.x) 6429 infoPtr->lefttop.x -= infoPtr->scrollPage.x; 6428 6430 else 6429 { 6430 scrollInfo.nPos = scrollInfo.nMin; 6431 } 6431 infoPtr->lefttop.x = 0; 6432 6432 } 6433 6433 break; 6434 6434 6435 6435 case SB_PAGERIGHT: 6436 if (scrollInfo.nPos < scrollInfo.nMax) 6437 { 6438 if (scrollInfo.nPos <= scrollInfo.nMax - scrollInfo.nPage) 6439 { 6440 scrollInfo.nPos += scrollInfo.nPage; 6441 } 6436 if (infoPtr->lefttop.x < maxX) 6437 { 6438 if (infoPtr->lefttop.x <= maxX-infoPtr->scrollPage.x) 6439 infoPtr->lefttop.x += infoPtr->scrollPage.x; 6442 6440 else 6443 { 6444 scrollInfo.nPos = scrollInfo.nMax; 6445 } 6441 infoPtr->lefttop.x = maxX; 6446 6442 } 6447 6443 break; 6448 6444 6449 6445 case SB_THUMBTRACK: 6450 scrollInfo.nPos = nCurrentPos; 6451 6452 if (scrollInfo.nPos > scrollInfo.nMax) 6453 scrollInfo.nPos=scrollInfo.nMax; 6454 6455 if (scrollInfo.nPos < scrollInfo.nMin) 6456 scrollInfo.nPos=scrollInfo.nMin; 6457 6446 infoPtr->lefttop.x = nCurrentPos; 6447 6448 if (infoPtr->lefttop.x > maxX) 6449 infoPtr->lefttop.x = maxX; 6450 6451 if (infoPtr->lefttop.x < 0) 6452 infoPtr->lefttop.x = 0; 6458 6453 break; 6459 } 6460 6461 if (nOldScrollPos != scrollInfo.nPos) 6462 { 6463 UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK; 6464 scrollInfo.fMask = SIF_POS; 6465 SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE); 6466 if(uView == LVS_REPORT) 6467 { 6468 scrollInfo.fMask = SIF_POS; 6469 GetScrollInfo(hwnd, SB_HORZ, &scrollInfo); 6470 LISTVIEW_UpdateHeaderSize(hwnd, scrollInfo.nPos); 6471 } 6472 LISTVIEW_Refresh(hwnd); 6473 } 6454 } 6455 6456 if (oldX != infoPtr->lefttop.x) 6457 { 6458 SCROLLINFO scrollInfo; 6459 RECT rect; 6460 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE); 6461 UINT uView = dwStyle & LVS_TYPEMASK; 6462 INT xScroll = (oldX-infoPtr->lefttop.x)* LISTVIEW_SCROLL_DIV_SIZE;//CB:tocheck 6463 6464 ZeroMemory(&scrollInfo, sizeof(SCROLLINFO)); 6465 scrollInfo.cbSize = sizeof(SCROLLINFO); 6466 scrollInfo.nPos = infoPtr->lefttop.x; 6467 scrollInfo.fMask = SIF_POS; 6468 SetScrollInfo(hwnd,SB_HORZ,&scrollInfo,TRUE); 6469 6470 LISTVIEW_ScrollWindow(hwnd,xScroll,0,uView); 6474 6471 } 6475 6472 … … 6912 6909 * Zero 6913 6910 */ 6914 static LRESULT LISTVIEW_LButtonDown(HWND hwnd, WORD wKey, WORD wPosX, 6915 WORD wPosY) 6911 static LRESULT LISTVIEW_LButtonDown(HWND hwnd, WORD wKey, WORD wPosX, WORD wPosY) 6916 6912 { 6917 6913 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)LISTVIEW_GetInfoPtr(hwnd); … … 6920 6916 POINT ptPosition; 6921 6917 INT nItem; 6922 6918 //CB: selecting last items in a large list -> high cpu usage! 6923 6919 /* send NM_RELEASEDCAPTURE notification */ 6924 6920 sendNotify(hwnd,NM_RELEASEDCAPTURE); 6925 6921 6926 6922 if (infoPtr->bFocus == FALSE) 6927 {6928 6923 SetFocus(hwnd); 6929 }6930 6924 6931 6925 /* set left button down flag */ … … 6940 6934 { 6941 6935 if ((LISTVIEW_GetItemState(hwnd, nItem, LVIS_SELECTED) & LVIS_SELECTED) && infoPtr->bDoEditLabel != TRUE) 6942 { 6936 infoPtr->bDoEditLabel = TRUE; 6937 else 6938 LISTVIEW_SetSelection(hwnd, nItem); 6939 } 6940 else 6941 { 6942 if ((wKey & MK_CONTROL) && (wKey & MK_SHIFT)) 6943 { 6944 if (bGroupSelect != FALSE) 6945 { 6946 LISTVIEW_AddGroupSelection(hwnd, nItem); 6947 } 6948 else 6949 { 6950 LISTVIEW_AddSelection(hwnd, nItem); 6951 } 6952 } 6953 else if (wKey & MK_CONTROL) 6954 { 6955 bGroupSelect = LISTVIEW_ToggleSelection(hwnd, nItem); 6956 } 6957 else if (wKey & MK_SHIFT) 6958 { 6959 LISTVIEW_SetGroupSelection(hwnd, nItem); 6960 } 6961 else 6962 { 6963 if ((LISTVIEW_GetItemState(hwnd, nItem, LVIS_SELECTED) & LVIS_SELECTED) && (infoPtr->bDoEditLabel != TRUE)) 6943 6964 infoPtr->bDoEditLabel = TRUE; 6944 }6945 else6946 {6947 LISTVIEW_SetSelection(hwnd, nItem);6948 }6949 }6950 else6951 {6952 if ((wKey & MK_CONTROL) && (wKey & MK_SHIFT))6953 {6954 if (bGroupSelect != FALSE)6955 {6956 LISTVIEW_AddGroupSelection(hwnd, nItem);6957 }6958 6965 else 6959 {6960 LISTVIEW_AddSelection(hwnd, nItem);6961 }6962 }6963 else if (wKey & MK_CONTROL)6964 {6965 bGroupSelect = LISTVIEW_ToggleSelection(hwnd, nItem);6966 }6967 else if (wKey & MK_SHIFT)6968 {6969 LISTVIEW_SetGroupSelection(hwnd, nItem);6970 }6971 else6972 {6973 if ((LISTVIEW_GetItemState(hwnd, nItem, LVIS_SELECTED) & LVIS_SELECTED) && (infoPtr->bDoEditLabel != TRUE))6974 {6975 infoPtr->bDoEditLabel = TRUE;6976 }6977 else6978 {6979 6966 LISTVIEW_SetSelection(hwnd, nItem); 6980 }6981 6967 } 6982 6968 } … … 7382 7368 * DefWinProc return value 7383 7369 */ 7384 static LRESULT LISTVIEW_SetRedraw(HWND hwnd, BOOL bRedraw) 7385 { 7370 static LRESULT LISTVIEW_SetRedraw(HWND hwnd,BOOL bRedraw) 7371 { 7372 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)LISTVIEW_GetInfoPtr(hwnd); 7386 7373 LRESULT lResult; 7387 //CB:todo 7388 lResult = DefWindowProcA(hwnd, WM_SETREDRAW, bRedraw, 0); 7389 //if (bRedraw) 7390 // RedrawWindow(hwnd,NULL,0,RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ALLCHILDREN | RDW_ERASENOW); 7374 7375 if (bRedraw) 7376 { 7377 infoPtr->refreshFlags &= ~RF_NOREDRAW; 7378 lResult = DefWindowProcA(hwnd, WM_SETREDRAW, bRedraw, 0); 7379 7380 LISTVIEW_UpdateScroll(hwnd); 7381 //CB: WINE calls RedrawWindow but many (all?) programs invalidate the control themself 7382 // RedrawWindow(hwnd,NULL,0,RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ALLCHILDREN | RDW_ERASENOW); 7383 } else 7384 { 7385 infoPtr->refreshFlags |= RF_NOREDRAW; 7386 if (infoPtr->refreshFlags & RF_REFRESH) 7387 KillTimer(hwnd,LV_REFRESH_TIMER); 7388 infoPtr->refreshFlags &= ~(RF_REFRESH | RF_UPDATESCROLL); 7389 lResult = DefWindowProcA(hwnd, WM_SETREDRAW, bRedraw, 0); 7390 } 7391 7391 7392 7392 return lResult; … … 7408 7408 static LRESULT LISTVIEW_Size(HWND hwnd, int Width, int Height) 7409 7409 { 7410 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)LISTVIEW_GetInfoPtr(hwnd); 7410 7411 LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE); 7411 7412 UINT uView = lStyle & LVS_TYPEMASK; 7412 7413 7413 // TRACE("(hwnd=%x, width=%d, height=%d)\n",hwnd, Width, Height);7414 7415 7414 LISTVIEW_UpdateSize(hwnd); 7416 7415 … … 7427 7426 } 7428 7427 7429 LISTVIEW_UpdateScroll(hwnd);7430 7431 7428 /* invalidate client area + erase background */ 7432 LISTVIEW_Refresh(hwnd);//CB:tocheck 7429 infoPtr->refreshFlags |= RF_UPDATESCROLL; 7430 LISTVIEW_QueueRefresh(hwnd); 7433 7431 7434 7432 return 0; … … 7447 7445 static VOID LISTVIEW_UpdateSize(HWND hwnd) 7448 7446 { 7449 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO 7447 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)LISTVIEW_GetInfoPtr(hwnd); 7450 7448 LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE); 7451 7449 UINT uView = lStyle & LVS_TYPEMASK; … … 7966 7964 7967 7965 case LVM_GETSTRINGWIDTHA: 7968 return LISTVIEW_GetStringWidth(hwnd, (LPWSTR)lParam,FALSE);7966 return LISTVIEW_GetStringWidth(hwnd,0,(LPWSTR)lParam,FALSE); 7969 7967 7970 7968 case LVM_GETSTRINGWIDTHW: 7971 return LISTVIEW_GetStringWidth(hwnd, (LPWSTR)lParam,TRUE);7969 return LISTVIEW_GetStringWidth(hwnd,0,(LPWSTR)lParam,TRUE); 7972 7970 7973 7971 /* case LVM_GETSUBITEMRECT: */
Note:
See TracChangeset
for help on using the changeset viewer.