Ignore:
Timestamp:
Mar 18, 2000, 5:17:35 PM (25 years ago)
Author:
cbratschi
Message:

Corel 20000317 merge, ccbase finished, bug fixes

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:16 cbratschi Exp $*/
     1/*$Id: listview.cpp,v 1.3 2000-03-18 16:17:24 cbratschi Exp $*/
    22/*
    33 * Listview control
     
    3939
    4040/*
    41  - Corel 20000212 level
    42  - WINE 20000130 level
     41 - Corel 20000317 level
     42 - (WINE 20000130 level)
    4343*/
    4444
    4545#include <string.h>
    4646#include <wcstr.h>
     47#include <stdio.h>
    4748#include "winbase.h"
    4849#include "commctrl.h"
     
    5051#include "listview.h"
    5152#include "comctl32.h"
     53#include "ctype.h"
    5254
    5355/*
     
    9698
    9799#define LISTVIEW_GetInfoPtr(hwnd) ((LISTVIEW_INFO*)getInfoPtr(hwnd))
     100
     101INT WINAPI COMCTL32_StrCmpNIA(LPCSTR,LPCSTR,INT);
     102
     103#define strncasecmp COMCTL32_StrCmpNIA
    98104
    99105/*
     
    20322038  }
    20332039
     2040  /* Don't bother painting item being edited */
     2041  if (infoPtr->hwndEdit && lvItem.state & LVIS_FOCUSED)
     2042      return;
     2043
    20342044  rcItem.top += infoPtr->iconSize.cy + ICON_BOTTOM_PADDING;
    20352045  nLabelWidth = ListView_GetStringWidthW(hwnd, lvItem.pszText);
     
    20692079 * None
    20702080 */
    2071 static VOID LISTVIEW_RefreshReport(HWND hwnd, HDC hdc)
     2081static VOID LISTVIEW_DrawReport(HWND hwnd, HDC hdc)
    20722082{
    20732083  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)LISTVIEW_GetInfoPtr(hwnd);
     
    22422252 * None
    22432253 */
    2244 static VOID LISTVIEW_RefreshList(HWND hwnd, HDC hdc)
     2254static VOID LISTVIEW_DrawList(HWND hwnd, HDC hdc)
    22452255{
    22462256  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)LISTVIEW_GetInfoPtr(hwnd);
     
    22502260  INT nColumnCount;
    22512261  INT nCountPerColumn;
    2252   INT nItemWidth = LISTVIEW_GetItemWidth(hwnd);
    2253   INT nItemHeight = LISTVIEW_GetItemHeight(hwnd);
     2262  INT nItemWidth = infoPtr->nItemWidth;
     2263  INT nItemHeight = infoPtr->nItemHeight;
    22542264
    22552265  /* get number of fully visible columns */
     
    22852295 * None
    22862296 */
    2287 static VOID LISTVIEW_RefreshIcon(HWND hwnd, HDC hdc, BOOL bSmall)
     2297static VOID LISTVIEW_DrawIcon(HWND hwnd, HDC hdc, BOOL bSmall)
    22882298{
    22892299  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)LISTVIEW_GetInfoPtr(hwnd);
     
    23382348 * NoneX
    23392349 */
    2340 static VOID LISTVIEW_Refresh(HWND hwnd, HDC hdc)
     2350static VOID LISTVIEW_Draw(HWND hwnd, HDC hdc)
    23412351{
    23422352  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)LISTVIEW_GetInfoPtr(hwnd);
     
    23572367  if (uView == LVS_LIST)
    23582368  {
    2359     LISTVIEW_RefreshList(hwnd, hdc);
     2369    LISTVIEW_DrawList(hwnd, hdc);
    23602370  }
    23612371  else if (uView == LVS_REPORT)
    23622372  {
    2363     LISTVIEW_RefreshReport(hwnd, hdc);
     2373    LISTVIEW_DrawReport(hwnd, hdc);
    23642374  }
    23652375  else if (uView == LVS_SMALLICON)
    23662376  {
    2367     LISTVIEW_RefreshIcon(hwnd, hdc, TRUE);
     2377    LISTVIEW_DrawIcon(hwnd, hdc, TRUE);
    23682378  }
    23692379  else if (uView == LVS_ICON)
    23702380  {
    2371     LISTVIEW_RefreshIcon(hwnd, hdc, FALSE);
     2381    LISTVIEW_DrawIcon(hwnd, hdc, FALSE);
    23722382  }
    23732383
     
    51725182  LISTVIEW_ITEM *lpItem = NULL;
    51735183
    5174 //  TRACE("(hwnd=%x,lpLVItem=%p)\n", hwnd, lpLVItem);
    5175 
    51765184  if (lpLVItem != NULL)
    51775185  {
     
    52145222                if (lpLVItem->mask & LVIF_STATE)
    52155223                {
    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)
    52175230                  {
    52185231                    LISTVIEW_SetItemFocus(hwnd, nItem);
     
    59405953  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)LISTVIEW_GetInfoPtr(hwnd);
    59415954
     5955  if (first == second)
     5956    return 0;
     5957
    59425958  rv = (infoPtr->pfnCompare)( ((LISTVIEW_ITEM*) first)->lParam,
    59435959          ((LISTVIEW_ITEM*) second)->lParam, infoPtr->lParamSort );
     
    65236539}
    65246540
     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************************************************************************************************************************/
     6572static 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
    65256781/***
    65266782 * DESCRIPTION:
     
    68667122  {
    68677123    hdc = BeginPaint(hwnd, &ps);
    6868     LISTVIEW_Refresh(hwnd, hdc);
     7124    LISTVIEW_Draw(hwnd, hdc);
    68697125    EndPaint(hwnd, &ps);
    68707126  }
    68717127  else
    68727128  {
    6873     LISTVIEW_Refresh(hwnd, hdc);
     7129    LISTVIEW_Draw(hwnd, hdc);
    68747130  }
    68757131
     
    73077563  }
    73087564
     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
    73097576  return 0;
    73107577}
     
    75687835    return LISTVIEW_Update(hwnd, (INT)wParam);
    75697836
    7570 /*      case WM_CHAR: */
     7837  case WM_CHAR:
     7838    return LISTVIEW_ProcessLetterKeys( hwnd, wParam, lParam );
     7839
    75717840  case WM_COMMAND:
    75727841    return LISTVIEW_Command(hwnd, wParam, lParam);
Note: See TracChangeset for help on using the changeset viewer.