Changeset 3154 for trunk/src/comctl32/listview.cpp
- Timestamp:
- Mar 18, 2000, 5:17:35 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/comctl32/listview.cpp
r2895 r3154 1 /*$Id: listview.cpp,v 1. 2 2000-02-25 17:00:16cbratschi Exp $*/1 /*$Id: listview.cpp,v 1.3 2000-03-18 16:17:24 cbratschi Exp $*/ 2 2 /* 3 3 * Listview control … … 39 39 40 40 /* 41 - Corel 20000 212level42 - WINE 20000130 level41 - Corel 20000317 level 42 - (WINE 20000130 level) 43 43 */ 44 44 45 45 #include <string.h> 46 46 #include <wcstr.h> 47 #include <stdio.h> 47 48 #include "winbase.h" 48 49 #include "commctrl.h" … … 50 51 #include "listview.h" 51 52 #include "comctl32.h" 53 #include "ctype.h" 52 54 53 55 /* … … 96 98 97 99 #define LISTVIEW_GetInfoPtr(hwnd) ((LISTVIEW_INFO*)getInfoPtr(hwnd)) 100 101 INT WINAPI COMCTL32_StrCmpNIA(LPCSTR,LPCSTR,INT); 102 103 #define strncasecmp COMCTL32_StrCmpNIA 98 104 99 105 /* … … 2032 2038 } 2033 2039 2040 /* Don't bother painting item being edited */ 2041 if (infoPtr->hwndEdit && lvItem.state & LVIS_FOCUSED) 2042 return; 2043 2034 2044 rcItem.top += infoPtr->iconSize.cy + ICON_BOTTOM_PADDING; 2035 2045 nLabelWidth = ListView_GetStringWidthW(hwnd, lvItem.pszText); … … 2069 2079 * None 2070 2080 */ 2071 static VOID LISTVIEW_ RefreshReport(HWND hwnd, HDC hdc)2081 static VOID LISTVIEW_DrawReport(HWND hwnd, HDC hdc) 2072 2082 { 2073 2083 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)LISTVIEW_GetInfoPtr(hwnd); … … 2242 2252 * None 2243 2253 */ 2244 static VOID LISTVIEW_ RefreshList(HWND hwnd, HDC hdc)2254 static VOID LISTVIEW_DrawList(HWND hwnd, HDC hdc) 2245 2255 { 2246 2256 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)LISTVIEW_GetInfoPtr(hwnd); … … 2250 2260 INT nColumnCount; 2251 2261 INT nCountPerColumn; 2252 INT nItemWidth = LISTVIEW_GetItemWidth(hwnd);2253 INT nItemHeight = LISTVIEW_GetItemHeight(hwnd);2262 INT nItemWidth = infoPtr->nItemWidth; 2263 INT nItemHeight = infoPtr->nItemHeight; 2254 2264 2255 2265 /* get number of fully visible columns */ … … 2285 2295 * None 2286 2296 */ 2287 static VOID LISTVIEW_ RefreshIcon(HWND hwnd, HDC hdc, BOOL bSmall)2297 static VOID LISTVIEW_DrawIcon(HWND hwnd, HDC hdc, BOOL bSmall) 2288 2298 { 2289 2299 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)LISTVIEW_GetInfoPtr(hwnd); … … 2338 2348 * NoneX 2339 2349 */ 2340 static VOID LISTVIEW_ Refresh(HWND hwnd, HDC hdc)2350 static VOID LISTVIEW_Draw(HWND hwnd, HDC hdc) 2341 2351 { 2342 2352 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)LISTVIEW_GetInfoPtr(hwnd); … … 2357 2367 if (uView == LVS_LIST) 2358 2368 { 2359 LISTVIEW_ RefreshList(hwnd, hdc);2369 LISTVIEW_DrawList(hwnd, hdc); 2360 2370 } 2361 2371 else if (uView == LVS_REPORT) 2362 2372 { 2363 LISTVIEW_ RefreshReport(hwnd, hdc);2373 LISTVIEW_DrawReport(hwnd, hdc); 2364 2374 } 2365 2375 else if (uView == LVS_SMALLICON) 2366 2376 { 2367 LISTVIEW_ RefreshIcon(hwnd, hdc, TRUE);2377 LISTVIEW_DrawIcon(hwnd, hdc, TRUE); 2368 2378 } 2369 2379 else if (uView == LVS_ICON) 2370 2380 { 2371 LISTVIEW_ RefreshIcon(hwnd, hdc, FALSE);2381 LISTVIEW_DrawIcon(hwnd, hdc, FALSE); 2372 2382 } 2373 2383 … … 5172 5182 LISTVIEW_ITEM *lpItem = NULL; 5173 5183 5174 // TRACE("(hwnd=%x,lpLVItem=%p)\n", hwnd, lpLVItem);5175 5176 5184 if (lpLVItem != NULL) 5177 5185 { … … 5214 5222 if (lpLVItem->mask & LVIF_STATE) 5215 5223 { 5216 if (lpLVItem->stateMask & LVIS_FOCUSED) 5224 lpItem->state &= ~(LVIS_FOCUSED|LVIS_SELECTED); 5225 if (lpLVItem->stateMask & LVIS_SELECTED) 5226 { 5227 LISTVIEW_SetSelection(hwnd, nItem); 5228 } 5229 else if (lpLVItem->stateMask & LVIS_FOCUSED) 5217 5230 { 5218 5231 LISTVIEW_SetItemFocus(hwnd, nItem); … … 5940 5953 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)LISTVIEW_GetInfoPtr(hwnd); 5941 5954 5955 if (first == second) 5956 return 0; 5957 5942 5958 rv = (infoPtr->pfnCompare)( ((LISTVIEW_ITEM*) first)->lParam, 5943 5959 ((LISTVIEW_ITEM*) second)->lParam, infoPtr->lParamSort ); … … 6523 6539 } 6524 6540 6541 /************************ Defines that LISTVIEW_ProcessLetterKeys uses *******************************/ 6542 #define KEY_DELAY 900 6543 #define LISTVIEW_InitLvItemStruct(item,idx,TEXT) \ 6544 ZeroMemory(&(item), sizeof(LVITEMA)); \ 6545 (item).mask = LVIF_TEXT; \ 6546 (item).iItem = (idx); \ 6547 (item).iSubItem = 0; \ 6548 (item).pszText = (CHAR*)&(TEXT); \ 6549 (item).cchTextMax = MAX_PATH 6550 6551 /************************************************************************************************************************ 6552 * DESCRIPTION: 6553 * Processes keyboard messages generated by pressing the letter keys on the keyboard. 6554 * Assumes the list is sorted alphabetically, without regard to case. 6555 * 6556 * PARAMETERS: 6557 * [ I ] HWND: handle to the window 6558 * [ I ] WPARAM: the character code, the actual character 6559 * [ I ] LPARAM: key data 6560 * 6561 * 6562 * RETURN: 6563 * Zero. 6564 * 6565 * CHANGE LOG: 6566 * Feb 17, 2000 -------------> Creation of function. 6567 * Feb 22, 2000 -------------> Added macros. 6568 * TODO: 6569 * 6570 * 6571 ************************************************************************************************************************/ 6572 static INT LISTVIEW_ProcessLetterKeys( HWND hwnd, WPARAM charCode, LPARAM keyData ) 6573 { 6574 LISTVIEW_INFO *infoPtr = NULL; 6575 INT nItem = -1; 6576 BOOL bRedraw; 6577 INT nSize = 0; 6578 INT idx = 0; 6579 BOOL bFoundMatchingFiles = FALSE; 6580 LVITEMA item; 6581 CHAR TEXT[ MAX_PATH ]; 6582 CHAR szCharCode[ 2 ]; 6583 DWORD timeSinceLastKeyPress = 0; 6584 6585 sprintf( szCharCode, "%c", charCode ); 6586 6587 /* simple parameter checking */ 6588 if ( !hwnd || !charCode || !keyData ) 6589 return 0; 6590 6591 infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0); 6592 6593 if ( !infoPtr ) 6594 return 0; 6595 6596 /* only allow the valid WM_CHARs through */ 6597 if ( isalnum( charCode ) || charCode == '.' || charCode == '`' || charCode == '!' 6598 || charCode == '@' || charCode == '#' || charCode == '$' || charCode == '%' 6599 || charCode == '^' || charCode == '&' || charCode == '*' || charCode == '(' 6600 || charCode == ')' || charCode == '-' || charCode == '_' || charCode == '+' 6601 || charCode == '=' || charCode == '\\'|| charCode == ']' || charCode == '}' 6602 || charCode == '[' || charCode == '{' || charCode == '/' || charCode == '?' 6603 || charCode == '>' || charCode == '<' || charCode == ',' || charCode == '~') 6604 { 6605 timeSinceLastKeyPress = GetTickCount(); 6606 6607 nSize = GETITEMCOUNT( infoPtr ); 6608 /* if there are 0 items, there is no where to go */ 6609 if ( nSize == 0 ) 6610 return 0; 6611 /* 6612 * If the last charCode equals the current charCode then look 6613 * to the next element in list to see if it matches the previous 6614 * charCode. 6615 */ 6616 if ( infoPtr->charCode == charCode ) 6617 { 6618 if ( timeSinceLastKeyPress - infoPtr->timeSinceLastKeyPress < KEY_DELAY ) 6619 { /* append new character to search string */ 6620 strcat( infoPtr->szSearchParam, szCharCode ); 6621 infoPtr->nSearchParamLength++; 6622 6623 /* loop from start of list view */ 6624 for( idx = infoPtr->nFocusedItem; idx < nSize; idx++ ) 6625 { /* get item */ 6626 LISTVIEW_InitLvItemStruct( item, idx, TEXT ); 6627 ListView_GetItemA( hwnd, &item ); 6628 6629 /* compare items */ 6630 if ( strncasecmp( item.pszText, infoPtr->szSearchParam, 6631 infoPtr->nSearchParamLength ) == 0 ) 6632 { 6633 nItem = idx; 6634 break; 6635 } 6636 } 6637 } 6638 else if ( infoPtr->timeSinceLastKeyPress > timeSinceLastKeyPress ) 6639 { /* The DWORD went over it's boundery?? Ergo assuming too slow??. */ 6640 for ( idx = 0; idx < nSize; idx++ ) 6641 { 6642 LISTVIEW_InitLvItemStruct( item, idx, TEXT ); 6643 ListView_GetItemA( hwnd, &item ); 6644 6645 if ( strncasecmp( &( item.pszText[ 0 ] ), szCharCode, 1 ) == 0 ) 6646 { 6647 nItem = idx; 6648 break; 6649 } 6650 } 6651 strcpy( infoPtr->szSearchParam, szCharCode ); 6652 infoPtr->nSearchParamLength = 1; 6653 } 6654 else 6655 { /* Save szCharCode for use in later searches */ 6656 strcpy( infoPtr->szSearchParam, szCharCode ); 6657 infoPtr->nSearchParamLength = 1; 6658 6659 LISTVIEW_InitLvItemStruct( item, infoPtr->nFocusedItem + 1, TEXT ); 6660 ListView_GetItemA( hwnd, &item ); 6661 6662 if ( strncasecmp( &( item.pszText[ 0 ] ), szCharCode, 1 ) == 0 ) 6663 nItem = infoPtr->nFocusedItem + 1; 6664 else 6665 { /* 6666 * Ok so there are no more folders that match 6667 * now we look for files. 6668 */ 6669 for ( idx = infoPtr->nFocusedItem + 1; idx < nSize; idx ++ ) 6670 { 6671 LISTVIEW_InitLvItemStruct( item, idx, TEXT ); 6672 ListView_GetItemA( hwnd, &item ); 6673 6674 if ( strncasecmp( &( item.pszText[ 0 ] ), szCharCode, 1 ) == 0 ) 6675 { 6676 nItem = idx; 6677 bFoundMatchingFiles = TRUE; 6678 break; 6679 } 6680 } 6681 if ( !bFoundMatchingFiles ) 6682 { /* go back to first instance */ 6683 for ( idx = 0; idx < nSize; idx ++ ) 6684 { 6685 LISTVIEW_InitLvItemStruct( item,idx, TEXT ); 6686 ListView_GetItemA( hwnd, &item ); 6687 6688 if ( strncasecmp( &( item.pszText[ 0 ] ), szCharCode, 1 ) == 0 ) 6689 { 6690 nItem = idx; 6691 break; 6692 } 6693 } 6694 } 6695 } 6696 } 6697 } /*END: if ( infoPtr->charCode == charCode )*/ 6698 6699 else /* different keypressed */ 6700 { 6701 /* could be that they are spelling the file/directory for us */ 6702 if ( timeSinceLastKeyPress - infoPtr->timeSinceLastKeyPress > KEY_DELAY ) 6703 { /* 6704 * Too slow, move to the first instance of the 6705 * charCode. 6706 */ 6707 for ( idx = 0; idx < nSize; idx++ ) 6708 { 6709 LISTVIEW_InitLvItemStruct( item,idx, TEXT ); 6710 ListView_GetItemA( hwnd, &item ); 6711 6712 if ( strncasecmp( &( item.pszText[ 0 ] ), szCharCode, 1 ) == 0 ) 6713 { 6714 nItem = idx; 6715 break; 6716 } 6717 } 6718 strcpy( infoPtr->szSearchParam, szCharCode ); 6719 infoPtr->nSearchParamLength = 1; 6720 } 6721 else if ( infoPtr->timeSinceLastKeyPress > timeSinceLastKeyPress ) 6722 { /* The DWORD went over it's boundery?? Ergo assuming too slow??. */ 6723 for ( idx = 0; idx < nSize; idx++ ) 6724 { 6725 LISTVIEW_InitLvItemStruct( item,idx, TEXT ); 6726 ListView_GetItemA( hwnd, &item ); 6727 6728 if ( strncasecmp( &( item.pszText[ 0 ] ), szCharCode, 1 ) == 0 ) 6729 { 6730 nItem = idx; 6731 break; 6732 } 6733 } 6734 strcpy( infoPtr->szSearchParam, szCharCode ); 6735 infoPtr->nSearchParamLength = 1; 6736 } 6737 else /* Search for the string the user is typing */ 6738 { 6739 /* append new character to search string */ 6740 strcat( infoPtr->szSearchParam, szCharCode ); 6741 infoPtr->nSearchParamLength++; 6742 6743 /* loop from start of list view */ 6744 for( idx = 0; idx < nSize; idx++ ) 6745 { /* get item */ 6746 LISTVIEW_InitLvItemStruct( item, idx, TEXT ); 6747 ListView_GetItemA( hwnd, &item ); 6748 6749 /* compare items */ 6750 if ( strncasecmp( item.pszText, infoPtr->szSearchParam, 6751 infoPtr->nSearchParamLength ) == 0 ) 6752 { 6753 nItem = idx; 6754 break; 6755 } 6756 } 6757 } 6758 }/*END: else */ 6759 } 6760 else 6761 return 0; 6762 6763 bRedraw = LISTVIEW_KeySelection(hwnd, nItem ); 6764 if (bRedraw != FALSE) 6765 { 6766 /* refresh client area */ 6767 InvalidateRect(hwnd, NULL, TRUE); 6768 UpdateWindow(hwnd); 6769 } 6770 6771 /* Store the WM_CHAR for next time */ 6772 infoPtr->charCode = charCode; 6773 6774 /* Store time */ 6775 infoPtr->timeSinceLastKeyPress = timeSinceLastKeyPress; 6776 6777 return 0; 6778 6779 }/*END:LISTVIEW_ProcessLetterKeys( HWND hwndParent, INT nVirtualKey, LONG lKeyData ) */ 6780 6525 6781 /*** 6526 6782 * DESCRIPTION: … … 6866 7122 { 6867 7123 hdc = BeginPaint(hwnd, &ps); 6868 LISTVIEW_ Refresh(hwnd, hdc);7124 LISTVIEW_Draw(hwnd, hdc); 6869 7125 EndPaint(hwnd, &ps); 6870 7126 } 6871 7127 else 6872 7128 { 6873 LISTVIEW_ Refresh(hwnd, hdc);7129 LISTVIEW_Draw(hwnd, hdc); 6874 7130 } 6875 7131 … … 7307 7563 } 7308 7564 7565 /* If they change the view and we have an active edit control 7566 we will need to kill the control since the redraw will 7567 misplace the edit control. 7568 */ 7569 if (infoPtr->hwndEdit && 7570 ((uNewView & (LVS_ICON|LVS_LIST|LVS_SMALLICON)) != 7571 ((LVS_ICON|LVS_LIST|LVS_SMALLICON) & uOldView))) 7572 { 7573 SendMessageA(infoPtr->hwndEdit, WM_KILLFOCUS, 0, 0); 7574 } 7575 7309 7576 return 0; 7310 7577 } … … 7568 7835 return LISTVIEW_Update(hwnd, (INT)wParam); 7569 7836 7570 /* case WM_CHAR: */ 7837 case WM_CHAR: 7838 return LISTVIEW_ProcessLetterKeys( hwnd, wParam, lParam ); 7839 7571 7840 case WM_COMMAND: 7572 7841 return LISTVIEW_Command(hwnd, wParam, lParam);
Note:
See TracChangeset
for help on using the changeset viewer.