Changeset 1565 for trunk/src/comctl32/listview.c
- Timestamp:
- Nov 2, 1999, 10:44:04 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/comctl32/listview.c
r1431 r1565 34 34 * LISTVIEW_GetISearchString : not implemented 35 35 * LISTVIEW_GetBkImage : not implemented 36 * LISTVIEW_EditLabel : REPORT (need to implement a timer)37 36 * LISTVIEW_GetColumnOrderArray : not implemented 38 37 * LISTVIEW_SetColumnOrderArray : not implemented … … 44 43 */ 45 44 46 /* WINE 99 0923level */45 /* WINE 991031 level */ 47 46 48 47 #include <string.h> … … 80 79 /* default column width for items in list display mode */ 81 80 #define DEFAULT_COLUMN_WIDTH 96 81 82 /* Increment size of the horizontal scroll bar */ 83 #define REPORT_HSCROLL_INC_SIZE 10 82 84 83 85 /* … … 91 93 /* retrieve the number of items in the listview */ 92 94 #define GETITEMCOUNT(infoPtr) ((infoPtr)->hdpaItems->nItemCount) 95 96 /* Some definitions for inline edit control */ 97 typedef BOOL (*EditlblCallback)(HWND, LPSTR, DWORD); 98 99 HWND CreateEditLabel(LPCSTR text, DWORD style, INT x, INT y, 100 INT width, INT height, HWND parent, HINSTANCE hinst, 101 EditlblCallback EditLblCb, DWORD param); 102 103 typedef struct tagEDITLABEL_ITEM 104 { 105 WNDPROC EditWndProc; 106 DWORD param; 107 EditlblCallback EditLblCb; 108 } EDITLABEL_ITEM; 93 109 94 110 /* … … 129 145 static BOOL LISTVIEW_ToggleSelection(HWND, INT); 130 146 static VOID LISTVIEW_UnsupportedStyles(LONG lStyle); 131 132 /*** 133 * DESCRIPTION: 134 * Update the scrollbars. This functions should be called whenever 147 static HWND LISTVIEW_EditLabelA(HWND hwnd, INT nItem); 148 static BOOL LISTVIEW_EndEditLabel(HWND hwnd, LPSTR pszText, DWORD nItem); 149 static LRESULT LISTVIEW_Command(HWND hwnd, WPARAM wParam, LPARAM lParam); 150 151 /************************************************************************* 152 * LISTVIEW_UpdateHeaderSize [Internal] 153 * 154 * Function to resize the header control 155 * 156 * PARAMS 157 * hwnd [I] handle to a window 158 * nNewScrollPos [I] Scroll Pos to Set 159 * nOldScrollPos [I] Previous Scroll Pos 160 * 161 * RETURNS 162 * nothing 163 * 164 * NOTES 165 */ 166 static VOID LISTVIEW_UpdateHeaderSize(HWND hwnd, INT nNewScrollPos, INT nOldScrollPos) 167 { 168 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0); 169 INT nDiff = nOldScrollPos-nNewScrollPos; 170 RECT winRect; 171 POINT point[2]; 172 173 GetWindowRect(infoPtr->hwndHeader, &winRect); 174 point[0].x = winRect.left; 175 point[0].y = winRect.top; 176 point[1].x = winRect.right; 177 point[1].y = winRect.bottom; 178 179 MapWindowPoints(HWND_DESKTOP, hwnd, point, 2); 180 point[0].x += (nDiff * REPORT_HSCROLL_INC_SIZE ); 181 point[1].x -= point[0].x; 182 183 SetWindowPos(infoPtr->hwndHeader,0, 184 point[0].x,point[0].y,point[1].x,point[1].y, 185 SWP_NOZORDER | SWP_NOACTIVATE); 186 } 187 188 /*** 189 * DESCRIPTION: 190 * Update the scrollbars. This functions should be called whenever 135 191 * the content, size or view changes. 136 * 192 * 137 193 * PARAMETER(S): 138 194 * [I] HWND : window handle … … 143 199 static VOID LISTVIEW_UpdateScroll(HWND hwnd) 144 200 { 145 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0); 201 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0); 146 202 LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE); 147 203 UINT uView = lStyle & LVS_TYPEMASK; … … 160 216 { 161 217 /* calculate new scrollbar range */ 162 INT nHiddenItemCount = GETITEMCOUNT(infoPtr) - nCountPerPage; 163 if (nHiddenItemCount % nCountPerColumn == 0) 164 { 165 scrollInfo.nMax = nHiddenItemCount / nCountPerColumn; 218 if((GETITEMCOUNT(infoPtr) % nCountPerPage) == 0) 219 { 220 scrollInfo.nMax = GETITEMCOUNT(infoPtr) / nCountPerPage * LISTVIEW_GetCountPerRow(hwnd)-1; 166 221 } 167 222 else 168 223 { 169 scrollInfo.nMax = nHiddenItemCount / nCountPerColumn + 1;170 } 171 224 scrollInfo.nMax = (GETITEMCOUNT(infoPtr) / nCountPerPage)* LISTVIEW_GetCountPerRow(hwnd); 225 } 226 172 227 scrollInfo.nPos = ListView_GetTopIndex(hwnd) / nCountPerColumn; 173 /*scrollInfo.nPage = LISTVIEW_GetCountPerRow(hwnd);*/174 scrollInfo.fMask = SIF_RANGE | SIF_POS /*| SIF_PAGE*/;228 scrollInfo.nPage = LISTVIEW_GetCountPerRow(hwnd); 229 scrollInfo.fMask = SIF_RANGE | SIF_POS | SIF_PAGE; 175 230 SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE); 176 231 } … … 180 235 if (lStyle & WS_HSCROLL) 181 236 { 182 237 ShowScrollBar(hwnd, SB_HORZ, FALSE); 183 238 } 184 239 } … … 186 241 else if (uView == LVS_REPORT) 187 242 { 243 RECT clientRect; 188 244 /* update vertical scrollbar */ 189 245 scrollInfo.nMin = 0; 190 scrollInfo.nMax = GETITEMCOUNT(infoPtr) - LISTVIEW_GetCountPerColumn(hwnd);246 scrollInfo.nMax = GETITEMCOUNT(infoPtr) - 1; 191 247 scrollInfo.nPos = ListView_GetTopIndex(hwnd); 192 /*scrollInfo.nPage = nCountPerColumn;*/193 scrollInfo.fMask = SIF_RANGE | SIF_POS /*| SIF_PAGE*/;248 scrollInfo.nPage = LISTVIEW_GetCountPerColumn(hwnd); 249 scrollInfo.fMask = SIF_RANGE | SIF_POS | SIF_PAGE; 194 250 SetScrollInfo(hwnd, SB_VERT, &scrollInfo, TRUE); 195 251 196 252 /* update horizontal scrollbar */ 197 /* if (infoPtr->nItemWidth > nListWidth) */ 198 /* { */ 199 /* scrollInfo.fMask = SIF_RANGE | SIF_POS | SIF_PAGE; */ 200 /* SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE); */ 201 /* } */ 202 203 /* horizontal scrolling has not been implemented yet! I experienced some 204 problems when performing child window scrolling. */ 253 infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd); 254 GetClientRect(hwnd, &clientRect); 255 256 if (GetScrollInfo(hwnd, SB_HORZ, &scrollInfo) == FALSE) 257 { 258 scrollInfo.nPos = 0; 259 } 260 scrollInfo.nMin = 0; 261 scrollInfo.fMask = SIF_RANGE | SIF_POS | SIF_PAGE ; 262 scrollInfo.nPage = (clientRect.right - clientRect.left) / REPORT_HSCROLL_INC_SIZE; 263 scrollInfo.nMax = infoPtr->nItemWidth; 264 265 /* Check to see if we need the scroll bar */ 266 if(scrollInfo.nMax < 0) 267 { 268 scrollInfo.nMax = 0; 269 } 270 else 271 { 272 /* Even up the max */ 273 scrollInfo.nMax -= (scrollInfo.nMax % REPORT_HSCROLL_INC_SIZE); 274 scrollInfo.nMax = (scrollInfo.nMax / REPORT_HSCROLL_INC_SIZE)-1; 275 } 276 /* Set the scroll pos to the max if the current scroll pos is greater */ 277 if((scrollInfo.nPos+scrollInfo.nPage) > scrollInfo.nMax 278 && scrollInfo.nMax > scrollInfo.nPage) 279 { 280 UINT nOldScrollPos = scrollInfo.nPos; 281 scrollInfo.nPos = scrollInfo.nMax; 282 SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE); 283 GetScrollInfo(hwnd, SB_HORZ, &scrollInfo); 284 LISTVIEW_UpdateHeaderSize(hwnd, scrollInfo.nPos, nOldScrollPos); 285 } 286 else 287 { 288 SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE); 289 } 205 290 } 206 291 else … … 233 318 scrollInfo.nPos = 0; 234 319 } 235 320 236 321 if (nHiddenWidth % nScrollPosWidth == 0) 237 322 { 238 scrollInfo.nMax = nHiddenWidth / nScrollPosWidth; 323 scrollInfo.nMax = nHiddenWidth / nScrollPosWidth; 239 324 } 240 325 else 241 326 { 242 scrollInfo.nMax = nHiddenWidth / nScrollPosWidth + 1; 243 } 244 327 scrollInfo.nMax = nHiddenWidth / nScrollPosWidth + 1; 328 } 329 245 330 scrollInfo.nMin = 0; 246 /*scrollInfo.nPage = 10;*/247 scrollInfo.fMask = SIF_RANGE | SIF_POS /*| SIF_PAGE*/;331 scrollInfo.nPage = 10; 332 scrollInfo.fMask = SIF_RANGE | SIF_POS | SIF_PAGE; 248 333 SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE); 249 334 } … … 279 364 if (nHiddenHeight % nScrollPosHeight == 0) 280 365 { 281 scrollInfo.nMax = nHiddenHeight / nScrollPosHeight; 366 scrollInfo.nMax = nHiddenHeight / nScrollPosHeight; 282 367 } 283 368 else 284 369 { 285 scrollInfo.nMax = nHiddenHeight / nScrollPosHeight + 1; 370 scrollInfo.nMax = nHiddenHeight / nScrollPosHeight + 1; 286 371 } 287 372 288 373 scrollInfo.nMin = 0; 289 /*scrollInfo.nPage = 10;*/290 scrollInfo.fMask = SIF_RANGE | SIF_POS /*| SIF_PAGE*/;374 scrollInfo.nPage = 10; 375 scrollInfo.fMask = SIF_RANGE | SIF_POS | SIF_PAGE; 291 376 SetScrollInfo(hwnd, SB_VERT, &scrollInfo, TRUE); 292 377 } … … 1775 1860 } 1776 1861 1862 /* Don't bother painting item being edited */ 1863 if (infoPtr->lpeditItem && lvItem.state & LVIS_FOCUSED) 1864 return; 1865 1777 1866 if ((lvItem.state & LVIS_SELECTED) && (infoPtr->bFocus != FALSE)) 1778 1867 { … … 1922 2011 * DESCRIPTION: 1923 2012 * Draws listview items when in report display mode. 1924 * 1925 * PARAMETER(S): 1926 * [I] HWND : window handle 1927 * [I] HDC : device context handle 2013 * 2014 * PARAMETER(S): 2015 * [I] HWND : window handle 2016 * [I] HDC : device context handle 1928 2017 * 1929 2018 * RETURN: … … 1933 2022 { 1934 2023 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd,0); 2024 SCROLLINFO scrollInfo; 1935 2025 INT nDrawPosY = infoPtr->rcList.top; 1936 2026 INT nColumnCount; … … 1940 2030 INT nLast; 1941 2031 2032 ZeroMemory(&scrollInfo, sizeof(SCROLLINFO)); 2033 scrollInfo.cbSize = sizeof(SCROLLINFO); 2034 scrollInfo.fMask = SIF_POS; 2035 1942 2036 nItem = ListView_GetTopIndex(hwnd); 1943 2037 … … 1955 2049 rcItem.top = nDrawPosY; 1956 2050 rcItem.bottom = rcItem.top + infoPtr->nItemHeight; 2051 2052 /* Offset the Scroll Bar Pos */ 2053 if (GetScrollInfo(hwnd, SB_HORZ, &scrollInfo) != FALSE) 2054 { 2055 rcItem.left -= (scrollInfo.nPos * REPORT_HSCROLL_INC_SIZE); 2056 rcItem.right -= (scrollInfo.nPos * REPORT_HSCROLL_INC_SIZE); 2057 } 2058 1957 2059 if (j == 0) 1958 2060 { 1959 LISTVIEW_DrawItem(hwnd, hdc, nItem, rcItem); 1960 } 1961 else 2061 LISTVIEW_DrawItem(hwnd, hdc, nItem, rcItem); 2062 } 2063 else 1962 2064 { 1963 2065 LISTVIEW_DrawSubItem(hwnd, hdc, nItem, j, rcItem); 1964 2066 } 1965 2067 } 1966 2068 1967 2069 nDrawPosY += infoPtr->nItemHeight; 1968 2070 } … … 2070 2172 * DESCRIPTION: 2071 2173 * Draws listview items when in list display mode. 2072 * 2073 * PARAMETER(S): 2074 * [I] HWND : window handle 2075 * [I] HDC : device context handle 2174 * 2175 * PARAMETER(S): 2176 * [I] HWND : window handle 2177 * [I] HDC : device context handle 2076 2178 * 2077 2179 * RETURN: … … 2086 2188 INT nColumnCount; 2087 2189 INT nCountPerColumn; 2088 2190 INT nItemWidth = LISTVIEW_GetItemWidth(hwnd); 2191 INT nItemHeight = LISTVIEW_GetItemHeight(hwnd); 2192 2089 2193 /* get number of fully visible columns */ 2090 2194 nColumnCount = LISTVIEW_GetColumnCount(hwnd); … … 2099 2203 return; 2100 2204 2101 rcItem.top = j * infoPtr->nItemHeight;2102 rcItem.left = i * infoPtr->nItemWidth;2103 rcItem.bottom = rcItem.top + infoPtr->nItemHeight;2104 rcItem.right = rcItem.left + infoPtr->nItemWidth;2205 rcItem.top = j * nItemHeight; 2206 rcItem.left = i * nItemWidth; 2207 rcItem.bottom = rcItem.top + nItemHeight; 2208 rcItem.right = rcItem.left + nItemWidth; 2105 2209 LISTVIEW_DrawItem(hwnd, hdc, nItem, rcItem); 2106 2210 } … … 2459 2563 * DESCRIPTION: 2460 2564 * Removes a column from the listview control. 2461 * 2565 * 2462 2566 * PARAMETER(S): 2463 2567 * [I] HWND : window handle … … 2473 2577 UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK; 2474 2578 BOOL bResult = FALSE; 2475 2579 2476 2580 if (Header_DeleteItem(infoPtr->hwndHeader, nColumn) != FALSE) 2477 2581 { 2478 2582 bResult = LISTVIEW_RemoveColumn(infoPtr->hdpaItems, nColumn); 2583 2584 /* Need to reset the item width when deleting a column */ 2585 infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd); 2479 2586 2480 2587 /* reset scroll parameters */ … … 2592 2699 } 2593 2700 2594 /* LISTVIEW_EditLabel */ 2701 /*** 2702 * DESCRIPTION: 2703 * Return edit control handle of current edit label 2704 * 2705 * PARAMETER(S): 2706 * [I] HWND : window handle 2707 * 2708 * RETURN: 2709 * SUCCESS : HWND 2710 * FAILURE : 0 2711 */ 2712 static LRESULT LISTVIEW_GetEditControl(hwnd) 2713 { 2714 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0); 2715 return infoPtr->hwndEdit; 2716 } 2717 2718 2719 /*** 2720 * DESCRIPTION: 2721 * Callback implementation for editlabel control 2722 * 2723 * PARAMETER(S): 2724 * [I] HWND : window handle 2725 * [I] LPSTR : modified text 2726 * [I] DWORD : item index 2727 * 2728 * RETURN: 2729 * SUCCESS : TRUE 2730 * FAILURE : FALSE 2731 */ 2732 2733 static BOOL LISTVIEW_EndEditLabel(HWND hwnd, LPSTR pszText, DWORD nItem) 2734 { 2735 NMLVDISPINFOA dispInfo; 2736 LISTVIEW_ITEM *lpItem; 2737 INT nCtrlId = GetWindowLongA(hwnd, GWL_ID); 2738 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0); 2739 HDPA hdpaSubItems; 2740 2741 ZeroMemory(&dispInfo, sizeof(NMLVDISPINFOA)); 2742 2743 if (NULL == (hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, nItem))) 2744 return FALSE; 2745 2746 if (NULL == (lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0))) 2747 return FALSE; 2748 2749 dispInfo.hdr.hwndFrom = hwnd; 2750 dispInfo.hdr.idFrom = nCtrlId; 2751 dispInfo.hdr.code = LVN_ENDLABELEDITA; 2752 dispInfo.item.mask = 0; 2753 dispInfo.item.iItem = nItem; 2754 dispInfo.item.state = lpItem->state; 2755 dispInfo.item.stateMask = 0; 2756 dispInfo.item.pszText = pszText; 2757 dispInfo.item.cchTextMax = pszText ? strlen(pszText) : 0; 2758 dispInfo.item.iImage = lpItem->iImage; 2759 dispInfo.item.lParam = lpItem->lParam; 2760 2761 ListView_Notify(GetParent(hwnd), nCtrlId, &dispInfo); 2762 infoPtr->hwndEdit = 0; 2763 infoPtr->lpeditItem = NULL; 2764 2765 return TRUE; 2766 } 2767 2768 /*** 2769 * DESCRIPTION: 2770 * Begin in place editing of specified list view item 2771 * 2772 * PARAMETER(S): 2773 * [I] HWND : window handle 2774 * [I] INT : item index 2775 * 2776 * RETURN: 2777 * SUCCESS : TRUE 2778 * FAILURE : FALSE 2779 */ 2780 2781 static HWND LISTVIEW_EditLabelA(HWND hwnd, INT nItem) 2782 { 2783 NMLVDISPINFOA dispInfo; 2784 RECT rect; 2785 LISTVIEW_ITEM *lpItem; 2786 HWND hedit; 2787 HINSTANCE hinst = GetWindowLongA(hwnd, GWL_HINSTANCE); 2788 INT nCtrlId = GetWindowLongA(hwnd, GWL_ID); 2789 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0); 2790 HDPA hdpaSubItems; 2791 2792 if (~GetWindowLongA(hwnd, GWL_STYLE) & LVS_EDITLABELS) 2793 return FALSE; 2794 2795 ZeroMemory(&dispInfo, sizeof(NMLVDISPINFOA)); 2796 if (NULL == (hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, nItem))) 2797 return 0; 2798 2799 if (NULL == (lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0))) 2800 return 0; 2801 2802 dispInfo.hdr.hwndFrom = hwnd; 2803 dispInfo.hdr.idFrom = nCtrlId; 2804 dispInfo.hdr.code = LVN_BEGINLABELEDITA; 2805 dispInfo.item.mask = 0; 2806 dispInfo.item.iItem = nItem; 2807 dispInfo.item.state = lpItem->state; 2808 dispInfo.item.stateMask = 0; 2809 dispInfo.item.pszText = lpItem->pszText; 2810 dispInfo.item.cchTextMax = strlen(lpItem->pszText); 2811 dispInfo.item.iImage = lpItem->iImage; 2812 dispInfo.item.lParam = lpItem->lParam; 2813 2814 if (ListView_LVNotify(GetParent(hwnd), nCtrlId, &dispInfo)) 2815 return 0; 2816 2817 rect.left = LVIR_LABEL; 2818 if (!LISTVIEW_GetItemRect(hwnd, nItem, &rect)) 2819 return 0; 2820 2821 if (!(hedit = CreateEditLabel(dispInfo.item.pszText , WS_VISIBLE, 2822 rect.left, rect.top, rect.right - rect.left + 15, 2823 rect.bottom - rect.top, 2824 hwnd, hinst, LISTVIEW_EndEditLabel, nItem))) 2825 return 0; 2826 2827 infoPtr->hwndEdit = hedit; 2828 infoPtr->lpeditItem = lpItem; 2829 SetFocus(hedit); 2830 SendMessageA(hedit, EM_SETSEL, 0, -1); 2831 2832 return hedit; 2833 } 2595 2834 2596 2835 /*** … … 3323 3562 Str_SetPtrA(&lpItem->pszText, dispInfo.item.pszText); 3324 3563 } 3325 lpLVItem->pszText = dispInfo.item.pszText;3564 strncpy(lpLVItem->pszText, dispInfo.item.pszText, lpLVItem->cchTextMax); 3326 3565 } 3327 3566 else if (lpLVItem->mask & LVIF_TEXT) 3328 3567 { 3329 lpLVItem->pszText = lpItem->pszText;3568 strncpy(lpLVItem->pszText, lpItem->pszText, lpLVItem->cchTextMax); 3330 3569 } 3331 3570 … … 3418 3657 Str_SetPtrA(&lpSubItem->pszText, dispInfo.item.pszText); 3419 3658 } 3420 lpLVItem->pszText = dispInfo.item.pszText;3659 strncpy(lpLVItem->pszText, dispInfo.item.pszText, lpLVItem->cchTextMax); 3421 3660 } 3422 3661 else if (lpLVItem->mask & LVIF_TEXT) 3423 3662 { 3424 lpLVItem->pszText = lpSubItem->pszText;3663 strncpy(lpLVItem->pszText, lpSubItem->pszText, lpLVItem->cchTextMax); 3425 3664 } 3426 3665 } … … 4536 4775 (WPARAM)nColumn, (LPARAM)&hdi); 4537 4776 4777 /* Need to reset the item width when inserting a new column */ 4778 infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd); 4779 4538 4780 LISTVIEW_UpdateScroll(hwnd); 4539 4781 InvalidateRect(hwnd, NULL, FALSE); … … 5458 5700 infoPtr->iconSpacing.cy = GetSystemMetrics(SM_CYICONSPACING); 5459 5701 ZeroMemory(&infoPtr->rcList, sizeof(RECT)); 5702 infoPtr->hwndEdit = 0; 5703 infoPtr->lpeditItem = NULL; 5460 5704 5461 5705 /* get default font (icon title) */ … … 5564 5808 * DESCRIPTION: 5565 5809 * Performs vertical scrolling. 5566 * 5810 * 5567 5811 * PARAMETER(S): 5568 5812 * [I] HWND : window handle 5569 5813 * [I] INT : scroll code 5570 * [I] SHORT : current scroll position if scroll code is SB_THIMBPOSITION 5814 * [I] SHORT : current scroll position if scroll code is SB_THIMBPOSITION 5571 5815 * or SB_THUMBTRACK. 5572 5816 * [I] HWND : scrollbar control window handle … … 5578 5822 HWND hScrollWnd) 5579 5823 { 5580 UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;5581 5824 SCROLLINFO scrollInfo; 5582 5825 5583 5826 ZeroMemory(&scrollInfo, sizeof(SCROLLINFO)); 5584 5827 scrollInfo.cbSize = sizeof(SCROLLINFO); 5585 scrollInfo.fMask = /*SIF_PAGE |*/SIF_POS | SIF_RANGE;5586 5828 scrollInfo.fMask = SIF_PAGE | SIF_POS | SIF_RANGE; 5829 5587 5830 if (GetScrollInfo(hwnd, SB_VERT, &scrollInfo) != FALSE) 5588 5831 { … … 5596 5839 } 5597 5840 break; 5598 5841 5599 5842 case SB_LINEDOWN: 5600 5843 if (scrollInfo.nPos < scrollInfo.nMax) … … 5603 5846 } 5604 5847 break; 5605 5848 5606 5849 case SB_PAGEUP: 5607 5850 if (scrollInfo.nPos > scrollInfo.nMin) 5608 5851 { 5609 INT nPage = 0; 5610 5611 if (uView == LVS_REPORT) 5612 { 5613 nPage = LISTVIEW_GetCountPerColumn(hwnd); 5614 } 5615 else if ((uView == LVS_ICON) || (uView == LVS_SMALLICON)) 5616 { 5617 nPage = 10; 5618 } 5619 5620 if (scrollInfo.nPos >= nPage) 5621 { 5622 scrollInfo.nPos -= nPage; 5852 5853 if (scrollInfo.nPos >= scrollInfo.nPage) 5854 { 5855 scrollInfo.nPos -= scrollInfo.nPage; 5623 5856 } 5624 5857 else … … 5628 5861 } 5629 5862 break; 5630 5863 5631 5864 case SB_PAGEDOWN: 5632 5865 if (scrollInfo.nPos < scrollInfo.nMax) 5633 5866 { 5634 INT nPage = 0; 5635 5636 if (uView == LVS_REPORT) 5637 { 5638 nPage = LISTVIEW_GetCountPerColumn(hwnd); 5639 } 5640 else if ((uView == LVS_ICON) || (uView == LVS_SMALLICON)) 5641 { 5642 nPage = 10; 5643 } 5644 5645 if (scrollInfo.nPos <= scrollInfo.nMax - nPage) 5646 { 5647 scrollInfo.nPos += nPage; 5867 if (scrollInfo.nPos <= scrollInfo.nMax - scrollInfo.nPage) 5868 { 5869 scrollInfo.nPos += scrollInfo.nPage; 5648 5870 } 5649 5871 else … … 5654 5876 break; 5655 5877 5656 case SB_THUMBPOSITION: 5878 case SB_THUMBTRACK: 5879 scrollInfo.nPos = nCurrentPos; 5657 5880 break; 5658 5881 } … … 5662 5885 scrollInfo.fMask = SIF_POS; 5663 5886 SetScrollInfo(hwnd, SB_VERT, &scrollInfo, TRUE); 5664 InvalidateRect(hwnd, NULL, FALSE);5665 } 5666 } 5667 5887 InvalidateRect(hwnd, NULL, TRUE); 5888 } 5889 } 5890 5668 5891 return 0; 5669 5892 } … … 5672 5895 * DESCRIPTION: 5673 5896 * Performs horizontal scrolling. 5674 * 5897 * 5675 5898 * PARAMETER(S): 5676 5899 * [I] HWND : window handle 5677 5900 * [I] INT : scroll code 5678 * [I] SHORT : current scroll position if scroll code is SB_THIMBPOSITION 5901 * [I] SHORT : current scroll position if scroll code is SB_THIMBPOSITION 5679 5902 * or SB_THUMBTRACK. 5680 5903 * [I] HWND : scrollbar control window handle … … 5686 5909 HWND hScrollWnd) 5687 5910 { 5688 UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;5689 5911 SCROLLINFO scrollInfo; 5690 5912 5691 5913 ZeroMemory(&scrollInfo, sizeof(SCROLLINFO)); 5692 5914 scrollInfo.cbSize = sizeof(SCROLLINFO); 5693 scrollInfo.fMask = /*SIF_PAGE |*/SIF_POS | SIF_RANGE;5694 5915 scrollInfo.fMask = SIF_PAGE | SIF_POS | SIF_RANGE; 5916 5695 5917 if (GetScrollInfo(hwnd, SB_HORZ, &scrollInfo) != FALSE) 5696 5918 { … … 5705 5927 } 5706 5928 break; 5707 5929 5708 5930 case SB_LINERIGHT: 5709 5931 if (scrollInfo.nPos < scrollInfo.nMax) … … 5712 5934 } 5713 5935 break; 5714 5936 5715 5937 case SB_PAGELEFT: 5716 5938 if (scrollInfo.nPos > scrollInfo.nMin) 5717 5939 { 5718 INT nPage = 0; 5719 5720 if (uView == LVS_LIST) 5721 { 5722 nPage = LISTVIEW_GetCountPerRow(hwnd); 5723 } 5724 else if ((uView == LVS_ICON) || (uView == LVS_SMALLICON)) 5725 { 5726 nPage = 10; 5727 } 5728 5729 if (scrollInfo.nPos >= nPage) 5730 { 5731 scrollInfo.nPos -= nPage; 5940 if (scrollInfo.nPos >= scrollInfo.nPage) 5941 { 5942 scrollInfo.nPos -= scrollInfo.nPage; 5732 5943 } 5733 5944 else … … 5737 5948 } 5738 5949 break; 5739 5950 5740 5951 case SB_PAGERIGHT: 5741 5952 if (scrollInfo.nPos < scrollInfo.nMax) 5742 5953 { 5743 INT nPage = 0; 5744 5745 if (uView == LVS_LIST) 5746 { 5747 nPage = LISTVIEW_GetCountPerRow(hwnd); 5748 } 5749 else if ((uView == LVS_ICON) || (uView == LVS_SMALLICON)) 5750 { 5751 nPage = 10; 5752 } 5753 5754 if (scrollInfo.nPos <= scrollInfo.nMax - nPage) 5755 { 5756 scrollInfo.nPos += nPage; 5954 if (scrollInfo.nPos <= scrollInfo.nMax - scrollInfo.nPage) 5955 { 5956 scrollInfo.nPos += scrollInfo.nPage; 5757 5957 } 5758 5958 else … … 5763 5963 break; 5764 5964 5765 case SB_THUMBPOSITION: 5965 case SB_THUMBTRACK: 5966 scrollInfo.nPos = nCurrentPos; 5766 5967 break; 5767 5968 } … … 5769 5970 if (nOldScrollPos != scrollInfo.nPos) 5770 5971 { 5972 UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK; 5771 5973 scrollInfo.fMask = SIF_POS; 5772 5974 SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE); 5773 InvalidateRect(hwnd, NULL, FALSE); 5774 } 5775 } 5776 5975 scrollInfo.fMask = SIF_PAGE | SIF_POS | SIF_RANGE; 5976 GetScrollInfo(hwnd, SB_HORZ, &scrollInfo); 5977 if(uView == LVS_REPORT) 5978 { 5979 LISTVIEW_UpdateHeaderSize(hwnd, scrollInfo.nPos, nOldScrollPos); 5980 } 5981 InvalidateRect(hwnd, NULL, TRUE); 5982 } 5983 } 5984 5777 5985 return 0; 5778 5986 } … … 6146 6354 * DESCRIPTION: 6147 6355 * Handles notifications from children. 6148 * 6356 * 6149 6357 * PARAMETER(S): 6150 6358 * [I] HWND : window handle 6151 6359 * [I] INT : control identifier 6152 6360 * [I] LPNMHDR : notification information 6153 * 6361 * 6154 6362 * RETURN: 6155 6363 * Zero … … 6158 6366 { 6159 6367 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0); 6160 6161 if (lpnmh->hwndFrom == infoPtr->hwndHeader) 6368 6369 if (lpnmh->hwndFrom == infoPtr->hwndHeader) 6162 6370 { 6163 6371 /* handle notification from header control */ … … 6165 6373 { 6166 6374 infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd); 6167 InvalidateRect(hwnd, NULL, FALSE); 6168 } 6375 InvalidateRect(hwnd, NULL, TRUE); 6376 } 6377 else if(lpnmh->code == HDN_ITEMCLICKA) 6378 { 6379 /* Handle sorting by Header Column */ 6380 NMLISTVIEW nmlv; 6381 LPNMHEADERA pnmHeader = (LPNMHEADERA) lpnmh; 6382 LONG lCtrlId = GetWindowLongA(hwnd, GWL_ID); 6383 6384 ZeroMemory(&nmlv, sizeof(NMLISTVIEW)); 6385 nmlv.hdr.hwndFrom = hwnd; 6386 nmlv.hdr.idFrom = lCtrlId; 6387 nmlv.hdr.code = LVN_COLUMNCLICK; 6388 nmlv.iItem = -1; 6389 nmlv.iSubItem = pnmHeader->iItem; 6390 6391 ListView_LVNotify(GetParent(hwnd),lCtrlId, &nmlv); 6392 6393 } 6394 else if(lpnmh->code == NM_RELEASEDCAPTURE) 6395 { 6396 /* Idealy this should be done in HDN_ENDTRACKA 6397 * but since SetItemBounds in Header.c is called after 6398 * the notification is sent, it is neccessary to handle the 6399 * update of the scroll bar here (Header.c works fine as it is, 6400 * no need to disturb it) 6401 */ 6402 LISTVIEW_UpdateScroll(hwnd); 6403 InvalidateRect(hwnd, NULL, TRUE); 6404 } 6405 6169 6406 } 6170 6407 … … 6673 6910 return LISTVIEW_DeleteItem(hwnd, (INT)wParam); 6674 6911 6675 /* case LVM_EDITLABEL: */ 6912 case LVM_EDITLABELW: 6913 case LVM_EDITLABELA: 6914 return LISTVIEW_EditLabelA(hwnd, (INT)wParam); 6676 6915 6677 6916 case LVM_ENSUREVISIBLE: … … 6705 6944 return LISTVIEW_GetCountPerPage(hwnd); 6706 6945 6707 /* case LVM_GETEDITCONTROL: */ 6946 case LVM_GETEDITCONTROL: 6947 return LISTVIEW_GetEditControl(hwnd); 6948 6708 6949 case LVM_GETEXTENDEDLISTVIEWSTYLE: 6709 6950 return LISTVIEW_GetExtendedListViewStyle(hwnd); … … 6889 7130 6890 7131 /* case WM_CHAR: */ 6891 /* case WM_COMMAND: */ 7132 case WM_COMMAND: 7133 return LISTVIEW_Command(hwnd, wParam, lParam); 6892 7134 6893 7135 case WM_CREATE: … … 7038 7280 } 7039 7281 7282 /*** 7283 * DESCRIPTION: 7284 * Handle any WM_COMMAND messages 7285 * 7286 * PARAMETER(S): 7287 * 7288 * RETURN: 7289 */ 7290 static LRESULT LISTVIEW_Command(HWND hwnd, WPARAM wParam, LPARAM lParam) 7291 { 7292 switch (HIWORD(wParam)) 7293 { 7294 case EN_UPDATE: 7295 { 7296 /* 7297 * Adjust the edit window size 7298 */ 7299 char buffer[1024]; 7300 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0); 7301 HDC hdc = GetDC(infoPtr->hwndEdit); 7302 RECT rect; 7303 SIZE sz; 7304 7305 GetWindowTextA(infoPtr->hwndEdit, buffer, 1024); 7306 GetWindowRect(infoPtr->hwndEdit, &rect); 7307 if (GetTextExtentPoint32A(hdc, buffer, strlen(buffer), &sz)) 7308 { 7309 SetWindowPos ( 7310 infoPtr->hwndEdit, 7311 HWND_TOP, 7312 0, 7313 0, 7314 sz.cx + 15, 7315 rect.bottom - rect.top, 7316 SWP_DRAWFRAME|SWP_NOMOVE); 7317 } 7318 ReleaseDC(hwnd, hdc); 7319 7320 break; 7321 } 7322 7323 default: 7324 return SendMessageA (GetParent (hwnd), WM_COMMAND, wParam, lParam); 7325 } 7326 7327 return 0; 7328 } 7329 7330 7331 /*** 7332 * DESCRIPTION: 7333 * Subclassed edit control windproc function 7334 * 7335 * PARAMETER(S): 7336 * 7337 * RETURN: 7338 */ 7339 LRESULT CALLBACK EditLblWndProc(HWND hwnd, UINT uMsg, 7340 WPARAM wParam, LPARAM lParam) 7341 { 7342 BOOL cancel = TRUE; 7343 EDITLABEL_ITEM *einfo = 7344 (EDITLABEL_ITEM *) GetWindowLongA(hwnd, GWL_USERDATA); 7345 7346 switch (uMsg) 7347 { 7348 case WM_KILLFOCUS: 7349 break; 7350 7351 case WM_CHAR: 7352 if (VK_RETURN == (INT)wParam) 7353 { 7354 cancel = FALSE; 7355 break; 7356 } 7357 else if (VK_ESCAPE == (INT)wParam) 7358 break; 7359 7360 default: 7361 return CallWindowProcA(einfo->EditWndProc, hwnd, 7362 uMsg, wParam, lParam); 7363 } 7364 7365 SetWindowLongA(hwnd, GWL_WNDPROC, (LONG)einfo->EditWndProc); 7366 if (einfo->EditLblCb) 7367 { 7368 char *buffer = NULL; 7369 7370 if (!cancel) 7371 { 7372 int len = 1 + GetWindowTextLengthA(hwnd); 7373 7374 if (len > 1) 7375 { 7376 if (NULL != (buffer = (char *)COMCTL32_Alloc(len*sizeof(char)))) 7377 { 7378 GetWindowTextA(hwnd, buffer, len); 7379 } 7380 } 7381 } 7382 7383 einfo->EditLblCb(GetParent(hwnd), buffer, einfo->param); 7384 7385 if (buffer) 7386 COMCTL32_Free(buffer); 7387 } 7388 7389 COMCTL32_Free(einfo); 7390 PostMessageA(hwnd, WM_CLOSE, 0, 0); 7391 return TRUE; 7392 } 7393 7394 7395 /*** 7396 * DESCRIPTION: 7397 * Creates a subclassed edit cotrol 7398 * 7399 * PARAMETER(S): 7400 * 7401 * RETURN: 7402 */ 7403 HWND CreateEditLabel(LPCSTR text, DWORD style, INT x, INT y, 7404 INT width, INT height, HWND parent, HINSTANCE hinst, 7405 EditlblCallback EditLblCb, DWORD param) 7406 { 7407 HWND hedit; 7408 EDITLABEL_ITEM *einfo; 7409 7410 if (NULL == (einfo = COMCTL32_Alloc(sizeof(EDITLABEL_ITEM)))) 7411 return 0; 7412 7413 style |= WS_CHILDWINDOW|WS_CLIPSIBLINGS|ES_LEFT|WS_BORDER; 7414 if (!(hedit = CreateWindowA("Edit", text, style, x, y, width, height, 7415 parent, 0, hinst, 0))) 7416 { 7417 COMCTL32_Free(einfo); 7418 return 0; 7419 } 7420 7421 einfo->param = param; 7422 einfo->EditLblCb = EditLblCb; 7423 einfo->EditWndProc = (WNDPROC)SetWindowLongA(hedit, 7424 GWL_WNDPROC, (LONG) EditLblWndProc); 7425 7426 SetWindowLongA(hedit, GWL_USERDATA, (LONG)einfo); 7427 7428 return hedit; 7429 }
Note:
See TracChangeset
for help on using the changeset viewer.