Changeset 2835 for trunk/src


Ignore:
Timestamp:
Feb 20, 2000, 7:29:58 PM (26 years ago)
Author:
cbratschi
Message:

* empty log message *

Location:
trunk/src/comctl32
Files:
3 edited

Legend:

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

    r2806 r2835  
    1 /* $Id: tooltips.c,v 1.21 2000-02-16 17:22:18 cbratschi Exp $ */
     1/* $Id: tooltips.c,v 1.22 2000-02-20 18:29:56 cbratschi Exp $ */
    22/*
    33 * Tool tip control
     
    244244
    245245    *lpRect = rc;
    246 
    247246}
    248247
  • trunk/src/comctl32/trackbar.c

    r2814 r2835  
    1 /* $Id: trackbar.c,v 1.25 2000-02-17 17:26:50 cbratschi Exp $ */
     1/* $Id: trackbar.c,v 1.26 2000-02-20 18:29:57 cbratschi Exp $ */
    22/*
    33 * Trackbar control
     
    17371737      ti.hwnd     = hwnd;
    17381738      ti.uId      = 0;
    1739       ti.lpszText = ""; /* LPSTR_TEXTCALLBACK */
     1739      ti.lpszText = "";
    17401740      SetRectEmpty(&ti.rect);
    17411741
     
    18831883           ti.uId      = 0;
    18841884           ti.hwnd     = (UINT)hwnd;
    1885            ti.hinst = 0;
     1885           ti.hinst    = 0;
    18861886           sprintf (buf,"%d",infoPtr->nPos);
    18871887           ti.lpszText = (LPSTR)buf;
  • trunk/src/comctl32/treeview.c

    r2820 r2835  
    1 /* $Id: treeview.c,v 1.28 2000-02-18 17:13:39 cbratschi Exp $ */
     1/* $Id: treeview.c,v 1.29 2000-02-20 18:29:58 cbratschi Exp $ */
    22/* Treeview control
    33 *
     
    66 * Copyright 1999 Sylvain St-Germain
    77 * Copyright 1999 Achim Hasenmueller
    8  * Copyright 1999-2000 Christoph Bratschi
     8 * Copyright 1999-2000 Christoph Bratschi (cbratschi@datacomm.ch)
    99 *
    1010 *
     
    1212 *   Using DPA to store the item ptr would be good.
    1313 *  -check custom draw
    14  *   FIXME: check fontsize. (uRealItemHeight)
    1514                        uHotItem
    1615 *   use separate routine to get item text/image.
     
    3231
    3332/* CB: todo
    34 
    3533 - bug in SetScrollInfo/ShowScrollBar: WM_SIZE and WM_NCPAINT problems (i.e. RegEdit)
     34 - tooltips not finished
     35 - expand not finished
    3636 - TVS_FULLROWSELECT
    37  - TVS_SINGLEEXPAND
    3837 - TVS_TRACKSELECT (called hottrack)
    39  - TVS_INFOTIP, TVS_NOTOOLTIPS and tooltip support
    4038 - WM_ENABLE: draw disabled control
    4139*/
    4240
     41#include <stdlib.h>
    4342#include <string.h>
     43#include <math.h>
    4444#include "winbase.h"
    4545#include "wingdi.h"
     
    7171static BOOL    TREEVIEW_SendCustomDrawItemNotify (HWND hwnd, HDC hdc, TREEVIEW_ITEM *tvItem, UINT uItemDrawState);
    7272static LRESULT TREEVIEW_SelectItem (HWND hwnd, WPARAM wParam, LPARAM lParam);
    73 static LRESULT TREEVIEW_DoSelectItem (HWND hwnd, INT action, HTREEITEM newSelect, INT cause);
     73static LRESULT TREEVIEW_DoSelectItem(HWND hwnd,INT action,HTREEITEM newSelect,INT cause);
    7474static void    TREEVIEW_Refresh(HWND hwnd);
    7575static void    TREEVIEW_Draw(HWND hwnd,HDC hdc,RECT *updateRect);
     
    409409        infoPtr->uNumPtrsAlloced=0;
    410410        infoPtr->uMaxHandle=0;
    411         infoPtr->cx = infoPtr->cy = 0;
     411        infoPtr->lefttop.x = infoPtr->lefttop.y = 0;
    412412    }
    413413}
     
    456456  INT cx,cy,prevHeight = infoPtr->uItemHeight;
    457457
    458   if (wParam==-1)
     458  if (wParam == -1)
    459459  {
    460460    infoPtr->uItemHeight = -1;
     
    469469
    470470  if (!(GetWindowLongA(hwnd, GWL_STYLE) & TVS_NONEVENHEIGHT))
    471     if (infoPtr->uItemHeight & 0x1) infoPtr->uItemHeight += 1;
     471    if (infoPtr->uItemHeight & 0x1) infoPtr->uItemHeight++;
    472472
    473473  return prevHeight;
     
    645645                   item->rect.bottom-3:  /* is linked to an icon       */
    646646                   item->rect.bottom+1;  /* is linked to a +/- box     */
    647     points[1].x = points[0].x = 28+20*item->iLevel-infoPtr->cx;
     647    points[1].x = points[0].x = 28+20*item->iLevel-infoPtr->lefttop.x;
    648648    points[1].y = (lastItem->rect.top+lastItem->rect.bottom)/2;  /* is linked to a +/- box     */
    649649#ifdef OS2LINEHACK
     
    677677  }
    678678
    679   //CB: what does COMCTL 5.0 with CDRF_NEWFONT? recalc items?
     679  //CDRF_NEWFONT: CCM_SETVERSION < 5 clips text (what we do now)
     680  //                             > 5 ??? recalc?
    680681
    681682  /*
     
    727728      } else
    728729      {
    729         points[1].x = 8+(20*item->iLevel)-infoPtr->cx;
     730        points[1].x = 8+(20*item->iLevel)-infoPtr->lefttop.x;
    730731        points[1].y = points[0].y = center;
    731732        points[0].x = points[1].x + 10;
     
    815816    }
    816817
    817     if (himlp)
     818    if (himlp && (imageIndex != I_IMAGENONE))
    818819    {
    819820      int ovlIdx = 0;
     
    13161317  BOOL ownDC = FALSE,changedLeftTop = FALSE;
    13171318  DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
    1318   INT maxCX,maxCY;
    1319   INT xDiff = 0,yDiff = 0;
     1319  INT maxXScroll,maxYScroll;
     1320  INT xDiff,yDiff;
     1321  HFONT oldFont;
    13201322
    13211323  GetClientRect(hwnd,&rect);
    13221324  infoPtr->uVisibleHeight = rect.bottom-rect.top;
    13231325  infoPtr->uVisibleWidth = rect.right-rect.left;
     1326
     1327  if (infoPtr->uInternalStatus & TV_CALCALL)
     1328  {
     1329    itemHeight = 0;
     1330    ImageList_GetIconSize (infoPtr->himlNormal, &x, &itemHeight);
     1331    itemHeight = MAX(infoPtr->uItemHeight,itemHeight);
     1332
     1333    if (!hdc)
     1334    {
     1335      ownDC = TRUE;
     1336      hdc = GetDC(hwnd);
     1337    }
     1338
     1339    oldFont = SelectObject(hdc,infoPtr->hFont);
     1340    GetTextMetricsA(hdc,&tm);
     1341    itemHeight = MAX(tm.tmHeight+tm.tmExternalLeading,itemHeight);
     1342    SelectObject(hdc,infoPtr->hBoldFont);
     1343    GetTextMetricsA(hdc,&tm);
     1344    itemHeight = MAX(tm.tmHeight+tm.tmExternalLeading,itemHeight);
     1345    SelectObject(hdc,oldFont);
     1346    if (!(dwStyle & TVS_NONEVENHEIGHT))
     1347      if (itemHeight & 0x1) itemHeight++; //important for PS_DOT pen!
     1348    infoPtr->uRealItemHeight = itemHeight;
     1349    infoPtr->uVScrollStep = itemHeight+ITEM_VSPACE;
     1350  } else
     1351  {
     1352    itemHeight = infoPtr->uRealItemHeight;
     1353  }
     1354  infoPtr->uTotalWidth = 0;
     1355
    13241356  view = rect;
    1325   OffsetRect(&view,infoPtr->cx,infoPtr->cy);
    1326 
    1327   itemHeight = 0;
    1328   ImageList_GetIconSize (infoPtr->himlNormal, &x, &itemHeight);
    1329   itemHeight = MAX(infoPtr->uItemHeight,itemHeight);
    1330 
    1331   if (!hdc)
    1332   {
    1333     ownDC = TRUE;
    1334     hdc = GetDC(hwnd);
    1335   }
    1336 
    1337   GetTextMetricsA (hdc, &tm);
    1338   itemHeight = MAX(tm.tmHeight+tm.tmExternalLeading,itemHeight);
    1339   if (!(dwStyle & TVS_NONEVENHEIGHT))
    1340     if (itemHeight & 0x1) itemHeight += 1; //important for PS_DOT pen!
    1341   infoPtr->uRealItemHeight = itemHeight;
    1342   infoPtr->uTotalWidth = 0;
     1357  OffsetRect(&view,infoPtr->lefttop.x,infoPtr->lefttop.y);
    13431358
    13441359  iItem = (INT)infoPtr->TopRootItem;
     
    13521367    item->iLevel = indent;
    13531368
    1354     height = itemHeight * item->iIntegral +1;
     1369    height = itemHeight*item->iIntegral+ITEM_VSPACE;
    13551370
    13561371    //calculate size and fill rects
    13571372    if ((infoPtr->uInternalStatus & TV_CALCALL) || !item->calculated)
    13581373    {
    1359       item->rect.top    = y-infoPtr->cy;
     1374      item->rect.top    = y-view.top;
    13601375      item->rect.bottom = item->rect.top+height;
    1361       item->rect.left   = x-infoPtr->cx;
     1376      item->rect.left   = x-view.left;
    13621377      item->rect.right  = rect.right; //dummy
     1378      if (!hdc)
     1379      {
     1380        ownDC = TRUE;
     1381        hdc = GetDC(hwnd);
     1382      }
    13631383      TREEVIEW_CalcItem(hwnd,hdc,dwStyle,infoPtr,item);
    13641384    } else
     
    13661386      INT xOffset,yOffset;
    13671387
    1368       xOffset = (x-infoPtr->cx)-item->rect.left;
    1369       yOffset = (y-infoPtr->cy)-item->rect.top;
     1388      xOffset = (x-view.left)-item->rect.left;
     1389      yOffset = (y-view.top)-item->rect.top;
    13701390      OffsetRect(&item->rect,xOffset,yOffset);
    13711391      OffsetRect(&item->text,xOffset,yOffset);
     
    13741394      OffsetRect(&item->statebitmap,xOffset,yOffset);
    13751395    }
    1376     infoPtr->uTotalWidth = MAX(infoPtr->uTotalWidth,item->rect.right+infoPtr->cx);
    1377 
    1378     if (((y >= view.top) && (y <= view.bottom)) || ((y+height >= view.top) && (y+height <= view.bottom)))
     1396    infoPtr->uTotalWidth = MAX(infoPtr->uTotalWidth,item->rect.right+infoPtr->lefttop.x);
     1397
     1398    if (((y >= view.top) && (y < view.bottom)) || ((y+height > view.top) && (y+height <= view.bottom)))
    13791399    {
    13801400      item->visible = TRUE;
     
    14101430
    14111431  //check cx and cy
    1412   maxCY = infoPtr->uTotalHeight-infoPtr->uVisibleHeight;
    1413   if (maxCY < 0) maxCY = 0;
    1414   if (infoPtr->cy > maxCY)
    1415   {
    1416     yDiff = maxCY-infoPtr->cy;
    1417     infoPtr->cy = maxCY;
    1418   }
    1419 
    1420   maxCX = infoPtr->uTotalWidth-infoPtr->uVisibleWidth;
    1421   if (maxCX < 0) maxCX = 0;
    1422   if (infoPtr->cx > maxCX)
    1423   {
    1424     xDiff = maxCX-infoPtr->cx;
    1425     infoPtr->cx = maxCX;
     1432  yDiff = xDiff = 0;
     1433
     1434  maxYScroll = infoPtr->uTotalHeight-infoPtr->uVisibleHeight;
     1435  if (maxYScroll < 0) maxYScroll = 0;
     1436  if (infoPtr->lefttop.y > maxYScroll)
     1437  {
     1438    INT mod = maxYScroll % infoPtr->uVScrollStep;
     1439
     1440    if (mod > 0) maxYScroll += infoPtr->uVScrollStep-mod;
     1441    yDiff = infoPtr->lefttop.y-maxYScroll;
     1442    infoPtr->lefttop.y = maxYScroll;
     1443  }
     1444
     1445  maxXScroll = infoPtr->uTotalWidth-infoPtr->uVisibleWidth;
     1446  if (maxXScroll < 0) maxXScroll = 0;
     1447  if (infoPtr->lefttop.x > maxXScroll)
     1448  {
     1449    xDiff = infoPtr->lefttop.x-maxXScroll;
     1450    infoPtr->lefttop.x = maxXScroll;
    14261451  }
    14271452
     
    14321457    item = NULL;
    14331458    indent = 0;
     1459    infoPtr->firstVisible = 0;
    14341460
    14351461    while (iItem)
     
    14411467      OffsetRect(&item->bitmap,xDiff,yDiff);
    14421468      OffsetRect(&item->statebitmap,xDiff,yDiff);
     1469
     1470      y = view.top+item->rect.top;
     1471      if (((y >= view.top) && (y < view.bottom)) || ((y+height > view.top) && (y+height <= view.bottom)))
     1472      {
     1473        item->visible = TRUE;
     1474        if (!infoPtr->firstVisible)
     1475          infoPtr->firstVisible = item->hItem;
     1476      } else item->visible = FALSE;
    14431477
    14441478      if ((item->firstChild) && (item->state & TVIS_EXPANDED))
     
    14681502      info.nMin   = 0;
    14691503      info.nMax   = infoPtr->uTotalHeight-1;
    1470       info.nPos   = infoPtr->cy;
     1504      info.nPos   = infoPtr->lefttop.y;
    14711505      info.nPage  = MAX(infoPtr->uVisibleHeight,1);
    14721506      info.fMask = SIF_RANGE | SIF_POS | SIF_PAGE;
     
    14861520      info.nMin   = 0;
    14871521      info.nMax   = infoPtr->uTotalWidth-1;
    1488       info.nPos   = infoPtr->cx;
     1522      info.nPos   = infoPtr->lefttop.x;
    14891523      info.nPage  = MAX(infoPtr->uVisibleWidth,1);
    14901524      info.fMask  = SIF_RANGE | SIF_POS | SIF_PAGE;
     
    16781712
    16791713  if (tvItem->mask & TVIF_HANDLE)
    1680     tvItem->hItem=wineItem->hItem;
     1714    tvItem->hItem = wineItem->hItem;
    16811715
    16821716  if (tvItem->mask & TVIF_IMAGE)
    1683     tvItem->iImage=wineItem->iImage;
     1717    tvItem->iImage = wineItem->iImage;
    16841718
    16851719  if (tvItem->mask & TVIF_INTEGRAL)
    1686     tvItem->iIntegral=wineItem->iIntegral;
     1720    tvItem->iIntegral = wineItem->iIntegral;
    16871721
    16881722  // undocumented: windows ignores TVIF_PARAM and
     
    16911725
    16921726  if (tvItem->mask & TVIF_SELECTEDIMAGE)
    1693     tvItem->iSelectedImage=wineItem->iSelectedImage;
     1727    tvItem->iSelectedImage = wineItem->iSelectedImage;
    16941728
    16951729  if (tvItem->mask & TVIF_STATE)
    1696     tvItem->state=wineItem->state & tvItem->stateMask;
     1730    tvItem->state = wineItem->state & tvItem->stateMask;
    16971731
    16981732  if (tvItem->mask & TVIF_TEXT)
     
    19161950 * Forward the DPA local callback to the treeview owner callback
    19171951 */
    1918 static INT WINAPI TREEVIEW_CallBackCompare(
    1919   LPVOID first,
    1920   LPVOID second,
    1921   LPARAM tvInfoPtr)
     1952static INT WINAPI TREEVIEW_CallBackCompare(LPVOID first,LPVOID second,LPARAM tvInfoPtr)
    19221953{
    19231954  /* Forward the call to the client define callback */
    19241955  TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr((HWND)tvInfoPtr);
     1956
    19251957  return (infoPtr->pCallBackSort->lpfnCompare)(
    19261958    ((TREEVIEW_ITEM*)first)->lParam,
     
    19321964 * Treeview native sort routine: sort on item text.
    19331965 */
    1934 static INT WINAPI TREEVIEW_SortOnName (
    1935   LPVOID first,
    1936   LPVOID second,
    1937   LPARAM tvInfoPtr)
    1938 {
    1939   HWND hwnd=(HWND) tvInfoPtr;
    1940   WCHAR *txt1, *txt2;
     1966static INT WINAPI TREEVIEW_SortOnName(LPVOID first,LPVOID second,LPARAM tvInfoPtr)
     1967{
     1968  HWND hwnd = (HWND)tvInfoPtr;
     1969  WCHAR *txt1,*txt2;
    19411970  TREEVIEW_ITEM *item;
    19421971
    1943 
    1944   item=(TREEVIEW_ITEM *) first;
    1945   if (item->pszText == LPSTR_TEXTCALLBACKW)  {
    1946          TREEVIEW_SendDispInfoNotify (hwnd, item, TVN_GETDISPINFO, TVIF_TEXT);
    1947         }
    1948   txt1=item->pszText;
    1949 
    1950   item=(TREEVIEW_ITEM *) second;
    1951   if (item->pszText == LPSTR_TEXTCALLBACKW)  {
    1952          TREEVIEW_SendDispInfoNotify (hwnd, item, TVN_GETDISPINFO, TVIF_TEXT);
    1953         }
    1954   txt2=item->pszText;
    1955 
    1956   return -lstrcmpW(txt1,txt2);
     1972  item = (TREEVIEW_ITEM *) first;
     1973  if (item->pszText == LPSTR_TEXTCALLBACKW)
     1974    TREEVIEW_SendDispInfoNotify (hwnd, item, TVN_GETDISPINFO, TVIF_TEXT);
     1975
     1976  txt1 = item->pszText;
     1977
     1978  item = (TREEVIEW_ITEM *) second;
     1979  if (item->pszText == LPSTR_TEXTCALLBACKW)
     1980    TREEVIEW_SendDispInfoNotify (hwnd, item, TVN_GETDISPINFO, TVIF_TEXT);
     1981
     1982  txt2 = item->pszText;
     1983
     1984  return lstrcmpW(txt1,txt2);
    19571985}
    19581986
     
    19681996 */
    19691997
    1970 static LRESULT WINAPI TREEVIEW_Sort (
    1971   HWND   hwnd,
    1972   BOOL   fRecurse,
    1973   HTREEITEM parent,
    1974   LPTVSORTCB pSort
    1975   )
     1998static LRESULT WINAPI TREEVIEW_Sort(HWND hwnd,BOOL fRecurse,HTREEITEM parent,LPTVSORTCB pSort)
    19761999{
    19772000  TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
     
    19792002  INT            cChildren;
    19802003  HTREEITEM      hti;
     2004  BOOL root;
    19812005
    19822006  /* Obtain the TVSORTBC struct */
     
    19852009  /* undocumented feature: TVI_ROOT means `sort the whole tree' */
    19862010
    1987   if (parent==TVI_ROOT)
    1988     parent=infoPtr->TopRootItem;
     2011  if ((parent == TVI_ROOT) || (parent == 0))
     2012  {
     2013    root = TRUE;
     2014    parent = infoPtr->TopRootItem;
     2015  }
    19892016
    19902017  /* Check for a valid handle to the parent item */
    1991   if (!TREEVIEW_ValidItem(infoPtr, parent))
    1992   {
    1993     //ERR ("invalid item hParent=%x\n", (INT)parent);
     2018  sortMe = TREEVIEW_ValidItem(infoPtr,parent);
     2019  if (!sortMe)
    19942020    return FALSE;
    1995   }
    1996 
    1997   /* Obtain the parent node to sort */
    1998   sortMe = &infoPtr->items[ (INT)parent ];
    19992021
    20002022  cChildren = 0;
    2001   for(hti = sortMe->firstChild; hti; hti = infoPtr->items[(INT)hti].sibling)
     2023  for(hti = root ? sortMe->hItem:sortMe->firstChild; hti; hti = infoPtr->items[(INT)hti].sibling)
    20022024      cChildren++;
    20032025
    20042026  /* Make sure there is something to sort */
    2005   if ( cChildren > 1 )
     2027  if (cChildren > 1)
    20062028  {
    20072029    /* pointer organization */
    20082030    HDPA          sortList   = DPA_Create(cChildren);
    2009     HTREEITEM     itemHandle = sortMe->firstChild;
    2010     TREEVIEW_ITEM *itemPtr   = & infoPtr->items[ (INT)itemHandle ];
     2031    HTREEITEM     itemHandle = root ? sortMe->hItem:sortMe->firstChild;
     2032    TREEVIEW_ITEM *itemPtr   = &infoPtr->items[(INT)itemHandle];
    20112033
    20122034    /* TREEVIEW_ITEM rechaining */
     
    20192041    do
    20202042    {
     2043      itemPtr    = &infoPtr->items[(INT)itemHandle];
    20212044      DPA_InsertPtr(
    2022         sortList,              /* the list */
     2045        sortList,      /* the list */
    20232046        cChildren+1,   /* force the insertion to be an append */
    2024         itemPtr);              /* the ptr to store */
     2047        itemPtr);      /* the ptr to store */
    20252048
    20262049      /* Get the next sibling */
    20272050      itemHandle = itemPtr->sibling;
    2028       itemPtr    = & infoPtr->items[ (INT)itemHandle ];
    2029     } while ( itemHandle != NULL );
     2051    } while (itemHandle != NULL);
    20302052
    20312053    /* let DPA perform the sort activity */
     
    20372059        else
    20382060                DPA_Sort (
    2039                         sortList,                  /* what  */
    2040                 TREEVIEW_SortOnName,      /* how   */
    2041                         hwnd);                     /* owner */
     2061                        sortList,            /* what  */
     2062                        TREEVIEW_SortOnName, /* how   */
     2063                        hwnd);               /* owner */
    20422064
    20432065    /*
     
    20482070    /* Get the first item and get ready to start... */
    20492071    item = DPA_GetPtr(sortList, count++);
    2050     while ( (nextItem = DPA_GetPtr(sortList, count++)) != NULL )
     2072    while ((nextItem = DPA_GetPtr(sortList, count++)) != NULL)
    20512073    {
    20522074      /* link the two current item toghether */
     
    20562078      if (prevItem == NULL) /* this is the first item, update the parent */
    20572079      {
    2058         sortMe->firstChild                = ((TREEVIEW_ITEM*)item)->hItem;
     2080        if (root)
     2081          infoPtr->TopRootItem = ((TREEVIEW_ITEM*)item)->hItem;
     2082        else
     2083          sortMe->firstChild = ((TREEVIEW_ITEM*)item)->hItem;
    20592084        ((TREEVIEW_ITEM*)item)->upsibling = NULL;
    20602085      }
     
    20732098
    20742099    DPA_Destroy(sortList);
     2100    TREEVIEW_QueueRefresh(hwnd);
    20752101
    20762102    return TRUE;
     
    20832109 * and sort the children of the TV item specified in lParam
    20842110 */
    2085 static LRESULT WINAPI TREEVIEW_SortChildrenCB(
    2086   HWND   hwnd,
    2087   WPARAM wParam,
    2088   LPARAM lParam
    2089   )
    2090 {
    2091   LPTVSORTCB pSort=(LPTVSORTCB) lParam;
     2111static LRESULT WINAPI TREEVIEW_SortChildrenCB(HWND hwnd,WPARAM wParam,LPARAM lParam)
     2112{
     2113  LPTVSORTCB pSort = (LPTVSORTCB) lParam;
    20922114
    20932115  return TREEVIEW_Sort (hwnd, wParam, pSort->hParent, pSort);
     
    20982120 * Sort the children of the TV item specified in lParam.
    20992121 */
    2100 static LRESULT WINAPI TREEVIEW_SortChildren (
    2101   HWND   hwnd,
    2102   WPARAM wParam,
    2103   LPARAM lParam)
     2122static LRESULT WINAPI TREEVIEW_SortChildren(HWND hwnd,WPARAM wParam,LPARAM lParam)
    21042123{
    21052124  return TREEVIEW_Sort (hwnd, (BOOL) wParam, (HTREEITEM) lParam, NULL);
     
    23802399   }
    23812400
    2382 
    2383    /* Fill in info structure */
    2384 
    2385    wineItem->mask=tvItem->mask;
    2386    wineItem->iIntegral=1;
    2387 
    2388    if (tvItem->mask & TVIF_CHILDREN)
    2389      wineItem->cChildren=tvItem->cChildren;
    2390 
     2401  /* Fill in info structure */
     2402
     2403  wineItem->mask = tvItem->mask;
     2404  wineItem->iIntegral = 1;
     2405
     2406  if (tvItem->mask & TVIF_CHILDREN)
     2407    wineItem->cChildren=tvItem->cChildren;
    23912408
    23922409  wineItem->expandBox.left   = 0; /* Initialize the expandBox */
     
    23952412  wineItem->expandBox.bottom = 0;
    23962413
    2397    if (tvItem->mask & TVIF_IMAGE)
    2398         wineItem->iImage=tvItem->iImage;
    2399 
    2400                 /* If the application sets TVIF_INTEGRAL without
    2401                         supplying a TVITEMEX structure, it's toast */
    2402 
    2403    if (tvItem->mask & TVIF_INTEGRAL)
    2404                 wineItem->iIntegral=tvItem->iIntegral;
    2405 
    2406    if (tvItem->mask & TVIF_SELECTEDIMAGE)
    2407         wineItem->iSelectedImage=tvItem->iSelectedImage;
    2408 
    2409    if (tvItem->mask & TVIF_STATE) {
    2410         wineItem->state=tvItem->state;
    2411         wineItem->stateMask=tvItem->stateMask;
    2412    }
    2413 
    2414    wineItem->calculated = FALSE;
    2415    TREEVIEW_QueueRefresh(hwnd);
    2416 
    2417    return (LRESULT) iItem;
     2414  if (tvItem->mask & TVIF_IMAGE)
     2415   wineItem->iImage = tvItem->iImage;
     2416
     2417  /* If the application sets TVIF_INTEGRAL without
     2418     supplying a TVITEMEX structure, it's toast */
     2419
     2420  if (tvItem->mask & TVIF_INTEGRAL)
     2421    wineItem->iIntegral = tvItem->iIntegral;
     2422
     2423  if (tvItem->mask & TVIF_SELECTEDIMAGE)
     2424    wineItem->iSelectedImage = tvItem->iSelectedImage;
     2425
     2426  if (tvItem->mask & TVIF_STATE)
     2427  {
     2428    wineItem->state = tvItem->state;
     2429    wineItem->stateMask = tvItem->stateMask;
     2430  }
     2431
     2432  wineItem->calculated = FALSE;
     2433  TREEVIEW_QueueRefresh(hwnd);
     2434
     2435  return (LRESULT) iItem;
    24182436}
    24192437
     
    26342652
    26352653  if (wParam == SIZE_RESTORED)
    2636   {
    26372654    if (TREEVIEW_CalcItems(hwnd,0,infoPtr))
    2638 #if 1 //CB: synchron update conflicts with Odin32 implementation -> check and fix
    2639       TREEVIEW_QueueRefresh(hwnd);
    2640 #else
    2641       TREEVIEW_Refresh(hwnd); //because size redraw isn't set
    2642 #endif
    2643   }
     2655      TREEVIEW_Refresh(hwnd);
    26442656
    26452657  return TRUE;
     
    26892701
    26902702  /* set default settings */
    2691   infoPtr->uInternalStatus = 0;
     2703  infoPtr->uInternalStatus = TV_CALCALL;
    26922704  if (IsWindowUnicode(hwnd)) infoPtr->uInternalStatus |= TV_UNICODE;
    26932705  infoPtr->uNumItems = 0;
     
    26952707  infoPtr->clrLine = GetSysColor (COLOR_WINDOWTEXT);
    26962708  infoPtr->clrInsertMark = GetSysColor (COLOR_BTNTEXT);
    2697   infoPtr->cy = 0;
    2698   infoPtr->cx = 0;
     2709  infoPtr->lefttop.y = 0;
     2710  infoPtr->lefttop.x = 0;
    26992711  infoPtr->uIndent = 15;
    27002712  infoPtr->himlNormal = NULL;
     
    27022714  infoPtr->uItemHeight = -1;
    27032715  infoPtr->uRealItemHeight = 0;
     2716  infoPtr->uVScrollStep = 1;
    27042717  infoPtr->uVisibleHeight = lpcs->cy;
    27052718  infoPtr->uTotalHeight = 0;
     
    27252738  infoPtr->uISearchLen = 0;
    27262739
     2740  infoPtr->tipItem = 0;
    27272741  infoPtr->hwndToolTip = 0;
    27282742  if (!(dwStyle & TVS_NOTOOLTIPS))
     
    27522766    ZeroMemory (&ti, sizeof(TTTOOLINFOA));
    27532767    ti.cbSize   = sizeof(TTTOOLINFOA);
    2754     ti.uFlags   = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT;
     2768    ti.uFlags   = TTF_TRACK | TTF_ABSOLUTE;
    27552769    ti.hwnd     = hwnd;
    27562770    ti.uId      = 0;
    2757     ti.lpszText = "Test"; /* LPSTR_TEXTCALLBACK; */
     2771    ti.lpszText = "";
    27582772    SetRectEmpty (&ti.rect);
    27592773
     
    28872901TREEVIEW_SendTreeviewNotify (HWND hwnd, UINT code, UINT action,
    28882902                        HTREEITEM oldItem, HTREEITEM newItem)
    2889 
    28902903{
    28912904  TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
     
    28952908  BOOL unicode = IsWindowUnicode(parent),rc;
    28962909  CHAR *oldText = NULL,*newText = NULL;
    2897 
    2898 //  TRACE (treeview,"code:%x action:%x olditem:%x newitem:%x\n",
    2899 //                code,action,(INT)oldItem,(INT)newItem);
    29002910
    29012911  ZeroMemory(&nmhdr,sizeof(NMTREEVIEWW));
     
    29792989  TREEVIEW_ITEM  *wineItem;
    29802990
    2981 //  TRACE (treeview,"code:%x dragitem:%x\n", code,(INT)dragItem);
    2982 
    29832991  nmhdr.hdr.hwndFrom = hwnd;
    29842992  nmhdr.hdr.idFrom =  GetWindowLongA( hwnd, GWL_ID);
     
    30783086  LPNMCUSTOMDRAW nmcd;
    30793087
    3080 //  TRACE (treeview,"drawstage:%lx hdc:%x\n", dwDrawStage, hdc);
    3081 
    30823088  nmcd= & nmcdhdr.nmcd;
    30833089  nmcd->hdr.hwndFrom = hwnd;
     
    30853091  nmcd->hdr.code   = NM_CUSTOMDRAW;
    30863092  nmcd->dwDrawStage= dwDrawStage;
    3087   nmcd->hdc                = hdc;
     3093  nmcd->hdc        = hdc;
    30883094  nmcd->rc.left    = rc.left;
    30893095  nmcd->rc.right   = rc.right;
     
    32193225      if (flag & TVE_EXPANDPARTIAL)
    32203226      {
    3221         //TRACE(treeview, "  case TVE_EXPANDPARTIAL\n");
    3222         //FIXME (treeview, "TVE_EXPANDPARTIAL not implemented\n");
    32233227return FALSE; //CB: to check
    32243228        wineItem->state ^=TVIS_EXPANDED;
     
    36233627  ht.pt.y = (INT)HIWORD(lParam);
    36243628
    3625   if (!TREEVIEW_HitTest(hwnd,&ht)) return 0;
     3629  TREEVIEW_HitTest(hwnd,&ht);
    36263630
    36273631  if (ht.hItem)
    36283632  {
     3633    DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
     3634
    36293635    item = &infoPtr->items[(INT)ht.hItem];
     3636
     3637    if (infoPtr->hwndToolTip && ((item->text.left < 0) || (item->text.right > infoPtr->uVisibleWidth)) && (infoPtr->tipItem != item->hItem))
     3638    {
     3639      DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
     3640      LPWSTR text;
     3641      TTTOOLINFOW ti;
     3642      POINT pt;
     3643
     3644      if(dwStyle & TVS_INFOTIP)
     3645      {
     3646        NMTVGETINFOTIPW tvgit;
     3647        HWND parent = GetParent(hwnd);
     3648        BOOL unicode = IsWindowUnicode(parent);
     3649
     3650        tvgit.hdr.hwndFrom = hwnd;
     3651        tvgit.hdr.idFrom   =  GetWindowLongA(hwnd,GWL_ID);
     3652        tvgit.hdr.code     = unicode ? TVN_GETINFOTIPW:TVN_GETINFOTIPA;
     3653        tvgit.pszText    = COMCTL32_Alloc(unicode ? INFOTIPSIZE*sizeof(WCHAR):INFOTIPSIZE*sizeof(CHAR));
     3654        tvgit.cchTextMax = INFOTIPSIZE;
     3655        tvgit.hItem      = item->hItem;
     3656        tvgit.lParam     = item->lParam;
     3657
     3658        if (unicode)
     3659        {
     3660          SendMessageW(parent,WM_NOTIFY,(WPARAM)tvgit.hdr.idFrom,(LPARAM)&tvgit);
     3661          text = tvgit.pszText;
     3662        } else
     3663        {
     3664          SendMessageA(parent,WM_NOTIFY,(WPARAM)tvgit.hdr.idFrom,(LPARAM)&tvgit);
     3665          text = COMCTL32_Alloc(tvgit.cchTextMax*sizeof(WCHAR));
     3666          lstrcpyAtoW(text,(LPSTR)tvgit.pszText);
     3667        }
     3668      } else
     3669      {
     3670        if (item->pszText == LPSTR_TEXTCALLBACKW)
     3671          TREEVIEW_SendDispInfoNotify(hwnd,item,TVN_GETDISPINFO,TVIF_TEXT);
     3672
     3673        text = item->pszText;
     3674      }
     3675#if 0 //CB: not yet
     3676      infoPtr->tipItem = item->hItem;
     3677      ti.cbSize   = sizeof(ti);
     3678      ti.uId      = 0;
     3679      ti.hwnd     = hwnd;
     3680      ti.hinst    = 0;
     3681      ti.lpszText = text;
     3682      pt.x = ti.rect.left;
     3683      pt.y = ti.rect.top;
     3684      ClientToScreen(hwnd,&pt);
     3685      SendMessageA(infoPtr->hwndToolTip,TTM_TRACKPOSITION,0,(LPARAM)MAKELPARAM(pt.x,pt.y));
     3686      SendMessageA(infoPtr->hwndToolTip,TTM_UPDATETIPTEXTW,0,(LPARAM)&ti);
     3687      SendMessageA(infoPtr->hwndToolTip,TTM_TRACKACTIVATE,(WPARAM)TRUE,(LPARAM)&ti);
     3688#endif
     3689      if (text != item->pszText) COMCTL32_Free(text);
     3690    }
     3691
     3692    if (dwStyle & TVS_TRACKSELECT)
     3693    {
     3694      //CB: todo: hottracking
     3695    }
    36303696  }
    36313697
     
    36663732  if (ht.flags & TVHT_ONITEMBUTTON)
    36673733  {
    3668      TREEVIEW_Expand (hwnd, (WPARAM) TVE_TOGGLE, (LPARAM) ht.hItem);
    3669      goto setfocus;
    3670   }
    3671   else if (bTrack)
    3672   {
    3673      if (TREEVIEW_TrackMouse(hwnd, ht.pt))
    3674      {
    3675         TREEVIEW_SendTreeviewDnDNotify (hwnd, TVN_BEGINDRAG, ht.hItem, ht.pt);
    3676         infoPtr->dropItem = ht.hItem;
    3677         return 0;
    3678      }
     3734    TREEVIEW_Expand (hwnd, (WPARAM) TVE_TOGGLE, (LPARAM) ht.hItem);
     3735    goto setfocus;
     3736  } else if (bTrack)
     3737  {
     3738    if (TREEVIEW_TrackMouse(hwnd, ht.pt))
     3739    {
     3740      TREEVIEW_SendTreeviewDnDNotify (hwnd, TVN_BEGINDRAG, ht.hItem, ht.pt);
     3741      infoPtr->dropItem = ht.hItem;
     3742      return 0;
     3743    }
    36793744  }
    36803745
     
    36863751   * and the click occured on the item label...
    36873752   */
    3688   if ( ( dwStyle & TVS_EDITLABELS ) &&
    3689        ( ht.flags & TVHT_ONITEMLABEL ) &&
    3690        ( infoPtr->selectedItem == ht.hItem ) )
    3691   {
    3692        if (infoPtr->Timer & TV_EDIT_TIMER_SET)
    3693           KillTimer (hwnd, TV_EDIT_TIMER);
    3694 
    3695        infoPtr->editItem = ht.hItem;
    3696        SetTimer (hwnd, TV_EDIT_TIMER, GetDoubleClickTime(), 0);
    3697        infoPtr->Timer|=TV_EDIT_TIMER_SET;
     3753  if ((dwStyle & TVS_EDITLABELS) && (ht.flags & TVHT_ONITEMLABEL) && (infoPtr->selectedItem == ht.hItem))
     3754  {
     3755    if (infoPtr->Timer & TV_EDIT_TIMER_SET)
     3756      KillTimer (hwnd, TV_EDIT_TIMER);
     3757
     3758    infoPtr->editItem = ht.hItem;
     3759    SetTimer (hwnd, TV_EDIT_TIMER, GetDoubleClickTime(), 0);
     3760    infoPtr->Timer|=TV_EDIT_TIMER_SET;
     3761  } else if (ht.flags & (TVHT_ONITEMLABEL | TVHT_ONITEMICON))
     3762  {
     3763    TREEVIEW_DoSelectItem(hwnd,TVGN_CARET,ht.hItem,TVC_BYMOUSE);
     3764  } else if (ht.flags & TVHT_ONITEMSTATEICON)
     3765  {
     3766    if (dwStyle & TVS_CHECKBOXES)  /* TVS_CHECKBOXES requires _us_ */
     3767    {                              /* to toggle the current state  */
     3768      int state;
     3769      TREEVIEW_ITEM *wineItem;
     3770
     3771      wineItem = TREEVIEW_ValidItem(infoPtr, ht.hItem);
     3772
     3773      state = 1-(wineItem->state>>12);
     3774      wineItem->state &= ~TVIS_STATEIMAGEMASK;
     3775      wineItem->state |= state<<12;
     3776      if (wineItem->visible)
     3777      {
     3778        TREEVIEW_UnqueueRefresh(hwnd,TRUE,TRUE);
     3779        InvalidateRect(hwnd,&wineItem->statebitmap,TRUE);
    36983780      }
    3699   else if ( ht.flags & (TVHT_ONITEMLABEL | TVHT_ONITEMICON))
    3700   {
    3701      TREEVIEW_DoSelectItem ( hwnd, TVGN_CARET, ht.hItem, TVC_BYMOUSE);
    3702   }
    3703   else if (ht.flags & TVHT_ONITEMSTATEICON)
    3704   {
    3705      if (dwStyle & TVS_CHECKBOXES)  /* TVS_CHECKBOXES requires _us_ */
    3706      {                              /* to toggle the current state  */
    3707        int state;
    3708        TREEVIEW_ITEM *wineItem;
    3709 
    3710        wineItem = TREEVIEW_ValidItem(infoPtr, ht.hItem);
    3711 
    3712        state = 1-(wineItem->state>>12);
    3713        wineItem->state &= ~TVIS_STATEIMAGEMASK;
    3714        wineItem->state |= state<<12;
    3715        if (wineItem->visible)
    3716        {
    3717          TREEVIEW_UnqueueRefresh(hwnd,TRUE,TRUE);
    3718          InvalidateRect(hwnd,&wineItem->statebitmap,TRUE);
    3719        }
    3720      }
     3781    }
    37213782  }
    37223783
    37233784setfocus:
    37243785  SetFocus (hwnd);
     3786
    37253787  return 0;
    37263788}
     
    37993861 hOldFont=SelectObject (hdc, infoPtr->hFont);
    38003862 GetTextExtentPoint32W (hdc, itemtxt, lstrlenW (itemtxt), &size);
    3801 // TRACE (treeview,"%d %d %s %d\n",size.cx,size.cy,itemtxt,lstrlenA(itemtxt));
     3863
    38023864 hbmp=CreateCompatibleBitmap (htopdc, size.cx, size.cy);
    38033865 hOldbmp=SelectObject (hdc, hbmp);
     
    38373899  TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
    38383900  TREEVIEW_ITEM *prevItem,*wineItem;
     3901  DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
    38393902  INT prevSelect;
    38403903
     
    38673930
    38683931      if (newSelect)
    3869         if (TREEVIEW_SendTreeviewNotify(
    3870               hwnd,
    3871               TVN_SELCHANGING,
    3872               cause,
    3873               (HTREEITEM)prevSelect,
    3874               (HTREEITEM)newSelect))
     3932        if (TREEVIEW_SendTreeviewNotify(hwnd,TVN_SELCHANGING,cause,(HTREEITEM)prevSelect,(HTREEITEM)newSelect))
    38753933          return FALSE;       /* FIXME: OK? */
    38763934
     
    38823940      infoPtr->selectedItem = (HTREEITEM)newSelect;
    38833941
     3942      if ((cause == TVC_BYMOUSE) && (dwStyle & TVS_SINGLEEXPAND))
     3943      {
     3944        BOOL control = GetKeyState(VK_CONTROL) & 0x8000;
     3945        UINT rc = TREEVIEW_SendTreeviewNotify(hwnd,TVN_SINGLEEXPAND,0,prevItem->hItem,wineItem->hItem);
     3946
     3947        if (!(rc & TVNRET_SKIPOLD) && !control && prevItem->state & TVIS_EXPANDED)
     3948          TREEVIEW_Expand(hwnd,TVE_COLLAPSE,(LPARAM)prevItem->hItem);
     3949        if (!(rc & TVNRET_SKIPNEW) && TREEVIEW_HasChildren(hwnd,wineItem))
     3950          TREEVIEW_Expand(hwnd,TVE_TOGGLE,(LPARAM)wineItem->hItem);
     3951      }
     3952
    38843953      TREEVIEW_UnqueueRefresh(hwnd,TRUE,TRUE);
    38853954      TREEVIEW_RefreshItem(hwnd,prevItem,FALSE);
    38863955      TREEVIEW_RefreshItem(hwnd,wineItem,FALSE);
    38873956
    3888       TREEVIEW_SendTreeviewNotify(
    3889         hwnd,
    3890         TVN_SELCHANGED,
    3891         cause,
    3892         (HTREEITEM)prevSelect,
    3893         (HTREEITEM)newSelect);
     3957      TREEVIEW_SendTreeviewNotify(hwnd,TVN_SELCHANGED,cause,(HTREEITEM)prevSelect,(HTREEITEM)newSelect);
    38943958
    38953959      break;
     
    39143978    case TVGN_FIRSTVISIBLE:
    39153979    {
     3980      TREEVIEW_ITEM *firstVis;
    39163981      INT scrollY;
     3982
     3983      if (!infoPtr->firstVisible) return FALSE;
     3984
     3985      firstVis = &infoPtr->items[(INT)infoPtr->firstVisible];
    39173986
    39183987      if (wineItem->rect.top < 0)
     
    39203989      else
    39213990      {
    3922         scrollY = MIN(wineItem->rect.top,infoPtr->uTotalHeight-infoPtr->uVisibleHeight);
    3923         if (scrollY < 0) scrollY = 0;
     3991        scrollY = MIN(wineItem->rect.top,(infoPtr->uTotalHeight-infoPtr->uVisibleHeight)-infoPtr->lefttop.y);
     3992        scrollY -= scrollY % infoPtr->uVScrollStep;
    39243993      }
    39253994
    39263995      if (scrollY != 0)
    39273996      {
    3928         infoPtr->cy += scrollY;
     3997        infoPtr->lefttop.y += scrollY;
    39293998        if (!TREEVIEW_UnqueueRefresh(hwnd,TRUE,TRUE))
    39303999          TREEVIEW_CalcItems(hwnd,0,infoPtr);
     
    39744043  infoPtr->hBoldFont = CreateFontIndirectA (&logFont);
    39754044
    3976   hdc = GetDC(hwnd);
    3977   hOldFont = SelectObject (hdc, hFont);
    3978   GetTextMetricsA (hdc, &tm);
    3979   height= tm.tmHeight + tm.tmExternalLeading;
    3980   if (height > infoPtr->uRealItemHeight)
    3981     infoPtr->uRealItemHeight = height;
    3982   SelectObject (hdc, hOldFont);
    3983   ReleaseDC(hwnd,hdc);
     4045  infoPtr->uInternalStatus |= TV_CALCALL;
     4046  TREEVIEW_CalcItems(hwnd,0,infoPtr);
    39844047
    39854048  if (lParam)
    39864049  {
    39874050    TREEVIEW_UnqueueRefresh(hwnd,FALSE,FALSE);
    3988     infoPtr->uInternalStatus |= TV_CALCALL;
    3989     TREEVIEW_CalcItems(hwnd,0,infoPtr);
    39904051    TREEVIEW_Refresh(hwnd);
    3991   } else infoPtr->uInternalStatus |= TV_CALCALL;
     4052  }
    39924053
    39934054  return 0;
    39944055}
    3995 
    39964056
    39974057static LRESULT
     
    39994059{
    40004060  TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
    4001   int maxHeight;
    4002   int lastPos = infoPtr->cy;
     4061  INT scrollY;
     4062  INT maxY = infoPtr->uTotalHeight-infoPtr->uVisibleHeight;
    40034063
    40044064  if (!(infoPtr->uInternalStatus & TV_VSCROLL)) return FALSE;
     
    40074067  {
    40084068    case SB_LINEUP:
    4009       if (!infoPtr->cy) return FALSE;
    4010       infoPtr->cy -= infoPtr->uRealItemHeight;
    4011       if (infoPtr->cy < 0) infoPtr->cy = 0;
     4069      scrollY = MIN(infoPtr->uVScrollStep,infoPtr->lefttop.y);
    40124070      break;
    40134071
    40144072    case SB_LINEDOWN:
    4015       maxHeight = infoPtr->uTotalHeight-infoPtr->uVisibleHeight;
    4016       if (maxHeight <= 0) return FALSE;
    4017       if (infoPtr->cy == maxHeight) return FALSE;
    4018       infoPtr->cy += infoPtr->uRealItemHeight;
    4019       if (infoPtr->cy > maxHeight)
    4020         infoPtr->cy = maxHeight;
     4073      scrollY = -infoPtr->uVScrollStep;
     4074      if (infoPtr->lefttop.y-scrollY > maxY) scrollY = -(maxY-infoPtr->lefttop.y);
    40214075      break;
    40224076
    40234077    case SB_PAGEUP:
    4024       if (!infoPtr->cy) return FALSE;
    4025       infoPtr->cy -= infoPtr->uVisibleHeight;
    4026       if (infoPtr->cy < 0) infoPtr->cy = 0;
     4078      scrollY = MIN(infoPtr->uVisibleHeight,infoPtr->lefttop.y);
    40274079      break;
    40284080
    40294081    case SB_PAGEDOWN:
    4030       maxHeight = infoPtr->uTotalHeight-infoPtr->uVisibleHeight;
    4031       if (maxHeight <= 0) return FALSE;
    4032       if (infoPtr->cy == maxHeight) return FALSE;
    4033       infoPtr->cy += infoPtr->uVisibleHeight;
    4034       if (infoPtr->cy > maxHeight)
    4035         infoPtr->cy = maxHeight;
     4082      scrollY = -infoPtr->uVisibleHeight;
     4083      if (infoPtr->lefttop.y-scrollY > maxY) scrollY = -(maxY-infoPtr->lefttop.y);
     4084      if (scrollY > 0) scrollY = 0;
    40364085      break;
    40374086
    40384087    case SB_THUMBTRACK:
    4039       maxHeight = infoPtr->uTotalHeight-infoPtr->uVisibleHeight;
    4040       if (maxHeight <= 0) return FALSE;
    4041       infoPtr->cy = HIWORD(wParam);
    4042       if (infoPtr->cy < 0) infoPtr->cy = 0;
    4043       if (infoPtr->cy > maxHeight) infoPtr->cy = maxHeight;
     4088      scrollY = infoPtr->lefttop.y-HIWORD(wParam);
    40444089      break;
    40454090
     
    40484093  }
    40494094
    4050   if (lastPos != infoPtr->cy)
    4051   {
     4095  scrollY -= scrollY % infoPtr->uVScrollStep; //CB: todo
     4096
     4097  if (scrollY != 0)
     4098  {
     4099    infoPtr->lefttop.y -= scrollY;
    40524100    if (!TREEVIEW_UnqueueRefresh(hwnd,TRUE,TRUE))
    40534101      TREEVIEW_CalcItems(hwnd,0,infoPtr);
    4054     ScrollWindowEx(hwnd,0,lastPos-infoPtr->cy,NULL,NULL,0,NULL,SW_INVALIDATE | SW_SCROLLCHILDREN | (infoPtr->uScrollTime << 16));
     4102    ScrollWindowEx(hwnd,0,scrollY,NULL,NULL,0,NULL,SW_INVALIDATE | SW_SCROLLCHILDREN | (infoPtr->uScrollTime << 16));
    40554103
    40564104    return TRUE;
     
    40654113  TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
    40664114  int maxWidth;
    4067   int lastPos = infoPtr->cx;
     4115  int lastPos = infoPtr->lefttop.x;
    40684116
    40694117  if (!(infoPtr->uInternalStatus & TV_HSCROLL)) return FALSE;
     
    40724120  {
    40734121    case SB_LINEUP:
    4074       if (!infoPtr->cx) return FALSE;
    4075       infoPtr->cx -= infoPtr->uRealItemHeight;
    4076       if (infoPtr->cx < 0) infoPtr->cx = 0;
     4122      if (!infoPtr->lefttop.x) return FALSE;
     4123      infoPtr->lefttop.x -= infoPtr->uRealItemHeight;
     4124      if (infoPtr->lefttop.x < 0) infoPtr->lefttop.x = 0;
    40774125      break;
    40784126
     
    40804128      maxWidth = infoPtr->uTotalWidth-infoPtr->uVisibleWidth;
    40814129      if (maxWidth <= 0) return FALSE;
    4082       if (infoPtr->cx == maxWidth) return FALSE;
    4083       infoPtr->cx += infoPtr->uRealItemHeight; /*FIXME */
    4084       if (infoPtr->cx > maxWidth)
    4085         infoPtr->cx = maxWidth;
     4130      if (infoPtr->lefttop.x == maxWidth) return FALSE;
     4131      infoPtr->lefttop.x += infoPtr->uRealItemHeight; /*FIXME */
     4132      if (infoPtr->lefttop.x > maxWidth)
     4133        infoPtr->lefttop.x = maxWidth;
    40864134      break;
    40874135
    40884136    case SB_PAGEUP:
    4089       if (!infoPtr->cx) return FALSE;
    4090       infoPtr->cx -= infoPtr->uVisibleWidth;
    4091       if (infoPtr->cx < 0) infoPtr->cx = 0;
     4137      if (!infoPtr->lefttop.x) return FALSE;
     4138      infoPtr->lefttop.x -= infoPtr->uVisibleWidth;
     4139      if (infoPtr->lefttop.x < 0) infoPtr->lefttop.x = 0;
    40924140      break;
    40934141
     
    40954143      maxWidth = infoPtr->uTotalWidth-infoPtr->uVisibleWidth;
    40964144      if (maxWidth <= 0) return FALSE;
    4097       if (infoPtr->cx == maxWidth) return FALSE;
    4098       infoPtr->cx += infoPtr->uVisibleWidth;
    4099       if (infoPtr->cx > maxWidth)
    4100         infoPtr->cx = maxWidth;
     4145      if (infoPtr->lefttop.x == maxWidth) return FALSE;
     4146      infoPtr->lefttop.x += infoPtr->uVisibleWidth;
     4147      if (infoPtr->lefttop.x > maxWidth)
     4148        infoPtr->lefttop.x = maxWidth;
    41014149      break;
    41024150
     
    41044152      maxWidth = infoPtr->uTotalWidth-infoPtr->uVisibleWidth;
    41054153      if (maxWidth <= 0) return FALSE;
    4106       infoPtr->cx = HIWORD(wParam);
    4107       if (infoPtr->cx < 0) infoPtr->cx = 0;
    4108       if (infoPtr->cx > maxWidth) infoPtr->cx = maxWidth;
     4154      infoPtr->lefttop.x = HIWORD(wParam);
     4155      if (infoPtr->lefttop.x < 0) infoPtr->lefttop.x = 0;
     4156      if (infoPtr->lefttop.x > maxWidth) infoPtr->lefttop.x = maxWidth;
    41094157      break;
    41104158
     
    41134161  }
    41144162
    4115   if (lastPos != infoPtr->cx)
     4163  if (lastPos != infoPtr->lefttop.x)
    41164164  {
    41174165    if (!TREEVIEW_UnqueueRefresh(hwnd,TRUE,TRUE))
    41184166      TREEVIEW_CalcItems(hwnd,0,infoPtr);
    4119     ScrollWindowEx(hwnd,lastPos-infoPtr->cx,0,NULL,NULL,0,NULL,SW_INVALIDATE | SW_SCROLLCHILDREN | (infoPtr->uScrollTime << 16));
     4167    ScrollWindowEx(hwnd,lastPos-infoPtr->lefttop.x,0,NULL,NULL,0,NULL,SW_INVALIDATE | SW_SCROLLCHILDREN | (infoPtr->uScrollTime << 16));
    41204168
    41214169    return TRUE;
     
    41444192    {
    41454193        int wheelDy = pulScrollLines * infoPtr->uRealItemHeight;
    4146         int newDy = infoPtr->cy + wheelDy;
    4147         int maxDy = infoPtr->uTotalHeight - infoPtr->uVisibleHeight;
     4194        int newDy = infoPtr->lefttop.y + wheelDy;
     4195        int maxDy = infoPtr->uTotalHeight-infoPtr->uVisibleHeight;
    41484196
    41494197        if (newDy > maxDy) newDy = maxDy;
    41504198        if (newDy < 0) newDy = 0;
    41514199
    4152         if (newDy == infoPtr->cy) return TRUE;
     4200        if (newDy == infoPtr->lefttop.y) return TRUE;
    41534201
    41544202        TREEVIEW_VScroll(hwnd, MAKEWPARAM(SB_THUMBTRACK,newDy),0);
     
    43294377  if (hNewSelection)
    43304378  {
    4331     if ( TREEVIEW_DoSelectItem(
    4332            hwnd,
    4333            TVGN_CARET,
    4334            (HTREEITEM)hNewSelection,
    4335            TVC_BYKEYBOARD))
     4379    if (TREEVIEW_DoSelectItem(hwnd,TVGN_CARET,(HTREEITEM)hNewSelection,TVC_BYKEYBOARD))
    43364380    {
    43374381      TREEVIEW_EnsureVisible(hwnd,hNewSelection);
     
    43974441    scrollY = item->rect.top;
    43984442  else if (item->rect.bottom > rect.bottom)
     4443  {
     4444    INT mod;
     4445
    43994446    scrollY = item->rect.bottom-rect.bottom;
    4400   else return FALSE;
     4447    mod = scrollY % infoPtr->uVScrollStep;
     4448    if (mod) scrollY += infoPtr->uVScrollStep-mod;
     4449  } else return FALSE;
    44014450
    44024451  if (scrollY != 0)
    44034452  {
    4404     infoPtr->cy += scrollY;
     4453    infoPtr->lefttop.y += scrollY;
    44054454    TREEVIEW_CalcItems(hwnd,0,infoPtr);
    44064455    ScrollWindowEx(hwnd,0,-scrollY,NULL,NULL,0,NULL,SW_INVALIDATE | SW_SCROLLCHILDREN | (infoPtr->uScrollTime << 16));
     
    44224471}
    44234472
    4424 static TREEVIEW_ITEM* TREEVIEW_SearchChildren(HWND hwnd,TREEVIEW_INFO *infoPtr,TREEVIEW_ITEM *item,TREEVIEW_ITEM *stop,LPWSTR text,INT textlen)
    4425 {
    4426   TREEVIEW_ITEM *child,*child2;
    4427 
    4428   if (!(item->firstChild && (item->state & TVIS_EXPANDED))) return NULL;
    4429 
    4430   child = &infoPtr->items[(INT)item->firstChild];
    4431   while (child)
    4432   {
    4433     if (child == stop) return NULL;
    4434     if (TREEVIEW_Compare(hwnd,child,text,textlen)) return child;
    4435     child2 = TREEVIEW_SearchChildren(hwnd,infoPtr,child,stop,text,textlen);
    4436     if (child2) return child2;
    4437     if (child->sibling) child = &infoPtr->items[(INT)child->sibling];
    4438     else return NULL;
    4439   }
    4440 
    4441   return NULL;
    4442 }
    4443 
    44444473static TREEVIEW_ITEM* TREEVIEW_Search(HWND hwnd,TREEVIEW_INFO *infoPtr,INT iItem,LPWSTR text,INT textlen)
    44454474{
     
    44494478  item = start = &infoPtr->items[iItem];
    44504479
    4451   if (TREEVIEW_Compare(hwnd,item,text,textlen)) found = TRUE; else
    4452   {
    4453     //search start to end
    4454     while (item->sibling || item->parent)
    4455     {
    4456       TREEVIEW_ITEM *child = TREEVIEW_SearchChildren(hwnd,infoPtr,item,NULL,text,textlen);
    4457 
    4458       if (child)
    4459       {
    4460         found = TRUE;
    4461         item = child;
    4462         break;
    4463       }
    4464 
     4480  //search start to end
     4481  while (item)
     4482  {
     4483    if (TREEVIEW_Compare(hwnd,item,text,textlen)) return item;
     4484    item = TREEVIEW_GetNextListItem(hwnd,infoPtr,item);
     4485  }
     4486  if (!found)
     4487  {
     4488    iItem = (INT)infoPtr->TopRootItem;
     4489    item = &infoPtr->items[iItem];
     4490
     4491    //search first to start
     4492    while (item != start)
     4493    {
     4494      if (TREEVIEW_Compare(hwnd,item,text,textlen)) return item;
    44654495      item = TREEVIEW_GetNextListItem(hwnd,infoPtr,item);
    4466       if (item && TREEVIEW_Compare(hwnd,item,text,textlen))
    4467       {
    4468         found = TRUE;
    4469         break;
    4470       }
    44714496    }
    4472     if (!found)
    4473     {
    4474       iItem = (INT)infoPtr->TopRootItem;
    4475       item = &infoPtr->items[iItem];
    4476       //search first to start
    4477       while (item != start)
    4478       {
    4479         TREEVIEW_ITEM *child;
    4480 
    4481         if (TREEVIEW_Compare(hwnd,item,text,textlen))
    4482         {
    4483           found = TRUE;
    4484           break;
    4485         }
    4486         child = TREEVIEW_SearchChildren(hwnd,infoPtr,item,start,text,textlen);
    4487 
    4488         if (child)
    4489         {
    4490           found = TRUE;
    4491           item = child;
    4492           break;
    4493         }
    4494         if (item->sibling) item = &infoPtr->items[(INT)item->sibling];
    4495         else break;
    4496       }
    4497     }
    4498   }
    4499 
    4500   return found ? item:NULL;
    4501 }
     4497  }
     4498
     4499  return NULL;
     4500}
     4501
     4502//CB: this method is CPU intense: optimize it and use a secondary thread
    45024503
    45034504static VOID TREEVIEW_ISearch(HWND hwnd,CHAR ch)
     
    45344535
    45354536  iItem = infoPtr->selectedItem ? (INT)infoPtr->selectedItem:(INT)infoPtr->TopRootItem;
     4537
     4538  if (infoPtr->selectedItem)
     4539  {
     4540    item = &infoPtr->items[iItem];
     4541    item = TREEVIEW_GetNextListItem(hwnd,infoPtr,item);
     4542    if (!item) item = &infoPtr->items[(INT)infoPtr->TopRootItem];
     4543    iItem = (INT)item->hItem;
     4544  } else iItem = (INT)infoPtr->TopRootItem;
     4545
    45364546  item = TREEVIEW_Search(hwnd,infoPtr,iItem,newString,len);
    4537   if (!item && infoPtr->pszISearch)
     4547  if (!item && infoPtr->selectedItem && infoPtr->pszISearch)
    45384548  {
    45394549    TREEVIEW_ITEM *next;
    4540 //CB: todo: must press key twice to go to the next item
     4550
    45414551    item = &infoPtr->items[iItem];
    4542     next = TREEVIEW_GetNextListItem(hwnd,infoPtr,item);
    4543     if (!next) next = &infoPtr->items[(INT)infoPtr->TopRootItem];
    4544     if (next && (next != item))
    4545     {
    4546       next = TREEVIEW_Search(hwnd,infoPtr,(INT)next->hItem,infoPtr->pszISearch,infoPtr->uISearchLen);
    4547       if (next)
    4548         TREEVIEW_SelectItem(hwnd,(WPARAM)TVGN_CARET,(LPARAM)next->hItem);
     4552    next = TREEVIEW_Search(hwnd,infoPtr,(INT)item->hItem,infoPtr->pszISearch,infoPtr->uISearchLen);
     4553    if (next)
     4554    {
     4555      TREEVIEW_SelectItem(hwnd,(WPARAM)TVGN_CARET,(LPARAM)next->hItem);
     4556      TREEVIEW_EnsureVisible(hwnd,next->hItem);
    45494557    }
    45504558    COMCTL32_Free(newString);
     
    45594567    infoPtr->uISearchLen = len;
    45604568    TREEVIEW_SelectItem(hwnd,(WPARAM)TVGN_CARET,(LPARAM)item->hItem);
     4569    TREEVIEW_EnsureVisible(hwnd,item->hItem);
    45614570    SetTimer(hwnd,TV_ISEARCH_TIMER,TV_ISEARCH_DELAY,0);
    45624571    infoPtr->Timer |= TV_ISEARCH_TIMER_SET;
     
    46874696
    46884697        case TVM_SORTCHILDREN:
    4689                 //@@@PH 1999/10/25 TREEVIEW_SortChildrenCB is wrong
    46904698                return TREEVIEW_SortChildren(hwnd, wParam, lParam);
    46914699
Note: See TracChangeset for help on using the changeset viewer.