Changeset 164 for trunk/src


Ignore:
Timestamp:
Jun 23, 1999, 9:45:02 PM (26 years ago)
Author:
achimha
Message:

updated comctl32 with the latest WINE bugfixes. Listview is much better now and tab control doesn't have the wrong color anymore. Many small improvements

Location:
trunk/src/comctl32
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/comctl32/comctl32.c

    r94 r164  
    1 /* $Id: comctl32.c,v 1.5 1999-06-10 16:21:58 achimha Exp $ */
     1/* $Id: comctl32.c,v 1.6 1999-06-23 19:45:00 achimha Exp $ */
    22/*
    33 * Win32 common controls implementation
     
    313313    UINT border = BDR_SUNKENOUTER;
    314314
    315     if (style == SBT_POPOUT)
     315    if (style & SBT_POPOUT)
    316316      border = BDR_RAISEDOUTER;
    317     else if (style == SBT_NOBORDERS)
     317    else if (style & SBT_NOBORDERS)
    318318      border = 0;
    319319
  • trunk/src/comctl32/comctl32undoc.c

    r94 r164  
    1 /* $Id: comctl32undoc.c,v 1.6 1999-06-10 16:21:58 achimha Exp $ */
     1/* $Id: comctl32undoc.c,v 1.7 1999-06-23 19:45:00 achimha Exp $ */
    22/*
    33 * Undocumented functions from COMCTL32.DLL
     
    618618    LPVOID pDest, lpTemp;
    619619   
    620 //    TRACE (commctrl, "(%p %d %p)\n", hdsa, nIndex, pSrc);
     620//    TRACE("(%p %d %p)\n", hdsa, nIndex, pSrc);
    621621
    622622    if ((!hdsa) || nIndex < 0)
     
    627627        if (hdsa->nMaxCount > nIndex) {
    628628            /* within the allocated space, set a new boundary */
    629             hdsa->nItemCount = nIndex;
     629            hdsa->nItemCount = nIndex + 1;
    630630        }
    631631        else {
     
    640640
    641641            hdsa->nMaxCount = nNewItems;
     642            hdsa->nItemCount = nIndex + 1;
    642643            hdsa->pData = lpTemp;
    643644        }   
     
    646647    /* put the new entry in */
    647648    pDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
    648 //    TRACE (commctrl, "-- move dest=%p src=%p size=%d\n",
     649//    TRACE("-- move dest=%p src=%p size=%d\n",
    649650//         pDest, pSrc, hdsa->nItemSize);
    650651    memmove (pDest, pSrc, hdsa->nItemSize);
     
    674675    LPDWORD p;
    675676   
    676 //    TRACE(commctrl, "(%p %d %p)\n", hdsa, nIndex, pSrc);
     677//    TRACE("(%p %d %p)\n", hdsa, nIndex, pSrc);
    677678
    678679    if ((!hdsa) || nIndex < 0)
     
    682683        p = *(DWORD**)((char *) pSrc + i);
    683684//      if (IsBadStringPtrA ((char*)p, 256))
    684 //          TRACE (commctrl, "-- %d=%p\n", i, (DWORD*)p);
     685//          TRACE("-- %d=%p\n", i, (DWORD*)p);
    685686//      else
    686 //          TRACE (commctrl, "-- %d=%p [%s]\n", i, p, debugstr_a((char*)p));
     687//          TRACE("-- %d=%p [%s]\n", i, p, debugstr_a((char*)p));
    687688    }
    688689   
     
    709710        lpDest = (char *) lpTemp + hdsa->nItemSize;
    710711        nSize = (hdsa->nItemCount - nIndex) * hdsa->nItemSize;
    711 //      TRACE (commctrl, "-- move dest=%p src=%p size=%d\n",
     712//      TRACE("-- move dest=%p src=%p size=%d\n",
    712713//             lpDest, lpTemp, nSize);
    713714        memmove (lpDest, lpTemp, nSize);
     
    717718    hdsa->nItemCount++;
    718719    lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
    719 //    TRACE (commctrl, "-- move dest=%p src=%p size=%d\n",
     720//    TRACE("-- move dest=%p src=%p size=%d\n",
    720721//         lpDest, pSrc, hdsa->nItemSize);
    721722    memmove (lpDest, pSrc, hdsa->nItemSize);
  • trunk/src/comctl32/imagelist.c

    r94 r164  
    1 /* $Id: imagelist.c,v 1.3 1999-06-10 16:21:59 achimha Exp $ */
     1/* $Id: imagelist.c,v 1.4 1999-06-23 19:45:00 achimha Exp $ */
    22/*
    33 *  ImageList implementation
     
    12071207    HICON  hIcon;
    12081208    HDC    hdcSrc, hdcDst;
    1209     INT    nWidth, nHeight;
    12101209
    12111210    if ((himl == NULL) || (i < 0) || (i >= himl->cCurImage))
    12121211        return 0;
    12131212
    1214     nWidth = GetSystemMetrics (SM_CXICON);
    1215     nHeight = GetSystemMetrics (SM_CYICON);
    1216 
    12171213    hdcSrc = CreateCompatibleDC(0);
    12181214    hdcDst = CreateCompatibleDC(0);
    12191215
    12201216    ii.fIcon = TRUE;
    1221     ii.xHotspot = nWidth / 2;
    1222     ii.yHotspot = nHeight / 2;
    1223     ii.hbmMask  = CreateCompatibleBitmap (hdcDst, nWidth, nHeight);
    1224     ii.hbmColor = CreateCompatibleBitmap (hdcDst, nWidth, nHeight);
     1217    ii.hbmMask  = CreateCompatibleBitmap (hdcDst, himl->cx, himl->cy);
     1218    ii.hbmColor = CreateCompatibleBitmap (hdcDst, himl->cx, himl->cy);
    12251219
    12261220
     
    12291223    if (himl->hbmMask) {
    12301224        SelectObject (hdcSrc, himl->hbmMask);
    1231         BitBlt (hdcDst, 0, 0, nWidth, nHeight,
     1225        BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
    12321226                  hdcSrc, i * himl->cx, 0, SRCCOPY);
    12331227    }
    12341228    else
    1235         PatBlt (hdcDst, 0, 0, nWidth, nHeight, BLACKNESS);
     1229        PatBlt (hdcDst, 0, 0, himl->cx, himl->cy, BLACKNESS);
    12361230
    12371231    /* draw image*/
    12381232    SelectObject (hdcDst, ii.hbmColor);
    12391233    SelectObject (hdcSrc, himl->hbmImage);
    1240     BitBlt (hdcDst, 0, 0, nWidth, nHeight,
     1234    BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
    12411235              hdcSrc, i * himl->cx, 0, SRCCOPY);
    12421236
  • trunk/src/comctl32/listview.c

    r94 r164  
    1 /* $Id: listview.c,v 1.3 1999-06-10 16:22:00 achimha Exp $ */
    21/*
    32 * Listview control
     
    1110 *
    1211 * TODO:
    13  *
    14  *   1. Multiple selections in icon or small icon display modes DO NOT
    15  *      behave like the Microsoft control.
    16  *   2. No horizontal scrolling when header is larger than the client area.
    17  *   3. Implement LVM_FINDITEM for key selections.
    18  *   4. Drawing optimizations.
     12 *   1. No horizontal scrolling when header is larger than the client area.
     13 *   2. Drawing optimizations.
    1914 *
    2015 * Notifications:
     
    2217 *
    2318 * Data structure:
    24  *   LISTVIEW_SortItems : empty stub
    2519 *   LISTVIEW_SetItemCount : empty stub
    2620 *
     
    4135 *   LISTVIEW_GetColumnOrderArray : not implemented
    4236 *   LISTVIEW_Arrange : empty stub
    43  *   LISTVIEW_FindItem : empty stub
    4437 *   LISTVIEW_ApproximateViewRect : incomplete
    4538 *   LISTVIEW_Scroll : not implemented
    46  *   LISTVIEW_KeyDown : page up and page down  + redo small icon and icon
    4739 *   LISTVIEW_RedrawItems : empty stub
    4840 *   LISTVIEW_Update : not completed
     
    5345#include "commctrl.h"
    5446#include "listview.h"
     47#include "debugtools.h"
    5548
    5649/*
     
    8679 * macros
    8780 */
    88 
    89 /* retrieve the number of items in the listview */
    9081#define GETITEMCOUNT(infoPtr) ((infoPtr)->hdpaItems->nItemCount)
    9182#define ListView_LVNotify(hwnd,lCtrlId,plvnm) \
     
    9384#define ListView_Notify(hwnd,lCtrlId,pnmh) \
    9485    (BOOL)SendMessageA((hwnd),WM_NOTIFY,(WPARAM)(INT)lCtrlId,(LPARAM)(LPNMHDR)(pnmh))
     86/* retrieve the number of items in the listview */
     87#define GETITEMCOUNT(infoPtr) ((infoPtr)->hdpaItems->nItemCount)
    9588
    9689/*
    9790 * forward declarations
    9891 */
    99 
     92static INT LISTVIEW_HitTestItem(HWND, LPLVHITTESTINFO);
     93static INT LISTVIEW_GetCountPerRow(HWND);
     94static INT LISTVIEW_GetCountPerColumn(HWND);
    10095static VOID LISTVIEW_AlignLeft(HWND);
    10196static VOID LISTVIEW_AlignTop(HWND);
     
    10499static BOOL LISTVIEW_AddSubItem(HWND, LPLVITEMA);
    105100static INT LISTVIEW_FindInsertPosition(HDPA, INT);
    106 static VOID LISTVIEW_GetItemDispInfo(HWND, INT, LISTVIEW_ITEM *lpItem, INT *,
    107                                      UINT *, CHAR **, INT);
    108 static INT LISTVIEW_GetItemHeight(HWND, LONG);
     101static INT LISTVIEW_GetItemHeight(HWND);
    109102static BOOL LISTVIEW_GetItemPosition(HWND, INT, LPPOINT);
    110103static LRESULT LISTVIEW_GetItemRect(HWND, INT, LPRECT);
    111 static INT LISTVIEW_GetItemWidth(HWND, LONG);
     104static INT LISTVIEW_GetItemWidth(HWND);
    112105static INT LISTVIEW_GetLabelWidth(HWND, INT);
    113106static LRESULT LISTVIEW_GetOrigin(HWND, LPPOINT);
    114107static LISTVIEW_SUBITEM* LISTVIEW_GetSubItem(HDPA, INT);
    115 static VOID LISTVIEW_GetSubItemDispInfo(HWND hwnd, INT, LPARAM,
    116                                         LISTVIEW_SUBITEM *, INT, INT *,
    117                                         CHAR **, INT);
    118108static LRESULT LISTVIEW_GetViewRect(HWND, LPRECT);
    119109static BOOL LISTVIEW_InitItem(HWND, LISTVIEW_ITEM *, LPLVITEMA);
    120110static BOOL LISTVIEW_InitSubItem(HWND, LISTVIEW_SUBITEM *, LPLVITEMA);
    121 static LRESULT LISTVIEW_MouseSelection(HWND, INT, INT);
     111static LRESULT LISTVIEW_MouseSelection(HWND, POINT);
    122112static BOOL LISTVIEW_RemoveColumn(HDPA, INT);
    123113static VOID LISTVIEW_RemoveSelections(HWND, INT, INT);
    124114static BOOL LISTVIEW_RemoveSubItem(HDPA, INT);
    125 static BOOL LISTVIEW_ScrollView(HWND, INT, INT);
    126115static VOID LISTVIEW_SetGroupSelection(HWND, INT);
    127116static BOOL LISTVIEW_SetItem(HWND, LPLVITEMA);
    128 static VOID LISTVIEW_SetItemFocus(HWND, INT);
     117static BOOL LISTVIEW_SetItemFocus(HWND, INT);
    129118static BOOL LISTVIEW_SetItemPosition(HWND, INT, INT, INT);
    130 static VOID LISTVIEW_SetScroll(HWND, LONG);
     119static VOID LISTVIEW_UpdateScroll(HWND);
    131120static VOID LISTVIEW_SetSelection(HWND, INT);
    132 static VOID LISTVIEW_SetSize(HWND, LONG, LONG, LONG);
     121static VOID LISTVIEW_UpdateSize(HWND);
    133122static BOOL LISTVIEW_SetSubItem(HWND, LPLVITEMA);
    134 static VOID LISTVIEW_SetViewInfo(HWND, LONG);
    135123static LRESULT LISTVIEW_SetViewRect(HWND, LPRECT);
    136124static BOOL LISTVIEW_ToggleSelection(HWND, INT);
     
    139127/***
    140128 * DESCRIPTION:
    141  * Scrolls the content of the listview.
    142  *
    143  * PARAMETER(S):
    144  * [I] HWND : window handle
    145  * [I] INT : number of horizontal scroll positions
    146  *           (relative to the current scroll postioon)
    147  * [I] INT : number of vertical scroll positions
    148  *           (relative to the current scroll postioon)
    149  *
    150  * RETURN:
    151  *   SUCCESS : TRUE
    152  *   FAILURE : FALSE
    153  */
    154 static BOOL LISTVIEW_ScrollView(HWND hwnd, INT nHScroll, INT nVScroll)
     129 * Update the scrollbars. This functions should be called whenever
     130 * the content, size or view changes.
     131 *
     132 * PARAMETER(S):
     133 * [I] HWND : window handle
     134 *
     135 * RETURN:
     136 * None
     137 */
     138static VOID LISTVIEW_UpdateScroll(HWND hwnd)
    155139{
    156140  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    157141  LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     142  UINT uView =  lStyle & LVS_TYPEMASK;
     143  INT nListHeight = infoPtr->rcList.bottom - infoPtr->rcList.top;
    158144  INT nListWidth = infoPtr->rcList.right - infoPtr->rcList.left;
    159   INT nListHeight = infoPtr->rcList.bottom - infoPtr->rcList.top;
    160   INT nHScrollPos = 0;
    161   INT nVScrollPos = 0;
    162   INT nHScrollInc = 0;
    163   INT nVScrollInc = 0;
    164   BOOL bResult = FALSE;
    165 
    166   if (((lStyle & WS_HSCROLL) != 0) && (nHScroll != 0))
    167   {
    168     switch (LVS_TYPEMASK & lStyle)
    169     {
    170     case LVS_LIST:
    171       nHScrollInc = nHScroll * infoPtr->nItemWidth;
    172       break;
    173 
    174     case LVS_REPORT:
    175       /* TO DO : not implemented at this point. I experiences some
    176          problems when performing child window scrolling. */
    177       break;
    178 
    179     case LVS_SMALLICON:
    180     case LVS_ICON:
    181       nHScrollInc = nHScroll * max(nListWidth, nListWidth / 10);
    182       break;
    183     }
    184    
    185     nHScrollPos = GetScrollPos(hwnd, SB_HORZ) + nHScroll;
    186   }
    187 
    188   if (((lStyle & WS_VSCROLL) != 0) & (nVScroll != 0))
    189   {
    190     switch (LVS_TYPEMASK & lStyle)
    191     {
    192     case LVS_REPORT:
    193       nVScrollInc = nVScroll * infoPtr->nItemHeight;
    194       nVScrollPos = GetScrollPos(hwnd, SB_VERT) + nVScroll;
    195       break;
     145  SCROLLINFO scrollInfo;
     146
     147  ZeroMemory(&scrollInfo, sizeof(SCROLLINFO));
     148  scrollInfo.cbSize = sizeof(SCROLLINFO);
     149
     150  if (uView == LVS_LIST)
     151  {
     152    INT nCountPerColumn = LISTVIEW_GetCountPerColumn(hwnd);
     153    INT nCountPerPage = LISTVIEW_GetCountPerRow(hwnd) * nCountPerColumn;
     154    if (nCountPerPage < GETITEMCOUNT(infoPtr))
     155    {
     156      /* calculate new scrollbar range */
     157      INT nHiddenItemCount = GETITEMCOUNT(infoPtr) - nCountPerPage;
     158      if (nHiddenItemCount % nCountPerColumn == 0)
     159      {
     160        scrollInfo.nMax = nHiddenItemCount / nCountPerColumn;
     161      }
     162      else
     163      {
     164        scrollInfo.nMax = nHiddenItemCount / nCountPerColumn + 1;
     165      }
    196166     
    197     case LVS_SMALLICON:
    198     case LVS_ICON:
    199       nVScrollInc = nVScroll * max(nListHeight, nListHeight / 10);
    200       nVScrollPos = GetScrollPos(hwnd, SB_VERT) + nVScroll;
    201       break;
    202     }
    203   }
    204 
    205   /* perform scroll operation & set new scroll position */
    206   if ((nHScrollInc != 0) || (nVScrollInc != 0))
    207   {
    208     RECT rc;
    209     HDC hdc = GetDC(hwnd);
    210     ScrollDC(hdc, -nHScrollInc, -nVScrollInc, &infoPtr->rcList, NULL,
    211              (HRGN) NULL, &rc);
    212     InvalidateRect(hwnd, &rc, TRUE);
    213     SetScrollPos(hwnd, SB_HORZ, nHScrollPos, TRUE);
    214     SetScrollPos(hwnd, SB_VERT, nVScrollPos, TRUE);
    215     ReleaseDC(hwnd, hdc);
    216     bResult = TRUE;
    217   }
    218 
    219   return bResult;
     167      scrollInfo.nPos = ListView_GetTopIndex(hwnd) / nCountPerColumn;
     168      /*scrollInfo.nPage = LISTVIEW_GetCountPerRow(hwnd);*/
     169      scrollInfo.fMask = SIF_RANGE | SIF_POS /*| SIF_PAGE*/;
     170      SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE);
     171    }
     172    else
     173    {
     174      /* hide scrollbar */
     175      if (lStyle & WS_HSCROLL)
     176      {
     177        ShowScrollBar(hwnd, SB_HORZ, FALSE);
     178      }
     179    }
     180  }
     181  else if (uView == LVS_REPORT)
     182  {
     183    /* update vertical scrollbar */
     184    scrollInfo.nMin = 0;
     185    scrollInfo.nMax = GETITEMCOUNT(infoPtr) - LISTVIEW_GetCountPerColumn(hwnd);
     186    scrollInfo.nPos = ListView_GetTopIndex(hwnd);
     187    /*scrollInfo.nPage = nCountPerColumn;*/
     188    scrollInfo.fMask = SIF_RANGE | SIF_POS /*| SIF_PAGE*/;
     189    SetScrollInfo(hwnd, SB_VERT, &scrollInfo, TRUE);
     190
     191    /* update horizontal scrollbar */
     192/*     if (infoPtr->nItemWidth > nListWidth) */
     193/*     { */
     194/*       scrollInfo.fMask = SIF_RANGE | SIF_POS | SIF_PAGE; */
     195/*       SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE); */
     196/*     } */
     197
     198    /* horizontal scrolling has not been implemented yet! I experienced some
     199       problems when performing child window scrolling. */
     200  }
     201  else
     202  {
     203    RECT rcView;
     204
     205    if (LISTVIEW_GetViewRect(hwnd, &rcView) != FALSE)
     206    {
     207      INT nViewWidth = rcView.right - rcView.left;
     208      INT nViewHeight = rcView.bottom - rcView.top;
     209
     210      if (nViewWidth > nListWidth)
     211      {
     212        INT nHiddenWidth;
     213        INT nScrollPosWidth = nListWidth / 10;
     214
     215        if (nScrollPosWidth == 0)
     216        {
     217          nScrollPosWidth = 1;
     218          nHiddenWidth = nViewWidth - nListWidth;
     219        }
     220        else
     221        {
     222          nHiddenWidth = nViewWidth - nScrollPosWidth * 10;
     223        }
     224
     225        scrollInfo.fMask = SIF_POS;
     226        if (GetScrollInfo(hwnd, SB_HORZ, &scrollInfo) == FALSE)
     227        {
     228          scrollInfo.nPos = 0;
     229        }
     230 
     231        if (nHiddenWidth % nScrollPosWidth == 0)
     232        {
     233          scrollInfo.nMax = nHiddenWidth / nScrollPosWidth;
     234        }
     235        else
     236        {
     237          scrollInfo.nMax = nHiddenWidth / nScrollPosWidth + 1;
     238        }
     239         
     240        scrollInfo.nMin = 0;
     241        /*scrollInfo.nPage = 10;*/
     242        scrollInfo.fMask = SIF_RANGE | SIF_POS /*| SIF_PAGE*/;
     243        SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE);
     244      }
     245      else
     246      {
     247        if (lStyle & WS_HSCROLL)
     248        {
     249          ShowScrollBar(hwnd, SB_HORZ, FALSE);
     250        }
     251      }
     252
     253      if (nViewHeight > nListHeight)
     254      {
     255        INT nHiddenHeight;
     256        INT nScrollPosHeight = nListHeight / 10;
     257
     258        if (nScrollPosHeight == 0)
     259        {
     260          nScrollPosHeight = 1;
     261          nHiddenHeight = nViewHeight - nListHeight;
     262        }
     263        else
     264        {
     265          nHiddenHeight = nViewHeight - nScrollPosHeight * 10;
     266        }
     267
     268        scrollInfo.fMask = SIF_POS;
     269        if (GetScrollInfo(hwnd, SB_VERT, &scrollInfo) == FALSE)
     270        {
     271          scrollInfo.nPos = 0;
     272        }
     273
     274        if (nHiddenHeight % nScrollPosHeight == 0)
     275        {
     276          scrollInfo.nMax = nHiddenHeight / nScrollPosHeight;
     277        }
     278        else
     279        {
     280          scrollInfo.nMax = nHiddenHeight / nScrollPosHeight + 1;
     281        }
     282
     283        scrollInfo.nMin = 0;
     284        /*scrollInfo.nPage = 10;*/
     285        scrollInfo.fMask = SIF_RANGE | SIF_POS /*| SIF_PAGE*/;
     286        SetScrollInfo(hwnd, SB_VERT, &scrollInfo, TRUE);
     287      }
     288      else
     289      {
     290        if (lStyle & WS_VSCROLL)
     291        {
     292          ShowScrollBar(hwnd, SB_VERT, FALSE);
     293        }
     294      }
     295    }
     296  }
    220297}
    221298
     
    235312  if ((LVS_TYPEMASK & lStyle) == LVS_EDITLABELS)
    236313  {
    237 //    FIXME( listview, "  LVS_EDITLABELS\n");
    238   }
    239 
    240   if ((LVS_TYPEMASK & lStyle) == LVS_NOCOLUMNHEADER)
    241   {
    242 //    FIXME( listview, "  LVS_SORTDESCENDING\n");
     314    FIXME("  LVS_EDITLABELS\n");
    243315  }
    244316
    245317  if ((LVS_TYPEMASK & lStyle) == LVS_NOLABELWRAP)
    246318  {
    247 //    FIXME( listview, "  LVS_NOLABELWRAP\n");
     319    FIXME("  LVS_NOLABELWRAP\n");
    248320  }
    249321
    250322  if ((LVS_TYPEMASK & lStyle) == LVS_NOSCROLL)
    251323  {
    252 //    FIXME( listview, "  LVS_NOSCROLL\n");
     324    FIXME("  LVS_NOSCROLL\n");
    253325  }
    254326
    255327  if ((LVS_TYPEMASK & lStyle) == LVS_NOSORTHEADER)
    256328  {
    257 //    FIXME( listview, "  LVS_NOSORTHEADER\n");
     329    FIXME("  LVS_NOSORTHEADER\n");
    258330  }
    259331
    260332  if ((LVS_TYPEMASK & lStyle) == LVS_OWNERDRAWFIXED)
    261333  {
    262 //    FIXME( listview, "  LVS_OWNERDRAWFIXED\n");
     334    FIXME("  LVS_OWNERDRAWFIXED\n");
    263335  }
    264336
    265337  if ((LVS_TYPEMASK & lStyle) == LVS_SHAREIMAGELISTS)
    266338  {
    267 //    FIXME( listview, "  LVS_SHAREIMAGELISTS\n");
    268   }
    269 
    270   if ((LVS_TYPEMASK & lStyle) == LVS_SHOWSELALWAYS)
    271   {
    272 //    FIXME( listview, "  LVS_SHOWSELALWAYS\n");
    273   }
    274 
    275   if ((LVS_TYPEMASK & lStyle) == LVS_SINGLESEL)
    276   {
    277 //    FIXME( listview, "  LVS_SINGLESEL\n");
     339    FIXME("  LVS_SHAREIMAGELISTS\n");
    278340  }
    279341
    280342  if ((LVS_TYPEMASK & lStyle) == LVS_SORTASCENDING)
    281343  {
    282 //    FIXME( listview, "  LVS_SORTASCENDING\n");
     344    FIXME("  LVS_SORTASCENDING\n");
    283345  }
    284346
    285347  if ((LVS_TYPEMASK & lStyle) == LVS_SORTDESCENDING)
    286348  {
    287 //    FIXME( listview, "  LVS_SORTDESCENDING\n");
     349    FIXME("  LVS_SORTDESCENDING\n");
    288350  }
    289351}
     
    302364{
    303365  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    304   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     366  UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    305367  INT nListWidth = infoPtr->rcList.right - infoPtr->rcList.left;
    306368  POINT ptItem;
     
    308370  INT i;
    309371 
    310   switch (LVS_TYPEMASK & lStyle)
    311   {
    312   case LVS_SMALLICON:
    313   case LVS_ICON:
     372  if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
     373  {
    314374    ZeroMemory(&ptItem, sizeof(POINT));
    315375    ZeroMemory(&rcView, sizeof(RECT));
     376   
    316377    if (nListWidth > infoPtr->nItemWidth)
    317378    {
     
    324385        }
    325386       
    326         LISTVIEW_SetItemPosition(hwnd, i, ptItem.x, ptItem.y);
     387        ListView_SetItemPosition(hwnd, i, ptItem.x, ptItem.y);
    327388        ptItem.x += infoPtr->nItemWidth;
    328389        rcView.right = max(rcView.right, ptItem.x);
    329390      }
     391
     392      rcView.bottom = ptItem.y + infoPtr->nItemHeight;
    330393    }
    331394    else
     
    333396      for (i = 0; i < GETITEMCOUNT(infoPtr); i++)
    334397      {
    335         LISTVIEW_SetItemPosition(hwnd, i, ptItem.x, ptItem.y);
    336         ptItem.x += infoPtr->nItemWidth;
    337       }
    338       rcView.right = ptItem.x;
    339       rcView.bottom = infoPtr->nItemHeight;
    340     }
    341 
    342     rcView.bottom = ptItem.y + infoPtr->nItemHeight;
     398        ListView_SetItemPosition(hwnd, i, ptItem.x, ptItem.y);
     399        ptItem.y += infoPtr->nItemHeight;
     400      }
     401
     402      rcView.right = infoPtr->nItemWidth;
     403      rcView.bottom = ptItem.y;
     404    }
     405
    343406    LISTVIEW_SetViewRect(hwnd, &rcView);
    344407  }
     
    358421{
    359422  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    360   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     423  UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    361424  INT nListHeight = infoPtr->rcList.bottom - infoPtr->rcList.top;
    362425  POINT ptItem;
     
    364427  INT i;
    365428 
    366   switch (LVS_TYPEMASK & lStyle)
    367   {
    368   case LVS_SMALLICON:
    369   case LVS_ICON:
     429  if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
     430  {
    370431    ZeroMemory(&ptItem, sizeof(POINT));
    371432    ZeroMemory(&rcView, sizeof(RECT));
     433
    372434    if (nListHeight > infoPtr->nItemHeight)
    373435    {
     
    380442        }
    381443
    382         LISTVIEW_SetItemPosition(hwnd, i, ptItem.x, ptItem.y);
     444        ListView_SetItemPosition(hwnd, i, ptItem.x, ptItem.y);
    383445        ptItem.y += infoPtr->nItemHeight;
    384446        rcView.bottom = max(rcView.bottom, ptItem.y);
    385447      }
     448
     449      rcView.right = ptItem.x + infoPtr->nItemWidth;
    386450    }
    387451    else
     
    389453      for (i = 0; i < GETITEMCOUNT(infoPtr); i++)
    390454      {
    391         LISTVIEW_SetItemPosition(hwnd, i, ptItem.x, ptItem.y);
    392         ptItem.y += infoPtr->nItemHeight;
    393       }
    394       rcView.bottom = ptItem.y;
    395       rcView.right = infoPtr->nItemWidth;
    396     }
    397 
    398     rcView.right = ptItem.x + infoPtr->nItemWidth;
     455        ListView_SetItemPosition(hwnd, i, ptItem.x, ptItem.y);
     456        ptItem.x += infoPtr->nItemWidth;
     457      }
     458
     459      rcView.bottom = infoPtr->nItemHeight;
     460      rcView.right = ptItem.x;
     461    }
     462
    399463    LISTVIEW_SetViewRect(hwnd, &rcView);
    400     break;
    401  }
    402 }
    403 
    404 /***
    405  * DESCRIPTION:
    406  * Retrieves display information.
    407  *
    408  * PARAMETER(S):
    409  * [I] HWND : window handle
    410  * [I] INT : item index
    411  * [I] LISTVIEW_ITEM* : listview control item
    412  * [O] INT : image index
    413  * [O] UINT : state value
    414  * [O] CHAR** : string
    415  * [I] INT : size of string
    416  *
    417  * RETURN:
    418  * None
    419  */
    420 static VOID LISTVIEW_GetItemDispInfo(HWND hwnd, INT nItem,
    421                                      LISTVIEW_ITEM *lpItem, INT *pnDispImage,
    422                                      UINT *puState, CHAR **ppszDispText,
    423                                      INT nDispTextSize)
    424 {
    425   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    426   LONG lCtrlId = GetWindowLongA(hwnd, GWL_ID);
    427   NMLVDISPINFOA dispInfo;
    428   ZeroMemory(&dispInfo, sizeof(NMLVDISPINFOA));
    429  
    430   if ((pnDispImage != NULL) && (lpItem->iImage == I_IMAGECALLBACK))
    431   {
    432     dispInfo.item.mask |= LVIF_IMAGE;
    433   }
    434 
    435   if ((ppszDispText != NULL) && (lpItem->pszText == LPSTR_TEXTCALLBACKA))
    436   {
    437     ZeroMemory(*ppszDispText, sizeof(CHAR)*nDispTextSize);
    438     dispInfo.item.mask |= LVIF_TEXT;
    439     dispInfo.item.pszText = *ppszDispText;
    440     dispInfo.item.cchTextMax = nDispTextSize;
    441   }
    442 
    443   if ((puState != NULL) && (infoPtr->uCallbackMask != 0))
    444   {
    445     dispInfo.item.mask |= LVIF_STATE;
    446     dispInfo.item.stateMask = infoPtr->uCallbackMask;
    447   }
    448 
    449   if (dispInfo.item.mask != 0)
    450   {
    451     dispInfo.hdr.hwndFrom = hwnd;
    452     dispInfo.hdr.idFrom = lCtrlId;
    453     dispInfo.hdr.code = LVN_GETDISPINFOA;
    454     dispInfo.item.iItem = nItem;
    455     dispInfo.item.iSubItem = 0;
    456     dispInfo.item.lParam = lpItem->lParam;
    457     ListView_Notify(GetParent(hwnd), lCtrlId, &dispInfo);
    458   }
    459 
    460   if (pnDispImage != NULL)
    461   {
    462     if (dispInfo.item.mask & LVIF_IMAGE)
    463     {
    464       *pnDispImage = dispInfo.item.iImage;
    465     }
    466     else
    467     {
    468       *pnDispImage = lpItem->iImage;
    469     }
    470   }
    471 
    472   if (ppszDispText != NULL)
    473   {
    474     if (dispInfo.item.mask & LVIF_TEXT)
    475     {
    476       if (dispInfo.item.mask & LVIF_DI_SETITEM)
    477       {
    478         Str_SetPtrA(&lpItem->pszText, dispInfo.item.pszText);
    479       }
    480       *ppszDispText = dispInfo.item.pszText;
    481     }
    482     else
    483     {
    484       *ppszDispText = lpItem->pszText;
    485     }
    486   }
    487 
    488   if (puState != NULL)
    489   {
    490     if (dispInfo.item.mask & LVIF_STATE)
    491     {
    492       *puState = lpItem->state;
    493       *puState &= ~dispInfo.item.stateMask;
    494       *puState |= (dispInfo.item.state & dispInfo.item.stateMask);
    495     }
    496     else
    497     {
    498       *puState = lpItem->state;
    499     }
    500   }
    501 }
    502 
    503 /***
    504  * DESCRIPTION:
    505  * Retrieves subitem display information.
    506  *
    507  * PARAMETER(S):
    508  * [I] HWND : window handle
    509  * [I] INT : item index
    510  * [I] LONG : LPARAM of item
    511  * [I] LISTVIEW_SUBITEM* : listview control subitem
    512  * [I] INT : subitem position/order
    513  * [O] INT : image index
    514  * [O] UINT : state value
    515  * [O] CHAR** : display string
    516  * [I] INT : size of string
    517  *
    518  * RETURN:
    519  * None
    520  */
    521 static VOID LISTVIEW_GetSubItemDispInfo(HWND hwnd, INT nItem, LPARAM lParam,
    522                                         LISTVIEW_SUBITEM *lpSubItem,
    523                                         INT nSubItemPos, INT *pnDispImage,
    524                                         CHAR **ppszDispText, INT nDispTextSize)
    525 {
    526   LONG lCtrlId = GetWindowLongA(hwnd, GWL_ID);
    527   NMLVDISPINFOA dispInfo;
    528   ZeroMemory(&dispInfo, sizeof(NMLVDISPINFOA));
    529 
    530   if (lpSubItem == NULL)
    531   {
    532     ZeroMemory(*ppszDispText, sizeof(CHAR)*nDispTextSize);
    533     dispInfo.item.mask |= LVIF_TEXT;
    534     dispInfo.item.pszText = *ppszDispText;
    535     dispInfo.item.cchTextMax = nDispTextSize;
    536     dispInfo.hdr.hwndFrom = hwnd;
    537     dispInfo.hdr.idFrom = lCtrlId;
    538     dispInfo.hdr.code = LVN_GETDISPINFOA;
    539     dispInfo.item.iItem = nItem;
    540     dispInfo.item.iSubItem = nSubItemPos;
    541     dispInfo.item.lParam = lParam;
    542     ListView_Notify(GetParent(hwnd), lCtrlId, &dispInfo);
    543     if (dispInfo.item.mask & LVIF_DI_SETITEM)
    544     {
    545       Str_SetPtrA(&lpSubItem->pszText, dispInfo.item.pszText);
    546     }
    547     *ppszDispText = dispInfo.item.pszText;
    548   }
    549   else
    550   {
    551     if ((pnDispImage != NULL) && (lpSubItem->iImage == I_IMAGECALLBACK))
    552     {
    553       dispInfo.item.mask |= LVIF_IMAGE;
    554     }
    555 
    556     if ((ppszDispText != NULL) && (lpSubItem->pszText == LPSTR_TEXTCALLBACKA))
    557     {
    558       ZeroMemory(*ppszDispText, sizeof(CHAR)*nDispTextSize);
    559       dispInfo.item.mask |= LVIF_TEXT;
    560       dispInfo.item.pszText = *ppszDispText;
    561       dispInfo.item.cchTextMax = nDispTextSize;
    562     }
    563 
    564     if (dispInfo.item.mask != 0)
    565     {
    566       dispInfo.hdr.hwndFrom = hwnd;
    567       dispInfo.hdr.idFrom = lCtrlId;
    568       dispInfo.hdr.code = LVN_GETDISPINFOA;
    569       dispInfo.item.iItem = nItem;
    570       dispInfo.item.iSubItem = lpSubItem->iSubItem;
    571       dispInfo.item.lParam = lParam;
    572       ListView_Notify(GetParent(hwnd), lCtrlId, &dispInfo);
    573     }
    574 
    575     if (pnDispImage != NULL)
    576     {
    577       if (dispInfo.item.mask & LVIF_IMAGE)
    578       {
    579         *pnDispImage = dispInfo.item.iImage;
    580       }
    581       else
    582       {
    583         *pnDispImage = lpSubItem->iImage;
    584       }
    585     }
    586 
    587     if (ppszDispText != NULL)
    588     {
    589       if (dispInfo.item.mask & LVIF_TEXT)
    590       {
    591         if (dispInfo.item.mask & LVIF_DI_SETITEM)
    592         {
    593           Str_SetPtrA(&lpSubItem->pszText, dispInfo.item.pszText);
    594         }
    595         *ppszDispText = dispInfo.item.pszText;
    596       }
    597       else
    598       {
    599         *ppszDispText = lpSubItem->pszText;
    600       }
    601     }
    602   }
     464  }
     465}
     466
     467/***
     468 * DESCRIPTION:
     469 * Set the bounding rectangle of all the items.
     470 *
     471 * PARAMETER(S):
     472 * [I] HWND : window handle
     473 * [I] LPRECT : bounding rectangle
     474 *
     475 * RETURN:
     476 *   SUCCESS : TRUE
     477 *   FAILURE : FALSE
     478 */
     479static LRESULT LISTVIEW_SetViewRect(HWND hwnd, LPRECT lprcView)
     480{
     481  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongA(hwnd, 0);
     482  BOOL bResult = FALSE;
     483
     484//  TRACE("(hwnd=%x, left=%d, top=%d, right=%d, bottom=%d)\n", hwnd,
     485//        lprcView->left, lprcView->top, lprcView->right, lprcView->bottom);
     486 
     487  if (lprcView != NULL)
     488  {
     489    bResult = TRUE;
     490    infoPtr->rcView.left = lprcView->left;
     491    infoPtr->rcView.top = lprcView->top;
     492    infoPtr->rcView.right = lprcView->right;
     493    infoPtr->rcView.bottom = lprcView->bottom;
     494  }
     495
     496  return bResult;
     497}
     498
     499/***
     500 * DESCRIPTION:
     501 * Retrieves the bounding rectangle of all the items.
     502 *
     503 * PARAMETER(S):
     504 * [I] HWND : window handle
     505 * [O] LPRECT : bounding rectangle
     506 *
     507 * RETURN:
     508 *   SUCCESS : TRUE
     509 *   FAILURE : FALSE
     510 */
     511static LRESULT LISTVIEW_GetViewRect(HWND hwnd, LPRECT lprcView)
     512{
     513  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongA(hwnd, 0);
     514  BOOL bResult = FALSE;
     515  POINT ptOrigin;
     516
     517//  TRACE("(hwnd=%x, lprcView=%p)\n", hwnd, lprcView);
     518
     519  if (lprcView != NULL)
     520  {
     521    bResult = LISTVIEW_GetOrigin(hwnd, &ptOrigin);
     522    if (bResult != FALSE)
     523    {
     524      lprcView->left = infoPtr->rcView.left + ptOrigin.x;
     525      lprcView->top = infoPtr->rcView.top + ptOrigin.y;
     526      lprcView->right = infoPtr->rcView.right + ptOrigin.x;
     527      lprcView->bottom = infoPtr->rcView.bottom + ptOrigin.y;
     528    }
     529
     530//    TRACE("(left=%d, top=%d, right=%d, bottom=%d)\n",
     531//          lprcView->left, lprcView->top, lprcView->right, lprcView->bottom);
     532  }
     533
     534  return bResult;
     535}
     536
     537/***
     538 * DESCRIPTION:
     539 * Retrieves the subitem pointer associated with the subitem index.
     540 *
     541 * PARAMETER(S):
     542 * [I] HDPA : DPA handle for a specific item
     543 * [I] INT : index of subitem
     544 *
     545 * RETURN:
     546 *   SUCCESS : subitem pointer
     547 *   FAILURE : NULL
     548 */
     549static LISTVIEW_SUBITEM* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems,
     550                                                INT nSubItem)
     551{
     552  LISTVIEW_SUBITEM *lpSubItem;
     553  INT i;
     554
     555  for (i = 1; i < hdpaSubItems->nItemCount; i++)
     556  {
     557    lpSubItem = (LISTVIEW_SUBITEM *) DPA_GetPtr(hdpaSubItems, i);
     558    if (lpSubItem != NULL)
     559    {
     560      if (lpSubItem->iSubItem == nSubItem)
     561      {
     562        return lpSubItem;
     563      }
     564    }
     565  }
     566
     567  return NULL;
    603568}
    604569
     
    614579 * Returns item width.
    615580 */
    616 static INT LISTVIEW_GetItemWidth(HWND hwnd, LONG lStyle)
    617 {
    618   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     581static INT LISTVIEW_GetItemWidth(HWND hwnd)
     582{
     583  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     584  UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    619585  INT nHeaderItemCount;
    620586  RECT rcHeaderItem;
     
    623589  INT i;
    624590
    625 //  TRACE(listview, "(hwnd=%x,lStyle=%lx)\n", hwnd, lStyle);
    626 
    627   switch (LVS_TYPEMASK & lStyle)
    628   {
    629   case LVS_ICON:
     591//  TRACE("(hwnd=%x)\n", hwnd);
     592
     593  if (uView == LVS_ICON)
     594  {
    630595    nItemWidth = infoPtr->iconSpacing.cx;
    631     break;
    632 
    633   case LVS_REPORT:
     596  }
     597  else if (uView == LVS_REPORT)
     598  {
    634599    /* calculate width of header */
    635600    nHeaderItemCount = Header_GetItemCount(infoPtr->hwndHeader);
     
    641606      }
    642607    }
    643     break;
    644 
    645   case LVS_SMALLICON:
    646   case LVS_LIST:
     608  }
     609  else
     610  {
    647611    for (i = 0; i < GETITEMCOUNT(infoPtr); i++)
    648612    {
     
    650614      nItemWidth = max(nItemWidth, nLabelWidth);
    651615    }
    652 
     616   
    653617    /* default label size */
    654618    if (GETITEMCOUNT(infoPtr) == 0)
     
    678642      }
    679643    }
    680     break;
    681 
    682   }
    683 
     644  }
     645 
    684646  return nItemWidth;
    685647}
     
    694656 *
    695657 * RETURN:
    696  * Returns item width.
    697  */
    698 static INT LISTVIEW_GetItemHeight(HWND hwnd, LONG lStyle)
    699 {
    700   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     658 * Returns item height.
     659 */
     660static INT LISTVIEW_GetItemHeight(HWND hwnd)
     661{
     662  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     663  UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    701664  INT nItemHeight = 0;
    702   TEXTMETRICA tm;
    703   HFONT hOldFont;
    704   HDC hdc;
    705 
    706   switch (LVS_TYPEMASK & lStyle)
    707   {
    708   case LVS_ICON:
     665
     666  if (uView == LVS_ICON)
     667  {
    709668    nItemHeight = infoPtr->iconSpacing.cy;
    710     break;
    711 
    712   case LVS_SMALLICON:
    713   case LVS_REPORT:
    714   case LVS_LIST:
    715     hdc = GetDC(hwnd);
    716     hOldFont = SelectObject(hdc, infoPtr->hFont);
     669  }
     670  else
     671  {
     672    TEXTMETRICA tm;
     673    HDC hdc = GetDC(hwnd);
     674    HFONT hOldFont = SelectObject(hdc, infoPtr->hFont);
    717675    GetTextMetricsA(hdc, &tm);
    718676    nItemHeight = max(tm.tmHeight, infoPtr->iconSize.cy) + HEIGHT_PADDING;
    719677    SelectObject(hdc, hOldFont);
    720678    ReleaseDC(hwnd, hdc);
    721     break;
    722679  }
    723680
    724681  return nItemHeight;
    725 }
    726 
    727 /***
    728  * DESCRIPTION:
    729  * Sets diplay information (needed for drawing operations).
    730  *
    731  * PARAMETER(S):
    732  * [I] HWND : window handle
    733  *
    734  * RETURN:
    735  * None
    736  */
    737 static VOID LISTVIEW_SetViewInfo(HWND hwnd, LONG lStyle)
    738 {
    739   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    740   INT nListHeight = infoPtr->rcList.bottom - infoPtr->rcList.top;
    741   INT nListWidth = infoPtr->rcList.right - infoPtr->rcList.left;
    742 
    743   switch (LVS_TYPEMASK & lStyle)
    744   {
    745   case LVS_REPORT:
    746     /* get number of fully visible items per column */
    747     infoPtr->nCountPerColumn = max(1, nListHeight / infoPtr->nItemHeight);
    748     break;
    749 
    750   case LVS_LIST:
    751     /* get number of fully visible items per column */
    752     infoPtr->nCountPerColumn = max(1, nListHeight / infoPtr->nItemHeight);
    753    
    754     /* get number of fully visible items per row */
    755     infoPtr->nCountPerRow = max(1, nListWidth / infoPtr->nItemWidth);
    756     break;
    757   }
    758682}
    759683
     
    855779/***
    856780 * DESCRIPTION:
     781 * Selects items based on view coorddiantes.
     782 *
     783 * PARAMETER(S):
     784 * [I] HWND : window handle
     785 * [I] RECT : selection rectangle 
     786 *
     787 * RETURN:
     788 * None
     789 */
     790static VOID LISTVIEW_SetSelectionRect(HWND hwnd, RECT rcSelRect)
     791{
     792  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     793  LVITEMA lvItem;
     794  POINT ptItem;
     795  INT i;
     796
     797  lvItem.stateMask = LVIS_SELECTED;
     798
     799  for (i = 0; i < GETITEMCOUNT(infoPtr); i++)
     800  {
     801    LISTVIEW_GetItemPosition(hwnd, i, &ptItem);
     802    if (PtInRect(&rcSelRect, ptItem) != FALSE)
     803    {
     804      lvItem.state = LVIS_SELECTED;
     805    }
     806    else
     807    {
     808      lvItem.state = 0;
     809    }
     810
     811    ListView_SetItemState(hwnd, i, &lvItem);
     812  }
     813}
     814
     815/***
     816 * DESCRIPTION:
    857817 * Sets a single group selection.
    858818 *
     
    867827{
    868828  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    869   INT nFirst = min(infoPtr->nSelectionMark, nItem);
    870   INT nLast = max(infoPtr->nSelectionMark, nItem);
     829  UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    871830  LVITEMA lvItem;
    872   INT i;
    873 
    874   if (nFirst > 0)
    875   {
    876     LISTVIEW_RemoveSelections(hwnd, 0, nFirst - 1);
    877   }
    878 
    879   if (nLast < GETITEMCOUNT(infoPtr))
    880   {
    881     LISTVIEW_RemoveSelections(hwnd, nLast + 1, GETITEMCOUNT(infoPtr));
    882   }
    883 
    884   lvItem.state = LVIS_SELECTED;
    885   lvItem.stateMask = LVIS_SELECTED;
    886 
    887   for (i = nFirst; i <= nLast; i++)
    888   {
    889     ListView_SetItemState(hwnd, i, &lvItem);
     831
     832  if ((uView == LVS_LIST) || (uView == LVS_REPORT))
     833  {
     834    INT i;
     835    INT nFirst = min(infoPtr->nSelectionMark, nItem);
     836    INT nLast = max(infoPtr->nSelectionMark, nItem);
     837    lvItem.stateMask = LVIS_SELECTED;
     838   
     839    for (i = 0; i <= GETITEMCOUNT(infoPtr); i++)
     840    {
     841      if ((i < nFirst) || (i > nLast))
     842      {
     843        lvItem.state = 0;
     844      }
     845      else
     846      {
     847        lvItem.state = LVIS_SELECTED;
     848      }
     849
     850      ListView_SetItemState(hwnd, i, &lvItem);
     851    }
     852  }
     853  else
     854  {
     855    POINT ptItem;
     856    POINT ptSelMark;
     857    RECT rcSel;
     858    LISTVIEW_GetItemPosition(hwnd, nItem, &ptItem);
     859    LISTVIEW_GetItemPosition(hwnd, infoPtr->nSelectionMark, &ptSelMark);
     860    rcSel.left = min(ptSelMark.x, ptItem.x);
     861    rcSel.top = min(ptSelMark.y, ptItem.y);
     862    rcSel.right = max(ptSelMark.x, ptItem.x) + infoPtr->nItemWidth;
     863    rcSel.bottom = max(ptSelMark.y, ptItem.y) + infoPtr->nItemHeight;
     864    LISTVIEW_SetSelectionRect(hwnd, rcSel);
    890865  }
    891866
     
    902877 *
    903878 * RETURN:
     879 *   TRUE : focused item changed
     880 *   FALSE : focused item has NOT changed
     881 */
     882static BOOL LISTVIEW_SetItemFocus(HWND hwnd, INT nItem)
     883{
     884  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     885  BOOL bResult = FALSE;
     886  LVITEMA lvItem;
     887
     888  if (infoPtr->nFocusedItem != nItem)
     889  {
     890    bResult = TRUE;
     891    ZeroMemory(&lvItem, sizeof(LVITEMA));
     892    lvItem.stateMask = LVIS_FOCUSED;
     893    ListView_SetItemState(hwnd, infoPtr->nFocusedItem, &lvItem);
     894
     895    lvItem.state =  LVIS_FOCUSED;
     896    lvItem.stateMask = LVIS_FOCUSED;
     897    ListView_SetItemState(hwnd, nItem, &lvItem);
     898
     899    infoPtr->nFocusedItem = nItem;
     900    ListView_EnsureVisible(hwnd, nItem, FALSE);
     901  }
     902 
     903  return bResult;
     904}
     905
     906/***
     907 * DESCRIPTION:
     908 * Sets a single selection.
     909 *
     910 * PARAMETER(S):
     911 * [I] HWND : window handle
     912 * [I] INT : item index
     913 *
     914 * RETURN:
    904915 * None
    905916 */
    906 static VOID LISTVIEW_SetItemFocus(HWND hwnd, INT nItem)
     917static VOID LISTVIEW_SetSelection(HWND hwnd, INT nItem)
    907918{
    908919  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    909920  LVITEMA lvItem;
    910921
    911   lvItem.state = 0;
    912   lvItem.stateMask = LVIS_FOCUSED;
    913   ListView_SetItemState(hwnd, infoPtr->nFocusedItem, &lvItem);
    914  
    915   lvItem.state =  LVIS_FOCUSED;
    916   lvItem.stateMask = LVIS_FOCUSED;
    917   ListView_SetItemState(hwnd, nItem, &lvItem);
    918 
    919   infoPtr->nFocusedItem = nItem;
    920 
    921   /* if multiple selection is allowed */
    922   ListView_EnsureVisible(hwnd, nItem, FALSE);
    923 }
    924 
    925 /***
    926  * DESCRIPTION:
    927  * Sets a single selection.
    928  *
    929  * PARAMETER(S):
    930  * [I] HWND : window handle
    931  * [I] INT : item index
    932  *
    933  * RETURN:
    934  * None
    935  */
    936 static VOID LISTVIEW_SetSelection(HWND hwnd, INT nItem)
    937 {
    938   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    939   LVITEMA lvItem;
    940 
    941922  if (nItem > 0)
    942923  {
     
    949930  }
    950931
    951   lvItem.state = 0;
     932  ZeroMemory(&lvItem, sizeof(LVITEMA));
    952933  lvItem.stateMask = LVIS_FOCUSED;
    953934  ListView_SetItemState(hwnd, infoPtr->nFocusedItem, &lvItem);
     
    970951 *
    971952 * RETURN:
    972  * None
    973  */
    974 static VOID LISTVIEW_KeySelection(HWND hwnd, INT nItem)
    975 {
     953 *   SUCCESS : TRUE (needs to be repainted)
     954 *   FAILURE : FALSE (nothing has changed)
     955 */
     956static BOOL LISTVIEW_KeySelection(HWND hwnd, INT nItem)
     957{
     958  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     959  LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
    976960  WORD wShift = HIWORD(GetKeyState(VK_SHIFT));
    977961  WORD wCtrl = HIWORD(GetKeyState(VK_CONTROL));
    978 
    979   if (wShift)
    980   {
    981     LISTVIEW_SetGroupSelection(hwnd, nItem);
    982   }
    983   else if (wCtrl)
    984   {
    985     LISTVIEW_SetItemFocus(hwnd, nItem);
    986   }
    987   else
    988   {
    989     LISTVIEW_SetSelection(hwnd, nItem);
    990 
    991     /* if multiple selection is allowed */
    992     ListView_EnsureVisible(hwnd, nItem, FALSE);
    993   }
    994 }
    995 
    996 /***
    997  * DESCRIPTION:
    998  * Determines the selected item.
    999  *
    1000  * PARAMETER(S):
    1001  * [I] HWND : window handle
    1002  * [I] INT : x ccordinate
    1003  * [I] INT : y coordinate
     962  BOOL bResult = FALSE;
     963
     964  if ((nItem >= 0) && (nItem < GETITEMCOUNT(infoPtr)))
     965  {
     966    if (lStyle & LVS_SINGLESEL)
     967    {
     968      bResult = TRUE;
     969      LISTVIEW_SetSelection(hwnd, nItem);
     970      ListView_EnsureVisible(hwnd, nItem, FALSE);
     971    }
     972    else
     973    {
     974      if (wShift)
     975      {
     976        bResult = TRUE;
     977        LISTVIEW_SetGroupSelection(hwnd, nItem);
     978      }
     979      else if (wCtrl)
     980      {
     981        bResult = LISTVIEW_SetItemFocus(hwnd, nItem);
     982      }
     983      else
     984      {
     985        bResult = TRUE;
     986        LISTVIEW_SetSelection(hwnd, nItem);
     987        ListView_EnsureVisible(hwnd, nItem, FALSE);
     988      }
     989    }
     990  }
     991
     992  return bResult;
     993}
     994 
     995/***
     996 * DESCRIPTION:
     997 * Selects an item based on coordinates.
     998 *
     999 * PARAMETER(S):
     1000 * [I] HWND : window handle
     1001 * [I] POINT : mouse click ccordinates
    10041002 *
    10051003 * RETURN:
     
    10071005 *   FAILURE : -1
    10081006 */
    1009 static LRESULT LISTVIEW_MouseSelection(HWND hwnd, INT nPosX, INT nPosY)
     1007static LRESULT LISTVIEW_MouseSelection(HWND hwnd, POINT pt)
    10101008{
    10111009  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     
    10181016    if (LISTVIEW_GetItemRect(hwnd, i, &rcItem) == TRUE)
    10191017    {
    1020       if ((rcItem.left <= nPosX) && (nPosX <= rcItem.right) &&
    1021           (rcItem.top <= nPosY) && (nPosY <= rcItem.bottom))
     1018      if (PtInRect(&rcItem, pt) != FALSE)
    10221019      {
    10231020        return i;
     
    11181115          COMCTL32_Free(lpSubItem->pszText);
    11191116        }
    1120      
     1117       
    11211118        /* free item */
    11221119        COMCTL32_Free(lpSubItem);
     
    11641161      }
    11651162    }
    1166    
     1163
    11671164    if (lpLVItem->mask & LVIF_IMAGE)
    11681165    {
     
    13141311 * Initializes subitem attributes.
    13151312 *
    1316  * NOTE: the documentation specifies that the operation fails if the user
     1313 * NOTE: The documentation specifies that the operation fails if the user
    13171314 * tries to set the indent of a subitem.
    13181315 *
     
    15431540              nmlv.uOldState = lpItem->state & lpLVItem->stateMask;
    15441541            }
    1545 
     1542           
    15461543            nmlv.uChanged = uChanged;
    15471544            nmlv.iItem = lpLVItem->iItem;
     
    16311628static INT LISTVIEW_GetTopIndex(HWND hwnd)
    16321629{
    1633   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *) GetWindowLongA(hwnd, 0);
    16341630  LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     1631  UINT uView = lStyle & LVS_TYPEMASK;
    16351632  INT nItem = 0;
    1636 
    1637   switch (LVS_TYPEMASK & lStyle)
    1638   {
    1639   case LVS_LIST:
     1633  SCROLLINFO scrollInfo;
     1634
     1635  ZeroMemory(&scrollInfo, sizeof(SCROLLINFO));
     1636  scrollInfo.cbSize = sizeof(SCROLLINFO);
     1637  scrollInfo.fMask = SIF_POS;
     1638 
     1639  if (uView == LVS_LIST)
     1640  {
    16401641    if (lStyle & WS_HSCROLL)
    16411642    {
    1642       nItem = GetScrollPos(hwnd, SB_HORZ) * infoPtr->nCountPerColumn;
    1643     }
    1644     break;
    1645 
    1646   case LVS_REPORT:
     1643      if (GetScrollInfo(hwnd, SB_HORZ, &scrollInfo) != FALSE)
     1644      {
     1645        nItem = scrollInfo.nPos * LISTVIEW_GetCountPerColumn(hwnd);
     1646      }
     1647    }
     1648  }
     1649  else if (uView == LVS_REPORT)
     1650  {
    16471651    if (lStyle & WS_VSCROLL)
    16481652    {
    1649       nItem = GetScrollPos(hwnd, SB_VERT);
    1650     }
    1651     break;
    1652   }
    1653 
     1653      if (GetScrollInfo(hwnd, SB_VERT, &scrollInfo) != FALSE)
     1654      {
     1655        nItem = scrollInfo.nPos;
     1656      }
     1657    }
     1658  }
     1659 
    16541660  return nItem;
    1655 }
    1656 
    1657 /***
    1658  * DESCRIPTION:
    1659  * Evaluates if scrollbars are needed & sets the scroll range/position.
    1660  *
    1661  * PARAMETER(S):
    1662  * [I] HWND : window handle
    1663  * [I] LONG : window style
    1664  *
    1665  * RETURN:
    1666  * None
    1667  */
    1668 static VOID LISTVIEW_SetScroll(HWND hwnd, LONG lStyle)
    1669 {
    1670   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    1671   INT nListWidth = infoPtr->rcList.right - infoPtr->rcList.left;
    1672   INT nListHeight = infoPtr->rcList.bottom - infoPtr->rcList.top;
    1673   INT nHScrollHeight = GetSystemMetrics(SM_CYHSCROLL);
    1674   INT nVScrollWidth = GetSystemMetrics(SM_CXVSCROLL);
    1675   INT nHiddenWidth;
    1676   INT nHiddenHeight;
    1677   INT nHiddenItemCount;
    1678   INT nScrollPos;
    1679   INT nMaxRange;
    1680   INT nCountPerPage;
    1681   INT nPixPerScrollPos;
    1682   RECT rcView;
    1683 
    1684 //  TRACE(listview, "(hwnd=%x,lStyle=%lx)\n", hwnd, lStyle);
    1685 
    1686   switch (LVS_TYPEMASK & lStyle)
    1687   {
    1688   case LVS_LIST:
    1689     nCountPerPage = infoPtr->nCountPerRow * infoPtr->nCountPerColumn;
    1690     if (nCountPerPage < GETITEMCOUNT(infoPtr))
    1691     {
    1692       /* display horizontal scrollbar */
    1693       if ((lStyle &  WS_HSCROLL) == 0)
    1694       {
    1695         ShowScrollBar(hwnd, SB_HORZ, TRUE);
    1696       }
    1697 
    1698       /* calculate new scrollbar range */
    1699       nHiddenItemCount = GETITEMCOUNT(infoPtr) - nCountPerPage;
    1700       if ((nHiddenItemCount % infoPtr->nCountPerColumn) == 0)
    1701       {
    1702         nMaxRange = nHiddenItemCount / infoPtr->nCountPerColumn;
    1703       }
    1704      else
    1705       {
    1706         nMaxRange = nHiddenItemCount / infoPtr->nCountPerColumn + 1;
    1707       }
    1708        
    1709       SetScrollRange(hwnd, SB_HORZ, 0, nMaxRange, FALSE);
    1710       nScrollPos = ListView_GetTopIndex(hwnd) / infoPtr->nCountPerColumn;
    1711       SetScrollPos(hwnd, SB_HORZ, nScrollPos, TRUE);
    1712     }
    1713     else
    1714     {
    1715       /* hide scrollbar */
    1716       if ((lStyle & WS_HSCROLL) != 0)
    1717       {
    1718         ShowScrollBar(hwnd, SB_HORZ, FALSE);
    1719       }
    1720     }
    1721     break;
    1722    
    1723   case LVS_REPORT:
    1724 /*
    1725  * This section was commented out because I experienced some problems
    1726  * with the scrolling of the header control. The idea was to add a
    1727  * horizontal scrollbar when the width of the client area was smaller
    1728  * than the width of the header control.
    1729  */
    1730 
    1731 /*     if (infoPtr->nItemWidth > nListWidth) */
    1732 /*     { */
    1733 /*       if ((lStyle &  WS_HSCROLL) == 0) */
    1734 /*       { */
    1735 /*         ShowScrollBar(hwnd, SB_HORZ, TRUE); */
    1736 /*         LISTVIEW_SetSize(hwnd, lStyle, -1, -1); */
    1737 /*         LISTVIEW_SetViewInfo(hwnd, lStyle); */
    1738 /*       } */
    1739      
    1740 /*       nListWidth = infoPtr->rcList.right - infoPtr->rcList.left; */
    1741 /*       nHiddenWidth = infoPtr->nItemWidth - nListWidth; */
    1742 /*       nPixPerScrollPos = max(1, nListWidth / 10); */
    1743      
    1744 /*       if ((nHiddenWidth % nPixPerScrollPos) == 0) */
    1745 /*       { */
    1746 /*         nMaxRange = nHiddenWidth / nPixPerScrollPos;  */
    1747 /*       } */
    1748 /*       else */
    1749 /*       { */
    1750 /*         nMaxRange = nHiddenWidth / nPixPerScrollPos + 1;  */
    1751 /*       } */
    1752 
    1753 /*       SetScrollRange(hwnd, SB_HORZ, 0, nMaxRange, FALSE); */
    1754 /*       SetScrollPos(hwnd, SB_HORZ, 0, TRUE); */
    1755 /*     } */
    1756 /*     else */
    1757 /*     { */
    1758 /*       if ((lStyle &  WS_HSCROLL) != 0) */
    1759 /*       { */
    1760 /*         ShowScrollBar(hwnd, SB_HORZ, FASLE); */
    1761 /*         LISTVIEW_SetSize(hwnd, lStyle, -1, -1);  */
    1762 /*         LISTVIEW_SetViewInfo(hwnd, lStyle);  */
    1763 /*       } */
    1764 /*     } */
    1765  
    1766     if (infoPtr->nCountPerColumn < GETITEMCOUNT(infoPtr))
    1767     {
    1768       if ((lStyle &  WS_VSCROLL) == 0)
    1769       {
    1770         if (nListWidth > nVScrollWidth)
    1771         {
    1772           ShowScrollBar(hwnd, SB_VERT, TRUE);
    1773           nListWidth -= nVScrollWidth;
    1774         }
    1775       }
    1776        
    1777       /* vertical range & position */
    1778       nMaxRange = GETITEMCOUNT(infoPtr) - infoPtr->nCountPerColumn;
    1779       SetScrollRange(hwnd, SB_VERT, 0, nMaxRange, FALSE);
    1780       SetScrollPos(hwnd, SB_VERT, ListView_GetTopIndex(hwnd), TRUE);
    1781     }
    1782     else
    1783     {
    1784       if ((lStyle &  WS_VSCROLL) != 0)
    1785       {
    1786         ShowScrollBar(hwnd, SB_VERT, FALSE);
    1787         nListWidth += nVScrollWidth;
    1788       }
    1789     }
    1790     break;
    1791 
    1792   case LVS_ICON:
    1793   case LVS_SMALLICON:
    1794     if (LISTVIEW_GetViewRect(hwnd, &rcView) != FALSE)
    1795     {
    1796       if (rcView.right - rcView.left > nListWidth)
    1797       {
    1798         if ((lStyle & WS_HSCROLL) == 0)
    1799         {
    1800           if (nListHeight > nHScrollHeight)
    1801           {
    1802             ShowScrollBar(hwnd, SB_HORZ, TRUE);
    1803             nListHeight -= nHScrollHeight;
    1804           }
    1805         }
    1806  
    1807         /* calculate size of hidden items */
    1808         nHiddenWidth = rcView.right - rcView.left - nListWidth;
    1809         nPixPerScrollPos = max(1, nListWidth / 10);
    1810 
    1811         /* vertical range & position */
    1812         if ((nHiddenWidth % nPixPerScrollPos) == 0)
    1813         {
    1814           nMaxRange = nHiddenWidth / nPixPerScrollPos;
    1815         }
    1816         else
    1817         {
    1818           nMaxRange = nHiddenWidth / nPixPerScrollPos + 1;
    1819         }
    1820 
    1821         /* set range and position */
    1822         SetScrollRange(hwnd, SB_HORZ, 0, nMaxRange, FALSE);
    1823         SetScrollPos(hwnd, SB_HORZ, 0, TRUE);
    1824       }
    1825       else
    1826       {
    1827         if ((lStyle &  WS_HSCROLL) != 0)
    1828         {
    1829           ShowScrollBar(hwnd, SB_HORZ, FALSE);
    1830           nListHeight += nHScrollHeight;
    1831         }
    1832       }
    1833 
    1834       if (rcView.bottom - rcView.top > nListHeight)
    1835       {
    1836         if ((lStyle &  WS_VSCROLL) == 0)
    1837         {
    1838           if (nListWidth > nVScrollWidth)
    1839           {
    1840             ShowScrollBar(hwnd, SB_VERT, TRUE);
    1841             nListWidth -= nVScrollWidth;
    1842           }
    1843         }
    1844        
    1845         /* calculate size of hidden items */
    1846         nHiddenHeight = rcView.bottom - rcView.top - nListHeight;
    1847         nPixPerScrollPos = max(1, nListHeight / 10);
    1848        
    1849         /* set vertical range & position */
    1850         if ((nHiddenHeight % nPixPerScrollPos) == 0)
    1851         {
    1852           nMaxRange = nHiddenHeight / nPixPerScrollPos;
    1853         }
    1854         else
    1855         {
    1856           nMaxRange = nHiddenHeight / nPixPerScrollPos + 1;
    1857         }
    1858          
    1859         /* set range and position */
    1860         SetScrollRange(hwnd, SB_VERT, 0, nMaxRange, FALSE);
    1861         SetScrollPos(hwnd, SB_VERT, 0, TRUE);
    1862       }
    1863       else
    1864       {
    1865         if ((lStyle &  WS_VSCROLL) != 0)
    1866         {
    1867           ShowScrollBar(hwnd, SB_VERT, FALSE);
    1868           nListWidth += nVScrollWidth;
    1869         }
    1870       }
    1871     }
    1872     break;
    1873   }
    18741661}
    18751662
     
    18821669 * [I] HDC : device context handle
    18831670 * [I] INT : item index
    1884  * [I] LPARAM : item lparam
    1885  * [I] LISTVIEW_SUBITEM * : item
    1886  * [I] INT : column index (header index)
     1671 * [I] INT : subitem index
    18871672 * [I] RECT * : clipping rectangle
    18881673 *
     
    18901675 * None
    18911676 */
    1892 static VOID LISTVIEW_DrawSubItem(HWND hwnd, HDC hdc, INT nItem, LPARAM lParam,
    1893                                  LISTVIEW_SUBITEM *lpSubItem, INT nColumn,
    1894                                  RECT *lprc)
    1895 {
    1896   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     1677static VOID LISTVIEW_DrawSubItem(HWND hwnd, HDC hdc, INT nItem, INT nSubItem,
     1678                                 RECT rcItem)
     1679{
     1680  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    18971681  CHAR szDispText[DISP_TEXT_SIZE];
    1898   LPSTR pszDispText = NULL;
     1682  LVITEMA lvItem;
     1683
     1684  TRACE("(hwnd=%x, hdc=%x, nItem=%d, nSubItem=%d\n", hwnd, hdc,
     1685        nItem, nSubItem);
     1686
     1687  /* get information needed for drawing the item */
     1688  ZeroMemory(&lvItem, sizeof(LVITEMA));
     1689  lvItem.mask = LVIF_TEXT;
     1690  lvItem.iItem = nItem;
     1691  lvItem.iSubItem = nSubItem;
     1692  lvItem.cchTextMax = DISP_TEXT_SIZE;
     1693  lvItem.pszText = szDispText;
     1694  ListView_GetItemA(hwnd, &lvItem);
    18991695
    19001696  /* set item colors */
     
    19021698  SetTextColor(hdc, infoPtr->clrText);
    19031699 
    1904   pszDispText = szDispText;
    1905   LISTVIEW_GetSubItemDispInfo(hwnd, nItem, lParam, lpSubItem, nColumn, NULL,
    1906                               &pszDispText, DISP_TEXT_SIZE);
    1907 
    1908   /* draw text : using arbitrary offset of 10 pixels */ 
     1700  ExtTextOutA(hdc, rcItem.left, rcItem.top, ETO_OPAQUE | ETO_CLIPPED,
     1701              &rcItem, lvItem.pszText, lstrlenA(lvItem.pszText), NULL);
     1702}
     1703
     1704
     1705/***
     1706 * DESCRIPTION:
     1707 * Draws an item.
     1708 *
     1709 * PARAMETER(S):
     1710 * [I] HWND : window handle
     1711 * [I] HDC : device context handle
     1712 * [I] INT : item index
     1713 * [I] RECT * : clipping rectangle
     1714 *
     1715 * RETURN:
     1716 * None
     1717 */
     1718static VOID LISTVIEW_DrawItem(HWND hwnd, HDC hdc, INT nItem, RECT rcItem)
     1719{
     1720  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     1721  CHAR szDispText[DISP_TEXT_SIZE];
     1722  INT nLabelWidth;
     1723  LVITEMA lvItem;
     1724  INT nMixMode;
     1725  DWORD dwBkColor;
     1726  DWORD dwTextColor;
     1727
     1728  TRACE("(hwnd=%x, hdc=%x, nItem=%d\n", hwnd, hdc, nItem);
     1729
     1730  /* get information needed for drawing the item */
     1731  ZeroMemory(&lvItem, sizeof(LVITEMA));
     1732  lvItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE | LVIF_INDENT;
     1733  lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED | LVIS_STATEIMAGEMASK;
     1734  lvItem.iItem = nItem;
     1735  lvItem.iSubItem = 0;
     1736  lvItem.cchTextMax = DISP_TEXT_SIZE;
     1737  lvItem.pszText = szDispText;
     1738  ListView_GetItemA(hwnd, &lvItem);
     1739
     1740  /* state icons */
     1741  if (infoPtr->himlState != NULL)
     1742  {
     1743     UINT uStateImage = (lvItem.state & LVIS_STATEIMAGEMASK) >> 12;
     1744     if (uStateImage != 0)
     1745     {
     1746       ImageList_Draw(infoPtr->himlState, uStateImage - 1, hdc, rcItem.left,
     1747                      rcItem.top, ILD_NORMAL);
     1748     }
     1749 
     1750     rcItem.left += infoPtr->iconSize.cx;
     1751  }
    19091752 
    1910   ExtTextOutA(hdc, lprc->left, lprc->top, ETO_OPAQUE|ETO_CLIPPED,
    1911               lprc, pszDispText, lstrlenA(pszDispText), NULL);
    1912 }
    1913 
    1914 /***
    1915  * DESCRIPTION:
    1916  * Draws an item.
     1753  /* small icons */
     1754  if (infoPtr->himlSmall != NULL)
     1755  {
     1756    if (lvItem.state & LVIS_SELECTED)
     1757    {
     1758      ImageList_SetBkColor(infoPtr->himlSmall, CLR_NONE);
     1759      ImageList_Draw(infoPtr->himlSmall, lvItem.iImage, hdc, rcItem.left,
     1760                     rcItem.top, ILD_SELECTED);
     1761    }
     1762    else
     1763    {
     1764      ImageList_SetBkColor(infoPtr->himlSmall, CLR_NONE);
     1765      ImageList_Draw(infoPtr->himlSmall, lvItem.iImage, hdc, rcItem.left,
     1766                     rcItem.top, ILD_NORMAL);
     1767    }
     1768   
     1769    rcItem.left += infoPtr->iconSize.cx;
     1770  }
     1771
     1772  if ((lvItem.state & LVIS_SELECTED) && (infoPtr->bFocus != FALSE))
     1773  {
     1774    /* set item colors */
     1775    dwBkColor = SetBkColor(hdc, GetSysColor(COLOR_HIGHLIGHT));
     1776    dwTextColor = SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
     1777    /* set raster mode */
     1778    nMixMode = SetROP2(hdc, R2_XORPEN);
     1779  }
     1780  else if ((GetWindowLongA(hwnd, GWL_STYLE) & LVS_SHOWSELALWAYS) &&
     1781           (lvItem.state & LVIS_SELECTED) && (infoPtr->bFocus == FALSE))
     1782  {
     1783    dwBkColor = SetBkColor(hdc, GetSysColor(COLOR_3DFACE));
     1784    dwTextColor = SetTextColor(hdc, GetSysColor(COLOR_BTNTEXT));
     1785    /* set raster mode */
     1786    nMixMode = SetROP2(hdc, R2_COPYPEN);
     1787  }
     1788  else
     1789  {
     1790    /* set item colors */
     1791    dwBkColor = SetBkColor(hdc, infoPtr->clrTextBk);
     1792    dwTextColor = SetTextColor(hdc, infoPtr->clrText);
     1793    /* set raster mode */
     1794    nMixMode = SetROP2(hdc, R2_COPYPEN);
     1795  }
     1796 
     1797  nLabelWidth = ListView_GetStringWidthA(hwnd, lvItem.pszText);
     1798  if (rcItem.left + nLabelWidth < rcItem.right)
     1799  {
     1800    rcItem.right = rcItem.left + nLabelWidth;
     1801  }
     1802 
     1803  /* draw label */ 
     1804  ExtTextOutA(hdc, rcItem.left, rcItem.top, ETO_OPAQUE | ETO_CLIPPED,
     1805              &rcItem, lvItem.pszText, lstrlenA(lvItem.pszText), NULL);
     1806 
     1807  if ((lvItem.state & LVIS_FOCUSED) && (infoPtr->bFocus == TRUE))
     1808  {
     1809    Rectangle(hdc, rcItem.left, rcItem.top, rcItem.right, rcItem.bottom);
     1810  }
     1811
     1812  if (nMixMode != 0)
     1813  {
     1814    SetROP2(hdc, R2_COPYPEN);
     1815    SetBkColor(hdc, infoPtr->clrTextBk);
     1816    SetTextColor(hdc, infoPtr->clrText);
     1817  }
     1818}
     1819
     1820/***
     1821 * DESCRIPTION:
     1822 * Draws an item when in large icon display mode.
    19171823 *
    19181824 * PARAMETER(S):
     
    19261832 * None
    19271833 */
    1928 static VOID LISTVIEW_DrawItem(HWND hwnd, HDC hdc, LISTVIEW_ITEM *lpItem,
    1929                               INT nItem, RECT rc)
     1834static VOID LISTVIEW_DrawLargeItem(HWND hwnd, HDC hdc, INT nItem, RECT rcItem)
    19301835{
    19311836  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    19321837  CHAR szDispText[DISP_TEXT_SIZE];
    1933   LPSTR pszDispText = NULL;
    1934   BOOL bSelected;
     1838  INT nDrawPosX = rcItem.left;
    19351839  INT nLabelWidth;
    1936   INT nImage;
    1937   UINT uState;
    1938 
    1939 //  TRACE(listview, "(hwnd=%x,hdc=%x,lpItem=%p,nItem=%d,rc.left=%d,rctop=%d,rc.right=%d,rc.bottom=%d)\n", hwnd, hdc, lpItem, nItem, rc.left, rc.top, rc.right, rc.bottom);
    1940 
    1941   pszDispText = szDispText;
    1942   LISTVIEW_GetItemDispInfo(hwnd, nItem, lpItem, &nImage, &uState, &pszDispText,
    1943                            DISP_TEXT_SIZE);
    1944  
    1945  if (uState & LVIS_SELECTED)
    1946   {
    1947     bSelected = TRUE;
    1948 
     1840  TEXTMETRICA tm;
     1841  LVITEMA lvItem;
     1842
     1843  TRACE("(hwnd=%x, hdc=%x, nItem=%d, left=%d, top=%d, right=%d, \
     1844bottom=%d)\n", hwnd, hdc, nItem, rcItem.left, rcItem.top, rcItem.right,
     1845        rcItem.bottom);
     1846
     1847  /* get information needed for drawing the item */
     1848  ZeroMemory(&lvItem, sizeof(LVITEMA));
     1849  lvItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE;
     1850  lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
     1851  lvItem.iItem = nItem;
     1852  lvItem.iSubItem = 0;
     1853  lvItem.cchTextMax = DISP_TEXT_SIZE;
     1854  lvItem.pszText = szDispText;
     1855  ListView_GetItemA(hwnd, &lvItem);
     1856
     1857  if (lvItem.state & LVIS_SELECTED)
     1858  {
    19491859    /* set item colors */
    19501860    SetBkColor(hdc, GetSysColor(COLOR_HIGHLIGHT));
    19511861    SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
    1952    
    19531862    /* set raster mode */
    19541863    SetROP2(hdc, R2_XORPEN);
     
    19561865  else
    19571866  {
    1958     bSelected = FALSE;
    1959    
    19601867    /* set item colors */
    19611868    SetBkColor(hdc, infoPtr->clrTextBk);
    19621869    SetTextColor(hdc, infoPtr->clrText);
    1963    
    19641870    /* set raster mode */
    19651871    SetROP2(hdc, R2_COPYPEN);
    19661872  }
    19671873
    1968   /* state icons */
    1969   if (infoPtr->himlState != NULL)
    1970   {
    1971     /* right shift 12 bits to obtain index in image list */
    1972     if (bSelected != FALSE)
    1973     {
    1974       ImageList_Draw(infoPtr->himlState, uState >> 12, hdc, rc.left,
    1975                      rc.top, ILD_SELECTED);
     1874  if (infoPtr->himlNormal != NULL)
     1875  {
     1876    rcItem.top += ICON_TOP_PADDING;
     1877    nDrawPosX += (infoPtr->iconSpacing.cx - infoPtr->iconSize.cx) / 2;
     1878    if (lvItem.state & LVIS_SELECTED)
     1879    {
     1880      ImageList_Draw(infoPtr->himlNormal, lvItem.iImage, hdc, nDrawPosX,
     1881                     rcItem.top, ILD_SELECTED);
    19761882    }
    19771883    else
    19781884    {
    1979       ImageList_Draw(infoPtr->himlState, uState >> 12, hdc, rc.left,
    1980                      rc.top, ILD_NORMAL);
    1981     }
    1982    
    1983     rc.left += infoPtr->iconSize.cx;
    1984   }
    1985  
    1986   /* small icons */
    1987   if (infoPtr->himlSmall != NULL)
    1988   {
    1989     if (bSelected != FALSE)
    1990     {
    1991       ImageList_Draw(infoPtr->himlSmall, nImage, hdc, rc.left,
    1992                      rc.top, ILD_SELECTED);
    1993     }
    1994     else
    1995     {
    1996       ImageList_Draw(infoPtr->himlSmall, nImage, hdc, rc.left,
    1997                      rc.top, ILD_NORMAL);
    1998     }
    1999    
    2000     rc.left += infoPtr->iconSize.cx;
    2001   }
    2002  
    2003   nLabelWidth = ListView_GetStringWidthA(hwnd, pszDispText);
    2004   if (rc.left + nLabelWidth < rc.right)
    2005   {
    2006     rc.right = rc.left + nLabelWidth;
    2007   }
    2008 
    2009   /* draw label */ 
    2010   ExtTextOutA(hdc, rc.left, rc.top, ETO_OPAQUE|ETO_CLIPPED,
    2011               &rc, pszDispText, lstrlenA(pszDispText), NULL);
    2012  
    2013   if (lpItem->state & LVIS_FOCUSED)
    2014   {
    2015     Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom);
    2016   }
    2017 }
    2018 
    2019 /***
    2020  * DESCRIPTION:
    2021  * Draws an item when in large icon display mode.
    2022  *
    2023  * PARAMETER(S):
    2024  * [I] HWND : window handle
    2025  * [I] HDC : device context handle
    2026  * [I] LISTVIEW_ITEM * : item
    2027  * [I] INT : item index
    2028  * [I] RECT * : clipping rectangle
    2029  *
    2030  * RETURN:
    2031  * None
    2032  */
    2033 static VOID LISTVIEW_DrawLargeItem(HWND hwnd, HDC hdc, LISTVIEW_ITEM *lpItem,
    2034                                    INT nItem, RECT rc)
    2035 {
    2036   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    2037   CHAR szDispText[DISP_TEXT_SIZE];
    2038   LPSTR pszDispText = NULL;
    2039   BOOL bSelected;
    2040   INT nLabelWidth;
    2041   INT nImage;
    2042   UINT uState;
    2043   INT nDrawPosX = 0;
    2044   TEXTMETRICA tm;
    2045 
    2046 //  TRACE(listview, "(hwnd=%x,hdc=%x,lpItem=%p,nItem=%d,rc.left=%d,rctop=%d,rc.right=%d,rc.bottom=%d)\n", hwnd, hdc, lpItem, nItem, rc.left, rc.top, rc.right, rc.bottom);
    2047 
    2048   pszDispText = szDispText;
    2049   LISTVIEW_GetItemDispInfo(hwnd, nItem, lpItem, &nImage, &uState, &pszDispText,
    2050                            DISP_TEXT_SIZE);
    2051   if (uState & LVIS_SELECTED)
    2052   {
    2053     bSelected = TRUE;
    2054 
    2055     /* set item colors */
    2056     SetBkColor(hdc, GetSysColor(COLOR_HIGHLIGHT));
    2057     SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
    2058    
    2059     /* set raster mode */
    2060     SetROP2(hdc, R2_XORPEN);
    2061   }
    2062   else
    2063   {
    2064     bSelected = FALSE;
    2065 
    2066     /* set item colors */
    2067     SetBkColor(hdc, infoPtr->clrTextBk);
    2068     SetTextColor(hdc, infoPtr->clrText);
    2069    
    2070     /* set raster mode */
    2071     SetROP2(hdc, R2_COPYPEN);
    2072   }
    2073 
    2074   if (infoPtr->himlNormal != NULL)
    2075   {
    2076     rc.top += ICON_TOP_PADDING;
    2077     nDrawPosX = rc.left + (infoPtr->iconSpacing.cx - infoPtr->iconSize.cx) / 2;
    2078     if (bSelected != FALSE)
    2079     {
    2080       ImageList_Draw(infoPtr->himlNormal, nImage, hdc, nDrawPosX, rc.top,
    2081                      ILD_SELECTED);
    2082     }
    2083     else
    2084     {
    2085       ImageList_Draw(infoPtr->himlNormal, nImage, hdc, nDrawPosX, rc.top,
    2086                      ILD_NORMAL);
    2087     }
    2088   }
    2089 
    2090   rc.top += infoPtr->iconSize.cy + ICON_BOTTOM_PADDING;
    2091   nLabelWidth = ListView_GetStringWidthA(hwnd, pszDispText);
     1885      ImageList_Draw(infoPtr->himlNormal, lvItem.iImage, hdc, nDrawPosX,
     1886                     rcItem.top, ILD_NORMAL);
     1887    }
     1888  }
     1889
     1890  rcItem.top += infoPtr->iconSize.cy + ICON_BOTTOM_PADDING;
     1891  nLabelWidth = ListView_GetStringWidthA(hwnd, lvItem.pszText);
    20921892  nDrawPosX = infoPtr->iconSpacing.cx - nLabelWidth;
    20931893  if (nDrawPosX > 1)
    20941894  {
    2095     rc.left += nDrawPosX / 2;
    2096     rc.right = rc.left + nLabelWidth;
     1895    rcItem.left += nDrawPosX / 2;
     1896    rcItem.right = rcItem.left + nLabelWidth;
    20971897  }
    20981898  else
    20991899  {
    2100     rc.left += 1;
    2101     rc.right = rc.left + infoPtr->iconSpacing.cx - 1;
     1900    rcItem.left += 1;
     1901    rcItem.right = rcItem.left + infoPtr->iconSpacing.cx - 1;
    21021902  }
    21031903
    21041904  /* draw label */ 
    21051905  GetTextMetricsA(hdc, &tm);
    2106   rc.bottom = rc.top + tm.tmHeight + HEIGHT_PADDING;
    2107   ExtTextOutA(hdc, rc.left, rc.top, ETO_OPAQUE|ETO_CLIPPED,
    2108               &rc, pszDispText, lstrlenA(pszDispText), NULL);
     1906  rcItem.bottom = rcItem.top + tm.tmHeight + HEIGHT_PADDING;
     1907  ExtTextOutA(hdc, rcItem.left, rcItem.top, ETO_OPAQUE | ETO_CLIPPED,
     1908              &rcItem, lvItem.pszText, lstrlenA(lvItem.pszText), NULL);
    21091909       
    2110   if (lpItem->state & LVIS_FOCUSED)
    2111   {
    2112     Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom);
     1910  if (lvItem.state & LVIS_FOCUSED)
     1911  {
     1912    Rectangle(hdc, rcItem.left, rcItem.top, rcItem.right, rcItem.bottom);
    21131913  }
    21141914}
     
    21291929  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd,0);
    21301930  INT nDrawPosY = infoPtr->rcList.top;
    2131   LISTVIEW_ITEM *lpItem;
    2132   LISTVIEW_SUBITEM *lpSubItem = NULL;
    2133   BOOL bNeedSubItem = TRUE;
    21341931  INT nColumnCount;
    2135   HDPA hdpaSubItems;
    21361932  RECT rcItem;
    2137   INT  j, k;
     1933  INT  j;
    21381934  INT nItem;
    21391935  INT nLast;
    21401936
    21411937  nItem = ListView_GetTopIndex(hwnd);
    2142   nLast = nItem + infoPtr->nCountPerColumn;
    2143   while (nItem <= nLast)
    2144   {
    2145     hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, nItem);
    2146     if (hdpaSubItems != NULL)
    2147     {
    2148       lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0);
    2149       if (lpItem != NULL)
    2150       {
    2151         /* the width of the header items will determine the size of the
    2152            listview items */
    2153         Header_GetItemRect(infoPtr->hwndHeader, 0, &rcItem);
    2154         rcItem.left += REPORT_MARGINX;
    2155         rcItem.right = max(rcItem.left, rcItem.right - REPORT_MARGINX);
    2156         rcItem.top = nDrawPosY;
    2157         rcItem.bottom = rcItem.top + infoPtr->nItemHeight;
    2158         LISTVIEW_DrawItem(hwnd, hdc, lpItem, nItem, rcItem);
    2159       }
    2160 
    2161       nColumnCount = Header_GetItemCount(infoPtr->hwndHeader);
    2162       for (k = 1, j = 1; j < nColumnCount; j++)
    2163       {
    2164         Header_GetItemRect(infoPtr->hwndHeader, j, &rcItem);
    2165         rcItem.left += REPORT_MARGINX;
    2166         rcItem.right = max(rcItem.left, rcItem.right - REPORT_MARGINX);
    2167         rcItem.top = nDrawPosY;
    2168         rcItem.bottom = rcItem.top + infoPtr->nItemHeight;
    2169 
    2170         if (k < hdpaSubItems->nItemCount)
    2171         {
    2172           if (bNeedSubItem != FALSE)
     1938
     1939  /* add 1 for displaying a partial item at the bottom */
     1940  nLast = nItem + LISTVIEW_GetCountPerColumn(hwnd) + 1;
     1941  nLast = min(nLast, GETITEMCOUNT(infoPtr));
     1942  for (; nItem < nLast; nItem++)
     1943  {
     1944    nColumnCount = Header_GetItemCount(infoPtr->hwndHeader);
     1945    for (j = 0; j < nColumnCount; j++)
     1946    {
     1947      Header_GetItemRect(infoPtr->hwndHeader, j, &rcItem);
     1948      rcItem.left += REPORT_MARGINX;
     1949      rcItem.right = max(rcItem.left, rcItem.right - REPORT_MARGINX);
     1950      rcItem.top = nDrawPosY;
     1951      rcItem.bottom = rcItem.top + infoPtr->nItemHeight;
     1952      if (j == 0)
     1953      {
     1954        LISTVIEW_DrawItem(hwnd, hdc, nItem, rcItem);
     1955      }
     1956      else
     1957      {
     1958        LISTVIEW_DrawSubItem(hwnd, hdc, nItem, j, rcItem);
     1959      }
     1960    }
     1961   
     1962    nDrawPosY += infoPtr->nItemHeight;
     1963  }
     1964}
     1965
     1966/***
     1967 * DESCRIPTION:
     1968 * Retrieves the number of items that can fit vertically in the client area.
     1969 *
     1970 * PARAMETER(S):
     1971 * [I] HWND : window handle
     1972 *
     1973 * RETURN:
     1974 * Number of items per row.
     1975 */
     1976static INT LISTVIEW_GetCountPerRow(HWND hwnd)
     1977{
     1978  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd,0);
     1979  UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
     1980  INT nListWidth = infoPtr->rcList.right - infoPtr->rcList.left;
     1981  INT nCountPerRow = 1;
     1982
     1983  if (nListWidth > 0)
     1984  {
     1985    if (uView == LVS_REPORT)
     1986    {
     1987      nCountPerRow = 1;
     1988    }
     1989    else
     1990    {
     1991      nCountPerRow =  nListWidth / infoPtr->nItemWidth;
     1992      if (nCountPerRow == 0)
     1993      {
     1994        nCountPerRow = 1;
     1995      }
     1996    }
     1997  }
     1998
     1999  return nCountPerRow;
     2000}
     2001
     2002/***
     2003 * DESCRIPTION:
     2004 * Retrieves the number of items that can fit horizontally in the client
     2005 * area.
     2006 *
     2007 * PARAMETER(S):
     2008 * [I] HWND : window handle
     2009 *
     2010 * RETURN:
     2011 * Number of items per column.
     2012 */
     2013static INT LISTVIEW_GetCountPerColumn(HWND hwnd)
     2014{
     2015  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd,0);
     2016  INT nListHeight = infoPtr->rcList.bottom - infoPtr->rcList.top;
     2017  INT nCountPerColumn = 1;
     2018
     2019  if (nListHeight > 0)
     2020  {
     2021    nCountPerColumn =  nListHeight / infoPtr->nItemHeight;
     2022    if (nCountPerColumn == 0)
     2023    {
     2024      nCountPerColumn = 1;
     2025    }
     2026  }
     2027
     2028  return nCountPerColumn;
     2029}
     2030
     2031/***
     2032 * DESCRIPTION:
     2033 * Retrieves the number of columns needed to display all the items when in
     2034 * list display mode.
     2035 *
     2036 * PARAMETER(S):
     2037 * [I] HWND : window handle
     2038 *
     2039 * RETURN:
     2040 * Number of columns.
     2041 */
     2042static INT LISTVIEW_GetColumnCount(hwnd)
     2043{
     2044  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     2045  LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     2046  INT nColumnCount = 0;
     2047
     2048  if ((lStyle & LVS_TYPEMASK) == LVS_LIST)
     2049  {
     2050    if (infoPtr->rcList.right % infoPtr->nItemWidth == 0)
     2051    {
     2052      nColumnCount = infoPtr->rcList.right / infoPtr->nItemWidth;
     2053    }
     2054    else
     2055    {
     2056      nColumnCount = infoPtr->rcList.right / infoPtr->nItemWidth + 1;
     2057    }
     2058  }
     2059
     2060  return nColumnCount;
     2061
     2062 
     2063
     2064/***
     2065 * DESCRIPTION:
     2066 * Draws listview items when in list display mode.
     2067 *
     2068 * PARAMETER(S):
     2069 * [I] HWND : window handle
     2070 * [I] HDC : device context handle
     2071 *
     2072 * RETURN:
     2073 * None
     2074 */
     2075static VOID LISTVIEW_RefreshList(HWND hwnd, HDC hdc)
     2076{
     2077  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     2078  RECT rcItem;
     2079  INT i, j;
     2080  INT nItem;
     2081  INT nColumnCount;
     2082  INT nCountPerColumn;
     2083 
     2084  /* get number of fully visible columns */
     2085  nColumnCount = LISTVIEW_GetColumnCount(hwnd);
     2086  nCountPerColumn = LISTVIEW_GetCountPerColumn(hwnd);
     2087  nItem = ListView_GetTopIndex(hwnd);
     2088
     2089  for (i = 0; i < nColumnCount; i++)
     2090  {
     2091    for (j = 0; j < nCountPerColumn; j++, nItem++)
     2092    {
     2093      if (nItem >= GETITEMCOUNT(infoPtr))
     2094        return;
     2095
     2096      rcItem.top = j * infoPtr->nItemHeight;
     2097      rcItem.left = i * infoPtr->nItemWidth;
     2098      rcItem.bottom = rcItem.top + infoPtr->nItemHeight;
     2099      rcItem.right = rcItem.left + infoPtr->nItemWidth;
     2100      LISTVIEW_DrawItem(hwnd, hdc, nItem, rcItem);
     2101    }
     2102  }
     2103}
     2104
     2105/***
     2106 * DESCRIPTION:
     2107 * Draws listview items when in icon or small icon display mode.
     2108 *
     2109 * PARAMETER(S):
     2110 * [I] HWND : window handle
     2111 * [I] HDC : device context handle
     2112 *
     2113 * RETURN:
     2114 * None
     2115 */
     2116static VOID LISTVIEW_RefreshIcon(HWND hwnd, HDC hdc, BOOL bSmall)
     2117{
     2118  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     2119  POINT ptPosition;
     2120  POINT ptOrigin;
     2121  RECT rcItem;
     2122  INT i;
     2123
     2124  LISTVIEW_GetOrigin(hwnd, &ptOrigin);
     2125  for (i = 0; i < GETITEMCOUNT(infoPtr); i++)
     2126  {
     2127    LISTVIEW_GetItemPosition(hwnd, i, &ptPosition);
     2128    ptPosition.x += ptOrigin.x;
     2129    ptPosition.y += ptOrigin.y;
     2130     
     2131    if (ptPosition.y + infoPtr->nItemHeight > infoPtr->rcList.top)
     2132    {
     2133      if (ptPosition.x + infoPtr->nItemWidth > infoPtr->rcList.left)
     2134      {
     2135        if (ptPosition.y < infoPtr->rcList.bottom)
     2136        {
     2137          if (ptPosition.x < infoPtr->rcList.right)
    21732138          {
    2174             lpSubItem = (LISTVIEW_SUBITEM *)DPA_GetPtr(hdpaSubItems, k);
    2175             k++;
    2176           }
    2177 
    2178           if (lpSubItem != NULL)
    2179           {
    2180             if (lpSubItem->iSubItem == j)
     2139            rcItem.top = ptPosition.y;
     2140            rcItem.left = ptPosition.x;
     2141            rcItem.bottom = rcItem.top + infoPtr->nItemHeight;
     2142            rcItem.right = rcItem.left + infoPtr->nItemWidth;
     2143            if (bSmall == FALSE)
    21812144            {
    2182               LISTVIEW_DrawSubItem(hwnd, hdc, nItem, lpItem->lParam, lpSubItem,
    2183                                    j, &rcItem);
    2184               bNeedSubItem = TRUE;
     2145              LISTVIEW_DrawLargeItem(hwnd, hdc, i, rcItem);
    21852146            }
    21862147            else
    21872148            {
    2188               LISTVIEW_DrawSubItem(hwnd, hdc, nItem, lpItem->lParam, NULL, j,
    2189                                    &rcItem);
    2190               bNeedSubItem = FALSE;
     2149              LISTVIEW_DrawItem(hwnd, hdc, i, rcItem);
    21912150            }
    21922151          }
    2193           else
    2194           {
    2195             LISTVIEW_DrawSubItem(hwnd, hdc, nItem, lpItem->lParam, NULL, j,
    2196                                  &rcItem);
    2197             bNeedSubItem = TRUE;
    2198           }
    2199         }
    2200         else
    2201         {
    2202           LISTVIEW_DrawSubItem(hwnd, hdc, nItem, lpItem->lParam, NULL, j,
    2203                                &rcItem);
    2204         }
    2205       }
    2206     }
    2207 
    2208     nDrawPosY += infoPtr->nItemHeight;
    2209     nItem++;
    2210   }
    2211 }
    2212 
    2213 /***
    2214  * DESCRIPTION:
    2215  * Draws listview items when in list display mode.
     2152        }
     2153      }
     2154    }
     2155  }
     2156}
     2157
     2158/***
     2159 * DESCRIPTION:
     2160 * Draws listview items.
    22162161 *
    22172162 * PARAMETER(S):
     
    22202165 *
    22212166 * RETURN:
    2222  * None
    2223  */
    2224 static VOID LISTVIEW_RefreshList(HWND hwnd, HDC hdc)
    2225 {
    2226   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    2227   LISTVIEW_ITEM *lpItem;
    2228   HDPA hdpaSubItems;
    2229   RECT rc;
    2230   INT i, j;
    2231   INT nColumnCount;
    2232   INT nItem = ListView_GetTopIndex(hwnd);
    2233 
    2234   if (infoPtr->rcList.right > 0)
    2235   {
    2236     /* get number of display columns */
    2237     if (infoPtr->rcList.right % infoPtr->nItemWidth == 0)
    2238     {
    2239       nColumnCount = infoPtr->rcList.right / infoPtr->nItemWidth;
    2240     }
    2241     else
    2242     {
    2243       nColumnCount = infoPtr->rcList.right / infoPtr->nItemWidth + 1;
    2244     }
    2245 
    2246     for (i = 0; i < nColumnCount; i++)
    2247     {
    2248       j = 0;
    2249       while ((nItem < GETITEMCOUNT(infoPtr)) &&
    2250              (j<infoPtr->nCountPerColumn))
    2251       {
    2252         hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, nItem);
    2253         if (hdpaSubItems != NULL)
    2254         {
    2255           lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0);
    2256           if (lpItem != NULL)
    2257           {
    2258             rc.top = j * infoPtr->nItemHeight;
    2259             rc.left = i * infoPtr->nItemWidth;
    2260             rc.bottom = rc.top + infoPtr->nItemHeight;
    2261             rc.right = rc.left + infoPtr->nItemWidth;
    2262             LISTVIEW_DrawItem(hwnd, hdc,  lpItem, nItem, rc);
    2263           }
    2264         }
    2265  
    2266         nItem++;
    2267         j++;
    2268       }
    2269     }
    2270   }
    2271 }
    2272 
    2273 /***
    2274  * DESCRIPTION:
    2275  * Draws listview items when in icon or small icon display mode.
    2276  *
    2277  * PARAMETER(S):
    2278  * [I] HWND : window handle
    2279  * [I] HDC : device context handle
    2280  *
    2281  * RETURN:
    2282  * None
    2283  */
    2284 static VOID LISTVIEW_RefreshIcon(HWND hwnd, HDC hdc, BOOL bSmall)
    2285 {
    2286   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    2287   LISTVIEW_ITEM *lpItem;
    2288   HDPA hdpaSubItems;
    2289   POINT ptPosition;
    2290   POINT ptOrigin;
    2291   RECT rc;
    2292   INT i;
    2293 
    2294   LISTVIEW_GetOrigin(hwnd, &ptOrigin);
    2295 
    2296   for (i = 0; i < GETITEMCOUNT(infoPtr); i++)
    2297   {
    2298     LISTVIEW_GetItemPosition(hwnd, i, &ptPosition);
    2299     ptPosition.x += ptOrigin.x;
    2300     ptPosition.y += ptOrigin.y;
    2301 
    2302     if (ptPosition.y + infoPtr->nItemHeight > infoPtr->rcList.top)
    2303     {
    2304       if (ptPosition.x + infoPtr->nItemWidth > infoPtr->rcList.left)
    2305       {
    2306         if (ptPosition.y < infoPtr->rcList.bottom)
    2307         {
    2308           if (ptPosition.x < infoPtr->rcList.right)
    2309           {
    2310             hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, i);
    2311             if (hdpaSubItems != NULL)
    2312             {
    2313               lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0);
    2314               if (lpItem != NULL)
    2315               {
    2316                 rc.top = ptPosition.y;
    2317                 rc.left = ptPosition.x;
    2318                 rc.bottom = rc.top + infoPtr->nItemHeight;
    2319                 rc.right = rc.left + infoPtr->nItemWidth;
    2320                 if (bSmall == FALSE)
    2321                 {
    2322                   LISTVIEW_DrawLargeItem(hwnd, hdc, lpItem, i, rc);
    2323                 }
    2324                 else
    2325                 {
    2326                   LISTVIEW_DrawItem(hwnd, hdc, lpItem, i, rc);
    2327                 }
    2328               }
    2329             }
    2330           }
    2331         }
    2332       }
    2333     }
    2334   }
    2335 }
    2336 
    2337 /***
    2338  * DESCRIPTION:
    2339  * Draws listview items.
    2340  *
    2341  * PARAMETER(S):
    2342  * [I] HWND : window handle
    2343  * [I] HDC : device context handle
    2344  *
    2345  * RETURN:
    23462167 * NoneX
    23472168 */
     
    23492170{
    23502171  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    2351   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     2172  UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    23522173  HFONT hOldFont;
    23532174  HPEN hPen, hOldPen;
     
    23632184  SelectObject(hdc, GetStockObject(NULL_BRUSH));
    23642185
    2365   switch (LVS_TYPEMASK & lStyle)
    2366   {
    2367   case LVS_LIST:
     2186  if (uView == LVS_LIST)
     2187  {
    23682188    LISTVIEW_RefreshList(hwnd, hdc);
    2369     break;
    2370   case LVS_REPORT:
     2189  }
     2190  else if (uView == LVS_REPORT)
     2191  {
    23712192    LISTVIEW_RefreshReport(hwnd, hdc);
    2372     break;
    2373   case LVS_SMALLICON:
     2193  }
     2194  else if (uView == LVS_SMALLICON)
     2195  {
    23742196    LISTVIEW_RefreshIcon(hwnd, hdc, TRUE);
    2375     break;
    2376   case LVS_ICON:
     2197  }
     2198  else if (uView == LVS_ICON)
     2199  {
    23772200    LISTVIEW_RefreshIcon(hwnd, hdc, FALSE);
    23782201  }
     
    24042227{
    24052228  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    2406   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     2229  UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    24072230  INT nItemCountPerColumn = 1;
    24082231  INT nColumnCount = 0;
     
    24102233
    24112234  if (nItemCount == -1)
     2235  {
    24122236    nItemCount = GETITEMCOUNT(infoPtr);
    2413 
    2414   if (lStyle & LVS_LIST)
     2237  }
     2238
     2239  if (uView == LVS_LIST)
    24152240  {
    24162241    if (wHeight == 0xFFFF)
    24172242    {
    24182243      /* use current height */
    2419       wHeight = infoPtr->rcList.bottom;
     2244      wHeight = infoPtr->rcList.bottom - infoPtr->rcList.top;
    24202245    }
    24212246
     
    24312256        nItemCountPerColumn = wHeight / infoPtr->nItemHeight;
    24322257        if (nItemCountPerColumn == 0)
     2258        {
    24332259          nItemCountPerColumn = 1;
    2434 
     2260        }
     2261       
    24352262        if (nItemCount % nItemCountPerColumn != 0)
     2263        {
    24362264          nColumnCount = nItemCount / nItemCountPerColumn;
     2265        }
    24372266        else
     2267        {
    24382268          nColumnCount = nItemCount / nItemCountPerColumn + 1;
     2269        }
    24392270      }
    24402271    }
     
    24462277    dwViewRect = MAKELONG(wWidth, wHeight);
    24472278  }
    2448   else if (lStyle & LVS_REPORT)
     2279  else if (uView == LVS_REPORT)
    24492280  {
    24502281    /* TO DO */
    2451     }
    2452   else if (lStyle & LVS_SMALLICON)
     2282  }
     2283  else if (uView == LVS_SMALLICON)
    24532284  {
    24542285    /* TO DO */
    24552286  }
    2456   else if (lStyle & LVS_ICON)
     2287  else if (uView == LVS_ICON)
    24572288  {
    24582289    /* TO DO */
     
    24762307static LRESULT LISTVIEW_Arrange(HWND hwnd, INT nAlignCode)
    24772308{
    2478   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     2309  UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    24792310  BOOL bResult = FALSE;
    24802311
    2481   if (((LVS_TYPEMASK & lStyle) == LVS_ICON) ||
    2482       ((LVS_TYPEMASK & lStyle) == LVS_SMALLICON))
     2312  if ((uView == LVS_ICON) || (uView == LVS_SMALLICON))
    24832313  {
    24842314    switch (nAlignCode)
     
    25202350  LONG lCtrlId = GetWindowLongA(hwnd, GWL_ID);
    25212351  LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     2352  UINT uView = lStyle & LVS_TYPEMASK;
    25222353  LISTVIEW_ITEM *lpItem;
    25232354  LISTVIEW_SUBITEM *lpSubItem;
     
    25292360  HDPA hdpaSubItems;
    25302361
    2531 //  TRACE(listview, "(hwnd=%x,)\n", hwnd);
     2362  TRACE("(hwnd=%x,)\n", hwnd);
    25322363
    25332364  if (GETITEMCOUNT(infoPtr) > 0)
     
    25992430   
    26002431    /* align items (set position of each item) */
    2601     switch (lStyle & LVS_TYPEMASK)
    2602     {
    2603     case LVS_ICON:
    2604     case LVS_SMALLICON:
     2432    if ((uView == LVS_ICON) || (uView == LVS_SMALLICON))
     2433    {
    26052434      if (lStyle & LVS_ALIGNLEFT)
    26062435      {
     
    26112440        LISTVIEW_AlignTop(hwnd);
    26122441      }
    2613       break;
    26142442    }
    26152443   
    2616     LISTVIEW_SetScroll(hwnd, lStyle);
     2444    LISTVIEW_UpdateScroll(hwnd);
    26172445
    26182446    /* invalidate client area (optimization needed) */
     
    26382466{
    26392467  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    2640   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     2468  UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    26412469  BOOL bResult = FALSE;
    26422470 
     
    26462474
    26472475    /* reset scroll parameters */
    2648     if ((lStyle & LVS_TYPEMASK) == LVS_REPORT)
    2649     {
    2650       LISTVIEW_SetViewInfo(hwnd, lStyle);
    2651       LISTVIEW_SetScroll(hwnd, lStyle);
    2652     }
    2653 
    2654     /* refresh client area */
    2655     InvalidateRect(hwnd, NULL, FALSE);
     2476    if (uView == LVS_REPORT)
     2477    {
     2478      /* update scrollbar(s) */
     2479      LISTVIEW_UpdateScroll(hwnd);
     2480
     2481      /* refresh client area */
     2482      InvalidateRect(hwnd, NULL, FALSE);
     2483    }
    26562484  }
    26572485
     
    26752503  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    26762504  LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     2505  UINT uView = lStyle & LVS_TYPEMASK;
    26772506  LONG lCtrlId = GetWindowLongA(hwnd, GWL_ID);
    26782507  NMLISTVIEW nmlv;
     
    26832512  INT i;
    26842513
    2685 //  TRACE(listview, "(hwnd=%x,nItem=%d)\n", hwnd, nItem);
     2514  TRACE("(hwnd=%x,nItem=%d)\n", hwnd, nItem);
    26862515
    26872516  if ((nItem >= 0) && (nItem < GETITEMCOUNT(infoPtr)))
     
    27372566
    27382567    /* align items (set position of each item) */
    2739     switch(lStyle & LVS_TYPEMASK)
    2740     {
    2741     case LVS_ICON:
    2742     case LVS_SMALLICON:
     2568    if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
     2569    {
    27432570      if (lStyle & LVS_ALIGNLEFT)
    27442571      {
     
    27492576        LISTVIEW_AlignTop(hwnd);
    27502577      }
    2751       break;
    2752     }
    2753 
    2754     LISTVIEW_SetScroll(hwnd, lStyle);
     2578    }
     2579
     2580    LISTVIEW_UpdateScroll(hwnd);
    27552581
    27562582    /* refresh client area */
     
    27792605{
    27802606  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    2781   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     2607  UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    27822608  INT nListHeight = infoPtr->rcList.bottom - infoPtr->rcList.top;
    27832609  INT nListWidth = infoPtr->rcList.right - infoPtr->rcList.left;
    2784   INT nHScrollPos = 0;
    2785   INT nVScrollPos = 0;
    27862610  INT nScrollPosHeight = 0;
    27872611  INT nScrollPosWidth = 0;
     2612  SCROLLINFO scrollInfo;
    27882613  RECT rcItem;
    2789   BOOL bResult = FALSE;
     2614
     2615  ZeroMemory(&scrollInfo, sizeof(SCROLLINFO));
     2616  scrollInfo.cbSize = sizeof(SCROLLINFO);
     2617  scrollInfo.fMask = SIF_POS;
    27902618
    27912619  /* ALWAYS bPartial == FALSE, FOR NOW! */
     
    27962624    if (rcItem.left < infoPtr->rcList.left)
    27972625    {
    2798       /* scroll left */
    2799       switch (LVS_TYPEMASK & lStyle)
    2800       {
    2801       case LVS_LIST:
    2802         rcItem.left += infoPtr->rcList.left;
    2803         nScrollPosWidth = infoPtr->nItemWidth;
    2804         break;
    2805 
    2806       case LVS_SMALLICON:
    2807       case LVS_ICON:
    2808         nScrollPosWidth = max(1, nListWidth / 10);
    2809         rcItem.left += infoPtr->rcList.left;
    2810         break;
    2811       }
    2812 
    2813       if (rcItem.left % nScrollPosWidth == 0)
    2814       {
    2815         nHScrollPos = rcItem.left / nScrollPosWidth;
    2816       }
    2817       else
    2818       {
    2819         nHScrollPos = rcItem.left / nScrollPosWidth - 1;
     2626      if (GetScrollInfo(hwnd, SB_HORZ, &scrollInfo) != FALSE)
     2627      {
     2628        /* scroll left */
     2629        if (uView == LVS_LIST)
     2630        {
     2631          nScrollPosWidth = infoPtr->nItemWidth;
     2632          rcItem.left += infoPtr->rcList.left;
     2633        }
     2634        else if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
     2635        {
     2636          nScrollPosWidth = max(1, nListWidth / 10);
     2637          rcItem.left += infoPtr->rcList.left;
     2638        }
     2639       
     2640        if (rcItem.left % nScrollPosWidth == 0)
     2641        {
     2642          scrollInfo.nPos += rcItem.left / nScrollPosWidth;
     2643        }
     2644        else
     2645        {
     2646          scrollInfo.nPos += rcItem.left / nScrollPosWidth - 1;
     2647        }
     2648       
     2649        SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE);
    28202650      }
    28212651    }
    28222652    else if (rcItem.right > infoPtr->rcList.right)
    28232653    {
    2824       /* scroll right */
    2825       switch (LVS_TYPEMASK & lStyle)
    2826       {
    2827       case LVS_LIST:
    2828         rcItem.right -= infoPtr->rcList.right;
    2829         nScrollPosWidth = infoPtr->nItemWidth;
    2830         break;
    2831 
    2832       case LVS_SMALLICON:
    2833       case LVS_ICON:
    2834         nScrollPosWidth = max(1, nListWidth / 10);
    2835         rcItem.right -= infoPtr->rcList.right;
    2836         break;
    2837       }
    2838 
    2839       if (rcItem.right % nScrollPosWidth == 0)
    2840       {
    2841         nHScrollPos = rcItem.right / nScrollPosWidth;
    2842       }
    2843       else
    2844       {
    2845         nHScrollPos = rcItem.right / nScrollPosWidth + 1;
     2654      if (GetScrollInfo(hwnd, SB_HORZ, &scrollInfo) != FALSE)
     2655      {
     2656        /* scroll right */
     2657        if (uView == LVS_LIST)
     2658        {
     2659          rcItem.right -= infoPtr->rcList.right;
     2660          nScrollPosWidth = infoPtr->nItemWidth;
     2661        }
     2662        else if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
     2663        {
     2664          rcItem.right -= infoPtr->rcList.right;
     2665          nScrollPosWidth = max(1, nListWidth / 10);
     2666        }
     2667
     2668        if (rcItem.right % nScrollPosWidth == 0)
     2669        {
     2670          scrollInfo.nPos += rcItem.right / nScrollPosWidth;
     2671        }
     2672        else
     2673        {
     2674          scrollInfo.nPos += rcItem.right / nScrollPosWidth + 1;
     2675        }
     2676
     2677        SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE);
    28462678      }
    28472679    }
     
    28502682    {
    28512683      /* scroll up */
    2852       switch (LVS_TYPEMASK & lStyle)
    2853       {
    2854       case LVS_REPORT:
    2855         rcItem.top -= infoPtr->rcList.top;
    2856         nScrollPosHeight = infoPtr->nItemHeight;
    2857         break;
    2858 
    2859       case LVS_SMALLICON:
    2860       case LVS_ICON:
    2861         nScrollPosHeight = max(1, nListHeight / 10);
    2862         rcItem.top += infoPtr->rcList.top;
    2863         break;
    2864       }
    2865 
    2866       if (rcItem.top % nScrollPosHeight == 0)
    2867       {
    2868         nVScrollPos = rcItem.top / nScrollPosHeight;
     2684      if (GetScrollInfo(hwnd, SB_VERT, &scrollInfo) != FALSE)
     2685      {
     2686        if (uView == LVS_REPORT)
     2687        {
     2688          rcItem.top -= infoPtr->rcList.top;
     2689          nScrollPosHeight = infoPtr->nItemHeight;
     2690        }
     2691        else if ((uView == LVS_ICON) || (uView == LVS_SMALLICON))
     2692        {
     2693          nScrollPosHeight = max(1, nListHeight / 10);
     2694          rcItem.top += infoPtr->rcList.top;
     2695        }
     2696
     2697        if (rcItem.top % nScrollPosHeight == 0)
     2698        {
     2699          scrollInfo.nPos += rcItem.top / nScrollPosHeight;
     2700        }
     2701        else
     2702        {
     2703          scrollInfo.nPos += rcItem.top / nScrollPosHeight - 1;
     2704        }
     2705       
     2706        SetScrollInfo(hwnd, SB_VERT, &scrollInfo, TRUE);
     2707      }
     2708    }
     2709    else if (rcItem.bottom > infoPtr->rcList.bottom)
     2710    {
     2711      /* scroll down */
     2712      if (GetScrollInfo(hwnd, SB_VERT, &scrollInfo) != FALSE)
     2713      {
     2714        if (uView == LVS_REPORT)
     2715        {
     2716          rcItem.bottom -= infoPtr->rcList.bottom;
     2717          nScrollPosHeight = infoPtr->nItemHeight;
     2718        }
     2719        else if ((uView == LVS_ICON) || (uView == LVS_SMALLICON))
     2720        {
     2721          nScrollPosHeight = max(1, nListHeight / 10);
     2722          rcItem.bottom -= infoPtr->rcList.bottom;
     2723        }
     2724
     2725        if (rcItem.bottom % nScrollPosHeight == 0)
     2726        {
     2727          scrollInfo.nPos += rcItem.bottom / nScrollPosHeight;
     2728        }
     2729        else
     2730        {
     2731          scrollInfo.nPos += rcItem.bottom / nScrollPosHeight + 1;
     2732        }
     2733       
     2734        SetScrollInfo(hwnd, SB_VERT, &scrollInfo, TRUE);
     2735      }
     2736    }
     2737  }
     2738 
     2739  return TRUE;
     2740}
     2741
     2742/***
     2743 * DESCRIPTION:
     2744 * Retrieves the nearest item, given a position and a direction.
     2745 *
     2746 * PARAMETER(S):
     2747 * [I] HWND : window handle
     2748 * [I] POINT : start position
     2749 * [I] UINT : direction
     2750 *
     2751 * RETURN:
     2752 * Item index if successdful, -1 otherwise.
     2753 */
     2754static INT LISTVIEW_GetNearestItem(HWND hwnd, POINT pt, UINT vkDirection)
     2755{
     2756  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     2757  LVHITTESTINFO lvHitTestInfo;
     2758  INT nItem = -1;
     2759  RECT rcView;
     2760
     2761  if (LISTVIEW_GetViewRect(hwnd, &rcView) != FALSE)
     2762  {
     2763    ZeroMemory(&lvHitTestInfo, sizeof(LVHITTESTINFO));
     2764    LISTVIEW_GetOrigin(hwnd, &lvHitTestInfo.pt);
     2765    lvHitTestInfo.pt.x += pt.x;
     2766    lvHitTestInfo.pt.y += pt.y;
     2767   
     2768    do
     2769    {
     2770      if (vkDirection == VK_DOWN)
     2771      {
     2772        lvHitTestInfo.pt.y += infoPtr->nItemHeight;
     2773      }     
     2774      else if (vkDirection == VK_UP)
     2775      {
     2776        lvHitTestInfo.pt.y -= infoPtr->nItemHeight;
     2777      }
     2778      else if (vkDirection == VK_LEFT)
     2779      {
     2780        lvHitTestInfo.pt.x -= infoPtr->nItemWidth;
     2781      }
     2782      else if (vkDirection == VK_RIGHT)
     2783      {
     2784        lvHitTestInfo.pt.x += infoPtr->nItemWidth;
     2785      }
     2786
     2787      if (PtInRect(&rcView, lvHitTestInfo.pt) == FALSE)
     2788      {
     2789        return -1;
    28692790      }
    28702791      else
    28712792      {
    2872         nVScrollPos = rcItem.top / nScrollPosHeight - 1;
    2873       }
    2874     }
    2875     else if (rcItem.bottom > infoPtr->rcList.bottom)
    2876     {
    2877       switch (LVS_TYPEMASK & lStyle)
    2878       {
    2879       case LVS_REPORT:
    2880         rcItem.bottom -= infoPtr->rcList.bottom;
    2881         nScrollPosHeight = infoPtr->nItemHeight;
    2882         break;
    2883 
    2884       case LVS_SMALLICON:
    2885       case LVS_ICON:
    2886         nScrollPosHeight = max(1, nListHeight / 10);
    2887         rcItem.bottom -= infoPtr->rcList.bottom;
    2888         break;
    2889       }
    2890 
    2891       if (rcItem.bottom % nScrollPosHeight == 0)
    2892       {
    2893         nVScrollPos = rcItem.bottom / nScrollPosHeight;
    2894       }
    2895       else
    2896       {
    2897         nVScrollPos = rcItem.bottom / nScrollPosHeight + 1;
    2898       }
    2899     }
    2900 
    2901     bResult = LISTVIEW_ScrollView(hwnd, nHScrollPos, nVScrollPos);
    2902   }
    2903  
    2904   return bResult;
    2905 }
     2793        nItem = LISTVIEW_HitTestItem(hwnd, &lvHitTestInfo);
     2794      }
     2795
     2796    }
     2797    while (nItem == -1);
     2798  }
     2799
     2800  return nItem;
     2801
    29062802
    29072803/***
     
    29212817                                 LPLVFINDINFO lpFindInfo)
    29222818{
    2923 //  FIXME (listview, "empty stub!\n");
    2924 
    2925   return -1;
     2819  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     2820  POINT ptItem;
     2821  CHAR szDispText[DISP_TEXT_SIZE];
     2822  LVITEMA lvItem;
     2823  BOOL bWrap = FALSE;
     2824  INT nItem = nStart;
     2825  INT nLast = GETITEMCOUNT(infoPtr);
     2826
     2827  if ((nItem >= -1) && (lpFindInfo != NULL))
     2828  {
     2829    ZeroMemory(&lvItem, sizeof(LVITEMA));
     2830
     2831    if (lpFindInfo->flags & LVFI_PARAM)
     2832    {
     2833      lvItem.mask |= LVIF_PARAM;
     2834    }
     2835   
     2836    if (lpFindInfo->flags & LVFI_STRING)
     2837    {
     2838      lvItem.mask |= LVIF_TEXT;
     2839      lvItem.pszText = szDispText;
     2840      lvItem.cchTextMax = DISP_TEXT_SIZE;
     2841    }
     2842
     2843    if (lpFindInfo->flags & LVFI_PARTIAL)
     2844    {
     2845      lvItem.mask |= LVIF_TEXT;
     2846      lvItem.pszText = szDispText;
     2847      lvItem.cchTextMax = DISP_TEXT_SIZE;
     2848    }
     2849
     2850    if (lpFindInfo->flags & LVFI_WRAP)
     2851    {
     2852      bWrap = TRUE;
     2853    }
     2854
     2855    if (lpFindInfo->flags & LVFI_NEARESTXY)
     2856    {
     2857      ptItem.x = lpFindInfo->pt.x;
     2858      ptItem.y = lpFindInfo->pt.y;
     2859    }
     2860
     2861    while (1)
     2862    {
     2863      while (nItem < nLast)
     2864      {
     2865        if (lpFindInfo->flags & LVFI_NEARESTXY)
     2866        {
     2867          nItem = LISTVIEW_GetNearestItem(hwnd, ptItem,
     2868                                          lpFindInfo->vkDirection);
     2869          if (nItem != -1)
     2870          {
     2871            /* get position of the new item index */
     2872            if (ListView_GetItemPosition(hwnd, nItem, &ptItem) == FALSE)
     2873              return -1;
     2874          }
     2875          else
     2876            return -1;
     2877        }
     2878        else
     2879        {
     2880          nItem++;
     2881        }
     2882       
     2883        lvItem.iItem = nItem;
     2884        lvItem.iSubItem = 0;
     2885        if (ListView_GetItemA(hwnd, &lvItem) != FALSE)
     2886        {
     2887          if (lvItem.mask & LVIF_TEXT)
     2888          {
     2889            if (lpFindInfo->flags & LVFI_PARTIAL)
     2890            {
     2891              if (strstr(lvItem.pszText, lpFindInfo->psz) == NULL)
     2892                continue;
     2893            }
     2894            else
     2895            {
     2896              if (strcmp(lvItem.pszText, lpFindInfo->psz) != 0)
     2897                continue;
     2898            }
     2899          }
     2900         
     2901          if (lvItem.mask & LVIF_PARAM)
     2902          {
     2903            if (lpFindInfo->lParam != lvItem.lParam)
     2904              continue;
     2905          }
     2906         
     2907          return nItem;
     2908        }
     2909      }
     2910
     2911      if (bWrap != FALSE)
     2912      {
     2913        nItem = -1;
     2914        nLast = nStart + 1;
     2915        bWrap = FALSE;
     2916      }
     2917      else
     2918      {
     2919        return -1;
     2920      }       
     2921    }
     2922  }
     2923
     2924 return -1;
    29262925}
    29272926
     
    29912990 *   FAILURE : FALSE
    29922991 */
    2993 static LRESULT LISTVIEW_GetColumnA(HWND hwnd, INT nItem,
    2994                                      LPLVCOLUMNA lpColumn)
     2992static LRESULT LISTVIEW_GetColumnA(HWND hwnd, INT nItem, LPLVCOLUMNA lpColumn)
    29952993{
    29962994  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     
    30973095{
    30983096  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    3099   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     3097  UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
     3098  INT nColumnWidth = 0;
    31003099  HDITEMA hdi;
    3101   INT nColumnWidth = 0;
    3102 
    3103   switch (LVS_TYPEMASK & lStyle)
    3104   {
    3105   case LVS_LIST:
     3100
     3101  if (uView == LVS_LIST)
     3102  {
    31063103    nColumnWidth = infoPtr->nItemWidth;
    3107     break;
    3108 
    3109   case LVS_REPORT:
     3104  }
     3105  else if (uView == LVS_REPORT)
     3106  {
    31103107    /* get column width from header */
    31113108    ZeroMemory(&hdi, sizeof(HDITEMA));
     
    31153112      nColumnWidth = hdi.cxy;
    31163113    }
    3117     break;
    31183114  }
    31193115
     
    31363132{
    31373133  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    3138   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     3134  UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    31393135  INT nItemCount = 0;
    31403136
    3141   switch (LVS_TYPEMASK & lStyle)
    3142   {
    3143   case LVS_LIST:
    3144     if (infoPtr->rcList.right / infoPtr->nItemWidth)
    3145     {
    3146       nItemCount = infoPtr->nCountPerRow * infoPtr->nCountPerColumn;
    3147     }
    3148     break;
    3149  
    3150   case LVS_REPORT:
    3151     nItemCount = infoPtr->nCountPerColumn;
    3152     break;
    3153    
    3154   case LVS_SMALLICON:
    3155   case LVS_ICON:
     3137  if (uView == LVS_LIST)
     3138  {
     3139    if (infoPtr->rcList.right > infoPtr->nItemWidth)
     3140    {
     3141      nItemCount = LISTVIEW_GetCountPerRow(hwnd) *
     3142                   LISTVIEW_GetCountPerColumn(hwnd);
     3143    }
     3144  }
     3145  else if (uView == LVS_REPORT)
     3146  {
     3147    nItemCount = LISTVIEW_GetCountPerColumn(hwnd);
     3148  }
     3149  else
     3150  {
    31563151    nItemCount = GETITEMCOUNT(infoPtr);
    3157     break;
    31583152  }
    31593153
     
    32353229{
    32363230  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     3231  LONG lCtrlId = GetWindowLongA(hwnd, GWL_ID);
     3232  BOOL bResult = FALSE;
     3233  NMLVDISPINFOA dispInfo;
     3234  LISTVIEW_SUBITEM *lpSubItem;
    32373235  LISTVIEW_ITEM *lpItem;
    3238   LISTVIEW_SUBITEM *lpSubItem;
    32393236  HDPA hdpaSubItems;
    3240   BOOL bResult = FALSE;
    3241 
    3242 //  TRACE(listview, "(hwnd=%x,lpLVItem=%p)\n", hwnd, lpLVItem);
     3237
     3238  TRACE("(hwnd=%x, lpLVItem=%p)\n", hwnd, lpLVItem);
    32433239
    32443240  if (lpLVItem != NULL)
     
    32463242    if ((lpLVItem->iItem >= 0) && (lpLVItem->iItem < GETITEMCOUNT(infoPtr)))
    32473243    {
     3244      ZeroMemory(&dispInfo, sizeof(NMLVDISPINFOA));
    32483245      hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, lpLVItem->iItem);
    32493246      if (hdpaSubItems != NULL)
    32503247      {
    3251         if (lpLVItem->iSubItem == 0)
    3252         {
    3253           lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0);
    3254           if (lpItem != NULL)
     3248        lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0);
     3249        if (lpItem != NULL)
     3250        {
     3251          bResult = TRUE;
     3252          if (lpLVItem->iSubItem == 0)
    32553253          {
    3256             bResult = TRUE;
    3257 
    3258             /* retrieve valid data */
    3259             if (lpLVItem->mask & LVIF_STATE)
     3254            if ((lpItem->iImage == I_IMAGECALLBACK) &&
     3255                (lpLVItem->mask & LVIF_IMAGE))
     3256            {
     3257              dispInfo.item.mask |= LVIF_IMAGE;
     3258            }
     3259           
     3260            if ((lpItem->pszText == LPSTR_TEXTCALLBACKA) &&
     3261                (lpLVItem->mask & LVIF_TEXT))
     3262            {
     3263              dispInfo.item.mask |= LVIF_TEXT;
     3264              ZeroMemory(lpLVItem->pszText, sizeof(CHAR)*lpLVItem->cchTextMax);
     3265              dispInfo.item.pszText = lpLVItem->pszText;
     3266              dispInfo.item.cchTextMax = lpLVItem->cchTextMax;
     3267            }
     3268           
     3269            if ((infoPtr->uCallbackMask != 0) && (lpLVItem->mask & LVIF_STATE))
     3270            {       
     3271              dispInfo.item.mask |= LVIF_STATE;
     3272              dispInfo.item.stateMask = infoPtr->uCallbackMask;
     3273            }
     3274           
     3275            if (dispInfo.item.mask != 0)
     3276            {
     3277              dispInfo.hdr.hwndFrom = hwnd;
     3278              dispInfo.hdr.idFrom = lCtrlId;
     3279              dispInfo.hdr.code = LVN_GETDISPINFOA;
     3280              dispInfo.item.iItem = lpLVItem->iItem;
     3281              dispInfo.item.iSubItem = 0;
     3282              dispInfo.item.lParam = lpItem->lParam;
     3283              ListView_Notify(GetParent(hwnd), lCtrlId, &dispInfo);
     3284            }
     3285           
     3286            if (dispInfo.item.mask & LVIF_IMAGE)
     3287            {
     3288              lpLVItem->iImage = dispInfo.item.iImage;
     3289            }
     3290            else if (lpLVItem->mask & LVIF_IMAGE)
     3291            {
     3292              lpLVItem->iImage = lpItem->iImage;
     3293            }
     3294           
     3295            if (dispInfo.item.mask & LVIF_TEXT)
     3296            {
     3297              if (dispInfo.item.mask & LVIF_DI_SETITEM)
     3298              {
     3299                Str_SetPtrA(&lpItem->pszText, dispInfo.item.pszText);
     3300              }
     3301              lpLVItem->pszText = dispInfo.item.pszText;
     3302            }
     3303            else if (lpLVItem->mask & LVIF_TEXT)
     3304            {
     3305              lpLVItem->pszText = lpItem->pszText;
     3306            }
     3307           
     3308            if (dispInfo.item.mask & LVIF_STATE)
     3309            {
     3310              lpLVItem->state = lpItem->state;
     3311              lpLVItem->state &= ~dispInfo.item.stateMask;
     3312              lpLVItem->state |= (dispInfo.item.state &
     3313                                  dispInfo.item.stateMask);
     3314            }
     3315            else if (lpLVItem->mask & LVIF_STATE)
    32603316            {
    32613317              lpLVItem->state = lpItem->state & lpLVItem->stateMask;
    32623318            }
    32633319
    3264             if (lpLVItem->mask & LVIF_TEXT)
    3265             {
    3266               if (lpItem->pszText == LPSTR_TEXTCALLBACKA)
    3267               {
    3268                 lpLVItem->pszText = LPSTR_TEXTCALLBACKA;
    3269               }
    3270               else
    3271               {
    3272                 bResult = Str_GetPtrA(lpItem->pszText, lpLVItem->pszText,
    3273                                         lpLVItem->cchTextMax);
    3274               }
    3275             }
    3276 
    3277             if (lpLVItem->mask & LVIF_IMAGE)
    3278             {
    3279               lpLVItem->iImage = lpItem->iImage;
    3280             }
    3281          
    32823320            if (lpLVItem->mask & LVIF_PARAM)
    32833321            {
    32843322              lpLVItem->lParam = lpItem->lParam;
    32853323            }
    3286      
     3324           
    32873325            if (lpLVItem->mask & LVIF_INDENT)
    32883326            {
     
    32903328            }
    32913329          }
    3292         }
    3293         else
    3294         {
    3295           lpSubItem = (LISTVIEW_SUBITEM *)DPA_GetPtr(hdpaSubItems,
    3296                                                      lpLVItem->iSubItem);
    3297           if (lpSubItem != NULL)
     3330          else
    32983331          {
    3299             bResult = TRUE;
    3300 
    3301             if (lpLVItem->mask & LVIF_TEXT)
     3332            lpSubItem = LISTVIEW_GetSubItemPtr(hdpaSubItems,
     3333                                               lpLVItem->iSubItem);
     3334            if (lpSubItem != NULL)
    33023335            {
    3303               if (lpSubItem->pszText == LPSTR_TEXTCALLBACKA)
     3336              if ((lpSubItem->iImage == I_IMAGECALLBACK) &&
     3337                  (lpLVItem->mask & LVIF_IMAGE))
    33043338              {
    3305                 lpLVItem->pszText = LPSTR_TEXTCALLBACKA;
     3339                dispInfo.item.mask |= LVIF_IMAGE;
    33063340              }
    3307               else
     3341             
     3342              if ((lpSubItem->pszText == LPSTR_TEXTCALLBACKA) &&
     3343                  (lpLVItem->mask & LVIF_TEXT))
    33083344              {
    3309                 bResult = Str_GetPtrA(lpSubItem->pszText, lpLVItem->pszText,
    3310                                         lpLVItem->cchTextMax);
     3345                dispInfo.item.mask |= LVIF_TEXT;
     3346                ZeroMemory(lpLVItem->pszText,
     3347                           sizeof(CHAR)*lpLVItem->cchTextMax);
     3348                dispInfo.item.pszText = lpLVItem->pszText;
     3349                dispInfo.item.cchTextMax = lpLVItem->cchTextMax;
    33113350              }
    33123351            }
    3313 
    3314             if (lpLVItem->mask & LVIF_IMAGE)
     3352            else
    33153353            {
    3316               lpLVItem->iImage = lpSubItem->iImage;
     3354              if (lpLVItem->mask & LVIF_IMAGE)
     3355              {
     3356                dispInfo.item.mask |= LVIF_IMAGE;
     3357              }
     3358         
     3359              if (lpLVItem->mask & LVIF_TEXT)
     3360              {
     3361                dispInfo.item.mask |= LVIF_TEXT;
     3362                ZeroMemory(lpLVItem->pszText,
     3363                           sizeof(CHAR)*lpLVItem->cchTextMax);
     3364                dispInfo.item.pszText = lpLVItem->pszText;
     3365                dispInfo.item.cchTextMax = lpLVItem->cchTextMax;
     3366              }
     3367            }
     3368
     3369            if (dispInfo.item.mask != 0)
     3370            {
     3371              dispInfo.hdr.hwndFrom = hwnd;
     3372              dispInfo.hdr.idFrom = lCtrlId;
     3373              dispInfo.hdr.code = LVN_GETDISPINFOA;
     3374              dispInfo.item.iItem = lpLVItem->iItem;
     3375              dispInfo.item.iSubItem = lpLVItem->iSubItem;
     3376              dispInfo.item.lParam = lpItem->lParam;
     3377              ListView_Notify(GetParent(hwnd), lCtrlId, &dispInfo);
     3378            }
     3379
     3380            if (dispInfo.item.mask & LVIF_IMAGE)
     3381            {
     3382              lpLVItem->iImage = dispInfo.item.iImage;
     3383            }
     3384            else if (lpLVItem->mask & LVIF_IMAGE)
     3385            {
     3386              lpLVItem->iImage = lpItem->iImage;
     3387            }
     3388
     3389            if (dispInfo.item.mask & LVIF_TEXT)
     3390            {
     3391              if (dispInfo.item.mask & LVIF_DI_SETITEM)
     3392              {
     3393                Str_SetPtrA(&lpItem->pszText, dispInfo.item.pszText);
     3394              }
     3395              lpLVItem->pszText = dispInfo.item.pszText;
     3396            }
     3397            else if (lpLVItem->mask & LVIF_TEXT)
     3398            {
     3399              lpLVItem->pszText = lpItem->pszText;
    33173400            }
    33183401          }
     
    33643447{
    33653448  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    3366   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     3449  UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    33673450  BOOL bResult = FALSE;
    33683451  HDPA hdpaSubItems;
    33693452  LISTVIEW_ITEM *lpItem;
     3453  INT nCountPerColumn;
    33703454  INT nRow;
    33713455
    3372 //  TRACE(listview, "(hwnd=%x,nItem=%d,lpptPosition=%p)\n", hwnd, nItem,
    3373 //        lpptPosition);
     3456  TRACE("(hwnd=%x,nItem=%d,lpptPosition=%p)\n", hwnd, nItem,
     3457        lpptPosition);
    33743458
    33753459  if ((nItem >= 0) && (nItem < GETITEMCOUNT(infoPtr)) &&
    33763460      (lpptPosition != NULL))
    33773461  {
    3378     switch (LVS_TYPEMASK & lStyle)
    3379     {
    3380     case LVS_LIST:
     3462    if (uView == LVS_LIST)
     3463    {
    33813464      bResult = TRUE;
    33823465      nItem = nItem - ListView_GetTopIndex(hwnd);
     3466      nCountPerColumn = LISTVIEW_GetCountPerColumn(hwnd);
    33833467      if (nItem < 0)
    33843468      {
    3385         nRow = nItem % infoPtr->nCountPerColumn;
     3469        nRow = nItem % nCountPerColumn;
    33863470        if (nRow == 0)
    33873471        {
    3388           lpptPosition->x = (nItem / infoPtr->nCountPerColumn *
    3389                              infoPtr->nItemWidth);
     3472          lpptPosition->x = nItem / nCountPerColumn * infoPtr->nItemWidth;
    33903473          lpptPosition->y = 0;
    33913474        }
    33923475        else
    33933476        {
    3394           lpptPosition->x = ((nItem / infoPtr->nCountPerColumn - 1) *
    3395                              infoPtr->nItemWidth);
    3396           lpptPosition->y = ((nRow + infoPtr->nCountPerColumn) *
    3397                              infoPtr->nItemHeight); 
     3477          lpptPosition->x = (nItem / nCountPerColumn -1) * infoPtr->nItemWidth;
     3478          lpptPosition->y = (nRow + nCountPerColumn) * infoPtr->nItemHeight; 
    33983479        }
    33993480      }
    34003481      else
    34013482      {
    3402         lpptPosition->x = (nItem / infoPtr->nCountPerColumn *
    3403                            infoPtr->nItemWidth);
    3404         lpptPosition->y = (nItem % infoPtr->nCountPerColumn *
    3405                            infoPtr->nItemHeight);
    3406       }
    3407       break;
    3408 
    3409     case LVS_REPORT:
     3483        lpptPosition->x = nItem / nCountPerColumn * infoPtr->nItemWidth;
     3484        lpptPosition->y = nItem % nCountPerColumn * infoPtr->nItemHeight;
     3485      }
     3486    }
     3487    else if (uView == LVS_REPORT)
     3488    {
    34103489      bResult = TRUE;
    34113490      lpptPosition->x = REPORT_MARGINX;
    34123491      lpptPosition->y = ((nItem - ListView_GetTopIndex(hwnd)) *
    34133492                         infoPtr->nItemHeight) + infoPtr->rcList.top;
    3414       break;
    3415 
    3416     case LVS_SMALLICON:
    3417     case LVS_ICON:
     3493    }
     3494    else
     3495    {
    34183496      hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, nItem);
    34193497      if (hdpaSubItems != NULL)
     
    34273505        }
    34283506      }
    3429       break;
    34303507    }
    34313508  }
     
    34503527{
    34513528  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    3452   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     3529  UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    34533530  BOOL bResult = FALSE;
    34543531  POINT ptOrigin;
     
    34603537  TEXTMETRICA tm;
    34613538
    3462 //  TRACE(listview, "(hwnd=%x,nItem=%d,lprc=%p)\n", hwnd, nItem, lprc);
    3463 
     3539  TRACE("(hwnd=%x, nItem=%d, lprc=%p)\n", hwnd, nItem, lprc);
     3540 
    34643541  if ((nItem >= 0) && (nItem < GETITEMCOUNT(infoPtr)) && (lprc != NULL))
    34653542  {
     
    34693546      { 
    34703547      case LVIR_ICON:
    3471         switch (LVS_TYPEMASK & lStyle)
    3472         {
    3473         case LVS_ICON:
     3548        if (uView == LVS_ICON)
     3549        {
    34743550          if (infoPtr->himlNormal != NULL)
    34753551          {
     
    34843560            }
    34853561          }
    3486           break;
    3487 
    3488         case LVS_SMALLICON:
     3562        }
     3563        else if (uView == LVS_SMALLICON)
     3564        {
    34893565          if (LISTVIEW_GetOrigin(hwnd, &ptOrigin) != FALSE)
    34903566          {
     
    34953571
    34963572            if (infoPtr->himlState != NULL)
    3497             {
    34983573              lprc->left += infoPtr->iconSize.cx;
    3499             }
    35003574             
    35013575            if (infoPtr->himlSmall != NULL)
    3502             {
    35033576              lprc->right = lprc->left + infoPtr->iconSize.cx;
    3504             }
    35053577            else
    3506             {
    35073578              lprc->right = lprc->left;
    3508             }
    35093579          }
    3510           break;
    3511 
    3512         case LVS_REPORT:
    3513         case LVS_LIST:
     3580        }
     3581        else
     3582        {
    35143583          bResult = TRUE;
    35153584          lprc->left = ptItem.x;
     
    35303599            lprc->right = lprc->left;
    35313600          }
    3532           break;
    35333601        }
    35343602        break;
    35353603
    35363604      case LVIR_LABEL:
    3537         switch (LVS_TYPEMASK & lStyle)
    3538         {
    3539         case LVS_ICON:
     3605        if (uView == LVS_ICON)
     3606        {
    35403607          if (infoPtr->himlNormal != NULL)
    35413608          {
     
    35663633            }             
    35673634          }
    3568           break;
    3569 
    3570         case LVS_SMALLICON:
     3635        }
     3636        else if (uView == LVS_SMALLICON)
     3637        {
    35713638          if (LISTVIEW_GetOrigin(hwnd, &ptOrigin) != FALSE)
    35723639          {
     
    35963663            }
    35973664          }
    3598           break;
    3599 
    3600         case LVS_REPORT:
    3601         case LVS_LIST:
     3665        }
     3666        else
     3667        {
    36023668          bResult = TRUE;
    36033669          lprc->left = ptItem.x;
     
    36163682
    36173683          lprc->right = lprc->left + LISTVIEW_GetLabelWidth(hwnd, nItem);
    3618           break;
    36193684        }
    36203685        break;
    36213686
    36223687      case LVIR_BOUNDS:
    3623         switch (LVS_TYPEMASK & lStyle)
    3624         {
    3625         case LVS_ICON:
     3688        if (uView == LVS_ICON)
     3689        {
    36263690          if (infoPtr->himlNormal != NULL)
    36273691          {
     
    36353699            }
    36363700          }
    3637           break;
    3638 
    3639         case LVS_SMALLICON:
     3701        }
     3702        else if (uView == LVS_SMALLICON)
     3703        {
    36403704          if (LISTVIEW_GetOrigin(hwnd, &ptOrigin) != FALSE)
    36413705          {
    36423706            bResult = TRUE;
    3643             lprc->left = ptItem.x +ptOrigin.x;
     3707            lprc->left = ptItem.x + ptOrigin.x;
    36443708            lprc->right = lprc->left;
    36453709            lprc->top = ptItem.y + ptOrigin.y;
    36463710            lprc->bottom = lprc->top + infoPtr->nItemHeight;
    3647            
    36483711            if (infoPtr->himlState != NULL)
    3649             {
    36503712              lprc->right += infoPtr->iconSize.cx;
    3651             }
    3652            
    36533713            if (infoPtr->himlSmall != NULL)
    3654             {
    36553714              lprc->right += infoPtr->iconSize.cx;
    3656             }
    3657            
    36583715            lprc->right += LISTVIEW_GetLabelWidth(hwnd, nItem);
    36593716          }
    3660           break;
    3661 
    3662         case LVS_REPORT:
    3663         case LVS_LIST:
     3717        }
     3718        else
     3719        {
    36643720          bResult = TRUE;
    36653721          lprc->left = ptItem.x;
     
    36793735
    36803736          lprc->right += LISTVIEW_GetLabelWidth(hwnd, nItem);
    3681           break;
    36823737        }
    36833738        break;
    36843739       
    36853740      case LVIR_SELECTBOUNDS:
    3686         switch (LVS_TYPEMASK & lStyle)
    3687         {
    3688         case LVS_ICON:
     3741        if (uView == LVS_ICON)
     3742        {
    36893743          if (infoPtr->himlNormal != NULL)
    36903744          {
     
    36983752            }
    36993753          }
    3700           break;
    3701 
    3702         case LVS_SMALLICON:
     3754        }
     3755        else if (uView == LVS_SMALLICON)
     3756        {
    37033757          if (LISTVIEW_GetOrigin(hwnd, &ptOrigin) != FALSE)
    37043758          {
     
    37223776            lprc->right += LISTVIEW_GetLabelWidth(hwnd, nItem);
    37233777          }
    3724           break;
    3725 
    3726         case LVS_REPORT:
    3727         case LVS_LIST:
     3778        }
     3779        else
     3780        {
    37283781          bResult = TRUE;
    37293782          lprc->left = ptItem.x;
     
    37443797
    37453798          lprc->right += LISTVIEW_GetLabelWidth(hwnd, nItem);
    3746           break;
    37473799        }
    37483800        break;
     
    37653817 *   FAILURE : zero
    37663818 */
    3767 
    37683819static INT LISTVIEW_GetLabelWidth(HWND hwnd, INT nItem)
    37693820{
    3770   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    3771   LISTVIEW_ITEM *lpItem;
    3772   HDPA hdpaSubItems;
     3821  CHAR szDispText[DISP_TEXT_SIZE];
    37733822  INT nLabelWidth = 0;
    3774 
    3775 //  TRACE(listview, "(hwnd=%x,nItem=%d)\n", hwnd, nItem);
    3776 
    3777   hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, nItem);
    3778   if (hdpaSubItems != NULL)
    3779   {
    3780     lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0);
    3781     if (lpItem != NULL)
    3782     {
    3783       CHAR szDispText[DISP_TEXT_SIZE];
    3784       LPSTR pszDispText = NULL;
    3785       pszDispText = szDispText;
    3786       LISTVIEW_GetItemDispInfo(hwnd, nItem, lpItem, NULL, NULL, &pszDispText,
    3787                                DISP_TEXT_SIZE);
    3788       nLabelWidth = ListView_GetStringWidthA(hwnd, pszDispText);
    3789     }
    3790   }
    3791 
     3823  LVITEMA lvItem;
     3824
     3825  TRACE("(hwnd=%x, nItem=%d)\n", hwnd, nItem);
     3826
     3827  ZeroMemory(&lvItem, sizeof(LVITEMA));
     3828  lvItem.mask = LVIF_TEXT;
     3829  lvItem.iItem = nItem;
     3830  lvItem.cchTextMax = DISP_TEXT_SIZE;
     3831  lvItem.pszText = szDispText;
     3832  if (ListView_GetItemA(hwnd, &lvItem) != FALSE)
     3833  {
     3834    nLabelWidth = ListView_GetStringWidthA(hwnd, lvItem.pszText);
     3835  }
     3836   
    37923837  return nLabelWidth;
    37933838}
     
    38653910 *
    38663911 * RETURN:
    3867  * None
     3912 *   SUCCESS : string length
     3913 *   FAILURE : 0
    38683914 */
    38693915static LRESULT LISTVIEW_GetItemTextA(HWND hwnd, INT nItem, LPLVITEMA lpLVItem)
    38703916{
    38713917  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    3872   LISTVIEW_ITEM *lpItem;
    3873   LISTVIEW_SUBITEM *lpSubItem;
    3874   HDPA hdpaSubItems;
    38753918  INT nLength = 0;
    38763919 
     
    38793922    if ((nItem >= 0) && (nItem < GETITEMCOUNT(infoPtr)))
    38803923    {
    3881       hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, lpLVItem->iItem);
    3882       if (hdpaSubItems != NULL)
    3883       {
    3884         if (lpLVItem->iSubItem == 0)
    3885         {
    3886           lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0);
    3887           if (lpItem != NULL)
    3888           {
    3889             if (lpLVItem->mask & LVIF_TEXT)
    3890             {
    3891               if (lpItem->pszText == LPSTR_TEXTCALLBACKA)
    3892               {
    3893                 lpLVItem->pszText = LPSTR_TEXTCALLBACKA;
    3894               }
    3895               else
    3896               {
    3897                 nLength = Str_GetPtrA(lpItem->pszText, lpLVItem->pszText,
    3898                                       lpLVItem->cchTextMax);
    3899               }
    3900             }
    3901           }
    3902         }
    3903         else
    3904         {
    3905           lpSubItem = (LISTVIEW_SUBITEM *)DPA_GetPtr(hdpaSubItems,
    3906                                                      lpLVItem->iSubItem);
    3907           if (lpSubItem != NULL)
    3908           {
    3909             if (lpLVItem->mask & LVIF_TEXT)
    3910             {
    3911               if (lpSubItem->pszText == LPSTR_TEXTCALLBACKA)
    3912               {
    3913                 lpLVItem->pszText = LPSTR_TEXTCALLBACKA;
    3914               }
    3915               else
    3916               {
    3917                 nLength = Str_GetPtrA(lpSubItem->pszText, lpLVItem->pszText,
    3918                                       lpLVItem->cchTextMax);
    3919               }
    3920             }
    3921           }
    3922         }
     3924      lpLVItem->mask = LVIF_TEXT;
     3925      lpLVItem->iItem = nItem;
     3926      if (ListView_GetItemA(hwnd, lpLVItem) != FALSE)
     3927      {
     3928        nLength = lstrlenA(lpLVItem->pszText);
    39233929      }
    39243930    }
     
    39343940 * PARAMETER(S):
    39353941 * [I] HWND : window handle
    3936  * [I] INT : starting search item index
    3937  * [I] UINT : relationship flag
     3942 * [I] INT : item index
     3943 * [I] INT : relationship flag
    39383944 *
    39393945 * RETURN:
     
    39413947 *   FAILURE : -1
    39423948 */
    3943 static LRESULT LISTVIEW_GetNextItem(HWND hwnd, INT iStart, UINT uFlags)
    3944 {
    3945   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongA(hwnd, 0);
    3946   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
    3947   LISTVIEW_ITEM *lpItem;
    3948   UINT style_mask = LVS_TYPEMASK & lStyle;
     3949static LRESULT LISTVIEW_GetNextItem(HWND hwnd, INT nItem, UINT uFlags)
     3950{
     3951  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     3952  UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    39493953  UINT uMask = 0;
    3950   INT nItems = GETITEMCOUNT(infoPtr);
    3951   INT iIndex = iStart;
    3952   INT eIndex = nItems - 1;
    3953   INT sIndex = 0;
    3954   INT delta = 1;
     3954  LVFINDINFO lvFindInfo;
     3955  INT nCountPerColumn;
     3956  INT i;
    39553957 
    3956   INT nCountPerColumn = max((infoPtr->rcList.bottom - infoPtr->rcList.top) /
    3957                             infoPtr->nItemHeight, 1);
    3958   INT nCountPerRow = max((infoPtr->rcList.right - infoPtr->rcList.left) /
    3959                          infoPtr->nItemWidth, 1);
    3960 
    3961   if(uFlags & LVNI_ABOVE) /* moving upwards from iStart */
    3962   {
    3963     if(style_mask == LVS_LIST || style_mask == LVS_REPORT)
    3964       delta = -1;
     3958  if ((nItem >= -1) && (nItem < GETITEMCOUNT(infoPtr)))
     3959  {
     3960    ZeroMemory(&lvFindInfo, sizeof(LVFINDINFO));
     3961
     3962    if (uFlags & LVNI_CUT)
     3963      uMask |= LVIS_CUT;
     3964   
     3965    if (uFlags & LVNI_DROPHILITED)
     3966      uMask |= LVIS_DROPHILITED;
     3967         
     3968    if (uFlags & LVNI_FOCUSED)
     3969      uMask |= LVIS_FOCUSED;
     3970
     3971    if (uFlags & LVNI_SELECTED)
     3972      uMask |= LVIS_SELECTED;
     3973
     3974    if (uFlags & LVNI_ABOVE)
     3975    {
     3976      if ((uView == LVS_LIST) || (uView == LVS_REPORT))
     3977      {
     3978        while (nItem >= 0)
     3979        {
     3980          nItem--;
     3981          if ((ListView_GetItemState(hwnd, nItem, uMask) & uMask) == uMask)
     3982            return nItem;
     3983        }
     3984      }
     3985      else
     3986      {
     3987        lvFindInfo.flags = LVFI_NEARESTXY;
     3988        lvFindInfo.vkDirection = VK_UP;
     3989        ListView_GetItemPosition(hwnd, nItem, &lvFindInfo.pt);
     3990        while ((nItem = LISTVIEW_FindItem(hwnd, nItem, &lvFindInfo)) != -1)
     3991        {
     3992          if ((ListView_GetItemState(hwnd, nItem, uMask) & uMask) == uMask)
     3993            return nItem;
     3994        }
     3995      }
     3996    }
     3997    else if (uFlags & LVNI_BELOW)
     3998    {
     3999      if ((uView == LVS_LIST) || (uView == LVS_REPORT))
     4000      {
     4001        while (nItem < GETITEMCOUNT(infoPtr))
     4002        {
     4003          nItem++;
     4004          if ((ListView_GetItemState(hwnd, nItem, uMask) & uMask) == uMask)
     4005            return nItem;
     4006        }
     4007      }
     4008      else
     4009      {
     4010        lvFindInfo.flags = LVFI_NEARESTXY;
     4011        lvFindInfo.vkDirection = VK_DOWN;
     4012        ListView_GetItemPosition(hwnd, nItem, &lvFindInfo.pt);
     4013        while ((nItem = LISTVIEW_FindItem(hwnd, nItem, &lvFindInfo)) != -1)
     4014        {
     4015          if ((ListView_GetItemState(hwnd, nItem, uMask) & uMask) == uMask)
     4016            return nItem;
     4017        }
     4018      }
     4019    }
     4020    else if (uFlags & LVNI_TOLEFT)
     4021    {
     4022      if (uView == LVS_LIST)
     4023      {
     4024        nCountPerColumn = LISTVIEW_GetCountPerColumn(hwnd);
     4025        while (nItem - nCountPerColumn >= 0)
     4026        {
     4027          nItem -= nCountPerColumn;
     4028          if ((ListView_GetItemState(hwnd, nItem, uMask) & uMask) == uMask)
     4029            return nItem;
     4030        }
     4031      }
     4032      else if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
     4033      {
     4034        lvFindInfo.flags = LVFI_NEARESTXY;
     4035        lvFindInfo.vkDirection = VK_LEFT;
     4036        ListView_GetItemPosition(hwnd, nItem, &lvFindInfo.pt);
     4037        while ((nItem = LISTVIEW_FindItem(hwnd, nItem, &lvFindInfo)) != -1)
     4038        {
     4039          if ((ListView_GetItemState(hwnd, nItem, uMask) & uMask) == uMask)
     4040            return nItem;
     4041        }
     4042      }
     4043    }
     4044    else if (uFlags & LVNI_TORIGHT)
     4045    {
     4046      if (uView == LVS_LIST)
     4047      {
     4048        nCountPerColumn = LISTVIEW_GetCountPerColumn(hwnd);
     4049        while (nItem + nCountPerColumn < GETITEMCOUNT(infoPtr))
     4050        {
     4051          nItem += nCountPerColumn;
     4052          if ((ListView_GetItemState(hwnd, nItem, uMask) & uMask) == uMask)
     4053            return nItem;
     4054        }
     4055      }
     4056      else if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
     4057      {
     4058        lvFindInfo.flags = LVFI_NEARESTXY;
     4059        lvFindInfo.vkDirection = VK_RIGHT;
     4060        ListView_GetItemPosition(hwnd, nItem, &lvFindInfo.pt);
     4061        while ((nItem = LISTVIEW_FindItem(hwnd, nItem, &lvFindInfo)) != -1)
     4062        {
     4063          if ((ListView_GetItemState(hwnd, nItem, uMask) & uMask) == uMask)
     4064            return nItem;
     4065        }
     4066      }
     4067    }
    39654068    else
    39664069    {
    3967       if(lStyle & LVS_ALIGNLEFT)
    3968       {
    3969         sIndex = iStart - (iStart % nCountPerColumn);
    3970         delta = -1;
    3971       }
    3972       else
    3973         delta = -nCountPerRow;
    3974     }
    3975   }
    3976   else if(uFlags & LVNI_BELOW) /* moving downwards from iStart */
    3977   {
    3978     if(style_mask == LVS_SMALLICON || style_mask == LVS_ICON)
    3979     {
    3980       if (lStyle & LVS_ALIGNLEFT)
    3981         eIndex = iStart + (nCountPerColumn - (iStart % nCountPerColumn) - 1);
    3982       else
    3983         delta = nCountPerRow;
    3984     }   
    3985   }
    3986   else if(uFlags & LVNI_TOLEFT) /* moving to the left of iStart */
    3987   {
    3988     if(style_mask == LVS_LIST)
    3989       delta = -infoPtr->nCountPerColumn;
    3990     else if(style_mask == LVS_SMALLICON || style_mask == LVS_ICON)
    3991     {
    3992       if(style_mask & LVS_ALIGNLEFT)
    3993         delta = -nCountPerColumn;
    3994       else
    3995       {
    3996         sIndex = iStart - (iStart % nCountPerRow);
    3997         delta = -1;
    3998       }
    3999     }   
    4000     else if(style_mask == LVS_REPORT)
    4001       return -1;
    4002   } 
    4003   else if(uFlags & LVNI_TORIGHT) /* moving to the right of iStart */
    4004   {
    4005     if(style_mask == LVS_LIST)
    4006       delta = infoPtr->nCountPerColumn;
    4007     else if(style_mask == LVS_ICON || style_mask == LVS_SMALLICON)
    4008     {
    4009       if(lStyle & LVS_ALIGNLEFT)
    4010         delta = nCountPerColumn;
    4011       else
    4012         eIndex = iStart + (nCountPerRow - (iStart % nCountPerRow) - 1);
    4013     }
    4014     else if(style_mask == LVS_REPORT)
    4015       return -1;
    4016   }
    4017  
    4018   /* perform come bounds checking before entering the main loop */
    4019   if(sIndex < 0) sIndex = 0;
    4020   if(eIndex > (nItems - 1)) eIndex = (nItems - 1);
    4021 
    4022   /* build uMask, the mask we are searching for */
    4023   if(uFlags & LVNI_CUT) uMask|=LVIS_CUT;
    4024   if(uFlags & LVNI_DROPHILITED) uMask|=LVIS_DROPHILITED;
    4025   if(uFlags & LVNI_FOCUSED) uMask|=LVIS_FOCUSED;
    4026   if(uFlags & LVNI_SELECTED) uMask|=LVIS_SELECTED; 
    4027 
    4028   while(TRUE) /* searching loop */
    4029   {
    4030     iIndex+=delta;   
    4031 
    4032     if((iIndex < sIndex) || (iIndex > eIndex))
    4033       break;
    4034 
    4035     /* see if flags match */
    4036     if(!uMask || (LISTVIEW_GetItemState(hwnd, iIndex, uMask) == uMask))
    4037       return iIndex;
    4038   }
     4070      nItem++;
     4071
     4072      /* search by index */
     4073      for (i = nItem; i < GETITEMCOUNT(infoPtr); i++)
     4074      {
     4075        if ((ListView_GetItemState(hwnd, i, uMask) & uMask) == uMask)
     4076          return i;
     4077      }
     4078    }
     4079  }
     4080
    40394081  return -1;
    40404082}
     
    40584100  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    40594101  LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     4102  UINT uView = lStyle & LVS_TYPEMASK;
    40604103  INT nListWidth = infoPtr->rcList.right - infoPtr->rcList.left;
    40614104  INT nListHeight = infoPtr->rcList.bottom - infoPtr->rcList.top;
    40624105  BOOL bResult = FALSE;
    4063 
    4064 //  TRACE(listview, "(hwnd=%x,lpptOrigin=%p)\n", hwnd, lpptOrigin);
    4065 
    4066   switch (LVS_TYPEMASK & lStyle)
    4067   {
    4068   case LVS_ICON:
    4069   case LVS_SMALLICON:
    4070     if ((lStyle & WS_HSCROLL) != 0)
    4071     {
    4072       lpptOrigin->x = -GetScrollPos(hwnd, SB_HORZ) * nListWidth / 10;
    4073     }
    4074     else
    4075     {
    4076       lpptOrigin->x = 0;
    4077     }
    4078 
    4079     if ((lStyle & WS_VSCROLL) != 0)
    4080     {
    4081       lpptOrigin->y = -GetScrollPos(hwnd, SB_VERT) * nListHeight / 10;
    4082     }
    4083     else
    4084     {
    4085       lpptOrigin->y = 0;
    4086     }
    40874106 
     4107  TRACE("(hwnd=%x, lpptOrigin=%p)\n", hwnd, lpptOrigin);
     4108
     4109  if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
     4110  {
     4111    SCROLLINFO scrollInfo;
     4112    ZeroMemory(lpptOrigin, sizeof(POINT));
     4113    ZeroMemory(&scrollInfo, sizeof(SCROLLINFO));
     4114    scrollInfo.cbSize = sizeof(SCROLLINFO);
     4115
     4116    if (lStyle & WS_HSCROLL)
     4117    {
     4118      scrollInfo.fMask = SIF_POS;
     4119      if (GetScrollInfo(hwnd, SB_HORZ, &scrollInfo) != FALSE)
     4120      {
     4121        lpptOrigin->x = -scrollInfo.nPos * max(nListWidth / 10, 1);
     4122      }
     4123    }
     4124
     4125    if (lStyle & WS_VSCROLL)
     4126    {
     4127      scrollInfo.fMask = SIF_POS;
     4128      if (GetScrollInfo(hwnd, SB_VERT, &scrollInfo) != FALSE)
     4129      {
     4130        lpptOrigin->y = -scrollInfo.nPos * max(nListHeight / 10, 1);
     4131      }
     4132    }
     4133     
    40884134    bResult = TRUE;
    4089     break;
    4090   }
    4091 
     4135  }
     4136 
    40924137  return bResult;
    40934138}
     
    41164161    }
    41174162  }
    4118 
     4163 
    41194164  return nSelectedCount;
    41204165}
     
    42054250/***
    42064251 * DESCRIPTION:
    4207  * Set the bounding rectangle of all the items.
    4208  *
    4209  * PARAMETER(S):
    4210  * [I] HWND : window handle
    4211  * [I] LPRECT : bounding rectangle
    4212  *
    4213  * RETURN:
    4214  *   SUCCESS : TRUE
    4215  *   FAILURE : FALSE
    4216  */
    4217 static LRESULT LISTVIEW_SetViewRect(HWND hwnd, LPRECT lprcView)
    4218 {
    4219   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongA(hwnd, 0);
    4220   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
    4221   BOOL bResult = FALSE;
    4222 
    4223 //  TRACE(listview, "(hwnd=%x,lprcView->left=%d,lprcView->top=%d,lprcView->right=%d,lprcView->bottom=%d)\n", hwnd, lprcView->left, lprcView->top, lprcView->right, lprcView->bottom);
    4224 
    4225   if (lprcView != NULL)
    4226   {
    4227     switch (lStyle & LVS_TYPEMASK)
    4228     {
    4229     case LVS_ICON:
    4230     case LVS_SMALLICON:
    4231       bResult = TRUE;
    4232       infoPtr->rcView.left = lprcView->left;
    4233       infoPtr->rcView.top = lprcView->top;
    4234       infoPtr->rcView.right = lprcView->right;
    4235       infoPtr->rcView.bottom = lprcView->bottom;
    4236       break;
    4237     }
    4238   }
    4239 
    4240   return bResult;
    4241 }
    4242 
    4243 /***
    4244  * DESCRIPTION:
    4245  * Retrieves the bounding rectangle of all the items.
    4246  *
    4247  * PARAMETER(S):
    4248  * [I] HWND : window handle
    4249  * [O] LPRECT : bounding rectangle
    4250  *
    4251  * RETURN:
    4252  *   SUCCESS : TRUE
    4253  *   FAILURE : FALSE
    4254  */
    4255 static LRESULT LISTVIEW_GetViewRect(HWND hwnd, LPRECT lprcView)
    4256 {
    4257   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongA(hwnd, 0);
    4258   BOOL bResult = FALSE;
    4259   POINT ptOrigin;
    4260 
    4261 //  TRACE(listview, "(hwnd=%x,lprcView=%p)\n", hwnd, lprcView);
    4262 
    4263   if (lprcView != NULL)
    4264   {
    4265     bResult = LISTVIEW_GetOrigin(hwnd, &ptOrigin);
    4266     if (bResult != FALSE)
    4267     {
    4268       lprcView->left = infoPtr->rcView.left + ptOrigin.x;
    4269       lprcView->top = infoPtr->rcView.top + ptOrigin.y;
    4270       lprcView->right = infoPtr->rcView.right + ptOrigin.x;
    4271       lprcView->bottom = infoPtr->rcView.bottom + ptOrigin.y;
    4272     }
    4273 
    4274 //    TRACE(listview, "(lprcView->left=%d,lprcView->top=%d,lprcView->right=%d,lprcView->bottom=%d)\n", lprcView->left, lprcView->top, lprcView->right, lprcView->bottom);
    4275 
    4276   }
    4277 
    4278   return bResult;
    4279 }
    4280 
    4281 /***
    4282  * DESCRIPTION:
    42834252 * Determines which section of the item was selected (if any).
    42844253 *
     
    42964265  RECT rcItem;
    42974266  INT i;
     4267 
     4268  TRACE("(hwnd=%x, x=%ld, y=%ld)\n", hwnd, lpHitTestInfo->pt.x,
     4269        lpHitTestInfo->pt.y);
    42984270
    42994271  for (i = 0; i < GETITEMCOUNT(infoPtr); i++)
     
    43024274    if (LISTVIEW_GetItemRect(hwnd, i, &rcItem) != FALSE)
    43034275    {
    4304       rcItem.left = LVIR_ICON;
    4305       if (LISTVIEW_GetItemRect(hwnd, i, &rcItem) != FALSE)
    4306       {
    4307         if ((lpHitTestInfo->pt.x >= rcItem.left) &&
    4308             (lpHitTestInfo->pt.x <= rcItem.right) &&
    4309             (lpHitTestInfo->pt.y >= rcItem.top) &&
    4310             (lpHitTestInfo->pt.y <= rcItem.bottom))
    4311         {
    4312           lpHitTestInfo->flags = LVHT_ONITEMICON | LVHT_ONITEM;
    4313           lpHitTestInfo->iItem = i;
    4314           lpHitTestInfo->iSubItem = 0;
    4315           return i;
    4316         }
    4317       }
     4276      if (PtInRect(&rcItem, lpHitTestInfo->pt) != FALSE)
     4277      {
     4278        rcItem.left = LVIR_ICON;
     4279        if (LISTVIEW_GetItemRect(hwnd, i, &rcItem) != FALSE)
     4280        {
     4281          if (PtInRect(&rcItem, lpHitTestInfo->pt) != FALSE)
     4282          {
     4283            lpHitTestInfo->flags = LVHT_ONITEMICON;
     4284            lpHitTestInfo->iItem = i;
     4285            lpHitTestInfo->iSubItem = 0;
     4286            return i;
     4287          }
     4288        }
    43184289     
    4319       rcItem.left = LVIR_LABEL;
    4320       if (LISTVIEW_GetItemRect(hwnd, i, &rcItem) != FALSE)
    4321       {
    4322         if ((lpHitTestInfo->pt.x >= rcItem.left) &&
    4323             (lpHitTestInfo->pt.x <= rcItem.right) &&
    4324             (lpHitTestInfo->pt.y >= rcItem.top) &&
    4325             (lpHitTestInfo->pt.y <= rcItem.bottom))
    4326         {
    4327           lpHitTestInfo->flags = LVHT_ONITEMLABEL | LVHT_ONITEM;
    4328           lpHitTestInfo->iItem = i;
    4329           lpHitTestInfo->iSubItem = 0;
    4330           return i;
    4331         }
    4332       }
    4333 
    4334       lpHitTestInfo->flags = LVHT_ONITEMSTATEICON | LVHT_ONITEM;
    4335       lpHitTestInfo->iItem = i;
    4336       lpHitTestInfo->iSubItem = 0;
    4337       return i;
     4290        rcItem.left = LVIR_LABEL;
     4291        if (LISTVIEW_GetItemRect(hwnd, i, &rcItem) != FALSE)
     4292        {
     4293          if (PtInRect(&rcItem, lpHitTestInfo->pt) != FALSE)
     4294          {
     4295            lpHitTestInfo->flags = LVHT_ONITEMLABEL;
     4296            lpHitTestInfo->iItem = i;
     4297            lpHitTestInfo->iSubItem = 0;
     4298            return i;
     4299          }
     4300        }
     4301       
     4302        lpHitTestInfo->flags = LVHT_ONITEMSTATEICON;
     4303        lpHitTestInfo->iItem = i;
     4304        lpHitTestInfo->iSubItem = 0;
     4305        return i;
     4306      }
    43384307    }
    43394308  }
     
    43464315/***
    43474316 * DESCRIPTION:
    4348  * Determines wich listview item is located at the specified position.
     4317 * Determines which listview item is located at the specified position.
    43494318 *
    43504319 * PARAMETER(S):
     
    43624331
    43634332  lpHitTestInfo->flags = 0;
     4333
    43644334  if (infoPtr->rcList.left > lpHitTestInfo->pt.x)
    43654335  {
     
    43704340    lpHitTestInfo->flags = LVHT_TORIGHT;
    43714341  }
    4372  
    43734342  if (infoPtr->rcList.top > lpHitTestInfo->pt.y)
    43744343  {
    43754344    lpHitTestInfo->flags |= LVHT_ABOVE;
    4376   } 
     4345  }
    43774346  else if (infoPtr->rcList.bottom < lpHitTestInfo->pt.y)
    43784347  {
     
    44054374{
    44064375  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    4407   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
    44084376  HDITEMA hdi;
    44094377  INT nNewColumn = -1;
    44104378
    4411 //  TRACE(listview,"(hwnd=%x,nColumn=%d,lpColumn=%p)\n",hwnd, nColumn, lpColumn);
     4379  TRACE("(hwnd=%x, nColumn=%d, lpColumn=%p)\n",hwnd, nColumn,
     4380        lpColumn);
    44124381
    44134382  if (lpColumn != NULL)
     
    44904459                             (WPARAM)nColumn, (LPARAM)&hdi);
    44914460
    4492     LISTVIEW_SetScroll(hwnd, lStyle);
     4461    LISTVIEW_UpdateScroll(hwnd);
    44934462    InvalidateRect(hwnd, NULL, FALSE);
    44944463  }
     
    45154484  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    45164485  LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     4486  UINT uView = lStyle & LVS_TYPEMASK;
    45174487  LONG lCtrlId = GetWindowLongA(hwnd, GWL_ID);
    45184488  NMLISTVIEW nmlv;
     
    45214491  LISTVIEW_ITEM *lpItem = NULL;
    45224492
    4523 //  TRACE(listview, "(hwnd=%x,lpLVItem=%p)\n", hwnd, lpLVItem);
     4493  TRACE("(hwnd=%x,lpLVItem=%p)\n", hwnd, lpLVItem);
    45244494
    45254495  if (lpLVItem != NULL)
     
    45644534               
    45654535                /* align items (set position of each item) */
    4566                 switch (lStyle & LVS_TYPEMASK)
     4536                if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
    45674537                {
    4568                 case LVS_ICON:
    4569                 case LVS_SMALLICON:
    45704538                  if (lStyle & LVS_ALIGNLEFT)
    45714539                  {
     
    45764544                    LISTVIEW_AlignTop(hwnd);
    45774545                  }
    4578                   break;
    45794546                }
    4580 
    4581                 LISTVIEW_SetScroll(hwnd, lStyle);
     4547               
     4548                LISTVIEW_UpdateScroll(hwnd);
    45824549                /* refresh client area */
    45834550                InvalidateRect(hwnd, NULL, FALSE);
     
    48034770    LONG lStyle;
    48044771
    4805     /* set column width only if in report mode */
     4772    // set column width only if in report mode
    48064773    lStyle = GetWindowLongA(hwnd, GWL_STYLE);
    48074774    if ((lStyle & LVS_TYPEMASK) != LVS_REPORT)
    48084775        return (FALSE);
    48094776
    4810     /* make sure we can get the listview info */
     4777    // make sure we can get the listview info
    48114778    if (!(infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0)))
    48124779        return (FALSE); 
    4813     if (!infoPtr->hwndHeader) /* make sure we have a header */
     4780    if (!infoPtr->hwndHeader) // make sure we have a header
    48144781        return (FALSE);
    48154782       
    4816     /*
    4817      * FIXME: currently ignoring LVSCW_AUTOSIZE (-1) and
    4818      * LVSCV_AUTOSIZE_USEHEADER (-2)
    4819      */
     4783    // FIXME: currently ignoring LVSCW_AUTOSIZE (-1) and
     4784    // LVSCV_AUTOSIZE_USEHEADER (-2)
    48204785    if (cx < 0)
    48214786        return (FALSE);
     
    48244789    hdi.cxy = cx;
    48254790
    4826     /* call header to update the column change */
     4791    // call header to update the column change
    48274792    lret = Header_SetItemA(infoPtr->hwndHeader, (WPARAM)iCol, (LPARAM)&hdi);
    48284793
    4829     infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd, LVS_REPORT);
    4830 
    4831     InvalidateRect(hwnd, NULL, TRUE); /* force redraw of the listview */
     4794    infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd);
     4795
     4796    InvalidateRect(hwnd, NULL, TRUE); // force redraw of the listview
    48324797
    48334798    return lret;
     
    48674832    himlTemp = infoPtr->himlState;
    48684833    infoPtr->himlState = himl;
     4834    ImageList_SetBkColor(infoPtr->himlState, CLR_NONE);
    48694835    return (LRESULT)himlTemp;
    48704836  }
     
    49254891static VOID LISTVIEW_SetItemCount(HWND hwnd, INT nItemCount)
    49264892{
    4927 //  FIXME (listview, "empty stub!\n");
     4893  FIXME("empty stub!\n");
    49284894}
    49294895
     
    49464912{
    49474913  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongA(hwnd, 0);
    4948   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     4914  UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    49494915  LISTVIEW_ITEM *lpItem;
    49504916  HDPA hdpaSubItems;
    49514917  BOOL bResult = FALSE;
    49524918
    4953 //  TRACE(listview, "(hwnd=%x,nItem=%d,X=%d,Y=%d)\n", hwnd, nItem, nPosX, nPosY);
     4919  TRACE("(hwnd=%x,nItem=%d,X=%d,Y=%d)\n", hwnd, nItem, nPosX, nPosY);
    49544920
    49554921  if ((nItem >= 0) || (nItem < GETITEMCOUNT(infoPtr)))
    49564922  {
    4957     switch (lStyle & LVS_TYPEMASK)
    4958     {
    4959     case LVS_ICON:
    4960     case LVS_SMALLICON:
     4923    if ((uView == LVS_ICON) || (uView == LVS_SMALLICON))
     4924    {
    49614925      hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, nItem);
    49624926      if (hdpaSubItems != NULL)
     
    49704934        }
    49714935      }
    4972       break;
    49734936    }
    49744937  }
     
    50034966    lvItem.mask = LVIF_STATE;
    50044967    lvItem.state = lpLVItem->state;
    5005     lvItem.stateMask = lpLVItem->stateMask;
     4968    lvItem.stateMask = lpLVItem->stateMask ;
    50064969   
    50074970    /* apply to all items */
     
    51045067}
    51055068
     5069
     5070/***
     5071 * DESCRIPTION:
     5072 * Callback internally used by LISTVIEW_SortItems()
     5073 *
     5074 * PARAMETER(S):
     5075 * [I] LPVOID : first LISTVIEW_ITEM to compare
     5076 * [I] LPVOID : second LISTVIEW_ITEM to compare
     5077 * [I] LPARAM : HWND of control
     5078 *
     5079 * RETURN:
     5080 *   if first comes before second : negative
     5081 *   if first comes after second : positive
     5082 *   if first and second are equivalent : zero
     5083 */
     5084static INT WINAPI LISTVIEW_CallBackCompare(
     5085  LPVOID first,
     5086  LPVOID second,
     5087  LPARAM lParam)
     5088{
     5089  /* Forward the call to the client defined callback */
     5090  HWND hwnd = (HWND)lParam;
     5091  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     5092
     5093  return (infoPtr->pfnCompare)(
     5094    ((LISTVIEW_ITEM *)first)->lParam,
     5095    ((LISTVIEW_ITEM *)second)->lParam,
     5096    infoPtr->lParamSort);
     5097}
     5098
    51065099/***
    51075100 * DESCRIPTION:
     
    51105103 * PARAMETER(S):
    51115104 * [I] HWND : window handle
     5105 * [I] WPARAM : application-defined value
     5106 * [I] LPARAM : pointer to comparision callback
    51125107 *
    51135108 * RETURN:
     
    51175112static LRESULT LISTVIEW_SortItems(HWND hwnd, WPARAM wParam, LPARAM lParam)
    51185113{
    5119 //  FIXME (listview, "empty stub!\n");
    5120 
    5121   return TRUE;
     5114    LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     5115    HDPA hdpaSubItems;
     5116    LISTVIEW_ITEM *lpItem;
     5117    int nCount, i;
     5118    HDPA sortList;
     5119   
     5120    if (!infoPtr || !infoPtr->hdpaItems)
     5121        return FALSE;
     5122   
     5123    nCount = GETITEMCOUNT(infoPtr);
     5124    // if there are 0 or 1 items, there is no need to sort
     5125    if (nCount > 1)
     5126    {
     5127        sortList = DPA_Create(nCount);
     5128
     5129        infoPtr->pfnCompare = (PFNLVCOMPARE)lParam;
     5130        infoPtr->lParamSort = (LPARAM)wParam;
     5131       
     5132        // append pointers one by one to sortList
     5133        for (i = 0; i < nCount; i++)
     5134        {
     5135            if ((hdpaSubItems = (HDPA) DPA_GetPtr(infoPtr->hdpaItems, i)))
     5136                if ((lpItem = (LISTVIEW_ITEM *) DPA_GetPtr(hdpaSubItems, 0)))
     5137                    DPA_InsertPtr(sortList, nCount + 1, lpItem);
     5138        }
     5139
     5140        // sort the sortList
     5141        DPA_Sort(sortList, LISTVIEW_CallBackCompare, hwnd);
     5142
     5143        // copy the pointers back
     5144        for (i = 0; i < nCount; i++)
     5145        {
     5146            if ((hdpaSubItems = (HDPA) DPA_GetPtr(infoPtr->hdpaItems, i)) &&
     5147                (lpItem = (LISTVIEW_ITEM *) DPA_GetPtr(sortList, i)))
     5148                DPA_SetPtr(hdpaSubItems, 0, lpItem);
     5149        }
     5150
     5151        DPA_Destroy(sortList);
     5152    }
     5153
     5154    return TRUE;
    51225155}
    51235156
     
    51565189      rc.left = LVIR_BOUNDS;
    51575190      ListView_GetItemRect(hwnd, nItem, &rc);
    5158       InvalidateRect(hwnd, &rc, FALSE);
     5191      InvalidateRect(hwnd, &rc, TRUE);
    51595192    }
    51605193  }
     
    51775210  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    51785211  LPCREATESTRUCTA lpcs = (LPCREATESTRUCTA)lParam;
     5212  UINT uView = lpcs->style & LVS_TYPEMASK;
    51795213  LOGFONTA logFont;
    51805214
     
    51875221  if (infoPtr->notifyFormat != NFR_ANSI)
    51885222  {
    5189 //    FIXME (listview, "ANSI notify format is NOT used\n");
     5223    FIXME("ANSI notify format is NOT used\n");
    51905224  }
    51915225 
     
    52175251  SendMessageA(infoPtr->hwndHeader, WM_SETFONT, (WPARAM)infoPtr->hFont,
    52185252               (LPARAM)TRUE);
    5219 
    52205253 
    5221   switch (lpcs->style & LVS_TYPEMASK)
    5222   {
    5223   case LVS_ICON:
     5254  if (uView == LVS_ICON)
     5255  {
    52245256    infoPtr->iconSize.cx = GetSystemMetrics(SM_CXICON);
    52255257    infoPtr->iconSize.cy = GetSystemMetrics(SM_CYICON);
    5226     break;
    5227 
    5228   case LVS_REPORT:
    5229     ShowWindow(infoPtr->hwndHeader, SW_SHOWNORMAL);
    5230   case LVS_SMALLICON:
    5231   case LVS_LIST:
     5258  }
     5259  else if (uView == LVS_REPORT)
     5260  {
     5261    if (!(LVS_NOCOLUMNHEADER & lpcs->style))
     5262    {
     5263      ShowWindow(infoPtr->hwndHeader, SW_SHOWNORMAL);
     5264    }
     5265
    52325266    infoPtr->iconSize.cx = GetSystemMetrics(SM_CXSMICON);
    52335267    infoPtr->iconSize.cy = GetSystemMetrics(SM_CYSMICON);
    5234     break;
     5268  }
     5269  else
     5270  {
     5271    infoPtr->iconSize.cx = GetSystemMetrics(SM_CXSMICON);
     5272    infoPtr->iconSize.cy = GetSystemMetrics(SM_CYSMICON);
    52355273  }
    52365274
     
    52425280
    52435281  /* initialize size of items */
    5244   infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd, lpcs->style);
    5245   infoPtr->nItemHeight = LISTVIEW_GetItemHeight(hwnd, lpcs->style);
     5282  infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd);
     5283  infoPtr->nItemHeight = LISTVIEW_GetItemHeight(hwnd);
    52465284
    52475285  return 0;
     
    53085346 * [I] HWND : window handle
    53095347 * [I] INT : scroll code
    5310  * [I] INT : scroll position
     5348 * [I] SHORT : current scroll position if scroll code is SB_THIMBPOSITION
     5349 *             or SB_THUMBTRACK.
    53115350 * [I] HWND : scrollbar control window handle
    53125351 *
     
    53145353 * Zero
    53155354 */
    5316 static LRESULT LISTVIEW_VScroll(HWND hwnd, INT nScrollCode, INT nScroll,
     5355static LRESULT LISTVIEW_VScroll(HWND hwnd, INT nScrollCode, SHORT nCurrentPos,
    53175356                                HWND hScrollWnd)
    53185357{
    5319   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    5320   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
    5321   INT nScrollPosInc = 0;
    5322   INT nScrollPos;
    5323   INT nMinRange;
    5324   INT nMaxRange;
    5325 
    5326   GetScrollRange(hwnd, SB_VERT, &nMinRange, &nMaxRange);
    5327   nScrollPos = GetScrollPos(hwnd, SB_VERT);
    5328 
    5329   switch (nScrollCode)
    5330   {
    5331   case SB_LINEUP:
    5332     if (nScrollPos > nMinRange)
    5333     {
    5334       nScrollPosInc = -1;
    5335     }
     5358  UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
     5359  SCROLLINFO scrollInfo;
     5360
     5361  ZeroMemory(&scrollInfo, sizeof(SCROLLINFO));
     5362  scrollInfo.cbSize = sizeof(SCROLLINFO);
     5363  scrollInfo.fMask = /*SIF_PAGE |*/ SIF_POS | SIF_RANGE;
     5364 
     5365  if (GetScrollInfo(hwnd, SB_VERT, &scrollInfo) != FALSE)
     5366  {
     5367    INT nOldScrollPos = scrollInfo.nPos;
     5368    switch (nScrollCode)
     5369    {
     5370    case SB_LINEUP:
     5371      if (scrollInfo.nPos > scrollInfo.nMin)
     5372      {
     5373        scrollInfo.nPos--;
     5374      }
    53365375    break;
    53375376   
    5338   case SB_LINEDOWN:
    5339     if (nScrollPos < nMaxRange)
    5340     {
    5341       nScrollPosInc = 1;
    5342     }
    5343     break;
    5344 
    5345   case SB_PAGEUP:
    5346     switch (LVS_TYPEMASK & lStyle)
    5347     {
    5348     case LVS_REPORT:
    5349       if (nScrollPos > nMinRange + infoPtr->nCountPerColumn)
    5350       {
    5351         nScrollPosInc = -infoPtr->nCountPerColumn;
    5352       }
    5353       else
    5354       {
    5355         nScrollPosInc = nMinRange - nScrollPos;
    5356       }
    5357       break;
    5358 
    5359     case LVS_SMALLICON:
    5360     case LVS_ICON:
    5361       if (nScrollPos > nMinRange + 10)
    5362       {
    5363         nScrollPosInc = -10;
    5364       }
    5365       else
    5366       {
    5367         nScrollPosInc = nMinRange - nScrollPos;
    5368       }
    5369       break;
    5370     }
    5371     break;
    5372 
    5373    case SB_PAGEDOWN:
    5374      switch (LVS_TYPEMASK & lStyle)
    5375      {
    5376      case LVS_REPORT:
    5377        if (nScrollPos < nMaxRange - infoPtr->nCountPerColumn)
    5378        {
    5379          nScrollPosInc = infoPtr->nCountPerColumn;
    5380        }
    5381        else
    5382        {
    5383          nScrollPosInc = nMaxRange - nScrollPos;
    5384        }
    5385        break;
    5386 
    5387      case LVS_SMALLICON:
    5388      case LVS_ICON:
    5389        if (nScrollPos < nMaxRange - 10)
    5390        {
    5391          nScrollPosInc = 10;
    5392        }
    5393        else
    5394        {
    5395          nScrollPosInc = nMaxRange - nScrollPos;
    5396        }
    5397        break;
    5398      }
    5399      break;
    5400 
    5401    case SB_THUMBPOSITION:
    5402      nScrollPosInc = nScroll - nScrollPos;
    5403     break;
    5404   }
    5405 
    5406   if (nScrollPosInc != 0)
    5407   {
    5408     LISTVIEW_ScrollView(hwnd, 0, nScrollPosInc);
    5409   }
    5410 
    5411   return 0;
    5412 }
    5413 
    5414 
    5415 /***
    5416  * DESCRIPTION:
    5417  * Performs horizontal scrolling.
    5418  *
    5419  * PARAMETER(S):
    5420  * [I] HWND : window handle
    5421  * [I] INT : scroll code
    5422  * [I] INT : scroll position
    5423  * [I] HWND : scrollbar control window handle
    5424  *
    5425  * RETURN:
    5426  * Zero
    5427  */
    5428 static LRESULT LISTVIEW_HScroll(HWND hwnd, INT nScrollCode,
    5429                                 INT nScroll, HWND hScrollWnd)
    5430 {
    5431   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    5432   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
    5433   INT nScrollPosInc = 0;
    5434   INT nScrollPos;
    5435   INT nMinRange;
    5436   INT nMaxRange;
    5437 
    5438   GetScrollRange(hwnd, SB_HORZ, &nMinRange, &nMaxRange);
    5439   nScrollPos = GetScrollPos(hwnd, SB_HORZ);
    5440 
    5441   switch (nScrollCode)
    5442   {
    5443   case SB_LINELEFT:
    5444     if (nScrollPos > nMinRange)
    5445     {
    5446       nScrollPosInc = -1;
    5447     }
    5448     break;
    5449 
    5450   case SB_LINERIGHT:
    5451     if (nScrollPos < nMaxRange)
    5452     {
    5453       nScrollPosInc = 1;
    5454     }
    5455     break;
    5456 
    5457   case SB_PAGELEFT:
    5458     switch (LVS_TYPEMASK & lStyle)
    5459     {
    5460     case LVS_LIST:
    5461       if (nScrollPos > nMinRange + infoPtr->nCountPerRow)
    5462       {
    5463         nScrollPosInc = -infoPtr->nCountPerRow;
    5464       }
    5465       else
    5466       {
    5467         nScrollPosInc = nMinRange - nScrollPos;
    5468       }
    5469       break;
    5470 
    5471     case LVS_REPORT:
    5472     case LVS_SMALLICON:
    5473     case LVS_ICON:
    5474       if (nScrollPos > nMinRange + 10)
    5475       {
    5476         nScrollPosInc = -10;
    5477       }
    5478       else
    5479       {
    5480         nScrollPosInc = nMinRange - nScrollPos;
    5481       }
    5482       break;
    5483     }
    5484     break;
    5485 
    5486   case SB_PAGERIGHT:
    5487     switch (LVS_TYPEMASK & lStyle)
    5488     {
    5489     case LVS_LIST:
    5490       if (nScrollPos < nMaxRange - infoPtr->nCountPerRow)
    5491       {
    5492         nScrollPosInc = infoPtr->nCountPerRow;
    5493       }
    5494       else
    5495       {
    5496         nScrollPosInc = nMaxRange - nScrollPos;
     5377    case SB_LINEDOWN:
     5378      if (scrollInfo.nPos < scrollInfo.nMax)
     5379      {
     5380        scrollInfo.nPos++;
    54975381      }
    54985382      break;
    54995383     
    5500     case LVS_REPORT:
    5501     case LVS_SMALLICON:
    5502     case LVS_ICON:
    5503       if (nScrollPos < nMaxRange - 10)
    5504       {
    5505         nScrollPosInc = 10;
    5506       }
    5507       else
    5508       {
    5509         nScrollPosInc = nMaxRange - nScrollPos;
     5384    case SB_PAGEUP:
     5385      if (scrollInfo.nPos > scrollInfo.nMin)
     5386      {
     5387        INT nPage = 0;
     5388
     5389        if (uView == LVS_REPORT)
     5390        {
     5391          nPage = LISTVIEW_GetCountPerColumn(hwnd);
     5392        }
     5393        else if ((uView == LVS_ICON) || (uView == LVS_SMALLICON))
     5394        {
     5395          nPage = 10;
     5396        }
     5397
     5398        if (scrollInfo.nPos >= nPage)
     5399        {
     5400          scrollInfo.nPos -= nPage;
     5401        }
     5402        else
     5403        {
     5404          scrollInfo.nPos = scrollInfo.nMin;
     5405        }
    55105406      }
    55115407      break;
    5512     }
    5513     break;
    5514 
    5515   case SB_THUMBPOSITION:
    5516     nScrollPosInc = nScroll - nScrollPos;
    5517     break;
    5518   }
    5519 
    5520   if (nScrollPosInc != 0)
    5521   {
    5522     LISTVIEW_ScrollView(hwnd, nScrollPosInc, 0);
    5523   }
    5524 
     5408     
     5409    case SB_PAGEDOWN:
     5410      if (scrollInfo.nPos < scrollInfo.nMax)
     5411      {
     5412        INT nPage = 0;
     5413
     5414        if (uView == LVS_REPORT)
     5415        {
     5416          nPage = LISTVIEW_GetCountPerColumn(hwnd);
     5417        }
     5418        else if ((uView == LVS_ICON) || (uView == LVS_SMALLICON))
     5419        {
     5420          nPage = 10;
     5421        }
     5422       
     5423        if (scrollInfo.nPos <= scrollInfo.nMax - nPage)
     5424        {
     5425          scrollInfo.nPos += nPage;
     5426        }
     5427        else
     5428        {
     5429          scrollInfo.nPos = scrollInfo.nMax;
     5430        }
     5431      }
     5432      break;
     5433
     5434    case SB_THUMBPOSITION:
     5435      break;
     5436    }
     5437
     5438    if (nOldScrollPos != scrollInfo.nPos)
     5439    {
     5440      scrollInfo.fMask = SIF_POS;
     5441      SetScrollInfo(hwnd, SB_VERT, &scrollInfo, TRUE);
     5442      InvalidateRect(hwnd, NULL, TRUE);
     5443    }
     5444  }
     5445   
     5446  return 0;
     5447}
     5448
     5449/***
     5450 * DESCRIPTION:
     5451 * Performs horizontal scrolling.
     5452 *
     5453 * PARAMETER(S):
     5454 * [I] HWND : window handle
     5455 * [I] INT : scroll code
     5456 * [I] SHORT : current scroll position if scroll code is SB_THIMBPOSITION
     5457 *             or SB_THUMBTRACK.
     5458 * [I] HWND : scrollbar control window handle
     5459 *
     5460 * RETURN:
     5461 * Zero
     5462 */
     5463static LRESULT LISTVIEW_HScroll(HWND hwnd, INT nScrollCode, SHORT nCurrentPos,
     5464                                HWND hScrollWnd)
     5465{
     5466  UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
     5467  SCROLLINFO scrollInfo;
     5468
     5469  ZeroMemory(&scrollInfo, sizeof(SCROLLINFO));
     5470  scrollInfo.cbSize = sizeof(SCROLLINFO);
     5471  scrollInfo.fMask = /*SIF_PAGE |*/ SIF_POS | SIF_RANGE;
     5472 
     5473  if (GetScrollInfo(hwnd, SB_HORZ, &scrollInfo) != FALSE)
     5474  {
     5475    INT nOldScrollPos = scrollInfo.nPos;
     5476
     5477    switch (nScrollCode)
     5478    {
     5479    case SB_LINELEFT:
     5480      if (scrollInfo.nPos > scrollInfo.nMin)
     5481      {
     5482        scrollInfo.nPos--;
     5483      }
     5484      break;
     5485   
     5486    case SB_LINERIGHT:
     5487      if (scrollInfo.nPos < scrollInfo.nMax)
     5488      {
     5489        scrollInfo.nPos++;
     5490      }
     5491      break;
     5492     
     5493    case SB_PAGELEFT:
     5494      if (scrollInfo.nPos > scrollInfo.nMin)
     5495      {
     5496        INT nPage = 0;
     5497
     5498        if (uView == LVS_LIST)
     5499        {
     5500          nPage = LISTVIEW_GetCountPerRow(hwnd);
     5501        }
     5502        else if ((uView == LVS_ICON) || (uView == LVS_SMALLICON))
     5503        {
     5504          nPage = 10;
     5505        }
     5506       
     5507        if (scrollInfo.nPos >= nPage)
     5508        {
     5509          scrollInfo.nPos -= nPage;
     5510        }
     5511        else
     5512        {
     5513          scrollInfo.nPos = scrollInfo.nMin;
     5514        }
     5515      }
     5516      break;
     5517     
     5518    case SB_PAGERIGHT:
     5519      if (scrollInfo.nPos < scrollInfo.nMax)
     5520      {
     5521        INT nPage = 0;
     5522
     5523        if (uView == LVS_LIST)
     5524        {
     5525          nPage = LISTVIEW_GetCountPerRow(hwnd);
     5526        }
     5527        else if ((uView == LVS_ICON) || (uView == LVS_SMALLICON))
     5528        {
     5529          nPage = 10;
     5530        }
     5531       
     5532        if (scrollInfo.nPos <= scrollInfo.nMax - nPage)
     5533        {
     5534          scrollInfo.nPos += nPage;
     5535        }
     5536        else
     5537        {
     5538          scrollInfo.nPos = scrollInfo.nMax;
     5539        }
     5540      }
     5541      break;
     5542
     5543    case SB_THUMBPOSITION:
     5544      break;
     5545    }
     5546
     5547    if (nOldScrollPos != scrollInfo.nPos)
     5548    {
     5549      scrollInfo.fMask = SIF_POS;
     5550      SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE);
     5551      InvalidateRect(hwnd, NULL, TRUE);
     5552    }
     5553  }
     5554   
    55255555  return 0;
    55265556}
     
    55415571{
    55425572  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    5543   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
    55445573  INT nCtrlId = GetWindowLongA(hwnd, GWL_ID);
    5545   INT nCountPerColumn;
    5546   INT nCountPerRow;
    55475574  HWND hwndParent = GetParent(hwnd);
    55485575  NMLVKEYDOWN nmKeyDown;
    55495576  NMHDR nmh;
    5550   INT oldFocusedItem = infoPtr->nFocusedItem;
     5577  INT nItem = -1;
     5578  BOOL bRedraw = FALSE;
    55515579
    55525580  /* send LVN_KEYDOWN notification */
     
    55815609    if (GETITEMCOUNT(infoPtr) > 0)
    55825610    {
    5583       LISTVIEW_KeySelection(hwnd, 0);
     5611      nItem = 0;
    55845612    }
    55855613    break;
     
    55885616    if (GETITEMCOUNT(infoPtr) > 0)
    55895617    {
    5590       LISTVIEW_KeySelection(hwnd, GETITEMCOUNT(infoPtr) - 1);
     5618      nItem = GETITEMCOUNT(infoPtr) - 1;
    55915619    }
    55925620    break;
    55935621
    55945622  case VK_LEFT:
    5595     switch (LVS_TYPEMASK & lStyle)
    5596     {
    5597     case LVS_LIST:
    5598       if (infoPtr->nFocusedItem >= infoPtr->nCountPerColumn)
    5599       {
    5600         LISTVIEW_KeySelection(hwnd, infoPtr->nFocusedItem -
    5601                               infoPtr->nCountPerColumn);
    5602       }
    5603       break;
    5604 
    5605     case LVS_SMALLICON:
    5606     case LVS_ICON:
    5607       if (lStyle & LVS_ALIGNLEFT)
    5608       {
    5609         nCountPerColumn = max((infoPtr->rcList.bottom - infoPtr->rcList.top) /
    5610                               infoPtr->nItemHeight, 1);
    5611         if (infoPtr->nFocusedItem >= nCountPerColumn)
    5612         {
    5613           LISTVIEW_KeySelection(hwnd, infoPtr->nFocusedItem - nCountPerColumn);
    5614         }
    5615       }
    5616       else
    5617       {
    5618         nCountPerRow = max((infoPtr->rcList.right - infoPtr->rcList.left) /
    5619                            infoPtr->nItemWidth, 1);
    5620         if (infoPtr->nFocusedItem % nCountPerRow != 0)
    5621         {
    5622           LISTVIEW_SetSelection(hwnd, infoPtr->nFocusedItem - 1);
    5623         }
    5624       }
    5625       break;
    5626     }
     5623    nItem = LISTVIEW_GetNextItem(hwnd, infoPtr->nFocusedItem, LVNI_TOLEFT);
    56275624    break;
    5628  
     5625
    56295626  case VK_UP:
    5630     switch (LVS_TYPEMASK & lStyle)
    5631     {
    5632     case LVS_LIST:
    5633     case LVS_REPORT:
    5634       if (infoPtr->nFocusedItem > 0)
    5635       {
    5636         LISTVIEW_KeySelection(hwnd, infoPtr->nFocusedItem - 1);
    5637       }
    5638       break;
    5639 
    5640     default:
    5641       if (lStyle & LVS_ALIGNLEFT)
    5642       {
    5643         nCountPerColumn = max((infoPtr->rcList.bottom - infoPtr->rcList.top) /
    5644                               infoPtr->nItemHeight, 1);
    5645         if (infoPtr->nFocusedItem % nCountPerColumn != 0)
    5646         {
    5647           LISTVIEW_KeySelection(hwnd, infoPtr->nFocusedItem - 1);
    5648         }
    5649       }
    5650       else
    5651       {
    5652         nCountPerRow = max((infoPtr->rcList.right - infoPtr->rcList.left) /
    5653                            infoPtr->nItemWidth, 1);
    5654         if (infoPtr->nFocusedItem >= nCountPerRow)
    5655         {
    5656           LISTVIEW_KeySelection(hwnd, infoPtr->nFocusedItem - nCountPerRow);
    5657         }
    5658       }
    5659     }
     5627    nItem = LISTVIEW_GetNextItem(hwnd, infoPtr->nFocusedItem, LVNI_ABOVE);
    56605628    break;
    56615629   
    56625630  case VK_RIGHT:
    5663     switch (LVS_TYPEMASK & lStyle)
    5664     {
    5665     case LVS_LIST:
    5666       if (infoPtr->nFocusedItem < GETITEMCOUNT(infoPtr) -
    5667           infoPtr->nCountPerColumn)
    5668       {
    5669         LISTVIEW_KeySelection(hwnd, infoPtr->nFocusedItem +
    5670                               infoPtr->nCountPerColumn);
    5671       }
    5672       break;
    5673 
    5674     case LVS_ICON:
    5675     case LVS_SMALLICON:
    5676       if (lStyle & LVS_ALIGNLEFT)
    5677       {
    5678         nCountPerColumn = max((infoPtr->rcList.bottom - infoPtr->rcList.top) /
    5679                               infoPtr->nItemHeight, 1);
    5680         if (infoPtr->nFocusedItem < GETITEMCOUNT(infoPtr) - nCountPerColumn)
    5681         {
    5682           LISTVIEW_KeySelection(hwnd, infoPtr->nFocusedItem + nCountPerColumn);
    5683         }
    5684       }
    5685       else
    5686       {
    5687         nCountPerRow = max((infoPtr->rcList.right - infoPtr->rcList.left) /
    5688                            infoPtr->nItemWidth, 1);
    5689         if ((infoPtr->nFocusedItem % nCountPerRow != nCountPerRow - 1) &&
    5690             (infoPtr->nFocusedItem < GETITEMCOUNT(infoPtr) - 1))
    5691         {
    5692           LISTVIEW_KeySelection(hwnd, infoPtr->nFocusedItem + 1);
    5693         }
    5694       }
    5695     }
     5631    nItem = LISTVIEW_GetNextItem(hwnd, infoPtr->nFocusedItem, LVNI_TORIGHT);
    56965632    break;
    56975633
    56985634  case VK_DOWN:
    5699     switch (LVS_TYPEMASK & lStyle)
    5700     {
    5701     case LVS_LIST:
    5702     case LVS_REPORT:
    5703       if (infoPtr->nFocusedItem < GETITEMCOUNT(infoPtr) - 1)
    5704       {
    5705         LISTVIEW_KeySelection(hwnd, infoPtr->nFocusedItem + 1);
    5706       }
    5707       break;
    5708 
    5709     case LVS_SMALLICON:
    5710     case LVS_ICON:
    5711       if (lStyle & LVS_ALIGNLEFT)
    5712       {
    5713         nCountPerColumn = max((infoPtr->rcList.bottom - infoPtr->rcList.top) /
    5714                               infoPtr->nItemHeight, 1);
    5715         if (infoPtr->nFocusedItem % nCountPerColumn != nCountPerColumn - 1)
    5716         {
    5717           LISTVIEW_KeySelection(hwnd, infoPtr->nFocusedItem + 1);
    5718         }
    5719       }
    5720       else
    5721       {
    5722         nCountPerRow = max((infoPtr->rcList.right - infoPtr->rcList.left) /
    5723                            infoPtr->nItemWidth, 1);
    5724         if (infoPtr->nFocusedItem < GETITEMCOUNT(infoPtr) - nCountPerRow)
    5725         {
    5726           LISTVIEW_KeySelection(hwnd, infoPtr->nFocusedItem + nCountPerRow);
    5727         }
    5728       }
    5729     }
     5635    nItem = LISTVIEW_GetNextItem(hwnd, infoPtr->nFocusedItem, LVNI_BELOW);
    57305636    break;
    57315637
    57325638  case VK_PRIOR:
     5639    /* TO DO */
    57335640    break;
    57345641
    57355642  case VK_NEXT:
     5643    /* TO DO */
    57365644    break;
    57375645  }
    57385646
    5739   /* refresh client area if necessary*/
    5740   if(oldFocusedItem != infoPtr->nFocusedItem)
    5741     InvalidateRect(hwnd, NULL, TRUE);
     5647  if ((nItem != -1) && (nItem != infoPtr->nFocusedItem))
     5648  {
     5649    bRedraw = LISTVIEW_KeySelection(hwnd, nItem);
     5650    if (bRedraw != FALSE)
     5651    {
     5652      /* refresh client area */
     5653      InvalidateRect(hwnd, NULL, TRUE);
     5654      UpdateWindow(hwnd);
     5655    }
     5656  }
    57425657
    57435658  return 0;
     
    57695684  infoPtr->bFocus = FALSE;
    57705685
     5686  /* NEED drawing optimization ; redraw the selected items */
     5687  InvalidateRect(hwnd, NULL, FALSE);
     5688
    57715689  return 0;
    57725690}
     
    57915709  NMHDR nmh;
    57925710
    5793 //  TRACE(listview, "(hwnd=%x,key=%hu,X=%hu,Y=%hu)\n", hwnd, wKey, wPosX, wPosY);
     5711  TRACE("(hwnd=%x,key=%hu,X=%hu,Y=%hu)\n", hwnd, wKey, wPosX, wPosY);
    57945712
    57955713  /* send NM_DBLCLK notification */
     
    58235741{
    58245742  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     5743  LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
    58255744  INT nCtrlId = GetWindowLongA(hwnd, GWL_ID);
    58265745  static BOOL bGroupSelect = TRUE;
     5746  POINT ptPosition;
    58275747  NMHDR nmh;
    58285748  INT nItem;
    58295749
    5830 //  TRACE(listview, "(hwnd=%x,key=%hu,X=%hu,Y=%hu)\n", hwnd, wKey, wPosX, wPosY);
     5750  TRACE("(hwnd=%x, key=%hu, X=%hu, Y=%hu)\n", hwnd, wKey, wPosX,
     5751        wPosY);
    58315752
    58325753  /* send NM_RELEASEDCAPTURE notification */
     
    58435764  /* set left button down flag */
    58445765  infoPtr->bLButtonDown = TRUE;
    5845 
    5846   nItem = LISTVIEW_MouseSelection(hwnd, wPosX, wPosY);
     5766 
     5767  ptPosition.x = wPosX;
     5768  ptPosition.y = wPosY;
     5769  nItem = LISTVIEW_MouseSelection(hwnd, ptPosition);
    58475770  if ((nItem >= 0) && (nItem < GETITEMCOUNT(infoPtr)))
    58485771  {
    5849     if ((wKey & MK_CONTROL) && (wKey & MK_SHIFT))
    5850     {
    5851       if (bGroupSelect != FALSE)
    5852       {
    5853         LISTVIEW_AddGroupSelection(hwnd, nItem);
     5772    if (lStyle & LVS_SINGLESEL)
     5773    {
     5774      LISTVIEW_SetSelection(hwnd, nItem);
     5775    }
     5776    else
     5777    {
     5778      if ((wKey & MK_CONTROL) && (wKey & MK_SHIFT))
     5779      {
     5780        if (bGroupSelect != FALSE)
     5781        {
     5782          LISTVIEW_AddGroupSelection(hwnd, nItem);
     5783        }
     5784        else
     5785        {
     5786          LISTVIEW_AddSelection(hwnd, nItem);
     5787        }
     5788      }
     5789      else if (wKey & MK_CONTROL)
     5790      {
     5791        bGroupSelect = LISTVIEW_ToggleSelection(hwnd, nItem);
     5792      }
     5793      else  if (wKey & MK_SHIFT)
     5794      {
     5795        LISTVIEW_SetGroupSelection(hwnd, nItem);
    58545796      }
    58555797      else
    58565798      {
    5857         LISTVIEW_AddSelection(hwnd, nItem);
    5858       }
    5859     }
    5860     else if (wKey & MK_CONTROL)
    5861     {
    5862       bGroupSelect = LISTVIEW_ToggleSelection(hwnd, nItem);
    5863     }
    5864     else  if (wKey & MK_SHIFT)
    5865     {
    5866       LISTVIEW_SetGroupSelection(hwnd, nItem);
    5867     }
    5868     else
    5869     {
    5870       LISTVIEW_SetSelection(hwnd, nItem);
     5799        LISTVIEW_SetSelection(hwnd, nItem);
     5800      }
    58715801    }
    58725802  }
     
    59005830  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    59015831
    5902 //  TRACE(listview, "(hwnd=%x,key=%hu,X=%hu,Y=%hu)\n", hwnd, wKey, wPosX, wPosY);
     5832  TRACE("(hwnd=%x,key=%hu,X=%hu,Y=%hu)\n", hwnd, wKey, wPosX, wPosY);
    59035833
    59045834  if (infoPtr->bLButtonDown != FALSE)
     
    59365866  LISTVIEW_INFO *infoPtr;
    59375867
    5938 //  TRACE(listview, "(hwnd=%x,wParam=%x,lParam=%lx)\n", hwnd, wParam, lParam);
     5868  TRACE("(hwnd=%x,wParam=%x,lParam=%lx)\n", hwnd, wParam, lParam);
    59395869
    59405870  /* allocate memory for info structure */
     
    59435873  if (infoPtr == NULL)
    59445874  {
    5945 //    ERR(listview, "could not allocate info memory!\n");
     5875    ERR("could not allocate info memory!\n");
    59465876    return 0;
    59475877  }
     
    59495879  if ((LISTVIEW_INFO *)GetWindowLongA(hwnd, 0) != infoPtr)
    59505880  {
    5951 //    ERR(listview, "pointer assignment error!\n");
     5881    ERR("pointer assignment error!\n");
    59525882    return 0;
    59535883  }
     
    59705900  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    59715901
    5972 //  TRACE(listview, "(hwnd=%x)\n", hwnd);
     5902  TRACE("(hwnd=%x)\n", hwnd);
    59735903
    59745904  /* delete all items */
     
    60125942    if (lpnmh->code == HDN_ENDTRACKA)
    60135943    {
    6014       infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd, LVS_REPORT);
     5944      infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd);
    60155945      InvalidateRect(hwnd, NULL, TRUE);
    60165946    }
     
    60435973    if (infoPtr->notifyFormat == NFR_UNICODE)
    60445974    {
    6045 //      FIXME (listview, "NO support for unicode structures");
     5975      FIXME("NO support for unicode structures");
    60465976    }
    60475977  }
     
    60655995  PAINTSTRUCT ps;
    60665996
    6067 //   TRACE(listview, "(hwnd=%x,hdc=%x)\n", hwnd, hdc);
     5997   TRACE("(hwnd=%x,hdc=%x)\n", hwnd, hdc);
    60685998
    60695999  if (hdc == 0)
     
    61006030  NMHDR nmh;
    61016031
    6102 //  TRACE(listview, "(hwnd=%x,key=%hu,X=%hu,Y=%hu)\n", hwnd, wKey, wPosX, wPosY);
     6032  TRACE("(hwnd=%x,key=%hu,X=%hu,Y=%hu)\n", hwnd, wKey, wPosX, wPosY);
    61036033
    61046034  /* send NM_RELEASEDCAPTURE notification */
     
    61336063  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    61346064  INT nCtrlId = GetWindowLongA(hwnd, GWL_ID);
     6065  POINT ptPosition;
    61356066  NMHDR nmh;
    61366067  INT nItem;
    61376068
    6138 //  TRACE(listview, "(hwnd=%x,key=%hu,X=%hu,Y=%hu)\n", hwnd, wKey, wPosX, wPosY);
     6069  TRACE("(hwnd=%x,key=%hu,X=%hu,Y=%hu)\n", hwnd, wKey, wPosX, wPosY);
    61396070
    61406071  /* send NM_RELEASEDCAPTURE notification */
     
    61546085
    61556086  /* determine the index of the selected item */
    6156   nItem = LISTVIEW_MouseSelection(hwnd, wPosX, wPosY);
     6087  ptPosition.x = wPosX;
     6088  ptPosition.y = wPosY;
     6089  nItem = LISTVIEW_MouseSelection(hwnd, ptPosition);
    61576090  if ((nItem >= 0) && (nItem < GETITEMCOUNT(infoPtr)))
    61586091  {
     
    61666099    LISTVIEW_RemoveSelections(hwnd, 0, GETITEMCOUNT(infoPtr));
    61676100  }
    6168 
     6101 
    61696102  return 0;
    61706103}
     
    61906123  NMHDR nmh;
    61916124
    6192 //  TRACE(listview, "(hwnd=%x,key=%hu,X=%hu,Y=%hu)\n", hwnd, wKey, wPosX, wPosY);
     6125  TRACE("(hwnd=%x,key=%hu,X=%hu,Y=%hu)\n", hwnd, wKey, wPosX, wPosY);
    61936126
    61946127  if (infoPtr->bRButtonDown != FALSE)
     
    62526185{
    62536186  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    6254   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
    6255 
    6256 //  TRACE(listview, "(hwnd=%x,hfont=%x,redraw=%hu)\n", hwnd, hFont, fRedraw);
     6187  UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
     6188
     6189  TRACE("(hwnd=%x,hfont=%x,redraw=%hu)\n", hwnd, hFont, fRedraw);
    62576190
    62586191  if (hFont == 0)
     
    62656198  }
    62666199
    6267   if ((LVS_TYPEMASK & lStyle ) == LVS_REPORT)
     6200  if (uView == LVS_REPORT)
    62686201  {
    62696202    /* set header font */
     
    62986231static LRESULT LISTVIEW_Size(HWND hwnd, int Width, int Height)
    62996232{
     6233  LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     6234  UINT uView = lStyle & LVS_TYPEMASK;
     6235
     6236  TRACE("(hwnd=%x, width=%d, height=%d)\n",hwnd, Width, Height);
     6237
     6238  LISTVIEW_UpdateSize(hwnd);
     6239
     6240  if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
     6241  {
     6242    if (lStyle & LVS_ALIGNLEFT)
     6243    {
     6244      LISTVIEW_AlignLeft(hwnd);
     6245    }
     6246    else
     6247    {
     6248      LISTVIEW_AlignTop(hwnd);
     6249    }
     6250  }
     6251
     6252  LISTVIEW_UpdateScroll(hwnd);
     6253 
     6254  /* invalidate client area + erase background */
     6255  InvalidateRect(hwnd, NULL, TRUE);
     6256
     6257  return 0;
     6258}
     6259
     6260/***
     6261 * DESCRIPTION:
     6262 * Sets the size information.
     6263 *
     6264 * PARAMETER(S):
     6265 * [I] HWND : window handle
     6266 *
     6267 * RETURN:
     6268 * Zero
     6269 */
     6270static VOID LISTVIEW_UpdateSize(HWND hwnd)
     6271{
     6272  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    63006273  LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
    6301 
    6302 //  TRACE(listview, "(hwnd=%x,width=%d,height=%d)\n",hwnd, Width, Height);
    6303 
    6304   LISTVIEW_SetSize(hwnd, lStyle, -1, -1);
    6305   switch (lStyle & LVS_TYPEMASK)
    6306   {
    6307   case LVS_LIST:
    6308   case LVS_REPORT:
    6309     LISTVIEW_SetViewInfo(hwnd, lStyle);
    6310     break;
    6311    
    6312   case LVS_ICON:
    6313   case LVS_SMALLICON:
    6314     if (lStyle & LVS_ALIGNLEFT)
    6315     {
    6316       LISTVIEW_AlignLeft(hwnd);
    6317     }
    6318     else
    6319     {
    6320       LISTVIEW_AlignTop(hwnd);
    6321     }
    6322     break;
    6323   }
    6324 
    6325   LISTVIEW_SetScroll(hwnd, lStyle);
    6326 
    6327   /* invalidate + erase background */
    6328   InvalidateRect(hwnd, NULL, TRUE);
    6329 
    6330   return 0;
    6331 }
    6332 
    6333 /***
    6334  * DESCRIPTION:
    6335  * Sets the size information for a given style.
    6336  *
    6337  * PARAMETER(S):
    6338  * [I] HWND : window handle
    6339  * [I] LONG : window style
    6340  * [I] WORD : new width
    6341  * [I] WORD : new height
    6342  *
    6343  * RETURN:
    6344  * Zero
    6345  */
    6346 static VOID LISTVIEW_SetSize(HWND hwnd, LONG lStyle, LONG lWidth, LONG lHeight)
    6347 {
    6348   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    6349   HDLAYOUT hl;
    6350   WINDOWPOS wp;
     6274  UINT uView = lStyle & LVS_TYPEMASK;
    63516275  RECT rcList;
    63526276 
    63536277  GetClientRect(hwnd, &rcList);
    6354   if (lWidth == -1)
    6355   {
    6356     infoPtr->rcList.left = max(rcList.left, 0);
    6357     infoPtr->rcList.right = max(rcList.right, 0);
    6358   }
    6359   else
    6360   {
    6361     infoPtr->rcList.left = max(rcList.left, 0);
    6362     infoPtr->rcList.right = infoPtr->rcList.left + max(lWidth, 0);
    6363   }
    6364 
    6365   if (lHeight == -1)
    6366   {
    6367     infoPtr->rcList.top = max(rcList.top, 0);
    6368     infoPtr->rcList.bottom = max(rcList.bottom, 0);
    6369   }
    6370   else
    6371   {
    6372     infoPtr->rcList.top = max(rcList.top, 0);
    6373     infoPtr->rcList.bottom = infoPtr->rcList.top + max(lHeight, 0);
    6374   }
    6375    
    6376   switch (lStyle & LVS_TYPEMASK)
    6377   {
    6378   case LVS_LIST:
     6278  infoPtr->rcList.left = 0;
     6279  infoPtr->rcList.right = max(rcList.right - rcList.left, 1);
     6280  infoPtr->rcList.top = 0;
     6281  infoPtr->rcList.bottom = max(rcList.bottom - rcList.top, 1);
     6282     
     6283  if (uView == LVS_LIST)
     6284  {
    63796285    if ((lStyle & WS_HSCROLL) == 0)
    63806286    {
    6381       INT nHScrollHeight;
    6382       nHScrollHeight = GetSystemMetrics(SM_CYHSCROLL);
     6287      INT nHScrollHeight = GetSystemMetrics(SM_CYHSCROLL);
    63836288      if (infoPtr->rcList.bottom > nHScrollHeight)
    63846289      {
     
    63866291      }
    63876292    }
    6388     break;
    6389 
    6390   case LVS_REPORT:
     6293  }
     6294  else if (uView == LVS_REPORT)
     6295  {
     6296    HDLAYOUT hl;
     6297    WINDOWPOS wp;
     6298
    63916299    hl.prc = &rcList;
    63926300    hl.pwpos = &wp;
    63936301    Header_Layout(infoPtr->hwndHeader, &hl);
    6394     infoPtr->rcList.top = max(wp.cy, 0);
    6395     break;
     6302    if (!(LVS_NOCOLUMNHEADER & lStyle))
     6303    {
     6304      infoPtr->rcList.top = max(wp.cy, 0);
     6305    }
    63966306  }
    63976307}
     
    64136323{
    64146324  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     6325  UINT uNewView = lpss->styleNew & LVS_TYPEMASK;
     6326  UINT uOldView = lpss->styleOld & LVS_TYPEMASK;
    64156327  RECT rcList = infoPtr->rcList;
    6416   HDLAYOUT hl;
    6417   WINDOWPOS wp;
    6418 
    6419 //  TRACE(listview, "(hwnd=%x,styletype=%x,stylestruct=%p)\n",
    6420 //        hwnd, wStyleType, lpss);
     6328
     6329  TRACE("(hwnd=%x, styletype=%x, stylestruct=%p)\n",
     6330        hwnd, wStyleType, lpss);
    64216331
    64226332  if (wStyleType == GWL_STYLE)
    64236333  {
     6334    if (uOldView == LVS_REPORT)
     6335    {
     6336      ShowWindow(infoPtr->hwndHeader, SW_HIDE);
     6337    }
     6338 
    64246339    if ((lpss->styleOld & WS_HSCROLL) != 0)
    64256340    {
    6426       ShowScrollBar(hwnd, SB_HORZ, FALSE);
    6427     }
    6428 
     6341       ShowScrollBar(hwnd, SB_HORZ, FALSE);
     6342    }
     6343 
    64296344    if ((lpss->styleOld & WS_VSCROLL) != 0)
    64306345    {
    6431       ShowScrollBar(hwnd, SB_VERT, FALSE);
    6432     }
    6433 
    6434     if ((LVS_TYPEMASK & lpss->styleOld) == LVS_REPORT)
    6435     {
    6436       /* remove header */
    6437       ShowWindow(infoPtr->hwndHeader, SW_HIDE);
    6438     }
    6439 
    6440     switch (lpss->styleNew & LVS_TYPEMASK)
    6441     {
    6442     case LVS_ICON:
     6346       ShowScrollBar(hwnd, SB_VERT, FALSE);
     6347    }
     6348 
     6349    if (uNewView == LVS_ICON)
     6350    {
    64436351      infoPtr->iconSize.cx = GetSystemMetrics(SM_CXICON);
    64446352      infoPtr->iconSize.cy = GetSystemMetrics(SM_CYICON);
    6445       LISTVIEW_SetSize(hwnd, lpss->styleNew, -1, -1);
    6446       infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd, lpss->styleNew);
    6447       infoPtr->nItemHeight = LISTVIEW_GetItemHeight(hwnd, lpss->styleNew);
     6353      infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd);
     6354      infoPtr->nItemHeight = LISTVIEW_GetItemHeight(hwnd);
    64486355      if (lpss->styleNew & LVS_ALIGNLEFT)
    64496356      {
     
    64546361        LISTVIEW_AlignTop(hwnd);
    64556362      }
    6456       break;
    6457 
    6458     case LVS_REPORT:
     6363    }
     6364    else if (uNewView == LVS_REPORT)
     6365    {
     6366      HDLAYOUT hl;
     6367      WINDOWPOS wp;
     6368
    64596369      hl.prc = &rcList;
    64606370      hl.pwpos = &wp;
    64616371      Header_Layout(infoPtr->hwndHeader, &hl);
    6462       SetWindowPos(infoPtr->hwndHeader, hwnd, wp.x, wp.y, wp.cx,
    6463                    wp.cy, wp.flags);
    6464       ShowWindow(infoPtr->hwndHeader, SW_SHOWNORMAL);
     6372      SetWindowPos(infoPtr->hwndHeader, hwnd, wp.x, wp.y, wp.cx, wp.cy,
     6373                   wp.flags);
     6374      if (!(LVS_NOCOLUMNHEADER & lpss->styleNew))
     6375      {
     6376        ShowWindow(infoPtr->hwndHeader, SW_SHOWNORMAL);
     6377      }
    64656378      infoPtr->iconSize.cx = GetSystemMetrics(SM_CXSMICON);
    64666379      infoPtr->iconSize.cy = GetSystemMetrics(SM_CYSMICON);
    6467       infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd, lpss->styleNew);
    6468       infoPtr->nItemHeight = LISTVIEW_GetItemHeight(hwnd, lpss->styleNew);
    6469       LISTVIEW_SetSize(hwnd, lpss->styleNew, -1, -1);
    6470       LISTVIEW_SetViewInfo(hwnd, lpss->styleNew);
    6471       break;
    6472 
    6473     case LVS_LIST:
     6380      infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd);
     6381      infoPtr->nItemHeight = LISTVIEW_GetItemHeight(hwnd);
     6382    }
     6383    else if (uNewView == LVS_LIST)
     6384    {
    64746385      infoPtr->iconSize.cx = GetSystemMetrics(SM_CXSMICON);
    64756386      infoPtr->iconSize.cy = GetSystemMetrics(SM_CYSMICON);
    6476       infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd, lpss->styleNew);
    6477       infoPtr->nItemHeight = LISTVIEW_GetItemHeight(hwnd, lpss->styleNew);
    6478       LISTVIEW_SetSize(hwnd, lpss->styleNew, -1, -1);
    6479       LISTVIEW_SetViewInfo(hwnd, lpss->styleNew);
    6480       break;
    6481 
    6482     case LVS_SMALLICON:
     6387      infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd);
     6388      infoPtr->nItemHeight = LISTVIEW_GetItemHeight(hwnd);
     6389    }
     6390    else
     6391    {
    64836392      infoPtr->iconSize.cx = GetSystemMetrics(SM_CXSMICON);
    64846393      infoPtr->iconSize.cy = GetSystemMetrics(SM_CYSMICON);
    6485       LISTVIEW_SetSize(hwnd, lpss->styleNew, -1, -1);
    6486       infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd, lpss->styleNew);
    6487       infoPtr->nItemHeight = LISTVIEW_GetItemHeight(hwnd, lpss->styleNew);
     6394      infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd);
     6395      infoPtr->nItemHeight = LISTVIEW_GetItemHeight(hwnd);
    64886396      if (lpss->styleNew & LVS_ALIGNLEFT)
    64896397      {
     
    64946402        LISTVIEW_AlignTop(hwnd);
    64956403      }
    6496       break;
    6497     }
    6498 
    6499     LISTVIEW_SetScroll(hwnd, lpss->styleNew);
     6404    }
     6405
     6406    /* update the size of the client area */
     6407    LISTVIEW_UpdateSize(hwnd);
     6408
     6409    /* add scrollbars if needed */
     6410    LISTVIEW_UpdateScroll(hwnd);
    65006411   
    6501     /* print unsupported styles */
     6412    /* invalidate client area + erase background */
     6413    InvalidateRect(hwnd, NULL, TRUE);
     6414
     6415    /* print the list of unsupported window styles */
    65026416    LISTVIEW_UnsupportedStyles(lpss->styleNew);
    6503 
    6504     /* invalidate client area */
    6505     InvalidateRect(hwnd, NULL, TRUE);
    65066417  }
    65076418
     
    65126423 * DESCRIPTION:
    65136424 * Window procedure of the listview control.
    6514  *
    6515  * PARAMETER(S):
    6516  * [I] HWND :
    6517  * [I] UINT :
    6518  * [I] WPARAM :
    6519  * [I] LPARAM :
    6520  *
    6521  * RETURN:
    6522  *
     6425 *
    65236426 */
    65246427LRESULT WINAPI LISTVIEW_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
     
    68306733    if (uMsg >= WM_USER)
    68316734    {
    6832 //      ERR(listview, "unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam,
    6833 //          lParam);
     6735      ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam,
     6736          lParam);
    68346737    }
    68356738
  • trunk/src/comctl32/status.c

    r110 r164  
    1 /* $Id: status.c,v 1.4 1999-06-16 20:25:43 cbratschi Exp $ */
     1/* $Id: status.c,v 1.5 1999-06-23 19:45:01 achimha Exp $ */
    22/*
    33 * Interface code to StatusWindow widget/control
     
    8080    UINT border = BDR_SUNKENOUTER;
    8181
    82     if (part->style==SBT_POPOUT)
     82    if (part->style & SBT_POPOUT)
    8383      border = BDR_RAISEDOUTER;
    84     else if (part->style==SBT_NOBORDERS)
     84    else if (part->style & SBT_NOBORDERS)
    8585      border = 0;
    8686
     
    136136    hOldFont = SelectObject (hdc, self->hFont ? self->hFont : self->hDefaultFont);
    137137
    138     if (part->style == SBT_OWNERDRAW) {
     138    if (part->style & SBT_OWNERDRAW) {
    139139        DRAWITEMSTRUCT dis;
    140140
     
    192192    else {
    193193        for (i = 0; i < infoPtr->numParts; i++) {
    194             if (infoPtr->parts[i].style == SBT_OWNERDRAW) {
     194            if (infoPtr->parts[i].style & SBT_OWNERDRAW) {
    195195                DRAWITEMSTRUCT dis;
    196196
     
    365365        part = &self->parts[nPart];
    366366
    367     if (part->style == SBT_OWNERDRAW)
     367    if (part->style & SBT_OWNERDRAW)
    368368        result = (LRESULT)part->text;
    369369    else {
     
    391391        part = &infoPtr->parts[nPart];
    392392
    393     if (part->style == SBT_OWNERDRAW)
     393    if (part->style & SBT_OWNERDRAW)
    394394        result = (LRESULT)part->text;
    395395    else {
     
    571571    if (oldNumParts > self->numParts) {
    572572        for (i = self->numParts ; i < oldNumParts; i++) {
    573             if (self->parts[i].text && (self->parts[i].style != SBT_OWNERDRAW))
     573            if (self->parts[i].text && !(self->parts[i].style & SBT_OWNERDRAW))
    574574                COMCTL32_Free (self->parts[i].text);
    575575        }
     
    635635    STATUSWINDOWINFO *self = STATUSBAR_GetInfoPtr (hwnd);
    636636    STATUSWINDOWPART *part;
    637     int part_num;
    638     int style;
     637    int part_num;
     638    int style;
    639639    LPSTR text;
    640     int len;
     640    int len;
    641641    HDC hdc;
    642642
     
    646646
    647647    if ((self->simple) || (self->parts==NULL) || (part_num==255))
    648         part = &self->part0;
     648        part = &self->part0;
    649649    else
    650         part = &self->parts[part_num];
     650        part = &self->parts[part_num];
    651651    if (!part) return FALSE;
     652
     653    if (!(part->style & SBT_OWNERDRAW) && part->text)
     654        COMCTL32_Free (part->text);
     655    part->text = 0;
     656
     657    if (style & SBT_OWNERDRAW) {
     658        part->text = (LPWSTR)text;
     659    }
     660    else {
     661        /* duplicate string */
     662        if (text && (len = lstrlenA(text))) {
     663            part->text = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
     664            lstrcpyAtoW (part->text, text);
     665        }
     666    }
    652667    part->style = style;
    653     if (style == SBT_OWNERDRAW) {
    654         part->text = (LPWSTR)text;
    655     }
    656     else {
    657         /* duplicate string */
    658         if (part->text)
    659             COMCTL32_Free (part->text);
    660         part->text = 0;
    661         if (text && (len = lstrlenA(text))) {
    662             part->text = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
    663             lstrcpyAtoW (part->text, text);
    664         }
    665     }
    666668
    667669    hdc = GetDC (hwnd);
     
    687689
    688690    if ((self->simple) || (self->parts==NULL) || (part_num==255))
    689         part = &self->part0;
     691        part = &self->part0;
    690692    else
    691         part = &self->parts[part_num];
     693        part = &self->parts[part_num];
    692694    if (!part) return FALSE;
     695
     696    if (!(part->style & SBT_OWNERDRAW) && part->text)
     697        COMCTL32_Free (part->text);
     698    part->text = 0;
     699
     700    if (style & SBT_OWNERDRAW) {
     701        part->text = text;
     702    }
     703    else {
     704        /* duplicate string */
     705        if (text && (len = lstrlenW(text))) {
     706            part->text = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
     707            lstrcpyW(part->text, text);
     708        }
     709    }
    693710    part->style = style;
    694     if (style == SBT_OWNERDRAW) {
    695         part->text = text;
    696     }
    697     else {
    698         /* duplicate string */
    699         if (part->text)
    700             COMCTL32_Free (part->text);
    701         part->text = 0;
    702         if (text && (len = lstrlenW(text))) {
    703             part->text = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
    704             lstrcpyW(part->text, text);
    705         }
    706     }
    707711
    708712    hdc = GetDC (hwnd);
     
    892896{
    893897    STATUSWINDOWINFO *self = STATUSBAR_GetInfoPtr (hwnd);
    894     int i;
     898    int i;
    895899
    896900    for (i = 0; i < self->numParts; i++) {
    897         if (self->parts[i].text && (self->parts[i].style != SBT_OWNERDRAW))
    898             COMCTL32_Free (self->parts[i].text);
    899     }
    900     if (self->part0.text && (self->part0.style != SBT_OWNERDRAW))
    901         COMCTL32_Free (self->part0.text);
     901        if (self->parts[i].text && !(self->parts[i].style & SBT_OWNERDRAW))
     902            COMCTL32_Free (self->parts[i].text);
     903    }
     904    if (self->part0.text && !(self->part0.style & SBT_OWNERDRAW))
     905        COMCTL32_Free (self->part0.text);
    902906    COMCTL32_Free (self->parts);
    903907
    904908    /* delete default font */
    905909    if (self->hDefaultFont)
    906         DeleteObject (self->hDefaultFont);
     910        DeleteObject (self->hDefaultFont);
    907911
    908912    /* delete tool tip control */
    909913    if (self->hwndToolTip)
    910         DestroyWindow (self->hwndToolTip);
     914        DestroyWindow (self->hwndToolTip);
    911915
    912916    COMCTL32_Free (self);
  • trunk/src/comctl32/tab.c

    r94 r164  
    1 /* $Id: tab.c,v 1.4 1999-06-10 16:22:02 achimha Exp $ */
     1/* $Id: tab.c,v 1.5 1999-06-23 19:45:01 achimha Exp $ */
    22/*
    33 * Tab control
     
    775775  if (isVisible)
    776776  {
    777     HBRUSH hbr       = CreateSolidBrush (GetSysColor(COLOR_BACKGROUND));   
     777    HBRUSH hbr       = CreateSolidBrush (GetSysColor(COLOR_BTNFACE));   
    778778    HPEN   hwPen     = GetSysColorPen (COLOR_3DHILIGHT);
    779779    HPEN   hbPen     = GetSysColorPen (COLOR_BTNSHADOW);
     
    848848       * Background color.
    849849       */
    850       hbr = CreateSolidBrush(GetSysColor(COLOR_BACKGROUND));   
     850      hbr = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));   
    851851
    852852      /*
     
    10871087  RECT clientRect;
    10881088
    1089   HBRUSH brush = CreateSolidBrush(GetSysColor(COLOR_BACKGROUND));
     1089  HBRUSH brush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
    10901090
    10911091  hdc = givenDC ? givenDC : GetDC(hwnd);
  • trunk/src/comctl32/treeview.c

    r110 r164  
    1 /* $Id: treeview.c,v 1.4 1999-06-16 20:25:44 cbratschi Exp $ */
     1/* $Id: treeview.c,v 1.5 1999-06-23 19:45:02 achimha Exp $ */
    22/* Treeview control
    33 *
     
    11481148   }
    11491149
    1150    if (tvItem->mask & TVIF_PARAM) {
    1151         tvItem->lParam=wineItem->lParam;
    1152    }
     1150   // undocumented: windows ignores TVIF_PARAM and
     1151   // always sets lParam
     1152   tvItem->lParam=wineItem->lParam;
    11531153
    11541154   if (tvItem->mask & TVIF_SELECTEDIMAGE) {
     
    15071507                    infoPtr->uNumPtrsAlloced/2 * sizeof(TREEVIEW_ITEM));
    15081508    memcpy (&infoPtr->freeList[0], &oldfreeList[0],
    1509                     infoPtr->uNumPtrsAlloced>>6 * sizeof(INT));
     1509                    (infoPtr->uNumPtrsAlloced>>6) * sizeof(INT));
    15101510
    15111511    COMCTL32_Free (oldItems);
Note: See TracChangeset for help on using the changeset viewer.