Ignore:
Timestamp:
May 8, 2002, 1:26:30 PM (23 years ago)
Author:
sandervl
Message:

merge with latest Wine

File:
1 edited

Legend:

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

    r8096 r8382  
    55 * Copyright 1999 Luc Tourangeau
    66 * Copyright 2000 Jason Mawdsley
     7 * Copyright 2001 Codeweavers Inc.
     8 * Copyright 2002 Dimitrie O. Paun
     9 *
     10 * This library is free software; you can redistribute it and/or
     11 * modify it under the terms of the GNU Lesser General Public
     12 * License as published by the Free Software Foundation; either
     13 * version 2.1 of the License, or (at your option) any later version.
     14 *
     15 * This library is distributed in the hope that it will be useful,
     16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     18 * Lesser General Public License for more details.
     19 *
     20 * You should have received a copy of the GNU Lesser General Public
     21 * License along with this library; if not, write to the Free Software
     22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    723 *
    824 * NOTES
    9  * Listview control implementation.
     25 * Listview control implementation. 
    1026 *
    1127 * TODO:
     
    1935 * Data structure:
    2036 *   LISTVIEW_SetItemCount : not completed for non OWNERDATA
    21  *
    22  * Unicode:
    23  *   LISTVIEW_SetItemW : no unicode support
    24  *   LISTVIEW_InsertItemW : no unicode support
    25  *   LISTVIEW_InsertColumnW : no unicode support
    26  *   LISTVIEW_GetColumnW : no unicode support
    27  *   LISTVIEW_SetColumnW : no unicode support
    28  *
     37 *
    2938 * Advanced functionality:
    3039 *   LISTVIEW_GetNumberOfWorkAreas : not implemented
    3140 *   LISTVIEW_GetHotCursor : not implemented
    32  *   LISTVIEW_GetISearchString : not implemented
     41 *   LISTVIEW_GetISearchString : not implemented 
    3342 *   LISTVIEW_GetBkImage : not implemented
    3443 *   LISTVIEW_SetBkImage : not implemented
     
    3746 *   LISTVIEW_Arrange : empty stub
    3847 *   LISTVIEW_ApproximateViewRect : incomplete
    39  *   LISTVIEW_Scroll : not implemented
     48 *   LISTVIEW_Scroll : not implemented 
    4049 *   LISTVIEW_Update : not completed
     50 *
     51 * Known differences in message stream from native control (not known if
     52 * these differences cause problems):
     53 *   LVM_INSERTITEM issues LVM_SETITEMSTATE and LVM_SETITEM in certain cases.
     54 *   LVM_SETITEM does not always issue LVN_ITEMCHANGING/LVN_ITEMCHANGED.
     55 *   WM_PAINT does LVN_GETDISPINFO in item order 0->n, native does n->0.
     56 *   WM_SETREDRAW(True) native does LVN_GETDISPINFO for all items and
     57 *     does *not* invoke DefWindowProc
     58 *   WM_CREATE does not issue WM_QUERYUISTATE and associated registry
     59 *     processing for "USEDOUBLECLICKTIME".
    4160 */
    4261
     
    4463#include <string.h>
    4564#include <stdlib.h>
     65#include <stdio.h>
    4666
    4767#include "winbase.h"
     68#include "winnt.h"
    4869#include "heap.h"
    4970#include "commctrl.h"
    50 #include "debugtools.h"
     71#include "wine/debug.h"
     72
     73WINE_DEFAULT_DEBUG_CHANNEL(listview);
    5174
    5275#ifdef __WIN32OS2__
     
    5578#include "header.h"
    5679
    57 #undef ListView_SetItemState
    58 #define ListView_SetItemState ListView_SetItemStateWine
    59 
    6080typedef struct
    6181{
     
    6989#endif
    7090
    71 DEFAULT_DEBUG_CHANNEL(listview);
    72 
    73 /* Some definitions for inline edit control */
    74 typedef BOOL (*EditlblCallback)(HWND, LPSTR, DWORD);
     91/* Some definitions for inline edit control */   
     92typedef BOOL (*EditlblCallbackW)(HWND, LPWSTR, DWORD);
     93typedef BOOL (*EditlblCallbackA)(HWND, LPWSTR, DWORD);
     94
     95typedef struct tagLV_INTHIT
     96{
     97  LVHITTESTINFO  ht;
     98  DWORD          distance;     /* distance to closest item    */
     99  INT            iDistItem;    /* item number that is closest */
     100} LV_INTHIT, *LPLV_INTHIT;
     101       
    75102
    76103typedef struct tagEDITLABEL_ITEM
    77104{
    78     WNDPROC EditWndProc;
    79     DWORD param;
    80     EditlblCallback EditLblCb;
     105  WNDPROC EditWndProc;
     106  DWORD param;
     107  EditlblCallbackW EditLblCb;
    81108} EDITLABEL_ITEM;
    82109
    83110typedef struct tagLISTVIEW_SUBITEM
    84111{
    85     LPSTR pszText;
    86     INT iImage;
    87     INT iSubItem;
    88 
     112  LPWSTR pszText;
     113  INT iImage;
     114  INT iSubItem;
    89115} LISTVIEW_SUBITEM;
    90116
     
    92118{
    93119  UINT state;
    94   LPSTR pszText;
     120  LPWSTR pszText;
    95121  INT iImage;
    96122  LPARAM lParam;
     
    123149    DWORD             internalFlags;
    124150#endif
    125     COLORREF clrBk;
    126     COLORREF clrText;
    127     COLORREF clrTextBk;
    128     HIMAGELIST himlNormal;
    129     HIMAGELIST himlSmall;
    130     HIMAGELIST himlState;
    131     BOOL bLButtonDown;
    132     BOOL bRButtonDown;
    133     INT nFocusedItem;
    134     HDPA hdpaSelectionRanges;
    135     INT nItemHeight;
    136     INT nItemWidth;
    137     INT nSelectionMark;
    138     INT nHotItem;
    139     SHORT notifyFormat;
    140     RECT rcList;
    141     RECT rcView;
    142     SIZE iconSize;
    143     SIZE iconSpacing;
    144     UINT uCallbackMask;
    145     HWND hwndHeader;
    146     HFONT hDefaultFont;
    147     HFONT hFont;
    148     BOOL bFocus;
    149     DWORD dwExStyle;    /* extended listview style */
    150     HDPA hdpaItems;
    151     PFNLVCOMPARE pfnCompare;
    152     LPARAM lParamSort;
    153     HWND hwndEdit;
    154     INT nEditLabelItem;
    155     EDITLABEL_ITEM *pedititem;
    156     DWORD dwHoverTime;
    157     INT nColumnCount; /* the number of columns in this control */
    158 
    159     DWORD lastKeyPressTimestamp; /* Added */
    160     WPARAM charCode; /* Added */
    161     INT nSearchParamLength; /* Added */
    162     CHAR szSearchParam[ MAX_PATH ]; /* Added */
     151  HWND hwndSelf;
     152  COLORREF clrBk;
     153  COLORREF clrText;
     154  COLORREF clrTextBk;
     155  HIMAGELIST himlNormal;
     156  HIMAGELIST himlSmall;
     157  HIMAGELIST himlState;
     158  BOOL bLButtonDown;
     159  BOOL bRButtonDown;
     160  INT nFocusedItem;
     161  HDPA hdpaSelectionRanges;
     162  INT nItemHeight;
     163  INT nItemWidth;
     164  INT nSelectionMark;
     165  INT nHotItem;
     166  SHORT notifyFormat;
     167  RECT rcList;
     168  RECT rcView;
     169  SIZE iconSize;
     170  SIZE iconSpacing;
     171  UINT uCallbackMask;
     172  HWND hwndHeader;
     173  HFONT hDefaultFont;
     174  HFONT hFont;
     175  INT ntmHeight;               /*  from GetTextMetrics from above font */
     176  INT ntmAveCharWidth;         /*  from GetTextMetrics from above font */
     177  BOOL bFocus;
     178  DWORD dwExStyle;             /* extended listview style */
     179  HDPA hdpaItems;
     180  PFNLVCOMPARE pfnCompare;
     181  LPARAM lParamSort;
     182  HWND hwndEdit;
     183  INT nEditLabelItem;
     184  EDITLABEL_ITEM *pedititem;
     185  DWORD dwHoverTime;
     186  INT nColumnCount;            /* the number of columns in this control */
     187
     188  DWORD lastKeyPressTimestamp; /* Added */
     189  WPARAM charCode;             /* Added */
     190  INT nSearchParamLength;      /* Added */
     191  WCHAR szSearchParam[ MAX_PATH ]; /* Added */
    163192} LISTVIEW_INFO;
    164193
    165194/*
    166  * constants
     195 * constants 
    167196 */
    168197
     
    179208#define REPORT_MARGINX 2
    180209
    181 /* padding for icon in large icon display mode */
    182 #define ICON_TOP_PADDING 2
    183 #define ICON_BOTTOM_PADDING 2
    184 
    185 /* padding for label in large icon display mode */
    186 #define LABEL_VERT_OFFSET 2
     210/* padding for icon in large icon display mode
     211 *   ICON_TOP_PADDING_NOTHITABLE - space between top of box and area
     212 *                                 that HITTEST will see.
     213 *   ICON_TOP_PADDING_HITABLE - spacing between above and icon.
     214 *   ICON_TOP_PADDING - sum of the two above.
     215 *   ICON_BOTTOM_PADDING - between bottom of icon and top of text
     216 *   LABEL_VERT_OFFSET - between bottom of text and end of box
     217 */
     218#define ICON_TOP_PADDING_NOTHITABLE  2
     219#define ICON_TOP_PADDING_HITABLE     2
     220#define ICON_TOP_PADDING ICON_TOP_PADDING_NOTHITABLE + ICON_TOP_PADDING_HITABLE
     221#define ICON_BOTTOM_PADDING 4
     222#define LABEL_VERT_OFFSET 10
    187223
    188224/* default label width for items in list and small icon display modes */
     
    190226
    191227/* default column width for items in list display mode */
    192 #define DEFAULT_COLUMN_WIDTH 96
     228#define DEFAULT_COLUMN_WIDTH 96 
    193229
    194230/* Increment size of the horizontal scroll bar */
     
    203239/* Border for the icon caption */
    204240#define CAPTION_BORDER  2
    205 /*
     241/* 
    206242 * macros
    207243 */
    208 #define ListView_LVNotify(hwnd,lCtrlId,plvnm) \
    209     (BOOL)SendMessageA((hwnd),WM_NOTIFY,(WPARAM)(INT)lCtrlId,(LPARAM)(LPNMLISTVIEW)(plvnm))
    210 #define ListView_Notify(hwnd,lCtrlId,pnmh) \
    211     (BOOL)SendMessageA((hwnd),WM_NOTIFY,(WPARAM)(INT)lCtrlId,(LPARAM)(LPNMHDR)(pnmh))
    212244/* retrieve the number of items in the listview */
    213245#define GETITEMCOUNT(infoPtr) ((infoPtr)->hdpaItems->nItemCount)
    214 
    215 HWND CreateEditLabel(LPCSTR text, DWORD style, INT x, INT y,
    216     INT width, INT height, HWND parent, HINSTANCE hinst,
    217     EditlblCallback EditLblCb, DWORD param);
    218 
    219 /*
    220  * forward declarations
    221  */
    222 static LRESULT LISTVIEW_GetItemA(HWND hwnd, LPLVITEMA lpLVItem, BOOL internal);
     246#define HDM_INSERTITEMT(isW) ( (isW) ? HDM_INSERTITEMW : HDM_INSERTITEMA )
     247
     248HWND CreateEditLabelT(LPCWSTR text, DWORD style, INT x, INT y,
     249        INT width, INT height, HWND parent, HINSTANCE hinst,
     250        EditlblCallbackW EditLblCb, DWORD param, BOOL isW);
     251 
     252/*
     253 * forward declarations
     254 */
     255static LRESULT LISTVIEW_GetItemT(HWND hwnd, LPLVITEMW lpLVItem, BOOL internal, BOOL isW);
     256static INT LISTVIEW_SuperHitTestItem(HWND, LPLV_INTHIT, BOOL);
    223257static INT LISTVIEW_HitTestItem(HWND, LPLVHITTESTINFO, BOOL);
    224258static INT LISTVIEW_GetCountPerRow(HWND);
     
    228262static VOID LISTVIEW_AddGroupSelection(HWND, INT);
    229263static VOID LISTVIEW_AddSelection(HWND, INT);
    230 static BOOL LISTVIEW_AddSubItem(HWND, LPLVITEMA);
     264static BOOL LISTVIEW_AddSubItemT(HWND, LPLVITEMW, BOOL);
    231265static INT LISTVIEW_FindInsertPosition(HDPA, INT);
    232266static INT LISTVIEW_GetItemHeight(HWND);
     267static BOOL LISTVIEW_GetItemBoundBox(HWND, INT, LPRECT);
    233268static BOOL LISTVIEW_GetItemPosition(HWND, INT, LPPOINT);
    234269static LRESULT LISTVIEW_GetItemRect(HWND, INT, LPRECT);
     
    239274static LISTVIEW_SUBITEM* LISTVIEW_GetSubItem(HDPA, INT);
    240275static LRESULT LISTVIEW_GetViewRect(HWND, LPRECT);
    241 static BOOL LISTVIEW_InitItem(HWND, LISTVIEW_ITEM *, LPLVITEMA);
    242 static BOOL LISTVIEW_InitSubItem(HWND, LISTVIEW_SUBITEM *, LPLVITEMA);
     276static BOOL LISTVIEW_InitItemT(HWND, LISTVIEW_ITEM *, LPLVITEMW, BOOL);
     277static BOOL LISTVIEW_InitSubItemT(HWND, LISTVIEW_SUBITEM *, LPLVITEMW, BOOL);
    243278static LRESULT LISTVIEW_MouseSelection(HWND, POINT);
    244279static BOOL LISTVIEW_RemoveColumn(HDPA, INT);
    245280static BOOL LISTVIEW_RemoveSubItem(HDPA, INT);
    246281static VOID LISTVIEW_SetGroupSelection(HWND, INT);
    247 static BOOL LISTVIEW_SetItem(HWND, LPLVITEMA);
     282static BOOL LISTVIEW_SetItemT(HWND, LPLVITEMW, BOOL);
    248283static BOOL LISTVIEW_SetItemFocus(HWND, INT);
    249284static BOOL LISTVIEW_SetItemPosition(HWND, INT, LONG, LONG);
    250285static VOID LISTVIEW_UpdateScroll(HWND);
    251286static VOID LISTVIEW_SetSelection(HWND, INT);
    252 static VOID LISTVIEW_UpdateSize(HWND);
    253 static BOOL LISTVIEW_SetSubItem(HWND, LPLVITEMA);
     287static BOOL LISTVIEW_UpdateSize(HWND);
     288static BOOL LISTVIEW_SetSubItemT(HWND, LPLVITEMW, BOOL);
    254289static LRESULT LISTVIEW_SetViewRect(HWND, LPRECT);
    255290static BOOL LISTVIEW_ToggleSelection(HWND, INT);
    256291static VOID LISTVIEW_UnsupportedStyles(LONG lStyle);
    257 static HWND LISTVIEW_EditLabelA(HWND hwnd, INT nItem);
    258 static BOOL LISTVIEW_EndEditLabel(HWND hwnd, LPSTR pszText, DWORD nItem);
     292static HWND LISTVIEW_EditLabelT(HWND hwnd, INT nItem, BOOL isW);
     293static BOOL LISTVIEW_EndEditLabelW(HWND hwnd, LPWSTR pszText, DWORD nItem);
     294static BOOL LISTVIEW_EndEditLabelA(HWND hwnd, LPSTR pszText, DWORD nItem);
    259295static LRESULT LISTVIEW_Command(HWND hwnd, WPARAM wParam, LPARAM lParam);
    260 static LRESULT LISTVIEW_SortItems(HWND hwnd, WPARAM wParam, LPARAM lParam);
    261 #ifdef __WIN32OS2__
    262 static LRESULT LISTVIEW_GetStringWidth(HWND hwnd,HDC hdc,LPWSTR lpszText,BOOL unicode);
    263 #define LISTVIEW_GetStringWidthA(a,b) LISTVIEW_GetStringWidth(a,0,(LPWSTR)b,FALSE)
    264 #else
    265 static LRESULT LISTVIEW_GetStringWidthA(HWND hwnd, LPCSTR lpszText);
    266 #endif
     296static LRESULT LISTVIEW_SortItems(HWND hwnd, PFNLVCOMPARE pfnCompare, LPARAM lParamSort);
     297static LRESULT LISTVIEW_GetStringWidthT(HWND hwnd, LPCWSTR lpszText, BOOL isW);
    267298static INT LISTVIEW_ProcessLetterKeys( HWND hwnd, WPARAM charCode, LPARAM keyData );
    268299static BOOL LISTVIEW_KeySelection(HWND hwnd, INT nItem);
    269300static LRESULT LISTVIEW_GetItemState(HWND hwnd, INT nItem, UINT uMask);
    270 static LRESULT LISTVIEW_SetItemState(HWND hwnd, INT nItem, LPLVITEMA lpLVItem);
     301static LRESULT LISTVIEW_SetItemState(HWND hwnd, INT nItem, LPLVITEMW lpLVItem);
    271302static BOOL LISTVIEW_IsSelected(HWND hwnd, INT nItem);
    272303static VOID LISTVIEW_RemoveSelectionRange(HWND hwnd, INT lItem, INT uItem);
    273304static void LISTVIEW_FillBackground(HWND hwnd, HDC hdc, LPRECT rc);
     305static void ListView_UpdateLargeItemLabelRect (HWND hwnd, const LISTVIEW_INFO* infoPtr, int nItem, RECT *rect);
     306static LRESULT LISTVIEW_GetColumnT(HWND, INT, LPLVCOLUMNW, BOOL);
    274307
    275308/******** Defines that LISTVIEW_ProcessLetterKeys uses ****************/
    276309#define KEY_DELAY       450
    277310
     311#define COUNTOF(array) (sizeof(array)/sizeof(array[0]))
     312
     313static inline BOOL is_textW(LPCWSTR text)
     314{
     315  return text != NULL && text != LPSTR_TEXTCALLBACKW;
     316}
     317
     318static inline BOOL is_textT(LPCWSTR text, BOOL isW)
     319{
     320  /* we can ignore isW since LPSTR_TEXTCALLBACKW == LPSTR_TEXTCALLBACKA */
     321  return is_textW(text);
     322}
     323
     324static inline int textlenT(LPCWSTR text, BOOL isW)
     325{
     326  return !is_textT(text, isW) ? 0 :
     327         isW ? lstrlenW(text) : lstrlenA((LPCSTR)text);
     328}
     329
     330static inline void textcpynT(LPWSTR dest, BOOL isDestW, LPCWSTR src, BOOL isSrcW, INT max)
     331{
     332  if (isDestW)
     333    if (isSrcW) lstrcpynW(dest, src, max);
     334    else MultiByteToWideChar(CP_ACP, 0, (LPCSTR)src, -1, dest, max);
     335  else
     336    if (isSrcW) WideCharToMultiByte(CP_ACP, 0, src, -1, (LPSTR)dest, max, NULL, NULL);
     337    else lstrcpynA((LPSTR)dest, (LPCSTR)src, max);
     338}
     339
     340static inline LPCSTR debugstr_t(LPCWSTR text, BOOL isW)
     341{
     342  return NULL;
     343}
     344
     345static inline LPCSTR debugstr_tn(LPCWSTR text, BOOL isW, INT n)
     346{
     347  return NULL;
     348}
     349
     350static inline LPWSTR textdupTtoW(LPCWSTR text, BOOL isW)
     351{
     352  LPWSTR wstr = (LPWSTR)text;
     353 
     354  TRACE("(text=%s, isW=%d)\n", debugstr_t(text, isW), isW); 
     355  if (!isW && text)
     356  {
     357    INT len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)text, -1, NULL, 0);
     358    wstr = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
     359    if (wstr) MultiByteToWideChar(CP_ACP, 0, (LPCSTR)text, -1, wstr, len);
     360  }
     361  TRACE("   wstr=%s\n", debugstr_w(wstr));
     362  return wstr;
     363}
     364
     365static inline void textfreeT(LPWSTR wstr, BOOL isW)
     366{
     367  if (!isW && wstr) HeapFree(GetProcessHeap(), 0, wstr);
     368}
     369
     370/*
     371 * dest is a pointer to a Unicode string
     372 * src is a pointer to a string (Unicode if isW, ANSI if !isW)
     373 */
     374static inline BOOL textsetptrT(LPWSTR *dest, LPWSTR src, BOOL isW)
     375{
     376    LPWSTR pszText = textdupTtoW(src, isW);
     377    BOOL bResult = TRUE;
     378    if (*dest == LPSTR_TEXTCALLBACKW) *dest = NULL;
     379    bResult = Str_SetPtrW(dest, pszText);
     380    textfreeT(pszText, isW);
     381    return bResult;
     382}
     383
     384static inline LRESULT CallWindowProcT(WNDPROC proc, HWND hwnd, UINT uMsg,
     385                                      WPARAM wParam, LPARAM lParam, BOOL isW)
     386{
     387  if (isW)
     388    return CallWindowProcW(proc, hwnd, uMsg, wParam, lParam);
     389  else
     390    return CallWindowProcA(proc, hwnd, uMsg, wParam, lParam);
     391}
     392
     393static inline BOOL notify(HWND self, INT code, LPNMHDR pnmh)
     394{
     395  pnmh->hwndFrom = self;
     396  pnmh->idFrom = GetWindowLongW(self, GWL_ID);
     397  pnmh->code = code;
     398  return (BOOL)SendMessageW(GetParent(self), WM_NOTIFY,
     399                            (WPARAM)pnmh->idFrom, (LPARAM)pnmh);
     400}
     401
     402static inline BOOL hdr_notify(HWND self, INT code)
     403{
     404  NMHDR nmh;
     405  return notify(self, code, &nmh);
     406}
     407
     408static inline BOOL listview_notify(HWND self, INT code, LPNMLISTVIEW plvnm)
     409{
     410  return notify(self, code, (LPNMHDR)plvnm);
     411}
     412
     413static int tabNotification[] = {
     414  LVN_BEGINLABELEDITW, LVN_BEGINLABELEDITA,
     415  LVN_ENDLABELEDITW, LVN_ENDLABELEDITA,
     416  LVN_GETDISPINFOW, LVN_GETDISPINFOA,
     417  LVN_SETDISPINFOW, LVN_SETDISPINFOA,
     418  LVN_ODFINDITEMW, LVN_ODFINDITEMA,
     419  LVN_GETINFOTIPW, LVN_GETINFOTIPA,
     420  0
     421};
     422
     423static int get_ansi_notification(INT unicodeNotificationCode)
     424{
     425  int *pTabNotif = tabNotification;
     426  while (*pTabNotif && (unicodeNotificationCode != *pTabNotif++));
     427  if (*pTabNotif) return *pTabNotif;
     428  ERR("unknown notification %x\n", unicodeNotificationCode);
     429  return unicodeNotificationCode;
     430}
     431
     432/*
     433  Send notification. depends on dispinfoW having same
     434  structure as dispinfoA.
     435  self : listview handle
     436  notificationCode : *Unicode* notification code
     437  pdi : dispinfo structure (can be unicode or ansi)
     438  isW : TRUE if dispinfo is Unicode
     439*/
     440static BOOL dispinfo_notifyT(HWND self, INT notificationCode, LPNMLVDISPINFOW pdi, BOOL isW)
     441{
     442  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(self, 0);
     443  BOOL bResult = FALSE;
     444  BOOL convertToAnsi = FALSE, convertToUnicode = FALSE;
     445  INT realNotifCode;
     446  INT cchTempBufMax = 0, savCchTextMax = 0;
     447  LPWSTR pszTempBuf = NULL, savPszText = NULL;
     448
     449  TRACE("(self=%x, code=%x, pdi=%p, isW=%d)\n", self, notificationCode, pdi, isW);
     450  TRACE("   notifyFormat=%s\n",
     451        infoPtr->notifyFormat == NFR_UNICODE ? "NFR_UNICODE" :
     452        infoPtr->notifyFormat == NFR_ANSI ? "NFR_ANSI" : "(not set)");
     453  if (infoPtr->notifyFormat == NFR_ANSI)
     454    realNotifCode = get_ansi_notification(notificationCode);
     455  else
     456    realNotifCode = notificationCode;
     457
     458  if (is_textT(pdi->item.pszText, isW))
     459  {
     460    if (isW && infoPtr->notifyFormat == NFR_ANSI)
     461        convertToAnsi = TRUE;
     462    if (!isW && infoPtr->notifyFormat == NFR_UNICODE)
     463        convertToUnicode = TRUE;
     464  }
     465 
     466  if (convertToAnsi || convertToUnicode)
     467  {
     468    TRACE("   we have to convert the text to the correct format\n");
     469    if (notificationCode != LVN_GETDISPINFOW)
     470    { /* length of existing text */
     471      cchTempBufMax = convertToUnicode ?
     472      MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pdi->item.pszText, -1, NULL, 0):
     473      WideCharToMultiByte(CP_ACP, 0, pdi->item.pszText, -1, NULL, 0, NULL, NULL);
     474    }
     475    else
     476      cchTempBufMax = pdi->item.cchTextMax;
     477
     478    pszTempBuf = HeapAlloc(GetProcessHeap(), 0,
     479        (convertToUnicode ? sizeof(WCHAR) : sizeof(CHAR)) * cchTempBufMax);
     480    if (!pszTempBuf) return FALSE;
     481    if (convertToUnicode)
     482      MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pdi->item.pszText, -1,
     483                          pszTempBuf, cchTempBufMax);
     484    else
     485      WideCharToMultiByte(CP_ACP, 0, pdi->item.pszText, -1, (LPSTR) pszTempBuf,
     486                          cchTempBufMax, NULL, NULL);
     487    TRACE("   text=%s\n", debugstr_t(pszTempBuf, convertToUnicode));
     488    savCchTextMax = pdi->item.cchTextMax;
     489    savPszText = pdi->item.pszText;
     490    pdi->item.pszText = pszTempBuf;
     491    pdi->item.cchTextMax = cchTempBufMax;
     492  }
     493 
     494  bResult = notify(self, realNotifCode, (LPNMHDR)pdi);
     495 
     496  if (convertToUnicode || convertToAnsi)
     497  { /* convert back result */
     498    TRACE("   returned text=%s\n", debugstr_t(pdi->item.pszText, convertToUnicode));
     499    if (convertToUnicode) /* note : pointer can be changed by app ! */
     500      WideCharToMultiByte(CP_ACP, 0, pdi->item.pszText, -1, (LPSTR) savPszText,
     501                          savCchTextMax, NULL, NULL);
     502    else
     503      MultiByteToWideChar(CP_ACP, 0, (LPSTR) pdi->item.pszText, -1,
     504                          savPszText, savCchTextMax);
     505    pdi->item.pszText = savPszText; /* restores our buffer */
     506    pdi->item.cchTextMax = savCchTextMax;
     507    HeapFree(GetProcessHeap(), 0, pszTempBuf);
     508  }
     509  return bResult;
     510}
     511
     512static inline LRESULT LISTVIEW_GetItemW(HWND hwnd, LPLVITEMW lpLVItem, BOOL internal)
     513{
     514  return LISTVIEW_GetItemT(hwnd, lpLVItem, internal, TRUE);
     515}
     516
     517static inline int lstrncmpiW(LPCWSTR s1, LPCWSTR s2, int n)
     518{
     519  int res;
     520
     521  n = min(min(n, strlenW(s1)), strlenW(s2));
     522  res = CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE, s1, n, s2, n);
     523  return res ? res - 2 : res;
     524}
     525
     526static char* debuglvitem_t(LPLVITEMW lpLVItem, BOOL isW)
     527{
     528  static int index = 0;
     529  static char buffers[20][256];
     530  char* buf = buffers[index++ % 20];
     531  if (lpLVItem == NULL) return "(null)";
     532  return buf;
     533}
     534
     535static char* debuglvcolumn_t(LPLVCOLUMNW lpColumn, BOOL isW)
     536{
     537  static int index = 0;
     538  static char buffers[20][256];
     539  char* buf = buffers[index++ % 20];
     540  if (lpColumn == NULL) return "(null)";
     541  return buf;
     542}
     543
     544static void LISTVIEW_DumpListview(LISTVIEW_INFO *iP, INT line)
     545{
     546  DWORD dwStyle = GetWindowLongW (iP->hwndSelf, GWL_STYLE);
     547  TRACE("listview %08x at line %d, clrBk=0x%06lx, clrText=0x%06lx, clrTextBk=0x%06lx, ItemHeight=%d, ItemWidth=%d, Style=0x%08lx\n",
     548        iP->hwndSelf, line, iP->clrBk, iP->clrText, iP->clrTextBk,
     549        iP->nItemHeight, iP->nItemWidth, dwStyle);
     550  TRACE("listview %08x at line %d, himlNor=%p, himlSml=%p, himlState=%p, Focused=%d, Hot=%d, exStyle=0x%08lx\n",
     551        iP->hwndSelf, line, iP->himlNormal, iP->himlSmall, iP->himlState,
     552        iP->nFocusedItem, iP->nHotItem, iP->dwExStyle);
     553}
    278554
    279555static BOOL
     
    281557                               RECT rc)
    282558{
    283   LISTVIEW_INFO *infoPtr;
     559  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    284560  NMLVCUSTOMDRAW nmcdhdr;
    285561  LPNMCUSTOMDRAW nmcd;
    286562
    287   TRACE("drawstage:%lx hdc:%x\n", dwDrawStage, hdc);
    288 
    289   infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     563  TRACE("(hwnd=%x, dwDrawStage=%lx, hdc=%x, rc=?)\n", hwnd, dwDrawStage, hdc);
    290564
    291565  nmcd= & nmcdhdr.nmcd;
    292566  nmcd->hdr.hwndFrom = hwnd;
    293   nmcd->hdr.idFrom =  GetWindowLongA( hwnd, GWL_ID);
     567  nmcd->hdr.idFrom =  GetWindowLongW( hwnd, GWL_ID);
    294568  nmcd->hdr.code   = NM_CUSTOMDRAW;
    295569  nmcd->dwDrawStage= dwDrawStage;
     
    305579  nmcdhdr.clrTextBk= infoPtr->clrBk;
    306580
    307   return (BOOL)SendMessageA (GetParent (hwnd), WM_NOTIFY,
    308               (WPARAM) GetWindowLongA( hwnd, GWL_ID), (LPARAM)&nmcdhdr);
     581  return (BOOL)SendMessageW (GetParent (hwnd), WM_NOTIFY,
     582              (WPARAM) GetWindowLongW( hwnd, GWL_ID), (LPARAM)&nmcdhdr);
    309583}
    310584
    311585static BOOL
    312586LISTVIEW_SendCustomDrawItemNotify (HWND hwnd, HDC hdc,
    313                                    UINT iItem, UINT iSubItem,
     587                                   UINT iItem, UINT iSubItem, 
    314588                                   UINT uItemDrawState)
    315589{
     
    321595 INT retval;
    322596 RECT itemRect;
    323  LVITEMA item;
    324 
    325  infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    326 
    327  ZeroMemory(&item,sizeof(LVITEMA));
     597 LVITEMW item;
     598
     599 infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     600
     601 ZeroMemory(&item,sizeof(item));
    328602 item.iItem = iItem;
    329603 item.mask = LVIF_PARAM;
    330  ListView_GetItemA(hwnd,&item);
     604 ListView_GetItemW(hwnd,&item);
    331605
    332606 dwDrawStage=CDDS_ITEM | uItemDrawState;
     
    343617 nmcd= & nmcdhdr.nmcd;
    344618 nmcd->hdr.hwndFrom = hwnd;
    345  nmcd->hdr.idFrom =  GetWindowLongA( hwnd, GWL_ID);
     619 nmcd->hdr.idFrom =  GetWindowLongW( hwnd, GWL_ID);
    346620 nmcd->hdr.code   = NM_CUSTOMDRAW;
    347621 nmcd->dwDrawStage= dwDrawStage;
    348  nmcd->hdc                = hdc;
     622 nmcd->hdc        = hdc;
    349623 nmcd->rc.left    = itemRect.left;
    350624 nmcd->rc.right   = itemRect.right;
     
    358632 nmcdhdr.iSubItem   =iSubItem;
    359633
    360  TRACE("drawstage:%lx hdc:%x item:%lx, itemstate:%x, lItemlParam:%lx\n",
    361                   nmcd->dwDrawStage, nmcd->hdc, nmcd->dwItemSpec,
    362           nmcd->uItemState, nmcd->lItemlParam);
    363 
    364  retval=SendMessageA (GetParent (hwnd), WM_NOTIFY,
    365                  (WPARAM) GetWindowLongA( hwnd, GWL_ID), (LPARAM)&nmcdhdr);
     634 TRACE("drawstage=%lx hdc=%x item=%lx, itemstate=%x, lItemlParam=%lx\n",
     635       nmcd->dwDrawStage, nmcd->hdc, nmcd->dwItemSpec,
     636       nmcd->uItemState, nmcd->lItemlParam);
     637
     638 retval=SendMessageW (GetParent (hwnd), WM_NOTIFY,
     639                 (WPARAM) GetWindowLongW( hwnd, GWL_ID), (LPARAM)&nmcdhdr);
    366640
    367641 infoPtr->clrText=nmcdhdr.clrText;
     
    372646
    373647/*************************************************************************
    374  *      LISTVIEW_ProcessLetterKeys
    375  *
    376  *  Processes keyboard messages generated by pressing the letter keys
     648 *              LISTVIEW_ProcessLetterKeys
     649 *
     650 *  Processes keyboard messages generated by pressing the letter keys 
    377651 *  on the keyboard.
    378  *  What this does is perform a case insensitive search from the
     652 *  What this does is perform a case insensitive search from the 
    379653 *  current position with the following quirks:
    380  *  - If two chars or more are pressed in quick succession we search
     654 *  - If two chars or more are pressed in quick succession we search 
    381655 *    for the corresponding string (e.g. 'abc').
    382  *  - If there is a delay we wipe away the current search string and
     656 *  - If there is a delay we wipe away the current search string and 
    383657 *    restart with just that char.
    384  *  - If the user keeps pressing the same character, whether slowly or
    385  *    fast, so that the search string is entirely composed of this
    386  *    character ('aaaaa' for instance), then we search for first item
     658 *  - If the user keeps pressing the same character, whether slowly or 
     659 *    fast, so that the search string is entirely composed of this 
     660 *    character ('aaaaa' for instance), then we search for first item 
    387661 *    that starting with that character.
    388  *  - If the user types the above character in quick succession, then
    389  *    we must also search for the corresponding string ('aaaaa'), and
     662 *  - If the user types the above character in quick succession, then 
     663 *    we must also search for the corresponding string ('aaaaa'), and 
    390664 *    go to that string if there is a match.
    391665 *
     
    396670 * BUGS
    397671 *
    398  *  - The current implementation has a list of characters it will
    399  *    accept and it ignores averything else. In particular it will
    400  *    ignore accentuated characters which seems to match what
    401  *    Windows does. But I'm not sure it makes sense to follow
     672 *  - The current implementation has a list of characters it will 
     673 *    accept and it ignores averything else. In particular it will 
     674 *    ignore accentuated characters which seems to match what 
     675 *    Windows does. But I'm not sure it makes sense to follow 
    402676 *    Windows there.
    403677 *  - We don't sound a beep when the search fails.
     
    417691    INT nSize;
    418692    INT endidx,idx;
    419     LVITEMA item;
    420     CHAR buffer[MAX_PATH];
     693    LVITEMW item;
     694    WCHAR buffer[MAX_PATH];
    421695    DWORD timestamp,elapsed;
    422696
     
    425699        return 0;
    426700
    427     infoPtr=(LISTVIEW_INFO*)GetWindowLongA(hwnd, 0);
     701    infoPtr=(LISTVIEW_INFO*)GetWindowLongW(hwnd, 0);
    428702    if (!infoPtr)
    429703        return 0;
     
    458732    infoPtr->lastKeyPressTimestamp=timestamp;
    459733    if (elapsed < KEY_DELAY) {
    460         if (infoPtr->nSearchParamLength < sizeof(infoPtr->szSearchParam)) {
     734        if (infoPtr->nSearchParamLength < COUNTOF(infoPtr->szSearchParam)) {
    461735            infoPtr->szSearchParam[infoPtr->nSearchParamLength++]=charCode;
    462736        }
     
    499773        item.iSubItem = 0;
    500774        item.pszText = buffer;
    501         item.cchTextMax = sizeof(buffer);
    502         ListView_GetItemA( hwnd, &item );
     775        item.cchTextMax = COUNTOF(buffer);
     776        ListView_GetItemW( hwnd, &item );
    503777
    504778        /* check for a match */
    505         if (strncasecmp(item.pszText,infoPtr->szSearchParam,infoPtr->nSearchParamLength) == 0) {
     779        if (lstrncmpiW(item.pszText,infoPtr->szSearchParam,infoPtr->nSearchParamLength) == 0) {
    506780            nItem=idx;
    507781            break;
    508782        } else if ( (charCode != 0) && (nItem == -1) && (nItem != infoPtr->nFocusedItem) &&
    509                     (strncasecmp(item.pszText,infoPtr->szSearchParam,1) == 0) ) {
     783                    (lstrncmpiW(item.pszText,infoPtr->szSearchParam,1) == 0) ) {
    510784            /* This would work but we must keep looking for a longer match */
    511785            nItem=idx;
     
    526800
    527801/*************************************************************************
    528  * LISTVIEW_UpdateHeaderSize [Internal]
     802 * LISTVIEW_UpdateHeaderSize [Internal] 
    529803 *
    530804 * Function to resize the header control
     
    541815static VOID LISTVIEW_UpdateHeaderSize(HWND hwnd, INT nNewScrollPos)
    542816{
    543     LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     817    LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    544818    RECT winRect;
    545819    POINT point[2];
     
    559833    point[1].x += (nNewScrollPos * LISTVIEW_SCROLL_DIV_SIZE);
    560834#endif
    561 
    562835    SetWindowPos(infoPtr->hwndHeader,0,
    563836        point[0].x,point[0].y,point[1].x,point[1].y,
     
    567840/***
    568841 * DESCRIPTION:
    569  * Update the scrollbars. This functions should be called whenever
     842 * Update the scrollbars. This functions should be called whenever 
    570843 * the content, size or view changes.
    571  *
     844 * 
    572845 * PARAMETER(S):
    573846 * [I] HWND : window handle
     
    579852static VOID LISTVIEW_UpdateScroll(HWND hwnd)
    580853{
    581   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     854  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    582855  INT nListHeight = infoPtr->rcList.bottom - infoPtr->rcList.top;
    583856  INT nListWidth = infoPtr->rcList.right - infoPtr->rcList.left;
    584857  SCROLLINFO scrollInfo;
    585   LONG dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
     858  LONG dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
    586859  UINT uView =  dwStyle & LVS_TYPEMASK;
    587860
     
    697970static VOID LISTVIEW_UpdateScroll(HWND hwnd)
    698971{
    699   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    700   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     972  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     973  LONG lStyle = GetWindowLongW(hwnd, GWL_STYLE);
    701974  UINT uView =  lStyle & LVS_TYPEMASK;
    702975  INT nListHeight = infoPtr->rcList.bottom - infoPtr->rcList.top;
     
    704977  SCROLLINFO scrollInfo;
    705978
    706 
     979  if (lStyle & LVS_NOSCROLL) return;
     980 
    707981  ZeroMemory(&scrollInfo, sizeof(SCROLLINFO));
    708982  scrollInfo.cbSize = sizeof(SCROLLINFO);
     
    719993    if((nNumOfItems % nCountPerColumn) == 0)
    720994    {
    721       scrollInfo.nMax--;
     995        scrollInfo.nMax--;
     996    }
     997    else
     998    {
     999        scrollInfo.nMax++;
    7221000    }
    7231001    scrollInfo.nPos = ListView_GetTopIndex(hwnd) / nCountPerColumn;
     
    7391017    /* update horizontal scrollbar */
    7401018    nListWidth = infoPtr->rcList.right - infoPtr->rcList.left;
    741     if (GetScrollInfo(hwnd, SB_HORZ, &scrollInfo) == FALSE
     1019    if (GetScrollInfo(hwnd, SB_HORZ, &scrollInfo) == FALSE 
    7421020       || GETITEMCOUNT(infoPtr) == 0)
    7431021    {
    7441022      scrollInfo.nPos = 0;
    745     }
     1023    } 
    7461024    scrollInfo.nMin = 0;
    747     scrollInfo.fMask = SIF_RANGE | SIF_POS | SIF_PAGE  ;
     1025    scrollInfo.fMask = SIF_RANGE | SIF_POS | SIF_PAGE  ; 
    7481026    scrollInfo.nPage = nListWidth / LISTVIEW_SCROLL_DIV_SIZE;
    7491027    scrollInfo.nMax = max(infoPtr->nItemWidth / LISTVIEW_SCROLL_DIV_SIZE, 0)-1;
    750     SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE);
     1028    SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE); 
    7511029
    7521030    /* Update the Header Control */
     
    8001078 * Prints a message for unsupported window styles.
    8011079 * A kind of TODO list for window styles.
    802  *
     1080 * 
    8031081 * PARAMETER(S):
    8041082 * [I] LONG : window style
     
    8091087static VOID LISTVIEW_UnsupportedStyles(LONG lStyle)
    8101088{
    811   if ((LVS_TYPEMASK & lStyle) == LVS_EDITLABELS)
    812   {
     1089  if ((LVS_TYPESTYLEMASK & lStyle) == LVS_NOSCROLL)
     1090    FIXME("  LVS_NOSCROLL\n");
     1091
     1092  if (lStyle & LVS_EDITLABELS)
    8131093    FIXME("  LVS_EDITLABELS\n");
    814   }
    815 
    816   if ((LVS_TYPEMASK & lStyle) == LVS_NOLABELWRAP)
    817   {
     1094
     1095  if (lStyle & LVS_NOLABELWRAP)
    8181096    FIXME("  LVS_NOLABELWRAP\n");
    819   }
    820 
    821   if ((LVS_TYPEMASK & lStyle) == LVS_NOSCROLL)
    822   {
    823     FIXME("  LVS_NOSCROLL\n");
    824   }
    825 
    826   if ((LVS_TYPEMASK & lStyle) == LVS_NOSORTHEADER)
    827   {
    828     FIXME("  LVS_NOSORTHEADER\n");
    829   }
    830 
    831   if ((LVS_TYPEMASK & lStyle) == LVS_OWNERDRAWFIXED)
    832   {
    833     FIXME("  LVS_OWNERDRAWFIXED\n");
    834   }
    835 
    836   if ((LVS_TYPEMASK & lStyle) == LVS_SHAREIMAGELISTS)
    837   {
     1097
     1098  if (lStyle & LVS_SHAREIMAGELISTS)
    8381099    FIXME("  LVS_SHAREIMAGELISTS\n");
    839   }
    840 
    841   if ((LVS_TYPEMASK & lStyle) == LVS_SORTASCENDING)
    842   {
     1100
     1101  if (lStyle & LVS_SORTASCENDING)
    8431102    FIXME("  LVS_SORTASCENDING\n");
    844   }
    845 
    846   if ((LVS_TYPEMASK & lStyle) == LVS_SORTDESCENDING)
    847   {
     1103
     1104  if (lStyle & LVS_SORTDESCENDING)
    8481105    FIXME("  LVS_SORTDESCENDING\n");
    849   }
    8501106}
    8511107
     
    8531109 * DESCRIPTION:
    8541110 * Aligns the items with the top edge of the window.
    855  *
     1111 * 
    8561112 * PARAMETER(S):
    8571113 * [I] HWND : window handle
     
    8621118static VOID LISTVIEW_AlignTop(HWND hwnd)
    8631119{
    864   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    865   UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
     1120  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     1121  UINT uView = GetWindowLongW(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    8661122  INT nListWidth = infoPtr->rcList.right - infoPtr->rcList.left;
    8671123  POINT ptItem;
    8681124  RECT rcView;
    869   INT i;
    870 
     1125  INT i, off_x=0, off_y=0;
     1126 
    8711127  if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
    8721128  {
    873     ZeroMemory(&ptItem, sizeof(POINT));
     1129    /* Since SetItemPosition uses upper-left of icon, and for
     1130       style=LVS_ICON the icon is not left adjusted, get the offset */
     1131    if (uView == LVS_ICON)
     1132    {
     1133      off_y = ICON_TOP_PADDING;
     1134      off_x = (infoPtr->iconSpacing.cx - infoPtr->iconSize.cx) / 2;
     1135    }
     1136    ptItem.x = off_x;
     1137    ptItem.y = off_y;
    8741138    ZeroMemory(&rcView, sizeof(RECT));
    8751139
     
    8801144        if (ptItem.x + infoPtr->nItemWidth > nListWidth)
    8811145        {
    882           ptItem.x = 0;
     1146          ptItem.x = off_x;
    8831147          ptItem.y += infoPtr->nItemHeight;
    8841148        }
    885 
    886         ListView_SetItemPosition(hwnd, i, ptItem.x, ptItem.y);
     1149       
     1150        LISTVIEW_SetItemPosition(hwnd, i, ptItem.x, ptItem.y);
    8871151        ptItem.x += infoPtr->nItemWidth;
    8881152        rcView.right = max(rcView.right, ptItem.x);
     
    8951159      for (i = 0; i < GETITEMCOUNT(infoPtr); i++)
    8961160      {
    897         ListView_SetItemPosition(hwnd, i, ptItem.x, ptItem.y);
     1161        LISTVIEW_SetItemPosition(hwnd, i, ptItem.x, ptItem.y);
    8981162        ptItem.y += infoPtr->nItemHeight;
    8991163      }
     
    9101174 * DESCRIPTION:
    9111175 * Aligns the items with the left edge of the window.
    912  *
     1176 * 
    9131177 * PARAMETER(S):
    9141178 * [I] HWND : window handle
     
    9191183static VOID LISTVIEW_AlignLeft(HWND hwnd)
    9201184{
    921   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    922   UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
     1185  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     1186  UINT uView = GetWindowLongW(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    9231187  INT nListHeight = infoPtr->rcList.bottom - infoPtr->rcList.top;
    9241188  POINT ptItem;
    9251189  RECT rcView;
    926   INT i;
    927 
     1190  INT i, off_x=0, off_y=0;
     1191 
    9281192  if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
    9291193  {
    930     ZeroMemory(&ptItem, sizeof(POINT));
     1194    /* Since SetItemPosition uses upper-left of icon, and for
     1195       style=LVS_ICON the icon is not left adjusted, get the offset */
     1196    if (uView == LVS_ICON)
     1197    {
     1198      off_y = ICON_TOP_PADDING;
     1199      off_x = (infoPtr->iconSpacing.cx - infoPtr->iconSize.cx) / 2;
     1200    }
     1201    ptItem.x = off_x;
     1202    ptItem.y = off_y;
    9311203    ZeroMemory(&rcView, sizeof(RECT));
    9321204
     
    9371209        if (ptItem.y + infoPtr->nItemHeight > nListHeight)
    9381210        {
    939           ptItem.y = 0;
     1211          ptItem.y = off_y;
    9401212          ptItem.x += infoPtr->nItemWidth;
    9411213        }
    9421214
    943         ListView_SetItemPosition(hwnd, i, ptItem.x, ptItem.y);
     1215        LISTVIEW_SetItemPosition(hwnd, i, ptItem.x, ptItem.y);
    9441216        ptItem.y += infoPtr->nItemHeight;
    9451217        rcView.bottom = max(rcView.bottom, ptItem.y);
     
    9521224      for (i = 0; i < GETITEMCOUNT(infoPtr); i++)
    9531225      {
    954         ListView_SetItemPosition(hwnd, i, ptItem.x, ptItem.y);
     1226        LISTVIEW_SetItemPosition(hwnd, i, ptItem.x, ptItem.y);
    9551227        ptItem.x += infoPtr->nItemWidth;
    9561228      }
     
    9671239 * DESCRIPTION:
    9681240 * Set the bounding rectangle of all the items.
    969  *
     1241 * 
    9701242 * PARAMETER(S):
    9711243 * [I] HWND : window handle
     
    9781250static LRESULT LISTVIEW_SetViewRect(HWND hwnd, LPRECT lprcView)
    9791251{
    980   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongA(hwnd, 0);
     1252  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongW(hwnd, 0);
    9811253  BOOL bResult = FALSE;
    9821254
    983   TRACE("(hwnd=%x, left=%d, top=%d, right=%d, bottom=%d)\n", hwnd,
     1255  TRACE("(hwnd=%x, left=%d, top=%d, right=%d, bottom=%d)\n", hwnd, 
    9841256        lprcView->left, lprcView->top, lprcView->right, lprcView->bottom);
    985 
     1257 
    9861258  if (lprcView != NULL)
    9871259  {
     
    9991271 * DESCRIPTION:
    10001272 * Retrieves the bounding rectangle of all the items.
    1001  *
     1273 * 
    10021274 * PARAMETER(S):
    10031275 * [I] HWND : window handle
     
    10101282static LRESULT LISTVIEW_GetViewRect(HWND hwnd, LPRECT lprcView)
    10111283{
    1012   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongA(hwnd, 0);
     1284  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongW(hwnd, 0);
    10131285  BOOL bResult = FALSE;
    10141286  POINT ptOrigin;
     
    10271299    }
    10281300
    1029     TRACE("(left=%d, top=%d, right=%d, bottom=%d)\n",
     1301    TRACE("(left=%d, top=%d, right=%d, bottom=%d)\n", 
    10301302          lprcView->left, lprcView->top, lprcView->right, lprcView->bottom);
    10311303  }
     
    10371309 * DESCRIPTION:
    10381310 * Retrieves the subitem pointer associated with the subitem index.
    1039  *
     1311 * 
    10401312 * PARAMETER(S):
    10411313 * [I] HDPA : DPA handle for a specific item
     
    10461318 *   FAILURE : NULL
    10471319 */
    1048 static LISTVIEW_SUBITEM* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems,
     1320static LISTVIEW_SUBITEM* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems, 
    10491321                                                INT nSubItem)
    10501322{
     
    10701342 * DESCRIPTION:
    10711343 * Calculates the width of an item.
    1072  *
     1344 * 
    10731345 * PARAMETER(S):
    10741346 * [I] HWND : window handle
     
    10801352static INT LISTVIEW_GetItemWidth(HWND hwnd)
    10811353{
    1082   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    1083   LONG style = GetWindowLongA(hwnd, GWL_STYLE);
    1084   UINT uView = style & LVS_TYPEMASK;
     1354  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     1355  LONG style = GetWindowLongW(hwnd, GWL_STYLE);
     1356  UINT uView = style & LVS_TYPEMASK; 
    10851357  INT nHeaderItemCount;
    10861358  RECT rcHeaderItem;
     
    11171389  {
    11181390    for (i = 0; i < GETITEMCOUNT(infoPtr); i++)
    1119     {
     1391    { 
    11201392      nLabelWidth = LISTVIEW_GetLabelWidth(hwnd, i);
    11211393      nItemWidth = max(nItemWidth, nLabelWidth);
    11221394    }
    1123 
     1395   
    11241396    /* default label size */
    11251397    if (GETITEMCOUNT(infoPtr) == 0)
     
    11371409        /* add padding */
    11381410        nItemWidth += WIDTH_PADDING;
    1139 
     1411     
    11401412        if (infoPtr->himlSmall != NULL)
    11411413        {
     
    11611433 * DESCRIPTION:
    11621434 * Calculates the width of a specific item.
    1163  *
    1164  * PARAMETER(S):
    1165  * [I] HWND : window handle
    1166  * [I] LPSTR : string
     1435 * 
     1436 * PARAMETER(S):
     1437 * [I] HWND : window handle
     1438 * [I] LPSTR : string 
    11671439 *
    11681440 * RETURN:
     
    11711443static INT LISTVIEW_CalculateWidth(HWND hwnd, INT nItem)
    11721444{
    1173   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    1174   UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
     1445  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     1446  UINT uView = GetWindowLongW(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    11751447  INT nHeaderItemCount;
    11761448  RECT rcHeaderItem;
     
    12161488        /* add padding */
    12171489        nItemWidth += WIDTH_PADDING;
    1218 
     1490     
    12191491        if (infoPtr->himlSmall != NULL)
    12201492        {
     
    12291501    }
    12301502  }
    1231 
     1503 
    12321504  return nItemWidth;
    12331505}
     
    12351507/***
    12361508 * DESCRIPTION:
     1509 * Retrieves and saves important text metrics info for the current
     1510 * Listview font.
     1511 *
     1512 * PARAMETER(S):
     1513 * [I] HWND : window handle
     1514 *
     1515 */
     1516static VOID LISTVIEW_SaveTextMetrics(HWND hwnd)
     1517{
     1518  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     1519  TEXTMETRICW tm;
     1520  HDC hdc = GetDC(hwnd);
     1521  HFONT hOldFont = SelectObject(hdc, infoPtr->hFont);
     1522  INT oldHeight, oldACW;
     1523
     1524  GetTextMetricsW(hdc, &tm);
     1525
     1526  oldHeight = infoPtr->ntmHeight;
     1527  oldACW = infoPtr->ntmAveCharWidth;
     1528  infoPtr->ntmHeight = tm.tmHeight;
     1529  infoPtr->ntmAveCharWidth = tm.tmAveCharWidth;
     1530
     1531  SelectObject(hdc, hOldFont);
     1532  ReleaseDC(hwnd, hdc);
     1533  TRACE("tmHeight old=%d,new=%d; tmAveCharWidth old=%d,new=%d\n",
     1534        oldHeight, infoPtr->ntmHeight, oldACW, infoPtr->ntmAveCharWidth);
     1535}
     1536
     1537
     1538/***
     1539 * DESCRIPTION:
    12371540 * Calculates the height of an item.
    1238  *
    1239  * PARAMETER(S):
    1240  * [I] HWND : window handle
    1241  * [I] LONG : window style
     1541 *
     1542 * PARAMETER(S):
     1543 * [I] HWND : window handle
    12421544 *
    12431545 * RETURN:
     
    12461548static INT LISTVIEW_GetItemHeight(HWND hwnd)
    12471549{
    1248   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     1550  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    12491551#ifdef __WIN32OS2__
    12501552  DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
     
    12611563  else
    12621564  {
    1263     TEXTMETRICA tm;
    1264     HDC hdc = GetDC(hwnd);
    1265     HFONT hOldFont = SelectObject(hdc, infoPtr->hFont);
    1266     GetTextMetricsA(hdc, &tm);
    1267 
    12681565    if(infoPtr->himlState || infoPtr->himlSmall)
    1269       nItemHeight = max(tm.tmHeight, infoPtr->iconSize.cy) + HEIGHT_PADDING;
     1566      nItemHeight = max(infoPtr->ntmHeight, infoPtr->iconSize.cy) + HEIGHT_PADDING;
    12701567    else
    1271       nItemHeight = tm.tmHeight;
    1272 
    1273     SelectObject(hdc, hOldFont);
    1274     ReleaseDC(hwnd, hdc);
     1568      nItemHeight = infoPtr->ntmHeight;
    12751569#ifdef __WIN32OS2__
    1276     if(dwStyle & LVS_OWNERDRAWFIXED) {
     1570  if(dwStyle & LVS_OWNERDRAWFIXED) {
    12771571        /* Get item height */
    12781572
     
    12901584#endif
    12911585  }
    1292 
    12931586  return nItemHeight;
    12941587}
     
    12971590static void LISTVIEW_PrintSelectionRanges(HWND hwnd)
    12981591{
    1299   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     1592  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    13001593  LISTVIEW_SELECTION *selection;
    13011594  INT topSelection = infoPtr->hdpaSelectionRanges->nItemCount;
     
    13241617 * 0 : if Item 1 == Item 2
    13251618 */
    1326 static INT CALLBACK LISTVIEW_CompareSelectionRanges(LPVOID range1, LPVOID range2,
     1619static INT CALLBACK LISTVIEW_CompareSelectionRanges(LPVOID range1, LPVOID range2, 
    13271620                                                    LPARAM flags)
    13281621{
     
    13301623  int l2 = ((LISTVIEW_SELECTION*)(range2))->lower;
    13311624  int u1 = ((LISTVIEW_SELECTION*)(range1))->upper;
    1332   int u2 = ((LISTVIEW_SELECTION*)(range2))->upper;
     1625  int u2 = ((LISTVIEW_SELECTION*)(range2))->upper; 
    13331626  int rc=0;
    13341627
    13351628  if (u1 < l2)
    13361629    rc= -1;
    1337 
     1630 
    13381631  if (u2 < l1)
    13391632     rc= 1;
     
    13451638* DESCRIPTION:
    13461639* Adds a selection range.
    1347 *
     1640* 
    13481641* PARAMETER(S):
    13491642* [I] HWND : window handle
    13501643* [I] INT : lower item index
    1351 * [I] INT : upper item index
     1644* [I] INT : upper item index 
    13521645*
    13531646* RETURN:
     
    13561649static VOID LISTVIEW_AddSelectionRange(HWND hwnd, INT lItem, INT uItem)
    13571650{
    1358  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     1651 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    13591652 LISTVIEW_SELECTION *selection;
    13601653 INT topSelection = infoPtr->hdpaSelectionRanges->nItemCount;
     
    13651658 selection->upper = uItem;
    13661659
    1367  TRACE("Add range %i - %i\n",lItem,uItem);
     1660 TRACE("Add range %i - %i\n", lItem, uItem);
    13681661 if (topSelection)
    13691662 {
     
    13831676                      LISTVIEW_CompareSelectionRanges,
    13841677                      0,0);
    1385    selection->upper --;
     1678   selection->upper --; 
    13861679   if (lowerzero)
    13871680     lowerzero=FALSE;
     
    13941687     TRACE("Merge with index %i (%lu - %lu)\n",index,checkselection->lower,
    13951688           checkselection->upper);
    1396 
     1689     
    13971690     checkselection->lower = min(selection->lower,checkselection->lower);
    13981691     checkselection->upper = max(selection->upper,checkselection->upper);
    1399 
    1400      TRACE("New range (%lu - %lu)\n", checkselection->lower,
     1692   
     1693     TRACE("New range (%lu - %lu)\n", checkselection->lower, 
    14011694           checkselection->upper);
    14021695
    1403      COMCTL32_Free(selection);
    1404 
     1696     COMCTL32_Free(selection);   
     1697 
    14051698     /* merge now common selection ranges in the lower group*/
    14061699     do
    14071700     {
    1408         checkselection->upper ++;
     1701        checkselection->upper ++; 
    14091702        if (checkselection->lower == 0)
    14101703          lowerzero = TRUE;
     
    14121705          checkselection->lower --;
    14131706
    1414         TRACE("search lower range (%lu - %lu)\n", checkselection->lower,
     1707        TRACE("search lower range (%lu - %lu)\n", checkselection->lower, 
    14151708              checkselection->upper);
    14161709
     
    14201713                                0);
    14211714
    1422         checkselection->upper --;
     1715        checkselection->upper --; 
    14231716        if (lowerzero)
    14241717          lowerzero = FALSE;
    14251718        else
    1426       checkselection->lower ++;
    1427 
    1428     if (mergeindex >=0  && mergeindex != index)
     1719          checkselection->lower ++;
     1720
     1721        if (mergeindex >=0  && mergeindex != index)
    14291722        {
    1430       TRACE("Merge with index %i\n",mergeindex);
     1723          TRACE("Merge with index %i\n",mergeindex);
    14311724          checkselection2 = DPA_GetPtr(infoPtr->hdpaSelectionRanges,
    14321725                                       mergeindex);
    1433           checkselection->lower = min(checkselection->lower,
     1726          checkselection->lower = min(checkselection->lower, 
    14341727                                      checkselection2->lower);
    14351728          checkselection->upper = max(checkselection->upper,
     
    14481741       if (checkselection->lower == 0)
    14491742         lowerzero = TRUE;
    1450        else
     1743       else 
    14511744         checkselection->lower --;
    14521745
    1453        TRACE("search upper range %i (%lu - %lu)\n",index,
     1746       TRACE("search upper range %i (%lu - %lu)\n",index, 
    14541747             checkselection->lower, checkselection->upper);
    14551748
     
    14571750       mergeindex = DPA_Search(infoPtr->hdpaSelectionRanges, checkselection,
    14581751                               index+1,
    1459                    LISTVIEW_CompareSelectionRanges, 0,
    1460                    0);
    1461 
    1462        checkselection->upper --;
     1752                               LISTVIEW_CompareSelectionRanges, 0,
     1753                               0);
     1754
     1755       checkselection->upper --; 
    14631756       if (lowerzero)
    14641757         lowerzero = FALSE;
     
    14681761       if (mergeindex >=0 && mergeindex !=index)
    14691762       {
    1470     TRACE("Merge with index %i\n",mergeindex);
    1471     checkselection2 = DPA_GetPtr(infoPtr->hdpaSelectionRanges,
    1472                       mergeindex);
    1473      checkselection->lower = min(checkselection->lower,
    1474                      checkselection2->lower);
    1475     checkselection->upper = max(checkselection->upper,
    1476                      checkselection2->upper);
    1477     COMCTL32_Free(checkselection2);
    1478     DPA_DeletePtr(infoPtr->hdpaSelectionRanges,mergeindex);
     1763        TRACE("Merge with index %i\n",mergeindex);
     1764        checkselection2 = DPA_GetPtr(infoPtr->hdpaSelectionRanges,
     1765                                      mergeindex);
     1766         checkselection->lower = min(checkselection->lower,
     1767                                     checkselection2->lower);
     1768        checkselection->upper = max(checkselection->upper,
     1769                                     checkselection2->upper);
     1770        COMCTL32_Free(checkselection2);
     1771        DPA_DeletePtr(infoPtr->hdpaSelectionRanges,mergeindex);
    14791772       }
    14801773    }
     
    14851778
    14861779     index = DPA_Search(infoPtr->hdpaSelectionRanges, selection, 0,
    1487                        LISTVIEW_CompareSelectionRanges, 0,
     1780                       LISTVIEW_CompareSelectionRanges, 0, 
    14881781                       DPAS_INSERTAFTER);
    14891782
     
    14911784     if (index == -1)
    14921785       index = 0;
    1493      DPA_InsertPtr(infoPtr->hdpaSelectionRanges,index,selection);
     1786     DPA_InsertPtr(infoPtr->hdpaSelectionRanges,index,selection); 
    14941787   }
    1495  }
     1788 } 
    14961789 else
    14971790 {
     
    14991792 }
    15001793 /*
    1501   * Incase of error
     1794  * Incase of error 
    15021795  */
    15031796 DPA_Sort(infoPtr->hdpaSelectionRanges,LISTVIEW_CompareSelectionRanges,0);
     
    15081801* DESCRIPTION:
    15091802* check if a specified index is selected.
    1510 *
     1803* 
    15111804* PARAMETER(S):
    15121805* [I] HWND : window handle
    1513 * [I] INT : item index
     1806* [I] INT : item index 
    15141807*
    15151808* RETURN:
     
    15181811static BOOL LISTVIEW_IsSelected(HWND hwnd, INT nItem)
    15191812{
    1520   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     1813  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    15211814  LISTVIEW_SELECTION selection;
    15221815  INT index;
     
    15471840static LRESULT LISTVIEW_RemoveAllSelections(HWND hwnd)
    15481841{
    1549   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     1842  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    15501843  LISTVIEW_SELECTION *selection;
    15511844  INT i;
    1552   LVITEMA item;
    1553 
     1845  LVITEMW item;
     1846 
    15541847  TRACE("(0x%x)\n",hwnd);
    15551848
    1556   ZeroMemory(&item,sizeof(LVITEMA));
     1849  ZeroMemory(&item,sizeof(item));
    15571850  item.stateMask = LVIS_SELECTED;
    15581851
     
    15671860      LISTVIEW_RemoveSelectionRange(hwnd,selection->lower,selection->upper);
    15681861    }
    1569   }
     1862  } 
    15701863  while (infoPtr->hdpaSelectionRanges->nItemCount>0);
    15711864
    15721865  TRACE("done\n");
    1573   return TRUE;
     1866  return TRUE; 
    15741867}
    15751868
     
    15771870* DESCRIPTION:
    15781871* Removes a range selections.
    1579 *
     1872* 
    15801873* PARAMETER(S):
    15811874* [I] HWND : window handle
    15821875* [I] INT : lower item index
    1583 * [I] INT : upper item index
     1876* [I] INT : upper item index 
    15841877*
    15851878* RETURN:
     
    15881881static VOID LISTVIEW_RemoveSelectionRange(HWND hwnd, INT lItem, INT uItem)
    15891882{
    1590   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     1883  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    15911884  LISTVIEW_SELECTION removeselection,*checkselection;
    15921885  INT index;
     
    16011894                     LISTVIEW_CompareSelectionRanges,
    16021895                     0,0);
    1603 
     1896 
    16041897  if (index == -1)
    16051898    return;
    16061899
    1607 
     1900 
    16081901  checkselection = DPA_GetPtr(infoPtr->hdpaSelectionRanges,
    16091902                              index);
     
    16131906
    16141907  /* case 1: Same */
    1615   if ((checkselection->upper == removeselection.upper) &&
     1908  if ((checkselection->upper == removeselection.upper) && 
    16161909     (checkselection->lower == removeselection.lower))
    16171910  {
     
    16201913  }
    16211914  /* case 2: engulf */
    1622   else if (((checkselection->upper < removeselection.upper) &&
     1915  else if (((checkselection->upper < removeselection.upper) && 
    16231916      (checkselection->lower > removeselection.lower))||
    16241917     ((checkselection->upper <= removeselection.upper) &&
     
    16581951    /* bisect the range */
    16591952    LISTVIEW_SELECTION *newselection;
    1660 
     1953   
    16611954    newselection = (LISTVIEW_SELECTION *)
    16621955                          COMCTL32_Alloc(sizeof(LISTVIEW_SELECTION));
     
    16741967* DESCRIPTION:
    16751968* Updates the various indices after an item has been inserted or deleted.
    1676 *
     1969* 
    16771970* PARAMETER(S):
    16781971* [I] HWND : window handle
    1679 * [I] INT : item index
     1972* [I] INT : item index 
    16801973* [I] INT : Direction of shift, +1 or -1.
    16811974*
     
    16851978static VOID LISTVIEW_ShiftIndices(HWND hwnd, INT nItem, INT direction)
    16861979{
    1687   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     1980  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    16881981  LISTVIEW_SELECTION selection,*checkselection;
    16891982  INT index;
     
    16981991                     0,DPAS_SORTED|DPAS_INSERTAFTER);
    16991992
    1700   while ((index < infoPtr->hdpaSelectionRanges->nItemCount)&&(index != -1))
     1993  while ((index < infoPtr->hdpaSelectionRanges->nItemCount)&&(index != -1)) 
    17011994  {
    17021995    checkselection = DPA_GetPtr(infoPtr->hdpaSelectionRanges,index);
     
    17422035 * DESCRIPTION:
    17432036 * Adds a block of selections.
    1744  *
    1745  * PARAMETER(S):
    1746  * [I] HWND : window handle
    1747  * [I] INT : item index
     2037 * 
     2038 * PARAMETER(S):
     2039 * [I] HWND : window handle
     2040 * [I] INT : item index 
    17482041 *
    17492042 * RETURN:
     
    17522045static VOID LISTVIEW_AddGroupSelection(HWND hwnd, INT nItem)
    17532046{
    1754   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     2047  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    17552048  INT nFirst = min(infoPtr->nSelectionMark, nItem);
    17562049  INT nLast = max(infoPtr->nSelectionMark, nItem);
    17572050  INT i;
    1758   LVITEMA item;
     2051  LVITEMW item;
    17592052
    17602053  if (nFirst == -1)
    17612054    nFirst = nItem;
    17622055
    1763   ZeroMemory(&item,sizeof(LVITEMA));
     2056  ZeroMemory(&item,sizeof(item));
    17642057  item.stateMask = LVIS_SELECTED;
    17652058  item.state = LVIS_SELECTED;
    17662059
    17672060  for (i = nFirst; i <= nLast; i++)
    1768   {
    17692061    LISTVIEW_SetItemState(hwnd,i,&item);
    1770   }
    17712062
    17722063  LISTVIEW_SetItemFocus(hwnd, nItem);
     
    17782069 * DESCRIPTION:
    17792070 * Adds a single selection.
    1780  *
    1781  * PARAMETER(S):
    1782  * [I] HWND : window handle
    1783  * [I] INT : item index
     2071 * 
     2072 * PARAMETER(S):
     2073 * [I] HWND : window handle
     2074 * [I] INT : item index 
    17842075 *
    17852076 * RETURN:
     
    17882079static VOID LISTVIEW_AddSelection(HWND hwnd, INT nItem)
    17892080{
    1790   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    1791   LVITEMA item;
    1792 
    1793   ZeroMemory(&item,sizeof(LVITEMA));
     2081  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     2082  LVITEMW item;
     2083
     2084  ZeroMemory(&item,sizeof(item));
    17942085  item.state = LVIS_SELECTED;
    17952086  item.stateMask = LVIS_SELECTED;
     
    18042095 * DESCRIPTION:
    18052096 * Selects or unselects an item.
    1806  *
    1807  * PARAMETER(S):
    1808  * [I] HWND : window handle
    1809  * [I] INT : item index
    1810  *
    1811  * RETURN:
    1812  *   SELECT: TRUE
     2097 * 
     2098 * PARAMETER(S):
     2099 * [I] HWND : window handle
     2100 * [I] INT : item index 
     2101 *
     2102 * RETURN:
     2103 *   SELECT: TRUE 
    18132104 *   UNSELECT : FALSE
    18142105 */
    18152106static BOOL LISTVIEW_ToggleSelection(HWND hwnd, INT nItem)
    18162107{
    1817   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     2108  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    18182109  BOOL bResult;
    1819   LVITEMA item;
    1820 
    1821   ZeroMemory(&item,sizeof(LVITEMA));
     2110  LVITEMW item;
     2111
     2112  ZeroMemory(&item,sizeof(item));
    18222113  item.stateMask = LVIS_SELECTED;
    18232114
    18242115  if (LISTVIEW_IsSelected(hwnd,nItem))
    18252116  {
    1826 
    18272117    LISTVIEW_SetItemState(hwnd,nItem,&item);
    18282118    bResult = FALSE;
     
    18432133/***
    18442134 * DESCRIPTION:
    1845  * Selects items based on view coordinates.
    1846  *
    1847  * PARAMETER(S):
    1848  * [I] HWND : window handle
    1849  * [I] RECT : selection rectangle
     2135 * Selects items based on view coordinates. 
     2136 * 
     2137 * PARAMETER(S):
     2138 * [I] HWND : window handle
     2139 * [I] RECT : selection rectangle 
    18502140 *
    18512141 * RETURN:
     
    18542144static VOID LISTVIEW_SetSelectionRect(HWND hwnd, RECT rcSelRect)
    18552145{
    1856   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     2146  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    18572147  POINT ptItem;
    18582148  INT i;
    1859   LVITEMA item;
    1860 
    1861   ZeroMemory(&item,sizeof(LVITEMA));
     2149  LVITEMW item;
     2150
     2151  ZeroMemory(&item,sizeof(item));
    18622152  item.stateMask = LVIS_SELECTED;
    18632153
     
    18672157
    18682158    if (PtInRect(&rcSelRect, ptItem) != FALSE)
    1869     {
    18702159      item.state = LVIS_SELECTED;
    1871       LISTVIEW_SetItemState(hwnd,i,&item);
    1872     }
    18732160    else
    1874     {
    18752161      item.state = 0;
    1876       LISTVIEW_SetItemState(hwnd,i,&item);
    1877     }
     2162    LISTVIEW_SetItemState(hwnd,i,&item);
    18782163  }
    18792164}
     
    18822167 * DESCRIPTION:
    18832168 * Sets a single group selection.
    1884  *
    1885  * PARAMETER(S):
    1886  * [I] HWND : window handle
    1887  * [I] INT : item index
    1888  *
    1889  * RETURN:
    1890  * None
     2169 * 
     2170 * PARAMETER(S):
     2171 * [I] HWND : window handle
     2172 * [I] INT : item index 
     2173 *
     2174 * RETURN:
     2175 * None 
    18912176 */
    18922177static VOID LISTVIEW_SetGroupSelection(HWND hwnd, INT nItem)
    18932178{
    1894   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    1895   UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    1896   LVITEMA item;
    1897 
    1898   ZeroMemory(&item,sizeof(LVITEMA));
     2179  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     2180  UINT uView = GetWindowLongW(hwnd, GWL_STYLE) & LVS_TYPEMASK;
     2181  LVITEMW item;
     2182
     2183  ZeroMemory(&item,sizeof(item));
    18992184  item.stateMask = LVIS_SELECTED;
    19002185
     
    19172202    {
    19182203      if ((i < nFirst) || (i > nLast))
    1919       {
    19202204        item.state = 0;
    1921         LISTVIEW_SetItemState(hwnd,i,&item);
    1922       }
    19232205      else
    1924       {
    19252206        item.state = LVIS_SELECTED;
    1926         LISTVIEW_SetItemState(hwnd,i,&item);
    1927       }
     2207      LISTVIEW_SetItemState(hwnd,i,&item);
    19282208    }
    19292209  }
    19302210  else
    19312211  {
    1932     POINT ptItem;
    1933     POINT ptSelMark;
     2212    RECT rcItem;
     2213    RECT rcSelMark;
    19342214    RECT rcSel;
    1935     LISTVIEW_GetItemPosition(hwnd, nItem, &ptItem);
    1936     LISTVIEW_GetItemPosition(hwnd, infoPtr->nSelectionMark, &ptSelMark);
    1937     rcSel.left = min(ptSelMark.x, ptItem.x);
    1938     rcSel.top = min(ptSelMark.y, ptItem.y);
    1939     rcSel.right = max(ptSelMark.x, ptItem.x) + infoPtr->nItemWidth;
    1940     rcSel.bottom = max(ptSelMark.y, ptItem.y) + infoPtr->nItemHeight;
     2215    LISTVIEW_GetItemBoundBox(hwnd, nItem, &rcItem);
     2216    LISTVIEW_GetItemBoundBox(hwnd, infoPtr->nSelectionMark, &rcSelMark);
     2217    rcSel.left = min(rcSelMark.left, rcItem.left);
     2218    rcSel.top = min(rcSelMark.top, rcItem.top);
     2219    rcSel.right = max(rcSelMark.right, rcItem.right);
     2220    rcSel.bottom = max(rcSelMark.bottom, rcItem.bottom);
    19412221    LISTVIEW_SetSelectionRect(hwnd, rcSel);
     2222    TRACE("item %d (%d,%d)-(%d,%d), mark %d (%d,%d)-(%d,%d), sel (%d,%d)-(%d,%d)\n",
     2223          nItem, rcItem.left, rcItem.top, rcItem.right, rcItem.bottom,
     2224          infoPtr->nSelectionMark,
     2225          rcSelMark.left, rcSelMark.top, rcSelMark.right, rcSelMark.bottom,
     2226          rcSel.left, rcSel.top, rcSel.right, rcSel.bottom);
     2227
    19422228  }
    19432229
     
    19482234 * DESCRIPTION:
    19492235 * Manages the item focus.
    1950  *
    1951  * PARAMETER(S):
    1952  * [I] HWND : window handle
    1953  * [I] INT : item index
     2236 * 
     2237 * PARAMETER(S):
     2238 * [I] HWND : window handle
     2239 * [I] INT : item index 
    19542240 *
    19552241 * RETURN:
     
    19592245static BOOL LISTVIEW_SetItemFocus(HWND hwnd, INT nItem)
    19602246{
    1961   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     2247  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    19622248  BOOL bResult = FALSE;
    1963   LVITEMA lvItem;
     2249  LVITEMW lvItem;
    19642250
    19652251  if (infoPtr->nFocusedItem != nItem)
     
    19702256      bResult = TRUE;
    19712257      infoPtr->nFocusedItem = -1;
    1972       ZeroMemory(&lvItem, sizeof(LVITEMA));
     2258      ZeroMemory(&lvItem, sizeof(lvItem));
    19732259      lvItem.stateMask = LVIS_FOCUSED;
    1974       ListView_SetItemState(hwnd, oldFocus, &lvItem);
     2260      ListView_SetItemState(hwnd, oldFocus, &lvItem); 
    19752261
    19762262    }
     
    19832269    ListView_EnsureVisible(hwnd, nItem, FALSE);
    19842270  }
    1985 
    1986   return bResult;
     2271 
     2272  return bResult; 
    19872273}
    19882274
     
    19902276 * DESCRIPTION:
    19912277 * Sets a single selection.
    1992  *
    1993  * PARAMETER(S):
    1994  * [I] HWND : window handle
    1995  * [I] INT : item index
     2278 * 
     2279 * PARAMETER(S):
     2280 * [I] HWND : window handle
     2281 * [I] INT : item index 
    19962282 *
    19972283 * RETURN:
     
    20002286static VOID LISTVIEW_SetSelection(HWND hwnd, INT nItem)
    20012287{
    2002   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    2003   LVITEMA lvItem;
    2004 
    2005   ZeroMemory(&lvItem, sizeof(LVITEMA));
     2288  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     2289  LVITEMW lvItem;
     2290
     2291  ZeroMemory(&lvItem, sizeof(lvItem));
    20062292  lvItem.stateMask = LVIS_FOCUSED;
    2007   ListView_SetItemState(hwnd, infoPtr->nFocusedItem, &lvItem);
     2293  ListView_SetItemState(hwnd, infoPtr->nFocusedItem, &lvItem); 
    20082294
    20092295  LISTVIEW_RemoveAllSelections(hwnd);
     
    20202306 * DESCRIPTION:
    20212307 * Set selection(s) with keyboard.
    2022  *
    2023  * PARAMETER(S):
    2024  * [I] HWND : window handle
    2025  * [I] INT : item index
     2308 * 
     2309 * PARAMETER(S):
     2310 * [I] HWND : window handle
     2311 * [I] INT : item index 
    20262312 *
    20272313 * RETURN:
     
    20312317static BOOL LISTVIEW_KeySelection(HWND hwnd, INT nItem)
    20322318{
    2033   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    2034   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     2319  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     2320  LONG lStyle = GetWindowLongW(hwnd, GWL_STYLE);
    20352321  WORD wShift = HIWORD(GetKeyState(VK_SHIFT));
    20362322  WORD wCtrl = HIWORD(GetKeyState(VK_CONTROL));
     
    20422328    {
    20432329      bResult = TRUE;
    2044       LISTVIEW_SetSelection(hwnd, nItem);
     2330      LISTVIEW_SetSelection(hwnd, nItem); 
    20452331      ListView_EnsureVisible(hwnd, nItem, FALSE);
    20462332    }
     
    20502336      {
    20512337        bResult = TRUE;
    2052         LISTVIEW_SetGroupSelection(hwnd, nItem);
     2338        LISTVIEW_SetGroupSelection(hwnd, nItem); 
    20532339      }
    20542340      else if (wCtrl)
     
    20592345      {
    20602346        bResult = TRUE;
    2061         LISTVIEW_SetSelection(hwnd, nItem);
     2347        LISTVIEW_SetSelection(hwnd, nItem); 
    20622348        ListView_EnsureVisible(hwnd, nItem, FALSE);
    20632349      }
     
    20842370 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
    20852371 * over the item for a certain period of time.
    2086  *
     2372 * 
    20872373 */
    20882374static LRESULT LISTVIEW_MouseHover(HWND hwnd, WPARAM wParam, LPARAM lParam)
    20892375{
    2090   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     2376  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    20912377  POINT pt;
    20922378
     
    21162402static LRESULT LISTVIEW_MouseMove(HWND hwnd, WPARAM wParam, LPARAM lParam)
    21172403{
    2118   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     2404  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    21192405  TRACKMOUSEEVENT trackinfo;
    2120 
     2406 
    21212407  /* see if we are supposed to be tracking mouse hovering */
    21222408  if(infoPtr->dwExStyle & LVS_EX_TRACKSELECT) {
     
    21372423    }
    21382424  }
    2139 
     2425 
    21402426  return 0;
    21412427}
     
    21442430 * DESCRIPTION:
    21452431 * Selects an item based on coordinates.
    2146  *
     2432 * 
    21472433 * PARAMETER(S):
    21482434 * [I] HWND : window handle
     
    21552441static LRESULT LISTVIEW_MouseSelection(HWND hwnd, POINT pt)
    21562442{
    2157   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     2443  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    21582444  RECT rcItem;
    21592445  INT i,topindex,bottomindex;
    2160   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     2446  LONG lStyle = GetWindowLongW(hwnd, GWL_STYLE);
    21612447  UINT uView = lStyle & LVS_TYPEMASK;
    21622448
     
    21642450  if (uView == LVS_REPORT)
    21652451  {
    2166     bottomindex = topindex + LISTVIEW_GetCountPerColumn(hwnd) + 1;
     2452    bottomindex = topindex + LISTVIEW_GetCountPerColumn(hwnd) + 1; 
    21672453    bottomindex = min(bottomindex,GETITEMCOUNT(infoPtr));
    21682454  }
     
    21722458  }
    21732459
    2174   for (i = topindex; i < bottomindex; i++)
     2460  for (i = topindex; i < bottomindex; i++) 
    21752461  {
    21762462    rcItem.left = LVIR_SELECTBOUNDS;
     
    21902476 * DESCRIPTION:
    21912477 * Removes a column.
    2192  *
     2478 * 
    21932479 * PARAMETER(S):
    21942480 * [IO] HDPA : dynamic pointer array handle
     
    22162502    }
    22172503  }
    2218 
     2504   
    22192505  return bResult;
    22202506}
     
    22232509 * DESCRIPTION:
    22242510 * Removes a subitem at a given position.
    2225  *
     2511 * 
    22262512 * PARAMETER(S):
    22272513 * [IO] HDPA : dynamic pointer array handle
     
    22452531      {
    22462532        /* free string */
    2247         if ((lpSubItem->pszText != NULL) &&
    2248             (lpSubItem->pszText != LPSTR_TEXTCALLBACKA))
    2249         {
     2533        if (is_textW(lpSubItem->pszText))
    22502534          COMCTL32_Free(lpSubItem->pszText);
    2251         }
    2252 
     2535       
    22532536        /* free item */
    22542537        COMCTL32_Free(lpSubItem);
     
    22562539        /* free dpa memory */
    22572540        if (DPA_DeletePtr(hdpaSubItems, i) == NULL)
    2258         {
    22592541          return FALSE;
    2260         }
    22612542      }
    22622543      else if (lpSubItem->iSubItem > nSubItem)
    2263       {
    22642544        return TRUE;
    2265       }
    2266     }
    2267   }
    2268 
     2545    }
     2546  }   
     2547 
    22692548  return TRUE;
    22702549}
     
    22732552 * DESCRIPTION:
    22742553 * Compares the item information.
    2275  *
    2276  * PARAMETER(S):
    2277  * [I] LISTVIEW_ITEM *: destination item
     2554 * 
     2555 * PARAMETER(S):
     2556 * [I] LISTVIEW_ITEM *: destination item 
    22782557 * [I] LPLVITEM : source item
     2558 * [I] isW : TRUE if lpLVItem is Unicode, FALSE it it's ANSI
    22792559 *
    22802560 * RETURN:
     
    22832563 */
    22842564#ifdef __WIN32OS2__
    2285 static UINT LISTVIEW_GetItemChanges(LISTVIEW_ITEM *lpItem, LPLVITEMA lpLVItem, DWORD lStyle)
     2565static UINT LISTVIEW_GetItemChangesT(LISTVIEW_ITEM *lpItem, LPLVITEMW lpLVItem, BOOL isW, DWORD lStyle)
    22862566#else
    2287 static UINT LISTVIEW_GetItemChanges(LISTVIEW_ITEM *lpItem, LPLVITEMA lpLVItem)
     2567static UINT LISTVIEW_GetItemChangesT(LISTVIEW_ITEM *lpItem, LPLVITEMW lpLVItem, BOOL isW)
    22882568#endif
    22892569{
     
    22942574    if (lpLVItem->mask & LVIF_STATE)
    22952575    {
    2296       if ((lpItem->state & lpLVItem->stateMask) !=
     2576      if ((lpItem->state & lpLVItem->stateMask) != 
    22972577          (lpLVItem->state & lpLVItem->stateMask))
     2578        uChanged |= LVIF_STATE;
     2579    }
     2580
     2581    if (lpLVItem->mask & LVIF_IMAGE)
     2582    {
     2583      if (lpItem->iImage != lpLVItem->iImage)
     2584        uChanged |= LVIF_IMAGE;
     2585    }
     2586 
     2587    if (lpLVItem->mask & LVIF_PARAM)
     2588    {
     2589      if (lpItem->lParam != lpLVItem->lParam)
     2590        uChanged |= LVIF_PARAM;
     2591    }
     2592   
     2593    if (lpLVItem->mask & LVIF_INDENT)
     2594    {
     2595      if (lpItem->iIndent != lpLVItem->iIndent)
     2596        uChanged |= LVIF_INDENT;
     2597    }
     2598
     2599    if (lpLVItem->mask & LVIF_TEXT)
     2600    {
     2601      if (lpLVItem->pszText == LPSTR_TEXTCALLBACKW)
    22982602      {
    2299         uChanged |= LVIF_STATE;
    2300       }
    2301     }
    2302 
    2303     if (lpLVItem->mask & LVIF_IMAGE)
    2304     {
    2305       if (lpItem->iImage != lpLVItem->iImage)
    2306       {
    2307         uChanged |= LVIF_IMAGE;
    2308       }
    2309     }
    2310 
    2311     if (lpLVItem->mask & LVIF_PARAM)
    2312     {
    2313       if (lpItem->lParam != lpLVItem->lParam)
    2314       {
    2315         uChanged |= LVIF_PARAM;
    2316       }
    2317     }
    2318 
    2319     if (lpLVItem->mask & LVIF_INDENT)
    2320     {
    2321       if (lpItem->iIndent != lpLVItem->iIndent)
    2322       {
    2323         uChanged |= LVIF_INDENT;
    2324       }
    2325     }
    2326 
    2327     if (lpLVItem->mask & LVIF_TEXT)
    2328     {
    2329       if (lpLVItem->pszText == LPSTR_TEXTCALLBACKA)
    2330       {
    2331         if (lpItem->pszText != LPSTR_TEXTCALLBACKA)
    2332         {
    2333           uChanged |= LVIF_TEXT;
    2334         }
     2603        if (lpItem->pszText != LPSTR_TEXTCALLBACKW)
     2604          uChanged |= LVIF_TEXT;
    23352605      }
    23362606      else
    23372607      {
    2338         if (lpItem->pszText == LPSTR_TEXTCALLBACKA)
     2608        if (lpItem->pszText == LPSTR_TEXTCALLBACKW)
    23392609        {
    2340           uChanged |= LVIF_TEXT;
     2610          uChanged |= LVIF_TEXT; 
    23412611        }
    2342     else
    2343     {
    2344       if (lpLVItem->pszText)
    2345       {
     2612        else
     2613        {
     2614          if (lpLVItem->pszText)
     2615          {
    23462616#ifdef __WIN32OS2__
    23472617        if(lStyle & LVS_OWNERDRAWFIXED) {
     
    23552625        else
    23562626#endif
    2357         if (lpItem->pszText)
    2358         {
    2359           if (strcmp(lpLVItem->pszText, lpItem->pszText) != 0)
    2360           {
    2361         uChanged |= LVIF_TEXT;
    2362           }
    2363         }
    2364         else
    2365         {
    2366           uChanged |= LVIF_TEXT;
    2367         }
     2627            if (lpItem->pszText)
     2628            {
     2629              LPWSTR pszText = textdupTtoW(lpLVItem->pszText, isW);
     2630              if (pszText && strcmpW(pszText, lpItem->pszText))
     2631                uChanged |= LVIF_TEXT;
     2632              textfreeT(pszText, isW);
     2633            }
     2634            else
     2635            {
     2636              uChanged |= LVIF_TEXT;
     2637            }
     2638          }
     2639          else
     2640          {
     2641            if (lpItem->pszText)
     2642              uChanged |= LVIF_TEXT;
     2643          }
     2644        }
    23682645      }
    2369       else
    2370       {
    2371         if (lpItem->pszText)
    2372         {
    2373           uChanged |= LVIF_TEXT;
    2374         }
    2375       }
    2376     }
    2377       }
    23782646    }
    23792647  }
     
    23842652 * DESCRIPTION:
    23852653 * Initializes item attributes.
    2386  *
    2387  * PARAMETER(S):
    2388  * [I] HWND : window handle
    2389  * [O] LISTVIEW_ITEM *: destination item
    2390  * [I] LPLVITEM : source item
     2654 *
     2655 * PARAMETER(S):
     2656 * [I] HWND : window handle
     2657 * [O] LISTVIEW_ITEM *: destination item
     2658 * [I] LPLVITEM : source item
     2659 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
    23912660 *
    23922661 * RETURN:
     
    23942663 *   FAILURE : FALSE
    23952664 */
    2396 static BOOL LISTVIEW_InitItem(HWND hwnd, LISTVIEW_ITEM *lpItem,
    2397                               LPLVITEMA lpLVItem)
    2398 {
    2399   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     2665static BOOL LISTVIEW_InitItemT(HWND hwnd, LISTVIEW_ITEM *lpItem,
     2666                              LPLVITEMW lpLVItem, BOOL isW)
     2667{
     2668  LONG lStyle = GetWindowLongW(hwnd, GWL_STYLE);
    24002669  BOOL bResult = FALSE;
    24012670
     
    24032672  {
    24042673    bResult = TRUE;
    2405 
     2674   
    24062675    if (lpLVItem->mask & LVIF_STATE)
    24072676    {
     
    24092678      lpItem->state |= (lpLVItem->state & lpLVItem->stateMask);
    24102679    }
    2411 
     2680   
    24122681    if (lpLVItem->mask & LVIF_IMAGE)
    2413     {
    24142682      lpItem->iImage = lpLVItem->iImage;
    2415     }
    2416 
     2683 
    24172684    if (lpLVItem->mask & LVIF_PARAM)
    2418     {
    24192685      lpItem->lParam = lpLVItem->lParam;
    2420     }
    2421 
     2686   
    24222687    if (lpLVItem->mask & LVIF_INDENT)
    2423     {
    24242688      lpItem->iIndent = lpLVItem->iIndent;
    2425     }
    2426 
    2427     if (lpLVItem->mask & LVIF_TEXT)
    2428     {
    2429       if (lpLVItem->pszText == LPSTR_TEXTCALLBACKA)
     2689
     2690    if (lpLVItem->mask & LVIF_TEXT)
     2691    {
     2692      if (lpLVItem->pszText == LPSTR_TEXTCALLBACKW)
    24302693      {
    24312694        if ((lStyle & LVS_SORTASCENDING) || (lStyle & LVS_SORTDESCENDING))
    2432         {
    24332695          return FALSE;
    2434         }
    2435 
    2436         if ((lpItem->pszText != NULL) &&
    2437             (lpItem->pszText != LPSTR_TEXTCALLBACKA))
    2438         {
     2696
     2697        if (is_textW(lpItem->pszText))
    24392698          COMCTL32_Free(lpItem->pszText);
    2440         }
    2441 
    2442         lpItem->pszText = LPSTR_TEXTCALLBACKA;
     2699   
     2700        lpItem->pszText = LPSTR_TEXTCALLBACKW;
    24432701      }
    2444       else
    2445       {
    2446         if (lpItem->pszText == LPSTR_TEXTCALLBACKA)
    2447         {
    2448           lpItem->pszText = NULL;
    2449         }
    2450 
    2451         bResult = Str_SetPtrA(&lpItem->pszText, lpLVItem->pszText);
    2452       }
     2702      else
     2703        bResult = textsetptrT(&lpItem->pszText, lpLVItem->pszText, isW);
    24532704    }
    24542705  }
     
    24682719 * [O] LISTVIEW_SUBITEM *: destination subitem
    24692720 * [I] LPLVITEM : source subitem
     2721 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
    24702722 *
    24712723 * RETURN:
     
    24732725 *   FAILURE : FALSE
    24742726 */
    2475 static BOOL LISTVIEW_InitSubItem(HWND hwnd, LISTVIEW_SUBITEM *lpSubItem,
    2476                                    LPLVITEMA lpLVItem)
    2477 {
    2478   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     2727static BOOL LISTVIEW_InitSubItemT(HWND hwnd, LISTVIEW_SUBITEM *lpSubItem,
     2728                                  LPLVITEMW lpLVItem, BOOL isW)
     2729{
     2730  LONG lStyle = GetWindowLongW(hwnd, GWL_STYLE);
    24792731  BOOL bResult = FALSE;
    2480 
     2732 
     2733  TRACE("(hwnd=%x, lpSubItem=%p, lpLVItem=%s, isW=%d)\n",
     2734        hwnd, lpSubItem, debuglvitem_t(lpLVItem, isW), isW);
     2735 
    24812736  if ((lpSubItem != NULL) && (lpLVItem != NULL))
    24822737  {
     
    24882743
    24892744      if (lpLVItem->mask & LVIF_IMAGE)
     2745        lpSubItem->iImage = lpLVItem->iImage;
     2746     
     2747      if (lpLVItem->mask & LVIF_TEXT)
    24902748      {
    2491         lpSubItem->iImage = lpLVItem->iImage;
    2492       }
    2493 
    2494       if (lpLVItem->mask & LVIF_TEXT)
    2495       {
    2496         if (lpLVItem->pszText == LPSTR_TEXTCALLBACKA)
     2749        if (lpLVItem->pszText == LPSTR_TEXTCALLBACKW)
    24972750        {
    24982751          if ((lStyle & LVS_SORTASCENDING) || (lStyle & LVS_SORTDESCENDING))
    2499           {
    25002752            return FALSE;
    2501           }
    2502 
    2503           if ((lpSubItem->pszText != NULL) &&
    2504               (lpSubItem->pszText != LPSTR_TEXTCALLBACKA))
    2505           {
     2753
     2754          if (is_textW(lpSubItem->pszText))
    25062755            COMCTL32_Free(lpSubItem->pszText);
    2507           }
    2508 
    2509           lpSubItem->pszText = LPSTR_TEXTCALLBACKA;
     2756   
     2757          lpSubItem->pszText = LPSTR_TEXTCALLBACKW;
    25102758        }
    2511         else
    2512         {
    2513           if (lpSubItem->pszText == LPSTR_TEXTCALLBACKA)
    2514           {
    2515             lpSubItem->pszText = NULL;
    2516           }
    2517 #ifdef __WIN32OS2__
    2518           else {
    2519              //No need to change anything if text is the same
    2520              if(lpSubItem->pszText && !strcmp(lpSubItem->pszText, lpLVItem->pszText)) {
    2521                  return FALSE;
    2522              }
    2523           }
    2524 #endif
    2525           bResult = Str_SetPtrA(&lpSubItem->pszText, lpLVItem->pszText);
    2526         }
     2759        else
     2760          bResult = textsetptrT(&lpSubItem->pszText, lpLVItem->pszText, isW);
    25272761      }
    25282762    }
     
    25352769 * DESCRIPTION:
    25362770 * Adds a subitem at a given position (column index).
    2537  *
    2538  * PARAMETER(S):
    2539  * [I] HWND : window handle
    2540  * [I] LPLVITEM : new subitem atttributes
     2771 *
     2772 * PARAMETER(S):
     2773 * [I] HWND : window handle
     2774 * [I] LPLVITEM : new subitem atttributes
     2775 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
    25412776 *
    25422777 * RETURN:
     
    25442779 *   FAILURE : FALSE
    25452780 */
    2546 static BOOL LISTVIEW_AddSubItem(HWND hwnd, LPLVITEMA lpLVItem)
    2547 {
    2548   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     2781static BOOL LISTVIEW_AddSubItemT(HWND hwnd, LPLVITEMW lpLVItem, BOOL isW)
     2782{
     2783  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    25492784  LISTVIEW_SUBITEM *lpSubItem = NULL;
    25502785  BOOL bResult = FALSE;
    25512786  HDPA hdpaSubItems;
    25522787  INT nPosition, nItem;
    2553   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
    2554 
     2788  LONG lStyle = GetWindowLongW(hwnd, GWL_STYLE);
     2789
     2790  TRACE("(hwnd=%x, lpLVItem=%s, isW=%d)\n", hwnd, debuglvitem_t(lpLVItem, isW), isW);
     2791 
    25552792  if (lStyle & LVS_OWNERDATA)
    25562793    return FALSE;
     
    25642801      if (lpSubItem != NULL)
    25652802      {
    2566     ZeroMemory(lpSubItem, sizeof(LISTVIEW_SUBITEM));
    2567         if (LISTVIEW_InitSubItem(hwnd, lpSubItem, lpLVItem) != FALSE)
     2803        ZeroMemory(lpSubItem, sizeof(LISTVIEW_SUBITEM));
     2804        if (LISTVIEW_InitSubItemT(hwnd, lpSubItem, lpLVItem, isW))
    25682805        {
    2569           nPosition = LISTVIEW_FindInsertPosition(hdpaSubItems,
     2806          nPosition = LISTVIEW_FindInsertPosition(hdpaSubItems, 
    25702807                                                  lpSubItem->iSubItem);
    25712808          nItem = DPA_InsertPtr(hdpaSubItems, nPosition, lpSubItem);
    2572           if (nItem != -1)
    2573           {
    2574             bResult = TRUE;
    2575           }
     2809          if (nItem != -1) bResult = TRUE;
    25762810        }
    25772811      }
    25782812    }
    25792813  }
    2580 
    2581   /* cleanup if unsuccessful */
    2582   if ((bResult == FALSE) && (lpSubItem != NULL))
    2583   {
    2584     COMCTL32_Free(lpSubItem);
    2585   }
    2586 
     2814 
     2815  /* cleanup if unsuccessful */   
     2816  if (!bResult && lpSubItem) COMCTL32_Free(lpSubItem);
     2817 
    25872818  return bResult;
    25882819}
     
    25912822 * DESCRIPTION:
    25922823 * Finds the dpa insert position (array index).
    2593  *
     2824 * 
    25942825 * PARAMETER(S):
    25952826 * [I] HWND : window handle
     
    26082839  {
    26092840    lpSubItem = (LISTVIEW_SUBITEM *)DPA_GetPtr(hdpaSubItems, i);
    2610     if (lpSubItem != NULL)
    2611     {
    2612       if (lpSubItem->iSubItem > nSubItem)
    2613       {
    2614         return i;
    2615       }
    2616     }
     2841    if (lpSubItem && lpSubItem->iSubItem > nSubItem)
     2842      return i;
    26172843  }
    26182844
     
    26232849 * DESCRIPTION:
    26242850 * Retrieves a listview subitem at a given position (column index).
    2625  *
     2851 * 
    26262852 * PARAMETER(S):
    26272853 * [I] HWND : window handle
     
    26432869    {
    26442870      if (lpSubItem->iSubItem == nSubItem)
    2645       {
    26462871        return lpSubItem;
    2647       }
    26482872      else if (lpSubItem->iSubItem > nSubItem)
    2649       {
    26502873        return NULL;
    2651       }
    2652     }
    2653   }
    2654 
     2874    }
     2875  }
     2876 
    26552877  return NULL;
    26562878}
     
    26592881 * DESCRIPTION:
    26602882 * Sets item attributes.
    2661  *
    2662  * PARAMETER(S):
    2663  * [I] HWND : window handle
    2664  * [I] LPLVITEM : new item atttributes
     2883 *
     2884 * PARAMETER(S):
     2885 * [I] HWND : window handle
     2886 * [I] LPLVITEM : new item atttributes
     2887 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
    26652888 *
    26662889 * RETURN:
     
    26682891 *   FAILURE : FALSE
    26692892 */
    2670 static BOOL LISTVIEW_SetItem(HWND hwnd, LPLVITEMA lpLVItem)
    2671 {
    2672   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     2893static BOOL LISTVIEW_SetMainItemT(HWND hwnd, LPLVITEMW lpLVItem, BOOL isW)
     2894{
     2895  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    26732896  BOOL bResult = FALSE;
    26742897  HDPA hdpaSubItems;
    26752898  LISTVIEW_ITEM *lpItem;
    26762899  NMLISTVIEW nmlv;
    2677   LONG lCtrlId = GetWindowLongA(hwnd, GWL_ID);
    2678   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     2900  LONG lStyle = GetWindowLongW(hwnd, GWL_STYLE);
    26792901  UINT uChanged;
    26802902  UINT uView = lStyle & LVS_TYPEMASK;
     
    26822904  RECT rcItem;
    26832905
     2906  TRACE("(hwnd=%x, lpLVItem=%s, isW=%d)\n", hwnd, debuglvitem_t(lpLVItem, isW), isW);
     2907   
    26842908  if (lStyle & LVS_OWNERDATA)
    26852909  {
    26862910    if ((lpLVItem->iSubItem == 0)&&(lpLVItem->mask == LVIF_STATE))
    26872911    {
    2688       LVITEMA itm;
    2689 
    2690       ZeroMemory(&itm,sizeof(LVITEMA));
     2912      LVITEMW itm;
     2913
     2914      ZeroMemory(&itm, sizeof(itm));
    26912915      itm.mask = LVIF_STATE | LVIF_PARAM;
    26922916      itm.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
    26932917      itm.iItem = lpLVItem->iItem;
    26942918      itm.iSubItem = 0;
    2695       ListView_GetItemA(hwnd,&itm);
    2696 
     2919      ListView_GetItemW(hwnd, &itm);
     2920     
    26972921
    26982922      ZeroMemory(&nmlv, sizeof(NMLISTVIEW));
    2699       nmlv.hdr.hwndFrom = hwnd;
    2700       nmlv.hdr.idFrom = lCtrlId;
    2701       nmlv.hdr.code = LVN_ITEMCHANGING;
    27022923      nmlv.uNewState = lpLVItem->state;
    27032924      nmlv.uOldState = itm.state;
     
    27062927      nmlv.iItem = lpLVItem->iItem;
    27072928
    2708       if ((itm.state & lpLVItem->stateMask) !=
     2929      if ((itm.state & lpLVItem->stateMask) != 
    27092930          (lpLVItem->state & lpLVItem->stateMask))
    27102931      {
    27112932        /* send LVN_ITEMCHANGING notification */
    2712         if (!ListView_LVNotify(GetParent(hwnd), lCtrlId, &nmlv))
     2933        if (!listview_notify(hwnd, LVN_ITEMCHANGING, &nmlv))
    27132934        {
    27142935          if (lpLVItem->stateMask & LVIS_FOCUSED)
     
    27232944            if (lpLVItem->state & LVIS_SELECTED)
    27242945            {
    2725                 if (lStyle & LVS_SINGLESEL)
    2726                 {
    2727                   LISTVIEW_RemoveAllSelections(hwnd);
    2728                 }
     2946              if (lStyle & LVS_SINGLESEL) LISTVIEW_RemoveAllSelections(hwnd);
    27292947              LISTVIEW_AddSelectionRange(hwnd,lpLVItem->iItem,lpLVItem->iItem);
    27302948            }
     
    27342952          }
    27352953
    2736           nmlv.hdr.code = LVN_ITEMCHANGED;
    2737 
    2738           ListView_LVNotify(GetParent(hwnd), lCtrlId, &nmlv);
    2739 
    2740       rcItem.left = LVIR_BOUNDS;
    2741       LISTVIEW_GetItemRect(hwnd, lpLVItem->iItem, &rcItem);
     2954          listview_notify(hwnd, LVN_ITEMCHANGED, &nmlv);
     2955
     2956          rcItem.left = LVIR_BOUNDS;
     2957          LISTVIEW_GetItemRect(hwnd, lpLVItem->iItem, &rcItem);
    27422958#ifdef __WIN32OS2__
    2743           if(lStyle & LVS_OWNERDRAWFIXED && rcItem.left == REPORT_MARGINX) {
    2744               rcItem.left = 0;
    2745           }
     2959            if(lStyle & LVS_OWNERDRAWFIXED && rcItem.left == REPORT_MARGINX) {
     2960               rcItem.left = 0;
     2961            }
    27462962#endif
    2747       InvalidateRect(hwnd, &rcItem, TRUE);
     2963          InvalidateRect(hwnd, &rcItem, TRUE);
    27482964        }
    27492965      }
     
    27642980        {
    27652981          ZeroMemory(&nmlv, sizeof(NMLISTVIEW));
    2766           nmlv.hdr.hwndFrom = hwnd;
    2767           nmlv.hdr.idFrom = lCtrlId;
    2768           nmlv.hdr.code = LVN_ITEMCHANGING;
    27692982          nmlv.lParam = lpItem->lParam;
    27702983#ifdef __WIN32OS2__
    2771           uChanged = LISTVIEW_GetItemChanges(lpItem, lpLVItem, lStyle);
     2984          uChanged = LISTVIEW_GetItemChangesT(lpItem, lpLVItem, isW, lStyle);
    27722985#else
    2773           uChanged = LISTVIEW_GetItemChanges(lpItem, lpLVItem);
     2986          uChanged = LISTVIEW_GetItemChangesT(lpItem, lpLVItem, isW);
    27742987#endif
    27752988          if (uChanged != 0)
     
    27893002                 */
    27903003                if (lStyle & LVS_SINGLESEL)
    2791                 {
    27923004                  LISTVIEW_RemoveAllSelections(hwnd);
    2793                 }
    2794 
    2795             LISTVIEW_AddSelectionRange(hwnd,lpLVItem->iItem,
     3005
     3006                LISTVIEW_AddSelectionRange(hwnd,lpLVItem->iItem,
    27963007                                             lpLVItem->iItem);
    27973008              }
     
    28013012                                              lpLVItem->iItem);
    28023013              }
    2803           if (nmlv.uNewState & LVIS_FOCUSED)
     3014              if (nmlv.uNewState & LVIS_FOCUSED)
    28043015              {
    28053016                /*
    28063017                 * This is a fun hoop to jump to try to catch if
    28073018                 * the user is calling us directly to call focus or if
    2808                  * this function is being called as a result of a
    2809                  * SetItemFocus call.
     3019                 * this function is being called as a result of a 
     3020                 * SetItemFocus call. 
    28103021                 */
    28113022#ifdef __WIN32OS2__
     
    28203031                  LISTVIEW_SetItemFocus(hwnd, lpLVItem->iItem);
    28213032#endif
    2822               }
     3033              }           
    28233034            }
    2824 
     3035           
    28253036            nmlv.uChanged = uChanged;
    28263037            nmlv.iItem = lpLVItem->iItem;
    28273038            nmlv.lParam = lpItem->lParam;
    28283039            /* send LVN_ITEMCHANGING notification */
    2829             ListView_LVNotify(GetParent(hwnd), lCtrlId, &nmlv);
     3040            listview_notify(hwnd, LVN_ITEMCHANGING, &nmlv);
    28303041
    28313042            /* copy information */
    2832             bResult = LISTVIEW_InitItem(hwnd, lpItem, lpLVItem);
     3043            bResult = LISTVIEW_InitItemT(hwnd, lpItem, lpLVItem, isW);
    28333044
    28343045            /* if LVS_LIST or LVS_SMALLICON, update the width of the items
     
    28363047            if((uView == LVS_LIST) || (uView == LVS_SMALLICON))
    28373048            {
    2838               item_width = LISTVIEW_GetStringWidthA(hwnd, lpItem->pszText);
     3049              item_width = LISTVIEW_GetStringWidthT(hwnd, lpItem->pszText, TRUE);
    28393050
    28403051              if(item_width > infoPtr->nItemWidth)
     
    28433054
    28443055            /* send LVN_ITEMCHANGED notification */
    2845             nmlv.hdr.code = LVN_ITEMCHANGED;
    2846             ListView_LVNotify(GetParent(hwnd), lCtrlId, &nmlv);
     3056            listview_notify(hwnd, LVN_ITEMCHANGED, &nmlv);
    28473057          }
    28483058          else
     
    28503060            bResult = TRUE;
    28513061          }
    2852 
     3062         
    28533063          if (uChanged)
    28543064          {
    28553065            rcItem.left = LVIR_BOUNDS;
    2856         LISTVIEW_GetItemRect(hwnd, lpLVItem->iItem, &rcItem);
     3066            LISTVIEW_GetItemRect(hwnd, lpLVItem->iItem, &rcItem);
    28573067#ifdef __WIN32OS2__
    28583068            if(lStyle & LVS_OWNERDRAWFIXED && rcItem.left == REPORT_MARGINX) {
     
    28733083 * DESCRIPTION:
    28743084 * Sets subitem attributes.
    2875  *
    2876  * PARAMETER(S):
    2877  * [I] HWND : window handle
    2878  * [I] LPLVITEM : new subitem atttributes
     3085 *
     3086 * PARAMETER(S):
     3087 * [I] HWND : window handle
     3088 * [I] LPLVITEM : new subitem atttributes
     3089 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
    28793090 *
    28803091 * RETURN:
     
    28823093 *   FAILURE : FALSE
    28833094 */
    2884 static BOOL LISTVIEW_SetSubItem(HWND hwnd, LPLVITEMA lpLVItem)
    2885 {
    2886   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     3095static BOOL LISTVIEW_SetSubItemT(HWND hwnd, LPLVITEMW lpLVItem, BOOL isW)
     3096{
     3097  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     3098  LONG lStyle = GetWindowLongW(hwnd, GWL_STYLE);
    28873099  BOOL bResult = FALSE;
    28883100  HDPA hdpaSubItems;
    28893101  LISTVIEW_SUBITEM *lpSubItem;
    2890   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
    28913102  RECT rcItem;
    28923103
     3104  TRACE("(hwnd=%x, lpLVItem=%s, isW=%d)\n", hwnd, debuglvitem_t(lpLVItem, isW), isW);
     3105 
    28933106  if (lStyle & LVS_OWNERDATA)
    28943107    return FALSE;
     
    29063119          lpSubItem = LISTVIEW_GetSubItem(hdpaSubItems, lpLVItem->iSubItem);
    29073120          if (lpSubItem != NULL)
    2908           {
    2909             bResult = LISTVIEW_InitSubItem(hwnd, lpSubItem, lpLVItem);
    2910           }
     3121            bResult = LISTVIEW_InitSubItemT(hwnd, lpSubItem, lpLVItem, isW);
    29113122          else
    2912           {
    2913             bResult = LISTVIEW_AddSubItem(hwnd, lpLVItem);
    2914           }
    2915 
     3123            bResult = LISTVIEW_AddSubItemT(hwnd, lpLVItem, isW);
    29163124#ifdef __WIN32OS2__
    29173125          if(bResult) {
    29183126#endif
    29193127          rcItem.left = LVIR_BOUNDS;
    2920       LISTVIEW_GetItemRect(hwnd, lpLVItem->iItem, &rcItem);
    2921       InvalidateRect(hwnd, &rcItem, FALSE);
     3128          LISTVIEW_GetItemRect(hwnd, lpLVItem->iItem, &rcItem);
     3129          InvalidateRect(hwnd, &rcItem, FALSE);
    29223130#ifdef __WIN32OS2__
    29233131          }
    29243132#endif
    2925         }
     3133        } 
    29263134      }
    29273135    }
     
    29333141/***
    29343142 * DESCRIPTION:
     3143 * Sets item attributes.
     3144 *
     3145 * PARAMETER(S):
     3146 * [I] HWND : window handle
     3147 * [I] LPLVITEM : new item atttributes
     3148 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
     3149 *
     3150 * RETURN:
     3151 *   SUCCESS : TRUE
     3152 *   FAILURE : FALSE
     3153 */
     3154static BOOL LISTVIEW_SetItemT(HWND hwnd, LPLVITEMW lpLVItem, BOOL isW)
     3155{
     3156  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     3157
     3158  if (!lpLVItem || lpLVItem->iItem < 0 ||
     3159      lpLVItem->iItem>=GETITEMCOUNT(infoPtr))
     3160    return FALSE;
     3161  if (lpLVItem->iSubItem == 0)
     3162    return LISTVIEW_SetMainItemT(hwnd, lpLVItem, isW);
     3163  else
     3164    return LISTVIEW_SetSubItemT(hwnd, lpLVItem, isW);
     3165}
     3166
     3167/***
     3168 * DESCRIPTION:
    29353169 * Retrieves the index of the item at coordinate (0, 0) of the client area.
    2936  *
     3170 * 
    29373171 * PARAMETER(S):
    29383172 * [I] HWND : window handle
     
    29433177static INT LISTVIEW_GetTopIndex(HWND hwnd)
    29443178{
    2945   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     3179  LONG lStyle = GetWindowLongW(hwnd, GWL_STYLE);
    29463180  UINT uView = lStyle & LVS_TYPEMASK;
    29473181  INT nItem = 0;
     
    29513185  scrollInfo.cbSize = sizeof(SCROLLINFO);
    29523186  scrollInfo.fMask = SIF_POS;
    2953 
     3187 
    29543188  if (uView == LVS_LIST)
    29553189  {
    2956     if (lStyle & WS_HSCROLL)
    2957     {
    2958       if (GetScrollInfo(hwnd, SB_HORZ, &scrollInfo) != FALSE)
    2959       {
    2960         nItem = scrollInfo.nPos * LISTVIEW_GetCountPerColumn(hwnd);
    2961       }
    2962     }
     3190    if ((lStyle & WS_HSCROLL) && GetScrollInfo(hwnd, SB_HORZ, &scrollInfo))
     3191      nItem = scrollInfo.nPos * LISTVIEW_GetCountPerColumn(hwnd);
    29633192  }
    29643193  else if (uView == LVS_REPORT)
    29653194  {
    2966     if (lStyle & WS_VSCROLL)
    2967     {
    2968       if (GetScrollInfo(hwnd, SB_VERT, &scrollInfo) != FALSE)
    2969       {
    2970         nItem = scrollInfo.nPos;
    2971       }
    2972     }
    2973   }
    2974 
     3195    if ((lStyle & WS_VSCROLL) && GetScrollInfo(hwnd, SB_VERT, &scrollInfo))
     3196      nItem = scrollInfo.nPos;
     3197  }
     3198 
    29753199  return nItem;
    29763200}
     
    29793203 * DESCRIPTION:
    29803204 * Draws a subitem.
    2981  *
     3205 * 
    29823206 * PARAMETER(S):
    29833207 * [I] HWND : window handle
     
    29903214 * None
    29913215 */
    2992 static VOID LISTVIEW_DrawSubItem(HWND hwnd, HDC hdc, INT nItem, INT nSubItem,
     3216static VOID LISTVIEW_DrawSubItem(HWND hwnd, HDC hdc, INT nItem, INT nSubItem, 
    29933217                                 RECT rcItem, BOOL Selected)
    29943218{
    2995   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    2996   CHAR szDispText[DISP_TEXT_SIZE];
    2997   LVITEMA lvItem;
     3219  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     3220  WCHAR szDispText[DISP_TEXT_SIZE];
     3221  LVITEMW lvItem;
     3222  LVCOLUMNW lvColumn;
    29983223  UINT textoutOptions = ETO_CLIPPED | ETO_OPAQUE;
    29993224  RECT rcTemp;
     3225  INT textLeft;
     3226  INT nLabelWidth = 0;
    30003227
    30013228  TRACE("(hwnd=%x, hdc=%x, nItem=%d, nSubItem=%d)\n", hwnd, hdc,
     
    30033230
    30043231  /* get information needed for drawing the item */
    3005   ZeroMemory(&lvItem, sizeof(LVITEMA));
     3232  ZeroMemory(&lvItem, sizeof(lvItem));
    30063233  lvItem.mask = LVIF_TEXT;
    30073234  lvItem.iItem = nItem;
     
    30093236  lvItem.cchTextMax = DISP_TEXT_SIZE;
    30103237  lvItem.pszText = szDispText;
    3011   LISTVIEW_GetItemA(hwnd, &lvItem, TRUE);
     3238  *lvItem.pszText = '\0';
     3239  LISTVIEW_GetItemW(hwnd, &lvItem, TRUE);
     3240  TRACE("   lvItem=%s\n", debuglvitem_t(&lvItem, TRUE));
     3241 
     3242  ZeroMemory(&lvColumn, sizeof(lvColumn));
     3243  lvColumn.mask = LVCF_FMT;
     3244  LISTVIEW_GetColumnT(hwnd, nSubItem, &lvColumn, TRUE);
     3245  textLeft = rcItem.left;
     3246  if (lvColumn.fmt != LVCFMT_LEFT)
     3247  {
     3248    if ((nLabelWidth = LISTVIEW_GetStringWidthT(hwnd, lvItem.pszText, TRUE)))
     3249    {
     3250      if (lvColumn.fmt == LVCFMT_RIGHT)
     3251        textLeft = rcItem.right - nLabelWidth;
     3252      else
     3253        textLeft = rcItem.left + (rcItem.right-rcItem.left-nLabelWidth)/2;
     3254    }
     3255  }
     3256   
    30123257
    30133258  /* redraw the background of the item */
    30143259  rcTemp = rcItem;
    30153260  if(infoPtr->nColumnCount == (nSubItem + 1))
    3016     rcTemp.right = infoPtr->rcList.right;
     3261    rcTemp.right  = infoPtr->rcList.right;
    30173262  else
    3018     rcTemp.right+=WIDTH_PADDING;
     3263    rcTemp.right += WIDTH_PADDING;
    30193264
    30203265  LISTVIEW_FillBackground(hwnd, hdc, &rcTemp);
     
    30503295  }
    30513296
    3052   ExtTextOutA(hdc, rcItem.left, rcItem.top, textoutOptions,
    3053               &rcItem, lvItem.pszText, lstrlenA(lvItem.pszText), NULL);
     3297  ExtTextOutW(hdc, textLeft, rcItem.top, textoutOptions,
     3298              &rcItem, lvItem.pszText, lstrlenW(lvItem.pszText), NULL);
    30543299
    30553300  if (Selected)
     
    30623307      rec.left = rec.right;
    30633308      rec.right = rec.left+REPORT_MARGINX;
    3064       ExtTextOutA(hdc, rec.left , rec.top, textoutOptions,
     3309      ExtTextOutW(hdc, rec.left , rec.top, textoutOptions,
    30653310        &rec, NULL, 0, NULL);
    30663311    }
     
    30683313    rec.right = rec.left;
    30693314    rec.left = rec.left - REPORT_MARGINX;
    3070     ExtTextOutA(hdc, rec.left , rec.top, textoutOptions,
     3315    ExtTextOutW(hdc, rec.left , rec.top, textoutOptions,
    30713316    &rec, NULL, 0, NULL);
    30723317  }
     
    30773322 * DESCRIPTION:
    30783323 * Draws an item.
    3079  *
     3324 * 
    30803325 * PARAMETER(S):
    30813326 * [I] HWND : window handle
     
    30893334static VOID LISTVIEW_DrawItem(HWND hwnd, HDC hdc, INT nItem, RECT rcItem, BOOL FullSelect, RECT* SuggestedFocus)
    30903335{
    3091   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    3092   CHAR szDispText[DISP_TEXT_SIZE];
     3336  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     3337  WCHAR szDispText[DISP_TEXT_SIZE];
    30933338  INT nLabelWidth;
    3094   LVITEMA lvItem;
     3339  LVITEMW lvItem;
    30953340  INT nMixMode;
    30963341  DWORD dwBkColor;
     
    31053350
    31063351  /* get information needed for drawing the item */
    3107   ZeroMemory(&lvItem, sizeof(LVITEMA));
     3352  ZeroMemory(&lvItem, sizeof(lvItem));
    31083353  lvItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE | LVIF_INDENT;
    31093354  lvItem.stateMask = LVIS_SELECTED |  LVIS_STATEIMAGEMASK;
     
    31123357  lvItem.cchTextMax = DISP_TEXT_SIZE;
    31133358  lvItem.pszText = szDispText;
    3114   LISTVIEW_GetItemA(hwnd, &lvItem, TRUE);
     3359  *lvItem.pszText = '\0';
     3360  LISTVIEW_GetItemW(hwnd, &lvItem, TRUE);
     3361  TRACE("   lvItem=%s\n", debuglvitem_t(&lvItem, TRUE));
    31153362
    31163363  /* redraw the background of the item */
     
    31263373  if (lvItem.iIndent>0 && infoPtr->iconSize.cx > 0)
    31273374  {
    3128     rcItem.left += infoPtr->iconSize.cx * lvItem.iIndent;
     3375    rcItem.left += infoPtr->iconSize.cx * lvItem.iIndent; 
    31293376
    31303377    if (SuggestedFocus)
    31313378      SuggestedFocus->left += infoPtr->iconSize.cx * lvItem.iIndent;
    3132   }
     3379  } 
    31333380
    31343381  /* state icons */
    31353382  if (infoPtr->himlState != NULL)
    31363383  {
    3137      UINT uStateImage = (lvItem.state & LVIS_STATEIMAGEMASK) >> 12;
     3384     UINT uStateImage = (lvItem.state & LVIS_STATEIMAGEMASK) >> 12; 
    31383385     if (uStateImage > 0)
    31393386     {
    3140        ImageList_Draw(infoPtr->himlState, uStateImage - 1, hdc, rcItem.left,
     3387       ImageList_Draw(infoPtr->himlState, uStateImage - 1, hdc, rcItem.left, 
    31413388                      rcItem.top, ILD_NORMAL);
    31423389     }
    3143 
    3144      rcItem.left += infoPtr->iconSize.cx;
     3390 
     3391     rcItem.left += infoPtr->iconSize.cx; 
    31453392     if (SuggestedFocus)
    31463393       SuggestedFocus->left += infoPtr->iconSize.cx;
    31473394     bImage = TRUE;
    31483395  }
    3149 
     3396 
    31503397  /* small icons */
    31513398  if (infoPtr->himlSmall != NULL)
     
    31553402    {
    31563403      ImageList_SetBkColor(infoPtr->himlSmall, CLR_NONE);
    3157       ImageList_Draw(infoPtr->himlSmall, lvItem.iImage, hdc, rcItem.left,
     3404      ImageList_Draw(infoPtr->himlSmall, lvItem.iImage, hdc, rcItem.left, 
    31583405                     rcItem.top, ILD_SELECTED);
    31593406    }
     
    31613408    {
    31623409      ImageList_SetBkColor(infoPtr->himlSmall, CLR_NONE);
    3163       ImageList_Draw(infoPtr->himlSmall, lvItem.iImage, hdc, rcItem.left,
     3410      ImageList_Draw(infoPtr->himlSmall, lvItem.iImage, hdc, rcItem.left, 
    31643411                     rcItem.top, ILD_NORMAL);
    31653412    }
    3166 
    3167     rcItem.left += infoPtr->iconSize.cx;
     3413   
     3414    rcItem.left += infoPtr->iconSize.cx; 
    31683415
    31693416    if (SuggestedFocus)
     
    31783425  if ((lvItem.state & LVIS_SELECTED) && (infoPtr->bFocus != FALSE))
    31793426  {
    3180     /* set item colors */
     3427    /* set item colors */ 
    31813428    dwBkColor = SetBkColor(hdc, GetSysColor(COLOR_HIGHLIGHT));
    31823429    dwTextColor = SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
     
    31843431    nMixMode = SetROP2(hdc, R2_XORPEN);
    31853432  }
    3186   else if ((GetWindowLongA(hwnd, GWL_STYLE) & LVS_SHOWSELALWAYS) &&
     3433  else if ((GetWindowLongW(hwnd, GWL_STYLE) & LVS_SHOWSELALWAYS) &&
    31873434           (lvItem.state & LVIS_SELECTED) && (infoPtr->bFocus == FALSE))
    31883435  {
     
    32113458    nMixMode = SetROP2(hdc, R2_COPYPEN);
    32123459  }
    3213 
    3214   nLabelWidth = ListView_GetStringWidthA(hwnd, lvItem.pszText);
     3460 
     3461  nLabelWidth = ListView_GetStringWidthW(hwnd, lvItem.pszText);
    32153462  if (rcItem.left + nLabelWidth < rcItem.right)
    32163463  {
     
    32203467      rcItem.right += IMAGE_PADDING;
    32213468  }
    3222 
    3223   /* draw label */
     3469 
     3470  /* draw label */ 
    32243471  dwTextX = rcItem.left + 1;
    32253472  if (bImage)
     
    32273474
    32283475  if (lvItem.pszText)
    3229     ExtTextOutA(hdc, dwTextX, rcItem.top, textoutOptions,
    3230                 &rcItem, lvItem.pszText, lstrlenA(lvItem.pszText), NULL);
     3476    ExtTextOutW(hdc, dwTextX, rcItem.top, textoutOptions,
     3477                &rcItem, lvItem.pszText, lstrlenW(lvItem.pszText), NULL);
    32313478
    32323479  if ((FullSelect)&&(Header_GetItemCount(infoPtr->hwndHeader) > 1))
     
    32373484    rec.left = rec.right;
    32383485    rec.right = rec.left+REPORT_MARGINX;
    3239     ExtTextOutA(hdc, rec.left , rec.top, textoutOptions,
     3486    ExtTextOutW(hdc, rec.left , rec.top, textoutOptions,
    32403487    &rec, NULL, 0, NULL);
    32413488  }
    3242 
     3489 
    32433490  if (!FullSelect)
    32443491      CopyRect(SuggestedFocus,&rcItem);
     
    32573504 * DESCRIPTION:
    32583505 * Draws an item when in large icon display mode.
    3259  *
     3506 * 
    32603507 * PARAMETER(S):
    32613508 * [I] HWND : window handle
    32623509 * [I] HDC : device context handle
    3263  * [I] LISTVIEW_ITEM * : item
    32643510 * [I] INT : item index
    3265  * [I] RECT * : clipping rectangle
     3511 * [I] RECT : clipping rectangle
     3512 * [O] RECT * : The text rectangle about which to draw the focus
    32663513 *
    32673514 * RETURN:
     
    32713518                                   RECT *SuggestedFocus)
    32723519{
    3273   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    3274   CHAR szDispText[DISP_TEXT_SIZE];
    3275   INT nDrawPosX = rcItem.left;
    3276   INT nLabelWidth, rcWidth;
    3277   TEXTMETRICA tm;
    3278   LVITEMA lvItem;
    3279   UINT textoutOptions = ETO_CLIPPED | ETO_OPAQUE;
     3520  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     3521  WCHAR szDispText[DISP_TEXT_SIZE] = { '\0' };
     3522  LVITEMW lvItem;
     3523  UINT uFormat = DT_TOP | DT_CENTER | DT_WORDBREAK | DT_NOPREFIX |
     3524                 DT_EDITCONTROL ;
     3525  /* Maintain this format in line with the one in LISTVIEW_UpdateLargeItemLabelRect*/
    32803526  RECT rcTemp;
    32813527
    32823528  TRACE("(hwnd=%x, hdc=%x, nItem=%d, left=%d, top=%d, right=%d, bottom=%d)\n",
    3283         hwnd, hdc, nItem, rcItem.left, rcItem.top, rcItem.right,
    3284         rcItem.bottom);
     3529        hwnd, hdc, nItem, rcItem.left, rcItem.top, rcItem.right, rcItem.bottom);
    32853530
    32863531  /* get information needed for drawing the item */
    3287   ZeroMemory(&lvItem, sizeof(LVITEMA));
     3532  ZeroMemory(&lvItem, sizeof(lvItem));
    32883533  lvItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE;
    32893534  lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
     
    32923537  lvItem.cchTextMax = DISP_TEXT_SIZE;
    32933538  lvItem.pszText = szDispText;
    3294   LISTVIEW_GetItemA(hwnd, &lvItem, TRUE);
     3539  *lvItem.pszText = '\0';
     3540  LISTVIEW_GetItemW(hwnd, &lvItem, FALSE);
     3541  TRACE("   lvItem=%s\n", debuglvitem_t(&lvItem, TRUE));
    32953542
    32963543  /* redraw the background of the item */
     
    33003547  else
    33013548    rcTemp.right+=WIDTH_PADDING;
    3302 
     3549    /* The comment doesn't say WIDTH_PADDING applies to large icons */
     3550 
     3551  TRACE("background rect (%d,%d)-(%d,%d)\n",
     3552        rcTemp.left, rcTemp.top, rcTemp.right, rcTemp.bottom);
     3553 
    33033554  LISTVIEW_FillBackground(hwnd, hdc, &rcTemp);
    33043555
     3556
     3557  /* Figure out text colours etc. depending on state
     3558   * At least the following states exist; there may be more.
     3559   * Many items may be selected
     3560   * At most one item may have the focus
     3561   * The application may not actually be active currently
     3562   * 1. The item is not selected in any way
     3563   * 2. The cursor is flying over the icon or text and the text is being
     3564   *    expanded because it is not fully displayed currently.
     3565   * 3. The item is selected and is focussed, i.e. the user has not clicked
     3566   *    in the blank area of the window, and the window (or application?)
     3567   *    still has the focus.
     3568   * 4. As 3 except that a different window has the focus
     3569   * 5. The item is the selected item of all the items, but the user has
     3570   *    clicked somewhere else on the window.
     3571   * Only a few of these are handled currently. In particular 2 is not yet
     3572   * handled since we do not support the functionality currently (or at least
     3573   * we didn't when I wrote this)
     3574   */
     3575
    33053576  if (lvItem.state & LVIS_SELECTED)
    33063577  {
    3307     /* set item colors */
     3578    /* set item colors */ 
    33083579    SetBkColor(hdc, GetSysColor(COLOR_HIGHLIGHT));
    33093580    SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
     3581    SetBkMode (hdc, OPAQUE);
    33103582    /* set raster mode */
    33113583    SetROP2(hdc, R2_XORPEN);
     3584    /* When exactly is it in XOR? while being dragged? */
    33123585  }
    33133586  else
     
    33173590    {
    33183591       SetBkMode(hdc, TRANSPARENT);
    3319        textoutOptions &= ~ETO_OPAQUE;
    33203592    }
    33213593    else
     
    33303602  }
    33313603
     3604  /* In cases 2,3 and 5 (see above) the full text is displayed, with word
     3605   * wrapping and long words split.
     3606   * In cases 1 and 4 only a portion of the text is displayed with word
     3607   * wrapping and both word and end ellipsis.  (I don't yet know about path
     3608   * ellipsis)
     3609   */
     3610  uFormat |= ( (lvItem.state & LVIS_FOCUSED) && infoPtr->bFocus) ?
     3611          DT_NOCLIP
     3612      :
     3613          DT_WORD_ELLIPSIS | DT_END_ELLIPSIS;
     3614
     3615  /* draw the icon */
    33323616  if (infoPtr->himlNormal != NULL)
    33333617  {
    3334     rcItem.top += ICON_TOP_PADDING;
    3335     nDrawPosX += (infoPtr->iconSpacing.cx - infoPtr->iconSize.cx) / 2;
    3336     if ((lvItem.state & LVIS_SELECTED) && (lvItem.iImage>=0))
    3337     {
    3338       ImageList_Draw(infoPtr->himlNormal, lvItem.iImage, hdc, nDrawPosX,
    3339                      rcItem.top, ILD_SELECTED);
    3340     }
    3341     else if (lvItem.iImage>=0)
    3342     {
    3343       ImageList_Draw(infoPtr->himlNormal, lvItem.iImage, hdc, nDrawPosX,
    3344                      rcItem.top, ILD_NORMAL);
    3345     }
    3346   }
     3618    if (lvItem.iImage >= 0)
     3619    {
     3620      ImageList_Draw (infoPtr->himlNormal, lvItem.iImage, hdc, rcItem.left,
     3621                      rcItem.top,
     3622                      (lvItem.state & LVIS_SELECTED) ? ILD_SELECTED : ILD_NORMAL);
     3623    }
     3624  }
     3625
     3626  /* Draw the text below the icon */
    33473627
    33483628  /* Don't bother painting item being edited */
    3349   if (infoPtr->hwndEdit && lvItem.state & LVIS_FOCUSED)
     3629  if ((infoPtr->hwndEdit && (lvItem.state & LVIS_FOCUSED)) ||
     3630      !lstrlenW(lvItem.pszText))
     3631  {
     3632    SetRectEmpty(SuggestedFocus);
    33503633    return;
    3351 
     3634  }
     3635
     3636  /* Since rcItem.left is left point of icon, compute left point of item box */
     3637  rcItem.left -= ((infoPtr->nItemWidth - infoPtr->iconSize.cx) / 2);
     3638  rcItem.right = rcItem.left + infoPtr->nItemWidth;
     3639  rcItem.bottom = rcItem.top + infoPtr->nItemHeight;
     3640  TRACE("bound box for text+icon (%d,%d)-(%d,%d), iS.cx=%ld, nItemWidth=%d\n",
     3641        rcItem.left, rcItem.top, rcItem.right, rcItem.bottom,
     3642        infoPtr->iconSize.cx, infoPtr->nItemWidth);
     3643  TRACE("rcList (%d,%d)-(%d,%d), rcView (%d,%d)-(%d,%d)\n",
     3644        infoPtr->rcList.left,    infoPtr->rcList.top,
     3645        infoPtr->rcList.right,   infoPtr->rcList.bottom,
     3646        infoPtr->rcView.left,    infoPtr->rcView.top,
     3647        infoPtr->rcView.right,   infoPtr->rcView.bottom);
     3648 
    33523649  InflateRect(&rcItem, -(2*CAPTION_BORDER), 0);
    3353   rcItem.top += infoPtr->iconSize.cy + ICON_BOTTOM_PADDING;
    3354   nLabelWidth = ListView_GetStringWidthA(hwnd, lvItem.pszText);
    3355   GetTextMetricsA(hdc, &tm);
    3356 
    3357   /* append an ellipse ('...') if the caption won't fit in the rect */
    3358   rcWidth = max(0, rcItem.right - rcItem.left);
    3359   if (nLabelWidth > rcWidth)
    3360   {
    3361       INT i, len, eos, nCharsFit;
    3362       /* give or take a couple, how many average sized chars would fit? */
    3363       nCharsFit = tm.tmAveCharWidth > 0 ? (rcWidth/tm.tmAveCharWidth)+2 : 0;
    3364       /* place the ellipse accordingly, without overrunning the buffer */
    3365       len = strlen(szDispText);
    3366       eos = min((nCharsFit > 1 && nCharsFit < len) ? nCharsFit+3 : len+2,
    3367                 sizeof(szDispText)-1);
    3368 
    3369       nLabelWidth = ListView_GetStringWidthA(hwnd, szDispText);
    3370       while ((nLabelWidth > rcWidth) && (eos > 3))
    3371       {
    3372      for (i = 1; i < 4; i++)
    3373         szDispText[eos-i] = '.';
    3374          /* shift the ellipse one char to the left for each iteration */
    3375          szDispText[eos--] = '\0';
    3376          nLabelWidth = ListView_GetStringWidthA(hwnd, szDispText);
    3377       }
    3378   }
    3379 
    3380   InflateRect(&rcItem, 2*CAPTION_BORDER, 0);
    3381   nDrawPosX = infoPtr->iconSpacing.cx - 2*CAPTION_BORDER - nLabelWidth;
    3382   if (nDrawPosX > 1)
    3383   {
    3384     rcItem.left += nDrawPosX / 2;
    3385     rcItem.right = rcItem.left + nLabelWidth + 2*CAPTION_BORDER;
    3386   }
    3387   else
    3388   {
    3389     rcItem.left += 1;
    3390     rcItem.right = rcItem.left + infoPtr->iconSpacing.cx - 1;
    3391   }
    3392 
    3393   /* draw label */
    3394   rcItem.bottom = rcItem.top + tm.tmHeight + HEIGHT_PADDING;
    3395 
    3396   ExtTextOutA(hdc, rcItem.left + CAPTION_BORDER, rcItem.top, textoutOptions,
    3397               &rcItem, lvItem.pszText, lstrlenA(lvItem.pszText), NULL);
    3398 
    3399 
    3400   CopyRect(SuggestedFocus,&rcItem);
     3650  rcItem.top += infoPtr->iconSize.cy + ICON_BOTTOM_PADDING;
     3651
     3652
     3653  /* draw label */ 
     3654
     3655  /* I am sure of most of the uFormat values.  However I am not sure about
     3656   * whether we need or do not need the following:
     3657   * DT_EXTERNALLEADING, DT_INTERNAL, DT_CALCRECT, DT_NOFULLWIDTHCHARBREAK,
     3658   * DT_PATH_ELLIPSIS, DT_RTLREADING,
     3659   * We certainly do not need
     3660   * DT_BOTTOM, DT_VCENTER, DT_MODIFYSTRING, DT_LEFT, DT_RIGHT, DT_PREFIXONLY,
     3661   * DT_SINGLELINE, DT_TABSTOP, DT_EXPANDTABS
     3662   */
     3663
     3664  /* If the text is being drawn without clipping (i.e. the full text) then we
     3665   * need to jump through a few hoops to ensure that it all gets displayed and
     3666   * that the background is complete
     3667   */
     3668  if (uFormat & DT_NOCLIP)
     3669  {
     3670      RECT rcBack=rcItem;
     3671      HBRUSH hBrush = CreateSolidBrush(GetBkColor (hdc));
     3672      int dx, dy, old_wid, new_wid;
     3673      DrawTextW (hdc, lvItem.pszText, -1, &rcItem, uFormat | DT_CALCRECT);
     3674      /* Microsoft, in their great wisdom, have decided that the rectangle
     3675       * returned by DrawText on DT_CALCRECT will only guarantee the dimension,
     3676       * not the location.  So we have to do the centring ourselves (and take
     3677       * responsibility for agreeing off-by-one consistency with them).
     3678       */
     3679      old_wid = rcItem.right-rcItem.left;
     3680      new_wid = rcBack.right - rcBack.left;
     3681      dx = rcBack.left - rcItem.left + (new_wid-old_wid)/2;
     3682      dy = rcBack.top - rcItem.top;
     3683      OffsetRect (&rcItem, dx, dy);
     3684      FillRect(hdc, &rcItem, hBrush);
     3685      DeleteObject(hBrush);
     3686  }
     3687  /* else ? What if we are losing the focus? will we not get a complete
     3688   * background?
     3689   */
     3690  DrawTextW (hdc, lvItem.pszText, -1, &rcItem, uFormat);
     3691
     3692  CopyRect(SuggestedFocus, &rcItem);
    34013693}
    34023694
     
    34043696 * DESCRIPTION:
    34053697 * Draws listview items when in report display mode.
    3406  *
    3407  * PARAMETER(S):
    3408  * [I] HWND : window handle
    3409  * [I] HDC : device context handle
     3698 * 
     3699 * PARAMETER(S):
     3700 * [I] HWND : window handle
     3701 * [I] HDC : device context handle 
    34103702 *
    34113703 * RETURN:
     
    34143706static VOID LISTVIEW_RefreshReport(HWND hwnd, HDC hdc, DWORD cdmode)
    34153707{
    3416   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd,0);
     3708  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd,0);
    34173709  SCROLLINFO scrollInfo;
    34183710  INT nDrawPosY = infoPtr->rcList.top;
     
    34243716  BOOL FullSelected;
    34253717  DWORD cditemmode = CDRF_DODEFAULT;
    3426   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     3718  LONG lStyle = GetWindowLongW(hwnd, GWL_STYLE);
    34273719  INT scrollOffset;
    34283720
     
    34383730
    34393731  /* send cache hint notification */
    3440   if (GetWindowLongA(hwnd,GWL_STYLE) & LVS_OWNERDATA)
     3732  if (GetWindowLongW(hwnd,GWL_STYLE) & LVS_OWNERDATA)
    34413733  {
    34423734    NMLVCACHEHINT nmlv;
    34433735
    34443736    nmlv.hdr.hwndFrom = hwnd;
    3445     nmlv.hdr.idFrom = GetWindowLongA(hwnd,GWL_ID);
     3737    nmlv.hdr.idFrom = GetWindowLongW(hwnd,GWL_ID);
    34463738    nmlv.hdr.code = LVN_ODCACHEHINT;
    34473739    nmlv.iFrom = nItem;
    34483740    nmlv.iTo   = nLast;
    34493741
    3450     SendMessageA(GetParent(hwnd), WM_NOTIFY, (WPARAM)nmlv.hdr.idFrom,
     3742    SendMessageW(GetParent(hwnd), WM_NOTIFY, (WPARAM)nmlv.hdr.idFrom,
    34513743                 (LPARAM)&nmlv);
    34523744  }
     
    34753767    if (lStyle & LVS_OWNERDRAWFIXED)
    34763768    {
    3477         UINT uID = GetWindowLongA( hwnd, GWL_ID);
     3769        UINT uID = GetWindowLongW( hwnd, GWL_ID);
    34783770        DRAWITEMSTRUCT dis;
    3479         LVITEMA item;
     3771        LVITEMW item;
    34803772        RECT br;
    34813773
    3482         TRACE("Owner Drawn\n");
     3774        TRACE("Owner Drawn\n");   
    34833775        dis.CtlType = ODT_LISTVIEW;
    34843776        dis.CtlID = uID;
     
    34863778        dis.itemAction = ODA_DRAWENTIRE;
    34873779        dis.itemState = 0;
    3488 
     3780       
    34893781        if (LISTVIEW_IsSelected(hwnd,nItem)) dis.itemState|=ODS_SELECTED;
    34903782        if (nItem==infoPtr->nFocusedItem)   dis.itemState|=ODS_FOCUS;
     
    34953787        Header_GetItemRect(infoPtr->hwndHeader, nColumnCount-1, &br);
    34963788
    3497         dis.rcItem.left = -scrollOffset;
     3789        dis.rcItem.left = -scrollOffset; 
    34983790        dis.rcItem.right = max(dis.rcItem.left, br.right - scrollOffset);
    34993791        dis.rcItem.top = nDrawPosY;
    35003792        dis.rcItem.bottom = dis.rcItem.top + infoPtr->nItemHeight;
    3501 
    3502         ZeroMemory(&item,sizeof(LVITEMA));
     3793       
     3794        ZeroMemory(&item,sizeof(item));
    35033795        item.iItem = nItem;
    35043796        item.mask = LVIF_PARAM;
    3505         ListView_GetItemA(hwnd,&item);
     3797        ListView_GetItemW(hwnd, &item);
    35063798
    35073799        dis.itemData = item.lParam;
    35083800
    3509         if (SendMessageA(GetParent(hwnd),WM_DRAWITEM,(WPARAM)uID,(LPARAM)&dis))
     3801        if (SendMessageW(GetParent(hwnd),WM_DRAWITEM,(WPARAM)uID,(LPARAM)&dis))
    35103802        {
    35113803          nDrawPosY += infoPtr->nItemHeight;
     
    35253817      ir.top = nDrawPosY;
    35263818      ir.bottom = ir.top + infoPtr->nItemHeight;
    3527 
     3819     
    35283820      CopyRect(&SuggestedFocusRect,&ir);
    35293821    }
     
    35513843      {
    35523844        LISTVIEW_DrawItem(hwnd, hdc, nItem, rcItem, FullSelected,
    3553                           &SuggestedFocusRect);
     3845                          &SuggestedFocusRect); 
    35543846      }
    3555       else
     3847      else 
    35563848      {
    3557         LISTVIEW_DrawSubItem(hwnd, hdc, nItem, j, rcItem,
    3558                               FullSelected);
     3849        LISTVIEW_DrawSubItem(hwnd, hdc, nItem, j, rcItem, FullSelected);
    35593850      }
    35603851
    35613852      if (cditemmode & CDRF_NOTIFYPOSTPAINT)
    3562         LISTVIEW_SendCustomDrawItemNotify(hwnd, hdc, nItem, 0,
    3563                       CDDS_ITEMPOSTPAINT);
     3853        LISTVIEW_SendCustomDrawItemNotify(hwnd, hdc, nItem, 0, 
     3854                                      CDDS_ITEMPOSTPAINT);
    35643855    }
    35653856    /*
     
    35723863        rop = SetROP2(hdc, R2_XORPEN);
    35733864
    3574       Rectangle(hdc, SuggestedFocusRect.left, SuggestedFocusRect.top,
    3575                 SuggestedFocusRect.right,SuggestedFocusRect.bottom);
     3865      Rectangle(hdc, SuggestedFocusRect.left, SuggestedFocusRect.top, 
     3866                SuggestedFocusRect.right,SuggestedFocusRect.bottom); 
    35763867
    35773868      if (rop)
     
    35853876 * DESCRIPTION:
    35863877 * Retrieves the number of items that can fit vertically in the client area.
    3587  *
     3878 * 
    35883879 * PARAMETER(S):
    35893880 * [I] HWND : window handle
     
    35943885static INT LISTVIEW_GetCountPerRow(HWND hwnd)
    35953886{
    3596   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd,0);
    3597   UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
     3887  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd,0);
     3888  UINT uView = GetWindowLongW(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    35983889  INT nListWidth = infoPtr->rcList.right - infoPtr->rcList.left;
    35993890  INT nCountPerRow = 1;
     
    36013892  if (nListWidth > 0)
    36023893  {
    3603     if (uView == LVS_REPORT)
    3604     {
    3605       nCountPerRow = 1;
    3606     }
    3607     else
     3894    if (uView != LVS_REPORT)
    36083895    {
    36093896      nCountPerRow =  nListWidth / infoPtr->nItemWidth;
    3610       if (nCountPerRow == 0)
    3611       {
    3612         nCountPerRow = 1;
    3613       }
     3897      if (nCountPerRow == 0) nCountPerRow = 1;
    36143898    }
    36153899  }
     
    36203904/***
    36213905 * DESCRIPTION:
    3622  * Retrieves the number of items that can fit horizontally in the client
     3906 * Retrieves the number of items that can fit horizontally in the client 
    36233907 * area.
    3624  *
     3908 * 
    36253909 * PARAMETER(S):
    36263910 * [I] HWND : window handle
     
    36313915static INT LISTVIEW_GetCountPerColumn(HWND hwnd)
    36323916{
    3633   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd,0);
     3917  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd,0);
    36343918  INT nListHeight = infoPtr->rcList.bottom - infoPtr->rcList.top;
    36353919  INT nCountPerColumn = 1;
     
    36433927  {
    36443928    nCountPerColumn =  nListHeight / infoPtr->nItemHeight;
    3645     if (nCountPerColumn == 0)
    3646     {
    3647       nCountPerColumn = 1;
    3648     }
     3929    if (nCountPerColumn == 0) nCountPerColumn = 1;
    36493930  }
    36503931
     
    36543935/***
    36553936 * DESCRIPTION:
    3656  * Retrieves the number of columns needed to display all the items when in
     3937 * Retrieves the number of columns needed to display all the items when in 
    36573938 * list display mode.
    3658  *
     3939 * 
    36593940 * PARAMETER(S):
    36603941 * [I] HWND : window handle
     
    36653946static INT LISTVIEW_GetColumnCount(HWND hwnd)
    36663947{
    3667   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    3668   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     3948  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     3949  LONG lStyle = GetWindowLongW(hwnd, GWL_STYLE);
    36693950  INT nColumnCount = 0;
    36703951
    36713952  if ((lStyle & LVS_TYPEMASK) == LVS_LIST)
    36723953  {
    3673     if (infoPtr->rcList.right % infoPtr->nItemWidth == 0)
    3674     {
    3675       nColumnCount = infoPtr->rcList.right / infoPtr->nItemWidth;
    3676     }
    3677     else
    3678     {
    3679       nColumnCount = infoPtr->rcList.right / infoPtr->nItemWidth + 1;
    3680     }
     3954    nColumnCount = infoPtr->rcList.right / infoPtr->nItemWidth;
     3955    if (infoPtr->rcList.right % infoPtr->nItemWidth) nColumnCount++;
    36813956  }
    36823957
    36833958  return nColumnCount;
    3684 }
    3685 
     3959} 
     3960 
    36863961
    36873962/***
    36883963 * DESCRIPTION:
    36893964 * Draws listview items when in list display mode.
    3690  *
    3691  * PARAMETER(S):
    3692  * [I] HWND : window handle
    3693  * [I] HDC : device context handle
     3965 * 
     3966 * PARAMETER(S):
     3967 * [I] HWND : window handle
     3968 * [I] HDC : device context handle 
    36943969 *
    36953970 * RETURN:
     
    36983973static VOID LISTVIEW_RefreshList(HWND hwnd, HDC hdc, DWORD cdmode)
    36993974{
    3700   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     3975  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    37013976  RECT rcItem, FocusRect, rcTemp;
    37023977  INT i, j;
     
    37444019       */
    37454020      if (LISTVIEW_GetItemState(hwnd,nItem,LVIS_FOCUSED) && infoPtr->bFocus)
    3746       Rectangle(hdc, FocusRect.left, FocusRect.top,
     4021      Rectangle(hdc, FocusRect.left, FocusRect.top, 
    37474022                FocusRect.right,FocusRect.bottom);
    37484023
    37494024      if (cditemmode & CDRF_NOTIFYPOSTPAINT)
    3750         LISTVIEW_SendCustomDrawItemNotify(hwnd, hdc, nItem, 0,
     4025        LISTVIEW_SendCustomDrawItemNotify(hwnd, hdc, nItem, 0, 
    37514026                                          CDDS_ITEMPOSTPAINT);
    3752 
     4027 
    37534028    }
    37544029  }
     
    37584033 * DESCRIPTION:
    37594034 * Draws listview items when in icon or small icon display mode.
    3760  *
    3761  * PARAMETER(S):
    3762  * [I] HWND : window handle
    3763  * [I] HDC : device context handle
     4035 * 
     4036 * PARAMETER(S):
     4037 * [I] HWND : window handle
     4038 * [I] HDC : device context handle 
    37644039 *
    37654040 * RETURN:
     
    37684043static VOID LISTVIEW_RefreshIcon(HWND hwnd, HDC hdc, BOOL bSmall, DWORD cdmode)
    37694044{
    3770   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     4045  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    37714046  POINT ptPosition;
    37724047  POINT ptOrigin;
     
    37984073    ptPosition.x += ptOrigin.x;
    37994074    ptPosition.y += ptOrigin.y;
    3800 
     4075     
    38014076    if (ptPosition.y + infoPtr->nItemHeight > infoPtr->rcList.top)
    38024077    {
     
    38114086            rcItem.bottom = rcItem.top + infoPtr->nItemHeight;
    38124087            rcItem.right = rcItem.left + infoPtr->nItemWidth;
    3813             if (bSmall == FALSE)
    3814             {
     4088            if (bSmall)
     4089              LISTVIEW_DrawItem(hwnd, hdc, i, rcItem, FALSE, &SuggestedFocus);
     4090            else
    38154091              LISTVIEW_DrawLargeItem(hwnd, hdc, i, rcItem, &SuggestedFocus);
    3816             }
    3817             else
    3818             {
    3819               LISTVIEW_DrawItem(hwnd, hdc, i, rcItem, FALSE, &SuggestedFocus);
    3820             }
    38214092            /*
    38224093             * Draw Focus Rect
    38234094             */
    3824             if (LISTVIEW_GetItemState(hwnd,i,LVIS_FOCUSED) &&
    3825                 infoPtr->bFocus)
    3826               Rectangle(hdc, SuggestedFocus.left, SuggestedFocus.top,
    3827                     SuggestedFocus.right,SuggestedFocus.bottom);
     4095            if (LISTVIEW_GetItemState(hwnd,i,LVIS_FOCUSED) && 
     4096                infoPtr->bFocus && !IsRectEmpty(&SuggestedFocus))
     4097              Rectangle(hdc, SuggestedFocus.left, SuggestedFocus.top, 
     4098                        SuggestedFocus.right,SuggestedFocus.bottom);
    38284099          }
    38294100        }
     
    38314102    }
    38324103    if (cditemmode & CDRF_NOTIFYPOSTPAINT)
    3833         LISTVIEW_SendCustomDrawItemNotify(hwnd, hdc, i, 0,
     4104        LISTVIEW_SendCustomDrawItemNotify(hwnd, hdc, i, 0, 
    38344105                                          CDDS_ITEMPOSTPAINT);
    38354106  }
     
    38394110 * DESCRIPTION:
    38404111 * Draws listview items.
    3841  *
    3842  * PARAMETER(S):
    3843  * [I] HWND : window handle
    3844  * [I] HDC : device context handle
     4112 * 
     4113 * PARAMETER(S):
     4114 * [I] HWND : window handle
     4115 * [I] HDC : device context handle 
    38454116 *
    38464117 * RETURN:
     
    38494120static VOID LISTVIEW_Refresh(HWND hwnd, HDC hdc)
    38504121{
    3851   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    3852   UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
     4122  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     4123  UINT uView = GetWindowLongW(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    38534124  HFONT hOldFont;
    38544125  HPEN hPen, hOldPen;
     
    38604131#endif
    38614132
     4133  LISTVIEW_DumpListview (infoPtr, __LINE__);
     4134
    38624135  GetClientRect(hwnd, &rect);
    38634136  cdmode = LISTVIEW_SendCustomDrawNotify(hwnd,CDDS_PREPAINT,hdc,rect);
     
    38734146
    38744147  /* select transparent brush (for drawing the focus box) */
    3875   SelectObject(hdc, GetStockObject(NULL_BRUSH));
     4148  SelectObject(hdc, GetStockObject(NULL_BRUSH)); 
    38764149
    38774150  if (uView == LVS_LIST)
    3878   {
    3879     LISTVIEW_RefreshList(hwnd, hdc, cdmode);
    3880   }
     4151    LISTVIEW_RefreshList(hwnd, hdc, cdmode);
    38814152  else if (uView == LVS_REPORT)
    3882   {
    38834153    LISTVIEW_RefreshReport(hwnd, hdc, cdmode);
    3884   }
    38854154  else if (uView == LVS_SMALLICON)
    3886   {
    38874155    LISTVIEW_RefreshIcon(hwnd, hdc, TRUE, cdmode);
    3888   }
    38894156  else if (uView == LVS_ICON)
    3890   {
    38914157    LISTVIEW_RefreshIcon(hwnd, hdc, FALSE, cdmode);
    3892   }
    38934158
    38944159  /* unselect objects */
    38954160  SelectObject(hdc, hOldFont);
    38964161  SelectObject(hdc, hOldPen);
    3897 
     4162 
    38984163  /* delete pen */
    38994164  DeleteObject(hPen);
    3900 
     4165 
    39014166  if (cdmode & CDRF_NOTIFYPOSTPAINT)
    39024167      LISTVIEW_SendCustomDrawNotify(hwnd, CDDS_POSTPAINT, hdc, rect);
     
    39074172 * DESCRIPTION:
    39084173 * Calculates the approximate width and height of a given number of items.
    3909  *
     4174 * 
    39104175 * PARAMETER(S):
    39114176 * [I] HWND : window handle
     
    39174182 * Returns a DWORD. The width in the low word and the height in high word.
    39184183 */
    3919 static LRESULT LISTVIEW_ApproximateViewRect(HWND hwnd, INT nItemCount,
     4184static LRESULT LISTVIEW_ApproximateViewRect(HWND hwnd, INT nItemCount, 
    39204185                                            WORD wWidth, WORD wHeight)
    39214186{
    3922   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    3923   UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
     4187  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     4188  UINT uView = GetWindowLongW(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    39244189  INT nItemCountPerColumn = 1;
    39254190  INT nColumnCount = 0;
     
    39274192
    39284193  if (nItemCount == -1)
    3929   {
    39304194    nItemCount = GETITEMCOUNT(infoPtr);
    3931   }
    39324195
    39334196  if (uView == LVS_LIST)
     
    39404203
    39414204    if (wHeight < infoPtr->nItemHeight)
    3942     {
    39434205      wHeight = infoPtr->nItemHeight;
    3944     }
    39454206
    39464207    if (nItemCount > 0)
     
    39504211        nItemCountPerColumn = wHeight / infoPtr->nItemHeight;
    39514212        if (nItemCountPerColumn == 0)
    3952         {
    39534213          nItemCountPerColumn = 1;
    3954         }
    3955 
     4214       
    39564215        if (nItemCount % nItemCountPerColumn != 0)
    3957         {
    39584216          nColumnCount = nItemCount / nItemCountPerColumn;
    3959         }
    39604217        else
    3961         {
    39624218          nColumnCount = nItemCount / nItemCountPerColumn + 1;
    3963         }
    39644219      }
    39654220    }
     
    39724227  }
    39734228  else if (uView == LVS_REPORT)
    3974   {
    3975     /* TO DO */
    3976   }
     4229    FIXME("uView == LVS_REPORT: not implemented\n");
    39774230  else if (uView == LVS_SMALLICON)
    3978   {
    3979     /* TO DO */
    3980   }
     4231    FIXME("uView == LVS_SMALLICON: not implemented\n");
    39814232  else if (uView == LVS_ICON)
    3982   {
    3983     /* TO DO */
    3984   }
    3985 
     4233    FIXME("uView == LVS_ICON: not implemented\n");
     4234 
    39864235  return dwViewRect;
    39874236}
     
    39904239 * DESCRIPTION:
    39914240 * Arranges listview items in icon display mode.
    3992  *
     4241 * 
    39934242 * PARAMETER(S):
    39944243 * [I] HWND : window handle
     
    40014250static LRESULT LISTVIEW_Arrange(HWND hwnd, INT nAlignCode)
    40024251{
    4003   UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
     4252  UINT uView = GetWindowLongW(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    40044253  BOOL bResult = FALSE;
    40054254
     
    40094258    {
    40104259    case LVA_ALIGNLEFT:
    4011       /* TO DO */
     4260      FIXME("nAlignCode=LVA_ALIGNLEFT: not implemented\n");
    40124261      break;
    40134262    case LVA_ALIGNTOP:
    4014       /* TO DO */
     4263      FIXME("nAlignCode=LVA_ALIGNTOP: not implemented\n");
    40154264      break;
    40164265    case LVA_DEFAULT:
    4017       /* TO DO */
     4266      FIXME("nAlignCode=LVA_DEFAULT: not implemented\n");
    40184267      break;
    40194268    case LVA_SNAPTOGRID:
    4020       /* TO DO */
     4269      FIXME("nAlignCode=LVA_SNAPTOGRID: not implemented\n");
    40214270      break;
    40224271    }
     
    40324281 * DESCRIPTION:
    40334282 * Removes all listview items and subitems.
    4034  *
     4283 * 
    40354284 * PARAMETER(S):
    40364285 * [I] HWND : window handle
     
    40424291static LRESULT LISTVIEW_DeleteAllItems(HWND hwnd)
    40434292{
    4044   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    4045   LONG lCtrlId = GetWindowLongA(hwnd, GWL_ID);
    4046   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     4293  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     4294  LONG lStyle = GetWindowLongW(hwnd, GWL_STYLE);
    40474295  UINT uView = lStyle & LVS_TYPEMASK;
    40484296  LISTVIEW_ITEM *lpItem;
     
    40514299  BOOL bSuppress;
    40524300  BOOL bResult = FALSE;
    4053   INT i;
    4054   INT j;
    40554301  HDPA hdpaSubItems;
    40564302
     
    40714317  if (GETITEMCOUNT(infoPtr) > 0)
    40724318  {
    4073     /* initialize memory */
     4319    INT i, j;
     4320   
     4321    /* send LVN_DELETEALLITEMS notification */
     4322    /* verify if subsequent LVN_DELETEITEM notifications should be
     4323       suppressed */
    40744324    ZeroMemory(&nmlv, sizeof(NMLISTVIEW));
    4075 
    4076     /* send LVN_DELETEALLITEMS notification */
    4077     nmlv.hdr.hwndFrom = hwnd;
    4078     nmlv.hdr.idFrom = lCtrlId;
    4079     nmlv.hdr.code = LVN_DELETEALLITEMS;
    40804325    nmlv.iItem = -1;
    4081 
    4082     /* verify if subsequent LVN_DELETEITEM notifications should be
    4083        suppressed */
    4084     bSuppress = ListView_LVNotify(GetParent(hwnd), lCtrlId, &nmlv);
     4326    bSuppress = listview_notify(hwnd, LVN_DELETEALLITEMS, &nmlv);
    40854327
    40864328    for (i = 0; i < GETITEMCOUNT(infoPtr); i++)
     
    40954337          {
    40964338            /* free subitem string */
    4097             if ((lpSubItem->pszText != NULL) &&
    4098                 (lpSubItem->pszText != LPSTR_TEXTCALLBACKA))
    4099             {
     4339            if (is_textW(lpSubItem->pszText))
    41004340              COMCTL32_Free(lpSubItem->pszText);
    4101             }
    4102 
     4341       
    41034342            /* free subitem */
    41044343            COMCTL32_Free(lpSubItem);
    4105           }
     4344          }   
    41064345        }
    41074346
     
    41094348        if (lpItem != NULL)
    41104349        {
    4111           if (bSuppress == FALSE)
     4350          if (!bSuppress)
    41124351          {
    41134352            /* send LVN_DELETEITEM notification */
    4114             nmlv.hdr.code = LVN_DELETEITEM;
    41154353            nmlv.iItem = i;
    41164354            nmlv.lParam = lpItem->lParam;
    4117             ListView_LVNotify(GetParent(hwnd), lCtrlId, &nmlv);
     4355            listview_notify(hwnd, LVN_DELETEITEM, &nmlv);
    41184356          }
    41194357
    41204358          /* free item string */
    4121           if ((lpItem->pszText != NULL) &&
    4122               (lpItem->pszText != LPSTR_TEXTCALLBACKA))
    4123           {
     4359          if (is_textW(lpItem->pszText))
    41244360            COMCTL32_Free(lpItem->pszText);
    4125           }
    4126 
     4361     
    41274362          /* free item */
    41284363          COMCTL32_Free(lpItem);
    41294364        }
    4130 
     4365       
    41314366        DPA_Destroy(hdpaSubItems);
    41324367      }
     
    41354370    /* reinitialize listview memory */
    41364371    bResult = DPA_DeleteAllPtrs(infoPtr->hdpaItems);
    4137 
     4372   
    41384373    /* align items (set position of each item) */
    41394374    if ((uView == LVS_ICON) || (uView == LVS_SMALLICON))
     
    41484383      }
    41494384    }
    4150 
     4385   
    41514386    LISTVIEW_UpdateScroll(hwnd);
    41524387
     
    41544389    InvalidateRect(hwnd, NULL, TRUE);
    41554390  }
    4156 
     4391 
    41574392  return bResult;
    41584393}
     
    41614396 * DESCRIPTION:
    41624397 * Removes a column from the listview control.
    4163  *
     4398 * 
    41644399 * PARAMETER(S):
    41654400 * [I] HWND : window handle
     
    41724407static LRESULT LISTVIEW_DeleteColumn(HWND hwnd, INT nColumn)
    41734408{
    4174   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    4175   UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    4176   UINT uOwnerData = GetWindowLongA(hwnd, GWL_STYLE) & LVS_OWNERDATA;
     4409  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     4410  UINT uView = GetWindowLongW(hwnd, GWL_STYLE) & LVS_TYPEMASK;
     4411  UINT uOwnerData = GetWindowLongW(hwnd, GWL_STYLE) & LVS_OWNERDATA;
    41774412  BOOL bResult = FALSE;
    41784413
     
    42024437 * DESCRIPTION:
    42034438 * Removes an item from the listview control.
    4204  *
    4205  * PARAMETER(S):
    4206  * [I] HWND : window handle
    4207  * [I] INT : item index
     4439 * 
     4440 * PARAMETER(S):
     4441 * [I] HWND : window handle
     4442 * [I] INT : item index 
    42084443 *
    42094444 * RETURN:
     
    42134448static LRESULT LISTVIEW_DeleteItem(HWND hwnd, INT nItem)
    42144449{
    4215   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    4216   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     4450  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     4451  LONG lStyle = GetWindowLongW(hwnd, GWL_STYLE);
    42174452  UINT uView = lStyle & LVS_TYPEMASK;
    4218   LONG lCtrlId = GetWindowLongA(hwnd, GWL_ID);
     4453  LONG lCtrlId = GetWindowLongW(hwnd, GWL_ID);
    42194454  NMLISTVIEW nmlv;
    42204455  BOOL bResult = FALSE;
     
    42234458  LISTVIEW_SUBITEM *lpSubItem;
    42244459  INT i;
    4225   LVITEMA item;
    4226 
    4227   TRACE("(hwnd=%x,nItem=%d)\n", hwnd, nItem);
    4228 
    4229 
     4460  LVITEMW item;
     4461
     4462  TRACE("(hwnd=%x, nItem=%d)\n", hwnd, nItem);
     4463 
     4464 
    42304465  /* First, send LVN_DELETEITEM notification. */
    42314466  memset(&nmlv, 0, sizeof (NMLISTVIEW));
     
    42344469  nmlv.hdr.code = LVN_DELETEITEM;
    42354470  nmlv.iItem = nItem;
    4236   SendMessageA(GetParent(hwnd), WM_NOTIFY, (WPARAM)lCtrlId,
     4471  SendMessageW(GetParent(hwnd), WM_NOTIFY, (WPARAM)lCtrlId,
    42374472               (LPARAM)&nmlv);
    42384473
    42394474
    42404475  /* remove it from the selection range */
    4241   ZeroMemory(&item,sizeof(LVITEMA));
     4476  ZeroMemory(&item,sizeof(item));
    42424477  item.stateMask = LVIS_SELECTED;
    42434478  LISTVIEW_SetItemState(hwnd,nItem,&item);
     
    42644499        {
    42654500          /* free item string */
    4266           if ((lpSubItem->pszText != NULL) &&
    4267               (lpSubItem->pszText != LPSTR_TEXTCALLBACKA))
    4268           {
     4501          if (is_textW(lpSubItem->pszText))
    42694502            COMCTL32_Free(lpSubItem->pszText);
    4270           }
    4271 
     4503       
    42724504          /* free item */
    42734505          COMCTL32_Free(lpSubItem);
    4274         }
     4506        }   
    42754507      }
    4276 
     4508 
    42774509      lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0);
    42784510      if (lpItem != NULL)
    42794511      {
    42804512        /* free item string */
    4281         if ((lpItem->pszText != NULL) &&
    4282             (lpItem->pszText != LPSTR_TEXTCALLBACKA))
    4283         {
     4513        if (is_textW(lpItem->pszText))
    42844514          COMCTL32_Free(lpItem->pszText);
    4285         }
    4286 
     4515     
    42874516        /* free item */
    42884517        COMCTL32_Free(lpItem);
    42894518      }
    4290 
     4519   
    42914520      bResult = DPA_Destroy(hdpaSubItems);
    42924521    }
     
    42984527    {
    42994528      if (lStyle & LVS_ALIGNLEFT)
    4300       {
    43014529        LISTVIEW_AlignLeft(hwnd);
    4302       }
    43034530      else
    4304       {
    43054531        LISTVIEW_AlignTop(hwnd);
    4306       }
    43074532    }
    43084533
     
    43124537    InvalidateRect(hwnd, NULL, TRUE);
    43134538  }
    4314 
     4539 
    43154540  return bResult;
    43164541}
     
    43304555static LRESULT LISTVIEW_GetEditControl(HWND hwnd)
    43314556{
    4332   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     4557  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    43334558  return infoPtr->hwndEdit;
    43344559}
     
    43434568 * [I] LPSTR : modified text
    43444569 * [I] DWORD : item index
     4570 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
    43454571 *
    43464572 * RETURN:
     
    43484574 *   FAILURE : FALSE
    43494575 */
    4350 
    4351 static BOOL LISTVIEW_EndEditLabel(HWND hwnd, LPSTR pszText, DWORD nItem)
    4352 {
    4353   NMLVDISPINFOA dispInfo;
     4576static BOOL LISTVIEW_EndEditLabelT(HWND hwnd, LPWSTR pszText, DWORD nItem, BOOL isW)
     4577{
     4578  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     4579  LONG lStyle = GetWindowLongW(hwnd, GWL_STYLE);
     4580  NMLVDISPINFOW dispInfo;
    43544581  LISTVIEW_ITEM *lpItem;
    4355   INT nCtrlId = GetWindowLongA(hwnd, GWL_ID);
    4356   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    4357   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
    43584582  HDPA hdpaSubItems;
    4359   BOOL bUpdateItemText;
    43604583  LISTVIEW_ITEM lvItemRef;
    4361   LVITEMA item;
    4362 
    4363   ZeroMemory(&dispInfo, sizeof(NMLVDISPINFOA));
    4364 
     4584  LVITEMW item;
     4585  BOOL bResult = TRUE;
     4586
     4587  TRACE("(hwnd=%x, pszText=%s, nItem=%ld, isW=%d)\n", hwnd, debugstr_t(pszText, isW), nItem, isW);
     4588 
    43654589  if (!(lStyle & LVS_OWNERDATA))
    43664590  {
    4367     if (NULL == (hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, nItem)))
    4368       return FALSE;
    4369 
    4370     if (NULL == (lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0)))
    4371       return FALSE;
     4591    if (!(hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, nItem)))
     4592          return FALSE;
     4593
     4594    if (!(lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0)))
     4595          return FALSE;
    43724596  }
    43734597  else
    43744598  {
    43754599    ZeroMemory(&lvItemRef,sizeof(LISTVIEW_ITEM));
    4376     ZeroMemory(&item,sizeof(LVITEMA));
     4600    ZeroMemory(&item,sizeof(item));
    43774601    item.iItem = nItem;
    43784602    item.iSubItem = 0;
    43794603    item.mask = LVIF_PARAM | LVIF_STATE;
    4380     ListView_GetItemA(hwnd,&item);
     4604    ListView_GetItemW(hwnd, &item);
    43814605    lvItemRef.state = item.state;
    43824606    lvItemRef.iImage = item.iImage;
     
    43854609  }
    43864610
    4387   dispInfo.hdr.hwndFrom = hwnd;
    4388   dispInfo.hdr.idFrom = nCtrlId;
    4389   dispInfo.hdr.code = LVN_ENDLABELEDITA;
     4611  ZeroMemory(&dispInfo, sizeof(dispInfo));
    43904612  dispInfo.item.mask = 0;
    43914613  dispInfo.item.iItem = nItem;
     
    43934615  dispInfo.item.stateMask = 0;
    43944616  dispInfo.item.pszText = pszText;
    4395   dispInfo.item.cchTextMax = pszText ? strlen(pszText) : 0;
     4617  dispInfo.item.cchTextMax = textlenT(pszText, isW);
    43964618  dispInfo.item.iImage = lpItem->iImage;
    43974619  dispInfo.item.lParam = lpItem->lParam;
    43984620  infoPtr->hwndEdit = 0;
    43994621
    4400   bUpdateItemText = ListView_Notify(GetParent(hwnd), nCtrlId, &dispInfo);
    4401 
    44024622  /* Do we need to update the Item Text */
    4403   if(bUpdateItemText)
    4404   {
    4405     if ((lpItem->pszText != LPSTR_TEXTCALLBACKA)&&(!(lStyle & LVS_OWNERDATA)))
    4406     {
    4407         Str_SetPtrA(&lpItem->pszText, pszText);
    4408     }
    4409   }
    4410 
    4411   return TRUE;
    4412 }
    4413 
    4414 /***
    4415  * DESCRIPTION:
    4416  * Begin in place editing of specified list view item
    4417  *
    4418  * PARAMETER(S):
    4419  * [I] HWND : window handle
    4420  * [I] INT : item index
     4623  if(dispinfo_notifyT(hwnd, LVN_ENDLABELEDITW, &dispInfo, isW))
     4624    if (lpItem->pszText != LPSTR_TEXTCALLBACKW && !(lStyle & LVS_OWNERDATA))
     4625      bResult = textsetptrT(&lpItem->pszText, pszText, isW);
     4626 
     4627  return bResult;
     4628}
     4629
     4630/***
     4631 * DESCRIPTION:
     4632 * Callback implementation for editlabel control
     4633 *
     4634 * PARAMETER(S):
     4635 * [I] HWND : window handle
     4636 * [I] LPSTR : modified text
     4637 * [I] DWORD : item index
    44214638 *
    44224639 * RETURN:
     
    44244641 *   FAILURE : FALSE
    44254642 */
    4426 
    4427 static HWND LISTVIEW_EditLabelA(HWND hwnd, INT nItem)
    4428 {
    4429   NMLVDISPINFOA dispInfo;
     4643static BOOL LISTVIEW_EndEditLabelW(HWND hwnd, LPWSTR pszText, DWORD nItem)
     4644{
     4645    return LISTVIEW_EndEditLabelT(hwnd, pszText, nItem, TRUE);
     4646}
     4647
     4648/***
     4649 * DESCRIPTION:
     4650 * Callback implementation for editlabel control
     4651 *
     4652 * PARAMETER(S):
     4653 * [I] HWND : window handle
     4654 * [I] LPSTR : modified text
     4655 * [I] DWORD : item index
     4656 *
     4657 * RETURN:
     4658 *   SUCCESS : TRUE
     4659 *   FAILURE : FALSE
     4660 */
     4661static BOOL LISTVIEW_EndEditLabelA(HWND hwnd, LPSTR pszText, DWORD nItem)
     4662{
     4663    return LISTVIEW_EndEditLabelT(hwnd, (LPWSTR)pszText, nItem, FALSE);
     4664}
     4665
     4666/***
     4667 * DESCRIPTION:
     4668 * Begin in place editing of specified list view item
     4669 *
     4670 * PARAMETER(S):
     4671 * [I] HWND : window handle
     4672 * [I] INT : item index
     4673 * [I] isW : TRUE if it's a Unicode req, FALSE if ASCII
     4674 *
     4675 * RETURN:
     4676 *   SUCCESS : TRUE
     4677 *   FAILURE : FALSE
     4678 */
     4679static HWND LISTVIEW_EditLabelT(HWND hwnd, INT nItem, BOOL isW)
     4680{
     4681  NMLVDISPINFOW dispInfo;
    44304682  RECT rect;
    44314683  LISTVIEW_ITEM *lpItem;
    4432   HWND hedit;
    4433   HINSTANCE hinst = GetWindowLongA(hwnd, GWL_HINSTANCE);
    4434   INT nCtrlId = GetWindowLongA(hwnd, GWL_ID);
    4435   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     4684  HWND hedit;
     4685  HINSTANCE hinst = GetWindowLongW(hwnd, GWL_HINSTANCE);
     4686  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    44364687  HDPA hdpaSubItems;
    4437   CHAR szDispText[DISP_TEXT_SIZE];
    4438   LVITEMA lvItem,item;
     4688  WCHAR szDispText[DISP_TEXT_SIZE];
     4689  LVITEMW lvItem;
    44394690  LISTVIEW_ITEM lvItemRef;
    4440   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
    4441 
    4442   if (~GetWindowLongA(hwnd, GWL_STYLE) & LVS_EDITLABELS)
     4691  LONG lStyle = GetWindowLongW(hwnd, GWL_STYLE);
     4692 
     4693  if (~GetWindowLongW(hwnd, GWL_STYLE) & LVS_EDITLABELS)
    44434694      return FALSE;
    44444695
    44454696  /* Is the EditBox still there, if so remove it */
    44464697  if(infoPtr->hwndEdit != 0)
    4447   {
    44484698      SetFocus(hwnd);
    4449   }
    44504699
    44514700  LISTVIEW_SetSelection(hwnd, nItem);
    44524701  LISTVIEW_SetItemFocus(hwnd, nItem);
    44534702
    4454   ZeroMemory(&dispInfo, sizeof(NMLVDISPINFOA));
    44554703  if (!(lStyle & LVS_OWNERDATA))
    44564704  {
    44574705    if (NULL == (hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, nItem)))
    4458       return 0;
     4706          return 0;
    44594707
    44604708    if (NULL == (lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0)))
    4461       return 0;
    4462   }
     4709          return 0;
     4710  } 
    44634711  else
    44644712  {
     4713    LVITEMW item;
    44654714    ZeroMemory(&lvItemRef,sizeof(LISTVIEW_ITEM));
    4466     ZeroMemory(&item,sizeof(LVITEMA));
     4715    ZeroMemory(&item, sizeof(item));
    44674716    item.iItem = nItem;
    44684717    item.iSubItem = 0;
    44694718    item.mask = LVIF_PARAM | LVIF_STATE;
    4470     ListView_GetItemA(hwnd,&item);
     4719    ListView_GetItemW(hwnd, &item);
    44714720    lvItemRef.iImage = item.iImage;
    44724721    lvItemRef.state = item.state;
     
    44764725
    44774726  /* get information needed for drawing the item */
    4478   ZeroMemory(&lvItem, sizeof(LVITEMA));
     4727  ZeroMemory(&lvItem, sizeof(lvItem));
    44794728  lvItem.mask = LVIF_TEXT;
    44804729  lvItem.iItem = nItem;
     
    44824731  lvItem.cchTextMax = DISP_TEXT_SIZE;
    44834732  lvItem.pszText = szDispText;
    4484   ListView_GetItemA(hwnd, &lvItem);
    4485 
    4486   dispInfo.hdr.hwndFrom = hwnd;
    4487   dispInfo.hdr.idFrom = nCtrlId;
    4488   dispInfo.hdr.code = LVN_BEGINLABELEDITA;
     4733  *lvItem.pszText = '\0';
     4734  LISTVIEW_GetItemT(hwnd, &lvItem, FALSE, isW);
     4735
     4736  ZeroMemory(&dispInfo, sizeof(dispInfo));
    44894737  dispInfo.item.mask = 0;
    44904738  dispInfo.item.iItem = nItem;
     
    44924740  dispInfo.item.stateMask = 0;
    44934741  dispInfo.item.pszText = lvItem.pszText;
    4494   dispInfo.item.cchTextMax = strlen(lvItem.pszText);
     4742  dispInfo.item.cchTextMax = lstrlenW(lvItem.pszText);
    44954743  dispInfo.item.iImage = lpItem->iImage;
    44964744  dispInfo.item.lParam = lpItem->lParam;
    44974745
    4498   if (ListView_LVNotify(GetParent(hwnd), nCtrlId, &dispInfo))
    4499       return 0;
     4746  if (dispinfo_notifyT(hwnd, LVN_BEGINLABELEDITW, &dispInfo, isW))
     4747          return 0;
    45004748
    45014749  rect.left = LVIR_LABEL;
    45024750  if (!LISTVIEW_GetItemRect(hwnd, nItem, &rect))
    4503       return 0;
    4504 
    4505   if (!(hedit = CreateEditLabel(szDispText , WS_VISIBLE,
    4506          rect.left-2, rect.top-1, 0,
    4507          rect.bottom - rect.top+2,
    4508          hwnd, hinst, LISTVIEW_EndEditLabel, nItem)))
    4509     return 0;
     4751          return 0;
     4752 
     4753  if (!(hedit = CreateEditLabelT(szDispText , WS_VISIBLE,
     4754                 rect.left-2, rect.top-1, 0, rect.bottom - rect.top+2, hwnd, hinst,
     4755                 isW ? LISTVIEW_EndEditLabelW : (EditlblCallbackW)LISTVIEW_EndEditLabelA,
     4756                 nItem, isW)))
     4757        return 0;
    45104758
    45114759  infoPtr->hwndEdit = hedit;
    4512   SetFocus(hedit);
    4513   SendMessageA(hedit, EM_SETSEL, 0, -1);
     4760  SetFocus(hedit); 
     4761  SendMessageW(hedit, EM_SETSEL, 0, -1);
    45144762
    45154763  return hedit;
     
    45204768 * DESCRIPTION:
    45214769 * Ensures the specified item is visible, scrolling into view if necessary.
    4522  *
     4770 * 
    45234771 * PARAMETER(S):
    45244772 * [I] HWND : window handle
     
    48495097}
    48505098#endif
     5099
    48515100/***
    48525101 * DESCRIPTION:
    48535102 * Retrieves the nearest item, given a position and a direction.
    4854  *
     5103 * 
    48555104 * PARAMETER(S):
    48565105 * [I] HWND : window handle
     
    48635112static INT LISTVIEW_GetNearestItem(HWND hwnd, POINT pt, UINT vkDirection)
    48645113{
    4865   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    4866   LVHITTESTINFO lvHitTestInfo;
     5114  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     5115  LV_INTHIT lvIntHit;
    48675116  INT nItem = -1;
    48685117  RECT rcView;
    48695118
     5119  TRACE("point %ld,%ld, direction %s\n", pt.x, pt.y,
     5120        (vkDirection == VK_DOWN) ? "VK_DOWN" :
     5121        ((vkDirection == VK_UP) ? "VK_UP" :
     5122        ((vkDirection == VK_LEFT) ? "VK_LEFT" : "VK_RIGHT")));
     5123
    48705124  if (LISTVIEW_GetViewRect(hwnd, &rcView) != FALSE)
    48715125  {
    4872     ZeroMemory(&lvHitTestInfo, sizeof(LVHITTESTINFO));
    4873     LISTVIEW_GetOrigin(hwnd, &lvHitTestInfo.pt);
    4874     lvHitTestInfo.pt.x += pt.x;
    4875     lvHitTestInfo.pt.y += pt.y;
    4876 
    4877     do
    4878     {
    4879       if (vkDirection == VK_DOWN)
    4880       {
    4881         lvHitTestInfo.pt.y += infoPtr->nItemHeight;
    4882       }
    4883       else if (vkDirection == VK_UP)
    4884       {
    4885         lvHitTestInfo.pt.y -= infoPtr->nItemHeight;
    4886       }
    4887       else if (vkDirection == VK_LEFT)
    4888       {
    4889         lvHitTestInfo.pt.x -= infoPtr->nItemWidth;
    4890       }
    4891       else if (vkDirection == VK_RIGHT)
    4892       {
    4893         lvHitTestInfo.pt.x += infoPtr->nItemWidth;
    4894       }
    4895 
    4896       if (PtInRect(&rcView, lvHitTestInfo.pt) == FALSE)
    4897       {
    4898         return -1;
    4899       }
    4900       else
    4901       {
    4902         nItem = LISTVIEW_HitTestItem(hwnd, &lvHitTestInfo, TRUE);
    4903       }
    4904 
    4905     }
    4906     while (nItem == -1);
     5126    ZeroMemory(&lvIntHit, sizeof(lvIntHit));
     5127    LISTVIEW_GetOrigin(hwnd, &lvIntHit.ht.pt);
     5128    lvIntHit.ht.pt.x += pt.x;
     5129    lvIntHit.ht.pt.y += pt.y;
     5130   
     5131    if (vkDirection == VK_DOWN)
     5132      lvIntHit.ht.pt.y += infoPtr->nItemHeight;
     5133    else if (vkDirection == VK_UP)
     5134      lvIntHit.ht.pt.y -= infoPtr->nItemHeight;
     5135    else if (vkDirection == VK_LEFT)
     5136      lvIntHit.ht.pt.x -= infoPtr->nItemWidth;
     5137    else if (vkDirection == VK_RIGHT)
     5138      lvIntHit.ht.pt.x += infoPtr->nItemWidth;
     5139
     5140    if (PtInRect(&rcView, lvIntHit.ht.pt) == FALSE)
     5141      return -1;
     5142    else
     5143    {
     5144      nItem = LISTVIEW_SuperHitTestItem(hwnd, &lvIntHit, TRUE);
     5145      return nItem == -1 ? lvIntHit.iDistItem : nItem;
     5146    }
    49075147  }
    49085148
    49095149  return nItem;
    4910 }
     5150} 
    49115151
    49125152/***
    49135153 * DESCRIPTION:
    49145154 * Searches for an item with specific characteristics.
    4915  *
    4916  * PARAMETER(S):
    4917  * [I] HWND : window handle
    4918  * [I] INT : base item index
    4919  * [I] LPLVFINDINFO : item information to look for
    4920  *
     5155 * 
     5156 * PARAMETER(S):
     5157 * [I] hwnd : window handle
     5158 * [I] nStart : base item index
     5159 * [I] lpFindInfo : item information to look for
     5160 * 
    49215161 * RETURN:
    49225162 *   SUCCESS : index of item
    49235163 *   FAILURE : -1
    49245164 */
    4925 static LRESULT LISTVIEW_FindItem(HWND hwnd, INT nStart,
    4926                                  LPLVFINDINFO lpFindInfo)
    4927 {
    4928   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     5165static LRESULT LISTVIEW_FindItemW(HWND hwnd, INT nStart,
     5166                                  LPLVFINDINFOW lpFindInfo)
     5167{
     5168  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    49295169  POINT ptItem;
    4930   CHAR szDispText[DISP_TEXT_SIZE];
    4931   LVITEMA lvItem;
     5170  WCHAR szDispText[DISP_TEXT_SIZE] = { '\0' };
     5171  LVITEMW lvItem;
    49325172  BOOL bWrap = FALSE;
    49335173  INT nItem = nStart;
     
    49365176  if ((nItem >= -1) && (lpFindInfo != NULL))
    49375177  {
    4938     ZeroMemory(&lvItem, sizeof(LVITEMA));
     5178    ZeroMemory(&lvItem, sizeof(lvItem));
    49395179
    49405180    if (lpFindInfo->flags & LVFI_PARAM)
     
    49425182      lvItem.mask |= LVIF_PARAM;
    49435183    }
    4944 
    4945     if (lpFindInfo->flags & LVFI_STRING)
     5184   
     5185    if (lpFindInfo->flags & (LVFI_STRING | LVFI_PARTIAL))
    49465186    {
    49475187      lvItem.mask |= LVIF_TEXT;
     
    49505190    }
    49515191
    4952     if (lpFindInfo->flags & LVFI_PARTIAL)
    4953     {
    4954       lvItem.mask |= LVIF_TEXT;
    4955       lvItem.pszText = szDispText;
    4956       lvItem.cchTextMax = DISP_TEXT_SIZE;
    4957     }
    4958 
    49595192    if (lpFindInfo->flags & LVFI_WRAP)
    4960     {
    49615193      bWrap = TRUE;
    4962     }
    49635194
    49645195    if (lpFindInfo->flags & LVFI_NEARESTXY)
     
    49745205        if (lpFindInfo->flags & LVFI_NEARESTXY)
    49755206        {
    4976           nItem = LISTVIEW_GetNearestItem(hwnd, ptItem,
     5207          nItem = LISTVIEW_GetNearestItem(hwnd, ptItem, 
    49775208                                          lpFindInfo->vkDirection);
    49785209          if (nItem != -1)
     
    49895220          nItem++;
    49905221        }
    4991 
     5222       
    49925223        lvItem.iItem = nItem;
    49935224        lvItem.iSubItem = 0;
    4994         if (LISTVIEW_GetItemA(hwnd, &lvItem, TRUE) != FALSE)
     5225        if (LISTVIEW_GetItemW(hwnd, &lvItem, TRUE))
    49955226        {
    49965227          if (lvItem.mask & LVIF_TEXT)
     
    49985229            if (lpFindInfo->flags & LVFI_PARTIAL)
    49995230            {
    5000               if (strstr(lvItem.pszText, lpFindInfo->psz) == NULL)
     5231              if (strstrW(lvItem.pszText, lpFindInfo->psz) == NULL)
    50015232                continue;
    50025233            }
    50035234            else
    50045235            {
    5005               if (strcmp(lvItem.pszText, lpFindInfo->psz) != 0)
     5236              if (lstrcmpW(lvItem.pszText, lpFindInfo->psz) != 0)
    50065237                continue;
    50075238            }
    50085239          }
    5009 
     5240         
    50105241          if (lvItem.mask & LVIF_PARAM)
    50115242          {
     
    50135244              continue;
    50145245          }
    5015 
     5246         
    50165247          return nItem;
    50175248        }
    50185249      }
    50195250
    5020       if (bWrap != FALSE)
     5251      if (bWrap)
    50215252      {
    50225253        nItem = -1;
     
    50275258      {
    50285259        return -1;
    5029       }
    5030     }
    5031   }
    5032 
    5033  return -1;
     5260      }       
     5261    }
     5262  }
     5263
     5264 return -1;
     5265}
     5266
     5267/***
     5268 * DESCRIPTION:
     5269 * Searches for an item with specific characteristics.
     5270 *
     5271 * PARAMETER(S):
     5272 * [I] hwnd : window handle
     5273 * [I] nStart : base item index
     5274 * [I] lpFindInfo : item information to look for
     5275 *
     5276 * RETURN:
     5277 *   SUCCESS : index of item
     5278 *   FAILURE : -1
     5279 */
     5280static LRESULT LISTVIEW_FindItemA(HWND hwnd, INT nStart,
     5281                                  LPLVFINDINFOA lpFindInfo)
     5282{
     5283  BOOL hasText = lpFindInfo->flags & (LVFI_STRING | LVFI_PARTIAL);
     5284  LVFINDINFOW fiw;
     5285  LRESULT res;
     5286 
     5287  memcpy(&fiw, lpFindInfo, sizeof(fiw));
     5288  if (hasText) fiw.psz = textdupTtoW((LPCWSTR)lpFindInfo->psz, FALSE);
     5289  res = LISTVIEW_FindItemW(hwnd, nStart, &fiw);
     5290  if (hasText) textfreeT((LPWSTR)fiw.psz, FALSE);
     5291  return res;
    50345292}
    50355293
     
    50375295 * DESCRIPTION:
    50385296 * Retrieves the background color of the listview control.
    5039  *
     5297 * 
    50405298 * PARAMETER(S):
    50415299 * [I] HWND : window handle
     
    50465304static LRESULT LISTVIEW_GetBkColor(HWND hwnd)
    50475305{
    5048   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     5306  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    50495307
    50505308  return infoPtr->clrBk;
     
    50545312 * DESCRIPTION:
    50555313 * Retrieves the background image of the listview control.
    5056  *
     5314 * 
    50575315 * PARAMETER(S):
    50585316 * [I] HWND : window handle
     
    50725330 * DESCRIPTION:
    50735331 * Retrieves the callback mask.
    5074  *
     5332 * 
    50755333 * PARAMETER(S):
    50765334 * [I] HWND : window handle
     
    50815339static UINT LISTVIEW_GetCallbackMask(HWND hwnd)
    50825340{
    5083   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     5341  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    50845342
    50855343  return infoPtr->uCallbackMask;
     
    50895347 * DESCRIPTION:
    50905348 * Retrieves column attributes.
    5091  *
     5349 * 
    50925350 * PARAMETER(S):
    50935351 * [I] HWND : window handle
    50945352 * [I] INT :  column index
    5095  * [IO] LPLVCOLUMNA : column information
     5353 * [IO] LPLVCOLUMNW : column information
     5354 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
     5355 *           otherwise it is in fact a LPLVCOLUMNA
    50965356 *
    50975357 * RETURN:
     
    50995359 *   FAILURE : FALSE
    51005360 */
    5101 static LRESULT LISTVIEW_GetColumnA(HWND hwnd, INT nItem, LPLVCOLUMNA lpColumn)
    5102 {
    5103   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    5104   HDITEMA hdi;
     5361static LRESULT LISTVIEW_GetColumnT(HWND hwnd, INT nItem, LPLVCOLUMNW lpColumn, BOOL isW)
     5362{
     5363  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     5364  HDITEMW hdi;
    51055365  BOOL bResult = FALSE;
    5106 
     5366 
    51075367  if (lpColumn != NULL)
    51085368  {
     5369
     5370    TRACE("(hwnd=%x, col=%d, lpColumn=%s, isW=%d)\n",
     5371        hwnd, nItem, debuglvcolumn_t(lpColumn, isW), isW);
     5372
    51095373    /* initialize memory */
    5110     ZeroMemory(&hdi, sizeof(HDITEMA));
    5111 
     5374    ZeroMemory(&hdi, sizeof(hdi));
     5375   
    51125376    if (lpColumn->mask & LVCF_FMT)
    5113     {
    51145377      hdi.mask |= HDI_FORMAT;
    5115     }
    51165378
    51175379    if (lpColumn->mask & LVCF_WIDTH)
    5118     {
    51195380      hdi.mask |= HDI_WIDTH;
    5120     }
    51215381
    51225382    if (lpColumn->mask & LVCF_TEXT)
     
    51285388
    51295389    if (lpColumn->mask & LVCF_IMAGE)
    5130     {
    51315390      hdi.mask |= HDI_IMAGE;
    5132     }
    51335391
    51345392    if (lpColumn->mask & LVCF_ORDER)
    5135     {
    51365393      hdi.mask |= HDI_ORDER;
    5137     }
    5138 
    5139     bResult = Header_GetItemA(infoPtr->hwndHeader, nItem, &hdi);
     5394
     5395    if (isW)
     5396      bResult = Header_GetItemW(infoPtr->hwndHeader, nItem, &hdi);
     5397    else
     5398      bResult = Header_GetItemA(infoPtr->hwndHeader, nItem, &hdi);
     5399
    51405400    if (bResult != FALSE)
    51415401    {
    5142       if (lpColumn->mask & LVCF_FMT)
     5402      if (lpColumn->mask & LVCF_FMT) 
    51435403      {
    51445404        lpColumn->fmt = 0;
    51455405
    51465406        if (hdi.fmt & HDF_LEFT)
    5147         {
    51485407          lpColumn->fmt |= LVCFMT_LEFT;
    5149         }
    51505408        else if (hdi.fmt & HDF_RIGHT)
    5151         {
    51525409          lpColumn->fmt |= LVCFMT_RIGHT;
    5153         }
    51545410        else if (hdi.fmt & HDF_CENTER)
    5155         {
    51565411          lpColumn->fmt |= LVCFMT_CENTER;
    5157         }
    51585412
    51595413        if (hdi.fmt & HDF_IMAGE)
    5160         {
    51615414          lpColumn->fmt |= LVCFMT_COL_HAS_IMAGES;
    5162         }
    5163 
    5164     if (hdi.fmt & HDF_BITMAP_ON_RIGHT)
    5165     {
    5166       lpColumn->fmt |= LVCFMT_BITMAP_ON_RIGHT;
    5167     }
     5415
     5416        if (hdi.fmt & HDF_BITMAP_ON_RIGHT)
     5417          lpColumn->fmt |= LVCFMT_BITMAP_ON_RIGHT;
    51685418      }
    51695419
    51705420      if (lpColumn->mask & LVCF_WIDTH)
    5171       {
    51725421        lpColumn->cx = hdi.cxy;
    5173       }
    5174 
     5422     
    51755423      if (lpColumn->mask & LVCF_IMAGE)
    5176       {
    51775424        lpColumn->iImage = hdi.iImage;
    5178       }
    51795425
    51805426      if (lpColumn->mask & LVCF_ORDER)
    5181       {
    51825427        lpColumn->iOrder = hdi.iOrder;
    5183       }
    51845428    }
    51855429  }
     
    51885432}
    51895433
    5190 /* LISTVIEW_GetColumnW */
    5191 
    51925434
    51935435static LRESULT LISTVIEW_GetColumnOrderArray(HWND hwnd, INT iCount, LPINT lpiArray)
    51945436{
    5195 /*  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0); */
     5437/*  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0); */
    51965438    INT i;
    51975439
    51985440    if (!lpiArray)
    5199     return FALSE;
     5441        return FALSE;
    52005442
    52015443    /* little hack */
    52025444    for (i = 0; i < iCount; i++)
    5203     lpiArray[i] = i;
     5445        lpiArray[i] = i;
    52045446
    52055447    return TRUE;
     
    52095451 * DESCRIPTION:
    52105452 * Retrieves the column width.
    5211  *
     5453 * 
    52125454 * PARAMETER(S):
    52135455 * [I] HWND : window handle
     
    52165458 * RETURN:
    52175459 *   SUCCESS : column width
    5218  *   FAILURE : zero
     5460 *   FAILURE : zero 
    52195461 */
    52205462static LRESULT LISTVIEW_GetColumnWidth(HWND hwnd, INT nColumn)
    52215463{
    5222   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    5223   UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
     5464  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     5465  UINT uView = GetWindowLongW(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    52245466  INT nColumnWidth = 0;
    5225   HDITEMA hdi;
     5467  HDITEMW hdi;
    52265468
    52275469  if (uView == LVS_LIST)
     
    52325474  {
    52335475    /* get column width from header */
    5234     ZeroMemory(&hdi, sizeof(HDITEMA));
     5476    ZeroMemory(&hdi, sizeof(hdi));
    52355477    hdi.mask = HDI_WIDTH;
    5236     if (Header_GetItemA(infoPtr->hwndHeader, nColumn, &hdi) != FALSE)
    5237     {
     5478    if (Header_GetItemW(infoPtr->hwndHeader, nColumn, &hdi) != FALSE)
    52385479      nColumnWidth = hdi.cxy;
    5239     }
    52405480  }
    52415481
     
    52455485/***
    52465486 * DESCRIPTION:
    5247  * In list or report display mode, retrieves the number of items that can fit
    5248  * vertically in the visible area. In icon or small icon display mode,
     5487 * In list or report display mode, retrieves the number of items that can fit 
     5488 * vertically in the visible area. In icon or small icon display mode, 
    52495489 * retrieves the total number of visible items.
    5250  *
     5490 * 
    52515491 * PARAMETER(S):
    52525492 * [I] HWND : window handle
     
    52575497static LRESULT LISTVIEW_GetCountPerPage(HWND hwnd)
    52585498{
    5259   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    5260   UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
     5499  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     5500  UINT uView = GetWindowLongW(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    52615501  INT nItemCount = 0;
    52625502
     
    52655505    if (infoPtr->rcList.right > infoPtr->nItemWidth)
    52665506    {
    5267       nItemCount = LISTVIEW_GetCountPerRow(hwnd) *
     5507      nItemCount = LISTVIEW_GetCountPerRow(hwnd) * 
    52685508                   LISTVIEW_GetCountPerColumn(hwnd);
    52695509    }
     
    52995539
    53005540    /* make sure we can get the listview info */
    5301     if (!(infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0)))
    5302     return (0);
     5541    if (!(infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0)))
     5542        return (0);
    53035543
    53045544    return (infoPtr->dwExStyle);
     
    53085548 * DESCRIPTION:
    53095549 * Retrieves the handle to the header control.
    5310  *
     5550 * 
    53115551 * PARAMETER(S):
    53125552 * [I] HWND : window handle
     
    53175557static LRESULT LISTVIEW_GetHeader(HWND hwnd)
    53185558{
    5319   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     5559  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    53205560
    53215561  return infoPtr->hwndHeader;
     
    53385578static LRESULT LISTVIEW_GetHoverTime(HWND hwnd)
    53395579{
    5340   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     5580  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    53415581
    53425582  return infoPtr->dwHoverTime;
     
    53465586 * DESCRIPTION:
    53475587 * Retrieves an image list handle.
    5348  *
    5349  * PARAMETER(S):
    5350  * [I] HWND : window handle
    5351  * [I] INT : image list identifier
    5352  *
     5588 * 
     5589 * PARAMETER(S):
     5590 * [I] HWND : window handle
     5591 * [I] INT : image list identifier 
     5592 * 
    53535593 * RETURN:
    53545594 *   SUCCESS : image list handle
     
    53575597static LRESULT LISTVIEW_GetImageList(HWND hwnd, INT nImageList)
    53585598{
    5359   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     5599  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    53605600  HIMAGELIST himl = NULL;
    53615601
    5362   switch (nImageList)
     5602  switch (nImageList) 
    53635603  {
    53645604  case LVSIL_NORMAL:
     
    53815621 * DESCRIPTION:
    53825622 * Retrieves item attributes.
    5383  *
    5384  * PARAMETER(S):
    5385  * [I] HWND : window handle
    5386  * [IO] LPLVITEMA : item info
     5623 * 
     5624 * PARAMETER(S):
     5625 * [I] hwnd : window handle
     5626 * [IO] lpLVItem : item info
    53875627 * [I] internal : if true then we will use tricks that avoid copies
    53885628 *               but are not compatible with the regular interface
    5389  *
    5390  * RETURN:
    5391  *   SUCCESS : TRUE
     5629 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
     5630 *           if FALSE, the lpLVItem is a LPLVITEMA.
     5631 *
     5632 * RETURN:
     5633 *   SUCCESS : TRUE
    53925634 *   FAILURE : FALSE
    53935635 */
    5394 static LRESULT LISTVIEW_GetItemA(HWND hwnd, LPLVITEMA lpLVItem, BOOL internal)
    5395 {
    5396   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    5397   LONG lCtrlId = GetWindowLongA(hwnd, GWL_ID);
    5398   NMLVDISPINFOA dispInfo;
     5636static LRESULT LISTVIEW_GetItemT(HWND hwnd, LPLVITEMW lpLVItem, BOOL internal, BOOL isW)
     5637{
     5638  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     5639  LONG lStyle = GetWindowLongW(hwnd, GWL_STYLE);
     5640  NMLVDISPINFOW dispInfo;
    53995641  LISTVIEW_SUBITEM *lpSubItem;
    54005642  LISTVIEW_ITEM *lpItem;
    5401   INT* piImage;
    5402   LPSTR* ppszText;
    5403   LPARAM *plParam;
    54045643  HDPA hdpaSubItems;
    5405   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     5644  void* null = NULL;
     5645  INT* piImage = (INT*)&null;
     5646  LPWSTR* ppszText= (LPWSTR*)&null;
     5647  LPARAM* plParam = (LPARAM*)&null;
     5648
     5649  if (internal && !isW)
     5650  {
     5651    ERR("We can't have internal non-Unicode GetItem!\n");
     5652    return FALSE;
     5653  }
     5654 
    54065655  /* In the following:
    54075656   * lpLVItem describes the information requested by the user
    54085657   * lpItem/lpSubItem is what we have
    5409    * dispInfo is a structure we use to request the missing
     5658   * dispInfo is a structure we use to request the missing 
    54105659   *     information from the application
    54115660   */
    54125661
    5413   TRACE("(hwnd=%x, lpLVItem=%p)\n", hwnd, lpLVItem);
    5414 
    5415   if ((lpLVItem == NULL) ||
    5416       (lpLVItem->iItem < 0) ||
    5417       (lpLVItem->iItem >= GETITEMCOUNT(infoPtr))
    5418      )
     5662  TRACE("(hwnd=%x, lpLVItem=%s, internal=%d, isW=%d)\n",
     5663        hwnd, debuglvitem_t(lpLVItem, isW), internal, isW);
     5664
     5665  if ((lpLVItem == NULL) || (lpLVItem->iItem < 0) ||
     5666      (lpLVItem->iItem >= GETITEMCOUNT(infoPtr)))
    54195667    return FALSE;
    54205668
     5669  ZeroMemory(&dispInfo, sizeof(dispInfo));
     5670
    54215671  if (lStyle & LVS_OWNERDATA)
    54225672  {
    54235673    if (lpLVItem->mask & ~LVIF_STATE)
    54245674    {
    5425       dispInfo.hdr.hwndFrom = hwnd;
    5426       dispInfo.hdr.idFrom = lCtrlId;
    5427       dispInfo.hdr.code = LVN_GETDISPINFOA;
    5428       memcpy(&dispInfo.item,lpLVItem,sizeof(LVITEMA));
    5429 
    5430       ListView_Notify(GetParent(hwnd), lCtrlId, &dispInfo);
    5431       memcpy(lpLVItem,&dispInfo.item,sizeof(LVITEMA));
     5675      memcpy(&dispInfo.item, lpLVItem, sizeof(LVITEMW));
     5676      dispinfo_notifyT(hwnd, LVN_GETDISPINFOW, &dispInfo, isW);
     5677      memcpy(lpLVItem, &dispInfo.item, sizeof(LVITEMW));
     5678      TRACE("   getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem, isW));
    54325679    }
    54335680
    54345681    if ((lpLVItem->mask & LVIF_STATE)&&(lpLVItem->iSubItem == 0))
    54355682    {
    5436       lpLVItem->state = 0;
     5683      lpLVItem->state = 0; 
    54375684      if (infoPtr->nFocusedItem == lpLVItem->iItem)
    54385685        lpLVItem->state |= LVIS_FOCUSED;
     
    54445691  }
    54455692
    5446 
    54475693  hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, lpLVItem->iItem);
    5448   if (hdpaSubItems == NULL)
     5694  if (hdpaSubItems == NULL) return FALSE;
     5695
     5696  if ( (lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0)) == NULL)
    54495697    return FALSE;
    54505698
    5451   lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0);
    5452   if (lpItem == NULL)
    5453     return FALSE;
    5454 
    5455   ZeroMemory(&dispInfo, sizeof(NMLVDISPINFOA));
     5699  ZeroMemory(&dispInfo.item, sizeof(LVITEMW));
    54565700  if (lpLVItem->iSubItem == 0)
    54575701  {
     
    54595703    ppszText=&lpItem->pszText;
    54605704    plParam=&lpItem->lParam;
    5461     if ((infoPtr->uCallbackMask != 0) && (lpLVItem->mask & LVIF_STATE))
    5462     {
     5705    if ((lpLVItem->mask & LVIF_STATE) && infoPtr->uCallbackMask)
     5706    {       
    54635707      dispInfo.item.mask |= LVIF_STATE;
    5464       dispInfo.item.stateMask = infoPtr->uCallbackMask;
     5708      dispInfo.item.stateMask = infoPtr->uCallbackMask; 
    54655709    }
    54665710  }
     
    54725716      piImage=&lpSubItem->iImage;
    54735717      ppszText=&lpSubItem->pszText;
    5474       plParam=NULL;
    5475     }
    5476     else
    5477     {
    5478       piImage=NULL;
    5479       ppszText=NULL;
    5480       plParam=NULL;
    5481     }
    5482   }
    5483 
    5484   if ((lpLVItem->mask & LVIF_IMAGE) &&
    5485       ((piImage==NULL) || (*piImage == I_IMAGECALLBACK)))
     5718    }
     5719  }
     5720
     5721  if ((lpLVItem->mask & LVIF_IMAGE) && (*piImage==I_IMAGECALLBACK))
    54865722  {
    54875723    dispInfo.item.mask |= LVIF_IMAGE;
    54885724  }
    54895725
    5490   if ((lpLVItem->mask & LVIF_TEXT) &&
    5491       ((ppszText==NULL) || (*ppszText == LPSTR_TEXTCALLBACKA)))
     5726  if ((lpLVItem->mask & LVIF_TEXT) && !is_textW(*ppszText))
    54925727  {
    54935728    dispInfo.item.mask |= LVIF_TEXT;
    54945729    dispInfo.item.pszText = lpLVItem->pszText;
    54955730    dispInfo.item.cchTextMax = lpLVItem->cchTextMax;
     5731    if (dispInfo.item.pszText && lpLVItem->cchTextMax > 0)
     5732      *dispInfo.item.pszText = '\0';
     5733    if (dispInfo.item.pszText && (*ppszText == NULL))
     5734      *dispInfo.item.pszText = '\0';
    54965735  }
    54975736
     
    54995738  {
    55005739    /* We don't have all the requested info, query the application */
    5501     dispInfo.hdr.hwndFrom = hwnd;
    5502     dispInfo.hdr.idFrom = lCtrlId;
    5503     dispInfo.hdr.code = LVN_GETDISPINFOA;
    55045740    dispInfo.item.iItem = lpLVItem->iItem;
    55055741    dispInfo.item.iSubItem = lpLVItem->iSubItem;
    55065742    dispInfo.item.lParam = lpItem->lParam;
    5507     ListView_Notify(GetParent(hwnd), lCtrlId, &dispInfo);
     5743    dispinfo_notifyT(hwnd, LVN_GETDISPINFOW, &dispInfo, isW);
     5744    TRACE("   getdispinfo(2):lpLVItem=%s\n", debuglvitem_t(&dispInfo.item, isW));
    55085745  }
    55095746
     
    55115748  {
    55125749    lpLVItem->iImage = dispInfo.item.iImage;
    5513     if ((dispInfo.item.mask & LVIF_DI_SETITEM) && piImage)
    5514     {
     5750    if ((dispInfo.item.mask & LVIF_DI_SETITEM) && (*piImage==I_IMAGECALLBACK))
    55155751      *piImage = dispInfo.item.iImage;
    5516     }
    55175752  }
    55185753  else if (lpLVItem->mask & LVIF_IMAGE)
     
    55245759  {
    55255760    lpLVItem->lParam = dispInfo.item.lParam;
    5526     if ((dispInfo.item.mask & LVIF_DI_SETITEM) && plParam)
    5527     {
     5761    if (dispInfo.item.mask & LVIF_DI_SETITEM)
    55285762      *plParam = dispInfo.item.lParam;
    5529     }
    55305763  }
    55315764  else if (lpLVItem->mask & LVIF_PARAM)
    5532   {
    55335765    lpLVItem->lParam = lpItem->lParam;
    5534   }
    55355766
    55365767#ifdef __WIN32OS2__
     
    55425773  if (dispInfo.item.mask & LVIF_TEXT)
    55435774  {
    5544     if ((dispInfo.item.mask & LVIF_DI_SETITEM) && (ppszText != NULL))
    5545     {
    5546 #ifdef __WIN32OS2__
    5547       dprintf(("LISTVIEW_GetItemA *ppszText (%x), dispInfo.item.pszText (%x);", *ppszText, dispInfo.item.pszText));
    5548       if (ppszText && (UINT)*ppszText != -1) {
    5549         Str_SetPtrA(ppszText, dispInfo.item.pszText);
    5550       } /* endif */
    5551 #else
    5552       Str_SetPtrA(ppszText, dispInfo.item.pszText);
    5553 #endif
    5554     }
     5775    if ((dispInfo.item.mask & LVIF_DI_SETITEM) && *ppszText)
     5776      textsetptrT(ppszText, dispInfo.item.pszText, isW);
     5777   
    55555778    /* If lpLVItem->pszText==dispInfo.item.pszText a copy is unnecessary, but */
    55565779    /* some apps give a new pointer in ListView_Notify so we can't be sure.  */
    5557     if (lpLVItem->pszText!=dispInfo.item.pszText) {
    5558       lstrcpynA(lpLVItem->pszText, dispInfo.item.pszText, lpLVItem->cchTextMax);
    5559     }
    5560 
    5561     if (ppszText == NULL)
    5562     {
    5563        lstrcpynA(lpLVItem->pszText, "", lpLVItem->cchTextMax);
    5564     }
     5780    if (lpLVItem->pszText != dispInfo.item.pszText)
     5781        textcpynT(lpLVItem->pszText, isW, dispInfo.item.pszText, isW, lpLVItem->cchTextMax);
     5782   
    55655783  }
    55665784  else if (lpLVItem->mask & LVIF_TEXT)
    55675785  {
    5568     if (internal==TRUE)
    5569     {
    5570       lpLVItem->pszText=*ppszText;
    5571     } else {
    5572       lstrcpynA(lpLVItem->pszText, *ppszText, lpLVItem->cchTextMax);
    5573     }
     5786    if (internal) lpLVItem->pszText = *ppszText;
     5787    else textcpynT(lpLVItem->pszText, isW, *ppszText, TRUE, lpLVItem->cchTextMax);
    55745788  }
    55755789
     
    55835797
    55845798      lpLVItem->state &= ~LVIS_SELECTED;
    5585       if ((dispInfo.item.stateMask & LVIS_SELECTED) &&
    5586          (LISTVIEW_IsSelected(hwnd,dispInfo.item.iItem)))
     5799      if ((dispInfo.item.stateMask & LVIS_SELECTED) && 
     5800          LISTVIEW_IsSelected(hwnd,dispInfo.item.iItem))
    55875801        lpLVItem->state |= LVIS_SELECTED;
    55885802    }
     
    55925806
    55935807      lpLVItem->state &= ~LVIS_SELECTED;
    5594       if ((lpLVItem->stateMask & LVIS_SELECTED) &&
    5595           (LISTVIEW_IsSelected(hwnd,lpLVItem->iItem)))
     5808      if ((lpLVItem->stateMask & LVIS_SELECTED) && 
     5809          LISTVIEW_IsSelected(hwnd,lpLVItem->iItem))
    55965810         lpLVItem->state |= LVIS_SELECTED;
    55975811    }
    55985812
    55995813    if (lpLVItem->mask & LVIF_PARAM)
    5600     {
    56015814      lpLVItem->lParam = lpItem->lParam;
    5602     }
    56035815
    56045816    if (lpLVItem->mask & LVIF_INDENT)
    5605     {
    56065817      lpLVItem->iIndent = lpItem->iIndent;
    5607     }
    56085818  }
    56095819
     
    56115821}
    56125822
    5613 /* LISTVIEW_GetItemW */
    56145823/* LISTVIEW_GetHotCursor */
    56155824
     
    56275836static LRESULT LISTVIEW_GetHotItem(HWND hwnd)
    56285837{
    5629     LISTVIEW_INFO *infoPtr;
    5630 
    5631     /* make sure we can get the listview info */
    5632     if (!(infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0)))
    5633     return (-1);
    5634 
    5635     return (infoPtr->nHotItem);
     5838  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     5839
     5840  return infoPtr->nHotItem;
    56365841}
    56375842
     
    56415846 * DESCRIPTION:
    56425847 * Retrieves the number of items in the listview control.
    5643  *
    5644  * PARAMETER(S):
    5645  * [I] HWND : window handle
    5646  *
     5848 * 
     5849 * PARAMETER(S):
     5850 * [I] HWND : window handle
     5851 * 
    56475852 * RETURN:
    56485853 * Number of items.
     
    56505855static LRESULT LISTVIEW_GetItemCount(HWND hwnd)
    56515856{
    5652   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     5857  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    56535858
    56545859  return GETITEMCOUNT(infoPtr);
     
    56575862/***
    56585863 * DESCRIPTION:
    5659  * Retrieves the position (upper-left) of the listview control item.
    5660  *
     5864 * Retrieves the rectangle enclosing the item icon and text.
     5865 * 
    56615866 * PARAMETER(S):
    56625867 * [I] HWND : window handle
    56635868 * [I] INT : item index
    5664  * [O] LPPOINT : coordinate information
     5869 * [O] LPRECT : coordinate information
    56655870 *
    56665871 * RETURN:
     
    56685873 *   FAILURE : FALSE
    56695874 */
    5670 static BOOL LISTVIEW_GetItemPosition(HWND hwnd, INT nItem,
    5671                                      LPPOINT lpptPosition)
    5672 {
    5673   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    5674   UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
     5875static BOOL LISTVIEW_GetItemBoundBox(HWND hwnd, INT nItem, LPRECT lpRect)
     5876{
     5877  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     5878  LONG lStyle = GetWindowLongW(hwnd, GWL_STYLE);
     5879  UINT uView = lStyle & LVS_TYPEMASK;
    56755880  BOOL bResult = FALSE;
    56765881  HDPA hdpaSubItems;
     
    56795884  INT nRow;
    56805885
    5681   TRACE("(hwnd=%x,nItem=%d,lpptPosition=%p)\n", hwnd, nItem,
    5682         lpptPosition);
    5683 
    5684   if ((nItem >= 0) && (nItem < GETITEMCOUNT(infoPtr)) &&
    5685       (lpptPosition != NULL))
     5886  TRACE("(hwnd=%x,nItem=%d,lpRect=%p)\n", hwnd, nItem, lpRect);
     5887 
     5888  if ((nItem >= 0) && (nItem < GETITEMCOUNT(infoPtr)) &&
     5889      (lpRect != NULL))
    56865890  {
    56875891    if (uView == LVS_LIST)
     
    56955899        if (nRow == 0)
    56965900        {
    5697           lpptPosition->x = nItem / nCountPerColumn * infoPtr->nItemWidth;
    5698           lpptPosition->y = 0;
     5901          lpRect->left = nItem / nCountPerColumn * infoPtr->nItemWidth;
     5902          lpRect->top = 0;
    56995903        }
    57005904        else
    57015905        {
    5702           lpptPosition->x = (nItem / nCountPerColumn -1) * infoPtr->nItemWidth;
    5703           lpptPosition->y = (nRow + nCountPerColumn) * infoPtr->nItemHeight;
     5906          lpRect->left = (nItem / nCountPerColumn -1) * infoPtr->nItemWidth;
     5907          lpRect->top = (nRow + nCountPerColumn) * infoPtr->nItemHeight;
    57045908        }
    57055909      }
    57065910      else
    57075911      {
    5708         lpptPosition->x = nItem / nCountPerColumn * infoPtr->nItemWidth;
    5709         lpptPosition->y = nItem % nCountPerColumn * infoPtr->nItemHeight;
     5912        lpRect->left = nItem / nCountPerColumn * infoPtr->nItemWidth;
     5913        lpRect->top = nItem % nCountPerColumn * infoPtr->nItemHeight;
    57105914      }
    57115915    }
    57125916    else if (uView == LVS_REPORT)
    57135917    {
    5714       SCROLLINFO scrollInfo;
    57155918      bResult = TRUE;
    5716       lpptPosition->x = REPORT_MARGINX;
    5717       lpptPosition->y = ((nItem - ListView_GetTopIndex(hwnd)) *
     5919      lpRect->left = REPORT_MARGINX;
     5920      lpRect->top = ((nItem - ListView_GetTopIndex(hwnd)) *
    57185921                         infoPtr->nItemHeight) + infoPtr->rcList.top;
    57195922
    5720       /* Adjust position by scrollbar offset */
    5721       ZeroMemory(&scrollInfo, sizeof(SCROLLINFO));
    5722       scrollInfo.cbSize = sizeof(SCROLLINFO);
    5723       scrollInfo.fMask = SIF_POS;
    5724       GetScrollInfo(hwnd, SB_HORZ, &scrollInfo);
    5725       lpptPosition->x -= scrollInfo.nPos * LISTVIEW_SCROLL_DIV_SIZE;
    5726     }
    5727     else
    5728     {
    5729       hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, nItem);
    5730       if (hdpaSubItems != NULL)
     5923      if (!(lStyle & LVS_NOSCROLL))
    57315924      {
    5732         lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0);
    5733         if (lpItem != NULL)
     5925        SCROLLINFO scrollInfo;
     5926        /* Adjust position by scrollbar offset */
     5927        ZeroMemory(&scrollInfo, sizeof(SCROLLINFO));
     5928        scrollInfo.cbSize = sizeof(SCROLLINFO);
     5929        scrollInfo.fMask = SIF_POS;
     5930        GetScrollInfo(hwnd, SB_HORZ, &scrollInfo);
     5931        lpRect->left -= scrollInfo.nPos * LISTVIEW_SCROLL_DIV_SIZE;
     5932      }
     5933    }
     5934    else /* either LVS_ICON or LVS_SMALLICON */
     5935    {
     5936      if ((hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, nItem)))
     5937      {
     5938        if ((lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0)))
    57345939        {
    57355940          bResult = TRUE;
    5736           lpptPosition->x = lpItem->ptPosition.x;
    5737           lpptPosition->y = lpItem->ptPosition.y;
     5941          lpRect->left = lpItem->ptPosition.x;
     5942          lpRect->top = lpItem->ptPosition.y;
    57385943        }
    57395944      }
    57405945    }
    57415946  }
     5947  lpRect->right = lpRect->left + infoPtr->nItemWidth;
     5948  lpRect->bottom = lpRect->top + infoPtr->nItemHeight;
     5949  TRACE("result %s: (%d,%d)-(%d,%d)\n", bResult ? "TRUE" : "FALSE",
     5950        lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
    57425951  return bResult;
    57435952}
     
    57455954/***
    57465955 * DESCRIPTION:
     5956 * Retrieves the position (upper-left) of the listview control item.
     5957 * Note that for LVS_ICON style, the upper-left is that of the icon
     5958 * and not the bounding box.
     5959 *
     5960 * PARAMETER(S):
     5961 * [I] HWND : window handle
     5962 * [I] INT : item index
     5963 * [O] LPPOINT : coordinate information
     5964 *
     5965 * RETURN:
     5966 *   SUCCESS : TRUE
     5967 *   FAILURE : FALSE
     5968 */
     5969static BOOL LISTVIEW_GetItemPosition(HWND hwnd, INT nItem, LPPOINT lpptPosition)
     5970{
     5971  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     5972  UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
     5973  BOOL bResult = FALSE;
     5974  RECT rcBounding;
     5975
     5976  TRACE("(hwnd=%x, nItem=%d, lpptPosition=%p)\n", hwnd, nItem, lpptPosition);
     5977
     5978  if ((nItem >= 0) && (nItem < GETITEMCOUNT(infoPtr)) &&
     5979      (lpptPosition != NULL))
     5980  {
     5981    bResult = LISTVIEW_GetItemBoundBox(hwnd, nItem, &rcBounding);
     5982    lpptPosition->x = rcBounding.left;
     5983    lpptPosition->y = rcBounding.top;
     5984    if (uView == LVS_ICON)
     5985    {
     5986       lpptPosition->y += ICON_TOP_PADDING;
     5987       lpptPosition->x += (infoPtr->iconSpacing.cx - infoPtr->iconSize.cx) / 2;
     5988    }
     5989    TRACE("result %s (%ld,%ld)\n", bResult ? "TRUE" : "FALSE",
     5990          lpptPosition->x, lpptPosition->y);
     5991   }
     5992   return bResult;
     5993}
     5994
     5995/***
     5996 * Update the bounding rectangle around the text under a large icon.
     5997 * This depends on whether it has the focus or not.
     5998 * On entry the rectangle's top, left and right should be set.
     5999 * On return the bottom will also be set and the width may have been
     6000 * modified.
     6001 *
     6002 * This appears to be weird, even in the Microsoft implementation.
     6003 */
     6004
     6005static void ListView_UpdateLargeItemLabelRect (
     6006        HWND hwnd,                    /* The window of the listview */
     6007        const LISTVIEW_INFO *infoPtr, /* The listview itself */
     6008        int nItem, /* The item for which we are calculating this */
     6009        RECT *rect) /* The rectangle to be updated */
     6010{
     6011    HDC hdc = GetDC (hwnd);
     6012    HFONT hOldFont = SelectObject (hdc, infoPtr->hFont);
     6013
     6014    if (infoPtr->bFocus && infoPtr->nFocusedItem == nItem)
     6015    {
     6016        /* We (aim to) display the full text.  In Windows 95 it appears to
     6017         * calculate the size assuming the specified font and then it draws
     6018         * the text in that region with the specified font except scaled to
     6019         * 10 point (or the height of the system font or ...).  Thus if the
     6020         * window has 24 point Helvetica the highlit rectangle will be
     6021         * taller than the text and if it is 7 point Helvetica then the text
     6022         * will be clipped.
     6023         * For now we will simply say that it is the correct size to display
     6024         * the text in the specified font.
     6025         */
     6026        LVITEMW lvItem;
     6027        lvItem.mask = LVIF_TEXT;
     6028        lvItem.iItem = nItem;
     6029        lvItem.iSubItem = 0;
     6030        /* We will specify INTERNAL and so will receive back a const
     6031         * pointer to the text, rather than specifying a buffer to which
     6032         * to copy it.
     6033         */
     6034        LISTVIEW_GetItemW (hwnd, &lvItem, TRUE);
     6035        DrawTextW (hdc, lvItem.pszText, -1, rect, DT_CALCRECT |
     6036                        DT_NOCLIP | DT_EDITCONTROL | DT_TOP | DT_CENTER |
     6037                        DT_WORDBREAK | DT_NOPREFIX);
     6038        /* Maintain this DT_* list in line with LISTVIEW_DrawLargeItem */
     6039    }
     6040    else
     6041    {
     6042        /* As far as I can see the text region seems to be trying to be
     6043         * "tall enough for two lines of text".  Once again (comctl32.dll ver
     6044         * 5.81?) it measures this on the basis of the selected font and then
     6045         * draws it with the same font except in 10 point size.  This can lead
     6046         * to more or less than the two rows appearing.
     6047         * Question; are we  supposed to be including DT_EXTERNALLEADING?
     6048         * Question; should the width be shrunk to the space required to
     6049         * display the two lines?
     6050         */
     6051        rect->bottom = rect->top + 2 * infoPtr->ntmHeight;
     6052    }
     6053
     6054    SelectObject (hdc, hOldFont);
     6055    ReleaseDC (hwnd, hdc);
     6056}
     6057
     6058/***
     6059 * DESCRIPTION:
    57476060 * Retrieves the bounding rectangle for a listview control item.
    5748  *
     6061 * 
    57496062 * PARAMETER(S):
    57506063 * [I] HWND : window handle
     
    57596072 *     LVIR_LABEL Returns the bounding rectangle of the item text.
    57606073 *     LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
    5761  *  rectangles, but excludes columns in report view.
    5762  *
     6074 *      rectangles, but excludes columns in report view.
     6075 * 
    57636076 * RETURN:
    57646077 *   SUCCESS : TRUE
    57656078 *   FAILURE : FALSE
     6079 *
     6080 * NOTES
     6081 *   Note that the bounding rectangle of the label in the LVS_ICON view depends
     6082 *   upon whether the window has the focus currently and on whether the item
     6083 *   is the one with the focus.  Ensure that the control's record of which
     6084 *   item has the focus agrees with the items' records.
    57666085 */
    57676086static LRESULT LISTVIEW_GetItemRect(HWND hwnd, INT nItem, LPRECT lprc)
    57686087{
    5769   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    5770   UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
     6088  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     6089  UINT uView = GetWindowLongW(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    57716090  BOOL bResult = FALSE;
    57726091  POINT ptOrigin;
    57736092  POINT ptItem;
    5774   HDC hdc;
    5775   HFONT hOldFont;
    57766093  INT nLeftPos;
    57776094  INT nLabelWidth;
    57786095  INT nIndent;
    5779   TEXTMETRICA tm;
    5780   LVITEMA lvItem;
     6096  LVITEMW lvItem;
     6097  RECT rcInternal;
    57816098
    57826099  TRACE("(hwnd=%x, nItem=%d, lprc=%p)\n", hwnd, nItem, lprc);
     
    57846101  if (uView & LVS_REPORT)
    57856102  {
    5786     ZeroMemory(&lvItem, sizeof(LVITEMA));
     6103    ZeroMemory(&lvItem, sizeof(lvItem));
    57876104    lvItem.mask = LVIF_INDENT;
    57886105    lvItem.iItem = nItem;
    57896106    lvItem.iSubItem = 0;
    5790     LISTVIEW_GetItemA(hwnd, &lvItem, TRUE);
     6107    LISTVIEW_GetItemW(hwnd, &lvItem, TRUE);
    57916108
    57926109    /* do indent */
    57936110    if (lvItem.iIndent>0 && infoPtr->iconSize.cx > 0)
    5794     {
    5795       nIndent = infoPtr->iconSize.cx * lvItem.iIndent;
    5796     }
     6111      nIndent = infoPtr->iconSize.cx * lvItem.iIndent;
    57976112    else
    5798      nIndent = 0;
     6113      nIndent = 0;
    57996114  }
    58006115  else
    58016116    nIndent = 0;
    5802 
     6117 
    58036118  if ((nItem >= 0) && (nItem < GETITEMCOUNT(infoPtr)) && (lprc != NULL))
    58046119  {
    5805     if (ListView_GetItemPosition(hwnd, nItem, &ptItem) != FALSE)
    5806     {
    5807       switch(lprc->left)
    5808       {
     6120      switch(lprc->left) 
     6121      { 
    58096122      case LVIR_ICON:
     6123        if (!ListView_GetItemPosition(hwnd, nItem, &ptItem)) break;
    58106124        if (uView == LVS_ICON)
    58116125        {
     
    58186132              lprc->top = ptItem.y + ptOrigin.y;
    58196133              lprc->right = lprc->left + infoPtr->iconSize.cx;
    5820               lprc->bottom = (lprc->top + infoPtr->iconSize.cy +
     6134              lprc->bottom = (lprc->top + infoPtr->iconSize.cy + 
    58216135                              ICON_BOTTOM_PADDING + ICON_TOP_PADDING);
    58226136            }
     
    58346148            if (infoPtr->himlState != NULL)
    58356149              lprc->left += infoPtr->iconSize.cx;
    5836 
     6150             
    58376151            if (infoPtr->himlSmall != NULL)
    58386152              lprc->right = lprc->left + infoPtr->iconSize.cx;
     
    58416155          }
    58426156        }
    5843         else
     6157        else 
    58446158        {
    58456159          bResult = TRUE;
     
    58516165
    58526166          if (infoPtr->himlState != NULL)
    5853           {
    58546167            lprc->left += infoPtr->iconSize.cx;
    5855           }
    5856 
     6168           
    58576169          if (infoPtr->himlSmall != NULL)
    5858           {
    58596170            lprc->right = lprc->left + infoPtr->iconSize.cx;
    5860           }
    58616171          else
    5862           {
    58636172            lprc->right = lprc->left;
    5864           }
    58656173        }
    58666174        break;
    58676175
    58686176      case LVIR_LABEL:
     6177        if (!ListView_GetItemPosition(hwnd, nItem, &ptItem)) break;
    58696178        if (uView == LVS_ICON)
    58706179        {
     
    58766185              lprc->left = ptItem.x + ptOrigin.x;
    58776186              lprc->top = (ptItem.y + ptOrigin.y + infoPtr->iconSize.cy +
    5878                            ICON_BOTTOM_PADDING + ICON_TOP_PADDING);
     6187                           ICON_BOTTOM_PADDING);
    58796188              nLabelWidth = LISTVIEW_GetLabelWidth(hwnd, nItem);
    58806189              if (infoPtr->iconSpacing.cx - nLabelWidth > 1)
     
    58876196                lprc->left += 1;
    58886197                lprc->right = lprc->left + infoPtr->iconSpacing.cx - 1;
     6198                ListView_UpdateLargeItemLabelRect (hwnd, infoPtr, nItem, lprc);
    58896199              }
    5890 
    5891               hdc = GetDC(hwnd);
    5892               hOldFont = SelectObject(hdc, infoPtr->hFont);
    5893               GetTextMetricsA(hdc, &tm);
    5894               lprc->bottom = lprc->top + tm.tmHeight + HEIGHT_PADDING;
    5895               SelectObject(hdc, hOldFont);
    5896               ReleaseDC(hwnd, hdc);
    5897             }
     6200            }             
    58986201          }
    58996202        }
     
    59036206          {
    59046207            bResult = TRUE;
    5905             nLeftPos = lprc->left = ptItem.x + ptOrigin.x;
     6208            nLeftPos = lprc->left = ptItem.x + ptOrigin.x; 
    59066209            lprc->top = ptItem.y + ptOrigin.y;
    59076210            lprc->bottom = lprc->top + infoPtr->nItemHeight;
    5908 
     6211           
    59096212            if (infoPtr->himlState != NULL)
    5910             {
    59116213              lprc->left += infoPtr->iconSize.cx;
    5912             }
    5913 
     6214           
    59146215            if (infoPtr->himlSmall != NULL)
    5915             {
    59166216              lprc->left += infoPtr->iconSize.cx;
    5917             }
    5918 
     6217           
    59196218            nLabelWidth = LISTVIEW_GetLabelWidth(hwnd, nItem);
    59206219            nLabelWidth += TRAILING_PADDING;
    59216220            if (lprc->left + nLabelWidth < nLeftPos + infoPtr->nItemWidth)
    5922             {
    59236221              lprc->right = lprc->left + nLabelWidth;
    5924             }
    59256222            else
    5926             {
    59276223              lprc->right = nLeftPos + infoPtr->nItemWidth;
    5928             }
    59296224          }
    59306225        }
     
    59326227        {
    59336228          bResult = TRUE;
    5934           if (uView & LVS_REPORT)
     6229          if (uView == LVS_REPORT)
    59356230            nLeftPos = lprc->left = ptItem.x + nIndent;
    5936           else
    5937             nLeftPos = lprc->left = ptItem.x;
     6231          else 
     6232            nLeftPos = lprc->left = ptItem.x; 
    59386233          lprc->top = ptItem.y;
    59396234          lprc->bottom = lprc->top + infoPtr->nItemHeight;
    59406235
    59416236          if (infoPtr->himlState != NULL)
     6237            lprc->left += infoPtr->iconSize.cx;
     6238
     6239          if (infoPtr->himlSmall != NULL)
     6240            lprc->left += infoPtr->iconSize.cx;
     6241
     6242          if (uView != LVS_REPORT)
    59426243          {
    5943             lprc->left += infoPtr->iconSize.cx;
     6244            nLabelWidth = LISTVIEW_GetLabelWidth(hwnd, nItem);
     6245            nLabelWidth += TRAILING_PADDING;
     6246            if (infoPtr->himlSmall)
     6247              nLabelWidth += IMAGE_PADDING;
    59446248          }
    5945 
    5946           if (infoPtr->himlSmall != NULL)
    5947           {
    5948             lprc->left += infoPtr->iconSize.cx;
    5949           }
    5950 
    5951       nLabelWidth = LISTVIEW_GetLabelWidth(hwnd, nItem);
    5952           nLabelWidth += TRAILING_PADDING;
    5953           if (infoPtr->himlSmall)
    5954             nLabelWidth += IMAGE_PADDING;
    5955       if (lprc->left + nLabelWidth < nLeftPos + infoPtr->nItemWidth)
    5956       {
    5957         lprc->right = lprc->left + nLabelWidth;
    5958       }
    5959       else
    5960       {
    5961         lprc->right = nLeftPos + infoPtr->nItemWidth;
    5962       }
     6249          else
     6250            nLabelWidth = LISTVIEW_GetColumnWidth(hwnd, 0)-lprc->left;
     6251          if (lprc->left + nLabelWidth < nLeftPos + infoPtr->nItemWidth)
     6252            lprc->right = lprc->left + nLabelWidth;
     6253          else
     6254            lprc->right = nLeftPos + infoPtr->nItemWidth;
    59636255        }
    59646256        break;
    59656257
    59666258      case LVIR_BOUNDS:
     6259        if (!LISTVIEW_GetItemBoundBox(hwnd, nItem, &rcInternal)) break;
     6260        ptItem.x = rcInternal.left;
     6261        ptItem.y = rcInternal.top;
     6262        if (uView == LVS_ICON)
     6263        {
     6264          if (infoPtr->himlNormal != NULL)
     6265          {
     6266            if (LISTVIEW_GetOrigin(hwnd, &ptOrigin) != FALSE)
     6267            {
     6268              RECT label_rect;
     6269              INT text_left, text_right, icon_left, text_pos_x;
     6270              /* for style LVS_ICON bounds
     6271               *            left = min(icon.left, text.left)
     6272               *            right = max(icon.right, text.right)
     6273               *            top = boundbox.top + NOTHITABLE
     6274               *            bottom = text.bottom + 1
     6275               */
     6276              bResult = TRUE;
     6277              icon_left = text_left = ptItem.x;
     6278 
     6279              /* Correct ptItem to icon upper-left */
     6280              icon_left += (infoPtr->nItemWidth - infoPtr->iconSize.cx)/2;
     6281              ptItem.y += ICON_TOP_PADDING;
     6282 
     6283              /* Compute the label left and right */
     6284               nLabelWidth = LISTVIEW_GetLabelWidth(hwnd, nItem);
     6285               text_pos_x = infoPtr->iconSpacing.cx - 2*CAPTION_BORDER - nLabelWidth;
     6286               if (text_pos_x > 1)
     6287               {
     6288                 text_left += text_pos_x / 2;
     6289                 text_right = text_left + nLabelWidth + 2*CAPTION_BORDER;
     6290               }
     6291               else
     6292               {
     6293                 text_left += 1;
     6294                 text_right = text_left + infoPtr->iconSpacing.cx - 1;
     6295               }
     6296 
     6297              /* Compute rectangle w/o the text height */
     6298               lprc->left = min(icon_left, text_left) + ptOrigin.x;
     6299               lprc->right = max(icon_left + infoPtr->iconSize.cx,
     6300                                text_right) + ptOrigin.x;
     6301               lprc->top = ptItem.y + ptOrigin.y - ICON_TOP_PADDING_HITABLE;
     6302               lprc->bottom = lprc->top + ICON_TOP_PADDING_HITABLE
     6303                             + infoPtr->iconSize.cy + 1
     6304                              + ICON_BOTTOM_PADDING;
     6305 
     6306               CopyRect (&label_rect, lprc);
     6307               label_rect.top = lprc->bottom;
     6308               ListView_UpdateLargeItemLabelRect (hwnd, infoPtr, nItem, &label_rect);
     6309               UnionRect (lprc, lprc, &label_rect);
     6310            }
     6311          }
     6312        }
     6313        else if (uView == LVS_SMALLICON)
     6314        {
     6315          if (LISTVIEW_GetOrigin(hwnd, &ptOrigin) != FALSE)
     6316          {
     6317            bResult = TRUE;
     6318            lprc->left = ptItem.x + ptOrigin.x;
     6319            lprc->right = lprc->left;
     6320            lprc->top = ptItem.y + ptOrigin.y;
     6321            lprc->bottom = lprc->top + infoPtr->nItemHeight;
     6322            if (infoPtr->himlState != NULL)
     6323              lprc->right += infoPtr->iconSize.cx;
     6324            if (infoPtr->himlSmall != NULL)
     6325              lprc->right += infoPtr->iconSize.cx;
     6326
     6327            nLabelWidth = LISTVIEW_GetLabelWidth(hwnd, nItem);
     6328            nLabelWidth += TRAILING_PADDING;
     6329            if (infoPtr->himlSmall)
     6330              nLabelWidth += IMAGE_PADDING;
     6331            if (lprc->right + nLabelWidth < lprc->left + infoPtr->nItemWidth)
     6332              lprc->right += nLabelWidth;
     6333            else
     6334              lprc->right = lprc->left + infoPtr->nItemWidth;
     6335          }
     6336        }
     6337        else
     6338        {
     6339          bResult = TRUE;
     6340          lprc->left = ptItem.x;
     6341          if (!(infoPtr->dwExStyle&LVS_EX_FULLROWSELECT) && uView&LVS_REPORT)
     6342            lprc->left += nIndent;
     6343          lprc->right = lprc->left;
     6344          lprc->top = ptItem.y;
     6345          lprc->bottom = lprc->top + infoPtr->nItemHeight;
     6346
     6347          if ((infoPtr->dwExStyle & LVS_EX_FULLROWSELECT) || (uView == LVS_REPORT))
     6348          {
     6349            RECT br;
     6350            int nColumnCount = Header_GetItemCount(infoPtr->hwndHeader);
     6351            Header_GetItemRect(infoPtr->hwndHeader, nColumnCount-1, &br);
     6352
     6353            lprc->right = max(lprc->left, br.right - REPORT_MARGINX);
     6354          }
     6355          else
     6356          {
     6357             if (infoPtr->himlState != NULL)
     6358              lprc->right += infoPtr->iconSize.cx;
     6359
     6360            if (infoPtr->himlSmall != NULL)
     6361              lprc->right += infoPtr->iconSize.cx;
     6362
     6363            nLabelWidth = LISTVIEW_GetLabelWidth(hwnd, nItem);
     6364            nLabelWidth += TRAILING_PADDING;
     6365            if (lprc->right + nLabelWidth < lprc->left + infoPtr->nItemWidth)
     6366              lprc->right += nLabelWidth;
     6367            else
     6368              lprc->right = lprc->left + infoPtr->nItemWidth;
     6369          }
     6370        }
     6371        break;
     6372       
     6373      case LVIR_SELECTBOUNDS:
     6374        if (!ListView_GetItemPosition(hwnd, nItem, &ptItem)) break;
    59676375        if (uView == LVS_ICON)
    59686376        {
     
    59776385              lprc->bottom = lprc->top + infoPtr->iconSpacing.cy;
    59786386            }
    5979           }
     6387          } 
    59806388        }
    59816389        else if (uView == LVS_SMALLICON)
     
    59846392          {
    59856393            bResult = TRUE;
    5986             lprc->left = ptItem.x + ptOrigin.x;
    5987             lprc->right = lprc->left;
     6394            nLeftPos= lprc->left = ptItem.x + ptOrigin.x; 
    59886395            lprc->top = ptItem.y + ptOrigin.y;
    59896396            lprc->bottom = lprc->top + infoPtr->nItemHeight;
     6397           
    59906398            if (infoPtr->himlState != NULL)
    5991               lprc->right += infoPtr->iconSize.cx;
     6399              lprc->left += infoPtr->iconSize.cx;
     6400           
     6401            lprc->right = lprc->left;
     6402           
    59926403            if (infoPtr->himlSmall != NULL)
    59936404              lprc->right += infoPtr->iconSize.cx;
    5994 
    5995         nLabelWidth = LISTVIEW_GetLabelWidth(hwnd, nItem);
     6405           
     6406            nLabelWidth = LISTVIEW_GetLabelWidth(hwnd, nItem);
    59966407            nLabelWidth += TRAILING_PADDING;
    5997             if (infoPtr->himlSmall)
    5998               nLabelWidth += IMAGE_PADDING;
    5999         if (lprc->right + nLabelWidth < lprc->left + infoPtr->nItemWidth)
    6000         {
    6001           lprc->right += nLabelWidth;
    6002         }
    6003         else
    6004         {
    6005           lprc->right = lprc->left + infoPtr->nItemWidth;
    6006         }
    6007           }
    6008         }
    6009         else
    6010         {
    6011           bResult = TRUE;
    6012           lprc->left = ptItem.x;
    6013           if (!(infoPtr->dwExStyle&LVS_EX_FULLROWSELECT) && uView&LVS_REPORT)
    6014             lprc->left += nIndent;
    6015           lprc->right = lprc->left;
    6016           lprc->top = ptItem.y;
    6017           lprc->bottom = lprc->top + infoPtr->nItemHeight;
    6018 
    6019           if (infoPtr->dwExStyle & LVS_EX_FULLROWSELECT)
    6020       {
    6021         RECT br;
    6022         int nColumnCount = Header_GetItemCount(infoPtr->hwndHeader);
    6023         Header_GetItemRect(infoPtr->hwndHeader, nColumnCount-1, &br);
    6024 
    6025         lprc->right = max(lprc->left, br.right - REPORT_MARGINX);
    6026       }
    6027           else
    6028           {
    6029          if (infoPtr->himlState != NULL)
    6030             {
    6031               lprc->right += infoPtr->iconSize.cx;
    6032             }
    6033 
    6034             if (infoPtr->himlSmall != NULL)
    6035             {
    6036               lprc->right += infoPtr->iconSize.cx;
    6037             }
    6038 
    6039         nLabelWidth = LISTVIEW_GetLabelWidth(hwnd, nItem);
    6040             nLabelWidth += TRAILING_PADDING;
    6041         if (lprc->right + nLabelWidth < lprc->left + infoPtr->nItemWidth)
    6042         {
    6043           lprc->right += nLabelWidth;
    6044         }
    6045         else
    6046         {
    6047           lprc->right = lprc->left + infoPtr->nItemWidth;
    6048         }
    6049           }
    6050         }
    6051         break;
    6052 
    6053       case LVIR_SELECTBOUNDS:
    6054         if (uView == LVS_ICON)
    6055         {
    6056           if (infoPtr->himlNormal != NULL)
    6057           {
    6058             if (LISTVIEW_GetOrigin(hwnd, &ptOrigin) != FALSE)
    6059             {
    6060               bResult = TRUE;
    6061               lprc->left = ptItem.x + ptOrigin.x;
    6062               lprc->top = ptItem.y + ptOrigin.y;
    6063               lprc->right = lprc->left + infoPtr->iconSpacing.cx;
    6064               lprc->bottom = lprc->top + infoPtr->iconSpacing.cy;
    6065             }
    6066           }
    6067         }
    6068         else if (uView == LVS_SMALLICON)
    6069         {
    6070           if (LISTVIEW_GetOrigin(hwnd, &ptOrigin) != FALSE)
    6071           {
    6072             bResult = TRUE;
    6073             nLeftPos= lprc->left = ptItem.x + ptOrigin.x;
    6074             lprc->top = ptItem.y + ptOrigin.y;
    6075             lprc->bottom = lprc->top + infoPtr->nItemHeight;
    6076 
    6077             if (infoPtr->himlState != NULL)
    6078             {
    6079               lprc->left += infoPtr->iconSize.cx;
    6080             }
    6081 
    6082             lprc->right = lprc->left;
    6083 
    6084             if (infoPtr->himlSmall != NULL)
    6085             {
    6086               lprc->right += infoPtr->iconSize.cx;
    6087             }
    6088 
    6089         nLabelWidth = LISTVIEW_GetLabelWidth(hwnd, nItem);
    6090             nLabelWidth += TRAILING_PADDING;
    6091         if (lprc->right + nLabelWidth < nLeftPos + infoPtr->nItemWidth)
    6092         {
    6093           lprc->right += nLabelWidth;
    6094         }
    6095         else
    6096         {
    6097           lprc->right = nLeftPos + infoPtr->nItemWidth;
    6098         }
     6408            if (lprc->right + nLabelWidth < nLeftPos + infoPtr->nItemWidth)
     6409              lprc->right += nLabelWidth;
     6410            else
     6411              lprc->right = nLeftPos + infoPtr->nItemWidth;
    60996412          }
    61006413        }
     
    61036416          bResult = TRUE;
    61046417          if (!(infoPtr->dwExStyle&LVS_EX_FULLROWSELECT) && (uView&LVS_REPORT))
    6105         nLeftPos = lprc->left = ptItem.x + nIndent;
     6418            nLeftPos = lprc->left = ptItem.x + nIndent;
    61066419          else
    6107         nLeftPos = lprc->left = ptItem.x;
     6420            nLeftPos = lprc->left = ptItem.x;
    61086421          lprc->top = ptItem.y;
    61096422          lprc->bottom = lprc->top + infoPtr->nItemHeight;
    61106423
    61116424          if (infoPtr->himlState != NULL)
    6112           {
    61136425            lprc->left += infoPtr->iconSize.cx;
    6114           }
    6115 
     6426         
    61166427          lprc->right = lprc->left;
    6117 
     6428       
    61186429          if (infoPtr->dwExStyle & LVS_EX_FULLROWSELECT)
    61196430          {
    6120         RECT br;
    6121         int nColumnCount = Header_GetItemCount(infoPtr->hwndHeader);
    6122         Header_GetItemRect(infoPtr->hwndHeader, nColumnCount-1, &br);
     6431            RECT br;
     6432            int nColumnCount = Header_GetItemCount(infoPtr->hwndHeader);
     6433            Header_GetItemRect(infoPtr->hwndHeader, nColumnCount-1, &br);
    61236434
    61246435            lprc->right = max(lprc->left, br.right - REPORT_MARGINX);
     
    61276438          {
    61286439            if (infoPtr->himlSmall != NULL)
    6129             {
    61306440              lprc->right += infoPtr->iconSize.cx;
    6131             }
    6132 
    6133         nLabelWidth = LISTVIEW_GetLabelWidth(hwnd, nItem);
     6441
     6442            nLabelWidth = LISTVIEW_GetLabelWidth(hwnd, nItem);
    61346443            nLabelWidth += TRAILING_PADDING;
    61356444            if (infoPtr->himlSmall)
    61366445              nLabelWidth += IMAGE_PADDING;
    6137         if (lprc->right + nLabelWidth < nLeftPos + infoPtr->nItemWidth)
    6138         {
    6139           lprc->right += nLabelWidth;
    6140         }
    6141         else
    6142         {
    6143           lprc->right = nLeftPos + infoPtr->nItemWidth;
    6144         }
     6446            if (lprc->right + nLabelWidth < nLeftPos + infoPtr->nItemWidth)
     6447              lprc->right += nLabelWidth;
     6448            else
     6449              lprc->right = nLeftPos + infoPtr->nItemWidth;
    61456450          }
    61466451        }
    61476452        break;
    61486453      }
    6149     }
    61506454  }
    61516455#ifdef __WIN32OS2__
     
    61546458          }
    61556459#endif
     6460  TRACE("result %s (%d,%d)-(%d,%d)\n", bResult ? "TRUE" : "FALSE",
     6461        lprc->left, lprc->top, lprc->right, lprc->bottom);
     6462
    61566463  return bResult;
    61576464}
     
    61606467 * DESCRIPTION:
    61616468 * Retrieves the width of a label.
    6162  *
    6163  * PARAMETER(S):
    6164  * [I] HWND : window handle
    6165  *
     6469 * 
     6470 * PARAMETER(S):
     6471 * [I] HWND : window handle
     6472 * 
    61666473 * RETURN:
    61676474 *   SUCCESS : string width (in pixels)
     
    61706477static INT LISTVIEW_GetLabelWidth(HWND hwnd, INT nItem)
    61716478{
    6172   CHAR szDispText[DISP_TEXT_SIZE];
     6479  WCHAR szDispText[DISP_TEXT_SIZE] = { '\0' };
    61736480  INT nLabelWidth = 0;
    6174   LVITEMA lvItem;
     6481  LVITEMW lvItem;
    61756482
    61766483  TRACE("(hwnd=%x, nItem=%d)\n", hwnd, nItem);
    61776484
    6178   ZeroMemory(&lvItem, sizeof(LVITEMA));
     6485  ZeroMemory(&lvItem, sizeof(lvItem));
    61796486  lvItem.mask = LVIF_TEXT;
    61806487  lvItem.iItem = nItem;
    61816488  lvItem.cchTextMax = DISP_TEXT_SIZE;
    61826489  lvItem.pszText = szDispText;
    6183   if (LISTVIEW_GetItemA(hwnd, &lvItem, TRUE) != FALSE)
    6184   {
    6185     nLabelWidth = ListView_GetStringWidthA(hwnd, lvItem.pszText);
    6186   }
    6187 
     6490  if (LISTVIEW_GetItemW(hwnd, &lvItem, TRUE))
     6491    nLabelWidth = ListView_GetStringWidthW(hwnd, lvItem.pszText);
     6492   
    61886493  return nLabelWidth;
    61896494}
     
    61926497 * DESCRIPTION:
    61936498 * Retrieves the spacing between listview control items.
    6194  *
    6195  * PARAMETER(S):
    6196  * [I] HWND : window handle
    6197  * [I] BOOL : flag for small or large icon
     6499 * 
     6500 * PARAMETER(S):
     6501 * [I] HWND : window handle
     6502 * [I] BOOL : flag for small or large icon 
    61986503 *
    61996504 * RETURN:
     
    62026507static LRESULT LISTVIEW_GetItemSpacing(HWND hwnd, BOOL bSmall)
    62036508{
    6204   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     6509  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    62056510  LONG lResult;
    62066511
     
    62116516  else
    62126517  {
    6213     LONG style = GetWindowLongA(hwnd, GWL_STYLE);
     6518    LONG style = GetWindowLongW(hwnd, GWL_STYLE);
    62146519    if ((style & LVS_TYPEMASK) == LVS_ICON)
    6215     {
    62166520      lResult = MAKELONG(DEFAULT_COLUMN_WIDTH, GetSystemMetrics(SM_CXSMICON)+HEIGHT_PADDING);
    6217     }
    62186521    else
    6219     {
    62206522      lResult = MAKELONG(infoPtr->nItemWidth, infoPtr->nItemHeight);
    6221     }
    62226523  }
    62236524  return lResult;
     
    62276528 * DESCRIPTION:
    62286529 * Retrieves the state of a listview control item.
    6229  *
     6530 * 
    62306531 * PARAMETER(S):
    62316532 * [I] HWND : window handle
    62326533 * [I] INT : item index
    62336534 * [I] UINT : state mask
    6234  *
     6535 * 
    62356536 * RETURN:
    62366537 * State specified by the mask.
     
    62386539static LRESULT LISTVIEW_GetItemState(HWND hwnd, INT nItem, UINT uMask)
    62396540{
    6240   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    6241   LVITEMA lvItem;
     6541  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     6542  LVITEMW lvItem;
    62426543  UINT uState = 0;
    62436544
    62446545  if ((nItem >= 0) && (nItem < GETITEMCOUNT(infoPtr)))
    62456546  {
    6246     ZeroMemory(&lvItem, sizeof(LVITEMA));
     6547    ZeroMemory(&lvItem, sizeof(lvItem));
    62476548    lvItem.iItem = nItem;
    62486549    lvItem.stateMask = uMask;
    62496550    lvItem.mask = LVIF_STATE;
    6250     if (LISTVIEW_GetItemA(hwnd, &lvItem, TRUE) != FALSE)
    6251     {
     6551    if (LISTVIEW_GetItemW(hwnd, &lvItem, TRUE))
    62526552      uState = lvItem.state;
    6253     }
    62546553  }
    62556554
     
    62596558/***
    62606559 * DESCRIPTION:
    6261  * Retrieves the text of a listview control item or subitem.
    6262  *
    6263  * PARAMETER(S):
    6264  * [I] HWND : window handle
    6265  * [I] INT : item index
    6266  * [IO] LPLVITEMA : item information
    6267  *
     6560 * Retrieves the text of a listview control item or subitem.
     6561 *
     6562 * PARAMETER(S):
     6563 * [I] hwnd : window handle
     6564 * [I] nItem : item index
     6565 * [IO] lpLVItem : item information
     6566 * [I] isW :  TRUE if lpLVItem is Unicode
     6567 *
    62686568 * RETURN:
    62696569 *   SUCCESS : string length
    62706570 *   FAILURE : 0
    62716571 */
    6272 static LRESULT LISTVIEW_GetItemTextA(HWND hwnd, INT nItem, LPLVITEMA lpLVItem)
    6273 {
    6274   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     6572static LRESULT LISTVIEW_GetItemTextT(HWND hwnd, INT nItem, LPLVITEMW lpLVItem, BOOL isW)
     6573{
     6574  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    62756575  INT nLength = 0;
    6276 
     6576 
    62776577  if (lpLVItem != NULL)
    62786578  {
     
    62816581      lpLVItem->mask = LVIF_TEXT;
    62826582      lpLVItem->iItem = nItem;
    6283       if (LISTVIEW_GetItemA(hwnd, lpLVItem, FALSE) != FALSE)
    6284       {
    6285         nLength = lstrlenA(lpLVItem->pszText);
    6286       }
     6583      if (LISTVIEW_GetItemT(hwnd, lpLVItem, FALSE, isW))
     6584        nLength = textlenT(lpLVItem->pszText, isW);
    62876585    }
    62886586  }
     
    62946592 * DESCRIPTION:
    62956593 * Searches for an item based on properties + relationships.
    6296  *
     6594 * 
    62976595 * PARAMETER(S):
    62986596 * [I] HWND : window handle
    62996597 * [I] INT : item index
    63006598 * [I] INT : relationship flag
    6301  *
     6599 * 
    63026600 * RETURN:
    63036601 *   SUCCESS : item index
     
    63066604static LRESULT LISTVIEW_GetNextItem(HWND hwnd, INT nItem, UINT uFlags)
    63076605{
    6308   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    6309   UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
     6606  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     6607  UINT uView = GetWindowLongW(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    63106608  UINT uMask = 0;
    6311   LVFINDINFO lvFindInfo;
     6609  LVFINDINFOW lvFindInfo;
    63126610  INT nCountPerColumn;
    63136611  INT i;
    6314 
     6612 
    63156613  if ((nItem >= -1) && (nItem < GETITEMCOUNT(infoPtr)))
    6316   {
    6317     ZeroMemory(&lvFindInfo, sizeof(LVFINDINFO));
     6614  { 
     6615    ZeroMemory(&lvFindInfo, sizeof(lvFindInfo));
    63186616
    63196617    if (uFlags & LVNI_CUT)
    63206618      uMask |= LVIS_CUT;
    6321 
     6619   
    63226620    if (uFlags & LVNI_DROPHILITED)
    63236621      uMask |= LVIS_DROPHILITED;
    6324 
     6622         
    63256623    if (uFlags & LVNI_FOCUSED)
    63266624      uMask |= LVIS_FOCUSED;
     
    63456643        lvFindInfo.vkDirection = VK_UP;
    63466644        ListView_GetItemPosition(hwnd, nItem, &lvFindInfo.pt);
    6347         while ((nItem = ListView_FindItem(hwnd, nItem, &lvFindInfo)) != -1)
     6645        while ((nItem = ListView_FindItemW(hwnd, nItem, &lvFindInfo)) != -1)
    63486646        {
    63496647          if ((ListView_GetItemState(hwnd, nItem, uMask) & uMask) == uMask)
     
    63686666        lvFindInfo.vkDirection = VK_DOWN;
    63696667        ListView_GetItemPosition(hwnd, nItem, &lvFindInfo.pt);
    6370         while ((nItem = ListView_FindItem(hwnd, nItem, &lvFindInfo)) != -1)
     6668        while ((nItem = ListView_FindItemW(hwnd, nItem, &lvFindInfo)) != -1)
    63716669        {
    63726670          if ((ListView_GetItemState(hwnd, nItem, uMask) & uMask) == uMask)
     
    63926690        lvFindInfo.vkDirection = VK_LEFT;
    63936691        ListView_GetItemPosition(hwnd, nItem, &lvFindInfo.pt);
    6394         while ((nItem = ListView_FindItem(hwnd, nItem, &lvFindInfo)) != -1)
     6692        while ((nItem = ListView_FindItemW(hwnd, nItem, &lvFindInfo)) != -1)
    63956693        {
    63966694          if ((ListView_GetItemState(hwnd, nItem, uMask) & uMask) == uMask)
     
    64166714        lvFindInfo.vkDirection = VK_RIGHT;
    64176715        ListView_GetItemPosition(hwnd, nItem, &lvFindInfo.pt);
    6418         while ((nItem = ListView_FindItem(hwnd, nItem, &lvFindInfo)) != -1)
     6716        while ((nItem = ListView_FindItemW(hwnd, nItem, &lvFindInfo)) != -1)
    64196717        {
    64206718          if ((ListView_GetItemState(hwnd, nItem, uMask) & uMask) == uMask)
     
    64446742 * DESCRIPTION:
    64456743 * Retrieves the origin coordinates when in icon or small icon display mode.
    6446  *
     6744 * 
    64476745 * PARAMETER(S):
    64486746 * [I] HWND : window handle
    64496747 * [O] LPPOINT : coordinate information
    6450  *
     6748 * 
    64516749 * RETURN:
    64526750 *   SUCCESS : TRUE
     
    64556753static LRESULT LISTVIEW_GetOrigin(HWND hwnd, LPPOINT lpptOrigin)
    64566754{
    6457   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     6755  LONG lStyle = GetWindowLongW(hwnd, GWL_STYLE);
    64586756  UINT uView = lStyle & LVS_TYPEMASK;
    64596757  BOOL bResult = FALSE;
    6460 
     6758 
    64616759  TRACE("(hwnd=%x, lpptOrigin=%p)\n", hwnd, lpptOrigin);
    64626760
     
    64716769    {
    64726770      scrollInfo.fMask = SIF_POS;
    6473       if (GetScrollInfo(hwnd, SB_HORZ, &scrollInfo) != FALSE)
    6474       {
    6475         lpptOrigin->x = -scrollInfo.nPos * LISTVIEW_SCROLL_DIV_SIZE;
    6476       }
     6771      if (GetScrollInfo(hwnd, SB_HORZ, &scrollInfo) != FALSE)
     6772        lpptOrigin->x = -scrollInfo.nPos * LISTVIEW_SCROLL_DIV_SIZE;
    64776773    }
    64786774
     
    64816777      scrollInfo.fMask = SIF_POS;
    64826778      if (GetScrollInfo(hwnd, SB_VERT, &scrollInfo) != FALSE)
    6483       {
    64846779        lpptOrigin->y = -scrollInfo.nPos * LISTVIEW_SCROLL_DIV_SIZE;
    6485       }
    6486     }
    6487 
     6780    }
     6781     
    64886782    bResult = TRUE;
    64896783  }
    6490 
     6784 
    64916785  return bResult;
    64926786}
     
    64956789 * DESCRIPTION:
    64966790 * Retrieves the number of items that are marked as selected.
    6497  *
    6498  * PARAMETER(S):
    6499  * [I] HWND : window handle
    6500  *
     6791 * 
     6792 * PARAMETER(S):
     6793 * [I] HWND : window handle
     6794 * 
    65016795 * RETURN:
    65026796 * Number of items selected.
     
    65056799{
    65066800/* REDO THIS */
    6507   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     6801  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    65086802  INT nSelectedCount = 0;
    65096803  INT i;
     
    65126806  {
    65136807    if (ListView_GetItemState(hwnd, i, LVIS_SELECTED) & LVIS_SELECTED)
    6514     {
    65156808      nSelectedCount++;
    6516     }
    6517   }
    6518 
     6809  }
     6810 
    65196811  return nSelectedCount;
    65206812}
     
    65236815 * DESCRIPTION:
    65246816 * Retrieves item index that marks the start of a multiple selection.
    6525  *
    6526  * PARAMETER(S):
    6527  * [I] HWND : window handle
    6528  *
     6817 * 
     6818 * PARAMETER(S):
     6819 * [I] HWND : window handle
     6820 * 
    65296821 * RETURN:
    65306822 * Index number or -1 if there is no selection mark.
     
    65326824static LRESULT LISTVIEW_GetSelectionMark(HWND hwnd)
    65336825{
    6534   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     6826  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    65356827
    65366828  return infoPtr->nSelectionMark;
    65376829}
    65386830
     6831
    65396832/***
    65406833 * DESCRIPTION:
    65416834 * Retrieves the width of a string.
    6542  *
    6543  * PARAMETER(S):
    6544  * [I] HWND : window handle
    6545  *
     6835 *
     6836 * PARAMETER(S):
     6837 * [I] hwnd : window handle
     6838 * [I] lpszText : text string to process
     6839 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
     6840 *
    65466841 * RETURN:
    65476842 *   SUCCESS : string width (in pixels)
    65486843 *   FAILURE : zero
    65496844 */
     6845static LRESULT LISTVIEW_GetStringWidthT(HWND hwnd, LPCWSTR lpszText, BOOL isW)
     6846{
     6847  if (is_textT(lpszText, isW))
     6848  {
     6849    LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     6850    HFONT hFont = infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont;
     6851    HDC hdc = GetDC(hwnd);
     6852    HFONT hOldFont = SelectObject(hdc, hFont);
     6853    DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
     6854    SIZE stringSize;
     6855    ZeroMemory(&stringSize, sizeof(SIZE));
     6856    if (isW)
     6857      GetTextExtentPointW(hdc, lpszText, lstrlenW(lpszText), &stringSize);
     6858    else
     6859      GetTextExtentPointA(hdc, (LPCSTR)lpszText, lstrlenA((LPCSTR)lpszText), &stringSize);
     6860    SelectObject(hdc, hOldFont);
     6861    ReleaseDC(hwnd, hdc);
    65506862#ifdef __WIN32OS2__
    6551 static LRESULT LISTVIEW_GetStringWidth(HWND hwnd,HDC hdc,LPWSTR lpszText,BOOL unicode)
    6552 {
    6553   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    6554   DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
    6555   HFONT hFont, hOldFont;
    6556   SIZE stringSize;
    6557   BOOL ownDC = FALSE;
    6558 
    6559   ZeroMemory(&stringSize,sizeof(SIZE));
    6560   if (lpszText != NULL && lpszText != LPSTR_TEXTCALLBACKA)
    6561   {
    6562     if (!hdc)
    6563     {
    6564       hFont = infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont;
    6565       hdc = GetDC(hwnd);
    6566       hOldFont = SelectObject(hdc, hFont);
    6567       ownDC = TRUE;
    6568     }
    6569     if (unicode)
    6570       GetTextExtentPointW(hdc,lpszText,lstrlenW(lpszText),&stringSize);
    6571     else
    6572       GetTextExtentPointA(hdc,(LPSTR)lpszText,lstrlenA((LPSTR)lpszText),&stringSize);
    6573     if (ownDC)
    6574     {
    6575       SelectObject(hdc, hOldFont);
    6576       ReleaseDC(hwnd, hdc);
    6577     }
    65786863    if(dwStyle & LVS_OWNERDRAWFIXED) {
    65796864        /* Get item width */
     
    65876872        mis.itemHeight = 0;
    65886873        mis.itemWidth  = 0;
    6589         SendMessageA(GetParent(hwnd), WM_MEASUREITEM, id, (LPARAM)&mis );
     6874        if (isW) 
     6875         SendMessageW(GetParent(hwnd), WM_MEASUREITEM, id, (LPARAM)&mis );
     6876        else
     6877         SendMessageA(GetParent(hwnd), WM_MEASUREITEM, id, (LPARAM)&mis );
    65906878        stringSize.cx  = (mis.itemWidth) ? mis.itemWidth : infoPtr->nItemWidth;
    65916879    }
    6592   }
    6593 
    6594   return stringSize.cx;
    6595 }
    6596 #else
    6597 static LRESULT LISTVIEW_GetStringWidthA(HWND hwnd, LPCSTR lpszText)
    6598 {
    6599   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    6600   HFONT hFont, hOldFont;
    6601   SIZE stringSize;
    6602   HDC hdc;
    6603 
    6604   ZeroMemory(&stringSize, sizeof(SIZE));
    6605   if (lpszText != NULL && lpszText != LPSTR_TEXTCALLBACKA)
    6606   {
    6607     hFont = infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont;
    6608     hdc = GetDC(hwnd);
    6609     hOldFont = SelectObject(hdc, hFont);
    6610     GetTextExtentPointA(hdc, lpszText, lstrlenA(lpszText), &stringSize);
    6611     SelectObject(hdc, hOldFont);
    6612     ReleaseDC(hwnd, hdc);
    6613   }
    6614 
    6615   return stringSize.cx;
    6616 }
    66176880#endif
     6881    return stringSize.cx;
     6882  }
     6883  return 0;
     6884}
    66186885
    66196886/***
    66206887 * DESCRIPTION:
    66216888 * Retrieves the text backgound color.
    6622  *
    6623  * PARAMETER(S):
    6624  * [I] HWND : window handle
    6625  *
     6889 * 
     6890 * PARAMETER(S):
     6891 * [I] HWND : window handle
     6892 * 
    66266893 * RETURN:
    66276894 * COLORREF associated with the the background.
     
    66296896static LRESULT LISTVIEW_GetTextBkColor(HWND hwnd)
    66306897{
    6631   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongA(hwnd, 0);
     6898  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongW(hwnd, 0);
    66326899
    66336900  return infoPtr->clrTextBk;
     
    66376904 * DESCRIPTION:
    66386905 * Retrieves the text color.
    6639  *
    6640  * PARAMETER(S):
    6641  * [I] HWND : window handle
    6642  *
     6906 * 
     6907 * PARAMETER(S):
     6908 * [I] HWND : window handle
     6909 * 
    66436910 * RETURN:
    66446911 * COLORREF associated with the text.
     
    66466913static LRESULT LISTVIEW_GetTextColor(HWND hwnd)
    66476914{
    6648   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongA(hwnd, 0);
     6915  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongW(hwnd, 0);
    66496916
    66506917  return infoPtr->clrText;
     
    66536920/***
    66546921 * DESCRIPTION:
    6655  * Determines which section of the item was selected (if any).
    6656  *
    6657  * PARAMETER(S):
    6658  * [I] HWND : window handle
    6659  * [IO] LPLVHITTESTINFO : hit test information
     6922 * Determines item if a hit or closest if not
     6923 * 
     6924 * PARAMETER(S):
     6925 * [I] HWND : window handle
     6926 * [IO] LPLV_INTHIT : hit test information
    66606927 * [I] subitem : fill out iSubItem.
    66616928 *
    66626929 * RETURN:
    6663  *   SUCCESS : item index
     6930 *   SUCCESS : item index of hit
    66646931 *   FAILURE : -1
    66656932 */
    6666 static INT LISTVIEW_HitTestItem(
    6667   HWND hwnd, LPLVHITTESTINFO lpHitTestInfo, BOOL subitem
    6668 ) {
    6669   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     6933static INT LISTVIEW_SuperHitTestItem(HWND hwnd, LPLV_INTHIT lpInt, BOOL subitem)
     6934{
     6935  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     6936  LONG lStyle = GetWindowLongW(hwnd, GWL_STYLE);
     6937  UINT uView = lStyle & LVS_TYPEMASK;
     6938  INT i,topindex,bottomindex;
    66706939  RECT rcItem;
    6671   INT i,topindex,bottomindex;
    6672   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
    6673   UINT uView = lStyle & LVS_TYPEMASK;
    6674 
    6675 
    6676   TRACE("(hwnd=%x, x=%ld, y=%ld)\n", hwnd, lpHitTestInfo->pt.x,
    6677         lpHitTestInfo->pt.y);
     6940  DWORD xterm, yterm, dist;
     6941
     6942  TRACE("(hwnd=%x, x=%ld, y=%ld)\n", hwnd, lpInt->ht.pt.x, lpInt->ht.pt.y);
    66786943
    66796944  topindex = ListView_GetTopIndex(hwnd);
    66806945  if (uView == LVS_REPORT)
    66816946  {
    6682     bottomindex = topindex + LISTVIEW_GetCountPerColumn(hwnd) + 1;
     6947    bottomindex = topindex + LISTVIEW_GetCountPerColumn(hwnd) + 1; 
    66836948    bottomindex = min(bottomindex,GETITEMCOUNT(infoPtr));
    66846949  }
     
    66886953  }
    66896954
     6955  lpInt->distance = 0x7fffffff;
     6956  lpInt->iDistItem = -1;
     6957
    66906958  for (i = topindex; i < bottomindex; i++)
    66916959  {
    66926960    rcItem.left = LVIR_BOUNDS;
    6693     if (LISTVIEW_GetItemRect(hwnd, i, &rcItem) != FALSE)
    6694     {
    6695       if (PtInRect(&rcItem, lpHitTestInfo->pt) != FALSE)
     6961    if (LISTVIEW_GetItemRect(hwnd, i, &rcItem))
     6962    {
     6963      if (PtInRect(&rcItem, lpInt->ht.pt))
    66966964      {
    66976965        rcItem.left = LVIR_ICON;
    6698         if (LISTVIEW_GetItemRect(hwnd, i, &rcItem) != FALSE)
     6966        if (LISTVIEW_GetItemRect(hwnd, i, &rcItem))
    66996967        {
    6700           if (PtInRect(&rcItem, lpHitTestInfo->pt) != FALSE)
     6968          if (PtInRect(&rcItem, lpInt->ht.pt))
    67016969          {
    6702             lpHitTestInfo->flags = LVHT_ONITEMICON;
    6703             lpHitTestInfo->iItem = i;
    6704             if (subitem) lpHitTestInfo->iSubItem = 0;
     6970            lpInt->ht.flags = LVHT_ONITEMICON;
     6971            lpInt->ht.iItem = i;
     6972            if (subitem) lpInt->ht.iSubItem = 0;
    67056973            return i;
    67066974          }
    67076975        }
    6708 
     6976     
    67096977        rcItem.left = LVIR_LABEL;
    6710         if (LISTVIEW_GetItemRect(hwnd, i, &rcItem) != FALSE)
     6978        if (LISTVIEW_GetItemRect(hwnd, i, &rcItem))
    67116979        {
    6712           if (PtInRect(&rcItem, lpHitTestInfo->pt) != FALSE)
     6980          if (PtInRect(&rcItem, lpInt->ht.pt))
    67136981          {
    6714             lpHitTestInfo->flags = LVHT_ONITEMLABEL;
    6715             lpHitTestInfo->iItem = i;
    6716             if (subitem) lpHitTestInfo->iSubItem = 0;
     6982            lpInt->ht.flags = LVHT_ONITEMLABEL;
     6983            lpInt->ht.iItem = i;
     6984            if (subitem) lpInt->ht.iSubItem = 0;
    67176985            return i;
    67186986          }
    67196987        }
    6720 
    6721         lpHitTestInfo->flags = LVHT_ONITEMSTATEICON;
    6722         lpHitTestInfo->iItem = i;
    6723         if (subitem) lpHitTestInfo->iSubItem = 0;
     6988       
     6989        lpInt->ht.flags = LVHT_ONITEMSTATEICON;
     6990        lpInt->ht.iItem = i;
     6991        if (subitem) lpInt->ht.iSubItem = 0;
    67246992        return i;
    67256993      }
    6726     }
    6727   }
    6728 
    6729   lpHitTestInfo->flags = LVHT_NOWHERE;
     6994      else
     6995      {
     6996        /*
     6997         * Now compute distance from point to center of boundary
     6998         * box. Since we are only interested in the relative
     6999         * distance, we can skip the nasty square root operation
     7000         */
     7001        xterm = rcItem.left + (rcItem.right - rcItem.left)/2 - lpInt->ht.pt.x;
     7002        yterm = rcItem.top + (rcItem.bottom - rcItem.top)/2 - lpInt->ht.pt.y;
     7003        dist = xterm * xterm + yterm * yterm;
     7004        if (dist < lpInt->distance)
     7005        {
     7006          lpInt->distance = dist;
     7007          lpInt->iDistItem = i;
     7008        }
     7009      }
     7010    }
     7011  }
     7012     
     7013  lpInt->ht.flags = LVHT_NOWHERE;
     7014  TRACE("no hit, closest item %d, distance %ld\n", lpInt->iDistItem, lpInt->distance);
    67307015
    67317016  return -1;
    67327017}
    67337018
     7019 /***
     7020  * DESCRIPTION:
     7021  * Determines which section of the item was selected (if any).
     7022  *
     7023  * PARAMETER(S):
     7024  * [I] HWND : window handle
     7025  * [IO] LPLVHITTESTINFO : hit test information
     7026  * [I] subitem : fill out iSubItem.
     7027  *
     7028  * RETURN:
     7029  *   SUCCESS : item index
     7030  *   FAILURE : -1
     7031  */
     7032static INT LISTVIEW_HitTestItem(HWND hwnd, LPLVHITTESTINFO lpHitTestInfo, BOOL subitem)
     7033{
     7034  INT ret;
     7035  LV_INTHIT lv_inthit;
     7036
     7037  TRACE("(hwnd=%x, x=%ld, y=%ld)\n", hwnd, lpHitTestInfo->pt.x,
     7038        lpHitTestInfo->pt.y);
     7039
     7040  memcpy(&lv_inthit, lpHitTestInfo, sizeof(LVHITTESTINFO));
     7041  ret = LISTVIEW_SuperHitTestItem(hwnd, &lv_inthit, subitem);
     7042  memcpy(lpHitTestInfo, &lv_inthit, sizeof(LVHITTESTINFO));
     7043  return ret;
     7044}
     7045
    67347046/***
    67357047 * DESCRIPTION:
    67367048 * Determines which listview item is located at the specified position.
    6737  *
     7049 * 
    67387050 * PARAMETER(S):
    67397051 * [I] HWND : window handle
     
    67467058static LRESULT LISTVIEW_HitTest(HWND hwnd, LPLVHITTESTINFO lpHitTestInfo)
    67477059{
    6748   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     7060  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    67497061  INT nItem = -1;
    67507062
     
    67527064
    67537065  if (infoPtr->rcList.left > lpHitTestInfo->pt.x)
    6754   {
    67557066    lpHitTestInfo->flags = LVHT_TOLEFT;
    6756   }
    6757   else if (infoPtr->rcList.right < lpHitTestInfo->pt.x)
    6758   {
     7067  else if (infoPtr->rcList.right < lpHitTestInfo->pt.x)
    67597068    lpHitTestInfo->flags = LVHT_TORIGHT;
    6760   }
    67617069  if (infoPtr->rcList.top > lpHitTestInfo->pt.y)
    6762   {
    67637070    lpHitTestInfo->flags |= LVHT_ABOVE;
    6764   }
    6765   else if (infoPtr->rcList.bottom < lpHitTestInfo->pt.y)
    6766   {
     7071  else if (infoPtr->rcList.bottom < lpHitTestInfo->pt.y)
    67677072    lpHitTestInfo->flags |= LVHT_BELOW;
    6768   }
    67697073
    67707074  if (lpHitTestInfo->flags == 0)
    67717075  {
    6772     /* NOTE (mm 20001022): We must not allow iSubItem to be touched, for
     7076    /* NOTE (mm 20001022): We must not allow iSubItem to be touched, for 
    67737077     * an app might pass only a structure with space up to iItem!
    67747078     * (MS Office 97 does that for instance in the file open dialog)
     
    67767080    nItem = LISTVIEW_HitTestItem(hwnd, lpHitTestInfo, FALSE);
    67777081  }
    6778 
     7082 
    67797083  return nItem;
    67807084}
     
    67837087 * DESCRIPTION:
    67847088 * Inserts a new column.
    6785  *
     7089 * 
    67867090 * PARAMETER(S):
    67877091 * [I] HWND : window handle
    67887092 * [I] INT : column index
    6789  * [I] LPLVCOLUMNA : column information
     7093 * [I] LPLVCOLUMNW : column information
    67907094 *
    67917095 * RETURN:
     
    67937097 *   FAILURE : -1
    67947098 */
    6795 static LRESULT LISTVIEW_InsertColumnA(HWND hwnd, INT nColumn,
    6796                                       LPLVCOLUMNA lpColumn)
    6797 {
    6798   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    6799   HDITEMA hdi;
     7099static LRESULT LISTVIEW_InsertColumnT(HWND hwnd, INT nColumn,
     7100                                      LPLVCOLUMNW lpColumn, BOOL isW)
     7101{
     7102  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    68007103  INT nNewColumn = -1;
    6801 
    6802   TRACE("(hwnd=%x, nColumn=%d, lpColumn=%p)\n",hwnd, nColumn,
    6803         lpColumn);
    6804 
    6805   if (lpColumn != NULL)
     7104  HDITEMW hdi;
     7105
     7106  TRACE("(hwnd=%x, nColumn=%d, lpColumn=%p)\n",hwnd, nColumn, lpColumn);
     7107
     7108  if (lpColumn != NULL) 
    68067109  {
    68077110    /* initialize memory */
    6808     ZeroMemory(&hdi, sizeof(HDITEMA));
    6809 
    6810     if (lpColumn->mask & LVCF_FMT)
     7111    ZeroMemory(&hdi, sizeof(hdi));
     7112
     7113    if (lpColumn->mask & LVCF_FMT) 
    68117114    {
    68127115      /* format member is valid */
     
    68337136        }
    68347137      }
    6835 
     7138 
    68367139      if (lpColumn->fmt & LVCFMT_BITMAP_ON_RIGHT)
    68377140      {
     
    68447147        /* ??? */
    68457148      }
    6846 
     7149     
    68477150      if (lpColumn->fmt & LVCFMT_IMAGE)
    68487151      {
     
    68527155    }
    68537156
    6854     if (lpColumn->mask & LVCF_WIDTH)
     7157    if (lpColumn->mask & LVCF_WIDTH) 
    68557158    {
    68567159      hdi.mask |= HDI_WIDTH;
    6857       hdi.cxy = lpColumn->cx;
    6858     }
    6859 
    6860     if (lpColumn->mask & LVCF_TEXT)
     7160      if(lpColumn->cx == LVSCW_AUTOSIZE_USEHEADER)
     7161      {
     7162        /* make it fill the remainder of the controls width */
     7163        HDITEMW hdit;
     7164        RECT rcHeader;
     7165        INT item_index;
     7166       
     7167        ZeroMemory(&hdit, sizeof(hdit));
     7168 
     7169        /* get the width of every item except the current one */
     7170        hdit.mask = HDI_WIDTH;
     7171        hdi.cxy = 0;
     7172       
     7173        for(item_index = 0; item_index < (nColumn - 1); item_index++) {
     7174          Header_GetItemW(infoPtr->hwndHeader, item_index, (LPARAM)(&hdit));
     7175          hdi.cxy+=hdit.cxy;
     7176        }
     7177
     7178        /* retrieve the layout of the header */
     7179        GetClientRect(hwnd, &rcHeader);
     7180/*        GetWindowRect(infoPtr->hwndHeader, &rcHeader);*/
     7181        TRACE("start cxy=%d left=%d right=%d\n", hdi.cxy, rcHeader.left, rcHeader.right);
     7182
     7183        hdi.cxy = (rcHeader.right - rcHeader.left) - hdi.cxy;
     7184      }
     7185      else
     7186        hdi.cxy = lpColumn->cx;
     7187    }
     7188 
     7189    if (lpColumn->mask & LVCF_TEXT)
    68617190    {
    68627191      hdi.mask |= HDI_TEXT | HDI_FORMAT;
    68637192      hdi.pszText = lpColumn->pszText;
    6864       hdi.cchTextMax = ((lpColumn->pszText!=NULL) && (lpColumn->pszText!=LPSTR_TEXTCALLBACKA) ? strlen(lpColumn->pszText) : 0);
     7193      hdi.cchTextMax = textlenT(lpColumn->pszText, isW);
    68657194      hdi.fmt |= HDF_STRING;
    68667195    }
    6867 
    6868     if (lpColumn->mask & LVCF_IMAGE)
     7196 
     7197    if (lpColumn->mask & LVCF_IMAGE) 
    68697198    {
    68707199      hdi.mask |= HDI_IMAGE;
     
    68727201    }
    68737202
    6874     if (lpColumn->mask & LVCF_ORDER)
     7203    if (lpColumn->mask & LVCF_ORDER) 
    68757204    {
    68767205      hdi.mask |= HDI_ORDER;
     
    68797208
    68807209    /* insert item in header control */
    6881     nNewColumn = SendMessageA(infoPtr->hwndHeader, HDM_INSERTITEMA,
     7210    nNewColumn = SendMessageW(infoPtr->hwndHeader, HDM_INSERTITEMT(isW),
    68827211                             (WPARAM)nColumn, (LPARAM)&hdi);
    6883 
     7212   
    68847213    /* Need to reset the item width when inserting a new column */
    68857214    infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd);
     
    68907219
    68917220  return nNewColumn;
    6892 }
    6893 
    6894 static LRESULT LISTVIEW_InsertColumnW(HWND hwnd, INT nColumn,
    6895                                       LPLVCOLUMNW lpColumn)
    6896 {
    6897   LVCOLUMNA lvca;
    6898   LRESULT       lres;
    6899 
    6900   memcpy(&lvca,lpColumn,sizeof(lvca));
    6901   if (lpColumn->mask & LVCF_TEXT) {
    6902     if (lpColumn->pszText == LPSTR_TEXTCALLBACKW)
    6903       lvca.pszText = LPSTR_TEXTCALLBACKA;
    6904     else
    6905       lvca.pszText = HEAP_strdupWtoA(GetProcessHeap(),0,lpColumn->pszText);
    6906   }
    6907   lres = LISTVIEW_InsertColumnA(hwnd,nColumn,&lvca);
    6908   if (lpColumn->mask & LVCF_TEXT) {
    6909     if (lpColumn->pszText != LPSTR_TEXTCALLBACKW)
    6910       HeapFree(GetProcessHeap(),0,lvca.pszText);
    6911   }
    6912   return lres;
    69137221}
    69147222
     
    69227230    (remarks on LVITEM: LVM_INSERTITEM will insert the new item in the proper sort postion...
    69237231        if:
    6924           LVS_SORTXXX must be specified,
    6925           LVS_OWNERDRAW is not set,
     7232          LVS_SORTXXX must be specified, 
     7233          LVS_OWNERDRAW is not set, 
    69267234          <item>.pszText is not LPSTR_TEXTCALLBACK.
    69277235
    6928     (LVS_SORT* flags): "For the LVS_SORTASCENDING... styles, item indices
    6929     are sorted based on item text..."
     7236    (LVS_SORT* flags): "For the LVS_SORTASCENDING... styles, item indices 
     7237    are sorted based on item text..." 
    69307238*/
    69317239static INT WINAPI LISTVIEW_InsertCompare(  LPVOID first, LPVOID second,  LPARAM lParam)
    69327240{
    6933   HDPA  hdpa_first = (HDPA) first;
    6934   HDPA  hdpa_second = (HDPA) second;
    6935   LISTVIEW_ITEM* lv_first = (LISTVIEW_ITEM*) DPA_GetPtr( hdpa_first, 0 );
    6936   LISTVIEW_ITEM* lv_second = (LISTVIEW_ITEM*) DPA_GetPtr( hdpa_second, 0 );
    6937   LONG lStyle = GetWindowLongA((HWND) lParam, GWL_STYLE);
    6938   INT  cmpv = lstrcmpA( lv_first->pszText, lv_second->pszText );
     7241  LONG lStyle = GetWindowLongW((HWND) lParam, GWL_STYLE);
     7242  LISTVIEW_ITEM* lv_first = (LISTVIEW_ITEM*) DPA_GetPtr( (HDPA)first, 0 );
     7243  LISTVIEW_ITEM* lv_second = (LISTVIEW_ITEM*) DPA_GetPtr( (HDPA)second, 0 );
     7244  INT  cmpv = lstrcmpW( lv_first->pszText, lv_second->pszText );
    69397245  /* if we're sorting descending, negate the return value */
    69407246  return (lStyle & LVS_SORTDESCENDING) ? -cmpv : cmpv;
     
    69447250 * nESCRIPTION:
    69457251 * Inserts a new item in the listview control.
    6946  *
    6947  * PARAMETER(S):
    6948  * [I] HWND : window handle
    6949  * [I] LPLVITEMA : item information
     7252 *
     7253 * PARAMETER(S):
     7254 * [I] HWND : window handle
     7255 * [I] LPLVITEMW : item information
     7256 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
    69507257 *
    69517258 * RETURN:
     
    69537260 *   FAILURE : -1
    69547261 */
    6955 static LRESULT LISTVIEW_InsertItemA(HWND hwnd, LPLVITEMA lpLVItem)
    6956 {
    6957   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    6958   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     7262static LRESULT LISTVIEW_InsertItemT(HWND hwnd, LPLVITEMW lpLVItem, BOOL isW)
     7263{
     7264  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     7265  LONG lStyle = GetWindowLongW(hwnd, GWL_STYLE);
    69597266  UINT uView = lStyle & LVS_TYPEMASK;
    6960   LONG lCtrlId = GetWindowLongA(hwnd, GWL_ID);
    6961   NMLISTVIEW nmlv;
    69627267  INT nItem = -1;
    69637268  HDPA hdpaSubItems;
     
    69657270  LISTVIEW_ITEM *lpItem = NULL;
    69667271
    6967   TRACE("(hwnd=%x,lpLVItem=%p)\n", hwnd, lpLVItem);
     7272  TRACE("(hwnd=%x, lpLVItem=%s, isW=%d)\n",
     7273        hwnd, debuglvitem_t(lpLVItem, isW), isW);
    69687274
    69697275  if (lStyle & LVS_OWNERDATA)
     
    69797285    if (lpLVItem->iSubItem == 0)
    69807286    {
    6981       lpItem = (LISTVIEW_ITEM *)COMCTL32_Alloc(sizeof(LISTVIEW_ITEM));
    6982       if (lpItem != NULL)
     7287      if ( (lpItem = (LISTVIEW_ITEM *)COMCTL32_Alloc(sizeof(LISTVIEW_ITEM))) )
    69837288      {
    69847289        ZeroMemory(lpItem, sizeof(LISTVIEW_ITEM));
    6985         if (LISTVIEW_InitItem(hwnd, lpItem, lpLVItem) != FALSE)
     7290        if (LISTVIEW_InitItemT(hwnd, lpItem, lpLVItem, isW))
    69867291        {
    69877292          /* insert item in listview control data structure */
    6988           hdpaSubItems = DPA_Create(8);
    6989           if (hdpaSubItems != NULL)
     7293          if ( (hdpaSubItems = DPA_Create(8)) )
    69907294          {
    6991             nItem = DPA_InsertPtr(hdpaSubItems, 0, lpItem);
    6992             if (nItem != -1)
     7295            if ( (nItem = DPA_InsertPtr(hdpaSubItems, 0, lpItem)) != -1)
    69937296            {
    69947297              if ( ((lStyle & LVS_SORTASCENDING) || (lStyle & LVS_SORTDESCENDING))
    6995               && !(lStyle & LVS_OWNERDRAWFIXED)
    6996               && (LPSTR_TEXTCALLBACKA != lpLVItem->pszText) )
    6997           {
    6998         /* Insert the item in the proper sort order based on the pszText
    6999           member. See comments for LISTVIEW_InsertCompare() for greater detail */
    7000           nItem = DPA_InsertPtr( infoPtr->hdpaItems,
    7001               GETITEMCOUNT( infoPtr ) + 1, hdpaSubItems );
    7002           DPA_Sort( infoPtr->hdpaItems, LISTVIEW_InsertCompare, hwnd );
    7003           nItem = DPA_GetPtrIndex( infoPtr->hdpaItems, hdpaSubItems );
    7004           }
    7005           else
    7006           {
    7007                 nItem = DPA_InsertPtr(infoPtr->hdpaItems, lpLVItem->iItem,
     7298                      && !(lStyle & LVS_OWNERDRAWFIXED)
     7299                      && (LPSTR_TEXTCALLBACKW != lpLVItem->pszText) )
     7300              {
     7301                /* Insert the item in the proper sort order based on the pszText
     7302                  member. See comments for LISTVIEW_InsertCompare() for greater detail */
     7303                  nItem = DPA_InsertPtr( infoPtr->hdpaItems,
     7304                          GETITEMCOUNT( infoPtr ) + 1, hdpaSubItems );
     7305                  DPA_Sort( infoPtr->hdpaItems, LISTVIEW_InsertCompare, hwnd );
     7306                  nItem = DPA_GetPtrIndex( infoPtr->hdpaItems, hdpaSubItems );
     7307              }
     7308              else
     7309              {
     7310                nItem = DPA_InsertPtr(infoPtr->hdpaItems, lpLVItem->iItem, 
    70087311                                    hdpaSubItems);
    7009           }
     7312              }
    70107313              if (nItem != -1)
    70117314              {
     7315                NMLISTVIEW nmlv;
     7316
    70127317                LISTVIEW_ShiftIndices(hwnd,nItem,1);
    70137318
     
    70157320                if (lpLVItem->mask & LVIF_STATE)
    70167321                {
    7017               lpItem->state &= ~(LVIS_FOCUSED|LVIS_SELECTED);
     7322                  lpItem->state &= ~(LVIS_FOCUSED|LVIS_SELECTED);
    70187323                  if (lpLVItem->stateMask & LVIS_SELECTED)
    7019                   {
    70207324                    LISTVIEW_SetSelection(hwnd, nItem);
    7021           }
    7022           else if (lpLVItem->stateMask & LVIS_FOCUSED)
    7023                   {
     7325                  else if (lpLVItem->stateMask & LVIS_FOCUSED)
    70247326                    LISTVIEW_SetItemFocus(hwnd, nItem);
    7025                   }
    70267327                }
    7027 
     7328               
    70287329                /* send LVN_INSERTITEM notification */
    70297330                ZeroMemory(&nmlv, sizeof(NMLISTVIEW));
    7030                 nmlv.hdr.hwndFrom = hwnd;
    7031                 nmlv.hdr.idFrom = lCtrlId;
    7032                 nmlv.hdr.code = LVN_INSERTITEM;
    70337331                nmlv.iItem = nItem;
    7034                 nmlv.lParam = lpItem->lParam;;
    7035                 ListView_LVNotify(GetParent(hwnd), lCtrlId, &nmlv);
    7036 
     7332                nmlv.lParam = lpItem->lParam;
     7333                listview_notify(hwnd, LVN_INSERTITEM, &nmlv);
     7334               
    70377335                if ((uView == LVS_SMALLICON) || (uView == LVS_LIST))
    7038         {
    7039           nItemWidth = LISTVIEW_CalculateWidth(hwnd, lpLVItem->iItem);
    7040           if (nItemWidth > infoPtr->nItemWidth)
    7041           {
    7042             infoPtr->nItemWidth = nItemWidth;
    7043           }
    7044         }
     7336                {
     7337                  nItemWidth = LISTVIEW_CalculateWidth(hwnd, lpLVItem->iItem);
     7338                  if (nItemWidth > infoPtr->nItemWidth)
     7339                    infoPtr->nItemWidth = nItemWidth;
     7340                }
    70457341
    70467342                /* align items (set position of each item) */
     
    70487344                {
    70497345                  if (lStyle & LVS_ALIGNLEFT)
    7050                   {
    70517346                    LISTVIEW_AlignLeft(hwnd);
    7052                   }
    70537347                  else
    7054                   {
    70557348                    LISTVIEW_AlignTop(hwnd);
    7056                   }
    70577349                }
    7058 
     7350               
    70597351                LISTVIEW_UpdateScroll(hwnd);
    70607352                /* refresh client area */
     
    70707362  /* free memory if unsuccessful */
    70717363  if ((nItem == -1) && (lpItem != NULL))
    7072   {
    70737364    COMCTL32_Free(lpItem);
    7074   }
    7075 
     7365 
    70767366  return nItem;
    70777367}
    70787368
    7079 static LRESULT LISTVIEW_InsertItemW(HWND hwnd, LPLVITEMW lpLVItem) {
    7080   LVITEMA lvia;
    7081   LRESULT lres;
    7082 
    7083   memcpy(&lvia,lpLVItem,sizeof(LVITEMA));
    7084   if (lvia.mask & LVIF_TEXT) {
    7085     if (lpLVItem->pszText == LPSTR_TEXTCALLBACKW)
    7086       lvia.pszText = LPSTR_TEXTCALLBACKA;
    7087     else
    7088       lvia.pszText = HEAP_strdupWtoA(GetProcessHeap(),0,lpLVItem->pszText);
    7089   }
    7090   lres = LISTVIEW_InsertItemA(hwnd, &lvia);
    7091   if (lvia.mask & LVIF_TEXT) {
    7092     if (lpLVItem->pszText != LPSTR_TEXTCALLBACKW)
    7093       HeapFree(GetProcessHeap(),0,lvia.pszText);
    7094   }
    7095   return lres;
    7096 }
    7097 
    7098 /* LISTVIEW_InsertItemW */
    7099 
    71007369/***
    71017370 * DESCRIPTION:
    71027371 * Redraws a range of items.
    7103  *
     7372 * 
    71047373 * PARAMETER(S):
    71057374 * [I] HWND : window handle
     
    71137382static LRESULT LISTVIEW_RedrawItems(HWND hwnd, INT nFirst, INT nLast)
    71147383{
    7115   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     7384  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    71167385  BOOL bResult = FALSE;
    71177386  RECT rcItem;
     7387  INT i;
    71187388
    71197389  if (nFirst <= nLast)
     
    71237393      if ((nLast >= 0) && (nLast < GETITEMCOUNT(infoPtr)))
    71247394      {
    7125           INT i;
    7126           for (i = nFirst; i <= nLast; i++)
    7127           {
    7128               rcItem.left = LVIR_BOUNDS;
    7129               LISTVIEW_GetItemRect(hwnd, i, &rcItem);
    7130               InvalidateRect(hwnd, &rcItem, TRUE);
    7131           }
     7395        for (i = nFirst; i <= nLast; i++)
     7396        {
     7397          rcItem.left = LVIR_BOUNDS;
     7398          LISTVIEW_GetItemRect(hwnd, i, &rcItem);
     7399          InvalidateRect(hwnd, &rcItem, TRUE);
     7400        }
    71327401      }
    71337402    }
     
    71427411 * DESCRIPTION:
    71437412 * Sets the background color.
    7144  *
     7413 * 
    71457414 * PARAMETER(S):
    71467415 * [I] HWND : window handle
     
    71537422static LRESULT LISTVIEW_SetBkColor(HWND hwnd, COLORREF clrBk)
    71547423{
    7155   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    7156 
    7157   infoPtr->clrBk = clrBk;
    7158   InvalidateRect(hwnd, NULL, TRUE);
    7159 
     7424  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     7425
     7426  if(infoPtr->clrBk!=clrBk){
     7427    infoPtr->clrBk = clrBk;
     7428    InvalidateRect(hwnd, NULL, TRUE);
     7429  }
     7430 
    71607431  return TRUE;
    71617432}
     
    71677438 * Sets the callback mask. This mask will be used when the parent
    71687439 * window stores state information (some or all).
    7169  *
     7440 * 
    71707441 * PARAMETER(S):
    71717442 * [I] HWND : window handle
     
    71787449static BOOL LISTVIEW_SetCallbackMask(HWND hwnd, UINT uMask)
    71797450{
    7180   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     7451  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    71817452
    71827453  infoPtr->uCallbackMask = uMask;
     
    71887459 * DESCRIPTION:
    71897460 * Sets the attributes of a header item.
    7190  *
     7461 * 
    71917462 * PARAMETER(S):
    71927463 * [I] HWND : window handle
    71937464 * [I] INT : column index
    7194  * [I] LPLVCOLUMNA : column attributes
     7465 * [I] LPLVCOLUMNW : column attributes
     7466 * [I] isW: if TRUE, the lpColumn is a LPLVCOLUMNW,
     7467 *          otherwise it is in fact a LPLVCOLUMNA
    71957468 *
    71967469 * RETURN:
     
    71987471 *   FAILURE : FALSE
    71997472 */
    7200 static LRESULT LISTVIEW_SetColumnA(HWND hwnd, INT nColumn,
    7201                                    LPLVCOLUMNA lpColumn)
    7202 {
    7203   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     7473static LRESULT LISTVIEW_SetColumnT(HWND hwnd, INT nColumn,
     7474                                   LPLVCOLUMNW lpColumn, BOOL isW)
     7475{
     7476  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    72047477  BOOL bResult = FALSE;
    7205   HDITEMA hdi, hdiget;
    7206 
    7207   if ((lpColumn != NULL) && (nColumn >= 0) &&
     7478  HDITEMW hdi, hdiget;
     7479
     7480  if ((lpColumn != NULL) && (nColumn >= 0) && 
    72087481      (nColumn < Header_GetItemCount(infoPtr->hwndHeader)))
    72097482  {
    72107483    /* initialize memory */
    7211     ZeroMemory(&hdi, sizeof(HDITEMA));
    7212 
    7213     if (lpColumn->mask & LVCF_FMT)
     7484    ZeroMemory(&hdi, sizeof(hdi));
     7485
     7486    if (lpColumn->mask & LVCF_FMT) 
    72147487    {
    72157488      /* format member is valid */
     
    72187491      /* get current format first */
    72197492      hdiget.mask = HDI_FORMAT;
    7220       if (Header_GetItemA(infoPtr->hwndHeader, nColumn, &hdiget))
    7221           /* preserve HDF_STRING if present */
    7222           hdi.fmt = hdiget.fmt & HDF_STRING;
     7493      if (Header_GetItemW(infoPtr->hwndHeader, nColumn, &hdiget))
     7494              /* preserve HDF_STRING if present */
     7495              hdi.fmt = hdiget.fmt & HDF_STRING;
    72237496
    72247497      /* set text alignment (leftmost column must be left-aligned) */
     
    72307503      {
    72317504        if (lpColumn->fmt & LVCFMT_LEFT)
    7232         {
    72337505          hdi.fmt |= HDF_LEFT;
    7234         }
    72357506        else if (lpColumn->fmt & LVCFMT_RIGHT)
    7236         {
    72377507          hdi.fmt |= HDF_RIGHT;
    7238         }
    72397508        else if (lpColumn->fmt & LVCFMT_CENTER)
    7240         {
    72417509          hdi.fmt |= HDF_CENTER;
    7242         }
    72437510      }
    7244 
     7511     
    72457512      if (lpColumn->fmt & LVCFMT_BITMAP_ON_RIGHT)
    7246       {
    72477513        hdi.fmt |= HDF_BITMAP_ON_RIGHT;
    7248       }
    72497514
    72507515      if (lpColumn->fmt & LVCFMT_COL_HAS_IMAGES)
    7251       {
    72527516        hdi.fmt |= HDF_IMAGE;
    7253       }
    7254 
     7517     
    72557518      if (lpColumn->fmt & LVCFMT_IMAGE)
    72567519      {
     
    72607523    }
    72617524
    7262     if (lpColumn->mask & LVCF_WIDTH)
     7525    if (lpColumn->mask & LVCF_WIDTH) 
    72637526    {
    72647527      hdi.mask |= HDI_WIDTH;
    72657528      hdi.cxy = lpColumn->cx;
    72667529    }
    7267 
    7268     if (lpColumn->mask & LVCF_TEXT)
     7530   
     7531    if (lpColumn->mask & LVCF_TEXT) 
    72697532    {
    72707533      hdi.mask |= HDI_TEXT | HDI_FORMAT;
    72717534      hdi.pszText = lpColumn->pszText;
    7272       hdi.cchTextMax = ((lpColumn->pszText!=NULL) && (lpColumn->pszText!=LPSTR_TEXTCALLBACKA) ? strlen(lpColumn->pszText) : 0);
     7535      hdi.cchTextMax = textlenT(lpColumn->pszText, isW);
    72737536      hdi.fmt |= HDF_STRING;
    72747537    }
    7275 
    7276     if (lpColumn->mask & LVCF_IMAGE)
     7538 
     7539    if (lpColumn->mask & LVCF_IMAGE) 
    72777540    {
    72787541      hdi.mask |= HDI_IMAGE;
     
    72807543    }
    72817544
    7282     if (lpColumn->mask & LVCF_ORDER)
     7545    if (lpColumn->mask & LVCF_ORDER) 
    72837546    {
    72847547      hdi.mask |= HDI_ORDER;
     
    72877550
    72887551    /* set header item attributes */
    7289     bResult = Header_SetItemA(infoPtr->hwndHeader, nColumn, &hdi);
    7290   }
    7291 
     7552    if (isW)
     7553      bResult = Header_SetItemW(infoPtr->hwndHeader, nColumn, &hdi);
     7554    else
     7555      bResult = Header_SetItemA(infoPtr->hwndHeader, nColumn, &hdi);
     7556  }
     7557 
    72927558  return bResult;
    72937559}
    7294 
    7295 /* LISTVIEW_SetColumnW */
    72967560
    72977561/***
     
    73107574static LRESULT LISTVIEW_SetColumnOrderArray(HWND hwnd, INT iCount, LPINT lpiArray)
    73117575{
    7312 /*  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0); */
    7313 
    7314     FIXME("iCount %d lpiArray %p\n", iCount, lpiArray);
    7315 
    7316     if (!lpiArray)
     7576  /* LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0); */
     7577
     7578  FIXME("iCount %d lpiArray %p\n", iCount, lpiArray);
     7579
     7580  if (!lpiArray)
    73177581    return FALSE;
    73187582
    7319     return TRUE;
     7583  return TRUE;
    73207584}
    73217585
     
    73377601{
    73387602    LISTVIEW_INFO *infoPtr;
    7339     HDITEMA hdi;
     7603    HDITEMW hdi;
    73407604    LRESULT lret;
    7341     LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
    7342     UINT uView = lStyle & LVS_TYPEMASK;
     7605    LONG lStyle = GetWindowLongW(hwnd, GWL_STYLE);
     7606    UINT uView = lStyle & LVS_TYPEMASK; 
    73437607    HDC hdc;
    73447608    HFONT header_font;
    73457609    HFONT old_font;
    73467610    SIZE size;
    7347     CHAR text_buffer[DISP_TEXT_SIZE];
     7611    WCHAR text_buffer[DISP_TEXT_SIZE];
    73487612    INT header_item_count;
    73497613    INT item_index;
     7614    INT nLabelWidth;
    73507615    RECT rcHeader;
    7351 
     7616    LVITEMW lvItem;
     7617    WCHAR szDispText[DISP_TEXT_SIZE];
    73527618
    73537619    /* make sure we can get the listview info */
    7354     if (!(infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0)))
     7620    if (!(infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0)))
    73557621      return (FALSE);
    73567622
     
    73607626    /* set column width only if in report or list mode */
    73617627    if ((uView != LVS_REPORT) && (uView != LVS_LIST))
    7362       return (FALSE);
    7363 
     7628      return (FALSE);           
     7629
     7630    TRACE("(hwnd=%x, iCol=%d, cx=%d\n", hwnd, iCol, cx);
     7631   
    73647632    /* take care of invalid cx values */
    73657633    if((uView == LVS_REPORT) && (cx < -2))
     
    73677635    else if (uView == LVS_LIST && (cx < 1))
    73687636      return FALSE;
    7369 
     7637 
    73707638    /* resize all columns if in LVS_LIST mode */
    73717639    if(uView == LVS_LIST) {
     
    73787646    if(cx == LVSCW_AUTOSIZE)
    73797647    {
    7380       /* set the width of the header to the width of the widest item */
    7381       for(item_index = 0; item_index < GETITEMCOUNT(infoPtr); item_index++)
     7648      /* set the width of the column to the width of the widest item */
     7649      if (iCol == 0 || uView == LVS_LIST)
    73827650      {
    7383         if(cx < LISTVIEW_GetLabelWidth(hwnd, item_index))
    7384           cx = LISTVIEW_GetLabelWidth(hwnd, item_index);
     7651        cx = 0;
     7652        for(item_index = 0; item_index < GETITEMCOUNT(infoPtr); item_index++)
     7653        {
     7654          nLabelWidth = LISTVIEW_GetLabelWidth(hwnd, item_index);
     7655          cx = (nLabelWidth>cx)?nLabelWidth:cx;
     7656        }
     7657        if (infoPtr->himlSmall)
     7658          cx += infoPtr->iconSize.cx + IMAGE_PADDING;
    73857659      }
     7660      else
     7661      {
     7662        ZeroMemory(&lvItem, sizeof(lvItem));
     7663        lvItem.iSubItem = iCol;
     7664        lvItem.mask = LVIF_TEXT;
     7665        lvItem.cchTextMax = DISP_TEXT_SIZE;
     7666        lvItem.pszText = szDispText;
     7667        *lvItem.pszText = '\0';
     7668        cx = 0;
     7669        for(item_index = 0; item_index < GETITEMCOUNT(infoPtr); item_index++)
     7670        {
     7671          lvItem.iItem = item_index;
     7672          LISTVIEW_GetItemT(hwnd, &lvItem, FALSE, TRUE);
     7673          nLabelWidth = LISTVIEW_GetStringWidthT(hwnd, lvItem.pszText, TRUE);
     7674          cx = (nLabelWidth>cx)?nLabelWidth:cx;
     7675        }
     7676      }
     7677      cx += TRAILING_PADDING;
    73867678    } /* autosize based on listview header width */
    73877679    else if(cx == LVSCW_AUTOSIZE_USEHEADER)
    73887680    {
    73897681      header_item_count = Header_GetItemCount(infoPtr->hwndHeader);
    7390 
     7682 
    73917683      /* if iCol is the last column make it fill the remainder of the controls width */
    73927684      if(iCol == (header_item_count - 1)) {
     
    73947686        hdi.mask = HDI_WIDTH;
    73957687        cx = 0;
    7396 
     7688       
    73977689        for(item_index = 0; item_index < (header_item_count - 1); item_index++) {
    7398           Header_GetItemA(infoPtr->hwndHeader, item_index, (LPARAM)(&hdi));
     7690          Header_GetItemW(infoPtr->hwndHeader, item_index, (LPARAM)(&hdi));
    73997691          cx+=hdi.cxy;
    74007692        }
    7401 
     7693 
    74027694        /* retrieve the layout of the header */
    74037695        GetWindowRect(infoPtr->hwndHeader, &rcHeader);
    74047696
    74057697        cx = (rcHeader.right - rcHeader.left) - cx;
    7406       }
     7698      }                                 
    74077699      else
    74087700      {
     7701        /* Despite what the MS docs say, if this is not the last
     7702           column, then MS resizes the column to the width of the
     7703           largest text string in the column, including headers
     7704           and items. This is different from LVSCW_AUTOSIZE in that
     7705           LVSCW_AUTOSIZE ignores the header string length.
     7706           */
     7707           
    74097708        /* retrieve header font */
    7410         header_font = SendMessageA(infoPtr->hwndHeader, WM_GETFONT, 0L, 0L);
    7411 
     7709        header_font = SendMessageW(infoPtr->hwndHeader, WM_GETFONT, 0L, 0L);
     7710 
    74127711        /* retrieve header text */
    74137712        hdi.mask = HDI_TEXT;
    7414         hdi.cchTextMax = sizeof(text_buffer);
    7415         hdi.pszText = text_buffer;
    7416 
    7417         Header_GetItemA(infoPtr->hwndHeader, iCol, (LPARAM)(&hdi));
    7418 
     7713        hdi.cchTextMax = sizeof(text_buffer)/sizeof(text_buffer[0]);
     7714        hdi.pszText = text_buffer;             
     7715   
     7716        Header_GetItemW(infoPtr->hwndHeader, iCol, (LPARAM)(&hdi));
     7717 
    74197718        /* determine the width of the text in the header */
    74207719        hdc = GetDC(hwnd);
    74217720        old_font = SelectObject(hdc, header_font); /* select the font into hdc */
    74227721
    7423         GetTextExtentPoint32A(hdc, text_buffer, strlen(text_buffer), &size);
    7424 
    7425         SelectObject(hdc, old_font); /* restore the old font */
     7722        GetTextExtentPoint32W(hdc, text_buffer, lstrlenW(text_buffer), &size);
     7723 
     7724        SelectObject(hdc, old_font); /* restore the old font */   
    74267725        ReleaseDC(hwnd, hdc);
    7427 
    7428         /* set the width of this column to the width of the text */
     7726 
     7727        ZeroMemory(&lvItem, sizeof(lvItem));
     7728        lvItem.iSubItem = iCol;
     7729        lvItem.mask = LVIF_TEXT;
     7730        lvItem.cchTextMax = DISP_TEXT_SIZE;
     7731        lvItem.pszText = szDispText;
     7732        *lvItem.pszText = '\0';
    74297733        cx = size.cx;
     7734        for(item_index = 0; item_index < GETITEMCOUNT(infoPtr); item_index++)
     7735        {
     7736          lvItem.iItem = item_index;
     7737          LISTVIEW_GetItemT(hwnd, &lvItem, FALSE, TRUE);
     7738          nLabelWidth = LISTVIEW_GetStringWidthT(hwnd, lvItem.pszText, TRUE);
     7739          nLabelWidth += TRAILING_PADDING;
     7740          /* While it is possible for subitems to have icons, even MS messes
     7741             up the positioning, so I suspect no applications actually use
     7742             them. */
     7743          if (item_index == 0 && infoPtr->himlSmall)
     7744            nLabelWidth += infoPtr->iconSize.cx + IMAGE_PADDING;
     7745          cx = (nLabelWidth>cx)?nLabelWidth:cx;
     7746        }
    74307747      }
    74317748  }
    74327749
    74337750  /* call header to update the column change */
    7434   hdi.mask = HDI_WIDTH;
     7751  hdi.mask = HDI_WIDTH;                         
    74357752
    74367753  hdi.cxy = cx;
    7437   lret = Header_SetItemA(infoPtr->hwndHeader, (WPARAM)iCol, (LPARAM)&hdi);
    7438 
     7754  lret = Header_SetItemW(infoPtr->hwndHeader, (WPARAM)iCol, (LPARAM)&hdi);
     7755 
    74397756  InvalidateRect(hwnd, NULL, TRUE); /* force redraw of the listview */
    7440 
     7757 
    74417758  return lret;
    74427759}
     
    74577774static LRESULT LISTVIEW_SetExtendedListViewStyle(HWND hwnd, DWORD dwMask, DWORD dwStyle)
    74587775{
    7459     LISTVIEW_INFO *infoPtr;
    7460     DWORD dwOldStyle;
    7461 
    7462     /* make sure we can get the listview info */
    7463     if (!(infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0)))
    7464     return (0);
    7465 
    7466     /* store previous style */
    7467     dwOldStyle = infoPtr->dwExStyle;
    7468 
    7469     /* set new style */
    7470     if (dwMask)
    7471       infoPtr->dwExStyle = (dwOldStyle & ~dwMask) | (dwStyle & dwMask);
    7472     else
    7473       infoPtr->dwExStyle = dwStyle;
    7474 
    7475     return (dwOldStyle);
     7776  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     7777  DWORD dwOldStyle = infoPtr->dwExStyle;
     7778
     7779  /* set new style */
     7780  if (dwMask)
     7781    infoPtr->dwExStyle = (dwOldStyle & ~dwMask) | (dwStyle & dwMask);
     7782  else
     7783    infoPtr->dwExStyle = dwStyle;
     7784
     7785  return dwOldStyle;
    74767786}
    74777787
     
    74927802static LRESULT LISTVIEW_SetHotItem(HWND hwnd, INT iIndex)
    74937803{
    7494     LISTVIEW_INFO *infoPtr;
    7495     INT iOldIndex;
    7496 
    7497     /* make sure we can get the listview info */
    7498     if (!(infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0)))
    7499     return (-1);
    7500 
    7501     /* store previous index */
    7502     iOldIndex = infoPtr->nHotItem;
    7503 
    7504     /* set new style */
    7505     infoPtr->nHotItem = iIndex;
    7506 
    7507     return (iOldIndex);
     7804  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     7805  INT iOldIndex = infoPtr->nHotItem;
     7806
     7807  /* set new style */
     7808  infoPtr->nHotItem = iIndex;
     7809
     7810  return iOldIndex;
    75087811}
    75097812
     
    75217824static LRESULT LISTVIEW_SetHoverTime(HWND hwnd, DWORD dwHoverTime)
    75227825{
     7826  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     7827  DWORD oldHoverTime = infoPtr->dwHoverTime;
     7828
     7829  infoPtr->dwHoverTime = dwHoverTime;
     7830
     7831  return oldHoverTime;
     7832}
     7833
     7834/***
     7835 * DESCRIPTION:
     7836 * Sets spacing for icons of LVS_ICON style.
     7837 *
     7838 * PARAMETER(S):
     7839 * [I] HWND : window handle
     7840 * [I] DWORD : MAKELONG(cx, cy)
     7841 *
     7842 * RETURN:
     7843 *   MAKELONG(oldcx, oldcy)
     7844 */
     7845#ifdef __WIN32OS2__
     7846static LRESULT LISTVIEW_SetIconSpacing(HWND hwnd,WPARAM wParam,LPARAM lParam)
     7847{
    75237848  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    7524   DWORD oldHoverTime = infoPtr->dwHoverTime;
    7525 
    7526   infoPtr->dwHoverTime = dwHoverTime;
    7527 
    7528   return oldHoverTime;
    7529 }
    7530 
    7531 /* LISTVIEW_SetIconSpacing */
     7849  UINT dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
     7850  UINT uView = dwStyle & LVS_TYPEMASK;
     7851  DWORD oldIS = MAKELONG(infoPtr->iconSpacing.cx,infoPtr->iconSpacing.cy);
     7852  INT cx = LOWORD(lParam),cy = HIWORD(lParam);
     7853
     7854  if (cx == -1) cx = GetSystemMetrics(SM_CXICONSPACING);
     7855  if (cy == -1) cy = GetSystemMetrics(SM_CYICONSPACING);
     7856  if ((cx != infoPtr->iconSpacing.cx) || (cy != infoPtr->iconSpacing.cy))
     7857  {
     7858    infoPtr->iconSpacing.cx = cx;
     7859    infoPtr->iconSpacing.cy = cy;
     7860    if (((uView == LVS_ICON) || (uView == LVS_SMALLICON)) && (dwStyle & LVS_AUTOARRANGE))
     7861    {
     7862      LISTVIEW_Arrange(hwnd,LVA_DEFAULT);
     7863    }
     7864  }
     7865  return oldIS;
     7866}
     7867#else
     7868static LRESULT LISTVIEW_SetIconSpacing(HWND hwnd, DWORD spacing)
     7869{
     7870  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     7871  INT cy = HIWORD(spacing);
     7872  INT cx = LOWORD(spacing);
     7873  DWORD oldspacing;
     7874  LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     7875  UINT uView = lStyle & LVS_TYPEMASK;
     7876
     7877  oldspacing = MAKELONG(infoPtr->iconSpacing.cx, infoPtr->iconSpacing.cy);
     7878  if (cx == -1) /* set to default */
     7879    cx = GetSystemMetrics(SM_CXICONSPACING);
     7880  if (cy == -1) /* set to default */
     7881    cy = GetSystemMetrics(SM_CYICONSPACING);
     7882
     7883  if (cx)
     7884    infoPtr->iconSpacing.cx = cx;
     7885  else
     7886  {  /* if 0 then compute width */
     7887    if (uView == LVS_ICON)
     7888       FIXME("width computation not yet done\n");
     7889       /*
     7890        * Should scan each item and determine max width of
     7891        * icon or label, then make that the width
     7892        */
     7893     else /* FIXME: unknown computation for non LVS_ICON - this is a guess */
     7894       infoPtr->iconSpacing.cx = LISTVIEW_GetItemWidth(hwnd);
     7895  }
     7896  if (cy)
     7897      infoPtr->iconSpacing.cy = cy;
     7898  else
     7899  {  /* if 0 then compute height */
     7900    if (uView == LVS_ICON)
     7901       infoPtr->iconSpacing.cy = infoPtr->iconSize.cy + infoPtr->ntmHeight
     7902                                  + ICON_BOTTOM_PADDING + ICON_TOP_PADDING + LABEL_VERT_OFFSET;
     7903        /* FIXME.  I don't think so; I think it is based on twice the ntmHeight */
     7904    else /* FIXME: unknown computation for non LVS_ICON - this is a guess */
     7905       infoPtr->iconSpacing.cy = LISTVIEW_GetItemHeight(hwnd);
     7906  }
     7907
     7908  TRACE("old=(%d,%d), new=(%ld,%ld)\n", LOWORD(oldspacing), HIWORD(oldspacing),
     7909        infoPtr->iconSpacing.cx, infoPtr->iconSpacing.cy);
     7910
     7911  /* these depend on the iconSpacing */
     7912  infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd);
     7913  infoPtr->nItemHeight = LISTVIEW_GetItemHeight(hwnd);
     7914
     7915  return oldspacing;
     7916}
     7917#endif
    75327918
    75337919/***
    75347920 * DESCRIPTION:
    75357921 * Sets image lists.
    7536  *
    7537  * PARAMETER(S):
    7538  * [I] HWND : window handle
    7539  * [I] INT : image list type
     7922 * 
     7923 * PARAMETER(S):
     7924 * [I] HWND : window handle
     7925 * [I] INT : image list type 
    75407926 * [I] HIMAGELIST : image list handle
    75417927 *
     
    75447930 *   FAILURE : NULL
    75457931 */
    7546 static LRESULT LISTVIEW_SetImageList(HWND hwnd, INT nType, HIMAGELIST himl)
    7547 {
    7548   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     7932static HIMAGELIST LISTVIEW_SetImageList(HWND hwnd, INT nType, HIMAGELIST himl)
     7933{
     7934  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    75497935  HIMAGELIST himlOld = 0;
    75507936  INT oldHeight;
    75517937
    7552   switch (nType)
     7938  switch (nType) 
    75537939  {
    75547940  case LVSIL_NORMAL:
     
    75747960    LISTVIEW_UpdateScroll(hwnd);
    75757961
    7576   return (LRESULT)himlOld;
    7577 }
    7578 
    7579 
    7580 /***
    7581  * DESCRIPTION:
    7582  * Sets the attributes of an item.
    7583  *
    7584  * PARAMETER(S):
    7585  * [I] HWND : window handle
    7586  * [I] LPLVITEM : item information
     7962  return himlOld;
     7963}
     7964
     7965/***
     7966 * DESCRIPTION:
     7967 * Preallocates memory (does *not* set the actual count of items !)
     7968 *
     7969 * PARAMETER(S):
     7970 * [I] HWND : window handle
     7971 * [I] INT   : item count (projected number of items to allocate)
     7972 * [I] DWORD : update flags
    75877973 *
    75887974 * RETURN:
     
    75907976 *   FAILURE : FALSE
    75917977 */
    7592 static LRESULT LISTVIEW_SetItemA(HWND hwnd, LPLVITEMA lpLVItem)
    7593 {
    7594   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    7595   BOOL bResult = FALSE;
    7596 
    7597   if (lpLVItem != NULL)
    7598   {
    7599     if ((lpLVItem->iItem >= 0) && (lpLVItem->iItem < GETITEMCOUNT(infoPtr)))
    7600     {
    7601       if (lpLVItem->iSubItem == 0)
    7602       {
    7603         bResult = LISTVIEW_SetItem(hwnd, lpLVItem);
    7604       }
    7605       else
    7606       {
    7607         bResult = LISTVIEW_SetSubItem(hwnd, lpLVItem);
    7608       }
    7609     }
    7610   }
    7611 
    7612 
    7613   return bResult;
    7614 }
    7615 
    7616 /* LISTVIEW_SetItemW  */
    7617 
    7618 /***
    7619  * DESCRIPTION:
    7620  * Preallocates memory (does *not* set the actual count of items !)
    7621  *
    7622  * PARAMETER(S):
    7623  * [I] HWND : window handle
    7624  * [I] INT   : item count (projected number of items to allocate)
    7625  * [I] DWORD : update flags
    7626  *
    7627  * RETURN:
    7628  *   SUCCESS : TRUE
    7629  *   FAILURE : FALSE
    7630  */
    76317978static BOOL LISTVIEW_SetItemCount(HWND hwnd, INT nItems, DWORD dwFlags)
    76327979{
    7633   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongA(hwnd, 0);
    7634 
    7635   if (GetWindowLongA(hwnd, GWL_STYLE) & LVS_OWNERDATA)
     7980  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongW(hwnd, 0);
     7981
     7982  TRACE("(hwnd=%x, nItems=%d, dwFlags=%lx)\n", hwnd, nItems, dwFlags);
     7983
     7984  if (GetWindowLongW(hwnd, GWL_STYLE) & LVS_OWNERDATA)
    76367985  {
    76377986      int precount,topvisible;
     7987
    76387988      TRACE("LVS_OWNERDATA is set!\n");
     7989      if (dwFlags & (LVSICF_NOINVALIDATEALL | LVSICF_NOSCROLL))
     7990        FIXME("flags %s %s not implemented\n",
     7991              (dwFlags & LVSICF_NOINVALIDATEALL) ? "LVSICF_NOINVALIDATEALL"
     7992              : "",
     7993              (dwFlags & LVSICF_NOSCROLL) ? "LVSICF_NOSCROLL" : "");
    76397994
    76407995      /*
    7641        * Internally remove all the selections.
     7996       * Internally remove all the selections. 
    76427997       */
    76437998      do
     
    76508005      }
    76518006      while (infoPtr->hdpaSelectionRanges->nItemCount>0);
    7652 
     8007 
    76538008      precount = infoPtr->hdpaItems->nItemCount;
    76548009      topvisible = ListView_GetTopIndex(hwnd) +
     
    76578012      infoPtr->hdpaItems->nItemCount = nItems;
    76588013
     8014      infoPtr->nItemWidth = max(LISTVIEW_GetItemWidth(hwnd),
     8015                                DEFAULT_COLUMN_WIDTH);
     8016
    76598017      LISTVIEW_UpdateSize(hwnd);
    76608018      LISTVIEW_UpdateScroll(hwnd);
    7661       if (min(precount,infoPtr->hdpaItems->nItemCount)<topvisible)
     8019
     8020      if (min(precount,infoPtr->hdpaItems->nItemCount)<topvisible)
    76628021        InvalidateRect(hwnd, NULL, TRUE);
    76638022  }
    76648023  else
    76658024  {
    7666       FIXME("setitemcount not done for non-ownerdata\n");
     8025    /* According to MSDN for non-LVS_OWNERDATA this is just
     8026     * a performance issue. The control allocates its internal
     8027     * data structures for the number of items specified. It
     8028     * cuts down on the number of memory allocations. Therefore
     8029     * we will just issue a WARN here
     8030     */
     8031     WARN("for non-ownerdata performance option not implemented.\n");
    76678032  }
    76688033
     
    76738038 * DESCRIPTION:
    76748039 * Sets the position of an item.
    7675  *
     8040 * 
    76768041 * PARAMETER(S):
    76778042 * [I] HWND : window handle
     
    76878052                                     LONG nPosX, LONG nPosY)
    76888053{
    7689   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongA(hwnd, 0);
    7690   UINT lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     8054  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongW(hwnd, 0);
     8055  UINT lStyle = GetWindowLongW(hwnd, GWL_STYLE);
    76918056  UINT uView = lStyle & LVS_TYPEMASK;
    76928057  LISTVIEW_ITEM *lpItem;
     
    76948059  BOOL bResult = FALSE;
    76958060
    7696   TRACE("(hwnd=%x,nItem=%d,X=%ld,Y=%ld)\n", hwnd, nItem, nPosX, nPosY);
    7697 
     8061  TRACE("(hwnd=%x, nItem=%d, X=%ld, Y=%ld)\n", hwnd, nItem, nPosX, nPosY);
     8062 
    76988063  if (lStyle & LVS_OWNERDATA)
    76998064    return FALSE;
     
    77038068    if ((uView == LVS_ICON) || (uView == LVS_SMALLICON))
    77048069    {
    7705       hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, nItem);
    7706       if (hdpaSubItems != NULL)
     8070      if ( (hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, nItem)) )
    77078071      {
    7708         lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0);
    7709         if (lpItem != NULL)
     8072        if ( (lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0)) )
    77108073        {
     8074          POINT orig;
    77118075          bResult = TRUE;
     8076          orig = lpItem->ptPosition;
     8077          if ((nPosX == -1) && (nPosY == -1))
     8078          {
     8079            /* This point value seems to be an undocumented feature. The
     8080             * best guess is that it means either at the origin, or at
     8081             * the true beginning of the list. I will assume the origin.
     8082             */
     8083            POINT pt1;
     8084            if (!LISTVIEW_GetOrigin(hwnd, &pt1))
     8085            {
     8086              pt1.x = 0;
     8087              pt1.y = 0;
     8088            }
     8089            nPosX = pt1.x;
     8090            nPosY = pt1.y;
     8091            if (uView == LVS_ICON)
     8092            {
     8093              nPosX += (infoPtr->iconSpacing.cx - infoPtr->iconSize.cx) / 2;
     8094              nPosY += ICON_TOP_PADDING;
     8095            }
     8096            TRACE("requested special (-1,-1), set to origin (%ld,%ld)\n",
     8097                  nPosX, nPosY);
     8098          }
     8099
    77128100          lpItem->ptPosition.x = nPosX;
    77138101          lpItem->ptPosition.y = nPosY;
     8102          if (uView == LVS_ICON)
     8103          {
     8104            lpItem->ptPosition.y -= ICON_TOP_PADDING;
     8105              lpItem->ptPosition.x -= (infoPtr->iconSpacing.cx - infoPtr->iconSize.cx) / 2;
     8106              if ((lpItem->ptPosition.y < 0) || (lpItem->ptPosition.x < 0))
     8107              {
     8108                  FIXME("failed orig (%ld,%ld), intent (%ld,%ld), is (%ld, %ld), setting neg to 0\n",
     8109                        orig.x, orig.y, nPosX, nPosY, lpItem->ptPosition.x, lpItem->ptPosition.y);
     8110 
     8111                  /*
     8112                  if (lpItem->ptPosition.x < 0) lpItem->ptPosition.x = 0;
     8113                  if (lpItem->ptPosition.y < 0) lpItem->ptPosition.y = 0;
     8114                  */
     8115              }
     8116              else
     8117              {
     8118                  TRACE("orig (%ld,%ld), intent (%ld,%ld), is (%ld,%ld)\n",
     8119                        orig.x, orig.y, nPosX, nPosY, lpItem->ptPosition.x, lpItem->ptPosition.y);
     8120              }
     8121          }
    77148122        }
    77158123      }
     
    77238131 * DESCRIPTION:
    77248132 * Sets the state of one or many items.
    7725  *
     8133 * 
    77268134 * PARAMETER(S):
    77278135 * [I] HWND : window handle
     
    77338141 *   FAILURE : FALSE
    77348142 */
    7735 static LRESULT LISTVIEW_SetItemState(HWND hwnd, INT nItem, LPLVITEMA lpLVItem)
    7736 {
    7737   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    7738   BOOL bResult = FALSE;
    7739   LVITEMA lvItem;
    7740   INT i;
     8143static LRESULT LISTVIEW_SetItemState(HWND hwnd, INT nItem, LPLVITEMW lpLVItem)
     8144{
     8145  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     8146  BOOL bResult = TRUE;
     8147  LVITEMW lvItem;
     8148
     8149  TRACE("(hwnd=%x, nItem=%d, lpLVItem=%s)\n",
     8150        hwnd, nItem, debuglvitem_t(lpLVItem, TRUE));
     8151
     8152  ZeroMemory(&lvItem, sizeof(lvItem));
     8153  lvItem.mask = LVIF_STATE;
     8154  lvItem.state = lpLVItem->state;
     8155  lvItem.stateMask = lpLVItem->stateMask ;
     8156  lvItem.iItem = nItem;
    77418157
    77428158  if (nItem == -1)
    77438159  {
    7744     bResult = TRUE;
    7745     ZeroMemory(&lvItem, sizeof(LVITEMA));
    7746     lvItem.mask = LVIF_STATE;
    7747     lvItem.state = lpLVItem->state;
    7748     lvItem.stateMask = lpLVItem->stateMask ;
    7749 
    77508160    /* apply to all items */
    7751     for (i = 0; i< GETITEMCOUNT(infoPtr); i++)
    7752     {
    7753       lvItem.iItem = i;
    7754       if (ListView_SetItemA(hwnd, &lvItem) == FALSE)
    7755       {
    7756         bResult = FALSE;
    7757       }
    7758     }
     8161    for (lvItem.iItem = 0; lvItem.iItem < GETITEMCOUNT(infoPtr); lvItem.iItem++)
     8162      if (!ListView_SetItemW(hwnd, &lvItem)) bResult = FALSE;
    77598163  }
    77608164  else
    7761   {
    7762     ZeroMemory(&lvItem, sizeof(LVITEMA));
    7763     lvItem.mask = LVIF_STATE;
    7764     lvItem.state = lpLVItem->state;
    7765     lvItem.stateMask = lpLVItem->stateMask;
    7766     lvItem.iItem = nItem;
    7767     bResult = ListView_SetItemA(hwnd, &lvItem);
    7768   }
     8165    bResult = ListView_SetItemW(hwnd, &lvItem);
    77698166
    77708167  return bResult;
     
    77748171 * DESCRIPTION:
    77758172 * Sets the text of an item or subitem.
    7776  *
    7777  * PARAMETER(S):
    7778  * [I] HWND : window handle
    7779  * [I] INT : item index
    7780  * [I] LPLVITEMA : item or subitem info
     8173 *
     8174 * PARAMETER(S):
     8175 * [I] hwnd : window handle
     8176 * [I] nItem : item index
     8177 * [I] lpLVItem : item or subitem info
     8178 * [I] isW : TRUE if input is Unicode
    77818179 *
    77828180 * RETURN:
     
    77848182 *   FAILURE : FALSE
    77858183 */
    7786 static BOOL LISTVIEW_SetItemTextA(HWND hwnd, INT nItem, LPLVITEMA lpLVItem)
    7787 {
    7788   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     8184static BOOL LISTVIEW_SetItemTextT(HWND hwnd, INT nItem, LPLVITEMW lpLVItem, BOOL isW)
     8185{
     8186  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    77898187  BOOL bResult = FALSE;
    7790   LVITEMA lvItem;
    7791 
     8188  LVITEMW lvItem;
     8189
     8190  TRACE("(hwnd=%x, nItem=%d, lpLVItem=%s, isW=%d)\n",
     8191        hwnd, nItem, debuglvitem_t(lpLVItem, isW), isW);
     8192 
    77928193  if ((nItem >= 0) && (nItem < GETITEMCOUNT(infoPtr)))
    77938194  {
    7794     ZeroMemory(&lvItem, sizeof(LVITEMA));
     8195    ZeroMemory(&lvItem, sizeof(LVITEMW));
    77958196    lvItem.mask = LVIF_TEXT;
    77968197    lvItem.pszText = lpLVItem->pszText;
    77978198    lvItem.iItem = nItem;
    77988199    lvItem.iSubItem = lpLVItem->iSubItem;
    7799     bResult = ListView_SetItemA(hwnd, &lvItem);
    7800   }
    7801 
     8200    if(isW) bResult = ListView_SetItemW(hwnd, &lvItem);
     8201    else    bResult = ListView_SetItemA(hwnd, &lvItem);
     8202  }
     8203 
    78028204  return bResult;
    78038205}
    78048206
    7805 /* LISTVIEW_SetItemTextW */
    7806 
    78078207/***
    78088208 * DESCRIPTION:
     
    78188218static LRESULT LISTVIEW_SetSelectionMark(HWND hwnd, INT nIndex)
    78198219{
    7820   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     8220  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    78218221  INT nOldIndex = infoPtr->nSelectionMark;
    78228222
     8223  TRACE("(hwnd=%x, nIndex=%d)\n", hwnd, nIndex);
     8224
    78238225  infoPtr->nSelectionMark = nIndex;
    78248226
     
    78298231 * DESCRIPTION:
    78308232 * Sets the text background color.
    7831  *
     8233 * 
    78328234 * PARAMETER(S):
    78338235 * [I] HWND : window handle
     
    78408242static LRESULT LISTVIEW_SetTextBkColor(HWND hwnd, COLORREF clrTextBk)
    78418243{
    7842   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    7843 
     8244  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     8245
     8246  TRACE("(hwnd=%x, clrTextBk=%lx)\n", hwnd, clrTextBk);
     8247 
    78448248  infoPtr->clrTextBk = clrTextBk;
    78458249  InvalidateRect(hwnd, NULL, TRUE);
     
    78518255 * DESCRIPTION:
    78528256 * Sets the text foreground color.
    7853  *
    7854  * PARAMETER(S):
    7855  * [I] HWND : window handle
    7856  * [I] COLORREF : text color
     8257 * 
     8258 * PARAMETER(S):
     8259 * [I] HWND : window handle
     8260 * [I] COLORREF : text color 
    78578261 *
    78588262 * RETURN:
     
    78628266static LRESULT LISTVIEW_SetTextColor (HWND hwnd, COLORREF clrText)
    78638267{
    7864   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     8268  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     8269
     8270  TRACE("(hwnd=%x, clrText=%lx)\n", hwnd, clrText);
    78658271
    78668272  infoPtr->clrText = clrText;
     
    78778283 * DESCRIPTION:
    78788284 * Callback internally used by LISTVIEW_SortItems()
    7879  *
     8285 * 
    78808286 * PARAMETER(S):
    78818287 * [I] LPVOID : first LISTVIEW_ITEM to compare
     
    78888294 *   if first and second are equivalent : zero
    78898295 */
    7890 static INT WINAPI LISTVIEW_CallBackCompare(
    7891   LPVOID first,
    7892   LPVOID second,
    7893   LPARAM lParam)
    7894 {
     8296static INT WINAPI LISTVIEW_CallBackCompare(LPVOID first, LPVOID second, LPARAM lParam)
     8297{
     8298  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW((HWND)lParam, 0);
     8299  LISTVIEW_ITEM* lv_first = (LISTVIEW_ITEM*) DPA_GetPtr( (HDPA)first, 0 );
     8300  LISTVIEW_ITEM* lv_second = (LISTVIEW_ITEM*) DPA_GetPtr( (HDPA)second, 0 );
     8301
    78958302  /* Forward the call to the client defined callback */
    7896   INT rv;
    7897   HWND hwnd = (HWND)lParam;
    7898   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    7899   HDPA  hdpa_first = (HDPA) first;
    7900   HDPA  hdpa_second = (HDPA) second;
    7901   LISTVIEW_ITEM* lv_first = (LISTVIEW_ITEM*) DPA_GetPtr( hdpa_first, 0 );
    7902   LISTVIEW_ITEM* lv_second = (LISTVIEW_ITEM*) DPA_GetPtr( hdpa_second, 0 );
    7903 
    7904   rv = (infoPtr->pfnCompare)( lv_first->lParam , lv_second->lParam, infoPtr->lParamSort );
    7905 
    7906   return rv;
     8303  return (infoPtr->pfnCompare)( lv_first->lParam , lv_second->lParam, infoPtr->lParamSort );
    79078304}
    79088305
     
    79108307 * DESCRIPTION:
    79118308 * Sorts the listview items.
    7912  *
     8309 * 
    79138310 * PARAMETER(S):
    79148311 * [I] HWND : window handle
     
    79208317 *   FAILURE : FALSE
    79218318 */
    7922 static LRESULT LISTVIEW_SortItems(HWND hwnd, WPARAM wParam, LPARAM lParam)
    7923 {
    7924     LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    7925     int nCount, i;
    7926     UINT lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     8319static LRESULT LISTVIEW_SortItems(HWND hwnd, PFNLVCOMPARE pfnCompare, LPARAM lParamSort)
     8320{
     8321    LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     8322    UINT lStyle = GetWindowLongW(hwnd, GWL_STYLE);
    79278323    HDPA hdpaSubItems=NULL;
    79288324    LISTVIEW_ITEM *pLVItem=NULL;
    79298325    LPVOID selectionMarkItem;
    7930 
    7931     if (lStyle & LVS_OWNERDATA)
    7932       return FALSE;
    7933 
    7934     if (!infoPtr || !infoPtr->hdpaItems)
    7935     return FALSE;
    7936 
     8326    int nCount, i;
     8327
     8328    TRACE("(hwnd=%x, pfnCompare=%p, lParamSort=%lx)\n", hwnd, pfnCompare, lParamSort);
     8329   
     8330    if (lStyle & LVS_OWNERDATA) return FALSE;
     8331
     8332    if (!infoPtr || !infoPtr->hdpaItems) return FALSE;
     8333   
    79378334    nCount = GETITEMCOUNT(infoPtr);
    79388335    /* if there are 0 or 1 items, there is no need to sort */
     
    79408337        return TRUE;
    79418338
    7942     infoPtr->pfnCompare = (PFNLVCOMPARE)lParam;
    7943     infoPtr->lParamSort = (LPARAM)wParam;
     8339    infoPtr->pfnCompare = pfnCompare;
     8340    infoPtr->lParamSort = lParamSort;
    79448341    DPA_Sort(infoPtr->hdpaItems, LISTVIEW_CallBackCompare, hwnd);
    79458342
    7946     /* Adjust selections and indices so that they are the way they should
    7947      * be after the sort (otherwise, the list items move around, but
    7948      * whatever is at the item's previous original position will be
     8343    /* Adjust selections and indices so that they are the way they should 
     8344     * be after the sort (otherwise, the list items move around, but 
     8345     * whatever is at the item's previous original position will be 
    79498346     * selected instead)
    79508347     */
     
    79808377 * DESCRIPTION:
    79818378 * Updates an items or rearranges the listview control.
    7982  *
     8379 * 
    79838380 * PARAMETER(S):
    79848381 * [I] HWND : window handle
     
    79918388static LRESULT LISTVIEW_Update(HWND hwnd, INT nItem)
    79928389{
    7993   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    7994   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     8390  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     8391  LONG lStyle = GetWindowLongW(hwnd, GWL_STYLE);
    79958392  BOOL bResult = FALSE;
    79968393  RECT rc;
    79978394
     8395  TRACE("(hwnd=%x, nItem=%d)\n", hwnd, nItem);
     8396 
    79988397  if ((nItem >= 0) && (nItem < GETITEMCOUNT(infoPtr)))
    79998398  {
     
    80208419 * DESCRIPTION:
    80218420 * Creates the listview control.
    8022  *
     8421 * 
    80238422 * PARAMETER(S):
    80248423 * [I] HWND : window handle
     
    80278426 * Zero
    80288427 */
    8029 static LRESULT LISTVIEW_Create(HWND hwnd, WPARAM wParam, LPARAM lParam)
    8030 {
    8031   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    8032   LPCREATESTRUCTA lpcs = (LPCREATESTRUCTA)lParam;
     8428static LRESULT LISTVIEW_Create(HWND hwnd, LPCREATESTRUCTW lpcs)
     8429{
     8430  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    80338431  UINT uView = lpcs->style & LVS_TYPEMASK;
    8034   LOGFONTA logFont;
     8432  LOGFONTW logFont;
     8433
     8434  TRACE("(hwnd=%x, lpcs=%p)\n", hwnd, lpcs);
    80358435
    80368436  /* initialize info pointer */
     
    80388438
    80398439  /* determine the type of structures to use */
    8040   infoPtr->notifyFormat = SendMessageA(GetParent(hwnd), WM_NOTIFYFORMAT,
     8440  infoPtr->notifyFormat = SendMessageW(GetParent(hwnd), WM_NOTIFYFORMAT,
    80418441                                       (WPARAM)hwnd, (LPARAM)NF_QUERY);
    8042   if (infoPtr->notifyFormat != NFR_ANSI)
    8043   {
    8044     FIXME("ANSI notify format is NOT used\n");
    8045   }
    8046 
     8442 
    80478443  /* initialize color information  */
    80488444  infoPtr->clrBk = GetSysColor(COLOR_WINDOW);
     
    80518447
    80528448  /* set default values */
     8449  infoPtr->hwndSelf = hwnd;
    80538450  infoPtr->uCallbackMask = 0;
    80548451#ifdef __WIN32OS2__
     
    80678464
    80688465  /* get default font (icon title) */
    8069   SystemParametersInfoA(SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
    8070   infoPtr->hDefaultFont = CreateFontIndirectA(&logFont);
     8466  SystemParametersInfoW(SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
     8467  infoPtr->hDefaultFont = CreateFontIndirectW(&logFont);
    80718468  infoPtr->hFont = infoPtr->hDefaultFont;
    8072 
     8469  LISTVIEW_SaveTextMetrics(hwnd);
     8470 
    80738471  /* create header */
    8074   infoPtr->hwndHeader = CreateWindowA(WC_HEADERA, (LPCSTR)NULL,
    8075                                       WS_CHILD | HDS_HORZ | HDS_BUTTONS,
    8076                                       0, 0, 0, 0, hwnd, (HMENU)0,
    8077                                       lpcs->hInstance, NULL);
     8472  infoPtr->hwndHeader = CreateWindowW(WC_HEADERW, (LPCWSTR)NULL,
     8473    WS_CHILD | HDS_HORZ | (DWORD)((LVS_NOSORTHEADER & lpcs->style)?0:HDS_BUTTONS),
     8474    0, 0, 0, 0, hwnd, (HMENU)0,
     8475    lpcs->hInstance, NULL);
     8476
     8477  /* set header unicode format */
     8478  SendMessageW(infoPtr->hwndHeader, HDM_SETUNICODEFORMAT,(WPARAM)TRUE,(LPARAM)NULL);
    80788479
    80798480  /* set header font */
    8080   SendMessageA(infoPtr->hwndHeader, WM_SETFONT, (WPARAM)infoPtr->hFont,
     8481  SendMessageW(infoPtr->hwndHeader, WM_SETFONT, (WPARAM)infoPtr->hFont,
    80818482               (LPARAM)TRUE);
    8082 
     8483 
    80838484  if (uView == LVS_ICON)
    80848485  {
     
    80958496    {
    80968497      /* set HDS_HIDDEN flag to hide the header bar */
    8097       SetWindowLongA(infoPtr->hwndHeader, GWL_STYLE,
    8098                     GetWindowLongA(infoPtr->hwndHeader, GWL_STYLE) | HDS_HIDDEN);
    8099     }
    8100 
     8498      SetWindowLongW(infoPtr->hwndHeader, GWL_STYLE,
     8499                    GetWindowLongW(infoPtr->hwndHeader, GWL_STYLE) | HDS_HIDDEN);
     8500    }
     8501     
    81018502
    81028503    infoPtr->iconSize.cx = GetSystemMetrics(SM_CXSMICON);
     
    81238524
    81248525  /* initialize the hover time to -1(indicating the default system hover time) */
    8125   infoPtr->dwHoverTime = -1;
     8526  infoPtr->dwHoverTime = -1; 
    81268527
    81278528#ifdef __WIN32OS2__
     
    81398540 * DESCRIPTION:
    81408541 * Erases the background of the listview control.
    8141  *
     8542 * 
    81428543 * PARAMETER(S):
    81438544 * [I] HWND : window handle
    81448545 * [I] WPARAM : device context handle
    81458546 * [I] LPARAM : not used
    8146  *
     8547 * 
    81478548 * RETURN:
    81488549 *   SUCCESS : TRUE
    81498550 *   FAILURE : FALSE
    81508551 */
    8151 static LRESULT LISTVIEW_EraseBackground(HWND hwnd, WPARAM wParam,
     8552static LRESULT LISTVIEW_EraseBackground(HWND hwnd, WPARAM wParam, 
    81528553                                        LPARAM lParam)
    81538554{
    8154   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     8555  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    81558556  BOOL bResult;
    81568557
    8157   if (infoPtr->clrBk == CLR_NONE)
    8158   {
    8159     bResult = SendMessageA(GetParent(hwnd), WM_ERASEBKGND, wParam, lParam);
    8160   }
    8161   else
     8558  TRACE("(hwnd=%x, wParam=%x, lParam=%lx)\n", hwnd, wParam, lParam);
     8559 
     8560  if (infoPtr->clrBk == CLR_NONE)
     8561  {
     8562    bResult = SendMessageW(GetParent(hwnd), WM_ERASEBKGND, wParam, lParam);
     8563  }
     8564  else
    81628565  {
    81638566    RECT rc;
     
    81758578static void LISTVIEW_FillBackground(HWND hwnd, HDC hdc, LPRECT rc)
    81768579{
    8177   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    8178 
    8179   if (infoPtr->clrBk != CLR_NONE)
     8580  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     8581
     8582  TRACE("(hwnd=%x, hdc=%x, rc=%p)\n", hwnd, hdc, rc);
     8583
     8584  if (infoPtr->clrBk != CLR_NONE)
    81808585  {
    81818586    HBRUSH hBrush = CreateSolidBrush(infoPtr->clrBk);
     
    81888593 * DESCRIPTION:
    81898594 * Retrieves the listview control font.
    8190  *
     8595 * 
    81918596 * PARAMETER(S):
    81928597 * [I] HWND : window handle
     
    81978602static LRESULT LISTVIEW_GetFont(HWND hwnd)
    81988603{
    8199   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     8604  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     8605
     8606  TRACE("(hwnd=%x)\n", hwnd);
    82008607
    82018608  return infoPtr->hFont;
     
    82058612 * DESCRIPTION:
    82068613 * Performs vertical scrolling.
    8207  *
     8614 * 
    82088615 * PARAMETER(S):
    82098616 * [I] HWND : window handle
    82108617 * [I] INT : scroll code
    8211  * [I] SHORT : current scroll position if scroll code is SB_THUMBPOSITION
     8618 * [I] SHORT : current scroll position if scroll code is SB_THUMBPOSITION 
    82128619 *             or SB_THUMBTRACK.
    82138620 * [I] HWND : scrollbar control window handle
     
    82198626                                HWND hScrollWnd)
    82208627{
     8628  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    82218629  SCROLLINFO scrollInfo;
    82228630
    8223   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    8224   SendMessageA(infoPtr->hwndEdit, WM_KILLFOCUS, 0, 0);
     8631  TRACE("(hwnd=%x, nScrollCode=%d, nCurrentPos=%d, hScrollWnd=%x)\n",
     8632        hwnd, nScrollCode, nCurrentPos, hScrollWnd);
     8633
     8634  SendMessageW(infoPtr->hwndEdit, WM_KILLFOCUS, 0, 0);
    82258635
    82268636  ZeroMemory(&scrollInfo, sizeof(SCROLLINFO));
     
    82358645    case SB_LINEUP:
    82368646      if (scrollInfo.nPos > scrollInfo.nMin)
    8237       {
    82388647        scrollInfo.nPos--;
    8239       }
    82408648    break;
    8241 
     8649   
    82428650    case SB_LINEDOWN:
    82438651      if (scrollInfo.nPos < scrollInfo.nMax)
    8244       {
    82458652        scrollInfo.nPos++;
    8246       }
    82478653      break;
    8248 
     8654     
    82498655    case SB_PAGEUP:
    82508656      if (scrollInfo.nPos > scrollInfo.nMin)
    82518657      {
    82528658        if (scrollInfo.nPos >= scrollInfo.nPage)
    8253         {
    82548659          scrollInfo.nPos -= scrollInfo.nPage;
    8255         }
    82568660        else
    8257         {
    82588661          scrollInfo.nPos = scrollInfo.nMin;
    8259         }
    82608662      }
    82618663      break;
    8262 
     8664     
    82638665    case SB_PAGEDOWN:
    82648666      if (scrollInfo.nPos < scrollInfo.nMax)
    82658667      {
    82668668        if (scrollInfo.nPos <= scrollInfo.nMax - scrollInfo.nPage)
    8267         {
    82688669          scrollInfo.nPos += scrollInfo.nPage;
    8269         }
    82708670        else
    8271         {
    82728671          scrollInfo.nPos = scrollInfo.nMax;
    8273         }
    82748672      }
    82758673      break;
     
    82918689      scrollInfo.fMask = SIF_POS;
    82928690      SetScrollInfo(hwnd, SB_VERT, &scrollInfo, TRUE);
    8293       InvalidateRect(hwnd, NULL, TRUE);
    8294     }
    8295   }
    8296 
     8691      if (IsWindowVisible(infoPtr->hwndHeader))
     8692      {
     8693        RECT rListview, rcHeader, rDest;
     8694        GetClientRect(hwnd, &rListview);
     8695        GetWindowRect(infoPtr->hwndHeader, &rcHeader);
     8696        MapWindowPoints((HWND) NULL, hwnd, (LPPOINT) &rcHeader, 2);
     8697        SubtractRect(&rDest, &rListview, &rcHeader);
     8698        InvalidateRect(hwnd, &rDest, TRUE);
     8699      }
     8700      else
     8701        InvalidateRect(hwnd, NULL, TRUE);
     8702    }
     8703  }
     8704   
    82978705  return 0;
    82988706}
     
    83018709 * DESCRIPTION:
    83028710 * Performs horizontal scrolling.
    8303  *
     8711 * 
    83048712 * PARAMETER(S):
    83058713 * [I] HWND : window handle
    83068714 * [I] INT : scroll code
    8307  * [I] SHORT : current scroll position if scroll code is SB_THUMBPOSITION
     8715 * [I] SHORT : current scroll position if scroll code is SB_THUMBPOSITION 
    83088716 *             or SB_THUMBTRACK.
    83098717 * [I] HWND : scrollbar control window handle
     
    83158723                                HWND hScrollWnd)
    83168724{
     8725  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    83178726  SCROLLINFO scrollInfo;
    83188727
    8319   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    8320   SendMessageA(infoPtr->hwndEdit, WM_KILLFOCUS, 0, 0);
    8321 
     8728  TRACE("(hwnd=%x, nScrollCode=%d, nCurrentPos=%d, hScrollWnd=%x)\n",
     8729        hwnd, nScrollCode, nCurrentPos, hScrollWnd);
     8730 
     8731  SendMessageW(infoPtr->hwndEdit, WM_KILLFOCUS, 0, 0);
    83228732
    83238733  ZeroMemory(&scrollInfo, sizeof(SCROLLINFO));
    83248734  scrollInfo.cbSize = sizeof(SCROLLINFO);
    83258735  scrollInfo.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
    8326 
     8736 
    83278737  if (GetScrollInfo(hwnd, SB_HORZ, &scrollInfo) != FALSE)
    83288738  {
     
    83338743    case SB_LINELEFT:
    83348744      if (scrollInfo.nPos > scrollInfo.nMin)
    8335       {
    83368745        scrollInfo.nPos--;
    8337       }
    83388746      break;
    8339 
     8747   
    83408748    case SB_LINERIGHT:
    83418749      if (scrollInfo.nPos < scrollInfo.nMax)
    8342       {
    83438750        scrollInfo.nPos++;
    8344       }
    83458751      break;
    8346 
     8752     
    83478753    case SB_PAGELEFT:
    83488754      if (scrollInfo.nPos > scrollInfo.nMin)
    83498755      {
    83508756        if (scrollInfo.nPos >= scrollInfo.nPage)
    8351         {
    83528757          scrollInfo.nPos -= scrollInfo.nPage;
    8353         }
    83548758        else
    8355         {
    83568759          scrollInfo.nPos = scrollInfo.nMin;
    8357         }
    83588760      }
    83598761      break;
    8360 
     8762     
    83618763    case SB_PAGERIGHT:
    83628764      if (scrollInfo.nPos < scrollInfo.nMax)
    83638765      {
    83648766        if (scrollInfo.nPos <= scrollInfo.nMax - scrollInfo.nPage)
    8365         {
    83668767          scrollInfo.nPos += scrollInfo.nPage;
    8367         }
    83688768        else
    8369         {
    83708769          scrollInfo.nPos = scrollInfo.nMax;
    8371         }
    83728770      }
    83738771      break;
     
    83878785    if (nOldScrollPos != scrollInfo.nPos)
    83888786    {
    8389       UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
     8787      UINT uView = GetWindowLongW(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    83908788      scrollInfo.fMask = SIF_POS;
    83918789      SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE);
     
    83998797    }
    84008798  }
    8401 
     8799   
    84028800  return 0;
    84038801}
     
    84058803static LRESULT LISTVIEW_MouseWheel(HWND hwnd, INT wheelDelta)
    84068804{
     8805    UINT uView = GetWindowLongW(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    84078806    INT gcWheelDelta = 0;
    84088807    UINT pulScrollLines = 3;
    84098808    SCROLLINFO scrollInfo;
    84108809
    8411     UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
     8810    TRACE("(hwnd=%x, wheelDelta=%d)\n", hwnd, wheelDelta);
    84128811
    84138812    SystemParametersInfoW(SPI_GETWHEELSCROLLLINES,0, &pulScrollLines, 0);
     
    84518850/***
    84528851 * DESCRIPTION:
    8453  * ???
    8454  *
    8455  * PARAMETER(S):
    8456  * [I] HWND : window handle
    8457  * [I] INT : virtual key
     8852 * ??? 
     8853 * 
     8854 * PARAMETER(S):
     8855 * [I] HWND : window handle
     8856 * [I] INT : virtual key 
    84588857 * [I] LONG : key data
    84598858 *
     
    84638862static LRESULT LISTVIEW_KeyDown(HWND hwnd, INT nVirtualKey, LONG lKeyData)
    84648863{
    8465   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     8864  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     8865  UINT uView =  GetWindowLongW(hwnd, GWL_STYLE) & LVS_TYPEMASK;
     8866  INT nItem = -1;
    84668867  INT nCtrlId = GetWindowLongA(hwnd, GWL_ID);
     8868  NMLVKEYDOWN nmKeyDown;
    84678869  HWND hwndParent = GetParent(hwnd);
    8468   NMLVKEYDOWN nmKeyDown;
    8469   NMHDR nmh;
    8470   INT nItem = -1;
    8471   BOOL bRedraw = FALSE;
    8472   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
    8473   UINT uView =  lStyle & LVS_TYPEMASK;
     8870
     8871  TRACE("(hwnd=%x, nVirtualKey=%d, lKeyData=%ld)\n", hwnd, nVirtualKey, lKeyData);
    84748872
    84758873  /* send LVN_KEYDOWN notification */
    8476   ZeroMemory(&nmKeyDown, sizeof(NMLVKEYDOWN));
    8477   nmKeyDown.hdr.hwndFrom = hwnd;
    8478   nmKeyDown.hdr.idFrom = nCtrlId;
    8479   nmKeyDown.hdr.code = LVN_KEYDOWN;
    8480   nmKeyDown.wVKey = nVirtualKey;
     8874  nmKeyDown.wVKey = nVirtualKey;
    84818875  nmKeyDown.flags = 0;
    84828876#ifdef __WIN32OS2__
     
    84868880  }
    84878881#else
    8488   SendMessageA(hwndParent, WM_NOTIFY, (WPARAM)nCtrlId, (LPARAM)&nmKeyDown);
     8882  notify(hwnd, LVN_KEYDOWN, &nmKeyDown.hdr);
    84898883#endif
    8490 
    8491   /* initialize */
    8492   nmh.hwndFrom = hwnd;
    8493   nmh.idFrom = nCtrlId;
    8494 
     8884 
    84958885  switch (nVirtualKey)
    84968886  {
     
    84988888    if ((GETITEMCOUNT(infoPtr) > 0) && (infoPtr->nFocusedItem != -1))
    84998889    {
    8500       /* send NM_RETURN notification */
    8501       nmh.code = NM_RETURN;
    8502       ListView_Notify(hwndParent, nCtrlId, &nmh);
    8503 
    8504       /* send LVN_ITEMACTIVATE notification */
    8505       nmh.code = LVN_ITEMACTIVATE;
    8506       ListView_Notify(hwndParent, nCtrlId, &nmh);
     8890      hdr_notify(hwnd, NM_RETURN);        /* NM_RETURN notification */
     8891      hdr_notify(hwnd, LVN_ITEMACTIVATE); /* LVN_ITEMACTIVATE notification */
    85078892    }
    85088893    break;
     
    85108895  case VK_HOME:
    85118896    if (GETITEMCOUNT(infoPtr) > 0)
    8512     {
    85138897      nItem = 0;
    8514     }
    85158898    break;
    85168899
    85178900  case VK_END:
    85188901    if (GETITEMCOUNT(infoPtr) > 0)
    8519     {
    85208902      nItem = GETITEMCOUNT(infoPtr) - 1;
    8521     }
    85228903    break;
    85238904
     
    85298910    nItem = ListView_GetNextItem(hwnd, infoPtr->nFocusedItem, LVNI_ABOVE);
    85308911    break;
    8531 
     8912   
    85328913  case VK_RIGHT:
    85338914    nItem = ListView_GetNextItem(hwnd, infoPtr->nFocusedItem, LVNI_TORIGHT);
     
    85408921  case VK_PRIOR:
    85418922    if (uView == LVS_REPORT)
    8542     {
    85438923      nItem = infoPtr->nFocusedItem - LISTVIEW_GetCountPerColumn(hwnd);
    8544     }
    85458924    else
    8546     {
    8547       nItem = infoPtr->nFocusedItem - LISTVIEW_GetCountPerColumn(hwnd)
     8925      nItem = infoPtr->nFocusedItem - LISTVIEW_GetCountPerColumn(hwnd)
    85488926                                    * LISTVIEW_GetCountPerRow(hwnd);
    8549     }
    85508927    if(nItem < 0) nItem = 0;
    85518928    break;
     
    85538930  case VK_NEXT:
    85548931    if (uView == LVS_REPORT)
    8555     {
    85568932      nItem = infoPtr->nFocusedItem + LISTVIEW_GetCountPerColumn(hwnd);
    8557     }
    85588933    else
    8559     {
    85608934      nItem = infoPtr->nFocusedItem + LISTVIEW_GetCountPerColumn(hwnd)
    85618935                                    * LISTVIEW_GetCountPerRow(hwnd);
    8562     }
    85638936    if(nItem >= GETITEMCOUNT(infoPtr)) nItem = GETITEMCOUNT(infoPtr) - 1;
    85648937    break;
     
    85678940  if ((nItem != -1) && (nItem != infoPtr->nFocusedItem))
    85688941  {
    8569     bRedraw = LISTVIEW_KeySelection(hwnd, nItem);
    8570     if (bRedraw != FALSE)
    8571     {
    8572       /* refresh client area */
    8573       UpdateWindow(hwnd);
    8574     }
     8942    if (LISTVIEW_KeySelection(hwnd, nItem))
     8943      UpdateWindow(hwnd); /* update client area */
    85758944  }
    85768945
     
    85818950 * DESCRIPTION:
    85828951 * Kills the focus.
    8583  *
     8952 * 
    85848953 * PARAMETER(S):
    85858954 * [I] HWND : window handle
     
    85908959static LRESULT LISTVIEW_KillFocus(HWND hwnd)
    85918960{
    8592   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongA(hwnd, 0);
    8593   INT nCtrlId = GetWindowLongA(hwnd, GWL_ID);
    8594   NMHDR nmh;
     8961  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongW(hwnd, 0);
     8962  UINT uView =  GetWindowLongW(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    85958963  INT i,nTop,nBottom;
    8596   RECT rcItem;
    8597   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
    8598   UINT uView =  lStyle & LVS_TYPEMASK;
    8599 
     8964 
    86008965  TRACE("(hwnd=%x)\n", hwnd);
    86018966
    86028967  /* send NM_KILLFOCUS notification */
    8603   nmh.hwndFrom = hwnd;
    8604   nmh.idFrom = nCtrlId;
    8605   nmh.code = NM_KILLFOCUS;
    8606   ListView_Notify(GetParent(hwnd), nCtrlId, &nmh);
     8968  hdr_notify(hwnd, NM_KILLFOCUS);
    86078969
    86088970  /* set window focus flag */
     
    86118973  /* NEED drawing optimization ; redraw the selected items */
    86128974  if (uView & LVS_REPORT)
    8613   {
     8975  { 
    86148976    nTop = LISTVIEW_GetTopIndex(hwnd);
    8615     nBottom = nTop +
     8977    nBottom = nTop + 
    86168978              LISTVIEW_GetCountPerColumn(hwnd) + 1;
    86178979  }
     
    86258987    if (LISTVIEW_IsSelected(hwnd,i))
    86268988    {
     8989      RECT rcItem;
    86278990      rcItem.left = LVIR_BOUNDS;
    86288991      LISTVIEW_GetItemRect(hwnd, i, &rcItem);
     
    86379000 * DESCRIPTION:
    86389001 * Processes double click messages (left mouse button).
    8639  *
     9002 * 
    86409003 * PARAMETER(S):
    86419004 * [I] HWND : window handle
     
    86479010 * Zero
    86489011 */
    8649 static LRESULT LISTVIEW_LButtonDblClk(HWND hwnd, WORD wKey, WORD wPosX,
     9012static LRESULT LISTVIEW_LButtonDblClk(HWND hwnd, WORD wKey, WORD wPosX, 
    86509013                                      WORD wPosY)
    86519014{
    8652   LONG nCtrlId = GetWindowLongA(hwnd, GWL_ID);
    86539015  LVHITTESTINFO htInfo;
    8654   NMHDR nmh;
    86559016  NMLISTVIEW nmlv;
    8656   INT ret;
    8657 
    8658   TRACE("(hwnd=%x,key=%hu,X=%hu,Y=%hu)\n", hwnd, wKey, wPosX, wPosY);
     9017
     9018  TRACE("(hwnd=%x, key=%hu, X=%hu, Y=%hu)\n", hwnd, wKey, wPosX, wPosY);
    86599019
    86609020  htInfo.pt.x = wPosX;
     
    86639023  /* send NM_DBLCLK notification */
    86649024  ZeroMemory(&nmlv, sizeof(NMLISTVIEW));
    8665   nmlv.hdr.hwndFrom = hwnd;
    8666   nmlv.hdr.idFrom = nCtrlId;
    8667   nmlv.hdr.code = NM_DBLCLK;
    8668   ret = LISTVIEW_HitTestItem(hwnd, &htInfo, TRUE);
    8669   if (ret != -1)
     9025  if (LISTVIEW_HitTestItem(hwnd, &htInfo, TRUE) != -1)
    86709026  {
    86719027    nmlv.iItem = htInfo.iItem;
     
    86769032    nmlv.iItem = -1;
    86779033    nmlv.iSubItem = 0;
    8678   }
     9034  } 
    86799035  nmlv.ptAction.x = wPosX;
    86809036  nmlv.ptAction.y = wPosY;
    8681   ListView_LVNotify(GetParent(hwnd), nCtrlId, &nmlv);
     9037  listview_notify(hwnd, NM_DBLCLK, &nmlv);
    86829038
    86839039
    86849040  /* To send the LVN_ITEMACTIVATE, it must be on an Item */
    8685   if(ret != -1)
    8686   {
    8687     /* send LVN_ITEMACTIVATE notification */
    8688     nmh.hwndFrom = hwnd;
    8689     nmh.idFrom = nCtrlId;
    8690     nmh.code = LVN_ITEMACTIVATE;
    8691     ListView_Notify(GetParent(hwnd), nCtrlId, &nmh);
    8692   }
     9041  if(nmlv.iItem != -1)
     9042    hdr_notify(hwnd, LVN_ITEMACTIVATE);
    86939043
    86949044  return 0;
     
    86989048 * DESCRIPTION:
    86999049 * Processes mouse down messages (left mouse button).
    8700  *
     9050 * 
    87019051 * PARAMETER(S):
    87029052 * [I] HWND : window handle
     
    87089058 * Zero
    87099059 */
    8710 static LRESULT LISTVIEW_LButtonDown(HWND hwnd, WORD wKey, WORD wPosX,
     9060static LRESULT LISTVIEW_LButtonDown(HWND hwnd, WORD wKey, WORD wPosX, 
    87119061                                    WORD wPosY)
    87129062{
    8713   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    8714   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
    8715   INT nCtrlId = GetWindowLongA(hwnd, GWL_ID);
     9063  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     9064  LONG lStyle = GetWindowLongW(hwnd, GWL_STYLE);
     9065  INT nCtrlId = GetWindowLongW(hwnd, GWL_ID);
    87169066  static BOOL bGroupSelect = TRUE;
    87179067  POINT ptPosition;
    8718   NMHDR nmh;
    87199068  INT nItem;
    87209069
    8721   TRACE("(hwnd=%x, key=%hu, X=%hu, Y=%hu)\n", hwnd, wKey, wPosX,
    8722         wPosY);
     9070  TRACE("(hwnd=%x, key=%hu, X=%hu, Y=%hu)\n", hwnd, wKey, wPosX, wPosY);
    87239071
    87249072  /* send NM_RELEASEDCAPTURE notification */
    8725   nmh.hwndFrom = hwnd;
    8726   nmh.idFrom = nCtrlId;
    8727   nmh.code = NM_RELEASEDCAPTURE;
    8728   ListView_Notify(GetParent(hwnd), nCtrlId, &nmh);
    8729 
     9073  hdr_notify(hwnd, NM_RELEASEDCAPTURE);
     9074 
    87309075  if (infoPtr->bFocus == FALSE)
    8731   {
    87329076    SetFocus(hwnd);
    8733   }
    87349077
    87359078  /* set left button down flag */
    87369079  infoPtr->bLButtonDown = TRUE;
    8737 
     9080 
    87389081  ptPosition.x = wPosX;
    87399082  ptPosition.y = wPosY;
     
    87449087    {
    87459088      if ((ListView_GetItemState(hwnd, nItem, LVIS_SELECTED) & LVIS_SELECTED)
    8746           && infoPtr->nEditLabelItem == -1)
    8747       {
     9089          && infoPtr->nEditLabelItem == -1)
    87489090          infoPtr->nEditLabelItem = nItem;
    8749       }
    87509091      else
    8751       {
    87529092        LISTVIEW_SetSelection(hwnd, nItem);
    8753       }
    87549093    }
    87559094    else
     
    87579096      if ((wKey & MK_CONTROL) && (wKey & MK_SHIFT))
    87589097      {
    8759         if (bGroupSelect != FALSE)
    8760         {
     9098        if (bGroupSelect)
    87619099          LISTVIEW_AddGroupSelection(hwnd, nItem);
    8762         }
    87639100        else
    8764         {
    87659101          LISTVIEW_AddSelection(hwnd, nItem);
    8766         }
    87679102      }
    87689103      else if (wKey & MK_CONTROL)
     
    87769111      else
    87779112      {
    8778     BOOL was_selected =
    8779         (ListView_GetItemState(hwnd, nItem, LVIS_SELECTED) & LVIS_SELECTED);
    8780 
    8781     /* set selection (clears other pre-existing selections) */
     9113        BOOL was_selected =
     9114            (ListView_GetItemState(hwnd, nItem, LVIS_SELECTED) & LVIS_SELECTED);
     9115
     9116        /* set selection (clears other pre-existing selections) */
    87829117        LISTVIEW_SetSelection(hwnd, nItem);
    87839118
    87849119        if (was_selected && infoPtr->nEditLabelItem == -1)
    8785         {
    87869120          infoPtr->nEditLabelItem = nItem;
    8787         }
    87889121      }
    87899122    }
     
    88099142 * DESCRIPTION:
    88109143 * Processes mouse up messages (left mouse button).
    8811  *
     9144 * 
    88129145 * PARAMETER(S):
    88139146 * [I] HWND : window handle
     
    88199152 * Zero
    88209153 */
    8821 static LRESULT LISTVIEW_LButtonUp(HWND hwnd, WORD wKey, WORD wPosX,
     9154static LRESULT LISTVIEW_LButtonUp(HWND hwnd, WORD wKey, WORD wPosX, 
    88229155                                  WORD wPosY)
    88239156{
    8824   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    8825 
    8826   TRACE("(hwnd=%x,key=%hu,X=%hu,Y=%hu)\n", hwnd, wKey, wPosX, wPosY);
    8827 
    8828   if (infoPtr->bLButtonDown != FALSE)
    8829   {
    8830     INT nCtrlId = GetWindowLongA(hwnd, GWL_ID);
     9157  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     9158
     9159  TRACE("(hwnd=%x, key=%hu, X=%hu, Y=%hu)\n", hwnd, wKey, wPosX, wPosY);
     9160
     9161  if (infoPtr->bLButtonDown != FALSE) 
     9162  {
     9163    LVHITTESTINFO lvHitTestInfo;
    88319164    NMLISTVIEW nmlv;
    8832     LVHITTESTINFO lvHitTestInfo;
    8833     INT ret;
    88349165
    88359166    lvHitTestInfo.pt.x = wPosX;
     
    88389169  /* send NM_CLICK notification */
    88399170    ZeroMemory(&nmlv, sizeof(NMLISTVIEW));
    8840     nmlv.hdr.hwndFrom = hwnd;
    8841     nmlv.hdr.idFrom = nCtrlId;
    8842     nmlv.hdr.code = NM_CLICK;
    8843     ret = LISTVIEW_HitTestItem(hwnd, &lvHitTestInfo, TRUE);
    8844     if (ret != -1)
     9171    if (LISTVIEW_HitTestItem(hwnd, &lvHitTestInfo, TRUE) != -1)
    88459172    {
    88469173        nmlv.iItem = lvHitTestInfo.iItem;
     
    88549181    nmlv.ptAction.x = wPosX;
    88559182    nmlv.ptAction.y = wPosY;
    8856     ListView_LVNotify(GetParent(hwnd), nCtrlId, &nmlv);
    8857 
     9183    listview_notify(hwnd, NM_CLICK, &nmlv);
    88589184
    88599185    /* set left button flag */
     
    88629188    if(infoPtr->nEditLabelItem != -1)
    88639189    {
    8864       if(lvHitTestInfo.iItem == infoPtr->nEditLabelItem)
    8865       {
    8866         LISTVIEW_EditLabelA(hwnd, lvHitTestInfo.iItem);
    8867       }
     9190      if(lvHitTestInfo.iItem == infoPtr->nEditLabelItem && lvHitTestInfo.flags & LVHT_ONITEMLABEL)
     9191        LISTVIEW_EditLabelT(hwnd, lvHitTestInfo.iItem, TRUE);
    88689192      infoPtr->nEditLabelItem = -1;
    88699193    }
     
    88769200 * DESCRIPTION:
    88779201 * Creates the listview control (called before WM_CREATE).
    8878  *
    8879  * PARAMETER(S):
    8880  * [I] HWND : window handle
    8881  * [I] WPARAM : unhandled
     9202 * 
     9203 * PARAMETER(S):
     9204 * [I] HWND : window handle
     9205 * [I] WPARAM : unhandled 
    88829206 * [I] LPARAM : widow creation info
    8883  *
     9207 * 
    88849208 * RETURN:
    88859209 * Zero
     
    88899213  LISTVIEW_INFO *infoPtr;
    88909214
    8891   TRACE("(hwnd=%x,wParam=%x,lParam=%lx)\n", hwnd, wParam, lParam);
     9215  TRACE("(hwnd=%x, wParam=%x, lParam=%lx)\n", hwnd, wParam, lParam);
    88929216
    88939217  /* allocate memory for info structure */
     
    88979221  infoPtr = (LISTVIEW_INFO *)COMCTL32_Alloc(sizeof(LISTVIEW_INFO));
    88989222#endif
    8899   SetWindowLongA(hwnd, 0, (LONG)infoPtr);
    8900   if (infoPtr == NULL)
     9223  if (infoPtr == NULL)
    89019224  {
    89029225    ERR("could not allocate info memory!\n");
     
    89049227  }
    89059228
    8906   if ((LISTVIEW_INFO *)GetWindowLongA(hwnd, 0) != infoPtr)
     9229  SetWindowLongW(hwnd, 0, (LONG)infoPtr);
     9230  if ((LISTVIEW_INFO *)GetWindowLongW(hwnd, 0) != infoPtr)
    89079231  {
    89089232    ERR("pointer assignment error!\n");
     
    89109234  }
    89119235
    8912   return DefWindowProcA(hwnd, WM_NCCREATE, wParam, lParam);
     9236  return DefWindowProcW(hwnd, WM_NCCREATE, wParam, lParam);
    89139237}
    89149238
     
    89169240 * DESCRIPTION:
    89179241 * Destroys the listview control (called after WM_DESTROY).
    8918  *
    8919  * PARAMETER(S):
    8920  * [I] HWND : window handle
    8921  *
     9242 * 
     9243 * PARAMETER(S):
     9244 * [I] HWND : window handle
     9245 * 
    89229246 * RETURN:
    89239247 * Zero
     
    89259249static LRESULT LISTVIEW_NCDestroy(HWND hwnd)
    89269250{
    8927   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     9251  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    89289252
    89299253  TRACE("(hwnd=%x)\n", hwnd);
     
    89519275  COMCTL32_Free(infoPtr);
    89529276
    8953   SetWindowLongA(hwnd, 0, 0);
     9277  SetWindowLongW(hwnd, 0, 0);
    89549278  return 0;
    89559279}
     
    89589282 * DESCRIPTION:
    89599283 * Handles notifications from children.
    8960  *
     9284 * 
    89619285 * PARAMETER(S):
    89629286 * [I] HWND : window handle
    89639287 * [I] INT : control identifier
    89649288 * [I] LPNMHDR : notification information
    8965  *
     9289 * 
    89669290 * RETURN:
    89679291 * Zero
     
    89699293static LRESULT LISTVIEW_Notify(HWND hwnd, INT nCtrlId, LPNMHDR lpnmh)
    89709294{
    8971   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    8972 
    8973   if (lpnmh->hwndFrom == infoPtr->hwndHeader)
     9295  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     9296 
     9297  TRACE("(hwnd=%x, nCtrlId=%d, lpnmh=%p)\n", hwnd, nCtrlId, lpnmh);
     9298 
     9299  if (lpnmh->hwndFrom == infoPtr->hwndHeader)
    89749300  {
    89759301    /* handle notification from header control */
    8976     if (lpnmh->code == HDN_ENDTRACKA)
     9302    if (lpnmh->code == HDN_ENDTRACKW)
    89779303    {
    89789304      infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd);
     
    89989324    }
    89999325#endif
    9000     else if(lpnmh->code ==  HDN_ITEMCLICKA)
     9326    else if(lpnmh->code ==  HDN_ITEMCLICKW || lpnmh->code ==  HDN_ITEMCLICKA)
    90019327    {
    90029328        /* Handle sorting by Header Column */
    90039329        NMLISTVIEW nmlv;
    9004         LPNMHEADERA pnmHeader = (LPNMHEADERA) lpnmh;
    9005         LONG lCtrlId = GetWindowLongA(hwnd, GWL_ID);
    90069330
    90079331        ZeroMemory(&nmlv, sizeof(NMLISTVIEW));
    9008         nmlv.hdr.hwndFrom = hwnd;
    9009         nmlv.hdr.idFrom = lCtrlId;
    9010         nmlv.hdr.code = LVN_COLUMNCLICK;
    90119332        nmlv.iItem = -1;
    9012         nmlv.iSubItem = pnmHeader->iItem;
    9013 
    9014         ListView_LVNotify(GetParent(hwnd),lCtrlId, &nmlv);
    9015 
     9333        nmlv.iSubItem = ((LPNMHEADERW)lpnmh)->iItem;
     9334        listview_notify(hwnd, LVN_COLUMNCLICK, &nmlv);
    90169335    }
    90179336    else if(lpnmh->code == NM_RELEASEDCAPTURE)
     
    90369355 * DESCRIPTION:
    90379356 * Determines the type of structure to use.
    9038  *
     9357 * 
    90399358 * PARAMETER(S):
    90409359 * [I] HWND : window handle of the sender
    9041  * [I] HWND : listview window handle
     9360 * [I] HWND : listview window handle 
    90429361 * [I] INT : command specifying the nature of the WM_NOTIFYFORMAT
    90439362 *
     
    90479366static LRESULT LISTVIEW_NotifyFormat(HWND hwndFrom, HWND hwnd, INT nCommand)
    90489367{
    9049   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    9050 
     9368  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     9369
     9370  TRACE("(hwndFrom=%x, hwnd=%x, nCommand=%d)\n", hwndFrom, hwnd, nCommand);
     9371 
    90519372  if (nCommand == NF_REQUERY)
    9052   {
    9053     /* determine the type of structure to use */
    9054     infoPtr->notifyFormat = SendMessageA(hwndFrom, WM_NOTIFYFORMAT,
     9373    infoPtr->notifyFormat = SendMessageW(hwndFrom, WM_NOTIFYFORMAT,
    90559374                                         (WPARAM)hwnd, (LPARAM)NF_QUERY);
    9056     if (infoPtr->notifyFormat == NFR_UNICODE)
    9057     {
    9058       FIXME("NO support for unicode structures\n");
    9059     }
    9060   }
    9061 
    90629375  return 0;
    90639376}
     
    90669379 * DESCRIPTION:
    90679380 * Paints/Repaints the listview control.
    9068  *
     9381 * 
    90699382 * PARAMETER(S):
    90709383 * [I] HWND : window handle
     
    90789391  PAINTSTRUCT ps;
    90799392
    9080    TRACE("(hwnd=%x,hdc=%x)\n", hwnd, hdc);
     9393  TRACE("(hwnd=%x, hdc=%x)\n", hwnd, hdc);
    90819394
    90829395  if (hdc == 0)
     
    90979410 * DESCRIPTION:
    90989411 * Processes double click messages (right mouse button).
    9099  *
     9412 * 
    91009413 * PARAMETER(S):
    91019414 * [I] HWND : window handle
     
    91079420 * Zero
    91089421 */
    9109 static LRESULT LISTVIEW_RButtonDblClk(HWND hwnd, WORD wKey, WORD wPosX,
     9422static LRESULT LISTVIEW_RButtonDblClk(HWND hwnd, WORD wKey, WORD wPosX, 
    91109423                                      WORD wPosY)
    91119424{
    9112   INT nCtrlId = GetWindowLongA(hwnd, GWL_ID);
    9113   NMHDR nmh;
    9114 
    91159425  TRACE("(hwnd=%x,key=%hu,X=%hu,Y=%hu)\n", hwnd, wKey, wPosX, wPosY);
    91169426
    9117   /* send NM_RELEASEDCAPTURE notification */
    9118   nmh.hwndFrom = hwnd;
    9119   nmh.idFrom = nCtrlId;
    9120   nmh.code = NM_RELEASEDCAPTURE;
    9121   ListView_Notify(GetParent(hwnd), nCtrlId, &nmh);
     9427  /* send NM_RELEASEDCAPTURE notification */
     9428  hdr_notify(hwnd, NM_RELEASEDCAPTURE);
    91229429
    91239430  /* send NM_RDBLCLK notification */
    9124   nmh.code = NM_RDBLCLK;
    9125   ListView_Notify(GetParent(hwnd), nCtrlId, &nmh);
     9431  hdr_notify(hwnd, NM_RDBLCLK);
    91269432
    91279433  return 0;
     
    91319437 * DESCRIPTION:
    91329438 * Processes mouse down messages (right mouse button).
    9133  *
     9439 * 
    91349440 * PARAMETER(S):
    91359441 * [I] HWND : window handle
     
    91419447 * Zero
    91429448 */
    9143 static LRESULT LISTVIEW_RButtonDown(HWND hwnd, WORD wKey, WORD wPosX,
     9449static LRESULT LISTVIEW_RButtonDown(HWND hwnd, WORD wKey, WORD wPosX, 
    91449450                                    WORD wPosY)
    91459451{
    9146   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    9147   INT nCtrlId = GetWindowLongA(hwnd, GWL_ID);
     9452  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    91489453  POINT ptPosition;
    9149   NMHDR nmh;
    91509454  INT nItem;
     9455  NMLISTVIEW nmlv;
     9456  LVHITTESTINFO lvHitTestInfo;
    91519457
    91529458  TRACE("(hwnd=%x,key=%hu,X=%hu,Y=%hu)\n", hwnd, wKey, wPosX, wPosY);
    91539459
    91549460  /* send NM_RELEASEDCAPTURE notification */
    9155   nmh.hwndFrom = hwnd;
    9156   nmh.idFrom = nCtrlId;
    9157   nmh.code = NM_RELEASEDCAPTURE;
    9158   ListView_Notify(GetParent(hwnd), nCtrlId, &nmh);
    9159 
     9461  hdr_notify(hwnd, NM_RELEASEDCAPTURE);
     9462 
    91609463  /* make sure the listview control window has the focus */
    91619464  if (infoPtr->bFocus == FALSE)
    9162   {
    91639465    SetFocus(hwnd);
    9164   }
    91659466
    91669467  /* set right button down flag */
     
    91769477    if (!((wKey & MK_SHIFT) || (wKey & MK_CONTROL)) &&
    91779478        !LISTVIEW_IsSelected(hwnd,nItem))
    9178     {
    91799479      LISTVIEW_SetSelection(hwnd, nItem);
    9180     }
    91819480  }
    91829481  else
     
    91859484  }
    91869485
     9486  lvHitTestInfo.pt.x = wPosX;
     9487  lvHitTestInfo.pt.y = wPosY;
     9488
     9489  /* Send NM_RClICK notification */
     9490  ZeroMemory(&nmlv, sizeof(nmlv));
     9491  if (LISTVIEW_HitTestItem(hwnd, &lvHitTestInfo, TRUE) != -1)
     9492  {
     9493    nmlv.iItem = lvHitTestInfo.iItem;
     9494    nmlv.iSubItem = lvHitTestInfo.iSubItem;
     9495  }
     9496  else
     9497  {
     9498    nmlv.iItem = -1;
     9499    nmlv.iSubItem = 0;
     9500  }
     9501  nmlv.ptAction.x = wPosX;
     9502  nmlv.ptAction.y = wPosY;
     9503  listview_notify(hwnd, NM_RCLICK, &nmlv);
     9504 
    91879505  return 0;
    91889506}
     
    91919509 * DESCRIPTION:
    91929510 * Processes mouse up messages (right mouse button).
    9193  *
     9511 * 
    91949512 * PARAMETER(S):
    91959513 * [I] HWND : window handle
     
    92019519 * Zero
    92029520 */
    9203 static LRESULT LISTVIEW_RButtonUp(HWND hwnd, WORD wKey, WORD wPosX,
     9521static LRESULT LISTVIEW_RButtonUp(HWND hwnd, WORD wKey, WORD wPosX, 
    92049522                                  WORD wPosY)
    92059523{
    9206   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    9207   INT nCtrlId = GetWindowLongA(hwnd, GWL_ID);
     9524  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    92089525
    92099526  TRACE("(hwnd=%x,key=%hu,X=%hu,Y=%hu)\n", hwnd, wKey, wPosX, wPosY);
    92109527
    9211   if (infoPtr->bRButtonDown != FALSE)
    9212   {
    9213     NMLISTVIEW nmlv;
    9214     LVHITTESTINFO lvHitTestInfo;
     9528  if (infoPtr->bRButtonDown)
     9529  {
    92159530    POINT pt;
    9216     INT ret;
    9217 
    9218     lvHitTestInfo.pt.x = wPosX;
    9219     lvHitTestInfo.pt.y = wPosY;
    9220 
    9221     /* Send NM_RClICK notification */
    9222     ZeroMemory(&nmlv, sizeof(NMLISTVIEW));
    9223     nmlv.hdr.hwndFrom = hwnd;
    9224     nmlv.hdr.idFrom = nCtrlId;
    9225     nmlv.hdr.code = NM_RCLICK;
    9226     ret = LISTVIEW_HitTestItem(hwnd, &lvHitTestInfo, TRUE);
    9227     if (ret != -1)
    9228     {
    9229         nmlv.iItem = lvHitTestInfo.iItem;
    9230         nmlv.iSubItem = lvHitTestInfo.iSubItem;
    9231     }
    9232     else
    9233     {
    9234         nmlv.iItem = -1;
    9235         nmlv.iSubItem = 0;
    9236     }
    9237     nmlv.ptAction.x = wPosX;
    9238     nmlv.ptAction.y = wPosY;
    9239     ListView_LVNotify(GetParent(hwnd), nCtrlId, &nmlv);
    92409531
    92419532    pt.x = wPosX;
     
    92449535    /* set button flag */
    92459536    infoPtr->bRButtonDown = FALSE;
    9246 
     9537   
    92479538    /* Change to screen coordinate for WM_CONTEXTMENU */
    92489539    ClientToScreen(hwnd, &pt);
    9249 
     9540   
    92509541    /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
    9251     SendMessageA( hwnd, WM_CONTEXTMENU, (WPARAM) hwnd, MAKELPARAM(pt.x, pt.y));
    9252   }
    9253 
     9542    SendMessageW( hwnd, WM_CONTEXTMENU, (WPARAM) hwnd, MAKELPARAM(pt.x, pt.y));
     9543  }
     9544 
    92549545  return 0;
    92559546}
     
    92579548/***
    92589549 * DESCRIPTION:
    9259  * Sets the focus.
    9260  *
     9550 * Sets the focus. 
     9551 * 
    92619552 * PARAMETER(S):
    92629553 * [I] HWND : window handle
     
    92689559static LRESULT LISTVIEW_SetFocus(HWND hwnd, HWND hwndLoseFocus)
    92699560{
    9270   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    9271   INT nCtrlId = GetWindowLongA(hwnd, GWL_ID);
    9272   NMHDR nmh;
     9561  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    92739562
    92749563  TRACE("(hwnd=%x, hwndLoseFocus=%x)\n", hwnd, hwndLoseFocus);
    92759564
    92769565  /* send NM_SETFOCUS notification */
    9277   nmh.hwndFrom = hwnd;
    9278   nmh.idFrom = nCtrlId;
    9279   nmh.code = NM_SETFOCUS;
    9280   ListView_Notify(GetParent(hwnd), nCtrlId, &nmh);
     9566  hdr_notify(hwnd, NM_SETFOCUS);
    92819567
    92829568  /* set window focus flag */
     
    92909576/***
    92919577 * DESCRIPTION:
    9292  * Sets the font.
    9293  *
     9578 * Sets the font. 
     9579 * 
    92949580 * PARAMETER(S):
    92959581 * [I] HWND : window handle
     
    93029588static LRESULT LISTVIEW_SetFont(HWND hwnd, HFONT hFont, WORD fRedraw)
    93039589{
    9304   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    9305   UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
     9590  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     9591  UINT uView = GetWindowLongW(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    93069592
    93079593  TRACE("(hwnd=%x,hfont=%x,redraw=%hu)\n", hwnd, hFont, fRedraw);
    93089594
    9309   if (hFont == 0)
    9310   {
    9311     infoPtr->hFont = infoPtr->hDefaultFont;
    9312   }
    9313   else
    9314   {
    9315     infoPtr->hFont = hFont;
    9316   }
     9595  infoPtr->hFont = hFont ? hFont : infoPtr->hDefaultFont;
     9596  LISTVIEW_SaveTextMetrics(hwnd);
    93179597
    93189598  if (uView == LVS_REPORT)
    93199599  {
    93209600    /* set header font */
    9321     SendMessageA(infoPtr->hwndHeader, WM_SETFONT, (WPARAM)hFont,
     9601    SendMessageW(infoPtr->hwndHeader, WM_SETFONT, (WPARAM)hFont,
    93229602                   MAKELPARAM(fRedraw, 0));
    93239603  }
     
    93309610  /* invalidate listview control client area */
    93319611  InvalidateRect(hwnd, NULL, TRUE);
    9332 
     9612 
    93339613  if (fRedraw != FALSE)
    9334   {
    93359614    UpdateWindow(hwnd);
    9336   }
    93379615
    93389616  return 0;
     
    93419619/***
    93429620 * DESCRIPTION:
    9343  * Message handling for WM_SETREDRAW.
     9621 * Message handling for WM_SETREDRAW. 
    93449622 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
    9345  *
     9623 * 
    93469624 * PARAMETER(S):
    93479625 * [I] HWND   : window handle
     
    93859663 * Resizes the listview control. This function processes WM_SIZE
    93869664 * messages.  At this time, the width and height are not used.
    9387  *
     9665 * 
    93889666 * PARAMETER(S):
    93899667 * [I] HWND : window handle
     
    93969674static LRESULT LISTVIEW_Size(HWND hwnd, int Width, int Height)
    93979675{
    9398   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     9676  LONG lStyle = GetWindowLongW(hwnd, GWL_STYLE);
    93999677  UINT uView = lStyle & LVS_TYPEMASK;
    94009678#ifdef __WIN32OS2__
    94019679  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    94029680#endif
    9403   TRACE("(hwnd=%x, width=%d, height=%d)\n",hwnd, Width, Height);
    9404 
    9405   LISTVIEW_UpdateSize(hwnd);
    9406 
    9407   if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
    9408   {
    9409     if (lStyle & LVS_ALIGNLEFT)
    9410     {
    9411       LISTVIEW_AlignLeft(hwnd);
    9412     }
    9413     else
    9414     {
    9415       LISTVIEW_AlignTop(hwnd);
    9416     }
    9417   }
    9418 
    9419   LISTVIEW_UpdateScroll(hwnd);
     9681  TRACE("(hwnd=%x, width=%d, height=%d)\n", hwnd, Width, Height);
     9682
     9683  if (LISTVIEW_UpdateSize(hwnd))
     9684  {
     9685    if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
     9686    {
     9687        if (lStyle & LVS_ALIGNLEFT)
     9688            LISTVIEW_AlignLeft(hwnd);
     9689        else
     9690            LISTVIEW_AlignTop(hwnd);
     9691    }
     9692
     9693    LISTVIEW_UpdateScroll(hwnd);
    94209694
    94219695#ifdef __WIN32OS2__
     
    94249698  infoPtr->nItemHeight = LISTVIEW_GetItemHeight(hwnd);
    94259699#endif
    9426 
    9427   /* invalidate client area + erase background */
    9428   InvalidateRect(hwnd, NULL, TRUE);
     9700 
     9701    /* invalidate client area + erase background */
     9702    InvalidateRect(hwnd, NULL, TRUE);
     9703  }
    94299704
    94309705  return 0;
     
    94349709 * DESCRIPTION:
    94359710 * Sets the size information.
    9436  *
    9437  * PARAMETER(S):
    9438  * [I] HWND : window handle
    9439  *
    9440  * RETURN:
    9441  * Zero
    9442  */
    9443 static VOID LISTVIEW_UpdateSize(HWND hwnd)
    9444 {
    9445   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    9446   LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
     9711 *
     9712 * PARAMETER(S):
     9713 * [I] HWND : window handle
     9714 *
     9715 * RETURN:
     9716 * Zero if no size change
     9717 * 1 of size changed
     9718 */
     9719static BOOL LISTVIEW_UpdateSize(HWND hwnd)
     9720{
     9721  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     9722  LONG lStyle = GetWindowLongW(hwnd, GWL_STYLE);
    94479723  UINT uView = lStyle & LVS_TYPEMASK;
    94489724  RECT rcList;
    9449 
     9725  RECT rcOld;
     9726 
     9727  TRACE("(hwnd=%x)\n", hwnd);
     9728 
    94509729  GetClientRect(hwnd, &rcList);
     9730  CopyRect(&rcOld,&(infoPtr->rcList));
    94519731  infoPtr->rcList.left = 0;
    94529732  infoPtr->rcList.right = max(rcList.right - rcList.left, 1);
    94539733  infoPtr->rcList.top = 0;
    94549734  infoPtr->rcList.bottom = max(rcList.bottom - rcList.top, 1);
    9455 
     9735     
    94569736  if (uView == LVS_LIST)
    94579737  {
     
    94609740      INT nHScrollHeight = GetSystemMetrics(SM_CYHSCROLL);
    94619741      if (infoPtr->rcList.bottom > nHScrollHeight)
    9462       {
    94639742        infoPtr->rcList.bottom -= nHScrollHeight;
    9464       }
    94659743    }
    94669744  }
     
    94779755
    94789756    if (!(LVS_NOCOLUMNHEADER & lStyle))
    9479     {
    94809757      infoPtr->rcList.top = max(wp.cy, 0);
    9481     }
    9482   }
    9483 }
    9484 
    9485 /***
    9486  * DESCRIPTION:
    9487  * Processes WM_STYLECHANGED messages.
    9488  *
     9758  }
     9759  return (!EqualRect(&rcOld,&(infoPtr->rcList)));
     9760}
     9761
     9762/***
     9763 * DESCRIPTION:
     9764 * Processes WM_STYLECHANGED messages. 
     9765 * 
    94899766 * PARAMETER(S):
    94909767 * [I] HWND : window handle
     
    94959772 * Zero
    94969773 */
    9497 static INT LISTVIEW_StyleChanged(HWND hwnd, WPARAM wStyleType,
     9774static INT LISTVIEW_StyleChanged(HWND hwnd, WPARAM wStyleType, 
    94989775                                 LPSTYLESTRUCT lpss)
    94999776{
    9500   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     9777  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
    95019778  UINT uNewView = lpss->styleNew & LVS_TYPEMASK;
    95029779  UINT uOldView = lpss->styleOld & LVS_TYPEMASK;
    95039780  RECT rcList = infoPtr->rcList;
    95049781
    9505   TRACE("(hwnd=%x, styletype=%x, stylestruct=%p)\n",
     9782  TRACE("(hwnd=%x, styletype=%x, stylestruct=%p)\n", 
    95069783        hwnd, wStyleType, lpss);
    95079784
     
    95099786  {
    95109787    if (uOldView == LVS_REPORT)
    9511     {
    95129788      ShowWindow(infoPtr->hwndHeader, SW_HIDE);
    9513     }
    9514 
    9515     if ((lpss->styleOld & WS_HSCROLL) != 0)
    9516     {
     9789 
     9790    if (((lpss->styleOld & WS_HSCROLL) != 0)&&
     9791        ((lpss->styleNew & WS_HSCROLL) == 0))
    95179792       ShowScrollBar(hwnd, SB_HORZ, FALSE);
    9518     }
    9519 
    9520     if ((lpss->styleOld & WS_VSCROLL) != 0)
    9521     {
     9793 
     9794    if (((lpss->styleOld & WS_VSCROLL) != 0)&&
     9795        ((lpss->styleNew & WS_VSCROLL) == 0))
    95229796       ShowScrollBar(hwnd, SB_VERT, FALSE);
    9523     }
    9524 
     9797 
    95259798    if (uNewView == LVS_ICON)
    95269799    {
     
    95309803      infoPtr->nItemHeight = LISTVIEW_GetItemHeight(hwnd);
    95319804      if (lpss->styleNew & LVS_ALIGNLEFT)
    9532       {
    95339805        LISTVIEW_AlignLeft(hwnd);
    9534       }
    95359806      else
    9536       {
    95379807        LISTVIEW_AlignTop(hwnd);
    9538       }
    95399808    }
    95409809    else if (uNewView == LVS_REPORT)
     
    95469815      hl.pwpos = &wp;
    95479816      Header_Layout(infoPtr->hwndHeader, &hl);
    9548       SetWindowPos(infoPtr->hwndHeader, hwnd, wp.x, wp.y, wp.cx, wp.cy,
     9817      SetWindowPos(infoPtr->hwndHeader, hwnd, wp.x, wp.y, wp.cx, wp.cy, 
    95499818                   wp.flags);
    95509819      if (!(LVS_NOCOLUMNHEADER & lpss->styleNew))
    95519820        ShowWindow(infoPtr->hwndHeader, SW_SHOWNORMAL);
    9552 
     9821     
    95539822      infoPtr->iconSize.cx = GetSystemMetrics(SM_CXSMICON);
    95549823      infoPtr->iconSize.cy = GetSystemMetrics(SM_CYSMICON);
     
    95709839      infoPtr->nItemHeight = LISTVIEW_GetItemHeight(hwnd);
    95719840      if (lpss->styleNew & LVS_ALIGNLEFT)
    9572       {
    95739841        LISTVIEW_AlignLeft(hwnd);
    9574       }
    95759842      else
    9576       {
    95779843        LISTVIEW_AlignTop(hwnd);
    9578       }
    9579     }
    9580 
     9844    }
    95819845
    95829846    /* update the size of the client area */
     
    95859849    /* add scrollbars if needed */
    95869850    LISTVIEW_UpdateScroll(hwnd);
    9587 
     9851   
    95889852    /* invalidate client area + erase background */
    95899853    InvalidateRect(hwnd, NULL, TRUE);
     
    95939857  }
    95949858
    9595   /* If they change the view and we have an active edit control
     9859  /* If they change the view and we have an active edit control 
    95969860     we will need to kill the control since the redraw will
    95979861     misplace the edit control.
     
    96019865        ((LVS_ICON|LVS_LIST|LVS_SMALLICON) & uOldView)))
    96029866  {
    9603      SendMessageA(infoPtr->hwndEdit, WM_KILLFOCUS, 0, 0);
     9867     SendMessageW(infoPtr->hwndEdit, WM_KILLFOCUS, 0, 0);
    96049868  }
    96059869
     
    980810072  lvItem.header.pszText = NULL;
    980910073  lvItem.mustFree = FALSE;
    9810 //  if (LISTVIEW_GetItemA(hwnd,(LPLVITEMW)&lvItem,TRUE,TRUE))
    9811   if (LISTVIEW_GetItemA(hwnd,(LPLVITEMA)&lvItem,TRUE))
    9812     nLabelWidth = LISTVIEW_GetStringWidth(hwnd,0,lvItem.header.pszText,lvItem.unicode);
     10074  if (LISTVIEW_GetItemT(hwnd,(LPLVITEMW)&lvItem,TRUE,TRUE))
     10075    nLabelWidth = ListView_GetStringWidthW(hwnd,lvItem.header.pszText);
    981310076  if (lvItem.mustFree) COMCTL32_Free(lvItem.header.pszText);
    981410077
     
    1000910272
    1001010273  return FALSE;
    10011 }
    10012 
    10013 static LRESULT LISTVIEW_SetIconSpacing(HWND hwnd,WPARAM wParam,LPARAM lParam)
    10014 {
    10015   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    10016   UINT dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
    10017   UINT uView = dwStyle & LVS_TYPEMASK;
    10018   DWORD oldIS = MAKELONG(infoPtr->iconSpacing.cx,infoPtr->iconSpacing.cy);
    10019   INT cx = LOWORD(lParam),cy = HIWORD(lParam);
    10020 
    10021   if (cx == -1) cx = GetSystemMetrics(SM_CXICONSPACING);
    10022   if (cy == -1) cy = GetSystemMetrics(SM_CYICONSPACING);
    10023   if ((cx != infoPtr->iconSpacing.cx) || (cy != infoPtr->iconSpacing.cy))
    10024   {
    10025     infoPtr->iconSpacing.cx = cx;
    10026     infoPtr->iconSpacing.cy = cy;
    10027     if (((uView == LVS_ICON) || (uView == LVS_SMALLICON)) && (dwStyle & LVS_AUTOARRANGE))
    10028     {
    10029       LISTVIEW_Arrange(hwnd,LVA_DEFAULT);
    10030     }
    10031   }
    10032 
    10033   return oldIS;
    1003410274}
    1003510275
     
    1045110691  TRACE("hwnd=%x uMsg=%x wParam=%x lParam=%lx\n", hwnd, uMsg, wParam, lParam);
    1045210692#endif
    10453 
    10454   if (!GetWindowLongA(hwnd, 0) && (uMsg != WM_NCCREATE))
    10455     return DefWindowProcA( hwnd, uMsg, wParam, lParam );
     10693  if (!GetWindowLongW(hwnd, 0) && (uMsg != WM_NCCREATE))
     10694    return DefWindowProcW( hwnd, uMsg, wParam, lParam );
    1045610695  switch (uMsg)
    1045710696  {
    10458   case LVM_APPROXIMATEVIEWRECT:
    10459     return LISTVIEW_ApproximateViewRect(hwnd, (INT)wParam,
     10697  case LVM_APPROXIMATEVIEWRECT: 
     10698    return LISTVIEW_ApproximateViewRect(hwnd, (INT)wParam, 
    1046010699                                        LOWORD(lParam), HIWORD(lParam));
    10461   case LVM_ARRANGE:
     10700  case LVM_ARRANGE: 
    1046210701    return LISTVIEW_Arrange(hwnd, (INT)wParam);
    1046310702
     
    1046710706
    1046810707#endif
     10708
    1046910709/* case LVM_CREATEDRAGIMAGE: */
    1047010710
     
    1047910719
    1048010720  case LVM_EDITLABELW:
     10721    return LISTVIEW_EditLabelT(hwnd, (INT)wParam, TRUE);
     10722   
    1048110723  case LVM_EDITLABELA:
    10482     return LISTVIEW_EditLabelA(hwnd, (INT)wParam);
     10724    return LISTVIEW_EditLabelT(hwnd, (INT)wParam, FALSE);
    1048310725
    1048410726  case LVM_ENSUREVISIBLE:
    1048510727    return LISTVIEW_EnsureVisible(hwnd, (INT)wParam, (BOOL)lParam);
    1048610728
     10729  case LVM_FINDITEMW:
     10730    return LISTVIEW_FindItemW(hwnd, (INT)wParam, (LPLVFINDINFOW)lParam);
     10731
    1048710732  case LVM_FINDITEMA:
    10488     return LISTVIEW_FindItem(hwnd, (INT)wParam, (LPLVFINDINFO)lParam);
     10733    return LISTVIEW_FindItemA(hwnd, (INT)wParam, (LPLVFINDINFOA)lParam);
    1048910734
    1049010735  case LVM_GETBKCOLOR:
     
    1049810743    return LISTVIEW_GetBkImage(hwnd,wParam,lParam,TRUE);
    1049910744#endif
    10500 /*  case LVM_GETBKIMAGE: */
     10745/*      case LVM_GETBKIMAGE: */
    1050110746
    1050210747  case LVM_GETCALLBACKMASK:
     
    1050410749
    1050510750  case LVM_GETCOLUMNA:
    10506     return LISTVIEW_GetColumnA(hwnd, (INT)wParam, (LPLVCOLUMNA)lParam);
    10507 
    10508 /*  case LVM_GETCOLUMNW: */
     10751    return LISTVIEW_GetColumnT(hwnd, (INT)wParam, (LPLVCOLUMNW)lParam, FALSE);
     10752
     10753  case LVM_GETCOLUMNW:
     10754    return LISTVIEW_GetColumnT(hwnd, (INT)wParam, (LPLVCOLUMNW)lParam, TRUE);
    1050910755
    1051010756  case LVM_GETCOLUMNORDERARRAY:
     
    1052610772    return LISTVIEW_GetHeader(hwnd);
    1052710773
    10528 /*  case LVM_GETHOTCURSOR: */
    1052910774#ifdef __WIN32OS2__
    1053010775  case LVM_GETHOTCURSOR:
     
    1054110786    return LISTVIEW_GetImageList(hwnd, (INT)wParam);
    1054210787
    10543 /*  case LVM_GETISEARCHSTRING: */
    10544 
    1054510788#ifdef __WIN32OS2__
    1054610789  case LVM_GETISEARCHSTRINGA:
     
    1055210795
    1055310796  case LVM_GETITEMA:
    10554     return LISTVIEW_GetItemA(hwnd, (LPLVITEMA)lParam, FALSE);
    10555 
    10556 /*  case LVM_GETITEMW: */
     10797    return LISTVIEW_GetItemT(hwnd, (LPLVITEMW)lParam, FALSE, FALSE);
     10798
     10799  case LVM_GETITEMW:
     10800    return LISTVIEW_GetItemT(hwnd, (LPLVITEMW)lParam, FALSE, TRUE);
    1055710801
    1055810802  case LVM_GETITEMCOUNT:
     
    1056210806    return LISTVIEW_GetItemPosition(hwnd, (INT)wParam, (LPPOINT)lParam);
    1056310807
    10564   case LVM_GETITEMRECT:
     10808  case LVM_GETITEMRECT: 
    1056510809    return LISTVIEW_GetItemRect(hwnd, (INT)wParam, (LPRECT)lParam);
    1056610810
    10567   case LVM_GETITEMSPACING:
     10811  case LVM_GETITEMSPACING: 
    1056810812    return LISTVIEW_GetItemSpacing(hwnd, (BOOL)wParam);
    1056910813
    10570   case LVM_GETITEMSTATE:
     10814  case LVM_GETITEMSTATE: 
    1057110815    return LISTVIEW_GetItemState(hwnd, (INT)wParam, (UINT)lParam);
    10572 
     10816   
    1057310817  case LVM_GETITEMTEXTA:
    10574     LISTVIEW_GetItemTextA(hwnd, (INT)wParam, (LPLVITEMA)lParam);
    10575     break;
    10576 
    10577 /*  case LVM_GETITEMTEXTW: */
     10818    return LISTVIEW_GetItemTextT(hwnd, (INT)wParam, (LPLVITEMW)lParam, FALSE);
     10819
     10820  case LVM_GETITEMTEXTW:
     10821    return LISTVIEW_GetItemTextT(hwnd, (INT)wParam, (LPLVITEMW)lParam, TRUE);
    1057810822
    1057910823  case LVM_GETNEXTITEM:
    1058010824    return LISTVIEW_GetNextItem(hwnd, (INT)wParam, LOWORD(lParam));
    10581 
    10582 /*  case LVM_GETNUMBEROFWORKAREAS: */
    1058310825
    1058410826#ifdef __WIN32OS2__
     
    1059310835    return LISTVIEW_GetSelectedCount(hwnd);
    1059410836
    10595   case LVM_GETSELECTIONMARK:
     10837  case LVM_GETSELECTIONMARK: 
    1059610838    return LISTVIEW_GetSelectionMark(hwnd);
    1059710839
    1059810840  case LVM_GETSTRINGWIDTHA:
    10599     return LISTVIEW_GetStringWidthA (hwnd, (LPCSTR)lParam);
    10600 
    10601 /*  case LVM_GETSTRINGWIDTHW: */
    10602 /*  case LVM_GETSUBITEMRECT: */
     10841    return LISTVIEW_GetStringWidthT(hwnd, (LPCWSTR)lParam, FALSE);
     10842
     10843  case LVM_GETSTRINGWIDTHW:
     10844    return LISTVIEW_GetStringWidthT(hwnd, (LPCWSTR)lParam, TRUE);
    1060310845
    1060410846#ifdef __WIN32OS2__
     
    1060610848      return LISTVIEW_GetSubItemRect(hwnd,(INT)wParam,(LPRECT)lParam);
    1060710849#endif
    10608 
     10850   
    1060910851  case LVM_GETTEXTBKCOLOR:
    1061010852    return LISTVIEW_GetTextBkColor(hwnd);
     
    1061310855    return LISTVIEW_GetTextColor(hwnd);
    1061410856
    10615 /*  case LVM_GETTOOLTIPS: */
    1061610857#ifdef __WIN32OS2__
    1061710858  case LVM_GETTOOLTIPS:
     
    1062210863    return LISTVIEW_GetTopIndex(hwnd);
    1062310864
    10624 /*  case LVM_GETUNICODEFORMAT: */
     10865  /*case LVM_GETUNICODEFORMAT:
     10866    FIXME("LVM_GETUNICODEFORMAT: unimplemented\n");
     10867    return FALSE;*/
    1062510868
    1062610869  case LVM_GETVIEWRECT:
    1062710870    return LISTVIEW_GetViewRect(hwnd, (LPRECT)lParam);
    1062810871
    10629 /*  case LVM_GETWORKAREAS: */
    1063010872#ifdef __WIN32OS2__
    1063110873  case LVM_GETWORKAREAS:
     
    1063710879
    1063810880  case LVM_INSERTCOLUMNA:
    10639     return LISTVIEW_InsertColumnA(hwnd, (INT)wParam, (LPLVCOLUMNA)lParam);
     10881    return LISTVIEW_InsertColumnT(hwnd, (INT)wParam, (LPLVCOLUMNW)lParam, FALSE);
    1064010882
    1064110883  case LVM_INSERTCOLUMNW:
    10642     return LISTVIEW_InsertColumnW(hwnd, (INT)wParam, (LPLVCOLUMNW)lParam);
     10884    return LISTVIEW_InsertColumnT(hwnd, (INT)wParam, (LPLVCOLUMNW)lParam, TRUE);
    1064310885
    1064410886  case LVM_INSERTITEMA:
    10645     return LISTVIEW_InsertItemA(hwnd, (LPLVITEMA)lParam);
     10887    return LISTVIEW_InsertItemT(hwnd, (LPLVITEMW)lParam, FALSE);
    1064610888
    1064710889  case LVM_INSERTITEMW:
    10648     return LISTVIEW_InsertItemW(hwnd, (LPLVITEMW)lParam);
     10890    return LISTVIEW_InsertItemT(hwnd, (LPLVITEMW)lParam, TRUE);
    1064910891
    1065010892  case LVM_REDRAWITEMS:
     
    1065510897    return LISTVIEW_Scroll(hwnd, (INT)wParam, (INT)lParam);
    1065610898#endif
     10899
    1065710900/*   case LVM_SCROLL:  */
    1065810901/*     return LISTVIEW_Scroll(hwnd, (INT)wParam, (INT)lParam); */
     
    1066110904    return LISTVIEW_SetBkColor(hwnd, (COLORREF)lParam);
    1066210905
    10663 /*  case LVM_SETBKIMAGE: */
     10906/*      case LVM_SETBKIMAGE: */
     10907
    1066410908#ifdef __WIN32OS2__
    1066510909  case LVM_SETBKIMAGEA:
     
    1067410918
    1067510919  case LVM_SETCOLUMNA:
    10676     return LISTVIEW_SetColumnA(hwnd, (INT)wParam, (LPLVCOLUMNA)lParam);
     10920    return LISTVIEW_SetColumnT(hwnd, (INT)wParam, (LPLVCOLUMNW)lParam, FALSE);
    1067710921
    1067810922  case LVM_SETCOLUMNW:
    10679     FIXME("Unimplemented msg LVM_SETCOLUMNW\n");
    10680     return 0;
     10923    return LISTVIEW_SetColumnT(hwnd, (INT)wParam, (LPLVCOLUMNW)lParam, TRUE);
    1068110924
    1068210925  case LVM_SETCOLUMNORDERARRAY:
     
    1068910932    return LISTVIEW_SetExtendedListViewStyle(hwnd, (DWORD)wParam, (DWORD)lParam);
    1069010933
    10691 /*  case LVM_SETHOTCURSOR: */
    1069210934#ifdef __WIN32OS2__
    1069310935  case LVM_SETHOTCURSOR:
     
    1069510937#endif
    1069610938
     10939/*      case LVM_SETHOTCURSOR: */
     10940
    1069710941  case LVM_SETHOTITEM:
    1069810942    return LISTVIEW_SetHotItem(hwnd, (INT)wParam);
     
    1070010944  case LVM_SETHOVERTIME:
    1070110945    return LISTVIEW_SetHoverTime(hwnd, (DWORD)wParam);
    10702 
    10703 /*  case LVM_SETICONSPACING: */
    1070410946#ifdef __WIN32OS2__
    1070510947  case LVM_SETICONSPACING:
    1070610948    return LISTVIEW_SetIconSpacing(hwnd,wParam,lParam);
    10707 #endif
    10708 
     10949#else
     10950  case LVM_SETICONSPACING:
     10951    return LISTVIEW_SetIconSpacing(hwnd, (DWORD)lParam);
     10952#endif 
    1070910953  case LVM_SETIMAGELIST:
    10710     return LISTVIEW_SetImageList(hwnd, (INT)wParam, (HIMAGELIST)lParam);
     10954    return (LRESULT)LISTVIEW_SetImageList(hwnd, (INT)wParam, (HIMAGELIST)lParam);
    1071110955
    1071210956  case LVM_SETITEMA:
    10713     return LISTVIEW_SetItemA(hwnd, (LPLVITEMA)lParam);
    10714 
    10715 /*  case LVM_SETITEMW: */
    10716 
    10717   case LVM_SETITEMCOUNT:
     10957    return LISTVIEW_SetItemT(hwnd, (LPLVITEMW)lParam, FALSE);
     10958
     10959  case LVM_SETITEMW:
     10960    return LISTVIEW_SetItemT(hwnd, (LPLVITEMW)lParam, TRUE);
     10961
     10962  case LVM_SETITEMCOUNT:
    1071810963    return LISTVIEW_SetItemCount(hwnd, (INT)wParam, (DWORD)lParam);
    10719 
     10964   
    1072010965  case LVM_SETITEMPOSITION:
    1072110966    return LISTVIEW_SetItemPosition(hwnd, (INT)wParam, (INT)LOWORD(lParam),
     
    1072410969  case LVM_SETITEMPOSITION32:
    1072510970    return LISTVIEW_SetItemPosition(hwnd, (INT)wParam, ((POINT*)lParam)->x,
    10726                     ((POINT*)lParam)->y);
     10971                                    ((POINT*)lParam)->y);
    1072710972
    1072810973  case LVM_SETITEMSTATE:
    10729     return LISTVIEW_SetItemState(hwnd, (INT)wParam, (LPLVITEMA)lParam);
     10974    return LISTVIEW_SetItemState(hwnd, (INT)wParam, (LPLVITEMW)lParam);
    1073010975
    1073110976  case LVM_SETITEMTEXTA:
    10732     return LISTVIEW_SetItemTextA(hwnd, (INT)wParam, (LPLVITEMA)lParam);
    10733 
    10734 /*  case LVM_SETITEMTEXTW: */
     10977    return LISTVIEW_SetItemTextT(hwnd, (INT)wParam, (LPLVITEMW)lParam, FALSE);
     10978
     10979  case LVM_SETITEMTEXTW:
     10980    return LISTVIEW_SetItemTextT(hwnd, (INT)wParam, (LPLVITEMW)lParam, TRUE);
    1073510981
    1073610982  case LVM_SETSELECTIONMARK:
     
    1075010996    return LISTVIEW_SetWorkAreas(hwnd,wParam,lParam);
    1075110997#endif
    10752 /*  case LVM_SETTOOLTIPS: */
    10753 /*  case LVM_SETUNICODEFORMAT: */
    10754 /*  case LVM_SETWORKAREAS: */
     10998
     10999/*      case LVM_SETTOOLTIPS: */
     11000/*      case LVM_SETUNICODEFORMAT: */
     11001/*      case LVM_SETWORKAREAS: */
    1075511002
    1075611003  case LVM_SORTITEMS:
    10757     return LISTVIEW_SortItems(hwnd, wParam, lParam);
    10758 
    10759 /*  case LVM_SUBITEMHITTEST: */
     11004    return LISTVIEW_SortItems(hwnd, (PFNLVCOMPARE)lParam, (LPARAM)wParam);
     11005
    1076011006#ifdef __WIN32OS2__
    1076111007  case LVM_SUBITEMHITTEST:
     
    1076311009#endif
    1076411010
    10765   case LVM_UPDATE:
     11011/*      case LVM_SUBITEMHITTEST: */
     11012
     11013  case LVM_UPDATE:
    1076611014    return LISTVIEW_Update(hwnd, (INT)wParam);
    1076711015
     
    1077311021
    1077411022  case WM_CREATE:
    10775     return LISTVIEW_Create(hwnd, wParam, lParam);
    10776 
     11023    return LISTVIEW_Create(hwnd, (LPCREATESTRUCTW)lParam);
     11024   
    1077711025  case WM_ERASEBKGND:
    1077811026    return LISTVIEW_EraseBackground(hwnd, wParam, lParam);
     
    1078511033
    1078611034  case WM_HSCROLL:
    10787     return LISTVIEW_HScroll(hwnd, (INT)LOWORD(wParam),
     11035    return LISTVIEW_HScroll(hwnd, (INT)LOWORD(wParam), 
    1078811036                            (INT)HIWORD(wParam), (HWND)lParam);
    1078911037
     
    1079511043
    1079611044  case WM_LBUTTONDBLCLK:
    10797     return LISTVIEW_LButtonDblClk(hwnd, (WORD)wParam, LOWORD(lParam),
     11045    return LISTVIEW_LButtonDblClk(hwnd, (WORD)wParam, LOWORD(lParam), 
    1079811046                                HIWORD(lParam));
    10799 
     11047   
    1080011048  case WM_LBUTTONDOWN:
    10801     return LISTVIEW_LButtonDown(hwnd, (WORD)wParam, LOWORD(lParam),
     11049    return LISTVIEW_LButtonDown(hwnd, (WORD)wParam, LOWORD(lParam), 
    1080211050                                HIWORD(lParam));
    1080311051  case WM_LBUTTONUP:
    10804     return LISTVIEW_LButtonUp(hwnd, (WORD)wParam, LOWORD(lParam),
     11052    return LISTVIEW_LButtonUp(hwnd, (WORD)wParam, LOWORD(lParam), 
    1080511053                              HIWORD(lParam));
    1080611054  case WM_MOUSEMOVE:
     
    1082211070    return LISTVIEW_NotifyFormat(hwnd, (HWND)wParam, (INT)lParam);
    1082311071
    10824   case WM_PAINT:
    10825     return LISTVIEW_Paint(hwnd, (HDC)wParam);
     11072  case WM_PAINT: 
     11073    return LISTVIEW_Paint(hwnd, (HDC)wParam); 
    1082611074
    1082711075  case WM_RBUTTONDBLCLK:
    10828     return LISTVIEW_RButtonDblClk(hwnd, (WORD)wParam, LOWORD(lParam),
     11076    return LISTVIEW_RButtonDblClk(hwnd, (WORD)wParam, LOWORD(lParam), 
    1082911077                                  HIWORD(lParam));
    1083011078
    1083111079  case WM_RBUTTONDOWN:
    10832     return LISTVIEW_RButtonDown(hwnd, (WORD)wParam, LOWORD(lParam),
     11080    return LISTVIEW_RButtonDown(hwnd, (WORD)wParam, LOWORD(lParam), 
    1083311081                                HIWORD(lParam));
    1083411082
    1083511083  case WM_RBUTTONUP:
    10836     return LISTVIEW_RButtonUp(hwnd, (WORD)wParam, LOWORD(lParam),
     11084    return LISTVIEW_RButtonUp(hwnd, (WORD)wParam, LOWORD(lParam), 
    1083711085                              HIWORD(lParam));
    1083811086
     
    1084311091    return LISTVIEW_SetFont(hwnd, (HFONT)wParam, (WORD)lParam);
    1084411092
    10845   case WM_SETREDRAW:
     11093  case WM_SETREDRAW: 
    1084611094    return LISTVIEW_SetRedraw(hwnd, (BOOL)wParam);
    1084711095
     
    1085211100    return LISTVIEW_StyleChanged(hwnd, wParam, (LPSTYLESTRUCT)lParam);
    1085311101
    10854 /*  case WM_TIMER: */
    1085511102#ifdef __WIN32OS2__
    1085611103  case WM_TIMER:
     
    1085811105#endif
    1085911106
     11107/*      case WM_TIMER: */
     11108
    1086011109  case WM_VSCROLL:
    10861     return LISTVIEW_VScroll(hwnd, (INT)LOWORD(wParam),
     11110    return LISTVIEW_VScroll(hwnd, (INT)LOWORD(wParam), 
    1086211111                            (INT)HIWORD(wParam), (HWND)lParam);
    1086311112
    1086411113  case WM_MOUSEWHEEL:
    1086511114      if (wParam & (MK_SHIFT | MK_CONTROL))
    10866           return DefWindowProcA( hwnd, uMsg, wParam, lParam );
    10867       return LISTVIEW_MouseWheel(hwnd, (short int)HIWORD(wParam));/*    case WM_WINDOWPOSCHANGED: */
    10868 
    10869 /*  case WM_WININICHANGE: */
     11115          return DefWindowProcW( hwnd, uMsg, wParam, lParam );
     11116      return LISTVIEW_MouseWheel(hwnd, (short int)HIWORD(wParam));/*    case WM_WINDOWPOSCHANGED: */
     11117
     11118/*      case WM_WININICHANGE: */
    1087011119
    1087111120  default:
    1087211121    if (uMsg >= WM_USER)
    1087311122    {
    10874       ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam,
     11123      ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, 
    1087511124          lParam);
    1087611125    }
    10877 
    10878     /* call default window procedure */
    1087911126#ifdef __WIN32OS2__
    1088011127    return defComCtl32ProcA (hwnd, uMsg, wParam, lParam);
     
    1089011137 * DESCRIPTION:
    1089111138 * Registers the window class.
    10892  *
     11139 * 
    1089311140 * PARAMETER(S):
    1089411141 * None
     
    1089911146VOID LISTVIEW_Register(void)
    1090011147{
    10901   WNDCLASSA wndClass;
    10902 
    10903     ZeroMemory(&wndClass, sizeof(WNDCLASSA));
     11148  WNDCLASSW wndClass;
     11149
     11150    ZeroMemory(&wndClass, sizeof(WNDCLASSW));
    1090411151    wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
    1090511152    wndClass.lpfnWndProc = (WNDPROC)LISTVIEW_WindowProc;
    1090611153    wndClass.cbClsExtra = 0;
    1090711154    wndClass.cbWndExtra = sizeof(LISTVIEW_INFO *);
    10908     wndClass.hCursor = LoadCursorA(0, IDC_ARROWA);
     11155    wndClass.hCursor = LoadCursorW(0, IDC_ARROWW);
    1090911156    wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    10910     wndClass.lpszClassName = WC_LISTVIEWA;
    10911     RegisterClassA(&wndClass);
     11157    wndClass.lpszClassName = WC_LISTVIEWW;
     11158    RegisterClassW(&wndClass);
    1091211159}
    1091311160
     
    1091511162 * DESCRIPTION:
    1091611163 * Unregisters the window class.
    10917  *
     11164 * 
    1091811165 * PARAMETER(S):
    1091911166 * None
     
    1092411171VOID LISTVIEW_Unregister(void)
    1092511172{
    10926     UnregisterClassA(WC_LISTVIEWA, (HINSTANCE)NULL);
     11173    UnregisterClassW(WC_LISTVIEWW, (HINSTANCE)NULL);
    1092711174}
    1092811175
     
    1093011177 * DESCRIPTION:
    1093111178 * Handle any WM_COMMAND messages
    10932  *
     11179 * 
    1093311180 * PARAMETER(S):
    1093411181 *
     
    1093911186    switch (HIWORD(wParam))
    1094011187    {
    10941     case EN_UPDATE:
    10942     {
    10943         /*
    10944          * Adjust the edit window size
    10945          */
    10946         char buffer[1024];
    10947         LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    10948         HDC           hdc      = GetDC(infoPtr->hwndEdit);
     11188        case EN_UPDATE:
     11189        {
     11190            /*
     11191             * Adjust the edit window size
     11192             */
     11193            WCHAR buffer[1024];
     11194            LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
     11195            HDC           hdc      = GetDC(infoPtr->hwndEdit);
    1094911196            HFONT         hFont, hOldFont = 0;
    10950         RECT      rect;
    10951         SIZE      sz;
    10952         int       len;
    10953 
    10954         len = GetWindowTextA(infoPtr->hwndEdit, buffer, 1023);
    10955         GetWindowRect(infoPtr->hwndEdit, &rect);
     11197            RECT          rect;
     11198            SIZE          sz;
     11199            int           len;
     11200
     11201            len = GetWindowTextW(infoPtr->hwndEdit, buffer, sizeof(buffer)/sizeof(buffer[0]));
     11202            GetWindowRect(infoPtr->hwndEdit, &rect);
    1095611203
    1095711204            /* Select font to get the right dimension of the string */
    10958             hFont = SendMessageA(infoPtr->hwndEdit, WM_GETFONT, 0, 0);
     11205            hFont = SendMessageW(infoPtr->hwndEdit, WM_GETFONT, 0, 0);
    1095911206            if(hFont != 0)
    1096011207            {
     
    1096211209            }
    1096311210
    10964         if (GetTextExtentPoint32A(hdc, buffer, strlen(buffer), &sz))
    10965         {
    10966                 TEXTMETRICA textMetric;
     11211            if (GetTextExtentPoint32W(hdc, buffer, lstrlenW(buffer), &sz))
     11212            {
     11213                TEXTMETRICW textMetric;
    1096711214
    1096811215                /* Add Extra spacing for the next character */
    10969                 GetTextMetricsA(hdc, &textMetric);
     11216                GetTextMetricsW(hdc, &textMetric);
    1097011217                sz.cx += (textMetric.tmMaxCharWidth * 2);
    1097111218
    10972         SetWindowPos (
    10973             infoPtr->hwndEdit,
    10974             HWND_TOP,
    10975             0,
    10976             0,
    10977             sz.cx,
    10978             rect.bottom - rect.top,
    10979             SWP_DRAWFRAME|SWP_NOMOVE);
    10980         }
     11219                SetWindowPos (
     11220                    infoPtr->hwndEdit,
     11221                    HWND_TOP,
     11222                    0,
     11223                    0,
     11224                    sz.cx,
     11225                    rect.bottom - rect.top,
     11226                    SWP_DRAWFRAME|SWP_NOMOVE);
     11227            }
    1098111228            if(hFont != 0)
    10982             {
    1098311229                SelectObject(hdc, hOldFont);
    10984             }
    10985 
    10986         ReleaseDC(hwnd, hdc);
    10987 
    10988         break;
    10989     }
    10990 
    10991     default:
    10992       return SendMessageA (GetParent (hwnd), WM_COMMAND, wParam, lParam);
     11230
     11231            ReleaseDC(hwnd, hdc);
     11232
     11233            break;
     11234        }
     11235
     11236        default:
     11237          return SendMessageW (GetParent (hwnd), WM_COMMAND, wParam, lParam);
    1099311238    }
    1099411239
     
    1100511250 * RETURN:
    1100611251 */
    11007 LRESULT CALLBACK EditLblWndProc(HWND hwnd, UINT uMsg,
    11008     WPARAM wParam, LPARAM lParam)
    11009 {
    11010     BOOL cancel = FALSE;
    11011     LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(GetParent(hwnd), 0);
     11252static LRESULT EditLblWndProcT(HWND hwnd, UINT uMsg,
     11253        WPARAM wParam, LPARAM lParam, BOOL isW)
     11254{
     11255    LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(GetParent(hwnd), 0);
    1101211256    EDITLABEL_ITEM *einfo = infoPtr->pedititem;
    1101311257    static BOOL bIgnoreKillFocus = FALSE;
     11258    BOOL cancel = FALSE;
     11259
     11260    TRACE("(hwnd=%x, uMsg=%x, wParam=%x, lParam=%lx, isW=%d)\n",
     11261          hwnd, uMsg, wParam, lParam, isW);
     11262   
    1101411263    switch (uMsg)
    1101511264    {
    11016     case WM_GETDLGCODE:
    11017       return DLGC_WANTARROWS | DLGC_WANTALLKEYS;
    11018 
    11019     case WM_KILLFOCUS:
    11020             if(bIgnoreKillFocus)
    11021             {
    11022                 return TRUE;
    11023             }
    11024         break;
    11025 
    11026     case WM_DESTROY:
    11027     {
    11028         WNDPROC editProc = einfo->EditWndProc;
    11029         SetWindowLongA(hwnd, GWL_WNDPROC, (LONG)editProc);
    11030         COMCTL32_Free(einfo);
    11031         infoPtr->pedititem = NULL;
    11032         return CallWindowProcA(editProc, hwnd, uMsg, wParam, lParam);
    11033     }
    11034 
    11035     case WM_KEYDOWN:
    11036         if (VK_ESCAPE == (INT)wParam)
    11037         {
    11038         cancel = TRUE;
     11265        case WM_GETDLGCODE:
     11266          return DLGC_WANTARROWS | DLGC_WANTALLKEYS;
     11267                       
     11268        case WM_KILLFOCUS:
     11269            if(bIgnoreKillFocus) return TRUE;
     11270            break;
     11271
     11272        case WM_DESTROY:
     11273        {
     11274            WNDPROC editProc = einfo->EditWndProc;
     11275            SetWindowLongW(hwnd, GWL_WNDPROC, (LONG)editProc);
     11276            COMCTL32_Free(einfo);
     11277            infoPtr->pedititem = NULL;
     11278            return CallWindowProcT(editProc, hwnd, uMsg, wParam, lParam, isW);
     11279        }
     11280
     11281        case WM_KEYDOWN:
     11282            if (VK_ESCAPE == (INT)wParam)
     11283            {
     11284                cancel = TRUE;
    1103911285                break;
    11040 
    11041         }
    11042         else if (VK_RETURN == (INT)wParam)
    11043         break;
    11044 
    11045     default:
    11046         return CallWindowProcA(einfo->EditWndProc, hwnd,
    11047             uMsg, wParam, lParam);
     11286            }
     11287            else if (VK_RETURN == (INT)wParam)
     11288                break;
     11289
     11290        default:
     11291            return CallWindowProcT(einfo->EditWndProc, hwnd, uMsg, wParam, lParam, isW);
    1104811292    }
    1104911293
    1105011294    if (einfo->EditLblCb)
    1105111295    {
    11052     char *buffer = NULL;
    11053 
    11054 
    11055     if (!cancel)
    11056     {
    11057         int len = 1 + GetWindowTextLengthA(hwnd);
    11058 
    11059         if (len > 1)
    11060         {
    11061         if (NULL != (buffer = (char *)COMCTL32_Alloc(len*sizeof(char))))
    11062         {
    11063             GetWindowTextA(hwnd, buffer, len);
    11064         }
    11065         }
    11066     }
     11296        LPWSTR buffer = NULL;
     11297       
     11298        if (!cancel)
     11299        {
     11300            DWORD len = isW ? GetWindowTextLengthW(hwnd) : GetWindowTextLengthA(hwnd);
     11301
     11302            if (len)
     11303            {
     11304                if ( (buffer = COMCTL32_Alloc((len+1) * (isW ? sizeof(WCHAR) : sizeof(CHAR)))) )
     11305                {
     11306                    if (isW) GetWindowTextW(hwnd, buffer, len+1);
     11307                    else GetWindowTextA(hwnd, (CHAR*)buffer, len+1);
     11308                }
     11309            }
     11310        }
    1106711311        /* Processing LVN_ENDLABELEDIT message could kill the focus       */
    1106811312        /* eg. Using a messagebox                                         */
    1106911313        bIgnoreKillFocus = TRUE;
    11070     einfo->EditLblCb(GetParent(hwnd), buffer, einfo->param);
    11071 
    11072     if (buffer)
    11073         COMCTL32_Free(buffer);
    11074 
    11075     einfo->EditLblCb = NULL;
     11314        einfo->EditLblCb(GetParent(hwnd), buffer, einfo->param);
     11315
     11316        if (buffer) COMCTL32_Free(buffer);
     11317
     11318        einfo->EditLblCb = NULL;
    1107611319        bIgnoreKillFocus = FALSE;
    1107711320    }
    1107811321
    11079     SendMessageA(hwnd, WM_CLOSE, 0, 0);
     11322    SendMessageW(hwnd, WM_CLOSE, 0, 0);
    1108011323    return TRUE;
    1108111324}
    1108211325
     11326/***
     11327 * DESCRIPTION:
     11328 * Subclassed edit control windproc function
     11329 *
     11330 * PARAMETER(S):
     11331 *
     11332 * RETURN:
     11333 */
     11334LRESULT CALLBACK EditLblWndProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
     11335{
     11336    return EditLblWndProcT(hwnd, uMsg, wParam, lParam, TRUE);
     11337}
     11338
     11339/***
     11340 * DESCRIPTION:
     11341 * Subclassed edit control windproc function
     11342 *
     11343 * PARAMETER(S):
     11344 *
     11345 * RETURN:
     11346 */
     11347LRESULT CALLBACK EditLblWndProcA(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
     11348{
     11349    return EditLblWndProcT(hwnd, uMsg, wParam, lParam, FALSE);
     11350}
    1108311351
    1108411352/***
     
    1109011358 * RETURN:
    1109111359 */
    11092 HWND CreateEditLabel(LPCSTR text, DWORD style, INT x, INT y,
    11093     INT width, INT height, HWND parent, HINSTANCE hinst,
    11094     EditlblCallback EditLblCb, DWORD param)
    11095 {
     11360HWND CreateEditLabelT(LPCWSTR text, DWORD style, INT x, INT y,
     11361        INT width, INT height, HWND parent, HINSTANCE hinst,
     11362        EditlblCallbackW EditLblCb, DWORD param, BOOL isW)
     11363{
     11364    LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(parent, 0);
     11365    WCHAR editName[5] = { 'E', 'd', 'i', 't', '\0' };
    1109611366    HWND hedit;
    1109711367    SIZE sz;
    1109811368    HDC hdc;
    1109911369    HDC hOldFont=0;
    11100     TEXTMETRICA textMetric;
    11101     LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(parent, 0);
    11102 
     11370    TEXTMETRICW textMetric;
     11371
     11372    TRACE("(text=%s, ..., isW=%d)\n", debugstr_t(text, isW), isW);
     11373   
    1110311374    if (NULL == (infoPtr->pedititem = COMCTL32_Alloc(sizeof(EDITLABEL_ITEM))))
    11104     return 0;
     11375        return 0;
    1110511376
    1110611377    style |= WS_CHILDWINDOW|WS_CLIPSIBLINGS|ES_LEFT|WS_BORDER;
     
    1110911380    /* Select the font to get appropriate metric dimensions */
    1111011381    if(infoPtr->hFont != 0)
    11111     {
    1111211382        hOldFont = SelectObject(hdc, infoPtr->hFont);
    11113     }
    1111411383
    1111511384    /*Get String Lenght in pixels */
    11116     GetTextExtentPoint32A(hdc, text, strlen(text), &sz);
     11385    GetTextExtentPoint32W(hdc, text, lstrlenW(text), &sz);
    1111711386
    1111811387    /*Add Extra spacing for the next character */
    11119     GetTextMetricsA(hdc, &textMetric);
     11388    GetTextMetricsW(hdc, &textMetric);
    1112011389    sz.cx += (textMetric.tmMaxCharWidth * 2);
    1112111390
    1112211391    if(infoPtr->hFont != 0)
    11123     {
    1112411392        SelectObject(hdc, hOldFont);
    11125     }
    1112611393
    1112711394    ReleaseDC(parent, hdc);
    11128     if (!(hedit = CreateWindowA("Edit", text, style, x, y, sz.cx, height,
    11129             parent, 0, hinst, 0)))
    11130     {
    11131     COMCTL32_Free(infoPtr->pedititem);
    11132     return 0;
     11395    if (isW)
     11396        hedit = CreateWindowW(editName, text, style, x, y, sz.cx, height, parent, 0, hinst, 0);
     11397    else
     11398        hedit = CreateWindowA("Edit", (LPCSTR)text, style, x, y, sz.cx, height, parent, 0, hinst, 0);
     11399
     11400    if (!hedit)
     11401    {
     11402        COMCTL32_Free(infoPtr->pedititem);
     11403        return 0;
    1113311404    }
    1113411405
    1113511406    infoPtr->pedititem->param = param;
    1113611407    infoPtr->pedititem->EditLblCb = EditLblCb;
    11137     infoPtr->pedititem->EditWndProc = (WNDPROC)SetWindowLongA(hedit,
    11138       GWL_WNDPROC, (LONG) EditLblWndProc);
    11139 
    11140     SendMessageA(hedit, WM_SETFONT, infoPtr->hFont, FALSE);
     11408    infoPtr->pedititem->EditWndProc = (WNDPROC)
     11409        (isW ? SetWindowLongW(hedit, GWL_WNDPROC, (LONG)EditLblWndProcW) :
     11410               SetWindowLongA(hedit, GWL_WNDPROC, (LONG)EditLblWndProcA) );
     11411
     11412    SendMessageW(hedit, WM_SETFONT, infoPtr->hFont, FALSE);
    1114111413
    1114211414    return hedit;
    1114311415}
    1114411416
    11145 
Note: See TracChangeset for help on using the changeset viewer.