Changeset 10165 for trunk/src


Ignore:
Timestamp:
Jul 14, 2003, 4:00:08 PM (22 years ago)
Author:
sandervl
Message:

KOM: Ascii/Unicode conversion fixes (DBCS)

Location:
trunk/src/comctl32
Files:
2 edited

Legend:

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

    r10098 r10165  
    222222    add_flag(PSH_NOCONTEXTHELP);
    223223    if (string[0] != '\0')
    224         FIXME("%s\n", string);
     224    FIXME("%s\n", string);
    225225}
    226226#undef add_flag
     
    294294  memcpy(&psInfo->ppshheader,lppsh,dwSize);
    295295  TRACE("\n** PROPSHEETHEADER **\ndwSize\t\t%ld\ndwFlags\t\t%08lx\nhwndParent\t%p\nhInstance\t%p\npszCaption\t'%s'\nnPages\t\t%d\npfnCallback\t%p\n",
    296         lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
    297         debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
     296    lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
     297    debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
    298298
    299299  PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
     
    301301  if (HIWORD(lppsh->pszCaption))
    302302  {
     303#ifdef __WIN32OS2__
     304     int len = MultiByteToWideChar( CP_ACP, 0, lppsh->pszCaption, -1, 0, 0 );
     305     psInfo->ppshheader.pszCaption = HeapAlloc( GetProcessHeap(), 0, len*sizeof (WCHAR) );
     306     MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, (LPWSTR) psInfo->ppshheader.pszCaption, len);
     307#else
    303308     int len = strlen(lppsh->pszCaption);
    304309     psInfo->ppshheader.pszCaption = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof (WCHAR) );
    305310     MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, (LPWSTR) psInfo->ppshheader.pszCaption, len+1);
     311#endif
    306312     /* strcpy( (char *)psInfo->ppshheader.pszCaption, lppsh->pszCaption ); */
    307313  }
     
    507513      {
    508514        pTitle = pszNull;
    509         FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
     515    FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
    510516      }
    511517      else
     
    538544    {
    539545      if (psInfo->hImageList == 0 )
    540         psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
     546    psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
    541547
    542548      ImageList_AddIcon(psInfo->hImageList, hIcon);
     
    826832  TRACE("Biggest page %ld %ld %ld %ld\n", rc.left, rc.top, rc.right, rc.bottom);
    827833  TRACE("   constants padx=%d, pady=%d, butH=%d, lH=%d\n",
    828         padding.x, padding.y, buttonHeight, lineHeight);
     834    padding.x, padding.y, buttonHeight, lineHeight);
    829835
    830836  /* Make room */
     
    10921098  if (psInfo->hasHelp)
    10931099  {
    1094         idButton = IDHELP;
     1100    idButton = IDHELP;
    10951101  }
    10961102  else
     
    10981104    if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
    10991105    {
    1100         idButton = IDC_NEXT_BUTTON;
     1106    idButton = IDC_NEXT_BUTTON;
    11011107    }
    11021108    else
    11031109    {
    1104         /* hopefully this is ok */
    1105         idButton = IDCANCEL;
     1110    /* hopefully this is ok */
     1111    idButton = IDCANCEL;
    11061112    }
    11071113  }
     
    11271133
    11281134  if (padding.y < 0)
    1129           ERR("padding negative ! Please report this !\n");
     1135      ERR("padding negative ! Please report this !\n");
    11301136
    11311137  /* this is most probably not correct, but the best we have now */
     
    12551261  /* font, if DS_SETFONT set */
    12561262  if ((DS_SETFONT & ((istemplateex)?  ((MyDLGTEMPLATEEX*)pTemplate)->style :
    1257                      pTemplate->style)))
     1263             pTemplate->style)))
    12581264    {
    12591265      p+=(istemplateex)?3:1;
     
    12681274    {
    12691275      p = (WORD*)(((DWORD)p + 3) & ~3); /* DWORD align */
    1270      
     1276
    12711277      /* skip header */
    12721278      p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
    1273      
     1279
    12741280      /* check class */
    12751281      switch ((WORD)*p)
    1276         {
    1277         case 0x0000:
    1278           p++;
    1279           break;
    1280         case 0xffff:
    1281           TRACE("class ordinal 0x%08lx\n",*(DWORD*)p);
    1282           p += 2;
    1283           break;
    1284         default:
    1285           TRACE("class %s\n",debugstr_w((LPCWSTR)p));
    1286           p += lstrlenW( (LPCWSTR)p ) + 1;
    1287           break;
    1288         }
     1282    {
     1283    case 0x0000:
     1284      p++;
     1285      break;
     1286    case 0xffff:
     1287      TRACE("class ordinal 0x%08lx\n",*(DWORD*)p);
     1288      p += 2;
     1289      break;
     1290    default:
     1291      TRACE("class %s\n",debugstr_w((LPCWSTR)p));
     1292      p += lstrlenW( (LPCWSTR)p ) + 1;
     1293      break;
     1294    }
    12891295
    12901296      /* check title text */
    12911297      switch ((WORD)*p)
    1292         {
    1293         case 0x0000:
    1294           p++;
    1295           break;
    1296         case 0xffff:
    1297           TRACE("text ordinal 0x%08lx\n",*(DWORD*)p);
    1298           p += 2;
    1299           break;
    1300         default:
    1301           TRACE("text %s\n",debugstr_w((LPCWSTR)p));
    1302           p += lstrlenW( (LPCWSTR)p ) + 1;
    1303           break;
    1304         }
     1298    {
     1299    case 0x0000:
     1300      p++;
     1301      break;
     1302    case 0xffff:
     1303      TRACE("text ordinal 0x%08lx\n",*(DWORD*)p);
     1304      p += 2;
     1305      break;
     1306    default:
     1307      TRACE("text %s\n",debugstr_w((LPCWSTR)p));
     1308      p += lstrlenW( (LPCWSTR)p ) + 1;
     1309      break;
     1310    }
    13051311      p += *p + 1;    /* Skip extra data */
    13061312      --nrofitems;
    13071313    }
    1308  
     1314
    13091315  TRACE("%p %p size 0x%08x\n",p, (WORD*)pTemplate,sizeof(WORD)*(p - (WORD*)pTemplate));
    13101316  return (p - (WORD*)pTemplate)*sizeof(WORD);
    1311  
     1317
    13121318}
    13131319
     
    13521358                                    RT_DIALOGW);
    13531359    if(!hResource)
    1354         return FALSE;
     1360    return FALSE;
    13551361
    13561362    resSize = SizeofResource(ppshpage->hInstance, hResource);
     
    13581364    hTemplate = LoadResource(ppshpage->hInstance, hResource);
    13591365    if(!hTemplate)
    1360         return FALSE;
     1366    return FALSE;
    13611367
    13621368    pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
     
    13681374  if (!temp)
    13691375    return FALSE;
    1370  
     1376
    13711377  TRACE("copying pTemplate %p into temp %p (%ld)\n", pTemplate, temp, resSize);
    13721378  memcpy(temp, pTemplate, resSize);
     
    14021408
    14031409  hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
    1404                                         pTemplate,
    1405                                         hwndParent,
    1406                                         ppshpage->pfnDlgProc,
    1407                                         (LPARAM)ppshpage);
     1410                    pTemplate,
     1411                    hwndParent,
     1412                    ppshpage->pfnDlgProc,
     1413                    (LPARAM)ppshpage);
    14081414  /* Free a no more needed copy */
    14091415  if(temp)
     
    14281434      padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
    14291435      TRACE("setting page %08lx, rc (%ld,%ld)-(%ld,%ld) w=%d, h=%d, padx=%d, pady=%d\n",
    1430             (DWORD)hwndPage, rc.left, rc.top, rc.right, rc.bottom,
    1431             pageWidth, pageHeight, padding.x, padding.y);
     1436        (DWORD)hwndPage, rc.left, rc.top, rc.right, rc.bottom,
     1437        pageWidth, pageHeight, padding.x, padding.y);
    14321438      SetWindowPos(hwndPage, HWND_TOP,
    1433                    rc.left + padding.x/2,
    1434                    rc.top + padding.y/2,
    1435                    pageWidth, pageHeight, 0);
     1439           rc.left + padding.x/2,
     1440           rc.top + padding.y/2,
     1441           pageWidth, pageHeight, 0);
    14361442  }
    14371443  else {
     
    14441450      pageHeight = rc.bottom - rc.top;
    14451451      TRACE("setting page %08lx, rc (%ld,%ld)-(%ld,%ld) w=%d, h=%d\n",
    1446             (DWORD)hwndPage, rc.left, rc.top, rc.right, rc.bottom,
    1447             pageWidth, pageHeight);
     1452        (DWORD)hwndPage, rc.left, rc.top, rc.right, rc.bottom,
     1453        pageWidth, pageHeight);
    14481454      SetWindowPos(hwndPage, HWND_TOP,
    1449                    rc.left, rc.top,
    1450                    pageWidth, pageHeight, 0);
     1455           rc.left, rc.top,
     1456           pageWidth, pageHeight, 0);
    14511457  }
    14521458
     
    18971903static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
    18981904                                int index,
    1899                                 int skipdir,
     1905                int skipdir,
    19001906                                HPROPSHEETPAGE hpage
    1901                                 )
     1907                )
    19021908{
    19031909  PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
     
    19211927
    19221928    if (hwndTabControl)
    1923         SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
     1929    SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
    19241930
    19251931    psn.hdr.code     = PSN_SETACTIVE;
     
    19391945      index+=skipdir;
    19401946      if (index < 0) {
    1941         index = 0;
    1942         FIXME("Tried to skip before first property sheet page!\n");
    1943         break;
     1947    index = 0;
     1948    FIXME("Tried to skip before first property sheet page!\n");
     1949    break;
    19441950      }
    19451951      if (index >= psInfo->nPages) {
    1946         FIXME("Tried to skip after last property sheet page!\n");
    1947         index = psInfo->nPages-1;
    1948         break;
     1952    FIXME("Tried to skip after last property sheet page!\n");
     1953    index = psInfo->nPages-1;
     1954    break;
    19491955      }
    19501956    }
     
    19962002     WCHAR szTitle[256];
    19972003     MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
     2004#ifdef __WIN32OS2__
     2005                 szTitle, sizeof( szTitle ) / sizeof( WCHAR ));
     2006#else
    19982007                             szTitle, sizeof szTitle);
     2008#endif
    19992009     PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
    20002010  }
     
    20102020static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
    20112021{
    2012   PropSheetInfo*        psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
    2013   WCHAR                 szTitle[256];
     2022  PropSheetInfo*    psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
     2023  WCHAR         szTitle[256];
    20142024
    20152025  TRACE("'%s' (style %08lx)\n", debugstr_w(lpszText), dwStyle);
     
    24152425                               psInfo, n))
    24162426    {
    2417         if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
    2418             DestroyPropertySheetPage(psInfo->proppage[n].hpage);
    2419         n--;
    2420         psInfo->nPages--;
     2427    if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
     2428        DestroyPropertySheetPage(psInfo->proppage[n].hpage);
     2429    n--;
     2430    psInfo->nPages--;
    24212431    }
    24222432  }
     
    24592469                               psInfo, n))
    24602470    {
    2461         if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
    2462             DestroyPropertySheetPage(psInfo->proppage[n].hpage);
    2463         n--;
    2464         psInfo->nPages--;
     2471    if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
     2472        DestroyPropertySheetPage(psInfo->proppage[n].hpage);
     2473    n--;
     2474    psInfo->nPages--;
    24652475    }
    24662476  }
     
    26232633    case IDOK:
    26242634    case IDC_APPLY_BUTTON:
    2625         {
    2626             HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
    2627 
    2628             if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
    2629                 break;
    2630 
    2631             if (wID == IDOK)
    2632                 {
    2633                     PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
    2634                                                                       PropSheetInfoStr);
    2635                     int result = TRUE;
    2636 
    2637                     if (psInfo->restartWindows)
    2638                         result = ID_PSRESTARTWINDOWS;
    2639 
    2640                     /* reboot system takes precedence over restart windows */
    2641                     if (psInfo->rebootSystem)
    2642                         result = ID_PSREBOOTSYSTEM;
    2643 
    2644                     if (psInfo->isModeless)
    2645                         psInfo->activeValid = FALSE;
    2646                     else
    2647                         EndDialog(hwnd, result);
    2648                 }
    2649             else
    2650                 EnableWindow(hwndApplyBtn, FALSE);
    2651 
    2652             break;
    2653         }
     2635    {
     2636        HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
     2637
     2638        if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
     2639        break;
     2640
     2641        if (wID == IDOK)
     2642        {
     2643            PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
     2644                                      PropSheetInfoStr);
     2645            int result = TRUE;
     2646
     2647            if (psInfo->restartWindows)
     2648            result = ID_PSRESTARTWINDOWS;
     2649
     2650            /* reboot system takes precedence over restart windows */
     2651            if (psInfo->rebootSystem)
     2652            result = ID_PSREBOOTSYSTEM;
     2653
     2654            if (psInfo->isModeless)
     2655            psInfo->activeValid = FALSE;
     2656            else
     2657            EndDialog(hwnd, result);
     2658        }
     2659        else
     2660        EnableWindow(hwndApplyBtn, FALSE);
     2661
     2662        break;
     2663    }
    26542664
    26552665    case IDC_BACK_BUTTON:
    2656         PROPSHEET_Back(hwnd);
    2657         break;
     2666    PROPSHEET_Back(hwnd);
     2667    break;
    26582668
    26592669    case IDC_NEXT_BUTTON:
    2660         PROPSHEET_Next(hwnd);
    2661         break;
     2670    PROPSHEET_Next(hwnd);
     2671    break;
    26622672
    26632673    case IDC_FINISH_BUTTON:
    2664         PROPSHEET_Finish(hwnd);
    2665         break;
     2674    PROPSHEET_Finish(hwnd);
     2675    break;
    26662676
    26672677    case IDCANCEL:
    2668         PROPSHEET_Cancel(hwnd, 0);
    2669         break;
     2678    PROPSHEET_Cancel(hwnd, 0);
     2679    break;
    26702680
    26712681    case IDHELP:
    2672         PROPSHEET_Help(hwnd);
    2673         break;
     2682    PROPSHEET_Help(hwnd);
     2683    break;
    26742684    }
    26752685
     
    26842694{
    26852695  TRACE("hwnd=%p msg=0x%04x wparam=%x lparam=%lx\n",
    2686         hwnd, uMsg, wParam, lParam);
     2696    hwnd, uMsg, wParam, lParam);
    26872697
    26882698  switch (uMsg)
     
    27572767      if (psInfo->useCallback)
    27582768             (*(psInfo->ppshheader.pfnCallback))(hwnd,
    2759                                               PSCB_INITIALIZED, (LPARAM)0);
     2769                          PSCB_INITIALIZED, (LPARAM)0);
    27602770
    27612771      idx = psInfo->active_page;
     
    28592869        msgResult = PROPSHEET_SetCurSel(hwnd,
    28602870                                       (int)wParam,
    2861                                        1,
     2871                       1,
    28622872                                       (HPROPSHEETPAGE)lParam);
    28632873      }
  • trunk/src/comctl32/treeview.c

    r10098 r10165  
    9696  UINT          uNumItems;      /* number of valid TREEVIEW_ITEMs */
    9797  INT           cdmode;         /* last custom draw setting */
    98   UINT          uScrollTime;    /* max. time for scrolling in milliseconds */
    99   BOOL          bRedraw;        /* if FALSE we validate but don't redraw in TREEVIEW_Paint() */
     98  UINT          uScrollTime;    /* max. time for scrolling in milliseconds */
     99  BOOL      bRedraw;    /* if FALSE we validate but don't redraw in TREEVIEW_Paint() */
    100100
    101101  UINT          uItemHeight;    /* item height */
     
    111111  HTREEITEM     selectedItem;   /* handle to selected item or 0 if none */
    112112  HTREEITEM     hotItem;        /* handle currently under cursor, 0 if none */
    113   HTREEITEM     focusedItem;    /* item that was under the cursor when WM_LBUTTONDOWN was received */
     113  HTREEITEM focusedItem;    /* item that was under the cursor when WM_LBUTTONDOWN was received */
    114114
    115115  HTREEITEM     firstVisible;   /* handle to first visible item */
     
    155155/* bitflags for infoPtr->uInternalStatus */
    156156
    157 #define TV_HSCROLL      0x01    /* treeview too large to fit in window */
    158 #define TV_VSCROLL      0x02    /* (horizontal/vertical) */
    159 #define TV_LDRAG                0x04    /* Lbutton pushed to start drag */
    160 #define TV_LDRAGGING    0x08    /* Lbutton pushed, mouse moved. */
    161 #define TV_RDRAG                0x10    /* dito Rbutton */
    162 #define TV_RDRAGGING    0x20
     157#define TV_HSCROLL  0x01    /* treeview too large to fit in window */
     158#define TV_VSCROLL  0x02    /* (horizontal/vertical) */
     159#define TV_LDRAG        0x04    /* Lbutton pushed to start drag */
     160#define TV_LDRAGGING    0x08    /* Lbutton pushed, mouse moved. */
     161#define TV_RDRAG        0x10    /* dito Rbutton */
     162#define TV_RDRAGGING    0x20
    163163
    164164/* bitflags for infoPtr->timer */
     
    241241    if (TREEVIEW_GetItemIndex(infoPtr, handle) == -1)
    242242    {
    243         TRACE("invalid item %p\n", handle);
    244         return FALSE;
     243    TRACE("invalid item %p\n", handle);
     244    return FALSE;
    245245    }
    246246    else
    247         return TRUE;
     247    return TRUE;
    248248}
    249249
     
    280280    do
    281281    {
    282         child = child->parent;
    283         if (child == parent) return TRUE;
     282    child = child->parent;
     283    if (child == parent) return TRUE;
    284284    } while (child != NULL);
    285285
     
    323323    if (tvItem->prevSibling)
    324324    {
    325         /* This item has a prevSibling, get the last item in the sibling's tree. */
    326         TREEVIEW_ITEM *upItem = tvItem->prevSibling;
    327 
    328         if ((upItem->state & TVIS_EXPANDED) && upItem->lastChild != NULL)
    329             return TREEVIEW_GetLastListItem(infoPtr, upItem->lastChild);
    330         else
    331             return upItem;
    332     }
     325    /* This item has a prevSibling, get the last item in the sibling's tree. */
     326    TREEVIEW_ITEM *upItem = tvItem->prevSibling;
     327
     328    if ((upItem->state & TVIS_EXPANDED) && upItem->lastChild != NULL)
     329        return TREEVIEW_GetLastListItem(infoPtr, upItem->lastChild);
    333330    else
    334     {
    335         /* this item does not have a prevSibling, get the parent */
    336         return (tvItem->parent != infoPtr->root) ? tvItem->parent : NULL;
     331        return upItem;
     332    }
     333    else
     334    {
     335    /* this item does not have a prevSibling, get the parent */
     336    return (tvItem->parent != infoPtr->root) ? tvItem->parent : NULL;
    337337    }
    338338}
     
    353353    if ((tvItem->state & TVIS_EXPANDED) && tvItem->firstChild != NULL)
    354354    {
    355         return tvItem->firstChild;
     355    return tvItem->firstChild;
    356356    }
    357357
     
    361361     */
    362362    if (tvItem->nextSibling)
    363         return tvItem->nextSibling;
     363    return tvItem->nextSibling;
    364364
    365365    /*
     
    368368    while (tvItem->parent)
    369369    {
    370         tvItem = tvItem->parent;
    371 
    372         if (tvItem->nextSibling)
    373             return tvItem->nextSibling;
     370    tvItem = tvItem->parent;
     371
     372    if (tvItem->nextSibling)
     373        return tvItem->nextSibling;
    374374    }
    375375
     
    386386static TREEVIEW_ITEM *
    387387TREEVIEW_GetListItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem,
    388                      LONG count)
     388             LONG count)
    389389{
    390390    TREEVIEW_ITEM *(*next_item)(TREEVIEW_INFO *, TREEVIEW_ITEM *);
     
    395395    if (count > 0)
    396396    {
    397         next_item = TREEVIEW_GetNextListItem;
     397    next_item = TREEVIEW_GetNextListItem;
    398398    }
    399399    else if (count < 0)
    400400    {
    401         count = -count;
    402         next_item = TREEVIEW_GetPrevListItem;
     401    count = -count;
     402    next_item = TREEVIEW_GetPrevListItem;
    403403    }
    404404    else
    405         return wineItem;
     405    return wineItem;
    406406
    407407    do
    408408    {
    409         previousItem = wineItem;
    410         wineItem = next_item(infoPtr, wineItem);
     409    previousItem = wineItem;
     410    wineItem = next_item(infoPtr, wineItem);
    411411
    412412    } while (--count && wineItem != NULL);
     
    421421{
    422422    if (!infoPtr->bNtfUnicode) {
    423         switch (code) {
    424         case TVN_SELCHANGINGW:    return TVN_SELCHANGINGA;
    425         case TVN_SELCHANGEDW:     return TVN_SELCHANGEDA;
    426         case TVN_GETDISPINFOW:    return TVN_GETDISPINFOA;
    427         case TVN_SETDISPINFOW:    return TVN_SETDISPINFOA;
    428         case TVN_ITEMEXPANDINGW:  return TVN_ITEMEXPANDINGA;
    429         case TVN_ITEMEXPANDEDW:   return TVN_ITEMEXPANDEDA;
    430         case TVN_BEGINDRAGW:      return TVN_BEGINDRAGA;
    431         case TVN_BEGINRDRAGW:     return TVN_BEGINRDRAGA;
    432         case TVN_DELETEITEMW:     return TVN_DELETEITEMA;
    433         case TVN_BEGINLABELEDITW: return TVN_BEGINLABELEDITA;
    434         case TVN_ENDLABELEDITW:   return TVN_ENDLABELEDITA;
    435         case TVN_GETINFOTIPW:     return TVN_GETINFOTIPA;
    436         }
     423    switch (code) {
     424    case TVN_SELCHANGINGW:    return TVN_SELCHANGINGA;
     425    case TVN_SELCHANGEDW:     return TVN_SELCHANGEDA;
     426    case TVN_GETDISPINFOW:    return TVN_GETDISPINFOA;
     427    case TVN_SETDISPINFOW:    return TVN_SETDISPINFOA;
     428    case TVN_ITEMEXPANDINGW:  return TVN_ITEMEXPANDINGA;
     429    case TVN_ITEMEXPANDEDW:   return TVN_ITEMEXPANDEDA;
     430    case TVN_BEGINDRAGW:      return TVN_BEGINDRAGA;
     431    case TVN_BEGINRDRAGW:     return TVN_BEGINRDRAGA;
     432    case TVN_DELETEITEMW:     return TVN_DELETEITEMA;
     433    case TVN_BEGINLABELEDITW: return TVN_BEGINLABELEDITA;
     434    case TVN_ENDLABELEDITW:   return TVN_ENDLABELEDITA;
     435    case TVN_GETINFOTIPW:     return TVN_GETINFOTIPA;
     436    }
    437437    }
    438438    return code;
     
    458458
    459459    return (BOOL)TREEVIEW_SendRealNotify(infoPtr,
    460                                   (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
     460                  (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
    461461}
    462462
     
    484484        if (len > 1) {
    485485            tvItem->pszText = (LPSTR)COMCTL32_Alloc (len*sizeof(WCHAR));
     486#ifdef __WIN32OS2__
     487            MultiByteToWideChar( CP_ACP, 0, item->pszText, -1, (LPWSTR)tvItem->pszText, len);
     488#else
    486489            MultiByteToWideChar( CP_ACP, 0, item->pszText, -1, (LPWSTR)tvItem->pszText, len*sizeof(WCHAR) );
    487         }
     490#endif
     491    }
    488492    }
    489493    else
    490         tvItem->pszText = item->pszText;
     494    tvItem->pszText = item->pszText;
    491495}
    492496
    493497static BOOL
    494498TREEVIEW_SendTreeviewNotify(TREEVIEW_INFO *infoPtr, UINT code, UINT action,
    495                             UINT mask, HTREEITEM oldItem, HTREEITEM newItem)
     499                UINT mask, HTREEITEM oldItem, HTREEITEM newItem)
    496500{
    497501    HWND hwnd = infoPtr->hwnd;
     
    500504
    501505    TRACE("code:%d action:%x olditem:%p newitem:%p\n",
    502           code, action, oldItem, newItem);
     506      code, action, oldItem, newItem);
    503507
    504508    ZeroMemory(&nmhdr, sizeof(NMTREEVIEWA));
     
    510514
    511515    if (oldItem)
    512         TREEVIEW_TVItemFromItem(infoPtr, mask, &nmhdr.itemOld, oldItem);
     516    TREEVIEW_TVItemFromItem(infoPtr, mask, &nmhdr.itemOld, oldItem);
    513517
    514518    if (newItem)
    515         TREEVIEW_TVItemFromItem(infoPtr, mask, &nmhdr.itemNew, newItem);
     519    TREEVIEW_TVItemFromItem(infoPtr, mask, &nmhdr.itemNew, newItem);
    516520
    517521    nmhdr.ptDrag.x = 0;
     
    519523
    520524    ret = (BOOL)TREEVIEW_SendRealNotify(infoPtr,
    521                               (WPARAM)GetWindowLongA(hwnd, GWL_ID),
    522                               (LPARAM)&nmhdr);
     525                  (WPARAM)GetWindowLongA(hwnd, GWL_ID),
     526                  (LPARAM)&nmhdr);
    523527    if (infoPtr->bNtfUnicode) {
    524         COMCTL32_Free(nmhdr.itemOld.pszText);
    525         COMCTL32_Free(nmhdr.itemNew.pszText);
     528    COMCTL32_Free(nmhdr.itemOld.pszText);
     529    COMCTL32_Free(nmhdr.itemNew.pszText);
    526530    }
    527531    return ret;
     
    530534static BOOL
    531535TREEVIEW_SendTreeviewDnDNotify(TREEVIEW_INFO *infoPtr, UINT code,
    532                                HTREEITEM dragItem, POINT pt)
     536                   HTREEITEM dragItem, POINT pt)
    533537{
    534538    HWND hwnd = infoPtr->hwnd;
     
    550554
    551555    return (BOOL)TREEVIEW_SendRealNotify(infoPtr,
    552                               (WPARAM)GetWindowLongA(hwnd, GWL_ID),
    553                               (LPARAM)&nmhdr);
     556                  (WPARAM)GetWindowLongA(hwnd, GWL_ID),
     557                  (LPARAM)&nmhdr);
    554558}
    555559
     
    557561static BOOL
    558562TREEVIEW_SendCustomDrawNotify(TREEVIEW_INFO *infoPtr, DWORD dwDrawStage,
    559                               HDC hdc, RECT rc)
     563                  HDC hdc, RECT rc)
    560564{
    561565    HWND hwnd = infoPtr->hwnd;
     
    580584
    581585    return (BOOL)TREEVIEW_SendRealNotify(infoPtr,
    582                               (WPARAM)GetWindowLongA(hwnd, GWL_ID),
    583                               (LPARAM)&nmcdhdr);
     586                  (WPARAM)GetWindowLongA(hwnd, GWL_ID),
     587                  (LPARAM)&nmcdhdr);
    584588}
    585589
     
    590594static BOOL
    591595TREEVIEW_SendCustomDrawItemNotify(TREEVIEW_INFO *infoPtr, HDC hdc,
    592                                   TREEVIEW_ITEM *wineItem, UINT uItemDrawState)
     596                  TREEVIEW_ITEM *wineItem, UINT uItemDrawState)
    593597{
    594598    HWND hwnd = infoPtr->hwnd;
     
    603607    uItemState = 0;
    604608    if (wineItem->state & TVIS_SELECTED)
    605         uItemState |= CDIS_SELECTED;
     609    uItemState |= CDIS_SELECTED;
    606610    if (wineItem == infoPtr->selectedItem)
    607         uItemState |= CDIS_FOCUS;
     611    uItemState |= CDIS_FOCUS;
    608612    if (wineItem == infoPtr->hotItem)
    609         uItemState |= CDIS_HOT;
     613    uItemState |= CDIS_HOT;
    610614
    611615    nmcd = &nmcdhdr.nmcd;
     
    624628
    625629    TRACE("drawstage:%lx hdc:%p item:%lx, itemstate:%x, lItemlParam:%lx\n",
    626           nmcd->dwDrawStage, nmcd->hdc, nmcd->dwItemSpec,
    627           nmcd->uItemState, nmcd->lItemlParam);
     630      nmcd->dwDrawStage, nmcd->hdc, nmcd->dwItemSpec,
     631      nmcd->uItemState, nmcd->lItemlParam);
    628632
    629633    retval = TREEVIEW_SendRealNotify(infoPtr,
    630                           (WPARAM)GetWindowLongA(hwnd, GWL_ID),
    631                           (LPARAM)&nmcdhdr);
     634              (WPARAM)GetWindowLongA(hwnd, GWL_ID),
     635              (LPARAM)&nmcdhdr);
    632636
    633637    infoPtr->clrText = nmcdhdr.clrText;
     
    656660        if (len > 1) {
    657661            tvdi.item.pszText = allocated = (LPSTR)COMCTL32_Alloc (len*sizeof(WCHAR));
     662#ifdef __WIN32OS2__
     663            MultiByteToWideChar( CP_ACP, 0, editItem->pszText, -1, (LPWSTR)tvdi.item.pszText, len);
     664            tvdi.item.cchTextMax = len;
     665#else
    658666            MultiByteToWideChar( CP_ACP, 0, editItem->pszText, -1, (LPWSTR)tvdi.item.pszText, len*sizeof(WCHAR) );
    659667            tvdi.item.cchTextMax = len*sizeof(WCHAR);
    660         }
    661         else {
    662             tvdi.item.pszText = editItem->pszText;  /* ??? */
    663             tvdi.item.cchTextMax = editItem->cchTextMax;  /* ??? */
    664         }
     668#endif
    665669    }
    666670    else {
    667         tvdi.item.pszText = editItem->pszText;
    668         tvdi.item.cchTextMax = editItem->cchTextMax;
     671        tvdi.item.pszText = editItem->pszText;  /* ??? */
     672        tvdi.item.cchTextMax = editItem->cchTextMax;  /* ??? */
     673    }
     674    }
     675    else {
     676    tvdi.item.pszText = editItem->pszText;
     677    tvdi.item.cchTextMax = editItem->cchTextMax;
    669678    }
    670679
    671680    ret = (BOOL)TREEVIEW_SendRealNotify(infoPtr,
    672                                         tvdi.hdr.idFrom,
    673                                         (LPARAM)&tvdi);
     681                    tvdi.hdr.idFrom,
     682                    (LPARAM)&tvdi);
    674683    if (allocated)
    675         COMCTL32_Free(allocated);
     684    COMCTL32_Free(allocated);
    676685    return ret;
    677686}
     
    679688static void
    680689TREEVIEW_UpdateDispInfo(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem,
    681                         UINT mask)
     690            UINT mask)
    682691{
    683692    NMTVDISPINFOA callback;
     
    714723    if ((mask & TVIF_TEXT) && callback.item.pszText != wineItem->pszText)
    715724    {
    716         /* Instead of copying text into our buffer user specified its own */
    717         if (infoPtr->bNtfUnicode) {
    718             LPWSTR newText;
    719             int buflen;
     725    /* Instead of copying text into our buffer user specified its own */
     726    if (infoPtr->bNtfUnicode) {
     727        LPWSTR newText;
     728        int buflen;
    720729            int len = WideCharToMultiByte( CP_ACP, 0,
    721                                            (LPWSTR)callback.item.pszText, -1,
     730                       (LPWSTR)callback.item.pszText, -1,
    722731                                           NULL, 0, NULL, NULL );
    723             buflen = max((len+1)*sizeof(WCHAR), TEXT_CALLBACK_SIZE);
    724             newText = (LPWSTR)COMCTL32_ReAlloc(wineItem->pszText, buflen);
    725 
    726             TRACE("returned wstr %s, len=%d, buflen=%d\n",
    727                   debugstr_w((LPWSTR)callback.item.pszText), len, buflen);
    728 
    729             if (newText)
    730             {
    731                 wineItem->pszText = (LPSTR)newText;
    732                 WideCharToMultiByte( CP_ACP, 0,
    733                                      (LPWSTR)callback.item.pszText, -1,
    734                                      wineItem->pszText, buflen,
    735                                      NULL, NULL );
    736                 wineItem->cchTextMax = buflen;
    737             }
    738             /* If ReAlloc fails we have nothing to do, but keep original text */
    739         }
    740         else {
    741             int len = max(lstrlenA(callback.item.pszText) + 1,
    742                           TEXT_CALLBACK_SIZE);
    743             LPSTR newText = COMCTL32_ReAlloc(wineItem->pszText, len);
    744 
    745             TRACE("returned str %s, len=%d\n",
    746                   debugstr_a(callback.item.pszText), len);
    747 
    748             if (newText)
    749             {
    750                 wineItem->pszText = newText;
    751                 strcpy(wineItem->pszText, callback.item.pszText);
    752                 wineItem->cchTextMax = len;
    753             }
    754             /* If ReAlloc fails we have nothing to do, but keep original text */
    755         }
     732        buflen = max((len+1)*sizeof(WCHAR), TEXT_CALLBACK_SIZE);
     733        newText = (LPWSTR)COMCTL32_ReAlloc(wineItem->pszText, buflen);
     734
     735        TRACE("returned wstr %s, len=%d, buflen=%d\n",
     736          debugstr_w((LPWSTR)callback.item.pszText), len, buflen);
     737
     738        if (newText)
     739        {
     740        wineItem->pszText = (LPSTR)newText;
     741        WideCharToMultiByte( CP_ACP, 0,
     742                     (LPWSTR)callback.item.pszText, -1,
     743                     wineItem->pszText, buflen,
     744                     NULL, NULL );
     745        wineItem->cchTextMax = buflen;
     746        }
     747        /* If ReAlloc fails we have nothing to do, but keep original text */
     748    }
     749    else {
     750        int len = max(lstrlenA(callback.item.pszText) + 1,
     751              TEXT_CALLBACK_SIZE);
     752        LPSTR newText = COMCTL32_ReAlloc(wineItem->pszText, len);
     753
     754        TRACE("returned str %s, len=%d\n",
     755          debugstr_a(callback.item.pszText), len);
     756
     757        if (newText)
     758        {
     759        wineItem->pszText = newText;
     760        strcpy(wineItem->pszText, callback.item.pszText);
     761        wineItem->cchTextMax = len;
     762        }
     763        /* If ReAlloc fails we have nothing to do, but keep original text */
     764    }
    756765    }
    757766    else if (mask & TVIF_TEXT) {
    758         /* User put text into our buffer, that is ok unless W string */
    759         if (infoPtr->bNtfUnicode) {
    760             LPWSTR newText;
    761             LPSTR oldText = NULL;
    762             int buflen;
     767    /* User put text into our buffer, that is ok unless W string */
     768    if (infoPtr->bNtfUnicode) {
     769        LPWSTR newText;
     770        LPSTR oldText = NULL;
     771        int buflen;
    763772            int len = WideCharToMultiByte( CP_ACP, 0,
    764                                            (LPWSTR)callback.item.pszText, -1,
     773                       (LPWSTR)callback.item.pszText, -1,
    765774                                           NULL, 0, NULL, NULL );
    766             buflen = max((len+1)*sizeof(WCHAR), TEXT_CALLBACK_SIZE);
    767             newText = (LPWSTR)COMCTL32_Alloc(buflen);
    768 
    769             TRACE("same buffer wstr %s, len=%d, buflen=%d\n",
    770                   debugstr_w((LPWSTR)callback.item.pszText), len, buflen);
    771 
    772             if (newText)
    773             {
    774                 oldText = wineItem->pszText;
    775                 wineItem->pszText = (LPSTR)newText;
    776                 WideCharToMultiByte( CP_ACP, 0,
    777                                      (LPWSTR)callback.item.pszText, -1,
    778                                      wineItem->pszText, buflen, NULL, NULL );
    779                 wineItem->cchTextMax = buflen;
    780                 if (oldText)
    781                     COMCTL32_Free(oldText);
    782             }
    783         }
     775        buflen = max((len+1)*sizeof(WCHAR), TEXT_CALLBACK_SIZE);
     776        newText = (LPWSTR)COMCTL32_Alloc(buflen);
     777
     778        TRACE("same buffer wstr %s, len=%d, buflen=%d\n",
     779          debugstr_w((LPWSTR)callback.item.pszText), len, buflen);
     780
     781        if (newText)
     782        {
     783        oldText = wineItem->pszText;
     784        wineItem->pszText = (LPSTR)newText;
     785        WideCharToMultiByte( CP_ACP, 0,
     786                     (LPWSTR)callback.item.pszText, -1,
     787                     wineItem->pszText, buflen, NULL, NULL );
     788        wineItem->cchTextMax = buflen;
     789        if (oldText)
     790            COMCTL32_Free(oldText);
     791        }
     792    }
    784793    }
    785794
    786795    if (mask & TVIF_IMAGE)
    787         wineItem->iImage = callback.item.iImage;
     796    wineItem->iImage = callback.item.iImage;
    788797
    789798    if (mask & TVIF_SELECTEDIMAGE)
    790         wineItem->iSelectedImage = callback.item.iSelectedImage;
     799    wineItem->iSelectedImage = callback.item.iSelectedImage;
    791800
    792801    if (mask & TVIF_CHILDREN)
    793         wineItem->cChildren = callback.item.cChildren;
     802    wineItem->cChildren = callback.item.cChildren;
    794803
    795804    /* These members are now permanently set. */
    796805    if (callback.item.mask & TVIF_DI_SETITEM)
    797         wineItem->callbackMask &= ~callback.item.mask;
     806    wineItem->callbackMask &= ~callback.item.mask;
    798807}
    799808
     
    820829static VOID
    821830TREEVIEW_ComputeItemInternalMetrics(TREEVIEW_INFO *infoPtr,
    822                                     TREEVIEW_ITEM *item)
     831                    TREEVIEW_ITEM *item)
    823832{
    824833    /* Same effect, different optimisation. */
    825834#if 0
    826835    BOOL lar = ((infoPtr->dwStyle & TVS_LINESATROOT)
    827                 && (infoPtr->dwStyle & (TVS_HASLINES|TVS_HASBUTTONS)));
     836        && (infoPtr->dwStyle & (TVS_HASLINES|TVS_HASBUTTONS)));
    828837#else
    829838    BOOL lar = ((infoPtr->dwStyle
    830                 & (TVS_LINESATROOT|TVS_HASLINES|TVS_HASBUTTONS))
    831                 > TVS_LINESATROOT);
     839        & (TVS_LINESATROOT|TVS_HASLINES|TVS_HASBUTTONS))
     840        > TVS_LINESATROOT);
    832841#endif
    833842
    834843    item->linesOffset = infoPtr->uIndent * (item->iLevel + lar - 1)
    835         - infoPtr->scrollX;
     844    - infoPtr->scrollX;
    836845    item->stateOffset = item->linesOffset + infoPtr->uIndent;
    837846    item->imageOffset = item->stateOffset
    838         + (STATEIMAGEINDEX(item->state) ? infoPtr->stateImageWidth : 0);
     847    + (STATEIMAGEINDEX(item->state) ? infoPtr->stateImageWidth : 0);
    839848    item->textOffset  = item->imageOffset + infoPtr->normalImageWidth;
    840849}
     
    850859    if (item->pszText == NULL)
    851860    {
    852         item->textWidth = 0;
    853         return;
     861    item->textWidth = 0;
     862    return;
    854863    }
    855864
     
    859868    if (hDC != 0)
    860869    {
    861         hdc = hDC;
     870    hdc = hDC;
    862871    }
    863872    else
    864873    {
    865         hdc = GetDC(infoPtr->hwnd);
    866         hOldFont = SelectObject(hdc, TREEVIEW_FontForItem(infoPtr, item));
     874    hdc = GetDC(infoPtr->hwnd);
     875    hOldFont = SelectObject(hdc, TREEVIEW_FontForItem(infoPtr, item));
    867876    }
    868877
     
    872881    if (hDC == 0)
    873882    {
    874         SelectObject(hdc, hOldFont);
    875         ReleaseDC(0, hdc);
     883    SelectObject(hdc, hOldFont);
     884    ReleaseDC(0, hdc);
    876885    }
    877886}
     
    881890{
    882891    item->rect.top = infoPtr->uItemHeight *
    883         (item->visibleOrder - infoPtr->firstVisible->visibleOrder);
     892    (item->visibleOrder - infoPtr->firstVisible->visibleOrder);
    884893
    885894    item->rect.bottom = item->rect.top
    886         + infoPtr->uItemHeight * item->iIntegral - 1;
     895    + infoPtr->uItemHeight * item->iIntegral - 1;
    887896
    888897    item->rect.left = 0;
     
    899908    if (!start)
    900909    {
    901         start = infoPtr->root->firstChild;
    902         order = 0;
     910    start = infoPtr->root->firstChild;
     911    order = 0;
    903912    }
    904913    else
    905         order = start->visibleOrder;
     914    order = start->visibleOrder;
    906915
    907916    for (item = start; item != NULL;
    908917         item = TREEVIEW_GetNextListItem(infoPtr, item))
    909918    {
    910         item->visibleOrder = order;
    911         order += item->iIntegral;
     919    item->visibleOrder = order;
     920    order += item->iIntegral;
    912921    }
    913922
     
    915924
    916925    for (item = start; item != NULL;
    917         item = TREEVIEW_GetNextListItem(infoPtr, item))
    918     {
    919         TREEVIEW_ComputeItemRect(infoPtr, item);
     926    item = TREEVIEW_GetNextListItem(infoPtr, item))
     927    {
     928    TREEVIEW_ComputeItemRect(infoPtr, item);
    920929    }
    921930}
     
    969978
    970979    if (!newItem)
    971         return NULL;
     980    return NULL;
    972981
    973982    if (DPA_InsertPtr(infoPtr->items, INT_MAX, newItem) == -1)
    974983    {
    975         COMCTL32_Free(newItem);
    976         return NULL;
     984    COMCTL32_Free(newItem);
     985    return NULL;
    977986    }
    978987
     
    10101019static void
    10111020TREEVIEW_InsertBefore(TREEVIEW_ITEM *newItem, TREEVIEW_ITEM *sibling,
    1012                       TREEVIEW_ITEM *parent)
     1021              TREEVIEW_ITEM *parent)
    10131022{
    10141023    assert(newItem != NULL);
     
    10171026    if (sibling != NULL)
    10181027    {
    1019         assert(sibling->parent == parent);
    1020 
    1021         if (sibling->prevSibling != NULL)
    1022             sibling->prevSibling->nextSibling = newItem;
    1023 
    1024         newItem->prevSibling = sibling->prevSibling;
    1025         sibling->prevSibling = newItem;
     1028    assert(sibling->parent == parent);
     1029
     1030    if (sibling->prevSibling != NULL)
     1031        sibling->prevSibling->nextSibling = newItem;
     1032
     1033    newItem->prevSibling = sibling->prevSibling;
     1034    sibling->prevSibling = newItem;
    10261035    }
    10271036    else
     
    10311040
    10321041    if (parent->firstChild == sibling)
    1033         parent->firstChild = newItem;
     1042    parent->firstChild = newItem;
    10341043
    10351044    if (parent->lastChild == NULL)
    1036         parent->lastChild = newItem;
     1045    parent->lastChild = newItem;
    10371046}
    10381047
     
    10431052static void
    10441053TREEVIEW_InsertAfter(TREEVIEW_ITEM *newItem, TREEVIEW_ITEM *sibling,
    1045                      TREEVIEW_ITEM *parent)
     1054             TREEVIEW_ITEM *parent)
    10461055{
    10471056    assert(newItem != NULL);
     
    10501059    if (sibling != NULL)
    10511060    {
    1052         assert(sibling->parent == parent);
    1053 
    1054         if (sibling->nextSibling != NULL)
    1055             sibling->nextSibling->prevSibling = newItem;
    1056 
    1057         newItem->nextSibling = sibling->nextSibling;
    1058         sibling->nextSibling = newItem;
     1061    assert(sibling->parent == parent);
     1062
     1063    if (sibling->nextSibling != NULL)
     1064        sibling->nextSibling->prevSibling = newItem;
     1065
     1066    newItem->nextSibling = sibling->nextSibling;
     1067    sibling->nextSibling = newItem;
    10591068    }
    10601069    else
     
    10641073
    10651074    if (parent->lastChild == sibling)
    1066         parent->lastChild = newItem;
     1075    parent->lastChild = newItem;
    10671076
    10681077    if (parent->firstChild == NULL)
    1069         parent->firstChild = newItem;
     1078    parent->firstChild = newItem;
    10701079}
    10711080
    10721081static BOOL
    10731082TREEVIEW_DoSetItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem,
    1074                    const TVITEMEXA *tvItem)
     1083           const TVITEMEXA *tvItem)
    10751084{
    10761085    UINT callbackClear = 0;
     
    10811090    {
    10821091        wineItem->textWidth = 0; /* force width recalculation */
    1083         if (tvItem->pszText != LPSTR_TEXTCALLBACKA)
    1084         {
    1085             int len = lstrlenA(tvItem->pszText) + 1;
    1086             LPSTR newText = COMCTL32_ReAlloc(wineItem->pszText, len);
    1087 
    1088             if (newText == NULL) return FALSE;
    1089 
    1090             callbackClear |= TVIF_TEXT;
    1091 
    1092             wineItem->pszText = newText;
    1093             wineItem->cchTextMax = len;
    1094             lstrcpynA(wineItem->pszText, tvItem->pszText, len);
    1095             TRACE("setting text %s, item %p\n",
    1096                   debugstr_a(wineItem->pszText), wineItem);
    1097         }
    1098         else
    1099         {
    1100             callbackSet |= TVIF_TEXT;
    1101 
    1102             wineItem->pszText = COMCTL32_ReAlloc(wineItem->pszText,
    1103                                                 TEXT_CALLBACK_SIZE);
    1104             wineItem->cchTextMax = TEXT_CALLBACK_SIZE;
    1105             TRACE("setting callback, item %p\n",
    1106                   wineItem);
    1107         }
     1092    if (tvItem->pszText != LPSTR_TEXTCALLBACKA)
     1093    {
     1094        int len = lstrlenA(tvItem->pszText) + 1;
     1095        LPSTR newText = COMCTL32_ReAlloc(wineItem->pszText, len);
     1096
     1097        if (newText == NULL) return FALSE;
     1098
     1099        callbackClear |= TVIF_TEXT;
     1100
     1101        wineItem->pszText = newText;
     1102        wineItem->cchTextMax = len;
     1103        lstrcpynA(wineItem->pszText, tvItem->pszText, len);
     1104        TRACE("setting text %s, item %p\n",
     1105          debugstr_a(wineItem->pszText), wineItem);
     1106    }
     1107    else
     1108    {
     1109        callbackSet |= TVIF_TEXT;
     1110
     1111        wineItem->pszText = COMCTL32_ReAlloc(wineItem->pszText,
     1112                        TEXT_CALLBACK_SIZE);
     1113        wineItem->cchTextMax = TEXT_CALLBACK_SIZE;
     1114        TRACE("setting callback, item %p\n",
     1115          wineItem);
     1116    }
    11081117    }
    11091118
    11101119    if (tvItem->mask & TVIF_CHILDREN)
    11111120    {
    1112         wineItem->cChildren = tvItem->cChildren;
    1113 
    1114         if (wineItem->cChildren == I_CHILDRENCALLBACK)
    1115             callbackSet |= TVIF_CHILDREN;
    1116         else
    1117             callbackClear |= TVIF_CHILDREN;
     1121    wineItem->cChildren = tvItem->cChildren;
     1122
     1123    if (wineItem->cChildren == I_CHILDRENCALLBACK)
     1124        callbackSet |= TVIF_CHILDREN;
     1125    else
     1126        callbackClear |= TVIF_CHILDREN;
    11181127    }
    11191128
    11201129    if (tvItem->mask & TVIF_IMAGE)
    11211130    {
    1122         wineItem->iImage = tvItem->iImage;
    1123 
    1124         if (wineItem->iImage == I_IMAGECALLBACK)
    1125             callbackSet |= TVIF_IMAGE;
    1126         else
    1127             callbackClear |= TVIF_IMAGE;
     1131    wineItem->iImage = tvItem->iImage;
     1132
     1133    if (wineItem->iImage == I_IMAGECALLBACK)
     1134        callbackSet |= TVIF_IMAGE;
     1135    else
     1136        callbackClear |= TVIF_IMAGE;
    11281137    }
    11291138
    11301139    if (tvItem->mask & TVIF_SELECTEDIMAGE)
    11311140    {
    1132         wineItem->iSelectedImage = tvItem->iSelectedImage;
    1133 
    1134         if (wineItem->iSelectedImage == I_IMAGECALLBACK)
    1135             callbackSet |= TVIF_SELECTEDIMAGE;
    1136         else
    1137             callbackClear |= TVIF_SELECTEDIMAGE;
     1141    wineItem->iSelectedImage = tvItem->iSelectedImage;
     1142
     1143    if (wineItem->iSelectedImage == I_IMAGECALLBACK)
     1144        callbackSet |= TVIF_SELECTEDIMAGE;
     1145    else
     1146        callbackClear |= TVIF_SELECTEDIMAGE;
    11381147    }
    11391148
    11401149    if (tvItem->mask & TVIF_PARAM)
    1141         wineItem->lParam = tvItem->lParam;
     1150    wineItem->lParam = tvItem->lParam;
    11421151
    11431152    /* If the application sets TVIF_INTEGRAL without
    11441153     * supplying a TVITEMEX structure, it's toast. */
    11451154    if (tvItem->mask & TVIF_INTEGRAL)
    1146         wineItem->iIntegral = tvItem->iIntegral;
     1155    wineItem->iIntegral = tvItem->iIntegral;
    11471156
    11481157    if (tvItem->mask & TVIF_STATE)
    11491158    {
    1150         TRACE("prevstate,state,mask:%x,%x,%x\n", wineItem->state, tvItem->state,
    1151               tvItem->stateMask);
    1152         wineItem->state &= ~tvItem->stateMask;
    1153         wineItem->state |= (tvItem->state & tvItem->stateMask);
     1159    TRACE("prevstate,state,mask:%x,%x,%x\n", wineItem->state, tvItem->state,
     1160          tvItem->stateMask);
     1161    wineItem->state &= ~tvItem->stateMask;
     1162    wineItem->state |= (tvItem->state & tvItem->stateMask);
    11541163    }
    11551164
     
    11721181    if (ptdi->hParent == TVI_ROOT || ptdi->hParent == 0)
    11731182    {
    1174         parentItem = infoPtr->root;
     1183    parentItem = infoPtr->root;
    11751184    }
    11761185    else
    11771186    {
    1178         parentItem = ptdi->hParent;
    1179 
    1180         if (!TREEVIEW_ValidItem(infoPtr, parentItem))
    1181         {
    1182             WARN("invalid parent %p\n", parentItem);
    1183             return (LRESULT)(HTREEITEM)NULL;
    1184         }
     1187    parentItem = ptdi->hParent;
     1188
     1189    if (!TREEVIEW_ValidItem(infoPtr, parentItem))
     1190    {
     1191        WARN("invalid parent %p\n", parentItem);
     1192        return (LRESULT)(HTREEITEM)NULL;
     1193    }
    11851194    }
    11861195
     
    11931202    case (DWORD)TVI_LAST:
    11941203    case (DWORD)TVI_SORT:
    1195         break;
     1204    break;
    11961205
    11971206    default:
    1198         if (!TREEVIEW_ValidItem(infoPtr, insertAfter) ||
     1207    if (!TREEVIEW_ValidItem(infoPtr, insertAfter) ||
    11991208            insertAfter->parent != parentItem)
    1200         {
    1201             WARN("invalid insert after %p\n", insertAfter);
    1202             insertAfter = TVI_LAST;
    1203         }
     1209    {
     1210        WARN("invalid insert after %p\n", insertAfter);
     1211        insertAfter = TVI_LAST;
     1212    }
    12041213    }
    12051214
    12061215    TRACE("parent %p position %p: '%s'\n", parentItem, insertAfter,
    1207           (tvItem->mask & TVIF_TEXT)
    1208           ? ((tvItem->pszText == LPSTR_TEXTCALLBACKA) ? "<callback>"
    1209              : tvItem->pszText)
    1210           : "<no label>");
     1216      (tvItem->mask & TVIF_TEXT)
     1217      ? ((tvItem->pszText == LPSTR_TEXTCALLBACKA) ? "<callback>"
     1218         : tvItem->pszText)
     1219      : "<no label>");
    12111220
    12121221    newItem = TREEVIEW_AllocateItem(infoPtr);
    12131222    if (newItem == NULL)
    1214         return (LRESULT)(HTREEITEM)NULL;
     1223    return (LRESULT)(HTREEITEM)NULL;
    12151224
    12161225    newItem->parent = parentItem;
     
    12181227
    12191228    if (!TREEVIEW_DoSetItem(infoPtr, newItem, tvItem))
    1220         return (LRESULT)(HTREEITEM)NULL;
     1229    return (LRESULT)(HTREEITEM)NULL;
    12211230
    12221231    /* After this point, nothing can fail. (Except for TVI_SORT.) */
     
    12331242              TREEVIEW_SetFirstVisible(infoPtr, newItem, TRUE);
    12341243        }
    1235         break;
     1244    break;
    12361245
    12371246    case (DWORD)TVI_LAST:
    1238         TREEVIEW_InsertAfter(newItem, parentItem->lastChild, parentItem);
    1239         break;
    1240 
    1241         /* hInsertAfter names a specific item we want to insert after */
     1247    TREEVIEW_InsertAfter(newItem, parentItem->lastChild, parentItem);
     1248    break;
     1249
     1250    /* hInsertAfter names a specific item we want to insert after */
    12421251    default:
    1243         TREEVIEW_InsertAfter(newItem, insertAfter, insertAfter->parent);
    1244         break;
     1252    TREEVIEW_InsertAfter(newItem, insertAfter, insertAfter->parent);
     1253    break;
    12451254
    12461255    case (DWORD)TVI_SORT:
    1247         {
    1248             TREEVIEW_ITEM *aChild;
    1249             TREEVIEW_ITEM *previousChild = NULL;
    1250             BOOL bItemInserted = FALSE;
    1251 
    1252             aChild = parentItem->firstChild;
    1253 
    1254             bTextUpdated = TRUE;
    1255             TREEVIEW_UpdateDispInfo(infoPtr, newItem, TVIF_TEXT);
    1256 
    1257             /* Iterate the parent children to see where we fit in */
    1258             while (aChild != NULL)
    1259             {
    1260                 INT comp;
    1261 
    1262                 TREEVIEW_UpdateDispInfo(infoPtr, aChild, TVIF_TEXT);
    1263                 comp = lstrcmpA(newItem->pszText, aChild->pszText);
    1264 
    1265                 if (comp < 0)   /* we are smaller than the current one */
    1266                 {
    1267                     TREEVIEW_InsertBefore(newItem, aChild, parentItem);
    1268                     bItemInserted = TRUE;
    1269                     break;
    1270                 }
    1271                 else if (comp > 0)      /* we are bigger than the current one */
    1272                 {
    1273                     previousChild = aChild;
    1274 
    1275                     /* This will help us to exit if there is no more sibling */
    1276                     aChild = (aChild->nextSibling == 0)
    1277                         ? NULL
    1278                         : aChild->nextSibling;
    1279 
    1280                     /* Look at the next item */
    1281                     continue;
    1282                 }
    1283                 else if (comp == 0)
    1284                 {
    1285                     /*
    1286                      * An item with this name is already existing, therefore,
    1287                      * we add after the one we found
    1288                      */
    1289                     TREEVIEW_InsertAfter(newItem, aChild, parentItem);
    1290                     bItemInserted = TRUE;
    1291                     break;
    1292                 }
    1293             }
    1294 
    1295             /*
    1296              * we reach the end of the child list and the item has not
    1297              * yet been inserted, therefore, insert it after the last child.
    1298              */
    1299             if ((!bItemInserted) && (aChild == NULL))
    1300                 TREEVIEW_InsertAfter(newItem, previousChild, parentItem);
    1301 
    1302             break;
    1303         }
     1256    {
     1257        TREEVIEW_ITEM *aChild;
     1258        TREEVIEW_ITEM *previousChild = NULL;
     1259        BOOL bItemInserted = FALSE;
     1260
     1261        aChild = parentItem->firstChild;
     1262
     1263        bTextUpdated = TRUE;
     1264        TREEVIEW_UpdateDispInfo(infoPtr, newItem, TVIF_TEXT);
     1265
     1266        /* Iterate the parent children to see where we fit in */
     1267        while (aChild != NULL)
     1268        {
     1269        INT comp;
     1270
     1271        TREEVIEW_UpdateDispInfo(infoPtr, aChild, TVIF_TEXT);
     1272        comp = lstrcmpA(newItem->pszText, aChild->pszText);
     1273
     1274        if (comp < 0)   /* we are smaller than the current one */
     1275        {
     1276            TREEVIEW_InsertBefore(newItem, aChild, parentItem);
     1277            bItemInserted = TRUE;
     1278            break;
     1279        }
     1280        else if (comp > 0)  /* we are bigger than the current one */
     1281        {
     1282            previousChild = aChild;
     1283
     1284            /* This will help us to exit if there is no more sibling */
     1285            aChild = (aChild->nextSibling == 0)
     1286            ? NULL
     1287            : aChild->nextSibling;
     1288
     1289            /* Look at the next item */
     1290            continue;
     1291        }
     1292        else if (comp == 0)
     1293        {
     1294            /*
     1295             * An item with this name is already existing, therefore,
     1296             * we add after the one we found
     1297             */
     1298            TREEVIEW_InsertAfter(newItem, aChild, parentItem);
     1299            bItemInserted = TRUE;
     1300            break;
     1301        }
     1302        }
     1303
     1304        /*
     1305         * we reach the end of the child list and the item has not
     1306         * yet been inserted, therefore, insert it after the last child.
     1307         */
     1308        if ((!bItemInserted) && (aChild == NULL))
     1309        TREEVIEW_InsertAfter(newItem, previousChild, parentItem);
     1310
     1311        break;
     1312    }
    13041313    }
    13051314
    13061315
    13071316    TRACE("new item %p; parent %p, mask %x\n", newItem,
    1308           newItem->parent, tvItem->mask);
     1317      newItem->parent, tvItem->mask);
    13091318
    13101319    newItem->iLevel = newItem->parent->iLevel + 1;
    13111320
    13121321    if (newItem->parent->cChildren == 0)
    1313         newItem->parent->cChildren = 1;
     1322    newItem->parent->cChildren = 1;
    13141323
    13151324    if (infoPtr->dwStyle & TVS_CHECKBOXES)
    13161325    {
    1317         if (STATEIMAGEINDEX(newItem->state) == 0)
    1318             newItem->state |= INDEXTOSTATEIMAGEMASK(1);
     1326    if (STATEIMAGEINDEX(newItem->state) == 0)
     1327        newItem->state |= INDEXTOSTATEIMAGEMASK(1);
    13191328    }
    13201329
    13211330    if (infoPtr->firstVisible == NULL)
    1322         infoPtr->firstVisible = newItem;
     1331    infoPtr->firstVisible = newItem;
    13231332
    13241333    TREEVIEW_VerifyTree(infoPtr);
     
    13441353       for (item = newItem;
    13451354            item != NULL;
    1346             item = TREEVIEW_GetNextListItem(infoPtr, item))
     1355        item = TREEVIEW_GetNextListItem(infoPtr, item))
    13471356          TREEVIEW_Invalidate(infoPtr, item);
    13481357    }
     
    13801389    tvisA.DUMMYUNIONNAME.item.stateMask = tvisW->DUMMYUNIONNAME.item.stateMask;
    13811390    tvisA.DUMMYUNIONNAME.item.cchTextMax =
    1382         tvisW->DUMMYUNIONNAME.item.cchTextMax;
     1391    tvisW->DUMMYUNIONNAME.item.cchTextMax;
    13831392
    13841393    if (tvisW->DUMMYUNIONNAME.item.pszText)
    13851394    {
    1386         if (tvisW->DUMMYUNIONNAME.item.pszText != LPSTR_TEXTCALLBACKW)
    1387         {
     1395    if (tvisW->DUMMYUNIONNAME.item.pszText != LPSTR_TEXTCALLBACKW)
     1396    {
    13881397            int len = WideCharToMultiByte( CP_ACP, 0, tvisW->DUMMYUNIONNAME.item.pszText, -1,
    13891398                                           NULL, 0, NULL, NULL );
    1390             tvisA.DUMMYUNIONNAME.item.pszText = COMCTL32_Alloc(len);
     1399        tvisA.DUMMYUNIONNAME.item.pszText = COMCTL32_Alloc(len);
    13911400            WideCharToMultiByte( CP_ACP, 0, tvisW->DUMMYUNIONNAME.item.pszText, -1,
    13921401                                 tvisA.DUMMYUNIONNAME.item.pszText, len, NULL, NULL );
    1393         }
    1394         else
    1395         {
    1396             tvisA.DUMMYUNIONNAME.item.pszText = LPSTR_TEXTCALLBACKA;
    1397             tvisA.DUMMYUNIONNAME.item.cchTextMax = 0;
    1398         }
     1402    }
     1403    else
     1404    {
     1405        tvisA.DUMMYUNIONNAME.item.pszText = LPSTR_TEXTCALLBACKA;
     1406        tvisA.DUMMYUNIONNAME.item.cchTextMax = 0;
     1407    }
    13991408    }
    14001409
    14011410    tvisA.DUMMYUNIONNAME.item.iImage = tvisW->DUMMYUNIONNAME.item.iImage;
    14021411    tvisA.DUMMYUNIONNAME.item.iSelectedImage =
    1403         tvisW->DUMMYUNIONNAME.item.iSelectedImage;
     1412    tvisW->DUMMYUNIONNAME.item.iSelectedImage;
    14041413    tvisA.DUMMYUNIONNAME.item.cChildren = tvisW->DUMMYUNIONNAME.item.cChildren;
    14051414    tvisA.DUMMYUNIONNAME.item.lParam = tvisW->DUMMYUNIONNAME.item.lParam;
     
    14091418    if (tvisA.DUMMYUNIONNAME.item.pszText != LPSTR_TEXTCALLBACKA)
    14101419    {
    1411         COMCTL32_Free(tvisA.DUMMYUNIONNAME.item.pszText);
     1420    COMCTL32_Free(tvisA.DUMMYUNIONNAME.item.pszText);
    14121421    }
    14131422
     
    14281437    while (kill != NULL)
    14291438    {
    1430         TREEVIEW_ITEM *next = kill->nextSibling;
    1431 
    1432         TREEVIEW_RemoveItem(infoPtr, kill);
    1433 
    1434         kill = next;
     1439    TREEVIEW_ITEM *next = kill->nextSibling;
     1440
     1441    TREEVIEW_RemoveItem(infoPtr, kill);
     1442
     1443    kill = next;
    14351444    }
    14361445
     
    14491458
    14501459    if (parentItem->firstChild == item)
    1451         parentItem->firstChild = item->nextSibling;
     1460    parentItem->firstChild = item->nextSibling;
    14521461
    14531462    if (parentItem->lastChild == item)
    1454         parentItem->lastChild = item->prevSibling;
     1463    parentItem->lastChild = item->prevSibling;
    14551464
    14561465    if (parentItem->firstChild == NULL && parentItem->lastChild == NULL
    1457         && parentItem->cChildren > 0)
    1458         parentItem->cChildren = 0;
     1466    && parentItem->cChildren > 0)
     1467    parentItem->cChildren = 0;
    14591468
    14601469    if (item->prevSibling)
    1461         item->prevSibling->nextSibling = item->nextSibling;
     1470    item->prevSibling->nextSibling = item->nextSibling;
    14621471
    14631472    if (item->nextSibling)
    1464         item->nextSibling->prevSibling = item->prevSibling;
     1473    item->nextSibling->prevSibling = item->prevSibling;
    14651474}
    14661475
     
    14711480
    14721481    TREEVIEW_SendTreeviewNotify(infoPtr, TVN_DELETEITEMW, TVC_UNKNOWN,
    1473                                 TVIF_HANDLE | TVIF_PARAM, wineItem, 0);
     1482                TVIF_HANDLE | TVIF_PARAM, wineItem, 0);
    14741483
    14751484    if (wineItem->firstChild)
    1476         TREEVIEW_RemoveAllChildren(infoPtr, wineItem);
     1485    TREEVIEW_RemoveAllChildren(infoPtr, wineItem);
    14771486
    14781487    TREEVIEW_UnlinkItem(wineItem);
     
    14811490
    14821491    if (wineItem->pszText != LPSTR_TEXTCALLBACKA)
    1483         COMCTL32_Free(wineItem->pszText);
     1492    COMCTL32_Free(wineItem->pszText);
    14841493
    14851494    TREEVIEW_FreeItem(infoPtr, wineItem);
     
    14931502    TREEVIEW_RemoveAllChildren(infoPtr, infoPtr->root);
    14941503
    1495     assert(infoPtr->uNumItems == 0);    /* root isn't counted in uNumItems */
     1504    assert(infoPtr->uNumItems == 0);    /* root isn't counted in uNumItems */
    14961505}
    14971506
     
    15071516    if (wineItem == TVI_ROOT)
    15081517    {
    1509         TRACE("TVI_ROOT\n");
    1510         parent = infoPtr->root;
    1511         newSelection = NULL;
    1512         visible = TRUE;
    1513         TREEVIEW_RemoveTree(infoPtr);
     1518    TRACE("TVI_ROOT\n");
     1519    parent = infoPtr->root;
     1520    newSelection = NULL;
     1521    visible = TRUE;
     1522    TREEVIEW_RemoveTree(infoPtr);
    15141523    }
    15151524    else
    15161525    {
    1517         if (!TREEVIEW_ValidItem(infoPtr, wineItem))
    1518             return FALSE;
    1519 
    1520         TRACE("%p (%s)\n", wineItem, TREEVIEW_ItemName(wineItem));
    1521         parent = wineItem->parent;
     1526    if (!TREEVIEW_ValidItem(infoPtr, wineItem))
     1527        return FALSE;
     1528
     1529    TRACE("%p (%s)\n", wineItem, TREEVIEW_ItemName(wineItem));
     1530    parent = wineItem->parent;
    15221531
    15231532        if (ISVISIBLE(wineItem))
     
    15271536        }
    15281537
    1529         if (infoPtr->selectedItem != NULL
    1530             && (wineItem == infoPtr->selectedItem
    1531                 || TREEVIEW_IsChildOf(wineItem, infoPtr->selectedItem)))
    1532         {
    1533             if (wineItem->nextSibling)
    1534                 newSelection = wineItem->nextSibling;
    1535             else if (wineItem->parent != infoPtr->root)
    1536                 newSelection = wineItem->parent;
    1537         }
    1538 
    1539         if (infoPtr->firstVisible == wineItem)
    1540         {
    1541             if (wineItem->nextSibling)
    1542                newFirstVisible = wineItem->nextSibling;
    1543             else if (wineItem->prevSibling)
    1544                newFirstVisible = wineItem->prevSibling;
    1545             else if (wineItem->parent != infoPtr->root)
    1546                newFirstVisible = wineItem->parent;
    1547                TREEVIEW_SetFirstVisible(infoPtr, NULL, TRUE);
    1548         }
    1549         else
    1550             newFirstVisible = infoPtr->firstVisible;
    1551 
    1552         TREEVIEW_RemoveItem(infoPtr, wineItem);
     1538    if (infoPtr->selectedItem != NULL
     1539        && (wineItem == infoPtr->selectedItem
     1540        || TREEVIEW_IsChildOf(wineItem, infoPtr->selectedItem)))
     1541    {
     1542        if (wineItem->nextSibling)
     1543        newSelection = wineItem->nextSibling;
     1544        else if (wineItem->parent != infoPtr->root)
     1545        newSelection = wineItem->parent;
     1546    }
     1547
     1548    if (infoPtr->firstVisible == wineItem)
     1549    {
     1550        if (wineItem->nextSibling)
     1551           newFirstVisible = wineItem->nextSibling;
     1552        else if (wineItem->prevSibling)
     1553           newFirstVisible = wineItem->prevSibling;
     1554        else if (wineItem->parent != infoPtr->root)
     1555           newFirstVisible = wineItem->parent;
     1556           TREEVIEW_SetFirstVisible(infoPtr, NULL, TRUE);
     1557    }
     1558    else
     1559        newFirstVisible = infoPtr->firstVisible;
     1560
     1561    TREEVIEW_RemoveItem(infoPtr, wineItem);
    15531562    }
    15541563
     
    15561565    if (oldSelection == infoPtr->selectedItem)
    15571566    {
    1558         if (TREEVIEW_ValidItem(infoPtr, newSelection))
    1559             TREEVIEW_DoSelectItem(infoPtr, TVGN_CARET, newSelection, TVC_UNKNOWN);
    1560         else
    1561             infoPtr->selectedItem = 0;
     1567    if (TREEVIEW_ValidItem(infoPtr, newSelection))
     1568        TREEVIEW_DoSelectItem(infoPtr, TVGN_CARET, newSelection, TVC_UNKNOWN);
     1569    else
     1570        infoPtr->selectedItem = 0;
    15621571    }
    15631572
     
    15661575     */
    15671576    if (!TREEVIEW_ValidItem(infoPtr, infoPtr->insertMarkItem))
    1568         infoPtr->insertMarkItem = 0;
     1577    infoPtr->insertMarkItem = 0;
    15691578
    15701579    if (!TREEVIEW_ValidItem(infoPtr, infoPtr->dropItem))
    1571         infoPtr->dropItem = 0;
     1580    infoPtr->dropItem = 0;
    15721581
    15731582    if (!TREEVIEW_ValidItem(infoPtr, newFirstVisible))
     
    16191628
    16201629    if (newIndent < MINIMUM_INDENT)
    1621         newIndent = MINIMUM_INDENT;
     1630    newIndent = MINIMUM_INDENT;
    16221631
    16231632    if (infoPtr->uIndent != newIndent)
    16241633    {
    1625         infoPtr->uIndent = newIndent;
    1626         TREEVIEW_UpdateSubTree(infoPtr, infoPtr->root);
    1627         TREEVIEW_UpdateScrollBars(infoPtr);
    1628         TREEVIEW_Invalidate(infoPtr, NULL);
     1634    infoPtr->uIndent = newIndent;
     1635    TREEVIEW_UpdateSubTree(infoPtr, infoPtr->root);
     1636    TREEVIEW_UpdateScrollBars(infoPtr);
     1637    TREEVIEW_Invalidate(infoPtr, NULL);
    16291638    }
    16301639
     
    16781687    {
    16791688    case (WPARAM)TVSIL_NORMAL:
    1680         return (LRESULT)infoPtr->himlNormal;
     1689    return (LRESULT)infoPtr->himlNormal;
    16811690
    16821691    case (WPARAM)TVSIL_STATE:
    1683         return (LRESULT)infoPtr->himlState;
     1692    return (LRESULT)infoPtr->himlState;
    16841693
    16851694    default:
    1686         return 0;
     1695    return 0;
    16871696    }
    16881697}
     
    17011710    {
    17021711    case (WPARAM)TVSIL_NORMAL:
    1703         himlOld = infoPtr->himlNormal;
    1704         infoPtr->himlNormal = himlNew;
    1705 
    1706         if (himlNew != NULL)
    1707             ImageList_GetIconSize(himlNew, &infoPtr->normalImageWidth,
    1708                                   &infoPtr->normalImageHeight);
    1709         else
    1710         {
    1711             infoPtr->normalImageWidth = 0;
    1712             infoPtr->normalImageHeight = 0;
    1713         }
    1714 
    1715         break;
     1712    himlOld = infoPtr->himlNormal;
     1713    infoPtr->himlNormal = himlNew;
     1714
     1715    if (himlNew != NULL)
     1716        ImageList_GetIconSize(himlNew, &infoPtr->normalImageWidth,
     1717                  &infoPtr->normalImageHeight);
     1718    else
     1719    {
     1720        infoPtr->normalImageWidth = 0;
     1721        infoPtr->normalImageHeight = 0;
     1722    }
     1723
     1724    break;
    17161725
    17171726    case (WPARAM)TVSIL_STATE:
    1718         himlOld = infoPtr->himlState;
    1719         infoPtr->himlState = himlNew;
    1720 
    1721         if (himlNew != NULL)
    1722             ImageList_GetIconSize(himlNew, &infoPtr->stateImageWidth,
    1723                                   &infoPtr->stateImageHeight);
    1724         else
    1725         {
    1726             infoPtr->stateImageWidth = 0;
    1727             infoPtr->stateImageHeight = 0;
    1728         }
    1729 
    1730         break;
     1727    himlOld = infoPtr->himlState;
     1728    infoPtr->himlState = himlNew;
     1729
     1730    if (himlNew != NULL)
     1731        ImageList_GetIconSize(himlNew, &infoPtr->stateImageWidth,
     1732                  &infoPtr->stateImageHeight);
     1733    else
     1734    {
     1735        infoPtr->stateImageWidth = 0;
     1736        infoPtr->stateImageHeight = 0;
     1737    }
     1738
     1739    break;
    17311740    }
    17321741
     
    17691778    if (newHeight == -1)
    17701779    {
    1771         infoPtr->uItemHeight = TREEVIEW_NaturalHeight(infoPtr);
    1772         infoPtr->bHeightSet = FALSE;
     1780    infoPtr->uItemHeight = TREEVIEW_NaturalHeight(infoPtr);
     1781    infoPtr->bHeightSet = FALSE;
    17731782    }
    17741783    else
    17751784    {
    1776         infoPtr->uItemHeight = newHeight;
    1777         infoPtr->bHeightSet = TRUE;
     1785    infoPtr->uItemHeight = newHeight;
     1786    infoPtr->bHeightSet = TRUE;
    17781787    }
    17791788
    17801789    /* Round down, unless we support odd ("non even") heights. */
    17811790    if (!(infoPtr->dwStyle) & TVS_NONEVENHEIGHT)
    1782         infoPtr->uItemHeight &= ~1;
     1791    infoPtr->uItemHeight &= ~1;
    17831792
    17841793    if (infoPtr->uItemHeight != prevHeight)
    17851794    {
    1786         TREEVIEW_RecalculateVisibleOrder(infoPtr, NULL);
    1787         TREEVIEW_UpdateScrollBars(infoPtr);
    1788         TREEVIEW_Invalidate(infoPtr, NULL);
     1795    TREEVIEW_RecalculateVisibleOrder(infoPtr, NULL);
     1796    TREEVIEW_UpdateScrollBars(infoPtr);
     1797    TREEVIEW_Invalidate(infoPtr, NULL);
    17891798    }
    17901799
     
    18311840
    18321841    if (!infoPtr->bHeightSet)
    1833         infoPtr->uItemHeight = TREEVIEW_NaturalHeight(infoPtr);
     1842    infoPtr->uItemHeight = TREEVIEW_NaturalHeight(infoPtr);
    18341843
    18351844    if (uHeight != infoPtr->uItemHeight)
     
    18421851
    18431852    if (bRedraw)
    1844         TREEVIEW_Invalidate(infoPtr, NULL);
     1853    TREEVIEW_Invalidate(infoPtr, NULL);
    18451854
    18461855    return 0;
     
    18821891
    18831892    if (infoPtr->clrText != prevColor)
    1884         TREEVIEW_Invalidate(infoPtr, NULL);
     1893    TREEVIEW_Invalidate(infoPtr, NULL);
    18851894
    18861895    return (LRESULT)prevColor;
     
    19041913
    19051914    if (newColor != prevColor)
    1906         TREEVIEW_Invalidate(infoPtr, NULL);
     1915    TREEVIEW_Invalidate(infoPtr, NULL);
    19071916
    19081917    return (LRESULT)prevColor;
     
    19351944
    19361945    if (!TREEVIEW_ValidItem(infoPtr, item))
    1937         return 0;
     1946    return 0;
    19381947
    19391948    infoPtr->insertBeforeorAfter = wParam;
     
    19611970     */
    19621971    if (pItem == NULL)
    1963         return FALSE;
     1972    return FALSE;
    19641973
    19651974    wineItem = *pItem;
    19661975    if (!TREEVIEW_ValidItem(infoPtr, wineItem) || !ISVISIBLE(wineItem))
    1967         return FALSE;
     1976    return FALSE;
    19681977
    19691978    /*
     
    19731982    if (fTextRect)
    19741983    {
    1975         /* Windows does not send TVN_GETDISPINFO here. */
    1976 
    1977         lpRect->top = wineItem->rect.top;
    1978         lpRect->bottom = wineItem->rect.bottom;
    1979 
    1980         lpRect->left = wineItem->textOffset;
    1981         lpRect->right = wineItem->textOffset + wineItem->textWidth;
     1984    /* Windows does not send TVN_GETDISPINFO here. */
     1985
     1986    lpRect->top = wineItem->rect.top;
     1987    lpRect->bottom = wineItem->rect.bottom;
     1988
     1989    lpRect->left = wineItem->textOffset;
     1990    lpRect->right = wineItem->textOffset + wineItem->textWidth;
    19821991    }
    19831992    else
    19841993    {
    1985         *lpRect = wineItem->rect;
     1994    *lpRect = wineItem->rect;
    19861995    }
    19871996
    19881997    TRACE("%s [L:%ld R:%ld T:%ld B:%ld]\n", fTextRect ? "text" : "item",
    1989           lpRect->left, lpRect->right, lpRect->top, lpRect->bottom);
     1998      lpRect->left, lpRect->right, lpRect->top, lpRect->bottom);
    19901999
    19912000    return TRUE;
     
    20072016    wineItem = tvItem->hItem;
    20082017    if (!TREEVIEW_ValidItem(infoPtr, wineItem))
    2009         return FALSE;
     2018    return FALSE;
    20102019
    20112020    TREEVIEW_UpdateDispInfo(infoPtr, wineItem, tvItem->mask);
    20122021
    20132022    if (tvItem->mask & TVIF_CHILDREN)
    2014         tvItem->cChildren = wineItem->cChildren;
     2023    tvItem->cChildren = wineItem->cChildren;
    20152024
    20162025    if (tvItem->mask & TVIF_HANDLE)
    2017         tvItem->hItem = wineItem;
     2026    tvItem->hItem = wineItem;
    20182027
    20192028    if (tvItem->mask & TVIF_IMAGE)
    2020         tvItem->iImage = wineItem->iImage;
     2029    tvItem->iImage = wineItem->iImage;
    20212030
    20222031    if (tvItem->mask & TVIF_INTEGRAL)
    2023         tvItem->iIntegral = wineItem->iIntegral;
     2032    tvItem->iIntegral = wineItem->iIntegral;
    20242033
    20252034    /* undocumented: windows ignores TVIF_PARAM and
     
    20292038
    20302039    if (tvItem->mask & TVIF_SELECTEDIMAGE)
    2031         tvItem->iSelectedImage = wineItem->iSelectedImage;
     2040    tvItem->iSelectedImage = wineItem->iSelectedImage;
    20322041
    20332042    if (tvItem->mask & TVIF_STATE) {
    20342043        /* Careful here - Windows ignores the stateMask when you get the state
    2035             That contradicts the documentation, but makes more common sense, masking
    2036             retrieval in this way seems overkill */
     2044        That contradicts the documentation, but makes more common sense, masking
     2045        retrieval in this way seems overkill */
    20372046        tvItem->state = wineItem->state;
    20382047    }
    20392048
    20402049    if (tvItem->mask & TVIF_TEXT)
    2041         lstrcpynA(tvItem->pszText, wineItem->pszText, tvItem->cchTextMax);
     2050    lstrcpynA(tvItem->pszText, wineItem->pszText, tvItem->cchTextMax);
    20422051
    20432052    TRACE("item <%p>, txt %p, img %p, mask %x\n",
    2044           wineItem, tvItem->pszText, &tvItem->iImage, tvItem->mask);
     2053      wineItem, tvItem->pszText, &tvItem->iImage, tvItem->mask);
    20452054
    20462055    return TRUE;
     
    20582067
    20592068    TRACE("item %d,mask %x\n", TREEVIEW_GetItemIndex(infoPtr, wineItem),
    2060           tvItem->mask);
     2069      tvItem->mask);
    20612070
    20622071    if (!TREEVIEW_ValidItem(infoPtr, wineItem))
    2063         return FALSE;
    2064    
     2072    return FALSE;
     2073
    20652074    /* store the orignal item values */
    20662075    originalItem = *wineItem;
    20672076
    20682077    if (!TREEVIEW_DoSetItem(infoPtr, wineItem, tvItem))
    2069         return FALSE;
     2078    return FALSE;
    20702079
    20712080    /* If the text or TVIS_BOLD was changed, and it is visible, recalculate. */
    20722081    if ((tvItem->mask & TVIF_TEXT
    2073         || (tvItem->mask & TVIF_STATE && tvItem->stateMask & TVIS_BOLD))
    2074         && ISVISIBLE(wineItem))
    2075     {
    2076         TREEVIEW_UpdateDispInfo(infoPtr, wineItem, TVIF_TEXT);
    2077         TREEVIEW_ComputeTextWidth(infoPtr, wineItem, 0);
     2082    || (tvItem->mask & TVIF_STATE && tvItem->stateMask & TVIS_BOLD))
     2083    && ISVISIBLE(wineItem))
     2084    {
     2085    TREEVIEW_UpdateDispInfo(infoPtr, wineItem, TVIF_TEXT);
     2086    TREEVIEW_ComputeTextWidth(infoPtr, wineItem, 0);
    20782087    }
    20792088
    20802089    if (tvItem->mask != 0 && ISVISIBLE(wineItem))
    20812090    {
    2082         /* The refresh updates everything, but we can't wait until then. */
    2083         TREEVIEW_ComputeItemInternalMetrics(infoPtr, wineItem);
     2091    /* The refresh updates everything, but we can't wait until then. */
     2092    TREEVIEW_ComputeItemInternalMetrics(infoPtr, wineItem);
    20842093
    20852094        /* if any of the items values changed, redraw the item */
     
    20872096        {
    20882097            if (tvItem->mask & TVIF_INTEGRAL)
    2089             {
    2090                 TREEVIEW_RecalculateVisibleOrder(infoPtr, wineItem);
    2091                 TREEVIEW_UpdateScrollBars(infoPtr);
    2092 
    2093                 TREEVIEW_Invalidate(infoPtr, NULL);
    2094             }
    2095             else
    2096             {
    2097                 TREEVIEW_UpdateScrollBars(infoPtr);
    2098                 TREEVIEW_Invalidate(infoPtr, wineItem);
    2099             }
     2098        {
     2099            TREEVIEW_RecalculateVisibleOrder(infoPtr, wineItem);
     2100            TREEVIEW_UpdateScrollBars(infoPtr);
     2101
     2102            TREEVIEW_Invalidate(infoPtr, NULL);
     2103        }
     2104        else
     2105        {
     2106            TREEVIEW_UpdateScrollBars(infoPtr);
     2107            TREEVIEW_Invalidate(infoPtr, wineItem);
     2108        }
    21002109        }
    21012110    }
     
    21482157        }
    21492158        else if (wineItem->pszText) {
    2150             TRACE("orig str %s at %p\n",
    2151                   debugstr_a(wineItem->pszText), wineItem->pszText);
     2159        TRACE("orig str %s at %p\n",
     2160          debugstr_a(wineItem->pszText), wineItem->pszText);
    21522161            MultiByteToWideChar(CP_ACP, 0, wineItem->pszText,
    21532162                                -1 , tvItem->pszText, tvItem->cchTextMax);
     
    21562165
    21572166    TRACE("item %d<%p>, txt %p<%s>, img %p, action %x\n",
    2158           iItem, tvItem, tvItem->pszText, debugstr_w(tvItem->pszText),
    2159           &tvItem->iImage, tvItem->mask);
     2167      iItem, tvItem, tvItem->pszText, debugstr_w(tvItem->pszText),
     2168      &tvItem->iImage, tvItem->mask);
    21602169    return TRUE;
    21612170}
     
    21732182    tvItemA.stateMask = tvItem->stateMask;
    21742183    if (tvItem->mask & TVIF_TEXT) {
    2175         len = WideCharToMultiByte(CP_ACP, 0, tvItem->pszText, -1,
    2176                                   NULL ,0 , NULL,NULL);
    2177         if (len) {
    2178             len ++;
     2184    len = WideCharToMultiByte(CP_ACP, 0, tvItem->pszText, -1,
     2185                  NULL ,0 , NULL,NULL);
     2186    if (len) {
     2187        len ++;
     2188#ifdef __WIN32OS2__
     2189            tvItemA.pszText = HeapAlloc(GetProcessHeap(),0,len);
     2190            len = WideCharToMultiByte(CP_ACP, 0, tvItem->pszText, -1,
     2191                                      tvItemA.pszText ,len,
     2192                                      NULL,NULL);
     2193#else
    21792194            tvItemA.pszText = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
    21802195            len = WideCharToMultiByte(CP_ACP, 0, tvItem->pszText, -1,
    21812196                                      tvItemA.pszText ,len*sizeof(WCHAR),
    21822197                                      NULL,NULL);
    2183         }
    2184         else
    2185             tvItemA.pszText = NULL;
     2198#endif
     2199    }
     2200    else
     2201        tvItemA.pszText = NULL;
    21862202    }
    21872203    tvItemA.cchTextMax = tvItem->cchTextMax;
     
    22032219
    22042220    if (!wineItem || !TREEVIEW_ValidItem(infoPtr, wineItem))
    2205         return 0;
     2221    return 0;
    22062222
    22072223    return (wineItem->state & mask);
     
    22182234    switch (which)
    22192235    {
    2220     case TVGN_CHILD:            /* Special case: child of 0 is root */
    2221         if (wineItem)
    2222             break;
    2223         /* fall through */
     2236    case TVGN_CHILD:        /* Special case: child of 0 is root */
     2237    if (wineItem)
     2238        break;
     2239    /* fall through */
    22242240    case TVGN_ROOT:
    2225         retval = infoPtr->root->firstChild;
    2226         break;
     2241    retval = infoPtr->root->firstChild;
     2242    break;
    22272243
    22282244    case TVGN_CARET:
    2229         retval = infoPtr->selectedItem;
    2230         break;
     2245    retval = infoPtr->selectedItem;
     2246    break;
    22312247
    22322248    case TVGN_FIRSTVISIBLE:
    2233         retval = infoPtr->firstVisible;
    2234         break;
     2249    retval = infoPtr->firstVisible;
     2250    break;
    22352251
    22362252    case TVGN_DROPHILITE:
    2237         retval = infoPtr->dropItem;
    2238         break;
     2253    retval = infoPtr->dropItem;
     2254    break;
    22392255
    22402256    case TVGN_LASTVISIBLE:
    2241         retval = TREEVIEW_GetLastListItem(infoPtr, infoPtr->root);
    2242         break;
     2257    retval = TREEVIEW_GetLastListItem(infoPtr, infoPtr->root);
     2258    break;
    22432259    }
    22442260
    22452261    if (retval)
    22462262    {
    2247         TRACE("flags:%x, returns %p\n", which, retval);
    2248         return (LRESULT)retval;
     2263    TRACE("flags:%x, returns %p\n", which, retval);
     2264    return (LRESULT)retval;
    22492265    }
    22502266
     
    22522268
    22532269    if (!TREEVIEW_ValidItem(infoPtr, wineItem))
    2254         return FALSE;
     2270    return FALSE;
    22552271
    22562272    switch (which)
    22572273    {
    22582274    case TVGN_NEXT:
    2259         retval = wineItem->nextSibling;
    2260         break;
     2275    retval = wineItem->nextSibling;
     2276    break;
    22612277    case TVGN_PREVIOUS:
    2262         retval = wineItem->prevSibling;
    2263         break;
     2278    retval = wineItem->prevSibling;
     2279    break;
    22642280    case TVGN_PARENT:
    2265         retval = (wineItem->parent != infoPtr->root) ? wineItem->parent : NULL;
    2266         break;
     2281    retval = (wineItem->parent != infoPtr->root) ? wineItem->parent : NULL;
     2282    break;
    22672283    case TVGN_CHILD:
    2268         retval = wineItem->firstChild;
    2269         break;
     2284    retval = wineItem->firstChild;
     2285    break;
    22702286    case TVGN_NEXTVISIBLE:
    2271         retval = TREEVIEW_GetNextListItem(infoPtr, wineItem);
    2272         break;
     2287    retval = TREEVIEW_GetNextListItem(infoPtr, wineItem);
     2288    break;
    22732289    case TVGN_PREVIOUSVISIBLE:
    2274         retval = TREEVIEW_GetPrevListItem(infoPtr, wineItem);
    2275         break;
     2290    retval = TREEVIEW_GetPrevListItem(infoPtr, wineItem);
     2291    break;
    22762292    default:
    2277         TRACE("Unknown msg %x,item %p\n", which, wineItem);
    2278         break;
     2293    TRACE("Unknown msg %x,item %p\n", which, wineItem);
     2294    break;
    22792295    }
    22802296
     
    22962312    if (infoPtr->dwStyle & TVS_CHECKBOXES)
    22972313    {
    2298         static const unsigned int state_table[] = { 0, 2, 1 };
    2299 
    2300         unsigned int state;
    2301 
    2302         state = STATEIMAGEINDEX(item->state);
    2303         TRACE("state:%x\n", state);
    2304         item->state &= ~TVIS_STATEIMAGEMASK;
    2305 
    2306         if (state < 3)
    2307             state = state_table[state];
    2308 
    2309         item->state |= INDEXTOSTATEIMAGEMASK(state);
    2310 
    2311         TRACE("state:%x\n", state);
    2312         TREEVIEW_Invalidate(infoPtr, item);
     2314    static const unsigned int state_table[] = { 0, 2, 1 };
     2315
     2316    unsigned int state;
     2317
     2318    state = STATEIMAGEINDEX(item->state);
     2319    TRACE("state:%x\n", state);
     2320    item->state &= ~TVIS_STATEIMAGEMASK;
     2321
     2322    if (state < 3)
     2323        state = state_table[state];
     2324
     2325    item->state |= INDEXTOSTATEIMAGEMASK(state);
     2326
     2327    TRACE("state:%x\n", state);
     2328    TREEVIEW_Invalidate(infoPtr, item);
    23132329    }
    23142330}
     
    23242340    LONG centerx, centery;
    23252341    BOOL lar = ((infoPtr->dwStyle
    2326                 & (TVS_LINESATROOT|TVS_HASLINES|TVS_HASBUTTONS))
    2327                 > TVS_LINESATROOT);
     2342        & (TVS_LINESATROOT|TVS_HASLINES|TVS_HASBUTTONS))
     2343        > TVS_LINESATROOT);
    23282344
    23292345    if (!lar && item->iLevel == 0)
    2330         return;
     2346    return;
    23312347
    23322348    centerx = (item->linesOffset + item->stateOffset) / 2;
     
    23352351    if (infoPtr->dwStyle & TVS_HASLINES)
    23362352    {
    2337         HPEN hOldPen, hNewPen;
    2338         HTREEITEM parent;
    2339 
    2340         /*
    2341         * Get a dotted grey pen
    2342         */
    2343         hNewPen = CreatePen(PS_ALTERNATE, 0, infoPtr->clrLine);
    2344         hOldPen = SelectObject(hdc, hNewPen);
    2345 
    2346         MoveToEx(hdc, item->stateOffset, centery, NULL);
    2347         LineTo(hdc, centerx - 1, centery);
    2348 
    2349         if (item->prevSibling || item->parent != infoPtr->root)
    2350         {
    2351             MoveToEx(hdc, centerx, item->rect.top, NULL);
    2352             LineTo(hdc, centerx, centery);
    2353         }
    2354 
    2355         if (item->nextSibling)
    2356         {
    2357             MoveToEx(hdc, centerx, centery, NULL);
    2358             LineTo(hdc, centerx, item->rect.bottom + 1);
    2359         }
    2360 
    2361         /* Draw the line from our parent to its next sibling. */
    2362         parent = item->parent;
    2363         while (parent != infoPtr->root)
    2364         {
    2365             int pcenterx = (parent->linesOffset + parent->stateOffset) / 2;
    2366 
    2367             if (parent->nextSibling
    2368                 /* skip top-levels unless TVS_LINESATROOT */
    2369                 && parent->stateOffset > parent->linesOffset)
    2370             {
    2371                 MoveToEx(hdc, pcenterx, item->rect.top, NULL);
    2372                 LineTo(hdc, pcenterx, item->rect.bottom + 1);
    2373             }
    2374 
    2375             parent = parent->parent;
    2376         }
    2377 
    2378         SelectObject(hdc, hOldPen);
    2379         DeleteObject(hNewPen);
     2353    HPEN hOldPen, hNewPen;
     2354    HTREEITEM parent;
     2355
     2356    /*
     2357    * Get a dotted grey pen
     2358    */
     2359    hNewPen = CreatePen(PS_ALTERNATE, 0, infoPtr->clrLine);
     2360    hOldPen = SelectObject(hdc, hNewPen);
     2361
     2362    MoveToEx(hdc, item->stateOffset, centery, NULL);
     2363    LineTo(hdc, centerx - 1, centery);
     2364
     2365    if (item->prevSibling || item->parent != infoPtr->root)
     2366    {
     2367        MoveToEx(hdc, centerx, item->rect.top, NULL);
     2368        LineTo(hdc, centerx, centery);
     2369    }
     2370
     2371    if (item->nextSibling)
     2372    {
     2373        MoveToEx(hdc, centerx, centery, NULL);
     2374        LineTo(hdc, centerx, item->rect.bottom + 1);
     2375    }
     2376
     2377    /* Draw the line from our parent to its next sibling. */
     2378    parent = item->parent;
     2379    while (parent != infoPtr->root)
     2380    {
     2381        int pcenterx = (parent->linesOffset + parent->stateOffset) / 2;
     2382
     2383        if (parent->nextSibling
     2384        /* skip top-levels unless TVS_LINESATROOT */
     2385        && parent->stateOffset > parent->linesOffset)
     2386        {
     2387        MoveToEx(hdc, pcenterx, item->rect.top, NULL);
     2388        LineTo(hdc, pcenterx, item->rect.bottom + 1);
     2389        }
     2390
     2391        parent = parent->parent;
     2392    }
     2393
     2394    SelectObject(hdc, hOldPen);
     2395    DeleteObject(hNewPen);
    23802396    }
    23812397
     
    23862402    if (infoPtr->dwStyle & TVS_HASBUTTONS)
    23872403    {
    2388         if (item->cChildren)
    2389         {
    2390             LONG height = item->rect.bottom - item->rect.top;
    2391             LONG width  = item->stateOffset - item->linesOffset;
    2392             LONG rectsize = min(height, width) / 4;
    2393             /* plussize = ceil(rectsize * 3/4) */
    2394             LONG plussize = (rectsize + 1) * 3 / 4;
    2395 
    2396             HPEN hNewPen  = CreatePen(PS_SOLID, 0, infoPtr->clrLine);
    2397             HPEN hOldPen  = SelectObject(hdc, hNewPen);
    2398             HBRUSH hbr    = CreateSolidBrush(infoPtr->clrBk);
    2399             HBRUSH hbrOld = SelectObject(hdc, hbr);
    2400 
    2401             Rectangle(hdc, centerx - rectsize, centery - rectsize,
    2402                       centerx + rectsize + 1, centery + rectsize + 1);
    2403 
    2404             SelectObject(hdc, hbrOld);
    2405             DeleteObject(hbr);
    2406 
    2407             SelectObject(hdc, hOldPen);
    2408             DeleteObject(hNewPen);
    2409 
    2410             MoveToEx(hdc, centerx - plussize + 1, centery, NULL);
    2411             LineTo(hdc, centerx + plussize, centery);
    2412 
    2413             if (!(item->state & TVIS_EXPANDED))
    2414             {
    2415                 MoveToEx(hdc, centerx, centery - plussize + 1, NULL);
    2416                 LineTo(hdc, centerx, centery + plussize);
    2417             }
    2418         }
     2404    if (item->cChildren)
     2405    {
     2406        LONG height = item->rect.bottom - item->rect.top;
     2407        LONG width  = item->stateOffset - item->linesOffset;
     2408        LONG rectsize = min(height, width) / 4;
     2409        /* plussize = ceil(rectsize * 3/4) */
     2410        LONG plussize = (rectsize + 1) * 3 / 4;
     2411
     2412        HPEN hNewPen  = CreatePen(PS_SOLID, 0, infoPtr->clrLine);
     2413        HPEN hOldPen  = SelectObject(hdc, hNewPen);
     2414        HBRUSH hbr    = CreateSolidBrush(infoPtr->clrBk);
     2415        HBRUSH hbrOld = SelectObject(hdc, hbr);
     2416
     2417        Rectangle(hdc, centerx - rectsize, centery - rectsize,
     2418              centerx + rectsize + 1, centery + rectsize + 1);
     2419
     2420        SelectObject(hdc, hbrOld);
     2421        DeleteObject(hbr);
     2422
     2423        SelectObject(hdc, hOldPen);
     2424        DeleteObject(hNewPen);
     2425
     2426        MoveToEx(hdc, centerx - plussize + 1, centery, NULL);
     2427        LineTo(hdc, centerx + plussize, centery);
     2428
     2429        if (!(item->state & TVIS_EXPANDED))
     2430        {
     2431        MoveToEx(hdc, centerx, centery - plussize + 1, NULL);
     2432        LineTo(hdc, centerx, centery + plussize);
     2433        }
     2434    }
    24192435    }
    24202436}
     
    24392455    if (infoPtr->cdmode & CDRF_NOTIFYITEMDRAW)
    24402456    {
    2441         cditem = TREEVIEW_SendCustomDrawItemNotify
    2442             (infoPtr, hdc, wineItem, CDDS_ITEMPREPAINT);
    2443         TRACE("prepaint:cditem-app returns 0x%x\n", cditem);
    2444 
    2445         if (cditem & CDRF_SKIPDEFAULT)
    2446         {
    2447             SelectObject(hdc, hOldFont);
    2448             return;
    2449         }
     2457    cditem = TREEVIEW_SendCustomDrawItemNotify
     2458        (infoPtr, hdc, wineItem, CDDS_ITEMPREPAINT);
     2459    TRACE("prepaint:cditem-app returns 0x%x\n", cditem);
     2460
     2461    if (cditem & CDRF_SKIPDEFAULT)
     2462    {
     2463        SelectObject(hdc, hOldFont);
     2464        return;
     2465    }
    24502466    }
    24512467
    24522468    if (cditem & CDRF_NEWFONT)
    2453         TREEVIEW_ComputeTextWidth(infoPtr, wineItem, hdc);
     2469    TREEVIEW_ComputeTextWidth(infoPtr, wineItem, hdc);
    24542470
    24552471    TREEVIEW_DrawItemLines(infoPtr, hdc, wineItem);
     
    24612477     */
    24622478    {
    2463         INT imageIndex;
    2464 
    2465         /* State images are displayed to the left of the Normal image
    2466         * image number is in state; zero should be `display no image'.
    2467         */
    2468         imageIndex = STATEIMAGEINDEX(wineItem->state);
    2469 
    2470         if (infoPtr->himlState && imageIndex)
    2471         {
    2472             ImageList_Draw(infoPtr->himlState, imageIndex, hdc,
    2473                            wineItem->stateOffset,
    2474                            centery - infoPtr->stateImageHeight / 2,
    2475                            ILD_NORMAL);
    2476         }
    2477 
    2478         /* Now, draw the normal image; can be either selected or
    2479         * non-selected image.
    2480         */
    2481 
    2482         if ((wineItem->state & TVIS_SELECTED) && (wineItem->iSelectedImage))
    2483         {
    2484             /* The item is currently selected */
    2485             imageIndex = wineItem->iSelectedImage;
    2486         }
    2487         else
    2488         {
    2489             /* The item is not selected */
    2490             imageIndex = wineItem->iImage;
    2491         }
    2492 
    2493         if (infoPtr->himlNormal)
    2494         {
    2495             int ovlIdx = wineItem->state & TVIS_OVERLAYMASK;
    2496 
    2497             ImageList_Draw(infoPtr->himlNormal, imageIndex, hdc,
    2498                            wineItem->imageOffset,
    2499                            centery - infoPtr->normalImageHeight / 2,
    2500                            ILD_NORMAL | ovlIdx);
    2501         }
     2479    INT imageIndex;
     2480
     2481    /* State images are displayed to the left of the Normal image
     2482    * image number is in state; zero should be `display no image'.
     2483    */
     2484    imageIndex = STATEIMAGEINDEX(wineItem->state);
     2485
     2486    if (infoPtr->himlState && imageIndex)
     2487    {
     2488        ImageList_Draw(infoPtr->himlState, imageIndex, hdc,
     2489               wineItem->stateOffset,
     2490               centery - infoPtr->stateImageHeight / 2,
     2491               ILD_NORMAL);
     2492    }
     2493
     2494    /* Now, draw the normal image; can be either selected or
     2495    * non-selected image.
     2496    */
     2497
     2498    if ((wineItem->state & TVIS_SELECTED) && (wineItem->iSelectedImage))
     2499    {
     2500        /* The item is currently selected */
     2501        imageIndex = wineItem->iSelectedImage;
     2502    }
     2503    else
     2504    {
     2505        /* The item is not selected */
     2506        imageIndex = wineItem->iImage;
     2507    }
     2508
     2509    if (infoPtr->himlNormal)
     2510    {
     2511        int ovlIdx = wineItem->state & TVIS_OVERLAYMASK;
     2512
     2513        ImageList_Draw(infoPtr->himlNormal, imageIndex, hdc,
     2514               wineItem->imageOffset,
     2515               centery - infoPtr->normalImageHeight / 2,
     2516               ILD_NORMAL | ovlIdx);
     2517    }
    25022518    }
    25032519
     
    25102526    if (!infoPtr->hwndEdit || (infoPtr->selectedItem != wineItem))
    25112527    {
    2512         if (wineItem->pszText)
    2513         {
    2514             COLORREF oldTextColor = 0;
    2515             INT oldBkMode;
    2516             HBRUSH hbrBk = 0;
    2517             BOOL inFocus = (GetFocus() == infoPtr->hwnd);
    2518             RECT rcText;
    2519 
    2520             oldBkMode = SetBkMode(hdc, TRANSPARENT);
    2521 
    2522             /* - If item is drop target or it is selected and window is in focus -
    2523              * use blue background (COLOR_HIGHLIGHT).
    2524              * - If item is selected, window is not in focus, but it has style
    2525              * TVS_SHOWSELALWAYS - use grey background (COLOR_BTNFACE)
    2526              * - Otherwise - don't fill background
    2527              */
    2528             if ((wineItem->state & TVIS_DROPHILITED) || ((wineItem == infoPtr->focusedItem) && !(wineItem->state & TVIS_SELECTED)) ||
    2529                 ((wineItem->state & TVIS_SELECTED) && (!infoPtr->focusedItem) &&
    2530                 (inFocus || (infoPtr->dwStyle & TVS_SHOWSELALWAYS))))
    2531             {
    2532                 if ((wineItem->state & TVIS_DROPHILITED) || inFocus)
    2533                 {
    2534                     hbrBk = CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT));
    2535                     oldTextColor =
    2536                         SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
    2537                 }
    2538                 else
    2539                 {
    2540                     hbrBk = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
    2541 
    2542                     if (infoPtr->clrText == -1)
    2543                         oldTextColor =
    2544                             SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
    2545                     else
    2546                         oldTextColor = SetTextColor(hdc, infoPtr->clrText);
    2547                 }
    2548             }
    2549             else
    2550             {
    2551                 if (infoPtr->clrText == -1)
    2552                     oldTextColor =
    2553                         SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
    2554                 else
    2555                     oldTextColor = SetTextColor(hdc, infoPtr->clrText);
    2556             }
    2557 
    2558             rcText.top = wineItem->rect.top;
    2559             rcText.bottom = wineItem->rect.bottom;
    2560             rcText.left = wineItem->textOffset;
    2561             rcText.right = rcText.left + wineItem->textWidth + 4;
    2562 
    2563             if (hbrBk)
    2564             {
    2565                 FillRect(hdc, &rcText, hbrBk);
    2566                 DeleteObject(hbrBk);
    2567             }
    2568 
    2569             /* Draw the box around the selected item */
    2570             if ((wineItem == infoPtr->selectedItem) && inFocus)
    2571             {
    2572                 DrawFocusRect(hdc,&rcText);
    2573             }
    2574 
    2575             InflateRect(&rcText, -2, -1); /* allow for the focus rect */
    2576 
    2577             TRACE("drawing text %s at (%ld,%ld)-(%ld,%ld)\n",
    2578                   debugstr_a(wineItem->pszText),
    2579                   rcText.left, rcText.top, rcText.right, rcText.bottom);
    2580 
    2581             /* Draw it */
    2582             DrawTextA(hdc,
    2583                       wineItem->pszText,
    2584                       lstrlenA(wineItem->pszText),
    2585                       &rcText,
    2586                       DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX);
    2587 
    2588             /* Restore the hdc state */
    2589             SetTextColor(hdc, oldTextColor);
    2590 
    2591             if (oldBkMode != TRANSPARENT)
    2592                 SetBkMode(hdc, oldBkMode);
    2593         }
     2528    if (wineItem->pszText)
     2529    {
     2530        COLORREF oldTextColor = 0;
     2531        INT oldBkMode;
     2532        HBRUSH hbrBk = 0;
     2533        BOOL inFocus = (GetFocus() == infoPtr->hwnd);
     2534        RECT rcText;
     2535
     2536        oldBkMode = SetBkMode(hdc, TRANSPARENT);
     2537
     2538        /* - If item is drop target or it is selected and window is in focus -
     2539         * use blue background (COLOR_HIGHLIGHT).
     2540         * - If item is selected, window is not in focus, but it has style
     2541         * TVS_SHOWSELALWAYS - use grey background (COLOR_BTNFACE)
     2542         * - Otherwise - don't fill background
     2543         */
     2544        if ((wineItem->state & TVIS_DROPHILITED) || ((wineItem == infoPtr->focusedItem) && !(wineItem->state & TVIS_SELECTED)) ||
     2545        ((wineItem->state & TVIS_SELECTED) && (!infoPtr->focusedItem) &&
     2546        (inFocus || (infoPtr->dwStyle & TVS_SHOWSELALWAYS))))
     2547        {
     2548        if ((wineItem->state & TVIS_DROPHILITED) || inFocus)
     2549        {
     2550            hbrBk = CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT));
     2551            oldTextColor =
     2552            SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
     2553        }
     2554        else
     2555        {
     2556            hbrBk = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
     2557
     2558            if (infoPtr->clrText == -1)
     2559            oldTextColor =
     2560                SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
     2561            else
     2562            oldTextColor = SetTextColor(hdc, infoPtr->clrText);
     2563        }
     2564        }
     2565        else
     2566        {
     2567        if (infoPtr->clrText == -1)
     2568            oldTextColor =
     2569            SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
     2570        else
     2571            oldTextColor = SetTextColor(hdc, infoPtr->clrText);
     2572        }
     2573
     2574        rcText.top = wineItem->rect.top;
     2575        rcText.bottom = wineItem->rect.bottom;
     2576        rcText.left = wineItem->textOffset;
     2577        rcText.right = rcText.left + wineItem->textWidth + 4;
     2578
     2579        if (hbrBk)
     2580        {
     2581        FillRect(hdc, &rcText, hbrBk);
     2582        DeleteObject(hbrBk);
     2583        }
     2584
     2585        /* Draw the box around the selected item */
     2586        if ((wineItem == infoPtr->selectedItem) && inFocus)
     2587        {
     2588        DrawFocusRect(hdc,&rcText);
     2589        }
     2590
     2591        InflateRect(&rcText, -2, -1); /* allow for the focus rect */
     2592
     2593        TRACE("drawing text %s at (%ld,%ld)-(%ld,%ld)\n",
     2594          debugstr_a(wineItem->pszText),
     2595          rcText.left, rcText.top, rcText.right, rcText.bottom);
     2596
     2597        /* Draw it */
     2598        DrawTextA(hdc,
     2599              wineItem->pszText,
     2600              lstrlenA(wineItem->pszText),
     2601              &rcText,
     2602              DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX);
     2603
     2604        /* Restore the hdc state */
     2605        SetTextColor(hdc, oldTextColor);
     2606
     2607        if (oldBkMode != TRANSPARENT)
     2608        SetBkMode(hdc, oldBkMode);
     2609    }
    25942610    }
    25952611
     
    25972613
    25982614    if (infoPtr->insertMarkItem)
    2599         TRACE("item:%d,mark:%d\n",
    2600               TREEVIEW_GetItemIndex(infoPtr, wineItem),
    2601               (int)infoPtr->insertMarkItem);
     2615    TRACE("item:%d,mark:%d\n",
     2616          TREEVIEW_GetItemIndex(infoPtr, wineItem),
     2617          (int)infoPtr->insertMarkItem);
    26022618
    26032619    if (wineItem == infoPtr->insertMarkItem)
    26042620    {
    2605         HPEN hNewPen, hOldPen;
    2606         int offset;
    2607         int left, right;
    2608 
    2609         hNewPen = CreatePen(PS_SOLID, 2, infoPtr->clrInsertMark);
    2610         hOldPen = SelectObject(hdc, hNewPen);
    2611 
    2612         if (infoPtr->insertBeforeorAfter)
    2613             offset = wineItem->rect.bottom - 1;
    2614         else
    2615             offset = wineItem->rect.top + 1;
    2616 
    2617         left = wineItem->textOffset - 2;
    2618         right = wineItem->textOffset + wineItem->textWidth + 2;
    2619 
    2620         MoveToEx(hdc, left, offset - 3, NULL);
    2621         LineTo(hdc, left, offset + 4);
    2622 
    2623         MoveToEx(hdc, left, offset, NULL);
    2624         LineTo(hdc, right + 1, offset);
    2625 
    2626         MoveToEx(hdc, right, offset + 3, NULL);
    2627         LineTo(hdc, right, offset - 4);
    2628 
    2629         SelectObject(hdc, hOldPen);
    2630         DeleteObject(hNewPen);
     2621    HPEN hNewPen, hOldPen;
     2622    int offset;
     2623    int left, right;
     2624
     2625    hNewPen = CreatePen(PS_SOLID, 2, infoPtr->clrInsertMark);
     2626    hOldPen = SelectObject(hdc, hNewPen);
     2627
     2628    if (infoPtr->insertBeforeorAfter)
     2629        offset = wineItem->rect.bottom - 1;
     2630    else
     2631        offset = wineItem->rect.top + 1;
     2632
     2633    left = wineItem->textOffset - 2;
     2634    right = wineItem->textOffset + wineItem->textWidth + 2;
     2635
     2636    MoveToEx(hdc, left, offset - 3, NULL);
     2637    LineTo(hdc, left, offset + 4);
     2638
     2639    MoveToEx(hdc, left, offset, NULL);
     2640    LineTo(hdc, right + 1, offset);
     2641
     2642    MoveToEx(hdc, right, offset + 3, NULL);
     2643    LineTo(hdc, right, offset - 4);
     2644
     2645    SelectObject(hdc, hOldPen);
     2646    DeleteObject(hNewPen);
    26312647    }
    26322648
    26332649    if (cditem & CDRF_NOTIFYPOSTPAINT)
    26342650    {
    2635         cditem = TREEVIEW_SendCustomDrawItemNotify
    2636             (infoPtr, hdc, wineItem, CDDS_ITEMPOSTPAINT);
    2637         TRACE("postpaint:cditem-app returns 0x%x\n", cditem);
     2651    cditem = TREEVIEW_SendCustomDrawItemNotify
     2652        (infoPtr, hdc, wineItem, CDDS_ITEMPOSTPAINT);
     2653    TRACE("postpaint:cditem-app returns 0x%x\n", cditem);
    26382654    }
    26392655
     
    26622678    while (wineItem != NULL)
    26632679    {
    2664         if (ISVISIBLE(wineItem))
    2665         {
     2680    if (ISVISIBLE(wineItem))
     2681    {
    26662682            /* actually we draw text at textOffset + 2 */
    2667             if (2+wineItem->textOffset+wineItem->textWidth > infoPtr->treeWidth)
    2668                 infoPtr->treeWidth = wineItem->textOffset+wineItem->textWidth+2;
    2669 
    2670             /* This is scroll-adjusted, but we fix this below. */
    2671             infoPtr->treeHeight = wineItem->rect.bottom;
    2672         }
    2673 
    2674         wineItem = TREEVIEW_GetNextListItem(infoPtr, wineItem);
     2683        if (2+wineItem->textOffset+wineItem->textWidth > infoPtr->treeWidth)
     2684        infoPtr->treeWidth = wineItem->textOffset+wineItem->textWidth+2;
     2685
     2686        /* This is scroll-adjusted, but we fix this below. */
     2687        infoPtr->treeHeight = wineItem->rect.bottom;
     2688    }
     2689
     2690    wineItem = TREEVIEW_GetNextListItem(infoPtr, wineItem);
    26752691    }
    26762692
    26772693    /* Fix the scroll adjusted treeHeight and treeWidth. */
    26782694    if (infoPtr->root->firstChild)
    2679         infoPtr->treeHeight -= infoPtr->root->firstChild->rect.top;
     2695    infoPtr->treeHeight -= infoPtr->root->firstChild->rect.top;
    26802696
    26812697    infoPtr->treeWidth += infoPtr->scrollX;
     
    26872703    if (infoPtr->treeHeight > infoPtr->clientHeight)
    26882704    {
    2689         vert = TRUE;
    2690 
    2691         if (infoPtr->treeWidth
    2692             > infoPtr->clientWidth - GetSystemMetrics(SM_CXVSCROLL))
    2693             horz = TRUE;
     2705    vert = TRUE;
     2706
     2707    if (infoPtr->treeWidth
     2708        > infoPtr->clientWidth - GetSystemMetrics(SM_CXVSCROLL))
     2709        horz = TRUE;
    26942710    }
    26952711    else if (infoPtr->treeWidth > infoPtr->clientWidth)
    2696         horz = TRUE;
     2712    horz = TRUE;
    26972713
    26982714    if (!vert && horz && infoPtr->treeHeight
    2699         > infoPtr->clientHeight - GetSystemMetrics(SM_CYVSCROLL))
    2700         vert = TRUE;
     2715    > infoPtr->clientHeight - GetSystemMetrics(SM_CYVSCROLL))
     2716    vert = TRUE;
    27012717
    27022718    if (horz && (infoPtr->dwStyle & TVS_NOHSCROLL)) horz = FALSE;
     
    27082724    if (vert)
    27092725    {
    2710         si.nPage = TREEVIEW_GetVisibleCount(infoPtr);
     2726    si.nPage = TREEVIEW_GetVisibleCount(infoPtr);
    27112727       if ( si.nPage )
    27122728       {
     
    27292745    else
    27302746    {
    2731         if (infoPtr->uInternalStatus & TV_VSCROLL)
    2732             ShowScrollBar(hwnd, SB_VERT, FALSE);
    2733         infoPtr->uInternalStatus &= ~TV_VSCROLL;
     2747    if (infoPtr->uInternalStatus & TV_VSCROLL)
     2748        ShowScrollBar(hwnd, SB_VERT, FALSE);
     2749    infoPtr->uInternalStatus &= ~TV_VSCROLL;
    27342750    }
    27352751
    27362752    if (horz)
    27372753    {
    2738         si.nPage = infoPtr->clientWidth;
    2739         si.nPos  = infoPtr->scrollX;
    2740         si.nMax  = infoPtr->treeWidth - 1;
    2741 
    2742         if (si.nPos > si.nMax - max( si.nPage-1, 0 ))
     2754    si.nPage = infoPtr->clientWidth;
     2755    si.nPos  = infoPtr->scrollX;
     2756    si.nMax  = infoPtr->treeWidth - 1;
     2757
     2758    if (si.nPos > si.nMax - max( si.nPage-1, 0 ))
    27432759        {
    27442760           si.nPos = si.nMax - max( si.nPage-1, 0 );
     
    27462762        }
    27472763
    2748         if (!(infoPtr->uInternalStatus & TV_HSCROLL))
    2749             ShowScrollBar(hwnd, SB_HORZ, TRUE);
    2750         infoPtr->uInternalStatus |= TV_HSCROLL;
    2751 
    2752         SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);
     2764    if (!(infoPtr->uInternalStatus & TV_HSCROLL))
     2765        ShowScrollBar(hwnd, SB_HORZ, TRUE);
     2766    infoPtr->uInternalStatus |= TV_HSCROLL;
     2767
     2768    SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);
    27532769    }
    27542770    else
    27552771    {
    2756         if (infoPtr->uInternalStatus & TV_HSCROLL)
    2757             ShowScrollBar(hwnd, SB_HORZ, FALSE);
    2758         infoPtr->uInternalStatus &= ~TV_HSCROLL;
    2759 
    2760         scrollX = 0;
     2772    if (infoPtr->uInternalStatus & TV_HSCROLL)
     2773        ShowScrollBar(hwnd, SB_HORZ, FALSE);
     2774    infoPtr->uInternalStatus &= ~TV_HSCROLL;
     2775
     2776    scrollX = 0;
    27612777    }
    27622778
    27632779    if (infoPtr->scrollX != scrollX)
    27642780    {
    2765         TREEVIEW_HScroll(infoPtr,
    2766                          MAKEWPARAM(SB_THUMBPOSITION, scrollX));
     2781    TREEVIEW_HScroll(infoPtr,
     2782                     MAKEWPARAM(SB_THUMBPOSITION, scrollX));
    27672783    }
    27682784
    27692785    if (!horz)
    2770         infoPtr->uInternalStatus &= ~TV_HSCROLL;
     2786    infoPtr->uInternalStatus &= ~TV_HSCROLL;
    27712787}
    27722788
     
    27942810    if (infoPtr->clientHeight == 0 || infoPtr->clientWidth == 0)
    27952811    {
    2796         TRACE("empty window\n");
    2797         return;
     2812    TRACE("empty window\n");
     2813    return;
    27982814    }
    27992815
    28002816    infoPtr->cdmode = TREEVIEW_SendCustomDrawNotify(infoPtr, CDDS_PREPAINT,
    2801                                                     hdc, rect);
     2817                            hdc, rect);
    28022818
    28032819    if (infoPtr->cdmode == CDRF_SKIPDEFAULT)
    28042820    {
    2805         ReleaseDC(hwnd, hdc);
    2806         return;
     2821    ReleaseDC(hwnd, hdc);
     2822    return;
    28072823    }
    28082824
     
    28112827         wineItem = TREEVIEW_GetNextListItem(infoPtr, wineItem))
    28122828    {
    2813         if (ISVISIBLE(wineItem))
    2814         {
     2829    if (ISVISIBLE(wineItem))
     2830    {
    28152831            /* Avoid unneeded calculations */
    28162832            if (wineItem->rect.top > rect.bottom)
     
    28192835                continue;
    28202836
    2821             TREEVIEW_DrawItem(infoPtr, hdc, wineItem);
    2822         }
     2837        TREEVIEW_DrawItem(infoPtr, hdc, wineItem);
     2838    }
    28232839    }
    28242840
     
    28262842
    28272843    if (infoPtr->cdmode & CDRF_NOTIFYPOSTPAINT)
    2828         infoPtr->cdmode =
    2829             TREEVIEW_SendCustomDrawNotify(infoPtr, CDDS_POSTPAINT, hdc, rect);
     2844    infoPtr->cdmode =
     2845        TREEVIEW_SendCustomDrawNotify(infoPtr, CDDS_POSTPAINT, hdc, rect);
    28302846}
    28312847
     
    28342850{
    28352851    if (item != NULL)
    2836         InvalidateRect(infoPtr->hwnd, &item->rect, TRUE);
     2852    InvalidateRect(infoPtr->hwnd, &item->rect, TRUE);
    28372853    else
    28382854        InvalidateRect(infoPtr->hwnd, NULL, TRUE);
     
    28742890
    28752891    if (!wParam)
    2876         EndPaint(infoPtr->hwnd, &ps);
     2892    EndPaint(infoPtr->hwnd, &ps);
    28772893
    28782894    return 0;
     
    28902906    /* Forward the call to the client-defined callback */
    28912907    return pCallBackSort->lpfnCompare(first->lParam,
    2892                                       second->lParam,
    2893                                       pCallBackSort->lParam);
     2908                      second->lParam,
     2909                      pCallBackSort->lParam);
    28942910}
    28952911
     
    29152931
    29162932    for (hti = item->firstChild; hti != NULL; hti = hti->nextSibling)
    2917         cChildren++;
     2933    cChildren++;
    29182934
    29192935    return cChildren;
     
    29322948    for (child = item->firstChild; child != NULL; child = child->nextSibling)
    29332949    {
    2934         if (DPA_InsertPtr(list, INT_MAX, child) == -1)
    2935         {
    2936             DPA_Destroy(list);
    2937             return NULL;
    2938         }
     2950    if (DPA_InsertPtr(list, INT_MAX, child) == -1)
     2951    {
     2952        DPA_Destroy(list);
     2953        return NULL;
     2954    }
    29392955    }
    29402956
     
    29552971static LRESULT
    29562972TREEVIEW_Sort(TREEVIEW_INFO *infoPtr, BOOL fRecurse, HTREEITEM parent,
    2957               LPTVSORTCB pSort)
     2973          LPTVSORTCB pSort)
    29582974{
    29592975    INT cChildren;
     
    29632979    /* undocumented feature: TVI_ROOT or NULL means `sort the whole tree' */
    29642980    if (parent == TVI_ROOT || parent == NULL)
    2965         parent = infoPtr->root;
     2981    parent = infoPtr->root;
    29662982
    29672983    /* Check for a valid handle to the parent item */
    29682984    if (!TREEVIEW_ValidItem(infoPtr, parent))
    29692985    {
    2970         ERR("invalid item hParent=%x\n", (INT)parent);
    2971         return FALSE;
     2986    ERR("invalid item hParent=%x\n", (INT)parent);
     2987    return FALSE;
    29722988    }
    29732989
    29742990    if (pSort)
    29752991    {
    2976         pfnCompare = (PFNDPACOMPARE)TREEVIEW_CallBackCompare;
    2977         lpCompare = (LPARAM)pSort;
     2992    pfnCompare = (PFNDPACOMPARE)TREEVIEW_CallBackCompare;
     2993    lpCompare = (LPARAM)pSort;
    29782994    }
    29792995    else
    29802996    {
    2981         pfnCompare = (PFNDPACOMPARE)TREEVIEW_SortOnName;
    2982         lpCompare = (LPARAM)infoPtr;
     2997    pfnCompare = (PFNDPACOMPARE)TREEVIEW_SortOnName;
     2998    lpCompare = (LPARAM)infoPtr;
    29832999    }
    29843000
     
    29883004    if (cChildren > 1)
    29893005    {
    2990         /* TREEVIEW_ITEM rechaining */
    2991         INT count = 0;
    2992         HTREEITEM item = 0;
    2993         HTREEITEM nextItem = 0;
    2994         HTREEITEM prevItem = 0;
    2995 
    2996         HDPA sortList = TREEVIEW_BuildChildDPA(infoPtr, parent);
    2997 
    2998         if (sortList == NULL)
    2999             return FALSE;
    3000 
    3001         /* let DPA sort the list */
    3002         DPA_Sort(sortList, pfnCompare, lpCompare);
    3003 
    3004         /* The order of DPA entries has been changed, so fixup the
    3005         * nextSibling and prevSibling pointers. */
    3006 
    3007         item = (HTREEITEM)DPA_GetPtr(sortList, count++);
    3008         while ((nextItem = (HTREEITEM)DPA_GetPtr(sortList, count++)) != NULL)
    3009         {
    3010             /* link the two current item toghether */
    3011             item->nextSibling = nextItem;
    3012             nextItem->prevSibling = item;
    3013 
    3014             if (prevItem == NULL)
    3015             {
    3016                 /* this is the first item, update the parent */
    3017                 parent->firstChild = item;
    3018                 item->prevSibling = NULL;
    3019             }
    3020             else
    3021             {
    3022                 /* fix the back chaining */
    3023                 item->prevSibling = prevItem;
    3024             }
    3025 
    3026             /* get ready for the next one */
    3027             prevItem = item;
    3028             item = nextItem;
    3029         }
    3030 
    3031         /* the last item is pointed to by item and never has a sibling */
    3032         item->nextSibling = NULL;
    3033         parent->lastChild = item;
    3034 
    3035         DPA_Destroy(sortList);
    3036 
    3037         TREEVIEW_VerifyTree(infoPtr);
    3038 
    3039         if (parent->state & TVIS_EXPANDED)
    3040         {
    3041             int visOrder = infoPtr->firstVisible->visibleOrder;
     3006    /* TREEVIEW_ITEM rechaining */
     3007    INT count = 0;
     3008    HTREEITEM item = 0;
     3009    HTREEITEM nextItem = 0;
     3010    HTREEITEM prevItem = 0;
     3011
     3012    HDPA sortList = TREEVIEW_BuildChildDPA(infoPtr, parent);
     3013
     3014    if (sortList == NULL)
     3015        return FALSE;
     3016
     3017    /* let DPA sort the list */
     3018    DPA_Sort(sortList, pfnCompare, lpCompare);
     3019
     3020    /* The order of DPA entries has been changed, so fixup the
     3021    * nextSibling and prevSibling pointers. */
     3022
     3023    item = (HTREEITEM)DPA_GetPtr(sortList, count++);
     3024    while ((nextItem = (HTREEITEM)DPA_GetPtr(sortList, count++)) != NULL)
     3025    {
     3026        /* link the two current item toghether */
     3027        item->nextSibling = nextItem;
     3028        nextItem->prevSibling = item;
     3029
     3030        if (prevItem == NULL)
     3031        {
     3032        /* this is the first item, update the parent */
     3033        parent->firstChild = item;
     3034        item->prevSibling = NULL;
     3035        }
     3036        else
     3037        {
     3038        /* fix the back chaining */
     3039        item->prevSibling = prevItem;
     3040        }
     3041
     3042        /* get ready for the next one */
     3043        prevItem = item;
     3044        item = nextItem;
     3045    }
     3046
     3047    /* the last item is pointed to by item and never has a sibling */
     3048    item->nextSibling = NULL;
     3049    parent->lastChild = item;
     3050
     3051    DPA_Destroy(sortList);
     3052
     3053    TREEVIEW_VerifyTree(infoPtr);
     3054
     3055    if (parent->state & TVIS_EXPANDED)
     3056    {
     3057        int visOrder = infoPtr->firstVisible->visibleOrder;
    30423058
    30433059        if (parent == infoPtr->root)
     
    30463062            TREEVIEW_RecalculateVisibleOrder(infoPtr, parent);
    30473063
    3048             if (TREEVIEW_IsChildOf(parent, infoPtr->firstVisible))
    3049             {
    3050                 TREEVIEW_ITEM *item;
    3051 
    3052                 for (item = infoPtr->root->firstChild; item != NULL;
    3053                      item = TREEVIEW_GetNextListItem(infoPtr, item))
    3054                 {
    3055                     if (item->visibleOrder == visOrder)
    3056                         break;
    3057                 }
     3064        if (TREEVIEW_IsChildOf(parent, infoPtr->firstVisible))
     3065        {
     3066            TREEVIEW_ITEM *item;
     3067
     3068            for (item = infoPtr->root->firstChild; item != NULL;
     3069                 item = TREEVIEW_GetNextListItem(infoPtr, item))
     3070            {
     3071                if (item->visibleOrder == visOrder)
     3072                    break;
     3073            }
    30583074
    30593075                TREEVIEW_SetFirstVisible(infoPtr, item, FALSE);
    3060             }
    3061 
    3062             TREEVIEW_Invalidate(infoPtr, NULL);
    3063         }
    3064 
    3065         return TRUE;
     3076        }
     3077
     3078        TREEVIEW_Invalidate(infoPtr, NULL);
     3079    }
     3080
     3081    return TRUE;
    30663082    }
    30673083    return FALSE;
     
    30943110static BOOL
    30953111TREEVIEW_SendExpanding(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem,
    3096                        UINT action)
     3112               UINT action)
    30973113{
    30983114    return !TREEVIEW_SendTreeviewNotify(infoPtr, TVN_ITEMEXPANDINGW, action,
    3099                                         TVIF_HANDLE | TVIF_STATE | TVIF_PARAM
    3100                                         | TVIF_IMAGE | TVIF_SELECTEDIMAGE,
    3101                                         0, wineItem);
     3115                    TVIF_HANDLE | TVIF_STATE | TVIF_PARAM
     3116                    | TVIF_IMAGE | TVIF_SELECTEDIMAGE,
     3117                    0, wineItem);
    31023118}
    31033119
    31043120static VOID
    31053121TREEVIEW_SendExpanded(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem,
    3106                       UINT action)
     3122              UINT action)
    31073123{
    31083124    TREEVIEW_SendTreeviewNotify(infoPtr, TVN_ITEMEXPANDEDW, action,
    3109                                 TVIF_HANDLE | TVIF_STATE | TVIF_PARAM
    3110                                 | TVIF_IMAGE | TVIF_SELECTEDIMAGE,
    3111                                 0, wineItem);
     3125                TVIF_HANDLE | TVIF_STATE | TVIF_PARAM
     3126                | TVIF_IMAGE | TVIF_SELECTEDIMAGE,
     3127                0, wineItem);
    31123128}
    31133129
     
    31173133static BOOL
    31183134TREEVIEW_Collapse(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem,
    3119                   BOOL bRemoveChildren, BOOL bUser)
     3135          BOOL bRemoveChildren, BOOL bUser)
    31203136{
    31213137    UINT action = TVE_COLLAPSE | (bRemoveChildren ? TVE_COLLAPSERESET : 0);
     
    31253141
    31263142    if (!(wineItem->state & TVIS_EXPANDED) || wineItem->firstChild == NULL)
    3127         return FALSE;
     3143    return FALSE;
    31283144
    31293145    if (bUser)
    3130         TREEVIEW_SendExpanding(infoPtr, wineItem, action);
     3146    TREEVIEW_SendExpanding(infoPtr, wineItem, action);
    31313147
    31323148    wineItem->state &= ~TVIS_EXPANDED;
    31333149
    31343150    if (bUser)
    3135         TREEVIEW_SendExpanded(infoPtr, wineItem, action);
     3151    TREEVIEW_SendExpanded(infoPtr, wineItem, action);
    31363152
    31373153    bSetSelection = (infoPtr->selectedItem != NULL
    3138                      && TREEVIEW_IsChildOf(wineItem, infoPtr->selectedItem));
     3154             && TREEVIEW_IsChildOf(wineItem, infoPtr->selectedItem));
    31393155
    31403156    bSetFirstVisible = (infoPtr->firstVisible != NULL
     
    31433159    if (bRemoveChildren)
    31443160    {
    3145         TRACE("TVE_COLLAPSERESET\n");
    3146         wineItem->state &= ~TVIS_EXPANDEDONCE;
    3147         TREEVIEW_RemoveAllChildren(infoPtr, wineItem);
     3161    TRACE("TVE_COLLAPSERESET\n");
     3162    wineItem->state &= ~TVIS_EXPANDEDONCE;
     3163    TREEVIEW_RemoveAllChildren(infoPtr, wineItem);
    31483164    }
    31493165
     
    31523168        TREEVIEW_ITEM *item, *sibling;
    31533169
    3154         sibling = TREEVIEW_GetNextListItem(infoPtr, wineItem);
    3155 
    3156         for (item = wineItem->firstChild; item != sibling;
    3157              item = TREEVIEW_GetNextListItem(infoPtr, item))
    3158         {
    3159             item->visibleOrder = -1;
    3160         }
     3170    sibling = TREEVIEW_GetNextListItem(infoPtr, wineItem);
     3171
     3172    for (item = wineItem->firstChild; item != sibling;
     3173         item = TREEVIEW_GetNextListItem(infoPtr, item))
     3174    {
     3175        item->visibleOrder = -1;
     3176    }
    31613177    }
    31623178
     
    31643180
    31653181    TREEVIEW_SetFirstVisible(infoPtr, bSetFirstVisible ? wineItem
    3166                              : infoPtr->firstVisible, TRUE);
     3182                 : infoPtr->firstVisible, TRUE);
    31673183
    31683184    if (bSetSelection)
    31693185    {
    3170         /* Don't call DoSelectItem, it sends notifications. */
    3171         if (TREEVIEW_ValidItem(infoPtr, infoPtr->selectedItem))
    3172             infoPtr->selectedItem->state &= ~TVIS_SELECTED;
    3173         wineItem->state |= TVIS_SELECTED;
    3174         infoPtr->selectedItem = wineItem;
    3175 
    3176         TREEVIEW_EnsureVisible(infoPtr, wineItem, FALSE);
     3186    /* Don't call DoSelectItem, it sends notifications. */
     3187    if (TREEVIEW_ValidItem(infoPtr, infoPtr->selectedItem))
     3188        infoPtr->selectedItem->state &= ~TVIS_SELECTED;
     3189    wineItem->state |= TVIS_SELECTED;
     3190    infoPtr->selectedItem = wineItem;
     3191
     3192    TREEVIEW_EnsureVisible(infoPtr, wineItem, FALSE);
    31773193    }
    31783194
     
    31853201static BOOL
    31863202TREEVIEW_Expand(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem,
    3187                 BOOL bExpandPartial, BOOL bUser)
     3203        BOOL bExpandPartial, BOOL bUser)
    31883204{
    31893205    TRACE("\n");
    31903206
    31913207    if (!TREEVIEW_HasChildren(infoPtr, wineItem)
    3192         || wineItem->state & TVIS_EXPANDED)
    3193         return FALSE;
     3208    || wineItem->state & TVIS_EXPANDED)
     3209    return FALSE;
    31943210
    31953211    TRACE("TVE_EXPAND %p %s\n", wineItem, TREEVIEW_ItemName(wineItem));
     
    31973213    if (bUser || !(wineItem->state & TVIS_EXPANDEDONCE))
    31983214    {
    3199         if (!TREEVIEW_SendExpanding(infoPtr, wineItem, TVE_EXPAND))
    3200         {
    3201             TRACE("  TVN_ITEMEXPANDING returned TRUE, exiting...\n");
    3202             return FALSE;
    3203         }
    3204 
    3205         wineItem->state |= TVIS_EXPANDED;
    3206         TREEVIEW_SendExpanded(infoPtr, wineItem, TVE_EXPAND);
    3207         wineItem->state |= TVIS_EXPANDEDONCE;
     3215    if (!TREEVIEW_SendExpanding(infoPtr, wineItem, TVE_EXPAND))
     3216    {
     3217        TRACE("  TVN_ITEMEXPANDING returned TRUE, exiting...\n");
     3218        return FALSE;
     3219    }
     3220
     3221    wineItem->state |= TVIS_EXPANDED;
     3222    TREEVIEW_SendExpanded(infoPtr, wineItem, TVE_EXPAND);
     3223    wineItem->state |= TVIS_EXPANDEDONCE;
    32083224    }
    32093225    else
    32103226    {
    3211         /* this item has already been expanded */
    3212         wineItem->state |= TVIS_EXPANDED;
     3227    /* this item has already been expanded */
     3228    wineItem->state |= TVIS_EXPANDED;
    32133229    }
    32143230
    32153231    if (bExpandPartial)
    3216         FIXME("TVE_EXPANDPARTIAL not implemented\n");
     3232    FIXME("TVE_EXPANDPARTIAL not implemented\n");
    32173233
    32183234    TREEVIEW_RecalculateVisibleOrder(infoPtr, wineItem);
     
    32253241    if (wineItem->firstChild != NULL)
    32263242    {
    3227         int nChildren = wineItem->lastChild->visibleOrder
    3228             - wineItem->firstChild->visibleOrder + 1;
    3229 
    3230         int visible_pos = wineItem->visibleOrder
    3231             - infoPtr->firstVisible->visibleOrder;
    3232 
    3233         int rows_below = TREEVIEW_GetVisibleCount(infoPtr) - visible_pos - 1;
    3234 
    3235         if (visible_pos > 0 && nChildren > rows_below)
    3236         {
    3237             int scroll = nChildren - rows_below;
    3238 
    3239             if (scroll > visible_pos)
    3240                 scroll = visible_pos;
    3241 
    3242             if (scroll > 0)
    3243             {
    3244                 TREEVIEW_ITEM *newFirstVisible
    3245                     = TREEVIEW_GetListItem(infoPtr, infoPtr->firstVisible,
    3246                                            scroll);
    3247 
    3248 
    3249                 TREEVIEW_SetFirstVisible(infoPtr, newFirstVisible, TRUE);
    3250             }
    3251         }
     3243    int nChildren = wineItem->lastChild->visibleOrder
     3244        - wineItem->firstChild->visibleOrder + 1;
     3245
     3246    int visible_pos = wineItem->visibleOrder
     3247        - infoPtr->firstVisible->visibleOrder;
     3248
     3249    int rows_below = TREEVIEW_GetVisibleCount(infoPtr) - visible_pos - 1;
     3250
     3251    if (visible_pos > 0 && nChildren > rows_below)
     3252    {
     3253        int scroll = nChildren - rows_below;
     3254
     3255        if (scroll > visible_pos)
     3256        scroll = visible_pos;
     3257
     3258        if (scroll > 0)
     3259        {
     3260        TREEVIEW_ITEM *newFirstVisible
     3261            = TREEVIEW_GetListItem(infoPtr, infoPtr->firstVisible,
     3262                       scroll);
     3263
     3264
     3265        TREEVIEW_SetFirstVisible(infoPtr, newFirstVisible, TRUE);
     3266        }
     3267    }
    32523268    }
    32533269
     
    32633279
    32643280    if (wineItem->state & TVIS_EXPANDED)
    3265         return TREEVIEW_Collapse(infoPtr, wineItem, FALSE, bUser);
     3281    return TREEVIEW_Collapse(infoPtr, wineItem, FALSE, bUser);
    32663282    else
    3267         return TREEVIEW_Expand(infoPtr, wineItem, FALSE, bUser);
     3283    return TREEVIEW_Expand(infoPtr, wineItem, FALSE, bUser);
    32683284}
    32693285
     
    32753291    for (item = item->firstChild; item != NULL; item = item->nextSibling)
    32763292    {
    3277         if (TREEVIEW_HasChildren(infoPtr, item))
    3278             TREEVIEW_ExpandAll(infoPtr, item);
     3293    if (TREEVIEW_HasChildren(infoPtr, item))
     3294        TREEVIEW_ExpandAll(infoPtr, item);
    32793295    }
    32803296}
     
    32903306{
    32913307    if (!TREEVIEW_ValidItem(infoPtr, wineItem))
    3292         return 0;
     3308    return 0;
    32933309
    32943310    TRACE("For (%s) item:%d, flags %x, state:%d\n",
    3295               TREEVIEW_ItemName(wineItem), flag,
    3296               TREEVIEW_GetItemIndex(infoPtr, wineItem), wineItem->state);
     3311          TREEVIEW_ItemName(wineItem), flag,
     3312          TREEVIEW_GetItemIndex(infoPtr, wineItem), wineItem->state);
    32973313
    32983314    switch (flag & TVE_TOGGLE)
    32993315    {
    33003316    case TVE_COLLAPSE:
    3301         return TREEVIEW_Collapse(infoPtr, wineItem, flag & TVE_COLLAPSERESET,
    3302                                 FALSE);
     3317    return TREEVIEW_Collapse(infoPtr, wineItem, flag & TVE_COLLAPSERESET,
     3318                FALSE);
    33033319
    33043320    case TVE_EXPAND:
    3305         return TREEVIEW_Expand(infoPtr, wineItem, flag & TVE_EXPANDPARTIAL,
    3306                                FALSE);
     3321    return TREEVIEW_Expand(infoPtr, wineItem, flag & TVE_EXPANDPARTIAL,
     3322                   FALSE);
    33073323
    33083324    case TVE_TOGGLE:
    3309         return TREEVIEW_Toggle(infoPtr, wineItem, TRUE);
     3325    return TREEVIEW_Toggle(infoPtr, wineItem, TRUE);
    33103326
    33113327    default:
    3312         return 0;
     3328    return 0;
    33133329    }
    33143330
     
    33273343
    33283344    if (!infoPtr->firstVisible)
    3329         return NULL;
     3345    return NULL;
    33303346
    33313347    row = pt.y / infoPtr->uItemHeight + infoPtr->firstVisible->visibleOrder;
    33323348
    33333349    for (wineItem = infoPtr->firstVisible; wineItem != NULL;
    3334         wineItem = TREEVIEW_GetNextListItem(infoPtr, wineItem))
    3335     {
    3336         if (row >= wineItem->visibleOrder
    3337             && row < wineItem->visibleOrder + wineItem->iIntegral)
    3338             break;
     3350    wineItem = TREEVIEW_GetNextListItem(infoPtr, wineItem))
     3351    {
     3352    if (row >= wineItem->visibleOrder
     3353        && row < wineItem->visibleOrder + wineItem->iIntegral)
     3354        break;
    33393355    }
    33403356
     
    33583374    if (x < rect.left)
    33593375    {
    3360         status |= TVHT_TOLEFT;
     3376    status |= TVHT_TOLEFT;
    33613377    }
    33623378    else if (x > rect.right)
    33633379    {
    3364         status |= TVHT_TORIGHT;
     3380    status |= TVHT_TORIGHT;
    33653381    }
    33663382
    33673383    if (y < rect.top)
    33683384    {
    3369         status |= TVHT_ABOVE;
     3385    status |= TVHT_ABOVE;
    33703386    }
    33713387    else if (y > rect.bottom)
    33723388    {
    3373         status |= TVHT_BELOW;
     3389    status |= TVHT_BELOW;
    33743390    }
    33753391
    33763392    if (status)
    33773393    {
    3378         lpht->flags = status;
    3379         return (LRESULT)(HTREEITEM)NULL;
     3394    lpht->flags = status;
     3395    return (LRESULT)(HTREEITEM)NULL;
    33803396    }
    33813397
     
    33833399    if (!wineItem)
    33843400    {
    3385         lpht->flags = TVHT_NOWHERE;
    3386         return (LRESULT)(HTREEITEM)NULL;
     3401    lpht->flags = TVHT_NOWHERE;
     3402    return (LRESULT)(HTREEITEM)NULL;
    33873403    }
    33883404
    33893405    if (x >= wineItem->textOffset + wineItem->textWidth)
    33903406    {
    3391         lpht->flags = TVHT_ONITEMRIGHT;
     3407    lpht->flags = TVHT_ONITEMRIGHT;
    33923408    }
    33933409    else if (x >= wineItem->textOffset)
    33943410    {
    3395         lpht->flags = TVHT_ONITEMLABEL;
     3411    lpht->flags = TVHT_ONITEMLABEL;
    33963412    }
    33973413    else if (x >= wineItem->imageOffset)
    33983414    {
    3399         lpht->flags = TVHT_ONITEMICON;
     3415    lpht->flags = TVHT_ONITEMICON;
    34003416    }
    34013417    else if (x >= wineItem->stateOffset)
    34023418    {
    3403         lpht->flags = TVHT_ONITEMSTATEICON;
     3419    lpht->flags = TVHT_ONITEMSTATEICON;
    34043420    }
    34053421    else if (x >= wineItem->linesOffset && infoPtr->dwStyle & TVS_HASBUTTONS)
    34063422    {
    3407         lpht->flags = TVHT_ONITEMBUTTON;
     3423    lpht->flags = TVHT_ONITEMBUTTON;
    34083424    }
    34093425    else
    34103426    {
    3411         lpht->flags = TVHT_ONITEMINDENT;
     3427    lpht->flags = TVHT_ONITEMINDENT;
    34123428    }
    34133429
     
    34353451    {
    34363452    case WM_PAINT:
    3437         {
    3438             LRESULT rc;
    3439             TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(GetParent(hwnd));
    3440 
    3441             TRACE("WM_PAINT start\n");
    3442             rc = CallWindowProcA(infoPtr->wpEditOrig, hwnd, uMsg, wParam,
    3443                                 lParam);
    3444             TRACE("WM_PAINT done\n");
    3445             return rc;
    3446         }
     3453    {
     3454        LRESULT rc;
     3455        TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(GetParent(hwnd));
     3456
     3457        TRACE("WM_PAINT start\n");
     3458        rc = CallWindowProcA(infoPtr->wpEditOrig, hwnd, uMsg, wParam,
     3459                lParam);
     3460        TRACE("WM_PAINT done\n");
     3461        return rc;
     3462    }
    34473463
    34483464    case WM_KILLFOCUS:
    34493465    {
    3450         TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(GetParent(hwnd));
    3451         if (infoPtr->bIgnoreEditKillFocus)
    3452             return TRUE;
    3453 
    3454         break;
     3466    TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(GetParent(hwnd));
     3467    if (infoPtr->bIgnoreEditKillFocus)
     3468        return TRUE;
     3469
     3470    break;
    34553471    }
    34563472
    34573473    case WM_GETDLGCODE:
    3458         return DLGC_WANTARROWS | DLGC_WANTALLKEYS;
     3474    return DLGC_WANTARROWS | DLGC_WANTALLKEYS;
    34593475
    34603476    case WM_KEYDOWN:
    3461         if (wParam == (WPARAM)VK_ESCAPE)
    3462         {
    3463             bCancel = TRUE;
    3464             break;
    3465         }
    3466         else if (wParam == (WPARAM)VK_RETURN)
    3467         {
    3468             break;
    3469         }
    3470 
    3471         /* fall through */
     3477    if (wParam == (WPARAM)VK_ESCAPE)
     3478    {
     3479        bCancel = TRUE;
     3480        break;
     3481    }
     3482    else if (wParam == (WPARAM)VK_RETURN)
     3483    {
     3484        break;
     3485    }
     3486
     3487    /* fall through */
    34723488    default:
    3473         {
    3474             TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(GetParent(hwnd));
    3475 
    3476             return CallWindowProcA(infoPtr->wpEditOrig, hwnd, uMsg, wParam,
    3477                                    lParam);
    3478         }
     3489    {
     3490        TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(GetParent(hwnd));
     3491
     3492        return CallWindowProcA(infoPtr->wpEditOrig, hwnd, uMsg, wParam,
     3493                   lParam);
     3494    }
    34793495    }
    34803496
     
    35013517    {
    35023518    case EN_UPDATE:
    3503         {
    3504             /*
    3505              * Adjust the edit window size
    3506              */
    3507             char buffer[1024];
    3508             TREEVIEW_ITEM *editItem = infoPtr->selectedItem;
    3509             HDC hdc = GetDC(infoPtr->hwndEdit);
    3510             SIZE sz;
    3511             int len;
    3512             HFONT hFont, hOldFont = 0;
    3513 
    3514             infoPtr->bLabelChanged = TRUE;
    3515 
    3516             len = GetWindowTextA(infoPtr->hwndEdit, buffer, sizeof(buffer));
    3517 
    3518             /* Select font to get the right dimension of the string */
    3519             hFont = (HFONT)SendMessageA(infoPtr->hwndEdit, WM_GETFONT, 0, 0);
    3520             if (hFont != 0)
    3521             {
    3522                 hOldFont = SelectObject(hdc, hFont);
    3523             }
    3524 
    3525             if (GetTextExtentPoint32A(hdc, buffer, strlen(buffer), &sz))
    3526             {
    3527                 TEXTMETRICA textMetric;
    3528 
    3529                 /* Add Extra spacing for the next character */
    3530                 GetTextMetricsA(hdc, &textMetric);
    3531                 sz.cx += (textMetric.tmMaxCharWidth * 2);
    3532 
    3533                 sz.cx = max(sz.cx, textMetric.tmMaxCharWidth * 3);
    3534                 sz.cx = min(sz.cx,
    3535                             infoPtr->clientWidth - editItem->textOffset + 2);
    3536 
    3537                 SetWindowPos(infoPtr->hwndEdit,
    3538                              HWND_TOP,
    3539                              0,
    3540                              0,
    3541                              sz.cx,
    3542                              editItem->rect.bottom - editItem->rect.top + 3,
    3543                              SWP_NOMOVE | SWP_DRAWFRAME);
    3544             }
    3545 
    3546             if (hFont != 0)
    3547             {
    3548                 SelectObject(hdc, hOldFont);
    3549             }
    3550 
    3551             ReleaseDC(infoPtr->hwnd, hdc);
    3552             break;
    3553         }
     3519    {
     3520        /*
     3521         * Adjust the edit window size
     3522         */
     3523        char buffer[1024];
     3524        TREEVIEW_ITEM *editItem = infoPtr->selectedItem;
     3525        HDC hdc = GetDC(infoPtr->hwndEdit);
     3526        SIZE sz;
     3527        int len;
     3528        HFONT hFont, hOldFont = 0;
     3529
     3530        infoPtr->bLabelChanged = TRUE;
     3531
     3532        len = GetWindowTextA(infoPtr->hwndEdit, buffer, sizeof(buffer));
     3533
     3534        /* Select font to get the right dimension of the string */
     3535        hFont = (HFONT)SendMessageA(infoPtr->hwndEdit, WM_GETFONT, 0, 0);
     3536        if (hFont != 0)
     3537        {
     3538        hOldFont = SelectObject(hdc, hFont);
     3539        }
     3540
     3541        if (GetTextExtentPoint32A(hdc, buffer, strlen(buffer), &sz))
     3542        {
     3543        TEXTMETRICA textMetric;
     3544
     3545        /* Add Extra spacing for the next character */
     3546        GetTextMetricsA(hdc, &textMetric);
     3547        sz.cx += (textMetric.tmMaxCharWidth * 2);
     3548
     3549        sz.cx = max(sz.cx, textMetric.tmMaxCharWidth * 3);
     3550        sz.cx = min(sz.cx,
     3551                infoPtr->clientWidth - editItem->textOffset + 2);
     3552
     3553        SetWindowPos(infoPtr->hwndEdit,
     3554                 HWND_TOP,
     3555                 0,
     3556                 0,
     3557                 sz.cx,
     3558                 editItem->rect.bottom - editItem->rect.top + 3,
     3559                 SWP_NOMOVE | SWP_DRAWFRAME);
     3560        }
     3561
     3562        if (hFont != 0)
     3563        {
     3564        SelectObject(hdc, hOldFont);
     3565        }
     3566
     3567        ReleaseDC(infoPtr->hwnd, hdc);
     3568        break;
     3569    }
    35543570
    35553571    default:
    3556         return SendMessageA(GetParent(infoPtr->hwnd), WM_COMMAND, wParam, lParam);
     3572    return SendMessageA(GetParent(infoPtr->hwnd), WM_COMMAND, wParam, lParam);
    35573573    }
    35583574
     
    35743590    TRACE("%x %p\n", (unsigned)hwnd, hItem);
    35753591    if (!TREEVIEW_ValidItem(infoPtr, editItem))
    3576         return NULL;
     3592    return NULL;
    35773593
    35783594    if (infoPtr->hwndEdit)
    3579         return infoPtr->hwndEdit;
     3595    return infoPtr->hwndEdit;
    35803596
    35813597    infoPtr->bLabelChanged = FALSE;
     
    35913607    if (infoPtr->hFont != 0)
    35923608    {
    3593         hOldFont = SelectObject(hdc, infoPtr->hFont);
     3609    hOldFont = SelectObject(hdc, infoPtr->hFont);
    35943610    }
    35953611
    35963612    /* Get string length in pixels */
    35973613    GetTextExtentPoint32A(hdc, editItem->pszText, strlen(editItem->pszText),
    3598                           &sz);
     3614              &sz);
    35993615
    36003616    /* Add Extra spacing for the next character */
     
    36073623    if (infoPtr->hFont != 0)
    36083624    {
    3609         SelectObject(hdc, hOldFont);
     3625    SelectObject(hdc, hOldFont);
    36103626    }
    36113627
    36123628    ReleaseDC(hwnd, hdc);
    36133629    hwndEdit = CreateWindowExA(WS_EX_LEFT,
    3614                                "EDIT",
    3615                                0,
    3616                                WS_CHILD | WS_BORDER | ES_AUTOHSCROLL |
    3617                                WS_CLIPSIBLINGS | ES_WANTRETURN |
    3618                                ES_LEFT, editItem->textOffset - 2,
    3619                                editItem->rect.top - 1, sz.cx + 3,
    3620                                editItem->rect.bottom -
    3621                                editItem->rect.top + 3, hwnd, 0, hinst, 0);
     3630                   "EDIT",
     3631                   0,
     3632                   WS_CHILD | WS_BORDER | ES_AUTOHSCROLL |
     3633                   WS_CLIPSIBLINGS | ES_WANTRETURN |
     3634                   ES_LEFT, editItem->textOffset - 2,
     3635                   editItem->rect.top - 1, sz.cx + 3,
     3636                   editItem->rect.bottom -
     3637                   editItem->rect.top + 3, hwnd, 0, hinst, 0);
    36223638/* FIXME: (HMENU)IDTVEDIT,pcs->hInstance,0); */
    36233639
     
    36263642    /* Get a 2D border. */
    36273643    SetWindowLongA(hwndEdit, GWL_EXSTYLE,
    3628                    GetWindowLongA(hwndEdit, GWL_EXSTYLE) & ~WS_EX_CLIENTEDGE);
     3644           GetWindowLongA(hwndEdit, GWL_EXSTYLE) & ~WS_EX_CLIENTEDGE);
    36293645    SetWindowLongA(hwndEdit, GWL_STYLE,
    3630                    GetWindowLongA(hwndEdit, GWL_STYLE) | WS_BORDER);
     3646           GetWindowLongA(hwndEdit, GWL_STYLE) | WS_BORDER);
    36313647
    36323648    SendMessageA(hwndEdit, WM_SETFONT,
    3633                 (WPARAM)TREEVIEW_FontForItem(infoPtr, editItem), FALSE);
     3649        (WPARAM)TREEVIEW_FontForItem(infoPtr, editItem), FALSE);
    36343650
    36353651    infoPtr->wpEditOrig = (WNDPROC)SetWindowLongA(hwndEdit, GWL_WNDPROC,
    3636                                                   (DWORD)
    3637                                                   TREEVIEW_Edit_SubclassProc);
     3652                          (DWORD)
     3653                          TREEVIEW_Edit_SubclassProc);
    36383654
    36393655    if (TREEVIEW_BeginLabelEditNotify(infoPtr, editItem))
    36403656    {
    3641         DestroyWindow(hwndEdit);
    3642         infoPtr->hwndEdit = 0;
    3643         return NULL;
     3657    DestroyWindow(hwndEdit);
     3658    infoPtr->hwndEdit = 0;
     3659    return NULL;
    36443660    }
    36453661
     
    36653681
    36663682    if (!infoPtr->hwndEdit)
    3667         return FALSE;
     3683    return FALSE;
    36683684
    36693685    tvdi.hdr.hwndFrom = hwnd;
     
    36773693    if (!bCancel)
    36783694    {
    3679         iLength = GetWindowTextA(infoPtr->hwndEdit, tmpText, 1023);
    3680 
    3681         if (iLength >= 1023)
    3682         {
    3683             ERR("Insufficient space to retrieve new item label\n");
    3684         }
    3685 
    3686         tvdi.item.pszText = tmpText;
    3687         tvdi.item.cchTextMax = iLength + 1;
     3695    iLength = GetWindowTextA(infoPtr->hwndEdit, tmpText, 1023);
     3696
     3697    if (iLength >= 1023)
     3698    {
     3699        ERR("Insufficient space to retrieve new item label\n");
     3700    }
     3701
     3702    tvdi.item.pszText = tmpText;
     3703    tvdi.item.cchTextMax = iLength + 1;
    36883704    }
    36893705    else
    36903706    {
    3691         tvdi.item.pszText = NULL;
    3692         tvdi.item.cchTextMax = 0;
     3707    tvdi.item.pszText = NULL;
     3708    tvdi.item.cchTextMax = 0;
    36933709    }
    36943710
    36953711    bCommit = (BOOL)TREEVIEW_SendRealNotify(infoPtr,
    3696                                 (WPARAM)tvdi.hdr.idFrom, (LPARAM)&tvdi);
    3697 
    3698     if (!bCancel && bCommit)    /* Apply the changes */
    3699     {
    3700         if (strcmp(tmpText, editedItem->pszText) != 0)
    3701         {
    3702             if (NULL == COMCTL32_ReAlloc(editedItem->pszText, iLength + 1))
    3703             {
    3704                 ERR("OutOfMemory, cannot allocate space for label\n");
    3705                 DestroyWindow(infoPtr->hwndEdit);
    3706                 infoPtr->hwndEdit = 0;
    3707                 return FALSE;
    3708             }
    3709             else
    3710             {
    3711                 editedItem->cchTextMax = iLength + 1;
    3712                 lstrcpyA(editedItem->pszText, tmpText);
    3713             }
    3714         }
     3712                (WPARAM)tvdi.hdr.idFrom, (LPARAM)&tvdi);
     3713
     3714    if (!bCancel && bCommit)    /* Apply the changes */
     3715    {
     3716    if (strcmp(tmpText, editedItem->pszText) != 0)
     3717    {
     3718        if (NULL == COMCTL32_ReAlloc(editedItem->pszText, iLength + 1))
     3719        {
     3720        ERR("OutOfMemory, cannot allocate space for label\n");
     3721        DestroyWindow(infoPtr->hwndEdit);
     3722        infoPtr->hwndEdit = 0;
     3723        return FALSE;
     3724        }
     3725        else
     3726        {
     3727        editedItem->cchTextMax = iLength + 1;
     3728        lstrcpyA(editedItem->pszText, tmpText);
     3729        }
     3730    }
    37153731    }
    37163732
     
    37263742    if (wParam != TV_EDIT_TIMER)
    37273743    {
    3728         ERR("got unknown timer\n");
    3729         return 1;
     3744    ERR("got unknown timer\n");
     3745    return 1;
    37303746    }
    37313747
     
    37623778    while (1)
    37633779    {
    3764         if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_NOYIELD))
    3765         {
    3766             if (msg.message == WM_MOUSEMOVE)
    3767             {
    3768                 pt.x = SLOWORD(msg.lParam);
    3769                 pt.y = SHIWORD(msg.lParam);
    3770                 if (PtInRect(&r, pt))
    3771                     continue;
    3772                 else
    3773                 {
    3774                     ReleaseCapture();
    3775                     return 1;
    3776                 }
    3777             }
    3778             else if (msg.message >= WM_LBUTTONDOWN &&
    3779                      msg.message <= WM_RBUTTONDBLCLK)
    3780             {
    3781                 if (msg.message == WM_RBUTTONUP)
    3782                     TREEVIEW_RButtonUp(infoPtr, &pt);
    3783                 break;
    3784             }
    3785 
    3786             DispatchMessageA(&msg);
    3787         }
    3788 
    3789         if (GetCapture() != infoPtr->hwnd)
    3790             return 0;
     3780    if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_NOYIELD))
     3781    {
     3782        if (msg.message == WM_MOUSEMOVE)
     3783        {
     3784        pt.x = SLOWORD(msg.lParam);
     3785        pt.y = SHIWORD(msg.lParam);
     3786        if (PtInRect(&r, pt))
     3787            continue;
     3788        else
     3789        {
     3790            ReleaseCapture();
     3791            return 1;
     3792        }
     3793        }
     3794        else if (msg.message >= WM_LBUTTONDOWN &&
     3795             msg.message <= WM_RBUTTONDBLCLK)
     3796        {
     3797        if (msg.message == WM_RBUTTONUP)
     3798            TREEVIEW_RButtonUp(infoPtr, &pt);
     3799        break;
     3800        }
     3801
     3802        DispatchMessageA(&msg);
     3803    }
     3804
     3805    if (GetCapture() != infoPtr->hwnd)
     3806        return 0;
    37913807    }
    37923808
     
    38073823    if (infoPtr->Timer & TV_EDIT_TIMER_SET)
    38083824    {
    3809         /* If there is pending 'edit label' event - kill it now */
    3810         KillTimer(infoPtr->hwnd, TV_EDIT_TIMER);
     3825    /* If there is pending 'edit label' event - kill it now */
     3826    KillTimer(infoPtr->hwnd, TV_EDIT_TIMER);
    38113827    }
    38123828
     
    38163832    wineItem = (TREEVIEW_ITEM *)TREEVIEW_HitTest(infoPtr, &hit);
    38173833    if (!wineItem)
    3818         return 0;
     3834    return 0;
    38193835    TRACE("item %d\n", TREEVIEW_GetItemIndex(infoPtr, wineItem));
    38203836
    38213837    if (TREEVIEW_SendSimpleNotify(infoPtr, NM_DBLCLK) == FALSE)
    3822     {                           /* FIXME! */
    3823         switch (hit.flags)
    3824         {
    3825         case TVHT_ONITEMRIGHT:
    3826             /* FIXME: we should not have sent NM_DBLCLK in this case. */
    3827             break;
    3828 
    3829         case TVHT_ONITEMINDENT:
    3830             if (!(infoPtr->dwStyle & TVS_HASLINES))
    3831             {
    3832                 break;
    3833             }
    3834             else
    3835             {
    3836                 int level = hit.pt.x / infoPtr->uIndent;
    3837                 if (!(infoPtr->dwStyle & TVS_LINESATROOT)) level++;
    3838 
    3839                 while (wineItem->iLevel > level)
    3840                 {
    3841                     wineItem = wineItem->parent;
    3842                 }
    3843 
    3844                 /* fall through */
    3845             }
    3846 
    3847         case TVHT_ONITEMLABEL:
    3848         case TVHT_ONITEMICON:
    3849         case TVHT_ONITEMBUTTON:
    3850             TREEVIEW_Toggle(infoPtr, wineItem, TRUE);
    3851             break;
    3852 
    3853         case TVHT_ONITEMSTATEICON:
    3854            if (infoPtr->dwStyle & TVS_CHECKBOXES)
    3855                TREEVIEW_ToggleItemState(infoPtr, wineItem);
    3856            else
    3857                TREEVIEW_Toggle(infoPtr, wineItem, TRUE);
    3858            break;
    3859         }
     3838    {               /* FIXME! */
     3839    switch (hit.flags)
     3840    {
     3841    case TVHT_ONITEMRIGHT:
     3842        /* FIXME: we should not have sent NM_DBLCLK in this case. */
     3843        break;
     3844
     3845    case TVHT_ONITEMINDENT:
     3846        if (!(infoPtr->dwStyle & TVS_HASLINES))
     3847        {
     3848        break;
     3849        }
     3850        else
     3851        {
     3852        int level = hit.pt.x / infoPtr->uIndent;
     3853        if (!(infoPtr->dwStyle & TVS_LINESATROOT)) level++;
     3854
     3855        while (wineItem->iLevel > level)
     3856        {
     3857            wineItem = wineItem->parent;
     3858        }
     3859
     3860        /* fall through */
     3861        }
     3862
     3863    case TVHT_ONITEMLABEL:
     3864    case TVHT_ONITEMICON:
     3865    case TVHT_ONITEMBUTTON:
     3866        TREEVIEW_Toggle(infoPtr, wineItem, TRUE);
     3867        break;
     3868
     3869    case TVHT_ONITEMSTATEICON:
     3870       if (infoPtr->dwStyle & TVS_CHECKBOXES)
     3871           TREEVIEW_ToggleItemState(infoPtr, wineItem);
     3872       else
     3873           TREEVIEW_Toggle(infoPtr, wineItem, TRUE);
     3874       break;
     3875    }
    38603876    }
    38613877    return TRUE;
     
    38783894    if (infoPtr->hwndEdit)
    38793895    {
    3880         SetFocus(hwnd);
    3881         return 0;
     3896    SetFocus(hwnd);
     3897    return 0;
    38823898    }
    38833899
     
    38993915
    39003916    bTrack = (ht.flags & TVHT_ONITEM)
    3901         && !(infoPtr->dwStyle & TVS_DISABLEDRAGDROP);
     3917    && !(infoPtr->dwStyle & TVS_DISABLEDRAGDROP);
    39023918
    39033919    /* Send NM_CLICK right away */
    39043920    if (!bTrack)
    3905         if (TREEVIEW_SendSimpleNotify(infoPtr, NM_CLICK))
    3906             goto setfocus;
     3921    if (TREEVIEW_SendSimpleNotify(infoPtr, NM_CLICK))
     3922        goto setfocus;
    39073923
    39083924    if (ht.flags & TVHT_ONITEMBUTTON)
    39093925    {
    3910         TREEVIEW_Toggle(infoPtr, ht.hItem, TRUE);
    3911         goto setfocus;
     3926    TREEVIEW_Toggle(infoPtr, ht.hItem, TRUE);
     3927    goto setfocus;
    39123928    }
    39133929    else if (bTrack)
    39143930    {   /* if TREEVIEW_TrackMouse == 1 dragging occurred and the cursor left the dragged item's rectangle */
    3915         if (TREEVIEW_TrackMouse(infoPtr, ht.pt))
    3916         {
    3917             TREEVIEW_SendTreeviewDnDNotify(infoPtr, TVN_BEGINDRAGW, ht.hItem, ht.pt);
    3918             infoPtr->dropItem = ht.hItem;
     3931    if (TREEVIEW_TrackMouse(infoPtr, ht.pt))
     3932    {
     3933        TREEVIEW_SendTreeviewDnDNotify(infoPtr, TVN_BEGINDRAGW, ht.hItem, ht.pt);
     3934        infoPtr->dropItem = ht.hItem;
    39193935
    39203936            /* clean up focusedItem as we dragged and won't select this item */
     
    39303946            }
    39313947
    3932             return 0;
     3948        return 0;
    39333949        }
    39343950    }
     
    39423958     */
    39433959    if ((infoPtr->dwStyle & TVS_EDITLABELS) &&
    3944                 (ht.flags & TVHT_ONITEMLABEL) && (infoPtr->selectedItem == ht.hItem))
    3945     {
    3946         if (infoPtr->Timer & TV_EDIT_TIMER_SET)
    3947             KillTimer(hwnd, TV_EDIT_TIMER);
    3948 
    3949         SetTimer(hwnd, TV_EDIT_TIMER, GetDoubleClickTime(), 0);
    3950         infoPtr->Timer |= TV_EDIT_TIMER_SET;
     3960            (ht.flags & TVHT_ONITEMLABEL) && (infoPtr->selectedItem == ht.hItem))
     3961    {
     3962    if (infoPtr->Timer & TV_EDIT_TIMER_SET)
     3963        KillTimer(hwnd, TV_EDIT_TIMER);
     3964
     3965    SetTimer(hwnd, TV_EDIT_TIMER, GetDoubleClickTime(), 0);
     3966    infoPtr->Timer |= TV_EDIT_TIMER_SET;
    39513967    }
    39523968    else if (ht.flags & TVHT_ONITEM) /* select the item if the hit was inside of the icon or text */
     
    40074023    else if (ht.flags & TVHT_ONITEMSTATEICON)
    40084024    {
    4009         /* TVS_CHECKBOXES requires us to toggle the current state */
    4010         if (infoPtr->dwStyle & TVS_CHECKBOXES)
    4011             TREEVIEW_ToggleItemState(infoPtr, ht.hItem);
     4025    /* TVS_CHECKBOXES requires us to toggle the current state */
     4026    if (infoPtr->dwStyle & TVS_CHECKBOXES)
     4027        TREEVIEW_ToggleItemState(infoPtr, ht.hItem);
    40124028    }
    40134029
     
    40254041    if (infoPtr->hwndEdit)
    40264042    {
    4027         SetFocus(infoPtr->hwnd);
    4028         return 0;
     4043    SetFocus(infoPtr->hwnd);
     4044    return 0;
    40294045    }
    40304046
     
    40364052    if (TREEVIEW_TrackMouse(infoPtr, ht.pt))
    40374053    {
    4038         if (ht.hItem)
    4039         {
    4040             TREEVIEW_SendTreeviewDnDNotify(infoPtr, TVN_BEGINRDRAGW, ht.hItem, ht.pt);
    4041             infoPtr->dropItem = ht.hItem;
    4042         }
     4054    if (ht.hItem)
     4055    {
     4056        TREEVIEW_SendTreeviewDnDNotify(infoPtr, TVN_BEGINRDRAGW, ht.hItem, ht.pt);
     4057        infoPtr->dropItem = ht.hItem;
     4058    }
    40434059    }
    40444060    else
    40454061    {
    4046         SetFocus(infoPtr->hwnd);
    4047         TREEVIEW_SendSimpleNotify(infoPtr, NM_RCLICK);
     4062    SetFocus(infoPtr->hwnd);
     4063    TREEVIEW_SendSimpleNotify(infoPtr, NM_RCLICK);
    40484064    }
    40494065
     
    40734089
    40744090    if (!(infoPtr->himlNormal))
    4075         return 0;
     4091    return 0;
    40764092
    40774093    if (!dragItem || !TREEVIEW_ValidItem(infoPtr, dragItem))
    4078         return 0;
     4094    return 0;
    40794095
    40804096    TREEVIEW_UpdateDispInfo(infoPtr, dragItem, TVIF_TEXT);
     
    40864102    hOldFont = SelectObject(hdc, infoPtr->hFont);
    40874103    GetTextExtentPoint32A(hdc, dragItem->pszText, lstrlenA(dragItem->pszText),
    4088                           &size);
     4104              &size);
    40894105    TRACE("%ld %ld %s %d\n", size.cx, size.cy, dragItem->pszText,
    4090           lstrlenA(dragItem->pszText));
     4106      lstrlenA(dragItem->pszText));
    40914107    hbmp = CreateCompatibleBitmap(htopdc, size.cx, size.cy);
    40924108    hOldbmp = SelectObject(hdc, hbmp);
     
    40954111    size.cx += cx;
    40964112    if (cy > size.cy)
    4097         size.cy = cy;
     4113    size.cy = cy;
    40984114
    40994115    infoPtr->dragList = ImageList_Create(size.cx, size.cy, ILC_COLOR, 10, 10);
    41004116    ImageList_Draw(infoPtr->himlNormal, dragItem->iImage, hdc, 0, 0,
    4101                    ILD_NORMAL);
     4117           ILD_NORMAL);
    41024118
    41034119/*
     
    41104126    SetRect(&rc, cx, 0, size.cx, size.cy);
    41114127    DrawTextA(hdc, dragItem->pszText, lstrlenA(dragItem->pszText), &rc,
    4112               DT_LEFT);
     4128          DT_LEFT);
    41134129    SelectObject(hdc, hOldFont);
    41144130    SelectObject(hdc, hOldbmp);
     
    41274143static LRESULT
    41284144TREEVIEW_DoSelectItem(TREEVIEW_INFO *infoPtr, INT action, HTREEITEM newSelect,
    4129                       INT cause)
     4145              INT cause)
    41304146{
    41314147    TREEVIEW_ITEM *prevSelect;
     
    41354151
    41364152    TRACE("Entering item %p (%s), flag %x, cause %x, state %d\n",
    4137           newSelect, TREEVIEW_ItemName(newSelect), action, cause,
    4138           newSelect ? newSelect->state : 0);
     4153      newSelect, TREEVIEW_ItemName(newSelect), action, cause,
     4154      newSelect ? newSelect->state : 0);
    41394155
    41404156    /* reset and redraw focusedItem if focusedItem was set so we don't */
     
    41504166    {
    41514167    case TVGN_CARET:
    4152         prevSelect = infoPtr->selectedItem;
    4153 
    4154         if (prevSelect == newSelect)
    4155             return FALSE;
    4156 
    4157         if (TREEVIEW_SendTreeviewNotify(infoPtr,
    4158                                         TVN_SELCHANGINGW,
    4159                                         cause,
    4160                                         TVIF_HANDLE | TVIF_STATE | TVIF_PARAM,
    4161                                         prevSelect,
    4162                                         newSelect))
    4163             return FALSE;
    4164 
    4165         if (prevSelect)
    4166             prevSelect->state &= ~TVIS_SELECTED;
    4167         if (newSelect)
    4168             newSelect->state |= TVIS_SELECTED;
    4169 
    4170         infoPtr->selectedItem = newSelect;
    4171 
    4172         TREEVIEW_EnsureVisible(infoPtr, infoPtr->selectedItem, FALSE);
    4173 
    4174         TREEVIEW_SendTreeviewNotify(infoPtr,
    4175                                     TVN_SELCHANGEDW,
    4176                                     cause,
    4177                                     TVIF_HANDLE | TVIF_STATE | TVIF_PARAM,
    4178                                     prevSelect,
    4179                                     newSelect);
    4180         TREEVIEW_Invalidate(infoPtr, prevSelect);
    4181         TREEVIEW_Invalidate(infoPtr, newSelect);
    4182         break;
     4168    prevSelect = infoPtr->selectedItem;
     4169
     4170    if (prevSelect == newSelect)
     4171        return FALSE;
     4172
     4173    if (TREEVIEW_SendTreeviewNotify(infoPtr,
     4174                    TVN_SELCHANGINGW,
     4175                    cause,
     4176                    TVIF_HANDLE | TVIF_STATE | TVIF_PARAM,
     4177                    prevSelect,
     4178                    newSelect))
     4179        return FALSE;
     4180
     4181    if (prevSelect)
     4182        prevSelect->state &= ~TVIS_SELECTED;
     4183    if (newSelect)
     4184        newSelect->state |= TVIS_SELECTED;
     4185
     4186    infoPtr->selectedItem = newSelect;
     4187
     4188    TREEVIEW_EnsureVisible(infoPtr, infoPtr->selectedItem, FALSE);
     4189
     4190    TREEVIEW_SendTreeviewNotify(infoPtr,
     4191                    TVN_SELCHANGEDW,
     4192                    cause,
     4193                    TVIF_HANDLE | TVIF_STATE | TVIF_PARAM,
     4194                    prevSelect,
     4195                    newSelect);
     4196    TREEVIEW_Invalidate(infoPtr, prevSelect);
     4197    TREEVIEW_Invalidate(infoPtr, newSelect);
     4198    break;
    41834199
    41844200    case TVGN_DROPHILITE:
    4185         prevSelect = infoPtr->dropItem;
    4186 
    4187         if (prevSelect)
    4188             prevSelect->state &= ~TVIS_DROPHILITED;
    4189 
    4190         infoPtr->dropItem = newSelect;
    4191 
    4192         if (newSelect)
    4193             newSelect->state |= TVIS_DROPHILITED;
    4194 
    4195         TREEVIEW_Invalidate(infoPtr, prevSelect);
    4196         TREEVIEW_Invalidate(infoPtr, newSelect);
    4197         break;
     4201    prevSelect = infoPtr->dropItem;
     4202
     4203    if (prevSelect)
     4204        prevSelect->state &= ~TVIS_DROPHILITED;
     4205
     4206    infoPtr->dropItem = newSelect;
     4207
     4208    if (newSelect)
     4209        newSelect->state |= TVIS_DROPHILITED;
     4210
     4211    TREEVIEW_Invalidate(infoPtr, prevSelect);
     4212    TREEVIEW_Invalidate(infoPtr, newSelect);
     4213    break;
    41984214
    41994215    case TVGN_FIRSTVISIBLE:
    4200         TREEVIEW_EnsureVisible(infoPtr, newSelect, FALSE);
    4201         TREEVIEW_SetFirstVisible(infoPtr, newSelect, TRUE);
    4202         TREEVIEW_Invalidate(infoPtr, NULL);
    4203         break;
     4216    TREEVIEW_EnsureVisible(infoPtr, newSelect, FALSE);
     4217    TREEVIEW_SetFirstVisible(infoPtr, newSelect, TRUE);
     4218    TREEVIEW_Invalidate(infoPtr, NULL);
     4219    break;
    42044220    }
    42054221
     
    42134229{
    42144230    if (item != NULL && !TREEVIEW_ValidItem(infoPtr, item))
    4215         return FALSE;
     4231    return FALSE;
    42164232
    42174233    TRACE("%p (%s) %d\n", item, TREEVIEW_ItemName(item), wParam);
    42184234
    42194235    if (!TREEVIEW_DoSelectItem(infoPtr, wParam, item, TVC_UNKNOWN))
    4220         return FALSE;
     4236    return FALSE;
    42214237
    42224238    return TRUE;
     
    42244240
    42254241/*************************************************************************
    4226  *              TREEVIEW_ProcessLetterKeys
     4242 *      TREEVIEW_ProcessLetterKeys
    42274243 *
    42284244 *  Processes keyboard messages generated by pressing the letter keys
     
    43824398
    43834399    if (!TREEVIEW_ValidItem(infoPtr, item))
    4384         return FALSE;
     4400    return FALSE;
    43854401
    43864402    if (!ISVISIBLE(item))
    43874403    {
    4388         /* Expand parents as necessary. */
    4389         HTREEITEM parent;
     4404    /* Expand parents as necessary. */
     4405    HTREEITEM parent;
    43904406
    43914407        /* see if we are trying to ensure that root is vislble */
     
    43954411          parent = item; /* this item is the topmost item */
    43964412
    4397         while (parent != infoPtr->root)
    4398         {
    4399             if (!(parent->state & TVIS_EXPANDED))
    4400                 TREEVIEW_Expand(infoPtr, parent, FALSE, FALSE);
    4401 
    4402             parent = parent->parent;
    4403         }
     4413    while (parent != infoPtr->root)
     4414    {
     4415        if (!(parent->state & TVIS_EXPANDED))
     4416        TREEVIEW_Expand(infoPtr, parent, FALSE, FALSE);
     4417
     4418        parent = parent->parent;
     4419    }
    44044420    }
    44054421
    44064422    TRACE("%p (%s) %ld - %ld\n", item, TREEVIEW_ItemName(item), item->visibleOrder,
    4407           infoPtr->firstVisible->visibleOrder);
     4423      infoPtr->firstVisible->visibleOrder);
    44084424
    44094425    visible_pos = item->visibleOrder - infoPtr->firstVisible->visibleOrder;
     
    44114427    if (visible_pos < 0)
    44124428    {
    4413         /* item is before the start of the list: put it at the top. */
    4414         newFirstVisible = item;
     4429    /* item is before the start of the list: put it at the top. */
     4430    newFirstVisible = item;
    44154431    }
    44164432    else if (visible_pos >= TREEVIEW_GetVisibleCount(infoPtr)
    4417              /* Sometimes, before we are displayed, GVC is 0, causing us to
    4418               * spuriously scroll up. */
    4419              && visible_pos > 0)
    4420     {
    4421         /* item is past the end of the list. */
    4422         int scroll = visible_pos - TREEVIEW_GetVisibleCount(infoPtr);
    4423 
    4424         newFirstVisible = TREEVIEW_GetListItem(infoPtr, infoPtr->firstVisible,
    4425                                                scroll + 1);
     4433         /* Sometimes, before we are displayed, GVC is 0, causing us to
     4434          * spuriously scroll up. */
     4435         && visible_pos > 0)
     4436    {
     4437    /* item is past the end of the list. */
     4438    int scroll = visible_pos - TREEVIEW_GetVisibleCount(infoPtr);
     4439
     4440    newFirstVisible = TREEVIEW_GetListItem(infoPtr, infoPtr->firstVisible,
     4441                           scroll + 1);
    44264442    }
    44274443
     
    44424458        x = max(x, textMetric.tmMaxCharWidth * 3);
    44434459
    4444         if (item->textOffset < 0)
    4445            pos = item->textOffset;
    4446         else if (item->textOffset + x > infoPtr->clientWidth)
     4460    if (item->textOffset < 0)
     4461       pos = item->textOffset;
     4462    else if (item->textOffset + x > infoPtr->clientWidth)
    44474463        {
    44484464           if (x > infoPtr->clientWidth)
     
    44544470           pos = 0;
    44554471
    4456         TREEVIEW_HScroll(infoPtr, MAKEWPARAM(SB_THUMBPOSITION, infoPtr->scrollX + pos));
     4472    TREEVIEW_HScroll(infoPtr, MAKEWPARAM(SB_THUMBPOSITION, infoPtr->scrollX + pos));
    44574473    }
    44584474
    44594475    if (newFirstVisible != NULL && newFirstVisible != infoPtr->firstVisible)
    44604476    {
    4461         TREEVIEW_SetFirstVisible(infoPtr, newFirstVisible, TRUE);
    4462 
    4463         return TRUE;
     4477    TREEVIEW_SetFirstVisible(infoPtr, newFirstVisible, TRUE);
     4478
     4479    return TRUE;
    44644480    }
    44654481
     
    44784494    if (newFirstVisible != NULL)
    44794495    {
    4480         /* Prevent an empty gap from appearing at the bottom... */
    4481         gap_size = TREEVIEW_GetVisibleCount(infoPtr)
    4482             - infoPtr->maxVisibleOrder + newFirstVisible->visibleOrder;
    4483 
    4484         if (gap_size > 0)
    4485         {
    4486             newFirstVisible = TREEVIEW_GetListItem(infoPtr, newFirstVisible,
    4487                                                    -gap_size);
    4488 
    4489             /* ... unless we just don't have enough items. */
    4490             if (newFirstVisible == NULL)
    4491                 newFirstVisible = infoPtr->root->firstChild;
    4492         }
     4496    /* Prevent an empty gap from appearing at the bottom... */
     4497    gap_size = TREEVIEW_GetVisibleCount(infoPtr)
     4498        - infoPtr->maxVisibleOrder + newFirstVisible->visibleOrder;
     4499
     4500    if (gap_size > 0)
     4501    {
     4502        newFirstVisible = TREEVIEW_GetListItem(infoPtr, newFirstVisible,
     4503                           -gap_size);
     4504
     4505        /* ... unless we just don't have enough items. */
     4506        if (newFirstVisible == NULL)
     4507        newFirstVisible = infoPtr->root->firstChild;
     4508    }
    44934509    }
    44944510
    44954511    if (infoPtr->firstVisible != newFirstVisible)
    44964512    {
    4497         if (infoPtr->firstVisible == NULL || newFirstVisible == NULL)
    4498         {
    4499             infoPtr->firstVisible = newFirstVisible;
    4500             TREEVIEW_Invalidate(infoPtr, NULL);
    4501         }
    4502         else
    4503         {
    4504             TREEVIEW_ITEM *item;
    4505             int scroll = infoPtr->uItemHeight *
    4506                          (infoPtr->firstVisible->visibleOrder
    4507                           - newFirstVisible->visibleOrder);
    4508 
    4509             infoPtr->firstVisible = newFirstVisible;
    4510 
    4511             for (item = infoPtr->root->firstChild; item != NULL;
    4512                  item = TREEVIEW_GetNextListItem(infoPtr, item))
    4513             {
    4514                item->rect.top += scroll;
    4515                item->rect.bottom += scroll;
    4516             }
    4517 
    4518             if (bUpdateScrollPos)
    4519                 SetScrollPos(infoPtr->hwnd, SB_VERT,
    4520                               newFirstVisible->visibleOrder, TRUE);
    4521 
    4522             ScrollWindow(infoPtr->hwnd, 0, scroll, NULL, NULL);
    4523             UpdateWindow(infoPtr->hwnd);
    4524         }
     4513    if (infoPtr->firstVisible == NULL || newFirstVisible == NULL)
     4514    {
     4515        infoPtr->firstVisible = newFirstVisible;
     4516        TREEVIEW_Invalidate(infoPtr, NULL);
     4517    }
     4518    else
     4519    {
     4520        TREEVIEW_ITEM *item;
     4521        int scroll = infoPtr->uItemHeight *
     4522                     (infoPtr->firstVisible->visibleOrder
     4523                      - newFirstVisible->visibleOrder);
     4524
     4525        infoPtr->firstVisible = newFirstVisible;
     4526
     4527        for (item = infoPtr->root->firstChild; item != NULL;
     4528             item = TREEVIEW_GetNextListItem(infoPtr, item))
     4529        {
     4530           item->rect.top += scroll;
     4531           item->rect.bottom += scroll;
     4532        }
     4533
     4534        if (bUpdateScrollPos)
     4535        SetScrollPos(infoPtr->hwnd, SB_VERT,
     4536                      newFirstVisible->visibleOrder, TRUE);
     4537
     4538        ScrollWindow(infoPtr->hwnd, 0, scroll, NULL, NULL);
     4539        UpdateWindow(infoPtr->hwnd);
     4540    }
    45254541    }
    45264542}
     
    45424558
    45434559    if (!(infoPtr->uInternalStatus & TV_VSCROLL))
    4544         return 0;
     4560    return 0;
    45454561
    45464562    if (infoPtr->hwndEdit)
    4547         SetFocus(infoPtr->hwnd);
     4563    SetFocus(infoPtr->hwnd);
    45484564
    45494565    if (!oldFirstVisible)
    45504566    {
    4551         assert(infoPtr->root->firstChild == NULL);
    4552         return 0;
     4567    assert(infoPtr->root->firstChild == NULL);
     4568    return 0;
    45534569    }
    45544570
     
    45564572    {
    45574573    case SB_TOP:
    4558         newFirstVisible = infoPtr->root->firstChild;
    4559         break;
     4574    newFirstVisible = infoPtr->root->firstChild;
     4575    break;
    45604576
    45614577    case SB_BOTTOM:
    4562         newFirstVisible = TREEVIEW_GetLastListItem(infoPtr, infoPtr->root);
    4563         break;
     4578    newFirstVisible = TREEVIEW_GetLastListItem(infoPtr, infoPtr->root);
     4579    break;
    45644580
    45654581    case SB_LINEUP:
    4566         newFirstVisible = TREEVIEW_GetPrevListItem(infoPtr, oldFirstVisible);
    4567         break;
     4582    newFirstVisible = TREEVIEW_GetPrevListItem(infoPtr, oldFirstVisible);
     4583    break;
    45684584
    45694585    case SB_LINEDOWN:
    4570         newFirstVisible = TREEVIEW_GetNextListItem(infoPtr, oldFirstVisible);
    4571         break;
     4586    newFirstVisible = TREEVIEW_GetNextListItem(infoPtr, oldFirstVisible);
     4587    break;
    45724588
    45734589    case SB_PAGEUP:
    4574         newFirstVisible = TREEVIEW_GetListItem(infoPtr, oldFirstVisible,
    4575                                                -max(1, TREEVIEW_GetVisibleCount(infoPtr)));
    4576         break;
     4590    newFirstVisible = TREEVIEW_GetListItem(infoPtr, oldFirstVisible,
     4591                           -max(1, TREEVIEW_GetVisibleCount(infoPtr)));
     4592    break;
    45774593
    45784594    case SB_PAGEDOWN:
    4579         newFirstVisible = TREEVIEW_GetListItem(infoPtr, oldFirstVisible,
    4580                                                max(1, TREEVIEW_GetVisibleCount(infoPtr)));
    4581         break;
     4595    newFirstVisible = TREEVIEW_GetListItem(infoPtr, oldFirstVisible,
     4596                           max(1, TREEVIEW_GetVisibleCount(infoPtr)));
     4597    break;
    45824598
    45834599    case SB_THUMBTRACK:
    45844600    case SB_THUMBPOSITION:
    4585         newFirstVisible = TREEVIEW_GetListItem(infoPtr,
    4586                                                infoPtr->root->firstChild,
    4587                                                (LONG)(SHORT)HIWORD(wParam));
    4588         break;
     4601    newFirstVisible = TREEVIEW_GetListItem(infoPtr,
     4602                           infoPtr->root->firstChild,
     4603                           (LONG)(SHORT)HIWORD(wParam));
     4604    break;
    45894605
    45904606    case SB_ENDSCROLL:
    4591         return 0;
     4607    return 0;
    45924608    }
    45934609
    45944610    if (newFirstVisible != NULL)
    45954611    {
    4596         if (newFirstVisible != oldFirstVisible)
    4597             TREEVIEW_SetFirstVisible(infoPtr, newFirstVisible,
    4598                                   nScrollCode != SB_THUMBTRACK);
    4599         else if (nScrollCode == SB_THUMBPOSITION)
    4600             SetScrollPos(infoPtr->hwnd, SB_VERT,
    4601                          newFirstVisible->visibleOrder, TRUE);
     4612    if (newFirstVisible != oldFirstVisible)
     4613        TREEVIEW_SetFirstVisible(infoPtr, newFirstVisible,
     4614                              nScrollCode != SB_THUMBTRACK);
     4615    else if (nScrollCode == SB_THUMBPOSITION)
     4616        SetScrollPos(infoPtr->hwnd, SB_VERT,
     4617                     newFirstVisible->visibleOrder, TRUE);
    46024618    }
    46034619
     
    46154631
    46164632    if (!(infoPtr->uInternalStatus & TV_HSCROLL))
    4617         return FALSE;
     4633    return FALSE;
    46184634
    46194635    if (infoPtr->hwndEdit)
    4620         SetFocus(infoPtr->hwnd);
     4636    SetFocus(infoPtr->hwnd);
    46214637
    46224638    maxWidth = infoPtr->treeWidth - infoPtr->clientWidth;
     
    46314647    {
    46324648    case SB_LINELEFT:
    4633         scrollX -= infoPtr->uItemHeight;
    4634         break;
     4649    scrollX -= infoPtr->uItemHeight;
     4650    break;
    46354651    case SB_LINERIGHT:
    4636         scrollX += infoPtr->uItemHeight;
    4637         break;
     4652    scrollX += infoPtr->uItemHeight;
     4653    break;
    46384654    case SB_PAGELEFT:
    4639         scrollX -= infoPtr->clientWidth;
    4640         break;
     4655    scrollX -= infoPtr->clientWidth;
     4656    break;
    46414657    case SB_PAGERIGHT:
    4642         scrollX += infoPtr->clientWidth;
    4643         break;
     4658    scrollX += infoPtr->clientWidth;
     4659    break;
    46444660
    46454661    case SB_THUMBTRACK:
    46464662    case SB_THUMBPOSITION:
    4647         scrollX = (int)(SHORT)HIWORD(wParam);
    4648         break;
     4663    scrollX = (int)(SHORT)HIWORD(wParam);
     4664    break;
    46494665
    46504666    case SB_ENDSCROLL:
     
    46724688        }
    46734689
    4674         ScrollWindow(infoPtr->hwnd, scroll_pixels, 0, NULL, NULL);
    4675         infoPtr->scrollX = scrollX;
    4676         UpdateWindow(infoPtr->hwnd);
     4690    ScrollWindow(infoPtr->hwnd, scroll_pixels, 0, NULL, NULL);
     4691    infoPtr->scrollX = scrollX;
     4692    UpdateWindow(infoPtr->hwnd);
    46774693    }
    46784694
     
    46904706
    46914707    if (infoPtr->firstVisible == NULL)
    4692         return TRUE;
     4708    return TRUE;
    46934709
    46944710    SystemParametersInfoW(SPI_GETWHEELSCROLLLINES, 0, &pulScrollLines, 0);
     
    46994715    if (abs(gcWheelDelta) >= WHEEL_DELTA && pulScrollLines)
    47004716    {
    4701         int newDy = infoPtr->firstVisible->visibleOrder + pulScrollLines;
    4702         int maxDy = infoPtr->maxVisibleOrder;
    4703 
    4704         if (newDy > maxDy)
    4705             newDy = maxDy;
    4706 
    4707         if (newDy < 0)
    4708             newDy = 0;
    4709 
    4710         TREEVIEW_VScroll(infoPtr, MAKEWPARAM(SB_THUMBPOSITION, newDy));
     4717    int newDy = infoPtr->firstVisible->visibleOrder + pulScrollLines;
     4718    int maxDy = infoPtr->maxVisibleOrder;
     4719
     4720    if (newDy > maxDy)
     4721        newDy = maxDy;
     4722
     4723    if (newDy < 0)
     4724        newDy = 0;
     4725
     4726    TREEVIEW_VScroll(infoPtr, MAKEWPARAM(SB_THUMBPOSITION, newDy));
    47114727    }
    47124728    return TRUE;
     
    47274743    if (infoPtr == NULL)
    47284744    {
    4729         ERR("could not allocate info memory!\n");
    4730         return 0;
     4745    ERR("could not allocate info memory!\n");
     4746    return 0;
    47314747    }
    47324748
     
    47394755    infoPtr->uNumItems = 0;
    47404756    infoPtr->cdmode = 0;
    4741     infoPtr->uScrollTime = 300; /* milliseconds */
     4757    infoPtr->uScrollTime = 300; /* milliseconds */
    47424758    infoPtr->bRedraw = TRUE;
    47434759
     
    47654781
    47664782    infoPtr->clrBk = GetSysColor(COLOR_WINDOW);
    4767     infoPtr->clrText = -1;      /* use system color */
     4783    infoPtr->clrText = -1;  /* use system color */
    47684784    infoPtr->clrLine = RGB(128, 128, 128);
    47694785    infoPtr->clrInsertMark = GetSysColor(COLOR_BTNTEXT);
     
    48094825
    48104826    if (!(infoPtr->dwStyle & TVS_NOTOOLTIPS))
    4811         infoPtr->hwndToolTip = COMCTL32_CreateToolTip(hwnd);
     4827    infoPtr->hwndToolTip = COMCTL32_CreateToolTip(hwnd);
    48124828
    48134829    if (infoPtr->dwStyle & TVS_CHECKBOXES)
    48144830    {
    4815         RECT rc;
    4816         HBITMAP hbm, hbmOld;
    4817         HDC hdc;
    4818         int nIndex;
    4819 
    4820         infoPtr->himlState =
    4821             ImageList_Create(16, 16, ILC_COLOR | ILC_MASK, 3, 0);
    4822 
    4823         hdc = CreateCompatibleDC(0);
    4824         hbm = CreateCompatibleBitmap(hdc, 48, 16);
    4825         hbmOld = SelectObject(hdc, hbm);
    4826 
    4827         rc.left  = 0;   rc.top    = 0;
    4828         rc.right = 48;  rc.bottom = 16;
    4829         FillRect(hdc, &rc, (HBRUSH)(COLOR_WINDOW+1));
    4830 
    4831         rc.left  = 18;   rc.top    = 2;
    4832         rc.right = 30;   rc.bottom = 14;
    4833         DrawFrameControl(hdc, &rc, DFC_BUTTON,
    4834                           DFCS_BUTTONCHECK|DFCS_FLAT);
    4835 
    4836         rc.left  = 34;   rc.right  = 46;
    4837         DrawFrameControl(hdc, &rc, DFC_BUTTON,
    4838                           DFCS_BUTTONCHECK|DFCS_FLAT|DFCS_CHECKED);
    4839 
    4840         nIndex = ImageList_AddMasked(infoPtr->himlState, hbm,
    4841                                       GetSysColor(COLOR_WINDOW));
    4842         TRACE("chckbox index %d\n", nIndex);
    4843         SelectObject(hdc, hbmOld);
    4844         DeleteObject(hbm);
    4845         DeleteDC(hdc);
    4846 
    4847         infoPtr->stateImageWidth = 16;
    4848         infoPtr->stateImageHeight = 16;
     4831    RECT rc;
     4832    HBITMAP hbm, hbmOld;
     4833    HDC hdc;
     4834    int nIndex;
     4835
     4836    infoPtr->himlState =
     4837        ImageList_Create(16, 16, ILC_COLOR | ILC_MASK, 3, 0);
     4838
     4839    hdc = CreateCompatibleDC(0);
     4840    hbm = CreateCompatibleBitmap(hdc, 48, 16);
     4841    hbmOld = SelectObject(hdc, hbm);
     4842
     4843    rc.left  = 0;   rc.top    = 0;
     4844    rc.right = 48;  rc.bottom = 16;
     4845    FillRect(hdc, &rc, (HBRUSH)(COLOR_WINDOW+1));
     4846
     4847    rc.left  = 18;   rc.top    = 2;
     4848    rc.right = 30;   rc.bottom = 14;
     4849    DrawFrameControl(hdc, &rc, DFC_BUTTON,
     4850                      DFCS_BUTTONCHECK|DFCS_FLAT);
     4851
     4852    rc.left  = 34;   rc.right  = 46;
     4853    DrawFrameControl(hdc, &rc, DFC_BUTTON,
     4854                      DFCS_BUTTONCHECK|DFCS_FLAT|DFCS_CHECKED);
     4855
     4856    nIndex = ImageList_AddMasked(infoPtr->himlState, hbm,
     4857                                  GetSysColor(COLOR_WINDOW));
     4858    TRACE("chckbox index %d\n", nIndex);
     4859    SelectObject(hdc, hbmOld);
     4860    DeleteObject(hbm);
     4861    DeleteDC(hdc);
     4862
     4863    infoPtr->stateImageWidth = 16;
     4864    infoPtr->stateImageHeight = 16;
    48494865    }
    48504866    return 0;
     
    48634879    /* Restore original wndproc */
    48644880    if (infoPtr->hwndEdit)
    4865         SetWindowLongA(infoPtr->hwndEdit, GWL_WNDPROC,
    4866                        (LONG)infoPtr->wpEditOrig);
     4881    SetWindowLongA(infoPtr->hwndEdit, GWL_WNDPROC,
     4882               (LONG)infoPtr->wpEditOrig);
    48674883
    48684884    /* Deassociate treeview from the window before doing anything drastic. */
     
    48824898    static const struct
    48834899    {
    4884         unsigned char code;
     4900    unsigned char code;
    48854901    }
    48864902    scroll[] =
    48874903    {
    48884904#define SCROLL_ENTRY(dir, code) { ((dir) << 7) | (code) }
    4889         SCROLL_ENTRY(SB_VERT, SB_PAGEUP),       /* VK_PRIOR */
    4890         SCROLL_ENTRY(SB_VERT, SB_PAGEDOWN),     /* VK_NEXT */
    4891         SCROLL_ENTRY(SB_VERT, SB_BOTTOM),       /* VK_END */
    4892         SCROLL_ENTRY(SB_VERT, SB_TOP),          /* VK_HOME */
    4893         SCROLL_ENTRY(SB_HORZ, SB_LINEUP),       /* VK_LEFT */
    4894         SCROLL_ENTRY(SB_VERT, SB_LINEUP),       /* VK_UP */
    4895         SCROLL_ENTRY(SB_HORZ, SB_LINEDOWN),     /* VK_RIGHT */
    4896         SCROLL_ENTRY(SB_VERT, SB_LINEDOWN)      /* VK_DOWN */
     4905    SCROLL_ENTRY(SB_VERT, SB_PAGEUP),   /* VK_PRIOR */
     4906    SCROLL_ENTRY(SB_VERT, SB_PAGEDOWN), /* VK_NEXT */
     4907    SCROLL_ENTRY(SB_VERT, SB_BOTTOM),   /* VK_END */
     4908    SCROLL_ENTRY(SB_VERT, SB_TOP),      /* VK_HOME */
     4909    SCROLL_ENTRY(SB_HORZ, SB_LINEUP),   /* VK_LEFT */
     4910    SCROLL_ENTRY(SB_VERT, SB_LINEUP),   /* VK_UP */
     4911    SCROLL_ENTRY(SB_HORZ, SB_LINEDOWN), /* VK_RIGHT */
     4912    SCROLL_ENTRY(SB_VERT, SB_LINEDOWN)  /* VK_DOWN */
    48974913#undef SCROLL_ENTRY
    48984914    };
     
    49004916    if (key >= VK_PRIOR && key <= VK_DOWN)
    49014917    {
    4902         unsigned char code = scroll[key - VK_PRIOR].code;
    4903 
    4904         (((code & (1 << 7)) == (SB_HORZ << 7))
    4905         ? TREEVIEW_HScroll
    4906         : TREEVIEW_VScroll)(infoPtr, code & 0x7F);
     4918    unsigned char code = scroll[key - VK_PRIOR].code;
     4919
     4920    (((code & (1 << 7)) == (SB_HORZ << 7))
     4921    ? TREEVIEW_HScroll
     4922    : TREEVIEW_VScroll)(infoPtr, code & 0x7F);
    49074923    }
    49084924
     
    49384954
    49394955    if (prevItem == NULL)
    4940         return FALSE;
     4956    return FALSE;
    49414957
    49424958    if (GetAsyncKeyState(VK_CONTROL) & 0x8000)
    4943         return TREEVIEW_ScrollKeyDown(infoPtr, wParam);
     4959    return TREEVIEW_ScrollKeyDown(infoPtr, wParam);
    49444960
    49454961    switch (wParam)
    49464962    {
    49474963    case VK_UP:
    4948         newSelection = TREEVIEW_GetPrevListItem(infoPtr, prevItem);
    4949         if (!newSelection)
    4950             newSelection = infoPtr->root->firstChild;
    4951         break;
     4964    newSelection = TREEVIEW_GetPrevListItem(infoPtr, prevItem);
     4965    if (!newSelection)
     4966        newSelection = infoPtr->root->firstChild;
     4967    break;
    49524968
    49534969    case VK_DOWN:
    4954         newSelection = TREEVIEW_GetNextListItem(infoPtr, prevItem);
    4955         break;
     4970    newSelection = TREEVIEW_GetNextListItem(infoPtr, prevItem);
     4971    break;
    49564972
    49574973    case VK_HOME:
    4958         newSelection = infoPtr->root->firstChild;
    4959         break;
     4974    newSelection = infoPtr->root->firstChild;
     4975    break;
    49604976
    49614977    case VK_END:
    4962         newSelection = TREEVIEW_GetLastListItem(infoPtr, infoPtr->root);
    4963         break;
     4978    newSelection = TREEVIEW_GetLastListItem(infoPtr, infoPtr->root);
     4979    break;
    49644980
    49654981    case VK_LEFT:
    4966         if (prevItem->state & TVIS_EXPANDED)
    4967         {
    4968             TREEVIEW_Collapse(infoPtr, prevItem, FALSE, TRUE);
    4969         }
    4970         else if (prevItem->parent != infoPtr->root)
    4971         {
    4972             newSelection = prevItem->parent;
    4973         }
    4974         break;
     4982    if (prevItem->state & TVIS_EXPANDED)
     4983    {
     4984        TREEVIEW_Collapse(infoPtr, prevItem, FALSE, TRUE);
     4985    }
     4986    else if (prevItem->parent != infoPtr->root)
     4987    {
     4988        newSelection = prevItem->parent;
     4989    }
     4990    break;
    49754991
    49764992    case VK_RIGHT:
    4977         if (TREEVIEW_HasChildren(infoPtr, prevItem))
    4978         {
    4979             if (!(prevItem->state & TVIS_EXPANDED))
    4980                 TREEVIEW_Expand(infoPtr, prevItem, FALSE, TRUE);
    4981             else
    4982             {
    4983                 newSelection = prevItem->firstChild;
    4984             }
    4985         }
    4986 
    4987         break;
     4993    if (TREEVIEW_HasChildren(infoPtr, prevItem))
     4994    {
     4995        if (!(prevItem->state & TVIS_EXPANDED))
     4996        TREEVIEW_Expand(infoPtr, prevItem, FALSE, TRUE);
     4997        else
     4998        {
     4999        newSelection = prevItem->firstChild;
     5000        }
     5001    }
     5002
     5003    break;
    49885004
    49895005    case VK_MULTIPLY:
    4990         TREEVIEW_ExpandAll(infoPtr, prevItem);
    4991         break;
     5006    TREEVIEW_ExpandAll(infoPtr, prevItem);
     5007    break;
    49925008
    49935009    case VK_ADD:
    4994         if (!(prevItem->state & TVIS_EXPANDED))
    4995             TREEVIEW_Expand(infoPtr, prevItem, FALSE, TRUE);
    4996         break;
     5010    if (!(prevItem->state & TVIS_EXPANDED))
     5011        TREEVIEW_Expand(infoPtr, prevItem, FALSE, TRUE);
     5012    break;
    49975013
    49985014    case VK_SUBTRACT:
    4999         if (prevItem->state & TVIS_EXPANDED)
    5000             TREEVIEW_Collapse(infoPtr, prevItem, FALSE, TRUE);
    5001         break;
     5015    if (prevItem->state & TVIS_EXPANDED)
     5016        TREEVIEW_Collapse(infoPtr, prevItem, FALSE, TRUE);
     5017    break;
    50025018
    50035019    case VK_PRIOR:
    5004         newSelection
    5005             = TREEVIEW_GetListItem(infoPtr, prevItem,
    5006                                    -TREEVIEW_GetVisibleCount(infoPtr));
    5007         break;
     5020    newSelection
     5021        = TREEVIEW_GetListItem(infoPtr, prevItem,
     5022                   -TREEVIEW_GetVisibleCount(infoPtr));
     5023    break;
    50085024
    50095025    case VK_NEXT:
    5010         newSelection
    5011             = TREEVIEW_GetListItem(infoPtr, prevItem,
    5012                                    TREEVIEW_GetVisibleCount(infoPtr));
    5013         break;
     5026    newSelection
     5027        = TREEVIEW_GetListItem(infoPtr, prevItem,
     5028                   TREEVIEW_GetVisibleCount(infoPtr));
     5029    break;
    50145030
    50155031    case VK_BACK:
    5016         newSelection = prevItem->parent;
    5017         if (newSelection == infoPtr->root)
    5018             newSelection = NULL;
    5019         break;
     5032    newSelection = prevItem->parent;
     5033    if (newSelection == infoPtr->root)
     5034        newSelection = NULL;
     5035    break;
    50205036
    50215037    case VK_SPACE:
    5022         if (infoPtr->dwStyle & TVS_CHECKBOXES)
    5023             TREEVIEW_ToggleItemState(infoPtr, prevItem);
    5024         break;
     5038    if (infoPtr->dwStyle & TVS_CHECKBOXES)
     5039        TREEVIEW_ToggleItemState(infoPtr, prevItem);
     5040    break;
    50255041    }
    50265042
    50275043    if (newSelection && newSelection != prevItem)
    50285044    {
    5029         if (TREEVIEW_DoSelectItem(infoPtr, TVGN_CARET, newSelection,
    5030                                   TVC_BYKEYBOARD))
    5031         {
    5032             TREEVIEW_EnsureVisible(infoPtr, newSelection, FALSE);
    5033         }
     5045    if (TREEVIEW_DoSelectItem(infoPtr, TVGN_CARET, newSelection,
     5046                  TVC_BYKEYBOARD))
     5047    {
     5048        TREEVIEW_EnsureVisible(infoPtr, newSelection, FALSE);
     5049    }
    50345050    }
    50355051
     
    50435059
    50445060    if (lpnmh->code == PGN_CALCSIZE) {
    5045         LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
    5046 
    5047         if (lppgc->dwFlag == PGF_CALCWIDTH) {
    5048             lppgc->iWidth = infoPtr->treeWidth;
    5049             TRACE("got PGN_CALCSIZE, returning horz size = %ld, client=%ld\n",
    5050                   infoPtr->treeWidth, infoPtr->clientWidth);
    5051         }
    5052         else {
    5053             lppgc->iHeight = infoPtr->treeHeight;
    5054             TRACE("got PGN_CALCSIZE, returning vert size = %ld, client=%ld\n",
    5055                   infoPtr->treeHeight, infoPtr->clientHeight);
    5056         }
    5057         return 0;
     5061    LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
     5062
     5063    if (lppgc->dwFlag == PGF_CALCWIDTH) {
     5064        lppgc->iWidth = infoPtr->treeWidth;
     5065        TRACE("got PGN_CALCSIZE, returning horz size = %ld, client=%ld\n",
     5066          infoPtr->treeWidth, infoPtr->clientWidth);
     5067    }
     5068    else {
     5069        lppgc->iHeight = infoPtr->treeHeight;
     5070        TRACE("got PGN_CALCSIZE, returning vert size = %ld, client=%ld\n",
     5071          infoPtr->treeHeight, infoPtr->clientHeight);
     5072    }
     5073    return 0;
    50585074    }
    50595075    return DefWindowProcA(infoPtr->hwnd, WM_NOTIFY, wParam, lParam);
     
    50635079{
    50645080    INT format;
    5065    
     5081
    50665082    TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom, nCommand);
    50675083
    50685084    if (nCommand != NF_REQUERY) return 0;
    5069    
     5085
    50705086    format = SendMessageW(hwndFrom, WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwnd, NF_QUERY);
    50715087    TRACE("format=%d\n", format);
    50725088
    50735089    if (format != NFR_ANSI && format != NFR_UNICODE) return 0;
    5074    
     5090
    50755091    infoPtr->bNtfUnicode = (format == NFR_UNICODE);
    5076    
     5092
    50775093    return format;
    50785094}
    5079    
     5095
    50805096static LRESULT
    50815097TREEVIEW_Size(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
     
    50835099    if (wParam == SIZE_RESTORED)
    50845100    {
    5085         infoPtr->clientWidth  = SLOWORD(lParam);
    5086         infoPtr->clientHeight = SHIWORD(lParam);
    5087 
    5088         TREEVIEW_RecalculateVisibleOrder(infoPtr, NULL);
    5089         TREEVIEW_SetFirstVisible(infoPtr, infoPtr->firstVisible, TRUE);
    5090         TREEVIEW_UpdateScrollBars(infoPtr);
     5101    infoPtr->clientWidth  = SLOWORD(lParam);
     5102    infoPtr->clientHeight = SHIWORD(lParam);
     5103
     5104    TREEVIEW_RecalculateVisibleOrder(infoPtr, NULL);
     5105    TREEVIEW_SetFirstVisible(infoPtr, infoPtr->firstVisible, TRUE);
     5106    TREEVIEW_UpdateScrollBars(infoPtr);
    50915107    }
    50925108    else
    50935109    {
    5094         FIXME("WM_SIZE flag %x %lx not handled\n", wParam, lParam);
     5110    FIXME("WM_SIZE flag %x %lx not handled\n", wParam, lParam);
    50955111    }
    50965112
     
    51405156    if (!infoPtr->selectedItem)
    51415157    {
    5142         TREEVIEW_DoSelectItem(infoPtr, TVGN_CARET, infoPtr->firstVisible,
    5143                               TVC_UNKNOWN);
     5158    TREEVIEW_DoSelectItem(infoPtr, TVGN_CARET, infoPtr->firstVisible,
     5159                  TVC_UNKNOWN);
    51445160    }
    51455161
     
    51675183    else
    51685184    {
    5169         if (uMsg == WM_CREATE)
    5170             TREEVIEW_Create(hwnd);
    5171         else
    5172             goto def;
     5185    if (uMsg == WM_CREATE)
     5186        TREEVIEW_Create(hwnd);
     5187    else
     5188        goto def;
    51735189    }
    51745190
     
    51765192    {
    51775193    case TVM_CREATEDRAGIMAGE:
    5178         return TREEVIEW_CreateDragImage(infoPtr, wParam, lParam);
     5194    return TREEVIEW_CreateDragImage(infoPtr, wParam, lParam);
    51795195
    51805196    case TVM_DELETEITEM:
    5181         return TREEVIEW_DeleteItem(infoPtr, (HTREEITEM)lParam);
     5197    return TREEVIEW_DeleteItem(infoPtr, (HTREEITEM)lParam);
    51825198
    51835199    case TVM_EDITLABELA:
    5184         return (LRESULT)TREEVIEW_EditLabelA(infoPtr, (HTREEITEM)lParam);
     5200    return (LRESULT)TREEVIEW_EditLabelA(infoPtr, (HTREEITEM)lParam);
    51855201
    51865202    case TVM_EDITLABELW:
    5187         FIXME("Unimplemented msg TVM_EDITLABELW\n");
    5188         return 0;
     5203    FIXME("Unimplemented msg TVM_EDITLABELW\n");
     5204    return 0;
    51895205
    51905206    case TVM_ENDEDITLABELNOW:
    5191         return TREEVIEW_EndEditLabelNow(infoPtr, (BOOL)wParam);
     5207    return TREEVIEW_EndEditLabelNow(infoPtr, (BOOL)wParam);
    51925208
    51935209    case TVM_ENSUREVISIBLE:
    5194         return TREEVIEW_EnsureVisible(infoPtr, (HTREEITEM)lParam, TRUE);
     5210    return TREEVIEW_EnsureVisible(infoPtr, (HTREEITEM)lParam, TRUE);
    51955211
    51965212    case TVM_EXPAND:
    5197         return TREEVIEW_ExpandMsg(infoPtr, (UINT)wParam, (HTREEITEM)lParam);
     5213    return TREEVIEW_ExpandMsg(infoPtr, (UINT)wParam, (HTREEITEM)lParam);
    51985214
    51995215    case TVM_GETBKCOLOR:
    5200         return TREEVIEW_GetBkColor(infoPtr);
     5216    return TREEVIEW_GetBkColor(infoPtr);
    52015217
    52025218    case TVM_GETCOUNT:
    5203         return TREEVIEW_GetCount(infoPtr);
     5219    return TREEVIEW_GetCount(infoPtr);
    52045220
    52055221    case TVM_GETEDITCONTROL:
    5206         return TREEVIEW_GetEditControl(infoPtr);
     5222    return TREEVIEW_GetEditControl(infoPtr);
    52075223
    52085224    case TVM_GETIMAGELIST:
    5209         return TREEVIEW_GetImageList(infoPtr, wParam);
     5225    return TREEVIEW_GetImageList(infoPtr, wParam);
    52105226
    52115227    case TVM_GETINDENT:
    5212         return TREEVIEW_GetIndent(infoPtr);
     5228    return TREEVIEW_GetIndent(infoPtr);
    52135229
    52145230    case TVM_GETINSERTMARKCOLOR:
    5215         return TREEVIEW_GetInsertMarkColor(infoPtr);
     5231    return TREEVIEW_GetInsertMarkColor(infoPtr);
    52165232
    52175233    case TVM_GETISEARCHSTRINGA:
    5218         FIXME("Unimplemented msg TVM_GETISEARCHSTRINGA\n");
    5219         return 0;
     5234    FIXME("Unimplemented msg TVM_GETISEARCHSTRINGA\n");
     5235    return 0;
    52205236
    52215237    case TVM_GETISEARCHSTRINGW:
    5222         FIXME("Unimplemented msg TVM_GETISEARCHSTRINGW\n");
    5223         return 0;
     5238    FIXME("Unimplemented msg TVM_GETISEARCHSTRINGW\n");
     5239    return 0;
    52245240
    52255241    case TVM_GETITEMA:
    5226         return TREEVIEW_GetItemA(infoPtr, (LPTVITEMEXA)lParam);
     5242    return TREEVIEW_GetItemA(infoPtr, (LPTVITEMEXA)lParam);
    52275243
    52285244    case TVM_GETITEMW:
    5229         return TREEVIEW_GetItemW(infoPtr, (LPTVITEMEXW)lParam);
     5245    return TREEVIEW_GetItemW(infoPtr, (LPTVITEMEXW)lParam);
    52305246
    52315247    case TVM_GETITEMHEIGHT:
    5232         return TREEVIEW_GetItemHeight(infoPtr);
     5248    return TREEVIEW_GetItemHeight(infoPtr);
    52335249
    52345250    case TVM_GETITEMRECT:
    5235         return TREEVIEW_GetItemRect(infoPtr, (BOOL)wParam, (LPRECT)lParam);
     5251    return TREEVIEW_GetItemRect(infoPtr, (BOOL)wParam, (LPRECT)lParam);
    52365252
    52375253    case TVM_GETITEMSTATE:
    5238         return TREEVIEW_GetItemState(infoPtr, (HTREEITEM)wParam, (UINT)lParam);
     5254    return TREEVIEW_GetItemState(infoPtr, (HTREEITEM)wParam, (UINT)lParam);
    52395255
    52405256    case TVM_GETLINECOLOR:
    5241         return TREEVIEW_GetLineColor(infoPtr);
     5257    return TREEVIEW_GetLineColor(infoPtr);
    52425258
    52435259    case TVM_GETNEXTITEM:
    5244         return TREEVIEW_GetNextItem(infoPtr, (UINT)wParam, (HTREEITEM)lParam);
     5260    return TREEVIEW_GetNextItem(infoPtr, (UINT)wParam, (HTREEITEM)lParam);
    52455261
    52465262    case TVM_GETSCROLLTIME:
    5247         return TREEVIEW_GetScrollTime(infoPtr);
     5263    return TREEVIEW_GetScrollTime(infoPtr);
    52485264
    52495265    case TVM_GETTEXTCOLOR:
    5250         return TREEVIEW_GetTextColor(infoPtr);
     5266    return TREEVIEW_GetTextColor(infoPtr);
    52515267
    52525268    case TVM_GETTOOLTIPS:
    5253         return TREEVIEW_GetToolTips(infoPtr);
     5269    return TREEVIEW_GetToolTips(infoPtr);
    52545270
    52555271    case TVM_GETUNICODEFORMAT:
    5256         FIXME("Unimplemented msg TVM_GETUNICODEFORMAT\n");
    5257         return 0;
     5272    FIXME("Unimplemented msg TVM_GETUNICODEFORMAT\n");
     5273    return 0;
    52585274
    52595275    case TVM_GETVISIBLECOUNT:
    5260         return TREEVIEW_GetVisibleCount(infoPtr);
     5276    return TREEVIEW_GetVisibleCount(infoPtr);
    52615277
    52625278    case TVM_HITTEST:
    5263         return TREEVIEW_HitTest(infoPtr, (LPTVHITTESTINFO)lParam);
     5279    return TREEVIEW_HitTest(infoPtr, (LPTVHITTESTINFO)lParam);
    52645280
    52655281    case TVM_INSERTITEMA:
    5266         return TREEVIEW_InsertItemA(infoPtr, lParam);
     5282    return TREEVIEW_InsertItemA(infoPtr, lParam);
    52675283
    52685284    case TVM_INSERTITEMW:
    5269         return TREEVIEW_InsertItemW(infoPtr, lParam);
     5285    return TREEVIEW_InsertItemW(infoPtr, lParam);
    52705286
    52715287    case TVM_SELECTITEM:
    5272         return TREEVIEW_SelectItem(infoPtr, (INT)wParam, (HTREEITEM)lParam);
     5288    return TREEVIEW_SelectItem(infoPtr, (INT)wParam, (HTREEITEM)lParam);
    52735289
    52745290    case TVM_SETBKCOLOR:
    5275         return TREEVIEW_SetBkColor(infoPtr, (COLORREF)lParam);
     5291    return TREEVIEW_SetBkColor(infoPtr, (COLORREF)lParam);
    52765292
    52775293    case TVM_SETIMAGELIST:
    5278         return TREEVIEW_SetImageList(infoPtr, wParam, (HIMAGELIST)lParam);
     5294    return TREEVIEW_SetImageList(infoPtr, wParam, (HIMAGELIST)lParam);
    52795295
    52805296    case TVM_SETINDENT:
    5281         return TREEVIEW_SetIndent(infoPtr, (UINT)wParam);
     5297    return TREEVIEW_SetIndent(infoPtr, (UINT)wParam);
    52825298
    52835299    case TVM_SETINSERTMARK:
    5284         return TREEVIEW_SetInsertMark(infoPtr, (BOOL)wParam, (HTREEITEM)lParam);
     5300    return TREEVIEW_SetInsertMark(infoPtr, (BOOL)wParam, (HTREEITEM)lParam);
    52855301
    52865302    case TVM_SETINSERTMARKCOLOR:
    5287         return TREEVIEW_SetInsertMarkColor(infoPtr, (COLORREF)lParam);
     5303    return TREEVIEW_SetInsertMarkColor(infoPtr, (COLORREF)lParam);
    52885304
    52895305    case TVM_SETITEMA:
    5290         return TREEVIEW_SetItemA(infoPtr, (LPTVITEMEXA)lParam);
     5306    return TREEVIEW_SetItemA(infoPtr, (LPTVITEMEXA)lParam);
    52915307
    52925308    case TVM_SETITEMW:
    52935309    return TREEVIEW_SetItemW(infoPtr, (LPTVITEMEXW)lParam);
    5294         return 0;
     5310    return 0;
    52955311
    52965312    case TVM_SETLINECOLOR:
    5297         return TREEVIEW_SetLineColor(infoPtr, (COLORREF)lParam);
     5313    return TREEVIEW_SetLineColor(infoPtr, (COLORREF)lParam);
    52985314
    52995315    case TVM_SETITEMHEIGHT:
    5300         return TREEVIEW_SetItemHeight(infoPtr, (INT)(SHORT)wParam);
     5316    return TREEVIEW_SetItemHeight(infoPtr, (INT)(SHORT)wParam);
    53015317
    53025318    case TVM_SETSCROLLTIME:
    5303         return TREEVIEW_SetScrollTime(infoPtr, (UINT)wParam);
     5319    return TREEVIEW_SetScrollTime(infoPtr, (UINT)wParam);
    53045320
    53055321    case TVM_SETTEXTCOLOR:
    5306         return TREEVIEW_SetTextColor(infoPtr, (COLORREF)lParam);
     5322    return TREEVIEW_SetTextColor(infoPtr, (COLORREF)lParam);
    53075323
    53085324    case TVM_SETTOOLTIPS:
    5309         return TREEVIEW_SetToolTips(infoPtr, (HWND)wParam);
     5325    return TREEVIEW_SetToolTips(infoPtr, (HWND)wParam);
    53105326
    53115327    case TVM_SETUNICODEFORMAT:
    5312         FIXME("Unimplemented msg TVM_SETUNICODEFORMAT\n");
    5313         return 0;
     5328    FIXME("Unimplemented msg TVM_SETUNICODEFORMAT\n");
     5329    return 0;
    53145330
    53155331    case TVM_SORTCHILDREN:
    5316         return TREEVIEW_SortChildren(infoPtr, wParam, lParam);
     5332    return TREEVIEW_SortChildren(infoPtr, wParam, lParam);
    53175333
    53185334    case TVM_SORTCHILDRENCB:
    5319         return TREEVIEW_SortChildrenCB(infoPtr, wParam, (LPTVSORTCB)lParam);
     5335    return TREEVIEW_SortChildrenCB(infoPtr, wParam, (LPTVSORTCB)lParam);
    53205336
    53215337    case WM_CHAR:
     
    53235339
    53245340    case WM_COMMAND:
    5325         return TREEVIEW_Command(infoPtr, wParam, lParam);
     5341    return TREEVIEW_Command(infoPtr, wParam, lParam);
    53265342
    53275343    case WM_DESTROY:
    5328         return TREEVIEW_Destroy(infoPtr);
    5329 
    5330         /* WM_ENABLE */
     5344    return TREEVIEW_Destroy(infoPtr);
     5345
     5346    /* WM_ENABLE */
    53315347
    53325348    case WM_ERASEBKGND:
    5333         return TREEVIEW_EraseBackground(infoPtr, (HDC)wParam);
     5349    return TREEVIEW_EraseBackground(infoPtr, (HDC)wParam);
    53345350
    53355351    case WM_GETDLGCODE:
    5336         return DLGC_WANTARROWS | DLGC_WANTCHARS;
     5352    return DLGC_WANTARROWS | DLGC_WANTCHARS;
    53375353
    53385354    case WM_GETFONT:
    5339         return TREEVIEW_GetFont(infoPtr);
     5355    return TREEVIEW_GetFont(infoPtr);
    53405356
    53415357    case WM_HSCROLL:
    5342         return TREEVIEW_HScroll(infoPtr, wParam);
     5358    return TREEVIEW_HScroll(infoPtr, wParam);
    53435359
    53445360    case WM_KEYDOWN:
    5345         return TREEVIEW_KeyDown(infoPtr, wParam);
     5361    return TREEVIEW_KeyDown(infoPtr, wParam);
    53465362
    53475363    case WM_KILLFOCUS:
    5348         return TREEVIEW_KillFocus(infoPtr);
     5364    return TREEVIEW_KillFocus(infoPtr);
    53495365
    53505366    case WM_LBUTTONDBLCLK:
    5351         return TREEVIEW_LButtonDoubleClick(infoPtr, lParam);
     5367    return TREEVIEW_LButtonDoubleClick(infoPtr, lParam);
    53525368
    53535369    case WM_LBUTTONDOWN:
    5354         return TREEVIEW_LButtonDown(infoPtr, lParam);
    5355 
    5356         /* WM_MBUTTONDOWN */
    5357 
    5358         /* WM_MOUSEMOVE */
     5370    return TREEVIEW_LButtonDown(infoPtr, lParam);
     5371
     5372    /* WM_MBUTTONDOWN */
     5373
     5374    /* WM_MOUSEMOVE */
    53595375
    53605376    case WM_NOTIFY:
    5361         return TREEVIEW_Notify(infoPtr, wParam, lParam);
     5377    return TREEVIEW_Notify(infoPtr, wParam, lParam);
    53625378
    53635379    case WM_NOTIFYFORMAT:
    5364         return TREEVIEW_NotifyFormat(infoPtr, (HWND)wParam, (UINT)lParam);
     5380    return TREEVIEW_NotifyFormat(infoPtr, (HWND)wParam, (UINT)lParam);
    53655381
    53665382    case WM_PAINT:
    5367         return TREEVIEW_Paint(infoPtr, wParam);
    5368 
    5369         /* WM_PRINTCLIENT */
     5383    return TREEVIEW_Paint(infoPtr, wParam);
     5384
     5385    /* WM_PRINTCLIENT */
    53705386
    53715387    case WM_RBUTTONDOWN:
    5372         return TREEVIEW_RButtonDown(infoPtr, lParam);
     5388    return TREEVIEW_RButtonDown(infoPtr, lParam);
    53735389
    53745390    case WM_SETFOCUS:
    5375         return TREEVIEW_SetFocus(infoPtr);
     5391    return TREEVIEW_SetFocus(infoPtr);
    53765392
    53775393    case WM_SETFONT:
    5378         return TREEVIEW_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
     5394    return TREEVIEW_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
    53795395
    53805396    case WM_SETREDRAW:
     
    53825398
    53835399    case WM_SIZE:
    5384         return TREEVIEW_Size(infoPtr, wParam, lParam);
     5400    return TREEVIEW_Size(infoPtr, wParam, lParam);
    53855401
    53865402    case WM_STYLECHANGED:
    5387         return TREEVIEW_StyleChanged(infoPtr, wParam, lParam);
    5388 
    5389         /* WM_SYSCOLORCHANGE */
    5390 
    5391         /* WM_SYSKEYDOWN */
     5403    return TREEVIEW_StyleChanged(infoPtr, wParam, lParam);
     5404
     5405    /* WM_SYSCOLORCHANGE */
     5406
     5407    /* WM_SYSKEYDOWN */
    53925408
    53935409    case WM_TIMER:
    5394         return TREEVIEW_HandleTimer(infoPtr, wParam);
     5410    return TREEVIEW_HandleTimer(infoPtr, wParam);
    53955411
    53965412    case WM_VSCROLL:
    5397         return TREEVIEW_VScroll(infoPtr, wParam);
    5398 
    5399         /* WM_WININICHANGE */
     5413    return TREEVIEW_VScroll(infoPtr, wParam);
     5414
     5415    /* WM_WININICHANGE */
    54005416
    54015417    case WM_MOUSEWHEEL:
    5402         if (wParam & (MK_SHIFT | MK_CONTROL))
    5403             goto def;
    5404         return TREEVIEW_MouseWheel(infoPtr, wParam);
     5418    if (wParam & (MK_SHIFT | MK_CONTROL))
     5419        goto def;
     5420    return TREEVIEW_MouseWheel(infoPtr, wParam);
    54055421
    54065422    case WM_DRAWITEM:
    5407         TRACE("drawItem\n");
    5408         goto def;
     5423    TRACE("drawItem\n");
     5424    goto def;
    54095425
    54105426    default:
    5411         /* This mostly catches MFC and Delphi messages. :( */
    5412         if ((uMsg >= WM_USER) && (uMsg < WM_APP))
    5413             TRACE("Unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
     5427    /* This mostly catches MFC and Delphi messages. :( */
     5428    if ((uMsg >= WM_USER) && (uMsg < WM_APP))
     5429        TRACE("Unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
    54145430def:
    5415         return DefWindowProcA(hwnd, uMsg, wParam, lParam);
     5431    return DefWindowProcA(hwnd, uMsg, wParam, lParam);
    54165432    }
    54175433    return 0;
     
    54565472
    54575473static inline void TREEVIEW_VerifyItemCommon(TREEVIEW_INFO *infoPtr,
    5458                                              TREEVIEW_ITEM *item)
     5474                         TREEVIEW_ITEM *item)
    54595475{
    54605476    assert(infoPtr != NULL);
     
    54695485    if (item->firstChild)
    54705486    {
    5471         assert(item->firstChild->parent == item);
    5472         assert(item->firstChild->prevSibling == NULL);
     5487    assert(item->firstChild->parent == item);
     5488    assert(item->firstChild->prevSibling == NULL);
    54735489    }
    54745490
    54755491    if (item->lastChild)
    54765492    {
    5477         assert(item->lastChild->parent == item);
    5478         assert(item->lastChild->nextSibling == NULL);
     5493    assert(item->lastChild->parent == item);
     5494    assert(item->lastChild->nextSibling == NULL);
    54795495    }
    54805496
     
    54825498    if (item->nextSibling)
    54835499    {
    5484         assert(item->nextSibling->parent == item->parent);
    5485         assert(item->nextSibling->prevSibling == item);
     5500    assert(item->nextSibling->parent == item->parent);
     5501    assert(item->nextSibling->prevSibling == item);
    54865502    }
    54875503
     
    54895505    if (item->prevSibling)
    54905506    {
    5491         assert(item->prevSibling->parent == item->parent);
    5492         assert(item->prevSibling->nextSibling == item);
     5507    assert(item->prevSibling->parent == item->parent);
     5508    assert(item->prevSibling->nextSibling == item);
    54935509    }
    54945510}
     
    55175533
    55185534    for (child = item->firstChild; child != NULL; child = child->nextSibling)
    5519         TREEVIEW_VerifyItem(infoPtr, child);
     5535    TREEVIEW_VerifyItem(infoPtr, child);
    55205536}
    55215537
Note: See TracChangeset for help on using the changeset viewer.